Re: [FFmpeg-devel] [PATCH] avformat/hls: release mem resource to fix memleak

2017-12-30 Thread Derek Buitenhuis
On 12/31/2017 5:21 AM, Aman Gupta wrote:
> I really don't think it makes any sense in this case, since it is expected
> that the av_opt_get will fail on non-http io contexts. It doesn't matter if
> the failure is due to AVERROR_OPTION_NOT_FOUND or AVERROR(ENOMEM). The only
> thing that matters is whether http_version_opt is set or remains NULL.

A behavioral change that may occur due to OOM rather than failing is not
very fun to debug.

Anyway, part of my point was that using error checks inconsistently often
leads to sloppiness elsewhere, because, well, checks are not always used,
and judgement on when to use them may not always be right, or the underlying
implementation of the unchecked function may change, such that it now does
matter (assumptions of the API being checked as per documentation, etc.).
There are long term benefits to a culture of always checking, IMO. I'm
sure people will reply to disagree with me, of course.

> Anyway, I don't feel strongly about this. If you think the extra
> instructions to store and compare the return value make this code cleaner
> or more secure, so be it. I will send a patch with the requested changes.

OK. (Fretting about extra instructions for return value checks in playlist
code is a tad silly...)

Sorry for the rant -- this sort of lax API use has been a pain in the
past when trying to change around implementation details, where API
users have neglected to check return values.

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2] avformat/hls: release mem resource to fix memleak

2017-12-30 Thread Derek Buitenhuis
On 12/31/2017 5:50 AM, Aman Gupta wrote:
> +int r = av_opt_get(v->input, "http_version", AV_OPT_SEARCH_CHILDREN, 
> _version_opt);
> +if (r >= 0) {
> +c->http_multiple = strncmp((const char *)http_version_opt, 
> "1.1", 3) == 0;
> +av_freep(_version_opt);
> +}

I mean, we should probably actually fail on ENOMEM, but I guess av_opt_get is
poorly designed in the sense that it can return fatal and nonfatal sorts of
errors, so I guess this gets no complaints from me.

Looking closer into the implementation of av_opt_get just kind of made me sad,
though. It has a bunch of unchecked allocations, such that it can return 0 but
have the string be NULL. I'll send a patch tomorrow to address that properly.
(Yes, I strongly believe handling allocation failures is still relevant in 
2017...)

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2] avformat/hls: release mem resource to fix memleak

2017-12-30 Thread Aman Gupta
From: Steven Liu 

fix CID: 1426991

Signed-off-by: Steven Liu 
Signed-off-by: Aman Gupta 
---
 libavformat/hls.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index d9f7c6de4d..950cc4c3bd 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -1473,8 +1473,11 @@ reload:
 
 if (c->http_multiple == -1) {
 uint8_t *http_version_opt = NULL;
-av_opt_get(v->input, "http_version", AV_OPT_SEARCH_CHILDREN, 
_version_opt);
-c->http_multiple = http_version_opt && strncmp((const char 
*)http_version_opt, "1.1", 3) == 0;
+int r = av_opt_get(v->input, "http_version", AV_OPT_SEARCH_CHILDREN, 
_version_opt);
+if (r >= 0) {
+c->http_multiple = strncmp((const char *)http_version_opt, "1.1", 
3) == 0;
+av_freep(_version_opt);
+}
 }
 
 seg = next_segment(v);
-- 
2.14.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/hls: release mem resource to fix memleak

2017-12-30 Thread Aman Gupta
On Sat, Dec 30, 2017 at 2:14 PM Derek Buitenhuis 
wrote:

> On 12/30/2017 5:50 PM, Aman Gupta wrote:
> > There is already a check in place to prevent strncmp from being called
> with
> > NULL.
>
> The point before still holds.
>
> Are people really arguing against consistent use of error checking?
> Inconsistent
> standards of error checking are how bugs and security issues happen.


I really don't think it makes any sense in this case, since it is expected
that the av_opt_get will fail on non-http io contexts. It doesn't matter if
the failure is due to AVERROR_OPTION_NOT_FOUND or AVERROR(ENOMEM). The only
thing that matters is whether http_version_opt is set or remains NULL.

Anyway, I don't feel strongly about this. If you think the extra
instructions to store and compare the return value make this code cleaner
or more secure, so be it. I will send a patch with the requested changes.

Aman


>
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/hls: release mem resource to fix memleak

2017-12-30 Thread Steven Liu


> 在 2017年12月31日,上午6:14,Derek Buitenhuis  写道:
> 
>> On 12/30/2017 5:50 PM, Aman Gupta wrote:
>> There is already a check in place to prevent strncmp from being called with
>> NULL.
> 
> The point before still holds.
> 
> Are people really arguing against consistent use of error checking? 
> Inconsistent
> standards of error checking are how bugs and security issues happen.
> 

ok, patch will update next year :D
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 6/6] avformat: deprecate AVFormatContext filename field

