blob: 895a13afef976f8c90cc238427618cb4edb8c943 [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;
35struct Parcel;
36struct CodecCapabilities;
37
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 {
47 void getSupportedProfileLevels(Vector<ProfileLevel> *profileLevels) const;
48 void getSupportedColorFormats(Vector<uint32_t> *colorFormats) const;
49 uint32_t getFlags() const;
Lajos Molnar2461e0c2014-08-12 08:55:25 -070050 const sp<AMessage> getDetails() const;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070051
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;
Lajos Molnar2461e0c2014-08-12 08:55:25 -070072 const sp<Capabilities> getCapabilitiesFor(const char *mime) const;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -070073 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
81private:
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);
Ronghua Wu9e6955a2015-03-26 13:52:57 -0700109 status_t updateMime(const char *mime);
Lajos Molnar60b1c0e2014-08-06 16:55:46 -0700110 status_t initializeCapabilities(const CodecCapabilities &caps);
111 void addDetail(const AString &key, const AString &value);
112 void addFeature(const AString &key, int32_t value);
Lajos Molnar732c6d92014-08-14 19:54:08 -0700113 void addFeature(const AString &key, const char *value);
Lajos Molnar6ff58f02014-08-11 16:46:15 -0700114 void removeMime(const char *mime);
Lajos Molnar60b1c0e2014-08-06 16:55:46 -0700115 void complete();
116
117 DISALLOW_EVIL_CONSTRUCTORS(MediaCodecInfo);
118
119 friend class MediaCodecList;
Ronghua Wu9e6955a2015-03-26 13:52:57 -0700120 friend class MediaCodecListOverridesTest;
Lajos Molnar60b1c0e2014-08-06 16:55:46 -0700121};
122
123} // namespace android
124
125#endif // MEDIA_CODEC_INFO_H_
126
127