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