2017-12-30 Thread James Almer
On 12/30/2017 6:16 PM, Marton Balint wrote:
> Signed-off-by: Marton Balint 
> ---
>  doc/APIchanges |  4 
>  libavformat/avformat.h |  5 +
>  libavformat/mux.c  | 10 ++
>  libavformat/utils.c|  8 
>  libavformat/version.h  |  5 -
>  5 files changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 7ca097486e..073a75ec44 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,10 @@ libavutil: 2017-10-21
>  
>  API changes, most recent first:
>  
> +201x-xx-xx - xxx - lavf 58.5.100 - avformat.h
> +  Deprecate AVFormatContext filename field which had limited length, use the
> +  new dynamically allocated url field instead.
> +
>  2017-xx-xx - xxx - lavf 58.4.100 - avformat.h
>Add url field to AVFormatContext and add ff_format_set_url helper function.
>  
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index c3229ed0e1..49ad5d1570 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -1382,13 +1382,18 @@ typedef struct AVFormatContext {
>   */
>  AVStream **streams;
>  
> +#if FF_API_FORMAT_FILENAME
>  /**
>   * input or output filename
>   *
>   * - demuxing: set by avformat_open_input()
>   * - muxing: may be set by the caller before avformat_write_header()
> + *
> + * @deprecated Use url instead.
>   */
> +attribute_deprecated
>  char filename[1024];
> +#endif
>  
>  /**
>   * input or output URL. Unlike the old filename field, this field has no
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index de63f2ca25..a13f0e3a1b 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -187,7 +187,11 @@ int avformat_alloc_output_context2(AVFormatContext 
> **avctx, AVOutputFormat *ofor
>  s->priv_data = NULL;
>  
>  if (filename) {
> +#if FF_API_FORMAT_FILENAME
> +FF_DISABLE_DEPRECATION_WARNINGS
>  av_strlcpy(s->filename, filename, sizeof(s->filename));
> +FF_ENABLE_DEPRECATION_WARNINGS
> +#endif
>  if (!(s->url = av_strdup(filename)))
>  goto nomem;
>  
> @@ -255,7 +259,13 @@ static int init_muxer(AVFormatContext *s, AVDictionary 
> **options)
>  (ret = av_opt_set_dict2(s->priv_data, , AV_OPT_SEARCH_CHILDREN)) 
> < 0)
>  goto fail;
>  
> +#if FF_API_FORMAT_FILENAME
> +FF_DISABLE_DEPRECATION_WARNINGS
>  if (!s->url && !(s->url = av_strdup(s->filename))) {
> +FF_ENABLE_DEPRECATION_WARNINGS
> +#else
> +if (!s->url && !(s->url = av_strdup(""))) {
> +#endif
>  ret = AVERROR(ENOMEM);
>  goto fail;
>  }
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index a74046591e..c9136a3a3b 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -556,7 +556,11 @@ int avformat_open_input(AVFormatContext **ps, const char 
> *filename,
>  goto fail;
>  }
>  
> +#if FF_API_FORMAT_FILENAME
> +FF_DISABLE_DEPRECATION_WARNINGS
>  av_strlcpy(s->filename, filename ? filename : "", sizeof(s->filename));
> +FF_ENABLE_DEPRECATION_WARNINGS
> +#endif
>  if ((ret = init_input(s, filename, )) < 0)
>  goto fail;
>  s->probe_score = ret;
> @@ -5636,5 +5640,9 @@ void ff_format_set_url(AVFormatContext *s, char *url)
>  av_assert0(url);
>  av_freep(>url);
>  s->url = url;
> +#if FF_API_FORMAT_FILENAME
> +FF_DISABLE_DEPRECATION_WARNINGS
>  av_strlcpy(s->filename, url, sizeof(s->filename));
> +FF_ENABLE_DEPRECATION_WARNINGS
> +#endif
>  }
> diff --git a/libavformat/version.h b/libavformat/version.h
> index 49b9906a20..b8e50db8c7 100644
> --- a/libavformat/version.h
> +++ b/libavformat/version.h
> @@ -32,7 +32,7 @@
>  // Major bumping may affect Ticket5467, 5421, 5451(compatibility with 
> Chromium)
>  // Also please add any ticket numbers that you believe might be affected here
>  #define LIBAVFORMAT_VERSION_MAJOR  58
> -#define LIBAVFORMAT_VERSION_MINOR   4
> +#define LIBAVFORMAT_VERSION_MINOR   5

IMO, just leave it as 4. One version bump to deprecate a field and add a
replacement is enough.

>  #define LIBAVFORMAT_VERSION_MICRO 100
>  
>  #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
> @@ -82,6 +82,9 @@
>  #ifndef FF_API_OLD_AVIO_EOF_0
>  #define FF_API_OLD_AVIO_EOF_0   (LIBAVFORMAT_VERSION_MAJOR < 59)
>  #endif
> +#ifndef FF_API_FORMAT_FILENAME
> +#define FF_API_FORMAT_FILENAME  (LIBAVFORMAT_VERSION_MAJOR < 59)
> +#endif
>  
>  
>  #ifndef FF_API_R_FRAME_RATE
> 

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/6] avformat: add url field to AVFormatContext

2017-12-30 Thread Derek Buitenhuis
On 12/30/2017 9:16 PM, Marton Balint wrote:
> + * - muxing: may be set by the caller before avformat_write_header() (or
> + *   avformat_init_output() if that is called first). Set to an
> + *   empty string if it was NULL in avformat_init_output().

For the muxing case, it would be nice if it was explicitly documented by who 
and how
the string is allocated and by who and how it is freed.

- Derek

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/hls: release mem resource to fix memleak

2017-12-30 Thread Derek Buitenhuis
On 12/30/2017 5:50 PM, Aman Gupta wrote:
> There is already a check in place to prevent strncmp from being called with
> NULL.

The point before still holds.

Are people really arguing against consistent use of error checking? Inconsistent
standards of error checking are how bugs and security issues happen.

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] tcp: properly return EOF

2017-12-30 Thread Aaron Levinson

On 12/30/2017 8:44 AM, wm4 wrote:

There is no POSIX error code for EOF - recv() signals EOF by simply
returning 0. But libavformat recently changed its conventionts and


"conventionts" -> "conventions"


requires an explicit AVERROR_EOF, or it might get into an endless retry
loop, consuming 100% CPU while doing nothing.
---
  libavformat/tcp.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index fef0729da6..8773493df1 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -225,6 +225,8 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
  return ret;
  }
  ret = recv(s->fd, buf, size, 0);
+if (ret == 0)
+return AVERROR_EOF;
  return ret < 0 ? ff_neterrno() : ret;
  }
  



LGTM
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 6/6] avformat: deprecate AVFormatContext filename field

2017-12-30 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 doc/APIchanges |  4 
 libavformat/avformat.h |  5 +
 libavformat/mux.c  | 10 ++
 libavformat/utils.c|  8 
 libavformat/version.h  |  5 -
 5 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 7ca097486e..073a75ec44 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,10 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+201x-xx-xx - xxx - lavf 58.5.100 - avformat.h
+  Deprecate AVFormatContext filename field which had limited length, use the
+  new dynamically allocated url field instead.
+
 2017-xx-xx - xxx - lavf 58.4.100 - avformat.h
   Add url field to AVFormatContext and add ff_format_set_url helper function.
 
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index c3229ed0e1..49ad5d1570 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1382,13 +1382,18 @@ typedef struct AVFormatContext {
  */
 AVStream **streams;
 
+#if FF_API_FORMAT_FILENAME
 /**
  * input or output filename
  *
  * - demuxing: set by avformat_open_input()
  * - muxing: may be set by the caller before avformat_write_header()
+ *
+ * @deprecated Use url instead.
  */
+attribute_deprecated
 char filename[1024];
+#endif
 
 /**
  * input or output URL. Unlike the old filename field, this field has no
diff --git a/libavformat/mux.c b/libavformat/mux.c
index de63f2ca25..a13f0e3a1b 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -187,7 +187,11 @@ int avformat_alloc_output_context2(AVFormatContext 
**avctx, AVOutputFormat *ofor
 s->priv_data = NULL;
 
 if (filename) {
+#if FF_API_FORMAT_FILENAME
+FF_DISABLE_DEPRECATION_WARNINGS
 av_strlcpy(s->filename, filename, sizeof(s->filename));
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 if (!(s->url = av_strdup(filename)))
 goto nomem;
 
@@ -255,7 +259,13 @@ static int init_muxer(AVFormatContext *s, AVDictionary 
**options)
 (ret = av_opt_set_dict2(s->priv_data, , AV_OPT_SEARCH_CHILDREN)) < 
0)
 goto fail;
 
+#if FF_API_FORMAT_FILENAME
+FF_DISABLE_DEPRECATION_WARNINGS
 if (!s->url && !(s->url = av_strdup(s->filename))) {
+FF_ENABLE_DEPRECATION_WARNINGS
+#else
+if (!s->url && !(s->url = av_strdup(""))) {
+#endif
 ret = AVERROR(ENOMEM);
 goto fail;
 }
diff --git a/libavformat/utils.c b/libavformat/utils.c
index a74046591e..c9136a3a3b 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -556,7 +556,11 @@ int avformat_open_input(AVFormatContext **ps, const char 
*filename,
 goto fail;
 }
 
+#if FF_API_FORMAT_FILENAME
+FF_DISABLE_DEPRECATION_WARNINGS
 av_strlcpy(s->filename, filename ? filename : "", sizeof(s->filename));
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 if ((ret = init_input(s, filename, )) < 0)
 goto fail;
 s->probe_score = ret;
@@ -5636,5 +5640,9 @@ void ff_format_set_url(AVFormatContext *s, char *url)
 av_assert0(url);
 av_freep(>url);
 s->url = url;
+#if FF_API_FORMAT_FILENAME
+FF_DISABLE_DEPRECATION_WARNINGS
 av_strlcpy(s->filename, url, sizeof(s->filename));
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 }
diff --git a/libavformat/version.h b/libavformat/version.h
index 49b9906a20..b8e50db8c7 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  58
-#define LIBAVFORMAT_VERSION_MINOR   4
+#define LIBAVFORMAT_VERSION_MINOR   5
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
@@ -82,6 +82,9 @@
 #ifndef FF_API_OLD_AVIO_EOF_0
 #define FF_API_OLD_AVIO_EOF_0   (LIBAVFORMAT_VERSION_MAJOR < 59)
 #endif
+#ifndef FF_API_FORMAT_FILENAME
+#define FF_API_FORMAT_FILENAME  (LIBAVFORMAT_VERSION_MAJOR < 59)
+#endif
 
 
 #ifndef FF_API_R_FRAME_RATE
-- 
2.13.6

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 4/6] avformat/hls: migrate to AVFormatContext->url

2017-12-30 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavformat/hls.c|   4 +-
 libavformat/hlsenc.c | 230 +--
 2 files changed, 116 insertions(+), 118 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index dccc7c7dd2..865278e6f0 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -1672,7 +1672,7 @@ static int nested_io_open(AVFormatContext *s, AVIOContext 
**pb, const char *url,
 av_log(s, AV_LOG_ERROR,
"A HLS playlist item '%s' referred to an external file '%s'. "
"Opening this file was forbidden for security reasons\n",
-   s->filename, url);
+   s->url, url);
 return AVERROR(EPERM);
 }
 
@@ -1810,7 +1810,7 @@ static int hls_read_header(AVFormatContext *s)
 update_options(>http_proxy, "http_proxy", u);
 }
 
-if ((ret = parse_playlist(c, s->filename, NULL, s->pb)) < 0)
+if ((ret = parse_playlist(c, s->url, NULL, s->pb)) < 0)
 goto fail;
 
 if ((ret = save_avio_options(s)) < 0)
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e6f3241765..cd99a4c9c3 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -275,7 +275,7 @@ static void hlsenc_io_close(AVFormatContext *s, AVIOContext 
**pb, char *filename
 
 static void set_http_options(AVFormatContext *s, AVDictionary **options, 
HLSContext *c)
 {
-int http_base_proto = ff_is_http_proto(s->filename);
+int http_base_proto = ff_is_http_proto(s->url);
 
 if (c->method) {
 av_dict_set(options, "method", c->method, 0);
@@ -290,14 +290,17 @@ static void set_http_options(AVFormatContext *s, 
AVDictionary **options, HLSCont
 
 }
 
-static int replace_int_data_in_filename(char *buf, int buf_size, const char 
*filename, char placeholder, int64_t number)
+static int replace_int_data_in_filename(AVFormatContext *s, const char 
*filename, char placeholder, int64_t number)
 {
 const char *p;
-char *q, buf1[20], c;
-int nd, len, addchar_count;
+char *new_filename;
+char c;
+int nd, addchar_count;
 int found_count = 0;
+AVBPrint buf;
+
+av_bprint_init(, 0, AV_BPRINT_SIZE_UNLIMITED);
 
-q = buf;
 p = filename;
 for (;;) {
 c = *p;
@@ -314,13 +317,7 @@ static int replace_int_data_in_filename(char *buf, int 
buf_size, const char *fil
 }
 
 if (*(p + addchar_count) == placeholder) {
-len = snprintf(buf1, sizeof(buf1), "%0*"PRId64, (number < 0) ? 
nd : nd++, number);
-if (len < 1)  // returned error or empty buf1
-goto fail;
-if ((q - buf + len) > buf_size - 1)
-goto fail;
-memcpy(q, buf1, len);
-q += len;
+av_bprintf(, "%0*"PRId64, (number < 0) ? nd : nd++, 
number);
 p += (addchar_count + 1);
 addchar_count = 0;
 found_count++;
@@ -329,17 +326,17 @@ static int replace_int_data_in_filename(char *buf, int 
buf_size, const char *fil
 } else
 addchar_count = 1;
 
-while (addchar_count--)
-if ((q - buf) < buf_size - 1)
-*q++ = *p++;
-else
-goto fail;
+av_bprint_append_data(, p, addchar_count);
+p += addchar_count;
 }
-*q = '\0';
+if (!av_bprint_is_complete()) {
+av_bprint_finalize(, NULL);
+return -1;
+}
+if (av_bprint_finalize(, _filename) < 0 || !new_filename)
+return -1;
+ff_format_set_url(s, new_filename);
 return found_count;
-fail:
-*q = '\0';
-return -1;
 }
 
 static void write_styp(AVIOContext *pb)
@@ -408,7 +405,7 @@ static int hls_delete_old_segments(AVFormatContext *s, 
HLSContext *hls,
 if (hls->segment_filename) {
 dirname = av_strdup(hls->segment_filename);
 } else {
-dirname = av_strdup(vs->avf->filename);
+dirname = av_strdup(vs->avf->url);
 }
 if (!dirname) {
 ret = AVERROR(ENOMEM);
@@ -435,7 +432,7 @@ static int hls_delete_old_segments(AVFormatContext *s, 
HLSContext *hls,
 av_strlcat(path, segment->filename, path_size);
 }
 
-proto = avio_find_protocol_name(s->filename);
+proto = avio_find_protocol_name(s->url);
 if (hls->method || (proto && !av_strcasecmp(proto, "http"))) {
 av_dict_set(, "method", "DELETE", 0);
 if ((ret = vs->avf->io_open(vs->avf, , path, AVIO_FLAG_WRITE, 
)) < 0)
@@ -505,12 +502,12 @@ static int do_encrypt(AVFormatContext *s, VariantStream 
*vs)
 AVIOContext *pb;
 uint8_t key[KEYSIZE];
 
-len = strlen(s->filename) + 4 + 1;
+len = strlen(s->url) + 4 + 1;
 hls->key_basename = av_mallocz(len);
 if (!hls->key_basename)
 return AVERROR(ENOMEM);
 
-av_strlcpy(hls->key_basename, s->filename, len);
+av_strlcpy(hls->key_basename, s->url, len);
 

[FFmpeg-devel] [PATCH 3/6] avdevice: migrate to AVFormatContext->url

2017-12-30 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavdevice/alsa.c  |  4 ++--
 libavdevice/avfoundation.m  |  2 +-
 libavdevice/bktr.c  |  2 +-
 libavdevice/caca.c  |  2 +-
 libavdevice/decklink_common.cpp |  2 +-
 libavdevice/decklink_dec.cpp|  4 ++--
 libavdevice/decklink_enc.cpp|  4 ++--
 libavdevice/dshow.c |  2 +-
 libavdevice/fbdev_dec.c |  4 ++--
 libavdevice/fbdev_enc.c |  4 ++--
 libavdevice/gdigrab.c   |  2 +-
 libavdevice/iec61883.c  |  8 
 libavdevice/jack.c  |  6 +++---
 libavdevice/lavfi.c |  2 +-
 libavdevice/libcdio.c   |  6 +++---
 libavdevice/libndi_newtek_dec.c |  2 +-
 libavdevice/libndi_newtek_enc.c |  4 ++--
 libavdevice/openal-dec.c|  2 +-
 libavdevice/opengl_enc.c|  2 +-
 libavdevice/oss_dec.c   |  2 +-
 libavdevice/oss_enc.c   |  2 +-
 libavdevice/pulse_audio_dec.c   |  4 ++--
 libavdevice/pulse_audio_enc.c   |  4 ++--
 libavdevice/sdl2.c  |  2 +-
 libavdevice/sndio_dec.c |  2 +-
 libavdevice/sndio_enc.c |  2 +-
 libavdevice/v4l2.c  | 16 +---
 libavdevice/v4l2enc.c   |  4 ++--
 libavdevice/vfwcap.c|  4 ++--
 libavdevice/xcbgrab.c   |  8 
 libavdevice/xv.c|  2 +-
 31 files changed, 59 insertions(+), 57 deletions(-)

diff --git a/libavdevice/alsa.c b/libavdevice/alsa.c
index 1bbff30d5c..1b21beb6d5 100644
--- a/libavdevice/alsa.c
+++ b/libavdevice/alsa.c
@@ -177,8 +177,8 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, 
snd_pcm_stream_t mode,
 snd_pcm_uframes_t buffer_size, period_size;
 uint64_t layout = ctx->streams[0]->codecpar->channel_layout;
 
-if (ctx->filename[0] == 0) audio_device = "default";
-else   audio_device = ctx->filename;
+if (ctx->url[0] == 0) audio_device = "default";
+else  audio_device = ctx->url;
 
 if (*codec_id == AV_CODEC_ID_NONE)
 *codec_id = DEFAULT_CODEC_ID;
diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
index e2ddf47dbe..a540f6a079 100644
--- a/libavdevice/avfoundation.m
+++ b/libavdevice/avfoundation.m
@@ -259,7 +259,7 @@ static void destroy_context(AVFContext* ctx)
 static void parse_device_name(AVFormatContext *s)
 {
 AVFContext *ctx = (AVFContext*)s->priv_data;
-char *tmp = av_strdup(s->filename);
+char *tmp = av_strdup(s->url);
 char *save;
 
 if (tmp[0] != ':') {
diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c
index 418247dc4e..993cc19ac7 100644
--- a/libavdevice/bktr.c
+++ b/libavdevice/bktr.c
@@ -294,7 +294,7 @@ static int grab_read_header(AVFormatContext *s1)
 st->codecpar->height = s->height;
 st->avg_frame_rate = framerate;
 
-if (bktr_init(s1->filename, s->width, s->height, s->standard,
+if (bktr_init(s1->url, s->width, s->height, s->standard,
   >video_fd, >tuner_fd, -1, 0.0) < 0) {
 ret = AVERROR(EIO);
 goto out;
diff --git a/libavdevice/caca.c b/libavdevice/caca.c
index 93cc0ffd25..47de8247dc 100644
--- a/libavdevice/caca.c
+++ b/libavdevice/caca.c
@@ -178,7 +178,7 @@ static int caca_write_header(AVFormatContext *s)
 }
 
 if (!c->window_title)
-c->window_title = av_strdup(s->filename);
+c->window_title = av_strdup(s->url);
 caca_set_display_title(c->display, c->window_title);
 caca_set_display_time(c->display, av_rescale_q(1, st->codec->time_base, 
AV_TIME_BASE_Q));
 
diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 6ef2c529f4..d0c043cfc6 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -393,7 +393,7 @@ int ff_decklink_list_formats(AVFormatContext *avctx, 
decklink_direction_t direct
 }
 
 av_log(avctx, AV_LOG_INFO, "Supported formats for 
'%s':\n\tformat_code\tdescription",
-   avctx->filename);
+   avctx->url);
 while (itermode->Next() == S_OK) {
 BMDTimeValue tb_num, tb_den;
 mode->GetFrameRate(_num, _den);
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 94dae26003..62bf52bfde 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -939,7 +939,7 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx)
 cctx->raw_format = MKBETAG('v','2','1','0');
 }
 
-strcpy (fname, avctx->filename);
+av_strlcpy(fname, avctx->url, sizeof(fname));
 tmp=strchr (fname, '@');
 if (tmp != NULL) {
 av_log(avctx, AV_LOG_WARNING, "The @mode syntax is deprecated and will 
be removed. Please use the -format_code option.\n");
@@ -954,7 +954,7 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx)
 /* Get input device. */
 if (ctx->dl->QueryInterface(IID_IDeckLinkInput, (void **) >dli) != 
S_OK) {
 av_log(avctx, AV_LOG_ERROR, "Could not open input device from 

[FFmpeg-devel] [PATCH 5/6] avformat: migrate to AVFormatContext->url

2017-12-30 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavformat/concatdec.c  |  4 ++--
 libavformat/dashenc.c| 16 
 libavformat/fifo.c   |  8 
 libavformat/flvenc.c |  4 ++--
 libavformat/gxfenc.c |  4 ++--
 libavformat/hdsenc.c | 24 
 libavformat/img2dec.c|  4 ++--
 libavformat/img2enc.c|  4 ++--
 libavformat/matroskadec.c|  4 ++--
 libavformat/mlvdec.c |  4 ++--
 libavformat/mov.c|  2 +-
 libavformat/movenc.c | 10 +-
 libavformat/mpeg.c   |  4 ++--
 libavformat/mpegtsenc.c  |  2 +-
 libavformat/options.c|  2 +-
 libavformat/rtsp.c   | 18 --
 libavformat/rtspdec.c|  4 ++--
 libavformat/rtspenc.c|  4 +++-
 libavformat/sapdec.c |  2 +-
 libavformat/sapenc.c | 10 --
 libavformat/sdp.c|  4 ++--
 libavformat/segment.c| 36 +---
 libavformat/smoothstreamingenc.c | 12 ++--
 libavformat/tee.c|  4 ++--
 libavformat/utils.c  |  2 +-
 libavformat/webm_chunk.c | 10 +-
 26 files changed, 111 insertions(+), 91 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0e189012ad..5b91d6e86d 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -126,10 +126,10 @@ static int add_file(AVFormatContext *avf, char *filename, 
ConcatFile **rfile,
 url = filename;
 filename = NULL;
 } else {
-url_len = strlen(avf->filename) + strlen(filename) + 16;
+url_len = strlen(avf->url) + strlen(filename) + 16;
 if (!(url = av_malloc(url_len)))
 FAIL(AVERROR(ENOMEM));
-ff_make_absolute_url(url, url_len, avf->filename, filename);
+ff_make_absolute_url(url, url_len, avf->url, filename);
 av_freep();
 }
 
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 3345b89118..59c55cc8b7 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -685,7 +685,7 @@ static int write_manifest(AVFormatContext *s, int final)
 AVIOContext *out;
 char temp_filename[1024];
 int ret, i;
-const char *proto = avio_find_protocol_name(s->filename);
+const char *proto = avio_find_protocol_name(s->url);
 int use_rename = proto && !strcmp(proto, "file");
 static unsigned int warned_non_file = 0;
 AVDictionaryEntry *title = av_dict_get(s->metadata, "title", NULL, 0);
@@ -694,7 +694,7 @@ static int write_manifest(AVFormatContext *s, int final)
 if (!use_rename && !warned_non_file++)
 av_log(s, AV_LOG_ERROR, "Cannot use rename on non file protocol, this 
may lead to races and temporary partial files\n");
 
-snprintf(temp_filename, sizeof(temp_filename), use_rename ? "%s.tmp" : 
"%s", s->filename);
+snprintf(temp_filename, sizeof(temp_filename), use_rename ? "%s.tmp" : 
"%s", s->url);
 set_http_options(, c);
 ret = dashenc_io_open(s, >mpd_out, temp_filename, );
 if (ret < 0) {
@@ -771,7 +771,7 @@ static int write_manifest(AVFormatContext *s, int final)
 dashenc_io_close(s, >mpd_out, temp_filename);
 
 if (use_rename) {
-if ((ret = avpriv_io_move(temp_filename, s->filename)) < 0)
+if ((ret = avpriv_io_move(temp_filename, s->url)) < 0)
 return ret;
 }
 
@@ -852,14 +852,14 @@ static int dash_init(AVFormatContext *s)
 if (c->single_file)
 c->use_template = 0;
 
-av_strlcpy(c->dirname, s->filename, sizeof(c->dirname));
+av_strlcpy(c->dirname, s->url, sizeof(c->dirname));
 ptr = strrchr(c->dirname, '/');
 if (ptr) {
 av_strlcpy(basename, [1], sizeof(basename));
 ptr[1] = '\0';
 } else {
 c->dirname[0] = '\0';
-av_strlcpy(basename, s->filename, sizeof(basename));
+av_strlcpy(basename, s->url, sizeof(basename));
 }
 
 ptr = strrchr(basename, '.');
@@ -1018,7 +1018,7 @@ static int dash_write_header(AVFormatContext *s)
 }
 ret = write_manifest(s, 0);
 if (!ret)
-av_log(s, AV_LOG_VERBOSE, "Manifest written to: %s\n", s->filename);
+av_log(s, AV_LOG_VERBOSE, "Manifest written to: %s\n", s->url);
 return ret;
 }
 
@@ -1117,7 +1117,7 @@ static int dash_flush(AVFormatContext *s, int final, int 
stream)
 DASHContext *c = s->priv_data;
 int i, ret = 0;
 
-const char *proto = avio_find_protocol_name(s->filename);
+const char *proto = avio_find_protocol_name(s->url);
 int use_rename = proto && !strcmp(proto, "file");
 
 int cur_flush_segment_index = 0;
@@ -1325,7 +1325,7 @@ static int dash_write_trailer(AVFormatContext *s)
 snprintf(filename, sizeof(filename), "%s%s", c->dirname, 
os->initfile);
 unlink(filename);
 }
-unlink(s->filename);
+

[FFmpeg-devel] [PATCH 2/6] fftools, tools, examples: migrate to AVFormatContext->url

2017-12-30 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 doc/examples/transcode_aac.c |  7 +--
 fftools/ffmpeg.c | 16 
 fftools/ffmpeg_opt.c |  8 
 fftools/ffplay.c |  6 +++---
 fftools/ffprobe.c|  2 +-
 tools/uncoded_frame.c|  2 +-
 6 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/doc/examples/transcode_aac.c b/doc/examples/transcode_aac.c
index 9fd5c00d60..3c7688cd33 100644
--- a/doc/examples/transcode_aac.c
+++ b/doc/examples/transcode_aac.c
@@ -171,8 +171,11 @@ static int open_output_file(const char *filename,
 goto cleanup;
 }
 
-av_strlcpy((*output_format_context)->filename, filename,
-   sizeof((*output_format_context)->filename));
+if (!((*output_format_context)->url = av_strdup(filename))) {
+fprintf(stderr, "Could not allocate url.\n");
+error = AVERROR(ENOMEM);
+goto cleanup;
+}
 
 /* Find the encoder to be used by its name. */
 if (!(output_codec = avcodec_find_encoder(AV_CODEC_ID_AAC))) {
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 6aff3366c5..56c077921c 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1563,7 +1563,7 @@ static void print_final_stats(int64_t total_size)
 uint64_t total_packets = 0, total_size = 0;
 
 av_log(NULL, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
-   i, f->ctx->filename);
+   i, f->ctx->url);
 
 for (j = 0; j < f->nb_streams; j++) {
 InputStream *ist = input_streams[f->ist_index + j];
@@ -1597,7 +1597,7 @@ static void print_final_stats(int64_t total_size)
 uint64_t total_packets = 0, total_size = 0;
 
 av_log(NULL, AV_LOG_VERBOSE, "Output file #%d (%s):\n",
-   i, of->ctx->filename);
+   i, of->ctx->url);
 
 for (j = 0; j < of->ctx->nb_streams; j++) {
 OutputStream *ost = output_streams[of->ost_index + j];
@@ -2105,7 +2105,7 @@ static void check_decode_result(InputStream *ist, int 
*got_output, int ret)
 
 if (exit_on_error && *got_output && ist) {
 if (ist->decoded_frame->decode_error_flags || 
(ist->decoded_frame->flags & AV_FRAME_FLAG_CORRUPT)) {
-av_log(NULL, AV_LOG_FATAL, "%s: corrupt decoded frame in stream 
%d\n", input_files[ist->file_index]->ctx->filename, ist->st->index);
+av_log(NULL, AV_LOG_FATAL, "%s: corrupt decoded frame in stream 
%d\n", input_files[ist->file_index]->ctx->url, ist->st->index);
 exit_program(1);
 }
 }
@@ -2989,7 +2989,7 @@ static int check_init_output_file(OutputFile *of, int 
file_index)
 //assert_avoptions(of->opts);
 of->header_written = 1;
 
-av_dump_format(of->ctx, file_index, of->ctx->filename, 1);
+av_dump_format(of->ctx, file_index, of->ctx->url, 1);
 
 if (sdp_filename || want_sdp)
 print_sdp();
@@ -4252,7 +4252,7 @@ static int process_input(int file_index)
 }
 if (ret < 0) {
 if (ret != AVERROR_EOF) {
-print_error(is->filename, ret);
+print_error(is->url, ret);
 if (exit_on_error)
 exit_program(1);
 }
@@ -4301,7 +4301,7 @@ static int process_input(int file_index)
 goto discard_packet;
 
 if (exit_on_error && (pkt.flags & AV_PKT_FLAG_CORRUPT)) {
-av_log(NULL, AV_LOG_FATAL, "%s: corrupt input packet in stream %d\n", 
is->filename, pkt.stream_index);
+av_log(NULL, AV_LOG_FATAL, "%s: corrupt input packet in stream %d\n", 
is->url, pkt.stream_index);
 exit_program(1);
 }
 
@@ -4668,11 +4668,11 @@ static int transcode(void)
 av_log(NULL, AV_LOG_ERROR,
"Nothing was written into output file %d (%s), because "
"at least one of its streams received no packets.\n",
-   i, os->filename);
+   i, os->url);
 continue;
 }
 if ((ret = av_write_trailer(os)) < 0) {
-av_log(NULL, AV_LOG_ERROR, "Error writing trailer of %s: %s\n", 
os->filename, av_err2str(ret));
+av_log(NULL, AV_LOG_ERROR, "Error writing trailer of %s: %s\n", 
os->url, av_err2str(ret));
 if (exit_on_error)
 exit_program(1);
 }
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index a6e36ac822..9ddeea18ff 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1272,7 +1272,7 @@ static int choose_encoder(OptionsContext *o, 
AVFormatContext *s, OutputStream *o
 if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == 
AVMEDIA_TYPE_SUBTITLE) {
 MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
 if (!codec_name) {
-ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, 
s->filename,
+ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, 
s->url,
  NULL, 

[FFmpeg-devel] [PATCH 1/6] avformat: add url field to AVFormatContext

2017-12-30 Thread Marton Balint
This will replace the 1024 character limited filename field. Compatiblity for
output contexts are provided by copying filename field to URL if URL is unset
and by providing an internal function for muxers to set both url and filename
at once.

Signed-off-by: Marton Balint 
---
 doc/APIchanges |  3 +++
 libavformat/avformat.h | 12 
 libavformat/internal.h |  7 +++
 libavformat/mux.c  | 11 ++-
 libavformat/utils.c| 14 ++
 libavformat/version.h  |  2 +-
 6 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 3c9f237596..7ca097486e 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2017-xx-xx - xxx - lavf 58.4.100 - avformat.h
+  Add url field to AVFormatContext and add ff_format_set_url helper function.
+
 2017-xx-xx - xxx - lavc 58.9.100 - avcodec.h
   Deprecate av_lockmgr_register(). You need to build FFmpeg with threading
   support enabled to get basic thread-safety (which is the default build
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 4f2798a871..c3229ed0e1 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1391,6 +1391,18 @@ typedef struct AVFormatContext {
 char filename[1024];
 
 /**
+ * input or output URL. Unlike the old filename field, this field has no
+ * length restriction.
+ *
+ * - demuxing: set by avformat_open_input(), initialized to an empty
+ * string if url parameter was NULL in avformat_open_input().
+ * - muxing: may be set by the caller before avformat_write_header() (or
+ *   avformat_init_output() if that is called first). Set to an
+ *   empty string if it was NULL in avformat_init_output().
+ */
+char *url;
+
+/**
  * Position of the first frame of the component, in
  * AV_TIME_BASE fractional seconds. NEVER set this value directly:
  * It is deduced from the AVStream values.
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 0cd0556dc7..1e2a3e05a1 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -696,4 +696,11 @@ int ff_interleaved_peek(AVFormatContext *s, int stream,
 int ff_lock_avformat(void);
 int ff_unlock_avformat(void);
 
+/**
+ * Set AVFormatContext url field to the provided pointer. The pointer must
+ * point to a valid string. The existing url field is freed if necessary. Also
+ * set the legacy filename field to the same string which was provided in url.
+ */
+void ff_format_set_url(AVFormatContext *s, char *url);
+
 #endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/mux.c b/libavformat/mux.c
index ea9f13fdf5..de63f2ca25 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -186,8 +186,12 @@ int avformat_alloc_output_context2(AVFormatContext 
**avctx, AVOutputFormat *ofor
 } else
 s->priv_data = NULL;
 
-if (filename)
+if (filename) {
 av_strlcpy(s->filename, filename, sizeof(s->filename));
+if (!(s->url = av_strdup(filename)))
+goto nomem;
+
+}
 *avctx = s;
 return 0;
 nomem:
@@ -251,6 +255,11 @@ static int init_muxer(AVFormatContext *s, AVDictionary 
**options)
 (ret = av_opt_set_dict2(s->priv_data, , AV_OPT_SEARCH_CHILDREN)) < 
0)
 goto fail;
 
+if (!s->url && !(s->url = av_strdup(s->filename))) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
 #if FF_API_LAVF_AVCTX
 FF_DISABLE_DEPRECATION_WARNINGS
 if (s->nb_streams && s->streams[0]->codec->flags & AV_CODEC_FLAG_BITEXACT) 
{
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 2185a6f05b..fdfd3a088d 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -551,6 +551,11 @@ int avformat_open_input(AVFormatContext **ps, const char 
*filename,
 if ((ret = av_opt_set_dict(s, )) < 0)
 goto fail;
 
+if (!(s->url = av_strdup(filename ? filename : ""))) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
 av_strlcpy(s->filename, filename ? filename : "", sizeof(s->filename));
 if ((ret = init_input(s, filename, )) < 0)
 goto fail;
@@ -4357,6 +4362,7 @@ void avformat_free_context(AVFormatContext *s)
 av_freep(>streams);
 flush_packet_queue(s);
 av_freep(>internal);
+av_freep(>url);
 av_free(s);
 }
 
@@ -5624,3 +5630,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
 return st->internal->avctx->time_base;
 #endif
 }
+
+void ff_format_set_url(AVFormatContext *s, char *url)
+{
+av_assert0(url);
+av_freep(>url);
+s->url = url;
+av_strlcpy(s->filename, url, sizeof(s->filename));
+}
diff --git a/libavformat/version.h b/libavformat/version.h
index 5ced041f0a..49b9906a20 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you 

Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_framerate: calculate interpolation as integer

2017-12-30 Thread Marton Balint


On Mon, 25 Dec 2017, Michael Niedermayer wrote:


On Sat, Dec 23, 2017 at 11:17:38PM +0100, Marton Balint wrote:

It was truncated to int later on anyway. Fate test changes are due to rounding
instead of truncation.

Signed-off-by: Marton Balint 
---
 libavfilter/vf_framerate.c | 22 +---
 tests/ref/fate/filter-framerate-12bit-down | 40 +++---
 tests/ref/fate/filter-framerate-12bit-up   | 40 +++---
 tests/ref/fate/filter-framerate-up |  4 +--
 4 files changed, 55 insertions(+), 51 deletions(-)


I didnt check the differnces so this isnt a full review but iam in favor
of this patch



Ping for the series. Will push this patch soon, probably will wait a 
bit more for the second one.


Regards,
Marton
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] Global options to compile FFmpeg with only audio-related features

2017-12-30 Thread Cyber Sinh
Hi Ronald,

Checking AVMEDIA_TYPE seems to be the best way to split audio and video codecs.
But what is the best way to exclude demuxers and parsers which have no sense 
for audio (because they are intended to be used only with video/image without 
audio for example)?

Thanks! 

-Message d'origine-
De : ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] De la part de Ronald 
S. Bultje
Envoyé : samedi 30 décembre 2017 18:15
À : FFmpeg development discussions and patches 
Objet : Re: [FFmpeg-devel] Global options to compile FFmpeg with only 
audio-related features

Hi,

On Sat, Dec 30, 2017 at 11:28 AM, Derek Buitenhuis < 
derek.buitenh...@gmail.com> wrote:

> On 12/30/2017 4:00 PM, Cyber Sinh wrote:
> > What do you think?
>
> That patches are welcome :).


Just to be clear: I'm not OK with a list of audio or video thingies in 
configure. Similar to the scraping of allcodecs.c, we should be able to 
classify them based on their AVMEDIA_TYPE and use that classification 
automatically in configure to do what you say.

Just to prevent you from doing a lot of work that won't be upstreamable for 
maintenance reasons.

Ronald
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/exr: Check buf_size more completely

2017-12-30 Thread Michael Niedermayer
On Fri, Dec 29, 2017 at 03:00:19AM +0100, Michael Niedermayer wrote:
> Fixes: Out of heap array read
> Fixes: 4683/clusterfuzz-testcase-minimized-6152313673613312
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/exr.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)

applied


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] avfilter/vf_interlace : add checkasm for lowpass_line and AVX2 version

2017-12-30 Thread Martin Vignali
> > >>
> > >> This broke several interlace fate tests, including the new checkasm
> one
> > >> you added.
> > >>
> 
>

New patch in attach for AVX2 version
i add a process of only 1* mmsize, before the loop (who process 2 * mmsize
at each loop)
Pass fate test for me (osX, x86_64).

Martin


0001-avfilter-x86-vf_interlace-add-AVX2-version.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] h264: fix RTSP stream decoding

