2014-06-03 17:00:34 +00:00
|
|
|
/* Generic video aggregator plugin
|
|
|
|
* Copyright (C) 2004, 2008 Wim Taymans <wim@fluendo.com>
|
|
|
|
* Copyright (C) 2010 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
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gstvideoaggregator
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: GstVideoAggregator
|
2014-06-03 17:00:34 +00:00
|
|
|
* @short_description: Base class for video aggregators
|
|
|
|
*
|
|
|
|
* VideoAggregator can accept AYUV, ARGB and BGRA video streams. For each of the requested
|
|
|
|
* sink pads it will compare the incoming geometry and framerate to define the
|
|
|
|
* output parameters. Indeed output video frames will have the geometry of the
|
|
|
|
* biggest incoming video stream and the framerate of the fastest incoming one.
|
|
|
|
*
|
|
|
|
* VideoAggregator will do colorspace conversion.
|
2015-05-10 08:55:16 +00:00
|
|
|
*
|
2014-06-03 17:00:34 +00:00
|
|
|
* Zorder for each input stream can be configured on the
|
|
|
|
* #GstVideoAggregatorPad.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gstvideoaggregator.h"
|
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_video_aggregator_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_video_aggregator_debug
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
/* Needed prototypes */
|
2016-05-16 11:27:50 +00:00
|
|
|
static void gst_video_aggregator_reset_qos (GstVideoAggregator * vagg);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
/****************************************
|
|
|
|
* GstVideoAggregatorPad implementation *
|
|
|
|
****************************************/
|
|
|
|
|
|
|
|
#define DEFAULT_PAD_ZORDER 0
|
2018-05-04 14:46:00 +00:00
|
|
|
#define DEFAULT_PAD_REPEAT_AFTER_EOS FALSE
|
2014-06-03 17:00:34 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_PAD_0,
|
|
|
|
PROP_PAD_ZORDER,
|
2018-05-04 14:46:00 +00:00
|
|
|
PROP_PAD_REPEAT_AFTER_EOS,
|
2014-06-03 17:00:34 +00:00
|
|
|
};
|
|
|
|
|
2014-06-20 20:02:07 +00:00
|
|
|
|
|
|
|
struct _GstVideoAggregatorPadPrivate
|
|
|
|
{
|
2018-05-05 13:49:17 +00:00
|
|
|
GstBuffer *buffer;
|
|
|
|
GstVideoFrame prepared_frame;
|
|
|
|
|
2018-05-04 15:18:12 +00:00
|
|
|
/* properties */
|
|
|
|
guint zorder;
|
|
|
|
gboolean repeat_after_eos;
|
|
|
|
|
2018-05-05 14:14:14 +00:00
|
|
|
/* Subclasses can force an alpha channel in the (input thus output)
|
|
|
|
* colorspace format */
|
|
|
|
gboolean needs_alpha;
|
|
|
|
|
2014-11-27 19:48:24 +00:00
|
|
|
GstClockTime start_time;
|
|
|
|
GstClockTime end_time;
|
2017-04-04 08:25:43 +00:00
|
|
|
|
|
|
|
GstVideoInfo pending_vinfo;
|
2014-06-20 20:02:07 +00:00
|
|
|
};
|
|
|
|
|
2015-09-09 22:51:18 +00:00
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
G_DEFINE_TYPE (GstVideoAggregatorPad, gst_video_aggregator_pad,
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_TYPE_AGGREGATOR_PAD);
|
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_pad_get_property (GObject * object, guint prop_id,
|
2014-06-03 17:00:34 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstVideoAggregatorPad *pad = GST_VIDEO_AGGREGATOR_PAD (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PAD_ZORDER:
|
2018-05-04 15:18:12 +00:00
|
|
|
g_value_set_uint (value, pad->priv->zorder);
|
2014-06-03 17:00:34 +00:00
|
|
|
break;
|
2018-05-04 14:46:00 +00:00
|
|
|
case PROP_PAD_REPEAT_AFTER_EOS:
|
2018-05-04 15:18:12 +00:00
|
|
|
g_value_set_boolean (value, pad->priv->repeat_after_eos);
|
2015-02-09 19:19:35 +00:00
|
|
|
break;
|
2014-06-03 17:00:34 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pad_zorder_compare (const GstVideoAggregatorPad * pad1,
|
|
|
|
const GstVideoAggregatorPad * pad2)
|
|
|
|
{
|
2018-05-04 15:18:12 +00:00
|
|
|
return pad1->priv->zorder - pad2->priv->zorder;
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_pad_set_property (GObject * object, guint prop_id,
|
2014-06-03 17:00:34 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstVideoAggregatorPad *pad = GST_VIDEO_AGGREGATOR_PAD (object);
|
|
|
|
GstVideoAggregator *vagg =
|
|
|
|
GST_VIDEO_AGGREGATOR (gst_pad_get_parent (GST_PAD (pad)));
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PAD_ZORDER:
|
|
|
|
GST_OBJECT_LOCK (vagg);
|
2018-05-04 15:18:12 +00:00
|
|
|
pad->priv->zorder = g_value_get_uint (value);
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_ELEMENT (vagg)->sinkpads = g_list_sort (GST_ELEMENT (vagg)->sinkpads,
|
|
|
|
(GCompareFunc) pad_zorder_compare);
|
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
|
|
|
break;
|
2018-05-04 14:46:00 +00:00
|
|
|
case PROP_PAD_REPEAT_AFTER_EOS:
|
2018-05-04 15:18:12 +00:00
|
|
|
pad->priv->repeat_after_eos = g_value_get_boolean (value);
|
2015-02-09 19:19:35 +00:00
|
|
|
break;
|
2014-06-03 17:00:34 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_object_unref (vagg);
|
|
|
|
}
|
|
|
|
|
2016-07-11 13:51:11 +00:00
|
|
|
static GstFlowReturn
|
2014-06-03 17:00:34 +00:00
|
|
|
_flush_pad (GstAggregatorPad * aggpad, GstAggregator * aggregator)
|
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (aggregator);
|
|
|
|
GstVideoAggregatorPad *pad = GST_VIDEO_AGGREGATOR_PAD (aggpad);
|
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_reset_qos (vagg);
|
2018-05-05 13:49:17 +00:00
|
|
|
gst_buffer_replace (&pad->priv->buffer, NULL);
|
2014-11-27 19:48:24 +00:00
|
|
|
pad->priv->start_time = -1;
|
|
|
|
pad->priv->end_time = -1;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2016-07-11 13:51:11 +00:00
|
|
|
return GST_FLOW_OK;
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
2017-12-28 11:15:21 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_aggregator_pad_skip_buffer (GstAggregatorPad * aggpad,
|
|
|
|
GstAggregator * agg, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
gboolean ret = FALSE;
|
2018-02-28 23:34:40 +00:00
|
|
|
GstSegment *agg_segment = &GST_AGGREGATOR_PAD (agg->srcpad)->segment;
|
2017-12-28 11:15:21 +00:00
|
|
|
|
2018-02-28 23:34:40 +00:00
|
|
|
if (agg_segment->position != GST_CLOCK_TIME_NONE
|
2017-12-28 11:15:21 +00:00
|
|
|
&& GST_BUFFER_DURATION (buffer) != GST_CLOCK_TIME_NONE) {
|
|
|
|
GstClockTime start_time =
|
2018-02-28 23:34:40 +00:00
|
|
|
gst_segment_to_running_time (agg_segment, GST_FORMAT_TIME,
|
2017-12-28 11:15:21 +00:00
|
|
|
GST_BUFFER_PTS (buffer));
|
|
|
|
GstClockTime end_time = start_time + GST_BUFFER_DURATION (buffer);
|
|
|
|
GstClockTime output_start_running_time =
|
2018-02-28 23:34:40 +00:00
|
|
|
gst_segment_to_running_time (agg_segment, GST_FORMAT_TIME,
|
|
|
|
agg_segment->position);
|
2017-12-28 11:15:21 +00:00
|
|
|
|
|
|
|
ret = end_time < output_start_running_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-26 17:24:05 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_aggregator_pad_prepare_frame (GstVideoAggregatorPad * pad,
|
2018-05-05 13:49:17 +00:00
|
|
|
GstVideoAggregator * vagg, GstBuffer * buffer,
|
|
|
|
GstVideoFrame * prepared_frame)
|
2014-11-26 17:24:05 +00:00
|
|
|
{
|
2018-05-06 13:21:24 +00:00
|
|
|
if (!gst_video_frame_map (prepared_frame, &pad->info, buffer, GST_MAP_READ)) {
|
2014-11-26 17:24:05 +00:00
|
|
|
GST_WARNING_OBJECT (vagg, "Could not map input buffer");
|
2014-11-28 09:22:44 +00:00
|
|
|
return FALSE;
|
2014-11-26 17:24:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_video_aggregator_pad_clean_frame (GstVideoAggregatorPad * pad,
|
2018-05-05 13:49:17 +00:00
|
|
|
GstVideoAggregator * vagg, GstVideoFrame * prepared_frame)
|
2014-11-26 17:24:05 +00:00
|
|
|
{
|
2018-05-05 13:49:17 +00:00
|
|
|
if (prepared_frame->buffer) {
|
|
|
|
gst_video_frame_unmap (prepared_frame);
|
|
|
|
memset (prepared_frame, 0, sizeof (GstVideoFrame));
|
2014-11-26 17:24:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_pad_class_init (GstVideoAggregatorPadClass * klass)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstAggregatorPadClass *aggpadclass = (GstAggregatorPadClass *) klass;
|
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
gobject_class->set_property = gst_video_aggregator_pad_set_property;
|
|
|
|
gobject_class->get_property = gst_video_aggregator_pad_get_property;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PAD_ZORDER,
|
|
|
|
g_param_spec_uint ("zorder", "Z-Order", "Z Order of the picture",
|
2015-06-14 21:13:59 +00:00
|
|
|
0, G_MAXUINT, DEFAULT_PAD_ZORDER,
|
2014-06-03 17:00:34 +00:00
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
|
2018-05-04 14:46:00 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PAD_REPEAT_AFTER_EOS,
|
|
|
|
g_param_spec_boolean ("repeat-after-eos", "Repeat After EOS",
|
|
|
|
"Repeat the " "last frame after EOS until all pads are EOS",
|
|
|
|
DEFAULT_PAD_REPEAT_AFTER_EOS,
|
2015-02-09 19:19:35 +00:00
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2014-06-20 20:02:07 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstVideoAggregatorPadPrivate));
|
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
aggpadclass->flush = GST_DEBUG_FUNCPTR (_flush_pad);
|
2017-12-28 11:15:21 +00:00
|
|
|
aggpadclass->skip_buffer =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_aggregator_pad_skip_buffer);
|
2014-11-26 17:24:05 +00:00
|
|
|
klass->prepare_frame =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_aggregator_pad_prepare_frame);
|
|
|
|
klass->clean_frame = GST_DEBUG_FUNCPTR (gst_video_aggregator_pad_clean_frame);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_pad_init (GstVideoAggregatorPad * vaggpad)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
2014-06-20 20:02:07 +00:00
|
|
|
vaggpad->priv =
|
|
|
|
G_TYPE_INSTANCE_GET_PRIVATE (vaggpad, GST_TYPE_VIDEO_AGGREGATOR_PAD,
|
|
|
|
GstVideoAggregatorPadPrivate);
|
|
|
|
|
2018-05-04 15:18:12 +00:00
|
|
|
vaggpad->priv->zorder = DEFAULT_PAD_ZORDER;
|
|
|
|
vaggpad->priv->repeat_after_eos = DEFAULT_PAD_REPEAT_AFTER_EOS;
|
2018-05-05 13:49:17 +00:00
|
|
|
memset (&vaggpad->priv->prepared_frame, 0, sizeof (GstVideoFrame));
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
2018-05-05 13:49:17 +00:00
|
|
|
/**
|
|
|
|
* gst_video_aggregator_pad_has_current_buffer:
|
|
|
|
* @pad: a #GstVideoAggregatorPad
|
|
|
|
*
|
|
|
|
* Checks if the pad currently has a buffer queued that is going to be used
|
|
|
|
* for the current output frame.
|
|
|
|
*
|
|
|
|
* This must only be called from the aggregate_frames() virtual method,
|
|
|
|
* or from the prepare_frame() virtual method of the aggregator pads.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the pad has currently a buffer queued
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_video_aggregator_pad_has_current_buffer (GstVideoAggregatorPad * pad)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_VIDEO_AGGREGATOR_PAD (pad), FALSE);
|
|
|
|
|
|
|
|
return pad->priv->buffer != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_aggregator_pad_has_current_buffer:
|
|
|
|
* @pad: a #GstVideoAggregatorPad
|
|
|
|
*
|
|
|
|
* Returns the currently queued buffer that is going to be used
|
|
|
|
* for the current output frame.
|
|
|
|
*
|
|
|
|
* This must only be called from the aggregate_frames() virtual method,
|
|
|
|
* or from the prepare_frame() virtual method of the aggregator pads.
|
|
|
|
*
|
|
|
|
* The return value is only valid until aggregate_frames() or prepare_frames()
|
|
|
|
* returns.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The currently queued buffer
|
|
|
|
*/
|
|
|
|
GstBuffer *
|
|
|
|
gst_video_aggregator_pad_get_current_buffer (GstVideoAggregatorPad * pad)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_VIDEO_AGGREGATOR_PAD (pad), NULL);
|
|
|
|
|
|
|
|
return pad->priv->buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_aggregator_pad_get_prepared_frame:
|
|
|
|
* @pad: a #GstVideoAggregatorPad
|
|
|
|
*
|
|
|
|
* Returns the currently prepared video frame that has to be aggregated into
|
|
|
|
* the current output frame.
|
|
|
|
*
|
|
|
|
* This must only be called from the aggregate_frames() virtual method,
|
|
|
|
* or from the prepare_frame() virtual method of the aggregator pads.
|
|
|
|
*
|
|
|
|
* The return value is only valid until aggregate_frames() or prepare_frames()
|
|
|
|
* returns.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The currently prepared video frame
|
|
|
|
*/
|
|
|
|
GstVideoFrame *
|
|
|
|
gst_video_aggregator_pad_get_prepared_frame (GstVideoAggregatorPad * pad)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_VIDEO_AGGREGATOR_PAD (pad), NULL);
|
|
|
|
|
|
|
|
return pad->priv->prepared_frame.buffer ? &pad->priv->prepared_frame : NULL;
|
|
|
|
}
|
|
|
|
|
2018-05-05 14:14:14 +00:00
|
|
|
/**
|
|
|
|
* gst_video_aggregator_pad_set_needs_alpha:
|
|
|
|
* @pad: a #GstVideoAggregatorPad
|
|
|
|
* @needs_alpha: %TRUE if this pad requires alpha output
|
|
|
|
*
|
|
|
|
* Allows selecting that this pad requires an output format with alpha
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The currently prepared video frame
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_video_aggregator_pad_set_needs_alpha (GstVideoAggregatorPad * pad,
|
|
|
|
gboolean needs_alpha)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_VIDEO_AGGREGATOR_PAD (pad));
|
|
|
|
|
|
|
|
if (needs_alpha != pad->priv->needs_alpha) {
|
|
|
|
GstAggregator *agg =
|
|
|
|
GST_AGGREGATOR (gst_object_get_parent (GST_OBJECT (pad)));
|
|
|
|
pad->priv->needs_alpha = needs_alpha;
|
|
|
|
if (agg) {
|
|
|
|
gst_pad_mark_reconfigure (GST_AGGREGATOR_SRC_PAD (agg));
|
|
|
|
gst_object_unref (agg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-06 13:21:24 +00:00
|
|
|
/****************************************
|
|
|
|
* GstVideoAggregatorConvertPad implementation *
|
|
|
|
****************************************/
|
|
|
|
|
|
|
|
struct _GstVideoAggregatorConvertPadPrivate
|
|
|
|
{
|
|
|
|
/* Converter, if NULL no conversion is done */
|
|
|
|
GstVideoConverter *convert;
|
|
|
|
|
|
|
|
/* caps used for conversion if needed */
|
|
|
|
GstVideoInfo conversion_info;
|
|
|
|
GstBuffer *converted_buffer;
|
|
|
|
|
|
|
|
gboolean converter_config_changed;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstVideoAggregatorConvertPad, gst_video_aggregator_convert_pad,
|
|
|
|
GST_TYPE_VIDEO_AGGREGATOR_PAD);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_video_aggregator_convert_pad_finalize (GObject * o)
|
|
|
|
{
|
|
|
|
GstVideoAggregatorConvertPad *vaggpad = GST_VIDEO_AGGREGATOR_CONVERT_PAD (o);
|
|
|
|
|
|
|
|
if (vaggpad->priv->convert)
|
|
|
|
gst_video_converter_free (vaggpad->priv->convert);
|
|
|
|
vaggpad->priv->convert = NULL;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_video_aggregator_pad_parent_class)->finalize (o);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_video_aggregator_convert_pad_update_conversion_info_internal
|
|
|
|
(GstVideoAggregatorPad * vpad)
|
|
|
|
{
|
|
|
|
GstVideoAggregatorConvertPad *pad = GST_VIDEO_AGGREGATOR_CONVERT_PAD (vpad);
|
|
|
|
|
|
|
|
pad->priv->converter_config_changed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_video_aggregator_convert_pad_prepare_frame (GstVideoAggregatorPad * vpad,
|
|
|
|
GstVideoAggregator * vagg, GstBuffer * buffer,
|
|
|
|
GstVideoFrame * prepared_frame)
|
|
|
|
{
|
|
|
|
GstVideoAggregatorConvertPad *pad = GST_VIDEO_AGGREGATOR_CONVERT_PAD (vpad);
|
|
|
|
GstVideoFrame frame;
|
|
|
|
|
|
|
|
/* Update/create converter as needed */
|
|
|
|
if (pad->priv->converter_config_changed) {
|
|
|
|
GstVideoAggregatorConvertPadClass *klass =
|
|
|
|
GST_VIDEO_AGGREGATOR_CONVERT_PAD_GET_CLASS (pad);
|
|
|
|
GstVideoInfo conversion_info;
|
|
|
|
|
|
|
|
gst_video_info_init (&conversion_info);
|
|
|
|
klass->create_conversion_info (pad, vagg, &conversion_info);
|
|
|
|
if (conversion_info.finfo == NULL)
|
|
|
|
return FALSE;
|
|
|
|
pad->priv->converter_config_changed = FALSE;
|
|
|
|
|
|
|
|
if (!pad->priv->conversion_info.finfo
|
|
|
|
|| !gst_video_info_is_equal (&conversion_info,
|
|
|
|
&pad->priv->conversion_info)) {
|
|
|
|
pad->priv->conversion_info = conversion_info;
|
|
|
|
|
|
|
|
if (pad->priv->convert)
|
|
|
|
gst_video_converter_free (pad->priv->convert);
|
|
|
|
pad->priv->convert = NULL;
|
|
|
|
|
|
|
|
if (!gst_video_info_is_equal (&vpad->info, &pad->priv->conversion_info)) {
|
|
|
|
pad->priv->convert =
|
|
|
|
gst_video_converter_new (&vpad->info, &pad->priv->conversion_info,
|
|
|
|
NULL);
|
|
|
|
if (!pad->priv->convert) {
|
|
|
|
GST_WARNING_OBJECT (pad, "No path found for conversion");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "This pad will be converted from %d to %d",
|
|
|
|
GST_VIDEO_INFO_FORMAT (&vpad->info),
|
|
|
|
GST_VIDEO_INFO_FORMAT (&pad->priv->conversion_info));
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (pad, "This pad will not need conversion");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_video_frame_map (&frame, &vpad->info, buffer, GST_MAP_READ)) {
|
|
|
|
GST_WARNING_OBJECT (vagg, "Could not map input buffer");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pad->priv->convert) {
|
|
|
|
GstVideoFrame converted_frame;
|
|
|
|
GstBuffer *converted_buf = NULL;
|
|
|
|
static GstAllocationParams params = { 0, 15, 0, 0, };
|
|
|
|
gint converted_size;
|
|
|
|
guint outsize;
|
|
|
|
|
|
|
|
/* We wait until here to set the conversion infos, in case vagg->info changed */
|
|
|
|
converted_size = pad->priv->conversion_info.size;
|
|
|
|
outsize = GST_VIDEO_INFO_SIZE (&vagg->info);
|
|
|
|
converted_size = converted_size > outsize ? converted_size : outsize;
|
|
|
|
converted_buf = gst_buffer_new_allocate (NULL, converted_size, ¶ms);
|
|
|
|
|
|
|
|
if (!gst_video_frame_map (&converted_frame, &(pad->priv->conversion_info),
|
|
|
|
converted_buf, GST_MAP_READWRITE)) {
|
|
|
|
GST_WARNING_OBJECT (vagg, "Could not map converted frame");
|
|
|
|
|
|
|
|
gst_video_frame_unmap (&frame);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_video_converter_frame (pad->priv->convert, &frame, &converted_frame);
|
|
|
|
pad->priv->converted_buffer = converted_buf;
|
|
|
|
gst_video_frame_unmap (&frame);
|
|
|
|
*prepared_frame = converted_frame;
|
|
|
|
} else {
|
|
|
|
*prepared_frame = frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_video_aggregator_convert_pad_clean_frame (GstVideoAggregatorPad * vpad,
|
|
|
|
GstVideoAggregator * vagg, GstVideoFrame * prepared_frame)
|
|
|
|
{
|
|
|
|
GstVideoAggregatorConvertPad *pad = GST_VIDEO_AGGREGATOR_CONVERT_PAD (vpad);
|
|
|
|
|
|
|
|
if (prepared_frame->buffer) {
|
|
|
|
gst_video_frame_unmap (prepared_frame);
|
|
|
|
memset (prepared_frame, 0, sizeof (GstVideoFrame));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pad->priv->converted_buffer) {
|
|
|
|
gst_buffer_unref (pad->priv->converted_buffer);
|
|
|
|
pad->priv->converted_buffer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_video_aggregator_convert_pad_create_conversion_info
|
|
|
|
(GstVideoAggregatorConvertPad * pad, GstVideoAggregator * agg,
|
|
|
|
GstVideoInfo * convert_info)
|
|
|
|
{
|
|
|
|
GstVideoAggregatorPad *vpad = GST_VIDEO_AGGREGATOR_PAD (pad);
|
|
|
|
gchar *colorimetry, *best_colorimetry;
|
|
|
|
const gchar *chroma, *best_chroma;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_VIDEO_AGGREGATOR_CONVERT_PAD (pad));
|
|
|
|
g_return_if_fail (convert_info != NULL);
|
|
|
|
|
|
|
|
if (!vpad->info.finfo
|
|
|
|
|| GST_VIDEO_INFO_FORMAT (&vpad->info) == GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!agg->info.finfo
|
|
|
|
|| GST_VIDEO_INFO_FORMAT (&agg->info) == GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
colorimetry = gst_video_colorimetry_to_string (&vpad->info.colorimetry);
|
|
|
|
chroma = gst_video_chroma_to_string (vpad->info.chroma_site);
|
|
|
|
|
|
|
|
best_colorimetry = gst_video_colorimetry_to_string (&agg->info.colorimetry);
|
|
|
|
best_chroma = gst_video_chroma_to_string (agg->info.chroma_site);
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_FORMAT (&agg->info) != GST_VIDEO_INFO_FORMAT (&vpad->info)
|
|
|
|
|| g_strcmp0 (colorimetry, best_colorimetry)
|
|
|
|
|| g_strcmp0 (chroma, best_chroma)) {
|
|
|
|
GstVideoInfo tmp_info;
|
|
|
|
|
|
|
|
/* Initialize with the wanted video format and our original width and
|
|
|
|
* height as we don't want to rescale. Then copy over the wanted
|
|
|
|
* colorimetry, and chroma-site and our current pixel-aspect-ratio
|
|
|
|
* and other relevant fields.
|
|
|
|
*/
|
|
|
|
gst_video_info_set_format (&tmp_info, GST_VIDEO_INFO_FORMAT (&agg->info),
|
|
|
|
vpad->info.width, vpad->info.height);
|
|
|
|
tmp_info.chroma_site = agg->info.chroma_site;
|
|
|
|
tmp_info.colorimetry = agg->info.colorimetry;
|
|
|
|
tmp_info.par_n = vpad->info.par_n;
|
|
|
|
tmp_info.par_d = vpad->info.par_d;
|
|
|
|
tmp_info.fps_n = vpad->info.fps_n;
|
|
|
|
tmp_info.fps_d = vpad->info.fps_d;
|
|
|
|
tmp_info.flags = vpad->info.flags;
|
|
|
|
tmp_info.interlace_mode = vpad->info.interlace_mode;
|
|
|
|
|
|
|
|
*convert_info = tmp_info;
|
|
|
|
} else {
|
|
|
|
*convert_info = vpad->info;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (colorimetry);
|
|
|
|
g_free (best_colorimetry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_video_aggregator_convert_pad_class_init (GstVideoAggregatorConvertPadClass *
|
|
|
|
klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstVideoAggregatorPadClass *vaggpadclass =
|
|
|
|
(GstVideoAggregatorPadClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->finalize = gst_video_aggregator_convert_pad_finalize;
|
|
|
|
|
|
|
|
g_type_class_add_private (klass,
|
|
|
|
sizeof (GstVideoAggregatorConvertPadPrivate));
|
|
|
|
|
|
|
|
vaggpadclass->update_conversion_info =
|
|
|
|
GST_DEBUG_FUNCPTR
|
|
|
|
(gst_video_aggregator_convert_pad_update_conversion_info_internal);
|
|
|
|
vaggpadclass->prepare_frame =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_aggregator_convert_pad_prepare_frame);
|
|
|
|
vaggpadclass->clean_frame =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_aggregator_convert_pad_clean_frame);
|
|
|
|
|
|
|
|
klass->create_conversion_info =
|
|
|
|
gst_video_aggregator_convert_pad_create_conversion_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_video_aggregator_convert_pad_init (GstVideoAggregatorConvertPad * vaggpad)
|
|
|
|
{
|
|
|
|
vaggpad->priv =
|
|
|
|
G_TYPE_INSTANCE_GET_PRIVATE (vaggpad,
|
|
|
|
GST_TYPE_VIDEO_AGGREGATOR_CONVERT_PAD,
|
|
|
|
GstVideoAggregatorConvertPadPrivate);
|
|
|
|
|
|
|
|
vaggpad->priv->converted_buffer = NULL;
|
|
|
|
vaggpad->priv->convert = NULL;
|
|
|
|
vaggpad->priv->converter_config_changed = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_aggregator_convert_pad_update_conversion_info:
|
|
|
|
* @pad: a #GstVideoAggregatorPad
|
|
|
|
*
|
|
|
|
* Requests the pad to check and update the converter before the next usage to
|
|
|
|
* update for any changes that have happened.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void gst_video_aggregator_convert_pad_update_conversion_info
|
|
|
|
(GstVideoAggregatorConvertPad * pad)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_VIDEO_AGGREGATOR_CONVERT_PAD (pad));
|
|
|
|
|
|
|
|
pad->priv->converter_config_changed = TRUE;
|
|
|
|
}
|
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
/**************************************
|
|
|
|
* GstVideoAggregator implementation *
|
|
|
|
**************************************/
|
|
|
|
|
|
|
|
#define GST_VIDEO_AGGREGATOR_GET_LOCK(vagg) (&GST_VIDEO_AGGREGATOR(vagg)->priv->lock)
|
|
|
|
|
|
|
|
#define GST_VIDEO_AGGREGATOR_LOCK(vagg) G_STMT_START { \
|
|
|
|
GST_LOG_OBJECT (vagg, "Taking EVENT lock from thread %p", \
|
|
|
|
g_thread_self()); \
|
|
|
|
g_mutex_lock(GST_VIDEO_AGGREGATOR_GET_LOCK(vagg)); \
|
|
|
|
GST_LOG_OBJECT (vagg, "Took EVENT lock from thread %p", \
|
|
|
|
g_thread_self()); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#define GST_VIDEO_AGGREGATOR_UNLOCK(vagg) G_STMT_START { \
|
|
|
|
GST_LOG_OBJECT (vagg, "Releasing EVENT lock from thread %p", \
|
|
|
|
g_thread_self()); \
|
|
|
|
g_mutex_unlock(GST_VIDEO_AGGREGATOR_GET_LOCK(vagg)); \
|
|
|
|
GST_LOG_OBJECT (vagg, "Took EVENT lock from thread %p", \
|
|
|
|
g_thread_self()); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
|
|
|
|
struct _GstVideoAggregatorPrivate
|
|
|
|
{
|
|
|
|
/* Lock to prevent the state to change while aggregating */
|
|
|
|
GMutex lock;
|
|
|
|
|
|
|
|
/* Current downstream segment */
|
|
|
|
GstClockTime ts_offset;
|
|
|
|
guint64 nframes;
|
|
|
|
|
|
|
|
/* QoS stuff */
|
|
|
|
gdouble proportion;
|
|
|
|
GstClockTime earliest_time;
|
|
|
|
guint64 qos_processed, qos_dropped;
|
|
|
|
|
|
|
|
/* current caps */
|
|
|
|
GstCaps *current_caps;
|
2015-06-15 12:18:39 +00:00
|
|
|
|
|
|
|
gboolean live;
|
2014-06-03 17:00:34 +00:00
|
|
|
};
|
|
|
|
|
2015-09-09 22:51:18 +00:00
|
|
|
/* Can't use the G_DEFINE_TYPE macros because we need the
|
|
|
|
* videoaggregator class in the _init to be able to set
|
|
|
|
* the sink pad non-alpha caps. Using the G_DEFINE_TYPE there
|
|
|
|
* seems to be no way of getting the real class being initialized */
|
2016-05-16 11:27:50 +00:00
|
|
|
static void gst_video_aggregator_init (GstVideoAggregator * self,
|
2015-09-09 22:51:18 +00:00
|
|
|
GstVideoAggregatorClass * klass);
|
2016-05-16 11:27:50 +00:00
|
|
|
static void gst_video_aggregator_class_init (GstVideoAggregatorClass * klass);
|
|
|
|
static gpointer gst_video_aggregator_parent_class = NULL;
|
2015-09-09 22:51:18 +00:00
|
|
|
|
|
|
|
GType
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_get_type (void)
|
2015-09-09 22:51:18 +00:00
|
|
|
{
|
|
|
|
static volatile gsize g_define_type_id_volatile = 0;
|
2015-09-29 12:31:18 +00:00
|
|
|
|
2015-09-09 22:51:18 +00:00
|
|
|
if (g_once_init_enter (&g_define_type_id_volatile)) {
|
|
|
|
GType g_define_type_id = g_type_register_static_simple (GST_TYPE_AGGREGATOR,
|
|
|
|
g_intern_static_string ("GstVideoAggregator"),
|
|
|
|
sizeof (GstVideoAggregatorClass),
|
2016-05-16 11:27:50 +00:00
|
|
|
(GClassInitFunc) gst_video_aggregator_class_init,
|
2015-09-09 22:51:18 +00:00
|
|
|
sizeof (GstVideoAggregator),
|
2016-05-16 11:27:50 +00:00
|
|
|
(GInstanceInitFunc) gst_video_aggregator_init,
|
2015-09-09 22:51:18 +00:00
|
|
|
(GTypeFlags) G_TYPE_FLAG_ABSTRACT);
|
|
|
|
g_once_init_leave (&g_define_type_id_volatile, g_define_type_id);
|
|
|
|
}
|
|
|
|
return g_define_type_id_volatile;
|
|
|
|
}
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_find_best_format (GstVideoAggregator * vagg,
|
2014-11-26 17:24:05 +00:00
|
|
|
GstCaps * downstream_caps, GstVideoInfo * best_info,
|
2014-06-03 17:00:34 +00:00
|
|
|
gboolean * at_least_one_alpha)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
GstCaps *possible_caps;
|
|
|
|
GstVideoAggregatorPad *pad;
|
|
|
|
gboolean need_alpha = FALSE;
|
|
|
|
gint best_format_number = 0;
|
|
|
|
GHashTable *formats_table = g_hash_table_new (g_direct_hash, g_direct_equal);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (vagg);
|
|
|
|
for (tmp = GST_ELEMENT (vagg)->sinkpads; tmp; tmp = tmp->next) {
|
|
|
|
GstStructure *s;
|
|
|
|
gint format_number;
|
|
|
|
|
|
|
|
pad = tmp->data;
|
|
|
|
|
|
|
|
if (!pad->info.finfo)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (pad->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_ALPHA)
|
|
|
|
*at_least_one_alpha = TRUE;
|
|
|
|
|
|
|
|
/* If we want alpha, disregard all the other formats */
|
|
|
|
if (need_alpha && !(pad->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_ALPHA))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* This can happen if we release a pad and another pad hasn't been negotiated_caps yet */
|
|
|
|
if (GST_VIDEO_INFO_FORMAT (&pad->info) == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
possible_caps = gst_video_info_to_caps (&pad->info);
|
|
|
|
|
|
|
|
s = gst_caps_get_structure (possible_caps, 0);
|
|
|
|
gst_structure_remove_fields (s, "width", "height", "framerate",
|
|
|
|
"pixel-aspect-ratio", "interlace-mode", NULL);
|
|
|
|
|
|
|
|
/* Can downstream accept this format ? */
|
|
|
|
if (!gst_caps_can_intersect (downstream_caps, possible_caps)) {
|
|
|
|
gst_caps_unref (possible_caps);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_unref (possible_caps);
|
|
|
|
|
|
|
|
format_number =
|
|
|
|
GPOINTER_TO_INT (g_hash_table_lookup (formats_table,
|
|
|
|
GINT_TO_POINTER (GST_VIDEO_INFO_FORMAT (&pad->info))));
|
2017-08-09 23:45:53 +00:00
|
|
|
format_number += pad->info.width * pad->info.height;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
g_hash_table_replace (formats_table,
|
|
|
|
GINT_TO_POINTER (GST_VIDEO_INFO_FORMAT (&pad->info)),
|
|
|
|
GINT_TO_POINTER (format_number));
|
|
|
|
|
|
|
|
/* If that pad is the first with alpha, set it as the new best format */
|
2018-05-05 14:14:14 +00:00
|
|
|
if (!need_alpha && (pad->priv->needs_alpha
|
2017-07-06 18:26:21 +00:00
|
|
|
&& (!GST_VIDEO_FORMAT_INFO_HAS_ALPHA (pad->info.finfo)))) {
|
|
|
|
need_alpha = TRUE;
|
|
|
|
/* Just fallback to ARGB in case we require alpha but the input pad
|
|
|
|
* does not have alpha.
|
|
|
|
* Do not increment best_format_number in that case. */
|
|
|
|
gst_video_info_set_format (best_info,
|
|
|
|
GST_VIDEO_FORMAT_ARGB,
|
2017-08-04 08:08:18 +00:00
|
|
|
GST_VIDEO_INFO_WIDTH (&pad->info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&pad->info));
|
2017-07-06 18:26:21 +00:00
|
|
|
} else if (!need_alpha
|
|
|
|
&& (pad->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_ALPHA)) {
|
2014-06-03 17:00:34 +00:00
|
|
|
need_alpha = TRUE;
|
|
|
|
*best_info = pad->info;
|
|
|
|
best_format_number = format_number;
|
|
|
|
} else if (format_number > best_format_number) {
|
|
|
|
*best_info = pad->info;
|
|
|
|
best_format_number = format_number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
|
|
|
|
|
|
|
g_hash_table_unref (formats_table);
|
|
|
|
}
|
|
|
|
|
2015-10-14 10:13:57 +00:00
|
|
|
static GstCaps *
|
2017-05-20 12:24:57 +00:00
|
|
|
gst_video_aggregator_default_fixate_src_caps (GstAggregator * agg,
|
2015-10-14 10:13:57 +00:00
|
|
|
GstCaps * caps)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
2017-05-20 12:24:57 +00:00
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (agg);
|
2014-06-03 17:00:34 +00:00
|
|
|
gint best_width = -1, best_height = -1;
|
|
|
|
gint best_fps_n = -1, best_fps_d = -1;
|
2015-10-14 10:13:57 +00:00
|
|
|
gdouble best_fps = -1.;
|
|
|
|
GstStructure *s;
|
|
|
|
GList *l;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (vagg);
|
|
|
|
for (l = GST_ELEMENT (vagg)->sinkpads; l; l = l->next) {
|
|
|
|
GstVideoAggregatorPad *mpad = l->data;
|
|
|
|
gint fps_n, fps_d;
|
|
|
|
gint width, height;
|
2015-10-14 10:13:57 +00:00
|
|
|
gdouble cur_fps;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
fps_n = GST_VIDEO_INFO_FPS_N (&mpad->info);
|
|
|
|
fps_d = GST_VIDEO_INFO_FPS_D (&mpad->info);
|
|
|
|
width = GST_VIDEO_INFO_WIDTH (&mpad->info);
|
|
|
|
height = GST_VIDEO_INFO_HEIGHT (&mpad->info);
|
|
|
|
|
|
|
|
if (width == 0 || height == 0)
|
|
|
|
continue;
|
|
|
|
|
2015-10-14 10:13:57 +00:00
|
|
|
if (best_width < width)
|
|
|
|
best_width = width;
|
|
|
|
if (best_height < height)
|
|
|
|
best_height = height;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
if (fps_d == 0)
|
|
|
|
cur_fps = 0.0;
|
|
|
|
else
|
|
|
|
gst_util_fraction_to_double (fps_n, fps_d, &cur_fps);
|
|
|
|
|
|
|
|
if (best_fps < cur_fps) {
|
|
|
|
best_fps = cur_fps;
|
|
|
|
best_fps_n = fps_n;
|
|
|
|
best_fps_d = fps_d;
|
|
|
|
}
|
|
|
|
}
|
2014-07-06 21:30:53 +00:00
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
if (best_fps_n <= 0 || best_fps_d <= 0 || best_fps == 0.0) {
|
|
|
|
best_fps_n = 25;
|
|
|
|
best_fps_d = 1;
|
|
|
|
best_fps = 25.0;
|
|
|
|
}
|
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
caps = gst_caps_make_writable (caps);
|
2015-10-14 10:13:57 +00:00
|
|
|
s = gst_caps_get_structure (caps, 0);
|
|
|
|
gst_structure_fixate_field_nearest_int (s, "width", best_width);
|
|
|
|
gst_structure_fixate_field_nearest_int (s, "height", best_height);
|
|
|
|
gst_structure_fixate_field_nearest_fraction (s, "framerate", best_fps_n,
|
|
|
|
best_fps_d);
|
|
|
|
if (gst_structure_has_field (s, "pixel-aspect-ratio"))
|
|
|
|
gst_structure_fixate_field_nearest_fraction (s, "pixel-aspect-ratio", 1, 1);
|
|
|
|
caps = gst_caps_fixate (caps);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2015-10-14 10:13:57 +00:00
|
|
|
return caps;
|
|
|
|
}
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2015-10-14 10:13:57 +00:00
|
|
|
static GstCaps *
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_default_update_caps (GstVideoAggregator * vagg,
|
2017-05-20 12:24:57 +00:00
|
|
|
GstCaps * caps)
|
2015-10-14 10:13:57 +00:00
|
|
|
{
|
2016-04-04 10:55:51 +00:00
|
|
|
GstVideoAggregatorClass *vagg_klass = GST_VIDEO_AGGREGATOR_GET_CLASS (vagg);
|
|
|
|
GstCaps *ret, *best_format_caps;
|
|
|
|
gboolean at_least_one_alpha = FALSE;
|
|
|
|
GstVideoFormat best_format;
|
|
|
|
GstVideoInfo best_info;
|
2017-11-25 11:48:40 +00:00
|
|
|
gchar *color_name;
|
2016-04-04 10:55:51 +00:00
|
|
|
|
|
|
|
best_format = GST_VIDEO_FORMAT_UNKNOWN;
|
|
|
|
gst_video_info_init (&best_info);
|
|
|
|
|
|
|
|
if (vagg_klass->find_best_format) {
|
|
|
|
vagg_klass->find_best_format (vagg, caps, &best_info, &at_least_one_alpha);
|
|
|
|
|
|
|
|
best_format = GST_VIDEO_INFO_FORMAT (&best_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (best_format == GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
GstCaps *tmp = gst_caps_fixate (gst_caps_ref (caps));
|
|
|
|
gst_video_info_from_caps (&best_info, tmp);
|
|
|
|
best_format = GST_VIDEO_INFO_FORMAT (&best_info);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (vagg,
|
2017-08-09 23:48:18 +00:00
|
|
|
"The output format will now be : %d with chroma : %s and colorimetry %s",
|
|
|
|
best_format, gst_video_chroma_to_string (best_info.chroma_site),
|
|
|
|
gst_video_colorimetry_to_string (&best_info.colorimetry));
|
2016-04-04 10:55:51 +00:00
|
|
|
|
|
|
|
best_format_caps = gst_caps_copy (caps);
|
2017-11-25 11:48:40 +00:00
|
|
|
color_name = gst_video_colorimetry_to_string (&best_info.colorimetry);
|
2016-04-04 10:55:51 +00:00
|
|
|
gst_caps_set_simple (best_format_caps, "format", G_TYPE_STRING,
|
|
|
|
gst_video_format_to_string (best_format), "chroma-site", G_TYPE_STRING,
|
2017-08-09 23:48:18 +00:00
|
|
|
gst_video_chroma_to_string (best_info.chroma_site), "colorimetry",
|
2017-11-25 11:48:40 +00:00
|
|
|
G_TYPE_STRING, color_name, NULL);
|
|
|
|
g_free (color_name);
|
2016-04-04 10:55:51 +00:00
|
|
|
ret = gst_caps_merge (best_format_caps, gst_caps_ref (caps));
|
2015-05-10 08:55:16 +00:00
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_video_aggregator_default_update_src_caps (GstAggregator * agg,
|
|
|
|
GstCaps * caps, GstCaps ** ret)
|
|
|
|
{
|
|
|
|
GstVideoAggregatorClass *vagg_klass = GST_VIDEO_AGGREGATOR_GET_CLASS (agg);
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (agg);
|
|
|
|
gboolean at_least_one_pad_configured = FALSE;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (vagg);
|
|
|
|
for (l = GST_ELEMENT (vagg)->sinkpads; l; l = l->next) {
|
|
|
|
GstVideoAggregatorPad *mpad = l->data;
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_WIDTH (&mpad->info) == 0
|
|
|
|
|| GST_VIDEO_INFO_HEIGHT (&mpad->info) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
at_least_one_pad_configured = TRUE;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
|
|
|
|
|
|
|
if (!at_least_one_pad_configured) {
|
|
|
|
/* We couldn't decide the output video info because the sinkpads don't have
|
|
|
|
* all the caps yet, so we mark the pad as needing a reconfigure. This
|
|
|
|
* allows aggregate() to skip ahead a bit and try again later. */
|
|
|
|
GST_DEBUG_OBJECT (vagg, "Couldn't decide output video info");
|
|
|
|
gst_pad_mark_reconfigure (agg->srcpad);
|
|
|
|
return GST_AGGREGATOR_FLOW_NEED_DATA;
|
2015-10-14 10:13:57 +00:00
|
|
|
}
|
2015-05-10 08:55:16 +00:00
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
g_assert (vagg_klass->update_caps);
|
|
|
|
|
|
|
|
*ret = vagg_klass->update_caps (vagg, caps);
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
2015-10-14 10:13:57 +00:00
|
|
|
}
|
2014-10-19 23:34:27 +00:00
|
|
|
|
2015-10-14 10:13:57 +00:00
|
|
|
static gboolean
|
2017-05-20 12:24:57 +00:00
|
|
|
gst_video_aggregator_default_negotiated_src_caps (GstAggregator * agg,
|
|
|
|
GstCaps * caps)
|
2015-10-14 10:13:57 +00:00
|
|
|
{
|
2017-05-20 12:24:57 +00:00
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (agg);
|
2015-10-14 10:13:57 +00:00
|
|
|
gboolean at_least_one_alpha = FALSE;
|
2017-05-20 12:24:57 +00:00
|
|
|
const GstVideoFormatInfo *finfo;
|
|
|
|
GstVideoInfo info;
|
2015-10-14 10:13:57 +00:00
|
|
|
GList *l;
|
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
GST_INFO_OBJECT (agg->srcpad, "set src caps: %" GST_PTR_FORMAT, caps);
|
2015-10-14 10:13:57 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (vagg);
|
|
|
|
for (l = GST_ELEMENT (vagg)->sinkpads; l; l = l->next) {
|
|
|
|
GstVideoAggregatorPad *mpad = l->data;
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_WIDTH (&mpad->info) == 0
|
|
|
|
|| GST_VIDEO_INFO_HEIGHT (&mpad->info) == 0)
|
|
|
|
continue;
|
|
|
|
|
2016-04-04 10:55:51 +00:00
|
|
|
if (mpad->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_ALPHA)
|
|
|
|
at_least_one_alpha = TRUE;
|
2015-10-14 10:13:57 +00:00
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_FPS_N (&vagg->info) != GST_VIDEO_INFO_FPS_N (&info) ||
|
|
|
|
GST_VIDEO_INFO_FPS_D (&vagg->info) != GST_VIDEO_INFO_FPS_D (&info)) {
|
2018-02-28 23:34:40 +00:00
|
|
|
if (GST_AGGREGATOR_PAD (agg->srcpad)->segment.position != -1) {
|
2017-05-20 12:24:57 +00:00
|
|
|
vagg->priv->nframes = 0;
|
|
|
|
/* The timestamp offset will be updated based on the
|
|
|
|
* segment position the next time we aggregate */
|
|
|
|
GST_DEBUG_OBJECT (vagg,
|
|
|
|
"Resetting frame counter because of framerate change");
|
2015-10-14 10:13:57 +00:00
|
|
|
}
|
2017-05-20 12:24:57 +00:00
|
|
|
gst_video_aggregator_reset_qos (vagg);
|
|
|
|
}
|
|
|
|
|
|
|
|
vagg->info = info;
|
2016-04-04 10:55:51 +00:00
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
finfo = vagg->info.finfo;
|
2015-10-14 10:13:57 +00:00
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
if (at_least_one_alpha && !(finfo->flags & GST_VIDEO_FORMAT_FLAG_ALPHA)) {
|
|
|
|
GST_ELEMENT_ERROR (vagg, CORE, NEGOTIATION,
|
|
|
|
("At least one of the input pads contains alpha, but configured caps don't support alpha."),
|
|
|
|
("Either convert your inputs to not contain alpha or add a videoconvert after the aggregator"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-10-14 10:13:57 +00:00
|
|
|
|
2017-11-06 20:07:51 +00:00
|
|
|
/* Then browse the sinks once more, setting or unsetting conversion if needed */
|
|
|
|
for (l = GST_ELEMENT (vagg)->sinkpads; l; l = l->next) {
|
|
|
|
GstVideoAggregatorPad *pad = GST_VIDEO_AGGREGATOR_PAD (l->data);
|
|
|
|
GstVideoAggregatorPadClass *vaggpad_klass =
|
|
|
|
GST_VIDEO_AGGREGATOR_PAD_GET_CLASS (pad);
|
2016-04-04 10:55:51 +00:00
|
|
|
|
2018-05-06 13:21:24 +00:00
|
|
|
if (vaggpad_klass->update_conversion_info) {
|
|
|
|
vaggpad_klass->update_conversion_info (pad);
|
2015-10-14 10:13:57 +00:00
|
|
|
}
|
2017-05-20 12:24:57 +00:00
|
|
|
}
|
2015-10-14 10:13:57 +00:00
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
if (vagg->priv->current_caps == NULL ||
|
|
|
|
gst_caps_is_equal (caps, vagg->priv->current_caps) == FALSE) {
|
|
|
|
GstClockTime latency;
|
2015-10-14 10:13:57 +00:00
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
gst_caps_replace (&vagg->priv->current_caps, caps);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
gst_aggregator_set_src_caps (agg, caps);
|
|
|
|
latency = gst_util_uint64_scale (GST_SECOND,
|
|
|
|
GST_VIDEO_INFO_FPS_D (&vagg->info), GST_VIDEO_INFO_FPS_N (&vagg->info));
|
|
|
|
gst_aggregator_set_latency (agg, latency, latency);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
return TRUE;
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
2016-03-28 18:44:27 +00:00
|
|
|
static gboolean
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_get_sinkpads_interlace_mode (GstVideoAggregator * vagg,
|
2016-03-28 18:44:27 +00:00
|
|
|
GstVideoAggregatorPad * skip_pad, GstVideoInterlaceMode * mode)
|
|
|
|
{
|
|
|
|
GList *walk;
|
|
|
|
|
|
|
|
for (walk = GST_ELEMENT (vagg)->sinkpads; walk; walk = g_list_next (walk)) {
|
|
|
|
GstVideoAggregatorPad *vaggpad = walk->data;
|
|
|
|
|
|
|
|
if (skip_pad && vaggpad == skip_pad)
|
|
|
|
continue;
|
|
|
|
if (vaggpad->info.finfo
|
|
|
|
&& GST_VIDEO_INFO_FORMAT (&vaggpad->info) != GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
*mode = GST_VIDEO_INFO_INTERLACE_MODE (&vaggpad->info);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
static gboolean
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_pad_sink_setcaps (GstPad * pad, GstObject * parent,
|
2014-06-03 17:00:34 +00:00
|
|
|
GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg;
|
|
|
|
GstVideoAggregatorPad *vaggpad;
|
|
|
|
GstVideoInfo info;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (pad, "Setting caps %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
vagg = GST_VIDEO_AGGREGATOR (parent);
|
|
|
|
vaggpad = GST_VIDEO_AGGREGATOR_PAD (pad);
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&info, caps)) {
|
|
|
|
GST_DEBUG_OBJECT (pad, "Failed to parse caps");
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_VIDEO_AGGREGATOR_LOCK (vagg);
|
2016-03-28 18:44:27 +00:00
|
|
|
{
|
|
|
|
GstVideoInterlaceMode pads_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
|
|
|
|
gboolean has_mode = FALSE;
|
|
|
|
|
|
|
|
/* get the current output setting or fallback to other pads settings */
|
|
|
|
if (GST_VIDEO_INFO_FORMAT (&vagg->info) != GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
pads_mode = GST_VIDEO_INFO_INTERLACE_MODE (&vagg->info);
|
|
|
|
has_mode = TRUE;
|
|
|
|
} else {
|
|
|
|
has_mode =
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_get_sinkpads_interlace_mode (vagg, vaggpad,
|
2016-03-28 18:44:27 +00:00
|
|
|
&pads_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_mode) {
|
|
|
|
if (pads_mode != GST_VIDEO_INFO_INTERLACE_MODE (&info)) {
|
|
|
|
GST_ERROR_OBJECT (pad,
|
|
|
|
"got input caps %" GST_PTR_FORMAT ", but current caps are %"
|
|
|
|
GST_PTR_FORMAT, caps, vagg->priv->current_caps);
|
|
|
|
GST_VIDEO_AGGREGATOR_UNLOCK (vagg);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-04 08:25:43 +00:00
|
|
|
if (!vaggpad->info.finfo ||
|
|
|
|
GST_VIDEO_INFO_FORMAT (&vaggpad->info) == GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
/* no video info was already set, so this is the first time
|
|
|
|
* that this pad is getting configured; configure immediately to avoid
|
|
|
|
* problems with the initial negotiation */
|
|
|
|
vaggpad->info = info;
|
|
|
|
gst_pad_mark_reconfigure (GST_AGGREGATOR_SRC_PAD (vagg));
|
|
|
|
} else {
|
|
|
|
/* this pad already had caps but received new ones; keep the new caps
|
|
|
|
* pending until we pick the next buffer from the queue, otherwise we
|
|
|
|
* might use an old buffer with the new caps and crash */
|
|
|
|
vaggpad->priv->pending_vinfo = info;
|
|
|
|
GST_DEBUG_OBJECT (pad, "delaying caps change");
|
|
|
|
}
|
2014-11-27 18:52:20 +00:00
|
|
|
ret = TRUE;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2014-09-18 15:14:22 +00:00
|
|
|
GST_VIDEO_AGGREGATOR_UNLOCK (vagg);
|
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
beach:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-09-09 22:51:18 +00:00
|
|
|
static gboolean
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_caps_has_alpha (GstCaps * caps)
|
2015-09-09 22:51:18 +00:00
|
|
|
{
|
|
|
|
guint size = gst_caps_get_size (caps);
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
GstStructure *s = gst_caps_get_structure (caps, i);
|
|
|
|
const GValue *formats = gst_structure_get_value (s, "format");
|
|
|
|
|
|
|
|
if (formats) {
|
|
|
|
const GstVideoFormatInfo *info;
|
|
|
|
|
|
|
|
if (GST_VALUE_HOLDS_LIST (formats)) {
|
|
|
|
guint list_size = gst_value_list_get_size (formats);
|
|
|
|
guint index;
|
|
|
|
|
|
|
|
for (index = 0; index < list_size; index++) {
|
|
|
|
const GValue *list_item = gst_value_list_get_value (formats, index);
|
|
|
|
info =
|
|
|
|
gst_video_format_get_info (gst_video_format_from_string
|
|
|
|
(g_value_get_string (list_item)));
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (info))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (G_VALUE_HOLDS_STRING (formats)) {
|
|
|
|
info =
|
|
|
|
gst_video_format_get_info (gst_video_format_from_string
|
|
|
|
(g_value_get_string (formats)));
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (info))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_assert_not_reached ();
|
|
|
|
GST_WARNING ("Unexpected type for video 'format' field: %s",
|
|
|
|
G_VALUE_TYPE_NAME (formats));
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-05-05 14:31:13 +00:00
|
|
|
static GstCaps *
|
|
|
|
_get_non_alpha_caps (GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstCaps *result;
|
|
|
|
guint i, size;
|
|
|
|
|
|
|
|
size = gst_caps_get_size (caps);
|
|
|
|
result = gst_caps_new_empty ();
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
GstStructure *s = gst_caps_get_structure (caps, i);
|
|
|
|
const GValue *formats = gst_structure_get_value (s, "format");
|
|
|
|
GValue new_formats = { 0, };
|
|
|
|
gboolean has_format = FALSE;
|
|
|
|
|
|
|
|
/* FIXME what to do if formats are missing? */
|
|
|
|
if (formats) {
|
|
|
|
const GstVideoFormatInfo *info;
|
|
|
|
|
|
|
|
if (GST_VALUE_HOLDS_LIST (formats)) {
|
|
|
|
guint list_size = gst_value_list_get_size (formats);
|
|
|
|
guint index;
|
|
|
|
|
|
|
|
g_value_init (&new_formats, GST_TYPE_LIST);
|
|
|
|
|
|
|
|
for (index = 0; index < list_size; index++) {
|
|
|
|
const GValue *list_item = gst_value_list_get_value (formats, index);
|
|
|
|
|
|
|
|
info =
|
|
|
|
gst_video_format_get_info (gst_video_format_from_string
|
|
|
|
(g_value_get_string (list_item)));
|
|
|
|
if (!GST_VIDEO_FORMAT_INFO_HAS_ALPHA (info)) {
|
|
|
|
has_format = TRUE;
|
|
|
|
gst_value_list_append_value (&new_formats, list_item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (G_VALUE_HOLDS_STRING (formats)) {
|
|
|
|
info =
|
|
|
|
gst_video_format_get_info (gst_video_format_from_string
|
|
|
|
(g_value_get_string (formats)));
|
|
|
|
if (!GST_VIDEO_FORMAT_INFO_HAS_ALPHA (info)) {
|
|
|
|
has_format = TRUE;
|
|
|
|
gst_value_init_and_copy (&new_formats, formats);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_assert_not_reached ();
|
|
|
|
GST_WARNING ("Unexpected type for video 'format' field: %s",
|
|
|
|
G_VALUE_TYPE_NAME (formats));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_format) {
|
|
|
|
s = gst_structure_copy (s);
|
|
|
|
gst_structure_take_value (s, "format", &new_formats);
|
|
|
|
gst_caps_append_structure (result, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
static GstCaps *
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_pad_sink_getcaps (GstPad * pad, GstVideoAggregator * vagg,
|
2014-06-03 17:00:34 +00:00
|
|
|
GstCaps * filter)
|
|
|
|
{
|
|
|
|
GstCaps *srccaps;
|
2015-09-09 22:51:18 +00:00
|
|
|
GstCaps *template_caps, *sink_template_caps;
|
2014-06-03 17:00:34 +00:00
|
|
|
GstCaps *returned_caps;
|
|
|
|
GstStructure *s;
|
|
|
|
gint i, n;
|
|
|
|
GstAggregator *agg = GST_AGGREGATOR (vagg);
|
2015-09-09 22:51:18 +00:00
|
|
|
GstPad *srcpad = GST_PAD (agg->srcpad);
|
|
|
|
gboolean has_alpha;
|
2016-03-28 18:44:27 +00:00
|
|
|
GstVideoInterlaceMode interlace_mode;
|
|
|
|
gboolean has_interlace_mode;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2015-09-09 22:51:18 +00:00
|
|
|
template_caps = gst_pad_get_pad_template_caps (srcpad);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2015-09-09 22:51:18 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "Get caps with filter: %" GST_PTR_FORMAT, filter);
|
|
|
|
|
2016-02-18 13:57:51 +00:00
|
|
|
srccaps = gst_pad_peer_query_caps (srcpad, template_caps);
|
2014-06-03 17:00:34 +00:00
|
|
|
srccaps = gst_caps_make_writable (srccaps);
|
2016-05-16 11:27:50 +00:00
|
|
|
has_alpha = gst_video_aggregator_caps_has_alpha (srccaps);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2016-03-28 18:44:27 +00:00
|
|
|
has_interlace_mode =
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_get_sinkpads_interlace_mode (vagg, NULL,
|
2016-03-28 18:44:27 +00:00
|
|
|
&interlace_mode);
|
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
n = gst_caps_get_size (srccaps);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
s = gst_caps_get_structure (srccaps, i);
|
|
|
|
gst_structure_set (s, "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
|
|
|
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
|
|
|
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
|
|
|
|
|
|
|
|
gst_structure_remove_fields (s, "colorimetry", "chroma-site", "format",
|
2015-07-06 16:51:07 +00:00
|
|
|
"pixel-aspect-ratio", NULL);
|
2016-03-28 18:44:27 +00:00
|
|
|
if (has_interlace_mode)
|
|
|
|
gst_structure_set (s, "interlace-mode", G_TYPE_STRING,
|
|
|
|
gst_video_interlace_mode_to_string (interlace_mode), NULL);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
2015-06-20 11:36:27 +00:00
|
|
|
if (filter) {
|
|
|
|
returned_caps = gst_caps_intersect (srccaps, filter);
|
|
|
|
gst_caps_unref (srccaps);
|
|
|
|
} else {
|
|
|
|
returned_caps = srccaps;
|
|
|
|
}
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2018-05-05 14:31:13 +00:00
|
|
|
sink_template_caps = gst_pad_get_pad_template_caps (pad);
|
|
|
|
if (!has_alpha) {
|
|
|
|
GstCaps *tmp = _get_non_alpha_caps (sink_template_caps);
|
|
|
|
gst_caps_unref (sink_template_caps);
|
|
|
|
sink_template_caps = tmp;
|
2015-09-09 22:51:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
GstCaps *intersect = gst_caps_intersect (returned_caps, sink_template_caps);
|
|
|
|
gst_caps_unref (returned_caps);
|
|
|
|
returned_caps = intersect;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_unref (template_caps);
|
|
|
|
gst_caps_unref (sink_template_caps);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "Returning caps: %" GST_PTR_FORMAT, returned_caps);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
return returned_caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_update_qos (GstVideoAggregator * vagg, gdouble proportion,
|
2014-06-03 17:00:34 +00:00
|
|
|
GstClockTimeDiff diff, GstClockTime timestamp)
|
|
|
|
{
|
2014-11-17 03:05:01 +00:00
|
|
|
gboolean live;
|
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_DEBUG_OBJECT (vagg,
|
2015-11-02 16:58:57 +00:00
|
|
|
"Updating QoS: proportion %lf, diff %" GST_STIME_FORMAT ", timestamp %"
|
|
|
|
GST_TIME_FORMAT, proportion, GST_STIME_ARGS (diff),
|
|
|
|
GST_TIME_ARGS (timestamp));
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2015-03-07 02:12:52 +00:00
|
|
|
live =
|
|
|
|
GST_CLOCK_TIME_IS_VALID (gst_aggregator_get_latency (GST_AGGREGATOR
|
|
|
|
(vagg)));
|
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_OBJECT_LOCK (vagg);
|
2014-11-17 03:05:01 +00:00
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
vagg->priv->proportion = proportion;
|
|
|
|
if (G_LIKELY (timestamp != GST_CLOCK_TIME_NONE)) {
|
2014-11-17 03:05:01 +00:00
|
|
|
if (!live && G_UNLIKELY (diff > 0))
|
2014-06-03 17:00:34 +00:00
|
|
|
vagg->priv->earliest_time =
|
|
|
|
timestamp + 2 * diff + gst_util_uint64_scale_int_round (GST_SECOND,
|
|
|
|
GST_VIDEO_INFO_FPS_D (&vagg->info),
|
|
|
|
GST_VIDEO_INFO_FPS_N (&vagg->info));
|
|
|
|
else
|
|
|
|
vagg->priv->earliest_time = timestamp + diff;
|
|
|
|
} else {
|
|
|
|
vagg->priv->earliest_time = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_reset_qos (GstVideoAggregator * vagg)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_update_qos (vagg, 0.5, 0, GST_CLOCK_TIME_NONE);
|
2014-06-03 17:00:34 +00:00
|
|
|
vagg->priv->qos_processed = vagg->priv->qos_dropped = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_read_qos (GstVideoAggregator * vagg, gdouble * proportion,
|
2014-06-03 17:00:34 +00:00
|
|
|
GstClockTime * time)
|
|
|
|
{
|
|
|
|
GST_OBJECT_LOCK (vagg);
|
|
|
|
*proportion = vagg->priv->proportion;
|
|
|
|
*time = vagg->priv->earliest_time;
|
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_reset (GstVideoAggregator * vagg)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GstAggregator *agg = GST_AGGREGATOR (vagg);
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
gst_video_info_init (&vagg->info);
|
|
|
|
vagg->priv->ts_offset = 0;
|
|
|
|
vagg->priv->nframes = 0;
|
2015-06-15 12:18:39 +00:00
|
|
|
vagg->priv->live = FALSE;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2018-02-28 23:34:40 +00:00
|
|
|
GST_AGGREGATOR_PAD (agg->srcpad)->segment.position = -1;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_reset_qos (vagg);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (vagg);
|
|
|
|
for (l = GST_ELEMENT (vagg)->sinkpads; l; l = l->next) {
|
|
|
|
GstVideoAggregatorPad *p = l->data;
|
|
|
|
|
2018-05-05 13:49:17 +00:00
|
|
|
gst_buffer_replace (&p->priv->buffer, NULL);
|
2014-11-27 19:48:24 +00:00
|
|
|
p->priv->start_time = -1;
|
|
|
|
p->priv->end_time = -1;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
gst_video_info_init (&p->info);
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
|
|
|
}
|
|
|
|
|
2017-10-13 10:46:09 +00:00
|
|
|
static GstFlowReturn
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_fill_queues (GstVideoAggregator * vagg,
|
2015-09-11 10:22:51 +00:00
|
|
|
GstClockTime output_start_running_time,
|
|
|
|
GstClockTime output_end_running_time)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GstAggregator *agg = GST_AGGREGATOR (vagg);
|
|
|
|
GList *l;
|
|
|
|
gboolean eos = TRUE;
|
|
|
|
gboolean need_more_data = FALSE;
|
2017-04-04 08:25:43 +00:00
|
|
|
gboolean need_reconfigure = FALSE;
|
2018-02-28 23:34:40 +00:00
|
|
|
GstSegment *agg_segment = &GST_AGGREGATOR_PAD (agg->srcpad)->segment;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2018-05-05 13:49:17 +00:00
|
|
|
/* get a set of buffers into pad->priv->buffer that are within output_start_running_time
|
2015-09-11 10:22:51 +00:00
|
|
|
* and output_end_running_time taking into account finished and unresponsive pads */
|
2014-10-06 07:10:38 +00:00
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_OBJECT_LOCK (vagg);
|
|
|
|
for (l = GST_ELEMENT (vagg)->sinkpads; l; l = l->next) {
|
|
|
|
GstVideoAggregatorPad *pad = l->data;
|
2015-01-14 19:45:06 +00:00
|
|
|
GstSegment segment;
|
2014-06-03 17:00:34 +00:00
|
|
|
GstAggregatorPad *bpad;
|
|
|
|
GstBuffer *buf;
|
|
|
|
gboolean is_eos;
|
|
|
|
|
|
|
|
bpad = GST_AGGREGATOR_PAD (pad);
|
2015-01-14 19:45:06 +00:00
|
|
|
GST_OBJECT_LOCK (bpad);
|
|
|
|
segment = bpad->segment;
|
|
|
|
GST_OBJECT_UNLOCK (bpad);
|
2015-01-26 10:25:54 +00:00
|
|
|
is_eos = gst_aggregator_pad_is_eos (bpad);
|
|
|
|
|
2014-10-06 07:33:52 +00:00
|
|
|
if (!is_eos)
|
|
|
|
eos = FALSE;
|
2018-01-23 09:01:00 +00:00
|
|
|
buf = gst_aggregator_pad_peek_buffer (bpad);
|
2014-06-03 17:00:34 +00:00
|
|
|
if (buf) {
|
|
|
|
GstClockTime start_time, end_time;
|
|
|
|
|
|
|
|
start_time = GST_BUFFER_TIMESTAMP (buf);
|
|
|
|
if (start_time == -1) {
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
GST_DEBUG_OBJECT (pad, "Need timestamped buffers!");
|
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Make all this work with negative rates */
|
2014-10-06 07:10:38 +00:00
|
|
|
end_time = GST_BUFFER_DURATION (buf);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2014-10-06 07:10:38 +00:00
|
|
|
if (end_time == -1) {
|
2015-02-08 13:59:30 +00:00
|
|
|
start_time = MAX (start_time, segment.start);
|
|
|
|
start_time =
|
|
|
|
gst_segment_to_running_time (&segment, GST_FORMAT_TIME, start_time);
|
|
|
|
|
2015-09-11 10:22:51 +00:00
|
|
|
if (start_time >= output_end_running_time) {
|
2018-05-05 13:49:17 +00:00
|
|
|
if (pad->priv->buffer) {
|
2015-03-24 13:34:26 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "buffer duration is -1, start_time >= "
|
2015-09-11 10:22:51 +00:00
|
|
|
"output_end_running_time. Keeping previous buffer");
|
2015-03-24 13:34:26 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (pad, "buffer duration is -1, start_time >= "
|
2016-05-14 09:56:59 +00:00
|
|
|
"output_end_running_time. No previous buffer.");
|
2015-03-24 13:34:26 +00:00
|
|
|
}
|
2015-02-08 13:59:30 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
continue;
|
2015-09-11 10:22:51 +00:00
|
|
|
} else if (start_time < output_start_running_time) {
|
2015-02-08 13:59:30 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "buffer duration is -1, start_time < "
|
2015-09-11 10:22:51 +00:00
|
|
|
"output_start_running_time. Discarding old buffer");
|
2018-05-05 13:49:17 +00:00
|
|
|
gst_buffer_replace (&pad->priv->buffer, buf);
|
2017-04-04 08:25:43 +00:00
|
|
|
if (pad->priv->pending_vinfo.finfo) {
|
|
|
|
pad->info = pad->priv->pending_vinfo;
|
|
|
|
need_reconfigure = TRUE;
|
|
|
|
pad->priv->pending_vinfo.finfo = NULL;
|
|
|
|
}
|
2015-02-08 13:59:30 +00:00
|
|
|
gst_buffer_unref (buf);
|
2015-02-13 16:03:53 +00:00
|
|
|
gst_aggregator_pad_drop_buffer (bpad);
|
2015-02-08 13:59:30 +00:00
|
|
|
need_more_data = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
2014-10-06 07:10:38 +00:00
|
|
|
gst_buffer_unref (buf);
|
2018-01-23 09:01:00 +00:00
|
|
|
buf = gst_aggregator_pad_pop_buffer (bpad);
|
2018-05-05 13:49:17 +00:00
|
|
|
gst_buffer_replace (&pad->priv->buffer, buf);
|
2017-04-04 08:25:43 +00:00
|
|
|
if (pad->priv->pending_vinfo.finfo) {
|
|
|
|
pad->info = pad->priv->pending_vinfo;
|
|
|
|
need_reconfigure = TRUE;
|
|
|
|
pad->priv->pending_vinfo.finfo = NULL;
|
|
|
|
}
|
2014-12-18 21:03:04 +00:00
|
|
|
/* FIXME: Set start_time and end_time to something here? */
|
2014-10-06 07:10:38 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
GST_DEBUG_OBJECT (pad, "buffer duration is -1");
|
|
|
|
continue;
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (start_time != -1 && end_time != -1);
|
|
|
|
end_time += start_time; /* convert from duration to position */
|
|
|
|
|
|
|
|
/* Check if it's inside the segment */
|
2015-01-14 19:45:06 +00:00
|
|
|
if (start_time >= segment.stop || end_time < segment.start) {
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_DEBUG_OBJECT (pad,
|
|
|
|
"Buffer outside the segment : segment: [%" GST_TIME_FORMAT " -- %"
|
|
|
|
GST_TIME_FORMAT "]" " Buffer [%" GST_TIME_FORMAT " -- %"
|
2015-01-14 19:45:06 +00:00
|
|
|
GST_TIME_FORMAT "]", GST_TIME_ARGS (segment.stop),
|
|
|
|
GST_TIME_ARGS (segment.start), GST_TIME_ARGS (start_time),
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_TIME_ARGS (end_time));
|
|
|
|
|
2014-10-06 07:10:38 +00:00
|
|
|
gst_buffer_unref (buf);
|
2015-02-13 16:03:53 +00:00
|
|
|
gst_aggregator_pad_drop_buffer (bpad);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
need_more_data = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clip to segment and convert to running time */
|
2015-01-14 19:45:06 +00:00
|
|
|
start_time = MAX (start_time, segment.start);
|
|
|
|
if (segment.stop != -1)
|
|
|
|
end_time = MIN (end_time, segment.stop);
|
2014-06-03 17:00:34 +00:00
|
|
|
start_time =
|
2015-01-14 19:45:06 +00:00
|
|
|
gst_segment_to_running_time (&segment, GST_FORMAT_TIME, start_time);
|
2014-06-03 17:00:34 +00:00
|
|
|
end_time =
|
2015-01-14 19:45:06 +00:00
|
|
|
gst_segment_to_running_time (&segment, GST_FORMAT_TIME, end_time);
|
2014-06-03 17:00:34 +00:00
|
|
|
g_assert (start_time != -1 && end_time != -1);
|
|
|
|
|
|
|
|
/* Convert to the output segment rate */
|
2018-02-28 23:34:40 +00:00
|
|
|
if (ABS (agg_segment->rate) != 1.0) {
|
|
|
|
start_time *= ABS (agg_segment->rate);
|
|
|
|
end_time *= ABS (agg_segment->rate);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 07:19:54 +00:00
|
|
|
GST_TRACE_OBJECT (pad, "dealing with buffer %p start %" GST_TIME_FORMAT
|
|
|
|
" end %" GST_TIME_FORMAT " out start %" GST_TIME_FORMAT
|
|
|
|
" out end %" GST_TIME_FORMAT, buf, GST_TIME_ARGS (start_time),
|
2015-09-11 10:22:51 +00:00
|
|
|
GST_TIME_ARGS (end_time), GST_TIME_ARGS (output_start_running_time),
|
|
|
|
GST_TIME_ARGS (output_end_running_time));
|
2014-12-05 07:19:54 +00:00
|
|
|
|
|
|
|
if (pad->priv->end_time != -1 && pad->priv->end_time > end_time) {
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "Buffer from the past, dropping");
|
2014-10-06 07:10:38 +00:00
|
|
|
gst_buffer_unref (buf);
|
2015-02-13 16:03:53 +00:00
|
|
|
gst_aggregator_pad_drop_buffer (bpad);
|
2014-06-03 17:00:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-09-11 10:22:51 +00:00
|
|
|
if (end_time >= output_start_running_time
|
|
|
|
&& start_time < output_end_running_time) {
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_DEBUG_OBJECT (pad,
|
|
|
|
"Taking new buffer with start time %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (start_time));
|
2018-05-05 13:49:17 +00:00
|
|
|
gst_buffer_replace (&pad->priv->buffer, buf);
|
2017-04-04 08:25:43 +00:00
|
|
|
if (pad->priv->pending_vinfo.finfo) {
|
|
|
|
pad->info = pad->priv->pending_vinfo;
|
|
|
|
need_reconfigure = TRUE;
|
|
|
|
pad->priv->pending_vinfo.finfo = NULL;
|
|
|
|
}
|
2014-11-27 19:48:24 +00:00
|
|
|
pad->priv->start_time = start_time;
|
|
|
|
pad->priv->end_time = end_time;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2014-10-06 07:10:38 +00:00
|
|
|
gst_buffer_unref (buf);
|
2015-02-13 16:03:53 +00:00
|
|
|
gst_aggregator_pad_drop_buffer (bpad);
|
2014-06-03 17:00:34 +00:00
|
|
|
eos = FALSE;
|
2015-09-11 10:22:51 +00:00
|
|
|
} else if (start_time >= output_end_running_time) {
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "Keeping buffer until %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (start_time));
|
2014-06-26 14:09:08 +00:00
|
|
|
gst_buffer_unref (buf);
|
2014-06-03 17:00:34 +00:00
|
|
|
eos = FALSE;
|
|
|
|
} else {
|
2018-05-05 13:49:17 +00:00
|
|
|
gst_buffer_replace (&pad->priv->buffer, buf);
|
2017-04-04 08:25:43 +00:00
|
|
|
if (pad->priv->pending_vinfo.finfo) {
|
|
|
|
pad->info = pad->priv->pending_vinfo;
|
|
|
|
need_reconfigure = TRUE;
|
|
|
|
pad->priv->pending_vinfo.finfo = NULL;
|
|
|
|
}
|
2014-12-18 21:03:04 +00:00
|
|
|
pad->priv->start_time = start_time;
|
|
|
|
pad->priv->end_time = end_time;
|
2014-10-06 07:10:38 +00:00
|
|
|
GST_DEBUG_OBJECT (pad,
|
2014-12-08 04:18:25 +00:00
|
|
|
"replacing old buffer with a newer buffer, start %" GST_TIME_FORMAT
|
|
|
|
" out end %" GST_TIME_FORMAT, GST_TIME_ARGS (start_time),
|
2015-09-11 10:22:51 +00:00
|
|
|
GST_TIME_ARGS (output_end_running_time));
|
2014-10-06 07:10:38 +00:00
|
|
|
gst_buffer_unref (buf);
|
2015-02-13 16:03:53 +00:00
|
|
|
gst_aggregator_pad_drop_buffer (bpad);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
need_more_data = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2018-05-04 15:18:12 +00:00
|
|
|
if (is_eos && pad->priv->repeat_after_eos) {
|
2015-02-09 19:19:35 +00:00
|
|
|
eos = FALSE;
|
|
|
|
GST_DEBUG_OBJECT (pad, "ignoring EOS and re-using previous buffer");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-12-05 07:19:54 +00:00
|
|
|
if (pad->priv->end_time != -1) {
|
2015-09-11 10:22:51 +00:00
|
|
|
if (pad->priv->end_time <= output_start_running_time) {
|
2014-11-27 19:48:24 +00:00
|
|
|
pad->priv->start_time = pad->priv->end_time = -1;
|
2017-04-10 23:18:51 +00:00
|
|
|
if (!is_eos) {
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_DEBUG ("I just need more data");
|
|
|
|
need_more_data = TRUE;
|
2017-04-10 23:18:51 +00:00
|
|
|
} else {
|
2018-05-05 13:49:17 +00:00
|
|
|
gst_buffer_replace (&pad->priv->buffer, NULL);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
} else if (is_eos) {
|
|
|
|
eos = FALSE;
|
|
|
|
}
|
2017-04-10 23:18:51 +00:00
|
|
|
} else if (is_eos) {
|
2018-05-05 13:49:17 +00:00
|
|
|
gst_buffer_replace (&pad->priv->buffer, NULL);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
|
|
|
|
2017-04-04 08:25:43 +00:00
|
|
|
if (need_reconfigure)
|
|
|
|
gst_pad_mark_reconfigure (GST_AGGREGATOR_SRC_PAD (vagg));
|
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
if (need_more_data)
|
2017-05-20 12:24:57 +00:00
|
|
|
return GST_AGGREGATOR_FLOW_NEED_DATA;
|
2014-06-03 17:00:34 +00:00
|
|
|
if (eos)
|
|
|
|
return GST_FLOW_EOS;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2017-11-02 12:46:26 +00:00
|
|
|
sync_pad_values (GstElement * vagg, GstPad * pad, gpointer user_data)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
2017-11-02 12:46:26 +00:00
|
|
|
GstVideoAggregatorPad *vpad = GST_VIDEO_AGGREGATOR_PAD (pad);
|
|
|
|
GstAggregatorPad *bpad = GST_AGGREGATOR_PAD_CAST (pad);
|
2015-01-20 14:23:09 +00:00
|
|
|
GstClockTime timestamp;
|
|
|
|
gint64 stream_time;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2018-05-05 13:49:17 +00:00
|
|
|
if (vpad->priv->buffer == NULL)
|
2015-01-20 14:23:09 +00:00
|
|
|
return TRUE;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2018-05-05 13:49:17 +00:00
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (vpad->priv->buffer);
|
2015-01-20 14:23:09 +00:00
|
|
|
GST_OBJECT_LOCK (bpad);
|
|
|
|
stream_time = gst_segment_to_stream_time (&bpad->segment, GST_FORMAT_TIME,
|
|
|
|
timestamp);
|
|
|
|
GST_OBJECT_UNLOCK (bpad);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2015-01-20 14:23:09 +00:00
|
|
|
/* sync object properties on stream time */
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (stream_time))
|
2017-11-02 12:46:26 +00:00
|
|
|
gst_object_sync_values (GST_OBJECT_CAST (pad), stream_time);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2015-01-20 14:23:09 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2015-01-20 14:23:09 +00:00
|
|
|
static gboolean
|
2017-11-02 12:46:26 +00:00
|
|
|
prepare_frames (GstElement * agg, GstPad * pad, gpointer user_data)
|
2015-01-20 14:23:09 +00:00
|
|
|
{
|
2017-11-02 12:46:26 +00:00
|
|
|
GstVideoAggregatorPad *vpad = GST_VIDEO_AGGREGATOR_PAD_CAST (pad);
|
2015-01-20 14:23:09 +00:00
|
|
|
GstVideoAggregatorPadClass *vaggpad_class =
|
|
|
|
GST_VIDEO_AGGREGATOR_PAD_GET_CLASS (pad);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2018-05-05 13:49:17 +00:00
|
|
|
memset (&vpad->priv->prepared_frame, 0, sizeof (GstVideoFrame));
|
|
|
|
|
|
|
|
if (vpad->priv->buffer == NULL || !vaggpad_class->prepare_frame)
|
2015-01-20 14:23:09 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2018-05-05 13:49:17 +00:00
|
|
|
return vaggpad_class->prepare_frame (vpad, GST_VIDEO_AGGREGATOR_CAST (agg),
|
|
|
|
vpad->priv->buffer, &vpad->priv->prepared_frame);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2017-11-02 12:46:26 +00:00
|
|
|
clean_pad (GstElement * agg, GstPad * pad, gpointer user_data)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
2017-11-02 12:46:26 +00:00
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR_CAST (agg);
|
|
|
|
GstVideoAggregatorPad *vpad = GST_VIDEO_AGGREGATOR_PAD_CAST (pad);
|
2014-11-26 17:24:05 +00:00
|
|
|
GstVideoAggregatorPadClass *vaggpad_class =
|
|
|
|
GST_VIDEO_AGGREGATOR_PAD_GET_CLASS (pad);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2017-11-06 20:07:51 +00:00
|
|
|
if (vaggpad_class->clean_frame)
|
2018-05-05 13:49:17 +00:00
|
|
|
vaggpad_class->clean_frame (vpad, vagg, &vpad->priv->prepared_frame);
|
|
|
|
|
|
|
|
memset (&vpad->priv->prepared_frame, 0, sizeof (GstVideoFrame));
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_do_aggregate (GstVideoAggregator * vagg,
|
2014-06-03 17:00:34 +00:00
|
|
|
GstClockTime output_start_time, GstClockTime output_end_time,
|
|
|
|
GstBuffer ** outbuf)
|
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
GstElementClass *klass = GST_ELEMENT_GET_CLASS (vagg);
|
|
|
|
GstVideoAggregatorClass *vagg_klass = (GstVideoAggregatorClass *) klass;
|
|
|
|
|
|
|
|
g_assert (vagg_klass->aggregate_frames != NULL);
|
2018-05-06 14:05:28 +00:00
|
|
|
g_assert (vagg_klass->create_output_buffer != NULL);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2018-05-06 14:05:28 +00:00
|
|
|
if ((ret = vagg_klass->create_output_buffer (vagg, outbuf)) != GST_FLOW_OK) {
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_WARNING_OBJECT (vagg, "Could not get an output buffer, reason: %s",
|
|
|
|
gst_flow_get_name (ret));
|
|
|
|
return ret;
|
|
|
|
}
|
2015-05-04 08:17:21 +00:00
|
|
|
if (*outbuf == NULL) {
|
|
|
|
/* sub-class doesn't want to generate output right now */
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (*outbuf) = output_start_time;
|
|
|
|
GST_BUFFER_DURATION (*outbuf) = output_end_time - output_start_time;
|
|
|
|
|
2015-01-20 14:23:09 +00:00
|
|
|
/* Sync pad properties to the stream time */
|
2017-11-02 12:46:26 +00:00
|
|
|
gst_element_foreach_sink_pad (GST_ELEMENT_CAST (vagg), sync_pad_values, NULL);
|
2015-01-20 14:23:09 +00:00
|
|
|
|
|
|
|
/* Convert all the frames the subclass has before aggregating */
|
2017-11-02 12:46:26 +00:00
|
|
|
gst_element_foreach_sink_pad (GST_ELEMENT_CAST (vagg), prepare_frames, NULL);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
ret = vagg_klass->aggregate_frames (vagg, *outbuf);
|
|
|
|
|
2017-11-06 20:07:51 +00:00
|
|
|
gst_element_foreach_sink_pad (GST_ELEMENT_CAST (vagg), clean_pad, NULL);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform qos calculations before processing the next frame. Returns TRUE if
|
|
|
|
* the frame should be processed, FALSE if the frame can be dropped entirely */
|
|
|
|
static gint64
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_do_qos (GstVideoAggregator * vagg, GstClockTime timestamp)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GstAggregator *agg = GST_AGGREGATOR (vagg);
|
|
|
|
GstClockTime qostime, earliest_time;
|
|
|
|
gdouble proportion;
|
|
|
|
gint64 jitter;
|
|
|
|
|
|
|
|
/* no timestamp, can't do QoS => process frame */
|
|
|
|
if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (timestamp))) {
|
|
|
|
GST_LOG_OBJECT (vagg, "invalid timestamp, can't do QoS, process frame");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get latest QoS observation values */
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_read_qos (vagg, &proportion, &earliest_time);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
/* skip qos if we have no observation (yet) => process frame */
|
|
|
|
if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (earliest_time))) {
|
|
|
|
GST_LOG_OBJECT (vagg, "no observation yet, process frame");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* qos is done on running time */
|
|
|
|
qostime =
|
2018-02-28 23:34:40 +00:00
|
|
|
gst_segment_to_running_time (&GST_AGGREGATOR_PAD (agg->srcpad)->segment,
|
|
|
|
GST_FORMAT_TIME, timestamp);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
/* see how our next timestamp relates to the latest qos timestamp */
|
|
|
|
GST_LOG_OBJECT (vagg, "qostime %" GST_TIME_FORMAT ", earliest %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (qostime), GST_TIME_ARGS (earliest_time));
|
|
|
|
|
|
|
|
jitter = GST_CLOCK_DIFF (qostime, earliest_time);
|
|
|
|
if (qostime != GST_CLOCK_TIME_NONE && jitter > 0) {
|
|
|
|
GST_DEBUG_OBJECT (vagg, "we are late, drop frame");
|
|
|
|
return jitter;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (vagg, "process frame");
|
|
|
|
return jitter;
|
|
|
|
}
|
|
|
|
|
2014-12-05 07:19:54 +00:00
|
|
|
static GstClockTime
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_get_next_time (GstAggregator * agg)
|
2014-12-05 07:19:54 +00:00
|
|
|
{
|
2015-09-11 10:22:51 +00:00
|
|
|
GstClockTime next_time;
|
2018-02-28 23:34:40 +00:00
|
|
|
GstSegment *agg_segment = &GST_AGGREGATOR_PAD (agg->srcpad)->segment;
|
2015-09-11 10:22:51 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (agg);
|
2018-02-28 23:34:40 +00:00
|
|
|
if (agg_segment->position == -1 || agg_segment->position < agg_segment->start)
|
|
|
|
next_time = agg_segment->start;
|
2014-12-05 07:19:54 +00:00
|
|
|
else
|
2018-02-28 23:34:40 +00:00
|
|
|
next_time = agg_segment->position;
|
2015-09-11 10:22:51 +00:00
|
|
|
|
2018-02-28 23:34:40 +00:00
|
|
|
if (agg_segment->stop != -1 && next_time > agg_segment->stop)
|
|
|
|
next_time = agg_segment->stop;
|
2015-09-11 10:22:51 +00:00
|
|
|
|
|
|
|
next_time =
|
2018-02-28 23:34:40 +00:00
|
|
|
gst_segment_to_running_time (agg_segment, GST_FORMAT_TIME, next_time);
|
2015-09-11 10:22:51 +00:00
|
|
|
GST_OBJECT_UNLOCK (agg);
|
|
|
|
|
|
|
|
return next_time;
|
2014-12-05 07:19:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
static void
|
|
|
|
gst_video_aggregator_advance_on_timeout (GstVideoAggregator * vagg)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
2017-05-20 12:24:57 +00:00
|
|
|
GstAggregator *agg = GST_AGGREGATOR (vagg);
|
|
|
|
guint64 frame_duration;
|
|
|
|
gint fps_d, fps_n;
|
2018-02-28 23:34:40 +00:00
|
|
|
GstSegment *agg_segment = &GST_AGGREGATOR_PAD (agg->srcpad)->segment;
|
2015-01-28 20:58:38 +00:00
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
GST_OBJECT_LOCK (agg);
|
2018-02-28 23:34:40 +00:00
|
|
|
if (agg_segment->position == -1) {
|
|
|
|
if (agg_segment->rate > 0.0)
|
|
|
|
agg_segment->position = agg_segment->start;
|
2017-05-20 12:24:57 +00:00
|
|
|
else
|
2018-02-28 23:34:40 +00:00
|
|
|
agg_segment->position = agg_segment->stop;
|
2014-11-27 18:52:20 +00:00
|
|
|
}
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
/* Advance position */
|
|
|
|
fps_d = GST_VIDEO_INFO_FPS_D (&vagg->info) ?
|
|
|
|
GST_VIDEO_INFO_FPS_D (&vagg->info) : 1;
|
|
|
|
fps_n = GST_VIDEO_INFO_FPS_N (&vagg->info) ?
|
|
|
|
GST_VIDEO_INFO_FPS_N (&vagg->info) : 25;
|
|
|
|
/* Default to 25/1 if no "best fps" is known */
|
|
|
|
frame_duration = gst_util_uint64_scale (GST_SECOND, fps_d, fps_n);
|
2018-02-28 23:34:40 +00:00
|
|
|
if (agg_segment->rate > 0.0)
|
|
|
|
agg_segment->position += frame_duration;
|
|
|
|
else if (agg_segment->position > frame_duration)
|
|
|
|
agg_segment->position -= frame_duration;
|
2017-05-20 12:24:57 +00:00
|
|
|
else
|
2018-02-28 23:34:40 +00:00
|
|
|
agg_segment->position = 0;
|
2017-05-20 12:24:57 +00:00
|
|
|
vagg->priv->nframes++;
|
|
|
|
GST_OBJECT_UNLOCK (agg);
|
2015-05-06 17:19:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_aggregate (GstAggregator * agg, gboolean timeout)
|
2015-05-06 17:19:36 +00:00
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (agg);
|
|
|
|
GstClockTime output_start_time, output_end_time;
|
2015-09-11 10:22:51 +00:00
|
|
|
GstClockTime output_start_running_time, output_end_running_time;
|
2015-05-06 17:19:36 +00:00
|
|
|
GstBuffer *outbuf = NULL;
|
|
|
|
GstFlowReturn flow_ret;
|
|
|
|
gint64 jitter;
|
2018-02-28 23:34:40 +00:00
|
|
|
GstSegment *agg_segment = &GST_AGGREGATOR_PAD (agg->srcpad)->segment;
|
2015-05-06 17:19:36 +00:00
|
|
|
|
|
|
|
GST_VIDEO_AGGREGATOR_LOCK (vagg);
|
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
if (GST_VIDEO_INFO_FORMAT (&vagg->info) == GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
if (timeout)
|
|
|
|
gst_video_aggregator_advance_on_timeout (vagg);
|
|
|
|
flow_ret = GST_AGGREGATOR_FLOW_NEED_DATA;
|
2015-05-06 17:29:01 +00:00
|
|
|
goto unlock_and_return;
|
2015-05-06 17:19:36 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 23:34:40 +00:00
|
|
|
output_start_time = agg_segment->position;
|
|
|
|
if (agg_segment->position == -1 || agg_segment->position < agg_segment->start)
|
|
|
|
output_start_time = agg_segment->start;
|
2015-09-11 10:22:51 +00:00
|
|
|
|
2015-06-15 16:30:20 +00:00
|
|
|
if (vagg->priv->nframes == 0) {
|
|
|
|
vagg->priv->ts_offset = output_start_time;
|
|
|
|
GST_DEBUG_OBJECT (vagg, "New ts offset %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (output_start_time));
|
|
|
|
}
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2015-09-11 10:22:51 +00:00
|
|
|
if (GST_VIDEO_INFO_FPS_N (&vagg->info) == 0) {
|
2014-12-05 07:19:54 +00:00
|
|
|
output_end_time = -1;
|
2015-09-11 10:22:51 +00:00
|
|
|
} else {
|
2014-12-05 07:19:54 +00:00
|
|
|
output_end_time =
|
|
|
|
vagg->priv->ts_offset +
|
|
|
|
gst_util_uint64_scale_round (vagg->priv->nframes + 1,
|
|
|
|
GST_SECOND * GST_VIDEO_INFO_FPS_D (&vagg->info),
|
2015-06-15 16:30:20 +00:00
|
|
|
GST_VIDEO_INFO_FPS_N (&vagg->info));
|
2015-09-11 10:22:51 +00:00
|
|
|
}
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2018-02-28 23:34:40 +00:00
|
|
|
if (agg_segment->stop != -1)
|
|
|
|
output_end_time = MIN (output_end_time, agg_segment->stop);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2015-09-11 10:22:51 +00:00
|
|
|
output_start_running_time =
|
2018-02-28 23:34:40 +00:00
|
|
|
gst_segment_to_running_time (agg_segment, GST_FORMAT_TIME,
|
2015-09-11 10:22:51 +00:00
|
|
|
output_start_time);
|
|
|
|
output_end_running_time =
|
2018-02-28 23:34:40 +00:00
|
|
|
gst_segment_to_running_time (agg_segment, GST_FORMAT_TIME,
|
2015-09-11 10:22:51 +00:00
|
|
|
output_end_time);
|
|
|
|
|
2014-11-19 16:02:40 +00:00
|
|
|
if (output_end_time == output_start_time) {
|
2015-05-06 16:59:51 +00:00
|
|
|
flow_ret = GST_FLOW_EOS;
|
2014-11-19 16:02:40 +00:00
|
|
|
} else {
|
2015-05-06 16:59:51 +00:00
|
|
|
flow_ret =
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_fill_queues (vagg, output_start_running_time,
|
2015-09-11 10:22:51 +00:00
|
|
|
output_end_running_time);
|
2014-11-19 16:02:40 +00:00
|
|
|
}
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2017-05-20 12:24:57 +00:00
|
|
|
if (flow_ret == GST_AGGREGATOR_FLOW_NEED_DATA && !timeout) {
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_DEBUG_OBJECT (vagg, "Need more data for decisions");
|
2015-05-06 17:29:01 +00:00
|
|
|
goto unlock_and_return;
|
2015-05-06 16:59:51 +00:00
|
|
|
} else if (flow_ret == GST_FLOW_EOS) {
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_DEBUG_OBJECT (vagg, "All sinkpads are EOS -- forwarding");
|
2015-05-06 17:29:01 +00:00
|
|
|
goto unlock_and_return;
|
2015-05-06 16:59:51 +00:00
|
|
|
} else if (flow_ret == GST_FLOW_ERROR) {
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_WARNING_OBJECT (vagg, "Error collecting buffers");
|
2015-05-06 17:29:01 +00:00
|
|
|
goto unlock_and_return;
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
2017-04-04 08:25:43 +00:00
|
|
|
/* It is possible that gst_video_aggregator_fill_queues() marked the pad
|
|
|
|
* for reconfiguration. In this case we have to reconfigure before continuing
|
|
|
|
* because we have picked a new buffer with different caps than before from
|
|
|
|
* one one of the sink pads and continuing here may lead to a crash.
|
|
|
|
* https://bugzilla.gnome.org/show_bug.cgi?id=780682
|
|
|
|
*/
|
|
|
|
if (gst_pad_needs_reconfigure (GST_AGGREGATOR_SRC_PAD (vagg))) {
|
|
|
|
GST_DEBUG_OBJECT (vagg, "Need reconfigure");
|
2017-05-21 10:41:53 +00:00
|
|
|
flow_ret = GST_AGGREGATOR_FLOW_NEED_DATA;
|
|
|
|
goto unlock_and_return;
|
2017-04-04 08:25:43 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 12:25:43 +00:00
|
|
|
GST_DEBUG_OBJECT (vagg,
|
2015-09-11 10:22:51 +00:00
|
|
|
"Producing buffer for %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT
|
|
|
|
", running time start %" GST_TIME_FORMAT ", running time end %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (output_start_time),
|
|
|
|
GST_TIME_ARGS (output_end_time),
|
|
|
|
GST_TIME_ARGS (output_start_running_time),
|
|
|
|
GST_TIME_ARGS (output_end_running_time));
|
2015-06-15 12:25:43 +00:00
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
jitter = gst_video_aggregator_do_qos (vagg, output_start_time);
|
2014-06-03 17:00:34 +00:00
|
|
|
if (jitter <= 0) {
|
2016-05-16 11:27:50 +00:00
|
|
|
flow_ret = gst_video_aggregator_do_aggregate (vagg, output_start_time,
|
2014-06-03 17:00:34 +00:00
|
|
|
output_end_time, &outbuf);
|
2015-05-06 16:59:51 +00:00
|
|
|
if (flow_ret != GST_FLOW_OK)
|
2015-05-04 08:17:21 +00:00
|
|
|
goto done;
|
2014-06-03 17:00:34 +00:00
|
|
|
vagg->priv->qos_processed++;
|
|
|
|
} else {
|
|
|
|
GstMessage *msg;
|
|
|
|
|
|
|
|
vagg->priv->qos_dropped++;
|
|
|
|
|
|
|
|
msg =
|
2015-06-15 12:18:39 +00:00
|
|
|
gst_message_new_qos (GST_OBJECT_CAST (vagg), vagg->priv->live,
|
2018-02-28 23:34:40 +00:00
|
|
|
output_start_running_time, gst_segment_to_stream_time (agg_segment,
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_FORMAT_TIME, output_start_time), output_start_time,
|
|
|
|
output_end_time - output_start_time);
|
|
|
|
gst_message_set_qos_values (msg, jitter, vagg->priv->proportion, 1000000);
|
|
|
|
gst_message_set_qos_stats (msg, GST_FORMAT_BUFFERS,
|
|
|
|
vagg->priv->qos_processed, vagg->priv->qos_dropped);
|
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (vagg), msg);
|
|
|
|
|
2015-05-06 16:59:51 +00:00
|
|
|
flow_ret = GST_FLOW_OK;
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_VIDEO_AGGREGATOR_UNLOCK (vagg);
|
|
|
|
if (outbuf) {
|
|
|
|
GST_DEBUG_OBJECT (vagg,
|
|
|
|
"Pushing buffer with ts %" GST_TIME_FORMAT " and duration %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)));
|
|
|
|
|
2015-05-06 16:59:51 +00:00
|
|
|
flow_ret = gst_aggregator_finish_buffer (agg, outbuf);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
2015-09-11 10:22:51 +00:00
|
|
|
|
|
|
|
GST_VIDEO_AGGREGATOR_LOCK (vagg);
|
|
|
|
vagg->priv->nframes++;
|
2018-02-28 23:34:40 +00:00
|
|
|
agg_segment->position = output_end_time;
|
2015-09-11 10:22:51 +00:00
|
|
|
GST_VIDEO_AGGREGATOR_UNLOCK (vagg);
|
|
|
|
|
2015-05-06 17:29:01 +00:00
|
|
|
return flow_ret;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
done:
|
2015-05-04 08:17:21 +00:00
|
|
|
if (outbuf)
|
|
|
|
gst_buffer_unref (outbuf);
|
2015-05-06 17:29:01 +00:00
|
|
|
unlock_and_return:
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_VIDEO_AGGREGATOR_UNLOCK (vagg);
|
2015-05-06 16:59:51 +00:00
|
|
|
return flow_ret;
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME, the duration query should reflect how long you will produce
|
|
|
|
* data, that is the amount of stream time until you will emit EOS.
|
|
|
|
*
|
|
|
|
* For synchronized aggregating this is always the max of all the durations
|
|
|
|
* of upstream since we emit EOS when all of them finished.
|
|
|
|
*
|
|
|
|
* We don't do synchronized aggregating so this really depends on where the
|
|
|
|
* streams where punched in and what their relative offsets are against
|
|
|
|
* each other which we can get from the first timestamps we see.
|
|
|
|
*
|
|
|
|
* When we add a new stream (or remove a stream) the duration might
|
|
|
|
* also become invalid again and we need to post a new DURATION
|
|
|
|
* message to notify this fact to the parent.
|
|
|
|
* For now we take the max of all the upstream elements so the simple
|
|
|
|
* cases work at least somewhat.
|
|
|
|
*/
|
|
|
|
static gboolean
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_query_duration (GstVideoAggregator * vagg,
|
|
|
|
GstQuery * query)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GValue item = { 0 };
|
|
|
|
gint64 max;
|
|
|
|
gboolean res;
|
|
|
|
GstFormat format;
|
|
|
|
GstIterator *it;
|
|
|
|
gboolean done;
|
|
|
|
|
|
|
|
/* parse format */
|
|
|
|
gst_query_parse_duration (query, &format, NULL);
|
|
|
|
|
|
|
|
max = -1;
|
|
|
|
res = TRUE;
|
|
|
|
done = FALSE;
|
|
|
|
|
|
|
|
/* Take maximum of all durations */
|
|
|
|
it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (vagg));
|
|
|
|
while (!done) {
|
|
|
|
switch (gst_iterator_next (it, &item)) {
|
|
|
|
case GST_ITERATOR_DONE:
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_OK:
|
|
|
|
{
|
|
|
|
GstPad *pad;
|
|
|
|
gint64 duration;
|
|
|
|
|
|
|
|
pad = g_value_get_object (&item);
|
|
|
|
|
|
|
|
/* ask sink peer for duration */
|
|
|
|
res &= gst_pad_peer_query_duration (pad, format, &duration);
|
|
|
|
/* take max from all valid return values */
|
|
|
|
if (res) {
|
|
|
|
/* valid unknown length, stop searching */
|
|
|
|
if (duration == -1) {
|
|
|
|
max = duration;
|
|
|
|
done = TRUE;
|
|
|
|
}
|
|
|
|
/* else see if bigger than current max */
|
|
|
|
else if (duration > max)
|
|
|
|
max = duration;
|
|
|
|
}
|
|
|
|
g_value_reset (&item);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_ITERATOR_RESYNC:
|
|
|
|
max = -1;
|
|
|
|
res = TRUE;
|
|
|
|
gst_iterator_resync (it);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_value_unset (&item);
|
|
|
|
gst_iterator_free (it);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
/* and store the max */
|
|
|
|
GST_DEBUG_OBJECT (vagg, "Total duration in format %s: %"
|
|
|
|
GST_TIME_FORMAT, gst_format_get_name (format), GST_TIME_ARGS (max));
|
|
|
|
gst_query_set_duration (query, format, max);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_src_query (GstAggregator * agg, GstQuery * query)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (agg);
|
|
|
|
gboolean res = FALSE;
|
2018-02-28 23:34:40 +00:00
|
|
|
GstSegment *agg_segment = &GST_AGGREGATOR_PAD (agg->srcpad)->segment;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_POSITION:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
gst_query_parse_position (query, &format, NULL);
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
gst_query_set_position (query, format,
|
2018-02-28 23:34:40 +00:00
|
|
|
gst_segment_to_stream_time (agg_segment, GST_FORMAT_TIME,
|
|
|
|
agg_segment->position));
|
2014-06-03 17:00:34 +00:00
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_DURATION:
|
2016-05-16 11:27:50 +00:00
|
|
|
res = gst_video_aggregator_query_duration (vagg, query);
|
2014-06-03 17:00:34 +00:00
|
|
|
break;
|
2015-06-15 12:18:39 +00:00
|
|
|
case GST_QUERY_LATENCY:
|
|
|
|
res =
|
2016-05-16 11:27:50 +00:00
|
|
|
GST_AGGREGATOR_CLASS (gst_video_aggregator_parent_class)->src_query
|
2015-06-15 12:18:39 +00:00
|
|
|
(agg, query);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
gst_query_parse_latency (query, &vagg->priv->live, NULL, NULL);
|
|
|
|
}
|
|
|
|
break;
|
2014-12-22 21:11:30 +00:00
|
|
|
default:
|
2014-06-03 17:00:34 +00:00
|
|
|
res =
|
2016-05-16 11:27:50 +00:00
|
|
|
GST_AGGREGATOR_CLASS (gst_video_aggregator_parent_class)->src_query
|
2014-06-03 17:00:34 +00:00
|
|
|
(agg, query);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_src_event (GstAggregator * agg, GstEvent * event)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (agg);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_QOS:
|
|
|
|
{
|
|
|
|
GstQOSType type;
|
|
|
|
GstClockTimeDiff diff;
|
|
|
|
GstClockTime timestamp;
|
|
|
|
gdouble proportion;
|
|
|
|
|
|
|
|
gst_event_parse_qos (event, &type, &proportion, &diff, ×tamp);
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_update_qos (vagg, proportion, diff, timestamp);
|
2014-06-03 17:00:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (vagg, "Handling SEEK event");
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2016-05-16 11:27:50 +00:00
|
|
|
GST_AGGREGATOR_CLASS (gst_video_aggregator_parent_class)->src_event (agg,
|
2014-06-03 17:00:34 +00:00
|
|
|
event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_flush (GstAggregator * agg)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
gdouble abs_rate;
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (agg);
|
2018-02-28 23:34:40 +00:00
|
|
|
GstSegment *agg_segment = &GST_AGGREGATOR_PAD (agg->srcpad)->segment;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
GST_INFO_OBJECT (agg, "Flushing");
|
|
|
|
GST_OBJECT_LOCK (vagg);
|
2018-02-28 23:34:40 +00:00
|
|
|
abs_rate = ABS (agg_segment->rate);
|
2014-06-03 17:00:34 +00:00
|
|
|
for (l = GST_ELEMENT (vagg)->sinkpads; l; l = l->next) {
|
|
|
|
GstVideoAggregatorPad *p = l->data;
|
|
|
|
|
|
|
|
/* Convert to the output segment rate */
|
2018-02-28 23:34:40 +00:00
|
|
|
if (ABS (agg_segment->rate) != abs_rate) {
|
2018-05-05 13:49:17 +00:00
|
|
|
if (ABS (agg_segment->rate) != 1.0 && p->priv->buffer) {
|
2018-02-28 23:34:40 +00:00
|
|
|
p->priv->start_time /= ABS (agg_segment->rate);
|
|
|
|
p->priv->end_time /= ABS (agg_segment->rate);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
2018-05-05 13:49:17 +00:00
|
|
|
if (abs_rate != 1.0 && p->priv->buffer) {
|
2014-11-27 19:48:24 +00:00
|
|
|
p->priv->start_time *= abs_rate;
|
|
|
|
p->priv->end_time *= abs_rate;
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
|
|
|
|
2018-02-28 23:34:40 +00:00
|
|
|
agg_segment->position = -1;
|
2014-06-03 17:00:34 +00:00
|
|
|
vagg->priv->ts_offset = 0;
|
|
|
|
vagg->priv->nframes = 0;
|
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_reset_qos (vagg);
|
2014-06-03 17:00:34 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_sink_event (GstAggregator * agg, GstAggregatorPad * bpad,
|
2014-06-03 17:00:34 +00:00
|
|
|
GstEvent * event)
|
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (agg);
|
|
|
|
GstVideoAggregatorPad *pad = GST_VIDEO_AGGREGATOR_PAD (bpad);
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "Got %s event on pad %s:%s",
|
|
|
|
GST_EVENT_TYPE_NAME (event), GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
ret =
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_pad_sink_setcaps (GST_PAD (pad),
|
2014-06-03 17:00:34 +00:00
|
|
|
GST_OBJECT (vagg), caps);
|
|
|
|
gst_event_unref (event);
|
|
|
|
event = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_SEGMENT:{
|
|
|
|
GstSegment seg;
|
|
|
|
gst_event_copy_segment (event, &seg);
|
|
|
|
|
|
|
|
g_assert (seg.format == GST_FORMAT_TIME);
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_reset_qos (vagg);
|
2014-06-03 17:00:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event != NULL)
|
2016-05-16 11:27:50 +00:00
|
|
|
return GST_AGGREGATOR_CLASS (gst_video_aggregator_parent_class)->sink_event
|
2014-06-03 17:00:34 +00:00
|
|
|
(agg, bpad, event);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_start (GstAggregator * agg)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (agg);
|
|
|
|
|
|
|
|
gst_caps_replace (&vagg->priv->current_caps, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_stop (GstAggregator * agg)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (agg);
|
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_reset (vagg);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GstElement vmethods */
|
|
|
|
static GstPad *
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_request_new_pad (GstElement * element,
|
2014-06-03 17:00:34 +00:00
|
|
|
GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg;
|
|
|
|
GstVideoAggregatorPad *vaggpad;
|
|
|
|
|
|
|
|
vagg = GST_VIDEO_AGGREGATOR (element);
|
|
|
|
|
|
|
|
vaggpad = (GstVideoAggregatorPad *)
|
2016-05-16 11:27:50 +00:00
|
|
|
GST_ELEMENT_CLASS (gst_video_aggregator_parent_class)->request_new_pad
|
2014-06-03 17:00:34 +00:00
|
|
|
(element, templ, req_name, caps);
|
|
|
|
|
|
|
|
if (vaggpad == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (vagg);
|
2018-05-04 15:18:12 +00:00
|
|
|
vaggpad->priv->zorder = GST_ELEMENT (vagg)->numsinkpads;
|
2014-11-27 19:48:24 +00:00
|
|
|
vaggpad->priv->start_time = -1;
|
|
|
|
vaggpad->priv->end_time = -1;
|
2014-06-03 17:00:34 +00:00
|
|
|
element->sinkpads = g_list_sort (element->sinkpads,
|
|
|
|
(GCompareFunc) pad_zorder_compare);
|
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
|
|
|
|
|
|
|
return GST_PAD (vaggpad);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_release_pad (GstElement * element, GstPad * pad)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg = NULL;
|
|
|
|
GstVideoAggregatorPad *vaggpad;
|
2014-11-27 18:52:20 +00:00
|
|
|
gboolean last_pad;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
vagg = GST_VIDEO_AGGREGATOR (element);
|
|
|
|
vaggpad = GST_VIDEO_AGGREGATOR_PAD (pad);
|
|
|
|
|
|
|
|
GST_VIDEO_AGGREGATOR_LOCK (vagg);
|
2014-10-31 10:01:47 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (vagg);
|
|
|
|
last_pad = (GST_ELEMENT (vagg)->numsinkpads - 1 == 0);
|
|
|
|
GST_OBJECT_UNLOCK (vagg);
|
|
|
|
|
2014-11-27 18:52:20 +00:00
|
|
|
if (last_pad)
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_reset (vagg);
|
2014-10-31 10:01:47 +00:00
|
|
|
|
2018-05-05 13:49:17 +00:00
|
|
|
gst_buffer_replace (&vaggpad->priv->buffer, NULL);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
GST_ELEMENT_CLASS (gst_video_aggregator_parent_class)->release_pad
|
|
|
|
(GST_ELEMENT (vagg), pad);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2015-05-06 16:08:11 +00:00
|
|
|
gst_pad_mark_reconfigure (GST_AGGREGATOR_SRC_PAD (vagg));
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2014-09-18 15:14:22 +00:00
|
|
|
GST_VIDEO_AGGREGATOR_UNLOCK (vagg);
|
2014-06-03 17:00:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-21 13:44:02 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_aggregator_propose_allocation (GstAggregator * agg,
|
|
|
|
GstAggregatorPad * pad, GstQuery * decide_query, GstQuery * query)
|
|
|
|
{
|
|
|
|
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:25:16 +00:00
|
|
|
static gboolean
|
2017-05-20 16:10:29 +00:00
|
|
|
gst_video_aggregator_decide_allocation (GstAggregator * agg, GstQuery * query)
|
2017-05-20 15:25:16 +00:00
|
|
|
{
|
2017-05-20 16:10:29 +00:00
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (agg);
|
2017-05-20 15:25:16 +00:00
|
|
|
GstAllocationParams params = { 0, 15, 0, 0 };
|
|
|
|
guint i;
|
2017-05-20 16:10:29 +00:00
|
|
|
GstBufferPool *pool;
|
2018-05-06 13:49:36 +00:00
|
|
|
GstAllocator *allocator;
|
2017-05-20 16:10:29 +00:00
|
|
|
guint size, min, max;
|
|
|
|
gboolean update = FALSE;
|
|
|
|
GstStructure *config = NULL;
|
|
|
|
GstCaps *caps = NULL;
|
2017-05-20 15:25:16 +00:00
|
|
|
|
2018-05-06 13:49:36 +00:00
|
|
|
if (gst_query_get_n_allocation_params (query) == 0) {
|
2017-05-20 15:25:16 +00:00
|
|
|
gst_query_add_allocation_param (query, NULL, ¶ms);
|
2018-05-06 13:49:36 +00:00
|
|
|
} else {
|
2017-05-20 15:25:16 +00:00
|
|
|
for (i = 0; i < gst_query_get_n_allocation_params (query); i++) {
|
|
|
|
GstAllocator *allocator;
|
|
|
|
|
|
|
|
gst_query_parse_nth_allocation_param (query, i, &allocator, ¶ms);
|
|
|
|
params.align = MAX (params.align, 15);
|
|
|
|
gst_query_set_nth_allocation_param (query, i, allocator, ¶ms);
|
|
|
|
}
|
2018-05-06 13:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
|
2017-05-20 15:25:16 +00:00
|
|
|
|
2017-05-20 16:10:29 +00:00
|
|
|
if (gst_query_get_n_allocation_pools (query) > 0) {
|
|
|
|
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
|
|
|
|
|
|
|
|
/* adjust size */
|
|
|
|
size = MAX (size, vagg->info.size);
|
|
|
|
update = TRUE;
|
|
|
|
} else {
|
|
|
|
pool = NULL;
|
|
|
|
size = vagg->info.size;
|
|
|
|
min = max = 0;
|
|
|
|
update = FALSE;
|
|
|
|
}
|
|
|
|
|
2018-05-06 13:49:36 +00:00
|
|
|
gst_query_parse_allocation (query, &caps, NULL);
|
|
|
|
|
2017-05-20 16:10:29 +00:00
|
|
|
/* no downstream pool, make our own */
|
|
|
|
if (pool == NULL)
|
|
|
|
pool = gst_video_buffer_pool_new ();
|
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
|
2018-05-06 13:49:36 +00:00
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, min, max);
|
|
|
|
gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
|
|
|
|
|
|
|
|
/* buffer pool may have to do some changes */
|
|
|
|
if (!gst_buffer_pool_set_config (pool, config)) {
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
|
|
|
|
/* If change are not acceptable, fallback to generic pool */
|
|
|
|
if (!gst_buffer_pool_config_validate_params (config, caps, size, min, max)) {
|
|
|
|
GST_DEBUG_OBJECT (agg, "unsupported pool, making new pool");
|
|
|
|
|
|
|
|
gst_object_unref (pool);
|
|
|
|
pool = gst_video_buffer_pool_new ();
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, min, max);
|
|
|
|
gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_set_config (pool, config))
|
|
|
|
goto config_failed;
|
|
|
|
}
|
2017-05-20 16:10:29 +00:00
|
|
|
|
|
|
|
if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
|
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
|
|
|
|
else
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, min, max);
|
|
|
|
|
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
2018-05-06 13:49:36 +00:00
|
|
|
if (allocator)
|
|
|
|
gst_object_unref (allocator);
|
2017-05-20 16:10:29 +00:00
|
|
|
|
2017-05-20 15:25:16 +00:00
|
|
|
return TRUE;
|
2018-05-06 13:49:36 +00:00
|
|
|
|
|
|
|
config_failed:
|
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
|
|
|
if (allocator)
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
|
|
|
|
GST_ELEMENT_ERROR (agg, RESOURCE, SETTINGS,
|
|
|
|
("Failed to configure the buffer pool"),
|
|
|
|
("Configuration is most likely invalid, please report this issue."));
|
|
|
|
return FALSE;
|
2017-05-20 15:25:16 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
static GstFlowReturn
|
2018-05-06 14:05:28 +00:00
|
|
|
gst_video_aggregator_create_output_buffer (GstVideoAggregator * videoaggregator,
|
2014-06-03 17:00:34 +00:00
|
|
|
GstBuffer ** outbuf)
|
|
|
|
{
|
2017-05-20 15:25:16 +00:00
|
|
|
GstAggregator *aggregator = GST_AGGREGATOR (videoaggregator);
|
|
|
|
GstBufferPool *pool;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2017-05-20 15:25:16 +00:00
|
|
|
pool = gst_aggregator_get_buffer_pool (aggregator);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2017-05-20 15:25:16 +00:00
|
|
|
if (pool) {
|
|
|
|
if (!gst_buffer_pool_is_active (pool)) {
|
|
|
|
if (!gst_buffer_pool_set_active (pool, TRUE)) {
|
|
|
|
GST_ELEMENT_ERROR (videoaggregator, RESOURCE, SETTINGS,
|
|
|
|
("failed to activate bufferpool"),
|
|
|
|
("failed to activate bufferpool"));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2017-05-20 15:25:16 +00:00
|
|
|
ret = gst_buffer_pool_acquire_buffer (pool, outbuf, NULL);
|
|
|
|
gst_object_unref (pool);
|
|
|
|
} else {
|
|
|
|
guint outsize;
|
|
|
|
GstAllocator *allocator;
|
|
|
|
GstAllocationParams params;
|
|
|
|
|
|
|
|
gst_aggregator_get_allocator (aggregator, &allocator, ¶ms);
|
|
|
|
|
|
|
|
outsize = GST_VIDEO_INFO_SIZE (&videoaggregator->info);
|
|
|
|
*outbuf = gst_buffer_new_allocate (allocator, outsize, ¶ms);
|
|
|
|
|
|
|
|
if (allocator)
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
|
|
|
|
if (*outbuf == NULL) {
|
|
|
|
GST_ELEMENT_ERROR (videoaggregator, RESOURCE, NO_SPACE_LEFT,
|
|
|
|
(NULL), ("Could not acquire buffer of size: %d", outsize));
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_pad_sink_acceptcaps (GstPad * pad,
|
2014-06-03 17:00:34 +00:00
|
|
|
GstVideoAggregator * vagg, GstCaps * caps)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
GstCaps *modified_caps;
|
|
|
|
GstCaps *accepted_caps;
|
|
|
|
GstCaps *template_caps;
|
|
|
|
gboolean had_current_caps = TRUE;
|
|
|
|
gint i, n;
|
|
|
|
GstStructure *s;
|
|
|
|
GstAggregator *agg = GST_AGGREGATOR (vagg);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "%" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
accepted_caps = gst_pad_get_current_caps (GST_PAD (agg->srcpad));
|
|
|
|
|
|
|
|
template_caps = gst_pad_get_pad_template_caps (GST_PAD (agg->srcpad));
|
|
|
|
|
|
|
|
if (accepted_caps == NULL) {
|
|
|
|
accepted_caps = template_caps;
|
|
|
|
had_current_caps = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
accepted_caps = gst_caps_make_writable (accepted_caps);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (pad, "src caps %" GST_PTR_FORMAT, accepted_caps);
|
|
|
|
|
|
|
|
n = gst_caps_get_size (accepted_caps);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
s = gst_caps_get_structure (accepted_caps, i);
|
|
|
|
gst_structure_set (s, "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
|
|
|
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
|
|
|
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
|
|
|
|
|
|
|
|
gst_structure_remove_fields (s, "colorimetry", "chroma-site", "format",
|
2015-07-06 16:51:07 +00:00
|
|
|
"pixel-aspect-ratio", NULL);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
modified_caps = gst_caps_intersect (accepted_caps, template_caps);
|
|
|
|
|
|
|
|
ret = gst_caps_can_intersect (caps, accepted_caps);
|
|
|
|
GST_DEBUG_OBJECT (pad, "%saccepted caps %" GST_PTR_FORMAT,
|
|
|
|
(ret ? "" : "not "), caps);
|
|
|
|
gst_caps_unref (accepted_caps);
|
|
|
|
gst_caps_unref (modified_caps);
|
|
|
|
if (had_current_caps)
|
|
|
|
gst_caps_unref (template_caps);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_sink_query (GstAggregator * agg, GstAggregatorPad * bpad,
|
2014-06-03 17:00:34 +00:00
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (agg);
|
|
|
|
GstVideoAggregatorPad *pad = GST_VIDEO_AGGREGATOR_PAD (bpad);
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
|
|
|
|
|
|
|
gst_query_parse_caps (query, &filter);
|
2016-05-16 11:27:50 +00:00
|
|
|
caps =
|
|
|
|
gst_video_aggregator_pad_sink_getcaps (GST_PAD (pad), vagg, filter);
|
2014-06-03 17:00:34 +00:00
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_ACCEPT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_query_parse_accept_caps (query, &caps);
|
2016-05-16 11:27:50 +00:00
|
|
|
ret =
|
|
|
|
gst_video_aggregator_pad_sink_acceptcaps (GST_PAD (pad), vagg, caps);
|
2014-06-03 17:00:34 +00:00
|
|
|
gst_query_set_accept_caps_result (query, ret);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ret =
|
2016-05-16 11:27:50 +00:00
|
|
|
GST_AGGREGATOR_CLASS (gst_video_aggregator_parent_class)->sink_query
|
2014-06-03 17:00:34 +00:00
|
|
|
(agg, bpad, query);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GObject vmethods */
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_finalize (GObject * o)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (o);
|
|
|
|
|
|
|
|
g_mutex_clear (&vagg->priv->lock);
|
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
G_OBJECT_CLASS (gst_video_aggregator_parent_class)->finalize (o);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_dispose (GObject * o)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GstVideoAggregator *vagg = GST_VIDEO_AGGREGATOR (o);
|
|
|
|
|
|
|
|
gst_caps_replace (&vagg->priv->current_caps, NULL);
|
2014-06-23 12:36:23 +00:00
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
G_OBJECT_CLASS (gst_video_aggregator_parent_class)->dispose (o);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_get_property (GObject * object,
|
2014-06-03 17:00:34 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_set_property (GObject * object,
|
2014-06-03 17:00:34 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GObject boilerplate */
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_class_init (GstVideoAggregatorClass * klass)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
|
|
|
GstAggregatorClass *agg_class = (GstAggregatorClass *) klass;
|
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_video_aggregator_debug, "videoaggregator", 0,
|
2014-06-03 17:00:34 +00:00
|
|
|
"base video aggregator");
|
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_parent_class = g_type_class_peek_parent (klass);
|
2015-09-29 12:31:18 +00:00
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstVideoAggregatorPrivate));
|
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
gobject_class->finalize = gst_video_aggregator_finalize;
|
|
|
|
gobject_class->dispose = gst_video_aggregator_dispose;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
gobject_class->get_property = gst_video_aggregator_get_property;
|
|
|
|
gobject_class->set_property = gst_video_aggregator_set_property;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
gstelement_class->request_new_pad =
|
2016-05-16 11:27:50 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_video_aggregator_request_new_pad);
|
2014-06-03 17:00:34 +00:00
|
|
|
gstelement_class->release_pad =
|
2016-05-16 11:27:50 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_video_aggregator_release_pad);
|
2014-06-03 17:00:34 +00:00
|
|
|
|
2016-05-16 11:27:50 +00:00
|
|
|
agg_class->start = gst_video_aggregator_start;
|
|
|
|
agg_class->stop = gst_video_aggregator_stop;
|
|
|
|
agg_class->sink_query = gst_video_aggregator_sink_query;
|
|
|
|
agg_class->sink_event = gst_video_aggregator_sink_event;
|
|
|
|
agg_class->flush = gst_video_aggregator_flush;
|
|
|
|
agg_class->aggregate = gst_video_aggregator_aggregate;
|
|
|
|
agg_class->src_event = gst_video_aggregator_src_event;
|
|
|
|
agg_class->src_query = gst_video_aggregator_src_query;
|
|
|
|
agg_class->get_next_time = gst_video_aggregator_get_next_time;
|
2017-05-20 12:24:57 +00:00
|
|
|
agg_class->update_src_caps = gst_video_aggregator_default_update_src_caps;
|
|
|
|
agg_class->fixate_src_caps = gst_video_aggregator_default_fixate_src_caps;
|
|
|
|
agg_class->negotiated_src_caps =
|
|
|
|
gst_video_aggregator_default_negotiated_src_caps;
|
2017-05-20 15:25:16 +00:00
|
|
|
agg_class->decide_allocation = gst_video_aggregator_decide_allocation;
|
2017-05-21 13:44:02 +00:00
|
|
|
agg_class->propose_allocation = gst_video_aggregator_propose_allocation;
|
2016-05-16 11:27:50 +00:00
|
|
|
|
|
|
|
klass->find_best_format = gst_video_aggregator_find_best_format;
|
2018-05-06 14:05:28 +00:00
|
|
|
klass->create_output_buffer = gst_video_aggregator_create_output_buffer;
|
2016-05-16 11:27:50 +00:00
|
|
|
klass->update_caps = gst_video_aggregator_default_update_caps;
|
2014-06-03 17:00:34 +00:00
|
|
|
|
|
|
|
/* Register the pad class */
|
|
|
|
g_type_class_ref (GST_TYPE_VIDEO_AGGREGATOR_PAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_init (GstVideoAggregator * vagg,
|
2015-09-09 22:51:18 +00:00
|
|
|
GstVideoAggregatorClass * klass)
|
2014-06-03 17:00:34 +00:00
|
|
|
{
|
|
|
|
vagg->priv =
|
|
|
|
G_TYPE_INSTANCE_GET_PRIVATE (vagg, GST_TYPE_VIDEO_AGGREGATOR,
|
|
|
|
GstVideoAggregatorPrivate);
|
|
|
|
|
|
|
|
vagg->priv->current_caps = NULL;
|
|
|
|
|
|
|
|
g_mutex_init (&vagg->priv->lock);
|
2015-09-09 22:51:18 +00:00
|
|
|
|
2014-06-03 17:00:34 +00:00
|
|
|
/* initialize variables */
|
2016-05-16 11:27:50 +00:00
|
|
|
gst_video_aggregator_reset (vagg);
|
2014-06-03 17:00:34 +00:00
|
|
|
}
|