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 
18 #ifndef ANDROID_MEDIA_RESOURCE_H
19 #define ANDROID_MEDIA_RESOURCE_H
20 
21 #include <aidl/android/media/MediaResourceParcel.h>
22 #include <utils/String8.h>
23 
24 namespace android {
25 
26 using aidl::android::media::MediaResourceParcel;
27 using aidl::android::media::MediaResourceSubType;
28 using aidl::android::media::MediaResourceType;
29 
30 class MediaResource : public MediaResourceParcel {
31 public:
32     using Type = MediaResourceType;
33     using SubType = MediaResourceSubType;
34 
35     MediaResource() = delete;
36     MediaResource(Type type, int64_t value);
37     MediaResource(Type type, SubType subType, int64_t value);
38     MediaResource(Type type, const std::vector<uint8_t> &id, int64_t value);
39 
40     static MediaResource CodecResource(bool secure, bool video, int64_t instanceCount = 1);
41     static MediaResource GraphicMemoryResource(int64_t value);
42     static MediaResource CpuBoostResource();
43     static MediaResource VideoBatteryResource();
44     static MediaResource DrmSessionResource(const std::vector<uint8_t> &id, int64_t value);
45 };
46 
47 inline static const char *asString(MediaResource::Type i, const char *def = "??") {
48     switch (i) {
49         case MediaResource::Type::kUnspecified:    return "unspecified";
50         case MediaResource::Type::kSecureCodec:    return "secure-codec";
51         case MediaResource::Type::kNonSecureCodec: return "non-secure-codec";
52         case MediaResource::Type::kGraphicMemory:  return "graphic-memory";
53         case MediaResource::Type::kCpuBoost:       return "cpu-boost";
54         case MediaResource::Type::kBattery:        return "battery";
55         case MediaResource::Type::kDrmSession:     return "drm-session";
56         default:                                   return def;
57     }
58 }
59 
60 inline static const char *asString(MediaResource::SubType i, const char *def = "??") {
61     switch (i) {
62         case MediaResource::SubType::kUnspecifiedSubType: return "unspecified";
63         case MediaResource::SubType::kAudioCodec:         return "audio-codec";
64         case MediaResource::SubType::kVideoCodec:         return "video-codec";
65         default:                                 return def;
66     }
67 }
68 
69 String8 toString(const MediaResourceParcel& resource);
70 
71 }; // namespace android
72 
73 #endif  // ANDROID_MEDIA_RESOURCE_H
74