Go to the documentation of this file.
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))
80 uint8_t *hpel_base[3][4];
108 typedef struct Plane {
254 return (
int)((x+1
U)*21845 + 10922) >> 16;
260 int i, remove_idx = -1;
262 for (
i = 0; framelist[
i];
i++)
263 if (framelist[
i]->avframe->display_picture_number == picnum) {
264 remove_pic = framelist[
i];
269 for (
i = remove_idx; framelist[
i];
i++)
270 framelist[
i] = framelist[
i+1];
278 for (
i = 0;
i < maxframes;
i++)
289 int sbheight =
DIVRNDUP(
s->seq.height, 4);
290 int i,
w,
h, top_padding;
293 for (
i = 0;
i < 3;
i++) {
296 w =
s->seq.width >> (
i ?
s->chroma_x_shift : 0);
297 h =
s->seq.height >> (
i ?
s->chroma_y_shift : 0);
308 s->plane[
i].idwt.buf_base =
av_calloc(
w + max_xblen,
h * (2 <<
s->pshift));
310 s->plane[
i].idwt.buf =
s->plane[
i].idwt.buf_base + (top_padding*
w)*(2 <<
s->pshift);
311 if (!
s->plane[
i].idwt.buf_base || !
s->plane[
i].idwt.tmp)
319 if (!
s->sbsplit || !
s->blmotion)
326 int w =
s->seq.width;
327 int h =
s->seq.height;
332 if (
s->buffer_stride >=
stride)
334 s->buffer_stride = 0;
337 memset(
s->edge_emu_buffer, 0,
sizeof(
s->edge_emu_buffer));
346 if (!
s->edge_emu_buffer_base || !
s->mctmp || !
s->mcscratch)
358 if (
s->all_frames[
i].avframe->data[0]) {
360 memset(
s->all_frames[
i].interpolated, 0,
sizeof(
s->all_frames[
i].interpolated));
363 for (j = 0; j < 3; j++)
364 for (k = 1; k < 4; k++)
368 memset(
s->ref_frames, 0,
sizeof(
s->ref_frames));
369 memset(
s->delay_frames, 0,
sizeof(
s->delay_frames));
371 for (
i = 0;
i < 3;
i++) {
376 s->buffer_stride = 0;
393 s->frame_number = -1;
395 s->thread_buf =
NULL;
396 s->threads_num_buf = -1;
397 s->thread_buf_size = -1;
405 if (!
s->all_frames[
i].avframe) {
422 s->seen_sequence_header = 0;
423 s->frame_number = -1;
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)) {
515 if (
quant > INT_MAX -
b->quant ||
b->quant +
quant < 0) {
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)); \
601 int cb_x, cb_y,
left, right, top, bottom;
606 int blockcnt_one = (cb_width + cb_height) == 2;
618 for (cb_y = 0; cb_y < cb_height; cb_y++) {
619 bottom = (
b->height * (cb_y+1LL)) / cb_height;
621 for (cb_x = 0; cb_x < cb_width; cb_x++) {
622 right = (
b->width * (cb_x+1LL)) / cb_width;
633 intra_dc_prediction_10(
b);
635 intra_dc_prediction_8(
b);
663 int level, num_bands = 0;
666 int damaged_count = 0;
670 for (orientation = !!
level; orientation < 4; orientation++) {
702 for (
i = 0;
i <
s->wavelet_depth * 3 + 1;
i++) {
706 if (damaged_count > (
s->wavelet_depth * 3 + 1) /2)
712 #define PARSE_VALUES(type, x, gb, ebits, buf1, buf2) \
713 type *buf = (type *)buf1; \
714 buf[x] = coeff_unpack_golomb(gb, qfactor, qoffset); \
715 if (get_bits_count(gb) >= ebits) \
718 buf = (type *)buf2; \
719 buf[x] = coeff_unpack_golomb(gb, qfactor, qoffset); \
720 if (get_bits_count(gb) >= ebits) \
725 int slice_x,
int slice_y,
int bits_end,
728 int left =
b1->width * slice_x /
s->num_x;
729 int right =
b1->width *(slice_x+1) /
s->num_x;
730 int top =
b1->height * slice_y /
s->num_y;
731 int bottom =
b1->height *(slice_y+1) /
s->num_y;
733 int qfactor, qoffset;
735 uint8_t *buf1 =
b1->ibuf + top *
b1->stride;
736 uint8_t *buf2 =
b2 ?
b2->ibuf + top *
b2->stride:
NULL;
751 for (y = top; y < bottom; y++) {
752 for (x =
left; x < right; x++) {
761 for (y = top; y < bottom; y++) {
762 for (x =
left; x < right; x++) {
791 for (orientation = !!
level; orientation < 4; orientation++) {
800 chroma_bits = 8*slice->
bytes - 7 - length_bits - luma_bits;
804 for (orientation = !!
level; orientation < 4; orientation++) {
807 &
s->plane[1].band[
level][orientation],
808 &
s->plane[2].band[
level][orientation]);
829 o->
top =
b->height * y /
s->num_y;
830 o->
left =
b->width * x /
s->num_x;
831 o->
tot_h = ((
b->width * (x + 1)) /
s->num_x) - o->
left;
832 o->
tot_v = ((
b->height * (y + 1)) /
s->num_y) - o->
top;
845 int i,
level, orientation, quant_idx;
860 for (orientation = !!
level; orientation < 4; orientation++) {
861 const int quant =
FFMAX(quant_idx -
s->lowdelay.quant[
level][orientation], 0);
868 for (
i = 0;
i < 3;
i++) {
869 int coef_num, coef_par, off = 0;
870 int64_t length =
s->highquality.size_scaler*
get_bits(gb, 8);
888 if (coef_num > coef_par) {
889 const int start_b = coef_par * (1 << (
s->pshift + 1));
890 const int end_b = coef_num * (1 << (
s->pshift + 1));
891 memset(&tmp_buf[start_b], 0, end_b - start_b);
896 for (orientation = !!
level; orientation < 4; orientation++) {
898 uint8_t *buf =
b1->ibuf +
c->top *
b1->stride + (
c->left << (
s->pshift + 1));
901 const int qfunc =
s->pshift + 2*(
c->tot_h <= 2);
902 s->diracdsp.dequant_subband[qfunc](&tmp_buf[off], buf,
b1->stride,
903 qfactor[
level][orientation],
904 qoffset[
level][orientation],
907 off +=
c->tot << (
s->pshift + 1);
922 uint8_t *thread_buf = &
s->thread_buf[
s->thread_buf_size*threadnr];
923 for (
i = 0;
i <
s->num_x;
i++)
935 int slice_x, slice_y, bufsize;
936 int64_t coef_buf_size, bytes = 0;
942 if (
s->slice_params_num_buf != (
s->num_x *
s->num_y)) {
944 if (!
s->slice_params_buf) {
946 s->slice_params_num_buf = 0;
949 s->slice_params_num_buf =
s->num_x *
s->num_y;
951 slices =
s->slice_params_buf;
956 coef_buf_size = (coef_buf_size << (1 +
s->pshift)) + 512;
959 s->thread_buf_size != coef_buf_size) {
961 s->thread_buf_size = coef_buf_size;
963 if (!
s->thread_buf) {
977 for (slice_y = 0; bufsize > 0 && slice_y <
s->num_y; slice_y++) {
978 for (slice_x = 0; bufsize > 0 && slice_x <
s->num_x; slice_x++) {
979 bytes =
s->highquality.prefix_bytes + 1;
980 for (
i = 0;
i < 3;
i++) {
981 if (bytes <= bufsize/8)
982 bytes += buf[bytes] *
s->highquality.size_scaler + 1;
984 if (bytes >= INT_MAX || bytes*8 > bufsize) {
989 slices[slice_num].
bytes = bytes;
990 slices[slice_num].
slice_x = slice_x;
991 slices[slice_num].
slice_y = slice_y;
996 if (bufsize/8 >= bytes)
1003 if (
s->num_x*
s->num_y != slice_num) {
1010 for (slice_y = 0; bufsize > 0 && slice_y <
s->num_y; slice_y++) {
1011 for (slice_x = 0; bufsize > 0 && slice_x <
s->num_x; slice_x++) {
1012 bytes = (slice_num+1) * (int64_t)
s->lowdelay.bytes.num /
s->lowdelay.bytes.den
1013 - slice_num * (int64_t)
s->lowdelay.bytes.num /
s->lowdelay.bytes.den;
1014 if (bytes >= INT_MAX || bytes*8 > bufsize) {
1018 slices[slice_num].
bytes = bytes;
1019 slices[slice_num].
slice_x = slice_x;
1020 slices[slice_num].
slice_y = slice_y;
1025 if (bufsize/8 >= bytes)
1035 if (
s->dc_prediction) {
1037 intra_dc_prediction_10(&
s->plane[0].band[0][0]);
1038 intra_dc_prediction_10(&
s->plane[1].band[0][0]);
1039 intra_dc_prediction_10(&
s->plane[2].band[0][0]);
1041 intra_dc_prediction_8(&
s->plane[0].band[0][0]);
1042 intra_dc_prediction_8(&
s->plane[1].band[0][0]);
1043 intra_dc_prediction_8(&
s->plane[2].band[0][0]);
1054 for (
i = 0;
i < 3;
i++) {
1057 p->
width =
s->seq.width >> (
i ?
s->chroma_x_shift : 0);
1058 p->
height =
s->seq.height >> (
i ?
s->chroma_y_shift : 0);
1066 for (orientation = !!
level; orientation < 4; orientation++) {
1069 b->pshift =
s->pshift;
1075 b->orientation = orientation;
1077 if (orientation & 1)
1078 b->ibuf +=
w << (1+
b->pshift);
1079 if (orientation > 1)
1080 b->ibuf += (
b->stride>>1);
1088 p->
xblen =
s->plane[0].xblen >>
s->chroma_x_shift;
1089 p->
yblen =
s->plane[0].yblen >>
s->chroma_y_shift;
1090 p->
xbsep =
s->plane[0].xbsep >>
s->chroma_x_shift;
1091 p->
ybsep =
s->plane[0].ybsep >>
s->chroma_y_shift;
1106 static const uint8_t default_blen[] = { 4, 12, 16, 24 };
1128 s->plane[0].xblen = default_blen[idx-1];
1129 s->plane[0].yblen = default_blen[idx-1];
1130 s->plane[0].xbsep = 4 * idx;
1131 s->plane[0].ybsep = 4 * idx;
1136 if (
s->plane[0].xblen % (1 <<
s->chroma_x_shift) != 0 ||
1137 s->plane[0].yblen % (1 <<
s->chroma_y_shift) != 0 ||
1138 !
s->plane[0].xblen || !
s->plane[0].yblen) {
1140 "invalid x/y block length (%d/%d) for x/y chroma shift (%d/%d)\n",
1141 s->plane[0].xblen,
s->plane[0].yblen,
s->chroma_x_shift,
s->chroma_y_shift);
1144 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) {
1148 if (
s->plane[0].xbsep >
s->plane[0].xblen ||
s->plane[0].ybsep >
s->plane[0].yblen) {
1160 if (
s->mv_precision > 3) {
1168 if (
s->globalmc_flag) {
1169 memset(
s->globalmc, 0,
sizeof(
s->globalmc));
1185 s->globalmc[
ref].zrs[0][0] = 1;
1186 s->globalmc[
ref].zrs[1][1] = 1;
1194 if (
s->globalmc[
ref].perspective_exp + (uint64_t)
s->globalmc[
ref].zrs_exp > 30) {
1210 s->weight_log2denom = 1;
1216 if (
s->weight_log2denom < 1 ||
s->weight_log2denom > 8) {
1218 s->weight_log2denom = 1;
1222 if (
s->num_refs == 2)
1238 #define CHECKEDREAD(dst, cond, errmsg) \
1239 tmp = get_interleaved_ue_golomb(gb); \
1241 av_log(s->avctx, AV_LOG_ERROR, errmsg); \
1242 return AVERROR_INVALIDDATA; \
1257 if (!
s->low_delay) {
1260 for (
i = 0;
i <=
s->wavelet_depth;
i++) {
1261 CHECKEDREAD(
s->codeblock[
i].width , tmp < 1 || tmp > (
s->avctx->width >>
s->wavelet_depth-
i),
"codeblock width invalid\n")
1262 CHECKEDREAD(
s->codeblock[
i].height, tmp < 1 || tmp > (
s->avctx->height>>
s->wavelet_depth-
i),
"codeblock height invalid\n")
1268 for (
i = 0;
i <=
s->wavelet_depth;
i++)
1269 s->codeblock[
i].width =
s->codeblock[
i].height = 1;
1275 if (
s->num_x *
s->num_y == 0 ||
s->num_x * (uint64_t)
s->num_y > INT_MAX ||
1276 s->num_x * (uint64_t)
s->avctx->width > INT_MAX ||
1277 s->num_y * (uint64_t)
s->avctx->height > INT_MAX ||
1278 s->num_x >
s->avctx->width ||
1279 s->num_y >
s->avctx->height
1282 s->num_x =
s->num_y = 0;
1285 if (
s->ld_picture) {
1288 if (
s->lowdelay.bytes.den <= 0) {
1292 }
else if (
s->hq_picture) {
1295 if (
s->highquality.prefix_bytes >= INT_MAX / 8) {
1311 if (
s->wavelet_depth > 4) {
1312 av_log(
s->avctx,
AV_LOG_ERROR,
"Mandatory custom low delay matrix missing for depth %d\n",
s->wavelet_depth);
1317 for (
i = 0;
i < 4;
i++) {
1320 if (
s->wavelet_idx == 3)
1321 s->lowdelay.quant[
level][
i] += 4*(
s->wavelet_depth-1 -
level);
1330 static const uint8_t avgsplit[7] = { 0, 0, 1, 1, 1, 2, 2 };
1339 return avgsplit[sbsplit[-1] + sbsplit[-
stride] + sbsplit[-
stride-1]];
1349 return block[-1].ref & refmask;
1355 return (
pred >> 1) & refmask;
1365 for (
i = 0;
i < 3;
i++)
1371 for (
i = 0;
i < 3;
i++)
1377 for (
i = 0;
i < 3;
i++)
1383 for (
i = 0;
i < 3;
i++)
1385 }
else if (n == 3) {
1386 for (
i = 0;
i < 3;
i++)
1394 int refmask =
ref+1;
1429 int ez =
s->globalmc[
ref].zrs_exp;
1430 int ep =
s->globalmc[
ref].perspective_exp;
1431 int (*
A)[2] =
s->globalmc[
ref].zrs;
1432 int *
b =
s->globalmc[
ref].pan_tilt;
1433 int *
c =
s->globalmc[
ref].perspective;
1435 int64_t m = (1<<ep) - (
c[0]*(int64_t)x +
c[1]*(int64_t)y);
1436 int64_t mx = m * (uint64_t)((
A[0][0] * (int64_t)x +
A[0][1]*(int64_t)y) + (1LL<<ez) *
b[0]);
1437 int64_t my = m * (uint64_t)((
A[1][0] * (int64_t)x +
A[1][1]*(int64_t)y) + (1LL<<ez) *
b[1]);
1439 block->u.mv[
ref][0] = (mx + (1<<(ez+ep))) >> (ez+ep);
1440 block->u.mv[
ref][1] = (my + (1<<(ez+ep))) >> (ez+ep);
1444 int stride,
int x,
int y)
1451 if (
s->num_refs == 2) {
1458 for (
i = 0;
i < 3;
i++)
1463 if (
s->globalmc_flag) {
1468 for (
i = 0;
i <
s->num_refs;
i++)
1469 if (
block->ref & (
i+1)) {
1488 for (x = 1; x <
size; x++)
1491 for (y = 1; y <
size; y++) {
1493 for (x = 0; x <
size; x++)
1505 uint8_t *sbsplit =
s->sbsplit;
1512 s->sbwidth =
DIVRNDUP(
s->seq.width, 4*
s->plane[0].xbsep);
1513 s->sbheight =
DIVRNDUP(
s->seq.height, 4*
s->plane[0].ybsep);
1514 s->blwidth = 4 *
s->sbwidth;
1515 s->blheight = 4 *
s->sbheight;
1520 for (y = 0; y <
s->sbheight; y++) {
1521 for (x = 0; x <
s->sbwidth; x++) {
1527 sbsplit +=
s->sbwidth;
1532 for (
i = 0;
i <
s->num_refs;
i++) {
1536 for (
i = 0;
i < 3;
i++)
1539 for (y = 0; y <
s->sbheight; y++)
1540 for (x = 0; x <
s->sbwidth; x++) {
1541 int blkcnt = 1 <<
s->sbsplit[y *
s->sbwidth + x];
1542 int step = 4 >>
s->sbsplit[y *
s->sbwidth + x];
1544 for (q = 0; q < blkcnt; q++)
1545 for (p = 0; p < blkcnt; p++) {
1546 int bx = 4 * x + p*
step;
1547 int by = 4 * y + q*
step;
1554 for (
i = 0;
i < 4 + 2*
s->num_refs;
i++) {
1564 #define ROLLOFF(i) offset == 1 ? ((i) ? 5 : 3) : \
1565 (1 + (6*(i) + offset - 1) / (2*offset - 1))
1569 else if (
i > blen-1 - 2*
offset)
1575 int left,
int right,
int wy)
1578 for (x = 0;
left && x < p->
xblen >> 1; x++)
1579 obmc_weight[x] = wy*8;
1580 for (; x < p->
xblen >> right; x++)
1582 for (; x < p->
xblen; x++)
1583 obmc_weight[x] = wy*8;
1589 int left,
int right,
int top,
int bottom)
1592 for (y = 0; top && y < p->
yblen >> 1; y++) {
1596 for (; y < p->
yblen >> bottom; y++) {
1601 for (; y < p->
yblen; y++) {
1610 int bottom = by ==
s->blheight-1;
1613 if (top || bottom || by == 1) {
1648 int x,
int y,
int ref,
int plane)
1650 Plane *p = &
s->plane[plane];
1651 uint8_t **ref_hpel =
s->ref_pics[
ref]->hpel[plane];
1652 int motion_x =
block->u.mv[
ref][0];
1653 int motion_y =
block->u.mv[
ref][1];
1654 int mx, my,
i, epel, nplanes = 0;
1657 motion_x >>=
s->chroma_x_shift;
1658 motion_y >>=
s->chroma_y_shift;
1661 mx = motion_x & ~(-1
U <<
s->mv_precision);
1662 my = motion_y & ~(-1
U <<
s->mv_precision);
1663 motion_x >>=
s->mv_precision;
1664 motion_y >>=
s->mv_precision;
1667 mx <<= 3 -
s->mv_precision;
1668 my <<= 3 -
s->mv_precision;
1677 src[0] = ref_hpel[(my>>1)+(mx>>2)] + y*p->
stride + x;
1681 for (
i = 0;
i < 4;
i++)
1706 src[!mx] =
src[2 + !!mx];
1708 }
else if (!(my&3)) {
1731 for (
i = 0;
i < nplanes;
i++) {
1732 s->vdsp.emulated_edge_mc(
s->edge_emu_buffer[
i],
src[
i],
1736 src[
i] =
s->edge_emu_buffer[
i];
1739 return (nplanes>>1) + epel;
1743 uint8_t *obmc_weight,
int xblen,
int yblen)
1748 for (y = 0; y < yblen; y++) {
1749 for (x = 0; x < xblen; x += 2) {
1750 dst[x ] +=
dc * obmc_weight[x ];
1751 dst[x+1] +=
dc * obmc_weight[x+1];
1759 uint16_t *mctmp, uint8_t *obmc_weight,
1760 int plane,
int dstx,
int dsty)
1762 Plane *p = &
s->plane[plane];
1763 const uint8_t *
src[5];
1766 switch (
block->ref&3) {
1775 s->weight_func(
s->mcscratch, p->
stride,
s->weight_log2denom,
1776 s->weight[0] +
s->weight[1], p->
yblen);
1782 if (
s->biweight_func) {
1785 s->biweight_func(
s->mcscratch,
s->mcscratch+32, p->
stride,
s->weight_log2denom,
1786 s->weight[0],
s->weight[1], p->
yblen);
1791 s->add_obmc(mctmp,
s->mcscratch, p->
stride, obmc_weight, p->
yblen);
1796 Plane *p = &
s->plane[plane];
1802 for (x = 1; x <
s->blwidth-1; x++) {
1818 memcpy(
s->put_pixels_tab,
s->diracdsp.put_dirac_pixels_tab[idx],
sizeof(
s->put_pixels_tab));
1819 memcpy(
s->avg_pixels_tab,
s->diracdsp.avg_dirac_pixels_tab[idx],
sizeof(
s->avg_pixels_tab));
1820 s->add_obmc =
s->diracdsp.add_dirac_obmc[idx];
1821 if (
s->weight_log2denom > 1 ||
s->weight[0] != 1 ||
s->weight[1] != 1) {
1822 s->weight_func =
s->diracdsp.weight_dirac_pixels_tab[idx];
1823 s->biweight_func =
s->diracdsp.biweight_dirac_pixels_tab[idx];
1825 s->weight_func =
NULL;
1826 s->biweight_func =
NULL;
1837 ref->hpel[plane][0] =
ref->avframe->data[plane];
1841 if (!
s->mv_precision)
1844 for (
i = 1;
i < 4;
i++) {
1845 if (!
ref->hpel_base[plane][
i])
1847 if (!
ref->hpel_base[plane][
i]) {
1851 ref->hpel[plane][
i] =
ref->hpel_base[plane][
i] + edge*
ref->avframe->linesize[plane] + 16;
1854 if (!
ref->interpolated[plane]) {
1855 s->diracdsp.dirac_hpel_filter(
ref->hpel[plane][1],
ref->hpel[plane][2],
1856 ref->hpel[plane][3],
ref->hpel[plane][0],
1862 ref->interpolated[plane] = 1;
1874 int y,
i,
comp, dsty;
1879 if (!
s->hq_picture) {
1893 uint8_t *
frame =
s->current_picture->avframe->data[
comp];
1896 for (
i = 0;
i < 4;
i++)
1899 if (!
s->zero_res && !
s->low_delay)
1907 s->wavelet_depth,
s->bit_depth);
1912 for (y = 0; y < p->
height; y += 16) {
1913 int idx = (
s->bit_depth - 8) >> 1;
1915 s->diracdsp.put_signed_rect_clamped[idx](
frame + y*p->
stride,
1925 for (
i = 0;
i <
s->num_refs;
i++) {
1934 for (y = 0; y <
s->blheight; y++) {
1936 start =
FFMAX(dsty, 0);
1937 uint16_t *mctmp =
s->mctmp + y*rowheight;
1945 h = p->
ybsep - (start - dsty);
1971 int chroma_x_shift, chroma_y_shift;
1983 for (
i = 0;
f->data[
i];
i++) {
1985 f->linesize[
i] + 32;
2000 unsigned retire, picnum;
2002 int64_t refdist, refnum;
2006 picnum =
s->current_picture->avframe->display_picture_number =
get_bits_long(gb, 32);
2013 if (
s->frame_number < 0)
2014 s->frame_number = picnum;
2016 s->ref_pics[0] =
s->ref_pics[1] =
NULL;
2017 for (
i = 0;
i <
s->num_refs;
i++) {
2019 refdist = INT64_MAX;
2024 if (
s->ref_frames[j]
2025 &&
FFABS(
s->ref_frames[j]->avframe->display_picture_number - refnum) < refdist) {
2026 s->ref_pics[
i] =
s->ref_frames[j];
2027 refdist =
FFABS(
s->ref_frames[j]->avframe->display_picture_number - refnum);
2030 if (!
s->ref_pics[
i] || refdist)
2034 if (!
s->ref_pics[
i])
2036 if (!
s->all_frames[j].avframe->data[0]) {
2037 s->ref_pics[
i] = &
s->all_frames[j];
2044 if (!
s->ref_pics[
i]) {
2052 if (
s->current_picture->reference) {
2054 if (retire != picnum) {
2093 for (
i = 1;
s->delay_frames[
i];
i++)
2094 if (
s->delay_frames[
i]->avframe->display_picture_number <
out->avframe->display_picture_number) {
2095 out =
s->delay_frames[
i];
2099 for (
i = out_idx;
s->delay_frames[
i];
i++)
2100 s->delay_frames[
i] =
s->delay_frames[
i+1];
2117 #define DATA_UNIT_HEADER_SIZE 13
2133 parse_code = buf[4];
2138 if (
s->seen_sequence_header)
2172 s->pshift =
s->bit_depth > 8;
2176 &
s->chroma_y_shift);
2184 s->seen_sequence_header = 1;
2187 s->seen_sequence_header = 0;
2193 if (sscanf(buf+14,
"Schroedinger %d.%d.%d", ver, ver+1, ver+2) == 3)
2194 if (ver[0] == 1 && ver[1] == 0 && ver[2] <= 7)
2195 s->old_delta_quant = 1;
2197 }
else if (parse_code & 0x8) {
2198 if (!
s->seen_sequence_header) {
2205 if (
s->all_frames[
i].avframe->data[0] ==
NULL)
2206 pic = &
s->all_frames[
i];
2215 tmp = parse_code & 0x03;
2221 s->is_arith = (parse_code & 0x48) == 0x08;
2222 s->low_delay = (parse_code & 0x88) == 0x88;
2223 s->core_syntax = (parse_code & 0x88) == 0x08;
2224 s->ld_picture = (parse_code & 0xF8) == 0xC8;
2225 s->hq_picture = (parse_code & 0xF8) == 0xE8;
2226 s->dc_prediction = (parse_code & 0x28) == 0x08;
2227 pic->
reference = (parse_code & 0x0C) == 0x0C;
2232 if (
s->version.minor == 2 && parse_code == 0x88)
2235 if (
s->low_delay && !(
s->ld_picture ||
s->hq_picture) ) {
2242 s->current_picture = pic;
2267 const uint8_t *buf =
pkt->
data;
2271 unsigned data_unit_size;
2275 if (
s->all_frames[
i].avframe->data[0] && !
s->all_frames[
i].reference) {
2277 memset(
s->all_frames[
i].interpolated, 0,
sizeof(
s->all_frames[
i].interpolated));
2280 s->current_picture =
NULL;
2292 if (buf[buf_idx ] ==
'B' && buf[buf_idx+1] ==
'B' &&
2293 buf[buf_idx+2] ==
'C' && buf[buf_idx+3] ==
'D')
2300 data_unit_size =
AV_RB32(buf+buf_idx+5);
2301 if (data_unit_size > buf_size - buf_idx || !data_unit_size) {
2302 if(data_unit_size > buf_size - buf_idx)
2304 "Data unit with size %d is larger than input buffer, discarding\n",
2316 buf_idx += data_unit_size;
2319 if (!
s->current_picture)
2322 if (
s->current_picture->avframe->display_picture_number >
s->frame_number) {
2328 int min_num =
s->delay_frames[0]->avframe->display_picture_number;
2332 for (
i = 1;
s->delay_frames[
i];
i++)
2333 if (
s->delay_frames[
i]->avframe->display_picture_number < min_num)
2334 min_num =
s->delay_frames[
i]->avframe->display_picture_number;
2340 if (delayed_frame) {
2346 }
else if (
s->current_picture->avframe->display_picture_number ==
s->frame_number) {
static void error(const char *err)
#define DATA_UNIT_HEADER_SIZE
Dirac Specification -> 9.6 Parse Info Header Syntax.
void(* put_pixels_tab[4])(uint8_t *dst, const uint8_t *src[5], int stride, int h)
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 void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static int get_bits_left(GetBitContext *gb)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVColorSpace colorspace
YUV colorspace type.
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
#define u(width, name, range_min, range_max)
#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...
static void free_sequence_buffers(DiracContext *s)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static const uint8_t epel_weights[4][4][4]
static int dirac_decode_picture_header(DiracContext *s)
Dirac Specification -> 11.1.1 Picture Header.
static const int8_t mv[256][2]
static int get_bits_count(const GetBitContext *s)
static int dirac_unpack_prediction_parameters(DiracContext *s)
Unpack the motion compensation parameters Dirac Specification -> 11.2 Picture prediction data.
#define DIRAC_REF_MASK_REF1
DiracBlock->ref flags, if set then the block does MC from the given ref.
static unsigned get_interleaved_ue_golomb(GetBitContext *gb)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
dirac_biweight_func biweight_func
static int decode_lowdelay_slice(AVCodecContext *avctx, void *arg)
Dirac Specification -> 13.5.2 Slices.
MpegvideoEncDSPContext mpvencdsp
void(* dirac_biweight_func)(uint8_t *dst, const uint8_t *src, int stride, int log2_denom, int weightd, int weights, int h)
static void init_planes(DiracContext *s)
#define DIRAC_REF_MASK_GLOBAL
static AVOnce dirac_arith_init
DiracFrame * delay_frames[MAX_DELAY+1]
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
const int32_t ff_dirac_qscale_tab[116]
static int dirac_get_arith_int(DiracArith *c, int follow_ctx, int data_ctx)
static int codeblock(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....
#define CHECKEDREAD(dst, cond, errmsg)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
DiracFrame * current_picture
static int alloc_buffers(DiracContext *s, int stride)
const uint8_t ff_dirac_default_qmat[7][4][4]
av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, AVCodecContext *avctx)
static int decode_subband_arith(AVCodecContext *avctx, void *b)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
AVCodec p
The public AVCodec.
static double b1(void *priv, double x, double y)
uint8_t * edge_emu_buffer[4]
int ff_spatial_idwt_init(DWTContext *d, DWTPlane *p, enum dwt_type type, int decomposition_count, int bit_depth)
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
int key_frame
1 -> keyframe, 0-> not
static double val(void *priv, double ch)
static int dirac_unpack_block_motion_data(DiracContext *s)
Dirac Specification ->
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.
static int decode_component(DiracContext *s, int comp)
Dirac Specification -> [DIRAC_STD] 13.4.1 core_transform_data()
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
static int pred_sbsplit(uint8_t *sbsplit, int stride, int x, int y)
static void pred_block_dc(DiracBlock *block, int stride, int x, int y)
static int quant(float coef, const float Q, const float rounding)
Quantize one coefficient.
static void select_dsp_funcs(DiracContext *s, int width, int height, int xblen, int yblen)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
void(* dirac_weight_func)(uint8_t *block, int stride, int log2_denom, int weight, int h)
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static int ff_thread_once(char *control, void(*routine)(void))
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int coeff_unpack_golomb(GetBitContext *gb, int qfactor, int qoffset)
static const uint16_t mask[17]
const FFCodec ff_dirac_decoder
#define FF_CODEC_DECODE_CB(func)
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define MAX_REFERENCE_FRAMES
The spec limits this to 3 for frame coding, but in practice can be as high as 6.
void ff_dirac_init_arith_decoder(DiracArith *c, GetBitContext *gb, int length)
static av_always_inline int decode_subband_internal(DiracContext *s, SubBand *b, int is_arith)
Dirac Specification -> 13.4.2 Non-skipped subbands.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t max_pixels
The number of pixels per image to maximally accept.
static const float bands[]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
struct DiracContext::@55 globalmc[2]
#define av_realloc_f(p, o, n)
DiracSlice * slice_params_buf
uint8_t * edge_emu_buffer_base
static int dirac_get_arith_bit(DiracArith *c, int ctx)
static void mc_row(DiracContext *s, DiracBlock *block, uint16_t *mctmp, int plane, int dsty)
const int ff_dirac_qoffset_inter_tab[122]
static int decode_hq_slice_row(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
dirac_weight_func weight_func
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int dirac_decode_frame_internal(DiracContext *s)
Dirac Specification -> 13.0 Transform data syntax.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
static int decode_lowdelay(DiracContext *s)
Dirac Specification -> 13.5.1 low_delay_transform_data()
Rational number (pair of numerator and denominator).
DiracFrame * ref_frames[MAX_REFERENCE_FRAMES+1]
static unsigned int get_bits1(GetBitContext *s)
unsigned old_delta_quant
schroedinger older than 1.0.8 doesn't store quant delta if only one codebook exists in a band
static int dirac_get_arith_uint(DiracArith *c, int follow_ctx, int data_ctx)
#define DIRAC_MAX_QUANT_INDEX
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static int weight(int i, int blen, int offset)
void ff_spatial_idwt_slice2(DWTContext *d, int y)
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output.
static int add_frame(DiracFrame *framelist[], int maxframes, DiracFrame *frame)
#define INTRA_DC_PRED(n, type)
Dirac Specification -> 13.3 intra_dc_prediction(band)
static av_cold int dirac_decode_end(AVCodecContext *avctx)
enum AVPictureType pict_type
Picture type of the frame.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
struct DiracContext::@54 highquality
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static void init_obmc_weight_row(Plane *p, uint8_t *obmc_weight, int stride, int left, int right, int wy)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
unsigned weight_log2denom
static char * split(char *message, char delim)
static double b2(void *priv, double x, double y)
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static int dirac_get_se_golomb(GetBitContext *gb)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
static void add_dc(uint16_t *dst, int dc, int stride, uint8_t *obmc_weight, int xblen, int yblen)
static int get_buffer_with_edge(AVCodecContext *avctx, AVFrame *f, int flags)
static int pred_block_mode(DiracBlock *block, int stride, int x, int y, int refmask)
static int decode_hq_slice(DiracContext *s, DiracSlice *slice, uint8_t *tmp_buf)
VC-2 Specification -> 13.5.3 hq_slice(sx,sy)
static int subband_coeffs(DiracContext *s, int x, int y, int p, SliceCoeffs c[MAX_DWT_LEVELS])
static void init_obmc_weights(DiracContext *s, Plane *p, int by)
#define DECLARE_ALIGNED(n, t, v)
static int dirac_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *pkt)
#define i(width, name, range_min, range_max)
static void pred_mv(DiracBlock *block, int stride, int x, int y, int ref)
#define UNPACK_ARITH(n, type)
static int alloc_sequence_buffers(DiracContext *s)
#define DIRAC_REF_MASK_REF2
#define PARSE_VALUES(type, x, gb, ebits, buf1, buf2)
static void decode_block_params(DiracContext *s, DiracArith arith[8], DiracBlock *block, int stride, int x, int y)
int ff_dirac_golomb_read_16bit(const uint8_t *buf, int bytes, uint8_t *_dst, int coeffs)
#define av_malloc_array(a, b)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
av_cold void ff_dirac_init_arith_tables(void)
const char * name
Name of the codec implementation.
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 ...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void * av_calloc(size_t nmemb, size_t size)
static int interpolate_refplane(DiracContext *s, DiracFrame *ref, int plane, int width, int height)
const uint8_t * coeff_data
static const float pred[4]
#define FFSWAP(type, a, b)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static const uint8_t * align_get_bits(GetBitContext *s)
static DiracFrame * remove_frame(DiracFrame *framelist[], int picnum)
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
int ff_dirac_golomb_read_32bit(const uint8_t *buf, int bytes, uint8_t *_dst, int coeffs)
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
static int decode_subband_golomb(AVCodecContext *avctx, void *arg)
const int32_t ff_dirac_qoffset_intra_tab[120]
void(* add_obmc)(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen)
main external API structure.
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.
DiracFrame all_frames[MAX_FRAMES]
#define CALC_PADDING(size, depth)
static int ref[MAX_W *MAX_W]
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
static int divide3(int x)
uint8_t quant[MAX_DWT_LEVELS][4]
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
SubBand band[DWT_LEVELS_3D][4]
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.
This structure stores compressed data.
static void global_mv(DiracContext *s, DiracBlock *block, int x, int y, int ref)
static void decode_subband(DiracContext *s, GetBitContext *gb, int quant, int slice_x, int slice_y, int bits_end, SubBand *b1, SubBand *b2)
void(* avg_pixels_tab[4])(uint8_t *dst, const uint8_t *src[5], int stride, int h)
int width
picture width / height.
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
The exact code depends on how similar the blocks are and how related they are to the block
static const double coeff[2][5]
static int dirac_decode_data_unit(AVCodecContext *avctx, const uint8_t *buf, int size)
struct DiracContext::@53 lowdelay
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static av_cold int dirac_decode_init(AVCodecContext *avctx)
av_cold void ff_diracdsp_init(DiracDSPContext *c)
static int dirac_unpack_idwt_params(DiracContext *s)
Dirac Specification -> 11.3 Wavelet transform data.
uint8_t obmc_weight[3][MAX_BLOCKSIZE *MAX_BLOCKSIZE]
static void dirac_decode_flush(AVCodecContext *avctx)
int display_picture_number
picture number in display order
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.
struct DiracContext::@52 codeblock[MAX_DWT_LEVELS+1]
static int get_delayed_pic(DiracContext *s, AVFrame *picture, int *got_frame)
static void init_obmc_weight(Plane *p, uint8_t *obmc_weight, int stride, int left, int right, int top, int bottom)
static void block_mc(DiracContext *s, DiracBlock *block, uint16_t *mctmp, uint8_t *obmc_weight, int plane, int dstx, int dsty)