Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 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> |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame^] | 31 | #include "PreviewPlayerBase.h" |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 32 | #include "VideoEditorPreviewController.h" |
| 33 | |
| 34 | namespace android { |
| 35 | |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame^] | 36 | struct AudioPlayerBase; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 37 | struct DataSource; |
| 38 | struct MediaBuffer; |
| 39 | struct MediaExtractor; |
| 40 | struct MediaSource; |
| 41 | |
| 42 | struct 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 | |
| 49 | private: |
| 50 | PreviewPlayerRenderer(const PreviewPlayerRenderer &); |
| 51 | PreviewPlayerRenderer &operator=(const PreviewPlayerRenderer &); |
| 52 | }; |
| 53 | |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame^] | 54 | struct PreviewPlayer : public PreviewPlayerBase { |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 55 | PreviewPlayer(); |
| 56 | ~PreviewPlayer(); |
| 57 | |
| 58 | //Override baseclass methods |
| 59 | void reset(); |
| 60 | |
| 61 | status_t play(); |
| 62 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 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(); |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 69 | void acquireLock(); |
| 70 | void releaseLock(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 71 | |
| 72 | status_t prepare(); |
| 73 | status_t setDataSource( |
| 74 | const char *uri, const KeyedVector<String8, String8> *headers); |
| 75 | |
| 76 | //Added methods |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 77 | status_t loadEffectsSettings(M4VSS3GPP_EffectSettings* pEffectSettings, |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 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(); |
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 95 | status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs); |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame^] | 96 | status_t setAudioPlayer(AudioPlayerBase *audioPlayer); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 97 | |
| 98 | private: |
| 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 Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 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(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 120 | status_t play_l(); |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 121 | status_t initRenderer_l(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 122 | status_t initAudioDecoder(); |
| 123 | status_t initVideoDecoder(uint32_t flags = 0); |
| 124 | void onVideoEvent(); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 125 | void onStreamDone(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 126 | status_t finishSetDataSource_l(); |
| 127 | static bool ContinuePreparation(void *cookie); |
| 128 | void onPrepareAsyncEvent(); |
| 129 | void finishAsyncPrepare_l(); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 130 | status_t startAudioPlayer_l(); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 131 | bool mIsChangeSourceRequired; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 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; |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 172 | M4OSA_UInt32 mCurrFramingEffectIndex; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 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; |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 184 | sp<TimedEventQueue::Event> mOverlayUpdateEvent; |
| 185 | bool mOverlayUpdateEventPending; |
| 186 | bool mOverlayUpdateEventPosted; |
| 187 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 188 | MediaBuffer *mResizedVideoBuffer; |
| 189 | bool mVideoResizedOrCropped; |
| 190 | M4xVSS_MediaRendering mRenderingMode; |
| 191 | uint32_t mOutputVideoWidth; |
| 192 | uint32_t mOutputVideoHeight; |
| 193 | |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 194 | int32_t mReportedWidth; //docoder reported width |
| 195 | int32_t mReportedHeight; //docoder reported height |
| 196 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 197 | uint32_t mStoryboardStartTimeMsec; |
| 198 | |
| 199 | bool mIsVideoSourceJpg; |
| 200 | bool mIsFiftiesEffectStarted; |
| 201 | int64_t mImageFrameTimeUs; |
| 202 | bool mStartNextPlayer; |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 203 | mutable Mutex mLockControl; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 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 | |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 215 | void postOverlayUpdateEvent_l(); |
| 216 | void onUpdateOverlayEvent(); |
| 217 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 218 | status_t setDataSource_l_jpg(); |
| 219 | |
| 220 | status_t prepare_l(); |
| 221 | status_t prepareAsync_l(); |
| 222 | |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 223 | VideoEditorAudioPlayer *mVeAudioPlayer; |
| 224 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 225 | PreviewPlayer(const PreviewPlayer &); |
| 226 | PreviewPlayer &operator=(const PreviewPlayer &); |
| 227 | }; |
| 228 | |
| 229 | } // namespace android |
| 230 | |
| 231 | #endif // PREVIEW_PLAYER_H_ |
| 232 | |