Commit 0196fb46 authored by Thiago Santos's avatar Thiago Santos

aspectratiocrop: Port to 0.11

parent 04080866
......@@ -53,26 +53,10 @@ enum
};
/* 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,
......@@ -86,8 +70,8 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
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);
......@@ -95,8 +79,10 @@ static void gst_aspect_ratio_crop_get_property (GObject * object, guint prop_id,
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,
......@@ -135,15 +121,13 @@ gst_aspect_ratio_crop_set_cropping (GstAspectRatioCrop * aspect_ratio_crop,
}
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);
......@@ -154,33 +138,46 @@ gst_aspect_ratio_crop_set_caps (GstPad * pad, GstCaps * caps)
"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;
......@@ -190,6 +187,16 @@ gst_aspect_ratio_crop_class_init (GstAspectRatioCropClass * klass)
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
......@@ -206,8 +213,7 @@ gst_aspect_ratio_crop_finalize (GObject * object)
}
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;
......@@ -241,8 +247,11 @@ gst_aspect_ratio_crop_init (GstAspectRatioCrop * aspect_ratio_crop,
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
......@@ -370,7 +379,7 @@ gst_aspect_ratio_crop_transform_caps (GstAspectRatioCrop * aspect_ratio_crop,
}
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;
......@@ -387,7 +396,7 @@ gst_aspect_ratio_crop_get_caps (GstPad * pad)
} 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);
......@@ -397,6 +406,13 @@ gst_aspect_ratio_crop_get_caps (GstPad * pad)
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;
}
......@@ -416,7 +432,7 @@ gst_aspect_ratio_crop_set_property (GObject * object, guint prop_id,
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:
......@@ -426,8 +442,9 @@ gst_aspect_ratio_crop_set_property (GObject * object, guint prop_id,
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);
}
}
......
......@@ -46,6 +46,7 @@ struct _GstAspectRatioCrop
GstElement *videocrop;
GstPad *sink;
GstPadEventFunction sinkpad_old_eventfunc;
/* target aspect ratio */
gint ar_num; /* if < 1 then don't change ar */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment