Re: [FFmpeg-devel] [PATCHv2 1/3] avutil/eval: separate AVExpr state to a new AVExprState struct

2020-01-01 Thread Michael Niedermayer
On Mon, Dec 30, 2019 at 11:23:40PM +0100, Marton Balint wrote:
> Also add helper functions to allocate and free such a struct, and make it
> usable by providing a new av_eval_expr2 function for which you can specify a
> custom AVExprState.
> 
> Signed-off-by: Marton Balint 
> ---
>  doc/APIchanges  |  4 
>  libavutil/eval.c| 36 +---
>  libavutil/eval.h| 41 +
>  libavutil/version.h |  2 +-
>  4 files changed, 71 insertions(+), 12 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 3c24dc6fbc..d0b33bda02 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,10 @@ libavutil: 2017-10-21
>  
>  API changes, most recent first:
>  
> +2020-01-xx - xx - lavu 56.39.100 - eval.h
> +  Add AVExprState struct and av_expr_eval2, av_expr_state_alloc,
> +  av_expr_state_free functions
> +
>  2019-12-27 - xx - lavu 56.38.100 - eval.h
>Add av_expr_count_func().
>  
> diff --git a/libavutil/eval.c b/libavutil/eval.c
> index d527f6a9d0..4619d0fba0 100644
> --- a/libavutil/eval.c
> +++ b/libavutil/eval.c
> @@ -53,7 +53,6 @@ typedef struct Parser {
>  void *opaque;
>  int log_offset;
>  void *log_ctx;
> -#define VARS 10
>  double *var;
>  } Parser;
>  
> @@ -173,7 +172,7 @@ struct AVExpr {
>  double (*func2)(void *, double, double);
>  } a;
>  struct AVExpr *param[3];
> -double *var;
> +AVExprState *state;
>  };
>  
>  static double etime(double v)
> @@ -191,7 +190,7 @@ static double eval_expr(Parser *p, AVExpr *e)
>  case e_func2:  return e->value * e->a.func2(p->opaque, eval_expr(p, 
> e->param[0]), eval_expr(p, e->param[1]));
>  case e_squish: return 1/(1+exp(4*eval_expr(p, e->param[0])));
>  case e_gauss: { double d = eval_expr(p, e->param[0]); return 
> exp(-d*d/2)/sqrt(2*M_PI); }
> -case e_ld: return e->value * p->var[av_clip(eval_expr(p, 
> e->param[0]), 0, VARS-1)];
> +case e_ld: return e->value * p->var[av_clip(eval_expr(p, 
> e->param[0]), 0, AV_EXPR_STATE_NB_VARS-1)];
>  case e_isnan:  return e->value * !!isnan(eval_expr(p, e->param[0]));
>  case e_isinf:  return e->value * !!isinf(eval_expr(p, e->param[0]));
>  case e_floor:  return e->value * floor(eval_expr(p, e->param[0]));
> @@ -230,7 +229,7 @@ static double eval_expr(Parser *p, AVExpr *e)
>  return x;
>  }
>  case e_random:{
> -int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1);
> +int idx= av_clip(eval_expr(p, e->param[0]), 0, 
> AV_EXPR_STATE_NB_VARS-1);
>  uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx];
>  r= r*1664525+1013904223;
>  p->var[idx]= r;
> @@ -245,7 +244,7 @@ static double eval_expr(Parser *p, AVExpr *e)
>  case e_taylor: {
>  double t = 1, d = 0, v;
>  double x = eval_expr(p, e->param[1]);
> -int id = e->param[2] ? av_clip(eval_expr(p, e->param[2]), 0, 
> VARS-1) : 0;
> +int id = e->param[2] ? av_clip(eval_expr(p, e->param[2]), 0, 
> AV_EXPR_STATE_NB_VARS-1) : 0;
>  int i;
>  double var0 = p->var[id];
>  for(i=0; i<1000; i++) {
> @@ -320,7 +319,7 @@ static double eval_expr(Parser *p, AVExpr *e)
>  case e_div: return e->value * ((!CONFIG_FTRAPV || d2 ) ? (d 
> / d2) : d * INFINITY);
>  case e_add: return e->value * (d + d2);
>  case e_last:return e->value * d2;
> -case e_st : return e->value * (p->var[av_clip(d, 0, 
> VARS-1)]= d2);
> +case e_st : return e->value * (p->var[av_clip(d, 0, 
> AV_EXPR_STATE_NB_VARS-1)]= d2);
>  case e_hypot:return e->value * hypot(d, d2);
>  case e_atan2:return e->value * atan2(d, d2);
>  case e_bitand: return isnan(d) || isnan(d2) ? NAN : e->value 
> * ((long int)d & (long int)d2);
> @@ -333,13 +332,23 @@ static double eval_expr(Parser *p, AVExpr *e)
>  
>  static int parse_expr(AVExpr **e, Parser *p);
>  
> +AVExprState *av_expr_state_alloc(void)
> +{
> +return av_mallocz(sizeof(AVExprState));
> +}
> +
> +void av_expr_state_free(AVExprState **ps)
> +{
> +av_freep(ps);
> +}
> +
>  void av_expr_free(AVExpr *e)
>  {
>  if (!e) return;
>  av_expr_free(e->param[0]);
>  av_expr_free(e->param[1]);
>  av_expr_free(e->param[2]);
> -av_freep(&e->var);
> +av_expr_state_free(&e->state);
>  av_freep(&e);
>  }
>  
> @@ -724,8 +733,8 @@ int av_expr_parse(AVExpr **expr, const char *s,
>  ret = AVERROR(EINVAL);
>  goto end;
>  }
> -e->var= av_mallocz(sizeof(double) *VARS);
> -if (!e->var) {
> +e->state = av_expr_state_alloc();
> +if (!e->state) {
>  ret = AVERROR(ENOMEM);
>  goto end;
>  }
> @@ -763,16 +772,21 @@ int av_expr_count_func(AVExpr *e, unsigned *counter, 
> int size, int

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

2020-01-01 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 
---
 libavformat/flvenc.c | 58 ++--
 1 file changed, 18 insertions(+), 40 deletions(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 1aaf0333ca..74f4e499f6 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,17 @@ 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");
-return AVERROR(ENOMEM);
-}
-
-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;
+int ret = av_fast_realloc_array(&flv->filepositions,
+&flv->filepositions_allocated,
+flv->filepositions_count + 1,
+UINT_MAX - 1,
+sizeof(*flv->filepositions));
+if (ret < 0) {
+av_log(s, AV_LOG_WARNING, "Adding entry to keyframe index failed.\n");
+return ret;
 }
 
-flv->filepositions_count++;
+flv->filepositions[flv->filepositions_count++] = (FLVFileposition){ pos, 
ts };
 
 return 0;
 }
@@ -586,7 +575,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 +773,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 +798,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_amf_string(pb, "");
 avio_w8(pb, A

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

2020-01-01 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 allows to limit the number of elements to an upper bound given
by the caller. This allows to restrict the number of allocated elements
to fit into an int and therefore makes this function usable with
counters of this type. It can also be used to avoid overflow checks in
the caller: E.g. setting it to UINT_MAX - 1 elements makes it safe to
increase the desired number of elements in steps of one. And it avoids
overallocations in situations where one already has an upper bound.
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.
e) By returning an int, av_fast_realloc_array() can distinguish between
ordinary allocation failures (meriting AVERROR(ENOMEM)) and failures
because of allocation limits (by returning AVERROR(ERANGE)).
f) It is no longer possible for the user to accidentally lose the
pointer by using ptr = av_fast_realloc(ptr, ...).

Because of f) there is no need to set the number of allocated elements
to zero on failure.

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 
---
Switched to returning an int and added the max_nb parameter. What has
not been done is switching to size_t. This function can still be turned
into a wrapper for a size_t function if the need for such a function
arises.

Furthermore, I have found that several reallocation functions don't
abide by their documented behaviour: "If `size` is zero, free the memory
block pointed to by `ptr`." says the documentation of av_realloc,
av_reallocp, av_realloc_f (implicitly); av_realloc_array and
av_reallocp_array claim to free the memory block in case the number of
elements to allocate is zero.

Yet realloc allocates size + !size bytes. av_realloc_f (calling
av_realloc) does also not free its array in case zero elements should be
allocated (or if the size of an element is zero). av_reallocp does what
its documentation says; av_realloc_array (relying on av_realloc) and
av_reallocp_array (relying on av_realloc_f) don't.

Changing the behaviour of av_realloc to match its documentation leads to
lots of failing FATE-tests, so I suggest updating the documentation to
match actual behaviour.

Finally, there is no check in av_max_alloc that the new max is actually
bigger than 32; this is a problem given that max_alloc_size - 32 is the
real limit. Maybe the 32 should simply be dropped (and the default value
be set to INT_MAX - 32 if it is deemed important)? (And why 32? I would
have expected AV_INPUT_BUFFER_PADDING_SIZE or so.)

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

diff --git a/doc/APIchanges b/doc/APIchanges
index 3c24dc6fbc..7feca58e98 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2020-01-01 - xx - lavu 56.39.100 - mem.h
+  Add av_fast_realloc_array().
+
 2019-12-27 - xx - lavu 56.38.100 - eval.h
   Add av_expr_count_func().
 
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 88fe09b179..56c82fcee7 100644
-

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

2020-01-01 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 
---
This patch will lead to a merge conflict with my recent Matroska muxer
patchset [1] (in particular, [2]), but it is trivially fixable. I will
update the other patchset as soon as one gets applied.

[1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-January/255139.html
[2]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-January/255151.html

 libavformat/matroskaenc.c | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 469b604de6..2f5f8873db 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
@@ -535,15 +536,16 @@ static mkv_cues *mkv_start_cues(int64_t segment_offset)
 static int mkv_add_cuepoint(mkv_cues *cues, int stream, int tracknum, int64_t 
ts,
 int64_t cluster_pos, int64_t relative_pos, int64_t 
duration)
 {
-mkv_cuepoint *entries = cues->entries;
+int ret;
 
 if (ts < 0)
 return 0;
 
-entries = av_realloc_array(entries, cues->num_entries + 1, 
sizeof(mkv_cuepoint));
-if (!entries)
-return AVERROR(ENOMEM);
-cues->entries = entries;
+ret = av_fast_realloc_array(&cues->entries, &cues->allocated_entries,
+cues->num_entries + 1, UINT_MAX - 1,
+sizeof(*cues->entries));
+if (ret < 0)
+return ret;
 
 cues->entries[cues->num_entries].pts   = ts;
 cues->entries[cues->num_entries].stream_idx= stream;
@@ -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 v2 16/17] avformat/matroskadec: Use av_fast_realloc_array()

2020-01-01 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 | 59 +++
 1 file changed, 28 insertions(+), 31 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 75f72d330c..2295bafd22 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,16 +1226,12 @@ static int ebml_parse(MatroskaDemuxContext *matroska,
 data = (char *) data + syntax->data_offset;
 if (syntax->list_elem_size) {
 EbmlList *list = data;
-void *newelem;
+res = av_fast_realloc_array(&list->elem, &list->nb_allocated,
+list->nb_elem + 1, UINT_MAX - 1,
+syntax->list_elem_size);
+if (res < 0)
+return res;
 
-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);
-if (!newelem)
-return AVERROR(ENOMEM);
-list->elem = newelem;
 data = (char *) list->elem + list->nb_elem * 
syntax->list_elem_size;
 memset(data, 0, syntax->list_elem_size);
 list->nb_elem++;
@@ -1464,7 +1460,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 +1476,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 +1544,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)
@@ -1703,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 &&
@@ -1737,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) {
@@ -1753,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);
 }
