1afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber/*
2afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber * Copyright (C) 2012 The Android Open Source Project
3afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber *
4afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
5afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber * you may not use this file except in compliance with the License.
6afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber * You may obtain a copy of the License at
7afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber *
8afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
9afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber *
10afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber * Unless required by applicable law or agreed to in writing, software
11afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
12afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber * See the License for the specific language governing permissions and
14afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber * limitations under the License.
15afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber */
16afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
17afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber#ifndef GENERIC_SOURCE_H_
18afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
19afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber#define GENERIC_SOURCE_H_
20afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
21afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber#include "NuPlayer.h"
22afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber#include "NuPlayerSource.h"
23afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
24afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber#include "ATSParser.h"
25afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
263423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih#include <media/mediaplayer.h>
273423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih
28afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Hubernamespace android {
29afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
30802768790c131f8237364906fd13981a6bb91193Ronghua Wuclass DecryptHandle;
31802768790c131f8237364906fd13981a6bb91193Ronghua Wuclass DrmManagerClient;
32afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huberstruct AnotherPacketSource;
33afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huberstruct ARTSPController;
34ee4e1b1a63758941460ae79a064249d3a5189443Lajos Molnarclass DataSource;
35ee4e1b1a63758941460ae79a064249d3a5189443Lajos Molnarclass IDataSource;
36bf9b95d712a24b654761cb9fea0d94d383cfc661Chong Zhangstruct IMediaHTTPService;
37afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huberstruct MediaSource;
383423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shihclass MediaBuffer;
39d354d8d1b09503c0166c1f3e626cda72a3eeb83cChong Zhangstruct NuCachedSource2;
40ee4e1b1a63758941460ae79a064249d3a5189443Lajos Molnarclass WVMExtractor;
41afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
42afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huberstruct NuPlayer::GenericSource : public NuPlayer::Source {
433de157dd8f9cd45bf9b0406268f5830887105ae1Chong Zhang    GenericSource(const sp<AMessage> &notify, bool uidValid, uid_t uid);
443de157dd8f9cd45bf9b0406268f5830887105ae1Chong Zhang
45bf9b95d712a24b654761cb9fea0d94d383cfc661Chong Zhang    status_t setDataSource(
461b86fe063badb5f28c467ade39be0f4008688947Andreas Huber            const sp<IMediaHTTPService> &httpService,
47afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber            const char *url,
483de157dd8f9cd45bf9b0406268f5830887105ae1Chong Zhang            const KeyedVector<String8, String8> *headers);
49afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
50bf9b95d712a24b654761cb9fea0d94d383cfc661Chong Zhang    status_t setDataSource(int fd, int64_t offset, int64_t length);
51afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
5299f31604136d66ae10e20669fb6b5716f342bde0Chris Watkins    status_t setDataSource(const sp<DataSource>& dataSource);
5399f31604136d66ae10e20669fb6b5716f342bde0Chris Watkins
549575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber    virtual void prepareAsync();
559575c96b6e418914e2ffc6741ecc8d71e3968dbeAndreas Huber
56afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    virtual void start();
57802768790c131f8237364906fd13981a6bb91193Ronghua Wu    virtual void stop();
58802768790c131f8237364906fd13981a6bb91193Ronghua Wu    virtual void pause();
59802768790c131f8237364906fd13981a6bb91193Ronghua Wu    virtual void resume();
60afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
6148296b792a8d68358de74141fa80bd5bd84d0307Chong Zhang    virtual void disconnect();
6248296b792a8d68358de74141fa80bd5bd84d0307Chong Zhang
63afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    virtual status_t feedMoreTSData();
64afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
65f0b72b509ab1147a2a0925aced970dd68fd7fa4fMarco Nelissen    virtual sp<MetaData> getFileFormatMeta() const;
66f0b72b509ab1147a2a0925aced970dd68fd7fa4fMarco Nelissen
67afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
68afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
69afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    virtual status_t getDuration(int64_t *durationUs);
70dd235727a1b4e283deeb581559f99c2c8889da07Robert Shih    virtual size_t getTrackCount() const;
71dd235727a1b4e283deeb581559f99c2c8889da07Robert Shih    virtual sp<AMessage> getTrackInfo(size_t trackIndex) const;
72e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar    virtual ssize_t getSelectedTrack(media_track_type type) const;
736ffb1fd67eb8f00f130a6db914ba42a8432aec70Robert Shih    virtual status_t selectTrack(size_t trackIndex, bool select, int64_t timeUs);
74afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    virtual status_t seekTo(int64_t seekTimeUs);
75b7c8e91880463ff4981e3e53e98e45d68e2fe374Andreas Huber
76cc227036b05f7c2f960a89c567a61f9decefe742Lajos Molnar    virtual status_t setBuffers(bool audio, Vector<MediaBuffer *> &buffers);
77cc227036b05f7c2f960a89c567a61f9decefe742Lajos Molnar
7802cb98d726b97d8e6dbb9c6c60d32a3cedc7f82dRonghua Wu    virtual bool isStreaming() const;
7902cb98d726b97d8e6dbb9c6c60d32a3cedc7f82dRonghua Wu
8014532f2383c3849d0db59a607ed0bd802f57155cWei Jia    virtual void setOffloadAudio(bool offload);
8114532f2383c3849d0db59a607ed0bd802f57155cWei Jia
82afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huberprotected:
83afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    virtual ~GenericSource();
84afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
853423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih    virtual void onMessageReceived(const sp<AMessage> &msg);
863423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih
87840667883fd09d44015716d79bc3ac4d60edc0f0Andreas Huber    virtual sp<MetaData> getFormatMeta(bool audio);
88840667883fd09d44015716d79bc3ac4d60edc0f0Andreas Huber
89afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huberprivate:
903423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih    enum {
911228d6b175de8b21787cbe0c6c4bb5642f4d555eChong Zhang        kWhatPrepareAsync,
923423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih        kWhatFetchSubtitleData,
93e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar        kWhatFetchTimedTextData,
943423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih        kWhatSendSubtitleData,
9555e2f4ca5bb23ce32fbdd627b0f648c27106b98eMarco Nelissen        kWhatSendGlobalTimedTextData,
96e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar        kWhatSendTimedTextData,
973423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih        kWhatChangeAVSource,
982a3cc9a64330dd36e466fe5e1b634146f2d641c1Chong Zhang        kWhatPollBuffering,
9917f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih        kWhatGetFormat,
10017f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih        kWhatGetSelectedTrack,
10117f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih        kWhatSelectTrack,
10217f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih        kWhatSeek,
10317f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih        kWhatReadBuffer,
1042abde2c118a94f843a7450818c925d3f0b673cd3Andy Hung        kWhatStopWidevine,
105efbb61950db36a5eb789be83f077246172507c67Chong Zhang        kWhatStart,
106efbb61950db36a5eb789be83f077246172507c67Chong Zhang        kWhatResume,
107fcd3e94c075e964670d946f6ec5d82d059bf9e09Lajos Molnar        kWhatSecureDecodersInstantiated,
1083423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih    };
1093423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih
110afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    struct Track {
111dd235727a1b4e283deeb581559f99c2c8889da07Robert Shih        size_t mIndex;
112b2487f03f12dcafdb801fc0007c8df8412397f44Marco Nelissen        sp<IMediaSource> mSource;
113afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber        sp<AnotherPacketSource> mPackets;
114afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    };
115afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
11614532f2383c3849d0db59a607ed0bd802f57155cWei Jia    // Helper to monitor buffering status. The polling happens every second.
11714532f2383c3849d0db59a607ed0bd802f57155cWei Jia    // When necessary, it will send out buffering events to the player.
11814532f2383c3849d0db59a607ed0bd802f57155cWei Jia    struct BufferingMonitor : public AHandler {
11914532f2383c3849d0db59a607ed0bd802f57155cWei Jia    public:
12014532f2383c3849d0db59a607ed0bd802f57155cWei Jia        BufferingMonitor(const sp<AMessage> &notify);
12114532f2383c3849d0db59a607ed0bd802f57155cWei Jia
12214532f2383c3849d0db59a607ed0bd802f57155cWei Jia        // Set up state.
12314532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void prepare(const sp<NuCachedSource2> &cachedSource,
12414532f2383c3849d0db59a607ed0bd802f57155cWei Jia                const sp<WVMExtractor> &wvmExtractor,
12514532f2383c3849d0db59a607ed0bd802f57155cWei Jia                int64_t durationUs,
12614532f2383c3849d0db59a607ed0bd802f57155cWei Jia                int64_t bitrate,
12714532f2383c3849d0db59a607ed0bd802f57155cWei Jia                bool isStreaming);
12814532f2383c3849d0db59a607ed0bd802f57155cWei Jia        // Stop and reset buffering monitor.
12914532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void stop();
13014532f2383c3849d0db59a607ed0bd802f57155cWei Jia        // Cancel the current monitor task.
13114532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void cancelPollBuffering();
13214532f2383c3849d0db59a607ed0bd802f57155cWei Jia        // Restart the monitor task.
13314532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void restartPollBuffering();
13414532f2383c3849d0db59a607ed0bd802f57155cWei Jia        // Stop buffering task and send out corresponding events.
13514532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void stopBufferingIfNecessary();
13614532f2383c3849d0db59a607ed0bd802f57155cWei Jia        // Make sure data source is getting data.
13714532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void ensureCacheIsFetching();
13814532f2383c3849d0db59a607ed0bd802f57155cWei Jia        // Update media time of just extracted buffer from data source.
13914532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void updateQueuedTime(bool isAudio, int64_t timeUs);
14014532f2383c3849d0db59a607ed0bd802f57155cWei Jia
14114532f2383c3849d0db59a607ed0bd802f57155cWei Jia        // Set the offload mode.
14214532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void setOffloadAudio(bool offload);
14314532f2383c3849d0db59a607ed0bd802f57155cWei Jia        // Update media time of last dequeued buffer which is sent to the decoder.
14414532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void updateDequeuedBufferTime(int64_t mediaUs);
14514532f2383c3849d0db59a607ed0bd802f57155cWei Jia
14614532f2383c3849d0db59a607ed0bd802f57155cWei Jia    protected:
14714532f2383c3849d0db59a607ed0bd802f57155cWei Jia        virtual ~BufferingMonitor();
14814532f2383c3849d0db59a607ed0bd802f57155cWei Jia        virtual void onMessageReceived(const sp<AMessage> &msg);
14914532f2383c3849d0db59a607ed0bd802f57155cWei Jia
15014532f2383c3849d0db59a607ed0bd802f57155cWei Jia    private:
15114532f2383c3849d0db59a607ed0bd802f57155cWei Jia        enum {
15214532f2383c3849d0db59a607ed0bd802f57155cWei Jia            kWhatPollBuffering,
15314532f2383c3849d0db59a607ed0bd802f57155cWei Jia        };
15414532f2383c3849d0db59a607ed0bd802f57155cWei Jia
15514532f2383c3849d0db59a607ed0bd802f57155cWei Jia        sp<AMessage> mNotify;
15614532f2383c3849d0db59a607ed0bd802f57155cWei Jia
15714532f2383c3849d0db59a607ed0bd802f57155cWei Jia        sp<NuCachedSource2> mCachedSource;
15814532f2383c3849d0db59a607ed0bd802f57155cWei Jia        sp<WVMExtractor> mWVMExtractor;
15914532f2383c3849d0db59a607ed0bd802f57155cWei Jia        int64_t mDurationUs;
16014532f2383c3849d0db59a607ed0bd802f57155cWei Jia        int64_t mBitrate;
16114532f2383c3849d0db59a607ed0bd802f57155cWei Jia        bool mIsStreaming;
16214532f2383c3849d0db59a607ed0bd802f57155cWei Jia
16314532f2383c3849d0db59a607ed0bd802f57155cWei Jia        int64_t mAudioTimeUs;
16414532f2383c3849d0db59a607ed0bd802f57155cWei Jia        int64_t mVideoTimeUs;
16514532f2383c3849d0db59a607ed0bd802f57155cWei Jia        int32_t mPollBufferingGeneration;
16614532f2383c3849d0db59a607ed0bd802f57155cWei Jia        bool mPrepareBuffering;
16714532f2383c3849d0db59a607ed0bd802f57155cWei Jia        bool mBuffering;
16814532f2383c3849d0db59a607ed0bd802f57155cWei Jia        int32_t mPrevBufferPercentage;
16914532f2383c3849d0db59a607ed0bd802f57155cWei Jia
17014532f2383c3849d0db59a607ed0bd802f57155cWei Jia        mutable Mutex mLock;
17114532f2383c3849d0db59a607ed0bd802f57155cWei Jia
17214532f2383c3849d0db59a607ed0bd802f57155cWei Jia        bool mOffloadAudio;
17314532f2383c3849d0db59a607ed0bd802f57155cWei Jia        int64_t mFirstDequeuedBufferRealUs;
17414532f2383c3849d0db59a607ed0bd802f57155cWei Jia        int64_t mFirstDequeuedBufferMediaUs;
17514532f2383c3849d0db59a607ed0bd802f57155cWei Jia        int64_t mlastDequeuedBufferMediaUs;
17614532f2383c3849d0db59a607ed0bd802f57155cWei Jia
17714532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void prepare_l(const sp<NuCachedSource2> &cachedSource,
17814532f2383c3849d0db59a607ed0bd802f57155cWei Jia                const sp<WVMExtractor> &wvmExtractor,
17914532f2383c3849d0db59a607ed0bd802f57155cWei Jia                int64_t durationUs,
18014532f2383c3849d0db59a607ed0bd802f57155cWei Jia                int64_t bitrate,
18114532f2383c3849d0db59a607ed0bd802f57155cWei Jia                bool isStreaming);
18214532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void cancelPollBuffering_l();
18314532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void notifyBufferingUpdate_l(int32_t percentage);
18414532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void startBufferingIfNecessary_l();
18514532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void stopBufferingIfNecessary_l();
18614532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void sendCacheStats_l();
18714532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void ensureCacheIsFetching_l();
18814532f2383c3849d0db59a607ed0bd802f57155cWei Jia        int64_t getLastReadPosition_l();
18914532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void onPollBuffering_l();
19014532f2383c3849d0db59a607ed0bd802f57155cWei Jia        void schedulePollBuffering_l();
19114532f2383c3849d0db59a607ed0bd802f57155cWei Jia    };
19214532f2383c3849d0db59a607ed0bd802f57155cWei Jia
193b2487f03f12dcafdb801fc0007c8df8412397f44Marco Nelissen    Vector<sp<IMediaSource> > mSources;
194afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    Track mAudioTrack;
195802768790c131f8237364906fd13981a6bb91193Ronghua Wu    int64_t mAudioTimeUs;
1965c67ddcf987b1f07c9abc1d051a0c051e7c73ff7Robert Shih    int64_t mAudioLastDequeueTimeUs;
197afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    Track mVideoTrack;
198802768790c131f8237364906fd13981a6bb91193Ronghua Wu    int64_t mVideoTimeUs;
1995c67ddcf987b1f07c9abc1d051a0c051e7c73ff7Robert Shih    int64_t mVideoLastDequeueTimeUs;
2003423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih    Track mSubtitleTrack;
201e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar    Track mTimedTextTrack;
202afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
2033423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih    int32_t mFetchSubtitleDataGeneration;
204e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar    int32_t mFetchTimedTextDataGeneration;
205afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    int64_t mDurationUs;
206afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    bool mAudioIsVorbis;
207cc227036b05f7c2f960a89c567a61f9decefe742Lajos Molnar    bool mIsWidevine;
20842e8153cf7271b572e4a94ade332b68521977f36Chong Zhang    bool mIsSecure;
209efbb61950db36a5eb789be83f077246172507c67Chong Zhang    bool mIsStreaming;
210cc227036b05f7c2f960a89c567a61f9decefe742Lajos Molnar    bool mUIDValid;
211cc227036b05f7c2f960a89c567a61f9decefe742Lajos Molnar    uid_t mUID;
212bf9b95d712a24b654761cb9fea0d94d383cfc661Chong Zhang    sp<IMediaHTTPService> mHTTPService;
213bf9b95d712a24b654761cb9fea0d94d383cfc661Chong Zhang    AString mUri;
214bf9b95d712a24b654761cb9fea0d94d383cfc661Chong Zhang    KeyedVector<String8, String8> mUriHeaders;
215bf9b95d712a24b654761cb9fea0d94d383cfc661Chong Zhang    int mFd;
216bf9b95d712a24b654761cb9fea0d94d383cfc661Chong Zhang    int64_t mOffset;
217bf9b95d712a24b654761cb9fea0d94d383cfc661Chong Zhang    int64_t mLength;
218bf9b95d712a24b654761cb9fea0d94d383cfc661Chong Zhang
219d354d8d1b09503c0166c1f3e626cda72a3eeb83cChong Zhang    sp<DataSource> mDataSource;
220d354d8d1b09503c0166c1f3e626cda72a3eeb83cChong Zhang    sp<NuCachedSource2> mCachedSource;
221360d6d0924f99b82ebacb5cfb6f7bca95e11b4eeRobert Shih    sp<DataSource> mHttpSource;
2222a3cc9a64330dd36e466fe5e1b634146f2d641c1Chong Zhang    sp<WVMExtractor> mWVMExtractor;
223f0b72b509ab1147a2a0925aced970dd68fd7fa4fMarco Nelissen    sp<MetaData> mFileMeta;
224802768790c131f8237364906fd13981a6bb91193Ronghua Wu    DrmManagerClient *mDrmManagerClient;
225802768790c131f8237364906fd13981a6bb91193Ronghua Wu    sp<DecryptHandle> mDecryptHandle;
226802768790c131f8237364906fd13981a6bb91193Ronghua Wu    bool mStarted;
2272abde2c118a94f843a7450818c925d3f0b673cd3Andy Hung    bool mStopRead;
2282a3cc9a64330dd36e466fe5e1b634146f2d641c1Chong Zhang    int64_t mBitrate;
22914532f2383c3849d0db59a607ed0bd802f57155cWei Jia    sp<BufferingMonitor> mBufferingMonitor;
23084f5278a36f2816cc38f64307b4a1ad8a6818507Lajos Molnar    uint32_t mPendingReadBufferTypes;
23155e2f4ca5bb23ce32fbdd627b0f648c27106b98eMarco Nelissen    sp<ABuffer> mGlobalTimedText;
232c287cad65bd0c7a79e43f4decc5e04593027a7c8Chong Zhang
23384f5278a36f2816cc38f64307b4a1ad8a6818507Lajos Molnar    mutable Mutex mReadBufferLock;
234ebc2712d5e8a66f8d6652e7cc7fb14cdbec7f235Robert Shih    mutable Mutex mDisconnectLock;
2351228d6b175de8b21787cbe0c6c4bb5642f4d555eChong Zhang
236d354d8d1b09503c0166c1f3e626cda72a3eeb83cChong Zhang    sp<ALooper> mLooper;
23714532f2383c3849d0db59a607ed0bd802f57155cWei Jia    sp<ALooper> mBufferingMonitorLooper;
2381228d6b175de8b21787cbe0c6c4bb5642f4d555eChong Zhang
239bf9b95d712a24b654761cb9fea0d94d383cfc661Chong Zhang    void resetDataSource();
240afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
241d354d8d1b09503c0166c1f3e626cda72a3eeb83cChong Zhang    status_t initFromDataSource();
242802768790c131f8237364906fd13981a6bb91193Ronghua Wu    void checkDrmStatus(const sp<DataSource>& dataSource);
243802768790c131f8237364906fd13981a6bb91193Ronghua Wu    int64_t getLastReadPosition();
244802768790c131f8237364906fd13981a6bb91193Ronghua Wu    void setDrmPlaybackStatusIfNeeded(int playbackStatus, int64_t position);
245d354d8d1b09503c0166c1f3e626cda72a3eeb83cChong Zhang
246d354d8d1b09503c0166c1f3e626cda72a3eeb83cChong Zhang    void notifyPreparedAndCleanup(status_t err);
247fcd3e94c075e964670d946f6ec5d82d059bf9e09Lajos Molnar    void onSecureDecodersInstantiated(status_t err);
248fcd3e94c075e964670d946f6ec5d82d059bf9e09Lajos Molnar    void finishPrepareAsync();
249fcd3e94c075e964670d946f6ec5d82d059bf9e09Lajos Molnar    status_t startSources();
250afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
25117f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih    void onGetFormatMeta(sp<AMessage> msg) const;
25217f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih    sp<MetaData> doGetFormatMeta(bool audio) const;
25317f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih
25417f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih    void onGetSelectedTrack(sp<AMessage> msg) const;
25517f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih    ssize_t doGetSelectedTrack(media_track_type type) const;
25617f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih
25717f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih    void onSelectTrack(sp<AMessage> msg);
2586ffb1fd67eb8f00f130a6db914ba42a8432aec70Robert Shih    status_t doSelectTrack(size_t trackIndex, bool select, int64_t timeUs);
25917f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih
26017f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih    void onSeek(sp<AMessage> msg);
26117f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih    status_t doSeek(int64_t seekTimeUs);
26217f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih
2631228d6b175de8b21787cbe0c6c4bb5642f4d555eChong Zhang    void onPrepareAsync();
2641228d6b175de8b21787cbe0c6c4bb5642f4d555eChong Zhang
265e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar    void fetchTextData(
266e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar            uint32_t what, media_track_type type,
267e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar            int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);
268e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar
26955e2f4ca5bb23ce32fbdd627b0f648c27106b98eMarco Nelissen    void sendGlobalTextData(
27055e2f4ca5bb23ce32fbdd627b0f648c27106b98eMarco Nelissen            uint32_t what,
27155e2f4ca5bb23ce32fbdd627b0f648c27106b98eMarco Nelissen            int32_t curGen, sp<AMessage> msg);
27255e2f4ca5bb23ce32fbdd627b0f648c27106b98eMarco Nelissen
273e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar    void sendTextData(
274e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar            uint32_t what, media_track_type type,
275e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar            int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);
276e26940f11c3f2040bced09f06a8f374b50c985fbLajos Molnar
2773423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih    sp<ABuffer> mediaBufferToABuffer(
2783423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih            MediaBuffer *mbuf,
2793423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih            media_track_type trackType,
280474d7c778b63aa33dcf25a92e23a52c1c47f0ac1Wei Jia            int64_t seekTimeUs,
2813423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih            int64_t *actualTimeUs = NULL);
2823423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih
28317f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih    void postReadBuffer(media_track_type trackType);
28417f6dd64cd749f4e38e12b672b551047f4cbe9b4Robert Shih    void onReadBuffer(sp<AMessage> msg);
285afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    void readBuffer(
2863423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih            media_track_type trackType,
2873423bbdb05f843a64356fa24e8657f03ecbb7d65Robert Shih            int64_t seekTimeUs = -1ll, int64_t *actualTimeUs = NULL, bool formatChange = false);
288afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
2898f291bc99e92015ebb959654a73c87e98bd46958Ronghua Wu    void queueDiscontinuityIfNeeded(
2908f291bc99e92015ebb959654a73c87e98bd46958Ronghua Wu            bool seeking, bool formatChange, media_track_type trackType, Track *track);
2918f291bc99e92015ebb959654a73c87e98bd46958Ronghua Wu
292afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber    DISALLOW_EVIL_CONSTRUCTORS(GenericSource);
293afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber};
294afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
295afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber}  // namespace android
296afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber
297afed0e1fa37473a4cd30018577b560acc79d9a3fAndreas Huber#endif  // GENERIC_SOURCE_H_
298