| 61 | } |
| 62 | |
| 63 | int cachedSource::Open(int flags) |
| 64 | { |
| 65 | std::lock_guard<std::mutex> uMutex(mMutex); |
| 66 | |
| 67 | if (mIsOpen) { |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | mDataSource->Set_config(mSourceConfig); |
| 72 | int ret = mDataSource->Open(flags); |
| 73 | |
| 74 | if (ret < 0) { |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | mFileSize = mDataSource->Seek(0, SEEK_SIZE); |
| 79 | |
| 80 | if (mFileSize <= 0) { |
| 81 | AF_LOGE("unknown file size can't cache"); |
| 82 | return -1; |
| 83 | } |
| 84 | |
| 85 | mIsOpen = true; |
| 86 | |
| 87 | if (mMaxUsedBufferSize == 0) { |
| 88 | mMaxUsedBufferSize = mFileSize; |
| 89 | } |
| 90 | |
| 91 | // std::lock_guard<std::mutex> uMutex(mMutex); |
| 92 | if (mBufferSource) { |
| 93 | delete mBufferSource; |
| 94 | } |
| 95 | |
| 96 | mBufferSource = new sliceBufferSource((uint64_t) ISliceManager::getManager().getSliceSize(), mMaxUsedBufferSize, |
| 97 | (uint64_t) mFileSize, *this, mSliceManager); |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | void cachedSource::Interrupt(bool bInterrput) |
| 102 | { |