GenericSource.h revision 3de157dd8f9cd45bf9b0406268f5830887105ae1
1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef GENERIC_SOURCE_H_
18
19#define GENERIC_SOURCE_H_
20
21#include "NuPlayer.h"
22#include "NuPlayerSource.h"
23
24#include "ATSParser.h"
25
26#include <media/mediaplayer.h>
27
28namespace android {
29
30struct AnotherPacketSource;
31struct ARTSPController;
32struct DataSource;
33struct MediaSource;
34class MediaBuffer;
35
36struct NuPlayer::GenericSource : public NuPlayer::Source {
37    GenericSource(const sp<AMessage> &notify, bool uidValid, uid_t uid);
38
39    status_t init(
40            const sp<IMediaHTTPService> &httpService,
41            const char *url,
42            const KeyedVector<String8, String8> *headers);
43
44    status_t init(int fd, int64_t offset, int64_t length);
45
46    virtual void prepareAsync();
47
48    virtual void start();
49
50    virtual status_t feedMoreTSData();
51
52    virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
53
54    virtual status_t getDuration(int64_t *durationUs);
55    virtual size_t getTrackCount() const;
56    virtual sp<AMessage> getTrackInfo(size_t trackIndex) const;
57    virtual ssize_t getSelectedTrack(media_track_type type) const;
58    virtual status_t selectTrack(size_t trackIndex, bool select);
59    virtual status_t seekTo(int64_t seekTimeUs);
60
61    virtual status_t setBuffers(bool audio, Vector<MediaBuffer *> &buffers);
62
63protected:
64    virtual ~GenericSource();
65
66    virtual void onMessageReceived(const sp<AMessage> &msg);
67
68    virtual sp<MetaData> getFormatMeta(bool audio);
69
70private:
71    enum {
72        kWhatFetchSubtitleData,
73        kWhatFetchTimedTextData,
74        kWhatSendSubtitleData,
75        kWhatSendTimedTextData,
76        kWhatChangeAVSource,
77    };
78
79    Vector<sp<MediaSource> > mSources;
80
81    struct Track {
82        size_t mIndex;
83        sp<MediaSource> mSource;
84        sp<AnotherPacketSource> mPackets;
85    };
86
87    Track mAudioTrack;
88    Track mVideoTrack;
89    Track mSubtitleTrack;
90    Track mTimedTextTrack;
91
92    int32_t mFetchSubtitleDataGeneration;
93    int32_t mFetchTimedTextDataGeneration;
94    int64_t mDurationUs;
95    bool mAudioIsVorbis;
96    bool mIsWidevine;
97    bool mUIDValid;
98    uid_t mUID;
99
100    status_t initFromDataSource(
101            const sp<DataSource> &dataSource,
102            const char *mime);
103
104    void fetchTextData(
105            uint32_t what, media_track_type type,
106            int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);
107
108    void sendTextData(
109            uint32_t what, media_track_type type,
110            int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);
111
112    sp<ABuffer> mediaBufferToABuffer(
113            MediaBuffer *mbuf,
114            media_track_type trackType,
115            int64_t *actualTimeUs = NULL);
116
117    void readBuffer(
118            media_track_type trackType,
119            int64_t seekTimeUs = -1ll, int64_t *actualTimeUs = NULL, bool formatChange = false);
120
121    DISALLOW_EVIL_CONSTRUCTORS(GenericSource);
122};
123
124}  // namespace android
125
126#endif  // GENERIC_SOURCE_H_
127