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 const audio_attributes_t& attr, 28 uint32_t sampleRate, 29 audio_format_t format, 30 audio_channel_mask_t channelMask, 31 size_t frameCount, 32 void *buffer, 33 size_t bufferSize, 34 audio_session_t sessionId, 35 pid_t creatorPid, 36 uid_t uid, 37 audio_input_flags_t flags, 38 track_type type, 39 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE); 40 virtual ~RecordTrack(); 41 virtual status_t initCheck() const; 42 43 virtual status_t start(AudioSystem::sync_event_t event, audio_session_t triggerSession); 44 virtual void stop(); 45 46 void destroy(); 47 48 virtual void invalidate(); 49 // clear the buffer overflow flag 50 void clearOverflow() { mOverflow = false; } 51 // set the buffer overflow flag and return previous value 52 bool setOverflow() { bool tmp = mOverflow; mOverflow = true; 53 return tmp; } 54 55 void appendDumpHeader(String8& result); 56 void appendDump(String8& result, bool active); 57 58 void handleSyncStartEvent(const sp<SyncEvent>& event); 59 void clearSyncStartEvent(); 60 61 void updateTrackFrameInfo(int64_t trackFramesReleased, 62 int64_t sourceFramesRead, 63 uint32_t halSampleRate, 64 const ExtendedTimestamp ×tamp); 65 66 virtual bool isFastTrack() const { return (mFlags & AUDIO_INPUT_FLAG_FAST) != 0; } 67 bool isDirect() const override 68 { return (mFlags & AUDIO_INPUT_FLAG_DIRECT) != 0; } 69 70 void setSilenced(bool silenced) { if (!isPatchTrack()) mSilenced = silenced; } 71 bool isSilenced() const { return mSilenced; } 72 73 status_t getActiveMicrophones(std::vector<media::MicrophoneInfo>* activeMicrophones); 74 75 status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction); 76 status_t setPreferredMicrophoneFieldDimension(float zoom); 77 78 static bool checkServerLatencySupported( 79 audio_format_t format, audio_input_flags_t flags) { 80 return audio_is_linear_pcm(format) 81 && (flags & AUDIO_INPUT_FLAG_HW_AV_SYNC) == 0; 82 } 83 84 private: 85 friend class AudioFlinger; // for mState 86 87 DISALLOW_COPY_AND_ASSIGN(RecordTrack); 88 89 // AudioBufferProvider interface 90 virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); 91 // releaseBuffer() not overridden 92 93 bool mOverflow; // overflow on most recent attempt to fill client buffer 94 95 AudioBufferProvider::Buffer mSink; // references client's buffer sink in shared memory 96 97 // sync event triggering actual audio capture. Frames read before this event will 98 // be dropped and therefore not read by the application. 99 sp<SyncEvent> mSyncStartEvent; 100 101 // number of captured frames to drop after the start sync event has been received. 102 // when < 0, maximum frames to drop before starting capture even if sync event is 103 // not received 104 ssize_t mFramesToDrop; 105 106 // used by resampler to find source frames 107 ResamplerBufferProvider *mResamplerBufferProvider; 108 109 // used by the record thread to convert frames to proper destination format 110 RecordBufferConverter *mRecordBufferConverter; 111 audio_input_flags_t mFlags; 112 113 bool mSilenced; 114 }; 115 116 // playback track, used by PatchPanel 117 class PatchRecord : public RecordTrack, public PatchTrackBase { 118 public: 119 120 PatchRecord(RecordThread *recordThread, 121 uint32_t sampleRate, 122 audio_channel_mask_t channelMask, 123 audio_format_t format, 124 size_t frameCount, 125 void *buffer, 126 size_t bufferSize, 127 audio_input_flags_t flags, 128 const Timeout& timeout = {}); 129 virtual ~PatchRecord(); 130 131 // AudioBufferProvider interface 132 virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); 133 virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer); 134 135 // PatchProxyBufferProvider interface 136 virtual status_t obtainBuffer(Proxy::Buffer *buffer, 137 const struct timespec *timeOut = NULL); 138 virtual void releaseBuffer(Proxy::Buffer *buffer); 139 }; // end of PatchRecord 140