1794c9f46Sopenharmony_ci/*
2794c9f46Sopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3794c9f46Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4794c9f46Sopenharmony_ci * you may not use this file except in compliance with the License.
5794c9f46Sopenharmony_ci * You may obtain a copy of the License at
6794c9f46Sopenharmony_ci *
7794c9f46Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8794c9f46Sopenharmony_ci *
9794c9f46Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10794c9f46Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11794c9f46Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12794c9f46Sopenharmony_ci * See the License for the specific language governing permissions and
13794c9f46Sopenharmony_ci * limitations under the License.
14794c9f46Sopenharmony_ci */
15794c9f46Sopenharmony_ci
16794c9f46Sopenharmony_ci#include "histreamer_ability_parser.h"
17794c9f46Sopenharmony_ci#include "dh_utils_tool.h"
18794c9f46Sopenharmony_ci#include "distributed_hardware_log.h"
19794c9f46Sopenharmony_ci
20794c9f46Sopenharmony_ci
21794c9f46Sopenharmony_cinamespace OHOS {
22794c9f46Sopenharmony_cinamespace DistributedHardware {
23794c9f46Sopenharmony_ci
24794c9f46Sopenharmony_cistatic const std::string NAME = "name";
25794c9f46Sopenharmony_cistatic const std::string INS = "ins";
26794c9f46Sopenharmony_cistatic const std::string OUTS = "outs";
27794c9f46Sopenharmony_cistatic const std::string MIME = "mime";
28794c9f46Sopenharmony_cistatic const std::string SAMPLE_RATE = "sample_rate";
29794c9f46Sopenharmony_cistatic const std::string AUDIO_SAMPLE_FORMAT = "sample_fmt";
30794c9f46Sopenharmony_cistatic const std::string AD_MPEG_VER = "ad_mpeg_ver";
31794c9f46Sopenharmony_cistatic const std::string AUDIO_AAC_PROFILE = "aac_profile";
32794c9f46Sopenharmony_cistatic const std::string AUDIO_AAC_STREAM_FORMAT = "aac_stm_fmt";
33794c9f46Sopenharmony_cistatic const std::string AUDIO_CHANNEL_LAYOUT = "channel_layout";
34794c9f46Sopenharmony_ci
35794c9f46Sopenharmony_cistatic const std::string VIDEO_PIXEL_FMT = "pixel_fmt";
36794c9f46Sopenharmony_cistatic const std::string VIDEO_BIT_STREAM_FMT = "vd_bit_stream_fmt";
37794c9f46Sopenharmony_ci
38794c9f46Sopenharmony_civoid FromJson(const cJSON *jsonObject, AudioEncoderIn &audioEncoderIn)
39794c9f46Sopenharmony_ci{
40794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
41794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
42794c9f46Sopenharmony_ci        return;
43794c9f46Sopenharmony_ci    }
44794c9f46Sopenharmony_ci    if (!IsString(jsonObject, MIME)) {
45794c9f46Sopenharmony_ci        DHLOGE("AudioEncoderIn MIME is invalid!\n");
46794c9f46Sopenharmony_ci        return;
47794c9f46Sopenharmony_ci    }
48794c9f46Sopenharmony_ci    audioEncoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
49794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, SAMPLE_RATE)) {
50794c9f46Sopenharmony_ci        DHLOGE("AudioEncoderIn SAMPLE_RATE is invalid\n");
51794c9f46Sopenharmony_ci        return;
52794c9f46Sopenharmony_ci    }
53794c9f46Sopenharmony_ci    cJSON *sampleRate = cJSON_GetObjectItem(jsonObject, SAMPLE_RATE.c_str());
54794c9f46Sopenharmony_ci    if (sampleRate == NULL) {
55794c9f46Sopenharmony_ci        DHLOGE("AudioEncoderIn SAMPLE_RATE is invalid\n");
56794c9f46Sopenharmony_ci        return;
57794c9f46Sopenharmony_ci    }
58794c9f46Sopenharmony_ci    cJSON *sampleRateItem = nullptr;
59794c9f46Sopenharmony_ci    cJSON_ArrayForEach(sampleRateItem, sampleRate) {
60794c9f46Sopenharmony_ci        if (sampleRateItem && sampleRateItem->type == cJSON_Number) {
61794c9f46Sopenharmony_ci            audioEncoderIn.sample_rate.push_back((uint32_t)sampleRateItem->valuedouble);
62794c9f46Sopenharmony_ci        }
63794c9f46Sopenharmony_ci    }
64794c9f46Sopenharmony_ci}
65794c9f46Sopenharmony_ci
66794c9f46Sopenharmony_civoid FromJson(const cJSON *jsonObject, AudioEncoderOut &audioEncoderOut)
67794c9f46Sopenharmony_ci{
68794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
69794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
70794c9f46Sopenharmony_ci        return;
71794c9f46Sopenharmony_ci    }
72794c9f46Sopenharmony_ci    if (!IsString(jsonObject, MIME)) {
73794c9f46Sopenharmony_ci        DHLOGE("AudioEncoderOut MIME is invalid!");
74794c9f46Sopenharmony_ci        return;
75794c9f46Sopenharmony_ci    }
76794c9f46Sopenharmony_ci    audioEncoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
77794c9f46Sopenharmony_ci    if (!IsUInt32(jsonObject, AD_MPEG_VER)) {
78794c9f46Sopenharmony_ci        DHLOGE("AudioEncoderOut AD_MPEG_VER is invalid!");
79794c9f46Sopenharmony_ci        return;
80794c9f46Sopenharmony_ci    }
81794c9f46Sopenharmony_ci    audioEncoderOut.ad_mpeg_ver = (uint32_t)cJSON_GetObjectItem(jsonObject, AD_MPEG_VER.c_str())->valuedouble;
82794c9f46Sopenharmony_ci
83794c9f46Sopenharmony_ci    if (!IsUInt8(jsonObject, AUDIO_AAC_PROFILE)) {
84794c9f46Sopenharmony_ci        DHLOGE("AudioEncoderOut AUDIO_AAC_PROFILE is invalid!");
85794c9f46Sopenharmony_ci        return;
86794c9f46Sopenharmony_ci    }
87794c9f46Sopenharmony_ci    audioEncoderOut.aac_profile =
88794c9f46Sopenharmony_ci        (AudioAacProfile)cJSON_GetObjectItem(jsonObject, AUDIO_AAC_PROFILE.c_str())->valuedouble;
89794c9f46Sopenharmony_ci
90794c9f46Sopenharmony_ci    if (!IsUInt8(jsonObject, AUDIO_AAC_STREAM_FORMAT)) {
91794c9f46Sopenharmony_ci        DHLOGE("AudioEncoderOut AUDIO_AAC_STREAM_FORMAT is invalid!");
92794c9f46Sopenharmony_ci        return;
93794c9f46Sopenharmony_ci    }
94794c9f46Sopenharmony_ci    audioEncoderOut.aac_stm_fmt =
95794c9f46Sopenharmony_ci        (AudioAacStreamFormat)cJSON_GetObjectItem(jsonObject, AUDIO_AAC_STREAM_FORMAT.c_str())->valuedouble;
96794c9f46Sopenharmony_ci}
97794c9f46Sopenharmony_ci
98794c9f46Sopenharmony_civoid FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder)
99794c9f46Sopenharmony_ci{
100794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
101794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
102794c9f46Sopenharmony_ci        return;
103794c9f46Sopenharmony_ci    }
104794c9f46Sopenharmony_ci    if (!IsString(jsonObject, NAME)) {
105794c9f46Sopenharmony_ci        DHLOGE("AudioEncoder NAME is invalid!");
106794c9f46Sopenharmony_ci        return;
107794c9f46Sopenharmony_ci    }
108794c9f46Sopenharmony_ci    audioEncoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring;
109794c9f46Sopenharmony_ci
110794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, INS)) {
111794c9f46Sopenharmony_ci        DHLOGE("AudioEncoder INS is invalid!");
112794c9f46Sopenharmony_ci        return;
113794c9f46Sopenharmony_ci    }
114794c9f46Sopenharmony_ci    cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
115794c9f46Sopenharmony_ci    cJSON *inJson = nullptr;
116794c9f46Sopenharmony_ci    cJSON_ArrayForEach(inJson, insJson) {
117794c9f46Sopenharmony_ci        AudioEncoderIn in;
118794c9f46Sopenharmony_ci        FromJson(inJson, in);
119794c9f46Sopenharmony_ci        audioEncoder.ins.push_back(in);
120794c9f46Sopenharmony_ci    }
121794c9f46Sopenharmony_ci
122794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, OUTS)) {
123794c9f46Sopenharmony_ci        DHLOGE("AudioEncoder OUTS is invalid!");
124794c9f46Sopenharmony_ci        return;
125794c9f46Sopenharmony_ci    }
126794c9f46Sopenharmony_ci    cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
127794c9f46Sopenharmony_ci    cJSON *outJson = nullptr;
128794c9f46Sopenharmony_ci    cJSON_ArrayForEach(outJson, outsJson) {
129794c9f46Sopenharmony_ci        AudioEncoderOut out;
130794c9f46Sopenharmony_ci        FromJson(outJson, out);
131794c9f46Sopenharmony_ci        audioEncoder.outs.push_back(out);
132794c9f46Sopenharmony_ci    }
133794c9f46Sopenharmony_ci}
134794c9f46Sopenharmony_ci
135794c9f46Sopenharmony_civoid FromJson(const cJSON *jsonObject, AudioDecoderIn &audioDecoderIn)
136794c9f46Sopenharmony_ci{
137794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
138794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
139794c9f46Sopenharmony_ci        return;
140794c9f46Sopenharmony_ci    }
141794c9f46Sopenharmony_ci    if (!IsString(jsonObject, MIME)) {
142794c9f46Sopenharmony_ci        DHLOGE("AudioDecoderIn MIME is invalid!");
143794c9f46Sopenharmony_ci        return;
144794c9f46Sopenharmony_ci    }
145794c9f46Sopenharmony_ci    audioDecoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
146794c9f46Sopenharmony_ci
147794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, AUDIO_CHANNEL_LAYOUT)) {
148794c9f46Sopenharmony_ci        DHLOGE("AudioDecoder AUDIO_CHANNEL_LAYOUT is invalid!");
149794c9f46Sopenharmony_ci        return;
150794c9f46Sopenharmony_ci    }
151794c9f46Sopenharmony_ci    const cJSON *channelLayoutJson = cJSON_GetObjectItem(jsonObject, AUDIO_CHANNEL_LAYOUT.c_str());
152794c9f46Sopenharmony_ci    const cJSON *layout = nullptr;
153794c9f46Sopenharmony_ci    cJSON_ArrayForEach(layout, channelLayoutJson) {
154794c9f46Sopenharmony_ci        if (layout && layout->type == cJSON_Number) {
155794c9f46Sopenharmony_ci            audioDecoderIn.channel_layout.push_back((AudioChannelLayout)layout->valuedouble);
156794c9f46Sopenharmony_ci        }
157794c9f46Sopenharmony_ci    }
158794c9f46Sopenharmony_ci}
159794c9f46Sopenharmony_ci
160794c9f46Sopenharmony_civoid FromJson(const cJSON *jsonObject, AudioDecoderOut &audioDecoderOut)
161794c9f46Sopenharmony_ci{
162794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
163794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
164794c9f46Sopenharmony_ci        return;
165794c9f46Sopenharmony_ci    }
166794c9f46Sopenharmony_ci    if (!IsString(jsonObject, MIME)) {
167794c9f46Sopenharmony_ci        DHLOGE("AudioDecoderOut MIME is invalid!");
168794c9f46Sopenharmony_ci        return;
169794c9f46Sopenharmony_ci    }
170794c9f46Sopenharmony_ci    audioDecoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
171794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, AUDIO_SAMPLE_FORMAT)) {
172794c9f46Sopenharmony_ci        DHLOGE("AudioDecoderOut AUDIO_SAMPLE_FORMAT is invalid!");
173794c9f46Sopenharmony_ci        return;
174794c9f46Sopenharmony_ci    }
175794c9f46Sopenharmony_ci    cJSON *sampleFormatJson = cJSON_GetObjectItem(jsonObject, AUDIO_SAMPLE_FORMAT.c_str());
176794c9f46Sopenharmony_ci    cJSON *format = nullptr;
177794c9f46Sopenharmony_ci    cJSON_ArrayForEach(format, sampleFormatJson) {
178794c9f46Sopenharmony_ci        if (format && format->type == cJSON_Number) {
179794c9f46Sopenharmony_ci            audioDecoderOut.sample_fmt.push_back((AudioSampleFormat)format->valuedouble);
180794c9f46Sopenharmony_ci        }
181794c9f46Sopenharmony_ci    }
182794c9f46Sopenharmony_ci}
183794c9f46Sopenharmony_ci
184794c9f46Sopenharmony_civoid FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder)
185794c9f46Sopenharmony_ci{
186794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
187794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
188794c9f46Sopenharmony_ci        return;
189794c9f46Sopenharmony_ci    }
190794c9f46Sopenharmony_ci    if (!IsString(jsonObject, NAME)) {
191794c9f46Sopenharmony_ci        DHLOGE("AudioDecoderOut MIME is invalid!");
192794c9f46Sopenharmony_ci        return;
193794c9f46Sopenharmony_ci    }
194794c9f46Sopenharmony_ci    audioDecoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring;
195794c9f46Sopenharmony_ci
196794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, INS)) {
197794c9f46Sopenharmony_ci        DHLOGE("AudioDecoder OUTS is invalid!");
198794c9f46Sopenharmony_ci        return;
199794c9f46Sopenharmony_ci    }
200794c9f46Sopenharmony_ci    const cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
201794c9f46Sopenharmony_ci    cJSON *inJson = nullptr;
202794c9f46Sopenharmony_ci    cJSON_ArrayForEach(inJson, insJson) {
203794c9f46Sopenharmony_ci        AudioDecoderIn in;
204794c9f46Sopenharmony_ci        FromJson(inJson, in);
205794c9f46Sopenharmony_ci        audioDecoder.ins.push_back(in);
206794c9f46Sopenharmony_ci    }
207794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, OUTS)) {
208794c9f46Sopenharmony_ci        DHLOGE("AudioDecoder OUTS is invalid!");
209794c9f46Sopenharmony_ci        return;
210794c9f46Sopenharmony_ci    }
211794c9f46Sopenharmony_ci    cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
212794c9f46Sopenharmony_ci    cJSON *outJson = nullptr;
213794c9f46Sopenharmony_ci    cJSON_ArrayForEach(outJson, outsJson) {
214794c9f46Sopenharmony_ci        AudioDecoderOut out;
215794c9f46Sopenharmony_ci        FromJson(outJson, out);
216794c9f46Sopenharmony_ci        audioDecoder.outs.push_back(out);
217794c9f46Sopenharmony_ci    }
218794c9f46Sopenharmony_ci}
219794c9f46Sopenharmony_ci
220794c9f46Sopenharmony_civoid FromJson(const cJSON *jsonObject, VideoEncoderIn &videoEncoderIn)
221794c9f46Sopenharmony_ci{
222794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
223794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
224794c9f46Sopenharmony_ci        return;
225794c9f46Sopenharmony_ci    }
226794c9f46Sopenharmony_ci    if (!IsString(jsonObject, MIME)) {
227794c9f46Sopenharmony_ci        DHLOGE("VideoEncoderIn MIME is invalid!");
228794c9f46Sopenharmony_ci        return;
229794c9f46Sopenharmony_ci    }
230794c9f46Sopenharmony_ci    videoEncoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
231794c9f46Sopenharmony_ci
232794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, VIDEO_PIXEL_FMT)) {
233794c9f46Sopenharmony_ci        DHLOGE("VideoEncoderIn VIDEO_PIXEL_FMT is invalid!");
234794c9f46Sopenharmony_ci        return;
235794c9f46Sopenharmony_ci    }
236794c9f46Sopenharmony_ci    cJSON *videoPixelFmt = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str());
237794c9f46Sopenharmony_ci    cJSON *pixelFmt = nullptr;
238794c9f46Sopenharmony_ci    cJSON_ArrayForEach(pixelFmt, videoPixelFmt) {
239794c9f46Sopenharmony_ci        if (pixelFmt && pixelFmt->type == cJSON_Number) {
240794c9f46Sopenharmony_ci            videoEncoderIn.pixel_fmt.push_back((VideoPixelFormat)pixelFmt->valuedouble);
241794c9f46Sopenharmony_ci        }
242794c9f46Sopenharmony_ci    }
243794c9f46Sopenharmony_ci}
244794c9f46Sopenharmony_ci
245794c9f46Sopenharmony_civoid FromJson(const cJSON *jsonObject, VideoEncoderOut &videoEncoderOut)
246794c9f46Sopenharmony_ci{
247794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
248794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
249794c9f46Sopenharmony_ci        return;
250794c9f46Sopenharmony_ci    }
251794c9f46Sopenharmony_ci    if (!IsString(jsonObject, MIME)) {
252794c9f46Sopenharmony_ci        DHLOGE("VideoEncoderIn MIME is invalid!");
253794c9f46Sopenharmony_ci        return;
254794c9f46Sopenharmony_ci    }
255794c9f46Sopenharmony_ci    videoEncoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
256794c9f46Sopenharmony_ci}
257794c9f46Sopenharmony_ci
258794c9f46Sopenharmony_civoid FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder)
259794c9f46Sopenharmony_ci{
260794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
261794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
262794c9f46Sopenharmony_ci        return;
263794c9f46Sopenharmony_ci    }
264794c9f46Sopenharmony_ci    if (!IsString(jsonObject, NAME)) {
265794c9f46Sopenharmony_ci        DHLOGE("VideoEncoder NAME is invalid!");
266794c9f46Sopenharmony_ci        return;
267794c9f46Sopenharmony_ci    }
268794c9f46Sopenharmony_ci    videoEncoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring;
269794c9f46Sopenharmony_ci
270794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, INS)) {
271794c9f46Sopenharmony_ci        DHLOGE("VideoEncoder INS is invalid!");
272794c9f46Sopenharmony_ci        return;
273794c9f46Sopenharmony_ci    }
274794c9f46Sopenharmony_ci    cJSON *videoEncoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
275794c9f46Sopenharmony_ci    cJSON *inJson = nullptr;
276794c9f46Sopenharmony_ci    cJSON_ArrayForEach(inJson, videoEncoderInsJson) {
277794c9f46Sopenharmony_ci        VideoEncoderIn in;
278794c9f46Sopenharmony_ci        FromJson(inJson, in);
279794c9f46Sopenharmony_ci        videoEncoder.ins.push_back(in);
280794c9f46Sopenharmony_ci    }
281794c9f46Sopenharmony_ci
282794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, OUTS)) {
283794c9f46Sopenharmony_ci        DHLOGE("VideoEncoder OUTS is invalid!");
284794c9f46Sopenharmony_ci        return;
285794c9f46Sopenharmony_ci    }
286794c9f46Sopenharmony_ci    cJSON *videoEncoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str());
287794c9f46Sopenharmony_ci    cJSON *outJson = nullptr;
288794c9f46Sopenharmony_ci    cJSON_ArrayForEach(outJson, videoEncoderOutsJson) {
289794c9f46Sopenharmony_ci        VideoEncoderOut out;
290794c9f46Sopenharmony_ci        FromJson(outJson, out);
291794c9f46Sopenharmony_ci        videoEncoder.outs.push_back(out);
292794c9f46Sopenharmony_ci    }
293794c9f46Sopenharmony_ci}
294794c9f46Sopenharmony_ci
295794c9f46Sopenharmony_civoid FromJson(const cJSON *jsonObject, VideoDecoderIn &videoDecoderIn)
296794c9f46Sopenharmony_ci{
297794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
298794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
299794c9f46Sopenharmony_ci        return;
300794c9f46Sopenharmony_ci    }
301794c9f46Sopenharmony_ci    if (!IsString(jsonObject, MIME)) {
302794c9f46Sopenharmony_ci        DHLOGE("VideoDecoderIn MIME is invalid!");
303794c9f46Sopenharmony_ci        return;
304794c9f46Sopenharmony_ci    }
305794c9f46Sopenharmony_ci    videoDecoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
306794c9f46Sopenharmony_ci
307794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, VIDEO_BIT_STREAM_FMT)) {
308794c9f46Sopenharmony_ci        DHLOGE("VideoDecoderIn VIDEO_BIT_STREAM_FMT is invalid!");
309794c9f46Sopenharmony_ci        return;
310794c9f46Sopenharmony_ci    }
311794c9f46Sopenharmony_ci    cJSON *videoBitStreamFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_BIT_STREAM_FMT.c_str());
312794c9f46Sopenharmony_ci    cJSON *fmt = nullptr;
313794c9f46Sopenharmony_ci    cJSON_ArrayForEach(fmt, videoBitStreamFmtJson) {
314794c9f46Sopenharmony_ci        if (fmt && fmt->type == cJSON_Number) {
315794c9f46Sopenharmony_ci            videoDecoderIn.vd_bit_stream_fmt.push_back((VideoBitStreamFormat)(fmt->valuedouble));
316794c9f46Sopenharmony_ci        }
317794c9f46Sopenharmony_ci    }
318794c9f46Sopenharmony_ci}
319794c9f46Sopenharmony_ci
320794c9f46Sopenharmony_civoid FromJson(const cJSON *jsonObject, VideoDecoderOut &videoDecoderOut)
321794c9f46Sopenharmony_ci{
322794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
323794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
324794c9f46Sopenharmony_ci        return;
325794c9f46Sopenharmony_ci    }
326794c9f46Sopenharmony_ci    if (!IsString(jsonObject, MIME)) {
327794c9f46Sopenharmony_ci        DHLOGE("VideoDecoderOut MIME is invalid!");
328794c9f46Sopenharmony_ci        return;
329794c9f46Sopenharmony_ci    }
330794c9f46Sopenharmony_ci    videoDecoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring;
331794c9f46Sopenharmony_ci
332794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, VIDEO_BIT_STREAM_FMT)) {
333794c9f46Sopenharmony_ci        DHLOGE("videoDecoderOut VIDEO_PIXEL_FMT is invalid!");
334794c9f46Sopenharmony_ci        return;
335794c9f46Sopenharmony_ci    }
336794c9f46Sopenharmony_ci    cJSON *videoPixelFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str());
337794c9f46Sopenharmony_ci    cJSON *fmt = nullptr;
338794c9f46Sopenharmony_ci    cJSON_ArrayForEach(fmt, videoPixelFmtJson) {
339794c9f46Sopenharmony_ci        if (fmt && fmt->type == cJSON_Number) {
340794c9f46Sopenharmony_ci            videoDecoderOut.pixel_fmt.push_back((VideoPixelFormat)(fmt->valuedouble));
341794c9f46Sopenharmony_ci        }
342794c9f46Sopenharmony_ci    }
343794c9f46Sopenharmony_ci}
344794c9f46Sopenharmony_ci
345794c9f46Sopenharmony_civoid FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder)
346794c9f46Sopenharmony_ci{
347794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
348794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
349794c9f46Sopenharmony_ci        return;
350794c9f46Sopenharmony_ci    }
351794c9f46Sopenharmony_ci    if (!IsString(jsonObject, NAME)) {
352794c9f46Sopenharmony_ci        DHLOGE("VideoDecoder NAME is invalid!");
353794c9f46Sopenharmony_ci        return;
354794c9f46Sopenharmony_ci    }
355794c9f46Sopenharmony_ci    videoDecoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring;
356794c9f46Sopenharmony_ci
357794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, INS)) {
358794c9f46Sopenharmony_ci        DHLOGE("VideoDecoder INS is invalid!");
359794c9f46Sopenharmony_ci        return;
360794c9f46Sopenharmony_ci    }
361794c9f46Sopenharmony_ci    cJSON *videoDecoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str());
362794c9f46Sopenharmony_ci    cJSON *inJson = nullptr;
363794c9f46Sopenharmony_ci    cJSON_ArrayForEach(inJson, videoDecoderInsJson) {
364794c9f46Sopenharmony_ci        VideoDecoderIn in;
365794c9f46Sopenharmony_ci        FromJson(inJson, in);
366794c9f46Sopenharmony_ci        videoDecoder.ins.push_back(in);
367794c9f46Sopenharmony_ci    }
368794c9f46Sopenharmony_ci
369794c9f46Sopenharmony_ci    if (!IsArray(jsonObject, OUTS)) {
370794c9f46Sopenharmony_ci        DHLOGE("VideoDecoder OUTS is invalid!");
371794c9f46Sopenharmony_ci        return;
372794c9f46Sopenharmony_ci    }
373794c9f46Sopenharmony_ci    cJSON *videoDecoderOutsJson =  cJSON_GetObjectItem(jsonObject, OUTS.c_str());
374794c9f46Sopenharmony_ci    cJSON *outJson = nullptr;
375794c9f46Sopenharmony_ci    cJSON_ArrayForEach(outJson, videoDecoderOutsJson) {
376794c9f46Sopenharmony_ci        VideoDecoderOut out;
377794c9f46Sopenharmony_ci        FromJson(outJson, out);
378794c9f46Sopenharmony_ci        videoDecoder.outs.push_back(out);
379794c9f46Sopenharmony_ci    }
380794c9f46Sopenharmony_ci}
381794c9f46Sopenharmony_ci
382794c9f46Sopenharmony_citemplate <typename T>
383794c9f46Sopenharmony_civoid FromJson(const std::string &key, const cJSON *jsonObject, std::vector<T> &objs)
384794c9f46Sopenharmony_ci{
385794c9f46Sopenharmony_ci    if (jsonObject == nullptr) {
386794c9f46Sopenharmony_ci        DHLOGE("Json pointer is nullptr!");
387794c9f46Sopenharmony_ci        return;
388794c9f46Sopenharmony_ci    }
389794c9f46Sopenharmony_ci    cJSON *json = cJSON_GetObjectItem(jsonObject, key.c_str());
390794c9f46Sopenharmony_ci    if (json == NULL) {
391794c9f46Sopenharmony_ci        DHLOGE("JSONObject key invalid, key: %{public}s", key.c_str());
392794c9f46Sopenharmony_ci        return;
393794c9f46Sopenharmony_ci    }
394794c9f46Sopenharmony_ci    if (cJSON_IsArray(json)) {
395794c9f46Sopenharmony_ci        cJSON *item;
396794c9f46Sopenharmony_ci        cJSON_ArrayForEach(item, json) {
397794c9f46Sopenharmony_ci            T obj;
398794c9f46Sopenharmony_ci            FromJson(item, obj);
399794c9f46Sopenharmony_ci            objs.push_back(obj);
400794c9f46Sopenharmony_ci        }
401794c9f46Sopenharmony_ci    } else {
402794c9f46Sopenharmony_ci        T obj;
403794c9f46Sopenharmony_ci        FromJson(json, obj);
404794c9f46Sopenharmony_ci        objs.push_back(obj);
405794c9f46Sopenharmony_ci    }
406794c9f46Sopenharmony_ci}
407794c9f46Sopenharmony_ci
408794c9f46Sopenharmony_citemplate
409794c9f46Sopenharmony_civoid FromJson<AudioEncoder>(const std::string &key, const cJSON *jsonObject, std::vector<AudioEncoder> &objs);
410794c9f46Sopenharmony_citemplate
411794c9f46Sopenharmony_civoid FromJson<AudioDecoder>(const std::string &key, const cJSON *jsonObject, std::vector<AudioDecoder> &objs);
412794c9f46Sopenharmony_citemplate
413794c9f46Sopenharmony_civoid FromJson<VideoEncoder>(const std::string &key, const cJSON *jsonObject, std::vector<VideoEncoder> &objs);
414794c9f46Sopenharmony_citemplate
415794c9f46Sopenharmony_civoid FromJson<VideoDecoder>(const std::string &key, const cJSON *jsonObject, std::vector<VideoDecoder> &objs);
416794c9f46Sopenharmony_ci
417794c9f46Sopenharmony_ci}
418794c9f46Sopenharmony_ci}