blob: 628e7328cf3e2ca83fdb514da8591c7a6287da7d [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#ifndef ANDROID_MEDIAPLAYER2_H
18#define ANDROID_MEDIAPLAYER2_H
19
Wei Jiaec044b02018-02-19 12:41:23 -080020#include <media/AVSyncSettings.h>
Wei Jia53692fa2017-12-11 10:33:46 -080021#include <media/AudioResamplerPublic.h>
22#include <media/BufferingSettings.h>
Wei Jiaec044b02018-02-19 12:41:23 -080023#include <media/Metadata.h>
24#include <media/mediaplayer_common.h>
25#include <mediaplayer2/MediaPlayer2Interface.h>
26#include <mediaplayer2/MediaPlayer2Types.h>
Wei Jia53692fa2017-12-11 10:33:46 -080027
Wei Jiaec044b02018-02-19 12:41:23 -080028#include <utils/Errors.h>
29#include <utils/Mutex.h>
30#include <utils/RefBase.h>
31#include <utils/String16.h>
32#include <utils/Vector.h>
33#include <system/audio-base.h>
Wei Jia53692fa2017-12-11 10:33:46 -080034
Wei Jia53692fa2017-12-11 10:33:46 -080035namespace android {
36
Wei Jia28288fb2017-12-15 13:45:29 -080037struct ANativeWindowWrapper;
Wei Jiac2636032018-02-01 09:15:25 -080038struct DataSourceDesc;
Wei Jiaec044b02018-02-19 12:41:23 -080039class MediaPlayer2AudioOutput;
Wei Jia53692fa2017-12-11 10:33:46 -080040
Wei Jia53692fa2017-12-11 10:33:46 -080041// ref-counted object for callbacks
42class MediaPlayer2Listener: virtual public RefBase
43{
44public:
Wei Jiad2bb1bd2018-02-08 09:47:37 -080045 virtual void notify(int64_t srcId, int msg, int ext1, int ext2, const Parcel *obj) = 0;
Wei Jia53692fa2017-12-11 10:33:46 -080046};
47
Wei Jiaec044b02018-02-19 12:41:23 -080048class MediaPlayer2 : public MediaPlayer2InterfaceListener
Wei Jia53692fa2017-12-11 10:33:46 -080049{
50public:
Wei Jia53692fa2017-12-11 10:33:46 -080051 ~MediaPlayer2();
Wei Jiaec044b02018-02-19 12:41:23 -080052
53 static sp<MediaPlayer2> Create();
54 static status_t DumpAll(int fd, const Vector<String16>& args);
55
Wei Jia53692fa2017-12-11 10:33:46 -080056 void disconnect();
57
Wei Jiad2bb1bd2018-02-08 09:47:37 -080058 status_t getSrcId(int64_t *srcId);
Wei Jiac2636032018-02-01 09:15:25 -080059 status_t setDataSource(const sp<DataSourceDesc> &dsd);
Wei Jia57aeffd2018-02-15 16:01:14 -080060 status_t prepareNextDataSource(const sp<DataSourceDesc> &dsd);
61 status_t playNextDataSource(int64_t srcId);
Wei Jia28288fb2017-12-15 13:45:29 -080062 status_t setVideoSurfaceTexture(const sp<ANativeWindowWrapper>& nww);
Wei Jia53692fa2017-12-11 10:33:46 -080063 status_t setListener(const sp<MediaPlayer2Listener>& listener);
64 status_t getBufferingSettings(BufferingSettings* buffering /* nonnull */);
65 status_t setBufferingSettings(const BufferingSettings& buffering);
Wei Jia53692fa2017-12-11 10:33:46 -080066 status_t prepareAsync();
67 status_t start();
Wei Jia53692fa2017-12-11 10:33:46 -080068 status_t pause();
69 bool isPlaying();
Wei Jia1f043e42018-06-20 16:52:50 -070070 mediaplayer2_states getState();
Wei Jia53692fa2017-12-11 10:33:46 -080071 status_t setPlaybackSettings(const AudioPlaybackRate& rate);
72 status_t getPlaybackSettings(AudioPlaybackRate* rate /* nonnull */);
73 status_t setSyncSettings(const AVSyncSettings& sync, float videoFpsHint);
74 status_t getSyncSettings(
75 AVSyncSettings* sync /* nonnull */,
76 float* videoFps /* nonnull */);
77 status_t getVideoWidth(int *w);
78 status_t getVideoHeight(int *h);
79 status_t seekTo(
Wei Jia800fe372018-02-20 15:00:45 -080080 int64_t msec,
Wei Jia53692fa2017-12-11 10:33:46 -080081 MediaPlayer2SeekMode mode = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC);
82 status_t notifyAt(int64_t mediaTimeUs);
Wei Jia800fe372018-02-20 15:00:45 -080083 status_t getCurrentPosition(int64_t *msec);
84 status_t getDuration(int64_t *msec);
Wei Jia53692fa2017-12-11 10:33:46 -080085 status_t reset();
86 status_t setAudioStreamType(audio_stream_type_t type);
87 status_t getAudioStreamType(audio_stream_type_t *type);
88 status_t setLooping(int loop);
89 bool isLooping();
90 status_t setVolume(float leftVolume, float rightVolume);
Wei Jiad2bb1bd2018-02-08 09:47:37 -080091 void notify(int64_t srcId, int msg, int ext1, int ext2,
92 const Parcel *obj = NULL);
Dongwon Kang9f631982018-07-10 12:34:41 -070093 status_t invoke(const PlayerMessage &request, PlayerMessage *reply);
Wei Jia53692fa2017-12-11 10:33:46 -080094 status_t setMetadataFilter(const Parcel& filter);
95 status_t getMetadata(bool update_only, bool apply_filter, Parcel *metadata);
96 status_t setAudioSessionId(audio_session_t sessionId);
97 audio_session_t getAudioSessionId();
98 status_t setAuxEffectSendLevel(float level);
99 status_t attachAuxEffect(int effectId);
100 status_t setParameter(int key, const Parcel& request);
101 status_t getParameter(int key, Parcel* reply);
Wei Jia53692fa2017-12-11 10:33:46 -0800102
Wei Jia53692fa2017-12-11 10:33:46 -0800103 // Modular DRM
104 status_t prepareDrm(const uint8_t uuid[16], const Vector<uint8_t>& drmSessionId);
105 status_t releaseDrm();
106 // AudioRouting
107 status_t setOutputDevice(audio_port_handle_t deviceId);
108 audio_port_handle_t getRoutedDeviceId();
109 status_t enableAudioDeviceCallback(bool enabled);
110
Wei Jiaec044b02018-02-19 12:41:23 -0800111 status_t dump(int fd, const Vector<String16>& args);
Wei Jia53692fa2017-12-11 10:33:46 -0800112
Wei Jiaec044b02018-02-19 12:41:23 -0800113private:
114 MediaPlayer2();
115 bool init();
116
117 // @param type Of the metadata to be tested.
118 // @return true if the metadata should be dropped according to
119 // the filters.
120 bool shouldDropMetadata(media::Metadata::Type type) const;
121
122 // Add a new element to the set of metadata updated. Noop if
123 // the element exists already.
124 // @param type Of the metadata to be recorded.
125 void addNewMetadataUpdate(media::Metadata::Type type);
126
127 // Disconnect from the currently connected ANativeWindow.
128 void disconnectNativeWindow_l();
129
130 status_t setAudioAttributes_l(const Parcel &request);
131
132 void clear_l();
Wei Jia800fe372018-02-20 15:00:45 -0800133 status_t seekTo_l(int64_t msec, MediaPlayer2SeekMode mode);
Wei Jiaec044b02018-02-19 12:41:23 -0800134 status_t prepareAsync_l();
Wei Jia800fe372018-02-20 15:00:45 -0800135 status_t getDuration_l(int64_t *msec);
Wei Jiaec044b02018-02-19 12:41:23 -0800136 status_t reset_l();
137 status_t checkStateForKeySet_l(int key);
138
139 pid_t mPid;
140 uid_t mUid;
141 sp<MediaPlayer2Interface> mPlayer;
142 sp<MediaPlayer2AudioOutput> mAudioOutput;
Wei Jiad2bb1bd2018-02-08 09:47:37 -0800143 int64_t mSrcId;
Wei Jia53692fa2017-12-11 10:33:46 -0800144 thread_id_t mLockThreadId;
Wei Jiaec044b02018-02-19 12:41:23 -0800145 mutable Mutex mLock;
Wei Jia53692fa2017-12-11 10:33:46 -0800146 Mutex mNotifyLock;
Wei Jia53692fa2017-12-11 10:33:46 -0800147 sp<MediaPlayer2Listener> mListener;
Wei Jia98787a72018-03-02 14:33:06 -0800148 media_player2_internal_states mCurrentState;
Wei Jia800fe372018-02-20 15:00:45 -0800149 int64_t mCurrentPosition;
Wei Jia53692fa2017-12-11 10:33:46 -0800150 MediaPlayer2SeekMode mCurrentSeekMode;
Wei Jia800fe372018-02-20 15:00:45 -0800151 int64_t mSeekPosition;
Wei Jia53692fa2017-12-11 10:33:46 -0800152 MediaPlayer2SeekMode mSeekMode;
Wei Jia53692fa2017-12-11 10:33:46 -0800153 audio_stream_type_t mStreamType;
154 Parcel* mAudioAttributesParcel;
155 bool mLoop;
156 float mLeftVolume;
157 float mRightVolume;
158 int mVideoWidth;
159 int mVideoHeight;
160 audio_session_t mAudioSessionId;
Wei Jiaec044b02018-02-19 12:41:23 -0800161 audio_attributes_t * mAudioAttributes;
Wei Jia53692fa2017-12-11 10:33:46 -0800162 float mSendLevel;
Wei Jiaec044b02018-02-19 12:41:23 -0800163
164 sp<ANativeWindowWrapper> mConnectedWindow;
165
166 // Metadata filters.
167 media::Metadata::Filter mMetadataAllow; // protected by mLock
168 media::Metadata::Filter mMetadataDrop; // protected by mLock
169
170 // Metadata updated. For each MEDIA_INFO_METADATA_UPDATE
171 // notification we try to update mMetadataUpdated which is a
172 // set: no duplicate.
173 // getMetadata clears this set.
174 media::Metadata::Filter mMetadataUpdated; // protected by mLock
Wei Jia53692fa2017-12-11 10:33:46 -0800175};
176
177}; // namespace android
178
179#endif // ANDROID_MEDIAPLAYER2_H