avcodec/rpza: Move frame allocation to a later point
This will allow performing some fast checks before the slow allocation Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
@@ -73,13 +73,12 @@ typedef struct RpzaContext {
|
|||||||
static int rpza_decode_stream(RpzaContext *s)
|
static int rpza_decode_stream(RpzaContext *s)
|
||||||
{
|
{
|
||||||
int width = s->avctx->width;
|
int width = s->avctx->width;
|
||||||
int stride = s->frame->linesize[0] / 2;
|
int stride, row_inc, ret;
|
||||||
int row_inc = stride - 4;
|
|
||||||
int chunk_size;
|
int chunk_size;
|
||||||
uint16_t colorA = 0, colorB;
|
uint16_t colorA = 0, colorB;
|
||||||
uint16_t color4[4];
|
uint16_t color4[4];
|
||||||
uint16_t ta, tb;
|
uint16_t ta, tb;
|
||||||
uint16_t *pixels = (uint16_t *)s->frame->data[0];
|
uint16_t *pixels;
|
||||||
|
|
||||||
int row_ptr = 0;
|
int row_ptr = 0;
|
||||||
int pixel_ptr = 0;
|
int pixel_ptr = 0;
|
||||||
@@ -106,6 +105,12 @@ static int rpza_decode_stream(RpzaContext *s)
|
|||||||
/* Number of 4x4 blocks in frame. */
|
/* Number of 4x4 blocks in frame. */
|
||||||
total_blocks = ((s->avctx->width + 3) / 4) * ((s->avctx->height + 3) / 4);
|
total_blocks = ((s->avctx->width + 3) / 4) * ((s->avctx->height + 3) / 4);
|
||||||
|
|
||||||
|
if ((ret = ff_reget_buffer(s->avctx, s->frame)) < 0)
|
||||||
|
return ret;
|
||||||
|
pixels = (uint16_t *)s->frame->data[0];
|
||||||
|
stride = s->frame->linesize[0] / 2;
|
||||||
|
row_inc = stride - 4;
|
||||||
|
|
||||||
/* Process chunk data */
|
/* Process chunk data */
|
||||||
while (bytestream2_get_bytes_left(&s->gb)) {
|
while (bytestream2_get_bytes_left(&s->gb)) {
|
||||||
uint8_t opcode = bytestream2_get_byte(&s->gb); /* Get opcode */
|
uint8_t opcode = bytestream2_get_byte(&s->gb); /* Get opcode */
|
||||||
@@ -256,9 +261,6 @@ static int rpza_decode_frame(AVCodecContext *avctx,
|
|||||||
|
|
||||||
bytestream2_init(&s->gb, avpkt->data, avpkt->size);
|
bytestream2_init(&s->gb, avpkt->data, avpkt->size);
|
||||||
|
|
||||||
if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
ret = rpza_decode_stream(s);
|
ret = rpza_decode_stream(s);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
Reference in New Issue
Block a user