@@ -1770,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);
 }
@@ -1787,7 +1783,7 @@ static void matroska_convert_tags(AVFormatContext *s)
 }
 if (!found) {
   

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

2020-01-01 Thread Nicolas George
Andreas Rheinhardt (12020-01-01):
> What has
> not been done is switching to size_t. This function can still be turned
> into a wrapper for a size_t function if the need for such a function
> arises.

I do not agree with that. size_t is the correct type for that use, and
therefore should be the choice for all new code. I remember trouble
about that, let us not make some more.

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 v2 12/17] avformat/flvenc: Use array instead of linked list for index

2020-01-01 Thread Carl Eugen Hoyos
Am Mi., 1. Jan. 2020 um 14:28 Uhr schrieb 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.

Does this change performance?

Carl Eugen
___
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 5/7] avformat/matroskadec: Use AV_DICT_DONT_STRDUP_VAL to save av_strdup

2020-01-01 Thread Michael Niedermayer
On Sun, Nov 10, 2019 at 05:07:31AM +0100, Andreas Rheinhardt wrote:
> This will likely also fix CID 1452562, a false positive resulting from
> Coverity thinking that av_dict_set() automatically frees its key and
> value parameters (even without the AV_DICT_DONT_STRDUP_* flags).
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/matroskadec.c | 12 ++--
>  1 file changed, 6 insertions(+), 6 deletions(-)

will apply

thx

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

There will always be a question for which you do not know the correct answer.


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] configure: bump year

2020-01-01 Thread Michael Niedermayer
On Wed, Jan 01, 2020 at 03:25:17PM +0800, myp...@gmail.com wrote:
> On Wed, Jan 1, 2020 at 2:46 PM Gyan Doshi  wrote:
> >
> > ---
> >  configure | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/configure b/configure
> > index 43dc409fe6..965b4c71b8 100755
> > --- a/configure
> > +++ b/configure
> > @@ -7456,7 +7456,7 @@ cat > $TMPH < >  #define FFMPEG_CONFIG_H
> >  #define FFMPEG_CONFIGURATION "$(c_escape $FFMPEG_CONFIGURATION)"
> >  #define FFMPEG_LICENSE "$(c_escape $license)"
> > -#define CONFIG_THIS_YEAR 2019
> > +#define CONFIG_THIS_YEAR 2020
> >  #define FFMPEG_DATADIR "$(eval c_escape $datadir)"
> >  #define AVCONV_DATADIR "$(eval c_escape $datadir)"
> >  #define CC_IDENT "$(c_escape ${cc_ident:-Unknown compiler})"
> > --
> > 2.24.1
> >
> Ha, new year, LGTM

will apply

thx

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

The smallest minority on earth is the individual. Those who deny 
individual rights cannot claim to be defenders of minorities. - Ayn Rand


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 05/20] avformat/matroskaenc: Check return value of ff_isom_write_hvcc()

2020-01-01 Thread Michael Niedermayer
On Wed, Jan 01, 2020 at 12:42:51PM +0800, myp...@gmail.com wrote:
> On Wed, Jan 1, 2020 at 8:59 AM Andreas Rheinhardt
>  wrote:
> >
> > The Matroska muxer currently does not check the return value of
> > ff_isom_write_hvcc(), the function used to write mp4-style
> > HEVC-extradata as Matroska also uses it. This was intentionally done in
> > 7a5356c72 to allow remuxing from mpeg-ts.
> >
> > But if ff_isom_write_hvcc() fails, it has not output anything and the
> > file ends up without CodecPrivate and, if the input was Annex B, with
> > Annex B data, which is against the spec. So check the return value
> > again.
> >
> > The underlying issue of not having extradata seems to have been fixed by
> > the introduction of the extract_extradata bitstream filter.
> >
> > Signed-off-by: Andreas Rheinhardt 
> > ---
> >  libavformat/matroskaenc.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> > index 76c38b8d09..8cea829b31 100644
> > --- a/libavformat/matroskaenc.c
> > +++ b/libavformat/matroskaenc.c
> > @@ -748,9 +748,8 @@ static int 
> > mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext *pb,
> >  return ff_isom_write_avcc(dyn_cp, par->extradata,
> >par->extradata_size);
> >  case AV_CODEC_ID_HEVC:
> > -ff_isom_write_hvcc(dyn_cp, par->extradata,
> > -   par->extradata_size, 0);
> > -return 0;
> > +return ff_isom_write_hvcc(dyn_cp, par->extradata,
> > +  par->extradata_size, 0);
> >  case AV_CODEC_ID_AV1:
> >  if (par->extradata_size)
> >  return ff_isom_write_av1c(dyn_cp, par->extradata,
> > --
> > 2.20.1
> LGTM

will apply

thx

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

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway


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 04/20] avformat/matroskaenc: Adapt documentation of put_ebml_num

2020-01-01 Thread Michael Niedermayer
On Wed, Jan 01, 2020 at 01:58:21AM +0100, Andreas Rheinhardt wrote:
> to its actual behaviour: That it uses the least amount of bytes unless
> overridden.
> 
> The current documentation leaves it undefined how many bytes will be used
> when no number to use has been given explicitly. But several estimates
> (used to write EBML Master elements with a small length field) require
> this number to be the least amount of bytes to work. Therefore change
> the documentation; and remove a comment about writing length fields
> indicating "unkown length". It has been outdated since 0580a122.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/matroskaenc.c | 7 +++
>  1 file changed, 3 insertions(+), 4 deletions(-)

will apply

thx

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

In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope


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] configure: bump year

2020-01-01 Thread Gyan



On 01-01-2020 09:00 pm, Michael Niedermayer wrote:

On Wed, Jan 01, 2020 at 03:25:17PM +0800, myp...@gmail.com wrote:

On Wed, Jan 1, 2020 at 2:46 PM Gyan Doshi  wrote:

---
  configure | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 43dc409fe6..965b4c71b8 100755
--- a/configure
+++ b/configure
@@ -7456,7 +7456,7 @@ cat > $TMPH <
Ha, new year, LGTM

will apply


Already pushed.

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] Adding a flag to give user the option to have ffmpeg fail instead of warn when mismatches are found in rtmp url stream or application names.

2020-01-01 Thread Michael Niedermayer
On Wed, Sep 25, 2019 at 11:57:08AM -0700, William Martin wrote:
> From: Will Martin 
> 
> Motivation: When running multiple rtmp ingest on the same machine on the same 
> port, users may want to explicitly forbid mismatched rtmp streams from 
> successfully completing handshakes. This patch allows for such enforcement
> Signed-off-by: Will Martin 
> ---
>  libavformat/librtmp.c   |  2 ++
>  libavformat/rtmpproto.c | 24 
>  2 files changed, 22 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/librtmp.c b/libavformat/librtmp.c
> index 43013e46e0..00b49666fd 100644
> --- a/libavformat/librtmp.c
> +++ b/libavformat/librtmp.c
> @@ -52,6 +52,7 @@ typedef struct LibRTMPContext {
>  int live;
>  char *temp_filename;
>  int buffer_size;
> +bool strict_paths;
>  } LibRTMPContext;
>  
>  static void rtmp_log(int level, const char *fmt, va_list args)
> @@ -333,6 +334,7 @@ static const AVOption options[] = {
>  {"rtmp_swfurl", "URL of the SWF player. By default no value will be 
> sent", OFFSET(swfurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
>  {"rtmp_swfverify", "URL to player swf file, compute hash/size 
> automatically. (unimplemented)", OFFSET(swfverify), AV_OPT_TYPE_STRING, {.str 
> = NULL }, 0, 0, DEC},
>  {"rtmp_tcurl", "URL of the target stream. Defaults to 
> proto://host[:port]/app.", OFFSET(tcurl), AV_OPT_TYPE_STRING, {.str = NULL }, 
> 0, 0, DEC|ENC},
> +{"rtmp_strict_paths", "Error instead of warn for mismatch on stream or 
> application path in url", OFFSET(strict_paths), AV_OPT_TYPE_BOOL, {.i64 = 0 
> }, 0, 1, DEC},
>  #if CONFIG_NETWORK
>  {"rtmp_buffer_size", "set buffer size in bytes", OFFSET(buffer_size), 
> AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, DEC|ENC },
>  #endif
> diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
> index b741e421af..dded3b6028 100644
> --- a/libavformat/rtmpproto.c
> +++ b/libavformat/rtmpproto.c
> @@ -129,6 +129,7 @@ typedef struct RTMPContext {
>  char  auth_params[500];
>  int   do_reconnect;
>  int   auth_tried;
> +int   strict_paths;   ///< If true, enforce strict 
> string matching on rtmp stream and application
>  } RTMPContext;
>  
>  #define PLAYER_KEY_OPEN_PART_LEN 30   ///< length of partial key used for 
> first client digest signing
> @@ -477,9 +478,16 @@ static int read_connect(URLContext *s, RTMPContext *rt)
>   "app", tmpstr, sizeof(tmpstr));
>  if (ret)
>  av_log(s, AV_LOG_WARNING, "App field not found in connect\n");
> -if (!ret && strcmp(tmpstr, rt->app))
> -av_log(s, AV_LOG_WARNING, "App field don't match up: %s <-> %s\n",
> +if (!ret && strcmp(tmpstr, rt->app)) {
> +if (rt->strict_paths) {
> +av_log(s, AV_LOG_ERROR, "App field don't match up: %s <-> %s. "
> +   "Exiting since rtmp_strict_paths provided\n", tmpstr, 
> rt->app);
> +return AVERROR(EIO);
> +} else {
> +av_log(s, AV_LOG_WARNING, "App field don't match up: %s <-> 
> %s\n",
> tmpstr, rt->app);
> +}
> +}
>  ff_rtmp_packet_destroy(&pkt);
>  
>  // Send Window Acknowledgement Size (as defined in specification)
> @@ -1946,9 +1954,16 @@ static int send_invoke_response(URLContext *s, 
> RTMPPacket *pkt)
>  pchar = s->filename;
>  }
>  pchar++;
> -if (strcmp(pchar, filename))
> -av_log(s, AV_LOG_WARNING, "Unexpected stream %s, expecting"
> +if (strcmp(pchar, filename)) {
> +if (rt->strict_paths) {
> +av_log(s, AV_LOG_ERROR, "Unexpected stream %s, expecting 
> %s. "
> +"Exiting since rtmp_strict_paths provided.\n", 
> filename, pchar);
> +return AVERROR(EIO);
> +} else {
> +av_log(s, AV_LOG_WARNING, "Unexpected stream %s, 
> expecting"
> " %s\n", filename, pchar);
> +}
> +}
>  }
>  rt->state = STATE_RECEIVING;
>  }
> @@ -3112,6 +3127,7 @@ static const AVOption rtmp_options[] = {
>  {"rtmp_listen", "Listen for incoming rtmp connections", OFFSET(listen), 
> AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC, "rtmp_listen" },
>  {"listen",  "Listen for incoming rtmp connections", OFFSET(listen), 
> AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC, "rtmp_listen" },
>  {"timeout", "Maximum timeout (in seconds) to wait for incoming 
> connections. -1 is infinite. Implies -rtmp_listen 1",  
> OFFSET(listen_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC, 
> "rtmp_listen" },
> +{"rtmp_strict_paths", "Error instead of warn for mismatch on stream or 
> application path in url", OFFSET(strict_paths), AV_OPT_TYPE_BOOL, {.i64 = 0 
> }, 0, 1, DEC},
>  { NULL },
>  };

