blob: e03b499cd6e5804150fb89d32314fdbadb76cf99 [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:
Dongwon Kang41929fb2018-09-09 08:29:56 -070045 virtual void notify(int64_t srcId, int msg, int ext1, int ext2,
46 const PlayerMessage *obj = NULL) = 0;
Wei Jia53692fa2017-12-11 10:33:46 -080047};
48
Wei Jiaec044b02018-02-19 12:41:23 -080049class MediaPlayer2 : public MediaPlayer2InterfaceListener
Wei Jia53692fa2017-12-11 10:33:46 -080050{
51public:
Wei Jia53692fa2017-12-11 10:33:46 -080052 ~MediaPlayer2();
Wei Jiaec044b02018-02-19 12:41:23 -080053
54 static sp<MediaPlayer2> Create();
55 static status_t DumpAll(int fd, const Vector<String16>& args);
56
Wei Jia53692fa2017-12-11 10:33:46 -080057 void disconnect();
58
Wei Jiad2bb1bd2018-02-08 09:47:37 -080059 status_t getSrcId(int64_t *srcId);
Wei Jiac2636032018-02-01 09:15:25 -080060 status_t setDataSource(const sp<DataSourceDesc> &dsd);
Wei Jia57aeffd2018-02-15 16:01:14 -080061 status_t prepareNextDataSource(const sp<DataSourceDesc> &dsd);
62 status_t playNextDataSource(int64_t srcId);
Wei Jia28288fb2017-12-15 13:45:29 -080063 status_t setVideoSurfaceTexture(const sp<ANativeWindowWrapper>& nww);
Wei Jia53692fa2017-12-11 10:33:46 -080064 status_t setListener(const sp<MediaPlayer2Listener>& listener);
65 status_t getBufferingSettings(BufferingSettings* buffering /* nonnull */);
66 status_t setBufferingSettings(const BufferingSettings& buffering);
Wei Jia53692fa2017-12-11 10:33:46 -080067 status_t prepareAsync();
68 status_t start();
Wei Jia53692fa2017-12-11 10:33:46 -080069 status_t pause();
70 bool isPlaying();
Wei Jia1f043e42018-06-20 16:52:50 -070071 mediaplayer2_states getState();
Wei Jia53692fa2017-12-11 10:33:46 -080072 status_t setPlaybackSettings(const AudioPlaybackRate& rate);
73 status_t getPlaybackSettings(AudioPlaybackRate* rate /* nonnull */);
74 status_t setSyncSettings(const AVSyncSettings& sync, float videoFpsHint);
75 status_t getSyncSettings(
76 AVSyncSettings* sync /* nonnull */,
77 float* videoFps /* nonnull */);
78 status_t getVideoWidth(int *w);
79 status_t getVideoHeight(int *h);
80 status_t seekTo(
Wei Jia800fe372018-02-20 15:00:45 -080081 int64_t msec,
Wei Jia53692fa2017-12-11 10:33:46 -080082 MediaPlayer2SeekMode mode = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC);
83 status_t notifyAt(int64_t mediaTimeUs);
Wei Jia800fe372018-02-20 15:00:45 -080084 status_t getCurrentPosition(int64_t *msec);
85 status_t getDuration(int64_t *msec);
Wei Jia53692fa2017-12-11 10:33:46 -080086 status_t reset();
87 status_t setAudioStreamType(audio_stream_type_t type);
88 status_t getAudioStreamType(audio_stream_type_t *type);
89 status_t setLooping(int loop);
90 bool isLooping();
91 status_t setVolume(float leftVolume, float rightVolume);
Wei Jiad2bb1bd2018-02-08 09:47:37 -080092 void notify(int64_t srcId, int msg, int ext1, int ext2,
Dongwon Kang41929fb2018-09-09 08:29:56 -070093 const PlayerMessage *obj = NULL);
Dongwon Kang9f631982018-07-10 12:34:41 -070094 status_t invoke(const PlayerMessage &request, PlayerMessage *reply);
Wei Jia53692fa2017-12-11 10:33:46 -080095 status_t setMetadataFilter(const Parcel& filter);
96 status_t getMetadata(bool update_only, bool apply_filter, Parcel *metadata);
97 status_t setAudioSessionId(audio_session_t sessionId);
98 audio_session_t getAudioSessionId();
99 status_t setAuxEffectSendLevel(float level);
100 status_t attachAuxEffect(int effectId);
101 status_t setParameter(int key, const Parcel& request);
102 status_t getParameter(int key, Parcel* reply);
Wei Jia53692fa2017-12-11 10:33:46 -0800103
Wei Jia53692fa2017-12-11 10:33:46 -0800104 // Modular DRM
105 status_t prepareDrm(const uint8_t uuid[16], const Vector<uint8_t>& drmSessionId);
106 status_t releaseDrm();
107 // AudioRouting
108 status_t setOutputDevice(audio_port_handle_t deviceId);
109 audio_port_handle_t getRoutedDeviceId();
110 status_t enableAudioDeviceCallback(bool enabled);
111
Wei Jiaec044b02018-02-19 12:41:23 -0800112 status_t dump(int fd, const Vector<String16>& args);
Wei Jia53692fa2017-12-11 10:33:46 -0800113
Wei Jiaec044b02018-02-19 12:41:23 -0800114private:
115 MediaPlayer2();
116 bool init();
117
118 // @param type Of the metadata to be tested.
119 // @return true if the metadata should be dropped according to
120 // the filters.
121 bool shouldDropMetadata(media::Metadata::Type type) const;
122
123 // Add a new element to the set of metadata updated. Noop if
124 // the element exists already.
125 // @param type Of the metadata to be recorded.
126 void addNewMetadataUpdate(media::Metadata::Type type);
127
128 // Disconnect from the currently connected ANativeWindow.
129 void disconnectNativeWindow_l();
130
131 status_t setAudioAttributes_l(const Parcel &request);
132
133 void clear_l();
Wei Jia800fe372018-02-20 15:00:45 -0800134 status_t seekTo_l(int64_t msec, MediaPlayer2SeekMode mode);
Wei Jiaec044b02018-02-19 12:41:23 -0800135 status_t prepareAsync_l();
Wei Jia800fe372018-02-20 15:00:45 -0800136 status_t getDuration_l(int64_t *msec);
Wei Jiaec044b02018-02-19 12:41:23 -0800137 status_t reset_l();
138 status_t checkStateForKeySet_l(int key);
139
140 pid_t mPid;
141 uid_t mUid;
142 sp<MediaPlayer2Interface> mPlayer;
143 sp<MediaPlayer2AudioOutput> mAudioOutput;
Wei Jiad2bb1bd2018-02-08 09:47:37 -0800144 int64_t mSrcId;
Wei Jia53692fa2017-12-11 10:33:46 -0800145 thread_id_t mLockThreadId;
Wei Jiaec044b02018-02-19 12:41:23 -0800146 mutable Mutex mLock;
Wei Jia53692fa2017-12-11 10:33:46 -0800147 Mutex mNotifyLock;
Wei Jia53692fa2017-12-11 10:33:46 -0800148 sp<MediaPlayer2Listener> mListener;
Wei Jia98787a72018-03-02 14:33:06 -0800149 media_player2_internal_states mCurrentState;
Wei Jia800fe372018-02-20 15:00:45 -0800150 int64_t mCurrentPosition;
Wei Jia53692fa2017-12-11 10:33:46 -0800151 MediaPlayer2SeekMode mCurrentSeekMode;
Wei Jia800fe372018-02-20 15:00:45 -0800152 int64_t mSeekPosition;
Wei Jia53692fa2017-12-11 10:33:46 -0800153 MediaPlayer2SeekMode mSeekMode;
Wei Jia53692fa2017-12-11 10:33:46 -0800154 audio_stream_type_t mStreamType;
155 Parcel* mAudioAttributesParcel;
156 bool mLoop;
157 float mLeftVolume;
158 float mRightVolume;
159 int mVideoWidth;
160 int mVideoHeight;
161 audio_session_t mAudioSessionId;
Wei Jiaec044b02018-02-19 12:41:23 -0800162 audio_attributes_t * mAudioAttributes;
Wei Jia53692fa2017-12-11 10:33:46 -0800163 float mSendLevel;
Wei Jiaec044b02018-02-19 12:41:23 -0800164
165 sp<ANativeWindowWrapper> mConnectedWindow;
166
167 // Metadata filters.
168 media::Metadata::Filter mMetadataAllow; // protected by mLock
169 media::Metadata::Filter mMetadataDrop; // protected by mLock
170
171 // Metadata updated. For each MEDIA_INFO_METADATA_UPDATE
172 // notification we try to update mMetadataUpdated which is a
173 // set: no duplicate.
174 // getMetadata clears this set.
175 media::Metadata::Filter mMetadataUpdated; // protected by mLock
Wei Jia53692fa2017-12-11 10:33:46 -0800176};
177
178}; // namespace android
179
180#endif // ANDROID_MEDIAPLAYER2_H