blob: 214c1362b58669927fbe8b1d7881175e25e81cc7 [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
77 status_t loadEffectsSettings(M4VSS3GPP_EffectSettings* pEffectSettings,
78 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();
95
96
97private:
98 friend struct PreviewPlayerEvent;
99
100 enum {
101 PLAYING = 1,
102 LOOPING = 2,
103 FIRST_FRAME = 4,
104 PREPARING = 8,
105 PREPARED = 16,
106 AT_EOS = 32,
107 PREPARE_CANCELLED = 64,
108 CACHE_UNDERRUN = 128,
109 AUDIO_AT_EOS = 256,
110 VIDEO_AT_EOS = 512,
111 AUTO_LOOPING = 1024,
112 };
113
114 sp<ISurface> mISurface;
115
116 void cancelPlayerEvents(bool keepBufferingGoing = false);
117 status_t setDataSource_l(const sp<MediaExtractor> &extractor);
118 status_t setDataSource_l(
119 const char *uri, const KeyedVector<String8, String8> *headers);
120 void reset_l();
121 void partial_reset_l();
122 status_t play_l();
123 void initRenderer_l();
124 status_t initAudioDecoder();
125 status_t initVideoDecoder(uint32_t flags = 0);
126 void onVideoEvent();
127 status_t finishSetDataSource_l();
128 static bool ContinuePreparation(void *cookie);
129 void onPrepareAsyncEvent();
130 void finishAsyncPrepare_l();
131
132 sp<PreviewPlayerRenderer> mVideoRenderer;
133
134 int32_t mVideoWidth, mVideoHeight;
135
136 MediaBuffer *mLastVideoBuffer;
137
138 struct SuspensionState {
139 String8 mUri;
140 KeyedVector<String8, String8> mUriHeaders;
141 sp<DataSource> mFileSource;
142
143 uint32_t mFlags;
144 int64_t mPositionUs;
145
146 void *mLastVideoFrame;
147 size_t mLastVideoFrameSize;
148 int32_t mColorFormat;
149 int32_t mVideoWidth, mVideoHeight;
150 int32_t mDecodedWidth, mDecodedHeight;
151
152 SuspensionState()
153 : mLastVideoFrame(NULL) {
154 }
155
156 ~SuspensionState() {
157 if (mLastVideoFrame) {
158 free(mLastVideoFrame);
159 mLastVideoFrame = NULL;
160 }
161 }
162 } *mSuspensionState;
163
164 //Data structures used for audio and video effects
165 M4VSS3GPP_EffectSettings* mEffectsSettings;
166 M4xVSS_AudioMixingSettings* mPreviewPlayerAudioMixSettings;
167 M4OSA_Context mAudioMixPCMFileHandle;
168 M4OSA_UInt32 mAudioMixStoryBoardTS;
169 M4OSA_UInt32 mCurrentMediaBeginCutTime;
170 M4OSA_UInt32 mCurrentMediaVolumeValue;
171
172 uint32_t mNumberEffects;
173 uint32_t mPlayBeginTimeMsec;
174 uint32_t mPlayEndTimeMsec;
175 uint64_t mDecodedVideoTs; // timestamp of current decoded video frame buffer
176 uint64_t mDecVideoTsStoryBoard; // timestamp of frame relative to storyboard
177 uint32_t mCurrentVideoEffect;
178 uint32_t mProgressCbInterval;
179 uint32_t mNumberDecVideoFrames; // Counter of number of video frames decoded
180 sp<TimedEventQueue::Event> mProgressCbEvent;
181 bool mProgressCbEventPending;
182 MediaBuffer *mResizedVideoBuffer;
183 bool mVideoResizedOrCropped;
184 M4xVSS_MediaRendering mRenderingMode;
185 uint32_t mOutputVideoWidth;
186 uint32_t mOutputVideoHeight;
187
188 uint32_t mStoryboardStartTimeMsec;
189
190 bool mIsVideoSourceJpg;
191 bool mIsFiftiesEffectStarted;
192 int64_t mImageFrameTimeUs;
193 bool mStartNextPlayer;
194
195 M4VIFI_UInt8* mFrameRGBBuffer;
196 M4VIFI_UInt8* mFrameYUVBuffer;
197
198 void setVideoPostProcessingNode(
199 M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable);
200 M4OSA_ERR doVideoPostProcessing();
201 M4OSA_ERR doMediaRendering();
202 void postProgressCallbackEvent_l();
203 void onProgressCbEvent();
204
205 status_t setDataSource_l_jpg();
206
207 status_t prepare_l();
208 status_t prepareAsync_l();
209
210 PreviewPlayer(const PreviewPlayer &);
211 PreviewPlayer &operator=(const PreviewPlayer &);
212};
213
214} // namespace android
215
216#endif // PREVIEW_PLAYER_H_
217