Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 25th, 2012  |  syntax: None  |  size: 4.26 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. commit 1d449d62395f74ad1891cdfc151df5f7ac3bc347
  2. Author: Janne Grunau <janne.grunau@collabora.co.uk>
  3. Date:   Thu Nov 4 18:36:09 2010 +0100
  4.  
  5.     v4l2src: check field information and set interlaced caps accordingly
  6.    
  7.     reject the format if the field type is not supported.
  8.  
  9. diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c
  10. index 96b6e59..8653573 100644
  11. --- a/sys/v4l2/gstv4l2object.c
  12. +++ b/sys/v4l2/gstv4l2object.c
  13. @@ -1454,6 +1454,10 @@ done:
  14.  }
  15.  
  16.  
  17. +static gboolean
  18. +gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
  19. +    guint32 pixelformat, gint * width, gint * height, gboolean * interlaced);
  20. +
  21.  
  22.  /* The frame interval enumeration code first appeared in Linux 2.6.19. */
  23.  #ifdef VIDIOC_ENUM_FRAMEINTERVALS
  24. @@ -1467,6 +1471,14 @@ gst_v4l2_object_probe_caps_for_format_and_size (GstV4l2Object * v4l2object,
  25.    guint32 num, denom;
  26.    GstStructure *s;
  27.    GValue rates = { 0, };
  28. +  gboolean interlaced;
  29. +  gint int_width = width;
  30. +  gint int_height = height;
  31. +
  32. +  /* interlaced detection using VIDIOC_TRY/S_FMT */
  33. +  if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat,
  34. +          &int_width, &int_height, &interlaced))
  35. +    return NULL;
  36.  
  37.    memset (&ival, 0, sizeof (struct v4l2_frmivalenum));
  38.    ival.index = 0;
  39. @@ -1624,7 +1636,8 @@ gst_v4l2_object_probe_caps_for_format_and_size (GstV4l2Object * v4l2object,
  40.  return_data:
  41.    s = gst_structure_copy (template);
  42.    gst_structure_set (s, "width", G_TYPE_INT, (gint) width,
  43. -      "height", G_TYPE_INT, (gint) height, NULL);
  44. +      "height", G_TYPE_INT, (gint) height,
  45. +      "interlaced", G_TYPE_BOOLEAN, interlaced, NULL);
  46.  
  47.    if (G_IS_VALUE (&rates)) {
  48.      /* only change the framerate on the template when we have a valid probed new
  49. @@ -1672,10 +1685,6 @@ sort_by_frame_size (GstStructure * s1, GstStructure * s2)
  50.  }
  51.  #endif
  52.  
  53. -static gboolean
  54. -gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
  55. -    guint32 pixelformat, gint * width, gint * height);
  56. -
  57.  GstCaps *
  58.  gst_v4l2_object_probe_caps_for_format (GstV4l2Object * v4l2object,
  59.      guint32 pixelformat, const GstStructure * template)
  60. @@ -1831,18 +1840,19 @@ default_frame_sizes:
  61.  #endif /* defined VIDIOC_ENUM_FRAMESIZES */
  62.    {
  63.      gint min_w, max_w, min_h, max_h, fix_num = 0, fix_denom = 0;
  64. +    gboolean interlaced;
  65.  
  66.      /* This code is for Linux < 2.6.19 */
  67.      min_w = min_h = 1;
  68.      max_w = max_h = GST_V4L2_MAX_SIZE;
  69.      if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &min_w,
  70. -            &min_h)) {
  71. +            &min_h, &interlaced)) {
  72.        GST_WARNING_OBJECT (v4l2object->element,
  73.            "Could not probe minimum capture size for pixelformat %"
  74.            GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
  75.      }
  76.      if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &max_w,
  77. -            &max_h)) {
  78. +            &max_h, &interlaced)) {
  79.        GST_WARNING_OBJECT (v4l2object->element,
  80.            "Could not probe maximum capture size for pixelformat %"
  81.            GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
  82. @@ -1885,6 +1895,8 @@ default_frame_sizes:
  83.      else
  84.        gst_structure_set (tmp, "height", GST_TYPE_INT_RANGE, min_h, max_h, NULL);
  85.  
  86. +    gst_structure_set (tmp, "interlaced", G_TYPE_BOOLEAN, interlaced, NULL);
  87. +
  88.      gst_caps_append_structure (ret, tmp);
  89.  
  90.      return ret;
  91. @@ -1893,7 +1905,7 @@ default_frame_sizes:
  92.  
  93.  static gboolean
  94.  gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
  95. -    guint32 pixelformat, gint * width, gint * height)
  96. +    guint32 pixelformat, gint * width, gint * height, gboolean * interlaced)
  97.  {
  98.    struct v4l2_format fmt;
  99.    int fd;
  100. @@ -1963,6 +1975,22 @@ gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
  101.    *width = fmt.fmt.pix.width;
  102.    *height = fmt.fmt.pix.height;
  103.  
  104. +  switch (fmt.fmt.pix.field) {
  105. +    case V4L2_FIELD_NONE:
  106. +      *interlaced = FALSE;
  107. +      break;
  108. +    case V4L2_FIELD_INTERLACED:
  109. +    case V4L2_FIELD_INTERLACED_TB:
  110. +    case V4L2_FIELD_INTERLACED_BT:
  111. +      *interlaced = TRUE;
  112. +      break;
  113. +    default:
  114. +      GST_WARNING_OBJECT (v4l2object->element,
  115. +          "Unsupported field type for %" GST_FOURCC_FORMAT "@%ux%u",
  116. +          GST_FOURCC_ARGS (pixelformat), width, height);
  117. +      return FALSE;
  118. +  }
  119. +
  120.    return TRUE;
  121.  }