2017-12-30 Thread Michael Niedermayer
On Sat, Dec 30, 2017 at 12:48:19AM +0300, ser...@gavrushkin.com wrote:
> > Please add "Fixes ticket #6422" to the commit message.
> > 
> > And maybe remove "rtsp" from the commit title, the issue
> > is reproducible with files.
> 
> Done.
> 
> Please feel free to edit commit title/message as you wish for merge.
> 
> Thank you, 
> Sergey
> 
> -
> 
> 
> 
> From e90ef7b56d4147ff6555468f0154321b55596846 Mon Sep 17 00:00:00 2001
> From: Sergey Gavrushkin >
> Date: Fri, 29 Dec 2017 20:03:50 +0300
> Subject: [PATCH] h264: fix decoding
> 
> Fixes ticket #6422 . It is a regression fix for an issue that was introduced 
> in commit
> 98c97994c5b90bdae02accb155eeceeb5224b8ef. Variable err_recognition is
> ignored while extradata is decoded and the whole decoding process is
> failed due to timeout.
> ---
> libavcodec/h264_parse.c | 12 ++--
> 1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
> index fee28d9..009d50c 100644
> --- a/libavcodec/h264_parse.c
> +++ b/libavcodec/h264_parse.c
> @@ -347,7 +347,7 @@ int ff_h264_init_poc(int pic_field_poc[2], int *pic_poc,
> }
> 
> static int decode_extradata_ps(const uint8_t *data, int size, H264ParamSets 
> *ps,
> -   int is_avc, void *logctx)
> +   int is_avc, int err_recognition, void *logctx)
> {
> H2645Packet pkt = { 0 };
> int i, ret = 0;
> @@ -363,13 +363,13 @@ static int decode_extradata_ps(const uint8_t *data, int 
> size, H264ParamSets *ps,
> switch (nal->type) {
> case H264_NAL_SPS:
> ret = ff_h264_decode_seq_parameter_set(>gb, logctx, ps, 0);
> -if (ret < 0)
> +if (ret < 0 && (err_recognition & AV_EF_EXPLODE))
> goto fail;
> break;
> case H264_NAL_PPS:
> ret = ff_h264_decode_picture_parameter_set(>gb, logctx, ps,
>nal->size_bits);
> -if (ret < 0)
> +if (ret < 0 && (err_recognition & AV_EF_EXPLODE))
> goto fail;
> break;
> default:

The error code returned by decode_extradata_ps() is inconsistent after this
its not "if any failed" it is returning an error if the last failed

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avfilter: add entropy filter

2017-12-30 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |   4 +
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/vf_entropy.c | 206 +++
 4 files changed, 212 insertions(+)
 create mode 100644 libavfilter/vf_entropy.c

diff --git a/doc/filters.texi b/doc/filters.texi
index f651f1234d..0e3f4cd78d 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8220,6 +8220,10 @@ Set pal8 output pixel format. This option does not work 
with codebook
 length greater than 256.
 @end table
 
+@section entropy
+
+Measure graylevel entropy in histogram of color channels of video frames.
+
 @section fade
 
 Apply a fade-in/out effect to the input video.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 8bde542163..7d9f2330ca 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -184,6 +184,7 @@ OBJS-$(CONFIG_DRAWGRID_FILTER)   += vf_drawbox.o
 OBJS-$(CONFIG_DRAWTEXT_FILTER)   += vf_drawtext.o
 OBJS-$(CONFIG_EDGEDETECT_FILTER) += vf_edgedetect.o
 OBJS-$(CONFIG_ELBG_FILTER)   += vf_elbg.o
+OBJS-$(CONFIG_ENTROPY_FILTER)+= vf_entropy.o
 OBJS-$(CONFIG_EQ_FILTER) += vf_eq.o
 OBJS-$(CONFIG_EROSION_FILTER)+= vf_neighbor.o
 OBJS-$(CONFIG_EXTRACTPLANES_FILTER)  += vf_extractplanes.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 67c073091f..7635a8a583 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -194,6 +194,7 @@ static void register_all(void)
 REGISTER_FILTER(DRAWTEXT,   drawtext,   vf);
 REGISTER_FILTER(EDGEDETECT, edgedetect, vf);
 REGISTER_FILTER(ELBG,   elbg,   vf);
+REGISTER_FILTER(ENTROPY,entropy,vf);
 REGISTER_FILTER(EQ, eq, vf);
 REGISTER_FILTER(EROSION,erosion,vf);
 REGISTER_FILTER(EXTRACTPLANES,  extractplanes,  vf);
diff --git a/libavfilter/vf_entropy.c b/libavfilter/vf_entropy.c
new file mode 100644
index 00..dbe6980384
--- /dev/null
+++ b/libavfilter/vf_entropy.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2017 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "avfilter.h"
+#include "drawutils.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct EntropyContext {
+const AVClass *class;
+
+int mode;
+
+int nb_planes;
+int planeheight[4];
+int planewidth[4];
+int depth;
+int is_rgb;
+uint8_t rgba_map[4];
+char planenames[4];
+int64_t *histogram;
+} EntropyContext;
+
+#define OFFSET(x) offsetof(EntropyContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption entropy_options[] = {
+{ "mode", "set kind of histogram entropy measurement",  OFFSET(mode), 
AV_OPT_TYPE_INT,   {.i64=0}, 0, 1, FLAGS, "mode" },
+{ "normal", NULL,   0,
AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
+{ "diff",   NULL,   0,
AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
+{ NULL }
+};
+
+AVFILTER_DEFINE_CLASS(entropy);
+
+static int query_formats(AVFilterContext *ctx)
+{
+static const enum AVPixelFormat pixfmts[] = {
+AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, 
AV_PIX_FMT_YUV411P,
+AV_PIX_FMT_YUV440P,
+AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ420P, 
AV_PIX_FMT_YUVJ411P,
+AV_PIX_FMT_YUVJ440P,
+AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
+AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
+AV_PIX_FMT_YUV440P10,
+AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12,
+AV_PIX_FMT_YUV440P12,
+AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV420P14,
+AV_PIX_FMT_YUV444P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV420P16,
+AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
+AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, 

Re: [FFmpeg-devel] [PATCH 1/2] avformat/http: return EINVAL if ff_http_do_new_request is called with non-http URLContext

2017-12-30 Thread Aman Gupta
On Sat, Dec 30, 2017 at 10:11 AM wm4  wrote:

> On Fri, 29 Dec 2017 15:41:57 -0800
> Aman Gupta  wrote:
>
> > From: Aman Gupta 
> >
> > Signed-off-by: Aman Gupta 
> > ---
> >  libavformat/http.c | 5 +
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/libavformat/http.c b/libavformat/http.c
> > index a376f1a488..8f7e56de54 100644
> > --- a/libavformat/http.c
> > +++ b/libavformat/http.c
> > @@ -311,6 +311,11 @@ int ff_http_do_new_request(URLContext *h, const
> char *uri)

>  char hostname1[1024], hostname2[1024], proto1[10], proto2[10];
> >  int port1, port2;
> >
> > +if (!h->prot ||
> > +!(!strcmp(h->prot->name, "http") ||
> > +  !strcmp(h->prot->name, "https")))
> > +return AVERROR(EINVAL);
> > +
> >  av_url_split(proto1, sizeof(proto1), NULL, 0,
> >   hostname1, sizeof(hostname1), ,
> >   NULL, 0, s->location);
>
> I rejected this, why was it pushed?


Sorry, I understood the rejection to be about the second patch in the set,
which is a hack to avoid crypto-wrapped segments.

This patch enforces that ff_http_do_new_request() is only invoked on
http/https URLContext, which seemed like a sane safe-guard to me.

Aman


> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] avformat/http: return EINVAL if ff_http_do_new_request is called with non-http URLContext

2017-12-30 Thread wm4
On Fri, 29 Dec 2017 15:41:57 -0800
Aman Gupta  wrote:

> From: Aman Gupta 
> 
> Signed-off-by: Aman Gupta 
> ---
>  libavformat/http.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/libavformat/http.c b/libavformat/http.c
> index a376f1a488..8f7e56de54 100644
> --- a/libavformat/http.c
> +++ b/libavformat/http.c
> @@ -311,6 +311,11 @@ int ff_http_do_new_request(URLContext *h, const char 
> *uri)
>  char hostname1[1024], hostname2[1024], proto1[10], proto2[10];
>  int port1, port2;
>  
> +if (!h->prot ||
> +!(!strcmp(h->prot->name, "http") ||
> +  !strcmp(h->prot->name, "https")))
> +return AVERROR(EINVAL);
> +
>  av_url_split(proto1, sizeof(proto1), NULL, 0,
>   hostname1, sizeof(hostname1), ,
>   NULL, 0, s->location);

I rejected this, why was it pushed?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] avformat/http: return EINVAL if ff_http_do_new_request is called with non-http URLContext

2017-12-30 Thread Carl Eugen Hoyos
2017-12-30 0:41 GMT+01:00 Aman Gupta :

> +if (!h->prot ||
> +!(!strcmp(h->prot->name, "http") ||
> +  !strcmp(h->prot->name, "https")))

Can't this be simplified?

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/hls: release mem resource to fix memleak

2017-12-30 Thread Aman Gupta
On Sat, Dec 30, 2017 at 8:34 AM Derek Buitenhuis 
wrote:

> On 12/30/2017 4:31 PM, Nicolas George wrote:
> > Does it really matter? If av_opt_get() fails for any reason,
> > http_multiple will just be false, which would let the processing
> > continue, only in a slightly degraded manner that was the norm a few
> > months ago.
>
> I contend that checking errors should *always* be done, as a matter of
> good practice, not whenever it "seems needed". Especially when it can
> be a alloc failure, leading, in this case to calling:
>
> strncmp((const char *)NULL, http_version_opt, "1.1", 3)
>
> if it fails.


There is already a check in place to prevent strncmp from being called with
NULL.

Aman


>
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v4] lavr: deprecate the entire library

2017-12-30 Thread wm4
On Sat, 30 Dec 2017 17:21:46 +
Derek Buitenhuis  wrote:

> On 12/30/2017 5:11 PM, Ronald S. Bultje wrote:
> > I'm in favour of deprecating and eventually removing it. As Mike used to
> > say: you need to break eggs to make omelettes.  
> 
> I'm in favour simply because I don't know of a good reason to *not*
> deprecate it? Does it have ASM, modes, APIs, etc. that swresample
> lacks? I know it makes supporting both Libav and FFmpeg more cumbersome,
> but I, and pretty well anyone else I know have long since stopped
> caring about doing that.

Reunification, cleaner code, and also I'm still using the libavresample
API (libswresample through ifdeffery - I hoped that to be a temporal
thing until libavresample was enabled by default).
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] http: block while waiting for reconnecting

2017-12-30 Thread Timo Rothenpieler

Am 30.12.2017 um 18:07 schrieb wm4:

It makes no sense to return an error after the first reconnect, and then
somehow resume the next time it's called.

Also make the wait reasonably interruptible. Since there is no mechanism
for this in the API, polling is the best we can do. (Some effort could
be put into making the wait more accurate, since the av_usleep() will
not wait exactly 1000 microseconds, and the error will add up.)

(The original code would work if it returned AVERROR(EAGAIN) or so,
which would make retry_transfer_wrapper() repeat the read call. But I
think having an explicit loop for this is better anyway.)
---
  libavformat/http.c | 22 +-
  1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index a376f1a488..2957648d61 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1443,25 +1443,29 @@ static int http_read_stream(URLContext *h, uint8_t 
*buf, int size)
  return http_buf_read_compressed(h, buf, size);
  #endif /* CONFIG_ZLIB */
  read_ret = http_buf_read(h, buf, size);
-if (   (read_ret  < 0 && s->reconnect&& (!h->is_streamed || s->reconnect_streamed) && 
s->filesize > 0 && s->off < s->filesize)
+while (   (read_ret  < 0 && s->reconnect&& (!h->is_streamed || s->reconnect_streamed) && 
s->filesize > 0 && s->off < s->filesize)
nit: could just get rid of the extra whitespace here and it will be 
perfectly aligned with the next line.



  || (read_ret == 0 && s->reconnect_at_eof && (!h->is_streamed || 
s->reconnect_streamed))) {
+unsigned int wait = 0;
  uint64_t target = h->is_streamed ? 0 : s->off;
  
  if (s->reconnect_delay > s->reconnect_delay_max)

  return AVERROR(EIO);
  
  av_log(h, AV_LOG_INFO, "Will reconnect at %"PRIu64" error=%s.\n", s->off, av_err2str(read_ret));

-av_usleep(1000U*1000*s->reconnect_delay);
+for (wait = 0; wait < 1000U*s->reconnect_delay; wait++) {
+if (ff_check_interrupt(>interrupt_callback))
+return AVERROR(EIO);
+av_usleep(1000);
+}
  s->reconnect_delay = 1 + 2*s->reconnect_delay;
  seek_ret = http_seek_internal(h, target, SEEK_SET, 1);
-if (seek_ret != target) {
+if (seek_ret >= 0 && seek_ret != target) {
  av_log(h, AV_LOG_ERROR, "Failed to reconnect at %"PRIu64".\n", 
target);
-return read_ret;
-}
-
-read_ret = http_buf_read(h, buf, size);
-} else
-s->reconnect_delay = 0;
+return AVERROR(EIO);
+} else
+read_ret = http_buf_read(h, buf, size);
+}
+s->reconnect_delay = 0;
  
  return read_ret;

  }



