Commit 8917116d authored by Rafaël Carré's avatar Rafaël Carré

TS mux: reduce indentation

parent c42b122e
...@@ -1271,263 +1271,249 @@ static int Mux( sout_mux_t *p_mux ) ...@@ -1271,263 +1271,249 @@ static int Mux( sout_mux_t *p_mux )
for (;;) for (;;)
{ {
sout_buffer_chain_t chain_ts; sout_buffer_chain_t chain_ts;
int i_packet_count; mtime_t i_shaping_delay = p_pcr_stream->b_key_frame
int i_packet_pos; ? p_pcr_stream->i_pes_length
mtime_t i_pcr_dts; : p_sys->i_shaping_delay;
mtime_t i_pcr_length;
mtime_t i_shaping_delay;
if( p_pcr_stream->b_key_frame ) bool b_ok = true;
{
i_shaping_delay = p_pcr_stream->i_pes_length;
}
else
{
i_shaping_delay = p_sys->i_shaping_delay;
}
/* 1: get enough PES packet for all input */ /* Accumulate enough data in the pcr stream (>i_shaping_delay) */
for (;;) /* Accumulate enough data in all other stream ( >= length of pcr)*/
for (int i = -1; !b_ok || i < p_mux->i_nb_inputs; i++ )
{ {
bool b_ok = true; if (i == p_mux->i_nb_inputs)
/* Accumulate enough data in the pcr stream (>i_shaping_delay) */
/* Accumulate enough data in all other stream ( >= length of pcr)*/
for (int i = -1; i < p_mux->i_nb_inputs; i++ )
{ {
sout_input_t *p_input; /* get enough PES packet for all input */
ts_stream_t *p_stream; b_ok = true;
int64_t i_spu_delay = 0; i = -1;
}
sout_input_t *p_input;
ts_stream_t *p_stream;
int64_t i_spu_delay = 0;
if( i == -1 ) if( i == -1 )
p_input = p_sys->p_pcr_input; p_input = p_sys->p_pcr_input;
else if( p_mux->pp_inputs[i]->p_sys == p_pcr_stream ) else if( p_mux->pp_inputs[i]->p_sys == p_pcr_stream )
continue; continue;
else else
p_input = p_mux->pp_inputs[i]; p_input = p_mux->pp_inputs[i];
p_stream = (ts_stream_t*)p_input->p_sys; p_stream = (ts_stream_t*)p_input->p_sys;
if( ( ( p_stream == p_pcr_stream ) && if( ( ( p_stream == p_pcr_stream ) &&
( p_stream->i_pes_length < i_shaping_delay ) ) || ( p_stream->i_pes_length < i_shaping_delay ) ) ||
( p_stream->i_pes_dts + p_stream->i_pes_length < ( p_stream->i_pes_dts + p_stream->i_pes_length <
p_pcr_stream->i_pes_dts + p_pcr_stream->i_pes_length ) ) p_pcr_stream->i_pes_dts + p_pcr_stream->i_pes_length ) )
{
/* Need more data */
if( block_FifoCount( p_input->p_fifo ) <= 1 )
{ {
/* Need more data */ if( ( p_input->p_fmt->i_cat == AUDIO_ES ) ||
if( block_FifoCount( p_input->p_fifo ) <= 1 ) ( p_input->p_fmt->i_cat == VIDEO_ES ) )
{ {
if( ( p_input->p_fmt->i_cat == AUDIO_ES ) || /* We need more data */
( p_input->p_fmt->i_cat == VIDEO_ES ) ) return VLC_SUCCESS;
{ }
/* We need more data */ else if( block_FifoCount( p_input->p_fifo ) <= 0 )
return VLC_SUCCESS; {
} /* spu, only one packet is needed */
else if( block_FifoCount( p_input->p_fifo ) <= 0 ) continue;
{ }
/* spu, only one packet is needed */ else if( p_input->p_fmt->i_cat == SPU_ES )
continue; {
} /* Don't mux the SPU yet if it is too early */
else if( p_input->p_fmt->i_cat == SPU_ES ) block_t *p_spu = block_FifoShow( p_input->p_fifo );
{
/* Don't mux the SPU yet if it is too early */
block_t *p_spu = block_FifoShow( p_input->p_fifo );
i_spu_delay = i_spu_delay =
p_spu->i_dts - p_pcr_stream->i_pes_dts; p_spu->i_dts - p_pcr_stream->i_pes_dts;
if( ( i_spu_delay > i_shaping_delay ) && if( ( i_spu_delay > i_shaping_delay ) &&
( i_spu_delay < INT64_C(100000000) ) ) ( i_spu_delay < INT64_C(100000000) ) )
continue; continue;
if ( ( i_spu_delay >= INT64_C(100000000) ) || if ( ( i_spu_delay >= INT64_C(100000000) ) ||
( i_spu_delay < INT64_C(10000) ) ) ( i_spu_delay < INT64_C(10000) ) )
{ {
BufferChainClean( &p_stream->chain_pes ); BufferChainClean( &p_stream->chain_pes );
p_stream->i_pes_dts = 0; p_stream->i_pes_dts = 0;
p_stream->i_pes_used = 0; p_stream->i_pes_used = 0;
p_stream->i_pes_length = 0; p_stream->i_pes_length = 0;
continue; continue;
}
} }
} }
b_ok = false; }
b_ok = false;
block_t *p_data;
if( p_stream == p_pcr_stream || p_sys->b_data_alignment
|| p_input->p_fmt->i_codec !=
VLC_CODEC_MPGA )
{
p_data = block_FifoGet( p_input->p_fifo );
if( p_input->p_fmt->i_codec == block_t *p_data;
VLC_CODEC_MP4A ) if( p_stream == p_pcr_stream || p_sys->b_data_alignment
p_data = Add_ADTS( p_data, p_input->p_fmt ); || p_input->p_fmt->i_codec !=
} VLC_CODEC_MPGA )
else {
p_data = FixPES( p_mux, p_input->p_fifo ); p_data = block_FifoGet( p_input->p_fifo );
if( block_FifoCount( p_input->p_fifo ) > 0 && if( p_input->p_fmt->i_codec ==
p_input->p_fmt->i_cat != SPU_ES ) VLC_CODEC_MP4A )
{ p_data = Add_ADTS( p_data, p_input->p_fmt );
block_t *p_next = block_FifoShow( p_input->p_fifo ); }
p_data->i_length = p_next->i_dts - p_data->i_dts; else
} p_data = FixPES( p_mux, p_input->p_fifo );
else if( p_input->p_fmt->i_codec !=
VLC_CODEC_SUBT )
p_data->i_length = 1000;
if( ( p_pcr_stream->i_pes_dts > 0 && if( block_FifoCount( p_input->p_fifo ) > 0 &&
p_data->i_dts - 10000000 > p_pcr_stream->i_pes_dts + p_input->p_fmt->i_cat != SPU_ES )
p_pcr_stream->i_pes_length ) || {
p_data->i_dts < p_stream->i_pes_dts || block_t *p_next = block_FifoShow( p_input->p_fifo );
( p_stream->i_pes_dts > 0 && p_data->i_length = p_next->i_dts - p_data->i_dts;
p_input->p_fmt->i_cat != SPU_ES && }
p_data->i_dts - 10000000 > p_stream->i_pes_dts + else if( p_input->p_fmt->i_codec !=
p_stream->i_pes_length ) ) VLC_CODEC_SUBT )
p_data->i_length = 1000;
if( ( p_pcr_stream->i_pes_dts > 0 &&
p_data->i_dts - 10000000 > p_pcr_stream->i_pes_dts +
p_pcr_stream->i_pes_length ) ||
p_data->i_dts < p_stream->i_pes_dts ||
( p_stream->i_pes_dts > 0 &&
p_input->p_fmt->i_cat != SPU_ES &&
p_data->i_dts - 10000000 > p_stream->i_pes_dts +
p_stream->i_pes_length ) )
{
msg_Warn( p_mux, "packet with too strange dts "
"(dts=%"PRId64",old=%"PRId64",pcr=%"PRId64")",
p_data->i_dts, p_stream->i_pes_dts,
p_pcr_stream->i_pes_dts );
block_Release( p_data );
BufferChainClean( &p_stream->chain_pes );
p_stream->i_pes_dts = 0;
p_stream->i_pes_used = 0;
p_stream->i_pes_length = 0;
if( p_input->p_fmt->i_cat != SPU_ES )
{ {
msg_Warn( p_mux, "packet with too strange dts " BufferChainClean( &p_pcr_stream->chain_pes );
"(dts=%"PRId64",old=%"PRId64",pcr=%"PRId64")", p_pcr_stream->i_pes_dts = 0;
p_data->i_dts, p_stream->i_pes_dts, p_pcr_stream->i_pes_used = 0;
p_pcr_stream->i_pes_dts ); p_pcr_stream->i_pes_length = 0;
block_Release( p_data );
BufferChainClean( &p_stream->chain_pes );
p_stream->i_pes_dts = 0;
p_stream->i_pes_used = 0;
p_stream->i_pes_length = 0;
if( p_input->p_fmt->i_cat != SPU_ES )
{
BufferChainClean( &p_pcr_stream->chain_pes );
p_pcr_stream->i_pes_dts = 0;
p_pcr_stream->i_pes_used = 0;
p_pcr_stream->i_pes_length = 0;
}
} }
else }
else
{
int i_header_size = 0;
int i_max_pes_size = 0;
int b_data_alignment = 0;
if( p_input->p_fmt->i_cat == SPU_ES )
{ {
int i_header_size = 0; if( p_input->p_fmt->i_codec ==
int i_max_pes_size = 0; VLC_CODEC_SUBT )
int b_data_alignment = 0;
if( p_input->p_fmt->i_cat == SPU_ES )
{ {
if( p_input->p_fmt->i_codec == /* Prepend header */
VLC_CODEC_SUBT ) p_data = block_Realloc( p_data, 2,
{ p_data->i_buffer );
/* Prepend header */ p_data->p_buffer[0] =
p_data = block_Realloc( p_data, 2, ( (p_data->i_buffer - 2) >> 8) & 0xff;
p_data->i_buffer ); p_data->p_buffer[1] =
p_data->p_buffer[0] = ( (p_data->i_buffer - 2) ) & 0xff;
( (p_data->i_buffer - 2) >> 8) & 0xff;
p_data->p_buffer[1] = /* remove trailling \0 if any */
( (p_data->i_buffer - 2) ) & 0xff; if( p_data->i_buffer > 2 &&
p_data->p_buffer[p_data->i_buffer -1] ==
/* remove trailling \0 if any */ '\0' )
if( p_data->i_buffer > 2 && p_data->i_buffer--;
p_data->p_buffer[p_data->i_buffer -1] ==
'\0' ) /* Append a empty sub (sub text only) */
p_data->i_buffer--; if( p_data->i_length > 0 &&
!( p_data->i_buffer == 1 &&
/* Append a empty sub (sub text only) */ *p_data->p_buffer == ' ' ) )
if( p_data->i_length > 0 &&
!( p_data->i_buffer == 1 &&
*p_data->p_buffer == ' ' ) )
{
block_t *p_spu = block_New( p_mux, 3 );
p_spu->i_dts = p_spu->i_pts =
p_data->i_dts + p_data->i_length;
p_spu->i_length = 1000;
p_spu->p_buffer[0] = 0;
p_spu->p_buffer[1] = 1;
p_spu->p_buffer[2] = ' ';
EStoPES( p_mux->p_sout, &p_spu, p_spu,
p_input->p_fmt,
p_stream->i_stream_id, 1,
0, 0, 0 );
p_data->p_next = p_spu;
}
}
else if( p_input->p_fmt->i_codec ==
VLC_CODEC_TELETEXT )
{
/* EN 300 472 */
i_header_size = 0x24;
b_data_alignment = 1;
}
else if( p_input->p_fmt->i_codec ==
VLC_CODEC_DVBS )
{ {
/* EN 300 743 */ block_t *p_spu = block_New( p_mux, 3 );
b_data_alignment = 1;
p_spu->i_dts = p_spu->i_pts =
p_data->i_dts + p_data->i_length;
p_spu->i_length = 1000;
p_spu->p_buffer[0] = 0;
p_spu->p_buffer[1] = 1;
p_spu->p_buffer[2] = ' ';
EStoPES( p_mux->p_sout, &p_spu, p_spu,
p_input->p_fmt,
p_stream->i_stream_id, 1,
0, 0, 0 );
p_data->p_next = p_spu;
} }
} }
else if( p_data->i_length < 0 || else if( p_input->p_fmt->i_codec ==
p_data->i_length > 2000000 ) VLC_CODEC_TELETEXT )
{ {
/* FIXME choose a better value, but anyway we /* EN 300 472 */
* should never have to do that */ i_header_size = 0x24;
p_data->i_length = 1000; b_data_alignment = 1;
} }
else if( p_input->p_fmt->i_codec ==
p_stream->i_pes_length += p_data->i_length; VLC_CODEC_DVBS )
if( p_stream->i_pes_dts == 0 )
{ {
p_stream->i_pes_dts = p_data->i_dts; /* EN 300 743 */
b_data_alignment = 1;
} }
}
else if( p_data->i_length < 0 ||
p_data->i_length > 2000000 )
{
/* FIXME choose a better value, but anyway we
* should never have to do that */
p_data->i_length = 1000;
}
/* Convert to pes */ p_stream->i_pes_length += p_data->i_length;
if( p_stream->i_stream_id == 0xa0 && if( p_stream->i_pes_dts == 0 )
p_data->i_pts <= 0 ) {
{ p_stream->i_pes_dts = p_data->i_dts;
/* XXX yes I know, it's awful, but it's needed, }
* so don't remove it ... */
p_data->i_pts = p_data->i_dts;
}
if( p_input->p_fmt->i_codec == /* Convert to pes */
VLC_CODEC_DIRAC ) if( p_stream->i_stream_id == 0xa0 &&
{ p_data->i_pts <= 0 )
b_data_alignment = 1; {
/* dirac pes packets should be unbounded in /* XXX yes I know, it's awful, but it's needed,
* length, specify a suitibly large max size */ * so don't remove it ... */
i_max_pes_size = INT_MAX; p_data->i_pts = p_data->i_dts;
} }
EStoPES ( p_mux->p_sout, &p_data, p_data, if( p_input->p_fmt->i_codec ==
p_input->p_fmt, p_stream->i_stream_id, VLC_CODEC_DIRAC )
1, b_data_alignment, i_header_size, {
i_max_pes_size ); b_data_alignment = 1;
/* dirac pes packets should be unbounded in
* length, specify a suitibly large max size */
i_max_pes_size = INT_MAX;
}
BufferChainAppend( &p_stream->chain_pes, p_data ); EStoPES ( p_mux->p_sout, &p_data, p_data,
p_input->p_fmt, p_stream->i_stream_id,
1, b_data_alignment, i_header_size,
i_max_pes_size );
if( p_sys->b_use_key_frames && p_stream == p_pcr_stream BufferChainAppend( &p_stream->chain_pes, p_data );
&& (p_data->i_flags & BLOCK_FLAG_TYPE_I)
&& !(p_data->i_flags & BLOCK_FLAG_NO_KEYFRAME) if( p_sys->b_use_key_frames && p_stream == p_pcr_stream
&& (p_stream->i_pes_length > 400000) ) && (p_data->i_flags & BLOCK_FLAG_TYPE_I)
{ && !(p_data->i_flags & BLOCK_FLAG_NO_KEYFRAME)
i_shaping_delay = p_stream->i_pes_length; && (p_stream->i_pes_length > 400000) )
p_stream->b_key_frame = 1; {
} i_shaping_delay = p_stream->i_pes_length;
p_stream->b_key_frame = 1;
} }
} }
} }
if( b_ok )
{
break;
}
} }
/* save */ /* save */
i_pcr_dts = p_pcr_stream->i_pes_dts; mtime_t i_pcr_dts = p_pcr_stream->i_pes_dts;
i_pcr_length = p_pcr_stream->i_pes_length; mtime_t i_pcr_length = p_pcr_stream->i_pes_length;
p_pcr_stream->b_key_frame = 0; p_pcr_stream->b_key_frame = 0;
/* msg_Dbg( p_mux, "starting muxing %lldms", i_pcr_length / 1000 ); */ /* msg_Dbg( p_mux, "starting muxing %lldms", i_pcr_length / 1000 ); */
/* 2: calculate non accurate total size of muxed ts */ /* 2: calculate non accurate total size of muxed ts */
i_packet_count = 0; int i_packet_count = 0;
for (int i = 0; i < p_mux->i_nb_inputs; i++ ) for (int i = 0; i < p_mux->i_nb_inputs; i++ )
{ {
ts_stream_t *p_stream = (ts_stream_t*)p_mux->pp_inputs[i]->p_sys; ts_stream_t *p_stream = (ts_stream_t*)p_mux->pp_inputs[i]->p_sys;
...@@ -1560,7 +1546,7 @@ static int Mux( sout_mux_t *p_mux ) ...@@ -1560,7 +1546,7 @@ static int Mux( sout_mux_t *p_mux )
/* append PAT/PMT -> FIXME with big pcr delay it won't have enough pat/pmt */ /* append PAT/PMT -> FIXME with big pcr delay it won't have enough pat/pmt */
GetPAT( p_mux, &chain_ts ); GetPAT( p_mux, &chain_ts );
GetPMT( p_mux, &chain_ts ); GetPMT( p_mux, &chain_ts );
i_packet_pos = 0; int i_packet_pos = 0;
i_packet_count += chain_ts.i_depth; i_packet_count += chain_ts.i_depth;
/* msg_Dbg( p_mux, "estimated pck=%d", i_packet_count ); */ /* msg_Dbg( p_mux, "estimated pck=%d", i_packet_count ); */
......
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