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