diff options
author | Stephan Hilb <stephan@ecshi.net> | 2012-08-23 20:40:22 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-08-31 02:24:11 +0400 |
commit | 6eac554659b6b6e9b348ec26c44b5105a3f4b11c (patch) | |
tree | a2a723ff2606b5bc72e02f40c21e30062e14ca9e /libavdevice/v4l2.c | |
parent | 469f8b1dcbacc921555af6c068db28ad3d3e5006 (diff) |
Add CPiA video decoder
The cpia video decoder is intended to be used with the v4l2 demuxer.
There are some small changes to the v4l2 demuxer to support the
variable frame length of the format.
Fixes ticket #1537
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavdevice/v4l2.c')
-rw-r--r-- | libavdevice/v4l2.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 867c363533..4b43688089 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -150,6 +150,7 @@ static struct fmt_map fmt_conversion_table[] = { { PIX_FMT_NV12, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV12 }, { PIX_FMT_NONE, AV_CODEC_ID_MJPEG, V4L2_PIX_FMT_MJPEG }, { PIX_FMT_NONE, AV_CODEC_ID_MJPEG, V4L2_PIX_FMT_JPEG }, + { PIX_FMT_NONE, AV_CODEC_ID_CPIA, V4L2_PIX_FMT_CPIA1 }, }; static int device_open(AVFormatContext *ctx) @@ -549,6 +550,13 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) return AVERROR(errno); } av_assert0(buf.index < s->buffers); + + /* 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) { av_log(ctx, AV_LOG_ERROR, "The v4l2 frame is %d bytes, but %d bytes are expected\n", @@ -767,7 +775,7 @@ static int v4l2_read_header(AVFormatContext *s1) AVStream *st; int res = 0; uint32_t desired_format; - enum AVCodecID codec_id; + enum AVCodecID codec_id = AV_CODEC_ID_NONE; enum PixelFormat pix_fmt = PIX_FMT_NONE; st = avformat_new_stream(s1, NULL); @@ -828,6 +836,14 @@ static int v4l2_read_header(AVFormatContext *s1) desired_format = device_try_init(s1, pix_fmt, &s->width, &s->height, &codec_id); + + /* If no pixel_format was specified, the codec_id was not known up + * until now. Set video_codec_id in the context, as codec_id will + * not be available outside this function + */ + if (codec_id != AV_CODEC_ID_NONE && s1->video_codec_id == AV_CODEC_ID_NONE) + s1->video_codec_id = codec_id; + if (desired_format == 0) { av_log(s1, AV_LOG_ERROR, "Cannot find a proper format for " "codec_id %d, pix_fmt %d.\n", s1->video_codec_id, pix_fmt); |