Revision f16055ee libavcodec/mjpegdec.c

View differences:

libavcodec/mjpegdec.c
1316 1316
    return val;
1317 1317
}
1318 1318

  
1319
int ff_mjpeg_decode_frame(AVCodecContext *avctx,
1320
                              void *data, int *data_size,
1321
                              AVPacket *avpkt)
1319
int ff_mjpeg_find_marker(MJpegDecodeContext *s,
1320
                         const uint8_t **buf_ptr, const uint8_t *buf_end,
1321
                         const uint8_t **unescaped_buf_ptr, int *unescaped_buf_size)
1322 1322
{
1323
    const uint8_t *buf = avpkt->data;
1324
    int buf_size = avpkt->size;
1325
    MJpegDecodeContext *s = avctx->priv_data;
1326
    const uint8_t *buf_end, *buf_ptr;
1327 1323
    int start_code;
1328
    AVFrame *picture = data;
1329

  
1330
    s->got_picture = 0; // picture from previous image can not be reused
1331
    buf_ptr = buf;
1332
    buf_end = buf + buf_size;
1333
    while (buf_ptr < buf_end) {
1334
        /* find start next marker */
1335
        start_code = find_marker(&buf_ptr, buf_end);
1336
        {
1337
            /* EOF */
1338
            if (start_code < 0) {
1339
                goto the_end;
1340
            } else {
1341
                av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n", start_code, buf_end - buf_ptr);
1324
    start_code = find_marker(buf_ptr, buf_end);
1342 1325

  
1343
                if ((buf_end - buf_ptr) > s->buffer_size)
1326
                if ((buf_end - *buf_ptr) > s->buffer_size)
1344 1327
                {
1345 1328
                    av_free(s->buffer);
1346
                    s->buffer_size = buf_end-buf_ptr;
1329
                    s->buffer_size = buf_end - *buf_ptr;
1347 1330
                    s->buffer = av_malloc(s->buffer_size + FF_INPUT_BUFFER_PADDING_SIZE);
1348
                    av_log(avctx, AV_LOG_DEBUG, "buffer too small, expanding to %d bytes\n",
1331
                    av_log(s->avctx, AV_LOG_DEBUG, "buffer too small, expanding to %d bytes\n",
1349 1332
                        s->buffer_size);
1350 1333
                }
1351 1334

  
1352 1335
                /* unescape buffer of SOS, use special treatment for JPEG-LS */
1353 1336
                if (start_code == SOS && !s->ls)
1354 1337
                {
1355
                    const uint8_t *src = buf_ptr;
1338
                    const uint8_t *src = *buf_ptr;
1356 1339
                    uint8_t *dst = s->buffer;
1357 1340

  
1358 1341
                    while (src<buf_end)
......
1360 1343
                        uint8_t x = *(src++);
1361 1344

  
1362 1345
                        *(dst++) = x;
1363
                        if (avctx->codec_id != CODEC_ID_THP)
1346
                        if (s->avctx->codec_id != CODEC_ID_THP)
1364 1347
                        {
1365 1348
                            if (x == 0xff) {
1366 1349
                                while (src < buf_end && x == 0xff)
......
1373 1356
                            }
1374 1357
                        }
1375 1358
                    }
1376
                    init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8);
1359
                    *unescaped_buf_ptr  = s->buffer;
1360
                    *unescaped_buf_size = dst - s->buffer;
1377 1361

  
1378
                    av_log(avctx, AV_LOG_DEBUG, "escaping removed %td bytes\n",
1379
                           (buf_end - buf_ptr) - (dst - s->buffer));
1362
                    av_log(s->avctx, AV_LOG_DEBUG, "escaping removed %td bytes\n",
1363
                           (buf_end - *buf_ptr) - (dst - s->buffer));
1380 1364
                }
1381 1365
                else if(start_code == SOS && s->ls){
1382
                    const uint8_t *src = buf_ptr;
1366
                    const uint8_t *src = *buf_ptr;
1383 1367
                    uint8_t *dst = s->buffer;
1384 1368
                    int bit_count = 0;
1385 1369
                    int t = 0, b = 0;
......
1415 1399
                    }
1416 1400
                    flush_put_bits(&pb);
1417 1401

  
1418
                    init_get_bits(&s->gb, dst, bit_count);
1402
                    *unescaped_buf_ptr  = dst;
1403
                    *unescaped_buf_size = (bit_count + 7) >> 3;
1419 1404
                }
1420 1405
                else
1421
                    init_get_bits(&s->gb, buf_ptr, (buf_end - buf_ptr)*8);
1406
                {
1407
                    *unescaped_buf_ptr  = *buf_ptr;
1408
                    *unescaped_buf_size = buf_end - *buf_ptr;
1409
                }
1410

  
1411
    return start_code;
1412
}
1413

  
1414
int ff_mjpeg_decode_frame(AVCodecContext *avctx,
1415
                              void *data, int *data_size,
1416
                              AVPacket *avpkt)
1417
{
1418
    const uint8_t *buf = avpkt->data;
1419
    int buf_size = avpkt->size;
1420
    MJpegDecodeContext *s = avctx->priv_data;
1421
    const uint8_t *buf_end, *buf_ptr;
1422
    const uint8_t *unescaped_buf_ptr;
1423
    int unescaped_buf_size;
1424
    int start_code;
1425
    AVFrame *picture = data;
1426

  
1427
    s->got_picture = 0; // picture from previous image can not be reused
1428
    buf_ptr = buf;
1429
    buf_end = buf + buf_size;
1430
    while (buf_ptr < buf_end) {
1431
        /* find start next marker */
1432
        start_code = ff_mjpeg_find_marker(s, &buf_ptr, buf_end,
1433
                                          &unescaped_buf_ptr, &unescaped_buf_size);
1434
        {
1435
            /* EOF */
1436
            if (start_code < 0) {
1437
                goto the_end;
1438
            } else {
1439
                av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n", start_code, buf_end - buf_ptr);
1440

  
1441
                init_get_bits(&s->gb, unescaped_buf_ptr, unescaped_buf_size*8);
1422 1442

  
1423 1443
                s->start_code = start_code;
1424 1444
                if(s->avctx->debug & FF_DEBUG_STARTCODE){

Also available in: Unified diff