update for basetransform lock removal

This commit is contained in:
Wim Taymans 2012-02-23 11:16:21 +01:00
parent c762e945be
commit 7749cd3f7b
5 changed files with 55 additions and 39 deletions

View file

@ -255,6 +255,8 @@ gst_spectrum_init (GstSpectrum * spectrum)
spectrum->interval = DEFAULT_INTERVAL; spectrum->interval = DEFAULT_INTERVAL;
spectrum->bands = DEFAULT_BANDS; spectrum->bands = DEFAULT_BANDS;
spectrum->threshold = DEFAULT_THRESHOLD; spectrum->threshold = DEFAULT_THRESHOLD;
g_mutex_init (&spectrum->lock);
} }
static void static void
@ -334,6 +336,7 @@ gst_spectrum_finalize (GObject * object)
GstSpectrum *spectrum = GST_SPECTRUM (object); GstSpectrum *spectrum = GST_SPECTRUM (object);
gst_spectrum_reset_state (spectrum); gst_spectrum_reset_state (spectrum);
g_mutex_clear (&spectrum->lock);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -356,37 +359,37 @@ gst_spectrum_set_property (GObject * object, guint prop_id,
break; break;
case PROP_INTERVAL:{ case PROP_INTERVAL:{
guint64 interval = g_value_get_uint64 (value); guint64 interval = g_value_get_uint64 (value);
g_mutex_lock (&filter->lock);
if (filter->interval != interval) { if (filter->interval != interval) {
GST_BASE_TRANSFORM_LOCK (filter);
filter->interval = interval; filter->interval = interval;
gst_spectrum_reset_state (filter); gst_spectrum_reset_state (filter);
GST_BASE_TRANSFORM_UNLOCK (filter);
}
} }
g_mutex_unlock (&filter->lock);
break; break;
}
case PROP_BANDS:{ case PROP_BANDS:{
guint bands = g_value_get_uint (value); guint bands = g_value_get_uint (value);
g_mutex_lock (&filter->lock);
if (filter->bands != bands) { if (filter->bands != bands) {
GST_BASE_TRANSFORM_LOCK (filter);
filter->bands = bands; filter->bands = bands;
gst_spectrum_reset_state (filter); gst_spectrum_reset_state (filter);
GST_BASE_TRANSFORM_UNLOCK (filter);
}
} }
g_mutex_unlock (&filter->lock);
break; break;
}
case PROP_THRESHOLD: case PROP_THRESHOLD:
filter->threshold = g_value_get_int (value); filter->threshold = g_value_get_int (value);
break; break;
case PROP_MULTI_CHANNEL:{ case PROP_MULTI_CHANNEL:{
gboolean multi_channel = g_value_get_boolean (value); gboolean multi_channel = g_value_get_boolean (value);
g_mutex_lock (&filter->lock);
if (filter->multi_channel != multi_channel) { if (filter->multi_channel != multi_channel) {
GST_BASE_TRANSFORM_LOCK (filter);
filter->multi_channel = multi_channel; filter->multi_channel = multi_channel;
gst_spectrum_reset_state (filter); gst_spectrum_reset_state (filter);
GST_BASE_TRANSFORM_UNLOCK (filter);
}
} }
g_mutex_unlock (&filter->lock);
break; break;
}
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -622,6 +625,7 @@ gst_spectrum_setup (GstAudioFilter * base, const GstAudioInfo * info)
gboolean multi_channel = spectrum->multi_channel; gboolean multi_channel = spectrum->multi_channel;
GstSpectrumInputData input_data = NULL; GstSpectrumInputData input_data = NULL;
g_mutex_lock (&spectrum->lock);
switch (GST_AUDIO_INFO_FORMAT (info)) { switch (GST_AUDIO_INFO_FORMAT (info)) {
case GST_AUDIO_FORMAT_S16: case GST_AUDIO_FORMAT_S16:
input_data = input_data =
@ -648,6 +652,7 @@ gst_spectrum_setup (GstAudioFilter * base, const GstAudioInfo * info)
spectrum->input_data = input_data; spectrum->input_data = input_data;
gst_spectrum_reset_state (spectrum); gst_spectrum_reset_state (spectrum);
g_mutex_unlock (&spectrum->lock);
return TRUE; return TRUE;
} }
@ -865,6 +870,7 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
GstSpectrumChannel *cd; GstSpectrumChannel *cd;
GstSpectrumInputData input_data; GstSpectrumInputData input_data;
g_mutex_lock (&spectrum->lock);
gst_buffer_map (buffer, &map, GST_MAP_READ); gst_buffer_map (buffer, &map, GST_MAP_READ);
data = map.data; data = map.data;
size = map.size; size = map.size;
@ -997,6 +1003,7 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
spectrum->input_pos = input_pos; spectrum->input_pos = input_pos;
gst_buffer_unmap (buffer, &map); gst_buffer_unmap (buffer, &map);
g_mutex_unlock (&spectrum->lock);
g_assert (size == 0); g_assert (size == 0);

View file

@ -78,6 +78,8 @@ struct _GstSpectrum
guint64 error_per_interval; guint64 error_per_interval;
guint64 accumulated_error; guint64 accumulated_error;
GMutex lock;
GstSpectrumInputData input_data; GstSpectrumInputData input_data;
}; };

