ges: Expose FrameCompositionMeta in public API

Knowing the positioning and size of each frame in the composition can help
applications optimize their rendering pipeline.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5652>
This commit is contained in:
Philippe Normand 2023-11-13 16:14:01 +00:00 committed by GStreamer Marge Bot
parent 0afeacce92
commit d6c425fc58
9 changed files with 282 additions and 107 deletions

View file

@ -4459,6 +4459,43 @@ else FALSE.</doc>
</parameter>
</parameters>
</callback>
<record name="FrameCompositionMeta" c:type="GESFrameCompositionMeta" version="1.24">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.h">Metadata type that holds information about the positioning, size,
transparency and composition operator of a video frame in the timeline
composition.</doc>
<source-position filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.h"/>
<field name="meta" writable="1">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.h">the parent #GstMeta.</doc>
<type name="Gst.Meta" c:type="GstMeta"/>
</field>
<field name="alpha" writable="1">
<type name="gdouble" c:type="gdouble"/>
</field>
<field name="posx" writable="1">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.h">The desired x position.</doc>
<type name="gint" c:type="gint"/>
</field>
<field name="posy" writable="1">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.h">The desired y position.</doc>
<type name="gint" c:type="gint"/>
</field>
<field name="height" writable="1">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.h">The desired height of the video.</doc>
<type name="gint" c:type="gint"/>
</field>
<field name="width" writable="1">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.h">The desired width of the video.</doc>
<type name="gint" c:type="gint"/>
</field>
<field name="zorder" writable="1">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.h">The desired z order.</doc>
<type name="guint" c:type="guint"/>
</field>
<field name="operator" writable="1">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.h">The blending operator for the source.</doc>
<type name="gint" c:type="gint"/>
</field>
</record>
<class name="Group" c:symbol-prefix="group" c:type="GESGroup" parent="Container" glib:type-name="GESGroup" glib:get-type="ges_group_get_type" glib:type-struct="GroupClass">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges-group.c">A #GESGroup controls one or more #GESContainer-s (usually #GESClip-s,
but it can also control other #GESGroup-s). Its children must share
@ -16197,6 +16234,20 @@ for later use.</doc>
</parameter>
</parameters>
</function>
<function name="buffer_add_frame_composition_meta" c:identifier="ges_buffer_add_frame_composition_meta" version="1.24">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.c">Attaches positioning metadata to a #GstBuffer.</doc>
<source-position filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.h"/>
<return-value transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.c">a pointer to the added #GESFrameCompositionMeta.</doc>
<type name="FrameCompositionMeta" c:type="GESFrameCompositionMeta*"/>
</return-value>
<parameters>
<parameter name="buffer" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.c">#GstBuffer to which protection metadata should be added.</doc>
<type name="Gst.Buffer" c:type="GstBuffer*"/>
</parameter>
</parameters>
</function>
<function name="deinit" c:identifier="ges_deinit">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges.c">Clean up any resources created by GES in ges_init().
@ -16253,6 +16304,13 @@ formatter asset.</doc>
</parameter>
</parameters>
</function>
<function name="frame_composition_meta_api_get_type" c:identifier="ges_frame_composition_meta_api_get_type">
<attribute name="doc.skip" value="true"/>
<source-position filename="../subprojects/gst-editing-services/ges/ges-frame-composition-meta.h"/>
<return-value transfer-ownership="none">
<type name="GType" c:type="GType"/>
</return-value>
</function>
<docsection name="ges.h">
<doc xml:space="preserve" filename="../subprojects/gst-editing-services/ges/ges.c">GES needs to be initialized after GStreamer itself. This section
contains the various functions to do so.</doc>

View file

@ -23,6 +23,7 @@ gi-index
ges-effect-asset.h
ges-track-element-asset.h
ges-source-clip-asset.h
ges-frame-composition-meta.h
ges-effect.h
ges-extractable.h
ges-group.h

View file

