Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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/MediaPlayer2Interface.h> |
| 18 | |
| 19 | #include <media/MediaAnalyticsItem.h> |
| 20 | #include <media/stagefright/foundation/ABase.h> |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | struct ALooper; |
| 25 | struct MediaClock; |
| 26 | struct NuPlayer2; |
| 27 | |
| 28 | struct NuPlayer2Driver : public MediaPlayer2Interface { |
| 29 | explicit NuPlayer2Driver(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<MediaHTTPService> &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 | |
Wei Jia | 28288fb | 2017-12-15 13:45:29 -0800 | [diff] [blame^] | 46 | virtual status_t setVideoSurfaceTexture(const sp<ANativeWindowWrapper> &nww); |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 47 | |
| 48 | virtual status_t getBufferingSettings( |
| 49 | BufferingSettings* buffering /* nonnull */) override; |
| 50 | virtual status_t setBufferingSettings(const BufferingSettings& buffering) override; |
| 51 | |
| 52 | virtual status_t prepare(); |
| 53 | virtual status_t prepareAsync(); |
| 54 | virtual status_t start(); |
| 55 | virtual status_t stop(); |
| 56 | virtual status_t pause(); |
| 57 | virtual bool isPlaying(); |
| 58 | virtual status_t setPlaybackSettings(const AudioPlaybackRate &rate); |
| 59 | virtual status_t getPlaybackSettings(AudioPlaybackRate *rate); |
| 60 | virtual status_t setSyncSettings(const AVSyncSettings &sync, float videoFpsHint); |
| 61 | virtual status_t getSyncSettings(AVSyncSettings *sync, float *videoFps); |
| 62 | virtual status_t seekTo( |
| 63 | int msec, MediaPlayer2SeekMode mode = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC); |
| 64 | virtual status_t getCurrentPosition(int *msec); |
| 65 | virtual status_t getDuration(int *msec); |
| 66 | virtual status_t reset(); |
| 67 | virtual status_t notifyAt(int64_t mediaTimeUs) override; |
| 68 | virtual status_t setLooping(int loop); |
| 69 | virtual player2_type playerType(); |
| 70 | virtual status_t invoke(const Parcel &request, Parcel *reply); |
| 71 | virtual void setAudioSink(const sp<AudioSink> &audioSink); |
| 72 | virtual status_t setParameter(int key, const Parcel &request); |
| 73 | virtual status_t getParameter(int key, Parcel *reply); |
| 74 | |
| 75 | virtual status_t getMetadata( |
| 76 | const media::Metadata::Filter& ids, Parcel *records); |
| 77 | |
| 78 | virtual status_t dump(int fd, const Vector<String16> &args) const; |
| 79 | |
Wei Jia | 12b9f4a | 2017-12-13 15:24:13 -0800 | [diff] [blame] | 80 | virtual void onMessageReceived(const sp<AMessage> &msg) override; |
| 81 | |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 82 | void notifySetDataSourceCompleted(status_t err); |
| 83 | void notifyPrepareCompleted(status_t err); |
| 84 | void notifyResetComplete(); |
| 85 | void notifySetSurfaceComplete(); |
| 86 | void notifyDuration(int64_t durationUs); |
| 87 | void notifyMorePlayingTimeUs(int64_t timeUs); |
| 88 | void notifyMoreRebufferingTimeUs(int64_t timeUs); |
| 89 | void notifyRebufferingWhenExit(bool status); |
| 90 | void notifySeekComplete(); |
| 91 | void notifySeekComplete_l(); |
| 92 | void notifyListener(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL); |
| 93 | void notifyFlagsChanged(uint32_t flags); |
| 94 | |
| 95 | // Modular DRM |
| 96 | virtual status_t prepareDrm(const uint8_t uuid[16], const Vector<uint8_t> &drmSessionId); |
| 97 | virtual status_t releaseDrm(); |
| 98 | |
| 99 | protected: |
| 100 | virtual ~NuPlayer2Driver(); |
| 101 | |
| 102 | private: |
| 103 | enum State { |
| 104 | STATE_IDLE, |
| 105 | STATE_SET_DATASOURCE_PENDING, |
| 106 | STATE_UNPREPARED, |
| 107 | STATE_PREPARING, |
| 108 | STATE_PREPARED, |
| 109 | STATE_RUNNING, |
| 110 | STATE_PAUSED, |
| 111 | STATE_RESET_IN_PROGRESS, |
| 112 | STATE_STOPPED, // equivalent to PAUSED |
| 113 | STATE_STOPPED_AND_PREPARING, // equivalent to PAUSED, but seeking |
| 114 | STATE_STOPPED_AND_PREPARED, // equivalent to PAUSED, but seek complete |
| 115 | }; |
| 116 | |
Ray Essick | 51f4c87 | 2017-12-15 12:27:56 -0800 | [diff] [blame] | 117 | std::string stateString(State state); |
| 118 | |
Wei Jia | 12b9f4a | 2017-12-13 15:24:13 -0800 | [diff] [blame] | 119 | enum { |
| 120 | kWhatNotifyListener, |
| 121 | }; |
| 122 | |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 123 | mutable Mutex mLock; |
| 124 | Condition mCondition; |
| 125 | |
| 126 | State mState; |
| 127 | |
| 128 | bool mIsAsyncPrepare; |
| 129 | status_t mAsyncResult; |
| 130 | |
| 131 | // The following are protected through "mLock" |
| 132 | // >>> |
| 133 | bool mSetSurfaceInProgress; |
| 134 | int64_t mDurationUs; |
| 135 | int64_t mPositionUs; |
| 136 | bool mSeekInProgress; |
| 137 | int64_t mPlayingTimeUs; |
| 138 | int64_t mRebufferingTimeUs; |
| 139 | int32_t mRebufferingEvents; |
| 140 | bool mRebufferingAtExit; |
| 141 | // <<< |
| 142 | |
| 143 | sp<ALooper> mLooper; |
Wei Jia | 12b9f4a | 2017-12-13 15:24:13 -0800 | [diff] [blame] | 144 | sp<ALooper> mNuPlayer2Looper; |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 145 | const sp<MediaClock> mMediaClock; |
| 146 | const sp<NuPlayer2> mPlayer; |
| 147 | sp<AudioSink> mAudioSink; |
| 148 | uint32_t mPlayerFlags; |
| 149 | |
| 150 | MediaAnalyticsItem *mAnalyticsItem; |
| 151 | uid_t mClientUid; |
| 152 | |
| 153 | bool mAtEOS; |
| 154 | bool mLooping; |
| 155 | bool mAutoLoop; |
| 156 | |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 157 | void updateMetrics(const char *where); |
| 158 | void logMetrics(const char *where); |
| 159 | |
| 160 | status_t prepare_l(); |
| 161 | status_t start_l(); |
| 162 | void notifyListener_l(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL); |
Wei Jia | 12b9f4a | 2017-12-13 15:24:13 -0800 | [diff] [blame] | 163 | void sendNotifyOnLooper(int msgId); |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 164 | |
| 165 | DISALLOW_EVIL_CONSTRUCTORS(NuPlayer2Driver); |
| 166 | }; |
| 167 | |
| 168 | } // namespace android |
| 169 | |
| 170 | |