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 23 class RecordTrack : public TrackBase { 24 public: 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 void *buffer, 32 audio_session_t sessionId, 33 int uid, 34 audio_input_flags_t flags, 35 track_type type); 36 virtual ~RecordTrack(); 37 virtual status_t initCheck() const; 38 39 virtual status_t start(AudioSystem::sync_event_t event, audio_session_t triggerSession); 40 virtual void stop(); 41 42 void destroy(); 43 44 void invalidate(); 45 // clear the buffer overflow flag clearOverflow()46 void clearOverflow() { mOverflow = false; } 47 // set the buffer overflow flag and return previous value setOverflow()48 bool setOverflow() { bool tmp = mOverflow; mOverflow = true; 49 return tmp; } 50 51 static void appendDumpHeader(String8& result); 52 void dump(char* buffer, size_t size, bool active); 53 54 void handleSyncStartEvent(const sp<SyncEvent>& event); 55 void clearSyncStartEvent(); 56 57 void updateTrackFrameInfo(int64_t trackFramesReleased, 58 int64_t sourceFramesRead, 59 uint32_t halSampleRate, 60 const ExtendedTimestamp ×tamp); 61 isFastTrack()62 virtual bool isFastTrack() const { return (mFlags & AUDIO_INPUT_FLAG_FAST) != 0; } 63 64 private: 65 friend class AudioFlinger; // for mState 66 67 RecordTrack(const RecordTrack&); 68 RecordTrack& operator = (const RecordTrack&); 69 70 // AudioBufferProvider interface 71 virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); 72 // releaseBuffer() not overridden 73 74 bool mOverflow; // overflow on most recent attempt to fill client buffer 75 76 AudioBufferProvider::Buffer mSink; // references client's buffer sink in shared memory 77 78 // sync event triggering actual audio capture. Frames read before this event will 79 // be dropped and therefore not read by the application. 80 sp<SyncEvent> mSyncStartEvent; 81 82 // number of captured frames to drop after the start sync event has been received. 83 // when < 0, maximum frames to drop before starting capture even if sync event is 84 // not received 85 ssize_t mFramesToDrop; 86 87 // used by resampler to find source frames 88 ResamplerBufferProvider *mResamplerBufferProvider; 89 90 // used by the record thread to convert frames to proper destination format 91 RecordBufferConverter *mRecordBufferConverter; 92 audio_input_flags_t mFlags; 93 }; 94 95 // playback track, used by PatchPanel 96 class PatchRecord : virtual public RecordTrack, public PatchProxyBufferProvider { 97 public: 98 99 PatchRecord(RecordThread *recordThread, 100 uint32_t sampleRate, 101 audio_channel_mask_t channelMask, 102 audio_format_t format, 103 size_t frameCount, 104 void *buffer, 105 audio_input_flags_t flags); 106 virtual ~PatchRecord(); 107 108 // AudioBufferProvider interface 109 virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); 110 virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer); 111 112 // PatchProxyBufferProvider interface 113 virtual status_t obtainBuffer(Proxy::Buffer *buffer, 114 const struct timespec *timeOut = NULL); 115 virtual void releaseBuffer(Proxy::Buffer *buffer); 116 setPeerProxy(PatchProxyBufferProvider * proxy)117 void setPeerProxy(PatchProxyBufferProvider *proxy) { mPeerProxy = proxy; } 118 119 private: 120 sp<ClientProxy> mProxy; 121 PatchProxyBufferProvider* mPeerProxy; 122 struct timespec mPeerTimeout; 123 }; // end of PatchRecord 124