From e85d6608a8da8c2425cf9cad5a0ff740a7dd9ffc Mon Sep 17 00:00:00 2001
From: Giorgio Vazzana <mywing81@gmail.com>
Date: Sat, 18 Oct 2014 18:06:40 +0200
Subject: [PATCH] lavd/v4l2: produce a 0 byte packet when a dequeued buffer is
flagged with V4L2_BUF_FLAG_ERROR
---
libavdevice/v4l2.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index cf7a92c..90947ad 100644
|
a
|
b
|
static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
|
| 517 | 517 | // always keep at least one buffer queued |
| 518 | 518 | av_assert0(avpriv_atomic_int_get(&s->buffers_queued) >= 1); |
| 519 | 519 | |
| 520 | | /* CPIA is a compressed format and we don't know the exact number of bytes |
| 521 | | * used by a frame, so set it here as the driver announces it. |
| 522 | | */ |
| 523 | | if (ctx->video_codec_id == AV_CODEC_ID_CPIA) |
| 524 | | s->frame_size = buf.bytesused; |
| | 520 | if (buf.flags & V4L2_BUF_FLAG_ERROR) { |
| | 521 | av_log(ctx, AV_LOG_WARNING, |
| | 522 | "Dequeued v4l2 buffer contains corrupted data (%d bytes).\n", |
| | 523 | buf.bytesused); |
| | 524 | buf.bytesused = 0; |
| | 525 | } else { |
| | 526 | /* CPIA is a compressed format and we don't know the exact number of bytes |
| | 527 | * used by a frame, so set it here as the driver announces it. */ |
| | 528 | if (ctx->video_codec_id == AV_CODEC_ID_CPIA) |
| | 529 | s->frame_size = buf.bytesused; |
| 525 | 530 | |
| 526 | | if (s->frame_size > 0 && buf.bytesused != s->frame_size) { |
| 527 | | av_log(ctx, AV_LOG_ERROR, |
| 528 | | "The v4l2 frame is %d bytes, but %d bytes are expected\n", |
| 529 | | buf.bytesused, s->frame_size); |
| 530 | | enqueue_buffer(s, &buf); |
| 531 | | return AVERROR_INVALIDDATA; |
| | 531 | if (s->frame_size > 0 && buf.bytesused != s->frame_size) { |
| | 532 | av_log(ctx, AV_LOG_ERROR, |
| | 533 | "Dequeued v4l2 buffer contains %d bytes, but %d were expected. Flags: 0x%08X.\n", |
| | 534 | buf.bytesused, s->frame_size, buf.flags); |
| | 535 | enqueue_buffer(s, &buf); |
| | 536 | return AVERROR_INVALIDDATA; |
| | 537 | } |
| 532 | 538 | } |
| 533 | 539 | |
| 534 | 540 | /* Image is at s->buff_start[buf.index] */ |
| … |
… |
FF_ENABLE_DEPRECATION_WARNINGS
|
| 583 | 589 | pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec; |
| 584 | 590 | convert_timestamp(ctx, &pkt->pts); |
| 585 | 591 | |
| 586 | | return s->buf_len[buf.index]; |
| | 592 | return pkt->size; |
| 587 | 593 | } |
| 588 | 594 | |
| 589 | 595 | static int mmap_start(AVFormatContext *ctx) |