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