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(Type type,int64_t value)26 MediaResource::MediaResource(Type type, int64_t value) {
27 this->type = type;
28 this->subType = SubType::kUnspecifiedSubType;
29 this->value = value;
30 }
31
MediaResource(Type type,SubType subType,int64_t value)32 MediaResource::MediaResource(Type type, SubType subType, int64_t value) {
33 this->type = type;
34 this->subType = subType;
35 this->value = value;
36 }
37
MediaResource(Type type,const std::vector<int8_t> & id,int64_t value)38 MediaResource::MediaResource(Type type, const std::vector<int8_t> &id, int64_t value) {
39 this->type = type;
40 this->subType = SubType::kUnspecifiedSubType;
41 this->id = id;
42 this->value = value;
43 }
44
45 //static
CodecResource(bool secure,bool video)46 MediaResource MediaResource::CodecResource(bool secure, bool video) {
47 return MediaResource(
48 secure ? Type::kSecureCodec : Type::kNonSecureCodec,
49 video ? SubType::kVideoCodec : SubType::kAudioCodec,
50 1);
51 }
52
53 //static
GraphicMemoryResource(int64_t value)54 MediaResource MediaResource::GraphicMemoryResource(int64_t value) {
55 return MediaResource(Type::kGraphicMemory, value);
56 }
57
58 //static
CpuBoostResource()59 MediaResource MediaResource::CpuBoostResource() {
60 return MediaResource(Type::kCpuBoost, 1);
61 }
62
63 //static
VideoBatteryResource()64 MediaResource MediaResource::VideoBatteryResource() {
65 return MediaResource(Type::kBattery, SubType::kVideoCodec, 1);
66 }
67
68 //static
DrmSessionResource(const std::vector<int8_t> & id,int64_t value)69 MediaResource MediaResource::DrmSessionResource(const std::vector<int8_t> &id, int64_t value) {
70 return MediaResource(Type::kDrmSession, id, value);
71 }
72
bytesToHexString(const std::vector<int8_t> & bytes)73 static String8 bytesToHexString(const std::vector<int8_t> &bytes) {
74 String8 str;
75 for (auto &b : bytes) {
76 str.appendFormat("%02x", b);
77 }
78 return str;
79 }
80
toString(const MediaResourceParcel & resource)81 String8 toString(const MediaResourceParcel& resource) {
82 String8 str;
83
84 str.appendFormat("%s/%s:[%s]:%lld",
85 asString(resource.type), asString(resource.subType),
86 bytesToHexString(resource.id).c_str(),
87 (long long)resource.value);
88 return str;
89 }
90
91 }; // namespace android
92