blob: ee6f94f08ef455b807b9bc5f211e53aeb9535d5f [file] [log] [blame]
Ajit Khare73cfaf42013-01-07 23:28:47 -08001/*
2 * Copyright (C) 2010 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 DASH_PLAYER_H_
18
19#define DASH_PLAYER_H_
20
21#include <media/MediaPlayerInterface.h>
22#include <media/stagefright/foundation/AHandler.h>
23#include <media/stagefright/NativeWindowWrapper.h>
24#include "DashPlayerStats.h"
25#include <media/stagefright/foundation/ABuffer.h>
26#define KEY_DASH_ADAPTION_PROPERTIES 8002
27#define KEY_DASH_MPD_QUERY 8003
Naupada Dharmendra Patnaika2e55052013-01-23 17:06:03 +053028#define KEY_DASH_QOE_EVENT 8004
29#define KEY_DASH_QOE_PERIODIC_EVENT 8008
Ajit Khare73cfaf42013-01-07 23:28:47 -080030
31namespace android {
32
Shalaj Jain65506622013-01-29 18:27:08 -080033struct DashCodec;
Ajit Khare73cfaf42013-01-07 23:28:47 -080034struct MetaData;
35struct DashPlayerDriver;
36
Naupada Dharmendra Patnaika2e55052013-01-23 17:06:03 +053037enum {
38 kWhatQOE,
39 kWhatQOEPlay,
40 kWhatQOEStop,
41 kWhatQOESwitch,
42 kWhatQOEPeriodic,
43 };
44
Ajit Khare73cfaf42013-01-07 23:28:47 -080045struct DashPlayer : public AHandler {
46 DashPlayer();
47
48 void setUID(uid_t uid);
49
50 void setDriver(const wp<DashPlayerDriver> &driver);
51
52 void setDataSource(const sp<IStreamSource> &source);
53
54 void setDataSource(
55 const char *url, const KeyedVector<String8, String8> *headers);
56
57 void setDataSource(int fd, int64_t offset, int64_t length);
58
Sudhir Sharma3cfecd62013-07-17 15:01:24 -070059#ifdef ANDROID_JB_MR2
60 void setVideoSurfaceTexture(const sp<IGraphicBufferProducer> &bufferProducer);
61#else
Ajit Khare73cfaf42013-01-07 23:28:47 -080062 void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);
Sudhir Sharma3cfecd62013-07-17 15:01:24 -070063#endif
64
Ajit Khare73cfaf42013-01-07 23:28:47 -080065 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink);
66 void start();
67
68 void pause();
69 void resume();
70
71 // Will notify the driver through "notifyResetComplete" once finished.
72 void resetAsync();
73
74 // Will notify the driver through "notifySeekComplete" once finished.
75 void seekToAsync(int64_t seekTimeUs);
76
77 status_t prepareAsync();
78 status_t getParameter(int key, Parcel *reply);
79 status_t setParameter(int key, const Parcel &request);
Surajit Podder852ebd52013-02-21 15:05:18 +053080 status_t dump(int fd, const Vector<String16> &args);
Ajit Khare73cfaf42013-01-07 23:28:47 -080081
82public:
83 struct DASHHTTPLiveSource;
84 struct WFDSource;
85
86protected:
87 virtual ~DashPlayer();
88
89 virtual void onMessageReceived(const sp<AMessage> &msg);
90
91private:
92 struct Decoder;
93 struct Renderer;
94 struct Source;
95
96 enum {
97 // These keys must be in sync with the keys in QCTimedText.java
98 KEY_DISPLAY_FLAGS = 1, // int
99 KEY_STYLE_FLAGS = 2, // int
100 KEY_BACKGROUND_COLOR_RGBA = 3, // int
101 KEY_HIGHLIGHT_COLOR_RGBA = 4, // int
102 KEY_SCROLL_DELAY = 5, // int
103 KEY_WRAP_TEXT = 6, // int
104 KEY_START_TIME = 7, // int
105 KEY_STRUCT_BLINKING_TEXT_LIST = 8, // List<CharPos>
106 KEY_STRUCT_FONT_LIST = 9, // List<Font>
107 KEY_STRUCT_HIGHLIGHT_LIST = 10,// List<CharPos>
108 KEY_STRUCT_HYPER_TEXT_LIST = 11,// List<HyperText>
109 KEY_STRUCT_KARAOKE_LIST = 12,// List<Karaoke>
110 KEY_STRUCT_STYLE_LIST = 13,// List<Style>
111 KEY_STRUCT_TEXT_POS = 14,// TextPos
112 KEY_STRUCT_JUSTIFICATION = 15,// Justification
113 KEY_STRUCT_TEXT = 16,// Text
114 KEY_HEIGHT = 17,
115 KEY_WIDTH = 18,
116 KEY_DURATION = 19,
117 KEY_START_OFFSET = 20,
118 KEY_SUB_ATOM = 21,
119 KEY_GLOBAL_SETTING = 101,
120 KEY_LOCAL_SETTING = 102,
121 KEY_START_CHAR = 103,
122 KEY_END_CHAR = 104,
123 KEY_FONT_ID = 105,
124 KEY_FONT_SIZE = 106,
125 KEY_TEXT_COLOR_RGBA = 107,
126 KEY_TEXT_EOS = 108,
127 };
128
129 enum {
130 kWhatSetDataSource = '=DaS',
131 kWhatSetVideoNativeWindow = '=NaW',
132 kWhatSetAudioSink = '=AuS',
133 kWhatMoreDataQueued = 'more',
134 kWhatStart = 'strt',
135 kWhatScanSources = 'scan',
136 kWhatVideoNotify = 'vidN',
137 kWhatAudioNotify = 'audN',
138 kWhatTextNotify = 'texN',
139 kWhatRendererNotify = 'renN',
140 kWhatReset = 'rset',
141 kWhatSeek = 'seek',
142 kWhatPause = 'paus',
143 kWhatResume = 'rsme',
144 kWhatPrepareAsync = 'pras',
145 kWhatIsPrepareDone = 'prdn',
146 kWhatSourceNotify = 'snfy',
147 kKeySmoothStreaming = 'ESmS', //bool (int32_t)
148 kKeyEnableDecodeOrder = 'EDeO', //bool (int32_t)
149 };
150
151 enum {
152 kWhatBufferingStart = 'bfst',
153 kWhatBufferingEnd = 'bfen',
154 };
155
156 wp<DashPlayerDriver> mDriver;
157 bool mUIDValid;
158 uid_t mUID;
159 sp<Source> mSource;
160 sp<NativeWindowWrapper> mNativeWindow;
161 sp<MediaPlayerBase::AudioSink> mAudioSink;
162 sp<Decoder> mVideoDecoder;
163 bool mVideoIsAVC;
164 sp<Decoder> mAudioDecoder;
165 sp<Decoder> mTextDecoder;
166 sp<Renderer> mRenderer;
167
168 bool mAudioEOS;
169 bool mVideoEOS;
170
171 bool mScanSourcesPending;
172 int32_t mScanSourcesGeneration;
173 bool mBufferingNotification;
174
175 enum TrackName {
176 kVideo = 0,
177 kAudio,
178 kText,
179 kTrackAll,
180 };
181
182 enum FlushStatus {
183 NONE,
184 AWAITING_DISCONTINUITY,
185 FLUSHING_DECODER,
186 FLUSHING_DECODER_SHUTDOWN,
187 SHUTTING_DOWN_DECODER,
188 FLUSHED,
189 SHUT_DOWN,
190 };
191
192 enum FrameFlags {
193 TIMED_TEXT_FLAG_FRAME = 0x00,
194 TIMED_TEXT_FLAG_CODEC_CONFIG_FRAME,
195 TIMED_TEXT_FLAG_EOS,
196 TIMED_TEXT_FLAG_END = TIMED_TEXT_FLAG_EOS,
197 };
198
199 // Once the current flush is complete this indicates whether the
200 // notion of time has changed.
201 bool mTimeDiscontinuityPending;
202
203 FlushStatus mFlushingAudio;
204 FlushStatus mFlushingVideo;
205 bool mResetInProgress;
206 bool mResetPostponed;
huiyQuic755dd882013-03-18 18:02:41 -0700207 bool mSetVideoSize;
Ajit Khare73cfaf42013-01-07 23:28:47 -0800208
209 int64_t mSkipRenderingAudioUntilMediaTimeUs;
210 int64_t mSkipRenderingVideoUntilMediaTimeUs;
211
212 int64_t mVideoLateByUs;
213 int64_t mNumFramesTotal, mNumFramesDropped;
214
215 bool mPauseIndication;
216
217 Mutex mLock;
218
219 char *mTrackName;
220 sp<AMessage> mTextNotify;
221 sp<AMessage> mSourceNotify;
Naupada Dharmendra Patnaika2e55052013-01-23 17:06:03 +0530222 sp<AMessage> mQOENotify;
Ajit Khare73cfaf42013-01-07 23:28:47 -0800223
224 enum NuSourceType {
225 kHttpLiveSource = 0,
226 kHttpDashSource,
227 kRtspSource,
228 kStreamingSource,
229 kWfdSource,
230 kGenericSource,
231 kDefaultSource
232 };
233 NuSourceType mSourceType;
234
235 bool mIsSecureInputBuffers;
236
237 int32_t mSRid;
238
239 status_t instantiateDecoder(int track, sp<Decoder> *decoder);
240
241 status_t feedDecoderInputData(int track, const sp<AMessage> &msg);
242 void renderBuffer(bool audio, const sp<AMessage> &msg);
243
244 void notifyListener(int msg, int ext1, int ext2, const Parcel *obj=NULL);
245
246 void finishFlushIfPossible();
247
248 void flushDecoder(bool audio, bool needShutdown);
249
250 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
251
252 void finishReset();
253 void postScanSources();
254
255 sp<Source> LoadCreateSource(const char * uri, const KeyedVector<String8,
256 String8> *headers, bool uidValid, uid_t uid, NuSourceType srcTyp);
257
258 void postIsPrepareDone();
259
260 // for qualcomm statistics profiling
261 sp<DashPlayerStats> mStats;
262
263 void sendTextPacket(sp<ABuffer> accessUnit, status_t err);
264 void getTrackName(int track, char* name);
265 void prepareSource();
266
267 struct QueueEntry {
268 sp<AMessage> mMessageToBeConsumed;
269 };
270
271 List<QueueEntry> mDecoderMessageQueue;
272
273
274 DISALLOW_EVIL_CONSTRUCTORS(DashPlayer);
275};
276
277} // namespace android
278
279#endif // DASH_PLAYER_H_