These should be also documented in d

Re: [FFmpeg-devel] [PATCH 2/4] avformat/mpeg: Remove secondary packet for reading VobSub

2020-01-01 Thread Michael Niedermayer
On Tue, Oct 08, 2019 at 07:41:14AM +0200, Andreas Rheinhardt wrote:
> When vobsub_read_packet() reads a packet, it uses a dedicated AVPacket
> to get the subtitle timing and position from an FFDemuxSubtitlesQueue
> (which has been filled with this data during reading the idx file in
> vobsub_read_header); afterwards the actual subtitle data is read into
> the packet destined for output and the timing and position are copied
> to this packet. Afterwards, the local packet is unreferenced.
> 
> This can be simplified: Simply use the output packet to get the timing
> and position from the FFDemuxSubtitlesQueue. The packet's size will be
> zero afterwards, so that it can be directly used to read the actual
> subtitle data. This makes copying the packet fields as well as
> unreferencing the local packet unecessary and also removes an instance
> of usage of sizeof(AVPacket) in libavformat.
> 
> The only difference is that the returned packet will already be flagged
> as a keyframe. This currently only happens in compute_pkt_fields().
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/mpeg.c | 23 +++
>  1 file changed, 7 insertions(+), 16 deletions(-)

will apply

thx

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

Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- 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] compat/avisynth: Fix unicode compilation.

2020-01-01 Thread Michael Niedermayer
On Mon, Dec 30, 2019 at 10:16:44PM -0500, Stephen Hutchinson wrote:
> On 12/30/2019 11:11 AM, Matt Oliver wrote:
> >---
> >  compat/avisynth/avisynth_c.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/compat/avisynth/avisynth_c.h b/compat/avisynth/avisynth_c.h
> >index 8d17125adc..9ff9321552 100644
> >--- a/compat/avisynth/avisynth_c.h
> >+++ b/compat/avisynth/avisynth_c.h
> >@@ -1096,7 +1096,7 @@ AVSC_INLINE AVS_Library * avs_load_library() {
> >AVS_Library *library = (AVS_Library *)malloc(sizeof(AVS_Library));
> >if (library == NULL)
> >  return NULL;
> >-  library->handle = LoadLibrary("avisynth");
> >+  library->handle = LoadLibraryA("avisynth");
> >if (library->handle == NULL)
> >  goto fail;
> >
> >--
> 
> LGTM.  

will apply

thx


> How are you compiling FFmpeg as unicode in order to expose the issue,
> though?

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

Avoid a single point of failure, be that a person or equipment.


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] [PATCHv2 1/3] avutil/eval: separate AVExpr state to a new AVExprState struct

2020-01-01 Thread Marton Balint



On Wed, 1 Jan 2020, Michael Niedermayer wrote:


On Mon, Dec 30, 2019 at 11:23:40PM +0100, Marton Balint wrote:

Also add helper functions to allocate and free such a struct, and make it
usable by providing a new av_eval_expr2 function for which you can specify a
custom AVExprState.

Signed-off-by: Marton Balint 
---
 doc/APIchanges  |  4 
 libavutil/eval.c| 36 +---
 libavutil/eval.h| 41 +
 libavutil/version.h |  2 +-
 4 files changed, 71 insertions(+), 12 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 3c24dc6fbc..d0b33bda02 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,10 @@ libavutil: 2017-10-21

 API changes, most recent first:

+2020-01-xx - xx - lavu 56.39.100 - eval.h
+  Add AVExprState struct and av_expr_eval2, av_expr_state_alloc,
+  av_expr_state_free functions
+
 2019-12-27 - xx - lavu 56.38.100 - eval.h
   Add av_expr_count_func().

diff --git a/libavutil/eval.c b/libavutil/eval.c
index d527f6a9d0..4619d0fba0 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -53,7 +53,6 @@ typedef struct Parser {
 void *opaque;
 int log_offset;
 void *log_ctx;
-#define VARS 10
 double *var;
 } Parser;

@@ -173,7 +172,7 @@ struct AVExpr {
 double (*func2)(void *, double, double);
 } a;
 struct AVExpr *param[3];
-double *var;
+AVExprState *state;
 };

 static double etime(double v)
@@ -191,7 +190,7 @@ static double eval_expr(Parser *p, AVExpr *e)
 case e_func2:  return e->value * e->a.func2(p->opaque, eval_expr(p, 
e->param[0]), eval_expr(p, e->param[1]));
 case e_squish: return 1/(1+exp(4*eval_expr(p, e->param[0])));
 case e_gauss: { double d = eval_expr(p, e->param[0]); return 
exp(-d*d/2)/sqrt(2*M_PI); }
-case e_ld: return e->value * p->var[av_clip(eval_expr(p, 
e->param[0]), 0, VARS-1)];
+case e_ld: return e->value * p->var[av_clip(eval_expr(p, 
e->param[0]), 0, AV_EXPR_STATE_NB_VARS-1)];
 case e_isnan:  return e->value * !!isnan(eval_expr(p, e->param[0]));
 case e_isinf:  return e->value * !!isinf(eval_expr(p, e->param[0]));
 case e_floor:  return e->value * floor(eval_expr(p, e->param[0]));
@@ -230,7 +229,7 @@ static double eval_expr(Parser *p, AVExpr *e)
 return x;
 }
 case e_random:{
-int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1);
+int idx= av_clip(eval_expr(p, e->param[0]), 0, 
AV_EXPR_STATE_NB_VARS-1);
 uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx];
 r= r*1664525+1013904223;
 p->var[idx]= r;
@@ -245,7 +244,7 @@ static double eval_expr(Parser *p, AVExpr *e)
 case e_taylor: {
 double t = 1, d = 0, v;
 double x = eval_expr(p, e->param[1]);
-int id = e->param[2] ? av_clip(eval_expr(p, e->param[2]), 0, 
VARS-1) : 0;
+int id = e->param[2] ? av_clip(eval_expr(p, e->param[2]), 0, 
AV_EXPR_STATE_NB_VARS-1) : 0;
 int i;
 double var0 = p->var[id];
 for(i=0; i<1000; i++) {
@@ -320,7 +319,7 @@ static double eval_expr(Parser *p, AVExpr *e)
 case e_div: return e->value * ((!CONFIG_FTRAPV || d2 ) ? (d / 
d2) : d * INFINITY);
 case e_add: return e->value * (d + d2);
 case e_last:return e->value * d2;
-case e_st : return e->value * (p->var[av_clip(d, 0, VARS-1)]= 
d2);
+case e_st : return e->value * (p->var[av_clip(d, 0, 
AV_EXPR_STATE_NB_VARS-1)]= d2);
 case e_hypot:return e->value * hypot(d, d2);
 case e_atan2:return e->value * atan2(d, d2);
 case e_bitand: return isnan(d) || isnan(d2) ? NAN : e->value * 
((long int)d & (long int)d2);
@@ -333,13 +332,23 @@ static double eval_expr(Parser *p, AVExpr *e)

 static int parse_expr(AVExpr **e, Parser *p);

+AVExprState *av_expr_state_alloc(void)
+{
+return av_mallocz(sizeof(AVExprState));
+}
+
+void av_expr_state_free(AVExprState **ps)
+{
+av_freep(ps);
+}
+
 void av_expr_free(AVExpr *e)
 {
 if (!e) return;
 av_expr_free(e->param[0]);
 av_expr_free(e->param[1]);
 av_expr_free(e->param[2]);
-av_freep(&e->var);
+av_expr_state_free(&e->state);
 av_freep(&e);
 }

@@ -724,8 +733,8 @@ int av_expr_parse(AVExpr **expr, const char *s,
 ret = AVERROR(EINVAL);
 goto end;
 }
-e->var= av_mallocz(sizeof(double) *VARS);
-if (!e->var) {
+e->state = av_expr_state_alloc();
+if (!e->state) {
 ret = AVERROR(ENOMEM);
 goto end;
 }
@@ -763,16 +772,21 @@ int av_expr_count_func(AVExpr *e, unsigned *counter, int 
size, int arg)
 return expr_count(e, counter, size, ((int[]){e_const, e_func1, 
e_func2})[arg]);
 }

-double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
+double av_expr_eval2(AVExpr *e, AVExprState *s, co

Re: [FFmpeg-devel] [PATCH V1 02/12] lavc/libkvazaar: fix memory leak after av_dict_parse_string fail

2020-01-01 Thread Marton Balint



On Wed, 1 Jan 2020, James Almer wrote:


On 1/1/2020 2:20 AM, Jun Zhao wrote:

From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 libavcodec/libkvazaar.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index a89ca7f..02bcae3 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -110,8 +110,8 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
entry->key, entry->value);
 }
 }
