The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 21 | #include <binder/Parcel.h> |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 22 | #include <binder/IMemory.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include <media/IMediaPlayerService.h> |
| 24 | #include <media/IMediaRecorder.h> |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 25 | #include <media/IOMX.h> |
Andreas Huber | 52b52cd | 2010-11-23 11:41:34 -0800 | [diff] [blame] | 26 | #include <media/IStreamSource.h> |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 27 | |
| 28 | #include <utils/Errors.h> // for status_t |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | enum { |
Dave Burke | fc301b0 | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 33 | CREATE = IBinder::FIRST_CALL_TRANSACTION, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | DECODE_URL, |
| 35 | DECODE_FD, |
| 36 | CREATE_MEDIA_RECORDER, |
| 37 | CREATE_METADATA_RETRIEVER, |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 38 | GET_OMX, |
| 39 | ADD_BATTERY_DATA, |
| 40 | PULL_BATTERY_DATA |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | class BpMediaPlayerService: public BpInterface<IMediaPlayerService> |
| 44 | { |
| 45 | public: |
| 46 | BpMediaPlayerService(const sp<IBinder>& impl) |
| 47 | : BpInterface<IMediaPlayerService>(impl) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | virtual sp<IMediaMetadataRetriever> createMetadataRetriever(pid_t pid) |
| 52 | { |
| 53 | Parcel data, reply; |
| 54 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
| 55 | data.writeInt32(pid); |
| 56 | remote()->transact(CREATE_METADATA_RETRIEVER, data, &reply); |
| 57 | return interface_cast<IMediaMetadataRetriever>(reply.readStrongBinder()); |
| 58 | } |
| 59 | |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 60 | virtual sp<IMediaPlayer> create( |
Dave Burke | fc301b0 | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 61 | pid_t pid, const sp<IMediaPlayerClient>& client, int audioSessionId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | Parcel data, reply; |
| 63 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
| 64 | data.writeInt32(pid); |
| 65 | data.writeStrongBinder(client->asBinder()); |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 66 | data.writeInt32(audioSessionId); |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 67 | |
Dave Burke | fc301b0 | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 68 | remote()->transact(CREATE, data, &reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | return interface_cast<IMediaPlayer>(reply.readStrongBinder()); |
| 70 | } |
| 71 | |
| 72 | virtual sp<IMediaRecorder> createMediaRecorder(pid_t pid) |
| 73 | { |
| 74 | Parcel data, reply; |
| 75 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
| 76 | data.writeInt32(pid); |
| 77 | remote()->transact(CREATE_MEDIA_RECORDER, data, &reply); |
| 78 | return interface_cast<IMediaRecorder>(reply.readStrongBinder()); |
| 79 | } |
| 80 | |
Glenn Kasten | 1c5a89d | 2012-01-04 09:36:37 -0800 | [diff] [blame] | 81 | virtual sp<IMemory> decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, audio_format_t* pFormat) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | { |
| 83 | Parcel data, reply; |
| 84 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
| 85 | data.writeCString(url); |
| 86 | remote()->transact(DECODE_URL, data, &reply); |
| 87 | *pSampleRate = uint32_t(reply.readInt32()); |
| 88 | *pNumChannels = reply.readInt32(); |
Glenn Kasten | 1c5a89d | 2012-01-04 09:36:37 -0800 | [diff] [blame] | 89 | *pFormat = (audio_format_t) reply.readInt32(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | return interface_cast<IMemory>(reply.readStrongBinder()); |
| 91 | } |
| 92 | |
Glenn Kasten | 1c5a89d | 2012-01-04 09:36:37 -0800 | [diff] [blame] | 93 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | { |
| 95 | Parcel data, reply; |
| 96 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
| 97 | data.writeFileDescriptor(fd); |
| 98 | data.writeInt64(offset); |
| 99 | data.writeInt64(length); |
| 100 | remote()->transact(DECODE_FD, data, &reply); |
| 101 | *pSampleRate = uint32_t(reply.readInt32()); |
| 102 | *pNumChannels = reply.readInt32(); |
Glenn Kasten | 1c5a89d | 2012-01-04 09:36:37 -0800 | [diff] [blame] | 103 | *pFormat = (audio_format_t) reply.readInt32(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | return interface_cast<IMemory>(reply.readStrongBinder()); |
| 105 | } |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 106 | |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 107 | virtual sp<IOMX> getOMX() { |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 108 | Parcel data, reply; |
| 109 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 110 | remote()->transact(GET_OMX, data, &reply); |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 111 | return interface_cast<IOMX>(reply.readStrongBinder()); |
| 112 | } |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 113 | |
| 114 | virtual void addBatteryData(uint32_t params) { |
| 115 | Parcel data, reply; |
| 116 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
| 117 | data.writeInt32(params); |
| 118 | remote()->transact(ADD_BATTERY_DATA, data, &reply); |
| 119 | } |
| 120 | |
| 121 | virtual status_t pullBatteryData(Parcel* reply) { |
| 122 | Parcel data; |
| 123 | data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); |
| 124 | return remote()->transact(PULL_BATTERY_DATA, data, reply); |
| 125 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | }; |
| 127 | |
niko | dcd810d | 2009-06-22 08:49:52 -0700 | [diff] [blame] | 128 | IMPLEMENT_META_INTERFACE(MediaPlayerService, "android.media.IMediaPlayerService"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | |
| 130 | // ---------------------------------------------------------------------- |
| 131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | status_t BnMediaPlayerService::onTransact( |
| 133 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 134 | { |
| 135 | switch(code) { |
Dave Burke | fc301b0 | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 136 | case CREATE: { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
| 138 | pid_t pid = data.readInt32(); |
Andreas Huber | 2564300 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 139 | sp<IMediaPlayerClient> client = |
| 140 | interface_cast<IMediaPlayerClient>(data.readStrongBinder()); |
Eric Laurent | 619346f | 2010-06-21 09:27:30 -0700 | [diff] [blame] | 141 | int audioSessionId = data.readInt32(); |
Dave Burke | fc301b0 | 2011-08-30 14:39:17 +0100 | [diff] [blame] | 142 | sp<IMediaPlayer> player = create(pid, client, audioSessionId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | reply->writeStrongBinder(player->asBinder()); |
| 144 | return NO_ERROR; |
| 145 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | case DECODE_URL: { |
| 147 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
| 148 | const char* url = data.readCString(); |
| 149 | uint32_t sampleRate; |
| 150 | int numChannels; |
Glenn Kasten | 1c5a89d | 2012-01-04 09:36:37 -0800 | [diff] [blame] | 151 | audio_format_t format; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | sp<IMemory> player = decode(url, &sampleRate, &numChannels, &format); |
| 153 | reply->writeInt32(sampleRate); |
| 154 | reply->writeInt32(numChannels); |
Glenn Kasten | 1c5a89d | 2012-01-04 09:36:37 -0800 | [diff] [blame] | 155 | reply->writeInt32((int32_t) format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | reply->writeStrongBinder(player->asBinder()); |
| 157 | return NO_ERROR; |
| 158 | } break; |
| 159 | case DECODE_FD: { |
| 160 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
| 161 | int fd = dup(data.readFileDescriptor()); |
| 162 | int64_t offset = data.readInt64(); |
| 163 | int64_t length = data.readInt64(); |
| 164 | uint32_t sampleRate; |
| 165 | int numChannels; |
Glenn Kasten | 1c5a89d | 2012-01-04 09:36:37 -0800 | [diff] [blame] | 166 | audio_format_t format; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | sp<IMemory> player = decode(fd, offset, length, &sampleRate, &numChannels, &format); |
| 168 | reply->writeInt32(sampleRate); |
| 169 | reply->writeInt32(numChannels); |
Glenn Kasten | 1c5a89d | 2012-01-04 09:36:37 -0800 | [diff] [blame] | 170 | reply->writeInt32((int32_t) format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | reply->writeStrongBinder(player->asBinder()); |
| 172 | return NO_ERROR; |
| 173 | } break; |
| 174 | case CREATE_MEDIA_RECORDER: { |
| 175 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
| 176 | pid_t pid = data.readInt32(); |
| 177 | sp<IMediaRecorder> recorder = createMediaRecorder(pid); |
| 178 | reply->writeStrongBinder(recorder->asBinder()); |
| 179 | return NO_ERROR; |
| 180 | } break; |
| 181 | case CREATE_METADATA_RETRIEVER: { |
| 182 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
| 183 | pid_t pid = data.readInt32(); |
| 184 | sp<IMediaMetadataRetriever> retriever = createMetadataRetriever(pid); |
| 185 | reply->writeStrongBinder(retriever->asBinder()); |
| 186 | return NO_ERROR; |
| 187 | } break; |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 188 | case GET_OMX: { |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 189 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
Andreas Huber | 784202e | 2009-10-15 13:46:54 -0700 | [diff] [blame] | 190 | sp<IOMX> omx = getOMX(); |
Andreas Huber | e46b7be | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 191 | reply->writeStrongBinder(omx->asBinder()); |
| 192 | return NO_ERROR; |
| 193 | } break; |
Gloria Wang | d211f41 | 2011-02-19 18:37:57 -0800 | [diff] [blame] | 194 | case ADD_BATTERY_DATA: { |
| 195 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
| 196 | uint32_t params = data.readInt32(); |
| 197 | addBatteryData(params); |
| 198 | return NO_ERROR; |
| 199 | } break; |
| 200 | case PULL_BATTERY_DATA: { |
| 201 | CHECK_INTERFACE(IMediaPlayerService, data, reply); |
| 202 | pullBatteryData(reply); |
| 203 | return NO_ERROR; |
| 204 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | default: |
| 206 | return BBinder::onTransact(code, data, reply, flags); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // ---------------------------------------------------------------------------- |
| 211 | |
| 212 | }; // namespace android |