gstreamer/ges/ges-internal.h
Sjors Gielen 84f7f04a64 Handle changing playback rate
Before this patch, NLE and GES did not support NleOperations (respectively
GESEffects) that changed the speed/tempo/rate at which the source plays. For
example, the 'pitch' element can make audio play faster or slower. In GES 1.5.90
and before, an NleOperation containing the pitch element to change the rate (or
tempo) would cause a pipeline state change to PAUSED after that stack; that has
been fixed in 1.5.91 (see #755012 [0]). But even then, in 1.5.91 and later,
NleComposition would send segment events to its NleSources assuming that one
source second is equal to one pipeline second. The resulting early EOS event
(in the case of a source rate higher than 1.0) would cause it to switch stacks
too early, causing confusion in the timeline and spectacularly messed up
output.

This patch fixes that by searching for rate-changing elements in
GESTrackElements such as GESEffects. If such rate-changing elements are found,
their final effect on the playing rate is stored in the corresponding NleObject
as the 'media duration factor', named like this because the 'media duration',
or source duration, of an NleObject can be computed by multiplying the duration
with the media duration factor of that object and its parents (this is called
the 'recursive media duration factor'). For example, a 4-second NleSource with
an NleOperation with a media duration factor of 2.0 will have an 8-second media
duration, which means that for playing 4 seconds in the pipeline, the seek
event sent to it must span 8 seconds of media. (So, the 'duration' of an
NleObject or GES object always refers to its duration in the timeline, not the
media duration.)

To summarize:

* Rate-changing elements are registered in the GESEffectClass (pitch::tempo and
  pitch::rate are registered by default);
* GESTimelineElement is responsible for detecting rate-changing elements and
  computing the media_duration_factor;
* GESTrackElement is responsible for storing the media_duration_factor in
  NleObject;
* NleComposition is responsible for the recursive_media_duration_factor;
* The latter property finally fixes media time computations in NleObject.

NLE and GES tests are included.

[0] https://bugzilla.gnome.org/show_bug.cgi?id=755012

Differential Revision: https://phabricator.freedesktop.org/D276
2016-02-26 19:54:40 +01:00

398 lines
19 KiB
C

/* GStreamer Editing Services
* Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
* 2009 Nokia Corporation
*
* 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.
*/
#ifndef __GES_INTERNAL_H__
#define __GES_INTERNAL_H__
#include <gst/gst.h>
#include <gio/gio.h>
#include "ges-timeline.h"
#include "ges-track-element.h"
#include "ges-timeline-element.h"
#include "ges-asset.h"
#include "ges-base-xml-formatter.h"
GST_DEBUG_CATEGORY_EXTERN (_ges_debug);
#define GST_CAT_DEFAULT _ges_debug
/* The first 2 NLE priorities are used for:
* 0- The Mixing element
* 1- The Gaps
*/
#define MIN_NLE_PRIO 2
#define LAYER_HEIGHT 1000
#define _START(obj) GES_TIMELINE_ELEMENT_START (obj)
#define _INPOINT(obj) GES_TIMELINE_ELEMENT_INPOINT (obj)
#define _DURATION(obj) GES_TIMELINE_ELEMENT_DURATION (obj)
#define _MAXDURATION(obj) GES_TIMELINE_ELEMENT_MAX_DURATION (obj)
#define _PRIORITY(obj) GES_TIMELINE_ELEMENT_PRIORITY (obj)
#define _END(obj) (_START (obj) + _DURATION (obj))
#define _set_start0 ges_timeline_element_set_start
#define _set_inpoint0 ges_timeline_element_set_inpoint
#define _set_duration0 ges_timeline_element_set_duration
#define _set_priority0 ges_timeline_element_set_priority
#define GES_TIMELINE_ELEMENT_FORMAT \
"s:%p" \
" start: %" GST_TIME_FORMAT \
" inpoint: %" GST_TIME_FORMAT \
" duration: %" GST_TIME_FORMAT
#define GES_TIMELINE_ELEMENT_ARGS(element) \
GES_TIMELINE_ELEMENT_NAME(element), element, \
GST_TIME_ARGS(GES_TIMELINE_ELEMENT_START(element)), \
GST_TIME_ARGS(GES_TIMELINE_ELEMENT_INPOINT(element)), \
GST_TIME_ARGS(GES_TIMELINE_ELEMENT_DURATION(element))
G_GNUC_INTERNAL gboolean
timeline_ripple_object (GESTimeline *timeline, GESTrackElement *obj,
GList * layers, GESEdge edge,
guint64 position);
G_GNUC_INTERNAL gboolean
timeline_slide_object (GESTimeline *timeline, GESTrackElement *obj,
GList * layers, GESEdge edge, guint64 position);
G_GNUC_INTERNAL gboolean
timeline_roll_object (GESTimeline *timeline, GESTrackElement *obj,
GList * layers, GESEdge edge, guint64 position);
G_GNUC_INTERNAL gboolean
timeline_trim_object (GESTimeline *timeline, GESTrackElement * object,
GList * layers, GESEdge edge, guint64 position);
G_GNUC_INTERNAL gboolean
ges_timeline_trim_object_simple (GESTimeline * timeline, GESTimelineElement * obj,
GList * layers, GESEdge edge, guint64 position, gboolean snapping);
G_GNUC_INTERNAL gboolean
ges_timeline_move_object_simple (GESTimeline * timeline, GESTimelineElement * object,
GList * layers, GESEdge edge, guint64 position);
G_GNUC_INTERNAL gboolean
timeline_move_object (GESTimeline *timeline, GESTrackElement * object,
GList * layers, GESEdge edge, guint64 position);
G_GNUC_INTERNAL gboolean
timeline_context_to_layer (GESTimeline *timeline, gint offset);
G_GNUC_INTERNAL void
timeline_add_group (GESTimeline *timeline,
GESGroup *group);
G_GNUC_INTERNAL
void
timeline_remove_group (GESTimeline *timeline,
GESGroup *group);
G_GNUC_INTERNAL
gboolean
timeline_add_element (GESTimeline *timeline,
GESTimelineElement *element);
G_GNUC_INTERNAL
gboolean
timeline_remove_element (GESTimeline *timeline,
GESTimelineElement *element);
G_GNUC_INTERNAL
void
timeline_fill_gaps (GESTimeline *timeline);
G_GNUC_INTERNAL GList *
timeline_get_groups (GESTimeline * timeline);
G_GNUC_INTERNAL
void
track_resort_and_fill_gaps (GESTrack *track);
G_GNUC_INTERNAL
void
track_disable_last_gap (GESTrack *track, gboolean disabled);
G_GNUC_INTERNAL void
ges_asset_cache_init (void);
G_GNUC_INTERNAL void
ges_asset_set_id (GESAsset *asset, const gchar *id);
G_GNUC_INTERNAL void
ges_asset_cache_put (GESAsset * asset, GTask *task);
G_GNUC_INTERNAL gboolean
ges_asset_cache_set_loaded(GType extractable_type, const gchar * id, GError *error);
GESAsset*
ges_asset_cache_lookup(GType extractable_type, const gchar * id);
gboolean
ges_asset_try_proxy (GESAsset *asset, const gchar *new_id);
G_GNUC_INTERNAL gboolean
ges_asset_request_id_update (GESAsset *asset, gchar **proposed_id,
GError *error);
G_GNUC_INTERNAL gchar *
ges_effect_assect_id_get_type_and_bindesc (const char *id,
GESTrackType *track_type,
GError **error);
/* GESExtractable internall methods
*
* FIXME Check if that should be public later
*/
G_GNUC_INTERNAL GType
ges_extractable_type_get_asset_type (GType type);
G_GNUC_INTERNAL gchar *
ges_extractable_type_check_id (GType type, const gchar *id, GError **error);
G_GNUC_INTERNAL GParameter *
ges_extractable_type_get_parameters_from_id (GType type, const gchar *id,
guint *n_params);
G_GNUC_INTERNAL GType
ges_extractable_get_real_extractable_type_for_id (GType type, const gchar * id);
G_GNUC_INTERNAL gboolean
ges_extractable_register_metas (GType extractable_type, GESAsset *asset);
/************************************************
* *
* GESFormatter internal methods *
* *
************************************************/
G_GNUC_INTERNAL void
ges_formatter_set_project (GESFormatter *formatter,
GESProject *project);
G_GNUC_INTERNAL GESProject *
ges_formatter_get_project (GESFormatter *formatter);
G_GNUC_INTERNAL GESAsset *
_find_formatter_asset_for_id (const gchar *id);
/************************************************
* *
* GESProject internal methods *
* *
************************************************/
/* FIXME This should probably become public, but we need to make sure it
* is the right API before doing so */
G_GNUC_INTERNAL gboolean ges_project_set_loaded (GESProject * project,
GESFormatter *formatter);
G_GNUC_INTERNAL gchar * ges_project_try_updating_id (GESProject *self,
GESAsset *asset,
GError *error);
G_GNUC_INTERNAL void ges_project_add_loading_asset (GESProject *project,
GType extractable_type,
const gchar *id);
/************************************************
* *
* GESBaseXmlFormatter internal methods *
* *
************************************************/
/* FIXME GESBaseXmlFormatter is all internal for now, the API is not stable
* fo now, so do not expose it */
G_GNUC_INTERNAL void ges_base_xml_formatter_add_clip (GESBaseXmlFormatter * self,
const gchar *id,
const char *asset_id,
GType type,
GstClockTime start,
GstClockTime inpoint,
GstClockTime duration,
guint layer_prio,
GESTrackType track_types,
GstStructure *properties,
const gchar *metadatas,
GError **error);
G_GNUC_INTERNAL void ges_base_xml_formatter_add_asset (GESBaseXmlFormatter * self,
const gchar * id,
GType extractable_type,
GstStructure *properties,
const gchar *metadatas,
const gchar *proxy_id,
GError **error);
G_GNUC_INTERNAL void ges_base_xml_formatter_add_layer (GESBaseXmlFormatter *self,
GType extractable_type,
guint priority,
GstStructure *properties,
const gchar *metadatas,
GError **error);
G_GNUC_INTERNAL void ges_base_xml_formatter_add_track (GESBaseXmlFormatter *self,
GESTrackType track_type,
GstCaps *caps,
const gchar *id,
GstStructure *properties,
const gchar *metadatas,
GError **error);
G_GNUC_INTERNAL void ges_base_xml_formatter_add_encoding_profile(GESBaseXmlFormatter * self,
const gchar *type,
const gchar *parent,
const gchar * name,
const gchar * description,
GstCaps * format,
const gchar * preset,
const gchar * preset_name,
guint id,
guint presence,
GstCaps * restriction,
guint pass,
gboolean variableframerate,
GstStructure * properties,
gboolean enabled,
GError ** error);
G_GNUC_INTERNAL void ges_base_xml_formatter_add_track_element (GESBaseXmlFormatter *self,
GType effect_type,
const gchar *asset_id,
const gchar * track_id,
const gchar *timeline_obj_id,
GstStructure *children_properties,
GstStructure *properties,
const gchar *metadatas,
GError **error);
G_GNUC_INTERNAL void ges_base_xml_formatter_add_source (GESBaseXmlFormatter *self,
const gchar * track_id,
GstStructure *children_properties);
G_GNUC_INTERNAL void ges_base_xml_formatter_add_group (GESBaseXmlFormatter *self,
const gchar *name,
const gchar *properties);
G_GNUC_INTERNAL void ges_base_xml_formatter_last_group_add_child(GESBaseXmlFormatter *self,
const gchar * id,
const gchar * name);
G_GNUC_INTERNAL void ges_base_xml_formatter_add_control_binding (GESBaseXmlFormatter * self,
const gchar * binding_type,
const gchar * source_type,
const gchar * property_name,
gint mode,
const gchar *track_id,
GSList * timed_values);
G_GNUC_INTERNAL gboolean set_property_foreach (GQuark field_id,
const GValue * value,
GObject * object);;
/* Function to initialise GES */
G_GNUC_INTERNAL void _init_standard_transition_assets (void);
G_GNUC_INTERNAL void _init_formatter_assets (void);
/* Utilities */
G_GNUC_INTERNAL gint element_start_compare (GESTimelineElement * a,
GESTimelineElement * b);
G_GNUC_INTERNAL gint element_end_compare (GESTimelineElement * a,
GESTimelineElement * b);
G_GNUC_INTERNAL GstElementFactory *
ges_get_compositor_factory (void);
G_GNUC_INTERNAL void
ges_base_xml_formatter_set_timeline_properties(GESBaseXmlFormatter * self,
GESTimeline *timeline,
const gchar *properties,
const gchar *metadatas);
/****************************************************
* GESCommandLineFormatter *
****************************************************/
G_GNUC_INTERNAL GOptionGroup *
_ges_command_line_formatter_get_option_group (void);
/****************************************************
* GESContainer *
****************************************************/
G_GNUC_INTERNAL void _ges_container_sort_children (GESContainer *container);
G_GNUC_INTERNAL void _ges_container_sort_children_by_end (GESContainer *container);
/****************************************************
* GESClip *
****************************************************/
G_GNUC_INTERNAL void ges_clip_set_layer (GESClip *clip, GESLayer *layer);
G_GNUC_INTERNAL gboolean ges_clip_is_moving_from_layer (GESClip *clip);
G_GNUC_INTERNAL guint32 ges_clip_get_layer_priority (GESClip *clip);
G_GNUC_INTERNAL void ges_clip_set_moving_from_layer (GESClip *clip, gboolean is_moving);
G_GNUC_INTERNAL GESTrackElement* ges_clip_create_track_element (GESClip *clip, GESTrackType type);
G_GNUC_INTERNAL GList* ges_clip_create_track_elements (GESClip *clip, GESTrackType type);
/****************************************************
* GESTrackElement *
****************************************************/
#define NLE_OBJECT_TRACK_ELEMENT_QUARK (g_quark_from_string ("nle_object_track_element_quark"))
G_GNUC_INTERNAL gboolean ges_track_element_set_track (GESTrackElement * object, GESTrack * track);
G_GNUC_INTERNAL guint32 _ges_track_element_get_layer_priority (GESTrackElement * element);
G_GNUC_INTERNAL void ges_track_element_copy_properties (GESTimelineElement * element,
GESTimelineElement * elementcopy);
G_GNUC_INTERNAL void ges_track_element_copy_bindings (GESTrackElement *element,
GESTrackElement *new_element,
guint64 position);
G_GNUC_INTERNAL GstElement *ges_source_create_topbin (const gchar * bin_name, GstElement * sub_element, ...);
G_GNUC_INTERNAL void ges_track_set_caps (GESTrack *track,
const GstCaps *caps);
G_GNUC_INTERNAL GstElement * ges_track_get_composition (GESTrack *track);
/*********************************************
* GESTrackElement subclasses contructores *
********************************************/
G_GNUC_INTERNAL GESAudioTestSource * ges_audio_test_source_new (void);
G_GNUC_INTERNAL GESAudioUriSource * ges_audio_uri_source_new (gchar *uri);
G_GNUC_INTERNAL GESVideoUriSource * ges_video_uri_source_new (gchar *uri);
G_GNUC_INTERNAL GESImageSource * ges_image_source_new (gchar *uri);
G_GNUC_INTERNAL GESTitleSource * ges_title_source_new (void);
G_GNUC_INTERNAL GESVideoTestSource * ges_video_test_source_new (void);
/****************************************************
* GESTimelineElement *
****************************************************/
G_GNUC_INTERNAL gdouble ges_timeline_element_get_media_duration_factor(GESTimelineElement *self);
/******************************
* GESMultiFile internal API *
******************************/
typedef struct GESMultiFileURI
{
gchar *location;
gint start;
gint end;
} GESMultiFileURI;
G_GNUC_INTERNAL GESMultiFileURI * ges_multi_file_uri_new (const gchar * uri);
/************************
* Our property masks *
************************/
#define GES_PARAM_NO_SERIALIZATION (1 << (G_PARAM_USER_SHIFT + 1))
/********************
* Gnonlin helpers *
********************/
G_GNUC_INTERNAL gboolean ges_nle_composition_add_object (GstElement *comp, GstElement *object);
G_GNUC_INTERNAL gboolean ges_nle_composition_remove_object (GstElement *comp, GstElement *object);
G_GNUC_INTERNAL gboolean ges_nle_object_commit (GstElement * nlesource, gboolean recurse);
#endif /* __GES_INTERNAL_H__ */