validate: Allow overriding ges-launch options through scenarios

In 99c45d42cf we allowed setting
track-types but in the end we could do it generically using the
following synthax in the scenario 'properties' metadata:

`ges-options={--track-types=video,--disable-mixing}`
This commit is contained in:
Thibault Saunier 2020-02-04 17:07:39 -03:00
parent 82159882d7
commit 1a111e95eb
4 changed files with 146 additions and 104 deletions

View file

@ -32,30 +32,6 @@
#include "ges-validate.h" #include "ges-validate.h"
#include "utils.h" #include "utils.h"
typedef struct
{
gboolean mute;
gboolean disable_mixing;
gchar *save_path;
gchar *save_only_path;
gchar *load_path;
GESTrackType track_types;
gboolean needs_set_state;
gboolean smartrender;
gchar *scenario;
gchar *format;
gchar *outputuri;
gchar *encoding_profile;
gchar *videosink;
gchar *audiosink;
gboolean list_transitions;
gboolean inspect_action_type;
gchar *sanitized_timeline;
const gchar *video_track_caps;
const gchar *audio_track_caps;
gboolean embed_nesteds;
} ParsedOptions;
struct _GESLauncherPrivate struct _GESLauncherPrivate
{ {
GESTimeline *timeline; GESTimeline *timeline;
@ -64,7 +40,7 @@ struct _GESLauncherPrivate
#ifdef G_OS_UNIX #ifdef G_OS_UNIX
guint signal_watch_id; guint signal_watch_id;
#endif #endif
ParsedOptions parsed_options; GESLauncherParsedOptions parsed_options;
}; };
G_DEFINE_TYPE_WITH_PRIVATE (GESLauncher, ges_launcher, G_TYPE_APPLICATION); G_DEFINE_TYPE_WITH_PRIVATE (GESLauncher, ges_launcher, G_TYPE_APPLICATION);
@ -82,10 +58,8 @@ static const gchar *HELP_SUMMARY =
static gboolean static gboolean
_parse_track_type (const gchar * option_name, const gchar * value, _parse_track_type (const gchar * option_name, const gchar * value,
GESLauncher * self, GError ** error) GESLauncherParsedOptions * opts, GError ** error)
{ {
ParsedOptions *opts = &self->priv->parsed_options;
if (!get_flags_from_string (GES_TYPE_TRACK_TYPE, value, &opts->track_types)) if (!get_flags_from_string (GES_TYPE_TRACK_TYPE, value, &opts->track_types))
return FALSE; return FALSE;
@ -116,7 +90,7 @@ _set_track_restriction_caps (GESTrack * track, const gchar * caps_str)
} }
static void static void
_set_restriction_caps (GESTimeline * timeline, ParsedOptions * opts) _set_restriction_caps (GESTimeline * timeline, GESLauncherParsedOptions * opts)
{ {
GList *tmp, *tracks = ges_timeline_get_tracks (timeline); GList *tmp, *tracks = ges_timeline_get_tracks (timeline);
@ -138,7 +112,7 @@ _timeline_set_user_options (GESLauncher * self, GESTimeline * timeline,
GList *tmp; GList *tmp;
GESTrack *tracka, *trackv; GESTrack *tracka, *trackv;
gboolean has_audio = FALSE, has_video = FALSE; gboolean has_audio = FALSE, has_video = FALSE;
ParsedOptions *opts = &self->priv->parsed_options; GESLauncherParsedOptions *opts = &self->priv->parsed_options;
retry: retry:
for (tmp = timeline->tracks; tmp; tmp = tmp->next) { for (tmp = timeline->tracks; tmp; tmp = tmp->next) {
@ -205,7 +179,7 @@ _project_loaded_cb (GESProject * project, GESTimeline * timeline,
GESLauncher * self) GESLauncher * self)
{ {
gchar *project_uri = NULL; gchar *project_uri = NULL;
ParsedOptions *opts = &self->priv->parsed_options; GESLauncherParsedOptions *opts = &self->priv->parsed_options;
GST_INFO ("Project loaded, playing it"); GST_INFO ("Project loaded, playing it");
if (opts->save_path) { if (opts->save_path) {
@ -237,8 +211,7 @@ _project_loaded_cb (GESProject * project, GESTimeline * timeline,
if (self->priv->parsed_options.load_path && project_uri if (self->priv->parsed_options.load_path && project_uri
&& ges_validate_activate (GST_PIPELINE (self->priv->pipeline), && ges_validate_activate (GST_PIPELINE (self->priv->pipeline),
&opts->track_types, opts->scenario, opts) == FALSE) {
&opts->needs_set_state) == FALSE) {
g_error ("Could not activate scenario %s", opts->scenario); g_error ("Could not activate scenario %s", opts->scenario);
self->priv->seenerrors = TRUE; self->priv->seenerrors = TRUE;
g_application_quit (G_APPLICATION (self)); g_application_quit (G_APPLICATION (self));
@ -325,7 +298,7 @@ _set_sink (GESLauncher * self, const gchar * sink_desc,
static gboolean static gboolean
_set_playback_details (GESLauncher * self) _set_playback_details (GESLauncher * self)
{ {
ParsedOptions *opts = &self->priv->parsed_options; GESLauncherParsedOptions *opts = &self->priv->parsed_options;
if (!_set_sink (self, opts->videosink, ges_pipeline_preview_set_video_sink) || if (!_set_sink (self, opts->videosink, ges_pipeline_preview_set_video_sink) ||
!_set_sink (self, opts->audiosink, ges_pipeline_preview_set_audio_sink)) !_set_sink (self, opts->audiosink, ges_pipeline_preview_set_audio_sink))
@ -409,7 +382,7 @@ intr_handler (GESLauncher * self)
static gboolean static gboolean
_save_timeline (GESLauncher * self) _save_timeline (GESLauncher * self)
{ {
ParsedOptions *opts = &self->priv->parsed_options; GESLauncherParsedOptions *opts = &self->priv->parsed_options;
if (opts->embed_nesteds) { if (opts->embed_nesteds) {
@ -464,12 +437,11 @@ static gboolean
_run_pipeline (GESLauncher * self) _run_pipeline (GESLauncher * self)
{ {
GstBus *bus; GstBus *bus;
ParsedOptions *opts = &self->priv->parsed_options; GESLauncherParsedOptions *opts = &self->priv->parsed_options;
if (!opts->load_path) { if (!opts->load_path) {
if (ges_validate_activate (GST_PIPELINE (self->priv->pipeline), if (ges_validate_activate (GST_PIPELINE (self->priv->pipeline),
&opts->track_types, opts->scenario, opts) == FALSE) {
&opts->needs_set_state) == FALSE) {
g_error ("Could not activate scenario %s", opts->scenario); g_error ("Could not activate scenario %s", opts->scenario);
return FALSE; return FALSE;
} }
@ -500,7 +472,7 @@ _run_pipeline (GESLauncher * self)
static gboolean static gboolean
_set_rendering_details (GESLauncher * self) _set_rendering_details (GESLauncher * self)
{ {
ParsedOptions *opts = &self->priv->parsed_options; GESLauncherParsedOptions *opts = &self->priv->parsed_options;
/* Setup profile/encoding if needed */ /* Setup profile/encoding if needed */
if (opts->outputuri) { if (opts->outputuri) {
@ -567,7 +539,7 @@ _create_pipeline (GESLauncher * self, const gchar * serialized_timeline)
{ {
gchar *uri = NULL; gchar *uri = NULL;
gboolean res = TRUE; gboolean res = TRUE;
ParsedOptions *opts = &self->priv->parsed_options; GESLauncherParsedOptions *opts = &self->priv->parsed_options;
/* Timeline creation */ /* Timeline creation */
if (opts->load_path) { if (opts->load_path) {
@ -642,10 +614,9 @@ _print_transition_list (void)
} }
static GOptionGroup * static GOptionGroup *
ges_launcher_get_project_option_group (GESLauncher * self) ges_launcher_get_project_option_group (GESLauncherParsedOptions * opts)
{ {
GOptionGroup *group; GOptionGroup *group;
ParsedOptions *opts = &self->priv->parsed_options;
GOptionEntry options[] = { GOptionEntry options[] = {
{"load", 'l', 0, G_OPTION_ARG_STRING, &opts->load_path, {"load", 'l', 0, G_OPTION_ARG_STRING, &opts->load_path,
@ -671,10 +642,9 @@ ges_launcher_get_project_option_group (GESLauncher * self)
} }
static GOptionGroup * static GOptionGroup *
ges_launcher_get_info_option_group (GESLauncher * self) ges_launcher_get_info_option_group (GESLauncherParsedOptions * opts)
{ {
GOptionGroup *group; GOptionGroup *group;
ParsedOptions *opts = &self->priv->parsed_options;
GOptionEntry options[] = { GOptionEntry options[] = {
#ifdef HAVE_GST_VALIDATE #ifdef HAVE_GST_VALIDATE
@ -700,10 +670,9 @@ ges_launcher_get_info_option_group (GESLauncher * self)
} }
static GOptionGroup * static GOptionGroup *
ges_launcher_get_rendering_option_group (GESLauncher * self) ges_launcher_get_rendering_option_group (GESLauncherParsedOptions * opts)
{ {
GOptionGroup *group; GOptionGroup *group;
ParsedOptions *opts = &self->priv->parsed_options;
GOptionEntry options[] = { GOptionEntry options[] = {
{"outputuri", 'o', 0, G_OPTION_ARG_STRING, &opts->outputuri, {"outputuri", 'o', 0, G_OPTION_ARG_STRING, &opts->outputuri,
@ -734,10 +703,9 @@ ges_launcher_get_rendering_option_group (GESLauncher * self)
} }
static GOptionGroup * static GOptionGroup *
ges_launcher_get_playback_option_group (GESLauncher * self) ges_launcher_get_playback_option_group (GESLauncherParsedOptions * opts)
{ {
GOptionGroup *group; GOptionGroup *group;
ParsedOptions *opts = &self->priv->parsed_options;
GOptionEntry options[] = { GOptionEntry options[] = {
{"videosink", 'v', 0, G_OPTION_ARG_STRING, &opts->videosink, {"videosink", 'v', 0, G_OPTION_ARG_STRING, &opts->videosink,
@ -757,30 +725,43 @@ ges_launcher_get_playback_option_group (GESLauncher * self)
return group; return group;
} }
static gboolean gboolean
_local_command_line (GApplication * application, gchar ** arguments[], ges_launcher_parse_options (GESLauncherParsedOptions * opts, gchar ** arguments,
gint * exit_status) gint * argc, GOptionContext * ctx, GError ** error)
{ {
GESLauncher *self = GES_LAUNCHER (application); gboolean res;
GError *error = NULL;
gchar **argv; gchar **argv;
gint argc;
GOptionContext *ctx;
ParsedOptions *opts = &self->priv->parsed_options;
GOptionGroup *main_group; GOptionGroup *main_group;
gint nargs = 0; gint nargs = 0, tmpargc;
gchar **commands = NULL, *help, *tmp; gchar **commands = NULL, *help, *tmp;
GError *err = NULL;
GOptionEntry options[] = { GOptionEntry options[] = {
{"disable-mixing", 0, 0, G_OPTION_ARG_NONE, &opts->disable_mixing, {"disable-mixing", 0, 0, G_OPTION_ARG_NONE, &opts->disable_mixing,
"Do not use mixing elements to mix layers together.", NULL}, "Do not use mixing elements to mix layers together.", NULL}
,
{"track-types", 't', 0, G_OPTION_ARG_CALLBACK, &_parse_track_type, {"track-types", 't', 0, G_OPTION_ARG_CALLBACK, &_parse_track_type,
"Specify the track types to be created. " "Specify the track types to be created. "
"When loading a project, only relevant tracks will be added to the timeline.", "When loading a project, only relevant tracks will be added to the timeline.",
"<track-types>"}, "<track-types>"}
{"video-caps", 0, 0, G_OPTION_ARG_STRING, &opts->video_track_caps, ,
"Specify the track restriction caps of the video track.",}, {
{"audio-caps", 0, 0, G_OPTION_ARG_STRING, &opts->audio_track_caps, "video-caps",
"Specify the track restriction caps of the audio track.",}, 0,
0,
G_OPTION_ARG_STRING,
&opts->video_track_caps,
"Specify the track restriction caps of the video track.",
}
,
{
"audio-caps",
0,
0,
G_OPTION_ARG_STRING,
&opts->audio_track_caps,
"Specify the track restriction caps of the audio track.",
}
,
#ifdef HAVE_GST_VALIDATE #ifdef HAVE_GST_VALIDATE
{"set-scenario", 0, 0, G_OPTION_ARG_STRING, &opts->scenario, {"set-scenario", 0, 0, G_OPTION_ARG_STRING, &opts->scenario,
"ges-launch-1.0 exposes gst-validate functionalities, such as scenarios." "ges-launch-1.0 exposes gst-validate functionalities, such as scenarios."
@ -788,19 +769,28 @@ _local_command_line (GApplication * application, gchar ** arguments[],
"GES implements editing-specific actions such as adding or removing clips. " "GES implements editing-specific actions such as adding or removing clips. "
"See gst-validate-1.0 --help for more info about validate and scenarios, " "See gst-validate-1.0 --help for more info about validate and scenarios, "
"and --inspect-action-type.", "and --inspect-action-type.",
"<scenario_name>"}, "<scenario_name>"}
,
#endif #endif
{"embed-nesteds", 0, 0, G_OPTION_ARG_NONE, &opts->embed_nesteds, {
"Embed nested timelines when saving.",}, "embed-nesteds",
0,
0,
G_OPTION_ARG_NONE,
&opts->embed_nesteds,
"Embed nested timelines when saving.",
}
,
{NULL} {NULL}
}; };
ctx = g_option_context_new ("- plays or renders a timeline."); if (!ctx)
argv = *arguments; ctx = g_option_context_new ("- plays or renders a timeline.");
argc = g_strv_length (argv); argv = arguments;
tmpargc = g_strv_length (argv);
if (argc > 2) { if (tmpargc > 2) {
nargs = argc - 2; nargs = tmpargc - 2;
commands = &argv[2]; commands = &argv[2];
} }
@ -814,24 +804,47 @@ _local_command_line (GApplication * application, gchar ** arguments[],
main_group = main_group =
g_option_group_new ("launcher", "launcher options", g_option_group_new ("launcher", "launcher options",
"Main launcher options", self, NULL); "Main launcher options", opts, NULL);
g_option_group_add_entries (main_group, options); g_option_group_add_entries (main_group, options);
g_option_context_set_main_group (ctx, main_group); g_option_context_set_main_group (ctx, main_group);
g_option_context_add_group (ctx, gst_init_get_option_group ()); g_option_context_add_group (ctx, gst_init_get_option_group ());
g_option_context_add_group (ctx, ges_init_get_option_group ()); g_option_context_add_group (ctx, ges_init_get_option_group ());
g_option_context_add_group (ctx, g_option_context_add_group (ctx,
ges_launcher_get_project_option_group (self)); ges_launcher_get_project_option_group (opts));
g_option_context_add_group (ctx, g_option_context_add_group (ctx,
ges_launcher_get_rendering_option_group (self)); ges_launcher_get_rendering_option_group (opts));
g_option_context_add_group (ctx, g_option_context_add_group (ctx,
ges_launcher_get_playback_option_group (self)); ges_launcher_get_playback_option_group (opts));
g_option_context_add_group (ctx, ges_launcher_get_info_option_group (self)); g_option_context_add_group (ctx, ges_launcher_get_info_option_group (opts));
g_option_context_set_ignore_unknown_options (ctx, TRUE); g_option_context_set_ignore_unknown_options (ctx, TRUE);
res = g_option_context_parse (ctx, &tmpargc, &argv, &err);
if (argc)
*argc = tmpargc;
if (err)
g_propagate_error (error, err);
return res;
}
static gboolean
_local_command_line (GApplication * application, gchar ** arguments[],
gint * exit_status)
{
gchar **argv;
gint argc;
GError *error = NULL;
GESLauncher *self = GES_LAUNCHER (application);
GESLauncherParsedOptions *opts = &self->priv->parsed_options;
GOptionContext *ctx = g_option_context_new ("- plays or renders a timeline.");
*exit_status = 0; *exit_status = 0;
argv = *arguments;
argc = g_strv_length (argv);
gst_init (&argc, &argv); gst_init (&argc, &argv);
if (!g_option_context_parse (ctx, &argc, &argv, &error)) { if (!ges_launcher_parse_options (opts, *arguments, &argc, ctx, &error)) {
gst_init (NULL, NULL); gst_init (NULL, NULL);
printerr ("Error initializing: %s\n", error->message); printerr ("Error initializing: %s\n", error->message);
g_option_context_free (ctx); g_option_context_free (ctx);
@ -870,7 +883,7 @@ static void
_startup (GApplication * application) _startup (GApplication * application)
{ {
GESLauncher *self = GES_LAUNCHER (application); GESLauncher *self = GES_LAUNCHER (application);
ParsedOptions *opts = &self->priv->parsed_options; GESLauncherParsedOptions *opts = &self->priv->parsed_options;
#ifdef G_OS_UNIX #ifdef G_OS_UNIX
self->priv->signal_watch_id = self->priv->signal_watch_id =
@ -919,7 +932,7 @@ _shutdown (GApplication * application)
{ {
gint validate_res = 0; gint validate_res = 0;
GESLauncher *self = GES_LAUNCHER (application); GESLauncher *self = GES_LAUNCHER (application);
ParsedOptions *opts = &self->priv->parsed_options; GESLauncherParsedOptions *opts = &self->priv->parsed_options;
_save_timeline (self); _save_timeline (self);

View file

@ -45,6 +45,30 @@ typedef struct _GESLauncherPrivate GESLauncherPrivate;
typedef struct _GESLauncher GESLauncher; typedef struct _GESLauncher GESLauncher;
typedef struct _GESLauncherClass GESLauncherClass; typedef struct _GESLauncherClass GESLauncherClass;
typedef struct
{
gboolean mute;
gboolean disable_mixing;
gchar *save_path;
gchar *save_only_path;
gchar *load_path;
GESTrackType track_types;
gboolean needs_set_state;
gboolean smartrender;
gchar *scenario;
gchar *format;
gchar *outputuri;
gchar *encoding_profile;
gchar *videosink;
gchar *audiosink;
gboolean list_transitions;
gboolean inspect_action_type;
gchar *sanitized_timeline;
const gchar *video_track_caps;
const gchar *audio_track_caps;
gboolean embed_nesteds;
} GESLauncherParsedOptions;
struct _GESLauncher { struct _GESLauncher {
GApplication parent; GApplication parent;
@ -67,6 +91,7 @@ GType ges_launcher_get_type (void);
GESLauncher* ges_launcher_new (void); GESLauncher* ges_launcher_new (void);
gint ges_launcher_get_exit_status (GESLauncher *self); gint ges_launcher_get_exit_status (GESLauncher *self);
gboolean ges_launcher_parse_options(GESLauncherParsedOptions* opts, gchar** arguments, gint *argc, GOptionContext* ctx, GError** error);
G_END_DECLS G_END_DECLS

View file

@ -101,8 +101,7 @@ ges_validate_register_issues (void)
} }
gboolean gboolean
ges_validate_activate (GstPipeline * pipeline, GESTrackType * track_types, ges_validate_activate (GstPipeline * pipeline, GESLauncherParsedOptions * opts)
const gchar * scenario, gboolean * needs_setting_state)
{ {
GstValidateRunner *runner = NULL; GstValidateRunner *runner = NULL;
GstValidateMonitor *monitor = NULL; GstValidateMonitor *monitor = NULL;
@ -110,9 +109,10 @@ ges_validate_activate (GstPipeline * pipeline, GESTrackType * track_types,
ges_validate_register_action_types (); ges_validate_register_action_types ();
ges_validate_register_issues (); ges_validate_register_issues ();
if (scenario) { if (opts->scenario) {
if (g_strcmp0 (scenario, "none")) { if (g_strcmp0 (opts->scenario, "none")) {
gchar *scenario_name = g_strconcat (scenario, "->gespipeline*", NULL); gchar *scenario_name =
g_strconcat (opts->scenario, "->gespipeline*", NULL);
g_setenv ("GST_VALIDATE_SCENARIO", scenario_name, TRUE); g_setenv ("GST_VALIDATE_SCENARIO", scenario_name, TRUE);
g_free (scenario_name); g_free (scenario_name);
} }
@ -131,24 +131,28 @@ ges_validate_activate (GstPipeline * pipeline, GESTrackType * track_types,
GST_VALIDATE_BIN_MONITOR (monitor)->scenario->description; GST_VALIDATE_BIN_MONITOR (monitor)->scenario->description;
if (metas) { if (metas) {
const gchar *track_types_str; gchar **ges_options = gst_validate_utils_get_strv (metas, "ges-options");
if ((track_types_str = if (ges_options) {
gst_structure_get_string (metas, "ges-track-types"))) { gint i;
if (!get_flags_from_string (GES_TYPE_TRACK_TYPE, track_types_str, gchar **ges_options_full =
track_types)) { g_new0 (gchar *, g_strv_length (ges_options) + 2);
GST_ERROR_OBJECT (pipeline, "Scenario track types: %s no valid",
track_types_str); ges_options_full[0] = g_strdup ("something");
return FALSE; for (i = 0; ges_options[i]; i++)
} ges_options_full[i + 1] = ges_options[i];
ges_launcher_parse_options (opts, ges_options_full, NULL, NULL, NULL);
g_free (ges_options);
g_strfreev (ges_options_full);
} }
} }
} }
gst_validate_reporter_set_handle_g_logs (GST_VALIDATE_REPORTER (monitor)); gst_validate_reporter_set_handle_g_logs (GST_VALIDATE_REPORTER (monitor));
g_object_get (monitor, "handles-states", needs_setting_state, NULL); g_object_get (monitor, "handles-states", &opts->needs_set_state, NULL);
*needs_setting_state = !*needs_setting_state; opts->needs_set_state = !opts->needs_set_state;
g_object_set_data (G_OBJECT (pipeline), MONITOR_ON_PIPELINE, monitor); g_object_set_data (G_OBJECT (pipeline), MONITOR_ON_PIPELINE, monitor);
g_object_set_data (G_OBJECT (pipeline), RUNNER_ON_PIPELINE, runner); g_object_set_data (G_OBJECT (pipeline), RUNNER_ON_PIPELINE, runner);
@ -188,7 +192,7 @@ ges_validate_handle_request_state_change (GstMessage * message,
if (GST_IS_VALIDATE_SCENARIO (GST_MESSAGE_SRC (message)) if (GST_IS_VALIDATE_SCENARIO (GST_MESSAGE_SRC (message))
&& state == GST_STATE_NULL) { && state == GST_STATE_NULL) {
gst_validate_printf (GST_MESSAGE_SRC (message), gst_validate_printf (GST_MESSAGE_SRC (message),
"State change request NULL, " "quiting application\n"); "State change request NULL, " "quitting application\n");
g_application_quit (application); g_application_quit (application);
} }
} }
@ -226,12 +230,11 @@ _print_position (GstElement * pipeline)
} }
gboolean gboolean
ges_validate_activate (GstPipeline * pipeline, GESTrackType * track_types, ges_validate_activate (GstPipeline * pipeline, GESLauncherParsedOptions * opts)
const gchar * scenario, gboolean * needs_setting_state)
{ {
if (scenario) { if (opts->scenario) {
GST_WARNING ("Trying to run scenario %s, but gst-validate not supported", GST_WARNING ("Trying to run scenario %s, but gst-validate not supported",
scenario); opts->scenario);
return FALSE; return FALSE;
} }
@ -240,7 +243,7 @@ ges_validate_activate (GstPipeline * pipeline, GESTrackType * track_types,
GUINT_TO_POINTER (g_timeout_add (200, GUINT_TO_POINTER (g_timeout_add (200,
(GSourceFunc) _print_position, pipeline))); (GSourceFunc) _print_position, pipeline)));
*needs_setting_state = TRUE; opts->needs_set_state = TRUE;
return TRUE; return TRUE;
} }

View file

@ -25,12 +25,13 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <ges/ges.h> #include <ges/ges.h>
#include "ges-launcher.h"
G_BEGIN_DECLS G_BEGIN_DECLS
gboolean gboolean
ges_validate_activate (GstPipeline *pipeline, GESTrackType *track_types, ges_validate_activate(GstPipeline* pipeline, GESLauncherParsedOptions* opts);
const gchar *scenario, gboolean *needs_set_state); void ges_launch_validate_uri(const gchar* nid);
void ges_launch_validate_uri (const gchar *nid);
gint gint
ges_validate_clean (GstPipeline *pipeline); ges_validate_clean (GstPipeline *pipeline);