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_mp3_encoder_demo.h"
33 #include "avcodec_audio_avbuffer_lbvc_decoder_inner_demo.h"
34 #include "avcodec_audio_avbuffer_lbvc_encoder_inner_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 cout << "3: switch surface" << endl;
307
308 string mode;
309 (void)getline(cin, mode);
310 if (mode != "0" && mode != "1" && mode != "2" && mode != "3") {
311 cout << "parameter invalid" << endl;
312 return 0;
313 }
314
315 auto videoDec = std::make_unique<VDecDemo>();
316 if (videoDec == nullptr) {
317 cout << "video decoder is null" << endl;
318 return 0;
319 }
320 videoDec->RunCase(mode);
321 cout << "demo video decoder end" << endl;
322 return 0;
323 }
324
RunVideoDecoderDrm()325 static int RunVideoDecoderDrm()
326 {
327 cout << "RunVideoDecoderDrm: " << endl;
328 cout << "Please select number for output mode (default buffer mode): " << endl;
329 cout << "0: buffer" << endl;
330 cout << "1: surface file" << endl;
331 cout << "2: surface render" << endl;
332
333 string mode;
334 (void)getline(cin, mode);
335 if (mode != "0" && mode != "1" && mode != "2") {
336 cout << "parameter invalid" << endl;
337 return 0;
338 }
339
340 auto videoDec = std::make_unique<VDecDemo>();
341 if (videoDec == nullptr) {
342 cout << "video decoder is null" << endl;
343 return 0;
344 }
345 videoDec->RunDrmCase();
346 cout << "demo video decoder end" << endl;
347 return 0;
348 }
349
RunVideoInnerDecoder()350 static int RunVideoInnerDecoder()
351 {
352 cout << "Please select number for output mode (default buffer mode): " << endl;
353 cout << "0: buffer" << endl;
354 cout << "1: surface file" << endl;
355 cout << "2: surface render" << endl;
356
357 string mode;
358 (void)getline(cin, mode);
359 if (mode != "0" && mode != "1" && mode != "2") {
360 cout << "parameter invalid" << endl;
361 return 0;
362 }
363
364 auto videoDec = std::make_unique<VDecInnerDemo>();
365 if (videoDec == nullptr) {
366 cout << "video decoder is null" << endl;
367 return 0;
368 }
369 videoDec->RunCase(mode);
370 cout << "demo video decoder end" << endl;
371 return 0;
372 }
373
RunE2EDemo()374 static int RunE2EDemo()
375 {
376 cout << "Please select number for api version (default api11): " << endl;
377 cout << "0: api11" << endl;
378 cout << "1: api10" << endl;
379
380 string mode;
381 (void)getline(cin, mode);
382 if (mode != "0" && mode != "1") {
383 cout << "parameter invalid" << endl;
384 return 0;
385 }
386 const char *path = "/data/test/media/input.mp4";
387 if (mode == "0") {
388 auto e2eDemo = std::make_unique<AVCodecE2EDemo>(path);
389 if (e2eDemo == nullptr) {
390 cout << "e2eDemo is null" << endl;
391 return 0;
392 }
393 e2eDemo->Configure();
394 e2eDemo->Start();
395 e2eDemo->WaitForEOS();
396 e2eDemo->Stop();
397 } else if (mode == "1") {
398 auto e2eDemo = std::make_unique<AVCodecE2EDemoAPI10>(path);
399 if (e2eDemo == nullptr) {
400 cout << "e2eDemo is null" << endl;
401 return 0;
402 }
403 e2eDemo->Configure();
404 e2eDemo->Start();
405 e2eDemo->WaitForEOS();
406 e2eDemo->Stop();
407 }
408 cout << "e2eDemo end" << endl;
409 return 0;
410 }
411
OptionPrint()412 static void OptionPrint()
413 {
414 cout << "Please select a demo scenario number(default Audio Decoder): " << endl;
415 cout << "0:Audio Decoder" << endl;
416 cout << "1:Audio Encoder" << endl;
417 cout << "2:Audio Inner Decoder" << endl;
418 cout << "3:Audio Inner Encoder" << endl;
419 cout << "4:muxer demo" << endl;
420 cout << "6:codeclist" << endl;
421 cout << "7:Video Decoder" << endl;
422 cout << "8:Video Inner Decoder" << endl;
423 cout << "9:demuxer demo" << endl;
424 cout << "10:Audio AVBuffer Decoder" << endl;
425 cout << "11:Video Decoder DRM" << endl;
426 cout << "12:E2E demo" << endl;
427 cout << "13:Audio AVBuffer Decoder with DRM" << endl;
428 }
429
main()430 int main()
431 {
432 OptionPrint();
433 string mode;
434 (void)getline(cin, mode);
435 if (mode == "" || mode == "0") {
436 (void)RunAudioDecoder();
437 } else if (mode == "1") {
438 (void)RunAudioEncoder();
439 } else if (mode == "2") {
440 (void)RunAudioInnerDecoder();
441 } else if (mode == "3") {
442 (void)RunAudioInnerEncoder();
443 } else if (mode == "4") {
444 (void)AVMuxerDemoCase();
445 } else if (mode == "6") {
446 (void)RunCodecList();
447 } else if (mode == "7") {
448 (void)RunVideoDecoder();
449 } else if (mode == "8") {
450 (void)RunVideoInnerDecoder();
451 } else if (mode == "9") {
452 (void)AVSourceDemuxerDemoCase();
453 } else if (mode == "10") {
454 (void)RunAudioAVBufferDecoder();
455 } else if (mode == "11") {
456 (void)RunVideoDecoderDrm();
457 } else if (mode == "12") {
458 (void)RunE2EDemo();
459 } else if (mode == "13") {
460 (void)RunAudioAVBufferDecoderDrm();
461 } else {
462 cout << "no that selection" << endl;
463 }
464 return 0;
465 }
466