looks reasonable to me, but it's not my code and I don't have any 
experience with it.




smime.p7s
Description: S/MIME Cryptographic Signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] Global options to compile FFmpeg with only audio-related features

2017-12-30 Thread Cyber Sinh
Hi Derek,

I would have already sent one if I could... But I do not know enough bash to 
code one.
I was hoping that a developer could either write one, or at least give 
directions to do so if my feature request makes sense.

Cyber Sinh

-Message d'origine-
De : ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] De la part de Derek 
Buitenhuis
Envoyé : samedi 30 décembre 2017 17:29
À : ffmpeg-devel@ffmpeg.org
Objet : Re: [FFmpeg-devel] Global options to compile FFmpeg with only 
audio-related features

On 12/30/2017 4:00 PM, Cyber Sinh wrote:
> What do you think?

That patches are welcome :).

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v4] lavr: deprecate the entire library

2017-12-30 Thread Derek Buitenhuis
On 12/30/2017 5:11 PM, Ronald S. Bultje wrote:
> I'm in favour of deprecating and eventually removing it. As Mike used to
> say: you need to break eggs to make omelettes.

I'm in favour simply because I don't know of a good reason to *not*
deprecate it? Does it have ASM, modes, APIs, etc. that swresample
lacks? I know it makes supporting both Libav and FFmpeg more cumbersome,
but I, and pretty well anyone else I know have long since stopped
caring about doing that.

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v4] lavr: deprecate the entire library

