1 /*****************************************************************************
2 * ogg.c : ogg stream demux module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2003 VideoLAN
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_capability( "demux", 50 );
45 set_callbacks( Open, Close );
46 add_shortcut( "ogg" );
50 /*****************************************************************************
51 * Definitions of structures and functions used by this plugins
52 *****************************************************************************/
53 typedef struct logical_stream_s
55 ogg_stream_state os; /* logical stream of packets */
64 /* the header of some logical streams (eg vorbis) contain essential
65 * data for the decoder. We back them up here in case we need to re-feed
66 * them to the decoder. */
69 ogg_packet *p_packets_backup;
71 /* program clock reference (in units of 90kHz) derived from the previous
74 mtime_t i_interpolated_pcr;
75 mtime_t i_previous_pcr;
79 int i_theora_keyframe_granule_shift;
81 /* for Annodex logical bitstreams */
82 int secondary_header_packets;
88 ogg_sync_state oy; /* sync and verify incoming physical bitstream */
90 int i_streams; /* number of logical bitstreams */
91 logical_stream_t **pp_stream; /* pointer to an array of logical streams */
93 /* program clock reference (in units of 90kHz) derived from the pcr of
101 /* OggDS headers for the new header format (used in ogm files) */
102 typedef struct stream_header_video
106 } stream_header_video;
108 typedef struct stream_header_audio
110 ogg_int16_t channels;
111 ogg_int16_t blockalign;
112 ogg_int32_t avgbytespersec;
113 } stream_header_audio;
115 typedef struct stream_header
120 ogg_int32_t size; /* size of the structure */
122 ogg_int64_t time_unit; /* in reference time */
123 ogg_int64_t samples_per_unit;
124 ogg_int32_t default_len; /* in media time */
126 ogg_int32_t buffersize;
127 ogg_int16_t bits_per_sample;
132 stream_header_video video;
134 stream_header_audio audio;
138 #define OGG_BLOCK_SIZE 4096
140 /* Some defines from OggDS */
141 #define PACKET_TYPE_HEADER 0x01
142 #define PACKET_TYPE_BITS 0x07
143 #define PACKET_LEN_BITS01 0xc0
144 #define PACKET_LEN_BITS2 0x02
145 #define PACKET_IS_SYNCPOINT 0x08
147 /*****************************************************************************
149 *****************************************************************************/
150 static int Demux ( input_thread_t * );
151 static int Control( input_thread_t *, int, va_list );
153 /* Bitstream manipulation */
154 static int Ogg_ReadPage ( input_thread_t *, ogg_page * );
155 static void Ogg_UpdatePCR ( logical_stream_t *, ogg_packet * );
156 static void Ogg_DecodePacket ( input_thread_t *, logical_stream_t *, ogg_packet * );
158 static int Ogg_BeginningOfStream( input_thread_t *p_input );
159 static int Ogg_FindLogicalStreams( input_thread_t *p_input );
160 static void Ogg_EndOfStream( input_thread_t *p_input );
162 /* Logical bitstream headers */
163 static void Ogg_ReadTheoraHeader( logical_stream_t *p_stream,
164 ogg_packet *p_oggpacket );
165 static void Ogg_ReadVorbisHeader( logical_stream_t *p_stream,
166 ogg_packet *p_oggpacket );
167 static void Ogg_ReadAnnodexHeader( vlc_object_t *, logical_stream_t *p_stream,
168 ogg_packet *p_oggpacket );
170 /*****************************************************************************
171 * Open: initializes ogg demux structures
172 *****************************************************************************/
173 static int Open( vlc_object_t * p_this )
175 input_thread_t *p_input = (input_thread_t *)p_this;
180 /* Check if we are dealing with an ogg stream */
181 if( stream_Peek( p_input->s, &p_peek, 4 ) < 4 )
183 msg_Err( p_input, "cannot peek" );
186 if( strcmp( p_input->psz_demux, "ogg" ) && strncmp( p_peek, "OggS", 4 ) )
188 msg_Warn( p_input, "ogg module discarded (invalid header)" );
192 /* Create one program */
193 vlc_mutex_lock( &p_input->stream.stream_lock );
194 if( input_InitStream( p_input, 0 ) == -1)
196 vlc_mutex_unlock( &p_input->stream.stream_lock );
197 msg_Err( p_input, "cannot init stream" );
200 vlc_mutex_unlock( &p_input->stream.stream_lock );
202 /* Set exported functions */
203 p_input->pf_demux = Demux;
204 p_input->pf_demux_control = Control;
205 p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) );
207 memset( p_sys, 0, sizeof( demux_sys_t ) );
208 p_sys->pp_stream = NULL;
210 /* Begnning of stream, tell the demux to look for elementary streams. */
213 /* Initialize the Ogg physical bitstream parser */
214 ogg_sync_init( &p_sys->oy );
219 /*****************************************************************************
220 * Close: frees unused data
221 *****************************************************************************/
222 static void Close( vlc_object_t *p_this )
224 input_thread_t *p_input = (input_thread_t *)p_this;
225 demux_sys_t *p_sys = p_input->p_demux_data ;
227 /* Cleanup the bitstream parser */
228 ogg_sync_clear( &p_sys->oy );
230 Ogg_EndOfStream( p_input );
235 /*****************************************************************************
236 * Demux: reads and demuxes data packets
237 *****************************************************************************
238 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
239 *****************************************************************************/
240 static int Demux( input_thread_t * p_input )
242 demux_sys_t *p_sys = p_input->p_demux_data;
244 ogg_packet oggpacket;
248 if( p_sys->i_eos == p_sys->i_streams )
252 msg_Dbg( p_input, "end of a group of logical streams" );
253 Ogg_EndOfStream( p_input );
256 if( Ogg_BeginningOfStream( p_input ) != VLC_SUCCESS ) return 0;
259 msg_Dbg( p_input, "beginning of a group of logical streams" );
260 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
264 * Demux an ogg page from the stream
266 if( Ogg_ReadPage( p_input, &oggpage ) != VLC_SUCCESS )
271 /* Test for End of Stream */
272 if( ogg_page_eos( &oggpage ) ) p_sys->i_eos++;
275 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
277 logical_stream_t *p_stream = p_sys->pp_stream[i_stream];
279 if( ogg_stream_pagein( &p_stream->os, &oggpage ) != 0 )
282 while( ogg_stream_packetout( &p_stream->os, &oggpacket ) > 0 )
284 /* Read info from any secondary header packets, if there are any */
285 if( p_stream->secondary_header_packets > 0 )
287 if( p_stream->fmt.i_codec == VLC_FOURCC( 't','h','e','o' ) &&
288 oggpacket.bytes >= 7 &&
289 ! strncmp( &oggpacket.packet[1], "theora", 6 ) )
291 Ogg_ReadTheoraHeader( p_stream, &oggpacket );
292 p_stream->secondary_header_packets = 0;
294 else if( p_stream->fmt.i_codec == VLC_FOURCC( 'v','o','r','b' ) &&
295 oggpacket.bytes >= 7 &&
296 ! strncmp( &oggpacket.packet[1], "vorbis", 6 ) )
298 Ogg_ReadVorbisHeader( p_stream, &oggpacket );
299 p_stream->secondary_header_packets = 0;
301 else if ( p_stream->fmt.i_codec == VLC_FOURCC( 'c','m','m','l' ) )
303 p_stream->secondary_header_packets = 0;
306 p_stream->secondary_header_packets--;
309 if( p_stream->b_reinit )
311 /* If synchro is re-initialized we need to drop all the packets
312 * until we find a new dated one. */
313 Ogg_UpdatePCR( p_stream, &oggpacket );
315 if( p_stream->i_pcr >= 0 )
317 p_stream->b_reinit = 0;
321 p_stream->i_interpolated_pcr = -1;
325 /* An Ogg/vorbis packet contains an end date granulepos */
326 if( p_stream->fmt.i_codec == VLC_FOURCC( 'v','o','r','b' ) ||
327 p_stream->fmt.i_codec == VLC_FOURCC( 's','p','x',' ' ) ||
328 p_stream->fmt.i_codec == VLC_FOURCC( 'f','l','a','c' ) )
330 if( ogg_stream_packetout( &p_stream->os, &oggpacket ) > 0 )
332 Ogg_DecodePacket( p_input, p_stream, &oggpacket );
336 es_out_Control( p_input->p_es_out, ES_OUT_SET_PCR, p_stream->i_pcr );
342 Ogg_DecodePacket( p_input, p_stream, &oggpacket );
347 i_stream = 0; p_sys->i_pcr = -1;
348 for( ; i_stream < p_sys->i_streams; i_stream++ )
350 logical_stream_t *p_stream = p_sys->pp_stream[i_stream];
352 if( p_stream->fmt.i_cat == SPU_ES )
354 if( p_stream->i_interpolated_pcr < 0 )
357 if( p_sys->i_pcr < 0 || p_stream->i_interpolated_pcr < p_sys->i_pcr )
358 p_sys->i_pcr = p_stream->i_interpolated_pcr;
361 if( p_sys->i_pcr >= 0 )
363 es_out_Control( p_input->p_es_out, ES_OUT_SET_PCR, p_sys->i_pcr );
370 /*****************************************************************************
372 *****************************************************************************/
373 static int Control( input_thread_t *p_input, int i_query, va_list args )
375 demux_sys_t *p_sys = p_input->p_demux_data;
382 pi64 = (int64_t*)va_arg( args, int64_t * );
383 *pi64 = p_sys->i_pcr;
389 case DEMUX_SET_POSITION:
390 for( i = 0; i < p_sys->i_streams; i++ )
392 logical_stream_t *p_stream = p_sys->pp_stream[i];
394 /* we'll trash all the data until we find the next pcr */
395 p_stream->b_reinit = 1;
396 p_stream->i_pcr = -1;
397 p_stream->i_interpolated_pcr = -1;
398 ogg_stream_reset( &p_stream->os );
400 ogg_sync_reset( &p_sys->oy );
403 return demux_vaControlDefault( p_input, i_query, args );
407 /****************************************************************************
408 * Ogg_ReadPage: Read a full Ogg page from the physical bitstream.
409 ****************************************************************************
410 * Returns VLC_SUCCESS if a page has been read. An error might happen if we
411 * are at the end of stream.
412 ****************************************************************************/
413 static int Ogg_ReadPage( input_thread_t *p_input, ogg_page *p_oggpage )
415 demux_sys_t *p_ogg = (demux_sys_t *)p_input->p_demux_data ;
417 data_packet_t *p_data;
420 while( ogg_sync_pageout( &p_ogg->oy, p_oggpage ) != 1 )
422 i_read = input_SplitBuffer( p_input, &p_data, OGG_BLOCK_SIZE );
426 p_buffer = ogg_sync_buffer( &p_ogg->oy, i_read );
427 p_input->p_vlc->pf_memcpy( p_buffer, p_data->p_payload_start, i_read );
428 ogg_sync_wrote( &p_ogg->oy, i_read );
429 input_DeletePacket( p_input->p_method_data, p_data );
435 /****************************************************************************
436 * Ogg_UpdatePCR: update the PCR (90kHz program clock reference) for the
438 ****************************************************************************/
439 static void Ogg_UpdatePCR( logical_stream_t *p_stream,
440 ogg_packet *p_oggpacket )
442 /* Convert the granulepos into a pcr */
443 if( p_oggpacket->granulepos >= 0 )
445 if( p_stream->fmt.i_codec != VLC_FOURCC( 't','h','e','o' ) )
447 p_stream->i_pcr = p_oggpacket->granulepos * I64C(1000000)
452 ogg_int64_t iframe = p_oggpacket->granulepos >>
453 p_stream->i_theora_keyframe_granule_shift;
454 ogg_int64_t pframe = p_oggpacket->granulepos -
455 ( iframe << p_stream->i_theora_keyframe_granule_shift );
457 p_stream->i_pcr = ( iframe + pframe ) * I64C(1000000)
461 p_stream->i_interpolated_pcr = p_stream->i_pcr;
465 p_stream->i_pcr = -1;
467 /* no granulepos available, try to interpolate the pcr.
468 * If we can't then don't touch the old value. */
469 if( p_stream->fmt.i_cat == VIDEO_ES )
470 /* 1 frame per packet */
471 p_stream->i_interpolated_pcr += (I64C(1000000) / p_stream->f_rate);
472 else if( p_stream->fmt.i_bitrate )
473 p_stream->i_interpolated_pcr += ( p_oggpacket->bytes * I64C(1000000)
474 / p_stream->fmt.i_bitrate / 8 );
478 /****************************************************************************
479 * Ogg_DecodePacket: Decode an Ogg packet.
480 ****************************************************************************/
481 static void Ogg_DecodePacket( input_thread_t *p_input,
482 logical_stream_t *p_stream,
483 ogg_packet *p_oggpacket )
486 vlc_bool_t b_selected;
487 int i_header_len = 0;
491 if( !p_oggpacket->bytes )
493 msg_Dbg( p_input, "discarding 0 sized packet" );
497 if( p_oggpacket->bytes >= 7 &&
498 ! strncmp ( &p_oggpacket->packet[0], "Annodex", 7 ) )
500 /* it's an Annodex packet -- skip it (do nothing) */
503 else if( p_oggpacket->bytes >= 7 &&
504 ! strncmp ( &p_oggpacket->packet[0], "AnxData", 7 ) )
506 /* it's an AnxData packet -- skip it (do nothing) */
510 if( p_stream->b_force_backup )
512 ogg_packet *p_packet_backup;
513 p_stream->i_packets_backup++;
514 switch( p_stream->fmt.i_codec )
516 case VLC_FOURCC( 'v','o','r','b' ):
517 case VLC_FOURCC( 's','p','x',' ' ):
518 case VLC_FOURCC( 't','h','e','o' ):
519 if( p_stream->i_packets_backup == 3 ) p_stream->b_force_backup = 0;
522 case VLC_FOURCC( 'f','l','a','c' ):
523 if( p_stream->i_packets_backup == 1 ) return;
524 else if( p_stream->i_packets_backup == 2 )
526 /* Parse the STREAMINFO metadata */
528 bs_init( &s, p_oggpacket->packet, p_oggpacket->bytes );
530 if( bs_read( &s, 7 ) == 0 )
532 if( bs_read( &s, 24 ) >= 34 /*size STREAMINFO*/ )
535 p_stream->f_rate = p_stream->fmt.audio.i_rate =
537 p_stream->fmt.audio.i_channels =
538 bs_read( &s, 3 ) + 1;
540 msg_Dbg( p_input, "FLAC header, channels: %i, rate: %i",
541 p_stream->fmt.audio.i_channels,
542 (int)p_stream->f_rate );
546 msg_Dbg( p_input, "FLAC STREAMINFO metadata too short" );
549 /* Store STREAMINFO for the decoder and packetizer */
550 p_stream->fmt.i_extra = p_oggpacket->bytes + 4;
551 p_stream->fmt.p_extra = malloc( p_stream->fmt.i_extra );
552 memcpy( p_stream->fmt.p_extra, "fLaC", 4);
553 memcpy( ((uint8_t *)p_stream->fmt.p_extra) + 4,
554 p_oggpacket->packet, p_oggpacket->bytes );
556 /* Fake this as the last metadata block */
557 ((uint8_t*)p_stream->fmt.p_extra)[4] |= 0x80;
559 p_stream->p_es = es_out_Add( p_input->p_es_out,
564 /* This ain't a STREAMINFO metadata */
565 msg_Dbg( p_input, "Invalid FLAC STREAMINFO metadata" );
567 p_stream->b_force_backup = 0;
568 p_stream->i_packets_backup = 0;
570 if( p_oggpacket->granulepos >= 0 )
571 Ogg_UpdatePCR( p_stream, p_oggpacket );
573 p_stream->i_previous_pcr = 0;
579 p_stream->b_force_backup = 0;
583 /* Backup the ogg packet (likely an header packet) */
584 p_stream->p_packets_backup =
585 realloc( p_stream->p_packets_backup, p_stream->i_packets_backup *
586 sizeof(ogg_packet) );
589 &p_stream->p_packets_backup[p_stream->i_packets_backup - 1];
591 p_packet_backup->bytes = p_oggpacket->bytes;
592 p_packet_backup->granulepos = p_oggpacket->granulepos;
594 if( p_oggpacket->granulepos >= 0 )
596 /* Because of vorbis granulepos scheme we must set the pcr for the
597 * 1st header packet so it doesn't get discarded in the
599 Ogg_UpdatePCR( p_stream, p_oggpacket );
602 p_packet_backup->packet = malloc( p_oggpacket->bytes );
603 if( !p_packet_backup->packet ) return;
604 memcpy( p_packet_backup->packet, p_oggpacket->packet,
605 p_oggpacket->bytes );
608 /* Check the ES is selected */
609 es_out_Control( p_input->p_es_out, ES_OUT_GET_ES_STATE,
610 p_stream->p_es, &b_selected );
612 if( b_selected && !p_stream->b_activated )
614 p_stream->b_activated = VLC_TRUE;
616 /* Newly activated stream, feed the backup headers to the decoder */
617 if( !p_stream->b_force_backup )
620 for( i = 0; i < p_stream->i_packets_backup; i++ )
622 /* Set correct starting date in header packets */
623 p_stream->p_packets_backup[i].granulepos =
624 p_stream->i_interpolated_pcr * p_stream->f_rate / I64C(1000000);
626 Ogg_DecodePacket( p_input, p_stream,
627 &p_stream->p_packets_backup[i] );
632 /* Convert the pcr into a pts */
633 if( p_stream->fmt.i_codec == VLC_FOURCC( 'v','o','r','b' ) ||
634 p_stream->fmt.i_codec == VLC_FOURCC( 's','p','x',' ' ) ||
635 p_stream->fmt.i_codec == VLC_FOURCC( 'f','l','a','c' ) )
637 if( p_stream->i_pcr >= 0 )
639 /* This is for streams where the granulepos of the header packets
640 * doesn't match these of the data packets (eg. ogg web radios). */
641 if( p_stream->i_previous_pcr == 0 &&
642 p_stream->i_pcr > 3 * DEFAULT_PTS_DELAY )
644 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
646 /* Call the pace control */
647 es_out_Control( p_input->p_es_out, ES_OUT_SET_PCR, p_stream->i_pcr );
650 p_stream->i_previous_pcr = p_stream->i_pcr;
652 /* The granulepos is the end date of the sample */
653 i_pts = p_stream->i_pcr;
657 /* Convert the granulepos into the next pcr */
658 Ogg_UpdatePCR( p_stream, p_oggpacket );
660 if( p_stream->i_pcr >= 0 )
662 /* This is for streams where the granulepos of the header packets
663 * doesn't match these of the data packets (eg. ogg web radios). */
664 if( p_stream->i_previous_pcr == 0 &&
665 p_stream->i_pcr > 3 * DEFAULT_PTS_DELAY )
667 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
669 /* Call the pace control */
670 es_out_Control( p_input->p_es_out, ES_OUT_SET_PCR, p_stream->i_pcr );
674 if( p_stream->fmt.i_codec != VLC_FOURCC( 'v','o','r','b' ) &&
675 p_stream->fmt.i_codec != VLC_FOURCC( 's','p','x',' ' ) &&
676 p_stream->fmt.i_codec != VLC_FOURCC( 'f','l','a','c' ) &&
677 p_stream->i_pcr >= 0 )
679 p_stream->i_previous_pcr = p_stream->i_pcr;
681 /* The granulepos is the start date of the sample */
682 i_pts = p_stream->i_pcr;
687 /* This stream isn't currently selected so we don't need to decode it,
688 * but we did need to store its pcr as it might be selected later on */
689 p_stream->b_activated = VLC_FALSE;
693 if( !( p_block = block_New( p_input, p_oggpacket->bytes ) ) ) return;
695 if( p_stream->fmt.i_cat == AUDIO_ES )
696 p_block->i_dts = p_block->i_pts = i_pts;
697 else if( p_stream->fmt.i_cat == SPU_ES )
699 p_block->i_pts = i_pts;
702 else if( p_stream->fmt.i_codec == VLC_FOURCC( 't','h','e','o' ) )
703 p_block->i_dts = p_block->i_pts = i_pts;
706 p_block->i_dts = i_pts;
710 if( p_stream->fmt.i_codec != VLC_FOURCC( 'v','o','r','b' ) &&
711 p_stream->fmt.i_codec != VLC_FOURCC( 's','p','x',' ' ) &&
712 p_stream->fmt.i_codec != VLC_FOURCC( 'f','l','a','c' ) &&
713 p_stream->fmt.i_codec != VLC_FOURCC( 't','a','r','k' ) &&
714 p_stream->fmt.i_codec != VLC_FOURCC( 't','h','e','o' ) &&
715 p_stream->fmt.i_codec != VLC_FOURCC( 'c','m','m','l' ) )
717 /* We remove the header from the packet */
718 i_header_len = (*p_oggpacket->packet & PACKET_LEN_BITS01) >> 6;
719 i_header_len |= (*p_oggpacket->packet & PACKET_LEN_BITS2) << 1;
721 if( p_stream->fmt.i_codec == VLC_FOURCC( 's','u','b','t' ))
723 /* But with subtitles we need to retrieve the duration first */
726 if( i_header_len > 0 && p_oggpacket->bytes >= i_header_len + 1 )
728 for( i = 0, lenbytes = 0; i < i_header_len; i++ )
730 lenbytes = lenbytes << 8;
731 lenbytes += *(p_oggpacket->packet + i_header_len - i);
734 if( p_oggpacket->bytes - 1 - i_header_len > 2 ||
735 ( p_oggpacket->packet[i_header_len + 1] != ' ' &&
736 p_oggpacket->packet[i_header_len + 1] != 0 &&
737 p_oggpacket->packet[i_header_len + 1] != '\n' &&
738 p_oggpacket->packet[i_header_len + 1] != '\r' ) )
740 p_block->i_dts = p_block->i_pts + (mtime_t)lenbytes * 1000;
745 p_block->i_buffer -= i_header_len;
748 if( p_stream->fmt.i_codec == VLC_FOURCC( 't','a','r','k' ) )
750 /* FIXME: the biggest hack I've ever done */
751 msg_Warn( p_input, "tarkin pts: "I64Fd", granule: "I64Fd,
752 p_block->i_pts, p_block->i_dts );
756 memcpy( p_block->p_buffer, p_oggpacket->packet + i_header_len,
757 p_oggpacket->bytes - i_header_len );
759 es_out_Send( p_input->p_es_out, p_stream->p_es, p_block );
762 /****************************************************************************
763 * Ogg_FindLogicalStreams: Find the logical streams embedded in the physical
764 * stream and fill p_ogg.
765 *****************************************************************************
766 * The initial page of a logical stream is marked as a 'bos' page.
767 * Furthermore, the Ogg specification mandates that grouped bitstreams begin
768 * together and all of the initial pages must appear before any data pages.
770 * On success this function returns VLC_SUCCESS.
771 ****************************************************************************/
772 static int Ogg_FindLogicalStreams( input_thread_t *p_input )
774 demux_sys_t *p_ogg = (demux_sys_t *)p_input->p_demux_data ;
775 ogg_packet oggpacket;
779 #define p_stream p_ogg->pp_stream[p_ogg->i_streams - 1]
781 while( Ogg_ReadPage( p_input, &oggpage ) == VLC_SUCCESS )
783 if( ogg_page_bos( &oggpage ) )
786 /* All is wonderful in our fine fine little world.
787 * We found the beginning of our first logical stream. */
788 while( ogg_page_bos( &oggpage ) )
792 realloc( p_ogg->pp_stream, p_ogg->i_streams *
793 sizeof(logical_stream_t *) );
795 p_stream = malloc( sizeof(logical_stream_t) );
796 memset( p_stream, 0, sizeof(logical_stream_t) );
798 es_format_Init( &p_stream->fmt, 0, 0 );
799 p_stream->b_activated = VLC_TRUE;
801 /* Setup the logical stream */
802 p_stream->i_serial_no = ogg_page_serialno( &oggpage );
803 ogg_stream_init( &p_stream->os, p_stream->i_serial_no );
805 /* Extract the initial header from the first page and verify
806 * the codec type of tis Ogg bitstream */
807 if( ogg_stream_pagein( &p_stream->os, &oggpage ) < 0 )
809 /* error. stream version mismatch perhaps */
810 msg_Err( p_input, "error reading first page of "
811 "Ogg bitstream data" );
815 /* FIXME: check return value */
816 ogg_stream_packetpeek( &p_stream->os, &oggpacket );
818 /* Check for Vorbis header */
819 if( oggpacket.bytes >= 7 &&
820 ! strncmp( &oggpacket.packet[1], "vorbis", 6 ) )
822 Ogg_ReadVorbisHeader( p_stream, &oggpacket );
823 msg_Dbg( p_input, "found vorbis header" );
825 /* Check for Speex header */
826 else if( oggpacket.bytes >= 7 &&
827 ! strncmp( &oggpacket.packet[0], "Speex", 5 ) )
831 p_stream->fmt.i_cat = AUDIO_ES;
832 p_stream->fmt.i_codec = VLC_FOURCC( 's','p','x',' ' );
834 /* Signal that we want to keep a backup of the vorbis
835 * stream headers. They will be used when switching between
837 p_stream->b_force_backup = 1;
839 /* Cheat and get additionnal info ;) */
840 oggpack_readinit( &opb, oggpacket.packet, oggpacket.bytes);
841 oggpack_adv( &opb, 224 );
842 oggpack_adv( &opb, 32 ); /* speex_version_id */
843 oggpack_adv( &opb, 32 ); /* header_size */
844 p_stream->f_rate = p_stream->fmt.audio.i_rate =
845 oggpack_read( &opb, 32 );
846 oggpack_adv( &opb, 32 ); /* mode */
847 oggpack_adv( &opb, 32 ); /* mode_bitstream_version */
848 p_stream->fmt.audio.i_channels = oggpack_read( &opb, 32 );
849 p_stream->fmt.i_bitrate = oggpack_read( &opb, 32 );
851 msg_Dbg( p_input, "found speex header, channels: %i, "
852 "rate: %i, bitrate: %i",
853 p_stream->fmt.audio.i_channels,
854 (int)p_stream->f_rate, p_stream->fmt.i_bitrate );
856 /* Check for Flac header */
857 else if( oggpacket.bytes >= 4 &&
858 ! strncmp( &oggpacket.packet[0], "fLaC", 4 ) )
860 msg_Dbg( p_input, "found FLAC header" );
862 /* Grrrr!!!! Did they really have to put all the
863 * important info in the second header packet!!!
864 * (STREAMINFO metadata is in the following packet) */
865 p_stream->b_force_backup = 1;
867 p_stream->fmt.i_cat = AUDIO_ES;
868 p_stream->fmt.i_codec = VLC_FOURCC( 'f','l','a','c' );
870 /* Check for Theora header */
871 else if( oggpacket.bytes >= 7 &&
872 ! strncmp( &oggpacket.packet[1], "theora", 6 ) )
874 Ogg_ReadTheoraHeader( p_stream, &oggpacket );
877 "found theora header, bitrate: %i, rate: %f",
878 p_stream->fmt.i_bitrate, p_stream->f_rate );
880 /* Check for Tarkin header */
881 else if( oggpacket.bytes >= 7 &&
882 ! strncmp( &oggpacket.packet[1], "tarkin", 6 ) )
886 msg_Dbg( p_input, "found tarkin header" );
887 p_stream->fmt.i_cat = VIDEO_ES;
888 p_stream->fmt.i_codec = VLC_FOURCC( 't','a','r','k' );
890 /* Cheat and get additionnal info ;) */
891 oggpack_readinit( &opb, oggpacket.packet, oggpacket.bytes);
892 oggpack_adv( &opb, 88 );
893 oggpack_adv( &opb, 104 );
894 p_stream->fmt.i_bitrate = oggpack_read( &opb, 32 );
895 p_stream->f_rate = 2; /* FIXME */
897 "found tarkin header, bitrate: %i, rate: %f",
898 p_stream->fmt.i_bitrate, p_stream->f_rate );
900 /* Check for Annodex header */
901 else if( oggpacket.bytes >= 7 &&
902 ! strncmp( &oggpacket.packet[0], "Annodex", 7 ) )
904 Ogg_ReadAnnodexHeader( VLC_OBJECT(p_input), p_stream,
906 /* kill annodex track */
910 /* Check for Annodex header */
911 else if( oggpacket.bytes >= 7 &&
912 ! strncmp( &oggpacket.packet[0], "AnxData", 7 ) )
914 Ogg_ReadAnnodexHeader( VLC_OBJECT(p_input), p_stream,
917 else if( oggpacket.bytes >= 142 &&
918 !strncmp( &oggpacket.packet[1],
919 "Direct Show Samples embedded in Ogg", 35 ))
921 /* Old header type */
923 /* Check for video header (old format) */
924 if( GetDWLE((oggpacket.packet+96)) == 0x05589f80 &&
925 oggpacket.bytes >= 184 )
927 p_stream->fmt.i_cat = VIDEO_ES;
928 p_stream->fmt.i_codec =
929 VLC_FOURCC( oggpacket.packet[68],
930 oggpacket.packet[69],
931 oggpacket.packet[70],
932 oggpacket.packet[71] );
933 msg_Dbg( p_input, "found video header of type: %.4s",
934 (char *)&p_stream->fmt.i_codec );
936 p_stream->f_rate = 10000000.0 /
937 GetQWLE((oggpacket.packet+164));
938 p_stream->fmt.video.i_bits_per_pixel =
939 GetWLE((oggpacket.packet+182));
940 if( !p_stream->fmt.video.i_bits_per_pixel )
942 p_stream->fmt.video.i_bits_per_pixel = 24;
943 p_stream->fmt.video.i_width =
944 GetDWLE((oggpacket.packet+176));
945 p_stream->fmt.video.i_height =
946 GetDWLE((oggpacket.packet+180));
949 "fps: %f, width:%i; height:%i, bitcount:%i",
951 p_stream->fmt.video.i_width,
952 p_stream->fmt.video.i_height,
953 p_stream->fmt.video.i_bits_per_pixel);
956 /* Check for audio header (old format) */
957 else if( GetDWLE((oggpacket.packet+96)) == 0x05589F81 )
959 unsigned int i_extra_size;
960 unsigned int i_format_tag;
962 p_stream->fmt.i_cat = AUDIO_ES;
964 i_extra_size = GetWLE((oggpacket.packet+140));
967 p_stream->fmt.i_extra = i_extra_size;
968 p_stream->fmt.p_extra = malloc( i_extra_size );
969 memcpy( p_stream->fmt.p_extra,
970 oggpacket.packet + 142, i_extra_size );
973 i_format_tag = GetWLE((oggpacket.packet+124));
974 p_stream->fmt.audio.i_channels =
975 GetWLE((oggpacket.packet+126));
976 p_stream->f_rate = p_stream->fmt.audio.i_rate =
977 GetDWLE((oggpacket.packet+128));
978 p_stream->fmt.i_bitrate =
979 GetDWLE((oggpacket.packet+132)) * 8;
980 p_stream->fmt.audio.i_blockalign =
981 GetWLE((oggpacket.packet+136));
982 p_stream->fmt.audio.i_bitspersample =
983 GetWLE((oggpacket.packet+138));
985 switch( i_format_tag )
987 case WAVE_FORMAT_PCM:
988 p_stream->fmt.i_codec =
989 VLC_FOURCC( 'a', 'r', 'a', 'w' );
991 case WAVE_FORMAT_MPEG:
992 case WAVE_FORMAT_MPEGLAYER3:
993 p_stream->fmt.i_codec =
994 VLC_FOURCC( 'm', 'p', 'g', 'a' );
996 case WAVE_FORMAT_A52:
997 p_stream->fmt.i_codec =
998 VLC_FOURCC( 'a', '5', '2', ' ' );
1000 case WAVE_FORMAT_WMA1:
1001 p_stream->fmt.i_codec =
1002 VLC_FOURCC( 'w', 'm', 'a', '1' );
1004 case WAVE_FORMAT_WMA2:
1005 p_stream->fmt.i_codec =
1006 VLC_FOURCC( 'w', 'm', 'a', '2' );
1009 p_stream->fmt.i_codec = VLC_FOURCC( 'm', 's',
1010 ( i_format_tag >> 8 ) & 0xff,
1011 i_format_tag & 0xff );
1014 msg_Dbg( p_input, "found audio header of type: %.4s",
1015 (char *)&p_stream->fmt.i_codec );
1016 msg_Dbg( p_input, "audio:0x%4.4x channels:%d %dHz "
1017 "%dbits/sample %dkb/s",
1019 p_stream->fmt.audio.i_channels,
1020 p_stream->fmt.audio.i_rate,
1021 p_stream->fmt.audio.i_bitspersample,
1022 p_stream->fmt.i_bitrate / 1024 );
1027 msg_Dbg( p_input, "stream %d has an old header "
1028 "but is of an unknown type", p_ogg->i_streams-1 );
1033 else if( (*oggpacket.packet & PACKET_TYPE_BITS )
1034 == PACKET_TYPE_HEADER &&
1035 oggpacket.bytes >= (int)sizeof(stream_header)+1 )
1037 stream_header *st = (stream_header *)(oggpacket.packet+1);
1039 /* Check for video header (new format) */
1040 if( !strncmp( st->streamtype, "video", 5 ) )
1042 p_stream->fmt.i_cat = VIDEO_ES;
1044 /* We need to get rid of the header packet */
1045 ogg_stream_packetout( &p_stream->os, &oggpacket );
1047 p_stream->fmt.i_codec =
1048 VLC_FOURCC( st->subtype[0], st->subtype[1],
1049 st->subtype[2], st->subtype[3] );
1050 msg_Dbg( p_input, "found video header of type: %.4s",
1051 (char *)&p_stream->fmt.i_codec );
1053 p_stream->f_rate = 10000000.0 /
1054 GetQWLE(&st->time_unit);
1055 p_stream->fmt.video.i_bits_per_pixel =
1056 GetWLE(&st->bits_per_sample);
1057 p_stream->fmt.video.i_width =
1058 GetDWLE(&st->sh.video.width);
1059 p_stream->fmt.video.i_height =
1060 GetDWLE(&st->sh.video.height);
1063 "fps: %f, width:%i; height:%i, bitcount:%i",
1065 p_stream->fmt.video.i_width,
1066 p_stream->fmt.video.i_height,
1067 p_stream->fmt.video.i_bits_per_pixel );
1069 /* Check for audio header (new format) */
1070 else if( !strncmp( st->streamtype, "audio", 5 ) )
1075 p_stream->fmt.i_cat = AUDIO_ES;
1077 /* We need to get rid of the header packet */
1078 ogg_stream_packetout( &p_stream->os, &oggpacket );
1080 memcpy( p_buffer, st->subtype, 4 );
1082 i_format_tag = strtol(p_buffer,NULL,16);
1083 p_stream->fmt.audio.i_channels =
1084 GetWLE(&st->sh.audio.channels);
1085 p_stream->f_rate = p_stream->fmt.audio.i_rate =
1086 GetQWLE(&st->samples_per_unit);
1087 p_stream->fmt.i_bitrate =
1088 GetDWLE(&st->sh.audio.avgbytespersec) * 8;
1089 p_stream->fmt.audio.i_blockalign =
1090 GetWLE(&st->sh.audio.blockalign);
1091 p_stream->fmt.audio.i_bitspersample =
1092 GetWLE(&st->bits_per_sample);
1094 switch( i_format_tag )
1096 case WAVE_FORMAT_PCM:
1097 p_stream->fmt.i_codec =
1098 VLC_FOURCC( 'a', 'r', 'a', 'w' );
1100 case WAVE_FORMAT_MPEG:
1101 case WAVE_FORMAT_MPEGLAYER3:
1102 p_stream->fmt.i_codec =
1103 VLC_FOURCC( 'm', 'p', 'g', 'a' );
1105 case WAVE_FORMAT_A52:
1106 p_stream->fmt.i_codec =
1107 VLC_FOURCC( 'a', '5', '2', ' ' );
1109 case WAVE_FORMAT_WMA1:
1110 p_stream->fmt.i_codec =
1111 VLC_FOURCC( 'w', 'm', 'a', '1' );
1113 case WAVE_FORMAT_WMA2:
1114 p_stream->fmt.i_codec =
1115 VLC_FOURCC( 'w', 'm', 'a', '2' );
1118 p_stream->fmt.i_codec = VLC_FOURCC( 'm', 's',
1119 ( i_format_tag >> 8 ) & 0xff,
1120 i_format_tag & 0xff );
1123 msg_Dbg( p_input, "found audio header of type: %.4s",
1124 (char *)&p_stream->fmt.i_codec );
1125 msg_Dbg( p_input, "audio:0x%4.4x channels:%d %dHz "
1126 "%dbits/sample %dkb/s",
1128 p_stream->fmt.audio.i_channels,
1129 p_stream->fmt.audio.i_rate,
1130 p_stream->fmt.audio.i_bitspersample,
1131 p_stream->fmt.i_bitrate / 1024 );
1133 /* Check for text (subtitles) header */
1134 else if( !strncmp(st->streamtype, "text", 4) )
1136 /* We need to get rid of the header packet */
1137 ogg_stream_packetout( &p_stream->os, &oggpacket );
1139 msg_Dbg( p_input, "found text subtitles header" );
1140 p_stream->fmt.i_cat = SPU_ES;
1141 p_stream->fmt.i_codec = VLC_FOURCC('s','u','b','t');
1142 p_stream->f_rate = 1000; /* granulepos is in milisec */
1146 msg_Dbg( p_input, "stream %d has a header marker "
1147 "but is of an unknown type", p_ogg->i_streams-1 );
1154 msg_Dbg( p_input, "stream %d is of unknown type",
1155 p_ogg->i_streams-1 );
1160 if( Ogg_ReadPage( p_input, &oggpage ) != VLC_SUCCESS )
1161 return VLC_EGENERIC;
1164 /* This is the first data page, which means we are now finished
1165 * with the initial pages. We just need to store it in the relevant
1167 for( i_stream = 0; i_stream < p_ogg->i_streams; i_stream++ )
1169 if( ogg_stream_pagein( &p_ogg->pp_stream[i_stream]->os,
1181 return VLC_EGENERIC;
1184 /****************************************************************************
1185 * Ogg_BeginningOfStream: Look for Beginning of Stream ogg pages and add
1186 * Elementary streams.
1187 ****************************************************************************/
1188 static int Ogg_BeginningOfStream( input_thread_t *p_input )
1190 demux_sys_t *p_ogg = (demux_sys_t *)p_input->p_demux_data ;
1193 /* Find the logical streams embedded in the physical stream and
1194 * initialize our p_ogg structure. */
1195 if( Ogg_FindLogicalStreams( p_input ) != VLC_SUCCESS )
1197 msg_Warn( p_input, "couldn't find any ogg logical stream" );
1198 return VLC_EGENERIC;
1201 vlc_mutex_lock( &p_input->stream.stream_lock );
1202 p_input->stream.i_mux_rate = 0;
1203 vlc_mutex_unlock( &p_input->stream.stream_lock );
1205 for( i_stream = 0 ; i_stream < p_ogg->i_streams; i_stream++ )
1207 #define p_stream p_ogg->pp_stream[i_stream]
1208 if( p_stream->fmt.i_codec != VLC_FOURCC('f','l','a','c') )
1209 p_stream->p_es = es_out_Add( p_input->p_es_out, &p_stream->fmt );
1211 if( p_stream->fmt.i_codec == VLC_FOURCC('c','m','m','l') )
1213 /* Set the CMML stream active */
1214 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1219 vlc_mutex_lock( &p_input->stream.stream_lock );
1220 p_input->stream.i_mux_rate += (p_stream->fmt.i_bitrate / ( 8 * 50 ));
1221 vlc_mutex_unlock( &p_input->stream.stream_lock );
1223 p_stream->i_pcr = p_stream->i_previous_pcr =
1224 p_stream->i_interpolated_pcr = -1;
1225 p_stream->b_reinit = 0;
1232 /****************************************************************************
1233 * Ogg_EndOfStream: clean up the ES when an End of Stream is detected.
1234 ****************************************************************************/
1235 static void Ogg_EndOfStream( input_thread_t *p_input )
1237 demux_sys_t *p_ogg = (demux_sys_t *)p_input->p_demux_data ;
1240 #define p_stream p_ogg->pp_stream[i_stream]
1241 for( i_stream = 0 ; i_stream < p_ogg->i_streams; i_stream++ )
1243 if( p_stream->p_es )
1244 es_out_Del( p_input->p_es_out, p_stream->p_es );
1246 vlc_mutex_lock( &p_input->stream.stream_lock );
1247 p_input->stream.i_mux_rate -= (p_stream->fmt.i_bitrate / ( 8 * 50 ));
1248 vlc_mutex_unlock( &p_input->stream.stream_lock );
1250 ogg_stream_clear( &p_ogg->pp_stream[i_stream]->os );
1251 for( j = 0; j < p_ogg->pp_stream[i_stream]->i_packets_backup; j++ )
1253 free( p_ogg->pp_stream[i_stream]->p_packets_backup[j].packet );
1255 if( p_ogg->pp_stream[i_stream]->p_packets_backup)
1256 free( p_ogg->pp_stream[i_stream]->p_packets_backup );
1258 es_format_Clean( &p_stream->fmt );
1260 free( p_ogg->pp_stream[i_stream] );
1265 if( p_ogg->pp_stream ) free( p_ogg->pp_stream );
1266 p_ogg->pp_stream = NULL;
1267 p_ogg->i_streams = 0;
1270 static void Ogg_ReadTheoraHeader( logical_stream_t *p_stream,
1271 ogg_packet *p_oggpacket )
1274 int i_fps_numerator;
1275 int i_fps_denominator;
1276 int i_keyframe_frequency_force;
1278 p_stream->fmt.i_cat = VIDEO_ES;
1279 p_stream->fmt.i_codec = VLC_FOURCC( 't','h','e','o' );
1281 /* Signal that we want to keep a backup of the vorbis
1282 * stream headers. They will be used when switching between
1284 p_stream->b_force_backup = 1;
1286 /* Cheat and get additionnal info ;) */
1287 bs_init( &bitstream, p_oggpacket->packet, p_oggpacket->bytes );
1288 bs_skip( &bitstream, 56 );
1289 bs_read( &bitstream, 8 ); /* major version num */
1290 bs_read( &bitstream, 8 ); /* minor version num */
1291 bs_read( &bitstream, 8 ); /* subminor version num */
1292 bs_read( &bitstream, 16 ) /*<< 4*/; /* width */
1293 bs_read( &bitstream, 16 ) /*<< 4*/; /* height */
1294 bs_read( &bitstream, 24 ); /* frame width */
1295 bs_read( &bitstream, 24 ); /* frame height */
1296 bs_read( &bitstream, 8 ); /* x offset */
1297 bs_read( &bitstream, 8 ); /* y offset */
1299 i_fps_numerator = bs_read( &bitstream, 32 );
1300 i_fps_denominator = bs_read( &bitstream, 32 );
1301 bs_read( &bitstream, 24 ); /* aspect_numerator */
1302 bs_read( &bitstream, 24 ); /* aspect_denominator */
1303 i_keyframe_frequency_force = 1 << bs_read( &bitstream, 5 );
1304 bs_read( &bitstream, 8 ); /* colorspace */
1305 p_stream->fmt.i_bitrate = bs_read( &bitstream, 24 );
1306 bs_read( &bitstream, 6 ); /* quality */
1308 /* granule_shift = i_log( frequency_force -1 ) */
1309 p_stream->i_theora_keyframe_granule_shift = 0;
1310 i_keyframe_frequency_force--;
1311 while( i_keyframe_frequency_force )
1313 p_stream->i_theora_keyframe_granule_shift++;
1314 i_keyframe_frequency_force >>= 1;
1317 p_stream->f_rate = ((float)i_fps_numerator) / i_fps_denominator;
1319 /* Save this data in p_extra for ffmpeg */
1320 p_stream->fmt.i_extra = p_oggpacket->bytes;
1321 p_stream->fmt.p_extra = malloc( p_oggpacket->bytes );
1322 memcpy( p_stream->fmt.p_extra, p_oggpacket->packet, p_oggpacket->bytes );
1326 static void Ogg_ReadVorbisHeader( logical_stream_t *p_stream,
1327 ogg_packet *p_oggpacket )
1331 p_stream->fmt.i_cat = AUDIO_ES;
1332 p_stream->fmt.i_codec = VLC_FOURCC( 'v','o','r','b' );
1334 /* Signal that we want to keep a backup of the vorbis
1335 * stream headers. They will be used when switching between
1337 p_stream->b_force_backup = 1;
1339 /* Cheat and get additionnal info ;) */
1340 oggpack_readinit( &opb, p_oggpacket->packet, p_oggpacket->bytes);
1341 oggpack_adv( &opb, 88 );
1342 p_stream->fmt.audio.i_channels = oggpack_read( &opb, 8 );
1343 p_stream->f_rate = p_stream->fmt.audio.i_rate =
1344 oggpack_read( &opb, 32 );
1345 oggpack_adv( &opb, 32 );
1346 p_stream->fmt.i_bitrate = oggpack_read( &opb, 32 );
1349 static void Ogg_ReadAnnodexHeader( vlc_object_t *p_this,
1350 logical_stream_t *p_stream,
1351 ogg_packet *p_oggpacket )
1353 if( ! strncmp( &p_oggpacket->packet[0], "Annodex", 7 ) )
1357 uint16_t major_version;
1358 uint16_t minor_version;
1359 uint64_t timebase_numerator;
1360 uint64_t timebase_denominator;
1362 Ogg_ReadTheoraHeader( p_stream, p_oggpacket );
1364 oggpack_readinit( &opb, p_oggpacket->packet, p_oggpacket->bytes);
1365 oggpack_adv( &opb, 8*8 ); /* "Annodex\0" header */
1366 major_version = oggpack_read( &opb, 2*8 ); /* major version */
1367 minor_version = oggpack_read( &opb, 2*8 ); /* minor version */
1368 timebase_numerator = GetQWLE( &p_oggpacket->packet[16] );
1369 timebase_denominator = GetQWLE( &p_oggpacket->packet[24] );
1371 else if( ! strncmp( &p_oggpacket->packet[0], "AnxData", 7 ) )
1373 uint64_t granule_rate_numerator;
1374 uint64_t granule_rate_denominator;
1375 char content_type_string[1024];
1377 /* Read in Annodex header fields */
1379 granule_rate_numerator = GetQWLE( &p_oggpacket->packet[8] );
1380 granule_rate_denominator = GetQWLE( &p_oggpacket->packet[16] );
1381 p_stream->secondary_header_packets =
1382 GetDWLE( &p_oggpacket->packet[24] );
1384 msg_Dbg( p_this, "anxdata packet info: %qd/%qd, %d",
1385 granule_rate_numerator, granule_rate_denominator,
1386 p_stream->secondary_header_packets);
1388 /* we are guaranteed that the first header field will be
1389 * the content-type (by the Annodex standard) */
1390 sscanf( &p_oggpacket->packet[28], "Content-Type: %1024s\r\n",
1391 content_type_string );
1393 p_stream->f_rate = (float) granule_rate_numerator /
1394 (float) granule_rate_denominator;
1396 /* What type of file do we have?
1397 * strcmp is safe to use here because we've extracted
1398 * content_type_string from the stream manually */
1399 if( !strncmp(content_type_string, "audio/x-wav", 11) )
1401 /* n.b. WAVs are unsupported right now */
1402 p_stream->fmt.i_cat = UNKNOWN_ES;
1404 else if( !strncmp(content_type_string, "audio/x-vorbis", 14) )
1406 p_stream->fmt.i_cat = AUDIO_ES;
1407 p_stream->fmt.i_codec = VLC_FOURCC( 'v','o','r','b' );
1409 p_stream->b_force_backup = 1;
1411 else if( !strncmp(content_type_string, "video/x-theora", 14) )
1413 p_stream->fmt.i_cat = VIDEO_ES;
1414 p_stream->fmt.i_codec = VLC_FOURCC( 't','h','e','o' );
1416 p_stream->b_force_backup = 1;
1418 else if( !strncmp(content_type_string, "video/x-xvid", 14) )
1420 p_stream->fmt.i_cat = VIDEO_ES;
1421 p_stream->fmt.i_codec = VLC_FOURCC( 'x','v','i','d' );
1423 p_stream->b_force_backup = 1;
1425 else if( !strncmp(content_type_string, "video/mpeg", 14) )
1427 /* n.b. MPEG streams are unsupported right now */
1428 p_stream->fmt.i_cat = VIDEO_ES;
1429 p_stream->fmt.i_codec = VLC_FOURCC( 'm','p','g','v' );
1431 else if( !strncmp(content_type_string, "text/x-cmml", 11) )
1433 ogg_stream_packetout( &p_stream->os, p_oggpacket );
1434 p_stream->fmt.i_cat = SPU_ES;
1435 p_stream->fmt.i_codec = VLC_FOURCC( 'c','m','m','l' );