typedef struct CRIContext {
AVCodecContext *jpeg_avctx; // wrapper context for MJPEG
+ AVPacket *jpkt; // encoded JPEG tile
AVFrame *jpgframe; // decoded JPEG tile
GetByteContext gb;
if (!s->jpgframe)
return AVERROR(ENOMEM);
+ s->jpkt = av_packet_alloc();
+ if (!s->jpkt)
+ return AVERROR(ENOMEM);
+
codec = avcodec_find_decoder(AV_CODEC_ID_MJPEG);
if (!codec)
return AVERROR_BUG;
int pos = 0;
while (count > 0) {
- uint32_t a0, a1,a2,a3;
+ uint32_t a0, a1, a2, a3;
if (bytestream2_get_bytes_left(gb) < 4)
break;
a0 = bytestream2_get_le32(gb);
char codec_name[1024];
uint32_t key, length;
float framerate;
+ int width, height;
key = bytestream2_get_le32(gb);
length = bytestream2_get_le32(gb);
case 100:
if (length < 16)
return AVERROR_INVALIDDATA;
- avctx->width = bytestream2_get_le32(gb);
- avctx->height = bytestream2_get_le32(gb);
+ width = bytestream2_get_le32(gb);
+ height = bytestream2_get_le32(gb);
s->color_model = bytestream2_get_le32(gb);
if (bytestream2_get_le32(gb) != 1)
return AVERROR_INVALIDDATA;
+ ret = ff_set_dimensions(avctx, width, height);
+ if (ret < 0)
+ return ret;
length -= 16;
goto skip;
case 101:
for (int y = 0; y < avctx->height; y++) {
uint16_t *dst = (uint16_t *)(p->data[0] + y * p->linesize[0]);
+ if (get_bits_left(&gbit) < avctx->width * bps)
+ break;
+
for (int x = 0; x < avctx->width; x++)
dst[x] = get_bits(&gbit, bps) << shift;
}
unsigned offset = 0;
for (int tile = 0; tile < 4; tile++) {
- AVPacket jpkt;
-
- av_init_packet(&jpkt);
- jpkt.data = (uint8_t *)s->data + offset;
- jpkt.size = s->tile_size[tile];
+ av_packet_unref(s->jpkt);
+ s->jpkt->data = (uint8_t *)s->data + offset;
+ s->jpkt->size = s->tile_size[tile];
- ret = avcodec_send_packet(s->jpeg_avctx, &jpkt);
+ ret = avcodec_send_packet(s->jpeg_avctx, s->jpkt);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
return ret;
CRIContext *s = avctx->priv_data;
av_frame_free(&s->jpgframe);
+ av_packet_free(&s->jpkt);
avcodec_free_context(&s->jpeg_avctx);
return 0;