]> git.nihav.org Git - nihav.git/blame - nihav-indeo/src/codecs/indeo3enc/mod.rs
indeo3enc: advance frameno on skip frames as well
[nihav.git] / nihav-indeo / src / codecs / indeo3enc / mod.rs
CommitLineData
77c25c7b
KS
1use nihav_core::codecs::*;
2use nihav_core::io::byteio::*;
3
4mod cell;
5use cell::*;
6mod mv;
7use mv::*;
8mod ratectl;
9use ratectl::*;
10mod tree;
11pub use tree::{Indeo3Cell, Plane};
12use tree::Indeo3PrimaryTree;
13
14const OS_HEADER_SIZE: usize = 16;
15const BITSTREAM_HEADER_SIZE: usize = 48;
16const HDR_FIELD_2: u32 = 0;
17const FRMH_TAG: u32 = ((b'F' as u32) << 24) | ((b'R' as u32) << 16)
18 | ((b'M' as u32) << 8) | (b'H' as u32);
19const PLANE_OFFSETS: usize = 32;
20
21const CB_SELECTORS: [u8; 16] = [
22 0x02, 0x14, 0x26, 0x38, 0x4A, 0x5C, 0x6E, 0x7F,
23 0x82, 0x94, 0xA6, 0xB8, 0xCA, 0xDC, 0xEE, 0xFF
24];
25
26const PLANE_ORDER: [usize; 3] = [1, 2, 0];
27
28pub struct Indeo3Writer<'a> {
29 dst: &'a mut Vec<u8>,
30 bitbuf: u8,
31 bits: u8,
32 bitpos: Option<usize>,
33}
34
35impl<'a> Indeo3Writer<'a> {
36 fn new(dst: &'a mut Vec<u8>) -> Self {
37 Self {
38 dst,
39 bitbuf: 0,
40 bits: 0,
41 bitpos: None,
42 }
43 }
44 pub fn put_byte(&mut self, b: u8) {
45 self.dst.push(b);
46 }
47 pub fn put_2bits(&mut self, val: u8) {
48 if self.bits == 0 {
49 self.bitpos = Some(self.dst.len());
50 self.dst.push(0);
51 }
52 self.bitbuf |= val << (6 - self.bits);
53 self.bits += 2;
54 if self.bits == 8 {
55 let bpos = self.bitpos.unwrap_or(0);
56 self.dst[bpos] = self.bitbuf;
57 self.bitbuf = 0;
58 self.bits = 0;
59 self.bitpos = None;
60 }
61 }
62}
63
64impl<'a> Drop for Indeo3Writer<'a> {
65 fn drop(&mut self) {
66 if self.bits != 0 {
67 let bpos = self.bitpos.unwrap_or(0);
68 self.dst[bpos] = self.bitbuf;
69 }
70 }
71}
72
73#[derive(Default)]
74struct Indeo3Frame {
75 plane: [Plane; 3],
76}
77
78impl Indeo3Frame {
79 fn new() -> Self { Self::default() }
80 fn alloc(&mut self, width: usize, height: usize) {
81 self.plane[0].alloc(width, height, 40);
82 self.plane[1].alloc(width / 4, height / 4, 10);
83 self.plane[2].alloc(width / 4, height / 4, 10);
84 }
85 fn fill(&mut self, vbuf: &NAVideoBufferRef<u8>) {
86 let data = vbuf.get_data();
87 for (plane_no, plane) in self.plane.iter_mut().enumerate() {
88 plane.fill(&data[vbuf.get_offset(plane_no)..], vbuf.get_stride(plane_no));
89 }
90 }
91 fn clear_mvs(&mut self) {
92 for plane in self.plane.iter_mut() {
93 plane.clear_mvs();
94 }
95 }
96}
97
98struct Indeo3Encoder {
99 stream: Option<NAStreamRef>,
100 pkt: Option<NAPacket>,
101 cframe: Indeo3Frame,
102 pframe: Indeo3Frame,
103 cenc: CellEncoder,
104 mv_est: MotionEstimator,
105 rc: RateControl,
106 frameno: u32,
107 buf_sel: bool,
108 width: usize,
109 height: usize,
110
111 debug_tree: bool,
112 debug_frm: bool,
113 try_again: bool,
114}
115
116impl Indeo3Encoder {
117 fn new() -> Self {
118 Self {
119 stream: None,
120 pkt: None,
121 cframe: Indeo3Frame::new(),
122 pframe: Indeo3Frame::new(),
123 cenc: CellEncoder::new(),
124 mv_est: MotionEstimator::new(),
125 rc: RateControl::new(),
126 frameno: 0,
127 buf_sel: false,
128 width: 0,
129 height: 0,
130
131 debug_tree: false,
132 debug_frm: false,
133 try_again: false,
134 }
135 }
136 fn encode_planes(&mut self, dbuf: &mut Vec<u8>, trees: &[Box<Indeo3PrimaryTree>], is_intra: bool) -> EncoderResult<()> {
137 for (&planeno, tree) in PLANE_ORDER.iter().zip(trees.iter()) {
138 let offset = dbuf.len();
139 let ref_plane = &self.pframe.plane[planeno];
140
141 let mut mc_count = [0; 4];
142 let mvs = &self.cframe.plane[planeno].mvs;
143 write_u32le(&mut mc_count, mvs.len() as u32)?;
144 dbuf.extend_from_slice(&mc_count);
145 for &(mv, _) in mvs.iter() {
146 dbuf.push(mv.y as u8);
147 dbuf.push(mv.x as u8);
148 }
149
150 let mut iw = Indeo3Writer::new(dbuf);
3ff976b2 151 self.cframe.plane[planeno].encode_tree(&mut iw, &tree, &mut self.cenc, ref_plane);
77c25c7b
KS
152 drop(iw);
153 while (dbuf.len() & 3) != 0 {
154 dbuf.push(0);
155 }
156
157 let plane_off = PLANE_OFFSETS + 4 * if planeno > 0 { planeno ^ 3 } else { 0 };
158 write_u32le(&mut dbuf[plane_off..], (offset - OS_HEADER_SIZE) as u32)?;
159 }
160
161 let mut checksum = 0;
162 for plane in self.cframe.plane.iter() {
163 checksum ^= plane.checksum();
164 }
7b430a1e 165 write_u16le(&mut dbuf[26..], checksum * 2)?;
77c25c7b
KS
166
167 let size = (dbuf.len() - OS_HEADER_SIZE) as u32;
168 write_u32le(&mut dbuf[8..], self.frameno ^ HDR_FIELD_2 ^ FRMH_TAG ^ size)?;
169 write_u32le(&mut dbuf[12..], size)?;
170 write_u32le(&mut dbuf[20..], size * 8)?;
171
172 if is_intra {
173 dbuf.extend_from_slice(b"\x0d\x0aVer 3.99.00.00\x0d\x0a\x00");
174 while (dbuf.len() & 3) != 0 {
175 dbuf.push(0);
176 }
177 }
178
179 Ok(())
180 }
181}
182
183impl NAEncoder for Indeo3Encoder {
184 fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
185 match encinfo.format {
186 NACodecTypeInfo::None => {
187 Ok(EncodeParameters {
188 format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV410_FORMAT)),
189 ..Default::default()
190 })
191 },
192 NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError),
193 NACodecTypeInfo::Video(vinfo) => {
194 let pix_fmt = YUV410_FORMAT;
195 let outinfo = NAVideoInfo::new((vinfo.width + 15) & !15, (vinfo.height + 15) & !15, false, pix_fmt);
196 let mut ofmt = *encinfo;
197 ofmt.format = NACodecTypeInfo::Video(outinfo);
198 Ok(ofmt)
199 }
200 }
201 }
202 fn init(&mut self, stream_id: u32, encinfo: EncodeParameters) -> EncoderResult<NAStreamRef> {
203 match encinfo.format {
204 NACodecTypeInfo::None => Err(EncoderError::FormatError),
205 NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError),
206 NACodecTypeInfo::Video(vinfo) => {
207 if vinfo.format != YUV410_FORMAT {
208 return Err(EncoderError::FormatError);
209 }
210 if ((vinfo.width | vinfo.height) & 15) != 0 {
211 return Err(EncoderError::FormatError);
212 }
213 if (vinfo.width > 640) || (vinfo.height > 480) {
214 return Err(EncoderError::FormatError);
215 }
216
217 self.width = vinfo.width;
218 self.height = vinfo.height;
219
220 let out_info = NAVideoInfo::new(vinfo.width, vinfo.height, false, vinfo.format);
221 let info = NACodecInfo::new("indeo3", NACodecTypeInfo::Video(out_info), None);
222 let mut stream = NAStream::new(StreamType::Video, stream_id, info, encinfo.tb_num, encinfo.tb_den, 0);
223 stream.set_num(stream_id as usize);
224 let stream = stream.into_ref();
225
226 self.stream = Some(stream.clone());
227
228 self.cframe.alloc(vinfo.width, vinfo.height);
229 self.pframe.alloc(vinfo.width, vinfo.height);
230
231 self.rc.set_bitrate(encinfo.bitrate, encinfo.tb_num, encinfo.tb_den);
232 self.rc.set_quality(encinfo.quality);
233
234 Ok(stream)
235 },
236 }
237 }
238 fn encode(&mut self, frm: &NAFrame) -> EncoderResult<()> {
239 let buf = frm.get_buffer();
240 if self.debug_tree || self.debug_frm {
241 println!("frame {}:", self.frameno);
242 }
243
244 let mut skip_frame = frm.get_frame_type() == FrameType::Skip;
245 if let NABufferType::None = buf {
246 skip_frame = true;
247 }
248 if skip_frame {
249 let mut dbuf = Vec::with_capacity(16);
250 let mut gw = GrowableMemoryWriter::new_write(&mut dbuf);
251 let mut bw = ByteWriter::new(&mut gw);
252
253 // OS header
254 bw.write_u32le(self.frameno)?;
255 bw.write_u32le(HDR_FIELD_2)?;
256 bw.write_u32le(0)?; // check
257 bw.write_u32le(0)?; // size
258
259 // bitstream header
260 bw.write_u16le(32)?; // version
261 bw.write_u16le(0)?;
262 bw.write_u32le(0)?; // data size in bits
263 bw.write_byte(0)?; // cb offset
264 bw.write_byte(14)?; // reserved
265 bw.write_u16le(0)?; // checksum
266 bw.write_u16le(self.height as u16)?;
267 bw.write_u16le(self.width as u16)?;
268
269 let size = (dbuf.len() - OS_HEADER_SIZE) as u32;
270 write_u32le(&mut dbuf[8..], self.frameno ^ HDR_FIELD_2 ^ FRMH_TAG ^ size)?;
271 write_u32le(&mut dbuf[12..], size)?;
272 write_u32le(&mut dbuf[20..], size * 8)?;
273
274 let fsize = dbuf.len() as u32;
275 self.rc.advance(fsize);
bd7a26d1 276 self.frameno += 1;
77c25c7b
KS
277
278 self.pkt = Some(NAPacket::new(self.stream.clone().unwrap(), frm.ts, false, dbuf));
279 return Ok(());
280 }
281
282 if let Some(ref vbuf) = buf.get_vbuf() {
283 let mut dbuf = Vec::with_capacity(16);
284 let mut gw = GrowableMemoryWriter::new_write(&mut dbuf);
285 let mut bw = ByteWriter::new(&mut gw);
286
287 let (width, height) = vbuf.get_dimensions(0);
288 if width != self.width || height != self.height {
289 self.width = width;
290 self.height = height;
291 self.cframe.alloc(width, height);
292 self.pframe.alloc(width, height);
293 self.rc.reset();
294 }
295
296 let (is_intra, quant) = self.rc.get_quant(self.frameno);
297 self.cenc.quant = quant;
298
299 if is_intra {
300 self.buf_sel = false;
301 } else {
302 self.buf_sel = !self.buf_sel;
303 }
304
305 self.cframe.fill(vbuf);
306 self.cframe.clear_mvs();
307
308 // OS header
309 bw.write_u32le(self.frameno)?;
310 bw.write_u32le(HDR_FIELD_2)?;
311 bw.write_u32le(0)?; // check
312 bw.write_u32le(0)?; // size
313
314 // bitstream header
315 bw.write_u16le(32)?; // version
316 let mut flags = 0;
317 if is_intra {
318 flags |= 0x5;
319 } else {
320 flags |= 1;
321 if self.buf_sel {
322 flags |= 1 << 9;
323 }
324 }
325 bw.write_u16le(flags)?;
326 bw.write_u32le(0)?; // data size in bits
327 bw.write_byte(0)?; // cb offset
328 bw.write_byte(14)?; // reserved
329 bw.write_u16le(0)?; // checksum
330 bw.write_u16le(height as u16)?;
331 bw.write_u16le(width as u16)?;
332 for _ in 0..3 {
333 bw.write_u32le(0)?; // plane data offset
334 }
335 bw.write_u32le(0)?; // reserved
336 bw.write_buf(&CB_SELECTORS)?;
337
338 let mut trees = Vec::with_capacity(PLANE_ORDER.len());
339
340 // prepare plane data structure
341 for &planeno in PLANE_ORDER.iter() {
342 let ref_plane = &self.pframe.plane[planeno];
bafe9cd4 343 let mut tree = self.cframe.plane[planeno].find_cells(is_intra, ref_plane, &self.mv_est);
77c25c7b
KS
344 if self.debug_tree {
345 println!(" tree for plane {}:", planeno);
346 tree.print();
347 }
77c25c7b 348 let mvs = &mut self.cframe.plane[planeno].mvs;
bafe9cd4
KS
349 if mvs.len() > 256 {
350 compact_mvs(mvs);
351 self.cframe.plane[planeno].prune_extra_mvs(&mut tree);
352 }
353 trees.push(tree);
77c25c7b
KS
354 }
355
356 self.encode_planes(&mut dbuf, &trees, is_intra)?;
357
358 let cur_quant = self.cenc.quant.unwrap_or(42);
5a5edb08 359 if self.try_again && !is_intra && cur_quant < 8 {
77c25c7b
KS
360 let expected_size = self.rc.get_expected_size();
361 if expected_size > 0 {
362 let cur_size = dbuf.len() as u32;
363 // try re-encoding frame if possible
364 if cur_size > expected_size * 3 / 2 {
365 self.cframe.fill(vbuf);
366 let new_quant = if cur_quant < 7 {
367 cur_quant + 1
368 } else {
369 cur_quant - 1
370 };
371 self.cenc.quant = Some(new_quant);
372 dbuf.truncate(OS_HEADER_SIZE + BITSTREAM_HEADER_SIZE);
373 self.encode_planes(&mut dbuf, &trees, is_intra)?;
374 }
375 }
376 }
377
378 if self.debug_frm {
379 for plane in self.cframe.plane.iter() {
380 for (y, line) in plane.data.chunks(plane.width).enumerate() {
381 print!(" {:3}:", y);
382 for &el in line.iter() { print!(" {:02X}", el); }
383 println!();
384 }
385 println!();
386 }
387 }
388
389 std::mem::swap(&mut self.cframe, &mut self.pframe);
390 self.frameno += 1;
391
392 let fsize = dbuf.len() as u32;
393 self.rc.advance(fsize);
394
395 self.pkt = Some(NAPacket::new(self.stream.clone().unwrap(), frm.ts, is_intra, dbuf));
396 Ok(())
397 } else {
398 Err(EncoderError::InvalidParameters)
399 }
400 }
401 fn get_packet(&mut self) -> EncoderResult<Option<NAPacket>> {
402 let mut npkt = None;
403 std::mem::swap(&mut self.pkt, &mut npkt);
404 Ok(npkt)
405 }
406 fn flush(&mut self) -> EncoderResult<()> {
407 Ok(())
408 }
409}
410
411const DEBUG_TREE_OPTION: &str = "debug_tree";
412const DEBUG_FRAME_OPTION: &str = "debug_frame";
413const MV_RANGE_OPTION: &str = "mv_range";
414const MV_FLAT_OPTION: &str = "mv_flat_threshold";
415const MV_THRESHOLD_OPTION: &str = "mv_threshold";
416const CELL_I_THRESHOLD_OPTION: &str = "cell_i_threshold";
417const CELL_P_THRESHOLD_OPTION: &str = "cell_p_threshold";
418const DO_RLE_OPTION: &str = "rle";
419const TRY_AGAIN_OPTION: &str = "try_recompress";
420
421const ENCODER_OPTS: &[NAOptionDefinition] = &[
422 NAOptionDefinition {
423 name: KEYFRAME_OPTION, description: KEYFRAME_OPTION_DESC,
424 opt_type: NAOptionDefinitionType::Int(Some(0), Some(128)) },
425 NAOptionDefinition {
426 name: DEBUG_TREE_OPTION, description: "Print frame trees",
427 opt_type: NAOptionDefinitionType::Bool },
428 NAOptionDefinition {
429 name: DEBUG_FRAME_OPTION, description: "Print encoder-reconstructed frames",
430 opt_type: NAOptionDefinitionType::Bool },
431 NAOptionDefinition {
432 name: MV_RANGE_OPTION, description: "Motion search range",
433 opt_type: NAOptionDefinitionType::Int(Some(0), Some(120)) },
434 NAOptionDefinition {
435 name: MV_FLAT_OPTION, description: "Threshold for coding cell as skipped one",
436 opt_type: NAOptionDefinitionType::Int(Some(0), Some(1000)) },
437 NAOptionDefinition {
438 name: MV_THRESHOLD_OPTION, description: "Threshold for coding cell as inter",
439 opt_type: NAOptionDefinitionType::Int(Some(0), Some(1000)) },
440 NAOptionDefinition {
441 name: CELL_I_THRESHOLD_OPTION, description: "Threshold for coding intra block as flat",
442 opt_type: NAOptionDefinitionType::Int(Some(0), Some(128)) },
443 NAOptionDefinition {
444 name: CELL_P_THRESHOLD_OPTION, description: "Threshold for coding inter cell in coarser mode",
445 opt_type: NAOptionDefinitionType::Int(Some(0), Some(128)) },
446 NAOptionDefinition {
447 name: DO_RLE_OPTION, description: "Perform zero run length compation",
448 opt_type: NAOptionDefinitionType::Bool },
449 NAOptionDefinition {
450 name: TRY_AGAIN_OPTION, description: "Try compressing the frame again for the better bitrate fit",
451 opt_type: NAOptionDefinitionType::Bool },
452];
453
454impl NAOptionHandler for Indeo3Encoder {
455 fn get_supported_options(&self) -> &[NAOptionDefinition] { ENCODER_OPTS }
456 fn set_options(&mut self, options: &[NAOption]) {
457 for option in options.iter() {
458 for opt_def in ENCODER_OPTS.iter() {
459 if opt_def.check(option).is_ok() {
460 match option.name {
461 KEYFRAME_OPTION => {
462 if let NAValue::Int(val) = option.value {
463 self.rc.set_key_int(val as u32);
464 }
465 },
466 DEBUG_TREE_OPTION => {
467 if let NAValue::Bool(val) = option.value {
468 self.debug_tree = val;
469 }
470 },
471 DEBUG_FRAME_OPTION => {
472 if let NAValue::Bool(val) = option.value {
473 self.debug_frm = val;
474 }
475 },
476 MV_RANGE_OPTION => {
477 if let NAValue::Int(val) = option.value {
478 self.mv_est.mv_range = val as i8;
479 }
480 },
481 MV_FLAT_OPTION => {
482 if let NAValue::Int(val) = option.value {
483 self.mv_est.flat_thr = val as u16;
484 }
485 },
486 MV_THRESHOLD_OPTION => {
487 if let NAValue::Int(val) = option.value {
488 self.mv_est.mv_thr = val as u16;
489 }
490 },
491 CELL_I_THRESHOLD_OPTION => {
492 if let NAValue::Int(val) = option.value {
493 self.cenc.flat_thr_i = val as u32;
494 }
495 },
496 CELL_P_THRESHOLD_OPTION => {
497 if let NAValue::Int(val) = option.value {
498 self.cenc.flat_thr_p = val as u32;
499 }
500 },
501 DO_RLE_OPTION => {
502 if let NAValue::Bool(val) = option.value {
503 self.cenc.do_rle = val;
504 }
505 },
506 TRY_AGAIN_OPTION => {
507 if let NAValue::Bool(val) = option.value {
508 self.try_again = val;
509 }
510 },
511 _ => {},
512 };
513 }
514 }
515 }
516 }
517 fn query_option_value(&self, name: &str) -> Option<NAValue> {
518 match name {
519 KEYFRAME_OPTION => Some(NAValue::Int(i64::from(self.rc.get_key_int()))),
520 DEBUG_TREE_OPTION => Some(NAValue::Bool(self.debug_tree)),
521 DEBUG_FRAME_OPTION => Some(NAValue::Bool(self.debug_frm)),
522 MV_RANGE_OPTION => Some(NAValue::Int(i64::from(self.mv_est.mv_range))),
523 MV_FLAT_OPTION => Some(NAValue::Int(i64::from(self.mv_est.flat_thr))),
524 MV_THRESHOLD_OPTION => Some(NAValue::Int(i64::from(self.mv_est.mv_thr))),
525 CELL_I_THRESHOLD_OPTION => Some(NAValue::Int(i64::from(self.cenc.flat_thr_i))),
526 CELL_P_THRESHOLD_OPTION => Some(NAValue::Int(i64::from(self.cenc.flat_thr_p))),
527 DO_RLE_OPTION => Some(NAValue::Bool(self.cenc.do_rle)),
528 TRY_AGAIN_OPTION => Some(NAValue::Bool(self.try_again)),
529 _ => None,
530 }
531 }
532}
533
534pub fn get_encoder() -> Box<dyn NAEncoder + Send> {
535 Box::new(Indeo3Encoder::new())
536}
537
538#[cfg(test)]
539mod test {
540 use crate::*;
541 use nihav_core::codecs::*;
542 use nihav_core::demuxers::*;
543 use nihav_core::muxers::*;
544 use nihav_commonfmt::*;
545 use nihav_codec_support::test::enc_video::*;
546
547 #[allow(unused_variables)]
548 fn encode_test(name: &'static str, enc_options: &[NAOption], limit: Option<u64>, hash: &[u32; 4]) {
549 let mut dmx_reg = RegisteredDemuxers::new();
550 generic_register_all_demuxers(&mut dmx_reg);
551 let mut dec_reg = RegisteredDecoders::new();
552 indeo_register_all_decoders(&mut dec_reg);
553 let mut mux_reg = RegisteredMuxers::new();
554 generic_register_all_muxers(&mut mux_reg);
555 let mut enc_reg = RegisteredEncoders::new();
556 indeo_register_all_encoders(&mut enc_reg);
557
558 let dec_config = DecoderTestParams {
559 demuxer: "avi",
560 in_name: "assets/Indeo/laser05.avi",
561 stream_type: StreamType::Video,
562 limit,
563 dmx_reg, dec_reg,
564 };
565 let enc_config = EncoderTestParams {
566 muxer: "avi",
567 enc_name: "indeo3",
568 out_name: name,
569 mux_reg, enc_reg,
570 };
571 let dst_vinfo = NAVideoInfo {
572 width: 0,
573 height: 0,
574 format: YUV410_FORMAT,
575 flipped: false,
576 bits: 9,
577 };
578 let enc_params = EncodeParameters {
579 format: NACodecTypeInfo::Video(dst_vinfo),
580 quality: 0,
581 bitrate: 25000 * 8,
582 tb_num: 0,
583 tb_den: 0,
584 flags: 0,
585 };
586 //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options);
587 test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options, hash);
588 }
589 #[test]
590 fn test_indeo3_encoder1() {
591 let enc_options = &[
592 NAOption { name: super::TRY_AGAIN_OPTION, value: NAValue::Bool(true) },
593 ];
f5c61879 594 encode_test("indeo3.avi", enc_options, Some(4), &[0x17d742bc, 0x6f4c1200, 0x79422bac, 0xc46b5dd0]);
77c25c7b
KS
595 }
596 /*#[test]
597 fn test_indeo3_roundtrip() {
598 const YPATTERN: [u8; 16] = [32, 72, 40, 106, 80, 20, 33, 58, 77, 140, 121, 100, 83, 57, 30, 11];
599 const CPATTERN: [u8; 4] = [0x80; 4];
600
601 let dst_vinfo = NAVideoInfo {
602 width: 16,
603 height: 16,
604 format: YUV410_FORMAT,
605 flipped: false,
606 bits: 9,
607 };
608 let enc_params = EncodeParameters {
609 format: NACodecTypeInfo::Video(dst_vinfo),
610 quality: 0,
611 bitrate: 0,
612 tb_num: 0,
613 tb_den: 0,
614 flags: 0,
615 };
616
617 let mut ienc = super::get_encoder();
618 ienc.init(0, enc_params).unwrap();
619 let mut buffer = alloc_video_buffer(dst_vinfo, 2).unwrap();
620 if let NABufferType::Video(ref mut buf) = buffer {
621 let vbuf = NASimpleVideoFrame::from_video_buf(buf).unwrap();
622 for i in 0..16 {
623 vbuf.data[vbuf.offset[0] + i * vbuf.stride[0]..][..16].copy_from_slice(&YPATTERN);
624 }
625 for plane in 1..3 {
626 for i in 0..4 {
627 vbuf.data[vbuf.offset[plane] + i * vbuf.stride[plane]..][..4].copy_from_slice(&CPATTERN);
628 }
629 }
630 }
631 let info = NACodecInfo::new("indeo3", NACodecTypeInfo::Video(dst_vinfo), None).into_ref();
632 let frm = NAFrame::new(NATimeInfo::new(Some(0), None, None, 1, 12), FrameType::I, true, info.clone(), buffer);
7b430a1e 633 //ienc.set_options(&[NAOption{ name: super::DEBUG_FRAME_OPTION, value: NAValue::Bool(true) }]);
77c25c7b
KS
634 ienc.encode(&frm).unwrap();
635 let pkt = ienc.get_packet().unwrap().unwrap();
636 println!(" pkt size {}", pkt.get_buffer().len());
637
638 let mut dec_reg = RegisteredDecoders::new();
639 indeo_register_all_decoders(&mut dec_reg);
640 let decfunc = dec_reg.find_decoder("indeo3").unwrap();
641 let mut dec = (decfunc)();
642 let mut dsupp = Box::new(NADecoderSupport::new());
643 dec.init(&mut dsupp, info).unwrap();
7b430a1e 644 dec.set_options(&[NAOption{ name: "checksum", value: NAValue::Bool(true) }]);
77c25c7b
KS
645 let dst = dec.decode(&mut dsupp, &pkt).unwrap();
646 if let NABufferType::Video(ref vbuf) = dst.get_buffer() {
647 for plane in 0..3 {
648 let size = if plane == 0 { 16 } else { 4 };
649 let start = vbuf.get_offset(plane);
650 for line in vbuf.get_data()[start..].chunks(vbuf.get_stride(plane)).take(size) {
651 print!(" ");
652 for &el in line[..size].iter() {
653 print!(" {:02X}", el >> 1);
654 }
655 println!();
656 }
657 if plane == 0 {
658 print!("ref");
659 for &el in YPATTERN.iter() { print!(" {:02X}", el >> 1); } println!();
660 }
661 println!();
662 }
663 }
664 panic!("end");
665 }*/
666}