-av_dict_free(&dict);
 }
+av_dict_free(&dict);
 }

 ctx->encoder = enc = api->encoder_open(cfg);


There's a patchset by Marton Balint changing this code in all the same
modules as in this patchset, by replacing it all with a simple
av_dict_copy() call.

http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2019-December/254805.html
and every following patch.


Yeah, although not every patch is covered, because libkvazaar for example 
uses comma(,) separator instead of colon(:) spearator, so it could not be 
converted to a simple AV_OPT_TYPE_DICT.


Probably I should apply my pending patches and then you should rebase this 
series and keep the ones which are still relevant.


Thanks,
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] avformat/image2: Upon request, make available extra metadata, fields related to input path to be used by filters.

2020-01-01 Thread Alexandre Heitor Schmidt

The patch follows attached, to avoid formatting issues. The
commit message is as follows:

avformat/image2: Upon request, make available extra metadata
 fields related to input path to be used by filters.

libavformat/img2.h: New field export_path_metadata to
VideoDemuxData to only allow the use of the extra metadata
upon explicit user request, for security reasons.

libavformat/img2dec.c: Modify image2 demuxer to make available
two special metadata entries called lavf.image2dec.source_path
and lavf.image2dec.source_basename, which represents, respectively,
the complete path to the source image for the current frame and
the basename i.e. the file name related to the current frame.
These can then be used by filters like drawtext and others. The
metadata fields will only be available when explicitly enabled
with image2 option -export_path_metadata 1.

doc/demuxers.texi: Documented the new metadata fields available
for image2 and how to use them.

doc/filters.texi: Added an example on how to use the new metadata
fields with drawtext filter, in order to plot the input file path
to each output frame.

Usage example:

ffmpeg -f image2 -export_path_metadata 1 -pattern_type glob
 -framerate 18 -i '/path/to/input/files/*.jpg'
 -filter_complex drawtext="fontsize=40:fontcolor=white:
 fontfile=FreeSans.ttf:borderw=2:bordercolor=black:
 text='%{metadata\:lavf.image2dec.source_basename\:NA}':x=5:y=50"
 output.avi

Fixes #2874.

Signed-off-by: Alexandre Heitor Schmidt 

>From 6294e556c63b99f9b58494fb8013e9c616444ab0 Mon Sep 17 00:00:00 2001
From: Alexandre Heitor Schmidt 
Date: Wed, 1 Jan 2020 16:57:02 +
Subject: [PATCH] avformat/image2: Upon request, make available extra metadata
 fields related to input path to be used by filters.

libavformat/img2.h: New field export_path_metadata to
VideoDemuxData to only allow the use of the extra metadata
upon explicit user request, for security reasons.

libavformat/img2dec.c: Modify image2 demuxer to make available
two special metadata entries called lavf.image2dec.source_path
and lavf.image2dec.source_basename, which represents, respectively,
the complete path to the source image for the current frame and
the basename i.e. the file name related to the current frame.
These can then be used by filters like drawtext and others. The
metadata fields will only be available when explicitly enabled
with image2 option -export_path_metadata 1.

doc/demuxers.texi: Documented the new metadata fields available
for image2 and how to use them.

doc/filters.texi: Added an example on how to use the new metadata
fields with drawtext filter, in order to plot the input file path
to each output frame.

Usage example:

ffmpeg -f image2 -export_path_metadata 1 -pattern_type glob
 -framerate 18 -i '/path/to/input/files/*.jpg'
 -filter_complex drawtext="fontsize=40:fontcolor=white:
 fontfile=FreeSans.ttf:borderw=2:bordercolor=black:
 text='%{metadata\:lavf.image2dec.source_basename\:NA}':x=5:y=50"
 output.avi

Fixes #2874.

Signed-off-by: Alexandre Heitor Schmidt 
---
 doc/demuxers.texi | 11 +++
 doc/filters.texi  |  9 +
 libavformat/img2.h|  1 +
 libavformat/img2dec.c | 38 ++
 4 files changed, 59 insertions(+)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 0d13bdd1b3..2de14b68d3 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -456,6 +456,17 @@ nanosecond precision.
 @item video_size
 Set the video size of the images to read. If not specified the video
 size is guessed from the first image file in the sequence.
+@item export_path_metadata
+If set to 1, will add two extra fields to the metadata found in input, making them
+also available for other filters (see @var{drawtext} filter for examples). Default
+value is 0. The extra fields are described below:
+@table @option
+@item lavf.image2dec.source_path
+Corresponds to the full path to the input file being read.
+@item lavf.image2dec.source_basename
+Corresponds to the name of the file being read.
+@end table
+
 @end table
 
 @subsection Examples
diff --git a/doc/filters.texi b/doc/filters.texi
index ba00989987..85b55be1bb 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -9888,6 +9888,15 @@ drawtext=fontfile=FreeSans.ttf:text=DOG:fontsize=24:x=10:y=20+24-max_glyph_a,
 drawtext=fontfile=FreeSans.ttf:text=cow:fontsize=24:x=80:y=20+24-max_glyph_a
 @end example
 
+@item
+Plot special @var{lavf.image2dec.source_basename} metadata onto each frame if
+such metadata exists. Otherwise, plot the string "NA". Note that image2 demuxer
+must have option @option{-export_path_metadata 1} for the special metadata fields
+to be available for filters.
+@example
+drawtext="fontsize=20:fontcolor=white:fontfile=FreeSans.ttf:text='%@{metadata\:lavf.image2dec.source_basename\:NA@}':x=10:y=10"
+@end example
+
 @end itemize
 
 For more information about libfreetype, check:
diff --git a/libavformat/img2.h b/libavformat/img2.h
index 0e5b374a6b..5fd8ff77fc 100644
--- a/libavformat/img2.

Re: [FFmpeg-devel] [PATCHv2 8/8] avformat/img2enc: add support for specifying protocol options

2020-01-01 Thread Marton Balint



On Tue, 31 Dec 2019, Michael Niedermayer wrote:


On Tue, Dec 31, 2019 at 12:37:02PM +0100, Nicolas George wrote:

Marton Balint (12019-12-28):

v2: simplified example

Signed-off-by: Marton Balint 
---
 doc/muxers.texi   | 11 +++
 libavformat/img2enc.c | 13 -
 2 files changed, 23 insertions(+), 1 deletion(-)


image2 is not the only demuxer that opens new streams. I think a generic
solution would be preferable.


i also had a slightly ungood feeling about the patch but didnt
had time to think more about it. a more generic solution like with
child AVClasses or something would be interresting but as said i didnt
had time to think about this ...


It looks like a big can of worms.

In the AVFMT_NOFILE case there is no IO context, so options can only be 
passed using avformat_write_header/avformat_init_output.


There is no way to determine which options the protocols will use 
without actually opening an IO context (protocol options are passed to the 
url_open method of each protocol), so we have to store all remaining 
options passed to avformat_write_header/avformat_init_output for possible 
nested IO use.


In the normal case (non AVFMT_NOFILE) muxers can use nested contexts too, 
so avio_open should also store the original options, all of them, because 
the nested contexts might use different protocols. This alone is 
problematic, because avio_open should return the unrecognized options...


Also it might make sense to specify different IO options for nested 
contexts than main contexts (or different options for some of the nested 
contexts)


IMHO being able to specify the nested options separately is a 
clean solution, admittedly less user friendly, but I don't see how this 
can work automagically without some major redesign.


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".

Re: [FFmpeg-devel] [PATCH v3 1/5] avutil: add AV_FRAME_DATA_USER_DATA_UNREGISTERED side data type

2020-01-01 Thread Moritz Barsnick
On Thu, Dec 19, 2019 at 13:09:03 +0800, lance.lmw...@gmail.com wrote:
> +2019-12-17 - xx - lavu 56.37.101 - frame.h
[...]
>  #define LIBAVUTIL_VERSION_MAJOR  56
> -#define LIBAVUTIL_VERSION_MINOR  36
> +#define LIBAVUTIL_VERSION_MINOR  37
>  #define LIBAVUTIL_VERSION_MICRO 101

When bumping major, you need to reset minor to 100.

Moritz
___
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

2020-01-01 Thread Marton Balint



On Fri, 27 Dec 2019, Marton Balint wrote:




On Thu, 26 Dec 2019, Michael Niedermayer wrote:


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, applied patches 1-3. Will wait a few days more for the rest.


Applied the rest.

Regard,
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".

Re: [FFmpeg-devel] [PATCH v1] avfilter: add overlay vaapi filter

2020-01-01 Thread Moritz Barsnick
On Fri, Dec 20, 2019 at 10:55:39 +0800, Xinpeng Sun wrote:
> +Set blocking detection thresholds. Allowed range is 0.0 to 1.0, it
> +need input video has alpha channel.

Incorrect grammar. I suggest ", it requires an input video with alpha
channel".

> +ret = ff_formats_ref(ff_make_format_list(main_in_fmts), 
> &ctx->inputs[MAIN]->out_formats);
> +if (ret < 0)
> +  return ret;
> +
> +ret = ff_formats_ref(ff_make_format_list(main_in_fmts), 
> &ctx->inputs[OVERLAY]->out_formats);
> +if (ret < 0)
> +  return ret;

Incorrect indentation (twice).

> +if (!support_flag) {
> +  av_log(avctx, AV_LOG_ERROR, "VAAPI driver doesn't support global alpha 
> blending\n");
> +return AVERROR(EINVAL);

Incorrect indentation.

Moritz
___
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 3/3] avfilter/vf_convolution: Add X86 SIMD optimizations for filter_column()

2020-01-01 Thread Moritz Barsnick
On Sun, Dec 22, 2019 at 16:37:03 +0800, xuju...@sjtu.edu.cn wrote:
> +if (s->mode[i] == MATRIX_COLUMN) {
> +if (EXTERNAL_SSE4(cpu_flags))
> +s->filter[i] = ff_filter_column_sse4;
> +}

Incorrect indentation.

Moritz
___
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] avdevice/xcbgrab: move some initialization code from pixfmt_from_pixmap_format to create_stream

