]> git.nihav.org Git - nihav.git/blob - src/demuxers/realmedia.rs
rm: silence some warnings
[nihav.git] / src / demuxers / realmedia.rs
1 use super::*;
2 use super::DemuxerError::*;
3 //use io::byteio::*;
4 //use frame::*;
5 use formats::*;
6 use std::io::SeekFrom;
7 use std::mem;
8
9 macro_rules! mktag {
10 ($a:expr, $b:expr, $c:expr, $d:expr) => ({
11 (($a as u32) << 24) | (($b as u32) << 16) | (($c as u32) << 8) | ($d as u32)
12 });
13 ($arr:expr) => ({
14 (($arr[0] as u32) << 24) | (($arr[1] as u32) << 16) | (($arr[2] as u32) << 8) | ($arr[3] as u32)
15 });
16 }
17
18 struct RMVideoStream {
19 frame: Vec<u8>,
20 hdr_size: usize,
21 frame_size: usize,
22 frame_pos: usize,
23 }
24
25 impl RMVideoStream {
26 fn new() -> Self {
27 RMVideoStream {
28 frame: Vec::new(),
29 hdr_size: 0,
30 frame_size: 0,
31 frame_pos: 0,
32 }
33 }
34 fn flush(&mut self) {
35 self.frame.truncate(0);
36 self.frame_size = 0;
37 self.frame_pos = 0;
38 }
39 fn start_slice(&mut self, num_slices: usize, frame_size: usize, data: &[u8]) {
40 self.hdr_size = num_slices * 8 + 1;
41 self.frame.resize(frame_size + self.hdr_size, 0);
42 self.frame[0] = (num_slices - 1) as u8;
43 self.frame_pos = 0;
44 self.add_slice(1, data);
45 }
46 fn add_slice(&mut self, slice_no: usize, data: &[u8]) {
47 self.write_slice_info(slice_no);
48 let mut dslice = &mut self.frame[self.hdr_size + self.frame_pos..][..data.len()];
49 dslice.copy_from_slice(data);
50 self.frame_pos += data.len();
51 }
52 fn write_slice_info(&mut self, slice_no: usize) {
53 let off = 1 + (slice_no - 1) * 8;
54 self.frame[off + 0] = 0;
55 self.frame[off + 1] = 0;
56 self.frame[off + 2] = 0;
57 self.frame[off + 3] = 1;
58 self.frame[off + 4] = (self.frame_pos >> 24) as u8;
59 self.frame[off + 5] = (self.frame_pos >> 16) as u8;
60 self.frame[off + 6] = (self.frame_pos >> 8) as u8;
61 self.frame[off + 7] = (self.frame_pos >> 0) as u8;
62 }
63 fn get_frame_data(&mut self) -> Vec<u8> {
64 let mut v: Vec<u8> = Vec::new();
65 mem::swap(&mut v, &mut self.frame);
66 self.flush();
67 v
68 }
69 }
70
71 #[allow(dead_code)]
72 #[derive(Clone,Copy,PartialEq)]
73 enum Deinterleaver {
74 None,
75 Generic,
76 Sipro,
77 VBR,
78 }
79
80 #[allow(dead_code)]
81 struct RMAudioStream {
82 deint: Deinterleaver,
83 }
84
85 impl RMAudioStream {
86 fn new(deint: Deinterleaver) -> Self {
87 RMAudioStream { deint: deint }
88 }
89 }
90
91 enum RMStreamType {
92 Audio(RMAudioStream),
93 Video(RMVideoStream),
94 Logical,
95 Unknown,
96 }
97
98 struct RealMediaDemuxer<'a> {
99 src: &'a mut ByteReader<'a>,
100 data_pos: u64,
101 num_packets: u32,
102 cur_packet: u32,
103
104 streams: Vec<RMStreamType>,
105 str_ids: Vec<u16>,
106
107 queued_pkts: Vec<NAPacket>,
108 slice_buf: Vec<u8>,
109 }
110
111 fn find_codec_name(registry: &[(&[u8;4], &'static str)], fcc: u32) -> &'static str {
112 for &(fourcc, name) in registry {
113 if mktag!(fourcc) == fcc { return name; }
114 }
115 "unknown"
116 }
117
118 fn read_14or30(src: &mut ByteReader) -> DemuxerResult<(bool, u32)> {
119 let tmp = src.read_u16be()?;
120 let flag = (tmp & 0x8000) != 0;
121 if (tmp & 0x4000) == 0x4000 {
122 Ok((flag, ((tmp & 0x3FFF) as u32)))
123 } else {
124 let val = ((tmp as u32) << 16) | (src.read_u16be()? as u32);
125 Ok((flag, val & 0x3FFFFFFF))
126 }
127 }
128
129 fn read_video_buf(src: &mut ByteReader, stream: Rc<NAStream>, ts: u32, keyframe: bool, frame_size: usize) -> DemuxerResult<NAPacket> {
130 let size = (frame_size as usize) + 9;
131 let mut vec: Vec<u8> = Vec::with_capacity(size);
132 vec.resize(size, 0);
133 //v[0] = 0; // 1 slice
134 vec[4] = 1;
135 src.read_buf(&mut vec[9..])?;
136
137 let (tb_num, tb_den) = stream.get_timebase();
138 let ts = NATimeInfo::new(Some(ts as u64), None, None, tb_num, tb_den);
139 Ok(NAPacket::new(stream, ts, keyframe, vec))
140 }
141
142 fn read_multiple_frame(src: &mut ByteReader, stream: Rc<NAStream>, keyframe: bool, skip_mtype: bool) -> DemuxerResult<NAPacket> {
143 if !skip_mtype {
144 let mtype = src.read_byte()?;
145 validate!(mtype == 0xC0);
146 }
147 let (_, frame_size) = read_14or30(src)?;
148 let (_, timestamp) = read_14or30(src)?;
149 let seq_no = src.read_byte()?;
150 println!(" multiple frame size {} ts {} seq {}", frame_size, timestamp, seq_no);
151
152 read_video_buf(src, stream, timestamp, keyframe, frame_size as usize)
153 }
154
155 impl<'a> DemuxCore<'a> for RealMediaDemuxer<'a> {
156 #[allow(unused_variables)]
157 fn open(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<()> {
158 self.read_header(strmgr)?;
159 Ok(())
160 }
161
162 #[allow(unused_variables)]
163 fn get_frame(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<NAPacket> {
164 if !self.queued_pkts.is_empty() {
165 let pkt = self.queued_pkts.pop().unwrap();
166 return Ok(pkt);
167 }
168 loop {
169 if self.cur_packet >= self.num_packets { return Err(DemuxerError::EOF); }
170
171 let pkt_start = self.src.tell();
172 let ver = self.src.read_u16le()?;
173 validate!(ver <= 1);
174 let len = self.src.read_u16be()? as usize;
175 let str_no = self.src.read_u16be()?;
176 let ts = self.src.read_u32be()?;
177 let pkt_grp;
178 if ver == 0 {
179 pkt_grp = self.src.read_byte()?;
180 } else {
181 //asm_rule = self.src.read_u16le()?;
182 self.src.read_skip(2)?;
183 pkt_grp = 0;
184 }
185 let flags = self.src.read_byte()?;
186 let hdr_size = self.src.tell() - pkt_start;
187 println!("packet @{:X} size {} for {} ts {} grp {} flags {:X}", pkt_start, len, str_no, ts, pkt_grp, flags);
188 self.cur_packet += 1;
189
190 let payload_size = len - (hdr_size as usize);
191
192 let sr = self.str_ids.iter().position(|x| *x == str_no);
193 if sr.is_none() {
194 println!("stream {} not found", str_no);
195 self.src.read_skip(payload_size)?;
196 return Err(DemuxerError::InvalidData);
197 }
198 let str_id = sr.unwrap();
199 let stream = strmgr.get_stream_by_id(str_no as u32).unwrap();
200 println!(" stream {}", str_id);
201 if strmgr.is_ignored_id(str_no as u32) {
202 self.src.read_skip(payload_size)?;
203 continue;
204 }
205 //todo skip unwanted packet
206 let keyframe = (flags & KEYFRAME_FLAG) != 0;
207
208 let result = match self.streams[str_id] {
209 RMStreamType::Video(ref mut vstr) => {
210
211 let pos = self.src.tell();
212 let b0 = self.src.read_byte()?;
213 match b0 >> 6 {
214 0 => { // partial frame
215 let b1 = self.src.read_byte()?;
216 let hdr1 = ((b0 as u16) << 8) | (b1 as u16);
217 let num_pkts = ((hdr1 >> 7) & 0x7F) as usize;
218 let packet_num = hdr1 & 0x7F;
219 let (_, frame_size) = read_14or30(self.src)?;
220 let (_, off) = read_14or30(self.src)?;
221 let seq_no = self.src.read_byte()?;
222 println!(" mode 0 pkt {}/{} off {}/{} seq {}", packet_num, num_pkts, off, frame_size, seq_no);
223 let hdr_skip = (self.src.tell() - pos) as usize;
224
225 let slice_size = (payload_size - hdr_skip) as usize;
226 self.slice_buf.resize(slice_size, 0);
227 self.src.read_buf(self.slice_buf.as_mut_slice())?;
228 if packet_num == 1 {
229 vstr.start_slice(num_pkts, frame_size as usize, self.slice_buf.as_slice());
230 } else {
231 vstr.add_slice(packet_num as usize, self.slice_buf.as_slice());
232 }
233 continue;
234 },
235 1 => { // whole frame
236 let seq_no = self.src.read_byte()?;
237 println!(" mode 1 seq {}", seq_no);
238 read_video_buf(self.src, stream, ts, keyframe, payload_size - 1)
239 },
240 2 => { // last partial frame
241 let b1 = self.src.read_byte()?;
242 let hdr1 = ((b0 as u16) << 8) | (b1 as u16);
243 let num_pkts = ((hdr1 >> 7) & 0x7F) as usize;
244 let packet_num = hdr1 & 0x7F;
245 let (_, frame_size) = read_14or30(self.src)?;
246 let (_, tail_size) = read_14or30(self.src)?;
247 let seq_no = self.src.read_byte()?;
248 println!(" mode 2 pkt {}/{} tail {}/{} seq {}", packet_num, num_pkts, tail_size, frame_size, seq_no);
249 self.slice_buf.resize(tail_size as usize, 0);
250 self.src.read_buf(self.slice_buf.as_mut_slice())?;
251 vstr.add_slice(packet_num as usize, self.slice_buf.as_slice());
252
253 while self.src.tell() < pos + (payload_size as u64) {
254 let res = read_multiple_frame(self.src, stream.clone(), false, false);
255 if res.is_err() { break; }
256 self.queued_pkts.push(res.unwrap());
257 }
258 self.queued_pkts.reverse();
259 let (tb_num, tb_den) = stream.get_timebase();
260 let ts = NATimeInfo::new(Some(ts as u64), None, None, tb_num, tb_den);
261 let pkt = NAPacket::new(stream, ts, keyframe, vstr.get_frame_data());
262 Ok(pkt)
263 },
264 _ => { // multiple frames
265 println!(" mode 3");
266 let res = read_multiple_frame(self.src, stream.clone(), keyframe, true);
267 if res.is_err() { return res; }
268 while self.src.tell() < pos + (payload_size as u64) {
269 let res = read_multiple_frame(self.src, stream.clone(), false, false);
270 if res.is_err() { break; }
271 self.queued_pkts.push(res.unwrap());
272 }
273 self.queued_pkts.reverse();
274 res
275 },
276 }
277 },
278 RMStreamType::Audio(ref mut astr) => {
279 let (tb_num, tb_den) = stream.get_timebase();
280 let ts = NATimeInfo::new(Some(ts as u64), None, None, tb_num, tb_den);
281 self.src.read_packet(stream, ts, keyframe, payload_size)
282 },
283 _ => {
284 // self.src.read_skip(payload_size)?;
285 Err(DemuxerError::InvalidData)
286 },
287 };
288 return result;
289 }
290 }
291
292 #[allow(unused_variables)]
293 fn seek(&mut self, time: u64) -> DemuxerResult<()> {
294 Err(NotImplemented)
295 }
296 }
297
298 fn read_chunk(src: &mut ByteReader) -> DemuxerResult<(u32, u32, u16)> {
299 let id = src.read_u32be()?;
300 let size = src.read_u32be()?;
301 validate!(size >= 10);
302 let ver = src.read_u16be()?;
303 validate!(ver <= 1);
304 Ok((id, size, ver))
305 }
306
307 const RMVB_HDR_SIZE: u32 = 18;
308 const RMVB_PROP_SIZE: u32 = 50;
309 const KEYFRAME_FLAG: u8 = 0x02;
310
311 impl<'a> RealMediaDemuxer<'a> {
312 fn new(io: &'a mut ByteReader<'a>) -> Self {
313 RealMediaDemuxer {
314 src: io,
315 data_pos: 0,
316 num_packets: 0,
317 cur_packet: 0,
318 streams: Vec::new(),
319 str_ids: Vec::new(),
320 queued_pkts: Vec::new(),
321 slice_buf: Vec::new(),
322 }
323 }
324 #[allow(unused_variables)]
325 fn read_header(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<()> {
326 let (id, size, ver) = read_chunk(self.src)?;
327 validate!(id == mktag!(b".RMF"));
328 validate!(size >= RMVB_HDR_SIZE);
329 let fver = self.src.read_u32be()?;
330 validate!(fver <= 1);
331 let num_hdr = self.src.read_u32be()? as usize;
332 validate!(num_hdr >= 1);
333 if size > RMVB_HDR_SIZE {
334 self.src.read_skip((size - RMVB_HDR_SIZE) as usize)?;
335 }
336
337 let (id, size, ver) = read_chunk(self.src)?;
338 validate!(size >= RMVB_PROP_SIZE);
339 validate!(ver == 0);
340 let maxbr = self.src.read_u32be()?;
341 let avgbr = self.src.read_u32be()?;
342 let maxps = self.src.read_u32be()?;
343 let avgps = self.src.read_u32be()?;
344 let num_pkt = self.src.read_u32be()? as usize;
345 let duration = self.src.read_u32be()?;
346 let preroll = self.src.read_u32be()?;
347 let idx_off = self.src.read_u32be()?;
348 let data_off = self.src.read_u32be()?;
349 let num_streams = self.src.read_u16be()? as usize;
350 let flags = self.src.read_u16be()?;
351 if size > RMVB_PROP_SIZE {
352 self.src.read_skip((size - RMVB_PROP_SIZE) as usize)?;
353 }
354
355 for _ in 0..num_hdr {
356 self.parse_chunk(strmgr)?;
357 }
358 println!("now @ {:X} / {}", self.src.tell(), self.data_pos);
359 validate!(self.data_pos > 0);
360 self.src.seek(SeekFrom::Start(self.data_pos))?;
361 let num_packets = self.src.read_u32be()?;
362 let next_data_hdr = self.src.read_u32be()?;
363 self.num_packets = num_packets;
364 self.cur_packet = 0;
365 Ok(())
366 }
367 fn parse_chunk(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<()> {
368 let (id, size, ver) = read_chunk(self.src)?;
369 let end_pos = self.src.tell() - 10 + (size as u64);
370
371 validate!(ver == 0);
372 if id == mktag!(b"CONT") { self.parse_content_desc()?; }
373 else if id == mktag!(b"MDPR") { self.parse_mdpr(strmgr)?; }
374 else if id == mktag!(b"DATA") { if self.data_pos == 0 { self.data_pos = self.src.tell(); } }
375 else if id == mktag!(b"INDX") { /* do nothing for now */ }
376 else { println!("unknown chunk type {:08X}", id); }
377
378 let cpos = self.src.tell();
379 if cpos < end_pos {
380 self.src.read_skip((end_pos - cpos) as usize)?;
381 }
382 Ok(())
383 }
384 #[allow(unused_variables)]
385 fn parse_content_desc(&mut self) -> DemuxerResult<()> {
386 let title_len = self.src.read_u16be()? as usize;
387 self.src.read_skip(title_len)?;
388 let author_len = self.src.read_u16be()? as usize;
389 self.src.read_skip(author_len)?;
390 let copywrong_len = self.src.read_u16be()? as usize;
391 self.src.read_skip(copywrong_len)?;
392 let comment_len = self.src.read_u16be()? as usize;
393 self.src.read_skip(comment_len)?;
394 Ok(())
395 }
396 #[allow(unused_variables)]
397 fn parse_mdpr(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<()> {
398 let stream_no = self.src.read_u16be()?;
399 //todo check stream_no for duplicates
400 let maxbr = self.src.read_u32be()?;
401 let avgbr = self.src.read_u32be()?;
402 let maxps = self.src.read_u32be()?;
403 let avgps = self.src.read_u32be()?;
404 let start = self.src.read_u32be()?;
405 let preroll = self.src.read_u32be()?;
406 let duration = self.src.read_u32be()?;
407 let sname_size = self.src.read_byte()? as usize;
408 let sname = read_string_size(self.src, sname_size)?;
409 println!("str #{} sname = {} pkts {}/{} start {} preroll {}", stream_no, sname, maxps, avgps, start, preroll);
410 let mime_size = self.src.read_byte()? as usize;
411 let mime = read_string_size(self.src, mime_size)?;
412 println!("mime = {}", mime);
413 let edata_size = self.src.read_u32be()? as usize;
414 let edata: Option<Vec<u8>> = if edata_size == 0 { None } else {
415 let mut edvec: Vec<u8> = Vec::with_capacity(edata_size);
416 edvec.resize(edata_size, 0);
417 self.src.read_buf(&mut edvec)?;
418 Some(edvec)
419 };
420 self.str_ids.push(stream_no);
421 if edata_size > 8 {
422 if let Some(edata_) = edata {
423 let mut mr = MemoryReader::new_read(edata_.as_slice());
424 let mut src = ByteReader::new(&mut mr);
425
426 let tag = src.read_u32be()?;
427 let tag2 = src.peek_u32be()?;
428 println!("tag1 {:X} tag2 {:X}", tag, tag2);
429 if tag == mktag!('.', 'r', 'a', 0xFD) {
430 //todo audio
431 let cname = "unknown";//find_codec_name(RM_AUDIO_CODEC_REGISTER, fcc);
432 let soniton = NASoniton::new(16, SONITON_FLAG_SIGNED);
433 let ahdr = NAAudioInfo::new(44100, 2, soniton, 1/*block_align as usize*/);
434 let extradata = None;
435 let ainfo = NACodecInfo::new(cname, NACodecTypeInfo::Audio(ahdr), extradata);
436 let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no as u32, ainfo, 1, 44100));
437 if res.is_none() { return Err(MemoryError); }
438
439 let astr = RMAudioStream::new(Deinterleaver::None);
440 self.streams.push(RMStreamType::Audio(astr));
441 } else if ((tag2 == mktag!('V', 'I', 'D', 'O')) || (tag2 == mktag!('I', 'M', 'A', 'G'))) && ((tag as usize) <= edata_size) {
442 src.read_skip(4)?;
443 let fcc = src.read_u32be()?;
444 let width = src.read_u16be()? as usize;
445 let height = src.read_u16be()? as usize;
446 let bpp = src.read_u16be()?;
447 let pad_w = src.read_u16be()?;
448 let pad_h = src.read_u16be()?;
449 let fps;
450 if tag2 == mktag!('V', 'I', 'D', 'O') {
451 fps = src.read_u32be()?;
452 } else {
453 fps = 0x10000;
454 }
455 let extradata: Option<Vec<u8>>;
456 if src.left() > 0 {
457 let eslice = &edata_[(src.tell() as usize)..];
458 extradata = Some(eslice.to_vec());
459 } else {
460 extradata = None;
461 }
462 let cname = find_codec_name(RM_VIDEO_CODEC_REGISTER, fcc);
463
464 let vhdr = NAVideoInfo::new(width, height, false, RGB24_FORMAT);
465 let vinfo = NACodecInfo::new(cname, NACodecTypeInfo::Video(vhdr), extradata);
466 let res = strmgr.add_stream(NAStream::new(StreamType::Video, stream_no as u32, vinfo, 0x10000, fps));
467 if res.is_none() { return Err(DemuxerError::MemoryError); }
468
469 let vstr = RMVideoStream::new();
470 self.streams.push(RMStreamType::Video(vstr));
471 } else {
472 self.streams.push(RMStreamType::Logical);
473 }
474 }
475 } else {
476 self.streams.push(RMStreamType::Unknown);
477 }
478
479 Ok(())
480 }
481 /*#[allow(unused_variables)]
482 fn read_pkt_header(&mut self) -> DemuxerResult<()> {
483 let ver = self.src.read_u16be()?;
484 validate!(ver <= 1);
485 let str_no = self.src.read_u16be()?;
486 let timestamp = self.src.read_u32be()?;
487 if ver == 0 {
488 let pkt_group = self.src.read_byte()?;
489 let pkt_flags = self.src.read_byte()?;
490 } else {
491 let asm_rule = self.src.read_u16be()?;
492 let asm_flags = self.src.read_byte()?;
493 }
494 Ok(())
495 }*/
496 }
497
498 fn read_string(src: &mut ByteReader) -> DemuxerResult<String> {
499 let mut vec: Vec<u8> = Vec::new();
500 loop {
501 let c = src.read_byte()?;
502 if c == 0 { break; }
503 vec.push(c);
504 }
505 let str = String::from_utf8(vec);
506 if str.is_ok() {
507 Ok(str.unwrap())
508 } else {
509 Ok(String::new())
510 }
511 }
512
513 fn read_string_size(src: &mut ByteReader, size: usize) -> DemuxerResult<String> {
514 let mut vec: Vec<u8> = Vec::new();
515 for _ in 0..size {
516 let c = src.read_byte()?;
517 vec.push(c);
518 }
519 let str = String::from_utf8(vec);
520 if str.is_ok() {
521 Ok(str.unwrap())
522 } else {
523 Ok(String::new())
524 }
525 }
526
527 #[allow(dead_code)]
528 #[allow(unused_variables)]
529 fn parse_rm_stream(io: &mut ByteReader) -> DemuxerResult<NAStream> {
530 let mimetype = read_string(io)?;
531 let strname = read_string(io)?;
532 let strnum = io.read_u32le()?;
533 let maxbr = io.read_u32le()?;
534 let avgbr = io.read_u32le()?;
535 let maxsize = io.read_u32le()?;
536 let avgsize = io.read_u32le()?;
537 let duration = io.read_u32le()?;
538 let preroll = io.read_u32le()?;
539 let start = io.read_u32le()?;
540 let edatalen = io.read_u32le()? as usize;
541 let mut edata: Vec<u8> = Vec::with_capacity(edatalen);
542 edata.resize(edatalen, 0);
543 io.read_buf(&mut edata)?;
544 let numprops = io.read_u32le()? as usize;
545 //read properties
546 unimplemented!();
547 }
548
549 #[allow(dead_code)]
550 #[allow(unused_variables)]
551 fn read_ra_vbr_stream(io: &mut ByteReader) -> DemuxerResult<NAPacket> {
552 let hdrsizesize = io.read_u16le()?;
553 let num_entries = (hdrsizesize / 16) as usize;
554 let mut sizes: Vec<usize> = Vec::with_capacity(num_entries);
555 for _ in 0..num_entries {
556 let sz = io.read_u16le()? as usize;
557 sizes.push(sz);
558 }
559 for i in 0..num_entries {
560 //read packet of sizes[i]
561 }
562 unimplemented!();
563 }
564
565 //todo interleavers
566
567 //todo opaque data
568
569
570 static RM_VIDEO_CODEC_REGISTER: &'static [(&[u8;4], &str)] = &[
571 (b"RV10", "realvideo1"),
572 (b"RV20", "realvideo2"),
573 (b"RVTR", "realvideo2"),
574 (b"RV30", "realvideo3"),
575 (b"RV40", "realvideo4"),
576 (b"CLV1", "clearvideo"),
577 ];
578
579 #[allow(dead_code)]
580 static RM_AUDIO_CODEC_REGISTER: &'static [(&[u8;4], &str)] = &[
581 (b"lpcJ", "ra14.4"),
582 (b"28_8", "ra28.8"),
583 (b"cook", "cook"),
584 (b"dnet", "ac3"),
585 (b"sipr", "sipro"),
586 (b"atrc", "atrac3"),
587 (b"LSD:", "ralf"),
588 (b"raac", "aac"),
589 (b"racp", "aac"),
590 ];
591
592 pub struct RealMediaDemuxerCreator { }
593
594 impl DemuxerCreator for RealMediaDemuxerCreator {
595 fn new_demuxer<'a>(&self, br: &'a mut ByteReader<'a>) -> Box<DemuxCore<'a> + 'a> {
596 Box::new(RealMediaDemuxer::new(br))
597 }
598 fn get_name(&self) -> &'static str { "realmedia" }
599 }
600
601 #[cfg(test)]
602 mod test {
603 use super::*;
604 use std::fs::File;
605
606 #[test]
607 fn test_rm_demux() {
608 let mut file =
609 File::open("assets/RV/rv10_dnet_640x352_realvideo_encoder_4.0.rm").unwrap();
610 // File::open("assets/RV/rv20_cook_640x352_realproducer_plus_8.51.rm").unwrap();
611 // File::open("assets/RV/rv20_svt_atrc_640x352_realproducer_plus_8.51.rm").unwrap();
612 // File::open("assets/RV/rv30_atrc_384x208_realproducer_plus_8.51.rm").unwrap();
613 // File::open("assets/RV/rv30_chroma_drift.rm").unwrap();
614 // File::open("assets/RV/rv30_weighted_mc.rm").unwrap();
615 // File::open("assets/RV/rv40_weighted_mc.rmvb").unwrap();
616 // File::open("assets/RV/rv40_weighted_mc_2.rmvb").unwrap();
617 // File::open("assets/RV/clv1_sipr_384x208_realvideo_encoder_4.0.rm").unwrap();
618 // File::open("assets/RV/luckynight.rmvb").unwrap();
619 // File::open("assets/RV/rv40_ralf.rmvb").unwrap();
620 let mut fr = FileReader::new_read(&mut file);
621 let mut br = ByteReader::new(&mut fr);
622 let mut dmx = RealMediaDemuxer::new(&mut br);
623 let mut sm = StreamManager::new();
624 dmx.open(&mut sm).unwrap();
625
626 loop {
627 let pktres = dmx.get_frame(&mut sm);
628 if let Err(e) = pktres {
629 if e == DemuxerError::EOF { break; }
630 panic!("error");
631 }
632 let pkt = pktres.unwrap();
633 println!("Got {}", pkt);
634 }
635 //panic!("the end");
636 }
637 }