blob: 5828c5f63bcf73ef5eda02fdbfb5feb672dd1a46 [file] [log] [blame]
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001/*
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#ifndef ANDROID_VE_PREVIEWCONTROLLER_H
19#define ANDROID_VE_PREVIEWCONTROLLER_H
20
21#include <utils/Log.h>
22#include "VideoEditorPlayer.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
46namespace android {
47
48typedef enum {
49 VePlayerIdle=0,
50 VePlayerBusy,
51 VePlayerAutoStop
52} VePlayerState;
53
54
55// Callback mechanism from PreviewController to Jni */
56typedef void (*jni_progress_callback_fct)(void* cookie, M4OSA_UInt32 msgType, M4OSA_UInt32 argc);
57
58class VideoEditorPreviewController {
59
60public:
61 VideoEditorPreviewController();
62 virtual ~VideoEditorPreviewController();
63
64 M4OSA_ERR loadEditSettings(M4VSS3GPP_EditSettings* pSettings,
65 M4xVSS_AudioMixingSettings* bgmSettings);
66
67 M4OSA_ERR setSurface(const sp<Surface> &surface);
68
69 M4OSA_ERR startPreview(M4OSA_UInt32 fromMS, M4OSA_Int32 toMs,
70 M4OSA_UInt16 callBackAfterFrameCount, M4OSA_Bool loop) ;
71
72 M4OSA_ERR stopPreview();
73
74 M4OSA_ERR renderPreviewFrame(const sp<Surface> &surface,
75 VideoEditor_renderPreviewFrameStr* pFrameInfo);
76
Dheeraj Sharma9ec356a2011-01-24 15:02:18 -080077 M4OSA_ERR clearSurface(const sp<Surface> &surface,
78 VideoEditor_renderPreviewFrameStr* pFrameInfo);
79
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080080 M4OSA_Void setJniCallback(void* cookie,
81 jni_progress_callback_fct callbackFct);
82
83 M4OSA_ERR setPreviewFrameRenderingMode(M4xVSS_MediaRendering mode,
84 M4VIDEOEDITING_VideoFrameSize outputVideoSize);
85
86private:
87 sp<VideoEditorPlayer> mVePlayer[NBPLAYER_INSTANCES];
88 int mCurrentPlayer; //Instance of the player currently being used
89 sp<ISurface> mISurface;
90 sp<Surface> mSurface;
91 mutable Mutex mLock;
92 M4OSA_Context mThreadContext;
93 VePlayerState mPlayerState;
94 M4VSS3GPP_ClipSettings **mClipList; //Pointer to an array of clip settings
95 M4OSA_UInt32 mNumberClipsInStoryBoard;
96 M4OSA_UInt32 mNumberClipsToPreview;
97 M4OSA_UInt32 mStartingClipIndex;
98 M4OSA_Bool mPreviewLooping;
99 M4OSA_UInt32 mCallBackAfterFrameCnt;
100 M4VSS3GPP_EffectSettings* mEffectsSettings;
101 M4OSA_UInt32 mNumberEffects;
102 M4OSA_Int32 mCurrentClipNumber;
103 M4OSA_UInt32 mClipTotalDuration;
104 M4OSA_UInt32 mCurrentVideoEffect;
105 M4xVSS_AudioMixingSettings* mBackgroundAudioSetting;
106 M4OSA_Context mAudioMixPCMFileHandle;
107 PreviewRenderer *mTarget;
108 M4OSA_Context mJniCookie;
109 jni_progress_callback_fct mJniCallback;
110 VideoEditor_renderPreviewFrameStr mFrameStr;
111 M4OSA_UInt32 mCurrentPlayedDuration;
112 M4OSA_UInt32 mCurrentClipDuration;
113 M4VIDEOEDITING_VideoFrameSize mOutputVideoSize;
114 M4OSA_UInt32 mFirstPreviewClipBeginTime;
115 M4OSA_UInt32 mLastPreviewClipEndTime;
116 M4OSA_UInt32 mVideoStoryBoardTimeMsUptoFirstPreviewClip;
117
118 M4xVSS_MediaRendering mRenderingMode;
119 uint32_t mOutputVideoWidth;
120 uint32_t mOutputVideoHeight;
121 bool bStopThreadInProgress;
122 M4OSA_Context mSemThreadWait;
123 bool mIsFiftiesEffectStarted;
124
125 M4VIFI_UInt8* mFrameRGBBuffer;
126 M4VIFI_UInt8* mFrameYUVBuffer;
127 static M4OSA_ERR preparePlayer(void* param, int playerInstance, int index);
128 static M4OSA_ERR threadProc(M4OSA_Void* param);
129 static void notify(void* cookie, int msg, int ext1, int ext2);
130
131 void setVideoEffectType(M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable);
132
133 M4OSA_ERR applyVideoEffect(M4OSA_Void * dataPtr, M4OSA_UInt32 colorFormat,
134 M4OSA_UInt32 videoWidth, M4OSA_UInt32 videoHeight,
135 M4OSA_UInt32 timeMs, M4OSA_Void* outPtr);
136
137 M4OSA_ERR doImageRenderingMode(M4OSA_Void * dataPtr,
138 M4OSA_UInt32 colorFormat, M4OSA_UInt32 videoWidth,
139 M4OSA_UInt32 videoHeight, M4OSA_Void* outPtr);
140
141 VideoEditorPreviewController(const VideoEditorPreviewController &);
142 VideoEditorPreviewController &operator=(const VideoEditorPreviewController &);
143};
144
145}
146
147#endif //ANDROID_VE_PREVIEWCONTROLLER_H