blob: 1bcb4b93fa68b299dde6d79a31ca49df6af5293f [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
Jooyung Hancfca1162020-02-22 00:46:06 +090038MediaResource::MediaResource(Type type, const std::vector<uint8_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
Brian Lindahla88d90c2022-01-17 10:38:35 +010046MediaResource MediaResource::CodecResource(bool secure, SubType subType, int64_t instanceCount) {
Chong Zhang181e6952019-10-09 13:23:39 -070047 return MediaResource(
48 secure ? Type::kSecureCodec : Type::kNonSecureCodec,
Brian Lindahla88d90c2022-01-17 10:38:35 +010049 subType,
Chong Zhanga9d45c72020-09-09 12:41:17 -070050 instanceCount);
Chong Zhang181e6952019-10-09 13:23:39 -070051}
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
Girisha5a2d672023-09-20 18:40:20 +000064MediaResource MediaResource::VideoBatteryResource(bool isHardware) {
65 SubType subType = isHardware ? SubType::kHwVideoCodec : SubType::kSwVideoCodec;
66 return MediaResource(Type::kBattery, subType, 1);
Chong Zhang181e6952019-10-09 13:23:39 -070067}
68
69//static
Jooyung Hancfca1162020-02-22 00:46:06 +090070MediaResource MediaResource::DrmSessionResource(const std::vector<uint8_t> &id, int64_t value) {
Chong Zhang181e6952019-10-09 13:23:39 -070071 return MediaResource(Type::kDrmSession, id, value);
Robert Shihc3af31b2019-09-20 21:45:01 -070072}
73
Jooyung Hancfca1162020-02-22 00:46:06 +090074static String8 bytesToHexString(const std::vector<uint8_t> &bytes) {
Robert Shihc3af31b2019-09-20 21:45:01 -070075 String8 str;
76 for (auto &b : bytes) {
77 str.appendFormat("%02x", b);
78 }
79 return str;
Ronghua Wu231c3d12015-03-11 15:10:32 -070080}
81
Chong Zhang181e6952019-10-09 13:23:39 -070082String8 toString(const MediaResourceParcel& resource) {
Ronghua Wu231c3d12015-03-11 15:10:32 -070083 String8 str;
Chong Zhang181e6952019-10-09 13:23:39 -070084
85 str.appendFormat("%s/%s:[%s]:%lld",
86 asString(resource.type), asString(resource.subType),
87 bytesToHexString(resource.id).c_str(),
88 (long long)resource.value);
Ronghua Wu231c3d12015-03-11 15:10:32 -070089 return str;
90}
91
Ronghua Wu231c3d12015-03-11 15:10:32 -070092}; // namespace android