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 | |
Wei Jia | 51b6956 | 2018-02-05 16:17:13 -0800 | [diff] [blame] | 17 | #include <mediaplayer2/MediaPlayer2Interface.h> |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 18 | |
| 19 | #include <media/MediaAnalyticsItem.h> |
| 20 | #include <media/stagefright/foundation/ABase.h> |
Dichen Zhang | fc9f40f | 2019-01-04 14:15:28 -0800 | [diff] [blame^] | 21 | #include <mediaplayer2/JObjectHolder.h> |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | struct ALooper; |
| 26 | struct MediaClock; |
| 27 | struct NuPlayer2; |
| 28 | |
| 29 | struct NuPlayer2Driver : public MediaPlayer2Interface { |
Dichen Zhang | fc9f40f | 2019-01-04 14:15:28 -0800 | [diff] [blame^] | 30 | explicit NuPlayer2Driver(pid_t pid, uid_t uid, const sp<JObjectHolder> &context); |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 31 | |
Wei Jia | 57aeffd | 2018-02-15 16:01:14 -0800 | [diff] [blame] | 32 | virtual status_t initCheck() override; |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 33 | |
Wei Jia | c263603 | 2018-02-01 09:15:25 -0800 | [diff] [blame] | 34 | virtual status_t setDataSource(const sp<DataSourceDesc> &dsd) override; |
Wei Jia | 57aeffd | 2018-02-15 16:01:14 -0800 | [diff] [blame] | 35 | virtual status_t prepareNextDataSource(const sp<DataSourceDesc> &dsd) override; |
| 36 | virtual status_t playNextDataSource(int64_t srcId) override; |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 37 | |
Wei Jia | 57aeffd | 2018-02-15 16:01:14 -0800 | [diff] [blame] | 38 | virtual status_t setVideoSurfaceTexture(const sp<ANativeWindowWrapper> &nww) override; |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 39 | |
| 40 | virtual status_t getBufferingSettings( |
| 41 | BufferingSettings* buffering /* nonnull */) override; |
| 42 | virtual status_t setBufferingSettings(const BufferingSettings& buffering) override; |
| 43 | |
Wei Jia | 0151ef4 | 2018-08-24 16:40:21 -0700 | [diff] [blame] | 44 | virtual status_t prepareAsync() override; |
| 45 | virtual status_t start() override; |
| 46 | virtual status_t pause() override; |
| 47 | virtual bool isPlaying() override; |
| 48 | virtual status_t setPlaybackSettings(const AudioPlaybackRate &rate) override; |
| 49 | virtual status_t getPlaybackSettings(AudioPlaybackRate *rate) override; |
| 50 | virtual status_t setSyncSettings(const AVSyncSettings &sync, float videoFpsHint) override; |
| 51 | virtual status_t getSyncSettings(AVSyncSettings *sync, float *videoFps) override; |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 52 | virtual status_t seekTo( |
Wei Jia | 0151ef4 | 2018-08-24 16:40:21 -0700 | [diff] [blame] | 53 | int64_t msec, |
| 54 | MediaPlayer2SeekMode mode = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC) override; |
| 55 | virtual status_t getCurrentPosition(int64_t *msec) override; |
| 56 | virtual status_t getDuration(int64_t *msec) override; |
| 57 | virtual status_t reset() override; |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 58 | virtual status_t notifyAt(int64_t mediaTimeUs) override; |
Wei Jia | 0151ef4 | 2018-08-24 16:40:21 -0700 | [diff] [blame] | 59 | virtual status_t setLooping(int loop) override; |
Dongwon Kang | 9f63198 | 2018-07-10 12:34:41 -0700 | [diff] [blame] | 60 | virtual status_t invoke(const PlayerMessage &request, PlayerMessage *response) override; |
Wei Jia | 0151ef4 | 2018-08-24 16:40:21 -0700 | [diff] [blame] | 61 | virtual void setAudioSink(const sp<AudioSink> &audioSink) override; |
| 62 | virtual status_t setParameter(int key, const Parcel &request) override; |
| 63 | virtual status_t getParameter(int key, Parcel *reply) override; |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 64 | |
Wei Jia | 0151ef4 | 2018-08-24 16:40:21 -0700 | [diff] [blame] | 65 | virtual status_t dump(int fd, const Vector<String16> &args) const override; |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 66 | |
Wei Jia | 12b9f4a | 2017-12-13 15:24:13 -0800 | [diff] [blame] | 67 | virtual void onMessageReceived(const sp<AMessage> &msg) override; |
| 68 | |
Wei Jia | d2bb1bd | 2018-02-08 09:47:37 -0800 | [diff] [blame] | 69 | void notifySetDataSourceCompleted(int64_t srcId, status_t err); |
| 70 | void notifyPrepareCompleted(int64_t srcId, status_t err); |
| 71 | void notifyResetComplete(int64_t srcId); |
| 72 | void notifySetSurfaceComplete(int64_t srcId); |
| 73 | void notifyDuration(int64_t srcId, int64_t durationUs); |
| 74 | void notifyMorePlayingTimeUs(int64_t srcId, int64_t timeUs); |
| 75 | void notifyMoreRebufferingTimeUs(int64_t srcId, int64_t timeUs); |
| 76 | void notifyRebufferingWhenExit(int64_t srcId, bool status); |
| 77 | void notifySeekComplete(int64_t srcId); |
Wei Jia | d2bb1bd | 2018-02-08 09:47:37 -0800 | [diff] [blame] | 78 | void notifyListener(int64_t srcId, int msg, int ext1 = 0, int ext2 = 0, |
Dongwon Kang | 41929fb | 2018-09-09 08:29:56 -0700 | [diff] [blame] | 79 | const PlayerMessage *in = NULL); |
Wei Jia | d2bb1bd | 2018-02-08 09:47:37 -0800 | [diff] [blame] | 80 | void notifyFlagsChanged(int64_t srcId, uint32_t flags); |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 81 | |
| 82 | // Modular DRM |
Robert Shih | 3c3728d | 2018-12-04 17:06:36 -0800 | [diff] [blame] | 83 | virtual status_t prepareDrm( |
| 84 | int64_t srcId, const uint8_t uuid[16], const Vector<uint8_t> &drmSessionId); |
| 85 | virtual status_t releaseDrm(int64_t srcId); |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 86 | |
| 87 | protected: |
| 88 | virtual ~NuPlayer2Driver(); |
| 89 | |
| 90 | private: |
| 91 | enum State { |
| 92 | STATE_IDLE, |
| 93 | STATE_SET_DATASOURCE_PENDING, |
| 94 | STATE_UNPREPARED, |
| 95 | STATE_PREPARING, |
| 96 | STATE_PREPARED, |
| 97 | STATE_RUNNING, |
| 98 | STATE_PAUSED, |
| 99 | STATE_RESET_IN_PROGRESS, |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 100 | }; |
| 101 | |
Ray Essick | 51f4c87 | 2017-12-15 12:27:56 -0800 | [diff] [blame] | 102 | std::string stateString(State state); |
| 103 | |
Wei Jia | 12b9f4a | 2017-12-13 15:24:13 -0800 | [diff] [blame] | 104 | enum { |
| 105 | kWhatNotifyListener, |
| 106 | }; |
| 107 | |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 108 | mutable Mutex mLock; |
| 109 | Condition mCondition; |
| 110 | |
| 111 | State mState; |
| 112 | |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 113 | status_t mAsyncResult; |
| 114 | |
| 115 | // The following are protected through "mLock" |
| 116 | // >>> |
Wei Jia | d2bb1bd | 2018-02-08 09:47:37 -0800 | [diff] [blame] | 117 | int64_t mSrcId; |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 118 | bool mSetSurfaceInProgress; |
| 119 | int64_t mDurationUs; |
| 120 | int64_t mPositionUs; |
| 121 | bool mSeekInProgress; |
| 122 | int64_t mPlayingTimeUs; |
| 123 | int64_t mRebufferingTimeUs; |
| 124 | int32_t mRebufferingEvents; |
| 125 | bool mRebufferingAtExit; |
| 126 | // <<< |
| 127 | |
| 128 | sp<ALooper> mLooper; |
Wei Jia | 12b9f4a | 2017-12-13 15:24:13 -0800 | [diff] [blame] | 129 | sp<ALooper> mNuPlayer2Looper; |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 130 | const sp<MediaClock> mMediaClock; |
| 131 | const sp<NuPlayer2> mPlayer; |
| 132 | sp<AudioSink> mAudioSink; |
| 133 | uint32_t mPlayerFlags; |
| 134 | |
| 135 | MediaAnalyticsItem *mAnalyticsItem; |
| 136 | uid_t mClientUid; |
| 137 | |
| 138 | bool mAtEOS; |
| 139 | bool mLooping; |
| 140 | bool mAutoLoop; |
| 141 | |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 142 | void updateMetrics(const char *where); |
| 143 | void logMetrics(const char *where); |
| 144 | |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 145 | status_t start_l(); |
Wei Jia | d2bb1bd | 2018-02-08 09:47:37 -0800 | [diff] [blame] | 146 | void notifyListener_l(int64_t srcId, int msg, int ext1 = 0, int ext2 = 0, |
Dongwon Kang | 41929fb | 2018-09-09 08:29:56 -0700 | [diff] [blame] | 147 | const PlayerMessage *in = NULL); |
Wei Jia | 53692fa | 2017-12-11 10:33:46 -0800 | [diff] [blame] | 148 | |
| 149 | DISALLOW_EVIL_CONSTRUCTORS(NuPlayer2Driver); |
| 150 | }; |
| 151 | |
| 152 | } // namespace android |
| 153 | |
| 154 | |