2013-06-03 21:02:15 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2013 Mathieu Duponchelle <mduponchelle1@gmail.com>
|
|
|
|
*
|
|
|
|
* 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 Street, Suite 500,
|
|
|
|
* Boston, MA 02110-1335, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
#include <math.h>
|
2013-06-03 21:02:15 +00:00
|
|
|
#include <gst/gst.h>
|
2013-08-22 21:06:38 +00:00
|
|
|
#include <gst/video/video.h>
|
2013-06-03 21:02:15 +00:00
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
#include "gstframepositioner.h"
|
2023-11-13 16:14:01 +00:00
|
|
|
#include "ges-frame-composition-meta.h"
|
2021-04-21 23:12:30 +00:00
|
|
|
#include "ges-internal.h"
|
2013-06-03 21:02:15 +00:00
|
|
|
|
2020-04-17 00:27:30 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (_framepositioner);
|
2020-02-20 15:28:59 +00:00
|
|
|
#undef GST_CAT_DEFAULT
|
2020-04-17 00:27:30 +00:00
|
|
|
#define GST_CAT_DEFAULT _framepositioner
|
2020-02-20 15:28:59 +00:00
|
|
|
|
2013-11-09 12:49:03 +00:00
|
|
|
/* We need to define a max number of pixel so we can interpolate them */
|
|
|
|
#define MAX_PIXELS 100000
|
|
|
|
#define MIN_PIXELS -100000
|
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
static void gst_frame_positioner_set_property (GObject * object,
|
2013-06-03 21:02:15 +00:00
|
|
|
guint property_id, const GValue * value, GParamSpec * pspec);
|
2016-04-13 09:31:05 +00:00
|
|
|
static void gst_frame_positioner_get_property (GObject * object,
|
2013-06-03 21:02:15 +00:00
|
|
|
guint property_id, GValue * value, GParamSpec * pspec);
|
2016-04-13 09:31:05 +00:00
|
|
|
static GstFlowReturn gst_frame_positioner_transform_ip (GstBaseTransform *
|
2013-06-03 21:02:15 +00:00
|
|
|
trans, GstBuffer * buf);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_ALPHA,
|
2024-02-27 17:00:04 +00:00
|
|
|
|
2013-06-03 21:02:15 +00:00
|
|
|
PROP_POSX,
|
2024-02-27 17:00:04 +00:00
|
|
|
PROP_FPOSX,
|
|
|
|
|
2013-06-03 21:02:15 +00:00
|
|
|
PROP_POSY,
|
2024-02-27 17:00:04 +00:00
|
|
|
PROP_FPOSY,
|
|
|
|
|
2013-08-21 09:32:45 +00:00
|
|
|
PROP_WIDTH,
|
2024-02-27 17:00:04 +00:00
|
|
|
PROP_FWIDTH,
|
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
PROP_HEIGHT,
|
2024-02-27 17:00:04 +00:00
|
|
|
PROP_FHEIGHT,
|
|
|
|
|
|
|
|
PROP_ZORDER,
|
2021-04-21 23:12:30 +00:00
|
|
|
PROP_OPERATOR,
|
2020-02-22 17:23:45 +00:00
|
|
|
PROP_LAST,
|
2013-06-03 21:02:15 +00:00
|
|
|
};
|
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
static GParamSpec *properties[PROP_LAST];
|
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
static GstStaticPadTemplate gst_frame_positioner_src_template =
|
2013-06-03 21:02:15 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2021-04-23 07:42:26 +00:00
|
|
|
GST_STATIC_CAPS ("video/x-raw(ANY)")
|
2013-06-03 21:02:15 +00:00
|
|
|
);
|
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
static GstStaticPadTemplate gst_frame_positioner_sink_template =
|
2013-06-03 21:02:15 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2021-04-23 07:42:26 +00:00
|
|
|
GST_STATIC_CAPS ("video/x-raw(ANY)")
|
2013-06-03 21:02:15 +00:00
|
|
|
);
|
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
G_DEFINE_TYPE (GstFramePositioner, gst_frame_positioner,
|
2013-06-03 21:02:15 +00:00
|
|
|
GST_TYPE_BASE_TRANSFORM);
|
|
|
|
|
2023-01-12 14:07:45 +00:00
|
|
|
GType
|
2021-04-21 23:12:30 +00:00
|
|
|
gst_compositor_operator_get_type_and_default_value (int *default_operator_value)
|
|
|
|
{
|
2022-06-16 20:40:21 +00:00
|
|
|
static gsize _init = 0;
|
|
|
|
static int operator_value = 0;
|
|
|
|
static GType operator_gtype = G_TYPE_NONE;
|
2021-04-21 23:12:30 +00:00
|
|
|
|
2022-06-16 20:40:21 +00:00
|
|
|
if (g_once_init_enter (&_init)) {
|
|
|
|
GstElement *compositor =
|
|
|
|
gst_element_factory_create (ges_get_compositor_factory (), NULL);
|
2021-04-21 23:12:30 +00:00
|
|
|
|
2022-06-16 20:40:21 +00:00
|
|
|
GstPad *compositorPad =
|
|
|
|
gst_element_request_pad_simple (compositor, "sink_%u");
|
2021-04-21 23:12:30 +00:00
|
|
|
|
2022-06-16 20:40:21 +00:00
|
|
|
GParamSpec *pspec =
|
|
|
|
g_object_class_find_property (G_OBJECT_GET_CLASS (compositorPad),
|
|
|
|
"operator");
|
2021-04-23 15:55:45 +00:00
|
|
|
|
2022-06-16 20:40:21 +00:00
|
|
|
if (pspec) {
|
|
|
|
operator_value =
|
|
|
|
g_value_get_enum (g_param_spec_get_default_value (pspec));
|
|
|
|
operator_gtype = pspec->value_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_release_request_pad (compositor, compositorPad);
|
|
|
|
gst_object_unref (compositorPad);
|
|
|
|
gst_object_unref (compositor);
|
|
|
|
|
|
|
|
g_once_init_leave (&_init, 1);
|
2021-04-23 15:55:45 +00:00
|
|
|
}
|
2021-04-21 23:12:30 +00:00
|
|
|
|
2023-01-12 14:07:45 +00:00
|
|
|
if (default_operator_value)
|
|
|
|
*default_operator_value = operator_value;
|
2021-04-21 23:12:30 +00:00
|
|
|
|
2022-06-16 20:40:21 +00:00
|
|
|
return operator_gtype;
|
2021-04-21 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2023-06-20 20:01:37 +00:00
|
|
|
static gboolean
|
|
|
|
scales_downstream (GstFramePositioner * self)
|
|
|
|
{
|
|
|
|
if (self->scale_in_compositor)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!self->track_source)
|
|
|
|
return self->scale_in_compositor;
|
|
|
|
|
|
|
|
GESTimelineElement *parent = GES_TIMELINE_ELEMENT_PARENT (self->track_source);
|
|
|
|
|
|
|
|
if (!parent || !GES_IS_CLIP (parent)) {
|
|
|
|
return self->scale_in_compositor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ges_clip_has_scale_effect (GES_CLIP (parent));
|
|
|
|
}
|
|
|
|
|
2013-08-21 09:32:45 +00:00
|
|
|
static void
|
2016-04-13 09:31:05 +00:00
|
|
|
_weak_notify_cb (GstFramePositioner * pos, GObject * old)
|
2013-08-21 09:32:45 +00:00
|
|
|
{
|
|
|
|
pos->current_track = NULL;
|
|
|
|
}
|
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
static gboolean
|
|
|
|
is_user_positionned (GstFramePositioner * self)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
GParamSpec *positioning_props[] = {
|
|
|
|
properties[PROP_WIDTH],
|
2024-02-27 17:00:04 +00:00
|
|
|
properties[PROP_FWIDTH],
|
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
properties[PROP_HEIGHT],
|
2024-02-27 17:00:04 +00:00
|
|
|
properties[PROP_FHEIGHT],
|
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
properties[PROP_POSX],
|
2024-02-27 17:00:04 +00:00
|
|
|
properties[PROP_FPOSX],
|
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
properties[PROP_POSY],
|
2024-02-27 17:00:04 +00:00
|
|
|
properties[PROP_FPOSY],
|
2020-02-22 17:23:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (self->user_positioned)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (positioning_props); i++) {
|
|
|
|
GstControlBinding *b = gst_object_get_control_binding (GST_OBJECT (self),
|
|
|
|
positioning_props[i]->name);
|
|
|
|
|
|
|
|
if (b) {
|
|
|
|
gst_object_unref (b);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-02-19 21:09:19 +00:00
|
|
|
static gboolean
|
|
|
|
auto_position (GstFramePositioner * self)
|
|
|
|
{
|
2020-04-17 00:27:30 +00:00
|
|
|
gdouble scaled_width = -1, scaled_height = -1, x, y;
|
2020-02-19 21:09:19 +00:00
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
if (is_user_positionned (self)) {
|
|
|
|
GST_DEBUG_OBJECT (self, "Was positioned by the user, not auto positioning");
|
2020-02-19 21:09:19 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!self->natural_width || !self->natural_height)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (self->track_width == self->natural_width &&
|
|
|
|
self->track_height == self->natural_height)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
scaled_height =
|
|
|
|
gst_util_uint64_scale_int (self->natural_height, self->track_width,
|
|
|
|
self->natural_width);
|
|
|
|
scaled_width = self->track_width;
|
|
|
|
if (scaled_height > self->track_height) {
|
|
|
|
scaled_height = self->track_height;
|
|
|
|
scaled_width =
|
|
|
|
gst_util_uint64_scale_int (self->natural_width, self->track_height,
|
|
|
|
self->natural_height);
|
|
|
|
}
|
|
|
|
|
2020-04-17 00:27:30 +00:00
|
|
|
x = MAX (0, (self->track_width - scaled_width) / 2.f);
|
|
|
|
y = MAX (0, (self->track_height - scaled_height) / 2.f);
|
2020-02-19 21:09:19 +00:00
|
|
|
|
|
|
|
GST_INFO_OBJECT (self, "Scalling video to match track size from "
|
2020-04-17 00:27:30 +00:00
|
|
|
"%dx%d to %fx%f",
|
2020-02-19 21:09:19 +00:00
|
|
|
self->natural_width, self->natural_height, scaled_width, scaled_height);
|
|
|
|
self->width = scaled_width;
|
|
|
|
self->height = scaled_height;
|
|
|
|
self->posx = x;
|
|
|
|
self->posy = y;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2020-04-17 00:27:30 +00:00
|
|
|
gdouble *value;
|
2020-02-22 17:23:45 +00:00
|
|
|
gint old_track_value;
|
|
|
|
gint track_value;
|
|
|
|
GParamSpec *pspec;
|
|
|
|
} RepositionPropertyData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
reposition_properties (GstFramePositioner * pos, gint old_track_width,
|
|
|
|
gint old_track_height)
|
|
|
|
{
|
|
|
|
gint i;
|
2024-02-27 17:00:04 +00:00
|
|
|
/* *INDENT-OFF* */
|
2020-02-22 17:23:45 +00:00
|
|
|
RepositionPropertyData props_data[] = {
|
2024-02-27 17:00:04 +00:00
|
|
|
{&pos->width, old_track_width, pos->track_width, properties[PROP_FWIDTH]},
|
2020-02-22 17:23:45 +00:00
|
|
|
{&pos->width, old_track_width, pos->track_width, properties[PROP_WIDTH]},
|
2024-02-27 17:00:04 +00:00
|
|
|
|
|
|
|
{&pos->height, old_track_height, pos->track_height, properties[PROP_FHEIGHT]},
|
|
|
|
{&pos->height, old_track_height, pos->track_height, properties[PROP_HEIGHT]},
|
|
|
|
|
|
|
|
{&pos->posx, old_track_width, pos->track_width, properties[PROP_FPOSX]},
|
2020-02-22 17:23:45 +00:00
|
|
|
{&pos->posx, old_track_width, pos->track_width, properties[PROP_POSX]},
|
2024-02-27 17:00:04 +00:00
|
|
|
|
|
|
|
{&pos->posy, old_track_height, pos->track_height, properties[PROP_FPOSY]},
|
2020-02-22 17:23:45 +00:00
|
|
|
{&pos->posy, old_track_height, pos->track_height, properties[PROP_POSY]},
|
|
|
|
};
|
2024-02-27 17:00:04 +00:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (props_data); i++) {
|
|
|
|
GList *values, *tmp;
|
|
|
|
gboolean absolute;
|
|
|
|
GstTimedValueControlSource *source = NULL;
|
|
|
|
|
|
|
|
RepositionPropertyData d = props_data[i];
|
|
|
|
GstControlBinding *binding =
|
|
|
|
gst_object_get_control_binding (GST_OBJECT (pos), d.pspec->name);
|
|
|
|
|
2024-02-27 17:00:04 +00:00
|
|
|
if (G_PARAM_SPEC_VALUE_TYPE (d.pspec) == G_TYPE_FLOAT) {
|
|
|
|
*(d.value) =
|
|
|
|
*(d.value) * (gdouble) d.track_value / (gdouble) d.old_track_value;
|
|
|
|
}
|
2020-02-22 17:23:45 +00:00
|
|
|
|
|
|
|
if (!binding)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!GST_IS_DIRECT_CONTROL_BINDING (binding)) {
|
|
|
|
GST_FIXME_OBJECT (pos, "Implement support for control binding type: %s",
|
|
|
|
G_OBJECT_TYPE_NAME (binding));
|
|
|
|
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_get (binding, "control_source", &source, NULL);
|
2020-02-28 14:58:30 +00:00
|
|
|
if (!source || !GST_IS_TIMED_VALUE_CONTROL_SOURCE (source)) {
|
2020-02-22 17:23:45 +00:00
|
|
|
GST_FIXME_OBJECT (pos, "Implement support for control source type: %s",
|
2020-02-28 14:58:30 +00:00
|
|
|
source ? G_OBJECT_TYPE_NAME (source) : "NULL");
|
2020-02-22 17:23:45 +00:00
|
|
|
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
values =
|
|
|
|
gst_timed_value_control_source_get_all (GST_TIMED_VALUE_CONTROL_SOURCE
|
|
|
|
(source));
|
|
|
|
|
|
|
|
if (!values)
|
|
|
|
goto next;
|
|
|
|
|
|
|
|
g_object_get (binding, "absolute", &absolute, NULL);
|
|
|
|
for (tmp = values; tmp; tmp = tmp->next) {
|
|
|
|
GstTimedValue *value = tmp->data;
|
|
|
|
|
|
|
|
gst_timed_value_control_source_set (source, value->timestamp,
|
|
|
|
value->value * d.track_value / d.old_track_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (values);
|
|
|
|
|
|
|
|
next:
|
|
|
|
gst_clear_object (&source);
|
|
|
|
gst_object_unref (binding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-21 09:32:45 +00:00
|
|
|
static void
|
2016-04-13 09:31:05 +00:00
|
|
|
gst_frame_positioner_update_properties (GstFramePositioner * pos,
|
2016-08-02 20:42:20 +00:00
|
|
|
gboolean track_mixing, gint old_track_width, gint old_track_height)
|
2013-08-21 09:32:45 +00:00
|
|
|
{
|
2013-09-04 23:03:51 +00:00
|
|
|
GstCaps *caps;
|
2013-08-21 09:32:45 +00:00
|
|
|
|
|
|
|
if (pos->capsfilter == NULL)
|
|
|
|
return;
|
|
|
|
|
2021-04-23 07:42:26 +00:00
|
|
|
caps = gst_caps_from_string ("video/x-raw(ANY)");
|
|
|
|
|
2016-08-02 20:42:20 +00:00
|
|
|
if (pos->track_width && pos->track_height &&
|
2023-06-20 20:01:37 +00:00
|
|
|
(!track_mixing || !scales_downstream (pos))) {
|
2021-04-23 07:42:26 +00:00
|
|
|
gst_caps_set_simple (caps, "width", G_TYPE_INT,
|
2015-06-13 16:48:20 +00:00
|
|
|
pos->track_width, "height", G_TYPE_INT, pos->track_height, NULL);
|
|
|
|
}
|
2013-08-21 09:32:45 +00:00
|
|
|
|
2013-09-04 23:03:51 +00:00
|
|
|
if (pos->fps_n != -1)
|
|
|
|
gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, pos->fps_n,
|
|
|
|
pos->fps_d, NULL);
|
|
|
|
|
2017-10-31 15:05:08 +00:00
|
|
|
if (pos->par_n != -1)
|
|
|
|
gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
pos->par_n, pos->par_d, NULL);
|
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
if (!pos->track_width || !pos->track_height) {
|
|
|
|
GST_INFO_OBJECT (pos, "Track doesn't have a proper size, not "
|
|
|
|
"positioning the source");
|
|
|
|
goto done;
|
|
|
|
} else if (auto_position (pos))
|
|
|
|
goto done;
|
2015-06-13 16:48:20 +00:00
|
|
|
|
2020-04-09 15:17:59 +00:00
|
|
|
if (!old_track_height || !old_track_width) {
|
2020-02-22 17:23:45 +00:00
|
|
|
GST_DEBUG_OBJECT (pos, "No old track size, can not properly reposition");
|
|
|
|
goto done;
|
|
|
|
}
|
2015-06-13 16:48:20 +00:00
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
if ((!pos->natural_width || !pos->natural_height) &&
|
|
|
|
(!pos->width || !pos->height)) {
|
|
|
|
GST_DEBUG_OBJECT (pos, "No natural aspect ratio and no user set "
|
|
|
|
" image size, can't not reposition.");
|
|
|
|
goto done;
|
|
|
|
}
|
2020-02-19 21:09:19 +00:00
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
if (gst_util_fraction_compare (old_track_width, old_track_height,
|
|
|
|
pos->track_width, pos->track_height)) {
|
|
|
|
GST_INFO_OBJECT (pos, "Not repositioning as track size change didn't"
|
|
|
|
" keep the same aspect ratio (previous %dx%d("
|
|
|
|
"ratio=%f), new: %dx%d(ratio=%f)",
|
|
|
|
old_track_width, old_track_height,
|
|
|
|
(gdouble) old_track_width / (gdouble) old_track_height,
|
|
|
|
pos->track_width, pos->track_height,
|
|
|
|
(gdouble) pos->track_width / (gdouble) pos->track_height);
|
|
|
|
goto done;
|
2015-06-13 16:48:20 +00:00
|
|
|
}
|
|
|
|
|
2020-02-22 17:23:45 +00:00
|
|
|
reposition_properties (pos, old_track_width, old_track_height);
|
|
|
|
|
|
|
|
done:
|
2023-06-20 20:01:37 +00:00
|
|
|
if (scales_downstream (pos) && pos->natural_width && pos->natural_height) {
|
|
|
|
GST_DEBUG_OBJECT (pos,
|
|
|
|
"Forcing natural width in source make downstream scaling work");
|
|
|
|
gst_caps_set_simple (caps, "width", G_TYPE_INT, pos->natural_width,
|
|
|
|
"height", G_TYPE_INT, pos->natural_height, NULL);
|
|
|
|
}
|
|
|
|
|
2021-04-14 03:58:30 +00:00
|
|
|
GST_DEBUG_OBJECT (pos, "setting caps %" GST_PTR_FORMAT, caps);
|
2013-09-04 23:03:51 +00:00
|
|
|
|
|
|
|
g_object_set (pos->capsfilter, "caps", caps, NULL);
|
2013-08-21 09:32:45 +00:00
|
|
|
|
2014-10-26 20:31:26 +00:00
|
|
|
gst_caps_unref (caps);
|
2013-08-21 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-08-02 20:42:20 +00:00
|
|
|
sync_properties_from_track (GstFramePositioner * pos, GESTrack * track)
|
2013-08-21 09:32:45 +00:00
|
|
|
{
|
|
|
|
gint width, height;
|
2014-11-02 10:46:37 +00:00
|
|
|
gint old_track_width, old_track_height;
|
2016-08-02 20:42:20 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
g_object_get (track, "restriction-caps", &caps, NULL);
|
2013-08-21 09:32:45 +00:00
|
|
|
|
|
|
|
width = height = 0;
|
|
|
|
|
|
|
|
if (caps && gst_caps_get_size (caps) > 0) {
|
|
|
|
GstStructure *structure;
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
if (!gst_structure_get_int (structure, "width", &width))
|
|
|
|
width = 0;
|
|
|
|
if (!gst_structure_get_int (structure, "height", &height))
|
2014-04-10 16:03:55 +00:00
|
|
|
height = 0;
|
2013-09-04 23:03:51 +00:00
|
|
|
if (!gst_structure_get_fraction (structure, "framerate", &(pos->fps_n),
|
|
|
|
&(pos->fps_d)))
|
|
|
|
pos->fps_n = -1;
|
2017-10-31 15:05:08 +00:00
|
|
|
|
|
|
|
if (!gst_structure_get_fraction (structure, "pixel-aspect-ratio",
|
|
|
|
&(pos->par_n), &(pos->par_d)))
|
|
|
|
pos->par_n = -1;
|
2013-08-21 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
2014-11-02 10:46:37 +00:00
|
|
|
old_track_width = pos->track_width;
|
|
|
|
old_track_height = pos->track_height;
|
|
|
|
|
2013-08-21 09:32:45 +00:00
|
|
|
pos->track_width = width;
|
|
|
|
pos->track_height = height;
|
|
|
|
|
2013-09-04 23:03:51 +00:00
|
|
|
GST_DEBUG_OBJECT (pos, "syncing framerate from caps : %d/%d", pos->fps_n,
|
|
|
|
pos->fps_d);
|
2019-04-09 12:56:49 +00:00
|
|
|
if (caps)
|
|
|
|
gst_caps_unref (caps);
|
2013-08-21 09:32:45 +00:00
|
|
|
|
2016-08-02 20:42:20 +00:00
|
|
|
gst_frame_positioner_update_properties (pos, ges_track_get_mixing (track),
|
|
|
|
old_track_width, old_track_height);
|
2013-08-21 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_track_restriction_changed_cb (GESTrack * track, GParamSpec * arg G_GNUC_UNUSED,
|
2016-04-13 09:31:05 +00:00
|
|
|
GstFramePositioner * pos)
|
2013-08-21 09:32:45 +00:00
|
|
|
{
|
2016-08-02 20:42:20 +00:00
|
|
|
sync_properties_from_track (pos, track);
|
2013-08-21 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-04-13 09:31:05 +00:00
|
|
|
set_track (GstFramePositioner * pos)
|
2013-08-21 09:32:45 +00:00
|
|
|
{
|
|
|
|
GESTrack *new_track;
|
|
|
|
|
|
|
|
if (pos->current_track) {
|
|
|
|
g_signal_handlers_disconnect_by_func (pos->current_track,
|
|
|
|
(GCallback) _track_restriction_changed_cb, pos);
|
|
|
|
g_object_weak_unref (G_OBJECT (pos->current_track),
|
|
|
|
(GWeakNotify) _weak_notify_cb, pos);
|
|
|
|
}
|
|
|
|
|
2016-01-25 10:56:57 +00:00
|
|
|
new_track = ges_track_element_get_track (pos->track_source);
|
2013-08-21 09:32:45 +00:00
|
|
|
if (new_track) {
|
|
|
|
pos->current_track = new_track;
|
|
|
|
g_object_weak_ref (G_OBJECT (new_track), (GWeakNotify) _weak_notify_cb,
|
|
|
|
pos);
|
|
|
|
GST_DEBUG_OBJECT (pos, "connecting to track : %p", pos->current_track);
|
2016-01-25 10:56:57 +00:00
|
|
|
|
2013-08-21 09:32:45 +00:00
|
|
|
g_signal_connect (pos->current_track, "notify::restriction-caps",
|
|
|
|
(GCallback) _track_restriction_changed_cb, pos);
|
2016-08-02 20:42:20 +00:00
|
|
|
sync_properties_from_track (pos, pos->current_track);
|
2016-01-25 10:56:57 +00:00
|
|
|
} else {
|
2013-08-21 09:32:45 +00:00
|
|
|
pos->current_track = NULL;
|
2016-01-25 10:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_track_changed_cb (GESTrackElement * trksrc, GParamSpec * arg G_GNUC_UNUSED,
|
2016-04-13 09:31:05 +00:00
|
|
|
GstFramePositioner * pos)
|
2016-01-25 10:56:57 +00:00
|
|
|
{
|
|
|
|
set_track (pos);
|
2013-08-21 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 10:53:32 +00:00
|
|
|
static void
|
|
|
|
_trk_element_weak_notify_cb (GstFramePositioner * pos, GObject * old)
|
|
|
|
{
|
|
|
|
pos->track_source = NULL;
|
2019-01-14 13:14:18 +00:00
|
|
|
gst_object_unref (pos);
|
2016-05-16 10:53:32 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 09:32:45 +00:00
|
|
|
void
|
2016-04-13 09:31:05 +00:00
|
|
|
ges_frame_positioner_set_source_and_filter (GstFramePositioner * pos,
|
2013-08-21 09:32:45 +00:00
|
|
|
GESTrackElement * trksrc, GstElement * capsfilter)
|
|
|
|
{
|
|
|
|
pos->track_source = trksrc;
|
|
|
|
pos->capsfilter = capsfilter;
|
|
|
|
pos->current_track = ges_track_element_get_track (trksrc);
|
2014-09-19 10:28:05 +00:00
|
|
|
|
2016-05-16 10:53:32 +00:00
|
|
|
g_object_weak_ref (G_OBJECT (trksrc),
|
2019-01-14 13:14:18 +00:00
|
|
|
(GWeakNotify) _trk_element_weak_notify_cb, gst_object_ref (pos));
|
2013-08-21 09:32:45 +00:00
|
|
|
g_signal_connect (trksrc, "notify::track", (GCallback) _track_changed_cb,
|
|
|
|
pos);
|
2016-01-25 10:56:57 +00:00
|
|
|
set_track (pos);
|
2013-08-21 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-04-13 09:31:05 +00:00
|
|
|
gst_frame_positioner_dispose (GObject * object)
|
2013-08-21 09:32:45 +00:00
|
|
|
{
|
2016-04-13 09:31:05 +00:00
|
|
|
GstFramePositioner *pos = GST_FRAME_POSITIONNER (object);
|
2013-08-21 09:32:45 +00:00
|
|
|
|
|
|
|
if (pos->track_source) {
|
|
|
|
g_signal_handlers_disconnect_by_func (pos->track_source, _track_changed_cb,
|
|
|
|
pos);
|
|
|
|
pos->track_source = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos->current_track) {
|
|
|
|
g_signal_handlers_disconnect_by_func (pos->current_track,
|
|
|
|
_track_restriction_changed_cb, pos);
|
|
|
|
g_object_weak_unref (G_OBJECT (pos->current_track),
|
|
|
|
(GWeakNotify) _weak_notify_cb, pos);
|
|
|
|
pos->current_track = NULL;
|
|
|
|
}
|
2014-03-07 20:48:06 +00:00
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
G_OBJECT_CLASS (gst_frame_positioner_parent_class)->dispose (object);
|
2013-08-21 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
2013-06-03 21:02:15 +00:00
|
|
|
static void
|
2016-04-13 09:31:05 +00:00
|
|
|
gst_frame_positioner_class_init (GstFramePositionerClass * klass)
|
2013-06-03 21:02:15 +00:00
|
|
|
{
|
2021-04-23 15:55:45 +00:00
|
|
|
int default_operator_value = 0;
|
2021-04-21 23:12:30 +00:00
|
|
|
GType operator_gtype =
|
|
|
|
gst_compositor_operator_get_type_and_default_value
|
|
|
|
(&default_operator_value);
|
2021-04-23 15:55:45 +00:00
|
|
|
guint n_pspecs = PROP_LAST;
|
2021-04-21 23:12:30 +00:00
|
|
|
|
2013-06-03 21:02:15 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstBaseTransformClass *base_transform_class =
|
|
|
|
GST_BASE_TRANSFORM_CLASS (klass);
|
|
|
|
|
2023-06-23 02:22:45 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (_framepositioner, "gesframepositioner",
|
2020-02-19 21:09:19 +00:00
|
|
|
GST_DEBUG_FG_YELLOW, "ges frame positioner");
|
|
|
|
|
2016-03-06 23:49:14 +00:00
|
|
|
gst_element_class_add_static_pad_template (GST_ELEMENT_CLASS (klass),
|
2016-04-13 09:31:05 +00:00
|
|
|
&gst_frame_positioner_src_template);
|
2016-03-06 23:49:14 +00:00
|
|
|
gst_element_class_add_static_pad_template (GST_ELEMENT_CLASS (klass),
|
2016-04-13 09:31:05 +00:00
|
|
|
&gst_frame_positioner_sink_template);
|
2013-06-03 21:02:15 +00:00
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
gobject_class->set_property = gst_frame_positioner_set_property;
|
|
|
|
gobject_class->get_property = gst_frame_positioner_get_property;
|
|
|
|
gobject_class->dispose = gst_frame_positioner_dispose;
|
2013-06-03 21:02:15 +00:00
|
|
|
base_transform_class->transform_ip =
|
2016-04-13 09:31:05 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_frame_positioner_transform_ip);
|
2013-06-03 21:02:15 +00:00
|
|
|
|
|
|
|
/**
|
2016-04-13 09:31:05 +00:00
|
|
|
* gstframepositioner:alpha:
|
2013-06-03 21:02:15 +00:00
|
|
|
*
|
|
|
|
* The desired alpha for the stream.
|
|
|
|
*/
|
2020-02-22 17:23:45 +00:00
|
|
|
properties[PROP_ALPHA] =
|
|
|
|
g_param_spec_double ("alpha", "alpha", "alpha of the stream", 0.0, 1.0,
|
|
|
|
1.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE);
|
2013-06-03 21:02:15 +00:00
|
|
|
|
|
|
|
/**
|
2016-04-13 09:31:05 +00:00
|
|
|
* gstframepositioner:posx:
|
2013-06-03 21:02:15 +00:00
|
|
|
*
|
|
|
|
* The desired x position for the stream.
|
|
|
|
*/
|
2020-02-22 17:23:45 +00:00
|
|
|
properties[PROP_POSX] =
|
2024-02-27 17:00:04 +00:00
|
|
|
g_param_spec_int ("posx", "posx", "x position of the stream",
|
|
|
|
MIN_PIXELS, MAX_PIXELS, 0,
|
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_LAX_VALIDATION);
|
2013-11-09 12:49:03 +00:00
|
|
|
|
2024-02-27 17:00:04 +00:00
|
|
|
/**
|
|
|
|
* gstframepositioner:fposx:
|
|
|
|
*
|
|
|
|
* The desired x position for the stream.
|
|
|
|
*/
|
|
|
|
properties[PROP_FPOSX] =
|
|
|
|
g_param_spec_float ("fposx", "fposx", "x position of the stream in float",
|
|
|
|
MIN_PIXELS, MAX_PIXELS, 0,
|
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_LAX_VALIDATION);
|
2013-06-03 21:02:15 +00:00
|
|
|
|
|
|
|
/**
|
2016-04-13 09:31:05 +00:00
|
|
|
* gstframepositioner:posy:
|
2013-06-03 21:02:15 +00:00
|
|
|
*
|
|
|
|
* The desired y position for the stream.
|
|
|
|
*/
|
2020-02-22 17:23:45 +00:00
|
|
|
properties[PROP_POSY] =
|
2024-02-27 17:00:04 +00:00
|
|
|
g_param_spec_int ("posy", "posy", "y position of the stream",
|
|
|
|
MIN_PIXELS, MAX_PIXELS, 0,
|
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_LAX_VALIDATION);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gstframepositioner:fposy:
|
|
|
|
*
|
|
|
|
* The desired y position for the stream.
|
|
|
|
*/
|
|
|
|
properties[PROP_FPOSY] =
|
|
|
|
g_param_spec_float ("fposy", "fposy", "y position of the stream in float",
|
|
|
|
MIN_PIXELS, MAX_PIXELS, 0,
|
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_LAX_VALIDATION);
|
2013-06-03 21:02:15 +00:00
|
|
|
|
|
|
|
/**
|
2016-04-13 09:31:05 +00:00
|
|
|
* gstframepositioner:zorder:
|
2013-06-03 21:02:15 +00:00
|
|
|
*
|
|
|
|
* The desired z order for the stream.
|
|
|
|
*/
|
2020-02-22 17:23:45 +00:00
|
|
|
properties[PROP_ZORDER] =
|
|
|
|
g_param_spec_uint ("zorder", "zorder", "z order of the stream", 0,
|
|
|
|
G_MAXUINT, 0, G_PARAM_READWRITE);
|
2013-06-03 21:02:15 +00:00
|
|
|
|
2013-08-21 09:32:45 +00:00
|
|
|
/**
|
2016-04-13 09:31:05 +00:00
|
|
|
* gesframepositioner:width:
|
2013-08-21 09:32:45 +00:00
|
|
|
*
|
|
|
|
* The desired width for that source.
|
|
|
|
* Set to 0 if size is not mandatory, will be set to width of the current track.
|
|
|
|
*/
|
2020-02-22 17:23:45 +00:00
|
|
|
properties[PROP_WIDTH] =
|
2024-02-27 17:00:04 +00:00
|
|
|
g_param_spec_int ("width", "width", "width of the source", 0,
|
|
|
|
MAX_PIXELS, 0,
|
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_LAX_VALIDATION);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gesframepositioner:fwidth:
|
|
|
|
*
|
|
|
|
* The desired width for that source.
|
|
|
|
* Set to 0 if size is not mandatory, will be set to width of the current track.
|
|
|
|
*/
|
|
|
|
properties[PROP_FWIDTH] =
|
|
|
|
g_param_spec_float ("fwidth", "fwidth", "width of the source in float", 0,
|
|
|
|
MAX_PIXELS, 0,
|
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_LAX_VALIDATION);
|
2013-08-21 09:32:45 +00:00
|
|
|
|
|
|
|
/**
|
2016-04-13 09:31:05 +00:00
|
|
|
* gesframepositioner:height:
|
2013-08-21 09:32:45 +00:00
|
|
|
*
|
|
|
|
* The desired height for that source.
|
|
|
|
* Set to 0 if size is not mandatory, will be set to height of the current track.
|
|
|
|
*/
|
2020-02-22 17:23:45 +00:00
|
|
|
properties[PROP_HEIGHT] =
|
|
|
|
g_param_spec_int ("height", "height", "height of the source", 0,
|
2024-02-27 17:00:04 +00:00
|
|
|
MAX_PIXELS, 0,
|
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_LAX_VALIDATION);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gesframepositioner:fheight:
|
|
|
|
*
|
|
|
|
* The desired height for that source.
|
|
|
|
* Set to 0 if size is not mandatory, will be set to height of the current track.
|
|
|
|
*/
|
|
|
|
properties[PROP_FHEIGHT] =
|
|
|
|
g_param_spec_float ("fheight", "fheight", "height of the source in float",
|
|
|
|
0, MAX_PIXELS, 0,
|
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_LAX_VALIDATION);
|
2020-02-22 17:23:45 +00:00
|
|
|
|
2021-04-21 23:12:30 +00:00
|
|
|
/**
|
|
|
|
* gesframepositioner:operator:
|
|
|
|
*
|
|
|
|
* The blending operator for the source.
|
|
|
|
*/
|
2023-01-12 14:07:45 +00:00
|
|
|
if (operator_gtype != G_TYPE_NONE) {
|
2021-04-23 15:55:45 +00:00
|
|
|
properties[PROP_OPERATOR] =
|
|
|
|
g_param_spec_enum ("operator", "Operator",
|
|
|
|
"Blending operator to use for blending this pad over the previous ones",
|
|
|
|
operator_gtype, default_operator_value,
|
|
|
|
(G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
|
|
|
|
GST_PARAM_CONDITIONALLY_AVAILABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
} else {
|
|
|
|
n_pspecs--;
|
|
|
|
}
|
2021-04-21 23:12:30 +00:00
|
|
|
|
2021-04-23 15:55:45 +00:00
|
|
|
g_object_class_install_properties (gobject_class, n_pspecs, properties);
|
2013-08-21 09:32:45 +00:00
|
|
|
|
2013-06-03 21:02:15 +00:00
|
|
|
gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
|
2016-04-13 09:31:05 +00:00
|
|
|
"frame positioner", "Metadata",
|
2013-06-03 21:02:15 +00:00
|
|
|
"This element provides with tagging facilities",
|
|
|
|
"mduponchelle1@gmail.com");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-04-13 09:31:05 +00:00
|
|
|
gst_frame_positioner_init (GstFramePositioner * framepositioner)
|
2013-06-03 21:02:15 +00:00
|
|
|
{
|
2021-04-23 14:01:35 +00:00
|
|
|
int default_operator_value;
|
|
|
|
gst_compositor_operator_get_type_and_default_value (&default_operator_value);
|
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
framepositioner->alpha = 1.0;
|
|
|
|
framepositioner->posx = 0.0;
|
|
|
|
framepositioner->posy = 0.0;
|
|
|
|
framepositioner->zorder = 0;
|
|
|
|
framepositioner->width = 0;
|
|
|
|
framepositioner->height = 0;
|
2021-04-23 14:01:35 +00:00
|
|
|
framepositioner->operator = default_operator_value;
|
2016-04-13 09:31:05 +00:00
|
|
|
framepositioner->fps_n = -1;
|
|
|
|
framepositioner->fps_d = -1;
|
|
|
|
framepositioner->track_width = 0;
|
|
|
|
framepositioner->track_height = 0;
|
|
|
|
framepositioner->capsfilter = NULL;
|
|
|
|
framepositioner->track_source = NULL;
|
|
|
|
framepositioner->current_track = NULL;
|
2016-08-02 20:42:20 +00:00
|
|
|
framepositioner->scale_in_compositor = TRUE;
|
2017-10-31 15:05:08 +00:00
|
|
|
|
|
|
|
framepositioner->par_n = -1;
|
|
|
|
framepositioner->par_d = 1;
|
2013-06-03 21:02:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-04-13 09:31:05 +00:00
|
|
|
gst_frame_positioner_set_property (GObject * object, guint property_id,
|
2013-06-03 21:02:15 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2016-04-13 09:31:05 +00:00
|
|
|
GstFramePositioner *framepositioner = GST_FRAME_POSITIONNER (object);
|
2016-08-02 20:42:20 +00:00
|
|
|
gboolean track_mixing = TRUE;
|
|
|
|
|
|
|
|
if (framepositioner->current_track)
|
|
|
|
track_mixing = ges_track_get_mixing (framepositioner->current_track);
|
2013-06-03 21:02:15 +00:00
|
|
|
|
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
GST_OBJECT_LOCK (framepositioner);
|
2013-06-03 21:02:15 +00:00
|
|
|
switch (property_id) {
|
|
|
|
case PROP_ALPHA:
|
2016-04-13 09:31:05 +00:00
|
|
|
framepositioner->alpha = g_value_get_double (value);
|
2013-06-03 21:02:15 +00:00
|
|
|
break;
|
|
|
|
case PROP_POSX:
|
2016-04-13 09:31:05 +00:00
|
|
|
framepositioner->posx = g_value_get_int (value);
|
2020-02-19 21:09:19 +00:00
|
|
|
framepositioner->user_positioned = TRUE;
|
2013-06-03 21:02:15 +00:00
|
|
|
break;
|
2024-02-27 17:00:04 +00:00
|
|
|
case PROP_FPOSX:
|
|
|
|
framepositioner->posx = g_value_get_float (value);
|
|
|
|
framepositioner->user_positioned = TRUE;
|
|
|
|
break;
|
2013-06-03 21:02:15 +00:00
|
|
|
case PROP_POSY:
|
2016-04-13 09:31:05 +00:00
|
|
|
framepositioner->posy = g_value_get_int (value);
|
2020-02-19 21:09:19 +00:00
|
|
|
framepositioner->user_positioned = TRUE;
|
2013-06-03 21:02:15 +00:00
|
|
|
break;
|
2024-02-27 17:00:04 +00:00
|
|
|
case PROP_FPOSY:
|
|
|
|
framepositioner->posy = g_value_get_float (value);
|
|
|
|
framepositioner->user_positioned = TRUE;
|
|
|
|
break;
|
2013-06-03 21:02:15 +00:00
|
|
|
case PROP_ZORDER:
|
2016-04-13 09:31:05 +00:00
|
|
|
framepositioner->zorder = g_value_get_uint (value);
|
2013-06-03 21:02:15 +00:00
|
|
|
break;
|
2013-08-21 09:32:45 +00:00
|
|
|
case PROP_WIDTH:
|
2020-02-19 21:09:19 +00:00
|
|
|
framepositioner->user_positioned = TRUE;
|
2016-04-13 09:31:05 +00:00
|
|
|
framepositioner->width = g_value_get_int (value);
|
2016-08-02 20:42:20 +00:00
|
|
|
gst_frame_positioner_update_properties (framepositioner, track_mixing,
|
|
|
|
0, 0);
|
2013-08-21 09:32:45 +00:00
|
|
|
break;
|
2024-02-27 17:00:04 +00:00
|
|
|
case PROP_FWIDTH:
|
|
|
|
framepositioner->user_positioned = TRUE;
|
|
|
|
framepositioner->width = g_value_get_float (value);
|
|
|
|
gst_frame_positioner_update_properties (framepositioner, track_mixing,
|
|
|
|
0, 0);
|
|
|
|
break;
|
2013-08-21 09:32:45 +00:00
|
|
|
case PROP_HEIGHT:
|
2020-02-19 21:09:19 +00:00
|
|
|
framepositioner->user_positioned = TRUE;
|
2016-04-13 09:31:05 +00:00
|
|
|
framepositioner->height = g_value_get_int (value);
|
2016-08-02 20:42:20 +00:00
|
|
|
gst_frame_positioner_update_properties (framepositioner, track_mixing,
|
|
|
|
0, 0);
|
2013-08-21 09:32:45 +00:00
|
|
|
break;
|
2024-02-27 17:00:04 +00:00
|
|
|
case PROP_FHEIGHT:
|
|
|
|
framepositioner->user_positioned = TRUE;
|
|
|
|
framepositioner->height = g_value_get_float (value);
|
|
|
|
gst_frame_positioner_update_properties (framepositioner, track_mixing,
|
|
|
|
0, 0);
|
|
|
|
break;
|
2021-04-21 23:12:30 +00:00
|
|
|
case PROP_OPERATOR:
|
|
|
|
framepositioner->operator = g_value_get_enum (value);
|
|
|
|
gst_frame_positioner_update_properties (framepositioner, track_mixing,
|
|
|
|
0, 0);
|
|
|
|
break;
|
2013-06-03 21:02:15 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2016-04-13 09:31:05 +00:00
|
|
|
GST_OBJECT_UNLOCK (framepositioner);
|
2013-06-03 21:02:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-04-13 09:31:05 +00:00
|
|
|
gst_frame_positioner_get_property (GObject * object, guint property_id,
|
2013-06-03 21:02:15 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2016-04-13 09:31:05 +00:00
|
|
|
GstFramePositioner *pos = GST_FRAME_POSITIONNER (object);
|
2024-02-27 17:00:04 +00:00
|
|
|
gdouble real_width, real_height;
|
2013-06-03 21:02:15 +00:00
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_ALPHA:
|
2013-08-21 09:32:45 +00:00
|
|
|
g_value_set_double (value, pos->alpha);
|
2013-06-03 21:02:15 +00:00
|
|
|
break;
|
|
|
|
case PROP_POSX:
|
2020-04-17 00:27:30 +00:00
|
|
|
g_value_set_int (value, round (pos->posx));
|
2013-06-03 21:02:15 +00:00
|
|
|
break;
|
2024-02-27 17:00:04 +00:00
|
|
|
case PROP_FPOSX:
|
|
|
|
g_value_set_float (value, pos->posx);
|
|
|
|
break;
|
2013-06-03 21:02:15 +00:00
|
|
|
case PROP_POSY:
|
2020-04-17 00:27:30 +00:00
|
|
|
g_value_set_int (value, round (pos->posy));
|
2013-06-03 21:02:15 +00:00
|
|
|
break;
|
2024-02-27 17:00:04 +00:00
|
|
|
case PROP_FPOSY:
|
|
|
|
g_value_set_float (value, pos->posy);
|
|
|
|
break;
|
2013-06-03 21:02:15 +00:00
|
|
|
case PROP_ZORDER:
|
2013-08-21 09:32:45 +00:00
|
|
|
g_value_set_uint (value, pos->zorder);
|
|
|
|
break;
|
|
|
|
case PROP_WIDTH:
|
2020-02-20 15:28:59 +00:00
|
|
|
if (pos->scale_in_compositor) {
|
2020-04-17 00:27:30 +00:00
|
|
|
g_value_set_int (value, round (pos->width));
|
2020-02-20 15:28:59 +00:00
|
|
|
} else {
|
2024-02-27 17:00:04 +00:00
|
|
|
real_width = pos->width > 0 ? pos->width : pos->track_width;
|
|
|
|
g_value_set_int (value, round (real_width));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROP_FWIDTH:
|
|
|
|
if (pos->scale_in_compositor) {
|
|
|
|
g_value_set_float (value, pos->width);
|
|
|
|
} else {
|
|
|
|
real_width = pos->width > 0 ? pos->width : pos->track_width;
|
|
|
|
g_value_set_float (value, real_width);
|
2020-02-20 15:28:59 +00:00
|
|
|
}
|
2013-08-21 09:32:45 +00:00
|
|
|
break;
|
|
|
|
case PROP_HEIGHT:
|
2020-02-20 15:28:59 +00:00
|
|
|
if (pos->scale_in_compositor) {
|
2020-04-17 00:27:30 +00:00
|
|
|
g_value_set_int (value, round (pos->height));
|
2020-02-20 15:28:59 +00:00
|
|
|
} else {
|
2024-02-27 17:00:04 +00:00
|
|
|
real_height = pos->height > 0 ? pos->height : pos->track_height;
|
|
|
|
g_value_set_int (value, round (real_height));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROP_FHEIGHT:
|
|
|
|
if (pos->scale_in_compositor) {
|
|
|
|
g_value_set_float (value, pos->height);
|
|
|
|
} else {
|
|
|
|
real_height = pos->height > 0 ? pos->height : pos->track_height;
|
|
|
|
g_value_set_float (value, real_height);
|
2020-02-20 15:28:59 +00:00
|
|
|
}
|
2013-06-03 21:02:15 +00:00
|
|
|
break;
|
2021-04-21 23:12:30 +00:00
|
|
|
case PROP_OPERATOR:
|
|
|
|
g_value_set_enum (value, pos->operator);
|
|
|
|
break;
|
2013-06-03 21:02:15 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2016-04-13 09:31:05 +00:00
|
|
|
gst_frame_positioner_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
2013-06-03 21:02:15 +00:00
|
|
|
{
|
2023-11-13 16:14:01 +00:00
|
|
|
GESFrameCompositionMeta *meta;
|
2016-04-13 09:31:05 +00:00
|
|
|
GstFramePositioner *framepositioner = GST_FRAME_POSITIONNER (trans);
|
2018-10-28 15:55:23 +00:00
|
|
|
GstClockTime timestamp = GST_BUFFER_PTS (buf);
|
2013-06-03 21:02:15 +00:00
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
|
|
|
|
gst_object_sync_values (GST_OBJECT (trans), timestamp);
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:14:01 +00:00
|
|
|
meta = ges_buffer_add_frame_composition_meta (buf);
|
2016-04-13 09:31:05 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (framepositioner);
|
|
|
|
meta->alpha = framepositioner->alpha;
|
2024-02-27 17:00:04 +00:00
|
|
|
meta->posx = framepositioner->posx;
|
|
|
|
meta->posy = framepositioner->posy;
|
|
|
|
meta->width = framepositioner->width;
|
|
|
|
meta->height = framepositioner->height;
|
2016-04-13 09:31:05 +00:00
|
|
|
meta->zorder = framepositioner->zorder;
|
2021-04-21 23:12:30 +00:00
|
|
|
meta->operator = framepositioner->operator;
|
2016-04-13 09:31:05 +00:00
|
|
|
GST_OBJECT_UNLOCK (framepositioner);
|
2013-06-03 21:02:15 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2024-02-27 17:00:04 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_frame_positioner_check_can_add_binding (GstFramePositioner * self,
|
|
|
|
const gchar * property_name)
|
|
|
|
{
|
|
|
|
gint i = 0;
|
|
|
|
const gchar *checked_prop = NULL;
|
|
|
|
const gchar *props[][2] = {
|
|
|
|
{"posx", "fposx"},
|
|
|
|
{"posy", "fposy"},
|
|
|
|
{"width", "fwidth"},
|
|
|
|
{"height", "fheight"},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (props); i++) {
|
|
|
|
if (!g_strcmp0 (property_name, props[i][0])) {
|
|
|
|
checked_prop = props[i][1];
|
|
|
|
break;
|
|
|
|
} else if (!g_strcmp0 (property_name, props[i][1])) {
|
|
|
|
checked_prop = props[i][0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!checked_prop)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
GstControlBinding *b =
|
|
|
|
gst_object_get_control_binding (GST_OBJECT (self), checked_prop);
|
|
|
|
if (b) {
|
|
|
|
gst_object_unref (b);
|
|
|
|
GST_WARNING_OBJECT (self,
|
|
|
|
"Can't add control binding for %s as %s already has one", property_name,
|
|
|
|
checked_prop);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|