PreviewPlayer.h revision d30f1bcd661eb469c92ceddaea15ae6fb07e7a92
1/* 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 "PreviewPlayerBase.h" 32#include "VideoEditorPreviewController.h" 33 34namespace android { 35 36struct AudioPlayerBase; 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 PreviewPlayerBase { 55 PreviewPlayer(); 56 ~PreviewPlayer(); 57 58 //Override baseclass methods 59 void reset(); 60 61 status_t play(); 62 63 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(); 69 void acquireLock(); 70 void releaseLock(); 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 status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs); 96 status_t setAudioPlayer(AudioPlayerBase *audioPlayer); 97 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 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(); 120 status_t play_l(); 121 status_t initRenderer_l(); 122 status_t initAudioDecoder(); 123 status_t initVideoDecoder(uint32_t flags = 0); 124 void onVideoEvent(); 125 void onStreamDone(); 126 status_t finishSetDataSource_l(); 127 static bool ContinuePreparation(void *cookie); 128 void onPrepareAsyncEvent(); 129 void finishAsyncPrepare_l(); 130 status_t startAudioPlayer_l(); 131 bool mIsChangeSourceRequired; 132 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; 172 M4OSA_UInt32 mCurrFramingEffectIndex; 173 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; 184 sp<TimedEventQueue::Event> mOverlayUpdateEvent; 185 bool mOverlayUpdateEventPending; 186 bool mOverlayUpdateEventPosted; 187 188 MediaBuffer *mResizedVideoBuffer; 189 bool mVideoResizedOrCropped; 190 M4xVSS_MediaRendering mRenderingMode; 191 uint32_t mOutputVideoWidth; 192 uint32_t mOutputVideoHeight; 193 194 int32_t mReportedWidth; //docoder reported width 195 int32_t mReportedHeight; //docoder reported height 196 197 uint32_t mStoryboardStartTimeMsec; 198 199 bool mIsVideoSourceJpg; 200 bool mIsFiftiesEffectStarted; 201 int64_t mImageFrameTimeUs; 202 bool mStartNextPlayer; 203 mutable Mutex mLockControl; 204 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 215 void postOverlayUpdateEvent_l(); 216 void onUpdateOverlayEvent(); 217 218 status_t setDataSource_l_jpg(); 219 220 status_t prepare_l(); 221 status_t prepareAsync_l(); 222 223 VideoEditorAudioPlayer *mVeAudioPlayer; 224 225 PreviewPlayer(const PreviewPlayer &); 226 PreviewPlayer &operator=(const PreviewPlayer &); 227}; 228 229} // namespace android 230 231#endif // PREVIEW_PLAYER_H_ 232 233