blob: 051eba528cc1bf2a07ea46be6b82e1328afb7694 [file] [log] [blame]
Wei Jia53692fa2017-12-11 10:33:46 -08001/*
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
22namespace android {
23
24struct ALooper;
25struct MediaClock;
26struct NuPlayer2;
27
28struct 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
46 virtual status_t setVideoSurfaceTexture(
47 const sp<IGraphicBufferProducer> &bufferProducer);
48
49 virtual status_t getBufferingSettings(
50 BufferingSettings* buffering /* nonnull */) override;
51 virtual status_t setBufferingSettings(const BufferingSettings& buffering) override;
52
53 virtual status_t prepare();
54 virtual status_t prepareAsync();
55 virtual status_t start();
56 virtual status_t stop();
57 virtual status_t pause();
58 virtual bool isPlaying();
59 virtual status_t setPlaybackSettings(const AudioPlaybackRate &rate);
60 virtual status_t getPlaybackSettings(AudioPlaybackRate *rate);
61 virtual status_t setSyncSettings(const AVSyncSettings &sync, float videoFpsHint);
62 virtual status_t getSyncSettings(AVSyncSettings *sync, float *videoFps);
63 virtual status_t seekTo(
64 int msec, MediaPlayer2SeekMode mode = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC);
65 virtual status_t getCurrentPosition(int *msec);
66 virtual status_t getDuration(int *msec);
67 virtual status_t reset();
68 virtual status_t notifyAt(int64_t mediaTimeUs) override;
69 virtual status_t setLooping(int loop);
70 virtual player2_type playerType();
71 virtual status_t invoke(const Parcel &request, Parcel *reply);
72 virtual void setAudioSink(const sp<AudioSink> &audioSink);
73 virtual status_t setParameter(int key, const Parcel &request);
74 virtual status_t getParameter(int key, Parcel *reply);
75
76 virtual status_t getMetadata(
77 const media::Metadata::Filter& ids, Parcel *records);
78
79 virtual status_t dump(int fd, const Vector<String16> &args) const;
80
Wei Jia12b9f4a2017-12-13 15:24:13 -080081 virtual void onMessageReceived(const sp<AMessage> &msg) override;
82
Wei Jia53692fa2017-12-11 10:33:46 -080083 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
100protected:
101 virtual ~NuPlayer2Driver();
102
103private:
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
Wei Jia12b9f4a2017-12-13 15:24:13 -0800118 enum {
119 kWhatNotifyListener,
120 };
121
Wei Jia53692fa2017-12-11 10:33:46 -0800122 mutable Mutex mLock;
123 Condition mCondition;
124
125 State mState;
126
127 bool mIsAsyncPrepare;
128 status_t mAsyncResult;
129
130 // The following are protected through "mLock"
131 // >>>
132 bool mSetSurfaceInProgress;
133 int64_t mDurationUs;
134 int64_t mPositionUs;
135 bool mSeekInProgress;
136 int64_t mPlayingTimeUs;
137 int64_t mRebufferingTimeUs;
138 int32_t mRebufferingEvents;
139 bool mRebufferingAtExit;
140 // <<<
141
142 sp<ALooper> mLooper;
Wei Jia12b9f4a2017-12-13 15:24:13 -0800143 sp<ALooper> mNuPlayer2Looper;
Wei Jia53692fa2017-12-11 10:33:46 -0800144 const sp<MediaClock> mMediaClock;
145 const sp<NuPlayer2> mPlayer;
146 sp<AudioSink> mAudioSink;
147 uint32_t mPlayerFlags;
148
149 MediaAnalyticsItem *mAnalyticsItem;
150 uid_t mClientUid;
151
152 bool mAtEOS;
153 bool mLooping;
154 bool mAutoLoop;
155
Wei Jia53692fa2017-12-11 10:33:46 -0800156 void updateMetrics(const char *where);
157 void logMetrics(const char *where);
158
159 status_t prepare_l();
160 status_t start_l();
161 void notifyListener_l(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL);
Wei Jia12b9f4a2017-12-13 15:24:13 -0800162 void sendNotifyOnLooper(int msgId);
Wei Jia53692fa2017-12-11 10:33:46 -0800163
164 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer2Driver);
165};
166
167} // namespace android
168
169