AudioTrackShared.h revision 573266210fb2b2e7d86fbd46d0dfe16763611d91
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 uint8_t channels; 59 uint8_t flowControlFlag; // underrun (out) or overrrun (in) indication 60 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 66 int32_t Padding[1]; 67 // Cache line boundary 68 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 84