blob: 9b784aece7153734c47986c3437be64aff7e9ef4 [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 Essickd4d00612017-01-03 09:36:27 -080019#include <media/MediaAnalyticsItem.h>
Andreas Huberf9334412010-12-15 15:17:42 -080020#include <media/stagefright/foundation/ABase.h>
21
22namespace android {
23
24struct ALooper;
25struct NuPlayer;
26
27struct NuPlayerDriver : public MediaPlayerInterface {
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -070028 explicit NuPlayerDriver(pid_t pid);
Andreas Huberf9334412010-12-15 15:17:42 -080029
30 virtual status_t initCheck();
31
Andreas Huber9b80c2b2011-06-30 15:47:02 -070032 virtual status_t setUID(uid_t uid);
33
Andreas Huberf9334412010-12-15 15:17:42 -080034 virtual status_t setDataSource(
Andreas Huber1b86fe02014-01-29 11:13:26 -080035 const sp<IMediaHTTPService> &httpService,
36 const char *url,
37 const KeyedVector<String8, String8> *headers);
Andreas Huberf9334412010-12-15 15:17:42 -080038
39 virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
40
41 virtual status_t setDataSource(const sp<IStreamSource> &source);
42
Chris Watkins99f31602015-03-20 13:06:33 -070043 virtual status_t setDataSource(const sp<DataSource>& dataSource);
44
Glenn Kasten11731182011-02-08 17:26:17 -080045 virtual status_t setVideoSurfaceTexture(
Andy McFadden8ba01022012-12-18 09:46:54 -080046 const sp<IGraphicBufferProducer> &bufferProducer);
Andreas Huberf9334412010-12-15 15:17:42 -080047 virtual status_t prepare();
48 virtual status_t prepareAsync();
49 virtual status_t start();
50 virtual status_t stop();
51 virtual status_t pause();
52 virtual bool isPlaying();
Lajos Molnar3a474aa2015-04-24 17:10:07 -070053 virtual status_t setPlaybackSettings(const AudioPlaybackRate &rate);
54 virtual status_t getPlaybackSettings(AudioPlaybackRate *rate);
55 virtual status_t setSyncSettings(const AVSyncSettings &sync, float videoFpsHint);
56 virtual status_t getSyncSettings(AVSyncSettings *sync, float *videoFps);
Wei Jiac5de0912016-11-18 10:22:14 -080057 virtual status_t seekTo(
58 int msec, MediaPlayerSeekMode mode = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC);
Andreas Huberf9334412010-12-15 15:17:42 -080059 virtual status_t getCurrentPosition(int *msec);
60 virtual status_t getDuration(int *msec);
61 virtual status_t reset();
62 virtual status_t setLooping(int loop);
63 virtual player_type playerType();
64 virtual status_t invoke(const Parcel &request, Parcel *reply);
65 virtual void setAudioSink(const sp<AudioSink> &audioSink);
Gloria Wang4f9e47f2011-04-25 17:28:22 -070066 virtual status_t setParameter(int key, const Parcel &request);
67 virtual status_t getParameter(int key, Parcel *reply);
Andreas Huberf9334412010-12-15 15:17:42 -080068
69 virtual status_t getMetadata(
70 const media::Metadata::Filter& ids, Parcel *records);
71
Andreas Huber3fe62152011-09-16 15:09:22 -070072 virtual status_t dump(int fd, const Vector<String16> &args) const;
73
Andreas Huber9575c962013-02-05 13:59:56 -080074 void notifySetDataSourceCompleted(status_t err);
75 void notifyPrepareCompleted(status_t err);
Andreas Huber43c3e6c2011-01-05 12:17:08 -080076 void notifyResetComplete();
Chong Zhang13d6faa2014-08-22 15:35:28 -070077 void notifySetSurfaceComplete();
Andreas Huber43c3e6c2011-01-05 12:17:08 -080078 void notifyDuration(int64_t durationUs);
Ray Essickd4d00612017-01-03 09:36:27 -080079 void notifyMorePlayingTimeUs(int64_t timeUs);
Andreas Huber43c3e6c2011-01-05 12:17:08 -080080 void notifySeekComplete();
Marco Nelisseneb645a02014-08-20 09:44:44 -070081 void notifySeekComplete_l();
Chong Zhangdcb89b32013-08-06 09:44:47 -070082 void notifyListener(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL);
Andreas Huber9575c962013-02-05 13:59:56 -080083 void notifyFlagsChanged(uint32_t flags);
Andreas Huber1aef2112011-01-04 14:01:29 -080084
Andreas Huberf9334412010-12-15 15:17:42 -080085protected:
86 virtual ~NuPlayerDriver();
87
88private:
Andreas Huber9575c962013-02-05 13:59:56 -080089 enum State {
90 STATE_IDLE,
91 STATE_SET_DATASOURCE_PENDING,
92 STATE_UNPREPARED,
93 STATE_PREPARING,
94 STATE_PREPARED,
95 STATE_RUNNING,
96 STATE_PAUSED,
97 STATE_RESET_IN_PROGRESS,
Lajos Molnar4b75b862013-08-15 15:59:19 -070098 STATE_STOPPED, // equivalent to PAUSED
99 STATE_STOPPED_AND_PREPARING, // equivalent to PAUSED, but seeking
100 STATE_STOPPED_AND_PREPARED, // equivalent to PAUSED, but seek complete
Andreas Huber9575c962013-02-05 13:59:56 -0800101 };
102
Andreas Huber3fe62152011-09-16 15:09:22 -0700103 mutable Mutex mLock;
Andreas Huber1aef2112011-01-04 14:01:29 -0800104 Condition mCondition;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800105
Andreas Huber9575c962013-02-05 13:59:56 -0800106 State mState;
107
Andreas Huberec0c5972013-02-05 14:47:13 -0800108 bool mIsAsyncPrepare;
Andreas Huber9575c962013-02-05 13:59:56 -0800109 status_t mAsyncResult;
110
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800111 // The following are protected through "mLock"
112 // >>>
Chong Zhang13d6faa2014-08-22 15:35:28 -0700113 bool mSetSurfaceInProgress;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800114 int64_t mDurationUs;
115 int64_t mPositionUs;
Ronghua Wua73d9e02014-10-08 15:13:29 -0700116 bool mSeekInProgress;
Ray Essickd4d00612017-01-03 09:36:27 -0800117 int64_t mPlayingTimeUs;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800118 // <<<
Andreas Huber1aef2112011-01-04 14:01:29 -0800119
Andreas Huberf9334412010-12-15 15:17:42 -0800120 sp<ALooper> mLooper;
121 sp<NuPlayer> mPlayer;
Marco Nelissenf0b72b52014-09-16 15:43:44 -0700122 sp<AudioSink> mAudioSink;
Andreas Huber9575c962013-02-05 13:59:56 -0800123 uint32_t mPlayerFlags;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800124
Ray Essickd4d00612017-01-03 09:36:27 -0800125 MediaAnalyticsItem *mAnalyticsItem;
126
Andreas Hubera4af2142011-10-26 15:23:31 -0700127 bool mAtEOS;
Lajos Molnara2e14302014-07-31 12:07:58 -0700128 bool mLooping;
Marco Nelissenf0b72b52014-09-16 15:43:44 -0700129 bool mAutoLoop;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800130
Ray Essickd4d00612017-01-03 09:36:27 -0800131 void finalizeMetrics(const char *where);
132 void logMetrics(const char *where);
133
Andreas Huber9575c962013-02-05 13:59:56 -0800134 status_t prepare_l();
Wei Jia8a092d32016-06-03 14:57:24 -0700135 status_t start_l();
Wei Jia05601952014-08-20 18:21:11 -0700136 void notifyListener_l(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL);
Andreas Huber9575c962013-02-05 13:59:56 -0800137
Andreas Huberf9334412010-12-15 15:17:42 -0800138 DISALLOW_EVIL_CONSTRUCTORS(NuPlayerDriver);
139};
140
141} // namespace android
142
143