blob: 55a0fade6ac2f956501295fff524506f5854bcce [file] [log] [blame]
Andreas Huberf9334412010-12-15 15:17:42 -08001/*
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
Ray Essickf27e9872019-12-07 06:28:46 -080019#include <media/MediaMetricsItem.h>
Andreas Huberf9334412010-12-15 15:17:42 -080020#include <media/stagefright/foundation/ABase.h>
21
22namespace android {
23
24struct ALooper;
Wei Jia0a68f662017-08-30 18:01:26 -070025struct MediaClock;
Andreas Huberf9334412010-12-15 15:17:42 -080026struct NuPlayer;
27
28struct NuPlayerDriver : public MediaPlayerInterface {
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -070029 explicit NuPlayerDriver(pid_t pid);
Andreas Huberf9334412010-12-15 15:17:42 -080030
31 virtual status_t initCheck();
32
Andreas Huber9b80c2b2011-06-30 15:47:02 -070033 virtual status_t setUID(uid_t uid);
34
Andreas Huberf9334412010-12-15 15:17:42 -080035 virtual status_t setDataSource(
Andreas Huber1b86fe02014-01-29 11:13:26 -080036 const sp<IMediaHTTPService> &httpService,
37 const char *url,
38 const KeyedVector<String8, String8> *headers);
Andreas Huberf9334412010-12-15 15:17:42 -080039
40 virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
41
42 virtual status_t setDataSource(const sp<IStreamSource> &source);
43
Chris Watkins99f31602015-03-20 13:06:33 -070044 virtual status_t setDataSource(const sp<DataSource>& dataSource);
45
Byeongjo Park28225ab2019-01-24 20:31:19 +090046 virtual status_t setDataSource(const String8& rtpParams);
47
Glenn Kasten11731182011-02-08 17:26:17 -080048 virtual status_t setVideoSurfaceTexture(
Andy McFadden8ba01022012-12-18 09:46:54 -080049 const sp<IGraphicBufferProducer> &bufferProducer);
Wei Jia48fa06d2016-12-20 15:30:49 -080050
Wei Jia9bb38032017-03-23 18:00:38 -070051 virtual status_t getBufferingSettings(
Wei Jia48fa06d2016-12-20 15:30:49 -080052 BufferingSettings* buffering /* nonnull */) override;
53 virtual status_t setBufferingSettings(const BufferingSettings& buffering) override;
54
Andreas Huberf9334412010-12-15 15:17:42 -080055 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();
Lajos Molnar3a474aa2015-04-24 17:10:07 -070061 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);
Wei Jiac5de0912016-11-18 10:22:14 -080065 virtual status_t seekTo(
66 int msec, MediaPlayerSeekMode mode = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC);
Andreas Huberf9334412010-12-15 15:17:42 -080067 virtual status_t getCurrentPosition(int *msec);
68 virtual status_t getDuration(int *msec);
69 virtual status_t reset();
Wei Jia52c28512017-09-13 18:17:51 -070070 virtual status_t notifyAt(int64_t mediaTimeUs) override;
Andreas Huberf9334412010-12-15 15:17:42 -080071 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);
Gloria Wang4f9e47f2011-04-25 17:28:22 -070075 virtual status_t setParameter(int key, const Parcel &request);
76 virtual status_t getParameter(int key, Parcel *reply);
Andreas Huberf9334412010-12-15 15:17:42 -080077
78 virtual status_t getMetadata(
79 const media::Metadata::Filter& ids, Parcel *records);
80
Andreas Huber3fe62152011-09-16 15:09:22 -070081 virtual status_t dump(int fd, const Vector<String16> &args) const;
82
Andreas Huber9575c962013-02-05 13:59:56 -080083 void notifySetDataSourceCompleted(status_t err);
84 void notifyPrepareCompleted(status_t err);
Andreas Huber43c3e6c2011-01-05 12:17:08 -080085 void notifyResetComplete();
Chong Zhang13d6faa2014-08-22 15:35:28 -070086 void notifySetSurfaceComplete();
Andreas Huber43c3e6c2011-01-05 12:17:08 -080087 void notifyDuration(int64_t durationUs);
Ray Essickd4d00612017-01-03 09:36:27 -080088 void notifyMorePlayingTimeUs(int64_t timeUs);
Ray Essick58e0f7a2017-11-21 10:59:38 -080089 void notifyMoreRebufferingTimeUs(int64_t timeUs);
90 void notifyRebufferingWhenExit(bool status);
Andreas Huber43c3e6c2011-01-05 12:17:08 -080091 void notifySeekComplete();
Marco Nelisseneb645a02014-08-20 09:44:44 -070092 void notifySeekComplete_l();
Chong Zhangdcb89b32013-08-06 09:44:47 -070093 void notifyListener(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL);
Andreas Huber9575c962013-02-05 13:59:56 -080094 void notifyFlagsChanged(uint32_t flags);
Andreas Huber1aef2112011-01-04 14:01:29 -080095
Hassan Shojaniacefac142017-02-06 21:02:02 -080096 // Modular DRM
97 virtual status_t prepareDrm(const uint8_t uuid[16], const Vector<uint8_t> &drmSessionId);
98 virtual status_t releaseDrm();
99
Andreas Huberf9334412010-12-15 15:17:42 -0800100protected:
101 virtual ~NuPlayerDriver();
102
103private:
Andreas Huber9575c962013-02-05 13:59:56 -0800104 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,
Lajos Molnar4b75b862013-08-15 15:59:19 -0700113 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
Andreas Huber9575c962013-02-05 13:59:56 -0800116 };
117
Ray Essick51f4c872017-12-15 12:27:56 -0800118 std::string stateString(State state);
119
Andreas Huber3fe62152011-09-16 15:09:22 -0700120 mutable Mutex mLock;
Andreas Huber1aef2112011-01-04 14:01:29 -0800121 Condition mCondition;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800122
Andreas Huber9575c962013-02-05 13:59:56 -0800123 State mState;
124
Andreas Huberec0c5972013-02-05 14:47:13 -0800125 bool mIsAsyncPrepare;
Andreas Huber9575c962013-02-05 13:59:56 -0800126 status_t mAsyncResult;
127
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800128 // The following are protected through "mLock"
129 // >>>
Chong Zhang13d6faa2014-08-22 15:35:28 -0700130 bool mSetSurfaceInProgress;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800131 int64_t mDurationUs;
132 int64_t mPositionUs;
Ronghua Wua73d9e02014-10-08 15:13:29 -0700133 bool mSeekInProgress;
Ray Essickd4d00612017-01-03 09:36:27 -0800134 int64_t mPlayingTimeUs;
Ray Essick58e0f7a2017-11-21 10:59:38 -0800135 int64_t mRebufferingTimeUs;
136 int32_t mRebufferingEvents;
137 bool mRebufferingAtExit;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800138 // <<<
Andreas Huber1aef2112011-01-04 14:01:29 -0800139
Andreas Huberf9334412010-12-15 15:17:42 -0800140 sp<ALooper> mLooper;
Wei Jia0a68f662017-08-30 18:01:26 -0700141 const sp<MediaClock> mMediaClock;
Hassan Shojania69579622017-03-07 09:16:52 -0800142 const sp<NuPlayer> mPlayer;
Marco Nelissenf0b72b52014-09-16 15:43:44 -0700143 sp<AudioSink> mAudioSink;
Andreas Huber9575c962013-02-05 13:59:56 -0800144 uint32_t mPlayerFlags;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800145
Ray Essickf27e9872019-12-07 06:28:46 -0800146 mediametrics::Item *mMetricsItem;
Ray Essicke99bcf22020-05-04 16:18:33 -0700147 mutable Mutex mMetricsLock;
Ray Essickf65f4212017-08-31 11:41:19 -0700148 uid_t mClientUid;
Ray Essickd4d00612017-01-03 09:36:27 -0800149
Andreas Hubera4af2142011-10-26 15:23:31 -0700150 bool mAtEOS;
Lajos Molnara2e14302014-07-31 12:07:58 -0700151 bool mLooping;
Marco Nelissenf0b72b52014-09-16 15:43:44 -0700152 bool mAutoLoop;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800153
Ray Essickf65f4212017-08-31 11:41:19 -0700154
Ray Essick54097702017-03-17 16:18:35 -0700155 void updateMetrics(const char *where);
Ray Essickd4d00612017-01-03 09:36:27 -0800156 void logMetrics(const char *where);
157
Andreas Huber9575c962013-02-05 13:59:56 -0800158 status_t prepare_l();
Wei Jia8a092d32016-06-03 14:57:24 -0700159 status_t start_l();
Wei Jia05601952014-08-20 18:21:11 -0700160 void notifyListener_l(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL);
Andreas Huber9575c962013-02-05 13:59:56 -0800161
Andreas Huberf9334412010-12-15 15:17:42 -0800162 DISALLOW_EVIL_CONSTRUCTORS(NuPlayerDriver);
163};
164
165} // namespace android
166
167