blob: b79363951c7d3bfb99237152a86f9d34d4e1ec9c [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>
James Dongc9dedc42011-05-01 12:36:22 -070031#include "PreviewPlayerBase.h"
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080032#include "VideoEditorPreviewController.h"
33
34namespace android {
35
James Dongc9dedc42011-05-01 12:36:22 -070036struct AudioPlayerBase;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080037struct 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
James Dongc9dedc42011-05-01 12:36:22 -070054struct PreviewPlayer : public PreviewPlayerBase {
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080055 PreviewPlayer();
56 ~PreviewPlayer();
57
58 //Override baseclass methods
59 void reset();
60
61 status_t play();
62
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080063 status_t seekTo(int64_t timeUs);
64
65 status_t getVideoDimensions(int32_t *width, int32_t *height) const;
66
67 status_t suspend();
68 status_t resume();
Raghavender Pallafa31daf2011-03-18 22:32:51 -070069 void acquireLock();
70 void releaseLock();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080071
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);
James Dongc9dedc42011-05-01 12:36:22 -070096 status_t setAudioPlayer(AudioPlayerBase *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
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800115 void cancelPlayerEvents(bool keepBufferingGoing = false);
116 status_t setDataSource_l(const sp<MediaExtractor> &extractor);
117 status_t setDataSource_l(
118 const char *uri, const KeyedVector<String8, String8> *headers);
119 void reset_l();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800120 status_t play_l();
Santosh Madhavabfece172011-02-03 16:59:47 -0800121 status_t initRenderer_l();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800122 status_t initAudioDecoder();
123 status_t initVideoDecoder(uint32_t flags = 0);
124 void onVideoEvent();
Rajneesh Chowdury1c97d9a2011-02-21 15:43:33 -0800125 void onStreamDone();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800126 status_t finishSetDataSource_l();
127 static bool ContinuePreparation(void *cookie);
128 void onPrepareAsyncEvent();
129 void finishAsyncPrepare_l();
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800130 status_t startAudioPlayer_l();
Rajneesh Chowdury1c97d9a2011-02-21 15:43:33 -0800131 bool mIsChangeSourceRequired;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800132
133 sp<PreviewPlayerRenderer> mVideoRenderer;
134
135 int32_t mVideoWidth, mVideoHeight;
136
137 MediaBuffer *mLastVideoBuffer;
138
139 struct SuspensionState {
140 String8 mUri;
141 KeyedVector<String8, String8> mUriHeaders;
142 sp<DataSource> mFileSource;
143
144 uint32_t mFlags;
145 int64_t mPositionUs;
146
147 void *mLastVideoFrame;
148 size_t mLastVideoFrameSize;
149 int32_t mColorFormat;
150 int32_t mVideoWidth, mVideoHeight;
151 int32_t mDecodedWidth, mDecodedHeight;
152
153 SuspensionState()
154 : mLastVideoFrame(NULL) {
155 }
156
157 ~SuspensionState() {
158 if (mLastVideoFrame) {
159 free(mLastVideoFrame);
160 mLastVideoFrame = NULL;
161 }
162 }
163 } *mSuspensionState;
164
165 //Data structures used for audio and video effects
166 M4VSS3GPP_EffectSettings* mEffectsSettings;
167 M4xVSS_AudioMixingSettings* mPreviewPlayerAudioMixSettings;
168 M4OSA_Context mAudioMixPCMFileHandle;
169 M4OSA_UInt32 mAudioMixStoryBoardTS;
170 M4OSA_UInt32 mCurrentMediaBeginCutTime;
171 M4OSA_UInt32 mCurrentMediaVolumeValue;
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800172 M4OSA_UInt32 mCurrFramingEffectIndex;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800173
174 uint32_t mNumberEffects;
175 uint32_t mPlayBeginTimeMsec;
176 uint32_t mPlayEndTimeMsec;
177 uint64_t mDecodedVideoTs; // timestamp of current decoded video frame buffer
178 uint64_t mDecVideoTsStoryBoard; // timestamp of frame relative to storyboard
179 uint32_t mCurrentVideoEffect;
180 uint32_t mProgressCbInterval;
181 uint32_t mNumberDecVideoFrames; // Counter of number of video frames decoded
182 sp<TimedEventQueue::Event> mProgressCbEvent;
183 bool mProgressCbEventPending;
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800184 sp<TimedEventQueue::Event> mOverlayUpdateEvent;
185 bool mOverlayUpdateEventPending;
186 bool mOverlayUpdateEventPosted;
187
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800188 MediaBuffer *mResizedVideoBuffer;
189 bool mVideoResizedOrCropped;
190 M4xVSS_MediaRendering mRenderingMode;
191 uint32_t mOutputVideoWidth;
192 uint32_t mOutputVideoHeight;
193
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -0800194 int32_t mReportedWidth; //docoder reported width
195 int32_t mReportedHeight; //docoder reported height
196
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800197 uint32_t mStoryboardStartTimeMsec;
198
199 bool mIsVideoSourceJpg;
200 bool mIsFiftiesEffectStarted;
201 int64_t mImageFrameTimeUs;
202 bool mStartNextPlayer;
Raghavender Pallafa31daf2011-03-18 22:32:51 -0700203 mutable Mutex mLockControl;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800204
205 M4VIFI_UInt8* mFrameRGBBuffer;
206 M4VIFI_UInt8* mFrameYUVBuffer;
207
208 void setVideoPostProcessingNode(
209 M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable);
210 M4OSA_ERR doVideoPostProcessing();
211 M4OSA_ERR doMediaRendering();
212 void postProgressCallbackEvent_l();
213 void onProgressCbEvent();
214
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800215 void postOverlayUpdateEvent_l();
216 void onUpdateOverlayEvent();
217
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800218 status_t setDataSource_l_jpg();
219
220 status_t prepare_l();
221 status_t prepareAsync_l();
222
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800223 VideoEditorAudioPlayer *mVeAudioPlayer;
224
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800225 PreviewPlayer(const PreviewPlayer &);
226 PreviewPlayer &operator=(const PreviewPlayer &);
227};
228
229} // namespace android
230
231#endif // PREVIEW_PLAYER_H_
232