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 <binder/Parcel.h>
22 #include <utils/String8.h>
23 #include <vector>
24 
25 namespace android {
26 
27 class MediaResource {
28 public:
29     enum Type {
30         kUnspecified = 0,
31         kSecureCodec,
32         kNonSecureCodec,
33         kGraphicMemory,
34         kCpuBoost,
35         kBattery,
36         kDrmSession,
37     };
38 
39     enum SubType {
40         kUnspecifiedSubType = 0,
41         kAudioCodec,
42         kVideoCodec,
43     };
44 
45     MediaResource();
46     MediaResource(Type type, uint64_t value);
47     MediaResource(Type type, SubType subType, uint64_t value);
48     MediaResource(Type type, const std::vector<uint8_t> &id, uint64_t value);
49 
50     void readFromParcel(const Parcel &parcel);
51     void writeToParcel(Parcel *parcel) const;
52 
53     String8 toString() const;
54 
55     bool operator==(const MediaResource &other) const;
56     bool operator!=(const MediaResource &other) const;
57 
58     Type mType;
59     SubType mSubType;
60     uint64_t mValue;
61     // for kDrmSession-type mId is the unique session id obtained via MediaDrm#openSession
62     std::vector<uint8_t> mId;
63 };
64 
65 inline static const char *asString(MediaResource::Type i, const char *def = "??") {
66     switch (i) {
67         case MediaResource::kUnspecified:    return "unspecified";
68         case MediaResource::kSecureCodec:    return "secure-codec";
69         case MediaResource::kNonSecureCodec: return "non-secure-codec";
70         case MediaResource::kGraphicMemory:  return "graphic-memory";
71         case MediaResource::kCpuBoost:       return "cpu-boost";
72         case MediaResource::kBattery:        return "battery";
73         case MediaResource::kDrmSession:     return "drm-session";
74         default:                             return def;
75     }
76 }
77 
78 inline static const char *asString(MediaResource::SubType i, const char *def = "??") {
79     switch (i) {
80         case MediaResource::kUnspecifiedSubType: return "unspecified";
81         case MediaResource::kAudioCodec:         return "audio-codec";
82         case MediaResource::kVideoCodec:         return "video-codec";
83         default:                                 return def;
84     }
85 }
86 
87 }; // namespace android
88 
89 #endif  // ANDROID_MEDIA_RESOURCE_H
90