2009-06-14 17:21:34 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-06-14 17:21:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gstfrei0r.h"
|
|
|
|
#include "gstfrei0rmixer.h"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_EXTERN (frei0r_debug);
|
|
|
|
#define GST_CAT_DEFAULT frei0r_debug
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
f0r_plugin_info_t info;
|
|
|
|
GstFrei0rFuncTable ftable;
|
|
|
|
} GstFrei0rMixerClassData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_frei0r_mixer_reset (GstFrei0rMixer * self)
|
|
|
|
{
|
|
|
|
GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_GET_CLASS (self);
|
2009-11-20 16:33:21 +00:00
|
|
|
GstEvent **p_ev;
|
2009-06-14 17:21:34 +00:00
|
|
|
|
|
|
|
if (self->f0r_instance) {
|
|
|
|
klass->ftable->destruct (self->f0r_instance);
|
|
|
|
self->f0r_instance = NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-29 10:02:19 +00:00
|
|
|
if (self->property_cache)
|
|
|
|
gst_frei0r_property_cache_free (klass->properties, self->property_cache,
|
|
|
|
klass->n_properties);
|
|
|
|
self->property_cache = NULL;
|
|
|
|
|
2009-06-14 17:21:34 +00:00
|
|
|
gst_caps_replace (&self->caps, NULL);
|
2012-09-28 15:59:57 +00:00
|
|
|
p_ev = &self->segment_event;
|
2009-11-20 16:33:21 +00:00
|
|
|
gst_event_replace (p_ev, NULL);
|
2009-06-29 10:02:19 +00:00
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_video_info_init (&self->info);
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_frei0r_mixer_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstFrei0rMixer *self = GST_FREI0R_MIXER (object);
|
|
|
|
GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_GET_CLASS (object);
|
|
|
|
|
|
|
|
if (self->property_cache)
|
|
|
|
gst_frei0r_property_cache_free (klass->properties, self->property_cache,
|
|
|
|
klass->n_properties);
|
|
|
|
self->property_cache = NULL;
|
|
|
|
|
2009-06-14 17:35:29 +00:00
|
|
|
if (self->collect)
|
|
|
|
gst_object_unref (self->collect);
|
|
|
|
self->collect = NULL;
|
|
|
|
|
2009-06-14 17:21:34 +00:00
|
|
|
G_OBJECT_CLASS (g_type_class_peek_parent (klass))->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_frei0r_mixer_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstFrei0rMixer *self = GST_FREI0R_MIXER (object);
|
|
|
|
GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_GET_CLASS (object);
|
|
|
|
|
2010-02-27 18:08:49 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
2009-06-14 17:21:34 +00:00
|
|
|
if (!gst_frei0r_get_property (self->f0r_instance, klass->ftable,
|
|
|
|
klass->properties, klass->n_properties, self->property_cache, prop_id,
|
|
|
|
value))
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2010-02-27 18:08:49 +00:00
|
|
|
GST_OBJECT_UNLOCK (self);
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_frei0r_mixer_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstFrei0rMixer *self = GST_FREI0R_MIXER (object);
|
|
|
|
GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_GET_CLASS (object);
|
|
|
|
|
2010-02-27 18:08:49 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
2009-06-14 17:21:34 +00:00
|
|
|
if (!gst_frei0r_set_property (self->f0r_instance, klass->ftable,
|
|
|
|
klass->properties, klass->n_properties, self->property_cache, prop_id,
|
|
|
|
value))
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2010-02-27 18:08:49 +00:00
|
|
|
GST_OBJECT_UNLOCK (self);
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_frei0r_mixer_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstFrei0rMixer *self = GST_FREI0R_MIXER (element);
|
|
|
|
GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_GET_CLASS (self);
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2012-04-17 13:22:59 +00:00
|
|
|
gst_collect_pads_start (self->collect);
|
2009-06-14 17:21:34 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop before calling the parent's state change function as
|
2012-04-17 13:22:59 +00:00
|
|
|
* GstCollectPads might take locks and we would deadlock in that
|
2009-06-14 17:21:34 +00:00
|
|
|
* case
|
|
|
|
*/
|
|
|
|
if (transition == GST_STATE_CHANGE_PAUSED_TO_READY)
|
2012-04-17 13:22:59 +00:00
|
|
|
gst_collect_pads_stop (self->collect);
|
2009-06-14 17:21:34 +00:00
|
|
|
|
|
|
|
ret =
|
|
|
|
GST_ELEMENT_CLASS (g_type_class_peek_parent (klass))->change_state
|
|
|
|
(element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
gst_frei0r_mixer_reset (self);
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_frei0r_mixer_query_pad_caps (GstPad * pad, GstPad * skip, GstCaps * filter)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
if (pad == skip)
|
|
|
|
return filter;
|
|
|
|
|
|
|
|
caps = gst_pad_peer_query_caps (pad, filter);
|
|
|
|
|
|
|
|
if (caps)
|
|
|
|
gst_caps_unref (filter);
|
|
|
|
else
|
|
|
|
caps = filter;
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
gst_frei0r_mixer_get_caps (GstFrei0rMixer * self, GstPad * pad,
|
|
|
|
GstCaps * filter)
|
2009-06-14 17:21:34 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
|
|
|
|
if (self->caps) {
|
|
|
|
caps = gst_caps_ref (self->caps);
|
|
|
|
} else {
|
2012-09-28 15:59:57 +00:00
|
|
|
GstCaps *tmp;
|
2009-06-14 17:21:34 +00:00
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
caps = gst_pad_get_pad_template_caps (self->src);
|
|
|
|
if (filter) {
|
|
|
|
tmp = caps;
|
|
|
|
caps = gst_caps_intersect_full (tmp, filter, GST_CAPS_INTERSECT_FIRST);
|
2009-06-14 17:21:34 +00:00
|
|
|
gst_caps_unref (tmp);
|
|
|
|
}
|
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
caps = gst_frei0r_mixer_query_pad_caps (self->src, pad, caps);
|
|
|
|
caps = gst_frei0r_mixer_query_pad_caps (self->sink0, pad, caps);
|
|
|
|
caps = gst_frei0r_mixer_query_pad_caps (self->sink1, pad, caps);
|
|
|
|
if (self->sink2)
|
|
|
|
caps = gst_frei0r_mixer_query_pad_caps (self->sink2, pad, caps);
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_frei0r_mixer_set_caps (GstFrei0rMixer * self, GstPad * pad, GstCaps * caps)
|
2009-06-14 17:21:34 +00:00
|
|
|
{
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
if (!self->caps) {
|
|
|
|
gst_caps_replace (&self->caps, caps);
|
2009-06-14 17:21:34 +00:00
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
ret = gst_pad_set_caps (self->src, caps);
|
2009-06-14 17:21:34 +00:00
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
if (ret) {
|
|
|
|
GstVideoInfo info;
|
|
|
|
|
|
|
|
gst_video_info_init (&info);
|
|
|
|
if (!gst_video_info_from_caps (&self->info, caps)) {
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
2012-09-28 15:59:57 +00:00
|
|
|
} else if (!gst_caps_is_equal (caps, self->caps)) {
|
|
|
|
if (gst_pad_peer_query_accept_caps (pad, self->caps))
|
|
|
|
gst_pad_push_event (pad, gst_event_new_reconfigure ());
|
|
|
|
ret = FALSE;
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_frei0r_mixer_src_query_duration (GstFrei0rMixer * self, GstQuery * query)
|
|
|
|
{
|
|
|
|
gint64 min;
|
|
|
|
gboolean res;
|
|
|
|
GstFormat format;
|
|
|
|
GstIterator *it;
|
|
|
|
gboolean done;
|
|
|
|
|
|
|
|
/* parse format */
|
|
|
|
gst_query_parse_duration (query, &format, NULL);
|
|
|
|
|
|
|
|
min = -1;
|
|
|
|
res = TRUE;
|
|
|
|
done = FALSE;
|
|
|
|
|
|
|
|
/* Take minimum of all durations */
|
|
|
|
it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (self));
|
|
|
|
while (!done) {
|
|
|
|
GstIteratorResult ires;
|
2012-09-28 15:59:57 +00:00
|
|
|
GValue item = { 0 };
|
2009-06-14 17:21:34 +00:00
|
|
|
|
|
|
|
ires = gst_iterator_next (it, &item);
|
|
|
|
switch (ires) {
|
|
|
|
case GST_ITERATOR_DONE:
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_OK:
|
|
|
|
{
|
2012-09-28 15:59:57 +00:00
|
|
|
GstPad *pad = g_value_get_object (&item);
|
2009-06-14 17:21:34 +00:00
|
|
|
gint64 duration;
|
|
|
|
|
|
|
|
/* ask sink peer for duration */
|
2012-09-28 15:59:57 +00:00
|
|
|
res &= gst_pad_peer_query_duration (pad, format, &duration);
|
2009-06-14 17:21:34 +00:00
|
|
|
/* take min from all valid return values */
|
|
|
|
if (res) {
|
|
|
|
/* valid unknown length, stop searching */
|
|
|
|
if (duration == -1) {
|
|
|
|
min = duration;
|
|
|
|
done = TRUE;
|
|
|
|
}
|
|
|
|
/* else see if smaller than current min */
|
|
|
|
else if (duration < min)
|
|
|
|
min = duration;
|
|
|
|
}
|
2012-09-28 15:59:57 +00:00
|
|
|
g_value_reset (&item);
|
2009-06-14 17:21:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_ITERATOR_RESYNC:
|
|
|
|
min = -1;
|
|
|
|
res = TRUE;
|
|
|
|
gst_iterator_resync (it);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2012-09-28 15:59:57 +00:00
|
|
|
|
|
|
|
g_value_unset (&item);
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
|
|
|
gst_iterator_free (it);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
/* and store the min */
|
|
|
|
GST_DEBUG_OBJECT (self, "Total duration in format %s: %"
|
|
|
|
GST_TIME_FORMAT, gst_format_get_name (format), GST_TIME_ARGS (min));
|
|
|
|
gst_query_set_duration (query, format, min);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_frei0r_mixer_src_query_latency (GstFrei0rMixer * self, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstClockTime min, max;
|
|
|
|
gboolean live;
|
|
|
|
gboolean res;
|
|
|
|
GstIterator *it;
|
|
|
|
gboolean done;
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
done = FALSE;
|
|
|
|
|
|
|
|
live = FALSE;
|
|
|
|
min = 0;
|
|
|
|
max = GST_CLOCK_TIME_NONE;
|
|
|
|
|
|
|
|
/* Take maximum of all latency values */
|
|
|
|
it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (self));
|
|
|
|
while (!done) {
|
|
|
|
GstIteratorResult ires;
|
2012-09-28 15:59:57 +00:00
|
|
|
GValue item = { 0 };
|
2009-06-14 17:21:34 +00:00
|
|
|
|
|
|
|
ires = gst_iterator_next (it, &item);
|
|
|
|
switch (ires) {
|
|
|
|
case GST_ITERATOR_DONE:
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_OK:
|
|
|
|
{
|
2012-09-28 15:59:57 +00:00
|
|
|
GstPad *pad = g_value_get_object (&item);
|
2009-06-14 17:21:34 +00:00
|
|
|
GstQuery *peerquery;
|
|
|
|
GstClockTime min_cur, max_cur;
|
|
|
|
gboolean live_cur;
|
|
|
|
|
|
|
|
peerquery = gst_query_new_latency ();
|
|
|
|
|
|
|
|
/* Ask peer for latency */
|
|
|
|
res &= gst_pad_peer_query (pad, peerquery);
|
|
|
|
|
|
|
|
/* take max from all valid return values */
|
|
|
|
if (res) {
|
|
|
|
gst_query_parse_latency (peerquery, &live_cur, &min_cur, &max_cur);
|
|
|
|
|
|
|
|
if (min_cur > min)
|
|
|
|
min = min_cur;
|
|
|
|
|
|
|
|
if (max_cur != GST_CLOCK_TIME_NONE &&
|
|
|
|
((max != GST_CLOCK_TIME_NONE && max_cur > max) ||
|
|
|
|
(max == GST_CLOCK_TIME_NONE)))
|
|
|
|
max = max_cur;
|
|
|
|
|
|
|
|
live = live || live_cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_query_unref (peerquery);
|
2012-09-28 15:59:57 +00:00
|
|
|
g_value_reset (&item);
|
2009-06-14 17:21:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_ITERATOR_RESYNC:
|
|
|
|
live = FALSE;
|
|
|
|
min = 0;
|
|
|
|
max = GST_CLOCK_TIME_NONE;
|
|
|
|
res = TRUE;
|
|
|
|
gst_iterator_resync (it);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2012-09-28 15:59:57 +00:00
|
|
|
|
|
|
|
g_value_unset (&item);
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
|
|
|
gst_iterator_free (it);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
/* store the results */
|
|
|
|
GST_DEBUG_OBJECT (self, "Calculated total latency: live %s, min %"
|
|
|
|
GST_TIME_FORMAT ", max %" GST_TIME_FORMAT,
|
|
|
|
(live ? "yes" : "no"), GST_TIME_ARGS (min), GST_TIME_ARGS (max));
|
|
|
|
gst_query_set_latency (query, live, min, max);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_frei0r_mixer_src_query (GstPad * pad, GstObject * object, GstQuery * query)
|
2009-06-14 17:21:34 +00:00
|
|
|
{
|
2012-09-28 15:59:57 +00:00
|
|
|
GstFrei0rMixer *self = GST_FREI0R_MIXER (object);
|
2009-06-14 17:21:34 +00:00
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_POSITION:
|
|
|
|
ret = gst_pad_query (self->sink0, query);
|
|
|
|
break;
|
|
|
|
case GST_QUERY_DURATION:
|
|
|
|
ret = gst_frei0r_mixer_src_query_duration (self, query);
|
|
|
|
break;
|
|
|
|
case GST_QUERY_LATENCY:
|
|
|
|
ret = gst_frei0r_mixer_src_query_latency (self, query);
|
|
|
|
break;
|
2012-09-28 15:59:57 +00:00
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
|
|
|
gst_query_parse_caps (query, &filter);
|
|
|
|
caps = gst_frei0r_mixer_get_caps (self, pad, filter);
|
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
break;
|
|
|
|
}
|
2009-06-14 17:21:34 +00:00
|
|
|
default:
|
2012-09-28 15:59:57 +00:00
|
|
|
ret = gst_pad_query_default (pad, GST_OBJECT (self), query);
|
2009-06-14 17:21:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_frei0r_mixer_sink_query (GstCollectPads * pads, GstCollectData * cdata,
|
|
|
|
GstQuery * query, GstFrei0rMixer * self)
|
2009-06-14 17:21:34 +00:00
|
|
|
{
|
2012-09-28 15:59:57 +00:00
|
|
|
gboolean ret = TRUE;
|
2009-06-14 17:21:34 +00:00
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
|
|
|
gst_query_parse_caps (query, &filter);
|
|
|
|
caps = gst_frei0r_mixer_get_caps (self, cdata->pad, filter);
|
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ret = gst_collect_pads_query_default (pads, cdata, query, FALSE);
|
|
|
|
break;
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
2012-09-28 15:59:57 +00:00
|
|
|
return ret;
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_frei0r_mixer_src_event (GstPad * pad, GstObject * object, GstEvent * event)
|
2009-06-14 17:21:34 +00:00
|
|
|
{
|
2012-09-28 15:59:57 +00:00
|
|
|
GstFrei0rMixer *self = GST_FREI0R_MIXER (object);
|
2009-06-14 17:21:34 +00:00
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_QOS:
|
|
|
|
/* QoS might be tricky */
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
|
|
|
GstSeekFlags flags;
|
|
|
|
|
|
|
|
/* parse the seek parameters */
|
|
|
|
gst_event_parse_seek (event, NULL, NULL, &flags, NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
/* check if we are flushing */
|
|
|
|
if (flags & GST_SEEK_FLAG_FLUSH) {
|
|
|
|
/* make sure we accept nothing anymore and return WRONG_STATE */
|
2012-04-17 13:22:59 +00:00
|
|
|
gst_collect_pads_set_flushing (self->collect, TRUE);
|
2009-06-14 17:21:34 +00:00
|
|
|
|
|
|
|
/* flushing seek, start flush downstream, the flush will be done
|
|
|
|
* when all pads received a FLUSH_STOP. */
|
|
|
|
gst_pad_push_event (self->src, gst_event_new_flush_start ());
|
|
|
|
}
|
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
ret = gst_pad_event_default (pad, GST_OBJECT (self), event);
|
2009-06-14 17:21:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2012-09-28 15:59:57 +00:00
|
|
|
ret = gst_pad_event_default (pad, GST_OBJECT (self), event);
|
2009-06-14 17:21:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_frei0r_mixer_sink_event (GstCollectPads * pads, GstCollectData * cdata,
|
|
|
|
GstEvent * event, GstFrei0rMixer * self)
|
2009-06-14 17:21:34 +00:00
|
|
|
{
|
2012-09-28 15:59:57 +00:00
|
|
|
gboolean ret = TRUE;
|
2009-06-14 17:21:34 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2012-09-28 15:59:57 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
ret = gst_frei0r_mixer_set_caps (self, cdata->pad, caps);
|
|
|
|
gst_event_unref (event);
|
2009-06-14 17:21:34 +00:00
|
|
|
break;
|
2012-09-28 15:59:57 +00:00
|
|
|
}
|
2009-06-14 17:21:34 +00:00
|
|
|
default:
|
2012-09-28 15:59:57 +00:00
|
|
|
ret = gst_collect_pads_event_default (pads, cdata, event, FALSE);
|
2009-06-14 17:21:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-04-17 13:22:59 +00:00
|
|
|
gst_frei0r_mixer_collected (GstCollectPads * pads, GstFrei0rMixer * self)
|
2009-06-14 17:21:34 +00:00
|
|
|
{
|
|
|
|
GstBuffer *inbuf0 = NULL, *inbuf1 = NULL, *inbuf2 = NULL;
|
|
|
|
GstBuffer *outbuf = NULL;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
GSList *l;
|
|
|
|
GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_GET_CLASS (self);
|
2010-02-28 09:42:38 +00:00
|
|
|
GstClockTime timestamp;
|
2009-06-14 17:21:34 +00:00
|
|
|
gdouble time;
|
2010-02-28 09:42:38 +00:00
|
|
|
GstSegment *segment = NULL;
|
2012-09-28 15:59:57 +00:00
|
|
|
GstAllocationParams alloc_params = { 0, 31, 0, 0 };
|
|
|
|
GstMapInfo outmap, inmap0, inmap1, inmap2;
|
2009-06-14 17:21:34 +00:00
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
if (G_UNLIKELY (self->info.width <= 0 || self->info.height <= 0))
|
2009-06-14 17:21:34 +00:00
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
|
2009-06-29 09:56:59 +00:00
|
|
|
if (G_UNLIKELY (!self->f0r_instance)) {
|
2012-09-28 15:59:57 +00:00
|
|
|
self->f0r_instance = gst_frei0r_instance_construct (klass->ftable,
|
|
|
|
klass->properties, klass->n_properties, self->property_cache,
|
|
|
|
self->info.width, self->info.height);
|
2009-06-29 09:56:59 +00:00
|
|
|
if (G_UNLIKELY (!self->f0r_instance))
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
if (self->segment_event) {
|
|
|
|
gst_pad_push_event (self->src, self->segment_event);
|
|
|
|
self->segment_event = NULL;
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
/* FIXME Request an allocator and/or pool */
|
|
|
|
outbuf = gst_buffer_new_allocate (NULL, self->info.size, &alloc_params);
|
2009-06-14 17:21:34 +00:00
|
|
|
|
|
|
|
for (l = pads->data; l; l = l->next) {
|
2012-04-17 13:22:59 +00:00
|
|
|
GstCollectData *cdata = l->data;
|
2009-06-14 17:21:34 +00:00
|
|
|
|
2010-02-28 09:42:38 +00:00
|
|
|
if (cdata->pad == self->sink0) {
|
2012-04-17 13:22:59 +00:00
|
|
|
inbuf0 = gst_collect_pads_pop (pads, cdata);
|
2010-02-28 09:42:38 +00:00
|
|
|
segment = &cdata->segment;
|
|
|
|
} else if (cdata->pad == self->sink1) {
|
2012-04-17 13:22:59 +00:00
|
|
|
inbuf1 = gst_collect_pads_pop (pads, cdata);
|
2010-02-28 09:42:38 +00:00
|
|
|
} else if (cdata->pad == self->sink2) {
|
2012-04-17 13:22:59 +00:00
|
|
|
inbuf2 = gst_collect_pads_pop (pads, cdata);
|
2010-02-28 09:42:38 +00:00
|
|
|
}
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!inbuf0 || !inbuf1 || (!inbuf2 && self->sink2))
|
|
|
|
goto eos;
|
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_buffer_map (outbuf, &outmap, GST_MAP_READWRITE);
|
|
|
|
gst_buffer_map (inbuf0, &inmap0, GST_MAP_READ);
|
|
|
|
gst_buffer_map (inbuf1, &inmap1, GST_MAP_READ);
|
|
|
|
if (inbuf2)
|
|
|
|
gst_buffer_map (inbuf2, &inmap2, GST_MAP_READ);
|
|
|
|
|
2010-02-28 09:42:38 +00:00
|
|
|
g_assert (segment != NULL);
|
2012-09-28 15:59:57 +00:00
|
|
|
timestamp = GST_BUFFER_PTS (inbuf0);
|
2010-02-28 09:42:38 +00:00
|
|
|
timestamp = gst_segment_to_stream_time (segment, GST_FORMAT_TIME, timestamp);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "sync to %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (timestamp));
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (timestamp))
|
2011-11-04 17:52:35 +00:00
|
|
|
gst_object_sync_values (GST_OBJECT (self), timestamp);
|
2010-02-28 09:42:38 +00:00
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_buffer_copy_into (outbuf, inbuf0,
|
|
|
|
GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
|
|
|
|
time = ((gdouble) GST_BUFFER_PTS (outbuf)) / GST_SECOND;
|
2009-06-14 17:21:34 +00:00
|
|
|
|
2010-02-27 18:08:49 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
2009-06-14 17:21:34 +00:00
|
|
|
klass->ftable->update2 (self->f0r_instance, time,
|
2012-09-28 15:59:57 +00:00
|
|
|
(const guint32 *) inmap0.data, (const guint32 *) inmap1.data,
|
|
|
|
(inbuf2) ? (const guint32 *) inmap2.data : NULL, (guint32 *) outmap.data);
|
2010-02-27 18:08:49 +00:00
|
|
|
GST_OBJECT_UNLOCK (self);
|
2009-06-14 17:21:34 +00:00
|
|
|
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_buffer_unmap (outbuf, &outmap);
|
2009-06-14 17:21:34 +00:00
|
|
|
gst_buffer_unref (inbuf0);
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_buffer_unmap (inbuf0, &inmap0);
|
2009-06-14 17:21:34 +00:00
|
|
|
gst_buffer_unref (inbuf1);
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_buffer_unmap (inbuf1, &inmap1);
|
|
|
|
if (inbuf2) {
|
|
|
|
gst_buffer_unmap (inbuf2, &inmap2);
|
2009-06-14 17:21:34 +00:00
|
|
|
gst_buffer_unref (inbuf2);
|
2012-09-28 15:59:57 +00:00
|
|
|
}
|
2009-06-14 17:21:34 +00:00
|
|
|
|
|
|
|
ret = gst_pad_push (self->src, outbuf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
eos:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (self, "no data available, must be EOS");
|
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
|
|
|
|
if (inbuf0)
|
|
|
|
gst_buffer_unref (inbuf0);
|
|
|
|
if (inbuf1)
|
|
|
|
gst_buffer_unref (inbuf1);
|
|
|
|
if (inbuf2)
|
|
|
|
gst_buffer_unref (inbuf2);
|
|
|
|
|
|
|
|
gst_pad_push_event (self->src, gst_event_new_eos ());
|
2012-09-28 15:59:57 +00:00
|
|
|
return GST_FLOW_EOS;
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_frei0r_mixer_class_init (GstFrei0rMixerClass * klass,
|
|
|
|
GstFrei0rMixerClassData * class_data)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
|
|
|
GstPadTemplate *templ;
|
2012-09-29 12:21:18 +00:00
|
|
|
const gchar *desc;
|
2009-06-14 17:21:34 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
gchar *author;
|
|
|
|
|
|
|
|
klass->ftable = &class_data->ftable;
|
|
|
|
klass->info = &class_data->info;
|
|
|
|
|
|
|
|
gobject_class->finalize = gst_frei0r_mixer_finalize;
|
|
|
|
gobject_class->set_property = gst_frei0r_mixer_set_property;
|
|
|
|
gobject_class->get_property = gst_frei0r_mixer_get_property;
|
|
|
|
|
|
|
|
klass->n_properties = klass->info->num_params;
|
|
|
|
klass->properties = g_new0 (GstFrei0rProperty, klass->n_properties);
|
|
|
|
|
|
|
|
gst_frei0r_klass_install_properties (gobject_class, klass->ftable,
|
|
|
|
klass->properties, klass->n_properties);
|
|
|
|
|
|
|
|
author =
|
|
|
|
g_strdup_printf
|
|
|
|
("Sebastian Dröge <sebastian.droege@collabora.co.uk>, %s",
|
|
|
|
class_data->info.author);
|
2012-09-29 12:21:18 +00:00
|
|
|
desc = class_data->info.explanation;
|
|
|
|
if (desc == NULL || *desc == '\0')
|
|
|
|
desc = "No details";
|
2012-09-14 15:08:49 +00:00
|
|
|
gst_element_class_set_metadata (gstelement_class, class_data->info.name,
|
2012-09-29 12:21:18 +00:00
|
|
|
"Filter/Editor/Video", desc, author);
|
2009-06-14 17:21:34 +00:00
|
|
|
g_free (author);
|
|
|
|
|
|
|
|
caps = gst_frei0r_caps_from_color_model (class_data->info.color_model);
|
|
|
|
|
|
|
|
templ =
|
|
|
|
gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
|
|
|
gst_caps_ref (caps));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class, templ);
|
|
|
|
|
|
|
|
templ =
|
|
|
|
gst_pad_template_new ("sink_0", GST_PAD_SINK, GST_PAD_ALWAYS,
|
|
|
|
gst_caps_ref (caps));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class, templ);
|
|
|
|
|
|
|
|
templ =
|
|
|
|
gst_pad_template_new ("sink_1", GST_PAD_SINK, GST_PAD_ALWAYS,
|
|
|
|
gst_caps_ref (caps));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class, templ);
|
|
|
|
|
|
|
|
if (klass->info->plugin_type == F0R_PLUGIN_TYPE_MIXER3) {
|
|
|
|
templ =
|
|
|
|
gst_pad_template_new ("sink_2", GST_PAD_SINK, GST_PAD_ALWAYS,
|
|
|
|
gst_caps_ref (caps));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class, templ);
|
|
|
|
}
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_frei0r_mixer_change_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_frei0r_mixer_init (GstFrei0rMixer * self, GstFrei0rMixerClass * klass)
|
|
|
|
{
|
|
|
|
self->property_cache =
|
|
|
|
gst_frei0r_property_cache_init (klass->properties, klass->n_properties);
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_video_info_init (&self->info);
|
2009-06-14 17:21:34 +00:00
|
|
|
|
2012-04-17 13:22:59 +00:00
|
|
|
self->collect = gst_collect_pads_new ();
|
|
|
|
gst_collect_pads_set_function (self->collect,
|
|
|
|
(GstCollectPadsFunction) gst_frei0r_mixer_collected, self);
|
2012-09-28 15:59:57 +00:00
|
|
|
gst_collect_pads_set_event_function (self->collect,
|
|
|
|
(GstCollectPadsEventFunction) gst_frei0r_mixer_sink_event, self);
|
|
|
|
gst_collect_pads_set_query_function (self->collect,
|
|
|
|
(GstCollectPadsQueryFunction) gst_frei0r_mixer_sink_query, self);
|
2009-06-14 17:21:34 +00:00
|
|
|
|
|
|
|
self->src =
|
|
|
|
gst_pad_new_from_template (gst_element_class_get_pad_template
|
|
|
|
(GST_ELEMENT_CLASS (klass), "src"), "src");
|
|
|
|
gst_pad_set_query_function (self->src,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_frei0r_mixer_src_query));
|
|
|
|
gst_pad_set_event_function (self->src,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_frei0r_mixer_src_event));
|
|
|
|
gst_element_add_pad (GST_ELEMENT_CAST (self), self->src);
|
|
|
|
|
|
|
|
self->sink0 =
|
|
|
|
gst_pad_new_from_template (gst_element_class_get_pad_template
|
|
|
|
(GST_ELEMENT_CLASS (klass), "sink_0"), "sink_0");
|
2012-04-17 13:22:59 +00:00
|
|
|
gst_collect_pads_add_pad (self->collect, self->sink0,
|
2012-09-12 19:13:35 +00:00
|
|
|
sizeof (GstCollectData), NULL, TRUE);
|
2009-06-14 17:21:34 +00:00
|
|
|
self->collect_event = (GstPadEventFunction) GST_PAD_EVENTFUNC (self->sink0);
|
|
|
|
gst_element_add_pad (GST_ELEMENT_CAST (self), self->sink0);
|
|
|
|
|
|
|
|
self->sink1 =
|
|
|
|
gst_pad_new_from_template (gst_element_class_get_pad_template
|
|
|
|
(GST_ELEMENT_CLASS (klass), "sink_1"), "sink_1");
|
2012-04-17 13:22:59 +00:00
|
|
|
gst_collect_pads_add_pad (self->collect, self->sink1,
|
2012-09-12 19:13:35 +00:00
|
|
|
sizeof (GstCollectData), NULL, TRUE);
|
2009-06-14 17:21:34 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT_CAST (self), self->sink1);
|
|
|
|
|
|
|
|
if (klass->info->plugin_type == F0R_PLUGIN_TYPE_MIXER3) {
|
|
|
|
self->sink2 =
|
|
|
|
gst_pad_new_from_template (gst_element_class_get_pad_template
|
|
|
|
(GST_ELEMENT_CLASS (klass), "sink_2"), "sink_2");
|
2012-04-17 13:22:59 +00:00
|
|
|
gst_collect_pads_add_pad (self->collect, self->sink2,
|
2012-09-12 19:13:35 +00:00
|
|
|
sizeof (GstCollectData), NULL, TRUE);
|
2009-06-14 17:21:34 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT_CAST (self), self->sink2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-07-11 08:47:37 +00:00
|
|
|
GstFrei0rPluginRegisterReturn
|
2010-09-25 08:46:34 +00:00
|
|
|
gst_frei0r_mixer_register (GstPlugin * plugin, const gchar * vendor,
|
|
|
|
const f0r_plugin_info_t * info, const GstFrei0rFuncTable * ftable)
|
2009-06-14 17:21:34 +00:00
|
|
|
{
|
|
|
|
GTypeInfo typeinfo = {
|
|
|
|
sizeof (GstFrei0rMixerClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_frei0r_mixer_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstFrei0rMixer),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_frei0r_mixer_init
|
|
|
|
};
|
|
|
|
GType type;
|
|
|
|
gchar *type_name, *tmp;
|
|
|
|
GstFrei0rMixerClassData *class_data;
|
2010-07-11 08:47:37 +00:00
|
|
|
GstFrei0rPluginRegisterReturn ret = GST_FREI0R_PLUGIN_REGISTER_RETURN_FAILED;
|
2009-06-14 17:21:34 +00:00
|
|
|
|
|
|
|
if (ftable->update2 == NULL)
|
2010-07-11 08:47:37 +00:00
|
|
|
return GST_FREI0R_PLUGIN_REGISTER_RETURN_FAILED;
|
2009-06-14 17:21:34 +00:00
|
|
|
|
2010-09-25 08:46:34 +00:00
|
|
|
if (vendor)
|
|
|
|
tmp = g_strdup_printf ("frei0r-mixer-%s-%s", vendor, info->name);
|
|
|
|
else
|
|
|
|
tmp = g_strdup_printf ("frei0r-mixer-%s", info->name);
|
2009-06-14 17:21:34 +00:00
|
|
|
type_name = g_ascii_strdown (tmp, -1);
|
|
|
|
g_free (tmp);
|
|
|
|
g_strcanon (type_name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-+", '-');
|
|
|
|
|
|
|
|
if (g_type_from_name (type_name)) {
|
2010-07-11 08:47:37 +00:00
|
|
|
GST_DEBUG ("Type '%s' already exists", type_name);
|
|
|
|
return GST_FREI0R_PLUGIN_REGISTER_RETURN_ALREADY_REGISTERED;
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class_data = g_new0 (GstFrei0rMixerClassData, 1);
|
|
|
|
memcpy (&class_data->info, info, sizeof (f0r_plugin_info_t));
|
|
|
|
memcpy (&class_data->ftable, ftable, sizeof (GstFrei0rFuncTable));
|
|
|
|
typeinfo.class_data = class_data;
|
|
|
|
|
|
|
|
type = g_type_register_static (GST_TYPE_ELEMENT, type_name, &typeinfo, 0);
|
2010-07-11 08:47:37 +00:00
|
|
|
if (gst_element_register (plugin, type_name, GST_RANK_NONE, type))
|
|
|
|
ret = GST_FREI0R_PLUGIN_REGISTER_RETURN_OK;
|
2009-06-14 17:41:27 +00:00
|
|
|
|
|
|
|
g_free (type_name);
|
|
|
|
return ret;
|
2009-06-14 17:21:34 +00:00
|
|
|
}
|