The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 18 | #include <arpa/inet.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | #include <sys/types.h> |
| 21 | |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 22 | #include <android/IDataSource.h> |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 23 | #include <binder/Parcel.h> |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 24 | #include <gui/IGraphicBufferProducer.h> |
Lajos Molnar | 3a474aa | 2015-04-24 17:10:07 -0700 | [diff] [blame] | 25 | #include <media/AudioResamplerPublic.h> |
| 26 | #include <media/AVSyncSettings.h> |
Wei Jia | d399e7e | 2016-10-26 15:49:11 -0700 | [diff] [blame] | 27 | #include <media/BufferingSettings.h> |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 28 | #include <media/IMediaHTTPService.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include <media/IMediaPlayer.h> |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 30 | #include <media/IStreamSource.h> |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 31 | #include <utils/String8.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | |
| 33 | namespace android { |
| 34 | |
Ivan Lozano | 8cf3a07 | 2017-08-09 09:01:33 -0700 | [diff] [blame] | 35 | using media::VolumeShaper; |
| 36 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | enum { |
| 38 | DISCONNECT = IBinder::FIRST_CALL_TRANSACTION, |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 39 | SET_DATA_SOURCE_URL, |
| 40 | SET_DATA_SOURCE_FD, |
| 41 | SET_DATA_SOURCE_STREAM, |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 42 | SET_DATA_SOURCE_CALLBACK, |
Byeongjo Park | 28225ab | 2019-01-24 20:31:19 +0900 | [diff] [blame] | 43 | SET_DATA_SOURCE_RTP, |
Wei Jia | d399e7e | 2016-10-26 15:49:11 -0700 | [diff] [blame] | 44 | SET_BUFFERING_SETTINGS, |
Wei Jia | 9bb3803 | 2017-03-23 18:00:38 -0700 | [diff] [blame] | 45 | GET_BUFFERING_SETTINGS, |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | PREPARE_ASYNC, |
| 47 | START, |
| 48 | STOP, |
| 49 | IS_PLAYING, |
Lajos Molnar | 3a474aa | 2015-04-24 17:10:07 -0700 | [diff] [blame] | 50 | SET_PLAYBACK_SETTINGS, |
| 51 | GET_PLAYBACK_SETTINGS, |
| 52 | SET_SYNC_SETTINGS, |
| 53 | GET_SYNC_SETTINGS, |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | PAUSE, |
| 55 | SEEK_TO, |
| 56 | GET_CURRENT_POSITION, |
| 57 | GET_DURATION, |
| 58 | RESET, |
Wei Jia | 52c2851 | 2017-09-13 18:17:51 -0700 | [diff] [blame] | 59 | NOTIFY_AT, |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | SET_AUDIO_STREAM_TYPE, |
| 61 | SET_LOOPING, |
Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 62 | SET_VOLUME, |
| 63 | INVOKE, |
Nicolas Catania | a7e0e8b | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 64 | SET_METADATA_FILTER, |
Nicolas Catania | 8e1b6cc | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 65 | GET_METADATA, |
Eric Laurent | 2beeb50 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 66 | SET_AUX_EFFECT_SEND_LEVEL, |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 67 | ATTACH_AUX_EFFECT, |
| 68 | SET_VIDEO_SURFACETEXTURE, |
Gloria Wang | 4f9e47f | 2011-04-25 17:28:22 -0700 | [diff] [blame] | 69 | SET_PARAMETER, |
| 70 | GET_PARAMETER, |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 71 | SET_RETRANSMIT_ENDPOINT, |
John Grossman | 44a7e42 | 2012-06-21 17:29:24 -0700 | [diff] [blame] | 72 | GET_RETRANSMIT_ENDPOINT, |
Marco Nelissen | 6b74d67 | 2012-02-28 16:07:44 -0800 | [diff] [blame] | 73 | SET_NEXT_PLAYER, |
Andy Hung | 9fc8b5c | 2017-01-24 13:36:48 -0800 | [diff] [blame] | 74 | APPLY_VOLUME_SHAPER, |
| 75 | GET_VOLUME_SHAPER_STATE, |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 76 | // Modular DRM |
Hassan Shojania | 071437a | 2017-01-23 09:19:40 -0800 | [diff] [blame] | 77 | PREPARE_DRM, |
| 78 | RELEASE_DRM, |
jiabin | 156c687 | 2017-10-06 09:47:15 -0700 | [diff] [blame] | 79 | // AudioRouting |
| 80 | SET_OUTPUT_DEVICE, |
| 81 | GET_ROUTED_DEVICE_ID, |
| 82 | ENABLE_AUDIO_DEVICE_CALLBACK, |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
Hassan Shojania | 071437a | 2017-01-23 09:19:40 -0800 | [diff] [blame] | 85 | // ModDrm helpers |
| 86 | static void readVector(const Parcel& reply, Vector<uint8_t>& vector) { |
| 87 | uint32_t size = reply.readUint32(); |
| 88 | vector.insertAt((size_t)0, size); |
| 89 | reply.read(vector.editArray(), size); |
| 90 | } |
| 91 | |
| 92 | static void writeVector(Parcel& data, Vector<uint8_t> const& vector) { |
| 93 | data.writeUint32(vector.size()); |
| 94 | data.write(vector.array(), vector.size()); |
| 95 | } |
| 96 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | class BpMediaPlayer: public BpInterface<IMediaPlayer> |
| 98 | { |
| 99 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 100 | explicit BpMediaPlayer(const sp<IBinder>& impl) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | : BpInterface<IMediaPlayer>(impl) |
| 102 | { |
| 103 | } |
| 104 | |
| 105 | // disconnect from media player service |
| 106 | void disconnect() |
| 107 | { |
| 108 | Parcel data, reply; |
| 109 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 110 | remote()->transact(DISCONNECT, data, &reply); |
| 111 | } |
| 112 | |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 113 | status_t setDataSource( |
| 114 | const sp<IMediaHTTPService> &httpService, |
| 115 | const char* url, |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 116 | const KeyedVector<String8, String8>* headers) |
| 117 | { |
| 118 | Parcel data, reply; |
| 119 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 120 | data.writeInt32(httpService != NULL); |
| 121 | if (httpService != NULL) { |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 122 | data.writeStrongBinder(IInterface::asBinder(httpService)); |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 123 | } |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 124 | data.writeCString(url); |
| 125 | if (headers == NULL) { |
| 126 | data.writeInt32(0); |
| 127 | } else { |
| 128 | // serialize the headers |
| 129 | data.writeInt32(headers->size()); |
| 130 | for (size_t i = 0; i < headers->size(); ++i) { |
| 131 | data.writeString8(headers->keyAt(i)); |
| 132 | data.writeString8(headers->valueAt(i)); |
| 133 | } |
| 134 | } |
| 135 | remote()->transact(SET_DATA_SOURCE_URL, data, &reply); |
| 136 | return reply.readInt32(); |
| 137 | } |
| 138 | |
| 139 | status_t setDataSource(int fd, int64_t offset, int64_t length) { |
| 140 | Parcel data, reply; |
| 141 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 142 | data.writeFileDescriptor(fd); |
| 143 | data.writeInt64(offset); |
| 144 | data.writeInt64(length); |
| 145 | remote()->transact(SET_DATA_SOURCE_FD, data, &reply); |
| 146 | return reply.readInt32(); |
| 147 | } |
| 148 | |
| 149 | status_t setDataSource(const sp<IStreamSource> &source) { |
| 150 | Parcel data, reply; |
| 151 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 152 | data.writeStrongBinder(IInterface::asBinder(source)); |
Glenn Kasten | 8d65510 | 2011-09-07 14:40:23 -0700 | [diff] [blame] | 153 | remote()->transact(SET_DATA_SOURCE_STREAM, data, &reply); |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 154 | return reply.readInt32(); |
| 155 | } |
| 156 | |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 157 | status_t setDataSource(const sp<IDataSource> &source) { |
| 158 | Parcel data, reply; |
| 159 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 160 | data.writeStrongBinder(IInterface::asBinder(source)); |
| 161 | remote()->transact(SET_DATA_SOURCE_CALLBACK, data, &reply); |
| 162 | return reply.readInt32(); |
| 163 | } |
| 164 | |
Byeongjo Park | 28225ab | 2019-01-24 20:31:19 +0900 | [diff] [blame] | 165 | status_t setDataSource(const String8& rtpParams) { |
| 166 | Parcel data, reply; |
| 167 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 168 | data.writeString8(rtpParams); |
| 169 | remote()->transact(SET_DATA_SOURCE_RTP, data, &reply); |
| 170 | |
| 171 | return reply.readInt32(); |
| 172 | } |
| 173 | |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 174 | // pass the buffered IGraphicBufferProducer to the media player service |
| 175 | status_t setVideoSurfaceTexture(const sp<IGraphicBufferProducer>& bufferProducer) |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 176 | { |
| 177 | Parcel data, reply; |
| 178 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 179 | sp<IBinder> b(IInterface::asBinder(bufferProducer)); |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 180 | data.writeStrongBinder(b); |
| 181 | remote()->transact(SET_VIDEO_SURFACETEXTURE, data, &reply); |
| 182 | return reply.readInt32(); |
| 183 | } |
| 184 | |
Wei Jia | d399e7e | 2016-10-26 15:49:11 -0700 | [diff] [blame] | 185 | status_t setBufferingSettings(const BufferingSettings& buffering) |
| 186 | { |
| 187 | Parcel data, reply; |
| 188 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
Dongwon Kang | 79e3373 | 2019-01-25 16:35:26 -0800 | [diff] [blame] | 189 | data.writeInt32(buffering.mInitialMarkMs); |
| 190 | data.writeInt32(buffering.mResumePlaybackMarkMs); |
Wei Jia | d399e7e | 2016-10-26 15:49:11 -0700 | [diff] [blame] | 191 | remote()->transact(SET_BUFFERING_SETTINGS, data, &reply); |
| 192 | return reply.readInt32(); |
| 193 | } |
| 194 | |
Wei Jia | 9bb3803 | 2017-03-23 18:00:38 -0700 | [diff] [blame] | 195 | status_t getBufferingSettings(BufferingSettings* buffering /* nonnull */) |
Wei Jia | d399e7e | 2016-10-26 15:49:11 -0700 | [diff] [blame] | 196 | { |
| 197 | if (buffering == nullptr) { |
| 198 | return BAD_VALUE; |
| 199 | } |
| 200 | Parcel data, reply; |
| 201 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
Wei Jia | 9bb3803 | 2017-03-23 18:00:38 -0700 | [diff] [blame] | 202 | remote()->transact(GET_BUFFERING_SETTINGS, data, &reply); |
Wei Jia | d399e7e | 2016-10-26 15:49:11 -0700 | [diff] [blame] | 203 | status_t err = reply.readInt32(); |
| 204 | if (err == OK) { |
Dongwon Kang | 79e3373 | 2019-01-25 16:35:26 -0800 | [diff] [blame] | 205 | buffering->mInitialMarkMs = reply.readInt32(); |
| 206 | buffering->mResumePlaybackMarkMs = reply.readInt32(); |
Wei Jia | d399e7e | 2016-10-26 15:49:11 -0700 | [diff] [blame] | 207 | } |
| 208 | return err; |
| 209 | } |
| 210 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | status_t prepareAsync() |
| 212 | { |
| 213 | Parcel data, reply; |
| 214 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 215 | remote()->transact(PREPARE_ASYNC, data, &reply); |
| 216 | return reply.readInt32(); |
| 217 | } |
| 218 | |
| 219 | status_t start() |
| 220 | { |
| 221 | Parcel data, reply; |
| 222 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 223 | remote()->transact(START, data, &reply); |
| 224 | return reply.readInt32(); |
| 225 | } |
| 226 | |
| 227 | status_t stop() |
| 228 | { |
| 229 | Parcel data, reply; |
| 230 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 231 | remote()->transact(STOP, data, &reply); |
| 232 | return reply.readInt32(); |
| 233 | } |
| 234 | |
| 235 | status_t isPlaying(bool* state) |
| 236 | { |
| 237 | Parcel data, reply; |
| 238 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 239 | remote()->transact(IS_PLAYING, data, &reply); |
| 240 | *state = reply.readInt32(); |
| 241 | return reply.readInt32(); |
| 242 | } |
| 243 | |
Lajos Molnar | 3a474aa | 2015-04-24 17:10:07 -0700 | [diff] [blame] | 244 | status_t setPlaybackSettings(const AudioPlaybackRate& rate) |
Wei Jia | 9816016 | 2015-02-04 17:01:11 -0800 | [diff] [blame] | 245 | { |
| 246 | Parcel data, reply; |
| 247 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
Lajos Molnar | 3a474aa | 2015-04-24 17:10:07 -0700 | [diff] [blame] | 248 | data.writeFloat(rate.mSpeed); |
| 249 | data.writeFloat(rate.mPitch); |
| 250 | data.writeInt32((int32_t)rate.mFallbackMode); |
| 251 | data.writeInt32((int32_t)rate.mStretchMode); |
| 252 | remote()->transact(SET_PLAYBACK_SETTINGS, data, &reply); |
Wei Jia | 9816016 | 2015-02-04 17:01:11 -0800 | [diff] [blame] | 253 | return reply.readInt32(); |
| 254 | } |
| 255 | |
Lajos Molnar | 3a474aa | 2015-04-24 17:10:07 -0700 | [diff] [blame] | 256 | status_t getPlaybackSettings(AudioPlaybackRate* rate /* nonnull */) |
| 257 | { |
| 258 | Parcel data, reply; |
| 259 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 260 | remote()->transact(GET_PLAYBACK_SETTINGS, data, &reply); |
| 261 | status_t err = reply.readInt32(); |
| 262 | if (err == OK) { |
| 263 | *rate = AUDIO_PLAYBACK_RATE_DEFAULT; |
| 264 | rate->mSpeed = reply.readFloat(); |
| 265 | rate->mPitch = reply.readFloat(); |
| 266 | rate->mFallbackMode = (AudioTimestretchFallbackMode)reply.readInt32(); |
| 267 | rate->mStretchMode = (AudioTimestretchStretchMode)reply.readInt32(); |
| 268 | } |
| 269 | return err; |
| 270 | } |
| 271 | |
| 272 | status_t setSyncSettings(const AVSyncSettings& sync, float videoFpsHint) |
| 273 | { |
| 274 | Parcel data, reply; |
| 275 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 276 | data.writeInt32((int32_t)sync.mSource); |
| 277 | data.writeInt32((int32_t)sync.mAudioAdjustMode); |
| 278 | data.writeFloat(sync.mTolerance); |
| 279 | data.writeFloat(videoFpsHint); |
| 280 | remote()->transact(SET_SYNC_SETTINGS, data, &reply); |
| 281 | return reply.readInt32(); |
| 282 | } |
| 283 | |
| 284 | status_t getSyncSettings(AVSyncSettings* sync /* nonnull */, float* videoFps /* nonnull */) |
| 285 | { |
| 286 | Parcel data, reply; |
| 287 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 288 | remote()->transact(GET_SYNC_SETTINGS, data, &reply); |
| 289 | status_t err = reply.readInt32(); |
| 290 | if (err == OK) { |
| 291 | AVSyncSettings settings; |
| 292 | settings.mSource = (AVSyncSource)reply.readInt32(); |
| 293 | settings.mAudioAdjustMode = (AVSyncAudioAdjustMode)reply.readInt32(); |
| 294 | settings.mTolerance = reply.readFloat(); |
| 295 | *sync = settings; |
| 296 | *videoFps = reply.readFloat(); |
| 297 | } |
| 298 | return err; |
| 299 | } |
| 300 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | status_t pause() |
| 302 | { |
| 303 | Parcel data, reply; |
| 304 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 305 | remote()->transact(PAUSE, data, &reply); |
| 306 | return reply.readInt32(); |
| 307 | } |
| 308 | |
Wei Jia | c5de091 | 2016-11-18 10:22:14 -0800 | [diff] [blame] | 309 | status_t seekTo(int msec, MediaPlayerSeekMode mode) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | { |
| 311 | Parcel data, reply; |
| 312 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 313 | data.writeInt32(msec); |
Wei Jia | c5de091 | 2016-11-18 10:22:14 -0800 | [diff] [blame] | 314 | data.writeInt32(mode); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | remote()->transact(SEEK_TO, data, &reply); |
| 316 | return reply.readInt32(); |
| 317 | } |
| 318 | |
| 319 | status_t getCurrentPosition(int* msec) |
| 320 | { |
| 321 | Parcel data, reply; |
| 322 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 323 | remote()->transact(GET_CURRENT_POSITION, data, &reply); |
| 324 | *msec = reply.readInt32(); |
| 325 | return reply.readInt32(); |
| 326 | } |
| 327 | |
| 328 | status_t getDuration(int* msec) |
| 329 | { |
| 330 | Parcel data, reply; |
| 331 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 332 | remote()->transact(GET_DURATION, data, &reply); |
| 333 | *msec = reply.readInt32(); |
| 334 | return reply.readInt32(); |
| 335 | } |
| 336 | |
| 337 | status_t reset() |
| 338 | { |
| 339 | Parcel data, reply; |
| 340 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 341 | remote()->transact(RESET, data, &reply); |
| 342 | return reply.readInt32(); |
| 343 | } |
| 344 | |
Wei Jia | 52c2851 | 2017-09-13 18:17:51 -0700 | [diff] [blame] | 345 | status_t notifyAt(int64_t mediaTimeUs) |
| 346 | { |
| 347 | Parcel data, reply; |
| 348 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 349 | data.writeInt64(mediaTimeUs); |
| 350 | remote()->transact(NOTIFY_AT, data, &reply); |
| 351 | return reply.readInt32(); |
| 352 | } |
| 353 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 354 | status_t setAudioStreamType(audio_stream_type_t stream) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | { |
| 356 | Parcel data, reply; |
| 357 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 358 | data.writeInt32((int32_t) stream); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | remote()->transact(SET_AUDIO_STREAM_TYPE, data, &reply); |
| 360 | return reply.readInt32(); |
| 361 | } |
| 362 | |
| 363 | status_t setLooping(int loop) |
| 364 | { |
| 365 | Parcel data, reply; |
| 366 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 367 | data.writeInt32(loop); |
| 368 | remote()->transact(SET_LOOPING, data, &reply); |
| 369 | return reply.readInt32(); |
| 370 | } |
| 371 | |
| 372 | status_t setVolume(float leftVolume, float rightVolume) |
| 373 | { |
| 374 | Parcel data, reply; |
Dave Sparks | 172fb9a | 2009-05-26 14:39:29 -0700 | [diff] [blame] | 375 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | data.writeFloat(leftVolume); |
| 377 | data.writeFloat(rightVolume); |
| 378 | remote()->transact(SET_VOLUME, data, &reply); |
| 379 | return reply.readInt32(); |
| 380 | } |
Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 381 | |
| 382 | status_t invoke(const Parcel& request, Parcel *reply) |
James Dong | 040e4a1 | 2011-04-06 18:29:01 -0700 | [diff] [blame] | 383 | { |
| 384 | // Avoid doing any extra copy. The interface descriptor should |
| 385 | // have been set by MediaPlayer.java. |
Nicolas Catania | 8e1b6cc | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 386 | return remote()->transact(INVOKE, request, reply); |
Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 387 | } |
Nicolas Catania | a7e0e8b | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 388 | |
| 389 | status_t setMetadataFilter(const Parcel& request) |
| 390 | { |
| 391 | Parcel reply; |
| 392 | // Avoid doing any extra copy of the request. The interface |
| 393 | // descriptor should have been set by MediaPlayer.java. |
| 394 | remote()->transact(SET_METADATA_FILTER, request, &reply); |
| 395 | return reply.readInt32(); |
| 396 | } |
Nicolas Catania | 8e1b6cc | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 397 | |
| 398 | status_t getMetadata(bool update_only, bool apply_filter, Parcel *reply) |
| 399 | { |
| 400 | Parcel request; |
| 401 | request.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 402 | // TODO: Burning 2 ints for 2 boolean. Should probably use flags in an int here. |
| 403 | request.writeInt32(update_only); |
| 404 | request.writeInt32(apply_filter); |
| 405 | remote()->transact(GET_METADATA, request, reply); |
| 406 | return reply->readInt32(); |
| 407 | } |
Andreas Huber | 4e92c7e | 2010-02-12 12:35:58 -0800 | [diff] [blame] | 408 | |
Eric Laurent | 2beeb50 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 409 | status_t setAuxEffectSendLevel(float level) |
| 410 | { |
| 411 | Parcel data, reply; |
| 412 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 413 | data.writeFloat(level); |
| 414 | remote()->transact(SET_AUX_EFFECT_SEND_LEVEL, data, &reply); |
| 415 | return reply.readInt32(); |
| 416 | } |
| 417 | |
| 418 | status_t attachAuxEffect(int effectId) |
| 419 | { |
| 420 | Parcel data, reply; |
| 421 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 422 | data.writeInt32(effectId); |
| 423 | remote()->transact(ATTACH_AUX_EFFECT, data, &reply); |
| 424 | return reply.readInt32(); |
| 425 | } |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 426 | |
Gloria Wang | 4f9e47f | 2011-04-25 17:28:22 -0700 | [diff] [blame] | 427 | status_t setParameter(int key, const Parcel& request) |
| 428 | { |
| 429 | Parcel data, reply; |
| 430 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 431 | data.writeInt32(key); |
| 432 | if (request.dataSize() > 0) { |
| 433 | data.appendFrom(const_cast<Parcel *>(&request), 0, request.dataSize()); |
| 434 | } |
| 435 | remote()->transact(SET_PARAMETER, data, &reply); |
| 436 | return reply.readInt32(); |
| 437 | } |
| 438 | |
| 439 | status_t getParameter(int key, Parcel *reply) |
| 440 | { |
| 441 | Parcel data; |
| 442 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 443 | data.writeInt32(key); |
| 444 | return remote()->transact(GET_PARAMETER, data, reply); |
| 445 | } |
| 446 | |
John Grossman | 44a7e42 | 2012-06-21 17:29:24 -0700 | [diff] [blame] | 447 | status_t setRetransmitEndpoint(const struct sockaddr_in* endpoint) |
| 448 | { |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 449 | Parcel data, reply; |
| 450 | status_t err; |
| 451 | |
| 452 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 453 | if (NULL != endpoint) { |
| 454 | data.writeInt32(sizeof(*endpoint)); |
| 455 | data.write(endpoint, sizeof(*endpoint)); |
| 456 | } else { |
| 457 | data.writeInt32(0); |
| 458 | } |
| 459 | |
| 460 | err = remote()->transact(SET_RETRANSMIT_ENDPOINT, data, &reply); |
| 461 | if (OK != err) { |
| 462 | return err; |
| 463 | } |
Marco Nelissen | 6b74d67 | 2012-02-28 16:07:44 -0800 | [diff] [blame] | 464 | return reply.readInt32(); |
| 465 | } |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 466 | |
Marco Nelissen | 6b74d67 | 2012-02-28 16:07:44 -0800 | [diff] [blame] | 467 | status_t setNextPlayer(const sp<IMediaPlayer>& player) { |
| 468 | Parcel data, reply; |
| 469 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 470 | sp<IBinder> b(IInterface::asBinder(player)); |
Marco Nelissen | 6b74d67 | 2012-02-28 16:07:44 -0800 | [diff] [blame] | 471 | data.writeStrongBinder(b); |
| 472 | remote()->transact(SET_NEXT_PLAYER, data, &reply); |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 473 | return reply.readInt32(); |
| 474 | } |
John Grossman | 44a7e42 | 2012-06-21 17:29:24 -0700 | [diff] [blame] | 475 | |
| 476 | status_t getRetransmitEndpoint(struct sockaddr_in* endpoint) |
| 477 | { |
| 478 | Parcel data, reply; |
| 479 | status_t err; |
| 480 | |
| 481 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 482 | err = remote()->transact(GET_RETRANSMIT_ENDPOINT, data, &reply); |
| 483 | |
| 484 | if ((OK != err) || (OK != (err = reply.readInt32()))) { |
| 485 | return err; |
| 486 | } |
| 487 | |
| 488 | data.read(endpoint, sizeof(*endpoint)); |
| 489 | |
| 490 | return err; |
| 491 | } |
Hassan Shojania | 071437a | 2017-01-23 09:19:40 -0800 | [diff] [blame] | 492 | |
Andy Hung | 9fc8b5c | 2017-01-24 13:36:48 -0800 | [diff] [blame] | 493 | virtual VolumeShaper::Status applyVolumeShaper( |
| 494 | const sp<VolumeShaper::Configuration>& configuration, |
| 495 | const sp<VolumeShaper::Operation>& operation) { |
| 496 | Parcel data, reply; |
| 497 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 498 | |
| 499 | status_t tmp; |
| 500 | status_t status = configuration.get() == nullptr |
| 501 | ? data.writeInt32(0) |
| 502 | : (tmp = data.writeInt32(1)) != NO_ERROR |
| 503 | ? tmp : configuration->writeToParcel(&data); |
| 504 | if (status != NO_ERROR) { |
| 505 | return VolumeShaper::Status(status); |
| 506 | } |
| 507 | |
| 508 | status = operation.get() == nullptr |
| 509 | ? status = data.writeInt32(0) |
| 510 | : (tmp = data.writeInt32(1)) != NO_ERROR |
| 511 | ? tmp : operation->writeToParcel(&data); |
| 512 | if (status != NO_ERROR) { |
| 513 | return VolumeShaper::Status(status); |
| 514 | } |
| 515 | |
| 516 | int32_t remoteVolumeShaperStatus; |
| 517 | status = remote()->transact(APPLY_VOLUME_SHAPER, data, &reply); |
| 518 | if (status == NO_ERROR) { |
| 519 | status = reply.readInt32(&remoteVolumeShaperStatus); |
| 520 | } |
| 521 | if (status != NO_ERROR) { |
| 522 | return VolumeShaper::Status(status); |
| 523 | } |
| 524 | return VolumeShaper::Status(remoteVolumeShaperStatus); |
| 525 | } |
| 526 | |
| 527 | virtual sp<VolumeShaper::State> getVolumeShaperState(int id) { |
| 528 | Parcel data, reply; |
| 529 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 530 | |
| 531 | data.writeInt32(id); |
| 532 | status_t status = remote()->transact(GET_VOLUME_SHAPER_STATE, data, &reply); |
| 533 | if (status != NO_ERROR) { |
| 534 | return nullptr; |
| 535 | } |
| 536 | sp<VolumeShaper::State> state = new VolumeShaper::State(); |
Ivan Lozano | 8cf3a07 | 2017-08-09 09:01:33 -0700 | [diff] [blame] | 537 | status = state->readFromParcel(&reply); |
Andy Hung | 9fc8b5c | 2017-01-24 13:36:48 -0800 | [diff] [blame] | 538 | if (status != NO_ERROR) { |
| 539 | return nullptr; |
| 540 | } |
| 541 | return state; |
| 542 | } |
| 543 | |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 544 | // Modular DRM |
| 545 | status_t prepareDrm(const uint8_t uuid[16], const Vector<uint8_t>& drmSessionId) |
Hassan Shojania | 071437a | 2017-01-23 09:19:40 -0800 | [diff] [blame] | 546 | { |
| 547 | Parcel data, reply; |
| 548 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 549 | |
| 550 | data.write(uuid, 16); |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 551 | writeVector(data, drmSessionId); |
Hassan Shojania | 071437a | 2017-01-23 09:19:40 -0800 | [diff] [blame] | 552 | |
| 553 | status_t status = remote()->transact(PREPARE_DRM, data, &reply); |
| 554 | if (status != OK) { |
| 555 | ALOGE("prepareDrm: binder call failed: %d", status); |
| 556 | return status; |
| 557 | } |
| 558 | |
| 559 | return reply.readInt32(); |
| 560 | } |
| 561 | |
| 562 | status_t releaseDrm() |
| 563 | { |
| 564 | Parcel data, reply; |
| 565 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 566 | |
| 567 | status_t status = remote()->transact(RELEASE_DRM, data, &reply); |
| 568 | if (status != OK) { |
| 569 | ALOGE("releaseDrm: binder call failed: %d", status); |
| 570 | return status; |
| 571 | } |
| 572 | |
| 573 | return reply.readInt32(); |
| 574 | } |
jiabin | 156c687 | 2017-10-06 09:47:15 -0700 | [diff] [blame] | 575 | |
| 576 | status_t setOutputDevice(audio_port_handle_t deviceId) |
| 577 | { |
| 578 | Parcel data, reply; |
| 579 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 580 | |
| 581 | data.writeInt32(deviceId); |
| 582 | |
| 583 | status_t status = remote()->transact(SET_OUTPUT_DEVICE, data, &reply); |
| 584 | if (status != OK) { |
| 585 | ALOGE("setOutputDevice: binder call failed: %d", status); |
| 586 | return status; |
| 587 | } |
| 588 | |
| 589 | return reply.readInt32(); |
| 590 | } |
| 591 | |
| 592 | status_t getRoutedDeviceId(audio_port_handle_t* deviceId) |
| 593 | { |
| 594 | Parcel data, reply; |
| 595 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 596 | |
| 597 | status_t status = remote()->transact(GET_ROUTED_DEVICE_ID, data, &reply); |
| 598 | if (status != OK) { |
| 599 | ALOGE("getRoutedDeviceid: binder call failed: %d", status); |
| 600 | *deviceId = AUDIO_PORT_HANDLE_NONE; |
| 601 | return status; |
| 602 | } |
| 603 | |
| 604 | status = reply.readInt32(); |
| 605 | if (status != NO_ERROR) { |
| 606 | *deviceId = AUDIO_PORT_HANDLE_NONE; |
| 607 | } else { |
| 608 | *deviceId = reply.readInt32(); |
| 609 | } |
| 610 | return status; |
| 611 | } |
| 612 | |
| 613 | status_t enableAudioDeviceCallback(bool enabled) |
| 614 | { |
| 615 | Parcel data, reply; |
| 616 | data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); |
| 617 | |
| 618 | data.writeBool(enabled); |
| 619 | |
| 620 | status_t status = remote()->transact(ENABLE_AUDIO_DEVICE_CALLBACK, data, &reply); |
| 621 | if (status != OK) { |
| 622 | ALOGE("enableAudioDeviceCallback: binder call failed: %d, %d", enabled, status); |
| 623 | return status; |
| 624 | } |
| 625 | |
| 626 | return reply.readInt32(); |
| 627 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | }; |
| 629 | |
niko | 56f0cc5 | 2009-06-22 08:49:52 -0700 | [diff] [blame] | 630 | IMPLEMENT_META_INTERFACE(MediaPlayer, "android.media.IMediaPlayer"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | |
| 632 | // ---------------------------------------------------------------------- |
| 633 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | status_t BnMediaPlayer::onTransact( |
| 635 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 636 | { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 637 | switch (code) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 638 | case DISCONNECT: { |
| 639 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 640 | disconnect(); |
| 641 | return NO_ERROR; |
| 642 | } break; |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 643 | case SET_DATA_SOURCE_URL: { |
| 644 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 645 | |
| 646 | sp<IMediaHTTPService> httpService; |
| 647 | if (data.readInt32()) { |
| 648 | httpService = |
| 649 | interface_cast<IMediaHTTPService>(data.readStrongBinder()); |
| 650 | } |
| 651 | |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 652 | const char* url = data.readCString(); |
Wei Jia | 0ca02a0 | 2016-01-14 13:14:31 -0800 | [diff] [blame] | 653 | if (url == NULL) { |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 654 | reply->writeInt32(BAD_VALUE); |
| 655 | return NO_ERROR; |
| 656 | } |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 657 | KeyedVector<String8, String8> headers; |
| 658 | int32_t numHeaders = data.readInt32(); |
| 659 | for (int i = 0; i < numHeaders; ++i) { |
| 660 | String8 key = data.readString8(); |
| 661 | String8 value = data.readString8(); |
| 662 | headers.add(key, value); |
| 663 | } |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 664 | reply->writeInt32(setDataSource( |
| 665 | httpService, url, numHeaders > 0 ? &headers : NULL)); |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 666 | return NO_ERROR; |
| 667 | } break; |
| 668 | case SET_DATA_SOURCE_FD: { |
| 669 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 670 | int fd = data.readFileDescriptor(); |
| 671 | int64_t offset = data.readInt64(); |
| 672 | int64_t length = data.readInt64(); |
| 673 | reply->writeInt32(setDataSource(fd, offset, length)); |
| 674 | return NO_ERROR; |
| 675 | } |
| 676 | case SET_DATA_SOURCE_STREAM: { |
| 677 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 678 | sp<IStreamSource> source = |
| 679 | interface_cast<IStreamSource>(data.readStrongBinder()); |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 680 | if (source == NULL) { |
| 681 | reply->writeInt32(BAD_VALUE); |
| 682 | } else { |
| 683 | reply->writeInt32(setDataSource(source)); |
| 684 | } |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 685 | return NO_ERROR; |
| 686 | } |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 687 | case SET_DATA_SOURCE_CALLBACK: { |
| 688 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 689 | sp<IDataSource> source = |
| 690 | interface_cast<IDataSource>(data.readStrongBinder()); |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 691 | if (source == NULL) { |
| 692 | reply->writeInt32(BAD_VALUE); |
| 693 | } else { |
| 694 | reply->writeInt32(setDataSource(source)); |
| 695 | } |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 696 | return NO_ERROR; |
| 697 | } |
Byeongjo Park | 28225ab | 2019-01-24 20:31:19 +0900 | [diff] [blame] | 698 | case SET_DATA_SOURCE_RTP: { |
| 699 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
Lajos Molnar | 1982933 | 2020-03-17 08:13:10 -0700 | [diff] [blame] | 700 | String8 rtpParams = data.readString8(); |
Byeongjo Park | 28225ab | 2019-01-24 20:31:19 +0900 | [diff] [blame] | 701 | reply->writeInt32(setDataSource(rtpParams)); |
| 702 | return NO_ERROR; |
| 703 | } |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 704 | case SET_VIDEO_SURFACETEXTURE: { |
| 705 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 706 | sp<IGraphicBufferProducer> bufferProducer = |
| 707 | interface_cast<IGraphicBufferProducer>(data.readStrongBinder()); |
| 708 | reply->writeInt32(setVideoSurfaceTexture(bufferProducer)); |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 709 | return NO_ERROR; |
| 710 | } break; |
Wei Jia | d399e7e | 2016-10-26 15:49:11 -0700 | [diff] [blame] | 711 | case SET_BUFFERING_SETTINGS: { |
| 712 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 713 | BufferingSettings buffering; |
Dongwon Kang | 79e3373 | 2019-01-25 16:35:26 -0800 | [diff] [blame] | 714 | buffering.mInitialMarkMs = data.readInt32(); |
| 715 | buffering.mResumePlaybackMarkMs = data.readInt32(); |
Wei Jia | d399e7e | 2016-10-26 15:49:11 -0700 | [diff] [blame] | 716 | reply->writeInt32(setBufferingSettings(buffering)); |
| 717 | return NO_ERROR; |
| 718 | } break; |
Wei Jia | 9bb3803 | 2017-03-23 18:00:38 -0700 | [diff] [blame] | 719 | case GET_BUFFERING_SETTINGS: { |
Wei Jia | d399e7e | 2016-10-26 15:49:11 -0700 | [diff] [blame] | 720 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 721 | BufferingSettings buffering; |
Wei Jia | 9bb3803 | 2017-03-23 18:00:38 -0700 | [diff] [blame] | 722 | status_t err = getBufferingSettings(&buffering); |
Wei Jia | d399e7e | 2016-10-26 15:49:11 -0700 | [diff] [blame] | 723 | reply->writeInt32(err); |
| 724 | if (err == OK) { |
Dongwon Kang | 79e3373 | 2019-01-25 16:35:26 -0800 | [diff] [blame] | 725 | reply->writeInt32(buffering.mInitialMarkMs); |
| 726 | reply->writeInt32(buffering.mResumePlaybackMarkMs); |
Wei Jia | d399e7e | 2016-10-26 15:49:11 -0700 | [diff] [blame] | 727 | } |
| 728 | return NO_ERROR; |
| 729 | } break; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 730 | case PREPARE_ASYNC: { |
| 731 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 732 | reply->writeInt32(prepareAsync()); |
| 733 | return NO_ERROR; |
| 734 | } break; |
| 735 | case START: { |
| 736 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 737 | reply->writeInt32(start()); |
| 738 | return NO_ERROR; |
| 739 | } break; |
| 740 | case STOP: { |
| 741 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 742 | reply->writeInt32(stop()); |
| 743 | return NO_ERROR; |
| 744 | } break; |
| 745 | case IS_PLAYING: { |
| 746 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 747 | bool state; |
| 748 | status_t ret = isPlaying(&state); |
| 749 | reply->writeInt32(state); |
| 750 | reply->writeInt32(ret); |
| 751 | return NO_ERROR; |
| 752 | } break; |
Lajos Molnar | 3a474aa | 2015-04-24 17:10:07 -0700 | [diff] [blame] | 753 | case SET_PLAYBACK_SETTINGS: { |
Wei Jia | 9816016 | 2015-02-04 17:01:11 -0800 | [diff] [blame] | 754 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
Lajos Molnar | 3a474aa | 2015-04-24 17:10:07 -0700 | [diff] [blame] | 755 | AudioPlaybackRate rate = AUDIO_PLAYBACK_RATE_DEFAULT; |
| 756 | rate.mSpeed = data.readFloat(); |
| 757 | rate.mPitch = data.readFloat(); |
| 758 | rate.mFallbackMode = (AudioTimestretchFallbackMode)data.readInt32(); |
| 759 | rate.mStretchMode = (AudioTimestretchStretchMode)data.readInt32(); |
| 760 | reply->writeInt32(setPlaybackSettings(rate)); |
| 761 | return NO_ERROR; |
| 762 | } break; |
| 763 | case GET_PLAYBACK_SETTINGS: { |
| 764 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 765 | AudioPlaybackRate rate = AUDIO_PLAYBACK_RATE_DEFAULT; |
| 766 | status_t err = getPlaybackSettings(&rate); |
| 767 | reply->writeInt32(err); |
| 768 | if (err == OK) { |
| 769 | reply->writeFloat(rate.mSpeed); |
| 770 | reply->writeFloat(rate.mPitch); |
| 771 | reply->writeInt32((int32_t)rate.mFallbackMode); |
| 772 | reply->writeInt32((int32_t)rate.mStretchMode); |
| 773 | } |
| 774 | return NO_ERROR; |
| 775 | } break; |
| 776 | case SET_SYNC_SETTINGS: { |
| 777 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 778 | AVSyncSettings sync; |
| 779 | sync.mSource = (AVSyncSource)data.readInt32(); |
| 780 | sync.mAudioAdjustMode = (AVSyncAudioAdjustMode)data.readInt32(); |
| 781 | sync.mTolerance = data.readFloat(); |
| 782 | float videoFpsHint = data.readFloat(); |
| 783 | reply->writeInt32(setSyncSettings(sync, videoFpsHint)); |
| 784 | return NO_ERROR; |
| 785 | } break; |
| 786 | case GET_SYNC_SETTINGS: { |
| 787 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 788 | AVSyncSettings sync; |
| 789 | float videoFps; |
| 790 | status_t err = getSyncSettings(&sync, &videoFps); |
| 791 | reply->writeInt32(err); |
| 792 | if (err == OK) { |
| 793 | reply->writeInt32((int32_t)sync.mSource); |
| 794 | reply->writeInt32((int32_t)sync.mAudioAdjustMode); |
| 795 | reply->writeFloat(sync.mTolerance); |
| 796 | reply->writeFloat(videoFps); |
| 797 | } |
Wei Jia | 9816016 | 2015-02-04 17:01:11 -0800 | [diff] [blame] | 798 | return NO_ERROR; |
| 799 | } break; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | case PAUSE: { |
| 801 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 802 | reply->writeInt32(pause()); |
| 803 | return NO_ERROR; |
| 804 | } break; |
| 805 | case SEEK_TO: { |
| 806 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
Wei Jia | 67b6dcc | 2016-10-31 17:01:37 -0700 | [diff] [blame] | 807 | int msec = data.readInt32(); |
Wei Jia | c5de091 | 2016-11-18 10:22:14 -0800 | [diff] [blame] | 808 | MediaPlayerSeekMode mode = (MediaPlayerSeekMode)data.readInt32(); |
| 809 | reply->writeInt32(seekTo(msec, mode)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 810 | return NO_ERROR; |
| 811 | } break; |
| 812 | case GET_CURRENT_POSITION: { |
| 813 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
Robert Shih | 8923543 | 2015-09-02 16:46:59 -0700 | [diff] [blame] | 814 | int msec = 0; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | status_t ret = getCurrentPosition(&msec); |
| 816 | reply->writeInt32(msec); |
| 817 | reply->writeInt32(ret); |
| 818 | return NO_ERROR; |
| 819 | } break; |
| 820 | case GET_DURATION: { |
| 821 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
Robert Shih | 8923543 | 2015-09-02 16:46:59 -0700 | [diff] [blame] | 822 | int msec = 0; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | status_t ret = getDuration(&msec); |
| 824 | reply->writeInt32(msec); |
| 825 | reply->writeInt32(ret); |
| 826 | return NO_ERROR; |
| 827 | } break; |
| 828 | case RESET: { |
| 829 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 830 | reply->writeInt32(reset()); |
| 831 | return NO_ERROR; |
| 832 | } break; |
Wei Jia | 52c2851 | 2017-09-13 18:17:51 -0700 | [diff] [blame] | 833 | case NOTIFY_AT: { |
| 834 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 835 | reply->writeInt32(notifyAt(data.readInt64())); |
| 836 | return NO_ERROR; |
| 837 | } break; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | case SET_AUDIO_STREAM_TYPE: { |
| 839 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 840 | reply->writeInt32(setAudioStreamType((audio_stream_type_t) data.readInt32())); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | return NO_ERROR; |
| 842 | } break; |
| 843 | case SET_LOOPING: { |
| 844 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 845 | reply->writeInt32(setLooping(data.readInt32())); |
| 846 | return NO_ERROR; |
| 847 | } break; |
| 848 | case SET_VOLUME: { |
Dave Sparks | 172fb9a | 2009-05-26 14:39:29 -0700 | [diff] [blame] | 849 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
Gloria Wang | de162ff | 2011-08-01 14:01:29 -0700 | [diff] [blame] | 850 | float leftVolume = data.readFloat(); |
| 851 | float rightVolume = data.readFloat(); |
| 852 | reply->writeInt32(setVolume(leftVolume, rightVolume)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | return NO_ERROR; |
| 854 | } break; |
Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 855 | case INVOKE: { |
| 856 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
James Dong | 040e4a1 | 2011-04-06 18:29:01 -0700 | [diff] [blame] | 857 | status_t result = invoke(data, reply); |
| 858 | return result; |
Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 859 | } break; |
Nicolas Catania | a7e0e8b | 2009-07-08 08:57:42 -0700 | [diff] [blame] | 860 | case SET_METADATA_FILTER: { |
| 861 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 862 | reply->writeInt32(setMetadataFilter(data)); |
| 863 | return NO_ERROR; |
| 864 | } break; |
Nicolas Catania | 8e1b6cc | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 865 | case GET_METADATA: { |
| 866 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
Gloria Wang | de162ff | 2011-08-01 14:01:29 -0700 | [diff] [blame] | 867 | bool update_only = static_cast<bool>(data.readInt32()); |
| 868 | bool apply_filter = static_cast<bool>(data.readInt32()); |
| 869 | const status_t retcode = getMetadata(update_only, apply_filter, reply); |
Nicolas Catania | 8e1b6cc | 2009-07-09 09:21:33 -0700 | [diff] [blame] | 870 | reply->setDataPosition(0); |
| 871 | reply->writeInt32(retcode); |
| 872 | reply->setDataPosition(0); |
| 873 | return NO_ERROR; |
| 874 | } break; |
Eric Laurent | 2beeb50 | 2010-07-16 07:43:46 -0700 | [diff] [blame] | 875 | case SET_AUX_EFFECT_SEND_LEVEL: { |
| 876 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 877 | reply->writeInt32(setAuxEffectSendLevel(data.readFloat())); |
| 878 | return NO_ERROR; |
| 879 | } break; |
| 880 | case ATTACH_AUX_EFFECT: { |
| 881 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 882 | reply->writeInt32(attachAuxEffect(data.readInt32())); |
| 883 | return NO_ERROR; |
| 884 | } break; |
Gloria Wang | 4f9e47f | 2011-04-25 17:28:22 -0700 | [diff] [blame] | 885 | case SET_PARAMETER: { |
| 886 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 887 | int key = data.readInt32(); |
| 888 | |
| 889 | Parcel request; |
| 890 | if (data.dataAvail() > 0) { |
| 891 | request.appendFrom( |
| 892 | const_cast<Parcel *>(&data), data.dataPosition(), data.dataAvail()); |
| 893 | } |
| 894 | request.setDataPosition(0); |
| 895 | reply->writeInt32(setParameter(key, request)); |
| 896 | return NO_ERROR; |
| 897 | } break; |
| 898 | case GET_PARAMETER: { |
| 899 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 900 | return getParameter(data.readInt32(), reply); |
| 901 | } break; |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 902 | case SET_RETRANSMIT_ENDPOINT: { |
| 903 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 904 | |
| 905 | struct sockaddr_in endpoint; |
Nick Kralevich | 0981df6 | 2015-08-20 09:56:39 -0700 | [diff] [blame] | 906 | memset(&endpoint, 0, sizeof(endpoint)); |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 907 | int amt = data.readInt32(); |
| 908 | if (amt == sizeof(endpoint)) { |
| 909 | data.read(&endpoint, sizeof(struct sockaddr_in)); |
| 910 | reply->writeInt32(setRetransmitEndpoint(&endpoint)); |
| 911 | } else { |
| 912 | reply->writeInt32(setRetransmitEndpoint(NULL)); |
| 913 | } |
John Grossman | 44a7e42 | 2012-06-21 17:29:24 -0700 | [diff] [blame] | 914 | |
| 915 | return NO_ERROR; |
| 916 | } break; |
| 917 | case GET_RETRANSMIT_ENDPOINT: { |
| 918 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 919 | |
| 920 | struct sockaddr_in endpoint; |
Nick Kralevich | 0981df6 | 2015-08-20 09:56:39 -0700 | [diff] [blame] | 921 | memset(&endpoint, 0, sizeof(endpoint)); |
John Grossman | 44a7e42 | 2012-06-21 17:29:24 -0700 | [diff] [blame] | 922 | status_t res = getRetransmitEndpoint(&endpoint); |
| 923 | |
| 924 | reply->writeInt32(res); |
| 925 | reply->write(&endpoint, sizeof(endpoint)); |
| 926 | |
Marco Nelissen | 6b74d67 | 2012-02-28 16:07:44 -0800 | [diff] [blame] | 927 | return NO_ERROR; |
| 928 | } break; |
| 929 | case SET_NEXT_PLAYER: { |
| 930 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 931 | reply->writeInt32(setNextPlayer(interface_cast<IMediaPlayer>(data.readStrongBinder()))); |
John Grossman | 44a7e42 | 2012-06-21 17:29:24 -0700 | [diff] [blame] | 932 | |
John Grossman | c795b64 | 2012-02-22 15:38:35 -0800 | [diff] [blame] | 933 | return NO_ERROR; |
| 934 | } break; |
Hassan Shojania | 071437a | 2017-01-23 09:19:40 -0800 | [diff] [blame] | 935 | |
Andy Hung | 9fc8b5c | 2017-01-24 13:36:48 -0800 | [diff] [blame] | 936 | case APPLY_VOLUME_SHAPER: { |
| 937 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 938 | sp<VolumeShaper::Configuration> configuration; |
| 939 | sp<VolumeShaper::Operation> operation; |
| 940 | |
| 941 | int32_t present; |
| 942 | status_t status = data.readInt32(&present); |
| 943 | if (status == NO_ERROR && present != 0) { |
| 944 | configuration = new VolumeShaper::Configuration(); |
Ivan Lozano | 8cf3a07 | 2017-08-09 09:01:33 -0700 | [diff] [blame] | 945 | status = configuration->readFromParcel(&data); |
Andy Hung | 9fc8b5c | 2017-01-24 13:36:48 -0800 | [diff] [blame] | 946 | } |
| 947 | if (status == NO_ERROR) { |
| 948 | status = data.readInt32(&present); |
| 949 | } |
| 950 | if (status == NO_ERROR && present != 0) { |
| 951 | operation = new VolumeShaper::Operation(); |
Ivan Lozano | 8cf3a07 | 2017-08-09 09:01:33 -0700 | [diff] [blame] | 952 | status = operation->readFromParcel(&data); |
Andy Hung | 9fc8b5c | 2017-01-24 13:36:48 -0800 | [diff] [blame] | 953 | } |
| 954 | if (status == NO_ERROR) { |
| 955 | status = (status_t)applyVolumeShaper(configuration, operation); |
| 956 | } |
| 957 | reply->writeInt32(status); |
| 958 | return NO_ERROR; |
| 959 | } break; |
| 960 | case GET_VOLUME_SHAPER_STATE: { |
| 961 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 962 | int id; |
| 963 | status_t status = data.readInt32(&id); |
| 964 | if (status == NO_ERROR) { |
| 965 | sp<VolumeShaper::State> state = getVolumeShaperState(id); |
| 966 | if (state.get() != nullptr) { |
| 967 | status = state->writeToParcel(reply); |
| 968 | } |
| 969 | } |
| 970 | return NO_ERROR; |
| 971 | } break; |
| 972 | |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 973 | // Modular DRM |
Hassan Shojania | 071437a | 2017-01-23 09:19:40 -0800 | [diff] [blame] | 974 | case PREPARE_DRM: { |
| 975 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 976 | |
andrewlewis | 35c7db9 | 2020-08-14 10:41:13 +0000 | [diff] [blame] | 977 | uint8_t uuid[16] = {}; |
Hassan Shojania | 071437a | 2017-01-23 09:19:40 -0800 | [diff] [blame] | 978 | data.read(uuid, sizeof(uuid)); |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 979 | Vector<uint8_t> drmSessionId; |
| 980 | readVector(data, drmSessionId); |
Hassan Shojania | 071437a | 2017-01-23 09:19:40 -0800 | [diff] [blame] | 981 | |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 982 | uint32_t result = prepareDrm(uuid, drmSessionId); |
Hassan Shojania | 071437a | 2017-01-23 09:19:40 -0800 | [diff] [blame] | 983 | reply->writeInt32(result); |
| 984 | return OK; |
| 985 | } |
| 986 | case RELEASE_DRM: { |
| 987 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 988 | |
| 989 | uint32_t result = releaseDrm(); |
| 990 | reply->writeInt32(result); |
| 991 | return OK; |
| 992 | } |
jiabin | 156c687 | 2017-10-06 09:47:15 -0700 | [diff] [blame] | 993 | |
| 994 | // AudioRouting |
| 995 | case SET_OUTPUT_DEVICE: { |
| 996 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 997 | int deviceId; |
| 998 | status_t status = data.readInt32(&deviceId); |
| 999 | if (status == NO_ERROR) { |
| 1000 | reply->writeInt32(setOutputDevice(deviceId)); |
| 1001 | } else { |
| 1002 | reply->writeInt32(BAD_VALUE); |
| 1003 | } |
| 1004 | return NO_ERROR; |
| 1005 | } |
| 1006 | case GET_ROUTED_DEVICE_ID: { |
| 1007 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 1008 | audio_port_handle_t deviceId; |
| 1009 | status_t ret = getRoutedDeviceId(&deviceId); |
| 1010 | reply->writeInt32(ret); |
| 1011 | if (ret == NO_ERROR) { |
| 1012 | reply->writeInt32(deviceId); |
| 1013 | } |
| 1014 | return NO_ERROR; |
| 1015 | } break; |
| 1016 | case ENABLE_AUDIO_DEVICE_CALLBACK: { |
| 1017 | CHECK_INTERFACE(IMediaPlayer, data, reply); |
| 1018 | bool enabled; |
| 1019 | status_t status = data.readBool(&enabled); |
| 1020 | if (status == NO_ERROR) { |
| 1021 | reply->writeInt32(enableAudioDeviceCallback(enabled)); |
| 1022 | } else { |
| 1023 | reply->writeInt32(BAD_VALUE); |
| 1024 | } |
| 1025 | return NO_ERROR; |
| 1026 | } break; |
| 1027 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1028 | default: |
| 1029 | return BBinder::onTransact(code, data, reply, flags); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | // ---------------------------------------------------------------------------- |
| 1034 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 1035 | } // namespace android |