blob: edd4556ce9370539233c1cb279b7df3f9caf3695 [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
81 void notifySetDataSourceCompleted(status_t err);
82 void notifyPrepareCompleted(status_t err);
83 void notifyResetComplete();
84 void notifySetSurfaceComplete();
85 void notifyDuration(int64_t durationUs);
86 void notifyMorePlayingTimeUs(int64_t timeUs);
87 void notifyMoreRebufferingTimeUs(int64_t timeUs);
88 void notifyRebufferingWhenExit(bool status);
89 void notifySeekComplete();
90 void notifySeekComplete_l();
91 void notifyListener(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL);
92 void notifyFlagsChanged(uint32_t flags);
93
94 // Modular DRM
95 virtual status_t prepareDrm(const uint8_t uuid[16], const Vector<uint8_t> &drmSessionId);
96 virtual status_t releaseDrm();
97
98protected:
99 virtual ~NuPlayer2Driver();
100
101private:
102 enum State {
103 STATE_IDLE,
104 STATE_SET_DATASOURCE_PENDING,
105 STATE_UNPREPARED,
106 STATE_PREPARING,
107 STATE_PREPARED,
108 STATE_RUNNING,
109 STATE_PAUSED,
110 STATE_RESET_IN_PROGRESS,
111 STATE_STOPPED, // equivalent to PAUSED
112 STATE_STOPPED_AND_PREPARING, // equivalent to PAUSED, but seeking
113 STATE_STOPPED_AND_PREPARED, // equivalent to PAUSED, but seek complete
114 };
115
116 mutable Mutex mLock;
117 Condition mCondition;
118
119 State mState;
120
121 bool mIsAsyncPrepare;
122 status_t mAsyncResult;
123
124 // The following are protected through "mLock"
125 // >>>
126 bool mSetSurfaceInProgress;
127 int64_t mDurationUs;
128 int64_t mPositionUs;
129 bool mSeekInProgress;
130 int64_t mPlayingTimeUs;
131 int64_t mRebufferingTimeUs;
132 int32_t mRebufferingEvents;
133 bool mRebufferingAtExit;
134 // <<<
135
136 sp<ALooper> mLooper;
137 const sp<MediaClock> mMediaClock;
138 const sp<NuPlayer2> mPlayer;
139 sp<AudioSink> mAudioSink;
140 uint32_t mPlayerFlags;
141
142 MediaAnalyticsItem *mAnalyticsItem;
143 uid_t mClientUid;
144
145 bool mAtEOS;
146 bool mLooping;
147 bool mAutoLoop;
148
149
150 void updateMetrics(const char *where);
151 void logMetrics(const char *where);
152
153 status_t prepare_l();
154 status_t start_l();
155 void notifyListener_l(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL);
156
157 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer2Driver);
158};
159
160} // namespace android
161
162