RecordTracks.h revision d776ac63ce9c013c9626226e43f7db606e035838
1/* 2** 3** Copyright 2012, The Android Open Source Project 4** 5** Licensed under the Apache License, Version 2.0 (the "License"); 6** you may not use this file except in compliance with the License. 7** You may obtain a copy of the License at 8** 9** http://www.apache.org/licenses/LICENSE-2.0 10** 11** Unless required by applicable law or agreed to in writing, software 12** distributed under the License is distributed on an "AS IS" BASIS, 13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14** See the License for the specific language governing permissions and 15** limitations under the License. 16*/ 17 18#ifndef INCLUDING_FROM_AUDIOFLINGER_H 19 #error This header file should only be included from AudioFlinger.h 20#endif 21 22// record track 23class RecordTrack : public TrackBase { 24public: 25 RecordTrack(RecordThread *thread, 26 const sp<Client>& client, 27 uint32_t sampleRate, 28 audio_format_t format, 29 audio_channel_mask_t channelMask, 30 size_t frameCount, 31 int sessionId, 32 int uid, 33 bool isFast); 34 virtual ~RecordTrack(); 35 36 virtual status_t start(AudioSystem::sync_event_t event, int triggerSession); 37 virtual void stop(); 38 39 void destroy(); 40 41 void invalidate(); 42 // clear the buffer overflow flag 43 void clearOverflow() { mOverflow = false; } 44 // set the buffer overflow flag and return previous value 45 bool setOverflow() { bool tmp = mOverflow; mOverflow = true; 46 return tmp; } 47 48 static void appendDumpHeader(String8& result); 49 void dump(char* buffer, size_t size, bool active); 50 51 void handleSyncStartEvent(const sp<SyncEvent>& event); 52 void clearSyncStartEvent(); 53 54private: 55 friend class AudioFlinger; // for mState 56 57 RecordTrack(const RecordTrack&); 58 RecordTrack& operator = (const RecordTrack&); 59 60 // AudioBufferProvider interface 61 virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer, 62 int64_t pts = kInvalidPTS); 63 // releaseBuffer() not overridden 64 65 bool mOverflow; // overflow on most recent attempt to fill client buffer 66 67 // updated by RecordThread::readInputParameters_l() 68 AudioResampler *mResampler; 69 70 // interleaved stereo pairs of fixed-point Q4.27 71 int32_t *mRsmpOutBuffer; 72 // current allocated frame count for the above, which may be larger than needed 73 size_t mRsmpOutFrameCount; 74 75 size_t mRsmpInUnrel; // unreleased frames remaining from 76 // most recent getNextBuffer 77 // for debug only 78 79 // rolling counter that is never cleared 80 int32_t mRsmpInFront; // next available frame 81 82 AudioBufferProvider::Buffer mSink; // references client's buffer sink in shared memory 83 84 // sync event triggering actual audio capture. Frames read before this event will 85 // be dropped and therefore not read by the application. 86 sp<SyncEvent> mSyncStartEvent; 87 88 // number of captured frames to drop after the start sync event has been received. 89 // when < 0, maximum frames to drop before starting capture even if sync event is 90 // not received 91 ssize_t mFramesToDrop; 92 93 // used by resampler to find source frames 94 ResamplerBufferProvider *mResamplerBufferProvider; 95}; 96