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 private:
52     MediaCodecListWriter() = default;
53 
54     void writeGlobalSettings(const sp<AMessage> &globalSettings) const;
55     void writeCodecInfos(std::vector<sp<MediaCodecInfo>> *codecInfos) const;
56 
57     std::vector<std::pair<std::string, std::string>> mGlobalSettings;
58     std::vector<sp<MediaCodecInfo>> mCodecInfos;
59 
60     friend struct MediaCodecList;
61 };
62 
63 /**
64  * This interface is to be used by `MediaCodecList` to fill its members with
65  * appropriate information. `buildMediaCodecList()` will be called from a
66  * `MediaCodecList` object during its construction.
67  */
68 struct MediaCodecListBuilderBase {
69     /**
70      * Build the `MediaCodecList` via the given `MediaCodecListWriter` interface.
71      *
72      * @param writer The writer interface.
73      * @return The status of the construction. `NO_ERROR` means success.
74      */
75     virtual status_t buildMediaCodecList(MediaCodecListWriter* writer) = 0;
76 
77     /**
78      * The default destructor does nothing.
79      */
80     virtual ~MediaCodecListBuilderBase() = default;
81 
82     typedef MediaCodecListBuilderBase *(*CreateBuilderFunc)(void);
83 };
84 
85 }  // namespace android
86 
87 #endif  // MEDIA_CODEC_LIST_WRITER_H_
88 
89