blob: 756e76aa49b7b418b9d705250a1c354266870e09 [file] [log] [blame]
Andreas Huberf9334412010-12-15 15:17:42 -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//#define LOG_NDEBUG 0
18#define LOG_TAG "NuPlayer"
19#include <utils/Log.h>
20
21#include "NuPlayer.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080022
23#include "HTTPLiveSource.h"
Andreas Huberf9334412010-12-15 15:17:42 -080024#include "NuPlayerDecoder.h"
Andreas Huber43c3e6c2011-01-05 12:17:08 -080025#include "NuPlayerDriver.h"
Andreas Huberf9334412010-12-15 15:17:42 -080026#include "NuPlayerRenderer.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080027#include "NuPlayerSource.h"
Andreas Huber2bfdd422011-10-11 15:24:07 -070028#include "RTSPSource.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080029#include "StreamingSource.h"
Andreas Huberafed0e12011-09-20 15:39:58 -070030#include "GenericSource.h"
Andreas Huber84066782011-08-16 09:34:26 -070031#include "mp4/MP4Source.h"
Andreas Huber5bc087c2010-12-23 10:27:40 -080032
33#include "ATSParser.h"
Andreas Huberf9334412010-12-15 15:17:42 -080034
Andreas Huber84066782011-08-16 09:34:26 -070035#include <cutils/properties.h> // for property_get
Andreas Huber3831a062010-12-21 10:22:33 -080036#include <media/stagefright/foundation/hexdump.h>
Andreas Huberf9334412010-12-15 15:17:42 -080037#include <media/stagefright/foundation/ABuffer.h>
38#include <media/stagefright/foundation/ADebug.h>
39#include <media/stagefright/foundation/AMessage.h>
40#include <media/stagefright/ACodec.h>
Andreas Huber3fe62152011-09-16 15:09:22 -070041#include <media/stagefright/MediaDefs.h>
Andreas Huberf9334412010-12-15 15:17:42 -080042#include <media/stagefright/MediaErrors.h>
43#include <media/stagefright/MetaData.h>
Glenn Kasten11731182011-02-08 17:26:17 -080044#include <gui/ISurfaceTexture.h>
Andreas Huberf9334412010-12-15 15:17:42 -080045
Andreas Huber3fe62152011-09-16 15:09:22 -070046#include "avc_utils.h"
47
Andreas Huber84066782011-08-16 09:34:26 -070048#include "ESDS.h"
49#include <media/stagefright/Utils.h>
50
Andreas Huberf9334412010-12-15 15:17:42 -080051namespace android {
52
53////////////////////////////////////////////////////////////////////////////////
54
55NuPlayer::NuPlayer()
Andreas Huber9b80c2b2011-06-30 15:47:02 -070056 : mUIDValid(false),
Andreas Huber3fe62152011-09-16 15:09:22 -070057 mVideoIsAVC(false),
Andreas Huber9b80c2b2011-06-30 15:47:02 -070058 mAudioEOS(false),
Andreas Huberf9334412010-12-15 15:17:42 -080059 mVideoEOS(false),
Andreas Huber5bc087c2010-12-23 10:27:40 -080060 mScanSourcesPending(false),
Andreas Huber1aef2112011-01-04 14:01:29 -080061 mScanSourcesGeneration(0),
Andreas Huber6e3d3112011-11-28 12:36:11 -080062 mTimeDiscontinuityPending(false),
Andreas Huberf9334412010-12-15 15:17:42 -080063 mFlushingAudio(NONE),
Andreas Huber1aef2112011-01-04 14:01:29 -080064 mFlushingVideo(NONE),
65 mResetInProgress(false),
Andreas Huber3fe62152011-09-16 15:09:22 -070066 mResetPostponed(false),
67 mSkipRenderingAudioUntilMediaTimeUs(-1ll),
68 mSkipRenderingVideoUntilMediaTimeUs(-1ll),
69 mVideoLateByUs(0ll),
70 mNumFramesTotal(0ll),
James Dong53a2d132012-08-31 12:18:27 -070071 mNumFramesDropped(0ll),
72 mVideoScalingMode(NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) {
Andreas Huberf9334412010-12-15 15:17:42 -080073}
74
75NuPlayer::~NuPlayer() {
76}
77
Andreas Huber9b80c2b2011-06-30 15:47:02 -070078void NuPlayer::setUID(uid_t uid) {
79 mUIDValid = true;
80 mUID = uid;
81}
82
Andreas Huber43c3e6c2011-01-05 12:17:08 -080083void NuPlayer::setDriver(const wp<NuPlayerDriver> &driver) {
84 mDriver = driver;
Andreas Huberf9334412010-12-15 15:17:42 -080085}
86
87void NuPlayer::setDataSource(const sp<IStreamSource> &source) {
88 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
89
Andreas Huber84066782011-08-16 09:34:26 -070090 char prop[PROPERTY_VALUE_MAX];
91 if (property_get("media.stagefright.use-mp4source", prop, NULL)
92 && (!strcmp(prop, "1") || !strcasecmp(prop, "true"))) {
93 msg->setObject("source", new MP4Source(source));
94 } else {
95 msg->setObject("source", new StreamingSource(source));
96 }
97
Andreas Huber5bc087c2010-12-23 10:27:40 -080098 msg->post();
99}
Andreas Huberf9334412010-12-15 15:17:42 -0800100
Andreas Huberafed0e12011-09-20 15:39:58 -0700101static bool IsHTTPLiveURL(const char *url) {
102 if (!strncasecmp("http://", url, 7)
103 || !strncasecmp("https://", url, 8)) {
104 size_t len = strlen(url);
105 if (len >= 5 && !strcasecmp(".m3u8", &url[len - 5])) {
106 return true;
107 }
108
109 if (strstr(url,"m3u8")) {
110 return true;
111 }
112 }
113
114 return false;
115}
116
Andreas Huber5bc087c2010-12-23 10:27:40 -0800117void NuPlayer::setDataSource(
118 const char *url, const KeyedVector<String8, String8> *headers) {
119 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
120
Andreas Huberafed0e12011-09-20 15:39:58 -0700121 sp<Source> source;
122 if (IsHTTPLiveURL(url)) {
123 source = new HTTPLiveSource(url, headers, mUIDValid, mUID);
124 } else if (!strncasecmp(url, "rtsp://", 7)) {
125 source = new RTSPSource(url, headers, mUIDValid, mUID);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700126 } else {
Andreas Huberafed0e12011-09-20 15:39:58 -0700127 source = new GenericSource(url, headers, mUIDValid, mUID);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700128 }
129
Andreas Huberafed0e12011-09-20 15:39:58 -0700130 msg->setObject("source", source);
131 msg->post();
132}
133
134void NuPlayer::setDataSource(int fd, int64_t offset, int64_t length) {
135 sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
136
137 sp<Source> source = new GenericSource(fd, offset, length);
138 msg->setObject("source", source);
Andreas Huberf9334412010-12-15 15:17:42 -0800139 msg->post();
140}
141
Glenn Kasten11731182011-02-08 17:26:17 -0800142void NuPlayer::setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture) {
143 sp<AMessage> msg = new AMessage(kWhatSetVideoNativeWindow, id());
144 sp<SurfaceTextureClient> surfaceTextureClient(surfaceTexture != NULL ?
145 new SurfaceTextureClient(surfaceTexture) : NULL);
146 msg->setObject("native-window", new NativeWindowWrapper(surfaceTextureClient));
Andreas Huberf9334412010-12-15 15:17:42 -0800147 msg->post();
148}
149
150void NuPlayer::setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink) {
151 sp<AMessage> msg = new AMessage(kWhatSetAudioSink, id());
152 msg->setObject("sink", sink);
153 msg->post();
154}
155
156void NuPlayer::start() {
157 (new AMessage(kWhatStart, id()))->post();
158}
159
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800160void NuPlayer::pause() {
Andreas Huberb4082222011-01-20 15:23:04 -0800161 (new AMessage(kWhatPause, id()))->post();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800162}
163
164void NuPlayer::resume() {
Andreas Huberb4082222011-01-20 15:23:04 -0800165 (new AMessage(kWhatResume, id()))->post();
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800166}
167
Andreas Huber1aef2112011-01-04 14:01:29 -0800168void NuPlayer::resetAsync() {
169 (new AMessage(kWhatReset, id()))->post();
170}
171
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800172void NuPlayer::seekToAsync(int64_t seekTimeUs) {
173 sp<AMessage> msg = new AMessage(kWhatSeek, id());
174 msg->setInt64("seekTimeUs", seekTimeUs);
175 msg->post();
176}
177
Andreas Huber53df1a42010-12-22 10:03:04 -0800178// static
Andreas Huber1aef2112011-01-04 14:01:29 -0800179bool NuPlayer::IsFlushingState(FlushStatus state, bool *needShutdown) {
Andreas Huber53df1a42010-12-22 10:03:04 -0800180 switch (state) {
181 case FLUSHING_DECODER:
Andreas Huber1aef2112011-01-04 14:01:29 -0800182 if (needShutdown != NULL) {
183 *needShutdown = false;
Andreas Huber53df1a42010-12-22 10:03:04 -0800184 }
185 return true;
186
Andreas Huber1aef2112011-01-04 14:01:29 -0800187 case FLUSHING_DECODER_SHUTDOWN:
188 if (needShutdown != NULL) {
189 *needShutdown = true;
Andreas Huber53df1a42010-12-22 10:03:04 -0800190 }
191 return true;
192
193 default:
194 return false;
195 }
196}
197
Andreas Huberf9334412010-12-15 15:17:42 -0800198void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
199 switch (msg->what()) {
200 case kWhatSetDataSource:
201 {
Steve Block3856b092011-10-20 11:56:00 +0100202 ALOGV("kWhatSetDataSource");
Andreas Huberf9334412010-12-15 15:17:42 -0800203
204 CHECK(mSource == NULL);
205
Andreas Huber5bc087c2010-12-23 10:27:40 -0800206 sp<RefBase> obj;
207 CHECK(msg->findObject("source", &obj));
Andreas Huberf9334412010-12-15 15:17:42 -0800208
Andreas Huber5bc087c2010-12-23 10:27:40 -0800209 mSource = static_cast<Source *>(obj.get());
Andreas Huberf9334412010-12-15 15:17:42 -0800210 break;
211 }
212
Glenn Kasten11731182011-02-08 17:26:17 -0800213 case kWhatSetVideoNativeWindow:
Andreas Huberf9334412010-12-15 15:17:42 -0800214 {
Steve Block3856b092011-10-20 11:56:00 +0100215 ALOGV("kWhatSetVideoNativeWindow");
Andreas Huberf9334412010-12-15 15:17:42 -0800216
217 sp<RefBase> obj;
Glenn Kasten11731182011-02-08 17:26:17 -0800218 CHECK(msg->findObject("native-window", &obj));
Andreas Huberf9334412010-12-15 15:17:42 -0800219
Glenn Kasten11731182011-02-08 17:26:17 -0800220 mNativeWindow = static_cast<NativeWindowWrapper *>(obj.get());
James Dong53a2d132012-08-31 12:18:27 -0700221
222 // XXX - ignore error from setVideoScalingMode for now
223 setVideoScalingMode(mVideoScalingMode);
Andreas Huberf9334412010-12-15 15:17:42 -0800224 break;
225 }
226
227 case kWhatSetAudioSink:
228 {
Steve Block3856b092011-10-20 11:56:00 +0100229 ALOGV("kWhatSetAudioSink");
Andreas Huberf9334412010-12-15 15:17:42 -0800230
231 sp<RefBase> obj;
232 CHECK(msg->findObject("sink", &obj));
233
234 mAudioSink = static_cast<MediaPlayerBase::AudioSink *>(obj.get());
235 break;
236 }
237
238 case kWhatStart:
239 {
Steve Block3856b092011-10-20 11:56:00 +0100240 ALOGV("kWhatStart");
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800241
Andreas Huber3fe62152011-09-16 15:09:22 -0700242 mVideoIsAVC = false;
Andreas Huber1aef2112011-01-04 14:01:29 -0800243 mAudioEOS = false;
244 mVideoEOS = false;
Andreas Huber32f3cef2011-03-02 15:34:46 -0800245 mSkipRenderingAudioUntilMediaTimeUs = -1;
246 mSkipRenderingVideoUntilMediaTimeUs = -1;
Andreas Huber3fe62152011-09-16 15:09:22 -0700247 mVideoLateByUs = 0;
248 mNumFramesTotal = 0;
249 mNumFramesDropped = 0;
Andreas Huber1aef2112011-01-04 14:01:29 -0800250
Andreas Huber5bc087c2010-12-23 10:27:40 -0800251 mSource->start();
Andreas Huberf9334412010-12-15 15:17:42 -0800252
253 mRenderer = new Renderer(
254 mAudioSink,
255 new AMessage(kWhatRendererNotify, id()));
256
257 looper()->registerHandler(mRenderer);
258
Andreas Huber1aef2112011-01-04 14:01:29 -0800259 postScanSources();
Andreas Huberf9334412010-12-15 15:17:42 -0800260 break;
261 }
262
263 case kWhatScanSources:
264 {
Andreas Huber1aef2112011-01-04 14:01:29 -0800265 int32_t generation;
266 CHECK(msg->findInt32("generation", &generation));
267 if (generation != mScanSourcesGeneration) {
268 // Drop obsolete msg.
269 break;
270 }
271
Andreas Huber5bc087c2010-12-23 10:27:40 -0800272 mScanSourcesPending = false;
273
Steve Block3856b092011-10-20 11:56:00 +0100274 ALOGV("scanning sources haveAudio=%d, haveVideo=%d",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800275 mAudioDecoder != NULL, mVideoDecoder != NULL);
276
Haynes Mathew George5d246ef2012-07-09 10:36:57 -0700277 if (mNativeWindow != NULL) {
278 instantiateDecoder(false, &mVideoDecoder);
279 }
Andreas Huberf9334412010-12-15 15:17:42 -0800280
281 if (mAudioSink != NULL) {
Andreas Huber5bc087c2010-12-23 10:27:40 -0800282 instantiateDecoder(true, &mAudioDecoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800283 }
284
Andreas Hubereac68ba2011-09-27 12:12:25 -0700285 status_t err;
286 if ((err = mSource->feedMoreTSData()) != OK) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800287 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
288 // We're not currently decoding anything (no audio or
289 // video tracks found) and we just ran out of input data.
Andreas Hubereac68ba2011-09-27 12:12:25 -0700290
291 if (err == ERROR_END_OF_STREAM) {
292 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
293 } else {
294 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
295 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800296 }
Andreas Huberf9334412010-12-15 15:17:42 -0800297 break;
298 }
299
Andreas Huber8a61c222012-08-31 14:05:27 -0700300 if ((mAudioDecoder == NULL && mAudioSink != NULL)
301 || (mVideoDecoder == NULL && mNativeWindow != NULL)) {
Andreas Huberf9334412010-12-15 15:17:42 -0800302 msg->post(100000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800303 mScanSourcesPending = true;
Andreas Huberf9334412010-12-15 15:17:42 -0800304 }
305 break;
306 }
307
308 case kWhatVideoNotify:
309 case kWhatAudioNotify:
310 {
311 bool audio = msg->what() == kWhatAudioNotify;
312
313 sp<AMessage> codecRequest;
314 CHECK(msg->findMessage("codec-request", &codecRequest));
315
316 int32_t what;
317 CHECK(codecRequest->findInt32("what", &what));
318
319 if (what == ACodec::kWhatFillThisBuffer) {
320 status_t err = feedDecoderInputData(
321 audio, codecRequest);
322
Andreas Huber5bc087c2010-12-23 10:27:40 -0800323 if (err == -EWOULDBLOCK) {
Andreas Hubereac68ba2011-09-27 12:12:25 -0700324 if (mSource->feedMoreTSData() == OK) {
Andreas Huber1183a4a2011-11-03 11:00:21 -0700325 msg->post(10000ll);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800326 }
Andreas Huberf9334412010-12-15 15:17:42 -0800327 }
328 } else if (what == ACodec::kWhatEOS) {
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700329 int32_t err;
330 CHECK(codecRequest->findInt32("err", &err));
331
332 if (err == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100333 ALOGV("got %s decoder EOS", audio ? "audio" : "video");
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700334 } else {
Steve Block3856b092011-10-20 11:56:00 +0100335 ALOGV("got %s decoder EOS w/ error %d",
Andreas Huberdc9bacd2011-09-26 10:53:29 -0700336 audio ? "audio" : "video",
337 err);
338 }
339
340 mRenderer->queueEOS(audio, err);
Andreas Huberf9334412010-12-15 15:17:42 -0800341 } else if (what == ACodec::kWhatFlushCompleted) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800342 bool needShutdown;
Andreas Huber53df1a42010-12-22 10:03:04 -0800343
Andreas Huberf9334412010-12-15 15:17:42 -0800344 if (audio) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800345 CHECK(IsFlushingState(mFlushingAudio, &needShutdown));
Andreas Huberf9334412010-12-15 15:17:42 -0800346 mFlushingAudio = FLUSHED;
347 } else {
Andreas Huber1aef2112011-01-04 14:01:29 -0800348 CHECK(IsFlushingState(mFlushingVideo, &needShutdown));
Andreas Huberf9334412010-12-15 15:17:42 -0800349 mFlushingVideo = FLUSHED;
Andreas Huber3fe62152011-09-16 15:09:22 -0700350
351 mVideoLateByUs = 0;
Andreas Huberf9334412010-12-15 15:17:42 -0800352 }
353
Steve Block3856b092011-10-20 11:56:00 +0100354 ALOGV("decoder %s flush completed", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800355
Andreas Huber1aef2112011-01-04 14:01:29 -0800356 if (needShutdown) {
Steve Block3856b092011-10-20 11:56:00 +0100357 ALOGV("initiating %s decoder shutdown",
Andreas Huber53df1a42010-12-22 10:03:04 -0800358 audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800359
Andreas Huber53df1a42010-12-22 10:03:04 -0800360 (audio ? mAudioDecoder : mVideoDecoder)->initiateShutdown();
Andreas Huberf9334412010-12-15 15:17:42 -0800361
Andreas Huber53df1a42010-12-22 10:03:04 -0800362 if (audio) {
363 mFlushingAudio = SHUTTING_DOWN_DECODER;
364 } else {
365 mFlushingVideo = SHUTTING_DOWN_DECODER;
366 }
Andreas Huberf9334412010-12-15 15:17:42 -0800367 }
Andreas Huber3831a062010-12-21 10:22:33 -0800368
369 finishFlushIfPossible();
Andreas Huber2c2814b2010-12-15 17:18:20 -0800370 } else if (what == ACodec::kWhatOutputFormatChanged) {
Andreas Huber31e25082011-01-10 10:38:31 -0800371 if (audio) {
372 int32_t numChannels;
373 CHECK(codecRequest->findInt32("channel-count", &numChannels));
Andreas Huber2c2814b2010-12-15 17:18:20 -0800374
Andreas Huber31e25082011-01-10 10:38:31 -0800375 int32_t sampleRate;
376 CHECK(codecRequest->findInt32("sample-rate", &sampleRate));
Andreas Huber2c2814b2010-12-15 17:18:20 -0800377
Steve Block3856b092011-10-20 11:56:00 +0100378 ALOGV("Audio output format changed to %d Hz, %d channels",
Andreas Huber31e25082011-01-10 10:38:31 -0800379 sampleRate, numChannels);
Andreas Huber2c2814b2010-12-15 17:18:20 -0800380
Andreas Huber31e25082011-01-10 10:38:31 -0800381 mAudioSink->close();
Eric Laurent1948eb32012-04-13 16:50:19 -0700382
383 audio_output_flags_t flags;
384 int64_t durationUs;
385 // FIXME: we should handle the case where the video decoder is created after
386 // we receive the format change indication. Current code will just make that
387 // we select deep buffer with video which should not be a problem as it should
388 // not prevent from keeping A/V sync.
389 if (mVideoDecoder == NULL &&
390 mSource->getDuration(&durationUs) == OK &&
391 durationUs > AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US) {
392 flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
393 } else {
394 flags = AUDIO_OUTPUT_FLAG_NONE;
395 }
396
Andreas Huber98065552012-05-03 11:33:01 -0700397 int32_t channelMask;
398 if (!codecRequest->findInt32("channel-mask", &channelMask)) {
399 channelMask = CHANNEL_MASK_USE_CHANNEL_ORDER;
400 }
401
Andreas Huber078cfcf2011-09-15 12:25:04 -0700402 CHECK_EQ(mAudioSink->open(
403 sampleRate,
404 numChannels,
Andreas Huber98065552012-05-03 11:33:01 -0700405 (audio_channel_mask_t)channelMask,
Andreas Huber078cfcf2011-09-15 12:25:04 -0700406 AUDIO_FORMAT_PCM_16_BIT,
Eric Laurent1948eb32012-04-13 16:50:19 -0700407 8 /* bufferCount */,
408 NULL,
409 NULL,
410 flags),
Andreas Huber078cfcf2011-09-15 12:25:04 -0700411 (status_t)OK);
Andreas Huber31e25082011-01-10 10:38:31 -0800412 mAudioSink->start();
Andreas Huber2c2814b2010-12-15 17:18:20 -0800413
Andreas Huber31e25082011-01-10 10:38:31 -0800414 mRenderer->signalAudioSinkChanged();
415 } else {
416 // video
Andreas Huber3831a062010-12-21 10:22:33 -0800417
Andreas Huber31e25082011-01-10 10:38:31 -0800418 int32_t width, height;
419 CHECK(codecRequest->findInt32("width", &width));
420 CHECK(codecRequest->findInt32("height", &height));
421
422 int32_t cropLeft, cropTop, cropRight, cropBottom;
423 CHECK(codecRequest->findRect(
424 "crop",
425 &cropLeft, &cropTop, &cropRight, &cropBottom));
426
Steve Block3856b092011-10-20 11:56:00 +0100427 ALOGV("Video output format changed to %d x %d "
Andreas Hubercb67cd12011-08-26 16:02:19 -0700428 "(crop: %d x %d @ (%d, %d))",
Andreas Huber31e25082011-01-10 10:38:31 -0800429 width, height,
Andreas Hubercb67cd12011-08-26 16:02:19 -0700430 (cropRight - cropLeft + 1),
431 (cropBottom - cropTop + 1),
432 cropLeft, cropTop);
Andreas Huber31e25082011-01-10 10:38:31 -0800433
434 notifyListener(
435 MEDIA_SET_VIDEO_SIZE,
436 cropRight - cropLeft + 1,
437 cropBottom - cropTop + 1);
438 }
Andreas Huber3831a062010-12-21 10:22:33 -0800439 } else if (what == ACodec::kWhatShutdownCompleted) {
Steve Block3856b092011-10-20 11:56:00 +0100440 ALOGV("%s shutdown completed", audio ? "audio" : "video");
Andreas Huber3831a062010-12-21 10:22:33 -0800441 if (audio) {
442 mAudioDecoder.clear();
443
444 CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER);
445 mFlushingAudio = SHUT_DOWN;
446 } else {
447 mVideoDecoder.clear();
448
449 CHECK_EQ((int)mFlushingVideo, (int)SHUTTING_DOWN_DECODER);
450 mFlushingVideo = SHUT_DOWN;
451 }
452
453 finishFlushIfPossible();
Andreas Huberc92fd242011-08-16 13:48:44 -0700454 } else if (what == ACodec::kWhatError) {
Steve Block29357bc2012-01-06 19:20:56 +0000455 ALOGE("Received error from %s decoder, aborting playback.",
Andreas Huberc92fd242011-08-16 13:48:44 -0700456 audio ? "audio" : "video");
457
458 mRenderer->queueEOS(audio, UNKNOWN_ERROR);
Andreas Huber57788222012-02-21 11:47:18 -0800459 } else if (what == ACodec::kWhatDrainThisBuffer) {
Andreas Huberf9334412010-12-15 15:17:42 -0800460 renderBuffer(audio, codecRequest);
Andreas Huber57788222012-02-21 11:47:18 -0800461 } else {
462 ALOGV("Unhandled codec notification %d.", what);
Andreas Huberf9334412010-12-15 15:17:42 -0800463 }
464
465 break;
466 }
467
468 case kWhatRendererNotify:
469 {
470 int32_t what;
471 CHECK(msg->findInt32("what", &what));
472
473 if (what == Renderer::kWhatEOS) {
474 int32_t audio;
475 CHECK(msg->findInt32("audio", &audio));
476
Andreas Huberc92fd242011-08-16 13:48:44 -0700477 int32_t finalResult;
478 CHECK(msg->findInt32("finalResult", &finalResult));
479
Andreas Huberf9334412010-12-15 15:17:42 -0800480 if (audio) {
481 mAudioEOS = true;
482 } else {
483 mVideoEOS = true;
484 }
485
Andreas Huberc92fd242011-08-16 13:48:44 -0700486 if (finalResult == ERROR_END_OF_STREAM) {
Steve Block3856b092011-10-20 11:56:00 +0100487 ALOGV("reached %s EOS", audio ? "audio" : "video");
Andreas Huberc92fd242011-08-16 13:48:44 -0700488 } else {
Steve Block29357bc2012-01-06 19:20:56 +0000489 ALOGE("%s track encountered an error (%d)",
Andreas Huberc92fd242011-08-16 13:48:44 -0700490 audio ? "audio" : "video", finalResult);
491
492 notifyListener(
493 MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, finalResult);
494 }
Andreas Huberf9334412010-12-15 15:17:42 -0800495
496 if ((mAudioEOS || mAudioDecoder == NULL)
497 && (mVideoEOS || mVideoDecoder == NULL)) {
498 notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
499 }
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800500 } else if (what == Renderer::kWhatPosition) {
501 int64_t positionUs;
502 CHECK(msg->findInt64("positionUs", &positionUs));
503
Andreas Huber3fe62152011-09-16 15:09:22 -0700504 CHECK(msg->findInt64("videoLateByUs", &mVideoLateByUs));
505
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800506 if (mDriver != NULL) {
507 sp<NuPlayerDriver> driver = mDriver.promote();
508 if (driver != NULL) {
509 driver->notifyPosition(positionUs);
Andreas Huber3fe62152011-09-16 15:09:22 -0700510
511 driver->notifyFrameStats(
512 mNumFramesTotal, mNumFramesDropped);
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800513 }
514 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700515 } else if (what == Renderer::kWhatFlushComplete) {
Andreas Huberf9334412010-12-15 15:17:42 -0800516 int32_t audio;
517 CHECK(msg->findInt32("audio", &audio));
518
Steve Block3856b092011-10-20 11:56:00 +0100519 ALOGV("renderer %s flush completed.", audio ? "audio" : "video");
James Dongf57b4ea2012-07-20 13:38:36 -0700520 } else if (what == Renderer::kWhatVideoRenderingStart) {
521 notifyListener(MEDIA_INFO, MEDIA_INFO_RENDERING_START, 0);
Andreas Huberf9334412010-12-15 15:17:42 -0800522 }
523 break;
524 }
525
526 case kWhatMoreDataQueued:
527 {
528 break;
529 }
530
Andreas Huber1aef2112011-01-04 14:01:29 -0800531 case kWhatReset:
532 {
Steve Block3856b092011-10-20 11:56:00 +0100533 ALOGV("kWhatReset");
Andreas Huber1aef2112011-01-04 14:01:29 -0800534
Andreas Huberb58ce9f2011-11-28 16:27:35 -0800535 if (mRenderer != NULL) {
536 // There's an edge case where the renderer owns all output
537 // buffers and is paused, therefore the decoder will not read
538 // more input data and will never encounter the matching
539 // discontinuity. To avoid this, we resume the renderer.
540
541 if (mFlushingAudio == AWAITING_DISCONTINUITY
542 || mFlushingVideo == AWAITING_DISCONTINUITY) {
543 mRenderer->resume();
544 }
545 }
546
Andreas Huber1aef2112011-01-04 14:01:29 -0800547 if (mFlushingAudio != NONE || mFlushingVideo != NONE) {
548 // We're currently flushing, postpone the reset until that's
549 // completed.
550
Andreas Huberea9d51b2011-11-30 09:53:40 -0800551 ALOGV("postponing reset mFlushingAudio=%d, mFlushingVideo=%d",
552 mFlushingAudio, mFlushingVideo);
Andreas Huber1aef2112011-01-04 14:01:29 -0800553
554 mResetPostponed = true;
555 break;
556 }
557
558 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
559 finishReset();
560 break;
561 }
562
Andreas Huber6e3d3112011-11-28 12:36:11 -0800563 mTimeDiscontinuityPending = true;
564
Andreas Huber1aef2112011-01-04 14:01:29 -0800565 if (mAudioDecoder != NULL) {
566 flushDecoder(true /* audio */, true /* needShutdown */);
567 }
568
569 if (mVideoDecoder != NULL) {
570 flushDecoder(false /* audio */, true /* needShutdown */);
571 }
572
573 mResetInProgress = true;
574 break;
575 }
576
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800577 case kWhatSeek:
578 {
579 int64_t seekTimeUs;
580 CHECK(msg->findInt64("seekTimeUs", &seekTimeUs));
581
Steve Block3856b092011-10-20 11:56:00 +0100582 ALOGV("kWhatSeek seekTimeUs=%lld us (%.2f secs)",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800583 seekTimeUs, seekTimeUs / 1E6);
584
585 mSource->seekTo(seekTimeUs);
586
587 if (mDriver != NULL) {
588 sp<NuPlayerDriver> driver = mDriver.promote();
589 if (driver != NULL) {
590 driver->notifySeekComplete();
591 }
592 }
593
594 break;
595 }
596
Andreas Huberb4082222011-01-20 15:23:04 -0800597 case kWhatPause:
598 {
599 CHECK(mRenderer != NULL);
600 mRenderer->pause();
601 break;
602 }
603
604 case kWhatResume:
605 {
606 CHECK(mRenderer != NULL);
607 mRenderer->resume();
608 break;
609 }
610
Andreas Huberf9334412010-12-15 15:17:42 -0800611 default:
612 TRESPASS();
613 break;
614 }
615}
616
Andreas Huber3831a062010-12-21 10:22:33 -0800617void NuPlayer::finishFlushIfPossible() {
618 if (mFlushingAudio != FLUSHED && mFlushingAudio != SHUT_DOWN) {
619 return;
620 }
621
622 if (mFlushingVideo != FLUSHED && mFlushingVideo != SHUT_DOWN) {
623 return;
624 }
625
Steve Block3856b092011-10-20 11:56:00 +0100626 ALOGV("both audio and video are flushed now.");
Andreas Huber3831a062010-12-21 10:22:33 -0800627
Andreas Huber6e3d3112011-11-28 12:36:11 -0800628 if (mTimeDiscontinuityPending) {
629 mRenderer->signalTimeDiscontinuity();
630 mTimeDiscontinuityPending = false;
631 }
Andreas Huber3831a062010-12-21 10:22:33 -0800632
Andreas Huber22fc52f2011-01-05 16:24:27 -0800633 if (mAudioDecoder != NULL) {
Andreas Huber3831a062010-12-21 10:22:33 -0800634 mAudioDecoder->signalResume();
635 }
636
Andreas Huber22fc52f2011-01-05 16:24:27 -0800637 if (mVideoDecoder != NULL) {
Andreas Huber3831a062010-12-21 10:22:33 -0800638 mVideoDecoder->signalResume();
639 }
640
641 mFlushingAudio = NONE;
642 mFlushingVideo = NONE;
Andreas Huber3831a062010-12-21 10:22:33 -0800643
Andreas Huber1aef2112011-01-04 14:01:29 -0800644 if (mResetInProgress) {
Steve Block3856b092011-10-20 11:56:00 +0100645 ALOGV("reset completed");
Andreas Huber1aef2112011-01-04 14:01:29 -0800646
647 mResetInProgress = false;
648 finishReset();
649 } else if (mResetPostponed) {
650 (new AMessage(kWhatReset, id()))->post();
651 mResetPostponed = false;
Andreas Huber22fc52f2011-01-05 16:24:27 -0800652 } else if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800653 postScanSources();
Andreas Huberf9334412010-12-15 15:17:42 -0800654 }
655}
656
Andreas Huber1aef2112011-01-04 14:01:29 -0800657void NuPlayer::finishReset() {
658 CHECK(mAudioDecoder == NULL);
659 CHECK(mVideoDecoder == NULL);
660
Andreas Huber2bfdd422011-10-11 15:24:07 -0700661 ++mScanSourcesGeneration;
662 mScanSourcesPending = false;
663
Andreas Huber1aef2112011-01-04 14:01:29 -0800664 mRenderer.clear();
Andreas Huber2bfdd422011-10-11 15:24:07 -0700665
666 if (mSource != NULL) {
667 mSource->stop();
668 mSource.clear();
669 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800670
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800671 if (mDriver != NULL) {
672 sp<NuPlayerDriver> driver = mDriver.promote();
673 if (driver != NULL) {
674 driver->notifyResetComplete();
675 }
676 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800677}
678
679void NuPlayer::postScanSources() {
680 if (mScanSourcesPending) {
681 return;
682 }
683
684 sp<AMessage> msg = new AMessage(kWhatScanSources, id());
685 msg->setInt32("generation", mScanSourcesGeneration);
686 msg->post();
687
688 mScanSourcesPending = true;
689}
690
Andreas Huber5bc087c2010-12-23 10:27:40 -0800691status_t NuPlayer::instantiateDecoder(bool audio, sp<Decoder> *decoder) {
Andreas Huberf9334412010-12-15 15:17:42 -0800692 if (*decoder != NULL) {
693 return OK;
694 }
695
Andreas Huber84066782011-08-16 09:34:26 -0700696 sp<AMessage> format = mSource->getFormat(audio);
Andreas Huberf9334412010-12-15 15:17:42 -0800697
Andreas Huber84066782011-08-16 09:34:26 -0700698 if (format == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800699 return -EWOULDBLOCK;
700 }
701
Andreas Huber3fe62152011-09-16 15:09:22 -0700702 if (!audio) {
Andreas Huber84066782011-08-16 09:34:26 -0700703 AString mime;
704 CHECK(format->findString("mime", &mime));
705 mVideoIsAVC = !strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime.c_str());
Andreas Huber3fe62152011-09-16 15:09:22 -0700706 }
707
Andreas Huberf9334412010-12-15 15:17:42 -0800708 sp<AMessage> notify =
709 new AMessage(audio ? kWhatAudioNotify : kWhatVideoNotify,
710 id());
711
Glenn Kasten11731182011-02-08 17:26:17 -0800712 *decoder = audio ? new Decoder(notify) :
713 new Decoder(notify, mNativeWindow);
Andreas Huberf9334412010-12-15 15:17:42 -0800714 looper()->registerHandler(*decoder);
715
Andreas Huber84066782011-08-16 09:34:26 -0700716 (*decoder)->configure(format);
Andreas Huberf9334412010-12-15 15:17:42 -0800717
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800718 int64_t durationUs;
719 if (mDriver != NULL && mSource->getDuration(&durationUs) == OK) {
720 sp<NuPlayerDriver> driver = mDriver.promote();
721 if (driver != NULL) {
722 driver->notifyDuration(durationUs);
723 }
724 }
725
Andreas Huberf9334412010-12-15 15:17:42 -0800726 return OK;
727}
728
729status_t NuPlayer::feedDecoderInputData(bool audio, const sp<AMessage> &msg) {
730 sp<AMessage> reply;
731 CHECK(msg->findMessage("reply", &reply));
732
Andreas Huber53df1a42010-12-22 10:03:04 -0800733 if ((audio && IsFlushingState(mFlushingAudio))
734 || (!audio && IsFlushingState(mFlushingVideo))) {
Andreas Huberf9334412010-12-15 15:17:42 -0800735 reply->setInt32("err", INFO_DISCONTINUITY);
736 reply->post();
737 return OK;
738 }
739
740 sp<ABuffer> accessUnit;
Andreas Huberf9334412010-12-15 15:17:42 -0800741
Andreas Huber3fe62152011-09-16 15:09:22 -0700742 bool dropAccessUnit;
743 do {
744 status_t err = mSource->dequeueAccessUnit(audio, &accessUnit);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800745
Andreas Huber3fe62152011-09-16 15:09:22 -0700746 if (err == -EWOULDBLOCK) {
747 return err;
748 } else if (err != OK) {
749 if (err == INFO_DISCONTINUITY) {
750 int32_t type;
751 CHECK(accessUnit->meta()->findInt32("discontinuity", &type));
Andreas Huber53df1a42010-12-22 10:03:04 -0800752
Andreas Huber3fe62152011-09-16 15:09:22 -0700753 bool formatChange =
Andreas Huber6e3d3112011-11-28 12:36:11 -0800754 (audio &&
755 (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT))
756 || (!audio &&
757 (type & ATSParser::DISCONTINUITY_VIDEO_FORMAT));
Andreas Huber53df1a42010-12-22 10:03:04 -0800758
Andreas Huber6e3d3112011-11-28 12:36:11 -0800759 bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0;
760
Steve Blockdf64d152012-01-04 20:05:49 +0000761 ALOGI("%s discontinuity (formatChange=%d, time=%d)",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800762 audio ? "audio" : "video", formatChange, timeChange);
Andreas Huber32f3cef2011-03-02 15:34:46 -0800763
Andreas Huber3fe62152011-09-16 15:09:22 -0700764 if (audio) {
765 mSkipRenderingAudioUntilMediaTimeUs = -1;
766 } else {
767 mSkipRenderingVideoUntilMediaTimeUs = -1;
768 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800769
Andreas Huber6e3d3112011-11-28 12:36:11 -0800770 if (timeChange) {
771 sp<AMessage> extra;
772 if (accessUnit->meta()->findMessage("extra", &extra)
773 && extra != NULL) {
774 int64_t resumeAtMediaTimeUs;
775 if (extra->findInt64(
776 "resume-at-mediatimeUs", &resumeAtMediaTimeUs)) {
Steve Blockdf64d152012-01-04 20:05:49 +0000777 ALOGI("suppressing rendering of %s until %lld us",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800778 audio ? "audio" : "video", resumeAtMediaTimeUs);
Andreas Huber3fe62152011-09-16 15:09:22 -0700779
Andreas Huber6e3d3112011-11-28 12:36:11 -0800780 if (audio) {
781 mSkipRenderingAudioUntilMediaTimeUs =
782 resumeAtMediaTimeUs;
783 } else {
784 mSkipRenderingVideoUntilMediaTimeUs =
785 resumeAtMediaTimeUs;
786 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700787 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800788 }
789 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700790
Andreas Huber6e3d3112011-11-28 12:36:11 -0800791 mTimeDiscontinuityPending =
792 mTimeDiscontinuityPending || timeChange;
793
794 if (formatChange || timeChange) {
795 flushDecoder(audio, formatChange);
796 } else {
797 // This stream is unaffected by the discontinuity
798
799 if (audio) {
800 mFlushingAudio = FLUSHED;
801 } else {
802 mFlushingVideo = FLUSHED;
803 }
804
805 finishFlushIfPossible();
806
807 return -EWOULDBLOCK;
808 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800809 }
810
Andreas Huber3fe62152011-09-16 15:09:22 -0700811 reply->setInt32("err", err);
812 reply->post();
813 return OK;
Andreas Huberf9334412010-12-15 15:17:42 -0800814 }
815
Andreas Huber3fe62152011-09-16 15:09:22 -0700816 if (!audio) {
817 ++mNumFramesTotal;
818 }
819
820 dropAccessUnit = false;
821 if (!audio
822 && mVideoLateByUs > 100000ll
823 && mVideoIsAVC
824 && !IsAVCReferenceFrame(accessUnit)) {
825 dropAccessUnit = true;
826 ++mNumFramesDropped;
827 }
828 } while (dropAccessUnit);
Andreas Huberf9334412010-12-15 15:17:42 -0800829
Steve Block3856b092011-10-20 11:56:00 +0100830 // ALOGV("returned a valid buffer of %s data", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800831
832#if 0
833 int64_t mediaTimeUs;
834 CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs));
Steve Block3856b092011-10-20 11:56:00 +0100835 ALOGV("feeding %s input buffer at media time %.2f secs",
Andreas Huberf9334412010-12-15 15:17:42 -0800836 audio ? "audio" : "video",
837 mediaTimeUs / 1E6);
838#endif
839
Andreas Huber2d8bedd2012-02-21 14:38:23 -0800840 reply->setBuffer("buffer", accessUnit);
Andreas Huberf9334412010-12-15 15:17:42 -0800841 reply->post();
842
843 return OK;
844}
845
846void NuPlayer::renderBuffer(bool audio, const sp<AMessage> &msg) {
Steve Block3856b092011-10-20 11:56:00 +0100847 // ALOGV("renderBuffer %s", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800848
849 sp<AMessage> reply;
850 CHECK(msg->findMessage("reply", &reply));
851
Andreas Huber18ac5402011-08-31 15:04:25 -0700852 if (IsFlushingState(audio ? mFlushingAudio : mFlushingVideo)) {
853 // We're currently attempting to flush the decoder, in order
854 // to complete this, the decoder wants all its buffers back,
855 // so we don't want any output buffers it sent us (from before
856 // we initiated the flush) to be stuck in the renderer's queue.
857
Steve Block3856b092011-10-20 11:56:00 +0100858 ALOGV("we're still flushing the %s decoder, sending its output buffer"
Andreas Huber18ac5402011-08-31 15:04:25 -0700859 " right back.", audio ? "audio" : "video");
860
861 reply->post();
862 return;
863 }
864
Andreas Huber2d8bedd2012-02-21 14:38:23 -0800865 sp<ABuffer> buffer;
866 CHECK(msg->findBuffer("buffer", &buffer));
Andreas Huberf9334412010-12-15 15:17:42 -0800867
Andreas Huber32f3cef2011-03-02 15:34:46 -0800868 int64_t &skipUntilMediaTimeUs =
869 audio
870 ? mSkipRenderingAudioUntilMediaTimeUs
871 : mSkipRenderingVideoUntilMediaTimeUs;
872
873 if (skipUntilMediaTimeUs >= 0) {
874 int64_t mediaTimeUs;
875 CHECK(buffer->meta()->findInt64("timeUs", &mediaTimeUs));
876
877 if (mediaTimeUs < skipUntilMediaTimeUs) {
Steve Block3856b092011-10-20 11:56:00 +0100878 ALOGV("dropping %s buffer at time %lld as requested.",
Andreas Huber32f3cef2011-03-02 15:34:46 -0800879 audio ? "audio" : "video",
880 mediaTimeUs);
881
882 reply->post();
883 return;
884 }
885
886 skipUntilMediaTimeUs = -1;
887 }
888
Andreas Huberf9334412010-12-15 15:17:42 -0800889 mRenderer->queueBuffer(audio, buffer, reply);
890}
891
892void NuPlayer::notifyListener(int msg, int ext1, int ext2) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800893 if (mDriver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800894 return;
895 }
896
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800897 sp<NuPlayerDriver> driver = mDriver.promote();
Andreas Huberf9334412010-12-15 15:17:42 -0800898
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800899 if (driver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800900 return;
901 }
902
Andreas Hubera4af2142011-10-26 15:23:31 -0700903 driver->notifyListener(msg, ext1, ext2);
Andreas Huberf9334412010-12-15 15:17:42 -0800904}
905
Andreas Huber1aef2112011-01-04 14:01:29 -0800906void NuPlayer::flushDecoder(bool audio, bool needShutdown) {
Andreas Huber6e3d3112011-11-28 12:36:11 -0800907 if ((audio && mAudioDecoder == NULL) || (!audio && mVideoDecoder == NULL)) {
Steve Blockdf64d152012-01-04 20:05:49 +0000908 ALOGI("flushDecoder %s without decoder present",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800909 audio ? "audio" : "video");
910 }
911
Andreas Huber1aef2112011-01-04 14:01:29 -0800912 // Make sure we don't continue to scan sources until we finish flushing.
913 ++mScanSourcesGeneration;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800914 mScanSourcesPending = false;
Andreas Huber1aef2112011-01-04 14:01:29 -0800915
916 (audio ? mAudioDecoder : mVideoDecoder)->signalFlush();
917 mRenderer->flush(audio);
918
919 FlushStatus newStatus =
920 needShutdown ? FLUSHING_DECODER_SHUTDOWN : FLUSHING_DECODER;
921
922 if (audio) {
923 CHECK(mFlushingAudio == NONE
924 || mFlushingAudio == AWAITING_DISCONTINUITY);
925
926 mFlushingAudio = newStatus;
927
928 if (mFlushingVideo == NONE) {
929 mFlushingVideo = (mVideoDecoder != NULL)
930 ? AWAITING_DISCONTINUITY
931 : FLUSHED;
932 }
933 } else {
934 CHECK(mFlushingVideo == NONE
935 || mFlushingVideo == AWAITING_DISCONTINUITY);
936
937 mFlushingVideo = newStatus;
938
939 if (mFlushingAudio == NONE) {
940 mFlushingAudio = (mAudioDecoder != NULL)
941 ? AWAITING_DISCONTINUITY
942 : FLUSHED;
943 }
944 }
945}
946
Andreas Huber84066782011-08-16 09:34:26 -0700947sp<AMessage> NuPlayer::Source::getFormat(bool audio) {
948 sp<MetaData> meta = getFormatMeta(audio);
949
950 if (meta == NULL) {
951 return NULL;
952 }
953
954 sp<AMessage> msg = new AMessage;
955
956 if(convertMetaDataToMessage(meta, &msg) == OK) {
957 return msg;
958 }
959 return NULL;
960}
961
James Dong53a2d132012-08-31 12:18:27 -0700962status_t NuPlayer::setVideoScalingMode(int32_t mode) {
963 mVideoScalingMode = mode;
James Dong9f235b52012-09-14 15:34:35 -0700964 if (mNativeWindow != NULL
965 && mNativeWindow->getNativeWindow() != NULL) {
James Dong53a2d132012-08-31 12:18:27 -0700966 status_t ret = native_window_set_scaling_mode(
967 mNativeWindow->getNativeWindow().get(), mVideoScalingMode);
968 if (ret != OK) {
969 ALOGE("Failed to set scaling mode (%d): %s",
970 -ret, strerror(-ret));
971 return ret;
972 }
973 }
974 return OK;
975}
976
Andreas Huberf9334412010-12-15 15:17:42 -0800977} // namespace android