diff mbox

[FFmpeg-devel,v2] avformat/tee.c: steal bsf option before passing to fifo muxer

Message ID 20191013211425.18923-1-junli1026@gmail.com
State Accepted
Commit 155508c6e925f4f2f5e77087a7e1925b3de735ff
Headers show

Commit Message

Jun Li Oct. 13, 2019, 9:14 p.m. UTC
Fix #7620
In the case tee muxer with both "bsf" and "use_fifo" parameters
will trigger this bug. Tee muxer will first steal parameters (like "f",
"select"...) and then "use_fifo" will try reading out remaining options
and pass them to fifo as option "format_options".
Current code miss the part of stealing "bsf" options.
---
 libavformat/tee.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Comments

Jun Li Oct. 17, 2019, 8:09 a.m. UTC | #1
On Sun, Oct 13, 2019 at 2:14 PM Jun Li <junli1026@gmail.com> wrote:

> Fix #7620
> In the case tee muxer with both "bsf" and "use_fifo" parameters
> will trigger this bug. Tee muxer will first steal parameters (like "f",
> "select"...) and then "use_fifo" will try reading out remaining options
> and pass them to fifo as option "format_options".
> Current code miss the part of stealing "bsf" options.
> ---
>  libavformat/tee.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/libavformat/tee.c b/libavformat/tee.c
> index 89a4ceb280..d91993354b 100644
> --- a/libavformat/tee.c
> +++ b/libavformat/tee.c
> @@ -159,7 +159,7 @@ static void close_slaves(AVFormatContext *avf)
>  static int open_slave(AVFormatContext *avf, char *slave, TeeSlave
> *tee_slave)
>  {
>      int i, ret;
> -    AVDictionary *options = NULL;
> +    AVDictionary *options = NULL, *bsf_options = NULL;
>      AVDictionaryEntry *entry;
>      char *filename;
>      char *format = NULL, *select = NULL, *on_fail = NULL;
> @@ -186,6 +186,12 @@ static int open_slave(AVFormatContext *avf, char
> *slave, TeeSlave *tee_slave)
>      STEAL_OPTION("onfail", on_fail);
>      STEAL_OPTION("use_fifo", use_fifo);
>      STEAL_OPTION("fifo_options", fifo_options_str);
> +    entry = NULL;
> +    while ((entry = av_dict_get(options, "bsfs", entry,
> AV_DICT_IGNORE_SUFFIX))) {
> +        /* trim out strlen("bsfs") characters from key */
> +        av_dict_set(&bsf_options, entry->key + 4, entry->value, 0);
> +        av_dict_set(&options, entry->key, NULL, 0);
> +    }
>
>      ret = parse_slave_failure_policy_option(on_fail, tee_slave);
>      if (ret < 0) {
> @@ -311,8 +317,8 @@ static int open_slave(AVFormatContext *avf, char
> *slave, TeeSlave *tee_slave)
>      }
>
>      entry = NULL;
> -    while (entry = av_dict_get(options, "bsfs", NULL,
> AV_DICT_IGNORE_SUFFIX)) {
> -        const char *spec = entry->key + strlen("bsfs");
> +    while (entry = av_dict_get(bsf_options, "", NULL,
> AV_DICT_IGNORE_SUFFIX)) {
> +        const char *spec = entry->key;
>          if (*spec) {
>              if (strspn(spec, slave_bsfs_spec_sep) != 1) {
>                  av_log(avf, AV_LOG_ERROR,
> @@ -352,7 +358,7 @@ static int open_slave(AVFormatContext *avf, char
> *slave, TeeSlave *tee_slave)
>              }
>          }
>
> -        av_dict_set(&options, entry->key, NULL, 0);
> +        av_dict_set(&bsf_options, entry->key, NULL, 0);
>      }
>
>      for (i = 0; i < avf->nb_streams; i++){
> @@ -399,6 +405,7 @@ end:
>      av_free(select);
>      av_free(on_fail);
>      av_dict_free(&options);
> +    av_dict_free(&bsf_options);
>      av_freep(&tmp_select);
>      return ret;
>  }
> --
> 2.17.1
>
>
Ping
Liu Steven Oct. 25, 2019, 4:26 a.m. UTC | #2
> 在 2019年10月17日,下午4:09,Jun Li <junli1026@gmail.com> 写道:
> 
> On Sun, Oct 13, 2019 at 2:14 PM Jun Li <junli1026@gmail.com> wrote:
> 
>> Fix #7620
>> In the case tee muxer with both "bsf" and "use_fifo" parameters
>> will trigger this bug. Tee muxer will first steal parameters (like "f",
>> "select"...) and then "use_fifo" will try reading out remaining options
>> and pass them to fifo as option "format_options".
>> Current code miss the part of stealing "bsf" options.
>> ---
>> libavformat/tee.c | 15 +++++++++++----
>> 1 file changed, 11 insertions(+), 4 deletions(-)
>> 
>> diff --git a/libavformat/tee.c b/libavformat/tee.c
>> index 89a4ceb280..d91993354b 100644
>> --- a/libavformat/tee.c
>> +++ b/libavformat/tee.c
>> @@ -159,7 +159,7 @@ static void close_slaves(AVFormatContext *avf)
>> static int open_slave(AVFormatContext *avf, char *slave, TeeSlave
>> *tee_slave)
>> {
>>     int i, ret;
>> -    AVDictionary *options = NULL;
>> +    AVDictionary *options = NULL, *bsf_options = NULL;
>>     AVDictionaryEntry *entry;
>>     char *filename;
>>     char *format = NULL, *select = NULL, *on_fail = NULL;
>> @@ -186,6 +186,12 @@ static int open_slave(AVFormatContext *avf, char
>> *slave, TeeSlave *tee_slave)
>>     STEAL_OPTION("onfail", on_fail);
>>     STEAL_OPTION("use_fifo", use_fifo);
>>     STEAL_OPTION("fifo_options", fifo_options_str);
>> +    entry = NULL;
>> +    while ((entry = av_dict_get(options, "bsfs", entry,
>> AV_DICT_IGNORE_SUFFIX))) {
>> +        /* trim out strlen("bsfs") characters from key */
>> +        av_dict_set(&bsf_options, entry->key + 4, entry->value, 0);
>> +        av_dict_set(&options, entry->key, NULL, 0);
>> +    }
>> 
>>     ret = parse_slave_failure_policy_option(on_fail, tee_slave);
>>     if (ret < 0) {
>> @@ -311,8 +317,8 @@ static int open_slave(AVFormatContext *avf, char
>> *slave, TeeSlave *tee_slave)
>>     }
>> 
>>     entry = NULL;
>> -    while (entry = av_dict_get(options, "bsfs", NULL,
>> AV_DICT_IGNORE_SUFFIX)) {
>> -        const char *spec = entry->key + strlen("bsfs");
>> +    while (entry = av_dict_get(bsf_options, "", NULL,
>> AV_DICT_IGNORE_SUFFIX)) {
>> +        const char *spec = entry->key;
>>         if (*spec) {
>>             if (strspn(spec, slave_bsfs_spec_sep) != 1) {
>>                 av_log(avf, AV_LOG_ERROR,
>> @@ -352,7 +358,7 @@ static int open_slave(AVFormatContext *avf, char
>> *slave, TeeSlave *tee_slave)
>>             }
>>         }
>> 
>> -        av_dict_set(&options, entry->key, NULL, 0);
>> +        av_dict_set(&bsf_options, entry->key, NULL, 0);
>>     }
>> 
>>     for (i = 0; i < avf->nb_streams; i++){
>> @@ -399,6 +405,7 @@ end:
>>     av_free(select);
>>     av_free(on_fail);
>>     av_dict_free(&options);
>> +    av_dict_free(&bsf_options);
>>     av_freep(&tmp_select);
>>     return ret;
>> }
>> --
>> 2.17.1
>> 
>> 
> Ping

will apply
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox

Patch

diff --git a/libavformat/tee.c b/libavformat/tee.c
index 89a4ceb280..d91993354b 100644
--- a/libavformat/tee.c
+++ b/libavformat/tee.c
@@ -159,7 +159,7 @@  static void close_slaves(AVFormatContext *avf)
 static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
 {
     int i, ret;
-    AVDictionary *options = NULL;
+    AVDictionary *options = NULL, *bsf_options = NULL;
     AVDictionaryEntry *entry;
     char *filename;
     char *format = NULL, *select = NULL, *on_fail = NULL;
@@ -186,6 +186,12 @@  static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
     STEAL_OPTION("onfail", on_fail);
     STEAL_OPTION("use_fifo", use_fifo);
     STEAL_OPTION("fifo_options", fifo_options_str);
+    entry = NULL;
+    while ((entry = av_dict_get(options, "bsfs", entry, AV_DICT_IGNORE_SUFFIX))) {
+        /* trim out strlen("bsfs") characters from key */
+        av_dict_set(&bsf_options, entry->key + 4, entry->value, 0);
+        av_dict_set(&options, entry->key, NULL, 0);
+    }
 
     ret = parse_slave_failure_policy_option(on_fail, tee_slave);
     if (ret < 0) {
@@ -311,8 +317,8 @@  static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
     }
 
     entry = NULL;
-    while (entry = av_dict_get(options, "bsfs", NULL, AV_DICT_IGNORE_SUFFIX)) {
-        const char *spec = entry->key + strlen("bsfs");
+    while (entry = av_dict_get(bsf_options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
+        const char *spec = entry->key;
         if (*spec) {
             if (strspn(spec, slave_bsfs_spec_sep) != 1) {
                 av_log(avf, AV_LOG_ERROR,
@@ -352,7 +358,7 @@  static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
             }
         }
 
-        av_dict_set(&options, entry->key, NULL, 0);
+        av_dict_set(&bsf_options, entry->key, NULL, 0);
     }
 
     for (i = 0; i < avf->nb_streams; i++){
@@ -399,6 +405,7 @@  end:
     av_free(select);
     av_free(on_fail);
     av_dict_free(&options);
+    av_dict_free(&bsf_options);
     av_freep(&tmp_select);
     return ret;
 }