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 | |
| 30 | namespace android { |
| 31 | |
| 32 | enum { |
| 33 | DISCONNECT = IBinder::FIRST_CALL_TRANSACTION, |
| 34 | SET_DATA_SOURCE_URL, |
| 35 | SET_DATA_SOURCE_FD, |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 36 | SET_DATA_SOURCE_CALLBACK, |
James Dong | 16afe2f | 2010-12-02 17:42:08 -0800 | [diff] [blame] | 37 | GET_FRAME_AT_TIME, |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 38 | GET_IMAGE_AT_INDEX, |
Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 39 | GET_IMAGE_RECT_AT_INDEX, |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 40 | GET_FRAME_AT_INDEX, |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 41 | EXTRACT_ALBUM_ART, |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | EXTRACT_METADATA, |
| 43 | }; |
| 44 | |
| 45 | class BpMediaMetadataRetriever: public BpInterface<IMediaMetadataRetriever> |
| 46 | { |
| 47 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 48 | explicit BpMediaMetadataRetriever(const sp<IBinder>& impl) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | : BpInterface<IMediaMetadataRetriever>(impl) |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | // disconnect from media metadata retriever service |
| 54 | void disconnect() |
| 55 | { |
| 56 | Parcel data, reply; |
| 57 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
| 58 | remote()->transact(DISCONNECT, data, &reply); |
| 59 | } |
| 60 | |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 61 | status_t setDataSource( |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 62 | const sp<IMediaHTTPService> &httpService, |
| 63 | const char *srcUrl, |
| 64 | const KeyedVector<String8, String8> *headers) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | { |
| 66 | Parcel data, reply; |
| 67 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 68 | data.writeInt32(httpService != NULL); |
| 69 | if (httpService != NULL) { |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 70 | data.writeStrongBinder(IInterface::asBinder(httpService)); |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 71 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | data.writeCString(srcUrl); |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 73 | |
| 74 | if (headers == NULL) { |
| 75 | data.writeInt32(0); |
| 76 | } else { |
| 77 | // serialize the headers |
Ray Essick | 9c9fdf6 | 2019-05-14 12:04:42 -0700 | [diff] [blame] | 78 | data.writeInt32(headers->size()); |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 79 | for (size_t i = 0; i < headers->size(); ++i) { |
| 80 | data.writeString8(headers->keyAt(i)); |
| 81 | data.writeString8(headers->valueAt(i)); |
| 82 | } |
| 83 | } |
| 84 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | remote()->transact(SET_DATA_SOURCE_URL, data, &reply); |
| 86 | return reply.readInt32(); |
| 87 | } |
| 88 | |
| 89 | status_t setDataSource(int fd, int64_t offset, int64_t length) |
| 90 | { |
| 91 | Parcel data, reply; |
| 92 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
| 93 | data.writeFileDescriptor(fd); |
| 94 | data.writeInt64(offset); |
| 95 | data.writeInt64(length); |
| 96 | remote()->transact(SET_DATA_SOURCE_FD, data, &reply); |
| 97 | return reply.readInt32(); |
| 98 | } |
| 99 | |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 100 | status_t setDataSource(const sp<IDataSource>& source, const char *mime) |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 101 | { |
| 102 | Parcel data, reply; |
| 103 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
| 104 | data.writeStrongBinder(IInterface::asBinder(source)); |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 105 | |
| 106 | if (mime != NULL) { |
| 107 | data.writeInt32(1); |
| 108 | data.writeCString(mime); |
| 109 | } else { |
| 110 | data.writeInt32(0); |
| 111 | } |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 112 | remote()->transact(SET_DATA_SOURCE_CALLBACK, data, &reply); |
| 113 | return reply.readInt32(); |
| 114 | } |
| 115 | |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 116 | 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] | 117 | { |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 118 | ALOGV("getTimeAtTime: time(%" PRId64 " us), option(%d), colorFormat(%d) metaOnly(%d)", |
| 119 | timeUs, option, colorFormat, metaOnly); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | Parcel data, reply; |
| 121 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
James Dong | 16afe2f | 2010-12-02 17:42:08 -0800 | [diff] [blame] | 122 | data.writeInt64(timeUs); |
| 123 | data.writeInt32(option); |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 124 | data.writeInt32(colorFormat); |
| 125 | data.writeInt32(metaOnly); |
James Dong | 16afe2f | 2010-12-02 17:42:08 -0800 | [diff] [blame] | 126 | remote()->transact(GET_FRAME_AT_TIME, data, &reply); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | status_t ret = reply.readInt32(); |
| 128 | if (ret != NO_ERROR) { |
| 129 | return NULL; |
| 130 | } |
| 131 | return interface_cast<IMemory>(reply.readStrongBinder()); |
| 132 | } |
| 133 | |
Chong Zhang | d5fa357 | 2018-04-09 19:03:10 -0700 | [diff] [blame] | 134 | sp<IMemory> getImageAtIndex(int index, int colorFormat, bool metaOnly, bool thumbnail) |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 135 | { |
Chong Zhang | d5fa357 | 2018-04-09 19:03:10 -0700 | [diff] [blame] | 136 | ALOGV("getImageAtIndex: index %d, colorFormat(%d) metaOnly(%d) thumbnail(%d)", |
| 137 | index, colorFormat, metaOnly, thumbnail); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 138 | Parcel data, reply; |
| 139 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
| 140 | data.writeInt32(index); |
| 141 | data.writeInt32(colorFormat); |
| 142 | data.writeInt32(metaOnly); |
Chong Zhang | d5fa357 | 2018-04-09 19:03:10 -0700 | [diff] [blame] | 143 | data.writeInt32(thumbnail); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 144 | remote()->transact(GET_IMAGE_AT_INDEX, data, &reply); |
| 145 | status_t ret = reply.readInt32(); |
| 146 | if (ret != NO_ERROR) { |
| 147 | return NULL; |
| 148 | } |
| 149 | return interface_cast<IMemory>(reply.readStrongBinder()); |
| 150 | } |
| 151 | |
Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 152 | sp<IMemory> getImageRectAtIndex( |
| 153 | int index, int colorFormat, int left, int top, int right, int bottom) |
| 154 | { |
| 155 | ALOGV("getImageRectAtIndex: index %d, colorFormat(%d) rect {%d, %d, %d, %d}", |
| 156 | index, colorFormat, left, top, right, bottom); |
| 157 | Parcel data, reply; |
| 158 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
| 159 | data.writeInt32(index); |
| 160 | data.writeInt32(colorFormat); |
| 161 | data.writeInt32(left); |
| 162 | data.writeInt32(top); |
| 163 | data.writeInt32(right); |
| 164 | data.writeInt32(bottom); |
Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 165 | remote()->transact(GET_IMAGE_RECT_AT_INDEX, data, &reply); |
| 166 | status_t ret = reply.readInt32(); |
| 167 | if (ret != NO_ERROR) { |
| 168 | return NULL; |
| 169 | } |
| 170 | return interface_cast<IMemory>(reply.readStrongBinder()); |
| 171 | } |
| 172 | |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 173 | sp<IMemory> getFrameAtIndex( |
| 174 | int index, int colorFormat, bool metaOnly) |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 175 | { |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 176 | ALOGV("getFrameAtIndex: index(%d), colorFormat(%d) metaOnly(%d)", |
| 177 | index, colorFormat, metaOnly); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 178 | Parcel data, reply; |
| 179 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 180 | data.writeInt32(index); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 181 | data.writeInt32(colorFormat); |
| 182 | data.writeInt32(metaOnly); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 183 | remote()->transact(GET_FRAME_AT_INDEX, data, &reply); |
| 184 | status_t ret = reply.readInt32(); |
| 185 | if (ret != NO_ERROR) { |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 186 | return NULL; |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 187 | } |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 188 | return interface_cast<IMemory>(reply.readStrongBinder()); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 189 | } |
| 190 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | sp<IMemory> extractAlbumArt() |
| 192 | { |
| 193 | Parcel data, reply; |
| 194 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 195 | remote()->transact(EXTRACT_ALBUM_ART, data, &reply); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | status_t ret = reply.readInt32(); |
| 197 | if (ret != NO_ERROR) { |
| 198 | return NULL; |
| 199 | } |
| 200 | return interface_cast<IMemory>(reply.readStrongBinder()); |
| 201 | } |
| 202 | |
| 203 | const char* extractMetadata(int keyCode) |
| 204 | { |
| 205 | Parcel data, reply; |
| 206 | data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor()); |
| 207 | data.writeInt32(keyCode); |
| 208 | remote()->transact(EXTRACT_METADATA, data, &reply); |
| 209 | status_t ret = reply.readInt32(); |
| 210 | if (ret != NO_ERROR) { |
| 211 | return NULL; |
| 212 | } |
Sangkyu Lee | d01c148 | 2013-02-08 16:26:39 +0900 | [diff] [blame] | 213 | const char* str = reply.readCString(); |
| 214 | if (str != NULL) { |
| 215 | String8 value(str); |
| 216 | if (mMetadata.indexOfKey(keyCode) < 0) { |
| 217 | mMetadata.add(keyCode, value); |
| 218 | } else { |
| 219 | mMetadata.replaceValueFor(keyCode, value); |
| 220 | } |
| 221 | return mMetadata.valueFor(keyCode).string(); |
| 222 | } else { |
| 223 | return NULL; |
| 224 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | } |
Sangkyu Lee | d01c148 | 2013-02-08 16:26:39 +0900 | [diff] [blame] | 226 | |
| 227 | private: |
| 228 | KeyedVector<int, String8> mMetadata; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | }; |
| 230 | |
niko | 56f0cc5 | 2009-06-22 08:49:52 -0700 | [diff] [blame] | 231 | IMPLEMENT_META_INTERFACE(MediaMetadataRetriever, "android.media.IMediaMetadataRetriever"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | |
| 233 | // ---------------------------------------------------------------------- |
| 234 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | status_t BnMediaMetadataRetriever::onTransact( |
| 236 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 237 | { |
| 238 | switch (code) { |
| 239 | case DISCONNECT: { |
| 240 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 241 | disconnect(); |
| 242 | return NO_ERROR; |
| 243 | } break; |
| 244 | case SET_DATA_SOURCE_URL: { |
| 245 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 246 | |
| 247 | sp<IMediaHTTPService> httpService; |
| 248 | if (data.readInt32()) { |
| 249 | httpService = |
| 250 | interface_cast<IMediaHTTPService>(data.readStrongBinder()); |
| 251 | } |
| 252 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | const char* srcUrl = data.readCString(); |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 254 | |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 255 | if (httpService == NULL || srcUrl == NULL) { |
| 256 | reply->writeInt32(BAD_VALUE); |
| 257 | return NO_ERROR; |
| 258 | } |
| 259 | |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 260 | KeyedVector<String8, String8> headers; |
Ray Essick | 9c9fdf6 | 2019-05-14 12:04:42 -0700 | [diff] [blame] | 261 | size_t numHeaders = (size_t) data.readInt32(); |
Glenn Kasten | e03dd22 | 2014-01-28 11:04:39 -0800 | [diff] [blame] | 262 | for (size_t i = 0; i < numHeaders; ++i) { |
Ray Essick | 9c9fdf6 | 2019-05-14 12:04:42 -0700 | [diff] [blame] | 263 | String8 key; |
| 264 | String8 value; |
| 265 | status_t status; |
| 266 | status = data.readString8(&key); |
| 267 | if (status != OK) { |
| 268 | return status; |
| 269 | } |
| 270 | status = data.readString8(&value); |
| 271 | if (status != OK) { |
| 272 | return status; |
| 273 | } |
| 274 | if (headers.add(key, value) < 0) { |
| 275 | return UNKNOWN_ERROR; |
| 276 | } |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | reply->writeInt32( |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 280 | setDataSource( |
| 281 | httpService, srcUrl, numHeaders > 0 ? &headers : NULL)); |
Andreas Huber | af8791e | 2011-03-21 10:25:44 -0700 | [diff] [blame] | 282 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | return NO_ERROR; |
| 284 | } break; |
| 285 | case SET_DATA_SOURCE_FD: { |
| 286 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
Taiju Tsuiki | 55203e2 | 2015-04-21 17:36:22 +0900 | [diff] [blame] | 287 | int fd = data.readFileDescriptor(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | int64_t offset = data.readInt64(); |
| 289 | int64_t length = data.readInt64(); |
| 290 | reply->writeInt32(setDataSource(fd, offset, length)); |
| 291 | return NO_ERROR; |
| 292 | } break; |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 293 | case SET_DATA_SOURCE_CALLBACK: { |
| 294 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 295 | sp<IDataSource> source = |
| 296 | interface_cast<IDataSource>(data.readStrongBinder()); |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 297 | if (source == NULL) { |
| 298 | reply->writeInt32(BAD_VALUE); |
| 299 | } else { |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 300 | int32_t hasMime = data.readInt32(); |
| 301 | const char *mime = NULL; |
| 302 | if (hasMime) { |
| 303 | mime = data.readCString(); |
| 304 | } |
| 305 | reply->writeInt32(setDataSource(source, mime)); |
Wei Jia | 2afac0c | 2016-01-07 12:13:07 -0800 | [diff] [blame] | 306 | } |
Chris Watkins | 99f3160 | 2015-03-20 13:06:33 -0700 | [diff] [blame] | 307 | return NO_ERROR; |
| 308 | } break; |
James Dong | 16afe2f | 2010-12-02 17:42:08 -0800 | [diff] [blame] | 309 | case GET_FRAME_AT_TIME: { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
James Dong | 16afe2f | 2010-12-02 17:42:08 -0800 | [diff] [blame] | 311 | int64_t timeUs = data.readInt64(); |
| 312 | int option = data.readInt32(); |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 313 | int colorFormat = data.readInt32(); |
| 314 | bool metaOnly = (data.readInt32() != 0); |
| 315 | ALOGV("getTimeAtTime: time(%" PRId64 " us), option(%d), colorFormat(%d), metaOnly(%d)", |
| 316 | timeUs, option, colorFormat, metaOnly); |
Chong Zhang | 24c1577 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 317 | sp<IMemory> bitmap = getFrameAtTime(timeUs, option, colorFormat, metaOnly); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | if (bitmap != 0) { // Don't send NULL across the binder interface |
| 319 | reply->writeInt32(NO_ERROR); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 320 | reply->writeStrongBinder(IInterface::asBinder(bitmap)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | } else { |
| 322 | reply->writeInt32(UNKNOWN_ERROR); |
| 323 | } |
| 324 | return NO_ERROR; |
| 325 | } break; |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 326 | case GET_IMAGE_AT_INDEX: { |
| 327 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 328 | int index = data.readInt32(); |
| 329 | int colorFormat = data.readInt32(); |
| 330 | bool metaOnly = (data.readInt32() != 0); |
Chong Zhang | d5fa357 | 2018-04-09 19:03:10 -0700 | [diff] [blame] | 331 | bool thumbnail = (data.readInt32() != 0); |
| 332 | ALOGV("getImageAtIndex: index(%d), colorFormat(%d), metaOnly(%d), thumbnail(%d)", |
| 333 | index, colorFormat, metaOnly, thumbnail); |
Chong Zhang | d5fa357 | 2018-04-09 19:03:10 -0700 | [diff] [blame] | 334 | sp<IMemory> bitmap = getImageAtIndex(index, colorFormat, metaOnly, thumbnail); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 335 | if (bitmap != 0) { // Don't send NULL across the binder interface |
| 336 | reply->writeInt32(NO_ERROR); |
| 337 | reply->writeStrongBinder(IInterface::asBinder(bitmap)); |
| 338 | } else { |
| 339 | reply->writeInt32(UNKNOWN_ERROR); |
| 340 | } |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 341 | return NO_ERROR; |
| 342 | } break; |
Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 343 | |
| 344 | case GET_IMAGE_RECT_AT_INDEX: { |
| 345 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 346 | int index = data.readInt32(); |
| 347 | int colorFormat = data.readInt32(); |
| 348 | int left = data.readInt32(); |
| 349 | int top = data.readInt32(); |
| 350 | int right = data.readInt32(); |
| 351 | int bottom = data.readInt32(); |
| 352 | ALOGV("getImageRectAtIndex: index(%d), colorFormat(%d), rect {%d, %d, %d, %d}", |
| 353 | index, colorFormat, left, top, right, bottom); |
Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 354 | sp<IMemory> bitmap = getImageRectAtIndex( |
| 355 | index, colorFormat, left, top, right, bottom); |
| 356 | if (bitmap != 0) { // Don't send NULL across the binder interface |
| 357 | reply->writeInt32(NO_ERROR); |
| 358 | reply->writeStrongBinder(IInterface::asBinder(bitmap)); |
| 359 | } else { |
| 360 | reply->writeInt32(UNKNOWN_ERROR); |
| 361 | } |
Chong Zhang | 0c1407f | 2018-05-02 17:09:05 -0700 | [diff] [blame] | 362 | return NO_ERROR; |
| 363 | } break; |
| 364 | |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 365 | case GET_FRAME_AT_INDEX: { |
| 366 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 367 | int index = data.readInt32(); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 368 | int colorFormat = data.readInt32(); |
| 369 | bool metaOnly = (data.readInt32() != 0); |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 370 | ALOGV("getFrameAtIndex: index(%d), colorFormat(%d), metaOnly(%d)", |
| 371 | index, colorFormat, metaOnly); |
Chong Zhang | 76a49d6 | 2019-07-12 11:20:33 -0700 | [diff] [blame] | 372 | sp<IMemory> frame = getFrameAtIndex(index, colorFormat, metaOnly); |
| 373 | if (frame != nullptr) { // Don't send NULL across the binder interface |
| 374 | reply->writeInt32(NO_ERROR); |
| 375 | reply->writeStrongBinder(IInterface::asBinder(frame)); |
| 376 | } else { |
| 377 | reply->writeInt32(UNKNOWN_ERROR); |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 378 | } |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 379 | return NO_ERROR; |
| 380 | } break; |
Dave Sparks | ec4dde7 | 2009-11-23 16:51:15 -0800 | [diff] [blame] | 381 | case EXTRACT_ALBUM_ART: { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 383 | sp<IMemory> albumArt = extractAlbumArt(); |
| 384 | if (albumArt != 0) { // Don't send NULL across the binder interface |
| 385 | reply->writeInt32(NO_ERROR); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 386 | reply->writeStrongBinder(IInterface::asBinder(albumArt)); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | } else { |
| 388 | reply->writeInt32(UNKNOWN_ERROR); |
| 389 | } |
| 390 | return NO_ERROR; |
| 391 | } break; |
| 392 | case EXTRACT_METADATA: { |
| 393 | CHECK_INTERFACE(IMediaMetadataRetriever, data, reply); |
| 394 | int keyCode = data.readInt32(); |
| 395 | const char* value = extractMetadata(keyCode); |
| 396 | if (value != NULL) { // Don't send NULL across the binder interface |
| 397 | reply->writeInt32(NO_ERROR); |
| 398 | reply->writeCString(value); |
| 399 | } else { |
| 400 | reply->writeInt32(UNKNOWN_ERROR); |
| 401 | } |
| 402 | return NO_ERROR; |
| 403 | } break; |
| 404 | default: |
| 405 | return BBinder::onTransact(code, data, reply, flags); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | // ---------------------------------------------------------------------------- |
| 410 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 411 | } // namespace android |