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 #include <vector>
23
24 namespace android {
25
MediaResource()26 MediaResource::MediaResource()
27 : mType(kUnspecified),
28 mSubType(kUnspecifiedSubType),
29 mValue(0) {}
30
MediaResource(Type type,uint64_t value)31 MediaResource::MediaResource(Type type, uint64_t value)
32 : mType(type),
33 mSubType(kUnspecifiedSubType),
34 mValue(value) {}
35
MediaResource(Type type,SubType subType,uint64_t value)36 MediaResource::MediaResource(Type type, SubType subType, uint64_t value)
37 : mType(type),
38 mSubType(subType),
39 mValue(value) {}
40
MediaResource(Type type,const std::vector<uint8_t> & id,uint64_t value)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
readFromParcel(const Parcel & parcel)47 void MediaResource::readFromParcel(const Parcel &parcel) {
48 mType = static_cast<Type>(parcel.readInt32());
49 mSubType = static_cast<SubType>(parcel.readInt32());
50 mValue = parcel.readUint64();
51 parcel.readByteVector(&mId);
52 }
53
writeToParcel(Parcel * parcel) const54 void MediaResource::writeToParcel(Parcel *parcel) const {
55 parcel->writeInt32(static_cast<int32_t>(mType));
56 parcel->writeInt32(static_cast<int32_t>(mSubType));
57 parcel->writeUint64(mValue);
58 parcel->writeByteVector(mId);
59 }
60
bytesToHexString(const std::vector<uint8_t> & bytes)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;
67 }
68
toString() const69 String8 MediaResource::toString() const {
70 String8 str;
71 str.appendFormat("%s/%s:[%s]:%llu",
72 asString(mType), asString(mSubType),
73 bytesToHexString(mId).c_str(),
74 (unsigned long long)mValue);
75 return str;
76 }
77
operator ==(const MediaResource & other) const78 bool MediaResource::operator==(const MediaResource &other) const {
79 return (other.mType == mType)
80 && (other.mSubType == mSubType)
81 && (other.mValue == mValue)
82 && (other.mId == mId);
83 }
84
operator !=(const MediaResource & other) const85 bool MediaResource::operator!=(const MediaResource &other) const {
86 return !(*this == other);
87 }
88
89 }; // namespace android
90