MediaCodecInfo.h revision 732c6d955524ead6c31e6e1bafbd41ea4cee525d
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
32namespace android {
33
34struct AMessage;
35struct Parcel;
36struct CodecCapabilities;
37
38struct MediaCodecInfo : public RefBase {
39    struct ProfileLevel {
40        uint32_t mProfile;
41        uint32_t mLevel;
42    };
43
44    struct Capabilities : public RefBase {
45        void getSupportedProfileLevels(Vector<ProfileLevel> *profileLevels) const;
46        void getSupportedColorFormats(Vector<uint32_t> *colorFormats) const;
47        uint32_t getFlags() const;
48        const sp<AMessage> getDetails() const;
49
50    private:
51        Vector<ProfileLevel> mProfileLevels;
52        Vector<uint32_t> mColorFormats;
53        uint32_t mFlags;
54        sp<AMessage> mDetails;
55
56        Capabilities();
57
58        // read object from parcel even if object creation fails
59        static sp<Capabilities> FromParcel(const Parcel &parcel);
60        status_t writeToParcel(Parcel *parcel) const;
61
62        DISALLOW_EVIL_CONSTRUCTORS(Capabilities);
63
64        friend class MediaCodecInfo;
65    };
66
67    bool isEncoder() const;
68    bool hasQuirk(const char *name) const;
69    void getSupportedMimes(Vector<AString> *mimes) const;
70    const sp<Capabilities> getCapabilitiesFor(const char *mime) const;
71    const char *getCodecName() const;
72
73    /**
74     * Serialization over Binder
75     */
76    static sp<MediaCodecInfo> FromParcel(const Parcel &parcel);
77    status_t writeToParcel(Parcel *parcel) const;
78
79private:
80    // variable set only in constructor - these are accessed by MediaCodecList
81    // to avoid duplication of same variables
82    AString mName;
83    bool mIsEncoder;
84    bool mHasSoleMime; // was initialized with mime
85
86    Vector<AString> mQuirks;
87    KeyedVector<AString, sp<Capabilities> > mCaps;
88
89    sp<Capabilities> mCurrentCaps; // currently initalized capabilities
90
91    ssize_t getCapabilityIndex(const char *mime) const;
92
93    /* Methods used by MediaCodecList to construct the info
94     * object from XML.
95     *
96     * After info object is created:
97     * - additional quirks can be added
98     * - additional mimes can be added
99     *   - OMX codec capabilities can be set for the current mime-type
100     *   - a capability detail can be set for the current mime-type
101     *   - a feature can be set for the current mime-type
102     *   - info object can be completed when parsing of a mime-type is done
103     */
104    MediaCodecInfo(AString name, bool encoder, const char *mime);
105    void addQuirk(const char *name);
106    status_t addMime(const char *mime);
107    status_t initializeCapabilities(const CodecCapabilities &caps);
108    void addDetail(const AString &key, const AString &value);
109    void addFeature(const AString &key, int32_t value);
110    void addFeature(const AString &key, const char *value);
111    void removeMime(const char *mime);
112    void complete();
113
114    DISALLOW_EVIL_CONSTRUCTORS(MediaCodecInfo);
115
116    friend class MediaCodecList;
117};
118
119}  // namespace android
120
121#endif  // MEDIA_CODEC_INFO_H_
122
123
124