[FFmpeg-cvslog] avfilter/vf_neighbor: rewrite without using temp memory

2018-05-01 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Tue May  1 13:12:50 
2018 +0200| [273edb2fe45a8f3805085f879ad4717d87247aeb] | committer: Paul B Mahol

avfilter/vf_neighbor: rewrite without using temp memory

Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=273edb2fe45a8f3805085f879ad4717d87247aeb
---

 libavfilter/vf_neighbor.c | 70 ---
 1 file changed, 24 insertions(+), 46 deletions(-)

diff --git a/libavfilter/vf_neighbor.c b/libavfilter/vf_neighbor.c
index de4a12f048..bd69c9e77f 100644
--- a/libavfilter/vf_neighbor.c
+++ b/libavfilter/vf_neighbor.c
@@ -34,7 +34,6 @@ typedef struct NContext {
 int nb_planes;
 int threshold[4];
 int coordinates;
-uint8_t *buffer;
 
 void (*filter)(uint8_t *dst, const uint8_t *p1, int width,
int threshold, const uint8_t *coordinates[], int coord);
@@ -52,25 +51,6 @@ static int query_formats(AVFilterContext *ctx)
 return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
 }
 
-static av_cold void uninit(AVFilterContext *ctx)
-{
-NContext *s = ctx->priv;
-
-av_freep(&s->buffer);
-}
-
-static inline void line_copy8(uint8_t *line, const uint8_t *srcp, int width, 
int mergin)
-{
-int i;
-
-memcpy(line, srcp, width);
-
-for (i = mergin; i > 0; i--) {
-line[-i] = line[i];
-line[width - 1 + i] = line[width - 1 - i];
-}
-}
-
 static void erosion(uint8_t *dst, const uint8_t *p1, int width,
 int threshold, const uint8_t *coordinates[], int coord)
 {
@@ -155,9 +135,6 @@ static int config_input(AVFilterLink *inlink)
 s->planeheight[0] = s->planeheight[3] = inlink->h;
 
 s->nb_planes = av_pix_fmt_count_planes(inlink->format);
-s->buffer = av_malloc(3 * (s->planewidth[0] + 32));
-if (!s->buffer)
-return AVERROR(ENOMEM);
 
 if (!strcmp(ctx->filter->name, "erosion"))
 s->filter = erosion;
@@ -190,32 +167,34 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 const int threshold = s->threshold[plane];
 
 if (threshold) {
+const int stride = in->linesize[plane];
+const int dstride = out->linesize[plane];
 const uint8_t *src = in->data[plane];
 uint8_t *dst = out->data[plane];
-int stride = in->linesize[plane];
-int height = s->planeheight[plane];
-int width  = s->planewidth[plane];
-uint8_t *p0 = s->buffer + 16;
-uint8_t *p1 = p0 + s->planewidth[0];
-uint8_t *p2 = p1 + s->planewidth[0];
-uint8_t *orig = p0, *end = p2;
-
-line_copy8(p0, src + stride, width, 1);
-line_copy8(p1, src, width, 1);
+const int height = s->planeheight[plane];
+const int width  = s->planewidth[plane];
 
 for (y = 0; y < height; y++) {
-const uint8_t *coordinates[] = { p0 - 1, p0, p0 + 1,
- p1 - 1, p1 + 1,
- p2 - 1, p2, p2 + 1};
-src += stride * (y < height - 1 ? 1 : -1);
-line_copy8(p2, src, width, 1);
-
-s->filter(dst, p1, width, threshold, coordinates, 
s->coordinates);
-
-p0 = p1;
-p1 = p2;
-p2 = (p2 == end) ? orig: p2 + s->planewidth[0];
-dst += out->linesize[plane];
+const int nh = y > 0;
+const int ph = y < height - 1;
+const uint8_t *coordinates[] = { src - nh * stride, src + 1 - 
nh * stride, src + 2 - nh * stride,
+ src,  
src + 2,
+ src + ph * stride, src + 1 + 
ph * stride, src + 2 + ph * stride};
+
+const uint8_t *coordinateslb[] = { src - nh * stride, src - nh 
* stride, src + 1 - nh * stride,
+   src,
  src + 1,
+   src + ph * stride, src + ph 
* stride, src + 1 + ph * stride};
+
+const uint8_t *coordinatesrb[] = { src + width - 2 - nh * 
stride, src + width - 1 - nh * stride, src + width - 1 - nh * stride,
+   src + width - 2,
  src + width - 1,
+   src + width - 2 + ph * 
stride, src + width - 1 + ph * stride, src + width - 1 + ph * stride};
+
+s->filter(dst, src, 1, 
threshold, coordinateslb, s->coordinates);
+s->filter(dst + 1, src + 1, width - 2, 
threshold, coordinates,   s->coordinates);
+s->filter(dst + width - 1, src + width - 1, 1, 
threshold, coordinatesrb, s-

[FFmpeg-cvslog] avfilter/vf_neighbor: simplify code little

2018-05-01 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Tue May  1 14:50:48 
2018 +0200| [ddf844d17c40fd6053f06d67d8973c302e01b61c] | committer: Paul B Mahol

avfilter/vf_neighbor: simplify code little

Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ddf844d17c40fd6053f06d67d8973c302e01b61c
---

 libavfilter/vf_neighbor.c | 66 +++
 1 file changed, 32 insertions(+), 34 deletions(-)

diff --git a/libavfilter/vf_neighbor.c b/libavfilter/vf_neighbor.c
index bd69c9e77f..1eb89c208d 100644
--- a/libavfilter/vf_neighbor.c
+++ b/libavfilter/vf_neighbor.c
@@ -165,41 +165,39 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
 for (plane = 0; plane < s->nb_planes; plane++) {
 const int threshold = s->threshold[plane];
+const int stride = in->linesize[plane];
+const int dstride = out->linesize[plane];
+const uint8_t *src = in->data[plane];
+uint8_t *dst = out->data[plane];
+const int height = s->planeheight[plane];
+const int width  = s->planewidth[plane];
+
+if (!threshold) {
+av_image_copy_plane(dst, dstride, src, stride, width, height);
+continue;
+}
 
-if (threshold) {
-const int stride = in->linesize[plane];
-const int dstride = out->linesize[plane];
-const uint8_t *src = in->data[plane];
-uint8_t *dst = out->data[plane];
-const int height = s->planeheight[plane];
-const int width  = s->planewidth[plane];
-
-for (y = 0; y < height; y++) {
-const int nh = y > 0;
-const int ph = y < height - 1;
-const uint8_t *coordinates[] = { src - nh * stride, src + 1 - 
nh * stride, src + 2 - nh * stride,
- src,  
src + 2,
- src + ph * stride, src + 1 + 
ph * stride, src + 2 + ph * stride};
-
-const uint8_t *coordinateslb[] = { src - nh * stride, src - nh 
* stride, src + 1 - nh * stride,
-   src,
  src + 1,
-   src + ph * stride, src + ph 
* stride, src + 1 + ph * stride};
-
-const uint8_t *coordinatesrb[] = { src + width - 2 - nh * 
stride, src + width - 1 - nh * stride, src + width - 1 - nh * stride,
-   src + width - 2,
  src + width - 1,
-   src + width - 2 + ph * 
stride, src + width - 1 + ph * stride, src + width - 1 + ph * stride};
-
-s->filter(dst, src, 1, 
threshold, coordinateslb, s->coordinates);
-s->filter(dst + 1, src + 1, width - 2, 
threshold, coordinates,   s->coordinates);
-s->filter(dst + width - 1, src + width - 1, 1, 
threshold, coordinatesrb, s->coordinates);
-
-src += stride;
-dst += dstride;
-}
-} else {
-av_image_copy_plane(out->data[plane], out->linesize[plane],
-in->data[plane], in->linesize[plane],
-s->planewidth[plane], s->planeheight[plane]);
+for (y = 0; y < height; y++) {
+const int nh = y > 0;
+const int ph = y < height - 1;
+const uint8_t *coordinates[] = { src - nh * stride, src + 1 - nh * 
stride, src + 2 - nh * stride,
+ src,  
src + 2,
+ src + ph * stride, src + 1 + ph * 
stride, src + 2 + ph * stride};
+
+const uint8_t *coordinateslb[] = { src - nh * stride, src - nh * 
stride, src + 1 - nh * stride,
+   src,
  src + 1,
+   src + ph * stride, src + ph * 
stride, src + 1 + ph * stride};
+
+const uint8_t *coordinatesrb[] = { src + width - 2 - nh * stride, 
src + width - 1 - nh * stride, src + width - 1 - nh * stride,
+   src + width - 2,
  src + width - 1,
+   src + width - 2 + ph * stride, 
src + width - 1 + ph * stride, src + width - 1 + ph * stride};
+
+s->filter(dst, src, 1, threshold, 
coordinateslb, s->coordinates);
+s->filter(dst + 1, src + 1, width - 2, threshold, 
coordinates,   s->coordinates);
+s->filter(dst + width - 1, src + width - 1, 1, threshold, 
coordinatesrb, s->coordinates);
+

[FFmpeg-cvslog] avfilter/vf_neighbor: add slice threading

2018-05-01 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Tue May  1 15:05:43 
2018 +0200| [5bfc433a6ed9ff55ad0a6b0d7745ea74bb0f1d99] | committer: Paul B Mahol

avfilter/vf_neighbor: add slice threading

Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5bfc433a6ed9ff55ad0a6b0d7745ea74bb0f1d99
---

 libavfilter/vf_neighbor.c | 54 +--
 1 file changed, 38 insertions(+), 16 deletions(-)

diff --git a/libavfilter/vf_neighbor.c b/libavfilter/vf_neighbor.c
index 1eb89c208d..12fe4b7ab7 100644
--- a/libavfilter/vf_neighbor.c
+++ b/libavfilter/vf_neighbor.c
@@ -27,6 +27,10 @@
 #include "internal.h"
 #include "video.h"
 
+typedef struct ThreadData {
+AVFrame *in, *out;
+} ThreadData;
+
 typedef struct NContext {
 const AVClass *class;
 int planeheight[4];
@@ -148,36 +152,31 @@ static int config_input(AVFilterLink *inlink)
 return 0;
 }
 
-static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
 {
-AVFilterContext *ctx = inlink->dst;
-AVFilterLink *outlink = ctx->outputs[0];
 NContext *s = ctx->priv;
-AVFrame *out;
+ThreadData *td = arg;
+AVFrame *out = td->out;
+AVFrame *in = td->in;
 int plane, y;
 
-out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
-if (!out) {
-av_frame_free(&in);
-return AVERROR(ENOMEM);
-}
-av_frame_copy_props(out, in);
-
 for (plane = 0; plane < s->nb_planes; plane++) {
 const int threshold = s->threshold[plane];
 const int stride = in->linesize[plane];
 const int dstride = out->linesize[plane];
-const uint8_t *src = in->data[plane];
-uint8_t *dst = out->data[plane];
 const int height = s->planeheight[plane];
 const int width  = s->planewidth[plane];
+const int slice_start = (height * jobnr) / nb_jobs;
+const int slice_end = (height * (jobnr+1)) / nb_jobs;
+const uint8_t *src = (const uint8_t *)in->data[plane] + slice_start * 
stride;
+uint8_t *dst = out->data[plane] + slice_start * dstride;
 
 if (!threshold) {
-av_image_copy_plane(dst, dstride, src, stride, width, height);
+av_image_copy_plane(dst, dstride, src, stride, width, slice_end - 
slice_start);
 continue;
 }
 
-for (y = 0; y < height; y++) {
+for (y = slice_start; y < slice_end; y++) {
 const int nh = y > 0;
 const int ph = y < height - 1;
 const uint8_t *coordinates[] = { src - nh * stride, src + 1 - nh * 
stride, src + 2 - nh * stride,
@@ -201,6 +200,28 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 }
 }
 
+return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+AVFilterContext *ctx = inlink->dst;
+AVFilterLink *outlink = ctx->outputs[0];
+NContext *s = ctx->priv;
+ThreadData td;
+AVFrame *out;
+
+out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+if (!out) {
+av_frame_free(&in);
+return AVERROR(ENOMEM);
+}
+av_frame_copy_props(out, in);
+
+td.in = in;
+td.out = out;
+ctx->internal->execute(ctx, filter_slice, &td, NULL, 
FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx)));
+
 av_frame_free(&in);
 return ff_filter_frame(outlink, out);
 }
@@ -237,7 +258,8 @@ AVFilter ff_vf_##name_ = {  
 \
 .query_formats = query_formats,  \
 .inputs= neighbor_inputs,\
 .outputs   = neighbor_outputs,   \
-.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, \
+.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC| \
+ AVFILTER_FLAG_SLICE_THREADS,\
 }
 
 #if CONFIG_EROSION_FILTER

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


[FFmpeg-cvslog] avfilter/af_biquads: add slice threading

2018-05-01 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Tue May  1 15:40:53 
2018 +0200| [d176497cec95f14aed1db847b2889843ef0843dd] | committer: Paul B Mahol

avfilter/af_biquads: add slice threading

Helps with multi-channels audio. Otherwise use threads=1.

Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d176497cec95f14aed1db847b2889843ef0843dd
---

 libavfilter/af_biquads.c | 52 ++--
 1 file changed, 37 insertions(+), 15 deletions(-)

diff --git a/libavfilter/af_biquads.c b/libavfilter/af_biquads.c
index 804528040d..56d3035d77 100644
--- a/libavfilter/af_biquads.c
+++ b/libavfilter/af_biquads.c
@@ -416,19 +416,50 @@ static int config_output(AVFilterLink *outlink)
 return config_filter(outlink, 1);
 }
 
+typedef struct ThreadData {
+AVFrame *in, *out;
+} ThreadData;
+
+static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+AVFilterLink *inlink = ctx->inputs[0];
+ThreadData *td = arg;
+AVFrame *buf = td->in;
+AVFrame *out_buf = td->out;
+BiquadsContext *s = ctx->priv;
+const int start = (buf->channels * jobnr) / nb_jobs;
+const int end = (buf->channels * (jobnr+1)) / nb_jobs;
+int ch;
+
+for (ch = start; ch < end; ch++) {
+if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & 
s->channels))) {
+if (buf != out_buf)
+memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
+   buf->nb_samples * s->block_align);
+continue;
+}
+
+s->filter(s, buf->extended_data[ch], out_buf->extended_data[ch], 
buf->nb_samples,
+  &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, 
&s->cache[ch].o2,
+  s->b0, s->b1, s->b2, s->a1, s->a2, &s->cache[ch].clippings);
+}
+
+return 0;
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
 {
 AVFilterContext  *ctx = inlink->dst;
 BiquadsContext *s = ctx->priv;
 AVFilterLink *outlink = ctx->outputs[0];
 AVFrame *out_buf;
-int nb_samples = buf->nb_samples;
+ThreadData td;
 int ch;
 
 if (av_frame_is_writable(buf)) {
 out_buf = buf;
 } else {
-out_buf = ff_get_audio_buffer(outlink, nb_samples);
+out_buf = ff_get_audio_buffer(outlink, buf->nb_samples);
 if (!out_buf) {
 av_frame_free(&buf);
 return AVERROR(ENOMEM);
@@ -436,19 +467,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
 av_frame_copy_props(out_buf, buf);
 }
 
-for (ch = 0; ch < buf->channels; ch++) {
-if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & 
s->channels))) {
-if (buf != out_buf)
-memcpy(out_buf->extended_data[ch], buf->extended_data[ch], 
nb_samples * s->block_align);
-continue;
-}
-s->filter(s, buf->extended_data[ch],
-  out_buf->extended_data[ch], nb_samples,
-  &s->cache[ch].i1, &s->cache[ch].i2,
-  &s->cache[ch].o1, &s->cache[ch].o2,
-  s->b0, s->b1, s->b2, s->a1, s->a2,
-  &s->cache[ch].clippings);
-}
+td.in = buf;
+td.out = out_buf;
+ctx->internal->execute(ctx, filter_channel, &td, NULL, 
FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
 
 for (ch = 0; ch < outlink->channels; ch++) {
 if (s->cache[ch].clippings > 0)
@@ -631,6 +652,7 @@ AVFilter ff_af_##name_ = { \
 .outputs   = outputs,\
 .priv_class= &name_##_class, \
 .process_command = process_command,  \
+.flags = AVFILTER_FLAG_SLICE_THREADS,\
 }
 
 #if CONFIG_EQUALIZER_FILTER

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


[FFmpeg-cvslog] avfilter/af_biquads: change clipping detection from global to channel

2018-05-01 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Tue May  1 15:26:20 
2018 +0200| [2308a3c7e37d1b27fd27764a97a75706f53508c2] | committer: Paul B Mahol

avfilter/af_biquads: change clipping detection from global to channel

Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2308a3c7e37d1b27fd27764a97a75706f53508c2
---

 libavfilter/af_biquads.c | 30 +-
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/libavfilter/af_biquads.c b/libavfilter/af_biquads.c
index 9dfc16cef6..804528040d 100644
--- a/libavfilter/af_biquads.c
+++ b/libavfilter/af_biquads.c
@@ -95,6 +95,7 @@ enum WidthType {
 typedef struct ChanCache {
 double i1, i2;
 double o1, o2;
+int clippings;
 } ChanCache;
 
 typedef struct BiquadsContext {
@@ -114,12 +115,11 @@ typedef struct BiquadsContext {
 double b0, b1, b2;
 
 ChanCache *cache;
-int clippings;
 int block_align;
 
 void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int 
len,
double *i1, double *i2, double *o1, double *o2,
-   double b0, double b1, double b2, double a1, double a2);
+   double b0, double b1, double b2, double a1, double a2, int 
*clippings);
 } BiquadsContext;
 
 static av_cold int init(AVFilterContext *ctx)
@@ -176,7 +176,7 @@ static void biquad_## name (BiquadsContext *s,  
  \
 double *in1, double *in2, \
 double *out1, double *out2,   \
 double b0, double b1, double b2,  \
-double a1, double a2) \
+double a1, double a2, int *clippings) \
 { \
 const type *ibuf = input; \
 type *obuf = output;  \
@@ -192,10 +192,10 @@ static void biquad_## name (BiquadsContext *s,
\
 o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1;\
 i2 = ibuf[i]; \
 if (need_clipping && o2 < min) {  \
-s->clippings++;   \
+(*clippings)++;   \
 obuf[i] = min;\
 } else if (need_clipping && o2 > max) {   \
-s->clippings++;   \
+(*clippings)++;   \
 obuf[i] = max;\
 } else {  \
 obuf[i] = o2; \
@@ -204,10 +204,10 @@ static void biquad_## name (BiquadsContext *s,
\
 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1;\
 i1 = ibuf[i]; \
 if (need_clipping && o1 < min) {  \
-s->clippings++;   \
+(*clippings)++;   \
 obuf[i] = min;\
 } else if (need_clipping && o1 > max) {   \
-s->clippings++;   \
+(*clippings)++;   \
 obuf[i] = max;\
 } else {  \
 obuf[i] = o1; \
@@ -220,10 +220,10 @@ static void biquad_## name (BiquadsContext *s,
\
 o2 = o1;  \
 o1 = o0;  \
 if (need_clipping && o0 < min) {  \
-s->clippings++;   \
+(*clippings)++;   \
 obuf[i] = min;\
 } else if (need_clipping && o0 > max) {   \
-s->clippings++;   \
+ 

[FFmpeg-cvslog] avformat/qtpalette: parse color table according to the QuickTime file format specs

2018-05-01 Thread Marton Balint
ffmpeg | branch: release/4.0 | Marton Balint  | Thu Apr 19 
20:11:02 2018 +0200| [da6c519f6e531239c0cc97f0d68d7f8756c6862a] | committer: 
Marton Balint

avformat/qtpalette: parse color table according to the QuickTime file format 
specs

The specs says that the the first color component in the color array is
not alpha, but simply 0.

Fixes 0 alpha of fate-suite/cvid/catfight-cvid-pal8-partial.mov

Signed-off-by: Marton Balint 
(cherry picked from commit c60a824ee87ae3b15ed1cb92b780bec9b642b019)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=da6c519f6e531239c0cc97f0d68d7f8756c6862a
---

 libavformat/qtpalette.c | 12 ++--
 tests/ref/lavf-fate/mov_qtrle_mace6 |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavformat/qtpalette.c b/libavformat/qtpalette.c
index 666c6b7351..6833f0cea9 100644
--- a/libavformat/qtpalette.c
+++ b/libavformat/qtpalette.c
@@ -49,7 +49,7 @@ int ff_get_qtpalette(int codec_id, AVIOContext *pb, uint32_t 
*palette)
 /* If the depth is 1, 2, 4, or 8 bpp, file is palettized. */
 if ((bit_depth == 1 || bit_depth == 2 || bit_depth == 4 || bit_depth == 
8)) {
 uint32_t color_count, color_start, color_end;
-uint32_t a, r, g, b;
+uint32_t r, g, b;
 
 /* Ignore the greyscale bit for 1-bit video and sample
  * descriptions containing a color table. */
@@ -94,17 +94,17 @@ int ff_get_qtpalette(int codec_id, AVIOContext *pb, 
uint32_t *palette)
 color_end = avio_rb16(pb);
 if ((color_start <= 255) && (color_end <= 255)) {
 for (i = color_start; i <= color_end; i++) {
-/* each A, R, G, or B component is 16 bits;
- * only use the top 8 bits */
-a = avio_r8(pb);
-avio_r8(pb);
+/* Each color is made of four unsigned 16 bit integers. The
+ * first integer is 0, the remaining integers are the red,
+ * the green and the blue values. We only use the top 8 
bit. */
+avio_skip(pb, 2);
 r = avio_r8(pb);
 avio_r8(pb);
 g = avio_r8(pb);
 avio_r8(pb);
 b = avio_r8(pb);
 avio_r8(pb);
-palette[i] = (a << 24 ) | (r << 16) | (g << 8) | (b);
+palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | (b);
 }
 }
 }
diff --git a/tests/ref/lavf-fate/mov_qtrle_mace6 
b/tests/ref/lavf-fate/mov_qtrle_mace6
index 30c705ee4c..f8428aaa49 100644
--- a/tests/ref/lavf-fate/mov_qtrle_mace6
+++ b/tests/ref/lavf-fate/mov_qtrle_mace6
@@ -1,3 +1,3 @@
 dcc9c4c182a5809dee9a9366f4533797 *./tests/data/lavf-fate/lavf.mov
 1270387 ./tests/data/lavf-fate/lavf.mov
-./tests/data/lavf-fate/lavf.mov CRC=0x5ec66f68
+./tests/data/lavf-fate/lavf.mov CRC=0x9320cd26

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


[FFmpeg-cvslog] avcodec/hnm4video: fix palette alpha

2018-05-01 Thread Marton Balint
ffmpeg | branch: release/4.0 | Marton Balint  | Mon Apr 23 
20:46:49 2018 +0200| [0a22e31fbbbadcd481ebc702871192c54ecf1ee9] | committer: 
Marton Balint

avcodec/hnm4video: fix palette alpha

Signed-off-by: Marton Balint 
(cherry picked from commit 4c501bafc08c0260c299074d119b85ba39ab334a)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0a22e31fbbbadcd481ebc702871192c54ecf1ee9
---

 libavcodec/hnm4video.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/hnm4video.c b/libavcodec/hnm4video.c
index a64dbb1746..9e1ac49ddc 100644
--- a/libavcodec/hnm4video.c
+++ b/libavcodec/hnm4video.c
@@ -375,6 +375,7 @@ static void hnm_update_palette(AVCodecContext *avctx, 
uint8_t *src,
 hnm->palette[writeoffset] = bytestream2_get_be24(&gb);
 if (!eight_bit_colors)
 hnm->palette[writeoffset] <<= 2;
+hnm->palette[writeoffset] |= (0xFFU << 24);
 count--;
 writeoffset++;
 }

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


[FFmpeg-cvslog] ffplay: Fix realloc_texture when input texture is NULL.

2018-05-01 Thread Matt Oliver
ffmpeg | branch: release/4.0 | Matt Oliver  | Tue Apr 10 
23:01:18 2018 +1000| [29328d96b90fc20048803201b379c6c6a18661b4] | committer: 
Marton Balint

ffplay: Fix realloc_texture when input texture is NULL.

SDL_QueryTexture and SDL_DestroyTexture require that the input texture
pointer be non-null. Debug builds of SDL will correctly check for this
and break program execution. This patch fixes this by checking the
status of the texture pointer.

Signed-off-by: Matt Oliver 
(cherry picked from commit 6be690685a8876a61f87b2b8bf30547e09030a96)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=29328d96b90fc20048803201b379c6c6a18661b4
---

 fftools/ffplay.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index bc9ddb8885..dcca9c26d8 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -834,10 +834,11 @@ static int realloc_texture(SDL_Texture **texture, Uint32 
new_format, int new_wid
 {
 Uint32 format;
 int access, w, h;
-if (SDL_QueryTexture(*texture, &format, &access, &w, &h) < 0 || new_width 
!= w || new_height != h || new_format != format) {
+if (!*texture || SDL_QueryTexture(*texture, &format, &access, &w, &h) < 0 
|| new_width != w || new_height != h || new_format != format) {
 void *pixels;
 int pitch;
-SDL_DestroyTexture(*texture);
+if (*texture)
+SDL_DestroyTexture(*texture);
 if (!(*texture = SDL_CreateTexture(renderer, new_format, 
SDL_TEXTUREACCESS_STREAMING, new_width, new_height)))
 return -1;
 if (SDL_SetTextureBlendMode(*texture, blendmode) < 0)

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


[FFmpeg-cvslog] avcodec/anm: fix palette alpha

2018-05-01 Thread Marton Balint
ffmpeg | branch: release/4.0 | Marton Balint  | Mon Apr 23 
20:46:25 2018 +0200| [70a01aa4901a217a95f32486354844a9496ff849] | committer: 
Marton Balint

avcodec/anm: fix palette alpha

Signed-off-by: Marton Balint 
(cherry picked from commit e894d958fce6f47cbe1e4a5e3f2c74af47057125)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=70a01aa4901a217a95f32486354844a9496ff849
---

 libavcodec/anm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/anm.c b/libavcodec/anm.c
index 72684189bb..ab6a3994e9 100644
--- a/libavcodec/anm.c
+++ b/libavcodec/anm.c
@@ -54,7 +54,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
 bytestream2_skipu(&s->gb, 16 * 8);
 for (i = 0; i < 256; i++)
-s->palette[i] = bytestream2_get_le32u(&s->gb);
+s->palette[i] = (0xFFU << 24) | bytestream2_get_le32u(&s->gb);
 
 return 0;
 }

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


[FFmpeg-cvslog] avdevice/decklink_dec: unref packets on avpacket_queue_put error

2018-05-01 Thread Marton Balint
ffmpeg | branch: release/4.0 | Marton Balint  | Sun Apr 22 
23:09:05 2018 +0200| [d89eea3455862a97963ac0701c51d9a1bdd21f19] | committer: 
Marton Balint

avdevice/decklink_dec: unref packets on avpacket_queue_put error

Signed-off-by: Marton Balint 
(cherry picked from commit 649087fa83a50e04a4ddd7f2f5f740a18ac28902)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d89eea3455862a97963ac0701c51d9a1bdd21f19
---

 libavdevice/decklink_dec.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index e97a4402ea..57004d7b06 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -467,16 +467,19 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket 
*pkt)
 
 // Drop Packet if queue size is > maximum queue size
 if (avpacket_queue_size(q) > (uint64_t)q->max_q_size) {
+av_packet_unref(pkt);
 av_log(q->avctx, AV_LOG_WARNING,  "Decklink input buffer overrun!\n");
 return -1;
 }
 /* ensure the packet is reference counted */
 if (av_packet_make_refcounted(pkt) < 0) {
+av_packet_unref(pkt);
 return -1;
 }
 
 pkt1 = (AVPacketList *)av_malloc(sizeof(AVPacketList));
 if (!pkt1) {
+av_packet_unref(pkt);
 return -1;
 }
 av_packet_move_ref(&pkt1->pkt, pkt);

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


[FFmpeg-cvslog] cbs: Fragment/unit data is always reference counted

2018-05-01 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Tue May  1 00:18:16 
2018 +0100| [d7786b66bdd4b625765eb461ec286b846e94e9f2] | committer: Mark 
Thompson

cbs: Fragment/unit data is always reference counted

Make this clear in the documentation and add some asserts to ensure
that it is always true.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d7786b66bdd4b625765eb461ec286b846e94e9f2
---

 libavcodec/cbs.c | 19 ---
 libavcodec/cbs.h | 10 ++
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index d81b4e03f7..4fd0fa7d5a 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -140,26 +140,30 @@ static int 
cbs_read_fragment_content(CodedBitstreamContext *ctx,
 int err, i, j;
 
 for (i = 0; i < frag->nb_units; i++) {
+CodedBitstreamUnit *unit = &frag->units[i];
+
 if (ctx->decompose_unit_types) {
 for (j = 0; j < ctx->nb_decompose_unit_types; j++) {
-if (ctx->decompose_unit_types[j] == frag->units[i].type)
+if (ctx->decompose_unit_types[j] == unit->type)
 break;
 }
 if (j >= ctx->nb_decompose_unit_types)
 continue;
 }
 
-av_buffer_unref(&frag->units[i].content_ref);
-frag->units[i].content = NULL;
+av_buffer_unref(&unit->content_ref);
+unit->content = NULL;
+
+av_assert0(unit->data && unit->data_ref);
 
-err = ctx->codec->read_unit(ctx, &frag->units[i]);
+err = ctx->codec->read_unit(ctx, unit);
 if (err == AVERROR(ENOSYS)) {
 av_log(ctx->log_ctx, AV_LOG_VERBOSE,
"Decomposition unimplemented for unit %d "
-   "(type %"PRIu32").\n", i, frag->units[i].type);
+   "(type %"PRIu32").\n", i, unit->type);
 } else if (err < 0) {
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d "
-   "(type %"PRIu32").\n", i, frag->units[i].type);
+   "(type %"PRIu32").\n", i, unit->type);
 return err;
 }
 }
@@ -277,6 +281,7 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
"(type %"PRIu32").\n", i, unit->type);
 return err;
 }
+av_assert0(unit->data && unit->data_ref);
 }
 
 av_buffer_unref(&frag->data_ref);
@@ -287,6 +292,7 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to assemble fragment.\n");
 return err;
 }
