blob: 18254a15fea16e6ef3bade84acb1d733cbe76b2f [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 setAudioSessionId(audio_session_t sessionId);
96 audio_session_t getAudioSessionId();
97 status_t setAuxEffectSendLevel(float level);
98 status_t attachAuxEffect(int effectId);
99 status_t setParameter(int key, const Parcel& request);
100 status_t getParameter(int key, Parcel* reply);
Wei Jia53692fa2017-12-11 10:33:46 -0800101
Wei Jia53692fa2017-12-11 10:33:46 -0800102 // Modular DRM
103 status_t prepareDrm(const uint8_t uuid[16], const Vector<uint8_t>& drmSessionId);
104 status_t releaseDrm();
105 // AudioRouting
106 status_t setOutputDevice(audio_port_handle_t deviceId);
107 audio_port_handle_t getRoutedDeviceId();
108 status_t enableAudioDeviceCallback(bool enabled);
109
Wei Jiaec044b02018-02-19 12:41:23 -0800110 status_t dump(int fd, const Vector<String16>& args);
Wei Jia53692fa2017-12-11 10:33:46 -0800111
Wei Jiaec044b02018-02-19 12:41:23 -0800112private:
113 MediaPlayer2();
114 bool init();
115
Wei Jiaec044b02018-02-19 12:41:23 -0800116 // Disconnect from the currently connected ANativeWindow.
117 void disconnectNativeWindow_l();
118
119 status_t setAudioAttributes_l(const Parcel &request);
120
121 void clear_l();
Wei Jia800fe372018-02-20 15:00:45 -0800122 status_t seekTo_l(int64_t msec, MediaPlayer2SeekMode mode);
Wei Jiaec044b02018-02-19 12:41:23 -0800123 status_t prepareAsync_l();
Wei Jia800fe372018-02-20 15:00:45 -0800124 status_t getDuration_l(int64_t *msec);
Wei Jiaec044b02018-02-19 12:41:23 -0800125 status_t reset_l();
126 status_t checkStateForKeySet_l(int key);
127
128 pid_t mPid;
129 uid_t mUid;
130 sp<MediaPlayer2Interface> mPlayer;
131 sp<MediaPlayer2AudioOutput> mAudioOutput;
Wei Jiad2bb1bd2018-02-08 09:47:37 -0800132 int64_t mSrcId;
Wei Jia53692fa2017-12-11 10:33:46 -0800133 thread_id_t mLockThreadId;
Wei Jiaec044b02018-02-19 12:41:23 -0800134 mutable Mutex mLock;
Wei Jia53692fa2017-12-11 10:33:46 -0800135 Mutex mNotifyLock;
Wei Jia53692fa2017-12-11 10:33:46 -0800136 sp<MediaPlayer2Listener> mListener;
Wei Jia98787a72018-03-02 14:33:06 -0800137 media_player2_internal_states mCurrentState;
Wei Jia800fe372018-02-20 15:00:45 -0800138 int64_t mCurrentPosition;
Wei Jia53692fa2017-12-11 10:33:46 -0800139 MediaPlayer2SeekMode mCurrentSeekMode;
Wei Jia800fe372018-02-20 15:00:45 -0800140 int64_t mSeekPosition;
Wei Jia53692fa2017-12-11 10:33:46 -0800141 MediaPlayer2SeekMode mSeekMode;
Wei Jia53692fa2017-12-11 10:33:46 -0800142 audio_stream_type_t mStreamType;
143 Parcel* mAudioAttributesParcel;
144 bool mLoop;
145 float mLeftVolume;
146 float mRightVolume;
147 int mVideoWidth;
148 int mVideoHeight;
149 audio_session_t mAudioSessionId;
Wei Jiaec044b02018-02-19 12:41:23 -0800150 audio_attributes_t * mAudioAttributes;
Wei Jia53692fa2017-12-11 10:33:46 -0800151 float mSendLevel;
Wei Jiaec044b02018-02-19 12:41:23 -0800152
153 sp<ANativeWindowWrapper> mConnectedWindow;
Wei Jia53692fa2017-12-11 10:33:46 -0800154};
155
156}; // namespace android
157
158#endif // ANDROID_MEDIAPLAYER2_H