ges: Add API to retrieve the natural framerate of an element

This commit is contained in:
Thibault Saunier 2020-02-18 15:21:38 -03:00
parent b93caf362c
commit bd33ed972c
11 changed files with 260 additions and 21 deletions

View file

@ -128,6 +128,17 @@ G_DEFINE_TYPE_WITH_CODE (GESAudioUriSource, ges_audio_uri_source,
/* GObject VMethods */
static gboolean
_get_natural_framerate (GESTimelineElement * self, gint * framerate_n,
gint * framerate_d)
{
if (self->parent)
return ges_timeline_element_get_natural_framerate (self->parent,
framerate_n, framerate_d);
return FALSE;
}
static void
ges_audio_uri_source_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
@ -177,6 +188,7 @@ static void
ges_audio_uri_source_class_init (GESAudioUriSourceClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GESTimelineElementClass *element_class = GES_TIMELINE_ELEMENT_CLASS (klass);
GESAudioSourceClass *source_class = GES_AUDIO_SOURCE_CLASS (klass);
object_class->get_property = ges_audio_uri_source_get_property;
@ -192,6 +204,8 @@ ges_audio_uri_source_class_init (GESAudioUriSourceClass * klass)
g_param_spec_string ("uri", "URI", "uri of the resource",
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
element_class->get_natural_framerate = _get_natural_framerate;
source_class->create_source = ges_audio_uri_source_create_source;
}

View file

@ -31,6 +31,8 @@
#endif
#include "ges-clip-asset.h"
#include "ges-source-clip.h"
#include "ges-internal.h"
#define GES_CLIP_ASSET_GET_PRIVATE(o)\
(G_TYPE_INSTANCE_GET_PRIVATE ((o), GES_TYPE_CLIP_ASSET, \
@ -172,3 +174,38 @@ ges_clip_asset_get_supported_formats (GESClipAsset * self)
return self->priv->supportedformats;
}
/**
* ges_clip_asset_get_natural_framerate:
* @self: The object from which to retrieve the natural framerate
* @framerate_n: The framerate numerator
* @framerate_d: The framerate denominator
*
* Result: %TRUE if @self has a natural framerate %FALSE otherwise
*/
gboolean
ges_clip_asset_get_natural_framerate (GESClipAsset * self,
gint * framerate_n, gint * framerate_d)
{
GESClipAssetClass *klass;
g_return_val_if_fail (GES_IS_CLIP_ASSET (self), FALSE);
g_return_val_if_fail (framerate_n && framerate_d, FALSE);
klass = GES_CLIP_ASSET_GET_CLASS (self);
*framerate_n = 0;
*framerate_d = -1;
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;
}

View file

@ -45,7 +45,9 @@ struct _GESClipAssetClass
{
GESAssetClass parent;
gpointer _ges_reserved[GES_PADDING];
gboolean (*get_natural_framerate) (GESClipAsset *self, gint *framerate_n, gint *framerate_d);
gpointer _ges_reserved[GES_PADDING - 1];
};
GES_API
@ -53,5 +55,7 @@ void ges_clip_asset_set_supported_formats (GESClipAsset *self,
GESTrackType supportedformats);
GES_API
GESTrackType ges_clip_asset_get_supported_formats (GESClipAsset *self);
GES_API
gboolean ges_clip_asset_get_natural_framerate (GESClipAsset* self, gint* framerate_n, gint* framerate_d);
G_END_DECLS

View file

@ -508,6 +508,22 @@ _get_layer_priority (GESTimelineElement * element)
return ges_layer_get_priority (clip->priv->layer);
}
static gboolean
_get_natural_framerate (GESTimelineElement * self, gint * framerate_n,
gint * framerate_d)
{
GESAsset *asset = ges_extractable_get_asset (GES_EXTRACTABLE (self));
if (!asset) {
GST_WARNING_OBJECT (self, "No asset set?");
return FALSE;
}
return ges_clip_asset_get_natural_framerate (GES_CLIP_ASSET (asset),
framerate_n, framerate_d);
}
/****************************************************
* *
* GESContainer virtual methods implementation *
@ -1138,6 +1154,7 @@ ges_clip_class_init (GESClipClass * klass)
element_class->deep_copy = _deep_copy;
element_class->lookup_child = _lookup_child;
element_class->get_layer_priority = _get_layer_priority;
element_class->get_natural_framerate = _get_natural_framerate;
container_class->add_child = _add_child;
container_class->remove_child = _remove_child;

View file

@ -358,6 +358,15 @@ _child_prop_handler_free (ChildPropHandler * handler)
g_slice_free (ChildPropHandler, handler);
}
static gboolean
_get_natural_framerate (GESTimelineElement * self, gint * framerate_n,
gint * framerate_d)
{
GST_INFO_OBJECT (self, "No natural framerate");
return FALSE;
}
static void
ges_timeline_element_init (GESTimelineElement * self)
{
@ -571,6 +580,7 @@ ges_timeline_element_class_init (GESTimelineElementClass * klass)
ges_timeline_element_get_children_properties;
klass->lookup_child = _lookup_child;
klass->set_child_property = _set_child_property;
klass->get_natural_framerate = _get_natural_framerate;
}
static void
@ -2492,3 +2502,41 @@ ges_timeline_element_edit (GESTimelineElement * self, GList * layers,
}
return FALSE;
}
/**
* ges_timeline_element_get_natural_framerate:
* @self: The #GESTimelineElement to get "natural" framerate from
* @framerate_n: (out): The framerate numerator
* @framerate_d: (out): The framerate denominator
*
* Get the "natural" framerate of @self. This is to say, for example
* for a #GESVideoUriSource the framerate of the source.
*
* Note that a #GESAudioSource may also have a natural framerate if it derives
* from the same #GESSourceClip asset as a #GESVideoSource, and its value will
* be that of the video source. For example, if the uri of a #GESUriClip points
* to a file that contains both a video and audio stream, then the corresponding
* #GESAudioUriSource will share the natural framerate of the corresponding
* #GESVideoUriSource.
*
* Returns: Whether @self has a natural framerate or not, @framerate_n
* and @framerate_d will be set to, respectively, 0 and -1 if it is
* not the case.
*
* Since: 1.18
*/
gboolean
ges_timeline_element_get_natural_framerate (GESTimelineElement * self,
gint * framerate_n, gint * framerate_d)
{
GESTimelineElementClass *klass;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (framerate_n && framerate_d, FALSE);
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
*framerate_n = 0;
*framerate_d = -1;
return klass->get_natural_framerate (self, framerate_n, framerate_d);
}

View file

@ -265,8 +265,9 @@ struct _GESTimelineElementClass
guint32 (*get_layer_priority) (GESTimelineElement *self);
/*< private > */
gboolean (*get_natural_framerate) (GESTimelineElement * self, gint *framerate_n, gint *framerate_d);
/* Padding for API extension */
gpointer _ges_reserved[GES_PADDING_LARGE - 4];
gpointer _ges_reserved[GES_PADDING_LARGE - 5];
};
GES_API
@ -379,6 +380,10 @@ GESTimelineElement * ges_timeline_element_paste (GESTimeli
GstClockTime paste_position);
GES_API
GESTrackType ges_timeline_element_get_track_types (GESTimelineElement * self);
GES_API
gboolean ges_timeline_element_get_natural_framerate (GESTimelineElement *self,
gint *framerate_n,
gint *framerate_d);
GES_API
guint32 ges_timeline_element_get_layer_priority (GESTimelineElement * self);

View file

@ -143,3 +143,31 @@ ges_track_element_asset_get_track_type (GESTrackElementAsset * asset)
return asset->priv->type;
}
/**
* ges_track_element_asset_get_natural_framerate:
* @self: A #GESAsset
* @framerate_n: The framerate numerator
* @framerate_d: The framerate denominator
*
* Result: %TRUE if @self has a natural framerate %FALSE otherwise
*/
gboolean
ges_track_element_asset_get_natural_framerate (GESTrackElementAsset * self,
gint * framerate_n, gint * framerate_d)
{
GESTrackElementAssetClass *klass;
g_return_val_if_fail (GES_IS_TRACK_ELEMENT_ASSET (self), FALSE);
g_return_val_if_fail (framerate_n && framerate_d, FALSE);
klass = GES_TRACK_ELEMENT_ASSET_GET_CLASS (self);
*framerate_n = 0;
*framerate_d = -1;
if (klass->get_natural_framerate)
return klass->get_natural_framerate (self, framerate_n, framerate_d);
return FALSE;
}

