blob: a6463995925d94fbf0806d8cbcb06d9217a733a1 [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
Dichen Zhangf8726912018-10-17 13:31:26 -070028#include <vector>
29#include <jni.h>
Wei Jiaec044b02018-02-19 12:41:23 -080030#include <utils/Errors.h>
31#include <utils/Mutex.h>
32#include <utils/RefBase.h>
33#include <utils/String16.h>
34#include <utils/Vector.h>
35#include <system/audio-base.h>
Wei Jia53692fa2017-12-11 10:33:46 -080036
Dongwon Kang0d7042d2018-10-12 16:52:14 -070037#include "jni.h"
38
Wei Jia53692fa2017-12-11 10:33:46 -080039namespace android {
40
Wei Jia28288fb2017-12-15 13:45:29 -080041struct ANativeWindowWrapper;
Wei Jiac2636032018-02-01 09:15:25 -080042struct DataSourceDesc;
Wei Jiaec044b02018-02-19 12:41:23 -080043class MediaPlayer2AudioOutput;
Wei Jia53692fa2017-12-11 10:33:46 -080044
Wei Jia53692fa2017-12-11 10:33:46 -080045// ref-counted object for callbacks
46class MediaPlayer2Listener: virtual public RefBase
47{
48public:
Dongwon Kang41929fb2018-09-09 08:29:56 -070049 virtual void notify(int64_t srcId, int msg, int ext1, int ext2,
50 const PlayerMessage *obj = NULL) = 0;
Wei Jia53692fa2017-12-11 10:33:46 -080051};
52
Wei Jiaec044b02018-02-19 12:41:23 -080053class MediaPlayer2 : public MediaPlayer2InterfaceListener
Wei Jia53692fa2017-12-11 10:33:46 -080054{
55public:
Wei Jia53692fa2017-12-11 10:33:46 -080056 ~MediaPlayer2();
Wei Jiaec044b02018-02-19 12:41:23 -080057
58 static sp<MediaPlayer2> Create();
59 static status_t DumpAll(int fd, const Vector<String16>& args);
60
Wei Jia53692fa2017-12-11 10:33:46 -080061 void disconnect();
62
Wei Jiad2bb1bd2018-02-08 09:47:37 -080063 status_t getSrcId(int64_t *srcId);
Wei Jiac2636032018-02-01 09:15:25 -080064 status_t setDataSource(const sp<DataSourceDesc> &dsd);
Wei Jia57aeffd2018-02-15 16:01:14 -080065 status_t prepareNextDataSource(const sp<DataSourceDesc> &dsd);
66 status_t playNextDataSource(int64_t srcId);
Wei Jia28288fb2017-12-15 13:45:29 -080067 status_t setVideoSurfaceTexture(const sp<ANativeWindowWrapper>& nww);
Wei Jia53692fa2017-12-11 10:33:46 -080068 status_t setListener(const sp<MediaPlayer2Listener>& listener);
69 status_t getBufferingSettings(BufferingSettings* buffering /* nonnull */);
70 status_t setBufferingSettings(const BufferingSettings& buffering);
Wei Jia53692fa2017-12-11 10:33:46 -080071 status_t prepareAsync();
72 status_t start();
Wei Jia53692fa2017-12-11 10:33:46 -080073 status_t pause();
74 bool isPlaying();
Wei Jia1f043e42018-06-20 16:52:50 -070075 mediaplayer2_states getState();
Wei Jia53692fa2017-12-11 10:33:46 -080076 status_t setPlaybackSettings(const AudioPlaybackRate& rate);
77 status_t getPlaybackSettings(AudioPlaybackRate* rate /* nonnull */);
78 status_t setSyncSettings(const AVSyncSettings& sync, float videoFpsHint);
79 status_t getSyncSettings(
80 AVSyncSettings* sync /* nonnull */,
81 float* videoFps /* nonnull */);
82 status_t getVideoWidth(int *w);
83 status_t getVideoHeight(int *h);
84 status_t seekTo(
Wei Jia800fe372018-02-20 15:00:45 -080085 int64_t msec,
Wei Jia53692fa2017-12-11 10:33:46 -080086 MediaPlayer2SeekMode mode = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC);
87 status_t notifyAt(int64_t mediaTimeUs);
Wei Jia800fe372018-02-20 15:00:45 -080088 status_t getCurrentPosition(int64_t *msec);
89 status_t getDuration(int64_t *msec);
Wei Jia53692fa2017-12-11 10:33:46 -080090 status_t reset();
91 status_t setAudioStreamType(audio_stream_type_t type);
92 status_t getAudioStreamType(audio_stream_type_t *type);
93 status_t setLooping(int loop);
94 bool isLooping();
Dichen Zhang7398ca02018-10-15 10:25:12 -070095 status_t setVolume(float volume);
Wei Jiad2bb1bd2018-02-08 09:47:37 -080096 void notify(int64_t srcId, int msg, int ext1, int ext2,
Dongwon Kang41929fb2018-09-09 08:29:56 -070097 const PlayerMessage *obj = NULL);
Dongwon Kang9f631982018-07-10 12:34:41 -070098 status_t invoke(const PlayerMessage &request, PlayerMessage *reply);
Wei Jia53692fa2017-12-11 10:33:46 -080099 status_t setAudioSessionId(audio_session_t sessionId);
100 audio_session_t getAudioSessionId();
101 status_t setAuxEffectSendLevel(float level);
102 status_t attachAuxEffect(int effectId);
103 status_t setParameter(int key, const Parcel& request);
104 status_t getParameter(int key, Parcel* reply);
Wei Jia53692fa2017-12-11 10:33:46 -0800105
Wei Jia53692fa2017-12-11 10:33:46 -0800106 // Modular DRM
107 status_t prepareDrm(const uint8_t uuid[16], const Vector<uint8_t>& drmSessionId);
108 status_t releaseDrm();
109 // AudioRouting
Dongwon Kang0d7042d2018-10-12 16:52:14 -0700110 status_t setPreferredDevice(jobject device);
111 jobject getRoutedDevice();
Dichen Zhangf8726912018-10-17 13:31:26 -0700112 status_t addAudioDeviceCallback(jobject routingDelegate);
113 status_t removeAudioDeviceCallback(jobject listener);
Wei Jia53692fa2017-12-11 10:33:46 -0800114
Wei Jiaec044b02018-02-19 12:41:23 -0800115 status_t dump(int fd, const Vector<String16>& args);
Wei Jia53692fa2017-12-11 10:33:46 -0800116
Wei Jiaec044b02018-02-19 12:41:23 -0800117private:
118 MediaPlayer2();
119 bool init();
120
Wei Jiaec044b02018-02-19 12:41:23 -0800121 // Disconnect from the currently connected ANativeWindow.
122 void disconnectNativeWindow_l();
123
124 status_t setAudioAttributes_l(const Parcel &request);
125
126 void clear_l();
Wei Jia800fe372018-02-20 15:00:45 -0800127 status_t seekTo_l(int64_t msec, MediaPlayer2SeekMode mode);
Wei Jiaec044b02018-02-19 12:41:23 -0800128 status_t prepareAsync_l();
Wei Jia800fe372018-02-20 15:00:45 -0800129 status_t getDuration_l(int64_t *msec);
Wei Jiaec044b02018-02-19 12:41:23 -0800130 status_t reset_l();
131 status_t checkStateForKeySet_l(int key);
132
133 pid_t mPid;
134 uid_t mUid;
135 sp<MediaPlayer2Interface> mPlayer;
136 sp<MediaPlayer2AudioOutput> mAudioOutput;
Wei Jiad2bb1bd2018-02-08 09:47:37 -0800137 int64_t mSrcId;
Wei Jia53692fa2017-12-11 10:33:46 -0800138 thread_id_t mLockThreadId;
Wei Jiaec044b02018-02-19 12:41:23 -0800139 mutable Mutex mLock;
Wei Jia53692fa2017-12-11 10:33:46 -0800140 Mutex mNotifyLock;
Wei Jia53692fa2017-12-11 10:33:46 -0800141 sp<MediaPlayer2Listener> mListener;
Wei Jia98787a72018-03-02 14:33:06 -0800142 media_player2_internal_states mCurrentState;
Wei Jia800fe372018-02-20 15:00:45 -0800143 int64_t mCurrentPosition;
Wei Jia53692fa2017-12-11 10:33:46 -0800144 MediaPlayer2SeekMode mCurrentSeekMode;
Wei Jia800fe372018-02-20 15:00:45 -0800145 int64_t mSeekPosition;
Wei Jia53692fa2017-12-11 10:33:46 -0800146 MediaPlayer2SeekMode mSeekMode;
Wei Jia53692fa2017-12-11 10:33:46 -0800147 audio_stream_type_t mStreamType;
148 Parcel* mAudioAttributesParcel;
149 bool mLoop;
Dichen Zhang7398ca02018-10-15 10:25:12 -0700150 float mVolume;
Wei Jia53692fa2017-12-11 10:33:46 -0800151 int mVideoWidth;
152 int mVideoHeight;
153 audio_session_t mAudioSessionId;
Wei Jiaec044b02018-02-19 12:41:23 -0800154 audio_attributes_t * mAudioAttributes;
Wei Jia53692fa2017-12-11 10:33:46 -0800155 float mSendLevel;
Dichen Zhangf8726912018-10-17 13:31:26 -0700156 std::vector<jobject> mRoutingDelegates;
Wei Jiaec044b02018-02-19 12:41:23 -0800157 sp<ANativeWindowWrapper> mConnectedWindow;
Wei Jia53692fa2017-12-11 10:33:46 -0800158};
159
160}; // namespace android
161
162#endif // ANDROID_MEDIAPLAYER2_H