blob: f8326b607a43355a81bbc075a31c133755f4ad9a [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
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 Project89fa4ad2009-03-03 19:31:44 -080020
Andreas Huber20111aa2009-07-14 16:56:47 -070021#include <binder/Parcel.h>
Mathias Agopian75624082009-05-19 19:08:10 -070022#include <binder/IMemory.h>
Vladimir Olteand0aa6472019-01-09 01:13:10 +020023#include <media/IHDCP.h>
Lajos Molnar1381d4b2014-08-07 15:18:35 -070024#include <media/IMediaCodecList.h>
Andreas Huber1b86fe02014-01-29 11:13:26 -080025#include <media/IMediaHTTPService.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080026#include <media/IMediaPlayerService.h>
Marco Nelissen5dcf85a2018-10-11 09:49:02 -070027#include <media/IMediaPlayer.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080028#include <media/IMediaRecorder.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070029#include <media/IOMX.h>
Jeff Brown2013a542012-09-04 21:38:42 -070030#include <media/IRemoteDisplay.h>
31#include <media/IRemoteDisplayClient.h>
Andreas Hubere2b10282010-11-23 11:41:34 -080032#include <media/IStreamSource.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070033
34#include <utils/Errors.h> // for status_t
Jeff Brown2013a542012-09-04 21:38:42 -070035#include <utils/String8.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080036
37namespace android {
38
Svet Ganov3e5f14f2021-05-13 22:51:08 +000039using android::content::AttributionSourceState;
Philip P. Moltmannbda45752020-07-17 16:41:18 -070040
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080041enum {
Dave Burked681bbb2011-08-30 14:39:17 +010042 CREATE = IBinder::FIRST_CALL_TRANSACTION,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080043 CREATE_MEDIA_RECORDER,
44 CREATE_METADATA_RETRIEVER,
Vladimir Olteand0aa6472019-01-09 01:13:10 +020045 MAKE_HDCP,
Gloria Wang7cf180c2011-02-19 18:37:57 -080046 ADD_BATTERY_DATA,
Jeff Brown2013a542012-09-04 21:38:42 -070047 PULL_BATTERY_DATA,
48 LISTEN_FOR_REMOTE_DISPLAY,
Lajos Molnar1381d4b2014-08-07 15:18:35 -070049 GET_CODEC_LIST,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080050};
51
52class BpMediaPlayerService: public BpInterface<IMediaPlayerService>
53{
54public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070055 explicit BpMediaPlayerService(const sp<IBinder>& impl)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080056 : BpInterface<IMediaPlayerService>(impl)
57 {
58 }
59
Glenn Kastenf37971f2012-02-03 11:06:53 -080060 virtual sp<IMediaMetadataRetriever> createMetadataRetriever()
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080061 {
62 Parcel data, reply;
63 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080064 remote()->transact(CREATE_METADATA_RETRIEVER, data, &reply);
65 return interface_cast<IMediaMetadataRetriever>(reply.readStrongBinder());
66 }
67
Andreas Huber2db84552010-01-28 11:19:57 -080068 virtual sp<IMediaPlayer> create(
Colin Crossb8a9dbb2020-08-27 04:12:26 +000069 const sp<IMediaPlayerClient>& client, audio_session_t audioSessionId,
Svet Ganov3e5f14f2021-05-13 22:51:08 +000070 const AttributionSourceState& attributionSource) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080071 Parcel data, reply;
72 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -080073 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurenta514bdb2010-06-21 09:27:30 -070074 data.writeInt32(audioSessionId);
Svet Ganov3e5f14f2021-05-13 22:51:08 +000075 data.writeParcelable(attributionSource);
Andreas Huber2db84552010-01-28 11:19:57 -080076
Dave Burked681bbb2011-08-30 14:39:17 +010077 remote()->transact(CREATE, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080078 return interface_cast<IMediaPlayer>(reply.readStrongBinder());
79 }
80
Svet Ganov3e5f14f2021-05-13 22:51:08 +000081 virtual sp<IMediaRecorder> createMediaRecorder(const AttributionSourceState& attributionSource)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080082 {
83 Parcel data, reply;
84 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Svet Ganov3e5f14f2021-05-13 22:51:08 +000085 data.writeParcelable(attributionSource);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080086 remote()->transact(CREATE_MEDIA_RECORDER, data, &reply);
87 return interface_cast<IMediaRecorder>(reply.readStrongBinder());
88 }
89
Vladimir Olteand0aa6472019-01-09 01:13:10 +020090 virtual sp<IHDCP> makeHDCP(bool createEncryptionModule) {
91 Parcel data, reply;
92 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
93 data.writeInt32(createEncryptionModule);
94 remote()->transact(MAKE_HDCP, data, &reply);
95 return interface_cast<IHDCP>(reply.readStrongBinder());
96 }
97
Gloria Wang7cf180c2011-02-19 18:37:57 -080098 virtual void addBatteryData(uint32_t params) {
99 Parcel data, reply;
100 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
101 data.writeInt32(params);
102 remote()->transact(ADD_BATTERY_DATA, data, &reply);
103 }
104
105 virtual status_t pullBatteryData(Parcel* reply) {
106 Parcel data;
107 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
108 return remote()->transact(PULL_BATTERY_DATA, data, reply);
109 }
Jeff Brown2013a542012-09-04 21:38:42 -0700110
Svet Ganovbe71aa22015-04-28 12:06:02 -0700111 virtual sp<IRemoteDisplay> listenForRemoteDisplay(const String16 &opPackageName,
112 const sp<IRemoteDisplayClient>& client, const String8& iface)
Jeff Brown2013a542012-09-04 21:38:42 -0700113 {
114 Parcel data, reply;
115 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Svet Ganovbe71aa22015-04-28 12:06:02 -0700116 data.writeString16(opPackageName);
Marco Nelissenf8880202014-11-14 07:58:25 -0800117 data.writeStrongBinder(IInterface::asBinder(client));
Jeff Brown2013a542012-09-04 21:38:42 -0700118 data.writeString8(iface);
119 remote()->transact(LISTEN_FOR_REMOTE_DISPLAY, data, &reply);
120 return interface_cast<IRemoteDisplay>(reply.readStrongBinder());
121 }
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700122
123 virtual sp<IMediaCodecList> getCodecList() const {
124 Parcel data, reply;
125 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
126 remote()->transact(GET_CODEC_LIST, data, &reply);
127 return interface_cast<IMediaCodecList>(reply.readStrongBinder());
128 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800129};
130
niko56f0cc52009-06-22 08:49:52 -0700131IMPLEMENT_META_INTERFACE(MediaPlayerService, "android.media.IMediaPlayerService");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800132
133// ----------------------------------------------------------------------
134
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800135status_t BnMediaPlayerService::onTransact(
136 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
137{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700138 switch (code) {
Dave Burked681bbb2011-08-30 14:39:17 +0100139 case CREATE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800140 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber2db84552010-01-28 11:19:57 -0800141 sp<IMediaPlayerClient> client =
142 interface_cast<IMediaPlayerClient>(data.readStrongBinder());
Glenn Kastend848eb42016-03-08 13:42:11 -0800143 audio_session_t audioSessionId = (audio_session_t) data.readInt32();
Svet Ganov3e5f14f2021-05-13 22:51:08 +0000144 AttributionSourceState attributionSource;
145 status_t status = data.readParcelable(&attributionSource);
Philip P. Moltmannbda45752020-07-17 16:41:18 -0700146 if (status != NO_ERROR) {
147 return status;
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000148 }
Svet Ganov3e5f14f2021-05-13 22:51:08 +0000149 sp<IMediaPlayer> player = create(client, audioSessionId, attributionSource);
Marco Nelissenf8880202014-11-14 07:58:25 -0800150 reply->writeStrongBinder(IInterface::asBinder(player));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800151 return NO_ERROR;
152 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800153 case CREATE_MEDIA_RECORDER: {
154 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Svet Ganov3e5f14f2021-05-13 22:51:08 +0000155 AttributionSourceState attributionSource;
156 status_t status = data.readParcelable(&attributionSource);
Philip P. Moltmannbda45752020-07-17 16:41:18 -0700157 if (status != NO_ERROR) {
158 return status;
159 }
Svet Ganov3e5f14f2021-05-13 22:51:08 +0000160 sp<IMediaRecorder> recorder = createMediaRecorder(attributionSource);
Marco Nelissenf8880202014-11-14 07:58:25 -0800161 reply->writeStrongBinder(IInterface::asBinder(recorder));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800162 return NO_ERROR;
163 } break;
164 case CREATE_METADATA_RETRIEVER: {
165 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800166 sp<IMediaMetadataRetriever> retriever = createMetadataRetriever();
Marco Nelissenf8880202014-11-14 07:58:25 -0800167 reply->writeStrongBinder(IInterface::asBinder(retriever));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800168 return NO_ERROR;
169 } break;
Vladimir Olteand0aa6472019-01-09 01:13:10 +0200170 case MAKE_HDCP: {
171 CHECK_INTERFACE(IMediaPlayerService, data, reply);
172 bool createEncryptionModule = data.readInt32();
173 sp<IHDCP> hdcp = makeHDCP(createEncryptionModule);
174 reply->writeStrongBinder(IInterface::asBinder(hdcp));
175 return NO_ERROR;
176 } break;
Gloria Wang7cf180c2011-02-19 18:37:57 -0800177 case ADD_BATTERY_DATA: {
178 CHECK_INTERFACE(IMediaPlayerService, data, reply);
179 uint32_t params = data.readInt32();
180 addBatteryData(params);
181 return NO_ERROR;
182 } break;
183 case PULL_BATTERY_DATA: {
184 CHECK_INTERFACE(IMediaPlayerService, data, reply);
185 pullBatteryData(reply);
186 return NO_ERROR;
187 } break;
Jeff Brown2013a542012-09-04 21:38:42 -0700188 case LISTEN_FOR_REMOTE_DISPLAY: {
189 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700190 const String16 opPackageName = data.readString16();
Jeff Brown2013a542012-09-04 21:38:42 -0700191 sp<IRemoteDisplayClient> client(
192 interface_cast<IRemoteDisplayClient>(data.readStrongBinder()));
Wei Jia2afac0c2016-01-07 12:13:07 -0800193 if (client == NULL) {
194 reply->writeStrongBinder(NULL);
195 return NO_ERROR;
196 }
Jeff Brown2013a542012-09-04 21:38:42 -0700197 String8 iface(data.readString8());
Svet Ganovbe71aa22015-04-28 12:06:02 -0700198 sp<IRemoteDisplay> display(listenForRemoteDisplay(opPackageName, client, iface));
Marco Nelissenf8880202014-11-14 07:58:25 -0800199 reply->writeStrongBinder(IInterface::asBinder(display));
Jeff Brown2013a542012-09-04 21:38:42 -0700200 return NO_ERROR;
201 } break;
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700202 case GET_CODEC_LIST: {
203 CHECK_INTERFACE(IMediaPlayerService, data, reply);
204 sp<IMediaCodecList> mcl = getCodecList();
Marco Nelissenf8880202014-11-14 07:58:25 -0800205 reply->writeStrongBinder(IInterface::asBinder(mcl));
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700206 return NO_ERROR;
207 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800208 default:
209 return BBinder::onTransact(code, data, reply, flags);
210 }
211}
212
213// ----------------------------------------------------------------------------
214
Glenn Kasten40bc9062015-03-20 09:09:33 -0700215} // namespace android