View file

@ -44,12 +44,18 @@ struct _GESTrackElementAssetClass
{
GESAssetClass parent_class;
gpointer _ges_reserved[GES_PADDING];
gboolean (*get_natural_framerate) (GESTrackElementAsset *self, gint *framerate_n, gint *framerate_d);
gpointer _ges_reserved[GES_PADDING - 1];
};
GES_API
const GESTrackType ges_track_element_asset_get_track_type (GESTrackElementAsset *asset);
GES_API
void ges_track_element_asset_set_track_type (GESTrackElementAsset * asset, GESTrackType type);
GES_API
gboolean ges_track_element_asset_get_natural_framerate (GESTrackElementAsset *self,
gint *framerate_n,
gint *framerate_d);
G_END_DECLS

View file

@ -144,6 +144,25 @@ _get_layer_priority (GESTimelineElement * element)
return ges_timeline_element_get_layer_priority (element->parent);
}
static gboolean
_get_natural_framerate (GESTimelineElement * self, gint * framerate_n,
gint * framerate_d)
{
GESAsset *asset = ges_extractable_get_asset (GES_EXTRACTABLE (self));
/* FIXME: asset should **never** be NULL */
if (asset &&
ges_track_element_asset_get_natural_framerate (GES_TRACK_ELEMENT_ASSET
(asset), framerate_n, framerate_d))
return TRUE;
if (self->parent)
return ges_timeline_element_get_natural_framerate (self->parent,
framerate_n, framerate_d);
return FALSE;
}
static void
ges_track_element_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
@ -430,6 +449,7 @@ ges_track_element_class_init (GESTrackElementClass * klass)
element_class->get_track_types = _get_track_types;
element_class->deep_copy = ges_track_element_copy_properties;
element_class->get_layer_priority = _get_layer_priority;
element_class->get_natural_framerate = _get_natural_framerate;
klass->create_gnl_object = ges_track_element_create_gnl_object_func;
klass->lookup_child = _lookup_child;

