summaryrefslogtreecommitdiffstats
path: root/libvideoeditor/lvpp/VideoEditorPreviewController.h
blob: 1756f32f933874d2de7be07f35179e3175f02c22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_VE_PREVIEWCONTROLLER_H
#define ANDROID_VE_PREVIEWCONTROLLER_H

#include "VideoEditorPlayer.h"
#include "VideoEditorTools.h"

namespace android {

// Callback mechanism from PreviewController to Jni  */
typedef void (*jni_progress_callback_fct)(void* cookie, M4OSA_UInt32 msgType, void *argc);

struct Surface;
struct PreviewRenderer;

class VideoEditorPreviewController {

public:
    VideoEditorPreviewController();
    ~VideoEditorPreviewController();

    M4OSA_ERR loadEditSettings(
            M4VSS3GPP_EditSettings* pSettings,
            M4xVSS_AudioMixingSettings* bgmSettings);

    M4OSA_ERR setSurface(const sp<Surface>& surface);

    M4OSA_ERR startPreview(
            M4OSA_UInt32 fromMS, M4OSA_Int32 toMs,
            M4OSA_UInt16 callBackAfterFrameCount,
            M4OSA_Bool loop) ;

    M4OSA_UInt32 stopPreview();

    M4OSA_ERR renderPreviewFrame(
            const sp<Surface>& surface,
            VideoEditor_renderPreviewFrameStr* pFrameInfo,
            VideoEditorCurretEditInfo *pCurrEditInfo);

    M4OSA_ERR clearSurface(
            const sp<Surface>& surface,
            VideoEditor_renderPreviewFrameStr* pFrameInfo);

    M4OSA_Void setJniCallback(
            void* cookie,
            jni_progress_callback_fct callbackFct);

    status_t setPreviewFrameRenderingMode(
            M4xVSS_MediaRendering mode,
            M4VIDEOEDITING_VideoFrameSize outputVideoSize);

private:
    enum {
        kTotalNumPlayerInstances = 2,
        kPreviewThreadStackSize = 65536,
    };

    typedef enum {
        VePlayerIdle = 0,
        VePlayerBusy,
        VePlayerAutoStop
    } PlayerState;

    typedef enum {
        OVERLAY_UPDATE = 0,
        OVERLAY_CLEAR
    } OverlayState;

    sp<VideoEditorPlayer> mVePlayer[kTotalNumPlayerInstances];
    int mCurrentPlayer;  // player instance currently being used
    sp<Surface>  mSurface;
    mutable Mutex mLock;
    M4OSA_Context mThreadContext;
    PlayerState mPlayerState;
    M4OSA_Bool    mPrepareReqest;
    M4VSS3GPP_ClipSettings **mClipList;
    M4OSA_UInt32 mNumberClipsInStoryBoard;
    M4OSA_UInt32 mNumberClipsToPreview;
    M4OSA_UInt32 mStartingClipIndex;
    M4OSA_Bool mPreviewLooping;
    M4OSA_UInt32 mCallBackAfterFrameCnt;
    M4VSS3GPP_EffectSettings* mEffectsSettings;
    M4OSA_UInt32 mNumberEffects;
    M4OSA_Int32 mCurrentClipNumber;
    M4OSA_UInt32 mClipTotalDuration;
    M4OSA_UInt32 mCurrentVideoEffect;
    M4xVSS_AudioMixingSettings* mBackgroundAudioSetting;
    M4OSA_Context mAudioMixPCMFileHandle;
    PreviewRenderer *mTarget;
    M4OSA_Context mJniCookie;
    jni_progress_callback_fct mJniCallback;
    VideoEditor_renderPreviewFrameStr mFrameStr;
    M4OSA_UInt32 mCurrentPlayedDuration;
    M4OSA_UInt32 mCurrentClipDuration;
    M4VIDEOEDITING_VideoFrameSize mOutputVideoSize;
    M4OSA_UInt32 mFirstPreviewClipBeginTime;
    M4OSA_UInt32 mLastPreviewClipEndTime;
    M4OSA_UInt32 mVideoStoryBoardTimeMsUptoFirstPreviewClip;
    OverlayState mOverlayState;
    int mActivePlayerIndex;

    M4xVSS_MediaRendering mRenderingMode;
    uint32_t mOutputVideoWidth;
    uint32_t mOutputVideoHeight;
    bool bStopThreadInProgress;
    M4OSA_Context mSemThreadWait;
    bool mIsFiftiesEffectStarted;

    sp<VideoEditorPlayer::VeAudioOutput> mVEAudioSink;
    VideoEditorAudioPlayer *mVEAudioPlayer;
    NativeWindowRenderer* mNativeWindowRenderer;

    M4VIFI_UInt8*  mFrameRGBBuffer;
    M4VIFI_UInt8*  mFrameYUVBuffer;
    mutable Mutex mLockSem;


    static M4OSA_ERR preparePlayer(void* param, int playerInstance, int index);
    static M4OSA_ERR threadProc(M4OSA_Void* param);
    static void notify(void* cookie, int msg, int ext1, int ext2);

    void setVideoEffectType(M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable);

    M4OSA_ERR applyVideoEffect(
            M4OSA_Void * dataPtr, M4OSA_UInt32 colorFormat,
            M4OSA_UInt32 videoWidth, M4OSA_UInt32 videoHeight,
            M4OSA_UInt32 timeMs, M4OSA_Void* outPtr);

    M4OSA_ERR doImageRenderingMode(
            M4OSA_Void * dataPtr,
            M4OSA_UInt32 colorFormat, M4OSA_UInt32 videoWidth,
            M4OSA_UInt32 videoHeight, M4OSA_Void* outPtr);

    // Don't call me!
    VideoEditorPreviewController(const VideoEditorPreviewController &);
    VideoEditorPreviewController &operator=(
            const VideoEditorPreviewController &);
};

}

#endif // ANDROID_VE_PREVIEWCONTROLLER_H