mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-26 19:01:44 +02:00
lavd/v4l2: produce a 0 byte packet when a dequeued buffer is flagged with V4L2_BUF_FLAG_ERROR
Fixes ticket #4030. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
982e7bbfa6
commit
28f20d2ff4
@ -499,13 +499,14 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
|
|||||||
};
|
};
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
pkt->size = 0;
|
||||||
|
|
||||||
/* FIXME: Some special treatment might be needed in case of loss of signal... */
|
/* FIXME: Some special treatment might be needed in case of loss of signal... */
|
||||||
while ((res = v4l2_ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && (errno == EINTR));
|
while ((res = v4l2_ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && (errno == EINTR));
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
if (errno == EAGAIN) {
|
if (errno == EAGAIN)
|
||||||
pkt->size = 0;
|
|
||||||
return AVERROR(EAGAIN);
|
return AVERROR(EAGAIN);
|
||||||
}
|
|
||||||
res = AVERROR(errno);
|
res = AVERROR(errno);
|
||||||
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n",
|
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n",
|
||||||
av_err2str(res));
|
av_err2str(res));
|
||||||
@ -520,18 +521,24 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
|
|||||||
// always keep at least one buffer queued
|
// always keep at least one buffer queued
|
||||||
av_assert0(avpriv_atomic_int_get(&s->buffers_queued) >= 1);
|
av_assert0(avpriv_atomic_int_get(&s->buffers_queued) >= 1);
|
||||||
|
|
||||||
/* CPIA is a compressed format and we don't know the exact number of bytes
|
if (buf.flags & V4L2_BUF_FLAG_ERROR) {
|
||||||
* used by a frame, so set it here as the driver announces it.
|
av_log(ctx, AV_LOG_WARNING,
|
||||||
*/
|
"Dequeued v4l2 buffer contains corrupted data (%d bytes).\n",
|
||||||
if (ctx->video_codec_id == AV_CODEC_ID_CPIA)
|
buf.bytesused);
|
||||||
s->frame_size = buf.bytesused;
|
buf.bytesused = 0;
|
||||||
|
} else {
|
||||||
|
/* CPIA is a compressed format and we don't know the exact number of bytes
|
||||||
|
* used by a frame, so set it here as the driver announces it. */
|
||||||
|
if (ctx->video_codec_id == AV_CODEC_ID_CPIA)
|
||||||
|
s->frame_size = buf.bytesused;
|
||||||
|
|
||||||
if (s->frame_size > 0 && buf.bytesused != s->frame_size) {
|
if (s->frame_size > 0 && buf.bytesused != s->frame_size) {
|
||||||
av_log(ctx, AV_LOG_ERROR,
|
av_log(ctx, AV_LOG_ERROR,
|
||||||
"The v4l2 frame is %d bytes, but %d bytes are expected. Flags: 0x%08X\n",
|
"Dequeued v4l2 buffer contains %d bytes, but %d were expected. Flags: 0x%08X.\n",
|
||||||
buf.bytesused, s->frame_size, buf.flags);
|
buf.bytesused, s->frame_size, buf.flags);
|
||||||
enqueue_buffer(s, &buf);
|
enqueue_buffer(s, &buf);
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Image is at s->buff_start[buf.index] */
|
/* Image is at s->buff_start[buf.index] */
|
||||||
@ -586,7 +593,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
|||||||
pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec;
|
pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec;
|
||||||
convert_timestamp(ctx, &pkt->pts);
|
convert_timestamp(ctx, &pkt->pts);
|
||||||
|
|
||||||
return s->buf_len[buf.index];
|
return pkt->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mmap_start(AVFormatContext *ctx)
|
static int mmap_start(AVFormatContext *ctx)
|
||||||
|
Loading…
Reference in New Issue
Block a user