2017-12-30 Thread Ronald S. Bultje
Hi,

On Sat, Dec 30, 2017 at 10:45 AM, Rostislav Pehlivanov 
wrote:

> On 30 December 2017 at 15:15, wm4  wrote:
>
> > On Sat, 30 Dec 2017 14:59:19 +
> > Rostislav Pehlivanov  wrote:
> >
> > > Deprecate the entire library. Merged years ago to provide compatibility
> > > with Libav, it remained unmaintained by the FFmpeg project and
> duplicated
> > > functionality provided by libswresample.
> > >
> > > In order to improve consistency and reduce attack surface, as well as
> to
> > ease
> > > burden on maintainers, it has been deprecated. Users of this library
> are
> > asked
> > > to migrate to libswresample, which, as well as providing more
> > functionality,
> > > is faster and has higher accuracy.
> > >
> > > Signed-off-by: Rostislav Pehlivanov 
> > > ---
> >
> > Still against. I'm hoping both libraries can be merged in the future,
> > and removing it would work against this goal.
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
>
> The facts speak for themselves - libswresample is better in every way and
> there's nothing we want ported from libavresample. If you think otherwise -
> send a patch or at least structural critique of how libswresample could be
> improved. There's still 2 years until the code is removed and even then
> it'd still be in git, bitrotting as it currently does.
>
> I'm still intending to apply this patch in a few days.


I'm in favour of deprecating and eventually removing it. As Mike used to
say: you need to break eggs to make omelettes.

Ronald
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] tcp: properly return EOF

2017-12-30 Thread Ronald S. Bultje
Hi,

On Sat, Dec 30, 2017 at 11:44 AM, wm4  wrote:

> There is no POSIX error code for EOF - recv() signals EOF by simply
> returning 0. But libavformat recently changed its conventionts and
> requires an explicit AVERROR_EOF, or it might get into an endless retry
> loop, consuming 100% CPU while doing nothing.
> ---
>  libavformat/tcp.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> index fef0729da6..8773493df1 100644
> --- a/libavformat/tcp.c
> +++ b/libavformat/tcp.c
> @@ -225,6 +225,8 @@ static int tcp_read(URLContext *h, uint8_t *buf, int
> size)
>  return ret;
>  }
>  ret = recv(s->fd, buf, size, 0);
> +if (ret == 0)
> +return AVERROR_EOF;
>  return ret < 0 ? ff_neterrno() : ret;
>  }


OK.

Ronald
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] Global options to compile FFmpeg with only audio-related features

2017-12-30 Thread Ronald S. Bultje
Hi,

On Sat, Dec 30, 2017 at 11:28 AM, Derek Buitenhuis <
derek.buitenh...@gmail.com> wrote:

> On 12/30/2017 4:00 PM, Cyber Sinh wrote:
> > What do you think?
>
> That patches are welcome :).


Just to be clear: I'm not OK with a list of audio or video thingies in
configure. Similar to the scraping of allcodecs.c, we should be able to
classify them based on their AVMEDIA_TYPE and use that classification
automatically in configure to do what you say.

Just to prevent you from doing a lot of work that won't be upstreamable for
maintenance reasons.

Ronald
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/utvideodec: add support for UMH2, UMY2, UMH4, UMY4, UMRA, UMRG

2017-12-30 Thread Paul B Mahol
On 12/30/17, Derek Buitenhuis  wrote:
> On 12/30/2017 3:10 PM, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol 
>> ---
>>  libavcodec/utvideo.h|   8 +-
>>  libavcodec/utvideodec.c | 194
>> ++--
>>  libavformat/riff.c  |   6 ++
>>  3 files changed, 169 insertions(+), 39 deletions(-)
>
> Can you add some info in the commit message about what these six (wow) new
> FourCCs are?

Added.

>
>> +if (bits == 0) {
>> +*(uint64_t *) p = 0;
>
> I assume p is guaranteed to be aligned properly for this (i.e. no aliasing
> issues)?

Yes.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avcodec/utvideodec: add support for UMH2, UMY2, UMH4, UMY4, UMRA, UMRG

2017-12-30 Thread Paul B Mahol
These are new modes which are supposed to be more SIMD friendly.

Signed-off-by: Paul B Mahol 
---
 libavcodec/utvideo.h|   8 +-
 libavcodec/utvideodec.c | 199 +++-
 libavformat/riff.c  |   6 ++
 3 files changed, 174 insertions(+), 39 deletions(-)

diff --git a/libavcodec/utvideo.h b/libavcodec/utvideo.h
index a8117851a7..cf0bb28c44 100644
--- a/libavcodec/utvideo.h
+++ b/libavcodec/utvideo.h
@@ -72,17 +72,23 @@ typedef struct UtvideoContext {
 LLVidDSPContext llviddsp;
 LLVidEncDSPContext llvidencdsp;
 
-uint32_t frame_info_size, flags, frame_info;
+uint32_t frame_info_size, flags, frame_info, offset;
 int  planes;
 int  slices;
 int  compression;
 int  interlaced;
 int  frame_pred;
 int  pro;
+int  pack;
 
 ptrdiff_t slice_stride;
 uint8_t *slice_bits, *slice_buffer[4];
 int  slice_bits_size;
+
+const uint8_t *packed_stream[4][256];
+size_t packed_stream_size[4][256];
+const uint8_t *control_stream[4][256];
+size_t control_stream_size[4][256];
 } UtvideoContext;
 
 typedef struct HuffEntry {
diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c
index c6076811d1..f019a40e8b 100644
--- a/libavcodec/utvideodec.c
+++ b/libavcodec/utvideodec.c
@@ -247,9 +247,50 @@ static int decode_plane(UtvideoContext *c, int plane_no,
 int sstart, send;
 VLC vlc;
 GetBitContext gb;
-int prev, fsym;
+int ret, prev, fsym;
 const int cmask = compute_cmask(plane_no, c->interlaced, 
c->avctx->pix_fmt);
 
+if (c->pack) {
+send = 0;
+for (slice = 0; slice < c->slices; slice++) {
+GetBitContext cbit, pbit;
+uint8_t *dest, *p;
+
+ret = init_get_bits8(, c->control_stream[plane_no][slice], 
c->control_stream_size[plane_no][slice]);
+if (ret < 0)
+return ret;
+
+ret = init_get_bits8(, c->packed_stream[plane_no][slice], 
c->packed_stream_size[plane_no][slice]);
+if (ret < 0)
+return ret;
+
+sstart = send;
+send   = (height * (slice + 1) / c->slices) & cmask;
+dest   = dst + sstart * stride;
+
+for (p = dest; p < dst + send * stride; p += 8) {
+int bits = get_bits_le(, 3);
+
+if (bits == 0) {
+*(uint64_t *) p = 0;
+} else {
+uint32_t sub = 0x80 >> (8 - (bits + 1)), add;
+int k;
+
+for (k = 0; k < 8; k++) {
+
+p[k] = get_bits_le(, bits + 1);
+add = (~p[k] & sub) << (8 - bits);
+p[k] -= sub;
+p[k] += add;
+}
+}
+}
+}
+
+return 0;
+}
+
 if (build_huff(src, , )) {
 av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
 return AVERROR_INVALIDDATA;
@@ -566,7 +607,43 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame,
 
 /* parse plane structure to get frame flags and validate slice offsets */
 bytestream2_init(, buf, buf_size);
-if (c->pro) {
+
+if (c->pack) {
+GetByteContext pb;
+uint32_t nb_cbs;
+const uint8_t *packed_stream;
+const uint8_t *control_stream;
+
+c->frame_info = PRED_GRADIENT << 8;
+
+if (bytestream2_get_byte() != 1)
+return AVERROR_INVALIDDATA;
+bytestream2_skip(, 3);
+c->offset = bytestream2_get_le32();
+
+if (buf_size <= c->offset + 8LL)
+return AVERROR_INVALIDDATA;
+
+bytestream2_init(, buf + 8 + c->offset, buf_size - 8 - c->offset);
+nb_cbs = bytestream2_get_le32();
+control_stream = buf + 8 + c->offset - nb_cbs;
+
+packed_stream = buf + 8;
+for (i = 0; i < c->planes; i++) {
+for (j = 0; j < c->slices; j++) {
+c->packed_stream[i][j] = packed_stream;
+c->packed_stream_size[i][j] = bytestream2_get_le32();
+packed_stream += c->packed_stream_size[i][j];
+}
+}
+for (i = 0; i < c->planes; i++) {
+for (j = 0; j < c->slices; j++) {
+c->control_stream[i][j] = control_stream;
+c->control_stream_size[i][j] = bytestream2_get_le32();
+control_stream += c->control_stream_size[i][j];
+}
+}
+} else if (c->pro) {
 if (bytestream2_get_bytes_left() < c->frame_info_size) {
 av_log(avctx, AV_LOG_ERROR, "Not enough data for frame 
information\n");
 return AVERROR_INVALIDDATA;
@@ -635,12 +712,14 @@ static int decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
 
 max_slice_size += 4*avctx->width;
 
-av_fast_malloc(>slice_bits, >slice_bits_size,
-

Re: [FFmpeg-devel] [PATCH][RFC]lavu/mem: Do not realloc in av_fast_alloc() if size == min_size

2017-12-30 Thread Derek Buitenhuis
On 12/30/2017 5:02 PM, Carl Eugen Hoyos wrote:
> I just confirmed the ("arbitrary") limit defaults to INT_MAX which at least
> on some systems is 2G as claimed above.

Right, but this is system-dependent, and not specific to FFmpeg, which was
what I meant. I digress though, this is off-topic from the patch at hand,
which looked OK to me (barring any special reason for < having been used,
which git blame found nothing for).

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] http: block while waiting for reconnecting

2017-12-30 Thread wm4
It makes no sense to return an error after the first reconnect, and then
somehow resume the next time it's called.

Also make the wait reasonably interruptible. Since there is no mechanism
for this in the API, polling is the best we can do. (Some effort could
be put into making the wait more accurate, since the av_usleep() will
not wait exactly 1000 microseconds, and the error will add up.)

(The original code would work if it returned AVERROR(EAGAIN) or so,
which would make retry_transfer_wrapper() repeat the read call. But I
think having an explicit loop for this is better anyway.)
---
 libavformat/http.c | 22 +-
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index a376f1a488..2957648d61 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1443,25 +1443,29 @@ static int http_read_stream(URLContext *h, uint8_t 
*buf, int size)
 return http_buf_read_compressed(h, buf, size);
 #endif /* CONFIG_ZLIB */
 read_ret = http_buf_read(h, buf, size);
-if (   (read_ret  < 0 && s->reconnect&& (!h->is_streamed || 
s->reconnect_streamed) && s->filesize > 0 && s->off < s->filesize)
+while (   (read_ret  < 0 && s->reconnect&& (!h->is_streamed || 
s->reconnect_streamed) && s->filesize > 0 && s->off < s->filesize)
 || (read_ret == 0 && s->reconnect_at_eof && (!h->is_streamed || 
s->reconnect_streamed))) {
+unsigned int wait = 0;
 uint64_t target = h->is_streamed ? 0 : s->off;
 
 if (s->reconnect_delay > s->reconnect_delay_max)
 return AVERROR(EIO);
 
 av_log(h, AV_LOG_INFO, "Will reconnect at %"PRIu64" error=%s.\n", 
s->off, av_err2str(read_ret));
-av_usleep(1000U*1000*s->reconnect_delay);
+for (wait = 0; wait < 1000U*s->reconnect_delay; wait++) {
+if (ff_check_interrupt(>interrupt_callback))
+return AVERROR(EIO);
+av_usleep(1000);
+}
 s->reconnect_delay = 1 + 2*s->reconnect_delay;
 seek_ret = http_seek_internal(h, target, SEEK_SET, 1);
-if (seek_ret != target) {
+if (seek_ret >= 0 && seek_ret != target) {
 av_log(h, AV_LOG_ERROR, "Failed to reconnect at %"PRIu64".\n", 
target);
-return read_ret;
-}
-
-read_ret = http_buf_read(h, buf, size);
-} else
-s->reconnect_delay = 0;
+return AVERROR(EIO);
+} else
+read_ret = http_buf_read(h, buf, size);
+}
+s->reconnect_delay = 0;
 
 return read_ret;
 }
-- 
2.15.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH][RFC]lavu/mem: Do not realloc in av_fast_alloc() if size == min_size

2017-12-30 Thread Carl Eugen Hoyos
2017-12-30 17:24 GMT+01:00 Derek Buitenhuis :
> On 12/30/2017 1:44 PM, Carl Eugen Hoyos wrote:
>> FFmpeg has an arbitrary allocation limit (2G iirc), av_fast_realloc()
>> increases the allocation even if the requested is equal the already
>> allocated size. I believe this can lead to unnecessary OOM (no
>> testcase) if the requested (and already allocated) size is close to
>> our limit.
>> Additionally, this avoids an over-allocation for the mov stts patch I just 
>> sent.
>> Attached patch changes the behaviour introduced 15 years ago.

> I'm not aware of such a limit within the libraries (there is no allocation
> tracking)?

I just confirmed the ("arbitrary") limit defaults to INT_MAX which at least
on some systems is 2G as claimed above.

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] tcp: properly return EOF

2017-12-30 Thread wm4
There is no POSIX error code for EOF - recv() signals EOF by simply
returning 0. But libavformat recently changed its conventionts and
requires an explicit AVERROR_EOF, or it might get into an endless retry
loop, consuming 100% CPU while doing nothing.
---
 libavformat/tcp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index fef0729da6..8773493df1 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -225,6 +225,8 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
 return ret;
 }
 ret = recv(s->fd, buf, size, 0);
+if (ret == 0)
+return AVERROR_EOF;
 return ret < 0 ? ff_neterrno() : ret;
 }
 
-- 
2.15.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/utvideodec: add support for UMH2, UMY2, UMH4, UMY4, UMRA, UMRG

2017-12-30 Thread Derek Buitenhuis
On 12/30/2017 3:10 PM, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  libavcodec/utvideo.h|   8 +-
>  libavcodec/utvideodec.c | 194 
> ++--
>  libavformat/riff.c  |   6 ++
>  3 files changed, 169 insertions(+), 39 deletions(-)

Can you add some info in the commit message about what these six (wow) new
FourCCs are?

> +if (bits == 0) {
> +*(uint64_t *) p = 0;

I assume p is guaranteed to be aligned properly for this (i.e. no aliasing 
issues)?

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/hls: release mem resource to fix memleak

2017-12-30 Thread Derek Buitenhuis
On 12/30/2017 4:31 PM, Nicolas George wrote:
> Does it really matter? If av_opt_get() fails for any reason,
> http_multiple will just be false, which would let the processing
> continue, only in a slightly degraded manner that was the norm a few
> months ago.

I contend that checking errors should *always* be done, as a matter of
good practice, not whenever it "seems needed". Especially when it can
be a alloc failure, leading, in this case to calling:

strncmp((const char *)NULL, http_version_opt, "1.1", 3)

if it fails.

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/hls: release mem resource to fix memleak

2017-12-30 Thread Nicolas George
Derek Buitenhuis (2017-12-30):
> On 12/30/2017 12:42 PM, Steven Liu wrote:
> >  av_opt_get(v->input, "http_version", AV_OPT_SEARCH_CHILDREN, 
> > _version_opt);
> >  c->http_multiple = http_version_opt && strncmp((const char 
> > *)http_version_opt, "1.1", 3) == 0;
> > +av_free(http_version_opt);
> 
> Looks OK, but the return value for av_opt_get should also be checked. It can
> fail with, for example, AVERROR(ENOMEM).

Does it really matter? If av_opt_get() fails for any reason,
http_multiple will just be false, which would let the processing
continue, only in a slightly degraded manner that was the norm a few
months ago.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] Global options to compile FFmpeg with only audio-related features

2017-12-30 Thread Derek Buitenhuis
On 12/30/2017 4:00 PM, Cyber Sinh wrote:
> What do you think?

That patches are welcome :).

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/hls: release mem resource to fix memleak

2017-12-30 Thread Derek Buitenhuis
On 12/30/2017 12:42 PM, Steven Liu wrote:
>  av_opt_get(v->input, "http_version", AV_OPT_SEARCH_CHILDREN, 
> _version_opt);
>  c->http_multiple = http_version_opt && strncmp((const char 
> *)http_version_opt, "1.1", 3) == 0;
> +av_free(http_version_opt);

Looks OK, but the return value for av_opt_get should also be checked. It can
fail with, for example, AVERROR(ENOMEM).

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH][RFC]lavu/mem: Do not realloc in av_fast_alloc() if size == min_size

