[vlc-commits] [Git][videolan/vlc][master] 2 commits: sout: duplicate: suffix and forward ES string IDs

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Tue Nov 7 15:35:09 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
3d943044 by Alaric Senat at 2023-11-07T14:35:45+00:00
sout: duplicate: suffix and forward ES string IDs

For uniqueness of the ES string IDs, `duplicate` should synthesize
different ES IDs for each duplicated ES.
This patch adds a `/duplicated-stream` suffix to the duplicated ES
followed by the stream number. The original ES keeps their former ES ID.

Example:

               +-----------+ -- video/1 ---------------------->
               |           | -- audio/2 ---------------------->
 -- video/1 -->| duplicate | -- video/1/duplicated-stream-1 -->
 -- audio/2 -->|           | -- audio/2/duplicated-stream-1 -->
               |           | -- video/1/duplicated-stream-2 -->
               +-----------+ -- audio/2/duplicated-stream-2 -->

- - - - -
b271fe99 by Alaric Senat at 2023-11-07T14:35:45+00:00
sout: duplicate: allow custom ES ID suffix

Add an optional parameter to the duplicated streams.
The ES ID suffix can be used to synthesize meaningful ES IDs.

By default, duplicated ES string IDs follows the
`.../duplicated-stream-N` scheme where `...` is the former ES string ID
and `N` is the duplicated stream index. This approach is great for
scenarios where users don't mind ES naming or for simple stream output
chains.
For advanced stream output chains where ES ID needs to be easily
readable or tied to a context, specifying the ES ID suffix become
important.

For example, the following pipeline outputs an HLS stream with two
renditions of the video track.

```
duplicate{
    dst="",                                                                # Forward all original tracks to the sink.
    dst="transcode{vcodec=h264,height=480}", select="video", suffix="low", # Duplicate and downscale the video track.
}:hls{
    variants={
      {video/1},    # Rendition 1: The original video track.
      {video/1/low} # Rendition 2: Suffixed downscaled video track.
    }
}
```

- - - - -


1 changed file:

- modules/stream_out/duplicate.c


Changes:

=====================================
modules/stream_out/duplicate.c
=====================================
@@ -67,6 +67,7 @@ static void  SetPCR( sout_stream_t *, vlc_tick_t );
 typedef struct {
     sout_stream_t *stream;
     char *select_chain;
+    char *es_id_suffix;
 } duplicated_stream_t;
 
 typedef struct
@@ -76,6 +77,7 @@ typedef struct
 
 typedef struct {
     void *id;
+    char *es_id;
     /* Reference to the duplicated output stream. */
     sout_stream_t *stream_owner;
 } duplicated_id_t;
@@ -172,6 +174,25 @@ static int Open( vlc_object_t *p_this )
                 }
             }
         }
+        else if( !strncmp( p_cfg->psz_name, "suffix", strlen( "suffix" ) ) )
+        {
+            const char *value = p_cfg->psz_value;
+            if( value == NULL || value[0] == '\0' )
+                continue;
+
+            if( p_sys->streams.size == 0 )
+            {
+                msg_Err( p_stream, " * ignore ES ID suffix `%s'", value );
+            }
+            else
+            {
+                msg_Dbg( p_stream, " * apply ES ID suffix `%s'", value );
+                char *name = strdup( value );
+                if( unlikely(name == NULL) )
+                    goto nomem;
+                vlc_vector_last_ref( &p_sys->streams )->es_id_suffix = name;
+            }
+        }
         else
         {
             msg_Err( p_stream, " * ignore unknown option `%s'", p_cfg->psz_name );
@@ -208,12 +229,35 @@ static void Close( vlc_object_t * p_this )
     {
         sout_StreamChainDelete( dup_stream->stream, p_stream->p_next );
         free( dup_stream->select_chain );
+        free( dup_stream->es_id_suffix );
     }
     vlc_vector_destroy( &p_sys->streams );
 
     free( p_sys );
 }
 
+static char *
+SuffixESID( size_t stream_index, const char *es_id, const char *suffix )
+{
+    char *dup_es_id;
+    int wrote;
+    if( suffix == NULL )
+    {
+        if( stream_index == 0 )
+        {
+            /* first stream just forwards the original ES ID. */
+            return strdup( es_id );
+        }
+
+        wrote = asprintf(
+            &dup_es_id, "%s/duplicated-stream-%zu", es_id, stream_index );
+    }
+    else
+        wrote = asprintf( &dup_es_id, "%s/%s", es_id, suffix );
+
+    return (wrote != -1) ? dup_es_id : NULL;
+}
+
 /*****************************************************************************
  * Add:
  *****************************************************************************/
@@ -239,18 +283,24 @@ Add( sout_stream_t *p_stream, const es_format_t *p_fmt, const char *es_id )
 
         if( ESSelected(p_stream->obj.logger, p_fmt, dup_stream->select_chain) )
         {
-            /* FIXME(Alaric): suffix the string id with the duplicated track
-             * count. */
+            char *dup_es_id =
+                SuffixESID( idx, es_id, dup_stream->es_id_suffix );
+            if( unlikely(dup_es_id == NULL) )
+                goto error;
+
             void *next_id = sout_StreamIdAdd( dup_stream->stream,
-                                              p_fmt, es_id );
+                                              p_fmt, dup_es_id );
             if( next_id != NULL )
             {
                 msg_Dbg( p_stream, "    - added for output %zu", idx );
-                const duplicated_id_t dup_id = {
-                    .stream_owner = dup_stream->stream, .id = next_id};
+                const duplicated_id_t dup_id = {.id = next_id,
+                                                .es_id = dup_es_id,
+                                                .stream_owner =
+                                                    dup_stream->stream};
                 if( !vlc_vector_push(&id->dup_ids, dup_id) )
                 {
                     sout_StreamIdDel( dup_stream->stream, next_id );
+                    free( dup_id.es_id );
                     goto error;
                 }
             }
@@ -283,6 +333,7 @@ static void Del( sout_stream_t *p_stream, void *_id )
     vlc_vector_foreach_ref( dup_id, &id->dup_ids )
     {
         sout_StreamIdDel( dup_id->stream_owner, dup_id->id );
+        free( dup_id->es_id );
     }
     vlc_vector_destroy( &id->dup_ids );
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/88d6858186874a7ce49318d03761e9a4aa95f563...b271fe99d442a187153921e71cc9c7267d1db1cd

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/88d6858186874a7ce49318d03761e9a4aa95f563...b271fe99d442a187153921e71cc9c7267d1db1cd
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