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