AudioRecord.h revision 879135196fd1c97deefc538c888037c56c2879a7
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright (C) 2008 The Android Open Source Project 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Licensed under the Apache License, Version 2.0 (the "License"); 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * you may not use this file except in compliance with the License. 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * You may obtain a copy of the License at 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * http://www.apache.org/licenses/LICENSE-2.0 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Unless required by applicable law or agreed to in writing, software 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * distributed under the License is distributed on an "AS IS" BASIS, 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) * See the License for the specific language governing permissions and 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * limitations under the License. 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef AUDIORECORD_H_ 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define AUDIORECORD_H_ 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <stdint.h> 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <sys/types.h> 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <media/IAudioFlinger.h> 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <media/IAudioRecord.h> 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <media/AudioTrack.h> 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <utils/RefBase.h> 28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include <utils/Errors.h> 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <binder/IInterface.h> 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <binder/IMemory.h> 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <utils/threads.h> 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <system/audio.h> 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace android { 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ---------------------------------------------------------------------------- 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AudioRecord 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){ 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 43d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) static const int DEFAULT_SAMPLE_RATE = 8000; 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* Events used by AudioRecord callback function (callback_t). 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * to keep in sync with frameworks/base/media/java/android/media/AudioRecord.java 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum event_type { 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EVENT_MORE_DATA = 0, // Request to reqd more data from PCM buffer. 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EVENT_OVERRUN = 1, // PCM buffer overrun occured. 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EVENT_MARKER = 2, // Record head is at the specified marker position 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (See setMarkerPosition()). 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EVENT_NEW_POS = 3, // Record head is at a new position 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (See setPositionUpdatePeriod()). 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* Create Buffer on the stack and pass it to obtainBuffer() 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * and releaseBuffer(). 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */ 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class Buffer 63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) { 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) enum { 66a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) MUTE = 0x00000001 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) uint32_t flags; 69d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) int channelCount; 70d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) int format; 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t frameCount; 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t size; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) union { 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void* raw; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) short* i16; 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int8_t* i8; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* These are static methods to control the system-wide AudioFlinger 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * only privileged processes can have access to them 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static status_t setMasterMute(bool mute); 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* As a convenience, if a callback is supplied, a handler thread 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * is automatically created with the appropriate priority. This thread 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * invokes the callback when a new buffer becomes ready or an overrun condition occurs. 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Parameters: 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * event: type of event notified (see enum AudioRecord::event_type). 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * user: Pointer to context for use by the callback receiver. 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * info: Pointer to optional parameter according to event type: 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * - EVENT_MORE_DATA: pointer to AudioRecord::Buffer struct. The callback must not read 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * more bytes than indicated by 'size' field and update 'size' if less bytes are 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * read. 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * - EVENT_OVERRUN: unused. 98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * - EVENT_MARKER: pointer to an uin32_t containing the marker position in frames. 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * - EVENT_NEW_POS: pointer to an uin32_t containing the new position in frames. 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef void (*callback_t)(int event, void* user, void *info); 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* Returns the minimum frame count required for the successful creation of 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * an AudioRecord object. 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Returned status (from utils/Errors.h) can be: 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * - NO_ERROR: successful operation 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * - NO_INIT: audio server or audio hardware not initialized 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * - BAD_VALUE: unsupported configuration 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static status_t getMinFrameCount(int* frameCount, 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint32_t sampleRate, 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int format, 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int channelCount); 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* Constructs an uninitialized AudioRecord. No connection with 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * AudioFlinger takes place. 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AudioRecord(); 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /* Creates an AudioRecord track and registers it with AudioFlinger. 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Once created, the track needs to be started before it can be used. 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Unspecified values are set to the audio hardware's current 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * values. 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Parameters: 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * inputSource: Select the audio input to record to (e.g. AUDIO_SOURCE_DEFAULT). 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * sampleRate: Track sampling rate in Hz. 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * format: Audio format (e.g AUDIO_FORMAT_PCM_16_BIT for signed 132d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) * 16 bits per sample). 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * channelMask: Channel mask: see audio_channels_t. 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * frameCount: Total size of track PCM buffer in frames. This defines the 135d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) * latency of the track. 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * flags: A bitmask of acoustic values from enum record_flags. It enables 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * AGC, NS, and IIR. 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * cbf: Callback function. If not null, this function is called periodically 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * to provide new PCM data. 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * notificationFrames: The callback function is called each time notificationFrames PCM 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * frames are ready in record track output buffer. 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * user Context for use by the callback receiver. 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum record_flags { 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RECORD_AGC_ENABLE = AUDIO_IN_ACOUSTICS_AGC_ENABLE, 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RECORD_NS_ENABLE = AUDIO_IN_ACOUSTICS_NS_ENABLE, 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RECORD_IIR_ENABLE = AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE, 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AudioRecord(int inputSource, 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint32_t sampleRate = 0, 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int format = 0, 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint32_t channelMask = AUDIO_CHANNEL_IN_MONO, 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int frameCount = 0, 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint32_t flags = 0, 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) callback_t cbf = 0, 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void* user = 0, 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int notificationFrames = 0, 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int sessionId = 0); 161 162 163 /* Terminates the AudioRecord and unregisters it from AudioFlinger. 164 * Also destroys all resources assotiated with the AudioRecord. 165 */ 166 ~AudioRecord(); 167 168 169 /* Initialize an uninitialized AudioRecord. 170 * Returned status (from utils/Errors.h) can be: 171 * - NO_ERROR: successful intialization 172 * - INVALID_OPERATION: AudioRecord is already intitialized or record device is already in use 173 * - BAD_VALUE: invalid parameter (channels, format, sampleRate...) 174 * - NO_INIT: audio server or audio hardware not initialized 175 * - PERMISSION_DENIED: recording is not allowed for the requesting process 176 * */ 177 status_t set(int inputSource = 0, 178 uint32_t sampleRate = 0, 179 int format = 0, 180 uint32_t channelMask = AUDIO_CHANNEL_IN_MONO, 181 int frameCount = 0, 182 uint32_t flags = 0, 183 callback_t cbf = 0, 184 void* user = 0, 185 int notificationFrames = 0, 186 bool threadCanCallJava = false, 187 int sessionId = 0); 188 189 190 /* Result of constructing the AudioRecord. This must be checked 191 * before using any AudioRecord API (except for set()), using 192 * an uninitialized AudioRecord produces undefined results. 193 * See set() method above for possible return codes. 194 */ 195 status_t initCheck() const; 196 197 /* Returns this track's latency in milliseconds. 198 * This includes the latency due to AudioRecord buffer size 199 * and audio hardware driver. 200 */ 201 uint32_t latency() const; 202 203 /* getters, see constructor */ 204 205 int format() const; 206 int channelCount() const; 207 int channels() const; 208 uint32_t frameCount() const; 209 int frameSize() const; 210 int inputSource() const; 211 212 213 /* After it's created the track is not active. Call start() to 214 * make it active. If set, the callback will start being called. 215 */ 216 status_t start(); 217 218 /* Stop a track. If set, the callback will cease being called and 219 * obtainBuffer returns STOPPED. Note that obtainBuffer() still works 220 * and will fill up buffers until the pool is exhausted. 221 */ 222 status_t stop(); 223 bool stopped() const; 224 225 /* get sample rate for this record track 226 */ 227 uint32_t getSampleRate(); 228 229 /* Sets marker position. When record reaches the number of frames specified, 230 * a callback with event type EVENT_MARKER is called. Calling setMarkerPosition 231 * with marker == 0 cancels marker notification callback. 232 * If the AudioRecord has been opened with no callback function associated, 233 * the operation will fail. 234 * 235 * Parameters: 236 * 237 * marker: marker position expressed in frames. 238 * 239 * Returned status (from utils/Errors.h) can be: 240 * - NO_ERROR: successful operation 241 * - INVALID_OPERATION: the AudioRecord has no callback installed. 242 */ 243 status_t setMarkerPosition(uint32_t marker); 244 status_t getMarkerPosition(uint32_t *marker); 245 246 247 /* Sets position update period. Every time the number of frames specified has been recorded, 248 * a callback with event type EVENT_NEW_POS is called. 249 * Calling setPositionUpdatePeriod with updatePeriod == 0 cancels new position notification 250 * callback. 251 * If the AudioRecord has been opened with no callback function associated, 252 * the operation will fail. 253 * 254 * Parameters: 255 * 256 * updatePeriod: position update notification period expressed in frames. 257 * 258 * Returned status (from utils/Errors.h) can be: 259 * - NO_ERROR: successful operation 260 * - INVALID_OPERATION: the AudioRecord has no callback installed. 261 */ 262 status_t setPositionUpdatePeriod(uint32_t updatePeriod); 263 status_t getPositionUpdatePeriod(uint32_t *updatePeriod); 264 265 266 /* Gets record head position. The position is the total number of frames 267 * recorded since record start. 268 * 269 * Parameters: 270 * 271 * position: Address where to return record head position within AudioRecord buffer. 272 * 273 * Returned status (from utils/Errors.h) can be: 274 * - NO_ERROR: successful operation 275 * - BAD_VALUE: position is NULL 276 */ 277 status_t getPosition(uint32_t *position); 278 279 /* returns a handle on the audio input used by this AudioRecord. 280 * 281 * Parameters: 282 * none. 283 * 284 * Returned value: 285 * handle on audio hardware input 286 */ 287 audio_io_handle_t getInput(); 288 289 /* returns the audio session ID associated to this AudioRecord. 290 * 291 * Parameters: 292 * none. 293 * 294 * Returned value: 295 * AudioRecord session ID. 296 */ 297 int getSessionId(); 298 299 /* obtains a buffer of "frameCount" frames. The buffer must be 300 * filled entirely. If the track is stopped, obtainBuffer() returns 301 * STOPPED instead of NO_ERROR as long as there are buffers availlable, 302 * at which point NO_MORE_BUFFERS is returned. 303 * Buffers will be returned until the pool (buffercount()) 304 * is exhausted, at which point obtainBuffer() will either block 305 * or return WOULD_BLOCK depending on the value of the "blocking" 306 * parameter. 307 */ 308 309 enum { 310 NO_MORE_BUFFERS = 0x80000001, 311 STOPPED = 1 312 }; 313 314 status_t obtainBuffer(Buffer* audioBuffer, int32_t waitCount); 315 void releaseBuffer(Buffer* audioBuffer); 316 317 318 /* As a convenience we provide a read() interface to the audio buffer. 319 * This is implemented on top of lockBuffer/unlockBuffer. 320 */ 321 ssize_t read(void* buffer, size_t size); 322 323 /* Return the amount of input frames lost in the audio driver since the last call of this function. 324 * Audio driver is expected to reset the value to 0 and restart counting upon returning the current value by this function call. 325 * Such loss typically occurs when the user space process is blocked longer than the capacity of audio driver buffers. 326 * Unit: the number of input audio frames 327 */ 328 unsigned int getInputFramesLost(); 329 330private: 331 /* copying audio tracks is not allowed */ 332 AudioRecord(const AudioRecord& other); 333 AudioRecord& operator = (const AudioRecord& other); 334 335 /* a small internal class to handle the callback */ 336 class ClientRecordThread : public Thread 337 { 338 public: 339 ClientRecordThread(AudioRecord& receiver, bool bCanCallJava = false); 340 private: 341 friend class AudioRecord; 342 virtual bool threadLoop(); 343 virtual status_t readyToRun() { return NO_ERROR; } 344 virtual void onFirstRef() {} 345 AudioRecord& mReceiver; 346 Mutex mLock; 347 }; 348 349 bool processAudioBuffer(const sp<ClientRecordThread>& thread); 350 status_t openRecord_l(uint32_t sampleRate, 351 uint32_t format, 352 uint32_t channelMask, 353 int frameCount, 354 uint32_t flags, 355 audio_io_handle_t input); 356 audio_io_handle_t getInput_l(); 357 status_t restoreRecord_l(audio_track_cblk_t*& cblk); 358 359 sp<IAudioRecord> mAudioRecord; 360 sp<IMemory> mCblkMemory; 361 sp<ClientRecordThread> mClientRecordThread; 362 Mutex mLock; 363 364 uint32_t mFrameCount; 365 366 audio_track_cblk_t* mCblk; 367 uint32_t mFormat; 368 uint8_t mChannelCount; 369 uint8_t mInputSource; 370 uint8_t mReserved[2]; 371 status_t mStatus; 372 uint32_t mLatency; 373 374 volatile int32_t mActive; 375 376 callback_t mCbf; 377 void* mUserData; 378 uint32_t mNotificationFrames; 379 uint32_t mRemainingFrames; 380 uint32_t mMarkerPosition; 381 bool mMarkerReached; 382 uint32_t mNewPosition; 383 uint32_t mUpdatePeriod; 384 uint32_t mFlags; 385 uint32_t mChannelMask; 386 audio_io_handle_t mInput; 387 int mSessionId; 388 int mPreviousPriority; // before start() 389 int mPreviousSchedulingGroup; 390}; 391 392}; // namespace android 393 394#endif /*AUDIORECORD_H_*/ 395