blob: 496a73987e74463e2d00b0491b19c66c70df2409 [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_AUDIO_TRACK_SHARED_H
18#define ANDROID_AUDIO_TRACK_SHARED_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/threads.h>
24
25namespace android {
26
27// ----------------------------------------------------------------------------
28
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080029#define THREAD_PRIORITY_AUDIO_CLIENT (ANDROID_PRIORITY_AUDIO)
30// Maximum cumulated timeout milliseconds before restarting audioflinger thread
31#define MAX_STARTUP_TIMEOUT_MS 3000 // Longer timeout period at startup to cope with A2DP init time
32#define MAX_RUN_TIMEOUT_MS 1000
33#define WAIT_PERIOD_MS 10
34
35
36struct audio_track_cblk_t
37{
38
39 // The data members are grouped so that members accessed frequently and in the same context
40 // are in the same line of data cache.
41 Mutex lock;
42 Condition cv;
43 volatile uint32_t user;
44 volatile uint32_t server;
45 uint32_t userBase;
46 uint32_t serverBase;
47 void* buffers;
48 uint32_t frameCount;
49 // Cache line boundary
50 uint32_t loopStart;
51 uint32_t loopEnd;
52 int loopCount;
53 volatile union {
54 uint16_t volume[2];
55 uint32_t volumeLR;
56 };
Eric Laurent57326622009-07-07 07:10:45 -070057 uint32_t sampleRate;
58 uint8_t channels;
59 uint8_t flowControlFlag; // underrun (out) or overrrun (in) indication
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080060 uint8_t out; // out equals 1 for AudioTrack and 0 for AudioRecord
61 uint8_t forceReady;
62 uint16_t bufferTimeoutMs; // Maximum cumulated timeout before restarting audioflinger
63 uint16_t waitTimeMs; // Cumulated wait time
64 // Padding ensuring that data buffer starts on a cache line boundary (32 bytes).
65 // See AudioFlinger::TrackBase constructor
The Android Open Source Project1179bc92009-03-18 17:39:46 -070066 int32_t Padding[1];
67 // Cache line boundary
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080068
69 audio_track_cblk_t();
70 uint32_t stepUser(uint32_t frameCount);
71 bool stepServer(uint32_t frameCount);
72 void* buffer(uint32_t offset) const;
73 uint32_t framesAvailable();
74 uint32_t framesAvailable_l();
75 uint32_t framesReady();
76};
77
78
79// ----------------------------------------------------------------------------
80
81}; // namespace android
82
83#endif // ANDROID_AUDIO_TRACK_SHARED_H