View file

@ -220,6 +220,52 @@ _request_id_update (GESAsset * self, gchar ** proposed_new_id, GError * error)
return FALSE;
}
static gboolean
ges_uri_source_asset_get_natural_framerate (GESTrackElementAsset * asset,
gint * framerate_n, gint * framerate_d)
{
GESUriSourceAssetPrivate *priv = GES_URI_SOURCE_ASSET (asset)->priv;
if (!GST_IS_DISCOVERER_VIDEO_INFO (priv->sinfo))
return FALSE;
*framerate_d =
gst_discoverer_video_info_get_framerate_denom (GST_DISCOVERER_VIDEO_INFO
(priv->sinfo));
*framerate_n =
gst_discoverer_video_info_get_framerate_num (GST_DISCOVERER_VIDEO_INFO
(priv->sinfo));
if ((*framerate_n == 0 && *framerate_d == 1) || *framerate_d == 0
|| *framerate_d == G_MAXINT) {
GST_INFO_OBJECT (asset, "No framerate information about the file.");
*framerate_n = 0;
*framerate_d = -1;
return FALSE;
}
return TRUE;
}
static gboolean
_get_natural_framerate (GESClipAsset * self, gint * framerate_n,
gint * framerate_d)
{
GList *tmp;
for (tmp = (GList *)
ges_uri_clip_asset_get_stream_assets (GES_URI_CLIP_ASSET (self)); tmp;
tmp = tmp->next) {
if (ges_track_element_asset_get_natural_framerate (tmp->data, framerate_n,
framerate_d))
return TRUE;
}
return FALSE;
}
static void
_asset_proxied (GESAsset * self, const gchar * new_uri)
{
@ -264,6 +310,8 @@ ges_uri_clip_asset_class_init (GESUriClipAssetClass * klass)
GES_ASSET_CLASS (klass)->request_id_update = _request_id_update;
GES_ASSET_CLASS (klass)->inform_proxy = _asset_proxied;
GES_CLIP_ASSET_CLASS (klass)->get_natural_framerate = _get_natural_framerate;
klass->discovered = discoverer_discovered_cb;
@ -802,6 +850,8 @@ ges_uri_source_asset_class_init (GESUriSourceAssetClass * klass)
object_class->dispose = ges_uri_source_asset_dispose;
GES_ASSET_CLASS (klass)->extract = _extract;
GES_TRACK_ELEMENT_ASSET_CLASS (klass)->get_natural_framerate =
ges_uri_source_asset_get_natural_framerate;
}
static void

