#include <vlc_sout.h>
#include <vlc_codec.h>
#include <vlc_osd.h>
+#include <vlc_meta.h>
#include <vlc_interface.h>
#include "audio_output/aout_internal.h"
#include "clock.h"
#include "decoder.h"
#include "event.h"
+#include "resource.h"
#include "../video_output/vout_control.h"
static subpicture_t *spu_new_buffer( decoder_t * );
static void spu_del_buffer( decoder_t *, subpicture_t * );
-static es_format_t null_es_format;
-
struct decoder_owner_sys_t
{
int64_t i_preroll_end;
/* */
bool b_fmt_description;
es_format_t fmt_description;
+ vlc_meta_t *p_description;
/* fifo */
block_fifo_t *p_fifo;
}
p_dec->p_owner->p_clock = p_clock;
+ assert( p_dec->fmt_out.i_cat != UNKNOWN_ES );
- if( fmt->i_cat == AUDIO_ES )
+ if( p_dec->fmt_out.i_cat == AUDIO_ES )
i_priority = VLC_THREAD_PRIORITY_AUDIO;
else
i_priority = VLC_THREAD_PRIORITY_VIDEO;
/* Spawn the decoder thread */
- if( vlc_thread_create( p_dec, "decoder", DecoderThread,
- i_priority, false ) )
+ if( vlc_thread_create( p_dec, "decoder", DecoderThread, i_priority ) )
{
msg_Err( p_dec, "cannot spawn decoder thread" );
module_unneed( p_dec, p_dec->p_module );
/* Make sure we aren't paused/buffering/waiting anymore */
vlc_mutex_lock( &p_owner->lock );
+ const bool b_was_paused = p_owner->b_paused;
p_owner->b_paused = false;
p_owner->b_buffering = false;
p_owner->b_flushing = true;
vlc_mutex_unlock( &p_owner->lock );
vlc_thread_join( p_dec );
+ p_owner->b_paused = b_was_paused;
+
module_unneed( p_dec, p_dec->p_module );
/* */
*pi_duration = 0;
vlc_mutex_lock( &p_owner->lock );
- if( p_dec->fmt_in.i_cat == VIDEO_ES )
+ if( p_dec->fmt_out.i_cat == VIDEO_ES )
{
if( p_owner->b_paused && p_owner->p_vout )
{
vlc_mutex_unlock( &p_owner->lock );
}
-bool input_DecoderHasFormatChanged( decoder_t *p_dec, es_format_t *p_fmt )
+bool input_DecoderHasFormatChanged( decoder_t *p_dec, es_format_t *p_fmt, vlc_meta_t **pp_meta )
{
decoder_owner_sys_t *p_owner = p_dec->p_owner;
bool b_changed;
{
if( p_fmt )
es_format_Copy( p_fmt, &p_owner->fmt_description );
+
+ if( pp_meta )
+ {
+ *pp_meta = NULL;
+ if( p_owner->p_description )
+ {
+ *pp_meta = vlc_meta_New();
+ if( *pp_meta )
+ vlc_meta_Merge( *pp_meta, p_owner->p_description );
+ }
+ }
p_owner->b_fmt_description = false;
}
vlc_mutex_unlock( &p_owner->lock );
if( !p_owner->p_clock || !i_ts )
return i_ts;
- return input_clock_GetTS( p_owner->p_clock, NULL, p_owner->p_input->i_pts_delay, i_ts );
+ if( input_clock_ConvertTS( p_owner->p_clock, NULL, &i_ts, NULL, INT64_MAX ) )
+ return 0;
+
+ return i_ts;
}
static int DecoderGetDisplayRate( decoder_t *p_dec )
{
{
decoder_t *p_dec;
decoder_owner_sys_t *p_owner;
+ es_format_t null_es_format;
+
int i;
p_dec = vlc_object_create( p_input, i_object_type );
p_dec->pf_get_cc = NULL;
p_dec->pf_packetize = NULL;
- /* Initialize the decoder fifo */
+ /* Initialize the decoder */
p_dec->p_module = NULL;
memset( &null_es_format, 0, sizeof(es_format_t) );
es_format_Copy( &p_dec->fmt_in, fmt );
es_format_Copy( &p_dec->fmt_out, &null_es_format );
+ p_dec->p_description = NULL;
+
/* Allocate our private structure for the decoder */
p_dec->p_owner = p_owner = malloc( sizeof( decoder_owner_sys_t ) );
if( p_dec->p_owner == NULL )
/* Find a suitable decoder/packetizer module */
if( i_object_type == VLC_OBJECT_DECODER )
- p_dec->p_module = module_need( p_dec, "decoder", "$codec", 0 );
+ p_dec->p_module = module_need( p_dec, "decoder", "$codec", false );
else
- p_dec->p_module = module_need( p_dec, "packetizer", "$packetizer", 0 );
+ p_dec->p_module = module_need( p_dec, "packetizer", "$packetizer", false );
/* Check if decoder requires already packetized data */
if( i_object_type == VLC_OBJECT_DECODER &&
p_dec->p_owner->p_packetizer->p_module =
module_need( p_dec->p_owner->p_packetizer,
- "packetizer", "$packetizer", 0 );
+ "packetizer", "$packetizer", false );
if( !p_dec->p_owner->p_packetizer->p_module )
{
p_owner->b_fmt_description = false;
es_format_Init( &p_owner->fmt_description, UNKNOWN_ES, 0 );
+ p_owner->p_description = NULL;
p_owner->b_paused = false;
p_owner->pause.i_date = 0;
for( ;; )
{
block_t *p_block = block_FifoGet( p_owner->p_fifo );
+
/* Make sure there is no cancellation point other than this one^^.
* If you need one, be sure to push cleanup of p_block. */
DecoderSignalBuffering( p_dec, p_block == NULL );
vlc_restorecancel( canc );
}
}
-
- DecoderSignalBuffering( p_dec, true );
return NULL;
}
+static block_t *DecoderBlockFlushNew()
+{
+ block_t *p_null = block_Alloc( 128 );
+ if( !p_null )
+ return NULL;
+
+ p_null->i_flags |= BLOCK_FLAG_DISCONTINUITY |
+ BLOCK_FLAG_CORRUPTED |
+ BLOCK_FLAG_CORE_FLUSH;
+ memset( p_null->p_buffer, 0, p_null->i_buffer );
+
+ return p_null;
+}
+
static void DecoderFlush( decoder_t *p_dec )
{
decoder_owner_sys_t *p_owner = p_dec->p_owner;
- block_t *p_null;
vlc_assert_locked( &p_owner->lock );
vlc_cond_signal( &p_owner->wait );
/* Send a special block */
- p_null = block_New( p_dec, 128 );
+ block_t *p_null = DecoderBlockFlushNew();
if( !p_null )
return;
- p_null->i_flags |= BLOCK_FLAG_DISCONTINUITY;
- p_null->i_flags |= BLOCK_FLAG_CORE_FLUSH;
- if( !p_dec->fmt_in.b_packetized )
- p_null->i_flags |= BLOCK_FLAG_CORRUPTED;
- memset( p_null->p_buffer, 0, p_null->i_buffer );
-
input_DecoderDecode( p_dec, p_null );
/* */
* - for sout it is useless
* - for subs, it is done by the vout
*/
- if( p_dec->fmt_in.i_cat == AUDIO_ES )
+ if( p_dec->fmt_out.i_cat == AUDIO_ES )
{
if( p_owner->p_aout && p_owner->p_aout_input )
aout_DecChangePause( p_owner->p_aout, p_owner->p_aout_input,
b_paused, i_date );
}
- else if( p_dec->fmt_in.i_cat == VIDEO_ES )
+ else if( p_dec->fmt_out.i_cat == VIDEO_ES )
{
if( p_owner->p_vout )
vout_ChangePause( p_owner->p_vout, b_paused, i_date );
*pi_preroll = __MIN( *pi_preroll, p->i_dts );
}
-static mtime_t DecoderTeletextFixTs( mtime_t i_ts, mtime_t i_ts_delay )
+static mtime_t DecoderTeletextFixTs( mtime_t i_ts )
{
mtime_t current_date = mdate();
{
/* ETSI EN 300 472 Annex A : do not take into account the PTS
* for teletext streams. */
- return current_date + 400000 + i_ts_delay;
+ return current_date + 400000;
}
return i_ts;
}
static void DecoderFixTs( decoder_t *p_dec, mtime_t *pi_ts0, mtime_t *pi_ts1,
- mtime_t *pi_duration, int *pi_rate, mtime_t *pi_delay, bool b_telx )
+ mtime_t *pi_duration, int *pi_rate, mtime_t i_ts_bound, bool b_telx )
{
decoder_owner_sys_t *p_owner = p_dec->p_owner;
input_clock_t *p_clock = p_owner->p_clock;
- int i_rate = 0;
vlc_assert_locked( &p_owner->lock );
- const mtime_t i_ts_delay = p_owner->p_input->i_pts_delay;
const mtime_t i_es_delay = p_owner->i_ts_delay;
if( p_clock )
{
const bool b_ephemere = pi_ts1 && *pi_ts0 == *pi_ts1;
+ int i_rate;
if( *pi_ts0 > 0 )
- *pi_ts0 = input_clock_GetTS( p_clock, &i_rate, i_ts_delay,
- *pi_ts0 + i_es_delay );
- if( pi_ts1 && *pi_ts1 > 0 )
- *pi_ts1 = input_clock_GetTS( p_clock, &i_rate, i_ts_delay,
- *pi_ts1 + i_es_delay );
+ {
+ *pi_ts0 += i_es_delay;
+ if( pi_ts1 && *pi_ts1 > 0 )
+ *pi_ts1 += i_es_delay;
+ if( input_clock_ConvertTS( p_clock, &i_rate, pi_ts0, pi_ts1, i_ts_bound ) )
+ *pi_ts0 = 0;
+ }
+ else
+ {
+ i_rate = input_clock_GetRate( p_clock );
+ }
/* Do not create ephemere data because of rounding errors */
if( !b_ephemere && pi_ts1 && *pi_ts0 == *pi_ts1 )
*pi_ts1 += 1;
- if( i_rate <= 0 )
- i_rate = input_clock_GetRate( p_clock );
-
if( pi_duration )
*pi_duration = ( *pi_duration * i_rate +
INPUT_RATE_DEFAULT-1 ) / INPUT_RATE_DEFAULT;
if( b_telx )
{
- *pi_ts0 = DecoderTeletextFixTs( *pi_ts0, i_ts_delay );
+ *pi_ts0 = DecoderTeletextFixTs( *pi_ts0 );
if( pi_ts1 && *pi_ts1 <= 0 )
*pi_ts1 = *pi_ts0;
}
}
- if( pi_delay )
- {
- const int r = i_rate > 0 ? i_rate : INPUT_RATE_DEFAULT;
- *pi_delay = i_ts_delay + i_es_delay * r / INPUT_RATE_DEFAULT;
- }
}
static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
}
/* */
+ const bool b_dated = p_audio->start_date > 0;
int i_rate = INPUT_RATE_DEFAULT;
- mtime_t i_delay;
DecoderFixTs( p_dec, &p_audio->start_date, &p_audio->end_date, NULL,
- &i_rate, &i_delay, false );
+ &i_rate, AOUT_MAX_ADVANCE_TIME, false );
vlc_mutex_unlock( &p_owner->lock );
- /* */
- const mtime_t i_max_date = mdate() + i_delay + AOUT_MAX_ADVANCE_TIME;
-
if( !p_aout || !p_aout_input ||
- p_audio->start_date <= 0 || p_audio->start_date > i_max_date ||
+ p_audio->start_date <= 0 ||
i_rate < INPUT_RATE_DEFAULT/AOUT_MAX_INPUT_RATE ||
i_rate > INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE )
b_reject = true;
}
else
{
- if( p_audio->start_date <= 0 )
- {
+ if( b_dated )
+ msg_Warn( p_aout, "received buffer in the future" );
+ else
msg_Warn( p_dec, "non-dated audio buffer received" );
- }
- else if( p_audio->start_date > i_max_date )
- {
- msg_Warn( p_aout, "received buffer in the future (%"PRId64")",
- p_audio->start_date - mdate() );
- }
+
*pi_lost_sum += 1;
aout_BufferFree( p_audio );
}
{
aout_instance_t *p_aout = p_owner->p_aout;
aout_input_t *p_aout_input = p_owner->p_aout_input;
- int i_lost = 0;
- int i_played;
if( p_dec->b_die )
{
}
/* */
- int i_rate = INPUT_RATE_DEFAULT;
- mtime_t i_delay;
-
if( b_buffering_first )
{
assert( p_owner->buffer.b_first );
msg_Dbg( p_dec, "Received first picture" );
p_owner->buffer.b_first = false;
p_picture->b_force = true;
- i_delay = 0;
- if( p_owner->p_clock )
- i_rate = input_clock_GetRate( p_owner->p_clock );
}
+
+ const bool b_dated = p_picture->date > 0;
+ int i_rate = INPUT_RATE_DEFAULT;
DecoderFixTs( p_dec, &p_picture->date, NULL, NULL,
- &i_rate, &i_delay, false );
+ &i_rate, DECODER_BOGUS_VIDEO_DELAY, false );
vlc_mutex_unlock( &p_owner->lock );
/* */
- const mtime_t i_max_date = mdate() + i_delay + DECODER_BOGUS_VIDEO_DELAY;
-
- if( !p_picture->b_force && ( p_picture->date <= 0 || p_picture->date >= i_max_date ) )
+ if( !p_picture->b_force && p_picture->date <= 0 )
b_reject = true;
if( !b_reject )
}
else
{
- if( p_picture->date <= 0 )
- {
- msg_Warn( p_vout, "non-dated video buffer received" );
- }
+ if( b_dated )
+ msg_Warn( p_vout, "early picture skipped" );
else
- {
- msg_Warn( p_vout, "early picture skipped (%"PRId64")",
- p_picture->date - mdate() );
- }
+ msg_Warn( p_vout, "non-dated video buffer received" );
+
*pi_lost_sum += 1;
vout_DropPicture( p_vout, p_picture );
}
/* */
DecoderFixTs( p_dec, &p_subpic->i_start, &p_subpic->i_stop, NULL,
- NULL, NULL, b_telx );
+ NULL, INT64_MAX, b_telx );
vlc_mutex_unlock( &p_owner->lock );
DecoderFixTs( p_dec, &p_sout_block->i_dts, &p_sout_block->i_pts,
&p_sout_block->i_length,
- &p_sout_block->i_rate, NULL, b_telx );
+ &p_sout_block->i_rate, INT64_MAX, b_telx );
vlc_mutex_unlock( &p_owner->lock );
p_packetized_block = p_next;
}
}
+ /* The packetizer does not output a block that tell the decoder to flush
+ * do it ourself */
+ if( b_flush )
+ {
+ block_t *p_null = DecoderBlockFlushNew();
+ if( p_null )
+ DecoderDecodeVideo( p_dec, p_null );
+ }
}
else if( p_block )
{
p_packetized_block = p_next;
}
}
+ /* The packetizer does not output a block that tell the decoder to flush
+ * do it ourself */
+ if( b_flush )
+ {
+ block_t *p_null = DecoderBlockFlushNew();
+ if( p_null )
+ DecoderDecodeAudio( p_dec, p_null );
+ }
}
else if( p_block )
{
stats_UpdateInteger( p_dec, p_input->p->counters.p_decoded_sub, 1, NULL );
vlc_mutex_unlock( &p_input->p->counters.counters_lock );
- p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
+ p_vout = input_resource_HoldVout( p_input->p->p_resource );
if( p_vout && p_owner->p_spu_vout == p_vout )
{
/* Preroll does not work very well with subtitle */
if( b_flush && p_owner->p_spu_vout )
{
- p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
+ p_vout = input_resource_HoldVout( p_input->p->p_resource );
if( p_vout && p_owner->p_spu_vout == p_vout )
spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR,
}
#ifdef ENABLE_SOUT
- if( p_dec->i_object_type == VLC_OBJECT_PACKETIZER )
+ if( vlc_internals( p_dec )->i_object_type == VLC_OBJECT_PACKETIZER )
{
if( p_block )
p_block->i_flags &= ~BLOCK_FLAG_CORE_PRIVATE_MASK;
p_block->i_flags &= ~BLOCK_FLAG_CORE_PRIVATE_MASK;
}
- if( p_dec->fmt_in.i_cat == AUDIO_ES )
+ if( p_dec->fmt_out.i_cat == AUDIO_ES )
{
DecoderProcessAudio( p_dec, p_block, b_flush );
}
- else if( p_dec->fmt_in.i_cat == VIDEO_ES )
+ else if( p_dec->fmt_out.i_cat == VIDEO_ES )
{
DecoderProcessVideo( p_dec, p_block, b_flush );
}
- else if( p_dec->fmt_in.i_cat == SPU_ES )
+ else if( p_dec->fmt_out.i_cat == SPU_ES )
{
DecoderProcessSpu( p_dec, p_block, b_flush );
}
aout_DecDelete( p_owner->p_aout, p_owner->p_aout_input );
if( p_owner->p_aout )
{
- vlc_object_release( p_owner->p_aout );
+ input_resource_RequestAout( p_owner->p_input->p->p_resource,
+ p_owner->p_aout );
+ input_SendEventAout( p_owner->p_input );
p_owner->p_aout = NULL;
}
if( p_owner->p_vout )
{
- /* Hack to make sure all the the pictures are freed by the decoder */
+ /* Hack to make sure all the the pictures are freed by the decoder
+ * and that the vout is not paused anymore */
vout_FixLeaks( p_owner->p_vout, true );
+ if( p_owner->b_paused )
+ vout_ChangePause( p_owner->p_vout, false, mdate() );
- /* We are about to die. Reattach video output to p_vlc. */
- vout_Request( p_dec, p_owner->p_vout, NULL );
+ /* */
+ input_resource_RequestVout( p_owner->p_input->p->p_resource, p_owner->p_vout, NULL, true );
input_SendEventVout( p_owner->p_input );
}
}
#endif
- if( p_dec->fmt_in.i_cat == SPU_ES )
+ if( p_dec->fmt_out.i_cat == SPU_ES )
{
vout_thread_t *p_vout;
- p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
- if( p_vout && p_owner->p_spu_vout == p_vout )
+ p_vout = input_resource_HoldVout( p_owner->p_input->p->p_resource );
+ if( p_vout )
{
- spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR,
- p_owner->i_spu_channel );
+ if( p_owner->p_spu_vout == p_vout )
+ spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, p_owner->i_spu_channel );
vlc_object_release( p_vout );
}
}
es_format_Clean( &p_dec->fmt_in );
es_format_Clean( &p_dec->fmt_out );
+ if( p_dec->p_description )
+ vlc_meta_Delete( p_dec->p_description );
+ es_format_Clean( &p_owner->fmt_description );
+ if( p_owner->p_description )
+ vlc_meta_Delete( p_owner->p_description );
if( p_owner->p_packetizer )
{
p_owner->p_packetizer->p_module );
es_format_Clean( &p_owner->p_packetizer->fmt_in );
es_format_Clean( &p_owner->p_packetizer->fmt_out );
+ if( p_owner->p_packetizer->p_description )
+ vlc_meta_Delete( p_owner->p_packetizer->p_description );
vlc_object_detach( p_owner->p_packetizer );
vlc_object_release( p_owner->p_packetizer );
}
- es_format_Clean( &p_owner->fmt_description );
-
vlc_cond_destroy( &p_owner->wait );
vlc_mutex_destroy( &p_owner->lock );
vlc_assert_locked( &p_owner->lock );
- es_format_Clean( &p_owner->fmt_description );
-
p_owner->b_fmt_description = true;
+
+ /* Copy es_format */
+ es_format_Clean( &p_owner->fmt_description );
es_format_Copy( &p_owner->fmt_description, &p_dec->fmt_out );
+
+ /* Move p_description */
+ if( p_owner->p_description && p_dec->p_description )
+ vlc_meta_Delete( p_owner->p_description );
+ p_owner->p_description = p_dec->p_description;
+ p_dec->p_description = NULL;
}
static vout_thread_t *aout_request_vout( void *p_private,
- vout_thread_t *p_vout, video_format_t *p_fmt )
+ vout_thread_t *p_vout, video_format_t *p_fmt, bool b_recyle )
{
decoder_t *p_dec = p_private;
+ input_thread_t *p_input = p_dec->p_owner->p_input;
- p_vout = vout_Request( p_dec, p_vout, p_fmt );
- input_SendEventVout( p_dec->p_owner->p_input );
+ p_vout = input_resource_RequestVout( p_input->p->p_resource, p_vout, p_fmt, b_recyle );
+ input_SendEventVout( p_input );
return p_vout;
}
request_vout.p_private = p_dec;
p_aout = p_owner->p_aout;
+ if( !p_aout )
+ p_aout = input_resource_RequestAout( p_owner->p_input->p->p_resource, NULL );
p_aout_input = aout_DecNew( p_dec, &p_aout,
&format, &p_dec->fmt_out.audio_replay_gain, &request_vout );
vlc_mutex_unlock( &p_owner->lock );
+ input_SendEventAout( p_owner->p_input );
+
if( p_owner->p_aout_input == NULL )
{
msg_Err( p_dec, "failed to create audio output" );
p_owner->p_vout = NULL;
vlc_mutex_unlock( &p_owner->lock );
- p_vout = vout_Request( p_dec, p_vout, &p_dec->fmt_out.video );
+ p_vout = input_resource_RequestVout( p_owner->p_input->p->p_resource,
+ p_vout, &p_dec->fmt_out.video, true );
vlc_mutex_lock( &p_owner->lock );
p_owner->p_vout = p_vout;
if( p_dec->b_die || p_dec->b_error )
break;
- p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
+ p_vout = input_resource_HoldVout( p_owner->p_input->p->p_resource );
if( p_vout )
break;
decoder_owner_sys_t *p_owner = p_dec->p_owner;
vout_thread_t *p_vout = NULL;
- p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
+ p_vout = input_resource_HoldVout( p_owner->p_input->p->p_resource );
if( !p_vout || p_owner->p_spu_vout != p_vout )
{
if( p_vout )