• 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_flac_encoder_demo.h"
26 #include "codeclist_demo.h"
27 #include "avcodec_video_decoder_demo.h"
28 #include "avcodec_video_decoder_inner_demo.h"
29 
30 using namespace OHOS;
31 using namespace OHOS::MediaAVCodec;
32 using namespace OHOS::MediaAVCodec::AudioDemo;
33 using namespace OHOS::MediaAVCodec::AudioFlacDemo;
34 using namespace OHOS::MediaAVCodec::AudioAacDemo;
35 using namespace OHOS::MediaAVCodec::InnerAudioDemo;
36 using namespace OHOS::MediaAVCodec::VideoDemo;
37 using namespace OHOS::MediaAVCodec::InnerVideoDemo;
38 using namespace std;
39 
RunAudioDecoder()40 static int RunAudioDecoder()
41 {
42     cout << "Please select number for format (default AAC Decoder): " << endl;
43     cout << "0: AAC" << endl;
44     cout << "1: FLAC" << endl;
45     cout << "2: MP3" << endl;
46     cout << "3: VORBIS" << endl;
47     string mode;
48     AudioFormatType audioFormatType = TYPE_AAC;
49     (void)getline(cin, mode);
50     if (mode == "" || mode == "0") {
51         audioFormatType = TYPE_AAC;
52     } else if (mode == "1") {
53         audioFormatType = TYPE_FLAC;
54     } else if (mode == "2") {
55         audioFormatType = TYPE_MP3;
56     } else if (mode == "3") {
57         audioFormatType = TYPE_VORBIS;
58     } else {
59         cout << "no that selection" << endl;
60         return 0;
61     }
62     auto audioDec = std::make_unique<ADecDemo>();
63     audioDec->RunCase(audioFormatType);
64     cout << "demo audio decoder end" << endl;
65     return 0;
66 }
67 
RunAudioEncoder()68 static int RunAudioEncoder()
69 {
70     cout << "Please select number for format (default AAC Encoder): " << endl;
71     cout << "0: AAC" << endl;
72     cout << "1: FLAC" << endl;
73 
74     string mode;
75     (void)getline(cin, mode);
76     if (mode == "" || mode == "0") {
77         auto audioEnc = std::make_unique<AEncAacDemo>();
78         audioEnc->RunCase();
79     } else if (mode == "1") {
80         auto audioEnc = std::make_unique<AEncFlacDemo>();
81         audioEnc->RunCase();
82     } else {
83         cout << "no that selection" << endl;
84         return 0;
85     }
86     cout << "demo audio encoder end" << endl;
87     return 0;
88 }
89 
RunAudioInnerDecoder()90 static int RunAudioInnerDecoder()
91 {
92     cout << "Please select number for format (default AAC Decoder): " << endl;
93     cout << "0: AAC" << endl;
94     cout << "1: FLAC" << endl;
95     cout << "2: MP3" << endl;
96     cout << "3: VORBIS" << endl;
97     string mode;
98     (void)getline(cin, mode);
99     if (mode == "" || mode == "0") {
100         auto audioDec = std::make_unique<ADecInnerDemo>();
101         audioDec->RunCase();
102     } else if (mode == "1") {
103         auto audioDec = std::make_unique<ADecInnerDemo>();
104         audioDec->RunCase();
105     } else if (mode == "2") {
106         auto audioDec = std::make_unique<ADecInnerDemo>();
107         audioDec->RunCase();
108     } else if (mode == "3") {
109         auto audioDec = std::make_unique<ADecInnerDemo>();
110         audioDec->RunCase();
111     } else {
112         cout << "no that selection" << endl;
113         return 0;
114     }
115     cout << "demo audio decoder end" << endl;
116     return 0;
117 }
118 
RunAudioInnerEncoder()119 static int RunAudioInnerEncoder()
120 {
121     cout << "Please select number for format (default AAC Encoder): " << endl;
122     cout << "0: AAC" << endl;
123     cout << "1: FLAC" << endl;
124     string mode;
125     (void)getline(cin, mode);
126     if (mode == "" || mode == "0") {
127         auto audioEnc = std::make_unique<AEnInnerDemo>();
128         audioEnc->RunCase();
129     } else if (mode == "1") {
130         auto audioEnc = std::make_unique<AEnInnerDemo>();
131         audioEnc->RunCase();
132     } else {
133         cout << "no that selection" << endl;
134         return 0;
135     }
136     cout << "demo audio encoder end" << endl;
137     return 0;
138 }
139 
RunCodecList()140 static int RunCodecList()
141 {
142     auto codecList = std::make_unique<CodecListDemo>();
143     if (codecList == nullptr) {
144         cout << "codec list is null" << endl;
145         return 0;
146     }
147     codecList->RunCase();
148     cout << "codec list end" << endl;
149     return 0;
150 }
151 
RunVideoDecoder()152 static int RunVideoDecoder()
153 {
154     cout << "Please select number for output mode (default buffer mode): " << endl;
155     cout << "0: buffer" << endl;
156     cout << "1: surface file" << endl;
157     cout << "2: surface render" << endl;
158 
159     string mode;
160     (void)getline(cin, mode);
161     if (mode != "0" && mode != "1" && mode != "2") {
162         cout << "parameter invalid" << endl;
163         return 0;
164     }
165 
166     auto videoDec = std::make_unique<VDecDemo>();
167     if (videoDec == nullptr) {
168         cout << "video decoder is null" << endl;
169         return 0;
170     }
171     videoDec->RunCase(mode);
172     cout << "demo video decoder end" << endl;
173     return 0;
174 }
175 
RunVideoInnerDecoder()176 static int RunVideoInnerDecoder()
177 {
178     cout << "Please select number for output mode (default buffer mode): " << endl;
179     cout << "0: buffer" << endl;
180     cout << "1: surface file" << endl;
181     cout << "2: surface render" << endl;
182 
183     string mode;
184     (void)getline(cin, mode);
185     if (mode != "0" && mode != "1" && mode != "2") {
186         cout << "parameter invalid" << endl;
187         return 0;
188     }
189 
190     auto videoDec = std::make_unique<VDecInnerDemo>();
191     if (videoDec == nullptr) {
192         cout << "video decoder is null" << endl;
193         return 0;
194     }
195     videoDec->RunCase(mode);
196     cout << "demo video decoder end" << endl;
197     return 0;
198 }
199 
OptionPrint()200 static void OptionPrint()
201 {
202     cout << "Please select a demo scenario number(default Audio Decoder): " << endl;
203     cout << "0:Audio Decoder" << endl;
204     cout << "1:Audio Encoder" << endl;
205     cout << "2:Audio Inner Decoder" << endl;
206     cout << "3:Audio Inner Encoder" << endl;
207     cout << "4:muxer demo" << endl;
208     cout << "6:codeclist" << endl;
209     cout << "7:Video Decoder" << endl;
210     cout << "8:Video Inner Decoder" << endl;
211     cout << "9:demuxer demo" << endl;
212 }
213 
main()214 int main()
215 {
216     OptionPrint();
217     string mode;
218     (void)getline(cin, mode);
219     if (mode == "" || mode == "0") {
220         (void)RunAudioDecoder();
221     } else if (mode == "1") {
222         (void)RunAudioEncoder();
223     } else if (mode == "2") {
224         (void)RunAudioInnerDecoder();
225     } else if (mode == "3") {
226         (void)RunAudioInnerEncoder();
227     } else if (mode == "4") {
228         (void)AvmuxerDemoCase();
229     } else if (mode == "6") {
230         (void)RunCodecList();
231     } else if (mode == "7") {
232         (void)RunVideoDecoder();
233     } else if (mode == "8") {
234         (void)RunVideoInnerDecoder();
235     } else if (mode == "9") {
236         (void)AVSourceDemuxerDemoCase();
237     } else {
238         cout << "no that selection" << endl;
239     }
240     return 0;
241 }
242