1 /*****************************************************************************
2 * ogg.c : ogg stream demux module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2007 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
29 #include <vlc_demux.h>
31 #include <vlc_input.h>
35 #include <vlc_codecs.h>
38 /*****************************************************************************
40 *****************************************************************************/
41 static int Open ( vlc_object_t * );
42 static void Close( vlc_object_t * );
45 set_shortname ( "OGG" );
46 set_description( _("OGG demuxer" ) );
47 set_category( CAT_INPUT );
48 set_subcategory( SUBCAT_INPUT_DEMUX );
49 set_capability( "demux2", 50 );
50 set_callbacks( Open, Close );
51 add_shortcut( "ogg" );
55 /*****************************************************************************
56 * Definitions of structures and functions used by this plugins
57 *****************************************************************************/
58 typedef struct logical_stream_s
60 ogg_stream_state os; /* logical stream of packets */
68 /* the header of some logical streams (eg vorbis) contain essential
69 * data for the decoder. We back them up here in case we need to re-feed
70 * them to the decoder. */
76 /* program clock reference (in units of 90kHz) derived from the previous
79 mtime_t i_interpolated_pcr;
80 mtime_t i_previous_pcr;
84 int i_theora_keyframe_granule_shift;
86 /* for Annodex logical bitstreams */
87 int secondary_header_packets;
93 ogg_sync_state oy; /* sync and verify incoming physical bitstream */
95 int i_streams; /* number of logical bitstreams */
96 logical_stream_t **pp_stream; /* pointer to an array of logical streams */
98 /* program clock reference (in units of 90kHz) derived from the pcr of
109 /* OggDS headers for the new header format (used in ogm files) */
110 typedef struct stream_header_video
114 } stream_header_video;
116 typedef struct stream_header_audio
118 ogg_int16_t channels;
119 ogg_int16_t blockalign;
120 ogg_int32_t avgbytespersec;
121 } stream_header_audio;
123 typedef struct stream_header
128 ogg_int32_t size; /* size of the structure */
130 ogg_int64_t time_unit; /* in reference time */
131 ogg_int64_t samples_per_unit;
132 ogg_int32_t default_len; /* in media time */
134 ogg_int32_t buffersize;
135 ogg_int16_t bits_per_sample;
140 stream_header_video video;
142 stream_header_audio audio;
146 #define OGG_BLOCK_SIZE 4096
148 /* Some defines from OggDS */
149 #define PACKET_TYPE_HEADER 0x01
150 #define PACKET_TYPE_BITS 0x07
151 #define PACKET_LEN_BITS01 0xc0
152 #define PACKET_LEN_BITS2 0x02
153 #define PACKET_IS_SYNCPOINT 0x08
155 /*****************************************************************************
157 *****************************************************************************/
158 static int Demux ( demux_t * );
159 static int Control( demux_t *, int, va_list );
161 /* Bitstream manipulation */
162 static int Ogg_ReadPage ( demux_t *, ogg_page * );
163 static void Ogg_UpdatePCR ( logical_stream_t *, ogg_packet * );
164 static void Ogg_DecodePacket ( demux_t *, logical_stream_t *, ogg_packet * );
166 static int Ogg_BeginningOfStream( demux_t *p_demux );
167 static int Ogg_FindLogicalStreams( demux_t *p_demux );
168 static void Ogg_EndOfStream( demux_t *p_demux );
170 /* Logical bitstream headers */
171 static void Ogg_ReadTheoraHeader( logical_stream_t *, ogg_packet * );
172 static void Ogg_ReadVorbisHeader( logical_stream_t *, ogg_packet * );
173 static void Ogg_ReadSpeexHeader( logical_stream_t *, ogg_packet * );
174 static void Ogg_ReadFlacHeader( demux_t *, logical_stream_t *, ogg_packet * );
175 static void Ogg_ReadAnnodexHeader( vlc_object_t *, logical_stream_t *, ogg_packet * );
177 /*****************************************************************************
178 * Open: initializes ogg demux structures
179 *****************************************************************************/
180 static int Open( vlc_object_t * p_this )
182 demux_t *p_demux = (demux_t *)p_this;
184 const uint8_t *p_peek;
187 /* Check if we are dealing with an ogg stream */
188 if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 ) return VLC_EGENERIC;
189 if( !p_demux->b_force && memcmp( p_peek, "OggS", 4 ) )
194 /* Set exported functions */
195 p_demux->pf_demux = Demux;
196 p_demux->pf_control = Control;
197 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
199 memset( p_sys, 0, sizeof( demux_sys_t ) );
200 p_sys->i_bitrate = 0;
201 p_sys->pp_stream = NULL;
203 /* Begnning of stream, tell the demux to look for elementary streams. */
206 /* Initialize the Ogg physical bitstream parser */
207 ogg_sync_init( &p_sys->oy );
212 /*****************************************************************************
213 * Close: frees unused data
214 *****************************************************************************/
215 static void Close( vlc_object_t *p_this )
217 demux_t *p_demux = (demux_t *)p_this;
218 demux_sys_t *p_sys = p_demux->p_sys ;
220 /* Cleanup the bitstream parser */
221 ogg_sync_clear( &p_sys->oy );
223 Ogg_EndOfStream( p_demux );
228 /*****************************************************************************
229 * Demux: reads and demuxes data packets
230 *****************************************************************************
231 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
232 *****************************************************************************/
233 static int Demux( demux_t * p_demux )
235 demux_sys_t *p_sys = p_demux->p_sys;
237 ogg_packet oggpacket;
241 if( p_sys->i_eos == p_sys->i_streams )
245 msg_Dbg( p_demux, "end of a group of logical streams" );
246 Ogg_EndOfStream( p_demux );
250 if( Ogg_BeginningOfStream( p_demux ) != VLC_SUCCESS ) return 0;
252 msg_Dbg( p_demux, "beginning of a group of logical streams" );
253 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
257 * Demux an ogg page from the stream
259 if( Ogg_ReadPage( p_demux, &oggpage ) != VLC_SUCCESS )
264 /* Test for End of Stream */
265 if( ogg_page_eos( &oggpage ) ) p_sys->i_eos++;
268 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
270 logical_stream_t *p_stream = p_sys->pp_stream[i_stream];
272 if( ogg_stream_pagein( &p_stream->os, &oggpage ) != 0 )
275 while( ogg_stream_packetout( &p_stream->os, &oggpacket ) > 0 )
277 /* Read info from any secondary header packets, if there are any */
278 if( p_stream->secondary_header_packets > 0 )
280 if( p_stream->fmt.i_codec == VLC_FOURCC('t','h','e','o') &&
281 oggpacket.bytes >= 7 &&
282 ! memcmp( oggpacket.packet, "\x80theora", 6 ) )
284 Ogg_ReadTheoraHeader( p_stream, &oggpacket );
285 p_stream->secondary_header_packets = 0;
287 else if( p_stream->fmt.i_codec == VLC_FOURCC('v','o','r','b') &&
288 oggpacket.bytes >= 7 &&
289 ! memcmp( oggpacket.packet, "\x01vorbis", 6 ) )
291 Ogg_ReadVorbisHeader( p_stream, &oggpacket );
292 p_stream->secondary_header_packets = 0;
294 else if ( p_stream->fmt.i_codec == VLC_FOURCC('c','m','m','l') )
296 p_stream->secondary_header_packets = 0;
300 if( p_stream->b_reinit )
302 /* If synchro is re-initialized we need to drop all the packets
303 * until we find a new dated one. */
304 Ogg_UpdatePCR( p_stream, &oggpacket );
306 if( p_stream->i_pcr >= 0 )
308 p_stream->b_reinit = 0;
312 p_stream->i_interpolated_pcr = -1;
316 /* An Ogg/vorbis packet contains an end date granulepos */
317 if( p_stream->fmt.i_codec == VLC_FOURCC( 'v','o','r','b' ) ||
318 p_stream->fmt.i_codec == VLC_FOURCC( 's','p','x',' ' ) ||
319 p_stream->fmt.i_codec == VLC_FOURCC( 'f','l','a','c' ) )
321 if( ogg_stream_packetout( &p_stream->os, &oggpacket ) > 0 )
323 Ogg_DecodePacket( p_demux, p_stream, &oggpacket );
327 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
334 Ogg_DecodePacket( p_demux, p_stream, &oggpacket );
339 i_stream = 0; p_sys->i_pcr = -1;
340 for( ; i_stream < p_sys->i_streams; i_stream++ )
342 logical_stream_t *p_stream = p_sys->pp_stream[i_stream];
344 if( p_stream->fmt.i_cat == SPU_ES )
346 if( p_stream->i_interpolated_pcr < 0 )
349 if( p_sys->i_pcr < 0 || p_stream->i_interpolated_pcr < p_sys->i_pcr )
350 p_sys->i_pcr = p_stream->i_interpolated_pcr;
353 if( p_sys->i_pcr >= 0 )
355 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_pcr );
362 /*****************************************************************************
364 *****************************************************************************/
365 static int Control( demux_t *p_demux, int i_query, va_list args )
367 demux_sys_t *p_sys = p_demux->p_sys;
374 case DEMUX_HAS_UNSUPPORTED_META:
375 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
380 pi64 = (int64_t*)va_arg( args, int64_t * );
381 *pi64 = p_sys->i_pcr;
387 case DEMUX_SET_POSITION:
388 for( i = 0; i < p_sys->i_streams; i++ )
390 logical_stream_t *p_stream = p_sys->pp_stream[i];
392 /* we'll trash all the data until we find the next pcr */
393 p_stream->b_reinit = 1;
394 p_stream->i_pcr = -1;
395 p_stream->i_interpolated_pcr = -1;
396 ogg_stream_reset( &p_stream->os );
398 ogg_sync_reset( &p_sys->oy );
401 return demux2_vaControlHelper( p_demux->s, 0, -1, p_sys->i_bitrate,
406 /****************************************************************************
407 * Ogg_ReadPage: Read a full Ogg page from the physical bitstream.
408 ****************************************************************************
409 * Returns VLC_SUCCESS if a page has been read. An error might happen if we
410 * are at the end of stream.
411 ****************************************************************************/
412 static int Ogg_ReadPage( demux_t *p_demux, ogg_page *p_oggpage )
414 demux_sys_t *p_ogg = p_demux->p_sys ;
418 while( ogg_sync_pageout( &p_ogg->oy, p_oggpage ) != 1 )
420 p_buffer = ogg_sync_buffer( &p_ogg->oy, OGG_BLOCK_SIZE );
422 i_read = stream_Read( p_demux->s, p_buffer, OGG_BLOCK_SIZE );
426 ogg_sync_wrote( &p_ogg->oy, i_read );
432 /****************************************************************************
433 * Ogg_UpdatePCR: update the PCR (90kHz program clock reference) for the
435 ****************************************************************************/
436 static void Ogg_UpdatePCR( logical_stream_t *p_stream,
437 ogg_packet *p_oggpacket )
439 /* Convert the granulepos into a pcr */
440 if( p_oggpacket->granulepos >= 0 )
442 if( p_stream->fmt.i_codec != VLC_FOURCC( 't','h','e','o' ) )
444 p_stream->i_pcr = p_oggpacket->granulepos * I64C(1000000)
449 ogg_int64_t iframe = p_oggpacket->granulepos >>
450 p_stream->i_theora_keyframe_granule_shift;
451 ogg_int64_t pframe = p_oggpacket->granulepos -
452 ( iframe << p_stream->i_theora_keyframe_granule_shift );
454 p_stream->i_pcr = ( iframe + pframe ) * I64C(1000000)
458 p_stream->i_interpolated_pcr = p_stream->i_pcr;
462 p_stream->i_pcr = -1;
464 /* no granulepos available, try to interpolate the pcr.
465 * If we can't then don't touch the old value. */
466 if( p_stream->fmt.i_cat == VIDEO_ES )
467 /* 1 frame per packet */
468 p_stream->i_interpolated_pcr += (I64C(1000000) / p_stream->f_rate);
469 else if( p_stream->fmt.i_bitrate )
470 p_stream->i_interpolated_pcr +=
471 ( p_oggpacket->bytes * I64C(1000000) /
472 p_stream->fmt.i_bitrate / 8 );
476 /****************************************************************************
477 * Ogg_DecodePacket: Decode an Ogg packet.
478 ****************************************************************************/
479 static void Ogg_DecodePacket( demux_t *p_demux,
480 logical_stream_t *p_stream,
481 ogg_packet *p_oggpacket )
484 vlc_bool_t b_selected;
485 int i_header_len = 0;
486 mtime_t i_pts = -1, i_interpolated_pts;
489 if( !p_oggpacket->bytes )
491 msg_Dbg( p_demux, "discarding 0 sized packet" );
495 if( p_oggpacket->bytes >= 7 &&
496 ! memcmp ( p_oggpacket->packet, "Annodex", 7 ) )
498 /* it's an Annodex packet -- skip it (do nothing) */
501 else if( p_oggpacket->bytes >= 7 &&
502 ! memcmp ( p_oggpacket->packet, "AnxData", 7 ) )
504 /* it's an AnxData packet -- skip it (do nothing) */
508 if( p_stream->fmt.i_codec == VLC_FOURCC( 's','u','b','t' ) &&
509 p_oggpacket->packet[0] & PACKET_TYPE_BITS ) return;
511 /* Check the ES is selected */
512 es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE,
513 p_stream->p_es, &b_selected );
515 if( p_stream->b_force_backup )
518 vlc_bool_t b_store_size = VLC_TRUE;
520 p_stream->i_packets_backup++;
521 switch( p_stream->fmt.i_codec )
523 case VLC_FOURCC( 'v','o','r','b' ):
524 case VLC_FOURCC( 's','p','x',' ' ):
525 case VLC_FOURCC( 't','h','e','o' ):
526 if( p_stream->i_packets_backup == 3 ) p_stream->b_force_backup = 0;
529 case VLC_FOURCC( 'f','l','a','c' ):
530 if( !p_stream->fmt.audio.i_rate && p_stream->i_packets_backup == 2 )
532 Ogg_ReadFlacHeader( p_demux, p_stream, p_oggpacket );
533 p_stream->b_force_backup = 0;
535 else if( p_stream->fmt.audio.i_rate )
537 p_stream->b_force_backup = 0;
538 if( p_oggpacket->bytes >= 9 )
540 p_oggpacket->packet += 9;
541 p_oggpacket->bytes -= 9;
544 b_store_size = VLC_FALSE;
548 p_stream->b_force_backup = 0;
552 /* Backup the ogg packet (likely an header packet) */
553 p_stream->p_headers =
554 realloc( p_stream->p_headers, p_stream->i_headers +
555 p_oggpacket->bytes + (b_store_size ? 2 : 0) );
556 p_extra = p_stream->p_headers + p_stream->i_headers;
559 *(p_extra++) = p_oggpacket->bytes >> 8;
560 *(p_extra++) = p_oggpacket->bytes & 0xFF;
562 memcpy( p_extra, p_oggpacket->packet, p_oggpacket->bytes );
563 p_stream->i_headers += p_oggpacket->bytes + (b_store_size ? 2 : 0);
565 if( !p_stream->b_force_backup )
567 /* Last header received, commit changes */
568 p_stream->fmt.i_extra = p_stream->i_headers;
569 p_stream->fmt.p_extra =
570 realloc( p_stream->fmt.p_extra, p_stream->i_headers );
571 memcpy( p_stream->fmt.p_extra, p_stream->p_headers,
572 p_stream->i_headers );
573 es_out_Control( p_demux->out, ES_OUT_SET_FMT,
574 p_stream->p_es, &p_stream->fmt );
577 b_selected = VLC_FALSE; /* Discard the header packet */
580 /* Convert the pcr into a pts */
581 if( p_stream->fmt.i_codec == VLC_FOURCC( 'v','o','r','b' ) ||
582 p_stream->fmt.i_codec == VLC_FOURCC( 's','p','x',' ' ) ||
583 p_stream->fmt.i_codec == VLC_FOURCC( 'f','l','a','c' ) )
585 if( p_stream->i_pcr >= 0 )
587 /* This is for streams where the granulepos of the header packets
588 * doesn't match these of the data packets (eg. ogg web radios). */
589 if( p_stream->i_previous_pcr == 0 &&
590 p_stream->i_pcr > 3 * DEFAULT_PTS_DELAY )
592 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
594 /* Call the pace control */
595 es_out_Control( p_demux->out, ES_OUT_SET_PCR,
599 p_stream->i_previous_pcr = p_stream->i_pcr;
601 /* The granulepos is the end date of the sample */
602 i_pts = p_stream->i_pcr;
606 /* Convert the granulepos into the next pcr */
607 i_interpolated_pts = p_stream->i_interpolated_pcr;
608 Ogg_UpdatePCR( p_stream, p_oggpacket );
610 if( p_stream->i_pcr >= 0 )
612 /* This is for streams where the granulepos of the header packets
613 * doesn't match these of the data packets (eg. ogg web radios). */
614 if( p_stream->i_previous_pcr == 0 &&
615 p_stream->i_pcr > 3 * DEFAULT_PTS_DELAY )
617 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
619 /* Call the pace control */
620 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_stream->i_pcr );
624 if( p_stream->fmt.i_codec != VLC_FOURCC( 'v','o','r','b' ) &&
625 p_stream->fmt.i_codec != VLC_FOURCC( 's','p','x',' ' ) &&
626 p_stream->fmt.i_codec != VLC_FOURCC( 'f','l','a','c' ) &&
627 p_stream->i_pcr >= 0 )
629 p_stream->i_previous_pcr = p_stream->i_pcr;
631 /* The granulepos is the start date of the sample */
632 i_pts = p_stream->i_pcr;
637 /* This stream isn't currently selected so we don't need to decode it,
638 * but we did need to store its pcr as it might be selected later on */
642 if( p_oggpacket->bytes <= 0 )
645 if( !( p_block = block_New( p_demux, p_oggpacket->bytes ) ) ) return;
648 if( i_pts == 0 ) i_pts = 1;
649 else if( i_pts == -1 && i_interpolated_pts == 0 ) i_pts = 1;
650 else if( i_pts == -1 ) i_pts = 0;
652 if( p_stream->fmt.i_cat == AUDIO_ES )
653 p_block->i_dts = p_block->i_pts = i_pts;
654 else if( p_stream->fmt.i_cat == SPU_ES )
656 p_block->i_dts = p_block->i_pts = i_pts;
657 p_block->i_length = 0;
659 else if( p_stream->fmt.i_codec == VLC_FOURCC( 't','h','e','o' ) )
660 p_block->i_dts = p_block->i_pts = i_pts;
663 p_block->i_dts = i_pts;
667 if( p_stream->fmt.i_codec != VLC_FOURCC( 'v','o','r','b' ) &&
668 p_stream->fmt.i_codec != VLC_FOURCC( 's','p','x',' ' ) &&
669 p_stream->fmt.i_codec != VLC_FOURCC( 'f','l','a','c' ) &&
670 p_stream->fmt.i_codec != VLC_FOURCC( 't','a','r','k' ) &&
671 p_stream->fmt.i_codec != VLC_FOURCC( 't','h','e','o' ) &&
672 p_stream->fmt.i_codec != VLC_FOURCC( 'c','m','m','l' ) )
674 /* We remove the header from the packet */
675 i_header_len = (*p_oggpacket->packet & PACKET_LEN_BITS01) >> 6;
676 i_header_len |= (*p_oggpacket->packet & PACKET_LEN_BITS2) << 1;
678 if( p_stream->fmt.i_codec == VLC_FOURCC( 's','u','b','t' ))
680 /* But with subtitles we need to retrieve the duration first */
683 if( i_header_len > 0 && p_oggpacket->bytes >= i_header_len + 1 )
685 for( i = 0, lenbytes = 0; i < i_header_len; i++ )
687 lenbytes = lenbytes << 8;
688 lenbytes += *(p_oggpacket->packet + i_header_len - i);
691 if( p_oggpacket->bytes - 1 - i_header_len > 2 ||
692 ( p_oggpacket->packet[i_header_len + 1] != ' ' &&
693 p_oggpacket->packet[i_header_len + 1] != 0 &&
694 p_oggpacket->packet[i_header_len + 1] != '\n' &&
695 p_oggpacket->packet[i_header_len + 1] != '\r' ) )
697 p_block->i_length = (mtime_t)lenbytes * 1000;
702 if( p_block->i_buffer >= (unsigned int)i_header_len )
703 p_block->i_buffer -= i_header_len;
705 p_block->i_buffer = 0;
708 if( p_stream->fmt.i_codec == VLC_FOURCC( 't','a','r','k' ) )
710 /* FIXME: the biggest hack I've ever done */
711 msg_Warn( p_demux, "tarkin pts: "I64Fd", granule: "I64Fd,
712 p_block->i_pts, p_block->i_dts );
716 memcpy( p_block->p_buffer, p_oggpacket->packet + i_header_len,
717 p_oggpacket->bytes - i_header_len );
719 es_out_Send( p_demux->out, p_stream->p_es, p_block );
722 /****************************************************************************
723 * Ogg_FindLogicalStreams: Find the logical streams embedded in the physical
724 * stream and fill p_ogg.
725 *****************************************************************************
726 * The initial page of a logical stream is marked as a 'bos' page.
727 * Furthermore, the Ogg specification mandates that grouped bitstreams begin
728 * together and all of the initial pages must appear before any data pages.
730 * On success this function returns VLC_SUCCESS.
731 ****************************************************************************/
732 static int Ogg_FindLogicalStreams( demux_t *p_demux )
734 demux_sys_t *p_ogg = p_demux->p_sys ;
735 ogg_packet oggpacket;
739 #define p_stream p_ogg->pp_stream[p_ogg->i_streams - 1]
741 while( Ogg_ReadPage( p_demux, &oggpage ) == VLC_SUCCESS )
743 if( ogg_page_bos( &oggpage ) )
746 /* All is wonderful in our fine fine little world.
747 * We found the beginning of our first logical stream. */
748 while( ogg_page_bos( &oggpage ) )
752 realloc( p_ogg->pp_stream, p_ogg->i_streams *
753 sizeof(logical_stream_t *) );
755 p_stream = malloc( sizeof(logical_stream_t) );
756 memset( p_stream, 0, sizeof(logical_stream_t) );
757 p_stream->p_headers = 0;
758 p_stream->secondary_header_packets = 0;
760 es_format_Init( &p_stream->fmt, 0, 0 );
762 /* Setup the logical stream */
763 p_stream->i_serial_no = ogg_page_serialno( &oggpage );
764 ogg_stream_init( &p_stream->os, p_stream->i_serial_no );
766 /* Extract the initial header from the first page and verify
767 * the codec type of tis Ogg bitstream */
768 if( ogg_stream_pagein( &p_stream->os, &oggpage ) < 0 )
770 /* error. stream version mismatch perhaps */
771 msg_Err( p_demux, "error reading first page of "
772 "Ogg bitstream data" );
776 /* FIXME: check return value */
777 ogg_stream_packetpeek( &p_stream->os, &oggpacket );
779 /* Check for Vorbis header */
780 if( oggpacket.bytes >= 7 &&
781 ! memcmp( oggpacket.packet, "\x01vorbis", 6 ) )
783 Ogg_ReadVorbisHeader( p_stream, &oggpacket );
784 msg_Dbg( p_demux, "found vorbis header" );
786 /* Check for Speex header */
787 else if( oggpacket.bytes >= 7 &&
788 ! memcmp( oggpacket.packet, "Speex", 5 ) )
790 Ogg_ReadSpeexHeader( p_stream, &oggpacket );
791 msg_Dbg( p_demux, "found speex header, channels: %i, "
792 "rate: %i, bitrate: %i",
793 p_stream->fmt.audio.i_channels,
794 (int)p_stream->f_rate, p_stream->fmt.i_bitrate );
796 /* Check for Flac header (< version 1.1.1) */
797 else if( oggpacket.bytes >= 4 &&
798 ! memcmp( oggpacket.packet, "fLaC", 4 ) )
800 msg_Dbg( p_demux, "found FLAC header" );
802 /* Grrrr!!!! Did they really have to put all the
803 * important info in the second header packet!!!
804 * (STREAMINFO metadata is in the following packet) */
805 p_stream->b_force_backup = 1;
807 p_stream->fmt.i_cat = AUDIO_ES;
808 p_stream->fmt.i_codec = VLC_FOURCC( 'f','l','a','c' );
810 /* Check for Flac header (>= version 1.1.1) */
811 else if( oggpacket.bytes >= 13 && oggpacket.packet[0] ==0x7F &&
812 ! memcmp( &oggpacket.packet[1], "FLAC", 4 ) &&
813 ! memcmp( &oggpacket.packet[9], "fLaC", 4 ) )
815 int i_packets = ((int)oggpacket.packet[7]) << 8 |
817 msg_Dbg( p_demux, "found FLAC header version %i.%i "
818 "(%i header packets)",
819 oggpacket.packet[5], oggpacket.packet[6],
822 p_stream->b_force_backup = 1;
824 p_stream->fmt.i_cat = AUDIO_ES;
825 p_stream->fmt.i_codec = VLC_FOURCC( 'f','l','a','c' );
826 oggpacket.packet += 13; oggpacket.bytes -= 13;
827 Ogg_ReadFlacHeader( p_demux, p_stream, &oggpacket );
829 /* Check for Theora header */
830 else if( oggpacket.bytes >= 7 &&
831 ! memcmp( oggpacket.packet, "\x80theora", 6 ) )
833 Ogg_ReadTheoraHeader( p_stream, &oggpacket );
836 "found theora header, bitrate: %i, rate: %f",
837 p_stream->fmt.i_bitrate, p_stream->f_rate );
839 /* Check for Tarkin header */
840 else if( oggpacket.bytes >= 7 &&
841 ! memcmp( &oggpacket.packet[1], "tarkin", 6 ) )
845 msg_Dbg( p_demux, "found tarkin header" );
846 p_stream->fmt.i_cat = VIDEO_ES;
847 p_stream->fmt.i_codec = VLC_FOURCC( 't','a','r','k' );
849 /* Cheat and get additionnal info ;) */
850 oggpack_readinit( &opb, oggpacket.packet, oggpacket.bytes);
851 oggpack_adv( &opb, 88 );
852 oggpack_adv( &opb, 104 );
853 p_stream->fmt.i_bitrate = oggpack_read( &opb, 32 );
854 p_stream->f_rate = 2; /* FIXME */
856 "found tarkin header, bitrate: %i, rate: %f",
857 p_stream->fmt.i_bitrate, p_stream->f_rate );
859 /* Check for Annodex header */
860 else if( oggpacket.bytes >= 7 &&
861 ! memcmp( oggpacket.packet, "Annodex", 7 ) )
863 Ogg_ReadAnnodexHeader( VLC_OBJECT(p_demux), p_stream,
865 /* kill annodex track */
869 /* Check for Annodex header */
870 else if( oggpacket.bytes >= 7 &&
871 ! memcmp( oggpacket.packet, "AnxData", 7 ) )
873 Ogg_ReadAnnodexHeader( VLC_OBJECT(p_demux), p_stream,
876 else if( oggpacket.bytes >= 142 &&
877 !memcmp( &oggpacket.packet[1],
878 "Direct Show Samples embedded in Ogg", 35 ))
880 /* Old header type */
882 /* Check for video header (old format) */
883 if( GetDWLE((oggpacket.packet+96)) == 0x05589f80 &&
884 oggpacket.bytes >= 184 )
886 p_stream->fmt.i_cat = VIDEO_ES;
887 p_stream->fmt.i_codec =
888 VLC_FOURCC( oggpacket.packet[68],
889 oggpacket.packet[69],
890 oggpacket.packet[70],
891 oggpacket.packet[71] );
892 msg_Dbg( p_demux, "found video header of type: %.4s",
893 (char *)&p_stream->fmt.i_codec );
895 p_stream->fmt.video.i_frame_rate = 10000000;
896 p_stream->fmt.video.i_frame_rate_base =
897 GetQWLE((oggpacket.packet+164));
898 p_stream->f_rate = 10000000.0 /
899 GetQWLE((oggpacket.packet+164));
900 p_stream->fmt.video.i_bits_per_pixel =
901 GetWLE((oggpacket.packet+182));
902 if( !p_stream->fmt.video.i_bits_per_pixel )
904 p_stream->fmt.video.i_bits_per_pixel = 24;
905 p_stream->fmt.video.i_width =
906 GetDWLE((oggpacket.packet+176));
907 p_stream->fmt.video.i_height =
908 GetDWLE((oggpacket.packet+180));
911 "fps: %f, width:%i; height:%i, bitcount:%i",
913 p_stream->fmt.video.i_width,
914 p_stream->fmt.video.i_height,
915 p_stream->fmt.video.i_bits_per_pixel);
918 /* Check for audio header (old format) */
919 else if( GetDWLE((oggpacket.packet+96)) == 0x05589F81 )
921 unsigned int i_extra_size;
922 unsigned int i_format_tag;
924 p_stream->fmt.i_cat = AUDIO_ES;
926 i_extra_size = GetWLE((oggpacket.packet+140));
929 p_stream->fmt.i_extra = i_extra_size;
930 p_stream->fmt.p_extra = malloc( i_extra_size );
931 memcpy( p_stream->fmt.p_extra,
932 oggpacket.packet + 142, i_extra_size );
935 i_format_tag = GetWLE((oggpacket.packet+124));
936 p_stream->fmt.audio.i_channels =
937 GetWLE((oggpacket.packet+126));
938 p_stream->f_rate = p_stream->fmt.audio.i_rate =
939 GetDWLE((oggpacket.packet+128));
940 p_stream->fmt.i_bitrate =
941 GetDWLE((oggpacket.packet+132)) * 8;
942 p_stream->fmt.audio.i_blockalign =
943 GetWLE((oggpacket.packet+136));
944 p_stream->fmt.audio.i_bitspersample =
945 GetWLE((oggpacket.packet+138));
947 wf_tag_to_fourcc( i_format_tag,
948 &p_stream->fmt.i_codec, 0 );
950 if( p_stream->fmt.i_codec ==
951 VLC_FOURCC('u','n','d','f') )
953 p_stream->fmt.i_codec = VLC_FOURCC( 'm', 's',
954 ( i_format_tag >> 8 ) & 0xff,
955 i_format_tag & 0xff );
958 msg_Dbg( p_demux, "found audio header of type: %.4s",
959 (char *)&p_stream->fmt.i_codec );
960 msg_Dbg( p_demux, "audio:0x%4.4x channels:%d %dHz "
961 "%dbits/sample %dkb/s",
963 p_stream->fmt.audio.i_channels,
964 p_stream->fmt.audio.i_rate,
965 p_stream->fmt.audio.i_bitspersample,
966 p_stream->fmt.i_bitrate / 1024 );
971 msg_Dbg( p_demux, "stream %d has an old header "
972 "but is of an unknown type", p_ogg->i_streams-1 );
977 else if( (*oggpacket.packet & PACKET_TYPE_BITS )
978 == PACKET_TYPE_HEADER &&
979 oggpacket.bytes >= (int)sizeof(stream_header)+1 )
981 stream_header *st = (stream_header *)(oggpacket.packet+1);
983 /* Check for video header (new format) */
984 if( !strncmp( st->streamtype, "video", 5 ) )
986 p_stream->fmt.i_cat = VIDEO_ES;
988 /* We need to get rid of the header packet */
989 ogg_stream_packetout( &p_stream->os, &oggpacket );
991 p_stream->fmt.i_codec =
992 VLC_FOURCC( st->subtype[0], st->subtype[1],
993 st->subtype[2], st->subtype[3] );
994 msg_Dbg( p_demux, "found video header of type: %.4s",
995 (char *)&p_stream->fmt.i_codec );
997 p_stream->fmt.video.i_frame_rate = 10000000;
998 p_stream->fmt.video.i_frame_rate_base =
999 GetQWLE(&st->time_unit);
1000 p_stream->f_rate = 10000000.0 /
1001 GetQWLE(&st->time_unit);
1002 p_stream->fmt.video.i_bits_per_pixel =
1003 GetWLE(&st->bits_per_sample);
1004 p_stream->fmt.video.i_width =
1005 GetDWLE(&st->sh.video.width);
1006 p_stream->fmt.video.i_height =
1007 GetDWLE(&st->sh.video.height);
1010 "fps: %f, width:%i; height:%i, bitcount:%i",
1012 p_stream->fmt.video.i_width,
1013 p_stream->fmt.video.i_height,
1014 p_stream->fmt.video.i_bits_per_pixel );
1016 /* Check for audio header (new format) */
1017 else if( !strncmp( st->streamtype, "audio", 5 ) )
1022 p_stream->fmt.i_cat = AUDIO_ES;
1024 /* We need to get rid of the header packet */
1025 ogg_stream_packetout( &p_stream->os, &oggpacket );
1027 p_stream->fmt.i_extra = GetQWLE(&st->size) -
1028 sizeof(stream_header);
1029 if( p_stream->fmt.i_extra )
1031 p_stream->fmt.p_extra =
1032 malloc( p_stream->fmt.i_extra );
1033 memcpy( p_stream->fmt.p_extra, st + 1,
1034 p_stream->fmt.i_extra );
1037 memcpy( p_buffer, st->subtype, 4 );
1039 i_format_tag = strtol(p_buffer,NULL,16);
1040 p_stream->fmt.audio.i_channels =
1041 GetWLE(&st->sh.audio.channels);
1042 p_stream->f_rate = p_stream->fmt.audio.i_rate =
1043 GetQWLE(&st->samples_per_unit);
1044 p_stream->fmt.i_bitrate =
1045 GetDWLE(&st->sh.audio.avgbytespersec) * 8;
1046 p_stream->fmt.audio.i_blockalign =
1047 GetWLE(&st->sh.audio.blockalign);
1048 p_stream->fmt.audio.i_bitspersample =
1049 GetWLE(&st->bits_per_sample);
1051 wf_tag_to_fourcc( i_format_tag,
1052 &p_stream->fmt.i_codec, 0 );
1054 if( p_stream->fmt.i_codec ==
1055 VLC_FOURCC('u','n','d','f') )
1057 p_stream->fmt.i_codec = VLC_FOURCC( 'm', 's',
1058 ( i_format_tag >> 8 ) & 0xff,
1059 i_format_tag & 0xff );
1062 msg_Dbg( p_demux, "found audio header of type: %.4s",
1063 (char *)&p_stream->fmt.i_codec );
1064 msg_Dbg( p_demux, "audio:0x%4.4x channels:%d %dHz "
1065 "%dbits/sample %dkb/s",
1067 p_stream->fmt.audio.i_channels,
1068 p_stream->fmt.audio.i_rate,
1069 p_stream->fmt.audio.i_bitspersample,
1070 p_stream->fmt.i_bitrate / 1024 );
1072 /* Check for text (subtitles) header */
1073 else if( !strncmp(st->streamtype, "text", 4) )
1075 /* We need to get rid of the header packet */
1076 ogg_stream_packetout( &p_stream->os, &oggpacket );
1078 msg_Dbg( p_demux, "found text subtitles header" );
1079 p_stream->fmt.i_cat = SPU_ES;
1080 p_stream->fmt.i_codec = VLC_FOURCC('s','u','b','t');
1081 p_stream->f_rate = 1000; /* granulepos is in milisec */
1085 msg_Dbg( p_demux, "stream %d has a header marker "
1086 "but is of an unknown type", p_ogg->i_streams-1 );
1091 else if( oggpacket.bytes >= 7 &&
1092 ! memcmp( oggpacket.packet, "fishead", 7 ) )
1096 msg_Dbg( p_demux, "stream %d is a skeleton",
1097 p_ogg->i_streams-1 );
1098 /* FIXME: https://trac.videolan.org/vlc/ticket/1412 */
1102 msg_Dbg( p_demux, "stream %d is of unknown type",
1103 p_ogg->i_streams-1 );
1108 if( Ogg_ReadPage( p_demux, &oggpage ) != VLC_SUCCESS )
1109 return VLC_EGENERIC;
1112 /* This is the first data page, which means we are now finished
1113 * with the initial pages. We just need to store it in the relevant
1115 for( i_stream = 0; i_stream < p_ogg->i_streams; i_stream++ )
1117 if( ogg_stream_pagein( &p_ogg->pp_stream[i_stream]->os,
1129 return VLC_EGENERIC;
1132 /****************************************************************************
1133 * Ogg_BeginningOfStream: Look for Beginning of Stream ogg pages and add
1134 * Elementary streams.
1135 ****************************************************************************/
1136 static int Ogg_BeginningOfStream( demux_t *p_demux )
1138 demux_sys_t *p_ogg = p_demux->p_sys ;
1141 /* Find the logical streams embedded in the physical stream and
1142 * initialize our p_ogg structure. */
1143 if( Ogg_FindLogicalStreams( p_demux ) != VLC_SUCCESS )
1145 msg_Warn( p_demux, "couldn't find any ogg logical stream" );
1146 return VLC_EGENERIC;
1149 p_ogg->i_bitrate = 0;
1151 for( i_stream = 0 ; i_stream < p_ogg->i_streams; i_stream++ )
1153 #define p_stream p_ogg->pp_stream[i_stream]
1154 p_stream->p_es = es_out_Add( p_demux->out, &p_stream->fmt );
1156 if( p_stream->fmt.i_codec == VLC_FOURCC('c','m','m','l') )
1158 /* Set the CMML stream active */
1159 es_out_Control( p_demux->out, ES_OUT_SET_ES, p_stream->p_es );
1162 p_ogg->i_bitrate += p_stream->fmt.i_bitrate;
1164 p_stream->i_pcr = p_stream->i_previous_pcr =
1165 p_stream->i_interpolated_pcr = -1;
1166 p_stream->b_reinit = 0;
1173 /****************************************************************************
1174 * Ogg_EndOfStream: clean up the ES when an End of Stream is detected.
1175 ****************************************************************************/
1176 static void Ogg_EndOfStream( demux_t *p_demux )
1178 demux_sys_t *p_ogg = p_demux->p_sys ;
1181 #define p_stream p_ogg->pp_stream[i_stream]
1182 for( i_stream = 0 ; i_stream < p_ogg->i_streams; i_stream++ )
1184 if( p_stream->p_es )
1185 es_out_Del( p_demux->out, p_stream->p_es );
1187 p_ogg->i_bitrate -= p_stream->fmt.i_bitrate;
1189 ogg_stream_clear( &p_ogg->pp_stream[i_stream]->os );
1190 if( p_ogg->pp_stream[i_stream]->p_headers)
1191 free( p_ogg->pp_stream[i_stream]->p_headers );
1193 es_format_Clean( &p_stream->fmt );
1195 free( p_ogg->pp_stream[i_stream] );
1200 if( p_ogg->pp_stream ) free( p_ogg->pp_stream );
1201 p_ogg->pp_stream = NULL;
1202 p_ogg->i_streams = 0;
1205 static void Ogg_ReadTheoraHeader( logical_stream_t *p_stream,
1206 ogg_packet *p_oggpacket )
1209 int i_fps_numerator;
1210 int i_fps_denominator;
1211 int i_keyframe_frequency_force;
1213 p_stream->fmt.i_cat = VIDEO_ES;
1214 p_stream->fmt.i_codec = VLC_FOURCC( 't','h','e','o' );
1216 /* Signal that we want to keep a backup of the theora
1217 * stream headers. They will be used when switching between
1219 p_stream->b_force_backup = 1;
1221 /* Cheat and get additionnal info ;) */
1222 bs_init( &bitstream, p_oggpacket->packet, p_oggpacket->bytes );
1223 bs_skip( &bitstream, 56 );
1224 bs_read( &bitstream, 8 ); /* major version num */
1225 bs_read( &bitstream, 8 ); /* minor version num */
1226 bs_read( &bitstream, 8 ); /* subminor version num */
1227 bs_read( &bitstream, 16 ) /*<< 4*/; /* width */
1228 bs_read( &bitstream, 16 ) /*<< 4*/; /* height */
1229 bs_read( &bitstream, 24 ); /* frame width */
1230 bs_read( &bitstream, 24 ); /* frame height */
1231 bs_read( &bitstream, 8 ); /* x offset */
1232 bs_read( &bitstream, 8 ); /* y offset */
1234 i_fps_numerator = bs_read( &bitstream, 32 );
1235 i_fps_denominator = bs_read( &bitstream, 32 );
1236 bs_read( &bitstream, 24 ); /* aspect_numerator */
1237 bs_read( &bitstream, 24 ); /* aspect_denominator */
1239 p_stream->fmt.video.i_frame_rate = i_fps_numerator;
1240 p_stream->fmt.video.i_frame_rate_base = i_fps_denominator;
1242 bs_read( &bitstream, 8 ); /* colorspace */
1243 p_stream->fmt.i_bitrate = bs_read( &bitstream, 24 );
1244 bs_read( &bitstream, 6 ); /* quality */
1246 i_keyframe_frequency_force = 1 << bs_read( &bitstream, 5 );
1248 /* granule_shift = i_log( frequency_force -1 ) */
1249 p_stream->i_theora_keyframe_granule_shift = 0;
1250 i_keyframe_frequency_force--;
1251 while( i_keyframe_frequency_force )
1253 p_stream->i_theora_keyframe_granule_shift++;
1254 i_keyframe_frequency_force >>= 1;
1257 p_stream->f_rate = ((float)i_fps_numerator) / i_fps_denominator;
1260 static void Ogg_ReadVorbisHeader( logical_stream_t *p_stream,
1261 ogg_packet *p_oggpacket )
1265 p_stream->fmt.i_cat = AUDIO_ES;
1266 p_stream->fmt.i_codec = VLC_FOURCC( 'v','o','r','b' );
1268 /* Signal that we want to keep a backup of the vorbis
1269 * stream headers. They will be used when switching between
1271 p_stream->b_force_backup = 1;
1273 /* Cheat and get additionnal info ;) */
1274 oggpack_readinit( &opb, p_oggpacket->packet, p_oggpacket->bytes);
1275 oggpack_adv( &opb, 88 );
1276 p_stream->fmt.audio.i_channels = oggpack_read( &opb, 8 );
1277 p_stream->f_rate = p_stream->fmt.audio.i_rate =
1278 oggpack_read( &opb, 32 );
1279 oggpack_adv( &opb, 32 );
1280 p_stream->fmt.i_bitrate = oggpack_read( &opb, 32 );
1283 static void Ogg_ReadSpeexHeader( logical_stream_t *p_stream,
1284 ogg_packet *p_oggpacket )
1288 p_stream->fmt.i_cat = AUDIO_ES;
1289 p_stream->fmt.i_codec = VLC_FOURCC( 's','p','x',' ' );
1291 /* Signal that we want to keep a backup of the speex
1292 * stream headers. They will be used when switching between
1294 p_stream->b_force_backup = 1;
1296 /* Cheat and get additionnal info ;) */
1297 oggpack_readinit( &opb, p_oggpacket->packet, p_oggpacket->bytes);
1298 oggpack_adv( &opb, 224 );
1299 oggpack_adv( &opb, 32 ); /* speex_version_id */
1300 oggpack_adv( &opb, 32 ); /* header_size */
1301 p_stream->f_rate = p_stream->fmt.audio.i_rate = oggpack_read( &opb, 32 );
1302 oggpack_adv( &opb, 32 ); /* mode */
1303 oggpack_adv( &opb, 32 ); /* mode_bitstream_version */
1304 p_stream->fmt.audio.i_channels = oggpack_read( &opb, 32 );
1305 p_stream->fmt.i_bitrate = oggpack_read( &opb, 32 );
1308 static void Ogg_ReadFlacHeader( demux_t *p_demux, logical_stream_t *p_stream,
1309 ogg_packet *p_oggpacket )
1311 /* Parse the STREAMINFO metadata */
1314 bs_init( &s, p_oggpacket->packet, p_oggpacket->bytes );
1317 if( bs_read( &s, 7 ) == 0 )
1319 if( bs_read( &s, 24 ) >= 34 /*size STREAMINFO*/ )
1322 p_stream->f_rate = p_stream->fmt.audio.i_rate = bs_read( &s, 20 );
1323 p_stream->fmt.audio.i_channels = bs_read( &s, 3 ) + 1;
1325 msg_Dbg( p_demux, "FLAC header, channels: %i, rate: %i",
1326 p_stream->fmt.audio.i_channels, (int)p_stream->f_rate );
1328 else msg_Dbg( p_demux, "FLAC STREAMINFO metadata too short" );
1330 /* Fake this as the last metadata block */
1331 *((uint8_t*)p_oggpacket->packet) |= 0x80;
1335 /* This ain't a STREAMINFO metadata */
1336 msg_Dbg( p_demux, "Invalid FLAC STREAMINFO metadata" );
1340 static void Ogg_ReadAnnodexHeader( vlc_object_t *p_this,
1341 logical_stream_t *p_stream,
1342 ogg_packet *p_oggpacket )
1344 if( p_oggpacket->bytes >= 28 &&
1345 !memcmp( p_oggpacket->packet, "Annodex", 7 ) )
1349 uint16_t major_version;
1350 uint16_t minor_version;
1351 uint64_t timebase_numerator;
1352 uint64_t timebase_denominator;
1354 Ogg_ReadTheoraHeader( p_stream, p_oggpacket );
1356 oggpack_readinit( &opb, p_oggpacket->packet, p_oggpacket->bytes);
1357 oggpack_adv( &opb, 8*8 ); /* "Annodex\0" header */
1358 major_version = oggpack_read( &opb, 2*8 ); /* major version */
1359 minor_version = oggpack_read( &opb, 2*8 ); /* minor version */
1360 timebase_numerator = GetQWLE( &p_oggpacket->packet[16] );
1361 timebase_denominator = GetQWLE( &p_oggpacket->packet[24] );
1363 else if( p_oggpacket->bytes >= 42 &&
1364 !memcmp( p_oggpacket->packet, "AnxData", 7 ) )
1366 uint64_t granule_rate_numerator;
1367 uint64_t granule_rate_denominator;
1368 char content_type_string[1024];
1370 /* Read in Annodex header fields */
1372 granule_rate_numerator = GetQWLE( &p_oggpacket->packet[8] );
1373 granule_rate_denominator = GetQWLE( &p_oggpacket->packet[16] );
1374 p_stream->secondary_header_packets =
1375 GetDWLE( &p_oggpacket->packet[24] );
1377 /* we are guaranteed that the first header field will be
1378 * the content-type (by the Annodex standard) */
1379 content_type_string[0] = '\0';
1380 if( !strncasecmp( (char*)(&p_oggpacket->packet[28]), "Content-Type: ", 14 ) )
1382 uint8_t *p = memchr( &p_oggpacket->packet[42], '\r',
1383 p_oggpacket->bytes - 1 );
1384 if( p && p[0] == '\r' && p[1] == '\n' )
1385 sscanf( (char*)(&p_oggpacket->packet[42]), "%1024s\r\n",
1386 content_type_string );
1389 msg_Dbg( p_this, "AnxData packet info: "I64Fd" / "I64Fd", %d, ``%s''",
1390 granule_rate_numerator, granule_rate_denominator,
1391 p_stream->secondary_header_packets, 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, "audio/x-speex", 14) )
1413 p_stream->fmt.i_cat = AUDIO_ES;
1414 p_stream->fmt.i_codec = VLC_FOURCC( 's','p','x',' ' );
1416 p_stream->b_force_backup = 1;
1418 else if( !strncmp(content_type_string, "video/x-theora", 14) )
1420 p_stream->fmt.i_cat = VIDEO_ES;
1421 p_stream->fmt.i_codec = VLC_FOURCC( 't','h','e','o' );
1423 p_stream->b_force_backup = 1;
1425 else if( !strncmp(content_type_string, "video/x-xvid", 14) )
1427 p_stream->fmt.i_cat = VIDEO_ES;
1428 p_stream->fmt.i_codec = VLC_FOURCC( 'x','v','i','d' );
1430 p_stream->b_force_backup = 1;
1432 else if( !strncmp(content_type_string, "video/mpeg", 14) )
1434 /* n.b. MPEG streams are unsupported right now */
1435 p_stream->fmt.i_cat = VIDEO_ES;
1436 p_stream->fmt.i_codec = VLC_FOURCC( 'm','p','g','v' );
1438 else if( !strncmp(content_type_string, "text/x-cmml", 11) )
1440 ogg_stream_packetout( &p_stream->os, p_oggpacket );
1441 p_stream->fmt.i_cat = SPU_ES;
1442 p_stream->fmt.i_codec = VLC_FOURCC( 'c','m','m','l' );