View file

@ -114,6 +114,29 @@ ges_video_uri_source_needs_converters (GESVideoSource * source)
return FALSE;
}
static GstDiscovererVideoInfo *
_get_video_stream_info (GESVideoUriSource * self)
{
GstDiscovererStreamInfo *info;
GESAsset *asset = ges_extractable_get_asset (GES_EXTRACTABLE (self));
if (!asset) {
GST_DEBUG_OBJECT (self, "No asset set yet");
return NULL;
}
info = ges_uri_source_asset_get_stream_info (GES_URI_SOURCE_ASSET (asset));
if (!GST_IS_DISCOVERER_VIDEO_INFO (info)) {
GST_ERROR_OBJECT (self, "Doesn't have a video info (%" GST_PTR_FORMAT
")", info);
return NULL;
}
return GST_DISCOVERER_VIDEO_INFO (info);
}
gboolean
ges_video_uri_source_get_natural_size (GESVideoSource * source, gint * width,
gint * height)
@ -121,27 +144,14 @@ ges_video_uri_source_get_natural_size (GESVideoSource * source, gint * width,
const GstTagList *tags = NULL;
gchar *rotation_info = NULL;
gint videoflip_method, rotate_angle;
GstDiscovererStreamInfo *info;
GESAsset *asset = ges_extractable_get_asset (GES_EXTRACTABLE (source));
GstDiscovererVideoInfo *info =
_get_video_stream_info (GES_VIDEO_URI_SOURCE (source));
if (!asset) {
GST_DEBUG_OBJECT (source, "No asset set yet");
if (!info)
return FALSE;
}
info = ges_uri_source_asset_get_stream_info (GES_URI_SOURCE_ASSET (asset));
if (!GST_IS_DISCOVERER_VIDEO_INFO (info)) {
GST_ERROR_OBJECT (source, "Doesn't have a video info (%" GST_PTR_FORMAT
")", info);
return FALSE;
}
*width =
gst_discoverer_video_info_get_width (GST_DISCOVERER_VIDEO_INFO (info));
*height =
gst_discoverer_video_info_get_height (GST_DISCOVERER_VIDEO_INFO (info));
*width = gst_discoverer_video_info_get_width (info);
*height = gst_discoverer_video_info_get_height (info);
if (!ges_timeline_element_lookup_child (GES_TIMELINE_ELEMENT (source),
"GstVideoFlip::video-direction", NULL, NULL))
goto done;