@ -0,0 +1,135 @@
/* GStreamer
* Copyright (C) 2013 Mathieu Duponchelle <mduponchelle1@gmail.com>
* Copyright (C) 2013 Thibault Saunier <thibault.saunier@collabora.com>
* Copyright (C) 2020 Thibault Saunier <tsaunier@igalia.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.
*/
/**
* SECTION: gesframecompositionmeta
* @title: GESFrameCompositionMeta interface
* @short_description: A Meta providing positioning information for a given
* video frame
*
* Since: 1.24
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ges-frame-composition-meta.h"
#include "gstframepositioner.h"
static gboolean ges_frame_composition_meta_init (GstMeta * meta,
gpointer params, GstBuffer * buffer);
static gboolean ges_frame_composition_meta_transform (GstBuffer * dest,
GstMeta * meta, GstBuffer * buffer, GQuark type, gpointer data);
GType
ges_frame_composition_meta_api_get_type (void)
{
static GType type;
static const gchar *tags[] = { "video", NULL };
if (g_once_init_enter (&type)) {
GType _type = gst_meta_api_type_register ("GstFrameCompositionApi", tags);
g_once_init_leave (&type, _type);
}
return type;
}
static const GstMetaInfo *
ges_frame_composition_meta_get_info (void)
{
static const GstMetaInfo *meta_info = NULL;
if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
const GstMetaInfo *meta =
gst_meta_register (ges_frame_composition_meta_api_get_type (),
"GESFrameCompositionMeta",
sizeof (GESFrameCompositionMeta), ges_frame_composition_meta_init, NULL,
ges_frame_composition_meta_transform);
g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) meta);
}
return meta_info;
}
static gboolean
ges_frame_composition_meta_init (GstMeta * meta, gpointer params,
GstBuffer * buffer)
{
int default_operator_value = 0;
GESFrameCompositionMeta *smeta;
smeta = (GESFrameCompositionMeta *) meta;
gst_compositor_operator_get_type_and_default_value (&default_operator_value);
smeta->alpha = 0.0;
smeta->posx = smeta->posy = smeta->height = smeta->width = 0;
smeta->zorder = 0;
smeta->operator = default_operator_value;
return TRUE;
}
static gboolean
ges_frame_composition_meta_transform (GstBuffer * dest, GstMeta * meta,
GstBuffer * buffer, GQuark type, gpointer data)
{
GESFrameCompositionMeta *dmeta, *smeta;
smeta = (GESFrameCompositionMeta *) meta;
if (GST_META_TRANSFORM_IS_COPY (type)) {
/* only copy if the complete data is copied as well */
dmeta =
(GESFrameCompositionMeta *) gst_buffer_add_meta (dest,
ges_frame_composition_meta_get_info (), NULL);
dmeta->alpha = smeta->alpha;
dmeta->posx = smeta->posx;
dmeta->posy = smeta->posy;
dmeta->width = smeta->width;
dmeta->height = smeta->height;
dmeta->zorder = smeta->zorder;
dmeta->operator = smeta->operator;
}
return TRUE;
}
/**
* ges_buffer_add_frame_composition_meta:
* @buffer: #GstBuffer to which protection metadata should be added.
*
* Attaches positioning metadata to a #GstBuffer.
*
* Returns: (transfer none): a pointer to the added #GESFrameCompositionMeta.
*
* Since: 1.24
*/
GESFrameCompositionMeta *
ges_buffer_add_frame_composition_meta (GstBuffer * buffer)
{
GESFrameCompositionMeta *meta;
meta =
(GESFrameCompositionMeta *) gst_buffer_add_meta (buffer,
ges_frame_composition_meta_get_info (), NULL);
return meta;
}

View file

