| 38 | } |
| 39 | |
| 40 | int BiDataSource::Open(int flags) |
| 41 | { |
| 42 | vector<string> strs = CicadaUtils::split(mUri.substr(strlen(header)), ':'); |
| 43 | |
| 44 | if (strs.size() < 2) { |
| 45 | return -EINVAL; |
| 46 | } |
| 47 | |
| 48 | if (strs.size() >= 3) { |
| 49 | fileSize = atoll(strs[2].c_str()); |
| 50 | } |
| 51 | for (int i = 0; i < 2; ++i) { |
| 52 | unique_ptr<source> pSource = unique_ptr<source>(new source()); |
| 53 | pSource->mUri = CicadaUtils::base64dec(strs[i]); |
| 54 | pSource->mDataSource = unique_ptr<IDataSource>(dataSourcePrototype::create(pSource->mUri,mOpts)); |
| 55 | if (pSource->mDataSource->getSpeedLevel() == speedLevel_local) { |
| 56 | int ret = pSource->mDataSource->Open(0); |
| 57 | if (ret >= 0) { |
| 58 | int64_t size = pSource->mDataSource->Seek(0, SEEK_SIZE); |
| 59 | if (size > 0) { |
| 60 | pSource->mRange.end = static_cast<uint64_t>(size); |
| 61 | } |
| 62 | pSource->mIsOpened = true; |
| 63 | addSource(pSource); |
| 64 | } |
| 65 | } else { |
| 66 | addSource(pSource); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | assert(!mSources.empty()); |
| 71 | if (mSources.empty()) |
| 72 | return -EINVAL; |
| 73 | if (mSources.size() == 1) { |
| 74 | assert(mSources[0]->mDataSource->getSpeedLevel() != speedLevel_local); |
| 75 | if (mSources[0]->mDataSource->getSpeedLevel() == speedLevel_local) { |
| 76 | return -EINVAL; |
| 77 | } |
| 78 | |
| 79 | if (!mSources[0]->mIsOpened) { |
| 80 | int ret = mSources[0]->mDataSource->Open(0); |
| 81 | if (ret < 0) { |
| 82 | AF_LOGE("open source error %0x\n", ret); |
| 83 | std::unique_lock<std::mutex> uMutex(mSourceMutex); |
| 84 | mSources.erase(mSources.begin()); |
| 85 | return ret; |
| 86 | } |
| 87 | mSources[0]->mIsOpened = true; |
| 88 | } |
| 89 | |
| 90 | mCurrent = mSources[0].get(); |
| 91 | |
| 92 | fileSize = mCurrent->mDataSource->Seek(0, SEEK_SIZE); |
| 93 | } else { |
| 94 | if (mSources[0]->mDataSource->getSpeedLevel() == speedLevel_local) |
| 95 | mCurrent = mSources[0].get(); |
| 96 | else |
| 97 | mCurrent = mSources[1].get(); |
no test coverage detected