From 9e1d419d07337e6db2cc3936472be205ce927e54 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Sun, 4 Apr 2010 06:43:41 -0500 Subject: [PATCH] v4l2: add norm property Based on a patch by Guennadi Liakhovetski. --- sys/v4l2/gstv4l2object.c | 81 ++++++++++++++++++++++++++++++++++++++++++------ sys/v4l2/gstv4l2object.h | 5 +-- sys/v4l2/gstv4l2sink.c | 16 +++++++--- sys/v4l2/gstv4l2tuner.c | 23 +++++++++++++- sys/v4l2/gstv4l2tuner.h | 5 +++ sys/v4l2/v4l2_calls.c | 3 ++ 6 files changed, 115 insertions(+), 18 deletions(-) diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c index aaa88d4..e1cce2b 100644 --- a/sys/v4l2/gstv4l2object.c +++ b/sys/v4l2/gstv4l2object.c @@ -49,7 +49,7 @@ GST_DEBUG_CATEGORY_EXTERN (v4l2_debug); #define DEFAULT_PROP_DEVICE_NAME NULL #define DEFAULT_PROP_DEVICE_FD -1 #define DEFAULT_PROP_FLAGS 0 -#define DEFAULT_PROP_NORM NULL +#define DEFAULT_PROP_TV_NORM 0 #define DEFAULT_PROP_CHANNEL NULL #define DEFAULT_PROP_FREQUENCY 0 @@ -309,6 +309,54 @@ gst_v4l2_device_get_type (void) return v4l2_device_type; } +#define GST_TYPE_V4L2_TV_NORM (gst_v4l2_tv_norm_get_type ()) +static GType +gst_v4l2_tv_norm_get_type (void) +{ + static GType v4l2_tv_norm = 0; + + if (!v4l2_tv_norm) { + static const GEnumValue tv_norms[] = { + {0, "none", "none"}, + {V4L2_STD_NTSC, "NTSC", "NTSC"}, + {V4L2_STD_NTSC_M, "NTSC-M", "NTSC-M"}, + {V4L2_STD_NTSC_M_JP, "NTSC-M-JP", "NTSC-M-JP"}, + {V4L2_STD_NTSC_M_KR, "NTSC-M-KR", "NTSC-M-KR"}, + {V4L2_STD_NTSC_443, "NTSC-443", "NTSC-443"}, + {V4L2_STD_PAL, "PAL", "PAL"}, + {V4L2_STD_PAL_BG, "PAL-BG", "PAL-BG"}, + {V4L2_STD_PAL_B, "PAL-B", "PAL-B"}, + {V4L2_STD_PAL_B1, "PAL-B1", "PAL-B1"}, + {V4L2_STD_PAL_G, "PAL-G", "PAL-G"}, + {V4L2_STD_PAL_H, "PAL-H", "PAL-H"}, + {V4L2_STD_PAL_I, "PAL-I", "PAL-I"}, + {V4L2_STD_PAL_DK, "PAL-DK", "PAL-DK"}, + {V4L2_STD_PAL_D, "PAL-D", "PAL-D"}, + {V4L2_STD_PAL_D1, "PAL-D1", "PAL-D1"}, + {V4L2_STD_PAL_K, "PAL-K", "PAL-K"}, + {V4L2_STD_PAL_M, "PAL-M", "PAL-M"}, + {V4L2_STD_PAL_N, "PAL-N", "PAL-N"}, + {V4L2_STD_PAL_Nc, "PAL-Nc", "PAL-Nc"}, + {V4L2_STD_PAL_60, "PAL-60", "PAL-60"}, + {V4L2_STD_SECAM, "SECAM", "SECAM"}, + {V4L2_STD_SECAM_B, "SECAM-B", "SECAM-B"}, + {V4L2_STD_SECAM_G, "SECAM-G", "SECAM-G"}, + {V4L2_STD_SECAM_H, "SECAM-H", "SECAM-H"}, + {V4L2_STD_SECAM_DK, "SECAM-DK", "SECAM-DK"}, + {V4L2_STD_SECAM_D, "SECAM-D", "SECAM-D"}, + {V4L2_STD_SECAM_K, "SECAM-K", "SECAM-K"}, + {V4L2_STD_SECAM_K1, "SECAM-K1", "SECAM-K1"}, + {V4L2_STD_SECAM_L, "SECAM-L", "SECAM-L"}, + {V4L2_STD_SECAM_LC, "SECAM-Lc", "SECAM-Lc"}, + {0, NULL, NULL} + }; + + v4l2_tv_norm = g_enum_register_static ("V4L2_TV_norms", tv_norms); + } + + return v4l2_tv_norm; +} + void gst_v4l2_object_install_properties_helper (GObjectClass * gobject_class, const char *default_device) @@ -377,6 +425,12 @@ gst_v4l2_object_install_properties_helper (GObjectClass * gobject_class, "Hue or color balance", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE)); + + g_object_class_install_property (gobject_class, PROP_TV_NORM, + g_param_spec_enum ("norm", "TV norm", + "video standard", + GST_TYPE_V4L2_TV_NORM, DEFAULT_PROP_TV_NORM, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); } GstV4l2Object * @@ -433,9 +487,6 @@ gst_v4l2_object_destroy (GstV4l2Object * v4l2object) if (v4l2object->channel) g_free (v4l2object->channel); - if (v4l2object->norm) - g_free (v4l2object->norm); - if (v4l2object->formats) { gst_v4l2_object_clear_format_list (v4l2object); } @@ -520,6 +571,9 @@ gst_v4l2_object_set_property_helper (GstV4l2Object * v4l2object, v4l2object->norm = g_value_dup_string (value); } break; + case PROP_TV_NORM: + v4l2object->tv_norm = g_value_get_enum (value); + break; case PROP_CHANNEL: if (GST_V4L2_IS_OPEN (v4l2object)) { GstTuner *tuner = GST_TUNER (v4l2object->element); @@ -624,6 +678,9 @@ gst_v4l2_object_get_property_helper (GstV4l2Object * v4l2object, return TRUE; } break; + case PROP_TV_NORM: + g_value_set_enum (value, v4l2object->tv_norm); + break; default: return FALSE; break; @@ -643,16 +700,18 @@ gst_v4l2_set_defaults (GstV4l2Object * v4l2object) tuner = GST_TUNER (v4l2object->element); - if (v4l2object->norm) - norm = gst_tuner_find_norm_by_name (tuner, v4l2object->norm); + if (v4l2object->tv_norm) + norm = gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm); + GST_DEBUG_OBJECT (v4l2object->element, "tv_norm=%llx, norm=%p", + v4l2object->tv_norm, norm); if (norm) { gst_tuner_set_norm (tuner, norm); } else { norm = GST_TUNER_NORM (gst_tuner_get_norm (GST_TUNER (v4l2object->element))); if (norm) { - g_free (v4l2object->norm); - v4l2object->norm = g_strdup (norm->label); + v4l2object->tv_norm = + gst_v4l2_tuner_get_std_id_by_norm (v4l2object, norm); gst_tuner_norm_changed (tuner, norm); } } @@ -1859,13 +1918,15 @@ default_frame_sizes: } /* Since we can't get framerate directly, try to use the current norm */ - if (v4l2object->norm && v4l2object->norms) { + if (v4l2object->tv_norm && v4l2object->norms) { GList *norms; GstTunerNorm *norm = NULL; + GstTunerNorm *current = + gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm); for (norms = v4l2object->norms; norms != NULL; norms = norms->next) { norm = (GstTunerNorm *) norms->data; - if (!strcmp (norm->label, v4l2object->norm)) + if (!strcmp (norm->label, current->label)) break; } /* If it's possible, set framerate to that (discrete) value */ diff --git a/sys/v4l2/gstv4l2object.h b/sys/v4l2/gstv4l2object.h index 1b38672..b21c27d 100644 --- a/sys/v4l2/gstv4l2object.h +++ b/sys/v4l2/gstv4l2object.h @@ -108,7 +108,7 @@ struct _GstV4l2Object { GList *channels; /* properties */ - gchar *norm; + v4l2_std_id tv_norm; gchar *channel; gulong frequency; @@ -137,7 +137,8 @@ GType gst_v4l2_object_get_type (void); PROP_BRIGHTNESS, \ PROP_CONTRAST, \ PROP_SATURATION, \ - PROP_HUE + PROP_HUE, \ + PROP_TV_NORM /* create/destroy */ GstV4l2Object * gst_v4l2_object_new (GstElement * element, diff --git a/sys/v4l2/gstv4l2sink.c b/sys/v4l2/gstv4l2sink.c index 421f639..9fce498 100644 --- a/sys/v4l2/gstv4l2sink.c +++ b/sys/v4l2/gstv4l2sink.c @@ -43,6 +43,7 @@ #include "gstv4l2colorbalance.h" +#include "gstv4l2tuner.h" #ifdef HAVE_XVIDEO #include "gstv4l2xoverlay.h" #endif @@ -79,6 +80,7 @@ enum GST_IMPLEMENT_V4L2_PROBE_METHODS (GstV4l2SinkClass, gst_v4l2sink); GST_IMPLEMENT_V4L2_COLOR_BALANCE_METHODS (GstV4l2Sink, gst_v4l2sink); +GST_IMPLEMENT_V4L2_TUNER_METHODS (GstV4l2Sink, gst_v4l2sink); #ifdef HAVE_XVIDEO GST_IMPLEMENT_V4L2_XOVERLAY_METHODS (GstV4l2Sink, gst_v4l2sink); #endif @@ -89,14 +91,12 @@ gst_v4l2sink_iface_supported (GstImplementsInterface * iface, GType iface_type) { GstV4l2Object *v4l2object = GST_V4L2SINK (iface)->v4l2object; + g_assert (iface_type == GST_TYPE_TUNER || #ifdef HAVE_XVIDEO - g_assert (iface_type == GST_TYPE_X_OVERLAY || + iface_type == GST_TYPE_X_OVERLAY || +#endif iface_type == GST_TYPE_COLOR_BALANCE || iface_type == GST_TYPE_VIDEO_ORIENTATION); -#else - g_assert (iface_type == GST_TYPE_COLOR_BALANCE || - iface_type == GST_TYPE_VIDEO_ORIENTATION); -#endif if (v4l2object->video_fd == -1) return FALSE; @@ -126,6 +126,11 @@ gst_v4l2sink_init_interfaces (GType type) NULL, NULL, }; + static const GInterfaceInfo v4l2_tuner_info = { + (GInterfaceInitFunc) gst_v4l2sink_tuner_interface_init, + NULL, + NULL, + }; #ifdef HAVE_XVIDEO static const GInterfaceInfo v4l2_xoverlay_info = { (GInterfaceInitFunc) gst_v4l2sink_xoverlay_interface_init, @@ -151,6 +156,7 @@ gst_v4l2sink_init_interfaces (GType type) g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE, &v4l2iface_info); + g_type_add_interface_static (type, GST_TYPE_TUNER, &v4l2_tuner_info); #ifdef HAVE_XVIDEO g_type_add_interface_static (type, GST_TYPE_X_OVERLAY, &v4l2_xoverlay_info); #endif diff --git a/sys/v4l2/gstv4l2tuner.c b/sys/v4l2/gstv4l2tuner.c index c5f8442..a805396 100644 --- a/sys/v4l2/gstv4l2tuner.c +++ b/sys/v4l2/gstv4l2tuner.c @@ -237,7 +237,6 @@ gst_v4l2_tuner_set_norm (GstV4l2Object * v4l2object, GstTunerNorm * norm) GstTunerNorm * gst_v4l2_tuner_get_norm (GstV4l2Object * v4l2object) { - GList *item; v4l2_std_id norm; /* assert that we're opened and that we're using a known item */ @@ -245,6 +244,14 @@ gst_v4l2_tuner_get_norm (GstV4l2Object * v4l2object) gst_v4l2_get_norm (v4l2object, &norm); + return gst_v4l2_tuner_get_norm_by_std_id (v4l2object, norm); +} + +GstTunerNorm * +gst_v4l2_tuner_get_norm_by_std_id (GstV4l2Object * v4l2object, v4l2_std_id norm) +{ + GList *item; + for (item = v4l2object->norms; item != NULL; item = item->next) { if (norm & GST_V4L2_TUNER_NORM (item->data)->index) return (GstTunerNorm *) item->data; @@ -253,6 +260,20 @@ gst_v4l2_tuner_get_norm (GstV4l2Object * v4l2object) return NULL; } +v4l2_std_id +gst_v4l2_tuner_get_std_id_by_norm (GstV4l2Object * v4l2object, + GstTunerNorm * norm) +{ + GList *item; + + for (item = v4l2object->norms; item != NULL; item = item->next) { + if (norm == GST_TUNER_NORM (item->data)) + return GST_V4L2_TUNER_NORM (item->data)->index; + } + + return 0; +} + void gst_v4l2_tuner_set_frequency_and_notify (GstV4l2Object * v4l2object, GstTunerChannel * channel, gulong frequency) diff --git a/sys/v4l2/gstv4l2tuner.h b/sys/v4l2/gstv4l2tuner.h index bf9ff94..699ca87 100644 --- a/sys/v4l2/gstv4l2tuner.h +++ b/sys/v4l2/gstv4l2tuner.h @@ -94,6 +94,11 @@ void gst_v4l2_tuner_set_norm_and_notify (GstV4l2Object * v4l2o GstTunerNorm* gst_v4l2_tuner_get_norm (GstV4l2Object * v4l2object); gboolean gst_v4l2_tuner_set_norm (GstV4l2Object * v4l2object, GstTunerNorm * norm); +GstTunerNorm* gst_v4l2_tuner_get_norm_by_std_id (GstV4l2Object * v4l2object, + v4l2_std_id norm); +v4l2_std_id gst_v4l2_tuner_get_std_id_by_norm (GstV4l2Object * v4l2object, + GstTunerNorm * norm); + /* frequency */ void gst_v4l2_tuner_set_frequency_and_notify (GstV4l2Object * v4l2object, GstTunerChannel * channel, diff --git a/sys/v4l2/v4l2_calls.c b/sys/v4l2/v4l2_calls.c index b4feef3..74b2e0a 100644 --- a/sys/v4l2/v4l2_calls.c +++ b/sys/v4l2/v4l2_calls.c @@ -226,6 +226,9 @@ gst_v4l2_fill_lists (GstV4l2Object * v4l2object) standard.frameperiod.denominator, standard.frameperiod.numerator); v4l2norm->index = standard.id; + GST_DEBUG_OBJECT (v4l2object->element, "index=%08x, label=%s", + (unsigned int) v4l2norm->index, norm->label); + v4l2object->norms = g_list_prepend (v4l2object->norms, (gpointer) norm); } v4l2object->norms = g_list_reverse (v4l2object->norms); -- 2.7.4