151#define FULLPEL_MODE 1
152#define HALFPEL_MODE 2
153#define THIRDPEL_MODE 3
154#define PREDICT_MODE 4
166 0 + 0 * 4, 1 + 0 * 4, 2 + 0 * 4, 2 + 1 * 4,
167 2 + 2 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4,
168 0 + 1 * 4, 0 + 2 * 4, 1 + 1 * 4, 1 + 2 * 4,
169 0 + 3 * 4, 1 + 3 * 4, 2 + 3 * 4, 3 + 3 * 4,
173 0 * 16 + 0 * 64, 1 * 16 + 0 * 64, 2 * 16 + 0 * 64, 0 * 16 + 2 * 64,
174 3 * 16 + 0 * 64, 0 * 16 + 1 * 64, 1 * 16 + 1 * 64, 2 * 16 + 1 * 64,
175 1 * 16 + 2 * 64, 2 * 16 + 2 * 64, 3 * 16 + 2 * 64, 0 * 16 + 3 * 64,
176 3 * 16 + 1 * 64, 1 * 16 + 3 * 64, 2 * 16 + 3 * 64, 3 * 16 + 3 * 64,
182 { 0, 2 }, { 1, 1 }, { 2, 0 },
183 { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
184 { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
185 { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
186 { 2, 4 }, { 3, 3 }, { 4, 2 },
192 { { 2, -1, -1, -1, -1 }, { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 },
193 { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 }, { 1, 2, -1, -1, -1 } },
194 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
195 { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
196 { { 2, 0, -1, -1, -1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
197 { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
198 { { 2, 0, -1, -1, -1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
199 { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
200 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
201 { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
202 { { 0, 2, -1, -1, -1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
203 { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
210 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
211 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
212 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
213 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
217 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
218 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
219 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
220 61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533
231 for (
i = 0;
i < 4;
i++) {
232 const int z0 = 13 * (input[4 *
i + 0] + input[4 *
i + 2]);
233 const int z1 = 13 * (input[4 *
i + 0] - input[4 *
i + 2]);
234 const int z2 = 7 * input[4 *
i + 1] - 17 * input[4 *
i + 3];
235 const int z3 = 17 * input[4 *
i + 1] + 7 * input[4 *
i + 3];
237 temp[4 *
i + 0] = z0 + z3;
238 temp[4 *
i + 1] = z1 + z2;
239 temp[4 *
i + 2] = z1 - z2;
240 temp[4 *
i + 3] = z0 - z3;
243 for (
i = 0;
i < 4;
i++) {
244 const int offset = x_offset[
i];
245 const int z0 = 13 * (
temp[4 * 0 +
i] +
temp[4 * 2 +
i]);
246 const int z1 = 13 * (
temp[4 * 0 +
i] -
temp[4 * 2 +
i]);
247 const int z2 = 7 *
temp[4 * 1 +
i] - 17 *
temp[4 * 3 +
i];
248 const int z3 = 17 *
temp[4 * 1 +
i] + 7 *
temp[4 * 3 +
i];
250 output[
stride * 0 +
offset] = (int)((z0 + z3) * qmul + 0x80000) >> 20;
251 output[
stride * 2 +
offset] = (int)((z1 + z2) * qmul + 0x80000) >> 20;
252 output[
stride * 8 +
offset] = (int)((z1 - z2) * qmul + 0x80000) >> 20;
253 output[
stride * 10 +
offset] = (int)((z0 - z3) * qmul + 0x80000) >> 20;
259 int stride,
int qp,
int dc)
265 dc = 13 * 13 * (dc == 1 ? 1538U*
block[0]
266 : qmul * (
block[0] >> 3) / 2);
270 for (
i = 0;
i < 4;
i++) {
271 const int z0 = 13 * (
block[0 + 4 *
i] +
block[2 + 4 *
i]);
272 const int z1 = 13 * (
block[0 + 4 *
i] -
block[2 + 4 *
i]);
273 const int z2 = 7 *
block[1 + 4 *
i] - 17 *
block[3 + 4 *
i];
274 const int z3 = 17 *
block[1 + 4 *
i] + 7 *
block[3 + 4 *
i];
276 block[0 + 4 *
i] = z0 + z3;
277 block[1 + 4 *
i] = z1 + z2;
278 block[2 + 4 *
i] = z1 - z2;
279 block[3 + 4 *
i] = z0 - z3;
282 for (
i = 0;
i < 4;
i++) {
283 const unsigned z0 = 13 * (
block[
i + 4 * 0] +
block[
i + 4 * 2]);
284 const unsigned z1 = 13 * (
block[
i + 4 * 0] -
block[
i + 4 * 2]);
285 const unsigned z2 = 7 *
block[
i + 4 * 1] - 17 *
block[
i + 4 * 3];
286 const unsigned z3 = 17 *
block[
i + 4 * 1] + 7 *
block[
i + 4 * 3];
287 const int rr = (dc + 0x80000u);
295 memset(
block, 0, 16 *
sizeof(int16_t));
301 static const uint8_t *
const scan_patterns[4] = {
307 const int intra = 3 *
type >> 2;
308 const uint8_t *
const scan = scan_patterns[
type];
315 sign = (vlc & 1) ? 0 : -1;
322 }
else if (vlc < 4) {
335 level = (vlc >> 3) + ((
run == 0) ? 8 : ((
run < 2) ? 2 : ((
run < 5) ? 0 : -1)));
338 level = (vlc >> 4) + ((
run == 0) ? 4 : ((
run < 3) ? 2 : ((
run < 10) ? 1 : 0)));
359 int i,
int list,
int part_width)
361 const int topright_ref =
s->ref_cache[list][
i - 8 + part_width];
364 *
C =
s->mv_cache[list][
i - 8 + part_width];
367 *
C =
s->mv_cache[list][
i - 8 - 1];
368 return s->ref_cache[list][
i - 8 - 1];
380 int part_width,
int list,
381 int ref,
int *
const mx,
int *
const my)
383 const int index8 =
scan8[n];
384 const int top_ref =
s->ref_cache[list][index8 - 8];
385 const int left_ref =
s->ref_cache[list][index8 - 1];
386 const int16_t *
const A =
s->mv_cache[list][index8 - 1];
387 const int16_t *
const B =
s->mv_cache[list][index8 - 8];
389 int diagonal_ref, match_count;
400 match_count = (diagonal_ref ==
ref) + (top_ref ==
ref) + (left_ref ==
ref);
401 if (match_count > 1) {
404 }
else if (match_count == 1) {
405 if (left_ref ==
ref) {
408 }
else if (top_ref ==
ref) {
430 int mx,
int my,
int dxy,
431 int thirdpel,
int dir,
int avg)
433 const SVQ3Frame *pic = (dir == 0) ?
s->last_pic :
s->next_pic;
436 int blocksize = 2 - (
width >> 3);
437 int linesize =
s->cur_pic->f->linesize[0];
438 int uvlinesize =
s->cur_pic->f->linesize[1];
451 dest =
s->cur_pic->f->data[0] + x + y * linesize;
455 s->vdsp.emulated_edge_mc(
s->edge_emu_buffer,
src,
458 mx,
my,
s->h_edge_pos,
s->v_edge_pos);
459 src =
s->edge_emu_buffer;
462 (
avg ?
s->tdsp.avg_tpel_pixels_tab
463 :
s->tdsp.put_tpel_pixels_tab)[dxy](dest,
src, linesize,
466 (
avg ?
s->hdsp.avg_pixels_tab
467 :
s->hdsp.put_pixels_tab)[blocksize][dxy](dest,
src, linesize,
471 mx =
mx + (
mx < (int) x) >> 1;
472 my =
my + (
my < (int) y) >> 1;
477 for (
i = 1;
i < 3;
i++) {
478 dest =
s->cur_pic->f->data[
i] + (x >> 1) + (y >> 1) * uvlinesize;
482 s->vdsp.emulated_edge_mc(
s->edge_emu_buffer,
src,
483 uvlinesize, uvlinesize,
485 mx,
my, (
s->h_edge_pos >> 1),
487 src =
s->edge_emu_buffer;
490 (
avg ?
s->tdsp.avg_tpel_pixels_tab
491 :
s->tdsp.put_tpel_pixels_tab)[dxy](dest,
src,
495 (
avg ?
s->hdsp.avg_pixels_tab
496 :
s->hdsp.put_pixels_tab)[blocksize][dxy](dest,
src,
506 int i, j, k,
mx,
my, dx, dy, x, y;
508 const int part_width = ((
size & 5) == 4) ? 4 : 16 >> (
size & 1);
509 const int part_height = 16 >> ((unsigned)(
size + 1) / 3);
511 const int h_edge_pos = 6 * (
s->h_edge_pos - part_width) - extra_width;
512 const int v_edge_pos = 6 * (
s->v_edge_pos - part_height) - extra_width;
514 for (
i = 0;
i < 16;
i += part_height)
515 for (j = 0; j < 16; j += part_width) {
516 const int b_xy = (4 *
s->mb_x + (j >> 2)) +
517 (4 *
s->mb_y + (
i >> 2)) *
s->b_stride;
519 x = 16 *
s->mb_x + j;
520 y = 16 *
s->mb_y +
i;
521 k = (j >> 2 & 1) + (
i >> 1 & 2) +
522 (j >> 1 & 4) + (
i & 8);
527 mx =
s->next_pic->motion_val[0][b_xy][0] * 2;
528 my =
s->next_pic->motion_val[0][b_xy][1] * 2;
531 mx =
mx *
s->frame_num_offset /
532 s->prev_frame_num_offset + 1 >> 1;
533 my =
my *
s->frame_num_offset /
534 s->prev_frame_num_offset + 1 >> 1;
536 mx =
mx * (
s->frame_num_offset -
s->prev_frame_num_offset) /
537 s->prev_frame_num_offset + 1 >> 1;
538 my =
my * (
s->frame_num_offset -
s->prev_frame_num_offset) /
539 s->prev_frame_num_offset + 1 >> 1;
544 mx =
av_clip(
mx, extra_width - 6 * x, h_edge_pos - 6 * x);
545 my =
av_clip(
my, extra_width - 6 * y, v_edge_pos - 6 * y);
554 if (dx != (int16_t)dx || dy != (int16_t)dy) {
563 mx = (
mx + 1 >> 1) + dx;
564 my = (
my + 1 >> 1) + dy;
565 fx = (unsigned)(
mx + 0x30000) / 3 - 0x10000;
566 fy = (unsigned)(
my + 0x30000) / 3 - 0x10000;
567 dxy = (
mx - 3 * fx) + 4 * (
my - 3 * fy);
570 fx, fy, dxy, 1, dir,
avg);
574 mx = (unsigned)(
mx + 1 + 0x30000) / 3 + dx - 0x10000;
575 my = (unsigned)(
my + 1 + 0x30000) / 3 + dy - 0x10000;
576 dxy = (
mx & 1) + 2 * (
my & 1);
579 mx >> 1,
my >> 1, dxy, 0, dir,
avg);
583 mx = (unsigned)(
mx + 3 + 0x60000) / 6 + dx - 0x10000;
584 my = (unsigned)(
my + 3 + 0x60000) / 6 + dy - 0x10000;
596 if (part_height == 8 &&
i < 8) {
599 if (part_width == 8 && j < 8)
602 if (part_width == 8 && j < 8)
604 if (part_width == 4 || part_height == 4)
610 part_width >> 2, part_height >> 2,
s->b_stride,
618 int mb_type,
const int *block_offset,
619 int linesize, uint8_t *dest_y)
623 for (
i = 0;
i < 16;
i++)
624 if (
s->non_zero_count_cache[
scan8[
i]] ||
s->mb[
i * 16]) {
625 uint8_t *
const ptr = dest_y + block_offset[
i];
634 const int *block_offset,
639 int qscale =
s->qscale;
642 for (
i = 0;
i < 16;
i++) {
643 uint8_t *
const ptr = dest_y + block_offset[
i];
644 const int dir =
s->intra4x4_pred_mode_cache[
scan8[
i]];
650 topright = ptr + 4 - linesize;
654 s->hpc.pred4x4[dir](ptr, topright, linesize);
655 nnz =
s->non_zero_count_cache[
scan8[
i]];
661 s->hpc.pred16x16[
s->intra16x16_pred_mode](dest_y, linesize);
668 const int mb_x =
s->mb_x;
669 const int mb_y =
s->mb_y;
670 const int mb_xy =
s->mb_xy;
671 const int mb_type =
s->cur_pic->mb_type[mb_xy];
672 uint8_t *dest_y, *dest_cb, *dest_cr;
673 int linesize, uvlinesize;
675 const int *block_offset = &
s->block_offset[0];
676 const int block_h = 16 >> 1;
678 linesize =
s->cur_pic->f->linesize[0];
679 uvlinesize =
s->cur_pic->f->linesize[1];
681 dest_y =
s->cur_pic->f->data[0] + (mb_x + mb_y * linesize) * 16;
682 dest_cb =
s->cur_pic->f->data[1] + mb_x * 8 + mb_y * uvlinesize * block_h;
683 dest_cr =
s->cur_pic->f->data[2] + mb_x * 8 + mb_y * uvlinesize * block_h;
685 s->vdsp.prefetch(dest_y + (
s->mb_x & 3) * 4 * linesize + 64, linesize, 4);
686 s->vdsp.prefetch(dest_cb + (
s->mb_x & 7) * uvlinesize + 64, dest_cr - dest_cb, 2);
689 s->hpc.pred8x8[
s->chroma_pred_mode](dest_cb, uvlinesize);
690 s->hpc.pred8x8[
s->chroma_pred_mode](dest_cr, uvlinesize);
698 uint8_t *dest[2] = { dest_cb, dest_cr };
699 s->h264dsp.chroma_dc_dequant_idct(
s->mb + 16 * 16 * 1,
700 s->dequant4_coeff[4][0]);
701 s->h264dsp.chroma_dc_dequant_idct(
s->mb + 16 * 16 * 2,
702 s->dequant4_coeff[4][0]);
703 for (j = 1; j < 3; j++) {
704 for (
i = j * 16;
i < j * 16 + 4;
i++)
705 if (
s->non_zero_count_cache[
scan8[
i]] ||
s->mb[
i * 16]) {
706 uint8_t *
const ptr = dest[j - 1] + block_offset[
i];
716 int i, j, k, m, dir,
mode;
720 const int mb_xy =
s->mb_xy;
721 const int b_xy = 4 *
s->mb_x + 4 *
s->mb_y *
s->b_stride;
723 s->top_samples_available = (
s->mb_y == 0) ? 0x33FF : 0xFFFF;
724 s->left_samples_available = (
s->mb_x == 0) ? 0x5F5F : 0xFFFF;
728 s->next_pic->mb_type[mb_xy] == -1) {
738 mb_type =
FFMIN(
s->next_pic->mb_type[mb_xy], 6);
746 }
else if (mb_type < 8) {
747 if (
s->thirdpel_flag &&
s->halfpel_flag == !
get_bits1(&
s->gb_slice))
749 else if (
s->halfpel_flag &&
764 for (m = 0; m < 2; m++) {
765 if (
s->mb_x > 0 &&
s->intra4x4_pred_mode[
s->mb2br_xy[mb_xy - 1] + 6] != -1) {
766 for (
i = 0;
i < 4;
i++)
768 s->cur_pic->motion_val[m][b_xy - 1 +
i *
s->b_stride]);
770 for (
i = 0;
i < 4;
i++)
774 memcpy(
s->mv_cache[m][
scan8[0] - 1 * 8],
775 s->cur_pic->motion_val[m][b_xy -
s->b_stride],
776 4 * 2 *
sizeof(int16_t));
777 memset(&
s->ref_cache[m][
scan8[0] - 1 * 8],
780 if (
s->mb_x <
s->mb_width - 1) {
782 s->cur_pic->motion_val[m][b_xy -
s->b_stride + 4]);
783 s->ref_cache[m][
scan8[0] + 4 - 1 * 8] =
784 (
s->intra4x4_pred_mode[
s->mb2br_xy[mb_xy -
s->mb_stride + 1] + 6] == -1 ||
790 s->cur_pic->motion_val[m][b_xy -
s->b_stride - 1]);
791 s->ref_cache[m][
scan8[0] - 1 - 1 * 8] =
796 memset(&
s->ref_cache[m][
scan8[0] - 1 * 8 - 1],
812 for (
i = 0;
i < 4;
i++)
813 memset(
s->cur_pic->motion_val[0][b_xy +
i *
s->b_stride],
814 0, 4 * 2 *
sizeof(int16_t));
820 for (
i = 0;
i < 4;
i++)
821 memset(
s->cur_pic->motion_val[1][b_xy +
i *
s->b_stride],
822 0, 4 * 2 *
sizeof(int16_t));
827 }
else if (mb_type == 8 || mb_type == 33) {
828 int8_t *i4x4 =
s->intra4x4_pred_mode +
s->mb2br_xy[
s->mb_xy];
829 int8_t *i4x4_cache =
s->intra4x4_pred_mode_cache;
831 memset(
s->intra4x4_pred_mode_cache, -1, 8 * 5 *
sizeof(int8_t));
835 for (
i = 0;
i < 4;
i++)
836 s->intra4x4_pred_mode_cache[
scan8[0] - 1 +
i * 8] =
s->intra4x4_pred_mode[
s->mb2br_xy[mb_xy - 1] + 6 -
i];
837 if (
s->intra4x4_pred_mode_cache[
scan8[0] - 1] == -1)
838 s->left_samples_available = 0x5F5F;
841 s->intra4x4_pred_mode_cache[4 + 8 * 0] =
s->intra4x4_pred_mode[
s->mb2br_xy[mb_xy -
s->mb_stride] + 0];
842 s->intra4x4_pred_mode_cache[5 + 8 * 0] =
s->intra4x4_pred_mode[
s->mb2br_xy[mb_xy -
s->mb_stride] + 1];
843 s->intra4x4_pred_mode_cache[6 + 8 * 0] =
s->intra4x4_pred_mode[
s->mb2br_xy[mb_xy -
s->mb_stride] + 2];
844 s->intra4x4_pred_mode_cache[7 + 8 * 0] =
s->intra4x4_pred_mode[
s->mb2br_xy[mb_xy -
s->mb_stride] + 3];
846 if (
s->intra4x4_pred_mode_cache[4 + 8 * 0] == -1)
847 s->top_samples_available = 0x33FF;
851 for (
i = 0;
i < 16;
i += 2) {
856 "luma prediction:%"PRIu32
"\n", vlc);
861 top = &
s->intra4x4_pred_mode_cache[
scan8[
i] - 8];
866 if (
left[1] == -1 ||
left[2] == -1) {
872 for (
i = 0;
i < 4;
i++)
873 memset(&
s->intra4x4_pred_mode_cache[
scan8[0] + 8 *
i],
DC_PRED, 4);
877 i4x4[4] = i4x4_cache[7 + 8 * 3];
878 i4x4[5] = i4x4_cache[7 + 8 * 2];
879 i4x4[6] = i4x4_cache[7 + 8 * 1];
883 s->avctx,
s->top_samples_available,
884 s->left_samples_available);
886 s->top_samples_available = (
s->mb_y == 0) ? 0x33FF : 0xFFFF;
887 s->left_samples_available = (
s->mb_x == 0) ? 0x5F5F : 0xFFFF;
889 for (
i = 0;
i < 4;
i++)
892 s->top_samples_available = 0x33FF;
893 s->left_samples_available = 0x5F5F;
899 dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
902 s->left_samples_available, dir, 0)) < 0) {
904 return s->intra16x16_pred_mode;
912 for (
i = 0;
i < 4;
i++)
913 memset(
s->cur_pic->motion_val[0][b_xy +
i *
s->b_stride],
914 0, 4 * 2 *
sizeof(int16_t));
916 for (
i = 0;
i < 4;
i++)
917 memset(
s->cur_pic->motion_val[1][b_xy +
i *
s->b_stride],
918 0, 4 * 2 *
sizeof(int16_t));
922 memset(
s->intra4x4_pred_mode +
s->mb2br_xy[mb_xy],
DC_PRED, 8);
925 memset(
s->non_zero_count_cache + 8, 0, 14 * 8 *
sizeof(uint8_t));
942 if (
s->qscale > 31u) {
952 "error while decoding intra luma dc\n");
961 for (
i = 0;
i < 4;
i++)
962 if ((cbp & (1 <<
i))) {
963 for (j = 0; j < 4; j++) {
964 k =
index ? (1 * (j & 1) + 2 * (
i & 1) +
965 2 * (j & 2) + 4 * (
i & 2))
967 s->non_zero_count_cache[
scan8[k]] = 1;
971 "error while decoding block\n");
978 for (
i = 1;
i < 3; ++
i)
981 "error while decoding chroma dc block\n");
986 for (
i = 1;
i < 3;
i++) {
987 for (j = 0; j < 4; j++) {
989 s->non_zero_count_cache[
scan8[k]] = 1;
993 "error while decoding chroma ac block\n");
1003 s->cur_pic->mb_type[mb_xy] = mb_type;
1015 const int mb_xy =
s->mb_xy;
1026 int slice_bits, slice_bytes, slice_length;
1027 int length =
header >> 5 & 3;
1029 slice_length =
show_bits(&
s->gb, 8 * length);
1030 slice_bits = slice_length * 8;
1031 slice_bytes = slice_length + length - 1;
1043 memcpy(
s->slice_buf,
s->gb.buffer +
s->gb.index / 8, slice_bytes);
1046 memmove(
s->slice_buf, &
s->slice_buf[slice_length], length - 1);
1049 if (
s->watermark_key) {
1065 if ((
header & 0x9F) == 2) {
1066 i = (
s->mb_num < 64) ? 6 : (1 +
av_log2(
s->mb_num - 1));
1080 if (
s->has_watermark)
1091 memset(
s->intra4x4_pred_mode +
s->mb2br_xy[mb_xy - 1] + 3,
1092 -1, 4 *
sizeof(int8_t));
1093 memset(
s->intra4x4_pred_mode +
s->mb2br_xy[mb_xy -
s->mb_x],
1094 -1, 8 *
sizeof(int8_t) *
s->mb_x);
1097 memset(
s->intra4x4_pred_mode +
s->mb2br_xy[mb_xy -
s->mb_stride],
1098 -1, 8 *
sizeof(int8_t) * (
s->mb_width -
s->mb_x));
1101 s->intra4x4_pred_mode[
s->mb2br_xy[mb_xy -
s->mb_stride - 1] + 3] = -1;
1110 const int max_qp = 51;
1112 for (q = 0; q < max_qp + 1; q++) {
1115 for (x = 0; x < 16; x++)
1116 s->dequant4_coeff[q][(x >> 2) | ((x << 2) & 0xF)] =
1124 const uint8_t *extradata = avctx->
extradata + seqh_offset;
1135 int frame_size_code =
get_bits(&gb, 3);
1137 switch (frame_size_code) {
1191 unk0, unk1, unk2, unk3, unk4);
1198 if (!
s->has_watermark)
1208 unsigned long buf_len = watermark_width *
1209 watermark_height * 4;
1212 if (watermark_height <= 0 ||
1214 (uint64_t)watermark_width * 4 > UINT_MAX / watermark_height)
1218 watermark_width, watermark_height);
1220 "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
1227 if (uncompress(buf, &buf_len, extradata +
offset,
1230 "could not uncompress watermark logo\n");
1236 s->watermark_key =
s->watermark_key << 16 |
s->watermark_key;
1238 "watermark key %#"PRIx32
"\n",
s->watermark_key);
1244 "this svq3 file contains watermark which need zlib support compiled in\n");
1253 unsigned char *extradata;
1256 s->cur_pic = &
s->frames[0];
1257 s->last_pic = &
s->frames[1];
1258 s->next_pic = &
s->frames[2];
1263 if (!
s->cur_pic->f || !
s->last_pic->f || !
s->next_pic->f)
1280 s->halfpel_flag = 1;
1281 s->thirdpel_flag = 1;
1282 s->has_watermark = 0;
1285 extradata = (
unsigned char *)avctx->
extradata;
1288 if (!memcmp(extradata,
"SEQH", 4)) {
1299 s->mb_width = (avctx->
width + 15) / 16;
1300 s->mb_height = (avctx->
height + 15) / 16;
1301 s->mb_stride =
s->mb_width + 1;
1302 s->mb_num =
s->mb_width *
s->mb_height;
1303 s->b_stride = 4 *
s->mb_width;
1304 s->h_edge_pos =
s->mb_width * 16;
1305 s->v_edge_pos =
s->mb_height * 16;
1307 const unsigned big_mb_num =
s->mb_stride * (
s->mb_height + 2) + 1;
1310 if (!
s->mb_type_buf)
1312 uint32_t *mb_type_buf =
s->mb_type_buf + 2 *
s->mb_stride + 1;
1314 const unsigned b4_stride =
s->mb_width * 4 + 1;
1315 const unsigned b4_array_size = b4_stride *
s->mb_height * 4;
1316 const unsigned motion_val_buf_size = b4_array_size + 4;
1318 s->motion_val_buf =
av_calloc(motion_val_buf_size,
1319 NUM_PICS * 2 *
sizeof(*
s->motion_val_buf));
1320 if (!
s->motion_val_buf)
1322 int16_t (*motion_val_buf)[2] =
s->motion_val_buf + 4;
1328 mb_type_buf += big_mb_num;
1331 motion_val_buf += motion_val_buf_size;
1335 s->intra4x4_pred_mode =
av_mallocz(
s->mb_stride * 2 * 8);
1336 if (!
s->intra4x4_pred_mode)
1339 s->mb2br_xy =
av_mallocz(
s->mb_stride * (
s->mb_height + 1) *
1340 sizeof(*
s->mb2br_xy));
1344 for (y = 0; y <
s->mb_height; y++)
1345 for (x = 0; x <
s->mb_width; x++) {
1346 const int mb_xy = x + y *
s->mb_stride;
1348 s->mb2br_xy[mb_xy] = 8 * (mb_xy % (2 *
s->mb_stride));
1365 if (!
s->edge_emu_buffer) {
1367 if (!
s->edge_emu_buffer)
1383 memset(pic->
f->
data[1], 0x80, (avctx->
height / 2) *
1385 memset(pic->
f->
data[2], 0x80, (avctx->
height / 2) *
1395 int buf_size = avpkt->
size;
1400 if (buf_size == 0) {
1401 if (
s->next_pic->f->data[0] && !
s->low_delay) {
1408 s->mb_x =
s->mb_y =
s->mb_xy = 0;
1418 if (avpkt->
size <
s->mb_width *
s->mb_height / 8)
1421 s->pict_type =
s->slice_type;
1429 s->cur_pic->f->pict_type =
s->pict_type;
1439 for (
i = 0;
i < 16;
i++) {
1441 s->block_offset[48 +
i] = (4 * ((
scan8[
i] -
scan8[0]) & 7)) + 8 *
s->cur_pic->f->linesize[0] * ((
scan8[
i] -
scan8[0]) >> 3);
1443 for (
i = 0;
i < 16;
i++) {
1444 s->block_offset[16 +
i] =
1445 s->block_offset[32 +
i] = (4 * ((
scan8[
i] -
scan8[0]) & 7)) + 4 *
s->cur_pic->f->linesize[1] * ((
scan8[
i] -
scan8[0]) >> 3);
1446 s->block_offset[48 + 16 +
i] =
1447 s->block_offset[48 + 32 +
i] = (4 * ((
scan8[
i] -
scan8[0]) & 7)) + 8 *
s->cur_pic->f->linesize[1] * ((
scan8[
i] -
scan8[0]) >> 3);
1451 if (!
s->last_pic->f->data[0]) {
1466 "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
1468 s->halfpel_flag,
s->thirdpel_flag,
1469 s->adaptive_quant,
s->qscale,
s->slice_num);
1477 s->frame_num_offset =
s->slice_num -
s->prev_frame_num;
1479 if (
s->frame_num_offset < 0)
1480 s->frame_num_offset += 256;
1481 if (
s->frame_num_offset == 0 ||
1482 s->frame_num_offset >=
s->prev_frame_num_offset) {
1487 s->prev_frame_num =
s->frame_num;
1488 s->frame_num =
s->slice_num;
1489 s->prev_frame_num_offset =
s->frame_num -
s->prev_frame_num;
1491 if (
s->prev_frame_num_offset < 0)
1492 s->prev_frame_num_offset += 256;
1495 for (m = 0; m < 2; m++) {
1497 for (
i = 0;
i < 4;
i++) {
1499 for (j = -1; j < 4; j++)
1500 s->ref_cache[m][
scan8[0] + 8 *
i + j] = 1;
1506 for (
s->mb_y = 0;
s->mb_y <
s->mb_height;
s->mb_y++) {
1507 for (
s->mb_x = 0;
s->mb_x <
s->mb_width;
s->mb_x++) {
1509 s->mb_xy =
s->mb_x +
s->mb_y *
s->mb_stride;
1519 if (
s->slice_type !=
s->pict_type) {
1533 "error while decoding MB %d %d\n",
s->mb_x,
s->mb_y);
1537 if (mb_type != 0 ||
s->cbp)
1541 s->cur_pic->mb_type[
s->mb_x +
s->mb_y *
s->mb_stride] =
1546 s->last_pic->f->data[0] ?
s->last_pic->f :
NULL,
1553 if (
s->mb_y !=
s->mb_height ||
s->mb_x !=
s->mb_width) {
1565 else if (
s->last_pic->f->data[0])
1571 if (
s->last_pic->f->data[0] ||
s->low_delay)
1601 CODEC_LONG_NAME(
"Sorenson Vector Quantizer 3 / Sorenson Video 3 / SVQ3"),
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_svq3_decoder
static av_cold void close(AVCodecParserContext *s)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Libavcodec external API header.
#define FF_DEBUG_PICT_INFO
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Public header for CRC hash function implementation.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
int(* init)(AVBSFContext *ctx)
static void fill_rectangle(int x, int y, int w, int h)
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int skip_1stop_8data_bits(GetBitContext *gb)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static void skip_bits1(GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int get_interleaved_se_golomb(GetBitContext *gb)
static unsigned get_interleaved_ue_golomb(GetBitContext *gb)
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
@ AVDISCARD_ALL
discard all
@ AVDISCARD_NONKEY
discard all frames except keyframes
@ AVDISCARD_NONREF
discard all non reference
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
int ff_h264_check_intra4x4_pred_mode(int8_t *pred_mode_cache, void *logctx, int top_samples_available, int left_samples_available)
Check if the top & left blocks are available if needed and change the dc mode so it only uses the ava...
int ff_h264_check_intra_pred_mode(void *logctx, int top_samples_available, int left_samples_available, int mode, int is_chroma)
Check if the top & left blocks are available if needed and change the dc mode so it only uses the ava...
H.264 decoder/parser shared code.
static const uint8_t scan8[16 *3+3]
static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
const uint8_t ff_h264_quant_div6[QP_MAX_NUM+1]
const IMbInfo ff_h264_i_mb_type_info[26]
const uint8_t ff_h264_golomb_to_inter_cbp[48]
const uint8_t ff_h264_quant_rem6[QP_MAX_NUM+1]
const uint8_t ff_h264_dequant4_coeff_init[6][3]
const uint8_t ff_h264_chroma_qp[7][QP_MAX_NUM+1]
const uint8_t ff_h264_golomb_to_pict_type[5]
const uint8_t ff_h264_chroma_dc_scan[4]
const uint8_t ff_h264_golomb_to_intra4x4_cbp[48]
H.264 / AVC / MPEG-4 prediction functions.
#define DIAG_DOWN_LEFT_PRED
#define PART_NOT_AVAILABLE
static const int8_t mv[256][2]
static int shift(int a, int b)
av_cold void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
av_cold void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth, int chroma_format_idc)
Set the intra prediction function pointers.
av_cold void ff_hpeldsp_init(HpelDSPContext *c, int flags)
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
Macro definitions for various function/variable attributes.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define FFSWAP(type, a, b)
const uint8_t ff_zigzag_scan[16+1]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
void ff_draw_horiz_band(AVCodecContext *avctx, const AVFrame *cur, const AVFrame *last, int y, int h, int picture_structure, int first_field, int low_delay)
Draw a horizontal band if supported.
#define MB_TYPE_INTRA16x16
@ AVCOL_RANGE_JPEG
Full range content.
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
useful rectangle filling function
static const uint8_t header[24]
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
int64_t frame_num
Frame counter, set by libavcodec.
int has_b_frames
Size of the frame reordering buffer in the decoder.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
enum AVDiscard skip_frame
Skip decoding for selected frames.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
This structure stores compressed data.
Context for storing H.264 DSP functions.
Context for storing H.264 prediction functions.
int prev_frame_num_offset
int16_t(* motion_val_buf)[2]
uint8_t * edge_emu_buffer
int16_t mb_luma_dc[3][16 *2]
enum AVPictureType pict_type
int16_t mv_cache[2][5 *8][2]
int8_t intra4x4_pred_mode_cache[5 *8]
SVQ3Frame frames[NUM_PICS]
uint8_t non_zero_count_cache[15 *8]
uint32_t dequant4_coeff[QP_MAX_NUM+1][16]
unsigned int top_samples_available
unsigned int left_samples_available
int8_t ref_cache[2][5 *8]
int block_offset[2 *(16 *3)]
int8_t * intra4x4_pred_mode
enum AVPictureType slice_type
int16_t(*[2] motion_val)[2]
static const int8_t svq3_pred_1[6][6][5]
static void svq3_mc_dir_part(SVQ3Context *s, int x, int y, int width, int height, int mx, int my, int dxy, int thirdpel, int dir, int avg)
static void init_dequant4_coeff_table(SVQ3Context *s)
static int svq3_mc_dir(SVQ3Context *s, int size, int mode, int dir, int avg)
static av_cold int svq3_decode_end(AVCodecContext *avctx)
static av_cold int svq3_decode_init(AVCodecContext *avctx)
static av_always_inline int svq3_fetch_diagonal_mv(const SVQ3Context *s, const int16_t **C, int i, int list, int part_width)
static av_always_inline void hl_decode_mb_predict_luma(SVQ3Context *s, int mb_type, const int *block_offset, int linesize, uint8_t *dest_y)
static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
static av_cold int svq3_decode_extradata(AVCodecContext *avctx, SVQ3Context *s, int seqh_offset)
static av_always_inline void hl_decode_mb_idct_luma(SVQ3Context *s, int mb_type, const int *block_offset, int linesize, uint8_t *dest_y)
static av_cold int alloc_dummy_frame(AVCodecContext *avctx, SVQ3Frame *pic)
static const uint8_t svq3_pred_0[25][2]
static int svq3_decode_slice_header(AVCodecContext *avctx)
static const uint8_t luma_dc_zigzag_scan[16]
static int get_buffer(AVCodecContext *avctx, SVQ3Frame *pic)
static const uint8_t svq3_scan[16]
static av_always_inline void svq3_pred_motion(const SVQ3Context *s, int n, int part_width, int list, int ref, int *const mx, int *const my)
Get the predicted MV.
static int svq3_decode_block(GetBitContext *gb, int16_t *block, int index, const int type)
static void svq3_add_idct_c(uint8_t *dst, int16_t *block, int stride, int qp, int dc)
static int svq3_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
static void hl_decode_mb(SVQ3Context *s)
static const uint32_t svq3_dequant_coeff[32]
static void svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)
static const struct @051316121005247241355335221116001077373164301323 svq3_dct_tables[2][16]
#define avpriv_request_sample(...)
static int ref[MAX_W *MAX_W]
av_cold void ff_tpeldsp_init(TpelDSPContext *c)
static double limit(double x)
Core video DSP helper functions.