• 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_decoder_inner_demo.h"
27 #include "avcodec_audio_flac_encoder_demo.h"
28 #include "avcodec_audio_avbuffer_flac_encoder_demo.h"
29 #include "avcodec_audio_avbuffer_g711mu_encoder_demo.h"
30 #include "avcodec_audio_opus_encoder_demo.h"
31 #include "avcodec_audio_g711mu_encoder_demo.h"
32 #include "codeclist_demo.h"
33 #include "avcodec_video_decoder_demo.h"
34 #include "avcodec_video_decoder_inner_demo.h"
35 #include "avcodec_audio_avbuffer_decoder_demo.h"
36 #include "avcodec_e2e_demo.h"
37 #include "avcodec_e2e_demo_api10.h"
38 
39 using namespace OHOS;
40 using namespace OHOS::MediaAVCodec;
41 using namespace OHOS::MediaAVCodec::AudioDemo;
42 using namespace OHOS::MediaAVCodec::AudioBufferDemo;
43 using namespace OHOS::MediaAVCodec::AudioFlacDemo;
44 using namespace OHOS::MediaAVCodec::AudioFlacEncDemo;  // AudioEncoderBufferDemo
45 using namespace OHOS::MediaAVCodec::AudioOpusDemo;
46 using namespace OHOS::MediaAVCodec::AudioG711muDemo;
47 using namespace OHOS::MediaAVCodec::AudioAvbufferG711muDemo;
48 using namespace OHOS::MediaAVCodec::AudioAacDemo;
49 using namespace OHOS::MediaAVCodec::AudioAacEncDemo;
50 using namespace OHOS::MediaAVCodec::InnerAudioDemo;
51 using namespace OHOS::MediaAVCodec::VideoDemo;
52 using namespace OHOS::MediaAVCodec::InnerVideoDemo;
53 using namespace OHOS::MediaAVCodec::E2EDemo;
54 using namespace std;
55 
RunAudioDecoder()56 static int RunAudioDecoder()
57 {
58     cout << "Please select number for format (default AAC Decoder): " << endl;
59     cout << "0: AAC" << endl;
60     cout << "1: FLAC" << endl;
61     cout << "2: MP3" << endl;
62     cout << "3: VORBIS" << endl;
63     cout << "4: AMRNB" << endl;
64     cout << "5: AMRWB" << endl;
65     cout << "6: OPUS" << endl;
66     cout << "7: G711MU" << endl;
67     string mode;
68     AudioFormatType audioFormatType = TYPE_AAC;
69     (void)getline(cin, mode);
70     if (mode == "" || mode == "0") {
71         audioFormatType = TYPE_AAC;
72     } else if (mode == "1") {
73         audioFormatType = TYPE_FLAC;
74     } else if (mode == "2") {
75         audioFormatType = TYPE_MP3;
76     } else if (mode == "3") {
77         audioFormatType = TYPE_VORBIS;
78     } else if (mode == "4") {
79         audioFormatType = TYPE_AMRNB;
80     } else if (mode == "5") {
81         audioFormatType = TYPE_AMRWB;
82     } else if (mode == "6") {
83         audioFormatType = TYPE_OPUS;
84     } else if (mode == "7") {
85         audioFormatType = TYPE_G711MU;
86     } else {
87         cout << "no that selection" << endl;
88         return 0;
89     }
90     auto audioDec = std::make_unique<ADecDemo>();
91     audioDec->RunCase(audioFormatType);
92     cout << "demo audio decoder end" << endl;
93     return 0;
94 }
95 
RunAudioAVBufferDecoder()96 static int RunAudioAVBufferDecoder()
97 {
98     cout << "Please select number for format (default AAC Decoder): " << endl;
99     cout << "0: AAC" << endl;
100     cout << "1: FLAC" << endl;
101     cout << "2: MP3" << endl;
102     cout << "3: VORBIS" << endl;
103     cout << "4: AMR-NB" << endl;
104     cout << "5: AMR-WB" << endl;
105     cout << "6: G711MU" << endl;
106 
107     string mode;
108     AudioBufferFormatType audioFormatType = AudioBufferFormatType::TYPE_AAC;
109     (void)getline(cin, mode);
110     if (mode == "" || mode == "0") {
111         audioFormatType = AudioBufferFormatType::TYPE_AAC;
112     } else if (mode == "1") {
113         audioFormatType = AudioBufferFormatType::TYPE_FLAC;
114     } else if (mode == "2") {
115         audioFormatType = AudioBufferFormatType::TYPE_MP3;
116     } else if (mode == "3") {
117         audioFormatType = AudioBufferFormatType::TYPE_VORBIS;
118     } else if (mode == "4") {
119         audioFormatType = AudioBufferFormatType::TYPE_AMRNB;
120     } else if (mode == "5") {
121         audioFormatType = AudioBufferFormatType::TYPE_AMRWB;
122     } else if (mode == "6") {
123         audioFormatType = AudioBufferFormatType::TYPE_G711MU;
124     } else {
125         cout << "no that selection" << endl;
126         return 0;
127     }
128     auto audioDec = std::make_unique<ADecBufferDemo>();
129     audioDec->RunCase(audioFormatType);
130     cout << "demo audio decoder end" << endl;
131     return 0;
132 }
133 
RunAudioEncoder()134 static int RunAudioEncoder()
135 {
136     cout << "Please select number for format (default AAC Encoder): " << endl;
137     cout << "0: AAC" << endl;
138     cout << "1: FLAC" << endl;
139     cout << "2: OPUS" << endl;
140     cout << "3: G711MU" << endl;
141     cout << "4: AAC-API11" << endl;
142     cout << "5: FLAC-API11" << endl;
143     cout << "6: G711MU-API11" << endl;
144     string mode;
145     (void)getline(cin, mode);
146     if (mode == "" || mode == "0") {
147         auto audioEnc = std::make_unique<AEncAacDemo>();
148         audioEnc->RunCase();
149     } else if (mode == "1") {
150         auto audioEnc = std::make_unique<AEncFlacDemo>();
151         audioEnc->RunCase();
152     } else if (mode == "2") {
153         auto audioEnc = std::make_unique<AEncOpusDemo>();
154         audioEnc->RunCase();
155     } else if (mode == "3") {
156         auto audioEnc = std::make_unique<AEncG711muDemo>();
157         audioEnc->RunCase();
158     } else if (mode == "4") {
159         auto audioEnc = std::make_unique<AudioBufferAacEncDemo>();
160         audioEnc->RunCase();
161     } else if (mode == "5") {
162         auto audioEnc = std::make_unique<AudioBufferFlacEncDemo>();
163         audioEnc->RunCase();
164     } else if (mode == "6") {
165         auto audioEnc = std::make_unique<AEncAvbufferG711muDemo>();
166         audioEnc->RunCase();
167     } else {
168         cout << "no that selection" << endl;
169         return 0;
170     }
171     cout << "demo audio encoder end" << endl;
172     return 0;
173 }
174 
RunAudioInnerDecoder()175 static int RunAudioInnerDecoder()
176 {
177     cout << "Please select number for format (default AAC Decoder): " << endl;
178     cout << "0: AAC" << endl;
179     cout << "1: FLAC" << endl;
180     cout << "2: MP3" << endl;
181     cout << "3: VORBIS" << endl;
182     cout << "4: DecoderInner-API11" << endl;
183     string mode;
184     (void)getline(cin, mode);
185     if (mode == "" || mode == "0") {
186         auto audioDec = std::make_unique<ADecInnerDemo>();
187         audioDec->RunCase();
188     } else if (mode == "1") {
189         auto audioDec = std::make_unique<ADecInnerDemo>();
190         audioDec->RunCase();
191     } else if (mode == "2") {
192         auto audioDec = std::make_unique<ADecInnerDemo>();
193         audioDec->RunCase();
194     } else if (mode == "3") {
195         auto audioDec = std::make_unique<ADecInnerDemo>();
196         audioDec->RunCase();
197     } else if (mode == "4") {
198         auto audioDec = std::make_unique<AudioDecInnerAvBufferDemo>();
199         audioDec->RunCase();
200     } else {
201         cout << "no that selection" << endl;
202         return 0;
203     }
204     cout << "demo audio decoder end" << endl;
205     return 0;
206 }
207 
RunAudioInnerEncoder()208 static int RunAudioInnerEncoder()
209 {
210     cout << "Please select number for format (default AAC Encoder): " << endl;
211     cout << "0: AAC" << endl;
212     cout << "1: FLAC" << endl;
213     string mode;
214     (void)getline(cin, mode);
215     if (mode == "" || mode == "0") {
216         auto audioEnc = std::make_unique<AEnInnerDemo>();
217         audioEnc->RunCase();
218     } else if (mode == "1") {
219         auto audioEnc = std::make_unique<AEnInnerDemo>();
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 
RunCodecList()229 static int RunCodecList()
230 {
231     auto codecList = std::make_unique<CodecListDemo>();
232     if (codecList == nullptr) {
233         cout << "codec list is null" << endl;
234         return 0;
235     }
236     codecList->RunCase();
237     cout << "codec list end" << endl;
238     return 0;
239 }
240 
RunVideoDecoder()241 static int RunVideoDecoder()
242 {
243     cout << "Please select number for output mode (default buffer mode): " << endl;
244     cout << "0: buffer" << endl;
245     cout << "1: surface file" << endl;
246     cout << "2: surface render" << endl;
247 
248     string mode;
249     (void)getline(cin, mode);
250     if (mode != "0" && mode != "1" && mode != "2") {
251         cout << "parameter invalid" << endl;
252         return 0;
253     }
254 
255     auto videoDec = std::make_unique<VDecDemo>();
256     if (videoDec == nullptr) {
257         cout << "video decoder is null" << endl;
258         return 0;
259     }
260     videoDec->RunCase(mode);
261     cout << "demo video decoder end" << endl;
262     return 0;
263 }
264 
RunVideoDecoderDrm()265 static int RunVideoDecoderDrm()
266 {
267     cout << "RunVideoDecoderDrm: " << endl;
268     cout << "Please select number for output mode (default buffer mode): " << endl;
269     cout << "0: buffer" << endl;
270     cout << "1: surface file" << endl;
271     cout << "2: surface render" << endl;
272 
273     string mode;
274     (void)getline(cin, mode);
275     if (mode != "0" && mode != "1" && mode != "2") {
276         cout << "parameter invalid" << endl;
277         return 0;
278     }
279 
280     auto videoDec = std::make_unique<VDecDemo>();
281     if (videoDec == nullptr) {
282         cout << "video decoder is null" << endl;
283         return 0;
284     }
285     videoDec->RunDrmCase();
286     cout << "demo video decoder end" << endl;
287     return 0;
288 }
289 
RunVideoInnerDecoder()290 static int RunVideoInnerDecoder()
291 {
292     cout << "Please select number for output mode (default buffer mode): " << endl;
293     cout << "0: buffer" << endl;
294     cout << "1: surface file" << endl;
295     cout << "2: surface render" << endl;
296 
297     string mode;
298     (void)getline(cin, mode);
299     if (mode != "0" && mode != "1" && mode != "2") {
300         cout << "parameter invalid" << endl;
301         return 0;
302     }
303 
304     auto videoDec = std::make_unique<VDecInnerDemo>();
305     if (videoDec == nullptr) {
306         cout << "video decoder is null" << endl;
307         return 0;
308     }
309     videoDec->RunCase(mode);
310     cout << "demo video decoder end" << endl;
311     return 0;
312 }
313 
RunE2EDemo()314 static int RunE2EDemo()
315 {
316     cout << "Please select number for api version (default api11): " << endl;
317     cout << "0: api11" << endl;
318     cout << "1: api10" << endl;
319 
320     string mode;
321     (void)getline(cin, mode);
322     if (mode != "0" && mode != "1") {
323         cout << "parameter invalid" << endl;
324         return 0;
325     }
326     const char *path = "/data/test/media/input.mp4";
327     if (mode == "0") {
328         auto e2eDemo = std::make_unique<AVCodecE2EDemo>(path);
329         if (e2eDemo == nullptr) {
330             cout << "e2eDemo is null" << endl;
331             return 0;
332         }
333         e2eDemo->Configure();
334         e2eDemo->Start();
335         e2eDemo->WaitForEOS();
336         e2eDemo->Stop();
337     } else if (mode == "1") {
338         auto e2eDemo = std::make_unique<AVCodecE2EDemoAPI10>(path);
339         if (e2eDemo == nullptr) {
340             cout << "e2eDemo is null" << endl;
341             return 0;
342         }
343         e2eDemo->Configure();
344         e2eDemo->Start();
345         e2eDemo->WaitForEOS();
346         e2eDemo->Stop();
347     }
348     cout << "e2eDemo end" << endl;
349     return 0;
350 }
351 
OptionPrint()352 static void OptionPrint()
353 {
354     cout << "Please select a demo scenario number(default Audio Decoder): " << endl;
355     cout << "0:Audio Decoder" << endl;
356     cout << "1:Audio Encoder" << endl;
357     cout << "2:Audio Inner Decoder" << endl;
358     cout << "3:Audio Inner Encoder" << endl;
359     cout << "4:muxer demo" << endl;
360     cout << "6:codeclist" << endl;
361     cout << "7:Video Decoder" << endl;
362     cout << "8:Video Inner Decoder" << endl;
363     cout << "9:demuxer demo" << endl;
364     cout << "10:Audio AVBuffer Decoder" << endl;
365     cout << "11:Video Decoder DRM" << endl;
366     cout << "12:E2E demo" << endl;
367 }
368 
main()369 int main()
370 {
371     OptionPrint();
372     string mode;
373     (void)getline(cin, mode);
374     if (mode == "" || mode == "0") {
375         (void)RunAudioDecoder();
376     } else if (mode == "1") {
377         (void)RunAudioEncoder();
378     } else if (mode == "2") {
379         (void)RunAudioInnerDecoder();
380     } else if (mode == "3") {
381         (void)RunAudioInnerEncoder();
382     } else if (mode == "4") {
383         (void)AVMuxerDemoCase();
384     } else if (mode == "6") {
385         (void)RunCodecList();
386     } else if (mode == "7") {
387         (void)RunVideoDecoder();
388     } else if (mode == "8") {
389         (void)RunVideoInnerDecoder();
390     } else if (mode == "9") {
391         (void)AVSourceDemuxerDemoCase();
392     } else if (mode == "10") {
393         (void)RunAudioAVBufferDecoder();
394     } else if (mode == "11") {
395         (void)RunVideoDecoderDrm();
396     } else if (mode == "12") {
397         (void)RunE2EDemo();
398     } else {
399         cout << "no that selection" << endl;
400     }
401     return 0;
402 }
403