#include "avcodec.h"
#include "internal.h"
+#include "mathops.h"
#include "rectangle.h"
#include "thread.h"
#include "vp8.h"
if ((ret = ff_thread_get_buffer(s->avctx, &f->tf,
ref ? AV_GET_BUFFER_FLAG_REF : 0)) < 0)
return ret;
- if (!(f->seg_map = av_buffer_allocz(s->mb_width * s->mb_height))) {
- ff_thread_release_buffer(s->avctx, &f->tf);
- return AVERROR(ENOMEM);
+ if (!(f->seg_map = av_buffer_allocz(s->mb_width * s->mb_height)))
+ goto fail;
+ if (s->avctx->hwaccel) {
+ const AVHWAccel *hwaccel = s->avctx->hwaccel;
+ 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;
+
+fail:
+ av_buffer_unref(&f->seg_map);
+ ff_thread_release_buffer(s->avctx, &f->tf);
+ return AVERROR(ENOMEM);
}
static void vp8_release_frame(VP8Context *s, VP8Frame *f)
{
av_buffer_unref(&f->seg_map);
+ av_buffer_unref(&f->hwaccel_priv_buf);
+ f->hwaccel_picture_private = NULL;
ff_thread_release_buffer(s->avctx, &f->tf);
}
vp8_release_frame(s, dst);
return AVERROR(ENOMEM);
}
+ if (src->hwaccel_picture_private) {
+ dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);
+ if (!dst->hwaccel_priv_buf)
+ return AVERROR(ENOMEM);
+ dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data;
+ }
return 0;
}
av_log(s->avctx, AV_LOG_FATAL, "Ran out of free frames!\n");
abort();
}
- if (frame->tf.f->data[0])
+ if (frame->tf.f->buf[0])
vp8_release_frame(s, frame);
return frame;
s->top_border = av_mallocz((s->mb_width + 1) * sizeof(*s->top_border));
s->thread_data = av_mallocz(MAX_THREADS * sizeof(VP8ThreadData));
+ if (!s->macroblocks_base || !s->top_nnz || !s->top_border ||
+ !s->thread_data || (!s->intra4x4_pred_mode_top && !s->mb_layout)) {
+ free_buffers(s);
+ return AVERROR(ENOMEM);
+ }
+
for (i = 0; i < MAX_THREADS; i++) {
s->thread_data[i].filter_strength =
av_mallocz(s->mb_width * sizeof(*s->thread_data[0].filter_strength));
+ if (!s->thread_data[i].filter_strength) {
+ free_buffers(s);
+ return AVERROR(ENOMEM);
+ }
#if HAVE_THREADS
pthread_mutex_init(&s->thread_data[i].lock, NULL);
pthread_cond_init(&s->thread_data[i].cond, NULL);
#endif
}
- if (!s->macroblocks_base || !s->top_nnz || !s->top_border ||
- (!s->intra4x4_pred_mode_top && !s->mb_layout))
- return AVERROR(ENOMEM);
-
s->macroblocks = s->macroblocks_base + 1;
return 0;
int i;
s->segmentation.update_map = vp8_rac_get(c);
+ s->segmentation.update_feature_data = vp8_rac_get(c);
- if (vp8_rac_get(c)) { // update segment feature data
+ if (s->segmentation.update_feature_data) {
s->segmentation.absolute_vals = vp8_rac_get(c);
for (i = 0; i < 4; i++)
int size = AV_RL24(sizes + 3 * i);
if (buf_size - size < 0)
return -1;
+ s->coeff_partition_size[i] = size;
ff_vp56_init_range_decoder(&s->coeff_partition[i], buf, size);
buf += size;
buf_size -= size;
}
+
+ s->coeff_partition_size[i] = buf_size;
ff_vp56_init_range_decoder(&s->coeff_partition[i], buf, buf_size);
return 0;
VP56RangeCoder *c = &s->c;
int i, base_qi;
- int yac_qi = vp8_rac_get_uint(c, 7);
- int ydc_delta = vp8_rac_get_sint(c, 4);
- int y2dc_delta = vp8_rac_get_sint(c, 4);
- int y2ac_delta = vp8_rac_get_sint(c, 4);
- int uvdc_delta = vp8_rac_get_sint(c, 4);
- int uvac_delta = vp8_rac_get_sint(c, 4);
+ s->quant.yac_qi = vp8_rac_get_uint(c, 7);
+ s->quant.ydc_delta = vp8_rac_get_sint(c, 4);
+ s->quant.y2dc_delta = vp8_rac_get_sint(c, 4);
+ s->quant.y2ac_delta = vp8_rac_get_sint(c, 4);
+ s->quant.uvdc_delta = vp8_rac_get_sint(c, 4);
+ s->quant.uvac_delta = vp8_rac_get_sint(c, 4);
for (i = 0; i < 4; i++) {
if (s->segmentation.enabled) {
base_qi = s->segmentation.base_quant[i];
if (!s->segmentation.absolute_vals)
- base_qi += yac_qi;
+ base_qi += s->quant.yac_qi;
} else
- base_qi = yac_qi;
+ base_qi = s->quant.yac_qi;
- s->qmat[i].luma_qmul[0] = vp8_dc_qlookup[av_clip_uintp2(base_qi + ydc_delta, 7)];
+ s->qmat[i].luma_qmul[0] = vp8_dc_qlookup[av_clip_uintp2(base_qi + s->quant.ydc_delta, 7)];
s->qmat[i].luma_qmul[1] = vp8_ac_qlookup[av_clip_uintp2(base_qi, 7)];
- s->qmat[i].luma_dc_qmul[0] = vp8_dc_qlookup[av_clip_uintp2(base_qi + y2dc_delta, 7)] * 2;
+ s->qmat[i].luma_dc_qmul[0] = vp8_dc_qlookup[av_clip_uintp2(base_qi + s->quant.y2dc_delta, 7)] * 2;
/* 101581>>16 is equivalent to 155/100 */
- s->qmat[i].luma_dc_qmul[1] = vp8_ac_qlookup[av_clip_uintp2(base_qi + y2ac_delta, 7)] * 101581 >> 16;
- s->qmat[i].chroma_qmul[0] = vp8_dc_qlookup[av_clip_uintp2(base_qi + uvdc_delta, 7)];
- s->qmat[i].chroma_qmul[1] = vp8_ac_qlookup[av_clip_uintp2(base_qi + uvac_delta, 7)];
+ s->qmat[i].luma_dc_qmul[1] = vp8_ac_qlookup[av_clip_uintp2(base_qi + s->quant.y2ac_delta, 7)] * 101581 >> 16;
+ s->qmat[i].chroma_qmul[0] = vp8_dc_qlookup[av_clip_uintp2(base_qi + s->quant.uvdc_delta, 7)];
+ s->qmat[i].chroma_qmul[1] = vp8_ac_qlookup[av_clip_uintp2(base_qi + s->quant.uvac_delta, 7)];
s->qmat[i].luma_dc_qmul[1] = FFMAX(s->qmat[i].luma_dc_qmul[1], 8);
s->qmat[i].chroma_qmul[0] = FFMIN(s->qmat[i].chroma_qmul[0], 132);
}
static void fade(uint8_t *dst, uint8_t *src,
- int width, int height, int linesize,
+ int width, int height, ptrdiff_t linesize,
int alpha, int beta)
{
int i, j;
int width = s->avctx->width;
int height = s->avctx->height;
+ if (buf_size < 4) {
+ return AVERROR_INVALIDDATA;
+ }
+
s->profile = (buf[0] >> 1) & 7;
if (s->profile > 1) {
avpriv_request_sample(s->avctx, "Unknown profile %d", s->profile);
buf += 4 - s->profile;
buf_size -= 4 - s->profile;
+ if (buf_size < part1_size) {
+ return AVERROR_INVALIDDATA;
+ }
+
memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_epel_pixels_tab, sizeof(s->put_pixels_tab));
ff_vp56_init_range_decoder(c, buf, part1_size);
sizeof(vp7_mv_default_prob[i]));
memset(&s->segmentation, 0, sizeof(s->segmentation));
memset(&s->lf_delta, 0, sizeof(s->lf_delta));
- memcpy(s->prob[0].scan, zigzag_scan, sizeof(s->prob[0].scan));
+ memcpy(s->prob[0].scan, ff_zigzag_scan, sizeof(s->prob[0].scan));
}
if (s->keyframe || s->profile > 0)
s->feature_index_prob[i][j] =
vp8_rac_get(c) ? vp8_rac_get_uint(c, 8) : 255;
- if (vp7_feature_value_size[i])
+ if (vp7_feature_value_size[s->profile][i])
for (j = 0; j < 4; j++)
s->feature_value[i][j] =
vp8_rac_get(c) ? vp8_rac_get_uint(c, vp7_feature_value_size[s->profile][i]) : 0;
/* G. DCT coefficient ordering specification */
if (vp8_rac_get(c))
for (i = 1; i < 16; i++)
- s->prob[0].scan[i] = zigzag_scan[vp8_rac_get_uint(c, 4)];
+ s->prob[0].scan[i] = ff_zigzag_scan[vp8_rac_get_uint(c, 4)];
/* H. Loop filter levels */
if (s->profile > 0)
buf += 3;
buf_size -= 3;
+ s->header_partition_size = header_size;
+
if (s->profile > 3)
av_log(s->avctx, AV_LOG_WARNING, "Unknown profile %d\n", s->profile);
buf_size -= header_size;
if (s->keyframe) {
- if (vp8_rac_get(c))
+ s->colorspace = vp8_rac_get(c);
+ if (s->colorspace)
av_log(s->avctx, AV_LOG_WARNING, "Unspecified colorspace\n");
- vp8_rac_get(c); // whether we can skip clamping in dsp functions
+ s->fullrange = vp8_rac_get(c);
}
if ((s->segmentation.enabled = vp8_rac_get(c)))
s->filter.level = vp8_rac_get_uint(c, 6);
s->filter.sharpness = vp8_rac_get_uint(c, 3);
- if ((s->lf_delta.enabled = vp8_rac_get(c)))
- if (vp8_rac_get(c))
+ if ((s->lf_delta.enabled = vp8_rac_get(c))) {
+ s->lf_delta.update = vp8_rac_get(c);
+ if (s->lf_delta.update)
update_lf_deltas(s);
+ }
if (setup_partitions(s, buf, buf_size)) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid partitions\n");
vp78_update_pred16x16_pred8x8_mvc_probabilities(s, VP8_MVC_SIZE);
}
+ // Record the entropy coder state here so that hwaccels can use it.
+ s->c.code_word = vp56_rac_renorm(&s->c);
+ s->coder_state_at_header_end.input = s->c.buffer - (-s->c.bits / 8);
+ s->coder_state_at_header_end.range = s->c.high;
+ s->coder_state_at_header_end.value = s->c.code_word >> 16;
+ s->coder_state_at_header_end.bit_count = -s->c.bits % 8;
+
return 0;
}
uint8_t *segment, uint8_t *ref, int layout, int is_vp7)
{
VP56RangeCoder *c = &s->c;
- const char *vp7_feature_name[] = { "q-index",
- "lf-delta",
- "partial-golden-update",
- "blit-pitch" };
+ static const char *vp7_feature_name[] = { "q-index",
+ "lf-delta",
+ "partial-golden-update",
+ "blit-pitch" };
if (is_vp7) {
int i;
*segment = 0;
int16_t qmul[2])
{
return decode_block_coeffs_internal(r, block, probs, i,
- token_prob, qmul, zigzag_scan, IS_VP8);
+ token_prob, qmul, ff_zigzag_scan, IS_VP8);
}
#endif
// decode DC values and do hadamard
nnz = decode_block_coeffs(c, td->block_dc, s->prob->token[1], 0,
nnz_pred, s->qmat[segment].luma_dc_qmul,
- zigzag_scan, is_vp7);
+ ff_zigzag_scan, is_vp7);
l_nnz[8] = t_nnz[8] = !!nnz;
if (is_vp7 && mb->mode > MODE_I4x4) {
static av_always_inline
void backup_mb_border(uint8_t *top_border, uint8_t *src_y,
uint8_t *src_cb, uint8_t *src_cr,
- int linesize, int uvlinesize, int simple)
+ ptrdiff_t linesize, ptrdiff_t uvlinesize, int simple)
{
AV_COPY128(top_border, src_y + 15 * linesize);
if (!simple) {
static av_always_inline
void xchg_mb_border(uint8_t *top_border, uint8_t *src_y, uint8_t *src_cb,
- uint8_t *src_cr, int linesize, int uvlinesize, int mb_x,
+ uint8_t *src_cr, ptrdiff_t linesize, ptrdiff_t uvlinesize, int mb_x,
int mb_y, int mb_width, int simple, int xchg)
{
uint8_t *top_border_m1 = top_border - 32; // for TL prediction
for (y = 0; y < 4; y++) {
uint8_t *topright = ptr + 4 - s->linesize;
for (x = 0; x < 4; x++) {
- int copy = 0, linesize = s->linesize;
+ int copy = 0;
+ ptrdiff_t linesize = s->linesize;
uint8_t *dst = ptr + 4 * x;
DECLARE_ALIGNED(4, uint8_t, copy_dst)[5 * 8];
uint8_t *src = ref->f->data[0];
if (AV_RN32A(mv)) {
- int src_linesize = linesize;
+ ptrdiff_t src_linesize = linesize;
int mx = (mv->x << 1) & 7, mx_idx = subpel_idx[0][mx];
int my = (mv->y << 1) & 7, my_idx = subpel_idx[0][my];
mb->bmv[2 * y * 4 + 2 * x + 1].y +
mb->bmv[(2 * y + 1) * 4 + 2 * x ].y +
mb->bmv[(2 * y + 1) * 4 + 2 * x + 1].y;
- uvmv.x = (uvmv.x + 2 + (uvmv.x >> (INT_BIT - 1))) >> 2;
- uvmv.y = (uvmv.y + 2 + (uvmv.y >> (INT_BIT - 1))) >> 2;
+ uvmv.x = (uvmv.x + 2 + FF_SIGNBIT(uvmv.x)) >> 2;
+ uvmv.y = (uvmv.y + 2 + FF_SIGNBIT(uvmv.y)) >> 2;
if (s->profile == 3) {
uvmv.x &= ~7;
uvmv.y &= ~7;
int filter_level = f->filter_level;
int inner_limit = f->inner_limit;
int inner_filter = f->inner_filter;
- int linesize = s->linesize;
- int uvlinesize = s->uvlinesize;
+ ptrdiff_t linesize = s->linesize;
+ ptrdiff_t uvlinesize = s->uvlinesize;
static const uint8_t hev_thresh_lut[2][64] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
int filter_level = f->filter_level;
int inner_limit = f->inner_limit;
int inner_filter = f->inner_filter;
- int linesize = s->linesize;
+ ptrdiff_t linesize = s->linesize;
if (!filter_level)
return;
return vp78_decode_mb_row_sliced(avctx, tdata, jobnr, threadnr, IS_VP8);
}
-
static av_always_inline
int vp78_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
AVPacket *avpkt, int is_vp7)
if (ret < 0)
goto err;
+ if (!is_vp7 && s->pix_fmt == AV_PIX_FMT_NONE) {
+ enum AVPixelFormat pix_fmts[] = {
+#if CONFIG_VP8_VAAPI_HWACCEL
+ AV_PIX_FMT_VAAPI,
+#endif
+ AV_PIX_FMT_YUV420P,
+ AV_PIX_FMT_NONE,
+ };
+
+ s->pix_fmt = ff_get_format(s->avctx, pix_fmts);
+ if (s->pix_fmt < 0) {
+ ret = AVERROR(EINVAL);
+ goto err;
+ }
+ avctx->pix_fmt = s->pix_fmt;
+ }
+
prev_frame = s->framep[VP56_FRAME_CURRENT];
referenced = s->update_last || s->update_golden == VP56_FRAME_CURRENT ||
curframe = s->framep[VP56_FRAME_CURRENT] = vp8_find_free_buffer(s);
+ if (!s->colorspace)
+ avctx->colorspace = AVCOL_SPC_BT470BG;
+ if (s->fullrange)
+ avctx->color_range = AVCOL_RANGE_JPEG;
+ else
+ avctx->color_range = AVCOL_RANGE_MPEG;
+
/* Given that arithmetic probabilities are updated every frame, it's quite
* likely that the values we have on a random interframe are complete
* junk if we didn't start decode on a keyframe. So just don't display
ff_thread_finish_setup(avctx);
- s->linesize = curframe->tf.f->linesize[0];
- s->uvlinesize = curframe->tf.f->linesize[1];
+ if (avctx->hwaccel) {
+ ret = avctx->hwaccel->start_frame(avctx, avpkt->data, avpkt->size);
+ if (ret < 0)
+ goto err;
- memset(s->top_nnz, 0, s->mb_width * sizeof(*s->top_nnz));
- /* Zero macroblock structures for top/top-left prediction
- * from outside the frame. */
- if (!s->mb_layout)
- memset(s->macroblocks + s->mb_height * 2 - 1, 0,
- (s->mb_width + 1) * sizeof(*s->macroblocks));
- if (!s->mb_layout && s->keyframe)
- memset(s->intra4x4_pred_mode_top, DC_PRED, s->mb_width * 4);
+ ret = avctx->hwaccel->decode_slice(avctx, avpkt->data, avpkt->size);
+ if (ret < 0)
+ goto err;
- memset(s->ref_count, 0, sizeof(s->ref_count));
+ ret = avctx->hwaccel->end_frame(avctx);
+ if (ret < 0)
+ goto err;
- if (s->mb_layout == 1) {
- // Make sure the previous frame has read its segmentation map,
- // if we re-use the same map.
- if (prev_frame && s->segmentation.enabled &&
- !s->segmentation.update_map)
- ff_thread_await_progress(&prev_frame->tf, 1, 0);
- if (is_vp7)
- vp7_decode_mv_mb_modes(avctx, curframe, prev_frame);
+ } else {
+ s->linesize = curframe->tf.f->linesize[0];
+ s->uvlinesize = curframe->tf.f->linesize[1];
+
+ memset(s->top_nnz, 0, s->mb_width * sizeof(*s->top_nnz));
+ /* Zero macroblock structures for top/top-left prediction
+ * from outside the frame. */
+ if (!s->mb_layout)
+ memset(s->macroblocks + s->mb_height * 2 - 1, 0,
+ (s->mb_width + 1) * sizeof(*s->macroblocks));
+ if (!s->mb_layout && s->keyframe)
+ memset(s->intra4x4_pred_mode_top, DC_PRED, s->mb_width * 4);
+
+ memset(s->ref_count, 0, sizeof(s->ref_count));
+
+ if (s->mb_layout == 1) {
+ // Make sure the previous frame has read its segmentation map,
+ // if we re-use the same map.
+ if (prev_frame && s->segmentation.enabled &&
+ !s->segmentation.update_map)
+ ff_thread_await_progress(&prev_frame->tf, 1, 0);
+ if (is_vp7)
+ vp7_decode_mv_mb_modes(avctx, curframe, prev_frame);
+ else
+ vp8_decode_mv_mb_modes(avctx, curframe, prev_frame);
+ }
+
+ if (avctx->active_thread_type == FF_THREAD_FRAME)
+ num_jobs = 1;
else
- vp8_decode_mv_mb_modes(avctx, curframe, prev_frame);
- }
+ num_jobs = FFMIN(s->num_coeff_partitions, avctx->thread_count);
+ s->num_jobs = num_jobs;
+ s->curframe = curframe;
+ s->prev_frame = prev_frame;
+ s->mv_min.y = -MARGIN;
+ s->mv_max.y = ((s->mb_height - 1) << 6) + MARGIN;
+ for (i = 0; i < MAX_THREADS; i++) {
+ s->thread_data[i].thread_mb_pos = 0;
+ s->thread_data[i].wait_mb_pos = INT_MAX;
+ }
- if (avctx->active_thread_type == FF_THREAD_FRAME)
- num_jobs = 1;
- else
- num_jobs = FFMIN(s->num_coeff_partitions, avctx->thread_count);
- s->num_jobs = num_jobs;
- s->curframe = curframe;
- s->prev_frame = prev_frame;
- s->mv_min.y = -MARGIN;
- s->mv_max.y = ((s->mb_height - 1) << 6) + MARGIN;
- for (i = 0; i < MAX_THREADS; i++) {
- s->thread_data[i].thread_mb_pos = 0;
- s->thread_data[i].wait_mb_pos = INT_MAX;
+ if (is_vp7)
+ avctx->execute2(avctx, vp7_decode_mb_row_sliced, s->thread_data, NULL,
+ num_jobs);
+ else
+ avctx->execute2(avctx, vp8_decode_mb_row_sliced, s->thread_data, NULL,
+ num_jobs);
}
- if (is_vp7)
- avctx->execute2(avctx, vp7_decode_mb_row_sliced, s->thread_data, NULL,
- num_jobs);
- else
- avctx->execute2(avctx, vp8_decode_mb_row_sliced, s->thread_data, NULL,
- num_jobs);
ff_thread_report_progress(&curframe->tf, INT_MAX, 0);
memcpy(&s->framep[0], &s->next_framep[0], sizeof(s->framep[0]) * 4);
int ret;
s->avctx = avctx;
+ s->pix_fmt = AV_PIX_FMT_NONE;
avctx->pix_fmt = AV_PIX_FMT_YUV420P;
avctx->internal->allocate_progress = 1;
}
/* does not change for VP8 */
- memcpy(s->prob[0].scan, zigzag_scan, sizeof(s->prob[0].scan));
+ memcpy(s->prob[0].scan, ff_zigzag_scan, sizeof(s->prob[0].scan));
if ((ret = vp8_init_frames(s)) < 0) {
ff_vp8_decode_free(avctx);
.init = vp7_decode_init,
.close = ff_vp8_decode_free,
.decode = vp7_decode_frame,
- .capabilities = CODEC_CAP_DR1,
+ .capabilities = AV_CODEC_CAP_DR1,
.flush = vp8_decode_flush,
};
#endif /* CONFIG_VP7_DECODER */
.init = ff_vp8_decode_init,
.close = ff_vp8_decode_free,
.decode = ff_vp8_decode_frame,
- .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS | CODEC_CAP_SLICE_THREADS,
+ .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
+ AV_CODEC_CAP_SLICE_THREADS,
.flush = vp8_decode_flush,
.init_thread_copy = ONLY_IF_THREADS_ENABLED(vp8_decode_init_thread_copy),
.update_thread_context = ONLY_IF_THREADS_ENABLED(vp8_decode_update_thread_context),