| 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> | 
| Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 28 | #include "NativeWindowRenderer.h" | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 29 |  | 
 | 30 | namespace android { | 
 | 31 |  | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 32 | struct VideoEditorAudioPlayer; | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 33 | struct MediaExtractor; | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 34 |  | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 35 | struct PreviewPlayer { | 
| Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 36 |     PreviewPlayer(NativeWindowRenderer* renderer); | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 37 |     ~PreviewPlayer(); | 
 | 38 |  | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 39 |     void setListener(const wp<MediaPlayerBase> &listener); | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 40 |     void reset(); | 
 | 41 |  | 
 | 42 |     status_t play(); | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 43 |     status_t pause(); | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 44 |  | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 45 |     bool isPlaying() const; | 
 | 46 |     void setSurface(const sp<Surface> &surface); | 
| Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 47 |     void setSurfaceTexture(const sp<IGraphicBufferProducer> &bufferProducer); | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 48 |     status_t seekTo(int64_t timeUs); | 
 | 49 |  | 
 | 50 |     status_t getVideoDimensions(int32_t *width, int32_t *height) const; | 
 | 51 |  | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 52 |  | 
 | 53 |     // FIXME: Sync between ... | 
| 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(); | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 58 |     status_t prepareAsync(); | 
| James Dong | daeb5b3 | 2012-01-12 12:12:40 -0800 | [diff] [blame] | 59 |     status_t setDataSource(const char *path); | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 60 |     status_t setDataSource(const sp<IStreamSource> &source); | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 61 |  | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 62 |     void setAudioSink(const sp<MediaPlayerBase::AudioSink> &audioSink); | 
 | 63 |     status_t setLooping(bool shouldLoop); | 
 | 64 |     status_t getDuration(int64_t *durationUs); | 
 | 65 |     status_t getPosition(int64_t *positionUs); | 
 | 66 |  | 
 | 67 |     uint32_t getSourceSeekFlags() const; | 
 | 68 |  | 
 | 69 |     void postAudioEOS(int64_t delayUs = 0ll); | 
 | 70 |     void postAudioSeekComplete(); | 
 | 71 |  | 
| Dharmaray Kundargi | 35cb2de | 2011-01-19 19:09:27 -0800 | [diff] [blame] | 72 |     status_t loadEffectsSettings(M4VSS3GPP_EffectSettings* pEffectSettings, | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 73 |                                  int nEffects); | 
 | 74 |     status_t loadAudioMixSettings(M4xVSS_AudioMixingSettings* pAudioMixSettings); | 
 | 75 |     status_t setAudioMixPCMFileHandle(M4OSA_Context pAudioMixPCMFileHandle); | 
 | 76 |     status_t setAudioMixStoryBoardParam(M4OSA_UInt32 audioMixStoryBoardTS, | 
 | 77 |                             M4OSA_UInt32 currentMediaBeginCutTime, | 
 | 78 |                             M4OSA_UInt32 currentMediaVolumeVol); | 
 | 79 |  | 
 | 80 |     status_t setPlaybackBeginTime(uint32_t msec); | 
 | 81 |     status_t setPlaybackEndTime(uint32_t msec); | 
 | 82 |     status_t setStoryboardStartTime(uint32_t msec); | 
 | 83 |     status_t setProgressCallbackInterval(uint32_t cbInterval); | 
 | 84 |     status_t setMediaRenderingMode(M4xVSS_MediaRendering mode, | 
 | 85 |                             M4VIDEOEDITING_VideoFrameSize outputVideoSize); | 
 | 86 |  | 
 | 87 |     status_t resetJniCallbackTimeStamp(); | 
 | 88 |     status_t setImageClipProperties(uint32_t width, uint32_t height); | 
 | 89 |     status_t readFirstVideoFrame(); | 
| Santosh Madhava | b2d6e0f | 2011-02-16 22:24:42 -0800 | [diff] [blame] | 90 |     status_t getLastRenderedTimeMs(uint32_t *lastRenderedTimeMs); | 
| James Dong | 727f9e1 | 2012-01-20 13:09:13 -0800 | [diff] [blame] | 91 |     status_t setAudioPlayer(VideoEditorAudioPlayer *audioPlayer); | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 92 |  | 
 | 93 | private: | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 94 |     enum { | 
 | 95 |         PLAYING             = 1, | 
 | 96 |         LOOPING             = 2, | 
 | 97 |         FIRST_FRAME         = 4, | 
 | 98 |         PREPARING           = 8, | 
 | 99 |         PREPARED            = 16, | 
 | 100 |         AT_EOS              = 32, | 
 | 101 |         PREPARE_CANCELLED   = 64, | 
 | 102 |         CACHE_UNDERRUN      = 128, | 
 | 103 |         AUDIO_AT_EOS        = 256, | 
 | 104 |         VIDEO_AT_EOS        = 512, | 
 | 105 |         AUTO_LOOPING        = 1024, | 
| Hong Teng | e018023 | 2011-09-28 18:40:38 -0700 | [diff] [blame] | 106 |         INFORMED_AV_EOS     = 2048, | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 107 |  | 
 | 108 |         // We are basically done preparing but are currently buffering | 
 | 109 |         // sufficient data to begin playback and finish the preparation phase | 
 | 110 |         // for good. | 
 | 111 |         PREPARING_CONNECTED = 2048, | 
 | 112 |  | 
 | 113 |         // We're triggering a single video event to display the first frame | 
 | 114 |         // after the seekpoint. | 
 | 115 |         SEEK_PREVIEW        = 4096, | 
 | 116 |  | 
 | 117 |         AUDIO_RUNNING       = 8192, | 
 | 118 |         AUDIOPLAYER_STARTED = 16384, | 
 | 119 |  | 
 | 120 |         INCOGNITO           = 32768, | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 121 |     }; | 
 | 122 |  | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 123 |     mutable Mutex mLock; | 
 | 124 |  | 
 | 125 |     OMXClient mClient; | 
 | 126 |     TimedEventQueue mQueue; | 
 | 127 |     bool mQueueStarted; | 
 | 128 |     wp<MediaPlayerBase> mListener; | 
 | 129 |  | 
 | 130 |     sp<Surface> mSurface; | 
 | 131 |     sp<ANativeWindow> mNativeWindow; | 
 | 132 |     sp<MediaPlayerBase::AudioSink> mAudioSink; | 
 | 133 |  | 
 | 134 |     SystemTimeSource mSystemTimeSource; | 
 | 135 |     TimeSource *mTimeSource; | 
 | 136 |  | 
 | 137 |     String8 mUri; | 
 | 138 |  | 
 | 139 |     sp<MediaSource> mVideoTrack; | 
 | 140 |     sp<MediaSource> mVideoSource; | 
 | 141 |     bool mVideoRendererIsPreview; | 
 | 142 |  | 
 | 143 |     sp<MediaSource> mAudioTrack; | 
 | 144 |     sp<MediaSource> mAudioSource; | 
| James Dong | 727f9e1 | 2012-01-20 13:09:13 -0800 | [diff] [blame] | 145 |     VideoEditorAudioPlayer *mAudioPlayer; | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 146 |     int64_t mDurationUs; | 
 | 147 |  | 
 | 148 |     int32_t mDisplayWidth; | 
 | 149 |     int32_t mDisplayHeight; | 
 | 150 |  | 
 | 151 |     uint32_t mFlags; | 
 | 152 |     uint32_t mExtractorFlags; | 
 | 153 |  | 
 | 154 |     int64_t mTimeSourceDeltaUs; | 
 | 155 |     int64_t mVideoTimeUs; | 
 | 156 |  | 
 | 157 |     enum SeekType { | 
 | 158 |         NO_SEEK, | 
 | 159 |         SEEK, | 
 | 160 |         SEEK_VIDEO_ONLY | 
 | 161 |     }; | 
 | 162 |     SeekType mSeeking; | 
 | 163 |  | 
 | 164 |     bool mSeekNotificationSent; | 
 | 165 |     int64_t mSeekTimeUs; | 
 | 166 |  | 
 | 167 |     int64_t mBitrate;  // total bitrate of the file (in bps) or -1 if unknown. | 
 | 168 |  | 
 | 169 |     bool mWatchForAudioSeekComplete; | 
 | 170 |     bool mWatchForAudioEOS; | 
 | 171 |  | 
 | 172 |     sp<TimedEventQueue::Event> mVideoEvent; | 
 | 173 |     bool mVideoEventPending; | 
 | 174 |     sp<TimedEventQueue::Event> mStreamDoneEvent; | 
 | 175 |     bool mStreamDoneEventPending; | 
 | 176 |     sp<TimedEventQueue::Event> mCheckAudioStatusEvent; | 
 | 177 |     bool mAudioStatusEventPending; | 
 | 178 |     sp<TimedEventQueue::Event> mVideoLagEvent; | 
 | 179 |     bool mVideoLagEventPending; | 
 | 180 |  | 
 | 181 |     sp<TimedEventQueue::Event> mAsyncPrepareEvent; | 
 | 182 |     Condition mPreparedCondition; | 
 | 183 |     bool mIsAsyncPrepare; | 
 | 184 |     status_t mPrepareResult; | 
 | 185 |     status_t mStreamDoneStatus; | 
 | 186 |  | 
 | 187 |     MediaBuffer *mVideoBuffer; | 
 | 188 |     int64_t mLastVideoTimeUs; | 
 | 189 |     ARect mCropRect; | 
 | 190 |     int32_t mGivenWidth, mGivenHeight; | 
 | 191 |  | 
 | 192 |  | 
| Rajneesh Chowdury | 1c97d9a | 2011-02-21 15:43:33 -0800 | [diff] [blame] | 193 |     bool mIsChangeSourceRequired; | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 194 |  | 
| Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 195 |     NativeWindowRenderer *mNativeWindowRenderer; | 
 | 196 |     RenderInput *mVideoRenderer; | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 197 |  | 
 | 198 |     int32_t mVideoWidth, mVideoHeight; | 
 | 199 |  | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 200 |     //Data structures used for audio and video effects | 
 | 201 |     M4VSS3GPP_EffectSettings* mEffectsSettings; | 
 | 202 |     M4xVSS_AudioMixingSettings* mPreviewPlayerAudioMixSettings; | 
 | 203 |     M4OSA_Context mAudioMixPCMFileHandle; | 
 | 204 |     M4OSA_UInt32 mAudioMixStoryBoardTS; | 
 | 205 |     M4OSA_UInt32 mCurrentMediaBeginCutTime; | 
 | 206 |     M4OSA_UInt32 mCurrentMediaVolumeValue; | 
| Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 207 |     M4OSA_UInt32 mCurrFramingEffectIndex; | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 208 |  | 
 | 209 |     uint32_t mNumberEffects; | 
 | 210 |     uint32_t mPlayBeginTimeMsec; | 
 | 211 |     uint32_t mPlayEndTimeMsec; | 
 | 212 |     uint64_t mDecodedVideoTs; // timestamp of current decoded video frame buffer | 
 | 213 |     uint64_t mDecVideoTsStoryBoard; // timestamp of frame relative to storyboard | 
 | 214 |     uint32_t mCurrentVideoEffect; | 
 | 215 |     uint32_t mProgressCbInterval; | 
 | 216 |     uint32_t mNumberDecVideoFrames; // Counter of number of video frames decoded | 
 | 217 |     sp<TimedEventQueue::Event> mProgressCbEvent; | 
 | 218 |     bool mProgressCbEventPending; | 
| Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 219 |     sp<TimedEventQueue::Event> mOverlayUpdateEvent; | 
 | 220 |     bool mOverlayUpdateEventPending; | 
 | 221 |     bool mOverlayUpdateEventPosted; | 
 | 222 |  | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 223 |     M4xVSS_MediaRendering mRenderingMode; | 
 | 224 |     uint32_t mOutputVideoWidth; | 
 | 225 |     uint32_t mOutputVideoHeight; | 
 | 226 |  | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 227 |     uint32_t mStoryboardStartTimeMsec; | 
 | 228 |  | 
 | 229 |     bool mIsVideoSourceJpg; | 
 | 230 |     bool mIsFiftiesEffectStarted; | 
 | 231 |     int64_t mImageFrameTimeUs; | 
 | 232 |     bool mStartNextPlayer; | 
| Raghavender Palla | fa31daf | 2011-03-18 22:32:51 -0700 | [diff] [blame] | 233 |     mutable Mutex mLockControl; | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 234 |  | 
 | 235 |     M4VIFI_UInt8*  mFrameRGBBuffer; | 
 | 236 |     M4VIFI_UInt8*  mFrameYUVBuffer; | 
 | 237 |  | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 238 |     void cancelPlayerEvents_l(bool updateProgressCb = false); | 
 | 239 |     status_t setDataSource_l(const sp<MediaExtractor> &extractor); | 
 | 240 |     status_t setDataSource_l(const char *path); | 
 | 241 |     void setNativeWindow_l(const sp<ANativeWindow> &native); | 
 | 242 |     void reset_l(); | 
 | 243 |     void clear_l(); | 
 | 244 |     status_t play_l(); | 
 | 245 |     status_t pause_l(bool at_eos = false); | 
 | 246 |     status_t initRenderer_l(); | 
 | 247 |     status_t initAudioDecoder_l(); | 
 | 248 |     status_t initVideoDecoder_l(uint32_t flags = 0); | 
 | 249 |     void notifyVideoSize_l(); | 
 | 250 |     void notifyListener_l(int msg, int ext1 = 0, int ext2 = 0); | 
 | 251 |     void onVideoEvent(); | 
 | 252 |     void onVideoLagUpdate(); | 
 | 253 |     void onStreamDone(); | 
 | 254 |     void onCheckAudioStatus(); | 
 | 255 |     void onPrepareAsyncEvent(); | 
 | 256 |  | 
 | 257 |     void finishAsyncPrepare_l(); | 
 | 258 |     void abortPrepare(status_t err); | 
 | 259 |  | 
 | 260 |     status_t startAudioPlayer_l(); | 
 | 261 |     void setVideoSource(const sp<MediaSource>& source); | 
 | 262 |     status_t finishSetDataSource_l(); | 
 | 263 |     void setAudioSource(const sp<MediaSource>& source); | 
 | 264 |  | 
 | 265 |     status_t seekTo_l(int64_t timeUs); | 
 | 266 |     void seekAudioIfNecessary_l(); | 
 | 267 |     void finishSeekIfNecessary(int64_t videoTimeUs); | 
 | 268 |  | 
 | 269 |     void postCheckAudioStatusEvent_l(int64_t delayUs); | 
 | 270 |     void postVideoLagEvent_l(); | 
 | 271 |     void postStreamDoneEvent_l(status_t status); | 
 | 272 |     void postVideoEvent_l(int64_t delayUs = -1); | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 273 |     void setVideoPostProcessingNode( | 
 | 274 |                     M4VSS3GPP_VideoEffectType type, M4OSA_Bool enable); | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 275 |     void postProgressCallbackEvent_l(); | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 276 |     void shutdownVideoDecoder_l(); | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 277 |     void onProgressCbEvent(); | 
 | 278 |  | 
| Dharmaray Kundargi | e6c0750 | 2011-01-21 16:58:31 -0800 | [diff] [blame] | 279 |     void postOverlayUpdateEvent_l(); | 
 | 280 |     void onUpdateOverlayEvent(); | 
 | 281 |  | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 282 |     status_t setDataSource_l_jpg(); | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 283 |     status_t prepare_l(); | 
 | 284 |     status_t prepareAsync_l(); | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 285 |     void updateBatteryUsage_l(); | 
| Chih-Chung Chang | 43fcc39 | 2011-08-02 16:17:39 +0800 | [diff] [blame] | 286 |     void updateSizeToRender(sp<MetaData> meta); | 
 | 287 |  | 
| James Dong | 00f742c | 2012-01-13 17:34:42 -0800 | [diff] [blame] | 288 |     void setDuration_l(int64_t durationUs); | 
 | 289 |     void setPosition_l(int64_t timeUs); | 
| Dheeraj Sharma | 5bc7fb4 | 2011-02-13 20:31:27 -0800 | [diff] [blame] | 290 |  | 
| Dharmaray Kundargi | 643290d | 2011-01-16 16:02:42 -0800 | [diff] [blame] | 291 |     PreviewPlayer(const PreviewPlayer &); | 
 | 292 |     PreviewPlayer &operator=(const PreviewPlayer &); | 
 | 293 | }; | 
 | 294 |  | 
 | 295 | }  // namespace android | 
 | 296 |  | 
 | 297 | #endif  // PREVIEW_PLAYER_H_ | 
 | 298 |  |