Skip to content

Commit 88cccd1

Browse files
committed
avcodec/flashsv: Avoid copying packet
Signed-off-by: Andreas Rheinhardt <[email protected]>
1 parent c3fea6d commit 88cccd1

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

libavcodec/flashsv.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include "internal.h"
4545

4646
typedef struct BlockInfo {
47-
uint8_t *pos;
47+
const uint8_t *pos;
4848
int size;
4949
} BlockInfo;
5050

@@ -59,7 +59,8 @@ typedef struct FlashSVContext {
5959
int ver;
6060
const uint32_t *pal;
6161
int is_keyframe;
62-
uint8_t *keyframedata;
62+
const uint8_t *keyframedata;
63+
AVBufferRef *keyframedata_buf;
6364
uint8_t *keyframe;
6465
BlockInfo *blocks;
6566
uint8_t *deflate_block;
@@ -138,7 +139,7 @@ static av_cold int flashsv_decode_init(AVCodecContext *avctx)
138139
return 0;
139140
}
140141

141-
static int flashsv2_prime(FlashSVContext *s, uint8_t *src, int size)
142+
static int flashsv2_prime(FlashSVContext *s, const uint8_t *src, int size)
142143
{
143144
z_stream zs;
144145
int zret; // Zlib return code
@@ -355,10 +356,10 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data,
355356
/* we care for keyframes only in Screen Video v2 */
356357
s->is_keyframe = (avpkt->flags & AV_PKT_FLAG_KEY) && (s->ver == 2);
357358
if (s->is_keyframe) {
358-
int err;
359-
if ((err = av_reallocp(&s->keyframedata, avpkt->size)) < 0)
359+
int err = av_buffer_replace(&s->keyframedata_buf, avpkt->buf);
360+
if (err < 0)
360361
return err;
361-
memcpy(s->keyframedata, avpkt->data, avpkt->size);
362+
s->keyframedata = avpkt->data;
362363
}
363364
if(s->ver == 2 && !s->blocks)
364365
s->blocks = av_mallocz((v_blocks + !!v_part) * (h_blocks + !!h_part) *
@@ -566,7 +567,7 @@ static av_cold int flashsv2_decode_end(AVCodecContext *avctx)
566567
{
567568
FlashSVContext *s = avctx->priv_data;
568569

569-
av_freep(&s->keyframedata);
570+
av_buffer_unref(&s->keyframedata_buf);
570571
av_freep(&s->blocks);
571572
av_freep(&s->keyframe);
572573
av_freep(&s->deflate_block);

0 commit comments

Comments
 (0)