Re: [FFmpeg-devel] [PATCH 3/5] avfilter/scale: separate exprs parse and eval

2019-12-26 Thread Gyan



On 24-12-2019 11:39 am, Gyan wrote:



On 24-12-2019 04:50 am, Michael Niedermayer wrote:

On Tue, Dec 17, 2019 at 02:55:06PM +0530, Gyan wrote:
[...]
@@ -127,6 +204,22 @@ static av_cold int init_dict(AVFilterContext 
*ctx, AVDictionary **opts)

  if (!scale->h_expr)
  av_opt_set(scale, "h", "ih", 0);
  +    ret = av_expr_parse(&scale->w_pexpr, scale->w_expr,
+    names,
+    NULL, NULL, NULL, NULL, 0, ctx);
+    if (ret < 0) {
+    av_log(ctx, AV_LOG_ERROR, "Cannot parse width expression: 
'%s'\n", scale->w_expr);

+    return ret;
+    }
+
+    ret = av_expr_parse(&scale->h_pexpr, scale->h_expr,
+    names,
+    NULL, NULL, NULL, NULL, 0, ctx);
+    if (ret < 0) {
+    av_log(ctx, AV_LOG_ERROR, "Cannot parse height expression: 
'%s'\n", scale->h_expr);

+    return ret;
+    }
+
+    if (w) {
+    ret = av_expr_parse(&scale->w_pexpr, scale->w_expr,
+    names,
+    NULL, NULL, NULL, NULL, 0, ctx);
+    if (ret < 0) {
+    av_log(ctx, AV_LOG_ERROR, "Cannot parse width 
expression: '%s'\n", scale->w_expr);

+    goto revert;
+    }
+    }
+
+    if (h) {
+    ret = av_expr_parse(&scale->h_pexpr, scale->h_expr,
+    names,
+    NULL, NULL, NULL, NULL, 0, ctx);
+    if (ret < 0) {
+    av_log(ctx, AV_LOG_ERROR, "Cannot parse height 
expression: '%s'\n", scale->h_expr);

+    goto revert;
+    }
+    }

Duplicate code


init_dict() is not called during command processing since we don't 
reset any other parameter except for one of width or height. Do you 
want me to reinit all parameters after a command?


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCHv2 1/2] avutil/buffer: add av_buffer_pool_buffer_get_opaque

2019-12-26 Thread Marton Balint



On Sun, 22 Dec 2019, Marton Balint wrote:


In order to access the original opaque parameter of a buffer in the buffer
pool. (The buffer pool implementation overrides the normal opaque parameter but
also saves it so it is accessible).

v2: add assertion check before dereferencing the BufferPoolEntry.

Signed-off-by: Marton Balint 
---
doc/APIchanges  |  3 +++
libavutil/buffer.c  |  8 
libavutil/buffer.h  | 13 +
libavutil/version.h |  4 ++--
4 files changed, 26 insertions(+), 2 deletions(-)


Applied.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 05/17] avformat/smoothstreaming: Don't write trailer of subcontext

2019-12-26 Thread Andreas Rheinhardt
Nothing written in avformat_write_trailer() for the submuxers will be
output anyway because the AVIOContexts used for actual output have been
closed before the call. Writing the trailer of the subcontext has probably
only been done in order to free the memory allocated by the submuxer.
And this job has been taken over by the deinit functions.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/smoothstreamingenc.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index a5fd8a18db..07745d5cb5 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -49,7 +49,6 @@ typedef struct Fragment {
 
 typedef struct OutputStream {
 AVFormatContext *ctx;
-int ctx_inited;
 char dirname[1024];
 uint8_t iobuf[32768];
 URLContext *out;  // Current output stream where all output is written
@@ -179,8 +178,6 @@ static void ism_free(AVFormatContext *s)
 ffurl_close(os->out2);
 ffurl_close(os->tail_out);
 os->out = os->out2 = os->tail_out = NULL;
-if (os->ctx && os->ctx_inited)
-av_write_trailer(os->ctx);
 if (os->ctx && os->ctx->pb)
 avio_context_free(&os->ctx->pb);
 avformat_free_context(os->ctx);
@@ -363,7 +360,6 @@ static int ism_write_header(AVFormatContext *s)
 if (ret < 0) {
  goto fail;
 }
-os->ctx_inited = 1;
 avio_flush(ctx->pb);
 s->streams[i]->time_base = st->time_base;
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 03/17] avformat/smoothstreaming: Fix memleaks on errors

2019-12-26 Thread Andreas Rheinhardt
If an AVFormatContext could be allocated, but white-/blacklists couldn't
be copied, the AVFormatContext would leak as it was only accessible
through a local variable that goes out of scope when one goes to fail.

Furthermore, in case writing a header of a submuxer failed, the options
used for said call could leak.

Both of these memleaks have been fixed.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/smoothstreamingenc.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index 2faf1e7897..0e4f531f90 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -332,12 +332,11 @@ static int ism_write_header(AVFormatContext *s)
 goto fail;
 }
 
-ctx = avformat_alloc_context();
+os->ctx = ctx = avformat_alloc_context();
 if (!ctx || ff_copy_whiteblacklists(ctx, s) < 0) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
-os->ctx = ctx;
 ctx->oformat = oformat;
 ctx->interrupt_callback = s->interrupt_callback;
 
@@ -357,12 +356,13 @@ static int ism_write_header(AVFormatContext *s)
 
 av_dict_set_int(&opts, "ism_lookahead", c->lookahead_count, 0);
 av_dict_set(&opts, "movflags", "frag_custom", 0);
-if ((ret = avformat_write_header(ctx, &opts)) < 0) {
+ret = avformat_write_header(ctx, &opts);
+av_dict_free(&opts);
+if (ret < 0) {
  goto fail;
 }
 os->ctx_inited = 1;
 avio_flush(ctx->pb);
-av_dict_free(&opts);
 s->streams[i]->time_base = st->time_base;
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 c->has_video = 1;
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 01/17] avformat/spdifenc: Replace write_trailer by deinit

2019-12-26 Thread Andreas Rheinhardt
The write_trailer function doesn't write anything anyway. It only frees
memory.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/spdifenc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c
index 4307942a44..d5f7d91e93 100644
--- a/libavformat/spdifenc.c
+++ b/libavformat/spdifenc.c
@@ -482,12 +482,11 @@ static int spdif_write_header(AVFormatContext *s)
 return 0;
 }
 
-static int spdif_write_trailer(AVFormatContext *s)
+static void spdif_deinit(AVFormatContext *s)
 {
 IEC61937Context *ctx = s->priv_data;
 av_freep(&ctx->buffer);
 av_freep(&ctx->hd_buf);
-return 0;
 }
 
 static av_always_inline void spdif_put_16(IEC61937Context *ctx,
@@ -560,7 +559,7 @@ AVOutputFormat ff_spdif_muxer = {
 .video_codec   = AV_CODEC_ID_NONE,
 .write_header  = spdif_write_header,
 .write_packet  = spdif_write_packet,
-.write_trailer = spdif_write_trailer,
+.deinit= spdif_deinit,
 .flags = AVFMT_NOTIMESTAMPS,
 .priv_class= &spdif_class,
 };
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 04/17] avformat/smoothstreaming: Forward errors from copying white/blacklists

2019-12-26 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/smoothstreamingenc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index 0e4f531f90..a5fd8a18db 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -333,10 +333,12 @@ static int ism_write_header(AVFormatContext *s)
 }
 
 os->ctx = ctx = avformat_alloc_context();
-if (!ctx || ff_copy_whiteblacklists(ctx, s) < 0) {
+if (!ctx) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
+if ((ret = ff_copy_whiteblacklists(ctx, s)) < 0)
+goto fail;
 ctx->oformat = oformat;
 ctx->interrupt_callback = s->interrupt_callback;
 
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 09/17] avformat/flvenc: Forward errors from allocating keyframe index

2019-12-26 Thread Andreas Rheinhardt
While the function adding a new element to the keyframe index checked
the allocation, the caller didn't check the return value. This has been
changed. To do so, the return value has been changed to an ordinary ret
instead of pb->error. This doesn't pose a problem, as write_packet() in
mux.c already checks for write errors (since 9ad1e0c1).

Signed-off-by: Andreas Rheinhardt 
---
No change since last time.

 libavformat/flvenc.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 862082dd2d..f6379cbe05 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -887,7 +887,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 unsigned ts;
 int size = pkt->size;
 uint8_t *data = NULL;
-int flags = -1, flags_size, ret;
+int flags = -1, flags_size, ret = 0;
 int64_t cur_offset = avio_tell(pb);
 
 if (par->codec_type == AVMEDIA_TYPE_AUDIO && !pkt->size) {
@@ -1057,15 +1057,17 @@ static int flv_write_packet(AVFormatContext *s, 
AVPacket *pkt)
 case AVMEDIA_TYPE_VIDEO:
 flv->videosize += (avio_tell(pb) - cur_offset);
 flv->lasttimestamp = flv->acurframeindex / flv->framerate;
+flv->acurframeindex++;
 if (pkt->flags & AV_PKT_FLAG_KEY) {
-double ts = flv->acurframeindex / flv->framerate;
+double ts = flv->lasttimestamp;
 int64_t pos = cur_offset;
 
-flv->lastkeyframetimestamp = flv->acurframeindex / 
flv->framerate;
+flv->lastkeyframetimestamp = ts;
 flv->lastkeyframelocation = pos;
-flv_append_keyframe_info(s, flv, ts, pos);
+ret = flv_append_keyframe_info(s, flv, ts, pos);
+if (ret < 0)
+goto fail;
 }
-flv->acurframeindex++;
 break;
 
 case AVMEDIA_TYPE_AUDIO:
@@ -1077,10 +1079,10 @@ static int flv_write_packet(AVFormatContext *s, 
AVPacket *pkt)
 break;
 }
 }
-
+fail:
 av_free(data);
 
-return pb->error;
+return ret;
 }
 
 static int flv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 02/17] avformat/wavenc: Add deinit function

2019-12-26 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/wavenc.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c
index 159119d693..269793d571 100644
--- a/libavformat/wavenc.c
+++ b/libavformat/wavenc.c
@@ -185,7 +185,6 @@ static av_cold int peak_init_writer(AVFormatContext *s)
 
 nomem:
 av_log(s, AV_LOG_ERROR, "Out of memory\n");
-peak_free_buffers(s);
 return AVERROR(ENOMEM);
 }
 
@@ -485,9 +484,6 @@ static int wav_write_trailer(AVFormatContext *s)
 }
 }
 
-if (wav->write_peak)
-peak_free_buffers(s);
-
 return ret;
 }
 
@@ -527,6 +523,7 @@ AVOutputFormat ff_wav_muxer = {
 .write_header  = wav_write_header,
 .write_packet  = wav_write_packet,
 .write_trailer = wav_write_trailer,
+.deinit= peak_free_buffers,
 .flags = AVFMT_TS_NONSTRICT,
 .codec_tag = (const AVCodecTag* const []){ ff_codec_wav_tags, 0 },
 .priv_class= &wav_muxer_class,
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 06/17] avformat/smoothstreaming: Add deinit function

2019-12-26 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/smoothstreamingenc.c | 43 
 1 file changed, 16 insertions(+), 27 deletions(-)

diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index 07745d5cb5..ff38edbe05 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -292,21 +292,18 @@ static int ism_write_header(AVFormatContext *s)
 ff_const59 AVOutputFormat *oformat;
 
 if (mkdir(s->url, 0777) == -1 && errno != EEXIST) {
-ret = AVERROR(errno);
 av_log(s, AV_LOG_ERROR, "mkdir failed\n");
-goto fail;
+return AVERROR(errno);
 }
 
 oformat = av_guess_format("ismv", NULL, NULL);
 if (!oformat) {
-ret = AVERROR_MUXER_NOT_FOUND;
-goto fail;
+return AVERROR_MUXER_NOT_FOUND;
 }
 
 c->streams = av_mallocz_array(s->nb_streams, sizeof(*c->streams));
 if (!c->streams) {
-ret = AVERROR(ENOMEM);
-goto fail;
+return AVERROR(ENOMEM);
 }
 
 for (i = 0; i < s->nb_streams; i++) {
@@ -324,24 +321,21 @@ static int ism_write_header(AVFormatContext *s)
 }
 
 if (mkdir(os->dirname, 0777) == -1 && errno != EEXIST) {
-ret = AVERROR(errno);
 av_log(s, AV_LOG_ERROR, "mkdir failed\n");
-goto fail;
+return AVERROR(errno);
 }
 
 os->ctx = ctx = avformat_alloc_context();
 if (!ctx) {
-ret = AVERROR(ENOMEM);
-goto fail;
+return AVERROR(ENOMEM);
 }
 if ((ret = ff_copy_whiteblacklists(ctx, s)) < 0)
-goto fail;
+return ret;
 ctx->oformat = oformat;
 ctx->interrupt_callback = s->interrupt_callback;
 
 if (!(st = avformat_new_stream(ctx, NULL))) {
-ret = AVERROR(ENOMEM);
-goto fail;
+return AVERROR(ENOMEM);
 }
 avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar);
 st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
@@ -349,8 +343,7 @@ static int ism_write_header(AVFormatContext *s)
 
 ctx->pb = avio_alloc_context(os->iobuf, sizeof(os->iobuf), 
AVIO_FLAG_WRITE, os, NULL, ism_write, ism_seek);
 if (!ctx->pb) {
-ret = AVERROR(ENOMEM);
-goto fail;
+return AVERROR(ENOMEM);
 }
 
 av_dict_set_int(&opts, "ism_lookahead", c->lookahead_count, 0);
@@ -358,7 +351,7 @@ static int ism_write_header(AVFormatContext *s)
 ret = avformat_write_header(ctx, &opts);
 av_dict_free(&opts);
 if (ret < 0) {
- goto fail;
+ return ret;
 }
 avio_flush(ctx->pb);
 s->streams[i]->time_base = st->time_base;