View file

@ -97,6 +97,8 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
#define gst_video_crop_parent_class parent_class #define gst_video_crop_parent_class parent_class
G_DEFINE_TYPE (GstVideoCrop, gst_video_crop, GST_TYPE_BASE_TRANSFORM); G_DEFINE_TYPE (GstVideoCrop, gst_video_crop, GST_TYPE_BASE_TRANSFORM);
static void gst_video_crop_finalize (GObject * object);
static void gst_video_crop_set_property (GObject * object, guint prop_id, static void gst_video_crop_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
static void gst_video_crop_get_property (GObject * object, guint prop_id, static void gst_video_crop_get_property (GObject * object, guint prop_id,
@ -155,6 +157,7 @@ gst_video_crop_src_event (GstBaseTransform * trans, GstEvent * event)
} }
GST_OBJECT_UNLOCK (vcrop); GST_OBJECT_UNLOCK (vcrop);
return GST_BASE_TRANSFORM_CLASS (parent_class)->src_event (trans, return GST_BASE_TRANSFORM_CLASS (parent_class)->src_event (trans,
(new_event ? new_event : event)); (new_event ? new_event : event));
} }
@ -170,25 +173,7 @@ gst_video_crop_class_init (GstVideoCropClass * klass)
element_class = (GstElementClass *) klass; element_class = (GstElementClass *) klass;
basetransform_class = (GstBaseTransformClass *) klass; basetransform_class = (GstBaseTransformClass *) klass;
gst_element_class_set_details_simple (element_class, "Crop", gobject_class->finalize = gst_video_crop_finalize;
"Filter/Effect/Video",
"Crops video into a user-defined region",
"Tim-Philipp Müller <tim centricular net>");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_template));
gst_element_class_set_details_simple (element_class, "Crop",
"Filter/Effect/Video",
"Crops video into a user-defined region",
"Tim-Philipp Müller <tim centricular net>");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_template));
gobject_class->set_property = gst_video_crop_set_property; gobject_class->set_property = gst_video_crop_set_property;
gobject_class->get_property = gst_video_crop_get_property; gobject_class->get_property = gst_video_crop_get_property;
@ -205,6 +190,15 @@ gst_video_crop_class_init (GstVideoCropClass * klass)
g_param_spec_int ("bottom", "Bottom", "Pixels to crop at bottom", g_param_spec_int ("bottom", "Bottom", "Pixels to crop at bottom",
0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_template));
gst_element_class_set_details_simple (element_class, "Crop",
"Filter/Effect/Video",
"Crops video into a user-defined region",
"Tim-Philipp Müller <tim centricular net>");
basetransform_class->transform = GST_DEBUG_FUNCPTR (gst_video_crop_transform); basetransform_class->transform = GST_DEBUG_FUNCPTR (gst_video_crop_transform);
basetransform_class->transform_caps = basetransform_class->transform_caps =
GST_DEBUG_FUNCPTR (gst_video_crop_transform_caps); GST_DEBUG_FUNCPTR (gst_video_crop_transform_caps);
@ -223,6 +217,20 @@ gst_video_crop_init (GstVideoCrop * vcrop)
vcrop->crop_left = 0; vcrop->crop_left = 0;
vcrop->crop_top = 0; vcrop->crop_top = 0;
vcrop->crop_bottom = 0; vcrop->crop_bottom = 0;
g_mutex_init (&vcrop->lock);
}
static void
gst_video_crop_finalize (GObject * object)
{
GstVideoCrop *vcrop;
vcrop = GST_VIDEO_CROP (object);
g_mutex_clear (&vcrop->lock);
G_OBJECT_CLASS (parent_class)->finalize (object);
} }
static gboolean static gboolean
@ -465,6 +473,7 @@ gst_video_crop_transform (GstBaseTransform * trans, GstBuffer * inbuf,
{ {
GstVideoCrop *vcrop = GST_VIDEO_CROP (trans); GstVideoCrop *vcrop = GST_VIDEO_CROP (trans);
g_mutex_lock (&vcrop->lock);
switch (vcrop->in.packing) { switch (vcrop->in.packing) {
case VIDEO_CROP_PIXEL_FORMAT_PACKED_SIMPLE: case VIDEO_CROP_PIXEL_FORMAT_PACKED_SIMPLE:
gst_video_crop_transform_packed_simple (vcrop, inbuf, outbuf); gst_video_crop_transform_packed_simple (vcrop, inbuf, outbuf);
@ -478,6 +487,7 @@ gst_video_crop_transform (GstBaseTransform * trans, GstBuffer * inbuf,
default: default:
g_assert_not_reached (); g_assert_not_reached ();
} }
g_mutex_unlock (&vcrop->lock);
return GST_FLOW_OK; return GST_FLOW_OK;
} }
@ -635,8 +645,8 @@ gst_video_crop_set_caps (GstBaseTransform * trans, GstCaps * incaps,
GST_LOG_OBJECT (crop, "incaps = %" GST_PTR_FORMAT ", outcaps = %" GST_LOG_OBJECT (crop, "incaps = %" GST_PTR_FORMAT ", outcaps = %"
GST_PTR_FORMAT, incaps, outcaps); GST_PTR_FORMAT, incaps, outcaps);
if ((crop->crop_left | crop->crop_right | crop->crop_top | crop-> if ((crop->crop_left | crop->crop_right | crop->
crop_bottom) == 0) { crop_top | crop->crop_bottom) == 0) {
GST_LOG_OBJECT (crop, "we are using passthrough"); GST_LOG_OBJECT (crop, "we are using passthrough");
gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (crop), TRUE); gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (crop), TRUE);
} else { } else {
@ -675,7 +685,7 @@ gst_video_crop_set_property (GObject * object, guint prop_id,
video_crop = GST_VIDEO_CROP (object); video_crop = GST_VIDEO_CROP (object);
/* don't modify while we are transforming */ /* don't modify while we are transforming */
GST_BASE_TRANSFORM_LOCK (GST_BASE_TRANSFORM_CAST (video_crop)); g_mutex_lock (&video_crop->lock);
/* protect with the object lock so that we can read them */ /* protect with the object lock so that we can read them */
GST_OBJECT_LOCK (video_crop); GST_OBJECT_LOCK (video_crop);
@ -696,14 +706,13 @@ gst_video_crop_set_property (GObject * object, guint prop_id,
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
} }
GST_OBJECT_UNLOCK (video_crop);
GST_LOG_OBJECT (video_crop, "l=%d,r=%d,b=%d,t=%d", GST_LOG_OBJECT (video_crop, "l=%d,r=%d,b=%d,t=%d",
video_crop->crop_left, video_crop->crop_right, video_crop->crop_bottom, video_crop->crop_left, video_crop->crop_right, video_crop->crop_bottom,
video_crop->crop_top); video_crop->crop_top);
GST_OBJECT_UNLOCK (video_crop);
gst_base_transform_reconfigure (GST_BASE_TRANSFORM (video_crop)); gst_base_transform_reconfigure (GST_BASE_TRANSFORM (video_crop));
GST_BASE_TRANSFORM_UNLOCK (GST_BASE_TRANSFORM_CAST (video_crop)); g_mutex_unlock (&video_crop->lock);
} }
static void static void

View file

@ -68,6 +68,8 @@ struct _GstVideoCrop
GstVideoCropImageDetails in; /* details of input image */ GstVideoCropImageDetails in; /* details of input image */
GstVideoCropImageDetails out; /* details of output image */ GstVideoCropImageDetails out; /* details of output image */
GMutex lock;
}; };
struct _GstVideoCropClass struct _GstVideoCropClass

