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