blob: 0936a99fdbaff2b85b28f3c382ecced07c141fb5 [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 Shihc3af31b2019-09-20 21:45:01 -070022#include <vector>
23
Ronghua Wu231c3d12015-03-11 15:10:32 -070024namespace android {
25
Chong Zhang181e6952019-10-09 13:23:39 -070026MediaResource::MediaResource(Type type, int64_t value) {
27 this->type = type;
28 this->subType = SubType::kUnspecifiedSubType;
29 this->value = value;
Ronghua Wu231c3d12015-03-11 15:10:32 -070030}
31
Chong Zhang181e6952019-10-09 13:23:39 -070032MediaResource::MediaResource(Type type, SubType subType, int64_t value) {
33 this->type = type;
34 this->subType = subType;
35 this->value = value;
36}
37
Chong Zhangfdd512a2019-11-22 11:03:14 -080038MediaResource::MediaResource(Type type, const std::vector<int8_t> &id, int64_t value) {
Chong Zhang181e6952019-10-09 13:23:39 -070039 this->type = type;
40 this->subType = SubType::kUnspecifiedSubType;
41 this->id = id;
42 this->value = value;
43}
44
45//static
46MediaResource 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
54MediaResource MediaResource::GraphicMemoryResource(int64_t value) {
55 return MediaResource(Type::kGraphicMemory, value);
56}
57
58//static
59MediaResource MediaResource::CpuBoostResource() {
60 return MediaResource(Type::kCpuBoost, 1);
61}
62
63//static
64MediaResource MediaResource::VideoBatteryResource() {
65 return MediaResource(Type::kBattery, SubType::kVideoCodec, 1);
66}
67
68//static
Chong Zhangfdd512a2019-11-22 11:03:14 -080069MediaResource MediaResource::DrmSessionResource(const std::vector<int8_t> &id, int64_t value) {
Chong Zhang181e6952019-10-09 13:23:39 -070070 return MediaResource(Type::kDrmSession, id, value);
Robert Shihc3af31b2019-09-20 21:45:01 -070071}
72
Chong Zhangfdd512a2019-11-22 11:03:14 -080073static String8 bytesToHexString(const std::vector<int8_t> &bytes) {
Robert Shihc3af31b2019-09-20 21:45:01 -070074 String8 str;
75 for (auto &b : bytes) {
76 str.appendFormat("%02x", b);
77 }
78 return str;
Ronghua Wu231c3d12015-03-11 15:10:32 -070079}
80
Chong Zhang181e6952019-10-09 13:23:39 -070081String8 toString(const MediaResourceParcel& resource) {
Ronghua Wu231c3d12015-03-11 15:10:32 -070082 String8 str;
Chong Zhang181e6952019-10-09 13:23:39 -070083
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);
Ronghua Wu231c3d12015-03-11 15:10:32 -070088 return str;
89}
90
Ronghua Wu231c3d12015-03-11 15:10:32 -070091}; // namespace android