blob: d116b149066ec3108dc403591e5a4b5f983f9293 [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,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080052};
53
54class BpMediaPlayerService: public BpInterface<IMediaPlayerService>
55{
56public:
57 BpMediaPlayerService(const sp<IBinder>& impl)
58 : BpInterface<IMediaPlayerService>(impl)
59 {
60 }
61
Glenn Kastenf37971f2012-02-03 11:06:53 -080062 virtual sp<IMediaMetadataRetriever> createMetadataRetriever()
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080063 {
64 Parcel data, reply;
65 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080066 remote()->transact(CREATE_METADATA_RETRIEVER, data, &reply);
67 return interface_cast<IMediaMetadataRetriever>(reply.readStrongBinder());
68 }
69
Andreas Huber2db84552010-01-28 11:19:57 -080070 virtual sp<IMediaPlayer> create(
Glenn Kastenf37971f2012-02-03 11:06:53 -080071 const sp<IMediaPlayerClient>& client, int audioSessionId) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080072 Parcel data, reply;
73 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080074 data.writeStrongBinder(client->asBinder());
Eric Laurenta514bdb2010-06-21 09:27:30 -070075 data.writeInt32(audioSessionId);
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
Glenn Kastenf37971f2012-02-03 11:06:53 -080081 virtual sp<IMediaRecorder> createMediaRecorder()
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080082 {
83 Parcel data, reply;
84 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080085 remote()->transact(CREATE_MEDIA_RECORDER, data, &reply);
86 return interface_cast<IMediaRecorder>(reply.readStrongBinder());
87 }
88
Andreas Huber1b86fe02014-01-29 11:13:26 -080089 virtual status_t decode(
90 const sp<IMediaHTTPService> &httpService,
91 const char* url,
92 uint32_t *pSampleRate,
93 int* pNumChannels,
94 audio_format_t* pFormat,
95 const sp<IMemoryHeap>& heap,
96 size_t *pSize)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080097 {
98 Parcel data, reply;
99 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber1b86fe02014-01-29 11:13:26 -0800100 data.writeInt32(httpService != NULL);
101 if (httpService != NULL) {
102 data.writeStrongBinder(httpService->asBinder());
103 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800104 data.writeCString(url);
Eric Laurent3d00aa62013-09-24 09:53:27 -0700105 data.writeStrongBinder(heap->asBinder());
106 status_t status = remote()->transact(DECODE_URL, data, &reply);
107 if (status == NO_ERROR) {
108 status = (status_t)reply.readInt32();
109 if (status == NO_ERROR) {
110 *pSampleRate = uint32_t(reply.readInt32());
111 *pNumChannels = reply.readInt32();
112 *pFormat = (audio_format_t)reply.readInt32();
113 *pSize = (size_t)reply.readInt32();
114 }
115 }
116 return status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800117 }
118
Eric Laurent3d00aa62013-09-24 09:53:27 -0700119 virtual status_t decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate,
120 int* pNumChannels, audio_format_t* pFormat,
121 const sp<IMemoryHeap>& heap, size_t *pSize)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800122 {
123 Parcel data, reply;
124 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
125 data.writeFileDescriptor(fd);
126 data.writeInt64(offset);
127 data.writeInt64(length);
Eric Laurent3d00aa62013-09-24 09:53:27 -0700128 data.writeStrongBinder(heap->asBinder());
129 status_t status = remote()->transact(DECODE_FD, data, &reply);
130 if (status == NO_ERROR) {
131 status = (status_t)reply.readInt32();
132 if (status == NO_ERROR) {
133 *pSampleRate = uint32_t(reply.readInt32());
134 *pNumChannels = reply.readInt32();
135 *pFormat = (audio_format_t)reply.readInt32();
136 *pSize = (size_t)reply.readInt32();
137 }
138 }
139 return status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800140 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700141
Andreas Huber318ad9c2009-10-15 13:46:54 -0700142 virtual sp<IOMX> getOMX() {
Andreas Huber20111aa2009-07-14 16:56:47 -0700143 Parcel data, reply;
144 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber318ad9c2009-10-15 13:46:54 -0700145 remote()->transact(GET_OMX, data, &reply);
Andreas Huber20111aa2009-07-14 16:56:47 -0700146 return interface_cast<IOMX>(reply.readStrongBinder());
147 }
Gloria Wang7cf180c2011-02-19 18:37:57 -0800148
Andreas Hubered3e3e02012-03-26 11:13:27 -0700149 virtual sp<ICrypto> makeCrypto() {
150 Parcel data, reply;
151 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
152 remote()->transact(MAKE_CRYPTO, data, &reply);
153 return interface_cast<ICrypto>(reply.readStrongBinder());
154 }
155
Jeff Tinkercc82dc62013-02-08 10:18:35 -0800156 virtual sp<IDrm> makeDrm() {
157 Parcel data, reply;
158 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
159 remote()->transact(MAKE_DRM, data, &reply);
160 return interface_cast<IDrm>(reply.readStrongBinder());
161 }
162
Andreas Huber279dcd82013-01-30 10:41:25 -0800163 virtual sp<IHDCP> makeHDCP(bool createEncryptionModule) {
Andreas Huber59451f82012-09-18 10:36:32 -0700164 Parcel data, reply;
165 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber279dcd82013-01-30 10:41:25 -0800166 data.writeInt32(createEncryptionModule);
Andreas Huber59451f82012-09-18 10:36:32 -0700167 remote()->transact(MAKE_HDCP, data, &reply);
168 return interface_cast<IHDCP>(reply.readStrongBinder());
169 }
170
Gloria Wang7cf180c2011-02-19 18:37:57 -0800171 virtual void addBatteryData(uint32_t params) {
172 Parcel data, reply;
173 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
174 data.writeInt32(params);
175 remote()->transact(ADD_BATTERY_DATA, data, &reply);
176 }
177
178 virtual status_t pullBatteryData(Parcel* reply) {
179 Parcel data;
180 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
181 return remote()->transact(PULL_BATTERY_DATA, data, reply);
182 }
Jeff Brown2013a542012-09-04 21:38:42 -0700183
184 virtual sp<IRemoteDisplay> listenForRemoteDisplay(const sp<IRemoteDisplayClient>& client,
185 const String8& iface)
186 {
187 Parcel data, reply;
188 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
189 data.writeStrongBinder(client->asBinder());
190 data.writeString8(iface);
191 remote()->transact(LISTEN_FOR_REMOTE_DISPLAY, data, &reply);
192 return interface_cast<IRemoteDisplay>(reply.readStrongBinder());
193 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800194};
195
niko56f0cc52009-06-22 08:49:52 -0700196IMPLEMENT_META_INTERFACE(MediaPlayerService, "android.media.IMediaPlayerService");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800197
198// ----------------------------------------------------------------------
199
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800200status_t BnMediaPlayerService::onTransact(
201 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
202{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700203 switch (code) {
Dave Burked681bbb2011-08-30 14:39:17 +0100204 case CREATE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800205 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber2db84552010-01-28 11:19:57 -0800206 sp<IMediaPlayerClient> client =
207 interface_cast<IMediaPlayerClient>(data.readStrongBinder());
Eric Laurenta514bdb2010-06-21 09:27:30 -0700208 int audioSessionId = data.readInt32();
Glenn Kastenf37971f2012-02-03 11:06:53 -0800209 sp<IMediaPlayer> player = create(client, audioSessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800210 reply->writeStrongBinder(player->asBinder());
211 return NO_ERROR;
212 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800213 case DECODE_URL: {
214 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber1b86fe02014-01-29 11:13:26 -0800215 sp<IMediaHTTPService> httpService;
216 if (data.readInt32()) {
217 httpService =
218 interface_cast<IMediaHTTPService>(data.readStrongBinder());
219 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800220 const char* url = data.readCString();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700221 sp<IMemoryHeap> heap = interface_cast<IMemoryHeap>(data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800222 uint32_t sampleRate;
223 int numChannels;
Glenn Kastene1c39622012-01-04 09:36:37 -0800224 audio_format_t format;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700225 size_t size;
Andreas Huber1b86fe02014-01-29 11:13:26 -0800226 status_t status =
227 decode(httpService,
228 url,
229 &sampleRate,
230 &numChannels,
231 &format,
232 heap,
233 &size);
Eric Laurent3d00aa62013-09-24 09:53:27 -0700234 reply->writeInt32(status);
235 if (status == NO_ERROR) {
236 reply->writeInt32(sampleRate);
237 reply->writeInt32(numChannels);
238 reply->writeInt32((int32_t)format);
239 reply->writeInt32((int32_t)size);
240 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800241 return NO_ERROR;
242 } break;
243 case DECODE_FD: {
244 CHECK_INTERFACE(IMediaPlayerService, data, reply);
245 int fd = dup(data.readFileDescriptor());
246 int64_t offset = data.readInt64();
247 int64_t length = data.readInt64();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700248 sp<IMemoryHeap> heap = interface_cast<IMemoryHeap>(data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800249 uint32_t sampleRate;
250 int numChannels;
Glenn Kastene1c39622012-01-04 09:36:37 -0800251 audio_format_t format;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700252 size_t size;
253 status_t status = decode(fd, offset, length, &sampleRate, &numChannels, &format,
254 heap, &size);
255 reply->writeInt32(status);
256 if (status == NO_ERROR) {
257 reply->writeInt32(sampleRate);
258 reply->writeInt32(numChannels);
259 reply->writeInt32((int32_t)format);
260 reply->writeInt32((int32_t)size);
261 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800262 return NO_ERROR;
263 } break;
264 case CREATE_MEDIA_RECORDER: {
265 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800266 sp<IMediaRecorder> recorder = createMediaRecorder();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800267 reply->writeStrongBinder(recorder->asBinder());
268 return NO_ERROR;
269 } break;
270 case CREATE_METADATA_RETRIEVER: {
271 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800272 sp<IMediaMetadataRetriever> retriever = createMetadataRetriever();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800273 reply->writeStrongBinder(retriever->asBinder());
274 return NO_ERROR;
275 } break;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700276 case GET_OMX: {
Andreas Huber20111aa2009-07-14 16:56:47 -0700277 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber318ad9c2009-10-15 13:46:54 -0700278 sp<IOMX> omx = getOMX();
Andreas Huber20111aa2009-07-14 16:56:47 -0700279 reply->writeStrongBinder(omx->asBinder());
280 return NO_ERROR;
281 } break;
Andreas Hubered3e3e02012-03-26 11:13:27 -0700282 case MAKE_CRYPTO: {
283 CHECK_INTERFACE(IMediaPlayerService, data, reply);
284 sp<ICrypto> crypto = makeCrypto();
285 reply->writeStrongBinder(crypto->asBinder());
286 return NO_ERROR;
287 } break;
Jeff Tinkercc82dc62013-02-08 10:18:35 -0800288 case MAKE_DRM: {
289 CHECK_INTERFACE(IMediaPlayerService, data, reply);
290 sp<IDrm> drm = makeDrm();
291 reply->writeStrongBinder(drm->asBinder());
292 return NO_ERROR;
293 } break;
Andreas Huber59451f82012-09-18 10:36:32 -0700294 case MAKE_HDCP: {
295 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber279dcd82013-01-30 10:41:25 -0800296 bool createEncryptionModule = data.readInt32();
297 sp<IHDCP> hdcp = makeHDCP(createEncryptionModule);
Andreas Huber59451f82012-09-18 10:36:32 -0700298 reply->writeStrongBinder(hdcp->asBinder());
299 return NO_ERROR;
300 } break;
Gloria Wang7cf180c2011-02-19 18:37:57 -0800301 case ADD_BATTERY_DATA: {
302 CHECK_INTERFACE(IMediaPlayerService, data, reply);
303 uint32_t params = data.readInt32();
304 addBatteryData(params);
305 return NO_ERROR;
306 } break;
307 case PULL_BATTERY_DATA: {
308 CHECK_INTERFACE(IMediaPlayerService, data, reply);
309 pullBatteryData(reply);
310 return NO_ERROR;
311 } break;
Jeff Brown2013a542012-09-04 21:38:42 -0700312 case LISTEN_FOR_REMOTE_DISPLAY: {
313 CHECK_INTERFACE(IMediaPlayerService, data, reply);
314 sp<IRemoteDisplayClient> client(
315 interface_cast<IRemoteDisplayClient>(data.readStrongBinder()));
316 String8 iface(data.readString8());
317 sp<IRemoteDisplay> display(listenForRemoteDisplay(client, iface));
318 reply->writeStrongBinder(display->asBinder());
319 return NO_ERROR;
320 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800321 default:
322 return BBinder::onTransact(code, data, reply, flags);
323 }
324}
325
326// ----------------------------------------------------------------------------
327
328}; // namespace android