blob: feea26729b442ca8ab9be6fd07b5f3f1243aa623 [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 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,
Lajos Molnar1381d4b2014-08-07 15:18:35 -070051 GET_CODEC_LIST,
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());
Marco Nelissenf8880202014-11-14 07:58:25 -080074 data.writeStrongBinder(IInterface::asBinder(client));
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 Huber318ad9c2009-10-15 13:46:54 -070089 virtual sp<IOMX> getOMX() {
Andreas Huber20111aa2009-07-14 16:56:47 -070090 Parcel data, reply;
91 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber318ad9c2009-10-15 13:46:54 -070092 remote()->transact(GET_OMX, data, &reply);
Andreas Huber20111aa2009-07-14 16:56:47 -070093 return interface_cast<IOMX>(reply.readStrongBinder());
94 }
Gloria Wang7cf180c2011-02-19 18:37:57 -080095
Andreas Hubered3e3e02012-03-26 11:13:27 -070096 virtual sp<ICrypto> makeCrypto() {
97 Parcel data, reply;
98 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
99 remote()->transact(MAKE_CRYPTO, data, &reply);
100 return interface_cast<ICrypto>(reply.readStrongBinder());
101 }
102
Jeff Tinkercc82dc62013-02-08 10:18:35 -0800103 virtual sp<IDrm> makeDrm() {
104 Parcel data, reply;
105 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
106 remote()->transact(MAKE_DRM, data, &reply);
107 return interface_cast<IDrm>(reply.readStrongBinder());
108 }
109
Andreas Huber279dcd82013-01-30 10:41:25 -0800110 virtual sp<IHDCP> makeHDCP(bool createEncryptionModule) {
Andreas Huber59451f82012-09-18 10:36:32 -0700111 Parcel data, reply;
112 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Andreas Huber279dcd82013-01-30 10:41:25 -0800113 data.writeInt32(createEncryptionModule);
Andreas Huber59451f82012-09-18 10:36:32 -0700114 remote()->transact(MAKE_HDCP, data, &reply);
115 return interface_cast<IHDCP>(reply.readStrongBinder());
116 }
117
Gloria Wang7cf180c2011-02-19 18:37:57 -0800118 virtual void addBatteryData(uint32_t params) {
119 Parcel data, reply;
120 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
121 data.writeInt32(params);
122 remote()->transact(ADD_BATTERY_DATA, data, &reply);
123 }
124
125 virtual status_t pullBatteryData(Parcel* reply) {
126 Parcel data;
127 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
128 return remote()->transact(PULL_BATTERY_DATA, data, reply);
129 }
Jeff Brown2013a542012-09-04 21:38:42 -0700130
131 virtual sp<IRemoteDisplay> listenForRemoteDisplay(const sp<IRemoteDisplayClient>& client,
132 const String8& iface)
133 {
134 Parcel data, reply;
135 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800136 data.writeStrongBinder(IInterface::asBinder(client));
Jeff Brown2013a542012-09-04 21:38:42 -0700137 data.writeString8(iface);
138 remote()->transact(LISTEN_FOR_REMOTE_DISPLAY, data, &reply);
139 return interface_cast<IRemoteDisplay>(reply.readStrongBinder());
140 }
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700141
142 virtual sp<IMediaCodecList> getCodecList() const {
143 Parcel data, reply;
144 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
145 remote()->transact(GET_CODEC_LIST, data, &reply);
146 return interface_cast<IMediaCodecList>(reply.readStrongBinder());
147 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800148};
149
niko56f0cc52009-06-22 08:49:52 -0700150IMPLEMENT_META_INTERFACE(MediaPlayerService, "android.media.IMediaPlayerService");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800151
152// ----------------------------------------------------------------------
153
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800154status_t BnMediaPlayerService::onTransact(
155 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
156{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700157 switch (code) {
Dave Burked681bbb2011-08-30 14:39:17 +0100158 case CREATE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800159 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber2db84552010-01-28 11:19:57 -0800160 sp<IMediaPlayerClient> client =
161 interface_cast<IMediaPlayerClient>(data.readStrongBinder());
Eric Laurenta514bdb2010-06-21 09:27:30 -0700162 int audioSessionId = data.readInt32();
Glenn Kastenf37971f2012-02-03 11:06:53 -0800163 sp<IMediaPlayer> player = create(client, audioSessionId);
Marco Nelissenf8880202014-11-14 07:58:25 -0800164 reply->writeStrongBinder(IInterface::asBinder(player));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800165 return NO_ERROR;
166 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800167 case CREATE_MEDIA_RECORDER: {
168 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800169 sp<IMediaRecorder> recorder = createMediaRecorder();
Marco Nelissenf8880202014-11-14 07:58:25 -0800170 reply->writeStrongBinder(IInterface::asBinder(recorder));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800171 return NO_ERROR;
172 } break;
173 case CREATE_METADATA_RETRIEVER: {
174 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800175 sp<IMediaMetadataRetriever> retriever = createMetadataRetriever();
Marco Nelissenf8880202014-11-14 07:58:25 -0800176 reply->writeStrongBinder(IInterface::asBinder(retriever));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800177 return NO_ERROR;
178 } break;
Andreas Huber318ad9c2009-10-15 13:46:54 -0700179 case GET_OMX: {
Andreas Huber20111aa2009-07-14 16:56:47 -0700180 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber318ad9c2009-10-15 13:46:54 -0700181 sp<IOMX> omx = getOMX();
Marco Nelissenf8880202014-11-14 07:58:25 -0800182 reply->writeStrongBinder(IInterface::asBinder(omx));
Andreas Huber20111aa2009-07-14 16:56:47 -0700183 return NO_ERROR;
184 } break;
Andreas Hubered3e3e02012-03-26 11:13:27 -0700185 case MAKE_CRYPTO: {
186 CHECK_INTERFACE(IMediaPlayerService, data, reply);
187 sp<ICrypto> crypto = makeCrypto();
Marco Nelissenf8880202014-11-14 07:58:25 -0800188 reply->writeStrongBinder(IInterface::asBinder(crypto));
Andreas Hubered3e3e02012-03-26 11:13:27 -0700189 return NO_ERROR;
190 } break;
Jeff Tinkercc82dc62013-02-08 10:18:35 -0800191 case MAKE_DRM: {
192 CHECK_INTERFACE(IMediaPlayerService, data, reply);
193 sp<IDrm> drm = makeDrm();
Marco Nelissenf8880202014-11-14 07:58:25 -0800194 reply->writeStrongBinder(IInterface::asBinder(drm));
Jeff Tinkercc82dc62013-02-08 10:18:35 -0800195 return NO_ERROR;
196 } break;
Andreas Huber59451f82012-09-18 10:36:32 -0700197 case MAKE_HDCP: {
198 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber279dcd82013-01-30 10:41:25 -0800199 bool createEncryptionModule = data.readInt32();
200 sp<IHDCP> hdcp = makeHDCP(createEncryptionModule);
Marco Nelissenf8880202014-11-14 07:58:25 -0800201 reply->writeStrongBinder(IInterface::asBinder(hdcp));
Andreas Huber59451f82012-09-18 10:36:32 -0700202 return NO_ERROR;
203 } break;
Gloria Wang7cf180c2011-02-19 18:37:57 -0800204 case ADD_BATTERY_DATA: {
205 CHECK_INTERFACE(IMediaPlayerService, data, reply);
206 uint32_t params = data.readInt32();
207 addBatteryData(params);
208 return NO_ERROR;
209 } break;
210 case PULL_BATTERY_DATA: {
211 CHECK_INTERFACE(IMediaPlayerService, data, reply);
212 pullBatteryData(reply);
213 return NO_ERROR;
214 } break;
Jeff Brown2013a542012-09-04 21:38:42 -0700215 case LISTEN_FOR_REMOTE_DISPLAY: {
216 CHECK_INTERFACE(IMediaPlayerService, data, reply);
217 sp<IRemoteDisplayClient> client(
218 interface_cast<IRemoteDisplayClient>(data.readStrongBinder()));
219 String8 iface(data.readString8());
220 sp<IRemoteDisplay> display(listenForRemoteDisplay(client, iface));
Marco Nelissenf8880202014-11-14 07:58:25 -0800221 reply->writeStrongBinder(IInterface::asBinder(display));
Jeff Brown2013a542012-09-04 21:38:42 -0700222 return NO_ERROR;
223 } break;
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700224 case GET_CODEC_LIST: {
225 CHECK_INTERFACE(IMediaPlayerService, data, reply);
226 sp<IMediaCodecList> mcl = getCodecList();
Marco Nelissenf8880202014-11-14 07:58:25 -0800227 reply->writeStrongBinder(IInterface::asBinder(mcl));
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700228 return NO_ERROR;
229 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800230 default:
231 return BBinder::onTransact(code, data, reply, flags);
232 }
233}
234
235// ----------------------------------------------------------------------------
236
237}; // namespace android