2017-12-30 Thread Derek Buitenhuis
On 12/30/2017 1:44 PM, Carl Eugen Hoyos wrote:
> FFmpeg has an arbitrary allocation limit (2G iirc), av_fast_realloc()
> increases the allocation even if the requested is equal the already
> allocated size. I believe this can lead to unnecessary OOM (no
> testcase) if the requested (and already allocated) size is close to
> our limit.
> Additionally, this avoids an over-allocation for the mov stts patch I just 
> sent.
> Attached patch changes the behaviour introduced 15 years ago.

I'm not aware of such a limit within the libraries (there is no allocation
tracking)?

The change itself looks like it is correct to me, unless there is some special
reason it was < instead of <= before.

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] Global options to compile FFmpeg with only audio-related features

2017-12-30 Thread Cyber Sinh
Hi,

 

I use FFmpeg in an audio-oriented software (for playing and acoustic 
fingerprinting). 

 

So, I want to compile FFmpeg with only:

- audio-oriented features to reduce the size (and compilation time) of the lib 
(eg. bypass video codecs). A feature should be considered as audio-related if 
it is video-only oriented (eg. A media container which supports audio stream 
should be considered as an audio feature).

- player-oriented features to demux/decode files (not to mux/encode them).

 

Disabling all muxers and encoders is easy: passing “--disable-muxers” and 
“--disable-encoders” to “configure” is enough.

 

But to enable only audio-oriented features, I have to pass many options (and 
maintain) to “configure” script:

​https://github.com/CyberSinh/Luminescence.Audio/blob/master/lib/make/ffmpeg/configure-ffmpeg-msvc.sh

 

It would be great if there was more global options in the “configure” bash 
script to enable all audio-related (or disable all video-related) features, 
like (eg. for decoders):

--disable-video-decoders

--enable-audio-decoders

 

What do you think?

 

Thanks.

 

Cyber Sinh

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v4] lavr: deprecate the entire library

2017-12-30 Thread Rostislav Pehlivanov
On 30 December 2017 at 15:15, wm4  wrote:

> On Sat, 30 Dec 2017 14:59:19 +
> Rostislav Pehlivanov  wrote:
>
> > Deprecate the entire library. Merged years ago to provide compatibility
> > with Libav, it remained unmaintained by the FFmpeg project and duplicated
> > functionality provided by libswresample.
> >
> > In order to improve consistency and reduce attack surface, as well as to
> ease
> > burden on maintainers, it has been deprecated. Users of this library are
> asked
> > to migrate to libswresample, which, as well as providing more
> functionality,
> > is faster and has higher accuracy.
> >
> > Signed-off-by: Rostislav Pehlivanov 
> > ---
>
> Still against. I'm hoping both libraries can be merged in the future,
> and removing it would work against this goal.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

The facts speak for themselves - libswresample is better in every way and
there's nothing we want ported from libavresample. If you think otherwise -
send a patch or at least structural critique of how libswresample could be
improved. There's still 2 years until the code is removed and even then
it'd still be in git, bitrotting as it currently does.

I'm still intending to apply this patch in a few days.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH, V2] avformat/concat: Fix wrong wrapped timestamp

2017-12-30 Thread Wu Zhiqiang
2017年12月30日 下午7:30,"Nicolas George" 写道:

Wu Zhiqiang (2017-12-30):
> The command to  generate sample video:
>
> ffmpeg -f lavfi -i testsrc=duration=120  -c:v h264 -profile:v high
-level:v
> 10 -pix_fmt yuv420p -r 30 -g 30 -c:a aac test.flv
> echo -e "file test.flv\nduration 120" > playlist
> ffplay -f concat playlist -ss 90 -max_ts_probe 0
>
> then seek to time before 30s , the result timestamp  is huge and
> print:"Invalid timestamps stream"

Thanks. I think I understand the problem: it is not that the timestamps
are not unwrapped, it is that they are unwrapped twice, because for some
reason lavf defaults to parameters tuned for MPEG.

See the attached patch.

Regards,

--
  Nicolas George

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Thanks for the patch, it works fine to me.
Disable is good enough to prevent unnecessary wrap control.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avcodec/utvideodec: add support for UMH2, UMY2, UMH4, UMY4, UMRA, UMRG

2017-12-30 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavcodec/utvideo.h|   8 +-
 libavcodec/utvideodec.c | 194 ++--
 libavformat/riff.c  |   6 ++
 3 files changed, 169 insertions(+), 39 deletions(-)