+av_assert0(frag->data && frag->data_ref);
 
 return 0;
 }
@@ -327,7 +333,6 @@ int ff_cbs_write_packet(CodedBitstreamContext *ctx,
 if (err < 0)
 return err;
 
-av_assert0(frag->data_ref);
 buf = av_buffer_ref(frag->data_ref);
 if (!buf)
 return AVERROR(ENOMEM);
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 402eb39e00..487358afaf 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -84,8 +84,9 @@ typedef struct CodedBitstreamUnit {
  */
 size_t   data_bit_padding;
 /**
- * If data is reference counted, a reference to the buffer containing
- * data.  Null if data is not reference counted.
+ * A reference to the buffer containing data.
+ *
+ * Must be set if data is not NULL.
  */
 AVBufferRef *data_ref;
 
@@ -130,8 +131,9 @@ typedef struct CodedBitstreamFragment {
  */
 size_t data_bit_padding;
 /**
- * If data is reference counted, a reference to the buffer containing
- * data.  Null if data is not reference counted.
+ * A reference to the buffer containing data.
+ *
+ * Must be set if data is not NULL.
  */
 AVBufferRef *data_ref;
 

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


[FFmpeg-cvslog] cbs_h2645: Simplify representation of fixed values

2018-05-01 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Mon Apr 30 22:35:24 
2018 +0100| [315cc8c0988da6e117e4466581bde5480c3abe2a] | committer: Mark 
Thompson

cbs_h2645: Simplify representation of fixed values

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=315cc8c0988da6e117e4466581bde5480c3abe2a
---

 libavcodec/cbs_h2645.c|  5 +
 libavcodec/cbs_h264_syntax_template.c | 30 ---
 libavcodec/cbs_h265_syntax_template.c | 38 +++
 3 files changed, 34 insertions(+), 39 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 5e5598f377..cb050cf073 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -239,6 +239,11 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, 
PutBitContext *pbc,
 #define FUNC_H264(rw, name) FUNC_NAME(rw, h264, name)
 #define FUNC_H265(rw, name) FUNC_NAME(rw, h265, name)
 
+#define fixed(width, name, value) do { \
+av_unused uint32_t fixed_value = value; \
+xu(width, name, fixed_value, value, value); \
+} while (0)
+
 
 #define READ
 #define READWRITE read
diff --git a/libavcodec/cbs_h264_syntax_template.c 
b/libavcodec/cbs_h264_syntax_template.c
index b5cd0b2310..7c507b9a13 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -19,10 +19,10 @@
 static int FUNC(rbsp_trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
 {
 int err;
-av_unused int one = 1, zero = 0;
-xu(1, rbsp_stop_one_bit, one, 1, 1);
+
+fixed(1, rbsp_stop_one_bit, 1);
 while (byte_alignment(rw) != 0)
-xu(1, rbsp_alignment_zero_bit, zero, 0, 0);
+fixed(1, rbsp_alignment_zero_bit, 0);
 
 return 0;
 }
@@ -740,9 +740,8 @@ static int FUNC(sei_payload)(CodedBitstreamContext *ctx, 
RWContext *rw,
 break;
 case H264_SEI_TYPE_FILLER_PAYLOAD:
 {
-av_unused int ff_byte = 0xff;
 for (i = 0; i  < current->payload_size; i++)
-xu(8, ff_byte, ff_byte, 0xff, 0xff);
+fixed(8, ff_byte, 0xff);
 }
 break;
 case H264_SEI_TYPE_USER_DATA_REGISTERED:
@@ -770,10 +769,9 @@ static int FUNC(sei_payload)(CodedBitstreamContext *ctx, 
RWContext *rw,
 }
 
 if (byte_alignment(rw)) {
-av_unused int one = 1, zero = 0;
-xu(1, bit_equal_to_one, one, 1, 1);
+fixed(1, bit_equal_to_one, 1);
 while (byte_alignment(rw))
-xu(1, bit_equal_to_zero, zero, 0, 0);
+fixed(1, bit_equal_to_zero, 0);
 }
 
 #ifdef READ
@@ -810,14 +808,14 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, 
RWContext *rw,
 uint32_t tmp;
 
 while (show_bits(rw, 8) == 0xff) {
-xu(8, ff_byte, tmp, 0xff, 0xff);
+fixed(8, ff_byte, 0xff);
 payload_type += 255;
 }
 xu(8, last_payload_type_byte, tmp, 0, 254);
 payload_type += tmp;
 
 while (show_bits(rw, 8) == 0xff) {
-xu(8, ff_byte, tmp, 0xff, 0xff);
+fixed(8, ff_byte, 0xff);
 payload_size += 255;
 }
 xu(8, last_payload_size_byte, tmp, 0, 254);
@@ -853,14 +851,14 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, 
RWContext *rw,
 
 tmp = current->payload[k].payload_type;
 while (tmp >= 255) {
-xu(8, ff_byte, 0xff, 0xff, 0xff);
+fixed(8, ff_byte, 0xff);
 tmp -= 255;
 }
 xu(8, last_payload_type_byte, tmp, 0, 254);
 
 tmp = current->payload[k].payload_size;
 while (tmp >= 255) {
-xu(8, ff_byte, 0xff, 0xff, 0xff);
+fixed(8, ff_byte, 0xff);
 tmp -= 255;
 }
 xu(8, last_payload_size_byte, tmp, 0, 254);
@@ -1240,9 +1238,8 @@ static int FUNC(slice_header)(CodedBitstreamContext *ctx, 
RWContext *rw,
 }
 
 if (pps->entropy_coding_mode_flag) {
-av_unused int one = 1;
 while (byte_alignment(rw))
-xu(1, cabac_alignment_one_bit, one, 1, 1);
+fixed(1, cabac_alignment_one_bit, 1);
 }
 
 return 0;
@@ -1251,7 +1248,6 @@ static int FUNC(slice_header)(CodedBitstreamContext *ctx, 
RWContext *rw,
 static int FUNC(filler)(CodedBitstreamContext *ctx, RWContext *rw,
 H264RawFiller *current)
 {
-av_unused int ff_byte = 0xff;
 int err;
 
 HEADER("Filler Data");
@@ -1261,14 +1257,14 @@ static int FUNC(filler)(CodedBitstreamContext *ctx, 
RWContext *rw,
 
 #ifdef READ
 while (show_bits(rw, 8) == 0xff) {
-xu(8, ff_byte, ff_byte, 0xff, 0xff);
+fixed(8, ff_byte, 0xff);
 ++current->filler_size;
 }
 #else
 {
 uint32_t i;
 for (i = 0; i < current->filler_size; i++)
-xu(8, ff_byte, ff_byte, 0xff, 0xff);
+fixed(8, ff_byte, 0xff);
 }
 #endif
 
diff --git a/libavcodec/cbs_h265_syntax_template.c 
b/libavc

[FFmpeg-cvslog] lavc: Add coded bitstream read/write support for VP9

2018-05-01 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Thu Jun 22 22:42:51 
2017 +0100| [b5df289eb771e3cd45a5e02b6c3ad05df34df291] | committer: Mark 
Thompson

lavc: Add coded bitstream read/write support for VP9

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b5df289eb771e3cd45a5e02b6c3ad05df34df291
---

 configure|   2 +
 doc/bitstream_filters.texi   |   2 +-
 libavcodec/Makefile  |   1 +
 libavcodec/cbs.c |   6 +
 libavcodec/cbs.h |   1 +
 libavcodec/cbs_internal.h|   1 +
 libavcodec/cbs_vp9.c | 679 +++
 libavcodec/cbs_vp9.h | 201 +++
 libavcodec/cbs_vp9_syntax_template.c | 390 
 9 files changed, 1282 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 0f002dc6eb..57748e1424 100755
--- a/configure
+++ b/configure
@@ -2236,6 +2236,7 @@ CONFIG_EXTRA="
 cbs_h264
 cbs_h265
 cbs_mpeg2
+cbs_vp9
 dirac_parse
 dvprofile
 exif
@@ -2497,6 +2498,7 @@ threads_if_any="$THREADS_LIST"
 cbs_h264_select="cbs golomb"
 cbs_h265_select="cbs golomb"
 cbs_mpeg2_select="cbs"
+cbs_vp9_select="cbs"
 dct_select="rdft"
 dirac_parse_select="golomb"
 error_resilience_select="me_cmp"
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 7322af6550..7f98cb714f 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -505,7 +505,7 @@ Log trace output containing all syntax elements in the 
coded stream
 headers (everything above the level of individual coded blocks).
 This can be useful for debugging low-level stream issues.
 
-Supports H.264, H.265 and MPEG-2.
+Supports H.264, H.265, MPEG-2 and VP9.
 
 @section vp9_superframe
 
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index d727b218dc..15e8c87385 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -65,6 +65,7 @@ OBJS-$(CONFIG_CBS) += cbs.o
 OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o h2645_parse.o
 OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o h2645_parse.o
 OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
+OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o
 OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
 OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o
 OBJS-$(CONFIG_ERROR_RESILIENCE)+= error_resilience.o
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index dd46d09f42..be6c043b58 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -38,6 +38,9 @@ static const CodedBitstreamType *cbs_type_table[] = {
 #if CONFIG_CBS_MPEG2
 &ff_cbs_type_mpeg2,
 #endif
+#if CONFIG_CBS_VP9
+&ff_cbs_type_vp9,
+#endif
 };
 
 const enum AVCodecID ff_cbs_all_codec_ids[] = {
@@ -50,6 +53,9 @@ const enum AVCodecID ff_cbs_all_codec_ids[] = {
 #if CONFIG_CBS_MPEG2
 AV_CODEC_ID_MPEG2VIDEO,
 #endif
+#if CONFIG_CBS_VP9
+AV_CODEC_ID_VP9,
+#endif
 AV_CODEC_ID_NONE
 };
 
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 487358afaf..53ac360bb1 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -48,6 +48,7 @@ struct CodedBitstreamType;
  * H.264 / AVC: nal_unit_type
  * H.265 / HEVC: nal_unit_type
  * MPEG-2: start code value (without prefix)
+ * VP9: unused, set to zero (every unit is a frame)
  */
 typedef uint32_t CodedBitstreamUnitType;
 
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 3280e7602d..172b8a2515 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -89,6 +89,7 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, 
PutBitContext *pbc,
 extern const CodedBitstreamType ff_cbs_type_h264;
 extern const CodedBitstreamType ff_cbs_type_h265;
 extern const CodedBitstreamType ff_cbs_type_mpeg2;
+extern const CodedBitstreamType ff_cbs_type_vp9;
 
 
 #endif /* AVCODEC_CBS_INTERNAL_H */
diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c
new file mode 100644
index 00..7498be4b73
--- /dev/null
+++ b/libavcodec/cbs_vp9.c
@@ -0,0 +1,679 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/avassert.h"
+
+#include "cbs.h"
+#include "cbs_internal.h"
+#include "cbs_vp9.h"
+#include "internal.h"
+
+
+stat

[FFmpeg-cvslog] lavc: Add VP9 metadata bitstream filter

2018-05-01 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Mon Apr  2 02:38:03 
2018 +0100| [308b989e0cf14d5b33b7d4cd546a94230a1423c2] | committer: Mark 
Thompson

lavc: Add VP9 metadata bitstream filter

Can adjust the colour information.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=308b989e0cf14d5b33b7d4cd546a94230a1423c2
---

 configure  |   1 +
 doc/bitstream_filters.texi |  26 +++
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/vp9_metadata_bsf.c  | 162 +
 5 files changed, 191 insertions(+)

diff --git a/configure b/configure
index 57748e1424..7f199c634d 100755
--- a/configure
+++ b/configure
@@ -2989,6 +2989,7 @@ hevc_metadata_bsf_select="cbs_h265"
 mjpeg2jpeg_bsf_select="jpegtables"
 mpeg2_metadata_bsf_select="cbs_mpeg2"
 trace_headers_bsf_select="cbs"
+vp9_metadata_bsf_select="cbs_vp9"
 
 # external libraries
 aac_at_decoder_deps="audiotoolbox"
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 7f98cb714f..7d7e97503a 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -507,6 +507,32 @@ This can be useful for debugging low-level stream issues.
 
 Supports H.264, H.265, MPEG-2 and VP9.
 
+@section vp9_metadata
+
+Modify metadata embedded in a VP9 stream.
+
+@table @option
+@item color_space
+Set the color space value in the frame header.
+@table @samp
+@item unknown
+@item bt601
+@item bt709
+@item smpte170
+@item smpte240
+@item bt2020
+@item rgb
+@end table
+
+@item color_range
+Set the color range value in the frame header.  Note that this cannot
+be set in RGB streams.
+@table @samp
+@item tv
+@item pc
+@end table
+@end table
+
 @section vp9_superframe
 
 Merge VP9 invisible (alt-ref) frames back into VP9 superframes. This
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 15e8c87385..663bdce4e4 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1066,6 +1066,7 @@ OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
 OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
 OBJS-$(CONFIG_TRACE_HEADERS_BSF)  += trace_headers_bsf.o
+OBJS-$(CONFIG_VP9_METADATA_BSF)   += vp9_metadata_bsf.o
 OBJS-$(CONFIG_VP9_RAW_REORDER_BSF)+= vp9_raw_reorder_bsf.o
 OBJS-$(CONFIG_VP9_SUPERFRAME_BSF) += vp9_superframe_bsf.o
 OBJS-$(CONFIG_VP9_SUPERFRAME_SPLIT_BSF)   += vp9_superframe_split_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 18b698a85f..c21373621c 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -49,6 +49,7 @@ extern const AVBitStreamFilter ff_null_bsf;
 extern const AVBitStreamFilter ff_remove_extradata_bsf;
 extern const AVBitStreamFilter ff_text2movsub_bsf;
 extern const AVBitStreamFilter ff_trace_headers_bsf;
+extern const AVBitStreamFilter ff_vp9_metadata_bsf;
 extern const AVBitStreamFilter ff_vp9_raw_reorder_bsf;
 extern const AVBitStreamFilter ff_vp9_superframe_bsf;
 extern const AVBitStreamFilter ff_vp9_superframe_split_bsf;
diff --git a/libavcodec/vp9_metadata_bsf.c b/libavcodec/vp9_metadata_bsf.c
new file mode 100644
index 00..be010edc3f
--- /dev/null
+++ b/libavcodec/vp9_metadata_bsf.c
@@ -0,0 +1,162 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/avstring.h"
+#include "libavutil/common.h"
+#include "libavutil/opt.h"
+
+#include "bsf.h"
+#include "cbs.h"
+#include "cbs_vp9.h"
+
+typedef struct VP9MetadataContext {
+const AVClass *class;
+
+CodedBitstreamContext *cbc;
+CodedBitstreamFragment fragment;
+
+int color_space;
+int color_range;
+
+int color_range_rgb_warned;
+} VP9MetadataContext;
+
+
+static int vp9_metadata_filter(AVBSFContext *bsf, AVPacket *out)
+{
+VP9MetadataContext *ctx = bsf->priv_data;
+AVPacket *in = NULL;
+CodedBitstreamFragment *frag = &ctx->fragment;
+int err, i;
+
+err = ff_bsf_get_packet(bsf, &in);
+if (err < 0)
+return err;
+
+err = ff_cbs_read_packet(ctx->cbc, frag, in);
+if (err < 0) {
+av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
+goto fail;
+}
+
+for (i = 0; i < 

[FFmpeg-cvslog] cbs: Add support for array subscripts in trace output

2018-05-01 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Mon Apr 30 22:35:30 
2018 +0100| [300ef253141fbebf9b201de676db1bb9e4298c40] | committer: Mark 
Thompson

cbs: Add support for array subscripts in trace output

This makes the trace output for arrays significantly nicer.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=300ef253141fbebf9b201de676db1bb9e4298c40
---

 libavcodec/cbs.c   |  44 ++--
 libavcodec/cbs_h2645.c |  83 ---
 libavcodec/cbs_h264_syntax_template.c  | 101 +--
 libavcodec/cbs_h265_syntax_template.c  | 179 +
 libavcodec/cbs_internal.h  |  10 +-
 libavcodec/cbs_mpeg2.c |  25 ++---
 libavcodec/cbs_mpeg2_syntax_template.c |  25 ++---
 7 files changed, 261 insertions(+), 206 deletions(-)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 4fd0fa7d5a..dd46d09f42 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -356,17 +356,43 @@ void ff_cbs_trace_header(CodedBitstreamContext *ctx,
 }
 
 void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position,
- const char *name, const char *bits,
- int64_t value)
+ const char *str, const int *subscripts,
+ const char *bits, int64_t value)
 {
+char name[256];
 size_t name_len, bits_len;
-int pad;
+int pad, subs, i, j, k, n;
 
 if (!ctx->trace_enable)
 return;
 
 av_assert0(value >= INT_MIN && value <= UINT32_MAX);
 
+subs = subscripts ? subscripts[0] : 0;
+n = 0;
+for (i = j = 0; str[i];) {
+if (str[i] == '[') {
+if (n < subs) {
+++n;
+k = snprintf(name + j, sizeof(name) - j, "[%d", subscripts[n]);
+av_assert0(k > 0 && j + k < sizeof(name));
+j += k;
+for (++i; str[i] && str[i] != ']'; i++);
+av_assert0(str[i] == ']');
+} else {
+while (str[i] && str[i] != ']')
+name[j++] = str[i++];
+av_assert0(str[i] == ']');
+}
+} else {
+av_assert0(j + 1 < sizeof(name));
+name[j++] = str[i++];
+}
+}
+av_assert0(j + 1 < sizeof(name));
+name[j] = 0;
+av_assert0(n == subs);
+
 name_len = strlen(name);
 bits_len = strlen(bits);
 
@@ -380,7 +406,8 @@ void ff_cbs_trace_syntax_element(CodedBitstreamContext 
*ctx, int position,
 }
 
 int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
- int width, const char *name, uint32_t *write_to,
+ int width, const char *name,
+ const int *subscripts, uint32_t *write_to,
  uint32_t range_min, uint32_t range_max)
 {
 uint32_t value;
@@ -406,7 +433,8 @@ int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, 
GetBitContext *gbc,
 bits[i] = value >> (width - i - 1) & 1 ? '1' : '0';
 bits[i] = 0;
 
-ff_cbs_trace_syntax_element(ctx, position, name, bits, value);
+ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
+bits, value);
 }
 
 if (value < range_min || value > range_max) {
@@ -421,7 +449,8 @@ int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, 
GetBitContext *gbc,
 }
 
 int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
-  int width, const char *name, uint32_t value,
+  int width, const char *name,
+  const int *subscripts, uint32_t value,
   uint32_t range_min, uint32_t range_max)
 {
 av_assert0(width > 0 && width <= 32);
@@ -443,7 +472,8 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, 
PutBitContext *pbc,
 bits[i] = value >> (width - i - 1) & 1 ? '1' : '0';
 bits[i] = 0;
 
-ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc), name, bits, 
value);
+ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc),
+name, subscripts, bits, value);
 }
 
 if (width < 32)
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index cb050cf073..64a1a2d1ee 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -32,7 +32,8 @@
 
 
 static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
-  const char *name, uint32_t *write_to,
+  const char *name, const int *subscripts,
+  uint32_t *write_to,
   uint32_t range_min, uint32_t range_max)
 {
 uint32_t value;
@@ -68,7 +69,8 @@ static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, 
GetBitContext *gbc,
 --value;
 
 if (ctx->trace_enable)
-ff_cbs_trace_synta

[FFmpeg-cvslog] lavc/cbs: Add tests for VP9

2018-05-01 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sat Apr  7 18:57:37 
2018 +0100| [ddd3a209dc5a535a4fca7fadd532e767651bd372] | committer: Mark 
Thompson

lavc/cbs: Add tests for VP9

Uses the same mechanism as other codecs - conformance test files are
passed through the metadata filter (which, with no options, reads the
input and writes it back) and the output verified to match the input.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ddd3a209dc5a535a4fca7fadd532e767651bd372
---

 tests/fate/cbs.mak | 34 ++
 tests/ref/fate/cbs-vp9-vp90-2-03-deltaq|  1 +
 tests/ref/fate/cbs-vp9-vp90-2-05-resize|  1 +
 tests/ref/fate/cbs-vp9-vp90-2-06-bilinear  |  1 +
 tests/ref/fate/cbs-vp9-vp90-2-09-lf_deltas |  1 +
 .../ref/fate/cbs-vp9-vp90-2-10-show-existing-frame |  1 +
 .../fate/cbs-vp9-vp90-2-10-show-existing-frame2|  1 +
 .../ref/fate/cbs-vp9-vp90-2-segmentation-aq-akiyo  |  1 +
 .../ref/fate/cbs-vp9-vp90-2-segmentation-sf-akiyo  |  1 +
 tests/ref/fate/cbs-vp9-vp90-2-tiling-pedestrian|  1 +
 tests/ref/fate/cbs-vp9-vp91-2-04-yuv440|  1 +
 tests/ref/fate/cbs-vp9-vp91-2-04-yuv444|  1 +
 tests/ref/fate/cbs-vp9-vp92-2-20-10bit-yuv420  |  1 +
 tests/ref/fate/cbs-vp9-vp93-2-20-10bit-yuv422  |  1 +
 tests/ref/fate/cbs-vp9-vp93-2-20-12bit-yuv444  |  1 +
 15 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/tests/fate/cbs.mak b/tests/fate/cbs.mak
index fc5967e6f3..0f773abd05 100644
--- a/tests/fate/cbs.mak
+++ b/tests/fate/cbs.mak
@@ -2,9 +2,9 @@
 # arguments, it decomposes the stream fully and then recomposes it
 # without making any changes.
 
-fate-cbs: fate-cbs-h264 fate-cbs-hevc fate-cbs-mpeg2
+fate-cbs: fate-cbs-h264 fate-cbs-hevc fate-cbs-mpeg2 fate-cbs-vp9
 
-FATE_CBS_DEPS = $(call ALLYES, $(1)_DEMUXER $(1)_PARSER $(2)_METADATA_BSF 
$(3)_DECODER $(3)_MUXER)
+FATE_CBS_DEPS = $(call ALLYES, $(1)_DEMUXER $(2)_PARSER $(3)_METADATA_BSF 
$(4)_DECODER $(5)_MUXER)
 
 define FATE_CBS_TEST
 # (codec, test_name, sample_file, output_format)
@@ -32,7 +32,7 @@ FATE_CBS_H264_SAMPLES =   \
 
 $(foreach N,$(FATE_CBS_H264_SAMPLES),$(eval $(call 
FATE_CBS_TEST,h264,$(basename $(N)),h264-conformance/$(N),h264)))
 
-FATE_CBS_H264-$(call FATE_CBS_DEPS, H264, H264, H264) = $(FATE_CBS_h264)
+FATE_CBS_H264-$(call FATE_CBS_DEPS, H264, H264, H264, H264, H264) = 
$(FATE_CBS_h264)
 FATE_SAMPLES_AVCONV += $(FATE_CBS_H264-yes)
 fate-cbs-h264: $(FATE_CBS_H264-yes)
 
@@ -61,7 +61,7 @@ FATE_CBS_HEVC_SAMPLES =   \
 
 $(foreach N,$(FATE_CBS_HEVC_SAMPLES),$(eval $(call 
FATE_CBS_TEST,hevc,$(basename $(N)),hevc-conformance/$(N),hevc)))
 
-FATE_CBS_HEVC-$(call FATE_CBS_DEPS, HEVC, HEVC, HEVC) = $(FATE_CBS_hevc)
+FATE_CBS_HEVC-$(call FATE_CBS_DEPS, HEVC, HEVC, HEVC, HEVC, HEVC) = 
$(FATE_CBS_hevc)
 FATE_SAMPLES_AVCONV += $(FATE_CBS_HEVC-yes)
 fate-cbs-hevc: $(FATE_CBS_HEVC-yes)
 
@@ -74,6 +74,30 @@ FATE_CBS_MPEG2_SAMPLES = \
 
 $(foreach N,$(FATE_CBS_MPEG2_SAMPLES),$(eval $(call 
FATE_CBS_TEST,mpeg2,$(basename $(N)),mpeg2/$(N),mpeg2video)))
 
-FATE_CBS_MPEG2-$(call FATE_CBS_DEPS, MPEGVIDEO, MPEG2, MPEG2VIDEO) = 
$(FATE_CBS_mpeg2)
+FATE_CBS_MPEG2-$(call FATE_CBS_DEPS, MPEGVIDEO, MPEGVIDEO, MPEG2, MPEG2VIDEO, 
MPEG2VIDEO) = $(FATE_CBS_mpeg2)
 FATE_SAMPLES_AVCONV += $(FATE_CBS_MPEG2-yes)
 fate-cbs-mpeg2: $(FATE_CBS_MPEG2-yes)
+
+# VP9 read/write
+
+FATE_CBS_VP9_SAMPLES =  \
+vp90-2-03-deltaq.webm   \
+vp90-2-05-resize.ivf\
+vp90-2-06-bilinear.webm \
+vp90-2-09-lf_deltas.webm\
+vp90-2-10-show-existing-frame.webm  \
+vp90-2-10-show-existing-frame2.webm \
+vp90-2-segmentation-aq-akiyo.webm   \
+vp90-2-segmentation-sf-akiyo.webm   \
+vp90-2-tiling-pedestrian.webm   \
+vp91-2-04-yuv440.webm   \
+vp91-2-04-yuv444.webm   \
+vp92-2-20-10bit-yuv420.webm \
+vp93-2-20-10bit-yuv422.webm \
+vp93-2-20-12bit-yuv444.webm
+
+$(foreach N,$(FATE_CBS_VP9_SAMPLES),$(eval $(call FATE_CBS_TEST,vp9,$(basename 
$(N)),vp9-test-vectors/$(N),ivf)))
+
+FATE_CBS_VP9-$(call FATE_CBS_DEPS, IVF, VP9, VP9, VP9, IVF) = $(FATE_CBS_vp9)
+FATE_SAMPLES_AVCONV += $(FATE_CBS_VP9-yes)
+fate-cbs-vp9: $(FATE_CBS_VP9-yes)
diff --git a/tests/ref/fate/cbs-vp9-vp90-2-03-deltaq 
b/tests/ref/fate/cbs-vp9-vp90-2-03-deltaq
new file mode 100644
index 00..db09cfd5e0
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp90-2-03-deltaq
@@ -0,0 +1 @@
+bb630ef560f83951fa6547a664fdb636
diff --git a/tests/ref/fate/cbs-vp9-vp90-2-05-resize 
b/tests/ref/fate/cbs-vp9-vp90-2-05-resize
new file mode 100644
index 00..8f036bba81
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp90-2-05-resize
@@ -0,0 +1 @@
+6838422ebb45df353a2bad62b9aff8e9
diff --git a/tests/ref/fate/cbs-vp9-vp90-2-06-bilinear 
b/tests/ref/fate/cbs-vp9-vp90-2-06-bilinear
new file mode 100644
index 00..f579459179
--- /dev/nu

[FFmpeg-cvslog] fate/cbs: Always overwrite output in cbs fate tests

2018-05-01 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Wed May  2 00:46:04 
2018 +0100| [e07b1913fc67b9244d82d49d2ab3cd661215c928] | committer: Mark 
Thompson

fate/cbs: Always overwrite output in cbs fate tests

Before this, a failed test would keep failing because the output file
is not cleaned up and subsequent runs would refuse to overwrite it.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e07b1913fc67b9244d82d49d2ab3cd661215c928
---

 tests/fate/cbs.mak | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/fate/cbs.mak b/tests/fate/cbs.mak
index 0f773abd05..bee349ed45 100644
--- a/tests/fate/cbs.mak
+++ b/tests/fate/cbs.mak
@@ -9,7 +9,7 @@ FATE_CBS_DEPS = $(call ALLYES, $(1)_DEMUXER $(2)_PARSER 
$(3)_METADATA_BSF $(4)_D
 define FATE_CBS_TEST
 # (codec, test_name, sample_file, output_format)
 FATE_CBS_$(1) += fate-cbs-$(1)-$(2)
-fate-cbs-$(1)-$(2): CMD = md5 -i $(TARGET_SAMPLES)/$(3) -c:v copy -bsf:v 
$(1)_metadata -f $(4)
+fate-cbs-$(1)-$(2): CMD = md5 -i $(TARGET_SAMPLES)/$(3) -c:v copy -y -bsf:v 
$(1)_metadata -f $(4)
 endef
 
 # H.264 read/write

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