blob: dc1e35149eca7d58676bd991c2fefc085ca2acf5 [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 Dong0d268a32012-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 Dong0d268a32012-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 Huberfbe9d812012-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 CHECK_EQ(what, (int32_t)Renderer::kWhatFlushComplete);
517
518 int32_t audio;
519 CHECK(msg->findInt32("audio", &audio));
520
Steve Block3856b092011-10-20 11:56:00 +0100521 ALOGV("renderer %s flush completed.", audio ? "audio" : "video");
James Dongf57b4ea2012-07-20 13:38:36 -0700522 } else if (what == Renderer::kWhatVideoRenderingStart) {
523 notifyListener(MEDIA_INFO, MEDIA_INFO_RENDERING_START, 0);
Andreas Huberf9334412010-12-15 15:17:42 -0800524 }
525 break;
526 }
527
528 case kWhatMoreDataQueued:
529 {
530 break;
531 }
532
Andreas Huber1aef2112011-01-04 14:01:29 -0800533 case kWhatReset:
534 {
Steve Block3856b092011-10-20 11:56:00 +0100535 ALOGV("kWhatReset");
Andreas Huber1aef2112011-01-04 14:01:29 -0800536
Andreas Huberb58ce9f2011-11-28 16:27:35 -0800537 if (mRenderer != NULL) {
538 // There's an edge case where the renderer owns all output
539 // buffers and is paused, therefore the decoder will not read
540 // more input data and will never encounter the matching
541 // discontinuity. To avoid this, we resume the renderer.
542
543 if (mFlushingAudio == AWAITING_DISCONTINUITY
544 || mFlushingVideo == AWAITING_DISCONTINUITY) {
545 mRenderer->resume();
546 }
547 }
548
Andreas Huber1aef2112011-01-04 14:01:29 -0800549 if (mFlushingAudio != NONE || mFlushingVideo != NONE) {
550 // We're currently flushing, postpone the reset until that's
551 // completed.
552
Andreas Huberea9d51b2011-11-30 09:53:40 -0800553 ALOGV("postponing reset mFlushingAudio=%d, mFlushingVideo=%d",
554 mFlushingAudio, mFlushingVideo);
Andreas Huber1aef2112011-01-04 14:01:29 -0800555
556 mResetPostponed = true;
557 break;
558 }
559
560 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
561 finishReset();
562 break;
563 }
564
Andreas Huber6e3d3112011-11-28 12:36:11 -0800565 mTimeDiscontinuityPending = true;
566
Andreas Huber1aef2112011-01-04 14:01:29 -0800567 if (mAudioDecoder != NULL) {
568 flushDecoder(true /* audio */, true /* needShutdown */);
569 }
570
571 if (mVideoDecoder != NULL) {
572 flushDecoder(false /* audio */, true /* needShutdown */);
573 }
574
575 mResetInProgress = true;
576 break;
577 }
578
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800579 case kWhatSeek:
580 {
581 int64_t seekTimeUs;
582 CHECK(msg->findInt64("seekTimeUs", &seekTimeUs));
583
Steve Block3856b092011-10-20 11:56:00 +0100584 ALOGV("kWhatSeek seekTimeUs=%lld us (%.2f secs)",
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800585 seekTimeUs, seekTimeUs / 1E6);
586
587 mSource->seekTo(seekTimeUs);
588
589 if (mDriver != NULL) {
590 sp<NuPlayerDriver> driver = mDriver.promote();
591 if (driver != NULL) {
592 driver->notifySeekComplete();
593 }
594 }
595
596 break;
597 }
598
Andreas Huberb4082222011-01-20 15:23:04 -0800599 case kWhatPause:
600 {
601 CHECK(mRenderer != NULL);
602 mRenderer->pause();
603 break;
604 }
605
606 case kWhatResume:
607 {
608 CHECK(mRenderer != NULL);
609 mRenderer->resume();
610 break;
611 }
612
Andreas Huberf9334412010-12-15 15:17:42 -0800613 default:
614 TRESPASS();
615 break;
616 }
617}
618
Andreas Huber3831a062010-12-21 10:22:33 -0800619void NuPlayer::finishFlushIfPossible() {
620 if (mFlushingAudio != FLUSHED && mFlushingAudio != SHUT_DOWN) {
621 return;
622 }
623
624 if (mFlushingVideo != FLUSHED && mFlushingVideo != SHUT_DOWN) {
625 return;
626 }
627
Steve Block3856b092011-10-20 11:56:00 +0100628 ALOGV("both audio and video are flushed now.");
Andreas Huber3831a062010-12-21 10:22:33 -0800629
Andreas Huber6e3d3112011-11-28 12:36:11 -0800630 if (mTimeDiscontinuityPending) {
631 mRenderer->signalTimeDiscontinuity();
632 mTimeDiscontinuityPending = false;
633 }
Andreas Huber3831a062010-12-21 10:22:33 -0800634
Andreas Huber22fc52f2011-01-05 16:24:27 -0800635 if (mAudioDecoder != NULL) {
Andreas Huber3831a062010-12-21 10:22:33 -0800636 mAudioDecoder->signalResume();
637 }
638
Andreas Huber22fc52f2011-01-05 16:24:27 -0800639 if (mVideoDecoder != NULL) {
Andreas Huber3831a062010-12-21 10:22:33 -0800640 mVideoDecoder->signalResume();
641 }
642
643 mFlushingAudio = NONE;
644 mFlushingVideo = NONE;
Andreas Huber3831a062010-12-21 10:22:33 -0800645
Andreas Huber1aef2112011-01-04 14:01:29 -0800646 if (mResetInProgress) {
Steve Block3856b092011-10-20 11:56:00 +0100647 ALOGV("reset completed");
Andreas Huber1aef2112011-01-04 14:01:29 -0800648
649 mResetInProgress = false;
650 finishReset();
651 } else if (mResetPostponed) {
652 (new AMessage(kWhatReset, id()))->post();
653 mResetPostponed = false;
Andreas Huber22fc52f2011-01-05 16:24:27 -0800654 } else if (mAudioDecoder == NULL || mVideoDecoder == NULL) {
Andreas Huber1aef2112011-01-04 14:01:29 -0800655 postScanSources();
Andreas Huberf9334412010-12-15 15:17:42 -0800656 }
657}
658
Andreas Huber1aef2112011-01-04 14:01:29 -0800659void NuPlayer::finishReset() {
660 CHECK(mAudioDecoder == NULL);
661 CHECK(mVideoDecoder == NULL);
662
Andreas Huber2bfdd422011-10-11 15:24:07 -0700663 ++mScanSourcesGeneration;
664 mScanSourcesPending = false;
665
Andreas Huber1aef2112011-01-04 14:01:29 -0800666 mRenderer.clear();
Andreas Huber2bfdd422011-10-11 15:24:07 -0700667
668 if (mSource != NULL) {
669 mSource->stop();
670 mSource.clear();
671 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800672
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800673 if (mDriver != NULL) {
674 sp<NuPlayerDriver> driver = mDriver.promote();
675 if (driver != NULL) {
676 driver->notifyResetComplete();
677 }
678 }
Andreas Huber1aef2112011-01-04 14:01:29 -0800679}
680
681void NuPlayer::postScanSources() {
682 if (mScanSourcesPending) {
683 return;
684 }
685
686 sp<AMessage> msg = new AMessage(kWhatScanSources, id());
687 msg->setInt32("generation", mScanSourcesGeneration);
688 msg->post();
689
690 mScanSourcesPending = true;
691}
692
Andreas Huber5bc087c2010-12-23 10:27:40 -0800693status_t NuPlayer::instantiateDecoder(bool audio, sp<Decoder> *decoder) {
Andreas Huberf9334412010-12-15 15:17:42 -0800694 if (*decoder != NULL) {
695 return OK;
696 }
697
Andreas Huber84066782011-08-16 09:34:26 -0700698 sp<AMessage> format = mSource->getFormat(audio);
Andreas Huberf9334412010-12-15 15:17:42 -0800699
Andreas Huber84066782011-08-16 09:34:26 -0700700 if (format == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800701 return -EWOULDBLOCK;
702 }
703
Andreas Huber3fe62152011-09-16 15:09:22 -0700704 if (!audio) {
Andreas Huber84066782011-08-16 09:34:26 -0700705 AString mime;
706 CHECK(format->findString("mime", &mime));
707 mVideoIsAVC = !strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime.c_str());
Andreas Huber3fe62152011-09-16 15:09:22 -0700708 }
709
Andreas Huberf9334412010-12-15 15:17:42 -0800710 sp<AMessage> notify =
711 new AMessage(audio ? kWhatAudioNotify : kWhatVideoNotify,
712 id());
713
Glenn Kasten11731182011-02-08 17:26:17 -0800714 *decoder = audio ? new Decoder(notify) :
715 new Decoder(notify, mNativeWindow);
Andreas Huberf9334412010-12-15 15:17:42 -0800716 looper()->registerHandler(*decoder);
717
Andreas Huber84066782011-08-16 09:34:26 -0700718 (*decoder)->configure(format);
Andreas Huberf9334412010-12-15 15:17:42 -0800719
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800720 int64_t durationUs;
721 if (mDriver != NULL && mSource->getDuration(&durationUs) == OK) {
722 sp<NuPlayerDriver> driver = mDriver.promote();
723 if (driver != NULL) {
724 driver->notifyDuration(durationUs);
725 }
726 }
727
Andreas Huberf9334412010-12-15 15:17:42 -0800728 return OK;
729}
730
731status_t NuPlayer::feedDecoderInputData(bool audio, const sp<AMessage> &msg) {
732 sp<AMessage> reply;
733 CHECK(msg->findMessage("reply", &reply));
734
Andreas Huber53df1a42010-12-22 10:03:04 -0800735 if ((audio && IsFlushingState(mFlushingAudio))
736 || (!audio && IsFlushingState(mFlushingVideo))) {
Andreas Huberf9334412010-12-15 15:17:42 -0800737 reply->setInt32("err", INFO_DISCONTINUITY);
738 reply->post();
739 return OK;
740 }
741
742 sp<ABuffer> accessUnit;
Andreas Huberf9334412010-12-15 15:17:42 -0800743
Andreas Huber3fe62152011-09-16 15:09:22 -0700744 bool dropAccessUnit;
745 do {
746 status_t err = mSource->dequeueAccessUnit(audio, &accessUnit);
Andreas Huber5bc087c2010-12-23 10:27:40 -0800747
Andreas Huber3fe62152011-09-16 15:09:22 -0700748 if (err == -EWOULDBLOCK) {
749 return err;
750 } else if (err != OK) {
751 if (err == INFO_DISCONTINUITY) {
752 int32_t type;
753 CHECK(accessUnit->meta()->findInt32("discontinuity", &type));
Andreas Huber53df1a42010-12-22 10:03:04 -0800754
Andreas Huber3fe62152011-09-16 15:09:22 -0700755 bool formatChange =
Andreas Huber6e3d3112011-11-28 12:36:11 -0800756 (audio &&
757 (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT))
758 || (!audio &&
759 (type & ATSParser::DISCONTINUITY_VIDEO_FORMAT));
Andreas Huber53df1a42010-12-22 10:03:04 -0800760
Andreas Huber6e3d3112011-11-28 12:36:11 -0800761 bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0;
762
Steve Blockdf64d152012-01-04 20:05:49 +0000763 ALOGI("%s discontinuity (formatChange=%d, time=%d)",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800764 audio ? "audio" : "video", formatChange, timeChange);
Andreas Huber32f3cef2011-03-02 15:34:46 -0800765
Andreas Huber3fe62152011-09-16 15:09:22 -0700766 if (audio) {
767 mSkipRenderingAudioUntilMediaTimeUs = -1;
768 } else {
769 mSkipRenderingVideoUntilMediaTimeUs = -1;
770 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800771
Andreas Huber6e3d3112011-11-28 12:36:11 -0800772 if (timeChange) {
773 sp<AMessage> extra;
774 if (accessUnit->meta()->findMessage("extra", &extra)
775 && extra != NULL) {
776 int64_t resumeAtMediaTimeUs;
777 if (extra->findInt64(
778 "resume-at-mediatimeUs", &resumeAtMediaTimeUs)) {
Steve Blockdf64d152012-01-04 20:05:49 +0000779 ALOGI("suppressing rendering of %s until %lld us",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800780 audio ? "audio" : "video", resumeAtMediaTimeUs);
Andreas Huber3fe62152011-09-16 15:09:22 -0700781
Andreas Huber6e3d3112011-11-28 12:36:11 -0800782 if (audio) {
783 mSkipRenderingAudioUntilMediaTimeUs =
784 resumeAtMediaTimeUs;
785 } else {
786 mSkipRenderingVideoUntilMediaTimeUs =
787 resumeAtMediaTimeUs;
788 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700789 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800790 }
791 }
Andreas Huber3fe62152011-09-16 15:09:22 -0700792
Andreas Huber6e3d3112011-11-28 12:36:11 -0800793 mTimeDiscontinuityPending =
794 mTimeDiscontinuityPending || timeChange;
795
796 if (formatChange || timeChange) {
797 flushDecoder(audio, formatChange);
798 } else {
799 // This stream is unaffected by the discontinuity
800
801 if (audio) {
802 mFlushingAudio = FLUSHED;
803 } else {
804 mFlushingVideo = FLUSHED;
805 }
806
807 finishFlushIfPossible();
808
809 return -EWOULDBLOCK;
810 }
Andreas Huber32f3cef2011-03-02 15:34:46 -0800811 }
812
Andreas Huber3fe62152011-09-16 15:09:22 -0700813 reply->setInt32("err", err);
814 reply->post();
815 return OK;
Andreas Huberf9334412010-12-15 15:17:42 -0800816 }
817
Andreas Huber3fe62152011-09-16 15:09:22 -0700818 if (!audio) {
819 ++mNumFramesTotal;
820 }
821
822 dropAccessUnit = false;
823 if (!audio
824 && mVideoLateByUs > 100000ll
825 && mVideoIsAVC
826 && !IsAVCReferenceFrame(accessUnit)) {
827 dropAccessUnit = true;
828 ++mNumFramesDropped;
829 }
830 } while (dropAccessUnit);
Andreas Huberf9334412010-12-15 15:17:42 -0800831
Steve Block3856b092011-10-20 11:56:00 +0100832 // ALOGV("returned a valid buffer of %s data", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800833
834#if 0
835 int64_t mediaTimeUs;
836 CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs));
Steve Block3856b092011-10-20 11:56:00 +0100837 ALOGV("feeding %s input buffer at media time %.2f secs",
Andreas Huberf9334412010-12-15 15:17:42 -0800838 audio ? "audio" : "video",
839 mediaTimeUs / 1E6);
840#endif
841
Andreas Huber2d8bedd2012-02-21 14:38:23 -0800842 reply->setBuffer("buffer", accessUnit);
Andreas Huberf9334412010-12-15 15:17:42 -0800843 reply->post();
844
845 return OK;
846}
847
848void NuPlayer::renderBuffer(bool audio, const sp<AMessage> &msg) {
Steve Block3856b092011-10-20 11:56:00 +0100849 // ALOGV("renderBuffer %s", audio ? "audio" : "video");
Andreas Huberf9334412010-12-15 15:17:42 -0800850
851 sp<AMessage> reply;
852 CHECK(msg->findMessage("reply", &reply));
853
Andreas Huber18ac5402011-08-31 15:04:25 -0700854 if (IsFlushingState(audio ? mFlushingAudio : mFlushingVideo)) {
855 // We're currently attempting to flush the decoder, in order
856 // to complete this, the decoder wants all its buffers back,
857 // so we don't want any output buffers it sent us (from before
858 // we initiated the flush) to be stuck in the renderer's queue.
859
Steve Block3856b092011-10-20 11:56:00 +0100860 ALOGV("we're still flushing the %s decoder, sending its output buffer"
Andreas Huber18ac5402011-08-31 15:04:25 -0700861 " right back.", audio ? "audio" : "video");
862
863 reply->post();
864 return;
865 }
866
Andreas Huber2d8bedd2012-02-21 14:38:23 -0800867 sp<ABuffer> buffer;
868 CHECK(msg->findBuffer("buffer", &buffer));
Andreas Huberf9334412010-12-15 15:17:42 -0800869
Andreas Huber32f3cef2011-03-02 15:34:46 -0800870 int64_t &skipUntilMediaTimeUs =
871 audio
872 ? mSkipRenderingAudioUntilMediaTimeUs
873 : mSkipRenderingVideoUntilMediaTimeUs;
874
875 if (skipUntilMediaTimeUs >= 0) {
876 int64_t mediaTimeUs;
877 CHECK(buffer->meta()->findInt64("timeUs", &mediaTimeUs));
878
879 if (mediaTimeUs < skipUntilMediaTimeUs) {
Steve Block3856b092011-10-20 11:56:00 +0100880 ALOGV("dropping %s buffer at time %lld as requested.",
Andreas Huber32f3cef2011-03-02 15:34:46 -0800881 audio ? "audio" : "video",
882 mediaTimeUs);
883
884 reply->post();
885 return;
886 }
887
888 skipUntilMediaTimeUs = -1;
889 }
890
Andreas Huberf9334412010-12-15 15:17:42 -0800891 mRenderer->queueBuffer(audio, buffer, reply);
892}
893
894void NuPlayer::notifyListener(int msg, int ext1, int ext2) {
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800895 if (mDriver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800896 return;
897 }
898
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800899 sp<NuPlayerDriver> driver = mDriver.promote();
Andreas Huberf9334412010-12-15 15:17:42 -0800900
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800901 if (driver == NULL) {
Andreas Huberf9334412010-12-15 15:17:42 -0800902 return;
903 }
904
Andreas Hubera4af2142011-10-26 15:23:31 -0700905 driver->notifyListener(msg, ext1, ext2);
Andreas Huberf9334412010-12-15 15:17:42 -0800906}
907
Andreas Huber1aef2112011-01-04 14:01:29 -0800908void NuPlayer::flushDecoder(bool audio, bool needShutdown) {
Andreas Huber6e3d3112011-11-28 12:36:11 -0800909 if ((audio && mAudioDecoder == NULL) || (!audio && mVideoDecoder == NULL)) {
Steve Blockdf64d152012-01-04 20:05:49 +0000910 ALOGI("flushDecoder %s without decoder present",
Andreas Huber6e3d3112011-11-28 12:36:11 -0800911 audio ? "audio" : "video");
912 }
913
Andreas Huber1aef2112011-01-04 14:01:29 -0800914 // Make sure we don't continue to scan sources until we finish flushing.
915 ++mScanSourcesGeneration;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800916 mScanSourcesPending = false;
Andreas Huber1aef2112011-01-04 14:01:29 -0800917
918 (audio ? mAudioDecoder : mVideoDecoder)->signalFlush();
919 mRenderer->flush(audio);
920
921 FlushStatus newStatus =
922 needShutdown ? FLUSHING_DECODER_SHUTDOWN : FLUSHING_DECODER;
923
924 if (audio) {
925 CHECK(mFlushingAudio == NONE
926 || mFlushingAudio == AWAITING_DISCONTINUITY);
927
928 mFlushingAudio = newStatus;
929
930 if (mFlushingVideo == NONE) {
931 mFlushingVideo = (mVideoDecoder != NULL)
932 ? AWAITING_DISCONTINUITY
933 : FLUSHED;
934 }
935 } else {
936 CHECK(mFlushingVideo == NONE
937 || mFlushingVideo == AWAITING_DISCONTINUITY);
938
939 mFlushingVideo = newStatus;
940
941 if (mFlushingAudio == NONE) {
942 mFlushingAudio = (mAudioDecoder != NULL)
943 ? AWAITING_DISCONTINUITY
944 : FLUSHED;
945 }
946 }
947}
948
Andreas Huber84066782011-08-16 09:34:26 -0700949sp<AMessage> NuPlayer::Source::getFormat(bool audio) {
950 sp<MetaData> meta = getFormatMeta(audio);
951
952 if (meta == NULL) {
953 return NULL;
954 }
955
956 sp<AMessage> msg = new AMessage;
957
958 if(convertMetaDataToMessage(meta, &msg) == OK) {
959 return msg;
960 }
961 return NULL;
962}
963
James Dong0d268a32012-08-31 12:18:27 -0700964status_t NuPlayer::setVideoScalingMode(int32_t mode) {
965 mVideoScalingMode = mode;
966 if (mNativeWindow != NULL) {
967 status_t ret = native_window_set_scaling_mode(
968 mNativeWindow->getNativeWindow().get(), mVideoScalingMode);
969 if (ret != OK) {
970 ALOGE("Failed to set scaling mode (%d): %s",
971 -ret, strerror(-ret));
972 return ret;
973 }
974 }
975 return OK;
976}
977
Andreas Huberf9334412010-12-15 15:17:42 -0800978} // namespace android