1 /*****************************************************************************
2 * ogg.c : ogg stream demux module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2003 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
8 * Andre Pang <Andre.Pang@csiro.au> (Annodex support)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
29 #include <vlc/input.h>
36 /*****************************************************************************
38 *****************************************************************************/
39 static int Open ( vlc_object_t * );
40 static void Close( vlc_object_t * );
43 set_description( _("Ogg stream demuxer" ) );
44 set_category( CAT_INPUT );
45 set_subcategory( SUBCAT_INPUT_DEMUX );
46 set_capability( "demux2", 50 );
47 set_callbacks( Open, Close );
48 add_shortcut( "ogg" );
52 /*****************************************************************************
53 * Definitions of structures and functions used by this plugins
54 *****************************************************************************/
55 typedef struct logical_stream_s
57 ogg_stream_state os; /* logical stream of packets */
65 /* the header of some logical streams (eg vorbis) contain essential
66 * data for the decoder. We back them up here in case we need to re-feed
67 * them to the decoder. */
73 /* program clock reference (in units of 90kHz) derived from the previous
76 mtime_t i_interpolated_pcr;
77 mtime_t i_previous_pcr;
81 int i_theora_keyframe_granule_shift;
83 /* for Annodex logical bitstreams */
84 int secondary_header_packets;
90 ogg_sync_state oy; /* sync and verify incoming physical bitstream */
92 int i_streams; /* number of logical bitstreams */
93 logical_stream_t **pp_stream; /* pointer to an array of logical streams */
95 /* program clock reference (in units of 90kHz) derived from the pcr of
106 /* OggDS headers for the new header format (used in ogm files) */
107 typedef struct stream_header_video
111 } stream_header_video;
113 typedef struct stream_header_audio
115 ogg_int16_t channels;
116 ogg_int16_t blockalign;
117 ogg_int32_t avgbytespersec;
118 } stream_header_audio;
120 typedef struct stream_header
125 ogg_int32_t size; /* size of the structure */
127 ogg_int64_t time_unit; /* in reference time */
128 ogg_int64_t samples_per_unit;
129 ogg_int32_t default_len; /* in media time */
131 ogg_int32_t buffersize;
132 ogg_int16_t bits_per_sample;
137 stream_header_video video;
139 stream_header_audio audio;
143 #define OGG_BLOCK_SIZE 4096
145 /* Some defines from OggDS */
146 #define PACKET_TYPE_HEADER 0x01
147 #define PACKET_TYPE_BITS 0x07
148 #define PACKET_LEN_BITS01 0xc0
149 #define PACKET_LEN_BITS2 0x02
150 #define PACKET_IS_SYNCPOINT 0x08
152 /*****************************************************************************
154 *****************************************************************************/
155 static int Demux ( demux_t * );
156 static int Control( demux_t *, int, va_list );
158 /* Bitstream manipulation */
159 static int Ogg_ReadPage ( demux_t *, ogg_page * );
160 static void Ogg_UpdatePCR ( logical_stream_t *, ogg_packet * );
161 static void Ogg_DecodePacket ( demux_t *, logical_stream_t *, ogg_packet * );
163 static int Ogg_BeginningOfStream( demux_t *p_demux );
164 static int Ogg_FindLogicalStreams( demux_t *p_demux );
165 static void Ogg_EndOfStream( demux_t *p_demux );
167 /* Logical bitstream headers */
168 static void Ogg_ReadTheoraHeader( logical_stream_t *, ogg_packet * );
169 static void Ogg_ReadVorbisHeader( logical_stream_t *, ogg_packet * );
170 static void Ogg_ReadSpeexHeader( logical_stream_t *, ogg_packet * );
171 static void Ogg_ReadFlacHeader( demux_t *, logical_stream_t *, ogg_packet * );
172 static void Ogg_ReadAnnodexHeader( vlc_object_t *, logical_stream_t *, ogg_packet * );
174 /*****************************************************************************
175 * Open: initializes ogg demux structures
176 *****************************************************************************/
177 static int Open( vlc_object_t * p_this )
179 demux_t *p_demux = (demux_t *)p_this;
184 /* Check if we are dealing with an ogg stream */
185 if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 ) return VLC_EGENERIC;
186 if( strcmp( p_demux->psz_demux, "ogg" ) && memcmp( p_peek, "OggS", 4 ) )
191 /* Set exported functions */
192 p_demux->pf_demux = Demux;
193 p_demux->pf_control = Control;
194 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
196 memset( p_sys, 0, sizeof( demux_sys_t ) );
197 p_sys->i_bitrate = 0;
198 p_sys->pp_stream = NULL;
200 /* Begnning of stream, tell the demux to look for elementary streams. */
203 /* Initialize the Ogg physical bitstream parser */
204 ogg_sync_init( &p_sys->oy );
209 /*****************************************************************************
210 * Close: frees unused data
211 *****************************************************************************/
212 static void Close( vlc_object_t *p_this )
214 demux_t *p_demux = (demux_t *)p_this;
215 demux_sys_t *p_sys = p_demux->p_sys ;
217 /* Cleanup the bitstream parser */
218 ogg_sync_clear( &p_sys->oy );
220 Ogg_EndOfStream( p_demux );
225 /*****************************************************************************
226 * Demux: reads and demuxes data packets
227 *****************************************************************************
228 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
229 *****************************************************************************/
230 static int Demux( demux_t * p_demux )
232 demux_sys_t *p_sys = p_demux->p_sys;
234 ogg_packet oggpacket;
238 if( p_sys->i_eos == p_sys->i_streams )
242 msg_Dbg( p_demux, "end of a group of logical streams" );
243 Ogg_EndOfStream( p_demux );
247 if( Ogg_BeginningOfStream( p_demux ) != VLC_SUCCESS ) return 0;
249 msg_Dbg( p_demux, "beginning of a group of logical streams" );
250 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
254 * Demux an ogg page from the stream
256 if( Ogg_ReadPage( p_demux, &oggpage ) != VLC_SUCCESS )
261 /* Test for End of Stream */
262 if( ogg_page_eos( &oggpage ) ) p_sys->i_eos++;
265 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
267 logical_stream_t *p_stream = p_sys->pp_stream[i_stream];
269 if( ogg_stream_pagein( &p_stream->os, &oggpage ) != 0 )
272 while( ogg_stream_packetout( &p_stream->os, &oggpacket ) > 0 )
274 /* Read info from any secondary header packets, if there are any */
275 if( p_stream->secondary_header_packets > 0 )
277 if( p_stream->fmt.i_codec == VLC_FOURCC('t','h','e','o') &&
278 oggpacket.bytes >= 7 &&
279 ! memcmp( &oggpacket.packet[1], "theora", 6 ) )
281 Ogg_ReadTheoraHeader( p_stream, &oggpacket );
282 p_stream->secondary_header_packets = 0;
284 else if( p_stream->fmt.i_codec == VLC_FOURCC('v','o','r','b') &&
285 oggpacket.bytes >= 7 &&
286 ! memcmp( &oggpacket.packet[1], "vorbis", 6 ) )
288 Ogg_ReadVorbisHeader( p_stream, &oggpacket );
289 p_stream->secondary_header_packets = 0;
291 else if ( p_stream->fmt.i_codec == VLC_FOURCC('c','m','m','l') )
293 p_stream->secondary_header_packets = 0;
297 if( p_stream->b_reinit )
299 /* If synchro is re-initialized we need to drop all the packets
300 * until we find a new dated one. */
301 Ogg_UpdatePCR( p_stream, &oggpacket );
303 if( p_stream->i_pcr >= 0 )
305 p_stream->b_reinit = 0;
309 p_stream->i_interpolated_pcr = -1;
313 /* An Ogg/vorbis packet contains an end date granulepos */
314 if( p_stream->fmt.i_codec == VLC_FOURCC( 'v','o','r','b' ) ||
315 p_stream->fmt.i_codec == VLC_FOURCC( 's','p','x',' ' ) ||
316 p_stream->fmt.i_codec == VLC_FOURCC( 'f','l','a','c' ) )
318 if( ogg_stream_packetout( &p_stream->os, &oggpacket ) > 0 )
320 Ogg_DecodePacket( p_demux, p_stream, &oggpacket );
324 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
331 Ogg_DecodePacket( p_demux, p_stream, &oggpacket );
336 i_stream = 0; p_sys->i_pcr = -1;
337 for( ; i_stream < p_sys->i_streams; i_stream++ )
339 logical_stream_t *p_stream = p_sys->pp_stream[i_stream];
341 if( p_stream->fmt.i_cat == SPU_ES )
343 if( p_stream->i_interpolated_pcr < 0 )
346 if( p_sys->i_pcr < 0 || p_stream->i_interpolated_pcr < p_sys->i_pcr )
347 p_sys->i_pcr = p_stream->i_interpolated_pcr;
350 if( p_sys->i_pcr >= 0 )
352 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_pcr );
359 /*****************************************************************************
361 *****************************************************************************/
362 static int Control( demux_t *p_demux, int i_query, va_list args )
364 demux_sys_t *p_sys = p_demux->p_sys;
371 pi64 = (int64_t*)va_arg( args, int64_t * );
372 *pi64 = p_sys->i_pcr;
378 case DEMUX_SET_POSITION:
379 for( i = 0; i < p_sys->i_streams; i++ )
381 logical_stream_t *p_stream = p_sys->pp_stream[i];
383 /* we'll trash all the data until we find the next pcr */
384 p_stream->b_reinit = 1;
385 p_stream->i_pcr = -1;
386 p_stream->i_interpolated_pcr = -1;
387 ogg_stream_reset( &p_stream->os );
389 ogg_sync_reset( &p_sys->oy );
392 return demux2_vaControlHelper( p_demux->s, 0, -1, p_sys->i_bitrate,
397 /****************************************************************************
398 * Ogg_ReadPage: Read a full Ogg page from the physical bitstream.
399 ****************************************************************************
400 * Returns VLC_SUCCESS if a page has been read. An error might happen if we
401 * are at the end of stream.
402 ****************************************************************************/
403 static int Ogg_ReadPage( demux_t *p_demux, ogg_page *p_oggpage )
405 demux_sys_t *p_ogg = p_demux->p_sys ;
409 while( ogg_sync_pageout( &p_ogg->oy, p_oggpage ) != 1 )
411 p_buffer = ogg_sync_buffer( &p_ogg->oy, OGG_BLOCK_SIZE );
413 i_read = stream_Read( p_demux->s, p_buffer, OGG_BLOCK_SIZE );
417 ogg_sync_wrote( &p_ogg->oy, i_read );
423 /****************************************************************************
424 * Ogg_UpdatePCR: update the PCR (90kHz program clock reference) for the
426 ****************************************************************************/
427 static void Ogg_UpdatePCR( logical_stream_t *p_stream,
428 ogg_packet *p_oggpacket )
430 /* Convert the granulepos into a pcr */
431 if( p_oggpacket->granulepos >= 0 )
433 if( p_stream->fmt.i_codec != VLC_FOURCC( 't','h','e','o' ) )
435 p_stream->i_pcr = p_oggpacket->granulepos * I64C(1000000)
440 ogg_int64_t iframe = p_oggpacket->granulepos >>
441 p_stream->i_theora_keyframe_granule_shift;
442 ogg_int64_t pframe = p_oggpacket->granulepos -
443 ( iframe << p_stream->i_theora_keyframe_granule_shift );
445 p_stream->i_pcr = ( iframe + pframe ) * I64C(1000000)
449 p_stream->i_interpolated_pcr = p_stream->i_pcr;
453 p_stream->i_pcr = -1;
455 /* no granulepos available, try to interpolate the pcr.
456 * If we can't then don't touch the old value. */
457 if( p_stream->fmt.i_cat == VIDEO_ES )
458 /* 1 frame per packet */
459 p_stream->i_interpolated_pcr += (I64C(1000000) / p_stream->f_rate);
460 else if( p_stream->fmt.i_bitrate )
461 p_stream->i_interpolated_pcr +=
462 ( p_oggpacket->bytes * I64C(1000000) /
463 p_stream->fmt.i_bitrate / 8 );
467 /****************************************************************************
468 * Ogg_DecodePacket: Decode an Ogg packet.
469 ****************************************************************************/
470 static void Ogg_DecodePacket( demux_t *p_demux,
471 logical_stream_t *p_stream,
472 ogg_packet *p_oggpacket )
475 vlc_bool_t b_selected;
476 int i_header_len = 0;
477 mtime_t i_pts = -1, i_interpolated_pts;
480 if( !p_oggpacket->bytes )
482 msg_Dbg( p_demux, "discarding 0 sized packet" );
486 if( p_oggpacket->bytes >= 7 &&
487 ! memcmp ( &p_oggpacket->packet[0], "Annodex", 7 ) )
489 /* it's an Annodex packet -- skip it (do nothing) */
492 else if( p_oggpacket->bytes >= 7 &&
493 ! memcmp ( &p_oggpacket->packet[0], "AnxData", 7 ) )
495 /* it's an AnxData packet -- skip it (do nothing) */
499 if( p_stream->fmt.i_codec == VLC_FOURCC( 's','u','b','t' ) &&
500 p_oggpacket->packet[0] & PACKET_TYPE_BITS ) return;
502 /* Check the ES is selected */
503 es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE,
504 p_stream->p_es, &b_selected );
506 if( p_stream->b_force_backup )
509 vlc_bool_t b_store_size = VLC_TRUE;
511 p_stream->i_packets_backup++;
512 switch( p_stream->fmt.i_codec )
514 case VLC_FOURCC( 'v','o','r','b' ):
515 case VLC_FOURCC( 's','p','x',' ' ):
516 case VLC_FOURCC( 't','h','e','o' ):
517 if( p_stream->i_packets_backup == 3 ) p_stream->b_force_backup = 0;
520 case VLC_FOURCC( 'f','l','a','c' ):
521 if( !p_stream->fmt.audio.i_rate && p_stream->i_packets_backup == 2 )
523 Ogg_ReadFlacHeader( p_demux, p_stream, p_oggpacket );
524 p_stream->b_force_backup = 0;
526 else if( p_stream->fmt.audio.i_rate )
528 p_stream->b_force_backup = 0;
529 p_oggpacket->packet += 9; p_oggpacket->bytes -= 9;
531 b_store_size = VLC_FALSE;
535 p_stream->b_force_backup = 0;
539 /* Backup the ogg packet (likely an header packet) */
540 p_stream->p_headers =
541 realloc( p_stream->p_headers, p_stream->i_headers +
542 p_oggpacket->bytes + (b_store_size ? 2 : 0) );
543 p_extra = p_stream->p_headers + p_stream->i_headers;
546 *(p_extra++) = p_oggpacket->bytes >> 8;
547 *(p_extra++) = p_oggpacket->bytes & 0xFF;
549 memcpy( p_extra, p_oggpacket->packet, p_oggpacket->bytes );
550 p_stream->i_headers += p_oggpacket->bytes + (b_store_size ? 2 : 0);
552 if( !p_stream->b_force_backup )
554 /* Last header received, commit changes */
555 p_stream->fmt.i_extra = p_stream->i_headers;
556 p_stream->fmt.p_extra =
557 realloc( p_stream->fmt.p_extra, p_stream->i_headers );
558 memcpy( p_stream->fmt.p_extra, p_stream->p_headers,
559 p_stream->i_headers );
560 es_out_Control( p_demux->out, ES_OUT_SET_FMT,
561 p_stream->p_es, &p_stream->fmt );
564 b_selected = VLC_FALSE; /* Discard the header packet */
567 /* Convert the pcr into a pts */
568 if( p_stream->fmt.i_codec == VLC_FOURCC( 'v','o','r','b' ) ||
569 p_stream->fmt.i_codec == VLC_FOURCC( 's','p','x',' ' ) ||
570 p_stream->fmt.i_codec == VLC_FOURCC( 'f','l','a','c' ) )
572 if( p_stream->i_pcr >= 0 )
574 /* This is for streams where the granulepos of the header packets
575 * doesn't match these of the data packets (eg. ogg web radios). */
576 if( p_stream->i_previous_pcr == 0 &&
577 p_stream->i_pcr > 3 * DEFAULT_PTS_DELAY )
579 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
581 /* Call the pace control */
582 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
586 p_stream->i_previous_pcr = p_stream->i_pcr;
588 /* The granulepos is the end date of the sample */
589 i_pts = p_stream->i_pcr;
593 /* Convert the granulepos into the next pcr */
594 i_interpolated_pts = p_stream->i_interpolated_pcr;
595 Ogg_UpdatePCR( p_stream, p_oggpacket );
597 if( p_stream->i_pcr >= 0 )
599 /* This is for streams where the granulepos of the header packets
600 * doesn't match these of the data packets (eg. ogg web radios). */
601 if( p_stream->i_previous_pcr == 0 &&
602 p_stream->i_pcr > 3 * DEFAULT_PTS_DELAY )
604 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
606 /* Call the pace control */
607 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_stream->i_pcr );
611 if( p_stream->fmt.i_codec != VLC_FOURCC( 'v','o','r','b' ) &&
612 p_stream->fmt.i_codec != VLC_FOURCC( 's','p','x',' ' ) &&
613 p_stream->fmt.i_codec != VLC_FOURCC( 'f','l','a','c' ) &&
614 p_stream->i_pcr >= 0 )
616 p_stream->i_previous_pcr = p_stream->i_pcr;
618 /* The granulepos is the start date of the sample */
619 i_pts = p_stream->i_pcr;
624 /* This stream isn't currently selected so we don't need to decode it,
625 * but we did need to store its pcr as it might be selected later on */
629 if( !( p_block = block_New( p_demux, p_oggpacket->bytes ) ) ) return;
632 if( i_pts == 0 ) i_pts = 1;
633 else if( i_pts == -1 && i_interpolated_pts == 0 ) i_pts = 1;
634 else if( i_pts == -1 ) i_pts = 0;
636 if( p_stream->fmt.i_cat == AUDIO_ES )
637 p_block->i_dts = p_block->i_pts = i_pts;
638 else if( p_stream->fmt.i_cat == SPU_ES )
640 p_block->i_dts = p_block->i_pts = i_pts;
641 p_block->i_length = 0;
643 else if( p_stream->fmt.i_codec == VLC_FOURCC( 't','h','e','o' ) )
644 p_block->i_dts = p_block->i_pts = i_pts;
647 p_block->i_dts = i_pts;
651 if( p_stream->fmt.i_codec != VLC_FOURCC( 'v','o','r','b' ) &&
652 p_stream->fmt.i_codec != VLC_FOURCC( 's','p','x',' ' ) &&
653 p_stream->fmt.i_codec != VLC_FOURCC( 'f','l','a','c' ) &&
654 p_stream->fmt.i_codec != VLC_FOURCC( 't','a','r','k' ) &&
655 p_stream->fmt.i_codec != VLC_FOURCC( 't','h','e','o' ) &&
656 p_stream->fmt.i_codec != VLC_FOURCC( 'c','m','m','l' ) )
658 /* We remove the header from the packet */
659 i_header_len = (*p_oggpacket->packet & PACKET_LEN_BITS01) >> 6;
660 i_header_len |= (*p_oggpacket->packet & PACKET_LEN_BITS2) << 1;
662 if( p_stream->fmt.i_codec == VLC_FOURCC( 's','u','b','t' ))
664 /* But with subtitles we need to retrieve the duration first */
667 if( i_header_len > 0 && p_oggpacket->bytes >= i_header_len + 1 )
669 for( i = 0, lenbytes = 0; i < i_header_len; i++ )
671 lenbytes = lenbytes << 8;
672 lenbytes += *(p_oggpacket->packet + i_header_len - i);
675 if( p_oggpacket->bytes - 1 - i_header_len > 2 ||
676 ( p_oggpacket->packet[i_header_len + 1] != ' ' &&
677 p_oggpacket->packet[i_header_len + 1] != 0 &&
678 p_oggpacket->packet[i_header_len + 1] != '\n' &&
679 p_oggpacket->packet[i_header_len + 1] != '\r' ) )
681 p_block->i_length = (mtime_t)lenbytes * 1000;
686 p_block->i_buffer -= i_header_len;
689 if( p_stream->fmt.i_codec == VLC_FOURCC( 't','a','r','k' ) )
691 /* FIXME: the biggest hack I've ever done */
692 msg_Warn( p_demux, "tarkin pts: "I64Fd", granule: "I64Fd,
693 p_block->i_pts, p_block->i_dts );
697 memcpy( p_block->p_buffer, p_oggpacket->packet + i_header_len,
698 p_oggpacket->bytes - i_header_len );
700 es_out_Send( p_demux->out, p_stream->p_es, p_block );
703 /****************************************************************************
704 * Ogg_FindLogicalStreams: Find the logical streams embedded in the physical
705 * stream and fill p_ogg.
706 *****************************************************************************
707 * The initial page of a logical stream is marked as a 'bos' page.
708 * Furthermore, the Ogg specification mandates that grouped bitstreams begin
709 * together and all of the initial pages must appear before any data pages.
711 * On success this function returns VLC_SUCCESS.
712 ****************************************************************************/
713 static int Ogg_FindLogicalStreams( demux_t *p_demux )
715 demux_sys_t *p_ogg = p_demux->p_sys ;
716 ogg_packet oggpacket;
720 #define p_stream p_ogg->pp_stream[p_ogg->i_streams - 1]
722 while( Ogg_ReadPage( p_demux, &oggpage ) == VLC_SUCCESS )
724 if( ogg_page_bos( &oggpage ) )
727 /* All is wonderful in our fine fine little world.
728 * We found the beginning of our first logical stream. */
729 while( ogg_page_bos( &oggpage ) )
733 realloc( p_ogg->pp_stream, p_ogg->i_streams *
734 sizeof(logical_stream_t *) );
736 p_stream = malloc( sizeof(logical_stream_t) );
737 memset( p_stream, 0, sizeof(logical_stream_t) );
738 p_stream->p_headers = 0;
739 p_stream->secondary_header_packets = 0;
741 es_format_Init( &p_stream->fmt, 0, 0 );
743 /* Setup the logical stream */
744 p_stream->i_serial_no = ogg_page_serialno( &oggpage );
745 ogg_stream_init( &p_stream->os, p_stream->i_serial_no );
747 /* Extract the initial header from the first page and verify
748 * the codec type of tis Ogg bitstream */
749 if( ogg_stream_pagein( &p_stream->os, &oggpage ) < 0 )
751 /* error. stream version mismatch perhaps */
752 msg_Err( p_demux, "error reading first page of "
753 "Ogg bitstream data" );
757 /* FIXME: check return value */
758 ogg_stream_packetpeek( &p_stream->os, &oggpacket );
760 /* Check for Vorbis header */
761 if( oggpacket.bytes >= 7 &&
762 ! memcmp( &oggpacket.packet[1], "vorbis", 6 ) )
764 Ogg_ReadVorbisHeader( p_stream, &oggpacket );
765 msg_Dbg( p_demux, "found vorbis header" );
767 /* Check for Speex header */
768 else if( oggpacket.bytes >= 7 &&
769 ! memcmp( &oggpacket.packet[0], "Speex", 5 ) )
771 Ogg_ReadSpeexHeader( p_stream, &oggpacket );
772 msg_Dbg( p_demux, "found speex header, channels: %i, "
773 "rate: %i, bitrate: %i",
774 p_stream->fmt.audio.i_channels,
775 (int)p_stream->f_rate, p_stream->fmt.i_bitrate );
777 /* Check for Flac header (< version 1.1.1) */
778 else if( oggpacket.bytes >= 4 &&
779 ! memcmp( &oggpacket.packet[0], "fLaC", 4 ) )
781 msg_Dbg( p_demux, "found FLAC header" );
783 /* Grrrr!!!! Did they really have to put all the
784 * important info in the second header packet!!!
785 * (STREAMINFO metadata is in the following packet) */
786 p_stream->b_force_backup = 1;
788 p_stream->fmt.i_cat = AUDIO_ES;
789 p_stream->fmt.i_codec = VLC_FOURCC( 'f','l','a','c' );
791 /* Check for Flac header (>= version 1.1.1) */
792 else if( oggpacket.bytes >= 13 && oggpacket.packet[0] ==0x7F &&
793 ! memcmp( &oggpacket.packet[1], "FLAC", 4 ) &&
794 ! memcmp( &oggpacket.packet[9], "fLaC", 4 ) )
796 int i_packets = ((int)oggpacket.packet[7]) << 8 |
798 msg_Dbg( p_demux, "found FLAC header version %i.%i "
799 "(%i header packets)",
800 oggpacket.packet[5], oggpacket.packet[6],
803 p_stream->b_force_backup = 1;
805 p_stream->fmt.i_cat = AUDIO_ES;
806 p_stream->fmt.i_codec = VLC_FOURCC( 'f','l','a','c' );
807 oggpacket.packet += 13; oggpacket.bytes -= 13;
808 Ogg_ReadFlacHeader( p_demux, p_stream, &oggpacket );
810 /* Check for Theora header */
811 else if( oggpacket.bytes >= 7 &&
812 ! memcmp( &oggpacket.packet[1], "theora", 6 ) )
814 Ogg_ReadTheoraHeader( p_stream, &oggpacket );
817 "found theora header, bitrate: %i, rate: %f",
818 p_stream->fmt.i_bitrate, p_stream->f_rate );
820 /* Check for Tarkin header */
821 else if( oggpacket.bytes >= 7 &&
822 ! memcmp( &oggpacket.packet[1], "tarkin", 6 ) )
826 msg_Dbg( p_demux, "found tarkin header" );
827 p_stream->fmt.i_cat = VIDEO_ES;
828 p_stream->fmt.i_codec = VLC_FOURCC( 't','a','r','k' );
830 /* Cheat and get additionnal info ;) */
831 oggpack_readinit( &opb, oggpacket.packet, oggpacket.bytes);
832 oggpack_adv( &opb, 88 );
833 oggpack_adv( &opb, 104 );
834 p_stream->fmt.i_bitrate = oggpack_read( &opb, 32 );
835 p_stream->f_rate = 2; /* FIXME */
837 "found tarkin header, bitrate: %i, rate: %f",
838 p_stream->fmt.i_bitrate, p_stream->f_rate );
840 /* Check for Annodex header */
841 else if( oggpacket.bytes >= 7 &&
842 ! memcmp( &oggpacket.packet[0], "Annodex", 7 ) )
844 Ogg_ReadAnnodexHeader( VLC_OBJECT(p_demux), p_stream,
846 /* kill annodex track */
850 /* Check for Annodex header */
851 else if( oggpacket.bytes >= 7 &&
852 ! memcmp( &oggpacket.packet[0], "AnxData", 7 ) )
854 Ogg_ReadAnnodexHeader( VLC_OBJECT(p_demux), p_stream,
857 else if( oggpacket.bytes >= 142 &&
858 !memcmp( &oggpacket.packet[1],
859 "Direct Show Samples embedded in Ogg", 35 ))
861 /* Old header type */
863 /* Check for video header (old format) */
864 if( GetDWLE((oggpacket.packet+96)) == 0x05589f80 &&
865 oggpacket.bytes >= 184 )
867 p_stream->fmt.i_cat = VIDEO_ES;
868 p_stream->fmt.i_codec =
869 VLC_FOURCC( oggpacket.packet[68],
870 oggpacket.packet[69],
871 oggpacket.packet[70],
872 oggpacket.packet[71] );
873 msg_Dbg( p_demux, "found video header of type: %.4s",
874 (char *)&p_stream->fmt.i_codec );
876 p_stream->fmt.video.i_frame_rate = 10000000;
877 p_stream->fmt.video.i_frame_rate_base =
878 GetQWLE((oggpacket.packet+164));
879 p_stream->f_rate = 10000000.0 /
880 GetQWLE((oggpacket.packet+164));
881 p_stream->fmt.video.i_bits_per_pixel =
882 GetWLE((oggpacket.packet+182));
883 if( !p_stream->fmt.video.i_bits_per_pixel )
885 p_stream->fmt.video.i_bits_per_pixel = 24;
886 p_stream->fmt.video.i_width =
887 GetDWLE((oggpacket.packet+176));
888 p_stream->fmt.video.i_height =
889 GetDWLE((oggpacket.packet+180));
892 "fps: %f, width:%i; height:%i, bitcount:%i",
894 p_stream->fmt.video.i_width,
895 p_stream->fmt.video.i_height,
896 p_stream->fmt.video.i_bits_per_pixel);
899 /* Check for audio header (old format) */
900 else if( GetDWLE((oggpacket.packet+96)) == 0x05589F81 )
902 unsigned int i_extra_size;
903 unsigned int i_format_tag;
905 p_stream->fmt.i_cat = AUDIO_ES;
907 i_extra_size = GetWLE((oggpacket.packet+140));
910 p_stream->fmt.i_extra = i_extra_size;
911 p_stream->fmt.p_extra = malloc( i_extra_size );
912 memcpy( p_stream->fmt.p_extra,
913 oggpacket.packet + 142, i_extra_size );
916 i_format_tag = GetWLE((oggpacket.packet+124));
917 p_stream->fmt.audio.i_channels =
918 GetWLE((oggpacket.packet+126));
919 p_stream->f_rate = p_stream->fmt.audio.i_rate =
920 GetDWLE((oggpacket.packet+128));
921 p_stream->fmt.i_bitrate =
922 GetDWLE((oggpacket.packet+132)) * 8;
923 p_stream->fmt.audio.i_blockalign =
924 GetWLE((oggpacket.packet+136));
925 p_stream->fmt.audio.i_bitspersample =
926 GetWLE((oggpacket.packet+138));
928 wf_tag_to_fourcc( i_format_tag,
929 &p_stream->fmt.i_codec, 0 );
931 if( p_stream->fmt.i_codec ==
932 VLC_FOURCC('u','n','d','f') )
934 p_stream->fmt.i_codec = VLC_FOURCC( 'm', 's',
935 ( i_format_tag >> 8 ) & 0xff,
936 i_format_tag & 0xff );
939 msg_Dbg( p_demux, "found audio header of type: %.4s",
940 (char *)&p_stream->fmt.i_codec );
941 msg_Dbg( p_demux, "audio:0x%4.4x channels:%d %dHz "
942 "%dbits/sample %dkb/s",
944 p_stream->fmt.audio.i_channels,
945 p_stream->fmt.audio.i_rate,
946 p_stream->fmt.audio.i_bitspersample,
947 p_stream->fmt.i_bitrate / 1024 );
952 msg_Dbg( p_demux, "stream %d has an old header "
953 "but is of an unknown type", p_ogg->i_streams-1 );
958 else if( (*oggpacket.packet & PACKET_TYPE_BITS )
959 == PACKET_TYPE_HEADER &&
960 oggpacket.bytes >= (int)sizeof(stream_header)+1 )
962 stream_header *st = (stream_header *)(oggpacket.packet+1);
964 /* Check for video header (new format) */
965 if( !strncmp( st->streamtype, "video", 5 ) )
967 p_stream->fmt.i_cat = VIDEO_ES;
969 /* We need to get rid of the header packet */
970 ogg_stream_packetout( &p_stream->os, &oggpacket );
972 p_stream->fmt.i_codec =
973 VLC_FOURCC( st->subtype[0], st->subtype[1],
974 st->subtype[2], st->subtype[3] );
975 msg_Dbg( p_demux, "found video header of type: %.4s",
976 (char *)&p_stream->fmt.i_codec );
978 p_stream->fmt.video.i_frame_rate = 10000000;
979 p_stream->fmt.video.i_frame_rate_base =
980 GetQWLE(&st->time_unit);
981 p_stream->f_rate = 10000000.0 /
982 GetQWLE(&st->time_unit);
983 p_stream->fmt.video.i_bits_per_pixel =
984 GetWLE(&st->bits_per_sample);
985 p_stream->fmt.video.i_width =
986 GetDWLE(&st->sh.video.width);
987 p_stream->fmt.video.i_height =
988 GetDWLE(&st->sh.video.height);
991 "fps: %f, width:%i; height:%i, bitcount:%i",
993 p_stream->fmt.video.i_width,
994 p_stream->fmt.video.i_height,
995 p_stream->fmt.video.i_bits_per_pixel );
997 /* Check for audio header (new format) */
998 else if( !strncmp( st->streamtype, "audio", 5 ) )
1003 p_stream->fmt.i_cat = AUDIO_ES;
1005 /* We need to get rid of the header packet */
1006 ogg_stream_packetout( &p_stream->os, &oggpacket );
1008 p_stream->fmt.i_extra = GetQWLE(&st->size) -
1009 sizeof(stream_header);
1010 if( p_stream->fmt.i_extra )
1012 p_stream->fmt.p_extra =
1013 malloc( p_stream->fmt.i_extra );
1014 memcpy( p_stream->fmt.p_extra, st + 1,
1015 p_stream->fmt.i_extra );
1018 memcpy( p_buffer, st->subtype, 4 );
1020 i_format_tag = strtol(p_buffer,NULL,16);
1021 p_stream->fmt.audio.i_channels =
1022 GetWLE(&st->sh.audio.channels);
1023 p_stream->f_rate = p_stream->fmt.audio.i_rate =
1024 GetQWLE(&st->samples_per_unit);
1025 p_stream->fmt.i_bitrate =
1026 GetDWLE(&st->sh.audio.avgbytespersec) * 8;
1027 p_stream->fmt.audio.i_blockalign =
1028 GetWLE(&st->sh.audio.blockalign);
1029 p_stream->fmt.audio.i_bitspersample =
1030 GetWLE(&st->bits_per_sample);
1032 wf_tag_to_fourcc( i_format_tag,
1033 &p_stream->fmt.i_codec, 0 );
1035 if( p_stream->fmt.i_codec ==
1036 VLC_FOURCC('u','n','d','f') )
1038 p_stream->fmt.i_codec = VLC_FOURCC( 'm', 's',
1039 ( i_format_tag >> 8 ) & 0xff,
1040 i_format_tag & 0xff );
1043 msg_Dbg( p_demux, "found audio header of type: %.4s",
1044 (char *)&p_stream->fmt.i_codec );
1045 msg_Dbg( p_demux, "audio:0x%4.4x channels:%d %dHz "
1046 "%dbits/sample %dkb/s",
1048 p_stream->fmt.audio.i_channels,
1049 p_stream->fmt.audio.i_rate,
1050 p_stream->fmt.audio.i_bitspersample,
1051 p_stream->fmt.i_bitrate / 1024 );
1053 /* Check for text (subtitles) header */
1054 else if( !strncmp(st->streamtype, "text", 4) )
1056 /* We need to get rid of the header packet */
1057 ogg_stream_packetout( &p_stream->os, &oggpacket );
1059 msg_Dbg( p_demux, "found text subtitles header" );
1060 p_stream->fmt.i_cat = SPU_ES;
1061 p_stream->fmt.i_codec = VLC_FOURCC('s','u','b','t');
1062 p_stream->f_rate = 1000; /* granulepos is in milisec */
1066 msg_Dbg( p_demux, "stream %d has a header marker "
1067 "but is of an unknown type", p_ogg->i_streams-1 );
1074 msg_Dbg( p_demux, "stream %d is of unknown type",
1075 p_ogg->i_streams-1 );
1080 if( Ogg_ReadPage( p_demux, &oggpage ) != VLC_SUCCESS )
1081 return VLC_EGENERIC;
1084 /* This is the first data page, which means we are now finished
1085 * with the initial pages. We just need to store it in the relevant
1087 for( i_stream = 0; i_stream < p_ogg->i_streams; i_stream++ )
1089 if( ogg_stream_pagein( &p_ogg->pp_stream[i_stream]->os,
1101 return VLC_EGENERIC;
1104 /****************************************************************************
1105 * Ogg_BeginningOfStream: Look for Beginning of Stream ogg pages and add
1106 * Elementary streams.
1107 ****************************************************************************/
1108 static int Ogg_BeginningOfStream( demux_t *p_demux )
1110 demux_sys_t *p_ogg = p_demux->p_sys ;
1113 /* Find the logical streams embedded in the physical stream and
1114 * initialize our p_ogg structure. */
1115 if( Ogg_FindLogicalStreams( p_demux ) != VLC_SUCCESS )
1117 msg_Warn( p_demux, "couldn't find any ogg logical stream" );
1118 return VLC_EGENERIC;
1121 p_ogg->i_bitrate = 0;
1123 for( i_stream = 0 ; i_stream < p_ogg->i_streams; i_stream++ )
1125 #define p_stream p_ogg->pp_stream[i_stream]
1126 p_stream->p_es = es_out_Add( p_demux->out, &p_stream->fmt );
1128 if( p_stream->fmt.i_codec == VLC_FOURCC('c','m','m','l') )
1130 /* Set the CMML stream active */
1131 es_out_Control( p_demux->out, ES_OUT_SET_ES, p_stream->p_es );
1134 p_ogg->i_bitrate += p_stream->fmt.i_bitrate;
1136 p_stream->i_pcr = p_stream->i_previous_pcr =
1137 p_stream->i_interpolated_pcr = -1;
1138 p_stream->b_reinit = 0;
1145 /****************************************************************************
1146 * Ogg_EndOfStream: clean up the ES when an End of Stream is detected.
1147 ****************************************************************************/
1148 static void Ogg_EndOfStream( demux_t *p_demux )
1150 demux_sys_t *p_ogg = p_demux->p_sys ;
1153 #define p_stream p_ogg->pp_stream[i_stream]
1154 for( i_stream = 0 ; i_stream < p_ogg->i_streams; i_stream++ )
1156 if( p_stream->p_es )
1157 es_out_Del( p_demux->out, p_stream->p_es );
1159 p_ogg->i_bitrate -= p_stream->fmt.i_bitrate;
1161 ogg_stream_clear( &p_ogg->pp_stream[i_stream]->os );
1162 if( p_ogg->pp_stream[i_stream]->p_headers)
1163 free( p_ogg->pp_stream[i_stream]->p_headers );
1165 es_format_Clean( &p_stream->fmt );
1167 free( p_ogg->pp_stream[i_stream] );
1172 if( p_ogg->pp_stream ) free( p_ogg->pp_stream );
1173 p_ogg->pp_stream = NULL;
1174 p_ogg->i_streams = 0;
1177 static void Ogg_ReadTheoraHeader( logical_stream_t *p_stream,
1178 ogg_packet *p_oggpacket )
1181 int i_fps_numerator;
1182 int i_fps_denominator;
1183 int i_keyframe_frequency_force;
1185 p_stream->fmt.i_cat = VIDEO_ES;
1186 p_stream->fmt.i_codec = VLC_FOURCC( 't','h','e','o' );
1188 /* Signal that we want to keep a backup of the theora
1189 * stream headers. They will be used when switching between
1191 p_stream->b_force_backup = 1;
1193 /* Cheat and get additionnal info ;) */
1194 bs_init( &bitstream, p_oggpacket->packet, p_oggpacket->bytes );
1195 bs_skip( &bitstream, 56 );
1196 bs_read( &bitstream, 8 ); /* major version num */
1197 bs_read( &bitstream, 8 ); /* minor version num */
1198 bs_read( &bitstream, 8 ); /* subminor version num */
1199 bs_read( &bitstream, 16 ) /*<< 4*/; /* width */
1200 bs_read( &bitstream, 16 ) /*<< 4*/; /* height */
1201 bs_read( &bitstream, 24 ); /* frame width */
1202 bs_read( &bitstream, 24 ); /* frame height */
1203 bs_read( &bitstream, 8 ); /* x offset */
1204 bs_read( &bitstream, 8 ); /* y offset */
1206 i_fps_numerator = bs_read( &bitstream, 32 );
1207 i_fps_denominator = bs_read( &bitstream, 32 );
1208 bs_read( &bitstream, 24 ); /* aspect_numerator */
1209 bs_read( &bitstream, 24 ); /* aspect_denominator */
1211 p_stream->fmt.video.i_frame_rate = i_fps_numerator;
1212 p_stream->fmt.video.i_frame_rate_base = i_fps_denominator;
1214 bs_read( &bitstream, 8 ); /* colorspace */
1215 p_stream->fmt.i_bitrate = bs_read( &bitstream, 24 );
1216 bs_read( &bitstream, 6 ); /* quality */
1218 i_keyframe_frequency_force = 1 << bs_read( &bitstream, 5 );
1220 /* granule_shift = i_log( frequency_force -1 ) */
1221 p_stream->i_theora_keyframe_granule_shift = 0;
1222 i_keyframe_frequency_force--;
1223 while( i_keyframe_frequency_force )
1225 p_stream->i_theora_keyframe_granule_shift++;
1226 i_keyframe_frequency_force >>= 1;
1229 p_stream->f_rate = ((float)i_fps_numerator) / i_fps_denominator;
1232 static void Ogg_ReadVorbisHeader( logical_stream_t *p_stream,
1233 ogg_packet *p_oggpacket )
1237 p_stream->fmt.i_cat = AUDIO_ES;
1238 p_stream->fmt.i_codec = VLC_FOURCC( 'v','o','r','b' );
1240 /* Signal that we want to keep a backup of the vorbis
1241 * stream headers. They will be used when switching between
1243 p_stream->b_force_backup = 1;
1245 /* Cheat and get additionnal info ;) */
1246 oggpack_readinit( &opb, p_oggpacket->packet, p_oggpacket->bytes);
1247 oggpack_adv( &opb, 88 );
1248 p_stream->fmt.audio.i_channels = oggpack_read( &opb, 8 );
1249 p_stream->f_rate = p_stream->fmt.audio.i_rate =
1250 oggpack_read( &opb, 32 );
1251 oggpack_adv( &opb, 32 );
1252 p_stream->fmt.i_bitrate = oggpack_read( &opb, 32 );
1255 static void Ogg_ReadSpeexHeader( logical_stream_t *p_stream,
1256 ogg_packet *p_oggpacket )
1260 p_stream->fmt.i_cat = AUDIO_ES;
1261 p_stream->fmt.i_codec = VLC_FOURCC( 's','p','x',' ' );
1263 /* Signal that we want to keep a backup of the speex
1264 * stream headers. They will be used when switching between
1266 p_stream->b_force_backup = 1;
1268 /* Cheat and get additionnal info ;) */
1269 oggpack_readinit( &opb, p_oggpacket->packet, p_oggpacket->bytes);
1270 oggpack_adv( &opb, 224 );
1271 oggpack_adv( &opb, 32 ); /* speex_version_id */
1272 oggpack_adv( &opb, 32 ); /* header_size */
1273 p_stream->f_rate = p_stream->fmt.audio.i_rate = oggpack_read( &opb, 32 );
1274 oggpack_adv( &opb, 32 ); /* mode */
1275 oggpack_adv( &opb, 32 ); /* mode_bitstream_version */
1276 p_stream->fmt.audio.i_channels = oggpack_read( &opb, 32 );
1277 p_stream->fmt.i_bitrate = oggpack_read( &opb, 32 );
1280 static void Ogg_ReadFlacHeader( demux_t *p_demux, logical_stream_t *p_stream,
1281 ogg_packet *p_oggpacket )
1283 /* Parse the STREAMINFO metadata */
1286 bs_init( &s, p_oggpacket->packet, p_oggpacket->bytes );
1289 if( bs_read( &s, 7 ) == 0 )
1291 if( bs_read( &s, 24 ) >= 34 /*size STREAMINFO*/ )
1294 p_stream->f_rate = p_stream->fmt.audio.i_rate = bs_read( &s, 20 );
1295 p_stream->fmt.audio.i_channels = bs_read( &s, 3 ) + 1;
1297 msg_Dbg( p_demux, "FLAC header, channels: %i, rate: %i",
1298 p_stream->fmt.audio.i_channels, (int)p_stream->f_rate );
1300 else msg_Dbg( p_demux, "FLAC STREAMINFO metadata too short" );
1302 /* Fake this as the last metadata block */
1303 *((uint8_t*)p_oggpacket->packet) |= 0x80;
1307 /* This ain't a STREAMINFO metadata */
1308 msg_Dbg( p_demux, "Invalid FLAC STREAMINFO metadata" );
1312 static void Ogg_ReadAnnodexHeader( vlc_object_t *p_this,
1313 logical_stream_t *p_stream,
1314 ogg_packet *p_oggpacket )
1316 if( ! memcmp( &p_oggpacket->packet[0], "Annodex", 7 ) )
1320 uint16_t major_version;
1321 uint16_t minor_version;
1322 uint64_t timebase_numerator;
1323 uint64_t timebase_denominator;
1325 Ogg_ReadTheoraHeader( p_stream, p_oggpacket );
1327 oggpack_readinit( &opb, p_oggpacket->packet, p_oggpacket->bytes);
1328 oggpack_adv( &opb, 8*8 ); /* "Annodex\0" header */
1329 major_version = oggpack_read( &opb, 2*8 ); /* major version */
1330 minor_version = oggpack_read( &opb, 2*8 ); /* minor version */
1331 timebase_numerator = GetQWLE( &p_oggpacket->packet[16] );
1332 timebase_denominator = GetQWLE( &p_oggpacket->packet[24] );
1334 else if( ! memcmp( &p_oggpacket->packet[0], "AnxData", 7 ) )
1336 uint64_t granule_rate_numerator;
1337 uint64_t granule_rate_denominator;
1338 char content_type_string[1024];
1340 /* Read in Annodex header fields */
1342 granule_rate_numerator = GetQWLE( &p_oggpacket->packet[8] );
1343 granule_rate_denominator = GetQWLE( &p_oggpacket->packet[16] );
1344 p_stream->secondary_header_packets =
1345 GetDWLE( &p_oggpacket->packet[24] );
1347 /* we are guaranteed that the first header field will be
1348 * the content-type (by the Annodex standard) */
1349 if( !strncasecmp( &p_oggpacket->packet[28], "Content-Type: ", 14 ) )
1351 sscanf( &p_oggpacket->packet[42], "%1024s\r\n",
1352 content_type_string );
1355 msg_Dbg( p_this, "AnxData packet info: "I64Fd" / "I64Fd", %d, ``%s''",
1356 granule_rate_numerator, granule_rate_denominator,
1357 p_stream->secondary_header_packets, content_type_string );
1359 p_stream->f_rate = (float) granule_rate_numerator /
1360 (float) granule_rate_denominator;
1362 /* What type of file do we have?
1363 * strcmp is safe to use here because we've extracted
1364 * content_type_string from the stream manually */
1365 if( !strncmp(content_type_string, "audio/x-wav", 11) )
1367 /* n.b. WAVs are unsupported right now */
1368 p_stream->fmt.i_cat = UNKNOWN_ES;
1370 else if( !strncmp(content_type_string, "audio/x-vorbis", 14) )
1372 p_stream->fmt.i_cat = AUDIO_ES;
1373 p_stream->fmt.i_codec = VLC_FOURCC( 'v','o','r','b' );
1375 p_stream->b_force_backup = 1;
1377 else if( !strncmp(content_type_string, "audio/x-speex", 14) )
1379 p_stream->fmt.i_cat = AUDIO_ES;
1380 p_stream->fmt.i_codec = VLC_FOURCC( 's','p','x',' ' );
1382 p_stream->b_force_backup = 1;
1384 else if( !strncmp(content_type_string, "video/x-theora", 14) )
1386 p_stream->fmt.i_cat = VIDEO_ES;
1387 p_stream->fmt.i_codec = VLC_FOURCC( 't','h','e','o' );
1389 p_stream->b_force_backup = 1;
1391 else if( !strncmp(content_type_string, "video/x-xvid", 14) )
1393 p_stream->fmt.i_cat = VIDEO_ES;
1394 p_stream->fmt.i_codec = VLC_FOURCC( 'x','v','i','d' );
1396 p_stream->b_force_backup = 1;
1398 else if( !strncmp(content_type_string, "video/mpeg", 14) )
1400 /* n.b. MPEG streams are unsupported right now */
1401 p_stream->fmt.i_cat = VIDEO_ES;
1402 p_stream->fmt.i_codec = VLC_FOURCC( 'm','p','g','v' );
1404 else if( !strncmp(content_type_string, "text/x-cmml", 11) )
1406 ogg_stream_packetout( &p_stream->os, p_oggpacket );
1407 p_stream->fmt.i_cat = SPU_ES;
1408 p_stream->fmt.i_codec = VLC_FOURCC( 'c','m','m','l' );