• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     cout << "8: G711A" << endl;
118 
119     string mode;
120     AudioBufferFormatType audioFormatType = AudioBufferFormatType::TYPE_AAC;
121     (void)getline(cin, mode);
122     if (mode == "" || mode == "0") {
123         audioFormatType = AudioBufferFormatType::TYPE_AAC;
124     } else if (mode == "1") {
125         audioFormatType = AudioBufferFormatType::TYPE_FLAC;
126     } else if (mode == "2") {
127         audioFormatType = AudioBufferFormatType::TYPE_MP3;
128     } else if (mode == "3") {
129         audioFormatType = AudioBufferFormatType::TYPE_VORBIS;
130     } else if (mode == "4") {
131         audioFormatType = AudioBufferFormatType::TYPE_AMRNB;
132     } else if (mode == "5") {
133         audioFormatType = AudioBufferFormatType::TYPE_AMRWB;
134     } else if (mode == "6") {
135         audioFormatType = AudioBufferFormatType::TYPE_G711MU;
136     } else if (mode == "7") {
137         audioFormatType = AudioBufferFormatType::TYPE_APE;
138     } else if (mode == "8") {
139         audioFormatType = AudioBufferFormatType::TYPE_G711A;
140     } else {
141         cout << "no that selection" << endl;
142         return 0;
143     }
144     auto audioDec = std::make_unique<ADecBufferDemo>();
145     audioDec->RunCase(audioFormatType);
146     cout << "demo audio decoder end" << endl;
147     return 0;
148 }
149 
RunAudioAVBufferDecoderDrm()150 static int RunAudioAVBufferDecoderDrm()
151 {
152     cout << "RunAudioAVBufferDecoderDrm" << endl;
153     cout << "Please select number for format (default AAC Decoder): " << endl;
154     cout << "0: AAC" << endl;
155     cout << "1: FLAC" << endl;
156     cout << "2: MP3" << endl;
157 
158     string mode;
159     AudioBufferFormatType audioFormatType = AudioBufferFormatType::TYPE_AAC;
160     (void)getline(cin, mode);
161     if (mode == "" || mode == "0") {
162         audioFormatType = AudioBufferFormatType::TYPE_AAC;
163     } else if (mode == "1") {
164         audioFormatType = AudioBufferFormatType::TYPE_FLAC;
165     } else if (mode == "2") {
166         audioFormatType = AudioBufferFormatType::TYPE_MP3;
167     } else {
168         cout << "no that selection" << endl;
169         return 0;
170     }
171     auto audioDec = std::make_unique<ADecBufferDemo>();
172     audioDec->RunDrmCase(audioFormatType);
173     cout << "demo audio decoder end" << endl;
174     return 0;
175 }
176 
RunAudioEncoder()177 static int RunAudioEncoder()
178 {
179     cout << "Please select number for format (default AAC Encoder): " << endl;
180     cout << "0: AAC\n" << "1: FLAC" << endl;
181     cout << "2: OPUS" << endl;
182     cout << "3: G711MU" << endl;
183     cout << "4: AAC-API11" << endl;
184     cout << "5: FLAC-API11" << endl;
185     cout << "6: G711MU-API11" << endl;
186     cout << "7: AMR-NB-API11" << endl;
187     cout << "8: AMR-WB-API11" << endl;
188     cout << "9: MP3-API11" << endl;
189     string mode;
190     (void)getline(cin, mode);
191     if (mode == "" || mode == "0") {
192         auto audioEnc = std::make_unique<AEncAacDemo>();
193         audioEnc->RunCase();
194     } else if (mode == "1") {
195         auto audioEnc = std::make_unique<AEncFlacDemo>();
196         audioEnc->RunCase();
197     } else if (mode == "2") {
198         auto audioEnc = std::make_unique<AEncOpusDemo>();
199         audioEnc->RunCase();
200     } else if (mode == "3") {
201         auto audioEnc = std::make_unique<AEncG711muDemo>();
202         audioEnc->RunCase();
203     } else if (mode == "4") {
204         auto audioEnc = std::make_unique<AudioBufferAacEncDemo>();
205         audioEnc->RunCase();
206     } else if (mode == "5") {
207         auto audioEnc = std::make_unique<AudioBufferFlacEncDemo>();
208         audioEnc->RunCase();
209     } else if (mode == "6") {
210         auto audioEnc = std::make_unique<AEncAvbufferG711muDemo>();
211         audioEnc->RunCase();
212     } else if (mode == "7") {
213         auto audioEnc = std::make_unique<AEncAvbufferAmrNbDemo>();
214         audioEnc->RunCase();
215     } else if (mode == "8") {
216         auto audioEnc = std::make_unique<AEncAvbufferAmrWbDemo>();
217         audioEnc->RunCase();
218     } else if (mode == "9") {
219         auto audioEnc = std::make_unique<AEncAvbufferMp3Demo>();
220         audioEnc->RunCase();
221     } else {
222         cout << "no that selection" << endl;
223         return 0;
224     }
225     cout << "demo audio encoder end" << endl;
226     return 0;
227 }
228 
RunAudioInnerDecoder()229 static int RunAudioInnerDecoder()
230 {
231     cout << "Please select number for format (default AAC Decoder): " << endl;
232     cout << "0: AAC" << endl;
233     cout << "1: FLAC" << endl;
234     cout << "2: MP3" << endl;
235     cout << "3: VORBIS" << endl;
236     cout << "4: DecoderInner-API11" << endl;
237     cout << "5: LBVC" << endl;
238     string mode;
239     (void)getline(cin, mode);
240     if (mode == "" || mode == "0") {
241         auto audioDec = std::make_unique<ADecInnerDemo>();
242         audioDec->RunCase();
243     } else if (mode == "1") {
244         auto audioDec = std::make_unique<ADecInnerDemo>();
245         audioDec->RunCase();
246     } else if (mode == "2") {
247         auto audioDec = std::make_unique<ADecInnerDemo>();
248         audioDec->RunCase();
249     } else if (mode == "3") {
250         auto audioDec = std::make_unique<ADecInnerDemo>();
251         audioDec->RunCase();
252     } else if (mode == "4") {
253         auto audioDec = std::make_unique<AudioDecInnerAvBufferDemo>();
254         audioDec->RunCase();
255     } else if (mode == "5") {
256         auto audioDec = std::make_unique<AudioDecInnerAvBufferLbvcDemo>();
257         audioDec->RunCase();
258     } else {
259         cout << "no that selection" << endl;
260         return 0;
261     }
262     cout << "demo audio decoder end" << endl;
263     return 0;
264 }
265 
RunAudioInnerEncoder()266 static int RunAudioInnerEncoder()
267 {
268     cout << "Please select number for format (default AAC Encoder): " << endl;
269     cout << "0: AAC" << endl;
270     cout << "1: FLAC" << endl;
271     cout << "2: LBVC" << endl;
272     string mode;
273     (void)getline(cin, mode);
274     if (mode == "" || mode == "0") {
275         auto audioEnc = std::make_unique<AEnInnerDemo>();
276         audioEnc->RunCase();
277     } else if (mode == "1") {
278         auto audioEnc = std::make_unique<AEnInnerDemo>();
279         audioEnc->RunCase();
280     } else if (mode == "2") {
281         auto audioEnc = std::make_unique<AudioEncInnerAvBufferLbvcDemo>();
282         audioEnc->RunCase();
283     } else {
284         cout << "no that selection" << endl;
285         return 0;
286     }
287     cout << "demo audio encoder end" << endl;
288     return 0;
289 }
290 
RunCodecList()291 static int RunCodecList()
292 {
293     auto codecList = std::make_unique<CodecListDemo>();
294     if (codecList == nullptr) {
295         cout << "codec list is null" << endl;
296         return 0;
297     }
298     codecList->RunCase();
299     cout << "codec list end" << endl;
300     return 0;
301 }
302 
RunVideoDecoder()303 static int RunVideoDecoder()
304 {
305     cout << "Please select number for output mode (default buffer mode): " << endl;
306     cout << "0: buffer" << endl;
307     cout << "1: surface file" << endl;
308     cout << "2: surface render" << endl;
309     cout << "3: switch surface" << endl;
310 
311     string mode;
312     (void)getline(cin, mode);
313     if (mode != "0" && mode != "1" && mode != "2" && mode != "3") {
314         cout << "parameter invalid" << endl;
315         return 0;
316     }
317 
318     auto videoDec = std::make_unique<VDecDemo>();
319     if (videoDec == nullptr) {
320         cout << "video decoder is null" << endl;
321         return 0;
322     }
323     videoDec->RunCase(mode);
324     cout << "demo video decoder end" << endl;
325     return 0;
326 }
327 
RunVideoDecoderDrm()328 static int RunVideoDecoderDrm()
329 {
330     cout << "RunVideoDecoderDrm: " << endl;
331     cout << "Please select number for output mode (default buffer mode): " << endl;
332     cout << "0: buffer" << endl;
333     cout << "1: surface file" << endl;
334     cout << "2: surface render" << endl;
335 
336     string mode;
337     (void)getline(cin, mode);
338     if (mode != "0" && mode != "1" && mode != "2") {
339         cout << "parameter invalid" << endl;
340         return 0;
341     }
342 
343     auto videoDec = std::make_unique<VDecDemo>();
344     if (videoDec == nullptr) {
345         cout << "video decoder is null" << endl;
346         return 0;
347     }
348     videoDec->RunDrmCase();
349     cout << "demo video decoder end" << endl;
350     return 0;
351 }
352 
RunVideoInnerDecoder()353 static int RunVideoInnerDecoder()
354 {
355     cout << "Please select number for output mode (default buffer mode): " << endl;
356     cout << "0: buffer" << endl;
357     cout << "1: surface file" << endl;
358     cout << "2: surface render" << endl;
359 
360     string mode;
361     (void)getline(cin, mode);
362     if (mode != "0" && mode != "1" && mode != "2") {
363         cout << "parameter invalid" << endl;
364         return 0;
365     }
366 
367     auto videoDec = std::make_unique<VDecInnerDemo>();
368     if (videoDec == nullptr) {
369         cout << "video decoder is null" << endl;
370         return 0;
371     }
372     videoDec->RunCase(mode);
373     cout << "demo video decoder end" << endl;
374     return 0;
375 }
376 
RunE2EDemo()377 static int RunE2EDemo()
378 {
379     cout << "Please select number for api version (default api11): " << endl;
380     cout << "0: api11" << endl;
381     cout << "1: api10" << endl;
382 
383     string mode;
384     (void)getline(cin, mode);
385     if (mode != "0" && mode != "1") {
386         cout << "parameter invalid" << endl;
387         return 0;
388     }
389     const char *path = "/data/test/media/input.mp4";
390     if (mode == "0") {
391         auto e2eDemo = std::make_unique<AVCodecE2EDemo>(path);
392         if (e2eDemo == nullptr) {
393             cout << "e2eDemo is null" << endl;
394             return 0;
395         }
396         e2eDemo->Configure();
397         e2eDemo->Start();
398         e2eDemo->WaitForEOS();
399         e2eDemo->Stop();
400     } else if (mode == "1") {
401         auto e2eDemo = std::make_unique<AVCodecE2EDemoAPI10>(path);
402         if (e2eDemo == nullptr) {
403             cout << "e2eDemo is null" << endl;
404             return 0;
405         }
406         e2eDemo->Configure();
407         e2eDemo->Start();
408         e2eDemo->WaitForEOS();
409         e2eDemo->Stop();
410     }
411     cout << "e2eDemo end" << endl;
412     return 0;
413 }
414 
OptionPrint()415 static void OptionPrint()
416 {
417     cout << "Please select a demo scenario number(default Audio Decoder): " << endl;
418     cout << "0:Audio Decoder" << endl;
419     cout << "1:Audio Encoder" << endl;
420     cout << "2:Audio Inner Decoder" << endl;
421     cout << "3:Audio Inner Encoder" << endl;
422     cout << "4:muxer demo" << endl;
423     cout << "6:codeclist" << endl;
424     cout << "7:Video Decoder" << endl;
425     cout << "8:Video Inner Decoder" << endl;
426     cout << "9:demuxer demo" << endl;
427     cout << "10:Audio AVBuffer Decoder" << endl;
428     cout << "11:Video Decoder DRM" << endl;
429     cout << "12:E2E demo" << endl;
430     cout << "13:Audio AVBuffer Decoder with DRM" << endl;
431 }
432 
main()433 int main()
434 {
435     OptionPrint();
436     string mode;
437     (void)getline(cin, mode);
438     if (mode == "" || mode == "0") {
439         (void)RunAudioDecoder();
440     } else if (mode == "1") {
441         (void)RunAudioEncoder();
442     } else if (mode == "2") {
443         (void)RunAudioInnerDecoder();
444     } else if (mode == "3") {
445         (void)RunAudioInnerEncoder();
446     } else if (mode == "4") {
447         (void)AVMuxerDemoCase();
448     } else if (mode == "6") {
449         (void)RunCodecList();
450     } else if (mode == "7") {
451         (void)RunVideoDecoder();
452     } else if (mode == "8") {
453         (void)RunVideoInnerDecoder();
454     } else if (mode == "9") {
455         (void)AVSourceDemuxerDemoCase();
456     } else if (mode == "10") {
457         (void)RunAudioAVBufferDecoder();
458     } else if (mode == "11") {
459         (void)RunVideoDecoderDrm();
460     } else if (mode == "12") {
461         (void)RunE2EDemo();
462     } else if (mode == "13") {
463         (void)RunAudioAVBufferDecoderDrm();
464     } else {
465         cout << "no that selection" << endl;
466     }
467     return 0;
468 }
469