1 /* 2 * Copyright (C) 2009 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 MEDIA_PLAYER_IMPL_H_ 18 19 #define MEDIA_PLAYER_IMPL_H_ 20 21 #include <pthread.h> 22 23 #include <media/MediaPlayerInterface.h> 24 #include <media/stagefright/OMXClient.h> 25 #include <utils/RefBase.h> 26 #include <utils/threads.h> 27 28 namespace android { 29 30 class AudioPlayer; 31 class IOMXRenderer; 32 class ISurface; 33 class MediaExtractor; 34 class MediaBuffer; 35 class MediaSource; 36 class MemoryHeapPmem; 37 class MetaData; 38 class Surface; 39 class TimeSource; 40 41 class MediaPlayerImpl { 42 public: 43 MediaPlayerImpl(const char *uri); 44 45 status_t initCheck() const; 46 47 // Assumes ownership of "fd". 48 MediaPlayerImpl(int fd, int64_t offset, int64_t length); 49 50 ~MediaPlayerImpl(); 51 52 void play(); 53 void pause(); 54 bool isPlaying() const; 55 56 void setSurface(const sp<Surface> &surface); 57 void setISurface(const sp<ISurface> &isurface); 58 59 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &audioSink); 60 getWidth()61 int32_t getWidth() const { return mVideoWidth; } getHeight()62 int32_t getHeight() const { return mVideoHeight; } 63 64 int64_t getDuration(); 65 int64_t getPosition(); 66 status_t seekTo(int64_t time); 67 68 private: 69 status_t mInitCheck; 70 71 OMXClient mClient; 72 73 sp<MediaExtractor> mExtractor; 74 75 TimeSource *mTimeSource; 76 77 sp<MediaSource> mAudioSource; 78 sp<MediaSource> mAudioDecoder; 79 AudioPlayer *mAudioPlayer; 80 81 sp<MediaSource> mVideoSource; 82 sp<MediaSource> mVideoDecoder; 83 int32_t mVideoWidth, mVideoHeight; 84 int64_t mVideoPosition; 85 86 int64_t mDuration; 87 88 bool mPlaying; 89 bool mPaused; 90 91 int64_t mTimeSourceDeltaUs; 92 93 sp<Surface> mSurface; 94 sp<ISurface> mISurface; 95 sp<IOMXRenderer> mVideoRenderer; 96 97 sp<MediaPlayerBase::AudioSink> mAudioSink; 98 99 Mutex mLock; 100 pthread_t mVideoThread; 101 102 bool mSeeking; 103 int64_t mSeekTimeUs; 104 105 void init(); 106 107 static void *VideoWrapper(void *me); 108 void videoEntry(); 109 110 void setAudioSource(const sp<MediaSource> &source); 111 void setVideoSource(const sp<MediaSource> &source); 112 113 MediaSource *makeShoutcastSource(const char *path); 114 115 void displayOrDiscardFrame(MediaBuffer *buffer, int64_t pts_us); 116 void populateISurface(); 117 void depopulateISurface(); 118 void sendFrameToISurface(MediaBuffer *buffer); 119 120 void stop(); 121 122 MediaPlayerImpl(const MediaPlayerImpl &); 123 MediaPlayerImpl &operator=(const MediaPlayerImpl &); 124 }; 125 126 } // namespace android 127 128 #endif // MEDIA_PLAYER_IMPL_H_ 129