1/* 2 * 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 21#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> 29#include "PreviewPlayerBase.h" 30#include "VideoEditorPreviewController.h" 31#include "NativeWindowRenderer.h" 32 33namespace android { 34 35struct AudioPlayerBase; 36struct DataSource; 37struct MediaBuffer; 38struct MediaExtractor; 39struct MediaSource; 40 41struct PreviewPlayer : public PreviewPlayerBase { 42 PreviewPlayer(NativeWindowRenderer* renderer); 43 ~PreviewPlayer(); 44 45 //Override baseclass methods 46 void reset(); 47 48 status_t play(); 49 50 status_t seekTo(int64_t timeUs); 51 52 status_t getVideoDimensions(int32_t *width, int32_t *height) const; 53 54 void acquireLock(); 55 void releaseLock(); 56 57 status_t prepare(); 58 status_t setDataSource( 59 const char *uri, const KeyedVector<String8, String8> *headers); 60 61 //Added methods 62 status_t loadEffectsSettings(M4VSS3GPP_EffectSettings* pEffectSettings, 63 int nEffects); 64 status_t loadAudioMixSettings(M4xVSS_AudioMixingSettings* pAudioMixSettings); 65 status_t setAudioMixPCMFileHandle(M4OSA_Context pAudioMixPCMFileHandle); 66 status_t setAudioMixStoryBoardParam(M4OSA_UInt32 audioMixStoryBoardTS, 67 M4OSA_UInt32 currentMediaBeginCutTime, 68 M4OSA_UInt32 currentMediaVolumeVol); 69 70 status_t setPlaybackBeginTime(uint32_t msec); 71 status_t setPlaybackEndTime(uint32_t msec); 72 status_t setStoryboardStartTime(uint32_t msec); 73 status_t setProgressCallbackInterval(uint32_t cbInterval); 74 status_t setMediaRenderingMode(M4xVSS_MediaRendering mode, 75 M4VIDEOEDITING_VideoFrameSize outputVideoSize); 76 77 status_t resetJniCallbackTimeStamp(); 78 status_t setImageClipProperties(uint32_t width, uint32_t height); 79 status_t readFirstVideoFrame(); 80 status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs); 81 status_t setAudioPlayer(AudioPlayerBase *audioPlayer); 82 83private: 84 friend struct PreviewPlayerEvent; 85 86 enum { 87 PLAYING = 1, 88 LOOPING = 2, 89 FIRST_FRAME = 4, 90 PREPARING = 8, 91 PREPARED = 16, 92 AT_EOS = 32, 93 PREPARE_CANCELLED = 64, 94 CACHE_UNDERRUN = 128, 95 AUDIO_AT_EOS = 256, 96 VIDEO_AT_EOS = 512, 97 AUTO_LOOPING = 1024, 98 INFORMED_AV_EOS = 2048, 99 }; 100 101 void cancelPlayerEvents(bool keepBufferingGoing = false); 102 status_t setDataSource_l(const sp<MediaExtractor> &extractor); 103 status_t setDataSource_l( 104 const char *uri, const KeyedVector<String8, String8> *headers); 105 void reset_l(); 106 status_t play_l(); 107 status_t initRenderer_l(); 108 status_t initAudioDecoder(); 109 status_t initVideoDecoder(uint32_t flags = 0); 110 void onVideoEvent(); 111 void onStreamDone(); 112 status_t finishSetDataSource_l(); 113 static bool ContinuePreparation(void *cookie); 114 void onPrepareAsyncEvent(); 115 void finishAsyncPrepare_l(); 116 status_t startAudioPlayer_l(); 117 bool mIsChangeSourceRequired; 118 119 NativeWindowRenderer *mNativeWindowRenderer; 120 RenderInput *mVideoRenderer; 121 122 int32_t mVideoWidth, mVideoHeight; 123 124 //Data structures used for audio and video effects 125 M4VSS3GPP_EffectSettings* mEffectsSettings; 126 M4xVSS_AudioMixingSettings* mPreviewPlayerAudioMixSettings; 127 M4OSA_Context mAudioMixPCMFileHandle; 128 M4OSA_UInt32 mAudioMixStoryBoardTS; 129 M4OSA_UInt32 mCurrentMediaBeginCutTime; 130 M4OSA_UInt32 mCurrentMediaVolumeValue; 131 M4OSA_UInt32 mCurrFramingEffectIndex; 132 133 uint32_t mNumberEffects; 134 uint32_t mPlayBeginTimeMsec; 135 uint32_t mPlayEndTimeMsec; 136 uint64_t mDecodedVideoTs; // timestamp of current decoded video frame buffer 137 uint64_t mDecVideoTsStoryBoard; // timestamp of frame relative to storyboard 138 uint32_t mCurrentVideoEffect; 139 uint32_t mProgressCbInterval; 140 uint32_t mNumberDecVideoFrames; // Counter of number of video frames decoded 141 sp<TimedEventQueue::Event> mProgressCbEvent; 142 bool mProgressCbEventPending; 143 sp<TimedEventQueue::Event> mOverlayUpdateEvent; 144 bool mOverlayUpdateEventPending; 145 bool mOverlayUpdateEventPosted; 146 147 M4xVSS_MediaRendering mRenderingMode; 148 uint32_t mOutputVideoWidth; 149 uint32_t mOutputVideoHeight; 150 151 uint32_t mStoryboardStartTimeMsec; 152 153 bool mIsVideoSourceJpg; 154 bool mIsFiftiesEffectStarted; 155 int64_t mImageFrameTimeUs; 156 bool mStartNextPlayer; 157 mutable Mutex mLockControl; 158 159 M4VIFI_UInt8* mFrameRGBBuffer; 160 M4VIFI_UInt8* mFrameYUVBuffer; 161 162 void setVideoPostProcessingNode( 163 M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable); 164 void postProgressCallbackEvent_l(); 165 void onProgressCbEvent(); 166 167 void postOverlayUpdateEvent_l(); 168 void onUpdateOverlayEvent(); 169 170 status_t setDataSource_l_jpg(); 171 172 status_t prepare_l(); 173 status_t prepareAsync_l(); 174 175 void updateSizeToRender(sp<MetaData> meta); 176 177 VideoEditorAudioPlayer *mVeAudioPlayer; 178 179 PreviewPlayer(const PreviewPlayer &); 180 PreviewPlayer &operator=(const PreviewPlayer &); 181}; 182 183} // namespace android 184 185#endif // PREVIEW_PLAYER_H_ 186 187