};
/* we support the same caps as videocrop */
-#define ASPECT_RATIO_CROP_CAPS \
- GST_VIDEO_CAPS_RGBx ";" \
- GST_VIDEO_CAPS_xRGB ";" \
- GST_VIDEO_CAPS_BGRx ";" \
- GST_VIDEO_CAPS_xBGR ";" \
- GST_VIDEO_CAPS_RGBA ";" \
- GST_VIDEO_CAPS_ARGB ";" \
- GST_VIDEO_CAPS_BGRA ";" \
- GST_VIDEO_CAPS_ABGR ";" \
- GST_VIDEO_CAPS_RGB ";" \
- GST_VIDEO_CAPS_BGR ";" \
- GST_VIDEO_CAPS_YUV ("AYUV") ";" \
- GST_VIDEO_CAPS_YUV ("YUY2") ";" \
- GST_VIDEO_CAPS_YUV ("YVYU") ";" \
- GST_VIDEO_CAPS_YUV ("UYVY") ";" \
- GST_VIDEO_CAPS_YUV ("Y800") ";" \
- GST_VIDEO_CAPS_YUV ("I420") ";" \
- GST_VIDEO_CAPS_YUV ("YV12") ";" \
- GST_VIDEO_CAPS_RGB_16 ";" \
- GST_VIDEO_CAPS_RGB_15
+#define ASPECT_RATIO_CROP_CAPS \
+ GST_VIDEO_CAPS_MAKE ("{ RGBx, xRGB, BGRx, xBGR, " \
+ "RGBA, ARGB, BGRA, ABGR, RGB, BGR, AYUV, YUY2, " \
+ "YVYU, UYVY, Y800, I420, RGB16, RGB15, GRAY8 }")
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_STATIC_CAPS (ASPECT_RATIO_CROP_CAPS)
);
-GST_BOILERPLATE (GstAspectRatioCrop, gst_aspect_ratio_crop, GstBin,
- GST_TYPE_BIN);
+#define gst_aspect_ratio_crop_parent_class parent_class
+G_DEFINE_TYPE (GstAspectRatioCrop, gst_aspect_ratio_crop, GST_TYPE_BIN);
static void gst_aspect_ratio_crop_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
GValue * value, GParamSpec * pspec);
static void gst_aspect_ratio_crop_set_cropping (GstAspectRatioCrop *
aspect_ratio_crop, gint top, gint right, gint bottom, gint left);
-static GstCaps *gst_aspect_ratio_crop_get_caps (GstPad * pad);
-static gboolean gst_aspect_ratio_crop_set_caps (GstPad * pad, GstCaps * caps);
+static GstCaps *gst_aspect_ratio_crop_get_caps (GstPad * pad, GstCaps * filter);
+static gboolean gst_aspect_ratio_crop_set_caps (GstAspectRatioCrop *
+ aspect_ratio_crop, GstCaps * caps);
+static gboolean gst_aspect_ratio_crop_sink_event (GstPad * pad, GstEvent * evt);
static void gst_aspect_ratio_crop_finalize (GObject * object);
static void gst_aspect_ratio_transform_structure (GstAspectRatioCrop *
aspect_ratio_crop, GstStructure * structure, GstStructure ** new_structure,
}
static gboolean
-gst_aspect_ratio_crop_set_caps (GstPad * pad, GstCaps * caps)
+gst_aspect_ratio_crop_set_caps (GstAspectRatioCrop * aspect_ratio_crop,
+ GstCaps * caps)
{
- GstAspectRatioCrop *aspect_ratio_crop;
GstPad *peer_pad;
GstStructure *structure;
gboolean ret;
- aspect_ratio_crop = GST_ASPECT_RATIO_CROP (gst_pad_get_parent (pad));
-
g_mutex_lock (aspect_ratio_crop->crop_lock);
structure = gst_caps_get_structure (caps, 0);
"sink");
ret = gst_pad_set_caps (peer_pad, caps);
gst_object_unref (peer_pad);
- gst_object_unref (aspect_ratio_crop);
g_mutex_unlock (aspect_ratio_crop->crop_lock);
return ret;
}
-static void
-gst_aspect_ratio_crop_base_init (gpointer g_class)
+static gboolean
+gst_aspect_ratio_crop_sink_event (GstPad * pad, GstEvent * evt)
{
- GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+ gboolean ret;
+ GstAspectRatioCrop *aspect_ratio_crop =
+ GST_ASPECT_RATIO_CROP (gst_pad_get_parent (pad));
- gst_element_class_set_details_simple (element_class, "aspectratiocrop",
- "Filter/Effect/Video",
- "Crops video into a user-defined aspect-ratio",
- "Thijs Vermeir <thijsvermeir@gmail.com>");
+ ret = aspect_ratio_crop->sinkpad_old_eventfunc (pad, gst_event_ref (evt));
- 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));
+ switch (GST_EVENT_TYPE (evt)) {
+ case GST_EVENT_CAPS:
+ {
+ GstCaps *caps;
+
+ gst_event_parse_caps (evt, &caps);
+ ret = gst_aspect_ratio_crop_set_caps (aspect_ratio_crop, caps);
+ gst_caps_unref (caps);
+ break;
+ }
+ default:
+ break;
+ }
+
+ gst_object_unref (aspect_ratio_crop);
+ gst_event_unref (evt);
+ return ret;
}
static void
gst_aspect_ratio_crop_class_init (GstAspectRatioCropClass * klass)
{
GObjectClass *gobject_class;
+ GstElementClass *element_class;
gobject_class = (GObjectClass *) klass;
+ element_class = (GstElementClass *) klass;
gobject_class->set_property = gst_aspect_ratio_crop_set_property;
gobject_class->get_property = gst_aspect_ratio_crop_get_property;
gst_param_spec_fraction ("aspect-ratio", "aspect-ratio",
"Target aspect-ratio of video", 0, 1, G_MAXINT, 1, 0, 1,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ gst_element_class_set_details_simple (element_class, "aspectratiocrop",
+ "Filter/Effect/Video",
+ "Crops video into a user-defined aspect-ratio",
+ "Thijs Vermeir <thijsvermeir@gmail.com>");
+
+ 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));
}
static void
}
static void
-gst_aspect_ratio_crop_init (GstAspectRatioCrop * aspect_ratio_crop,
- GstAspectRatioCropClass * klass)
+gst_aspect_ratio_crop_init (GstAspectRatioCrop * aspect_ratio_crop)
{
GstPad *link_pad;
GstPad *src_pad;
gst_element_add_pad (GST_ELEMENT (aspect_ratio_crop),
aspect_ratio_crop->sink);
gst_object_unref (link_pad);
- gst_pad_set_setcaps_function (aspect_ratio_crop->sink,
- GST_DEBUG_FUNCPTR (gst_aspect_ratio_crop_set_caps));
+
+ aspect_ratio_crop->sinkpad_old_eventfunc =
+ GST_PAD_EVENTFUNC (aspect_ratio_crop->sink);
+ gst_pad_set_event_function (aspect_ratio_crop->sink,
+ GST_DEBUG_FUNCPTR (gst_aspect_ratio_crop_sink_event));
}
static void
}
static GstCaps *
-gst_aspect_ratio_crop_get_caps (GstPad * pad)
+gst_aspect_ratio_crop_get_caps (GstPad * pad, GstCaps * filter)
{
GstPad *peer;
GstAspectRatioCrop *aspect_ratio_crop;
} else {
GstCaps *peer_caps;
- peer_caps = gst_pad_get_caps (peer);
+ peer_caps = gst_pad_get_caps (peer, filter);
return_caps =
gst_aspect_ratio_crop_transform_caps (aspect_ratio_crop, peer_caps);
gst_caps_unref (peer_caps);
g_mutex_unlock (aspect_ratio_crop->crop_lock);
gst_object_unref (aspect_ratio_crop);
+ if (return_caps && filter) {
+ GstCaps *tmp =
+ gst_caps_intersect_full (filter, return_caps, GST_CAPS_INTERSECT_FIRST);
+ gst_caps_replace (&return_caps, tmp);
+ gst_caps_unref (tmp);
+ }
+
return return_caps;
}
aspect_ratio_crop->ar_num = gst_value_get_fraction_numerator (value);
aspect_ratio_crop->ar_denom =
gst_value_get_fraction_denominator (value);
- recheck = (GST_PAD_CAPS (aspect_ratio_crop->sink) != NULL);
+ recheck = gst_pad_has_current_caps (aspect_ratio_crop->sink);
}
break;
default:
GST_OBJECT_UNLOCK (aspect_ratio_crop);
if (recheck) {
- gst_aspect_ratio_crop_set_caps (aspect_ratio_crop->sink,
- GST_PAD_CAPS (aspect_ratio_crop->sink));
+ GstCaps *caps = gst_pad_get_current_caps (aspect_ratio_crop->sink);
+ gst_aspect_ratio_crop_set_caps (aspect_ratio_crop, caps);
+ gst_caps_unref (caps);
}
}