if (buf_size < 2) {
av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
- if (c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
- c->pic.reference = 1;
+ c->pic.reference = 3;
c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE |
FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
- if (avctx->reget_buffer(avctx, &c->pic) < 0) {
- if ((ret = ff_get_buffer(avctx, &c->pic)) < 0) {
++ if ((ret = avctx->reget_buffer(avctx, &c->pic)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
+ return ret;
}
// decompress data
}
/**
- * Inititalize GetBitContext.
- * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger than the actual read bits
- * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
+ * Initialize GetBitContext.
+ * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes
+ * larger than the actual read bits because some optimized bitstream
+ * readers read 32 or 64 bit at once and could read over the end
* @param bit_size the size of the buffer in bits
+ * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
*/
- static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer,
- int bit_size)
+ static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
+ int bit_size)
{
- int buffer_size = (bit_size+7)>>3;
- if (buffer_size < 0 || bit_size < 0) {
+ int buffer_size;
+ int ret = 0;
+
- if (bit_size > INT_MAX - 7 || bit_size <= 0) {
++ if (bit_size > INT_MAX - 7 || bit_size < 0) {
buffer_size = bit_size = 0;
buffer = NULL;
+ ret = AVERROR_INVALIDDATA;
}
+ buffer_size = (bit_size + 7) >> 3;
+
s->buffer = buffer;
s->size_in_bits = bit_size;
-#if !UNCHECKED_BITSTREAM_READER
s->size_in_bits_plus8 = bit_size + 8;
-#endif
s->buffer_end = buffer + buffer_size;
s->index = 0;
+ return ret;
+ }
+
+ /**
+ * Initialize GetBitContext.
+ * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes
+ * larger than the actual read bits because some optimized bitstream
+ * readers read 32 or 64 bit at once and could read over the end
+ * @param byte_size the size of the buffer in bytes
+ * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
+ */
+ static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer,
+ int byte_size)
+ {
+ if (byte_size > INT_MAX / 8)
+ return AVERROR_INVALIDDATA;
+ return init_get_bits(s, buffer, byte_size * 8);
}
static inline void align_get_bits(GetBitContext *s)
break;
default:
av_log(avctx, AV_LOG_ERROR, "unsupported bits per sample\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
+ avcodec_get_frame_defaults(&s->frame);
s->frame.data[0] = NULL;
+ if (avctx->extradata_size >= 4)
+ for (i = 0; i < FFMIN(avctx->extradata_size, AVPALETTE_SIZE)/4; i++)
+ s->pal[i] = 0xFFU<<24 | AV_RL32(avctx->extradata+4*i);
+
return 0;
}
s->buf = buf;
s->size = buf_size;
- s->frame.reference = 1;
+ s->frame.reference = 3;
s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
- if (avctx->reget_buffer(avctx, &s->frame)) {
+ if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
- return -1;
+ return ret;
}
- if (avctx->bits_per_coded_sample <= 8) {
+ if (avctx->bits_per_coded_sample > 1 && avctx->bits_per_coded_sample <= 8) {
const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
if (pal) {