blob: bda969ce832511b2eb6b1584e54a8f31d6473883 [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
29#define MAX_SAMPLE_RATE 65535
30#define THREAD_PRIORITY_AUDIO_CLIENT (ANDROID_PRIORITY_AUDIO)
31// Maximum cumulated timeout milliseconds before restarting audioflinger thread
32#define MAX_STARTUP_TIMEOUT_MS 3000 // Longer timeout period at startup to cope with A2DP init time
33#define MAX_RUN_TIMEOUT_MS 1000
34#define WAIT_PERIOD_MS 10
35
36
37struct audio_track_cblk_t
38{
39
40 // The data members are grouped so that members accessed frequently and in the same context
41 // are in the same line of data cache.
42 Mutex lock;
43 Condition cv;
44 volatile uint32_t user;
45 volatile uint32_t server;
46 uint32_t userBase;
47 uint32_t serverBase;
48 void* buffers;
49 uint32_t frameCount;
50 // Cache line boundary
51 uint32_t loopStart;
52 uint32_t loopEnd;
53 int loopCount;
54 volatile union {
55 uint16_t volume[2];
56 uint32_t volumeLR;
57 };
58 uint16_t sampleRate;
59 uint16_t channels;
60 int16_t flowControlFlag; // underrun (out) or overrrun (in) indication
61 uint8_t out; // out equals 1 for AudioTrack and 0 for AudioRecord
62 uint8_t forceReady;
63 uint16_t bufferTimeoutMs; // Maximum cumulated timeout before restarting audioflinger
64 uint16_t waitTimeMs; // Cumulated wait time
65 // Padding ensuring that data buffer starts on a cache line boundary (32 bytes).
66 // See AudioFlinger::TrackBase constructor
The Android Open Source Project1179bc92009-03-18 17:39:46 -070067 int32_t Padding[1];
68 // Cache line boundary
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080069
70 audio_track_cblk_t();
71 uint32_t stepUser(uint32_t frameCount);
72 bool stepServer(uint32_t frameCount);
73 void* buffer(uint32_t offset) const;
74 uint32_t framesAvailable();
75 uint32_t framesAvailable_l();
76 uint32_t framesReady();
77};
78
79
80// ----------------------------------------------------------------------------
81
82}; // namespace android
83
84#endif // ANDROID_AUDIO_TRACK_SHARED_H