blob: 86260094801150f380bf05214d217bfc829346a1 [file] [log] [blame]
Ronghua Wu231c3d12015-03-11 15:10:32 -07001/*
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 Shih79673cf2019-09-20 21:45:01 -070022#include <vector>
23
Ronghua Wu231c3d12015-03-11 15:10:32 -070024namespace android {
25
Ronghua Wuea15fd22016-03-03 13:35:05 -080026MediaResource::MediaResource()
27 : mType(kUnspecified),
28 mSubType(kUnspecifiedSubType),
29 mValue(0) {}
Ronghua Wu231c3d12015-03-11 15:10:32 -070030
Ronghua Wuea15fd22016-03-03 13:35:05 -080031MediaResource::MediaResource(Type type, uint64_t value)
Ronghua Wu231c3d12015-03-11 15:10:32 -070032 : mType(type),
Ronghua Wuea15fd22016-03-03 13:35:05 -080033 mSubType(kUnspecifiedSubType),
Ronghua Wu231c3d12015-03-11 15:10:32 -070034 mValue(value) {}
35
Ronghua Wuea15fd22016-03-03 13:35:05 -080036MediaResource::MediaResource(Type type, SubType subType, uint64_t value)
Ronghua Wu231c3d12015-03-11 15:10:32 -070037 : mType(type),
38 mSubType(subType),
39 mValue(value) {}
40
Robert Shih79673cf2019-09-20 21:45:01 -070041MediaResource::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 Wu231c3d12015-03-11 15:10:32 -070047void MediaResource::readFromParcel(const Parcel &parcel) {
Ronghua Wuea15fd22016-03-03 13:35:05 -080048 mType = static_cast<Type>(parcel.readInt32());
49 mSubType = static_cast<SubType>(parcel.readInt32());
Ronghua Wu231c3d12015-03-11 15:10:32 -070050 mValue = parcel.readUint64();
Robert Shih79673cf2019-09-20 21:45:01 -070051 parcel.readByteVector(&mId);
Ronghua Wu231c3d12015-03-11 15:10:32 -070052}
53
54void MediaResource::writeToParcel(Parcel *parcel) const {
Ronghua Wuea15fd22016-03-03 13:35:05 -080055 parcel->writeInt32(static_cast<int32_t>(mType));
56 parcel->writeInt32(static_cast<int32_t>(mSubType));
Ronghua Wu231c3d12015-03-11 15:10:32 -070057 parcel->writeUint64(mValue);
Robert Shih79673cf2019-09-20 21:45:01 -070058 parcel->writeByteVector(mId);
59}
60
61static 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 Wu231c3d12015-03-11 15:10:32 -070067}
68
69String8 MediaResource::toString() const {
70 String8 str;
Robert Shih79673cf2019-09-20 21:45:01 -070071 str.appendFormat("%s/%s:[%s]:%llu",
72 asString(mType), asString(mSubType),
73 bytesToHexString(mId).c_str(),
74 (unsigned long long)mValue);
Ronghua Wu231c3d12015-03-11 15:10:32 -070075 return str;
76}
77
78bool MediaResource::operator==(const MediaResource &other) const {
Robert Shih79673cf2019-09-20 21:45:01 -070079 return (other.mType == mType)
80 && (other.mSubType == mSubType)
81 && (other.mValue == mValue)
82 && (other.mId == mId);
Ronghua Wu231c3d12015-03-11 15:10:32 -070083}
84
85bool MediaResource::operator!=(const MediaResource &other) const {
86 return !(*this == other);
87}
88
89}; // namespace android