2020-01-01 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavdevice/xcbgrab.c | 24 +---
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c
index 113cce71a5..06b486a536 100644
--- a/libavdevice/xcbgrab.c
+++ b/libavdevice/xcbgrab.c
@@ -487,7 +487,7 @@ static xcb_screen_t *get_screen(const xcb_setup_t *setup, 
int screen_num)
 }
 
 static int pixfmt_from_pixmap_format(AVFormatContext *s, int depth,
- int *pix_fmt)
+ int *pix_fmt, int *bpp)
 {
 XCBGrabContext *c= s->priv_data;
 const xcb_setup_t *setup = xcb_get_setup(c->conn);
@@ -525,14 +525,7 @@ static int pixfmt_from_pixmap_format(AVFormatContext *s, 
int depth,
 }
 
 if (*pix_fmt) {
-c->bpp= fmt->bits_per_pixel;
-c->frame_size = c->width * c->height * fmt->bits_per_pixel / 8;
-#if CONFIG_LIBXCB_SHM
-c->shm_pool = av_buffer_pool_init2(c->frame_size + 
AV_INPUT_BUFFER_PADDING_SIZE,
-   c->conn, allocate_shm_buffer, 
NULL);
-if (!c->shm_pool)
-return AVERROR(ENOMEM);
-#endif
+*bpp= fmt->bits_per_pixel;
 return 0;
 }
 
@@ -592,9 +585,18 @@ static int create_stream(AVFormatContext *s)
 st->codecpar->width  = c->width;
 st->codecpar->height = c->height;
 
-ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codecpar->format);
-
+ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codecpar->format, 
&c->bpp);
 free(geo);
+if (ret < 0)
+return ret;
+
+c->frame_size = c->width * c->height * c->bpp / 8;
+#if CONFIG_LIBXCB_SHM
+c->shm_pool = av_buffer_pool_init2(c->frame_size + 
AV_INPUT_BUFFER_PADDING_SIZE,
+   c->conn, allocate_shm_buffer, NULL);
+if (!c->shm_pool)
+return AVERROR(ENOMEM);
+#endif
 
 return ret;
 }
-- 
2.16.4

___
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 2/2] avdevice/xcbgrab: check if frame size fits in INT_MAX

2020-01-01 Thread Marton Balint
Also fixes a possible overflow and sets stream bitrate.

Signed-off-by: Marton Balint 
---
 libavdevice/xcbgrab.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c
index 06b486a536..6f6b2dbf15 100644
--- a/libavdevice/xcbgrab.c
+++ b/libavdevice/xcbgrab.c
@@ -542,6 +542,7 @@ static int create_stream(AVFormatContext *s)
 AVStream *st  = avformat_new_stream(s, NULL);
 xcb_get_geometry_cookie_t gc;
 xcb_get_geometry_reply_t *geo;
+int64_t frame_size_bits;
 int ret;
 
 if (!st)
@@ -580,17 +581,18 @@ static int create_stream(AVFormatContext *s)
 c->frame_duration = av_rescale_q(1, c->time_base, AV_TIME_BASE_Q);
 c->time_frame = av_gettime();
 
-st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
-st->codecpar->codec_id   = AV_CODEC_ID_RAWVIDEO;
-st->codecpar->width  = c->width;
-st->codecpar->height = c->height;
-
 ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codecpar->format, 
&c->bpp);
 free(geo);
 if (ret < 0)
 return ret;
 
-c->frame_size = c->width * c->height * c->bpp / 8;
+frame_size_bits = (int64_t)c->width * c->height * c->bpp;
+if (frame_size_bits / 8 + AV_INPUT_BUFFER_PADDING_SIZE > INT_MAX) {
+av_log(s, AV_LOG_ERROR, "Captured area is too large\n");
+return AVERROR_PATCHWELCOME;
+}
+c->frame_size = frame_size_bits / 8;
+
 #if CONFIG_LIBXCB_SHM
 c->shm_pool = av_buffer_pool_init2(c->frame_size + 
AV_INPUT_BUFFER_PADDING_SIZE,
c->conn, allocate_shm_buffer, NULL);
@@ -598,6 +600,12 @@ static int create_stream(AVFormatContext *s)
 return AVERROR(ENOMEM);
 #endif
 
+st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+st->codecpar->codec_id   = AV_CODEC_ID_RAWVIDEO;
+st->codecpar->width  = c->width;
+st->codecpar->height = c->height;
+st->codecpar->bit_rate   = av_rescale(frame_size_bits, 
st->avg_frame_rate.num, st->avg_frame_rate.den);
+
 return ret;
 }
 
-- 
2.16.4

___
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 2/2] avcodec/rawdec: Use linesize in b64a

2020-01-01 Thread Michael Niedermayer
Fixes: out of array access
Fixes: 
19750/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RAWVIDEO_fuzzer-5074834119983104

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/rawdec.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index 0b2d8708e6..a110a690f5 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -467,10 +467,13 @@ static int raw_decode(AVCodecContext *avctx, void *data, 
int *got_frame,
 avctx->pix_fmt   == AV_PIX_FMT_RGBA64BE) {
 uint8_t *dst = frame->data[0];
 uint64_t v;
-int x;
-for (x = 0; x >> 3 < avctx->width * avctx->height; x += 8) {
-v = AV_RB64(&dst[x]);
-AV_WB64(&dst[x], v << 16 | v >> 48);
+int x, y;
+for (y = 0; y < avctx->height; y++) {
+for (x = 0; x >> 3 < avctx->width; x += 8) {
+v = AV_RB64(&dst[x]);
+AV_WB64(&dst[x], v << 16 | v >> 48);
+}
+dst += frame->linesize[0];
 }
 }
 
-- 
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 1/2] avcodec/smacker: Check space before decoding type

2020-01-01 Thread Michael Niedermayer
Fixes: Timeout (232sec -> 280ms)
Fixes: 
19682/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SMACKER_fuzzer-5654129649385472

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

diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index 4c20831155..b4c463b4b9 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -398,6 +398,8 @@ static av_always_inline int smk_get_code(GetBitContext *gb, 
int *recode, int *la
 int v;
 
 while(*table & SMK_NODE) {
+if (get_bits_left(gb) < 1)
+return AVERROR_INVALIDDATA;
 if(get_bits1(gb))
 table += (*table) & (~SMK_NODE);
 table++;
@@ -462,6 +464,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame,
 uint16_t pix;
 
 type = smk_get_code(&gb, smk->type_tbl, smk->type_last);
+if (type < 0)
+return type;
 run = block_runs[(type >> 2) & 0x3F];
 switch(type & 3){
 case SMK_BLK_MONO:
-- 
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 v3 1/5] avutil: add AV_FRAME_DATA_USER_DATA_UNREGISTERED side data type

2020-01-01 Thread lance . lmwang
On Wed, Jan 01, 2020 at 09:45:19PM +0100, Moritz Barsnick wrote:
> On Thu, Dec 19, 2019 at 13:09:03 +0800, lance.lmw...@gmail.com wrote:
> > +2019-12-17 - xx - lavu 56.37.101 - frame.h
> [...]
> >  #define LIBAVUTIL_VERSION_MAJOR  56
> > -#define LIBAVUTIL_VERSION_MINOR  36
> > +#define LIBAVUTIL_VERSION_MINOR  37
> >  #define LIBAVUTIL_VERSION_MICRO 101
> 
> When bumping major, you need to reset minor to 100.

Sure, I'll resend it.


> 
> Moritz
> ___
> 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".

-- 
Thanks,
Limin Wang
___
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 02/12] lavc/libkvazaar: fix memory leak after av_dict_parse_string fail

2020-01-01 Thread myp...@gmail.com
On Thu, Jan 2, 2020 at 12:46 AM Marton Balint  wrote:
>
>
>
> On Wed, 1 Jan 2020, James Almer wrote:
>
> > On 1/1/2020 2:20 AM, Jun Zhao wrote:
> >> From: Jun Zhao 
> >>
> >> In case of failure, all the successfully set entries are stored in
> >> *pm. We need to manually free the created dictionary to avoid
> >> memory leak.
> >>
> >> Signed-off-by: Jun Zhao 
> >> ---
> >>  libavcodec/libkvazaar.c |2 +-
> >>  1 files changed, 1 insertions(+), 1 deletions(-)
> >>
> >> diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
> >> index a89ca7f..02bcae3 100644
> >> --- a/libavcodec/libkvazaar.c
> >> +++ b/libavcodec/libkvazaar.c
> >> @@ -110,8 +110,8 @@ static av_cold int libkvazaar_init(AVCodecContext
*avctx)
> >> entry->key, entry->value);
> >>  }
> >>  }
> >> -av_dict_free(&dict);
> >>  }
> >> +av_dict_free(&dict);
> >>  }
> >>
> >>  ctx->encoder = enc = api->encoder_open(cfg);
> >
> > There's a patchset by Marton Balint changing this code in all the same
> > modules as in this patchset, by replacing it all with a simple
> > av_dict_copy() call.
> >
> > http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2019-December/254805.html
> > and every following patch.
>
> Yeah, although not every patch is covered, because libkvazaar for example
> uses comma(,) separator instead of colon(:) spearator, so it could not be
> converted to a simple AV_OPT_TYPE_DICT.
>
> Probably I should apply my pending patches and then you should rebase this
> series and keep the ones which are still relevant.
>
Ok, I will rebase the patchset after you apply the pending AV_OPT_TYPE_DICT
patches.
___
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] lavf/libsrt: add version guard for srt encryption control

