AudioTrackShared.h revision 45df6a2a25ff36606a5301155d8d97e9bf80d00b
1/*
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 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                };
57                uint32_t    sampleRate;
58                // NOTE: audio_track_cblk_t::frameSize is not equal to AudioTrack::frameSize() for
59                // 8 bit PCM data: in this case,  mCblk->frameSize is based on a sample size of
60                // 16 bit because data is converted to 16 bit before being stored in buffer
61                uint32_t    frameSize;
62                uint8_t     channelCount;
63                uint8_t     flowControlFlag; // underrun (out) or overrrun (in) indication
64                uint8_t     out;        // out equals 1 for AudioTrack and 0 for AudioRecord
65                uint8_t     forceReady;
66                uint16_t    bufferTimeoutMs; // Maximum cumulated timeout before restarting audioflinger
67                uint16_t    waitTimeMs;      // Cumulated wait time
68                // Cache line boundary (32 bytes)
69
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
85