blob: 190adf25339942d775a67fa6669d73687719898a [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>
Andreas Hubered3e3e02012-03-26 11:13:27 -070023#include <media/ICrypto.h>
Jeff Tinkercc82dc62013-02-08 10:18:35 -080024#include <media/IDrm.h>
Andreas Huber59451f82012-09-18 10:36:32 -070025#include <media/IHDCP.h>
Andreas Huber1b86fe02014-01-29 11:13:26 -080026#include <media/IMediaHTTPService.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080027#include <media/IMediaPlayerService.h>
28#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
39enum {
Dave Burked681bbb2011-08-30 14:39:17 +010040 CREATE = IBinder::FIRST_CALL_TRANSACTION,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080041 DECODE_URL,
42 DECODE_FD,
43 CREATE_MEDIA_RECORDER,
44 CREATE_METADATA_RETRIEVER,
Gloria Wang7cf180c2011-02-19 18:37:57 -080045 GET_OMX,
Andreas Hubered3e3e02012-03-26 11:13:27 -070046 MAKE_CRYPTO,
Jeff Tinkercc82dc62013-02-08 10:18:35 -080047 MAKE_DRM,
Andreas Huber59451f82012-09-18 10:36:32 -070048 MAKE_HDCP,
Gloria Wang7cf180c2011-02-19 18:37:57 -080049 ADD_BATTERY_DATA,
Jeff Brown2013a542012-09-04 21:38:42 -070050 PULL_BATTERY_DATA,
51 LISTEN_FOR_REMOTE_DISPLAY,
Andreas Huberb7319a72013-05-29 14:20:52 -070052 UPDATE_PROXY_CONFIG,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080053};
54
55class BpMediaPlayerService: public BpInterface<IMediaPlayerService>
56{
57public:
58 BpMediaPlayerService(const sp<IBinder>& impl)
59 : BpInterface<IMediaPlayerService>(impl)
60 {
61 }
62
Glenn Kastenf37971f2012-02-03 11:06:53 -080063 virtual sp<IMediaMetadataRetriever> createMetadataRetriever()
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080064 {
65 Parcel data, reply;
66 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080067 remote()->transact(CREATE_METADATA_RETRIEVER, data, &reply);
68 return interface_cast<IMediaMetadataRetriever>(reply.readStrongBinder());
69 }
70
Andreas Huber2db84552010-01-28 11:19:57 -080071 virtual sp<IMediaPlayer> create(
Glenn Kastenf37971f2012-02-03 11:06:53 -080072 const sp<IMediaPlayerClient>& client, int audioSessionId) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080073 Parcel data, reply;
74 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080075 data.writeStrongBinder(client->asBinder());
Eric Laurenta514bdb2010-06-21 09:27:30 -070076 data.writeInt32(audioSessionId);
Andreas Huber2db84552010-01-28 11:19:57 -080077
Dave Burked681bbb2011-08-30 14:39:17 +010078 remote()->transact(CREATE, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080079 return interface_cast<IMediaPlayer>(reply.readStrongBinder());
80 }
81
Glenn Kastenf37971f2012-02-03 11:06:53 -080082 virtual sp<IMediaRecorder> createMediaRecorder()
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080083 {
84 Parcel data, reply;
85 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
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
Andreas Huber1b86fe02014-01-29 11:13:26 -080090 virtual status_t decode(
91 const sp<IMediaHTTPService> &httpService,
92 const char* url,
93 uint32_t *pSampleRate,
94 int* pNumChannels,
95 audio_format_t* pFormat,
96 const sp<IMemoryHeap>& heap,
97 size_t *pSize)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080098 {
99 Parcel data, reply;
100 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber1b86fe02014-01-29 11:13:26 -0800101 data.writeInt32(httpService != NULL);
102 if (httpService != NULL) {
103 data.writeStrongBinder(httpService->asBinder());
104 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800105 data.writeCString(url);
Eric Laurent3d00aa62013-09-24 09:53:27 -0700106 data.writeStrongBinder(heap->asBinder());
107 status_t status = remote()->transact(DECODE_URL, data, &reply);
108 if (status == NO_ERROR) {
109 status = (status_t)reply.readInt32();
110 if (status == NO_ERROR) {
111 *pSampleRate = uint32_t(reply.readInt32());
112 *pNumChannels = reply.readInt32();
113 *pFormat = (audio_format_t)reply.readInt32();
114 *pSize = (size_t)reply.readInt32();
115 }
116 }
117 return status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800118 }
119
Eric Laurent3d00aa62013-09-24 09:53:27 -0700120 virtual status_t decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate,
121 int* pNumChannels, audio_format_t* pFormat,
122 const sp<IMemoryHeap>& heap, size_t *pSize)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800123 {
124 Parcel data, reply;
125 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
126 data.writeFileDescriptor(fd);
127 data.writeInt64(offset);
128 data.writeInt64(length);
Eric Laurent3d00aa62013-09-24 09:53:27 -0700129 data.writeStrongBinder(heap->asBinder());
130 status_t status = remote()->transact(DECODE_FD, data, &reply);
131 if (status == NO_ERROR) {
132 status = (status_t)reply.readInt32();
133 if (status == NO_ERROR) {
134 *pSampleRate = uint32_t(reply.readInt32());
135 *pNumChannels = reply.readInt32();
136 *pFormat = (audio_format_t)reply.readInt32();
137 *pSize = (size_t)reply.readInt32();
138 }
139 }
140 return status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800141 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700142
Andreas Huber318ad9c2009-10-15 13:46:54 -0700143 virtual sp<IOMX> getOMX() {
Andreas Huber20111aa2009-07-14 16:56:47 -0700144 Parcel data, reply;
145 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber318ad9c2009-10-15 13:46:54 -0700146 remote()->transact(GET_OMX, data, &reply);
Andreas Huber20111aa2009-07-14 16:56:47 -0700147 return interface_cast<IOMX>(reply.readStrongBinder());
148 }
Gloria Wang7cf180c2011-02-19 18:37:57 -0800149
Andreas Hubered3e3e02012-03-26 11:13:27 -0700150 virtual sp<ICrypto> makeCrypto() {
151 Parcel data, reply;
152 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
153 remote()->transact(MAKE_CRYPTO, data, &reply);
154 return interface_cast<ICrypto>(reply.readStrongBinder());
155 }
156
Jeff Tinkercc82dc62013-02-08 10:18:35 -0800157 virtual sp<IDrm> makeDrm() {
158 Parcel data, reply;
159 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
160 remote()->transact(MAKE_DRM, data, &reply);
161 return interface_cast<IDrm>(reply.readStrongBinder());
162 }
163
Andreas Huber279dcd82013-01-30 10:41:25 -0800164 virtual sp<IHDCP> makeHDCP(bool createEncryptionModule) {
Andreas Huber59451f82012-09-18 10:36:32 -0700165 Parcel data, reply;
166 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber279dcd82013-01-30 10:41:25 -0800167 data.writeInt32(createEncryptionModule);
Andreas Huber59451f82012-09-18 10:36:32 -0700168 remote()->transact(MAKE_HDCP, data, &reply);
169 return interface_cast<IHDCP>(reply.readStrongBinder());
170 }
171
Gloria Wang7cf180c2011-02-19 18:37:57 -0800172 virtual void addBatteryData(uint32_t params) {
173 Parcel data, reply;
174 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
175 data.writeInt32(params);
176 remote()->transact(ADD_BATTERY_DATA, data, &reply);
177 }
178
179 virtual status_t pullBatteryData(Parcel* reply) {
180 Parcel data;
181 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
182 return remote()->transact(PULL_BATTERY_DATA, data, reply);
183 }
Jeff Brown2013a542012-09-04 21:38:42 -0700184
185 virtual sp<IRemoteDisplay> listenForRemoteDisplay(const sp<IRemoteDisplayClient>& client,
186 const String8& iface)
187 {
188 Parcel data, reply;
189 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
190 data.writeStrongBinder(client->asBinder());
191 data.writeString8(iface);
192 remote()->transact(LISTEN_FOR_REMOTE_DISPLAY, data, &reply);
193 return interface_cast<IRemoteDisplay>(reply.readStrongBinder());
194 }
Andreas Huberb7319a72013-05-29 14:20:52 -0700195
196 virtual status_t updateProxyConfig(
197 const char *host, int32_t port, const char *exclusionList) {
198 Parcel data, reply;
199
200 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
201 if (host == NULL) {
202 data.writeInt32(0);
203 } else {
204 data.writeInt32(1);
205 data.writeCString(host);
206 data.writeInt32(port);
207 data.writeCString(exclusionList);
208 }
209
210 remote()->transact(UPDATE_PROXY_CONFIG, data, &reply);
211
212 return reply.readInt32();
213 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800214};
215
niko56f0cc52009-06-22 08:49:52 -0700216IMPLEMENT_META_INTERFACE(MediaPlayerService, "android.media.IMediaPlayerService");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800217
218// ----------------------------------------------------------------------
219
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800220status_t BnMediaPlayerService::onTransact(
221 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
222{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700223 switch (code) {
Dave Burked681bbb2011-08-30 14:39:17 +0100224 case CREATE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800225 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber2db84552010-01-28 11:19:57 -0800226 sp<IMediaPlayerClient> client =
227 interface_cast<IMediaPlayerClient>(data.readStrongBinder());
Eric Laurenta514bdb2010-06-21 09:27:30 -0700228 int audioSessionId = data.readInt32();
Glenn Kastenf37971f2012-02-03 11:06:53 -0800229 sp<IMediaPlayer> player = create(client, audioSessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800230 reply->writeStrongBinder(player->asBinder());
231 return NO_ERROR;
232 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800233 case DECODE_URL: {
234 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber1b86fe02014-01-29 11:13:26 -0800235 sp<IMediaHTTPService> httpService;
236 if (data.readInt32()) {
237 httpService =
238 interface_cast<IMediaHTTPService>(data.readStrongBinder());
239 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800240 const char* url = data.readCString();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700241 sp<IMemoryHeap> heap = interface_cast<IMemoryHeap>(data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800242 uint32_t sampleRate;
243 int numChannels;
Glenn Kastene1c39622012-01-04 09:36:37 -0800244 audio_format_t format;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700245 size_t size;
Andreas Huber1b86fe02014-01-29 11:13:26 -0800246 status_t status =
247 decode(httpService,
248 url,
249 &sampleRate,
250 &numChannels,
251 &format,
252 heap,
253 &size);
Eric Laurent3d00aa62013-09-24 09:53:27 -0700254 reply->writeInt32(status);
255 if (status == NO_ERROR) {
256 reply->writeInt32(sampleRate);
257 reply->writeInt32(numChannels);
258 reply->writeInt32((int32_t)format);
259 reply->writeInt32((int32_t)size);
260 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800261 return NO_ERROR;
262 } break;
263 case DECODE_FD: {
264 CHECK_INTERFACE(IMediaPlayerService, data, reply);
265 int fd = dup(data.readFileDescriptor());
266 int64_t offset = data.readInt64();
267 int64_t length = data.readInt64();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700268 sp<IMemoryHeap> heap = interface_cast<IMemoryHeap>(data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800269 uint32_t sampleRate;
270 int numChannels;
Glenn Kastene1c39622012-01-04 09:36:37 -0800271 audio_format_t format;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700272 size_t size;
273 status_t status = decode(fd, offset, length, &sampleRate, &numChannels, &format,
274 heap, &size);
275 reply->writeInt32(status);
276 if (status == NO_ERROR) {
277 reply->writeInt32(sampleRate);
278 reply->writeInt32(numChannels);
279 reply->writeInt32((int32_t)format);
280 reply->writeInt32((int32_t)size);
281 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800282 return NO_ERROR;
283 } break;
284 case CREATE_MEDIA_RECORDER: {
285 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800286 sp<IMediaRecorder> recorder = createMediaRecorder();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800287 reply->writeStrongBinder(recorder->asBinder());
288 return NO_ERROR;
289 } break;
290 case CREATE_METADATA_RETRIEVER: {
291 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800292 sp<IMediaMetadataRetriever> retriever = createMetadataRetriever();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800293 reply->writeStrongBinder(retriever->asBinder());
294 return NO_ERROR;
295 } break;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700296 case GET_OMX: {
Andreas Huber20111aa2009-07-14 16:56:47 -0700297 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber318ad9c2009-10-15 13:46:54 -0700298 sp<IOMX> omx = getOMX();
Andreas Huber20111aa2009-07-14 16:56:47 -0700299 reply->writeStrongBinder(omx->asBinder());
300 return NO_ERROR;
301 } break;
Andreas Hubered3e3e02012-03-26 11:13:27 -0700302 case MAKE_CRYPTO: {
303 CHECK_INTERFACE(IMediaPlayerService, data, reply);
304 sp<ICrypto> crypto = makeCrypto();
305 reply->writeStrongBinder(crypto->asBinder());
306 return NO_ERROR;
307 } break;
Jeff Tinkercc82dc62013-02-08 10:18:35 -0800308 case MAKE_DRM: {
309 CHECK_INTERFACE(IMediaPlayerService, data, reply);
310 sp<IDrm> drm = makeDrm();
311 reply->writeStrongBinder(drm->asBinder());
312 return NO_ERROR;
313 } break;
Andreas Huber59451f82012-09-18 10:36:32 -0700314 case MAKE_HDCP: {
315 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber279dcd82013-01-30 10:41:25 -0800316 bool createEncryptionModule = data.readInt32();
317 sp<IHDCP> hdcp = makeHDCP(createEncryptionModule);
Andreas Huber59451f82012-09-18 10:36:32 -0700318 reply->writeStrongBinder(hdcp->asBinder());
319 return NO_ERROR;
320 } break;
Gloria Wang7cf180c2011-02-19 18:37:57 -0800321 case ADD_BATTERY_DATA: {
322 CHECK_INTERFACE(IMediaPlayerService, data, reply);
323 uint32_t params = data.readInt32();
324 addBatteryData(params);
325 return NO_ERROR;
326 } break;
327 case PULL_BATTERY_DATA: {
328 CHECK_INTERFACE(IMediaPlayerService, data, reply);
329 pullBatteryData(reply);
330 return NO_ERROR;
331 } break;
Jeff Brown2013a542012-09-04 21:38:42 -0700332 case LISTEN_FOR_REMOTE_DISPLAY: {
333 CHECK_INTERFACE(IMediaPlayerService, data, reply);
334 sp<IRemoteDisplayClient> client(
335 interface_cast<IRemoteDisplayClient>(data.readStrongBinder()));
336 String8 iface(data.readString8());
337 sp<IRemoteDisplay> display(listenForRemoteDisplay(client, iface));
338 reply->writeStrongBinder(display->asBinder());
339 return NO_ERROR;
340 } break;
Andreas Huberb7319a72013-05-29 14:20:52 -0700341 case UPDATE_PROXY_CONFIG:
342 {
343 CHECK_INTERFACE(IMediaPlayerService, data, reply);
344
345 const char *host = NULL;
346 int32_t port = 0;
347 const char *exclusionList = NULL;
348
349 if (data.readInt32()) {
350 host = data.readCString();
351 port = data.readInt32();
352 exclusionList = data.readCString();
353 }
354
355 reply->writeInt32(updateProxyConfig(host, port, exclusionList));
356
357 return OK;
358 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800359 default:
360 return BBinder::onTransact(code, data, reply, flags);
361 }
362}
363
364// ----------------------------------------------------------------------------
365
366}; // namespace android