summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-07-28 20:18:24 +0200
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-07-28 20:18:24 +0200
commitaaa5d3752d0ca2cd8b3a0848580c5253ab24c603 (patch)
tree5d347253fc461d4445a5f4de5d8aadb2ab443df0
parent8a3cb0e6629490d62827187fa9fc09552bf36cda (diff)
v4l: add support for more pixel-formats (ref #282)
-rw-r--r--modules/v4l/v4l.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/modules/v4l/v4l.c b/modules/v4l/v4l.c
index 25b7640..a171021 100644
--- a/modules/v4l/v4l.c
+++ b/modules/v4l/v4l.c
@@ -35,6 +35,7 @@ struct vidsrc_st {
bool run;
struct vidsz size;
struct mbuf *mb;
+ enum vidfmt fmt;
vidsrc_frame_h *frameh;
void *arg;
};
@@ -71,12 +72,23 @@ static int v4l_check_palette(struct vidsrc_st *st)
return errno;
}
- if (VIDEO_PALETTE_RGB24 != pic.palette) {
- warning("v4l: unsupported palette %d (only RGB24 supp.)\n",
- pic.palette);
+ switch (pic.palette) {
+
+ case VIDEO_PALETTE_RGB24:
+ st->fmt = VID_FMT_RGB32;
+ break;
+
+ case VIDEO_PALETTE_YUYV:
+ st->fmt = VID_FMT_YUYV422;
+ break;
+
+ default:
+ warning("v4l: unsupported palette %d\n", pic.palette);
return ENODEV;
}
+ info("v4l: pixel format is %s\n", vidfmt_name(st->fmt));
+
return 0;
}
@@ -109,7 +121,7 @@ static void call_frame_handler(struct vidsrc_st *st, uint8_t *buf)
{
struct vidframe frame;
- vidframe_init_buf(&frame, VID_FMT_RGB32, &st->size, buf);
+ vidframe_init_buf(&frame, st->fmt, &st->size, buf);
st->frameh(&frame, st->arg);
}
@@ -167,12 +179,6 @@ static void destructor(void *arg)
}
-static uint32_t rgb24_size(const struct vidsz *sz)
-{
- return sz ? (sz->w * sz->h * 24/8) : 0;
-}
-
-
static int alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
struct media_ctx **ctx, struct vidsrc_prm *prm,
const struct vidsz *size, const char *fmt,
@@ -219,8 +225,8 @@ static int alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
if (err)
goto out;
- /* note: assumes RGB24 */
- st->mb = mbuf_alloc(rgb24_size(&st->size));
+ /* allocate buffer for the picture */
+ st->mb = mbuf_alloc(vidframe_size(st->fmt, &st->size));
if (!st->mb) {
err = ENOMEM;
goto out;