While it offers modest speedups compared to the ordinary code, removing it completely offers even bigger speedups; and given that these speedups also exist in the ordinary mode, they are even more important. The no-output code has a 7.8% performance improvement (based on benchmarking mpeg4_encode_mb()), yet removing the no-output code resulted in a 9.4% improvement. Furthermore, the no-output code was broken for the majority of its existence (until 9207dc3b0db368bb9cf5eb295cbc1129c2975e31) and no one complained, so it is likely not used at all.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -292,14 +292,6 @@ static inline void mpeg4_encode_dc(PutBitContext *s, int level, int n) · 291 unmodified lines | ||
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | −static inline int mpeg4_get_dc_length(int level, int n) | |
| 296 | −{ | |
| 297 | − if (n < 4) | |
| 298 | − return uni_DCtab_lum_len[level + 256]; | |
| 299 | − else | |
| 300 | − return uni_DCtab_chrom_len[level + 256]; | |
| 301 | −} | |
| 302 | − | |
| 303 | 295 | /** |
| 304 | 296 | * Encode an 8x8 block. |
| 305 | 297 | * @param n block index (0-3 are luma, 4-5 are chroma) |
| @@ -365,60 +357,6 @@ static inline void mpeg4_encode_block(const MPVEncContext *const s, · 59 unmodified lines | ||
| 365 | 357 | } |
| 366 | 358 | } |
| 367 | 359 | |
| 368 | −static int mpeg4_get_block_length(MPVEncContext *const s, | |
| 369 | − const int16_t *block, int n, | |
| 370 | − int intra_dc, const uint8_t *scan_table) | |
| 371 | −{ | |
| 372 | − int i, last_non_zero; | |
| 373 | − const uint8_t *len_tab; | |
| 374 | − const int last_index = s->c.block_last_index[n]; | |
| 375 | − int len = 0; | |
| 376 | − | |
| 377 | − if (s->c.mb_intra) { // Note gcc (3.2.1 at least) will optimize this away | |
| 378 | − /* MPEG-4 based DC predictor */ | |
| 379 | − len += mpeg4_get_dc_length(intra_dc, n); | |
| 380 | − if (last_index < 1) | |
| 381 | − return len; | |
| 382 | − i = 1; | |
| 383 | − len_tab = uni_mpeg4_intra_rl_len; | |
| 384 | − } else { | |
| 385 | − if (last_index < 0) | |
| 386 | − return 0; | |
| 387 | − i = 0; | |
| 388 | − len_tab = uni_mpeg4_inter_rl_len; | |
| 389 | − } | |
| 390 | − | |
| 391 | − /* AC coefs */ | |
| 392 | − last_non_zero = i - 1; | |
| 393 | − for (; i < last_index; i++) { | |
| 394 | − int level = block[scan_table[i]]; | |
| 395 | − if (level) { | |
| 396 | − int run = i - last_non_zero - 1; | |
| 397 | − level += 64; | |
| 398 | − if ((level & (~127)) == 0) { | |
| 399 | − const int index = UNI_MPEG4_ENC_INDEX(0, run, level); | |
| 400 | − len += len_tab[index]; | |
| 401 | − } else { // ESC3 | |
| 402 | − len += 7 + 2 + 1 + 6 + 1 + 12 + 1; | |
| 403 | − } | |
| 404 | − last_non_zero = i; | |
| 405 | − } | |
| 406 | − } | |
| 407 | − /* if (i <= last_index) */ { | |
| 408 | − int level = block[scan_table[i]]; | |
| 409 | − int run = i - last_non_zero - 1; | |
| 410 | − level += 64; | |
| 411 | − if ((level & (~127)) == 0) { | |
| 412 | − const int index = UNI_MPEG4_ENC_INDEX(1, run, level); | |
| 413 | − len += len_tab[index]; | |
| 414 | − } else { // ESC3 | |
| 415 | − len += 7 + 2 + 1 + 6 + 1 + 12 + 1; | |
| 416 | − } | |
| 417 | − } | |
| 418 | − | |
| 419 | − return len; | |
| 420 | −} | |
| 421 | − | |
| 422 | 360 | static inline void mpeg4_encode_blocks(MPVEncContext *const s, |
| 423 | 361 | const int16_t block[6][64], |
| 424 | 362 | const int intra_dc[6], |
| @@ -429,29 +367,15 @@ static inline void mpeg4_encode_blocks(MPVEncContext *const s, · 4 unmodified lines | ||
| 429 | 367 | int i; |
| 430 | 368 | |
| 431 | 369 | if (scan_table) { |
| 432 | − if (s->c.avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT) { | |
| 433 | − for (i = 0; i < 6; i++) | |
| 434 | − skip_put_bits(&s->pb, | |
| 435 | − mpeg4_get_block_length(s, block[i], i, | |
| 436 | − intra_dc[i], scan_table[i])); | |
| 437 | − } else { | |
| 438 | 370 | /* encode each block */ |
| 439 | 371 | for (i = 0; i < 6; i++) |
| 440 | 372 | mpeg4_encode_block(s, block[i], i, |
| 441 | 373 | intra_dc[i], scan_table[i], dc_pb, ac_pb); |
| 442 | − } | |
| 443 | 374 | } else { |
| 444 | − if (s->c.avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT) { | |
| 445 | − for (i = 0; i < 6; i++) | |
| 446 | − skip_put_bits(&s->pb, | |
| 447 | − mpeg4_get_block_length(s, block[i], i, 0, | |
| 448 | − s->c.intra_scantable.permutated)); | |
| 449 | − } else { | |
| 450 | 375 | /* encode each block */ |
| 451 | 376 | for (i = 0; i < 6; i++) |
| 452 | 377 | mpeg4_encode_block(s, block[i], i, 0, |
| 453 | 378 | s->c.intra_scantable.permutated, dc_pb, ac_pb); |
| 454 | − } | |
| 455 | 379 | } |
| 456 | 380 | } |
| 457 | 381 | |