v4l2object: Split _v4l2fourcc_to_video_format

https://bugzilla.gnome.org/show_bug.cgi?id=720568
This commit is contained in:
Nicolas Dufresne 2013-12-03 18:27:47 -05:00
parent e1be685c34
commit 4956b46bab
2 changed files with 83 additions and 71 deletions

View file

@ -1357,74 +1357,9 @@ gst_v4l2_object_get_format_list (GstV4l2Object * v4l2object)
return v4l2object->formats;
}
GstStructure *
gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc)
static GstVideoFormat
gst_v4l2_object_v4l2fourcc_to_video_format (guint32 fourcc)
{
GstStructure *structure = NULL;
switch (fourcc) {
case V4L2_PIX_FMT_MJPEG: /* Motion-JPEG */
#ifdef V4L2_PIX_FMT_PJPG
case V4L2_PIX_FMT_PJPG: /* Progressive-JPEG */
#endif
case V4L2_PIX_FMT_JPEG: /* JFIF JPEG */
structure = gst_structure_new_empty ("image/jpeg");
break;
case V4L2_PIX_FMT_YYUV: /* 16 YUV 4:2:2 */
case V4L2_PIX_FMT_HI240: /* 8 8-bit color */
/* FIXME: get correct fourccs here */
break;
#ifdef V4L2_PIX_FMT_MPEG4
case V4L2_PIX_FMT_MPEG4:
structure = gst_structure_new ("video/mpeg",
"mpegversion", G_TYPE_INT, 4, "systemstream",
G_TYPE_BOOLEAN, FALSE, NULL);
break;
#endif
#ifdef V4L2_PIX_FMT_H263
case V4L2_PIX_FMT_H263:
structure = gst_structure_new ("video/x-h263",
"variant", G_TYPE_STRING, "itu", NULL);
break;
#endif
#ifdef V4L2_PIX_FMT_H264
case V4L2_PIX_FMT_H264: /* H.264 */
structure = gst_structure_new ("video/x-h264",
"stream-format", G_TYPE_STRING, "byte-stream", "alignment",
G_TYPE_STRING, "au", NULL);
break;
#endif
case V4L2_PIX_FMT_RGB332:
case V4L2_PIX_FMT_RGB555X:
case V4L2_PIX_FMT_RGB565X:
/* FIXME: get correct fourccs here */
break;
case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
case V4L2_PIX_FMT_RGB555:
case V4L2_PIX_FMT_RGB565:
case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_BGR24:
case V4L2_PIX_FMT_RGB32:
case V4L2_PIX_FMT_BGR32:
case V4L2_PIX_FMT_NV12: /* 12 Y/CbCr 4:2:0 */
case V4L2_PIX_FMT_NV12M:
case V4L2_PIX_FMT_NV21: /* 12 Y/CrCb 4:2:0 */
case V4L2_PIX_FMT_NV21M:
case V4L2_PIX_FMT_YVU410:
case V4L2_PIX_FMT_YUV410:
case V4L2_PIX_FMT_YUV420: /* I420/IYUV */
case V4L2_PIX_FMT_YUYV:
case V4L2_PIX_FMT_YVU420:
case V4L2_PIX_FMT_UYVY:
#if 0
case V4L2_PIX_FMT_Y41P:
#endif
case V4L2_PIX_FMT_YUV422P:
#ifdef V4L2_PIX_FMT_YVYU
case V4L2_PIX_FMT_YVYU:
#endif
case V4L2_PIX_FMT_YUV411P:{
GstVideoFormat format;
switch (fourcc) {
@ -1496,6 +1431,79 @@ gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc)
g_assert_not_reached ();
break;
}
return format;
}
GstStructure *
gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc)
{
GstStructure *structure = NULL;
switch (fourcc) {
case V4L2_PIX_FMT_MJPEG: /* Motion-JPEG */
#ifdef V4L2_PIX_FMT_PJPG
case V4L2_PIX_FMT_PJPG: /* Progressive-JPEG */
#endif
case V4L2_PIX_FMT_JPEG: /* JFIF JPEG */
structure = gst_structure_new_empty ("image/jpeg");
break;
case V4L2_PIX_FMT_YYUV: /* 16 YUV 4:2:2 */
case V4L2_PIX_FMT_HI240: /* 8 8-bit color */
/* FIXME: get correct fourccs here */
break;
#ifdef V4L2_PIX_FMT_MPEG4
case V4L2_PIX_FMT_MPEG4:
structure = gst_structure_new ("video/mpeg",
"mpegversion", G_TYPE_INT, 4, "systemstream",
G_TYPE_BOOLEAN, FALSE, NULL);
break;
#endif
#ifdef V4L2_PIX_FMT_H263
case V4L2_PIX_FMT_H263:
structure = gst_structure_new ("video/x-h263",
"variant", G_TYPE_STRING, "itu", NULL);
break;
#endif
#ifdef V4L2_PIX_FMT_H264
case V4L2_PIX_FMT_H264: /* H.264 */
structure = gst_structure_new ("video/x-h264",
"stream-format", G_TYPE_STRING, "byte-stream", "alignment",
G_TYPE_STRING, "au", NULL);
break;
#endif
case V4L2_PIX_FMT_RGB332:
case V4L2_PIX_FMT_RGB555X:
case V4L2_PIX_FMT_RGB565X:
/* FIXME: get correct fourccs here */
break;
case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
case V4L2_PIX_FMT_RGB555:
case V4L2_PIX_FMT_RGB565:
case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_BGR24:
case V4L2_PIX_FMT_RGB32:
case V4L2_PIX_FMT_BGR32:
case V4L2_PIX_FMT_NV12: /* 12 Y/CbCr 4:2:0 */
case V4L2_PIX_FMT_NV12M:
case V4L2_PIX_FMT_NV21: /* 12 Y/CrCb 4:2:0 */
case V4L2_PIX_FMT_NV21M:
case V4L2_PIX_FMT_YVU410:
case V4L2_PIX_FMT_YUV410:
case V4L2_PIX_FMT_YUV420: /* I420/IYUV */
case V4L2_PIX_FMT_YUYV:
case V4L2_PIX_FMT_YVU420:
case V4L2_PIX_FMT_UYVY:
#if 0
case V4L2_PIX_FMT_Y41P:
#endif
case V4L2_PIX_FMT_YUV422P:
#ifdef V4L2_PIX_FMT_YVYU
case V4L2_PIX_FMT_YVYU:
#endif
case V4L2_PIX_FMT_YUV411P:{
GstVideoFormat format;
format = gst_v4l2_object_v4l2fourcc_to_video_format (fourcc);
if (format != GST_VIDEO_FORMAT_UNKNOWN)
structure = gst_structure_new ("video/x-raw",
"format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
@ -2306,6 +2314,9 @@ gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
fd = v4l2object->video_fd;
memset (&fmt, 0, sizeof (struct v4l2_format));
memset (&prevfmt, 0, sizeof (struct v4l2_format));
/* Some drivers are buggy and will modify the currently set format
when processing VIDIOC_TRY_FMT, so we remember what is set at the
minute, and will reset it when done. */
@ -2625,7 +2636,7 @@ gst_v4l2_object_set_format (GstV4l2Object * v4l2object, GstCaps * caps)
v4l2object->sizeimage = 0;
for (i = 0; i < format.fmt.pix_mp.num_planes; i++) {
/* For compatibility reasons with the non-v4l2-multiplanar mode
* we have to use the bytesperline of the first v4l plane
* we have to use the bytesperline of<F3> the first v4l plane
* See plane_fmt[0] instead of plane_fmt[i] in next line */
v4l2object->bytesperline[i] = format.fmt.pix_mp.plane_fmt[0].bytesperline;
v4l2object->sizeimage += format.fmt.pix_mp.plane_fmt[i].sizeimage;

View file

@ -275,6 +275,7 @@ GstCaps * gst_v4l2_object_get_caps (GstV4l2Object * v4l2object,
GstCaps * filter);
#define GST_IMPLEMENT_V4L2_PROBE_METHODS(Type_Class, interface_as_function) \
\
static void \