1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <climits>
17 #include <iostream>
18 #include <vector>
19 #include "avmuxer_demo_runner.h"
20 #include "avdemuxer_demo_runner.h"
21 #include "avcodec_audio_decoder_inner_demo.h"
22 #include "avcodec_audio_encoder_inner_demo.h"
23 #include "avcodec_audio_decoder_demo.h"
24 #include "avcodec_audio_aac_encoder_demo.h"
25 #include "avcodec_audio_avbuffer_aac_encoder_demo.h"
26 #include "avcodec_audio_avbuffer_amrnb_encoder_demo.h"
27 #include "avcodec_audio_avbuffer_amrwb_encoder_demo.h"
28 #include "avcodec_audio_avbuffer_decoder_inner_demo.h"
29 #include "avcodec_audio_flac_encoder_demo.h"
30 #include "avcodec_audio_avbuffer_flac_encoder_demo.h"
31 #include "avcodec_audio_avbuffer_g711mu_encoder_demo.h"
32 #include "avcodec_audio_avbuffer_lbvc_decoder_inner_demo.h"
33 #include "avcodec_audio_avbuffer_lbvc_encoder_inner_demo.h"
34 #include "avcodec_audio_avbuffer_mp3_encoder_demo.h"
35 #include "avcodec_audio_opus_encoder_demo.h"
36 #include "avcodec_audio_g711mu_encoder_demo.h"
37 #include "codeclist_demo.h"
38 #include "avcodec_video_decoder_demo.h"
39 #include "avcodec_video_decoder_inner_demo.h"
40 #include "avcodec_audio_avbuffer_decoder_demo.h"
41 #include "avcodec_e2e_demo.h"
42 #include "avcodec_e2e_demo_api10.h"
43
44 using namespace OHOS;
45 using namespace OHOS::MediaAVCodec;
46 using namespace OHOS::MediaAVCodec::AudioDemo;
47 using namespace OHOS::MediaAVCodec::AudioBufferDemo;
48 using namespace OHOS::MediaAVCodec::AudioFlacDemo;
49 using namespace OHOS::MediaAVCodec::AudioFlacEncDemo; // AudioEncoderBufferDemo
50 using namespace OHOS::MediaAVCodec::AudioOpusDemo;
51 using namespace OHOS::MediaAVCodec::AudioG711muDemo;
52 using namespace OHOS::MediaAVCodec::AudioAvbufferG711muDemo;
53 using namespace OHOS::MediaAVCodec::AudioAvbufferMp3EncoderDemo;
54 using namespace OHOS::MediaAVCodec::AudioAacDemo;
55 using namespace OHOS::MediaAVCodec::AudioAacEncDemo;
56 using namespace OHOS::MediaAVCodec::InnerAudioDemo;
57 using namespace OHOS::MediaAVCodec::VideoDemo;
58 using namespace OHOS::MediaAVCodec::InnerVideoDemo;
59 using namespace OHOS::MediaAVCodec::E2EDemo;
60 using namespace OHOS::MediaAVCodec::InnerAudioDecoderLbvcDemo;
61 using namespace OHOS::MediaAVCodec::InnerAudioEncoderLbvcDemo;
62 using namespace OHOS::MediaAVCodec::AudioAvbufferAmrNbDemo;
63 using namespace OHOS::MediaAVCodec::AudioAvbufferAmrWbDemo;
64 using namespace std;
65
RunAudioDecoder()66 static int RunAudioDecoder()
67 {
68 cout << "Please select number for format (default AAC Decoder): " << endl;
69 cout << "0: AAC" << endl;
70 cout << "1: FLAC" << endl;
71 cout << "2: MP3" << endl;
72 cout << "3: VORBIS" << endl;
73 cout << "4: AMRNB" << endl;
74 cout << "5: AMRWB" << endl;
75 cout << "6: OPUS" << endl;
76 cout << "7: G711MU" << endl;
77 string mode;
78 AudioFormatType audioFormatType = TYPE_AAC;
79 (void)getline(cin, mode);
80 if (mode == "" || mode == "0") {
81 audioFormatType = TYPE_AAC;
82 } else if (mode == "1") {
83 audioFormatType = TYPE_FLAC;
84 } else if (mode == "2") {
85 audioFormatType = TYPE_MP3;
86 } else if (mode == "3") {
87 audioFormatType = TYPE_VORBIS;
88 } else if (mode == "4") {
89 audioFormatType = TYPE_AMRNB;
90 } else if (mode == "5") {
91 audioFormatType = TYPE_AMRWB;
92 } else if (mode == "6") {
93 audioFormatType = TYPE_OPUS;
94 } else if (mode == "7") {
95 audioFormatType = TYPE_G711MU;
96 } else {
97 cout << "no that selection" << endl;
98 return 0;
99 }
100 auto audioDec = std::make_unique<ADecDemo>();
101 audioDec->RunCase(audioFormatType);
102 cout << "demo audio decoder end" << endl;
103 return 0;
104 }
105
RunAudioAVBufferDecoder()106 static int RunAudioAVBufferDecoder()
107 {
108 cout << "Please select number for format (default AAC Decoder): " << endl;
109 cout << "0: AAC" << endl;
110 cout << "1: FLAC" << endl;
111 cout << "2: MP3" << endl;
112 cout << "3: VORBIS" << endl;
113 cout << "4: AMR-NB" << endl;
114 cout << "5: AMR-WB" << endl;
115 cout << "6: G711MU" << endl;
116 cout << "7: APE" << endl;
117
118 string mode;
119 AudioBufferFormatType audioFormatType = AudioBufferFormatType::TYPE_AAC;
120 (void)getline(cin, mode);
121 if (mode == "" || mode == "0") {
122 audioFormatType = AudioBufferFormatType::TYPE_AAC;
123 } else if (mode == "1") {
124 audioFormatType = AudioBufferFormatType::TYPE_FLAC;
125 } else if (mode == "2") {
126 audioFormatType = AudioBufferFormatType::TYPE_MP3;
127 } else if (mode == "3") {
128 audioFormatType = AudioBufferFormatType::TYPE_VORBIS;
129 } else if (mode == "4") {
130 audioFormatType = AudioBufferFormatType::TYPE_AMRNB;
131 } else if (mode == "5") {
132 audioFormatType = AudioBufferFormatType::TYPE_AMRWB;
133 } else if (mode == "6") {
134 audioFormatType = AudioBufferFormatType::TYPE_G711MU;
135 } else if (mode == "7") {
136 audioFormatType = AudioBufferFormatType::TYPE_APE;
137 } else {
138 cout << "no that selection" << endl;
139 return 0;
140 }
141 auto audioDec = std::make_unique<ADecBufferDemo>();
142 audioDec->RunCase(audioFormatType);
143 cout << "demo audio decoder end" << endl;
144 return 0;
145 }
146
RunAudioAVBufferDecoderDrm()147 static int RunAudioAVBufferDecoderDrm()
148 {
149 cout << "RunAudioAVBufferDecoderDrm" << endl;
150 cout << "Please select number for format (default AAC Decoder): " << endl;
151 cout << "0: AAC" << endl;
152 cout << "1: FLAC" << endl;
153 cout << "2: MP3" << endl;
154
155 string mode;
156 AudioBufferFormatType audioFormatType = AudioBufferFormatType::TYPE_AAC;
157 (void)getline(cin, mode);
158 if (mode == "" || mode == "0") {
159 audioFormatType = AudioBufferFormatType::TYPE_AAC;
160 } else if (mode == "1") {
161 audioFormatType = AudioBufferFormatType::TYPE_FLAC;
162 } else if (mode == "2") {
163 audioFormatType = AudioBufferFormatType::TYPE_MP3;
164 } else {
165 cout << "no that selection" << endl;
166 return 0;
167 }
168 auto audioDec = std::make_unique<ADecBufferDemo>();
169 audioDec->RunDrmCase(audioFormatType);
170 cout << "demo audio decoder end" << endl;
171 return 0;
172 }
173
RunAudioEncoder()174 static int RunAudioEncoder()
175 {
176 cout << "Please select number for format (default AAC Encoder): " << endl;
177 cout << "0: AAC\n" << "1: FLAC" << endl;
178 cout << "2: OPUS" << endl;
179 cout << "3: G711MU" << endl;
180 cout << "4: AAC-API11" << endl;
181 cout << "5: FLAC-API11" << endl;
182 cout << "6: G711MU-API11" << endl;
183 cout << "7: AMR-NB-API11" << endl;
184 cout << "8: AMR-WB-API11" << endl;
185 cout << "9: MP3-API11" << endl;
186 string mode;
187 (void)getline(cin, mode);
188 if (mode == "" || mode == "0") {
189 auto audioEnc = std::make_unique<AEncAacDemo>();
190 audioEnc->RunCase();
191 } else if (mode == "1") {
192 auto audioEnc = std::make_unique<AEncFlacDemo>();
193 audioEnc->RunCase();
194 } else if (mode == "2") {
195 auto audioEnc = std::make_unique<AEncOpusDemo>();
196 audioEnc->RunCase();
197 } else if (mode == "3") {
198 auto audioEnc = std::make_unique<AEncG711muDemo>();
199 audioEnc->RunCase();
200 } else if (mode == "4") {
201 auto audioEnc = std::make_unique<AudioBufferAacEncDemo>();
202 audioEnc->RunCase();
203 } else if (mode == "5") {
204 auto audioEnc = std::make_unique<AudioBufferFlacEncDemo>();
205 audioEnc->RunCase();
206 } else if (mode == "6") {
207 auto audioEnc = std::make_unique<AEncAvbufferG711muDemo>();
208 audioEnc->RunCase();
209 } else if (mode == "7") {
210 auto audioEnc = std::make_unique<AEncAvbufferAmrNbDemo>();
211 audioEnc->RunCase();
212 } else if (mode == "8") {
213 auto audioEnc = std::make_unique<AEncAvbufferAmrWbDemo>();
214 audioEnc->RunCase();
215 } else if (mode == "9") {
216 auto audioEnc = std::make_unique<AEncAvbufferMp3Demo>();
217 audioEnc->RunCase();
218 } else {
219 cout << "no that selection" << endl;
220 return 0;
221 }
222 cout << "demo audio encoder end" << endl;
223 return 0;
224 }
225
RunAudioInnerDecoder()226 static int RunAudioInnerDecoder()
227 {
228 cout << "Please select number for format (default AAC Decoder): " << endl;
229 cout << "0: AAC" << endl;
230 cout << "1: FLAC" << endl;
231 cout << "2: MP3" << endl;
232 cout << "3: VORBIS" << endl;
233 cout << "4: DecoderInner-API11" << endl;
234 cout << "5: LBVC" << endl;
235 string mode;
236 (void)getline(cin, mode);
237 if (mode == "" || mode == "0") {
238 auto audioDec = std::make_unique<ADecInnerDemo>();
239 audioDec->RunCase();
240 } else if (mode == "1") {
241 auto audioDec = std::make_unique<ADecInnerDemo>();
242 audioDec->RunCase();
243 } else if (mode == "2") {
244 auto audioDec = std::make_unique<ADecInnerDemo>();
245 audioDec->RunCase();
246 } else if (mode == "3") {
247 auto audioDec = std::make_unique<ADecInnerDemo>();
248 audioDec->RunCase();
249 } else if (mode == "4") {
250 auto audioDec = std::make_unique<AudioDecInnerAvBufferDemo>();
251 audioDec->RunCase();
252 } else if (mode == "5") {
253 auto audioDec = std::make_unique<AudioDecInnerAvBufferLbvcDemo>();
254 audioDec->RunCase();
255 } else {
256 cout << "no that selection" << endl;
257 return 0;
258 }
259 cout << "demo audio decoder end" << endl;
260 return 0;
261 }
262
RunAudioInnerEncoder()263 static int RunAudioInnerEncoder()
264 {
265 cout << "Please select number for format (default AAC Encoder): " << endl;
266 cout << "0: AAC" << endl;
267 cout << "1: FLAC" << endl;
268 cout << "2: LBVC" << endl;
269 string mode;
270 (void)getline(cin, mode);
271 if (mode == "" || mode == "0") {
272 auto audioEnc = std::make_unique<AEnInnerDemo>();
273 audioEnc->RunCase();
274 } else if (mode == "1") {
275 auto audioEnc = std::make_unique<AEnInnerDemo>();
276 audioEnc->RunCase();
277 } else if (mode == "2") {
278 auto audioEnc = std::make_unique<AudioEncInnerAvBufferLbvcDemo>();
279 audioEnc->RunCase();
280 } else {
281 cout << "no that selection" << endl;
282 return 0;
283 }
284 cout << "demo audio encoder end" << endl;
285 return 0;
286 }
287
RunCodecList()288 static int RunCodecList()
289 {
290 auto codecList = std::make_unique<CodecListDemo>();
291 if (codecList == nullptr) {
292 cout << "codec list is null" << endl;
293 return 0;
294 }
295 codecList->RunCase();
296 cout << "codec list end" << endl;
297 return 0;
298 }
299
RunVideoDecoder()300 static int RunVideoDecoder()
301 {
302 cout << "Please select number for output mode (default buffer mode): " << endl;
303 cout << "0: buffer" << endl;
304 cout << "1: surface file" << endl;
305 cout << "2: surface render" << endl;
306
307 string mode;
308 (void)getline(cin, mode);
309 if (mode != "0" && mode != "1" && mode != "2") {
310 cout << "parameter invalid" << endl;
311 return 0;
312 }
313
314 auto videoDec = std::make_unique<VDecDemo>();
315 if (videoDec == nullptr) {
316 cout << "video decoder is null" << endl;
317 return 0;
318 }
319 videoDec->RunCase(mode);
320 cout << "demo video decoder end" << endl;
321 return 0;
322 }
323
RunVideoDecoderDrm()324 static int RunVideoDecoderDrm()
325 {
326 cout << "RunVideoDecoderDrm: " << endl;
327 cout << "Please select number for output mode (default buffer mode): " << endl;
328 cout << "0: buffer" << endl;
329 cout << "1: surface file" << endl;
330 cout << "2: surface render" << endl;
331
332 string mode;
333 (void)getline(cin, mode);
334 if (mode != "0" && mode != "1" && mode != "2") {
335 cout << "parameter invalid" << endl;
336 return 0;
337 }
338
339 auto videoDec = std::make_unique<VDecDemo>();
340 if (videoDec == nullptr) {
341 cout << "video decoder is null" << endl;
342 return 0;
343 }
344 videoDec->RunDrmCase();
345 cout << "demo video decoder end" << endl;
346 return 0;
347 }
348
RunVideoInnerDecoder()349 static int RunVideoInnerDecoder()
350 {
351 cout << "Please select number for output mode (default buffer mode): " << endl;
352 cout << "0: buffer" << endl;
353 cout << "1: surface file" << endl;
354 cout << "2: surface render" << endl;
355
356 string mode;
357 (void)getline(cin, mode);
358 if (mode != "0" && mode != "1" && mode != "2") {
359 cout << "parameter invalid" << endl;
360 return 0;
361 }
362
363 auto videoDec = std::make_unique<VDecInnerDemo>();
364 if (videoDec == nullptr) {
365 cout << "video decoder is null" << endl;
366 return 0;
367 }
368 videoDec->RunCase(mode);
369 cout << "demo video decoder end" << endl;
370 return 0;
371 }
372
RunE2EDemo()373 static int RunE2EDemo()
374 {
375 cout << "Please select number for api version (default api11): " << endl;
376 cout << "0: api11" << endl;
377 cout << "1: api10" << endl;
378
379 string mode;
380 (void)getline(cin, mode);
381 if (mode != "0" && mode != "1") {
382 cout << "parameter invalid" << endl;
383 return 0;
384 }
385 const char *path = "/data/test/media/input.mp4";
386 if (mode == "0") {
387 auto e2eDemo = std::make_unique<AVCodecE2EDemo>(path);
388 if (e2eDemo == nullptr) {
389 cout << "e2eDemo is null" << endl;
390 return 0;
391 }
392 e2eDemo->Configure();
393 e2eDemo->Start();
394 e2eDemo->WaitForEOS();
395 e2eDemo->Stop();
396 } else if (mode == "1") {
397 auto e2eDemo = std::make_unique<AVCodecE2EDemoAPI10>(path);
398 if (e2eDemo == nullptr) {
399 cout << "e2eDemo is null" << endl;
400 return 0;
401 }
402 e2eDemo->Configure();
403 e2eDemo->Start();
404 e2eDemo->WaitForEOS();
405 e2eDemo->Stop();
406 }
407 cout << "e2eDemo end" << endl;
408 return 0;
409 }
410
OptionPrint()411 static void OptionPrint()
412 {
413 cout << "Please select a demo scenario number(default Audio Decoder): " << endl;
414 cout << "0:Audio Decoder" << endl;
415 cout << "1:Audio Encoder" << endl;
416 cout << "2:Audio Inner Decoder" << endl;
417 cout << "3:Audio Inner Encoder" << endl;
418 cout << "4:muxer demo" << endl;
419 cout << "6:codeclist" << endl;
420 cout << "7:Video Decoder" << endl;
421 cout << "8:Video Inner Decoder" << endl;
422 cout << "9:demuxer demo" << endl;
423 cout << "10:Audio AVBuffer Decoder" << endl;
424 cout << "11:Video Decoder DRM" << endl;
425 cout << "12:E2E demo" << endl;
426 cout << "13:Audio AVBuffer Decoder with DRM" << endl;
427 }
428
main()429 int main()
430 {
431 OptionPrint();
432 string mode;
433 (void)getline(cin, mode);
434 if (mode == "" || mode == "0") {
435 (void)RunAudioDecoder();
436 } else if (mode == "1") {
437 (void)RunAudioEncoder();
438 } else if (mode == "2") {
439 (void)RunAudioInnerDecoder();
440 } else if (mode == "3") {
441 (void)RunAudioInnerEncoder();
442 } else if (mode == "4") {
443 (void)AVMuxerDemoCase();
444 } else if (mode == "6") {
445 (void)RunCodecList();
446 } else if (mode == "7") {
447 (void)RunVideoDecoder();
448 } else if (mode == "8") {
449 (void)RunVideoInnerDecoder();
450 } else if (mode == "9") {
451 (void)AVSourceDemuxerDemoCase();
452 } else if (mode == "10") {
453 (void)RunAudioAVBufferDecoder();
454 } else if (mode == "11") {
455 (void)RunVideoDecoderDrm();
456 } else if (mode == "12") {
457 (void)RunE2EDemo();
458 } else if (mode == "13") {
459 (void)RunAudioAVBufferDecoderDrm();
460 } else {
461 cout << "no that selection" << endl;
462 }
463 return 0;
464 }
465