Go to the documentation of this file.
   23 #define UNCHECKED_BITSTREAM_READER 1 
   46 #define SPRITE_TRAJ_VLC_BITS 6 
   48 #define MB_TYPE_B_VLC_BITS 4 
   49 #define STUDIO_INTRA_BITS 9 
   72     int16_t *ac_val, *ac_val1;
 
   73     int8_t *
const qscale_table = 
s->current_picture.qscale_table;
 
   76     ac_val  = &
s->ac_val[0][0][0] + 
s->block_index[
n] * 16;
 
   80             const int xy = 
s->mb_x - 1 + 
s->mb_y * 
s->mb_stride;
 
   84             if (
s->mb_x == 0 || 
s->qscale == qscale_table[xy] ||
 
   87                 for (
i = 1; 
i < 8; 
i++)
 
   88                     block[
s->idsp.idct_permutation[
i << 3]] += ac_val[
i];
 
   91                 for (
i = 1; 
i < 8; 
i++)
 
   95             const int xy = 
s->mb_x + 
s->mb_y * 
s->mb_stride - 
s->mb_stride;
 
   97             ac_val -= 16 * 
s->block_wrap[
n];
 
   99             if (
s->mb_y == 0 || 
s->qscale == qscale_table[xy] ||
 
  102                 for (
i = 1; 
i < 8; 
i++)
 
  103                     block[
s->idsp.idct_permutation[
i]] += ac_val[
i + 8];
 
  106                 for (
i = 1; 
i < 8; 
i++)
 
  112     for (
i = 1; 
i < 8; 
i++)
 
  113         ac_val1[
i] = 
block[
s->idsp.idct_permutation[
i << 3]];
 
  117         ac_val1[8 + 
i] = 
block[
s->idsp.idct_permutation[
i]];
 
  135             (v >> (8 - 
s->pict_type) != 1) || 
s->partitioned_frame)
 
  138         bits_count += 8 + 
s->pict_type;
 
  142     if (bits_count + 8 >= 
s->gb.size_in_bits) {
 
  144         v  |= 0x7F >> (7 - (bits_count & 7));
 
  151             int mb_num_bits = 
av_log2(
s->mb_num - 1) + 1;
 
  162             if (!mb_num || mb_num > 
s->mb_num || 
get_bits_count(&
s->gb)+6 > 
s->gb.size_in_bits)
 
  177     int a     = 2 << 
s->sprite_warping_accuracy;
 
  178     int rho   = 3  - 
s->sprite_warping_accuracy;
 
  184     int min_ab, 
i, w2, h2, w3, h3;
 
  185     int sprite_ref[4][2];
 
  186     int virtual_ref[2][2];
 
  187     int64_t sprite_offset[2][2];
 
  188     int64_t sprite_delta[2][2];
 
  191     const int vop_ref[4][2] = { { 0, 0 },         { 
s->width, 0 },
 
  192                                 { 0, 
s->height }, { 
s->width, 
s->height } };
 
  193     int d[4][2]             = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
 
  195     if (
w <= 0 || 
h <= 0)
 
  202     for (
i = 0; 
i < 
ctx->num_sprite_warping_points; 
i++) {
 
  210         if (!(
ctx->divx_version == 500 && 
ctx->divx_build == 413))
 
  218         ctx->sprite_traj[
i][0] = d[
i][0] = x;
 
  219         ctx->sprite_traj[
i][1] = d[
i][1] = y;
 
  222         ctx->sprite_traj[
i][0] = 
ctx->sprite_traj[
i][1] = 0;
 
  226     while ((1 << beta) < 
h)
 
  232     if (
ctx->divx_version == 500 && 
ctx->divx_build == 413) {
 
  233         sprite_ref[0][0] = 
a * vop_ref[0][0] + d[0][0];
 
  234         sprite_ref[0][1] = 
a * vop_ref[0][1] + d[0][1];
 
  235         sprite_ref[1][0] = 
a * vop_ref[1][0] + d[0][0] + d[1][0];
 
  236         sprite_ref[1][1] = 
a * vop_ref[1][1] + d[0][1] + d[1][1];
 
  237         sprite_ref[2][0] = 
a * vop_ref[2][0] + d[0][0] + d[2][0];
 
  238         sprite_ref[2][1] = 
a * vop_ref[2][1] + d[0][1] + d[2][1];
 
  240         sprite_ref[0][0] = (
a >> 1) * (2 * vop_ref[0][0] + d[0][0]);
 
  241         sprite_ref[0][1] = (
a >> 1) * (2 * vop_ref[0][1] + d[0][1]);
 
  242         sprite_ref[1][0] = (
a >> 1) * (2 * vop_ref[1][0] + d[0][0] + d[1][0]);
 
  243         sprite_ref[1][1] = (
a >> 1) * (2 * vop_ref[1][1] + d[0][1] + d[1][1]);
 
  244         sprite_ref[2][0] = (
a >> 1) * (2 * vop_ref[2][0] + d[0][0] + d[2][0]);
 
  245         sprite_ref[2][1] = (
a >> 1) * (2 * vop_ref[2][1] + d[0][1] + d[2][1]);
 
  255     virtual_ref[0][0] = 16 * (vop_ref[0][0] + w2) +
 
  257                                            (
r * sprite_ref[0][0] - 16LL * vop_ref[0][0]) +
 
  258                                       w2 * (
r * sprite_ref[1][0] - 16LL * vop_ref[1][0])), 
w);
 
  259     virtual_ref[0][1] = 16 * vop_ref[0][1] +
 
  261                                           (
r * sprite_ref[0][1] - 16LL * vop_ref[0][1]) +
 
  262                                      w2 * (
r * sprite_ref[1][1] - 16LL * vop_ref[1][1])), 
w);
 
  263     virtual_ref[1][0] = 16 * vop_ref[0][0] +
 
  264                         ROUNDED_DIV(((
h - h2) * (
r * sprite_ref[0][0] - 16LL * vop_ref[0][0]) +
 
  265                                            h2 * (
r * sprite_ref[2][0] - 16LL * vop_ref[2][0])), 
h);
 
  266     virtual_ref[1][1] = 16 * (vop_ref[0][1] + h2) +
 
  267                         ROUNDED_DIV(((
h - h2) * (
r * sprite_ref[0][1] - 16LL * vop_ref[0][1]) +
 
  268                                            h2 * (
r * sprite_ref[2][1] - 16LL * vop_ref[2][1])), 
h);
 
  270     switch (
ctx->num_sprite_warping_points) {
 
  272         sprite_offset[0][0]    =
 
  273         sprite_offset[0][1]    =
 
  274         sprite_offset[1][0]    =
 
  275         sprite_offset[1][1]    = 0;
 
  276         sprite_delta[0][0]     = 
a;
 
  278         sprite_delta[1][0]     = 0;
 
  279         sprite_delta[1][1]     = 
a;
 
  280         ctx->sprite_shift[0]   =
 
  281         ctx->sprite_shift[1]   = 0;
 
  284         sprite_offset[0][0]    = sprite_ref[0][0] - 
a * vop_ref[0][0];
 
  285         sprite_offset[0][1]    = sprite_ref[0][1] - 
a * vop_ref[0][1];
 
  286         sprite_offset[1][0]    = ((sprite_ref[0][0] >> 1) | (sprite_ref[0][0] & 1)) -
 
  287                                  a * (vop_ref[0][0] / 2);
 
  288         sprite_offset[1][1]    = ((sprite_ref[0][1] >> 1) | (sprite_ref[0][1] & 1)) -
 
  289                                  a * (vop_ref[0][1] / 2);
 
  290         sprite_delta[0][0]     = 
a;
 
  292         sprite_delta[1][0]     = 0;
 
  293         sprite_delta[1][1]     = 
a;
 
  294         ctx->sprite_shift[0]   =
 
  295         ctx->sprite_shift[1]   = 0;
 
  298         sprite_offset[0][0]    = ((int64_t)      sprite_ref[0][0] * (1 << 
alpha + rho)) +
 
  299                                  ((int64_t) -
r * sprite_ref[0][0] + virtual_ref[0][0]) *
 
  300                                  ((int64_t)        -vop_ref[0][0]) +
 
  301                                  ((int64_t)  
r * sprite_ref[0][1] - virtual_ref[0][1]) *
 
  302                                  ((int64_t)        -vop_ref[0][1]) + (1 << (
alpha + rho - 1));
 
  303         sprite_offset[0][1]    = ((int64_t)      sprite_ref[0][1] * (1 << 
alpha + rho)) +
 
  304                                  ((int64_t) -
r * sprite_ref[0][1] + virtual_ref[0][1]) *
 
  305                                  ((int64_t)        -vop_ref[0][0]) +
 
  306                                  ((int64_t) -
r * sprite_ref[0][0] + virtual_ref[0][0]) *
 
  307                                  ((int64_t)        -vop_ref[0][1]) + (1 << (
alpha + rho - 1));
 
  308         sprite_offset[1][0]    = (((int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) *
 
  309                                   ((int64_t)-2 *    vop_ref[0][0] + 1) +
 
  310                                   ((int64_t) 
r * sprite_ref[0][1] - virtual_ref[0][1]) *
 
  311                                   ((int64_t)-2 *    vop_ref[0][1] + 1) + 2 * w2 * 
r *
 
  312                                    (int64_t)     sprite_ref[0][0] - 16 * w2 + (1 << (
alpha + rho + 1)));
 
  313         sprite_offset[1][1]    = (((int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) *
 
  314                                   ((int64_t)-2 *    vop_ref[0][0] + 1) +
 
  315                                   ((int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) *
 
  316                                   ((int64_t)-2 *    vop_ref[0][1] + 1) + 2 * w2 * 
r *
 
  317                                   (int64_t)      sprite_ref[0][1] - 16 * w2 + (1 << (
alpha + rho + 1)));
 
  318         sprite_delta[0][0] = (-
r * sprite_ref[0][0] + virtual_ref[0][0]);
 
  319         sprite_delta[0][1] = (+
r * sprite_ref[0][1] - virtual_ref[0][1]);
 
  320         sprite_delta[1][0] = (-
r * sprite_ref[0][1] + virtual_ref[0][1]);
 
  321         sprite_delta[1][1] = (-
r * sprite_ref[0][0] + virtual_ref[0][0]);
 
  324         ctx->sprite_shift[1]  = 
alpha + rho + 2;
 
  330         sprite_offset[0][0]    = ((int64_t)sprite_ref[0][0] * (1 << (
alpha + beta + rho - min_ab))) +
 
  331                                  ((int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-vop_ref[0][0]) +
 
  332                                  ((int64_t)-
r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-vop_ref[0][1]) +
 
  333                                  ((int64_t)1 << (
alpha + beta + rho - min_ab - 1));
 
  334         sprite_offset[0][1]    = ((int64_t)sprite_ref[0][1] * (1 << (
alpha + beta + rho - min_ab))) +
 
  335                                  ((int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-vop_ref[0][0]) +
 
  336                                  ((int64_t)-
r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-vop_ref[0][1]) +
 
  337                                  ((int64_t)1 << (
alpha + beta + rho - min_ab - 1));
 
  338         sprite_offset[1][0]    = ((int64_t)-
r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-2 * vop_ref[0][0] + 1) +
 
  339                                  ((int64_t)-
r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-2 * vop_ref[0][1] + 1) +
 
  340                                   (int64_t)2 * w2 * h3 * 
r * sprite_ref[0][0] - 16 * w2 * h3 +
 
  341                                  ((int64_t)1 << (
alpha + beta + rho - min_ab + 1));
 
  342         sprite_offset[1][1]    = ((int64_t)-
r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-2 * vop_ref[0][0] + 1) +
 
  343                                  ((int64_t)-
r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-2 * vop_ref[0][1] + 1) +
 
  344                                   (int64_t)2 * w2 * h3 * 
r * sprite_ref[0][1] - 16 * w2 * h3 +
 
  345                                  ((int64_t)1 << (
alpha + beta + rho - min_ab + 1));
 
  346         sprite_delta[0][0] = (-
r * (int64_t)sprite_ref[0][0] + virtual_ref[0][0]) * h3;
 
  347         sprite_delta[0][1] = (-
r * (int64_t)sprite_ref[0][0] + virtual_ref[1][0]) * w3;
 
  348         sprite_delta[1][0] = (-
r * (int64_t)sprite_ref[0][1] + virtual_ref[0][1]) * h3;
 
  349         sprite_delta[1][1] = (-
r * (int64_t)sprite_ref[0][1] + virtual_ref[1][1]) * w3;
 
  351         ctx->sprite_shift[0]  = 
alpha + beta + rho - min_ab;
 
  352         ctx->sprite_shift[1]  = 
alpha + beta + rho - min_ab + 2;
 
  356     if (sprite_delta[0][0] == 
a << 
ctx->sprite_shift[0] &&
 
  357         sprite_delta[0][1] == 0 &&
 
  358         sprite_delta[1][0] == 0 &&
 
  359         sprite_delta[1][1] == 
a << 
ctx->sprite_shift[0]) {
 
  360         sprite_offset[0][0] >>= 
ctx->sprite_shift[0];
 
  361         sprite_offset[0][1] >>= 
ctx->sprite_shift[0];
 
  362         sprite_offset[1][0] >>= 
ctx->sprite_shift[1];
 
  363         sprite_offset[1][1] >>= 
ctx->sprite_shift[1];
 
  364         sprite_delta[0][0] = 
a;
 
  365         sprite_delta[0][1] = 0;
 
  366         sprite_delta[1][0] = 0;
 
  367         sprite_delta[1][1] = 
a;
 
  368         ctx->sprite_shift[0] = 0;
 
  369         ctx->sprite_shift[1] = 0;
 
  370         s->real_sprite_warping_points = 1;
 
  372         int shift_y = 16 - 
ctx->sprite_shift[0];
 
  373         int shift_c = 16 - 
ctx->sprite_shift[1];
 
  375         for (
i = 0; 
i < 2; 
i++) {
 
  376             if (shift_c < 0 || shift_y < 0 ||
 
  377                 FFABS(  sprite_offset[0][
i]) >= INT_MAX >> shift_y  ||
 
  378                 FFABS(  sprite_offset[1][
i]) >= INT_MAX >> shift_c  ||
 
  379                 FFABS(   sprite_delta[0][
i]) >= INT_MAX >> shift_y  ||
 
  380                 FFABS(   sprite_delta[1][
i]) >= INT_MAX >> shift_y
 
  387         for (
i = 0; 
i < 2; 
i++) {
 
  388             sprite_offset[0][
i]    *= 1 << shift_y;
 
  389             sprite_offset[1][
i]    *= 1 << shift_c;
 
  390             sprite_delta[0][
i]     *= 1 << shift_y;
 
  391             sprite_delta[1][
i]     *= 1 << shift_y;
 
  392             ctx->sprite_shift[
i]     = 16;
 
  395         for (
i = 0; 
i < 2; 
i++) {
 
  397                 sprite_delta[
i][0] - 
a * (1LL<<16),
 
  398                 sprite_delta[
i][1] - 
a * (1LL<<16)
 
  401             if (llabs(sprite_offset[0][
i] + sprite_delta[
i][0] * (
w+16LL)) >= INT_MAX ||
 
  402                 llabs(sprite_offset[0][
i] + sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
 
  403                 llabs(sprite_offset[0][
i] + sprite_delta[
i][0] * (
w+16LL) + sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
 
  404                 llabs(sprite_delta[
i][0] * (
w+16LL)) >= INT_MAX ||
 
  405                 llabs(sprite_delta[
i][1] * (
h+16LL)) >= INT_MAX ||
 
  406                 llabs(sd[0]) >= INT_MAX ||
 
  407                 llabs(sd[1]) >= INT_MAX ||
 
  408                 llabs(sprite_offset[0][
i] + sd[0] * (
w+16LL)) >= INT_MAX ||
 
  409                 llabs(sprite_offset[0][
i] + sd[1] * (
h+16LL)) >= INT_MAX ||
 
  410                 llabs(sprite_offset[0][
i] + sd[0] * (
w+16LL) + sd[1] * (
h+16LL)) >= INT_MAX
 
  416         s->real_sprite_warping_points = 
ctx->num_sprite_warping_points;
 
  419     for (
i = 0; 
i < 4; 
i++) {
 
  420         s->sprite_offset[
i&1][
i>>1] = sprite_offset[
i&1][
i>>1];
 
  421         s->sprite_delta [
i&1][
i>>1] = sprite_delta [
i&1][
i>>1];
 
  426     memset(
s->sprite_offset, 0, 
sizeof(
s->sprite_offset));
 
  427     memset(
s->sprite_delta, 0, 
sizeof(
s->sprite_delta));
 
  451     int mb_num_bits      = 
av_log2(
s->mb_num - 1) + 1;
 
  452     int header_extension = 0, mb_num, 
len;
 
  473     if (mb_num >= 
s->mb_num || !mb_num) {
 
  475                "illegal mb_num in video packet (%d %d) \n", mb_num, 
s->mb_num);
 
  479     s->mb_x = mb_num % 
s->mb_width;
 
  480     s->mb_y = mb_num / 
s->mb_width;
 
  483         int qscale = 
get_bits(&
s->gb, 
s->quant_precision);
 
  485             s->chroma_qscale = 
s->qscale = qscale;
 
  491     if (header_extension) {
 
  497         check_marker(
s->avctx, &
s->gb, 
"before time_increment in video packed header");
 
  499         check_marker(
s->avctx, &
s->gb, 
"before vop_coding_type in video packed header");
 
  520                            "Error, video packet header damaged (f_code=0)\n");
 
  526                            "Error, video packet header damaged (b_code=0)\n");
 
  541     s->last_dc[2] = 1 << (
s->avctx->bits_per_raw_sample + 
s->dct_precision + 
s->intra_dc_precision - 1);
 
  556         vlc_len = 
av_log2(
s->mb_width * 
s->mb_height) + 1;
 
  559         if (mb_num >= 
s->mb_num)
 
  562         s->mb_x = mb_num % 
s->mb_width;
 
  563         s->mb_y = mb_num / 
s->mb_width;
 
  593     int x, y, mb_v, sum, dx, dy, 
shift;
 
  594     int len     = 1 << (
s->f_code + 4);
 
  595     const int a = 
s->sprite_warping_accuracy;
 
  598         len >>= 
s->quarter_sample;
 
  600     if (
s->real_sprite_warping_points == 1) {
 
  601         if (
ctx->divx_version == 500 && 
ctx->divx_build == 413 && 
a >= 
s->quarter_sample)
 
  602             sum = 
s->sprite_offset[0][
n] / (1 << (
a - 
s->quarter_sample));
 
  604             sum = 
RSHIFT(
s->sprite_offset[0][
n] * (1 << 
s->quarter_sample), 
a);
 
  606         dx    = 
s->sprite_delta[
n][0];
 
  607         dy    = 
s->sprite_delta[
n][1];
 
  610             dy -= 1 << (
shift + 
a + 1);
 
  612             dx -= 1 << (
shift + 
a + 1);
 
  613         mb_v = 
s->sprite_offset[0][
n] + dx * 
s->mb_x * 16
U + dy * 
s->mb_y * 16
U;
 
  616         for (y = 0; y < 16; y++) {
 
  621             for (x = 0; x < 16; x++) {
 
  626         sum = 
RSHIFT(sum, 
a + 8 - 
s->quarter_sample);
 
  652     if (code < 0 || code > 9 ) {
 
  694     static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
 
  697     s->first_slice_line = 1;
 
  698     for (; 
s->mb_y < 
s->mb_height; 
s->mb_y++) {
 
  700         for (; 
s->mb_x < 
s->mb_width; 
s->mb_x++) {
 
  701             const int xy = 
s->mb_x + 
s->mb_y * 
s->mb_stride;
 
  707             if (
s->mb_x == 
s->resync_mb_x && 
s->mb_y == 
s->resync_mb_y + 1)
 
  708                 s->first_slice_line = 0;
 
  720                                "mcbpc corrupted at %d %d\n", 
s->mb_x, 
s->mb_y);
 
  725                 s->cbp_table[xy]               = cbpc & 3;
 
  732                 s->current_picture.qscale_table[xy] = 
s->qscale;
 
  734                 s->mbintra_table[xy] = 1;
 
  735                 for (
i = 0; 
i < 6; 
i++) {
 
  740                                "DC corrupted at %d %d\n", 
s->mb_x, 
s->mb_y);
 
  747                 s->pred_dir_table[xy] = dir;
 
  749                 int mx, my, pred_x, pred_y, 
bits;
 
  750                 int16_t *
const mot_val = 
s->current_picture.motion_val[0][
s->block_index[0]];
 
  751                 const int stride       = 
s->b8_stride * 2;
 
  759                 if (
bits & 0x10000) {
 
  784                     if (
s->mbintra_table[xy])
 
  792                            "mcbpc corrupted at %d %d\n", 
s->mb_x, 
s->mb_y);
 
  798                 s->cbp_table[xy] = cbpc & (8 + 3);  
 
  800                 s->mb_intra = ((cbpc & 4) != 0);
 
  804                     s->mbintra_table[xy] = 1;
 
  814                     if (
s->mbintra_table[xy])
 
  824                     if ((cbpc & 16) == 0) {
 
  858                         for (
i = 0; 
i < 4; 
i++) {
 
  887     static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
 
  889     s->mb_x = 
s->resync_mb_x;
 
  890     s->first_slice_line = 1;
 
  891     for (
s->mb_y = 
s->resync_mb_y; mb_num < mb_count; s->mb_y++) {
 
  893         for (; mb_num < mb_count && 
s->mb_x < 
s->mb_width; 
s->mb_x++) {
 
  894             const int xy = 
s->mb_x + 
s->mb_y * 
s->mb_stride;
 
  898             if (
s->mb_x == 
s->resync_mb_x && 
s->mb_y == 
s->resync_mb_y + 1)
 
  899                 s->first_slice_line = 0;
 
  906                            "cbpy corrupted at %d %d\n", 
s->mb_x, 
s->mb_y);
 
  910                 s->cbp_table[xy]               |= cbpy << 2;
 
  913                 if (
IS_INTRA(
s->current_picture.mb_type[xy])) {
 
  921                                "I cbpy corrupted at %d %d\n", 
s->mb_x, 
s->mb_y);
 
  925                     if (
s->cbp_table[xy] & 8)
 
  927                     s->current_picture.qscale_table[xy] = 
s->qscale;
 
  929                     for (
i = 0; 
i < 6; 
i++) {
 
  934                                    "DC corrupted at %d %d\n", 
s->mb_x, 
s->mb_y);
 
  941                     s->cbp_table[xy]               &= 3;  
 
  942                     s->cbp_table[xy]               |= cbpy << 2;
 
  944                     s->pred_dir_table[xy]           = dir;
 
  945                 } 
else if (
IS_SKIP(
s->current_picture.mb_type[xy])) {
 
  946                     s->current_picture.qscale_table[xy] = 
s->qscale;
 
  947                     s->cbp_table[xy]                    = 0;
 
  953                                "P cbpy corrupted at %d %d\n", 
s->mb_x, 
s->mb_y);
 
  957                     if (
s->cbp_table[xy] & 8)
 
  959                     s->current_picture.qscale_table[xy] = 
s->qscale;
 
  961                     s->cbp_table[xy] &= 3;  
 
  962                     s->cbp_table[xy] |= (cbpy ^ 0xf) << 2;
 
  966         if (mb_num >= mb_count)
 
  988                         s->mb_x, 
s->mb_y, part_a_error);
 
  992     if (
s->resync_mb_x + 
s->resync_mb_y * 
s->mb_width + mb_num > 
s->mb_num) {
 
  995                         s->mb_x, 
s->mb_y, part_a_error);
 
  999     s->mb_num_left = mb_num;
 
 1006                    "marker missing after first I partition at %d %d\n",
 
 1015                    "marker missing after first P partition at %d %d\n",
 
 1021                     s->mb_x - 1, 
s->mb_y, part_a_end);
 
 1043                                      int n, 
int coded, 
int intra, 
int rvlc)
 
 1055         if (
ctx->use_intra_dc_vlc) {
 
 1057             if (
s->partitioned_frame) {
 
 1058                 level = 
s->dc_val[0][
s->block_index[
n]];
 
 1063                 dc_pred_dir = (
s->pred_dir_table[
s->mb_x + 
s->mb_y * 
s->mb_stride] << 
n) & 32;
 
 1086             if (dc_pred_dir == 0)
 
 1087                 scan_table = 
s->intra_v_scantable.permutated;  
 
 1089                 scan_table = 
s->intra_h_scantable.permutated;  
 
 1091             scan_table = 
s->intra_scantable.permutated;
 
 1098             s->block_last_index[
n] = 
i;
 
 1106         scan_table = 
s->intra_scantable.permutated;
 
 1108         if (
s->mpeg_quant) {
 
 1116             qmul = 
s->qscale << 1;
 
 1117             qadd = (
s->qscale - 1) | 1;
 
 1134                                "1. marker bit missing in rvlc esc\n");
 
 1147                                "2. marker bit missing in rvlc esc\n");
 
 1173                         cache ^= 0xC0000000;
 
 1175                     if (cache & 0x80000000) {
 
 1176                         if (cache & 0x40000000) {
 
 1191                                            "1. marker bit missing in 3. esc\n");
 
 1202                                            "2. marker bit missing in 3. esc\n");
 
 1211                             if (
s->error_recognition >= FF_ER_COMPLIANT) {
 
 1214                                     const int run1= 
run - rl->
max_run[last][abs_level] - 1;
 
 1215                                     if (abs_level <= rl->max_level[last][
run]) {
 
 1219                                     if (
s->error_recognition > FF_ER_COMPLIANT) {
 
 1220                                         if (abs_level <= rl->max_level[last][
run]*2) {
 
 1224                                         if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) {
 
 1237                             if ((
unsigned)(
level + 2048) > 4095) {
 
 1241                                                "|level| overflow in 3. esc, qp=%d\n",
 
 1275             ff_tlog(
s->avctx, 
"dct[%d][%d] = %- 4d end?:%d\n", scan_table[
i&63]&7, scan_table[
i&63] >> 3, 
level, 
i>62);
 
 1280                            "ac-tex damaged at %d %d\n", 
s->mb_x, 
s->mb_y);
 
 1295         if (!
ctx->use_intra_dc_vlc) {
 
 1305     s->block_last_index[
n] = 
i;
 
 1317     const int xy = 
s->mb_x + 
s->mb_y * 
s->mb_stride;
 
 1321     mb_type = 
s->current_picture.mb_type[xy];
 
 1322     cbp     = 
s->cbp_table[xy];
 
 1324     ctx->use_intra_dc_vlc = 
s->qscale < 
ctx->intra_dc_threshold;
 
 1326     if (
s->current_picture.qscale_table[xy] != 
s->qscale)
 
 1332         for (
i = 0; 
i < 4; 
i++) {
 
 1333             s->mv[0][
i][0] = 
s->current_picture.motion_val[0][
s->block_index[
i]][0];
 
 1334             s->mv[0][
i][1] = 
s->current_picture.motion_val[0][
s->block_index[
i]][1];
 
 1340             for (
i = 0; 
i < 6; 
i++)
 
 1341                 s->block_last_index[
i] = -1;
 
 1352         } 
else if (
s->mb_intra) {
 
 1353             s->ac_pred = 
IS_ACPRED(
s->current_picture.mb_type[xy]);
 
 1354         } 
else if (!
s->mb_intra) {
 
 1366         s->ac_pred  = 
IS_ACPRED(
s->current_picture.mb_type[xy]);
 
 1371         s->bdsp.clear_blocks(
s->block[0]);
 
 1373         for (
i = 0; 
i < 6; 
i++) {
 
 1376                        "texture corrupted at %d %d %d\n",
 
 1377                        s->mb_x, 
s->mb_y, 
s->mb_intra);
 
 1385     if (--
s->mb_num_left <= 0) {
 
 1392             const int delta = 
s->mb_x + 1 == 
s->mb_width ? 2 : 1;
 
 1393             if (
s->cbp_table[xy + 
delta])
 
 1403     int cbpc, cbpy, 
i, cbp, pred_x, pred_y, mx, my, dquant;
 
 1405     static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
 
 1406     const int xy = 
s->mb_x + 
s->mb_y * 
s->mb_stride;
 
 1417                 for (
i = 0; 
i < 6; 
i++)
 
 1418                     s->block_last_index[
i] = -1;
 
 1445                        "mcbpc damaged at %d %d\n", 
s->mb_x, 
s->mb_y);
 
 1448         } 
while (cbpc == 20);
 
 1450         s->bdsp.clear_blocks(
s->block[0]);
 
 1452         s->mb_intra = ((cbpc & 4) != 0);
 
 1464                    "P cbpy damaged at %d %d\n", 
s->mb_x, 
s->mb_y);
 
 1468         cbp = (cbpc & 3) | (cbpy << 2);
 
 1471         if ((!
s->progressive_sequence) &&
 
 1476         if ((cbpc & 16) == 0) {
 
 1485                 s->mv[0][0][0] = mx;
 
 1486                 s->mv[0][0][1] = my;
 
 1487             } 
else if ((!
s->progressive_sequence) && 
get_bits1(&
s->gb)) {
 
 1499                 for (
i = 0; 
i < 2; 
i++) {
 
 1508                     s->mv[0][
i][0] = mx;
 
 1509                     s->mv[0][
i][1] = my;
 
 1525                 s->mv[0][0][0] = mx;
 
 1526                 s->mv[0][0][1] = my;
 
 1531             for (
i = 0; 
i < 4; 
i++) {
 
 1540                 s->mv[0][
i][0] = mx;
 
 1541                 s->mv[0][
i][1] = my;
 
 1555             for (
i = 0; 
i < 2; 
i++) {
 
 1556                 s->last_mv[
i][0][0] =
 
 1557                 s->last_mv[
i][0][1] =
 
 1558                 s->last_mv[
i][1][0] =
 
 1559                 s->last_mv[
i][1][1] = 0;
 
 1566         s->mb_skipped = 
s->next_picture.mbskip_table[
s->mb_y * 
s->mb_stride + 
s->mb_x];  
 
 1568         if (
s->mb_skipped) {
 
 1570             for (
i = 0; 
i < 6; 
i++)
 
 1571                 s->block_last_index[
i] = -1;
 
 1601                 s->bdsp.clear_blocks(
s->block[0]);
 
 1610             if (!
s->progressive_sequence) {
 
 1638                     s->last_mv[0][1][0] =
 
 1639                     s->last_mv[0][0][0] =
 
 1640                     s->mv[0][0][0]      = mx;
 
 1641                     s->last_mv[0][1][1] =
 
 1642                     s->last_mv[0][0][1] =
 
 1643                     s->mv[0][0][1]      = my;
 
 1651                     s->last_mv[1][1][0] =
 
 1652                     s->last_mv[1][0][0] =
 
 1653                     s->mv[1][0][0]      = mx;
 
 1654                     s->last_mv[1][1][1] =
 
 1655                     s->last_mv[1][0][1] =
 
 1656                     s->mv[1][0][1]      = my;
 
 1664                     for (
i = 0; 
i < 2; 
i++) {
 
 1667                         s->last_mv[0][
i][0] =
 
 1668                         s->mv[0][
i][0]      = mx;
 
 1669                         s->last_mv[0][
i][1] = (
s->mv[0][
i][1] = my) * 2;
 
 1676                     for (
i = 0; 
i < 2; 
i++) {
 
 1679                         s->last_mv[1][
i][0] =
 
 1680                         s->mv[1][
i][0]      = mx;
 
 1681                         s->last_mv[1][
i][1] = (
s->mv[1][
i][1] = my) * 2;
 
 1699         s->current_picture.mb_type[xy] = mb_type;
 
 1705                        "I cbpc damaged at %d %d\n", 
s->mb_x, 
s->mb_y);
 
 1708         } 
while (cbpc == 8);
 
 1723                    "I cbpy damaged at %d %d\n", 
s->mb_x, 
s->mb_y);
 
 1726         cbp = (cbpc & 3) | (cbpy << 2);
 
 1728         ctx->use_intra_dc_vlc = 
s->qscale < 
ctx->intra_dc_threshold;
 
 1733         if (!
s->progressive_sequence)
 
 1736         s->bdsp.clear_blocks(
s->block[0]);
 
 1738         for (
i = 0; 
i < 6; 
i++) {
 
 1747     for (
i = 0; 
i < 6; 
i++) {
 
 1758             if        (
s->mb_x + 
s->mb_y*
s->mb_width + 1 >  next && (
s->avctx->err_recognition & 
AV_EF_AGGRESSIVE)) {
 
 1760             } 
else if (
s->mb_x + 
s->mb_y*
s->mb_width + 1 >= next)
 
 1764                 const int delta= 
s->mb_x + 1 == 
s->mb_width ? 2 : 1;
 
 1766                                          (
s->mb_x + 
delta >= 
s->mb_width)
 
 1767                                          ? 
FFMIN(
s->mb_y + 1, 
s->mb_height - 1)
 
 1769                 if (
s->next_picture.mbskip_table[xy + 
delta])
 
 1821     int cc, dct_dc_size, dct_diff, 
code, j, idx = 1, group = 0, 
run = 0,
 
 1822         additional_code_len, sign, mismatch;
 
 1823     VLC *cur_vlc = &
ctx->studio_intra_tab[0];
 
 1824     uint8_t *
const scantable = 
s->intra_scantable.permutated;
 
 1825     const uint16_t *quant_matrix;
 
 1827     const int min = -1 *  (1 << (
s->avctx->bits_per_raw_sample + 6));
 
 1828     const int max =      ((1 << (
s->avctx->bits_per_raw_sample + 6)) - 1);
 
 1829     int shift =  3 - 
s->dct_precision;
 
 1838         quant_matrix = 
s->intra_matrix;
 
 1845         quant_matrix = 
s->chroma_intra_matrix;
 
 1848     if (dct_dc_size < 0) {
 
 1851     } 
else if (dct_dc_size == 0) {
 
 1856         if (dct_dc_size > 8) {
 
 1863     s->last_dc[cc] += dct_diff;
 
 1866         block[0] = 
s->last_dc[cc] * (8 >> 
s->intra_dc_precision);
 
 1868         block[0] = 
s->last_dc[cc] * (8 >> 
s->intra_dc_precision) * (8 >> 
s->dct_precision);
 
 1872     mismatch ^= 
block[0];
 
 1889         } 
else if (group >= 1 && group <= 6) {
 
 1891             run = 1 << additional_code_len;
 
 1892             if (additional_code_len)
 
 1896         } 
else if (group >= 7 && group <= 12) {
 
 1901             run = (1 << (additional_code_len - 1)) + 
code;
 
 1905             j = scantable[idx++];
 
 1906             block[j] = sign ? 1 : -1;
 
 1907         } 
else if (group >= 13 && group <= 20) {
 
 1911             j = scantable[idx++];
 
 1913         } 
else if (group == 21) {
 
 1917             j = scantable[idx++];
 
 1918             additional_code_len = 
s->avctx->bits_per_raw_sample + 
s->dct_precision + 4;
 
 1919             flc = 
get_bits(&
s->gb, additional_code_len);
 
 1920             if (flc >> (additional_code_len-1))
 
 1921                 block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1);
 
 1927         mismatch ^= 
block[j];
 
 1930     block[63] ^= mismatch & 1;
 
 1937     int i, j, 
w, 
h, idx = 0;
 
 1938     int block_mean, rice_parameter, rice_prefix_code, rice_suffix_code,
 
 1939         dpcm_residual, 
left, top, topleft, min_left_top, max_left_top, p, p2, 
output;
 
 1940     h = 16 >> (
n ? 
s->chroma_y_shift : 0);
 
 1941     w = 16 >> (
n ? 
s->chroma_x_shift : 0);
 
 1943     block_mean = 
get_bits(&
s->gb, 
s->avctx->bits_per_raw_sample);
 
 1944     if (block_mean == 0){
 
 1948     s->last_dc[
n] = block_mean * (1 << (
s->dct_precision + 
s->intra_dc_precision));
 
 1951     if (rice_parameter == 0) {
 
 1956     if (rice_parameter == 15)
 
 1959     if (rice_parameter > 11) {
 
 1964     for (
i = 0; 
i < 
h; 
i++) {
 
 1965         output = 1 << (
s->avctx->bits_per_raw_sample - 1);
 
 1966         top = 1 << (
s->avctx->bits_per_raw_sample - 1);
 
 1968         for (j = 0; j < 
w; j++) {
 
 1975             if (rice_prefix_code == 11)
 
 1976                 dpcm_residual = 
get_bits(&
s->gb, 
s->avctx->bits_per_raw_sample);
 
 1978                 if (rice_prefix_code == 12) {
 
 1982                 rice_suffix_code = 
get_bitsz(&
s->gb, rice_parameter);
 
 1983                 dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code;
 
 1987             if (dpcm_residual & 1)
 
 1988                 dpcm_residual = (-1 * dpcm_residual) >> 1;
 
 1990                 dpcm_residual = (dpcm_residual >> 1);
 
 1993                 top = macroblock[idx-
w];
 
 1995             p = 
left + top - topleft;
 
 1997             if (p < min_left_top)
 
 2001             if (p > max_left_top)
 
 2004             p2 = (
FFMIN(min_left_top, topleft) + 
FFMAX(max_left_top, topleft)) >> 1;
 
 2009                 dpcm_residual *= -1;
 
 2011             macroblock[idx++] = 
output = (dpcm_residual + p) & ((1 << 
s->avctx->bits_per_raw_sample) - 1);
 
 2022     s->dpcm_direction = 0;
 
 2043         for (
i = 0; 
i < 3; 
i++) {
 
 2067     int hours, minutes, seconds;
 
 2079     s->time_base = seconds + 60*(minutes + 60*hours);
 
 2103     int visual_object_type;
 
 2104     int is_visual_object_identifier = 
get_bits1(gb);
 
 2106     if (is_visual_object_identifier) {
 
 2109     visual_object_type = 
get_bits(gb, 4);
 
 2114         if (video_signal_type) {
 
 2115             int video_range, color_description;
 
 2122             if (color_description) {
 
 2123                 s->avctx->color_primaries = 
get_bits(gb, 8);
 
 2138     for (
i = 0; 
i < 64; 
i++) {
 
 2139         int j = 
s->idsp.idct_permutation[
i];
 
 2141         s->intra_matrix[j]        = v;
 
 2142         s->chroma_intra_matrix[j] = v;
 
 2145         s->inter_matrix[j]        = v;
 
 2146         s->chroma_inter_matrix[j] = v;
 
 2168         s->studio_profile = 1;
 
 2171     } 
else if (
s->studio_profile) {
 
 2183         s->avctx->sample_aspect_ratio.num = 
get_bits(gb, 8);  
 
 2184         s->avctx->sample_aspect_ratio.den = 
get_bits(gb, 8);  
 
 2190         int chroma_format = 
get_bits(gb, 2);
 
 2201             check_marker(
s->avctx, gb, 
"after first_half_vbv_buffer_size");
 
 2204             check_marker(
s->avctx, gb, 
"after first_half_vbv_occupancy");
 
 2206             check_marker(
s->avctx, gb, 
"after latter_half_vbv_occupancy");
 
 2211         if (
s->picture_number == 0) {
 
 2212             switch(
s->vo_type) {
 
 2231     check_marker(
s->avctx, gb, 
"before time_increment_resolution");
 
 2233     s->avctx->framerate.num = 
get_bits(gb, 16);
 
 2234     if (!
s->avctx->framerate.num) {
 
 2239     ctx->time_increment_bits = 
av_log2(
s->avctx->framerate.num - 1) + 1;
 
 2240     if (
ctx->time_increment_bits < 1)
 
 2241         ctx->time_increment_bits = 1;
 
 2246         s->avctx->framerate.den = 
get_bits(gb, 
ctx->time_increment_bits);
 
 2248         s->avctx->framerate.den = 1;
 
 2262                 !(
s->width && 
s->codec_tag == 
AV_RL32(
"MP4S"))) {
 
 2263                 if (
s->width && 
s->height &&
 
 2265                     s->context_reinit = 1;
 
 2271         s->progressive_sequence  =
 
 2273         s->interlaced_dct        = 0;
 
 2276                    "MPEG-4 OBMC not supported (very likely buggy encoder)\n");
 
 2297             if (
ctx->num_sprite_warping_points > 3) {
 
 2299                        "%d sprite_warping_points\n",
 
 2300                        ctx->num_sprite_warping_points);
 
 2301                 ctx->num_sprite_warping_points = 0;
 
 2304             s->sprite_warping_accuracy  = 
get_bits(gb, 2);
 
 2315             if (
s->quant_precision != 5)
 
 2317                        "quant precision %d\n", 
s->quant_precision);
 
 2318             if (
s->quant_precision<3 || 
s->quant_precision>9) {
 
 2319                 s->quant_precision = 5;
 
 2322             s->quant_precision = 5;
 
 2335                 for (
i = 0; 
i < 64; 
i++) {
 
 2347                     s->intra_matrix[j]        = last;
 
 2348                     s->chroma_intra_matrix[j] = last;
 
 2352                 for (; 
i < 64; 
i++) {
 
 2354                     s->intra_matrix[j]        = last;
 
 2355                     s->chroma_intra_matrix[j] = last;
 
 2362                 for (
i = 0; 
i < 64; 
i++) {
 
 2374                     s->inter_matrix[j]        = v;
 
 2375                     s->chroma_inter_matrix[j] = v;
 
 2379                 for (; 
i < 64; 
i++) {
 
 2381                     s->inter_matrix[j]        = last;
 
 2382                     s->chroma_inter_matrix[j] = last;
 
 2392             s->quarter_sample = 0;
 
 2401             int estimation_method = 
get_bits(gb, 2);
 
 2402             if (estimation_method < 2) {
 
 2417                 if (!
check_marker(
s->avctx, gb, 
"in complexity estimation part 1")) {
 
 2435                 if (!
check_marker(
s->avctx, gb, 
"in complexity estimation part 2")) {
 
 2439                 if (estimation_method == 1) {
 
 2445                        "Invalid Complexity estimation method %d\n",
 
 2450             ctx->cplx_estimation_trash_i =
 
 2451             ctx->cplx_estimation_trash_p =
 
 2452             ctx->cplx_estimation_trash_b = 0;
 
 2458         if (
s->data_partitioning)
 
 2461         if (vo_ver_id != 1) {
 
 2463             if (
ctx->new_pred) {
 
 2470                        "reduced resolution VOP not supported\n");
 
 2477         if (
ctx->scalability) {
 
 2479             int h_sampling_factor_n;
 
 2480             int h_sampling_factor_m;
 
 2481             int v_sampling_factor_n;
 
 2482             int v_sampling_factor_m;
 
 2487             h_sampling_factor_n = 
get_bits(gb, 5);
 
 2488             h_sampling_factor_m = 
get_bits(gb, 5);
 
 2489             v_sampling_factor_n = 
get_bits(gb, 5);
 
 2490             v_sampling_factor_m = 
get_bits(gb, 5);
 
 2493             if (h_sampling_factor_n == 0 || h_sampling_factor_m == 0 ||
 
 2494                 v_sampling_factor_n == 0 || v_sampling_factor_m == 0) {
 
 2497                 ctx->scalability = 0;
 
 2507         av_log(
s->avctx, 
AV_LOG_DEBUG, 
"tb %d/%d, tincrbits:%d, qp_prec:%d, ps:%d, low_delay:%d  %s%s%s%s\n",
 
 2508                s->avctx->framerate.den, 
s->avctx->framerate.num,
 
 2509                ctx->time_increment_bits,
 
 2511                s->progressive_sequence,
 
 2513                ctx->scalability ? 
"scalability " :
"" , 
s->quarter_sample ? 
"qpel " : 
"",
 
 2514                s->data_partitioning ? 
"partition " : 
"", 
ctx->rvlc ? 
"rvlc " : 
"" 
 2531     int ver = 0, build = 0, ver2 = 0, ver3 = 0;
 
 2542     e = sscanf(
buf, 
"DivX%dBuild%d%c", &ver, &build, &last);
 
 2544         e = sscanf(
buf, 
"DivX%db%d%c", &ver, &build, &last);
 
 2546         ctx->divx_version = ver;
 
 2547         ctx->divx_build   = build;
 
 2548         s->divx_packed  = e == 3 && last == 
'p';
 
 2552     e = sscanf(
buf, 
"FFmpe%*[^b]b%d", &build) + 3;
 
 2554         e = sscanf(
buf, 
"FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
 
 2556         e = sscanf(
buf, 
"Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1;
 
 2558             if (ver > 0xFFU || ver2 > 0xFFU || ver3 > 0xFFU) {
 
 2560                      "Unknown Lavc version string encountered, %d.%d.%d; " 
 2561                      "clamping sub-version values to 8-bits.\n",
 
 2564             build = ((ver & 0xFF) << 16) + ((ver2 & 0xFF) << 8) + (ver3 & 0xFF);
 
 2568         if (strcmp(
buf, 
"ffmpeg") == 0)
 
 2569             ctx->lavc_build = 4600;
 
 2572         ctx->lavc_build = build;
 
 2575     e = sscanf(
buf, 
"XviD%d", &build);
 
 2577         ctx->xvid_build = build;
 
 2587     if (
ctx->xvid_build == -1 && 
ctx->divx_version == -1 && 
ctx->lavc_build == -1) {
 
 2588         if (
s->codec_tag        == 
AV_RL32(
"XVID") ||
 
 2593             ctx->xvid_build = 0;
 
 2596     if (
ctx->xvid_build == -1 && 
ctx->divx_version == -1 && 
ctx->lavc_build == -1)
 
 2597         if (
s->codec_tag == 
AV_RL32(
"DIVX") && 
s->vo_type == 0 &&
 
 2598             ctx->vol_control_parameters == 0)
 
 2599             ctx->divx_version = 400;  
 
 2601     if (
ctx->xvid_build >= 0 && 
ctx->divx_version >= 0) {
 
 2603         ctx->divx_build   = -1;
 
 2607         if (
s->codec_tag == 
AV_RL32(
"XVIX"))
 
 2610         if (
s->codec_tag == 
AV_RL32(
"UMP4"))
 
 2613         if (
ctx->divx_version >= 500 && 
ctx->divx_build < 1814)
 
 2616         if (
ctx->divx_version > 502 && 
ctx->divx_build < 1814)
 
 2619         if (
ctx->xvid_build <= 3
U)
 
 2620             s->padding_bug_score = 256 * 256 * 256 * 64;
 
 2622         if (
ctx->xvid_build <= 1
U)
 
 2625         if (
ctx->xvid_build <= 12
U)
 
 2628         if (
ctx->xvid_build <= 32
U)
 
 2631 #define SET_QPEL_FUNC(postfix1, postfix2)                           \ 
 2632     s->qdsp.put_        ## postfix1 = ff_put_        ## postfix2;   \ 
 2633     s->qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2;   \ 
 2634     s->qdsp.avg_        ## postfix1 = ff_avg_        ## postfix2; 
 2636         if (
ctx->lavc_build < 4653
U)
 
 2639         if (
ctx->lavc_build < 4655
U)
 
 2642         if (
ctx->lavc_build < 4670
U)
 
 2645         if (
ctx->lavc_build <= 4712
U)
 
 2648         if ((
ctx->lavc_build&0xFF) >= 100) {
 
 2649             if (
ctx->lavc_build > 3621476 && 
ctx->lavc_build < 3752552 &&
 
 2650                (
ctx->lavc_build < 3752037 || 
ctx->lavc_build > 3752191) 
 
 2655         if (
ctx->divx_version >= 0)
 
 2657         if (
ctx->divx_version == 501 && 
ctx->divx_build == 20020416)
 
 2658             s->padding_bug_score = 256 * 256 * 256 * 64;
 
 2660         if (
ctx->divx_version < 500
U)
 
 2663         if (
ctx->divx_version >= 0)
 
 2685                "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
 
 2686                s->workaround_bugs, 
ctx->lavc_build, 
ctx->xvid_build,
 
 2687                ctx->divx_version, 
ctx->divx_build, 
s->divx_packed ? 
"p" : 
"");
 
 2689     if (CONFIG_MPEG4_DECODER && 
ctx->xvid_build >= 0 &&
 
 2703     int time_incr, time_increment;
 
 2715     if (
s->partitioned_frame)
 
 2726     if (
ctx->time_increment_bits == 0 ||
 
 2729                "time_increment_bits %d is invalid in relation to the current bitstream, this is likely caused by a missing VOL header\n", 
ctx->time_increment_bits);
 
 2731         for (
ctx->time_increment_bits = 1;
 
 2732              ctx->time_increment_bits < 16;
 
 2733              ctx->time_increment_bits++) {
 
 2737                 if ((
show_bits(gb, 
ctx->time_increment_bits + 6) & 0x37) == 0x30)
 
 2739             } 
else if ((
show_bits(gb, 
ctx->time_increment_bits + 5) & 0x1F) == 0x18)
 
 2744                "time_increment_bits set to %d bits, based on bitstream analysis\n", 
ctx->time_increment_bits);
 
 2745         if (
s->avctx->framerate.num && 4*
s->avctx->framerate.num < 1<<
ctx->time_increment_bits) {
 
 2746             s->avctx->framerate.num = 1<<
ctx->time_increment_bits;
 
 2754         time_increment = 
get_bits(gb, 
ctx->time_increment_bits);
 
 2757         s->last_time_base = 
s->time_base;
 
 2758         s->time_base     += time_incr;
 
 2759         s->time = 
s->time_base * (int64_t)
s->avctx->framerate.num + time_increment;
 
 2761             if (
s->time < 
s->last_non_b_time) {
 
 2765                 s->time += 
s->avctx->framerate.num;
 
 2768         s->pp_time         = 
s->time - 
s->last_non_b_time;
 
 2769         s->last_non_b_time = 
s->time;
 
 2771         s->time    = (
s->last_time_base + time_incr) * (int64_t)
s->avctx->framerate.num + time_increment;
 
 2772         s->pb_time = 
s->pp_time - (
s->last_non_b_time - 
s->time);
 
 2773         if (
s->pp_time <= 
s->pb_time ||
 
 2774             s->pp_time <= 
s->pp_time - 
s->pb_time ||
 
 2781         if (
ctx->t_frame == 0)
 
 2782             ctx->t_frame = 
s->pb_time;
 
 2783         if (
ctx->t_frame == 0)
 
 2789         if (
s->pp_field_time <= 
s->pb_field_time || 
s->pb_field_time <= 1) {
 
 2790             s->pb_field_time = 2;
 
 2791             s->pp_field_time = 4;
 
 2792             if (!
s->progressive_sequence)
 
 2797     if (
s->avctx->framerate.den)
 
 2855         if (!
s->progressive_sequence) {
 
 2859             s->alternate_scan = 0;
 
 2862     if (
s->alternate_scan) {
 
 2879             if (
ctx->sprite_brightness_change)
 
 2881                     "sprite_brightness_change not supported\n");
 
 2885             memset(
s->sprite_offset, 0, 
sizeof(
s->sprite_offset));
 
 2886             memset(
s->sprite_delta, 0, 
sizeof(
s->sprite_delta));
 
 2891         s->chroma_qscale = 
s->qscale = 
get_bits(gb, 
s->quant_precision);
 
 2892         if (
s->qscale == 0) {
 
 2894                    "Error, header damaged or not MPEG-4 header (qscale=0)\n");
 
 2900             if (
s->f_code == 0) {
 
 2902                        "Error, header damaged or not MPEG-4 header (f_code=0)\n");
 
 2911             if (
s->b_code == 0) {
 
 2913                        "Error, header damaged or not MPEG4 header (b_code=0)\n");
 
 2922                    "qp:%d fc:%d,%d %s size:%d pro:%d alt:%d top:%d %spel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d time:%"PRId64
" tincr:%d\n",
 
 2923                    s->qscale, 
s->f_code, 
s->b_code,
 
 2926                    s->top_field_first, 
s->quarter_sample ? 
"q" : 
"h",
 
 2927                    s->data_partitioning, 
ctx->resync_marker,
 
 2928                    ctx->num_sprite_warping_points, 
s->sprite_warping_accuracy,
 
 2929                    1 - 
s->no_rounding, 
s->vo_type,
 
 2930                    ctx->vol_control_parameters ? 
" VOLC" : 
" ", 
ctx->intra_dc_threshold,
 
 2931                    ctx->cplx_estimation_trash_i, 
ctx->cplx_estimation_trash_p,
 
 2932                    ctx->cplx_estimation_trash_b,
 
 2938         if (!
ctx->scalability) {
 
 2942             if (
ctx->enhancement_type) {
 
 2943                 int load_backward_shape = 
get_bits1(gb);
 
 2944                 if (load_backward_shape)
 
 2946                            "load backward shape isn't supported\n");
 
 2954     if (
s->vo_type == 0 && 
ctx->vol_control_parameters == 0 &&
 
 2955         ctx->divx_version == -1 && 
s->picture_number == 0) {
 
 2957                "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
 
 2961     s->picture_number++;  
 
 2968         s->h_edge_pos = 
s->width;
 
 2969         s->v_edge_pos = 
s->height;
 
 2982         for (
i = 0; 
i < 64; 
i++) {
 
 2985             s->intra_matrix[j]        = v;
 
 2986             s->chroma_intra_matrix[j] = v;
 
 2994         for (
i = 0; 
i < 64; 
i++) {
 
 3003         for (
i = 0; 
i < 64; 
i++) {
 
 3006             s->chroma_intra_matrix[j] = v;
 
 3014         for (
i = 0; 
i < 64; 
i++) {
 
 3066     s->partitioned_frame = 0;
 
 3067     s->interlaced_dct = 0;
 
 3090         s->intra_dc_precision = 
get_bits(gb, 2);
 
 3094     if (
s->alternate_scan) {
 
 3117     int visual_object_type;
 
 3120         visual_object_type = 
get_bits(gb, 4);
 
 3136     int bits_per_raw_sample;
 
 3137     int rgb, chroma_format;
 
 3157                 bits_per_raw_sample = 
get_bits(gb, 4); 
 
 3158                 if (bits_per_raw_sample == 10) {
 
 3170                 if (rgb != 
ctx->rgb || 
s->chroma_format != chroma_format)
 
 3171                     s->context_reinit = 1;
 
 3172                 s->avctx->bits_per_raw_sample = bits_per_raw_sample;
 
 3174                 s->chroma_format = chroma_format;
 
 3177                 check_marker(
s->avctx, gb, 
"before video_object_layer_width");
 
 3179                 check_marker(
s->avctx, gb, 
"before video_object_layer_height");
 
 3181                 check_marker(
s->avctx, gb, 
"after video_object_layer_height");
 
 3185                     if (
s->width && 
s->height &&
 
 3187                         s->context_reinit = 1;
 
 3194                 s->avctx->sample_aspect_ratio.num = 
get_bits(gb, 8);  
 
 3195                 s->avctx->sample_aspect_ratio.den = 
get_bits(gb, 8);  
 
 3205             check_marker(
s->avctx, gb, 
"after first_half_vbv_buffer_size");
 
 3208             check_marker(
s->avctx, gb, 
"after first_half_vbv_buffer_size");
 
 3210             check_marker(
s->avctx, gb, 
"after latter_half_vbv_occupancy");
 
 3231     unsigned startcode, v;
 
 3241     if (!
s->studio_profile && 
s->avctx->bits_per_raw_sample != 8)
 
 3242         s->avctx->bits_per_raw_sample = 0;
 
 3254                 (
ctx->divx_version >= 0 || 
ctx->xvid_build >= 0) || 
s->codec_tag == 
AV_RL32(
"QMP4")) {
 
 3265         startcode = ((startcode << 8) | v) & 0xffffffff;
 
 3267         if ((startcode & 0xFFFFFF00) != 0x100)
 
 3272             if (startcode <= 0x11F)
 
 3274             else if (startcode <= 0x12F)
 
 3276             else if (startcode <= 0x13F)
 
 3278             else if (startcode <= 0x15F)
 
 3280             else if (startcode <= 0x1AF)
 
 3282             else if (startcode == 0x1B0)
 
 3284             else if (startcode == 0x1B1)
 
 3286             else if (startcode == 0x1B2)
 
 3288             else if (startcode == 0x1B3)
 
 3290             else if (startcode == 0x1B4)
 
 3292             else if (startcode == 0x1B5)
 
 3294             else if (startcode == 0x1B6)
 
 3296             else if (startcode == 0x1B7)
 
 3298             else if (startcode == 0x1B8)
 
 3300             else if (startcode == 0x1B9)
 
 3302             else if (startcode == 0x1BA)
 
 3304             else if (startcode == 0x1BB)
 
 3306             else if (startcode == 0x1BC)
 
 3308             else if (startcode == 0x1BD)
 
 3310             else if (startcode == 0x1BE)
 
 3312             else if (startcode == 0x1BF)
 
 3314             else if (startcode == 0x1C0)
 
 3316             else if (startcode == 0x1C1)
 
 3318             else if (startcode == 0x1C2)
 
 3320             else if (startcode == 0x1C3)
 
 3322             else if (startcode <= 0x1C5)
 
 3324             else if (startcode <= 0x1FF)
 
 3329         if (startcode >= 0x120 && startcode <= 0x12F) {
 
 3346                 s->studio_profile = 1;
 
 3349             } 
else if (
s->studio_profile) {
 
 3356             if (
s->studio_profile) {
 
 3372     s->avctx->has_b_frames = !
s->low_delay;
 
 3374     if (
s->studio_profile) {
 
 3375         if (!
s->avctx->bits_per_raw_sample) {
 
 3385     static int done = 0;
 
 3418     if (
s->divx_packed) {
 
 3419         int current_pos     = 
s->gb.buffer == 
s->bitstream_buffer ? 0 : (
get_bits_count(&
s->gb) >> 3);
 
 3420         int startcode_found = 0;
 
 3422         if (buf_size - current_pos > 7) {
 
 3425             for (
i = current_pos; 
i < buf_size - 4; 
i++)
 
 3430                     buf[
i + 3] == 0xB6) {
 
 3431                     startcode_found = !(
buf[
i + 4] & 0x40);
 
 3436         if (startcode_found) {
 
 3437             if (!
ctx->showed_packed_warning) {
 
 3439                        "wasteful way to store B-frames ('packed B-frames'). " 
 3440                        "Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it.\n");
 
 3441                 ctx->showed_packed_warning = 1;
 
 3444                            &
s->allocated_bitstream_buffer_size,
 
 3445                            buf_size - current_pos);
 
 3446             if (!
s->bitstream_buffer) {
 
 3447                 s->bitstream_buffer_size = 0;
 
 3450             memcpy(
s->bitstream_buffer, 
buf + current_pos,
 
 3451                    buf_size - current_pos);
 
 3452             s->bitstream_buffer_size = buf_size - current_pos;
 
 3465     int init = 
s->m.context_initialized;
 
 3474     if (CONFIG_MPEG4_DECODER && !
init && 
s1->xvid_build >= 0)
 
 3485     for (
i = 0; 
i < 12; 
i++) {
 
 3521     ctx->lavc_build   = -1;
 
 3533     ctx->time_increment_bits = 4; 
 
 3547         for (
i = 0; 
i < 12; 
i++)
 
 3590 #if CONFIG_MPEG4_NVDEC_HWACCEL 
 3593 #if CONFIG_MPEG4_VAAPI_HWACCEL 
 3596 #if CONFIG_MPEG4_VDPAU_HWACCEL 
 3599 #if CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL 
  
av_cold void ff_mpeg4videodec_static_init(void)
#define HWACCEL_NVDEC(codec)
const AVProfile ff_mpeg4_video_profiles[]
#define MV_TYPE_16X16
1 vector for the whole mb
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
static const AVClass mpeg4_class
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
#define FF_ASPECT_EXTENDED
#define VISUAL_OBJ_STARTCODE
static av_cold int init(AVCodecContext *avctx)
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 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
av_cold void ff_xvid_idct_init(IDCTDSPContext *c, AVCodecContext *avctx)
static const uint8_t mpeg4_block_count[4]
static int mpeg_get_qscale(MpegEncContext *s)
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
static int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, int n, int coded, int intra, int rvlc)
Decode a block.
static int get_bits_count(const GetBitContext *s)
static const uint8_t ac_state_tab[22][2]
const uint16_t ff_sprite_trajectory_tab[15][2]
#define MV_DIRECT
bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
static av_cold int end(AVCodecContext *avctx)
#define AV_CODEC_CAP_TRUNCATED
@ AVCOL_RANGE_JPEG
the normal 2^n-1 "JPEG" YUV ranges
static int mpeg4_decode_studio_mb(MpegEncContext *s, int16_t block_[12][64])
#define ADV_SIMPLE_VO_TYPE
int ff_mpeg4_decode_studio_slice_header(Mpeg4DecContext *ctx)
Decode the next video packet.
#define init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
static int mpeg4_decode_gop_header(MpegEncContext *s, GetBitContext *gb)
static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define AV_LOG_VERBOSE
Detailed information.
void ff_clean_intra_table_entries(MpegEncContext *s)
Clean dc, ac, coded_block for the current non-intra MB.
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
void ff_init_block_index(MpegEncContext *s)
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
#define UPDATE_CACHE(name, gb)
#define FF_BUG_HPEL_CHROMA
static void decode_smpte_tc(Mpeg4DecContext *ctx, GetBitContext *gb)
#define FF_PROFILE_MPEG4_SIMPLE_STUDIO
static int mpeg4_decode_visual_object(MpegEncContext *s, GetBitContext *gb)
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before ff_thread_await_progress() has been called on them. reget_buffer() and buffer age optimizations no longer work. *The contents of buffers must not be written to after ff_thread_report_progress() has been called on them. This includes draw_edges(). Porting codecs to frame threading
const uint16_t ff_mpeg4_resync_prefix[8]
const uint16_t ff_mpeg4_studio_dc_chroma[19][2]
#define FF_DEBUG_PICT_INFO
#define GET_CACHE(name, gb)
#define VOT_STILL_TEXTURE_ID
static void skip_bits(GetBitContext *s, int n)
int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
int is_copy
Whether the parent AVCodecContext is a copy of the context which had init() called on it.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
const uint8_t ff_mpeg4_DCtab_chrom[13][2]
static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb)
Decode the user data stuff in the header.
#define SKIP_CACHE(name, gb, num)
static int get_amv(Mpeg4DecContext *ctx, int n)
Get the average motion vector for a GMC MB.
#define INTRA_MCBPC_VLC_BITS
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
const uint16_t ff_mpeg4_studio_intra[12][22][2]
VLC ff_h263_intra_MCBPC_vlc
#define MB_TYPE_B_VLC_BITS
#define STUDIO_INTRA_BITS
#define FF_BUG_QPEL_CHROMA2
#define AV_PIX_FMT_GBRP10
void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir)
Predict the ac.
const AVRational ff_h263_pixel_aspect[16]
int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s)
#define CORE_STUDIO_VO_TYPE
#define USES_LIST(a, list)
static int mpeg4_decode_profile_level(MpegEncContext *s, GetBitContext *gb, int *profile, int *level)
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
#define SLICE_END
end marker found
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
#define AV_PIX_FMT_YUV444P10
#define AV_EF_BITSTREAM
detect bitstream specification deviations
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx)
Decode the first and second partition.
static void extension_and_user_data(MpegEncContext *s, GetBitContext *gb, int id)
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
#define CLOSE_READER(name, gb)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
int8_t * max_level[2]
encoding & decoding
int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header)
Decode MPEG-4 headers.
#define SHOW_SBITS(name, gb, num)
#define FF_BUG_NO_PADDING
RLTable ff_mpeg4_rl_intra
#define FF_PROFILE_UNKNOWN
static enum AVPixelFormat pix_fmts[]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
#define SKIP_BITS(name, gb, num)
void ff_free_vlc(VLC *vlc)
#define FF_BUG_DIRECT_BLOCKSIZE
static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *gb)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
const uint8_t ff_mpeg4_DCtab_lum[13][2]
#define FRAME_SKIPPED
Return value for header parsers if frame is not coded.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
static av_cold int decode_end(AVCodecContext *avctx)
static const int mb_type_b_map[4]
#define LIBAVUTIL_VERSION_INT
static void mpeg4_load_default_matrices(MpegEncContext *s)
Describe the class of an AVClass context structure.
static void flush(AVCodecContext *avctx)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
av_cold void ff_mpv_idct_init(MpegEncContext *s)
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Rational number (pair of numerator and denominator).
static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64])
decode partition C of one MB.
static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n)
struct AVCodecInternal * internal
Private context used for internal data.
#define SLICE_NOEND
no end marker or error found but mb count exceeded
enum AVPixelFormat ff_h263_hwaccel_pixfmt_list_420[]
#define ROUNDED_DIV(a, b)
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
static unsigned int get_bits1(GetBitContext *s)
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
#define LAST_SKIP_BITS(name, gb, num)
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
#define SET_QPEL_FUNC(postfix1, postfix2)
const uint8_t ff_alternate_horizontal_scan[64]
#define AV_PIX_FMT_YUV422P10
const uint8_t ff_mpeg4_dc_threshold[8]
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
#define MV_TYPE_8X8
4 vectors (H.263, MPEG-4 4MV)
static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
Decode first partition.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int ff_h263_decode_motion(MpegEncContext *s, int pred, int f_code)
#define AV_EF_IGNORE_ERR
ignore errors and continue
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.
const uint8_t ff_mpeg4_y_dc_scale_table[32]
static int ff_mpeg4_pred_dc(MpegEncContext *s, int n, int level, int *dir_ptr, int encoding)
Predict the dc.
int allocate_progress
Whether to allocate progress for frame threading.
const int16_t ff_mpeg4_default_intra_matrix[64]
static int read_quant_matrix_ext(MpegEncContext *s, GetBitContext *gb)
#define AV_NOPTS_VALUE
Undefined timestamp value.
void ff_mpeg_flush(AVCodecContext *avctx)
static const uint8_t header[24]
#define MB_TYPE_INTERLACED
#define OPEN_READER(name, gb)
#define INTER_MCBPC_VLC_BITS
uint8_t ff_mpeg4_static_rl_table_store[3][2][2 *MAX_RUN+MAX_LEVEL+3]
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
const int16_t ff_mpeg4_default_non_intra_matrix[64]
int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
#define MV_TYPE_FIELD
2 vectors, one per field
static int get_xbits(GetBitContext *s, int n)
Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
static void skip_bits1(GetBitContext *s)
#define AV_LOG_INFO
Standard information.
static void ff_update_block_index(MpegEncContext *s)
static av_cold int init_studio_vlcs(Mpeg4DecContext *ctx)
int ff_h263_decode_init(AVCodecContext *avctx)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr)
Decode the dc value.
#define SKIP_COUNTER(name, gb, num)
#define i(width, name, range_min, range_max)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
const uint8_t ff_alternate_vertical_scan[64]
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
int8_t * max_run[2]
encoding & decoding
int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx)
Decode the next video packet.
int ff_h263_decode_end(AVCodecContext *avctx)
#define SIMPLE_STUDIO_VO_TYPE
#define FF_BUG_AUTODETECT
autodetection
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...
#define FF_DEBUG_STARTCODE
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
const char * name
Name of the codec implementation.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
#define USER_DATA_STARTCODE
#define FF_BUG_QPEL_CHROMA
@ AVCOL_RANGE_MPEG
the normal 219*2^(n-8) "MPEG" YUV ranges
#define SPRITE_TRAJ_VLC_BITS
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
const uint8_t ff_zigzag_direct[64]
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static const uint8_t * align_get_bits(GetBitContext *s)
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
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
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
main external API structure.
#define HWACCEL_VAAPI(codec)
static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count)
decode second partition.
#define SHOW_UBITS(name, gb, num)
const uint8_t ff_mb_type_b_tab[4][2]
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
av_cold int ff_rl_init(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
static const AVOption mpeg4_options[]
static const AVProfile profiles[]
#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 decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
#define AV_EF_AGGRESSIVE
consider things that a sane encoder should not do as an error
static int mpeg4_is_resync(Mpeg4DecContext *ctx)
check if the next stuff is a resync marker or the end.
static int shift(int a, int b)
#define INIT_VLC_RL(rl, static_size)
static int mpeg4_decode_dpcm_macroblock(MpegEncContext *s, int16_t macroblock[256], int n)
@ AV_PICTURE_TYPE_P
Predicted.
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
Undefined Behavior In the C some operations are like signed integer overflow
#define FF_BUG_XVID_ILACE
#define avpriv_request_sample(...)
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static void reset_studio_dc_predictors(MpegEncContext *s)
const uint8_t ff_mpeg4_c_dc_scale_table[32]
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
#define QUANT_MATRIX_EXT_ID
static void next_start_code_studio(GetBitContext *gb)
static const int16_t alpha[]
static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
Decode the next studio vop header.
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
The exact code depends on how similar the blocks are and how related they are to the block
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
const uint16_t ff_mpeg4_studio_dc_luma[19][2]
static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb)
static av_cold int decode_init(AVCodecContext *avctx)
static VLC sprite_trajectory
@ AV_PICTURE_TYPE_S
S(GMC)-VOP MPEG-4.
VLC_TYPE(* table)[2]
code, bits
#define HWACCEL_VDPAU(codec)
RL_VLC_ELEM * rl_vlc[32]
decoding only
VLC ff_h263_inter_MCBPC_vlc