History

avcodec/qtrle: call ff_reget_buffer() only when the picture data is going to change

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.

James Almer committed 7 years ago

Commit d70bbdc1 parent 8b71cc31 file · +23 −5Browse files

Unified · Split

libavcodec/qtrle.c+23−5
@@ -452,15 +452,16 @@ static int qtrle_decode_frame(AVCodecContext *avctx, · 451 unmodified lines
452452 int header, start_line;
453453 int height, row_ptr;
454454 int has_palette = 0;
455+ int duplicate = 0;
455456 int ret, size;
456457
457458 bytestream2_init(&s->g, avpkt->data, avpkt->size);
458− if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
459− return ret;
460459
461460 /* check if this frame is even supposed to change */
462− if (avpkt->size < 8)
461+ if (avpkt->size < 8) {
462+ duplicate = 1;
463463 goto done;
464+ }
464465
465466 /* start after the chunk size */
466467 size = bytestream2_get_be32(&s->g) & 0x3FFFFFFF;
@@ -473,18 +474,25 @@ static int qtrle_decode_frame(AVCodecContext *avctx, · 6 unmodified lines
473474
474475 /* if a header is present, fetch additional decoding parameters */
475476 if (header & 0x0008) {
476− if (avpkt->size < 14)
477+ if (avpkt->size < 14) {
478+ duplicate = 1;
477479 goto done;
480+ }
478481 start_line = bytestream2_get_be16(&s->g);
479482 bytestream2_skip(&s->g, 2);
480483 height = bytestream2_get_be16(&s->g);
481484 bytestream2_skip(&s->g, 2);
482− if (height > s->avctx->height - start_line)
485+ if (height > s->avctx->height - start_line) {
486+ duplicate = 1;
483487 goto done;
488+ }
484489 } else {
485490 start_line = 0;
486491 height = s->avctx->height;
487492 }
493+ if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
494+ return ret;
495+
488496 row_ptr = s->frame->linesize[0] * start_line;
489497
490498 switch (avctx->bits_per_coded_sample) {
@@ -546,6 +554,16 @@ static int qtrle_decode_frame(AVCodecContext *avctx, · 55 unmodified lines
546554 }
547555
548556 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+
549567 if ((ret = av_frame_ref(data, s->frame)) < 0)
550568 return ret;
551569 *got_frame = 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t