[vlc-commits] [Git][videolan/vlc][master] 20 commits: input: es_out: use early return

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Oct 4 09:22:51 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
e5dfc4f5 by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: use early return

The first if branch is already terminating with a return, so there is no
need for an else branch. It makes the early return path more readable by
listing the condition where the clock is not ready among the other
condition where buffering is not ready.

- - - - -
5584bf9b by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: use early return

The first if branch is already terminating with a return, so there is no
need for an else branch.

- - - - -
66c64c0c by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: change else into if

The first if branch is already terminating with a return, so there is no
need for an else branch and we can keep only the if. The return in the
branch is also superfluous given that the success path is the same.

- - - - -
c39d5b4a by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: early return

The if else block is followed by a single return, but the else block is
much more complex than the if block. To simplify, we can add the early
return to the first branch as an early success, ie. there is no other
handling necessary for PCR if buffering is still enabled.

- - - - -
8af10a9e by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: early return

Like the previous commit, handle the case when buffering is enabled with
an early return instead of branching in the case where it's disabled, in
order to remove the whole indentation level and specify exit conditions
at the beginning of the case.

- - - - -
668d7cb6 by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: early return

Like the previous commit, handle the case when clock settings need to be
changed with an early return instead of branching in the case where the
parameters need to be changed, in order to remove the whole indentation
level and specify exit conditions at the beginning.

- - - - -
1142148b by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: remove intermediate variable

The variable was only written once and then returned.

- - - - -
e5961e9c by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: merge if branches

The branches are redundants

- - - - -
f9cffc08 by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: early return

As done in multiple places for deallocation, prefer exiting the release
function in case of non-null reference count instead of branching the
whole function to reduce indentation level and complexity.

- - - - -
22d83dc4 by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: early return

Use the early return on the !b_record path where it cannot fail (release
of resources) and which is much simpler than the b_record path which
needs to handle errors.

- - - - -
b86e4a92 by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: return early when allocating

- - - - -
145c5e99 by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: early return

Remove an indentation level by explicitely skipping the non-matching es.

- - - - -
dae60ffb by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: merge if branches

- - - - -
e2b9a9ab by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: use early return instead of else branch

- - - - -
21af7911 by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: skip es explicitely

Skip the ES explicitely from the beginning of the loop instead of
skipping implicitely with branching, removing an indentation level and
making the skip condition clearer.

- - - - -
4834e113 by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: early continue

Explicitely skip NULL decoder instead of branching the whole loop to
implicitely skip them.

- - - - -
298d563a by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: rename variables for clarity

- - - - -
cd5b0e16 by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: merge conditions

Mergin the two nested if branch removes an indentation level.

- - - - -
36c779d0 by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: early return on allocation

Returning early removes the indentation level and makes it easy to read
that an allocation has been done and must be freed.

- - - - -
ed5f57a1 by Alexandre Janniaux at 2023-10-04T09:03:56+00:00
input: es_out: switch the error and success path

There is no real reason to inverse them in this case, but other cases in
the files are now returning when they succeed in generating the string,
and fallback to other methods when they cannot generate it.

- - - - -


1 changed file:

- src/input/es_out.c


Changes:

=====================================
src/input/es_out.c
=====================================
@@ -5,6 +5,7 @@
  *
  * Authors: Laurent Aimar <fenrir at via.ecp.fr>
  *          Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
+ *          Alexandre Janniaux <ajanni at videolabs.io>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published by
@@ -316,14 +317,11 @@ default_val:
 
 static inline int EsOutGetClosedCaptionsChannel( const es_format_t *p_fmt )
 {
-    int i_channel;
-    if( p_fmt->i_codec == VLC_CODEC_CEA608 && p_fmt->subs.cc.i_channel < 4 )
-        i_channel = p_fmt->subs.cc.i_channel;
-    else if( p_fmt->i_codec == VLC_CODEC_CEA708 && p_fmt->subs.cc.i_channel < 64 )
-        i_channel = p_fmt->subs.cc.i_channel;
-    else
-        i_channel = -1;
-    return i_channel;
+    if ((p_fmt->i_codec == VLC_CODEC_CEA608 && p_fmt->subs.cc.i_channel < 4)
+     || (p_fmt->i_codec == VLC_CODEC_CEA708 && p_fmt->subs.cc.i_channel < 64))
+        return p_fmt->subs.cc.i_channel;
+
+    return -1;
 }
 
 #define foreach_es_then_es_slaves( pos ) \
