androidcamera: Store GParamSpec for properties and use that for the PropertyProbe comparison

This commit is contained in:
Youness Alaoui 2012-11-09 16:55:57 -05:00 committed by Nicolas Dufresne
parent dd78e052ae
commit 0a2530ef79

View file

@ -140,8 +140,11 @@ enum
PROP_FLICKER_MODE, PROP_FLICKER_MODE,
PROP_FOCUS_MODE, PROP_FOCUS_MODE,
PROP_ZOOM, PROP_ZOOM,
PROP_LAST
}; };
static GParamSpec *properties[PROP_LAST];
#define DEFAULT_DEVICE "0" #define DEFAULT_DEVICE "0"
GST_BOILERPLATE_FULL (GstAHCSrc, gst_ahc_src, GstPushSrc, GST_TYPE_PUSH_SRC, GST_BOILERPLATE_FULL (GstAHCSrc, gst_ahc_src, GstPushSrc, GST_TYPE_PUSH_SRC,
@ -237,55 +240,105 @@ gst_ahc_src_class_init (GstAHCSrcClass * klass)
gstpushsrc_class->create = gst_ahc_src_create; gstpushsrc_class->create = gst_ahc_src_create;
properties[PROP_DEVICE] = g_param_spec_string ("device",
"device", "Device ID", DEFAULT_DEVICE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, PROP_DEVICE, g_object_class_install_property (gobject_class, PROP_DEVICE,
g_param_spec_string ("device", "device", properties[PROP_DEVICE]);
"Device ID", DEFAULT_DEVICE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
properties[PROP_DEVICE_ORIENTATION] = g_param_spec_int ("device-orientation",
"Device orientation", "The orientation of the camera image",
0, 360, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, PROP_DEVICE_ORIENTATION, g_object_class_install_property (gobject_class, PROP_DEVICE_ORIENTATION,
g_param_spec_int ("device-orientation", "Device orientation", properties[PROP_DEVICE_ORIENTATION]);
"The orientation of the camera image",
0, 360, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_DEVICE_FACING, properties[PROP_DEVICE_FACING] = g_param_spec_enum ("device-facing",
g_param_spec_enum ("device-facing", "Device facing", "Device facing", "The direction that the camera faces",
"The direction that the camera faces",
GST_AHC_SRC_FACING_TYPE, CAMERA_FACING_BACK, GST_AHC_SRC_FACING_TYPE, CAMERA_FACING_BACK,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, PROP_DEVICE_FACING,
properties[PROP_DEVICE_FACING]);
/* Override GstPhotography properties */ /* Override GstPhotography properties */
g_object_class_override_property (gobject_class, PROP_WB_MODE, g_object_class_override_property (gobject_class, PROP_WB_MODE,
GST_PHOTOGRAPHY_PROP_WB_MODE); GST_PHOTOGRAPHY_PROP_WB_MODE);
properties[PROP_WB_MODE] = g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_WB_MODE);
g_object_class_override_property (gobject_class, PROP_COLOUR_TONE, g_object_class_override_property (gobject_class, PROP_COLOUR_TONE,
GST_PHOTOGRAPHY_PROP_COLOUR_TONE); GST_PHOTOGRAPHY_PROP_COLOUR_TONE);
properties[PROP_COLOUR_TONE] = g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_COLOUR_TONE);
g_object_class_override_property (gobject_class, PROP_SCENE_MODE, g_object_class_override_property (gobject_class, PROP_SCENE_MODE,
GST_PHOTOGRAPHY_PROP_SCENE_MODE); GST_PHOTOGRAPHY_PROP_SCENE_MODE);
properties[PROP_SCENE_MODE] = g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_SCENE_MODE);
g_object_class_override_property (gobject_class, PROP_FLASH_MODE, g_object_class_override_property (gobject_class, PROP_FLASH_MODE,
GST_PHOTOGRAPHY_PROP_FLASH_MODE); GST_PHOTOGRAPHY_PROP_FLASH_MODE);
properties[PROP_FLASH_MODE] = g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_FLASH_MODE);
g_object_class_override_property (gobject_class, PROP_NOISE_REDUCTION, g_object_class_override_property (gobject_class, PROP_NOISE_REDUCTION,
GST_PHOTOGRAPHY_PROP_NOISE_REDUCTION); GST_PHOTOGRAPHY_PROP_NOISE_REDUCTION);
properties[PROP_NOISE_REDUCTION] =
g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_NOISE_REDUCTION);
g_object_class_override_property (gobject_class, PROP_CAPABILITIES, g_object_class_override_property (gobject_class, PROP_CAPABILITIES,
GST_PHOTOGRAPHY_PROP_CAPABILITIES); GST_PHOTOGRAPHY_PROP_CAPABILITIES);
properties[PROP_CAPABILITIES] = g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_CAPABILITIES);
g_object_class_override_property (gobject_class, PROP_EV_COMP, g_object_class_override_property (gobject_class, PROP_EV_COMP,
GST_PHOTOGRAPHY_PROP_EV_COMP); GST_PHOTOGRAPHY_PROP_EV_COMP);
properties[PROP_EV_COMP] = g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_EV_COMP);
g_object_class_override_property (gobject_class, PROP_ISO_SPEED, g_object_class_override_property (gobject_class, PROP_ISO_SPEED,
GST_PHOTOGRAPHY_PROP_ISO_SPEED); GST_PHOTOGRAPHY_PROP_ISO_SPEED);
properties[PROP_ISO_SPEED] = g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_ISO_SPEED);
g_object_class_override_property (gobject_class, PROP_APERTURE, g_object_class_override_property (gobject_class, PROP_APERTURE,
GST_PHOTOGRAPHY_PROP_APERTURE); GST_PHOTOGRAPHY_PROP_APERTURE);
properties[PROP_APERTURE] = g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_APERTURE);
g_object_class_override_property (gobject_class, PROP_EXPOSURE, g_object_class_override_property (gobject_class, PROP_EXPOSURE,
GST_PHOTOGRAPHY_PROP_EXPOSURE); GST_PHOTOGRAPHY_PROP_EXPOSURE);
properties[PROP_EXPOSURE] = g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_EXPOSURE);
g_object_class_override_property (gobject_class, g_object_class_override_property (gobject_class,
PROP_IMAGE_CAPTURE_SUPPORTED_CAPS, PROP_IMAGE_CAPTURE_SUPPORTED_CAPS,
GST_PHOTOGRAPHY_PROP_IMAGE_CAPTURE_SUPPORTED_CAPS); GST_PHOTOGRAPHY_PROP_IMAGE_CAPTURE_SUPPORTED_CAPS);
properties[PROP_IMAGE_CAPTURE_SUPPORTED_CAPS] =
g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_IMAGE_CAPTURE_SUPPORTED_CAPS);
g_object_class_override_property (gobject_class, g_object_class_override_property (gobject_class,
PROP_IMAGE_PREVIEW_SUPPORTED_CAPS, PROP_IMAGE_PREVIEW_SUPPORTED_CAPS,
GST_PHOTOGRAPHY_PROP_IMAGE_PREVIEW_SUPPORTED_CAPS); GST_PHOTOGRAPHY_PROP_IMAGE_PREVIEW_SUPPORTED_CAPS);
properties[PROP_IMAGE_PREVIEW_SUPPORTED_CAPS] =
g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_IMAGE_PREVIEW_SUPPORTED_CAPS);
g_object_class_override_property (gobject_class, PROP_FLICKER_MODE, g_object_class_override_property (gobject_class, PROP_FLICKER_MODE,
GST_PHOTOGRAPHY_PROP_FLICKER_MODE); GST_PHOTOGRAPHY_PROP_FLICKER_MODE);
properties[PROP_FLICKER_MODE] = g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_FLICKER_MODE);
g_object_class_override_property (gobject_class, PROP_FOCUS_MODE, g_object_class_override_property (gobject_class, PROP_FOCUS_MODE,
GST_PHOTOGRAPHY_PROP_FOCUS_MODE); GST_PHOTOGRAPHY_PROP_FOCUS_MODE);
properties[PROP_FOCUS_MODE] = g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_FOCUS_MODE);
g_object_class_override_property (gobject_class, PROP_ZOOM, g_object_class_override_property (gobject_class, PROP_ZOOM,
GST_PHOTOGRAPHY_PROP_ZOOM); GST_PHOTOGRAPHY_PROP_ZOOM);
properties[PROP_ZOOM] = g_object_class_find_property (gobject_class,
GST_PHOTOGRAPHY_PROP_ZOOM);
klass->probe_properties = NULL; klass->probe_properties = NULL;
} }
@ -532,19 +585,16 @@ gst_ahc_src_implements_interface_init (GstImplementsInterfaceClass * klass)
static const GList * static const GList *
gst_ahc_src_probe_get_properties (GstPropertyProbe * probe) gst_ahc_src_probe_get_properties (GstPropertyProbe * probe)
{ {
GObjectClass *klass = G_OBJECT_GET_CLASS (probe);
GstAHCSrcClass *ahc_class = GST_AHC_SRC_CLASS (probe); GstAHCSrcClass *ahc_class = GST_AHC_SRC_CLASS (probe);
GList **list = &ahc_class->probe_properties;
if (!ahc_class->probe_properties) { if (!*list) {
ahc_class->probe_properties = g_list_append (NULL, *list = g_list_append (*list, properties[PROP_DEVICE]);
g_object_class_find_property (klass, "device")); *list = g_list_append (*list, properties[PROP_EV_COMP]);
ahc_class->probe_properties = g_list_append (ahc_class->probe_properties, *list = g_list_append (*list, properties[PROP_ZOOM]);
g_object_class_find_property (klass, GST_PHOTOGRAPHY_PROP_EV_COMP));
ahc_class->probe_properties = g_list_append (ahc_class->probe_properties,
g_object_class_find_property (klass, GST_PHOTOGRAPHY_PROP_ZOOM));
} }
return ahc_class->probe_properties; return *list;
} }
static GValueArray * static GValueArray *
@ -554,8 +604,10 @@ gst_ahc_src_probe_get_values (GstPropertyProbe * probe,
GstAHCSrc *self = GST_AHC_SRC (probe); GstAHCSrc *self = GST_AHC_SRC (probe);
GValueArray *array = NULL; GValueArray *array = NULL;
switch (prop_id) { /* g_object_class_find_property returns overriden property with
case PROP_DEVICE:{ * param_id == 0, so we can't switch/case the prop_id and
* we need to check the pspec instead */
if (pspec == properties[PROP_DEVICE]) {
GValue value = { 0 }; GValue value = { 0 };
gint num_cams = gst_ah_camera_get_number_of_cameras (); gint num_cams = gst_ah_camera_get_number_of_cameras ();
gint i; gint i;
@ -567,15 +619,7 @@ gst_ahc_src_probe_get_values (GstPropertyProbe * probe,
g_value_array_append (array, &value); g_value_array_append (array, &value);
} }
g_value_unset (&value); g_value_unset (&value);
} } else if (pspec == properties[PROP_EV_COMP]) {
break;
default:
/* g_object_class_find_property returns overriden property with
* param_id == 0, so we can't switch/case the prop_id and
* g_param_spec_get_redirect_target() returns NULL, so we need to
* do a strcmp on the property's name instead */
if (!g_strcmp0 (pspec->name, GST_PHOTOGRAPHY_PROP_EV_COMP)) {
//case PROP_EV_COMP:
if (self->camera) { if (self->camera) {
GstAHCParameters *params; GstAHCParameters *params;
@ -596,7 +640,6 @@ gst_ahc_src_probe_get_values (GstPropertyProbe * probe,
array = g_value_array_new (max - min + 1); array = g_value_array_new (max - min + 1);
g_value_init (&value, G_TYPE_FLOAT); g_value_init (&value, G_TYPE_FLOAT);
for (i = min; i <= max; i++) { for (i = min; i <= max; i++) {
/* floats are bad... :( */
g_value_set_float (&value, step * i); g_value_set_float (&value, step * i);
g_value_array_append (array, &value); g_value_array_append (array, &value);
} }
@ -606,8 +649,7 @@ gst_ahc_src_probe_get_values (GstPropertyProbe * probe,
gst_ahc_parameters_free (params); gst_ahc_parameters_free (params);
} }
} }
} else if (!g_strcmp0 (pspec->name, GST_PHOTOGRAPHY_PROP_ZOOM)) { } else if (pspec == properties[PROP_ZOOM]) {
//case PROP_ZOOM:
if (self->camera) { if (self->camera) {
GstAHCParameters *params; GstAHCParameters *params;
@ -637,8 +679,6 @@ gst_ahc_src_probe_get_values (GstPropertyProbe * probe,
} else { } else {
G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
} }
break;
}
return array; return array;
} }