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