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