]> git.sesse.net Git - vlc/blobdiff - src/input/es_out.c
Display codec meta data.
[vlc] / src / input / es_out.c
index 0d6197cd105ba94f5840b69c0e6429926fde0813..65d0f783fda452ace5f9b1b6d976c244c9b64574 100644 (file)
@@ -169,7 +169,7 @@ static int          EsOutControl( es_out_t *, int i_query, va_list );
 static void         EsOutDelete ( es_out_t * );
 
 static void         EsOutSelect( es_out_t *, es_out_id_t *es, bool b_force );
-static void         EsOutUpdateInfo( es_out_t *, es_out_id_t *es, const es_format_t * );
+static void         EsOutUpdateInfo( es_out_t *, es_out_id_t *es, const es_format_t *, const vlc_meta_t * );
 static int          EsOutSetRecord(  es_out_t *, bool b_record );
 
 static bool EsIsSelected( es_out_id_t *es );
@@ -575,6 +575,8 @@ static void EsOutChangePosition( es_out_t *out )
 {
     es_out_sys_t      *p_sys = out->p_sys;
 
+    input_SendEventCache( p_sys->p_input, 0.0 );
+
     for( int i = 0; i < p_sys->i_es; i++ )
     {
         es_out_id_t *p_es = p_sys->es[i];
@@ -626,10 +628,13 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
 
     if( i_stream_duration <= i_buffering_duration && !b_forced )
     {
-        msg_Dbg( p_sys->p_input, "Buffering %d%%",
-                 (int)(100 * i_stream_duration / i_buffering_duration ) );
+        const double f_level = (double)i_stream_duration / i_buffering_duration;
+        input_SendEventCache( p_sys->p_input, f_level );
+
+        msg_Dbg( p_sys->p_input, "Buffering %d%%", (int)(100 * f_level) );
         return;
     }
+    input_SendEventCache( p_sys->p_input, 1.0 );
 
     msg_Dbg( p_sys->p_input, "Stream buffering done (%d ms in %d ms)",
               (int)(i_stream_duration/1000), (int)(i_system_duration/1000) );
@@ -793,8 +798,52 @@ static void EsOutFrameNext( es_out_t *out )
 
     p_sys->i_preroll_end = -1;
 }
+static mtime_t EsOutGetBuffering( es_out_t *out )
+{
+    es_out_sys_t *p_sys = out->p_sys;
+
+    if( !p_sys->p_pgrm )
+        return 0;
+
+    int i_ret;
+    mtime_t i_stream_start;
+    mtime_t i_system_start;
+    mtime_t i_stream_duration;
+    mtime_t i_system_duration;
+    i_ret = input_clock_GetState( p_sys->p_pgrm->p_clock,
+                                  &i_stream_start, &i_system_start,
+                                  &i_stream_duration, &i_system_duration );
 
+    if( i_ret )
+        return 0;
 
+    mtime_t i_delay;
+
+    if( p_sys->b_buffering && p_sys->i_buffering_extra_initial <= 0 )
+    {
+        i_delay = i_stream_duration;
+    }
+    else
+    {
+        mtime_t i_system_duration;
+        if( p_sys->b_paused )
+        {
+            i_system_duration = p_sys->i_pause_date  - i_system_start;
+            if( p_sys->i_buffering_extra_initial > 0 )
+                i_system_duration += p_sys->i_buffering_extra_system - p_sys->i_buffering_extra_initial;
+        }
+        else
+        {
+            i_system_duration = mdate() - i_system_start;
+        }
+
+        const mtime_t i_consumed = i_system_duration * INPUT_RATE_DEFAULT / p_sys->i_rate - i_stream_duration;
+        i_delay = p_sys->p_input->i_pts_delay - i_consumed;
+    }
+    if( i_delay < 0 )
+        return 0;
+    return i_delay;
+}
 
 static void EsOutESVarUpdateGeneric( es_out_t *out, int i_id, es_format_t *fmt, const char *psz_language,
                                      bool b_delete )
@@ -934,10 +983,8 @@ static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
     }
 
     /* Update now playing */
-    input_item_SetNowPlaying( p_input->p->input.p_item,
-                              p_pgrm->psz_now_playing );
-    input_item_SetPublisher( p_input->p->input.p_item,
-                             p_pgrm->psz_publisher );
+    input_item_SetNowPlaying( p_input->p->p_item, p_pgrm->psz_now_playing );
+    input_item_SetPublisher( p_input->p->p_item, p_pgrm->psz_publisher );
 
     input_SendEventMeta( p_input );
 }
@@ -962,7 +1009,7 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
     p_pgrm->psz_now_playing = NULL;
     p_pgrm->psz_publisher = NULL;
     p_pgrm->p_epg = NULL;
