NuPlayerDriver.h revision 99f31604136d66ae10e20669fb6b5716f342bde0
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 setDataSource(const sp<DataSource>& dataSource); 43 44 virtual status_t setVideoSurfaceTexture( 45 const sp<IGraphicBufferProducer> &bufferProducer); 46 virtual status_t prepare(); 47 virtual status_t prepareAsync(); 48 virtual status_t start(); 49 virtual status_t stop(); 50 virtual status_t pause(); 51 virtual bool isPlaying(); 52 virtual status_t setPlaybackRate(float rate); 53 virtual status_t seekTo(int msec); 54 virtual status_t getCurrentPosition(int *msec); 55 virtual status_t getDuration(int *msec); 56 virtual status_t reset(); 57 virtual status_t setLooping(int loop); 58 virtual player_type playerType(); 59 virtual status_t invoke(const Parcel &request, Parcel *reply); 60 virtual void setAudioSink(const sp<AudioSink> &audioSink); 61 virtual status_t setParameter(int key, const Parcel &request); 62 virtual status_t getParameter(int key, Parcel *reply); 63 64 virtual status_t getMetadata( 65 const media::Metadata::Filter& ids, Parcel *records); 66 67 virtual status_t dump(int fd, const Vector<String16> &args) const; 68 69 void notifySetDataSourceCompleted(status_t err); 70 void notifyPrepareCompleted(status_t err); 71 void notifyResetComplete(); 72 void notifySetSurfaceComplete(); 73 void notifyDuration(int64_t durationUs); 74 void notifySeekComplete(); 75 void notifySeekComplete_l(); 76 void notifyListener(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL); 77 void notifyFlagsChanged(uint32_t flags); 78 79protected: 80 virtual ~NuPlayerDriver(); 81 82private: 83 enum State { 84 STATE_IDLE, 85 STATE_SET_DATASOURCE_PENDING, 86 STATE_UNPREPARED, 87 STATE_PREPARING, 88 STATE_PREPARED, 89 STATE_RUNNING, 90 STATE_PAUSED, 91 STATE_RESET_IN_PROGRESS, 92 STATE_STOPPED, // equivalent to PAUSED 93 STATE_STOPPED_AND_PREPARING, // equivalent to PAUSED, but seeking 94 STATE_STOPPED_AND_PREPARED, // equivalent to PAUSED, but seek complete 95 }; 96 97 mutable Mutex mLock; 98 Condition mCondition; 99 100 State mState; 101 102 bool mIsAsyncPrepare; 103 status_t mAsyncResult; 104 105 // The following are protected through "mLock" 106 // >>> 107 bool mSetSurfaceInProgress; 108 int64_t mDurationUs; 109 int64_t mPositionUs; 110 bool mSeekInProgress; 111 // <<< 112 113 sp<ALooper> mLooper; 114 sp<NuPlayer> mPlayer; 115 sp<AudioSink> mAudioSink; 116 uint32_t mPlayerFlags; 117 118 bool mAtEOS; 119 bool mLooping; 120 bool mAutoLoop; 121 122 int64_t mStartupSeekTimeUs; 123 124 status_t prepare_l(); 125 void notifyListener_l(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL); 126 127 DISALLOW_EVIL_CONSTRUCTORS(NuPlayerDriver); 128}; 129 130} // namespace android 131 132 133