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];
159 if( tk->p_frame ) block_Release( tk->p_frame );
160 es_format_Clean( &tk->fmt );
162 while( tk->i_subpackets-- )
164 if( tk->p_subpackets[tk->i_subpackets] )
165 block_Release( tk->p_subpackets[tk->i_subpackets] );
166 if( !tk->i_subpackets ) free( tk->p_subpackets );
172 if( p_sys->i_track > 0 ) free( p_sys->track );
177 /*****************************************************************************
179 *****************************************************************************/
180 static int Demux( demux_t *p_demux )
182 demux_sys_t *p_sys = p_demux->p_sys;
184 int i_size, i_id, i_flags, i;
186 real_track_t *tk = NULL;
187 vlc_bool_t b_selected;
189 if( p_sys->i_data_packets >= p_sys->i_data_packets_count &&
190 p_sys->i_data_packets_count )
192 if( stream_Read( p_demux->s, header, 18 ) < 18 )
196 if( strncmp( (char *)header, "DATA", 4 ) )
200 p_sys->i_data_offset = stream_Tell( p_demux->s ) - 18;
201 p_sys->i_data_size = GetDWBE( &header[4] );
202 p_sys->i_data_packets_count = GetDWBE( &header[10] );
203 p_sys->i_data_packets = 0;
204 p_sys->i_data_offset_next = GetDWBE( &header[14] );
206 msg_Dbg( p_demux, "entering new DATA packets=%d next=%u",
207 p_sys->i_data_packets_count,
208 (uint32_t)p_sys->i_data_offset_next );
211 if( stream_Read( p_demux->s, header, 12 ) < 12 ) return 0;
213 i_size = GetWBE( &header[2] ) - 12;
214 i_id = GetWBE( &header[4] );
215 i_pts = 1000 * GetDWBE( &header[6] );
216 i_pts += 1000; /* Avoid 0 pts */
217 i_flags= header[11]; /* flags 0x02 -> keyframe */
220 msg_Dbg( p_demux, "packet %d size=%d id=%d pts=%u",
221 p_sys->i_data_packets, i_size, i_id, (uint32_t)(i_pts/1000) );
224 p_sys->i_data_packets++;
226 stream_Read( p_demux->s, p_sys->buffer, i_size );
228 for( i = 0; i < p_sys->i_track; i++ )
230 if( p_sys->track[i]->i_id == i_id ) tk = p_sys->track[i];
235 msg_Warn( p_demux, "unknown track id(0x%x)", i_id );
238 es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE, tk->p_es, &b_selected );
240 if( tk->fmt.i_cat == VIDEO_ES && b_selected )
242 uint8_t *p = p_sys->buffer;
244 while( p < &p_sys->buffer[i_size - 2] )
253 if( (h&0xc0) == 0x40 )
257 i_len = &p_sys->buffer[i_size] - p;
263 i_subseq = (*p++)&0x7f;
265 i_len = (p[0] << 8)|p[1]; p += 2;
266 if( (i_len&0xc000) == 0 )
269 i_len |= (p[0] << 8)|p[1]; p += 2;
277 i_offset = (p[0] << 8)|p[1]; p += 2;
278 if( (i_offset&0xc000) == 0 )
281 i_offset |= (p[0] << 8)|p[1]; p += 2;
282 i_offset &= 0x3fffffff;
291 i_copy = i_len - i_offset;
292 if( i_copy > &p_sys->buffer[i_size] - p )
294 i_copy = &p_sys->buffer[i_size] - p;
296 else if( i_copy < 0 )
301 msg_Dbg( p_demux, " - len=%d offset=%d size=%d subseq=%d seqnum=%d",
302 i_len, i_offset, i_copy, i_subseq, i_seqnum );
304 if( (h&0xc0) == 0x80 )
306 /* last fragment -> fixes */
308 i_offset = i_len - i_copy;
309 msg_Dbg( p_demux, "last fixing copy=%d offset=%d",
314 ( tk->p_frame->i_dts != i_pts ||
315 tk->i_frame != i_len ) )
317 msg_Dbg( p_demux, "sending size=%d", tk->p_frame->i_buffer );
319 if( p_sys->i_pcr < tk->p_frame->i_dts )
321 p_sys->i_pcr = tk->p_frame->i_dts;
323 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
324 (int64_t)p_sys->i_pcr );
326 es_out_Send( p_demux->out, tk->p_es, tk->p_frame );
332 if( (h&0xc0) != 0x80 && (h&0xc0) != 0x00 && !tk->p_frame )
340 if( tk->p_frame == NULL )
342 msg_Dbg( p_demux, "new frame size=%d", i_len );
344 if( !( tk->p_frame = block_New( p_demux, i_len + 8 + 1000) ) )
348 memset( &tk->p_frame->p_buffer[8], 0, i_len );
349 tk->p_frame->i_dts = i_pts;
350 tk->p_frame->i_pts = i_pts;
352 ((uint32_t*)tk->p_frame->p_buffer)[0] = i_len; /* len */
353 ((uint32_t*)tk->p_frame->p_buffer)[1] = 0; /* chunk counts */
356 if( i_offset < tk->i_frame)
358 int i_ck = ((uint32_t*)tk->p_frame->p_buffer)[1]++;
360 msg_Dbg( p_demux, "copying new buffer n=%d offset=%d copy=%d",
361 i_ck, i_offset, i_copy );
363 ((uint32_t*)(tk->p_frame->p_buffer+i_len+8))[i_ck] = i_offset;
365 memcpy( &tk->p_frame->p_buffer[i_offset + 8], p, i_copy );
370 if( (h&0xc0) != 0x80 )
379 int i_ck = ((uint32_t*)tk->p_frame->p_buffer)[1]++;
381 if( (h&0xc0) == 0x80 )
385 i_offset = i_len - i_offset;
387 ((uint32_t*)(tk->p_frame->p_buffer+i_len+8))[i_ck] = i_offset;
388 memcpy( &tk->p_frame->p_buffer[i_offset+ 8], p, i_copy );
391 if( p_sys->i_pcr < tk->p_frame->i_dts )
393 p_sys->i_pcr = tk->p_frame->i_dts;
394 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
395 (int64_t)p_sys->i_pcr );
397 es_out_Send( p_demux->out, tk->p_es, tk->p_frame );
405 ((uint32_t*)(tk->p_frame->p_buffer+i_len+8))[i_ck] = i_offset;
406 memcpy( &tk->p_frame->p_buffer[i_offset + 8], p, i_copy );
410 if( (h&0xc0) != 0x00 )
415 if( !( p_frame = block_New( p_demux, i_copy + 8 + 8 ) ) )
419 p_frame->i_dts = i_pts;
420 p_frame->i_pts = i_pts;
422 ((uint32_t*)p_frame->p_buffer)[0] = i_copy;
423 ((uint32_t*)p_frame->p_buffer)[1] = 1;
424 ((uint32_t*)(p_frame->p_buffer+i_copy+8))[0] = 0;
425 memcpy( &p_frame->p_buffer[8], p, i_copy );
429 if( p_sys->i_pcr < p_frame->i_dts )
431 p_sys->i_pcr = p_frame->i_dts;
432 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
433 (int64_t)p_sys->i_pcr );
435 es_out_Send( p_demux->out, tk->p_es, p_frame );
441 if( !( tk->p_frame = block_New( p_demux, i_len + 8 + 1000) ) )
445 memset( &tk->p_frame->p_buffer[8], 0, i_len );
446 tk->p_frame->i_dts = i_pts;
447 tk->p_frame->i_pts = i_pts;
449 ((uint32_t*)tk->p_frame->p_buffer)[0] = i_len; /* len */
450 ((uint32_t*)tk->p_frame->p_buffer)[1] = 1; /* chunk counts */
451 ((uint32_t*)(tk->p_frame->p_buffer+i_len+8))[0] = i_offset;
452 memcpy( &tk->p_frame->p_buffer[i_offset + 8], p, i_copy );
459 else if( tk->fmt.i_cat == AUDIO_ES && b_selected )
462 if( p_sys->i_pcr < i_pts )
464 p_sys->i_pcr = i_pts;
465 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
466 (int64_t)p_sys->i_pcr );
469 if( tk->fmt.i_codec == VLC_FOURCC( 'm', 'p', '4', 'a' ) )
471 int i_sub = (p_sys->buffer[1] >> 4)&0x0f;
472 uint8_t *p_sub = &p_sys->buffer[2+2*i_sub];
475 for( i = 0; i < i_sub; i++ )
477 int i_sub_size = GetWBE( &p_sys->buffer[2+i*2]);
478 block_t *p_block = block_New( p_demux, i_sub_size );
481 memcpy( p_block->p_buffer, p_sub, i_sub_size );
485 p_block->i_pts = ( i == 0 ? i_pts : 0 );
487 es_out_Send( p_demux->out, tk->p_es, p_block );
491 else if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) ||
492 tk->fmt.i_codec == VLC_FOURCC('2','8','_','8') )
494 uint8_t *p_buf = p_sys->buffer;
495 int y = tk->i_subpacket / (tk->i_frame_size /tk->i_subpacket_size);
499 if( i_flags & 2 ) y = tk->i_subpacket = 0;
501 if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) )
502 for( i = 0; i < tk->i_frame_size / tk->i_subpacket_size; i++ )
504 block_t *p_block = block_New( p_demux, tk->i_subpacket_size );
505 memcpy( p_block->p_buffer, p_buf, tk->i_subpacket_size );
506 p_buf += tk->i_subpacket_size;
508 i_index = tk->i_subpacket_h * i +
509 ((tk->i_subpacket_h + 1) / 2) * (y&1) + (y>>1);
511 p_block->i_dts = p_block->i_pts = i_pts;
512 tk->p_subpackets[i_index] = p_block;
516 if( tk->fmt.i_codec == VLC_FOURCC('2','8','_','8') )
517 for( i = 0; i < tk->i_subpacket_h / 2; i++ )
519 block_t *p_block = block_New( p_demux, tk->i_coded_frame_size);
520 memcpy( p_block->p_buffer, p_buf, tk->i_coded_frame_size );
521 p_buf += tk->i_coded_frame_size;
523 i_index = (i * 2 * tk->i_frame_size) /
524 tk->i_coded_frame_size + y;
526 p_block->i_dts = p_block->i_pts = i_pts;
527 tk->p_subpackets[i_index] = p_block;
531 while( tk->i_out_subpacket != tk->i_subpackets &&
532 tk->p_subpackets[tk->i_out_subpacket] )
534 block_t *p_block = tk->p_subpackets[tk->i_out_subpacket];
535 tk->p_subpackets[tk->i_out_subpacket] = 0;
537 if( tk->i_out_subpacket ) p_block->i_dts = p_block->i_pts = 0;
538 es_out_Send( p_demux->out, tk->p_es, p_block );
540 tk->i_out_subpacket++;
543 if( tk->i_subpacket == tk->i_subpackets &&
544 tk->i_out_subpacket != tk->i_subpackets )
546 msg_Warn( p_demux, "i_subpacket != i_out_subpacket, "
547 "this shouldn't happen" );
550 if( tk->i_subpacket == tk->i_subpackets )
553 tk->i_out_subpacket = 0;
558 block_t *p_block = block_New( p_demux, i_size );
560 if( tk->fmt.i_codec == VLC_FOURCC( 'a', '5', '2', ' ' ) )
562 uint8_t *src = p_sys->buffer;
563 uint8_t *dst = p_block->p_buffer;
566 while( dst < &p_block->p_buffer[i_size- 1])
576 memcpy( p_block->p_buffer, p_sys->buffer, i_size );
578 p_block->i_dts = p_block->i_pts = i_pts;
579 es_out_Send( p_demux->out, tk->p_es, p_block );
587 /*****************************************************************************
589 *****************************************************************************/
590 static int Control( demux_t *p_demux, int i_query, va_list args )
593 demux_sys_t *p_sys = p_demux->p_sys;
599 case DEMUX_GET_POSITION:
600 pf = (double*) va_arg( args, double* );
601 i64 = stream_Size( p_demux->s );
604 *pf = (double)stream_Tell( p_demux->s ) / (double)i64;
611 case DEMUX_SET_POSITION:
612 f = (double) va_arg( args, double );
613 i64 = stream_Size( p_demux->s );
615 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
617 return stream_Seek( p_demux->s, (int64_t)(i64 * f) );
620 pi64 = (int64_t*)va_arg( args, int64_t * );
621 if( p_sys->i_mux_rate > 0 )
623 *pi64 = (int64_t)1000000 * ( stream_Tell( p_demux->s ) / 50 ) / p_sys->i_mux_rate;
629 case DEMUX_GET_LENGTH:
630 pi64 = (int64_t*)va_arg( args, int64_t * );
631 if( p_sys->i_mux_rate > 0 )
633 *pi64 = (int64_t)1000000 * ( stream_Size( p_demux->s ) / 50 ) / p_sys->i_mux_rate;
648 /*****************************************************************************
650 *****************************************************************************/
651 static int HeaderRead( demux_t *p_demux )
653 demux_sys_t *p_sys = p_demux->p_sys;
654 uint8_t header[100]; /* FIXME */
663 /* Read the header */
664 if( stream_Read( p_demux->s, header, 10 ) < 10 )
668 i_id = VLC_FOURCC( header[0], header[1], header[2], header[3] );
669 i_size = GetDWBE( &header[4] );
670 i_version = GetWBE( &header[8] );
672 msg_Dbg( p_demux, "object %4.4s size=%d version=%d",
673 (char*)&i_id, i_size, i_version );
677 msg_Dbg( p_demux, "invalid size for object %4.4s", (char*)&i_id );
680 i_skip = i_size - 10;
682 if( i_id == VLC_FOURCC('.','R','M','F') )
684 if( stream_Read( p_demux->s, header, 8 ) < 8 ) return VLC_EGENERIC;
685 msg_Dbg( p_demux, " - file version=0x%x num headers=%d",
686 GetDWBE( &header[0] ), GetDWBE( &header[4] ) );
690 else if( i_id == VLC_FOURCC('P','R','O','P') )
694 if( stream_Read(p_demux->s, header, 40) < 40 ) return VLC_EGENERIC;
696 msg_Dbg( p_demux, " - max bitrate=%d avg bitrate=%d",
697 GetDWBE(&header[0]), GetDWBE(&header[4]) );
698 msg_Dbg( p_demux, " - max packet size=%d avg bitrate=%d",
699 GetDWBE(&header[8]), GetDWBE(&header[12]) );
700 msg_Dbg( p_demux, " - packets count=%d", GetDWBE(&header[16]) );
701 msg_Dbg( p_demux, " - duration=%d ms", GetDWBE(&header[20]) );
702 msg_Dbg( p_demux, " - preroll=%d ms", GetDWBE(&header[24]) );
703 msg_Dbg( p_demux, " - index offset=%d", GetDWBE(&header[28]) );
704 msg_Dbg( p_demux, " - data offset=%d", GetDWBE(&header[32]) );
705 msg_Dbg( p_demux, " - num streams=%d", GetWBE(&header[36]) );
706 i_flags = GetWBE(&header[38]);
707 msg_Dbg( p_demux, " - flags=0x%x %s%s%s",
709 i_flags&0x0001 ? "PN_SAVE_ENABLED " : "",
710 i_flags&0x0002 ? "PN_PERFECT_PLAY_ENABLED " : "",
711 i_flags&0x0004 ? "PN_LIVE_BROADCAST" : "" );
714 else if( i_id == VLC_FOURCC('C','O','N','T') )
719 stream_Read( p_demux->s, header, 2 );
720 if( ( i_len = GetWBE( header ) ) > 0 )
722 psz = malloc( i_len + 1 );
723 stream_Read( p_demux->s, psz, i_len );
726 msg_Dbg( p_demux, " - title=`%s'", psz );
732 stream_Read( p_demux->s, header, 2 );
733 if( ( i_len = GetWBE( header ) ) > 0 )
735 psz = malloc( i_len + 1 );
736 stream_Read( p_demux->s, psz, i_len );
739 msg_Dbg( p_demux, " - author=`%s'", psz );
745 stream_Read( p_demux->s, header, 2 );
746 if( ( i_len = GetWBE( header ) ) > 0 )
748 psz = malloc( i_len + 1 );
749 stream_Read( p_demux->s, psz, i_len );
752 msg_Dbg( p_demux, " - copyright=`%s'", psz );
758 stream_Read( p_demux->s, header, 2 );
759 if( ( i_len = GetWBE( header ) ) > 0 )
761 psz = malloc( i_len + 1 );
762 stream_Read( p_demux->s, psz, i_len );
765 msg_Dbg( p_demux, " - comment=`%s'", psz );
771 else if( i_id == VLC_FOURCC('M','D','P','R') )
773 /* Media properties header */
778 if( stream_Read(p_demux->s, header, 30) < 30 ) return VLC_EGENERIC;
779 i_num = GetWBE( header );
780 msg_Dbg( p_demux, " - id=0x%x", i_num );
781 msg_Dbg( p_demux, " - max bitrate=%d avg bitrate=%d",
782 GetDWBE(&header[2]), GetDWBE(&header[6]) );
783 msg_Dbg( p_demux, " - max packet size=%d avg packet size=%d",
784 GetDWBE(&header[10]), GetDWBE(&header[14]) );
785 msg_Dbg( p_demux, " - start time=%d", GetDWBE(&header[18]) );
786 msg_Dbg( p_demux, " - preroll=%d", GetDWBE(&header[22]) );
787 msg_Dbg( p_demux, " - duration=%d", GetDWBE(&header[26]) );
790 stream_Read( p_demux->s, header, 1 );
791 if( ( i_len = header[0] ) > 0 )
793 psz = malloc( i_len + 1 );
794 stream_Read( p_demux->s, psz, i_len );
797 msg_Dbg( p_demux, " - name=`%s'", psz );
803 stream_Read( p_demux->s, header, 1 );
804 if( ( i_len = header[0] ) > 0 )
806 psz = malloc( i_len + 1 );
807 stream_Read( p_demux->s, psz, i_len );
810 msg_Dbg( p_demux, " - mime=`%s'", psz );
816 stream_Read( p_demux->s, header, 4 );
817 if( ( i_len = GetDWBE( header ) ) > 0 )
819 ReadCodecSpecificData( p_demux, i_len, i_num );
820 stream_Read( p_demux->s, NULL, i_len );
826 else if( i_id == VLC_FOURCC('D','A','T','A') )
828 stream_Read( p_demux->s, header, 8 );
830 p_sys->i_data_offset = stream_Tell( p_demux->s ) - 10;
831 p_sys->i_data_size = i_size;
832 p_sys->i_data_packets_count = GetDWBE( header );
833 p_sys->i_data_packets = 0;
834 p_sys->i_data_offset_next = GetDWBE( &header[4] );
836 msg_Dbg( p_demux, " - packets count=%d next=%u",
837 p_sys->i_data_packets_count,
838 (uint32_t)p_sys->i_data_offset_next );
840 /* we have finished the header */
846 msg_Dbg( p_demux, "unknown chunk" );
849 if( i_skip < 0 ) return VLC_EGENERIC;
850 stream_Read( p_demux->s, NULL, i_skip );
853 /* TODO read index if possible */
858 static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
860 demux_sys_t *p_sys = p_demux->p_sys;
865 msg_Dbg( p_demux, " - specific data len=%d", i_len );
866 if( stream_Peek(p_demux->s, &p_peek, i_len) < i_len ) return VLC_EGENERIC;
868 if( !strncmp( (char *)&p_peek[4], "VIDO", 4 ) )
870 es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( p_peek[8], p_peek[9],
871 p_peek[10], p_peek[11] ) );
872 fmt.video.i_width = GetWBE( &p_peek[12] );
873 fmt.video.i_height= GetWBE( &p_peek[14] );
876 fmt.p_extra = malloc( 8 );
877 ((uint32_t*)fmt.p_extra)[0] = GetDWBE( &p_peek[26] );
878 ((uint32_t*)fmt.p_extra)[1] = GetDWBE( &p_peek[30] );
880 msg_Dbg( p_demux, " - video 0x%08x 0x%08x",
881 ((uint32_t*)fmt.p_extra)[0], ((uint32_t*)fmt.p_extra)[1] );
883 if( GetDWBE( &p_peek[30] ) == 0x10003000 ||
884 GetDWBE( &p_peek[30] ) == 0x10003001 )
886 fmt.i_codec = VLC_FOURCC( 'R','V','1','3' );
888 else if( GetDWBE( &p_peek[30] ) == 0x20001000 ||
889 GetDWBE( &p_peek[30] ) == 0x20100001 ||
890 GetDWBE( &p_peek[30] ) == 0x20200002 )
892 fmt.i_codec = VLC_FOURCC( 'R','V','2','0' );
894 else if( GetDWBE( &p_peek[30] ) == 0x30202002 )
896 fmt.i_codec = VLC_FOURCC( 'R','V','3','0' );
898 else if( GetDWBE( &p_peek[30] ) == 0x40000000 )
900 fmt.i_codec = VLC_FOURCC( 'R','V','4','0' );
903 msg_Dbg( p_demux, " - video %4.4s %dx%d",
904 (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height );
906 tk = malloc( sizeof( real_track_t ) );
911 tk->p_es = es_out_Add( p_demux->out, &fmt );
913 TAB_APPEND( p_sys->i_track, p_sys->track, tk );
915 else if( !strncmp( (char *)p_peek, ".ra\xfd", 4 ) )
917 int i_version = GetWBE( &p_peek[4] );
918 int i_header_size, i_flavor, i_coded_frame_size, i_subpacket_h;
919 int i_frame_size, i_subpacket_size;
921 msg_Dbg( p_demux, " - audio version=%d", i_version );
924 es_format_Init( &fmt, AUDIO_ES, 0 );
928 msg_Dbg( p_demux, " - audio version 3 is not supported!" );
932 p_peek += 2; /* 00 00 */
933 p_peek += 4; /* .ra4 or .ra5 */
934 p_peek += 4; /* ?? */
935 p_peek += 2; /* version (4 or 5) */
936 i_header_size = GetDWBE( p_peek ); p_peek += 4; /* header size */
937 i_flavor = GetWBE( p_peek ); p_peek += 2; /* codec flavor */
938 i_coded_frame_size = GetDWBE( p_peek ); p_peek += 4;
939 p_peek += 4; /* ?? */
940 p_peek += 4; /* ?? */
941 p_peek += 4; /* ?? */
942 i_subpacket_h = GetWBE( p_peek ); p_peek += 2;
943 i_frame_size = GetWBE( p_peek ); p_peek += 2;
944 i_subpacket_size = GetWBE( p_peek ); p_peek += 2;
945 p_peek += 2; /* ?? */
947 if( i_version == 5 ) p_peek += 6; /* 0, srate, 0 */
949 fmt.audio.i_rate = GetWBE( p_peek ); p_peek += 2;
950 p_peek += 2; /* ?? */
951 fmt.audio.i_bitspersample = GetWBE( p_peek ); p_peek += 2;
952 fmt.audio.i_channels = GetWBE( p_peek ); p_peek += 2;
953 fmt.audio.i_blockalign = i_frame_size;
957 p_peek += 4; /* genr */
958 memcpy( (char *)&fmt.i_codec, p_peek, 4 ); p_peek += 4;
962 p_peek += p_peek[0] + 1; /* descr 1 */
963 memcpy( (char *)&fmt.i_codec, p_peek + 1, 4 ); /* descr 2 */
964 p_peek += p_peek[0] + 1;
967 msg_Dbg( p_demux, " - audio codec=%4.4s channels=%d rate=%dHz",
968 (char*)&fmt.i_codec, fmt.audio.i_channels, fmt.audio.i_rate );
970 p_peek += 3; /* ?? */
971 if( i_version == 5 ) p_peek++;
973 switch( fmt.i_codec )
975 case VLC_FOURCC( 'd', 'n', 'e', 't' ):
976 fmt.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
979 case VLC_FOURCC( 'r', 'a', 'a', 'c' ):
980 case VLC_FOURCC( 'r', 'a', 'c', 'p' ):
981 fmt.i_extra = GetDWBE( p_peek ); p_peek += 4;
982 if( fmt.i_extra > 0 ) { fmt.i_extra--; p_peek++; }
983 if( fmt.i_extra > 0 )
985 fmt.p_extra = malloc( fmt.i_extra );
986 memcpy( fmt.p_extra, p_peek, fmt.i_extra );
989 fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
992 case VLC_FOURCC('c','o','o','k'):
993 fmt.audio.i_blockalign = i_subpacket_size;
994 if( !(fmt.i_extra = GetDWBE( p_peek )) ) break;
995 fmt.p_extra = malloc( fmt.i_extra );
996 memcpy( fmt.p_extra, p_peek + 4, fmt.i_extra );
999 case VLC_FOURCC('2','8','_','8'):
1000 fmt.audio.i_blockalign = i_coded_frame_size;
1004 msg_Dbg( p_demux, " - unknown audio codec=%4.4s",
1005 (char*)&fmt.i_codec );
1009 if( fmt.i_codec != 0 )
1013 msg_Dbg( p_demux, " - extra data=%d", fmt.i_extra );
1015 tk = malloc( sizeof( real_track_t ) );
1021 tk->i_subpacket_h = i_subpacket_h;
1022 tk->i_subpacket_size = i_subpacket_size;
1023 tk->i_coded_frame_size = i_coded_frame_size;
1024 tk->i_frame_size = i_frame_size;
1026 tk->i_out_subpacket = 0;
1027 tk->i_subpacket = 0;
1028 tk->i_subpackets = 0;
1029 tk->p_subpackets = NULL;
1030 if( fmt.i_codec == VLC_FOURCC('c','o','o','k') )
1033 i_subpacket_h * i_frame_size / tk->i_subpacket_size;
1035 malloc( tk->i_subpackets * sizeof(block_t *) );
1037 else if( fmt.i_codec == VLC_FOURCC('2','8','_','8') )
1040 i_subpacket_h * i_frame_size / tk->i_coded_frame_size;
1042 malloc( tk->i_subpackets * sizeof(block_t *) );
1045 for( i = 0; i < tk->i_subpackets; i++ ) tk->p_subpackets[i] = NULL;
1047 tk->p_es = es_out_Add( p_demux->out, &fmt );
1049 TAB_APPEND( p_sys->i_track, p_sys->track, tk );