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 | |
| 18 | #include <stdint.h> |
| 19 | #include <sys/types.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 21 | #include <binder/Parcel.h> |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 22 | #include <binder/IMemory.h> |
Lajos Molnar | 1381d4b | 2014-08-07 15:18:35 -0700 | [diff] [blame] | 23 | #include <media/IMediaCodecList.h> |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 24 | #include <media/IMediaHTTPService.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <media/IMediaPlayerService.h> |
Marco Nelissen | 5dcf85a | 2018-10-11 09:49:02 -0700 | [diff] [blame] | 26 | #include <media/IMediaPlayer.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <media/IMediaRecorder.h> |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 28 | #include <media/IOMX.h> |
Jeff Brown | 2013a54 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 29 | #include <media/IRemoteDisplay.h> |
| 30 | #include <media/IRemoteDisplayClient.h> |
Andreas Huber | e2b1028 | 2010-11-23 11:41:34 -0800 | [diff] [blame] | 31 | #include <media/IStreamSource.h> |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 32 | |
| 33 | #include <utils/Errors.h> // for status_t |
Jeff Brown | 2013a54 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 34 | #include <utils/String8.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
| 36 | namespace android { |
| 37 | |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame^] | 38 | using android::content::AttributionSourceState; |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 39 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | enum { |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 41 | CREATE = IBinder::FIRST_CALL_TRANSACTION, |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | CREATE_MEDIA_RECORDER, |
| 43 | CREATE_METADATA_RETRIEVER, |
Gloria Wang | 7cf180c | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 44 | ADD_BATTERY_DATA, |
Jeff Brown | 2013a54 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 45 | PULL_BATTERY_DATA, |
| 46 | LISTEN_FOR_REMOTE_DISPLAY, |
Lajos Molnar | 1381d4b | 2014-08-07 15:18:35 -0700 | [diff] [blame] | 47 | GET_CODEC_LIST, |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | class BpMediaPlayerService: public BpInterface<IMediaPlayerService> |
| 51 | { |
| 52 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 53 | explicit BpMediaPlayerService(const sp<IBinder>& impl) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | : BpInterface<IMediaPlayerService>(impl) |
| 55 | { |
| 56 | } |
| 57 | |
Glenn Kasten | f37971f | 2012-02-03 11:06:53 -0800 | [diff] [blame] | 58 | virtual sp<IMediaMetadataRetriever> createMetadataRetriever() |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | { |
| 60 | Parcel data, reply; |
| 61 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | remote()->transact(CREATE_METADATA_RETRIEVER, data, &reply); |
| 63 | return interface_cast<IMediaMetadataRetriever>(reply.readStrongBinder()); |
| 64 | } |
| 65 | |
Andreas Huber | 2db8455 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 66 | virtual sp<IMediaPlayer> create( |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 67 | const sp<IMediaPlayerClient>& client, audio_session_t audioSessionId, |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame^] | 68 | const AttributionSourceState& attributionSource) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | Parcel data, reply; |
| 70 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 71 | data.writeStrongBinder(IInterface::asBinder(client)); |
Eric Laurent | a514bdb | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 72 | data.writeInt32(audioSessionId); |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame^] | 73 | data.writeParcelable(attributionSource); |
Andreas Huber | 2db8455 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 74 | |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 75 | remote()->transact(CREATE, data, &reply); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | return interface_cast<IMediaPlayer>(reply.readStrongBinder()); |
| 77 | } |
| 78 | |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame^] | 79 | virtual sp<IMediaRecorder> createMediaRecorder(const AttributionSourceState& attributionSource) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | { |
| 81 | Parcel data, reply; |
| 82 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame^] | 83 | data.writeParcelable(attributionSource); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | remote()->transact(CREATE_MEDIA_RECORDER, data, &reply); |
| 85 | return interface_cast<IMediaRecorder>(reply.readStrongBinder()); |
| 86 | } |
| 87 | |
Gloria Wang | 7cf180c | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 88 | virtual void addBatteryData(uint32_t params) { |
| 89 | Parcel data, reply; |
| 90 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
| 91 | data.writeInt32(params); |
| 92 | remote()->transact(ADD_BATTERY_DATA, data, &reply); |
| 93 | } |
| 94 | |
| 95 | virtual status_t pullBatteryData(Parcel* reply) { |
| 96 | Parcel data; |
| 97 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
| 98 | return remote()->transact(PULL_BATTERY_DATA, data, reply); |
| 99 | } |
Jeff Brown | 2013a54 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 100 | |
Svet Ganov | be71aa2 | 2015-04-28 12:06:02 -0700 | [diff] [blame] | 101 | virtual sp<IRemoteDisplay> listenForRemoteDisplay(const String16 &opPackageName, |
| 102 | const sp<IRemoteDisplayClient>& client, const String8& iface) |
Jeff Brown | 2013a54 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 103 | { |
| 104 | Parcel data, reply; |
| 105 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
Svet Ganov | be71aa2 | 2015-04-28 12:06:02 -0700 | [diff] [blame] | 106 | data.writeString16(opPackageName); |
Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 107 | data.writeStrongBinder(IInterface::asBinder(client)); |
Jeff Brown | 2013a54 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 108 | data.writeString8(iface); |
| 109 | remote()->transact(LISTEN_FOR_REMOTE_DISPLAY, data, &reply); |
| 110 | return interface_cast<IRemoteDisplay>(reply.readStrongBinder()); |
| 111 | } |
Lajos Molnar | 1381d4b | 2014-08-07 15:18:35 -0700 | [diff] [blame] | 112 | |
| 113 | virtual sp<IMediaCodecList> getCodecList() const { |
| 114 | Parcel data, reply; |
| 115 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
| 116 | remote()->transact(GET_CODEC_LIST, data, &reply); |
| 117 | return interface_cast<IMediaCodecList>(reply.readStrongBinder()); |
| 118 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | }; |
| 120 | |
niko | 56f0cc5 | 2009-06-22 08:49:52 -0700 | [diff] [blame] | 121 | IMPLEMENT_META_INTERFACE(MediaPlayerService, "android.media.IMediaPlayerService"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | |
| 123 | // ---------------------------------------------------------------------- |
| 124 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | status_t BnMediaPlayerService::onTransact( |
| 126 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 127 | { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 128 | switch (code) { |
Dave Burke | d681bbb | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 129 | case CREATE: { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
Andreas Huber | 2db8455 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 131 | sp<IMediaPlayerClient> client = |
| 132 | interface_cast<IMediaPlayerClient>(data.readStrongBinder()); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 133 | audio_session_t audioSessionId = (audio_session_t) data.readInt32(); |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame^] | 134 | AttributionSourceState attributionSource; |
| 135 | status_t status = data.readParcelable(&attributionSource); |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 136 | if (status != NO_ERROR) { |
| 137 | return status; |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 138 | } |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame^] | 139 | sp<IMediaPlayer> player = create(client, audioSessionId, attributionSource); |
Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 140 | reply->writeStrongBinder(IInterface::asBinder(player)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | return NO_ERROR; |
| 142 | } break; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | case CREATE_MEDIA_RECORDER: { |
| 144 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame^] | 145 | AttributionSourceState attributionSource; |
| 146 | status_t status = data.readParcelable(&attributionSource); |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 147 | if (status != NO_ERROR) { |
| 148 | return status; |
| 149 | } |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame^] | 150 | sp<IMediaRecorder> recorder = createMediaRecorder(attributionSource); |
Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 151 | reply->writeStrongBinder(IInterface::asBinder(recorder)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | return NO_ERROR; |
| 153 | } break; |
| 154 | case CREATE_METADATA_RETRIEVER: { |
| 155 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
Glenn Kasten | f37971f | 2012-02-03 11:06:53 -0800 | [diff] [blame] | 156 | sp<IMediaMetadataRetriever> retriever = createMetadataRetriever(); |
Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 157 | reply->writeStrongBinder(IInterface::asBinder(retriever)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | return NO_ERROR; |
| 159 | } break; |
Gloria Wang | 7cf180c | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 160 | case ADD_BATTERY_DATA: { |
| 161 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
| 162 | uint32_t params = data.readInt32(); |
| 163 | addBatteryData(params); |
| 164 | return NO_ERROR; |
| 165 | } break; |
| 166 | case PULL_BATTERY_DATA: { |
| 167 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
| 168 | pullBatteryData(reply); |
| 169 | return NO_ERROR; |
| 170 | } break; |
Jeff Brown | 2013a54 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 171 | case LISTEN_FOR_REMOTE_DISPLAY: { |
| 172 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
Svet Ganov | be71aa2 | 2015-04-28 12:06:02 -0700 | [diff] [blame] | 173 | const String16 opPackageName = data.readString16(); |
Jeff Brown | 2013a54 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 174 | sp<IRemoteDisplayClient> client( |
| 175 | interface_cast<IRemoteDisplayClient>(data.readStrongBinder())); |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 176 | if (client == NULL) { |
| 177 | reply->writeStrongBinder(NULL); |
| 178 | return NO_ERROR; |
| 179 | } |
Jeff Brown | 2013a54 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 180 | String8 iface(data.readString8()); |
Svet Ganov | be71aa2 | 2015-04-28 12:06:02 -0700 | [diff] [blame] | 181 | sp<IRemoteDisplay> display(listenForRemoteDisplay(opPackageName, client, iface)); |
Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 182 | reply->writeStrongBinder(IInterface::asBinder(display)); |
Jeff Brown | 2013a54 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 183 | return NO_ERROR; |
| 184 | } break; |
Lajos Molnar | 1381d4b | 2014-08-07 15:18:35 -0700 | [diff] [blame] | 185 | case GET_CODEC_LIST: { |
| 186 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
| 187 | sp<IMediaCodecList> mcl = getCodecList(); |
Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 188 | reply->writeStrongBinder(IInterface::asBinder(mcl)); |
Lajos Molnar | 1381d4b | 2014-08-07 15:18:35 -0700 | [diff] [blame] | 189 | return NO_ERROR; |
| 190 | } break; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | default: |
| 192 | return BBinder::onTransact(code, data, reply, flags); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | // ---------------------------------------------------------------------------- |
| 197 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 198 | } // namespace android |