2014-10-23 19:46:04 +00:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
#
|
|
|
|
# Copyright (c) 2013,Thibault Saunier <thibault.saunier@collabora.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program 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
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this program; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
# Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2016-11-07 21:01:51 +00:00
|
|
|
import urllib.parse
|
2014-10-23 19:46:04 +00:00
|
|
|
import subprocess
|
2016-11-07 21:01:51 +00:00
|
|
|
from launcher import utils
|
|
|
|
from urllib.parse import unquote
|
2014-10-23 19:46:04 +00:00
|
|
|
import xml.etree.ElementTree as ET
|
2016-11-07 21:01:51 +00:00
|
|
|
from launcher.baseclasses import GstValidateTest, TestsManager, ScenarioManager, MediaFormatCombination, \
|
2014-10-23 19:46:04 +00:00
|
|
|
MediaDescriptor, GstValidateEncodingTestInterface
|
|
|
|
|
|
|
|
GES_DURATION_TOLERANCE = utils.GST_SECOND / 2
|
|
|
|
|
|
|
|
GES_LAUNCH_COMMAND = "ges-launch-1.0"
|
|
|
|
if "win32" in sys.platform:
|
|
|
|
GES_LAUNCH_COMMAND += ".exe"
|
|
|
|
|
|
|
|
|
|
|
|
GES_ENCODING_TARGET_COMBINATIONS = [
|
|
|
|
MediaFormatCombination("ogg", "vorbis", "theora"),
|
2016-08-01 16:55:07 +00:00
|
|
|
MediaFormatCombination("ogg", "opus", "theora"),
|
2014-10-23 19:46:04 +00:00
|
|
|
MediaFormatCombination("webm", "vorbis", "vp8"),
|
2016-07-15 12:57:28 +00:00
|
|
|
MediaFormatCombination("webm", "opus", "vp8"),
|
|
|
|
MediaFormatCombination("mp4", "aac", "h264"),
|
|
|
|
MediaFormatCombination("mp4", "ac3", "h264"),
|
2016-07-29 19:48:28 +00:00
|
|
|
MediaFormatCombination("quicktime", "aac", "jpeg"),
|
2016-07-15 12:57:28 +00:00
|
|
|
MediaFormatCombination("mkv", "opus", "h264"),
|
2016-07-29 19:48:28 +00:00
|
|
|
MediaFormatCombination("mkv", "vorbis", "h264"),
|
|
|
|
MediaFormatCombination("mkv", "opus", "jpeg"),
|
|
|
|
MediaFormatCombination("mkv", "vorbis", "jpeg")
|
2016-07-15 12:57:28 +00:00
|
|
|
]
|
2014-10-23 19:46:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
def quote_uri(uri):
|
|
|
|
"""
|
|
|
|
Encode a URI/path according to RFC 2396, without touching the file:/// part.
|
|
|
|
"""
|
|
|
|
# Split off the "file:///" part, if present.
|
2016-11-07 21:01:51 +00:00
|
|
|
parts = urllib.parse.urlsplit(uri, allow_fragments=False)
|
2014-10-23 19:46:04 +00:00
|
|
|
# Make absolutely sure the string is unquoted before quoting again!
|
|
|
|
raw_path = unquote(parts.path)
|
|
|
|
return utils.path2url(raw_path)
|
|
|
|
|
|
|
|
|
|
|
|
class XgesProjectDescriptor(MediaDescriptor):
|
|
|
|
def __init__(self, uri):
|
|
|
|
super(XgesProjectDescriptor, self).__init__()
|
|
|
|
|
|
|
|
self._uri = uri
|
|
|
|
self._xml_path = utils.url2path(uri)
|
|
|
|
self._root = ET.parse(self._xml_path)
|
|
|
|
self._duration = None
|
|
|
|
|
|
|
|
def get_media_filepath(self):
|
|
|
|
return self._xml_path
|
|
|
|
|
|
|
|
def get_path(self):
|
|
|
|
return self._xml_path
|
|
|
|
|
|
|
|
def get_caps(self):
|
|
|
|
raise NotImplemented
|
|
|
|
|
|
|
|
def get_uri(self):
|
|
|
|
return self._uri
|
|
|
|
|
|
|
|
def get_duration(self):
|
|
|
|
if self._duration:
|
|
|
|
return self._duration
|
|
|
|
|
|
|
|
for l in self._root.iter():
|
|
|
|
if l.tag == "timeline":
|
2016-11-07 21:01:51 +00:00
|
|
|
self._duration=int(l.attrib['metadatas'].split("duration=(guint64)")[1].split(" ")[0].split(";")[0])
|
2014-10-23 19:46:04 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
if not self._duration:
|
|
|
|
self.error("%s does not have duration! (setting 2mins)" % self._uri)
|
|
|
|
self._duration = 2 * 60
|
|
|
|
|
|
|
|
return self._duration
|
|
|
|
|
|
|
|
def get_protocol(self):
|
|
|
|
return Protocols.FILE
|
|
|
|
|
|
|
|
def is_seekable(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def is_image(self):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_num_tracks(self, track_type):
|
|
|
|
num_tracks = 0
|
|
|
|
for l in self._root.iter():
|
|
|
|
if l.tag == "track":
|
|
|
|
if track_type in l.attrib["caps"]:
|
|
|
|
num_tracks += 1
|
|
|
|
return num_tracks
|
|
|
|
|
|
|
|
|
|
|
|
class GESTest(GstValidateTest):
|
2014-11-29 00:12:43 +00:00
|
|
|
def __init__(self, classname, options, reporter, project, scenario=None,
|
2019-06-11 18:21:14 +00:00
|
|
|
combination=None, expected_failures=None, nest=False):
|
2014-10-23 19:46:04 +00:00
|
|
|
|
|
|
|
super(GESTest, self).__init__(GES_LAUNCH_COMMAND, classname, options, reporter,
|
|
|
|
scenario=scenario)
|
|
|
|
|
2014-11-29 00:12:43 +00:00
|
|
|
self.project = project
|
2019-06-11 18:21:14 +00:00
|
|
|
self.nested = nest
|
2014-10-23 19:46:04 +00:00
|
|
|
|
|
|
|
def set_sample_paths(self):
|
|
|
|
if not self.options.paths:
|
|
|
|
if self.options.disable_recurse:
|
|
|
|
return
|
2018-07-20 02:06:54 +00:00
|
|
|
if self.project:
|
|
|
|
paths = [os.path.dirname(self.project.get_media_filepath())]
|
|
|
|
else:
|
|
|
|
paths = []
|
2014-10-23 19:46:04 +00:00
|
|
|
else:
|
|
|
|
paths = self.options.paths
|
|
|
|
|
|
|
|
if not isinstance(paths, list):
|
|
|
|
paths = [paths]
|
|
|
|
|
|
|
|
for path in paths:
|
|
|
|
# We always want paths separator to be cut with '/' for ges-launch
|
|
|
|
path = path.replace("\\", "/")
|
|
|
|
if not self.options.disable_recurse:
|
2015-03-25 14:43:16 +00:00
|
|
|
self.add_arguments("--ges-sample-path-recurse", quote_uri(path))
|
2014-10-23 19:46:04 +00:00
|
|
|
else:
|
2015-03-25 14:43:16 +00:00
|
|
|
self.add_arguments("--ges-sample-paths", quote_uri(path))
|
2014-10-23 19:46:04 +00:00
|
|
|
|
|
|
|
def build_arguments(self):
|
|
|
|
GstValidateTest.build_arguments(self)
|
|
|
|
|
|
|
|
if self.options.mute:
|
2019-06-23 17:03:04 +00:00
|
|
|
needs_clock = self.scenario.needs_clock_sync() \
|
|
|
|
if self.scenario else False
|
|
|
|
audiosink = utils.get_fakesink_for_media_type("audio", needs_clock)
|
|
|
|
videosink = utils.get_fakesink_for_media_type("video", needs_clock)
|
|
|
|
else:
|
|
|
|
audiosink = 'autoaudiosink'
|
|
|
|
videosink = 'autovideosink'
|
|
|
|
self.add_arguments("--videosink", videosink + " name=videosink")
|
|
|
|
self.add_arguments("--audiosink", audiosink + " name=audiosink")
|
2014-10-23 19:46:04 +00:00
|
|
|
|
|
|
|
self.set_sample_paths()
|
2018-07-20 02:06:54 +00:00
|
|
|
|
|
|
|
if self.project:
|
2019-06-11 18:21:14 +00:00
|
|
|
if self.nested:
|
|
|
|
self.add_arguments("+clip", self.project.get_uri())
|
|
|
|
else:
|
|
|
|
self.add_arguments("-l", self.project.get_uri())
|
2014-10-23 19:46:04 +00:00
|
|
|
|
|
|
|
class GESPlaybackTest(GESTest):
|
2019-06-11 18:21:14 +00:00
|
|
|
def __init__(self, classname, options, reporter, project, scenario,nest):
|
2014-10-23 19:46:04 +00:00
|
|
|
super(GESPlaybackTest, self).__init__(classname, options, reporter,
|
2019-06-11 18:21:14 +00:00
|
|
|
project, scenario=scenario, nest=nest)
|
2014-10-23 19:46:04 +00:00
|
|
|
|
|
|
|
def get_current_value(self):
|
|
|
|
return self.get_current_position()
|
|
|
|
|
2018-07-20 02:06:54 +00:00
|
|
|
class GESScenarioTest(GESTest):
|
|
|
|
def __init__(self, classname, options, reporter, scenario):
|
|
|
|
super().__init__(classname, options, reporter, None, scenario=scenario)
|
|
|
|
|
|
|
|
def build_arguments(self):
|
|
|
|
super().build_arguments()
|
|
|
|
self.add_arguments("--set-scenario", self.scenario.path)
|
|
|
|
|
|
|
|
def get_subproc_env(self):
|
|
|
|
scenario = self.scenario
|
|
|
|
self.scenario = None
|
|
|
|
res = super().get_subproc_env()
|
|
|
|
self.scenario = scenario
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
def get_current_value(self):
|
|
|
|
return self.get_current_position()
|
|
|
|
|
2014-10-23 19:46:04 +00:00
|
|
|
|
|
|
|
class GESRenderTest(GESTest, GstValidateEncodingTestInterface):
|
2014-11-29 00:12:43 +00:00
|
|
|
def __init__(self, classname, options, reporter, project, combination):
|
|
|
|
GESTest.__init__(self, classname, options, reporter, project)
|
2014-10-23 19:46:04 +00:00
|
|
|
|
|
|
|
GstValidateEncodingTestInterface.__init__(self, combination, self.project)
|
|
|
|
|
|
|
|
def build_arguments(self):
|
|
|
|
GESTest.build_arguments(self)
|
|
|
|
self._set_rendering_info()
|
|
|
|
|
2018-05-13 20:37:08 +00:00
|
|
|
def run_external_checks(self):
|
|
|
|
reference_file_path = urllib.parse.urlsplit(self.media_descriptor.get_uri()).path + ".expected_result"
|
|
|
|
if os.path.exists(reference_file_path):
|
|
|
|
self.run_iqa_test(utils.path2url(reference_file_path))
|
|
|
|
|
2014-10-23 19:46:04 +00:00
|
|
|
def _set_rendering_info(self):
|
|
|
|
self.dest_file = path = os.path.join(self.options.dest,
|
|
|
|
self.classname.replace(".render.", os.sep).
|
|
|
|
replace(".", os.sep))
|
2016-11-07 21:01:51 +00:00
|
|
|
utils.mkdir(os.path.dirname(urllib.parse.urlsplit(self.dest_file).path))
|
2014-10-23 19:46:04 +00:00
|
|
|
if not utils.isuri(self.dest_file):
|
|
|
|
self.dest_file = utils.path2url(self.dest_file)
|
|
|
|
|
2018-04-20 20:56:15 +00:00
|
|
|
profile = self.get_profile()
|
2014-10-23 19:46:04 +00:00
|
|
|
self.add_arguments("-f", profile, "-o", self.dest_file)
|
|
|
|
|
|
|
|
def check_results(self):
|
|
|
|
if self.result in [Result.PASSED, Result.NOT_RUN] and self.scenario is None:
|
2017-08-11 01:38:04 +00:00
|
|
|
if self.process.returncode != 0:
|
|
|
|
return super().check_results()
|
|
|
|
|
2014-10-23 19:46:04 +00:00
|
|
|
res, msg = self.check_encoded_file()
|
|
|
|
self.set_result(res, msg)
|
|
|
|
else:
|
|
|
|
if self.result == utils.Result.TIMEOUT:
|
|
|
|
missing_eos = False
|
|
|
|
try:
|
|
|
|
if utils.get_duration(self.dest_file) == self.project.get_duration():
|
|
|
|
missing_eos = True
|
|
|
|
except Exception as e:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if missing_eos is True:
|
2017-08-10 14:18:22 +00:00
|
|
|
self.set_result(utils.Result.TIMEOUT, "The rendered file had right duration, MISSING EOS?\n",
|
2014-11-25 18:15:52 +00:00
|
|
|
"failure")
|
2014-10-23 19:46:04 +00:00
|
|
|
else:
|
|
|
|
GstValidateTest.check_results(self)
|
|
|
|
|
|
|
|
def get_current_value(self):
|
|
|
|
size = self.get_current_size()
|
|
|
|
if size is None:
|
|
|
|
return self.get_current_position()
|
|
|
|
|
|
|
|
return size
|
|
|
|
|
|
|
|
|
|
|
|
class GESTestsManager(TestsManager):
|
|
|
|
name = "ges"
|
|
|
|
|
|
|
|
_scenarios = ScenarioManager()
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super(GESTestsManager, self).__init__()
|
|
|
|
|
|
|
|
def init(self):
|
|
|
|
try:
|
2016-11-07 21:01:51 +00:00
|
|
|
if "--set-scenario=" in subprocess.check_output([GES_LAUNCH_COMMAND, "--help"]).decode():
|
2014-10-23 19:46:04 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
self.warning("Can not use ges-launch, it seems not to be compiled against"
|
|
|
|
" gst-validate")
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
self.warning("Can not use ges-launch: %s" % e)
|
|
|
|
except OSError as e:
|
|
|
|
self.warning("Can not use ges-launch: %s" % e)
|
|
|
|
|
|
|
|
def add_options(self, parser):
|
|
|
|
group = parser.add_argument_group("GStreamer Editing Services specific option"
|
|
|
|
" and behaviours",
|
|
|
|
description="""
|
|
|
|
The GStreamer Editing Services launcher will be usable only if GES has been compiled against GstValidate
|
|
|
|
You can simply run scenarios specifying project as args. For example the following will run all available
|
|
|
|
and activated scenarios on project.xges:
|
|
|
|
|
|
|
|
$gst-validate-launcher ges /some/ges/project.xges
|
|
|
|
|
|
|
|
|
|
|
|
Available options:""")
|
|
|
|
group.add_argument("-P", "--projects-paths", dest="projects_paths",
|
|
|
|
default=os.path.join(utils.DEFAULT_GST_QA_ASSETS,
|
2014-11-29 00:12:43 +00:00
|
|
|
"ges",
|
2014-10-23 19:46:04 +00:00
|
|
|
"ges-projects"),
|
|
|
|
help="Paths in which to look for moved medias")
|
2018-07-20 02:06:54 +00:00
|
|
|
group.add_argument("--ges-scenario-paths", dest="scenarios_path",
|
2018-07-23 04:07:07 +00:00
|
|
|
default=None,
|
2018-07-20 02:06:54 +00:00
|
|
|
help="Paths in which to look for moved medias")
|
2014-10-23 19:46:04 +00:00
|
|
|
group.add_argument("-r", "--disable-recurse-paths", dest="disable_recurse",
|
|
|
|
default=False, action="store_true",
|
|
|
|
help="Whether to recurse into paths to find medias")
|
|
|
|
|
|
|
|
def set_settings(self, options, args, reporter):
|
|
|
|
TestsManager.set_settings(self, options, args, reporter)
|
2014-11-29 00:12:43 +00:00
|
|
|
self._scenarios.config = self.options
|
2014-10-23 19:46:04 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
os.makedirs(utils.url2path(options.dest)[0])
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def list_tests(self):
|
2014-11-29 00:12:43 +00:00
|
|
|
return self.tests
|
2014-10-23 19:46:04 +00:00
|
|
|
|
2018-07-23 04:07:07 +00:00
|
|
|
def register_defaults(self, project_paths=None, scenarios_path=None):
|
2014-10-23 19:46:04 +00:00
|
|
|
projects = list()
|
2019-06-23 17:03:54 +00:00
|
|
|
all_scenarios = {}
|
2014-10-23 19:46:04 +00:00
|
|
|
if not self.args:
|
2014-11-29 00:12:43 +00:00
|
|
|
if project_paths == None:
|
|
|
|
path = self.options.projects_paths
|
|
|
|
else:
|
|
|
|
path = project_paths
|
|
|
|
|
2014-10-23 19:46:04 +00:00
|
|
|
for root, dirs, files in os.walk(path):
|
|
|
|
for f in files:
|
|
|
|
if not f.endswith(".xges"):
|
|
|
|
continue
|
|
|
|
projects.append(utils.path2url(os.path.join(path, root, f)))
|
2018-07-20 02:06:54 +00:00
|
|
|
|
2018-07-23 04:07:07 +00:00
|
|
|
if self.options.scenarios_path:
|
|
|
|
scenarios_path = self.options.scenarios_path
|
|
|
|
|
|
|
|
if scenarios_path:
|
|
|
|
for root, dirs, files in os.walk(scenarios_path):
|
|
|
|
for f in files:
|
|
|
|
if not f.endswith(".scenario"):
|
|
|
|
continue
|
2019-06-23 17:03:54 +00:00
|
|
|
f = os.path.join(root, f)
|
|
|
|
config = f + ".config"
|
|
|
|
if not os.path.exists(config):
|
|
|
|
config = None
|
|
|
|
all_scenarios[f] = config
|
2014-10-23 19:46:04 +00:00
|
|
|
else:
|
2014-11-29 00:12:43 +00:00
|
|
|
for proj_uri in self.args:
|
|
|
|
if not utils.isuri(proj_uri):
|
|
|
|
proj_uri = utils.path2url(proj_uri)
|
2014-10-23 19:46:04 +00:00
|
|
|
|
2014-11-29 00:12:43 +00:00
|
|
|
if os.path.exists(proj_uri):
|
|
|
|
projects.append(proj_uri)
|
2014-10-23 19:46:04 +00:00
|
|
|
|
2014-11-25 18:15:52 +00:00
|
|
|
if self.options.long_limit != 0:
|
|
|
|
scenarios = ["none",
|
|
|
|
"scrub_forward_seeking",
|
|
|
|
"scrub_backward_seeking"]
|
|
|
|
else:
|
|
|
|
scenarios = ["play_15s",
|
|
|
|
"scrub_forward_seeking_full",
|
|
|
|
"scrub_backward_seeking_full"]
|
2014-11-29 00:12:43 +00:00
|
|
|
for proj_uri in projects:
|
2014-10-23 19:46:04 +00:00
|
|
|
# First playback casses
|
2014-11-29 00:12:43 +00:00
|
|
|
project = XgesProjectDescriptor(proj_uri)
|
2014-11-25 18:15:52 +00:00
|
|
|
for scenario_name in scenarios:
|
2014-10-23 19:46:04 +00:00
|
|
|
scenario = self._scenarios.get_scenario(scenario_name)
|
|
|
|
if scenario is None:
|
|
|
|
continue
|
2014-11-29 00:12:43 +00:00
|
|
|
|
|
|
|
if scenario.get_min_media_duration() >= (project.get_duration() / utils.GST_SECOND):
|
|
|
|
continue
|
|
|
|
|
2017-07-13 20:38:04 +00:00
|
|
|
classname = "playback.%s.%s" % (scenario.name,
|
2014-11-29 00:12:43 +00:00
|
|
|
os.path.basename(proj_uri).replace(".xges", ""))
|
2014-10-23 19:46:04 +00:00
|
|
|
self.add_test(GESPlaybackTest(classname,
|
|
|
|
self.options,
|
|
|
|
self.reporter,
|
2014-11-29 00:12:43 +00:00
|
|
|
project,
|
2019-06-11 18:21:14 +00:00
|
|
|
scenario=scenario,
|
|
|
|
nest=False))
|
|
|
|
#For nested timelines
|
|
|
|
classname = "playback.nested.%s.%s" % (scenario.name,
|
|
|
|
os.path.basename(proj_uri).replace(".xges", ""))
|
|
|
|
self.add_test(GESPlaybackTest(classname,
|
|
|
|
self.options,
|
|
|
|
self.reporter,
|
|
|
|
project,
|
|
|
|
scenario=scenario,
|
|
|
|
nest=True))
|
2014-10-23 19:46:04 +00:00
|
|
|
|
|
|
|
# And now rendering casses
|
|
|
|
for comb in GES_ENCODING_TARGET_COMBINATIONS:
|
2017-07-13 20:38:04 +00:00
|
|
|
classname = "render.%s.%s" % (str(comb).replace(' ', '_'),
|
2014-11-29 00:12:43 +00:00
|
|
|
os.path.splitext(os.path.basename(proj_uri))[0])
|
2014-10-23 19:46:04 +00:00
|
|
|
self.add_test(GESRenderTest(classname, self.options,
|
2014-11-29 00:12:43 +00:00
|
|
|
self.reporter, project,
|
2014-10-23 19:46:04 +00:00
|
|
|
combination=comb)
|
|
|
|
)
|
2018-07-23 04:07:07 +00:00
|
|
|
if all_scenarios:
|
2019-06-23 17:03:54 +00:00
|
|
|
for scenario in self._scenarios.discover_scenarios(list(all_scenarios.keys())):
|
|
|
|
config = all_scenarios[scenario.path]
|
2018-07-23 04:07:07 +00:00
|
|
|
classname = "scenario.%s" % scenario.name
|
2019-06-23 17:03:54 +00:00
|
|
|
test = GESScenarioTest(classname, self.options, self.reporter, scenario=scenario)
|
|
|
|
if config:
|
|
|
|
test.add_validate_config(config)
|
|
|
|
self.add_test(test)
|