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 | |
| 22 | namespace android { |
| 23 | |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame^] | 24 | MediaResource::MediaResource() |
| 25 | : mType(kUnspecified), |
| 26 | mSubType(kUnspecifiedSubType), |
| 27 | mValue(0) {} |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 28 | |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame^] | 29 | MediaResource::MediaResource(Type type, uint64_t value) |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 30 | : mType(type), |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame^] | 31 | mSubType(kUnspecifiedSubType), |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 32 | mValue(value) {} |
| 33 | |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame^] | 34 | MediaResource::MediaResource(Type type, SubType subType, uint64_t value) |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 35 | : mType(type), |
| 36 | mSubType(subType), |
| 37 | mValue(value) {} |
| 38 | |
| 39 | void MediaResource::readFromParcel(const Parcel &parcel) { |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame^] | 40 | mType = static_cast<Type>(parcel.readInt32()); |
| 41 | mSubType = static_cast<SubType>(parcel.readInt32()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 42 | mValue = parcel.readUint64(); |
| 43 | } |
| 44 | |
| 45 | void MediaResource::writeToParcel(Parcel *parcel) const { |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame^] | 46 | parcel->writeInt32(static_cast<int32_t>(mType)); |
| 47 | parcel->writeInt32(static_cast<int32_t>(mSubType)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 48 | parcel->writeUint64(mValue); |
| 49 | } |
| 50 | |
| 51 | String8 MediaResource::toString() const { |
| 52 | String8 str; |
Ronghua Wu | ea15fd2 | 2016-03-03 13:35:05 -0800 | [diff] [blame^] | 53 | str.appendFormat("%s/%s:%llu", asString(mType), asString(mSubType), (unsigned long long)mValue); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 54 | return str; |
| 55 | } |
| 56 | |
| 57 | bool MediaResource::operator==(const MediaResource &other) const { |
| 58 | return (other.mType == mType) && (other.mSubType == mSubType) && (other.mValue == mValue); |
| 59 | } |
| 60 | |
| 61 | bool MediaResource::operator!=(const MediaResource &other) const { |
| 62 | return !(*this == other); |
| 63 | } |
| 64 | |
| 65 | }; // namespace android |