diff --git a/libavcodec/utvideo.h b/libavcodec/utvideo.h
index a8117851a7..cf0bb28c44 100644
--- a/libavcodec/utvideo.h
+++ b/libavcodec/utvideo.h
@@ -72,17 +72,23 @@ typedef struct UtvideoContext {
 LLVidDSPContext llviddsp;
 LLVidEncDSPContext llvidencdsp;
 
-uint32_t frame_info_size, flags, frame_info;
+uint32_t frame_info_size, flags, frame_info, offset;
 int  planes;
 int  slices;
 int  compression;
 int  interlaced;
 int  frame_pred;
 int  pro;
+int  pack;
 
 ptrdiff_t slice_stride;
 uint8_t *slice_bits, *slice_buffer[4];
 int  slice_bits_size;
+
+const uint8_t *packed_stream[4][256];
+size_t packed_stream_size[4][256];
+const uint8_t *control_stream[4][256];
+size_t control_stream_size[4][256];
 } UtvideoContext;
 
 typedef struct HuffEntry {
diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c
index c6076811d1..846678dc3a 100644
--- a/libavcodec/utvideodec.c
+++ b/libavcodec/utvideodec.c
@@ -247,9 +247,45 @@ static int decode_plane(UtvideoContext *c, int plane_no,
 int sstart, send;
 VLC vlc;
 GetBitContext gb;
-int prev, fsym;
+int ret, prev, fsym;
 const int cmask = compute_cmask(plane_no, c->interlaced, 
c->avctx->pix_fmt);
 
+if (c->pack) {
+send = 0;
+for (slice = 0; slice < c->slices; slice++) {
+GetBitContext cbit, pbit;
+uint8_t *dest, *p;
+
+ret = init_get_bits8(, c->control_stream[plane_no][slice], 
c->control_stream_size[plane_no][slice]);
+if (ret < 0)
+return ret;
+
+ret = init_get_bits8(, c->packed_stream[plane_no][slice], 
c->packed_stream_size[plane_no][slice]);
+if (ret < 0)
+return ret;
+
+sstart = send;
+send   = (height * (slice + 1) / c->slices) & cmask;
+dest   = dst + sstart * stride;
+
+for (p = dest; p < dst + send * stride; p += 8) {
+int bits = get_bits_le(, 3);
+
+if (bits == 0) {
+*(uint64_t *) p = 0;
+} else {
+int k;
+
+for (k = 0; k < 8; k++)
+p[k] = get_bits_le(, bits);
+}
+
+}
+}
+
+return 0;
+}
+
 if (build_huff(src, , )) {
 av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
 return AVERROR_INVALIDDATA;
@@ -566,7 +602,43 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame,
 
 /* parse plane structure to get frame flags and validate slice offsets */
 bytestream2_init(, buf, buf_size);
-if (c->pro) {
+
+if (c->pack) {
+GetByteContext pb;
+uint32_t nb_cbs;
+const uint8_t *packed_stream;
+const uint8_t *control_stream;
+
+c->frame_info = PRED_GRADIENT << 8;
+
+if (bytestream2_get_byte() != 1)
+return AVERROR_INVALIDDATA;
+bytestream2_skip(, 3);
+c->offset = bytestream2_get_le32();
+
+if (buf_size <= c->offset + 8LL)
+return AVERROR_INVALIDDATA;
+
+bytestream2_init(, buf + 8 + c->offset, buf_size - 8 - c->offset);
+nb_cbs = bytestream2_get_le32();
+control_stream = buf + 8 + c->offset - nb_cbs;
+
+packed_stream = buf + 8;
+for (i = 0; i < c->planes; i++) {
+for (j = 0; j < c->slices; j++) {
+c->packed_stream[i][j] = packed_stream;
+c->packed_stream_size[i][j] = bytestream2_get_le32();
+packed_stream += c->packed_stream_size[i][j];
+}
+}
+for (i = 0; i < c->planes; i++) {
+for (j = 0; j < c->slices; j++) {
+c->control_stream[i][j] = control_stream;
+c->control_stream_size[i][j] = bytestream2_get_le32();
+control_stream += c->control_stream_size[i][j];
+}
+}
+} else if (c->pro) {
 if (bytestream2_get_bytes_left() < c->frame_info_size) {
 av_log(avctx, AV_LOG_ERROR, "Not enough data for frame 
information\n");
 return AVERROR_INVALIDDATA;
@@ -635,12 +707,14 @@ static int decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
 
 max_slice_size += 4*avctx->width;
 
-av_fast_malloc(>slice_bits, >slice_bits_size,
-   max_slice_size + AV_INPUT_BUFFER_PADDING_SIZE);
+if (!c->pack) {
+av_fast_malloc(>slice_bits, >slice_bits_size,
+   max_slice_size + AV_INPUT_BUFFER_PADDING_SIZE);
 
-if (!c->slice_bits) {
-av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary 

Re: [FFmpeg-devel] [PATCH v4] lavr: deprecate the entire library

2017-12-30 Thread wm4
On Sat, 30 Dec 2017 14:59:19 +
Rostislav Pehlivanov  wrote:

> Deprecate the entire library. Merged years ago to provide compatibility
> with Libav, it remained unmaintained by the FFmpeg project and duplicated
> functionality provided by libswresample.
> 
> In order to improve consistency and reduce attack surface, as well as to ease
> burden on maintainers, it has been deprecated. Users of this library are asked
> to migrate to libswresample, which, as well as providing more functionality,
> is faster and has higher accuracy.
> 
> Signed-off-by: Rostislav Pehlivanov 
> ---

Still against. I'm hoping both libraries can be merged in the future,
and removing it would work against this goal.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v4] lavr: deprecate the entire library

2017-12-30 Thread Rostislav Pehlivanov
Deprecate the entire library. Merged years ago to provide compatibility
with Libav, it remained unmaintained by the FFmpeg project and duplicated
functionality provided by libswresample.

In order to improve consistency and reduce attack surface, as well as to ease
burden on maintainers, it has been deprecated. Users of this library are asked
to migrate to libswresample, which, as well as providing more functionality,
is faster and has higher accuracy.

Signed-off-by: Rostislav Pehlivanov 
---
I've kept the deprecations on the enums - they can't hurt.
 configure  |   4 +-
 doc/APIchanges |   9 
 libavresample/avresample.h | 106 ++---
 3 files changed, 110 insertions(+), 9 deletions(-)

diff --git a/configure b/configure
index 688f6ab803..f2fdb93668 100755
--- a/configure
+++ b/configure
@@ -133,7 +133,7 @@ Component options:
   --disable-swscaledisable libswscale build
   --disable-postproc   disable libpostproc build
   --disable-avfilter   disable libavfilter build
-  --enable-avresample  enable libavresample build [no]
+  --enable-avresample  enable libavresample build (deprecated) [no]
   --disable-pthreads   disable pthreads [autodetect]
   --disable-w32threads disable Win32 threads [autodetect]
   --disable-os2threads disable OS/2 threads [autodetect]
@@ -6521,7 +6521,7 @@ check_deps $CONFIG_LIST   \
$ALL_COMPONENTS\
 
 enabled threads && ! enabled pthreads && ! enabled atomics_native && die "non 
pthread threading without atomics not supported, try adding --enable-pthreads 
or --cpu=i486 or higher if you are on x86"
-
+enabled avresample && warn "Building with deprecated library libavresample"
 
 if test $target_os = "haiku"; then
 disable memalign
diff --git a/doc/APIchanges b/doc/APIchanges
index 3c9f237596..38c1be61c7 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,15 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2017-xx-xx - xxx - lavr 4.0.0 - avresample.h
+  Deprecate the entire library. Merged years ago to provide compatibility
+  with Libav, it remained unmaintained by the FFmpeg project and duplicated
+  functionality provided by libswresample.
+
+  In order to improve consistency and reduce attack surface, it has been 
deprecated.
+  Users of this library are asked to migrate to libswresample, which, as well 
as
+  providing more functionality, is faster and has higher accuracy.
+
 2017-xx-xx - xxx - lavc 58.9.100 - avcodec.h
   Deprecate av_lockmgr_register(). You need to build FFmpeg with threading
   support enabled to get basic thread-safety (which is the default build
diff --git a/libavresample/avresample.h b/libavresample/avresample.h
index 193443e2a6..440e1a16e7 100644
--- a/libavresample/avresample.h
+++ b/libavresample/avresample.h
@@ -103,24 +103,33 @@
 
 #define AVRESAMPLE_MAX_CHANNELS 32
 
-typedef struct AVAudioResampleContext AVAudioResampleContext;
+typedef attribute_deprecated struct AVAudioResampleContext 
AVAudioResampleContext;
 
-/** Mixing Coefficient Types */
-enum AVMixCoeffType {
+/**
+ * @deprecated use libswresample
+ *
+ * Mixing Coefficient Types */
+enum attribute_deprecated AVMixCoeffType {
 AV_MIX_COEFF_TYPE_Q8,   /** 16-bit 8.8 fixed-point  */
 AV_MIX_COEFF_TYPE_Q15,  /** 32-bit 17.15 fixed-point*/
 AV_MIX_COEFF_TYPE_FLT,  /** floating-point  */
 AV_MIX_COEFF_TYPE_NB,   /** Number of coeff types. Not part of ABI  */
 };
 
-/** Resampling Filter Types */
-enum AVResampleFilterType {
+/**
+ * @deprecated use libswresample
+ *
+ * Resampling Filter Types */
+enum attribute_deprecated AVResampleFilterType {
 AV_RESAMPLE_FILTER_TYPE_CUBIC,  /**< Cubic */
 AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL,   /**< Blackman Nuttall Windowed 
Sinc */
 AV_RESAMPLE_FILTER_TYPE_KAISER, /**< Kaiser Windowed Sinc */
 };
 
-enum AVResampleDitherMethod {
+/**
+ * @deprecated use libswresample
+ */
+enum attribute_deprecated AVResampleDitherMethod {
 AV_RESAMPLE_DITHER_NONE,/**< Do not use dithering */
 AV_RESAMPLE_DITHER_RECTANGULAR, /**< Rectangular Dither */
 AV_RESAMPLE_DITHER_TRIANGULAR,  /**< Triangular Dither*/
@@ -130,22 +139,37 @@ enum AVResampleDitherMethod {
 };
 
 /**
+ *
+ * @deprecated use libswresample
+ *
  * Return the LIBAVRESAMPLE_VERSION_INT constant.
  */
+attribute_deprecated
 unsigned avresample_version(void);
 
 /**
+ *
+ * @deprecated use libswresample
+ *
  * Return the libavresample build-time configuration.
  * @return  configure string
  */
+attribute_deprecated
 const char *avresample_configuration(void);
 
 /**
+ *
+ * @deprecated use libswresample
+ *
  * Return the libavresample license.
  */
+attribute_deprecated
 const char *avresample_license(void);
 
 /**
+ *
+ * @deprecated use libswresample
+ *
  * 

[FFmpeg-devel] [PATCH][RFC]lavu/mem: Do not realloc in av_fast_alloc() if size == min_size

2017-12-30 Thread Carl Eugen Hoyos
Hi!

FFmpeg has an arbitrary allocation limit (2G iirc), av_fast_realloc()
increases the allocation even if the requested is equal the already
allocated size. I believe this can lead to unnecessary OOM (no
testcase) if the requested (and already allocated) size is close to
our limit.
Additionally, this avoids an over-allocation for the mov stts patch I just sent.
Attached patch changes the behaviour introduced 15 years ago.

Please comment, Carl Eugen
From 0ad7a0517c69d04a4443e66eeec802bda21aea55 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos 
Date: Sat, 30 Dec 2017 14:38:33 +0100
Subject: [PATCH] lavu/mem: Do not realloc in av_fast_realloc() if size ==
 min_size.

This can avoid OOM for min_size close to FFmpeg's arbitrary alloc limits.
---
 libavutil/mem.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/mem.c b/libavutil/mem.c
index 79e8b59..0729e1d 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -463,7 +463,7 @@ void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
 
 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
 {
-if (min_size < *size)
+if (min_size <= *size)
 return ptr;
 
 min_size = FFMAX(min_size + min_size / 16 + 32, min_size);
-- 
1.7.10.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]lavf/mov: Do not blindly allocate stts entries

2017-12-30 Thread Carl Eugen Hoyos
2017-12-29 23:37 GMT+01:00 Carl Eugen Hoyos :
> 2017-11-28 21:32 GMT+01:00 Michael Niedermayer :
>> On Mon, Nov 27, 2017 at 05:24:14AM +0100, Carl Eugen Hoyos wrote:
>
>>>  for (i = 0; i < entries && !pb->eof_reached; i++) {
>>> -int sample_duration;
>>> +int sample_duration, ret;
>>>  unsigned int sample_count;
>>> +if (i > sc->stts_count) {
>>> +ret = av_reallocp_array(>stts_data,
>>> +FFMIN(sc->stts_count * 2LL, entries),
>>> +sizeof(*sc->stts_data));
>>
>> this should use a variant of av_fast_realloc
>
> Do you prefer the new patch?
> The old variant here looks slightly saner to me.

Attached is what you possibly had in mind.

Please review, Carl Eugen
From f5fcd9ed1e5ce604c358a3787f1977277005ebb5 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos 
Date: Sat, 30 Dec 2017 14:34:41 +0100
Subject: [PATCH] lavf/mov: Use av_fast_realloc() in mov_read_stts().

Avoids large allocations for short files with invalid stts entry.
Fixes bugzilla 1102.
---
 libavformat/mov.c |   13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 2064473..1e97652 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2850,13 +2850,22 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 av_log(c->fc, AV_LOG_WARNING, "Duplicated STTS atom\n");
 av_free(sc->stts_data);
 sc->stts_count = 0;
-sc->stts_data = av_malloc_array(entries, sizeof(*sc->stts_data));
-if (!sc->stts_data)
+if (entries >= INT_MAX / sizeof(*sc->stts_data))
 return AVERROR(ENOMEM);
 
 for (i = 0; i < entries && !pb->eof_reached; i++) {
 int sample_duration;
 unsigned int sample_count;
+unsigned alloc_size = 0, min_entries = FFMIN(FFMAX(i, 1024 * 1024), entries);
+MOVStts *stts_data = av_fast_realloc(sc->stts_data, _size,
+ min_entries * sizeof(*sc->stts_data));
+if (!stts_data) {
+av_freep(>stts_data);
+sc->stts_count = 0;
+return AVERROR(ENOMEM);
+}
+sc->stts_count = min_entries;
+sc->stts_data = stts_data;
 
 sample_count=avio_rb32(pb);
 sample_duration = avio_rb32(pb);
-- 
1.7.10.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/hls: release mem resource to fix memleak

2017-12-30 Thread Steven Liu
fix CID: 1426991

Signed-off-by: Steven Liu 
---
 libavformat/hls.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index dccc7c7dd2..9918d1af74 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -1475,6 +1475,7 @@ reload:
 uint8_t *http_version_opt = NULL;
 av_opt_get(v->input, "http_version", AV_OPT_SEARCH_CHILDREN, 
_version_opt);
 c->http_multiple = http_version_opt && strncmp((const char 
*)http_version_opt, "1.1", 3) == 0;
+av_free(http_version_opt);
 }
 
 seg = next_segment(v);
-- 
2.11.0 (Apple Git-81)



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH, V2] avformat/concat: Fix wrong wrapped timestamp

2017-12-30 Thread Nicolas George
Wu Zhiqiang (2017-12-30):
> The command to  generate sample video:
> 
> ffmpeg -f lavfi -i testsrc=duration=120  -c:v h264 -profile:v high -level:v
> 10 -pix_fmt yuv420p -r 30 -g 30 -c:a aac test.flv
> echo -e "file test.flv\nduration 120" > playlist
> ffplay -f concat playlist -ss 90 -max_ts_probe 0
> 
> then seek to time before 30s , the result timestamp  is huge and
> print:"Invalid timestamps stream"

Thanks. I think I understand the problem: it is not that the timestamps
are not unwrapped, it is that they are unwrapped twice, because for some
reason lavf defaults to parameters tuned for MPEG.

See the attached patch.

Regards,

-- 
  Nicolas George
From 9f24fe25cddabc0b0dc1a60d1789ea7feaa125f7 Mon Sep 17 00:00:00 2001
From: Nicolas George 
Date: Sat, 30 Dec 2017 12:17:08 +0100
Subject: [PATCH] lavf/concatdec: properly init streams timestamp parameters.

pts_wrap_bits defaults to 33 (like MPEG), that causes valid
timestamps to be unwrapped and become invalid.
Inspired by a patch by Wu Zhiqiang .

Signed-off-by: Nicolas George 
---
 libavformat/concatdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0e189012ad..bd5174ada2 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -185,8 +185,8 @@ static int copy_stream_props(AVStream *st, AVStream *source_st)
 return ret;
 st->r_frame_rate= source_st->r_frame_rate;
 st->avg_frame_rate  = source_st->avg_frame_rate;
-st->time_base   = source_st->time_base;
 st->sample_aspect_ratio = source_st->sample_aspect_ratio;
+avpriv_set_pts_info(st, 64, source_st->time_base.num, source_st->time_base.den);
 
 av_dict_copy(>metadata, source_st->metadata, 0);
 return 0;
-- 
2.15.1



signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] avformat/hls: use AVIOContext new_http_request callback

2017-12-30 Thread wm4
On Sat, 30 Dec 2017 11:53:14 +0100
Nicolas George  wrote:

> Aman Gupta (2017-12-29):
> > It also makes it easier in the future to add http keepalive support to
> > other consumers like the dash demuxer and the crypto protocol.  
> 
> For that, the API does not need to be public, it just need to be clean.
> 
> I thought you were referring to using the hls demuxer with other
> protocols that may allow connection reuse. That could justify a public
> API. But we do not know what kind of parameters these other protocols
> may need; maybe some of them will require flags to select parallel /
> sequential requests; maybe one of them will need to return some kind of
> connection handle. We do not know, therefore we need to plan carefully,
> or even better: wait for an actual case. Also, naming the callback
> http_something would be a misnomer.

As usual, you block patches based on some theoretical nonsense that
will never happen anyway. Like your XML parser.

> > I'll go ahead and submit another patchset using this approach to fix
> > the immediate segfault while we consider a larger API change.  
> 
> Thanks. It seems to me a very sane course of action, and I have no
> objection to the two patches you just sent.

Well I object to the other patches.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] avformat/hls: use AVIOContext new_http_request callback

2017-12-30 Thread Nicolas George
Aman Gupta (2017-12-29):
> It also makes it easier in the future to add http keepalive support to
> other consumers like the dash demuxer and the crypto protocol.

For that, the API does not need to be public, it just need to be clean.

I thought you were referring to using the hls demuxer with other
protocols that may allow connection reuse. That could justify a public
API. But we do not know what kind of parameters these other protocols
may need; maybe some of them will require flags to select parallel /
sequential requests; maybe one of them will need to return some kind of
connection handle. We do not know, therefore we need to plan carefully,
or even better: wait for an actual case. Also, naming the callback
http_something would be a misnomer.

> I'll go ahead and submit another patchset using this approach to fix
> the immediate segfault while we consider a larger API change.

Thanks. It seems to me a very sane course of action, and I have no
objection to the two patches you just sent.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] avformat/hls: use AVIOContext new_http_request callback

2017-12-30 Thread wm4
On Fri, 29 Dec 2017 23:45:10 +0100
Nicolas George  wrote:

> Aman Gupta (2017-12-29):
> > From: Aman Gupta 
> > 
> > This fixes a segfault when streaming from an HLS playlist which uses
> > crypto, by ensuring ff_http_do_new_request will never be invoked on a
> > non-http URLContext.
> > 
> > Additionally it simplifies the demuxer by removing http.h and all the
> > http specific code in open_url_keepalive.  
> 
> It it awfully specific for something quite minor. And it is messing with
> the public API, that requires careful design.

Reusing a http connection is not minor. It's pretty straightforward
too, and doesn't require being stuck forever in a bikeshed carousel.

> I suggest to have ff_http_do_new_request() check that its argument is
> really a HTTP context and return EINVAL or ENOSYS otherwise.

Unclean and fragile. How many more bugs do you want to have with this?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 8/8] decklink: Add support for compressed AC-3 output over SDI

2017-12-30 Thread Aaron Levinson

On 12/29/2017 10:12 AM, Devin Heitmueller wrote:

Extend the decklink output to include support for compressed AC-3,
encapsulated using the SMPTE ST 377:2015 standard.

This functionality can be exercised by using the "copy" codec when
the input audio stream is AC-3.  For example:

./ffmpeg -i ~/foo.ts -codec:a copy -f decklink 'UltraStudio Mini Monitor'

Note that the default behavior continues to be to do PCM output,
which means without specifying the copy codec a stream containing
AC-3 will be decoded and downmixed to stereo audio before output.

Signed-off-by: Devin Heitmueller 
---
  libavdevice/decklink_enc.cpp | 101 ---
  1 file changed, 86 insertions(+), 15 deletions(-)

diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp
index 59a4181e19..aca3c13861 100644
--- a/libavdevice/decklink_enc.cpp
+++ b/libavdevice/decklink_enc.cpp
@@ -224,19 +224,32 @@ static int decklink_setup_audio(AVFormatContext *avctx, 
AVStream *st)
  av_log(avctx, AV_LOG_ERROR, "Only one audio stream is supported!\n");
  return -1;
  }
-if (c->sample_rate != 48000) {
-av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate!"
-   " Only 48kHz is supported.\n");
-return -1;
-}
-if (c->channels != 2 && c->channels != 8 && c->channels != 16) {
-av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels!"
-   " Only 2, 8 or 16 channels are supported.\n");
+
+if (st->codecpar->codec_id == AV_CODEC_ID_AC3) {
+/* Regardless of the number of channels in the codec, we're only
+   using 2 SDI audio channels at 48000Hz */
+ctx->channels = 2;
+} else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) {
+if (c->channels != 2 && c->channels != 8 && c->channels != 16) {
+av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels!"
+   " Only 2, 8 or 16 channels are supported.\n");
+return -1;
+}
+if (c->sample_rate != bmdAudioSampleRate48kHz) {
+av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate!"
+   " Only 48kHz is supported.\n");
+return -1;
+}
+ctx->channels = c->channels;
+} else {
+av_log(avctx, AV_LOG_ERROR, "Unsupported codec specified!"
+   " Only PCM_S16LE and AC-3 are supported.\n");
  return -1;
  }
+
  if (ctx->dlo->EnableAudioOutput(bmdAudioSampleRate48kHz,
  bmdAudioSampleType16bitInteger,
-c->channels,
+ctx->channels,
  bmdAudioOutputStreamTimestamped) != S_OK) 
{
  av_log(avctx, AV_LOG_ERROR, "Could not enable audio output!\n");
  return -1;
@@ -247,8 +260,7 @@ static int decklink_setup_audio(AVFormatContext *avctx, 
AVStream *st)
  }
  
  /* The device expects the sample rate to be fixed. */

-avpriv_set_pts_info(st, 64, 1, c->sample_rate);
-ctx->channels = c->channels;
+avpriv_set_pts_info(st, 64, 1, bmdAudioSampleRate48kHz);
  
  ctx->audio = 1;
  
@@ -536,25 +548,84 @@ static int decklink_write_video_packet(AVFormatContext *avctx, AVPacket *pkt)

  return 0;
  }
  
+static int create_s337_payload(AVPacket *pkt, enum AVCodecID codec_id, uint8_t **outbuf, int *outsize)

+{
+uint8_t *s337_payload;
+uint8_t *s337_payload_start;
+int i;
+
+/* Encapsulate AC3 syncframe into SMPTE 337 packet */
+*outsize = (pkt->size + 4) * sizeof(uint16_t);
+s337_payload = (uint8_t *) av_mallocz(*outsize);
+if (s337_payload == NULL)
+return AVERROR(ENOMEM);
+
+*outbuf = s337_payload;


Should not store s337_payload in outbuf until the end of the function 
and returning success.  If it fails prematurely (say with the call to 
AVERROR(EINVAL)), the caller may rightfully interpret this to mean that 
outbuf has not been filled in and let outbuf leak.  In the case of 
failure, this function should call av_free() on s337_payload.  Also 
technically true for outsize as well--best to only modify output 
parameters when success is guaranteed.



+
+/* Construct SMPTE S337 Burst preamble */
+s337_payload[0] = 0x72; /* Sync Word 1 */
+s337_payload[1] = 0xf8; /* Sync Word 1 */
+s337_payload[2] = 0x1f; /* Sync Word 1 */
+s337_payload[3] = 0x4e; /* Sync Word 1 */
+
+if (codec_id == AV_CODEC_ID_AC3) {
+s337_payload[4] = 0x01;
+} else {
+return AVERROR(EINVAL);
+}
+
+s337_payload[5] = 0x00;
+uint16_t bitcount = pkt->size * 8;
+s337_payload[6] = bitcount & 0xff; /* Length code */
+s337_payload[7] = bitcount >> 8; /* Length code */
+s337_payload_start = _payload[8];
+for (i = 0; i < pkt->size; i += 2) {
+s337_payload_start[0] = pkt->data[i+1];
+s337_payload_start[1] = pkt->data[i];
+

Re: [FFmpeg-devel] [PATCH 7/8] decklink: Add support for SCTE-104 to decklink capture

2017-12-30 Thread Aaron Levinson

On 12/29/2017 10:12 AM, Devin Heitmueller wrote:

Make use of libklvanc to parse SCTE-104 packets and announce them
as a new stream.  Right now we just pass the payload straight
through, but once this is hoooked into libklscte35 we'll be able


"hoooked" -> "hooked"


to generate SCTE-35 messages in the MPEG TS stream.

Note that this feature needs to be explicitly enabled by the user
through the "-enable_scte_104" option, since we cannot autodetect
the presence of SCTE-104 (because unlike with 708/AFD messages are
not set except when trigger occurs, thus the stream wouldn't get
created during the read_header phase).

Updated to reflect feedback from Derek Buitenhuis 

Signed-off-by: Devin Heitmueller 
---
  libavcodec/avcodec.h|  1 +
  libavcodec/codec_desc.c |  6 
  libavdevice/decklink_common.h   |  6 
  libavdevice/decklink_common_c.h |  1 +
  libavdevice/decklink_dec.cpp| 61 -
  libavdevice/decklink_dec_c.c|  1 +
  libavdevice/version.h   |  2 +-
  7 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 4f7b6df09d..2b4a0bd669 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -668,6 +668,7 @@ enum AVCodecID {
  AV_CODEC_ID_TTF = 0x18000,
  
  AV_CODEC_ID_SCTE_35, ///< Contain timestamp estimated through PCR of program stream.

+AV_CODEC_ID_SCTE_104,
  AV_CODEC_ID_BINTEXT= 0x18800,
  AV_CODEC_ID_XBIN,
  AV_CODEC_ID_IDF,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index c3688de1d6..e198985bb4 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3103,6 +3103,12 @@ static const AVCodecDescriptor codec_descriptors[] = {
  .name  = "scte_35",
  .long_name = NULL_IF_CONFIG_SMALL("SCTE 35 Message Queue"),
  },
+{
+.id= AV_CODEC_ID_SCTE_104,
+.type  = AVMEDIA_TYPE_DATA,
+.name  = "scte_104",
+.long_name = NULL_IF_CONFIG_SMALL("SCTE 104 Digital Program 
Insertion"),
+},
  
  /* deprecated codec ids */

  };
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index 06b241029e..4d2052ea79 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -41,6 +41,10 @@
 Actual number for any particular model of card may be lower */
  #define DECKLINK_MAX_AUDIO_CHANNELS 32
  
+/* This isn't actually tied to the Blackmagic hardware - it's an arbitrary

+   number used to size the array of streams */
+#define DECKLINK_MAX_DATA_STREAMS 16
+
  class decklink_output_callback;
  class decklink_input_callback;
  
@@ -92,6 +96,8 @@ struct decklink_ctx {

  unsigned int dropped;
  AVStream *audio_st[DECKLINK_MAX_AUDIO_CHANNELS];
  int num_audio_streams;
+AVStream *data_st[DECKLINK_MAX_DATA_STREAMS];
+int num_data_streams;
  AVStream *video_st;
  AVStream *teletext_st;
  uint16_t cdp_sequence_num;
diff --git a/libavdevice/decklink_common_c.h b/libavdevice/decklink_common_c.h
index 02011ed53b..cb73ec990b 100644
--- a/libavdevice/decklink_common_c.h
+++ b/libavdevice/decklink_common_c.h
@@ -58,6 +58,7 @@ struct decklink_cctx {
  char *format_code;
  int raw_format;
  int64_t queue_size;
+int enable_scte_104;
  };
  
  #endif /* AVDEVICE_DECKLINK_COMMON_C_H */

diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 86db6d8fbd..f3f0d989bf 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -672,6 +672,30 @@ error:
  return ret;
  }
  
+static int setup_data(AVFormatContext *avctx)

+{
+struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
+struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
+AVStream *st;
+
+if (cctx->enable_scte_104) {
+st = avformat_new_stream(avctx, NULL);
+if (!st) {
+av_log(avctx, AV_LOG_ERROR, "Cannot add data stream\n");
+return AVERROR(ENOMEM);
+}
+st->codecpar->codec_type  = AVMEDIA_TYPE_DATA;
+st->time_base.den = ctx->bmd_tb_den;
+st->time_base.num = ctx->bmd_tb_num;


I wonder if there is any reason to set time_base here.  Aren't the 
triggers relatively infrequent?



+st->codecpar->codec_id= AV_CODEC_ID_SCTE_104;
+avpriv_set_pts_info(st, 64, 1, 100);  /* 64 bits pts in us */
+ctx->data_st[ctx->num_data_streams] = st;
+ctx->num_data_streams++;
+}
+
+return 0;
+}
+
  #if CONFIG_LIBKLVANC
  /* VANC Callbacks */
  struct vanc_cb_ctx {
@@ -731,12 +755,44 @@ static int cb_EIA_708B(void *callback_context, struct 
klvanc_context_s *ctx,
  return 0;
  }
  
+static int cb_SCTE_104(void *callback_context, struct klvanc_context_s *ctx,

+   struct klvanc_packet_scte_104_s *pkt)
+{
+struct vanc_cb_ctx *cb_ctx