NuPlayerDriver.h revision f0b72b509ab1147a2a0925aced970dd68fd7fa4f
1/* 2 * Copyright (C) 2010 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#include <media/MediaPlayerInterface.h> 18 19#include <media/stagefright/foundation/ABase.h> 20 21namespace android { 22 23struct ALooper; 24struct NuPlayer; 25 26struct NuPlayerDriver : public MediaPlayerInterface { 27 NuPlayerDriver(); 28 29 virtual status_t initCheck(); 30 31 virtual status_t setUID(uid_t uid); 32 33 virtual status_t setDataSource( 34 const sp<IMediaHTTPService> &httpService, 35 const char *url, 36 const KeyedVector<String8, String8> *headers); 37 38 virtual status_t setDataSource(int fd, int64_t offset, int64_t length); 39 40 virtual status_t setDataSource(const sp<IStreamSource> &source); 41 42 virtual status_t setVideoSurfaceTexture( 43 const sp<IGraphicBufferProducer> &bufferProducer); 44 virtual status_t prepare(); 45 virtual status_t prepareAsync(); 46 virtual status_t start(); 47 virtual status_t stop(); 48 virtual status_t pause(); 49 virtual bool isPlaying(); 50 virtual status_t seekTo(int msec); 51 virtual status_t getCurrentPosition(int *msec); 52 virtual status_t getDuration(int *msec); 53 virtual status_t reset(); 54 virtual status_t setLooping(int loop); 55 virtual player_type playerType(); 56 virtual status_t invoke(const Parcel &request, Parcel *reply); 57 virtual void setAudioSink(const sp<AudioSink> &audioSink); 58 virtual status_t setParameter(int key, const Parcel &request); 59 virtual status_t getParameter(int key, Parcel *reply); 60 61 virtual status_t getMetadata( 62 const media::Metadata::Filter& ids, Parcel *records); 63 64 virtual status_t dump(int fd, const Vector<String16> &args) const; 65 66 void notifySetDataSourceCompleted(status_t err); 67 void notifyPrepareCompleted(status_t err); 68 void notifyResetComplete(); 69 void notifySetSurfaceComplete(); 70 void notifyDuration(int64_t durationUs); 71 void notifyPosition(int64_t positionUs); 72 void notifySeekComplete(); 73 void notifySeekComplete_l(); 74 void notifyFrameStats(int64_t numFramesTotal, int64_t numFramesDropped); 75 void notifyListener(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL); 76 void notifyFlagsChanged(uint32_t flags); 77 78protected: 79 virtual ~NuPlayerDriver(); 80 81private: 82 enum State { 83 STATE_IDLE, 84 STATE_SET_DATASOURCE_PENDING, 85 STATE_UNPREPARED, 86 STATE_PREPARING, 87 STATE_PREPARED, 88 STATE_RUNNING, 89 STATE_PAUSED, 90 STATE_RESET_IN_PROGRESS, 91 STATE_STOPPED, // equivalent to PAUSED 92 STATE_STOPPED_AND_PREPARING, // equivalent to PAUSED, but seeking 93 STATE_STOPPED_AND_PREPARED, // equivalent to PAUSED, but seek complete 94 }; 95 96 mutable Mutex mLock; 97 Condition mCondition; 98 99 State mState; 100 101 bool mIsAsyncPrepare; 102 status_t mAsyncResult; 103 104 // The following are protected through "mLock" 105 // >>> 106 bool mSetSurfaceInProgress; 107 int64_t mDurationUs; 108 int64_t mPositionUs; 109 int64_t mNotifyTimeRealUs; 110 int64_t mPauseStartedTimeUs; 111 int64_t mNumFramesTotal; 112 int64_t mNumFramesDropped; 113 // <<< 114 115 sp<ALooper> mLooper; 116 sp<NuPlayer> mPlayer; 117 sp<AudioSink> mAudioSink; 118 uint32_t mPlayerFlags; 119 120 bool mAtEOS; 121 bool mLooping; 122 bool mAutoLoop; 123 124 int64_t mStartupSeekTimeUs; 125 126 status_t prepare_l(); 127 void notifyListener_l(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL); 128 void setPauseStartedTimeIfNeeded(); 129 130 DISALLOW_EVIL_CONSTRUCTORS(NuPlayerDriver); 131}; 132 133} // namespace android 134 135 136