ffmpeg-cvslog
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
May 2018
- 2 participants
- 330 discussions
02 May '18
ffmpeg | branch: master | Paul B Mahol <onemda(a)gmail.com> | Wed May 2 19:23:41 2018 +0200| [ab1114a0f5b32d91e7f56dc1183087a33a96153c] | committer: Paul B Mahol
avfilter/vf_convolution: rewrite so it doesn't use temp buffers
Signed-off-by: Paul B Mahol <onemda(a)gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ab1114a0f5b32d91e…
---
libavfilter/vf_convolution.c | 969 ++++++++++++-------------------------------
1 file changed, 261 insertions(+), 708 deletions(-)
diff --git a/libavfilter/vf_convolution.c b/libavfilter/vf_convolution.c
index e9b1f4abe8..026b881873 100644
--- a/libavfilter/vf_convolution.c
+++ b/libavfilter/vf_convolution.c
@@ -21,6 +21,7 @@
#include "libavutil/avstring.h"
#include "libavutil/imgutils.h"
+#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
@@ -40,10 +41,8 @@ typedef struct ConvolutionContext {
int size[4];
int depth;
+ int max;
int bpc;
- int bstride;
- uint8_t *buffer;
- uint8_t **bptrs;
int nb_planes;
int nb_threads;
int planewidth[4];
@@ -52,7 +51,11 @@ typedef struct ConvolutionContext {
int matrix_length[4];
int copy[4];
- int (*filter[4])(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
+ void (*setup[4])(const uint8_t *c[], const uint8_t *src, int stride,
+ int x, int width, int y, int height, int bpc);
+ void (*filter[4])(uint8_t *dst, const uint8_t *src, int width,
+ float rdiv, float bias, const int *const matrix,
+ const uint8_t *c[], int peak);
} ConvolutionContext;
#define OFFSET(x) offsetof(ConvolutionContext, x)
@@ -120,743 +123,314 @@ static int query_formats(AVFilterContext *ctx)
return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
}
-static inline void line_copy8(uint8_t *line, const uint8_t *srcp, int width, int mergin)
+typedef struct ThreadData {
+ AVFrame *in, *out;
+} ThreadData;
+
+static void filter16_prewitt(uint8_t *dstp, const uint8_t *src, int width,
+ float scale, float delta, const int *const matrix,
+ const uint8_t *c[], int peak)
{
- int i;
+ uint16_t *dst = (uint16_t *)dstp;
+ int x;
- memcpy(line, srcp, width);
+ for (x = 0; x < width; x++) {
+ int suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * -1 +
+ AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) * 1 + AV_RN16A(&c[8][2 * x]) * 1;
+ int sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -1 +
+ AV_RN16A(&c[5][2 * x]) * 1 + AV_RN16A(&c[6][2 * x]) * -1 + AV_RN16A(&c[8][2 * x]) * 1;
- for (i = mergin; i > 0; i--) {
- line[-i] = line[i];
- line[width - 1 + i] = line[width - 1 - i];
+ dst[x] = av_clip(sqrt(suma*suma + sumb*sumb) * scale + delta, 0, peak);
}
}
-static inline void line_copy16(uint16_t *line, const uint16_t *srcp, int width, int mergin)
+static void filter16_roberts(uint8_t *dstp, const uint8_t *src, int width,
+ float scale, float delta, const int *const matrix,
+ const uint8_t *c[], int peak)
{
- int i;
+ uint16_t *dst = (uint16_t *)dstp;
+ int x;
- memcpy(line, srcp, width * 2);
+ for (x = 0; x < width; x++) {
+ int suma = AV_RN16A(&c[0][2 * x]) * 1 + AV_RN16A(&c[4][2 * x]) * -1;
+ int sumb = AV_RN16A(&c[1][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -1;
- for (i = mergin; i > 0; i--) {
- line[-i] = line[i];
- line[width - 1 + i] = line[width - 1 - i];
+ dst[x] = av_clip(sqrt(suma*suma + sumb*sumb) * scale + delta, 0, peak);
}
}
-typedef struct ThreadData {
- AVFrame *in, *out;
- int plane;
-} ThreadData;
-
-static int filter16_prewitt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static void filter16_sobel(uint8_t *dstp, const uint8_t *src, int width,
+ float scale, float delta, const int *const matrix,
+ const uint8_t *c[], int peak)
{
- ConvolutionContext *s = ctx->priv;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
- const int plane = td->plane;
- const int peak = (1 << s->depth) - 1;
- const int stride = in->linesize[plane] / 2;
- const int bstride = s->bstride;
- 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 uint16_t *src = (const uint16_t *)in->data[plane] + slice_start * stride;
- uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * (out->linesize[plane] / 2);
- const float scale = s->scale;
- const float delta = s->delta;
- uint16_t *p0 = (uint16_t *)s->bptrs[jobnr] + 16;
- uint16_t *p1 = p0 + bstride;
- uint16_t *p2 = p1 + bstride;
- uint16_t *orig = p0, *end = p2;
- int y, x;
-
- line_copy16(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
- line_copy16(p1, src, width, 1);
-
- for (y = slice_start; y < slice_end; y++) {
- src += stride * (y < height - 1 ? 1 : -1);
- line_copy16(p2, src, width, 1);
-
- for (x = 0; x < width; x++) {
- int suma = p0[x - 1] * -1 +
- p0[x] * -1 +
- p0[x + 1] * -1 +
- p2[x - 1] * 1 +
- p2[x] * 1 +
- p2[x + 1] * 1;
- int sumb = p0[x - 1] * -1 +
- p0[x + 1] * 1 +
- p1[x - 1] * -1 +
- p1[x + 1] * 1 +
- p2[x - 1] * -1 +
- p2[x + 1] * 1;
-
- dst[x] = av_clip(sqrt(suma*suma + sumb*sumb) * scale + delta, 0, peak);
- }
+ uint16_t *dst = (uint16_t *)dstp;
+ int x;
- p0 = p1;
- p1 = p2;
- p2 = (p2 == end) ? orig: p2 + bstride;
- dst += out->linesize[plane] / 2;
- }
+ for (x = 0; x < width; x++) {
+ int suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * -2 + AV_RN16A(&c[2][2 * x]) * -1 +
+ AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) * 2 + AV_RN16A(&c[8][2 * x]) * 1;
+ int sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -2 +
+ AV_RN16A(&c[5][2 * x]) * 2 + AV_RN16A(&c[6][2 * x]) * -1 + AV_RN16A(&c[8][2 * x]) * 1;
- return 0;
+ dst[x] = av_clip(sqrt(suma*suma + sumb*sumb) * scale + delta, 0, peak);
+ }
}
-static int filter16_roberts(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static void filter_prewitt(uint8_t *dst, const uint8_t *src, int width,
+ float scale, float delta, const int *const matrix,
+ const uint8_t *c[], int peak)
{
- ConvolutionContext *s = ctx->priv;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
- const int plane = td->plane;
- const int peak = (1 << s->depth) - 1;
- const int stride = in->linesize[plane] / 2;
- const int bstride = s->bstride;
- 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 uint16_t *src = (const uint16_t *)in->data[plane] + slice_start * stride;
- uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * (out->linesize[plane] / 2);
- const float scale = s->scale;
- const float delta = s->delta;
- uint16_t *p0 = (uint16_t *)s->bptrs[jobnr] + 16;
- uint16_t *p1 = p0 + bstride;
- uint16_t *p2 = p1 + bstride;
- uint16_t *orig = p0, *end = p2;
- int y, x;
-
- line_copy16(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
- line_copy16(p1, src, width, 1);
-
- for (y = slice_start; y < slice_end; y++) {
- src += stride * (y < height - 1 ? 1 : -1);
- line_copy16(p2, src, width, 1);
-
- for (x = 0; x < width; x++) {
- int suma = p0[x - 1] * 1 +
- p1[x ] * -1;
- int sumb = p0[x ] * 1 +
- p1[x - 1] * -1;
-
- dst[x] = av_clip(sqrt(suma*suma + sumb*sumb) * scale + delta, 0, peak);
- }
-
- p0 = p1;
- p1 = p2;
- p2 = (p2 == end) ? orig: p2 + bstride;
- dst += out->linesize[plane] / 2;
+ const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
+ const uint8_t *c3 = c[3], *c5 = c[5];
+ const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
+ int x;
+
+ for (x = 0; x < width; x++) {
+ int suma = c0[x] * -1 + c1[x] * -1 + c2[x] * -1 +
+ c6[x] * 1 + c7[x] * 1 + c8[x] * 1;
+ int sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -1 +
+ c5[x] * 1 + c6[x] * -1 + c8[x] * 1;
+
+ dst[x] = av_clip_uint8(sqrt(suma*suma + sumb*sumb) * scale + delta);
}
-
- return 0;
}
-static int filter16_sobel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static void filter_roberts(uint8_t *dst, const uint8_t *src, int width,
+ float scale, float delta, const int *const matrix,
+ const uint8_t *c[], int peak)
{
- ConvolutionContext *s = ctx->priv;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
- const int plane = td->plane;
- const int peak = (1 << s->depth) - 1;
- const int stride = in->linesize[plane] / 2;
- const int bstride = s->bstride;
- 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 uint16_t *src = (const uint16_t *)in->data[plane] + slice_start * stride;
- uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * (out->linesize[plane] / 2);
- const float scale = s->scale;
- const float delta = s->delta;
- uint16_t *p0 = (uint16_t *)s->bptrs[jobnr] + 16;
- uint16_t *p1 = p0 + bstride;
- uint16_t *p2 = p1 + bstride;
- uint16_t *orig = p0, *end = p2;
- int y, x;
-
- line_copy16(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
- line_copy16(p1, src, width, 1);
-
- for (y = slice_start; y < slice_end; y++) {
- src += stride * (y < height - 1 ? 1 : -1);
- line_copy16(p2, src, width, 1);
-
- for (x = 0; x < width; x++) {
- int suma = p0[x - 1] * -1 +
- p0[x] * -2 +
- p0[x + 1] * -1 +
- p2[x - 1] * 1 +
- p2[x] * 2 +
- p2[x + 1] * 1;
- int sumb = p0[x - 1] * -1 +
- p0[x + 1] * 1 +
- p1[x - 1] * -2 +
- p1[x + 1] * 2 +
- p2[x - 1] * -1 +
- p2[x + 1] * 1;
-
- dst[x] = av_clip(sqrt(suma*suma + sumb*sumb) * scale + delta, 0, peak);
- }
+ int x;
- p0 = p1;
- p1 = p2;
- p2 = (p2 == end) ? orig: p2 + bstride;
- dst += out->linesize[plane] / 2;
- }
+ for (x = 0; x < width; x++) {
+ int suma = c[0][x - 1] * 1 + c[4][x ] * -1;
+ int sumb = c[1][x ] * 1 + c[3][x - 1] * -1;
- return 0;
+ dst[x] = av_clip_uint8(sqrt(suma*suma + sumb*sumb) * scale + delta);
+ }
}
-static int filter_prewitt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static void filter_sobel(uint8_t *dst, const uint8_t *src, int width,
+ float scale, float delta, const int *const matrix,
+ const uint8_t *c[], int peak)
{
- ConvolutionContext *s = ctx->priv;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
- const int plane = td->plane;
- const int stride = in->linesize[plane];
- const int bstride = s->bstride;
- 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 = in->data[plane] + slice_start * stride;
- uint8_t *dst = out->data[plane] + slice_start * out->linesize[plane];
- const float scale = s->scale;
- const float delta = s->delta;
- uint8_t *p0 = s->bptrs[jobnr] + 16;
- uint8_t *p1 = p0 + bstride;
- uint8_t *p2 = p1 + bstride;
- uint8_t *orig = p0, *end = p2;
- int y, x;
-
- line_copy8(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
- line_copy8(p1, src, width, 1);
-
- for (y = slice_start; y < slice_end; y++) {
- src += stride * (y < height - 1 ? 1 : -1);
- line_copy8(p2, src, width, 1);
-
- for (x = 0; x < width; x++) {
- int suma = p0[x - 1] * -1 +
- p0[x] * -1 +
- p0[x + 1] * -1 +
- p2[x - 1] * 1 +
- p2[x] * 1 +
- p2[x + 1] * 1;
- int sumb = p0[x - 1] * -1 +
- p0[x + 1] * 1 +
- p1[x - 1] * -1 +
- p1[x + 1] * 1 +
- p2[x - 1] * -1 +
- p2[x + 1] * 1;
-
- dst[x] = av_clip_uint8(sqrt(suma*suma + sumb*sumb) * scale + delta);
- }
-
- p0 = p1;
- p1 = p2;
- p2 = (p2 == end) ? orig: p2 + bstride;
- dst += out->linesize[plane];
+ const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
+ const uint8_t *c3 = c[3], *c5 = c[5];
+ const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
+ int x;
+
+ for (x = 0; x < width; x++) {
+ int suma = c0[x] * -1 + c1[x] * -2 + c2[x] * -1 +
+ c6[x] * 1 + c7[x] * 2 + c8[x] * 1;
+ int sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -2 +
+ c5[x] * 2 + c6[x] * -1 + c8[x] * 1;
+
+ dst[x] = av_clip_uint8(sqrt(suma*suma + sumb*sumb) * scale + delta);
}
+}
- return 0;
+static void filter16_3x3(uint8_t *dstp, const uint8_t *src, int width,
+ float rdiv, float bias, const int *const matrix,
+ const uint8_t *c[], int peak)
+{
+ uint16_t *dst = (uint16_t *)dstp;
+ int x;
+
+ for (x = 0; x < width; x++) {
+ int sum = AV_RN16A(&c[0][2 * x]) * matrix[0] +
+ AV_RN16A(&c[1][2 * x]) * matrix[1] +
+ AV_RN16A(&c[2][2 * x]) * matrix[2] +
+ AV_RN16A(&c[3][2 * x]) * matrix[3] +
+ AV_RN16A(&c[4][2 * x]) * matrix[4] +
+ AV_RN16A(&c[5][2 * x]) * matrix[5] +
+ AV_RN16A(&c[6][2 * x]) * matrix[6] +
+ AV_RN16A(&c[7][2 * x]) * matrix[7] +
+ AV_RN16A(&c[8][2 * x]) * matrix[8];
+ sum = (int)(sum * rdiv + bias + 0.5f);
+ dst[x] = av_clip(sum, 0, peak);
+ }
}
-static int filter_roberts(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static void filter16_5x5(uint8_t *dstp, const uint8_t *src, int width,
+ float rdiv, float bias, const int *const matrix,
+ const uint8_t *c[], int peak)
{
- ConvolutionContext *s = ctx->priv;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
- const int plane = td->plane;
- const int stride = in->linesize[plane];
- const int bstride = s->bstride;
- 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 = in->data[plane] + slice_start * stride;
- uint8_t *dst = out->data[plane] + slice_start * out->linesize[plane];
- const float scale = s->scale;
- const float delta = s->delta;
- uint8_t *p0 = s->bptrs[jobnr] + 16;
- uint8_t *p1 = p0 + bstride;
- uint8_t *p2 = p1 + bstride;
- uint8_t *orig = p0, *end = p2;
- int y, x;
-
- line_copy8(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
- line_copy8(p1, src, width, 1);
-
- for (y = slice_start; y < slice_end; y++) {
- src += stride * (y < height - 1 ? 1 : -1);
- line_copy8(p2, src, width, 1);
-
- for (x = 0; x < width; x++) {
- int suma = p0[x - 1] * 1 +
- p1[x ] * -1;
- int sumb = p0[x ] * 1 +
- p1[x - 1] * -1;
-
- dst[x] = av_clip_uint8(sqrt(suma*suma + sumb*sumb) * scale + delta);
- }
+ uint16_t *dst = (uint16_t *)dstp;
+ int x;
- p0 = p1;
- p1 = p2;
- p2 = (p2 == end) ? orig: p2 + bstride;
- dst += out->linesize[plane];
- }
+ for (x = 0; x < width; x++) {
+ int i, sum = 0;
- return 0;
+ for (i = 0; i < 25; i++)
+ sum += AV_RN16A(&c[i][2 * x]) * matrix[i];
+
+ sum = (int)(sum * rdiv + bias + 0.5f);
+ dst[x] = av_clip(sum, 0, peak);
+ }
}
-static int filter_sobel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static void filter16_7x7(uint8_t *dstp, const uint8_t *src, int width,
+ float rdiv, float bias, const int *const matrix,
+ const uint8_t *c[], int peak)
{
- ConvolutionContext *s = ctx->priv;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
- const int plane = td->plane;
- const int stride = in->linesize[plane];
- const int bstride = s->bstride;
- 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 = in->data[plane] + slice_start * stride;
- uint8_t *dst = out->data[plane] + slice_start * out->linesize[plane];
- const float scale = s->scale;
- const float delta = s->delta;
- uint8_t *p0 = s->bptrs[jobnr] + 16;
- uint8_t *p1 = p0 + bstride;
- uint8_t *p2 = p1 + bstride;
- uint8_t *orig = p0, *end = p2;
- int y, x;
-
- line_copy8(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
- line_copy8(p1, src, width, 1);
-
- for (y = slice_start; y < slice_end; y++) {
- src += stride * (y < height - 1 ? 1 : -1);
- line_copy8(p2, src, width, 1);
-
- for (x = 0; x < width; x++) {
- int suma = p0[x - 1] * -1 +
- p0[x] * -2 +
- p0[x + 1] * -1 +
- p2[x - 1] * 1 +
- p2[x] * 2 +
- p2[x + 1] * 1;
- int sumb = p0[x - 1] * -1 +
- p0[x + 1] * 1 +
- p1[x - 1] * -2 +
- p1[x + 1] * 2 +
- p2[x - 1] * -1 +
- p2[x + 1] * 1;
-
- dst[x] = av_clip_uint8(sqrt(suma*suma + sumb*sumb) * scale + delta);
- }
+ uint16_t *dst = (uint16_t *)dstp;
+ int x;
- p0 = p1;
- p1 = p2;
- p2 = (p2 == end) ? orig: p2 + bstride;
- dst += out->linesize[plane];
- }
+ for (x = 0; x < width; x++) {
+ int i, sum = 0;
- return 0;
+ for (i = 0; i < 49; i++)
+ sum += AV_RN16A(&c[i][2 * x]) * matrix[i];
+
+ sum = (int)(sum * rdiv + bias + 0.5f);
+ dst[x] = av_clip(sum, 0, peak);
+ }
}
-static int filter16_3x3(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static void filter_7x7(uint8_t *dst, const uint8_t *src, int width,
+ float rdiv, float bias, const int *const matrix,
+ const uint8_t *c[], int peak)
{
- ConvolutionContext *s = ctx->priv;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
- const int plane = td->plane;
- const int peak = (1 << s->depth) - 1;
- const int stride = in->linesize[plane] / 2;
- const int bstride = s->bstride;
- 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 uint16_t *src = (const uint16_t *)in->data[plane] + slice_start * stride;
- uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * (out->linesize[plane] / 2);
- uint16_t *p0 = (uint16_t *)s->bptrs[jobnr] + 16;
- uint16_t *p1 = p0 + bstride;
- uint16_t *p2 = p1 + bstride;
- uint16_t *orig = p0, *end = p2;
- const int *matrix = s->matrix[plane];
- const float rdiv = s->rdiv[plane];
- const float bias = s->bias[plane];
- int y, x;
-
- line_copy16(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
- line_copy16(p1, src, width, 1);
-
- for (y = slice_start; y < slice_end; y++) {
- src += stride * (y < height - 1 ? 1 : -1);
- line_copy16(p2, src, width, 1);
-
- for (x = 0; x < width; x++) {
- int sum = p0[x - 1] * matrix[0] +
- p0[x] * matrix[1] +
- p0[x + 1] * matrix[2] +
- p1[x - 1] * matrix[3] +
- p1[x] * matrix[4] +
- p1[x + 1] * matrix[5] +
- p2[x - 1] * matrix[6] +
- p2[x] * matrix[7] +
- p2[x + 1] * matrix[8];
- sum = (int)(sum * rdiv + bias + 0.5f);
- dst[x] = av_clip(sum, 0, peak);
- }
+ int x;
- p0 = p1;
- p1 = p2;
- p2 = (p2 == end) ? orig: p2 + bstride;
- dst += out->linesize[plane] / 2;
- }
+ for (x = 0; x < width; x++) {
+ int i, sum = 0;
- return 0;
+ for (i = 0; i < 49; i++)
+ sum += c[i][x] * matrix[i];
+
+ sum = (int)(sum * rdiv + bias + 0.5f);
+ dst[x] = av_clip_uint8(sum);
+ }
}
-static int filter16_5x5(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static void filter_5x5(uint8_t *dst, const uint8_t *src, int width,
+ float rdiv, float bias, const int *const matrix,
+ const uint8_t *c[], int peak)
{
- ConvolutionContext *s = ctx->priv;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
- const int plane = td->plane;
- const int peak = (1 << s->depth) - 1;
- const int stride = in->linesize[plane] / 2;
- const int bstride = s->bstride;
- 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 uint16_t *src = (const uint16_t *)in->data[plane] + slice_start * stride;
- uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * (out->linesize[plane] / 2);
- uint16_t *p0 = (uint16_t *)s->bptrs[jobnr] + 16;
- uint16_t *p1 = p0 + bstride;
- uint16_t *p2 = p1 + bstride;
- uint16_t *p3 = p2 + bstride;
- uint16_t *p4 = p3 + bstride;
- uint16_t *orig = p0, *end = p4;
- const int *matrix = s->matrix[plane];
- float rdiv = s->rdiv[plane];
- float bias = s->bias[plane];
- int y, x, i;
-
- line_copy16(p0, src + 2 * stride * (slice_start < 2 ? 1 : -1), width, 2);
- line_copy16(p1, src + stride * (slice_start == 0 ? 1 : -1), width, 2);
- line_copy16(p2, src, width, 2);
- src += stride;
- line_copy16(p3, src, width, 2);
-
- for (y = slice_start; y < slice_end; y++) {
- uint16_t *array[] = {
- p0 - 2, p0 - 1, p0, p0 + 1, p0 + 2,
- p1 - 2, p1 - 1, p1, p1 + 1, p1 + 2,
- p2 - 2, p2 - 1, p2, p2 + 1, p2 + 2,
- p3 - 2, p3 - 1, p3, p3 + 1, p3 + 2,
- p4 - 2, p4 - 1, p4, p4 + 1, p4 + 2
- };
-
- src += stride * (y < height - 2 ? 1 : -1);
- line_copy16(p4, src, width, 2);
-
- for (x = 0; x < width; x++) {
- int sum = 0;
-
- for (i = 0; i < 25; i++) {
- sum += *(array[i] + x) * matrix[i];
- }
- sum = (int)(sum * rdiv + bias + 0.5f);
- dst[x] = av_clip(sum, 0, peak);
- }
+ int x;
+
+ for (x = 0; x < width; x++) {
+ int i, sum = 0;
- p0 = p1;
- p1 = p2;
- p2 = p3;
- p3 = p4;
- p4 = (p4 == end) ? orig: p4 + bstride;
- dst += out->linesize[plane] / 2;
+ for (i = 0; i < 25; i++)
+ sum += c[i][x] * matrix[i];
+
+ sum = (int)(sum * rdiv + bias + 0.5f);
+ dst[x] = av_clip_uint8(sum);
}
+}
- return 0;
+static void filter_3x3(uint8_t *dst, const uint8_t *src, int width,
+ float rdiv, float bias, const int *const matrix,
+ const uint8_t *c[], int peak)
+{
+ const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
+ const uint8_t *c3 = c[3], *c4 = c[4], *c5 = c[5];
+ const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
+ int x;
+
+ for (x = 0; x < width; x++) {
+ int sum = c0[x] * matrix[0] + c1[x] * matrix[1] + c2[x] * matrix[2] +
+ c3[x] * matrix[3] + c4[x] * matrix[4] + c5[x] * matrix[5] +
+ c6[x] * matrix[6] + c7[x] * matrix[7] + c8[x] * matrix[8];
+ sum = (int)(sum * rdiv + bias + 0.5f);
+ dst[x] = av_clip_uint8(sum);
+ }
}
-static int filter16_7x7(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static void setup_3x3(const uint8_t *c[], const uint8_t *src, int stride,
+ int x, int w, int y, int h, int bpc)
{
- ConvolutionContext *s = ctx->priv;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
- const int plane = td->plane;
- const int peak = (1 << s->depth) - 1;
- const int stride = in->linesize[plane] / 2;
- const int bstride = s->bstride;
- 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 uint16_t *src = (const uint16_t *)in->data[plane] + slice_start * stride;
- uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * (out->linesize[plane] / 2);
- uint16_t *p0 = (uint16_t *)s->bptrs[jobnr] + 32;
- uint16_t *p1 = p0 + bstride;
- uint16_t *p2 = p1 + bstride;
- uint16_t *p3 = p2 + bstride;
- uint16_t *p4 = p3 + bstride;
- uint16_t *p5 = p4 + bstride;
- uint16_t *p6 = p5 + bstride;
- uint16_t *orig = p0, *end = p6;
- const int *matrix = s->matrix[plane];
- float rdiv = s->rdiv[plane];
- float bias = s->bias[plane];
- int y, x, i;
-
- line_copy16(p0, src + 3 * stride * (slice_start < 3 ? 1 : -1), width, 3);
- line_copy16(p1, src + 2 * stride * (slice_start < 2 ? 1 : -1), width, 3);
- line_copy16(p2, src + stride * (slice_start == 0 ? 1 : -1), width, 3);
- line_copy16(p3, src, width, 3);
- src += stride;
- line_copy16(p4, src, width, 3);
- src += stride;
- line_copy16(p5, src, width, 3);
-
- for (y = slice_start; y < slice_end; y++) {
- uint16_t *array[] = {
- p0 - 3, p0 - 2, p0 - 1, p0, p0 + 1, p0 + 2, p0 + 3,
- p1 - 3, p1 - 2, p1 - 1, p1, p1 + 1, p1 + 2, p1 + 3,
- p2 - 3, p2 - 2, p2 - 1, p2, p2 + 1, p2 + 2, p2 + 3,
- p3 - 3, p3 - 2, p3 - 1, p3, p3 + 1, p3 + 2, p3 + 3,
- p4 - 3, p4 - 2, p4 - 1, p4, p4 + 1, p4 + 2, p4 + 3,
- p5 - 3, p5 - 2, p5 - 1, p5, p5 + 1, p5 + 2, p5 + 3,
- p6 - 3, p6 - 2, p6 - 1, p6, p6 + 1, p6 + 2, p6 + 3,
- };
-
- src += stride * (y < height - 3 ? 1 : -1);
- line_copy16(p6, src, width, 3);
-
- for (x = 0; x < width; x++) {
- int sum = 0;
-
- for (i = 0; i < 25; i++) {
- sum += *(array[i] + x) * matrix[i];
- }
- sum = (int)(sum * rdiv + bias + 0.5f);
- dst[x] = av_clip(sum, 0, peak);
- }
+ int i;
- p0 = p1;
- p1 = p2;
- p2 = p3;
- p3 = p4;
- p4 = p5;
- p5 = p6;
- p6 = (p6 == end) ? orig: p6 + bstride;
- dst += out->linesize[plane] / 2;
- }
+ for (i = 0; i < 9; i++) {
+ int xoff = FFABS(x + ((i % 3) - 1));
+ int yoff = FFABS(y + (i / 3) - 1);
- return 0;
+ xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
+ yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
+
+ c[i] = src + xoff * bpc + yoff * stride;
+ }
}
-static int filter_3x3(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static void setup_5x5(const uint8_t *c[], const uint8_t *src, int stride,
+ int x, int w, int y, int h, int bpc)
{
- ConvolutionContext *s = ctx->priv;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
- const int plane = td->plane;
- const int stride = in->linesize[plane];
- const int bstride = s->bstride;
- 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 = in->data[plane] + slice_start * stride;
- uint8_t *dst = out->data[plane] + slice_start * out->linesize[plane];
- uint8_t *p0 = s->bptrs[jobnr] + 16;
- uint8_t *p1 = p0 + bstride;
- uint8_t *p2 = p1 + bstride;
- uint8_t *orig = p0, *end = p2;
- const int *matrix = s->matrix[plane];
- const float rdiv = s->rdiv[plane];
- const float bias = s->bias[plane];
- int y, x;
-
- line_copy8(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
- line_copy8(p1, src, width, 1);
-
- for (y = slice_start; y < slice_end; y++) {
- src += stride * (y < height - 1 ? 1 : -1);
- line_copy8(p2, src, width, 1);
-
- for (x = 0; x < width; x++) {
- int sum = p0[x - 1] * matrix[0] +
- p0[x] * matrix[1] +
- p0[x + 1] * matrix[2] +
- p1[x - 1] * matrix[3] +
- p1[x] * matrix[4] +
- p1[x + 1] * matrix[5] +
- p2[x - 1] * matrix[6] +
- p2[x] * matrix[7] +
- p2[x + 1] * matrix[8];
- sum = (int)(sum * rdiv + bias + 0.5f);
- dst[x] = av_clip_uint8(sum);
- }
+ int i;
- p0 = p1;
- p1 = p2;
- p2 = (p2 == end) ? orig: p2 + bstride;
- dst += out->linesize[plane];
- }
+ for (i = 0; i < 25; i++) {
+ int xoff = FFABS(x + ((i % 5) - 2));
+ int yoff = FFABS(y + (i / 5) - 2);
- return 0;
+ xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
+ yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
+
+ c[i] = src + xoff * bpc + yoff * stride;
+ }
}
-static int filter_5x5(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static void setup_7x7(const uint8_t *c[], const uint8_t *src, int stride,
+ int x, int w, int y, int h, int bpc)
{
- ConvolutionContext *s = ctx->priv;
- ThreadData *td = arg;
- AVFrame *in = td->in;
- AVFrame *out = td->out;
- const int plane = td->plane;
- const int stride = in->linesize[plane];
- const int bstride = s->bstride;
- 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 = in->data[plane] + slice_start * stride;
- uint8_t *dst = out->data[plane] + slice_start * out->linesize[plane];
- uint8_t *p0 = s->bptrs[jobnr] + 16;
- uint8_t *p1 = p0 + bstride;
- uint8_t *p2 = p1 + bstride;
- uint8_t *p3 = p2 + bstride;
- uint8_t *p4 = p3 + bstride;
- uint8_t *orig = p0, *end = p4;
- const int *matrix = s->matrix[plane];
- float rdiv = s->rdiv[plane];
- float bias = s->bias[plane];
- int y, x, i;
-
- line_copy8(p0, src + 2 * stride * (slice_start < 2 ? 1 : -1), width, 2);
- line_copy8(p1, src + stride * (slice_start == 0 ? 1 : -1), width, 2);
- line_copy8(p2, src, width, 2);
- src += stride;
- line_copy8(p3, src, width, 2);
-
-
- for (y = slice_start; y < slice_end; y++) {
- uint8_t *array[] = {
- p0 - 2, p0 - 1, p0, p0 + 1, p0 + 2,
- p1 - 2, p1 - 1, p1, p1 + 1, p1 + 2,
- p2 - 2, p2 - 1, p2, p2 + 1, p2 + 2,
- p3 - 2, p3 - 1, p3, p3 + 1, p3 + 2,
- p4 - 2, p4 - 1, p4, p4 + 1, p4 + 2
- };
-
- src += stride * (y < height - 2 ? 1 : -1);
- line_copy8(p4, src, width, 2);
-
- for (x = 0; x < width; x++) {
- int sum = 0;
-
- for (i = 0; i < 25; i++) {
- sum += *(array[i] + x) * matrix[i];
- }
- sum = (int)(sum * rdiv + bias + 0.5f);
- dst[x] = av_clip_uint8(sum);
- }
+ int i;
- p0 = p1;
- p1 = p2;
- p2 = p3;
- p3 = p4;
- p4 = (p4 == end) ? orig: p4 + bstride;
- dst += out->linesize[plane];
- }
+ for (i = 0; i < 49; i++) {
+ int xoff = FFABS(x + ((i % 7) - 3));
+ int yoff = FFABS(y + (i / 7) - 3);
- return 0;
+ xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
+ yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
+
+ c[i] = src + xoff * bpc + yoff * stride;
+ }
}
-static int filter_7x7(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
ConvolutionContext *s = ctx->priv;
ThreadData *td = arg;
AVFrame *in = td->in;
AVFrame *out = td->out;
- const int plane = td->plane;
- const int stride = in->linesize[plane];
- const int bstride = s->bstride;
- 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 = in->data[plane] + slice_start * stride;
- uint8_t *dst = out->data[plane] + slice_start * out->linesize[plane];
- uint8_t *p0 = s->bptrs[jobnr] + 32;
- uint8_t *p1 = p0 + bstride;
- uint8_t *p2 = p1 + bstride;
- uint8_t *p3 = p2 + bstride;
- uint8_t *p4 = p3 + bstride;
- uint8_t *p5 = p4 + bstride;
- uint8_t *p6 = p5 + bstride;
- uint8_t *orig = p0, *end = p6;
- const int *matrix = s->matrix[plane];
- float rdiv = s->rdiv[plane];
- float bias = s->bias[plane];
- int y, x, i;
-
- line_copy8(p0, src + 3 * stride * (slice_start < 3 ? 1 : -1), width, 3);
- line_copy8(p1, src + 2 * stride * (slice_start < 2 ? 1 : -1), width, 3);
- line_copy8(p2, src + stride * (slice_start == 0 ? 1 : -1), width, 3);
- line_copy8(p3, src, width, 3);
- src += stride;
- line_copy8(p4, src, width, 3);
- src += stride;
- line_copy8(p5, src, width, 3);
-
- for (y = slice_start; y < slice_end; y++) {
- uint8_t *array[] = {
- p0 - 3, p0 - 2, p0 - 1, p0, p0 + 1, p0 + 2, p0 + 3,
- p1 - 3, p1 - 2, p1 - 1, p1, p1 + 1, p1 + 2, p1 + 3,
- p2 - 3, p2 - 2, p2 - 1, p2, p2 + 1, p2 + 2, p2 + 3,
- p3 - 3, p3 - 2, p3 - 1, p3, p3 + 1, p3 + 2, p3 + 3,
- p4 - 3, p4 - 2, p4 - 1, p4, p4 + 1, p4 + 2, p4 + 3,
- p5 - 3, p5 - 2, p5 - 1, p5, p5 + 1, p5 + 2, p5 + 3,
- p6 - 3, p6 - 2, p6 - 1, p6, p6 + 1, p6 + 2, p6 + 3,
- };
-
- src += stride * (y < height - 3 ? 1 : -1);
- line_copy8(p6, src, width, 3);
-
- for (x = 0; x < width; x++) {
- int sum = 0;
-
- for (i = 0; i < 49; i++) {
- sum += *(array[i] + x) * matrix[i];
- }
- sum = (int)(sum * rdiv + bias + 0.5f);
- dst[x] = av_clip_uint8(sum);
+ int plane;
+
+ for (plane = 0; plane < s->nb_planes; plane++) {
+ const int radius = s->size[plane] / 2;
+ const int height = s->planeheight[plane];
+ const int width = s->planewidth[plane];
+ const int stride = in->linesize[plane];
+ const int dstride = out->linesize[plane];
+ const int slice_start = (height * jobnr) / nb_jobs;
+ const int slice_end = (height * (jobnr+1)) / nb_jobs;
+ const float rdiv = s->rdiv[plane];
+ const float bias = s->bias[plane];
+ const uint8_t *src = in->data[plane];
+ uint8_t *dst = out->data[plane] + slice_start * out->linesize[plane];
+ const int *matrix = s->matrix[plane];
+ const int bpc = s->bpc;
+ const uint8_t *c[49];
+ int y, x;
+
+ if (s->copy[plane]) {
+ av_image_copy_plane(dst, dstride, src + slice_start * stride, stride,
+ width * bpc, slice_end - slice_start);
+ continue;
}
- p0 = p1;
- p1 = p2;
- p2 = p3;
- p3 = p4;
- p4 = p5;
- p5 = p6;
- p6 = (p6 == end) ? orig: p6 + bstride;
- dst += out->linesize[plane];
+ for (y = slice_start; y < slice_end; y++) {
+ for (x = 0; x < radius; x++) {
+ s->setup[plane](c, src, stride, x, width, y, height, bpc);
+ s->filter[plane](dst + x * bpc, src, 1, rdiv, bias, matrix, c, s->max);
+ }
+ s->setup[plane](c, src, stride, radius, width, y, height, bpc);
+ s->filter[plane](dst + radius * bpc, src, width - 2 * radius,
+ rdiv, bias, matrix, c, s->max);
+ for (x = width - radius; x < width; x++) {
+ s->setup[plane](c, src, stride, x, width, y, height, bpc);
+ s->filter[plane](dst + x * bpc, src, 1, rdiv, bias, matrix, c, s->max);
+ }
+ dst += dstride;
+ }
}
return 0;
@@ -870,6 +444,7 @@ static int config_input(AVFilterLink *inlink)
int p;
s->depth = desc->comp[0].depth;
+ s->max = (1 << s->depth) - 1;
s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
s->planewidth[0] = s->planewidth[3] = inlink->w;
@@ -878,19 +453,7 @@ static int config_input(AVFilterLink *inlink)
s->nb_planes = av_pix_fmt_count_planes(inlink->format);
s->nb_threads = ff_filter_get_nb_threads(ctx);
- s->bptrs = av_calloc(s->nb_threads, sizeof(*s->bptrs));
- if (!s->bptrs)
- return AVERROR(ENOMEM);
-
- s->bstride = s->planewidth[0] + 64;
s->bpc = (s->depth + 7) / 8;
- s->buffer = av_malloc_array(7 * s->bstride * s->nb_threads, s->bpc);
- if (!s->buffer)
- return AVERROR(ENOMEM);
-
- for (p = 0; p < s->nb_threads; p++) {
- s->bptrs[p] = s->buffer + 7 * s->bstride * s->bpc * p;
- }
if (!strcmp(ctx->filter->name, "convolution")) {
if (s->depth > 8) {
@@ -926,7 +489,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
ConvolutionContext *s = ctx->priv;
AVFilterLink *outlink = ctx->outputs[0];
AVFrame *out;
- int plane;
+ ThreadData td;
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
if (!out) {
@@ -935,22 +498,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
}
av_frame_copy_props(out, in);
- for (plane = 0; plane < s->nb_planes; plane++) {
- ThreadData td;
-
- if (s->copy[plane]) {
- av_image_copy_plane(out->data[plane], out->linesize[plane],
- in->data[plane], in->linesize[plane],
- s->planewidth[plane] * s->bpc,
- s->planeheight[plane]);
- continue;
- }
-
- td.in = in;
- td.out = out;
- td.plane = plane;
- ctx->internal->execute(ctx, s->filter[plane], &td, NULL, FFMIN(s->planeheight[plane], s->nb_threads));
- }
+ td.in = in;
+ td.out = out;
+ ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(s->planeheight[1], s->nb_threads));
av_frame_free(&in);
return ff_filter_frame(outlink, out);
@@ -984,18 +534,21 @@ static av_cold int init(AVFilterContext *ctx)
s->copy[i] = 1;
else
s->filter[i] = filter_3x3;
+ s->setup[i] = setup_3x3;
} else if (s->matrix_length[i] == 25) {
s->size[i] = 5;
if (!memcmp(matrix, same5x5, sizeof(same5x5)))
s->copy[i] = 1;
else
s->filter[i] = filter_5x5;
+ s->setup[i] = setup_5x5;
} else if (s->matrix_length[i] == 49) {
s->size[i] = 7;
if (!memcmp(matrix, same7x7, sizeof(same7x7)))
s->copy[i] = 1;
else
s->filter[i] = filter_7x7;
+ s->setup[i] = setup_7x7;
} else {
return AVERROR(EINVAL);
}
@@ -1014,6 +567,10 @@ static av_cold int init(AVFilterContext *ctx)
s->filter[i] = filter_prewitt;
else
s->copy[i] = 1;
+ s->size[i] = 3;
+ s->setup[i] = setup_3x3;
+ s->rdiv[i] = s->scale;
+ s->bias[i] = s->delta;
}
} else if (!strcmp(ctx->filter->name, "roberts")) {
for (i = 0; i < 4; i++) {
@@ -1021,6 +578,10 @@ static av_cold int init(AVFilterContext *ctx)
s->filter[i] = filter_roberts;
else
s->copy[i] = 1;
+ s->size[i] = 3;
+ s->setup[i] = setup_3x3;
+ s->rdiv[i] = s->scale;
+ s->bias[i] = s->delta;
}
} else if (!strcmp(ctx->filter->name, "sobel")) {
for (i = 0; i < 4; i++) {
@@ -1028,20 +589,16 @@ static av_cold int init(AVFilterContext *ctx)
s->filter[i] = filter_sobel;
else
s->copy[i] = 1;
+ s->size[i] = 3;
+ s->setup[i] = setup_3x3;
+ s->rdiv[i] = s->scale;
+ s->bias[i] = s->delta;
}
}
return 0;
}
-static av_cold void uninit(AVFilterContext *ctx)
-{
- ConvolutionContext *s = ctx->priv;
-
- av_freep(&s->bptrs);
- av_freep(&s->buffer);
-}
-
static const AVFilterPad convolution_inputs[] = {
{
.name = "default",
@@ -1068,7 +625,6 @@ AVFilter ff_vf_convolution = {
.priv_size = sizeof(ConvolutionContext),
.priv_class = &convolution_class,
.init = init,
- .uninit = uninit,
.query_formats = query_formats,
.inputs = convolution_inputs,
.outputs = convolution_outputs,
@@ -1094,7 +650,6 @@ AVFilter ff_vf_prewitt = {
.priv_size = sizeof(ConvolutionContext),
.priv_class = &prewitt_class,
.init = init,
- .uninit = uninit,
.query_formats = query_formats,
.inputs = convolution_inputs,
.outputs = convolution_outputs,
@@ -1120,7 +675,6 @@ AVFilter ff_vf_sobel = {
.priv_size = sizeof(ConvolutionContext),
.priv_class = &sobel_class,
.init = init,
- .uninit = uninit,
.query_formats = query_formats,
.inputs = convolution_inputs,
.outputs = convolution_outputs,
@@ -1146,7 +700,6 @@ AVFilter ff_vf_roberts = {
.priv_size = sizeof(ConvolutionContext),
.priv_class = &roberts_class,
.init = init,
- .uninit = uninit,
.query_formats = query_formats,
.inputs = convolution_inputs,
.outputs = convolution_outputs,
1
0
ffmpeg | branch: master | Paul B Mahol <onemda(a)gmail.com> | Mon Apr 30 12:01:07 2018 +0200| [6d7c63588c81ba61b75701702b8680bd0063f36c] | committer: Paul B Mahol
avfilter/vf_overlay: add x86 SIMD
Specifically for yuv444, yuv422, yuv420 format when main stream has no alpha, and alpha
is straight.
Signed-off-by: Paul B Mahol <onemda(a)gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6d7c63588c81ba61b…
---
libavfilter/vf_overlay.c | 75 +++++---------------
libavfilter/vf_overlay.h | 85 ++++++++++++++++++++++
libavfilter/x86/Makefile | 2 +
libavfilter/x86/vf_overlay.asm | 144 ++++++++++++++++++++++++++++++++++++++
libavfilter/x86/vf_overlay_init.c | 63 +++++++++++++++++
5 files changed, 313 insertions(+), 56 deletions(-)
diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index 8c1895cca4..c4d87306f1 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -39,6 +39,7 @@
#include "drawutils.h"
#include "framesync.h"
#include "video.h"
+#include "vf_overlay.h"
typedef struct ThreadData {
AVFrame *dst, *src;
@@ -59,21 +60,6 @@ static const char *const var_names[] = {
NULL
};
-enum var_name {
- VAR_MAIN_W, VAR_MW,
- VAR_MAIN_H, VAR_MH,
- VAR_OVERLAY_W, VAR_OW,
- VAR_OVERLAY_H, VAR_OH,
- VAR_HSUB,
- VAR_VSUB,
- VAR_X,
- VAR_Y,
- VAR_N,
- VAR_POS,
- VAR_T,
- VAR_VARS_NB
-};
-
#define MAIN 0
#define OVERLAY 1
@@ -92,45 +78,6 @@ enum EvalMode {
EVAL_MODE_NB
};
-enum OverlayFormat {
- OVERLAY_FORMAT_YUV420,
- OVERLAY_FORMAT_YUV422,
- OVERLAY_FORMAT_YUV444,
- OVERLAY_FORMAT_RGB,
- OVERLAY_FORMAT_GBRP,
- OVERLAY_FORMAT_AUTO,
- OVERLAY_FORMAT_NB
-};
-
-typedef struct OverlayContext {
- const AVClass *class;
- int x, y; ///< position of overlaid picture
-
- uint8_t main_is_packed_rgb;
- uint8_t main_rgba_map[4];
- uint8_t main_has_alpha;
- uint8_t overlay_is_packed_rgb;
- uint8_t overlay_rgba_map[4];
- uint8_t overlay_has_alpha;
- int format; ///< OverlayFormat
- int alpha_format;
- int eval_mode; ///< EvalMode
-
- FFFrameSync fs;
-
- int main_pix_step[4]; ///< steps per pixel for each plane of the main output
- int overlay_pix_step[4]; ///< steps per pixel for each plane of the overlay
- int hsub, vsub; ///< chroma subsampling values
- const AVPixFmtDescriptor *main_desc; ///< format descriptor for main input
-
- double var_values[VAR_VARS_NB];
- char *x_expr, *y_expr;
-
- AVExpr *x_pexpr, *y_pexpr;
-
- int (*blend_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
-} OverlayContext;
-
static av_cold void uninit(AVFilterContext *ctx)
{
OverlayContext *s = ctx->priv;
@@ -509,6 +456,7 @@ static av_always_inline void blend_plane(AVFilterContext *ctx,
int jobnr,
int nb_jobs)
{
+ OverlayContext *octx = ctx->priv;
int src_wp = AV_CEIL_RSHIFT(src_w, hsub);
int src_hp = AV_CEIL_RSHIFT(src_h, vsub);
int dst_wp = AV_CEIL_RSHIFT(dst_w, hsub);
@@ -538,8 +486,18 @@ static av_always_inline void blend_plane(AVFilterContext *ctx,
s = sp + k;
a = ap + (k<<hsub);
da = dap + ((xp+k) << hsub);
+ kmax = FFMIN(-xp + dst_wp, src_wp);
+
+ if (((vsub && j+1 < src_hp) || !vsub) && octx->blend_row[i]) {
+ int c = octx->blend_row[i](d, da, s, a, kmax - k, src->linesize[3]);
- for (kmax = FFMIN(-xp + dst_wp, src_wp); k < kmax; k++) {
+ s += c;
+ d += dst_step * c;
+ da += (1 << hsub) * c;
+ a += (1 << hsub) * c;
+ k += c;
+ }
+ for (; k < kmax; k++) {
int alpha_v, alpha_h, alpha;
// average alpha for color components, improve quality
@@ -916,7 +874,7 @@ static int config_input_main(AVFilterLink *inlink)
}
if (!s->alpha_format)
- return 0;
+ goto end;
switch (s->format) {
case OVERLAY_FORMAT_YUV420:
@@ -960,6 +918,11 @@ static int config_input_main(AVFilterLink *inlink)
}
break;
}
+
+end:
+ if (ARCH_X86)
+ ff_overlay_init_x86(s, s->format, s->alpha_format, s->main_has_alpha);
+
return 0;
}
diff --git a/libavfilter/vf_overlay.h b/libavfilter/vf_overlay.h
new file mode 100644
index 0000000000..072ece358f
--- /dev/null
+++ b/libavfilter/vf_overlay.h
@@ -0,0 +1,85 @@
+/*
+ * 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
+ */
+
+#ifndef AVFILTER_OVERLAY_H
+#define AVFILTER_OVERLAY_H
+
+#include "libavutil/eval.h"
+#include "libavutil/pixdesc.h"
+#include "framesync.h"
+#include "avfilter.h"
+
+enum var_name {
+ VAR_MAIN_W, VAR_MW,
+ VAR_MAIN_H, VAR_MH,
+ VAR_OVERLAY_W, VAR_OW,
+ VAR_OVERLAY_H, VAR_OH,
+ VAR_HSUB,
+ VAR_VSUB,
+ VAR_X,
+ VAR_Y,
+ VAR_N,
+ VAR_POS,
+ VAR_T,
+ VAR_VARS_NB
+};
+
+enum OverlayFormat {
+ OVERLAY_FORMAT_YUV420,
+ OVERLAY_FORMAT_YUV422,
+ OVERLAY_FORMAT_YUV444,
+ OVERLAY_FORMAT_RGB,
+ OVERLAY_FORMAT_GBRP,
+ OVERLAY_FORMAT_AUTO,
+ OVERLAY_FORMAT_NB
+};
+
+typedef struct OverlayContext {
+ const AVClass *class;
+ int x, y; ///< position of overlaid picture
+
+ uint8_t main_is_packed_rgb;
+ uint8_t main_rgba_map[4];
+ uint8_t main_has_alpha;
+ uint8_t overlay_is_packed_rgb;
+ uint8_t overlay_rgba_map[4];
+ uint8_t overlay_has_alpha;
+ int format; ///< OverlayFormat
+ int alpha_format;
+ int eval_mode; ///< EvalMode
+
+ FFFrameSync fs;
+
+ int main_pix_step[4]; ///< steps per pixel for each plane of the main output
+ int overlay_pix_step[4]; ///< steps per pixel for each plane of the overlay
+ int hsub, vsub; ///< chroma subsampling values
+ const AVPixFmtDescriptor *main_desc; ///< format descriptor for main input
+
+ double var_values[VAR_VARS_NB];
+ char *x_expr, *y_expr;
+
+ AVExpr *x_pexpr, *y_pexpr;
+
+ int (*blend_row[4])(uint8_t *d, uint8_t *da, uint8_t *s, uint8_t *a, int w,
+ ptrdiff_t alinesize);
+ int (*blend_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
+} OverlayContext;
+
+void ff_overlay_init_x86(OverlayContext *s, int format, int alpha_format, int main_has_alpha);
+
+#endif /* AVFILTER_OVERLAY_H */
diff --git a/libavfilter/x86/Makefile b/libavfilter/x86/Makefile
index f60de3b73b..b484c8bd1c 100644
--- a/libavfilter/x86/Makefile
+++ b/libavfilter/x86/Makefile
@@ -13,6 +13,7 @@ OBJS-$(CONFIG_INTERLACE_FILTER) += x86/vf_tinterlace_init.o
OBJS-$(CONFIG_LIMITER_FILTER) += x86/vf_limiter_init.o
OBJS-$(CONFIG_MASKEDMERGE_FILTER) += x86/vf_maskedmerge_init.o
OBJS-$(CONFIG_NOISE_FILTER) += x86/vf_noise.o
+OBJS-$(CONFIG_OVERLAY_FILTER) += x86/vf_overlay_init.o
OBJS-$(CONFIG_PP7_FILTER) += x86/vf_pp7_init.o
OBJS-$(CONFIG_PSNR_FILTER) += x86/vf_psnr_init.o
OBJS-$(CONFIG_PULLUP_FILTER) += x86/vf_pullup_init.o
@@ -41,6 +42,7 @@ X86ASM-OBJS-$(CONFIG_IDET_FILTER) += x86/vf_idet.o
X86ASM-OBJS-$(CONFIG_INTERLACE_FILTER) += x86/vf_interlace.o
X86ASM-OBJS-$(CONFIG_LIMITER_FILTER) += x86/vf_limiter.o
X86ASM-OBJS-$(CONFIG_MASKEDMERGE_FILTER) += x86/vf_maskedmerge.o
+X86ASM-OBJS-$(CONFIG_OVERLAY_FILTER) += x86/vf_overlay.o
X86ASM-OBJS-$(CONFIG_PP7_FILTER) += x86/vf_pp7.o
X86ASM-OBJS-$(CONFIG_PSNR_FILTER) += x86/vf_psnr.o
X86ASM-OBJS-$(CONFIG_PULLUP_FILTER) += x86/vf_pullup.o
diff --git a/libavfilter/x86/vf_overlay.asm b/libavfilter/x86/vf_overlay.asm
new file mode 100644
index 0000000000..14ec60ca34
--- /dev/null
+++ b/libavfilter/x86/vf_overlay.asm
@@ -0,0 +1,144 @@
+;*****************************************************************************
+;* x86-optimized functions for overlay filter
+;*
+;* Copyright (C) 2018 Paul B Mahol
+;* Copyright (C) 2018 Henrik Gramner
+;*
+;* 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/x86/x86util.asm"
+
+SECTION_RODATA
+
+pb_1: times 16 db 1
+pw_128: times 8 dw 128
+pw_255: times 8 dw 255
+pw_257: times 8 dw 257
+
+SECTION .text
+
+INIT_XMM sse4
+cglobal overlay_row_44, 5, 7, 6, 0, d, da, s, a, w, r, x
+ xor xq, xq
+ movsxdifnidn wq, wd
+ mov rq, wq
+ and rq, mmsize/2 - 1
+ cmp wq, mmsize/2
+ jl .end
+ sub wq, rq
+ mova m3, [pw_255]
+ mova m4, [pw_128]
+ mova m5, [pw_257]
+ .loop:
+ pmovzxbw m0, [sq+xq]
+ pmovzxbw m2, [aq+xq]
+ pmovzxbw m1, [dq+xq]
+ pmullw m0, m2
+ pxor m2, m3
+ pmullw m1, m2
+ paddw m0, m4
+ paddw m0, m1
+ pmulhuw m0, m5
+ packuswb m0, m0
+ movq [dq+xq], m0
+ add xq, mmsize/2
+ cmp xq, wq
+ jl .loop
+
+ .end:
+ mov eax, xd
+ RET
+
+INIT_XMM sse4
+cglobal overlay_row_22, 5, 7, 6, 0, d, da, s, a, w, r, x
+ xor xq, xq
+ movsxdifnidn wq, wd
+ sub wq, 1
+ mov rq, wq
+ and rq, mmsize/2 - 1
+ cmp wq, mmsize/2
+ jl .end
+ sub wq, rq
+ mova m3, [pw_255]
+ mova m4, [pw_128]
+ mova m5, [pw_257]
+ .loop:
+ pmovzxbw m0, [sq+xq]
+ movu m1, [aq+2*xq]
+ pandn m2, m3, m1
+ psllw m1, 8
+ pavgw m2, m1
+ pavgw m2, m1
+ psrlw m2, 8
+ pmovzxbw m1, [dq+xq]
+ pmullw m0, m2
+ pxor m2, m3
+ pmullw m1, m2
+ paddw m0, m4
+ paddw m0, m1
+ pmulhuw m0, m5
+ packuswb m0, m0
+ movq [dq+xq], m0
+ add xq, mmsize/2
+ cmp xq, wq
+ jl .loop
+
+ .end:
+ mov eax, xd
+ RET
+
+INIT_XMM sse4
+cglobal overlay_row_20, 6, 7, 7, 0, d, da, s, a, w, r, x
+ mov daq, aq
+ add daq, rmp
+ xor xq, xq
+ movsxdifnidn wq, wd
+ sub wq, 1
+ mov rq, wq
+ and rq, mmsize/2 - 1
+ cmp wq, mmsize/2
+ jl .end
+ sub wq, rq
+ mova m3, [pw_255]
+ mova m4, [pw_128]
+ mova m5, [pw_257]
+ mova m6, [pb_1]
+ .loop:
+ pmovzxbw m0, [sq+xq]
+ movu m2, [aq+2*xq]
+ movu m1, [daq+2*xq]
+ pmaddubsw m2, m6
+ pmaddubsw m1, m6
+ paddw m2, m1
+ psrlw m2, 2
+ pmovzxbw m1, [dq+xq]
+ pmullw m0, m2
+ pxor m2, m3
+ pmullw m1, m2
+ paddw m0, m4
+ paddw m0, m1
+ pmulhuw m0, m5
+ packuswb m0, m0
+ movq [dq+xq], m0
+ add xq, mmsize/2
+ cmp xq, wq
+ jl .loop
+
+ .end:
+ mov eax, xd
+ RET
diff --git a/libavfilter/x86/vf_overlay_init.c b/libavfilter/x86/vf_overlay_init.c
new file mode 100644
index 0000000000..fec1629829
--- /dev/null
+++ b/libavfilter/x86/vf_overlay_init.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2018 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libavutil/x86/cpu.h"
+#include "libavfilter/vf_overlay.h"
+
+int ff_overlay_row_44_sse4(uint8_t *d, uint8_t *da, uint8_t *s, uint8_t *a,
+ int w, ptrdiff_t alinesize);
+
+int ff_overlay_row_20_sse4(uint8_t *d, uint8_t *da, uint8_t *s, uint8_t *a,
+ int w, ptrdiff_t alinesize);
+
+int ff_overlay_row_22_sse4(uint8_t *d, uint8_t *da, uint8_t *s, uint8_t *a,
+ int w, ptrdiff_t alinesize);
+
+av_cold void ff_overlay_init_x86(OverlayContext *s, int format, int alpha_format, int main_has_alpha)
+{
+ int cpu_flags = av_get_cpu_flags();
+
+ if (EXTERNAL_SSE4(cpu_flags) &&
+ (format == OVERLAY_FORMAT_YUV444 ||
+ format == OVERLAY_FORMAT_GBRP) &&
+ alpha_format == 0 && main_has_alpha == 0) {
+ s->blend_row[0] = ff_overlay_row_44_sse4;
+ s->blend_row[1] = ff_overlay_row_44_sse4;
+ s->blend_row[2] = ff_overlay_row_44_sse4;
+ }
+
+ if (EXTERNAL_SSE4(cpu_flags) &&
+ (format == OVERLAY_FORMAT_YUV420) &&
+ alpha_format == 0 && main_has_alpha == 0) {
+ s->blend_row[0] = ff_overlay_row_44_sse4;
+ s->blend_row[1] = ff_overlay_row_20_sse4;
+ s->blend_row[2] = ff_overlay_row_20_sse4;
+ }
+
+ if (EXTERNAL_SSE4(cpu_flags) &&
+ (format == OVERLAY_FORMAT_YUV422) &&
+ alpha_format == 0 && main_has_alpha == 0) {
+ s->blend_row[0] = ff_overlay_row_44_sse4;
+ s->blend_row[1] = ff_overlay_row_22_sse4;
+ s->blend_row[2] = ff_overlay_row_22_sse4;
+ }
+}
1
0
ffmpeg | branch: master | Tobias Rapp <t.rapp(a)noa-archive.com> | Thu Apr 26 14:23:02 2018 +0200| [a150b2e3a099fd539ecc6664050fd20617ce223c] | committer: Tobias Rapp
fftools/ffmpeg: properly initialize output stream field order
Fixes stream field order written by avformat_write_header when "top"
option is specified on the command-line.
Signed-off-by: Tobias Rapp <t.rapp(a)noa-archive.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a150b2e3a099fd539…
---
fftools/ffmpeg.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5dc198f933..5a19a09d9a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3389,6 +3389,12 @@ static int init_output_stream_encode(OutputStream *ost)
enc_ctx->bits_per_raw_sample = frame_bits_per_raw_sample;
}
+ if (ost->top_field_first == 0) {
+ enc_ctx->field_order = AV_FIELD_BB;
+ } else if (ost->top_field_first == 1) {
+ enc_ctx->field_order = AV_FIELD_TT;
+ }
+
if (ost->forced_keyframes) {
if (!strncmp(ost->forced_keyframes, "expr:", 5)) {
ret = av_expr_parse(&ost->forced_keyframes_pexpr, ost->forced_keyframes+5,
1
0
ffmpeg | branch: master | Mark Thompson <sw(a)jkqxz.net> | 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=e07b1913fc67b9244…
---
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
1
0
ffmpeg | branch: master | Mark Thompson <sw(a)jkqxz.net> | 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=ddd3a209dc5a535a4…
---
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 0000000000..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 0000000000..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 0000000000..f579459179
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp90-2-06-bilinear
@@ -0,0 +1 @@
+2ca9d012c7212e38f5e2727ac66ec6c5
diff --git a/tests/ref/fate/cbs-vp9-vp90-2-09-lf_deltas b/tests/ref/fate/cbs-vp9-vp90-2-09-lf_deltas
new file mode 100644
index 0000000000..e0b5686d0b
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp90-2-09-lf_deltas
@@ -0,0 +1 @@
+78f5e46bfaecbcd62b9126697a0d97b7
diff --git a/tests/ref/fate/cbs-vp9-vp90-2-10-show-existing-frame b/tests/ref/fate/cbs-vp9-vp90-2-10-show-existing-frame
new file mode 100644
index 0000000000..4a4d752428
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp90-2-10-show-existing-frame
@@ -0,0 +1 @@
+eea9d10a696c6ed971e4fae9fb619b10
diff --git a/tests/ref/fate/cbs-vp9-vp90-2-10-show-existing-frame2 b/tests/ref/fate/cbs-vp9-vp90-2-10-show-existing-frame2
new file mode 100644
index 0000000000..6da8999114
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp90-2-10-show-existing-frame2
@@ -0,0 +1 @@
+abf4c7d4be7d3576d96b6f92166b5894
diff --git a/tests/ref/fate/cbs-vp9-vp90-2-segmentation-aq-akiyo b/tests/ref/fate/cbs-vp9-vp90-2-segmentation-aq-akiyo
new file mode 100644
index 0000000000..12dfb10d40
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp90-2-segmentation-aq-akiyo
@@ -0,0 +1 @@
+86cd3750cc9a0672717643c9b9f87fd5
diff --git a/tests/ref/fate/cbs-vp9-vp90-2-segmentation-sf-akiyo b/tests/ref/fate/cbs-vp9-vp90-2-segmentation-sf-akiyo
new file mode 100644
index 0000000000..c2b1b8723a
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp90-2-segmentation-sf-akiyo
@@ -0,0 +1 @@
+5d12fbe6220aae9e62b1d79785a83387
diff --git a/tests/ref/fate/cbs-vp9-vp90-2-tiling-pedestrian b/tests/ref/fate/cbs-vp9-vp90-2-tiling-pedestrian
new file mode 100644
index 0000000000..f9cab39bd6
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp90-2-tiling-pedestrian
@@ -0,0 +1 @@
+4c51f3c796baa7c2baa4b7ec0d011406
diff --git a/tests/ref/fate/cbs-vp9-vp91-2-04-yuv440 b/tests/ref/fate/cbs-vp9-vp91-2-04-yuv440
new file mode 100644
index 0000000000..6289930070
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp91-2-04-yuv440
@@ -0,0 +1 @@
+293bdc92851ca1105e27f04737d8c5f3
diff --git a/tests/ref/fate/cbs-vp9-vp91-2-04-yuv444 b/tests/ref/fate/cbs-vp9-vp91-2-04-yuv444
new file mode 100644
index 0000000000..628ea9a4d9
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp91-2-04-yuv444
@@ -0,0 +1 @@
+911eafd8e442e646c5ce97d781757ca8
diff --git a/tests/ref/fate/cbs-vp9-vp92-2-20-10bit-yuv420 b/tests/ref/fate/cbs-vp9-vp92-2-20-10bit-yuv420
new file mode 100644
index 0000000000..eeb7580d74
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp92-2-20-10bit-yuv420
@@ -0,0 +1 @@
+16198c32c29228e0513004ed1bf6fcee
diff --git a/tests/ref/fate/cbs-vp9-vp93-2-20-10bit-yuv422 b/tests/ref/fate/cbs-vp9-vp93-2-20-10bit-yuv422
new file mode 100644
index 0000000000..b25bc1166e
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp93-2-20-10bit-yuv422
@@ -0,0 +1 @@
+4bceedef4aa6a663a09761971e43b5a8
diff --git a/tests/ref/fate/cbs-vp9-vp93-2-20-12bit-yuv444 b/tests/ref/fate/cbs-vp9-vp93-2-20-12bit-yuv444
new file mode 100644
index 0000000000..8d122d1370
--- /dev/null
+++ b/tests/ref/fate/cbs-vp9-vp93-2-20-12bit-yuv444
@@ -0,0 +1 @@
+0f413b840633bfcfcc78b4c9fab933bf
1
0
ffmpeg | branch: master | Mark Thompson <sw(a)jkqxz.net> | 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=308b989e0cf14d5b3…
---
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 0000000000..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 < frag->nb_units; i++) {
+ VP9RawFrame *frame = frag->units[i].content;
+ VP9RawFrameHeader *header = &frame->header;
+
+ if (ctx->color_space >= 0) {
+ header->color_space = ctx->color_space;
+ }
+ if (ctx->color_range >= 0) {
+ if (ctx->color_range == 0 &&
+ header->color_space == VP9_CS_RGB &&
+ !ctx->color_range_rgb_warned) {
+ av_log(bsf, AV_LOG_WARNING, "Warning: color_range cannot "
+ "be set to limited in RGB streams.\n");
+ ctx->color_range_rgb_warned = 1;
+ } else {
+ header->color_range = ctx->color_range;
+ }
+ }
+ }
+
+ err = ff_cbs_write_packet(ctx->cbc, out, frag);
+ if (err < 0) {
+ av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
+ goto fail;
+ }
+
+ err = av_packet_copy_props(out, in);
+ if (err < 0)
+ goto fail;
+
+ err = 0;
+fail:
+ ff_cbs_fragment_uninit(ctx->cbc, frag);
+
+ if (err < 0)
+ av_packet_unref(out);
+ av_packet_free(&in);
+
+ return err;
+}
+
+static int vp9_metadata_init(AVBSFContext *bsf)
+{
+ VP9MetadataContext *ctx = bsf->priv_data;
+
+ return ff_cbs_init(&ctx->cbc, AV_CODEC_ID_VP9, bsf);
+}
+
+static void vp9_metadata_close(AVBSFContext *bsf)
+{
+ VP9MetadataContext *ctx = bsf->priv_data;
+ ff_cbs_close(&ctx->cbc);
+}
+
+#define OFFSET(x) offsetof(VP9MetadataContext, x)
+#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
+static const AVOption vp9_metadata_options[] = {
+ { "color_space", "Set colour space (section 7.2.2)",
+ OFFSET(color_space), AV_OPT_TYPE_INT,
+ { .i64 = -1 }, -1, VP9_CS_RGB, FLAGS, "cs" },
+ { "unknown", "Unknown/unspecified", 0, AV_OPT_TYPE_CONST,
+ { .i64 = VP9_CS_UNKNOWN }, .flags = FLAGS, .unit = "cs" },
+ { "bt601", "ITU-R BT.601-7", 0, AV_OPT_TYPE_CONST,
+ { .i64 = VP9_CS_BT_601 }, .flags = FLAGS, .unit = "cs" },
+ { "bt709", "ITU-R BT.709-6", 0, AV_OPT_TYPE_CONST,
+ { .i64 = VP9_CS_BT_709 }, .flags = FLAGS, .unit = "cs" },
+ { "smpte170", "SMPTE-170", 0, AV_OPT_TYPE_CONST,
+ { .i64 = VP9_CS_SMPTE_170 }, .flags = FLAGS, .unit = "cs" },
+ { "smpte240", "SMPTE-240", 0, AV_OPT_TYPE_CONST,
+ { .i64 = VP9_CS_SMPTE_240 }, .flags = FLAGS, .unit = "cs" },
+ { "bt2020", "ITU-R BT.2020-2", 0, AV_OPT_TYPE_CONST,
+ { .i64 = VP9_CS_BT_2020 }, .flags = FLAGS, .unit = "cs" },
+ { "rgb", "sRGB / IEC 61966-2-1", 0, AV_OPT_TYPE_CONST,
+ { .i64 = VP9_CS_RGB }, .flags = FLAGS, .unit = "cs" },
+
+ { "color_range", "Set colour range (section 7.2.2)",
+ OFFSET(color_range), AV_OPT_TYPE_INT,
+ { .i64 = -1 }, -1, 1, FLAGS, "cr" },
+ { "tv", "TV (limited) range", 0, AV_OPT_TYPE_CONST,
+ { .i64 = 0 }, .flags = FLAGS, .unit = "cr" },
+ { "pc", "PC (full) range", 0, AV_OPT_TYPE_CONST,
+ { .i64 = 1 }, .flags = FLAGS, .unit = "cr" },
+
+ { NULL }
+};
+
+static const AVClass vp9_metadata_class = {
+ .class_name = "vp9_metadata_bsf",
+ .item_name = av_default_item_name,
+ .option = vp9_metadata_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static const enum AVCodecID vp9_metadata_codec_ids[] = {
+ AV_CODEC_ID_VP9, AV_CODEC_ID_NONE,
+};
+
+const AVBitStreamFilter ff_vp9_metadata_bsf = {
+ .name = "vp9_metadata",
+ .priv_data_size = sizeof(VP9MetadataContext),
+ .priv_class = &vp9_metadata_class,
+ .init = &vp9_metadata_init,
+ .close = &vp9_metadata_close,
+ .filter = &vp9_metadata_filter,
+ .codec_ids = vp9_metadata_codec_ids,
+};
1
0
ffmpeg | branch: master | Mark Thompson <sw(a)jkqxz.net> | 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=b5df289eb771e3cd4…
---
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 0000000000..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"
+
+
+static int cbs_vp9_read_s(CodedBitstreamContext *ctx, GetBitContext *gbc,
+ int width, const char *name,
+ const int *subscripts, int32_t *write_to)
+{
+ uint32_t magnitude;
+ int position, sign;
+ int32_t value;
+
+ if (ctx->trace_enable)
+ position = get_bits_count(gbc);
+
+ if (get_bits_left(gbc) < width + 1) {
+ av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid signed value at "
+ "%s: bitstream ended.\n", name);
+ return AVERROR_INVALIDDATA;
+ }
+
+ magnitude = get_bits(gbc, width);
+ sign = get_bits1(gbc);
+ value = sign ? -(int32_t)magnitude : magnitude;
+
+ if (ctx->trace_enable) {
+ char bits[33];
+ int i;
+ for (i = 0; i < width; i++)
+ bits[i] = magnitude >> (width - i - 1) & 1 ? '1' : '0';
+ bits[i] = sign ? '1' : '0';
+ bits[i + 1] = 0;
+
+ ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
+ bits, value);
+ }
+
+ *write_to = value;
+ return 0;
+}
+
+static int cbs_vp9_write_s(CodedBitstreamContext *ctx, PutBitContext *pbc,
+ int width, const char *name,
+ const int *subscripts, int32_t value)
+{
+ uint32_t magnitude;
+ int sign;
+
+ if (put_bits_left(pbc) < width + 1)
+ return AVERROR(ENOSPC);
+
+ sign = value < 0;
+ magnitude = sign ? -value : value;
+
+ if (ctx->trace_enable) {
+ char bits[33];
+ int i;
+ for (i = 0; i < width; i++)
+ bits[i] = magnitude >> (width - i - 1) & 1 ? '1' : '0';
+ bits[i] = sign ? '1' : '0';
+ bits[i + 1] = 0;
+
+ ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc),
+ name, subscripts, bits, value);
+ }
+
+ put_bits(pbc, width, magnitude);
+ put_bits(pbc, 1, sign);
+
+ return 0;
+}
+
+static int cbs_vp9_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc,
+ uint32_t range_min, uint32_t range_max,
+ const char *name, uint32_t *write_to)
+{
+ uint32_t value;
+ int position, i;
+ char bits[8];
+
+ av_assert0(range_min <= range_max && range_max - range_min < sizeof(bits) - 1);
+ if (ctx->trace_enable)
+ position = get_bits_count(gbc);
+
+ for (i = 0, value = range_min; value < range_max;) {
+ if (get_bits_left(gbc) < 1) {
+ av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid increment value at "
+ "%s: bitstream ended.\n", name);
+ return AVERROR_INVALIDDATA;
+ }
+ if (get_bits1(gbc)) {
+ bits[i++] = '1';
+ ++value;
+ } else {
+ bits[i++] = '0';
+ break;
+ }
+ }
+
+ if (ctx->trace_enable) {
+ bits[i] = 0;
+ ff_cbs_trace_syntax_element(ctx, position, name, NULL, bits, value);
+ }
+
+ *write_to = value;
+ return 0;
+}
+
+static int cbs_vp9_write_increment(CodedBitstreamContext *ctx, PutBitContext *pbc,
+ uint32_t range_min, uint32_t range_max,
+ const char *name, uint32_t value)
+{
+ int len;
+
+ av_assert0(range_min <= range_max && range_max - range_min < 8);
+ if (value < range_min || value > range_max) {
+ av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
+ "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
+ name, value, range_min, range_max);
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (value == range_max)
+ len = range_max - range_min;
+ else
+ len = value - range_min + 1;
+ if (put_bits_left(pbc) < len)
+ return AVERROR(ENOSPC);
+
+ if (ctx->trace_enable) {
+ char bits[8];
+ int i;
+ for (i = 0; i < len; i++) {
+ if (range_min + i == value)
+ bits[i] = '0';
+ else
+ bits[i] = '1';
+ }
+ bits[i] = 0;
+ ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc),
+ name, NULL, bits, value);
+ }
+
+ if (len > 0)
+ put_bits(pbc, len, (1 << len) - 1 - (value != range_max));
+
+ return 0;
+}
+
+static int cbs_vp9_read_le(CodedBitstreamContext *ctx, GetBitContext *gbc,
+ int width, const char *name,
+ const int *subscripts, uint32_t *write_to)
+{
+ uint32_t value;
+ int position, b;
+
+ av_assert0(width % 8 == 0);
+
+ if (ctx->trace_enable)
+ position = get_bits_count(gbc);
+
+ if (get_bits_left(gbc) < width) {
+ av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid le value at "
+ "%s: bitstream ended.\n", name);
+ return AVERROR_INVALIDDATA;
+ }
+
+ value = 0;
+ for (b = 0; b < width; b += 8)
+ value |= get_bits(gbc, 8) << b;
+
+ if (ctx->trace_enable) {
+ char bits[33];
+ int i;
+ for (b = 0; b < width; b += 8)
+ for (i = 0; i < 8; i++)
+ bits[b + i] = value >> (b + i) & 1 ? '1' : '0';
+ bits[b] = 0;
+
+ ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
+ bits, value);
+ }
+
+ *write_to = value;
+ return 0;
+}
+
+static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc,
+ int width, const char *name,
+ const int *subscripts, uint32_t value)
+{
+ int b;
+
+ av_assert0(width % 8 == 0);
+
+ if (put_bits_left(pbc) < width)
+ return AVERROR(ENOSPC);
+
+ if (ctx->trace_enable) {
+ char bits[33];
+ int i;
+ for (b = 0; b < width; b += 8)
+ for (i = 0; i < 8; i++)
+ bits[b + i] = value >> (b + i) & 1 ? '1' : '0';
+ bits[b] = 0;
+
+ ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc),
+ name, subscripts, bits, value);
+ }
+
+ for (b = 0; b < width; b += 8)
+ put_bits(pbc, 8, value >> b & 0xff);
+
+ return 0;
+}
+
+#define HEADER(name) do { \
+ ff_cbs_trace_header(ctx, name); \
+ } while (0)
+
+#define CHECK(call) do { \
+ err = (call); \
+ if (err < 0) \
+ return err; \
+ } while (0)
+
+#define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
+#define FUNC_VP9(rw, name) FUNC_NAME(rw, vp9, name)
+#define FUNC(name) FUNC_VP9(READWRITE, name)
+
+#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
+
+#define f(width, name) \
+ xf(width, name, current->name, 0)
+#define s(width, name) \
+ xs(width, name, current->name, 0)
+#define fs(width, name, subs, ...) \
+ xf(width, name, current->name, subs, __VA_ARGS__)
+#define ss(width, name, subs, ...) \
+ xs(width, name, current->name, subs, __VA_ARGS__)
+
+
+#define READ
+#define READWRITE read
+#define RWContext GetBitContext
+
+#define xf(width, name, var, subs, ...) do { \
+ uint32_t value = 0; \
+ CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), \
+ &value, 0, (1 << width) - 1)); \
+ var = value; \
+ } while (0)
+#define xs(width, name, var, subs, ...) do { \
+ int32_t value = 0; \
+ CHECK(cbs_vp9_read_s(ctx, rw, width, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
+ var = value; \
+ } while (0)
+
+
+#define increment(name, min, max) do { \
+ uint32_t value = 0; \
+ CHECK(cbs_vp9_read_increment(ctx, rw, min, max, #name, &value)); \
+ current->name = value; \
+ } while (0)
+
+#define fle(width, name, subs, ...) do { \
+ CHECK(cbs_vp9_read_le(ctx, rw, width, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), ¤t->name)); \
+ } while (0)
+
+#define delta_q(name) do { \
+ uint8_t delta_coded; \
+ int8_t delta_q; \
+ xf(1, name.delta_coded, delta_coded, 0); \
+ if (delta_coded) \
+ xs(4, name.delta_q, delta_q, 0); \
+ else \
+ delta_q = 0; \
+ current->name = delta_q; \
+ } while (0)
+
+#define prob(name, subs, ...) do { \
+ uint8_t prob_coded; \
+ int8_t prob; \
+ xf(1, name.prob_coded, prob_coded, subs, __VA_ARGS__); \
+ if (prob_coded) \
+ xf(8, name.prob, prob, subs, __VA_ARGS__); \
+ else \
+ prob = 255; \
+ current->name = prob; \
+ } while (0)
+
+#define infer(name, value) do { \
+ current->name = value; \
+ } while (0)
+
+#define byte_alignment(rw) (get_bits_count(rw) % 8)
+
+#include "cbs_vp9_syntax_template.c"
+
+#undef READ
+#undef READWRITE
+#undef RWContext
+#undef xf
+#undef xs
+#undef increment
+#undef fle
+#undef delta_q
+#undef prob
+#undef infer
+#undef byte_alignment
+
+
+#define WRITE
+#define READWRITE write
+#define RWContext PutBitContext
+
+#define xf(width, name, var, subs, ...) do { \
+ CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), \
+ var, 0, (1 << width) - 1)); \
+ } while (0)
+#define xs(width, name, var, subs, ...) do { \
+ CHECK(cbs_vp9_write_s(ctx, rw, width, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), var)); \
+ } while (0)
+
+#define increment(name, min, max) do { \
+ CHECK(cbs_vp9_write_increment(ctx, rw, min, max, #name, current->name)); \
+ } while (0)
+
+#define fle(width, name, subs, ...) do { \
+ CHECK(cbs_vp9_write_le(ctx, rw, width, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), current->name)); \
+ } while (0)
+
+#define delta_q(name) do { \
+ xf(1, name.delta_coded, !!current->name, 0); \
+ if (current->name) \
+ xs(4, name.delta_q, current->name, 0); \
+ } while (0)
+
+#define prob(name, subs, ...) do { \
+ xf(1, name.prob_coded, current->name != 255, subs, __VA_ARGS__); \
+ if (current->name != 255) \
+ xf(8, name.prob, current->name, subs, __VA_ARGS__); \
+ } while (0)
+
+#define infer(name, value) do { \
+ if (current->name != (value)) { \
+ av_log(ctx->log_ctx, AV_LOG_WARNING, "Warning: " \
+ "%s does not match inferred value: " \
+ "%"PRId64", but should be %"PRId64".\n", \
+ #name, (int64_t)current->name, (int64_t)(value)); \
+ } \
+ } while (0)
+
+#define byte_alignment(rw) (put_bits_count(rw) % 8)
+
+#include "cbs_vp9_syntax_template.c"
+
+#undef READ
+#undef READWRITE
+#undef RWContext
+#undef xf
+#undef xs
+#undef increment
+#undef fle
+#undef delta_q
+#undef prob
+#undef infer
+#undef byte_alignment
+
+
+static int cbs_vp9_split_fragment(CodedBitstreamContext *ctx,
+ CodedBitstreamFragment *frag,
+ int header)
+{
+ uint8_t superframe_header;
+ int err;
+
+ // Last byte in the packet.
+ superframe_header = frag->data[frag->data_size - 1];
+
+ if ((superframe_header & 0xe0) == 0xc0) {
+ VP9RawSuperframeIndex sfi;
+ GetBitContext gbc;
+ size_t index_size, pos;
+ int i;
+
+ index_size = 2 + (((superframe_header & 0x18) >> 3) + 1) *
+ ((superframe_header & 0x07) + 1);
+
+ err = init_get_bits(&gbc, frag->data + frag->data_size - index_size,
+ 8 * index_size);
+ if (err < 0)
+ return err;
+
+ err = cbs_vp9_read_superframe_index(ctx, &gbc, &sfi);
+ if (err < 0)
+ return err;
+
+ pos = 0;
+ for (i = 0; i <= sfi.frames_in_superframe_minus_1; i++) {
+ if (pos + sfi.frame_sizes[i] + index_size > frag->data_size) {
+ av_log(ctx->log_ctx, AV_LOG_ERROR, "Frame %d too large "
+ "in superframe: %"PRIu32" bytes.\n",
+ i, sfi.frame_sizes[i]);
+ return AVERROR_INVALIDDATA;
+ }
+
+ err = ff_cbs_insert_unit_data(ctx, frag, -1, 0,
+ frag->data + pos,
+ sfi.frame_sizes[i],
+ frag->data_ref);
+ if (err < 0)
+ return err;
+
+ pos += sfi.frame_sizes[i];
+ }
+ if (pos + index_size != frag->data_size) {
+ av_log(ctx->log_ctx, AV_LOG_WARNING, "Extra padding at "
+ "end of superframe: %zu bytes.\n",
+ frag->data_size - (pos + index_size));
+ }
+
+ return 0;
+
+ } else {
+ err = ff_cbs_insert_unit_data(ctx, frag, -1, 0,
+ frag->data, frag->data_size,
+ frag->data_ref);
+ if (err < 0)
+ return err;
+ }
+
+ return 0;
+}
+
+static void cbs_vp9_free_frame(void *unit, uint8_t *content)
+{
+ VP9RawFrame *frame = (VP9RawFrame*)content;
+ av_buffer_unref(&frame->data_ref);
+ av_freep(&frame);
+}
+
+static int cbs_vp9_read_unit(CodedBitstreamContext *ctx,
+ CodedBitstreamUnit *unit)
+{
+ VP9RawFrame *frame;
+ GetBitContext gbc;
+ int err, pos;
+
+ err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
+ if (err < 0)
+ return err;
+
+ err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*frame),
+ &cbs_vp9_free_frame);
+ if (err < 0)
+ return err;
+ frame = unit->content;
+
+ err = cbs_vp9_read_frame(ctx, &gbc, frame);
+ if (err < 0)
+ return err;
+
+ pos = get_bits_count(&gbc);
+ av_assert0(pos % 8 == 0);
+ pos /= 8;
+ av_assert0(pos <= unit->data_size);
+
+ if (pos == unit->data_size) {
+ // No data (e.g. a show-existing-frame frame).
+ } else {
+ frame->data_ref = av_buffer_ref(unit->data_ref);
+ if (!frame->data_ref)
+ return AVERROR(ENOMEM);
+
+ frame->data = unit->data + pos;
+ frame->data_size = unit->data_size - pos;
+ }
+
+ return 0;
+}
+
+static int cbs_vp9_write_unit(CodedBitstreamContext *ctx,
+ CodedBitstreamUnit *unit)
+{
+ CodedBitstreamVP9Context *priv = ctx->priv_data;
+ VP9RawFrame *frame = unit->content;
+ PutBitContext pbc;
+ int err;
+
+ if (!priv->write_buffer) {
+ // Initial write buffer size is 1MB.
+ priv->write_buffer_size = 1024 * 1024;
+
+ reallocate_and_try_again:
+ err = av_reallocp(&priv->write_buffer, priv->write_buffer_size);
+ if (err < 0) {
+ av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
+ "sufficiently large write buffer (last attempt "
+ "%zu bytes).\n", priv->write_buffer_size);
+ return err;
+ }
+ }
+
+ init_put_bits(&pbc, priv->write_buffer, priv->write_buffer_size);
+
+ err = cbs_vp9_write_frame(ctx, &pbc, frame);
+ if (err == AVERROR(ENOSPC)) {
+ priv->write_buffer_size *= 2;
+ goto reallocate_and_try_again;
+ }
+ if (err < 0)
+ return err;
+
+ // Frame must be byte-aligned.
+ av_assert0(put_bits_count(&pbc) % 8 == 0);
+
+ unit->data_size = put_bits_count(&pbc) / 8;
+ unit->data_bit_padding = 0;
+ flush_put_bits(&pbc);
+
+ if (frame->data) {
+ if (unit->data_size + frame->data_size >
+ priv->write_buffer_size) {
+ priv->write_buffer_size *= 2;
+ goto reallocate_and_try_again;
+ }
+
+ memcpy(priv->write_buffer + unit->data_size,
+ frame->data, frame->data_size);
+ unit->data_size += frame->data_size;
+ }
+
+ err = ff_cbs_alloc_unit_data(ctx, unit, unit->data_size);
+ if (err < 0)
+ return err;
+
+ memcpy(unit->data, priv->write_buffer, unit->data_size);
+
+ return 0;
+}
+
+static int cbs_vp9_assemble_fragment(CodedBitstreamContext *ctx,
+ CodedBitstreamFragment *frag)
+{
+ int err;
+
+ if (frag->nb_units == 1) {
+ // Output is just the content of the single frame.
+
+ CodedBitstreamUnit *frame = &frag->units[0];
+
+ frag->data_ref = av_buffer_ref(frame->data_ref);
+ if (!frag->data_ref)
+ return AVERROR(ENOMEM);
+
+ frag->data = frame->data;
+ frag->data_size = frame->data_size;
+
+ } else {
+ // Build superframe out of frames.
+
+ VP9RawSuperframeIndex sfi;
+ PutBitContext pbc;
+ AVBufferRef *ref;
+ uint8_t *data;
+ size_t size, max, pos;
+ int i, size_len;
+
+ if (frag->nb_units > 8) {
+ av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many frames to "
+ "make superframe: %d.\n", frag->nb_units);
+ return AVERROR(EINVAL);
+ }
+
+ max = 0;
+ for (i = 0; i < frag->nb_units; i++)
+ if (max < frag->units[i].data_size)
+ max = frag->units[i].data_size;
+
+ if (max < 2)
+ size_len = 1;
+ else
+ size_len = av_log2(max) / 8 + 1;
+ av_assert0(size_len <= 4);
+
+ sfi.superframe_marker = VP9_SUPERFRAME_MARKER;
+ sfi.bytes_per_framesize_minus_1 = size_len - 1;
+ sfi.frames_in_superframe_minus_1 = frag->nb_units - 1;
+
+ size = 2;
+ for (i = 0; i < frag->nb_units; i++) {
+ size += size_len + frag->units[i].data_size;
+ sfi.frame_sizes[i] = frag->units[i].data_size;
+ }
+
+ ref = av_buffer_alloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
+ if (!ref)
+ return AVERROR(ENOMEM);
+ data = ref->data;
+ memset(data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+
+ pos = 0;
+ for (i = 0; i < frag->nb_units; i++) {
+ av_assert0(size - pos > frag->units[i].data_size);
+ memcpy(data + pos, frag->units[i].data,
+ frag->units[i].data_size);
+ pos += frag->units[i].data_size;
+ }
+ av_assert0(size - pos == 2 + frag->nb_units * size_len);
+
+ init_put_bits(&pbc, data + pos, size - pos);
+
+ err = cbs_vp9_write_superframe_index(ctx, &pbc, &sfi);
+ if (err < 0) {
+ av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to write "
+ "superframe index.\n");
+ av_buffer_unref(&ref);
+ return err;
+ }
+
+ av_assert0(put_bits_left(&pbc) == 0);
+ flush_put_bits(&pbc);
+
+ frag->data_ref = ref;
+ frag->data = data;
+ frag->data_size = size;
+ }
+
+ return 0;
+}
+
+static void cbs_vp9_close(CodedBitstreamContext *ctx)
+{
+ CodedBitstreamVP9Context *priv = ctx->priv_data;
+
+ av_freep(&priv->write_buffer);
+}
+
+const CodedBitstreamType ff_cbs_type_vp9 = {
+ .codec_id = AV_CODEC_ID_VP9,
+
+ .priv_data_size = sizeof(CodedBitstreamVP9Context),
+
+ .split_fragment = &cbs_vp9_split_fragment,
+ .read_unit = &cbs_vp9_read_unit,
+ .write_unit = &cbs_vp9_write_unit,
+ .assemble_fragment = &cbs_vp9_assemble_fragment,
+
+ .close = &cbs_vp9_close,
+};
diff --git a/libavcodec/cbs_vp9.h b/libavcodec/cbs_vp9.h
new file mode 100644
index 0000000000..5b99c90c2e
--- /dev/null
+++ b/libavcodec/cbs_vp9.h
@@ -0,0 +1,201 @@
+/*
+ * 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
+ */
+
+#ifndef AVCODEC_CBS_VP9_H
+#define AVCODEC_CBS_VP9_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "cbs.h"
+
+
+// Miscellaneous constants (section 3).
+enum {
+ VP9_REFS_PER_FRAME = 3,
+
+ VP9_MIN_TILE_WIDTH_B64 = 4,
+ VP9_MAX_TILE_WIDTH_B64 = 64,
+
+ VP9_NUM_REF_FRAMES = 8,
+ VP9_MAX_REF_FRAMES = 4,
+
+ VP9_MAX_SEGMENTS = 8,
+ VP9_SEG_LVL_MAX = 4,
+};
+
+// Frame types (section 7.2).
+enum {
+ VP9_KEY_FRAME = 0,
+ VP9_NON_KEY_FRAME = 1,
+};
+
+// Frame sync bytes (section 7.2.1).
+enum {
+ VP9_FRAME_SYNC_0 = 0x49,
+ VP9_FRAME_SYNC_1 = 0x83,
+ VP9_FRAME_SYNC_2 = 0x42,
+};
+
+// Color space values (section 7.2.2).
+enum {
+ VP9_CS_UNKNOWN = 0,
+ VP9_CS_BT_601 = 1,
+ VP9_CS_BT_709 = 2,
+ VP9_CS_SMPTE_170 = 3,
+ VP9_CS_SMPTE_240 = 4,
+ VP9_CS_BT_2020 = 5,
+ VP9_CS_RESERVED = 6,
+ VP9_CS_RGB = 7,
+};
+
+// Reference frame types (section 7.4.12).
+enum {
+ VP9_INTRA_FRAME = 0,
+ VP9_LAST_FRAME = 1,
+ VP9_GOLDEN_FRAME = 2,
+ VP9_ALTREF_FRAME = 3,
+};
+
+// Superframe properties (section B.3).
+enum {
+ VP9_MAX_FRAMES_IN_SUPERFRAME = 8,
+
+ VP9_SUPERFRAME_MARKER = 6,
+};
+
+
+typedef struct VP9RawFrameHeader {
+ uint8_t frame_marker;
+ uint8_t profile_low_bit;
+ uint8_t profile_high_bit;
+ uint8_t profile_reserved_zero;
+
+ uint8_t show_existing_frame;
+ uint8_t frame_to_show_map_idx;
+
+ uint8_t frame_type;
+ uint8_t show_frame;
+ uint8_t error_resilient_mode;
+
+ // Color config.
+ uint8_t ten_or_twelve_bit;
+ uint8_t color_space;
+ uint8_t color_range;
+ uint8_t subsampling_x;
+ uint8_t subsampling_y;
+ uint8_t color_config_reserved_zero;
+
+ uint8_t refresh_frame_flags;
+
+ uint8_t intra_only;
+ uint8_t reset_frame_context;
+
+ uint8_t ref_frame_idx[VP9_REFS_PER_FRAME];
+ uint8_t ref_frame_sign_bias[VP9_MAX_REF_FRAMES];
+
+ uint8_t allow_high_precision_mv;
+
+ uint8_t refresh_frame_context;
+ uint8_t frame_parallel_decoding_mode;
+
+ uint8_t frame_context_idx;
+
+ // Frame/render size.
+ uint8_t found_ref[VP9_REFS_PER_FRAME];
+ uint16_t frame_width_minus_1;
+ uint16_t frame_height_minus_1;
+ uint8_t render_and_frame_size_different;
+ uint16_t render_width_minus_1;
+ uint16_t render_height_minus_1;
+
+ // Interpolation filter.
+ uint8_t is_filter_switchable;
+ uint8_t raw_interpolation_filter_type;
+
+ // Loop filter params.
+ uint8_t loop_filter_level;
+ uint8_t loop_filter_sharpness;
+ uint8_t loop_filter_delta_enabled;
+ uint8_t loop_filter_delta_update;
+ uint8_t update_ref_delta[VP9_MAX_REF_FRAMES];
+ int8_t loop_filter_ref_deltas[VP9_MAX_REF_FRAMES];
+ uint8_t update_mode_delta[2];
+ int8_t loop_filter_mode_deltas[2];
+
+ // Quantization params.
+ uint8_t base_q_idx;
+ int8_t delta_q_y_dc;
+ int8_t delta_q_uv_dc;
+ int8_t delta_q_uv_ac;
+
+ // Segmentation params.
+ uint8_t segmentation_enabled;
+ uint8_t segmentation_update_map;
+ uint8_t segmentation_tree_probs[7];
+ uint8_t segmentation_temporal_update;
+ uint8_t segmentation_pred_prob[3];
+ uint8_t segmentation_update_data;
+ uint8_t segmentation_abs_or_delta_update;
+ uint8_t feature_enabled[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX];
+ uint8_t feature_value[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX];
+ uint8_t feature_sign[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX];
+
+ // Tile info.
+ uint8_t tile_cols_log2;
+ uint8_t tile_rows_log2;
+
+ uint16_t header_size_in_bytes;
+} VP9RawFrameHeader;
+
+typedef struct VP9RawFrame {
+ VP9RawFrameHeader header;
+
+ uint8_t *data;
+ size_t data_size;
+ AVBufferRef *data_ref;
+} VP9RawFrame;
+
+typedef struct VP9RawSuperframeIndex {
+ uint8_t superframe_marker;
+ uint8_t bytes_per_framesize_minus_1;
+ uint8_t frames_in_superframe_minus_1;
+ uint32_t frame_sizes[VP9_MAX_FRAMES_IN_SUPERFRAME];
+} VP9RawSuperframeIndex;
+
+typedef struct VP9RawSuperframe {
+ VP9RawFrame frames[VP9_MAX_FRAMES_IN_SUPERFRAME];
+ VP9RawSuperframeIndex index;
+} VP9RawSuperframe;
+
+
+typedef struct CodedBitstreamVP9Context {
+ // Frame dimensions in 8x8 mode info blocks.
+ uint16_t mi_cols;
+ uint16_t mi_rows;
+ // Frame dimensions in 64x64 superblocks.
+ uint16_t sb64_cols;
+ uint16_t sb64_rows;
+
+ // Write buffer.
+ uint8_t *write_buffer;
+ size_t write_buffer_size;
+} CodedBitstreamVP9Context;
+
+
+#endif /* AVCODEC_CBS_VP9_H */
diff --git a/libavcodec/cbs_vp9_syntax_template.c b/libavcodec/cbs_vp9_syntax_template.c
new file mode 100644
index 0000000000..0db0f52a6d
--- /dev/null
+++ b/libavcodec/cbs_vp9_syntax_template.c
@@ -0,0 +1,390 @@
+/*
+ * 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
+ */
+
+static int FUNC(frame_sync_code)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawFrameHeader *current)
+{
+ uint8_t frame_sync_byte_0 = VP9_FRAME_SYNC_0;
+ uint8_t frame_sync_byte_1 = VP9_FRAME_SYNC_1;
+ uint8_t frame_sync_byte_2 = VP9_FRAME_SYNC_2;
+ int err;
+
+ xf(8, frame_sync_byte_0, frame_sync_byte_0, 0);
+ xf(8, frame_sync_byte_1, frame_sync_byte_1, 0);
+ xf(8, frame_sync_byte_2, frame_sync_byte_2, 0);
+
+ if (frame_sync_byte_0 != VP9_FRAME_SYNC_0 ||
+ frame_sync_byte_1 != VP9_FRAME_SYNC_1 ||
+ frame_sync_byte_2 != VP9_FRAME_SYNC_2) {
+ av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid frame sync code: "
+ "%02x %02x %02x.\n", frame_sync_byte_0,
+ frame_sync_byte_1, frame_sync_byte_2);
+ return AVERROR_INVALIDDATA;
+ }
+
+ return 0;
+}
+
+static int FUNC(color_config)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawFrameHeader *current, int profile)
+{
+ int err;
+
+ if (profile >= 2)
+ f(1, ten_or_twelve_bit);
+
+ f(3, color_space);
+
+ if (current->color_space != VP9_CS_RGB) {
+ f(1, color_range);
+ if (profile == 1 || profile == 3) {
+ f(1, subsampling_x);
+ f(1, subsampling_y);
+ f(1, color_config_reserved_zero);
+ } else {
+ infer(subsampling_x, 1);
+ infer(subsampling_y, 1);
+ }
+ } else {
+ infer(color_range, 1);
+ if (profile == 1 || profile == 3) {
+ infer(subsampling_x, 0);
+ infer(subsampling_y, 0);
+ }
+ }
+
+ return 0;
+}
+
+static int FUNC(frame_size)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawFrameHeader *current)
+{
+ CodedBitstreamVP9Context *vp9 = ctx->priv_data;
+ int err;
+
+ f(16, frame_width_minus_1);
+ f(16, frame_height_minus_1);
+
+ vp9->mi_cols = (current->frame_width_minus_1 + 8) >> 3;
+ vp9->mi_rows = (current->frame_height_minus_1 + 8) >> 3;
+ vp9->sb64_cols = (vp9->mi_cols + 7) >> 3;
+ vp9->sb64_rows = (vp9->mi_rows + 7) >> 3;
+
+ return 0;
+}
+
+static int FUNC(render_size)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawFrameHeader *current)
+{
+ int err;
+
+ f(1, render_and_frame_size_different);
+
+ if (current->render_and_frame_size_different) {
+ f(16, render_width_minus_1);
+ f(16, render_height_minus_1);
+ }
+
+ return 0;
+}
+
+static int FUNC(frame_size_with_refs)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawFrameHeader *current)
+{
+ int err, i;
+
+ for (i = 0; i < VP9_REFS_PER_FRAME; i++) {
+ fs(1, found_ref[i], 1, i);
+ if (current->found_ref[i])
+ break;
+ }
+ if (i >= VP9_REFS_PER_FRAME)
+ CHECK(FUNC(frame_size)(ctx, rw, current));
+ CHECK(FUNC(render_size)(ctx, rw, current));
+
+ return 0;
+}
+
+static int FUNC(interpolation_filter)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawFrameHeader *current)
+{
+ int err;
+
+ f(1, is_filter_switchable);
+ if (!current->is_filter_switchable)
+ f(2, raw_interpolation_filter_type);
+
+ return 0;
+}
+
+static int FUNC(loop_filter_params)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawFrameHeader *current)
+{
+ int err, i;
+
+ f(6, loop_filter_level);
+ f(3, loop_filter_sharpness);
+
+ f(1, loop_filter_delta_enabled);
+ if (current->loop_filter_delta_enabled) {
+ f(1, loop_filter_delta_update);
+ if (current->loop_filter_delta_update) {
+ for (i = 0; i < VP9_MAX_REF_FRAMES; i++) {
+ fs(1, update_ref_delta[i], 1, i);
+ if (current->update_ref_delta[i])
+ ss(6, loop_filter_ref_deltas[i], 1, i);
+ }
+ for (i = 0; i < 2; i++) {
+ fs(1, update_mode_delta[i], 1, i);
+ if (current->update_mode_delta[i])
+ ss(6, loop_filter_mode_deltas[i], 1, i);
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int FUNC(quantization_params)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawFrameHeader *current)
+{
+ int err;
+
+ f(8, base_q_idx);
+
+ delta_q(delta_q_y_dc);
+ delta_q(delta_q_uv_dc);
+ delta_q(delta_q_uv_ac);
+
+ return 0;
+}
+
+static int FUNC(segmentation_params)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawFrameHeader *current)
+{
+ static const int segmentation_feature_bits[VP9_SEG_LVL_MAX] = { 8, 6, 2, 0 };
+ static const int segmentation_feature_signed[VP9_SEG_LVL_MAX] = { 1, 1, 0, 0 };
+
+ int err, i, j;
+
+ f(1, segmentation_enabled);
+
+ if (current->segmentation_enabled) {
+ f(1, segmentation_update_map);
+ if (current->segmentation_update_map) {
+ for (i = 0; i < 7; i++)
+ prob(segmentation_tree_probs[i], 1, i);
+ f(1, segmentation_temporal_update);
+ for (i = 0; i < 3; i++) {
+ if (current->segmentation_temporal_update)
+ prob(segmentation_pred_prob[i], 1, i);
+ else
+ infer(segmentation_pred_prob[i], 255);
+ }
+ }
+
+ f(1, segmentation_update_data);
+ if (current->segmentation_update_data) {
+ f(1, segmentation_abs_or_delta_update);
+ for (i = 0; i < VP9_MAX_SEGMENTS; i++) {
+ for (j = 0; j < VP9_SEG_LVL_MAX; j++) {
+ fs(1, feature_enabled[i][j], 2, i, j);
+ if (current->feature_enabled[i][j] &&
+ segmentation_feature_bits[j]) {
+ fs(segmentation_feature_bits[j],
+ feature_value[i][j], 2, i, j);
+ if (segmentation_feature_signed[j])
+ fs(1, feature_sign[i][j], 2, i, j);
+ else
+ infer(feature_sign[i][j], 0);
+ } else {
+ infer(feature_value[i][j], 0);
+ infer(feature_sign[i][j], 0);
+ }
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int FUNC(tile_info)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawFrameHeader *current)
+{
+ CodedBitstreamVP9Context *vp9 = ctx->priv_data;
+ int min_log2_tile_cols, max_log2_tile_cols;
+ int err;
+
+ min_log2_tile_cols = 0;
+ while ((VP9_MAX_TILE_WIDTH_B64 << min_log2_tile_cols) < vp9->sb64_cols)
+ ++min_log2_tile_cols;
+ max_log2_tile_cols = 0;
+ while ((vp9->sb64_cols >> (max_log2_tile_cols + 1)) >= VP9_MIN_TILE_WIDTH_B64)
+ ++max_log2_tile_cols;
+
+ increment(tile_cols_log2, min_log2_tile_cols, max_log2_tile_cols);
+
+ increment(tile_rows_log2, 0, 2);
+
+ return 0;
+}
+
+static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawFrameHeader *current)
+{
+ int profile, i;
+ int err;
+
+ f(2, frame_marker);
+
+ f(1, profile_low_bit);
+ f(1, profile_high_bit);
+ profile = (current->profile_high_bit << 1) + current->profile_low_bit;
+ if (profile == 3)
+ f(1, profile_reserved_zero);
+
+ f(1, show_existing_frame);
+ if (current->show_existing_frame) {
+ f(3, frame_to_show_map_idx);
+ infer(header_size_in_bytes, 0);
+ infer(refresh_frame_flags, 0x00);
+ infer(loop_filter_level, 0);
+ return 0;
+ }
+
+ f(1, frame_type);
+ f(1, show_frame);
+ f(1, error_resilient_mode);
+
+ if (current->frame_type == VP9_KEY_FRAME) {
+ CHECK(FUNC(frame_sync_code)(ctx, rw, current));
+ CHECK(FUNC(color_config)(ctx, rw, current, profile));
+ CHECK(FUNC(frame_size)(ctx, rw, current));
+ CHECK(FUNC(render_size)(ctx, rw, current));
+
+ infer(refresh_frame_flags, 0xff);
+
+ } else {
+ if (current->show_frame == 0)
+ f(1, intra_only);
+ else
+ infer(intra_only, 0);
+
+ if (current->error_resilient_mode == 0)
+ f(2, reset_frame_context);
+ else
+ infer(reset_frame_context, 0);
+
+ if (current->intra_only == 1) {
+ CHECK(FUNC(frame_sync_code)(ctx, rw, current));
+
+ if (profile > 0) {
+ CHECK(FUNC(color_config)(ctx, rw, current, profile));
+ } else {
+ infer(color_space, 1);
+ infer(subsampling_x, 1);
+ infer(subsampling_y, 1);
+ }
+
+ f(8, refresh_frame_flags);
+
+ CHECK(FUNC(frame_size)(ctx, rw, current));
+ CHECK(FUNC(render_size)(ctx, rw, current));
+ } else {
+ f(8, refresh_frame_flags);
+
+ for (i = 0; i < VP9_REFS_PER_FRAME; i++) {
+ fs(3, ref_frame_idx[i], 1, i);
+ fs(1, ref_frame_sign_bias[VP9_LAST_FRAME + i],
+ 1, VP9_LAST_FRAME + i);
+ }
+
+ CHECK(FUNC(frame_size_with_refs)(ctx, rw, current));
+ f(1, allow_high_precision_mv);
+ CHECK(FUNC(interpolation_filter)(ctx, rw, current));
+ }
+ }
+
+ if (current->error_resilient_mode == 0) {
+ f(1, refresh_frame_context);
+ f(1, frame_parallel_decoding_mode);
+ } else {
+ infer(refresh_frame_context, 0);
+ infer(frame_parallel_decoding_mode, 1);
+ }
+
+ f(2, frame_context_idx);
+
+ CHECK(FUNC(loop_filter_params)(ctx, rw, current));
+ CHECK(FUNC(quantization_params)(ctx, rw, current));
+ CHECK(FUNC(segmentation_params)(ctx, rw, current));
+ CHECK(FUNC(tile_info)(ctx, rw, current));
+
+ f(16, header_size_in_bytes);
+
+ return 0;
+}
+
+static int FUNC(trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
+{
+ int err;
+ av_unused int zero = 0;
+ while (byte_alignment(rw) != 0)
+ xf(1, zero_bit, zero, 0);
+
+ return 0;
+}
+
+static int FUNC(frame)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawFrame *current)
+{
+ int err;
+
+ HEADER("Frame");
+
+ CHECK(FUNC(uncompressed_header)(ctx, rw, ¤t->header));
+
+ CHECK(FUNC(trailing_bits)(ctx, rw));
+
+ return 0;
+}
+
+static int FUNC(superframe_index)(CodedBitstreamContext *ctx, RWContext *rw,
+ VP9RawSuperframeIndex *current)
+{
+ int err, i;
+
+ HEADER("Superframe Index");
+
+ f(3, superframe_marker);
+ f(2, bytes_per_framesize_minus_1);
+ f(3, frames_in_superframe_minus_1);
+
+ for (i = 0; i <= current->frames_in_superframe_minus_1; i++) {
+ // Surprise little-endian!
+ fle(8 * (current->bytes_per_framesize_minus_1 + 1),
+ frame_sizes[i], 1, i);
+ }
+
+ f(3, superframe_marker);
+ f(2, bytes_per_framesize_minus_1);
+ f(3, frames_in_superframe_minus_1);
+
+ return 0;
+}
1
0
ffmpeg | branch: master | Mark Thompson <sw(a)jkqxz.net> | 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=300ef253141fbebf9…
---
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_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) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
@@ -82,7 +84,8 @@ static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
}
static int cbs_read_se_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
- const char *name, int32_t *write_to,
+ const char *name, const int *subscripts,
+ int32_t *write_to,
int32_t range_min, int32_t range_max)
{
int32_t value;
@@ -122,7 +125,8 @@ static int cbs_read_se_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
value = v / 2;
if (ctx->trace_enable)
- 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) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
@@ -136,7 +140,8 @@ static int cbs_read_se_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
}
static int cbs_write_ue_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
- const char *name, uint32_t value,
+ const char *name, const int *subscripts,
+ uint32_t value,
uint32_t range_min, uint32_t range_max)
{
int len;
@@ -164,7 +169,8 @@ static int cbs_write_ue_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
bits[len + i + 1] = (value + 1) >> (len - i - 1) & 1 ? '1' : '0';
bits[len + len + 1] = 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);
}
put_bits(pbc, len, 0);
@@ -177,7 +183,8 @@ static int cbs_write_ue_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
}
static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
- const char *name, int32_t value,
+ const char *name, const int *subscripts,
+ int32_t value,
int32_t range_min, int32_t range_max)
{
int len;
@@ -213,7 +220,8 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
bits[len + i + 1] = (uvalue + 1) >> (len - i - 1) & 1 ? '1' : '0';
bits[len + len + 1] = 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);
}
put_bits(pbc, len, 0);
@@ -239,9 +247,28 @@ 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 SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
+
+#define u(width, name, range_min, range_max) \
+ xu(width, name, current->name, range_min, range_max, 0)
+#define flag(name) u(1, name, 0, 1)
+#define ue(name, range_min, range_max) \
+ xue(name, current->name, range_min, range_max, 0)
+#define se(name, range_min, range_max) \
+ xse(name, current->name, range_min, range_max, 0)
+
+#define us(width, name, range_min, range_max, subs, ...) \
+ xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
+#define flags(name, subs, ...) \
+ xu(1, name, current->name, 0, 1, subs, __VA_ARGS__)
+#define ues(name, range_min, range_max, subs, ...) \
+ xue(name, current->name, range_min, range_max, subs, __VA_ARGS__)
+#define ses(name, range_min, range_max, subs, ...) \
+ xse(name, current->name, range_min, range_max, subs, __VA_ARGS__)
+
#define fixed(width, name, value) do { \
av_unused uint32_t fixed_value = value; \
- xu(width, name, fixed_value, value, value); \
+ xu(width, name, fixed_value, value, value, 0); \
} while (0)
@@ -249,34 +276,29 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc,
#define READWRITE read
#define RWContext GetBitContext
-#define xu(width, name, var, range_min, range_max) do { \
+#define xu(width, name, var, range_min, range_max, subs, ...) do { \
uint32_t value = range_min; \
CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), \
&value, range_min, range_max)); \
var = value; \
} while (0)
-#define xue(name, var, range_min, range_max) do { \
+#define xue(name, var, range_min, range_max, subs, ...) do { \
uint32_t value = range_min; \
CHECK(cbs_read_ue_golomb(ctx, rw, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), \
&value, range_min, range_max)); \
var = value; \
} while (0)
-#define xse(name, var, range_min, range_max) do { \
+#define xse(name, var, range_min, range_max, subs, ...) do { \
int32_t value = range_min; \
CHECK(cbs_read_se_golomb(ctx, rw, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), \
&value, range_min, range_max)); \
var = value; \
} while (0)
-#define u(width, name, range_min, range_max) \
- xu(width, name, current->name, range_min, range_max)
-#define flag(name) u(1, name, 0, 1)
-#define ue(name, range_min, range_max) \
- xue(name, current->name, range_min, range_max)
-#define se(name, range_min, range_max) \
- xse(name, current->name, range_min, range_max)
-
#define infer(name, value) do { \
current->name = value; \
} while (0)
@@ -316,10 +338,6 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
#undef xu
#undef xue
#undef xse
-#undef u
-#undef flag
-#undef ue
-#undef se
#undef infer
#undef more_rbsp_data
#undef byte_alignment
@@ -330,30 +348,25 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
#define READWRITE write
#define RWContext PutBitContext
-#define xu(width, name, var, range_min, range_max) do { \
+#define xu(width, name, var, range_min, range_max, subs, ...) do { \
uint32_t value = var; \
CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), \
value, range_min, range_max)); \
} while (0)
-#define xue(name, var, range_min, range_max) do { \
+#define xue(name, var, range_min, range_max, subs, ...) do { \
uint32_t value = var; \
CHECK(cbs_write_ue_golomb(ctx, rw, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), \
value, range_min, range_max)); \
} while (0)
-#define xse(name, var, range_min, range_max) do { \
+#define xse(name, var, range_min, range_max, subs, ...) do { \
int32_t value = var; \
CHECK(cbs_write_se_golomb(ctx, rw, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), \
value, range_min, range_max)); \
} while (0)
-#define u(width, name, range_min, range_max) \
- xu(width, name, current->name, range_min, range_max)
-#define flag(name) u(1, name, 0, 1)
-#define ue(name, range_min, range_max) \
- xue(name, current->name, range_min, range_max)
-#define se(name, range_min, range_max) \
- xse(name, current->name, range_min, range_max)
-
#define infer(name, value) do { \
if (current->name != (value)) { \
av_log(ctx->log_ctx, AV_LOG_WARNING, "Warning: " \
diff --git a/libavcodec/cbs_h264_syntax_template.c b/libavcodec/cbs_h264_syntax_template.c
index 7c507b9a13..c3327f6e90 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -76,7 +76,7 @@ static int FUNC(scaling_list)(CodedBitstreamContext *ctx, RWContext *rw,
scale = 8;
for (i = 0; i < size_of_scaling_list; i++) {
- xse(delta_scale, current->delta_scale[i], -128, +127);
+ ses(delta_scale[i], -128, +127, 1, i);
scale = (scale + current->delta_scale[i] + 256) % 256;
if (scale == 0)
break;
@@ -95,9 +95,9 @@ static int FUNC(hrd_parameters)(CodedBitstreamContext *ctx, RWContext *rw,
u(4, cpb_size_scale, 0, 15);
for (i = 0; i <= current->cpb_cnt_minus1; i++) {
- ue(bit_rate_value_minus1[i], 0, UINT32_MAX - 1);
- ue(cpb_size_value_minus1[i], 0, UINT32_MAX - 1);
- flag(cbr_flag[i]);
+ ues(bit_rate_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
+ ues(cpb_size_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
+ flags(cbr_flag[i], 1, i);
}
u(5, initial_cpb_removal_delay_length_minus1, 0, 31);
@@ -256,7 +256,7 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw,
flag(seq_scaling_matrix_present_flag);
if (current->seq_scaling_matrix_present_flag) {
for (i = 0; i < ((current->chroma_format_idc != 3) ? 8 : 12); i++) {
- flag(seq_scaling_list_present_flag[i]);
+ flags(seq_scaling_list_present_flag[i], 1, i);
if (current->seq_scaling_list_present_flag[i]) {
if (i < 6)
CHECK(FUNC(scaling_list)(ctx, rw,
@@ -289,7 +289,7 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw,
ue(num_ref_frames_in_pic_order_cnt_cycle, 0, 255);
for (i = 0; i < current->num_ref_frames_in_pic_order_cnt_cycle; i++)
- se(offset_for_ref_frame[i], INT32_MIN + 1, INT32_MAX);
+ ses(offset_for_ref_frame[i], INT32_MIN + 1, INT32_MAX, 1, i);
}
ue(max_num_ref_frames, 0, H264_MAX_DPB_FRAMES);
@@ -390,12 +390,13 @@ static int FUNC(pps)(CodedBitstreamContext *ctx, RWContext *rw,
if (current->slice_group_map_type == 0) {
for (iGroup = 0; iGroup <= current->num_slice_groups_minus1; iGroup++)
- ue(run_length_minus1[iGroup], 0, pic_size - 1);
+ ues(run_length_minus1[iGroup], 0, pic_size - 1, 1, iGroup);
} else if (current->slice_group_map_type == 2) {
for (iGroup = 0; iGroup < current->num_slice_groups_minus1; iGroup++) {
- ue(top_left[iGroup], 0, pic_size - 1);
- ue(bottom_right[iGroup], current->top_left[iGroup], pic_size - 1);
+ ues(top_left[iGroup], 0, pic_size - 1, 1, iGroup);
+ ues(bottom_right[iGroup],
+ current->top_left[iGroup], pic_size - 1, 1, iGroup);
}
} else if (current->slice_group_map_type == 3 ||
current->slice_group_map_type == 4 ||
@@ -408,8 +409,8 @@ static int FUNC(pps)(CodedBitstreamContext *ctx, RWContext *rw,
allocate(current->slice_group_id,
current->pic_size_in_map_units_minus1 + 1);
for (i = 0; i <= current->pic_size_in_map_units_minus1; i++)
- u(av_log2(2 * current->num_slice_groups_minus1 + 1),
- slice_group_id[i], 0, current->num_slice_groups_minus1);
+ us(av_log2(2 * current->num_slice_groups_minus1 + 1),
+ slice_group_id[i], 0, current->num_slice_groups_minus1, 1, i);
}
}
@@ -435,7 +436,7 @@ static int FUNC(pps)(CodedBitstreamContext *ctx, RWContext *rw,
if (current->pic_scaling_matrix_present_flag) {
for (i = 0; i < 6 + (((sps->chroma_format_idc != 3) ? 2 : 6) *
current->transform_8x8_mode_flag); i++) {
- flag(pic_scaling_list_present_flag[i]);
+ flags(pic_scaling_list_present_flag[i], 1, i);
if (current->pic_scaling_list_present_flag[i]) {
if (i < 6)
CHECK(FUNC(scaling_list)(ctx, rw,
@@ -483,10 +484,10 @@ static int FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext *rw,
length = sps->vui.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1;
xu(length, initial_cpb_removal_delay[SchedSelIdx],
current->nal.initial_cpb_removal_delay[i],
- 1, MAX_UINT_BITS(length));
+ 1, MAX_UINT_BITS(length), 1, i);
xu(length, initial_cpb_removal_delay_offset[SchedSelIdx],
current->nal.initial_cpb_removal_delay_offset[i],
- 0, MAX_UINT_BITS(length));
+ 0, MAX_UINT_BITS(length), 1, i);
}
}
@@ -495,10 +496,10 @@ static int FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext *rw,
length = sps->vui.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1;
xu(length, initial_cpb_removal_delay[SchedSelIdx],
current->vcl.initial_cpb_removal_delay[i],
- 1, MAX_UINT_BITS(length));
+ 1, MAX_UINT_BITS(length), 1, i);
xu(length, initial_cpb_removal_delay_offset[SchedSelIdx],
current->vcl.initial_cpb_removal_delay_offset[i],
- 0, MAX_UINT_BITS(length));
+ 0, MAX_UINT_BITS(length), 1, i);
}
}
@@ -616,7 +617,7 @@ static int FUNC(sei_pic_timing)(CodedBitstreamContext *ctx, RWContext *rw,
return AVERROR_INVALIDDATA;
for (i = 0; i < num_clock_ts[current->pic_struct]; i++) {
- flag(clock_timestamp_flag[i]);
+ flags(clock_timestamp_flag[i], 1, i);
if (current->clock_timestamp_flag[i])
CHECK(FUNC(sei_pic_timestamp)(ctx, rw, ¤t->timestamp[i]));
}
@@ -652,7 +653,7 @@ static int FUNC(sei_user_data_registered)(CodedBitstreamContext *ctx, RWContext
allocate(current->data, current->data_length);
for (j = 0; j < current->data_length; j++)
- xu(8, itu_t_t35_payload_byte, current->data[j], 0x00, 0xff);
+ xu(8, itu_t_t35_payload_byte[i], current->data[j], 0x00, 0xff, 1, i + j);
return 0;
}
@@ -674,15 +675,13 @@ static int FUNC(sei_user_data_unregistered)(CodedBitstreamContext *ctx, RWContex
*payload_size = 16 + current->data_length;
#endif
- for (i = 0; i < 16; i++) {
- xu(8, uuid_iso_iec_11578,
- current->uuid_iso_iec_11578[i], 0x00, 0xff);
- }
+ for (i = 0; i < 16; i++)
+ us(8, uuid_iso_iec_11578[i], 0x00, 0xff, 1, i);
allocate(current->data, current->data_length);
for (i = 0; i < current->data_length; i++)
- xu(8, user_data_payload_byte, current->data[i], 0x00, 0xff);
+ xu(8, user_data_payload_byte[i], current->data[i], 0x00, 0xff, 1, i);
return 0;
}
@@ -764,7 +763,7 @@ static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
{
allocate(current->payload.other.data, current->payload_size);
for (i = 0; i < current->payload_size; i++)
- xu(8, payload_byte, current->payload.other.data[i], 0, 255);
+ xu(8, payload_byte, current->payload.other.data[i], 0, 255, 1, i);
}
}
@@ -811,14 +810,14 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext *rw,
fixed(8, ff_byte, 0xff);
payload_type += 255;
}
- xu(8, last_payload_type_byte, tmp, 0, 254);
+ xu(8, last_payload_type_byte, tmp, 0, 254, 0);
payload_type += tmp;
while (show_bits(rw, 8) == 0xff) {
fixed(8, ff_byte, 0xff);
payload_size += 255;
}
- xu(8, last_payload_size_byte, tmp, 0, 254);
+ xu(8, last_payload_size_byte, tmp, 0, 254, 0);
payload_size += tmp;
current->payload[k].payload_type = payload_type;
@@ -854,14 +853,14 @@ static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext *rw,
fixed(8, ff_byte, 0xff);
tmp -= 255;
}
- xu(8, last_payload_type_byte, tmp, 0, 254);
+ xu(8, last_payload_type_byte, tmp, 0, 254, 0);
tmp = current->payload[k].payload_size;
while (tmp >= 255) {
fixed(8, ff_byte, 0xff);
tmp -= 255;
}
- xu(8, last_payload_size_byte, tmp, 0, 254);
+ xu(8, last_payload_size_byte, tmp, 0, 254, 0);
CHECK(FUNC(sei_payload)(ctx, rw, ¤t->payload[k]));
}
@@ -903,7 +902,7 @@ static int FUNC(ref_pic_list_modification)(CodedBitstreamContext *ctx, RWContext
if (current->ref_pic_list_modification_flag_l0) {
for (i = 0; i < H264_MAX_RPLM_COUNT; i++) {
xue(modification_of_pic_nums_idc,
- current->rplm_l0[i].modification_of_pic_nums_idc, 0, 3);
+ current->rplm_l0[i].modification_of_pic_nums_idc, 0, 3, 0);
mopn = current->rplm_l0[i].modification_of_pic_nums_idc;
if (mopn == 3)
@@ -913,11 +912,11 @@ static int FUNC(ref_pic_list_modification)(CodedBitstreamContext *ctx, RWContext
xue(abs_diff_pic_num_minus1,
current->rplm_l0[i].abs_diff_pic_num_minus1,
0, (1 + current->field_pic_flag) *
- (1 << (sps->log2_max_frame_num_minus4 + 4)));
+ (1 << (sps->log2_max_frame_num_minus4 + 4)), 0);
else if (mopn == 2)
xue(long_term_pic_num,
current->rplm_l0[i].long_term_pic_num,
- 0, sps->max_num_ref_frames - 1);
+ 0, sps->max_num_ref_frames - 1, 0);
}
}
}
@@ -927,7 +926,7 @@ static int FUNC(ref_pic_list_modification)(CodedBitstreamContext *ctx, RWContext
if (current->ref_pic_list_modification_flag_l1) {
for (i = 0; i < H264_MAX_RPLM_COUNT; i++) {
xue(modification_of_pic_nums_idc,
- current->rplm_l1[i].modification_of_pic_nums_idc, 0, 3);
+ current->rplm_l1[i].modification_of_pic_nums_idc, 0, 3, 0);
mopn = current->rplm_l1[i].modification_of_pic_nums_idc;
if (mopn == 3)
@@ -937,11 +936,11 @@ static int FUNC(ref_pic_list_modification)(CodedBitstreamContext *ctx, RWContext
xue(abs_diff_pic_num_minus1,
current->rplm_l1[i].abs_diff_pic_num_minus1,
0, (1 + current->field_pic_flag) *
- (1 << (sps->log2_max_frame_num_minus4 + 4)));
+ (1 << (sps->log2_max_frame_num_minus4 + 4)), 0);
else if (mopn == 2)
xue(long_term_pic_num,
current->rplm_l1[i].long_term_pic_num,
- 0, sps->max_num_ref_frames - 1);
+ 0, sps->max_num_ref_frames - 1, 0);
}
}
}
@@ -964,17 +963,17 @@ static int FUNC(pred_weight_table)(CodedBitstreamContext *ctx, RWContext *rw,
ue(chroma_log2_weight_denom, 0, 7);
for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
- flag(luma_weight_l0_flag[i]);
+ flags(luma_weight_l0_flag[i], 1, i);
if (current->luma_weight_l0_flag[i]) {
- se(luma_weight_l0[i], -128, +127);
- se(luma_offset_l0[i], -128, +127);
+ ses(luma_weight_l0[i], -128, +127, 1, i);
+ ses(luma_offset_l0[i], -128, +127, 1, i);
}
if (chroma) {
- flag(chroma_weight_l0_flag[i]);
+ flags(chroma_weight_l0_flag[i], 1, i);
if (current->chroma_weight_l0_flag[i]) {
for (j = 0; j < 2; j++) {
- se(chroma_weight_l0[i][j], -128, +127);
- se(chroma_offset_l0[i][j], -128, +127);
+ ses(chroma_weight_l0[i][j], -128, +127, 2, i, j);
+ ses(chroma_offset_l0[i][j], -128, +127, 2, i, j);
}
}
}
@@ -982,17 +981,17 @@ static int FUNC(pred_weight_table)(CodedBitstreamContext *ctx, RWContext *rw,
if (current->slice_type % 5 == 1) {
for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
- flag(luma_weight_l1_flag[i]);
+ flags(luma_weight_l1_flag[i], 1, i);
if (current->luma_weight_l1_flag[i]) {
- se(luma_weight_l1[i], -128, +127);
- se(luma_offset_l1[i], -128, +127);
+ ses(luma_weight_l1[i], -128, +127, 1, i);
+ ses(luma_offset_l1[i], -128, +127, 1, i);
}
if (chroma) {
- flag(chroma_weight_l1_flag[i]);
+ flags(chroma_weight_l1_flag[i], 1, i);
if (current->chroma_weight_l1_flag[i]) {
for (j = 0; j < 2; j++) {
- se(chroma_weight_l1[i][j], -128, +127);
- se(chroma_offset_l1[i][j], -128, +127);
+ ses(chroma_weight_l1[i][j], -128, +127, 2, i, j);
+ ses(chroma_offset_l1[i][j], -128, +127, 2, i, j);
}
}
}
@@ -1019,7 +1018,7 @@ static int FUNC(dec_ref_pic_marking)(CodedBitstreamContext *ctx, RWContext *rw,
for (i = 0; i < H264_MAX_MMCO_COUNT; i++) {
xue(memory_management_control_operation,
current->mmco[i].memory_management_control_operation,
- 0, 6);
+ 0, 6, 0);
mmco = current->mmco[i].memory_management_control_operation;
if (mmco == 0)
@@ -1028,19 +1027,19 @@ static int FUNC(dec_ref_pic_marking)(CodedBitstreamContext *ctx, RWContext *rw,
if (mmco == 1 || mmco == 3)
xue(difference_of_pic_nums_minus1,
current->mmco[i].difference_of_pic_nums_minus1,
- 0, INT32_MAX);
+ 0, INT32_MAX, 0);
if (mmco == 2)
xue(long_term_pic_num,
current->mmco[i].long_term_pic_num,
- 0, sps->max_num_ref_frames - 1);
+ 0, sps->max_num_ref_frames - 1, 0);
if (mmco == 3 || mmco == 6)
xue(long_term_frame_idx,
current->mmco[i].long_term_frame_idx,
- 0, sps->max_num_ref_frames - 1);
+ 0, sps->max_num_ref_frames - 1, 0);
if (mmco == 4)
xue(max_long_term_frame_idx_plus1,
current->mmco[i].max_long_term_frame_idx_plus1,
- 0, sps->max_num_ref_frames);
+ 0, sps->max_num_ref_frames, 0);
}
if (i == H264_MAX_MMCO_COUNT) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many "
diff --git a/libavcodec/cbs_h265_syntax_template.c b/libavcodec/cbs_h265_syntax_template.c
index 58a79f3014..9f13061f38 100644
--- a/libavcodec/cbs_h265_syntax_template.c
+++ b/libavcodec/cbs_h265_syntax_template.c
@@ -74,13 +74,13 @@ static int FUNC(extension_data)(CodedBitstreamContext *ctx, RWContext *rw,
*rw = start;
allocate(current->data, (current->bit_length + 7) / 8);
for (k = 0; k < current->bit_length; k++) {
- xu(1, extension_data, bit, 0, 1);
+ xu(1, extension_data, bit, 0, 1, 0);
current->data[k / 8] |= bit << (7 - k % 8);
}
}
#else
for (k = 0; k < current->bit_length; k++)
- xu(1, extension_data, current->data[k / 8] >> (7 - k % 8), 0, 1);
+ xu(1, extension_data, current->data[k / 8] >> (7 - k % 8), 0, 1, 0);
#endif
return 0;
}
@@ -98,7 +98,7 @@ static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
u(5, general_profile_idc, 0, 31);
for (j = 0; j < 32; j++)
- flag(general_profile_compatibility_flag[j]);
+ flags(general_profile_compatibility_flag[j], 1, j);
flag(general_progressive_source_flag);
flag(general_interlaced_source_flag);
@@ -148,8 +148,8 @@ static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
u(8, general_level_idc, 0, 255);
for (i = 0; i < max_num_sub_layers_minus1; i++) {
- flag(sub_layer_profile_present_flag[i]);
- flag(sub_layer_level_present_flag[i]);
+ flags(sub_layer_profile_present_flag[i], 1, i);
+ flags(sub_layer_level_present_flag[i], 1, i);
}
if (max_num_sub_layers_minus1 > 0) {
@@ -180,13 +180,13 @@ static int FUNC(sub_layer_hrd_parameters)(CodedBitstreamContext *ctx, RWContext
current = &hrd->vcl_sub_layer_hrd_parameters[sub_layer_id];
for (i = 0; i <= hrd->cpb_cnt_minus1[sub_layer_id]; i++) {
- ue(bit_rate_value_minus1[i], 0, UINT32_MAX - 1);
- ue(cpb_size_value_minus1[i], 0, UINT32_MAX - 1);
+ ues(bit_rate_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
+ ues(cpb_size_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
if (hrd->sub_pic_hrd_params_present_flag) {
- ue(cpb_size_du_value_minus1[i], 0, UINT32_MAX - 1);
- ue(bit_rate_du_value_minus1[i], 0, UINT32_MAX - 1);
+ ues(cpb_size_du_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
+ ues(bit_rate_du_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
}
- flag(cbr_flag[i]);
+ flags(cbr_flag[i], 1, i);
}
return 0;
@@ -230,21 +230,21 @@ static int FUNC(hrd_parameters)(CodedBitstreamContext *ctx, RWContext *rw,
}
for (i = 0; i <= max_num_sub_layers_minus1; i++) {
- flag(fixed_pic_rate_general_flag[i]);
+ flags(fixed_pic_rate_general_flag[i], 1, i);
if (!current->fixed_pic_rate_general_flag[i])
- flag(fixed_pic_rate_within_cvs_flag[i]);
+ flags(fixed_pic_rate_within_cvs_flag[i], 1, i);
else
infer(fixed_pic_rate_within_cvs_flag[i], 1);
if (current->fixed_pic_rate_within_cvs_flag[i]) {
- ue(elemental_duration_in_tc_minus1[i], 0, 2047);
+ ues(elemental_duration_in_tc_minus1[i], 0, 2047, 1, i);
infer(low_delay_hrd_flag[i], 0);
} else
- flag(low_delay_hrd_flag[i]);
+ flags(low_delay_hrd_flag[i], 1, i);
if (!current->low_delay_hrd_flag[i])
- ue(cpb_cnt_minus1[i], 0, 31);
+ ues(cpb_cnt_minus1[i], 0, 31, 1, i);
else
infer(cpb_cnt_minus1[i], 0);
@@ -392,9 +392,12 @@ static int FUNC(vps)(CodedBitstreamContext *ctx, RWContext *rw,
for (i = (current->vps_sub_layer_ordering_info_present_flag ?
0 : current->vps_max_sub_layers_minus1);
i <= current->vps_max_sub_layers_minus1; i++) {
- ue(vps_max_dec_pic_buffering_minus1[i], 0, HEVC_MAX_DPB_SIZE - 1);
- ue(vps_max_num_reorder_pics[i], 0, current->vps_max_dec_pic_buffering_minus1[i]);
- ue(vps_max_latency_increase_plus1[i], 0, UINT32_MAX - 1);
+ ues(vps_max_dec_pic_buffering_minus1[i],
+ 0, HEVC_MAX_DPB_SIZE - 1, 1, i);
+ ues(vps_max_num_reorder_pics[i],
+ 0, current->vps_max_dec_pic_buffering_minus1[i], 1, i);
+ ues(vps_max_latency_increase_plus1[i],
+ 0, UINT32_MAX - 1, 1, i);
}
if (!current->vps_sub_layer_ordering_info_present_flag) {
for (i = 0; i < current->vps_max_sub_layers_minus1; i++) {
@@ -411,7 +414,7 @@ static int FUNC(vps)(CodedBitstreamContext *ctx, RWContext *rw,
ue(vps_num_layer_sets_minus1, 0, HEVC_MAX_LAYER_SETS - 1);
for (i = 1; i <= current->vps_num_layer_sets_minus1; i++) {
for (j = 0; j <= current->vps_max_layer_id; j++)
- flag(layer_id_included_flag[i][j]);
+ flags(layer_id_included_flag[i][j], 2, i, j);
}
for (j = 0; j <= current->vps_max_layer_id; j++)
infer(layer_id_included_flag[0][j], j == 0);
@@ -425,11 +428,11 @@ static int FUNC(vps)(CodedBitstreamContext *ctx, RWContext *rw,
ue(vps_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
ue(vps_num_hrd_parameters, 0, current->vps_num_layer_sets_minus1 + 1);
for (i = 0; i < current->vps_num_hrd_parameters; i++) {
- ue(hrd_layer_set_idx[i],
- current->vps_base_layer_internal_flag ? 0 : 1,
- current->vps_num_layer_sets_minus1);
+ ues(hrd_layer_set_idx[i],
+ current->vps_base_layer_internal_flag ? 0 : 1,
+ current->vps_num_layer_sets_minus1, 1, i);
if (i > 0)
- flag(cprms_present_flag[i]);
+ flags(cprms_present_flag[i], 1, i);
else
infer(cprms_present_flag[0], 1);
@@ -483,9 +486,9 @@ static int FUNC(st_ref_pic_set)(CodedBitstreamContext *ctx, RWContext *rw,
(current->abs_delta_rps_minus1 + 1);
for (j = 0; j <= num_delta_pocs; j++) {
- flag(used_by_curr_pic_flag[j]);
+ flags(used_by_curr_pic_flag[j], 1, j);
if (!current->used_by_curr_pic_flag[j])
- flag(use_delta_flag[j]);
+ flags(use_delta_flag[j], 1, j);
else
infer(use_delta_flag[j], 1);
}
@@ -580,13 +583,13 @@ static int FUNC(st_ref_pic_set)(CodedBitstreamContext *ctx, RWContext *rw,
ue(num_positive_pics, 0, 15 - current->num_negative_pics);
for (i = 0; i < current->num_negative_pics; i++) {
- ue(delta_poc_s0_minus1[i], 0, INT16_MAX);
- flag(used_by_curr_pic_s0_flag[i]);
+ ues(delta_poc_s0_minus1[i], 0, INT16_MAX, 1, i);
+ flags(used_by_curr_pic_s0_flag[i], 1, i);
}
for (i = 0; i < current->num_positive_pics; i++) {
- ue(delta_poc_s1_minus1[i], 0, INT16_MAX);
- flag(used_by_curr_pic_s1_flag[i]);
+ ues(delta_poc_s1_minus1[i], 0, INT16_MAX, 1, i);
+ flags(used_by_curr_pic_s1_flag[i], 1, i);
}
}
@@ -601,18 +604,21 @@ static int FUNC(scaling_list_data)(CodedBitstreamContext *ctx, RWContext *rw,
for (sizeId = 0; sizeId < 4; sizeId++) {
for (matrixId = 0; matrixId < 6; matrixId += (sizeId == 3 ? 3 : 1)) {
- flag(scaling_list_pred_mode_flag[sizeId][matrixId]);
+ flags(scaling_list_pred_mode_flag[sizeId][matrixId],
+ 2, sizeId, matrixId);
if (!current->scaling_list_pred_mode_flag[sizeId][matrixId]) {
- ue(scaling_list_pred_matrix_id_delta[sizeId][matrixId],
- 0, sizeId == 3 ? matrixId / 3 : matrixId);
+ ues(scaling_list_pred_matrix_id_delta[sizeId][matrixId],
+ 0, sizeId == 3 ? matrixId / 3 : matrixId,
+ 2, sizeId, matrixId);
} else {
n = FFMIN(64, 1 << (4 + (sizeId << 1)));
- if (sizeId > 1)
- se(scaling_list_dc_coef_minus8[sizeId - 2][matrixId], -7, +247);
+ if (sizeId > 1) {
+ ses(scaling_list_dc_coef_minus8[sizeId - 2][matrixId], -7, +247,
+ 2, sizeId - 2, matrixId);
+ }
for (i = 0; i < n; i++) {
- xse(scaling_list_delta_coeff,
- current->scaling_list_delta_coeff[sizeId][matrixId][i],
- -128, +127);
+ ses(scaling_list_delta_coeff[sizeId][matrixId][i],
+ -128, +127, 3, sizeId, matrixId, i);
}
}
}
@@ -658,8 +664,8 @@ static int FUNC(sps_scc_extension)(CodedBitstreamContext *ctx, RWContext *rw,
int bit_depth = comp == 0 ? current->bit_depth_luma_minus8 + 8
: current->bit_depth_chroma_minus8 + 8;
for (i = 0; i <= current->sps_num_palette_predictor_initializer_minus1; i++)
- u(bit_depth, sps_palette_predictor_initializers[comp][i],
- 0, MAX_UINT_BITS(bit_depth));
+ us(bit_depth, sps_palette_predictor_initializers[comp][i],
+ 0, MAX_UINT_BITS(bit_depth), 2, comp, i);
}
}
}
@@ -742,9 +748,12 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw,
for (i = (current->sps_sub_layer_ordering_info_present_flag ?
0 : current->sps_max_sub_layers_minus1);
i <= current->sps_max_sub_layers_minus1; i++) {
- ue(sps_max_dec_pic_buffering_minus1[i], 0, HEVC_MAX_DPB_SIZE - 1);
- ue(sps_max_num_reorder_pics[i], 0, current->sps_max_dec_pic_buffering_minus1[i]);
- ue(sps_max_latency_increase_plus1[i], 0, UINT32_MAX - 1);
+ ues(sps_max_dec_pic_buffering_minus1[i],
+ 0, HEVC_MAX_DPB_SIZE - 1, 1, i);
+ ues(sps_max_num_reorder_pics[i],
+ 0, current->sps_max_dec_pic_buffering_minus1[i], 1, i);
+ ues(sps_max_latency_increase_plus1[i],
+ 0, UINT32_MAX - 1, 1, i);
}
if (!current->sps_sub_layer_ordering_info_present_flag) {
for (i = 0; i < current->sps_max_sub_layers_minus1; i++) {
@@ -819,10 +828,10 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw,
if (current->long_term_ref_pics_present_flag) {
ue(num_long_term_ref_pics_sps, 0, HEVC_MAX_LONG_TERM_REF_PICS);
for (i = 0; i < current->num_long_term_ref_pics_sps; i++) {
- u(current->log2_max_pic_order_cnt_lsb_minus4 + 4,
- lt_ref_pic_poc_lsb_sps[i],
- 0, MAX_UINT_BITS(current->log2_max_pic_order_cnt_lsb_minus4 + 4));
- flag(used_by_curr_pic_lt_sps_flag[i]);
+ us(current->log2_max_pic_order_cnt_lsb_minus4 + 4,
+ lt_ref_pic_poc_lsb_sps[i],
+ 0, MAX_UINT_BITS(current->log2_max_pic_order_cnt_lsb_minus4 + 4), 1, i);
+ flags(used_by_curr_pic_lt_sps_flag[i], 1, i);
}
}
@@ -875,8 +884,8 @@ static int FUNC(pps_range_extension)(CodedBitstreamContext *ctx, RWContext *rw,
0, sps->log2_diff_max_min_luma_coding_block_size);
ue(chroma_qp_offset_list_len_minus1, 0, 5);
for (i = 0; i <= current->chroma_qp_offset_list_len_minus1; i++) {
- se(cb_qp_offset_list[i], -12, +12);
- se(cr_qp_offset_list[i], -12, +12);
+ ses(cb_qp_offset_list[i], -12, +12, 1, i);
+ ses(cr_qp_offset_list[i], -12, +12, 1, i);
}
}
@@ -918,8 +927,8 @@ static int FUNC(pps_scc_extension)(CodedBitstreamContext *ctx, RWContext *rw,
int bit_depth = comp == 0 ? current->luma_bit_depth_entry_minus8 + 8
: current->chroma_bit_depth_entry_minus8 + 8;
for (i = 0; i < current->pps_num_palette_predictor_initializer; i++)
- u(bit_depth, pps_palette_predictor_initializers[comp][i],
- 0, MAX_UINT_BITS(bit_depth));
+ us(bit_depth, pps_palette_predictor_initializers[comp][i],
+ 0, MAX_UINT_BITS(bit_depth), 2, comp, i);
}
}
}
@@ -985,9 +994,9 @@ static int FUNC(pps)(CodedBitstreamContext *ctx, RWContext *rw,
flag(uniform_spacing_flag);
if (!current->uniform_spacing_flag) {
for (i = 0; i < current->num_tile_columns_minus1; i++)
- ue(column_width_minus1[i], 0, sps->pic_width_in_luma_samples);
+ ues(column_width_minus1[i], 0, sps->pic_width_in_luma_samples, 1, i);
for (i = 0; i < current->num_tile_rows_minus1; i++)
- ue(row_height_minus1[i], 0, sps->pic_height_in_luma_samples);
+ ues(row_height_minus1[i], 0, sps->pic_height_in_luma_samples, 1, i);
}
flag(loop_filter_across_tiles_enabled_flag);
} else {
@@ -1078,14 +1087,14 @@ static int FUNC(ref_pic_lists_modification)(CodedBitstreamContext *ctx, RWContex
flag(ref_pic_list_modification_flag_l0);
if (current->ref_pic_list_modification_flag_l0) {
for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++)
- u(entry_size, list_entry_l0[i], 0, num_pic_total_curr - 1);
+ us(entry_size, list_entry_l0[i], 0, num_pic_total_curr - 1, 1, i);
}
if (current->slice_type == HEVC_SLICE_B) {
flag(ref_pic_list_modification_flag_l1);
if (current->ref_pic_list_modification_flag_l1) {
for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++)
- u(entry_size, list_entry_l1[i], 0, num_pic_total_curr - 1);
+ us(entry_size, list_entry_l1[i], 0, num_pic_total_curr - 1, 1, i);
}
}
@@ -1109,14 +1118,14 @@ static int FUNC(pred_weight_table)(CodedBitstreamContext *ctx, RWContext *rw,
for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
if (1 /* is not same POC and same layer_id */)
- flag(luma_weight_l0_flag[i]);
+ flags(luma_weight_l0_flag[i], 1, i);
else
infer(luma_weight_l0_flag[i], 0);
}
if (chroma) {
for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
if (1 /* is not same POC and same layer_id */)
- flag(chroma_weight_l0_flag[i]);
+ flags(chroma_weight_l0_flag[i], 1, i);
else
infer(chroma_weight_l0_flag[i], 0);
}
@@ -1124,20 +1133,20 @@ static int FUNC(pred_weight_table)(CodedBitstreamContext *ctx, RWContext *rw,
for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
if (current->luma_weight_l0_flag[i]) {
- se(delta_luma_weight_l0[i], -128, +127);
- se(luma_offset_l0[i],
- -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
- ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1));
+ ses(delta_luma_weight_l0[i], -128, +127, 1, i);
+ ses(luma_offset_l0[i],
+ -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
+ ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
} else {
infer(delta_luma_weight_l0[i], 0);
infer(luma_offset_l0[i], 0);
}
if (current->chroma_weight_l0_flag[i]) {
for (j = 0; j < 2; j++) {
- se(delta_chroma_weight_l0[i][j], -128, +127);
- se(chroma_offset_l0[i][j],
- -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
- ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1));
+ ses(delta_chroma_weight_l0[i][j], -128, +127, 2, i, j);
+ ses(chroma_offset_l0[i][j],
+ -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
+ ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
}
} else {
for (j = 0; j < 2; j++) {
@@ -1150,14 +1159,14 @@ static int FUNC(pred_weight_table)(CodedBitstreamContext *ctx, RWContext *rw,
if (current->slice_type == HEVC_SLICE_B) {
for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
- flag(luma_weight_l1_flag[i]);
+ flags(luma_weight_l1_flag[i], 1, i);
else
infer(luma_weight_l1_flag[i], 0);
}
if (chroma) {
for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
- flag(chroma_weight_l1_flag[i]);
+ flags(chroma_weight_l1_flag[i], 1, i);
else
infer(chroma_weight_l1_flag[i], 0);
}
@@ -1165,20 +1174,20 @@ static int FUNC(pred_weight_table)(CodedBitstreamContext *ctx, RWContext *rw,
for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
if (current->luma_weight_l1_flag[i]) {
- se(delta_luma_weight_l1[i], -128, +127);
- se(luma_offset_l1[i],
- -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
- ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1));
+ ses(delta_luma_weight_l1[i], -128, +127, 1, i);
+ ses(luma_offset_l1[i],
+ -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
+ ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
} else {
infer(delta_luma_weight_l1[i], 0);
infer(luma_offset_l1[i], 0);
}
if (current->chroma_weight_l1_flag[i]) {
for (j = 0; j < 2; j++) {
- se(delta_chroma_weight_l1[i][j], -128, +127);
- se(chroma_offset_l1[i][j],
- -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
- ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1));
+ ses(delta_chroma_weight_l1[i][j], -128, +127, 2, i, j);
+ ses(chroma_offset_l1[i][j],
+ -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
+ ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
}
} else {
for (j = 0; j < 2; j++) {
@@ -1253,7 +1262,7 @@ static int FUNC(slice_segment_header)(CodedBitstreamContext *ctx, RWContext *rw,
if (!current->dependent_slice_segment_flag) {
for (i = 0; i < pps->num_extra_slice_header_bits; i++)
- flag(slice_reserved_flag[i]);
+ flags(slice_reserved_flag[i], 1, i);
ue(slice_type, 0, 2);
@@ -1309,20 +1318,20 @@ static int FUNC(slice_segment_header)(CodedBitstreamContext *ctx, RWContext *rw,
current->num_long_term_pics; i++) {
if (i < current->num_long_term_sps) {
if (sps->num_long_term_ref_pics_sps > 1)
- u(idx_size, lt_idx_sps[i],
- 0, sps->num_long_term_ref_pics_sps - 1);
+ us(idx_size, lt_idx_sps[i],
+ 0, sps->num_long_term_ref_pics_sps - 1, 1, i);
if (sps->used_by_curr_pic_lt_sps_flag[current->lt_idx_sps[i]])
++num_pic_total_curr;
} else {
- u(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, poc_lsb_lt[i],
- 0, MAX_UINT_BITS(sps->log2_max_pic_order_cnt_lsb_minus4 + 4));
- flag(used_by_curr_pic_lt_flag[i]);
+ us(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, poc_lsb_lt[i],
+ 0, MAX_UINT_BITS(sps->log2_max_pic_order_cnt_lsb_minus4 + 4), 1, i);
+ flags(used_by_curr_pic_lt_flag[i], 1, i);
if (current->used_by_curr_pic_lt_flag[i])
++num_pic_total_curr;
}
- flag(delta_poc_msb_present_flag[i]);
+ flags(delta_poc_msb_present_flag[i], 1, i);
if (current->delta_poc_msb_present_flag[i])
- ue(delta_poc_msb_cycle_lt[i], 0, UINT32_MAX - 1);
+ ues(delta_poc_msb_cycle_lt[i], 0, UINT32_MAX - 1, 1, i);
else
infer(delta_poc_msb_cycle_lt[i], 0);
}
@@ -1480,15 +1489,15 @@ static int FUNC(slice_segment_header)(CodedBitstreamContext *ctx, RWContext *rw,
if (current->num_entry_point_offsets > 0) {
ue(offset_len_minus1, 0, 31);
for (i = 0; i < current->num_entry_point_offsets; i++)
- u(current->offset_len_minus1 + 1, entry_point_offset_minus1[i],
- 0, MAX_UINT_BITS(current->offset_len_minus1 + 1));
+ us(current->offset_len_minus1 + 1, entry_point_offset_minus1[i],
+ 0, MAX_UINT_BITS(current->offset_len_minus1 + 1), 1, i);
}
}
if (pps->slice_segment_header_extension_present_flag) {
ue(slice_segment_header_extension_length, 0, 256);
for (i = 0; i < current->slice_segment_header_extension_length; i++)
- u(8, slice_segment_header_extension_data_byte[i], 0x00, 0xff);
+ us(8, slice_segment_header_extension_data_byte[i], 0x00, 0xff, 1, i);
}
CHECK(FUNC(byte_alignment)(ctx, rw));
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index be540e2a44..3280e7602d 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -63,8 +63,8 @@ typedef struct CodedBitstreamType {
void ff_cbs_trace_header(CodedBitstreamContext *ctx,
const char *name);
-void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx,
- int position, const char *name,
+void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position,
+ const char *name, const int *subscripts,
const char *bitstring, int64_t value);
@@ -72,11 +72,13 @@ void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx,
// generation of trace output.
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);
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);
// The largest value representable in N bits, suitable for use as
diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 8ca47061fe..0df4234b12 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -38,24 +38,29 @@
#define FUNC_MPEG2(rw, name) FUNC_NAME(rw, mpeg2, name)
#define FUNC(name) FUNC_MPEG2(READWRITE, name)
+#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
+
+#define ui(width, name) \
+ xui(width, name, current->name, 0)
+#define uis(width, name, subs, ...) \
+ xui(width, name, current->name, subs, __VA_ARGS__)
+
#define READ
#define READWRITE read
#define RWContext GetBitContext
-#define xui(width, name, var) do { \
+#define xui(width, name, var, subs, ...) do { \
uint32_t value = 0; \
CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), \
&value, 0, (1 << width) - 1)); \
var = value; \
} while (0)
-#define ui(width, name) \
- xui(width, name, current->name)
-
#define marker_bit() do { \
av_unused uint32_t one; \
- CHECK(ff_cbs_read_unsigned(ctx, rw, 1, "marker_bit", &one, 1, 1)); \
+ CHECK(ff_cbs_read_unsigned(ctx, rw, 1, "marker_bit", NULL, &one, 1, 1)); \
} while (0)
#define nextbits(width, compare, var) \
@@ -68,7 +73,6 @@
#undef READWRITE
#undef RWContext
#undef xui
-#undef ui
#undef marker_bit
#undef nextbits
@@ -77,16 +81,14 @@
#define READWRITE write
#define RWContext PutBitContext
-#define xui(width, name, var) do { \
+#define xui(width, name, var, subs, ...) do { \
CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
+ SUBSCRIPTS(subs, __VA_ARGS__), \
var, 0, (1 << width) - 1)); \
} while (0)
-#define ui(width, name) \
- xui(width, name, current->name)
-
#define marker_bit() do { \
- CHECK(ff_cbs_write_unsigned(ctx, rw, 1, "marker_bit", 1, 1, 1)); \
+ CHECK(ff_cbs_write_unsigned(ctx, rw, 1, "marker_bit", NULL, 1, 1, 1)); \
} while (0)
#define nextbits(width, compare, var) (var)
@@ -97,7 +99,6 @@
#undef READWRITE
#undef RWContext
#undef xui
-#undef ui
#undef marker_bit
#undef nextbits
diff --git a/libavcodec/cbs_mpeg2_syntax_template.c b/libavcodec/cbs_mpeg2_syntax_template.c
index 51c32cb58d..8b5d35437e 100644
--- a/libavcodec/cbs_mpeg2_syntax_template.c
+++ b/libavcodec/cbs_mpeg2_syntax_template.c
@@ -44,13 +44,13 @@ static int FUNC(sequence_header)(CodedBitstreamContext *ctx, RWContext *rw,
ui(1, load_intra_quantiser_matrix);
if (current->load_intra_quantiser_matrix) {
for (i = 0; i < 64; i++)
- ui(8, intra_quantiser_matrix[i]);
+ uis(8, intra_quantiser_matrix[i], 1, i);
}
ui(1, load_non_intra_quantiser_matrix);
if (current->load_non_intra_quantiser_matrix) {
for (i = 0; i < 64; i++)
- ui(8, non_intra_quantiser_matrix[i]);
+ uis(8, non_intra_quantiser_matrix[i], 1, i);
}
return 0;
@@ -79,7 +79,7 @@ static int FUNC(user_data)(CodedBitstreamContext *ctx, RWContext *rw,
#endif
for (k = 0; k < current->user_data_length; k++)
- xui(8, user_data, current->user_data[k]);
+ xui(8, user_data, current->user_data[k], 0);
return 0;
}
@@ -250,25 +250,25 @@ static int FUNC(quant_matrix_extension)(CodedBitstreamContext *ctx, RWContext *r
ui(1, load_intra_quantiser_matrix);
if (current->load_intra_quantiser_matrix) {
for (i = 0; i < 64; i++)
- ui(8, intra_quantiser_matrix[i]);
+ uis(8, intra_quantiser_matrix[i], 1, i);
}
ui(1, load_non_intra_quantiser_matrix);
if (current->load_non_intra_quantiser_matrix) {
for (i = 0; i < 64; i++)
- ui(8, non_intra_quantiser_matrix[i]);
+ uis(8, non_intra_quantiser_matrix[i], 1, i);
}
ui(1, load_chroma_intra_quantiser_matrix);
if (current->load_chroma_intra_quantiser_matrix) {
for (i = 0; i < 64; i++)
- ui(8, intra_quantiser_matrix[i]);
+ uis(8, intra_quantiser_matrix[i], 1, i);
}
ui(1, load_chroma_non_intra_quantiser_matrix);
if (current->load_chroma_non_intra_quantiser_matrix) {
for (i = 0; i < 64; i++)
- ui(8, chroma_non_intra_quantiser_matrix[i]);
+ uis(8, chroma_non_intra_quantiser_matrix[i], 1, i);
}
return 0;
@@ -366,15 +366,16 @@ static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw,
if (!current->extra_information)
return AVERROR(ENOMEM);
for (k = 0; k < current->extra_information_length; k++) {
- xui(1, extra_bit_slice, bit);
- xui(8, extra_information_slice,
- current->extra_information[k]);
+ xui(1, extra_bit_slice, bit, 0);
+ xui(8, extra_information_slice[k],
+ current->extra_information[k], 1, k);
}
}
#else
for (k = 0; k < current->extra_information_length; k++) {
- xui(1, extra_bit_slice, 1);
- xui(8, extra_information_slice, current->extra_information[k]);
+ xui(1, extra_bit_slice, 1, 0);
+ xui(8, extra_information_slice[k],
+ current->extra_information[k], 1, k);
}
#endif
}
1
0
ffmpeg | branch: master | Mark Thompson <sw(a)jkqxz.net> | 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=315cc8c0988da6e11…
---
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/libavcodec/cbs_h265_syntax_template.c
index 140c827c9d..58a79f3014 100644
--- a/libavcodec/cbs_h265_syntax_template.c
+++ b/libavcodec/cbs_h265_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;
}
@@ -50,10 +50,10 @@ static int FUNC(nal_unit_header)(CodedBitstreamContext *ctx, RWContext *rw,
static int FUNC(byte_alignment)(CodedBitstreamContext *ctx, RWContext *rw)
{
int err;
- av_unused int one = 1, zero = 0;
- xu(1, alignment_bit_equal_to_one, one, 1, 1);
+
+ fixed(1, alignment_bit_equal_to_one, 1);
while (byte_alignment(rw) != 0)
- xu(1, alignment_bit_equal_to_zero, zero, 0, 0);
+ fixed(1, alignment_bit_equal_to_zero, 0);
return 0;
}
@@ -90,7 +90,6 @@ static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
int profile_present_flag,
int max_num_sub_layers_minus1)
{
- av_unused unsigned int zero = 0;
int err, i, j;
if (profile_present_flag) {
@@ -125,15 +124,15 @@ static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
if (profile_compatible(5) || profile_compatible(9) ||
profile_compatible(10)) {
flag(general_max_14bit_constraint_flag);
- xu(24, general_reserved_zero_33bits, zero, 0, 0);
- xu(9, general_reserved_zero_33bits, zero, 0, 0);
+ fixed(24, general_reserved_zero_33bits, 0);
+ fixed( 9, general_reserved_zero_33bits, 0);
} else {
- xu(24, general_reserved_zero_34bits, zero, 0, 0);
- xu(10, general_reserved_zero_34bits, zero, 0, 0);
+ fixed(24, general_reserved_zero_34bits, 0);
+ fixed(10, general_reserved_zero_34bits, 0);
}
} else {
- xu(24, general_reserved_zero_43bits, zero, 0, 0);
- xu(19, general_reserved_zero_43bits, zero, 0, 0);
+ fixed(24, general_reserved_zero_43bits, 0);
+ fixed(19, general_reserved_zero_43bits, 0);
}
if (profile_compatible(1) || profile_compatible(2) ||
@@ -141,7 +140,7 @@ static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
profile_compatible(5) || profile_compatible(9)) {
flag(general_inbld_flag);
} else {
- xu(1, general_reserved_zero_bit, zero, 0, 0);
+ fixed(1, general_reserved_zero_bit, 0);
}
#undef profile_compatible
}
@@ -154,10 +153,8 @@ static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
}
if (max_num_sub_layers_minus1 > 0) {
- for (i = max_num_sub_layers_minus1; i < 8; i++) {
- av_unused int zero = 0;
- xu(2, reserved_zero_2bits, zero, 0, 0);
- }
+ for (i = max_num_sub_layers_minus1; i < 8; i++)
+ fixed(2, reserved_zero_2bits, 0);
}
for (i = 0; i < max_num_sub_layers_minus1; i++) {
@@ -386,10 +383,7 @@ static int FUNC(vps)(CodedBitstreamContext *ctx, RWContext *rw,
return AVERROR_INVALIDDATA;
}
- {
- av_unused uint16_t ffff = 0xffff;
- xu(16, vps_reserved_0xffff_16bits, ffff, 0xffff, 0xffff);
- }
+ fixed(16, vps_reserved_0xffff_16bits, 0xffff);
CHECK(FUNC(profile_tier_level)(ctx, rw, ¤t->profile_tier_level,
1, current->vps_max_sub_layers_minus1));
1
0
ffmpeg | branch: master | Mark Thompson <sw(a)jkqxz.net> | 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=d7786b66bdd4b6257…
---
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;
1
0