Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | #ifndef ANDROID_VE_PREVIEWCONTROLLER_H |
| 18 | #define ANDROID_VE_PREVIEWCONTROLLER_H |
| 19 | |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 20 | #include "VideoEditorPlayer.h" |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 21 | #include "VideoEditorTools.h" |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 25 | // Callback mechanism from PreviewController to Jni */ |
| 26 | typedef void (*jni_progress_callback_fct)(void* cookie, M4OSA_UInt32 msgType, void *argc); |
| 27 | |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 28 | struct Surface; |
| 29 | struct PreviewRenderer; |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 30 | |
| 31 | class VideoEditorPreviewController { |
| 32 | |
| 33 | public: |
| 34 | VideoEditorPreviewController(); |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 35 | ~VideoEditorPreviewController(); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 36 | |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 37 | M4OSA_ERR loadEditSettings( |
| 38 | M4VSS3GPP_EditSettings* pSettings, |
| 39 | M4xVSS_AudioMixingSettings* bgmSettings); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 40 | |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 41 | M4OSA_ERR setSurface(const sp<Surface>& surface); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 42 | |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 43 | M4OSA_ERR startPreview( |
| 44 | M4OSA_UInt32 fromMS, M4OSA_Int32 toMs, |
| 45 | M4OSA_UInt16 callBackAfterFrameCount, |
| 46 | M4OSA_Bool loop) ; |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 47 | |
| 48 | M4OSA_UInt32 stopPreview(); |
| 49 | |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 50 | M4OSA_ERR renderPreviewFrame( |
| 51 | const sp<Surface>& surface, |
| 52 | VideoEditor_renderPreviewFrameStr* pFrameInfo, |
| 53 | VideoEditorCurretEditInfo *pCurrEditInfo); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 54 | |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 55 | M4OSA_ERR clearSurface( |
| 56 | const sp<Surface>& surface, |
| 57 | VideoEditor_renderPreviewFrameStr* pFrameInfo); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 58 | |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 59 | M4OSA_Void setJniCallback( |
| 60 | void* cookie, |
| 61 | jni_progress_callback_fct callbackFct); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 62 | |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 63 | status_t setPreviewFrameRenderingMode( |
| 64 | M4xVSS_MediaRendering mode, |
| 65 | M4VIDEOEDITING_VideoFrameSize outputVideoSize); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 66 | |
| 67 | private: |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 68 | enum { |
| 69 | kTotalNumPlayerInstances = 2, |
| 70 | kPreviewThreadStackSize = 65536, |
| 71 | }; |
| 72 | |
| 73 | typedef enum { |
| 74 | VePlayerIdle = 0, |
| 75 | VePlayerBusy, |
| 76 | VePlayerAutoStop |
| 77 | } PlayerState; |
| 78 | |
| 79 | typedef enum { |
| 80 | OVERLAY_UPDATE = 0, |
| 81 | OVERLAY_CLEAR |
| 82 | } OverlayState; |
| 83 | |
| 84 | sp<VideoEditorPlayer> mVePlayer[kTotalNumPlayerInstances]; |
| 85 | int mCurrentPlayer; // player instance currently being used |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 86 | sp<Surface> mSurface; |
| 87 | mutable Mutex mLock; |
| 88 | M4OSA_Context mThreadContext; |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 89 | PlayerState mPlayerState; |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 90 | M4OSA_Bool mPrepareReqest; |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 91 | M4VSS3GPP_ClipSettings **mClipList; |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 92 | M4OSA_UInt32 mNumberClipsInStoryBoard; |
| 93 | M4OSA_UInt32 mNumberClipsToPreview; |
| 94 | M4OSA_UInt32 mStartingClipIndex; |
| 95 | M4OSA_Bool mPreviewLooping; |
| 96 | M4OSA_UInt32 mCallBackAfterFrameCnt; |
| 97 | M4VSS3GPP_EffectSettings* mEffectsSettings; |
| 98 | M4OSA_UInt32 mNumberEffects; |
| 99 | M4OSA_Int32 mCurrentClipNumber; |
| 100 | M4OSA_UInt32 mClipTotalDuration; |
| 101 | M4OSA_UInt32 mCurrentVideoEffect; |
| 102 | M4xVSS_AudioMixingSettings* mBackgroundAudioSetting; |
| 103 | M4OSA_Context mAudioMixPCMFileHandle; |
| 104 | PreviewRenderer *mTarget; |
| 105 | M4OSA_Context mJniCookie; |
| 106 | jni_progress_callback_fct mJniCallback; |
| 107 | VideoEditor_renderPreviewFrameStr mFrameStr; |
| 108 | M4OSA_UInt32 mCurrentPlayedDuration; |
| 109 | M4OSA_UInt32 mCurrentClipDuration; |
| 110 | M4VIDEOEDITING_VideoFrameSize mOutputVideoSize; |
| 111 | M4OSA_UInt32 mFirstPreviewClipBeginTime; |
| 112 | M4OSA_UInt32 mLastPreviewClipEndTime; |
| 113 | M4OSA_UInt32 mVideoStoryBoardTimeMsUptoFirstPreviewClip; |
| 114 | OverlayState mOverlayState; |
| 115 | int mActivePlayerIndex; |
| 116 | |
| 117 | M4xVSS_MediaRendering mRenderingMode; |
| 118 | uint32_t mOutputVideoWidth; |
| 119 | uint32_t mOutputVideoHeight; |
| 120 | bool bStopThreadInProgress; |
| 121 | M4OSA_Context mSemThreadWait; |
| 122 | bool mIsFiftiesEffectStarted; |
| 123 | |
| 124 | sp<VideoEditorPlayer::VeAudioOutput> mVEAudioSink; |
| 125 | VideoEditorAudioPlayer *mVEAudioPlayer; |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 126 | NativeWindowRenderer* mNativeWindowRenderer; |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 127 | |
| 128 | M4VIFI_UInt8* mFrameRGBBuffer; |
| 129 | M4VIFI_UInt8* mFrameYUVBuffer; |
| 130 | mutable Mutex mLockSem; |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 131 | |
| 132 | |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 133 | static M4OSA_ERR preparePlayer(void* param, int playerInstance, int index); |
| 134 | static M4OSA_ERR threadProc(M4OSA_Void* param); |
| 135 | static void notify(void* cookie, int msg, int ext1, int ext2); |
| 136 | |
| 137 | void setVideoEffectType(M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable); |
| 138 | |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 139 | M4OSA_ERR applyVideoEffect( |
| 140 | M4OSA_Void * dataPtr, M4OSA_UInt32 colorFormat, |
| 141 | M4OSA_UInt32 videoWidth, M4OSA_UInt32 videoHeight, |
| 142 | M4OSA_UInt32 timeMs, M4OSA_Void* outPtr); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 143 | |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 144 | M4OSA_ERR doImageRenderingMode( |
| 145 | M4OSA_Void * dataPtr, |
| 146 | M4OSA_UInt32 colorFormat, M4OSA_UInt32 videoWidth, |
| 147 | M4OSA_UInt32 videoHeight, M4OSA_Void* outPtr); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 148 | |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 149 | // Don't call me! |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 150 | VideoEditorPreviewController(const VideoEditorPreviewController &); |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 151 | VideoEditorPreviewController &operator=( |
| 152 | const VideoEditorPreviewController &); |
Chih-Chung Chang | 9969866 | 2011-06-30 14:21:38 +0800 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | } |
| 156 | |
James Dong | 3d2d40a | 2012-01-27 19:01:13 -0800 | [diff] [blame] | 157 | #endif // ANDROID_VE_PREVIEWCONTROLLER_H |