View file

@ -432,7 +432,7 @@ gst_video_balance_transform_frame_ip (GstVideoFilter * vfilter,
goto not_negotiated; goto not_negotiated;
/* if no change is needed, we are done */ /* if no change is needed, we are done */
if (GST_BASE_TRANSFORM (vfilter)->passthrough) if (gst_base_transform_is_passthrough (GST_BASE_TRANSFORM (vfilter)))
goto done; goto done;
GST_OBJECT_LOCK (videobalance); GST_OBJECT_LOCK (videobalance);
@ -584,7 +584,6 @@ gst_video_balance_colorbalance_set_value (GstColorBalance * balance,
g_return_if_fail (GST_IS_VIDEO_FILTER (vb)); g_return_if_fail (GST_IS_VIDEO_FILTER (vb));
g_return_if_fail (channel->label != NULL); g_return_if_fail (channel->label != NULL);
GST_BASE_TRANSFORM_LOCK (vb);
GST_OBJECT_LOCK (vb); GST_OBJECT_LOCK (vb);
if (!g_ascii_strcasecmp (channel->label, "HUE")) { if (!g_ascii_strcasecmp (channel->label, "HUE")) {
new_val = (value + 1000.0) * 2.0 / 2000.0 - 1.0; new_val = (value + 1000.0) * 2.0 / 2000.0 - 1.0;
@ -607,7 +606,6 @@ gst_video_balance_colorbalance_set_value (GstColorBalance * balance,
if (changed) if (changed)
gst_video_balance_update_properties (vb); gst_video_balance_update_properties (vb);
GST_OBJECT_UNLOCK (vb); GST_OBJECT_UNLOCK (vb);
GST_BASE_TRANSFORM_UNLOCK (vb);
if (changed) { if (changed) {
gst_color_balance_value_changed (balance, channel, gst_color_balance_value_changed (balance, channel,
@ -670,7 +668,6 @@ gst_video_balance_set_property (GObject * object, guint prop_id,
gdouble d; gdouble d;
const gchar *label = NULL; const gchar *label = NULL;
GST_BASE_TRANSFORM_LOCK (balance);
GST_OBJECT_LOCK (balance); GST_OBJECT_LOCK (balance);
switch (prop_id) { switch (prop_id) {
case PROP_CONTRAST: case PROP_CONTRAST:
@ -712,7 +709,6 @@ gst_video_balance_set_property (GObject * object, guint prop_id,
gst_video_balance_update_properties (balance); gst_video_balance_update_properties (balance);
GST_OBJECT_UNLOCK (balance); GST_OBJECT_UNLOCK (balance);
GST_BASE_TRANSFORM_UNLOCK (balance);
if (label) { if (label) {
GstColorBalanceChannel *channel = GstColorBalanceChannel *channel =