blob: 74f574dc332e4697437b3653a06cd1b33986dfe2 [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>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080026#include <media/IMediaPlayerService.h>
27#include <media/IMediaRecorder.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070028#include <media/IOMX.h>
Jeff Brown2013a542012-09-04 21:38:42 -070029#include <media/IRemoteDisplay.h>
30#include <media/IRemoteDisplayClient.h>
Andreas Hubere2b10282010-11-23 11:41:34 -080031#include <media/IStreamSource.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070032
33#include <utils/Errors.h> // for status_t
Jeff Brown2013a542012-09-04 21:38:42 -070034#include <utils/String8.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080035
36namespace android {
37
38enum {
Dave Burked681bbb2011-08-30 14:39:17 +010039 CREATE = IBinder::FIRST_CALL_TRANSACTION,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080040 DECODE_URL,
41 DECODE_FD,
42 CREATE_MEDIA_RECORDER,
43 CREATE_METADATA_RETRIEVER,
Gloria Wang7cf180c2011-02-19 18:37:57 -080044 GET_OMX,
Andreas Hubered3e3e02012-03-26 11:13:27 -070045 MAKE_CRYPTO,
Jeff Tinkercc82dc62013-02-08 10:18:35 -080046 MAKE_DRM,
Andreas Huber59451f82012-09-18 10:36:32 -070047 MAKE_HDCP,
Gloria Wang7cf180c2011-02-19 18:37:57 -080048 ADD_BATTERY_DATA,
Jeff Brown2013a542012-09-04 21:38:42 -070049 PULL_BATTERY_DATA,
50 LISTEN_FOR_REMOTE_DISPLAY,
Andreas Huberb7319a72013-05-29 14:20:52 -070051 UPDATE_PROXY_CONFIG,
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
Glenn Kastene1c39622012-01-04 09:36:37 -080089 virtual sp<IMemory> decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, audio_format_t* pFormat)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080090 {
91 Parcel data, reply;
92 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
93 data.writeCString(url);
94 remote()->transact(DECODE_URL, data, &reply);
95 *pSampleRate = uint32_t(reply.readInt32());
96 *pNumChannels = reply.readInt32();
Glenn Kastene1c39622012-01-04 09:36:37 -080097 *pFormat = (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080098 return interface_cast<IMemory>(reply.readStrongBinder());
99 }
100
Glenn Kastene1c39622012-01-04 09:36:37 -0800101 virtual sp<IMemory> decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, audio_format_t* pFormat)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800102 {
103 Parcel data, reply;
104 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
105 data.writeFileDescriptor(fd);
106 data.writeInt64(offset);
107 data.writeInt64(length);
108 remote()->transact(DECODE_FD, data, &reply);
109 *pSampleRate = uint32_t(reply.readInt32());
110 *pNumChannels = reply.readInt32();
Glenn Kastene1c39622012-01-04 09:36:37 -0800111 *pFormat = (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800112 return interface_cast<IMemory>(reply.readStrongBinder());
113 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700114
Andreas Huber318ad9c2009-10-15 13:46:54 -0700115 virtual sp<IOMX> getOMX() {
Andreas Huber20111aa2009-07-14 16:56:47 -0700116 Parcel data, reply;
117 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber318ad9c2009-10-15 13:46:54 -0700118 remote()->transact(GET_OMX, data, &reply);
Andreas Huber20111aa2009-07-14 16:56:47 -0700119 return interface_cast<IOMX>(reply.readStrongBinder());
120 }
Gloria Wang7cf180c2011-02-19 18:37:57 -0800121
Andreas Hubered3e3e02012-03-26 11:13:27 -0700122 virtual sp<ICrypto> makeCrypto() {
123 Parcel data, reply;
124 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
125 remote()->transact(MAKE_CRYPTO, data, &reply);
126 return interface_cast<ICrypto>(reply.readStrongBinder());
127 }
128
Jeff Tinkercc82dc62013-02-08 10:18:35 -0800129 virtual sp<IDrm> makeDrm() {
130 Parcel data, reply;
131 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
132 remote()->transact(MAKE_DRM, data, &reply);
133 return interface_cast<IDrm>(reply.readStrongBinder());
134 }
135
Andreas Huber279dcd82013-01-30 10:41:25 -0800136 virtual sp<IHDCP> makeHDCP(bool createEncryptionModule) {
Andreas Huber59451f82012-09-18 10:36:32 -0700137 Parcel data, reply;
138 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber279dcd82013-01-30 10:41:25 -0800139 data.writeInt32(createEncryptionModule);
Andreas Huber59451f82012-09-18 10:36:32 -0700140 remote()->transact(MAKE_HDCP, data, &reply);
141 return interface_cast<IHDCP>(reply.readStrongBinder());
142 }
143
Gloria Wang7cf180c2011-02-19 18:37:57 -0800144 virtual void addBatteryData(uint32_t params) {
145 Parcel data, reply;
146 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
147 data.writeInt32(params);
148 remote()->transact(ADD_BATTERY_DATA, data, &reply);
149 }
150
151 virtual status_t pullBatteryData(Parcel* reply) {
152 Parcel data;
153 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
154 return remote()->transact(PULL_BATTERY_DATA, data, reply);
155 }
Jeff Brown2013a542012-09-04 21:38:42 -0700156
157 virtual sp<IRemoteDisplay> listenForRemoteDisplay(const sp<IRemoteDisplayClient>& client,
158 const String8& iface)
159 {
160 Parcel data, reply;
161 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
162 data.writeStrongBinder(client->asBinder());
163 data.writeString8(iface);
164 remote()->transact(LISTEN_FOR_REMOTE_DISPLAY, data, &reply);
165 return interface_cast<IRemoteDisplay>(reply.readStrongBinder());
166 }
Andreas Huberb7319a72013-05-29 14:20:52 -0700167
168 virtual status_t updateProxyConfig(
169 const char *host, int32_t port, const char *exclusionList) {
170 Parcel data, reply;
171
172 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
173 if (host == NULL) {
174 data.writeInt32(0);
175 } else {
176 data.writeInt32(1);
177 data.writeCString(host);
178 data.writeInt32(port);
179 data.writeCString(exclusionList);
180 }
181
182 remote()->transact(UPDATE_PROXY_CONFIG, data, &reply);
183
184 return reply.readInt32();
185 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800186};
187
niko56f0cc52009-06-22 08:49:52 -0700188IMPLEMENT_META_INTERFACE(MediaPlayerService, "android.media.IMediaPlayerService");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800189
190// ----------------------------------------------------------------------
191
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800192status_t BnMediaPlayerService::onTransact(
193 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
194{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700195 switch (code) {
Dave Burked681bbb2011-08-30 14:39:17 +0100196 case CREATE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800197 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber2db84552010-01-28 11:19:57 -0800198 sp<IMediaPlayerClient> client =
199 interface_cast<IMediaPlayerClient>(data.readStrongBinder());
Eric Laurenta514bdb2010-06-21 09:27:30 -0700200 int audioSessionId = data.readInt32();
Glenn Kastenf37971f2012-02-03 11:06:53 -0800201 sp<IMediaPlayer> player = create(client, audioSessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800202 reply->writeStrongBinder(player->asBinder());
203 return NO_ERROR;
204 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800205 case DECODE_URL: {
206 CHECK_INTERFACE(IMediaPlayerService, data, reply);
207 const char* url = data.readCString();
208 uint32_t sampleRate;
209 int numChannels;
Glenn Kastene1c39622012-01-04 09:36:37 -0800210 audio_format_t format;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800211 sp<IMemory> player = decode(url, &sampleRate, &numChannels, &format);
212 reply->writeInt32(sampleRate);
213 reply->writeInt32(numChannels);
Glenn Kastene1c39622012-01-04 09:36:37 -0800214 reply->writeInt32((int32_t) format);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800215 reply->writeStrongBinder(player->asBinder());
216 return NO_ERROR;
217 } break;
218 case DECODE_FD: {
219 CHECK_INTERFACE(IMediaPlayerService, data, reply);
220 int fd = dup(data.readFileDescriptor());
221 int64_t offset = data.readInt64();
222 int64_t length = data.readInt64();
223 uint32_t sampleRate;
224 int numChannels;
Glenn Kastene1c39622012-01-04 09:36:37 -0800225 audio_format_t format;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800226 sp<IMemory> player = decode(fd, offset, length, &sampleRate, &numChannels, &format);
227 reply->writeInt32(sampleRate);
228 reply->writeInt32(numChannels);
Glenn Kastene1c39622012-01-04 09:36:37 -0800229 reply->writeInt32((int32_t) format);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800230 reply->writeStrongBinder(player->asBinder());
231 return NO_ERROR;
232 } break;
233 case CREATE_MEDIA_RECORDER: {
234 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800235 sp<IMediaRecorder> recorder = createMediaRecorder();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800236 reply->writeStrongBinder(recorder->asBinder());
237 return NO_ERROR;
238 } break;
239 case CREATE_METADATA_RETRIEVER: {
240 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800241 sp<IMediaMetadataRetriever> retriever = createMetadataRetriever();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800242 reply->writeStrongBinder(retriever->asBinder());
243 return NO_ERROR;
244 } break;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700245 case GET_OMX: {
Andreas Huber20111aa2009-07-14 16:56:47 -0700246 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber318ad9c2009-10-15 13:46:54 -0700247 sp<IOMX> omx = getOMX();
Andreas Huber20111aa2009-07-14 16:56:47 -0700248 reply->writeStrongBinder(omx->asBinder());
249 return NO_ERROR;
250 } break;
Andreas Hubered3e3e02012-03-26 11:13:27 -0700251 case MAKE_CRYPTO: {
252 CHECK_INTERFACE(IMediaPlayerService, data, reply);
253 sp<ICrypto> crypto = makeCrypto();
254 reply->writeStrongBinder(crypto->asBinder());
255 return NO_ERROR;
256 } break;
Jeff Tinkercc82dc62013-02-08 10:18:35 -0800257 case MAKE_DRM: {
258 CHECK_INTERFACE(IMediaPlayerService, data, reply);
259 sp<IDrm> drm = makeDrm();
260 reply->writeStrongBinder(drm->asBinder());
261 return NO_ERROR;
262 } break;
Andreas Huber59451f82012-09-18 10:36:32 -0700263 case MAKE_HDCP: {
264 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber279dcd82013-01-30 10:41:25 -0800265 bool createEncryptionModule = data.readInt32();
266 sp<IHDCP> hdcp = makeHDCP(createEncryptionModule);
Andreas Huber59451f82012-09-18 10:36:32 -0700267 reply->writeStrongBinder(hdcp->asBinder());
268 return NO_ERROR;
269 } break;
Gloria Wang7cf180c2011-02-19 18:37:57 -0800270 case ADD_BATTERY_DATA: {
271 CHECK_INTERFACE(IMediaPlayerService, data, reply);
272 uint32_t params = data.readInt32();
273 addBatteryData(params);
274 return NO_ERROR;
275 } break;
276 case PULL_BATTERY_DATA: {
277 CHECK_INTERFACE(IMediaPlayerService, data, reply);
278 pullBatteryData(reply);
279 return NO_ERROR;
280 } break;
Jeff Brown2013a542012-09-04 21:38:42 -0700281 case LISTEN_FOR_REMOTE_DISPLAY: {
282 CHECK_INTERFACE(IMediaPlayerService, data, reply);
283 sp<IRemoteDisplayClient> client(
284 interface_cast<IRemoteDisplayClient>(data.readStrongBinder()));
285 String8 iface(data.readString8());
286 sp<IRemoteDisplay> display(listenForRemoteDisplay(client, iface));
287 reply->writeStrongBinder(display->asBinder());
288 return NO_ERROR;
289 } break;
Andreas Huberb7319a72013-05-29 14:20:52 -0700290 case UPDATE_PROXY_CONFIG:
291 {
292 CHECK_INTERFACE(IMediaPlayerService, data, reply);
293
294 const char *host = NULL;
295 int32_t port = 0;
296 const char *exclusionList = NULL;
297
298 if (data.readInt32()) {
299 host = data.readCString();
300 port = data.readInt32();
301 exclusionList = data.readCString();
302 }
303
304 reply->writeInt32(updateProxyConfig(host, port, exclusionList));
305
306 return OK;
307 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800308 default:
309 return BBinder::onTransact(code, data, reply, flags);
310 }
311}
312
313// ----------------------------------------------------------------------------
314
315}; // namespace android