@@ -371,8 +364,7 @@ static int ism_write_header(AVFormatContext *s)
 os->fourcc = "WVC1";
 } else {
 av_log(s, AV_LOG_ERROR, "Unsupported video codec\n");
-ret = AVERROR(EINVAL);
-goto fail;
+return AVERROR(EINVAL);
 }
 } else {
 c->has_audio = 1;
@@ -385,8 +377,7 @@ static int ism_write_header(AVFormatContext *s)
 os->audio_tag = 0x0162;
 } else {
 av_log(s, AV_LOG_ERROR, "Unsupported audio codec\n");
-ret = AVERROR(EINVAL);
-goto fail;
+return AVERROR(EINVAL);
 }
 os->packet_size = st->codecpar->block_align ? 
st->codecpar->block_align : 4;
 }
@@ -395,15 +386,13 @@ static int ism_write_header(AVFormatContext *s)
 
 if (!c->has_video && c->min_frag_duration <= 0) {
 av_log(s, AV_LOG_WARNING, "no video stream and no min frag duration 
set\n");
-ret = AVERROR(EINVAL);
-goto fail;
+return AVERROR(EINVAL);
 }
 ret = write_manifest(s, 0);
+if (ret < 0)
+return ret;
 
-fail:
-if (ret)
-ism_free(s);
-return ret;
+return 0;
 }
 
 static int parse_fragment(AVFormatContext *s, const char *filename, int64_t 
*start_ts, int64_t *duration, int64_t *moof_size, int64_t size)
@@ -633,7 +622,6 @@ static int ism_write_trailer(AVFormatContext *s)
 rmdir(s->url);
 }
 
-ism_free(s);
 return 0;
 }
 
@@ -666,5 +654,6 @@ AVOutputFormat ff_smoothstreaming_muxer = {
 .write_header   = ism_write_header,
 .write_packet   = ism_write_packet,
 .write_trailer  = ism_write_trailer,
+.deinit = ism_free,
 .priv_class = &ism_class,
 };
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 17/17] avformat/matroskadec: Don't discard the upper 32bits of TrackNumber

2019-12-26 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index fe4a10..268a2dd476 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1542,7 +1542,7 @@ static int matroska_probe(const AVProbeData *p)
 }
 
 static MatroskaTrack *matroska_find_track_by_num(MatroskaDemuxContext 
*matroska,
- int num)
+ uint64_t num)
 {
 MatroskaTrack *tracks = matroska->tracks.elem;
 unsigned i;
@@ -1551,7 +1551,7 @@ static MatroskaTrack 
*matroska_find_track_by_num(MatroskaDemuxContext *matroska,
 if (tracks[i].num == num)
 return &tracks[i];
 
-av_log(matroska->ctx, AV_LOG_ERROR, "Invalid track number %d\n", num);
+av_log(matroska->ctx, AV_LOG_ERROR, "Invalid track number %"PRIu64"\n", 
num);
 return NULL;
 }
 
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 11/17] avutil/mem: Add av_fast_realloc_array()

2019-12-26 Thread Andreas Rheinhardt
This is an array-equivalent of av_fast_realloc(). Its advantages
compared to using av_fast_realloc() for allocating arrays are as
follows:

a) It performs its own overflow checks for the multiplication that is
implicit in array allocations. (And it only needs to perform these
checks (as well as the multiplication itself) in case the array needs to
be reallocated.)
b) It guarantees to not allocated more than UINT_MAX - 1 elements, so
the caller needn't check for overflow if the desired size is increased
in steps of one.
c) Should the caller have increased max_alloc_size, av_fast_realloc()
could come in a situation where it allocates more than what fits into an
unsigned. In this case the variable containing the allocated size (an
unsigned) won't accurately reflect how much has been allocated. After
this point, lots of reallocations will happen despite the buffer
actually being big enough.
d) av_fast_realloc_array() will always allocate in multiples of array
elements; no memory is wasted with partial elements.

av_fast_realloc() usually allocates size + size / 16 + 32 bytes if size
bytes are desired and if the already existing buffer isn't big enough.
av_fast_realloc_array() instead allocates nb + (nb + 14) / 16. Rounding
up is done in order not to reallocate in steps of one if the current
number is < 16; adding 14 instead of 15 has the effect of only
allocating one element if one element is desired. This is done with an
eye towards applications where arrays might commonly only contain one
element (as happens with the Matroska CueTrackPositions).

Which of the two functions allocates faster depends upon the size of
the elements. E.g. if the elements have a size of 32B and the desired
size is incremented in steps of one, allocations happen at
1, 3, 5, 7, 9, 11, 13, 15, 17, 20, 23, 26 ... for av_fast_realloc(),
1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 21, 24 ... for
av_fast_realloc_array(). For element sizes of 96B, the numbers are
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 21, 23, 25, 27, 30 ...
for av_fast_realloc() whereas the pattern for av_fast_realloc_array() is
unchanged.

Signed-off-by: Andreas Rheinhardt 
---
a) In most places where av_fast_realloc is currently used to reallocate an
array the number of valid entries is stored in a variable of type int.
This patch uses unsigned, because negative values make no sense and because
av_fast_realloc already uses unsigned for the number of allocated bytes.
But this means that when this function is used to replace
av_fast_realloc (like in the patch in the Matroska demuxer in this
patchset), the types of several other variables must be changed. If one
used int for both, one could avoid this, but then one would either have
to ignore the possibility of negative values or check for them and I
like neither of these two possibilities.
b) As can be seen from the code, the allocation limit is even lower than
UINT_MAX - 1. This can of course be easily lifted if desired; it's only
done because I don't see a need for such big arrays.

 doc/APIchanges  |  3 +++
 libavutil/mem.c | 30 ++
 libavutil/mem.h | 30 ++
 libavutil/version.h |  4 ++--
 4 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 401c65a753..7c64755650 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2019-12-25 - xx - lavu 56.37.100 - mem.h
+  Add av_fast_realloc_array().
+
 2019-11-17 - 1c23abc88f - lavu 56.36.100 - eval API
   Add av_expr_count_vars().
 
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 88fe09b179..151ab586c4 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -497,6 +497,36 @@ void *av_fast_realloc(void *ptr, unsigned int *size, 
size_t min_size)
 return ptr;
 }
 
