Go to the documentation of this file.
99 #define MAX_VLC_SIZE 864
105 int counts[17] = {0};
112 codes[0] = counts[0] = 0;
113 for (
int i = 0;
i < 17;
i++)
114 codes[
i+1] = (codes[
i] + counts[
i]) << 1;
126 for (
int i = 0;
i < count;
i++) {
127 for (
int j = 0; j < 2; j++) {
140 for (
int i = 0;
i < 7;
i++)
141 for (
int j = 0; j < 4; j++)
144 for (
int i = 0;
i < 7;
i++)
145 for (
int j = 0; j < 3; j++)
146 for (
int k = 0; k < 4; k++)
162 uint8_t cu_split[1+4+16+64];
164 uint8_t coded_blk[64];
166 uint8_t avg_buffer[64*64 + 32*32*2];
167 uint8_t * avg_data[3];
235 if (
s->nb_progress < count) {
240 memset(
s->progress +
s->nb_progress, 0, (count -
s->nb_progress) *
sizeof(*
s->progress));
241 for (
int i =
s->nb_progress;
i < count;
i++) {
245 s->nb_progress =
i + 1;
249 for (
int i = 0;
i < count;
i++)
266 for (
int i = 0;
i < 3;
i++) {
268 if (!
s->last_frame[
i])
281 if (
width !=
s->avctx->width ||
height !=
s->avctx->height) {
285 for (
int i = 0;
i < 3;
i++)
291 if (
s->avctx->width <= 64 ||
s->avctx->height <= 64)
292 av_log(
s->avctx,
AV_LOG_WARNING,
"unable to faithfully reproduce emulated edges; expect visual artefacts\n");
298 s->cu_width = (
width + 63) >> 6;
299 s->cu_height = (
height + 63) >> 6;
301 s->pu_stride =
s->cu_width << 3;
302 s->blk_stride =
s->cu_width << 4;
313 memset(
s->pu_info, 0,
s->pu_stride * (
s->cu_height << 3) *
sizeof(
s->pu_info[0]));
314 memset(
s->blk_info, 0,
s->blk_stride * (
s->cu_height << 4) *
sizeof(
s->blk_info[0]));
316 for (
int j = 0; j <
s->cu_height << 4; j++)
317 for (
int i = 0;
i <
s->cu_width << 4;
i++)
323 s->dblk_stride =
s->awidth >> 2;
325 size =
s->dblk_stride * (
s->aheight >> 2);
333 memset(
s->top_str, 0,
size);
334 memset(
s->left_str, 0,
size);
386 for (
int i = 0;
i < count;
i++)
387 for (
int j = 0; j < 2 <<
i; j++)
400 for (
int i = 0;
i <
s->cu_height;
i++)
408 for (
int i = 1;
i <
s->cu_height;
i++) {
410 if (
s->slice[
i].sign)
416 s->slice[
i].size = last_size;
436 return ypos + dy && xpos + dx +
size <=
s->awidth;
441 return xpos + dx && ypos + dy +
size <=
s->aheight;
490 memset(
i->t, 0x80,
sizeof(
i->t));
491 memset(
i->l, 0x80,
sizeof(
i->l));
492 i->has_t =
i->has_tr =
i->has_l =
i->has_ld = 0;
504 if (cu->
ypos + yoff > 0) {
516 if (cu->
xpos + xoff > 0)
520 if (cu->
xpos + xoff > 0) {
523 for (
int y = 0; y <
size; y++)
529 for (
int y =
size; y <
size * 2; y++)
534 if (cu->
ypos + yoff > 0)
541 int lastl =
p->l[
size + 1];
542 int lastt =
p->t[
size + 1];
543 int tmp1[64], tmp2[64];
544 int top_ref[64], left_ref[64];
547 for (
int i = 0;
i <
size;
i++) {
548 tmp1[
i] = lastl -
p->t[
i + 1];
549 tmp2[
i] = lastt -
p->l[
i + 1];
553 for (
int i = 0;
i <
size;
i++) {
554 top_ref[
i] =
p->t[
i + 1] << (
shift - 1);
555 left_ref[
i] =
p->l[
i + 1] << (
shift - 1);
558 for (
int y = 0; y <
size; y++) {
560 int sum = left_ref[y] +
size;
561 for (
int x = 0; x <
size; x++) {
562 int v = tmp1[x] + top_ref[x];
574 if (!
p->has_t && !
p->has_l)
579 for (
int x = 0; x <
size; x++)
582 for (
int y = 0; y <
size; y++)
584 if (
p->has_t &&
p->has_l)
590 for (
int y = 0; y <
size; y++)
593 if (
filter &&
p->has_t &&
p->has_l) {
594 dst[0] = (
p->t[1] +
p->l[1] + 2 *
dst[0] + 2) >> 2;
595 for (
int x = 1; x <
size; x++)
596 dst[x] = (
p->t[x + 1] + 3 *
dst[x] + 2) >> 2;
597 for (
int y = 1; y <
size; y++)
605 for (
int i = 1;
i <
size - 1;
i++)
613 int sum = (v0 << 5) + (1 << (5 - 1));
614 for (
int i = 0;
i <
size;
i++) {
623 for (
int x = 0; x <
size; x++) {
626 off = (sum >> 5) + 32;
629 for (
int y = 0; y <
size; y++)
632 for (
int y = 0; y <
size; y++) {
633 int a =
src[off + y];
634 int b =
src[off + y + 1];
635 dst[y*
stride + x] = ((32 - frac) *
a + frac *
b + 16) >> 5;
644 for (
int y = 0; y <
size; y++) {
647 off = (sum >> 5) + 32;
652 for (
int x = 0; x <
size; x++) {
653 int a =
src[off + x];
654 int b =
src[off + x + 1];
655 dst[y*
stride + x] = ((32 - frac) *
a + frac *
b + 16) >> 5;
663 uint8_t filtered1[96], filtered2[96];
667 }
else if (imode == 1) {
669 }
else if (imode <= 9) {
671 int add_size = (
size * ang_weight + 31) >> 5;
679 }
else if (imode == 10) {
684 for (
int y = 0; y <
size; y++)
685 for (
int x = 0; x <
size; x++)
689 for (
int x = 0; x <
size; x++)
692 }
else if (imode <= 17) {
695 int add_size = (
size * ang_weight + 31) >> 5;
697 memcpy(filtered1 + 32 - 1,
p->l,
size + 1);
698 memcpy(filtered2 + 32 - 1,
p->t,
size + 1);
700 filtered1[32 - 1] =
p->l[0];
702 filtered2[32 - 1] =
p->t[0];
707 for (
int i = 1;
i < add_size;
i++) {
709 filtered1[32 - 1 -
i] = filtered2[32 - 1 + (sum >> 8)];
713 }
else if (imode <= 25) {
716 int add_size = (
size * ang_weight + 31) >> 5;
718 memcpy(filtered1 + 32 - 1,
p->t,
size + 1);
719 memcpy(filtered2 + 32 - 1,
p->l,
size + 1);
721 filtered1[32 - 1] =
p->t[0];
723 filtered2[32 - 1] =
p->l[0];
728 for (
int i = 1;
i < add_size;
i++) {
730 filtered1[32 - 1 -
i] = filtered2[32 - 1 + (sum >> 8)];
734 }
else if (imode == 26) {
743 for (
int y = 0; y <
size; y++)
746 }
else if (imode <= 34) {
748 int add_size = (
size * ang_weight + 31) >> 5;
771 #define MK_UNIQUELIST(name, type, max_size) \
773 type list[max_size]; \
775 } unique_list_##name; \
777 static void unique_list_##name##_init(unique_list_##name * s) \
779 memset(s->list, 0, sizeof(s->list)); \
783 static void unique_list_##name##_add(unique_list_##name * s, type cand) \
785 if (s->size == max_size) \
788 for (int i = 0; i < s->size; i++) { \
789 if (!memcmp(&s->list[i], &cand, sizeof(type))) { \
793 s->list[s->size++] = cand; \
801 int blk_pos, tl_x, tl_y;
802 unique_list_intramode ipm_cand;
810 unique_list_intramode_init(&ipm_cand);
813 const PUInfo * pu = &
s->pu_info[cu->pu_pos -
s->pu_stride];
815 unique_list_intramode_add(&ipm_cand,
s->blk_info[cu->blk_pos -
s->blk_stride + (sub & 1)].imode);
818 blk_pos = cu->blk_pos + (sub >> 1) *
s->blk_stride + (sub & 1);
821 const PUInfo * pu = &
s->pu_info[cu->pu_pos - 1];
823 unique_list_intramode_add(&ipm_cand,
s->blk_info[blk_pos - 1 - (sub & 1)].imode);
826 tl_x = !(sub & 2) ? (cu->xpos + (sub & 1) * 4) : cu->xpos;
827 tl_y = cu->ypos + (sub & 2) * 4;
828 if (tl_x > 0 && tl_y > 0) {
831 case 0: pu = &
s->pu_info[cu->pu_pos -
s->pu_stride - 1];
break;
832 case 1: pu = &
s->pu_info[cu->pu_pos -
s->pu_stride];
break;
833 default: pu = &
s->pu_info[cu->pu_pos - 1];
837 unique_list_intramode_add(&ipm_cand,
s->blk_info[blk_pos -
s->blk_stride - 1].imode);
839 unique_list_intramode_add(&ipm_cand,
s->blk_info[blk_pos -
s->blk_stride - 2].imode);
847 return ipm_cand.list[cu->imode_param[sub]];
850 enum IntraMode imode = cu->imode_param[sub];
851 qsort(ipm_cand.list, 3,
sizeof(ipm_cand.list[0]),
ipm_compar);
852 for (
int i = 0;
i < 3;
i++)
853 if (imode >= ipm_cand.list[
i])
875 unique_list_mvinfo_add(skip_cand, *mvi);
880 int mv_size =
size >> 2;
886 if (cu->
ypos && cu->
xpos + size < s->awidth)
888 if (cu->
xpos && cu->
ypos + size < s->aheight)
897 for (
int i = skip_cand->size;
i < 4;
i++)
907 int mv_size =
size >> 2;
910 dim->w =
dim->h = mv_size;
914 dim->h = mv_size >> 1;
917 dim->w = mv_size >> 1;
921 dim->w =
dim->h = mv_size >> 1;
925 dim->h = !part_no ? (mv_size >> 2) : ((3 * mv_size) >> 2);
929 dim->h = !part_no ? ((3 * mv_size) >> 2) : (mv_size >> 2);
932 dim->w = !part_no ? (mv_size >> 2) : ((3 * mv_size) >> 2);
936 dim->w = !part_no ? ((3 * mv_size) >> 2) : (mv_size >> 2);
968 *mv_pos +=
dim->h*
s->blk_stride -
dim->w;
973 *mv_pos +=
dim->h *
s->blk_stride;
1010 if (
a->mvref !=
b->mvref)
1015 int dx =
a->f_mv.x -
b->f_mv.x;
1016 int dy =
a->f_mv.y -
b->f_mv.y;
1020 int dx =
a->b_mv.x -
b->b_mv.x;
1021 int dy =
a->b_mv.y -
b->b_mv.y;
1034 ret->x = a.x < c.x ? c.x : a.x; \
1037 ret->x = a.x < c.x ? a.x : c.x; \
1047 int mv_pos = mv_y *
s->blk_stride + mv_x;
1056 const MVInfo *
mv = &
s->blk_info[mv_pos - 1].mv;
1058 cand[cand_size++] =
mv->f_mv;
1061 const MVInfo *
mv = &
s->blk_info[mv_pos -
s->blk_stride].mv;
1063 cand[cand_size++] =
mv->f_mv;
1066 const MVInfo *
mv = &
s->blk_info[mv_pos -
s->blk_stride + mv_w].mv;
1068 cand[cand_size++] =
mv->f_mv;
1071 switch (cand_size) {
1077 f_mv.
x = (cand[0].
x + cand[1].
x) >> 1;
1078 f_mv.
y = (cand[0].
y + cand[1].
y) >> 1;
1081 mv_pred(&f_mv, cand[0], cand[1], cand[2]);
1091 dst->f_mv.x =
src->f_mv.x + f_mv.
x;
1092 dst->f_mv.y =
src->f_mv.y + f_mv.
y;
1098 const MVInfo *
mv = &
s->blk_info[mv_pos - 1].mv;
1100 cand[cand_size++] =
mv->b_mv;
1103 const MVInfo *
mv = &
s->blk_info[mv_pos -
s->blk_stride].mv;
1105 cand[cand_size++] =
mv->b_mv;
1108 const MVInfo *
mv = &
s->blk_info[mv_pos -
s->blk_stride + mv_w].mv;
1110 cand[cand_size++] =
mv->b_mv;
1113 switch (cand_size) {
1119 b_mv.
x = (cand[0].
x + cand[1].
x) >> 1;
1120 b_mv.
y = (cand[0].
y + cand[1].
y) >> 1;
1123 mv_pred(&b_mv, cand[0], cand[1], cand[2]);
1133 dst->b_mv.x =
src->b_mv.x + b_mv.
x;
1134 dst->b_mv.y =
src->b_mv.y + b_mv.
y;
1139 int pu_size =
size >> 3;
1141 int imode, mv_x, mv_y, mv_pos, count, mv_size;
1142 unique_list_mvinfo skip_cand;
1151 for (
int y = 0; y < 2; y++)
1152 for (
int x = 0; x < 2; x++)
1153 s->blk_info[cu->
blk_pos + y*
s->blk_stride + x].imode =
1161 for (
int y = 0; y < size >> 2; y++)
1162 for (
int x = 0; x < size >> 2; x++)
1163 s->blk_info[cu->
blk_pos + y*
s->blk_stride + x].imode = imode;
1166 mv_x = cu->
xpos >> 2;
1167 mv_y = cu->
ypos >> 2;
1170 for (
int part_no = 0; part_no < count; part_no++) {
1174 for (
int y = 0; y <
dim.h; y++)
1175 for (
int x = 0; x <
dim.w; x++)
1176 s->blk_info[mv_pos + y*
s->blk_stride + x].mv =
mv;
1181 unique_list_mvinfo_init(&skip_cand);
1184 mv_size =
size >> 2;
1185 for (
int y = 0; y < mv_size; y++)
1186 for (
int x = 0; x < mv_size; x++)
1187 s->blk_info[cu->
blk_pos + y*
s->blk_stride + x].mv =
mv;
1190 for (
int y = 0; y < pu_size; y++)
1191 for (
int x = 0; x < pu_size; x++)
1192 s->pu_info[cu->
pu_pos + y*
s->pu_stride + x] = pui;
1229 #define FILTER1(src, src_stride, src_y_ofs, step) \
1230 ( (src)[(y + src_y_ofs)*(src_stride) + x - 2*step] \
1231 - 5 * (src)[(y + src_y_ofs)*(src_stride) + x - 1*step] \
1232 +52 * (src)[(y + src_y_ofs)*(src_stride) + x ] \
1233 +20 * (src)[(y + src_y_ofs)*(src_stride) + x + 1*step] \
1234 - 5 * (src)[(y + src_y_ofs)*(src_stride) + x + 2*step] \
1235 + (src)[(y + src_y_ofs)*(src_stride) + x + 3*step] + 32) >> 6
1237 #define FILTER2(src, src_stride, src_y_ofs, step) \
1238 ( (src)[(y + src_y_ofs)*(src_stride) + x - 2*step] \
1239 - 5 * (src)[(y + src_y_ofs)*(src_stride) + x - 1*step] \
1240 +20 * (src)[(y + src_y_ofs)*(src_stride) + x ] \
1241 +20 * (src)[(y + src_y_ofs)*(src_stride) + x + 1*step] \
1242 - 5 * (src)[(y + src_y_ofs)*(src_stride) + x + 2*step] \
1243 + (src)[(y + src_y_ofs)*(src_stride) + x + 3*step] + 16) >> 5
1245 #define FILTER3(src, src_stride, src_y_ofs, step) \
1246 ( (src)[(y + src_y_ofs)*(src_stride) + x - 2*step] \
1247 - 5 * (src)[(y + src_y_ofs)*(src_stride) + x - 1*step] \
1248 +20 * (src)[(y + src_y_ofs)*(src_stride) + x ] \
1249 +52 * (src)[(y + src_y_ofs)*(src_stride) + x + 1*step] \
1250 - 5 * (src)[(y + src_y_ofs)*(src_stride) + x + 2*step] \
1251 + (src)[(y + src_y_ofs)*(src_stride) + x + 3*step] + 32) >> 6
1253 #define FILTER_CASE(idx, dst, dst_stride, filter, w, h) \
1255 for (int y = 0; y < h; y++) \
1256 for (int x = 0; x < w; x++) \
1257 (dst)[y*dst_stride + x] = av_clip_uint8(filter); \
1260 #define FILTER_BLOCK(dst, dst_stride, src, src_stride, src_y_ofs, w, h, cond, step) \
1262 FILTER_CASE(1, dst, dst_stride, FILTER1(src, src_stride, src_y_ofs, step), w, h) \
1263 FILTER_CASE(2, dst, dst_stride, FILTER2(src, src_stride, src_y_ofs, step), w, h) \
1264 FILTER_CASE(3, dst, dst_stride, FILTER3(src, src_stride, src_y_ofs, step), w, h) \
1267 static void luma_mc(uint8_t *
dst,
int dst_stride,
const uint8_t *
src,
int src_stride,
int w,
int h,
int cx,
int cy)
1270 for (
int y = 0; y <
h; y++)
1271 memcpy(
dst + y*dst_stride,
src + y*src_stride,
w);
1276 }
else if (cx != 3 || cy != 3) {
1277 uint8_t
tmp[70 * 64];
1281 for (
int j = 0; j <
h; j++)
1282 for (
int i = 0;
i <
w;
i++)
1283 dst[j*dst_stride +
i] = (
1284 src[j*src_stride +
i] +
1285 src[j*src_stride +
i + 1] +
1286 src[(j + 1)*src_stride +
i] +
1287 src[(j + 1)*src_stride +
i + 1] + 2) >> 2;
1291 static void chroma_mc(uint8_t *
dst,
int dst_stride,
const uint8_t *
src,
int src_stride,
int w,
int h,
int x,
int y)
1294 for (
int j = 0; j <
h; j++)
1295 memcpy(
dst + j*dst_stride,
src + j*src_stride,
w);
1296 }
else if (x > 0 && y > 0) {
1299 if (x == 3 && y == 3)
1302 a = (4 - x) * (4 - y);
1306 for (
int j = 0; j <
h; j++)
1307 for (
int i = 0;
i <
w;
i++)
1308 dst[j*dst_stride +
i] =
1309 (
a *
src[j*src_stride +
i] +
1310 b *
src[j*src_stride +
i + 1] +
1311 c *
src[(j + 1)*src_stride +
i] +
1312 d *
src[(j + 1)*src_stride +
i + 1] + 8) >> 4;
1314 int a = (4 - x) * (4 - y);
1315 int e = x * (4 - y) + (4 - x) * y;
1316 int step = y > 0 ? src_stride : 1;
1317 for (
int j = 0; j <
h; j++)
1318 for (
int i = 0;
i <
w;
i++)
1319 dst[j*dst_stride +
i] =
1320 (
a *
src[j*src_stride +
i] +
1321 e *
src[j*src_stride +
i +
step] + 8) >> 4;
1325 static int check_pos(
int x,
int y,
int cw,
int ch,
int w,
int h,
int dx,
int dy,
int e0,
int e1,
int e2,
int e3)
1329 return x2 - e0 >= 0 && x2 + cw + e1 <=
w && y2 - e2 >= 0 && y2 + ch + e3 <=
h;
1335 int off = !
avg ? y * frame_linesize[0] + x : 0;
1337 int fh =
s->aheight;
1343 if (
check_pos(x, y,
w,
h, fw, fh, dx, dy,
rv60_edge1[cx],
rv60_edge2[cx],
rv60_edge1[cy],
rv60_edge2[cy])) {
1347 ref->data[0] + (y + dy) *
ref->linesize[0] + x + dx,
1352 int xoff = x + dx - 2;
1353 int yoff = y + dy - 2;
1354 s->vdsp.emulated_edge_mc(buf,
1355 ref->data[0] + yoff *
ref->linesize[0] + xoff,
1356 70,
ref->linesize[0],
1362 buf + 70 * 2 + 2, 70,
w,
h, cx, cy);
1366 int fw =
s->awidth >> 1;
1367 int fh =
s->aheight >> 1;
1377 for (
int plane = 1; plane < 3; plane++) {
1378 int off = !
avg ? (y >> 1) * frame_linesize[plane] + (x >> 1) : 0;
1379 if (
check_pos(x >> 1, y >> 1, cw, ch, fw, fh, dx, dy, 0, 1, 0, 1)) {
1382 frame_linesize[plane],
1383 ref->data[plane] + ((y >> 1) + dy) *
ref->linesize[plane] + (x >> 1) + dx,
1384 ref->linesize[plane],
1388 s->vdsp.emulated_edge_mc(buf,
1389 ref->data[plane] + ((y >> 1) + dy) *
ref->linesize[plane] + (x >> 1) + dx,
1390 40,
ref->linesize[plane],
1392 (x >> 1) + dx, (y >> 1) + dy,
1400 static void avg_plane(uint8_t *
dst,
int dst_stride,
const uint8_t *
src,
int src_stride,
int w,
int h)
1402 for (
int j = 0; j <
h; j++)
1403 for (
int i = 0;
i <
w;
i++)
1404 dst[j*dst_stride +
i] = (
dst[j*dst_stride +
i] +
src[j*src_stride +
i]) >> 1;
1407 static void avg(
AVFrame *
frame, uint8_t * prev_frame_data[3],
int prev_frame_linesize[3],
int x,
int y,
int w,
int h)
1409 for (
int plane = 0; plane < 3; plane++) {
1410 int shift = !plane ? 0 : 1;
1412 prev_frame_data[plane], prev_frame_linesize[plane],
1427 return (v * q + 8) >> 4;
1435 return inval &&
get_bits1(gb) ? -inval : inval;
1439 int esc_bits = esc_sym - 23;
1440 val += (1 << esc_bits) +
get_bits(gb, esc_bits) + 22;
1487 int sym0 =
get_vlc2(gb, vlcs->
l0[!is_luma], 9, 2);
1488 int grp0 = sym0 >> 3;
1494 int grp =
get_vlc2(gb, vlcs->
l12[!is_luma], 9, 2);
1498 int grp =
get_vlc2(gb, vlcs->
l12[!is_luma], 9, 2);
1502 int grp =
get_vlc2(gb, vlcs->
l3[!is_luma], 9, 2);
1509 int sym0 =
get_vlc2(gb, vlcs->
l0[!is_luma], 9, 2);
1510 int grp0 = (sym0 >> 3);
1516 int grp =
get_vlc2(gb, vlcs->
l12[!is_luma], 9, 2);
1520 int grp =
get_vlc2(gb, vlcs->
l12[!is_luma], 9, 2);
1524 int grp =
get_vlc2(gb, vlcs->
l3[!is_luma], 9, 2);
1537 memset(y_coeffs, 0,
sizeof(y_coeffs[0])*256);
1538 for (
int i = 0;
i < 16;
i++)
1542 memset(u_coeffs, 0,
sizeof(u_coeffs[0])*64);
1543 for (
int i = 0;
i < 4;
i++)
1544 if ((cbp >> (16 +
i)) & 1)
1547 memset(v_coeffs, 0,
sizeof(v_coeffs[0])*64);
1548 for (
int i = 0;
i < 4;
i++)
1549 if ((cbp >> (20 +
i)) & 1)
1559 static void decode_cu_8x8(
GetBitContext * gb,
int is_intra,
int qp,
int sel_qp, int16_t * y_coeffs, int16_t * u_coeffs, int16_t * v_coeffs,
int ccbp,
int mode4x4)
1567 memset(y_coeffs, 0,
sizeof(y_coeffs[0])*64);
1568 for (
int i = 0;
i < 4;
i++) {
1569 if ((ccbp >>
i) & 1) {
1575 offset = (
i & 1) * 4 + (
i & 2) * 2 * 8;
1582 if ((ccbp >> 4) & 1) {
1583 memset(u_coeffs, 0,
sizeof(u_coeffs[0])*16);
1587 if ((ccbp >> 5) & 1) {
1588 memset(v_coeffs, 0,
sizeof(u_coeffs[0])*16);
1601 memset(y_coeffs, 0,
sizeof(y_coeffs[0])*256);
1602 for (
int i = 0;
i < 16;
i++)
1603 if ((ccbp >>
i) & 1) {
1604 int off = (
i & 3) * 4 + (
i >> 2) * 4 * 16;
1608 memset(u_coeffs, 0,
sizeof(u_coeffs[0])*64);
1609 for (
int i = 0;
i < 4;
i++)
1610 if ((ccbp >> (16 +
i)) & 1) {
1611 int off = (
i & 1) * 4 + (
i & 2) * 2 * 8;
1618 memset(v_coeffs, 0,
sizeof(v_coeffs[0])*64);
1619 for (
int i = 0;
i < 4;
i++)
1620 if ((ccbp >> (20 +
i)) & 1) {
1621 int off = (
i & 1) * 4 + (
i & 2) * 2 * 8;
1631 int sym0 =
get_vlc2(gb, vlc[0], 9, 2);
1632 int sym1 =
get_vlc2(gb, vlc[1], 9, 2);
1633 int sym2 =
get_vlc2(gb, vlc[2], 9, 2);
1634 int sym3 =
get_vlc2(gb, vlc[3], 9, 2);
1636 + ((sym0 & 0x03) << 0)
1637 + ((sym0 & 0x0C) << 2)
1638 + ((sym0 & 0x10) << 12)
1639 + ((sym0 & 0x20) << 15)
1640 + ((sym1 & 0x03) << 2)
1641 + ((sym1 & 0x0C) << 4)
1642 + ((sym1 & 0x10) << 13)
1643 + ((sym1 & 0x20) << 16)
1644 + ((sym2 & 0x03) << 8)
1645 + ((sym2 & 0x0C) << 10)
1646 + ((sym2 & 0x10) << 14)
1647 + ((sym2 & 0x20) << 17)
1648 + ((sym3 & 0x03) << 10)
1649 + ((sym3 & 0x0C) << 12)
1650 + ((sym3 & 0x10) << 15)
1651 + ((sym3 & 0x20) << 18);
1662 int size = 1 << log_size;
1663 int split,
ret, ttype, count, is_intra, cu_pos, subset, cbp8, imode, split_i4x4, num_clusters, cl_cbp, super_cbp, mv_x, mv_y, mv_pos;
1664 int16_t y_coeffs[16*16], u_coeffs[8*8], v_coeffs[8*8];
1667 if (xpos >=
s->awidth || ypos >=
s->aheight)
1685 cu.
pu_pos = (xpos >> 3) + (ypos >> 3) *
s->pu_stride;
1686 cu.
blk_pos = (xpos >> 2) + (ypos >> 2) *
s->blk_stride;
1693 for (
int i = 0;
i < 4;
i++)
1695 else if (
size <= 32)
1703 for (
int i = 0;
i < count;
i++)
1718 imode =
s->blk_info[cu.
blk_pos].imode;
1720 int off = ypos *
frame->linesize[0] + xpos;
1725 for (
int plane = 1; plane < 3; plane++) {
1726 int off = (ypos >> 1) *
frame->linesize[plane] + (xpos >> 1);
1735 mv_pos = mv_y *
s->blk_stride + mv_x;
1737 for (
int part_no = 0; part_no < count; part_no++) {
1742 mv =
s->blk_info[mv_pos].mv;
1749 if (!(
mv.mvref & 2)) {
1750 if (!
s->last_frame[
LAST_PIC]->data[0]) {
1756 if (!
s->last_frame[
NEXT_PIC]->data[0]) {
1787 else if (
size >= 32)
1789 else if (
size == 16)
1797 cu_pos = ((xpos & 63) >> 3) + ((ypos & 63) >> 3) * 8;
1801 subset = is_intra ? 0 : 2;
1806 for (
int y = 0; y < 4; y++)
1807 for (
int x = 0; x < 4; x++) {
1809 if ((cbp16 >>
i) & 1) {
1810 int off = (ypos + y * 4)*
frame->linesize[0] + xpos + x * 4;
1812 thread->
coded_blk[cu_pos + (y/2)*8 + (x/2)] = 1;
1815 for (
int y = 0; y < 2; y++)
1816 for (
int x = 0; x < 2; x++) {
1818 int xoff = (xpos >> 1) + x * 4;
1819 int yoff = (ypos >> 1) + y * 4;
1820 if ((cbp16 >> (16 +
i)) & 1) {
1821 int off = yoff *
frame->linesize[1] + xoff;
1823 thread->
coded_blk[cu_pos + y*8 + x] = 1;
1825 if ((cbp16 >> (20 +
i)) & 1) {
1826 int off = yoff *
frame->linesize[2] + xoff;
1828 thread->
coded_blk[cu_pos + y*8 + x] = 1;
1836 decode_cu_8x8(gb, is_intra, qp, sel_qp, y_coeffs, u_coeffs, v_coeffs, cbp8, 1);
1838 for (
int i = 0;
i < 4;
i++) {
1839 int xoff = (
i & 1) << 2;
1840 int yoff = (
i & 2) << 1;
1842 int off = (ypos + yoff) *
frame->linesize[0] + xpos + xoff;
1843 int imode =
s->blk_info[cu.
blk_pos + (
i >> 1) *
s->blk_stride + (
i & 1)].imode;
1848 if ((cbp8 >>
i) & 1) {
1849 int off = (ypos + yoff) *
frame->linesize[0] + xpos + xoff;
1853 if ((cbp8 >> 4) & 1) {
1854 int off = (ypos >> 1) *
frame->linesize[1] + (xpos >> 1);
1857 if ((cbp8 >> 5) & 1) {
1858 int off = (ypos >> 1) *
frame->linesize[2] + (xpos >> 1);
1864 subset = is_intra ? 1 : 3;
1868 decode_cu_8x8(gb, is_intra, qp, sel_qp, y_coeffs, u_coeffs, v_coeffs, cbp8, 0);
1870 int off = ypos *
frame->linesize[0] + xpos;
1873 if ((cbp8 >> 4) & 1) {
1874 int off = (ypos >> 1) *
frame->linesize[1] + (xpos >> 1);
1877 if ((cbp8 >> 5) & 1) {
1878 int off = (ypos >> 1) *
frame->linesize[2] + (xpos >> 1);
1884 subset = is_intra ? 1 : 3;
1885 num_clusters =
size >> 4;
1886 cl_cbp =
get_bits(gb, num_clusters * num_clusters);
1887 for (
int y = 0; y < num_clusters; y++) {
1888 for (
int x = 0; x < num_clusters; x++) {
1889 if (!((cl_cbp >> (y*num_clusters + x)) & 1))
1891 thread->
coded_blk[cu_pos + y*2*8 + x*2 + 0] = 1;
1892 thread->
coded_blk[cu_pos + y*2*8 + x*2 + 1] = 1;
1893 thread->
coded_blk[cu_pos + y*2*8 + x*2 + 8] = 1;
1894 thread->
coded_blk[cu_pos + y*2*8 + x*2 + 9] = 1;
1897 decode_cu_16x16(gb, is_intra, qp, sel_qp, y_coeffs, u_coeffs, v_coeffs, super_cbp);
1898 if (super_cbp & 0xFFFF) {
1899 int off = (ypos + y * 16) *
frame->linesize[0] + xpos + x * 16;
1902 if ((super_cbp >> 16) & 0xF) {
1903 int off = ((ypos >> 1) + y * 8) *
frame->linesize[1] + (xpos >> 1) + x * 8;
1906 if ((super_cbp >> 20) & 0xF) {
1907 int off = ((ypos >> 1) + y * 8) *
frame->linesize[2] + (xpos >> 1) + x * 8;
1921 return (ypos >> 2) *
s->dblk_stride + (xpos >> 2);
1927 int dsize =
size >> 2;
1928 int dval = (q << 2) + strength;
1930 for (
int x = 0; x < dsize; x++) {
1931 s->top_str[
pos + x] = dval;
1932 s->top_str[
pos + (dsize - 1)*
s->dblk_stride + x] = dval;
1935 for (
int y = 0; y < dsize; y++) {
1936 s->left_str[
pos + y*
s->dblk_stride] = dval;
1937 s->left_str[
pos + y*
s->dblk_stride + dsize - 1] = dval;
1943 return s->top_str[
pos] & 3;
1948 return s->left_str[
pos] & 3;
1953 s->top_str[
pos] |= strength;
1958 s->left_str[
pos] |= strength;
1963 int blk_pos = (ypos >> 2) *
s->blk_stride + (xpos >> 2);
1966 for (
int i = 0;
i <
size;
i++)
1970 for (
int i = 0;
i <
size;
i++)
1975 #define STRENGTH(el, lim) (FFABS(el) < (lim) ? 3 : 1)
1976 #define CLIP_SYMM(a, b) av_clip(a, -(b), b)
1980 int16_t diff_q1q0[4];
1981 int16_t diff_p1p0[4];
1982 int str_p, str_q, msum, maxprod, weak;
1984 for (
int i = 0;
i < 4;
i++) {
1989 str_p =
STRENGTH(diff_q1q0[0] + diff_q1q0[1] + diff_q1q0[2] + diff_q1q0[3], lim2);
1990 str_q =
STRENGTH(diff_p1p0[0] + diff_p1p0[1] + diff_p1p0[2] + diff_p1p0[3], lim2);
1992 if (str_p + str_q <= 2)
1995 msum = (mode1 + mode2 + str_q + str_p) >> 1;
1996 if (str_q == 1 || str_p == 1) {
2004 for (
int y = 0; y < 4; y++) {
2007 if (diff_p0q0 &&
result <= maxprod) {
2014 int diff_strg = (
dst[-2*
step] -
dst[
step] + 4 * diff_p0q0 + 4) >> 3;
2019 if (str_p != 1 &&
FFABS(diff_q1q2) <= (lim2 >> 2)) {
2020 int diff = (diff_q1q0[y] + diff_q1q2 -
delta) >> 1;
2024 if (str_q != 1 &&
FFABS(diff_p1p2) <= (lim2 >> 2)) {
2025 int diff = (diff_p1p0[y] + diff_p1p2 +
delta) >> 1;
2038 int str_q =
STRENGTH(diff_q, lim2);
2039 int str_p =
STRENGTH(diff_p, lim2);
2040 int msum, maxprod, weak;
2042 if (str_p + str_q <= 2)
2045 msum = (mode1 + mode2 + str_q + str_p) >> 1;
2046 if (str_q == 1 || str_p == 1) {
2054 for (
int y = 0; y < 2; y++) {
2057 if (diff_pq &&
result <= maxprod) {
2062 int diff_strg = (
dst[-2*
step] -
dst[
step] + 4 * diff_pq + 4) >> 3;
2074 int qp_l = dblk_l >> 2;
2075 int str_l = dblk_l & 3;
2076 int qp_r = dblk_r >> 2;
2077 int str_r = dblk_r & 3;
2080 int mode_l = str_l ? dl_l[str_l - 1] : 0;
2081 int mode_r = str_r ? dl_r[str_r - 1] : 0;
2083 int lim2 = dl_r[3] * 4;
2086 if ((str_l | str_r) >= 2 && deblock_chroma)
2087 for (
int plane = 1; plane < 3; plane++)
2093 int qp_t = dblk_t >> 2;
2094 int str_t = dblk_t & 3;
2095 int qp_d = dblk_d >> 2;
2096 int str_d = dblk_d & 3;
2099 int mode_t = str_t ? dl_t[str_t - 1] : 0;
2100 int mode_d = str_d ? dl_d[str_d - 1] : 0;
2102 int lim2 = dl_d[3] * 4;
2105 if ((str_t | str_d) >= 2 && deblock_chroma)
2106 for (
int plane = 1; plane < 3; plane++)
2114 int str_l =
s->left_str[dblkpos -
s->dblk_stride - 1];
2115 int str_r =
s->left_str[dblkpos -
s->dblk_stride];
2116 if ((str_l | str_r) & 3)
2120 int str_l =
s->left_str[dblkpos - 1];
2121 int str_r =
s->left_str[dblkpos];
2122 if ((str_l | str_r) & 3)
2125 if (ypos + 8 >=
s->aheight) {
2126 int str_l =
s->left_str[dblkpos +
s->dblk_stride - 1];
2127 int str_r =
s->left_str[dblkpos +
s->dblk_stride];
2128 if ((str_l | str_r) & 3)
2134 int str_t =
s->top_str[dblkpos -
s->dblk_stride - 1];
2135 int str_d =
s->top_str[dblkpos - 1];
2136 if ((str_t | str_d) & 3)
2140 int str_t =
s->top_str[dblkpos -
s->dblk_stride];
2141 int str_d =
s->top_str[dblkpos];
2142 if ((str_t | str_d) & 3)
2145 if (xpos + 8 >=
s->awidth) {
2146 int str_t =
s->top_str[dblkpos -
s->dblk_stride + 1];
2147 int str_d =
s->top_str[dblkpos + 1];
2148 if ((str_t | str_d) & 3)
2156 for (
int x = 0; x < size >> 3; x++)
2159 for (
int y = 1; y < size >> 3; y++)
2165 int pu_pos, tsize, ntiles;
2168 if (xpos >=
s->awidth || ypos >=
s->aheight)
2172 int hsize = 1 << (log_size - 1);
2181 pu_pos = (ypos >> 3) *
s->pu_stride + (xpos >> 3);
2182 cu_type =
s->pu_info[pu_pos].cu_type;
2184 case 3: tsize = 3;
break;
2185 case 4: tsize = cu_type &&
s->pu_info[pu_pos].pu_type ? 3 : 4;
break;
2187 case 6: tsize = 4;
break;
2189 ntiles = 1 << (log_size - tsize);
2191 for (
int ty = 0; ty < ntiles; ty++)
2192 for (
int tx = 0; tx < ntiles; tx++) {
2193 int x = xpos + (tx << tsize);
2194 int y = ypos + (ty << tsize);
2195 int cu_pos = ((y & 63) >> 3) * 8 + ((x & 63) >> 3);
2214 switch (qp_off_type) {
2219 return val != 2 ?
val : -1;
2227 return -((
val & 1) + 1);
2235 case 1:
return qp <= 25 ? qp + 5 : qp;
2252 int qp, sel_qp,
ret;
2264 for (
int cu_x = 0; cu_x <
s->cu_width; cu_x++) {
2269 if (qp < 0 || qp >= 64) {
2303 if (avpkt->
size == 0) {
2311 if (avpkt->
size < 9)
2314 header_size = avpkt->
data[0] * 8 + 9;
2315 if (avpkt->
size < header_size)
2338 s->last_frame[
CUR_PIC]->pict_type =
s->pict_type;
2345 if (!
s->last_frame[
CUR_PIC]->data[0])
2354 for (
int i = 0;
i <
s->cu_height;
i++) {
2355 if (ofs >= avpkt->
size - header_size)
2357 s->slice[
i].data = avpkt->
data + header_size + ofs;
2358 s->slice[
i].data_size =
FFMIN(
s->slice[
i].size, avpkt->
size - header_size - ofs);
2359 if (
s->slice[
i].size > INT32_MAX - ofs)
2361 ofs +=
s->slice[
i].size;
2373 else if (
s->last_frame[
LAST_PIC]->data[0])
2387 s->ref_pts[0] =
s->ref_pts[1];
2388 s->ref_pts[1] = avpkt->
pts;
2390 s->ref_ts[0] =
s->ref_ts[1];
2391 s->ref_ts[1] =
s->ts;
2393 if (
s->ref_pts[1] >
s->ref_pts[0] &&
s->ref_ts[1] >
s->ref_ts[0])
2394 s->ts_scale = (
s->ref_pts[1] -
s->ref_pts[0]) / (
s->ref_ts[1] -
s->ref_ts[0]);
2396 frame->pts =
s->ref_pts[0] + (
s->ts -
s->ref_ts[0]) *
s->ts_scale;
2406 for (
int i = 0;
i < 3;
i++)
2414 for (
int i = 0;
i < 3;
i++)
2423 for (
int i = 0;
i <
s->nb_progress;
i++)
static void fill_mv_skip_cand(RV60Context *s, const CUContext *cu, unique_list_mvinfo *skip_cand, int size)
static void filter_luma_edge(uint8_t *dst, int step, int stride, int mode1, int mode2, int lim1, int lim2)
static const uint8_t skip_mv_ref[4]
#define AV_LOG_WARNING
Something somehow does not look correct.
static void decode_2x2_dc(GetBitContext *gb, const CoeffVLCs *vlcs, int16_t *coeffs, int stride, int block2, int dsc, int q_dc, int q_ac)
void ff_thread_progress_report(ThreadProgress *pro, int n)
This function is a no-op in no-op mode; otherwise it notifies other threads that a certain level of p...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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
static int pu_is_intra(const PUInfo *pu)
ThreadProgress is an API to easily notify other threads about progress of any kind as long as it can ...
static int deblock_get_top_strength(const RV60Context *s, int pos)
static void deblock(const RV60Context *s, AVFrame *frame, int xpos, int ypos, int size, int dpos)
static int pred_angle(const IntraPredContext *p, uint8_t *dst, int stride, int size, int imode, int filter)
void ff_rv60_idct8x8_add(const int16_t *block, uint8_t *dst, int dst_stride)
static void read_mv(GetBitContext *gb, MV *mv)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static void decode_cu_16x16(GetBitContext *gb, int is_intra, int qp, int sel_qp, int16_t *y_coeffs, int16_t *u_coeffs, int16_t *v_coeffs, int ccbp)
static const int8_t mv[256][2]
#define FILTER_BLOCK(dst, dst_stride, src, src_stride, src_y_ofs, w, h, cond, step)
static int get_bits_count(const GetBitContext *s)
static void deblock_edge_ver(AVFrame *frame, int xpos, int ypos, int dblk_l, int dblk_r, int deblock_chroma)
static const VLCElem * cbp8_vlc[7][4]
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.
static av_cold void rv60_init_static_data(void)
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
static int mvinfo_matches_forward(const MVInfo *a, const MVInfo *b)
static void mc(RV60Context *s, uint8_t *frame_data[3], int frame_linesize[3], const AVFrame *ref, int x, int y, int w, int h, MV mv, int avg)
static void filter_weak(uint8_t *dst, const uint8_t *src, int size)
static av_cold void rv60_flush(AVCodecContext *avctx)
const FFCodec ff_rv60_decoder
void(* filter)(uint8_t *src, int stride, int qscale)
static const uint8_t rv60_cbp8_lens[7][4][64]
static int update_dimensions_clear_info(RV60Context *s, int width, int height)
static void decode_4x4_block(GetBitContext *gb, const CoeffVLCs *vlcs, int is_luma, int16_t *coeffs, int stride, int q_ac)
static void decode_cu_4x4in16x16(GetBitContext *gb, int is_intra, int qp, int sel_qp, int16_t *y_coeffs, int16_t *u_coeffs, int16_t *v_coeffs, int cbp)
static int ipm_compar(const void *a, const void *b)
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.
static int deblock_get_pos(RV60Context *s, int xpos, int ypos)
static int deblock_get_left_strength(const RV60Context *s, int pos)
static void populate_ipred(const RV60Context *s, CUContext *cu, const uint8_t *src, int stride, int xoff, int yoff, int size, int is_luma)
uint8_t avg_buffer[64 *64+32 *32 *2]
static void skip_bits(GetBitContext *s, int n)
static av_cold void close(AVCodecParserContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int has_left_block(const RV60Context *s, int xpos, int ypos, int dx, int dy, int size)
AVCodec p
The public AVCodec.
enum AVDiscard skip_frame
Skip decoding for selected frames.
static void deblock_set_top_strength(RV60Context *s, int pos, int strength)
static int get_skip_mv_index(enum MVRefEnum mvref)
static void deblock_edge_hor(AVFrame *frame, int xpos, int ypos, int dblk_t, int dblk_d, int deblock_chroma)
const h264_weight_func weight
static double val(void *priv, double ch)
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
static void get_mv_dimensions(Dimensions *dim, enum PUType pu_type, int part_no, int size)
static void pred_plane(const IntraPredContext *p, uint8_t *dst, int stride, int size)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static void derive_deblock_strength(RV60Context *s, int xpos, int ypos, int size)
static int ff_thread_once(char *control, void(*routine)(void))
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int quant(int v, int q)
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
For static VLCs, the number of bits can often be hardcoded at each get_vlc2() callsite.
static int decode_slice(AVCodecContext *avctx, void *tdata, int cu_y, int threadnr)
#define FF_CODEC_DECODE_CB(func)
static const uint8_t rv60_deblock_limits[32][4]
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
static const uint8_t rv60_edge2[4]
uint8_t cu_split[1+4+16+64]
#define MK_UNIQUELIST(name, type, max_size)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const uint8_t rv60_cbp16_lens[7][3][4][64]
static void predict_mv(const RV60Context *s, MVInfo *dst, int mv_x, int mv_y, int mv_w, const MVInfo *src)
static int mv_is_forward(enum MVRefEnum mvref)
static const uint8_t rv60_ipred_angle[9]
static int mv_is_ref0(enum MVRefEnum mvref)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static void mv_pred(MV *ret, MV a, MV b, MV c)
static void deblock8x8(const RV60Context *s, AVFrame *frame, int xpos, int ypos, int dblkpos)
#define CODEC_LONG_NAME(str)
static int read_frame_header(RV60Context *s, GetBitContext *gb, int *width, int *height)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
@ AVDISCARD_ALL
discard all
static void decode_4x4_block_dc(GetBitContext *gb, const CoeffVLCs *vlcs, int is_luma, int16_t *coeffs, int stride, int q_dc, int q_ac)
static void ipred_init(IntraPredContext *i)
void ff_thread_progress_await(const ThreadProgress *pro_c, int n)
This function is a no-op in no-op mode; otherwise it waits until other threads have reached a certain...
static int mvinfo_is_deblock_cand(const MVInfo *a, const MVInfo *b)
and forward the result(frame or status change) to the corresponding input. If nothing is possible
static int decode_cu_r(RV60Context *s, AVFrame *frame, ThreadContext *thread, GetBitContext *gb, int xpos, int ypos, int log_size, int qp, int sel_qp)
static const uint8_t rv60_chroma_quant_ac[32]
static int has_ver_split(enum PUType pu_type)
static VLCElem table_data[129148]
static unsigned int get_bits1(GetBitContext *s)
@ AV_PICTURE_TYPE_I
Intra.
static int read_slice_sizes(RV60Context *s, GetBitContext *gb)
static int has_hor_split(enum PUType pu_type)
static void decode_2x2(GetBitContext *gb, const CoeffVLCs *vlcs, int16_t *coeffs, int stride, int block2, int dsc, int q_ac)
static int has_top_block(const RV60Context *s, int xpos, int ypos, int dx, int dy, int size)
static const uint8_t rv60_dsc_to_lx[][4]
static const VLCElem * cbp16_vlc[7][4][4]
static const VLCElem * gen_vlc(const uint8_t *bits, int size, VLCInitState *state)
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static const CoeffLens rv60_intra_lens[5]
static void luma_mc(uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h, int cx, int cy)
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 void pred_dc(const IntraPredContext *p, uint8_t *dst, int stride, int size, int filter)
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
static void read_mv_info(RV60Context *s, GetBitContext *gb, MVInfo *mvinfo, int size, enum PUType pu_type)
@ AVDISCARD_NONKEY
discard all frames except keyframes
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
static const uint8_t rv60_avail_mask[64]
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]
static const uint16_t rv60_ipred_inv_angle[9]
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static void filter_bilin32(uint8_t *dst, int v0, int v1, int size)
static void build_coeff_vlc(const CoeffLens *lens, CoeffVLCs *vlc, int count, VLCInitState *state)
static int shift(int a, int b)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int rv60_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static int pu_type_num_parts(enum PUType pu_type)
static void add_if_valid(unique_list_mvinfo *skip_cand, const MVInfo *mvi)
static int get_interleaved_se_golomb(GetBitContext *gb)
static const CoeffLens rv60_inter_lens[7]
static void chroma_mc(uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h, int x, int y)
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
static void filter_chroma_edge(uint8_t *dst, int step, int stride, int mode1, int mode2, int lim1, int lim2)
static av_cold int rv60_decode_end(AVCodecContext *avctx)
@ AV_PICTURE_TYPE_NONE
Undefined.
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
static char * split(char *message, char delim)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
static CoeffVLCs intra_coeff_vlc[5]
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
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 pred_hor_angle(uint8_t *dst, int stride, int size, int weight, const uint8_t *src)
struct ThreadProgress * progress
static void skip_bits1(GetBitContext *s)
static void deblock_cu_r(RV60Context *s, AVFrame *frame, ThreadContext *thread, int xpos, int ypos, int log_size, int qp)
static int calc_sel_qp(int osvquant, int qp)
static int read_intra_mode(GetBitContext *gb, int *param)
#define AV_LOG_INFO
Standard information.
static int decode_super_cbp(GetBitContext *gb, const VLCElem *vlc[4])
#define STRENGTH(el, lim)
static const uint8_t rv60_candidate_intra_angles[6]
static int decode_cbp8(GetBitContext *gb, int subset, int qp)
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static int has_left_down_block(const RV60Context *s, int xpos, int ypos, int dx, int dy, int size)
av_cold int ff_thread_progress_init(ThreadProgress *pro, int init_mode)
Initialize a ThreadProgress.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
static int has_top_right_block(const RV60Context *s, int xpos, int ypos, int dx, int dy, int size)
static void avg(AVFrame *frame, uint8_t *prev_frame_data[3], int prev_frame_linesize[3], int x, int y, int w, int h)
const char * name
Name of the codec implementation.
void ff_rv60_idct4x4_add(const int16_t *block, uint8_t *dst, int dst_stride)
static void pred_ver_angle(uint8_t *dst, int stride, int size, int weight, const uint8_t *src)
static av_cold int rv60_decode_init(AVCodecContext *avctx)
static int decode_coeff(GetBitContext *gb, const CoeffVLCs *vlcs, int inval, int val)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int mv_is_backward(enum MVRefEnum mvref)
static int reconstruct_intra(const RV60Context *s, const CUContext *cu, int size, int sub)
static int mvinfo_matches_backward(const MVInfo *a, const MVInfo *b)
#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 int progress_init(RV60Context *s, unsigned count)
static const uint8_t * align_get_bits(GetBitContext *s)
static CoeffVLCs inter_coeff_vlc[7]
av_cold void ff_thread_progress_destroy(ThreadProgress *pro)
Destroy a ThreadProgress.
static int decode_cbp16(GetBitContext *gb, int subset, int qp)
main external API structure.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
static void get_next_mv(const RV60Context *s, const Dimensions *dim, enum PUType pu_type, int part_no, int *mv_pos, int *mv_x, int *mv_y)
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 void ff_thread_progress_reset(ThreadProgress *pro)
Reset the ThreadProgress.progress counter; must only be called if the ThreadProgress is not in use in...
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
static void deblock_set_strength(RV60Context *s, int xpos, int ypos, int size, int q, int strength)
@ AV_PICTURE_TYPE_P
Predicted.
static const VLCElem * ff_vlc_init_tables(VLCInitState *state, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, int flags)
static void deblock_set_left_strength(RV60Context *s, int pos, int strength)
static const uint8_t rv60_chroma_quant_dc[32]
static int read_qp_offset(GetBitContext *gb, int qp_off_type)
static int read_code012(GetBitContext *gb)
static int check_pos(int x, int y, int cw, int ch, int w, int h, int dx, int dy, int e0, int e1, int e2, int e3)
static const uint8_t rv60_qp_to_idx[64]
#define VLC_INIT_STATE(_table)
static int get_c4x4_set(int qp, int is_intra)
This structure stores compressed data.
static void avg_plane(uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h)
void ff_rv60_idct16x16_add(const int16_t *block, uint8_t *dst, int dst_stride)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void decode_cu_8x8(GetBitContext *gb, int is_intra, int qp, int sel_qp, int16_t *y_coeffs, int16_t *u_coeffs, int16_t *v_coeffs, int ccbp, int mode4x4)
@ AVDISCARD_NONREF
discard all non reference
static const uint8_t rv60_edge1[4]
static void reconstruct(RV60Context *s, const CUContext *cu, int size)
static const int8_t frame_types[4]
static const uint16_t rv60_quants_b[32]