blob: d3081de31e26623b9cfed60d0f6d409866a011a4 [file] [log] [blame]
Andreas Huberafed0e12011-09-20 15:39:58 -07001/*
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
Robert Shih3423bbd2014-07-16 15:47:09 -070026#include <media/mediaplayer.h>
27
Andreas Huberafed0e12011-09-20 15:39:58 -070028namespace android {
29
30struct AnotherPacketSource;
31struct ARTSPController;
32struct DataSource;
Chong Zhangbf9b95d2014-08-07 15:35:07 -070033struct IMediaHTTPService;
Andreas Huberafed0e12011-09-20 15:39:58 -070034struct MediaSource;
Robert Shih3423bbd2014-07-16 15:47:09 -070035class MediaBuffer;
Andreas Huberafed0e12011-09-20 15:39:58 -070036
37struct NuPlayer::GenericSource : public NuPlayer::Source {
Chong Zhang3de157d2014-08-05 20:54:44 -070038 GenericSource(const sp<AMessage> &notify, bool uidValid, uid_t uid);
39
Chong Zhangbf9b95d2014-08-07 15:35:07 -070040 status_t setDataSource(
Andreas Huber1b86fe02014-01-29 11:13:26 -080041 const sp<IMediaHTTPService> &httpService,
Andreas Huberafed0e12011-09-20 15:39:58 -070042 const char *url,
Chong Zhang3de157d2014-08-05 20:54:44 -070043 const KeyedVector<String8, String8> *headers);
Andreas Huberafed0e12011-09-20 15:39:58 -070044
Chong Zhangbf9b95d2014-08-07 15:35:07 -070045 status_t setDataSource(int fd, int64_t offset, int64_t length);
Andreas Huberafed0e12011-09-20 15:39:58 -070046
Andreas Huber9575c962013-02-05 13:59:56 -080047 virtual void prepareAsync();
48
Andreas Huberafed0e12011-09-20 15:39:58 -070049 virtual void start();
50
51 virtual status_t feedMoreTSData();
52
Andreas Huberafed0e12011-09-20 15:39:58 -070053 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
54
55 virtual status_t getDuration(int64_t *durationUs);
Robert Shihdd235722014-06-12 14:49:23 -070056 virtual size_t getTrackCount() const;
57 virtual sp<AMessage> getTrackInfo(size_t trackIndex) const;
Lajos Molnare26940f2014-07-31 10:31:26 -070058 virtual ssize_t getSelectedTrack(media_track_type type) const;
Robert Shih3423bbd2014-07-16 15:47:09 -070059 virtual status_t selectTrack(size_t trackIndex, bool select);
Andreas Huberafed0e12011-09-20 15:39:58 -070060 virtual status_t seekTo(int64_t seekTimeUs);
Andreas Huberb7c8e912012-11-27 15:02:53 -080061
Lajos Molnarcc227032014-07-17 15:33:06 -070062 virtual status_t setBuffers(bool audio, Vector<MediaBuffer *> &buffers);
63
Andreas Huberafed0e12011-09-20 15:39:58 -070064protected:
65 virtual ~GenericSource();
66
Robert Shih3423bbd2014-07-16 15:47:09 -070067 virtual void onMessageReceived(const sp<AMessage> &msg);
68
Andreas Huber84066782011-08-16 09:34:26 -070069 virtual sp<MetaData> getFormatMeta(bool audio);
70
Andreas Huberafed0e12011-09-20 15:39:58 -070071private:
Robert Shih3423bbd2014-07-16 15:47:09 -070072 enum {
Chong Zhang1228d6b2014-08-12 21:25:48 -070073 kWhatPrepareAsync,
Robert Shih3423bbd2014-07-16 15:47:09 -070074 kWhatFetchSubtitleData,
Lajos Molnare26940f2014-07-31 10:31:26 -070075 kWhatFetchTimedTextData,
Robert Shih3423bbd2014-07-16 15:47:09 -070076 kWhatSendSubtitleData,
Lajos Molnare26940f2014-07-31 10:31:26 -070077 kWhatSendTimedTextData,
Robert Shih3423bbd2014-07-16 15:47:09 -070078 kWhatChangeAVSource,
79 };
80
Robert Shihdd235722014-06-12 14:49:23 -070081 Vector<sp<MediaSource> > mSources;
82
Andreas Huberafed0e12011-09-20 15:39:58 -070083 struct Track {
Robert Shihdd235722014-06-12 14:49:23 -070084 size_t mIndex;
Andreas Huberafed0e12011-09-20 15:39:58 -070085 sp<MediaSource> mSource;
86 sp<AnotherPacketSource> mPackets;
87 };
88
89 Track mAudioTrack;
90 Track mVideoTrack;
Robert Shih3423bbd2014-07-16 15:47:09 -070091 Track mSubtitleTrack;
Lajos Molnare26940f2014-07-31 10:31:26 -070092 Track mTimedTextTrack;
Andreas Huberafed0e12011-09-20 15:39:58 -070093
Robert Shih3423bbd2014-07-16 15:47:09 -070094 int32_t mFetchSubtitleDataGeneration;
Lajos Molnare26940f2014-07-31 10:31:26 -070095 int32_t mFetchTimedTextDataGeneration;
Andreas Huberafed0e12011-09-20 15:39:58 -070096 int64_t mDurationUs;
97 bool mAudioIsVorbis;
Lajos Molnarcc227032014-07-17 15:33:06 -070098 bool mIsWidevine;
99 bool mUIDValid;
100 uid_t mUID;
Chong Zhangbf9b95d2014-08-07 15:35:07 -0700101 sp<IMediaHTTPService> mHTTPService;
102 AString mUri;
103 KeyedVector<String8, String8> mUriHeaders;
104 int mFd;
105 int64_t mOffset;
106 int64_t mLength;
107
Chong Zhang1228d6b2014-08-12 21:25:48 -0700108 sp<ALooper> mLooper;
109
110
Chong Zhangbf9b95d2014-08-07 15:35:07 -0700111 void resetDataSource();
Andreas Huberafed0e12011-09-20 15:39:58 -0700112
Chong Zhang3de157d2014-08-05 20:54:44 -0700113 status_t initFromDataSource(
114 const sp<DataSource> &dataSource,
115 const char *mime);
Andreas Huberafed0e12011-09-20 15:39:58 -0700116
Chong Zhang1228d6b2014-08-12 21:25:48 -0700117 void onPrepareAsync();
118
Lajos Molnare26940f2014-07-31 10:31:26 -0700119 void fetchTextData(
120 uint32_t what, media_track_type type,
121 int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);
122
123 void sendTextData(
124 uint32_t what, media_track_type type,
125 int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);
126
Robert Shih3423bbd2014-07-16 15:47:09 -0700127 sp<ABuffer> mediaBufferToABuffer(
128 MediaBuffer *mbuf,
129 media_track_type trackType,
130 int64_t *actualTimeUs = NULL);
131
Andreas Huberafed0e12011-09-20 15:39:58 -0700132 void readBuffer(
Robert Shih3423bbd2014-07-16 15:47:09 -0700133 media_track_type trackType,
134 int64_t seekTimeUs = -1ll, int64_t *actualTimeUs = NULL, bool formatChange = false);
Andreas Huberafed0e12011-09-20 15:39:58 -0700135
136 DISALLOW_EVIL_CONSTRUCTORS(GenericSource);
137};
138
139} // namespace android
140
141#endif // GENERIC_SOURCE_H_