PlaybackTracks.h revision 20b9ef0b55c9150ae11057ab997ae61be2d496ef
181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent/*
281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent**
381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent** Copyright 2012, The Android Open Source Project
481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent**
581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent** Licensed under the Apache License, Version 2.0 (the "License");
681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent** you may not use this file except in compliance with the License.
781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent** You may obtain a copy of the License at
881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent**
981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent**     http://www.apache.org/licenses/LICENSE-2.0
1081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent**
1181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent** Unless required by applicable law or agreed to in writing, software
1281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent** distributed under the License is distributed on an "AS IS" BASIS,
1381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent** See the License for the specific language governing permissions and
1581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent** limitations under the License.
1681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent*/
1781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
1881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent#ifndef INCLUDING_FROM_AUDIOFLINGER_H
1981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    #error This header file should only be included from AudioFlinger.h
2081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent#endif
2181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
2281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// playback track
2381784c37c61b09289654b979567a42bf73cd2b12Eric Laurentclass Track : public TrackBase, public VolumeProvider {
2481784c37c61b09289654b979567a42bf73cd2b12Eric Laurentpublic:
2581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                        Track(  PlaybackThread *thread,
2681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                const sp<Client>& client,
2781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                audio_stream_type_t streamType,
2881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                uint32_t sampleRate,
2981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                audio_format_t format,
3081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                audio_channel_mask_t channelMask,
3181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                size_t frameCount,
3283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent                                void *buffer,
3381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                const sp<IMemory>& sharedBuffer,
34d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten                                audio_session_t sessionId,
351f12a8ad958344c50733b948628ffa06db9c5bc6Andy Hung                                uid_t uid,
36050677873c10d4da308ac222f8533c96cca3207eEric Laurent                                audio_output_flags_t flags,
3720b9ef0b55c9150ae11057ab997ae61be2d496efEric Laurent                                track_type type,
3820b9ef0b55c9150ae11057ab997ae61be2d496efEric Laurent                                audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE);
3981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    virtual             ~Track();
40030033342a6ea17003e6af38a56c7edc6d2ead01Glenn Kasten    virtual status_t    initCheck() const;
4181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
4281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    static  void        appendDumpHeader(String8& result);
43b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen            void        dump(char* buffer, size_t size, bool active);
4481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    virtual status_t    start(AudioSystem::sync_event_t event =
4581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    AudioSystem::SYNC_EVENT_NONE,
46d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten                             audio_session_t triggerSession = AUDIO_SESSION_NONE);
4781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    virtual void        stop();
4881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            void        pause();
4981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
5081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            void        flush();
5181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            void        destroy();
5281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            int         name() const { return mName; }
5381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
549f80dd223d83d9bb9077fb6baee056cee4eaf7e5Glenn Kasten    virtual uint32_t    sampleRate() const;
559f80dd223d83d9bb9077fb6baee056cee4eaf7e5Glenn Kasten
5681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            audio_stream_type_t streamType() const {
5781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                return mStreamType;
5881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            }
59050677873c10d4da308ac222f8533c96cca3207eEric Laurent            bool        isOffloaded() const
60050677873c10d4da308ac222f8533c96cca3207eEric Laurent                                { return (mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0; }
61050677873c10d4da308ac222f8533c96cca3207eEric Laurent            bool        isDirect() const { return (mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0; }
62bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent            status_t    setParameters(const String8& keyValuePairs);
6381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            status_t    attachAuxEffect(int EffectId);
6481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            void        setAuxBuffer(int EffectId, int32_t *buffer);
6581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            int32_t     *auxBuffer() const { return mAuxBuffer; }
6681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            void        setMainBuffer(int16_t *buffer) { mMainBuffer = buffer; }
6781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            int16_t     *mainBuffer() const { return mMainBuffer; }
6881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            int         auxEffectId() const { return mAuxEffectId; }
69573d80a8f463f648a515fc0975bf83951b272993Glenn Kasten    virtual status_t    getTimestamp(AudioTimestamp& timestamp);
7059fe010bcc072597852454a2ec53d7b0a2002a3bEric Laurent            void        signal();
7181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
7281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// implement FastMixerState::VolumeProvider interface
73c56f3426099a3cf2d07ccff8886050c7fbce140fGlenn Kasten    virtual gain_minifloat_packed_t getVolumeLR();
7481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
7581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    virtual status_t    setSyncEvent(const sp<SyncEvent>& event);
7681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
77050677873c10d4da308ac222f8533c96cca3207eEric Laurent    virtual bool        isFastTrack() const { return (mFlags & AUDIO_OUTPUT_FLAG_FAST) != 0; }
78050677873c10d4da308ac222f8533c96cca3207eEric Laurent
7981784c37c61b09289654b979567a42bf73cd2b12Eric Laurentprotected:
8081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    // for numerous
8181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    friend class PlaybackThread;
8281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    friend class MixerThread;
8381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    friend class DirectOutputThread;
84bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent    friend class OffloadThread;
8581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
8681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                        Track(const Track&);
8781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                        Track& operator = (const Track&);
8881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
8981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    // AudioBufferProvider interface
90d79072e9dff59f767cce2cda1caab80ce5a0815bGlenn Kasten    virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer);
9181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    // releaseBuffer() not overridden
9281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
936466c9e6e6278c740aed77f695f679be9f5db478Glenn Kasten    // ExtendedAudioBufferProvider interface
9481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    virtual size_t framesReady() const;
95818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung    virtual int64_t framesReleased() const;
96818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung    virtual void onTimestamp(const ExtendedTimestamp &timestamp);
9781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
98c9b2e20f7c9a71e07ef398152709c76079decbcdGlenn Kasten    bool isPausing() const { return mState == PAUSING; }
99c9b2e20f7c9a71e07ef398152709c76079decbcdGlenn Kasten    bool isPaused() const { return mState == PAUSED; }
100c9b2e20f7c9a71e07ef398152709c76079decbcdGlenn Kasten    bool isResuming() const { return mState == RESUMING; }
10181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    bool isReady() const;
10281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    void setPaused() { mState = PAUSED; }
10381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    void reset();
1047844f679be8d94c5cdf017f53754cb68ee2f00daHaynes Mathew George    bool isFlushPending() const { return mFlushHwPending; }
1057844f679be8d94c5cdf017f53754cb68ee2f00daHaynes Mathew George    void flushAck();
1068d6c292a0bed3d63b5b7297d09a604af6327c663Krishnankutty Kolathappilly    bool isResumePending();
1078d6c292a0bed3d63b5b7297d09a604af6327c663Krishnankutty Kolathappilly    void resumeAck();
108818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung    void updateTrackFrameInfo(int64_t trackFramesReleased, int64_t sinkFramesWritten,
109818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung            const ExtendedTimestamp &timeStamp);
11081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
11181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    sp<IMemory> sharedBuffer() const { return mSharedBuffer; }
11281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
11381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    // framesWritten is cumulative, never reset, and is shared all tracks
11481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    // audioHalFrames is derived from output latency
11581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    // FIXME parameters not needed, could get them from the thread
116818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung    bool presentationComplete(int64_t framesWritten, size_t audioHalFrames);
1174d231dc0ee34380956c71cbe18a750e487a69601Eric Laurent    void signalClientFlag(int32_t flag);
11881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
11981784c37c61b09289654b979567a42bf73cd2b12Eric Laurentpublic:
12081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    void triggerEvents(AudioSystem::sync_event_t type);
1215736c35b841de56ce394b4879389f669b61425e6Glenn Kasten    void invalidate();
1224d231dc0ee34380956c71cbe18a750e487a69601Eric Laurent    void disable();
1234d231dc0ee34380956c71cbe18a750e487a69601Eric Laurent
1245736c35b841de56ce394b4879389f669b61425e6Glenn Kasten    bool isInvalid() const { return mIsInvalid; }
125d054c32443a493513ab63529b0c8b1aca290278cGlenn Kasten    int fastIndex() const { return mFastIndex; }
12681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
12781784c37c61b09289654b979567a42bf73cd2b12Eric Laurentprotected:
12881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
12981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    // FILLED state is used for suppressing volume ramp at begin of playing
13081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    enum {FS_INVALID, FS_FILLING, FS_FILLED, FS_ACTIVE};
13181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    mutable uint8_t     mFillingUpStatus;
13281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    int8_t              mRetryCount;
1330c72b24f91c68442eb374bd1b338c394105b8262Glenn Kasten
1340c72b24f91c68442eb374bd1b338c394105b8262Glenn Kasten    // see comment at AudioFlinger::PlaybackThread::Track::~Track for why this can't be const
1350c72b24f91c68442eb374bd1b338c394105b8262Glenn Kasten    sp<IMemory>         mSharedBuffer;
1360c72b24f91c68442eb374bd1b338c394105b8262Glenn Kasten
13781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    bool                mResetDone;
13881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    const audio_stream_type_t mStreamType;
13981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    int                 mName;      // track name on the normal mixer,
14081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    // allocated statically at track creation time,
14181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    // and is even allocated (though unused) for fast tracks
14281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    // FIXME don't allocate track name for fast tracks
14381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    int16_t             *mMainBuffer;
14481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    int32_t             *mAuxBuffer;
14581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    int                 mAuxEffectId;
14681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    bool                mHasVolumeController;
14781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    size_t              mPresentationCompleteFrames; // number of frames written to the
14881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    // audio HAL when this track will be fully rendered
14981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    // zero means not monitoring
150e10393e72454bfd8298017dc193faf424f4e9a8fAndy Hung
151e10393e72454bfd8298017dc193faf424f4e9a8fAndy Hung    // access these three variables only when holding thread lock.
152818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung    LinearMap<int64_t> mFrameMap;           // track frame to server frame mapping
153818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung
154818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung    ExtendedTimestamp  mSinkTimestamp;
155e10393e72454bfd8298017dc193faf424f4e9a8fAndy Hung
15681784c37c61b09289654b979567a42bf73cd2b12Eric Laurentprivate:
15781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    // The following fields are only for fast tracks, and should be in a subclass
15881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    int                 mFastIndex; // index within FastMixerState::mFastTracks[];
15981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    // either mFastIndex == -1 if not isFastTrack()
16081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    // or 0 < mFastIndex < FastMixerState::kMaxFast because
16181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    // index 0 is reserved for normal mixer's submix;
16281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    // index is allocated statically at track creation time
16381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    // but the slot is only used if track is active
16481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    FastTrackUnderruns  mObservedUnderruns; // Most recently observed value of
16581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    // mFastMixerDumpState.mTracks[mFastIndex].mUnderruns
16681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    volatile float      mCachedVolume;  // combined master volume and stream type volume;
16781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                        // 'volatile' means accessed without lock or
16881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                        // barrier, but is read/written atomically
1695736c35b841de56ce394b4879389f669b61425e6Glenn Kasten    bool                mIsInvalid; // non-resettable latch, set by invalidate()
1705bba2f6916dbe00aea7c0521faa0c6ed42114a75Eric Laurent    sp<AudioTrackServerProxy>  mAudioTrackServerProxy;
171bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent    bool                mResumeToStopping; // track was paused in stopping state.
1727844f679be8d94c5cdf017f53754cb68ee2f00daHaynes Mathew George    bool                mFlushHwPending; // track requests for thread flush
173050677873c10d4da308ac222f8533c96cca3207eEric Laurent    audio_output_flags_t mFlags;
17481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent};  // end of Track
17581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
17681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
17781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// playback track, used by DuplicatingThread
17881784c37c61b09289654b979567a42bf73cd2b12Eric Laurentclass OutputTrack : public Track {
17981784c37c61b09289654b979567a42bf73cd2b12Eric Laurentpublic:
18081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
18181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    class Buffer : public AudioBufferProvider::Buffer {
18281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    public:
183c25b84abdd7ff229d0af663fbf3a37bd9512939dAndy Hung        void *mBuffer;
18481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    };
18581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
18681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                        OutputTrack(PlaybackThread *thread,
18781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                DuplicatingThread *sourceThread,
18881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                uint32_t sampleRate,
18981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                audio_format_t format,
19081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                audio_channel_mask_t channelMask,
191462fd2fa9eef642b0574aa7409de0bde3fec8d43Marco Nelissen                                size_t frameCount,
1921f12a8ad958344c50733b948628ffa06db9c5bc6Andy Hung                                uid_t uid);
19381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    virtual             ~OutputTrack();
19481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
19581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    virtual status_t    start(AudioSystem::sync_event_t event =
19681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                    AudioSystem::SYNC_EVENT_NONE,
197d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten                             audio_session_t triggerSession = AUDIO_SESSION_NONE);
19881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    virtual void        stop();
199c25b84abdd7ff229d0af663fbf3a37bd9512939dAndy Hung            bool        write(void* data, uint32_t frames);
20081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            bool        bufferQueueEmpty() const { return mBufferQueue.size() == 0; }
20181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent            bool        isActive() const { return mActive; }
20281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    const wp<ThreadBase>& thread() const { return mThread; }
20381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
20481784c37c61b09289654b979567a42bf73cd2b12Eric Laurentprivate:
20581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
20681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    status_t            obtainBuffer(AudioBufferProvider::Buffer* buffer,
20781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent                                     uint32_t waitTimeMs);
20881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    void                clearBufferQueue();
20981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
2104d231dc0ee34380956c71cbe18a750e487a69601Eric Laurent    void                restartIfDisabled();
2114d231dc0ee34380956c71cbe18a750e487a69601Eric Laurent
21281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    // Maximum number of pending buffers allocated by OutputTrack::write()
21381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    static const uint8_t kMaxOverFlowBuffers = 10;
21481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent
21581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    Vector < Buffer* >          mBufferQueue;
21681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    AudioBufferProvider::Buffer mOutBuffer;
21781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent    bool                        mActive;
2185bba2f6916dbe00aea7c0521faa0c6ed42114a75Eric Laurent    DuplicatingThread* const    mSourceThread; // for waitTimeMs() in write()
2195bba2f6916dbe00aea7c0521faa0c6ed42114a75Eric Laurent    sp<AudioTrackClientProxy>   mClientProxy;
22081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent};  // end of OutputTrack
22183b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent
22283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent// playback track, used by PatchPanel
22383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurentclass PatchTrack : public Track, public PatchProxyBufferProvider {
22483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurentpublic:
22583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent
22683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent                        PatchTrack(PlaybackThread *playbackThread,
2273bcf8597189c592713675ec58326ecbef0ac4ae9Eric Laurent                                   audio_stream_type_t streamType,
22883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent                                   uint32_t sampleRate,
22983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent                                   audio_channel_mask_t channelMask,
23083b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent                                   audio_format_t format,
23183b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent                                   size_t frameCount,
23283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent                                   void *buffer,
233050677873c10d4da308ac222f8533c96cca3207eEric Laurent                                   audio_output_flags_t flags);
23483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent    virtual             ~PatchTrack();
23583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent
2364d231dc0ee34380956c71cbe18a750e487a69601Eric Laurent    virtual status_t    start(AudioSystem::sync_event_t event =
2374d231dc0ee34380956c71cbe18a750e487a69601Eric Laurent                                    AudioSystem::SYNC_EVENT_NONE,
238d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten                             audio_session_t triggerSession = AUDIO_SESSION_NONE);
2394d231dc0ee34380956c71cbe18a750e487a69601Eric Laurent
24083b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent    // AudioBufferProvider interface
241d79072e9dff59f767cce2cda1caab80ce5a0815bGlenn Kasten    virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer);
24283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent    virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer);
24383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent
24483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent    // PatchProxyBufferProvider interface
24583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent    virtual status_t    obtainBuffer(Proxy::Buffer* buffer,
24683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent                                     const struct timespec *timeOut = NULL);
24783b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent    virtual void        releaseBuffer(Proxy::Buffer* buffer);
24883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent
24983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent            void setPeerProxy(PatchProxyBufferProvider *proxy) { mPeerProxy = proxy; }
25083b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent
25183b8808faad1e91690c64d7007348be8d9ebde73Eric Laurentprivate:
2524d231dc0ee34380956c71cbe18a750e487a69601Eric Laurent            void restartIfDisabled();
2534d231dc0ee34380956c71cbe18a750e487a69601Eric Laurent
25483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent    sp<ClientProxy>             mProxy;
25583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent    PatchProxyBufferProvider*   mPeerProxy;
25683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent    struct timespec             mPeerTimeout;
25783b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent};  // end of PatchTrack
258