blob: ccd88a7a6f4c55edaa1c48e3401816ba9f322722 [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
40struct PreviewPlayerRenderer : public RefBase {
41 PreviewPlayerRenderer() {}
42
43 virtual void render(MediaBuffer *buffer) = 0;
44 virtual void render() = 0;
45 virtual void getBuffer(uint8_t **data, size_t *stride) = 0;
46
47private:
48 PreviewPlayerRenderer(const PreviewPlayerRenderer &);
49 PreviewPlayerRenderer &operator=(const PreviewPlayerRenderer &);
50};
51
James Dongc9dedc42011-05-01 12:36:22 -070052struct PreviewPlayer : public PreviewPlayerBase {
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080053 PreviewPlayer();
54 ~PreviewPlayer();
55
56 //Override baseclass methods
57 void reset();
58
59 status_t play();
60
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080061 status_t seekTo(int64_t timeUs);
62
63 status_t getVideoDimensions(int32_t *width, int32_t *height) const;
64
Raghavender Pallafa31daf2011-03-18 22:32:51 -070065 void acquireLock();
66 void releaseLock();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080067
68 status_t prepare();
69 status_t setDataSource(
70 const char *uri, const KeyedVector<String8, String8> *headers);
71
72 //Added methods
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -080073 status_t loadEffectsSettings(M4VSS3GPP_EffectSettings* pEffectSettings,
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080074 int nEffects);
75 status_t loadAudioMixSettings(M4xVSS_AudioMixingSettings* pAudioMixSettings);
76 status_t setAudioMixPCMFileHandle(M4OSA_Context pAudioMixPCMFileHandle);
77 status_t setAudioMixStoryBoardParam(M4OSA_UInt32 audioMixStoryBoardTS,
78 M4OSA_UInt32 currentMediaBeginCutTime,
79 M4OSA_UInt32 currentMediaVolumeVol);
80
81 status_t setPlaybackBeginTime(uint32_t msec);
82 status_t setPlaybackEndTime(uint32_t msec);
83 status_t setStoryboardStartTime(uint32_t msec);
84 status_t setProgressCallbackInterval(uint32_t cbInterval);
85 status_t setMediaRenderingMode(M4xVSS_MediaRendering mode,
86 M4VIDEOEDITING_VideoFrameSize outputVideoSize);
87
88 status_t resetJniCallbackTimeStamp();
89 status_t setImageClipProperties(uint32_t width, uint32_t height);
90 status_t readFirstVideoFrame();
Santosh Madhavab2d6e0f2011-02-16 22:24:42 -080091 status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs);
James Dongc9dedc42011-05-01 12:36:22 -070092 status_t setAudioPlayer(AudioPlayerBase *audioPlayer);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -080093
94private:
95 friend struct PreviewPlayerEvent;
96
97 enum {
98 PLAYING = 1,
99 LOOPING = 2,
100 FIRST_FRAME = 4,
101 PREPARING = 8,
102 PREPARED = 16,
103 AT_EOS = 32,
104 PREPARE_CANCELLED = 64,
105 CACHE_UNDERRUN = 128,
106 AUDIO_AT_EOS = 256,
107 VIDEO_AT_EOS = 512,
108 AUTO_LOOPING = 1024,
109 };
110
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800111 void cancelPlayerEvents(bool keepBufferingGoing = false);
112 status_t setDataSource_l(const sp<MediaExtractor> &extractor);
113 status_t setDataSource_l(
114 const char *uri, const KeyedVector<String8, String8> *headers);
115 void reset_l();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800116 status_t play_l();
Santosh Madhavabfece172011-02-03 16:59:47 -0800117 status_t initRenderer_l();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800118 status_t initAudioDecoder();
119 status_t initVideoDecoder(uint32_t flags = 0);
120 void onVideoEvent();
Rajneesh Chowdury1c97d9a2011-02-21 15:43:33 -0800121 void onStreamDone();
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800122 status_t finishSetDataSource_l();
123 static bool ContinuePreparation(void *cookie);
124 void onPrepareAsyncEvent();
125 void finishAsyncPrepare_l();
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800126 status_t startAudioPlayer_l();
Rajneesh Chowdury1c97d9a2011-02-21 15:43:33 -0800127 bool mIsChangeSourceRequired;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800128
129 sp<PreviewPlayerRenderer> mVideoRenderer;
130
131 int32_t mVideoWidth, mVideoHeight;
132
133 MediaBuffer *mLastVideoBuffer;
134
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800135 //Data structures used for audio and video effects
136 M4VSS3GPP_EffectSettings* mEffectsSettings;
137 M4xVSS_AudioMixingSettings* mPreviewPlayerAudioMixSettings;
138 M4OSA_Context mAudioMixPCMFileHandle;
139 M4OSA_UInt32 mAudioMixStoryBoardTS;
140 M4OSA_UInt32 mCurrentMediaBeginCutTime;
141 M4OSA_UInt32 mCurrentMediaVolumeValue;
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800142 M4OSA_UInt32 mCurrFramingEffectIndex;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800143
144 uint32_t mNumberEffects;
145 uint32_t mPlayBeginTimeMsec;
146 uint32_t mPlayEndTimeMsec;
147 uint64_t mDecodedVideoTs; // timestamp of current decoded video frame buffer
148 uint64_t mDecVideoTsStoryBoard; // timestamp of frame relative to storyboard
149 uint32_t mCurrentVideoEffect;
150 uint32_t mProgressCbInterval;
151 uint32_t mNumberDecVideoFrames; // Counter of number of video frames decoded
152 sp<TimedEventQueue::Event> mProgressCbEvent;
153 bool mProgressCbEventPending;
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800154 sp<TimedEventQueue::Event> mOverlayUpdateEvent;
155 bool mOverlayUpdateEventPending;
156 bool mOverlayUpdateEventPosted;
157
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800158 MediaBuffer *mResizedVideoBuffer;
159 bool mVideoResizedOrCropped;
160 M4xVSS_MediaRendering mRenderingMode;
161 uint32_t mOutputVideoWidth;
162 uint32_t mOutputVideoHeight;
163
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -0800164 int32_t mReportedWidth; //docoder reported width
165 int32_t mReportedHeight; //docoder reported height
166
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800167 uint32_t mStoryboardStartTimeMsec;
168
169 bool mIsVideoSourceJpg;
170 bool mIsFiftiesEffectStarted;
171 int64_t mImageFrameTimeUs;
172 bool mStartNextPlayer;
Raghavender Pallafa31daf2011-03-18 22:32:51 -0700173 mutable Mutex mLockControl;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800174
175 M4VIFI_UInt8* mFrameRGBBuffer;
176 M4VIFI_UInt8* mFrameYUVBuffer;
177
178 void setVideoPostProcessingNode(
179 M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable);
180 M4OSA_ERR doVideoPostProcessing();
181 M4OSA_ERR doMediaRendering();
182 void postProgressCallbackEvent_l();
183 void onProgressCbEvent();
184
Dharmaray Kundargie6c07502011-01-21 16:58:31 -0800185 void postOverlayUpdateEvent_l();
186 void onUpdateOverlayEvent();
187
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800188 status_t setDataSource_l_jpg();
189
190 status_t prepare_l();
191 status_t prepareAsync_l();
192
Dheeraj Sharma5bc7fb42011-02-13 20:31:27 -0800193 VideoEditorAudioPlayer *mVeAudioPlayer;
194
Dharmaray Kundargi643290d2011-01-16 16:02:42 -0800195 PreviewPlayer(const PreviewPlayer &);
196 PreviewPlayer &operator=(const PreviewPlayer &);
197};
198
199} // namespace android
200
201#endif // PREVIEW_PLAYER_H_
202