1 /*****************************************************************************
2 * real.c: Real demuxer.
3 *****************************************************************************
4 * Copyright (C) 2004, 2006 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program 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.
14 * This program 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.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
30 #include <vlc/input.h>
32 /*****************************************************************************
34 *****************************************************************************/
35 static int Open ( vlc_object_t * );
36 static void Close ( vlc_object_t * );
39 set_description( _("Real demuxer" ) );
40 set_capability( "demux2", 15 );
41 set_category( CAT_INPUT );
42 set_subcategory( SUBCAT_INPUT_DEMUX );
43 set_callbacks( Open, Close );
44 add_shortcut( "real" );
48 /*****************************************************************************
50 *****************************************************************************/
64 int i_coded_frame_size;
69 block_t **p_subpackets;
76 int64_t i_data_offset;
78 uint32_t i_data_packets_count;
79 uint32_t i_data_packets;
80 int64_t i_data_offset_next;
88 uint8_t buffer[65536];
95 static int Demux( demux_t *p_demux );
96 static int Control( demux_t *p_demux, int i_query, va_list args );
98 static int HeaderRead( demux_t *p_demux );
99 static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num );
101 /*****************************************************************************
103 *****************************************************************************/
104 static int Open( vlc_object_t *p_this )
106 demux_t *p_demux = (demux_t*)p_this;
111 if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 ) return VLC_EGENERIC;
112 if( strncmp( (char *)p_peek, ".RMF", 4 ) ) return VLC_EGENERIC;
114 /* Fill p_demux field */
115 p_demux->pf_demux = Demux;
116 p_demux->pf_control = Control;
117 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
118 memset( p_sys, 0, sizeof( demux_sys_t ) );
119 p_sys->i_data_offset = 0;
125 /* Parse the headers */
126 if( HeaderRead( p_demux ) )
129 msg_Err( p_demux, "invalid header" );
130 for( i = 0; i < p_sys->i_track; i++ )
132 real_track_t *tk = p_sys->track[i];
136 es_out_Del( p_demux->out, tk->p_es );
140 if( p_sys->i_track > 0 )
142 free( p_sys->track );
151 /*****************************************************************************
153 *****************************************************************************/
154 static void Close( vlc_object_t *p_this )
156 demux_t *p_demux = (demux_t*)p_this;
157 demux_sys_t *p_sys = p_demux->p_sys;
160 for( i = 0; i < p_sys->i_track; i++ )
162 real_track_t *tk = p_sys->track[i];
163 int j = tk->i_subpackets;
165 if( tk->p_frame ) block_Release( tk->p_frame );
166 es_format_Clean( &tk->fmt );
170 if( tk->p_subpackets[ j ] )
171 block_Release( tk->p_subpackets[ j ] );
173 if( !tk->i_subpackets ) free( tk->p_subpackets );
178 if( p_sys->i_track > 0 ) free( p_sys->track );
183 /*****************************************************************************
185 *****************************************************************************/
186 static int Demux( demux_t *p_demux )
188 demux_sys_t *p_sys = p_demux->p_sys;
190 int i_size, i_id, i_flags, i;
192 real_track_t *tk = NULL;
193 vlc_bool_t b_selected;
195 if( p_sys->i_data_packets >= p_sys->i_data_packets_count &&
196 p_sys->i_data_packets_count )
198 if( stream_Read( p_demux->s, header, 18 ) < 18 )
202 if( strncmp( (char *)header, "DATA", 4 ) )
206 p_sys->i_data_offset = stream_Tell( p_demux->s ) - 18;
207 p_sys->i_data_size = GetDWBE( &header[4] );
208 p_sys->i_data_packets_count = GetDWBE( &header[10] );
209 p_sys->i_data_packets = 0;
210 p_sys->i_data_offset_next = GetDWBE( &header[14] );
212 msg_Dbg( p_demux, "entering new DATA packets=%d next=%u",
213 p_sys->i_data_packets_count,
214 (uint32_t)p_sys->i_data_offset_next );
217 if( stream_Read( p_demux->s, header, 12 ) < 12 ) return 0;
219 i_size = GetWBE( &header[2] ) - 12;
220 i_id = GetWBE( &header[4] );
221 i_pts = 1000 * GetDWBE( &header[6] );
222 i_pts += 1000; /* Avoid 0 pts */
223 i_flags= header[11]; /* flags 0x02 -> keyframe */
226 msg_Dbg( p_demux, "packet %d size=%d id=%d pts=%u",
227 p_sys->i_data_packets, i_size, i_id, (uint32_t)(i_pts/1000) );
230 p_sys->i_data_packets++;
232 stream_Read( p_demux->s, p_sys->buffer, i_size );
234 for( i = 0; i < p_sys->i_track; i++ )
236 if( p_sys->track[i]->i_id == i_id ) tk = p_sys->track[i];
241 msg_Warn( p_demux, "unknown track id(0x%x)", i_id );
244 es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE, tk->p_es, &b_selected );
246 if( tk->fmt.i_cat == VIDEO_ES && b_selected )
248 uint8_t *p = p_sys->buffer;
250 while( p < &p_sys->buffer[i_size - 2] )
259 if( (h&0xc0) == 0x40 )
263 i_len = &p_sys->buffer[i_size] - p;
269 i_subseq = (*p++)&0x7f;
271 i_len = (p[0] << 8)|p[1]; p += 2;
272 if( (i_len&0xc000) == 0 )
275 i_len |= (p[0] << 8)|p[1]; p += 2;
283 i_offset = (p[0] << 8)|p[1]; p += 2;
284 if( (i_offset&0xc000) == 0 )
287 i_offset |= (p[0] << 8)|p[1]; p += 2;
288 i_offset &= 0x3fffffff;
297 i_copy = i_len - i_offset;
298 if( i_copy > &p_sys->buffer[i_size] - p )
300 i_copy = &p_sys->buffer[i_size] - p;
302 else if( i_copy < 0 )
307 msg_Dbg( p_demux, " - len=%d offset=%d size=%d subseq=%d seqnum=%d",
308 i_len, i_offset, i_copy, i_subseq, i_seqnum );
310 if( (h&0xc0) == 0x80 )
312 /* last fragment -> fixes */
314 i_offset = i_len - i_copy;
315 msg_Dbg( p_demux, "last fixing copy=%d offset=%d",
320 ( tk->p_frame->i_dts != i_pts ||
321 tk->i_frame != i_len ) )
323 msg_Dbg( p_demux, "sending size=%d", tk->p_frame->i_buffer );
325 if( p_sys->i_pcr < tk->p_frame->i_dts )
327 p_sys->i_pcr = tk->p_frame->i_dts;
329 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
330 (int64_t)p_sys->i_pcr );
332 es_out_Send( p_demux->out, tk->p_es, tk->p_frame );
338 if( (h&0xc0) != 0x80 && (h&0xc0) != 0x00 && !tk->p_frame )
346 if( tk->p_frame == NULL )
348 msg_Dbg( p_demux, "new frame size=%d", i_len );
350 if( !( tk->p_frame = block_New( p_demux, i_len + 8 + 1000) ) )
354 memset( &tk->p_frame->p_buffer[8], 0, i_len );
355 tk->p_frame->i_dts = i_pts;
356 tk->p_frame->i_pts = i_pts;
358 ((uint32_t*)tk->p_frame->p_buffer)[0] = i_len; /* len */
359 ((uint32_t*)tk->p_frame->p_buffer)[1] = 0; /* chunk counts */
362 if( i_offset < tk->i_frame)
364 int i_ck = ((uint32_t*)tk->p_frame->p_buffer)[1]++;
366 msg_Dbg( p_demux, "copying new buffer n=%d offset=%d copy=%d",
367 i_ck, i_offset, i_copy );
369 ((uint32_t*)(tk->p_frame->p_buffer+i_len+8))[i_ck] = i_offset;
371 memcpy( &tk->p_frame->p_buffer[i_offset + 8], p, i_copy );
376 if( (h&0xc0) != 0x80 )
385 int i_ck = ((uint32_t*)tk->p_frame->p_buffer)[1]++;
387 if( (h&0xc0) == 0x80 )
391 i_offset = i_len - i_offset;
393 ((uint32_t*)(tk->p_frame->p_buffer+i_len+8))[i_ck] = i_offset;
394 memcpy( &tk->p_frame->p_buffer[i_offset+ 8], p, i_copy );
397 if( p_sys->i_pcr < tk->p_frame->i_dts )
399 p_sys->i_pcr = tk->p_frame->i_dts;
400 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
401 (int64_t)p_sys->i_pcr );
403 es_out_Send( p_demux->out, tk->p_es, tk->p_frame );
411 ((uint32_t*)(tk->p_frame->p_buffer+i_len+8))[i_ck] = i_offset;
412 memcpy( &tk->p_frame->p_buffer[i_offset + 8], p, i_copy );
416 if( (h&0xc0) != 0x00 )
421 if( !( p_frame = block_New( p_demux, i_copy + 8 + 8 ) ) )
425 p_frame->i_dts = i_pts;
426 p_frame->i_pts = i_pts;
428 ((uint32_t*)p_frame->p_buffer)[0] = i_copy;
429 ((uint32_t*)p_frame->p_buffer)[1] = 1;
430 ((uint32_t*)(p_frame->p_buffer+i_copy+8))[0] = 0;
431 memcpy( &p_frame->p_buffer[8], p, i_copy );
435 if( p_sys->i_pcr < p_frame->i_dts )
437 p_sys->i_pcr = p_frame->i_dts;
438 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
439 (int64_t)p_sys->i_pcr );
441 es_out_Send( p_demux->out, tk->p_es, p_frame );
447 if( !( tk->p_frame = block_New( p_demux, i_len + 8 + 1000) ) )
451 memset( &tk->p_frame->p_buffer[8], 0, i_len );
452 tk->p_frame->i_dts = i_pts;
453 tk->p_frame->i_pts = i_pts;
455 ((uint32_t*)tk->p_frame->p_buffer)[0] = i_len; /* len */
456 ((uint32_t*)tk->p_frame->p_buffer)[1] = 1; /* chunk counts */
457 ((uint32_t*)(tk->p_frame->p_buffer+i_len+8))[0] = i_offset;
458 memcpy( &tk->p_frame->p_buffer[i_offset + 8], p, i_copy );
465 else if( tk->fmt.i_cat == AUDIO_ES && b_selected )
468 if( p_sys->i_pcr < i_pts )
470 p_sys->i_pcr = i_pts;
471 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
472 (int64_t)p_sys->i_pcr );
475 if( tk->fmt.i_codec == VLC_FOURCC( 'm', 'p', '4', 'a' ) )
477 int i_sub = (p_sys->buffer[1] >> 4)&0x0f;
478 uint8_t *p_sub = &p_sys->buffer[2+2*i_sub];
481 for( i = 0; i < i_sub; i++ )
483 int i_sub_size = GetWBE( &p_sys->buffer[2+i*2]);
484 block_t *p_block = block_New( p_demux, i_sub_size );
487 memcpy( p_block->p_buffer, p_sub, i_sub_size );
491 p_block->i_pts = ( i == 0 ? i_pts : 0 );
493 es_out_Send( p_demux->out, tk->p_es, p_block );
497 else if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) ||
498 tk->fmt.i_codec == VLC_FOURCC('2','8','_','8') )
500 uint8_t *p_buf = p_sys->buffer;
501 int y = tk->i_subpacket / (tk->i_frame_size /tk->i_subpacket_size);
505 if( i_flags & 2 ) y = tk->i_subpacket = 0;
507 if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) )
508 for( i = 0; i < tk->i_frame_size / tk->i_subpacket_size; i++ )
510 block_t *p_block = block_New( p_demux, tk->i_subpacket_size );
511 memcpy( p_block->p_buffer, p_buf, tk->i_subpacket_size );
512 p_buf += tk->i_subpacket_size;
514 i_index = tk->i_subpacket_h * i +
515 ((tk->i_subpacket_h + 1) / 2) * (y&1) + (y>>1);
517 p_block->i_dts = p_block->i_pts = i_pts;
518 tk->p_subpackets[i_index] = p_block;
522 if( tk->fmt.i_codec == VLC_FOURCC('2','8','_','8') )
523 for( i = 0; i < tk->i_subpacket_h / 2; i++ )
525 block_t *p_block = block_New( p_demux, tk->i_coded_frame_size);
526 memcpy( p_block->p_buffer, p_buf, tk->i_coded_frame_size );
527 p_buf += tk->i_coded_frame_size;
529 i_index = (i * 2 * tk->i_frame_size) /
530 tk->i_coded_frame_size + y;
532 p_block->i_dts = p_block->i_pts = i_pts;
533 tk->p_subpackets[i_index] = p_block;
537 while( tk->i_out_subpacket != tk->i_subpackets &&
538 tk->p_subpackets[tk->i_out_subpacket] )
540 block_t *p_block = tk->p_subpackets[tk->i_out_subpacket];
541 tk->p_subpackets[tk->i_out_subpacket] = 0;
543 if( tk->i_out_subpacket ) p_block->i_dts = p_block->i_pts = 0;
544 es_out_Send( p_demux->out, tk->p_es, p_block );
546 tk->i_out_subpacket++;
549 if( tk->i_subpacket == tk->i_subpackets &&
550 tk->i_out_subpacket != tk->i_subpackets )
552 msg_Warn( p_demux, "i_subpacket != i_out_subpacket, "
553 "this shouldn't happen" );
556 if( tk->i_subpacket == tk->i_subpackets )
559 tk->i_out_subpacket = 0;
564 block_t *p_block = block_New( p_demux, i_size );
566 if( tk->fmt.i_codec == VLC_FOURCC( 'a', '5', '2', ' ' ) )
568 uint8_t *src = p_sys->buffer;
569 uint8_t *dst = p_block->p_buffer;
572 while( dst < &p_block->p_buffer[i_size- 1])
582 memcpy( p_block->p_buffer, p_sys->buffer, i_size );
584 p_block->i_dts = p_block->i_pts = i_pts;
585 es_out_Send( p_demux->out, tk->p_es, p_block );
593 /*****************************************************************************
595 *****************************************************************************/
596 static int Control( demux_t *p_demux, int i_query, va_list args )
598 demux_sys_t *p_sys = p_demux->p_sys;
608 case DEMUX_GET_POSITION:
609 pf = (double*) va_arg( args, double* );
610 i64 = stream_Size( p_demux->s );
613 *pf = (double)stream_Tell( p_demux->s ) / (double)i64;
621 case DEMUX_SET_POSITION:
622 f = (double) va_arg( args, double );
623 i64 = stream_Size( p_demux->s );
625 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
627 return stream_Seek( p_demux->s, (int64_t)(i64 * f) );
630 pi64 = (int64_t*)va_arg( args, int64_t * );
631 if( p_sys->i_mux_rate > 0 )
633 *pi64 = (int64_t)1000000 * ( stream_Tell( p_demux->s ) / 50 ) / p_sys->i_mux_rate;
640 case DEMUX_GET_LENGTH:
641 pi64 = (int64_t*)va_arg( args, int64_t * );
643 /* the commented following lines are fen's implementation, which doesn't seem to
644 * work for one reason or another -- FK */
645 /*if( p_sys->i_mux_rate > 0 )
647 *pi64 = (int64_t)1000000 * ( stream_Size( p_demux->s ) / 50 ) / p_sys->i_mux_rate;
650 if( p_sys->i_our_duration > 0 )
652 /* our stored duration is in ms, so... */
653 *pi64 = (int64_t)1000 * p_sys->i_our_duration;
662 vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
663 *pp_meta = p_sys->p_meta;
675 /*****************************************************************************
677 *****************************************************************************/
678 static int HeaderRead( demux_t *p_demux )
680 demux_sys_t *p_sys = p_demux->p_sys;
681 uint8_t header[100]; /* FIXME */
688 p_sys->p_meta = vlc_meta_New();
692 /* Read the header */
693 if( stream_Read( p_demux->s, header, 10 ) < 10 )
697 i_id = VLC_FOURCC( header[0], header[1], header[2], header[3] );
698 i_size = GetDWBE( &header[4] );
699 i_version = GetWBE( &header[8] );
701 msg_Dbg( p_demux, "object %4.4s size=%d version=%d",
702 (char*)&i_id, i_size, i_version );
706 msg_Dbg( p_demux, "invalid size for object %4.4s", (char*)&i_id );
709 i_skip = i_size - 10;
711 if( i_id == VLC_FOURCC('.','R','M','F') )
713 if( stream_Read( p_demux->s, header, 8 ) < 8 ) return VLC_EGENERIC;
714 msg_Dbg( p_demux, " - file version=0x%x num headers=%d",
715 GetDWBE( &header[0] ), GetDWBE( &header[4] ) );
719 else if( i_id == VLC_FOURCC('P','R','O','P') )
723 if( stream_Read(p_demux->s, header, 40) < 40 ) return VLC_EGENERIC;
725 msg_Dbg( p_demux, " - max bitrate=%d avg bitrate=%d",
726 GetDWBE(&header[0]), GetDWBE(&header[4]) );
727 msg_Dbg( p_demux, " - max packet size=%d avg bitrate=%d",
728 GetDWBE(&header[8]), GetDWBE(&header[12]) );
729 msg_Dbg( p_demux, " - packets count=%d", GetDWBE(&header[16]) );
730 msg_Dbg( p_demux, " - duration=%d ms", GetDWBE(&header[20]) );
731 msg_Dbg( p_demux, " - preroll=%d ms", GetDWBE(&header[24]) );
732 msg_Dbg( p_demux, " - index offset=%d", GetDWBE(&header[28]) );
733 msg_Dbg( p_demux, " - data offset=%d", GetDWBE(&header[32]) );
734 msg_Dbg( p_demux, " - num streams=%d", GetWBE(&header[36]) );
736 /* set the duration for export in control */
737 p_sys->i_our_duration = (int)GetDWBE(&header[20]);
739 i_flags = GetWBE(&header[38]);
740 msg_Dbg( p_demux, " - flags=0x%x %s%s%s",
742 i_flags&0x0001 ? "PN_SAVE_ENABLED " : "",
743 i_flags&0x0002 ? "PN_PERFECT_PLAY_ENABLED " : "",
744 i_flags&0x0004 ? "PN_LIVE_BROADCAST" : "" );
747 else if( i_id == VLC_FOURCC('C','O','N','T') )
752 /* FIXME FIXME: should convert from whatever the character
753 * encoding of the input meta data is to UTF-8. */
755 stream_Read( p_demux->s, header, 2 );
756 if( ( i_len = GetWBE( header ) ) > 0 )
758 psz = malloc( i_len + 1 );
759 stream_Read( p_demux->s, psz, i_len );
762 msg_Dbg( p_demux, " - title=`%s'", psz );
764 vlc_meta_SetTitle( p_sys->p_meta, psz );
770 stream_Read( p_demux->s, header, 2 );
771 if( ( i_len = GetWBE( header ) ) > 0 )
773 psz = malloc( i_len + 1 );
774 stream_Read( p_demux->s, psz, i_len );
777 msg_Dbg( p_demux, " - author=`%s'", psz );
779 vlc_meta_SetArtist( p_sys->p_meta, psz );
785 stream_Read( p_demux->s, header, 2 );
786 if( ( i_len = GetWBE( header ) ) > 0 )
788 psz = malloc( i_len + 1 );
789 stream_Read( p_demux->s, psz, i_len );
792 msg_Dbg( p_demux, " - copyright=`%s'", psz );
794 vlc_meta_SetCopyright( p_sys->p_meta, psz );
800 stream_Read( p_demux->s, header, 2 );
801 if( ( i_len = GetWBE( header ) ) > 0 )
803 psz = malloc( i_len + 1 );
804 stream_Read( p_demux->s, psz, i_len );
807 msg_Dbg( p_demux, " - comment=`%s'", psz );
809 vlc_meta_SetDescription( p_sys->p_meta, psz );
815 else if( i_id == VLC_FOURCC('M','D','P','R') )
817 /* Media properties header */
822 if( stream_Read(p_demux->s, header, 30) < 30 ) return VLC_EGENERIC;
823 i_num = GetWBE( header );
824 msg_Dbg( p_demux, " - id=0x%x", i_num );
825 msg_Dbg( p_demux, " - max bitrate=%d avg bitrate=%d",
826 GetDWBE(&header[2]), GetDWBE(&header[6]) );
827 msg_Dbg( p_demux, " - max packet size=%d avg packet size=%d",
828 GetDWBE(&header[10]), GetDWBE(&header[14]) );
829 msg_Dbg( p_demux, " - start time=%d", GetDWBE(&header[18]) );
830 msg_Dbg( p_demux, " - preroll=%d", GetDWBE(&header[22]) );
831 msg_Dbg( p_demux, " - duration=%d", GetDWBE(&header[26]) );
835 stream_Read( p_demux->s, header, 1 );
836 if( ( i_len = header[0] ) > 0 )
838 psz = malloc( i_len + 1 );
839 stream_Read( p_demux->s, psz, i_len );
842 msg_Dbg( p_demux, " - name=`%s'", psz );
848 stream_Read( p_demux->s, header, 1 );
849 if( ( i_len = header[0] ) > 0 )
851 psz = malloc( i_len + 1 );
852 stream_Read( p_demux->s, psz, i_len );
855 msg_Dbg( p_demux, " - mime=`%s'", psz );
861 stream_Read( p_demux->s, header, 4 );
862 if( ( i_len = GetDWBE( header ) ) > 0 )
864 ReadCodecSpecificData( p_demux, i_len, i_num );
865 stream_Read( p_demux->s, NULL, i_len );
871 else if( i_id == VLC_FOURCC('D','A','T','A') )
873 stream_Read( p_demux->s, header, 8 );
875 p_sys->i_data_offset = stream_Tell( p_demux->s ) - 10;
876 p_sys->i_data_size = i_size;
877 p_sys->i_data_packets_count = GetDWBE( header );
878 p_sys->i_data_packets = 0;
879 p_sys->i_data_offset_next = GetDWBE( &header[4] );
881 msg_Dbg( p_demux, " - packets count=%d next=%u",
882 p_sys->i_data_packets_count,
883 (uint32_t)p_sys->i_data_offset_next );
885 /* we have finished the header */
891 msg_Dbg( p_demux, "unknown chunk" );
894 if( i_skip < 0 ) return VLC_EGENERIC;
895 stream_Read( p_demux->s, NULL, i_skip );
898 /* TODO read index if possible */
903 static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
905 demux_sys_t *p_sys = p_demux->p_sys;
910 msg_Dbg( p_demux, " - specific data len=%d", i_len );
911 if( stream_Peek(p_demux->s, &p_peek, i_len) < i_len ) return VLC_EGENERIC;
913 if( !strncmp( (char *)&p_peek[4], "VIDO", 4 ) )
915 es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( p_peek[8], p_peek[9],
916 p_peek[10], p_peek[11] ) );
917 fmt.video.i_width = GetWBE( &p_peek[12] );
918 fmt.video.i_height= GetWBE( &p_peek[14] );
921 fmt.p_extra = malloc( 8 );
922 ((uint32_t*)fmt.p_extra)[0] = GetDWBE( &p_peek[26] );
923 ((uint32_t*)fmt.p_extra)[1] = GetDWBE( &p_peek[30] );
925 msg_Dbg( p_demux, " - video 0x%08x 0x%08x",
926 ((uint32_t*)fmt.p_extra)[0], ((uint32_t*)fmt.p_extra)[1] );
928 if( GetDWBE( &p_peek[30] ) == 0x10003000 ||
929 GetDWBE( &p_peek[30] ) == 0x10003001 )
931 fmt.i_codec = VLC_FOURCC( 'R','V','1','3' );
933 else if( GetDWBE( &p_peek[30] ) == 0x20001000 ||
934 GetDWBE( &p_peek[30] ) == 0x20100001 ||
935 GetDWBE( &p_peek[30] ) == 0x20200002 )
937 fmt.i_codec = VLC_FOURCC( 'R','V','2','0' );
939 else if( GetDWBE( &p_peek[30] ) == 0x30202002 )
941 fmt.i_codec = VLC_FOURCC( 'R','V','3','0' );
943 else if( GetDWBE( &p_peek[30] ) == 0x40000000 )
945 fmt.i_codec = VLC_FOURCC( 'R','V','4','0' );
948 msg_Dbg( p_demux, " - video %4.4s %dx%d",
949 (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height );
951 tk = malloc( sizeof( real_track_t ) );
952 tk->i_out_subpacket = 0;
954 tk->i_subpackets = 0;
955 tk->p_subpackets = NULL;
960 tk->p_es = es_out_Add( p_demux->out, &fmt );
962 TAB_APPEND( p_sys->i_track, p_sys->track, tk );
964 else if( !strncmp( (char *)p_peek, ".ra\xfd", 4 ) )
966 int i_version = GetWBE( &p_peek[4] );
967 int i_header_size, i_flavor, i_coded_frame_size, i_subpacket_h;
968 int i_frame_size, i_subpacket_size;
970 msg_Dbg( p_demux, " - audio version=%d", i_version );
973 es_format_Init( &fmt, AUDIO_ES, 0 );
977 msg_Dbg( p_demux, " - audio version 3 is not supported!" );
981 p_peek += 2; /* 00 00 */
982 p_peek += 4; /* .ra4 or .ra5 */
983 p_peek += 4; /* ?? */
984 p_peek += 2; /* version (4 or 5) */
985 i_header_size = GetDWBE( p_peek ); p_peek += 4; /* header size */
986 i_flavor = GetWBE( p_peek ); p_peek += 2; /* codec flavor */
987 i_coded_frame_size = GetDWBE( p_peek ); p_peek += 4;
988 p_peek += 4; /* ?? */
989 p_peek += 4; /* ?? */
990 p_peek += 4; /* ?? */
991 i_subpacket_h = GetWBE( p_peek ); p_peek += 2;
992 i_frame_size = GetWBE( p_peek ); p_peek += 2;
993 i_subpacket_size = GetWBE( p_peek ); p_peek += 2;
994 p_peek += 2; /* ?? */
996 if( i_version == 5 ) p_peek += 6; /* 0, srate, 0 */
998 fmt.audio.i_rate = GetWBE( p_peek ); p_peek += 2;
999 p_peek += 2; /* ?? */
1000 fmt.audio.i_bitspersample = GetWBE( p_peek ); p_peek += 2;
1001 fmt.audio.i_channels = GetWBE( p_peek ); p_peek += 2;
1002 fmt.audio.i_blockalign = i_frame_size;
1004 if( i_version == 5 )
1006 p_peek += 4; /* genr */
1007 memcpy( (char *)&fmt.i_codec, p_peek, 4 ); p_peek += 4;
1011 p_peek += p_peek[0] + 1; /* descr 1 */
1012 memcpy( (char *)&fmt.i_codec, p_peek + 1, 4 ); /* descr 2 */
1013 p_peek += p_peek[0] + 1;
1016 msg_Dbg( p_demux, " - audio codec=%4.4s channels=%d rate=%dHz",
1017 (char*)&fmt.i_codec, fmt.audio.i_channels, fmt.audio.i_rate );
1019 p_peek += 3; /* ?? */
1020 if( i_version == 5 ) p_peek++;
1022 switch( fmt.i_codec )
1024 case VLC_FOURCC( 'd', 'n', 'e', 't' ):
1025 fmt.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
1028 case VLC_FOURCC( 'r', 'a', 'a', 'c' ):
1029 case VLC_FOURCC( 'r', 'a', 'c', 'p' ):
1030 fmt.i_extra = GetDWBE( p_peek ); p_peek += 4;
1031 if( fmt.i_extra > 0 ) { fmt.i_extra--; p_peek++; }
1032 if( fmt.i_extra > 0 )
1034 fmt.p_extra = malloc( fmt.i_extra );
1035 memcpy( fmt.p_extra, p_peek, fmt.i_extra );
1038 fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
1041 case VLC_FOURCC('c','o','o','k'):
1042 fmt.audio.i_blockalign = i_subpacket_size;
1043 if( !(fmt.i_extra = GetDWBE( p_peek )) ) break;
1044 fmt.p_extra = malloc( fmt.i_extra );
1045 memcpy( fmt.p_extra, p_peek + 4, fmt.i_extra );
1048 case VLC_FOURCC('2','8','_','8'):
1049 fmt.audio.i_blockalign = i_coded_frame_size;
1053 msg_Dbg( p_demux, " - unknown audio codec=%4.4s",
1054 (char*)&fmt.i_codec );
1058 if( fmt.i_codec != 0 )
1062 msg_Dbg( p_demux, " - extra data=%d", fmt.i_extra );
1064 tk = malloc( sizeof( real_track_t ) );
1070 tk->i_subpacket_h = i_subpacket_h;
1071 tk->i_subpacket_size = i_subpacket_size;
1072 tk->i_coded_frame_size = i_coded_frame_size;
1073 tk->i_frame_size = i_frame_size;
1075 tk->i_out_subpacket = 0;
1076 tk->i_subpacket = 0;
1077 tk->i_subpackets = 0;
1078 tk->p_subpackets = NULL;
1079 if( fmt.i_codec == VLC_FOURCC('c','o','o','k') )
1082 i_subpacket_h * i_frame_size / tk->i_subpacket_size;
1084 malloc( tk->i_subpackets * sizeof(block_t *) );
1086 else if( fmt.i_codec == VLC_FOURCC('2','8','_','8') )
1089 i_subpacket_h * i_frame_size / tk->i_coded_frame_size;
1091 malloc( tk->i_subpackets * sizeof(block_t *) );
1094 for( i = 0; i < tk->i_subpackets; i++ ) tk->p_subpackets[i] = NULL;
1096 tk->p_es = es_out_Add( p_demux->out, &fmt );
1098 TAB_APPEND( p_sys->i_track, p_sys->track, tk );