blob: 3c5f55cc764ab3ed10c39519e036812301931cb1 [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;
33struct MediaSource;
Robert Shih3423bbd2014-07-16 15:47:09 -070034class MediaBuffer;
Andreas Huberafed0e12011-09-20 15:39:58 -070035
36struct NuPlayer::GenericSource : public NuPlayer::Source {
37 GenericSource(
Andreas Huberb5f25f02013-02-05 10:14:26 -080038 const sp<AMessage> &notify,
Andreas Huber1b86fe02014-01-29 11:13:26 -080039 const sp<IMediaHTTPService> &httpService,
Andreas Huberafed0e12011-09-20 15:39:58 -070040 const char *url,
Lajos Molnarcc227032014-07-17 15:33:06 -070041 const KeyedVector<String8, String8> *headers,
42 bool isWidevine = false,
43 bool uidValid = false,
44 uid_t uid = 0);
Andreas Huberafed0e12011-09-20 15:39:58 -070045
Andreas Huberb5f25f02013-02-05 10:14:26 -080046 GenericSource(
47 const sp<AMessage> &notify,
48 int fd, int64_t offset, int64_t length);
Andreas Huberafed0e12011-09-20 15:39:58 -070049
Andreas Huber9575c962013-02-05 13:59:56 -080050 virtual void prepareAsync();
51
Andreas Huberafed0e12011-09-20 15:39:58 -070052 virtual void start();
53
54 virtual status_t feedMoreTSData();
55
Andreas Huberafed0e12011-09-20 15:39:58 -070056 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
57
58 virtual status_t getDuration(int64_t *durationUs);
Robert Shihdd235722014-06-12 14:49:23 -070059 virtual size_t getTrackCount() const;
60 virtual sp<AMessage> getTrackInfo(size_t trackIndex) const;
Lajos Molnare26940f2014-07-31 10:31:26 -070061 virtual ssize_t getSelectedTrack(media_track_type type) const;
Robert Shih3423bbd2014-07-16 15:47:09 -070062 virtual status_t selectTrack(size_t trackIndex, bool select);
Andreas Huberafed0e12011-09-20 15:39:58 -070063 virtual status_t seekTo(int64_t seekTimeUs);
Andreas Huberb7c8e912012-11-27 15:02:53 -080064
Lajos Molnarcc227032014-07-17 15:33:06 -070065 virtual status_t setBuffers(bool audio, Vector<MediaBuffer *> &buffers);
66
Andreas Huberafed0e12011-09-20 15:39:58 -070067protected:
68 virtual ~GenericSource();
69
Robert Shih3423bbd2014-07-16 15:47:09 -070070 virtual void onMessageReceived(const sp<AMessage> &msg);
71
Andreas Huber84066782011-08-16 09:34:26 -070072 virtual sp<MetaData> getFormatMeta(bool audio);
73
Andreas Huberafed0e12011-09-20 15:39:58 -070074private:
Robert Shih3423bbd2014-07-16 15:47:09 -070075 enum {
76 kWhatFetchSubtitleData,
Lajos Molnare26940f2014-07-31 10:31:26 -070077 kWhatFetchTimedTextData,
Robert Shih3423bbd2014-07-16 15:47:09 -070078 kWhatSendSubtitleData,
Lajos Molnare26940f2014-07-31 10:31:26 -070079 kWhatSendTimedTextData,
Robert Shih3423bbd2014-07-16 15:47:09 -070080 kWhatChangeAVSource,
81 };
82
Robert Shihdd235722014-06-12 14:49:23 -070083 Vector<sp<MediaSource> > mSources;
84
Andreas Huberafed0e12011-09-20 15:39:58 -070085 struct Track {
Robert Shihdd235722014-06-12 14:49:23 -070086 size_t mIndex;
Andreas Huberafed0e12011-09-20 15:39:58 -070087 sp<MediaSource> mSource;
88 sp<AnotherPacketSource> mPackets;
89 };
90
91 Track mAudioTrack;
92 Track mVideoTrack;
Robert Shih3423bbd2014-07-16 15:47:09 -070093 Track mSubtitleTrack;
Lajos Molnare26940f2014-07-31 10:31:26 -070094 Track mTimedTextTrack;
Andreas Huberafed0e12011-09-20 15:39:58 -070095
Robert Shih3423bbd2014-07-16 15:47:09 -070096 int32_t mFetchSubtitleDataGeneration;
Lajos Molnare26940f2014-07-31 10:31:26 -070097 int32_t mFetchTimedTextDataGeneration;
Andreas Huberafed0e12011-09-20 15:39:58 -070098 int64_t mDurationUs;
99 bool mAudioIsVorbis;
Lajos Molnarcc227032014-07-17 15:33:06 -0700100 bool mIsWidevine;
101 bool mUIDValid;
102 uid_t mUID;
Andreas Huberafed0e12011-09-20 15:39:58 -0700103
104 void initFromDataSource(const sp<DataSource> &dataSource);
105
Lajos Molnare26940f2014-07-31 10:31:26 -0700106 void fetchTextData(
107 uint32_t what, media_track_type type,
108 int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);
109
110 void sendTextData(
111 uint32_t what, media_track_type type,
112 int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);
113
Robert Shih3423bbd2014-07-16 15:47:09 -0700114 sp<ABuffer> mediaBufferToABuffer(
115 MediaBuffer *mbuf,
116 media_track_type trackType,
117 int64_t *actualTimeUs = NULL);
118
Andreas Huberafed0e12011-09-20 15:39:58 -0700119 void readBuffer(
Robert Shih3423bbd2014-07-16 15:47:09 -0700120 media_track_type trackType,
121 int64_t seekTimeUs = -1ll, int64_t *actualTimeUs = NULL, bool formatChange = false);
Andreas Huberafed0e12011-09-20 15:39:58 -0700122
123 DISALLOW_EVIL_CONSTRUCTORS(GenericSource);
124};
125
126} // namespace android
127
128#endif // GENERIC_SOURCE_H_