Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 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 | |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 24 | namespace android { |
| 25 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 26 | MediaResource::MediaResource(Type type, int64_t value) { |
| 27 | this->type = type; |
| 28 | this->subType = SubType::kUnspecifiedSubType; |
| 29 | this->value = value; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 32 | MediaResource::MediaResource(Type type, SubType subType, int64_t value) { |
| 33 | this->type = type; |
| 34 | this->subType = subType; |
| 35 | this->value = value; |
| 36 | } |
| 37 | |
Jooyung Han | 3d564ff | 2020-02-22 00:46:06 +0900 | [diff] [blame] | 38 | MediaResource::MediaResource(Type type, const std::vector<uint8_t> &id, int64_t value) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 39 | this->type = type; |
| 40 | this->subType = SubType::kUnspecifiedSubType; |
| 41 | this->id = id; |
| 42 | this->value = value; |
| 43 | } |
| 44 | |
| 45 | //static |
| 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 |
| 54 | MediaResource MediaResource::GraphicMemoryResource(int64_t value) { |
| 55 | return MediaResource(Type::kGraphicMemory, value); |
| 56 | } |
| 57 | |
| 58 | //static |
| 59 | MediaResource MediaResource::CpuBoostResource() { |
| 60 | return MediaResource(Type::kCpuBoost, 1); |
| 61 | } |
| 62 | |
| 63 | //static |
| 64 | MediaResource MediaResource::VideoBatteryResource() { |
| 65 | return MediaResource(Type::kBattery, SubType::kVideoCodec, 1); |
| 66 | } |
| 67 | |
| 68 | //static |
Jooyung Han | 3d564ff | 2020-02-22 00:46:06 +0900 | [diff] [blame] | 69 | MediaResource MediaResource::DrmSessionResource(const std::vector<uint8_t> &id, int64_t value) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 70 | return MediaResource(Type::kDrmSession, id, value); |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Jooyung Han | 3d564ff | 2020-02-22 00:46:06 +0900 | [diff] [blame] | 73 | static String8 bytesToHexString(const std::vector<uint8_t> &bytes) { |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 74 | String8 str; |
| 75 | for (auto &b : bytes) { |
| 76 | str.appendFormat("%02x", b); |
| 77 | } |
| 78 | return str; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 81 | String8 toString(const MediaResourceParcel& resource) { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 82 | String8 str; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 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); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 88 | return str; |
| 89 | } |
| 90 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 91 | }; // namespace android |