The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright (C) 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 | |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 18 | #include <inttypes.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | #include <sys/types.h> |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 21 | |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 22 | #include <android/IDataSource.h> |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 23 | #include <binder/Parcel.h> |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 24 | #include <media/IMediaHTTPService.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <media/IMediaMetadataRetriever.h> |
Suren Baghdasaryan | 7435e7d | 2018-12-19 17:09:28 -0800 | [diff] [blame] | 26 | #include <processgroup/sched_policy.h> |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 27 | #include <utils/String8.h> |
Sangkyu Lee | d01c148 | 2013-02-08 16:26:39 +0900 | [diff] [blame] | 28 | #include <utils/KeyedVector.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 30 | // The binder is supposed to propagate the scheduler group across |
| 31 | // the binder interface so that remote calls are executed with |
| 32 | // the same priority as local calls. This is currently not working |
| 33 | // so this change puts in a temporary hack to fix the issue with |
| 34 | // metadata retrieval which can be a huge CPU hit if done on a |
| 35 | // foreground thread. |
| 36 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 37 | |
Dave Sparks | f311c55 | 2009-11-23 19:51:33 -0800 | [diff] [blame] | 38 | #undef LOG_TAG |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 39 | #define LOG_TAG "IMediaMetadataRetriever" |
| 40 | #include <utils/Log.h> |
| 41 | #include <cutils/sched_policy.h> |
| 42 | |
| 43 | namespace android { |
| 44 | |
| 45 | static void sendSchedPolicy(Parcel& data) |
| 46 | { |
| 47 | SchedPolicy policy; |
Glenn Kasten | 0512ab5 | 2011-05-04 17:58:57 -0700 | [diff] [blame] | 48 | get_sched_policy(gettid(), &policy); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 49 | data.writeInt32(policy); |
| 50 | } |
| 51 | |
| 52 | static void setSchedPolicy(const Parcel& data) |
| 53 | { |
| 54 | SchedPolicy policy = (SchedPolicy) data.readInt32(); |
Glenn Kasten | 0512ab5 | 2011-05-04 17:58:57 -0700 | [diff] [blame] | 55 | set_sched_policy(gettid(), policy); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 56 | } |
| 57 | static void restoreSchedPolicy() |
| 58 | { |
Glenn Kasten | 0512ab5 | 2011-05-04 17:58:57 -0700 | [diff] [blame] | 59 | set_sched_policy(gettid(), SP_FOREGROUND); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 60 | } |
| 61 | }; // end namespace android |
| 62 | #endif |
| 63 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | namespace android { |
| 65 | |
| 66 | enum { |
| 67 | DISCONNECT = IBinder::FIRST_CALL_TRANSACTION, |
| 68 | SET_DATA_SOURCE_URL, |
| 69 | SET_DATA_SOURCE_FD, |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 70 | SET_DATA_SOURCE_CALLBACK, |
James Dong | 16afe2f | 2010-12-02 17:42:08 -0800 | [diff] [blame] | 71 | GET_FRAME_AT_TIME, |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 72 | GET_IMAGE_AT_INDEX, |
Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 73 | GET_IMAGE_RECT_AT_INDEX, |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 74 | GET_FRAME_AT_INDEX, |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 75 | EXTRACT_ALBUM_ART, |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | EXTRACT_METADATA, |
| 77 | }; |
| 78 | |
| 79 | class BpMediaMetadataRetriever: public BpInterface<IMediaMetadataRetriever> |
| 80 | { |
| 81 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 82 | explicit BpMediaMetadataRetriever(const sp<IBinder>& impl) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | : BpInterface<IMediaMetadataRetriever>(impl) |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | // disconnect from media metadata retriever service |
| 88 | void disconnect() |
| 89 | { |
| 90 | Parcel data, reply; |
| 91 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
| 92 | remote()->transact(DISCONNECT, data, &reply); |
| 93 | } |
| 94 | |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 95 | status_t setDataSource( |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 96 | const sp<IMediaHTTPService> &httpService, |
| 97 | const char *srcUrl, |
| 98 | const KeyedVector<String8, String8> *headers) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | { |
| 100 | Parcel data, reply; |
| 101 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 102 | data.writeInt32(httpService != NULL); |
| 103 | if (httpService != NULL) { |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 104 | data.writeStrongBinder(IInterface::asBinder(httpService)); |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 105 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | data.writeCString(srcUrl); |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 107 | |
| 108 | if (headers == NULL) { |
| 109 | data.writeInt32(0); |
| 110 | } else { |
| 111 | // serialize the headers |
Ray Essick | 9c9fdf6 | 2019-05-14 12:04:42 -0700 | [diff] [blame] | 112 | data.writeInt32(headers->size()); |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 113 | for (size_t i = 0; i < headers->size(); ++i) { |
| 114 | data.writeString8(headers->keyAt(i)); |
| 115 | data.writeString8(headers->valueAt(i)); |
| 116 | } |
| 117 | } |
| 118 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | remote()->transact(SET_DATA_SOURCE_URL, data, &reply); |
| 120 | return reply.readInt32(); |
| 121 | } |
| 122 | |
| 123 | status_t setDataSource(int fd, int64_t offset, int64_t length) |
| 124 | { |
| 125 | Parcel data, reply; |
| 126 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
| 127 | data.writeFileDescriptor(fd); |
| 128 | data.writeInt64(offset); |
| 129 | data.writeInt64(length); |
| 130 | remote()->transact(SET_DATA_SOURCE_FD, data, &reply); |
| 131 | return reply.readInt32(); |
| 132 | } |
| 133 | |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 134 | status_t setDataSource(const sp<IDataSource>& source, const char *mime) |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 135 | { |
| 136 | Parcel data, reply; |
| 137 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
| 138 | data.writeStrongBinder(IInterface::asBinder(source)); |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 139 | |
| 140 | if (mime != NULL) { |
| 141 | data.writeInt32(1); |
| 142 | data.writeCString(mime); |
| 143 | } else { |
| 144 | data.writeInt32(0); |
| 145 | } |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 146 | remote()->transact(SET_DATA_SOURCE_CALLBACK, data, &reply); |
| 147 | return reply.readInt32(); |
| 148 | } |
| 149 | |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 150 | sp<IMemory> getFrameAtTime(int64_t timeUs, int option, int colorFormat, bool metaOnly) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | { |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 152 | ALOGV("getTimeAtTime: time(%" PRId64 " us), option(%d), colorFormat(%d) metaOnly(%d)", |
| 153 | timeUs, option, colorFormat, metaOnly); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | Parcel data, reply; |
| 155 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
James Dong | 16afe2f | 2010-12-02 17:42:08 -0800 | [diff] [blame] | 156 | data.writeInt64(timeUs); |
| 157 | data.writeInt32(option); |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 158 | data.writeInt32(colorFormat); |
| 159 | data.writeInt32(metaOnly); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 160 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 161 | sendSchedPolicy(data); |
| 162 | #endif |
James Dong | 16afe2f | 2010-12-02 17:42:08 -0800 | [diff] [blame] | 163 | remote()->transact(GET_FRAME_AT_TIME, data, &reply); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | status_t ret = reply.readInt32(); |
| 165 | if (ret != NO_ERROR) { |
| 166 | return NULL; |
| 167 | } |
| 168 | return interface_cast<IMemory>(reply.readStrongBinder()); |
| 169 | } |
| 170 | |
Chong Zhang | d5fa357 | 2018-04-09 19:03:10 -0700 | [diff] [blame] | 171 | sp<IMemory> getImageAtIndex(int index, int colorFormat, bool metaOnly, bool thumbnail) |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 172 | { |
Chong Zhang | d5fa357 | 2018-04-09 19:03:10 -0700 | [diff] [blame] | 173 | ALOGV("getImageAtIndex: index %d, colorFormat(%d) metaOnly(%d) thumbnail(%d)", |
| 174 | index, colorFormat, metaOnly, thumbnail); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 175 | Parcel data, reply; |
| 176 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
| 177 | data.writeInt32(index); |
| 178 | data.writeInt32(colorFormat); |
| 179 | data.writeInt32(metaOnly); |
Chong Zhang | d5fa357 | 2018-04-09 19:03:10 -0700 | [diff] [blame] | 180 | data.writeInt32(thumbnail); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 181 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 182 | sendSchedPolicy(data); |
| 183 | #endif |
| 184 | remote()->transact(GET_IMAGE_AT_INDEX, data, &reply); |
| 185 | status_t ret = reply.readInt32(); |
| 186 | if (ret != NO_ERROR) { |
| 187 | return NULL; |
| 188 | } |
| 189 | return interface_cast<IMemory>(reply.readStrongBinder()); |
| 190 | } |
| 191 | |
Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 192 | sp<IMemory> getImageRectAtIndex( |
| 193 | int index, int colorFormat, int left, int top, int right, int bottom) |
| 194 | { |
| 195 | ALOGV("getImageRectAtIndex: index %d, colorFormat(%d) rect {%d, %d, %d, %d}", |
| 196 | index, colorFormat, left, top, right, bottom); |
| 197 | Parcel data, reply; |
| 198 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
| 199 | data.writeInt32(index); |
| 200 | data.writeInt32(colorFormat); |
| 201 | data.writeInt32(left); |
| 202 | data.writeInt32(top); |
| 203 | data.writeInt32(right); |
| 204 | data.writeInt32(bottom); |
| 205 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 206 | sendSchedPolicy(data); |
| 207 | #endif |
| 208 | remote()->transact(GET_IMAGE_RECT_AT_INDEX, data, &reply); |
| 209 | status_t ret = reply.readInt32(); |
| 210 | if (ret != NO_ERROR) { |
| 211 | return NULL; |
| 212 | } |
| 213 | return interface_cast<IMemory>(reply.readStrongBinder()); |
| 214 | } |
| 215 | |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 216 | sp<IMemory> getFrameAtIndex( |
| 217 | int index, int colorFormat, bool metaOnly) |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 218 | { |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 219 | ALOGV("getFrameAtIndex: index(%d), colorFormat(%d) metaOnly(%d)", |
| 220 | index, colorFormat, metaOnly); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 221 | Parcel data, reply; |
| 222 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 223 | data.writeInt32(index); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 224 | data.writeInt32(colorFormat); |
| 225 | data.writeInt32(metaOnly); |
| 226 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 227 | sendSchedPolicy(data); |
| 228 | #endif |
| 229 | remote()->transact(GET_FRAME_AT_INDEX, data, &reply); |
| 230 | status_t ret = reply.readInt32(); |
| 231 | if (ret != NO_ERROR) { |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 232 | return NULL; |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 233 | } |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 234 | return interface_cast<IMemory>(reply.readStrongBinder()); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 235 | } |
| 236 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | sp<IMemory> extractAlbumArt() |
| 238 | { |
| 239 | Parcel data, reply; |
| 240 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 241 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 242 | sendSchedPolicy(data); |
| 243 | #endif |
| 244 | remote()->transact(EXTRACT_ALBUM_ART, data, &reply); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | status_t ret = reply.readInt32(); |
| 246 | if (ret != NO_ERROR) { |
| 247 | return NULL; |
| 248 | } |
| 249 | return interface_cast<IMemory>(reply.readStrongBinder()); |
| 250 | } |
| 251 | |
| 252 | const char* extractMetadata(int keyCode) |
| 253 | { |
| 254 | Parcel data, reply; |
| 255 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 256 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 257 | sendSchedPolicy(data); |
| 258 | #endif |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | data.writeInt32(keyCode); |
| 260 | remote()->transact(EXTRACT_METADATA, data, &reply); |
| 261 | status_t ret = reply.readInt32(); |
| 262 | if (ret != NO_ERROR) { |
| 263 | return NULL; |
| 264 | } |
Sangkyu Lee | d01c148 | 2013-02-08 16:26:39 +0900 | [diff] [blame] | 265 | const char* str = reply.readCString(); |
| 266 | if (str != NULL) { |
| 267 | String8 value(str); |
| 268 | if (mMetadata.indexOfKey(keyCode) < 0) { |
| 269 | mMetadata.add(keyCode, value); |
| 270 | } else { |
| 271 | mMetadata.replaceValueFor(keyCode, value); |
| 272 | } |
| 273 | return mMetadata.valueFor(keyCode).string(); |
| 274 | } else { |
| 275 | return NULL; |
| 276 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | } |
Sangkyu Lee | d01c148 | 2013-02-08 16:26:39 +0900 | [diff] [blame] | 278 | |
| 279 | private: |
| 280 | KeyedVector<int, String8> mMetadata; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | }; |
| 282 | |
niko | 56f0cc5 | 2009-06-22 08:49:52 -0700 | [diff] [blame] | 283 | IMPLEMENT_META_INTERFACE(MediaMetadataRetriever, "android.media.IMediaMetadataRetriever"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | |
| 285 | // ---------------------------------------------------------------------- |
| 286 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | status_t BnMediaMetadataRetriever::onTransact( |
| 288 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 289 | { |
| 290 | switch (code) { |
| 291 | case DISCONNECT: { |
| 292 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 293 | disconnect(); |
| 294 | return NO_ERROR; |
| 295 | } break; |
| 296 | case SET_DATA_SOURCE_URL: { |
| 297 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 298 | |
| 299 | sp<IMediaHTTPService> httpService; |
| 300 | if (data.readInt32()) { |
| 301 | httpService = |
| 302 | interface_cast<IMediaHTTPService>(data.readStrongBinder()); |
| 303 | } |
| 304 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | const char* srcUrl = data.readCString(); |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 306 | |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 307 | if (httpService == NULL || srcUrl == NULL) { |
| 308 | reply->writeInt32(BAD_VALUE); |
| 309 | return NO_ERROR; |
| 310 | } |
| 311 | |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 312 | KeyedVector<String8, String8> headers; |
Ray Essick | 9c9fdf6 | 2019-05-14 12:04:42 -0700 | [diff] [blame] | 313 | size_t numHeaders = (size_t) data.readInt32(); |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 314 | for (size_t i = 0; i < numHeaders; ++i) { |
Ray Essick | 9c9fdf6 | 2019-05-14 12:04:42 -0700 | [diff] [blame] | 315 | String8 key; |
| 316 | String8 value; |
| 317 | status_t status; |
| 318 | status = data.readString8(&key); |
| 319 | if (status != OK) { |
| 320 | return status; |
| 321 | } |
| 322 | status = data.readString8(&value); |
| 323 | if (status != OK) { |
| 324 | return status; |
| 325 | } |
| 326 | if (headers.add(key, value) < 0) { |
| 327 | return UNKNOWN_ERROR; |
| 328 | } |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | reply->writeInt32( |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 332 | setDataSource( |
| 333 | httpService, srcUrl, numHeaders > 0 ? &headers : NULL)); |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 334 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | return NO_ERROR; |
| 336 | } break; |
| 337 | case SET_DATA_SOURCE_FD: { |
| 338 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
Taiju Tsuiki | 55203e2 | 2015-04-21 17:36:22 +0900 | [diff] [blame] | 339 | int fd = data.readFileDescriptor(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | int64_t offset = data.readInt64(); |
| 341 | int64_t length = data.readInt64(); |
| 342 | reply->writeInt32(setDataSource(fd, offset, length)); |
| 343 | return NO_ERROR; |
| 344 | } break; |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 345 | case SET_DATA_SOURCE_CALLBACK: { |
| 346 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 347 | sp<IDataSource> source = |
| 348 | interface_cast<IDataSource>(data.readStrongBinder()); |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 349 | if (source == NULL) { |
| 350 | reply->writeInt32(BAD_VALUE); |
| 351 | } else { |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 352 | int32_t hasMime = data.readInt32(); |
| 353 | const char *mime = NULL; |
| 354 | if (hasMime) { |
| 355 | mime = data.readCString(); |
| 356 | } |
| 357 | reply->writeInt32(setDataSource(source, mime)); |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 358 | } |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 359 | return NO_ERROR; |
| 360 | } break; |
James Dong | 16afe2f | 2010-12-02 17:42:08 -0800 | [diff] [blame] | 361 | case GET_FRAME_AT_TIME: { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
James Dong | 16afe2f | 2010-12-02 17:42:08 -0800 | [diff] [blame] | 363 | int64_t timeUs = data.readInt64(); |
| 364 | int option = data.readInt32(); |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 365 | int colorFormat = data.readInt32(); |
| 366 | bool metaOnly = (data.readInt32() != 0); |
| 367 | ALOGV("getTimeAtTime: time(%" PRId64 " us), option(%d), colorFormat(%d), metaOnly(%d)", |
| 368 | timeUs, option, colorFormat, metaOnly); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 369 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 370 | setSchedPolicy(data); |
| 371 | #endif |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 372 | sp<IMemory> bitmap = getFrameAtTime(timeUs, option, colorFormat, metaOnly); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | if (bitmap != 0) { // Don't send NULL across the binder interface |
| 374 | reply->writeInt32(NO_ERROR); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 375 | reply->writeStrongBinder(IInterface::asBinder(bitmap)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | } else { |
| 377 | reply->writeInt32(UNKNOWN_ERROR); |
| 378 | } |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 379 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 380 | restoreSchedPolicy(); |
| 381 | #endif |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | return NO_ERROR; |
| 383 | } break; |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 384 | case GET_IMAGE_AT_INDEX: { |
| 385 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 386 | int index = data.readInt32(); |
| 387 | int colorFormat = data.readInt32(); |
| 388 | bool metaOnly = (data.readInt32() != 0); |
Chong Zhang | d5fa357 | 2018-04-09 19:03:10 -0700 | [diff] [blame] | 389 | bool thumbnail = (data.readInt32() != 0); |
| 390 | ALOGV("getImageAtIndex: index(%d), colorFormat(%d), metaOnly(%d), thumbnail(%d)", |
| 391 | index, colorFormat, metaOnly, thumbnail); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 392 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 393 | setSchedPolicy(data); |
| 394 | #endif |
Chong Zhang | d5fa357 | 2018-04-09 19:03:10 -0700 | [diff] [blame] | 395 | sp<IMemory> bitmap = getImageAtIndex(index, colorFormat, metaOnly, thumbnail); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 396 | if (bitmap != 0) { // Don't send NULL across the binder interface |
| 397 | reply->writeInt32(NO_ERROR); |
| 398 | reply->writeStrongBinder(IInterface::asBinder(bitmap)); |
| 399 | } else { |
| 400 | reply->writeInt32(UNKNOWN_ERROR); |
| 401 | } |
| 402 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 403 | restoreSchedPolicy(); |
| 404 | #endif |
| 405 | return NO_ERROR; |
| 406 | } break; |
Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 407 | |
| 408 | case GET_IMAGE_RECT_AT_INDEX: { |
| 409 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 410 | int index = data.readInt32(); |
| 411 | int colorFormat = data.readInt32(); |
| 412 | int left = data.readInt32(); |
| 413 | int top = data.readInt32(); |
| 414 | int right = data.readInt32(); |
| 415 | int bottom = data.readInt32(); |
| 416 | ALOGV("getImageRectAtIndex: index(%d), colorFormat(%d), rect {%d, %d, %d, %d}", |
| 417 | index, colorFormat, left, top, right, bottom); |
| 418 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 419 | setSchedPolicy(data); |
| 420 | #endif |
| 421 | sp<IMemory> bitmap = getImageRectAtIndex( |
| 422 | index, colorFormat, left, top, right, bottom); |
| 423 | if (bitmap != 0) { // Don't send NULL across the binder interface |
| 424 | reply->writeInt32(NO_ERROR); |
| 425 | reply->writeStrongBinder(IInterface::asBinder(bitmap)); |
| 426 | } else { |
| 427 | reply->writeInt32(UNKNOWN_ERROR); |
| 428 | } |
| 429 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 430 | restoreSchedPolicy(); |
| 431 | #endif |
| 432 | return NO_ERROR; |
| 433 | } break; |
| 434 | |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 435 | case GET_FRAME_AT_INDEX: { |
| 436 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 437 | int index = data.readInt32(); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 438 | int colorFormat = data.readInt32(); |
| 439 | bool metaOnly = (data.readInt32() != 0); |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 440 | ALOGV("getFrameAtIndex: index(%d), colorFormat(%d), metaOnly(%d)", |
| 441 | index, colorFormat, metaOnly); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 442 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 443 | setSchedPolicy(data); |
| 444 | #endif |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 445 | sp<IMemory> frame = getFrameAtIndex(index, colorFormat, metaOnly); |
| 446 | if (frame != nullptr) { // Don't send NULL across the binder interface |
| 447 | reply->writeInt32(NO_ERROR); |
| 448 | reply->writeStrongBinder(IInterface::asBinder(frame)); |
| 449 | } else { |
| 450 | reply->writeInt32(UNKNOWN_ERROR); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 451 | } |
| 452 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 453 | restoreSchedPolicy(); |
| 454 | #endif |
| 455 | return NO_ERROR; |
| 456 | } break; |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 457 | case EXTRACT_ALBUM_ART: { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 459 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 460 | setSchedPolicy(data); |
| 461 | #endif |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | sp<IMemory> albumArt = extractAlbumArt(); |
| 463 | if (albumArt != 0) { // Don't send NULL across the binder interface |
| 464 | reply->writeInt32(NO_ERROR); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 465 | reply->writeStrongBinder(IInterface::asBinder(albumArt)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | } else { |
| 467 | reply->writeInt32(UNKNOWN_ERROR); |
| 468 | } |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 469 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 470 | restoreSchedPolicy(); |
| 471 | #endif |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | return NO_ERROR; |
| 473 | } break; |
| 474 | case EXTRACT_METADATA: { |
| 475 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 476 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 477 | setSchedPolicy(data); |
| 478 | #endif |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | int keyCode = data.readInt32(); |
| 480 | const char* value = extractMetadata(keyCode); |
| 481 | if (value != NULL) { // Don't send NULL across the binder interface |
| 482 | reply->writeInt32(NO_ERROR); |
| 483 | reply->writeCString(value); |
| 484 | } else { |
| 485 | reply->writeInt32(UNKNOWN_ERROR); |
| 486 | } |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 487 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 488 | restoreSchedPolicy(); |
| 489 | #endif |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | return NO_ERROR; |
| 491 | } break; |
| 492 | default: |
| 493 | return BBinder::onTransact(code, data, reply, flags); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | // ---------------------------------------------------------------------------- |
| 498 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 499 | } // namespace android |