Commit bfe559d0 authored by ogg.k.ogg.k's avatar ogg.k.ogg.k Committed by Jean-Baptiste Kempf

add video streams' BOS packets first

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 6f2d1380
...@@ -619,87 +619,94 @@ static block_t *OggCreateHeader( sout_mux_t *p_mux ) ...@@ -619,87 +619,94 @@ static block_t *OggCreateHeader( sout_mux_t *p_mux )
/* Write header for each stream. All b_o_s (beginning of stream) packets /* Write header for each stream. All b_o_s (beginning of stream) packets
* must appear first in the ogg stream so we take care of them first. */ * must appear first in the ogg stream so we take care of them first. */
for( i = 0; i < p_mux->i_nb_inputs; i++ ) for( int pass = 0; pass < 2; pass++ )
{ {
sout_input_t *p_input = p_mux->pp_inputs[i]; for( i = 0; i < p_mux->i_nb_inputs; i++ )
ogg_stream_t *p_stream = (ogg_stream_t*)p_input->p_sys; {
p_stream->b_new = false; sout_input_t *p_input = p_mux->pp_inputs[i];
ogg_stream_t *p_stream = (ogg_stream_t*)p_input->p_sys;
msg_Dbg( p_mux, "creating header for %4.4s", bool video = ( p_stream->i_fourcc == VLC_CODEC_THEORA || p_stream->i_fourcc == VLC_CODEC_DIRAC );
(char *)&p_stream->i_fourcc ); if( ( ( pass == 0 && !video ) || ( pass == 1 && video ) ) )
continue;
ogg_stream_init( &p_stream->os, p_stream->i_serial_no ); msg_Dbg( p_mux, "creating header for %4.4s",
p_stream->i_packet_no = 0; (char *)&p_stream->i_fourcc );
if( p_stream->i_fourcc == VLC_CODEC_VORBIS || ogg_stream_init( &p_stream->os, p_stream->i_serial_no );
p_stream->i_fourcc == VLC_CODEC_SPEEX || p_stream->b_new = false;
p_stream->i_fourcc == VLC_CODEC_THEORA ) p_stream->i_packet_no = 0;
{
/* First packet in order: vorbis/speex/theora info */
p_extra = p_input->p_fmt->p_extra;
i_extra = p_input->p_fmt->i_extra;
op.bytes = *(p_extra++) << 8; if( p_stream->i_fourcc == VLC_CODEC_VORBIS ||
op.bytes |= (*(p_extra++) & 0xFF); p_stream->i_fourcc == VLC_CODEC_SPEEX ||
op.packet = p_extra; p_stream->i_fourcc == VLC_CODEC_THEORA )
i_extra -= (op.bytes + 2);
if( i_extra < 0 )
{ {
msg_Err( p_mux, "header data corrupted"); /* First packet in order: vorbis/speex/theora info */
op.bytes += i_extra; p_extra = p_input->p_fmt->p_extra;
} i_extra = p_input->p_fmt->i_extra;
op.b_o_s = 1; op.bytes = *(p_extra++) << 8;
op.e_o_s = 0; op.bytes |= (*(p_extra++) & 0xFF);
op.granulepos = 0; op.packet = p_extra;
op.packetno = p_stream->i_packet_no++; i_extra -= (op.bytes + 2);
ogg_stream_packetin( &p_stream->os, &op ); if( i_extra < 0 )
p_og = OggStreamFlush( p_mux, &p_stream->os, 0 ); {
msg_Err( p_mux, "header data corrupted");
op.bytes += i_extra;
}
op.b_o_s = 1;
op.e_o_s = 0;
op.granulepos = 0;
op.packetno = p_stream->i_packet_no++;
ogg_stream_packetin( &p_stream->os, &op );
p_og = OggStreamFlush( p_mux, &p_stream->os, 0 );
/* Get keyframe_granule_shift for theora granulepos calculation */ /* Get keyframe_granule_shift for theora granulepos calculation */
if( p_stream->i_fourcc == VLC_CODEC_THEORA ) if( p_stream->i_fourcc == VLC_CODEC_THEORA )
{
p_stream->i_keyframe_granule_shift =
( (op.packet[40] & 0x03) << 3 ) | ( (op.packet[41] & 0xe0) >> 5 );
}
}
else if( p_stream->i_fourcc == VLC_CODEC_DIRAC )
{
op.packet = p_input->p_fmt->p_extra;
op.bytes = p_input->p_fmt->i_extra;
op.b_o_s = 1;
op.e_o_s = 0;
op.granulepos = ~0;
op.packetno = p_stream->i_packet_no++;
ogg_stream_packetin( &p_stream->os, &op );
p_og = OggStreamFlush( p_mux, &p_stream->os, 0 );
}
else if( p_stream->i_fourcc == VLC_CODEC_FLAC )
{ {
p_stream->i_keyframe_granule_shift = /* flac stream marker (yeah, only that in the 1st packet) */
( (op.packet[40] & 0x03) << 3 ) | ( (op.packet[41] & 0xe0) >> 5 ); op.packet = (unsigned char *)"fLaC";
op.bytes = 4;
op.b_o_s = 1;
op.e_o_s = 0;
op.granulepos = 0;
op.packetno = p_stream->i_packet_no++;
ogg_stream_packetin( &p_stream->os, &op );
p_og = OggStreamFlush( p_mux, &p_stream->os, 0 );
}
else if( p_stream->p_oggds_header )
{
/* ds header */
op.packet = (uint8_t*)p_stream->p_oggds_header;
op.bytes = p_stream->p_oggds_header->i_size + 1;
op.b_o_s = 1;
op.e_o_s = 0;
op.granulepos = 0;
op.packetno = p_stream->i_packet_no++;
ogg_stream_packetin( &p_stream->os, &op );
p_og = OggStreamFlush( p_mux, &p_stream->os, 0 );
} }
}
else if( p_stream->i_fourcc == VLC_CODEC_DIRAC )
{
op.packet = p_input->p_fmt->p_extra;
op.bytes = p_input->p_fmt->i_extra;
op.b_o_s = 1;
op.e_o_s = 0;
op.granulepos = ~0;
op.packetno = p_stream->i_packet_no++;
ogg_stream_packetin( &p_stream->os, &op );
p_og = OggStreamFlush( p_mux, &p_stream->os, 0 );
}
else if( p_stream->i_fourcc == VLC_CODEC_FLAC )
{
/* flac stream marker (yeah, only that in the 1st packet) */
op.packet = (unsigned char *)"fLaC";
op.bytes = 4;
op.b_o_s = 1;
op.e_o_s = 0;
op.granulepos = 0;
op.packetno = p_stream->i_packet_no++;
ogg_stream_packetin( &p_stream->os, &op );
p_og = OggStreamFlush( p_mux, &p_stream->os, 0 );
}
else if( p_stream->p_oggds_header )
{
/* ds header */
op.packet = (uint8_t*)p_stream->p_oggds_header;
op.bytes = p_stream->p_oggds_header->i_size + 1;
op.b_o_s = 1;
op.e_o_s = 0;
op.granulepos = 0;
op.packetno = p_stream->i_packet_no++;
ogg_stream_packetin( &p_stream->os, &op );
p_og = OggStreamFlush( p_mux, &p_stream->os, 0 );
}
block_ChainAppend( &p_hdr, p_og ); block_ChainAppend( &p_hdr, p_og );
}
} }
/* Take care of the non b_o_s headers */ /* Take care of the non b_o_s headers */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment