Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 1 | /*
|
| 2 | * Copyright (C) 2011 NXP Software
|
| 3 | * Copyright (C) 2011 The Android Open Source Project
|
| 4 | *
|
| 5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 | * you may not use this file except in compliance with the License.
|
| 7 | * You may obtain a copy of the License at
|
| 8 | *
|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 10 | *
|
| 11 | * Unless required by applicable law or agreed to in writing, software
|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 | * See the License for the specific language governing permissions and
|
| 15 | * limitations under the License.
|
| 16 | */
|
| 17 |
|
| 18 | #define LOG_NDEBUG 1
|
| 19 | #define LOG_TAG "VideoEditorPreviewController"
|
| 20 | #include "VideoEditorPreviewController.h"
|
| 21 |
|
| 22 | namespace android {
|
| 23 |
|
| 24 | #define PREVIEW_THREAD_STACK_SIZE (65536)
|
| 25 |
|
| 26 | VideoEditorPreviewController::VideoEditorPreviewController()
|
| 27 | : mCurrentPlayer(0),
|
| 28 | mThreadContext(NULL),
|
| 29 | mPlayerState(VePlayerIdle),
|
| 30 | mClipList(NULL),
|
| 31 | mNumberClipsInStoryBoard(0),
|
| 32 | mNumberClipsToPreview(0),
|
| 33 | mStartingClipIndex(0),
|
| 34 | mPreviewLooping(M4OSA_FALSE),
|
| 35 | mCallBackAfterFrameCnt(0),
|
| 36 | mEffectsSettings(NULL),
|
| 37 | mNumberEffects(0),
|
| 38 | mCurrentClipNumber(-1),
|
| 39 | mClipTotalDuration(0),
|
| 40 | mCurrentVideoEffect(VIDEO_EFFECT_NONE),
|
| 41 | mTarget(NULL),
|
| 42 | mJniCookie(NULL),
|
| 43 | mJniCallback(NULL),
|
| 44 | mBackgroundAudioSetting(NULL),
|
| 45 | mAudioMixPCMFileHandle(NULL),
|
| 46 | mVideoStoryBoardTimeMsUptoFirstPreviewClip(0),
|
| 47 | mCurrentPlayedDuration(0),
|
| 48 | mCurrentClipDuration(0),
|
| 49 | mOutputVideoWidth(0),
|
| 50 | mOutputVideoHeight(0),
|
| 51 | bStopThreadInProgress(false),
|
| 52 | mSemThreadWait(NULL) {
|
| 53 | LOGV("VideoEditorPreviewController");
|
| 54 | mRenderingMode = M4xVSS_kBlackBorders;
|
| 55 | mIsFiftiesEffectStarted = false;
|
| 56 |
|
| 57 | for (int i=0; i<NBPLAYER_INSTANCES; i++) {
|
| 58 | mVePlayer[i] = NULL;
|
| 59 | }
|
| 60 | }
|
| 61 |
|
| 62 | VideoEditorPreviewController::~VideoEditorPreviewController() {
|
| 63 | M4OSA_UInt32 i = 0;
|
| 64 | M4OSA_ERR err = M4NO_ERROR;
|
| 65 | LOGV("~VideoEditorPreviewController");
|
| 66 |
|
| 67 | // Stop the thread if its still running
|
| 68 | if(mThreadContext != NULL) {
|
| 69 | err = M4OSA_threadSyncStop(mThreadContext);
|
| 70 | if(err != M4NO_ERROR) {
|
| 71 | LOGV("~VideoEditorPreviewController: error 0x%x \
|
| 72 | in trying to stop thread", err);
|
| 73 | // Continue even if error
|
| 74 | }
|
| 75 |
|
| 76 | err = M4OSA_threadSyncClose(mThreadContext);
|
| 77 | if(err != M4NO_ERROR) {
|
| 78 | LOGE("~VideoEditorPreviewController: error 0x%x \
|
| 79 | in trying to close thread", err);
|
| 80 | // Continue even if error
|
| 81 | }
|
| 82 |
|
| 83 | mThreadContext = NULL;
|
| 84 | }
|
| 85 |
|
| 86 | for (int playerInst=0; playerInst<NBPLAYER_INSTANCES;
|
| 87 | playerInst++) {
|
| 88 | if(mVePlayer[playerInst] != NULL) {
|
| 89 | LOGV("clearing mVePlayer %d", playerInst);
|
| 90 | mVePlayer[playerInst].clear();
|
| 91 | }
|
| 92 | }
|
| 93 |
|
| 94 | if(mClipList != NULL) {
|
| 95 | // Clean up
|
| 96 | for(i=0;i<mNumberClipsInStoryBoard;i++)
|
| 97 | {
|
| 98 | if(mClipList[i]->pFile != NULL) {
|
| 99 | M4OSA_free((M4OSA_MemAddr32)mClipList[i]->pFile);
|
| 100 | mClipList[i]->pFile = NULL;
|
| 101 | }
|
| 102 |
|
| 103 | M4OSA_free((M4OSA_MemAddr32)mClipList[i]);
|
| 104 | }
|
| 105 | M4OSA_free((M4OSA_MemAddr32)mClipList);
|
| 106 | mClipList = NULL;
|
| 107 | }
|
| 108 |
|
| 109 | if(mEffectsSettings) {
|
| 110 | for(i=0;i<mNumberEffects;i++) {
|
| 111 | if(mEffectsSettings[i].xVSS.pFramingBuffer != NULL) {
|
| 112 | M4OSA_free(
|
| 113 | (M4OSA_MemAddr32)mEffectsSettings[i].xVSS.pFramingBuffer->pac_data);
|
| 114 |
|
| 115 | M4OSA_free(
|
| 116 | (M4OSA_MemAddr32)mEffectsSettings[i].xVSS.pFramingBuffer);
|
| 117 |
|
| 118 | mEffectsSettings[i].xVSS.pFramingBuffer = NULL;
|
| 119 | }
|
| 120 | }
|
| 121 | M4OSA_free((M4OSA_MemAddr32)mEffectsSettings);
|
| 122 | mEffectsSettings = NULL;
|
| 123 | }
|
| 124 |
|
| 125 | if(mTarget != NULL) {
|
| 126 | delete mTarget;
|
| 127 | mTarget = NULL;
|
| 128 | }
|
| 129 |
|
| 130 | LOGV("~VideoEditorPreviewController returns");
|
| 131 | }
|
| 132 |
|
| 133 | M4OSA_ERR VideoEditorPreviewController::loadEditSettings(
|
| 134 | M4VSS3GPP_EditSettings* pSettings,M4xVSS_AudioMixingSettings* bgmSettings) {
|
| 135 |
|
| 136 | M4OSA_UInt32 i = 0, iClipDuration = 0, rgbSize = 0;
|
| 137 | M4VIFI_UInt8 *tmp = NULL;
|
| 138 | M4OSA_ERR err = M4NO_ERROR;
|
| 139 |
|
| 140 | LOGV("loadEditSettings");
|
| 141 | LOGV("loadEditSettings Channels = %d, sampling Freq %d",
|
| 142 | bgmSettings->uiNbChannels, bgmSettings->uiSamplingFrequency );
|
| 143 | bgmSettings->uiSamplingFrequency = 32000;
|
| 144 |
|
| 145 | LOGV("loadEditSettings Channels = %d, sampling Freq %d",
|
| 146 | bgmSettings->uiNbChannels, bgmSettings->uiSamplingFrequency );
|
| 147 | Mutex::Autolock autoLock(mLock);
|
| 148 |
|
| 149 | // Clean up any previous Edit settings before loading new ones
|
| 150 | mCurrentVideoEffect = VIDEO_EFFECT_NONE;
|
| 151 |
|
| 152 | if(mAudioMixPCMFileHandle) {
|
| 153 | err = M4OSA_fileReadClose (mAudioMixPCMFileHandle);
|
| 154 | mAudioMixPCMFileHandle = M4OSA_NULL;
|
| 155 | }
|
| 156 |
|
| 157 | if(mBackgroundAudioSetting != NULL) {
|
| 158 | M4OSA_free((M4OSA_MemAddr32)mBackgroundAudioSetting);
|
| 159 | mBackgroundAudioSetting = NULL;
|
| 160 | }
|
| 161 |
|
| 162 | if(mClipList != NULL) {
|
| 163 | // Clean up
|
| 164 | for(i=0;i<mNumberClipsInStoryBoard;i++)
|
| 165 | {
|
| 166 | if(mClipList[i]->pFile != NULL) {
|
| 167 | M4OSA_free((M4OSA_MemAddr32)mClipList[i]->pFile);
|
| 168 | mClipList[i]->pFile = NULL;
|
| 169 | }
|
| 170 |
|
| 171 | M4OSA_free((M4OSA_MemAddr32)mClipList[i]);
|
| 172 | }
|
| 173 | M4OSA_free((M4OSA_MemAddr32)mClipList);
|
| 174 | mClipList = NULL;
|
| 175 | }
|
| 176 |
|
| 177 | if(mEffectsSettings) {
|
| 178 | for(i=0;i<mNumberEffects;i++) {
|
| 179 | if(mEffectsSettings[i].xVSS.pFramingBuffer != NULL) {
|
| 180 | M4OSA_free(
|
| 181 | (M4OSA_MemAddr32)mEffectsSettings[i].xVSS.pFramingBuffer->pac_data);
|
| 182 |
|
| 183 | M4OSA_free(
|
| 184 | (M4OSA_MemAddr32)mEffectsSettings[i].xVSS.pFramingBuffer);
|
| 185 |
|
| 186 | mEffectsSettings[i].xVSS.pFramingBuffer = NULL;
|
| 187 | }
|
| 188 | }
|
| 189 | M4OSA_free((M4OSA_MemAddr32)mEffectsSettings);
|
| 190 | mEffectsSettings = NULL;
|
| 191 | }
|
| 192 |
|
| 193 | if(mClipList == NULL) {
|
| 194 | mNumberClipsInStoryBoard = pSettings->uiClipNumber;
|
| 195 | LOGV("loadEditSettings: # of Clips = %d", mNumberClipsInStoryBoard);
|
| 196 |
|
| 197 | mClipList = (M4VSS3GPP_ClipSettings**)M4OSA_malloc(
|
| 198 | sizeof(M4VSS3GPP_ClipSettings*)*pSettings->uiClipNumber, M4VS,
|
| 199 | (M4OSA_Char*)"LvPP, copy of pClipList");
|
| 200 |
|
| 201 | if(NULL == mClipList) {
|
| 202 | LOGE("loadEditSettings: Malloc error");
|
| 203 | return M4ERR_ALLOC;
|
| 204 | }
|
| 205 | M4OSA_memset((M4OSA_MemAddr8)mClipList,
|
| 206 | sizeof(M4VSS3GPP_ClipSettings*)*pSettings->uiClipNumber, 0);
|
| 207 |
|
| 208 | for(i=0;i<pSettings->uiClipNumber;i++) {
|
| 209 |
|
| 210 | // Allocate current clip
|
| 211 | mClipList[i] =
|
| 212 | (M4VSS3GPP_ClipSettings*)M4OSA_malloc(
|
| 213 | sizeof(M4VSS3GPP_ClipSettings),M4VS,(M4OSA_Char*)"clip settings");
|
| 214 |
|
| 215 | if(mClipList[i] == NULL) {
|
| 216 |
|
| 217 | LOGE("loadEditSettings: Allocation error for mClipList[%d]", i);
|
| 218 | return M4ERR_ALLOC;
|
| 219 | }
|
| 220 | // Copy plain structure
|
| 221 | M4OSA_memcpy((M4OSA_MemAddr8)mClipList[i],
|
| 222 | (M4OSA_MemAddr8)pSettings->pClipList[i],
|
| 223 | sizeof(M4VSS3GPP_ClipSettings));
|
| 224 |
|
| 225 | if(NULL != pSettings->pClipList[i]->pFile) {
|
| 226 | mClipList[i]->pFile = (M4OSA_Char*)M4OSA_malloc(
|
| 227 | pSettings->pClipList[i]->filePathSize, M4VS,
|
| 228 | (M4OSA_Char*)"pClipSettingsDest->pFile");
|
| 229 |
|
| 230 | if(NULL == mClipList[i]->pFile)
|
| 231 | {
|
| 232 | LOGE("loadEditSettings : ERROR allocating filename");
|
| 233 | return M4ERR_ALLOC;
|
| 234 | }
|
| 235 |
|
| 236 | M4OSA_memcpy((M4OSA_MemAddr8)mClipList[i]->pFile,
|
| 237 | (M4OSA_MemAddr8)pSettings->pClipList[i]->pFile,
|
| 238 | pSettings->pClipList[i]->filePathSize);
|
| 239 | }
|
| 240 | else {
|
| 241 | LOGE("NULL file path");
|
| 242 | return M4ERR_PARAMETER;
|
| 243 | }
|
| 244 |
|
| 245 | // Calculate total duration of all clips
|
| 246 | iClipDuration = pSettings->pClipList[i]->uiEndCutTime -
|
| 247 | pSettings->pClipList[i]->uiBeginCutTime;
|
| 248 |
|
| 249 | mClipTotalDuration = mClipTotalDuration+iClipDuration;
|
| 250 | }
|
| 251 | }
|
| 252 |
|
| 253 | if(mEffectsSettings == NULL) {
|
| 254 | mNumberEffects = pSettings->nbEffects;
|
| 255 | LOGV("loadEditSettings: mNumberEffects = %d", mNumberEffects);
|
| 256 |
|
| 257 | if(mNumberEffects != 0) {
|
| 258 | mEffectsSettings = (M4VSS3GPP_EffectSettings*)M4OSA_malloc(
|
| 259 | mNumberEffects*sizeof(M4VSS3GPP_EffectSettings),
|
| 260 | M4VS, (M4OSA_Char*)"effects settings");
|
| 261 |
|
| 262 | if(mEffectsSettings == NULL) {
|
| 263 | LOGE("loadEffectsSettings: Allocation error");
|
| 264 | return M4ERR_ALLOC;
|
| 265 | }
|
| 266 |
|
| 267 | M4OSA_memset((M4OSA_MemAddr8)mEffectsSettings,
|
| 268 | mNumberEffects*sizeof(M4VSS3GPP_EffectSettings), 0);
|
| 269 |
|
| 270 | for(i=0;i<mNumberEffects;i++) {
|
| 271 |
|
| 272 | mEffectsSettings[i].xVSS.pFramingFilePath = NULL;
|
| 273 | mEffectsSettings[i].xVSS.pFramingBuffer = NULL;
|
| 274 | mEffectsSettings[i].xVSS.pTextBuffer = NULL;
|
| 275 |
|
| 276 | M4OSA_memcpy((M4OSA_MemAddr8)&(mEffectsSettings[i]),
|
| 277 | (M4OSA_MemAddr8)&(pSettings->Effects[i]),
|
| 278 | sizeof(M4VSS3GPP_EffectSettings));
|
| 279 |
|
| 280 | if(pSettings->Effects[i].VideoEffectType ==
|
| 281 | M4xVSS_kVideoEffectType_Framing) {
|
| 282 | // Allocate the pFraming RGB buffer
|
| 283 | mEffectsSettings[i].xVSS.pFramingBuffer =
|
| 284 | (M4VIFI_ImagePlane *)M4OSA_malloc(sizeof(M4VIFI_ImagePlane),
|
| 285 | M4VS, (M4OSA_Char*)"lvpp framing buffer");
|
| 286 |
|
| 287 | if(mEffectsSettings[i].xVSS.pFramingBuffer == NULL) {
|
| 288 | LOGE("loadEffectsSettings:Alloc error for pFramingBuf");
|
| 289 | M4OSA_free((M4OSA_MemAddr32)mEffectsSettings);
|
| 290 | mEffectsSettings = NULL;
|
| 291 | return M4ERR_ALLOC;
|
| 292 | }
|
| 293 |
|
| 294 | // Allocate the pac_data (RGB)
|
| 295 | if(pSettings->Effects[i].xVSS.rgbType == M4VSS3GPP_kRGB565){
|
| 296 | rgbSize =
|
| 297 | pSettings->Effects[i].xVSS.pFramingBuffer->u_width *
|
| 298 | pSettings->Effects[i].xVSS.pFramingBuffer->u_height*2;
|
| 299 | }
|
| 300 | else if(
|
| 301 | pSettings->Effects[i].xVSS.rgbType == M4VSS3GPP_kRGB888) {
|
| 302 | rgbSize =
|
| 303 | pSettings->Effects[i].xVSS.pFramingBuffer->u_width *
|
| 304 | pSettings->Effects[i].xVSS.pFramingBuffer->u_height*3;
|
| 305 | }
|
| 306 | else {
|
| 307 | LOGE("loadEffectsSettings: wrong RGB type");
|
| 308 | M4OSA_free((M4OSA_MemAddr32)mEffectsSettings);
|
| 309 | mEffectsSettings = NULL;
|
| 310 | return M4ERR_PARAMETER;
|
| 311 | }
|
| 312 |
|
| 313 | tmp = (M4VIFI_UInt8 *)M4OSA_malloc(rgbSize, M4VS,
|
| 314 | (M4OSA_Char*)"framing buffer pac_data");
|
| 315 |
|
| 316 | if(tmp == NULL) {
|
| 317 | LOGE("loadEffectsSettings:Alloc error pFramingBuf pac");
|
| 318 | M4OSA_free((M4OSA_MemAddr32)mEffectsSettings);
|
| 319 | mEffectsSettings = NULL;
|
| 320 | M4OSA_free(
|
| 321 | (M4OSA_MemAddr32)mEffectsSettings[i].xVSS.pFramingBuffer);
|
| 322 |
|
| 323 | mEffectsSettings[i].xVSS.pFramingBuffer = NULL;
|
| 324 | return M4ERR_ALLOC;
|
| 325 | }
|
| 326 | /* Initialize the pFramingBuffer*/
|
| 327 | mEffectsSettings[i].xVSS.pFramingBuffer->pac_data = tmp;
|
| 328 | mEffectsSettings[i].xVSS.pFramingBuffer->u_height =
|
| 329 | pSettings->Effects[i].xVSS.pFramingBuffer->u_height;
|
| 330 |
|
| 331 | mEffectsSettings[i].xVSS.pFramingBuffer->u_width =
|
| 332 | pSettings->Effects[i].xVSS.pFramingBuffer->u_width;
|
| 333 |
|
| 334 | mEffectsSettings[i].xVSS.pFramingBuffer->u_stride =
|
| 335 | pSettings->Effects[i].xVSS.pFramingBuffer->u_stride;
|
| 336 |
|
| 337 | mEffectsSettings[i].xVSS.pFramingBuffer->u_topleft =
|
| 338 | pSettings->Effects[i].xVSS.pFramingBuffer->u_topleft;
|
| 339 |
|
| 340 | mEffectsSettings[i].xVSS.uialphaBlendingStart =
|
| 341 | pSettings->Effects[i].xVSS.uialphaBlendingStart;
|
| 342 |
|
| 343 | mEffectsSettings[i].xVSS.uialphaBlendingMiddle =
|
| 344 | pSettings->Effects[i].xVSS.uialphaBlendingMiddle;
|
| 345 |
|
| 346 | mEffectsSettings[i].xVSS.uialphaBlendingEnd =
|
| 347 | pSettings->Effects[i].xVSS.uialphaBlendingEnd;
|
| 348 |
|
| 349 | mEffectsSettings[i].xVSS.uialphaBlendingFadeInTime =
|
| 350 | pSettings->Effects[i].xVSS.uialphaBlendingFadeInTime;
|
| 351 | mEffectsSettings[i].xVSS.uialphaBlendingFadeOutTime =
|
| 352 | pSettings->Effects[i].xVSS.uialphaBlendingFadeOutTime;
|
| 353 |
|
| 354 | // Copy the pFraming data
|
| 355 | M4OSA_memcpy((M4OSA_MemAddr8)
|
| 356 | mEffectsSettings[i].xVSS.pFramingBuffer->pac_data,
|
| 357 | (M4OSA_MemAddr8)pSettings->Effects[i].xVSS.pFramingBuffer->pac_data,
|
| 358 | rgbSize);
|
| 359 |
|
| 360 | mEffectsSettings[i].xVSS.rgbType =
|
| 361 | pSettings->Effects[i].xVSS.rgbType;
|
| 362 | }
|
| 363 | }
|
| 364 | }
|
| 365 | }
|
| 366 |
|
| 367 | if (mBackgroundAudioSetting == NULL) {
|
| 368 |
|
| 369 | mBackgroundAudioSetting = (M4xVSS_AudioMixingSettings*)M4OSA_malloc(
|
| 370 | sizeof(M4xVSS_AudioMixingSettings), M4VS,
|
| 371 | (M4OSA_Char*)"LvPP, copy of bgmSettings");
|
| 372 |
|
| 373 | if(NULL == mBackgroundAudioSetting) {
|
| 374 | LOGE("loadEditSettings: mBackgroundAudioSetting Malloc failed");
|
| 375 | return M4ERR_ALLOC;
|
| 376 | }
|
| 377 |
|
| 378 | M4OSA_memset((M4OSA_MemAddr8)mBackgroundAudioSetting, sizeof(M4xVSS_AudioMixingSettings*), 0);
|
| 379 | M4OSA_memcpy((M4OSA_MemAddr8)mBackgroundAudioSetting, (M4OSA_MemAddr8)bgmSettings, sizeof(M4xVSS_AudioMixingSettings));
|
| 380 |
|
| 381 | if ( mBackgroundAudioSetting->pFile != M4OSA_NULL ) {
|
| 382 |
|
| 383 | mBackgroundAudioSetting->pFile = (M4OSA_Void*) bgmSettings->pPCMFilePath;
|
| 384 | mBackgroundAudioSetting->uiNbChannels = 2;
|
| 385 | mBackgroundAudioSetting->uiSamplingFrequency = 32000;
|
| 386 | }
|
| 387 |
|
| 388 | // Open the BG file
|
| 389 | if ( mBackgroundAudioSetting->pFile != M4OSA_NULL ) {
|
| 390 | err = M4OSA_fileReadOpen(&mAudioMixPCMFileHandle,
|
| 391 | mBackgroundAudioSetting->pFile, M4OSA_kFileRead);
|
| 392 |
|
| 393 | if (err != M4NO_ERROR) {
|
| 394 | LOGE("loadEditSettings: mBackgroundAudio PCM File open failed");
|
| 395 | return M4ERR_PARAMETER;
|
| 396 | }
|
| 397 | }
|
| 398 | }
|
| 399 |
|
| 400 | mOutputVideoSize = pSettings->xVSS.outputVideoSize;
|
| 401 | mFrameStr.pBuffer = M4OSA_NULL;
|
| 402 | return M4NO_ERROR;
|
| 403 | }
|
| 404 |
|
| 405 | M4OSA_ERR VideoEditorPreviewController::setSurface(const sp<Surface> &surface) {
|
| 406 | LOGV("setSurface");
|
| 407 | Mutex::Autolock autoLock(mLock);
|
| 408 |
|
| 409 | mSurface = surface;
|
| 410 | mISurface = surface->getISurface();
|
| 411 | LOGV("setSurface: mISurface = %p", mISurface.get());
|
| 412 | return M4NO_ERROR;
|
| 413 | }
|
| 414 |
|
| 415 | M4OSA_ERR VideoEditorPreviewController::startPreview(
|
| 416 | M4OSA_UInt32 fromMS, M4OSA_Int32 toMs, M4OSA_UInt16 callBackAfterFrameCount,
|
| 417 | M4OSA_Bool loop) {
|
| 418 |
|
| 419 | M4OSA_ERR err = M4NO_ERROR;
|
| 420 | M4OSA_UInt32 i = 0, iIncrementedDuration = 0;
|
| 421 | LOGV("startPreview");
|
| 422 |
|
| 423 | if(fromMS > toMs) {
|
| 424 | LOGE("startPreview: fromMS > toMs");
|
| 425 | return M4ERR_PARAMETER;
|
| 426 | }
|
| 427 |
|
| 428 | if(toMs == 0) {
|
| 429 | LOGE("startPreview: toMs is 0");
|
| 430 | return M4ERR_PARAMETER;
|
| 431 | }
|
| 432 |
|
| 433 | // If already started, then stop preview first
|
| 434 | for(int playerInst=0; playerInst<NBPLAYER_INSTANCES; playerInst++) {
|
| 435 | if(mVePlayer[playerInst] != NULL) {
|
| 436 | LOGV("startPreview: stopping previously started preview playback");
|
| 437 | stopPreview();
|
| 438 | break;
|
| 439 | }
|
| 440 | }
|
| 441 |
|
| 442 | // If renderPreview was called previously, then delete Renderer object first
|
| 443 | if(mTarget != NULL) {
|
| 444 | LOGV("startPreview: delete previous PreviewRenderer");
|
| 445 | delete mTarget;
|
| 446 | mTarget = NULL;
|
| 447 | }
|
| 448 |
|
| 449 | LOGV("startPreview: loop = %d", loop);
|
| 450 | mPreviewLooping = loop;
|
| 451 |
|
| 452 | LOGV("startPreview: callBackAfterFrameCount = %d", callBackAfterFrameCount);
|
| 453 | mCallBackAfterFrameCnt = callBackAfterFrameCount;
|
| 454 |
|
| 455 | for (int playerInst=0; playerInst<NBPLAYER_INSTANCES; playerInst++) {
|
| 456 | mVePlayer[playerInst] = new VideoEditorPlayer();
|
| 457 | if(mVePlayer[playerInst] == NULL) {
|
| 458 | LOGE("startPreview:Error creating VideoEditorPlayer %d",playerInst);
|
| 459 | return M4ERR_ALLOC;
|
| 460 | }
|
| 461 | LOGV("startPreview: object created");
|
| 462 |
|
| 463 | mVePlayer[playerInst]->setNotifyCallback(this,(notify_callback_f)notify);
|
| 464 | LOGV("startPreview: notify callback set");
|
| 465 |
|
| 466 | mVePlayer[playerInst]->loadEffectsSettings(mEffectsSettings,
|
| 467 | mNumberEffects);
|
| 468 | LOGV("startPreview: effects settings loaded");
|
| 469 |
|
| 470 | mVePlayer[playerInst]->loadAudioMixSettings(mBackgroundAudioSetting);
|
| 471 | LOGV("startPreview: AudioMixSettings settings loaded");
|
| 472 |
|
| 473 | mVePlayer[playerInst]->setAudioMixPCMFileHandle(mAudioMixPCMFileHandle);
|
| 474 | LOGV("startPreview: AudioMixPCMFileHandle set");
|
| 475 |
|
| 476 | mVePlayer[playerInst]->setProgressCallbackInterval(
|
| 477 | mCallBackAfterFrameCnt);
|
| 478 | LOGV("startPreview: setProgressCallBackInterval");
|
| 479 | }
|
| 480 |
|
| 481 | mPlayerState = VePlayerIdle;
|
| 482 |
|
| 483 | if(fromMS == 0) {
|
| 484 | mCurrentClipNumber = -1;
|
| 485 | // Save original value
|
| 486 | mFirstPreviewClipBeginTime = mClipList[0]->uiBeginCutTime;
|
| 487 | mVideoStoryBoardTimeMsUptoFirstPreviewClip = 0;
|
| 488 | }
|
| 489 | else {
|
| 490 | LOGV("startPreview: fromMS=%d", fromMS);
|
| 491 | if(fromMS >= mClipTotalDuration) {
|
| 492 | LOGE("startPreview: fromMS >= mClipTotalDuration");
|
| 493 | return M4ERR_PARAMETER;
|
| 494 | }
|
| 495 | for(i=0;i<mNumberClipsInStoryBoard;i++) {
|
| 496 | if(fromMS < (iIncrementedDuration + (mClipList[i]->uiEndCutTime -
|
| 497 | mClipList[i]->uiBeginCutTime))) {
|
| 498 | // Set to 1 index below,
|
| 499 | // as threadProcess first increments the clip index
|
| 500 | // and then processes clip in thread loop
|
| 501 | mCurrentClipNumber = i-1;
|
| 502 | LOGV("startPreview:mCurrentClipNumber = %d fromMS=%d",i,fromMS);
|
| 503 |
|
| 504 | // Save original value
|
| 505 | mFirstPreviewClipBeginTime = mClipList[i]->uiBeginCutTime;
|
| 506 |
|
| 507 | // Set correct begin time to start playback
|
| 508 | if((fromMS+mClipList[i]->uiBeginCutTime) >
|
| 509 | (iIncrementedDuration+mClipList[i]->uiBeginCutTime)) {
|
| 510 |
|
| 511 | mClipList[i]->uiBeginCutTime =
|
| 512 | mClipList[i]->uiBeginCutTime +
|
| 513 | (fromMS - iIncrementedDuration);
|
| 514 | }
|
| 515 | break;
|
| 516 | }
|
| 517 | else {
|
| 518 | iIncrementedDuration = iIncrementedDuration +
|
| 519 | (mClipList[i]->uiEndCutTime - mClipList[i]->uiBeginCutTime);
|
| 520 | }
|
| 521 | }
|
| 522 | mVideoStoryBoardTimeMsUptoFirstPreviewClip = iIncrementedDuration;
|
| 523 | }
|
| 524 |
|
| 525 | for (int playerInst=0; playerInst<NBPLAYER_INSTANCES; playerInst++) {
|
| 526 | mVePlayer[playerInst]->setAudioMixStoryBoardParam(fromMS,
|
| 527 | mFirstPreviewClipBeginTime,
|
| 528 | mClipList[i]->ClipProperties.uiClipAudioVolumePercentage);
|
| 529 |
|
| 530 | LOGV("startPreview:setAudioMixStoryBoardSkimTimeStamp set %d cuttime \
|
| 531 | %d", fromMS, mFirstPreviewClipBeginTime);
|
| 532 | }
|
| 533 |
|
| 534 | mStartingClipIndex = mCurrentClipNumber+1;
|
| 535 |
|
| 536 | // Start playing with player instance 0
|
| 537 | mCurrentPlayer = 0;
|
| 538 |
|
| 539 | if(toMs == -1) {
|
| 540 | LOGV("startPreview: Preview till end of storyboard");
|
| 541 | mNumberClipsToPreview = mNumberClipsInStoryBoard;
|
| 542 | // Save original value
|
| 543 | mLastPreviewClipEndTime =
|
| 544 | mClipList[mNumberClipsToPreview-1]->uiEndCutTime;
|
| 545 | }
|
| 546 | else {
|
| 547 | LOGV("startPreview: toMs=%d", toMs);
|
| 548 | if(toMs > mClipTotalDuration) {
|
| 549 | LOGE("startPreview: toMs > mClipTotalDuration");
|
| 550 | return M4ERR_PARAMETER;
|
| 551 | }
|
| 552 |
|
| 553 | iIncrementedDuration = 0;
|
| 554 |
|
| 555 | for(i=0;i<mNumberClipsInStoryBoard;i++) {
|
| 556 | if(toMs <= (iIncrementedDuration +
|
| 557 | (mClipList[i]->uiEndCutTime - mClipList[i]->uiBeginCutTime))) {
|
| 558 | // Save original value
|
| 559 | mLastPreviewClipEndTime = mClipList[i]->uiEndCutTime;
|
| 560 | // Set the end cut time of clip index i to toMs
|
| 561 | mClipList[i]->uiEndCutTime = toMs;
|
| 562 |
|
| 563 | // Number of clips to be previewed is from index 0 to i
|
| 564 | // increment by 1 as i starts from 0
|
| 565 | mNumberClipsToPreview = i+1;
|
| 566 | break;
|
| 567 | }
|
| 568 | else {
|
| 569 | iIncrementedDuration = iIncrementedDuration +
|
| 570 | (mClipList[i]->uiEndCutTime - mClipList[i]->uiBeginCutTime);
|
| 571 | }
|
| 572 | }
|
| 573 | }
|
| 574 |
|
| 575 | // Open the thread semaphore
|
| 576 | M4OSA_semaphoreOpen(&mSemThreadWait, 1);
|
| 577 |
|
| 578 | // Open the preview process thread
|
| 579 | err = M4OSA_threadSyncOpen(&mThreadContext, (M4OSA_ThreadDoIt)threadProc);
|
| 580 | if (M4NO_ERROR != err) {
|
| 581 | LOGE("VideoEditorPreviewController:M4OSA_threadSyncOpen error %d", err);
|
| 582 | return err;
|
| 583 | }
|
| 584 |
|
| 585 | // Set the stacksize
|
| 586 | err = M4OSA_threadSyncSetOption(mThreadContext, M4OSA_ThreadStackSize,
|
| 587 | (M4OSA_DataOption)PREVIEW_THREAD_STACK_SIZE);
|
| 588 |
|
| 589 | if (M4NO_ERROR != err) {
|
| 590 | LOGE("VideoEditorPreviewController: threadSyncSetOption error %d", err);
|
| 591 | M4OSA_threadSyncClose(mThreadContext);
|
| 592 | mThreadContext = NULL;
|
| 593 | return err;
|
| 594 | }
|
| 595 |
|
| 596 | // Start the thread
|
| 597 | err = M4OSA_threadSyncStart(mThreadContext, (M4OSA_Void*)this);
|
| 598 | if (M4NO_ERROR != err) {
|
| 599 | LOGE("VideoEditorPreviewController: threadSyncStart error %d", err);
|
| 600 | M4OSA_threadSyncClose(mThreadContext);
|
| 601 | mThreadContext = NULL;
|
| 602 | return err;
|
| 603 | }
|
| 604 | bStopThreadInProgress = false;
|
| 605 |
|
| 606 | LOGV("startPreview: process thread started");
|
| 607 | return M4NO_ERROR;
|
| 608 | }
|
| 609 |
|
| 610 | M4OSA_ERR VideoEditorPreviewController::stopPreview() {
|
| 611 | M4OSA_ERR err = M4NO_ERROR;
|
| 612 | LOGV("stopPreview");
|
| 613 |
|
| 614 | // Stop the thread
|
| 615 | if(mThreadContext != NULL) {
|
| 616 | bStopThreadInProgress = true;
|
| 617 | err = M4OSA_semaphorePost(mSemThreadWait);
|
| 618 |
|
| 619 | err = M4OSA_threadSyncStop(mThreadContext);
|
| 620 | if(err != M4NO_ERROR) {
|
| 621 | LOGV("stopPreview: error 0x%x in trying to stop thread", err);
|
| 622 | // Continue even if error
|
| 623 | }
|
| 624 |
|
| 625 | err = M4OSA_threadSyncClose(mThreadContext);
|
| 626 | if(err != M4NO_ERROR) {
|
| 627 | LOGE("stopPreview: error 0x%x in trying to close thread", err);
|
| 628 | // Continue even if error
|
| 629 | }
|
| 630 |
|
| 631 | mThreadContext = NULL;
|
| 632 | }
|
| 633 |
|
| 634 | // Close the semaphore first
|
| 635 | if(mSemThreadWait != NULL) {
|
| 636 | err = M4OSA_semaphoreClose(mSemThreadWait);
|
| 637 | LOGV("stopPreview: close semaphore returns 0x%x", err);
|
| 638 | }
|
| 639 |
|
| 640 | for (int playerInst=0; playerInst<NBPLAYER_INSTANCES; playerInst++) {
|
| 641 | if(mVePlayer[playerInst] != NULL) {
|
| 642 | if(mVePlayer[playerInst]->isPlaying()) {
|
| 643 | LOGV("stop the player first");
|
| 644 | mVePlayer[playerInst]->stop();
|
| 645 | }
|
| 646 |
|
| 647 | LOGV("stopPreview: clearing mVePlayer");
|
| 648 | mVePlayer[playerInst].clear();
|
| 649 | mVePlayer[playerInst] = NULL;
|
| 650 | }
|
| 651 | }
|
| 652 |
|
| 653 | // If image file playing, then free the buffer pointer
|
| 654 | if(mFrameStr.pBuffer != M4OSA_NULL) {
|
| 655 | M4OSA_free((M4OSA_MemAddr32)mFrameStr.pBuffer);
|
| 656 | mFrameStr.pBuffer = M4OSA_NULL;
|
| 657 | }
|
| 658 |
|
| 659 | // Reset original begin cuttime of first previewed clip*/
|
| 660 | mClipList[mStartingClipIndex]->uiBeginCutTime = mFirstPreviewClipBeginTime;
|
| 661 | // Reset original end cuttime of last previewed clip*/
|
| 662 | mClipList[mNumberClipsToPreview-1]->uiEndCutTime = mLastPreviewClipEndTime;
|
| 663 |
|
| 664 | mPlayerState = VePlayerIdle;
|
| 665 |
|
| 666 | mCurrentPlayedDuration = 0;
|
| 667 | mCurrentClipDuration = 0;
|
| 668 | mRenderingMode = M4xVSS_kBlackBorders;
|
| 669 | mOutputVideoWidth = 0;
|
| 670 | mOutputVideoHeight = 0;
|
| 671 |
|
| 672 | return M4NO_ERROR;
|
| 673 | }
|
| 674 |
|
| 675 | M4OSA_ERR VideoEditorPreviewController::renderPreviewFrame(
|
| 676 | const sp<Surface> &surface, VideoEditor_renderPreviewFrameStr* pFrameInfo) {
|
| 677 |
|
| 678 | M4OSA_ERR err = M4NO_ERROR;
|
| 679 | M4OSA_UInt32 i = 0, iIncrementedDuration = 0, tnTimeMs=0, framesize =0;
|
| 680 | VideoEditor_renderPreviewFrameStr* pFrameStr = pFrameInfo;
|
| 681 | M4VIFI_UInt8 *pixelArray = NULL;
|
| 682 |
|
| 683 | Mutex::Autolock autoLock(mLock);
|
| 684 |
|
| 685 | // Get the Isurface to be passed to renderer
|
| 686 | mISurface = surface->getISurface();
|
| 687 |
|
| 688 | // Delete previous renderer instance
|
| 689 | if(mTarget != NULL) {
|
| 690 | delete mTarget;
|
| 691 | mTarget = NULL;
|
| 692 | }
|
| 693 |
|
| 694 | if(mOutputVideoWidth == 0) {
|
| 695 | mOutputVideoWidth = pFrameStr->uiFrameWidth;
|
| 696 | }
|
| 697 | if(mOutputVideoHeight == 0) {
|
| 698 | mOutputVideoHeight = pFrameStr->uiFrameHeight;
|
| 699 | }
|
| 700 |
|
| 701 | // Initialize the renderer
|
| 702 | if(mTarget == NULL) {
|
| 703 | mTarget = new PreviewRenderer(
|
| 704 | OMX_COLOR_FormatYUV420Planar, surface, mOutputVideoWidth, mOutputVideoHeight,
|
| 705 | mOutputVideoWidth, mOutputVideoHeight, 0);
|
| 706 | if(mTarget == NULL) {
|
| 707 | LOGE("renderPreviewFrame: cannot create PreviewRenderer");
|
| 708 | return M4ERR_ALLOC;
|
| 709 | }
|
| 710 | }
|
| 711 |
|
| 712 | pixelArray = NULL;
|
| 713 |
|
| 714 | // Postprocessing (apply video effect)
|
| 715 | if(pFrameStr->bApplyEffect == M4OSA_TRUE) {
|
| 716 |
|
| 717 | for(i=0;i<mNumberEffects;i++) {
|
| 718 | // First check if effect starttime matches the clip being previewed
|
| 719 | if((mEffectsSettings[i].uiStartTime < pFrameStr->clipBeginCutTime)
|
| 720 | ||(mEffectsSettings[i].uiStartTime >= pFrameStr->clipEndCutTime)) {
|
| 721 | // This effect doesn't belong to this clip, check next one
|
| 722 | continue;
|
| 723 | }
|
| 724 | if((mEffectsSettings[i].uiStartTime <= pFrameStr->timeMs) &&
|
| 725 | ((mEffectsSettings[i].uiStartTime+mEffectsSettings[i].uiDuration) >=
|
| 726 | pFrameStr->timeMs) && (mEffectsSettings[i].uiDuration != 0)) {
|
| 727 | setVideoEffectType(mEffectsSettings[i].VideoEffectType, TRUE);
|
| 728 | }
|
| 729 | else {
|
| 730 | setVideoEffectType(mEffectsSettings[i].VideoEffectType, FALSE);
|
| 731 | }
|
| 732 | }
|
| 733 |
|
| 734 | if(mCurrentVideoEffect != VIDEO_EFFECT_NONE) {
|
| 735 | err = applyVideoEffect((M4OSA_Void *)pFrameStr->pBuffer,
|
| 736 | OMX_COLOR_FormatYUV420Planar, pFrameStr->uiFrameWidth,
|
| 737 | pFrameStr->uiFrameHeight, pFrameStr->timeMs,
|
| 738 | (M4OSA_Void *)pixelArray);
|
| 739 |
|
| 740 | if(err != M4NO_ERROR) {
|
| 741 | LOGE("renderPreviewFrame: applyVideoEffect error 0x%x", err);
|
| 742 | delete mTarget;
|
| 743 | mTarget = NULL;
|
| 744 | M4OSA_free((M4OSA_MemAddr32)pixelArray);
|
| 745 | pixelArray = NULL;
|
| 746 | return err;
|
| 747 | }
|
| 748 | mCurrentVideoEffect = VIDEO_EFFECT_NONE;
|
| 749 | }
|
| 750 | else {
|
| 751 | // Apply the rendering mode
|
| 752 | err = doImageRenderingMode((M4OSA_Void *)pFrameStr->pBuffer,
|
| 753 | OMX_COLOR_FormatYUV420Planar, pFrameStr->uiFrameWidth,
|
| 754 | pFrameStr->uiFrameHeight, (M4OSA_Void *)pixelArray);
|
| 755 |
|
| 756 | if(err != M4NO_ERROR) {
|
| 757 | LOGE("renderPreviewFrame:doImageRenderingMode error 0x%x", err);
|
| 758 | delete mTarget;
|
| 759 | mTarget = NULL;
|
| 760 | M4OSA_free((M4OSA_MemAddr32)pixelArray);
|
| 761 | pixelArray = NULL;
|
| 762 | return err;
|
| 763 | }
|
| 764 | }
|
| 765 | }
|
| 766 | else {
|
| 767 | // Apply the rendering mode
|
| 768 | err = doImageRenderingMode((M4OSA_Void *)pFrameStr->pBuffer,
|
| 769 | OMX_COLOR_FormatYUV420Planar, pFrameStr->uiFrameWidth,
|
| 770 | pFrameStr->uiFrameHeight, (M4OSA_Void *)pixelArray);
|
| 771 |
|
| 772 | if(err != M4NO_ERROR) {
|
| 773 | LOGE("renderPreviewFrame: doImageRenderingMode error 0x%x", err);
|
| 774 | delete mTarget;
|
| 775 | mTarget = NULL;
|
| 776 | M4OSA_free((M4OSA_MemAddr32)pixelArray);
|
| 777 | pixelArray = NULL;
|
| 778 | return err;
|
| 779 | }
|
| 780 | }
|
| 781 |
|
| 782 | mTarget->renderYV12();
|
| 783 | return err;
|
| 784 | }
|
| 785 |
|
| 786 | M4OSA_Void VideoEditorPreviewController::setJniCallback(void* cookie,
|
| 787 | jni_progress_callback_fct callbackFct) {
|
| 788 | //LOGV("setJniCallback");
|
| 789 | mJniCookie = cookie;
|
| 790 | mJniCallback = callbackFct;
|
| 791 | }
|
| 792 |
|
| 793 | M4OSA_ERR VideoEditorPreviewController::preparePlayer(
|
| 794 | void* param, int playerInstance, int index) {
|
| 795 |
|
| 796 | M4OSA_ERR err = M4NO_ERROR;
|
| 797 | VideoEditorPreviewController *pController =
|
| 798 | (VideoEditorPreviewController *)param;
|
| 799 |
|
| 800 | LOGV("preparePlayer: instance %d file %d", playerInstance, index);
|
| 801 |
|
| 802 | pController->mVePlayer[playerInstance]->setDataSource(
|
| 803 | (const char *)pController->mClipList[index]->pFile, NULL);
|
| 804 | LOGV("preparePlayer: setDataSource instance %s",
|
| 805 | (const char *)pController->mClipList[index]->pFile);
|
| 806 |
|
| 807 | pController->mVePlayer[playerInstance]->setVideoISurface(
|
| 808 | pController->mISurface);
|
| 809 | LOGV("preparePlayer: setVideoISurface");
|
| 810 |
|
| 811 | pController->mVePlayer[playerInstance]->setVideoSurface(
|
| 812 | pController->mSurface);
|
| 813 | LOGV("preparePlayer: setVideoSurface");
|
| 814 |
|
| 815 | pController->mVePlayer[playerInstance]->setMediaRenderingMode(
|
| 816 | pController->mClipList[index]->xVSS.MediaRendering,
|
| 817 | pController->mOutputVideoSize);
|
| 818 | LOGV("preparePlayer: setMediaRenderingMode");
|
| 819 |
|
| 820 | if(index == pController->mStartingClipIndex) {
|
| 821 | pController->mVePlayer[playerInstance]->setPlaybackBeginTime(
|
| 822 | pController->mFirstPreviewClipBeginTime);
|
| 823 | }
|
| 824 | else {
|
| 825 | pController->mVePlayer[playerInstance]->setPlaybackBeginTime(
|
| 826 | pController->mClipList[index]->uiBeginCutTime);
|
| 827 | }
|
| 828 | LOGV("preparePlayer: setPlaybackBeginTime(%d)",
|
| 829 | pController->mClipList[index]->uiBeginCutTime);
|
| 830 |
|
| 831 | pController->mVePlayer[playerInstance]->setPlaybackEndTime(
|
| 832 | pController->mClipList[index]->uiEndCutTime);
|
| 833 | LOGV("preparePlayer: setPlaybackEndTime(%d)",
|
| 834 | pController->mClipList[index]->uiEndCutTime);
|
| 835 |
|
| 836 | if(pController->mClipList[index]->FileType == M4VIDEOEDITING_kFileType_ARGB8888) {
|
| 837 | pController->mVePlayer[playerInstance]->setImageClipProperties(
|
| 838 | pController->mClipList[index]->ClipProperties.uiVideoWidth,
|
| 839 | pController->mClipList[index]->ClipProperties.uiVideoHeight);
|
| 840 | LOGV("preparePlayer: setImageClipProperties");
|
| 841 | }
|
| 842 |
|
| 843 | pController->mVePlayer[playerInstance]->prepare();
|
| 844 | LOGV("preparePlayer: prepared");
|
| 845 |
|
| 846 | if(pController->mClipList[index]->uiBeginCutTime > 0) {
|
| 847 | pController->mVePlayer[playerInstance]->seekTo(
|
| 848 | pController->mClipList[index]->uiBeginCutTime);
|
| 849 |
|
| 850 | LOGV("preparePlayer: seekTo(%d)",
|
| 851 | pController->mClipList[index]->uiBeginCutTime);
|
| 852 | }
|
| 853 |
|
| 854 | pController->mVePlayer[playerInstance]->readFirstVideoFrame();
|
| 855 | LOGV("preparePlayer: readFirstVideoFrame of clip");
|
| 856 |
|
| 857 | return err;
|
| 858 | }
|
| 859 |
|
| 860 | M4OSA_ERR VideoEditorPreviewController::threadProc(M4OSA_Void* param) {
|
| 861 | M4OSA_ERR err = M4NO_ERROR;
|
| 862 | M4OSA_Int32 index = 0;
|
| 863 | VideoEditorPreviewController *pController =
|
| 864 | (VideoEditorPreviewController *)param;
|
| 865 |
|
| 866 | LOGV("inside threadProc");
|
| 867 | if(pController->mPlayerState == VePlayerIdle) {
|
| 868 | (pController->mCurrentClipNumber)++;
|
| 869 |
|
| 870 | LOGV("threadProc: playing file index %d total clips %d",
|
| 871 | pController->mCurrentClipNumber, pController->mNumberClipsToPreview);
|
| 872 |
|
| 873 | if(pController->mCurrentClipNumber >=
|
| 874 | pController->mNumberClipsToPreview) {
|
| 875 |
|
| 876 | LOGV("All clips previewed");
|
| 877 |
|
| 878 | pController->mCurrentPlayedDuration = 0;
|
| 879 | pController->mCurrentClipDuration = 0;
|
| 880 | pController->mCurrentPlayer = 0;
|
| 881 |
|
| 882 | if(pController->mPreviewLooping == M4OSA_TRUE) {
|
| 883 | pController->mCurrentClipNumber =
|
| 884 | pController->mStartingClipIndex;
|
| 885 |
|
| 886 | LOGV("Preview looping TRUE, restarting from clip index %d",
|
| 887 | pController->mCurrentClipNumber);
|
| 888 |
|
| 889 | // Reset the story board timestamp inside the player
|
| 890 | for (int playerInst=0; playerInst<NBPLAYER_INSTANCES;
|
| 891 | playerInst++) {
|
| 892 | pController->mVePlayer[playerInst]->resetJniCallbackTimeStamp();
|
| 893 | }
|
| 894 | }
|
| 895 | else {
|
| 896 | if(pController->mJniCallback != NULL) {
|
| 897 | pController->mJniCallback(
|
| 898 | pController->mJniCookie, MSG_TYPE_PREVIEW_END, 0);
|
| 899 | }
|
| 900 | pController->mPlayerState = VePlayerAutoStop;
|
| 901 |
|
| 902 | // Reset original begin cuttime of first previewed clip
|
| 903 | pController->mClipList[pController->mStartingClipIndex]->uiBeginCutTime =
|
| 904 | pController->mFirstPreviewClipBeginTime;
|
| 905 | // Reset original end cuttime of last previewed clip
|
| 906 | pController->mClipList[pController->mNumberClipsToPreview-1]->uiEndCutTime =
|
| 907 | pController->mLastPreviewClipEndTime;
|
| 908 |
|
| 909 | // Return a warning to M4OSA thread handler
|
| 910 | // so that thread is moved from executing state to open state
|
| 911 | return M4WAR_NO_MORE_STREAM;
|
| 912 | }
|
| 913 | }
|
| 914 |
|
| 915 | index=pController->mCurrentClipNumber;
|
| 916 | if(pController->mCurrentClipNumber == pController->mStartingClipIndex) {
|
| 917 | pController->mCurrentPlayedDuration +=
|
| 918 | pController->mVideoStoryBoardTimeMsUptoFirstPreviewClip;
|
| 919 |
|
| 920 | pController->mCurrentClipDuration =
|
| 921 | pController->mClipList[pController->mCurrentClipNumber]->uiEndCutTime
|
| 922 | - pController->mFirstPreviewClipBeginTime;
|
| 923 |
|
| 924 | preparePlayer((void*)pController, pController->mCurrentPlayer, index);
|
| 925 | }
|
| 926 | else {
|
| 927 | pController->mCurrentPlayedDuration +=
|
| 928 | pController->mCurrentClipDuration;
|
| 929 |
|
| 930 | pController->mCurrentClipDuration =
|
| 931 | pController->mClipList[pController->mCurrentClipNumber]->uiEndCutTime -
|
| 932 | pController->mClipList[pController->mCurrentClipNumber]->uiBeginCutTime;
|
| 933 | }
|
| 934 |
|
| 935 | pController->mVePlayer[pController->mCurrentPlayer]->setStoryboardStartTime(
|
| 936 | pController->mCurrentPlayedDuration);
|
| 937 | LOGV("threadProc: setStoryboardStartTime");
|
| 938 |
|
| 939 | // Set the next clip duration for Audio mix here
|
| 940 | if(pController->mCurrentClipNumber != pController->mStartingClipIndex) {
|
| 941 |
|
| 942 | pController->mVePlayer[pController->mCurrentPlayer]->setAudioMixStoryBoardParam(
|
| 943 | pController->mCurrentPlayedDuration,
|
| 944 | pController->mClipList[index]->uiBeginCutTime,
|
| 945 | pController->mClipList[index]->ClipProperties.uiClipAudioVolumePercentage);
|
| 946 |
|
| 947 | LOGV("threadProc: setAudioMixStoryBoardParam fromMS %d \
|
| 948 | ClipBeginTime %d", pController->mCurrentPlayedDuration +
|
| 949 | pController->mClipList[index]->uiBeginCutTime,
|
| 950 | pController->mClipList[index]->uiBeginCutTime,
|
| 951 | pController->mClipList[index]->ClipProperties.uiClipAudioVolumePercentage);
|
| 952 | }
|
| 953 |
|
| 954 | pController->mVePlayer[pController->mCurrentPlayer]->start();
|
| 955 | LOGV("threadProc: started");
|
| 956 |
|
| 957 | pController->mPlayerState = VePlayerBusy;
|
| 958 |
|
| 959 | }
|
| 960 | else if(pController->mPlayerState == VePlayerAutoStop) {
|
| 961 | LOGV("Preview completed..auto stop the player");
|
| 962 | }
|
| 963 | else {
|
| 964 | if(!pController->bStopThreadInProgress) {
|
| 965 | LOGV("threadProc: state busy...wait for sem");
|
| 966 | err = M4OSA_semaphoreWait(pController->mSemThreadWait,
|
| 967 | M4OSA_WAIT_FOREVER);
|
| 968 | }
|
| 969 | LOGV("threadProc: sem wait returned err = 0x%x", err);
|
| 970 | }
|
| 971 |
|
| 972 | //Always return M4NO_ERROR to ensure the thread keeps running
|
| 973 | return M4NO_ERROR;
|
| 974 | }
|
| 975 |
|
| 976 | void VideoEditorPreviewController::notify(
|
| 977 | void* cookie, int msg, int ext1, int ext2)
|
| 978 | {
|
| 979 | VideoEditorPreviewController *pController =
|
| 980 | (VideoEditorPreviewController *)cookie;
|
| 981 |
|
| 982 | M4OSA_ERR err = M4NO_ERROR;
|
| 983 | uint32_t clipDuration = 0;
|
| 984 | switch (msg) {
|
| 985 | case MEDIA_NOP: // interface test message
|
| 986 | LOGV("MEDIA_NOP");
|
| 987 | break;
|
| 988 | case MEDIA_PREPARED:
|
| 989 | LOGV("MEDIA_PREPARED");
|
| 990 | break;
|
| 991 | case MEDIA_PLAYBACK_COMPLETE:
|
| 992 | LOGV("notify:MEDIA_PLAYBACK_COMPLETE");
|
| 993 | pController->mPlayerState = VePlayerIdle;
|
| 994 |
|
| 995 | //send progress callback with last frame timestamp
|
| 996 | if(pController->mCurrentClipNumber ==
|
| 997 | pController->mStartingClipIndex) {
|
| 998 | clipDuration =
|
| 999 | pController->mClipList[pController->mCurrentClipNumber]->uiEndCutTime
|
| 1000 | - pController->mFirstPreviewClipBeginTime;
|
| 1001 | }
|
| 1002 | else {
|
| 1003 | clipDuration =
|
| 1004 | pController->mClipList[pController->mCurrentClipNumber]->uiEndCutTime
|
| 1005 | - pController->mClipList[pController->mCurrentClipNumber]->uiBeginCutTime;
|
| 1006 | }
|
| 1007 | pController->mJniCallback(
|
| 1008 | pController->mJniCookie, MSG_TYPE_PROGRESS_INDICATION,
|
| 1009 | (clipDuration+pController->mCurrentPlayedDuration));
|
| 1010 |
|
| 1011 | M4OSA_semaphorePost(pController->mSemThreadWait);
|
| 1012 | break;
|
| 1013 | case MEDIA_ERROR:
|
| 1014 | // Always log errors.
|
| 1015 | // ext1: Media framework error code.
|
| 1016 | // ext2: Implementation dependant error code.
|
| 1017 | LOGE("MEDIA_ERROR; error (%d, %d)", ext1, ext2);
|
| 1018 | if(pController->mJniCallback != NULL) {
|
| 1019 | pController->mJniCallback(pController->mJniCookie,
|
| 1020 | MSG_TYPE_PLAYER_ERROR, ext1);
|
| 1021 | }
|
| 1022 | break;
|
| 1023 | case MEDIA_INFO:
|
| 1024 | // ext1: Media framework error code.
|
| 1025 | // ext2: Implementation dependant error code.
|
| 1026 | //LOGW("MEDIA_INFO; info/warning (%d, %d)", ext1, ext2);
|
| 1027 | if(pController->mJniCallback != NULL) {
|
| 1028 | pController->mJniCallback(pController->mJniCookie,
|
| 1029 | MSG_TYPE_PROGRESS_INDICATION, ext2);
|
| 1030 | }
|
| 1031 | break;
|
| 1032 | case MEDIA_SEEK_COMPLETE:
|
| 1033 | LOGV("MEDIA_SEEK_COMPLETE; Received seek complete");
|
| 1034 | break;
|
| 1035 | case MEDIA_BUFFERING_UPDATE:
|
| 1036 | LOGV("MEDIA_BUFFERING_UPDATE; buffering %d", ext1);
|
| 1037 | break;
|
| 1038 | case MEDIA_SET_VIDEO_SIZE:
|
| 1039 | LOGV("MEDIA_SET_VIDEO_SIZE; New video size %d x %d", ext1, ext2);
|
| 1040 | break;
|
| 1041 | case 0xAAAAAAAA:
|
| 1042 | LOGV("VIDEO PLAYBACK ALMOST over, prepare next player");
|
| 1043 |
|
| 1044 | // Select next player and prepare it
|
| 1045 | // If there is a clip after this one
|
| 1046 | if ((pController->mCurrentClipNumber+1) <
|
| 1047 | pController->mNumberClipsToPreview) {
|
| 1048 |
|
| 1049 | pController->mCurrentPlayer++;
|
| 1050 | if (pController->mCurrentPlayer >= NBPLAYER_INSTANCES) {
|
| 1051 | pController->mCurrentPlayer = 0;
|
| 1052 | }
|
| 1053 | // Prepare the first clip to be played
|
| 1054 | preparePlayer((void*)pController, pController->mCurrentPlayer,
|
| 1055 | pController->mCurrentClipNumber+1);
|
| 1056 | }
|
| 1057 | break;
|
| 1058 | default:
|
| 1059 | LOGV("unrecognized message: (%d, %d, %d)", msg, ext1, ext2);
|
| 1060 | break;
|
| 1061 | }
|
| 1062 | }
|
| 1063 |
|
| 1064 | void VideoEditorPreviewController::setVideoEffectType(
|
| 1065 | M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable) {
|
| 1066 |
|
| 1067 | M4OSA_UInt32 effect = VIDEO_EFFECT_NONE;
|
| 1068 |
|
| 1069 | // map M4VSS3GPP_VideoEffectType to local enum
|
| 1070 | switch(type) {
|
| 1071 | case M4VSS3GPP_kVideoEffectType_FadeFromBlack:
|
| 1072 | effect = VIDEO_EFFECT_FADEFROMBLACK;
|
| 1073 | break;
|
| 1074 |
|
| 1075 | case M4VSS3GPP_kVideoEffectType_FadeToBlack:
|
| 1076 | effect = VIDEO_EFFECT_FADETOBLACK;
|
| 1077 | break;
|
| 1078 |
|
| 1079 | case M4VSS3GPP_kVideoEffectType_CurtainOpening:
|
| 1080 | effect = VIDEO_EFFECT_CURTAINOPEN;
|
| 1081 | break;
|
| 1082 |
|
| 1083 | case M4VSS3GPP_kVideoEffectType_CurtainClosing:
|
| 1084 | effect = VIDEO_EFFECT_CURTAINCLOSE;
|
| 1085 | break;
|
| 1086 |
|
| 1087 | case M4xVSS_kVideoEffectType_BlackAndWhite:
|
| 1088 | effect = VIDEO_EFFECT_BLACKANDWHITE;
|
| 1089 | break;
|
| 1090 |
|
| 1091 | case M4xVSS_kVideoEffectType_Pink:
|
| 1092 | effect = VIDEO_EFFECT_PINK;
|
| 1093 | break;
|
| 1094 |
|
| 1095 | case M4xVSS_kVideoEffectType_Green:
|
| 1096 | effect = VIDEO_EFFECT_GREEN;
|
| 1097 | break;
|
| 1098 |
|
| 1099 | case M4xVSS_kVideoEffectType_Sepia:
|
| 1100 | effect = VIDEO_EFFECT_SEPIA;
|
| 1101 | break;
|
| 1102 |
|
| 1103 | case M4xVSS_kVideoEffectType_Negative:
|
| 1104 | effect = VIDEO_EFFECT_NEGATIVE;
|
| 1105 | break;
|
| 1106 |
|
| 1107 | case M4xVSS_kVideoEffectType_Framing:
|
| 1108 | effect = VIDEO_EFFECT_FRAMING;
|
| 1109 | break;
|
| 1110 |
|
| 1111 | case M4xVSS_kVideoEffectType_Fifties:
|
| 1112 | effect = VIDEO_EFFECT_FIFTIES;
|
| 1113 | break;
|
| 1114 |
|
| 1115 | case M4xVSS_kVideoEffectType_ColorRGB16:
|
| 1116 | effect = VIDEO_EFFECT_COLOR_RGB16;
|
| 1117 | break;
|
| 1118 |
|
| 1119 | case M4xVSS_kVideoEffectType_Gradient:
|
| 1120 | effect = VIDEO_EFFECT_GRADIENT;
|
| 1121 | break;
|
| 1122 |
|
| 1123 | default:
|
| 1124 | effect = VIDEO_EFFECT_NONE;
|
| 1125 | break;
|
| 1126 | }
|
| 1127 |
|
| 1128 | if(enable == M4OSA_TRUE) {
|
| 1129 | // If already set, then no need to set again
|
| 1130 | if(!(mCurrentVideoEffect & effect))
|
| 1131 | mCurrentVideoEffect |= effect;
|
| 1132 | if(effect == VIDEO_EFFECT_FIFTIES) {
|
| 1133 | mIsFiftiesEffectStarted = true;
|
| 1134 | }
|
| 1135 | }
|
| 1136 | else {
|
| 1137 | // Reset only if already set
|
| 1138 | if(mCurrentVideoEffect & effect)
|
| 1139 | mCurrentVideoEffect &= ~effect;
|
| 1140 | }
|
| 1141 |
|
| 1142 | return;
|
| 1143 | }
|
| 1144 |
|
| 1145 |
|
| 1146 | M4OSA_ERR VideoEditorPreviewController::applyVideoEffect(
|
| 1147 | M4OSA_Void * dataPtr, M4OSA_UInt32 colorFormat, M4OSA_UInt32 videoWidth,
|
| 1148 | M4OSA_UInt32 videoHeight, M4OSA_UInt32 timeMs, M4OSA_Void* outPtr) {
|
| 1149 |
|
| 1150 | M4OSA_ERR err = M4NO_ERROR;
|
| 1151 | vePostProcessParams postProcessParams;
|
| 1152 |
|
| 1153 | postProcessParams.vidBuffer = (M4VIFI_UInt8*)dataPtr;
|
| 1154 | postProcessParams.videoWidth = videoWidth;
|
| 1155 | postProcessParams.videoHeight = videoHeight;
|
| 1156 | postProcessParams.timeMs = timeMs;
|
| 1157 | postProcessParams.timeOffset = 0; //Since timeMS already takes care of offset in this case
|
| 1158 | postProcessParams.effectsSettings = mEffectsSettings;
|
| 1159 | postProcessParams.numberEffects = mNumberEffects;
|
| 1160 | postProcessParams.outVideoWidth = mOutputVideoWidth;
|
| 1161 | postProcessParams.outVideoHeight = mOutputVideoHeight;
|
| 1162 | postProcessParams.currentVideoEffect = mCurrentVideoEffect;
|
| 1163 | postProcessParams.renderingMode = mRenderingMode;
|
| 1164 | if(mIsFiftiesEffectStarted == M4OSA_TRUE) {
|
| 1165 | postProcessParams.isFiftiesEffectStarted = M4OSA_TRUE;
|
| 1166 | mIsFiftiesEffectStarted = M4OSA_FALSE;
|
| 1167 | }
|
| 1168 | else {
|
| 1169 | postProcessParams.isFiftiesEffectStarted = M4OSA_FALSE;
|
| 1170 | }
|
| 1171 | //postProcessParams.renderer = mTarget;
|
| 1172 | postProcessParams.overlayFrameRGBBuffer = NULL;
|
| 1173 | postProcessParams.overlayFrameYUVBuffer = NULL;
|
| 1174 |
|
| 1175 | mTarget->getBufferYV12(&(postProcessParams.pOutBuffer), &(postProcessParams.outBufferStride));
|
| 1176 |
|
| 1177 | err = applyEffectsAndRenderingMode(&postProcessParams);
|
| 1178 | return err;
|
| 1179 | }
|
| 1180 |
|
| 1181 | M4OSA_ERR VideoEditorPreviewController::setPreviewFrameRenderingMode(
|
| 1182 | M4xVSS_MediaRendering mode, M4VIDEOEDITING_VideoFrameSize outputVideoSize) {
|
| 1183 |
|
| 1184 | //LOGV("setMediaRenderingMode: outputVideoSize = %d", outputVideoSize);
|
| 1185 | mRenderingMode = mode;
|
| 1186 |
|
| 1187 | switch(outputVideoSize) {
|
| 1188 | case M4VIDEOEDITING_kSQCIF:
|
| 1189 | mOutputVideoWidth = 128;
|
| 1190 | mOutputVideoHeight = 96;
|
| 1191 | break;
|
| 1192 |
|
| 1193 | case M4VIDEOEDITING_kQQVGA:
|
| 1194 | mOutputVideoWidth = 160;
|
| 1195 | mOutputVideoHeight = 120;
|
| 1196 | break;
|
| 1197 |
|
| 1198 | case M4VIDEOEDITING_kQCIF:
|
| 1199 | mOutputVideoWidth = 176;
|
| 1200 | mOutputVideoHeight = 144;
|
| 1201 | break;
|
| 1202 |
|
| 1203 | case M4VIDEOEDITING_kQVGA:
|
| 1204 | mOutputVideoWidth = 320;
|
| 1205 | mOutputVideoHeight = 240;
|
| 1206 | break;
|
| 1207 |
|
| 1208 | case M4VIDEOEDITING_kCIF:
|
| 1209 | mOutputVideoWidth = 352;
|
| 1210 | mOutputVideoHeight = 288;
|
| 1211 | break;
|
| 1212 |
|
| 1213 | case M4VIDEOEDITING_kVGA:
|
| 1214 | mOutputVideoWidth = 640;
|
| 1215 | mOutputVideoHeight = 480;
|
| 1216 | break;
|
| 1217 |
|
| 1218 | case M4VIDEOEDITING_kWVGA:
|
| 1219 | mOutputVideoWidth = 800;
|
| 1220 | mOutputVideoHeight = 480;
|
| 1221 | break;
|
| 1222 |
|
| 1223 | case M4VIDEOEDITING_kNTSC:
|
| 1224 | mOutputVideoWidth = 720;
|
| 1225 | mOutputVideoHeight = 480;
|
| 1226 | break;
|
| 1227 |
|
| 1228 | case M4VIDEOEDITING_k640_360:
|
| 1229 | mOutputVideoWidth = 640;
|
| 1230 | mOutputVideoHeight = 360;
|
| 1231 | break;
|
| 1232 |
|
| 1233 | case M4VIDEOEDITING_k854_480:
|
| 1234 | mOutputVideoWidth = 854;
|
| 1235 | mOutputVideoHeight = 480;
|
| 1236 | break;
|
| 1237 |
|
| 1238 | case M4VIDEOEDITING_kHD1280:
|
| 1239 | mOutputVideoWidth = 1280;
|
| 1240 | mOutputVideoHeight = 720;
|
| 1241 | break;
|
| 1242 |
|
| 1243 | case M4VIDEOEDITING_kHD1080:
|
| 1244 | mOutputVideoWidth = 1080;
|
| 1245 | mOutputVideoHeight = 720;
|
| 1246 | break;
|
| 1247 |
|
| 1248 | case M4VIDEOEDITING_kHD960:
|
| 1249 | mOutputVideoWidth = 960;
|
| 1250 | mOutputVideoHeight = 720;
|
| 1251 | break;
|
| 1252 |
|
| 1253 | default:
|
| 1254 | mOutputVideoWidth = 0;
|
| 1255 | mOutputVideoHeight = 0;
|
| 1256 | break;
|
| 1257 | }
|
| 1258 |
|
| 1259 | return OK;
|
| 1260 | }
|
| 1261 |
|
| 1262 | M4OSA_ERR VideoEditorPreviewController::doImageRenderingMode(
|
| 1263 | M4OSA_Void * dataPtr, M4OSA_UInt32 colorFormat, M4OSA_UInt32 videoWidth,
|
| 1264 | M4OSA_UInt32 videoHeight, M4OSA_Void* outPtr) {
|
| 1265 |
|
| 1266 | M4OSA_ERR err = M4NO_ERROR;
|
| 1267 | M4VIFI_ImagePlane planeIn[3], planeOut[3];
|
| 1268 | M4VIFI_UInt8 *inBuffer = M4OSA_NULL;
|
| 1269 | M4OSA_UInt32 outputBufferWidth =0, outputBufferHeight=0;
|
| 1270 |
|
| 1271 | //frameSize = (videoWidth*videoHeight*3) >> 1;
|
| 1272 | inBuffer = (M4OSA_UInt8 *)dataPtr;
|
| 1273 |
|
| 1274 | // In plane
|
| 1275 | prepareYUV420ImagePlane(planeIn, videoWidth,
|
| 1276 | videoHeight, (M4VIFI_UInt8 *)inBuffer);
|
| 1277 |
|
| 1278 | outputBufferWidth = mOutputVideoWidth;
|
| 1279 | outputBufferHeight = mOutputVideoHeight;
|
| 1280 |
|
| 1281 | // Out plane
|
| 1282 | uint8_t* outBuffer;
|
| 1283 | size_t outBufferStride = 0;
|
| 1284 |
|
| 1285 | LOGV("doMediaRendering CALL getBuffer()");
|
| 1286 | mTarget->getBufferYV12(&outBuffer, &outBufferStride);
|
| 1287 |
|
| 1288 | // Set the output YUV420 plane to be compatible with YV12 format
|
| 1289 | //In YV12 format, sizes must be even
|
| 1290 | M4OSA_UInt32 yv12PlaneWidth = ((mOutputVideoWidth +1)>>1)<<1;
|
| 1291 | M4OSA_UInt32 yv12PlaneHeight = ((mOutputVideoHeight+1)>>1)<<1;
|
| 1292 |
|
| 1293 | prepareYV12ImagePlane(planeOut, yv12PlaneWidth, yv12PlaneHeight,
|
| 1294 | (M4OSA_UInt32)outBufferStride, (M4VIFI_UInt8 *)outBuffer);
|
| 1295 |
|
| 1296 | err = applyRenderingMode(planeIn, planeOut, mRenderingMode);
|
| 1297 | if(err != M4NO_ERROR) {
|
| 1298 | LOGE("doImageRenderingMode: applyRenderingMode returned err=0x%x", err);
|
| 1299 | }
|
| 1300 | return err;
|
| 1301 | }
|
| 1302 |
|
| 1303 | } //namespace android
|