]>
Commit | Line | Data |
---|---|---|
1 | //! Routines for testing decoders. | |
2 | use std::fs::File; | |
3 | use std::io::prelude::*; | |
4 | use nihav_core::frame::*; | |
5 | use nihav_core::codecs::*; | |
6 | use nihav_core::demuxers::*; | |
7 | //use nihav_core::io::byteio::*; | |
8 | use nihav_core::scale::*; | |
9 | use super::wavwriter::WavWriter; | |
10 | use super::md5::MD5; | |
11 | pub use super::ExpectedTestResult; | |
12 | ||
13 | const OUTPUT_PREFIX: &str = "assets/test_out"; | |
14 | ||
15 | fn write_pgmyuv(pfx: &str, strno: usize, num: u64, frm: NAFrameRef) { | |
16 | if let NABufferType::None = frm.get_buffer() { return; } | |
17 | let name = format!("{}/{}out{:02}_{:06}.pgm", OUTPUT_PREFIX, pfx, strno, num); | |
18 | let mut ofile = File::create(name).unwrap(); | |
19 | let buf = frm.get_buffer().get_vbuf().unwrap(); | |
20 | let (w, h) = buf.get_dimensions(0); | |
21 | let (w2, h2) = buf.get_dimensions(1); | |
22 | let has_alpha = buf.get_info().get_format().has_alpha(); | |
23 | let mut tot_h = h + h2; | |
24 | if has_alpha { | |
25 | tot_h += h; | |
26 | } | |
27 | if w2 > w/2 { | |
28 | tot_h += h2; | |
29 | } | |
30 | let hdr = format!("P5\n{} {}\n255\n", w, tot_h); | |
31 | ofile.write_all(hdr.as_bytes()).unwrap(); | |
32 | let dta = buf.get_data(); | |
33 | let ls = buf.get_stride(0); | |
34 | let mut idx = 0; | |
35 | let mut idx2 = w; | |
36 | let is_flipped = buf.get_info().is_flipped(); | |
37 | if is_flipped { | |
38 | idx += h * ls; | |
39 | idx2 += h * ls; | |
40 | } | |
41 | for _ in 0..h { | |
42 | if is_flipped { | |
43 | idx -= ls; | |
44 | idx2 -= ls; | |
45 | } | |
46 | let line = &dta[idx..idx2]; | |
47 | ofile.write_all(line).unwrap(); | |
48 | if !is_flipped { | |
49 | idx += ls; | |
50 | idx2 += ls; | |
51 | } | |
52 | } | |
53 | if w2 <= w/2 { | |
54 | let pad: Vec<u8> = vec![0xFF; (w - w2 * 2) / 2]; | |
55 | let mut base1 = buf.get_offset(1); | |
56 | let stride1 = buf.get_stride(1); | |
57 | let mut base2 = buf.get_offset(2); | |
58 | let stride2 = buf.get_stride(2); | |
59 | if is_flipped { | |
60 | base1 += h2 * stride1; | |
61 | base2 += h2 * stride2; | |
62 | } | |
63 | for _ in 0..h2 { | |
64 | if is_flipped { | |
65 | base1 -= stride1; | |
66 | base2 -= stride2; | |
67 | } | |
68 | let bend1 = base1 + w2; | |
69 | let line = &dta[base1..bend1]; | |
70 | ofile.write_all(line).unwrap(); | |
71 | ofile.write_all(pad.as_slice()).unwrap(); | |
72 | ||
73 | let bend2 = base2 + w2; | |
74 | let line = &dta[base2..bend2]; | |
75 | ofile.write_all(line).unwrap(); | |
76 | ofile.write_all(pad.as_slice()).unwrap(); | |
77 | ||
78 | if !is_flipped { | |
79 | base1 += stride1; | |
80 | base2 += stride2; | |
81 | } | |
82 | } | |
83 | } else { | |
84 | let pad: Vec<u8> = vec![0xFF; w - w2]; | |
85 | let mut base1 = buf.get_offset(1); | |
86 | let stride1 = buf.get_stride(1); | |
87 | if is_flipped { | |
88 | base1 += h2 * stride1; | |
89 | } | |
90 | for _ in 0..h2 { | |
91 | if is_flipped { | |
92 | base1 -= stride1; | |
93 | } | |
94 | let bend1 = base1 + w2; | |
95 | let line = &dta[base1..bend1]; | |
96 | ofile.write_all(line).unwrap(); | |
97 | ofile.write_all(pad.as_slice()).unwrap(); | |
98 | if !is_flipped { | |
99 | base1 += stride1; | |
100 | } | |
101 | } | |
102 | let mut base2 = buf.get_offset(2); | |
103 | let stride2 = buf.get_stride(2); | |
104 | if is_flipped { | |
105 | base2 += h2 * stride2; | |
106 | } | |
107 | for _ in 0..h2 { | |
108 | if is_flipped { | |
109 | base2 -= stride2; | |
110 | } | |
111 | let bend2 = base2 + w2; | |
112 | let line = &dta[base2..bend2]; | |
113 | ofile.write_all(line).unwrap(); | |
114 | ofile.write_all(pad.as_slice()).unwrap(); | |
115 | if !is_flipped { | |
116 | base2 += stride2; | |
117 | } | |
118 | } | |
119 | } | |
120 | if has_alpha { | |
121 | let ls = buf.get_stride(3); | |
122 | let mut idx = buf.get_offset(3); | |
123 | let mut idx2 = idx + w; | |
124 | if is_flipped { | |
125 | idx += h * ls; | |
126 | idx2 += h * ls; | |
127 | } | |
128 | for _ in 0..h { | |
129 | if is_flipped { | |
130 | idx -= ls; | |
131 | idx2 -= ls; | |
132 | } | |
133 | let line = &dta[idx..idx2]; | |
134 | ofile.write_all(line).unwrap(); | |
135 | if !is_flipped { | |
136 | idx += ls; | |
137 | idx2 += ls; | |
138 | } | |
139 | } | |
140 | } | |
141 | } | |
142 | ||
143 | fn write_palppm(pfx: &str, strno: usize, num: u64, frm: NAFrameRef) { | |
144 | let name = format!("{}/{}out{:02}_{:06}.ppm", OUTPUT_PREFIX, pfx, strno, num); | |
145 | let mut ofile = File::create(name).unwrap(); | |
146 | let buf = frm.get_buffer().get_vbuf().unwrap(); | |
147 | let (w, h) = buf.get_dimensions(0); | |
148 | let paloff = buf.get_offset(1); | |
149 | let hdr = format!("P6\n{} {}\n255\n", w, h); | |
150 | ofile.write_all(hdr.as_bytes()).unwrap(); | |
151 | let dta = buf.get_data(); | |
152 | let ls = buf.get_stride(0); | |
153 | let offs: [usize; 3] = [ | |
154 | buf.get_info().get_format().get_chromaton(0).unwrap().get_offset() as usize, | |
155 | buf.get_info().get_format().get_chromaton(1).unwrap().get_offset() as usize, | |
156 | buf.get_info().get_format().get_chromaton(2).unwrap().get_offset() as usize | |
157 | ]; | |
158 | let mut idx = 0; | |
159 | let mut line: Vec<u8> = vec![0; w * 3]; | |
160 | for _ in 0..h { | |
161 | let src = &dta[idx..(idx+w)]; | |
162 | for x in 0..w { | |
163 | let pix = src[x] as usize; | |
164 | line[x * 3 + 0] = dta[paloff + pix * 3 + offs[0]]; | |
165 | line[x * 3 + 1] = dta[paloff + pix * 3 + offs[1]]; | |
166 | line[x * 3 + 2] = dta[paloff + pix * 3 + offs[2]]; | |
167 | } | |
168 | ofile.write_all(line.as_slice()).unwrap(); | |
169 | idx += ls; | |
170 | } | |
171 | } | |
172 | ||
173 | fn write_ppm(pfx: &str, strno: usize, num: u64, frm: NAFrameRef) { | |
174 | let name = format!("{}/{}out{:02}_{:06}.ppm", OUTPUT_PREFIX, pfx, strno, num); | |
175 | let mut ofile = File::create(name).unwrap(); | |
176 | let info = frm.get_buffer().get_video_info().unwrap(); | |
177 | let mut dpic = alloc_video_buffer(NAVideoInfo::new(info.get_width(), info.get_height(), false, RGB24_FORMAT), 0).unwrap(); | |
178 | let ifmt = ScaleInfo { width: info.get_width(), height: info.get_height(), fmt: info.get_format() }; | |
179 | let ofmt = ScaleInfo { width: info.get_width(), height: info.get_height(), fmt: RGB24_FORMAT }; | |
180 | let mut scaler = NAScale::new(ifmt, ofmt).unwrap(); | |
181 | scaler.convert(&frm.get_buffer(), &mut dpic).unwrap(); | |
182 | let buf = dpic.get_vbuf().unwrap(); | |
183 | let (w, h) = buf.get_dimensions(0); | |
184 | let hdr = format!("P6\n{} {}\n255\n", w, h); | |
185 | ofile.write_all(hdr.as_bytes()).unwrap(); | |
186 | let dta = buf.get_data(); | |
187 | let stride = buf.get_stride(0); | |
188 | for src in dta.chunks(stride) { | |
189 | ofile.write_all(&src[0..w*3]).unwrap(); | |
190 | } | |
191 | } | |
192 | ||
193 | /*fn open_wav_out(pfx: &str, strno: usize) -> WavWriter { | |
194 | let name = format!("assets/{}out{:02}.wav", pfx, strno); | |
195 | let mut file = File::create(name).unwrap(); | |
196 | let mut fw = FileWriter::new_write(&mut file); | |
197 | let mut wr = ByteWriter::new(&mut fw); | |
198 | WavWriter::new(&mut wr) | |
199 | }*/ | |
200 | ||
201 | /// Tests decoding of provided file and optionally outputs video frames as PNM (PPM for RGB video, PGM for YUV). | |
202 | /// | |
203 | /// This function expects the following arguments: | |
204 | /// * `demuxer` - container format name (used to find proper demuxer for it) | |
205 | /// * `name` - input file name | |
206 | /// * `limit` - optional PTS value after which decoding is stopped | |
207 | /// * `decode_video`/`decode_audio` - flags for enabling video/audio decoding | |
208 | /// * `video_pfx` - prefix for video frames written as pictures (if enabled then output picture names should look like `<crate_name>/assets/test_out/PFXout00_000000.ppm` | |
209 | /// * `dmx_reg` and `dec_reg` - registered demuxers and decoders that should contain demuxer and decoder(s) needed to decode the provided file. | |
210 | /// | |
211 | /// Since the function is intended for tests, it will panic instead of returning an error. | |
212 | pub fn test_file_decoding(demuxer: &str, name: &str, limit: Option<u64>, | |
213 | decode_video: bool, decode_audio: bool, | |
214 | video_pfx: Option<&str>, | |
215 | dmx_reg: &RegisteredDemuxers, dec_reg: &RegisteredDecoders) { | |
216 | let dmx_f = dmx_reg.find_demuxer(demuxer).unwrap(); | |
217 | let mut file = File::open(name).unwrap(); | |
218 | let mut fr = FileReader::new_read(&mut file); | |
219 | let mut br = ByteReader::new(&mut fr); | |
220 | let mut dmx = create_demuxer(dmx_f, &mut br).unwrap(); | |
221 | ||
222 | let mut decs: Vec<Option<(Box<NADecoderSupport>, Box<dyn NADecoder>)>> = Vec::new(); | |
223 | for i in 0..dmx.get_num_streams() { | |
224 | let s = dmx.get_stream(i).unwrap(); | |
225 | let info = s.get_info(); | |
226 | let decfunc = dec_reg.find_decoder(info.get_name()); | |
227 | if let Some(df) = decfunc { | |
228 | if (decode_video && info.is_video()) || (decode_audio && info.is_audio()) { | |
229 | let mut dec = (df)(); | |
230 | let mut dsupp = Box::new(NADecoderSupport::new()); | |
231 | dec.init(&mut dsupp, info).unwrap(); | |
232 | decs.push(Some((dsupp, dec))); | |
233 | } else { | |
234 | decs.push(None); | |
235 | } | |
236 | } else { | |
237 | decs.push(None); | |
238 | } | |
239 | } | |
240 | ||
241 | loop { | |
242 | let pktres = dmx.get_frame(); | |
243 | if let Err(e) = pktres { | |
244 | if e == DemuxerError::EOF { break; } | |
245 | panic!("error"); | |
246 | } | |
247 | let pkt = pktres.unwrap(); | |
248 | let streamno = pkt.get_stream().get_id() as usize; | |
249 | if let Some((ref mut dsupp, ref mut dec)) = decs[streamno] { | |
250 | if let (Some(lim), Some(ppts)) = (limit, pkt.get_pts()) { | |
251 | if ppts > lim { break; } | |
252 | } | |
253 | let frm = dec.decode(dsupp, &pkt).unwrap(); | |
254 | if pkt.get_stream().get_info().is_video() && video_pfx.is_some() && frm.get_frame_type() != FrameType::Skip { | |
255 | let pfx = video_pfx.unwrap(); | |
256 | let pts = if let Some(fpts) = frm.get_pts() { fpts } else { pkt.get_pts().unwrap() }; | |
257 | let vinfo = frm.get_buffer().get_video_info().unwrap(); | |
258 | if vinfo.get_format().is_paletted() { | |
259 | write_palppm(pfx, streamno, pts, frm); | |
260 | } else if vinfo.get_format().get_model().is_yuv() { | |
261 | write_pgmyuv(pfx, streamno, pts, frm); | |
262 | } else if vinfo.get_format().get_model().is_rgb() { | |
263 | write_ppm(pfx, streamno, pts, frm); | |
264 | } else { | |
265 | panic!(" unknown format"); | |
266 | } | |
267 | } | |
268 | } | |
269 | } | |
270 | } | |
271 | ||
272 | /// Tests audio decoder with the content in the provided file and optionally outputs decoded audio. | |
273 | /// | |
274 | /// The syntax is very similar to [`test_file_decoding`] except that it is intended for testing audio codecs. | |
275 | /// | |
276 | /// Since the function is intended for tests, it will panic instead of returning an error. | |
277 | /// | |
278 | /// [`test_file_decoding`]: ./fn.test_file_decoding.html | |
279 | pub fn test_decode_audio(demuxer: &str, name: &str, limit: Option<u64>, audio_pfx: Option<&str>, | |
280 | dmx_reg: &RegisteredDemuxers, dec_reg: &RegisteredDecoders) { | |
281 | let dmx_f = dmx_reg.find_demuxer(demuxer).unwrap(); | |
282 | let mut file = File::open(name).unwrap(); | |
283 | let mut fr = FileReader::new_read(&mut file); | |
284 | let mut br = ByteReader::new(&mut fr); | |
285 | let mut dmx = create_demuxer(dmx_f, &mut br).unwrap(); | |
286 | ||
287 | let mut decs: Vec<Option<(Box<NADecoderSupport>, Box<dyn NADecoder>)>> = Vec::new(); | |
288 | for i in 0..dmx.get_num_streams() { | |
289 | let s = dmx.get_stream(i).unwrap(); | |
290 | let info = s.get_info(); | |
291 | let decfunc = dec_reg.find_decoder(info.get_name()); | |
292 | if let Some(df) = decfunc { | |
293 | if info.is_audio() { | |
294 | let mut dec = (df)(); | |
295 | let mut dsupp = Box::new(NADecoderSupport::new()); | |
296 | dec.init(&mut dsupp, info).unwrap(); | |
297 | decs.push(Some((dsupp, dec))); | |
298 | } else { | |
299 | decs.push(None); | |
300 | } | |
301 | } else { | |
302 | decs.push(None); | |
303 | } | |
304 | } | |
305 | ||
306 | if let Some(audio_pfx) = audio_pfx { | |
307 | let name = format!("{}/{}out.wav", OUTPUT_PREFIX, audio_pfx); | |
308 | let file = File::create(name).unwrap(); | |
309 | let mut fw = FileWriter::new_write(file); | |
310 | let mut wr = ByteWriter::new(&mut fw); | |
311 | let mut wwr = WavWriter::new(&mut wr); | |
312 | let mut wrote_header = false; | |
313 | ||
314 | loop { | |
315 | let pktres = dmx.get_frame(); | |
316 | if let Err(e) = pktres { | |
317 | if e == DemuxerError::EOF { break; } | |
318 | panic!("error"); | |
319 | } | |
320 | let pkt = pktres.unwrap(); | |
321 | if limit.is_some() && pkt.get_pts().is_some() && pkt.get_pts().unwrap() > limit.unwrap() { | |
322 | break; | |
323 | } | |
324 | let streamno = pkt.get_stream().get_id() as usize; | |
325 | if let Some((ref mut dsupp, ref mut dec)) = decs[streamno] { | |
326 | let frm = dec.decode(dsupp, &pkt).unwrap(); | |
327 | if frm.get_info().is_audio() { | |
328 | if !wrote_header { | |
329 | wwr.write_header(frm.get_info().as_ref().get_properties().get_audio_info().unwrap()).unwrap(); | |
330 | wrote_header = true; | |
331 | } | |
332 | wwr.write_frame(frm.get_buffer()).unwrap(); | |
333 | } | |
334 | } | |
335 | } | |
336 | } else { | |
337 | loop { | |
338 | let pktres = dmx.get_frame(); | |
339 | if let Err(e) = pktres { | |
340 | if e == DemuxerError::EOF { break; } | |
341 | panic!("error"); | |
342 | } | |
343 | let pkt = pktres.unwrap(); | |
344 | if limit.is_some() && pkt.get_pts().is_some() && pkt.get_pts().unwrap() > limit.unwrap() { | |
345 | break; | |
346 | } | |
347 | let streamno = pkt.get_stream().get_id() as usize; | |
348 | if let Some((ref mut dsupp, ref mut dec)) = decs[streamno] { | |
349 | let _ = dec.decode(dsupp, &pkt).unwrap(); | |
350 | } | |
351 | } | |
352 | } | |
353 | } | |
354 | ||
355 | fn frame_checksum(md5: &mut MD5, frm: NAFrameRef) { | |
356 | match frm.get_buffer() { | |
357 | NABufferType::Video(ref vb) => { | |
358 | md5.update_hash(vb.get_data()); | |
359 | }, | |
360 | NABufferType::Video16(ref vb) => { | |
361 | let mut samp = [0u8; 2]; | |
362 | let data = vb.get_data(); | |
363 | for el in data.iter() { | |
364 | samp[0] = (*el >> 8) as u8; | |
365 | samp[1] = (*el >> 0) as u8; | |
366 | md5.update_hash(&samp); | |
367 | } | |
368 | }, | |
369 | NABufferType::Video32(ref vb) => { | |
370 | let mut samp = [0u8; 4]; | |
371 | let data = vb.get_data(); | |
372 | for el in data.iter() { | |
373 | samp[0] = (*el >> 24) as u8; | |
374 | samp[1] = (*el >> 16) as u8; | |
375 | samp[2] = (*el >> 8) as u8; | |
376 | samp[3] = (*el >> 0) as u8; | |
377 | md5.update_hash(&samp); | |
378 | } | |
379 | }, | |
380 | NABufferType::VideoPacked(ref vb) => { | |
381 | md5.update_hash(vb.get_data()); | |
382 | }, | |
383 | NABufferType::AudioU8(ref ab) => { | |
384 | md5.update_hash(ab.get_data()); | |
385 | }, | |
386 | NABufferType::AudioI16(ref ab) => { | |
387 | let mut samp = [0u8; 2]; | |
388 | let data = ab.get_data(); | |
389 | for el in data.iter() { | |
390 | samp[0] = (*el >> 8) as u8; | |
391 | samp[1] = (*el >> 0) as u8; | |
392 | md5.update_hash(&samp); | |
393 | } | |
394 | }, | |
395 | NABufferType::AudioI32(ref ab) => { | |
396 | let mut samp = [0u8; 4]; | |
397 | let data = ab.get_data(); | |
398 | for el in data.iter() { | |
399 | samp[0] = (*el >> 24) as u8; | |
400 | samp[1] = (*el >> 16) as u8; | |
401 | samp[2] = (*el >> 8) as u8; | |
402 | samp[3] = (*el >> 0) as u8; | |
403 | md5.update_hash(&samp); | |
404 | } | |
405 | }, | |
406 | NABufferType::AudioF32(ref ab) => { | |
407 | let mut samp = [0u8; 4]; | |
408 | let data = ab.get_data(); | |
409 | for el in data.iter() { | |
410 | let bits = el.to_bits(); | |
411 | samp[0] = (bits >> 24) as u8; | |
412 | samp[1] = (bits >> 16) as u8; | |
413 | samp[2] = (bits >> 8) as u8; | |
414 | samp[3] = (bits >> 0) as u8; | |
415 | md5.update_hash(&samp); | |
416 | } | |
417 | }, | |
418 | NABufferType::AudioPacked(ref ab) => { | |
419 | md5.update_hash(ab.get_data()); | |
420 | }, | |
421 | NABufferType::Data(ref db) => { | |
422 | md5.update_hash(db.as_ref()); | |
423 | }, | |
424 | NABufferType::None => {}, | |
425 | }; | |
426 | } | |
427 | ||
428 | /// Tests decoder for requested codec in provided file. | |
429 | /// | |
430 | /// This functions tries to decode a stream corresponding to `dec_name` codec in input file and validate the results against expected ones. | |
431 | /// | |
432 | /// Since the function is intended for tests, it will panic instead of returning an error. | |
433 | /// | |
434 | /// # Examples | |
435 | /// | |
436 | /// Test RealVideo 4 decoder in test stream: | |
437 | /// ```no_run | |
438 | /// use nihav_codec_support::test::ExpectedTestResult; | |
439 | /// use nihav_codec_support::test::dec_video::test_decoding; | |
440 | /// use nihav_core::codecs::RegisteredDecoders; | |
441 | /// use nihav_core::demuxers::RegisteredDemuxers; | |
442 | /// | |
443 | /// let mut dmx_reg = RegisteredDemuxers::new(); | |
444 | /// let mut dec_reg = RegisteredDecoders::new(); | |
445 | /// // ... register RealMedia demuxers and RealVideo decoders ... | |
446 | /// test_decoding("realmedia", "rv40", "assets/test_file.rmvb", None, &dmx_reg, &dec_reg, ExpectedTestResult::MD5([0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f])); | |
447 | /// ``` | |
448 | pub fn test_decoding(demuxer: &str, dec_name: &str, filename: &str, limit: Option<u64>, | |
449 | dmx_reg: &RegisteredDemuxers, dec_reg: &RegisteredDecoders, | |
450 | test: ExpectedTestResult) { | |
451 | let dmx_f = dmx_reg.find_demuxer(demuxer).unwrap(); | |
452 | let mut file = File::open(filename).unwrap(); | |
453 | let mut fr = FileReader::new_read(&mut file); | |
454 | let mut br = ByteReader::new(&mut fr); | |
455 | let mut dmx = create_demuxer(dmx_f, &mut br).unwrap(); | |
456 | ||
457 | let mut decs: Vec<Option<(Box<NADecoderSupport>, Box<dyn NADecoder>)>> = Vec::new(); | |
458 | let mut found = false; | |
459 | for i in 0..dmx.get_num_streams() { | |
460 | let s = dmx.get_stream(i).unwrap(); | |
461 | let info = s.get_info(); | |
462 | println!("stream {} codec {} / {}", i, info.get_name(), dec_name); | |
463 | if !found && (info.get_name() == dec_name) { | |
464 | let decfunc = dec_reg.find_decoder(info.get_name()); | |
465 | if let Some(df) = decfunc { | |
466 | let mut dec = (df)(); | |
467 | let mut dsupp = Box::new(NADecoderSupport::new()); | |
468 | dec.init(&mut dsupp, info).unwrap(); | |
469 | decs.push(Some((dsupp, dec))); | |
470 | found = true; | |
471 | } else { | |
472 | decs.push(None); | |
473 | } | |
474 | } else { | |
475 | decs.push(None); | |
476 | } | |
477 | } | |
478 | ||
479 | let mut md5 = MD5::new(); | |
480 | let mut frameiter = if let ExpectedTestResult::MD5Frames(ref vec) = test { | |
481 | Some(vec.iter()) | |
482 | } else { | |
483 | None | |
484 | }; | |
485 | loop { | |
486 | let pktres = dmx.get_frame(); | |
487 | if let Err(e) = pktres { | |
488 | if e == DemuxerError::EOF { break; } | |
489 | panic!("error"); | |
490 | } | |
491 | let pkt = pktres.unwrap(); | |
492 | let streamno = pkt.get_stream().get_id() as usize; | |
493 | if let Some((ref mut dsupp, ref mut dec)) = decs[streamno] { | |
494 | if limit.is_some() && pkt.get_pts().is_some() && pkt.get_pts().unwrap() > limit.unwrap() { | |
495 | break; | |
496 | } | |
497 | let frm = dec.decode(dsupp, &pkt).unwrap(); | |
498 | match &test { | |
499 | ExpectedTestResult::Decodes => {}, | |
500 | ExpectedTestResult::MD5(_) => { frame_checksum(&mut md5, frm); }, | |
501 | ExpectedTestResult::MD5Frames(_) => { | |
502 | md5 = MD5::new(); | |
503 | frame_checksum(&mut md5, frm); | |
504 | md5.finish(); | |
505 | if let Some(ref mut iter) = frameiter { | |
506 | let ret = iter.next(); | |
507 | if ret.is_none() { break; } | |
508 | let ref_hash = ret.unwrap(); | |
509 | let mut hash = [0u32; 4]; | |
510 | md5.get_hash(&mut hash); | |
511 | println!("frame pts {:?} hash {}", pkt.get_pts(), md5); | |
512 | assert_eq!(&hash, ref_hash); | |
513 | } | |
514 | }, | |
515 | ExpectedTestResult::GenerateMD5Frames => { | |
516 | md5 = MD5::new(); | |
517 | frame_checksum(&mut md5, frm); | |
518 | md5.finish(); | |
519 | let mut hash = [0u32; 4]; | |
520 | md5.get_hash(&mut hash); | |
521 | println!("frame pts {:?} hash [0x{:08x}, 0x{:08x}, 0x{:08x}, 0x{:08x}],", pkt.get_pts(), hash[0], hash[1], hash[2], hash[3]); | |
522 | }, | |
523 | }; | |
524 | } | |
525 | } | |
526 | if let ExpectedTestResult::MD5(ref ref_hash) = test { | |
527 | md5.finish(); | |
528 | let mut hash = [0u32; 4]; | |
529 | md5.get_hash(&mut hash); | |
530 | println!("full hash {}", md5); | |
531 | assert_eq!(&hash, ref_hash); | |
532 | } | |
533 | if let ExpectedTestResult::GenerateMD5Frames = test { | |
534 | panic!("generated hashes"); | |
535 | } | |
536 | } |