2020-01-01 Thread myp...@gmail.com
On Sun, Dec 29, 2019 at 9:57 AM Jun Zhao  wrote:
>
> From: Jun Zhao 
>
> add version guard for srt encryption control. and use
> SRTO_STRICTENC(53) for compatibility.
>
> Signed-off-by: Jun Zhao 
> ---
>  libavformat/libsrt.c |   11 +--
>  1 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
> index 2fdfe8e..a727b1c 100644
> --- a/libavformat/libsrt.c
> +++ b/libavformat/libsrt.c
> @@ -62,9 +62,11 @@ typedef struct SRTContext {
>  int64_t maxbw;
>  int pbkeylen;
>  char *passphrase;
> +#if SRT_VERSION_VALUE >= 0x010302
>  int enforced_encryption;
>  int kmrefreshrate;
>  int kmpreannounce;
> +#endif
>  int mss;
>  int ffs;
>  int ipttl;
> @@ -105,9 +107,11 @@ static const AVOption libsrt_options[] = {
>  { "maxbw",  "Maximum bandwidth (bytes per second) that the 
> connection can use", OFFSET(maxbw),AV_OPT_TYPE_INT64,{ 
> .i64 = -1 }, -1, INT64_MAX, .flags = D|E },
>  { "pbkeylen",   "Crypto key len in bytes {16,24,32} Default: 16 
> (128-bit)", OFFSET(pbkeylen), AV_OPT_TYPE_INT,  { 
> .i64 = -1 }, -1, 32,.flags = D|E },
>  { "passphrase", "Crypto PBKDF2 Passphrase size[0,10..64] 0:disable 
> crypto", OFFSET(passphrase),   AV_OPT_TYPE_STRING,   { .str = 
> NULL },  .flags = D|E },
> -{ "enforced_encryption", "Enforces that both connection parties have the 
> same passphrase set ", 
> OFFSET(enforced_encryption), AV_OPT_TYPE_BOOL,  { .i64 = -1 }, -1, 1, 
> .flags = D|E },
> +#if SRT_VERSION_VALUE >= 0x010302
> +{ "enforced_encryption", "Enforces that both connection parties have the 
> same passphrase set",  
> OFFSET(enforced_encryption), AV_OPT_TYPE_BOOL,  { .i64 = -1 }, -1, 1, 
> .flags = D|E },
>  { "kmrefreshrate",   "The number of packets to be transmitted after 
> which the encryption key is switched to a new key", OFFSET(kmrefreshrate),
>AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
>  { "kmpreannounce",   "The interval between when a new encryption key 
> is sent and when switchover occurs",   OFFSET(kmpreannounce), 
>   AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, INT_MAX,   .flags = D|E },
> +#endif
>  { "mss","The Maximum Segment Size",  
>OFFSET(mss),  AV_OPT_TYPE_INT,  { .i64 = 
> -1 }, -1, 1500,  .flags = D|E },
>  { "ffs","Flight flag size (window size) (in bytes)", 
>OFFSET(ffs),  AV_OPT_TYPE_INT,  { .i64 = 
> -1 }, -1, INT_MAX,   .flags = D|E },
>  { "ipttl",  "IP Time To Live",   
>OFFSET(ipttl),AV_OPT_TYPE_INT,  { .i64 = 
> -1 }, -1, 255,   .flags = D|E },
> @@ -327,9 +331,12 @@ static int libsrt_set_options_pre(URLContext *h, int fd)
>  (s->maxbw >= 0 && libsrt_setsockopt(h, fd, SRTO_MAXBW, "SRTO_MAXBW", 
> &s->maxbw, sizeof(s->maxbw)) < 0) ||
>  (s->pbkeylen >= 0 && libsrt_setsockopt(h, fd, SRTO_PBKEYLEN, 
> "SRTO_PBKEYLEN", &s->pbkeylen, sizeof(s->pbkeylen)) < 0) ||
>  (s->passphrase && libsrt_setsockopt(h, fd, SRTO_PASSPHRASE, 
> "SRTO_PASSPHRASE", s->passphrase, strlen(s->passphrase)) < 0) ||
> -(s->enforced_encryption >= 0 && libsrt_setsockopt(h, fd, 
> SRTO_ENFORCEDENCRYPTION, "SRTO_ENFORCEDENCRYPTION", &s->enforced_encryption, 
> sizeof(s->enforced_encryption)) < 0) ||
> +#if SRT_VERSION_VALUE >= 0x010302
> +/* SRTO_STRICTENC == SRTO_ENFORCEDENCRYPTION (53), but for 
> compatibility, we used SRTO_STRICTENC */
> +(s->enforced_encryption >= 0 && libsrt_setsockopt(h, fd, 
> SRTO_STRICTENC, "SRTO_STRICTENC", &s->enforced_encryption, 
> sizeof(s->enforced_encryption)) < 0) ||
>  (s->kmrefreshrate >= 0 && libsrt_setsockopt(h, fd, 
> SRTO_KMREFRESHRATE, "SRTO_KMREFRESHRATE", &s->kmrefreshrate, 
> sizeof(s->kmrefreshrate)) < 0) ||
>  (s->kmpreannounce >= 0 && libsrt_setsockopt(h, fd, 
> SRTO_KMPREANNOUNCE, "SRTO_KMPREANNOUNCE", &s->kmpreannounce, 
> sizeof(s->kmpreannounce)) < 0) ||
> +#endif
>  (s->mss >= 0 && libsrt_setsockopt(h, fd, SRTO_MSS, "SRTO_MMS", 
> &s->mss, sizeof(s->mss)) < 0) ||
>  (s->ffs >= 0 && libsrt_setsockopt(h, fd, SRTO_FC, "SRTO_FC", 
> &s->ffs, sizeof(s->ffs)) < 0) ||
>  (s->ipttl >= 0 && libsrt_setsockopt(h, fd, SRTO_IPTTL, "SRTO_UPTTL", 
> &s->ipttl, sizeof(s->ipttl)) < 0) ||
> --
> 1.7.1
>
Applied, thx
___
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 v5 2/4] avcodec/hevc_sei: add support for user data unregistered SEI message

2020-01-01 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavcodec/hevc_sei.c   | 31 +++
 libavcodec/hevc_sei.h   |  6 ++
 libavcodec/hevcdec.c| 14 ++
 tests/ref/fate/hevc-monochrome-crop |  3 +++
 4 files changed, 54 insertions(+)

diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index 562ce8b..a7c49ce 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -207,6 +207,30 @@ static int 
decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB
 return 0;
 }
 
+static int decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, 
GetBitContext *gb,
+  int size)
+{
+AVBufferRef *buf_ref, **tmp;
+
+if (size < 16)
+   return AVERROR(EINVAL);
+
+tmp = av_realloc_array(s->buf_ref, s->nb_buf_ref + 1, sizeof(*s->buf_ref));
+if (!tmp)
+return AVERROR(ENOMEM);
+s->buf_ref = tmp;
+
+buf_ref = av_buffer_alloc(size);
+if (!buf_ref)
+return AVERROR(ENOMEM);
+
+for (int i = 0; i < size; i++)
+buf_ref->data[i] = get_bits(gb, 8);
+s->buf_ref[s->nb_buf_ref++] = buf_ref;
+
+return 0;
+}
+
 static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, 
GetBitContext *gb,
  int size)
 {
@@ -294,6 +318,8 @@ static int decode_nal_sei_prefix(GetBitContext *gb, void 
*logctx, HEVCSEI *s,
 return decode_nal_sei_active_parameter_sets(s, gb, logctx);
 case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35:
 return decode_nal_sei_user_data_registered_itu_t_t35(s, gb, size);
+case HEVC_SEI_TYPE_USER_DATA_UNREGISTERED:
+return decode_nal_sei_user_data_unregistered(&s->unregistered, gb, 
size);
 case HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS:
 return decode_nal_sei_alternative_transfer(&s->alternative_transfer, 
gb);
 default:
@@ -365,4 +391,9 @@ int ff_hevc_decode_nal_sei(GetBitContext *gb, void *logctx, 
HEVCSEI *s,
 void ff_hevc_reset_sei(HEVCSEI *s)
 {
 av_buffer_unref(&s->a53_caption.buf_ref);
+
+for (int i = 0; i < s->unregistered.nb_buf_ref; i++)
+av_buffer_unref(&s->unregistered.buf_ref[i]);
+s->unregistered.nb_buf_ref = 0;
+av_freep(&s->unregistered.buf_ref);
 }
diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
index 2769d41..a8a2ab7 100644
--- a/libavcodec/hevc_sei.h
+++ b/libavcodec/hevc_sei.h
@@ -86,6 +86,11 @@ typedef struct HEVCSEIA53Caption {
 AVBufferRef *buf_ref;
 } HEVCSEIA53Caption;
 
+typedef struct HEVCSEIUnregistered {
+AVBufferRef **buf_ref;
+int nb_buf_ref;
+} HEVCSEIUnregistered;
+
 typedef struct HEVCSEIMasteringDisplay {
 int present;
 uint16_t display_primaries[3][2];
@@ -111,6 +116,7 @@ typedef struct HEVCSEI {
 HEVCSEIDisplayOrientation display_orientation;
 HEVCSEIPictureTiming picture_timing;
 HEVCSEIA53Caption a53_caption;
+HEVCSEIUnregistered unregistered;
 HEVCSEIMasteringDisplay mastering_display;
 HEVCSEIContentLight content_light;
 int active_seq_parameter_set_id;
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 19b0cd8..f3f855d 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2789,6 +2789,20 @@ static int set_side_data(HEVCContext *s)
 s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
 }
 
+for (int i = 0; i < s->sei.unregistered.nb_buf_ref; i++) {
+HEVCSEIUnregistered *unreg = &s->sei.unregistered;
+
+if (unreg->buf_ref[i]) {
+AVFrameSideData *sd = av_frame_new_side_data_from_buf(out,
+AV_FRAME_DATA_USER_DATA_UNREGISTERED,
+unreg->buf_ref[i]);
+if (!sd)
+av_buffer_unref(&unreg->buf_ref[i]);
+unreg->buf_ref[i] = NULL;
+}
+}
+s->sei.unregistered.nb_buf_ref = 0;
+
 return 0;
 }
 
diff --git a/tests/ref/fate/hevc-monochrome-crop 
b/tests/ref/fate/hevc-monochrome-crop
index 4e45412..43f0abb 100644
--- a/tests/ref/fate/hevc-monochrome-crop
+++ b/tests/ref/fate/hevc-monochrome-crop
@@ -1,6 +1,9 @@
 [FRAME]
 width=384
 height=240
+[SIDE_DATA]
+side_data_type=User Data Unregistered
+[/SIDE_DATA]
 [/FRAME]
 [STREAM]
 width=384
-- 
2.9.5

___
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 v5 1/4] add AV_FRAME_DATA_USER_DATA_UNREGISTERED side data type

2020-01-01 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
rebase the patchset for the latest code

 doc/APIchanges  | 3 +++
 libavutil/frame.c   | 1 +
 libavutil/frame.h   | 8 
 libavutil/version.h | 2 +-
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 3c24dc6..6e1673e 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2020-01-xx - xx - lavu 56.39.100 - frame.h
+  Add AV_FRAME_DATA_USER_DATA_UNREGISTERED.
+
 2019-12-27 - xx - lavu 56.38.100 - eval.h
   Add av_expr_count_func().
 
diff --git a/libavutil/frame.c b/libavutil/frame.c
index e403809..1d0faec6 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -842,6 +842,7 @@ const char *av_frame_side_data_name(enum 
AVFrameSideDataType type)
 #endif
 case AV_FRAME_DATA_DYNAMIC_HDR_PLUS: return "HDR Dynamic Metadata 
SMPTE2094-40 (HDR10+)";
 case AV_FRAME_DATA_REGIONS_OF_INTEREST: return "Regions Of Interest";
+case AV_FRAME_DATA_USER_DATA_UNREGISTERED: return "User Data Unregistered";
 }
 return NULL;
 }
