uint8_t ss_h, ss_v;
uint8_t last_bpp, bpp, bpp_index, bytesperpixel;
uint8_t last_keyframe;
+ enum AVPixelFormat pix_fmt, last_fmt;
ThreadFrame next_refs[8];
struct {
}
};
+static void vp9_unref_frame(AVCodecContext *ctx, VP9Frame *f)
+{
+ ff_thread_release_buffer(ctx, &f->tf);
+ av_buffer_unref(&f->extradata);
+ av_buffer_unref(&f->hwaccel_priv_buf);
+ f->segmentation_map = NULL;
+ f->hwaccel_picture_private = NULL;
+}
+
static int vp9_alloc_frame(AVCodecContext *ctx, VP9Frame *f)
{
VP9Context *s = ctx->priv_data;
return ret;
sz = 64 * s->sb_cols * s->sb_rows;
if (!(f->extradata = av_buffer_allocz(sz * (1 + sizeof(struct VP9mvrefPair))))) {
- ff_thread_release_buffer(ctx, &f->tf);
- return AVERROR(ENOMEM);
+ goto fail;
}
f->segmentation_map = f->extradata->data;
f->mv = (struct VP9mvrefPair *) (f->extradata->data + sz);
+ if (ctx->hwaccel) {
+ const AVHWAccel *hwaccel = ctx->hwaccel;
+ av_assert0(!f->hwaccel_picture_private);
+ if (hwaccel->frame_priv_data_size) {
+ f->hwaccel_priv_buf = av_buffer_allocz(hwaccel->frame_priv_data_size);
+ if (!f->hwaccel_priv_buf)
+ goto fail;
+ f->hwaccel_picture_private = f->hwaccel_priv_buf->data;
+ }
+ }
+
return 0;
-}
-static void vp9_unref_frame(AVCodecContext *ctx, VP9Frame *f)
-{
- ff_thread_release_buffer(ctx, &f->tf);
- av_buffer_unref(&f->extradata);
- f->segmentation_map = NULL;
+fail:
+ vp9_unref_frame(ctx, f);
+ return AVERROR(ENOMEM);
}
static int vp9_ref_frame(AVCodecContext *ctx, VP9Frame *dst, VP9Frame *src)
if ((res = ff_thread_ref_frame(&dst->tf, &src->tf)) < 0) {
return res;
} else if (!(dst->extradata = av_buffer_ref(src->extradata))) {
- vp9_unref_frame(ctx, dst);
- return AVERROR(ENOMEM);
+ goto fail;
}
dst->segmentation_map = src->segmentation_map;
dst->mv = src->mv;
dst->uses_2pass = src->uses_2pass;
+ if (src->hwaccel_picture_private) {
+ dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);
+ if (!dst->hwaccel_priv_buf)
+ goto fail;
+ dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data;
+ }
+
return 0;
+
+fail:
+ vp9_unref_frame(ctx, dst);
+ return AVERROR(ENOMEM);
}
-static int update_size(AVCodecContext *ctx, int w, int h, enum AVPixelFormat fmt)
+static int update_size(AVCodecContext *ctx, int w, int h)
{
+#define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + CONFIG_VP9_D3D11VA_HWACCEL)
+ enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
VP9Context *s = ctx->priv_data;
uint8_t *p;
int bytesperpixel = s->bytesperpixel, res;
av_assert0(w > 0 && h > 0);
- if (s->intra_pred_data[0] && w == ctx->width && h == ctx->height && ctx->pix_fmt == fmt)
+ if (s->intra_pred_data[0] && w == ctx->width && h == ctx->height && s->pix_fmt == s->last_fmt)
return 0;
if ((res = ff_set_dimensions(ctx, w, h)) < 0)
return res;
- ctx->pix_fmt = fmt;
+
+ if (s->pix_fmt == AV_PIX_FMT_YUV420P) {
+#if CONFIG_VP9_DXVA2_HWACCEL
+ *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
+#endif
+#if CONFIG_VP9_D3D11VA_HWACCEL
+ *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
+#endif
+ }
+
+ *fmtp++ = s->pix_fmt;
+ *fmtp = AV_PIX_FMT_NONE;
+
+ res = ff_thread_get_format(ctx, pix_fmts);
+ if (res < 0)
+ return res;
+
+ ctx->pix_fmt = res;
+ s->last_fmt = s->pix_fmt;
s->sb_cols = (w + 63) >> 6;
s->sb_rows = (h + 63) >> 6;
s->cols = (w + 7) >> 3;
255 - inv_recenter_nonneg(inv_map_table[d], 255 - p);
}
-static enum AVPixelFormat read_colorspace_details(AVCodecContext *ctx)
+static int read_colorspace_details(AVCodecContext *ctx)
{
static const enum AVColorSpace colorspaces[8] = {
AVCOL_SPC_UNSPECIFIED, AVCOL_SPC_BT470BG, AVCOL_SPC_BT709, AVCOL_SPC_SMPTE170M,
AVCOL_SPC_SMPTE240M, AVCOL_SPC_BT2020_NCL, AVCOL_SPC_RESERVED, AVCOL_SPC_RGB,
};
VP9Context *s = ctx->priv_data;
- enum AVPixelFormat res;
int bits = ctx->profile <= 1 ? 0 : 1 + get_bits1(&s->gb); // 0:8, 1:10, 2:12
s->bpp_index = bits;
static const enum AVPixelFormat pix_fmt_rgb[3] = {
AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12
};
+ s->ss_h = s->ss_v = 0;
+ ctx->color_range = AVCOL_RANGE_JPEG;
+ s->pix_fmt = pix_fmt_rgb[bits];
if (ctx->profile & 1) {
- s->ss_h = s->ss_v = 0;
- res = pix_fmt_rgb[bits];
- ctx->color_range = AVCOL_RANGE_JPEG;
if (get_bits1(&s->gb)) {
av_log(ctx, AV_LOG_ERROR, "Reserved bit set in RGB\n");
return AVERROR_INVALIDDATA;
if (ctx->profile & 1) {
s->ss_h = get_bits1(&s->gb);
s->ss_v = get_bits1(&s->gb);
- if ((res = pix_fmt_for_ss[bits][s->ss_v][s->ss_h]) == AV_PIX_FMT_YUV420P) {
+ s->pix_fmt = pix_fmt_for_ss[bits][s->ss_v][s->ss_h];
+ if (s->pix_fmt == AV_PIX_FMT_YUV420P) {
av_log(ctx, AV_LOG_ERROR, "YUV 4:2:0 not supported in profile %d\n",
ctx->profile);
return AVERROR_INVALIDDATA;
}
} else {
s->ss_h = s->ss_v = 1;
- res = pix_fmt_for_ss[bits][1][1];
+ s->pix_fmt = pix_fmt_for_ss[bits][1][1];
}
}
- return res;
+ return 0;
}
static int decode_frame_header(AVCodecContext *ctx,
{
VP9Context *s = ctx->priv_data;
int c, i, j, k, l, m, n, w, h, max, size2, res, sharp;
- enum AVPixelFormat fmt = ctx->pix_fmt;
int last_invisible;
const uint8_t *data2;
av_log(ctx, AV_LOG_ERROR, "Invalid sync code\n");
return AVERROR_INVALIDDATA;
}
- if ((fmt = read_colorspace_details(ctx)) < 0)
- return fmt;
+ if ((res = read_colorspace_details(ctx)) < 0)
+ return res;
// for profile 1, here follows the subsampling bits
s->s.h.refreshrefmask = 0xff;
w = get_bits(&s->gb, 16) + 1;
return AVERROR_INVALIDDATA;
}
if (ctx->profile >= 1) {
- if ((fmt = read_colorspace_details(ctx)) < 0)
- return fmt;
+ if ((res = read_colorspace_details(ctx)) < 0)
+ return res;
} else {
s->ss_h = s->ss_v = 1;
s->bpp = 8;
s->bpp_index = 0;
s->bytesperpixel = 1;
- fmt = AV_PIX_FMT_YUV420P;
+ s->pix_fmt = AV_PIX_FMT_YUV420P;
ctx->colorspace = AVCOL_SPC_BT470BG;
ctx->color_range = AVCOL_RANGE_JPEG;
}
s->s.h.varcompref[1] = 2;
}
}
-
- for (i = 0; i < 3; i++) {
- AVFrame *ref = s->s.refs[s->s.h.refidx[i]].f;
- int refw = ref->width, refh = ref->height;
-
- if (ref->format != fmt) {
- av_log(ctx, AV_LOG_ERROR,
- "Ref pixfmt (%s) did not match current frame (%s)",
- av_get_pix_fmt_name(ref->format),
- av_get_pix_fmt_name(fmt));
- return AVERROR_INVALIDDATA;
- } else if (refw == w && refh == h) {
- s->mvscale[i][0] = s->mvscale[i][1] = 0;
- } else {
- if (w * 2 < refw || h * 2 < refh || w > 16 * refw || h > 16 * refh) {
- av_log(ctx, AV_LOG_ERROR,
- "Invalid ref frame dimensions %dx%d for frame size %dx%d\n",
- refw, refh, w, h);
- return AVERROR_INVALIDDATA;
- }
- s->mvscale[i][0] = (refw << 14) / w;
- s->mvscale[i][1] = (refh << 14) / h;
- s->mvstep[i][0] = 16 * s->mvscale[i][0] >> 14;
- s->mvstep[i][1] = 16 * s->mvscale[i][1] >> 14;
- }
- }
}
}
s->s.h.refreshctx = s->s.h.errorres ? 0 : get_bits1(&s->gb);
}
/* tiling info */
- if ((res = update_size(ctx, w, h, fmt)) < 0) {
- av_log(ctx, AV_LOG_ERROR, "Failed to initialize decoder for %dx%d @ %d\n", w, h, fmt);
+ if ((res = update_size(ctx, w, h)) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Failed to initialize decoder for %dx%d @ %d\n",
+ w, h, s->pix_fmt);
return res;
}
for (s->s.h.tiling.log2_tile_cols = 0;
}
}
+ /* check reference frames */
+ if (!s->s.h.keyframe && !s->s.h.intraonly) {
+ for (i = 0; i < 3; i++) {
+ AVFrame *ref = s->s.refs[s->s.h.refidx[i]].f;
+ int refw = ref->width, refh = ref->height;
+
+ if (ref->format != ctx->pix_fmt) {
+ av_log(ctx, AV_LOG_ERROR,
+ "Ref pixfmt (%s) did not match current frame (%s)",
+ av_get_pix_fmt_name(ref->format),
+ av_get_pix_fmt_name(ctx->pix_fmt));
+ return AVERROR_INVALIDDATA;
+ } else if (refw == w && refh == h) {
+ s->mvscale[i][0] = s->mvscale[i][1] = 0;
+ } else {
+ if (w * 2 < refw || h * 2 < refh || w > 16 * refw || h > 16 * refh) {
+ av_log(ctx, AV_LOG_ERROR,
+ "Invalid ref frame dimensions %dx%d for frame size %dx%d\n",
+ refw, refh, w, h);
+ return AVERROR_INVALIDDATA;
+ }
+ s->mvscale[i][0] = (refw << 14) / w;
+ s->mvscale[i][1] = (refh << 14) / h;
+ s->mvstep[i][0] = 16 * s->mvscale[i][0] >> 14;
+ s->mvstep[i][1] = 16 * s->mvscale[i][1] >> 14;
+ }
+ }
+ }
+
if (s->s.h.keyframe || s->s.h.errorres || (s->s.h.intraonly && s->s.h.resetctx == 3)) {
s->prob_ctx[0].p = s->prob_ctx[1].p = s->prob_ctx[2].p =
s->prob_ctx[3].p = vp9_default_probs;
return res;
}
+ if (ctx->hwaccel) {
+ res = ctx->hwaccel->start_frame(ctx, NULL, 0);
+ if (res < 0)
+ return res;
+ res = ctx->hwaccel->decode_slice(ctx, pkt->data, pkt->size);
+ if (res < 0)
+ return res;
+ res = ctx->hwaccel->end_frame(ctx);
+ if (res < 0)
+ return res;
+ goto finish;
+ }
+
// main tile decode loop
bytesperpixel = s->bytesperpixel;
memset(s->above_partition_ctx, 0, s->cols);
} while (s->pass++ == 1);
ff_thread_report_progress(&s->s.frames[CUR_FRAME].tf, INT_MAX, 0);
+finish:
// ref frame setup
for (i = 0; i < 8; i++) {
if (s->s.refs[i].f->buf[0])
// detect size changes in other threads
if (s->intra_pred_data[0] &&
(!ssrc->intra_pred_data[0] || s->cols != ssrc->cols ||
- s->rows != ssrc->rows || s->bpp != ssrc->bpp)) {
+ s->rows != ssrc->rows || s->bpp != ssrc->bpp || s->pix_fmt != ssrc->pix_fmt)) {
free_buffers(s);
}
s->bytesperpixel = ssrc->bytesperpixel;
s->bpp = ssrc->bpp;
s->bpp_index = ssrc->bpp_index;
+ s->pix_fmt = ssrc->pix_fmt;
memcpy(&s->prob_ctx, &ssrc->prob_ctx, sizeof(s->prob_ctx));
memcpy(&s->s.h.lf_delta, &ssrc->s.h.lf_delta, sizeof(s->s.h.lf_delta));
memcpy(&s->s.h.segmentation.feat, &ssrc->s.h.segmentation.feat,