Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 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; |
Lajos Molnar | 6d339f1 | 2015-04-17 16:15:53 -0700 | [diff] [blame] | 35 | class Parcel; |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 36 | |
Ronghua Wu | 9e6955a | 2015-03-26 13:52:57 -0700 | [diff] [blame] | 37 | typedef KeyedVector<AString, AString> CodecSettings; |
| 38 | |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 39 | struct MediaCodecInfo : public RefBase { |
| 40 | struct ProfileLevel { |
| 41 | uint32_t mProfile; |
| 42 | uint32_t mLevel; |
| 43 | }; |
| 44 | |
| 45 | struct Capabilities : public RefBase { |
Lajos Molnar | 5b05e49 | 2016-02-04 18:57:45 -0800 | [diff] [blame] | 46 | 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 Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 57 | void getSupportedProfileLevels(Vector<ProfileLevel> *profileLevels) const; |
| 58 | void getSupportedColorFormats(Vector<uint32_t> *colorFormats) const; |
| 59 | uint32_t getFlags() const; |
Lajos Molnar | 2461e0c | 2014-08-12 08:55:25 -0700 | [diff] [blame] | 60 | const sp<AMessage> getDetails() const; |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 61 | |
Lajos Molnar | 5b05e49 | 2016-02-04 18:57:45 -0800 | [diff] [blame] | 62 | protected: |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 63 | Vector<ProfileLevel> mProfileLevels; |
| 64 | Vector<uint32_t> mColorFormats; |
| 65 | uint32_t mFlags; |
| 66 | sp<AMessage> mDetails; |
| 67 | |
| 68 | Capabilities(); |
| 69 | |
Lajos Molnar | 5b05e49 | 2016-02-04 18:57:45 -0800 | [diff] [blame] | 70 | private: |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 71 | // 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 Molnar | 5b05e49 | 2016-02-04 18:57:45 -0800 | [diff] [blame] | 80 | // 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 Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 88 | bool isEncoder() const; |
| 89 | bool hasQuirk(const char *name) const; |
| 90 | void getSupportedMimes(Vector<AString> *mimes) const; |
Lajos Molnar | 2461e0c | 2014-08-12 08:55:25 -0700 | [diff] [blame] | 91 | const sp<Capabilities> getCapabilitiesFor(const char *mime) const; |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 92 | 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 | |
| 100 | private: |
| 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 Wu | 9e6955a | 2015-03-26 13:52:57 -0700 | [diff] [blame] | 128 | status_t updateMime(const char *mime); |
Lajos Molnar | 0a4427b | 2016-02-11 19:42:52 -0800 | [diff] [blame] | 129 | |
| 130 | status_t initializeCapabilities(const sp<Capabilities> &caps); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 131 | void addDetail(const AString &key, const AString &value); |
| 132 | void addFeature(const AString &key, int32_t value); |
Lajos Molnar | 732c6d9 | 2014-08-14 19:54:08 -0700 | [diff] [blame] | 133 | void addFeature(const AString &key, const char *value); |
Lajos Molnar | 6ff58f0 | 2014-08-11 16:46:15 -0700 | [diff] [blame] | 134 | void removeMime(const char *mime); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 135 | void complete(); |
| 136 | |
| 137 | DISALLOW_EVIL_CONSTRUCTORS(MediaCodecInfo); |
| 138 | |
| 139 | friend class MediaCodecList; |
Ronghua Wu | 9e6955a | 2015-03-26 13:52:57 -0700 | [diff] [blame] | 140 | friend class MediaCodecListOverridesTest; |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | } // namespace android |
| 144 | |
| 145 | #endif // MEDIA_CODEC_INFO_H_ |
| 146 | |
| 147 | |