@@ -550,45 +548,37 @@ static char *EsGetTitle( es_out_id_t *es )
     /* Take care of the ES description */
     if( fmt->psz_description && *fmt->psz_description )
     {
-        if( es->psz_language && *es->psz_language )
-        {
-            if( asprintf( &title, "%s - [%s]", fmt->psz_description,
-                          es->psz_language ) == -1 )
-                title = NULL;
-        }
-        else
-            title = strdup( fmt->psz_description );
+        if (es->psz_language == NULL || *es->psz_language == '\0')
+            return strdup(fmt->psz_description);
+
+        if (asprintf(&title, "%s - [%s]", fmt->psz_description,
+                     es->psz_language) != -1)
+            return title;
     }
-    else
+    else if (es->psz_language && *es->psz_language)
     {
-        if( es->psz_language && *es->psz_language )
-        {
-            if( asprintf( &title, "%s %zu - [%s]", _("Track"),
-                          es->i_pos, es->psz_language ) == -1 )
-                title = NULL;
-        }
-        else
-        {
-            if( asprintf( &title, "%s %zu", _("Track"), es->i_pos ) == -1 )
-                title = NULL;
-        }
+        if (asprintf(&title, "%s %zu - [%s]", _("Track"),
+                     es->i_pos, es->psz_language ) != -1 )
+            return title;
     }
+    else if (asprintf(&title, "%s %zu", _("Track"), es->i_pos) != -1)
+        return title;
 
-    return title;
+    return NULL;
 }
 
 static void EsRelease(es_out_id_t *es)
 {
-    if (vlc_atomic_rc_dec(&es->rc))
-    {
-        free(es->psz_title);
-        free(es->psz_language);
-        free(es->psz_language_code);
-        es_format_Clean(&es->fmt);
-        input_source_Release(es->id.source);
-        free(es->id.str_id);
-        free(es);
-    }
+    if (!vlc_atomic_rc_dec(&es->rc))
+        return;
+
+    free(es->psz_title);
+    free(es->psz_language);
+    free(es->psz_language_code);
+    es_format_Clean(&es->fmt);
+    input_source_Release(es->id.source);
+    free(es->id.str_id);
+    free(es);
 }
 
 static void EsHold(es_out_id_t *es)
@@ -757,90 +747,89 @@ static int EsOutSetRecord(  es_out_t *out, bool b_record, const char *dir_path )
 
     assert( ( b_record && !p_sys->p_sout_record ) || ( !b_record && p_sys->p_sout_record ) );
 
-    if( b_record )
+    if (!b_record)
     {
-        char *psz_path = NULL;
-        if( dir_path == NULL )
+        vlc_list_foreach (p_es, &p_sys->es, node) /* Only master es */
         {
-            psz_path = var_CreateGetNonEmptyString( p_input, "input-record-path" );
-            if( psz_path == NULL )
-            {
-                if( var_CountChoices( p_input, "video-es" ) )
-                    psz_path = config_GetUserDir( VLC_VIDEOS_DIR );
-                else if( var_CountChoices( p_input, "audio-es" ) )
-                    psz_path = config_GetUserDir( VLC_MUSIC_DIR );
-                else
-                    psz_path = config_GetUserDir( VLC_DOWNLOAD_DIR );
-            }
+            if (!p_es->p_dec_record)
+                continue;
+
+            vlc_input_decoder_Flush(p_es->p_dec_record);
+            vlc_input_decoder_Delete(p_es->p_dec_record);
+            p_es->p_dec_record = NULL;
+        }
+        sout_StreamChainDelete(p_sys->p_sout_record, NULL);
+        p_sys->p_sout_record = NULL;
+        return VLC_SUCCESS;
+    }
 
-            dir_path = psz_path;
+    char *psz_path = NULL;
+    if (dir_path == NULL)
+    {
+        psz_path = var_CreateGetNonEmptyString(p_input, "input-record-path");
+        if (psz_path == NULL)
+        {
+            if (var_CountChoices(p_input, "video-es"))
+                psz_path = config_GetUserDir(VLC_VIDEOS_DIR);
+            else if (var_CountChoices(p_input, "audio-es"))
+                psz_path = config_GetUserDir(VLC_MUSIC_DIR);
+            else
+                psz_path = config_GetUserDir(VLC_DOWNLOAD_DIR);
         }
 
-        char *psz_sout = NULL;  // TODO conf
+        dir_path = psz_path;
+    }
+
+    char *psz_sout = NULL;  // TODO conf
 
