MediaCodecList.h revision d74110cdef2becd4f7fd2334c34c3ca73f56b355
1afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber/*
2afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber * Copyright 2012, The Android Open Source Project
3afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber *
4afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
5afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber * you may not use this file except in compliance with the License.
6afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber * You may obtain a copy of the License at
7afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber *
8afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber *     http://www.apache.org/licenses/LICENSE-2.0
9afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber *
10afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber * Unless required by applicable law or agreed to in writing, software
11afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
12afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber * See the License for the specific language governing permissions and
14afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber * limitations under the License.
15afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber */
16afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
17afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber#ifndef MEDIA_CODEC_LIST_H_
18afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
19afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber#define MEDIA_CODEC_LIST_H_
20afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
21afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber#include <media/stagefright/foundation/ABase.h>
22afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber#include <media/stagefright/foundation/AString.h>
23afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
24afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber#include <sys/types.h>
25afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber#include <utils/Errors.h>
26afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber#include <utils/KeyedVector.h>
27afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber#include <utils/Vector.h>
28afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
29afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Hubernamespace android {
30afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
31afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huberstruct MediaCodecList {
32afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    static const MediaCodecList *getInstance();
33afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
34afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    ssize_t findCodecByType(
35afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber            const char *type, bool encoder, size_t startIndex = 0) const;
36afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
37afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    ssize_t findCodecByName(const char *name) const;
38afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
3969829f3bd09ee4e6be49fee8795c5df24c4da70eAndreas Huber    size_t countCodecs() const;
40afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    const char *getCodecName(size_t index) const;
4169829f3bd09ee4e6be49fee8795c5df24c4da70eAndreas Huber    bool isEncoder(size_t index) const;
42afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    bool codecHasQuirk(size_t index, const char *quirkName) const;
43afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
4469829f3bd09ee4e6be49fee8795c5df24c4da70eAndreas Huber    status_t getSupportedTypes(size_t index, Vector<AString> *types) const;
4569829f3bd09ee4e6be49fee8795c5df24c4da70eAndreas Huber
4669829f3bd09ee4e6be49fee8795c5df24c4da70eAndreas Huber    struct ProfileLevel {
4769829f3bd09ee4e6be49fee8795c5df24c4da70eAndreas Huber        uint32_t mProfile;
4869829f3bd09ee4e6be49fee8795c5df24c4da70eAndreas Huber        uint32_t mLevel;
4969829f3bd09ee4e6be49fee8795c5df24c4da70eAndreas Huber    };
5069829f3bd09ee4e6be49fee8795c5df24c4da70eAndreas Huber    status_t getCodecCapabilities(
5169829f3bd09ee4e6be49fee8795c5df24c4da70eAndreas Huber            size_t index, const char *type,
5269829f3bd09ee4e6be49fee8795c5df24c4da70eAndreas Huber            Vector<ProfileLevel> *profileLevels,
532ee14000a38683220fb250d9e7300e1d71ccdaa0Lajos Molnar            Vector<uint32_t> *colorFormats,
542ee14000a38683220fb250d9e7300e1d71ccdaa0Lajos Molnar            uint32_t *flags) const;
5569829f3bd09ee4e6be49fee8795c5df24c4da70eAndreas Huber
56afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huberprivate:
57afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    enum Section {
58afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber        SECTION_TOPLEVEL,
59afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber        SECTION_DECODERS,
60afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber        SECTION_DECODER,
61afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber        SECTION_ENCODERS,
62afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber        SECTION_ENCODER,
63d74110cdef2becd4f7fd2334c34c3ca73f56b355Lajos Molnar        SECTION_INCLUDE,
64afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    };
65afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
66afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    struct CodecInfo {
67afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber        AString mName;
68afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber        bool mIsEncoder;
69afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber        uint32_t mTypes;
70afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber        uint32_t mQuirks;
71afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    };
72afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
73afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    static MediaCodecList *sCodecList;
74afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
75afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    status_t mInitCheck;
76afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    Section mCurrentSection;
77d74110cdef2becd4f7fd2334c34c3ca73f56b355Lajos Molnar    Vector<Section> mPastSections;
78afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    int32_t mDepth;
79d74110cdef2becd4f7fd2334c34c3ca73f56b355Lajos Molnar    AString mHrefBase;
80afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
81afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    Vector<CodecInfo> mCodecInfos;
82afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    KeyedVector<AString, size_t> mCodecQuirks;
83afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    KeyedVector<AString, size_t> mTypes;
84afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
85afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    MediaCodecList();
86afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    ~MediaCodecList();
87afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
88afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    status_t initCheck() const;
89d74110cdef2becd4f7fd2334c34c3ca73f56b355Lajos Molnar    void parseXMLFile(const char *path);
90d74110cdef2becd4f7fd2334c34c3ca73f56b355Lajos Molnar    void parseTopLevelXMLFile(const char *path);
91afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
92afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    static void StartElementHandlerWrapper(
93afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber            void *me, const char *name, const char **attrs);
94afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
95afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    static void EndElementHandlerWrapper(void *me, const char *name);
96afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
97afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    void startElementHandler(const char *name, const char **attrs);
98afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    void endElementHandler(const char *name);
99afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
100d74110cdef2becd4f7fd2334c34c3ca73f56b355Lajos Molnar    status_t includeXMLFile(const char **attrs);
101afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    status_t addMediaCodecFromAttributes(bool encoder, const char **attrs);
102afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    void addMediaCodec(bool encoder, const char *name, const char *type = NULL);
103afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
104afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    status_t addQuirk(const char **attrs);
105afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    status_t addTypeFromAttributes(const char **attrs);
106afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    void addType(const char *name);
107afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
108afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    DISALLOW_EVIL_CONSTRUCTORS(MediaCodecList);
109afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber};
110afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
111afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber}  // namespace android
112afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
113afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber#endif  // MEDIA_CODEC_LIST_H_
114afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber
115