52#define MAX_REFERENCE_FRAMES 8
54#define MAX_FRAMES (MAX_REFERENCE_FRAMES + MAX_DELAY + 1)
56#define MAX_BLOCKSIZE 32
61#define DIRAC_REF_MASK_REF1 1
62#define DIRAC_REF_MASK_REF2 2
63#define DIRAC_REF_MASK_GLOBAL 4
69#define DELAYED_PIC_REF 4
71#define CALC_PADDING(size, depth) \
72 (((size + (1 << depth) - 1) >> depth) << depth)
74#define DIVRNDUP(a, b) (((a) + (b) - 1) / (b))
109typedef struct Plane {
255 return (
int)((x+1U)*21845 + 10922) >> 16;
261 int i, remove_idx = -1;
263 for (
i = 0; framelist[
i];
i++)
264 if (framelist[
i]->picture_number == picnum) {
265 remove_pic = framelist[
i];
270 for (
i = remove_idx; framelist[
i];
i++)
271 framelist[
i] = framelist[
i+1];
279 for (
i = 0;
i < maxframes;
i++)
290 int sbheight =
DIVRNDUP(
s->seq.height, 4);
291 int i,
w,
h, top_padding;
294 for (
i = 0;
i < 3;
i++) {
297 w =
s->seq.width >> (
i ?
s->chroma_x_shift : 0);
298 h =
s->seq.height >> (
i ?
s->chroma_y_shift : 0);
309 s->plane[
i].idwt.buf_base =
av_calloc(
w + max_xblen,
h * (2 <<
s->pshift));
311 s->plane[
i].idwt.buf =
s->plane[
i].idwt.buf_base + (top_padding*
w)*(2 <<
s->pshift);
312 if (!
s->plane[
i].idwt.buf_base || !
s->plane[
i].idwt.tmp)
320 if (!
s->sbsplit || !
s->blmotion)
327 int w =
s->seq.width;
328 int h =
s->seq.height;
333 if (
s->buffer_stride >=
stride)
335 s->buffer_stride = 0;
338 memset(
s->edge_emu_buffer, 0,
sizeof(
s->edge_emu_buffer));
347 if (!
s->edge_emu_buffer_base || !
s->mctmp || !
s->mcscratch)
359 if (
s->all_frames[
i].avframe->data[0]) {
361 memset(
s->all_frames[
i].interpolated, 0,
sizeof(
s->all_frames[
i].interpolated));
364 for (j = 0; j < 3; j++)
365 for (k = 1; k < 4; k++)
369 memset(
s->ref_frames, 0,
sizeof(
s->ref_frames));
370 memset(
s->delay_frames, 0,
sizeof(
s->delay_frames));
372 for (
i = 0;
i < 3;
i++) {
377 s->buffer_stride = 0;
394 s->frame_number = -1;
396 s->thread_buf =
NULL;
397 s->threads_num_buf = -1;
398 s->thread_buf_size = -1;
406 if (!
s->all_frames[
i].avframe)
420 s->seen_sequence_header = 0;
421 s->frame_number = -1;
444 const unsigned sign =
FFSIGN(coeff);
446 coeff = sign*((sign * coeff * qfactor + qoffset) >> 2);
450#define SIGN_CTX(x) (CTX_SIGN_ZERO + ((x) > 0) - ((x) < 0))
452#define UNPACK_ARITH(n, type) \
453 static inline void coeff_unpack_arith_##n(DiracArith *c, int qfactor, int qoffset, \
454 SubBand *b, type *buf, int x, int y) \
456 int sign, sign_pred = 0, pred_ctx = CTX_ZPZN_F1; \
458 const int mstride = -(b->stride >> (1+b->pshift)); \
460 const type *pbuf = (type *)b->parent->ibuf; \
461 const int stride = b->parent->stride >> (1+b->parent->pshift); \
462 pred_ctx += !!pbuf[stride * (y>>1) + (x>>1)] << 1; \
464 if (b->orientation == subband_hl) \
465 sign_pred = buf[mstride]; \
467 pred_ctx += !(buf[-1] | buf[mstride] | buf[-1 + mstride]); \
468 if (b->orientation == subband_lh) \
469 sign_pred = buf[-1]; \
471 pred_ctx += !buf[mstride]; \
473 coeff = dirac_get_arith_uint(c, pred_ctx, CTX_COEFF_DATA); \
475 coeff = (coeff * qfactor + qoffset) >> 2; \
476 sign = dirac_get_arith_bit(c, SIGN_CTX(sign_pred)); \
477 coeff = (coeff ^ -sign) + sign; \
491 int left,
int right,
int top,
int bottom,
492 int blockcnt_one,
int is_arith)
494 int x, y, zero_block;
495 int qoffset, qfactor;
509 if (
s->codeblock_mode && !(
s->old_delta_quant && blockcnt_one)) {
512 quant = dirac_get_arith_int(c, CTX_DELTA_Q_F, CTX_DELTA_Q_DATA);
514 quant = dirac_get_se_golomb(gb);
515 if (quant > INT_MAX - b->quant || b->quant + quant < 0) {
516 av_log(s->avctx, AV_LOG_ERROR,
"Invalid quant\n");
517 return AVERROR_INVALIDDATA;
523 av_log(s->avctx, AV_LOG_ERROR,
"Unsupported quant %d\n", b->quant);
525 return AVERROR_INVALIDDATA;
535 buf =
b->ibuf + top *
b->stride;
537 for (y = top; y < bottom; y++) {
540 for (x =
left; x < right; x++) {
542 coeff_unpack_arith_10(
c, qfactor, qoffset,
b, (
int32_t*)(buf)+x, x, y);
544 coeff_unpack_arith_8(
c, qfactor, qoffset,
b, (int16_t*)(buf)+x, x, y);
550 for (y = top; y < bottom; y++) {
553 for (x =
left; x < right; x++) {
571#define INTRA_DC_PRED(n, type) \
572 static inline void intra_dc_prediction_##n(SubBand *b) \
574 type *buf = (type*)b->ibuf; \
577 for (x = 1; x < b->width; x++) \
578 buf[x] += buf[x-1]; \
579 buf += (b->stride >> (1+b->pshift)); \
581 for (y = 1; y < b->height; y++) { \
582 buf[0] += buf[-(b->stride >> (1+b->pshift))]; \
584 for (x = 1; x < b->width; x++) { \
585 int pred = buf[x - 1] + buf[x - (b->stride >> (1+b->pshift))] + buf[x - (b->stride >> (1+b->pshift))-1]; \
586 buf[x] += divide3(pred); \
588 buf += (b->stride >> (1+b->pshift)); \
602 int cb_x, cb_y,
left, right, top, bottom;
605 int cb_width =
s->codeblock[
b->level + (
b->orientation !=
subband_ll)].width;
606 int cb_height =
s->codeblock[
b->level + (
b->orientation !=
subband_ll)].height;
607 int blockcnt_one = (cb_width + cb_height) == 2;
619 for (cb_y = 0; cb_y < cb_height; cb_y++) {
620 bottom = (
b->height * (cb_y+1LL)) / cb_height;
622 for (cb_x = 0; cb_x < cb_width; cb_x++) {
623 right = (
b->width * (cb_x+1LL)) / cb_width;
634 intra_dc_prediction_10(b);
636 intra_dc_prediction_8(b);
664 int level, num_bands = 0;
667 int damaged_count = 0;
671 for (orientation = !!
level; orientation < 4; orientation++) {
703 for (
i = 0;
i <
s->wavelet_depth * 3 + 1;
i++) {
707 if (damaged_count > (
s->wavelet_depth * 3 + 1) /2)
713#define PARSE_VALUES(type, x, gb, ebits, buf1, buf2) \
714 type *buf = (type *)buf1; \
715 buf[x] = coeff_unpack_golomb(gb, qfactor, qoffset); \
716 if (get_bits_count(gb) >= ebits) \
719 buf = (type *)buf2; \
720 buf[x] = coeff_unpack_golomb(gb, qfactor, qoffset); \
721 if (get_bits_count(gb) >= ebits) \
726 int slice_x,
int slice_y,
int bits_end,
729 int left =
b1->width * slice_x /
s->num_x;
730 int right =
b1->width *(slice_x+1) /
s->num_x;
731 int top =
b1->height * slice_y /
s->num_y;
732 int bottom =
b1->height *(slice_y+1) /
s->num_y;
734 int qfactor, qoffset;
736 uint8_t *buf1 =
b1->ibuf + top *
b1->stride;
737 uint8_t *buf2 =
b2 ?
b2->ibuf + top *
b2->stride:
NULL;
752 for (y = top; y < bottom; y++) {
753 for (x =
left; x < right; x++) {
762 for (y = top; y < bottom; y++) {
763 for (x =
left; x < right; x++) {
792 for (orientation = !!
level; orientation < 4; orientation++) {
801 chroma_bits = 8*slice->
bytes - 7 - length_bits - luma_bits;
805 for (orientation = !!
level; orientation < 4; orientation++) {
808 &
s->plane[1].band[
level][orientation],
809 &
s->plane[2].band[
level][orientation]);
830 o->
top =
b->height * y /
s->num_y;
831 o->
left =
b->width * x /
s->num_x;
832 o->
tot_h = ((
b->width * (x + 1)) /
s->num_x) - o->
left;
833 o->
tot_v = ((
b->height * (y + 1)) /
s->num_y) - o->
top;
846 int i,
level, orientation, quant_idx;
861 for (orientation = !!
level; orientation < 4; orientation++) {
862 const int quant =
FFMAX(quant_idx -
s->lowdelay.quant[
level][orientation], 0);
869 for (
i = 0;
i < 3;
i++) {
870 int coef_num, coef_par, off = 0;
889 if (coef_num > coef_par) {
890 const int start_b = coef_par * (1 << (
s->pshift + 1));
891 const int end_b = coef_num * (1 << (
s->pshift + 1));
892 memset(&tmp_buf[start_b], 0, end_b - start_b);
897 for (orientation = !!
level; orientation < 4; orientation++) {
899 uint8_t *buf =
b1->ibuf +
c->top *
b1->stride + (
c->left << (
s->pshift + 1));
902 const int qfunc =
s->pshift + 2*(
c->tot_h <= 2);
903 s->diracdsp.dequant_subband[qfunc](&tmp_buf[off], buf,
b1->stride,
904 qfactor[
level][orientation],
905 qoffset[
level][orientation],
908 off +=
c->tot << (
s->pshift + 1);
923 uint8_t *thread_buf = &
s->thread_buf[
s->thread_buf_size*threadnr];
924 for (
i = 0;
i <
s->num_x;
i++)
936 int slice_x, slice_y, bufsize;
937 int64_t coef_buf_size, bytes = 0;
943 if (
s->slice_params_num_buf != (
s->num_x *
s->num_y)) {
945 if (!
s->slice_params_buf) {
947 s->slice_params_num_buf = 0;
950 s->slice_params_num_buf =
s->num_x *
s->num_y;
952 slices =
s->slice_params_buf;
957 coef_buf_size = (coef_buf_size << (1 +
s->pshift)) + 512;
960 s->thread_buf_size != coef_buf_size) {
967 s->thread_buf = thread_buf;
969 s->thread_buf_size = coef_buf_size;
980 for (slice_y = 0; bufsize > 0 && slice_y <
s->num_y; slice_y++) {
981 for (slice_x = 0; bufsize > 0 && slice_x <
s->num_x; slice_x++) {
982 bytes =
s->highquality.prefix_bytes + 1;
983 for (
i = 0;
i < 3;
i++) {
984 if (bytes <= bufsize/8)
985 bytes += buf[bytes] *
s->highquality.size_scaler + 1;
987 if (bytes >= INT_MAX || bytes*8 > bufsize) {
992 slices[slice_num].
bytes = bytes;
993 slices[slice_num].
slice_x = slice_x;
994 slices[slice_num].
slice_y = slice_y;
999 if (bufsize/8 >= bytes)
1006 if (
s->num_x*
s->num_y != slice_num) {
1013 for (slice_y = 0; bufsize > 0 && slice_y <
s->num_y; slice_y++) {
1014 for (slice_x = 0; bufsize > 0 && slice_x <
s->num_x; slice_x++) {
1015 bytes = (slice_num+1) * (
int64_t)
s->lowdelay.bytes.num /
s->lowdelay.bytes.den
1016 - slice_num * (
int64_t)
s->lowdelay.bytes.num /
s->lowdelay.bytes.den;
1017 if (bytes >= INT_MAX || bytes*8 > bufsize) {
1021 slices[slice_num].
bytes = bytes;
1022 slices[slice_num].
slice_x = slice_x;
1023 slices[slice_num].
slice_y = slice_y;
1028 if (bufsize/8 >= bytes)
1038 if (
s->dc_prediction) {
1040 intra_dc_prediction_10(&
s->plane[0].band[0][0]);
1041 intra_dc_prediction_10(&
s->plane[1].band[0][0]);
1042 intra_dc_prediction_10(&
s->plane[2].band[0][0]);
1044 intra_dc_prediction_8(&
s->plane[0].band[0][0]);
1045 intra_dc_prediction_8(&
s->plane[1].band[0][0]);
1046 intra_dc_prediction_8(&
s->plane[2].band[0][0]);
1057 for (
i = 0;
i < 3;
i++) {
1060 p->width =
s->seq.width >> (
i ?
s->chroma_x_shift : 0);
1061 p->height =
s->seq.height >> (
i ?
s->chroma_y_shift : 0);
1064 p->idwt.stride =
FFALIGN(p->idwt.width, 8) << (1 +
s->pshift);
1069 for (orientation = !!
level; orientation < 4; orientation++) {
1072 b->pshift =
s->pshift;
1073 b->ibuf = p->idwt.buf;
1075 b->stride = p->idwt.stride << (
s->wavelet_depth -
level);
1078 b->orientation = orientation;
1080 if (orientation & 1)
1081 b->ibuf +=
w << (1+
b->pshift);
1082 if (orientation > 1)
1083 b->ibuf += (
b->stride>>1);
1086 b->parent = &p->band[
level-1][orientation];
1091 p->xblen =
s->plane[0].xblen >>
s->chroma_x_shift;
1092 p->yblen =
s->plane[0].yblen >>
s->chroma_y_shift;
1093 p->xbsep =
s->plane[0].xbsep >>
s->chroma_x_shift;
1094 p->ybsep =
s->plane[0].ybsep >>
s->chroma_y_shift;
1097 p->xoffset = (p->xblen - p->xbsep)/2;
1098 p->yoffset = (p->yblen - p->ybsep)/2;
1109 static const uint8_t default_blen[] = { 4, 12, 16, 24 };
1131 s->plane[0].xblen = default_blen[idx-1];
1132 s->plane[0].yblen = default_blen[idx-1];
1133 s->plane[0].xbsep = 4 * idx;
1134 s->plane[0].ybsep = 4 * idx;
1139 if (
s->plane[0].xblen % (1 <<
s->chroma_x_shift) != 0 ||
1140 s->plane[0].yblen % (1 <<
s->chroma_y_shift) != 0 ||
1141 !
s->plane[0].xblen || !
s->plane[0].yblen) {
1143 "invalid x/y block length (%d/%d) for x/y chroma shift (%d/%d)\n",
1144 s->plane[0].xblen,
s->plane[0].yblen,
s->chroma_x_shift,
s->chroma_y_shift);
1147 if (!
s->plane[0].xbsep || !
s->plane[0].ybsep ||
s->plane[0].xbsep <
s->plane[0].xblen/2 ||
s->plane[0].ybsep <
s->plane[0].yblen/2) {
1151 if (
s->plane[0].xbsep >
s->plane[0].xblen ||
s->plane[0].ybsep >
s->plane[0].yblen) {
1163 if (
s->mv_precision > 3) {
1171 if (
s->globalmc_flag) {
1172 memset(
s->globalmc, 0,
sizeof(
s->globalmc));
1188 s->globalmc[
ref].zrs[0][0] = 1;
1189 s->globalmc[
ref].zrs[1][1] = 1;
1197 if (
s->globalmc[
ref].perspective_exp + (uint64_t)
s->globalmc[
ref].zrs_exp > 30) {
1213 s->weight_log2denom = 1;
1219 if (
s->weight_log2denom < 1 ||
s->weight_log2denom > 8) {
1221 s->weight_log2denom = 1;
1225 if (
s->num_refs == 2)
1241#define CHECKEDREAD(dst, cond, errmsg) \
1242 tmp = get_interleaved_ue_golomb(gb); \
1244 av_log(s->avctx, AV_LOG_ERROR, errmsg); \
1245 return AVERROR_INVALIDDATA; \
1260 if (!
s->low_delay) {
1263 for (
i = 0;
i <=
s->wavelet_depth;
i++) {
1271 for (
i = 0;
i <=
s->wavelet_depth;
i++)
1272 s->codeblock[
i].width =
s->codeblock[
i].height = 1;
1278 if (
s->num_x *
s->num_y == 0 ||
s->num_x * (uint64_t)
s->num_y > INT_MAX ||
1279 s->num_x * (uint64_t)
s->avctx->width > INT_MAX ||
1280 s->num_y * (uint64_t)
s->avctx->height > INT_MAX ||
1281 s->num_x >
s->avctx->width ||
1282 s->num_y >
s->avctx->height
1285 s->num_x =
s->num_y = 0;
1288 if (
s->ld_picture) {
1291 if (
s->lowdelay.bytes.den <= 0) {
1295 }
else if (
s->hq_picture) {
1298 if (
s->highquality.prefix_bytes >= INT_MAX / 8) {
1314 if (
s->wavelet_depth > 4) {
1315 av_log(
s->avctx,
AV_LOG_ERROR,
"Mandatory custom low delay matrix missing for depth %d\n",
s->wavelet_depth);
1320 for (
i = 0;
i < 4;
i++) {
1323 if (
s->wavelet_idx == 3)
1324 s->lowdelay.quant[
level][
i] += 4*(
s->wavelet_depth-1 -
level);
1333 static const uint8_t avgsplit[7] = { 0, 0, 1, 1, 1, 2, 2 };
1342 return avgsplit[sbsplit[-1] + sbsplit[-
stride] + sbsplit[-
stride-1]];
1352 return block[-1].ref & refmask;
1358 return (
pred >> 1) & refmask;
1368 for (
i = 0;
i < 3;
i++)
1374 for (
i = 0;
i < 3;
i++)
1380 for (
i = 0;
i < 3;
i++)
1386 for (
i = 0;
i < 3;
i++)
1388 }
else if (n == 3) {
1389 for (
i = 0;
i < 3;
i++)
1397 int refmask =
ref+1;
1432 int ez =
s->globalmc[
ref].zrs_exp;
1433 int ep =
s->globalmc[
ref].perspective_exp;
1434 int (*
A)[2] =
s->globalmc[
ref].zrs;
1435 int *
b =
s->globalmc[
ref].pan_tilt;
1436 int *
c =
s->globalmc[
ref].perspective;
1442 block->u.mv[
ref][0] = (
mx + (1<<(ez+ep))) >> (ez+ep);
1443 block->u.mv[
ref][1] = (
my + (1<<(ez+ep))) >> (ez+ep);
1447 int stride,
int x,
int y)
1454 if (
s->num_refs == 2) {
1461 for (
i = 0;
i < 3;
i++)
1466 if (
s->globalmc_flag) {
1471 for (
i = 0;
i <
s->num_refs;
i++)
1472 if (
block->ref & (
i+1)) {
1491 for (x = 1; x <
size; x++)
1494 for (y = 1; y <
size; y++) {
1496 for (x = 0; x <
size; x++)
1508 uint8_t *sbsplit =
s->sbsplit;
1515 s->sbwidth =
DIVRNDUP(
s->seq.width, 4*
s->plane[0].xbsep);
1516 s->sbheight =
DIVRNDUP(
s->seq.height, 4*
s->plane[0].ybsep);
1517 s->blwidth = 4 *
s->sbwidth;
1518 s->blheight = 4 *
s->sbheight;
1523 for (y = 0; y <
s->sbheight; y++) {
1524 for (x = 0; x <
s->sbwidth; x++) {
1530 sbsplit +=
s->sbwidth;
1535 for (
i = 0;
i <
s->num_refs;
i++) {
1539 for (
i = 0;
i < 3;
i++)
1542 for (y = 0; y <
s->sbheight; y++)
1543 for (x = 0; x <
s->sbwidth; x++) {
1544 int blkcnt = 1 <<
s->sbsplit[y *
s->sbwidth + x];
1545 int step = 4 >>
s->sbsplit[y *
s->sbwidth + x];
1547 for (q = 0; q < blkcnt; q++)
1548 for (p = 0; p < blkcnt; p++) {
1549 int bx = 4 * x + p*step;
1550 int by = 4 * y + q*step;
1557 for (
i = 0;
i < 4 + 2*
s->num_refs;
i++) {
1567#define ROLLOFF(i) offset == 1 ? ((i) ? 5 : 3) : \
1568 (1 + (6*(i) + offset - 1) / (2*offset - 1))
1572 else if (
i > blen-1 - 2*
offset)
1578 int left,
int right,
int wy)
1581 for (x = 0;
left && x < p->xblen >> 1; x++)
1582 obmc_weight[x] = wy*8;
1583 for (; x < p->xblen >> right; x++)
1584 obmc_weight[x] = wy*
weight(x, p->xblen, p->xoffset);
1585 for (; x < p->xblen; x++)
1586 obmc_weight[x] = wy*8;
1592 int left,
int right,
int top,
int bottom)
1595 for (y = 0; top && y < p->yblen >> 1; y++) {
1599 for (; y < p->yblen >> bottom; y++) {
1600 int wy =
weight(y, p->yblen, p->yoffset);
1604 for (; y < p->yblen; y++) {
1613 int bottom = by ==
s->blheight-1;
1616 if (top || bottom || by == 1) {
1651 int x,
int y,
int ref,
int plane)
1653 Plane *p = &
s->plane[plane];
1654 uint8_t **ref_hpel =
s->ref_pics[
ref]->hpel[plane];
1655 int motion_x =
block->u.mv[
ref][0];
1656 int motion_y =
block->u.mv[
ref][1];
1657 int mx,
my,
i, epel, nplanes = 0;
1660 motion_x >>=
s->chroma_x_shift;
1661 motion_y >>=
s->chroma_y_shift;
1664 mx = motion_x & ~(-1U <<
s->mv_precision);
1665 my = motion_y & ~(-1U <<
s->mv_precision);
1666 motion_x >>=
s->mv_precision;
1667 motion_y >>=
s->mv_precision;
1670 mx <<= 3 -
s->mv_precision;
1671 my <<= 3 -
s->mv_precision;
1680 src[0] = ref_hpel[(
my>>1)+(
mx>>2)] + y*p->stride + x;
1684 for (
i = 0;
i < 4;
i++)
1685 src[
i] = ref_hpel[
i] + y*p->stride + x;
1695 src[0] += p->stride;
1696 src[1] += p->stride;
1711 }
else if (!(
my&3)) {
1734 for (
i = 0;
i < nplanes;
i++) {
1735 s->vdsp.emulated_edge_mc(
s->edge_emu_buffer[
i],
src[
i],
1736 p->stride, p->stride,
1737 p->xblen, p->yblen, x, y,
1739 src[
i] =
s->edge_emu_buffer[
i];
1742 return (nplanes>>1) + epel;
1746 uint8_t *obmc_weight,
int xblen,
int yblen)
1751 for (y = 0; y < yblen; y++) {
1752 for (x = 0; x < xblen; x += 2) {
1753 dst[x ] += dc * obmc_weight[x ];
1754 dst[x+1] += dc * obmc_weight[x+1];
1762 uint16_t *mctmp, uint8_t *obmc_weight,
1763 int plane,
int dstx,
int dsty)
1765 Plane *p = &
s->plane[plane];
1766 const uint8_t *
src[5];
1769 switch (
block->ref&3) {
1771 add_dc(mctmp,
block->u.dc[plane], p->stride, obmc_weight, p->xblen, p->yblen);
1776 s->put_pixels_tab[idx](
s->mcscratch,
src, p->stride, p->yblen);
1778 s->weight_func(
s->mcscratch, p->stride,
s->weight_log2denom,
1779 s->weight[0] +
s->weight[1], p->yblen);
1783 s->put_pixels_tab[idx](
s->mcscratch,
src, p->stride, p->yblen);
1785 if (
s->biweight_func) {
1787 s->put_pixels_tab[idx](
s->mcscratch + 32,
src, p->stride, p->yblen);
1788 s->biweight_func(
s->mcscratch,
s->mcscratch+32, p->stride,
s->weight_log2denom,
1789 s->weight[0],
s->weight[1], p->yblen);
1791 s->avg_pixels_tab[idx](
s->mcscratch,
src, p->stride, p->yblen);
1794 s->add_obmc(mctmp,
s->mcscratch, p->stride, obmc_weight, p->yblen);
1799 Plane *p = &
s->plane[plane];
1800 int x, dstx = p->xbsep - p->xoffset;
1802 block_mc(
s,
block, mctmp,
s->obmc_weight[0], plane, -p->xoffset, dsty);
1805 for (x = 1; x <
s->blwidth-1; x++) {
1821 memcpy(
s->put_pixels_tab,
s->diracdsp.put_dirac_pixels_tab[idx],
sizeof(
s->put_pixels_tab));
1822 memcpy(
s->avg_pixels_tab,
s->diracdsp.avg_dirac_pixels_tab[idx],
sizeof(
s->avg_pixels_tab));
1823 s->add_obmc =
s->diracdsp.add_dirac_obmc[idx];
1824 if (
s->weight_log2denom > 1 ||
s->weight[0] != 1 ||
s->weight[1] != 1) {
1825 s->weight_func =
s->diracdsp.weight_dirac_pixels_tab[idx];
1826 s->biweight_func =
s->diracdsp.biweight_dirac_pixels_tab[idx];
1828 s->weight_func =
NULL;
1829 s->biweight_func =
NULL;
1840 ref->hpel[plane][0] =
ref->avframe->data[plane];
1844 if (!
s->mv_precision)
1847 for (
i = 1;
i < 4;
i++) {
1848 if (!
ref->hpel_base[plane][
i])
1850 if (!
ref->hpel_base[plane][
i]) {
1854 ref->hpel[plane][
i] =
ref->hpel_base[plane][
i] + edge*
ref->avframe->linesize[plane] + 16;
1857 if (!
ref->interpolated[plane]) {
1858 s->diracdsp.dirac_hpel_filter(
ref->hpel[plane][1],
ref->hpel[plane][2],
1859 ref->hpel[plane][3],
ref->hpel[plane][0],
1865 ref->interpolated[plane] = 1;
1877 int y,
i,
comp, dsty;
1882 if (!
s->hq_picture) {
1885 memset(p->idwt.buf, 0, p->idwt.stride * p->idwt.height);
1896 uint8_t *
frame =
s->current_picture->avframe->data[
comp];
1899 for (
i = 0;
i < 4;
i++)
1902 if (!
s->zero_res && !
s->low_delay)
1904 memset(p->idwt.buf, 0, p->idwt.stride * p->idwt.height);
1910 s->wavelet_depth,
s->bit_depth);
1915 for (y = 0; y < p->height; y += 16) {
1916 int idx = (
s->bit_depth - 8) >> 1;
1918 s->diracdsp.put_signed_rect_clamped[idx](
frame + y*p->stride,
1920 p->idwt.buf + y*p->idwt.stride,
1921 p->idwt.stride, p->width, 16);
1924 int rowheight = p->ybsep*p->stride;
1928 for (
i = 0;
i <
s->num_refs;
i++) {
1934 memset(
s->mctmp, 0, 4*p->yoffset*p->stride);
1937 for (y = 0; y <
s->blheight; y++) {
1939 start =
FFMAX(dsty, 0);
1940 uint16_t *mctmp =
s->mctmp + y*rowheight;
1945 if (y ==
s->blheight-1 || start+p->ybsep > p->height)
1946 h = p->height - start;
1948 h = p->ybsep - (start - dsty);
1952 memset(mctmp+2*p->yoffset*p->stride, 0, 2*rowheight);
1955 mctmp += (start - dsty)*p->stride + p->xoffset;
1959 s->diracdsp.add_rect_clamped(
frame + start*p->stride, mctmp, p->stride,
1960 (int16_t*)(p->idwt.buf) + start*(p->idwt.stride >> 1), (p->idwt.stride >> 1), p->width,
h);
1974 int chroma_x_shift, chroma_y_shift;
1986 for (
i = 0;
f->data[
i];
i++) {
1988 f->linesize[
i] + 32;
2003 unsigned retire, picnum;
2009 picnum =
s->current_picture->picture_number =
get_bits_long(gb, 32);
2016 if (
s->frame_number < 0)
2017 s->frame_number = picnum;
2019 s->ref_pics[0] =
s->ref_pics[1] =
NULL;
2020 for (
i = 0;
i <
s->num_refs;
i++) {
2022 refdist = INT64_MAX;
2027 if (
s->ref_frames[j]
2028 &&
FFABS(
s->ref_frames[j]->picture_number - refnum) < refdist) {
2029 s->ref_pics[
i] =
s->ref_frames[j];
2030 refdist =
FFABS(
s->ref_frames[j]->picture_number - refnum);
2033 if (!
s->ref_pics[
i] || refdist)
2037 if (!
s->ref_pics[
i])
2039 if (!
s->all_frames[j].avframe->data[0]) {
2040 s->ref_pics[
i] = &
s->all_frames[j];
2047 if (!
s->ref_pics[
i]) {
2055 if (
s->current_picture->reference) {
2057 if (retire != picnum) {
2096 for (
i = 1;
s->delay_frames[
i];
i++)
2097 if (
s->delay_frames[
i]->picture_number <
out->picture_number) {
2098 out =
s->delay_frames[
i];
2102 for (
i = out_idx;
s->delay_frames[
i];
i++)
2103 s->delay_frames[
i] =
s->delay_frames[
i+1];
2120#define DATA_UNIT_HEADER_SIZE 13
2136 parse_code = buf[4];
2143 if (
s->seen_sequence_header)
2177 s->pshift =
s->bit_depth > 8;
2181 &
s->chroma_y_shift);
2189 s->seen_sequence_header = 1;
2192 s->seen_sequence_header = 0;
2198 if (sscanf(buf+14,
"Schroedinger %d.%d.%d", ver, ver+1, ver+2) == 3)
2199 if (ver[0] == 1 && ver[1] == 0 && ver[2] <= 7)
2200 s->old_delta_quant = 1;
2202 }
else if (parse_code & 0x8) {
2203 if (!
s->seen_sequence_header) {
2210 if (
s->all_frames[
i].avframe->data[0] ==
NULL)
2211 pic = &
s->all_frames[
i];
2220 tmp = parse_code & 0x03;
2226 s->is_arith = (parse_code & 0x48) == 0x08;
2227 s->low_delay = (parse_code & 0x88) == 0x88;
2228 s->core_syntax = (parse_code & 0x88) == 0x08;
2229 s->ld_picture = (parse_code & 0xF8) == 0xC8;
2230 s->hq_picture = (parse_code & 0xF8) == 0xE8;
2231 s->dc_prediction = (parse_code & 0x28) == 0x08;
2232 pic->
reference = (parse_code & 0x0C) == 0x0C;
2233 if (
s->num_refs == 0)
2240 if (
s->version.minor == 2 && parse_code == 0x88)
2243 if (
s->low_delay && !(
s->ld_picture ||
s->hq_picture) ) {
2250 s->current_picture = pic;
2275 const uint8_t *buf =
pkt->data;
2276 int buf_size =
pkt->size;
2279 unsigned data_unit_size;
2283 if (
s->all_frames[
i].avframe->data[0] && !
s->all_frames[
i].reference) {
2285 memset(
s->all_frames[
i].interpolated, 0,
sizeof(
s->all_frames[
i].interpolated));
2288 s->current_picture =
NULL;
2300 if (buf[buf_idx ] ==
'B' && buf[buf_idx+1] ==
'B' &&
2301 buf[buf_idx+2] ==
'C' && buf[buf_idx+3] ==
'D')
2308 data_unit_size =
AV_RB32(buf+buf_idx+5);
2309 if (data_unit_size > buf_size - buf_idx || !data_unit_size) {
2310 if(data_unit_size > buf_size - buf_idx)
2312 "Data unit with size %d is larger than input buffer, discarding\n",
2324 buf_idx += data_unit_size;
2327 if (!
s->current_picture)
2330 if (
s->current_picture->picture_number >
s->frame_number) {
2336 unsigned min_num =
s->delay_frames[0]->picture_number;
2340 for (
i = 1;
s->delay_frames[
i];
i++)
2341 if (
s->delay_frames[
i]->picture_number < min_num)
2342 min_num =
s->delay_frames[
i]->picture_number;
2348 if (delayed_frame) {
2355 }
else if (
s->current_picture->picture_number ==
s->frame_number) {
2359 s->frame_number =
s->current_picture->picture_number + 1LL;
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
static char * split(char *message, char delim)
static const float bands[]
const FFCodec ff_dirac_decoder
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Interface to Dirac Decoder/Encoder.
#define MAX_DWT_LEVELS
The spec limits the number of wavelet decompositions to 4 for both level 1 (VC-2) and 128 (long-gop d...
void ff_dirac_init_arith_decoder(DiracArith *c, GetBitContext *gb, int length)
av_cold void ff_dirac_init_arith_tables(void)
Arithmetic decoder for Dirac.
static int dirac_get_arith_uint(DiracArith *c, int follow_ctx, int data_ctx)
static int dirac_get_arith_bit(DiracArith *c, int ctx)
static int dirac_get_arith_int(DiracArith *c, int follow_ctx, int data_ctx)
void ff_spatial_idwt_slice2(DWTContext *d, int y)
int ff_spatial_idwt_init(DWTContext *d, DWTPlane *p, enum dwt_type type, int decomposition_count, int bit_depth)
int ff_dirac_golomb_read_32bit(const uint8_t *buf, int bytes, uint8_t *_dst, int coeffs)
int ff_dirac_golomb_read_16bit(const uint8_t *buf, int bytes, uint8_t *_dst, int coeffs)
void(* dirac_biweight_func)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int log2_denom, int weightd, int weights, int h)
void(* dirac_weight_func)(uint8_t *block, ptrdiff_t stride, int log2_denom, int weight, int h)
const int32_t ff_dirac_qoffset_intra_tab[120]
const int ff_dirac_qoffset_inter_tab[122]
const int32_t ff_dirac_qscale_tab[116]
const uint8_t ff_dirac_default_qmat[7][4][4]
#define DIRAC_MAX_QUANT_INDEX
int(* init)(AVBSFContext *ctx)
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static const uint8_t * align_get_bits(GetBitContext *s)
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int dirac_get_se_golomb(GetBitContext *gb)
static unsigned get_interleaved_ue_golomb(GetBitContext *gb)
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
#define u(width, name, range_min, range_max)
int av_dirac_parse_sequence_header(AVDiracSeqHeader **pdsh, const uint8_t *buf, size_t buf_size, void *log_ctx)
Parse a Dirac sequence header.
static int decode_hq_slice_row(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
#define DATA_UNIT_HEADER_SIZE
Dirac Specification -> 9.6 Parse Info Header Syntax.
static av_cold void dirac_decode_flush(AVCodecContext *avctx)
#define CALC_PADDING(size, depth)
static void pred_block_dc(DiracBlock *block, int stride, int x, int y)
static int dirac_unpack_block_motion_data(DiracContext *s)
Dirac Specification ->
static int subband_coeffs(const DiracContext *s, int x, int y, int p, SliceCoeffs c[MAX_DWT_LEVELS])
#define CHECKEDREAD(dst, cond, errmsg)
static void init_planes(DiracContext *s)
#define MAX_REFERENCE_FRAMES
The spec limits this to 3 for frame coding, but in practice can be as high as 6.
static int decode_component(DiracContext *s, int comp)
Dirac Specification -> [DIRAC_STD] 13.4.1 core_transform_data()
static int dirac_unpack_prediction_parameters(DiracContext *s)
Unpack the motion compensation parameters Dirac Specification -> 11.2 Picture prediction data.
static int dirac_decode_picture_header(DiracContext *s)
Dirac Specification -> 11.1.1 Picture Header.
static const uint8_t epel_weights[4][4][4]
static void decode_subband(const DiracContext *s, GetBitContext *gb, int quant, int slice_x, int slice_y, int bits_end, const SubBand *b1, const SubBand *b2)
static int decode_subband_arith(AVCodecContext *avctx, void *b)
static int decode_subband_golomb(AVCodecContext *avctx, void *arg)
static int alloc_sequence_buffers(DiracContext *s)
static DiracFrame * remove_frame(DiracFrame *framelist[], unsigned picnum)
static av_cold void free_sequence_buffers(DiracContext *s)
static av_cold int dirac_decode_init(AVCodecContext *avctx)
static void init_obmc_weight(Plane *p, uint8_t *obmc_weight, int stride, int left, int right, int top, int bottom)
static void decode_block_params(DiracContext *s, DiracArith arith[8], DiracBlock *block, int stride, int x, int y)
#define DIRAC_REF_MASK_REF2
#define DIRAC_REF_MASK_GLOBAL
static int pred_block_mode(DiracBlock *block, int stride, int x, int y, int refmask)
static int decode_lowdelay_slice(AVCodecContext *avctx, void *arg)
Dirac Specification -> 13.5.2 Slices.
static void add_dc(uint16_t *dst, int dc, int stride, uint8_t *obmc_weight, int xblen, int yblen)
static int interpolate_refplane(DiracContext *s, DiracFrame *ref, int plane, int width, int height)
static void init_obmc_weight_row(Plane *p, uint8_t *obmc_weight, int stride, int left, int right, int wy)
static int dirac_decode_data_unit(AVCodecContext *avctx, const uint8_t *buf, int size)
static int dirac_decode_frame_internal(DiracContext *s)
Dirac Specification -> 13.0 Transform data syntax.
static int alloc_buffers(DiracContext *s, int stride)
static av_always_inline int decode_subband_internal(const DiracContext *s, SubBand *b, int is_arith)
Dirac Specification -> 13.4.2 Non-skipped subbands.
#define PARSE_VALUES(type, x, gb, ebits, buf1, buf2)
static void pred_mv(DiracBlock *block, int stride, int x, int y, int ref)
static int divide3(int x)
static void block_mc(DiracContext *s, DiracBlock *block, uint16_t *mctmp, uint8_t *obmc_weight, int plane, int dstx, int dsty)
static int get_delayed_pic(DiracContext *s, AVFrame *picture, int *got_frame)
static int codeblock(const DiracContext *s, SubBand *b, GetBitContext *gb, DiracArith *c, int left, int right, int top, int bottom, int blockcnt_one, int is_arith)
Decode the coeffs in the rectangle defined by left, right, top, bottom [DIRAC_STD] 13....
static int decode_lowdelay(DiracContext *s)
Dirac Specification -> 13.5.1 low_delay_transform_data()
static void propagate_block_data(DiracBlock *block, int stride, int size)
Copies the current block to the other blocks covered by the current superblock split mode.
static int mc_subpel(DiracContext *s, DiracBlock *block, const uint8_t *src[5], int x, int y, int ref, int plane)
For block x,y, determine which of the hpel planes to do bilinear interpolation from and set src[] to ...
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output.
static void mc_row(DiracContext *s, DiracBlock *block, uint16_t *mctmp, int plane, int dsty)
static int add_frame(DiracFrame *framelist[], int maxframes, DiracFrame *frame)
static void init_obmc_weights(DiracContext *s, Plane *p, int by)
#define UNPACK_ARITH(n, type)
static void global_mv(DiracContext *s, DiracBlock *block, int x, int y, int ref)
#define INTRA_DC_PRED(n, type)
Dirac Specification -> 13.3 intra_dc_prediction(band)
static int pred_sbsplit(uint8_t *sbsplit, int stride, int x, int y)
static int decode_hq_slice(const DiracContext *s, DiracSlice *slice, uint8_t *tmp_buf)
VC-2 Specification -> 13.5.3 hq_slice(sx,sy)
static int dirac_unpack_idwt_params(DiracContext *s)
Dirac Specification -> 11.3 Wavelet transform data.
static int dirac_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *pkt)
static void select_dsp_funcs(DiracContext *s, int width, int height, int xblen, int yblen)
static int coeff_unpack_golomb(GetBitContext *gb, int qfactor, int qoffset)
#define DIRAC_REF_MASK_REF1
DiracBlock->ref flags, if set then the block does MC from the given ref.
static AVOnce dirac_arith_init
static int get_buffer_with_edge(AVCodecContext *avctx, AVFrame *f, int flags)
static av_cold int dirac_decode_end(AVCodecContext *avctx)
av_cold void ff_diracdsp_init(DiracDSPContext *c)
av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, AVCodecContext *avctx)
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
static int ff_thread_once(char *control, void(*routine)(void))
static const uint16_t mask[17]
#define FFSWAP(type, a, b)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
const h264_weight_func weight
static const float pred[4]
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int64_t max_pixels
The number of pixels per image to maximally accept.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int level
Encoding level descriptor.
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
enum AVColorSpace colorspace
YUV colorspace type.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
This structure describes decoded (raw) audio or video data.
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
MpegvideoEncDSPContext mpvencdsp
struct DiracContext::@147166022327170112176317016052126250043074320045 highquality
DiracFrame * delay_frames[MAX_DELAY+1]
dirac_biweight_func biweight_func
uint8_t obmc_weight[3][MAX_BLOCKSIZE *MAX_BLOCKSIZE]
uint8_t * edge_emu_buffer[4]
uint8_t quant[MAX_DWT_LEVELS][4]
DiracFrame * ref_frames[MAX_REFERENCE_FRAMES+1]
uint8_t * edge_emu_buffer_base
unsigned weight_log2denom
DiracFrame * current_picture
dirac_weight_func weight_func
DiracSlice * slice_params_buf
unsigned old_delta_quant
schroedinger older than 1.0.8 doesn't store quant delta if only one codebook exists in a band
DiracFrame all_frames[MAX_FRAMES]
void(* avg_pixels_tab[4])(uint8_t *dst, const uint8_t *src[5], ptrdiff_t stride, int h)
void(* put_pixels_tab[4])(uint8_t *dst, const uint8_t *src[5], ptrdiff_t stride, int h)
void(* add_obmc)(uint16_t *dst, const uint8_t *src, ptrdiff_t stride, const uint8_t *obmc_weight, int yblen)
struct DiracContext::@326161170100263300254156105370361300176302314315 globalmc[2]
struct DiracContext::@263155311377021006273053315211030157311361241365 lowdelay
uint8_t * hpel_base[3][4]
SubBand band[DWT_LEVELS_3D][4]
const uint8_t * coeff_data
#define av_malloc_array(a, b)
#define av_realloc_f(p, o, n)
static void error(const char *err)
static int ref[MAX_W *MAX_W]
static double b1(void *priv, double x, double y)
static double b2(void *priv, double x, double y)
Core video DSP helper functions.
static const uint8_t quant[64]