blob: 2e02d1770acd7e6a484a23ef0786aeca7a81f42d [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>
Lajos Molnar1381d4b2014-08-07 15:18:35 -070026#include <media/IMediaCodecList.h>
Andreas Huber1b86fe02014-01-29 11:13:26 -080027#include <media/IMediaHTTPService.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080028#include <media/IMediaPlayerService.h>
29#include <media/IMediaRecorder.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070030#include <media/IOMX.h>
Jeff Brown2013a542012-09-04 21:38:42 -070031#include <media/IRemoteDisplay.h>
32#include <media/IRemoteDisplayClient.h>
Andreas Hubere2b10282010-11-23 11:41:34 -080033#include <media/IStreamSource.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070034
35#include <utils/Errors.h> // for status_t
Jeff Brown2013a542012-09-04 21:38:42 -070036#include <utils/String8.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080037
38namespace android {
39
40enum {
Dave Burked681bbb2011-08-30 14:39:17 +010041 CREATE = IBinder::FIRST_CALL_TRANSACTION,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080042 DECODE_URL,
43 DECODE_FD,
44 CREATE_MEDIA_RECORDER,
45 CREATE_METADATA_RETRIEVER,
Gloria Wang7cf180c2011-02-19 18:37:57 -080046 GET_OMX,
Andreas Hubered3e3e02012-03-26 11:13:27 -070047 MAKE_CRYPTO,
Jeff Tinkercc82dc62013-02-08 10:18:35 -080048 MAKE_DRM,
Andreas Huber59451f82012-09-18 10:36:32 -070049 MAKE_HDCP,
Gloria Wang7cf180c2011-02-19 18:37:57 -080050 ADD_BATTERY_DATA,
Jeff Brown2013a542012-09-04 21:38:42 -070051 PULL_BATTERY_DATA,
52 LISTEN_FOR_REMOTE_DISPLAY,
Lajos Molnar1381d4b2014-08-07 15:18:35 -070053 GET_CODEC_LIST,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080054};
55
56class BpMediaPlayerService: public BpInterface<IMediaPlayerService>
57{
58public:
59 BpMediaPlayerService(const sp<IBinder>& impl)
60 : BpInterface<IMediaPlayerService>(impl)
61 {
62 }
63
Glenn Kastenf37971f2012-02-03 11:06:53 -080064 virtual sp<IMediaMetadataRetriever> createMetadataRetriever()
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080065 {
66 Parcel data, reply;
67 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080068 remote()->transact(CREATE_METADATA_RETRIEVER, data, &reply);
69 return interface_cast<IMediaMetadataRetriever>(reply.readStrongBinder());
70 }
71
Andreas Huber2db84552010-01-28 11:19:57 -080072 virtual sp<IMediaPlayer> create(
Glenn Kastenf37971f2012-02-03 11:06:53 -080073 const sp<IMediaPlayerClient>& client, int audioSessionId) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080074 Parcel data, reply;
75 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080076 data.writeStrongBinder(client->asBinder());
Eric Laurenta514bdb2010-06-21 09:27:30 -070077 data.writeInt32(audioSessionId);
Andreas Huber2db84552010-01-28 11:19:57 -080078
Dave Burked681bbb2011-08-30 14:39:17 +010079 remote()->transact(CREATE, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080080 return interface_cast<IMediaPlayer>(reply.readStrongBinder());
81 }
82
Glenn Kastenf37971f2012-02-03 11:06:53 -080083 virtual sp<IMediaRecorder> createMediaRecorder()
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080084 {
85 Parcel data, reply;
86 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080087 remote()->transact(CREATE_MEDIA_RECORDER, data, &reply);
88 return interface_cast<IMediaRecorder>(reply.readStrongBinder());
89 }
90
Andreas Huber1b86fe02014-01-29 11:13:26 -080091 virtual status_t decode(
92 const sp<IMediaHTTPService> &httpService,
93 const char* url,
94 uint32_t *pSampleRate,
95 int* pNumChannels,
96 audio_format_t* pFormat,
97 const sp<IMemoryHeap>& heap,
98 size_t *pSize)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080099 {
100 Parcel data, reply;
101 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber1b86fe02014-01-29 11:13:26 -0800102 data.writeInt32(httpService != NULL);
103 if (httpService != NULL) {
104 data.writeStrongBinder(httpService->asBinder());
105 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800106 data.writeCString(url);
Eric Laurent3d00aa62013-09-24 09:53:27 -0700107 data.writeStrongBinder(heap->asBinder());
108 status_t status = remote()->transact(DECODE_URL, data, &reply);
109 if (status == NO_ERROR) {
110 status = (status_t)reply.readInt32();
111 if (status == NO_ERROR) {
112 *pSampleRate = uint32_t(reply.readInt32());
113 *pNumChannels = reply.readInt32();
114 *pFormat = (audio_format_t)reply.readInt32();
115 *pSize = (size_t)reply.readInt32();
116 }
117 }
118 return status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800119 }
120
Eric Laurent3d00aa62013-09-24 09:53:27 -0700121 virtual status_t decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate,
122 int* pNumChannels, audio_format_t* pFormat,
123 const sp<IMemoryHeap>& heap, size_t *pSize)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800124 {
125 Parcel data, reply;
126 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
127 data.writeFileDescriptor(fd);
128 data.writeInt64(offset);
129 data.writeInt64(length);
Eric Laurent3d00aa62013-09-24 09:53:27 -0700130 data.writeStrongBinder(heap->asBinder());
131 status_t status = remote()->transact(DECODE_FD, data, &reply);
132 if (status == NO_ERROR) {
133 status = (status_t)reply.readInt32();
134 if (status == NO_ERROR) {
135 *pSampleRate = uint32_t(reply.readInt32());
136 *pNumChannels = reply.readInt32();
137 *pFormat = (audio_format_t)reply.readInt32();
138 *pSize = (size_t)reply.readInt32();
139 }
140 }
141 return status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800142 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700143
Andreas Huber318ad9c2009-10-15 13:46:54 -0700144 virtual sp<IOMX> getOMX() {
Andreas Huber20111aa2009-07-14 16:56:47 -0700145 Parcel data, reply;
146 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber318ad9c2009-10-15 13:46:54 -0700147 remote()->transact(GET_OMX, data, &reply);
Andreas Huber20111aa2009-07-14 16:56:47 -0700148 return interface_cast<IOMX>(reply.readStrongBinder());
149 }
Gloria Wang7cf180c2011-02-19 18:37:57 -0800150
Andreas Hubered3e3e02012-03-26 11:13:27 -0700151 virtual sp<ICrypto> makeCrypto() {
152 Parcel data, reply;
153 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
154 remote()->transact(MAKE_CRYPTO, data, &reply);
155 return interface_cast<ICrypto>(reply.readStrongBinder());
156 }
157
Jeff Tinkercc82dc62013-02-08 10:18:35 -0800158 virtual sp<IDrm> makeDrm() {
159 Parcel data, reply;
160 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
161 remote()->transact(MAKE_DRM, data, &reply);
162 return interface_cast<IDrm>(reply.readStrongBinder());
163 }
164
Andreas Huber279dcd82013-01-30 10:41:25 -0800165 virtual sp<IHDCP> makeHDCP(bool createEncryptionModule) {
Andreas Huber59451f82012-09-18 10:36:32 -0700166 Parcel data, reply;
167 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber279dcd82013-01-30 10:41:25 -0800168 data.writeInt32(createEncryptionModule);
Andreas Huber59451f82012-09-18 10:36:32 -0700169 remote()->transact(MAKE_HDCP, data, &reply);
170 return interface_cast<IHDCP>(reply.readStrongBinder());
171 }
172
Gloria Wang7cf180c2011-02-19 18:37:57 -0800173 virtual void addBatteryData(uint32_t params) {
174 Parcel data, reply;
175 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
176 data.writeInt32(params);
177 remote()->transact(ADD_BATTERY_DATA, data, &reply);
178 }
179
180 virtual status_t pullBatteryData(Parcel* reply) {
181 Parcel data;
182 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
183 return remote()->transact(PULL_BATTERY_DATA, data, reply);
184 }
Jeff Brown2013a542012-09-04 21:38:42 -0700185
186 virtual sp<IRemoteDisplay> listenForRemoteDisplay(const sp<IRemoteDisplayClient>& client,
187 const String8& iface)
188 {
189 Parcel data, reply;
190 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
191 data.writeStrongBinder(client->asBinder());
192 data.writeString8(iface);
193 remote()->transact(LISTEN_FOR_REMOTE_DISPLAY, data, &reply);
194 return interface_cast<IRemoteDisplay>(reply.readStrongBinder());
195 }
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700196
197 virtual sp<IMediaCodecList> getCodecList() const {
198 Parcel data, reply;
199 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
200 remote()->transact(GET_CODEC_LIST, data, &reply);
201 return interface_cast<IMediaCodecList>(reply.readStrongBinder());
202 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800203};
204
niko56f0cc52009-06-22 08:49:52 -0700205IMPLEMENT_META_INTERFACE(MediaPlayerService, "android.media.IMediaPlayerService");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800206
207// ----------------------------------------------------------------------
208
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800209status_t BnMediaPlayerService::onTransact(
210 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
211{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700212 switch (code) {
Dave Burked681bbb2011-08-30 14:39:17 +0100213 case CREATE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800214 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber2db84552010-01-28 11:19:57 -0800215 sp<IMediaPlayerClient> client =
216 interface_cast<IMediaPlayerClient>(data.readStrongBinder());
Eric Laurenta514bdb2010-06-21 09:27:30 -0700217 int audioSessionId = data.readInt32();
Glenn Kastenf37971f2012-02-03 11:06:53 -0800218 sp<IMediaPlayer> player = create(client, audioSessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800219 reply->writeStrongBinder(player->asBinder());
220 return NO_ERROR;
221 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800222 case DECODE_URL: {
223 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber1b86fe02014-01-29 11:13:26 -0800224 sp<IMediaHTTPService> httpService;
225 if (data.readInt32()) {
226 httpService =
227 interface_cast<IMediaHTTPService>(data.readStrongBinder());
228 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800229 const char* url = data.readCString();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700230 sp<IMemoryHeap> heap = interface_cast<IMemoryHeap>(data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800231 uint32_t sampleRate;
232 int numChannels;
Glenn Kastene1c39622012-01-04 09:36:37 -0800233 audio_format_t format;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700234 size_t size;
Andreas Huber1b86fe02014-01-29 11:13:26 -0800235 status_t status =
236 decode(httpService,
237 url,
238 &sampleRate,
239 &numChannels,
240 &format,
241 heap,
242 &size);
Eric Laurent3d00aa62013-09-24 09:53:27 -0700243 reply->writeInt32(status);
244 if (status == NO_ERROR) {
245 reply->writeInt32(sampleRate);
246 reply->writeInt32(numChannels);
247 reply->writeInt32((int32_t)format);
248 reply->writeInt32((int32_t)size);
249 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800250 return NO_ERROR;
251 } break;
252 case DECODE_FD: {
253 CHECK_INTERFACE(IMediaPlayerService, data, reply);
254 int fd = dup(data.readFileDescriptor());
255 int64_t offset = data.readInt64();
256 int64_t length = data.readInt64();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700257 sp<IMemoryHeap> heap = interface_cast<IMemoryHeap>(data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800258 uint32_t sampleRate;
259 int numChannels;
Glenn Kastene1c39622012-01-04 09:36:37 -0800260 audio_format_t format;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700261 size_t size;
262 status_t status = decode(fd, offset, length, &sampleRate, &numChannels, &format,
263 heap, &size);
264 reply->writeInt32(status);
265 if (status == NO_ERROR) {
266 reply->writeInt32(sampleRate);
267 reply->writeInt32(numChannels);
268 reply->writeInt32((int32_t)format);
269 reply->writeInt32((int32_t)size);
270 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800271 return NO_ERROR;
272 } break;
273 case CREATE_MEDIA_RECORDER: {
274 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800275 sp<IMediaRecorder> recorder = createMediaRecorder();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800276 reply->writeStrongBinder(recorder->asBinder());
277 return NO_ERROR;
278 } break;
279 case CREATE_METADATA_RETRIEVER: {
280 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800281 sp<IMediaMetadataRetriever> retriever = createMetadataRetriever();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800282 reply->writeStrongBinder(retriever->asBinder());
283 return NO_ERROR;
284 } break;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700285 case GET_OMX: {
Andreas Huber20111aa2009-07-14 16:56:47 -0700286 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber318ad9c2009-10-15 13:46:54 -0700287 sp<IOMX> omx = getOMX();
Andreas Huber20111aa2009-07-14 16:56:47 -0700288 reply->writeStrongBinder(omx->asBinder());
289 return NO_ERROR;
290 } break;
Andreas Hubered3e3e02012-03-26 11:13:27 -0700291 case MAKE_CRYPTO: {
292 CHECK_INTERFACE(IMediaPlayerService, data, reply);
293 sp<ICrypto> crypto = makeCrypto();
294 reply->writeStrongBinder(crypto->asBinder());
295 return NO_ERROR;
296 } break;
Jeff Tinkercc82dc62013-02-08 10:18:35 -0800297 case MAKE_DRM: {
298 CHECK_INTERFACE(IMediaPlayerService, data, reply);
299 sp<IDrm> drm = makeDrm();
300 reply->writeStrongBinder(drm->asBinder());
301 return NO_ERROR;
302 } break;
Andreas Huber59451f82012-09-18 10:36:32 -0700303 case MAKE_HDCP: {
304 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber279dcd82013-01-30 10:41:25 -0800305 bool createEncryptionModule = data.readInt32();
306 sp<IHDCP> hdcp = makeHDCP(createEncryptionModule);
Andreas Huber59451f82012-09-18 10:36:32 -0700307 reply->writeStrongBinder(hdcp->asBinder());
308 return NO_ERROR;
309 } break;
Gloria Wang7cf180c2011-02-19 18:37:57 -0800310 case ADD_BATTERY_DATA: {
311 CHECK_INTERFACE(IMediaPlayerService, data, reply);
312 uint32_t params = data.readInt32();
313 addBatteryData(params);
314 return NO_ERROR;
315 } break;
316 case PULL_BATTERY_DATA: {
317 CHECK_INTERFACE(IMediaPlayerService, data, reply);
318 pullBatteryData(reply);
319 return NO_ERROR;
320 } break;
Jeff Brown2013a542012-09-04 21:38:42 -0700321 case LISTEN_FOR_REMOTE_DISPLAY: {
322 CHECK_INTERFACE(IMediaPlayerService, data, reply);
323 sp<IRemoteDisplayClient> client(
324 interface_cast<IRemoteDisplayClient>(data.readStrongBinder()));
325 String8 iface(data.readString8());
326 sp<IRemoteDisplay> display(listenForRemoteDisplay(client, iface));
327 reply->writeStrongBinder(display->asBinder());
328 return NO_ERROR;
329 } break;
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700330 case GET_CODEC_LIST: {
331 CHECK_INTERFACE(IMediaPlayerService, data, reply);
332 sp<IMediaCodecList> mcl = getCodecList();
333 reply->writeStrongBinder(mcl->asBinder());
334 return NO_ERROR;
335 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800336 default:
337 return BBinder::onTransact(code, data, reply, flags);
338 }
339}
340
341// ----------------------------------------------------------------------------
342
343}; // namespace android