Revision 7e6a9e64

View differences:

libavcodec/mjpegdec.c
1299 1299
    return val;
1300 1300
}
1301 1301

  
1302
int ff_mjpeg_decode_frame(AVCodecContext *avctx,
1303
                              void *data, int *data_size,
1304
                              AVPacket *avpkt)
1302
int ff_mjpeg_find_marker(MJpegDecodeContext *s,
1303
                         const uint8_t **buf_ptr, const uint8_t *buf_end,
1304
                         const uint8_t **unescaped_buf_ptr, int *unescaped_buf_size)
1305 1305
{
1306
    const uint8_t *buf = avpkt->data;
1307
    int buf_size = avpkt->size;
1308
    MJpegDecodeContext *s = avctx->priv_data;
1309
    const uint8_t *buf_end, *buf_ptr;
1310 1306
    int start_code;
1311
    AVFrame *picture = data;
1312

  
1313
    s->got_picture = 0; // picture from previous image can not be reused
1314
    buf_ptr = buf;
1315
    buf_end = buf + buf_size;
1316
    while (buf_ptr < buf_end) {
1317
        /* find start next marker */
1318
        start_code = find_marker(&buf_ptr, buf_end);
1319
        {
1320
            /* EOF */
1321
            if (start_code < 0) {
1322
                goto the_end;
1323
            } else {
1324
                av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n", start_code, buf_end - buf_ptr);
1307
    start_code = find_marker(buf_ptr, buf_end);
1325 1308

  
1326
                if ((buf_end - buf_ptr) > s->buffer_size)
1309
                if ((buf_end - *buf_ptr) > s->buffer_size)
1327 1310
                {
1328 1311
                    av_free(s->buffer);
1329
                    s->buffer_size = buf_end-buf_ptr;
1312
                    s->buffer_size = buf_end - *buf_ptr;
1330 1313
                    s->buffer = av_malloc(s->buffer_size + FF_INPUT_BUFFER_PADDING_SIZE);
1331
                    av_log(avctx, AV_LOG_DEBUG, "buffer too small, expanding to %d bytes\n",
1314
                    av_log(s->avctx, AV_LOG_DEBUG, "buffer too small, expanding to %d bytes\n",
1332 1315
                        s->buffer_size);
1333 1316
                }
1334 1317

  
1335 1318
                /* unescape buffer of SOS, use special treatment for JPEG-LS */
1336 1319
                if (start_code == SOS && !s->ls)
1337 1320
                {
1338
                    const uint8_t *src = buf_ptr;
1321
                    const uint8_t *src = *buf_ptr;
1339 1322
                    uint8_t *dst = s->buffer;
1340 1323

  
1341 1324
                    while (src<buf_end)
......
1343 1326
                        uint8_t x = *(src++);
1344 1327

  
1345 1328
                        *(dst++) = x;
1346
                        if (avctx->codec_id != CODEC_ID_THP)
1329
                        if (s->avctx->codec_id != CODEC_ID_THP)
1347 1330
                        {
1348 1331
                            if (x == 0xff) {
1349 1332
                                while (src < buf_end && x == 0xff)
......
1356 1339
                            }
1357 1340
                        }
1358 1341
                    }
1359
                    init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8);
1342
                    *unescaped_buf_ptr  = s->buffer;
1343
                    *unescaped_buf_size = dst - s->buffer;
1360 1344

  
1361
                    av_log(avctx, AV_LOG_DEBUG, "escaping removed %td bytes\n",
1362
                           (buf_end - buf_ptr) - (dst - s->buffer));
1345
                    av_log(s->avctx, AV_LOG_DEBUG, "escaping removed %td bytes\n",
1346
                           (buf_end - *buf_ptr) - (dst - s->buffer));
1363 1347
                }
1364 1348
                else if(start_code == SOS && s->ls){
1365
                    const uint8_t *src = buf_ptr;
1349
                    const uint8_t *src = *buf_ptr;
1366 1350
                    uint8_t *dst = s->buffer;
1367 1351
                    int bit_count = 0;
1368 1352
                    int t = 0, b = 0;
......
1398 1382
                    }
1399 1383
                    flush_put_bits(&pb);
1400 1384

  
1401
                    init_get_bits(&s->gb, dst, bit_count);
1385
                    *unescaped_buf_ptr  = dst;
1386
                    *unescaped_buf_size = (bit_count + 7) >> 3;
1402 1387
                }
1403 1388
                else
1404
                    init_get_bits(&s->gb, buf_ptr, (buf_end - buf_ptr)*8);
1389
                {
1390
                    *unescaped_buf_ptr  = *buf_ptr;
1391
                    *unescaped_buf_size = buf_end - *buf_ptr;
1392
                }
1393

  
1394
    return start_code;
1395
}
1396

  
1397
int ff_mjpeg_decode_frame(AVCodecContext *avctx,
1398
                              void *data, int *data_size,
1399
                              AVPacket *avpkt)
1400
{
1401
    const uint8_t *buf = avpkt->data;
1402
    int buf_size = avpkt->size;
1403
    MJpegDecodeContext *s = avctx->priv_data;
1404
    const uint8_t *buf_end, *buf_ptr;
1405
    const uint8_t *unescaped_buf_ptr;
1406
    int unescaped_buf_size;
1407
    int start_code;
1408
    AVFrame *picture = data;
1409

  
1410
    s->got_picture = 0; // picture from previous image can not be reused
1411
    buf_ptr = buf;
1412
    buf_end = buf + buf_size;
1413
    while (buf_ptr < buf_end) {
1414
        /* find start next marker */
1415
        start_code = ff_mjpeg_find_marker(s, &buf_ptr, buf_end,
1416
                                          &unescaped_buf_ptr, &unescaped_buf_size);
1417
        {
1418
            /* EOF */
1419
            if (start_code < 0) {
1420
                goto the_end;
1421
            } else {
1422
                av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n", start_code, buf_end - buf_ptr);
1423

  
1424
                init_get_bits(&s->gb, unescaped_buf_ptr, unescaped_buf_size*8);
1405 1425

  
1406 1426
                s->start_code = start_code;
1407 1427
                if(s->avctx->debug & FF_DEBUG_STARTCODE){
libavcodec/mjpegdec.h
117 117
int ff_mjpeg_decode_sof(MJpegDecodeContext *s);
118 118
int ff_mjpeg_decode_sos(MJpegDecodeContext *s,
119 119
                        const uint8_t *mb_bitmask, const AVFrame *reference);
120
int ff_mjpeg_find_marker(MJpegDecodeContext *s,
121
                         const uint8_t **buf_ptr, const uint8_t *buf_end,
122
                         const uint8_t **unescaped_buf_ptr, int *unescaped_buf_size);
120 123

  
121 124
#endif /* AVCODEC_MJPEGDEC_H */

Also available in: Unified diff