Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 "MediaResource" |
| 19 | #include <utils/Log.h> |
| 20 | #include <media/MediaResource.h> |
| 21 | |
Robert Shih | 79673cf | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 24 | namespace android { |
| 25 | |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame] | 26 | MediaResource::MediaResource() |
| 27 | : mType(kUnspecified), |
| 28 | mSubType(kUnspecifiedSubType), |
| 29 | mValue(0) {} |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 30 | |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame] | 31 | MediaResource::MediaResource(Type type, uint64_t value) |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 32 | : mType(type), |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame] | 33 | mSubType(kUnspecifiedSubType), |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 34 | mValue(value) {} |
| 35 | |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame] | 36 | MediaResource::MediaResource(Type type, SubType subType, uint64_t value) |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 37 | : mType(type), |
| 38 | mSubType(subType), |
| 39 | mValue(value) {} |
| 40 | |
Robert Shih | 79673cf | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 41 | MediaResource::MediaResource(Type type, const std::vector<uint8_t> &id, uint64_t value) |
| 42 | : mType(type), |
| 43 | mSubType(kUnspecifiedSubType), |
| 44 | mValue(value), |
| 45 | mId(id) {} |
| 46 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 47 | void MediaResource::readFromParcel(const Parcel &parcel) { |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame] | 48 | mType = static_cast<Type>(parcel.readInt32()); |
| 49 | mSubType = static_cast<SubType>(parcel.readInt32()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 50 | mValue = parcel.readUint64(); |
Robert Shih | 79673cf | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 51 | parcel.readByteVector(&mId); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void MediaResource::writeToParcel(Parcel *parcel) const { |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame] | 55 | parcel->writeInt32(static_cast<int32_t>(mType)); |
| 56 | parcel->writeInt32(static_cast<int32_t>(mSubType)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 57 | parcel->writeUint64(mValue); |
Robert Shih | 79673cf | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 58 | parcel->writeByteVector(mId); |
| 59 | } |
| 60 | |
| 61 | static String8 bytesToHexString(const std::vector<uint8_t> &bytes) { |
| 62 | String8 str; |
| 63 | for (auto &b : bytes) { |
| 64 | str.appendFormat("%02x", b); |
| 65 | } |
| 66 | return str; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | String8 MediaResource::toString() const { |
| 70 | String8 str; |
Robert Shih | 79673cf | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 71 | str.appendFormat("%s/%s:[%s]:%llu", |
| 72 | asString(mType), asString(mSubType), |
| 73 | bytesToHexString(mId).c_str(), |
| 74 | (unsigned long long)mValue); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 75 | return str; |
| 76 | } |
| 77 | |
| 78 | bool MediaResource::operator==(const MediaResource &other) const { |
Robert Shih | 79673cf | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 79 | return (other.mType == mType) |
| 80 | && (other.mSubType == mSubType) |
| 81 | && (other.mValue == mValue) |
| 82 | && (other.mId == mId); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | bool MediaResource::operator!=(const MediaResource &other) const { |
| 86 | return !(*this == other); |
| 87 | } |
| 88 | |
| 89 | }; // namespace android |