blob: 1756f32f933874d2de7be07f35179e3175f02c22 [file] [log] [blame]
Chih-Chung Chang99698662011-06-30 14:21:38 +08001/*
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 Chang99698662011-06-30 14:21:38 +080020#include "VideoEditorPlayer.h"
Chih-Chung Chang99698662011-06-30 14:21:38 +080021#include "VideoEditorTools.h"
Chih-Chung Chang99698662011-06-30 14:21:38 +080022
23namespace android {
24
Chih-Chung Chang99698662011-06-30 14:21:38 +080025// Callback mechanism from PreviewController to Jni */
26typedef void (*jni_progress_callback_fct)(void* cookie, M4OSA_UInt32 msgType, void *argc);
27
James Dong3d2d40a2012-01-27 19:01:13 -080028struct Surface;
29struct PreviewRenderer;
Chih-Chung Chang99698662011-06-30 14:21:38 +080030
31class VideoEditorPreviewController {
32
33public:
34 VideoEditorPreviewController();
James Dong3d2d40a2012-01-27 19:01:13 -080035 ~VideoEditorPreviewController();
Chih-Chung Chang99698662011-06-30 14:21:38 +080036
James Dong3d2d40a2012-01-27 19:01:13 -080037 M4OSA_ERR loadEditSettings(
38 M4VSS3GPP_EditSettings* pSettings,
39 M4xVSS_AudioMixingSettings* bgmSettings);
Chih-Chung Chang99698662011-06-30 14:21:38 +080040
James Dong3d2d40a2012-01-27 19:01:13 -080041 M4OSA_ERR setSurface(const sp<Surface>& surface);
Chih-Chung Chang99698662011-06-30 14:21:38 +080042
James Dong3d2d40a2012-01-27 19:01:13 -080043 M4OSA_ERR startPreview(
44 M4OSA_UInt32 fromMS, M4OSA_Int32 toMs,
45 M4OSA_UInt16 callBackAfterFrameCount,
46 M4OSA_Bool loop) ;
Chih-Chung Chang99698662011-06-30 14:21:38 +080047
48 M4OSA_UInt32 stopPreview();
49
James Dong3d2d40a2012-01-27 19:01:13 -080050 M4OSA_ERR renderPreviewFrame(
51 const sp<Surface>& surface,
52 VideoEditor_renderPreviewFrameStr* pFrameInfo,
53 VideoEditorCurretEditInfo *pCurrEditInfo);
Chih-Chung Chang99698662011-06-30 14:21:38 +080054
James Dong3d2d40a2012-01-27 19:01:13 -080055 M4OSA_ERR clearSurface(
56 const sp<Surface>& surface,
57 VideoEditor_renderPreviewFrameStr* pFrameInfo);
Chih-Chung Chang99698662011-06-30 14:21:38 +080058
James Dong3d2d40a2012-01-27 19:01:13 -080059 M4OSA_Void setJniCallback(
60 void* cookie,
61 jni_progress_callback_fct callbackFct);
Chih-Chung Chang99698662011-06-30 14:21:38 +080062
James Dong3d2d40a2012-01-27 19:01:13 -080063 status_t setPreviewFrameRenderingMode(
64 M4xVSS_MediaRendering mode,
65 M4VIDEOEDITING_VideoFrameSize outputVideoSize);
Chih-Chung Chang99698662011-06-30 14:21:38 +080066
67private:
James Dong3d2d40a2012-01-27 19:01:13 -080068 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 Chang99698662011-06-30 14:21:38 +080086 sp<Surface> mSurface;
87 mutable Mutex mLock;
88 M4OSA_Context mThreadContext;
James Dong3d2d40a2012-01-27 19:01:13 -080089 PlayerState mPlayerState;
Chih-Chung Chang99698662011-06-30 14:21:38 +080090 M4OSA_Bool mPrepareReqest;
James Dong3d2d40a2012-01-27 19:01:13 -080091 M4VSS3GPP_ClipSettings **mClipList;
Chih-Chung Chang99698662011-06-30 14:21:38 +080092 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 Chang43fcc392011-08-02 16:17:39 +0800126 NativeWindowRenderer* mNativeWindowRenderer;
Chih-Chung Chang99698662011-06-30 14:21:38 +0800127
128 M4VIFI_UInt8* mFrameRGBBuffer;
129 M4VIFI_UInt8* mFrameYUVBuffer;
130 mutable Mutex mLockSem;
James Dong3d2d40a2012-01-27 19:01:13 -0800131
132
Chih-Chung Chang99698662011-06-30 14:21:38 +0800133 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 Dong3d2d40a2012-01-27 19:01:13 -0800139 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 Chang99698662011-06-30 14:21:38 +0800143
James Dong3d2d40a2012-01-27 19:01:13 -0800144 M4OSA_ERR doImageRenderingMode(
145 M4OSA_Void * dataPtr,
146 M4OSA_UInt32 colorFormat, M4OSA_UInt32 videoWidth,
147 M4OSA_UInt32 videoHeight, M4OSA_Void* outPtr);
Chih-Chung Chang99698662011-06-30 14:21:38 +0800148
James Dong3d2d40a2012-01-27 19:01:13 -0800149 // Don't call me!
Chih-Chung Chang99698662011-06-30 14:21:38 +0800150 VideoEditorPreviewController(const VideoEditorPreviewController &);
James Dong3d2d40a2012-01-27 19:01:13 -0800151 VideoEditorPreviewController &operator=(
152 const VideoEditorPreviewController &);
Chih-Chung Chang99698662011-06-30 14:21:38 +0800153};
154
155}
156
James Dong3d2d40a2012-01-27 19:01:13 -0800157#endif // ANDROID_VE_PREVIEWCONTROLLER_H