blob: ac5b075952ad723d39418fb396d5b43495761ad5 [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 Molnar65dd3ee2016-02-04 18:57:45 -080046 enum {
47 // decoder flags
48 kFlagSupportsAdaptivePlayback = 1 << 0,
49 kFlagSupportsSecurePlayback = 1 << 1,
50 kFlagSupportsTunneledPlayback = 1 << 2,
51 };
52
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070053 void getSupportedProfileLevels(Vector<ProfileLevel> *profileLevels) const;
54 void getSupportedColorFormats(Vector<uint32_t> *colorFormats) const;
55 uint32_t getFlags() const;
Lajos Molnar2461e0c2014-08-12 08:55:25 -070056 const sp<AMessage> getDetails() const;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070057
Lajos Molnar65dd3ee2016-02-04 18:57:45 -080058 protected:
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070059 Vector<ProfileLevel> mProfileLevels;
60 Vector<uint32_t> mColorFormats;
61 uint32_t mFlags;
62 sp<AMessage> mDetails;
63
64 Capabilities();
65
Lajos Molnar65dd3ee2016-02-04 18:57:45 -080066 private:
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070067 // read object from parcel even if object creation fails
68 static sp<Capabilities> FromParcel(const Parcel &parcel);
69 status_t writeToParcel(Parcel *parcel) const;
70
71 DISALLOW_EVIL_CONSTRUCTORS(Capabilities);
72
73 friend class MediaCodecInfo;
74 };
75
Lajos Molnar65dd3ee2016-02-04 18:57:45 -080076 // Use a subclass to allow setting fields on construction without allowing
77 // to do the same throughout the framework.
78 struct CapabilitiesBuilder : public Capabilities {
79 void addProfileLevel(uint32_t profile, uint32_t level);
80 void addColorFormat(uint32_t format);
81 void addFlags(uint32_t flags);
82 };
83
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070084 bool isEncoder() const;
85 bool hasQuirk(const char *name) const;
86 void getSupportedMimes(Vector<AString> *mimes) const;
Lajos Molnar2461e0c2014-08-12 08:55:25 -070087 const sp<Capabilities> getCapabilitiesFor(const char *mime) const;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070088 const char *getCodecName() const;
89
90 /**
91 * Serialization over Binder
92 */
93 static sp<MediaCodecInfo> FromParcel(const Parcel &parcel);
94 status_t writeToParcel(Parcel *parcel) const;
95
96private:
97 // variable set only in constructor - these are accessed by MediaCodecList
98 // to avoid duplication of same variables
99 AString mName;
100 bool mIsEncoder;
101 bool mHasSoleMime; // was initialized with mime
102
103 Vector<AString> mQuirks;
104 KeyedVector<AString, sp<Capabilities> > mCaps;
105
106 sp<Capabilities> mCurrentCaps; // currently initalized capabilities
107
108 ssize_t getCapabilityIndex(const char *mime) const;
109
110 /* Methods used by MediaCodecList to construct the info
111 * object from XML.
112 *
113 * After info object is created:
114 * - additional quirks can be added
115 * - additional mimes can be added
116 * - OMX codec capabilities can be set for the current mime-type
117 * - a capability detail can be set for the current mime-type
118 * - a feature can be set for the current mime-type
119 * - info object can be completed when parsing of a mime-type is done
120 */
121 MediaCodecInfo(AString name, bool encoder, const char *mime);
122 void addQuirk(const char *name);
123 status_t addMime(const char *mime);
Ronghua Wu9e6955a2015-03-26 13:52:57 -0700124 status_t updateMime(const char *mime);
Lajos Molnaref2bdbc2016-02-11 19:42:52 -0800125
126 status_t initializeCapabilities(const sp<Capabilities> &caps);
Lajos Molnar60b1c0e2014-08-06 16:55:46 -0700127 void addDetail(const AString &key, const AString &value);
128 void addFeature(const AString &key, int32_t value);
Lajos Molnar732c6d92014-08-14 19:54:08 -0700129 void addFeature(const AString &key, const char *value);
Lajos Molnar6ff58f02014-08-11 16:46:15 -0700130 void removeMime(const char *mime);
Lajos Molnar60b1c0e2014-08-06 16:55:46 -0700131 void complete();
132
133 DISALLOW_EVIL_CONSTRUCTORS(MediaCodecInfo);
134
135 friend class MediaCodecList;
Ronghua Wu9e6955a2015-03-26 13:52:57 -0700136 friend class MediaCodecListOverridesTest;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -0700137};
138
139} // namespace android
140
141#endif // MEDIA_CODEC_INFO_H_
142
143