-        if( !psz_sout && dir_path )
+    if (!psz_sout && dir_path)
+    {
+        char *psz_file = input_item_CreateFilename(input_GetItem(p_input),
+                                                   dir_path,
+                                                   INPUT_RECORD_PREFIX, NULL);
+        if (psz_file)
         {
-            char *psz_file = input_item_CreateFilename( input_GetItem(p_input),
-                                                        dir_path,
-                                                        INPUT_RECORD_PREFIX, NULL );
-            if( psz_file )
+            char* psz_file_esc = config_StringEscape(psz_file);
+            if (psz_file_esc)
             {
-                char* psz_file_esc = config_StringEscape( psz_file );
-                if ( psz_file_esc )
-                {
-                    if( asprintf( &psz_sout, "#record{dst-prefix='%s'}", psz_file_esc ) < 0 )
-                        psz_sout = NULL;
-                    free( psz_file_esc );
-                }
-                free( psz_file );
+                if (asprintf(&psz_sout, "#record{dst-prefix='%s'}", psz_file_esc) < 0)
+                    psz_sout = NULL;
+                free(psz_file_esc);
             }
+            free(psz_file);
         }
-        free( psz_path );
+    }
+    free(psz_path);
 
-        if( !psz_sout )
-            return VLC_EGENERIC;
+    if (!psz_sout)
+        return VLC_EGENERIC;
 
-        p_sys->p_sout_record = sout_NewInstance( p_input, psz_sout );
-        free( psz_sout );
+    p_sys->p_sout_record = sout_NewInstance(p_input, psz_sout);
+    free(psz_sout);
 
-        if( !p_sys->p_sout_record )
-            return VLC_EGENERIC;
-
-        vlc_list_foreach( p_es, &p_sys->es, node ) /* Only master es */
-        {
-            if( !p_es->p_dec )
-                continue;
+    if (!p_sys->p_sout_record)
+        return VLC_EGENERIC;
 
-            const struct vlc_input_decoder_cfg cfg = {
-                .fmt = &p_es->fmt,
-                .str_id = p_es->id.str_id,
-                .clock = NULL,
-                .resource = input_priv(p_input)->p_resource,
-                .sout = p_sys->p_sout_record,
-                .input_type = INPUT_TYPE_NONE,
-                .cbs = &decoder_cbs,
-                .cbs_data = p_es,
-            };
+    vlc_list_foreach (p_es, &p_sys->es, node) /* Only master es */
+    {
+        if (p_es->p_dec == NULL)
+            continue;
 
-            p_es->p_dec_record = vlc_input_decoder_New( VLC_OBJECT(p_input), &cfg );
+        const struct vlc_input_decoder_cfg cfg = {
+            .fmt = &p_es->fmt,
+            .str_id = p_es->id.str_id,
+            .clock = NULL,
+            .resource = input_priv(p_input)->p_resource,
+            .sout = p_sys->p_sout_record,
+            .input_type = INPUT_TYPE_NONE,
+            .cbs = &decoder_cbs,
+            .cbs_data = p_es,
+        };
 
-            if( p_es->p_dec_record && p_sys->b_buffering )
-                vlc_input_decoder_StartWait( p_es->p_dec_record );
-        }
-    }
-    else
-    {
-        vlc_list_foreach( p_es, &p_sys->es, node ) /* Only master es */
-        {
-            if( !p_es->p_dec_record )
-                continue;
+        p_es->p_dec_record = vlc_input_decoder_New(VLC_OBJECT(p_input), &cfg);
 
-            vlc_input_decoder_Flush(p_es->p_dec_record);
-            vlc_input_decoder_Delete( p_es->p_dec_record );
-            p_es->p_dec_record = NULL;
-        }
-        sout_StreamChainDelete( p_sys->p_sout_record, NULL );
-        p_sys->p_sout_record = NULL;
+        if (p_es->p_dec_record != NULL && p_sys->b_buffering)
+            vlc_input_decoder_StartWait(p_es->p_dec_record);
     }
 
     return VLC_SUCCESS;
