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