blob: fd2e6d28f9eb28f948c8896415298e876346d4ea [file] [log] [blame]
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001/*
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08002 * 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
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080021#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>
James Dongc9dedc42011-05-01 12:36:22 -070029#include "PreviewPlayerBase.h"
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080030#include "VideoEditorPreviewController.h"
31
32namespace android {
33
James Dongc9dedc42011-05-01 12:36:22 -070034struct AudioPlayerBase;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080035struct DataSource;
36struct MediaBuffer;
37struct MediaExtractor;
38struct MediaSource;
39
James Dongc9dedc42011-05-01 12:36:22 -070040struct PreviewPlayer : public PreviewPlayerBase {
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080041 PreviewPlayer();
42 ~PreviewPlayer();
43
44 //Override baseclass methods
45 void reset();
46
47 status_t play();
48
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080049 status_t seekTo(int64_t timeUs);
50
51 status_t getVideoDimensions(int32_t *width, int32_t *height) const;
52
Raghavender Pallafa31daf2011-03-18 22:32:51 -070053 void acquireLock();
54 void releaseLock();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080055
56 status_t prepare();
57 status_t setDataSource(
58 const char *uri, const KeyedVector<String8, String8> *headers);
59
60 //Added methods
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -080061 status_t loadEffectsSettings(M4VSS3GPP_EffectSettings* pEffectSettings,
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080062 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();
Santosh Madhavab2d6e0f2011-02-16 22:24:42 -080079 status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs);
James Dongc9dedc42011-05-01 12:36:22 -070080 status_t setAudioPlayer(AudioPlayerBase *audioPlayer);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080081
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
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080099 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();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800104 status_t play_l();
Santosh Madhavabfece172011-02-03 16:59:47 -0800105 status_t initRenderer_l();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800106 status_t initAudioDecoder();
107 status_t initVideoDecoder(uint32_t flags = 0);
108 void onVideoEvent();
Rajneesh Chowdury1c97d9a2011-02-21 15:43:33 -0800109 void onStreamDone();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800110 status_t finishSetDataSource_l();
111 static bool ContinuePreparation(void *cookie);
112 void onPrepareAsyncEvent();
113 void finishAsyncPrepare_l();
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800114 status_t startAudioPlayer_l();
Rajneesh Chowdury1c97d9a2011-02-21 15:43:33 -0800115 bool mIsChangeSourceRequired;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800116
Chih-Chung Change048e902011-08-01 12:15:59 +0800117 PreviewRenderer *mVideoRenderer;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800118
119 int32_t mVideoWidth, mVideoHeight;
120
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800121 //Data structures used for audio and video effects
122 M4VSS3GPP_EffectSettings* mEffectsSettings;
123 M4xVSS_AudioMixingSettings* mPreviewPlayerAudioMixSettings;
124 M4OSA_Context mAudioMixPCMFileHandle;
125 M4OSA_UInt32 mAudioMixStoryBoardTS;
126 M4OSA_UInt32 mCurrentMediaBeginCutTime;
127 M4OSA_UInt32 mCurrentMediaVolumeValue;
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800128 M4OSA_UInt32 mCurrFramingEffectIndex;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800129
130 uint32_t mNumberEffects;
131 uint32_t mPlayBeginTimeMsec;
132 uint32_t mPlayEndTimeMsec;
133 uint64_t mDecodedVideoTs; // timestamp of current decoded video frame buffer
134 uint64_t mDecVideoTsStoryBoard; // timestamp of frame relative to storyboard
135 uint32_t mCurrentVideoEffect;
136 uint32_t mProgressCbInterval;
137 uint32_t mNumberDecVideoFrames; // Counter of number of video frames decoded
138 sp<TimedEventQueue::Event> mProgressCbEvent;
139 bool mProgressCbEventPending;
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800140 sp<TimedEventQueue::Event> mOverlayUpdateEvent;
141 bool mOverlayUpdateEventPending;
142 bool mOverlayUpdateEventPosted;
143
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800144 MediaBuffer *mResizedVideoBuffer;
145 bool mVideoResizedOrCropped;
146 M4xVSS_MediaRendering mRenderingMode;
147 uint32_t mOutputVideoWidth;
148 uint32_t mOutputVideoHeight;
149
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -0800150 int32_t mReportedWidth; //docoder reported width
151 int32_t mReportedHeight; //docoder reported height
152
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800153 uint32_t mStoryboardStartTimeMsec;
154
155 bool mIsVideoSourceJpg;
156 bool mIsFiftiesEffectStarted;
157 int64_t mImageFrameTimeUs;
158 bool mStartNextPlayer;
Raghavender Pallafa31daf2011-03-18 22:32:51 -0700159 mutable Mutex mLockControl;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800160
161 M4VIFI_UInt8* mFrameRGBBuffer;
162 M4VIFI_UInt8* mFrameYUVBuffer;
163
164 void setVideoPostProcessingNode(
165 M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable);
166 M4OSA_ERR doVideoPostProcessing();
167 M4OSA_ERR doMediaRendering();
168 void postProgressCallbackEvent_l();
169 void onProgressCbEvent();
170
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800171 void postOverlayUpdateEvent_l();
172 void onUpdateOverlayEvent();
173
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800174 status_t setDataSource_l_jpg();
175
176 status_t prepare_l();
177 status_t prepareAsync_l();
178
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800179 VideoEditorAudioPlayer *mVeAudioPlayer;
180
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800181 PreviewPlayer(const PreviewPlayer &);
182 PreviewPlayer &operator=(const PreviewPlayer &);
183};
184
185} // namespace android
186
187#endif // PREVIEW_PLAYER_H_
188