blob: aca7ad99794a5706e63f52834eb53198ccb5f04e [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>
Lajos Molnar1381d4b2014-08-07 15:18:35 -070023#include <media/IMediaCodecList.h>
Andreas Huber1b86fe02014-01-29 11:13:26 -080024#include <media/IMediaHTTPService.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080025#include <media/IMediaPlayerService.h>
26#include <media/IMediaRecorder.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070027#include <media/IOMX.h>
Jeff Brown2013a542012-09-04 21:38:42 -070028#include <media/IRemoteDisplay.h>
29#include <media/IRemoteDisplayClient.h>
Andreas Hubere2b10282010-11-23 11:41:34 -080030#include <media/IStreamSource.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070031
32#include <utils/Errors.h> // for status_t
Jeff Brown2013a542012-09-04 21:38:42 -070033#include <utils/String8.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080034
35namespace android {
36
37enum {
Dave Burked681bbb2011-08-30 14:39:17 +010038 CREATE = IBinder::FIRST_CALL_TRANSACTION,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080039 CREATE_MEDIA_RECORDER,
40 CREATE_METADATA_RETRIEVER,
Gloria Wang7cf180c2011-02-19 18:37:57 -080041 ADD_BATTERY_DATA,
Jeff Brown2013a542012-09-04 21:38:42 -070042 PULL_BATTERY_DATA,
43 LISTEN_FOR_REMOTE_DISPLAY,
Lajos Molnar1381d4b2014-08-07 15:18:35 -070044 GET_CODEC_LIST,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080045};
46
47class BpMediaPlayerService: public BpInterface<IMediaPlayerService>
48{
49public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070050 explicit BpMediaPlayerService(const sp<IBinder>& impl)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080051 : BpInterface<IMediaPlayerService>(impl)
52 {
53 }
54
Glenn Kastenf37971f2012-02-03 11:06:53 -080055 virtual sp<IMediaMetadataRetriever> createMetadataRetriever()
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080056 {
57 Parcel data, reply;
58 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080059 remote()->transact(CREATE_METADATA_RETRIEVER, data, &reply);
60 return interface_cast<IMediaMetadataRetriever>(reply.readStrongBinder());
61 }
62
Andreas Huber2db84552010-01-28 11:19:57 -080063 virtual sp<IMediaPlayer> create(
Glenn Kastend848eb42016-03-08 13:42:11 -080064 const sp<IMediaPlayerClient>& client, audio_session_t audioSessionId) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080065 Parcel data, reply;
66 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -080067 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurenta514bdb2010-06-21 09:27:30 -070068 data.writeInt32(audioSessionId);
Andreas Huber2db84552010-01-28 11:19:57 -080069
Dave Burked681bbb2011-08-30 14:39:17 +010070 remote()->transact(CREATE, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080071 return interface_cast<IMediaPlayer>(reply.readStrongBinder());
72 }
73
Svet Ganovbe71aa22015-04-28 12:06:02 -070074 virtual sp<IMediaRecorder> createMediaRecorder(const String16 &opPackageName)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080075 {
76 Parcel data, reply;
77 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Svet Ganovbe71aa22015-04-28 12:06:02 -070078 data.writeString16(opPackageName);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080079 remote()->transact(CREATE_MEDIA_RECORDER, data, &reply);
80 return interface_cast<IMediaRecorder>(reply.readStrongBinder());
81 }
82
Gloria Wang7cf180c2011-02-19 18:37:57 -080083 virtual void addBatteryData(uint32_t params) {
84 Parcel data, reply;
85 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
86 data.writeInt32(params);
87 remote()->transact(ADD_BATTERY_DATA, data, &reply);
88 }
89
90 virtual status_t pullBatteryData(Parcel* reply) {
91 Parcel data;
92 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
93 return remote()->transact(PULL_BATTERY_DATA, data, reply);
94 }
Jeff Brown2013a542012-09-04 21:38:42 -070095
Svet Ganovbe71aa22015-04-28 12:06:02 -070096 virtual sp<IRemoteDisplay> listenForRemoteDisplay(const String16 &opPackageName,
97 const sp<IRemoteDisplayClient>& client, const String8& iface)
Jeff Brown2013a542012-09-04 21:38:42 -070098 {
99 Parcel data, reply;
100 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Svet Ganovbe71aa22015-04-28 12:06:02 -0700101 data.writeString16(opPackageName);
Marco Nelissenf8880202014-11-14 07:58:25 -0800102 data.writeStrongBinder(IInterface::asBinder(client));
Jeff Brown2013a542012-09-04 21:38:42 -0700103 data.writeString8(iface);
104 remote()->transact(LISTEN_FOR_REMOTE_DISPLAY, data, &reply);
105 return interface_cast<IRemoteDisplay>(reply.readStrongBinder());
106 }
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700107
108 virtual sp<IMediaCodecList> getCodecList() const {
109 Parcel data, reply;
110 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
111 remote()->transact(GET_CODEC_LIST, data, &reply);
112 return interface_cast<IMediaCodecList>(reply.readStrongBinder());
113 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800114};
115
niko56f0cc52009-06-22 08:49:52 -0700116IMPLEMENT_META_INTERFACE(MediaPlayerService, "android.media.IMediaPlayerService");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800117
118// ----------------------------------------------------------------------
119
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800120status_t BnMediaPlayerService::onTransact(
121 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
122{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700123 switch (code) {
Dave Burked681bbb2011-08-30 14:39:17 +0100124 case CREATE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800125 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber2db84552010-01-28 11:19:57 -0800126 sp<IMediaPlayerClient> client =
127 interface_cast<IMediaPlayerClient>(data.readStrongBinder());
Glenn Kastend848eb42016-03-08 13:42:11 -0800128 audio_session_t audioSessionId = (audio_session_t) data.readInt32();
Glenn Kastenf37971f2012-02-03 11:06:53 -0800129 sp<IMediaPlayer> player = create(client, audioSessionId);
Marco Nelissenf8880202014-11-14 07:58:25 -0800130 reply->writeStrongBinder(IInterface::asBinder(player));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800131 return NO_ERROR;
132 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800133 case CREATE_MEDIA_RECORDER: {
134 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700135 const String16 opPackageName = data.readString16();
136 sp<IMediaRecorder> recorder = createMediaRecorder(opPackageName);
Marco Nelissenf8880202014-11-14 07:58:25 -0800137 reply->writeStrongBinder(IInterface::asBinder(recorder));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800138 return NO_ERROR;
139 } break;
140 case CREATE_METADATA_RETRIEVER: {
141 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800142 sp<IMediaMetadataRetriever> retriever = createMetadataRetriever();
Marco Nelissenf8880202014-11-14 07:58:25 -0800143 reply->writeStrongBinder(IInterface::asBinder(retriever));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800144 return NO_ERROR;
145 } break;
Gloria Wang7cf180c2011-02-19 18:37:57 -0800146 case ADD_BATTERY_DATA: {
147 CHECK_INTERFACE(IMediaPlayerService, data, reply);
148 uint32_t params = data.readInt32();
149 addBatteryData(params);
150 return NO_ERROR;
151 } break;
152 case PULL_BATTERY_DATA: {
153 CHECK_INTERFACE(IMediaPlayerService, data, reply);
154 pullBatteryData(reply);
155 return NO_ERROR;
156 } break;
Jeff Brown2013a542012-09-04 21:38:42 -0700157 case LISTEN_FOR_REMOTE_DISPLAY: {
158 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700159 const String16 opPackageName = data.readString16();
Jeff Brown2013a542012-09-04 21:38:42 -0700160 sp<IRemoteDisplayClient> client(
161 interface_cast<IRemoteDisplayClient>(data.readStrongBinder()));
Wei Jia2afac0c2016-01-07 12:13:07 -0800162 if (client == NULL) {
163 reply->writeStrongBinder(NULL);
164 return NO_ERROR;
165 }
Jeff Brown2013a542012-09-04 21:38:42 -0700166 String8 iface(data.readString8());
Svet Ganovbe71aa22015-04-28 12:06:02 -0700167 sp<IRemoteDisplay> display(listenForRemoteDisplay(opPackageName, client, iface));
Marco Nelissenf8880202014-11-14 07:58:25 -0800168 reply->writeStrongBinder(IInterface::asBinder(display));
Jeff Brown2013a542012-09-04 21:38:42 -0700169 return NO_ERROR;
170 } break;
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700171 case GET_CODEC_LIST: {
172 CHECK_INTERFACE(IMediaPlayerService, data, reply);
173 sp<IMediaCodecList> mcl = getCodecList();
Marco Nelissenf8880202014-11-14 07:58:25 -0800174 reply->writeStrongBinder(IInterface::asBinder(mcl));
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700175 return NO_ERROR;
176 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800177 default:
178 return BBinder::onTransact(code, data, reply, flags);
179 }
180}
181
182// ----------------------------------------------------------------------------
183
Glenn Kasten40bc9062015-03-20 09:09:33 -0700184} // namespace android