1 /*
2  * test-tcmoduleinfo.c -- testsuite for tcmoduleinfo* functions;
3  *                        everyone feel free to add more tests and improve
4  *                        existing ones.
5  * (C) 2006-2010 - Francesco Romani <fromani -at- gmail -dot- com>
6  *
7  * This file is part of transcode, a video stream processing tool.
8  *
9  * transcode is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * transcode is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 
24 
25 #include "src/transcode.h"
26 #include "libtc/tcmodule-info.h"
27 #include "libtc/tccodecs.h"
28 
29 static const TCCodecID empty_codecs[] = { TC_CODEC_ERROR };
30 static TCModuleInfo empty = {
31     TC_MODULE_FEATURE_NONE,
32     TC_MODULE_FLAG_NONE,
33     "",
34     "",
35     "",
36     empty_codecs,
37     empty_codecs
38 };
39 
40 static const TCCodecID pass_enc_codecs[] = { TC_CODEC_ANY, TC_CODEC_ERROR };
41 static TCModuleInfo pass_enc = {
42     TC_MODULE_FEATURE_ENCODE | TC_MODULE_FEATURE_VIDEO
43         | TC_MODULE_FEATURE_AUDIO | TC_MODULE_FEATURE_EXTRA,
44     TC_MODULE_FLAG_RECONFIGURABLE,
45     "encode_pass.so",
46     "0.0.1 (2005-11-14)",
47     "accepts everything, outputs verbatim",
48     pass_enc_codecs,
49     pass_enc_codecs
50 };
51 
52 static const TCCodecID fake_pcm_codecs[] = { TC_CODEC_PCM, TC_CODEC_ERROR };
53 static TCModuleInfo fake_wav_mplex = {
54     TC_MODULE_FEATURE_MULTIPLEX | TC_MODULE_FEATURE_AUDIO,
55     TC_MODULE_FLAG_RECONFIGURABLE,
56     "mplex_wav.so",
57     "0.0.1 (2006-06-11)",
58     "accepts pcm, writes wav (fake!)",
59     fake_pcm_codecs,
60     empty_codecs
61 };
62 
63 static const TCCodecID fake_yuv_codecs[] = { TC_CODEC_YUV420P, TC_CODEC_ERROR };
64 static TCModuleInfo fake_y4m_mplex = {
65     TC_MODULE_FEATURE_MULTIPLEX | TC_MODULE_FEATURE_VIDEO,
66     TC_MODULE_FLAG_RECONFIGURABLE,
67     "mplex_y4m.so",
68     "0.0.1 (2006-06-11)",
69     "accepts yuv420p, writes YUV4MPEG2 (fake!)",
70     fake_yuv_codecs,
71     empty_codecs
72 };
73 
74 
75 static const TCCodecID fake_mplex_codecs[] = { TC_CODEC_ANY, TC_CODEC_ERROR };
76 static TCModuleInfo fake_mplex = {
77     TC_MODULE_FEATURE_MULTIPLEX | TC_MODULE_FEATURE_VIDEO
78         | TC_MODULE_FEATURE_AUDIO | TC_MODULE_FEATURE_EXTRA,
79     TC_MODULE_FLAG_RECONFIGURABLE,
80     "mplex_null.so",
81     "0.0.1 (2005-11-14)",
82     "accepts and discards everything",
83     fake_mplex_codecs,
84     empty_codecs
85 };
86 
87 static const TCCodecID pcm_pass_codecs[] = { TC_CODEC_PCM, TC_CODEC_ERROR };
88 static TCModuleInfo pcm_pass = {
89     TC_MODULE_FEATURE_ENCODE | TC_MODULE_FEATURE_AUDIO,
90     TC_MODULE_FLAG_RECONFIGURABLE,
91     "encode_pcm.so",
92     "0.0.1 (2006-03-11)",
93     "passthrough pcm",
94     pcm_pass_codecs,
95     pcm_pass_codecs
96 };
97 
98 static const TCCodecID yuv_pass_codecs[] = { TC_CODEC_YUV420P, TC_CODEC_ERROR };
99 static TCModuleInfo yuv_pass = {
100     TC_MODULE_FEATURE_ENCODE | TC_MODULE_FEATURE_VIDEO,
101     TC_MODULE_FLAG_RECONFIGURABLE,
102     "encode_yuv.so",
103     "0.0.1 (2006-03-11)",
104     "passthrough yuv",
105     yuv_pass_codecs,
106     yuv_pass_codecs
107 };
108 
109 static const TCCodecID fake_mpeg_codecs_in[] = { TC_CODEC_YUV420P, TC_CODEC_ERROR };
110 static const TCCodecID fake_mpeg_codecs_out[] = { TC_CODEC_MPEG1VIDEO, TC_CODEC_MPEG2VIDEO, TC_CODEC_XVID, TC_CODEC_ERROR };
111 static TCModuleInfo fake_mpeg_enc = {
112     TC_MODULE_FEATURE_ENCODE | TC_MODULE_FEATURE_VIDEO,
113     TC_MODULE_FLAG_NONE,
114     "encode_mpeg.so",
115     "0.0.1 (2005-11-14)",
116     "fake YUV420P -> MPEG video encoder",
117     fake_mpeg_codecs_in,
118     fake_mpeg_codecs_out
119 };
120 
121 static const TCCodecID fake_vorbis_codecs_in[] = { TC_CODEC_PCM, TC_CODEC_ERROR };
122 static const TCCodecID fake_vorbis_codecs_out[] = { TC_CODEC_VORBIS, TC_CODEC_ERROR };
123 static TCModuleInfo fake_vorbis_enc = {
124     TC_MODULE_FEATURE_ENCODE | TC_MODULE_FEATURE_AUDIO,
125     TC_MODULE_FLAG_NONE,
126     "encode_vorbis.so",
127     "0.0.1 (2005-11-14)",
128     "fake PCM -> Vorbis audio encoder",
129     fake_vorbis_codecs_in,
130     fake_vorbis_codecs_out
131 };
132 
133 static const TCCodecID fake_avi_codecs_in[] = {
134         TC_CODEC_MPEG1VIDEO, TC_CODEC_XVID, TC_CODEC_YUV420P,
135         TC_CODEC_MP3, TC_CODEC_PCM,
136         TC_CODEC_ERROR
137 };
138 static TCModuleInfo fake_avi_mplex = {
139     TC_MODULE_FEATURE_MULTIPLEX | TC_MODULE_FEATURE_VIDEO
140         | TC_MODULE_FEATURE_AUDIO,
141     TC_MODULE_FLAG_NONE,
142     "mplex_avi.so",
143     "0.0.1 (2005-11-14)",
144     "fakes an AVI muxer",
145     fake_avi_codecs_in,
146     empty_codecs
147  };
148 
149 
test_match_helper(int codec,const TCModuleInfo * m1,const TCModuleInfo * m2,int expected)150 static int test_match_helper(int codec,
151                               const TCModuleInfo *m1,
152                               const TCModuleInfo *m2,
153                               int expected)
154 {
155     int match = tc_module_info_match(codec, m1, m2);
156     int err = 0;
157 #ifdef VERBOSE
158     const char *str = tc_codec_to_string(codec);
159 
160     tc_log_msg(__FILE__, "codec: %s (0x%x)", str, codec);
161 #endif
162     if (match != expected) {
163         tc_log_error(__FILE__, "'%s' <-%c-> '%s' FAILED",
164                         m1->name,
165                         (expected == 1) ?'-' :'!',
166                         m2->name);
167         err = 1;
168     } else {
169         tc_log_info(__FILE__, "'%s' <-%c-> '%s' OK",
170                         m1->name,
171                         (expected == 1) ?'-' :'!',
172                         m2->name);
173     }
174     return err;
175 }
176 
test_module_match(void)177 static int test_module_match(void)
178 {
179     int errors = 0;
180 
181     errors += test_match_helper(TC_CODEC_ANY, &empty, &empty, 0);
182     errors += test_match_helper(TC_CODEC_ANY, &empty, &fake_mpeg_enc, 0);
183     errors += test_match_helper(TC_CODEC_ANY, &fake_mpeg_enc, &empty, 0);
184 
185     errors += test_match_helper(TC_CODEC_ANY, &pass_enc, &fake_mplex, 1);
186     errors += test_match_helper(TC_CODEC_ANY, &pass_enc, &fake_avi_mplex, 1);
187     errors += test_match_helper(TC_CODEC_ANY, &pcm_pass, &fake_avi_mplex, 1);
188     errors += test_match_helper(TC_CODEC_PCM, &pass_enc, &fake_avi_mplex, 1);
189 
190 //  this is tricky. Should fail since there are two *encoders* chained
191 //  and this make no sense *in our current architecture*.
192 //  but from tcmoduleinfo infrastructure POV, it make perfectly sense (yet)
193 //  since encoders involved have compatible I/O capabilties, so it doesn't fail.
194 //    errors += test_match_helper(TC_CODEC_ANY, &pass_enc, &fake_mpeg_enc, 0);
195 
196     errors += test_match_helper(TC_CODEC_MPEG2VIDEO, &fake_mpeg_enc, &fake_vorbis_enc, 0);
197     errors += test_match_helper(TC_CODEC_ANY, &fake_mpeg_enc, &fake_mplex, 1);
198     errors += test_match_helper(TC_CODEC_MPEG1VIDEO, &fake_mpeg_enc, &fake_mplex, 1);
199     errors += test_match_helper(TC_CODEC_ANY, &fake_mpeg_enc, &fake_avi_mplex, 1);
200     errors += test_match_helper(TC_CODEC_MPEG1VIDEO, &fake_mpeg_enc, &fake_avi_mplex, 1);
201     errors += test_match_helper(TC_CODEC_XVID, &fake_mpeg_enc, &fake_avi_mplex, 1);
202 
203     errors += test_match_helper(TC_CODEC_VORBIS, &fake_vorbis_enc, &fake_mpeg_enc, 0);
204     errors += test_match_helper(TC_CODEC_VORBIS, &fake_vorbis_enc, &fake_mplex, 1);
205     errors += test_match_helper(TC_CODEC_VORBIS, &fake_vorbis_enc, &fake_avi_mplex, 0);
206 
207     errors += test_match_helper(TC_CODEC_PCM, &pcm_pass, &fake_wav_mplex, 1);
208     errors += test_match_helper(TC_CODEC_PCM, &pcm_pass, &fake_y4m_mplex, 0);
209     errors += test_match_helper(TC_CODEC_MPEG1VIDEO, &fake_mpeg_enc, &fake_wav_mplex, 0);
210 
211     errors += test_match_helper(TC_CODEC_YUV420P, &yuv_pass, &fake_y4m_mplex, 1);
212     errors += test_match_helper(TC_CODEC_YUV420P, &yuv_pass, &fake_wav_mplex, 0);
213     errors += test_match_helper(TC_CODEC_YUV420P, &yuv_pass, &fake_avi_mplex, 1);
214     errors += test_match_helper(TC_CODEC_YUV420P, &yuv_pass, &fake_mplex, 1);
215 
216     return errors;
217 }
218 
main(void)219 int main(void)
220 {
221     int errors = test_module_match();
222 
223     putchar('\n');
224     tc_log_info(__FILE__, "test summary: %i error%s (%s)",
225                 errors,
226                 (errors > 1) ?"s" :"",
227                 (errors > 0) ?"FAILED" :"PASSED");
228     return (errors > 0) ?1 :0;
229 }
230 
231 /*************************************************************************/
232 
233 /*
234  * Local variables:
235  *   c-file-style: "stroustrup"
236  *   c-file-offsets: ((case-label . *) (statement-case-intro . *))
237  *   indent-tabs-mode: nil
238  * End:
239  *
240  * vim: expandtab shiftwidth=4:
241  */
242