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