1 /*
2  * Copyright 2014, 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 #ifndef MEDIA_CODEC_INFO_H_
18 
19 #define MEDIA_CODEC_INFO_H_
20 
21 #include <binder/Parcel.h>
22 #include <media/stagefright/foundation/ABase.h>
23 #include <media/stagefright/foundation/AString.h>
24 
25 #include <sys/types.h>
26 #include <utils/Errors.h>
27 #include <utils/KeyedVector.h>
28 #include <utils/RefBase.h>
29 #include <utils/Vector.h>
30 #include <utils/StrongPointer.h>
31 
32 namespace android {
33 
34 struct AMessage;
35 class Parcel;
36 struct CodecCapabilities;
37 
38 typedef KeyedVector<AString, AString> CodecSettings;
39 
40 struct MediaCodecInfo : public RefBase {
41     struct ProfileLevel {
42         uint32_t mProfile;
43         uint32_t mLevel;
44     };
45 
46     struct Capabilities : public RefBase {
47         void getSupportedProfileLevels(Vector<ProfileLevel> *profileLevels) const;
48         void getSupportedColorFormats(Vector<uint32_t> *colorFormats) const;
49         uint32_t getFlags() const;
50         const sp<AMessage> getDetails() const;
51 
52     private:
53         Vector<ProfileLevel> mProfileLevels;
54         Vector<uint32_t> mColorFormats;
55         uint32_t mFlags;
56         sp<AMessage> mDetails;
57 
58         Capabilities();
59 
60         // read object from parcel even if object creation fails
61         static sp<Capabilities> FromParcel(const Parcel &parcel);
62         status_t writeToParcel(Parcel *parcel) const;
63 
64         DISALLOW_EVIL_CONSTRUCTORS(Capabilities);
65 
66         friend class MediaCodecInfo;
67     };
68 
69     bool isEncoder() const;
70     bool hasQuirk(const char *name) const;
71     void getSupportedMimes(Vector<AString> *mimes) const;
72     const sp<Capabilities> getCapabilitiesFor(const char *mime) const;
73     const char *getCodecName() const;
74 
75     /**
76      * Serialization over Binder
77      */
78     static sp<MediaCodecInfo> FromParcel(const Parcel &parcel);
79     status_t writeToParcel(Parcel *parcel) const;
80 
81 private:
82     // variable set only in constructor - these are accessed by MediaCodecList
83     // to avoid duplication of same variables
84     AString mName;
85     bool mIsEncoder;
86     bool mHasSoleMime; // was initialized with mime
87 
88     Vector<AString> mQuirks;
89     KeyedVector<AString, sp<Capabilities> > mCaps;
90 
91     sp<Capabilities> mCurrentCaps; // currently initalized capabilities
92 
93     ssize_t getCapabilityIndex(const char *mime) const;
94 
95     /* Methods used by MediaCodecList to construct the info
96      * object from XML.
97      *
98      * After info object is created:
99      * - additional quirks can be added
100      * - additional mimes can be added
101      *   - OMX codec capabilities can be set for the current mime-type
102      *   - a capability detail can be set for the current mime-type
103      *   - a feature can be set for the current mime-type
104      *   - info object can be completed when parsing of a mime-type is done
105      */
106     MediaCodecInfo(AString name, bool encoder, const char *mime);
107     void addQuirk(const char *name);
108     status_t addMime(const char *mime);
109     status_t updateMime(const char *mime);
110     status_t initializeCapabilities(const CodecCapabilities &caps);
111     void addDetail(const AString &key, const AString &value);
112     void addFeature(const AString &key, int32_t value);
113     void addFeature(const AString &key, const char *value);
114     void removeMime(const char *mime);
115     void complete();
116 
117     DISALLOW_EVIL_CONSTRUCTORS(MediaCodecInfo);
118 
119     friend class MediaCodecList;
120     friend class MediaCodecListOverridesTest;
121 };
122 
123 }  // namespace android
124 
125 #endif  // MEDIA_CODEC_INFO_H_
126 
127 
128