blob: 9bae14a7d5e5aad48e023087849dfb7dfcebaa77 [file] [log] [blame]
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001/*
2 * Copyright (C) 2011 NXP Software
3 * Copyright (C) 2011 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Santosh Madhavabfece172011-02-03 16:59:47 -080018
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080019#define LOG_NDEBUG 1
20#define LOG_TAG "PreviewPlayer"
21#include <utils/Log.h>
22
23#include <dlfcn.h>
24
25#include "include/ARTSPController.h"
26#include "PreviewPlayer.h"
27#include "DummyAudioSource.h"
28#include "DummyVideoSource.h"
29#include "VideoEditorSRC.h"
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080030#include "include/NuCachedSource2.h"
31#include "include/ThrottledSource.h"
32
33
34#include "PreviewRenderer.h"
35
36#include <binder/IPCThreadState.h>
37#include <media/stagefright/DataSource.h>
38#include <media/stagefright/FileSource.h>
39#include <media/stagefright/MediaBuffer.h>
40#include <media/stagefright/MediaDefs.h>
41#include <media/stagefright/MediaExtractor.h>
42#include <media/stagefright/MediaDebug.h>
43#include <media/stagefright/MediaSource.h>
44#include <media/stagefright/MetaData.h>
45#include <media/stagefright/OMXCodec.h>
46
47#include <surfaceflinger/Surface.h>
48#include <media/stagefright/foundation/ALooper.h>
49
50namespace android {
51
52
53struct PreviewPlayerEvent : public TimedEventQueue::Event {
54 PreviewPlayerEvent(
55 PreviewPlayer *player,
56 void (PreviewPlayer::*method)())
57 : mPlayer(player),
58 mMethod(method) {
59 }
60
61protected:
62 virtual ~PreviewPlayerEvent() {}
63
64 virtual void fire(TimedEventQueue *queue, int64_t /* now_us */) {
65 (mPlayer->*mMethod)();
66 }
67
68private:
69 PreviewPlayer *mPlayer;
70 void (PreviewPlayer::*mMethod)();
71
72 PreviewPlayerEvent(const PreviewPlayerEvent &);
73 PreviewPlayerEvent &operator=(const PreviewPlayerEvent &);
74};
75
76
77struct PreviewLocalRenderer : public PreviewPlayerRenderer {
Santosh Madhavabfece172011-02-03 16:59:47 -080078
79 static PreviewLocalRenderer* initPreviewLocalRenderer (
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080080 bool previewOnly,
81 OMX_COLOR_FORMATTYPE colorFormat,
82 const sp<Surface> &surface,
83 size_t displayWidth, size_t displayHeight,
84 size_t decodedWidth, size_t decodedHeight,
85 int32_t rotationDegrees = 0)
Santosh Madhavabfece172011-02-03 16:59:47 -080086 {
87 PreviewLocalRenderer* mLocalRenderer = new
88 PreviewLocalRenderer(
89 previewOnly,
90 colorFormat,
91 surface,
92 displayWidth, displayHeight,
93 decodedWidth, decodedHeight,
94 rotationDegrees);
95
96 if ( mLocalRenderer->init(previewOnly,
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080097 colorFormat, surface,
98 displayWidth, displayHeight,
99 decodedWidth, decodedHeight,
Santosh Madhavabfece172011-02-03 16:59:47 -0800100 rotationDegrees) != OK )
101 {
102 delete mLocalRenderer;
103 return NULL;
104 }
105 return mLocalRenderer;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800106 }
107
108 virtual void render(MediaBuffer *buffer) {
109 render((const uint8_t *)buffer->data() + buffer->range_offset(),
110 buffer->range_length());
111 }
112
113 void render(const void *data, size_t size) {
114 mTarget->render(data, size, NULL);
115 }
116 void render() {
117 mTarget->renderYV12();
118 }
119 void getBuffer(uint8_t **data, size_t *stride) {
120 mTarget->getBufferYV12(data, stride);
121 }
122
123protected:
124 virtual ~PreviewLocalRenderer() {
125 delete mTarget;
126 mTarget = NULL;
127 }
128
129private:
130 PreviewRenderer *mTarget;
131
Santosh Madhavabfece172011-02-03 16:59:47 -0800132 PreviewLocalRenderer(
133 bool previewOnly,
134 OMX_COLOR_FORMATTYPE colorFormat,
135 const sp<Surface> &surface,
136 size_t displayWidth, size_t displayHeight,
137 size_t decodedWidth, size_t decodedHeight,
138 int32_t rotationDegrees = 0)
139 : mTarget(NULL) {
140 }
141
142
143 int init(
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800144 bool previewOnly,
145 OMX_COLOR_FORMATTYPE colorFormat,
146 const sp<Surface> &surface,
147 size_t displayWidth, size_t displayHeight,
148 size_t decodedWidth, size_t decodedHeight,
149 int32_t rotationDegrees = 0);
150
151 PreviewLocalRenderer(const PreviewLocalRenderer &);
152 PreviewLocalRenderer &operator=(const PreviewLocalRenderer &);;
153};
154
Santosh Madhavabfece172011-02-03 16:59:47 -0800155int PreviewLocalRenderer::init(
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800156 bool previewOnly,
157 OMX_COLOR_FORMATTYPE colorFormat,
158 const sp<Surface> &surface,
159 size_t displayWidth, size_t displayHeight,
160 size_t decodedWidth, size_t decodedHeight,
161 int32_t rotationDegrees) {
Santosh Madhavabfece172011-02-03 16:59:47 -0800162
163 mTarget = PreviewRenderer::CreatePreviewRenderer (
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800164 colorFormat, surface, displayWidth, displayHeight,
165 decodedWidth, decodedHeight, rotationDegrees);
Santosh Madhavabfece172011-02-03 16:59:47 -0800166 if (mTarget == M4OSA_NULL) {
167 return UNKNOWN_ERROR;
168 }
169 return OK;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800170}
171
172PreviewPlayer::PreviewPlayer()
173 : AwesomePlayer(),
174 mFrameRGBBuffer(NULL),
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -0800175 mFrameYUVBuffer(NULL),
176 mReportedWidth(0),
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800177 mReportedHeight(0),
178 mCurrFramingEffectIndex(0) {
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800179
180 mVideoRenderer = NULL;
181 mLastVideoBuffer = NULL;
182 mSuspensionState = NULL;
183 mEffectsSettings = NULL;
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800184 mVeAudioPlayer = NULL;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800185 mAudioMixStoryBoardTS = 0;
186 mCurrentMediaBeginCutTime = 0;
187 mCurrentMediaVolumeValue = 0;
188 mNumberEffects = 0;
189 mDecodedVideoTs = 0;
190 mDecVideoTsStoryBoard = 0;
191 mCurrentVideoEffect = VIDEO_EFFECT_NONE;
192 mProgressCbInterval = 0;
193 mNumberDecVideoFrames = 0;
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800194 mOverlayUpdateEventPosted = false;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800195
196 mVideoEvent = new PreviewPlayerEvent(this, &PreviewPlayer::onVideoEvent);
197 mVideoEventPending = false;
198 mStreamDoneEvent = new PreviewPlayerEvent(this,
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800199 &AwesomePlayer::onStreamDone);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800200
201 mStreamDoneEventPending = false;
202
203 mCheckAudioStatusEvent = new PreviewPlayerEvent(
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800204 this, &AwesomePlayer::onCheckAudioStatus);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800205
206 mAudioStatusEventPending = false;
207
208 mProgressCbEvent = new PreviewPlayerEvent(this,
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800209 &PreviewPlayer::onProgressCbEvent);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800210
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800211 mOverlayUpdateEvent = new PreviewPlayerEvent(this,
212 &PreviewPlayer::onUpdateOverlayEvent);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800213 mProgressCbEventPending = false;
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800214
215 mOverlayUpdateEventPending = false;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800216 mResizedVideoBuffer = NULL;
217 mVideoResizedOrCropped = false;
218 mRenderingMode = (M4xVSS_MediaRendering)MEDIA_RENDERING_INVALID;
219 mIsFiftiesEffectStarted = false;
220 reset();
221}
222
223PreviewPlayer::~PreviewPlayer() {
224
225 if (mQueueStarted) {
226 mQueue.stop();
227 }
228
229 reset();
230
231 if(mResizedVideoBuffer != NULL) {
232 M4OSA_free((M4OSA_MemAddr32)(mResizedVideoBuffer->data()));
233 mResizedVideoBuffer = NULL;
234 }
235
236 mVideoRenderer.clear();
237 mVideoRenderer = NULL;
238}
239
240void PreviewPlayer::cancelPlayerEvents(bool keepBufferingGoing) {
241 mQueue.cancelEvent(mVideoEvent->eventID());
242 mVideoEventPending = false;
243 mQueue.cancelEvent(mStreamDoneEvent->eventID());
244 mStreamDoneEventPending = false;
245 mQueue.cancelEvent(mCheckAudioStatusEvent->eventID());
246 mAudioStatusEventPending = false;
247
248 mQueue.cancelEvent(mProgressCbEvent->eventID());
249 mProgressCbEventPending = false;
250}
251
252status_t PreviewPlayer::setDataSource(
253 const char *uri, const KeyedVector<String8, String8> *headers) {
254 Mutex::Autolock autoLock(mLock);
255 return setDataSource_l(uri, headers);
256}
257
258status_t PreviewPlayer::setDataSource_l(
259 const char *uri, const KeyedVector<String8, String8> *headers) {
260 reset_l();
261
262 mUri = uri;
263
264 if (headers) {
265 mUriHeaders = *headers;
266 }
267
268 // The actual work will be done during preparation in the call to
269 // ::finishSetDataSource_l to avoid blocking the calling thread in
270 // setDataSource for any significant time.
271 return OK;
272}
273
274status_t PreviewPlayer::setDataSource_l(const sp<MediaExtractor> &extractor) {
275 bool haveAudio = false;
276 bool haveVideo = false;
277 for (size_t i = 0; i < extractor->countTracks(); ++i) {
278 sp<MetaData> meta = extractor->getTrackMetaData(i);
279
280 const char *mime;
281 CHECK(meta->findCString(kKeyMIMEType, &mime));
282
283 if (!haveVideo && !strncasecmp(mime, "video/", 6)) {
284 setVideoSource(extractor->getTrack(i));
285 haveVideo = true;
286 } else if (!haveAudio && !strncasecmp(mime, "audio/", 6)) {
287 setAudioSource(extractor->getTrack(i));
288 haveAudio = true;
289
290 if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_VORBIS)) {
291 // Only do this for vorbis audio, none of the other audio
292 // formats even support this ringtone specific hack and
293 // retrieving the metadata on some extractors may turn out
294 // to be very expensive.
295 sp<MetaData> fileMeta = extractor->getMetaData();
296 int32_t loop;
297 if (fileMeta != NULL
298 && fileMeta->findInt32(kKeyAutoLoop, &loop)
299 && loop != 0) {
300 mFlags |= AUTO_LOOPING;
301 }
302 }
303 }
304
305 if (haveAudio && haveVideo) {
306 break;
307 }
308 }
309
310 /* Add the support for Dummy audio*/
311 if( !haveAudio ){
312 LOGV("PreviewPlayer: setDataSource_l Dummyaudiocreation started");
313
314 mAudioTrack = DummyAudioSource::Create(32000, 2, 20000,
315 ((mPlayEndTimeMsec)*1000));
316 LOGV("PreviewPlayer: setDataSource_l Dummyauiosource created");
317 if(mAudioTrack != NULL) {
318 haveAudio = true;
319 }
320 }
321
322 if (!haveAudio && !haveVideo) {
323 return UNKNOWN_ERROR;
324 }
325
326 mExtractorFlags = extractor->flags();
327 return OK;
328}
329
330status_t PreviewPlayer::setDataSource_l_jpg() {
331 M4OSA_ERR err = M4NO_ERROR;
332 LOGV("PreviewPlayer: setDataSource_l_jpg started");
333
334 mAudioSource = DummyAudioSource::Create(32000, 2, 20000,
335 ((mPlayEndTimeMsec)*1000));
336 LOGV("PreviewPlayer: setDataSource_l_jpg Dummyaudiosource created");
337 if(mAudioSource != NULL) {
338 setAudioSource(mAudioSource);
339 }
340 status_t error = mAudioSource->start();
341 if (error != OK) {
342 LOGV("Error starting dummy audio source");
343 mAudioSource.clear();
344 return err;
345 }
346
347 mDurationUs = (mPlayEndTimeMsec - mPlayBeginTimeMsec)*1000;
348
349 mVideoSource = DummyVideoSource::Create(mVideoWidth, mVideoHeight,
350 mDurationUs, mUri);
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -0800351 mReportedWidth = mVideoWidth;
352 mReportedHeight = mVideoHeight;
353
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800354 setVideoSource(mVideoSource);
355 status_t err1 = mVideoSource->start();
356 if (err1 != OK) {
357 mVideoSource.clear();
358 return err;
359 }
360
361 mIsVideoSourceJpg = true;
362 return OK;
363}
364
365void PreviewPlayer::reset() {
366 Mutex::Autolock autoLock(mLock);
367 reset_l();
368}
369
370void PreviewPlayer::reset_l() {
371
372 if (mFlags & PREPARING) {
373 mFlags |= PREPARE_CANCELLED;
374 }
375
376 while (mFlags & PREPARING) {
377 mPreparedCondition.wait(mLock);
378 }
379
380 cancelPlayerEvents();
381 mAudioTrack.clear();
382 mVideoTrack.clear();
383
384 // Shutdown audio first, so that the respone to the reset request
385 // appears to happen instantaneously as far as the user is concerned
386 // If we did this later, audio would continue playing while we
387 // shutdown the video-related resources and the player appear to
388 // not be as responsive to a reset request.
389 if (mAudioPlayer == NULL && mAudioSource != NULL) {
390 // If we had an audio player, it would have effectively
391 // taken possession of the audio source and stopped it when
392 // _it_ is stopped. Otherwise this is still our responsibility.
393 mAudioSource->stop();
394 }
395 mAudioSource.clear();
396
397 mTimeSource = NULL;
398
399 delete mAudioPlayer;
400 mAudioPlayer = NULL;
401
402 if (mLastVideoBuffer) {
403 mLastVideoBuffer->release();
404 mLastVideoBuffer = NULL;
405 }
406
407 if (mVideoBuffer) {
408 mVideoBuffer->release();
409 mVideoBuffer = NULL;
410 }
411
412 if (mVideoSource != NULL) {
413 mVideoSource->stop();
414
415 // The following hack is necessary to ensure that the OMX
416 // component is completely released by the time we may try
417 // to instantiate it again.
418 wp<MediaSource> tmp = mVideoSource;
419 mVideoSource.clear();
420 while (tmp.promote() != NULL) {
421 usleep(1000);
422 }
423 IPCThreadState::self()->flushCommands();
424 }
425
426 mDurationUs = -1;
427 mFlags = 0;
428 mExtractorFlags = 0;
429 mVideoWidth = mVideoHeight = -1;
430 mTimeSourceDeltaUs = 0;
431 mVideoTimeUs = 0;
432
433 mSeeking = false;
434 mSeekNotificationSent = false;
435 mSeekTimeUs = 0;
436
437 mUri.setTo("");
438 mUriHeaders.clear();
439
440 mFileSource.clear();
441
442 delete mSuspensionState;
443 mSuspensionState = NULL;
444
445 mCurrentVideoEffect = VIDEO_EFFECT_NONE;
446 mIsVideoSourceJpg = false;
447 mFrameRGBBuffer = NULL;
448 if(mFrameYUVBuffer != NULL) {
449 M4OSA_free((M4OSA_MemAddr32)mFrameYUVBuffer);
450 mFrameYUVBuffer = NULL;
451 }
452}
453
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800454status_t PreviewPlayer::play() {
455 Mutex::Autolock autoLock(mLock);
456
457 mFlags &= ~CACHE_UNDERRUN;
458
459 return play_l();
460}
461
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800462status_t PreviewPlayer::startAudioPlayer_l() {
463 CHECK(!(mFlags & AUDIO_RUNNING));
464
465 if (mAudioSource == NULL || mAudioPlayer == NULL) {
466 return OK;
467 }
468
469 if (!(mFlags & AUDIOPLAYER_STARTED)) {
470 mFlags |= AUDIOPLAYER_STARTED;
471
472 // We've already started the MediaSource in order to enable
473 // the prefetcher to read its data.
474 status_t err = mVeAudioPlayer->start(
475 true /* sourceAlreadyStarted */);
476
477 if (err != OK) {
478 notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
479 return err;
480 }
481 } else {
482 mVeAudioPlayer->resume();
483 }
484
485 mFlags |= AUDIO_RUNNING;
486
487 mWatchForAudioEOS = true;
488
489 return OK;
490}
491
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800492status_t PreviewPlayer::play_l() {
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800493
Rajneesh Chowdury8b95de22011-02-16 15:32:06 -0800494 mFlags &= ~SEEK_PREVIEW;
495
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800496 if (mFlags & PLAYING) {
497 return OK;
498 }
499 mStartNextPlayer = false;
500
501 if (!(mFlags & PREPARED)) {
502 status_t err = prepare_l();
503
504 if (err != OK) {
505 return err;
506 }
507 }
508
509 mFlags |= PLAYING;
510 mFlags |= FIRST_FRAME;
511
512 bool deferredAudioSeek = false;
513
514 if (mAudioSource != NULL) {
515 if (mAudioPlayer == NULL) {
516 if (mAudioSink != NULL) {
517
518 mAudioPlayer = new VideoEditorAudioPlayer(mAudioSink, this);
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800519 mVeAudioPlayer =
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800520 (VideoEditorAudioPlayer*)mAudioPlayer;
521
522 mAudioPlayer->setSource(mAudioSource);
523
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800524 mVeAudioPlayer->setAudioMixSettings(
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800525 mPreviewPlayerAudioMixSettings);
526
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800527 mVeAudioPlayer->setAudioMixPCMFileHandle(
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800528 mAudioMixPCMFileHandle);
529
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800530 mVeAudioPlayer->setAudioMixStoryBoardSkimTimeStamp(
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800531 mAudioMixStoryBoardTS, mCurrentMediaBeginCutTime,
532 mCurrentMediaVolumeValue);
533
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800534 mTimeSource = mVeAudioPlayer; //mAudioPlayer;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800535
536 deferredAudioSeek = true;
537 mWatchForAudioSeekComplete = false;
538 mWatchForAudioEOS = true;
539 }
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800540 }
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800541
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800542 CHECK(!(mFlags & AUDIO_RUNNING));
543
544 if (mVideoSource == NULL) {
545 status_t err = startAudioPlayer_l();
546
547 if (err != OK) {
548 delete mAudioPlayer;
549 mAudioPlayer = NULL;
550 mFlags &= ~(PLAYING | FIRST_FRAME);
551 return err;
552 }
553 }
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800554 }
555
556 if (mTimeSource == NULL && mAudioPlayer == NULL) {
557 mTimeSource = &mSystemTimeSource;
558 }
559
Dharmaray Kundargi53c567c2011-01-29 18:52:50 -0800560 // Set the seek option for Image source files and read.
561 // This resets the timestamping for image play
562 if (mIsVideoSourceJpg) {
563 MediaSource::ReadOptions options;
564 MediaBuffer *aLocalBuffer;
565 options.setSeekTo(mSeekTimeUs);
566 mVideoSource->read(&aLocalBuffer, &options);
Santosh Madhava4ca3e5d2011-02-11 20:28:45 -0800567 aLocalBuffer->release();
Dharmaray Kundargi53c567c2011-01-29 18:52:50 -0800568 }
569
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800570 if (mVideoSource != NULL) {
571 // Kick off video playback
572 postVideoEvent_l();
573 }
574
575 if (deferredAudioSeek) {
576 // If there was a seek request while we were paused
577 // and we're just starting up again, honor the request now.
578 seekAudioIfNecessary_l();
579 }
580
581 if (mFlags & AT_EOS) {
582 // Legacy behaviour, if a stream finishes playing and then
583 // is started again, we play from the start...
584 seekTo_l(0);
585 }
586
587 return OK;
588}
589
590
Santosh Madhavabfece172011-02-03 16:59:47 -0800591status_t PreviewPlayer::initRenderer_l() {
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800592 if (mSurface != NULL || mISurface != NULL) {
593 sp<MetaData> meta = mVideoSource->getFormat();
594
595 int32_t format;
596 const char *component;
597 int32_t decodedWidth, decodedHeight;
598 CHECK(meta->findInt32(kKeyColorFormat, &format));
599 CHECK(meta->findCString(kKeyDecoderComponent, &component));
600 CHECK(meta->findInt32(kKeyWidth, &decodedWidth));
601 CHECK(meta->findInt32(kKeyHeight, &decodedHeight));
602
603 // Must ensure that mVideoRenderer's destructor is actually executed
604 // before creating a new one.
605 IPCThreadState::self()->flushCommands();
606
607 // always use localrenderer since decoded buffers are modified
608 // by postprocessing module
609 // Other decoders are instantiated locally and as a consequence
610 // allocate their buffers in local address space.
611 if(mVideoRenderer == NULL) {
612
Santosh Madhavabfece172011-02-03 16:59:47 -0800613 mVideoRenderer = PreviewLocalRenderer:: initPreviewLocalRenderer (
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800614 false, // previewOnly
615 (OMX_COLOR_FORMATTYPE)format,
616 mSurface,
617 mOutputVideoWidth, mOutputVideoHeight,
618 mOutputVideoWidth, mOutputVideoHeight);
Santosh Madhavabfece172011-02-03 16:59:47 -0800619
620 if ( mVideoRenderer == NULL )
621 {
622 return UNKNOWN_ERROR;
623 }
624 return OK;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800625 }
626 }
Santosh Madhavabfece172011-02-03 16:59:47 -0800627 return OK;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800628}
629
630
631void PreviewPlayer::setISurface(const sp<ISurface> &isurface) {
632 Mutex::Autolock autoLock(mLock);
633 mISurface = isurface;
634}
635
636
637status_t PreviewPlayer::seekTo(int64_t timeUs) {
638
639 if ((mExtractorFlags & MediaExtractor::CAN_SEEK) || (mIsVideoSourceJpg)) {
640 Mutex::Autolock autoLock(mLock);
641 return seekTo_l(timeUs);
642 }
643
644 return OK;
645}
646
647
648status_t PreviewPlayer::getVideoDimensions(
649 int32_t *width, int32_t *height) const {
650 Mutex::Autolock autoLock(mLock);
651
652 if (mVideoWidth < 0 || mVideoHeight < 0) {
653 return UNKNOWN_ERROR;
654 }
655
656 *width = mVideoWidth;
657 *height = mVideoHeight;
658
659 return OK;
660}
661
662
663status_t PreviewPlayer::initAudioDecoder() {
664 sp<MetaData> meta = mAudioTrack->getFormat();
665 const char *mime;
666 CHECK(meta->findCString(kKeyMIMEType, &mime));
667
668 if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_RAW)) {
669 mAudioSource = mAudioTrack;
670 } else {
671 sp<MediaSource> aRawSource;
672 aRawSource = OMXCodec::Create(
673 mClient.interface(), mAudioTrack->getFormat(),
674 false, // createEncoder
675 mAudioTrack);
676
677 if(aRawSource != NULL) {
678 LOGV("initAudioDecoder: new VideoEditorSRC");
679 mAudioSource = new VideoEditorSRC(aRawSource);
680 }
681 }
682
683 if (mAudioSource != NULL) {
684 int64_t durationUs;
685 if (mAudioTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {
686 Mutex::Autolock autoLock(mMiscStateLock);
687 if (mDurationUs < 0 || durationUs > mDurationUs) {
688 mDurationUs = durationUs;
689 }
690 }
691 status_t err = mAudioSource->start();
692
693 if (err != OK) {
694 mAudioSource.clear();
695 return err;
696 }
697 } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_QCELP)) {
698 // For legacy reasons we're simply going to ignore the absence
699 // of an audio decoder for QCELP instead of aborting playback
700 // altogether.
701 return OK;
702 }
703
704 return mAudioSource != NULL ? OK : UNKNOWN_ERROR;
705}
706
707
708status_t PreviewPlayer::initVideoDecoder(uint32_t flags) {
709
710 mVideoSource = OMXCodec::Create(
711 mClient.interface(), mVideoTrack->getFormat(),
712 false,
713 mVideoTrack,
714 NULL, flags);
715
716 if (mVideoSource != NULL) {
717 int64_t durationUs;
718 if (mVideoTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {
719 Mutex::Autolock autoLock(mMiscStateLock);
720 if (mDurationUs < 0 || durationUs > mDurationUs) {
721 mDurationUs = durationUs;
722 }
723 }
724
725 CHECK(mVideoTrack->getFormat()->findInt32(kKeyWidth, &mVideoWidth));
726 CHECK(mVideoTrack->getFormat()->findInt32(kKeyHeight, &mVideoHeight));
727
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -0800728 mReportedWidth = mVideoWidth;
729 mReportedHeight = mVideoHeight;
730
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800731 status_t err = mVideoSource->start();
732
733 if (err != OK) {
734 mVideoSource.clear();
735 return err;
736 }
737 }
738
739 return mVideoSource != NULL ? OK : UNKNOWN_ERROR;
740}
741
742
743void PreviewPlayer::onVideoEvent() {
744 uint32_t i=0;
745 bool bAppliedVideoEffect = false;
746 M4OSA_ERR err1 = M4NO_ERROR;
747 int64_t imageFrameTimeUs = 0;
748
749 Mutex::Autolock autoLock(mLock);
750 if (!mVideoEventPending) {
751 // The event has been cancelled in reset_l() but had already
752 // been scheduled for execution at that time.
753 return;
754 }
755 mVideoEventPending = false;
756
Andreas Huber9e4c36a2011-02-08 13:12:32 -0800757 if (mFlags & SEEK_PREVIEW) {
758 mFlags &= ~SEEK_PREVIEW;
759 return;
760 }
761
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800762 TimeSource *ts_st = &mSystemTimeSource;
763 int64_t timeStartUs = ts_st->getRealTimeUs();
764
765 if (mSeeking) {
766 if (mLastVideoBuffer) {
767 mLastVideoBuffer->release();
768 mLastVideoBuffer = NULL;
769 }
770
771
772 if(mAudioSource != NULL) {
773
774 // We're going to seek the video source first, followed by
775 // the audio source.
776 // In order to avoid jumps in the DataSource offset caused by
777 // the audio codec prefetching data from the old locations
778 // while the video codec is already reading data from the new
779 // locations, we'll "pause" the audio source, causing it to
780 // stop reading input data until a subsequent seek.
781
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800782 if (mAudioPlayer != NULL && (mFlags & AUDIO_RUNNING)) {
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800783 mAudioPlayer->pause();
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800784 mFlags &= ~AUDIO_RUNNING;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800785 }
786 mAudioSource->pause();
787 }
788 }
789
790 if (!mVideoBuffer) {
791 MediaSource::ReadOptions options;
792 if (mSeeking) {
793 LOGV("LV PLAYER seeking to %lld us (%.2f secs)", mSeekTimeUs,
794 mSeekTimeUs / 1E6);
795
796 options.setSeekTo(
797 mSeekTimeUs, MediaSource::ReadOptions::SEEK_CLOSEST);
798 }
799 for (;;) {
800 status_t err = mVideoSource->read(&mVideoBuffer, &options);
801 options.clearSeekTo();
802
803 if (err != OK) {
804 CHECK_EQ(mVideoBuffer, NULL);
805
806 if (err == INFO_FORMAT_CHANGED) {
807 LOGV("LV PLAYER VideoSource signalled format change");
808 notifyVideoSize_l();
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -0800809 sp<MetaData> meta = mVideoSource->getFormat();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800810
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -0800811 CHECK(meta->findInt32(kKeyWidth, &mReportedWidth));
812 CHECK(meta->findInt32(kKeyHeight, &mReportedHeight));
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800813 if (mVideoRenderer != NULL) {
814 mVideoRendererIsPreview = false;
Santosh Madhavabfece172011-02-03 16:59:47 -0800815 err = initRenderer_l();
Santosh Madhava4ca3e5d2011-02-11 20:28:45 -0800816 if (err != OK) {
817 postStreamDoneEvent_l(err);
818 }
Santosh Madhavabfece172011-02-03 16:59:47 -0800819
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800820 }
821 continue;
822 }
823 // So video playback is complete, but we may still have
Santosh Madhava342f9322011-01-27 16:27:12 -0800824 // a seek request pending that needs to be applied to the audio track
825 if (mSeeking) {
826 LOGV("video stream ended while seeking!");
827 }
828 finishSeekIfNecessary(-1);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800829 LOGV("PreviewPlayer: onVideoEvent EOS reached.");
830 mFlags |= VIDEO_AT_EOS;
Dheeraj Sharma4f4efef2011-02-10 16:55:37 -0800831 mOverlayUpdateEventPosted = false;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800832 postStreamDoneEvent_l(err);
833 return;
834 }
835
836 if (mVideoBuffer->range_length() == 0) {
837 // Some decoders, notably the PV AVC software decoder
838 // return spurious empty buffers that we just want to ignore.
839
840 mVideoBuffer->release();
841 mVideoBuffer = NULL;
842 continue;
843 }
844
845 int64_t videoTimeUs;
846 CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &videoTimeUs));
847
848 if((videoTimeUs/1000) < mPlayBeginTimeMsec) {
849 // Frames are before begin cut time
850 // Donot render
851 mVideoBuffer->release();
852 mVideoBuffer = NULL;
853 continue;
854 }
855
856 break;
857 }
858 }
859
860 mNumberDecVideoFrames++;
861
862 int64_t timeUs;
863 CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &timeUs));
864
865 {
866 Mutex::Autolock autoLock(mMiscStateLock);
867 mVideoTimeUs = timeUs;
868 }
869
870 mDecodedVideoTs = timeUs;
871
872 if(!mStartNextPlayer) {
873 int64_t playbackTimeRemaining = (mPlayEndTimeMsec*1000) - timeUs;
874 if(playbackTimeRemaining <= 1500000) {
875 //When less than 1.5 sec of playback left
876 // send notification to start next player
877
878 mStartNextPlayer = true;
879 notifyListener_l(0xAAAAAAAA);
880 }
881 }
882
883 bool wasSeeking = mSeeking;
884 finishSeekIfNecessary(timeUs);
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800885 if (mAudioPlayer != NULL && !(mFlags & (AUDIO_RUNNING))) {
886 status_t err = startAudioPlayer_l();
887 if (err != OK) {
888 LOGE("Starting the audio player failed w/ err %d", err);
889 return;
890 }
891 }
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800892
893 TimeSource *ts = (mFlags & AUDIO_AT_EOS) ? &mSystemTimeSource : mTimeSource;
894
895 if(ts == NULL) {
896 mVideoBuffer->release();
897 mVideoBuffer = NULL;
898 return;
899 }
900
901 if(!mIsVideoSourceJpg) {
902 if (mFlags & FIRST_FRAME) {
903 mFlags &= ~FIRST_FRAME;
904
905 mTimeSourceDeltaUs = ts->getRealTimeUs() - timeUs;
906 }
907
908 int64_t realTimeUs, mediaTimeUs;
909 if (!(mFlags & AUDIO_AT_EOS) && mAudioPlayer != NULL
910 && mAudioPlayer->getMediaTimeMapping(&realTimeUs, &mediaTimeUs)) {
911 mTimeSourceDeltaUs = realTimeUs - mediaTimeUs;
912 }
913
914 int64_t nowUs = ts->getRealTimeUs() - mTimeSourceDeltaUs;
915
916 int64_t latenessUs = nowUs - timeUs;
917
918 if (wasSeeking) {
Santosh Madhava342f9322011-01-27 16:27:12 -0800919 // Let's display the first frame after seeking right away.
920 latenessUs = 0;
921 }
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800922 LOGV("Audio time stamp = %lld and video time stamp = %lld",
923 ts->getRealTimeUs(),timeUs);
924 if (latenessUs > 40000) {
925 // We're more than 40ms late.
926
927 LOGV("LV PLAYER we're late by %lld us (%.2f secs)",
928 latenessUs, latenessUs / 1E6);
929
930 mVideoBuffer->release();
931 mVideoBuffer = NULL;
Dharmaray Kundargi4f155f02011-02-01 19:16:43 -0800932 postVideoEvent_l(0);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800933 return;
934 }
935
Dharmaray Kundargi4f155f02011-02-01 19:16:43 -0800936 if (latenessUs < -25000) {
937 // We're more than 25ms early.
938 LOGV("We're more than 25ms early, lateness %lld", latenessUs);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800939
Dharmaray Kundargi4f155f02011-02-01 19:16:43 -0800940 postVideoEvent_l(25000);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800941 return;
942 }
943 }
944
945 if (mVideoRendererIsPreview || mVideoRenderer == NULL) {
946 mVideoRendererIsPreview = false;
947
Santosh Madhavabfece172011-02-03 16:59:47 -0800948 status_t err = initRenderer_l();
Santosh Madhava4ca3e5d2011-02-11 20:28:45 -0800949 if (err != OK) {
950 postStreamDoneEvent_l(err);
951 }
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800952 }
953
954 // If timestamp exceeds endCutTime of clip, donot render
955 if((timeUs/1000) > mPlayEndTimeMsec) {
956 if (mLastVideoBuffer) {
957 mLastVideoBuffer->release();
958 mLastVideoBuffer = NULL;
959 }
960 mLastVideoBuffer = mVideoBuffer;
961 mVideoBuffer = NULL;
962 mFlags |= VIDEO_AT_EOS;
963 mFlags |= AUDIO_AT_EOS;
Santosh Madhavabfece172011-02-03 16:59:47 -0800964 LOGV("PreviewPlayer: onVideoEvent timeUs > mPlayEndTime; send EOS..");
Dheeraj Sharma4f4efef2011-02-10 16:55:37 -0800965 mOverlayUpdateEventPosted = false;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800966 postStreamDoneEvent_l(ERROR_END_OF_STREAM);
967 return;
968 }
969
970 // Post processing to apply video effects
971 for(i=0;i<mNumberEffects;i++) {
972 // First check if effect starttime matches the clip being previewed
973 if((mEffectsSettings[i].uiStartTime < (mDecVideoTsStoryBoard/1000)) ||
974 (mEffectsSettings[i].uiStartTime >=
975 ((mDecVideoTsStoryBoard/1000) + mPlayEndTimeMsec - mPlayBeginTimeMsec)))
976 {
977 // This effect doesn't belong to this clip, check next one
978 continue;
979 }
980 // Check if effect applies to this particular frame timestamp
981 if((mEffectsSettings[i].uiStartTime <=
982 (((timeUs+mDecVideoTsStoryBoard)/1000)-mPlayBeginTimeMsec)) &&
983 ((mEffectsSettings[i].uiStartTime+mEffectsSettings[i].uiDuration) >=
984 (((timeUs+mDecVideoTsStoryBoard)/1000)-mPlayBeginTimeMsec))
985 && (mEffectsSettings[i].uiDuration != 0)) {
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800986 setVideoPostProcessingNode(
987 mEffectsSettings[i].VideoEffectType, TRUE);
988 }
989 else {
990 setVideoPostProcessingNode(
991 mEffectsSettings[i].VideoEffectType, FALSE);
992 }
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800993 }
994
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800995 //Provide the overlay Update indication when there is an overlay effect
Dharmaray Kundargid01ef562011-01-26 21:11:00 -0800996 if (mCurrentVideoEffect & VIDEO_EFFECT_FRAMING) {
997 mCurrentVideoEffect &= ~VIDEO_EFFECT_FRAMING; //never apply framing here.
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800998 if (!mOverlayUpdateEventPosted) {
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800999 // Find the effect in effectSettings array
1000 int index;
1001 for (index = 0; index < mNumberEffects; index++) {
1002 M4OSA_UInt32 timeMs = mDecodedVideoTs/1000;
1003 M4OSA_UInt32 timeOffset = mDecVideoTsStoryBoard/1000;
1004 if(mEffectsSettings[index].VideoEffectType ==
1005 M4xVSS_kVideoEffectType_Framing) {
Dharmaray Kundargi254c8df2011-01-28 19:28:31 -08001006 if (((mEffectsSettings[index].uiStartTime + 1) <=
1007 timeMs + timeOffset - mPlayBeginTimeMsec) &&
Dharmaray Kundargie6c07502011-01-21 16:58:31 -08001008 ((mEffectsSettings[index].uiStartTime - 1 +
Dharmaray Kundargi254c8df2011-01-28 19:28:31 -08001009 mEffectsSettings[index].uiDuration) >=
1010 timeMs + timeOffset - mPlayBeginTimeMsec))
Dharmaray Kundargie6c07502011-01-21 16:58:31 -08001011 {
1012 break;
1013 }
1014 }
1015 }
1016 if (index < mNumberEffects) {
1017 mCurrFramingEffectIndex = index;
1018 mOverlayUpdateEventPosted = true;
1019 postOverlayUpdateEvent_l();
1020 LOGV("Framing index = %d", mCurrFramingEffectIndex);
1021 } else {
1022 LOGV("No framing effects found");
1023 }
1024 }
1025
1026 } else if (mOverlayUpdateEventPosted) {
1027 //Post the event when the overlay is no more valid
1028 LOGV("Overlay is Done");
1029 mOverlayUpdateEventPosted = false;
1030 postOverlayUpdateEvent_l();
1031 }
1032
1033
1034 if (mCurrentVideoEffect != VIDEO_EFFECT_NONE) {
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001035 err1 = doVideoPostProcessing();
1036 if(err1 != M4NO_ERROR) {
1037 LOGE("doVideoPostProcessing returned err");
1038 bAppliedVideoEffect = false;
1039 }
1040 else {
1041 bAppliedVideoEffect = true;
1042 }
1043 }
1044 else {
1045 bAppliedVideoEffect = false;
1046 if(mRenderingMode != MEDIA_RENDERING_INVALID) {
1047 // No effects to be applied, but media rendering to be done
1048 err1 = doMediaRendering();
1049 if(err1 != M4NO_ERROR) {
1050 LOGE("doMediaRendering returned err");
1051 //Use original mVideoBuffer for rendering
1052 mVideoResizedOrCropped = false;
1053 }
1054 }
1055 }
1056
1057 if (mVideoRenderer != NULL) {
1058 LOGV("mVideoRenderer CALL render()");
1059 mVideoRenderer->render();
1060 }
1061
1062 if (mLastVideoBuffer) {
1063 mLastVideoBuffer->release();
1064 mLastVideoBuffer = NULL;
1065 }
1066
1067 mLastVideoBuffer = mVideoBuffer;
1068 mVideoBuffer = NULL;
1069
1070 // Post progress callback based on callback interval set
1071 if(mNumberDecVideoFrames >= mProgressCbInterval) {
1072 postProgressCallbackEvent_l();
1073 mNumberDecVideoFrames = 0; // reset counter
1074 }
1075
1076 // if reached EndCutTime of clip, post EOS event
1077 if((timeUs/1000) >= mPlayEndTimeMsec) {
1078 LOGV("PreviewPlayer: onVideoEvent EOS.");
1079 mFlags |= VIDEO_AT_EOS;
1080 mFlags |= AUDIO_AT_EOS;
Dheeraj Sharma4f4efef2011-02-10 16:55:37 -08001081 mOverlayUpdateEventPosted = false;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001082 postStreamDoneEvent_l(ERROR_END_OF_STREAM);
1083 }
1084 else {
1085 if(!mIsVideoSourceJpg) {
Dharmaray Kundargi4f155f02011-02-01 19:16:43 -08001086 postVideoEvent_l(0);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001087 }
1088 else {
1089 postVideoEvent_l(33000);
1090 }
1091 }
1092}
1093
1094status_t PreviewPlayer::prepare() {
1095 Mutex::Autolock autoLock(mLock);
1096 return prepare_l();
1097}
1098
1099status_t PreviewPlayer::prepare_l() {
1100 if (mFlags & PREPARED) {
1101 return OK;
1102 }
1103
1104 if (mFlags & PREPARING) {
1105 return UNKNOWN_ERROR;
1106 }
1107
1108 mIsAsyncPrepare = false;
1109 status_t err = prepareAsync_l();
1110
1111 if (err != OK) {
1112 return err;
1113 }
1114
1115 while (mFlags & PREPARING) {
1116 mPreparedCondition.wait(mLock);
1117 }
1118
1119 return mPrepareResult;
1120}
1121
1122status_t PreviewPlayer::prepareAsync_l() {
1123 if (mFlags & PREPARING) {
1124 return UNKNOWN_ERROR; // async prepare already pending
1125 }
1126
1127 if (!mQueueStarted) {
1128 mQueue.start();
1129 mQueueStarted = true;
1130 }
1131
1132 mFlags |= PREPARING;
1133 mAsyncPrepareEvent = new PreviewPlayerEvent(
1134 this, &PreviewPlayer::onPrepareAsyncEvent);
1135
1136 mQueue.postEvent(mAsyncPrepareEvent);
1137
1138 return OK;
1139}
1140
1141status_t PreviewPlayer::finishSetDataSource_l() {
1142 sp<DataSource> dataSource;
1143 sp<MediaExtractor> extractor;
1144
1145 dataSource = DataSource::CreateFromURI(mUri.string(), &mUriHeaders);
1146
1147 if (dataSource == NULL) {
1148 return UNKNOWN_ERROR;
1149 }
1150
1151 //If file type is .rgb, then no need to check for Extractor
1152 int uriLen = strlen(mUri);
1153 int startOffset = uriLen - 4;
1154 if(!strncasecmp(mUri+startOffset, ".rgb", 4)) {
1155 extractor = NULL;
1156 }
1157 else {
1158 extractor = MediaExtractor::Create(dataSource,
1159 MEDIA_MIMETYPE_CONTAINER_MPEG4);
1160 }
1161
1162 if (extractor == NULL) {
1163 LOGV("PreviewPlayer::finishSetDataSource_l extractor == NULL");
1164 return setDataSource_l_jpg();
1165 }
1166
1167 return setDataSource_l(extractor);
1168}
1169
1170
1171// static
1172bool PreviewPlayer::ContinuePreparation(void *cookie) {
1173 PreviewPlayer *me = static_cast<PreviewPlayer *>(cookie);
1174
1175 return (me->mFlags & PREPARE_CANCELLED) == 0;
1176}
1177
1178void PreviewPlayer::onPrepareAsyncEvent() {
1179 Mutex::Autolock autoLock(mLock);
1180 LOGV("onPrepareAsyncEvent");
1181
1182 if (mFlags & PREPARE_CANCELLED) {
Santosh Madhavabfece172011-02-03 16:59:47 -08001183 LOGV("LV PLAYER prepare was cancelled before doing anything");
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001184 abortPrepare(UNKNOWN_ERROR);
1185 return;
1186 }
1187
1188 if (mUri.size() > 0) {
1189 status_t err = finishSetDataSource_l();
1190
1191 if (err != OK) {
1192 abortPrepare(err);
1193 return;
1194 }
1195 }
1196
1197 if (mVideoTrack != NULL && mVideoSource == NULL) {
1198 status_t err = initVideoDecoder(OMXCodec::kHardwareCodecsOnly);
1199
1200 if (err != OK) {
1201 abortPrepare(err);
1202 return;
1203 }
1204 }
1205
1206 if (mAudioTrack != NULL && mAudioSource == NULL) {
1207 status_t err = initAudioDecoder();
1208
1209 if (err != OK) {
1210 abortPrepare(err);
1211 return;
1212 }
1213 }
1214 finishAsyncPrepare_l();
1215
1216}
1217
1218void PreviewPlayer::finishAsyncPrepare_l() {
1219 if (mIsAsyncPrepare) {
1220 if (mVideoSource == NULL) {
1221 LOGV("finishAsyncPrepare_l: MEDIA_SET_VIDEO_SIZE 0 0 ");
1222 notifyListener_l(MEDIA_SET_VIDEO_SIZE, 0, 0);
1223 } else {
1224 LOGV("finishAsyncPrepare_l: MEDIA_SET_VIDEO_SIZE");
1225 notifyVideoSize_l();
1226 }
1227 LOGV("finishAsyncPrepare_l: MEDIA_PREPARED");
1228 notifyListener_l(MEDIA_PREPARED);
1229 }
1230
1231 mPrepareResult = OK;
1232 mFlags &= ~(PREPARING|PREPARE_CANCELLED);
1233 mFlags |= PREPARED;
1234 mAsyncPrepareEvent = NULL;
1235 mPreparedCondition.broadcast();
1236}
1237
1238status_t PreviewPlayer::suspend() {
1239 LOGV("suspend");
1240 Mutex::Autolock autoLock(mLock);
1241
1242 if (mSuspensionState != NULL) {
1243 if (mLastVideoBuffer == NULL) {
1244 //go into here if video is suspended again
1245 //after resuming without being played between
1246 //them
1247 SuspensionState *state = mSuspensionState;
1248 mSuspensionState = NULL;
1249 reset_l();
1250 mSuspensionState = state;
1251 return OK;
1252 }
1253
1254 delete mSuspensionState;
1255 mSuspensionState = NULL;
1256 }
1257
1258 if (mFlags & PREPARING) {
1259 mFlags |= PREPARE_CANCELLED;
1260 }
1261
1262 while (mFlags & PREPARING) {
1263 mPreparedCondition.wait(mLock);
1264 }
1265
1266 SuspensionState *state = new SuspensionState;
1267 state->mUri = mUri;
1268 state->mUriHeaders = mUriHeaders;
1269 state->mFileSource = mFileSource;
1270
1271 state->mFlags = mFlags & (PLAYING | AUTO_LOOPING | LOOPING | AT_EOS);
1272 getPosition(&state->mPositionUs);
1273
1274 if (mLastVideoBuffer) {
1275 size_t size = mLastVideoBuffer->range_length();
1276 if (size) {
1277 int32_t unreadable;
1278 if (!mLastVideoBuffer->meta_data()->findInt32(
1279 kKeyIsUnreadable, &unreadable)
1280 || unreadable == 0) {
1281 state->mLastVideoFrameSize = size;
1282 state->mLastVideoFrame = malloc(size);
1283 memcpy(state->mLastVideoFrame,
1284 (const uint8_t *)mLastVideoBuffer->data()
1285 + mLastVideoBuffer->range_offset(),
1286 size);
1287
1288 state->mVideoWidth = mVideoWidth;
1289 state->mVideoHeight = mVideoHeight;
1290
1291 sp<MetaData> meta = mVideoSource->getFormat();
1292 CHECK(meta->findInt32(kKeyColorFormat, &state->mColorFormat));
1293 CHECK(meta->findInt32(kKeyWidth, &state->mDecodedWidth));
1294 CHECK(meta->findInt32(kKeyHeight, &state->mDecodedHeight));
1295 } else {
1296 LOGV("Unable to save last video frame, we have no access to "
1297 "the decoded video data.");
1298 }
1299 }
1300 }
1301
1302 reset_l();
1303
1304 mSuspensionState = state;
1305
1306 return OK;
1307}
1308
1309status_t PreviewPlayer::resume() {
1310 LOGV("resume");
1311 Mutex::Autolock autoLock(mLock);
1312
1313 if (mSuspensionState == NULL) {
1314 return INVALID_OPERATION;
1315 }
1316
1317 SuspensionState *state = mSuspensionState;
1318 mSuspensionState = NULL;
1319
1320 status_t err;
1321 if (state->mFileSource != NULL) {
1322 err = AwesomePlayer::setDataSource_l(state->mFileSource);
1323
1324 if (err == OK) {
1325 mFileSource = state->mFileSource;
1326 }
1327 } else {
1328 err = AwesomePlayer::setDataSource_l(state->mUri, &state->mUriHeaders);
1329 }
1330
1331 if (err != OK) {
1332 delete state;
1333 state = NULL;
1334
1335 return err;
1336 }
1337
1338 seekTo_l(state->mPositionUs);
1339
1340 mFlags = state->mFlags & (AUTO_LOOPING | LOOPING | AT_EOS);
1341
1342 if (state->mLastVideoFrame && (mSurface != NULL || mISurface != NULL)) {
1343 mVideoRenderer =
Santosh Madhavabfece172011-02-03 16:59:47 -08001344 PreviewLocalRenderer::initPreviewLocalRenderer(
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001345 true, // previewOnly
1346 (OMX_COLOR_FORMATTYPE)state->mColorFormat,
1347 mSurface,
1348 state->mVideoWidth,
1349 state->mVideoHeight,
1350 state->mDecodedWidth,
1351 state->mDecodedHeight);
1352
1353 mVideoRendererIsPreview = true;
1354
1355 ((PreviewLocalRenderer *)mVideoRenderer.get())->render(
1356 state->mLastVideoFrame, state->mLastVideoFrameSize);
1357 }
1358
1359 if (state->mFlags & PLAYING) {
1360 play_l();
1361 }
1362
1363 mSuspensionState = state;
1364 state = NULL;
1365
1366 return OK;
1367}
1368
1369
1370status_t PreviewPlayer::loadEffectsSettings(
1371 M4VSS3GPP_EffectSettings* pEffectSettings, int nEffects) {
1372 M4OSA_UInt32 i = 0, rgbSize = 0;
1373 M4VIFI_UInt8 *tmp = M4OSA_NULL;
1374
1375 mNumberEffects = nEffects;
1376 mEffectsSettings = pEffectSettings;
1377 return OK;
1378}
1379
1380status_t PreviewPlayer::loadAudioMixSettings(
1381 M4xVSS_AudioMixingSettings* pAudioMixSettings) {
1382
1383 LOGV("PreviewPlayer: loadAudioMixSettings: ");
1384 mPreviewPlayerAudioMixSettings = pAudioMixSettings;
1385 return OK;
1386}
1387
1388status_t PreviewPlayer::setAudioMixPCMFileHandle(
1389 M4OSA_Context pAudioMixPCMFileHandle) {
1390
1391 LOGV("PreviewPlayer: setAudioMixPCMFileHandle: ");
1392 mAudioMixPCMFileHandle = pAudioMixPCMFileHandle;
1393 return OK;
1394}
1395
1396status_t PreviewPlayer::setAudioMixStoryBoardParam(
1397 M4OSA_UInt32 audioMixStoryBoardTS,
1398 M4OSA_UInt32 currentMediaBeginCutTime,
1399 M4OSA_UInt32 primaryTrackVolValue ) {
1400
1401 mAudioMixStoryBoardTS = audioMixStoryBoardTS;
1402 mCurrentMediaBeginCutTime = currentMediaBeginCutTime;
1403 mCurrentMediaVolumeValue = primaryTrackVolValue;
1404 return OK;
1405}
1406
1407status_t PreviewPlayer::setPlaybackBeginTime(uint32_t msec) {
1408
1409 mPlayBeginTimeMsec = msec;
1410 return OK;
1411}
1412
1413status_t PreviewPlayer::setPlaybackEndTime(uint32_t msec) {
1414
1415 mPlayEndTimeMsec = msec;
1416 return OK;
1417}
1418
1419status_t PreviewPlayer::setStoryboardStartTime(uint32_t msec) {
1420
1421 mStoryboardStartTimeMsec = msec;
1422 mDecVideoTsStoryBoard = mStoryboardStartTimeMsec*1000;
1423 return OK;
1424}
1425
1426status_t PreviewPlayer::setProgressCallbackInterval(uint32_t cbInterval) {
1427
1428 mProgressCbInterval = cbInterval;
1429 return OK;
1430}
1431
1432
1433status_t PreviewPlayer::setMediaRenderingMode(
1434 M4xVSS_MediaRendering mode,
1435 M4VIDEOEDITING_VideoFrameSize outputVideoSize) {
1436
1437 mRenderingMode = mode;
1438
1439 /* reset boolean for each clip*/
1440 mVideoResizedOrCropped = false;
1441
1442 switch(outputVideoSize) {
1443 case M4VIDEOEDITING_kSQCIF:
1444 mOutputVideoWidth = 128;
1445 mOutputVideoHeight = 96;
1446 break;
1447
1448 case M4VIDEOEDITING_kQQVGA:
1449 mOutputVideoWidth = 160;
1450 mOutputVideoHeight = 120;
1451 break;
1452
1453 case M4VIDEOEDITING_kQCIF:
1454 mOutputVideoWidth = 176;
1455 mOutputVideoHeight = 144;
1456 break;
1457
1458 case M4VIDEOEDITING_kQVGA:
1459 mOutputVideoWidth = 320;
1460 mOutputVideoHeight = 240;
1461 break;
1462
1463 case M4VIDEOEDITING_kCIF:
1464 mOutputVideoWidth = 352;
1465 mOutputVideoHeight = 288;
1466 break;
1467
1468 case M4VIDEOEDITING_kVGA:
1469 mOutputVideoWidth = 640;
1470 mOutputVideoHeight = 480;
1471 break;
1472
1473 case M4VIDEOEDITING_kWVGA:
1474 mOutputVideoWidth = 800;
1475 mOutputVideoHeight = 480;
1476 break;
1477
1478 case M4VIDEOEDITING_kNTSC:
1479 mOutputVideoWidth = 720;
1480 mOutputVideoHeight = 480;
1481 break;
1482
1483 case M4VIDEOEDITING_k640_360:
1484 mOutputVideoWidth = 640;
1485 mOutputVideoHeight = 360;
1486 break;
1487
1488 case M4VIDEOEDITING_k854_480:
1489 mOutputVideoWidth = 854;
1490 mOutputVideoHeight = 480;
1491 break;
1492
1493 case M4VIDEOEDITING_kHD1280:
1494 mOutputVideoWidth = 1280;
1495 mOutputVideoHeight = 720;
1496 break;
1497
1498 case M4VIDEOEDITING_kHD1080:
1499 mOutputVideoWidth = 1080;
1500 mOutputVideoHeight = 720;
1501 break;
1502
1503 case M4VIDEOEDITING_kHD960:
1504 mOutputVideoWidth = 960;
1505 mOutputVideoHeight = 720;
1506 break;
1507
1508 default:
1509 LOGE("unsupported output video size set");
1510 return BAD_VALUE;
1511 }
1512
1513 return OK;
1514}
1515
1516M4OSA_ERR PreviewPlayer::doMediaRendering() {
1517 M4OSA_ERR err = M4NO_ERROR;
1518 M4VIFI_ImagePlane planeIn[3], planeOut[3];
1519 M4VIFI_UInt8 *inBuffer = M4OSA_NULL, *finalOutputBuffer = M4OSA_NULL;
1520 M4VIFI_UInt8 *tempOutputBuffer= M4OSA_NULL;
1521 size_t videoBufferSize = 0;
1522 M4OSA_UInt32 frameSize = 0, i=0, index =0, nFrameCount =0, bufferOffset =0;
1523 int32_t colorFormat = 0;
1524
1525 if(!mIsVideoSourceJpg) {
1526 sp<MetaData> meta = mVideoSource->getFormat();
1527 CHECK(meta->findInt32(kKeyColorFormat, &colorFormat));
1528 }
1529 else {
1530 colorFormat = OMX_COLOR_FormatYUV420Planar;
1531 }
1532
1533 videoBufferSize = mVideoBuffer->size();
1534 frameSize = (mVideoWidth*mVideoHeight*3) >> 1;
1535
1536 uint8_t* outBuffer;
1537 size_t outBufferStride = 0;
1538
1539 mVideoRenderer->getBuffer(&outBuffer, &outBufferStride);
1540
1541 bufferOffset = index*frameSize;
1542 inBuffer = (M4OSA_UInt8 *)mVideoBuffer->data()+
1543 mVideoBuffer->range_offset()+bufferOffset;
1544
1545
1546 /* In plane*/
1547 prepareYUV420ImagePlane(planeIn, mVideoWidth,
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08001548 mVideoHeight, (M4VIFI_UInt8 *)inBuffer, mReportedWidth, mReportedHeight);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001549
1550 // Set the output YUV420 plane to be compatible with YV12 format
1551 // W & H even
1552 // YVU instead of YUV
1553 // align buffers on 32 bits
1554
1555 //In YV12 format, sizes must be even
1556 M4OSA_UInt32 yv12PlaneWidth = ((mOutputVideoWidth +1)>>1)<<1;
1557 M4OSA_UInt32 yv12PlaneHeight = ((mOutputVideoHeight+1)>>1)<<1;
1558
1559 prepareYV12ImagePlane(planeOut, yv12PlaneWidth, yv12PlaneHeight,
1560 (M4OSA_UInt32)outBufferStride, (M4VIFI_UInt8 *)outBuffer);
1561
1562
1563 err = applyRenderingMode(planeIn, planeOut, mRenderingMode);
1564
1565 if(err != M4NO_ERROR)
1566 {
1567 LOGE("doMediaRendering: applyRenderingMode returned err=0x%x", err);
1568 return err;
1569 }
1570 mVideoResizedOrCropped = true;
1571
1572 return err;
1573}
1574
1575status_t PreviewPlayer::resetJniCallbackTimeStamp() {
1576
1577 mDecVideoTsStoryBoard = mStoryboardStartTimeMsec*1000;
1578 return OK;
1579}
1580
1581void PreviewPlayer::postProgressCallbackEvent_l() {
1582 if (mProgressCbEventPending) {
1583 return;
1584 }
1585 mProgressCbEventPending = true;
1586
1587 mQueue.postEvent(mProgressCbEvent);
1588}
1589
Dharmaray Kundargie6c07502011-01-21 16:58:31 -08001590
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001591void PreviewPlayer::onProgressCbEvent() {
1592 Mutex::Autolock autoLock(mLock);
1593 if (!mProgressCbEventPending) {
1594 return;
1595 }
1596 mProgressCbEventPending = false;
1597 // If playback starts from previous I-frame,
1598 // then send frame storyboard duration
1599 if((mDecodedVideoTs/1000) < mPlayBeginTimeMsec) {
1600 notifyListener_l(MEDIA_INFO, 0, mDecVideoTsStoryBoard/1000);
1601 }
1602 else {
1603 notifyListener_l(MEDIA_INFO, 0,
1604 (((mDecodedVideoTs+mDecVideoTsStoryBoard)/1000)-mPlayBeginTimeMsec));
1605 }
1606}
1607
Dharmaray Kundargie6c07502011-01-21 16:58:31 -08001608void PreviewPlayer::postOverlayUpdateEvent_l() {
1609 if (mOverlayUpdateEventPending) {
1610 return;
1611 }
1612 mOverlayUpdateEventPending = true;
1613 mQueue.postEvent(mOverlayUpdateEvent);
1614}
1615
1616void PreviewPlayer::onUpdateOverlayEvent() {
1617 Mutex::Autolock autoLock(mLock);
1618
1619 if (!mOverlayUpdateEventPending) {
1620 return;
1621 }
1622 mOverlayUpdateEventPending = false;
1623
1624 int updateState;
1625 if (mOverlayUpdateEventPosted) {
1626 updateState = 1;
1627 } else {
1628 updateState = 0;
1629 }
1630 notifyListener_l(0xBBBBBBBB, updateState, mCurrFramingEffectIndex);
1631}
1632
1633
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001634void PreviewPlayer::setVideoPostProcessingNode(
1635 M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable) {
1636
1637 uint32_t effect = VIDEO_EFFECT_NONE;
1638
1639 //Map M4VSS3GPP_VideoEffectType to local enum
1640 switch(type) {
1641 case M4VSS3GPP_kVideoEffectType_FadeFromBlack:
1642 effect = VIDEO_EFFECT_FADEFROMBLACK;
1643 break;
1644
1645 case M4VSS3GPP_kVideoEffectType_FadeToBlack:
1646 effect = VIDEO_EFFECT_FADETOBLACK;
1647 break;
1648
1649 case M4VSS3GPP_kVideoEffectType_CurtainOpening:
1650 effect = VIDEO_EFFECT_CURTAINOPEN;
1651 break;
1652
1653 case M4VSS3GPP_kVideoEffectType_CurtainClosing:
1654 effect = VIDEO_EFFECT_CURTAINCLOSE;
1655 break;
1656
1657 case M4xVSS_kVideoEffectType_BlackAndWhite:
1658 effect = VIDEO_EFFECT_BLACKANDWHITE;
1659 break;
1660
1661 case M4xVSS_kVideoEffectType_Pink:
1662 effect = VIDEO_EFFECT_PINK;
1663 break;
1664
1665 case M4xVSS_kVideoEffectType_Green:
1666 effect = VIDEO_EFFECT_GREEN;
1667 break;
1668
1669 case M4xVSS_kVideoEffectType_Sepia:
1670 effect = VIDEO_EFFECT_SEPIA;
1671 break;
1672
1673 case M4xVSS_kVideoEffectType_Negative:
1674 effect = VIDEO_EFFECT_NEGATIVE;
1675 break;
1676
1677 case M4xVSS_kVideoEffectType_Framing:
1678 effect = VIDEO_EFFECT_FRAMING;
1679 break;
1680
1681 case M4xVSS_kVideoEffectType_Fifties:
1682 effect = VIDEO_EFFECT_FIFTIES;
1683 break;
1684
1685 case M4xVSS_kVideoEffectType_ColorRGB16:
1686 effect = VIDEO_EFFECT_COLOR_RGB16;
1687 break;
1688
1689 case M4xVSS_kVideoEffectType_Gradient:
1690 effect = VIDEO_EFFECT_GRADIENT;
1691 break;
1692
1693 default:
1694 effect = VIDEO_EFFECT_NONE;
1695 break;
1696 }
1697
1698 if(enable == M4OSA_TRUE) {
1699 //If already set, then no need to set again
1700 if(!(mCurrentVideoEffect & effect)) {
1701 mCurrentVideoEffect |= effect;
1702 if(effect == VIDEO_EFFECT_FIFTIES) {
1703 mIsFiftiesEffectStarted = true;
1704 }
1705 }
1706 }
1707 else {
1708 //Reset only if already set
1709 if(mCurrentVideoEffect & effect) {
1710 mCurrentVideoEffect &= ~effect;
1711 }
1712 }
1713}
1714
1715status_t PreviewPlayer::setImageClipProperties(uint32_t width,uint32_t height) {
1716 mVideoWidth = width;
1717 mVideoHeight = height;
1718 return OK;
1719}
1720
1721
1722M4OSA_ERR PreviewPlayer::doVideoPostProcessing() {
1723 M4OSA_ERR err = M4NO_ERROR;
1724 vePostProcessParams postProcessParams;
1725 int32_t colorFormat = 0;
1726
1727
1728 if(!mIsVideoSourceJpg) {
1729 sp<MetaData> meta = mVideoSource->getFormat();
1730 CHECK(meta->findInt32(kKeyColorFormat, &colorFormat));
1731 }
1732 else {
1733 colorFormat = OMX_COLOR_FormatYUV420Planar;
1734 }
1735
1736 if((colorFormat == OMX_COLOR_FormatYUV420SemiPlanar) ||
1737 (colorFormat == 0x7FA30C00)) {
1738 LOGE("doVideoPostProcessing: colorFormat YUV420Sp not supported");
1739 return M4ERR_UNSUPPORTED_MEDIA_TYPE;
1740 }
1741
1742 postProcessParams.vidBuffer = (M4VIFI_UInt8*)mVideoBuffer->data()
1743 + mVideoBuffer->range_offset();
1744
1745 postProcessParams.videoWidth = mVideoWidth;
1746 postProcessParams.videoHeight = mVideoHeight;
1747 postProcessParams.timeMs = mDecodedVideoTs/1000;
1748 postProcessParams.timeOffset = mDecVideoTsStoryBoard/1000;
1749 postProcessParams.effectsSettings = mEffectsSettings;
1750 postProcessParams.numberEffects = mNumberEffects;
1751 postProcessParams.outVideoWidth = mOutputVideoWidth;
1752 postProcessParams.outVideoHeight = mOutputVideoHeight;
1753 postProcessParams.currentVideoEffect = mCurrentVideoEffect;
1754 postProcessParams.renderingMode = mRenderingMode;
1755 if(mIsFiftiesEffectStarted == M4OSA_TRUE) {
1756 postProcessParams.isFiftiesEffectStarted = M4OSA_TRUE;
1757 mIsFiftiesEffectStarted = M4OSA_FALSE;
1758 }
1759 else {
1760 postProcessParams.isFiftiesEffectStarted = M4OSA_FALSE;
1761 }
1762
1763 postProcessParams.overlayFrameRGBBuffer = mFrameRGBBuffer;
1764 postProcessParams.overlayFrameYUVBuffer = mFrameYUVBuffer;
1765 mVideoRenderer->getBuffer(&(postProcessParams.pOutBuffer), &(postProcessParams.outBufferStride));
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08001766 err = applyEffectsAndRenderingMode(&postProcessParams, mReportedWidth, mReportedHeight);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001767
1768 return err;
1769}
1770
1771status_t PreviewPlayer::readFirstVideoFrame() {
1772 LOGV("PreviewPlayer::readFirstVideoFrame");
1773
1774 if (!mVideoBuffer) {
1775 MediaSource::ReadOptions options;
1776 if (mSeeking) {
1777 LOGV("LV PLAYER seeking to %lld us (%.2f secs)", mSeekTimeUs,
1778 mSeekTimeUs / 1E6);
1779
1780 options.setSeekTo(
1781 mSeekTimeUs, MediaSource::ReadOptions::SEEK_CLOSEST);
1782 }
1783 for (;;) {
1784 status_t err = mVideoSource->read(&mVideoBuffer, &options);
1785 options.clearSeekTo();
1786
1787 if (err != OK) {
1788 CHECK_EQ(mVideoBuffer, NULL);
1789
1790 if (err == INFO_FORMAT_CHANGED) {
1791 LOGV("LV PLAYER VideoSource signalled format change");
1792 notifyVideoSize_l();
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08001793 sp<MetaData> meta = mVideoSource->getFormat();
1794
1795 CHECK(meta->findInt32(kKeyWidth, &mReportedWidth));
1796 CHECK(meta->findInt32(kKeyHeight, &mReportedHeight));
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001797
1798 if (mVideoRenderer != NULL) {
1799 mVideoRendererIsPreview = false;
Santosh Madhavabfece172011-02-03 16:59:47 -08001800 err = initRenderer_l();
Santosh Madhava4ca3e5d2011-02-11 20:28:45 -08001801 if (err != OK) {
1802 postStreamDoneEvent_l(err);
1803 }
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001804 }
1805 continue;
1806 }
1807 LOGV("PreviewPlayer: onVideoEvent EOS reached.");
1808 mFlags |= VIDEO_AT_EOS;
1809 postStreamDoneEvent_l(err);
1810 return OK;
1811 }
1812
1813 if (mVideoBuffer->range_length() == 0) {
1814 // Some decoders, notably the PV AVC software decoder
1815 // return spurious empty buffers that we just want to ignore.
1816
1817 mVideoBuffer->release();
1818 mVideoBuffer = NULL;
1819 continue;
1820 }
1821
1822 int64_t videoTimeUs;
1823 CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &videoTimeUs));
1824
1825 if((videoTimeUs/1000) < mPlayBeginTimeMsec) {
1826 // buffers are before begin cut time
1827 // ignore them
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001828 mVideoBuffer->release();
1829 mVideoBuffer = NULL;
1830 continue;
1831 }
1832
1833 break;
1834 }
1835 }
1836
1837 int64_t timeUs;
1838 CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &timeUs));
1839
1840 {
1841 Mutex::Autolock autoLock(mMiscStateLock);
1842 mVideoTimeUs = timeUs;
1843 }
1844
1845 mDecodedVideoTs = timeUs;
1846
1847 return OK;
1848
1849}
1850
1851} // namespace android