-    p_pgrm->p_clock = input_clock_New( p_input->p->input.i_cr_average, p_sys->i_rate );
+    p_pgrm->p_clock = input_clock_New( p_input->p->i_cr_average, p_sys->i_rate );
     if( !p_pgrm->p_clock )
     {
         free( p_pgrm );
@@ -1126,7 +1173,7 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, vlc_meta_t *p_meta )
     {
         if( p_sys->p_pgrm == p_pgrm )
         {
-            input_item_SetPublisher( p_input->p->input.p_item, psz_provider );
+            input_item_SetPublisher( p_input->p->p_item, psz_provider );
             input_SendEventMeta( p_input );
         }
         input_Control( p_input, INPUT_ADD_INFO, psz_cat, input_MetaTypeToLocalizedString(vlc_meta_Publisher), psz_provider );
@@ -1252,7 +1299,7 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, vlc_epg_t *p_epg )
 
     if( p_pgrm == p_sys->p_pgrm )
     {
-        input_item_SetNowPlaying( p_input->p->input.p_item, p_pgrm->psz_now_playing );
+        input_item_SetNowPlaying( p_input->p->p_item, p_pgrm->psz_now_playing );
         input_SendEventMeta( p_input );
     }
 
@@ -1329,9 +1376,9 @@ static es_out_id_t *EsOutAdd( es_out_t *out, const es_format_t *fmt )
         es->i_channel = p_sys->i_audio;
 
         memset( &rg, 0, sizeof(rg) );
-        vlc_mutex_lock( &p_input->p->input.p_item->lock );
-        vlc_audio_replay_gain_MergeFromMeta( &rg, p_input->p->input.p_item->p_meta );
-        vlc_mutex_unlock( &p_input->p->input.p_item->lock );
+        vlc_mutex_lock( &p_input->p->p_item->lock );
+        vlc_audio_replay_gain_MergeFromMeta( &rg, p_input->p->p_item->p_meta );
+        vlc_mutex_unlock( &p_input->p->p_item->lock );
 
         for( i = 0; i < AUDIO_REPLAY_GAIN_MAX; i++ )
         {
@@ -1396,7 +1443,7 @@ static es_out_id_t *EsOutAdd( es_out_t *out, const es_format_t *fmt )
             break;
     }
 
-    EsOutUpdateInfo( out, es, &es->fmt );
+    EsOutUpdateInfo( out, es, &es->fmt, NULL );
 
     vlc_mutex_unlock( &p_sys->lock );
 
@@ -1802,10 +1849,14 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
     input_DecoderDecode( es->p_dec, p_block );
 
     es_format_t fmt_dsc;
-    if( input_DecoderHasFormatChanged( es->p_dec, &fmt_dsc ) )
+    vlc_meta_t  *p_meta_dsc;
+    if( input_DecoderHasFormatChanged( es->p_dec, &fmt_dsc, &p_meta_dsc ) )
     {
-        EsOutUpdateInfo( out, es, &fmt_dsc );
+        EsOutUpdateInfo( out, es, &fmt_dsc, p_meta_dsc );
+
         es_format_Clean( &fmt_dsc );
+        if( p_meta_dsc )
+            vlc_meta_Delete( p_meta_dsc );
     }
 
     /* Check CC status */
@@ -2313,7 +2364,18 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
             mtime_t i_time = (mtime_t)va_arg( args, mtime_t );
             mtime_t i_length = (mtime_t)va_arg( args, mtime_t );
 
-            /* TODO handle es_out buffering */
+            /* Fix for buffering delay */
+            const mtime_t i_delay = EsOutGetBuffering( out );
+
+            i_time -= i_delay;
+            if( i_time < 0 )
+                i_time = 0;
+
+            if( i_length > 0 )
+                f_position -= (double)i_delay / i_length;
+            if( f_position < 0 )
+                f_position = 0;
+
             input_SendEventTimes( p_sys->p_input, f_position, i_time, i_length );
             return VLC_SUCCESS;
         }
@@ -2472,7 +2534,7 @@ static int LanguageArrayIndex( char **ppsz_langs, char *psz_lang )
  * EsOutUpdateInfo:
  * - add meta info to the playlist item
  ****************************************************************************/
-static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *fmt )
+static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *fmt, const vlc_meta_t *p_meta )
 {
     es_out_sys_t   *p_sys = out->p_sys;
     input_thread_t *p_input = p_sys->p_input;
@@ -2613,5 +2675,21 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
         break;
     }
 
+    /* Append generic meta */
+    if( p_meta )
+    {
+        char **ppsz_all_keys = vlc_dictionary_all_keys( &p_meta->extra_tags );
+        for( int i = 0; ppsz_all_keys && ppsz_all_keys[i]; i++ )
+        {
+            char *psz_key = ppsz_all_keys[i];
+            char *psz_value = vlc_dictionary_value_for_key( &p_meta->extra_tags, psz_key );
+
+            if( psz_value )
+                input_Control( p_input, INPUT_ADD_INFO, psz_cat, _(psz_key), _(psz_value) );
+            free( psz_key );
+        }
+        free( ppsz_all_keys );
+    }
+
     free( psz_cat );
 }