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