Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "BpMediaSource" |
| 19 | #include <utils/Log.h> |
| 20 | |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 21 | #include <inttypes.h> |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 22 | #include <stdint.h> |
| 23 | #include <sys/types.h> |
| 24 | |
| 25 | #include <binder/Parcel.h> |
| 26 | #include <media/IMediaSource.h> |
| 27 | #include <media/stagefright/MediaBuffer.h> |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 28 | #include <media/stagefright/MediaBufferGroup.h> |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 29 | #include <media/stagefright/MediaSource.h> |
| 30 | #include <media/stagefright/MetaData.h> |
| 31 | |
| 32 | namespace android { |
| 33 | |
| 34 | enum { |
| 35 | START = IBinder::FIRST_CALL_TRANSACTION, |
| 36 | STOP, |
| 37 | PAUSE, |
| 38 | GETFORMAT, |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 39 | READ, |
Wei Jia | 1f1fc45 | 2016-05-11 16:17:22 -0700 | [diff] [blame] | 40 | READMULTIPLE, |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 41 | RELEASE_BUFFER |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 44 | enum { |
| 45 | NULL_BUFFER, |
| 46 | SHARED_BUFFER, |
| 47 | INLINE_BUFFER |
| 48 | }; |
| 49 | |
| 50 | class RemoteMediaBufferReleaser : public BBinder { |
| 51 | public: |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 52 | RemoteMediaBufferReleaser(MediaBuffer *buf, sp<BnMediaSource> owner) { |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 53 | mBuf = buf; |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 54 | mOwner = owner; |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 55 | } |
| 56 | ~RemoteMediaBufferReleaser() { |
| 57 | if (mBuf) { |
| 58 | ALOGW("RemoteMediaBufferReleaser dtor called while still holding buffer"); |
| 59 | mBuf->release(); |
| 60 | } |
| 61 | } |
| 62 | virtual status_t onTransact( uint32_t code, |
| 63 | const Parcel& data, |
| 64 | Parcel* reply, |
| 65 | uint32_t flags = 0) { |
| 66 | if (code == RELEASE_BUFFER) { |
| 67 | mBuf->release(); |
| 68 | mBuf = NULL; |
| 69 | return OK; |
| 70 | } else { |
| 71 | return BBinder::onTransact(code, data, reply, flags); |
| 72 | } |
| 73 | } |
| 74 | private: |
| 75 | MediaBuffer *mBuf; |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 76 | // Keep a ref to ensure MediaBuffer is released before the owner, i.e., BnMediaSource, |
| 77 | // because BnMediaSource needs to delete MediaBufferGroup in its dtor and |
| 78 | // MediaBufferGroup dtor requires all MediaBuffer's have 0 ref count. |
| 79 | sp<BnMediaSource> mOwner; |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | |
| 83 | class RemoteMediaBufferWrapper : public MediaBuffer { |
| 84 | public: |
| 85 | RemoteMediaBufferWrapper(sp<IMemory> mem, sp<IBinder> source); |
| 86 | protected: |
| 87 | virtual ~RemoteMediaBufferWrapper(); |
| 88 | private: |
| 89 | sp<IMemory> mMemory; |
| 90 | sp<IBinder> mRemoteSource; |
| 91 | }; |
| 92 | |
| 93 | RemoteMediaBufferWrapper::RemoteMediaBufferWrapper(sp<IMemory> mem, sp<IBinder> source) |
| 94 | : MediaBuffer(mem->pointer(), mem->size()) { |
| 95 | mMemory = mem; |
| 96 | mRemoteSource = source; |
| 97 | } |
| 98 | |
| 99 | RemoteMediaBufferWrapper::~RemoteMediaBufferWrapper() { |
| 100 | mMemory.clear(); |
| 101 | // Explicitly ask the remote side to release the buffer. We could also just clear |
| 102 | // mRemoteSource, but that doesn't immediately release the reference on the remote side. |
| 103 | Parcel data, reply; |
| 104 | mRemoteSource->transact(RELEASE_BUFFER, data, &reply); |
| 105 | mRemoteSource.clear(); |
| 106 | } |
| 107 | |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 108 | class BpMediaSource : public BpInterface<IMediaSource> { |
| 109 | public: |
| 110 | BpMediaSource(const sp<IBinder>& impl) |
| 111 | : BpInterface<IMediaSource>(impl) |
| 112 | { |
| 113 | } |
| 114 | |
| 115 | virtual status_t start(MetaData *params) { |
| 116 | ALOGV("start"); |
| 117 | Parcel data, reply; |
| 118 | data.writeInterfaceToken(BpMediaSource::getInterfaceDescriptor()); |
| 119 | if (params) { |
| 120 | params->writeToParcel(data); |
| 121 | } |
| 122 | status_t ret = remote()->transact(START, data, &reply); |
| 123 | if (ret == NO_ERROR && params) { |
| 124 | ALOGW("ignoring potentially modified MetaData from start"); |
| 125 | ALOGW("input:"); |
| 126 | params->dumpToLog(); |
| 127 | sp<MetaData> meta = MetaData::createFromParcel(reply); |
| 128 | ALOGW("output:"); |
| 129 | meta->dumpToLog(); |
| 130 | } |
| 131 | return ret; |
| 132 | } |
| 133 | |
| 134 | virtual status_t stop() { |
| 135 | ALOGV("stop"); |
| 136 | Parcel data, reply; |
| 137 | data.writeInterfaceToken(BpMediaSource::getInterfaceDescriptor()); |
| 138 | return remote()->transact(STOP, data, &reply); |
| 139 | } |
| 140 | |
| 141 | virtual sp<MetaData> getFormat() { |
| 142 | ALOGV("getFormat"); |
| 143 | Parcel data, reply; |
| 144 | data.writeInterfaceToken(BpMediaSource::getInterfaceDescriptor()); |
| 145 | status_t ret = remote()->transact(GETFORMAT, data, &reply); |
| 146 | if (ret == NO_ERROR) { |
| 147 | mMetaData = MetaData::createFromParcel(reply); |
| 148 | return mMetaData; |
| 149 | } |
| 150 | return NULL; |
| 151 | } |
| 152 | |
| 153 | virtual status_t read(MediaBuffer **buffer, const ReadOptions *options) { |
| 154 | ALOGV("read"); |
| 155 | Parcel data, reply; |
| 156 | data.writeInterfaceToken(BpMediaSource::getInterfaceDescriptor()); |
| 157 | if (options) { |
| 158 | data.writeByteArray(sizeof(*options), (uint8_t*) options); |
| 159 | } |
| 160 | status_t ret = remote()->transact(READ, data, &reply); |
| 161 | if (ret != NO_ERROR) { |
| 162 | return ret; |
| 163 | } |
| 164 | // wrap the returned data in a MediaBuffer |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 165 | ret = reply.readInt32(); |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 166 | int32_t buftype = reply.readInt32(); |
| 167 | if (buftype == SHARED_BUFFER) { |
| 168 | sp<IBinder> remote = reply.readStrongBinder(); |
| 169 | sp<IBinder> binder = reply.readStrongBinder(); |
| 170 | sp<IMemory> mem = interface_cast<IMemory>(binder); |
| 171 | if (mem == NULL) { |
| 172 | ALOGE("received NULL IMemory for shared buffer"); |
| 173 | } |
| 174 | size_t offset = reply.readInt32(); |
| 175 | size_t length = reply.readInt32(); |
| 176 | MediaBuffer *buf = new RemoteMediaBufferWrapper(mem, remote); |
| 177 | buf->set_range(offset, length); |
| 178 | buf->meta_data()->updateFromParcel(reply); |
| 179 | *buffer = buf; |
| 180 | } else if (buftype == NULL_BUFFER) { |
| 181 | ALOGV("got status %d and NULL buffer", ret); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 182 | *buffer = NULL; |
| 183 | } else { |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 184 | int32_t len = reply.readInt32(); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 185 | ALOGV("got status %d and len %d", ret, len); |
| 186 | *buffer = new MediaBuffer(len); |
| 187 | reply.read((*buffer)->data(), len); |
| 188 | (*buffer)->meta_data()->updateFromParcel(reply); |
| 189 | } |
| 190 | return ret; |
| 191 | } |
| 192 | |
Wei Jia | 1f1fc45 | 2016-05-11 16:17:22 -0700 | [diff] [blame] | 193 | virtual status_t readMultiple(Vector<MediaBuffer *> *buffers, uint32_t maxNumBuffers) { |
| 194 | ALOGV("readMultiple"); |
| 195 | if (buffers == NULL || !buffers->isEmpty()) { |
| 196 | return BAD_VALUE; |
| 197 | } |
| 198 | Parcel data, reply; |
| 199 | data.writeInterfaceToken(BpMediaSource::getInterfaceDescriptor()); |
| 200 | data.writeUint32(maxNumBuffers); |
| 201 | status_t ret = remote()->transact(READMULTIPLE, data, &reply); |
| 202 | if (ret != NO_ERROR) { |
| 203 | return ret; |
| 204 | } |
| 205 | // wrap the returned data in a vector of MediaBuffers |
| 206 | int32_t bufCount = 0; |
| 207 | while (1) { |
| 208 | if (reply.readInt32() == 0) { |
| 209 | break; |
| 210 | } |
| 211 | int32_t len = reply.readInt32(); |
| 212 | ALOGV("got len %d", len); |
| 213 | MediaBuffer *buf = new MediaBuffer(len); |
| 214 | reply.read(buf->data(), len); |
| 215 | buf->meta_data()->updateFromParcel(reply); |
| 216 | buffers->push_back(buf); |
| 217 | ++bufCount; |
| 218 | } |
| 219 | ret = reply.readInt32(); |
| 220 | ALOGV("got status %d, bufCount %d", ret, bufCount); |
| 221 | return ret; |
| 222 | } |
| 223 | |
Wei Jia | d3f4e14 | 2016-06-13 14:51:43 -0700 | [diff] [blame] | 224 | bool supportReadMultiple() { |
| 225 | return true; |
| 226 | } |
| 227 | |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 228 | virtual status_t pause() { |
| 229 | ALOGV("pause"); |
| 230 | Parcel data, reply; |
| 231 | data.writeInterfaceToken(BpMediaSource::getInterfaceDescriptor()); |
| 232 | return remote()->transact(PAUSE, data, &reply); |
| 233 | } |
| 234 | |
| 235 | virtual status_t setBuffers(const Vector<MediaBuffer *> & buffers __unused) { |
| 236 | ALOGV("setBuffers NOT IMPLEMENTED"); |
| 237 | return ERROR_UNSUPPORTED; // default |
| 238 | } |
| 239 | |
| 240 | private: |
| 241 | // NuPlayer passes pointers-to-metadata around, so we use this to keep the metadata alive |
| 242 | // XXX: could we use this for caching, or does metadata change on the fly? |
| 243 | sp<MetaData> mMetaData; |
Marco Nelissen | e7d8e71 | 2016-03-14 09:29:42 -0700 | [diff] [blame] | 244 | |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | IMPLEMENT_META_INTERFACE(MediaSource, "android.media.IMediaSource"); |
| 248 | |
| 249 | #undef LOG_TAG |
| 250 | #define LOG_TAG "BnMediaSource" |
| 251 | |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 252 | BnMediaSource::BnMediaSource() |
| 253 | : mGroup(NULL) { |
| 254 | } |
| 255 | |
| 256 | BnMediaSource::~BnMediaSource() { |
| 257 | delete mGroup; |
| 258 | mGroup = NULL; |
| 259 | } |
| 260 | |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 261 | status_t BnMediaSource::onTransact( |
| 262 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 263 | { |
| 264 | switch (code) { |
| 265 | case START: { |
| 266 | ALOGV("start"); |
| 267 | CHECK_INTERFACE(IMediaSource, data, reply); |
| 268 | sp<MetaData> meta; |
| 269 | if (data.dataAvail()) { |
| 270 | meta = MetaData::createFromParcel(data); |
| 271 | } |
| 272 | status_t ret = start(meta.get()); |
| 273 | if (ret == NO_ERROR && meta != NULL) { |
| 274 | meta->writeToParcel(*reply); |
| 275 | } |
| 276 | return ret; |
| 277 | } |
| 278 | case STOP: { |
| 279 | ALOGV("stop"); |
| 280 | CHECK_INTERFACE(IMediaSource, data, reply); |
| 281 | return stop(); |
| 282 | } |
| 283 | case PAUSE: { |
| 284 | ALOGV("pause"); |
| 285 | CHECK_INTERFACE(IMediaSource, data, reply); |
| 286 | return pause(); |
| 287 | } |
| 288 | case GETFORMAT: { |
| 289 | ALOGV("getFormat"); |
| 290 | CHECK_INTERFACE(IMediaSource, data, reply); |
| 291 | sp<MetaData> meta = getFormat(); |
| 292 | if (meta != NULL) { |
| 293 | meta->writeToParcel(*reply); |
| 294 | return NO_ERROR; |
| 295 | } |
| 296 | return UNKNOWN_ERROR; |
| 297 | } |
| 298 | case READ: { |
| 299 | ALOGV("read"); |
| 300 | CHECK_INTERFACE(IMediaSource, data, reply); |
| 301 | status_t ret; |
| 302 | MediaBuffer *buf = NULL; |
| 303 | ReadOptions opts; |
| 304 | uint32_t len; |
| 305 | if (data.readUint32(&len) == NO_ERROR && |
| 306 | len == sizeof(opts) && data.read((void*)&opts, len) == NO_ERROR) { |
| 307 | ret = read(&buf, &opts); |
| 308 | } else { |
| 309 | ret = read(&buf, NULL); |
| 310 | } |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 311 | |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 312 | reply->writeInt32(ret); |
| 313 | if (buf != NULL) { |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 314 | size_t usedSize = buf->range_length(); |
| 315 | // even if we're using shared memory, we might not want to use it, since for small |
| 316 | // sizes it's faster to copy data through the Binder transaction |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 317 | // On the other hand, if the data size is large enough, it's better to use shared |
| 318 | // memory. When data is too large, binder can't handle it. |
| 319 | if (usedSize >= MediaBuffer::kSharedMemThreshold) { |
| 320 | ALOGV("use shared memory: %zu", usedSize); |
| 321 | |
| 322 | MediaBuffer *transferBuf = buf; |
| 323 | size_t offset = buf->range_offset(); |
| 324 | if (transferBuf->mMemory == NULL) { |
| 325 | if (mGroup == NULL) { |
| 326 | mGroup = new MediaBufferGroup; |
| 327 | size_t allocateSize = usedSize; |
| 328 | if (usedSize < SIZE_MAX / 3) { |
| 329 | allocateSize = usedSize * 3 / 2; |
| 330 | } |
| 331 | mGroup->add_buffer(new MediaBuffer(allocateSize)); |
| 332 | } |
| 333 | |
Wei Jia | 027b811 | 2016-04-04 09:50:14 -0700 | [diff] [blame] | 334 | MediaBuffer *newBuf = NULL; |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 335 | ret = mGroup->acquire_buffer( |
Wei Jia | 027b811 | 2016-04-04 09:50:14 -0700 | [diff] [blame] | 336 | &newBuf, false /* nonBlocking */, usedSize); |
| 337 | if (ret != OK || newBuf == NULL || newBuf->mMemory == NULL) { |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 338 | ALOGW("failed to acquire shared memory, ret %d", ret); |
Wei Jia | 027b811 | 2016-04-04 09:50:14 -0700 | [diff] [blame] | 339 | buf->release(); |
| 340 | if (newBuf != NULL) { |
| 341 | newBuf->release(); |
| 342 | } |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 343 | reply->writeInt32(NULL_BUFFER); |
| 344 | return NO_ERROR; |
| 345 | } |
Wei Jia | 027b811 | 2016-04-04 09:50:14 -0700 | [diff] [blame] | 346 | transferBuf = newBuf; |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 347 | memcpy(transferBuf->data(), (uint8_t*)buf->data() + buf->range_offset(), |
| 348 | buf->range_length()); |
| 349 | offset = 0; |
| 350 | } |
| 351 | |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 352 | reply->writeInt32(SHARED_BUFFER); |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 353 | RemoteMediaBufferReleaser *wrapper = |
| 354 | new RemoteMediaBufferReleaser(transferBuf, this); |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 355 | reply->writeStrongBinder(wrapper); |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 356 | reply->writeStrongBinder(IInterface::asBinder(transferBuf->mMemory)); |
| 357 | reply->writeInt32(offset); |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 358 | reply->writeInt32(usedSize); |
| 359 | buf->meta_data()->writeToParcel(*reply); |
Wei Jia | 1d5a306 | 2016-02-29 09:47:27 -0800 | [diff] [blame] | 360 | if (buf->mMemory == NULL) { |
| 361 | buf->release(); |
| 362 | } |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 363 | } else { |
Wei Jia | e9a5b96 | 2016-02-12 11:38:27 -0800 | [diff] [blame] | 364 | // buffer is small: copy it |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 365 | if (buf->mMemory != NULL) { |
| 366 | ALOGV("%zu shared mem available, but only %zu used", buf->mMemory->size(), buf->range_length()); |
| 367 | } |
| 368 | reply->writeInt32(INLINE_BUFFER); |
| 369 | reply->writeByteArray(buf->range_length(), (uint8_t*)buf->data() + buf->range_offset()); |
| 370 | buf->meta_data()->writeToParcel(*reply); |
| 371 | buf->release(); |
| 372 | } |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 373 | } else { |
| 374 | ALOGV("ret %d, buf %p", ret, buf); |
Marco Nelissen | b65990f | 2015-11-09 15:39:49 -0800 | [diff] [blame] | 375 | reply->writeInt32(NULL_BUFFER); |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 376 | } |
| 377 | return NO_ERROR; |
| 378 | } |
Wei Jia | 1f1fc45 | 2016-05-11 16:17:22 -0700 | [diff] [blame] | 379 | case READMULTIPLE: { |
| 380 | ALOGV("readmultiple"); |
| 381 | CHECK_INTERFACE(IMediaSource, data, reply); |
| 382 | uint32_t maxNumBuffers; |
| 383 | data.readUint32(&maxNumBuffers); |
| 384 | status_t ret = NO_ERROR; |
| 385 | uint32_t bufferCount = 0; |
| 386 | if (maxNumBuffers > kMaxNumReadMultiple) { |
| 387 | maxNumBuffers = kMaxNumReadMultiple; |
| 388 | } |
| 389 | while (bufferCount < maxNumBuffers) { |
| 390 | if (reply->dataSize() >= MediaBuffer::kSharedMemThreshold) { |
| 391 | break; |
| 392 | } |
| 393 | |
| 394 | MediaBuffer *buf = NULL; |
| 395 | ret = read(&buf, NULL); |
| 396 | if (ret != NO_ERROR || buf == NULL) { |
| 397 | break; |
| 398 | } |
| 399 | ++bufferCount; |
| 400 | reply->writeInt32(1); // indicate one more MediaBuffer. |
| 401 | reply->writeByteArray( |
| 402 | buf->range_length(), (uint8_t*)buf->data() + buf->range_offset()); |
| 403 | buf->meta_data()->writeToParcel(*reply); |
| 404 | buf->release(); |
| 405 | } |
| 406 | reply->writeInt32(0); // indicate no more MediaBuffer. |
| 407 | reply->writeInt32(ret); |
| 408 | return NO_ERROR; |
| 409 | } |
Marco Nelissen | b2487f0 | 2015-09-01 13:23:23 -0700 | [diff] [blame] | 410 | default: |
| 411 | return BBinder::onTransact(code, data, reply, flags); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | //////////////////////////////////////////////////////////////////////////////// |
| 416 | |
| 417 | IMediaSource::ReadOptions::ReadOptions() { |
| 418 | reset(); |
| 419 | } |
| 420 | |
| 421 | void IMediaSource::ReadOptions::reset() { |
| 422 | mOptions = 0; |
| 423 | mSeekTimeUs = 0; |
| 424 | mLatenessUs = 0; |
| 425 | mNonBlocking = false; |
| 426 | } |
| 427 | |
| 428 | void IMediaSource::ReadOptions::setNonBlocking() { |
| 429 | mNonBlocking = true; |
| 430 | } |
| 431 | |
| 432 | void IMediaSource::ReadOptions::clearNonBlocking() { |
| 433 | mNonBlocking = false; |
| 434 | } |
| 435 | |
| 436 | bool IMediaSource::ReadOptions::getNonBlocking() const { |
| 437 | return mNonBlocking; |
| 438 | } |
| 439 | |
| 440 | void IMediaSource::ReadOptions::setSeekTo(int64_t time_us, SeekMode mode) { |
| 441 | mOptions |= kSeekTo_Option; |
| 442 | mSeekTimeUs = time_us; |
| 443 | mSeekMode = mode; |
| 444 | } |
| 445 | |
| 446 | void IMediaSource::ReadOptions::clearSeekTo() { |
| 447 | mOptions &= ~kSeekTo_Option; |
| 448 | mSeekTimeUs = 0; |
| 449 | mSeekMode = SEEK_CLOSEST_SYNC; |
| 450 | } |
| 451 | |
| 452 | bool IMediaSource::ReadOptions::getSeekTo( |
| 453 | int64_t *time_us, SeekMode *mode) const { |
| 454 | *time_us = mSeekTimeUs; |
| 455 | *mode = mSeekMode; |
| 456 | return (mOptions & kSeekTo_Option) != 0; |
| 457 | } |
| 458 | |
| 459 | void IMediaSource::ReadOptions::setLateBy(int64_t lateness_us) { |
| 460 | mLatenessUs = lateness_us; |
| 461 | } |
| 462 | |
| 463 | int64_t IMediaSource::ReadOptions::getLateBy() const { |
| 464 | return mLatenessUs; |
| 465 | } |
| 466 | |
| 467 | |
| 468 | } // namespace android |
| 469 | |