diff --git a/libavutil/frame.h b/libavutil/frame.h
index b5afb58..9e8c3a9 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,14 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+
+/**
+ * User data unregistered metadata associated with a video frame.
+ * This data payload is stored as uint8_t in AVFrameSideData.data.
+ * The number of bytes of data payload is AVFrameSideData.size.
+ * The data payload consists of 16 bytes UUID and real user data.
+ */
+AV_FRAME_DATA_USER_DATA_UNREGISTERED,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/version.h b/libavutil/version.h
index af8f614..2bc1b98 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  38
+#define LIBAVUTIL_VERSION_MINOR  39
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.9.5

___
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 v5 3/4] avfilter/vf_showinfo: display user data unregistered message

2020-01-01 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavfilter/vf_showinfo.c | 33 +
 1 file changed, 33 insertions(+)

diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index 31f6b32..bb3b37e 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -169,6 +169,36 @@ static void dump_content_light_metadata(AVFilterContext 
*ctx, AVFrameSideData *s
metadata->MaxCLL, metadata->MaxFALL);
 }
 
+static int string_is_ascii(const uint8_t *str)
+{
+while (*str && *str < 128) str++;
+return !*str;
+}
+
+static void dump_user_data_unregistered_metadata(AVFilterContext *ctx, 
AVFrameSideData *sd)
+{
+const int uuid_size = 16;
+uint8_t *user_data = sd->data;
+
+if (sd->size < uuid_size) {
+av_log(ctx, AV_LOG_ERROR, "invalid data(%d < UUID(%d-bytes))", 
sd->size, uuid_size);
+return;
+}
+
+av_log(ctx, AV_LOG_INFO, "User Data Unregistered:\n");
+av_log(ctx, AV_LOG_INFO, "UUID=");
+for (int i = 0; i < uuid_size; i++)
+av_log(ctx, AV_LOG_INFO, "%x", user_data[i]);
+av_log(ctx, AV_LOG_INFO, "\n");
+
+user_data += uuid_size;
+/* Only print the user data details if it's string */
+if (string_is_ascii(user_data)) {
+av_log(ctx, AV_LOG_INFO, "User Data=");
+av_log(ctx, AV_LOG_INFO, "%s", user_data);
+}
+}
+
 static void dump_color_property(AVFilterContext *ctx, AVFrame *frame)
 {
 const char *color_range_str = av_color_range_name(frame->color_range);
@@ -319,6 +349,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
 av_log(ctx, AV_LOG_INFO, "GOP timecode - %s", tcbuf);
 break;
 }
+case AV_FRAME_DATA_USER_DATA_UNREGISTERED:
+dump_user_data_unregistered_metadata(ctx, sd);
+break;
 default:
 av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)",
sd->type, sd->size);
-- 
2.9.5

___
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 v5 4/4] avcodec/h264: create user data unregistered side data H.264

2020-01-01 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavcodec/h264_sei.c |  20 +++--
 libavcodec/h264_sei.h |   2 +
 libavcodec/h264_slice.c   |  14 
 tests/ref/fate/mov-zombie | 195 ++
 4 files changed, 161 insertions(+), 70 deletions(-)

diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
index a565fea..43e2814 100644
--- a/libavcodec/h264_sei.c
+++ b/libavcodec/h264_sei.c
@@ -52,6 +52,10 @@ void ff_h264_sei_uninit(H264SEIContext *h)
 h->afd.present =  0;
 
 av_buffer_unref(&h->a53_caption.buf_ref);
