From 13325aabdd9a63162704f33ff7876d479859c457 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 17 Mar 2020 11:53:47 -0300 Subject: [PATCH] ges: Add a SourceClipAsset class Cleaning up the way we use the default framerate for natural frame rate. --- ges/ges-clip-asset.c | 15 +++--------- ges/ges-source-clip-asset.c | 48 +++++++++++++++++++++++++++++++++++++ ges/ges-source-clip-asset.h | 40 +++++++++++++++++++++++++++++++ ges/ges-source-clip.c | 10 +++++++- ges/ges-test-clip.c | 7 +++--- ges/ges-uri-asset.c | 2 +- ges/ges-uri-asset.h | 6 ++--- ges/meson.build | 2 ++ 8 files changed, 110 insertions(+), 20 deletions(-) create mode 100644 ges/ges-source-clip-asset.c create mode 100644 ges/ges-source-clip-asset.h diff --git a/ges/ges-clip-asset.c b/ges/ges-clip-asset.c index 7fef08064d..deb279e30b 100644 --- a/ges/ges-clip-asset.c +++ b/ges/ges-clip-asset.c @@ -199,22 +199,13 @@ ges_clip_asset_get_natural_framerate (GESClipAsset * self, if (klass->get_natural_framerate) return klass->get_natural_framerate (self, framerate_n, framerate_d); - if (g_type_is_a (ges_asset_get_extractable_type (GES_ASSET (self)), - GES_TYPE_SOURCE_CLIP)) { - *framerate_n = DEFAULT_FRAMERATE_N; - *framerate_d = DEFAULT_FRAMERATE_D; - - return TRUE; - } - return FALSE; } /** * ges_clip_asset_get_frame_time: * @self: The object for which to compute timestamp for specifed frame - * @frame_number: The frame number we want the timestamp for the frame number - * inside the media scale of @self + * @frame_number: The frame number we want the internal time coordinate timestamp of * * Converts the given frame number into a timestamp, using the "natural" frame * rate of the asset. @@ -222,8 +213,8 @@ ges_clip_asset_get_natural_framerate (GESClipAsset * self, * You can use this to reference a specific frame in a media file and use this * as, for example, the `in-point` or `max-duration` of a #GESClip. * - * Returns: The timestamp corresponding to @frame_number in the element source - * in the media scale, or #GST_CLOCK_TIME_NONE if the clip asset does not have a + * Returns: The timestamp corresponding to @frame_number in the element source, given + * in internal time coordinates, or #GST_CLOCK_TIME_NONE if the clip asset does not have a * natural frame rate. */ GstClockTime diff --git a/ges/ges-source-clip-asset.c b/ges/ges-source-clip-asset.c new file mode 100644 index 0000000000..74169b25d7 --- /dev/null +++ b/ges/ges-source-clip-asset.c @@ -0,0 +1,48 @@ +/* GStreamer Editing Services + * Copyright (C) 2020 Igalia S.L + * Author: 2020 Thibault Saunier + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "ges-source-clip-asset.h" +#include "ges-internal.h" + +G_DEFINE_TYPE (GESSourceClipAsset, ges_source_clip_asset, GES_TYPE_CLIP_ASSET); + +static gboolean +get_natural_framerate (GESClipAsset * self, gint * framerate_n, + gint * framerate_d) +{ + *framerate_n = DEFAULT_FRAMERATE_N; + *framerate_d = DEFAULT_FRAMERATE_D; + return TRUE; +} + +static void +ges_source_clip_asset_class_init (GESSourceClipAssetClass * klass) +{ + GES_CLIP_ASSET_CLASS (klass)->get_natural_framerate = get_natural_framerate; +} + +static void +ges_source_clip_asset_init (GESSourceClipAsset * self) +{ +} diff --git a/ges/ges-source-clip-asset.h b/ges/ges-source-clip-asset.h new file mode 100644 index 0000000000..1ecfa20460 --- /dev/null +++ b/ges/ges-source-clip-asset.h @@ -0,0 +1,40 @@ +/* GStreamer Editing Services + * Copyright (C) 2020 Igalia S.L + * Author: 2020 Thibault Saunier + * + * 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. + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define GES_TYPE_SOURCE_CLIP_ASSET ges_source_clip_asset_get_type () + +GES_API +G_DECLARE_DERIVABLE_TYPE(GESSourceClipAsset, ges_source_clip_asset, GES, + SOURCE_CLIP_ASSET, GESClipAsset); + +struct _GESSourceClipAssetClass +{ + GESClipAssetClass parent_class; + /* FIXME 2.0: Add some padding, meanwhile that would break ABI */ +}; + + +G_END_DECLS \ No newline at end of file diff --git a/ges/ges-source-clip.c b/ges/ges-source-clip.c index 322072f389..f72d6e4fa2 100644 --- a/ges/ges-source-clip.c +++ b/ges/ges-source-clip.c @@ -53,7 +53,15 @@ enum PROP_0, }; -G_DEFINE_TYPE_WITH_PRIVATE (GESSourceClip, ges_source_clip, GES_TYPE_CLIP); +static void +extractable_interface_init (GESExtractableInterface * iface) +{ + iface->asset_type = GES_TYPE_SOURCE_CLIP_ASSET; +} + +G_DEFINE_TYPE_WITH_CODE (GESSourceClip, ges_source_clip, + GES_TYPE_CLIP, G_ADD_PRIVATE (GESSourceClip) + G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE, extractable_interface_init)); static void ges_source_clip_get_property (GObject * object, guint property_id, diff --git a/ges/ges-test-clip.c b/ges/ges-test-clip.c index 36257ed854..9d8063ef4a 100644 --- a/ges/ges-test-clip.c +++ b/ges/ges-test-clip.c @@ -52,11 +52,11 @@ #define DEFAULT_VPATTERN GES_VIDEO_TEST_PATTERN_SMPTE G_DECLARE_FINAL_TYPE (GESTestClipAsset, ges_test_clip_asset, GES, - TEST_CLIP_ASSET, GESClipAsset); + TEST_CLIP_ASSET, GESSourceClipAsset); struct _GESTestClipAsset { - GESClipAsset parent; + GESSourceClipAsset parent; gint natural_framerate_n; gint natural_framerate_d; @@ -66,7 +66,8 @@ struct _GESTestClipAsset }; #define GES_TYPE_TEST_CLIP_ASSET (ges_test_clip_asset_get_type()) -G_DEFINE_TYPE (GESTestClipAsset, ges_test_clip_asset, GES_TYPE_CLIP_ASSET); +G_DEFINE_TYPE (GESTestClipAsset, ges_test_clip_asset, + GES_TYPE_SOURCE_CLIP_ASSET); static gboolean _get_natural_framerate (GESClipAsset * asset, gint * framerate_n, diff --git a/ges/ges-uri-asset.c b/ges/ges-uri-asset.c index f37407c7eb..d0011f1fac 100644 --- a/ges/ges-uri-asset.c +++ b/ges/ges-uri-asset.c @@ -126,7 +126,7 @@ struct _GESUriSourceAssetPrivate }; G_DEFINE_TYPE_WITH_CODE (GESUriClipAsset, ges_uri_clip_asset, - GES_TYPE_CLIP_ASSET, G_ADD_PRIVATE (GESUriClipAsset) + GES_TYPE_SOURCE_CLIP_ASSET, G_ADD_PRIVATE (GESUriClipAsset) G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)); static void diff --git a/ges/ges-uri-asset.h b/ges/ges-uri-asset.h index 4b17fe2d34..db559710c4 100644 --- a/ges/ges-uri-asset.h +++ b/ges/ges-uri-asset.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include G_BEGIN_DECLS @@ -34,7 +34,7 @@ GES_DECLARE_TYPE(UriClipAsset, uri_clip_asset, URI_CLIP_ASSET); struct _GESUriClipAsset { - GESClipAsset parent; + GESSourceClipAsset parent; /* */ GESUriClipAssetPrivate *priv; @@ -45,7 +45,7 @@ struct _GESUriClipAsset struct _GESUriClipAssetClass { - GESClipAssetClass parent_class; + GESSourceClipAssetClass parent_class; /* */ GstDiscoverer *discoverer; /* Unused */ diff --git a/ges/meson.build b/ges/meson.build index d7edd8256e..c50cdfd1cd 100644 --- a/ges/meson.build +++ b/ges/meson.build @@ -7,6 +7,7 @@ ges_sources = files([ 'ges-clip.c', 'ges-pipeline.c', 'ges-source-clip.c', + 'ges-source-clip-asset.c', 'ges-base-effect-clip.c', 'ges-effect-clip.c', 'ges-uri-clip.c', @@ -77,6 +78,7 @@ ges_headers = files([ 'ges-clip.h', 'ges-pipeline.h', 'ges-source-clip.h', + 'ges-source-clip-asset.h', 'ges-uri-clip.h', 'ges-base-effect-clip.h', 'ges-effect-clip.h',