@ -0,0 +1,73 @@
/* GStreamer
* Copyright (C) 2013 Mathieu Duponchelle <mduponchelle1@gmail.com>
* Copyright (C) 2013 Thibault Saunier <thibault.saunier@collabora.com>
* Copyright (C) 2020 Thibault Saunier <tsaunier@igalia.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.
*/
#pragma once
#include <ges/ges-types.h>
#include <glib-object.h>
#include <gst/gst.h>
G_BEGIN_DECLS
/**
* ges_frame_composition_meta_api_get_type: (attributes doc.skip=true)
*/
GES_API
GType ges_frame_composition_meta_api_get_type (void);
/**
* GES_TYPE_META_FRAME_COMPOSITION: (attributes doc.skip=true)
*/
#define GES_TYPE_META_FRAME_COMPOSITION (ges_frame_composition_meta_api_get_type())
/**
* GESFrameCompositionMeta:
* @meta: the parent #GstMeta.
* @posx: The desired x position.
* @posy: The desired y position.
* @height: The desired height of the video.
* @width: The desired width of the video.
* @zorder: The desired z order.
* @operator:The blending operator for the source.
*
* Metadata type that holds information about the positioning, size,
* transparency and composition operator of a video frame in the timeline
* composition.
*
* Since: 1.24
*/
typedef struct _GESFrameCompositionMeta GESFrameCompositionMeta;
struct _GESFrameCompositionMeta {
GstMeta meta;
gdouble alpha;
gint posx;
gint posy;
gint height;
gint width;
guint zorder;
gint operator;
};
GES_API
GESFrameCompositionMeta * ges_buffer_add_frame_composition_meta (GstBuffer * buffer);
G_END_DECLS

View file

@ -21,6 +21,7 @@
#endif
#include "gstframepositioner.h"
#include "ges-frame-composition-meta.h"
#include "ges-types.h"
#include "ges-internal.h"
#include "ges-smart-video-mixer.h"
@ -204,19 +205,19 @@ ges_smart_mixer_get_mixer_pad (GESSmartMixer * self, GstPad ** mixerpad)
}
static void
set_pad_properties_from_positioner_meta (GstPad * mixer_pad, GstSample * sample,
GESSmartMixerPad * ghost)
set_pad_properties_from_composition_meta (GstPad * mixer_pad,
GstSample * sample, GESSmartMixerPad * ghost)
{
GstFramePositionerMeta *meta;
GESFrameCompositionMeta *meta;
GstBuffer *buf = gst_sample_get_buffer (sample);
GESSmartMixer *self = GES_SMART_MIXER (GST_OBJECT_PARENT (ghost));
meta =
(GstFramePositionerMeta *) gst_buffer_get_meta (buf,
gst_frame_positioner_meta_api_get_type ());
(GESFrameCompositionMeta *) gst_buffer_get_meta (buf,
GES_TYPE_META_FRAME_COMPOSITION);
if (!meta) {
GST_WARNING ("The current source should use a framepositioner");
GST_WARNING ("The current source should use a framecomposition");
return;
}
@ -373,7 +374,7 @@ compositor_sync_properties_with_meta (GstElement * compositor,
GST_AGGREGATOR_PAD (sinkpad));
if (sample) {
set_pad_properties_from_positioner_meta (sinkpad,
set_pad_properties_from_composition_meta (sinkpad,
sample, GES_SMART_MIXER_PAD (info->ghostpad));
gst_sample_unref (sample);
} else {

View file

@ -82,6 +82,7 @@
#include <ges/ges-gerror.h>
#include <ges/ges-audio-track.h>
#include <ges/ges-video-track.h>
#include <ges/ges-frame-composition-meta.h>
#include <ges/ges-version.h>
#include <ges/ges-marker-list.h>
#include <ges/ges-discoverer-manager.h>

View file

@ -26,6 +26,7 @@
#include <gst/video/video.h>
#include "gstframepositioner.h"
#include "ges-frame-composition-meta.h"
#include "ges-internal.h"
GST_DEBUG_CATEGORY_STATIC (_framepositioner);
@ -43,12 +44,6 @@ static void gst_frame_positioner_get_property (GObject * object,
static GstFlowReturn gst_frame_positioner_transform_ip (GstBaseTransform *
trans, GstBuffer * buf);
static gboolean
gst_frame_positioner_meta_init (GstMeta * meta, gpointer params,
GstBuffer * buffer);
static gboolean gst_frame_positioner_meta_transform (GstBuffer * dest,
GstMeta * meta, GstBuffer * buffer, GQuark type, gpointer data);
enum
{
PROP_0,
@ -693,84 +688,10 @@ gst_frame_positioner_get_property (GObject * object, guint property_id,
}
}
GType
gst_frame_positioner_meta_api_get_type (void)
{
static GType type;
static const gchar *tags[] = { "video", NULL };
if (g_once_init_enter (&type)) {
GType _type = gst_meta_api_type_register ("GstFramePositionerApi", tags);
g_once_init_leave (&type, _type);
}
return type;
}
static const GstMetaInfo *
gst_frame_positioner_get_info (void)
{
static const GstMetaInfo *meta_info = NULL;
if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
const GstMetaInfo *meta =
gst_meta_register (gst_frame_positioner_meta_api_get_type (),
"GstFramePositionerMeta",
sizeof (GstFramePositionerMeta), gst_frame_positioner_meta_init,
NULL,
gst_frame_positioner_meta_transform);
g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) meta);
}
return meta_info;
}
static gboolean
gst_frame_positioner_meta_init (GstMeta * meta, gpointer params,
GstBuffer * buffer)
{
int default_operator_value = 0;
GstFramePositionerMeta *smeta;
smeta = (GstFramePositionerMeta *) meta;
gst_compositor_operator_get_type_and_default_value (&default_operator_value);
smeta->alpha = 0.0;
smeta->posx = smeta->posy = smeta->height = smeta->width = 0;
smeta->zorder = 0;
smeta->operator = default_operator_value;
return TRUE;
}
static gboolean
gst_frame_positioner_meta_transform (GstBuffer * dest, GstMeta * meta,
GstBuffer * buffer, GQuark type, gpointer data)
{
GstFramePositionerMeta *dmeta, *smeta;
smeta = (GstFramePositionerMeta *) meta;
if (GST_META_TRANSFORM_IS_COPY (type)) {
/* only copy if the complete data is copied as well */
dmeta =
(GstFramePositionerMeta *) gst_buffer_add_meta (dest,
gst_frame_positioner_get_info (), NULL);
dmeta->alpha = smeta->alpha;
dmeta->posx = smeta->posx;
dmeta->posy = smeta->posy;
dmeta->width = smeta->width;
dmeta->height = smeta->height;
dmeta->zorder = smeta->zorder;
dmeta->operator = smeta->operator;
}
return TRUE;
}
static GstFlowReturn
gst_frame_positioner_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
GstFramePositionerMeta *meta;
GESFrameCompositionMeta *meta;
GstFramePositioner *framepositioner = GST_FRAME_POSITIONNER (trans);
GstClockTime timestamp = GST_BUFFER_PTS (buf);
@ -778,9 +699,7 @@ gst_frame_positioner_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
gst_object_sync_values (GST_OBJECT (trans), timestamp);
}
meta =
(GstFramePositionerMeta *) gst_buffer_add_meta (buf,
gst_frame_positioner_get_info (), NULL);
meta = ges_buffer_add_frame_composition_meta (buf);
GST_OBJECT_LOCK (framepositioner);
meta->alpha = framepositioner->alpha;

