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" |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame^] | 31 | #include "NativeWindowRenderer.h" |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 32 | |
| 33 | namespace android { |
| 34 | |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame] | 35 | struct AudioPlayerBase; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 36 | struct DataSource; |
| 37 | struct MediaBuffer; |
| 38 | struct MediaExtractor; |
| 39 | struct MediaSource; |
| 40 | |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame] | 41 | struct PreviewPlayer : public PreviewPlayerBase { |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame^] | 42 | PreviewPlayer(NativeWindowRenderer* renderer); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 43 | ~PreviewPlayer(); |
| 44 | |
| 45 | //Override baseclass methods |
| 46 | void reset(); |
| 47 | |
| 48 | status_t play(); |
| 49 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 50 | status_t seekTo(int64_t timeUs); |
| 51 | |
| 52 | status_t getVideoDimensions(int32_t *width, int32_t *height) const; |
| 53 | |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 54 | void acquireLock(); |
| 55 | void releaseLock(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 56 | |
| 57 | status_t prepare(); |
| 58 | status_t setDataSource( |
| 59 | const char *uri, const KeyedVector<String8, String8> *headers); |
| 60 | |
| 61 | //Added methods |
Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 62 | status_t loadEffectsSettings(M4VSS3GPP_EffectSettings* pEffectSettings, |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 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(); |
Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 80 | status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs); |
James Dong | c9dedc4 | 2011-05-01 12:36:22 -0700 | [diff] [blame] | 81 | status_t setAudioPlayer(AudioPlayerBase *audioPlayer); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 82 | |
| 83 | private: |
| 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 | }; |
| 99 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 100 | void cancelPlayerEvents(bool keepBufferingGoing = false); |
| 101 | status_t setDataSource_l(const sp<MediaExtractor> &extractor); |
| 102 | status_t setDataSource_l( |
| 103 | const char *uri, const KeyedVector<String8, String8> *headers); |
| 104 | void reset_l(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 105 | status_t play_l(); |
Santosh Madhava | bfece17 | 2011-02-03 16:59:47 -0800 | [diff] [blame] | 106 | status_t initRenderer_l(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 107 | status_t initAudioDecoder(); |
| 108 | status_t initVideoDecoder(uint32_t flags = 0); |
| 109 | void onVideoEvent(); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 110 | void onStreamDone(); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 111 | status_t finishSetDataSource_l(); |
| 112 | static bool ContinuePreparation(void *cookie); |
| 113 | void onPrepareAsyncEvent(); |
| 114 | void finishAsyncPrepare_l(); |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 115 | status_t startAudioPlayer_l(); |
Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 116 | bool mIsChangeSourceRequired; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 117 | |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame^] | 118 | NativeWindowRenderer *mNativeWindowRenderer; |
| 119 | RenderInput *mVideoRenderer; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 120 | |
| 121 | int32_t mVideoWidth, mVideoHeight; |
| 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 | M4xVSS_MediaRendering mRenderingMode; |
| 147 | uint32_t mOutputVideoWidth; |
| 148 | uint32_t mOutputVideoHeight; |
| 149 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 150 | uint32_t mStoryboardStartTimeMsec; |
| 151 | |
| 152 | bool mIsVideoSourceJpg; |
| 153 | bool mIsFiftiesEffectStarted; |
| 154 | int64_t mImageFrameTimeUs; |
| 155 | bool mStartNextPlayer; |
Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 156 | mutable Mutex mLockControl; |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 157 | |
| 158 | M4VIFI_UInt8* mFrameRGBBuffer; |
| 159 | M4VIFI_UInt8* mFrameYUVBuffer; |
| 160 | |
| 161 | void setVideoPostProcessingNode( |
| 162 | M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable); |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 163 | void postProgressCallbackEvent_l(); |
| 164 | void onProgressCbEvent(); |
| 165 | |
Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 166 | void postOverlayUpdateEvent_l(); |
| 167 | void onUpdateOverlayEvent(); |
| 168 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 169 | status_t setDataSource_l_jpg(); |
| 170 | |
| 171 | status_t prepare_l(); |
| 172 | status_t prepareAsync_l(); |
| 173 | |
Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame^] | 174 | void updateSizeToRender(sp<MetaData> meta); |
| 175 | |
Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 176 | VideoEditorAudioPlayer *mVeAudioPlayer; |
| 177 | |
Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 178 | PreviewPlayer(const PreviewPlayer &); |
| 179 | PreviewPlayer &operator=(const PreviewPlayer &); |
| 180 | }; |
| 181 | |
| 182 | } // namespace android |
| 183 | |
| 184 | #endif // PREVIEW_PLAYER_H_ |
| 185 | |