Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1 | /* |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 2 | * Copyright (C) 2011 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 | |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 17 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 18 | #define LOG_NDEBUG 1 |
| 19 | #define LOG_TAG "PreviewPlayer" |
| 20 | #include <utils/Log.h> |
| 21 | |
| 22 | #include <dlfcn.h> |
| 23 | |
| 24 | #include "include/ARTSPController.h" |
| 25 | #include "PreviewPlayer.h" |
| 26 | #include "DummyAudioSource.h" |
| 27 | #include "DummyVideoSource.h" |
| 28 | #include "VideoEditorSRC.h" |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 29 | #include "include/NuCachedSource2.h" |
| 30 | #include "include/ThrottledSource.h" |
| 31 | |
| 32 | |
| 33 | #include "PreviewRenderer.h" |
| 34 | |
| 35 | #include <binder/IPCThreadState.h> |
| 36 | #include <media/stagefright/DataSource.h> |
| 37 | #include <media/stagefright/FileSource.h> |
| 38 | #include <media/stagefright/MediaBuffer.h> |
| 39 | #include <media/stagefright/MediaDefs.h> |
| 40 | #include <media/stagefright/MediaExtractor.h> |
| 41 | #include <media/stagefright/MediaDebug.h> |
| 42 | #include <media/stagefright/MediaSource.h> |
| 43 | #include <media/stagefright/MetaData.h> |
| 44 | #include <media/stagefright/OMXCodec.h> |
| 45 | |
| 46 | #include <surfaceflinger/Surface.h> |
| 47 | #include <media/stagefright/foundation/ALooper.h> |
| 48 | |
| 49 | namespace android { |
| 50 | |
| 51 | |
| 52 | struct PreviewPlayerEvent : public TimedEventQueue::Event { |
| 53 | PreviewPlayerEvent( |
| 54 | PreviewPlayer *player, |
| 55 | void (PreviewPlayer::*method)()) |
| 56 | : mPlayer(player), |
| 57 | mMethod(method) { |
| 58 | } |
| 59 | |
| 60 | protected: |
| 61 | virtual ~PreviewPlayerEvent() {} |
| 62 | |
| 63 | virtual void fire(TimedEventQueue *queue, int64_t /* now_us */) { |
| 64 | (mPlayer->*mMethod)(); |
| 65 | } |
| 66 | |
| 67 | private: |
| 68 | PreviewPlayer *mPlayer; |
| 69 | void (PreviewPlayer::*mMethod)(); |
| 70 | |
| 71 | PreviewPlayerEvent(const PreviewPlayerEvent &); |
| 72 | PreviewPlayerEvent &operator=(const PreviewPlayerEvent &); |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | struct PreviewLocalRenderer : public PreviewPlayerRenderer { |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 77 | |
| 78 | static PreviewLocalRenderer* initPreviewLocalRenderer ( |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 79 | bool previewOnly, |
| 80 | OMX_COLOR_FORMATTYPE colorFormat, |
| 81 | const sp<Surface> &surface, |
| 82 | size_t displayWidth, size_t displayHeight, |
| 83 | size_t decodedWidth, size_t decodedHeight, |
| 84 | int32_t rotationDegrees = 0) |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 85 | { |
| 86 | PreviewLocalRenderer* mLocalRenderer = new |
| 87 | PreviewLocalRenderer( |
| 88 | previewOnly, |
| 89 | colorFormat, |
| 90 | surface, |
| 91 | displayWidth, displayHeight, |
| 92 | decodedWidth, decodedHeight, |
| 93 | rotationDegrees); |
| 94 | |
| 95 | if ( mLocalRenderer->init(previewOnly, |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 96 | colorFormat, surface, |
| 97 | displayWidth, displayHeight, |
| 98 | decodedWidth, decodedHeight, |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 99 | rotationDegrees) != OK ) |
| 100 | { |
| 101 | delete mLocalRenderer; |
| 102 | return NULL; |
| 103 | } |
| 104 | return mLocalRenderer; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | virtual void render(MediaBuffer *buffer) { |
| 108 | render((const uint8_t *)buffer->data() + buffer->range_offset(), |
| 109 | buffer->range_length()); |
| 110 | } |
| 111 | |
| 112 | void render(const void *data, size_t size) { |
| 113 | mTarget->render(data, size, NULL); |
| 114 | } |
| 115 | void render() { |
| 116 | mTarget->renderYV12(); |
| 117 | } |
| 118 | void getBuffer(uint8_t **data, size_t *stride) { |
| 119 | mTarget->getBufferYV12(data, stride); |
| 120 | } |
| 121 | |
| 122 | protected: |
| 123 | virtual ~PreviewLocalRenderer() { |
| 124 | delete mTarget; |
| 125 | mTarget = NULL; |
| 126 | } |
| 127 | |
| 128 | private: |
| 129 | PreviewRenderer *mTarget; |
| 130 | |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 131 | PreviewLocalRenderer( |
| 132 | bool previewOnly, |
| 133 | OMX_COLOR_FORMATTYPE colorFormat, |
| 134 | const sp<Surface> &surface, |
| 135 | size_t displayWidth, size_t displayHeight, |
| 136 | size_t decodedWidth, size_t decodedHeight, |
| 137 | int32_t rotationDegrees = 0) |
| 138 | : mTarget(NULL) { |
| 139 | } |
| 140 | |
| 141 | |
| 142 | int init( |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 143 | bool previewOnly, |
| 144 | OMX_COLOR_FORMATTYPE colorFormat, |
| 145 | const sp<Surface> &surface, |
| 146 | size_t displayWidth, size_t displayHeight, |
| 147 | size_t decodedWidth, size_t decodedHeight, |
| 148 | int32_t rotationDegrees = 0); |
| 149 | |
| 150 | PreviewLocalRenderer(const PreviewLocalRenderer &); |
| 151 | PreviewLocalRenderer &operator=(const PreviewLocalRenderer &);; |
| 152 | }; |
| 153 | |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 154 | int PreviewLocalRenderer::init( |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 155 | bool previewOnly, |
| 156 | OMX_COLOR_FORMATTYPE colorFormat, |
| 157 | const sp<Surface> &surface, |
| 158 | size_t displayWidth, size_t displayHeight, |
| 159 | size_t decodedWidth, size_t decodedHeight, |
| 160 | int32_t rotationDegrees) { |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 161 | |
| 162 | mTarget = PreviewRenderer::CreatePreviewRenderer ( |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 163 | colorFormat, surface, displayWidth, displayHeight, |
| 164 | decodedWidth, decodedHeight, rotationDegrees); |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 165 | if (mTarget == M4OSA_NULL) { |
| 166 | return UNKNOWN_ERROR; |
| 167 | } |
| 168 | return OK; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | PreviewPlayer::PreviewPlayer() |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame] | 172 | : PreviewPlayerBase(), |
Basavapatna Dattaguru | 408e25b | 2011-02-27 21:04:57 -0800 | [diff] [blame] | 173 | mCurrFramingEffectIndex(0) , |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 174 | mReportedWidth(0), |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 175 | mReportedHeight(0), |
Basavapatna Dattaguru | 408e25b | 2011-02-27 21:04:57 -0800 | [diff] [blame] | 176 | mFrameRGBBuffer(NULL), |
| 177 | mFrameYUVBuffer(NULL){ |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 178 | |
| 179 | mVideoRenderer = NULL; |
| 180 | mLastVideoBuffer = NULL; |
| 181 | mSuspensionState = NULL; |
| 182 | mEffectsSettings = NULL; |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 183 | mVeAudioPlayer = NULL; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 184 | mAudioMixStoryBoardTS = 0; |
| 185 | mCurrentMediaBeginCutTime = 0; |
| 186 | mCurrentMediaVolumeValue = 0; |
| 187 | mNumberEffects = 0; |
| 188 | mDecodedVideoTs = 0; |
| 189 | mDecVideoTsStoryBoard = 0; |
| 190 | mCurrentVideoEffect = VIDEO_EFFECT_NONE; |
| 191 | mProgressCbInterval = 0; |
| 192 | mNumberDecVideoFrames = 0; |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 193 | mOverlayUpdateEventPosted = false; |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 194 | mIsChangeSourceRequired = true; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 195 | |
| 196 | mVideoEvent = new PreviewPlayerEvent(this, &PreviewPlayer::onVideoEvent); |
| 197 | mVideoEventPending = false; |
| 198 | mStreamDoneEvent = new PreviewPlayerEvent(this, |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 199 | &PreviewPlayer::onStreamDone); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 200 | |
| 201 | mStreamDoneEventPending = false; |
| 202 | |
| 203 | mCheckAudioStatusEvent = new PreviewPlayerEvent( |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame] | 204 | this, &PreviewPlayerBase::onCheckAudioStatus); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 205 | |
| 206 | mAudioStatusEventPending = false; |
| 207 | |
| 208 | mProgressCbEvent = new PreviewPlayerEvent(this, |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 209 | &PreviewPlayer::onProgressCbEvent); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 210 | |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 211 | mOverlayUpdateEvent = new PreviewPlayerEvent(this, |
| 212 | &PreviewPlayer::onUpdateOverlayEvent); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 213 | mProgressCbEventPending = false; |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 214 | |
| 215 | mOverlayUpdateEventPending = false; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 216 | mResizedVideoBuffer = NULL; |
| 217 | mVideoResizedOrCropped = false; |
| 218 | mRenderingMode = (M4xVSS_MediaRendering)MEDIA_RENDERING_INVALID; |
| 219 | mIsFiftiesEffectStarted = false; |
| 220 | reset(); |
| 221 | } |
| 222 | |
| 223 | PreviewPlayer::~PreviewPlayer() { |
| 224 | |
| 225 | if (mQueueStarted) { |
| 226 | mQueue.stop(); |
| 227 | } |
| 228 | |
| 229 | reset(); |
| 230 | |
| 231 | if(mResizedVideoBuffer != NULL) { |
Shyam Pallapothu | 694816d | 2011-04-21 09:48:41 -0700 | [diff] [blame] | 232 | free((mResizedVideoBuffer->data())); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 233 | mResizedVideoBuffer = NULL; |
| 234 | } |
| 235 | |
| 236 | mVideoRenderer.clear(); |
| 237 | mVideoRenderer = NULL; |
| 238 | } |
| 239 | |
| 240 | void 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 | |
| 252 | status_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 | |
| 258 | status_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 | |
| 274 | status_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, |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 315 | ((mPlayEndTimeMsec)*1000LL)); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 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 | |
| 330 | status_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, |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 335 | ((mPlayEndTimeMsec)*1000LL)); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 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 | |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 347 | mDurationUs = (mPlayEndTimeMsec - mPlayBeginTimeMsec)*1000LL; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 348 | |
| 349 | mVideoSource = DummyVideoSource::Create(mVideoWidth, mVideoHeight, |
| 350 | mDurationUs, mUri); |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 351 | mReportedWidth = mVideoWidth; |
| 352 | mReportedHeight = mVideoHeight; |
| 353 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 354 | 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 | |
| 365 | void PreviewPlayer::reset() { |
| 366 | Mutex::Autolock autoLock(mLock); |
| 367 | reset_l(); |
| 368 | } |
| 369 | |
| 370 | void 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 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 399 | //Single audio player instance used |
| 400 | //So donot delete it here |
| 401 | //It is deleted from PreviewController class |
| 402 | //delete mAudioPlayer; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 403 | mAudioPlayer = NULL; |
| 404 | |
| 405 | if (mLastVideoBuffer) { |
| 406 | mLastVideoBuffer->release(); |
| 407 | mLastVideoBuffer = NULL; |
| 408 | } |
| 409 | |
| 410 | if (mVideoBuffer) { |
| 411 | mVideoBuffer->release(); |
| 412 | mVideoBuffer = NULL; |
| 413 | } |
| 414 | |
| 415 | if (mVideoSource != NULL) { |
| 416 | mVideoSource->stop(); |
| 417 | |
| 418 | // The following hack is necessary to ensure that the OMX |
| 419 | // component is completely released by the time we may try |
| 420 | // to instantiate it again. |
| 421 | wp<MediaSource> tmp = mVideoSource; |
| 422 | mVideoSource.clear(); |
| 423 | while (tmp.promote() != NULL) { |
| 424 | usleep(1000); |
| 425 | } |
| 426 | IPCThreadState::self()->flushCommands(); |
| 427 | } |
| 428 | |
| 429 | mDurationUs = -1; |
| 430 | mFlags = 0; |
| 431 | mExtractorFlags = 0; |
| 432 | mVideoWidth = mVideoHeight = -1; |
| 433 | mTimeSourceDeltaUs = 0; |
| 434 | mVideoTimeUs = 0; |
| 435 | |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 436 | mSeeking = NO_SEEK; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 437 | mSeekNotificationSent = false; |
| 438 | mSeekTimeUs = 0; |
| 439 | |
| 440 | mUri.setTo(""); |
| 441 | mUriHeaders.clear(); |
| 442 | |
| 443 | mFileSource.clear(); |
| 444 | |
| 445 | delete mSuspensionState; |
| 446 | mSuspensionState = NULL; |
| 447 | |
| 448 | mCurrentVideoEffect = VIDEO_EFFECT_NONE; |
| 449 | mIsVideoSourceJpg = false; |
| 450 | mFrameRGBBuffer = NULL; |
| 451 | if(mFrameYUVBuffer != NULL) { |
Shyam Pallapothu | 694816d | 2011-04-21 09:48:41 -0700 | [diff] [blame] | 452 | free(mFrameYUVBuffer); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 453 | mFrameYUVBuffer = NULL; |
| 454 | } |
| 455 | } |
| 456 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 457 | status_t PreviewPlayer::play() { |
| 458 | Mutex::Autolock autoLock(mLock); |
| 459 | |
| 460 | mFlags &= ~CACHE_UNDERRUN; |
| 461 | |
| 462 | return play_l(); |
| 463 | } |
| 464 | |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 465 | status_t PreviewPlayer::startAudioPlayer_l() { |
| 466 | CHECK(!(mFlags & AUDIO_RUNNING)); |
| 467 | |
| 468 | if (mAudioSource == NULL || mAudioPlayer == NULL) { |
| 469 | return OK; |
| 470 | } |
| 471 | |
| 472 | if (!(mFlags & AUDIOPLAYER_STARTED)) { |
| 473 | mFlags |= AUDIOPLAYER_STARTED; |
| 474 | |
| 475 | // We've already started the MediaSource in order to enable |
| 476 | // the prefetcher to read its data. |
| 477 | status_t err = mVeAudioPlayer->start( |
| 478 | true /* sourceAlreadyStarted */); |
| 479 | |
| 480 | if (err != OK) { |
| 481 | notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err); |
| 482 | return err; |
| 483 | } |
| 484 | } else { |
| 485 | mVeAudioPlayer->resume(); |
| 486 | } |
| 487 | |
| 488 | mFlags |= AUDIO_RUNNING; |
| 489 | |
| 490 | mWatchForAudioEOS = true; |
| 491 | |
| 492 | return OK; |
| 493 | } |
| 494 | |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame] | 495 | status_t PreviewPlayer::setAudioPlayer(AudioPlayerBase *audioPlayer) { |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 496 | Mutex::Autolock autoLock(mLock); |
| 497 | CHECK(!(mFlags & PLAYING)); |
| 498 | mAudioPlayer = audioPlayer; |
| 499 | |
| 500 | LOGV("SetAudioPlayer"); |
| 501 | mIsChangeSourceRequired = true; |
| 502 | mVeAudioPlayer = |
| 503 | (VideoEditorAudioPlayer*)mAudioPlayer; |
| 504 | |
| 505 | // check if the new and old source are dummy |
| 506 | sp<MediaSource> anAudioSource = mVeAudioPlayer->getSource(); |
| 507 | if (anAudioSource == NULL) { |
| 508 | // Audio player does not have any source set. |
| 509 | LOGV("setAudioPlayer: Audio player does not have any source set"); |
| 510 | return OK; |
| 511 | } |
| 512 | |
Rajneesh Chowdury | 9a8c9a8 | 2011-03-11 14:02:47 -0800 | [diff] [blame] | 513 | // If new video source is not dummy, then always change source |
| 514 | // Else audio player continues using old audio source and there are |
| 515 | // frame drops to maintain AV sync |
| 516 | sp<MetaData> meta; |
| 517 | if (mVideoSource != NULL) { |
| 518 | meta = mVideoSource->getFormat(); |
| 519 | const char *pVidSrcType; |
| 520 | if (meta->findCString(kKeyDecoderComponent, &pVidSrcType)) { |
| 521 | if (strcmp(pVidSrcType, "DummyVideoSource") != 0) { |
| 522 | LOGV(" Video clip with silent audio; need to change source"); |
| 523 | return OK; |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 528 | const char *pSrcType1; |
| 529 | const char *pSrcType2; |
Rajneesh Chowdury | 9a8c9a8 | 2011-03-11 14:02:47 -0800 | [diff] [blame] | 530 | meta = anAudioSource->getFormat(); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 531 | |
| 532 | if (meta->findCString(kKeyDecoderComponent, &pSrcType1)) { |
| 533 | if (strcmp(pSrcType1, "DummyAudioSource") == 0) { |
| 534 | meta = mAudioSource->getFormat(); |
| 535 | if (meta->findCString(kKeyDecoderComponent, &pSrcType2)) { |
| 536 | if (strcmp(pSrcType2, "DummyAudioSource") == 0) { |
| 537 | mIsChangeSourceRequired = false; |
| 538 | // Just set the new play duration for the existing source |
| 539 | MediaSource *pMediaSrc = anAudioSource.get(); |
| 540 | DummyAudioSource *pDummyAudioSource = (DummyAudioSource*)pMediaSrc; |
| 541 | //Increment the duration of audio source |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 542 | pDummyAudioSource->setDuration( |
| 543 | (int64_t)((mPlayEndTimeMsec)*1000LL)); |
Rajneesh Chowdury | b6e2b5c | 2011-02-25 22:59:46 -0800 | [diff] [blame] | 544 | |
| 545 | // Stop the new audio source |
| 546 | // since we continue using old source |
| 547 | LOGV("setAudioPlayer: stop new audio source"); |
| 548 | mAudioSource->stop(); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | return OK; |
| 555 | } |
| 556 | |
| 557 | void PreviewPlayer::onStreamDone() { |
| 558 | // Posted whenever any stream finishes playing. |
| 559 | |
| 560 | Mutex::Autolock autoLock(mLock); |
| 561 | if (!mStreamDoneEventPending) { |
| 562 | return; |
| 563 | } |
| 564 | mStreamDoneEventPending = false; |
| 565 | |
| 566 | if (mStreamDoneStatus != ERROR_END_OF_STREAM) { |
| 567 | LOGV("MEDIA_ERROR %d", mStreamDoneStatus); |
| 568 | |
| 569 | notifyListener_l( |
| 570 | MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, mStreamDoneStatus); |
| 571 | |
| 572 | pause_l(true /* at eos */); |
| 573 | |
| 574 | mFlags |= AT_EOS; |
| 575 | return; |
| 576 | } |
| 577 | |
| 578 | const bool allDone = |
| 579 | (mVideoSource == NULL || (mFlags & VIDEO_AT_EOS)) |
| 580 | && (mAudioSource == NULL || (mFlags & AUDIO_AT_EOS)); |
| 581 | |
| 582 | if (!allDone) { |
| 583 | return; |
| 584 | } |
| 585 | |
| 586 | if (mFlags & (LOOPING | AUTO_LOOPING)) { |
| 587 | seekTo_l(0); |
| 588 | |
| 589 | if (mVideoSource != NULL) { |
| 590 | postVideoEvent_l(); |
| 591 | } |
| 592 | } else { |
| 593 | LOGV("MEDIA_PLAYBACK_COMPLETE"); |
| 594 | //pause before sending event |
| 595 | pause_l(true /* at eos */); |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 596 | |
| 597 | //This lock is used to syncronize onStreamDone() in PreviewPlayer and |
| 598 | //stopPreview() in PreviewController |
| 599 | Mutex::Autolock autoLock(mLockControl); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 600 | notifyListener_l(MEDIA_PLAYBACK_COMPLETE); |
| 601 | |
| 602 | mFlags |= AT_EOS; |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 603 | LOGV("onStreamDone end"); |
| 604 | return; |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
| 608 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 609 | status_t PreviewPlayer::play_l() { |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 610 | |
Rajneesh Chowdury | 8b95de2 | 2011-02-16 15:32:06 -0800 | [diff] [blame] | 611 | mFlags &= ~SEEK_PREVIEW; |
| 612 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 613 | if (mFlags & PLAYING) { |
| 614 | return OK; |
| 615 | } |
| 616 | mStartNextPlayer = false; |
| 617 | |
| 618 | if (!(mFlags & PREPARED)) { |
| 619 | status_t err = prepare_l(); |
| 620 | |
| 621 | if (err != OK) { |
| 622 | return err; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | mFlags |= PLAYING; |
| 627 | mFlags |= FIRST_FRAME; |
| 628 | |
| 629 | bool deferredAudioSeek = false; |
| 630 | |
| 631 | if (mAudioSource != NULL) { |
| 632 | if (mAudioPlayer == NULL) { |
| 633 | if (mAudioSink != NULL) { |
| 634 | |
| 635 | mAudioPlayer = new VideoEditorAudioPlayer(mAudioSink, this); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 636 | mVeAudioPlayer = |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 637 | (VideoEditorAudioPlayer*)mAudioPlayer; |
| 638 | |
| 639 | mAudioPlayer->setSource(mAudioSource); |
| 640 | |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 641 | mVeAudioPlayer->setAudioMixSettings( |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 642 | mPreviewPlayerAudioMixSettings); |
| 643 | |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 644 | mVeAudioPlayer->setAudioMixPCMFileHandle( |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 645 | mAudioMixPCMFileHandle); |
| 646 | |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 647 | mVeAudioPlayer->setAudioMixStoryBoardSkimTimeStamp( |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 648 | mAudioMixStoryBoardTS, mCurrentMediaBeginCutTime, |
| 649 | mCurrentMediaVolumeValue); |
| 650 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 651 | mFlags |= AUDIOPLAYER_STARTED; |
| 652 | // We've already started the MediaSource in order to enable |
| 653 | // the prefetcher to read its data. |
| 654 | status_t err = mVeAudioPlayer->start( |
| 655 | true /* sourceAlreadyStarted */); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 656 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 657 | if (err != OK) { |
| 658 | //delete mAudioPlayer; |
| 659 | mAudioPlayer = NULL; |
| 660 | |
| 661 | mFlags &= ~(PLAYING | FIRST_FRAME); |
| 662 | return err; |
| 663 | } |
| 664 | |
| 665 | mTimeSource = mVeAudioPlayer; |
| 666 | mFlags |= AUDIO_RUNNING; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 667 | deferredAudioSeek = true; |
| 668 | mWatchForAudioSeekComplete = false; |
| 669 | mWatchForAudioEOS = true; |
| 670 | } |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 671 | } else { |
| 672 | mVeAudioPlayer = (VideoEditorAudioPlayer*)mAudioPlayer; |
| 673 | bool isAudioPlayerStarted = mVeAudioPlayer->isStarted(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 674 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 675 | if (mIsChangeSourceRequired == true) { |
| 676 | LOGV("play_l: Change audio source required"); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 677 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 678 | if (isAudioPlayerStarted == true) { |
| 679 | mVeAudioPlayer->pause(); |
| 680 | } |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 681 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 682 | mVeAudioPlayer->setSource(mAudioSource); |
| 683 | mVeAudioPlayer->setObserver(this); |
| 684 | |
| 685 | mVeAudioPlayer->setAudioMixSettings( |
| 686 | mPreviewPlayerAudioMixSettings); |
| 687 | |
| 688 | mVeAudioPlayer->setAudioMixStoryBoardSkimTimeStamp( |
| 689 | mAudioMixStoryBoardTS, mCurrentMediaBeginCutTime, |
| 690 | mCurrentMediaVolumeValue); |
| 691 | |
| 692 | if (isAudioPlayerStarted == true) { |
| 693 | mVeAudioPlayer->resume(); |
| 694 | } else { |
| 695 | status_t err = OK; |
| 696 | err = mVeAudioPlayer->start(true); |
| 697 | if (err != OK) { |
| 698 | mAudioPlayer = NULL; |
| 699 | mVeAudioPlayer = NULL; |
| 700 | |
| 701 | mFlags &= ~(PLAYING | FIRST_FRAME); |
| 702 | return err; |
| 703 | } |
| 704 | } |
| 705 | } else { |
| 706 | LOGV("play_l: No Source change required"); |
| 707 | mVeAudioPlayer->setAudioMixStoryBoardSkimTimeStamp( |
| 708 | mAudioMixStoryBoardTS, mCurrentMediaBeginCutTime, |
| 709 | mCurrentMediaVolumeValue); |
| 710 | |
| 711 | mVeAudioPlayer->resume(); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 712 | } |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 713 | |
| 714 | mFlags |= AUDIOPLAYER_STARTED; |
| 715 | mFlags |= AUDIO_RUNNING; |
| 716 | mTimeSource = mVeAudioPlayer; |
| 717 | deferredAudioSeek = true; |
| 718 | mWatchForAudioSeekComplete = false; |
| 719 | mWatchForAudioEOS = true; |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 720 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | if (mTimeSource == NULL && mAudioPlayer == NULL) { |
| 724 | mTimeSource = &mSystemTimeSource; |
| 725 | } |
| 726 | |
Dharmaray Kundargi | 53c567c | 2011-01-29 18:52:50 -0800 | [diff] [blame] | 727 | // Set the seek option for Image source files and read. |
| 728 | // This resets the timestamping for image play |
| 729 | if (mIsVideoSourceJpg) { |
| 730 | MediaSource::ReadOptions options; |
| 731 | MediaBuffer *aLocalBuffer; |
| 732 | options.setSeekTo(mSeekTimeUs); |
| 733 | mVideoSource->read(&aLocalBuffer, &options); |
Santosh Madhava | 4ca3e5d | 2011-02-11 20:28:45 -0800 | [diff] [blame] | 734 | aLocalBuffer->release(); |
Dharmaray Kundargi | 53c567c | 2011-01-29 18:52:50 -0800 | [diff] [blame] | 735 | } |
| 736 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 737 | if (mVideoSource != NULL) { |
| 738 | // Kick off video playback |
| 739 | postVideoEvent_l(); |
| 740 | } |
| 741 | |
| 742 | if (deferredAudioSeek) { |
| 743 | // If there was a seek request while we were paused |
| 744 | // and we're just starting up again, honor the request now. |
| 745 | seekAudioIfNecessary_l(); |
| 746 | } |
| 747 | |
| 748 | if (mFlags & AT_EOS) { |
| 749 | // Legacy behaviour, if a stream finishes playing and then |
| 750 | // is started again, we play from the start... |
| 751 | seekTo_l(0); |
| 752 | } |
| 753 | |
| 754 | return OK; |
| 755 | } |
| 756 | |
| 757 | |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 758 | status_t PreviewPlayer::initRenderer_l() { |
Mathias Agopian | 6e22429 | 2011-04-05 15:38:24 -0700 | [diff] [blame] | 759 | if (mSurface != NULL) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 760 | sp<MetaData> meta = mVideoSource->getFormat(); |
| 761 | |
| 762 | int32_t format; |
| 763 | const char *component; |
| 764 | int32_t decodedWidth, decodedHeight; |
| 765 | CHECK(meta->findInt32(kKeyColorFormat, &format)); |
| 766 | CHECK(meta->findCString(kKeyDecoderComponent, &component)); |
| 767 | CHECK(meta->findInt32(kKeyWidth, &decodedWidth)); |
| 768 | CHECK(meta->findInt32(kKeyHeight, &decodedHeight)); |
| 769 | |
| 770 | // Must ensure that mVideoRenderer's destructor is actually executed |
| 771 | // before creating a new one. |
| 772 | IPCThreadState::self()->flushCommands(); |
| 773 | |
| 774 | // always use localrenderer since decoded buffers are modified |
| 775 | // by postprocessing module |
| 776 | // Other decoders are instantiated locally and as a consequence |
| 777 | // allocate their buffers in local address space. |
| 778 | if(mVideoRenderer == NULL) { |
| 779 | |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 780 | mVideoRenderer = PreviewLocalRenderer:: initPreviewLocalRenderer ( |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 781 | false, // previewOnly |
| 782 | (OMX_COLOR_FORMATTYPE)format, |
| 783 | mSurface, |
| 784 | mOutputVideoWidth, mOutputVideoHeight, |
| 785 | mOutputVideoWidth, mOutputVideoHeight); |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 786 | |
| 787 | if ( mVideoRenderer == NULL ) |
| 788 | { |
| 789 | return UNKNOWN_ERROR; |
| 790 | } |
| 791 | return OK; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 792 | } |
| 793 | } |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 794 | return OK; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 798 | status_t PreviewPlayer::seekTo(int64_t timeUs) { |
| 799 | |
| 800 | if ((mExtractorFlags & MediaExtractor::CAN_SEEK) || (mIsVideoSourceJpg)) { |
| 801 | Mutex::Autolock autoLock(mLock); |
| 802 | return seekTo_l(timeUs); |
| 803 | } |
| 804 | |
| 805 | return OK; |
| 806 | } |
| 807 | |
| 808 | |
| 809 | status_t PreviewPlayer::getVideoDimensions( |
| 810 | int32_t *width, int32_t *height) const { |
| 811 | Mutex::Autolock autoLock(mLock); |
| 812 | |
| 813 | if (mVideoWidth < 0 || mVideoHeight < 0) { |
| 814 | return UNKNOWN_ERROR; |
| 815 | } |
| 816 | |
| 817 | *width = mVideoWidth; |
| 818 | *height = mVideoHeight; |
| 819 | |
| 820 | return OK; |
| 821 | } |
| 822 | |
| 823 | |
| 824 | status_t PreviewPlayer::initAudioDecoder() { |
| 825 | sp<MetaData> meta = mAudioTrack->getFormat(); |
| 826 | const char *mime; |
| 827 | CHECK(meta->findCString(kKeyMIMEType, &mime)); |
| 828 | |
| 829 | if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_RAW)) { |
| 830 | mAudioSource = mAudioTrack; |
| 831 | } else { |
| 832 | sp<MediaSource> aRawSource; |
| 833 | aRawSource = OMXCodec::Create( |
| 834 | mClient.interface(), mAudioTrack->getFormat(), |
| 835 | false, // createEncoder |
| 836 | mAudioTrack); |
| 837 | |
| 838 | if(aRawSource != NULL) { |
| 839 | LOGV("initAudioDecoder: new VideoEditorSRC"); |
| 840 | mAudioSource = new VideoEditorSRC(aRawSource); |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | if (mAudioSource != NULL) { |
| 845 | int64_t durationUs; |
| 846 | if (mAudioTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) { |
| 847 | Mutex::Autolock autoLock(mMiscStateLock); |
| 848 | if (mDurationUs < 0 || durationUs > mDurationUs) { |
| 849 | mDurationUs = durationUs; |
| 850 | } |
| 851 | } |
| 852 | status_t err = mAudioSource->start(); |
| 853 | |
| 854 | if (err != OK) { |
| 855 | mAudioSource.clear(); |
| 856 | return err; |
| 857 | } |
| 858 | } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_QCELP)) { |
| 859 | // For legacy reasons we're simply going to ignore the absence |
| 860 | // of an audio decoder for QCELP instead of aborting playback |
| 861 | // altogether. |
| 862 | return OK; |
| 863 | } |
| 864 | |
| 865 | return mAudioSource != NULL ? OK : UNKNOWN_ERROR; |
| 866 | } |
| 867 | |
| 868 | |
| 869 | status_t PreviewPlayer::initVideoDecoder(uint32_t flags) { |
| 870 | |
| 871 | mVideoSource = OMXCodec::Create( |
| 872 | mClient.interface(), mVideoTrack->getFormat(), |
| 873 | false, |
| 874 | mVideoTrack, |
| 875 | NULL, flags); |
| 876 | |
| 877 | if (mVideoSource != NULL) { |
| 878 | int64_t durationUs; |
| 879 | if (mVideoTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) { |
| 880 | Mutex::Autolock autoLock(mMiscStateLock); |
| 881 | if (mDurationUs < 0 || durationUs > mDurationUs) { |
| 882 | mDurationUs = durationUs; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | CHECK(mVideoTrack->getFormat()->findInt32(kKeyWidth, &mVideoWidth)); |
| 887 | CHECK(mVideoTrack->getFormat()->findInt32(kKeyHeight, &mVideoHeight)); |
| 888 | |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 889 | mReportedWidth = mVideoWidth; |
| 890 | mReportedHeight = mVideoHeight; |
| 891 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 892 | status_t err = mVideoSource->start(); |
| 893 | |
| 894 | if (err != OK) { |
| 895 | mVideoSource.clear(); |
| 896 | return err; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | return mVideoSource != NULL ? OK : UNKNOWN_ERROR; |
| 901 | } |
| 902 | |
| 903 | |
| 904 | void PreviewPlayer::onVideoEvent() { |
| 905 | uint32_t i=0; |
| 906 | bool bAppliedVideoEffect = false; |
| 907 | M4OSA_ERR err1 = M4NO_ERROR; |
| 908 | int64_t imageFrameTimeUs = 0; |
| 909 | |
| 910 | Mutex::Autolock autoLock(mLock); |
| 911 | if (!mVideoEventPending) { |
| 912 | // The event has been cancelled in reset_l() but had already |
| 913 | // been scheduled for execution at that time. |
| 914 | return; |
| 915 | } |
| 916 | mVideoEventPending = false; |
| 917 | |
Andreas Huber | 9e4c36a | 2011-02-08 13:12:32 -0800 | [diff] [blame] | 918 | if (mFlags & SEEK_PREVIEW) { |
| 919 | mFlags &= ~SEEK_PREVIEW; |
| 920 | return; |
| 921 | } |
| 922 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 923 | TimeSource *ts_st = &mSystemTimeSource; |
| 924 | int64_t timeStartUs = ts_st->getRealTimeUs(); |
| 925 | |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 926 | if (mSeeking != NO_SEEK) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 927 | if (mLastVideoBuffer) { |
| 928 | mLastVideoBuffer->release(); |
| 929 | mLastVideoBuffer = NULL; |
| 930 | } |
| 931 | |
| 932 | |
| 933 | if(mAudioSource != NULL) { |
| 934 | |
| 935 | // We're going to seek the video source first, followed by |
| 936 | // the audio source. |
| 937 | // In order to avoid jumps in the DataSource offset caused by |
| 938 | // the audio codec prefetching data from the old locations |
| 939 | // while the video codec is already reading data from the new |
| 940 | // locations, we'll "pause" the audio source, causing it to |
| 941 | // stop reading input data until a subsequent seek. |
| 942 | |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 943 | if (mAudioPlayer != NULL && (mFlags & AUDIO_RUNNING)) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 944 | mAudioPlayer->pause(); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 945 | mFlags &= ~AUDIO_RUNNING; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 946 | } |
| 947 | mAudioSource->pause(); |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | if (!mVideoBuffer) { |
| 952 | MediaSource::ReadOptions options; |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 953 | if (mSeeking != NO_SEEK) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 954 | LOGV("LV PLAYER seeking to %lld us (%.2f secs)", mSeekTimeUs, |
| 955 | mSeekTimeUs / 1E6); |
| 956 | |
| 957 | options.setSeekTo( |
| 958 | mSeekTimeUs, MediaSource::ReadOptions::SEEK_CLOSEST); |
| 959 | } |
| 960 | for (;;) { |
| 961 | status_t err = mVideoSource->read(&mVideoBuffer, &options); |
| 962 | options.clearSeekTo(); |
| 963 | |
| 964 | if (err != OK) { |
| 965 | CHECK_EQ(mVideoBuffer, NULL); |
| 966 | |
| 967 | if (err == INFO_FORMAT_CHANGED) { |
| 968 | LOGV("LV PLAYER VideoSource signalled format change"); |
| 969 | notifyVideoSize_l(); |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 970 | sp<MetaData> meta = mVideoSource->getFormat(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 971 | |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 972 | CHECK(meta->findInt32(kKeyWidth, &mReportedWidth)); |
| 973 | CHECK(meta->findInt32(kKeyHeight, &mReportedHeight)); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 974 | if (mVideoRenderer != NULL) { |
| 975 | mVideoRendererIsPreview = false; |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 976 | err = initRenderer_l(); |
Santosh Madhava | 4ca3e5d | 2011-02-11 20:28:45 -0800 | [diff] [blame] | 977 | if (err != OK) { |
| 978 | postStreamDoneEvent_l(err); |
| 979 | } |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 980 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 981 | } |
| 982 | continue; |
| 983 | } |
| 984 | // So video playback is complete, but we may still have |
Santosh Madhava | 342f932 | 2011-01-27 16:27:12 -0800 | [diff] [blame] | 985 | // a seek request pending that needs to be applied to the audio track |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 986 | if (mSeeking != NO_SEEK) { |
Santosh Madhava | 342f932 | 2011-01-27 16:27:12 -0800 | [diff] [blame] | 987 | LOGV("video stream ended while seeking!"); |
| 988 | } |
| 989 | finishSeekIfNecessary(-1); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 990 | LOGV("PreviewPlayer: onVideoEvent EOS reached."); |
| 991 | mFlags |= VIDEO_AT_EOS; |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 992 | mFlags |= AUDIO_AT_EOS; |
Dheeraj Sharma | 4f4efef | 2011-02-10 16:55:37 -0800 | [diff] [blame] | 993 | mOverlayUpdateEventPosted = false; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 994 | postStreamDoneEvent_l(err); |
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 995 | // Set the last decoded timestamp to duration |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 996 | mDecodedVideoTs = (mPlayEndTimeMsec*1000LL); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 997 | return; |
| 998 | } |
| 999 | |
| 1000 | if (mVideoBuffer->range_length() == 0) { |
| 1001 | // Some decoders, notably the PV AVC software decoder |
| 1002 | // return spurious empty buffers that we just want to ignore. |
| 1003 | |
| 1004 | mVideoBuffer->release(); |
| 1005 | mVideoBuffer = NULL; |
| 1006 | continue; |
| 1007 | } |
| 1008 | |
| 1009 | int64_t videoTimeUs; |
| 1010 | CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &videoTimeUs)); |
| 1011 | |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 1012 | if (mSeeking != NO_SEEK) { |
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 1013 | if (videoTimeUs < mSeekTimeUs) { |
| 1014 | // buffers are before seek time |
| 1015 | // ignore them |
| 1016 | mVideoBuffer->release(); |
| 1017 | mVideoBuffer = NULL; |
| 1018 | continue; |
| 1019 | } |
| 1020 | } else { |
| 1021 | if((videoTimeUs/1000) < mPlayBeginTimeMsec) { |
| 1022 | // Frames are before begin cut time |
| 1023 | // Donot render |
| 1024 | mVideoBuffer->release(); |
| 1025 | mVideoBuffer = NULL; |
| 1026 | continue; |
| 1027 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1028 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1029 | break; |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | mNumberDecVideoFrames++; |
| 1034 | |
| 1035 | int64_t timeUs; |
| 1036 | CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &timeUs)); |
| 1037 | |
| 1038 | { |
| 1039 | Mutex::Autolock autoLock(mMiscStateLock); |
| 1040 | mVideoTimeUs = timeUs; |
| 1041 | } |
| 1042 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1043 | |
| 1044 | if(!mStartNextPlayer) { |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 1045 | int64_t playbackTimeRemaining = (mPlayEndTimeMsec*1000LL) - timeUs; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1046 | if(playbackTimeRemaining <= 1500000) { |
| 1047 | //When less than 1.5 sec of playback left |
| 1048 | // send notification to start next player |
| 1049 | |
| 1050 | mStartNextPlayer = true; |
| 1051 | notifyListener_l(0xAAAAAAAA); |
| 1052 | } |
| 1053 | } |
| 1054 | |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 1055 | SeekType wasSeeking = mSeeking; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1056 | finishSeekIfNecessary(timeUs); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 1057 | if (mAudioPlayer != NULL && !(mFlags & (AUDIO_RUNNING))) { |
| 1058 | status_t err = startAudioPlayer_l(); |
| 1059 | if (err != OK) { |
| 1060 | LOGE("Starting the audio player failed w/ err %d", err); |
| 1061 | return; |
| 1062 | } |
| 1063 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1064 | |
| 1065 | TimeSource *ts = (mFlags & AUDIO_AT_EOS) ? &mSystemTimeSource : mTimeSource; |
| 1066 | |
| 1067 | if(ts == NULL) { |
| 1068 | mVideoBuffer->release(); |
| 1069 | mVideoBuffer = NULL; |
| 1070 | return; |
| 1071 | } |
| 1072 | |
| 1073 | if(!mIsVideoSourceJpg) { |
| 1074 | if (mFlags & FIRST_FRAME) { |
| 1075 | mFlags &= ~FIRST_FRAME; |
| 1076 | |
| 1077 | mTimeSourceDeltaUs = ts->getRealTimeUs() - timeUs; |
| 1078 | } |
| 1079 | |
| 1080 | int64_t realTimeUs, mediaTimeUs; |
| 1081 | if (!(mFlags & AUDIO_AT_EOS) && mAudioPlayer != NULL |
| 1082 | && mAudioPlayer->getMediaTimeMapping(&realTimeUs, &mediaTimeUs)) { |
| 1083 | mTimeSourceDeltaUs = realTimeUs - mediaTimeUs; |
| 1084 | } |
| 1085 | |
| 1086 | int64_t nowUs = ts->getRealTimeUs() - mTimeSourceDeltaUs; |
| 1087 | |
| 1088 | int64_t latenessUs = nowUs - timeUs; |
| 1089 | |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 1090 | if (wasSeeking != NO_SEEK) { |
Santosh Madhava | 342f932 | 2011-01-27 16:27:12 -0800 | [diff] [blame] | 1091 | // Let's display the first frame after seeking right away. |
| 1092 | latenessUs = 0; |
| 1093 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1094 | LOGV("Audio time stamp = %lld and video time stamp = %lld", |
| 1095 | ts->getRealTimeUs(),timeUs); |
| 1096 | if (latenessUs > 40000) { |
| 1097 | // We're more than 40ms late. |
| 1098 | |
| 1099 | LOGV("LV PLAYER we're late by %lld us (%.2f secs)", |
| 1100 | latenessUs, latenessUs / 1E6); |
| 1101 | |
| 1102 | mVideoBuffer->release(); |
| 1103 | mVideoBuffer = NULL; |
Dharmaray Kundargi | 4f155f0 | 2011-02-01 19:16:43 -0800 | [diff] [blame] | 1104 | postVideoEvent_l(0); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1105 | return; |
| 1106 | } |
| 1107 | |
Dharmaray Kundargi | 4f155f0 | 2011-02-01 19:16:43 -0800 | [diff] [blame] | 1108 | if (latenessUs < -25000) { |
| 1109 | // We're more than 25ms early. |
| 1110 | LOGV("We're more than 25ms early, lateness %lld", latenessUs); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1111 | |
Dharmaray Kundargi | 4f155f0 | 2011-02-01 19:16:43 -0800 | [diff] [blame] | 1112 | postVideoEvent_l(25000); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1113 | return; |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | if (mVideoRendererIsPreview || mVideoRenderer == NULL) { |
| 1118 | mVideoRendererIsPreview = false; |
| 1119 | |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 1120 | status_t err = initRenderer_l(); |
Santosh Madhava | 4ca3e5d | 2011-02-11 20:28:45 -0800 | [diff] [blame] | 1121 | if (err != OK) { |
| 1122 | postStreamDoneEvent_l(err); |
| 1123 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | // If timestamp exceeds endCutTime of clip, donot render |
| 1127 | if((timeUs/1000) > mPlayEndTimeMsec) { |
| 1128 | if (mLastVideoBuffer) { |
| 1129 | mLastVideoBuffer->release(); |
| 1130 | mLastVideoBuffer = NULL; |
| 1131 | } |
| 1132 | mLastVideoBuffer = mVideoBuffer; |
| 1133 | mVideoBuffer = NULL; |
| 1134 | mFlags |= VIDEO_AT_EOS; |
| 1135 | mFlags |= AUDIO_AT_EOS; |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 1136 | LOGV("PreviewPlayer: onVideoEvent timeUs > mPlayEndTime; send EOS.."); |
Dheeraj Sharma | 4f4efef | 2011-02-10 16:55:37 -0800 | [diff] [blame] | 1137 | mOverlayUpdateEventPosted = false; |
Santosh Madhava | fe288aa | 2011-03-01 21:31:04 -0800 | [diff] [blame] | 1138 | // Set the last decoded timestamp to duration |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 1139 | mDecodedVideoTs = (mPlayEndTimeMsec*1000LL); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1140 | postStreamDoneEvent_l(ERROR_END_OF_STREAM); |
| 1141 | return; |
| 1142 | } |
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 1143 | // Capture the frame timestamp to be rendered |
| 1144 | mDecodedVideoTs = timeUs; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1145 | |
| 1146 | // Post processing to apply video effects |
| 1147 | for(i=0;i<mNumberEffects;i++) { |
| 1148 | // First check if effect starttime matches the clip being previewed |
| 1149 | if((mEffectsSettings[i].uiStartTime < (mDecVideoTsStoryBoard/1000)) || |
| 1150 | (mEffectsSettings[i].uiStartTime >= |
| 1151 | ((mDecVideoTsStoryBoard/1000) + mPlayEndTimeMsec - mPlayBeginTimeMsec))) |
| 1152 | { |
| 1153 | // This effect doesn't belong to this clip, check next one |
| 1154 | continue; |
| 1155 | } |
| 1156 | // Check if effect applies to this particular frame timestamp |
| 1157 | if((mEffectsSettings[i].uiStartTime <= |
| 1158 | (((timeUs+mDecVideoTsStoryBoard)/1000)-mPlayBeginTimeMsec)) && |
| 1159 | ((mEffectsSettings[i].uiStartTime+mEffectsSettings[i].uiDuration) >= |
| 1160 | (((timeUs+mDecVideoTsStoryBoard)/1000)-mPlayBeginTimeMsec)) |
| 1161 | && (mEffectsSettings[i].uiDuration != 0)) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1162 | setVideoPostProcessingNode( |
| 1163 | mEffectsSettings[i].VideoEffectType, TRUE); |
| 1164 | } |
| 1165 | else { |
| 1166 | setVideoPostProcessingNode( |
| 1167 | mEffectsSettings[i].VideoEffectType, FALSE); |
| 1168 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1169 | } |
| 1170 | |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1171 | //Provide the overlay Update indication when there is an overlay effect |
Dharmaray Kundargi | d01ef56 | 2011-01-26 21:11:00 -0800 | [diff] [blame] | 1172 | if (mCurrentVideoEffect & VIDEO_EFFECT_FRAMING) { |
| 1173 | mCurrentVideoEffect &= ~VIDEO_EFFECT_FRAMING; //never apply framing here. |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1174 | if (!mOverlayUpdateEventPosted) { |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1175 | // Find the effect in effectSettings array |
Basavapatna Dattaguru | 408e25b | 2011-02-27 21:04:57 -0800 | [diff] [blame] | 1176 | M4OSA_UInt32 index; |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1177 | for (index = 0; index < mNumberEffects; index++) { |
| 1178 | M4OSA_UInt32 timeMs = mDecodedVideoTs/1000; |
| 1179 | M4OSA_UInt32 timeOffset = mDecVideoTsStoryBoard/1000; |
| 1180 | if(mEffectsSettings[index].VideoEffectType == |
Basavapatna Dattaguru | 408e25b | 2011-02-27 21:04:57 -0800 | [diff] [blame] | 1181 | (M4VSS3GPP_VideoEffectType)M4xVSS_kVideoEffectType_Framing) { |
Dharmaray Kundargi | 254c8df | 2011-01-28 19:28:31 -0800 | [diff] [blame] | 1182 | if (((mEffectsSettings[index].uiStartTime + 1) <= |
| 1183 | timeMs + timeOffset - mPlayBeginTimeMsec) && |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1184 | ((mEffectsSettings[index].uiStartTime - 1 + |
Dharmaray Kundargi | 254c8df | 2011-01-28 19:28:31 -0800 | [diff] [blame] | 1185 | mEffectsSettings[index].uiDuration) >= |
| 1186 | timeMs + timeOffset - mPlayBeginTimeMsec)) |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1187 | { |
| 1188 | break; |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | if (index < mNumberEffects) { |
| 1193 | mCurrFramingEffectIndex = index; |
| 1194 | mOverlayUpdateEventPosted = true; |
| 1195 | postOverlayUpdateEvent_l(); |
| 1196 | LOGV("Framing index = %d", mCurrFramingEffectIndex); |
| 1197 | } else { |
| 1198 | LOGV("No framing effects found"); |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | } else if (mOverlayUpdateEventPosted) { |
| 1203 | //Post the event when the overlay is no more valid |
| 1204 | LOGV("Overlay is Done"); |
| 1205 | mOverlayUpdateEventPosted = false; |
| 1206 | postOverlayUpdateEvent_l(); |
| 1207 | } |
| 1208 | |
| 1209 | |
| 1210 | if (mCurrentVideoEffect != VIDEO_EFFECT_NONE) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1211 | err1 = doVideoPostProcessing(); |
| 1212 | if(err1 != M4NO_ERROR) { |
| 1213 | LOGE("doVideoPostProcessing returned err"); |
| 1214 | bAppliedVideoEffect = false; |
| 1215 | } |
| 1216 | else { |
| 1217 | bAppliedVideoEffect = true; |
| 1218 | } |
| 1219 | } |
| 1220 | else { |
| 1221 | bAppliedVideoEffect = false; |
| 1222 | if(mRenderingMode != MEDIA_RENDERING_INVALID) { |
| 1223 | // No effects to be applied, but media rendering to be done |
| 1224 | err1 = doMediaRendering(); |
| 1225 | if(err1 != M4NO_ERROR) { |
| 1226 | LOGE("doMediaRendering returned err"); |
| 1227 | //Use original mVideoBuffer for rendering |
| 1228 | mVideoResizedOrCropped = false; |
| 1229 | } |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | if (mVideoRenderer != NULL) { |
| 1234 | LOGV("mVideoRenderer CALL render()"); |
| 1235 | mVideoRenderer->render(); |
| 1236 | } |
| 1237 | |
| 1238 | if (mLastVideoBuffer) { |
| 1239 | mLastVideoBuffer->release(); |
| 1240 | mLastVideoBuffer = NULL; |
| 1241 | } |
| 1242 | |
| 1243 | mLastVideoBuffer = mVideoBuffer; |
| 1244 | mVideoBuffer = NULL; |
| 1245 | |
| 1246 | // Post progress callback based on callback interval set |
| 1247 | if(mNumberDecVideoFrames >= mProgressCbInterval) { |
| 1248 | postProgressCallbackEvent_l(); |
| 1249 | mNumberDecVideoFrames = 0; // reset counter |
| 1250 | } |
| 1251 | |
| 1252 | // if reached EndCutTime of clip, post EOS event |
| 1253 | if((timeUs/1000) >= mPlayEndTimeMsec) { |
| 1254 | LOGV("PreviewPlayer: onVideoEvent EOS."); |
| 1255 | mFlags |= VIDEO_AT_EOS; |
| 1256 | mFlags |= AUDIO_AT_EOS; |
Dheeraj Sharma | 4f4efef | 2011-02-10 16:55:37 -0800 | [diff] [blame] | 1257 | mOverlayUpdateEventPosted = false; |
Santosh Madhava | fe288aa | 2011-03-01 21:31:04 -0800 | [diff] [blame] | 1258 | // Set the last decoded timestamp to duration |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 1259 | mDecodedVideoTs = (mPlayEndTimeMsec*1000LL); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1260 | postStreamDoneEvent_l(ERROR_END_OF_STREAM); |
| 1261 | } |
| 1262 | else { |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 1263 | if ((wasSeeking != NO_SEEK) && (mFlags & SEEK_PREVIEW)) { |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 1264 | mFlags &= ~SEEK_PREVIEW; |
| 1265 | return; |
| 1266 | } |
| 1267 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1268 | if(!mIsVideoSourceJpg) { |
Dharmaray Kundargi | 4f155f0 | 2011-02-01 19:16:43 -0800 | [diff] [blame] | 1269 | postVideoEvent_l(0); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1270 | } |
| 1271 | else { |
| 1272 | postVideoEvent_l(33000); |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | status_t PreviewPlayer::prepare() { |
| 1278 | Mutex::Autolock autoLock(mLock); |
| 1279 | return prepare_l(); |
| 1280 | } |
| 1281 | |
| 1282 | status_t PreviewPlayer::prepare_l() { |
| 1283 | if (mFlags & PREPARED) { |
| 1284 | return OK; |
| 1285 | } |
| 1286 | |
| 1287 | if (mFlags & PREPARING) { |
| 1288 | return UNKNOWN_ERROR; |
| 1289 | } |
| 1290 | |
| 1291 | mIsAsyncPrepare = false; |
| 1292 | status_t err = prepareAsync_l(); |
| 1293 | |
| 1294 | if (err != OK) { |
| 1295 | return err; |
| 1296 | } |
| 1297 | |
| 1298 | while (mFlags & PREPARING) { |
| 1299 | mPreparedCondition.wait(mLock); |
| 1300 | } |
| 1301 | |
| 1302 | return mPrepareResult; |
| 1303 | } |
| 1304 | |
| 1305 | status_t PreviewPlayer::prepareAsync_l() { |
| 1306 | if (mFlags & PREPARING) { |
| 1307 | return UNKNOWN_ERROR; // async prepare already pending |
| 1308 | } |
| 1309 | |
| 1310 | if (!mQueueStarted) { |
| 1311 | mQueue.start(); |
| 1312 | mQueueStarted = true; |
| 1313 | } |
| 1314 | |
| 1315 | mFlags |= PREPARING; |
| 1316 | mAsyncPrepareEvent = new PreviewPlayerEvent( |
| 1317 | this, &PreviewPlayer::onPrepareAsyncEvent); |
| 1318 | |
| 1319 | mQueue.postEvent(mAsyncPrepareEvent); |
| 1320 | |
| 1321 | return OK; |
| 1322 | } |
| 1323 | |
| 1324 | status_t PreviewPlayer::finishSetDataSource_l() { |
| 1325 | sp<DataSource> dataSource; |
| 1326 | sp<MediaExtractor> extractor; |
| 1327 | |
| 1328 | dataSource = DataSource::CreateFromURI(mUri.string(), &mUriHeaders); |
| 1329 | |
| 1330 | if (dataSource == NULL) { |
| 1331 | return UNKNOWN_ERROR; |
| 1332 | } |
| 1333 | |
| 1334 | //If file type is .rgb, then no need to check for Extractor |
| 1335 | int uriLen = strlen(mUri); |
| 1336 | int startOffset = uriLen - 4; |
| 1337 | if(!strncasecmp(mUri+startOffset, ".rgb", 4)) { |
| 1338 | extractor = NULL; |
| 1339 | } |
| 1340 | else { |
| 1341 | extractor = MediaExtractor::Create(dataSource, |
| 1342 | MEDIA_MIMETYPE_CONTAINER_MPEG4); |
| 1343 | } |
| 1344 | |
| 1345 | if (extractor == NULL) { |
| 1346 | LOGV("PreviewPlayer::finishSetDataSource_l extractor == NULL"); |
| 1347 | return setDataSource_l_jpg(); |
| 1348 | } |
| 1349 | |
| 1350 | return setDataSource_l(extractor); |
| 1351 | } |
| 1352 | |
| 1353 | |
| 1354 | // static |
| 1355 | bool PreviewPlayer::ContinuePreparation(void *cookie) { |
| 1356 | PreviewPlayer *me = static_cast<PreviewPlayer *>(cookie); |
| 1357 | |
| 1358 | return (me->mFlags & PREPARE_CANCELLED) == 0; |
| 1359 | } |
| 1360 | |
| 1361 | void PreviewPlayer::onPrepareAsyncEvent() { |
| 1362 | Mutex::Autolock autoLock(mLock); |
| 1363 | LOGV("onPrepareAsyncEvent"); |
| 1364 | |
| 1365 | if (mFlags & PREPARE_CANCELLED) { |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 1366 | LOGV("LV PLAYER prepare was cancelled before doing anything"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1367 | abortPrepare(UNKNOWN_ERROR); |
| 1368 | return; |
| 1369 | } |
| 1370 | |
| 1371 | if (mUri.size() > 0) { |
| 1372 | status_t err = finishSetDataSource_l(); |
| 1373 | |
| 1374 | if (err != OK) { |
| 1375 | abortPrepare(err); |
| 1376 | return; |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | if (mVideoTrack != NULL && mVideoSource == NULL) { |
| 1381 | status_t err = initVideoDecoder(OMXCodec::kHardwareCodecsOnly); |
| 1382 | |
| 1383 | if (err != OK) { |
| 1384 | abortPrepare(err); |
| 1385 | return; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | if (mAudioTrack != NULL && mAudioSource == NULL) { |
| 1390 | status_t err = initAudioDecoder(); |
| 1391 | |
| 1392 | if (err != OK) { |
| 1393 | abortPrepare(err); |
| 1394 | return; |
| 1395 | } |
| 1396 | } |
| 1397 | finishAsyncPrepare_l(); |
| 1398 | |
| 1399 | } |
| 1400 | |
| 1401 | void PreviewPlayer::finishAsyncPrepare_l() { |
| 1402 | if (mIsAsyncPrepare) { |
| 1403 | if (mVideoSource == NULL) { |
| 1404 | LOGV("finishAsyncPrepare_l: MEDIA_SET_VIDEO_SIZE 0 0 "); |
| 1405 | notifyListener_l(MEDIA_SET_VIDEO_SIZE, 0, 0); |
| 1406 | } else { |
| 1407 | LOGV("finishAsyncPrepare_l: MEDIA_SET_VIDEO_SIZE"); |
| 1408 | notifyVideoSize_l(); |
| 1409 | } |
| 1410 | LOGV("finishAsyncPrepare_l: MEDIA_PREPARED"); |
| 1411 | notifyListener_l(MEDIA_PREPARED); |
| 1412 | } |
| 1413 | |
| 1414 | mPrepareResult = OK; |
| 1415 | mFlags &= ~(PREPARING|PREPARE_CANCELLED); |
| 1416 | mFlags |= PREPARED; |
| 1417 | mAsyncPrepareEvent = NULL; |
| 1418 | mPreparedCondition.broadcast(); |
| 1419 | } |
| 1420 | |
| 1421 | status_t PreviewPlayer::suspend() { |
| 1422 | LOGV("suspend"); |
| 1423 | Mutex::Autolock autoLock(mLock); |
| 1424 | |
| 1425 | if (mSuspensionState != NULL) { |
| 1426 | if (mLastVideoBuffer == NULL) { |
| 1427 | //go into here if video is suspended again |
| 1428 | //after resuming without being played between |
| 1429 | //them |
| 1430 | SuspensionState *state = mSuspensionState; |
| 1431 | mSuspensionState = NULL; |
| 1432 | reset_l(); |
| 1433 | mSuspensionState = state; |
| 1434 | return OK; |
| 1435 | } |
| 1436 | |
| 1437 | delete mSuspensionState; |
| 1438 | mSuspensionState = NULL; |
| 1439 | } |
| 1440 | |
| 1441 | if (mFlags & PREPARING) { |
| 1442 | mFlags |= PREPARE_CANCELLED; |
| 1443 | } |
| 1444 | |
| 1445 | while (mFlags & PREPARING) { |
| 1446 | mPreparedCondition.wait(mLock); |
| 1447 | } |
| 1448 | |
| 1449 | SuspensionState *state = new SuspensionState; |
| 1450 | state->mUri = mUri; |
| 1451 | state->mUriHeaders = mUriHeaders; |
| 1452 | state->mFileSource = mFileSource; |
| 1453 | |
| 1454 | state->mFlags = mFlags & (PLAYING | AUTO_LOOPING | LOOPING | AT_EOS); |
| 1455 | getPosition(&state->mPositionUs); |
| 1456 | |
| 1457 | if (mLastVideoBuffer) { |
| 1458 | size_t size = mLastVideoBuffer->range_length(); |
| 1459 | if (size) { |
| 1460 | int32_t unreadable; |
| 1461 | if (!mLastVideoBuffer->meta_data()->findInt32( |
| 1462 | kKeyIsUnreadable, &unreadable) |
| 1463 | || unreadable == 0) { |
| 1464 | state->mLastVideoFrameSize = size; |
| 1465 | state->mLastVideoFrame = malloc(size); |
| 1466 | memcpy(state->mLastVideoFrame, |
| 1467 | (const uint8_t *)mLastVideoBuffer->data() |
| 1468 | + mLastVideoBuffer->range_offset(), |
| 1469 | size); |
| 1470 | |
| 1471 | state->mVideoWidth = mVideoWidth; |
| 1472 | state->mVideoHeight = mVideoHeight; |
| 1473 | |
| 1474 | sp<MetaData> meta = mVideoSource->getFormat(); |
| 1475 | CHECK(meta->findInt32(kKeyColorFormat, &state->mColorFormat)); |
| 1476 | CHECK(meta->findInt32(kKeyWidth, &state->mDecodedWidth)); |
| 1477 | CHECK(meta->findInt32(kKeyHeight, &state->mDecodedHeight)); |
| 1478 | } else { |
| 1479 | LOGV("Unable to save last video frame, we have no access to " |
| 1480 | "the decoded video data."); |
| 1481 | } |
| 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | reset_l(); |
| 1486 | |
| 1487 | mSuspensionState = state; |
| 1488 | |
| 1489 | return OK; |
| 1490 | } |
| 1491 | |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 1492 | void PreviewPlayer::acquireLock() { |
| 1493 | LOGV("acquireLock"); |
| 1494 | mLockControl.lock(); |
| 1495 | } |
| 1496 | |
| 1497 | void PreviewPlayer::releaseLock() { |
| 1498 | LOGV("releaseLock"); |
| 1499 | mLockControl.unlock(); |
| 1500 | } |
| 1501 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1502 | status_t PreviewPlayer::resume() { |
| 1503 | LOGV("resume"); |
| 1504 | Mutex::Autolock autoLock(mLock); |
| 1505 | |
| 1506 | if (mSuspensionState == NULL) { |
| 1507 | return INVALID_OPERATION; |
| 1508 | } |
| 1509 | |
| 1510 | SuspensionState *state = mSuspensionState; |
| 1511 | mSuspensionState = NULL; |
| 1512 | |
| 1513 | status_t err; |
| 1514 | if (state->mFileSource != NULL) { |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame] | 1515 | err = PreviewPlayerBase::setDataSource_l(state->mFileSource); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1516 | |
| 1517 | if (err == OK) { |
| 1518 | mFileSource = state->mFileSource; |
| 1519 | } |
| 1520 | } else { |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame] | 1521 | err = PreviewPlayerBase::setDataSource_l(state->mUri, &state->mUriHeaders); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | if (err != OK) { |
| 1525 | delete state; |
| 1526 | state = NULL; |
| 1527 | |
| 1528 | return err; |
| 1529 | } |
| 1530 | |
| 1531 | seekTo_l(state->mPositionUs); |
| 1532 | |
| 1533 | mFlags = state->mFlags & (AUTO_LOOPING | LOOPING | AT_EOS); |
| 1534 | |
Mathias Agopian | 6e22429 | 2011-04-05 15:38:24 -0700 | [diff] [blame] | 1535 | if (state->mLastVideoFrame && (mSurface != NULL)) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1536 | mVideoRenderer = |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 1537 | PreviewLocalRenderer::initPreviewLocalRenderer( |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1538 | true, // previewOnly |
| 1539 | (OMX_COLOR_FORMATTYPE)state->mColorFormat, |
| 1540 | mSurface, |
| 1541 | state->mVideoWidth, |
| 1542 | state->mVideoHeight, |
| 1543 | state->mDecodedWidth, |
| 1544 | state->mDecodedHeight); |
| 1545 | |
| 1546 | mVideoRendererIsPreview = true; |
| 1547 | |
| 1548 | ((PreviewLocalRenderer *)mVideoRenderer.get())->render( |
| 1549 | state->mLastVideoFrame, state->mLastVideoFrameSize); |
| 1550 | } |
| 1551 | |
| 1552 | if (state->mFlags & PLAYING) { |
| 1553 | play_l(); |
| 1554 | } |
| 1555 | |
| 1556 | mSuspensionState = state; |
| 1557 | state = NULL; |
| 1558 | |
| 1559 | return OK; |
| 1560 | } |
| 1561 | |
| 1562 | |
| 1563 | status_t PreviewPlayer::loadEffectsSettings( |
| 1564 | M4VSS3GPP_EffectSettings* pEffectSettings, int nEffects) { |
| 1565 | M4OSA_UInt32 i = 0, rgbSize = 0; |
| 1566 | M4VIFI_UInt8 *tmp = M4OSA_NULL; |
| 1567 | |
| 1568 | mNumberEffects = nEffects; |
| 1569 | mEffectsSettings = pEffectSettings; |
| 1570 | return OK; |
| 1571 | } |
| 1572 | |
| 1573 | status_t PreviewPlayer::loadAudioMixSettings( |
| 1574 | M4xVSS_AudioMixingSettings* pAudioMixSettings) { |
| 1575 | |
| 1576 | LOGV("PreviewPlayer: loadAudioMixSettings: "); |
| 1577 | mPreviewPlayerAudioMixSettings = pAudioMixSettings; |
| 1578 | return OK; |
| 1579 | } |
| 1580 | |
| 1581 | status_t PreviewPlayer::setAudioMixPCMFileHandle( |
| 1582 | M4OSA_Context pAudioMixPCMFileHandle) { |
| 1583 | |
| 1584 | LOGV("PreviewPlayer: setAudioMixPCMFileHandle: "); |
| 1585 | mAudioMixPCMFileHandle = pAudioMixPCMFileHandle; |
| 1586 | return OK; |
| 1587 | } |
| 1588 | |
| 1589 | status_t PreviewPlayer::setAudioMixStoryBoardParam( |
| 1590 | M4OSA_UInt32 audioMixStoryBoardTS, |
| 1591 | M4OSA_UInt32 currentMediaBeginCutTime, |
| 1592 | M4OSA_UInt32 primaryTrackVolValue ) { |
| 1593 | |
| 1594 | mAudioMixStoryBoardTS = audioMixStoryBoardTS; |
| 1595 | mCurrentMediaBeginCutTime = currentMediaBeginCutTime; |
| 1596 | mCurrentMediaVolumeValue = primaryTrackVolValue; |
| 1597 | return OK; |
| 1598 | } |
| 1599 | |
| 1600 | status_t PreviewPlayer::setPlaybackBeginTime(uint32_t msec) { |
| 1601 | |
| 1602 | mPlayBeginTimeMsec = msec; |
| 1603 | return OK; |
| 1604 | } |
| 1605 | |
| 1606 | status_t PreviewPlayer::setPlaybackEndTime(uint32_t msec) { |
| 1607 | |
| 1608 | mPlayEndTimeMsec = msec; |
| 1609 | return OK; |
| 1610 | } |
| 1611 | |
| 1612 | status_t PreviewPlayer::setStoryboardStartTime(uint32_t msec) { |
| 1613 | |
| 1614 | mStoryboardStartTimeMsec = msec; |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 1615 | mDecVideoTsStoryBoard = mStoryboardStartTimeMsec*1000LL; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1616 | return OK; |
| 1617 | } |
| 1618 | |
| 1619 | status_t PreviewPlayer::setProgressCallbackInterval(uint32_t cbInterval) { |
| 1620 | |
| 1621 | mProgressCbInterval = cbInterval; |
| 1622 | return OK; |
| 1623 | } |
| 1624 | |
| 1625 | |
| 1626 | status_t PreviewPlayer::setMediaRenderingMode( |
| 1627 | M4xVSS_MediaRendering mode, |
| 1628 | M4VIDEOEDITING_VideoFrameSize outputVideoSize) { |
| 1629 | |
| 1630 | mRenderingMode = mode; |
| 1631 | |
| 1632 | /* reset boolean for each clip*/ |
| 1633 | mVideoResizedOrCropped = false; |
| 1634 | |
Hong Teng | 8806b70 | 2011-07-06 18:29:28 -0700 | [diff] [blame^] | 1635 | status_t err = OK; |
| 1636 | /* get the video width and height by resolution */ |
| 1637 | err = getVideoSizeByResolution(outputVideoSize, |
| 1638 | &mOutputVideoWidth, &mOutputVideoHeight); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1639 | |
Hong Teng | 8806b70 | 2011-07-06 18:29:28 -0700 | [diff] [blame^] | 1640 | return err; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1641 | } |
| 1642 | |
| 1643 | M4OSA_ERR PreviewPlayer::doMediaRendering() { |
| 1644 | M4OSA_ERR err = M4NO_ERROR; |
| 1645 | M4VIFI_ImagePlane planeIn[3], planeOut[3]; |
| 1646 | M4VIFI_UInt8 *inBuffer = M4OSA_NULL, *finalOutputBuffer = M4OSA_NULL; |
| 1647 | M4VIFI_UInt8 *tempOutputBuffer= M4OSA_NULL; |
| 1648 | size_t videoBufferSize = 0; |
| 1649 | M4OSA_UInt32 frameSize = 0, i=0, index =0, nFrameCount =0, bufferOffset =0; |
| 1650 | int32_t colorFormat = 0; |
| 1651 | |
| 1652 | if(!mIsVideoSourceJpg) { |
| 1653 | sp<MetaData> meta = mVideoSource->getFormat(); |
| 1654 | CHECK(meta->findInt32(kKeyColorFormat, &colorFormat)); |
| 1655 | } |
| 1656 | else { |
| 1657 | colorFormat = OMX_COLOR_FormatYUV420Planar; |
| 1658 | } |
| 1659 | |
| 1660 | videoBufferSize = mVideoBuffer->size(); |
| 1661 | frameSize = (mVideoWidth*mVideoHeight*3) >> 1; |
| 1662 | |
| 1663 | uint8_t* outBuffer; |
| 1664 | size_t outBufferStride = 0; |
| 1665 | |
| 1666 | mVideoRenderer->getBuffer(&outBuffer, &outBufferStride); |
| 1667 | |
| 1668 | bufferOffset = index*frameSize; |
| 1669 | inBuffer = (M4OSA_UInt8 *)mVideoBuffer->data()+ |
| 1670 | mVideoBuffer->range_offset()+bufferOffset; |
| 1671 | |
| 1672 | |
| 1673 | /* In plane*/ |
| 1674 | prepareYUV420ImagePlane(planeIn, mVideoWidth, |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 1675 | mVideoHeight, (M4VIFI_UInt8 *)inBuffer, mReportedWidth, mReportedHeight); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1676 | |
| 1677 | // Set the output YUV420 plane to be compatible with YV12 format |
| 1678 | // W & H even |
| 1679 | // YVU instead of YUV |
| 1680 | // align buffers on 32 bits |
| 1681 | |
| 1682 | //In YV12 format, sizes must be even |
| 1683 | M4OSA_UInt32 yv12PlaneWidth = ((mOutputVideoWidth +1)>>1)<<1; |
| 1684 | M4OSA_UInt32 yv12PlaneHeight = ((mOutputVideoHeight+1)>>1)<<1; |
| 1685 | |
| 1686 | prepareYV12ImagePlane(planeOut, yv12PlaneWidth, yv12PlaneHeight, |
| 1687 | (M4OSA_UInt32)outBufferStride, (M4VIFI_UInt8 *)outBuffer); |
| 1688 | |
| 1689 | |
| 1690 | err = applyRenderingMode(planeIn, planeOut, mRenderingMode); |
| 1691 | |
| 1692 | if(err != M4NO_ERROR) |
| 1693 | { |
Basavapatna Dattaguru | 408e25b | 2011-02-27 21:04:57 -0800 | [diff] [blame] | 1694 | LOGE("doMediaRendering: applyRenderingMode returned err=0x%x", (int)err); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1695 | return err; |
| 1696 | } |
| 1697 | mVideoResizedOrCropped = true; |
| 1698 | |
| 1699 | return err; |
| 1700 | } |
| 1701 | |
| 1702 | status_t PreviewPlayer::resetJniCallbackTimeStamp() { |
| 1703 | |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 1704 | mDecVideoTsStoryBoard = mStoryboardStartTimeMsec*1000LL; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1705 | return OK; |
| 1706 | } |
| 1707 | |
| 1708 | void PreviewPlayer::postProgressCallbackEvent_l() { |
| 1709 | if (mProgressCbEventPending) { |
| 1710 | return; |
| 1711 | } |
| 1712 | mProgressCbEventPending = true; |
| 1713 | |
| 1714 | mQueue.postEvent(mProgressCbEvent); |
| 1715 | } |
| 1716 | |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1717 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1718 | void PreviewPlayer::onProgressCbEvent() { |
| 1719 | Mutex::Autolock autoLock(mLock); |
| 1720 | if (!mProgressCbEventPending) { |
| 1721 | return; |
| 1722 | } |
| 1723 | mProgressCbEventPending = false; |
| 1724 | // If playback starts from previous I-frame, |
| 1725 | // then send frame storyboard duration |
| 1726 | if((mDecodedVideoTs/1000) < mPlayBeginTimeMsec) { |
| 1727 | notifyListener_l(MEDIA_INFO, 0, mDecVideoTsStoryBoard/1000); |
| 1728 | } |
| 1729 | else { |
| 1730 | notifyListener_l(MEDIA_INFO, 0, |
| 1731 | (((mDecodedVideoTs+mDecVideoTsStoryBoard)/1000)-mPlayBeginTimeMsec)); |
| 1732 | } |
| 1733 | } |
| 1734 | |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1735 | void PreviewPlayer::postOverlayUpdateEvent_l() { |
| 1736 | if (mOverlayUpdateEventPending) { |
| 1737 | return; |
| 1738 | } |
| 1739 | mOverlayUpdateEventPending = true; |
| 1740 | mQueue.postEvent(mOverlayUpdateEvent); |
| 1741 | } |
| 1742 | |
| 1743 | void PreviewPlayer::onUpdateOverlayEvent() { |
| 1744 | Mutex::Autolock autoLock(mLock); |
| 1745 | |
| 1746 | if (!mOverlayUpdateEventPending) { |
| 1747 | return; |
| 1748 | } |
| 1749 | mOverlayUpdateEventPending = false; |
| 1750 | |
| 1751 | int updateState; |
| 1752 | if (mOverlayUpdateEventPosted) { |
| 1753 | updateState = 1; |
| 1754 | } else { |
| 1755 | updateState = 0; |
| 1756 | } |
| 1757 | notifyListener_l(0xBBBBBBBB, updateState, mCurrFramingEffectIndex); |
| 1758 | } |
| 1759 | |
| 1760 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1761 | void PreviewPlayer::setVideoPostProcessingNode( |
| 1762 | M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable) { |
| 1763 | |
| 1764 | uint32_t effect = VIDEO_EFFECT_NONE; |
| 1765 | |
| 1766 | //Map M4VSS3GPP_VideoEffectType to local enum |
| 1767 | switch(type) { |
| 1768 | case M4VSS3GPP_kVideoEffectType_FadeFromBlack: |
| 1769 | effect = VIDEO_EFFECT_FADEFROMBLACK; |
| 1770 | break; |
| 1771 | |
| 1772 | case M4VSS3GPP_kVideoEffectType_FadeToBlack: |
| 1773 | effect = VIDEO_EFFECT_FADETOBLACK; |
| 1774 | break; |
| 1775 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1776 | case M4xVSS_kVideoEffectType_BlackAndWhite: |
| 1777 | effect = VIDEO_EFFECT_BLACKANDWHITE; |
| 1778 | break; |
| 1779 | |
| 1780 | case M4xVSS_kVideoEffectType_Pink: |
| 1781 | effect = VIDEO_EFFECT_PINK; |
| 1782 | break; |
| 1783 | |
| 1784 | case M4xVSS_kVideoEffectType_Green: |
| 1785 | effect = VIDEO_EFFECT_GREEN; |
| 1786 | break; |
| 1787 | |
| 1788 | case M4xVSS_kVideoEffectType_Sepia: |
| 1789 | effect = VIDEO_EFFECT_SEPIA; |
| 1790 | break; |
| 1791 | |
| 1792 | case M4xVSS_kVideoEffectType_Negative: |
| 1793 | effect = VIDEO_EFFECT_NEGATIVE; |
| 1794 | break; |
| 1795 | |
| 1796 | case M4xVSS_kVideoEffectType_Framing: |
| 1797 | effect = VIDEO_EFFECT_FRAMING; |
| 1798 | break; |
| 1799 | |
| 1800 | case M4xVSS_kVideoEffectType_Fifties: |
| 1801 | effect = VIDEO_EFFECT_FIFTIES; |
| 1802 | break; |
| 1803 | |
| 1804 | case M4xVSS_kVideoEffectType_ColorRGB16: |
| 1805 | effect = VIDEO_EFFECT_COLOR_RGB16; |
| 1806 | break; |
| 1807 | |
| 1808 | case M4xVSS_kVideoEffectType_Gradient: |
| 1809 | effect = VIDEO_EFFECT_GRADIENT; |
| 1810 | break; |
| 1811 | |
| 1812 | default: |
| 1813 | effect = VIDEO_EFFECT_NONE; |
| 1814 | break; |
| 1815 | } |
| 1816 | |
| 1817 | if(enable == M4OSA_TRUE) { |
| 1818 | //If already set, then no need to set again |
| 1819 | if(!(mCurrentVideoEffect & effect)) { |
| 1820 | mCurrentVideoEffect |= effect; |
| 1821 | if(effect == VIDEO_EFFECT_FIFTIES) { |
| 1822 | mIsFiftiesEffectStarted = true; |
| 1823 | } |
| 1824 | } |
| 1825 | } |
| 1826 | else { |
| 1827 | //Reset only if already set |
| 1828 | if(mCurrentVideoEffect & effect) { |
| 1829 | mCurrentVideoEffect &= ~effect; |
| 1830 | } |
| 1831 | } |
| 1832 | } |
| 1833 | |
| 1834 | status_t PreviewPlayer::setImageClipProperties(uint32_t width,uint32_t height) { |
| 1835 | mVideoWidth = width; |
| 1836 | mVideoHeight = height; |
| 1837 | return OK; |
| 1838 | } |
| 1839 | |
| 1840 | |
| 1841 | M4OSA_ERR PreviewPlayer::doVideoPostProcessing() { |
| 1842 | M4OSA_ERR err = M4NO_ERROR; |
| 1843 | vePostProcessParams postProcessParams; |
| 1844 | int32_t colorFormat = 0; |
| 1845 | |
| 1846 | |
| 1847 | if(!mIsVideoSourceJpg) { |
| 1848 | sp<MetaData> meta = mVideoSource->getFormat(); |
| 1849 | CHECK(meta->findInt32(kKeyColorFormat, &colorFormat)); |
| 1850 | } |
| 1851 | else { |
| 1852 | colorFormat = OMX_COLOR_FormatYUV420Planar; |
| 1853 | } |
| 1854 | |
| 1855 | if((colorFormat == OMX_COLOR_FormatYUV420SemiPlanar) || |
| 1856 | (colorFormat == 0x7FA30C00)) { |
| 1857 | LOGE("doVideoPostProcessing: colorFormat YUV420Sp not supported"); |
| 1858 | return M4ERR_UNSUPPORTED_MEDIA_TYPE; |
| 1859 | } |
| 1860 | |
| 1861 | postProcessParams.vidBuffer = (M4VIFI_UInt8*)mVideoBuffer->data() |
| 1862 | + mVideoBuffer->range_offset(); |
| 1863 | |
| 1864 | postProcessParams.videoWidth = mVideoWidth; |
| 1865 | postProcessParams.videoHeight = mVideoHeight; |
| 1866 | postProcessParams.timeMs = mDecodedVideoTs/1000; |
| 1867 | postProcessParams.timeOffset = mDecVideoTsStoryBoard/1000; |
| 1868 | postProcessParams.effectsSettings = mEffectsSettings; |
| 1869 | postProcessParams.numberEffects = mNumberEffects; |
| 1870 | postProcessParams.outVideoWidth = mOutputVideoWidth; |
| 1871 | postProcessParams.outVideoHeight = mOutputVideoHeight; |
| 1872 | postProcessParams.currentVideoEffect = mCurrentVideoEffect; |
| 1873 | postProcessParams.renderingMode = mRenderingMode; |
| 1874 | if(mIsFiftiesEffectStarted == M4OSA_TRUE) { |
| 1875 | postProcessParams.isFiftiesEffectStarted = M4OSA_TRUE; |
| 1876 | mIsFiftiesEffectStarted = M4OSA_FALSE; |
| 1877 | } |
| 1878 | else { |
| 1879 | postProcessParams.isFiftiesEffectStarted = M4OSA_FALSE; |
| 1880 | } |
| 1881 | |
| 1882 | postProcessParams.overlayFrameRGBBuffer = mFrameRGBBuffer; |
| 1883 | postProcessParams.overlayFrameYUVBuffer = mFrameYUVBuffer; |
| 1884 | mVideoRenderer->getBuffer(&(postProcessParams.pOutBuffer), &(postProcessParams.outBufferStride)); |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 1885 | err = applyEffectsAndRenderingMode(&postProcessParams, mReportedWidth, mReportedHeight); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1886 | |
| 1887 | return err; |
| 1888 | } |
| 1889 | |
| 1890 | status_t PreviewPlayer::readFirstVideoFrame() { |
| 1891 | LOGV("PreviewPlayer::readFirstVideoFrame"); |
| 1892 | |
| 1893 | if (!mVideoBuffer) { |
| 1894 | MediaSource::ReadOptions options; |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 1895 | if (mSeeking != NO_SEEK) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1896 | LOGV("LV PLAYER seeking to %lld us (%.2f secs)", mSeekTimeUs, |
| 1897 | mSeekTimeUs / 1E6); |
| 1898 | |
| 1899 | options.setSeekTo( |
| 1900 | mSeekTimeUs, MediaSource::ReadOptions::SEEK_CLOSEST); |
| 1901 | } |
| 1902 | for (;;) { |
| 1903 | status_t err = mVideoSource->read(&mVideoBuffer, &options); |
| 1904 | options.clearSeekTo(); |
| 1905 | |
| 1906 | if (err != OK) { |
| 1907 | CHECK_EQ(mVideoBuffer, NULL); |
| 1908 | |
| 1909 | if (err == INFO_FORMAT_CHANGED) { |
| 1910 | LOGV("LV PLAYER VideoSource signalled format change"); |
| 1911 | notifyVideoSize_l(); |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 1912 | sp<MetaData> meta = mVideoSource->getFormat(); |
| 1913 | |
| 1914 | CHECK(meta->findInt32(kKeyWidth, &mReportedWidth)); |
| 1915 | CHECK(meta->findInt32(kKeyHeight, &mReportedHeight)); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1916 | |
| 1917 | if (mVideoRenderer != NULL) { |
| 1918 | mVideoRendererIsPreview = false; |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 1919 | err = initRenderer_l(); |
Santosh Madhava | 4ca3e5d | 2011-02-11 20:28:45 -0800 | [diff] [blame] | 1920 | if (err != OK) { |
| 1921 | postStreamDoneEvent_l(err); |
| 1922 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1923 | } |
| 1924 | continue; |
| 1925 | } |
| 1926 | LOGV("PreviewPlayer: onVideoEvent EOS reached."); |
| 1927 | mFlags |= VIDEO_AT_EOS; |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 1928 | mFlags |= AUDIO_AT_EOS; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1929 | postStreamDoneEvent_l(err); |
| 1930 | return OK; |
| 1931 | } |
| 1932 | |
| 1933 | if (mVideoBuffer->range_length() == 0) { |
| 1934 | // Some decoders, notably the PV AVC software decoder |
| 1935 | // return spurious empty buffers that we just want to ignore. |
| 1936 | |
| 1937 | mVideoBuffer->release(); |
| 1938 | mVideoBuffer = NULL; |
| 1939 | continue; |
| 1940 | } |
| 1941 | |
| 1942 | int64_t videoTimeUs; |
| 1943 | CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &videoTimeUs)); |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 1944 | if (mSeeking != NO_SEEK) { |
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 1945 | if (videoTimeUs < mSeekTimeUs) { |
| 1946 | // buffers are before seek time |
| 1947 | // ignore them |
| 1948 | mVideoBuffer->release(); |
| 1949 | mVideoBuffer = NULL; |
| 1950 | continue; |
| 1951 | } |
| 1952 | } else { |
| 1953 | if((videoTimeUs/1000) < mPlayBeginTimeMsec) { |
| 1954 | // buffers are before begin cut time |
| 1955 | // ignore them |
| 1956 | mVideoBuffer->release(); |
| 1957 | mVideoBuffer = NULL; |
| 1958 | continue; |
| 1959 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1960 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1961 | break; |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | int64_t timeUs; |
| 1966 | CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &timeUs)); |
| 1967 | |
| 1968 | { |
| 1969 | Mutex::Autolock autoLock(mMiscStateLock); |
| 1970 | mVideoTimeUs = timeUs; |
| 1971 | } |
| 1972 | |
| 1973 | mDecodedVideoTs = timeUs; |
| 1974 | |
| 1975 | return OK; |
| 1976 | |
| 1977 | } |
| 1978 | |
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 1979 | status_t PreviewPlayer::getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs) { |
| 1980 | *lastRenderedTimeMs = (((mDecodedVideoTs+mDecVideoTsStoryBoard)/1000)-mPlayBeginTimeMsec); |
| 1981 | return OK; |
| 1982 | } |
| 1983 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1984 | } // namespace android |