+void *av_fast_realloc_array(void *ptr, unsigned *nb_allocated,
+unsigned min_nb, size_t elsize)
+{
+unsigned max_nb, nb;
+
+if (min_nb <= *nb_allocated)
+return ptr;
+
+/* The 16 / 17 implies that we do not need to check
+ * for overflow in the calculation of nb below. */
+max_nb = FFMIN((UINT_MAX - 1) * 16 / 17, (max_alloc_size - 32) / elsize);
+
+if (min_nb > max_nb) {
+*nb_allocated = 0;
+return NULL;
+}
+
+nb = FFMIN(max_nb, min_nb + (min_nb + 14) / 16);
+
+ptr = av_realloc(ptr, nb * elsize);
+/* We could keep *nb_allocated in case of failure, but this is safer
+ * if the user lost the ptr and uses NULL now. */
+if (!ptr)
+nb = 0;
+
+*nb_allocated = nb;
+
+return ptr;
+}
+
 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
 {
 ff_fast_malloc(ptr, size, min_size, 0);
diff --git a/libavutil/mem.h b/libavutil/mem.h
index 5fb1a02dd9..539a030387 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -370,11 +370,41 @@ int av_reallocp_array(void *ptr, size_t nmemb, size_t 
size);
  

[FFmpeg-devel] [PATCH 15/17] avformat/matroskaenc: Use av_fast_realloc_array for index entries

2019-12-26 Thread Andreas Rheinhardt
Currently, the Matroska muxer reallocates its array of index entries
each time another entry is added. This is bad performance-wise,
especially on Windows where reallocations are slow. This is solved
by switching to av_fast_realloc_array() which ensures that actual
reallocations will happen only seldomly.

For an (admittedly extreme) example which consists of looping a video
consisting of a single keyframe of size 4KB 54 times this improved
the time for writing a frame from 23524201 decicycles (516466 runs,
7822 skips) to 225240 decicycles (522122 runs, 2166 skips) on Windows.

(Writing CRC-32 elements was disabled for these tests.)

Signed-off-by: Andreas Rheinhardt 
---
The guy from ticket #8109 will probably be quite happy about this.

 libavformat/matroskaenc.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 469b604de6..72d19a9f5a 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -88,7 +88,8 @@ typedef struct mkv_cuepoint {
 typedef struct mkv_cues {
 int64_t segment_offset;
 mkv_cuepoint*entries;
-int num_entries;
+unsignednum_entries;
+unsignedallocated_entries;
 } mkv_cues;
 
 typedef struct mkv_track {
@@ -171,7 +172,7 @@ typedef struct MatroskaMuxContext {
 
 /** per-cuepoint-track - 5 1-byte EBML IDs, 5 1-byte EBML sizes, 3 8-byte uint 
max
  * and one 1-byte uint for the track number (this assumes MAX_TRACKS to be <= 
255) */
-#define MAX_CUETRACKPOS_SIZE 35
+#define MAX_CUETRACKPOS_SIZE 35LL
 
 /** per-cuepoint - 1 1-byte EBML ID, 1 1-byte EBML size, 8-byte uint max */
 #define MAX_CUEPOINT_CONTENT_SIZE(num_tracks) 10 + MAX_CUETRACKPOS_SIZE * 
num_tracks
@@ -540,7 +541,8 @@ static int mkv_add_cuepoint(mkv_cues *cues, int stream, int 
tracknum, int64_t ts
 if (ts < 0)
 return 0;
 
-entries = av_realloc_array(entries, cues->num_entries + 1, 
sizeof(mkv_cuepoint));
+entries = av_fast_realloc_array(entries, &cues->allocated_entries,
+cues->num_entries + 1, 
sizeof(mkv_cuepoint));
 if (!entries)
 return AVERROR(ENOMEM);
 cues->entries = entries;
@@ -560,21 +562,21 @@ static int64_t mkv_write_cues(AVFormatContext *s, 
mkv_cues *cues, mkv_track *tra
 MatroskaMuxContext *mkv = s->priv_data;
 AVIOContext *dyn_cp, *pb = s->pb;
 int64_t currentpos;
-int i, j, ret;
+int ret;
 
 currentpos = avio_tell(pb);
 ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CUES);
 if (ret < 0)
 return ret;
 
-for (i = 0; i < cues->num_entries; i++) {
+for (unsigned i = 0; i < cues->num_entries; i++) {
 ebml_master cuepoint, track_positions;
 mkv_cuepoint *entry = &cues->entries[i];
 uint64_t pts = entry->pts;
-int ctp_nb = 0;
+unsigned ctp_nb = 0, j;
 
 // Calculate the number of entries, so we know the element size
-for (j = 0; j < num_tracks; j++)
+for (int j = 0; j < num_tracks; j++)
 tracks[j].has_cue = 0;
 for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) {
 int idx = entry[j].stream_idx;
@@ -591,7 +593,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues 
*cues, mkv_track *tra
 
 // put all the entries from different tracks that have the exact same
 // timestamp into the same CuePoint
-for (j = 0; j < num_tracks; j++)
+for (int j = 0; j < num_tracks; j++)
 tracks[j].has_cue = 0;
 for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) {
 int idx = entry[j].stream_idx;
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 16/17] avformat/matroskadec: Use av_fast_realloc_array()

2019-12-26 Thread Andreas Rheinhardt
instead of av_fast_realloc() for allocating an array. It has the
advantage of doing it's own overflow checks and does not overallocate
unnecessarily: It allocates exactly one element if one element is
desired. This is advantageous for CueTrackPositions: While it is
allowed (and supported) to have more than one of them in a CuePoint,
there is typically only one of them, so that overallocating is a waste.
The memory used for a file with 54 cues entries therefore decreased
from 69624 KB to 52592 KB.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 56 +++
 1 file changed, 27 insertions(+), 29 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 72624dc3f1..fe4a10 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -109,8 +109,8 @@ typedef const struct EbmlSyntax {
 } EbmlSyntax;
 
 typedef struct EbmlList {
-int nb_elem;
-unsigned int alloc_elem_size;
+unsigned nb_elem;
+unsigned nb_allocated;
 void *elem;
 } EbmlList;
 
@@ -1226,13 +1226,10 @@ static int ebml_parse(MatroskaDemuxContext *matroska,
 data = (char *) data + syntax->data_offset;
 if (syntax->list_elem_size) {
 EbmlList *list = data;
-void *newelem;
-
-if ((unsigned)list->nb_elem + 1 >= UINT_MAX / 
syntax->list_elem_size)
-return AVERROR(ENOMEM);
-newelem = av_fast_realloc(list->elem,
-  &list->alloc_elem_size,
-  (list->nb_elem + 1) * 
syntax->list_elem_size);
+void *newelem = av_fast_realloc_array(list->elem,
+  &list->nb_allocated,
+  list->nb_elem + 1,
+  syntax->list_elem_size);
 if (!newelem)
 return AVERROR(ENOMEM);
 list->elem = newelem;
@@ -1464,7 +1461,7 @@ level_check:
 
 static void ebml_free(EbmlSyntax *syntax, void *data)
 {
-int i, j;
+int i;
 for (i = 0; syntax[i].id; i++) {
 void *data_off = (char *) data + syntax[i].data_offset;
 switch (syntax[i].type) {
@@ -1480,12 +1477,12 @@ static void ebml_free(EbmlSyntax *syntax, void *data)
 if (syntax[i].list_elem_size) {
 EbmlList *list = data_off;
 char *ptr = list->elem;
-for (j = 0; j < list->nb_elem;
+for (unsigned j = 0; j < list->nb_elem;
  j++, ptr += syntax[i].list_elem_size)
 ebml_free(syntax[i].def.n, ptr);
 av_freep(&list->elem);
 list->nb_elem = 0;
-list->alloc_elem_size = 0;
+list->nb_allocated = 0;
 } else
 ebml_free(syntax[i].def.n, data_off);
 default:
@@ -1548,7 +1545,7 @@ static MatroskaTrack 
*matroska_find_track_by_num(MatroskaDemuxContext *matroska,
  int num)
 {
 MatroskaTrack *tracks = matroska->tracks.elem;
-int i;
+unsigned i;
 
 for (i = 0; i < matroska->tracks.nb_elem; i++)
 if (tracks[i].num == num)
@@ -1702,7 +1699,7 @@ static void matroska_convert_tag(AVFormatContext *s, 
EbmlList *list,
 {
 MatroskaTag *tags = list->elem;
 char key[1024];
-int i;
+unsigned i;
 
 for (i = 0; i < list->nb_elem; i++) {
 const char *lang = tags[i].lang &&
@@ -1736,7 +1733,7 @@ static void matroska_convert_tags(AVFormatContext *s)
 {
 MatroskaDemuxContext *matroska = s->priv_data;
 MatroskaTags *tags = matroska->tags.elem;
-int i, j;
+unsigned i, j;
 
 for (i = 0; i < matroska->tags.nb_elem; i++) {
 if (tags[i].target.attachuid) {
@@ -1752,7 +1749,7 @@ static void matroska_convert_tags(AVFormatContext *s)
 }
 if (!found) {
 av_log(NULL, AV_LOG_WARNING,
-   "The tags at index %d refer to a "
+   "The tags at index %u refer to a "
"non-existent attachment %"PRId64".\n",
i, tags[i].target.attachuid);
 }
@@ -1769,7 +1766,7 @@ static void matroska_convert_tags(AVFormatContext *s)
 }
 if (!found) {
 av_log(NULL, AV_LOG_WARNING,
-   "The tags at index %d refer to a non-existent chapter "
+   "The tags at index %u refer to a non-existent chapter "
"%"PRId64".\n",
i, tags[i].target.chapteruid);
 }
@@ -1786,7 +1783,7 @@ static void matroska_convert_tags(AVFormatContext *s)
 }
 if (!found) {
 av_log(NULL, AV_LOG_WARNING,
-   "The tags at index %d refer to a non-existent track "
+   "The tags a

[FFmpeg-devel] [PATCH 13/17] avformat/flvenc: Add deinit function

2019-12-26 Thread Andreas Rheinhardt
Fixes memleaks when the trailer is never written or when shift_data()
fails when writing the trailer.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/flvenc.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 106beb..574a44eac6 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -810,8 +810,6 @@ static int flv_write_trailer(AVFormatContext *s)
 put_amf_double(pb, flv_posinfo[i].keyframe_timestamp);
 }
 
-av_freep(&flv->filepositions);
-
 put_amf_string(pb, "");
 avio_w8(pb, AMF_END_OF_OBJECT);
 
@@ -1078,6 +1076,14 @@ static int flv_check_bitstream(struct AVFormatContext 
*s, const AVPacket *pkt)
 return ret;
 }
 
+static void flv_deinit(AVFormatContext *s)
+{
+FLVContext *flv = s->priv_data;
+
+av_freep(&flv->filepositions);
+flv->filepositions_count = flv->filepositions_allocated = 0;
+}
+
 static const AVOption options[] = {
 { "flvflags", "FLV muxer flags", offsetof(FLVContext, flags), 
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 
"flvflags" },
 { "aac_seq_header_detect", "Put AAC sequence header based on stream data", 
0, AV_OPT_TYPE_CONST, {.i64 = FLV_AAC_SEQ_HEADER_DETECT}, INT_MIN, INT_MAX, 
AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
@@ -1107,6 +1113,7 @@ AVOutputFormat ff_flv_muxer = {
 .write_header   = flv_write_header,
 .write_packet   = flv_write_packet,
 .write_trailer  = flv_write_trailer,
+.deinit = flv_deinit,
 .check_bitstream= flv_check_bitstream,
 .codec_tag  = (const AVCodecTag* const []) {
   flv_video_codec_ids, flv_audio_codec_ids, 0
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 12/17] avformat/flvenc: Use array instead of linked list for index

2019-12-26 Thread Andreas Rheinhardt
Using a linked list had very much overhead (the pointer to the next
entry increased the size of the index entry struct from 16 to 24 bytes,
not to mention the overhead of having separate allocations), so it is
better to (re)allocate a continuous array for the index.
av_fast_realloc_array() is used for this purpose, in order not to
reallocate the array for each entry.

Signed-off-by: Andreas Rheinhardt 
---
Now no longer increasing the size of the array by a factor of two.

 libavformat/flvenc.c | 58 +++-
 1 file changed, 19 insertions(+), 39 deletions(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 1aaf0333ca..106beb 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -74,7 +74,6 @@ typedef enum {
 typedef struct FLVFileposition {
 int64_t keyframe_position;
 double keyframe_timestamp;
-struct FLVFileposition *next;
 } FLVFileposition;
 
 typedef struct FLVContext {
@@ -108,9 +107,9 @@ typedef struct FLVContext {
 int acurframeindex;
 int64_t keyframes_info_offset;
 
-int64_t filepositions_count;
 FLVFileposition *filepositions;
-FLVFileposition *head_filepositions;
+unsigned filepositions_count;
+unsigned filepositions_allocated;
 
 AVCodecParameters *audio_par;
 AVCodecParameters *video_par;
@@ -549,27 +548,19 @@ static void flv_write_codec_header(AVFormatContext* s, 
AVCodecParameters* par, i
 
 static int flv_append_keyframe_info(AVFormatContext *s, FLVContext *flv, 
double ts, int64_t pos)
 {
-FLVFileposition *position = av_malloc(sizeof(FLVFileposition));
-
-if (!position) {
-av_log(s, AV_LOG_WARNING, "no mem for add keyframe index!\n");
+FLVFileposition *filepos;
+
+filepos = av_fast_realloc_array(flv->filepositions,
+&flv->filepositions_allocated,
+flv->filepositions_count + 1,
+sizeof(*flv->filepositions));
+if (!filepos) {
+av_log(s, AV_LOG_WARNING, "No memory for keyframe index\n");
 return AVERROR(ENOMEM);
 }
+flv->filepositions = filepos;
 
-position->keyframe_timestamp = ts;
-position->keyframe_position = pos;
-
-if (!flv->filepositions_count) {
-flv->filepositions = position;
-flv->head_filepositions = flv->filepositions;
-position->next = NULL;
-} else {
-flv->filepositions->next = position;
-position->next = NULL;
-flv->filepositions = flv->filepositions->next;
-}
-
-flv->filepositions_count++;
+filepos[flv->filepositions_count++] = (FLVFileposition){ pos, ts };
 
 return 0;
 }
@@ -586,7 +577,7 @@ static int shift_data(AVFormatContext *s)
 int read_size[2];
 AVIOContext *read_pb;
 
-metadata_size = flv->filepositions_count * 9 * 2 + 10; /* filepositions 
and times value */
+metadata_size = flv->filepositions_count * 9LL * 2 + 10; /* filepositions 
and times value */
 metadata_size += 2 + 13; /* filepositions String */
 metadata_size += 2 + 5; /* times String */
 metadata_size += 3; /* Object end */
@@ -784,7 +775,7 @@ static int flv_write_trailer(AVFormatContext *s)
 int64_t cur_pos = avio_tell(s->pb);
 
 if (build_keyframes_idx) {
-FLVFileposition *newflv_posinfo, *p;
+FLVFileposition *flv_posinfo = flv->filepositions;
 
 avio_seek(pb, flv->videosize_offset, SEEK_SET);
 put_amf_double(pb, flv->videosize);
@@ -809,28 +800,17 @@ static int flv_write_trailer(AVFormatContext *s)
 avio_seek(pb, flv->keyframes_info_offset, SEEK_SET);
 put_amf_string(pb, "filepositions");
 put_amf_dword_array(pb, flv->filepositions_count);
-for (newflv_posinfo = flv->head_filepositions; newflv_posinfo; 
newflv_posinfo = newflv_posinfo->next) {
-put_amf_double(pb, newflv_posinfo->keyframe_position + 
flv->keyframe_index_size);
+for (unsigned i = 0; i < flv->filepositions_count; i++) {
+put_amf_double(pb, flv_posinfo[i].keyframe_position + 
flv->keyframe_index_size);
 }
 
 put_amf_string(pb, "times");
 put_amf_dword_array(pb, flv->filepositions_count);
-for (newflv_posinfo = flv->head_filepositions; newflv_posinfo; 
newflv_posinfo = newflv_posinfo->next) {
-put_amf_double(pb, newflv_posinfo->keyframe_timestamp);
+for (unsigned i = 0; i < flv->filepositions_count; i++) {
+put_amf_double(pb, flv_posinfo[i].keyframe_timestamp);
 }
 
-newflv_posinfo = flv->head_filepositions;
-while (newflv_posinfo) {
-p = newflv_posinfo->next;
-if (p) {
-newflv_posinfo->next = p->next;
-av_free(p);
-p = NULL;
-} else {
-av_free(newflv_posinfo);
-newflv_posinfo = NULL;
-}
-}
+av_freep(&flv->filepositions);
 
 put_

[FFmpeg-devel] [PATCH 14/17] avformat/hdsenc: Add explicit deinit function

2019-12-26 Thread Andreas Rheinhardt
hdsenc already had an explicit function to free all allocations in case
of an error, but it was not marked as deinit function, so that it was
not called automatically when the AVFormatContext for muxing gets freed.

Using an explicit deinit function also makes the code cleaner by
allowing to return immediately without "goto fail".

Signed-off-by: Andreas Rheinhardt 
---
Unchanged since last time.

 libavformat/hdsenc.c | 33 +++--
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c
index 46f0026bce..353a45f6df 100644
--- a/libavformat/hdsenc.c
+++ b/libavformat/hdsenc.c
@@ -317,21 +317,18 @@ static int hds_write_header(AVFormatContext *s)
 ff_const59 AVOutputFormat *oformat;
 
 if (mkdir(s->url, 0777) == -1 && errno != EEXIST) {
-ret = AVERROR(errno);
 av_log(s, AV_LOG_ERROR , "Failed to create directory %s\n", s->url);
-goto fail;
+return AVERROR(errno);
 }
 
 oformat = av_guess_format("flv", NULL, NULL);
 if (!oformat) {
-ret = AVERROR_MUXER_NOT_FOUND;
-goto fail;
+return AVERROR_MUXER_NOT_FOUND;
 }
 
 c->streams = av_mallocz_array(s->nb_streams, sizeof(*c->streams));
 if (!c->streams) {
-ret = AVERROR(ENOMEM);
-goto fail;
+return AVERROR(ENOMEM);
 }
 
 for (i = 0; i < s->nb_streams; i++) {
@@ -341,8 +338,7 @@ static int hds_write_header(AVFormatContext *s)
 
 if (!st->codecpar->bit_rate) {
 av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n", i);
-ret = AVERROR(EINVAL);
-goto fail;
+return AVERROR(EINVAL);
 }
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 if (os->has_video) {
@@ -358,8 +354,7 @@ static int hds_write_header(AVFormatContext *s)
 os->has_audio = 1;
 } else {
 av_log(s, AV_LOG_ERROR, "Unsupported stream type in stream %d\n", 
i);
-ret = AVERROR(EINVAL);
-goto fail;
+return AVERROR(EINVAL);
 }
 os->bitrate += s->streams[i]->codecpar->bit_rate;
 
@@ -367,8 +362,7 @@ static int hds_write_header(AVFormatContext *s)
 os->first_stream = i;
 ctx = avformat_alloc_context();
 if (!ctx) {
-ret = AVERROR(ENOMEM);
-goto fail;
+return AVERROR(ENOMEM);
 }
 os->ctx = ctx;
 ctx->oformat = oformat;
@@ -379,8 +373,7 @@ static int hds_write_header(AVFormatContext *s)
  AVIO_FLAG_WRITE, os,
  NULL, hds_write, NULL);
 if (!ctx->pb) {
-ret = AVERROR(ENOMEM);
-goto fail;
+return AVERROR(ENOMEM);
 }
 } else {
 ctx = os->ctx;
@@ -388,8 +381,7 @@ static int hds_write_header(AVFormatContext *s)
 s->streams[i]->id = c->nb_streams;
 
 if (!(st = avformat_new_stream(ctx, NULL))) {
-ret = AVERROR(ENOMEM);
-goto fail;
+return AVERROR(ENOMEM);
 }
 avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar);
 st->codecpar->codec_tag = 0;
@@ -403,7 +395,7 @@ static int hds_write_header(AVFormatContext *s)
 OutputStream *os = &c->streams[i];
 int j;
 if ((ret = avformat_write_header(os->ctx, NULL)) < 0) {
- goto fail;
+ return ret;
 }
 os->ctx_inited = 1;
 avio_flush(os->ctx->pb);
@@ -414,7 +406,7 @@ static int hds_write_header(AVFormatContext *s)
  "%s/stream%d_temp", s->url, i);
 ret = init_file(s, os, 0);
 if (ret < 0)
-goto fail;
+return ret;
 
 if (!os->has_video && c->min_frag_duration <= 0) {
 av_log(s, AV_LOG_WARNING,
@@ -425,9 +417,6 @@ static int hds_write_header(AVFormatContext *s)
 }
 ret = write_manifest(s, 0);
 
-fail:
-if (ret)
-hds_free(s);
 return ret;
 }
 
@@ -557,7 +546,6 @@ static int hds_write_trailer(AVFormatContext *s)
 rmdir(s->url);
 }
 
-hds_free(s);
 return 0;
 }
 
@@ -588,5 +576,6 @@ AVOutputFormat ff_hds_muxer = {
 .write_header   = hds_write_header,
 .write_packet   = hds_write_packet,
 .write_trailer  = hds_write_trailer,
+.deinit = hds_free,
 .priv_class = &hds_class,
 };
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 10/17] avformat/flvenc: Fix leak of oversized packets

2019-12-26 Thread Andreas Rheinhardt
Might happen for annex B H.264.

Signed-off-by: Andreas Rheinhardt 
---
No change since last time.

 libavformat/flvenc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index f6379cbe05..1aaf0333ca 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -992,7 +992,8 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 if (size + flags_size >= 1<<24) {
 av_log(s, AV_LOG_ERROR, "Too large packet with size %u >= %u\n",
size + flags_size, 1<<24);
-return AVERROR(EINVAL);
+ret = AVERROR(EINVAL);
+goto fail;
 }
 
 avio_wb24(pb, size + flags_size);
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 07/17] avformat/webmdashenc: Remove write_trailer

2019-12-26 Thread Andreas Rheinhardt
It doesn't do anything: All allocated blocks have already been freed in
write_header.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/webmdashenc.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
index 26b8727304..d2f0e0ec4d 100644
--- a/libavformat/webmdashenc.c
+++ b/libavformat/webmdashenc.c
@@ -550,12 +550,6 @@ static int webm_dash_manifest_write_packet(AVFormatContext 
*s, AVPacket *pkt)
 return AVERROR_EOF;
 }
 
-static int webm_dash_manifest_write_trailer(AVFormatContext *s)
-{
-free_adaptation_sets(s);
-return 0;
-}
-
 #define OFFSET(x) offsetof(WebMDashMuxContext, x)
 static const AVOption options[] = {
 { "adaptation_sets", "Adaptation sets. Syntax: id=0,streams=0,1,2 
id=1,streams=3,4 and so on", OFFSET(adaptation_sets), AV_OPT_TYPE_STRING, { 0 
}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
@@ -585,7 +579,6 @@ AVOutputFormat ff_webm_dash_manifest_muxer = {
 .priv_data_size= sizeof(WebMDashMuxContext),
 .write_header  = webm_dash_manifest_write_header,
 .write_packet  = webm_dash_manifest_write_packet,
-.write_trailer = webm_dash_manifest_write_trailer,
 .priv_class= &webm_dash_class,
 };
 #endif
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 08/17] avformat/webmdashenc: Fix memleak upon realloc failure

2019-12-26 Thread Andreas Rheinhardt
The classical ptr = av_realloc(ptr, size).

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/webmdashenc.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
index d2f0e0ec4d..e8b7a07974 100644
--- a/libavformat/webmdashenc.c
+++ b/libavformat/webmdashenc.c
@@ -489,11 +489,12 @@ static int parse_adaptation_sets(AVFormatContext *s)
 state = parsing_streams;
 } else if (state == parsing_streams) {
 struct AdaptationSet *as = &w->as[w->nb_as - 1];
+int ret = av_reallocp_array(&as->streams, ++as->nb_streams,
+sizeof(*as->streams));
+if (ret < 0)
+return ret;
 q = p;
 while (*q != '\0' && *q != ',' && *q != ' ') q++;
-as->streams = av_realloc(as->streams, sizeof(*as->streams) * 
++as->nb_streams);
-if (as->streams == NULL)
-return AVERROR(ENOMEM);
 as->streams[as->nb_streams - 1] = to_integer(p, q - p + 1);
 if (as->streams[as->nb_streams - 1] < 0 ||
 as->streams[as->nb_streams - 1] >= s->nb_streams) {
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avfilter: add thistogram video filter

2019-12-26 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi|  46 +
 libavfilter/Makefile|   1 +
 libavfilter/allfilters.c|   1 +
 libavfilter/vf_thistogram.c | 358 
 4 files changed, 406 insertions(+)
 create mode 100644 libavfilter/vf_thistogram.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 8c5d3a5760..4468351fc4 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -11674,6 +11674,7 @@ the histogram. Possible values are @code{none}, 
@code{weak} or
 @code{strong}. It defaults to @code{none}.
 @end table
 
+@anchor{histogram}
 @section histogram
 
 Compute and draw a color distribution histogram for the input video.
@@ -17717,6 +17718,51 @@ PAL output (25i):
 16p: 3334
 @end example
 
+@section thistogram
+
+Compute and draw a color distribution histogram for the input video across 
time.
+
+Unlike @ref{histogram} video filter which only shows histogram of single input 
frame
+at certain time, this filter shows also past histograms of number of frames 
defined
+by @code{width} option.
+
+The computed histogram is a representation of the color component
+distribution in an image.
+
+The filter accepts the following options:
+
+@table @option
+@item width
+Set width of single color component output. Default value is @code{1080}.
+This also set number of passed histograms to keep.
+Allowed range is [50, 8192].
+
+@item display_mode, d
+Set display mode.
+It accepts the following values:
+@table @samp
+@item stack
+Per color component graphs are placed below each other.
+
+@item parade
+Per color component graphs are placed side by side.
+
+@item overlay
+Presents information identical to that in the @code{parade}, except
+that the graphs representing color components are superimposed directly
+over one another.
+@end table
+Default is @code{stack}.
+
+@item levels_mode, m
+Set mode. Can be either @code{linear}, or @code{logarithmic}.
+Default is @code{linear}.
+
+@item components, c
+Set what color components to display.
+Default is @code{7}.
+@end table
+
 @section threshold
 
 Apply threshold effect to video stream.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 37d4eee858..cb024f95ff 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -401,6 +401,7 @@ OBJS-$(CONFIG_SWAPRECT_FILTER)   += 
vf_swaprect.o
 OBJS-$(CONFIG_SWAPUV_FILTER) += vf_swapuv.o
 OBJS-$(CONFIG_TBLEND_FILTER) += vf_blend.o framesync.o
 OBJS-$(CONFIG_TELECINE_FILTER)   += vf_telecine.o
+OBJS-$(CONFIG_THISTOGRAM_FILTER) += vf_thistogram.o
 OBJS-$(CONFIG_THRESHOLD_FILTER)  += vf_threshold.o framesync.o
 OBJS-$(CONFIG_THUMBNAIL_FILTER)  += vf_thumbnail.o
 OBJS-$(CONFIG_THUMBNAIL_CUDA_FILTER) += vf_thumbnail_cuda.o 
vf_thumbnail_cuda.ptx.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index c295f8e403..9f2080f857 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -382,6 +382,7 @@ extern AVFilter ff_vf_swaprect;
 extern AVFilter ff_vf_swapuv;
 extern AVFilter ff_vf_tblend;
 extern AVFilter ff_vf_telecine;
+extern AVFilter ff_vf_thistogram;
 extern AVFilter ff_vf_threshold;
 extern AVFilter ff_vf_thumbnail;
 extern AVFilter ff_vf_thumbnail_cuda;
diff --git a/libavfilter/vf_thistogram.c b/libavfilter/vf_thistogram.c
new file mode 100644
index 00..c29d8f8876
--- /dev/null
+++ b/libavfilter/vf_thistogram.c
@@ -0,0 +1,358 @@
+/*
+ * Copyright (c) 2019 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/avassert.h"
+#include "libavutil/opt.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/intreadwrite.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct THistogramContext {
+const AVClass *class;   ///< AVClass context for log and 
options purpose
+unsigned   histogram[65536];
+inthistogram_size;
+intx_pos;
+intmult;
+intncomp;
+intdncomp;
+intwidth;
+intdisplay_mode;
+intlevels_mod

Re: [FFmpeg-devel] [PATCH] avfilter: add thistogram video filter

2019-12-26 Thread Nicolas George
Paul B Mahol (12019-12-26):
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi|  46 +
>  libavfilter/Makefile|   1 +
>  libavfilter/allfilters.c|   1 +
>  libavfilter/vf_thistogram.c | 358 
>  4 files changed, 406 insertions(+)
>  create mode 100644 libavfilter/vf_thistogram.c
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 8c5d3a5760..4468351fc4 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -11674,6 +11674,7 @@ the histogram. Possible values are @code{none}, 
> @code{weak} or
>  @code{strong}. It defaults to @code{none}.
>  @end table
>  
> +@anchor{histogram}
>  @section histogram
>  
>  Compute and draw a color distribution histogram for the input video.
> @@ -17717,6 +17718,51 @@ PAL output (25i):
>  16p: 3334
>  @end example
>  
> +@section thistogram
> +
> +Compute and draw a color distribution histogram for the input video across 
> time.
> +
> +Unlike @ref{histogram} video filter which only shows histogram of single 
> input frame
> +at certain time, this filter shows also past histograms of number of frames 
> defined
> +by @code{width} option.

Is there a reason to make it a separate filter rather than adding the
option "width" to the existing filter?

If it cannot be done, query_formats(), config_input() and a significant
part of filter_frame() are identical or almost identical: please reduce
code duplication.

Regards,

-- 
  Nicolas George


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avfilter: add thistogram video filter

2019-12-26 Thread Paul B Mahol
On 12/26/19, Nicolas George  wrote:
> Paul B Mahol (12019-12-26):
>> Signed-off-by: Paul B Mahol 
>> ---
>>  doc/filters.texi|  46 +
>>  libavfilter/Makefile|   1 +
>>  libavfilter/allfilters.c|   1 +
>>  libavfilter/vf_thistogram.c | 358 
>>  4 files changed, 406 insertions(+)
>>  create mode 100644 libavfilter/vf_thistogram.c
>>
>> diff --git a/doc/filters.texi b/doc/filters.texi
>> index 8c5d3a5760..4468351fc4 100644
>> --- a/doc/filters.texi
>> +++ b/doc/filters.texi
>> @@ -11674,6 +11674,7 @@ the histogram. Possible values are @code{none},
>> @code{weak} or
>>  @code{strong}. It defaults to @code{none}.
>>  @end table
>>
>> +@anchor{histogram}
>>  @section histogram
>>
>>  Compute and draw a color distribution histogram for the input video.
>> @@ -17717,6 +17718,51 @@ PAL output (25i):
>>  16p: 3334
>>  @end example
>>
>> +@section thistogram
>> +
>> +Compute and draw a color distribution histogram for the input video
>> across time.
>> +
>> +Unlike @ref{histogram} video filter which only shows histogram of single
>> input frame
>> +at certain time, this filter shows also past histograms of number of
>> frames defined
>> +by @code{width} option.
>
> Is there a reason to make it a separate filter rather than adding the
> option "width" to the existing filter?
>
> If it cannot be done, query_formats(), config_input() and a significant
> part of filter_frame() are identical or almost identical: please reduce
> code duplication.

No, I will not.

I hereby here summon FFmpeg Technical Committee to help me with this conflict.

>
> Regards,
>
> --
>   Nicolas George
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/5] avcodec/atrac9dec: Clamp band_ext_data to max that can be read if skipped.

2019-12-26 Thread Lynne
Dec 16, 2019, 23:19 by mich...@niedermayer.cc:

> Fixes: out of array read
> Fixes: 
> 19327/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ATRAC9_fuzzer-5679823087468544
>
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer  
>

Just zero the entire ATRAC9ChannelData->band_ext_data and return if 
!get_bits(gb, 5). That way mode 0 won't change the signal and mode 1, 2, 3 and 
4 will have minimal effect.The 5 bits that are read are meant to correspond to 
the length (already known) of the band extension data to be read. I'm not sure 
what Sony were thinking if its 0.
And ping me on IRC next time.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avfilter/image2: Add source file path and basename to each packet side data.

2019-12-26 Thread Alexandre Heitor Schmidt
> you may have to only activate this (or at least the full path 
metadata) feature
> if the user explicitly requests it. Probably the best way to do that 
is to
> introduce a new option of the image2 demuxer, probably with an 
AV_OPT_TYPE_FLAGS

> type.

Do you mean image2 should, for example, have another option like 
'enable_path_metadata' which would make the demuxer export the metadata 
only when set to "1"?


Thanks.

Alex.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avfilter/image2: Add source file path and basename to each packet side data.

2019-12-26 Thread Alexandre Heitor Schmidt

> About security
> The file path can reveal a wide range of information like
> The platform used,
> The username,
> A potentially writable location
> And a lot more depending on how the directories are layed out
>
> About privacy
> The username is commonly related to the users real name, thats
> sensitive information
> And a lot more depending on how the directories are layed out
> consider a doctors office might have directories which use the
> patients social security numbers in the path
>
> The problem here is this is new metadata, the input never contained
> this sensitive data but depending on what is done downstream with
> it the output might contain this sensitive metadata
>
> converting inputfile to outputfile shouldnt result in outputfile
> containing sensitive information that wasnt in the input and that
> the user did not explicitly ask for to be addded
>
> To show why for example thers a privacy concern here, a slightly
> unfunny hypothetical example:
> A girl gets stalked by some guy online, she takes a screenshoot of
> the message the guy sent her on facebook. And uploads that picture
> sadly the picture contains her name, phone number and GPS coordinates
> without her knowing.

I see your point. I just think that, if the user is generating an 
output, he has access to the input files and path. If he wants to use 
the input information, he can. If he doesn't want to use that 
information, he can just ignore it. Maybe I'm not being able to see the 
whole picture.


> About "That it won't be applied?"
> I think the feature makes sense but it must be ensured that sensitive
> data isnt added or leaking somewhere without the users knowledge and
> concent

The 'concent' here, in my opinion, is the freedom the user has to either 
use or don't use the metadata. Or are you referring to cases where the 
input and output are not processed by the same person, such as on 
broadcast, streaming, etc?


Anyway, if an extra flag for image2, to make it export/don't export the 
path-related metadata is necessary, it can be implemented.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avformat/utils: log corrupt packets

2019-12-26 Thread Gyan Doshi
---
 libavformat/utils.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index b83a740500..7ac3920257 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -876,13 +876,16 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
 if (err < 0)
 return err;
 
-if ((s->flags & AVFMT_FLAG_DISCARD_CORRUPT) &&
-(pkt->flags & AV_PKT_FLAG_CORRUPT)) {
+if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
 av_log(s, AV_LOG_WARNING,
-   "Dropped corrupted packet (stream = %d)\n",
-   pkt->stream_index);
-av_packet_unref(pkt);
-continue;
+   "Packet corrupt (stream = %d, dts = %s)",
+   pkt->stream_index, av_ts2str(pkt->pkt.dts));
+if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) {
+av_log(s, AV_LOG_WARNING, ", dropping it.\n");
+av_packet_unref(pkt);
+continue;
+}
+av_log(s, AV_LOG_WARNING, ".\n");
 }
 
 if (pkt->stream_index >= (unsigned)s->nb_streams) {
-- 
2.24.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avfilter/buffersrc: Remove unused variables

2019-12-26 Thread Michael Niedermayer
On Wed, Dec 25, 2019 at 12:59:07PM +0100, Andreas Rheinhardt wrote:
> Unused since f09ae730.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/buffersrc.c | 2 --
>  1 file changed, 2 deletions(-)

will apply

thx

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

"I am not trying to be anyone's saviour, I'm trying to think about the
 future and not be sad" - Elon Musk



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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/cbs_vp9: Check data_size

2019-12-26 Thread Michael Niedermayer
On Wed, Dec 25, 2019 at 10:49:47PM -0300, James Almer wrote:
> On 12/25/2019 9:18 PM, Michael Niedermayer wrote:
> > Fixes: out of array access
> > Fixes: 
> > 19542/clusterfuzz-testcase-minimized-ffmpeg_BSF_TRACE_HEADERS_fuzzer-5659498341728256
> > 
> > Found-by: continuous fuzzing process 
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/cbs_vp9.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c
> > index 98730e03e3..ec82f11c76 100644
> > --- a/libavcodec/cbs_vp9.c
> > +++ b/libavcodec/cbs_vp9.c
> > @@ -416,6 +416,9 @@ static int cbs_vp9_split_fragment(CodedBitstreamContext 
> > *ctx,
> >  uint8_t superframe_header;
> >  int err;
> >  
> > +if (frag->data_size == 0)
> > +return AVERROR_INVALIDDATA;
> 
> cbs_h2645 and cbs_av1 return 0 when frag->data_size == 0, but cbs_jpeg
> returns invalid data. I don't know which is more correct or ideal, but
> if the failure doesn't happen here it will happen later in the process
> when any code that finds out frag->nb_units is 0 will just bail out, so
> LGTM.

will apply

thx

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

During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/utils: log corrupt packets

2019-12-26 Thread Andreas Rheinhardt
On Thu, Dec 26, 2019 at 3:55 PM Gyan Doshi  wrote:

> ---
>  libavformat/utils.c | 15 +--
>  1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index b83a740500..7ac3920257 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -876,13 +876,16 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
>  if (err < 0)
>  return err;
>
> -if ((s->flags & AVFMT_FLAG_DISCARD_CORRUPT) &&
> -(pkt->flags & AV_PKT_FLAG_CORRUPT)) {
> +if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
>  av_log(s, AV_LOG_WARNING,
> -   "Dropped corrupted packet (stream = %d)\n",
> -   pkt->stream_index);
> -av_packet_unref(pkt);
> -continue;
> +   "Packet corrupt (stream = %d, dts = %s)",
> +   pkt->stream_index, av_ts2str(pkt->pkt.dts));
>

pkt->pkt.dts? This shouldn't even compile.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] lavc: remove not required includes, relocate some functions

2019-12-26 Thread Vitamin Vitamin
Ping?

On Wed, 25 Dec 2019 at 23:13, vitamin-caig  wrote:

> Signed-off-by: vitamin-caig 
> ---
>  libavcodec/raw.c| 11 +++
>  libavcodec/raw.h|  2 --
>  libavcodec/rawdec.c |  2 +-
>  libavcodec/utils.c  | 12 
>  4 files changed, 12 insertions(+), 15 deletions(-)
>
> diff --git a/libavcodec/raw.c b/libavcodec/raw.c
> index b6fb91c1c6..96b7442f51 100644
> --- a/libavcodec/raw.c
> +++ b/libavcodec/raw.c
> @@ -301,6 +301,17 @@ const struct PixelFormatTag
> *avpriv_get_raw_pix_fmt_tags(void)
>  return ff_raw_pix_fmt_tags;
>  }
>
> +enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags,
> +   unsigned int fourcc)
> +{
> +while (tags->pix_fmt >= 0) {
> +if (tags->fourcc == fourcc)
> +return tags->pix_fmt;
> +tags++;
> +}
> +return AV_PIX_FMT_NONE;
> +}
> +
>  unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat fmt)
>  {
>  const PixelFormatTag *tags = ff_raw_pix_fmt_tags;
> diff --git a/libavcodec/raw.h b/libavcodec/raw.h
> index 28a27b1f9e..af3dd4fb79 100644
> --- a/libavcodec/raw.h
> +++ b/libavcodec/raw.h
> @@ -36,8 +36,6 @@ typedef struct PixelFormatTag {
>  unsigned int fourcc;
>  } PixelFormatTag;
>
> -extern const PixelFormatTag ff_raw_pix_fmt_tags[]; // exposed through
> avpriv_get_raw_pix_fmt_tags()
> -
>  const struct PixelFormatTag *avpriv_get_raw_pix_fmt_tags(void);
>
>  enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags,
> unsigned int fourcc);
> diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
> index 0b2d8708e6..a99f1a2c52 100644
> --- a/libavcodec/rawdec.c
> +++ b/libavcodec/rawdec.c
> @@ -81,7 +81,7 @@ static av_cold int raw_init_decoder(AVCodecContext
> *avctx)
>  avctx->pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi,
>avctx->bits_per_coded_sample);
>  else if (avctx->codec_tag && (avctx->codec_tag & 0xFF) !=
> MKTAG('B','I','T', 0))
> -avctx->pix_fmt = avpriv_find_pix_fmt(ff_raw_pix_fmt_tags,
> avctx->codec_tag);
> +avctx->pix_fmt =
> avpriv_find_pix_fmt(avpriv_get_raw_pix_fmt_tags(), avctx->codec_tag);
>  else if (avctx->pix_fmt == AV_PIX_FMT_NONE &&
> avctx->bits_per_coded_sample)
>  avctx->pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi,
>avctx->bits_per_coded_sample);
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 8a49234bcd..6ce8d7b964 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -55,7 +55,6 @@
>  #include "version.h"
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #if CONFIG_ICONV
> @@ -464,17 +463,6 @@ int avcodec_default_execute2(AVCodecContext *c, int
> (*func)(AVCodecContext *c2,
>  return 0;
>  }
>
> -enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags,
> -   unsigned int fourcc)
> -{
> -while (tags->pix_fmt >= 0) {
> -if (tags->fourcc == fourcc)
> -return tags->pix_fmt;
> -tags++;
> -}
> -return AV_PIX_FMT_NONE;
> -}
> -
>  #if FF_API_CODEC_GET_SET
>  MAKE_ACCESSORS(AVCodecContext, codec, AVRational, pkt_timebase)
>  MAKE_ACCESSORS(AVCodecContext, codec, const AVCodecDescriptor *,
> codec_descriptor)
> --
> 2.20.1
>
>

-- 
With best wishes
  Vitamin/CAIG/2001
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2] avformat/utils: log corrupt packets

2019-12-26 Thread Gyan Doshi
---
 libavformat/utils.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index b472762dd1..1d2c41e6e6 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -883,13 +883,16 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
 return err;
 }
 
-if ((s->flags & AVFMT_FLAG_DISCARD_CORRUPT) &&
-(pkt->flags & AV_PKT_FLAG_CORRUPT)) {
+if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
 av_log(s, AV_LOG_WARNING,
-   "Dropped corrupted packet (stream = %d)\n",
-   pkt->stream_index);
-av_packet_unref(pkt);
-continue;
+   "Packet corrupt (stream = %d, dts = %s)",
+   pkt->stream_index, av_ts2str(pkt->dts));
+if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) {
+av_log(s, AV_LOG_WARNING, ", dropping it.\n");
+av_packet_unref(pkt);
+continue;
+}
+av_log(s, AV_LOG_WARNING, ".\n");
 }
 
 av_assert0(pkt->stream_index < (unsigned)s->nb_streams &&
-- 
2.24.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/utils: log corrupt packets

2019-12-26 Thread Gyan



On 26-12-2019 08:30 pm, Andreas Rheinhardt wrote:

On Thu, Dec 26, 2019 at 3:55 PM Gyan Doshi  wrote:


---
  libavformat/utils.c | 15 +--
  1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index b83a740500..7ac3920257 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -876,13 +876,16 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
  if (err < 0)
  return err;

-if ((s->flags & AVFMT_FLAG_DISCARD_CORRUPT) &&
-(pkt->flags & AV_PKT_FLAG_CORRUPT)) {
+if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
  av_log(s, AV_LOG_WARNING,
-   "Dropped corrupted packet (stream = %d)\n",
-   pkt->stream_index);
-av_packet_unref(pkt);
-continue;
+   "Packet corrupt (stream = %d, dts = %s)",
+   pkt->stream_index, av_ts2str(pkt->pkt.dts));


pkt->pkt.dts? This shouldn't even compile.

Oops. Fixed and checked.

Thanks.
Gyan
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/5] avcodec/atrac9dec: Clamp band_ext_data to max that can be read if skipped.

2019-12-26 Thread Lynne
Dec 26, 2019, 13:57 by d...@lynne.ee:

> Dec 16, 2019, 23:19 by mich...@niedermayer.cc:
>
>> Fixes: out of array read
>> Fixes: 
>> 19327/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ATRAC9_fuzzer-5679823087468544
>>
>> Found-by: continuous fuzzing process 
>> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
>> Signed-off-by: Michael Niedermayer  
>>

Actually nevermind, patch is good as-is. I think a 0 len just means to reuse 
the parameters from the previous. So clipping them should be fine.
You should replace the FFMIN(val, (len << 1) - 1) with a av_clip_uintp2(val, 
len) which does exactly that.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/5] avcodec/atrac9dec: Clamp band_ext_data to max that can be read if skipped.

2019-12-26 Thread James Almer
On 12/26/2019 1:24 PM, Lynne wrote:
> Dec 26, 2019, 13:57 by d...@lynne.ee:
> 
>> Dec 16, 2019, 23:19 by mich...@niedermayer.cc:
>>
>>> Fixes: out of array read
>>> Fixes: 
>>> 19327/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ATRAC9_fuzzer-5679823087468544
>>>
>>> Found-by: continuous fuzzing process 
>>> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
>>> Signed-off-by: Michael Niedermayer  
>>>
> 
> Actually nevermind, patch is good as-is. I think a 0 len just means to reuse 
> the parameters from the previous. So clipping them should be fine.
> You should replace the FFMIN(val, (len << 1) - 1) with a av_clip_uintp2(val, 
> len) which does exactly that.

I guess he didn't use it because c->band_ext_data is an int array. A
quick look at the code shows it apparently can't be negative, so
av_clip_uintp2() should be safe, but maybe the type should be changed to
unsigned to avoid confusion.

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/5] avcodec/atrac9dec: Clamp band_ext_data to max that can be read if skipped.

2019-12-26 Thread James Almer
On 12/26/2019 1:30 PM, James Almer wrote:
> On 12/26/2019 1:24 PM, Lynne wrote:
>> Dec 26, 2019, 13:57 by d...@lynne.ee:
>>
>>> Dec 16, 2019, 23:19 by mich...@niedermayer.cc:
>>>
 Fixes: out of array read
 Fixes: 
 19327/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ATRAC9_fuzzer-5679823087468544

 Found-by: continuous fuzzing process 
 https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
 Signed-off-by: Michael Niedermayer  

>>
>> Actually nevermind, patch is good as-is. I think a 0 len just means to reuse 
>> the parameters from the previous. So clipping them should be fine.
>> You should replace the FFMIN(val, (len << 1) - 1) with a av_clip_uintp2(val, 
>> len) which does exactly that.
> 
> I guess he didn't use it because c->band_ext_data is an int array. A
> quick look at the code shows it apparently can't be negative, so
> av_clip_uintp2() should be safe, but maybe the type should be changed to
> unsigned to avoid confusion.

Nevermind, didn't realize av_clip_uintp2() takes ints as input arguments.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] lavu/avstring: deprecate av_d2str().

2019-12-26 Thread Nicolas George
It is no longer used in our code base and does not seem
to be used much in other projects.

Signed-off-by: Nicolas George 
---
 doc/APIchanges | 3 +++
 libavutil/avstring.c   | 2 ++
 libavutil/avstring.h   | 5 +
 libavutil/tests/avstring.c | 4 
 libavutil/version.h| 3 +++
 5 files changed, 17 insertions(+)

diff --git a/doc/APIchanges b/doc/APIchanges
index 5b8d801f06..a22932c8f2 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2019-12-xx - xx - lavu 56.37.100 - avstring.h
+  Deprecate av_d2str(). Use av_asprintf() instead.
+
 2019-12-xx - xx - lavu 56.37.100 - buffer.h
   Add av_buffer_pool_buffer_get_opaque().
 
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 76a13ba3b5..f6f7ab568e 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -136,6 +136,7 @@ end:
 return p;
 }
 
+#if FF_API_D2STR
 char *av_d2str(double d)
 {
 char *str = av_malloc(16);
@@ -143,6 +144,7 @@ char *av_d2str(double d)
 snprintf(str, 16, "%f", d);
 return str;
 }
+#endif
 
 #define WHITESPACES " \n\t\r"
 
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index 274335cfb9..ee225585b3 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include "attributes.h"
+#include "version.h"
 
 /**
  * @addtogroup lavu_string
@@ -155,10 +156,14 @@ static inline size_t av_strnlen(const char *s, size_t len)
  */
 char *av_asprintf(const char *fmt, ...) av_printf_format(1, 2);
 
+#if FF_API_D2STR
 /**
  * Convert a number to an av_malloced string.
+ * @deprecated  use av_asprintf() with "%f" or a more specific format
  */
+attribute_deprecated
 char *av_d2str(double d);
+#endif
 
 /**
  * Unescape the given string until a non escaped terminating char,
diff --git a/libavutil/tests/avstring.c b/libavutil/tests/avstring.c
index 887bd25a12..37a2cf1833 100644
--- a/libavutil/tests/avstring.c
+++ b/libavutil/tests/avstring.c
@@ -109,6 +109,8 @@ int main(void)
 TEST_STRIREPLACE(haystack, needle [2], "Education consists mainly in what 
we have instead.");
 TEST_STRIREPLACE(haystack, needle [1], "Education consists mainly in what 
we have instead");
 
+#if FF_API_D2STR
+FF_DISABLE_DEPRECATION_WARNINGS
 /*Testing av_d2str()*/
 #define TEST_D2STR(value, expected) \
 if((ptr = av_d2str(value)) == NULL){ \
@@ -121,5 +123,7 @@ int main(void)
 TEST_D2STR(0 ,  "0.00");
 TEST_D2STR(-1.2333234, "-1.233323");
 TEST_D2STR(-1.2333237, "-1.233324");
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 return 0;
 }
diff --git a/libavutil/version.h b/libavutil/version.h
index 4de0fa1fc3..835206a8ff 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -129,6 +129,9 @@
 #ifndef FF_API_PSEUDOPAL
 #define FF_API_PSEUDOPAL(LIBAVUTIL_VERSION_MAJOR < 57)
 #endif
+#ifndef FF_API_D2STR
+#define FF_API_D2STR(LIBAVUTIL_VERSION_MAJOR < 57)
+#endif
 
 
 /**
-- 
2.24.0

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2] avutil/mem: Add av_fast_realloc_array()

2019-12-26 Thread Andreas Rheinhardt
This is an array-equivalent of av_fast_realloc(). Its advantages
compared to using av_fast_realloc() for allocating arrays are as
follows:

a) It performs its own overflow checks for the multiplication that is
implicit in array allocations. (And it only needs to perform these
checks (as well as the multiplication itself) in case the array needs to
be reallocated.)
b) It guarantees to not allocated more than UINT_MAX - 1 elements, so
the caller needn't check for overflow if the desired size is increased
in steps of one.
c) Should the caller have increased max_alloc_size, av_fast_realloc()
could come in a situation where it allocates more than what fits into an
unsigned. In this case the variable containing the allocated size (an
unsigned) won't accurately reflect how much has been allocated. After
this point, lots of reallocations will happen despite the buffer
actually being big enough.
d) av_fast_realloc_array() will always allocate in multiples of array
elements; no memory is wasted with partial elements.

av_fast_realloc() usually allocates size + size / 16 + 32 bytes if size
bytes are desired and if the already existing buffer isn't big enough.
av_fast_realloc_array() instead allocates nb + (nb + 14) / 16. Rounding
up is done in order not to reallocate in steps of one if the current
number is < 16; adding 14 instead of 15 has the effect of only
allocating one element if one element is desired. This is done with an
eye towards applications where arrays might commonly only contain one
element (as happens with the Matroska CueTrackPositions).

Which of the two functions allocates faster depends upon the size of
the elements. E.g. if the elements have a size of 32B and the desired
size is incremented in steps of one, allocations happen at
1, 3, 5, 7, 9, 11, 13, 15, 17, 20, 23, 26 ... for av_fast_realloc(),
1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 21, 24 ... for
av_fast_realloc_array(). For element sizes of 96B, the numbers are
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 21, 23, 25, 27, 30 ...
for av_fast_realloc() whereas the pattern for av_fast_realloc_array() is
unchanged.

Signed-off-by: Andreas Rheinhardt 
---
I missed that Marton has already pushed his patch for avutil/buffer
which also included changes to doc/APIchanges and the lavu version
number. Therefore I am resending this to solve the ensuing merge
conflict.

 doc/APIchanges  |  3 +++
 libavutil/mem.c | 30 ++
 libavutil/mem.h | 30 ++
 libavutil/version.h |  2 +-
 4 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 5b8d801f06..b7cede329a 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2019-12-26 - xx - lavu 56.38.100 - mem.h
+  Add av_fast_realloc_array().
+
 2019-12-xx - xx - lavu 56.37.100 - buffer.h
   Add av_buffer_pool_buffer_get_opaque().
 
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 88fe09b179..151ab586c4 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -497,6 +497,36 @@ void *av_fast_realloc(void *ptr, unsigned int *size, 
size_t min_size)
 return ptr;
 }
 
+void *av_fast_realloc_array(void *ptr, unsigned *nb_allocated,
+unsigned min_nb, size_t elsize)
+{
+unsigned max_nb, nb;
+
+if (min_nb <= *nb_allocated)
+return ptr;
+
+/* The 16 / 17 implies that we do not need to check
+ * for overflow in the calculation of nb below. */
+max_nb = FFMIN((UINT_MAX - 1) * 16 / 17, (max_alloc_size - 32) / elsize);
+
+if (min_nb > max_nb) {
+*nb_allocated = 0;
+return NULL;
+}
+
+nb = FFMIN(max_nb, min_nb + (min_nb + 14) / 16);
+
+ptr = av_realloc(ptr, nb * elsize);
+/* We could keep *nb_allocated in case of failure, but this is safer
+ * if the user lost the ptr and uses NULL now. */
+if (!ptr)
+nb = 0;
+
+*nb_allocated = nb;
+
+return ptr;
+}
+
 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
 {
 ff_fast_malloc(ptr, size, min_size, 0);
diff --git a/libavutil/mem.h b/libavutil/mem.h
index 5fb1a02dd9..539a030387 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -370,11 +370,41 @@ int av_reallocp_array(void *ptr, size_t nmemb, size_t 
size);
  * @return `ptr` if the buffer is large enough, a pointer to newly reallocated
  * buffer if the buffer was not large enough, or `NULL` in case of
  * error
+ * @see av_fast_realloc_array()
  * @see av_realloc()
  * @see av_fast_malloc()
  */
 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
 
+/**
+ * Reallocate the given array if it is not large enough, otherwise do nothing.
+ *
+ * If the given array is `NULL`, then a new uninitialized array is allocated.
+ *
+ * If the given array is not large enough, and reallocation fails, `NULL` is
+ * returned and `*nb_allocated` is set to 0, but the original array 

Re: [FFmpeg-devel] [PATCH] avfilter: add thistogram video filter

2019-12-26 Thread Paul B Mahol
On 12/26/19, Paul B Mahol  wrote:
> On 12/26/19, Nicolas George  wrote:
>> Paul B Mahol (12019-12-26):
>>> Signed-off-by: Paul B Mahol 
>>> ---
>>>  doc/filters.texi|  46 +
>>>  libavfilter/Makefile|   1 +
>>>  libavfilter/allfilters.c|   1 +
>>>  libavfilter/vf_thistogram.c | 358 
>>>  4 files changed, 406 insertions(+)
>>>  create mode 100644 libavfilter/vf_thistogram.c
>>>
>>> diff --git a/doc/filters.texi b/doc/filters.texi
>>> index 8c5d3a5760..4468351fc4 100644
>>> --- a/doc/filters.texi
>>> +++ b/doc/filters.texi
>>> @@ -11674,6 +11674,7 @@ the histogram. Possible values are @code{none},
>>> @code{weak} or
>>>  @code{strong}. It defaults to @code{none}.
>>>  @end table
>>>
>>> +@anchor{histogram}
>>>  @section histogram
>>>
>>>  Compute and draw a color distribution histogram for the input video.
>>> @@ -17717,6 +17718,51 @@ PAL output (25i):
>>>  16p: 3334
>>>  @end example
>>>
>>> +@section thistogram
>>> +
>>> +Compute and draw a color distribution histogram for the input video
>>> across time.
>>> +
>>> +Unlike @ref{histogram} video filter which only shows histogram of
>>> single
>>> input frame
>>> +at certain time, this filter shows also past histograms of number of
>>> frames defined
>>> +by @code{width} option.
>>
>> Is there a reason to make it a separate filter rather than adding the
>> option "width" to the existing filter?
>>
>> If it cannot be done, query_formats(), config_input() and a significant
>> part of filter_frame() are identical or almost identical: please reduce
>> code duplication.
>
> No, I will not.
>
> I hereby here summon FFmpeg Technical Committee to help me with this
> conflict.

Also there is bunch of all small different changes in code, which
conflict more with your proposal.

>
>>
>> Regards,
>>
>> --
>>   Nicolas George
>>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 11/17] avutil/mem: Add av_fast_realloc_array()

2019-12-26 Thread Michael Niedermayer
On Thu, Dec 26, 2019 at 11:53:36AM +0100, Andreas Rheinhardt wrote:
> This is an array-equivalent of av_fast_realloc(). Its advantages
> compared to using av_fast_realloc() for allocating arrays are as
> follows:
> 
> a) It performs its own overflow checks for the multiplication that is
> implicit in array allocations. (And it only needs to perform these
> checks (as well as the multiplication itself) in case the array needs to
> be reallocated.)
> b) It guarantees to not allocated more than UINT_MAX - 1 elements, so
> the caller needn't check for overflow if the desired size is increased
> in steps of one.
> c) Should the caller have increased max_alloc_size, av_fast_realloc()
> could come in a situation where it allocates more than what fits into an
> unsigned. In this case the variable containing the allocated size (an
> unsigned) won't accurately reflect how much has been allocated. After
> this point, lots of reallocations will happen despite the buffer
> actually being big enough.
> d) av_fast_realloc_array() will always allocate in multiples of array
> elements; no memory is wasted with partial elements.
> 
> av_fast_realloc() usually allocates size + size / 16 + 32 bytes if size
> bytes are desired and if the already existing buffer isn't big enough.
> av_fast_realloc_array() instead allocates nb + (nb + 14) / 16. Rounding
> up is done in order not to reallocate in steps of one if the current
> number is < 16; adding 14 instead of 15 has the effect of only
> allocating one element if one element is desired. This is done with an
> eye towards applications where arrays might commonly only contain one
> element (as happens with the Matroska CueTrackPositions).
> 
> Which of the two functions allocates faster depends upon the size of
> the elements. E.g. if the elements have a size of 32B and the desired
> size is incremented in steps of one, allocations happen at
> 1, 3, 5, 7, 9, 11, 13, 15, 17, 20, 23, 26 ... for av_fast_realloc(),
> 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 21, 24 ... for
> av_fast_realloc_array(). For element sizes of 96B, the numbers are
> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 21, 23, 25, 27, 30 ...
> for av_fast_realloc() whereas the pattern for av_fast_realloc_array() is
> unchanged.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
> a) In most places where av_fast_realloc is currently used to reallocate an
> array the number of valid entries is stored in a variable of type int.
> This patch uses unsigned, because negative values make no sense and because
> av_fast_realloc already uses unsigned for the number of allocated bytes.
> But this means that when this function is used to replace
> av_fast_realloc (like in the patch in the Matroska demuxer in this
> patchset), the types of several other variables must be changed. If one
> used int for both, one could avoid this, but then one would either have
> to ignore the possibility of negative values or check for them and I
> like neither of these two possibilities.

using INT_MAX instead of UINT_MAX would solve this indepenandt of the
argument type.
And considering that most arrays we have are indexed by int type arguments.
If we use an arbitrary limit INT_MAX seems the more robust choice than UINT_MAX

thx

[...]
-- 
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
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avfilter: add thistogram video filter

2019-12-26 Thread Nicolas George
Paul B Mahol (12019-12-26):
> Also there is bunch of all small different changes in code, which
> conflict more with your proposal.

I had looked at the code before making my comment: a significant part is
exactly identical or only differs by the name of the variable.

The rest can be handled with conditional and variables, I trust your
skill for that.

But as it is, there is way too much code duplication: any fix or
enhancement made to one of the filter will have to be done to the other,
which is in practice unlikely, and we will end up with two filters with
slightly different user interface and features. This is terrible for
user experience.

-- 
  Nicolas George


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v2] avutil/mem: Add av_fast_realloc_array()

2019-12-26 Thread Nicolas George
Andreas Rheinhardt (12019-12-26):
> b) It guarantees to not allocated more than UINT_MAX - 1 elements, so
> the caller needn't check for overflow if the desired size is increased
> in steps of one.

This is preparing trouble for later, and as Michael pointed, it will not
work when the number of elements is stored in a signed integer. (It was
a mistake to use a signed integer in the first place, but that
particular mistake is already all over the place). I strongly suggest we
try to make things properly:

- Make nb_allocated and min_nb size_t as they should be.

- Do not hard-code UINT_MAX-1, make it an argument, max_nb: that way, if
  the index is an integer, just pass INT_MAX-1, and if it is properly
  size_t, pass SIZE_MAX-1.

- Since we can't pass a pointer to int as a pointer to size_t, add a
  small convenience wrapper av_fast_realloc_array_int() just to convert
  the type of nb_allocated. That's ugly, but I do not see a better
  solution. Or we can decide we must change the type of the size to
  size_t whenever we update code to use av_fast_realloc_array().

And while we are at it, I would like better:

- Alter ptr the same way nb_allocated is altered, and return a real
  error code in case of error. Otherwise, the caller has to guess that
  only AVERROR(ENOMEM) is possible, and we have seen that these
  assumptions and hard-coded error code have a way of overstaying their
  welcome.

Poor choice of types have caused problems in the past. They will cause
more problems as the memory of computers, and therefore the task we give
them, grow. Let us not cultivate them.

Regards,

-- 
  Nicolas George


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 01/13] avutil/opt: add full support for AV_OPT_TYPE_DICT

2019-12-26 Thread Michael Niedermayer
On Wed, Dec 25, 2019 at 10:43:02PM +0100, Marton Balint wrote:
> Now it is possible to set them from a string, to serialize them and to use a
> default value.
> 
> Signed-off-by: Marton Balint 
> ---
>  libavutil/opt.c | 51 ++-
>  libavutil/opt.h | 10 +++---
>  2 files changed, 53 insertions(+), 8 deletions(-)

nice patch

thanks

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

During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] lavu/avstring: deprecate av_d2str().

2019-12-26 Thread James Almer
On 12/26/2019 3:40 PM, Nicolas George wrote:
> It is no longer used in our code base and does not seem
> to be used much in other projects.
> 
> Signed-off-by: Nicolas George 
> ---
>  doc/APIchanges | 3 +++
>  libavutil/avstring.c   | 2 ++
>  libavutil/avstring.h   | 5 +
>  libavutil/tests/avstring.c | 4 
>  libavutil/version.h| 3 +++
>  5 files changed, 17 insertions(+)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 5b8d801f06..a22932c8f2 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
>  
>  API changes, most recent first:
>  
> +2019-12-xx - xx - lavu 56.37.100 - avstring.h
> +  Deprecate av_d2str(). Use av_asprintf() instead.
> +
>  2019-12-xx - xx - lavu 56.37.100 - buffer.h
>Add av_buffer_pool_buffer_get_opaque().
>  
> diff --git a/libavutil/avstring.c b/libavutil/avstring.c
> index 76a13ba3b5..f6f7ab568e 100644
> --- a/libavutil/avstring.c
> +++ b/libavutil/avstring.c
> @@ -136,6 +136,7 @@ end:
>  return p;
>  }
>  
> +#if FF_API_D2STR
>  char *av_d2str(double d)
>  {
>  char *str = av_malloc(16);
> @@ -143,6 +144,7 @@ char *av_d2str(double d)
>  snprintf(str, 16, "%f", d);
>  return str;
>  }
> +#endif
>  
>  #define WHITESPACES " \n\t\r"
>  
> diff --git a/libavutil/avstring.h b/libavutil/avstring.h
> index 274335cfb9..ee225585b3 100644
> --- a/libavutil/avstring.h
> +++ b/libavutil/avstring.h
> @@ -24,6 +24,7 @@
>  #include 
>  #include 
>  #include "attributes.h"
> +#include "version.h"
>  
>  /**
>   * @addtogroup lavu_string
> @@ -155,10 +156,14 @@ static inline size_t av_strnlen(const char *s, size_t 
> len)
>   */
>  char *av_asprintf(const char *fmt, ...) av_printf_format(1, 2);
>  
> +#if FF_API_D2STR
>  /**
>   * Convert a number to an av_malloced string.
> + * @deprecated  use av_asprintf() with "%f" or a more specific format
>   */
> +attribute_deprecated
>  char *av_d2str(double d);
> +#endif
>  
>  /**
>   * Unescape the given string until a non escaped terminating char,
> diff --git a/libavutil/tests/avstring.c b/libavutil/tests/avstring.c
> index 887bd25a12..37a2cf1833 100644
> --- a/libavutil/tests/avstring.c
> +++ b/libavutil/tests/avstring.c
> @@ -109,6 +109,8 @@ int main(void)
>  TEST_STRIREPLACE(haystack, needle [2], "Education consists mainly in 
> what we have instead.");
>  TEST_STRIREPLACE(haystack, needle [1], "Education consists mainly in 
> what we have instead");
>  
> +#if FF_API_D2STR
> +FF_DISABLE_DEPRECATION_WARNINGS
>  /*Testing av_d2str()*/
>  #define TEST_D2STR(value, expected) \
>  if((ptr = av_d2str(value)) == NULL){ \
> @@ -121,5 +123,7 @@ int main(void)
>  TEST_D2STR(0 ,  "0.00");
>  TEST_D2STR(-1.2333234, "-1.233323");
>  TEST_D2STR(-1.2333237, "-1.233324");
> +FF_ENABLE_DEPRECATION_WARNINGS
> +#endif
>  return 0;
>  }
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 4de0fa1fc3..835206a8ff 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -129,6 +129,9 @@
>  #ifndef FF_API_PSEUDOPAL
>  #define FF_API_PSEUDOPAL(LIBAVUTIL_VERSION_MAJOR < 57)
>  #endif
> +#ifndef FF_API_D2STR
> +#define FF_API_D2STR(LIBAVUTIL_VERSION_MAJOR < 57)

I guess we'll bumping in the coming months (it's been a long while since
the last time, and some cleaning is in order), so might as well make
this < 58 so we don't have to postpone it later.

> +#endif
>  
>  
>  /**
> 

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] lavc: remove not required includes, relocate some functions

2019-12-26 Thread vitamin-caig
Signed-off-by: vitamin-caig 
---
 libavcodec/raw.c| 11 +++
 libavcodec/raw.h|  2 --
 libavcodec/rawdec.c |  2 +-
 libavcodec/utils.c  | 12 
 4 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/libavcodec/raw.c b/libavcodec/raw.c
index b6fb91c1c6..96b7442f51 100644
--- a/libavcodec/raw.c
+++ b/libavcodec/raw.c
@@ -301,6 +301,17 @@ const struct PixelFormatTag 
*avpriv_get_raw_pix_fmt_tags(void)
 return ff_raw_pix_fmt_tags;
 }
 
+enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags,
+   unsigned int fourcc)
+{
+while (tags->pix_fmt >= 0) {
+if (tags->fourcc == fourcc)
+return tags->pix_fmt;
+tags++;
+}
+return AV_PIX_FMT_NONE;
+}
+
 unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat fmt)
 {
 const PixelFormatTag *tags = ff_raw_pix_fmt_tags;
diff --git a/libavcodec/raw.h b/libavcodec/raw.h
index 28a27b1f9e..af3dd4fb79 100644
--- a/libavcodec/raw.h
+++ b/libavcodec/raw.h
@@ -36,8 +36,6 @@ typedef struct PixelFormatTag {
 unsigned int fourcc;
 } PixelFormatTag;
 
-extern const PixelFormatTag ff_raw_pix_fmt_tags[]; // exposed through 
avpriv_get_raw_pix_fmt_tags()
-
 const struct PixelFormatTag *avpriv_get_raw_pix_fmt_tags(void);
 
 enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags, unsigned 
int fourcc);
diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index 0b2d8708e6..a99f1a2c52 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -81,7 +81,7 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
 avctx->pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi,
   avctx->bits_per_coded_sample);
 else if (avctx->codec_tag && (avctx->codec_tag & 0xFF) != 
MKTAG('B','I','T', 0))
-avctx->pix_fmt = avpriv_find_pix_fmt(ff_raw_pix_fmt_tags, 
avctx->codec_tag);
+avctx->pix_fmt = avpriv_find_pix_fmt(avpriv_get_raw_pix_fmt_tags(), 
avctx->codec_tag);
 else if (avctx->pix_fmt == AV_PIX_FMT_NONE && avctx->bits_per_coded_sample)
 avctx->pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi,
   avctx->bits_per_coded_sample);
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 8a49234bcd..6ce8d7b964 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -55,7 +55,6 @@
 #include "version.h"
 #include 
 #include 
-#include 
 #include 
 #include 
 #if CONFIG_ICONV
@@ -464,17 +463,6 @@ int avcodec_default_execute2(AVCodecContext *c, int 
(*func)(AVCodecContext *c2,
 return 0;
 }
 
-enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags,
-   unsigned int fourcc)
-{
-while (tags->pix_fmt >= 0) {
-if (tags->fourcc == fourcc)
-return tags->pix_fmt;
-tags++;
-}
-return AV_PIX_FMT_NONE;
-}
-
 #if FF_API_CODEC_GET_SET
 MAKE_ACCESSORS(AVCodecContext, codec, AVRational, pkt_timebase)
 MAKE_ACCESSORS(AVCodecContext, codec, const AVCodecDescriptor *, 
codec_descriptor)
-- 
2.20.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/2] avfilter: add thistogram video filter

2019-12-26 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi   |  46 ++
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vf_histogram.c | 127 ++---
 4 files changed, 151 insertions(+), 24 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 8c5d3a5760..4468351fc4 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -11674,6 +11674,7 @@ the histogram. Possible values are @code{none}, 
@code{weak} or
 @code{strong}. It defaults to @code{none}.
 @end table
 
+@anchor{histogram}
 @section histogram
 
 Compute and draw a color distribution histogram for the input video.
@@ -17717,6 +17718,51 @@ PAL output (25i):
 16p: 3334
 @end example
 
+@section thistogram
+
+Compute and draw a color distribution histogram for the input video across 
time.
+
+Unlike @ref{histogram} video filter which only shows histogram of single input 
frame
+at certain time, this filter shows also past histograms of number of frames 
defined
+by @code{width} option.
+
+The computed histogram is a representation of the color component
+distribution in an image.
+
+The filter accepts the following options:
+
+@table @option
+@item width
+Set width of single color component output. Default value is @code{1080}.
+This also set number of passed histograms to keep.
+Allowed range is [50, 8192].
+
+@item display_mode, d
+Set display mode.
+It accepts the following values:
+@table @samp
+@item stack
+Per color component graphs are placed below each other.
+
+@item parade
+Per color component graphs are placed side by side.
+
+@item overlay
+Presents information identical to that in the @code{parade}, except
+that the graphs representing color components are superimposed directly
+over one another.
+@end table
+Default is @code{stack}.
+
+@item levels_mode, m
+Set mode. Can be either @code{linear}, or @code{logarithmic}.
+Default is @code{linear}.
+
+@item components, c
+Set what color components to display.
+Default is @code{7}.
+@end table
+
 @section threshold
 
 Apply threshold effect to video stream.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 37d4eee858..8b8a5bd535 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -401,6 +401,7 @@ OBJS-$(CONFIG_SWAPRECT_FILTER)   += 
vf_swaprect.o
 OBJS-$(CONFIG_SWAPUV_FILTER) += vf_swapuv.o
 OBJS-$(CONFIG_TBLEND_FILTER) += vf_blend.o framesync.o
 OBJS-$(CONFIG_TELECINE_FILTER)   += vf_telecine.o
+OBJS-$(CONFIG_THISTOGRAM_FILTER) += vf_histogram.o
 OBJS-$(CONFIG_THRESHOLD_FILTER)  += vf_threshold.o framesync.o
 OBJS-$(CONFIG_THUMBNAIL_FILTER)  += vf_thumbnail.o
 OBJS-$(CONFIG_THUMBNAIL_CUDA_FILTER) += vf_thumbnail_cuda.o 
vf_thumbnail_cuda.ptx.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index c295f8e403..9f2080f857 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -382,6 +382,7 @@ extern AVFilter ff_vf_swaprect;
 extern AVFilter ff_vf_swapuv;
 extern AVFilter ff_vf_tblend;
 extern AVFilter ff_vf_telecine;
+extern AVFilter ff_vf_thistogram;
 extern AVFilter ff_vf_threshold;
 extern AVFilter ff_vf_thumbnail;
 extern AVFilter ff_vf_thumbnail_cuda;
diff --git a/libavfilter/vf_histogram.c b/libavfilter/vf_histogram.c
index 64ee993a21..83e8925ea7 100644
--- a/libavfilter/vf_histogram.c
+++ b/libavfilter/vf_histogram.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2013 Paul B Mahol
+ * Copyright (c) 2012-2019 Paul B Mahol
  *
  * This file is part of FFmpeg.
  *
@@ -31,8 +31,11 @@
 
 typedef struct HistogramContext {
 const AVClass *class;   ///< AVClass context for log and 
options purpose
+intthistogram;
 unsigned   histogram[256*256];
 inthistogram_size;
+intwidth;
+intx_pos;
 intmult;
 intncomp;
 intdncomp;
@@ -48,25 +51,30 @@ typedef struct HistogramContext {
 float  bgopacity;
 intplanewidth[4];
 intplaneheight[4];
+intstart[4];
+AVFrame   *out;
 } HistogramContext;
 
 #define OFFSET(x) offsetof(HistogramContext, x)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
+#define COMMON_OPTIONS \
+{ "display_mode", "set display mode", OFFSET(display_mode), 
AV_OPT_TYPE_INT, {.i64=2}, 0, 2, FLAGS, "display_mode"}, \
+{ "d","set display mode", OFFSET(display_mode), 
AV_OPT_TYPE_INT, {.i64=2}, 0, 2, FLAGS, "display_mode"}, \
+{ "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, 
"display_mode" }, \
+{ "parade",  NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, 
"display_mode" }, \
+{ "stack",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, 
"display_mode" }, \
+{ "levels_mode", "set levels mode", OFFSET(levels_mode), AV_OPT_TYPE_INT, 
{.i64=0}, 0, 1, FLAGS, "level

[FFmpeg-devel] [PATCH 2/2] avfilter/vf_histogram: reindent after previous commit

2019-12-26 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/vf_histogram.c | 110 ++---
 1 file changed, 55 insertions(+), 55 deletions(-)

diff --git a/libavfilter/vf_histogram.c b/libavfilter/vf_histogram.c
index 83e8925ea7..2381fe980c 100644
--- a/libavfilter/vf_histogram.c
+++ b/libavfilter/vf_histogram.c
@@ -255,8 +255,8 @@ static int config_output(AVFilterLink *outlink)
 outlink->w = s->width * FFMAX(ncomp * (s->display_mode == 1), 1);
 outlink->h = s->histogram_size * FFMAX(ncomp * (s->display_mode == 2), 
1);
 } else {
-outlink->w = s->histogram_size * FFMAX(ncomp * (s->display_mode == 1), 1);
-outlink->h = (s->level_height + s->scale_height) * FFMAX(ncomp * 
(s->display_mode == 2), 1);
+outlink->w = s->histogram_size * FFMAX(ncomp * (s->display_mode == 1), 
1);
+outlink->h = (s->level_height + s->scale_height) * FFMAX(ncomp * 
(s->display_mode == 2), 1);
 }
 
 s->odesc = av_pix_fmt_desc_get(outlink->format);
@@ -275,34 +275,34 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 int i, j, k, l, m;
 
 if (!s->thistogram || !out) {
-out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
-if (!out) {
-av_frame_free(&in);
-return AVERROR(ENOMEM);
-}
-s->out = out;
+out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+if (!out) {
+av_frame_free(&in);
+return AVERROR(ENOMEM);
+}
+s->out = out;
 
-for (k = 0; k < 4 && out->data[k]; k++) {
-const int is_chroma = (k == 1 || k == 2);
-const int dst_h = AV_CEIL_RSHIFT(outlink->h, (is_chroma ? 
s->odesc->log2_chroma_h : 0));
-const int dst_w = AV_CEIL_RSHIFT(outlink->w, (is_chroma ? 
s->odesc->log2_chroma_w : 0));
+for (k = 0; k < 4 && out->data[k]; k++) {
+const int is_chroma = (k == 1 || k == 2);
+const int dst_h = AV_CEIL_RSHIFT(outlink->h, (is_chroma ? 
s->odesc->log2_chroma_h : 0));
+const int dst_w = AV_CEIL_RSHIFT(outlink->w, (is_chroma ? 
s->odesc->log2_chroma_w : 0));
 
-if (s->histogram_size <= 256) {
-for (i = 0; i < dst_h ; i++)
-memset(out->data[s->odesc->comp[k].plane] +
-   i * out->linesize[s->odesc->comp[k].plane],
-   s->bg_color[k], dst_w);
-} else {
-const int mult = s->mult;
+if (s->histogram_size <= 256) {
+for (i = 0; i < dst_h ; i++)
+memset(out->data[s->odesc->comp[k].plane] +
+   i * out->linesize[s->odesc->comp[k].plane],
+   s->bg_color[k], dst_w);
+} else {
+const int mult = s->mult;
 
-for (i = 0; i < dst_h ; i++)
-for (j = 0; j < dst_w; j++)
-AV_WN16(out->data[s->odesc->comp[k].plane] +
-i * out->linesize[s->odesc->comp[k].plane] + j * 2,
-s->bg_color[k] * mult);
+for (i = 0; i < dst_h ; i++)
+for (j = 0; j < dst_w; j++)
+AV_WN16(out->data[s->odesc->comp[k].plane] +
+i * out->linesize[s->odesc->comp[k].plane] + j * 2,
+s->bg_color[k] * mult);
+}
 }
 }
-}
 
 for (m = 0, k = 0; k < s->ncomp; k++) {
 const int p = s->desc->comp[k].plane;
@@ -319,8 +319,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 starty = m * s->histogram_size * (s->display_mode == 2);
 startx = m++ * s->width * (s->display_mode == 1);
 } else {
-startx = m * s->histogram_size * (s->display_mode == 1);
-starty = m++ * (s->level_height + s->scale_height) * (s->display_mode 
== 2);
+startx = m * s->histogram_size * (s->display_mode == 1);
+starty = m++ * (s->level_height + s->scale_height) * 
(s->display_mode == 2);
 }
 
 if (s->histogram_size <= 256) {
@@ -358,41 +358,41 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 }
 }
 } else {
-for (i = 0; i < s->histogram_size; i++) {
-int col_height;
+for (i = 0; i < s->histogram_size; i++) {
+int col_height;
 
-if (s->levels_mode)
-col_height = lrint(s->level_height * (1. - 
(log2(s->histogram[i] + 1) / max_hval_log)));
-else
-col_height = s->level_height - (s->histogram[i] * 
(int64_t)s->level_height + max_hval - 1) / max_hval;
+if (s->levels_mode)
+col_height = lrint(s->level_height * (1. - 
(log2(s->histogram[i] + 1) / max_hval_log)));
+else
+col_height = s->level_height - (s->histogram[i] * 
(int64_t)s->level_height + max_hval - 1) / max_hval;
 
-if (s->histogra

Re: [FFmpeg-devel] [PATCH v2] avutil/mem: Add av_fast_realloc_array()

2019-12-26 Thread Andreas Rheinhardt
On Thu, Dec 26, 2019 at 8:35 PM Nicolas George  wrote:

> Andreas Rheinhardt (12019-12-26):
> > b) It guarantees to not allocated more than UINT_MAX - 1 elements, so
> > the caller needn't check for overflow if the desired size is increased
> > in steps of one.
>
> This is preparing trouble for later,


I don't understand. Do you think that callers will take this as a blank
cheque to not check at all?


> and as Michael pointed, it will not
> work when the number of elements is stored in a signed integer.


My intention was actually to convert the types for every user of this
function when using this function (see e.g. the -Matroska demuxer patch).


> (It was
> a mistake to use a signed integer in the first place, but that
> particular mistake is already all over the place).


I agree.


> I strongly suggest we
> try to make things properly:
>
> - Make nb_allocated and min_nb size_t as they should be.
>

Do we have arrays where there is a need to go beyond the range of ordinary
integers for the number of elements?

>
> - Do not hard-code UINT_MAX-1, make it an argument, max_nb: that way, if
>   the index is an integer, just pass INT_MAX-1, and if it is properly
>   size_t, pass SIZE_MAX-1.
>
> - Since we can't pass a pointer to int as a pointer to size_t, add a
>   small convenience wrapper av_fast_realloc_array_int() just to convert
>   the type of nb_allocated. That's ugly, but I do not see a better
>   solution. Or we can decide we must change the type of the size to
>   size_t whenever we update code to use av_fast_realloc_array().
>

I'd like not to turn the int/unsigned version of av_fast_realloc_array()
into a wrapper until there is a real case where an array is needed that
doesn't fit into an int (or an unsigned). And switching to size_t
everywhere would increase the size of certain structures which I very much
like to avoid (e.g. the size of every MatroskaIndex element would increase
by eight bytes (for 64 bit systems)).

>
> And while we are at it, I would like better:
>
> - Alter ptr the same way nb_allocated is altered, and return a real
>   error code in case of error. Otherwise, the caller has to guess that
>   only AVERROR(ENOMEM) is possible, and we have seen that these
>   assumptions and hard-coded error code have a way of overstaying their
>   welcome.
>

That is certainly possible (if "alter ptr the same way nb_allocated is
altered" means: Via a pointer to a pointer. (The other interpretation (that
the array should be automatically freed on failure and ptr set to NULL)
would have elicited a different response.))

>
> Poor choice of types have caused problems in the past. They will cause
> more problems as the memory of computers, and therefore the task we give
> them, grow. Let us not cultivate them.
>
> Regards,
>
> --
>   Nicolas George
>

Thanks for looking over this.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1 1/2] avcodec/ass: remove the unneeded ()

2019-12-26 Thread Michael Niedermayer
On Thu, Dec 26, 2019 at 09:31:03AM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  libavcodec/ass.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply both patches

thx

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

Many that live deserve death. And some that die deserve life. Can you give
it to them? Then do not be too eager to deal out death in judgement. For
even the very wise cannot see all ends. -- Gandalf


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 01/17] avformat/spdifenc: Replace write_trailer by deinit

2019-12-26 Thread Michael Niedermayer
On Thu, Dec 26, 2019 at 11:53:26AM +0100, Andreas Rheinhardt wrote:
> The write_trailer function doesn't write anything anyway. It only frees
> memory.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/spdifenc.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

will apply

thx

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

If a bugfix only changes things apparently unrelated to the bug with no
further explanation, that is a good sign that the bugfix is wrong.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 02/17] avformat/wavenc: Add deinit function

2019-12-26 Thread Michael Niedermayer
On Thu, Dec 26, 2019 at 11:53:27AM +0100, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/wavenc.c | 5 +
>  1 file changed, 1 insertion(+), 4 deletions(-)

will apply

thx

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

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 02/17] avformat/wavenc: Add deinit function

2019-12-26 Thread James Almer
On 12/26/2019 7:53 AM, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/wavenc.c | 5 +
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c
> index 159119d693..269793d571 100644
> --- a/libavformat/wavenc.c
> +++ b/libavformat/wavenc.c
> @@ -185,7 +185,6 @@ static av_cold int peak_init_writer(AVFormatContext *s)
>  
>  nomem:
>  av_log(s, AV_LOG_ERROR, "Out of memory\n");
> -peak_free_buffers(s);
>  return AVERROR(ENOMEM);
>  }
>  
> @@ -485,9 +484,6 @@ static int wav_write_trailer(AVFormatContext *s)
>  }
>  }
>  
> -if (wav->write_peak)
> -peak_free_buffers(s);
> -
>  return ret;
>  }
>  
> @@ -527,6 +523,7 @@ AVOutputFormat ff_wav_muxer = {
>  .write_header  = wav_write_header,
>  .write_packet  = wav_write_packet,
>  .write_trailer = wav_write_trailer,
> +.deinit= peak_free_buffers,

Could also rename it to wav_deinit() while at it.

>  .flags = AVFMT_TS_NONSTRICT,
>  .codec_tag = (const AVCodecTag* const []){ ff_codec_wav_tags, 0 
> },
>  .priv_class= &wav_muxer_class,
> 

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 09/17] avformat/flvenc: Forward errors from allocating keyframe index

2019-12-26 Thread Michael Niedermayer
On Thu, Dec 26, 2019 at 11:53:34AM +0100, Andreas Rheinhardt wrote:
> While the function adding a new element to the keyframe index checked
> the allocation, the caller didn't check the return value. This has been
> changed. To do so, the return value has been changed to an ordinary ret
> instead of pb->error. This doesn't pose a problem, as write_packet() in
> mux.c already checks for write errors (since 9ad1e0c1).
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
> No change since last time.

will apply

thx

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

Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 10/17] avformat/flvenc: Fix leak of oversized packets

2019-12-26 Thread Michael Niedermayer
On Thu, Dec 26, 2019 at 11:53:35AM +0100, Andreas Rheinhardt wrote:
> Might happen for annex B H.264.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
> No change since last time.

will apply

thx

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

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avcodec/ralf: Fix overflows of biased values

2019-12-26 Thread Michael Niedermayer
Fixes: signed integer overflow: 2003010644 * 2 cannot be represented in type 
'int'
Fixes: 
19593/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RALF_fuzzer-5660628006207488

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/ralf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/ralf.c b/libavcodec/ralf.c
index d8f1803086..5d88b4c943 100644
--- a/libavcodec/ralf.c
+++ b/libavcodec/ralf.c
@@ -60,7 +60,7 @@ typedef struct RALFContext {
 int filter_bits; ///< filter precision for the current channel data
 int32_t filter[64];
 
-int bias[2]; ///< a constant value added to channel data after 
filtering
+unsigned bias[2];///< a constant value added to channel data after 
filtering
 
 int num_blocks;  ///< number of blocks inside the frame
 int sample_offset;
-- 
2.24.0

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avformat/microdvd: Use \n instead of \0 to end file header

2019-12-26 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Andreas Rheinhardt:
>> Up until now, the microdvd demuxer uses av_strdup() to allocate the
>> extradata from a string; its length is set to strlen() + 1, i.e.
>> including the \0 at the end. Upon remuxing, the muxer would simply copy
>> the extradata at the beginning, including the \0.
>>
>> This commit changes this by not adding the \0 to the size of the
>> extradata; the muxer now delimits extradata by inserting a \n. This
>> required to change the subtitles-microdvd-remux FATE-test.
>>
>> Furthermore, the extradata is now allocated with zeroed padding.
>>
>> The microdvd decoder is not affected by this, as it didn't use the size
>> of the extradata at all, but treated it as a C-string.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>  libavformat/microdvddec.c |   9 +
>>  libavformat/microdvdenc.c |   1 +
>>  tests/ref/fate/sub-microdvd-remux | Bin 416 -> 416 bytes
>>  3 files changed, 6 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavformat/microdvddec.c b/libavformat/microdvddec.c
>> index ca9086afe9..08e6fca09c 100644
>> --- a/libavformat/microdvddec.c
>> +++ b/libavformat/microdvddec.c
>> @@ -117,10 +117,11 @@ static int microdvd_read_header(AVFormatContext *s)
>>  continue;
>>  }
>>  if (!st->codecpar->extradata && sscanf(line, "{DEFAULT}{}%c", 
>> &c) == 1) {
>> -st->codecpar->extradata = av_strdup(line + 11);
>> -if (!st->codecpar->extradata)
>> -return AVERROR(ENOMEM);
>> -st->codecpar->extradata_size = 
>> strlen(st->codecpar->extradata) + 1;
>> +int ret, size = strlen(line + 11);
>> +ret = ff_alloc_extradata(st->codecpar, size);
>> +if (ret < 0)
>> +return ret;
>> +memcpy(st->codecpar->extradata, line + 11, size);
>>  continue;
>>  }
>>  }
>> diff --git a/libavformat/microdvdenc.c b/libavformat/microdvdenc.c
>> index 04f475b645..6639651e02 100644
>> --- a/libavformat/microdvdenc.c
>> +++ b/libavformat/microdvdenc.c
>> @@ -36,6 +36,7 @@ static int microdvd_write_header(struct AVFormatContext *s)
>>  if (par->extradata && par->extradata_size > 0) {
>>  avio_write(s->pb, "{DEFAULT}{}", 11);
>>  avio_write(s->pb, par->extradata, par->extradata_size);
>> +avio_w8(s->pb, '\n');
>>  avio_flush(s->pb);
>>  }
>>  
>> diff --git a/tests/ref/fate/sub-microdvd-remux 
>> b/tests/ref/fate/sub-microdvd-remux
>> index 
>> a71da99031fdc4bff13ea7124c046e761a650dc8..92ff233f56b6fec33d4e9e0698ec43377ea5fab7
>>  100644
>> GIT binary patch
>> delta 12
>> TcmZ3$ynuOvE+f}Qy&^^c7%l^0
>>
>> delta 12
>> TcmZ3$ynuOvE+fN6y&^^c7yJWP
>>
> Ping.
> 
> - Andreas
> 
Ping.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".