ff_reget_buffer() will attempt to create a writable copy of the frame, which is not needed when the decoder intends to return a reference to the same buffer as the previous frame. Should reduce data copy, hopefully achieving a similar speed up as a9dacdeea6168787a142209bd19fdd74aefc9dd6 without dropping frames.
Unified · Split
| @@ -452,15 +452,16 @@ static int qtrle_decode_frame(AVCodecContext *avctx, · 451 unmodified lines | ||
| 452 | 452 | int header, start_line; |
| 453 | 453 | int height, row_ptr; |
| 454 | 454 | int has_palette = 0; |
| 455 | + int duplicate = 0; | |
| 455 | 456 | int ret, size; |
| 456 | 457 | |
| 457 | 458 | bytestream2_init(&s->g, avpkt->data, avpkt->size); |
| 458 | − if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) | |
| 459 | − return ret; | |
| 460 | 459 | |
| 461 | 460 | /* check if this frame is even supposed to change */ |
| 462 | − if (avpkt->size < 8) | |
| 461 | + if (avpkt->size < 8) { | |
| 462 | + duplicate = 1; | |
| 463 | 463 | goto done; |
| 464 | + } | |
| 464 | 465 | |
| 465 | 466 | /* start after the chunk size */ |
| 466 | 467 | size = bytestream2_get_be32(&s->g) & 0x3FFFFFFF; |
| @@ -473,18 +474,25 @@ static int qtrle_decode_frame(AVCodecContext *avctx, · 6 unmodified lines | ||
| 473 | 474 | |
| 474 | 475 | /* if a header is present, fetch additional decoding parameters */ |
| 475 | 476 | if (header & 0x0008) { |
| 476 | − if (avpkt->size < 14) | |
| 477 | + if (avpkt->size < 14) { | |
| 478 | + duplicate = 1; | |
| 477 | 479 | goto done; |
| 480 | + } | |
| 478 | 481 | start_line = bytestream2_get_be16(&s->g); |
| 479 | 482 | bytestream2_skip(&s->g, 2); |
| 480 | 483 | height = bytestream2_get_be16(&s->g); |
| 481 | 484 | bytestream2_skip(&s->g, 2); |
| 482 | − if (height > s->avctx->height - start_line) | |
| 485 | + if (height > s->avctx->height - start_line) { | |
| 486 | + duplicate = 1; | |
| 483 | 487 | goto done; |
| 488 | + } | |
| 484 | 489 | } else { |
| 485 | 490 | start_line = 0; |
| 486 | 491 | height = s->avctx->height; |
| 487 | 492 | } |
| 493 | + if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) | |
| 494 | + return ret; | |
| 495 | + | |
| 488 | 496 | row_ptr = s->frame->linesize[0] * start_line; |
| 489 | 497 | |
| 490 | 498 | switch (avctx->bits_per_coded_sample) { |
| @@ -546,6 +554,16 @@ static int qtrle_decode_frame(AVCodecContext *avctx, · 55 unmodified lines | ||
| 546 | 554 | } |
| 547 | 555 | |
| 548 | 556 | done: |
| 557 | + if (!s->frame->data[0]) | |
| 558 | + return AVERROR_INVALIDDATA; | |
| 559 | + if (duplicate) { | |
| 560 | + // ff_reget_buffer() isn't needed when frames don't change, so just update | |
| 561 | + // frame props. | |
| 562 | + ret = ff_decode_frame_props(avctx, s->frame); | |
| 563 | + if (ret < 0) | |
| 564 | + return ret; | |
| 565 | + } | |
| 566 | + | |
| 549 | 567 | if ((ret = av_frame_ref(data, s->frame)) < 0) |
| 550 | 568 | return ret; |
| 551 | 569 | *got_frame = 1; |