1 /*
2  * Copyright 2012, 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_LIST_WRITER_H_
18 
19 #define MEDIA_CODEC_LIST_WRITER_H_
20 
21 #include <media/stagefright/foundation/ABase.h>
22 #include <media/stagefright/MediaCodecListWriter.h>
23 #include <media/MediaCodecInfo.h>
24 
25 #include <utils/Errors.h>
26 #include <utils/StrongPointer.h>
27 
28 namespace android {
29 
30 /**
31  * This class is to be used by a `MediaCodecListBuilderBase` instance to add
32  * information to the destination `MediaCodecList` object.
33  */
34 struct MediaCodecListWriter {
35     /**
36      * Add a key-value pair to a `MediaCodecList`'s global settings.
37      *
38      * @param key Key.
39      * @param value Value.
40      */
41     void addGlobalSetting(const char* key, const char* value);
42     /**
43      * Create an add a new `MediaCodecInfo` object for a `MediaCodecList`, and
44      * return a `MediaCodecInfoWriter` object associated with the newly added
45      * `MediaCodecInfo`.
46      *
47      * @return The `MediaCodecInfoWriter` object associated with the newly
48      * added `MediaCodecInfo` object.
49      */
50     std::unique_ptr<MediaCodecInfoWriter> addMediaCodecInfo();
51     /**
52      * Find an existing `MediaCodecInfo` object for a codec name and return a
53      * `MediaCodecInfoWriter` object associated with the found added `MediaCodecInfo`.
54      *
55      * @return The `MediaCodecInfoWriter` object if found, or nullptr if not found.
56      */
57     std::unique_ptr<MediaCodecInfoWriter> findMediaCodecInfo(const char *codecName);
58 private:
59     MediaCodecListWriter() = default;
60 
61     void writeGlobalSettings(const sp<AMessage> &globalSettings) const;
62     void writeCodecInfos(std::vector<sp<MediaCodecInfo>> *codecInfos) const;
63 
64     std::vector<std::pair<std::string, std::string>> mGlobalSettings;
65     std::vector<sp<MediaCodecInfo>> mCodecInfos;
66 
67     friend struct MediaCodecList;
68 };
69 
70 /**
71  * This interface is to be used by `MediaCodecList` to fill its members with
72  * appropriate information. `buildMediaCodecList()` will be called from a
73  * `MediaCodecList` object during its construction.
74  */
75 struct MediaCodecListBuilderBase {
76     /**
77      * Build the `MediaCodecList` via the given `MediaCodecListWriter` interface.
78      *
79      * @param writer The writer interface.
80      * @return The status of the construction. `NO_ERROR` means success.
81      */
82     virtual status_t buildMediaCodecList(MediaCodecListWriter* writer) = 0;
83 
84     /**
85      * The default destructor does nothing.
86      */
87     virtual ~MediaCodecListBuilderBase() = default;
88 
89     typedef MediaCodecListBuilderBase *(*CreateBuilderFunc)(void);
90 };
91 
92 }  // namespace android
93 
94 #endif  // MEDIA_CODEC_LIST_WRITER_H_
95 
96