Home | History | Annotate | Download | only in lvpp
      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 
     20 #include "VideoEditorPlayer.h"
     21 #include "VideoEditorTools.h"
     22 
     23 namespace android {
     24 
     25 // Callback mechanism from PreviewController to Jni  */
     26 typedef void (*jni_progress_callback_fct)(void* cookie, M4OSA_UInt32 msgType, void *argc);
     27 
     28 struct Surface;
     29 struct PreviewRenderer;
     30 
     31 class VideoEditorPreviewController {
     32 
     33 public:
     34     VideoEditorPreviewController();
     35     ~VideoEditorPreviewController();
     36 
     37     M4OSA_ERR loadEditSettings(
     38             M4VSS3GPP_EditSettings* pSettings,
     39             M4xVSS_AudioMixingSettings* bgmSettings);
     40 
     41     M4OSA_ERR setSurface(const sp<Surface>& surface);
     42 
     43     M4OSA_ERR startPreview(
     44             M4OSA_UInt32 fromMS, M4OSA_Int32 toMs,
     45             M4OSA_UInt16 callBackAfterFrameCount,
     46             M4OSA_Bool loop) ;
     47 
     48     M4OSA_UInt32 stopPreview();
     49 
     50     M4OSA_ERR renderPreviewFrame(
     51             const sp<Surface>& surface,
     52             VideoEditor_renderPreviewFrameStr* pFrameInfo,
     53             VideoEditorCurretEditInfo *pCurrEditInfo);
     54 
     55     M4OSA_ERR clearSurface(
     56             const sp<Surface>& surface,
     57             VideoEditor_renderPreviewFrameStr* pFrameInfo);
     58 
     59     M4OSA_Void setJniCallback(
     60             void* cookie,
     61             jni_progress_callback_fct callbackFct);
     62 
     63     status_t setPreviewFrameRenderingMode(
     64             M4xVSS_MediaRendering mode,
     65             M4VIDEOEDITING_VideoFrameSize outputVideoSize);
     66 
     67 private:
     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
     86     sp<Surface>  mSurface;
     87     mutable Mutex mLock;
     88     M4OSA_Context mThreadContext;
     89     PlayerState mPlayerState;
     90     M4OSA_Bool    mPrepareReqest;
     91     M4VSS3GPP_ClipSettings **mClipList;
     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;
    126     NativeWindowRenderer* mNativeWindowRenderer;
    127 
    128     M4VIFI_UInt8*  mFrameRGBBuffer;
    129     M4VIFI_UInt8*  mFrameYUVBuffer;
    130     mutable Mutex mLockSem;
    131 
    132 
    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 
    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);
    143 
    144     M4OSA_ERR doImageRenderingMode(
    145             M4OSA_Void * dataPtr,
    146             M4OSA_UInt32 colorFormat, M4OSA_UInt32 videoWidth,
    147             M4OSA_UInt32 videoHeight, M4OSA_Void* outPtr);
    148 
    149     // Don't call me!
    150     VideoEditorPreviewController(const VideoEditorPreviewController &);
    151     VideoEditorPreviewController &operator=(
    152             const VideoEditorPreviewController &);
    153 };
    154 
    155 }
    156 
    157 #endif // ANDROID_VE_PREVIEWCONTROLLER_H
    158