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 | |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 22 | #include <binder/Parcel.h> |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 23 | #include <media/IDataSource.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 |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 112 | data.writeInt64(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 | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 216 | status_t getFrameAtIndex(std::vector<sp<IMemory> > *frames, |
| 217 | int frameIndex, int numFrames, int colorFormat, bool metaOnly) |
| 218 | { |
| 219 | ALOGV("getFrameAtIndex: frameIndex(%d), numFrames(%d), colorFormat(%d) metaOnly(%d)", |
| 220 | frameIndex, numFrames, colorFormat, metaOnly); |
| 221 | Parcel data, reply; |
| 222 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
| 223 | data.writeInt32(frameIndex); |
| 224 | data.writeInt32(numFrames); |
| 225 | data.writeInt32(colorFormat); |
| 226 | data.writeInt32(metaOnly); |
| 227 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 228 | sendSchedPolicy(data); |
| 229 | #endif |
| 230 | remote()->transact(GET_FRAME_AT_INDEX, data, &reply); |
| 231 | status_t ret = reply.readInt32(); |
| 232 | if (ret != NO_ERROR) { |
| 233 | return ret; |
| 234 | } |
| 235 | int retNumFrames = reply.readInt32(); |
| 236 | if (retNumFrames < numFrames) { |
| 237 | numFrames = retNumFrames; |
| 238 | } |
| 239 | for (int i = 0; i < numFrames; i++) { |
| 240 | frames->push_back(interface_cast<IMemory>(reply.readStrongBinder())); |
| 241 | } |
| 242 | return OK; |
| 243 | } |
| 244 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | sp<IMemory> extractAlbumArt() |
| 246 | { |
| 247 | Parcel data, reply; |
| 248 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 249 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 250 | sendSchedPolicy(data); |
| 251 | #endif |
| 252 | remote()->transact(EXTRACT_ALBUM_ART, data, &reply); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | status_t ret = reply.readInt32(); |
| 254 | if (ret != NO_ERROR) { |
| 255 | return NULL; |
| 256 | } |
| 257 | return interface_cast<IMemory>(reply.readStrongBinder()); |
| 258 | } |
| 259 | |
| 260 | const char* extractMetadata(int keyCode) |
| 261 | { |
| 262 | Parcel data, reply; |
| 263 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 264 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 265 | sendSchedPolicy(data); |
| 266 | #endif |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | data.writeInt32(keyCode); |
| 268 | remote()->transact(EXTRACT_METADATA, data, &reply); |
| 269 | status_t ret = reply.readInt32(); |
| 270 | if (ret != NO_ERROR) { |
| 271 | return NULL; |
| 272 | } |
Sangkyu Lee | d01c148 | 2013-02-08 16:26:39 +0900 | [diff] [blame] | 273 | const char* str = reply.readCString(); |
| 274 | if (str != NULL) { |
| 275 | String8 value(str); |
| 276 | if (mMetadata.indexOfKey(keyCode) < 0) { |
| 277 | mMetadata.add(keyCode, value); |
| 278 | } else { |
| 279 | mMetadata.replaceValueFor(keyCode, value); |
| 280 | } |
| 281 | return mMetadata.valueFor(keyCode).string(); |
| 282 | } else { |
| 283 | return NULL; |
| 284 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | } |
Sangkyu Lee | d01c148 | 2013-02-08 16:26:39 +0900 | [diff] [blame] | 286 | |
| 287 | private: |
| 288 | KeyedVector<int, String8> mMetadata; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | }; |
| 290 | |
niko | 56f0cc5 | 2009-06-22 08:49:52 -0700 | [diff] [blame] | 291 | IMPLEMENT_META_INTERFACE(MediaMetadataRetriever, "android.media.IMediaMetadataRetriever"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | |
| 293 | // ---------------------------------------------------------------------- |
| 294 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | status_t BnMediaMetadataRetriever::onTransact( |
| 296 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 297 | { |
| 298 | switch (code) { |
| 299 | case DISCONNECT: { |
| 300 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 301 | disconnect(); |
| 302 | return NO_ERROR; |
| 303 | } break; |
| 304 | case SET_DATA_SOURCE_URL: { |
| 305 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 306 | |
| 307 | sp<IMediaHTTPService> httpService; |
| 308 | if (data.readInt32()) { |
| 309 | httpService = |
| 310 | interface_cast<IMediaHTTPService>(data.readStrongBinder()); |
| 311 | } |
| 312 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | const char* srcUrl = data.readCString(); |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 314 | |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 315 | if (httpService == NULL || srcUrl == NULL) { |
| 316 | reply->writeInt32(BAD_VALUE); |
| 317 | return NO_ERROR; |
| 318 | } |
| 319 | |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 320 | KeyedVector<String8, String8> headers; |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 321 | size_t numHeaders = (size_t) data.readInt64(); |
| 322 | for (size_t i = 0; i < numHeaders; ++i) { |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 323 | String8 key = data.readString8(); |
| 324 | String8 value = data.readString8(); |
| 325 | headers.add(key, value); |
| 326 | } |
| 327 | |
| 328 | reply->writeInt32( |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 329 | setDataSource( |
| 330 | httpService, srcUrl, numHeaders > 0 ? &headers : NULL)); |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 331 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | return NO_ERROR; |
| 333 | } break; |
| 334 | case SET_DATA_SOURCE_FD: { |
| 335 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
Taiju Tsuiki | 55203e2 | 2015-04-21 17:36:22 +0900 | [diff] [blame] | 336 | int fd = data.readFileDescriptor(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | int64_t offset = data.readInt64(); |
| 338 | int64_t length = data.readInt64(); |
| 339 | reply->writeInt32(setDataSource(fd, offset, length)); |
| 340 | return NO_ERROR; |
| 341 | } break; |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 342 | case SET_DATA_SOURCE_CALLBACK: { |
| 343 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 344 | sp<IDataSource> source = |
| 345 | interface_cast<IDataSource>(data.readStrongBinder()); |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 346 | if (source == NULL) { |
| 347 | reply->writeInt32(BAD_VALUE); |
| 348 | } else { |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 349 | int32_t hasMime = data.readInt32(); |
| 350 | const char *mime = NULL; |
| 351 | if (hasMime) { |
| 352 | mime = data.readCString(); |
| 353 | } |
| 354 | reply->writeInt32(setDataSource(source, mime)); |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 355 | } |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 356 | return NO_ERROR; |
| 357 | } break; |
James Dong | 16afe2f | 2010-12-02 17:42:08 -0800 | [diff] [blame] | 358 | case GET_FRAME_AT_TIME: { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
James Dong | 16afe2f | 2010-12-02 17:42:08 -0800 | [diff] [blame] | 360 | int64_t timeUs = data.readInt64(); |
| 361 | int option = data.readInt32(); |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 362 | int colorFormat = data.readInt32(); |
| 363 | bool metaOnly = (data.readInt32() != 0); |
| 364 | ALOGV("getTimeAtTime: time(%" PRId64 " us), option(%d), colorFormat(%d), metaOnly(%d)", |
| 365 | timeUs, option, colorFormat, metaOnly); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 366 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 367 | setSchedPolicy(data); |
| 368 | #endif |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 369 | sp<IMemory> bitmap = getFrameAtTime(timeUs, option, colorFormat, metaOnly); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | if (bitmap != 0) { // Don't send NULL across the binder interface |
| 371 | reply->writeInt32(NO_ERROR); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 372 | reply->writeStrongBinder(IInterface::asBinder(bitmap)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | } else { |
| 374 | reply->writeInt32(UNKNOWN_ERROR); |
| 375 | } |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 376 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 377 | restoreSchedPolicy(); |
| 378 | #endif |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | return NO_ERROR; |
| 380 | } break; |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 381 | case GET_IMAGE_AT_INDEX: { |
| 382 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 383 | int index = data.readInt32(); |
| 384 | int colorFormat = data.readInt32(); |
| 385 | bool metaOnly = (data.readInt32() != 0); |
Chong Zhang | d5fa357 | 2018-04-09 19:03:10 -0700 | [diff] [blame] | 386 | bool thumbnail = (data.readInt32() != 0); |
| 387 | ALOGV("getImageAtIndex: index(%d), colorFormat(%d), metaOnly(%d), thumbnail(%d)", |
| 388 | index, colorFormat, metaOnly, thumbnail); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 389 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 390 | setSchedPolicy(data); |
| 391 | #endif |
Chong Zhang | d5fa357 | 2018-04-09 19:03:10 -0700 | [diff] [blame] | 392 | sp<IMemory> bitmap = getImageAtIndex(index, colorFormat, metaOnly, thumbnail); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 393 | if (bitmap != 0) { // Don't send NULL across the binder interface |
| 394 | reply->writeInt32(NO_ERROR); |
| 395 | reply->writeStrongBinder(IInterface::asBinder(bitmap)); |
| 396 | } else { |
| 397 | reply->writeInt32(UNKNOWN_ERROR); |
| 398 | } |
| 399 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 400 | restoreSchedPolicy(); |
| 401 | #endif |
| 402 | return NO_ERROR; |
| 403 | } break; |
Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 404 | |
| 405 | case GET_IMAGE_RECT_AT_INDEX: { |
| 406 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 407 | int index = data.readInt32(); |
| 408 | int colorFormat = data.readInt32(); |
| 409 | int left = data.readInt32(); |
| 410 | int top = data.readInt32(); |
| 411 | int right = data.readInt32(); |
| 412 | int bottom = data.readInt32(); |
| 413 | ALOGV("getImageRectAtIndex: index(%d), colorFormat(%d), rect {%d, %d, %d, %d}", |
| 414 | index, colorFormat, left, top, right, bottom); |
| 415 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 416 | setSchedPolicy(data); |
| 417 | #endif |
| 418 | sp<IMemory> bitmap = getImageRectAtIndex( |
| 419 | index, colorFormat, left, top, right, bottom); |
| 420 | if (bitmap != 0) { // Don't send NULL across the binder interface |
| 421 | reply->writeInt32(NO_ERROR); |
| 422 | reply->writeStrongBinder(IInterface::asBinder(bitmap)); |
| 423 | } else { |
| 424 | reply->writeInt32(UNKNOWN_ERROR); |
| 425 | } |
| 426 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 427 | restoreSchedPolicy(); |
| 428 | #endif |
| 429 | return NO_ERROR; |
| 430 | } break; |
| 431 | |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 432 | case GET_FRAME_AT_INDEX: { |
| 433 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 434 | int frameIndex = data.readInt32(); |
| 435 | int numFrames = data.readInt32(); |
| 436 | int colorFormat = data.readInt32(); |
| 437 | bool metaOnly = (data.readInt32() != 0); |
| 438 | ALOGV("getFrameAtIndex: frameIndex(%d), numFrames(%d), colorFormat(%d), metaOnly(%d)", |
| 439 | frameIndex, numFrames, colorFormat, metaOnly); |
| 440 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 441 | setSchedPolicy(data); |
| 442 | #endif |
| 443 | std::vector<sp<IMemory> > frames; |
| 444 | status_t err = getFrameAtIndex( |
| 445 | &frames, frameIndex, numFrames, colorFormat, metaOnly); |
| 446 | reply->writeInt32(err); |
| 447 | if (OK == err) { |
| 448 | reply->writeInt32(frames.size()); |
| 449 | for (size_t i = 0; i < frames.size(); i++) { |
| 450 | reply->writeStrongBinder(IInterface::asBinder(frames[i])); |
| 451 | } |
| 452 | } |
| 453 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 454 | restoreSchedPolicy(); |
| 455 | #endif |
| 456 | return NO_ERROR; |
| 457 | } break; |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 458 | case EXTRACT_ALBUM_ART: { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 460 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 461 | setSchedPolicy(data); |
| 462 | #endif |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | sp<IMemory> albumArt = extractAlbumArt(); |
| 464 | if (albumArt != 0) { // Don't send NULL across the binder interface |
| 465 | reply->writeInt32(NO_ERROR); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 466 | reply->writeStrongBinder(IInterface::asBinder(albumArt)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | } else { |
| 468 | reply->writeInt32(UNKNOWN_ERROR); |
| 469 | } |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 470 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 471 | restoreSchedPolicy(); |
| 472 | #endif |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | return NO_ERROR; |
| 474 | } break; |
| 475 | case EXTRACT_METADATA: { |
| 476 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 477 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 478 | setSchedPolicy(data); |
| 479 | #endif |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | int keyCode = data.readInt32(); |
| 481 | const char* value = extractMetadata(keyCode); |
| 482 | if (value != NULL) { // Don't send NULL across the binder interface |
| 483 | reply->writeInt32(NO_ERROR); |
| 484 | reply->writeCString(value); |
| 485 | } else { |
| 486 | reply->writeInt32(UNKNOWN_ERROR); |
| 487 | } |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 488 | #ifndef DISABLE_GROUP_SCHEDULE_HACK |
| 489 | restoreSchedPolicy(); |
| 490 | #endif |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | return NO_ERROR; |
| 492 | } break; |
| 493 | default: |
| 494 | return BBinder::onTransact(code, data, reply, flags); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | // ---------------------------------------------------------------------------- |
| 499 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 500 | } // namespace android |