| 2395 | } |
| 2396 | |
| 2397 | int ff_mjpeg_decode_frame_from_buf(AVCodecContext *avctx, AVFrame *frame, |
| 2398 | int *got_frame, const AVPacket *avpkt, |
| 2399 | const uint8_t *buf, const int buf_size) |
| 2400 | { |
| 2401 | MJpegDecodeContext *s = avctx->priv_data; |
| 2402 | const uint8_t *buf_end, *buf_ptr; |
| 2403 | int hshift, vshift; |
| 2404 | int start_code; |
| 2405 | int index; |
| 2406 | int ret = 0; |
| 2407 | int is16bit; |
| 2408 | |
| 2409 | s->force_pal8 = 0; |
| 2410 | |
| 2411 | s->buf_size = buf_size; |
| 2412 | |
| 2413 | av_exif_free(&s->exif_metadata); |
| 2414 | av_freep(&s->stereo3d); |
| 2415 | s->adobe_transform = -1; |
| 2416 | |
| 2417 | if (s->iccnum != 0) |
| 2418 | reset_icc_profile(s); |
| 2419 | |
| 2420 | redo_for_pal8: |
| 2421 | buf_ptr = buf; |
| 2422 | buf_end = buf + buf_size; |
| 2423 | while (buf_ptr < buf_end) { |
| 2424 | /* find start next marker */ |
| 2425 | start_code = ff_mjpeg_find_marker(&buf_ptr, buf_end); |
| 2426 | /* EOF */ |
| 2427 | if (start_code < 0) |
| 2428 | break; |
| 2429 | |
| 2430 | ptrdiff_t bytes_left = buf_end - buf_ptr; |
| 2431 | if (bytes_left > INT_MAX / 8) { |
| 2432 | av_log(avctx, AV_LOG_ERROR, |
| 2433 | "MJPEG packet 0x%x too big (%td/%d), corrupt data?\n", |
| 2434 | start_code, bytes_left, buf_size); |
| 2435 | return AVERROR_INVALIDDATA; |
| 2436 | } |
| 2437 | av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n", |
| 2438 | start_code, buf_end - buf_ptr); |
| 2439 | |
| 2440 | bytestream2_init(&s->gB, buf_ptr, bytes_left); |
| 2441 | |
| 2442 | if (avctx->debug & FF_DEBUG_STARTCODE) |
| 2443 | av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code); |
| 2444 | |
| 2445 | /* process markers */ |
| 2446 | if (start_code >= RST0 && start_code <= RST7) { |
| 2447 | av_log(avctx, AV_LOG_DEBUG, |
| 2448 | "restart marker: %d\n", start_code & 0x0f); |
| 2449 | /* APP fields */ |
| 2450 | } else if (start_code >= APP0 && start_code <= APP15) { |
| 2451 | if ((ret = mjpeg_decode_app(s, start_code)) < 0) |
| 2452 | av_log(avctx, AV_LOG_ERROR, "unable to decode APP fields: %s\n", |
| 2453 | av_err2str(ret)); |
| 2454 | /* Comment */ |
no test coverage detected