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 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 24 | #include "PreviewPlayer.h" |
| 25 | #include "DummyAudioSource.h" |
| 26 | #include "DummyVideoSource.h" |
| 27 | #include "VideoEditorSRC.h" |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 28 | #include "include/NuCachedSource2.h" |
| 29 | #include "include/ThrottledSource.h" |
| 30 | |
| 31 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 32 | #include <binder/IPCThreadState.h> |
| 33 | #include <media/stagefright/DataSource.h> |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 34 | #include <media/stagefright/MediaBuffer.h> |
| 35 | #include <media/stagefright/MediaDefs.h> |
| 36 | #include <media/stagefright/MediaExtractor.h> |
| 37 | #include <media/stagefright/MediaDebug.h> |
| 38 | #include <media/stagefright/MediaSource.h> |
| 39 | #include <media/stagefright/MetaData.h> |
| 40 | #include <media/stagefright/OMXCodec.h> |
| 41 | |
| 42 | #include <surfaceflinger/Surface.h> |
| 43 | #include <media/stagefright/foundation/ALooper.h> |
| 44 | |
| 45 | namespace android { |
| 46 | |
| 47 | |
| 48 | struct PreviewPlayerEvent : public TimedEventQueue::Event { |
| 49 | PreviewPlayerEvent( |
| 50 | PreviewPlayer *player, |
| 51 | void (PreviewPlayer::*method)()) |
| 52 | : mPlayer(player), |
| 53 | mMethod(method) { |
| 54 | } |
| 55 | |
| 56 | protected: |
| 57 | virtual ~PreviewPlayerEvent() {} |
| 58 | |
| 59 | virtual void fire(TimedEventQueue *queue, int64_t /* now_us */) { |
| 60 | (mPlayer->*mMethod)(); |
| 61 | } |
| 62 | |
| 63 | private: |
| 64 | PreviewPlayer *mPlayer; |
| 65 | void (PreviewPlayer::*mMethod)(); |
| 66 | |
| 67 | PreviewPlayerEvent(const PreviewPlayerEvent &); |
| 68 | PreviewPlayerEvent &operator=(const PreviewPlayerEvent &); |
| 69 | }; |
| 70 | |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 71 | PreviewPlayer::PreviewPlayer(NativeWindowRenderer* renderer) |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame] | 72 | : PreviewPlayerBase(), |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 73 | mNativeWindowRenderer(renderer), |
| 74 | mCurrFramingEffectIndex(0), |
Basavapatna Dattaguru | 408e25b | 2011-02-27 21:04:57 -0800 | [diff] [blame] | 75 | mFrameRGBBuffer(NULL), |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 76 | mFrameYUVBuffer(NULL) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 77 | |
| 78 | mVideoRenderer = NULL; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 79 | mEffectsSettings = NULL; |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 80 | mVeAudioPlayer = NULL; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 81 | mAudioMixStoryBoardTS = 0; |
| 82 | mCurrentMediaBeginCutTime = 0; |
| 83 | mCurrentMediaVolumeValue = 0; |
| 84 | mNumberEffects = 0; |
| 85 | mDecodedVideoTs = 0; |
| 86 | mDecVideoTsStoryBoard = 0; |
| 87 | mCurrentVideoEffect = VIDEO_EFFECT_NONE; |
| 88 | mProgressCbInterval = 0; |
| 89 | mNumberDecVideoFrames = 0; |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 90 | mOverlayUpdateEventPosted = false; |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 91 | mIsChangeSourceRequired = true; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 92 | |
| 93 | mVideoEvent = new PreviewPlayerEvent(this, &PreviewPlayer::onVideoEvent); |
| 94 | mVideoEventPending = false; |
| 95 | mStreamDoneEvent = new PreviewPlayerEvent(this, |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 96 | &PreviewPlayer::onStreamDone); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 97 | |
| 98 | mStreamDoneEventPending = false; |
| 99 | |
| 100 | mCheckAudioStatusEvent = new PreviewPlayerEvent( |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame] | 101 | this, &PreviewPlayerBase::onCheckAudioStatus); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 102 | |
| 103 | mAudioStatusEventPending = false; |
| 104 | |
| 105 | mProgressCbEvent = new PreviewPlayerEvent(this, |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 106 | &PreviewPlayer::onProgressCbEvent); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 107 | |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 108 | mOverlayUpdateEvent = new PreviewPlayerEvent(this, |
| 109 | &PreviewPlayer::onUpdateOverlayEvent); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 110 | mProgressCbEventPending = false; |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 111 | |
| 112 | mOverlayUpdateEventPending = false; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 113 | mRenderingMode = (M4xVSS_MediaRendering)MEDIA_RENDERING_INVALID; |
| 114 | mIsFiftiesEffectStarted = false; |
| 115 | reset(); |
| 116 | } |
| 117 | |
| 118 | PreviewPlayer::~PreviewPlayer() { |
| 119 | |
| 120 | if (mQueueStarted) { |
| 121 | mQueue.stop(); |
| 122 | } |
| 123 | |
| 124 | reset(); |
| 125 | |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 126 | if (mVideoRenderer) { |
| 127 | mNativeWindowRenderer->destroyRenderInput(mVideoRenderer); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 128 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 129 | } |
| 130 | |
James Dong | daeb5b3 | 2012-01-12 12:12:40 -0800 | [diff] [blame^] | 131 | void PreviewPlayer::cancelPlayerEvents() { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 132 | mQueue.cancelEvent(mVideoEvent->eventID()); |
| 133 | mVideoEventPending = false; |
| 134 | mQueue.cancelEvent(mStreamDoneEvent->eventID()); |
| 135 | mStreamDoneEventPending = false; |
| 136 | mQueue.cancelEvent(mCheckAudioStatusEvent->eventID()); |
| 137 | mAudioStatusEventPending = false; |
| 138 | |
| 139 | mQueue.cancelEvent(mProgressCbEvent->eventID()); |
| 140 | mProgressCbEventPending = false; |
| 141 | } |
| 142 | |
James Dong | daeb5b3 | 2012-01-12 12:12:40 -0800 | [diff] [blame^] | 143 | status_t PreviewPlayer::setDataSource(const char *path) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 144 | Mutex::Autolock autoLock(mLock); |
James Dong | daeb5b3 | 2012-01-12 12:12:40 -0800 | [diff] [blame^] | 145 | return setDataSource_l(path); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 146 | } |
| 147 | |
James Dong | daeb5b3 | 2012-01-12 12:12:40 -0800 | [diff] [blame^] | 148 | status_t PreviewPlayer::setDataSource_l(const char *path) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 149 | reset_l(); |
| 150 | |
James Dong | daeb5b3 | 2012-01-12 12:12:40 -0800 | [diff] [blame^] | 151 | mUri = path; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 152 | |
| 153 | // The actual work will be done during preparation in the call to |
| 154 | // ::finishSetDataSource_l to avoid blocking the calling thread in |
| 155 | // setDataSource for any significant time. |
| 156 | return OK; |
| 157 | } |
| 158 | |
| 159 | status_t PreviewPlayer::setDataSource_l(const sp<MediaExtractor> &extractor) { |
| 160 | bool haveAudio = false; |
| 161 | bool haveVideo = false; |
| 162 | for (size_t i = 0; i < extractor->countTracks(); ++i) { |
| 163 | sp<MetaData> meta = extractor->getTrackMetaData(i); |
| 164 | |
| 165 | const char *mime; |
| 166 | CHECK(meta->findCString(kKeyMIMEType, &mime)); |
| 167 | |
| 168 | if (!haveVideo && !strncasecmp(mime, "video/", 6)) { |
| 169 | setVideoSource(extractor->getTrack(i)); |
| 170 | haveVideo = true; |
| 171 | } else if (!haveAudio && !strncasecmp(mime, "audio/", 6)) { |
| 172 | setAudioSource(extractor->getTrack(i)); |
| 173 | haveAudio = true; |
| 174 | |
| 175 | if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_VORBIS)) { |
| 176 | // Only do this for vorbis audio, none of the other audio |
| 177 | // formats even support this ringtone specific hack and |
| 178 | // retrieving the metadata on some extractors may turn out |
| 179 | // to be very expensive. |
| 180 | sp<MetaData> fileMeta = extractor->getMetaData(); |
| 181 | int32_t loop; |
| 182 | if (fileMeta != NULL |
| 183 | && fileMeta->findInt32(kKeyAutoLoop, &loop) |
| 184 | && loop != 0) { |
| 185 | mFlags |= AUTO_LOOPING; |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | if (haveAudio && haveVideo) { |
| 191 | break; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /* Add the support for Dummy audio*/ |
| 196 | if( !haveAudio ){ |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 197 | ALOGV("PreviewPlayer: setDataSource_l Dummyaudiocreation started"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 198 | |
| 199 | mAudioTrack = DummyAudioSource::Create(32000, 2, 20000, |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 200 | ((mPlayEndTimeMsec)*1000LL)); |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 201 | ALOGV("PreviewPlayer: setDataSource_l Dummyauiosource created"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 202 | if(mAudioTrack != NULL) { |
| 203 | haveAudio = true; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | if (!haveAudio && !haveVideo) { |
| 208 | return UNKNOWN_ERROR; |
| 209 | } |
| 210 | |
| 211 | mExtractorFlags = extractor->flags(); |
| 212 | return OK; |
| 213 | } |
| 214 | |
| 215 | status_t PreviewPlayer::setDataSource_l_jpg() { |
| 216 | M4OSA_ERR err = M4NO_ERROR; |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 217 | ALOGV("PreviewPlayer: setDataSource_l_jpg started"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 218 | |
| 219 | mAudioSource = DummyAudioSource::Create(32000, 2, 20000, |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 220 | ((mPlayEndTimeMsec)*1000LL)); |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 221 | ALOGV("PreviewPlayer: setDataSource_l_jpg Dummyaudiosource created"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 222 | if(mAudioSource != NULL) { |
| 223 | setAudioSource(mAudioSource); |
| 224 | } |
| 225 | status_t error = mAudioSource->start(); |
| 226 | if (error != OK) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 227 | ALOGV("Error starting dummy audio source"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 228 | mAudioSource.clear(); |
| 229 | return err; |
| 230 | } |
| 231 | |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 232 | mDurationUs = (mPlayEndTimeMsec - mPlayBeginTimeMsec)*1000LL; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 233 | |
| 234 | mVideoSource = DummyVideoSource::Create(mVideoWidth, mVideoHeight, |
| 235 | mDurationUs, mUri); |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 236 | |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 237 | updateSizeToRender(mVideoSource->getFormat()); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 238 | setVideoSource(mVideoSource); |
| 239 | status_t err1 = mVideoSource->start(); |
| 240 | if (err1 != OK) { |
| 241 | mVideoSource.clear(); |
| 242 | return err; |
| 243 | } |
| 244 | |
| 245 | mIsVideoSourceJpg = true; |
| 246 | return OK; |
| 247 | } |
| 248 | |
| 249 | void PreviewPlayer::reset() { |
| 250 | Mutex::Autolock autoLock(mLock); |
| 251 | reset_l(); |
| 252 | } |
| 253 | |
| 254 | void PreviewPlayer::reset_l() { |
| 255 | |
| 256 | if (mFlags & PREPARING) { |
| 257 | mFlags |= PREPARE_CANCELLED; |
| 258 | } |
| 259 | |
| 260 | while (mFlags & PREPARING) { |
| 261 | mPreparedCondition.wait(mLock); |
| 262 | } |
| 263 | |
| 264 | cancelPlayerEvents(); |
| 265 | mAudioTrack.clear(); |
| 266 | mVideoTrack.clear(); |
| 267 | |
| 268 | // Shutdown audio first, so that the respone to the reset request |
| 269 | // appears to happen instantaneously as far as the user is concerned |
| 270 | // If we did this later, audio would continue playing while we |
| 271 | // shutdown the video-related resources and the player appear to |
| 272 | // not be as responsive to a reset request. |
| 273 | if (mAudioPlayer == NULL && mAudioSource != NULL) { |
| 274 | // If we had an audio player, it would have effectively |
| 275 | // taken possession of the audio source and stopped it when |
| 276 | // _it_ is stopped. Otherwise this is still our responsibility. |
| 277 | mAudioSource->stop(); |
| 278 | } |
| 279 | mAudioSource.clear(); |
| 280 | |
| 281 | mTimeSource = NULL; |
| 282 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 283 | //Single audio player instance used |
| 284 | //So donot delete it here |
| 285 | //It is deleted from PreviewController class |
| 286 | //delete mAudioPlayer; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 287 | mAudioPlayer = NULL; |
| 288 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 289 | if (mVideoBuffer) { |
| 290 | mVideoBuffer->release(); |
| 291 | mVideoBuffer = NULL; |
| 292 | } |
| 293 | |
| 294 | if (mVideoSource != NULL) { |
| 295 | mVideoSource->stop(); |
| 296 | |
| 297 | // The following hack is necessary to ensure that the OMX |
| 298 | // component is completely released by the time we may try |
| 299 | // to instantiate it again. |
| 300 | wp<MediaSource> tmp = mVideoSource; |
| 301 | mVideoSource.clear(); |
| 302 | while (tmp.promote() != NULL) { |
| 303 | usleep(1000); |
| 304 | } |
| 305 | IPCThreadState::self()->flushCommands(); |
| 306 | } |
| 307 | |
| 308 | mDurationUs = -1; |
| 309 | mFlags = 0; |
| 310 | mExtractorFlags = 0; |
| 311 | mVideoWidth = mVideoHeight = -1; |
| 312 | mTimeSourceDeltaUs = 0; |
| 313 | mVideoTimeUs = 0; |
| 314 | |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 315 | mSeeking = NO_SEEK; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 316 | mSeekNotificationSent = false; |
| 317 | mSeekTimeUs = 0; |
| 318 | |
| 319 | mUri.setTo(""); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 320 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 321 | mCurrentVideoEffect = VIDEO_EFFECT_NONE; |
| 322 | mIsVideoSourceJpg = false; |
| 323 | mFrameRGBBuffer = NULL; |
| 324 | if(mFrameYUVBuffer != NULL) { |
Shyam Pallapothu | 694816d | 2011-04-21 09:48:41 -0700 | [diff] [blame] | 325 | free(mFrameYUVBuffer); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 326 | mFrameYUVBuffer = NULL; |
| 327 | } |
| 328 | } |
| 329 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 330 | status_t PreviewPlayer::play() { |
| 331 | Mutex::Autolock autoLock(mLock); |
| 332 | |
| 333 | mFlags &= ~CACHE_UNDERRUN; |
Hong Teng | e018023 | 2011-09-28 18:40:38 -0700 | [diff] [blame] | 334 | mFlags &= ~INFORMED_AV_EOS; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 335 | return play_l(); |
| 336 | } |
| 337 | |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 338 | status_t PreviewPlayer::startAudioPlayer_l() { |
| 339 | CHECK(!(mFlags & AUDIO_RUNNING)); |
| 340 | |
| 341 | if (mAudioSource == NULL || mAudioPlayer == NULL) { |
| 342 | return OK; |
| 343 | } |
| 344 | |
| 345 | if (!(mFlags & AUDIOPLAYER_STARTED)) { |
| 346 | mFlags |= AUDIOPLAYER_STARTED; |
| 347 | |
| 348 | // We've already started the MediaSource in order to enable |
| 349 | // the prefetcher to read its data. |
| 350 | status_t err = mVeAudioPlayer->start( |
| 351 | true /* sourceAlreadyStarted */); |
| 352 | |
| 353 | if (err != OK) { |
| 354 | notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err); |
| 355 | return err; |
| 356 | } |
| 357 | } else { |
| 358 | mVeAudioPlayer->resume(); |
| 359 | } |
| 360 | |
| 361 | mFlags |= AUDIO_RUNNING; |
| 362 | |
| 363 | mWatchForAudioEOS = true; |
| 364 | |
| 365 | return OK; |
| 366 | } |
| 367 | |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame] | 368 | status_t PreviewPlayer::setAudioPlayer(AudioPlayerBase *audioPlayer) { |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 369 | Mutex::Autolock autoLock(mLock); |
| 370 | CHECK(!(mFlags & PLAYING)); |
| 371 | mAudioPlayer = audioPlayer; |
| 372 | |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 373 | ALOGV("SetAudioPlayer"); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 374 | mIsChangeSourceRequired = true; |
| 375 | mVeAudioPlayer = |
| 376 | (VideoEditorAudioPlayer*)mAudioPlayer; |
| 377 | |
| 378 | // check if the new and old source are dummy |
| 379 | sp<MediaSource> anAudioSource = mVeAudioPlayer->getSource(); |
| 380 | if (anAudioSource == NULL) { |
| 381 | // Audio player does not have any source set. |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 382 | ALOGV("setAudioPlayer: Audio player does not have any source set"); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 383 | return OK; |
| 384 | } |
| 385 | |
Rajneesh Chowdury | 9a8c9a8 | 2011-03-11 14:02:47 -0800 | [diff] [blame] | 386 | // If new video source is not dummy, then always change source |
| 387 | // Else audio player continues using old audio source and there are |
| 388 | // frame drops to maintain AV sync |
| 389 | sp<MetaData> meta; |
| 390 | if (mVideoSource != NULL) { |
| 391 | meta = mVideoSource->getFormat(); |
| 392 | const char *pVidSrcType; |
| 393 | if (meta->findCString(kKeyDecoderComponent, &pVidSrcType)) { |
| 394 | if (strcmp(pVidSrcType, "DummyVideoSource") != 0) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 395 | ALOGV(" Video clip with silent audio; need to change source"); |
Rajneesh Chowdury | 9a8c9a8 | 2011-03-11 14:02:47 -0800 | [diff] [blame] | 396 | return OK; |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 401 | const char *pSrcType1; |
| 402 | const char *pSrcType2; |
Rajneesh Chowdury | 9a8c9a8 | 2011-03-11 14:02:47 -0800 | [diff] [blame] | 403 | meta = anAudioSource->getFormat(); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 404 | |
| 405 | if (meta->findCString(kKeyDecoderComponent, &pSrcType1)) { |
| 406 | if (strcmp(pSrcType1, "DummyAudioSource") == 0) { |
| 407 | meta = mAudioSource->getFormat(); |
| 408 | if (meta->findCString(kKeyDecoderComponent, &pSrcType2)) { |
| 409 | if (strcmp(pSrcType2, "DummyAudioSource") == 0) { |
| 410 | mIsChangeSourceRequired = false; |
| 411 | // Just set the new play duration for the existing source |
| 412 | MediaSource *pMediaSrc = anAudioSource.get(); |
| 413 | DummyAudioSource *pDummyAudioSource = (DummyAudioSource*)pMediaSrc; |
| 414 | //Increment the duration of audio source |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 415 | pDummyAudioSource->setDuration( |
| 416 | (int64_t)((mPlayEndTimeMsec)*1000LL)); |
Rajneesh Chowdury | b6e2b5c | 2011-02-25 22:59:46 -0800 | [diff] [blame] | 417 | |
| 418 | // Stop the new audio source |
| 419 | // since we continue using old source |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 420 | ALOGV("setAudioPlayer: stop new audio source"); |
Rajneesh Chowdury | b6e2b5c | 2011-02-25 22:59:46 -0800 | [diff] [blame] | 421 | mAudioSource->stop(); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | return OK; |
| 428 | } |
| 429 | |
| 430 | void PreviewPlayer::onStreamDone() { |
| 431 | // Posted whenever any stream finishes playing. |
| 432 | |
| 433 | Mutex::Autolock autoLock(mLock); |
| 434 | if (!mStreamDoneEventPending) { |
| 435 | return; |
| 436 | } |
| 437 | mStreamDoneEventPending = false; |
| 438 | |
| 439 | if (mStreamDoneStatus != ERROR_END_OF_STREAM) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 440 | ALOGV("MEDIA_ERROR %d", mStreamDoneStatus); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 441 | |
| 442 | notifyListener_l( |
| 443 | MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, mStreamDoneStatus); |
| 444 | |
| 445 | pause_l(true /* at eos */); |
| 446 | |
| 447 | mFlags |= AT_EOS; |
| 448 | return; |
| 449 | } |
| 450 | |
| 451 | const bool allDone = |
| 452 | (mVideoSource == NULL || (mFlags & VIDEO_AT_EOS)) |
| 453 | && (mAudioSource == NULL || (mFlags & AUDIO_AT_EOS)); |
| 454 | |
| 455 | if (!allDone) { |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | if (mFlags & (LOOPING | AUTO_LOOPING)) { |
| 460 | seekTo_l(0); |
| 461 | |
| 462 | if (mVideoSource != NULL) { |
| 463 | postVideoEvent_l(); |
| 464 | } |
| 465 | } else { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 466 | ALOGV("MEDIA_PLAYBACK_COMPLETE"); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 467 | //pause before sending event |
| 468 | pause_l(true /* at eos */); |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 469 | |
| 470 | //This lock is used to syncronize onStreamDone() in PreviewPlayer and |
| 471 | //stopPreview() in PreviewController |
| 472 | Mutex::Autolock autoLock(mLockControl); |
Hong Teng | e018023 | 2011-09-28 18:40:38 -0700 | [diff] [blame] | 473 | /* Make sure PreviewPlayer only notifies MEDIA_PLAYBACK_COMPLETE once for each clip! |
| 474 | * It happens twice in following scenario. |
| 475 | * To make the clips in preview storyboard are played and switched smoothly, |
| 476 | * PreviewController uses two PreviewPlayer instances and one AudioPlayer. |
| 477 | * The two PreviewPlayer use the same AudioPlayer to play the audio, |
| 478 | * and change the audio source of the AudioPlayer. |
| 479 | * If the audio source of current playing clip and next clip are dummy |
| 480 | * audio source(image or video without audio), it will not change the audio source |
| 481 | * to avoid the "audio glitch", and keep using the current audio source. |
| 482 | * When the video of current clip reached the EOS, PreviewPlayer will set EOS flag |
| 483 | * for video and audio, and it will notify MEDIA_PLAYBACK_COMPLETE. |
| 484 | * But the audio(dummy audio source) is still playing(for next clip), |
| 485 | * and when it reached the EOS, and video reached EOS, |
| 486 | * PreviewPlayer will notify MEDIA_PLAYBACK_COMPLETE again. */ |
| 487 | if (!(mFlags & INFORMED_AV_EOS)) { |
| 488 | notifyListener_l(MEDIA_PLAYBACK_COMPLETE); |
| 489 | mFlags |= INFORMED_AV_EOS; |
| 490 | } |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 491 | mFlags |= AT_EOS; |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 492 | ALOGV("onStreamDone end"); |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 493 | return; |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
| 497 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 498 | status_t PreviewPlayer::play_l() { |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 499 | |
Rajneesh Chowdury | 8b95de2 | 2011-02-16 15:32:06 -0800 | [diff] [blame] | 500 | mFlags &= ~SEEK_PREVIEW; |
| 501 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 502 | if (mFlags & PLAYING) { |
| 503 | return OK; |
| 504 | } |
| 505 | mStartNextPlayer = false; |
| 506 | |
| 507 | if (!(mFlags & PREPARED)) { |
| 508 | status_t err = prepare_l(); |
| 509 | |
| 510 | if (err != OK) { |
| 511 | return err; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | mFlags |= PLAYING; |
| 516 | mFlags |= FIRST_FRAME; |
| 517 | |
| 518 | bool deferredAudioSeek = false; |
| 519 | |
| 520 | if (mAudioSource != NULL) { |
| 521 | if (mAudioPlayer == NULL) { |
| 522 | if (mAudioSink != NULL) { |
| 523 | |
| 524 | mAudioPlayer = new VideoEditorAudioPlayer(mAudioSink, this); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 525 | mVeAudioPlayer = |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 526 | (VideoEditorAudioPlayer*)mAudioPlayer; |
| 527 | |
| 528 | mAudioPlayer->setSource(mAudioSource); |
| 529 | |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 530 | mVeAudioPlayer->setAudioMixSettings( |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 531 | mPreviewPlayerAudioMixSettings); |
| 532 | |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 533 | mVeAudioPlayer->setAudioMixPCMFileHandle( |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 534 | mAudioMixPCMFileHandle); |
| 535 | |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 536 | mVeAudioPlayer->setAudioMixStoryBoardSkimTimeStamp( |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 537 | mAudioMixStoryBoardTS, mCurrentMediaBeginCutTime, |
| 538 | mCurrentMediaVolumeValue); |
| 539 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 540 | mFlags |= AUDIOPLAYER_STARTED; |
| 541 | // We've already started the MediaSource in order to enable |
| 542 | // the prefetcher to read its data. |
| 543 | status_t err = mVeAudioPlayer->start( |
| 544 | true /* sourceAlreadyStarted */); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 545 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 546 | if (err != OK) { |
| 547 | //delete mAudioPlayer; |
| 548 | mAudioPlayer = NULL; |
| 549 | |
| 550 | mFlags &= ~(PLAYING | FIRST_FRAME); |
| 551 | return err; |
| 552 | } |
| 553 | |
| 554 | mTimeSource = mVeAudioPlayer; |
| 555 | mFlags |= AUDIO_RUNNING; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 556 | deferredAudioSeek = true; |
| 557 | mWatchForAudioSeekComplete = false; |
| 558 | mWatchForAudioEOS = true; |
| 559 | } |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 560 | } else { |
| 561 | mVeAudioPlayer = (VideoEditorAudioPlayer*)mAudioPlayer; |
| 562 | bool isAudioPlayerStarted = mVeAudioPlayer->isStarted(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 563 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 564 | if (mIsChangeSourceRequired == true) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 565 | ALOGV("play_l: Change audio source required"); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 566 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 567 | if (isAudioPlayerStarted == true) { |
| 568 | mVeAudioPlayer->pause(); |
| 569 | } |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 570 | |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 571 | mVeAudioPlayer->setSource(mAudioSource); |
| 572 | mVeAudioPlayer->setObserver(this); |
| 573 | |
| 574 | mVeAudioPlayer->setAudioMixSettings( |
| 575 | mPreviewPlayerAudioMixSettings); |
| 576 | |
| 577 | mVeAudioPlayer->setAudioMixStoryBoardSkimTimeStamp( |
| 578 | mAudioMixStoryBoardTS, mCurrentMediaBeginCutTime, |
| 579 | mCurrentMediaVolumeValue); |
| 580 | |
| 581 | if (isAudioPlayerStarted == true) { |
| 582 | mVeAudioPlayer->resume(); |
| 583 | } else { |
| 584 | status_t err = OK; |
| 585 | err = mVeAudioPlayer->start(true); |
| 586 | if (err != OK) { |
| 587 | mAudioPlayer = NULL; |
| 588 | mVeAudioPlayer = NULL; |
| 589 | |
| 590 | mFlags &= ~(PLAYING | FIRST_FRAME); |
| 591 | return err; |
| 592 | } |
| 593 | } |
| 594 | } else { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 595 | ALOGV("play_l: No Source change required"); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 596 | mVeAudioPlayer->setAudioMixStoryBoardSkimTimeStamp( |
| 597 | mAudioMixStoryBoardTS, mCurrentMediaBeginCutTime, |
| 598 | mCurrentMediaVolumeValue); |
| 599 | |
| 600 | mVeAudioPlayer->resume(); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 601 | } |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 602 | |
| 603 | mFlags |= AUDIOPLAYER_STARTED; |
| 604 | mFlags |= AUDIO_RUNNING; |
| 605 | mTimeSource = mVeAudioPlayer; |
| 606 | deferredAudioSeek = true; |
| 607 | mWatchForAudioSeekComplete = false; |
| 608 | mWatchForAudioEOS = true; |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 609 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | if (mTimeSource == NULL && mAudioPlayer == NULL) { |
| 613 | mTimeSource = &mSystemTimeSource; |
| 614 | } |
| 615 | |
Dharmaray Kundargi | 53c567c | 2011-01-29 18:52:50 -0800 | [diff] [blame] | 616 | // Set the seek option for Image source files and read. |
| 617 | // This resets the timestamping for image play |
| 618 | if (mIsVideoSourceJpg) { |
| 619 | MediaSource::ReadOptions options; |
| 620 | MediaBuffer *aLocalBuffer; |
| 621 | options.setSeekTo(mSeekTimeUs); |
| 622 | mVideoSource->read(&aLocalBuffer, &options); |
Santosh Madhava | 4ca3e5d | 2011-02-11 20:28:45 -0800 | [diff] [blame] | 623 | aLocalBuffer->release(); |
Dharmaray Kundargi | 53c567c | 2011-01-29 18:52:50 -0800 | [diff] [blame] | 624 | } |
| 625 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 626 | if (mVideoSource != NULL) { |
| 627 | // Kick off video playback |
| 628 | postVideoEvent_l(); |
| 629 | } |
| 630 | |
| 631 | if (deferredAudioSeek) { |
| 632 | // If there was a seek request while we were paused |
| 633 | // and we're just starting up again, honor the request now. |
| 634 | seekAudioIfNecessary_l(); |
| 635 | } |
| 636 | |
| 637 | if (mFlags & AT_EOS) { |
| 638 | // Legacy behaviour, if a stream finishes playing and then |
| 639 | // is started again, we play from the start... |
| 640 | seekTo_l(0); |
| 641 | } |
| 642 | |
| 643 | return OK; |
| 644 | } |
| 645 | |
| 646 | |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 647 | status_t PreviewPlayer::initRenderer_l() { |
Mathias Agopian | 6e22429 | 2011-04-05 15:38:24 -0700 | [diff] [blame] | 648 | if (mSurface != NULL) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 649 | if(mVideoRenderer == NULL) { |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 650 | mVideoRenderer = mNativeWindowRenderer->createRenderInput(); |
| 651 | if (mVideoSource != NULL) { |
| 652 | updateSizeToRender(mVideoSource->getFormat()); |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 653 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 654 | } |
| 655 | } |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 656 | return OK; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 660 | status_t PreviewPlayer::seekTo(int64_t timeUs) { |
| 661 | |
| 662 | if ((mExtractorFlags & MediaExtractor::CAN_SEEK) || (mIsVideoSourceJpg)) { |
| 663 | Mutex::Autolock autoLock(mLock); |
| 664 | return seekTo_l(timeUs); |
| 665 | } |
| 666 | |
| 667 | return OK; |
| 668 | } |
| 669 | |
| 670 | |
| 671 | status_t PreviewPlayer::getVideoDimensions( |
| 672 | int32_t *width, int32_t *height) const { |
| 673 | Mutex::Autolock autoLock(mLock); |
| 674 | |
| 675 | if (mVideoWidth < 0 || mVideoHeight < 0) { |
| 676 | return UNKNOWN_ERROR; |
| 677 | } |
| 678 | |
| 679 | *width = mVideoWidth; |
| 680 | *height = mVideoHeight; |
| 681 | |
| 682 | return OK; |
| 683 | } |
| 684 | |
| 685 | |
| 686 | status_t PreviewPlayer::initAudioDecoder() { |
| 687 | sp<MetaData> meta = mAudioTrack->getFormat(); |
| 688 | const char *mime; |
| 689 | CHECK(meta->findCString(kKeyMIMEType, &mime)); |
| 690 | |
| 691 | if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_RAW)) { |
| 692 | mAudioSource = mAudioTrack; |
| 693 | } else { |
| 694 | sp<MediaSource> aRawSource; |
| 695 | aRawSource = OMXCodec::Create( |
| 696 | mClient.interface(), mAudioTrack->getFormat(), |
| 697 | false, // createEncoder |
| 698 | mAudioTrack); |
| 699 | |
| 700 | if(aRawSource != NULL) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 701 | ALOGV("initAudioDecoder: new VideoEditorSRC"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 702 | mAudioSource = new VideoEditorSRC(aRawSource); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | if (mAudioSource != NULL) { |
| 707 | int64_t durationUs; |
| 708 | if (mAudioTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) { |
| 709 | Mutex::Autolock autoLock(mMiscStateLock); |
| 710 | if (mDurationUs < 0 || durationUs > mDurationUs) { |
| 711 | mDurationUs = durationUs; |
| 712 | } |
| 713 | } |
| 714 | status_t err = mAudioSource->start(); |
| 715 | |
| 716 | if (err != OK) { |
| 717 | mAudioSource.clear(); |
| 718 | return err; |
| 719 | } |
| 720 | } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_QCELP)) { |
| 721 | // For legacy reasons we're simply going to ignore the absence |
| 722 | // of an audio decoder for QCELP instead of aborting playback |
| 723 | // altogether. |
| 724 | return OK; |
| 725 | } |
| 726 | |
| 727 | return mAudioSource != NULL ? OK : UNKNOWN_ERROR; |
| 728 | } |
| 729 | |
| 730 | |
| 731 | status_t PreviewPlayer::initVideoDecoder(uint32_t flags) { |
| 732 | |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 733 | initRenderer_l(); |
| 734 | |
| 735 | if (mVideoRenderer == NULL) { |
Steve Block | f8bd29c | 2012-01-08 10:14:44 +0000 | [diff] [blame] | 736 | ALOGE("Cannot create renderer"); |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 737 | return UNKNOWN_ERROR; |
| 738 | } |
| 739 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 740 | mVideoSource = OMXCodec::Create( |
| 741 | mClient.interface(), mVideoTrack->getFormat(), |
| 742 | false, |
| 743 | mVideoTrack, |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 744 | NULL, flags, mVideoRenderer->getTargetWindow()); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 745 | |
| 746 | if (mVideoSource != NULL) { |
| 747 | int64_t durationUs; |
| 748 | if (mVideoTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) { |
| 749 | Mutex::Autolock autoLock(mMiscStateLock); |
| 750 | if (mDurationUs < 0 || durationUs > mDurationUs) { |
| 751 | mDurationUs = durationUs; |
| 752 | } |
| 753 | } |
| 754 | |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 755 | updateSizeToRender(mVideoTrack->getFormat()); |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 756 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 757 | status_t err = mVideoSource->start(); |
| 758 | |
| 759 | if (err != OK) { |
| 760 | mVideoSource.clear(); |
| 761 | return err; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | return mVideoSource != NULL ? OK : UNKNOWN_ERROR; |
| 766 | } |
| 767 | |
| 768 | |
| 769 | void PreviewPlayer::onVideoEvent() { |
| 770 | uint32_t i=0; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 771 | M4OSA_ERR err1 = M4NO_ERROR; |
| 772 | int64_t imageFrameTimeUs = 0; |
| 773 | |
| 774 | Mutex::Autolock autoLock(mLock); |
| 775 | if (!mVideoEventPending) { |
| 776 | // The event has been cancelled in reset_l() but had already |
| 777 | // been scheduled for execution at that time. |
| 778 | return; |
| 779 | } |
| 780 | mVideoEventPending = false; |
| 781 | |
Andreas Huber | 9e4c36a | 2011-02-08 13:12:32 -0800 | [diff] [blame] | 782 | if (mFlags & SEEK_PREVIEW) { |
| 783 | mFlags &= ~SEEK_PREVIEW; |
| 784 | return; |
| 785 | } |
| 786 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 787 | TimeSource *ts_st = &mSystemTimeSource; |
| 788 | int64_t timeStartUs = ts_st->getRealTimeUs(); |
| 789 | |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 790 | if (mSeeking != NO_SEEK) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 791 | |
| 792 | if(mAudioSource != NULL) { |
| 793 | |
| 794 | // We're going to seek the video source first, followed by |
| 795 | // the audio source. |
| 796 | // In order to avoid jumps in the DataSource offset caused by |
| 797 | // the audio codec prefetching data from the old locations |
| 798 | // while the video codec is already reading data from the new |
| 799 | // locations, we'll "pause" the audio source, causing it to |
| 800 | // stop reading input data until a subsequent seek. |
| 801 | |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 802 | if (mAudioPlayer != NULL && (mFlags & AUDIO_RUNNING)) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 803 | mAudioPlayer->pause(); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 804 | mFlags &= ~AUDIO_RUNNING; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 805 | } |
| 806 | mAudioSource->pause(); |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | if (!mVideoBuffer) { |
| 811 | MediaSource::ReadOptions options; |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 812 | if (mSeeking != NO_SEEK) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 813 | ALOGV("LV PLAYER seeking to %lld us (%.2f secs)", mSeekTimeUs, |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 814 | mSeekTimeUs / 1E6); |
| 815 | |
| 816 | options.setSeekTo( |
| 817 | mSeekTimeUs, MediaSource::ReadOptions::SEEK_CLOSEST); |
| 818 | } |
| 819 | for (;;) { |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 820 | status_t err = mVideoSource->read(&mVideoBuffer, &options); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 821 | options.clearSeekTo(); |
| 822 | |
| 823 | if (err != OK) { |
| 824 | CHECK_EQ(mVideoBuffer, NULL); |
| 825 | |
| 826 | if (err == INFO_FORMAT_CHANGED) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 827 | ALOGV("LV PLAYER VideoSource signalled format change"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 828 | notifyVideoSize_l(); |
| 829 | |
| 830 | if (mVideoRenderer != NULL) { |
| 831 | mVideoRendererIsPreview = false; |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 832 | err = initRenderer_l(); |
Santosh Madhava | 4ca3e5d | 2011-02-11 20:28:45 -0800 | [diff] [blame] | 833 | if (err != OK) { |
| 834 | postStreamDoneEvent_l(err); |
| 835 | } |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 836 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 837 | } |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 838 | |
| 839 | updateSizeToRender(mVideoSource->getFormat()); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 840 | continue; |
| 841 | } |
| 842 | // So video playback is complete, but we may still have |
Santosh Madhava | 342f932 | 2011-01-27 16:27:12 -0800 | [diff] [blame] | 843 | // 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] | 844 | if (mSeeking != NO_SEEK) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 845 | ALOGV("video stream ended while seeking!"); |
Santosh Madhava | 342f932 | 2011-01-27 16:27:12 -0800 | [diff] [blame] | 846 | } |
| 847 | finishSeekIfNecessary(-1); |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 848 | ALOGV("PreviewPlayer: onVideoEvent EOS reached."); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 849 | mFlags |= VIDEO_AT_EOS; |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 850 | mFlags |= AUDIO_AT_EOS; |
Dheeraj Sharma | 4f4efef | 2011-02-10 16:55:37 -0800 | [diff] [blame] | 851 | mOverlayUpdateEventPosted = false; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 852 | postStreamDoneEvent_l(err); |
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 853 | // Set the last decoded timestamp to duration |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 854 | mDecodedVideoTs = (mPlayEndTimeMsec*1000LL); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 855 | return; |
| 856 | } |
| 857 | |
| 858 | if (mVideoBuffer->range_length() == 0) { |
| 859 | // Some decoders, notably the PV AVC software decoder |
| 860 | // return spurious empty buffers that we just want to ignore. |
| 861 | |
| 862 | mVideoBuffer->release(); |
| 863 | mVideoBuffer = NULL; |
| 864 | continue; |
| 865 | } |
| 866 | |
| 867 | int64_t videoTimeUs; |
| 868 | CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &videoTimeUs)); |
| 869 | |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 870 | if (mSeeking != NO_SEEK) { |
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 871 | if (videoTimeUs < mSeekTimeUs) { |
| 872 | // buffers are before seek time |
| 873 | // ignore them |
| 874 | mVideoBuffer->release(); |
| 875 | mVideoBuffer = NULL; |
| 876 | continue; |
| 877 | } |
| 878 | } else { |
| 879 | if((videoTimeUs/1000) < mPlayBeginTimeMsec) { |
| 880 | // Frames are before begin cut time |
| 881 | // Donot render |
| 882 | mVideoBuffer->release(); |
| 883 | mVideoBuffer = NULL; |
| 884 | continue; |
| 885 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 886 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 887 | break; |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | mNumberDecVideoFrames++; |
| 892 | |
| 893 | int64_t timeUs; |
| 894 | CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &timeUs)); |
| 895 | |
| 896 | { |
| 897 | Mutex::Autolock autoLock(mMiscStateLock); |
| 898 | mVideoTimeUs = timeUs; |
| 899 | } |
| 900 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 901 | |
| 902 | if(!mStartNextPlayer) { |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 903 | int64_t playbackTimeRemaining = (mPlayEndTimeMsec*1000LL) - timeUs; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 904 | if(playbackTimeRemaining <= 1500000) { |
| 905 | //When less than 1.5 sec of playback left |
| 906 | // send notification to start next player |
| 907 | |
| 908 | mStartNextPlayer = true; |
| 909 | notifyListener_l(0xAAAAAAAA); |
| 910 | } |
| 911 | } |
| 912 | |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 913 | SeekType wasSeeking = mSeeking; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 914 | finishSeekIfNecessary(timeUs); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 915 | if (mAudioPlayer != NULL && !(mFlags & (AUDIO_RUNNING))) { |
| 916 | status_t err = startAudioPlayer_l(); |
| 917 | if (err != OK) { |
Steve Block | f8bd29c | 2012-01-08 10:14:44 +0000 | [diff] [blame] | 918 | ALOGE("Starting the audio player failed w/ err %d", err); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 919 | return; |
| 920 | } |
| 921 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 922 | |
| 923 | TimeSource *ts = (mFlags & AUDIO_AT_EOS) ? &mSystemTimeSource : mTimeSource; |
| 924 | |
| 925 | if(ts == NULL) { |
| 926 | mVideoBuffer->release(); |
| 927 | mVideoBuffer = NULL; |
| 928 | return; |
| 929 | } |
| 930 | |
| 931 | if(!mIsVideoSourceJpg) { |
| 932 | if (mFlags & FIRST_FRAME) { |
| 933 | mFlags &= ~FIRST_FRAME; |
| 934 | |
| 935 | mTimeSourceDeltaUs = ts->getRealTimeUs() - timeUs; |
| 936 | } |
| 937 | |
| 938 | int64_t realTimeUs, mediaTimeUs; |
| 939 | if (!(mFlags & AUDIO_AT_EOS) && mAudioPlayer != NULL |
| 940 | && mAudioPlayer->getMediaTimeMapping(&realTimeUs, &mediaTimeUs)) { |
| 941 | mTimeSourceDeltaUs = realTimeUs - mediaTimeUs; |
| 942 | } |
| 943 | |
| 944 | int64_t nowUs = ts->getRealTimeUs() - mTimeSourceDeltaUs; |
| 945 | |
| 946 | int64_t latenessUs = nowUs - timeUs; |
| 947 | |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 948 | if (wasSeeking != NO_SEEK) { |
Santosh Madhava | 342f932 | 2011-01-27 16:27:12 -0800 | [diff] [blame] | 949 | // Let's display the first frame after seeking right away. |
| 950 | latenessUs = 0; |
| 951 | } |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 952 | ALOGV("Audio time stamp = %lld and video time stamp = %lld", |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 953 | ts->getRealTimeUs(),timeUs); |
| 954 | if (latenessUs > 40000) { |
| 955 | // We're more than 40ms late. |
| 956 | |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 957 | ALOGV("LV PLAYER we're late by %lld us (%.2f secs)", |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 958 | latenessUs, latenessUs / 1E6); |
| 959 | |
| 960 | mVideoBuffer->release(); |
| 961 | mVideoBuffer = NULL; |
Dharmaray Kundargi | 4f155f0 | 2011-02-01 19:16:43 -0800 | [diff] [blame] | 962 | postVideoEvent_l(0); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 963 | return; |
| 964 | } |
| 965 | |
Dharmaray Kundargi | 4f155f0 | 2011-02-01 19:16:43 -0800 | [diff] [blame] | 966 | if (latenessUs < -25000) { |
| 967 | // We're more than 25ms early. |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 968 | ALOGV("We're more than 25ms early, lateness %lld", latenessUs); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 969 | |
Dharmaray Kundargi | 4f155f0 | 2011-02-01 19:16:43 -0800 | [diff] [blame] | 970 | postVideoEvent_l(25000); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 971 | return; |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | if (mVideoRendererIsPreview || mVideoRenderer == NULL) { |
| 976 | mVideoRendererIsPreview = false; |
| 977 | |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 978 | status_t err = initRenderer_l(); |
Santosh Madhava | 4ca3e5d | 2011-02-11 20:28:45 -0800 | [diff] [blame] | 979 | if (err != OK) { |
| 980 | postStreamDoneEvent_l(err); |
| 981 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | // If timestamp exceeds endCutTime of clip, donot render |
| 985 | if((timeUs/1000) > mPlayEndTimeMsec) { |
Chih-Chung Chang | cece4b3 | 2011-08-01 16:34:05 +0800 | [diff] [blame] | 986 | mVideoBuffer->release(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 987 | mVideoBuffer = NULL; |
| 988 | mFlags |= VIDEO_AT_EOS; |
| 989 | mFlags |= AUDIO_AT_EOS; |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 990 | ALOGV("PreviewPlayer: onVideoEvent timeUs > mPlayEndTime; send EOS.."); |
Dheeraj Sharma | 4f4efef | 2011-02-10 16:55:37 -0800 | [diff] [blame] | 991 | mOverlayUpdateEventPosted = false; |
Santosh Madhava | fe288aa | 2011-03-01 21:31:04 -0800 | [diff] [blame] | 992 | // Set the last decoded timestamp to duration |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 993 | mDecodedVideoTs = (mPlayEndTimeMsec*1000LL); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 994 | postStreamDoneEvent_l(ERROR_END_OF_STREAM); |
| 995 | return; |
| 996 | } |
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 997 | // Capture the frame timestamp to be rendered |
| 998 | mDecodedVideoTs = timeUs; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 999 | |
| 1000 | // Post processing to apply video effects |
| 1001 | for(i=0;i<mNumberEffects;i++) { |
| 1002 | // First check if effect starttime matches the clip being previewed |
| 1003 | if((mEffectsSettings[i].uiStartTime < (mDecVideoTsStoryBoard/1000)) || |
| 1004 | (mEffectsSettings[i].uiStartTime >= |
| 1005 | ((mDecVideoTsStoryBoard/1000) + mPlayEndTimeMsec - mPlayBeginTimeMsec))) |
| 1006 | { |
| 1007 | // This effect doesn't belong to this clip, check next one |
| 1008 | continue; |
| 1009 | } |
| 1010 | // Check if effect applies to this particular frame timestamp |
| 1011 | if((mEffectsSettings[i].uiStartTime <= |
| 1012 | (((timeUs+mDecVideoTsStoryBoard)/1000)-mPlayBeginTimeMsec)) && |
| 1013 | ((mEffectsSettings[i].uiStartTime+mEffectsSettings[i].uiDuration) >= |
| 1014 | (((timeUs+mDecVideoTsStoryBoard)/1000)-mPlayBeginTimeMsec)) |
| 1015 | && (mEffectsSettings[i].uiDuration != 0)) { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1016 | setVideoPostProcessingNode( |
| 1017 | mEffectsSettings[i].VideoEffectType, TRUE); |
| 1018 | } |
| 1019 | else { |
| 1020 | setVideoPostProcessingNode( |
| 1021 | mEffectsSettings[i].VideoEffectType, FALSE); |
| 1022 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1023 | } |
| 1024 | |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1025 | //Provide the overlay Update indication when there is an overlay effect |
Dharmaray Kundargi | d01ef56 | 2011-01-26 21:11:00 -0800 | [diff] [blame] | 1026 | if (mCurrentVideoEffect & VIDEO_EFFECT_FRAMING) { |
| 1027 | mCurrentVideoEffect &= ~VIDEO_EFFECT_FRAMING; //never apply framing here. |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1028 | if (!mOverlayUpdateEventPosted) { |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1029 | // Find the effect in effectSettings array |
Basavapatna Dattaguru | 408e25b | 2011-02-27 21:04:57 -0800 | [diff] [blame] | 1030 | M4OSA_UInt32 index; |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1031 | for (index = 0; index < mNumberEffects; index++) { |
| 1032 | M4OSA_UInt32 timeMs = mDecodedVideoTs/1000; |
| 1033 | M4OSA_UInt32 timeOffset = mDecVideoTsStoryBoard/1000; |
| 1034 | if(mEffectsSettings[index].VideoEffectType == |
Basavapatna Dattaguru | 408e25b | 2011-02-27 21:04:57 -0800 | [diff] [blame] | 1035 | (M4VSS3GPP_VideoEffectType)M4xVSS_kVideoEffectType_Framing) { |
Dharmaray Kundargi | 254c8df | 2011-01-28 19:28:31 -0800 | [diff] [blame] | 1036 | if (((mEffectsSettings[index].uiStartTime + 1) <= |
| 1037 | timeMs + timeOffset - mPlayBeginTimeMsec) && |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1038 | ((mEffectsSettings[index].uiStartTime - 1 + |
Dharmaray Kundargi | 254c8df | 2011-01-28 19:28:31 -0800 | [diff] [blame] | 1039 | mEffectsSettings[index].uiDuration) >= |
| 1040 | timeMs + timeOffset - mPlayBeginTimeMsec)) |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1041 | { |
| 1042 | break; |
| 1043 | } |
| 1044 | } |
| 1045 | } |
| 1046 | if (index < mNumberEffects) { |
| 1047 | mCurrFramingEffectIndex = index; |
| 1048 | mOverlayUpdateEventPosted = true; |
| 1049 | postOverlayUpdateEvent_l(); |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1050 | ALOGV("Framing index = %d", mCurrFramingEffectIndex); |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1051 | } else { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1052 | ALOGV("No framing effects found"); |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | } else if (mOverlayUpdateEventPosted) { |
| 1057 | //Post the event when the overlay is no more valid |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1058 | ALOGV("Overlay is Done"); |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1059 | mOverlayUpdateEventPosted = false; |
| 1060 | postOverlayUpdateEvent_l(); |
| 1061 | } |
| 1062 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1063 | if (mVideoRenderer != NULL) { |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 1064 | mVideoRenderer->render(mVideoBuffer, mCurrentVideoEffect, |
| 1065 | mRenderingMode, mIsVideoSourceJpg); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1066 | } |
| 1067 | |
Chih-Chung Chang | cece4b3 | 2011-08-01 16:34:05 +0800 | [diff] [blame] | 1068 | mVideoBuffer->release(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1069 | mVideoBuffer = NULL; |
| 1070 | |
| 1071 | // Post progress callback based on callback interval set |
| 1072 | if(mNumberDecVideoFrames >= mProgressCbInterval) { |
| 1073 | postProgressCallbackEvent_l(); |
| 1074 | mNumberDecVideoFrames = 0; // reset counter |
| 1075 | } |
| 1076 | |
| 1077 | // if reached EndCutTime of clip, post EOS event |
| 1078 | if((timeUs/1000) >= mPlayEndTimeMsec) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1079 | ALOGV("PreviewPlayer: onVideoEvent EOS."); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1080 | mFlags |= VIDEO_AT_EOS; |
| 1081 | mFlags |= AUDIO_AT_EOS; |
Dheeraj Sharma | 4f4efef | 2011-02-10 16:55:37 -0800 | [diff] [blame] | 1082 | mOverlayUpdateEventPosted = false; |
Santosh Madhava | fe288aa | 2011-03-01 21:31:04 -0800 | [diff] [blame] | 1083 | // Set the last decoded timestamp to duration |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 1084 | mDecodedVideoTs = (mPlayEndTimeMsec*1000LL); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1085 | postStreamDoneEvent_l(ERROR_END_OF_STREAM); |
| 1086 | } |
| 1087 | else { |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 1088 | if ((wasSeeking != NO_SEEK) && (mFlags & SEEK_PREVIEW)) { |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 1089 | mFlags &= ~SEEK_PREVIEW; |
| 1090 | return; |
| 1091 | } |
| 1092 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1093 | if(!mIsVideoSourceJpg) { |
Dharmaray Kundargi | 4f155f0 | 2011-02-01 19:16:43 -0800 | [diff] [blame] | 1094 | postVideoEvent_l(0); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1095 | } |
| 1096 | else { |
| 1097 | postVideoEvent_l(33000); |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | status_t PreviewPlayer::prepare() { |
| 1103 | Mutex::Autolock autoLock(mLock); |
| 1104 | return prepare_l(); |
| 1105 | } |
| 1106 | |
| 1107 | status_t PreviewPlayer::prepare_l() { |
| 1108 | if (mFlags & PREPARED) { |
| 1109 | return OK; |
| 1110 | } |
| 1111 | |
| 1112 | if (mFlags & PREPARING) { |
| 1113 | return UNKNOWN_ERROR; |
| 1114 | } |
| 1115 | |
| 1116 | mIsAsyncPrepare = false; |
| 1117 | status_t err = prepareAsync_l(); |
| 1118 | |
| 1119 | if (err != OK) { |
| 1120 | return err; |
| 1121 | } |
| 1122 | |
| 1123 | while (mFlags & PREPARING) { |
| 1124 | mPreparedCondition.wait(mLock); |
| 1125 | } |
| 1126 | |
| 1127 | return mPrepareResult; |
| 1128 | } |
| 1129 | |
| 1130 | status_t PreviewPlayer::prepareAsync_l() { |
| 1131 | if (mFlags & PREPARING) { |
| 1132 | return UNKNOWN_ERROR; // async prepare already pending |
| 1133 | } |
| 1134 | |
| 1135 | if (!mQueueStarted) { |
| 1136 | mQueue.start(); |
| 1137 | mQueueStarted = true; |
| 1138 | } |
| 1139 | |
| 1140 | mFlags |= PREPARING; |
| 1141 | mAsyncPrepareEvent = new PreviewPlayerEvent( |
| 1142 | this, &PreviewPlayer::onPrepareAsyncEvent); |
| 1143 | |
| 1144 | mQueue.postEvent(mAsyncPrepareEvent); |
| 1145 | |
| 1146 | return OK; |
| 1147 | } |
| 1148 | |
| 1149 | status_t PreviewPlayer::finishSetDataSource_l() { |
| 1150 | sp<DataSource> dataSource; |
| 1151 | sp<MediaExtractor> extractor; |
| 1152 | |
James Dong | daeb5b3 | 2012-01-12 12:12:40 -0800 | [diff] [blame^] | 1153 | dataSource = DataSource::CreateFromURI(mUri.string(), NULL); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1154 | |
| 1155 | if (dataSource == NULL) { |
| 1156 | return UNKNOWN_ERROR; |
| 1157 | } |
| 1158 | |
| 1159 | //If file type is .rgb, then no need to check for Extractor |
| 1160 | int uriLen = strlen(mUri); |
| 1161 | int startOffset = uriLen - 4; |
| 1162 | if(!strncasecmp(mUri+startOffset, ".rgb", 4)) { |
| 1163 | extractor = NULL; |
| 1164 | } |
| 1165 | else { |
| 1166 | extractor = MediaExtractor::Create(dataSource, |
| 1167 | MEDIA_MIMETYPE_CONTAINER_MPEG4); |
| 1168 | } |
| 1169 | |
| 1170 | if (extractor == NULL) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1171 | ALOGV("PreviewPlayer::finishSetDataSource_l extractor == NULL"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1172 | return setDataSource_l_jpg(); |
| 1173 | } |
| 1174 | |
| 1175 | return setDataSource_l(extractor); |
| 1176 | } |
| 1177 | |
| 1178 | |
| 1179 | // static |
| 1180 | bool PreviewPlayer::ContinuePreparation(void *cookie) { |
| 1181 | PreviewPlayer *me = static_cast<PreviewPlayer *>(cookie); |
| 1182 | |
| 1183 | return (me->mFlags & PREPARE_CANCELLED) == 0; |
| 1184 | } |
| 1185 | |
| 1186 | void PreviewPlayer::onPrepareAsyncEvent() { |
| 1187 | Mutex::Autolock autoLock(mLock); |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1188 | ALOGV("onPrepareAsyncEvent"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1189 | |
| 1190 | if (mFlags & PREPARE_CANCELLED) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1191 | ALOGV("LV PLAYER prepare was cancelled before doing anything"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1192 | abortPrepare(UNKNOWN_ERROR); |
| 1193 | return; |
| 1194 | } |
| 1195 | |
| 1196 | if (mUri.size() > 0) { |
| 1197 | status_t err = finishSetDataSource_l(); |
| 1198 | |
| 1199 | if (err != OK) { |
| 1200 | abortPrepare(err); |
| 1201 | return; |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | if (mVideoTrack != NULL && mVideoSource == NULL) { |
| 1206 | status_t err = initVideoDecoder(OMXCodec::kHardwareCodecsOnly); |
| 1207 | |
| 1208 | if (err != OK) { |
| 1209 | abortPrepare(err); |
| 1210 | return; |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | if (mAudioTrack != NULL && mAudioSource == NULL) { |
| 1215 | status_t err = initAudioDecoder(); |
| 1216 | |
| 1217 | if (err != OK) { |
| 1218 | abortPrepare(err); |
| 1219 | return; |
| 1220 | } |
| 1221 | } |
| 1222 | finishAsyncPrepare_l(); |
| 1223 | |
| 1224 | } |
| 1225 | |
| 1226 | void PreviewPlayer::finishAsyncPrepare_l() { |
| 1227 | if (mIsAsyncPrepare) { |
| 1228 | if (mVideoSource == NULL) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1229 | ALOGV("finishAsyncPrepare_l: MEDIA_SET_VIDEO_SIZE 0 0 "); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1230 | notifyListener_l(MEDIA_SET_VIDEO_SIZE, 0, 0); |
| 1231 | } else { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1232 | ALOGV("finishAsyncPrepare_l: MEDIA_SET_VIDEO_SIZE"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1233 | notifyVideoSize_l(); |
| 1234 | } |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1235 | ALOGV("finishAsyncPrepare_l: MEDIA_PREPARED"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1236 | notifyListener_l(MEDIA_PREPARED); |
| 1237 | } |
| 1238 | |
| 1239 | mPrepareResult = OK; |
| 1240 | mFlags &= ~(PREPARING|PREPARE_CANCELLED); |
| 1241 | mFlags |= PREPARED; |
| 1242 | mAsyncPrepareEvent = NULL; |
| 1243 | mPreparedCondition.broadcast(); |
| 1244 | } |
| 1245 | |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 1246 | void PreviewPlayer::acquireLock() { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1247 | ALOGV("acquireLock"); |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 1248 | mLockControl.lock(); |
| 1249 | } |
| 1250 | |
| 1251 | void PreviewPlayer::releaseLock() { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1252 | ALOGV("releaseLock"); |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 1253 | mLockControl.unlock(); |
| 1254 | } |
| 1255 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1256 | status_t PreviewPlayer::loadEffectsSettings( |
| 1257 | M4VSS3GPP_EffectSettings* pEffectSettings, int nEffects) { |
| 1258 | M4OSA_UInt32 i = 0, rgbSize = 0; |
| 1259 | M4VIFI_UInt8 *tmp = M4OSA_NULL; |
| 1260 | |
| 1261 | mNumberEffects = nEffects; |
| 1262 | mEffectsSettings = pEffectSettings; |
| 1263 | return OK; |
| 1264 | } |
| 1265 | |
| 1266 | status_t PreviewPlayer::loadAudioMixSettings( |
| 1267 | M4xVSS_AudioMixingSettings* pAudioMixSettings) { |
| 1268 | |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1269 | ALOGV("PreviewPlayer: loadAudioMixSettings: "); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1270 | mPreviewPlayerAudioMixSettings = pAudioMixSettings; |
| 1271 | return OK; |
| 1272 | } |
| 1273 | |
| 1274 | status_t PreviewPlayer::setAudioMixPCMFileHandle( |
| 1275 | M4OSA_Context pAudioMixPCMFileHandle) { |
| 1276 | |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1277 | ALOGV("PreviewPlayer: setAudioMixPCMFileHandle: "); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1278 | mAudioMixPCMFileHandle = pAudioMixPCMFileHandle; |
| 1279 | return OK; |
| 1280 | } |
| 1281 | |
| 1282 | status_t PreviewPlayer::setAudioMixStoryBoardParam( |
| 1283 | M4OSA_UInt32 audioMixStoryBoardTS, |
| 1284 | M4OSA_UInt32 currentMediaBeginCutTime, |
| 1285 | M4OSA_UInt32 primaryTrackVolValue ) { |
| 1286 | |
| 1287 | mAudioMixStoryBoardTS = audioMixStoryBoardTS; |
| 1288 | mCurrentMediaBeginCutTime = currentMediaBeginCutTime; |
| 1289 | mCurrentMediaVolumeValue = primaryTrackVolValue; |
| 1290 | return OK; |
| 1291 | } |
| 1292 | |
| 1293 | status_t PreviewPlayer::setPlaybackBeginTime(uint32_t msec) { |
| 1294 | |
| 1295 | mPlayBeginTimeMsec = msec; |
| 1296 | return OK; |
| 1297 | } |
| 1298 | |
| 1299 | status_t PreviewPlayer::setPlaybackEndTime(uint32_t msec) { |
| 1300 | |
| 1301 | mPlayEndTimeMsec = msec; |
| 1302 | return OK; |
| 1303 | } |
| 1304 | |
| 1305 | status_t PreviewPlayer::setStoryboardStartTime(uint32_t msec) { |
| 1306 | |
| 1307 | mStoryboardStartTimeMsec = msec; |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 1308 | mDecVideoTsStoryBoard = mStoryboardStartTimeMsec*1000LL; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1309 | return OK; |
| 1310 | } |
| 1311 | |
| 1312 | status_t PreviewPlayer::setProgressCallbackInterval(uint32_t cbInterval) { |
| 1313 | |
| 1314 | mProgressCbInterval = cbInterval; |
| 1315 | return OK; |
| 1316 | } |
| 1317 | |
| 1318 | |
| 1319 | status_t PreviewPlayer::setMediaRenderingMode( |
| 1320 | M4xVSS_MediaRendering mode, |
| 1321 | M4VIDEOEDITING_VideoFrameSize outputVideoSize) { |
| 1322 | |
| 1323 | mRenderingMode = mode; |
| 1324 | |
Hong Teng | 8806b70 | 2011-07-06 18:29:28 -0700 | [diff] [blame] | 1325 | status_t err = OK; |
| 1326 | /* get the video width and height by resolution */ |
| 1327 | err = getVideoSizeByResolution(outputVideoSize, |
| 1328 | &mOutputVideoWidth, &mOutputVideoHeight); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1329 | |
Hong Teng | 8806b70 | 2011-07-06 18:29:28 -0700 | [diff] [blame] | 1330 | return err; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1331 | } |
| 1332 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1333 | status_t PreviewPlayer::resetJniCallbackTimeStamp() { |
| 1334 | |
Raghavender Palla | ebf4015 | 2011-03-14 20:15:12 -0700 | [diff] [blame] | 1335 | mDecVideoTsStoryBoard = mStoryboardStartTimeMsec*1000LL; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1336 | return OK; |
| 1337 | } |
| 1338 | |
| 1339 | void PreviewPlayer::postProgressCallbackEvent_l() { |
| 1340 | if (mProgressCbEventPending) { |
| 1341 | return; |
| 1342 | } |
| 1343 | mProgressCbEventPending = true; |
| 1344 | |
| 1345 | mQueue.postEvent(mProgressCbEvent); |
| 1346 | } |
| 1347 | |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1348 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1349 | void PreviewPlayer::onProgressCbEvent() { |
| 1350 | Mutex::Autolock autoLock(mLock); |
| 1351 | if (!mProgressCbEventPending) { |
| 1352 | return; |
| 1353 | } |
| 1354 | mProgressCbEventPending = false; |
| 1355 | // If playback starts from previous I-frame, |
| 1356 | // then send frame storyboard duration |
| 1357 | if((mDecodedVideoTs/1000) < mPlayBeginTimeMsec) { |
| 1358 | notifyListener_l(MEDIA_INFO, 0, mDecVideoTsStoryBoard/1000); |
| 1359 | } |
| 1360 | else { |
| 1361 | notifyListener_l(MEDIA_INFO, 0, |
| 1362 | (((mDecodedVideoTs+mDecVideoTsStoryBoard)/1000)-mPlayBeginTimeMsec)); |
| 1363 | } |
| 1364 | } |
| 1365 | |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 1366 | void PreviewPlayer::postOverlayUpdateEvent_l() { |
| 1367 | if (mOverlayUpdateEventPending) { |
| 1368 | return; |
| 1369 | } |
| 1370 | mOverlayUpdateEventPending = true; |
| 1371 | mQueue.postEvent(mOverlayUpdateEvent); |
| 1372 | } |
| 1373 | |
| 1374 | void PreviewPlayer::onUpdateOverlayEvent() { |
| 1375 | Mutex::Autolock autoLock(mLock); |
| 1376 | |
| 1377 | if (!mOverlayUpdateEventPending) { |
| 1378 | return; |
| 1379 | } |
| 1380 | mOverlayUpdateEventPending = false; |
| 1381 | |
| 1382 | int updateState; |
| 1383 | if (mOverlayUpdateEventPosted) { |
| 1384 | updateState = 1; |
| 1385 | } else { |
| 1386 | updateState = 0; |
| 1387 | } |
| 1388 | notifyListener_l(0xBBBBBBBB, updateState, mCurrFramingEffectIndex); |
| 1389 | } |
| 1390 | |
| 1391 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1392 | void PreviewPlayer::setVideoPostProcessingNode( |
| 1393 | M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable) { |
| 1394 | |
| 1395 | uint32_t effect = VIDEO_EFFECT_NONE; |
| 1396 | |
| 1397 | //Map M4VSS3GPP_VideoEffectType to local enum |
| 1398 | switch(type) { |
| 1399 | case M4VSS3GPP_kVideoEffectType_FadeFromBlack: |
| 1400 | effect = VIDEO_EFFECT_FADEFROMBLACK; |
| 1401 | break; |
| 1402 | |
| 1403 | case M4VSS3GPP_kVideoEffectType_FadeToBlack: |
| 1404 | effect = VIDEO_EFFECT_FADETOBLACK; |
| 1405 | break; |
| 1406 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1407 | case M4xVSS_kVideoEffectType_BlackAndWhite: |
| 1408 | effect = VIDEO_EFFECT_BLACKANDWHITE; |
| 1409 | break; |
| 1410 | |
| 1411 | case M4xVSS_kVideoEffectType_Pink: |
| 1412 | effect = VIDEO_EFFECT_PINK; |
| 1413 | break; |
| 1414 | |
| 1415 | case M4xVSS_kVideoEffectType_Green: |
| 1416 | effect = VIDEO_EFFECT_GREEN; |
| 1417 | break; |
| 1418 | |
| 1419 | case M4xVSS_kVideoEffectType_Sepia: |
| 1420 | effect = VIDEO_EFFECT_SEPIA; |
| 1421 | break; |
| 1422 | |
| 1423 | case M4xVSS_kVideoEffectType_Negative: |
| 1424 | effect = VIDEO_EFFECT_NEGATIVE; |
| 1425 | break; |
| 1426 | |
| 1427 | case M4xVSS_kVideoEffectType_Framing: |
| 1428 | effect = VIDEO_EFFECT_FRAMING; |
| 1429 | break; |
| 1430 | |
| 1431 | case M4xVSS_kVideoEffectType_Fifties: |
| 1432 | effect = VIDEO_EFFECT_FIFTIES; |
| 1433 | break; |
| 1434 | |
| 1435 | case M4xVSS_kVideoEffectType_ColorRGB16: |
| 1436 | effect = VIDEO_EFFECT_COLOR_RGB16; |
| 1437 | break; |
| 1438 | |
| 1439 | case M4xVSS_kVideoEffectType_Gradient: |
| 1440 | effect = VIDEO_EFFECT_GRADIENT; |
| 1441 | break; |
| 1442 | |
| 1443 | default: |
| 1444 | effect = VIDEO_EFFECT_NONE; |
| 1445 | break; |
| 1446 | } |
| 1447 | |
| 1448 | if(enable == M4OSA_TRUE) { |
| 1449 | //If already set, then no need to set again |
| 1450 | if(!(mCurrentVideoEffect & effect)) { |
| 1451 | mCurrentVideoEffect |= effect; |
| 1452 | if(effect == VIDEO_EFFECT_FIFTIES) { |
| 1453 | mIsFiftiesEffectStarted = true; |
| 1454 | } |
| 1455 | } |
| 1456 | } |
| 1457 | else { |
| 1458 | //Reset only if already set |
| 1459 | if(mCurrentVideoEffect & effect) { |
| 1460 | mCurrentVideoEffect &= ~effect; |
| 1461 | } |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | status_t PreviewPlayer::setImageClipProperties(uint32_t width,uint32_t height) { |
| 1466 | mVideoWidth = width; |
| 1467 | mVideoHeight = height; |
| 1468 | return OK; |
| 1469 | } |
| 1470 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1471 | status_t PreviewPlayer::readFirstVideoFrame() { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1472 | ALOGV("PreviewPlayer::readFirstVideoFrame"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1473 | |
| 1474 | if (!mVideoBuffer) { |
| 1475 | MediaSource::ReadOptions options; |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 1476 | if (mSeeking != NO_SEEK) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1477 | ALOGV("LV PLAYER seeking to %lld us (%.2f secs)", mSeekTimeUs, |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1478 | mSeekTimeUs / 1E6); |
| 1479 | |
| 1480 | options.setSeekTo( |
| 1481 | mSeekTimeUs, MediaSource::ReadOptions::SEEK_CLOSEST); |
| 1482 | } |
| 1483 | for (;;) { |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 1484 | status_t err = mVideoSource->read(&mVideoBuffer, &options); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1485 | options.clearSeekTo(); |
| 1486 | |
| 1487 | if (err != OK) { |
| 1488 | CHECK_EQ(mVideoBuffer, NULL); |
| 1489 | |
| 1490 | if (err == INFO_FORMAT_CHANGED) { |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1491 | ALOGV("LV PLAYER VideoSource signalled format change"); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1492 | notifyVideoSize_l(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1493 | |
| 1494 | if (mVideoRenderer != NULL) { |
| 1495 | mVideoRendererIsPreview = false; |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 1496 | err = initRenderer_l(); |
Santosh Madhava | 4ca3e5d | 2011-02-11 20:28:45 -0800 | [diff] [blame] | 1497 | if (err != OK) { |
| 1498 | postStreamDoneEvent_l(err); |
| 1499 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1500 | } |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 1501 | |
| 1502 | updateSizeToRender(mVideoSource->getFormat()); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1503 | continue; |
| 1504 | } |
Steve Block | 2703f23 | 2011-10-20 11:56:09 +0100 | [diff] [blame] | 1505 | ALOGV("PreviewPlayer: onVideoEvent EOS reached."); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1506 | mFlags |= VIDEO_AT_EOS; |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 1507 | mFlags |= AUDIO_AT_EOS; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1508 | postStreamDoneEvent_l(err); |
| 1509 | return OK; |
| 1510 | } |
| 1511 | |
| 1512 | if (mVideoBuffer->range_length() == 0) { |
| 1513 | // Some decoders, notably the PV AVC software decoder |
| 1514 | // return spurious empty buffers that we just want to ignore. |
| 1515 | |
| 1516 | mVideoBuffer->release(); |
| 1517 | mVideoBuffer = NULL; |
| 1518 | continue; |
| 1519 | } |
| 1520 | |
| 1521 | int64_t videoTimeUs; |
| 1522 | CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &videoTimeUs)); |
Andreas Huber | a5872f7 | 2011-02-24 15:25:21 -0800 | [diff] [blame] | 1523 | if (mSeeking != NO_SEEK) { |
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 1524 | if (videoTimeUs < mSeekTimeUs) { |
| 1525 | // buffers are before seek time |
| 1526 | // ignore them |
| 1527 | mVideoBuffer->release(); |
| 1528 | mVideoBuffer = NULL; |
| 1529 | continue; |
| 1530 | } |
| 1531 | } else { |
| 1532 | if((videoTimeUs/1000) < mPlayBeginTimeMsec) { |
| 1533 | // buffers are before begin cut time |
| 1534 | // ignore them |
| 1535 | mVideoBuffer->release(); |
| 1536 | mVideoBuffer = NULL; |
| 1537 | continue; |
| 1538 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1539 | } |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1540 | break; |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | int64_t timeUs; |
| 1545 | CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &timeUs)); |
| 1546 | |
| 1547 | { |
| 1548 | Mutex::Autolock autoLock(mMiscStateLock); |
| 1549 | mVideoTimeUs = timeUs; |
| 1550 | } |
| 1551 | |
| 1552 | mDecodedVideoTs = timeUs; |
| 1553 | |
| 1554 | return OK; |
| 1555 | |
| 1556 | } |
| 1557 | |
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 1558 | status_t PreviewPlayer::getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs) { |
| 1559 | *lastRenderedTimeMs = (((mDecodedVideoTs+mDecVideoTsStoryBoard)/1000)-mPlayBeginTimeMsec); |
| 1560 | return OK; |
| 1561 | } |
| 1562 | |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 1563 | void PreviewPlayer::updateSizeToRender(sp<MetaData> meta) { |
| 1564 | if (mVideoRenderer) { |
| 1565 | mVideoRenderer->updateVideoSize(meta); |
| 1566 | } |
| 1567 | } |
| 1568 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1569 | } // namespace android |