AwesomePlayer.h revision 1862a33b246249630b654182afb5914da3480d4c
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 AWESOME_PLAYER_H_ 18 19#define AWESOME_PLAYER_H_ 20 21#include "TimedEventQueue.h" 22 23#include <media/MediaPlayerInterface.h> 24#include <media/stagefright/OMXClient.h> 25#include <utils/threads.h> 26 27namespace android { 28 29struct AudioPlayer; 30struct MediaBuffer; 31struct MediaExtractor; 32struct MediaSource; 33struct Prefetcher; 34struct TimeSource; 35 36struct AwesomeRenderer : public RefBase { 37 AwesomeRenderer() {} 38 39 virtual void render(MediaBuffer *buffer) = 0; 40 41private: 42 AwesomeRenderer(const AwesomeRenderer &); 43 AwesomeRenderer &operator=(const AwesomeRenderer &); 44}; 45 46struct AwesomePlayer { 47 AwesomePlayer(); 48 ~AwesomePlayer(); 49 50 void setListener(const wp<MediaPlayerBase> &listener); 51 52 status_t setDataSource( 53 const char *uri, 54 const KeyedVector<String8, String8> *headers = NULL); 55 56 status_t setDataSource(int fd, int64_t offset, int64_t length); 57 58 void reset(); 59 60 status_t play(); 61 status_t pause(); 62 63 bool isPlaying() const; 64 65 void setISurface(const sp<ISurface> &isurface); 66 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &audioSink); 67 status_t setLooping(bool shouldLoop); 68 69 status_t getDuration(int64_t *durationUs); 70 status_t getPosition(int64_t *positionUs); 71 72 status_t seekTo(int64_t timeUs); 73 74 status_t getVideoDimensions(int32_t *width, int32_t *height) const; 75 76private: 77 friend struct AwesomeEvent; 78 79 enum Flags { 80 PLAYING = 1, 81 LOOPING = 2, 82 FIRST_FRAME = 4, 83 }; 84 85 mutable Mutex mLock; 86 87 OMXClient mClient; 88 TimedEventQueue mQueue; 89 wp<MediaPlayerBase> mListener; 90 91 sp<ISurface> mISurface; 92 sp<MediaPlayerBase::AudioSink> mAudioSink; 93 94 TimeSource *mTimeSource; 95 96 sp<MediaSource> mVideoSource; 97 sp<AwesomeRenderer> mVideoRenderer; 98 99 sp<MediaSource> mAudioSource; 100 AudioPlayer *mAudioPlayer; 101 int64_t mDurationUs; 102 103 uint32_t mFlags; 104 105 int32_t mVideoWidth, mVideoHeight; 106 int64_t mTimeSourceDeltaUs; 107 int64_t mVideoTimeUs; 108 109 bool mSeeking; 110 int64_t mSeekTimeUs; 111 112 bool mWatchForAudioSeekComplete; 113 bool mWatchForAudioEOS; 114 115 sp<TimedEventQueue::Event> mVideoEvent; 116 bool mVideoEventPending; 117 sp<TimedEventQueue::Event> mStreamDoneEvent; 118 bool mStreamDoneEventPending; 119 sp<TimedEventQueue::Event> mBufferingEvent; 120 bool mBufferingEventPending; 121 sp<TimedEventQueue::Event> mCheckAudioStatusEvent; 122 bool mAudioStatusEventPending; 123 124 void postVideoEvent_l(int64_t delayUs = -1); 125 void postBufferingEvent_l(); 126 void postStreamDoneEvent_l(); 127 void postCheckAudioStatusEvent_l(); 128 129 MediaBuffer *mLastVideoBuffer; 130 MediaBuffer *mVideoBuffer; 131 132 sp<Prefetcher> mPrefetcher; 133 134 status_t setDataSource_l(const sp<MediaExtractor> &extractor); 135 void reset_l(); 136 status_t seekTo_l(int64_t timeUs); 137 status_t pause_l(); 138 void initRenderer_l(); 139 void seekAudioIfNecessary_l(); 140 141 void cancelPlayerEvents(bool keepBufferingGoing = false); 142 143 status_t setAudioSource(sp<MediaSource> source); 144 status_t setVideoSource(sp<MediaSource> source); 145 146 void onEvent(int32_t code); 147 void onStreamDone(); 148 149 void notifyListener_l(int msg, int ext1 = 0); 150 151 void onBufferingUpdate(); 152 void onCheckAudioStatus(); 153 154 AwesomePlayer(const AwesomePlayer &); 155 AwesomePlayer &operator=(const AwesomePlayer &); 156}; 157 158} // namespace android 159 160#endif // AWESOME_PLAYER_H_ 161 162