1 /*****************************************************************************
2 * real.c: Real demuxer.
3 *****************************************************************************
4 * Copyright (C) 2004 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;
85 uint8_t buffer[65536];
90 static int Demux( demux_t *p_demux );
91 static int Control( demux_t *p_demux, int i_query, va_list args );
93 static int HeaderRead( demux_t *p_demux );
94 static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num );
96 /*****************************************************************************
98 *****************************************************************************/
99 static int Open( vlc_object_t *p_this )
101 demux_t *p_demux = (demux_t*)p_this;
106 if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 ) return VLC_EGENERIC;
107 if( strncmp( (char *)p_peek, ".RMF", 4 ) ) return VLC_EGENERIC;
109 /* Fill p_demux field */
110 p_demux->pf_demux = Demux;
111 p_demux->pf_control = Control;
112 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
113 memset( p_sys, 0, sizeof( demux_sys_t ) );
114 p_sys->i_data_offset = 0;
120 /* Parse the headers */
121 if( HeaderRead( p_demux ) )
124 msg_Err( p_demux, "invalid header" );
125 for( i = 0; i < p_sys->i_track; i++ )
127 real_track_t *tk = p_sys->track[i];
131 es_out_Del( p_demux->out, tk->p_es );
135 if( p_sys->i_track > 0 )
137 free( p_sys->track );
146 /*****************************************************************************
148 *****************************************************************************/
149 static void Close( vlc_object_t *p_this )
151 demux_t *p_demux = (demux_t*)p_this;
152 demux_sys_t *p_sys = p_demux->p_sys;
155 for( i = 0; i < p_sys->i_track; i++ )
157 real_track_t *tk = p_sys->track[i];
158 int j = tk->i_subpackets;
160 if( tk->p_frame ) block_Release( tk->p_frame );
161 es_format_Clean( &tk->fmt );
165 if( tk->p_subpackets[ j ] )
166 block_Release( tk->p_subpackets[ j ] );
168 if( !tk->i_subpackets ) free( tk->p_subpackets );
173 if( p_sys->i_track > 0 ) free( p_sys->track );
178 /*****************************************************************************
180 *****************************************************************************/
181 static int Demux( demux_t *p_demux )
183 demux_sys_t *p_sys = p_demux->p_sys;
185 int i_size, i_id, i_flags, i;
187 real_track_t *tk = NULL;
188 vlc_bool_t b_selected;
190 if( p_sys->i_data_packets >= p_sys->i_data_packets_count &&
191 p_sys->i_data_packets_count )
193 if( stream_Read( p_demux->s, header, 18 ) < 18 )
197 if( strncmp( (char *)header, "DATA", 4 ) )
201 p_sys->i_data_offset = stream_Tell( p_demux->s ) - 18;
202 p_sys->i_data_size = GetDWBE( &header[4] );
203 p_sys->i_data_packets_count = GetDWBE( &header[10] );
204 p_sys->i_data_packets = 0;
205 p_sys->i_data_offset_next = GetDWBE( &header[14] );
207 msg_Dbg( p_demux, "entering new DATA packets=%d next=%u",
208 p_sys->i_data_packets_count,
209 (uint32_t)p_sys->i_data_offset_next );
212 if( stream_Read( p_demux->s, header, 12 ) < 12 ) return 0;
214 i_size = GetWBE( &header[2] ) - 12;
215 i_id = GetWBE( &header[4] );
216 i_pts = 1000 * GetDWBE( &header[6] );
217 i_pts += 1000; /* Avoid 0 pts */
218 i_flags= header[11]; /* flags 0x02 -> keyframe */
221 msg_Dbg( p_demux, "packet %d size=%d id=%d pts=%u",
222 p_sys->i_data_packets, i_size, i_id, (uint32_t)(i_pts/1000) );
225 p_sys->i_data_packets++;
227 stream_Read( p_demux->s, p_sys->buffer, i_size );
229 for( i = 0; i < p_sys->i_track; i++ )
231 if( p_sys->track[i]->i_id == i_id ) tk = p_sys->track[i];
236 msg_Warn( p_demux, "unknown track id(0x%x)", i_id );
239 es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE, tk->p_es, &b_selected );
241 if( tk->fmt.i_cat == VIDEO_ES && b_selected )
243 uint8_t *p = p_sys->buffer;
245 while( p < &p_sys->buffer[i_size - 2] )
254 if( (h&0xc0) == 0x40 )
258 i_len = &p_sys->buffer[i_size] - p;
264 i_subseq = (*p++)&0x7f;
266 i_len = (p[0] << 8)|p[1]; p += 2;
267 if( (i_len&0xc000) == 0 )
270 i_len |= (p[0] << 8)|p[1]; p += 2;
278 i_offset = (p[0] << 8)|p[1]; p += 2;
279 if( (i_offset&0xc000) == 0 )
282 i_offset |= (p[0] << 8)|p[1]; p += 2;
283 i_offset &= 0x3fffffff;
292 i_copy = i_len - i_offset;
293 if( i_copy > &p_sys->buffer[i_size] - p )
295 i_copy = &p_sys->buffer[i_size] - p;
297 else if( i_copy < 0 )
302 msg_Dbg( p_demux, " - len=%d offset=%d size=%d subseq=%d seqnum=%d",
303 i_len, i_offset, i_copy, i_subseq, i_seqnum );
305 if( (h&0xc0) == 0x80 )
307 /* last fragment -> fixes */
309 i_offset = i_len - i_copy;
310 msg_Dbg( p_demux, "last fixing copy=%d offset=%d",
315 ( tk->p_frame->i_dts != i_pts ||
316 tk->i_frame != i_len ) )
318 msg_Dbg( p_demux, "sending size=%d", tk->p_frame->i_buffer );
320 if( p_sys->i_pcr < tk->p_frame->i_dts )
322 p_sys->i_pcr = tk->p_frame->i_dts;
324 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
325 (int64_t)p_sys->i_pcr );
327 es_out_Send( p_demux->out, tk->p_es, tk->p_frame );
333 if( (h&0xc0) != 0x80 && (h&0xc0) != 0x00 && !tk->p_frame )
341 if( tk->p_frame == NULL )
343 msg_Dbg( p_demux, "new frame size=%d", i_len );
345 if( !( tk->p_frame = block_New( p_demux, i_len + 8 + 1000) ) )
349 memset( &tk->p_frame->p_buffer[8], 0, i_len );
350 tk->p_frame->i_dts = i_pts;
351 tk->p_frame->i_pts = i_pts;
353 ((uint32_t*)tk->p_frame->p_buffer)[0] = i_len; /* len */
354 ((uint32_t*)tk->p_frame->p_buffer)[1] = 0; /* chunk counts */
357 if( i_offset < tk->i_frame)
359 int i_ck = ((uint32_t*)tk->p_frame->p_buffer)[1]++;
361 msg_Dbg( p_demux, "copying new buffer n=%d offset=%d copy=%d",
362 i_ck, i_offset, i_copy );
364 ((uint32_t*)(tk->p_frame->p_buffer+i_len+8))[i_ck] = i_offset;
366 memcpy( &tk->p_frame->p_buffer[i_offset + 8], p, i_copy );
371 if( (h&0xc0) != 0x80 )
380 int i_ck = ((uint32_t*)tk->p_frame->p_buffer)[1]++;
382 if( (h&0xc0) == 0x80 )
386 i_offset = i_len - i_offset;
388 ((uint32_t*)(tk->p_frame->p_buffer+i_len+8))[i_ck] = i_offset;
389 memcpy( &tk->p_frame->p_buffer[i_offset+ 8], p, i_copy );
392 if( p_sys->i_pcr < tk->p_frame->i_dts )
394 p_sys->i_pcr = tk->p_frame->i_dts;
395 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
396 (int64_t)p_sys->i_pcr );
398 es_out_Send( p_demux->out, tk->p_es, tk->p_frame );
406 ((uint32_t*)(tk->p_frame->p_buffer+i_len+8))[i_ck] = i_offset;
407 memcpy( &tk->p_frame->p_buffer[i_offset + 8], p, i_copy );
411 if( (h&0xc0) != 0x00 )
416 if( !( p_frame = block_New( p_demux, i_copy + 8 + 8 ) ) )
420 p_frame->i_dts = i_pts;
421 p_frame->i_pts = i_pts;
423 ((uint32_t*)p_frame->p_buffer)[0] = i_copy;
424 ((uint32_t*)p_frame->p_buffer)[1] = 1;
425 ((uint32_t*)(p_frame->p_buffer+i_copy+8))[0] = 0;
426 memcpy( &p_frame->p_buffer[8], p, i_copy );
430 if( p_sys->i_pcr < p_frame->i_dts )
432 p_sys->i_pcr = p_frame->i_dts;
433 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
434 (int64_t)p_sys->i_pcr );
436 es_out_Send( p_demux->out, tk->p_es, p_frame );
442 if( !( tk->p_frame = block_New( p_demux, i_len + 8 + 1000) ) )
446 memset( &tk->p_frame->p_buffer[8], 0, i_len );
447 tk->p_frame->i_dts = i_pts;
448 tk->p_frame->i_pts = i_pts;
450 ((uint32_t*)tk->p_frame->p_buffer)[0] = i_len; /* len */
451 ((uint32_t*)tk->p_frame->p_buffer)[1] = 1; /* chunk counts */
452 ((uint32_t*)(tk->p_frame->p_buffer+i_len+8))[0] = i_offset;
453 memcpy( &tk->p_frame->p_buffer[i_offset + 8], p, i_copy );
460 else if( tk->fmt.i_cat == AUDIO_ES && b_selected )
463 if( p_sys->i_pcr < i_pts )
465 p_sys->i_pcr = i_pts;
466 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
467 (int64_t)p_sys->i_pcr );
470 if( tk->fmt.i_codec == VLC_FOURCC( 'm', 'p', '4', 'a' ) )
472 int i_sub = (p_sys->buffer[1] >> 4)&0x0f;
473 uint8_t *p_sub = &p_sys->buffer[2+2*i_sub];
476 for( i = 0; i < i_sub; i++ )
478 int i_sub_size = GetWBE( &p_sys->buffer[2+i*2]);
479 block_t *p_block = block_New( p_demux, i_sub_size );
482 memcpy( p_block->p_buffer, p_sub, i_sub_size );
486 p_block->i_pts = ( i == 0 ? i_pts : 0 );
488 es_out_Send( p_demux->out, tk->p_es, p_block );
492 else if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) ||
493 tk->fmt.i_codec == VLC_FOURCC('2','8','_','8') )
495 uint8_t *p_buf = p_sys->buffer;
496 int y = tk->i_subpacket / (tk->i_frame_size /tk->i_subpacket_size);
500 if( i_flags & 2 ) y = tk->i_subpacket = 0;
502 if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) )
503 for( i = 0; i < tk->i_frame_size / tk->i_subpacket_size; i++ )
505 block_t *p_block = block_New( p_demux, tk->i_subpacket_size );
506 memcpy( p_block->p_buffer, p_buf, tk->i_subpacket_size );
507 p_buf += tk->i_subpacket_size;
509 i_index = tk->i_subpacket_h * i +
510 ((tk->i_subpacket_h + 1) / 2) * (y&1) + (y>>1);
512 p_block->i_dts = p_block->i_pts = i_pts;
513 tk->p_subpackets[i_index] = p_block;
517 if( tk->fmt.i_codec == VLC_FOURCC('2','8','_','8') )
518 for( i = 0; i < tk->i_subpacket_h / 2; i++ )
520 block_t *p_block = block_New( p_demux, tk->i_coded_frame_size);
521 memcpy( p_block->p_buffer, p_buf, tk->i_coded_frame_size );
522 p_buf += tk->i_coded_frame_size;
524 i_index = (i * 2 * tk->i_frame_size) /
525 tk->i_coded_frame_size + y;
527 p_block->i_dts = p_block->i_pts = i_pts;
528 tk->p_subpackets[i_index] = p_block;
532 while( tk->i_out_subpacket != tk->i_subpackets &&
533 tk->p_subpackets[tk->i_out_subpacket] )
535 block_t *p_block = tk->p_subpackets[tk->i_out_subpacket];
536 tk->p_subpackets[tk->i_out_subpacket] = 0;
538 if( tk->i_out_subpacket ) p_block->i_dts = p_block->i_pts = 0;
539 es_out_Send( p_demux->out, tk->p_es, p_block );
541 tk->i_out_subpacket++;
544 if( tk->i_subpacket == tk->i_subpackets &&
545 tk->i_out_subpacket != tk->i_subpackets )
547 msg_Warn( p_demux, "i_subpacket != i_out_subpacket, "
548 "this shouldn't happen" );
551 if( tk->i_subpacket == tk->i_subpackets )
554 tk->i_out_subpacket = 0;
559 block_t *p_block = block_New( p_demux, i_size );
561 if( tk->fmt.i_codec == VLC_FOURCC( 'a', '5', '2', ' ' ) )
563 uint8_t *src = p_sys->buffer;
564 uint8_t *dst = p_block->p_buffer;
567 while( dst < &p_block->p_buffer[i_size- 1])
577 memcpy( p_block->p_buffer, p_sys->buffer, i_size );
579 p_block->i_dts = p_block->i_pts = i_pts;
580 es_out_Send( p_demux->out, tk->p_es, p_block );
588 /*****************************************************************************
590 *****************************************************************************/
591 static int Control( demux_t *p_demux, int i_query, va_list args )
594 demux_sys_t *p_sys = p_demux->p_sys;
600 case DEMUX_GET_POSITION:
601 pf = (double*) va_arg( args, double* );
602 i64 = stream_Size( p_demux->s );
605 *pf = (double)stream_Tell( p_demux->s ) / (double)i64;
612 case DEMUX_SET_POSITION:
613 f = (double) va_arg( args, double );
614 i64 = stream_Size( p_demux->s );
616 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
618 return stream_Seek( p_demux->s, (int64_t)(i64 * f) );
621 pi64 = (int64_t*)va_arg( args, int64_t * );
622 if( p_sys->i_mux_rate > 0 )
624 *pi64 = (int64_t)1000000 * ( stream_Tell( p_demux->s ) / 50 ) / p_sys->i_mux_rate;
630 case DEMUX_GET_LENGTH:
631 pi64 = (int64_t*)va_arg( args, int64_t * );
632 if( p_sys->i_mux_rate > 0 )
634 *pi64 = (int64_t)1000000 * ( stream_Size( p_demux->s ) / 50 ) / p_sys->i_mux_rate;
649 /*****************************************************************************
651 *****************************************************************************/
652 static int HeaderRead( demux_t *p_demux )
654 demux_sys_t *p_sys = p_demux->p_sys;
655 uint8_t header[100]; /* FIXME */
664 /* Read the header */
665 if( stream_Read( p_demux->s, header, 10 ) < 10 )
669 i_id = VLC_FOURCC( header[0], header[1], header[2], header[3] );
670 i_size = GetDWBE( &header[4] );
671 i_version = GetWBE( &header[8] );
673 msg_Dbg( p_demux, "object %4.4s size=%d version=%d",
674 (char*)&i_id, i_size, i_version );
678 msg_Dbg( p_demux, "invalid size for object %4.4s", (char*)&i_id );
681 i_skip = i_size - 10;
683 if( i_id == VLC_FOURCC('.','R','M','F') )
685 if( stream_Read( p_demux->s, header, 8 ) < 8 ) return VLC_EGENERIC;
686 msg_Dbg( p_demux, " - file version=0x%x num headers=%d",
687 GetDWBE( &header[0] ), GetDWBE( &header[4] ) );
691 else if( i_id == VLC_FOURCC('P','R','O','P') )
695 if( stream_Read(p_demux->s, header, 40) < 40 ) return VLC_EGENERIC;
697 msg_Dbg( p_demux, " - max bitrate=%d avg bitrate=%d",
698 GetDWBE(&header[0]), GetDWBE(&header[4]) );
699 msg_Dbg( p_demux, " - max packet size=%d avg bitrate=%d",
700 GetDWBE(&header[8]), GetDWBE(&header[12]) );
701 msg_Dbg( p_demux, " - packets count=%d", GetDWBE(&header[16]) );
702 msg_Dbg( p_demux, " - duration=%d ms", GetDWBE(&header[20]) );
703 msg_Dbg( p_demux, " - preroll=%d ms", GetDWBE(&header[24]) );
704 msg_Dbg( p_demux, " - index offset=%d", GetDWBE(&header[28]) );
705 msg_Dbg( p_demux, " - data offset=%d", GetDWBE(&header[32]) );
706 msg_Dbg( p_demux, " - num streams=%d", GetWBE(&header[36]) );
707 i_flags = GetWBE(&header[38]);
708 msg_Dbg( p_demux, " - flags=0x%x %s%s%s",
710 i_flags&0x0001 ? "PN_SAVE_ENABLED " : "",
711 i_flags&0x0002 ? "PN_PERFECT_PLAY_ENABLED " : "",
712 i_flags&0x0004 ? "PN_LIVE_BROADCAST" : "" );
715 else if( i_id == VLC_FOURCC('C','O','N','T') )
720 stream_Read( p_demux->s, header, 2 );
721 if( ( i_len = GetWBE( header ) ) > 0 )
723 psz = malloc( i_len + 1 );
724 stream_Read( p_demux->s, psz, i_len );
727 msg_Dbg( p_demux, " - title=`%s'", psz );
733 stream_Read( p_demux->s, header, 2 );
734 if( ( i_len = GetWBE( header ) ) > 0 )
736 psz = malloc( i_len + 1 );
737 stream_Read( p_demux->s, psz, i_len );
740 msg_Dbg( p_demux, " - author=`%s'", psz );
746 stream_Read( p_demux->s, header, 2 );
747 if( ( i_len = GetWBE( header ) ) > 0 )
749 psz = malloc( i_len + 1 );
750 stream_Read( p_demux->s, psz, i_len );
753 msg_Dbg( p_demux, " - copyright=`%s'", psz );
759 stream_Read( p_demux->s, header, 2 );
760 if( ( i_len = GetWBE( header ) ) > 0 )
762 psz = malloc( i_len + 1 );
763 stream_Read( p_demux->s, psz, i_len );
766 msg_Dbg( p_demux, " - comment=`%s'", psz );
772 else if( i_id == VLC_FOURCC('M','D','P','R') )
774 /* Media properties header */
779 if( stream_Read(p_demux->s, header, 30) < 30 ) return VLC_EGENERIC;
780 i_num = GetWBE( header );
781 msg_Dbg( p_demux, " - id=0x%x", i_num );
782 msg_Dbg( p_demux, " - max bitrate=%d avg bitrate=%d",
783 GetDWBE(&header[2]), GetDWBE(&header[6]) );
784 msg_Dbg( p_demux, " - max packet size=%d avg packet size=%d",
785 GetDWBE(&header[10]), GetDWBE(&header[14]) );
786 msg_Dbg( p_demux, " - start time=%d", GetDWBE(&header[18]) );
787 msg_Dbg( p_demux, " - preroll=%d", GetDWBE(&header[22]) );
788 msg_Dbg( p_demux, " - duration=%d", GetDWBE(&header[26]) );
791 stream_Read( p_demux->s, header, 1 );
792 if( ( i_len = header[0] ) > 0 )
794 psz = malloc( i_len + 1 );
795 stream_Read( p_demux->s, psz, i_len );
798 msg_Dbg( p_demux, " - name=`%s'", psz );
804 stream_Read( p_demux->s, header, 1 );
805 if( ( i_len = header[0] ) > 0 )
807 psz = malloc( i_len + 1 );
808 stream_Read( p_demux->s, psz, i_len );
811 msg_Dbg( p_demux, " - mime=`%s'", psz );
817 stream_Read( p_demux->s, header, 4 );
818 if( ( i_len = GetDWBE( header ) ) > 0 )
820 ReadCodecSpecificData( p_demux, i_len, i_num );
821 stream_Read( p_demux->s, NULL, i_len );
827 else if( i_id == VLC_FOURCC('D','A','T','A') )
829 stream_Read( p_demux->s, header, 8 );
831 p_sys->i_data_offset = stream_Tell( p_demux->s ) - 10;
832 p_sys->i_data_size = i_size;
833 p_sys->i_data_packets_count = GetDWBE( header );
834 p_sys->i_data_packets = 0;
835 p_sys->i_data_offset_next = GetDWBE( &header[4] );
837 msg_Dbg( p_demux, " - packets count=%d next=%u",
838 p_sys->i_data_packets_count,
839 (uint32_t)p_sys->i_data_offset_next );
841 /* we have finished the header */
847 msg_Dbg( p_demux, "unknown chunk" );
850 if( i_skip < 0 ) return VLC_EGENERIC;
851 stream_Read( p_demux->s, NULL, i_skip );
854 /* TODO read index if possible */
859 static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
861 demux_sys_t *p_sys = p_demux->p_sys;
866 msg_Dbg( p_demux, " - specific data len=%d", i_len );
867 if( stream_Peek(p_demux->s, &p_peek, i_len) < i_len ) return VLC_EGENERIC;
869 if( !strncmp( (char *)&p_peek[4], "VIDO", 4 ) )
871 es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( p_peek[8], p_peek[9],
872 p_peek[10], p_peek[11] ) );
873 fmt.video.i_width = GetWBE( &p_peek[12] );
874 fmt.video.i_height= GetWBE( &p_peek[14] );
877 fmt.p_extra = malloc( 8 );
878 ((uint32_t*)fmt.p_extra)[0] = GetDWBE( &p_peek[26] );
879 ((uint32_t*)fmt.p_extra)[1] = GetDWBE( &p_peek[30] );
881 msg_Dbg( p_demux, " - video 0x%08x 0x%08x",
882 ((uint32_t*)fmt.p_extra)[0], ((uint32_t*)fmt.p_extra)[1] );
884 if( GetDWBE( &p_peek[30] ) == 0x10003000 ||
885 GetDWBE( &p_peek[30] ) == 0x10003001 )
887 fmt.i_codec = VLC_FOURCC( 'R','V','1','3' );
889 else if( GetDWBE( &p_peek[30] ) == 0x20001000 ||
890 GetDWBE( &p_peek[30] ) == 0x20100001 ||
891 GetDWBE( &p_peek[30] ) == 0x20200002 )
893 fmt.i_codec = VLC_FOURCC( 'R','V','2','0' );
895 else if( GetDWBE( &p_peek[30] ) == 0x30202002 )
897 fmt.i_codec = VLC_FOURCC( 'R','V','3','0' );
899 else if( GetDWBE( &p_peek[30] ) == 0x40000000 )
901 fmt.i_codec = VLC_FOURCC( 'R','V','4','0' );
904 msg_Dbg( p_demux, " - video %4.4s %dx%d",
905 (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height );
907 tk = malloc( sizeof( real_track_t ) );
908 tk->i_out_subpacket = 0;
910 tk->i_subpackets = 0;
911 tk->p_subpackets = NULL;
916 tk->p_es = es_out_Add( p_demux->out, &fmt );
918 TAB_APPEND( p_sys->i_track, p_sys->track, tk );
920 else if( !strncmp( (char *)p_peek, ".ra\xfd", 4 ) )
922 int i_version = GetWBE( &p_peek[4] );
923 int i_header_size, i_flavor, i_coded_frame_size, i_subpacket_h;
924 int i_frame_size, i_subpacket_size;
926 msg_Dbg( p_demux, " - audio version=%d", i_version );
929 es_format_Init( &fmt, AUDIO_ES, 0 );
933 msg_Dbg( p_demux, " - audio version 3 is not supported!" );
937 p_peek += 2; /* 00 00 */
938 p_peek += 4; /* .ra4 or .ra5 */
939 p_peek += 4; /* ?? */
940 p_peek += 2; /* version (4 or 5) */
941 i_header_size = GetDWBE( p_peek ); p_peek += 4; /* header size */
942 i_flavor = GetWBE( p_peek ); p_peek += 2; /* codec flavor */
943 i_coded_frame_size = GetDWBE( p_peek ); p_peek += 4;
944 p_peek += 4; /* ?? */
945 p_peek += 4; /* ?? */
946 p_peek += 4; /* ?? */
947 i_subpacket_h = GetWBE( p_peek ); p_peek += 2;
948 i_frame_size = GetWBE( p_peek ); p_peek += 2;
949 i_subpacket_size = GetWBE( p_peek ); p_peek += 2;
950 p_peek += 2; /* ?? */
952 if( i_version == 5 ) p_peek += 6; /* 0, srate, 0 */
954 fmt.audio.i_rate = GetWBE( p_peek ); p_peek += 2;
955 p_peek += 2; /* ?? */
956 fmt.audio.i_bitspersample = GetWBE( p_peek ); p_peek += 2;
957 fmt.audio.i_channels = GetWBE( p_peek ); p_peek += 2;
958 fmt.audio.i_blockalign = i_frame_size;
962 p_peek += 4; /* genr */
963 memcpy( (char *)&fmt.i_codec, p_peek, 4 ); p_peek += 4;
967 p_peek += p_peek[0] + 1; /* descr 1 */
968 memcpy( (char *)&fmt.i_codec, p_peek + 1, 4 ); /* descr 2 */
969 p_peek += p_peek[0] + 1;
972 msg_Dbg( p_demux, " - audio codec=%4.4s channels=%d rate=%dHz",
973 (char*)&fmt.i_codec, fmt.audio.i_channels, fmt.audio.i_rate );
975 p_peek += 3; /* ?? */
976 if( i_version == 5 ) p_peek++;
978 switch( fmt.i_codec )
980 case VLC_FOURCC( 'd', 'n', 'e', 't' ):
981 fmt.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
984 case VLC_FOURCC( 'r', 'a', 'a', 'c' ):
985 case VLC_FOURCC( 'r', 'a', 'c', 'p' ):
986 fmt.i_extra = GetDWBE( p_peek ); p_peek += 4;
987 if( fmt.i_extra > 0 ) { fmt.i_extra--; p_peek++; }
988 if( fmt.i_extra > 0 )
990 fmt.p_extra = malloc( fmt.i_extra );
991 memcpy( fmt.p_extra, p_peek, fmt.i_extra );
994 fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
997 case VLC_FOURCC('c','o','o','k'):
998 fmt.audio.i_blockalign = i_subpacket_size;
999 if( !(fmt.i_extra = GetDWBE( p_peek )) ) break;
1000 fmt.p_extra = malloc( fmt.i_extra );
1001 memcpy( fmt.p_extra, p_peek + 4, fmt.i_extra );
1004 case VLC_FOURCC('2','8','_','8'):
1005 fmt.audio.i_blockalign = i_coded_frame_size;
1009 msg_Dbg( p_demux, " - unknown audio codec=%4.4s",
1010 (char*)&fmt.i_codec );
1014 if( fmt.i_codec != 0 )
1018 msg_Dbg( p_demux, " - extra data=%d", fmt.i_extra );
1020 tk = malloc( sizeof( real_track_t ) );
1026 tk->i_subpacket_h = i_subpacket_h;
1027 tk->i_subpacket_size = i_subpacket_size;
1028 tk->i_coded_frame_size = i_coded_frame_size;
1029 tk->i_frame_size = i_frame_size;
1031 tk->i_out_subpacket = 0;
1032 tk->i_subpacket = 0;
1033 tk->i_subpackets = 0;
1034 tk->p_subpackets = NULL;
1035 if( fmt.i_codec == VLC_FOURCC('c','o','o','k') )
1038 i_subpacket_h * i_frame_size / tk->i_subpacket_size;
1040 malloc( tk->i_subpackets * sizeof(block_t *) );
1042 else if( fmt.i_codec == VLC_FOURCC('2','8','_','8') )
1045 i_subpacket_h * i_frame_size / tk->i_coded_frame_size;
1047 malloc( tk->i_subpackets * sizeof(block_t *) );
1050 for( i = 0; i < tk->i_subpackets; i++ ) tk->p_subpackets[i] = NULL;
1052 tk->p_es = es_out_Add( p_demux->out, &fmt );
1054 TAB_APPEND( p_sys->i_track, p_sys->track, tk );