PreviewPlayer.h revision 6e40775e3e797c81b865acfbb9e8e42bd6b90ac0
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 PREVIEW_PLAYER_H_
18
19#define PREVIEW_PLAYER_H_
20
21#include "TimedEventQueue.h"
22#include "VideoEditorAudioPlayer.h"
23
24#include <media/MediaPlayerInterface.h>
25#include <media/stagefright/DataSource.h>
26#include <media/stagefright/OMXClient.h>
27#include <media/stagefright/TimeSource.h>
28#include <utils/threads.h>
29#include "PreviewPlayerBase.h"
30#include "VideoEditorPreviewController.h"
31
32namespace android {
33
34struct AudioPlayerBase;
35struct DataSource;
36struct MediaBuffer;
37struct MediaExtractor;
38struct MediaSource;
39
40struct PreviewPlayer : public PreviewPlayerBase {
41    PreviewPlayer();
42    ~PreviewPlayer();
43
44    //Override baseclass methods
45    void reset();
46
47    status_t play();
48
49    status_t seekTo(int64_t timeUs);
50
51    status_t getVideoDimensions(int32_t *width, int32_t *height) const;
52
53    void acquireLock();
54    void releaseLock();
55
56    status_t prepare();
57    status_t setDataSource(
58        const char *uri, const KeyedVector<String8, String8> *headers);
59
60    //Added methods
61    status_t loadEffectsSettings(M4VSS3GPP_EffectSettings* pEffectSettings,
62                                 int nEffects);
63    status_t loadAudioMixSettings(M4xVSS_AudioMixingSettings* pAudioMixSettings);
64    status_t setAudioMixPCMFileHandle(M4OSA_Context pAudioMixPCMFileHandle);
65    status_t setAudioMixStoryBoardParam(M4OSA_UInt32 audioMixStoryBoardTS,
66                            M4OSA_UInt32 currentMediaBeginCutTime,
67                            M4OSA_UInt32 currentMediaVolumeVol);
68
69    status_t setPlaybackBeginTime(uint32_t msec);
70    status_t setPlaybackEndTime(uint32_t msec);
71    status_t setStoryboardStartTime(uint32_t msec);
72    status_t setProgressCallbackInterval(uint32_t cbInterval);
73    status_t setMediaRenderingMode(M4xVSS_MediaRendering mode,
74                            M4VIDEOEDITING_VideoFrameSize outputVideoSize);
75
76    status_t resetJniCallbackTimeStamp();
77    status_t setImageClipProperties(uint32_t width, uint32_t height);
78    status_t readFirstVideoFrame();
79    status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs);
80    status_t setAudioPlayer(AudioPlayerBase *audioPlayer);
81
82private:
83    friend struct PreviewPlayerEvent;
84
85    enum {
86        PLAYING             = 1,
87        LOOPING             = 2,
88        FIRST_FRAME         = 4,
89        PREPARING           = 8,
90        PREPARED            = 16,
91        AT_EOS              = 32,
92        PREPARE_CANCELLED   = 64,
93        CACHE_UNDERRUN      = 128,
94        AUDIO_AT_EOS        = 256,
95        VIDEO_AT_EOS        = 512,
96        AUTO_LOOPING        = 1024,
97    };
98
99    void cancelPlayerEvents(bool keepBufferingGoing = false);
100    status_t setDataSource_l(const sp<MediaExtractor> &extractor);
101    status_t setDataSource_l(
102        const char *uri, const KeyedVector<String8, String8> *headers);
103    void reset_l();
104    status_t play_l();
105    status_t initRenderer_l();
106    status_t initAudioDecoder();
107    status_t initVideoDecoder(uint32_t flags = 0);
108    void onVideoEvent();
109    void onStreamDone();
110    status_t finishSetDataSource_l();
111    static bool ContinuePreparation(void *cookie);
112    void onPrepareAsyncEvent();
113    void finishAsyncPrepare_l();
114    status_t startAudioPlayer_l();
115    bool mIsChangeSourceRequired;
116
117    PreviewRenderer *mVideoRenderer;
118
119    int32_t mVideoWidth, mVideoHeight;
120
121    MediaBuffer *mLastVideoBuffer;
122
123    //Data structures used for audio and video effects
124    M4VSS3GPP_EffectSettings* mEffectsSettings;
125    M4xVSS_AudioMixingSettings* mPreviewPlayerAudioMixSettings;
126    M4OSA_Context mAudioMixPCMFileHandle;
127    M4OSA_UInt32 mAudioMixStoryBoardTS;
128    M4OSA_UInt32 mCurrentMediaBeginCutTime;
129    M4OSA_UInt32 mCurrentMediaVolumeValue;
130    M4OSA_UInt32 mCurrFramingEffectIndex;
131
132    uint32_t mNumberEffects;
133    uint32_t mPlayBeginTimeMsec;
134    uint32_t mPlayEndTimeMsec;
135    uint64_t mDecodedVideoTs; // timestamp of current decoded video frame buffer
136    uint64_t mDecVideoTsStoryBoard; // timestamp of frame relative to storyboard
137    uint32_t mCurrentVideoEffect;
138    uint32_t mProgressCbInterval;
139    uint32_t mNumberDecVideoFrames; // Counter of number of video frames decoded
140    sp<TimedEventQueue::Event> mProgressCbEvent;
141    bool mProgressCbEventPending;
142    sp<TimedEventQueue::Event> mOverlayUpdateEvent;
143    bool mOverlayUpdateEventPending;
144    bool mOverlayUpdateEventPosted;
145
146    MediaBuffer *mResizedVideoBuffer;
147    bool mVideoResizedOrCropped;
148    M4xVSS_MediaRendering mRenderingMode;
149    uint32_t mOutputVideoWidth;
150    uint32_t mOutputVideoHeight;
151
152    int32_t mReportedWidth;  //docoder reported width
153    int32_t mReportedHeight; //docoder reported height
154
155    uint32_t mStoryboardStartTimeMsec;
156
157    bool mIsVideoSourceJpg;
158    bool mIsFiftiesEffectStarted;
159    int64_t mImageFrameTimeUs;
160    bool mStartNextPlayer;
161    mutable Mutex mLockControl;
162
163    M4VIFI_UInt8*  mFrameRGBBuffer;
164    M4VIFI_UInt8*  mFrameYUVBuffer;
165
166    void setVideoPostProcessingNode(
167                    M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable);
168    M4OSA_ERR doVideoPostProcessing();
169    M4OSA_ERR doMediaRendering();
170    void postProgressCallbackEvent_l();
171    void onProgressCbEvent();
172
173    void postOverlayUpdateEvent_l();
174    void onUpdateOverlayEvent();
175
176    status_t setDataSource_l_jpg();
177
178    status_t prepare_l();
179    status_t prepareAsync_l();
180
181    VideoEditorAudioPlayer  *mVeAudioPlayer;
182
183    PreviewPlayer(const PreviewPlayer &);
184    PreviewPlayer &operator=(const PreviewPlayer &);
185};
186
187}  // namespace android
188
189#endif  // PREVIEW_PLAYER_H_
190
191