camerabin2: check negotiated caps avoid reseting of the pipe

To avoid useless renegotiation of the pipe we can check for
negotiated caps on src_filter and compare it with requested
filter. If the caps intersect, avoid restart.

Signed-off-by: Oleksij Rempel <bug-track@fisher-privat.net>

https://bugzilla.gnome.org/show_bug.cgi?id=672610
This commit is contained in:
Oleksij Rempel 2012-03-22 08:47:57 +01:00 committed by Thiago Santos
parent 2eac423273
commit e8a3973b8f
2 changed files with 40 additions and 15 deletions

View file

@ -92,6 +92,10 @@ gst_wrapper_camera_bin_src_dispose (GObject * object)
gst_object_unref (self->app_vid_filter); gst_object_unref (self->app_vid_filter);
self->app_vid_filter = NULL; self->app_vid_filter = NULL;
} }
if (self->srcfilter_pad) {
gst_object_unref (self->srcfilter_pad);
self->srcfilter_pad = NULL;
}
gst_caps_replace (&self->image_capture_caps, NULL); gst_caps_replace (&self->image_capture_caps, NULL);
G_OBJECT_CLASS (parent_class)->dispose (object); G_OBJECT_CLASS (parent_class)->dispose (object);
@ -169,23 +173,45 @@ gst_wrapper_camera_bin_src_get_property (GObject * object,
static void static void
gst_wrapper_camera_bin_reset_video_src_caps (GstWrapperCameraBinSrc * self, gst_wrapper_camera_bin_reset_video_src_caps (GstWrapperCameraBinSrc * self,
GstCaps * caps) GstCaps * new_filter_caps)
{ {
GST_DEBUG_OBJECT (self, "Resetting src caps to %" GST_PTR_FORMAT, caps); GST_DEBUG_OBJECT (self, "Resetting src caps to %" GST_PTR_FORMAT,
new_filter_caps);
if (self->src_vid_src) { if (self->src_vid_src) {
GstCaps *old_caps; GstCaps *src_neg_caps; /* negotiated caps on src_filter */
gboolean ret = FALSE;
g_object_get (G_OBJECT (self->src_filter), "caps", &old_caps, NULL); /* After pipe was negotiated src_filter do not have any filter caps.
if (gst_caps_is_equal (caps, old_caps)) { * In this situation we should compare neogotiated caps on capsfilter pad
GST_DEBUG_OBJECT (self, "old and new caps are same, do not reset it"); * with requested range of caps. If one of this caps intersect,
if (old_caps) * then we can avoid reseting.
gst_caps_unref (old_caps); */
src_neg_caps = gst_pad_get_current_caps (self->srcfilter_pad);
if (src_neg_caps && new_filter_caps && gst_caps_is_fixed (new_filter_caps))
ret = gst_caps_can_intersect (src_neg_caps, new_filter_caps);
else if (new_filter_caps == NULL) {
/* If new_filter_caps = NULL, then some body wont to empty
* capsfilter (set to ANY). In this case we will need to reset pipe,
* but if capsfilter is actually empthy, then we can avoid
* one more reseting.
*/
GstCaps *old_filter_caps; /* range of caps on capsfilter */
g_object_get (G_OBJECT (self->src_filter),
"caps", &old_filter_caps, NULL);
ret = gst_caps_is_any (old_filter_caps);
gst_caps_unref (old_filter_caps);
}
if (src_neg_caps)
gst_caps_unref (src_neg_caps);
if (ret) {
GST_DEBUG_OBJECT (self, "Negotiated caps on srcfilter intersect "
"with requested caps, do not reset it.");
return; return;
} }
if (old_caps)
gst_caps_unref (old_caps);
set_capsfilter_caps (self, caps); set_capsfilter_caps (self, new_filter_caps);
} }
} }
@ -537,7 +563,6 @@ gst_wrapper_camera_bin_src_construct_pipeline (GstBaseCameraSrc * bcamsrc)
gboolean ret = FALSE; gboolean ret = FALSE;
GstPad *vf_pad; GstPad *vf_pad;
GstPad *tee_capture_pad; GstPad *tee_capture_pad;
GstPad *src_caps_src_pad;
/* checks and adds a new video src if needed */ /* checks and adds a new video src if needed */
if (!check_and_replace_src (self)) if (!check_and_replace_src (self))
@ -569,10 +594,9 @@ gst_wrapper_camera_bin_src_construct_pipeline (GstBaseCameraSrc * bcamsrc)
/* attach to notify::caps on the first capsfilter and use a callback /* attach to notify::caps on the first capsfilter and use a callback
* to recalculate the zoom properties when these caps change and to * to recalculate the zoom properties when these caps change and to
* propagate the caps to the second capsfilter */ * propagate the caps to the second capsfilter */
src_caps_src_pad = gst_element_get_static_pad (self->src_filter, "src"); self->srcfilter_pad = gst_element_get_static_pad (self->src_filter, "src");
g_signal_connect (src_caps_src_pad, "notify::caps", g_signal_connect (self->srcfilter_pad, "notify::caps",
G_CALLBACK (gst_wrapper_camera_bin_src_caps_cb), self); G_CALLBACK (gst_wrapper_camera_bin_src_caps_cb), self);
gst_object_unref (src_caps_src_pad);
if (!(self->src_zoom_crop = if (!(self->src_zoom_crop =
gst_camerabin_create_and_add_element (cbin, "videocrop", gst_camerabin_create_and_add_element (cbin, "videocrop",

View file

@ -63,6 +63,7 @@ struct _GstWrapperCameraBinSrc
GstCameraBinMode mode; GstCameraBinMode mode;
GstPad *srcfilter_pad;
GstPad *vfsrc; GstPad *vfsrc;
GstPad *imgsrc; GstPad *imgsrc;
GstPad *vidsrc; GstPad *vidsrc;