blob: 0800115b519630fd4af375be6b8d08873c0ac0b1 [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 PREVIEW_PLAYER_H_
19
20#define PREVIEW_PLAYER_H_
21
22#include "NuHTTPDataSource.h"
23#include "TimedEventQueue.h"
24#include "VideoEditorAudioPlayer.h"
25
26#include <media/MediaPlayerInterface.h>
27#include <media/stagefright/DataSource.h>
28#include <media/stagefright/OMXClient.h>
29#include <media/stagefright/TimeSource.h>
30#include <utils/threads.h>
31#include <AwesomePlayer.h>
32#include "VideoEditorPreviewController.h"
33
34namespace android {
35
36struct AudioPlayer;
37struct DataSource;
38struct MediaBuffer;
39struct MediaExtractor;
40struct MediaSource;
41
42struct PreviewPlayerRenderer : public RefBase {
43 PreviewPlayerRenderer() {}
44
45 virtual void render(MediaBuffer *buffer) = 0;
46 virtual void render() = 0;
47 virtual void getBuffer(uint8_t **data, size_t *stride) = 0;
48
49private:
50 PreviewPlayerRenderer(const PreviewPlayerRenderer &);
51 PreviewPlayerRenderer &operator=(const PreviewPlayerRenderer &);
52};
53
54struct PreviewPlayer : public AwesomePlayer {
55 PreviewPlayer();
56 ~PreviewPlayer();
57
58 //Override baseclass methods
59 void reset();
60
61 status_t play();
62
63 void setISurface(const sp<ISurface> &isurface);
64
65 status_t seekTo(int64_t timeUs);
66
67 status_t getVideoDimensions(int32_t *width, int32_t *height) const;
68
69 status_t suspend();
70 status_t resume();
71
72 status_t prepare();
73 status_t setDataSource(
74 const char *uri, const KeyedVector<String8, String8> *headers);
75
76 //Added methods
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -080077 status_t loadEffectsSettings(M4VSS3GPP_EffectSettings* pEffectSettings,
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080078 int nEffects);
79 status_t loadAudioMixSettings(M4xVSS_AudioMixingSettings* pAudioMixSettings);
80 status_t setAudioMixPCMFileHandle(M4OSA_Context pAudioMixPCMFileHandle);
81 status_t setAudioMixStoryBoardParam(M4OSA_UInt32 audioMixStoryBoardTS,
82 M4OSA_UInt32 currentMediaBeginCutTime,
83 M4OSA_UInt32 currentMediaVolumeVol);
84
85 status_t setPlaybackBeginTime(uint32_t msec);
86 status_t setPlaybackEndTime(uint32_t msec);
87 status_t setStoryboardStartTime(uint32_t msec);
88 status_t setProgressCallbackInterval(uint32_t cbInterval);
89 status_t setMediaRenderingMode(M4xVSS_MediaRendering mode,
90 M4VIDEOEDITING_VideoFrameSize outputVideoSize);
91
92 status_t resetJniCallbackTimeStamp();
93 status_t setImageClipProperties(uint32_t width, uint32_t height);
94 status_t readFirstVideoFrame();
Santosh Madhavab2d6e0f2011-02-16 22:24:42 -080095 status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs);
Rajneesh Chowdury1c97d9a2011-02-21 15:43:33 -080096 status_t setAudioPlayer(AudioPlayer *audioPlayer);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080097
98private:
99 friend struct PreviewPlayerEvent;
100
101 enum {
102 PLAYING = 1,
103 LOOPING = 2,
104 FIRST_FRAME = 4,
105 PREPARING = 8,
106 PREPARED = 16,
107 AT_EOS = 32,
108 PREPARE_CANCELLED = 64,
109 CACHE_UNDERRUN = 128,
110 AUDIO_AT_EOS = 256,
111 VIDEO_AT_EOS = 512,
112 AUTO_LOOPING = 1024,
113 };
114
115 sp<ISurface> mISurface;
116
117 void cancelPlayerEvents(bool keepBufferingGoing = false);
118 status_t setDataSource_l(const sp<MediaExtractor> &extractor);
119 status_t setDataSource_l(
120 const char *uri, const KeyedVector<String8, String8> *headers);
121 void reset_l();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800122 status_t play_l();
Santosh Madhavabfece172011-02-03 16:59:47 -0800123 status_t initRenderer_l();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800124 status_t initAudioDecoder();
125 status_t initVideoDecoder(uint32_t flags = 0);
126 void onVideoEvent();
Rajneesh Chowdury1c97d9a2011-02-21 15:43:33 -0800127 void onStreamDone();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800128 status_t finishSetDataSource_l();
129 static bool ContinuePreparation(void *cookie);
130 void onPrepareAsyncEvent();
131 void finishAsyncPrepare_l();
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800132 status_t startAudioPlayer_l();
Rajneesh Chowdury1c97d9a2011-02-21 15:43:33 -0800133 bool mIsChangeSourceRequired;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800134
135 sp<PreviewPlayerRenderer> mVideoRenderer;
136
137 int32_t mVideoWidth, mVideoHeight;
138
139 MediaBuffer *mLastVideoBuffer;
140
141 struct SuspensionState {
142 String8 mUri;
143 KeyedVector<String8, String8> mUriHeaders;
144 sp<DataSource> mFileSource;
145
146 uint32_t mFlags;
147 int64_t mPositionUs;
148
149 void *mLastVideoFrame;
150 size_t mLastVideoFrameSize;
151 int32_t mColorFormat;
152 int32_t mVideoWidth, mVideoHeight;
153 int32_t mDecodedWidth, mDecodedHeight;
154
155 SuspensionState()
156 : mLastVideoFrame(NULL) {
157 }
158
159 ~SuspensionState() {
160 if (mLastVideoFrame) {
161 free(mLastVideoFrame);
162 mLastVideoFrame = NULL;
163 }
164 }
165 } *mSuspensionState;
166
167 //Data structures used for audio and video effects
168 M4VSS3GPP_EffectSettings* mEffectsSettings;
169 M4xVSS_AudioMixingSettings* mPreviewPlayerAudioMixSettings;
170 M4OSA_Context mAudioMixPCMFileHandle;
171 M4OSA_UInt32 mAudioMixStoryBoardTS;
172 M4OSA_UInt32 mCurrentMediaBeginCutTime;
173 M4OSA_UInt32 mCurrentMediaVolumeValue;
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800174 M4OSA_UInt32 mCurrFramingEffectIndex;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800175
176 uint32_t mNumberEffects;
177 uint32_t mPlayBeginTimeMsec;
178 uint32_t mPlayEndTimeMsec;
179 uint64_t mDecodedVideoTs; // timestamp of current decoded video frame buffer
180 uint64_t mDecVideoTsStoryBoard; // timestamp of frame relative to storyboard
181 uint32_t mCurrentVideoEffect;
182 uint32_t mProgressCbInterval;
183 uint32_t mNumberDecVideoFrames; // Counter of number of video frames decoded
184 sp<TimedEventQueue::Event> mProgressCbEvent;
185 bool mProgressCbEventPending;
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800186 sp<TimedEventQueue::Event> mOverlayUpdateEvent;
187 bool mOverlayUpdateEventPending;
188 bool mOverlayUpdateEventPosted;
189
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800190 MediaBuffer *mResizedVideoBuffer;
191 bool mVideoResizedOrCropped;
192 M4xVSS_MediaRendering mRenderingMode;
193 uint32_t mOutputVideoWidth;
194 uint32_t mOutputVideoHeight;
195
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -0800196 int32_t mReportedWidth; //docoder reported width
197 int32_t mReportedHeight; //docoder reported height
198
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800199 uint32_t mStoryboardStartTimeMsec;
200
201 bool mIsVideoSourceJpg;
202 bool mIsFiftiesEffectStarted;
203 int64_t mImageFrameTimeUs;
204 bool mStartNextPlayer;
205
206 M4VIFI_UInt8* mFrameRGBBuffer;
207 M4VIFI_UInt8* mFrameYUVBuffer;
208
209 void setVideoPostProcessingNode(
210 M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable);
211 M4OSA_ERR doVideoPostProcessing();
212 M4OSA_ERR doMediaRendering();
213 void postProgressCallbackEvent_l();
214 void onProgressCbEvent();
215
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800216 void postOverlayUpdateEvent_l();
217 void onUpdateOverlayEvent();
218
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800219 status_t setDataSource_l_jpg();
220
221 status_t prepare_l();
222 status_t prepareAsync_l();
223
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800224 VideoEditorAudioPlayer *mVeAudioPlayer;
225
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800226 PreviewPlayer(const PreviewPlayer &);
227 PreviewPlayer &operator=(const PreviewPlayer &);
228};
229
230} // namespace android
231
232#endif // PREVIEW_PLAYER_H_
233