View file

@ -34,7 +34,6 @@ G_BEGIN_DECLS
typedef struct _GstFramePositioner GstFramePositioner;
typedef struct _GstFramePositionerClass GstFramePositionerClass;
typedef struct _GstFramePositionerMeta GstFramePositionerMeta;
struct _GstFramePositioner
{
@ -73,25 +72,11 @@ struct _GstFramePositionerClass
GstBaseTransformClass base_framepositioner_class;
};
struct _GstFramePositionerMeta {
GstMeta meta;
gdouble alpha;
gint posx;
gint posy;
gint height;
gint width;
guint zorder;
gint operator;
};
G_GNUC_INTERNAL GType gst_compositor_operator_get_type_and_default_value (int *default_operator_value);
G_GNUC_INTERNAL void ges_frame_positioner_set_source_and_filter (GstFramePositioner *pos,
GESTrackElement *trksrc,
GstElement *capsfilter);
G_GNUC_INTERNAL GType gst_frame_positioner_get_type (void);
G_GNUC_INTERNAL GType
gst_frame_positioner_meta_api_get_type (void);
G_END_DECLS

View file

@ -1,6 +1,7 @@
ges_sources = files([
'ges.c',
'ges-enums.c',
'ges-frame-composition-meta.c',
'ges-meta-container.c',
'ges-timeline.c',
'ges-layer.c',
@ -73,6 +74,7 @@ ges_headers = files([
'ges-types.h',
'ges.h',
'ges-prelude.h',
'ges-frame-composition-meta.h',
'ges-enums.h',
'ges-gerror.h',
'ges-meta-container.h',