blob: 11005c6cdfc3335e2af24584c199ca4af943144e [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>
Marco Nelissen5dcf85a2018-10-11 09:49:02 -070026#include <media/IMediaPlayer.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080027#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 CREATE_MEDIA_RECORDER,
41 CREATE_METADATA_RETRIEVER,
Gloria Wang7cf180c2011-02-19 18:37:57 -080042 ADD_BATTERY_DATA,
Jeff Brown2013a542012-09-04 21:38:42 -070043 PULL_BATTERY_DATA,
44 LISTEN_FOR_REMOTE_DISPLAY,
Lajos Molnar1381d4b2014-08-07 15:18:35 -070045 GET_CODEC_LIST,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080046};
47
48class BpMediaPlayerService: public BpInterface<IMediaPlayerService>
49{
50public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070051 explicit BpMediaPlayerService(const sp<IBinder>& impl)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080052 : BpInterface<IMediaPlayerService>(impl)
53 {
54 }
55
Glenn Kastenf37971f2012-02-03 11:06:53 -080056 virtual sp<IMediaMetadataRetriever> createMetadataRetriever()
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080057 {
58 Parcel data, reply;
59 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080060 remote()->transact(CREATE_METADATA_RETRIEVER, data, &reply);
61 return interface_cast<IMediaMetadataRetriever>(reply.readStrongBinder());
62 }
63
Andreas Huber2db84552010-01-28 11:19:57 -080064 virtual sp<IMediaPlayer> create(
Colin Crossb8a9dbb2020-08-27 04:12:26 +000065 const sp<IMediaPlayerClient>& client, audio_session_t audioSessionId,
66 const std::string opPackageName) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080067 Parcel data, reply;
68 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -080069 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurenta514bdb2010-06-21 09:27:30 -070070 data.writeInt32(audioSessionId);
Colin Crossb8a9dbb2020-08-27 04:12:26 +000071 data.writeCString(opPackageName.c_str());
Andreas Huber2db84552010-01-28 11:19:57 -080072
Dave Burked681bbb2011-08-30 14:39:17 +010073 remote()->transact(CREATE, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080074 return interface_cast<IMediaPlayer>(reply.readStrongBinder());
75 }
76
Svet Ganovbe71aa22015-04-28 12:06:02 -070077 virtual sp<IMediaRecorder> createMediaRecorder(const String16 &opPackageName)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080078 {
79 Parcel data, reply;
80 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Svet Ganovbe71aa22015-04-28 12:06:02 -070081 data.writeString16(opPackageName);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080082 remote()->transact(CREATE_MEDIA_RECORDER, data, &reply);
83 return interface_cast<IMediaRecorder>(reply.readStrongBinder());
84 }
85
Gloria Wang7cf180c2011-02-19 18:37:57 -080086 virtual void addBatteryData(uint32_t params) {
87 Parcel data, reply;
88 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
89 data.writeInt32(params);
90 remote()->transact(ADD_BATTERY_DATA, data, &reply);
91 }
92
93 virtual status_t pullBatteryData(Parcel* reply) {
94 Parcel data;
95 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
96 return remote()->transact(PULL_BATTERY_DATA, data, reply);
97 }
Jeff Brown2013a542012-09-04 21:38:42 -070098
Svet Ganovbe71aa22015-04-28 12:06:02 -070099 virtual sp<IRemoteDisplay> listenForRemoteDisplay(const String16 &opPackageName,
100 const sp<IRemoteDisplayClient>& client, const String8& iface)
Jeff Brown2013a542012-09-04 21:38:42 -0700101 {
102 Parcel data, reply;
103 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
Svet Ganovbe71aa22015-04-28 12:06:02 -0700104 data.writeString16(opPackageName);
Marco Nelissenf8880202014-11-14 07:58:25 -0800105 data.writeStrongBinder(IInterface::asBinder(client));
Jeff Brown2013a542012-09-04 21:38:42 -0700106 data.writeString8(iface);
107 remote()->transact(LISTEN_FOR_REMOTE_DISPLAY, data, &reply);
108 return interface_cast<IRemoteDisplay>(reply.readStrongBinder());
109 }
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700110
111 virtual sp<IMediaCodecList> getCodecList() const {
112 Parcel data, reply;
113 data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
114 remote()->transact(GET_CODEC_LIST, data, &reply);
115 return interface_cast<IMediaCodecList>(reply.readStrongBinder());
116 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800117};
118
niko56f0cc52009-06-22 08:49:52 -0700119IMPLEMENT_META_INTERFACE(MediaPlayerService, "android.media.IMediaPlayerService");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800120
121// ----------------------------------------------------------------------
122
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800123status_t BnMediaPlayerService::onTransact(
124 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
125{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700126 switch (code) {
Dave Burked681bbb2011-08-30 14:39:17 +0100127 case CREATE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800128 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Andreas Huber2db84552010-01-28 11:19:57 -0800129 sp<IMediaPlayerClient> client =
130 interface_cast<IMediaPlayerClient>(data.readStrongBinder());
Glenn Kastend848eb42016-03-08 13:42:11 -0800131 audio_session_t audioSessionId = (audio_session_t) data.readInt32();
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000132 const char* opPackageName = data.readCString();
133 if (opPackageName == nullptr) {
134 return FAILED_TRANSACTION;
135 }
136 std::string opPackageNameStr(opPackageName);
137 sp<IMediaPlayer> player = create(client, audioSessionId, opPackageNameStr);
Marco Nelissenf8880202014-11-14 07:58:25 -0800138 reply->writeStrongBinder(IInterface::asBinder(player));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800139 return NO_ERROR;
140 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800141 case CREATE_MEDIA_RECORDER: {
142 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700143 const String16 opPackageName = data.readString16();
144 sp<IMediaRecorder> recorder = createMediaRecorder(opPackageName);
Marco Nelissenf8880202014-11-14 07:58:25 -0800145 reply->writeStrongBinder(IInterface::asBinder(recorder));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800146 return NO_ERROR;
147 } break;
148 case CREATE_METADATA_RETRIEVER: {
149 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Glenn Kastenf37971f2012-02-03 11:06:53 -0800150 sp<IMediaMetadataRetriever> retriever = createMetadataRetriever();
Marco Nelissenf8880202014-11-14 07:58:25 -0800151 reply->writeStrongBinder(IInterface::asBinder(retriever));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800152 return NO_ERROR;
153 } break;
Gloria Wang7cf180c2011-02-19 18:37:57 -0800154 case ADD_BATTERY_DATA: {
155 CHECK_INTERFACE(IMediaPlayerService, data, reply);
156 uint32_t params = data.readInt32();
157 addBatteryData(params);
158 return NO_ERROR;
159 } break;
160 case PULL_BATTERY_DATA: {
161 CHECK_INTERFACE(IMediaPlayerService, data, reply);
162 pullBatteryData(reply);
163 return NO_ERROR;
164 } break;
Jeff Brown2013a542012-09-04 21:38:42 -0700165 case LISTEN_FOR_REMOTE_DISPLAY: {
166 CHECK_INTERFACE(IMediaPlayerService, data, reply);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700167 const String16 opPackageName = data.readString16();
Jeff Brown2013a542012-09-04 21:38:42 -0700168 sp<IRemoteDisplayClient> client(
169 interface_cast<IRemoteDisplayClient>(data.readStrongBinder()));
Wei Jia2afac0c2016-01-07 12:13:07 -0800170 if (client == NULL) {
171 reply->writeStrongBinder(NULL);
172 return NO_ERROR;
173 }
Jeff Brown2013a542012-09-04 21:38:42 -0700174 String8 iface(data.readString8());
Svet Ganovbe71aa22015-04-28 12:06:02 -0700175 sp<IRemoteDisplay> display(listenForRemoteDisplay(opPackageName, client, iface));
Marco Nelissenf8880202014-11-14 07:58:25 -0800176 reply->writeStrongBinder(IInterface::asBinder(display));
Jeff Brown2013a542012-09-04 21:38:42 -0700177 return NO_ERROR;
178 } break;
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700179 case GET_CODEC_LIST: {
180 CHECK_INTERFACE(IMediaPlayerService, data, reply);
181 sp<IMediaCodecList> mcl = getCodecList();
Marco Nelissenf8880202014-11-14 07:58:25 -0800182 reply->writeStrongBinder(IInterface::asBinder(mcl));
Lajos Molnar1381d4b2014-08-07 15:18:35 -0700183 return NO_ERROR;
184 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800185 default:
186 return BBinder::onTransact(code, data, reply, flags);
187 }
188}
189
190// ----------------------------------------------------------------------------
191
Glenn Kasten40bc9062015-03-20 09:09:33 -0700192} // namespace android