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 | int header, start_line; | 452 | int header, start_line; |
| 453 | int height, row_ptr; | 453 | int height, row_ptr; |
| 454 | int has_palette = 0; | 454 | int has_palette = 0; |
| 455 | int duplicate = 0; | ||
| 455 | int ret, size; | 456 | int ret, size; |
| 456 | 457 | ||
| 457 | bytestream2_init(&s->g, avpkt->data, avpkt->size); | 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 | /* check if this frame is even supposed to change */ | 460 | /* check if this frame is even supposed to change */ |
| 462 | if (avpkt->size < 8) | 461 | if (avpkt->size < 8) { |
| 462 | duplicate = 1; | ||
| 463 | goto done; | 463 | goto done; |
| 464 | } | ||
| 464 | 465 | ||
| 465 | /* start after the chunk size */ | 466 | /* start after the chunk size */ |
| 466 | size = bytestream2_get_be32(&s->g) & 0x3FFFFFFF; | 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 | /* if a header is present, fetch additional decoding parameters */ | 475 | /* if a header is present, fetch additional decoding parameters */ |
| 475 | if (header & 0x0008) { | 476 | if (header & 0x0008) { |
| 476 | if (avpkt->size < 14) | 477 | if (avpkt->size < 14) { |
| 478 | duplicate = 1; | ||
| 477 | goto done; | 479 | goto done; |
| 480 | } | ||
| 478 | start_line = bytestream2_get_be16(&s->g); | 481 | start_line = bytestream2_get_be16(&s->g); |
| 479 | bytestream2_skip(&s->g, 2); | 482 | bytestream2_skip(&s->g, 2); |
| 480 | height = bytestream2_get_be16(&s->g); | 483 | height = bytestream2_get_be16(&s->g); |
| 481 | bytestream2_skip(&s->g, 2); | 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 | goto done; | 487 | goto done; |
| 488 | } | ||
| 484 | } else { | 489 | } else { |
| 485 | start_line = 0; | 490 | start_line = 0; |
| 486 | height = s->avctx->height; | 491 | height = s->avctx->height; |
| 487 | } | 492 | } |
| 493 | if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) | ||
| 494 | return ret; | ||
| 495 | |||
| 488 | row_ptr = s->frame->linesize[0] * start_line; | 496 | row_ptr = s->frame->linesize[0] * start_line; |
| 489 | 497 | ||
| 490 | switch (avctx->bits_per_coded_sample) { | 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 | done: | 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 | if ((ret = av_frame_ref(data, s->frame)) < 0) | 567 | if ((ret = av_frame_ref(data, s->frame)) < 0) |
| 550 | return ret; | 568 | return ret; |
| 551 | *got_frame = 1; | 569 | *got_frame = 1; |