blob: 3ce54335e13ef49cbac87934ed6612a54f0a9d09 [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 Molnar7f2262f2016-02-11 10:35:37 -080036struct CodecCapabilities;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070037
Ronghua Wu9e6955a2015-03-26 13:52:57 -070038typedef KeyedVector<AString, AString> CodecSettings;
39
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070040struct MediaCodecInfo : public RefBase {
41 struct ProfileLevel {
42 uint32_t mProfile;
43 uint32_t mLevel;
44 };
45
46 struct Capabilities : public RefBase {
Lajos Molnar5b05e492016-02-04 18:57:45 -080047 enum {
48 // decoder flags
49 kFlagSupportsAdaptivePlayback = 1 << 0,
50 kFlagSupportsSecurePlayback = 1 << 1,
51 kFlagSupportsTunneledPlayback = 1 << 2,
52
53 // encoder flags
54 kFlagSupportsIntraRefresh = 1 << 0,
55
56 };
57
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070058 void getSupportedProfileLevels(Vector<ProfileLevel> *profileLevels) const;
59 void getSupportedColorFormats(Vector<uint32_t> *colorFormats) const;
60 uint32_t getFlags() const;
Lajos Molnar2461e0c2014-08-12 08:55:25 -070061 const sp<AMessage> getDetails() const;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070062
Lajos Molnar5b05e492016-02-04 18:57:45 -080063 protected:
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070064 Vector<ProfileLevel> mProfileLevels;
65 Vector<uint32_t> mColorFormats;
66 uint32_t mFlags;
67 sp<AMessage> mDetails;
68
69 Capabilities();
70
Lajos Molnar5b05e492016-02-04 18:57:45 -080071 private:
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070072 // read object from parcel even if object creation fails
73 static sp<Capabilities> FromParcel(const Parcel &parcel);
74 status_t writeToParcel(Parcel *parcel) const;
75
76 DISALLOW_EVIL_CONSTRUCTORS(Capabilities);
77
78 friend class MediaCodecInfo;
79 };
80
Lajos Molnar5b05e492016-02-04 18:57:45 -080081 // Use a subclass to allow setting fields on construction without allowing
82 // to do the same throughout the framework.
83 struct CapabilitiesBuilder : public Capabilities {
84 void addProfileLevel(uint32_t profile, uint32_t level);
85 void addColorFormat(uint32_t format);
86 void addFlags(uint32_t flags);
87 };
88
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070089 bool isEncoder() const;
90 bool hasQuirk(const char *name) const;
91 void getSupportedMimes(Vector<AString> *mimes) const;
Lajos Molnar2461e0c2014-08-12 08:55:25 -070092 const sp<Capabilities> getCapabilitiesFor(const char *mime) const;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070093 const char *getCodecName() const;
94
95 /**
96 * Serialization over Binder
97 */
98 static sp<MediaCodecInfo> FromParcel(const Parcel &parcel);
99 status_t writeToParcel(Parcel *parcel) const;
100
101private:
102 // variable set only in constructor - these are accessed by MediaCodecList
103 // to avoid duplication of same variables
104 AString mName;
105 bool mIsEncoder;
106 bool mHasSoleMime; // was initialized with mime
107
108 Vector<AString> mQuirks;
109 KeyedVector<AString, sp<Capabilities> > mCaps;
110
111 sp<Capabilities> mCurrentCaps; // currently initalized capabilities
112
113 ssize_t getCapabilityIndex(const char *mime) const;
114
115 /* Methods used by MediaCodecList to construct the info
116 * object from XML.
117 *
118 * After info object is created:
119 * - additional quirks can be added
120 * - additional mimes can be added
121 * - OMX codec capabilities can be set for the current mime-type
122 * - a capability detail can be set for the current mime-type
123 * - a feature can be set for the current mime-type
124 * - info object can be completed when parsing of a mime-type is done
125 */
126 MediaCodecInfo(AString name, bool encoder, const char *mime);
127 void addQuirk(const char *name);
128 status_t addMime(const char *mime);
Ronghua Wu9e6955a2015-03-26 13:52:57 -0700129 status_t updateMime(const char *mime);
Lajos Molnar7f2262f2016-02-11 10:35:37 -0800130 status_t initializeCapabilities(const CodecCapabilities &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