@@ -1186,15 +1175,15 @@ static vlc_tick_t EsOutGetBuffering( es_out_t *out )
 
     if( !p_sys->p_pgrm )
         return 0;
-    else
-    {
-        vlc_tick_t i_stream_start, i_system_duration;
 
-        if( input_clock_GetState( p_sys->p_pgrm->p_input_clock,
-                                  &i_stream_start, &i_system_start,
-                                  &i_stream_duration, &i_system_duration ) )
-            return 0;
-    }
+    vlc_tick_t i_stream_start, i_system_duration;
+
+    /* If the input_clock is not ready, we don't have a reference point
+     * which means that buffering has not started, continue waiting. */
+    if (input_clock_GetState(p_sys->p_pgrm->p_input_clock,
+                             &i_stream_start, &i_system_start,
+                             &i_stream_duration, &i_system_duration))
+        return 0;
 
     vlc_tick_t i_delay;
 
@@ -1204,8 +1193,6 @@ static vlc_tick_t EsOutGetBuffering( es_out_t *out )
     }
     else
     {
-        vlc_tick_t i_system_duration;
-
         if( p_sys->b_paused )
         {
             i_system_duration = p_sys->i_pause_date  - i_system_start;
@@ -1580,41 +1567,35 @@ static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm )
     char *psz = NULL;
     if( p_pgrm->p_meta && vlc_meta_Get( p_pgrm->p_meta, vlc_meta_Title ) )
     {
-        if( asprintf( &psz, _("%s [%s %d]"), vlc_meta_Get( p_pgrm->p_meta, vlc_meta_Title ),
-                      _("Program"), p_pgrm->i_id ) == -1 )
-            return NULL;
+        if (asprintf(&psz, _("%s [%s %d]"), vlc_meta_Get(p_pgrm->p_meta, vlc_meta_Title),
+                     _("Program"), p_pgrm->i_id) != -1)
+            return psz;
     }
-    else
-    {
-        if( asprintf( &psz, "%s %d", _("Program"), p_pgrm->i_id ) == -1 )
-            return NULL;
-    }
-    return psz;
+    else if (asprintf(&psz, "%s %d", _("Program"), p_pgrm->i_id) != -1)
+        return psz;
+    return NULL;
 }
 
 static char *EsOutProgramGetProgramName( es_out_pgrm_t *p_pgrm )
 {
     char *psz = NULL;
     if( p_pgrm->p_meta && vlc_meta_Get( p_pgrm->p_meta, vlc_meta_Title ) )
-    {
         return strdup( vlc_meta_Get( p_pgrm->p_meta, vlc_meta_Title ) );
-    }
-    else
-    {
-        if( asprintf( &psz, "%s %d", _("Program"), p_pgrm->i_id ) == -1 )
-            return NULL;
-    }
-    return psz;
+
+    if (asprintf(&psz, "%s %d", _("Program"), p_pgrm->i_id) != -1 )
+        return psz;
+
+    return NULL;
 }
 
 static char *EsInfoCategoryName( es_out_id_t* es )
 {
     char *psz_category;
 
-    if( asprintf( &psz_category, _("Stream '%s'"), es->id.str_id ) == -1 )
-        return NULL;
+    if (asprintf(&psz_category, _("Stream '%s'"), es->id.str_id) != -1)
+        return psz_category;
 
-    return psz_category;
+    return NULL;
 }
 
 static void EsOutProgramMeta( es_out_t *out, input_source_t *source,
@@ -2208,21 +2189,21 @@ static es_out_id_t *EsOutAdd( es_out_t *out, input_source_t *source, const es_fo
 
 static bool EsIsSelected( es_out_id_t *es )
 {
-    if( es->p_master )
-    {
-        bool b_decode = false;
-        if( es->p_master->p_dec )
-        {
-            int i_channel = EsOutGetClosedCaptionsChannel( &es->fmt );
-            vlc_input_decoder_GetCcState( es->p_master->p_dec, es->fmt.i_codec,
-                                          i_channel, &b_decode );
-        }
-        return b_decode;
-    }
-    else
-    {
+    /* Some tracks, especially closed-captions, are extracted from an
+     * existing elementary stream through the packetizer or the decoder,
+     * which must be selected for the extracted track to be selected.
+     * In every other cases, we don't need to consider that. */
+    if (es->p_master == NULL)
         return es->p_dec != NULL;
+
+    bool b_decode = false;
+    if( es->p_master->p_dec )
+    {
+        int i_channel = EsOutGetClosedCaptionsChannel( &es->fmt );
+        vlc_input_decoder_GetCcState( es->p_master->p_dec, es->fmt.i_codec,
+                                      i_channel, &b_decode );
     }
+    return b_decode;
 }
 
 static void ClockUpdate(vlc_tick_t system_ts, vlc_tick_t ts, double rate,
@@ -2544,15 +2525,10 @@ static void EsOutUnselectEs( es_out_t *out, es_out_id_t *es, bool b_update )
 static bool EsOutSelectMatchPrioritized( const es_out_es_props_t *p_esprops,
                                          const es_out_id_t *es )
 {
-    /* Otherwise, fallback by priority */
     if( p_esprops->p_main_es != NULL )
-    {
-        return ( es->fmt.i_priority > p_esprops->p_main_es->fmt.i_priority );
-    }
-    else
-    {
-        return ( es->fmt.i_priority > ES_PRIORITY_NOT_DEFAULTABLE );
-    }
+        return es->fmt.i_priority > p_esprops->p_main_es->fmt.i_priority;
+
+    return es->fmt.i_priority > ES_PRIORITY_NOT_DEFAULTABLE;
 }
 
 static bool EsOutSelectHasExplicitParams( const es_out_es_props_t *p_esprops )
@@ -2818,16 +2794,17 @@ static void EsOutSelectList( es_out_t *out, enum es_format_category_e cat,
     /* Now, select all ES from es_id_list */
     foreach_es_then_es_slaves(other)
     {
-        if( other->fmt.i_cat != cat )
+        if (other->fmt.i_cat != cat ||
+            !EsOutIdMatchEsList(other, es_id_list) ||
+            EsIsSelected(other))
+        {
             continue;
+        }
 
-        if( EsOutIdMatchEsList( other, es_id_list ) && !EsIsSelected( other ) )
-        {
-            EsOutSelectEs( out, other, true );
+        EsOutSelectEs(out, other, true);
 
-            if( p_esprops->e_policy == ES_OUT_ES_POLICY_EXCLUSIVE )
-                break;
-        }
+        if (p_esprops->e_policy == ES_OUT_ES_POLICY_EXCLUSIVE)
+            break;
     }
 }
 
@@ -3145,15 +3122,15 @@ static vlc_tick_t EsOutGetTracksDelay(es_out_t *out)
     es_out_id_t *es;
     foreach_es_then_es_slaves(es)
     {
-        if (es->p_dec)
-        {
-            if (es->delay != VLC_TICK_MAX)
-                tracks_delay = __MIN(tracks_delay, es->delay);
-            else if (es->fmt.i_cat == AUDIO_ES)
-                has_audio = true;
-            else if (es->fmt.i_cat == SPU_ES)
-                has_spu = true;
-        }
+        if (es->p_dec == NULL)
+            continue;
+
+        if (es->delay != VLC_TICK_MAX)
+            tracks_delay = __MIN(tracks_delay, es->delay);
+        else if (es->fmt.i_cat == AUDIO_ES)
+            has_audio = true;
+        else if (es->fmt.i_cat == SPU_ES)
+            has_spu = true;
     }
     if (has_audio)
         tracks_delay = __MIN(tracks_delay, p_sys->i_audio_delay);
@@ -3185,17 +3162,17 @@ static int EsOutVaControlLocked( es_out_t *out, input_source_t *source,
     case ES_OUT_SET_ES_STATE:
     {
         es_out_id_t *es = va_arg( args, es_out_id_t * );
-        bool b = va_arg( args, int );
-        if( b && !EsIsSelected( es ) )
+        bool request_select = va_arg(args, int);
+        bool is_selected = EsIsSelected(es);
+        if(request_select && !is_selected)
         {
             EsOutSelectEs( out, es, true );
             return EsIsSelected( es ) ? VLC_SUCCESS : VLC_EGENERIC;
         }
-        else if( !b && EsIsSelected( es ) )
-        {
+
+        if(!request_select && is_selected)
             EsOutUnselectEs( out, es, es->p_pgrm == p_sys->p_pgrm );
-            return VLC_SUCCESS;
-        }
+
         return VLC_SUCCESS;
     }
 
@@ -3243,21 +3220,18 @@ static int EsOutVaControlLocked( es_out_t *out, input_source_t *source,
 
         foreach_es_then_es_slaves(other)
         {
-            if( i_cat == IGNORE_ES )
+            if (i_cat == IGNORE_ES && es == other)
             {
-                if (es == other)
+                if (i_query == ES_OUT_RESTART_ES && es->p_dec != NULL)
                 {
-                    if (i_query == ES_OUT_RESTART_ES && es->p_dec != NULL)
-                    {
-                        EsOutDestroyDecoder(out, es);
-                        EsOutCreateDecoder(out, es);
-                    }
-                    else if( i_query == ES_OUT_SET_ES )
-                    {
-                        EsOutSelect(out, es, true);
-                    }
-                    break;
+                    EsOutDestroyDecoder(out, es);
+                    EsOutCreateDecoder(out, es);
                 }
+                else if (i_query == ES_OUT_SET_ES)
+                {
+                    EsOutSelect(out, es, true);
+                }
+                break;
             }
             else if (i_cat == UNKNOWN_ES || other->fmt.i_cat == i_cat)
             {
@@ -3287,16 +3261,16 @@ static int EsOutVaControlLocked( es_out_t *out, input_source_t *source,
             return VLC_EGENERIC;
         foreach_es_then_es_slaves(other)
         {
-            if (es == other)
+            if (es != other)
+                continue;
+
+            if (EsIsSelected(other))
             {
-                if (EsIsSelected(other))
-                {
-                    EsOutUnselectEs(out, other, other->p_pgrm == p_sys->p_pgrm);
-                    EsOutStopFreeVout( out );
-                    return VLC_SUCCESS;
-                }
-                break;
+                EsOutUnselectEs(out, other, other->p_pgrm == p_sys->p_pgrm);
+                EsOutStopFreeVout(out);
+                return VLC_SUCCESS;
             }
+            break;
         }
         return VLC_EGENERIC;
     }
@@ -3401,68 +3375,75 @@ static int EsOutVaControlLocked( es_out_t *out, input_source_t *source,
         {
             /* Check buffering state on master clock update */
             EsOutDecodersStopBuffering( out, false );
+            return VLC_SUCCESS;
         }
-        else if( p_pgrm == p_sys->p_pgrm )
-        {
-            if( p_sys->p_next_frame_es != NULL )
-                return VLC_SUCCESS;
 
-            /* Last pcr/clock update was late. We need to compensate by offsetting
-               from the clock the rendering dates */
-            if( i_late > 0 && ( !priv->p_sout ||
-                            !priv->b_out_pace_control ) )
-            {
-                /* input_clock_GetJitter returns compound delay:
-                 * - initial pts delay (buffering/caching)
-                 * - jitter compensation
-                 * - track offset pts delay
-                 * updated on input_clock_Update
-                 * Late/jitter amount is updated from median of late values */
-                vlc_tick_t i_clock_total_delay = input_clock_GetJitter( p_pgrm->p_input_clock );
-
-                /* Current jitter */
-                vlc_tick_t i_new_jitter = i_clock_total_delay
-                                        - p_sys->i_tracks_pts_delay
-                                        - p_sys->i_pts_delay;
-
-                /* If the clock update is late, we have 2 possibilities:
-                 *  - offset rendering a bit more by increasing the total pts-delay
-                 *  - ignore, set clock to a new reference ahead of previous one
-                 *    and flush buffers (because all previous pts will now be late) */
-
-                /* Avoid dangerously high value */
-                /* If the jitter increase is over our max or the total hits the maximum */
-                if( i_new_jitter > priv->i_jitter_max ||
-                    i_clock_total_delay > INPUT_PTS_DELAY_MAX ||
-                    /* jitter is always 0 due to median calculation first output
-                       and low delay can't allow non reversible jitter increase
-                       in branch below */
-                    (b_low_delay && i_late > priv->i_jitter_max) )
-                {
-                    msg_Err( p_sys->p_input,
-                             "ES_OUT_SET_(GROUP_)PCR  is called %d ms late (jitter of %d ms ignored)",
-                             (int)MS_FROM_VLC_TICK(i_late),
-                             (int)MS_FROM_VLC_TICK(i_new_jitter) );
+        if (p_pgrm != p_sys->p_pgrm || p_sys->p_next_frame_es != NULL)
+            return VLC_SUCCESS;
 
-                    /* don't change the current jitter */
-                    i_new_jitter = p_sys->i_pts_jitter;
-                }
-                else
-                {
-                    msg_Err( p_sys->p_input,
-                             "ES_OUT_SET_(GROUP_)PCR  is called %d ms late (pts_delay increased to %d ms)",
-                             (int)MS_FROM_VLC_TICK(i_late),
-                             (int)MS_FROM_VLC_TICK(i_clock_total_delay) );
-                }
+        /* The PCR is not considered late, there is no compensation needed. */
+        if (i_late <= 0)
+            return VLC_SUCCESS;
+
+        /* The output is paced by another client, there is no clock
+         * compensation possible. */
+        if (priv->p_sout != NULL && priv->b_out_pace_control)
+            return VLC_SUCCESS;
 
-                /* Force a rebufferization when we are too late */
-                EsOutControlLocked( out, source, ES_OUT_RESET_PCR );
+        /* Last pcr/clock update was late. We need to compensate by offsetting
+         * from the clock the rendering dates. */
+
+        /* input_clock_GetJitter returns compound delay:
+         * - initial pts delay (buffering/caching)
+         * - jitter compensation
+         * - track offset pts delay
+         * updated on input_clock_Update
+         * Late/jitter amount is updated from median of late values */
+        vlc_tick_t i_clock_total_delay = input_clock_GetJitter(p_pgrm->p_input_clock);
+
+        /* Current jitter */
+        vlc_tick_t i_new_jitter = i_clock_total_delay
+                                - p_sys->i_tracks_pts_delay
+                                - p_sys->i_pts_delay;
+
+        /* If the clock update is late, we have 2 possibilities:
+         *  - offset rendering a bit more by increasing the total pts-delay
+         *  - ignore, set clock to a new reference ahead of previous one
+         *    and flush buffers (because all previous pts will now be late) */
+
+        /* Avoid dangerously high value */
+        /* If the jitter increase is over our max or the total hits the maximum */
+        if (i_new_jitter > priv->i_jitter_max ||
+            i_clock_total_delay > INPUT_PTS_DELAY_MAX ||
+            /* jitter is always 0 due to median calculation first output
+               and low delay can't allow non reversible jitter increase
+               in branch below */
+            (b_low_delay && i_late > priv->i_jitter_max))
+        {
 
-                EsOutPrivControlLocked( out, source, ES_OUT_PRIV_SET_JITTER,
-                                        p_sys->i_pts_delay, i_new_jitter,
-                                        p_sys->i_cr_average );
-            }
+            msg_Err(p_sys->p_input,
+                    "ES_OUT_SET_(GROUP_)PCR  is called %d ms late (jitter of %d ms ignored)",
+                    (int)MS_FROM_VLC_TICK(i_late),
+                    (int)MS_FROM_VLC_TICK(i_new_jitter));
+
+            /* don't change the current jitter */
+            i_new_jitter = p_sys->i_pts_jitter;
         }
+        else
+        {
+            msg_Err(p_sys->p_input,
+                    "ES_OUT_SET_(GROUP_)PCR  is called %d ms late (pts_delay increased to %d ms)",
+                    (int)MS_FROM_VLC_TICK(i_late),
+                    (int)MS_FROM_VLC_TICK(i_clock_total_delay));
+        }
+
+        /* Force a rebufferization when we are too late */
+        EsOutControlLocked(out, source, ES_OUT_RESET_PCR);
+
+        EsOutPrivControlLocked(out, source, ES_OUT_PRIV_SET_JITTER,
+                               p_sys->i_pts_delay, i_new_jitter,
+                               p_sys->i_cr_average);
+
         return VLC_SUCCESS;
     }
 
@@ -3900,37 +3881,38 @@ static int EsOutVaPrivControlLocked( es_out_t *out, input_source_t *source,
         if( source != p_sys->main_source )
             return VLC_SUCCESS;
 
-        if( !p_sys->b_buffering )
+        if (p_sys->b_buffering)
         {
-            vlc_tick_t i_delay;
+            input_SendEventTimes(p_sys->p_input, 0.0, VLC_TICK_INVALID,
+                                 i_normal_time, i_length);
+            return VLC_SUCCESS;
+        }
 
-            /* Fix for buffering delay */
-            if( !input_priv(p_sys->p_input)->p_sout ||
-                !input_priv(p_sys->p_input)->b_out_pace_control )
-                i_delay = EsOutGetBuffering( out );
-            else
-                i_delay = 0;
+        vlc_tick_t i_delay;
 
-            if( i_time != VLC_TICK_INVALID )
-            {
-                i_time -= i_delay;
-                if( i_time < VLC_TICK_0 )
-                    i_time = VLC_TICK_0;
-            }
+        /* Fix for buffering delay */
+        if (!input_priv(p_sys->p_input)->p_sout ||
+            !input_priv(p_sys->p_input)->b_out_pace_control)
+            i_delay = EsOutGetBuffering(out);
+        else
+            i_delay = 0;
 
-            if( i_length != 0 )
-                f_position -= (double)i_delay / i_length;
-            if( f_position < 0 )
-                f_position = 0;
+        if (i_time != VLC_TICK_INVALID)
+        {
+            i_time -= i_delay;
+            if (i_time < VLC_TICK_0)
+                i_time = VLC_TICK_0;
+        }
 
-            assert( i_normal_time >= VLC_TICK_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_normal_time, i_length );
-        }
-        else
-            input_SendEventTimes( p_sys->p_input, 0.0, VLC_TICK_INVALID,
-                                  i_normal_time, i_length );
+        assert(i_normal_time >= VLC_TICK_0);
+
+        input_SendEventTimes(p_sys->p_input, f_position, i_time,
+                             i_normal_time, i_length);
         return VLC_SUCCESS;
     }
     case ES_OUT_PRIV_SET_JITTER:
@@ -3953,16 +3935,15 @@ static int EsOutVaPrivControlLocked( es_out_t *out, input_source_t *source,
         p_sys->i_cr_average = i_cr_average;
         p_sys->i_tracks_pts_delay = i_tracks_pts_delay;
 
-        if (b_change_clock)
-        {
-            i_pts_delay += i_pts_jitter + i_tracks_pts_delay;
+        if (!b_change_clock)
+            return VLC_SUCCESS;
 
-            vlc_list_foreach(pgrm, &p_sys->programs, node)
-            {
-                input_clock_SetJitter(pgrm->p_input_clock, i_pts_delay,
-                                      i_cr_average);
-                vlc_clock_main_SetInputDejitter(pgrm->p_main_clock, i_pts_delay);
-            }
+        i_pts_delay += i_pts_jitter + i_tracks_pts_delay;
+        vlc_list_foreach(pgrm, &p_sys->programs, node)
+        {
+            input_clock_SetJitter(pgrm->p_input_clock,
+                                  i_pts_delay, i_cr_average);
+            vlc_clock_main_SetInputDejitter(pgrm->p_main_clock, i_pts_delay);
         }
         return VLC_SUCCESS;
     }
@@ -4644,16 +4625,15 @@ static void EsOutDeleteInfoEs( es_out_t *out, es_out_id_t *es )
     es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);
     input_thread_t *p_input = p_sys->p_input;
     input_item_t   *p_item = input_priv(p_input)->p_item;
-    char* psz_info_category;
+    char* psz_info_category = EsInfoCategoryName(es);
+    if (unlikely(psz_info_category == NULL))
+        return;
 
-    if( likely( psz_info_category = EsInfoCategoryName( es ) ) )
-    {
-        int ret = input_item_DelInfo( p_item, psz_info_category, NULL );
-        free( psz_info_category );
+    int ret = input_item_DelInfo(p_item, psz_info_category, NULL);
+    free(psz_info_category);
 
-        if( ret == VLC_SUCCESS && p_sys->input_type != INPUT_TYPE_PREPARSING )
-            input_SendEventMetaInfo( p_input );
-    }
+    if (ret == VLC_SUCCESS && p_sys->input_type != INPUT_TYPE_PREPARSING)
+        input_SendEventMetaInfo(p_input);
 }
 
 es_out_id_t *vlc_es_id_get_out(vlc_es_id_t *id)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/db905e5c7a1dbdee4c5ef08e452e5e8c9ca2bce8...ed5f57a144aaadc7aeef1dd6a443e5e169bb4845

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/db905e5c7a1dbdee4c5ef08e452e5e8c9ca2bce8...ed5f57a144aaadc7aeef1dd6a443e5e169bb4845
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list