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