+for (int i = 0; i < h->unregistered.nb_buf_ref; i++)
+av_buffer_unref(&h->unregistered.buf_ref[i]);
+h->unregistered.nb_buf_ref = 0;
+av_freep(&h->unregistered.buf_ref);
 }
 
 static int decode_picture_timing(H264SEIPictureTiming *h, GetBitContext *gb,
@@ -246,25 +250,31 @@ static int 
decode_unregistered_user_data(H264SEIUnregistered *h, GetBitContext *
 {
 uint8_t *user_data;
 int e, build, i;
+AVBufferRef *buf_ref, **tmp;
 
-if (size < 16 || size >= INT_MAX - 1)
+if (size < 16)
 return AVERROR_INVALIDDATA;
 
-user_data = av_malloc(size + 1);
-if (!user_data)
+tmp = av_realloc_array(h->buf_ref, h->nb_buf_ref + 1, sizeof(*h->buf_ref));
+if (!tmp)
 return AVERROR(ENOMEM);
+h->buf_ref = tmp;
+
+buf_ref = av_buffer_alloc(size);
+if (!buf_ref)
+return AVERROR(ENOMEM);
+user_data = buf_ref->data;
 
 for (i = 0; i < size; i++)
 user_data[i] = get_bits(gb, 8);
+h->buf_ref[h->nb_buf_ref++] = buf_ref;
 
-user_data[i] = 0;
 e = sscanf(user_data + 16, "x264 - core %d", &build);
 if (e == 1 && build > 0)
 h->x264_build = build;
 if (e == 1 && build == 1 && !strncmp(user_data+16, "x264 - core ", 16))
 h->x264_build = 67;
 
-av_free(user_data);
 return 0;
 }
 
diff --git a/libavcodec/h264_sei.h b/libavcodec/h264_sei.h
index a75c3aa..aa4595f 100644
--- a/libavcodec/h264_sei.h
+++ b/libavcodec/h264_sei.h
@@ -121,6 +121,8 @@ typedef struct H264SEIA53Caption {
 
 typedef struct H264SEIUnregistered {
 int x264_build;
+AVBufferRef **buf_ref;
+int nb_buf_ref;
 } H264SEIUnregistered;
 
 typedef struct H264SEIRecoveryPoint {
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index e24d41c..ea967c8 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1285,6 +1285,20 @@ static int h264_export_frame_props(H264Context *h)
 h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
 }
 
+for (int i = 0; i < h->sei.unregistered.nb_buf_ref; i++) {
+H264SEIUnregistered *unreg = &h->sei.unregistered;
+
+if (unreg->buf_ref[i]) {
+AVFrameSideData *sd = av_frame_new_side_data_from_buf(cur->f,
+AV_FRAME_DATA_USER_DATA_UNREGISTERED,
+unreg->buf_ref[i]);
+if (!sd)
+av_buffer_unref(&unreg->buf_ref[i]);
+unreg->buf_ref[i] = NULL;
+}
+}
+h->sei.unregistered.nb_buf_ref = 0;
+
 if (h->sei.picture_timing.timecode_cnt > 0) {
 uint32_t tc = 0;
 uint32_t *tc_sd;
diff --git a/tests/ref/fate/mov-zombie b/tests/ref/fate/mov-zombie
index f45fa59..0888295 100644
--- a/tests/ref/fate/mov-zombie
+++ b/tests/ref/fate/mov-zombie
@@ -1,133 +1,198 @@
 
packet|codec_type=video|stream_index=0|pts=0|pts_time=0.00|dts=-3004|dts_time=-0.033378|duration=3003|duration_time=0.033367|convergence_duration=N/A|convergence_duration_time=N/A|size=4133|pos=11309|flags=K_
 
packet|codec_type=video|stream_index=0|pts=5440|pts_time=0.060444|dts=-567|dts_time=-0.006300|duration=3003|duration_time=0.033367|convergence_duration=N/A|convergence_duration_time=N/A|size=1077|pos=15442|flags=__
-frame|media_type=video|stream_index=0|key_frame=1|pkt_pts=0|pkt_pts_time=0.00|pkt_dts=-567|pkt_dts_time=-0.006300|best_effort_timestamp=0|best_effort_timestamp_time=0.00|pkt_duration=3003|pkt_duration_time=0.033367|pkt_pos=11309|pkt_size=4133|width=160|height=240|pix_fmt=yuv420p|sample_aspect_ratio=2:1|pict_type=I|coded_picture_number=0|display_picture_number=0|interlaced_frame=0|top_field_first=0|repeat_pict=0|color_range=tv|color_space=smpte170m|color_primaries=smpte170m|color_transfer=bt709|chroma_location=topleft
+frame|media_type=video|stream_index=0|key_frame=1|pkt_pts=0|pkt_pts_time=0.00|pkt_dts=-567|pkt_dts_time=-0.006300|best_effort_timestamp=0|best_effort_timestamp_time=0.00|pkt_duration=3003|pkt_duration_time=0.033367|pkt_pos=11309|pkt_size=4133|width=160|height=240|pix_fmt=yuv420p|sample_aspect_ratio=2:1|pict_type=I|coded_picture_number=0|display_picture_number=0|interlaced_frame=0|top_field_first=0|repeat_pict=0|color_range=tv|color_space=smpte170m|color_primaries=smpte170m|color_transfer=bt709|chroma_location=topleftside_data|side_data_type=User
 Data Unregistered
+
 
packet|codec_type=video|stream_index=0|pts=2437|pts_time=0.0

[FFmpeg-devel] [PATCH] Removes linebreaks forbidden by the WEBVTT spec on encode

2020-01-01 Thread bloomtom
libavformat/webvttenc.c: The WEBVTT spec only allows one sequential
linebreak (\r, \n) character within packet data. Two or more linebreaks
in a row signifies the end of a data packet. Previous behavior allows data
to be orphaned outside packets parsed by the spec in the best case, but
some parsers simply refuse to process such vtt files. This patch shims
packet data writing, skipping linebreak characters at the start and end of
packet data, and replacing any number of sequential linebreaks between
valid characters with a single linefeed.
tests/ref/fate/sub-webvttenc: Modified to expect the new behavior in webvttenc.

Signed-off-by: Tom Bloom 
---
 libavformat/webvttenc.c  | 43 ++--
 tests/ref/fate/sub-webvttenc |  4 
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/libavformat/webvttenc.c b/libavformat/webvttenc.c
index 61b7f54622..8da2818aec 100644
--- a/libavformat/webvttenc.c
+++ b/libavformat/webvttenc.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2013 Matthew Heaney
+ * Copyright (c) 2020 Thomas Bloom
  *
  * This file is part of FFmpeg.
  *
@@ -62,6 +63,42 @@ static int webvtt_write_header(AVFormatContext *ctx)
 return 0;
 }
 

+static int is_linebreak(char c)
+{
+return c == '\n' || c == '\r';
+}
+
+static int webvtt_write_data(AVIOContext *pb, uint8_t *pkt, int pkt_len)
+{
+int start = 0;
+int written = 0;
+
+// Fast forward to first non-linebreak.
+while(start < pkt_len - 1 && is_linebreak(pkt[start])) {
+start++;
+}
+
+for (int i = start; i < pkt_len; i++) {
+while(is_linebreak(pkt[i])) {
+if (i == pkt_len - 1) {
+// Hit end with no stop in linebreaks.
+return written;
+}
+else if (!is_linebreak(pkt[i+1])) {
+// write a single linefeed to cover all skipped.
+avio_printf(pb, "\n");
+written++;
+}
+i++;
+}
+
+avio_write(pb, &pkt[i], 1);
+written++;
+}
+
+return written;
+}
+
 static int webvtt_write_packet(AVFormatContext *ctx, AVPacket *pkt)
 {
 AVIOContext  *pb = ctx->pb;
@@ -88,8 +125,10 @@ static int webvtt_write_packet(AVFormatContext *ctx, 
AVPacket *pkt)
 

 avio_printf(pb, "\n");
 

-avio_write(pb, pkt->data, pkt->size);
-avio_printf(pb, "\n");
+if (webvtt_write_data(pb, pkt->data, pkt->size) > 0) {
+// Data not empty. Write a linefeed to divide packets in output.
+avio_printf(pb, "\n");
+}
 

 return 0;
 }
diff --git a/tests/ref/fate/sub-webvttenc b/tests/ref/fate/sub-webvttenc
index 45ae0b6131..012f10a8ba 100644
--- a/tests/ref/fate/sub-webvttenc
+++ b/tests/ref/fate/sub-webvttenc
@@ -128,14 +128,12 @@ also hide these tags:
 but show this: {normal text}
 

 00:54.501 --> 01:00.500
-
 \ N is a forced line break
 \ h is a hard space
 Normal spaces at the start and at the end of the line are trimmed while hard 
spaces are not trimmed.
 
The\hline\hwill\hnever\hbreak\hautomatically\hright\hbefore\hor\hafter\ha\hhard\hspace.\h:-D
 

 00:54.501 --> 00:56.500
-
 \h\h\h\h\hA (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
@@ -147,13 +145,11 @@ A (No hard spaces followed by a letter)
 Show this: \TEST and this: \-)
 

 00:58.501 --> 01:00.500
-
 A letter followed by 05 hard spaces: A\h\h\h\h\h
 A letter followed by normal  spaces: A
 A letter followed by no hard spaces: A
 05 hard  spaces between letters: A\h\h\h\h\hA
 5 normal spaces between letters: A A
-
 ^--Forced line break
 

 01:00.501 --> 01:02.500
-- 

2.17.1

WEBVTT

00:00.000 --> 00:02.000



Line 1

Line 2


00:02.000 --> 00:03.000

Line 3

00:04.000 --> 00:05.000



00:06.000 --> 00:07.000





test-multi-line-sub.ass
Description: Binary data
WEBVTT

00:00.000 --> 00:02.000
Line 1
Line 2

00:02.000 --> 00:03.000
Line 3

00:04.000 --> 00:05.000

00:06.000 --> 00:07.000


Removes-linebreaks-forbidden-by-the-WEBVTT-spec-on-e.patch
Description: Binary data


signature.asc
Description: OpenPGP digital 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 v1] avfilter: add overlay vaapi filter

2020-01-01 Thread Sun, Xinpeng

> -Original Message-
> From: Paul B Mahol 
> Sent: Tuesday, December 31, 2019 5:06 PM
> To: FFmpeg development discussions and patches 
> Cc: Sun, Xinpeng ; Zhou, Zachary
> 
> Subject: Re: [FFmpeg-devel] [PATCH v1] avfilter: add overlay vaapi filter
> 
> On 12/20/19, Xinpeng Sun  wrote:
> > Overlay one video on the top of another.
> >
> > It takes two inputs and has one output. The first input is the "main"
> > video on which the second input is overlaid. This filter requires same
> > memory layout for all the inputs.
> >
> > An example command to use this filter to overlay an image LOGO at the
> > top-left corner of the INPUT video and both inputs are yuv420p format:
> > FFMPEG -hwaccel vaapi -vaapi_device /dev/dri/renderD128
> > -hwaccel_output_format vaapi \ -i INPUT -i LOGO -filter_complex \
> > "[0:v]hwupload[a], [1:v]format=yuv420p, hwupload[b],
> > [a][b]overlay_vaapi, hwdownload" \ OUTPUT
> >
> > Signed-off-by: Xinpeng Sun 
> > Signed-off-by: Zachary Zhou 
> > ---
> >  configure  |   3 +
> >  doc/filters.texi   |  51 
> >  libavfilter/Makefile   |   1 +
> >  libavfilter/allfilters.c   |   1 +
> >  libavfilter/vf_overlay_vaapi.c | 432
> > +
> >  5 files changed, 488 insertions(+)
> >  create mode 100644 libavfilter/vf_overlay_vaapi.c
> >
> > diff --git a/configure b/configure
> > index eec43c3b06..9969c9e984 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3527,6 +3527,7 @@ openclsrc_filter_deps="opencl"
> >  overlay_opencl_filter_deps="opencl"
> >  overlay_qsv_filter_deps="libmfx"
> >  overlay_qsv_filter_select="qsvvpp"
> > +overlay_vaapi_filter_deps="vaapi"
> >  owdenoise_filter_deps="gpl"
> >  pan_filter_deps="swresample"
> >  perspective_filter_deps="gpl"
> > @@ -3584,6 +3585,7 @@ tonemap_vaapi_filter_deps="vaapi
> > VAProcPipelineParameterBuffer_output_hdr_metada
> >  tonemap_opencl_filter_deps="opencl const_nan"
> >  transpose_opencl_filter_deps="opencl"
> >  transpose_vaapi_filter_deps="vaapi VAProcPipelineCaps_rotation_flags"
> > +overlay_vaapi_filter_deps="vaapi VAProcPipelineCaps_blend_flags"
> >  unsharp_opencl_filter_deps="opencl"
> >  uspp_filter_deps="gpl avcodec"
> >  vaguedenoiser_filter_deps="gpl"
> > @@ -6587,6 +6589,7 @@ if enabled vaapi; then
> >  check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth
> >  check_struct "va/va.h va/va_vpp.h" "VAProcPipelineParameterBuffer"
> > output_hdr_metadata
> >  check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps"
> > rotation_flags
> > +check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps"
> > + blend_flags
> >  check_type "va/va.h va/va_enc_hevc.h"
> "VAEncPictureParameterBufferHEVC"
> >  check_type "va/va.h va/va_enc_jpeg.h"
> "VAEncPictureParameterBufferJPEG"
> >  check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
> > diff --git a/doc/filters.texi b/doc/filters.texi index
> > 527c6a08b2..d391218529 100644
> > --- a/doc/filters.texi
> > +++ b/doc/filters.texi
> > @@ -21049,6 +21049,57 @@ To enable compilation of these filters you
> > need to configure FFmpeg with
> >
> >  To use vaapi filters, you need to setup the vaapi device correctly.
> > For more information, please read
> > @url{https://trac.ffmpeg.org/wiki/Hardware/VAAPI}
> >
> > +@section overlay_vaapi
> > +
> > +Overlay one video on the top of another.
> > +
> > +It takes two inputs and has one output. The first input is the "main"
> > +video
> > on which the second input is overlaid.
> > +This filter requires same memory layout for all the inputs. So,
> > +format
> > conversion may be needed.
> > +
> > +The filter accepts the following options:
> > +
> > +@table @option
> > +
> > +@item x
> > +Set the x coordinate of the overlaid video on the main video.
> > +Default value is @code{0}.
> > +
> > +@item y
> > +Set the y coordinate of the overlaid video on the main video.
> > +Default value is @code{0}.
> > +
> > +@item w
> > +Set the width of the overlaid video on the main video.
> > +Default value is the width of input overlay video.
> > +
> > +@item h
> > +Set the height of the overlaid video on the main video.
> > +Default value is the height of input overlay video.
> > +
> > +@item alpha
> > +Set blocking detection thresholds. Allowed range is 0.0 to 1.0, it
> > +need input video has alpha channel.
> 
> needs input video that have alpha channel.

Will be fixed in the next version.

> 
> > +Default value is @code{0.0}.
> > +
> > +@end table
> > +
> > +@subsection Examples
> > +
> > +@itemize
> > +@item
> > +Overlay an image LOGO at the top-left corner of the INPUT video. Both
> > inputs are yuv420p format.
> > +@example
> > +-i INPUT -i LOGO -filter_complex "[0:v]hwupload[a],
> > +[1:v]format=yuv420p,
> > hwupload[b], [a][b]overlay_vaapi, hwdownload" OUTPUT
> > +@end example
> > +@item
> > +Overlay an image LOGO at the offset (200, 100) from the top-left
> > +corner of
> > the INPUT video.
> > +The inputs have same memor

Re: [FFmpeg-devel] [PATCH v1] avfilter: add overlay vaapi filter

2020-01-01 Thread Sun, Xinpeng

> -Original Message-
> From: ffmpeg-devel  On Behalf Of Moritz
> Barsnick
> Sent: Thursday, January 2, 2020 6:30 AM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH v1] avfilter: add overlay vaapi filter
> 
> On Fri, Dec 20, 2019 at 10:55:39 +0800, Xinpeng Sun wrote:
> > +Set blocking detection thresholds. Allowed range is 0.0 to 1.0, it
> > +need input video has alpha channel.
> 
> Incorrect grammar. I suggest ", it requires an input video with alpha 
> channel".
> 
> > +ret = ff_formats_ref(ff_make_format_list(main_in_fmts), &ctx-
> >inputs[MAIN]->out_formats);
> > +if (ret < 0)
> > +  return ret;
> > +
> > +ret = ff_formats_ref(ff_make_format_list(main_in_fmts), &ctx-
> >inputs[OVERLAY]->out_formats);
> > +if (ret < 0)
> > +  return ret;
> 
> Incorrect indentation (twice).
> 
> > +if (!support_flag) {
> > +  av_log(avctx, AV_LOG_ERROR, "VAAPI driver doesn't support global 
> > alpha
> blending\n");
> > +return AVERROR(EINVAL);
> 
> Incorrect indentation.
> 
> Moritz

Thanks for review. I will fix them in the next version.

Xinpeng
___
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".