blob: 48d0407137981fa1b58fc59093c040154061c7e5 [file] [log] [blame]
Lajos Molnar60b1c0e2014-08-06 16:55:46 -07001/*
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
32namespace android {
33
34struct AMessage;
Lajos Molnar6d339f12015-04-17 16:15:53 -070035class Parcel;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070036
Ronghua Wu9e6955a2015-03-26 13:52:57 -070037typedef KeyedVector<AString, AString> CodecSettings;
38
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070039struct MediaCodecInfo : public RefBase {
40 struct ProfileLevel {
41 uint32_t mProfile;
42 uint32_t mLevel;
43 };
44
45 struct Capabilities : public RefBase {
Lajos Molnar5b05e492016-02-04 18:57:45 -080046 enum {
47 // decoder flags
48 kFlagSupportsAdaptivePlayback = 1 << 0,
49 kFlagSupportsSecurePlayback = 1 << 1,
50 kFlagSupportsTunneledPlayback = 1 << 2,
51
52 // encoder flags
53 kFlagSupportsIntraRefresh = 1 << 0,
54
55 };
56
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070057 void getSupportedProfileLevels(Vector<ProfileLevel> *profileLevels) const;
58 void getSupportedColorFormats(Vector<uint32_t> *colorFormats) const;
59 uint32_t getFlags() const;
Lajos Molnar2461e0c2014-08-12 08:55:25 -070060 const sp<AMessage> getDetails() const;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070061
Lajos Molnar5b05e492016-02-04 18:57:45 -080062 protected:
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070063 Vector<ProfileLevel> mProfileLevels;
64 Vector<uint32_t> mColorFormats;
65 uint32_t mFlags;
66 sp<AMessage> mDetails;
67
68 Capabilities();
69
Lajos Molnar5b05e492016-02-04 18:57:45 -080070 private:
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070071 // read object from parcel even if object creation fails
72 static sp<Capabilities> FromParcel(const Parcel &parcel);
73 status_t writeToParcel(Parcel *parcel) const;
74
75 DISALLOW_EVIL_CONSTRUCTORS(Capabilities);
76
77 friend class MediaCodecInfo;
78 };
79
Lajos Molnar5b05e492016-02-04 18:57:45 -080080 // Use a subclass to allow setting fields on construction without allowing
81 // to do the same throughout the framework.
82 struct CapabilitiesBuilder : public Capabilities {
83 void addProfileLevel(uint32_t profile, uint32_t level);
84 void addColorFormat(uint32_t format);
85 void addFlags(uint32_t flags);
86 };
87
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070088 bool isEncoder() const;
89 bool hasQuirk(const char *name) const;
90 void getSupportedMimes(Vector<AString> *mimes) const;
Lajos Molnar2461e0c2014-08-12 08:55:25 -070091 const sp<Capabilities> getCapabilitiesFor(const char *mime) const;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070092 const char *getCodecName() const;
93
94 /**
95 * Serialization over Binder
96 */
97 static sp<MediaCodecInfo> FromParcel(const Parcel &parcel);
98 status_t writeToParcel(Parcel *parcel) const;
99
100private:
101 // variable set only in constructor - these are accessed by MediaCodecList
102 // to avoid duplication of same variables
103 AString mName;
104 bool mIsEncoder;
105 bool mHasSoleMime; // was initialized with mime
106
107 Vector<AString> mQuirks;
108 KeyedVector<AString, sp<Capabilities> > mCaps;
109
110 sp<Capabilities> mCurrentCaps; // currently initalized capabilities
111
112 ssize_t getCapabilityIndex(const char *mime) const;
113
114 /* Methods used by MediaCodecList to construct the info
115 * object from XML.
116 *
117 * After info object is created:
118 * - additional quirks can be added
119 * - additional mimes can be added
120 * - OMX codec capabilities can be set for the current mime-type
121 * - a capability detail can be set for the current mime-type
122 * - a feature can be set for the current mime-type
123 * - info object can be completed when parsing of a mime-type is done
124 */
125 MediaCodecInfo(AString name, bool encoder, const char *mime);
126 void addQuirk(const char *name);
127 status_t addMime(const char *mime);
Ronghua Wu9e6955a2015-03-26 13:52:57 -0700128 status_t updateMime(const char *mime);
Lajos Molnar0a4427b2016-02-11 19:42:52 -0800129
130 status_t initializeCapabilities(const sp<Capabilities> &caps);
Lajos Molnar60b1c0e2014-08-06 16:55:46 -0700131 void addDetail(const AString &key, const AString &value);
132 void addFeature(const AString &key, int32_t value);
Lajos Molnar732c6d92014-08-14 19:54:08 -0700133 void addFeature(const AString &key, const char *value);
Lajos Molnar6ff58f02014-08-11 16:46:15 -0700134 void removeMime(const char *mime);
Lajos Molnar60b1c0e2014-08-06 16:55:46 -0700135 void complete();
136
137 DISALLOW_EVIL_CONSTRUCTORS(MediaCodecInfo);
138
139 friend class MediaCodecList;
Ronghua Wu9e6955a2015-03-26 13:52:57 -0700140 friend class MediaCodecListOverridesTest;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -0700141};
142
143} // namespace android
144
145#endif // MEDIA_CODEC_INFO_H_
146
147