2014-05-16 14:20:26 +00:00
|
|
|
#!/usr/bin/env python2
|
2013-12-31 10:45:07 +00:00
|
|
|
#
|
|
|
|
# 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
|
2014-03-28 14:00:01 +00:00
|
|
|
import sys
|
2014-01-09 08:14:27 +00:00
|
|
|
import urlparse
|
2014-01-09 15:57:54 +00:00
|
|
|
import subprocess
|
2014-01-10 09:12:13 +00:00
|
|
|
import utils
|
2013-12-31 10:45:07 +00:00
|
|
|
from urllib import unquote
|
2014-01-10 09:12:13 +00:00
|
|
|
import xml.etree.ElementTree as ET
|
2014-07-16 10:16:03 +00:00
|
|
|
from baseclasses import GstValidateTest, TestsManager, ScenarioManager, MediaFormatCombination
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-30 14:40:21 +00:00
|
|
|
GES_DURATION_TOLERANCE = utils.GST_SECOND / 2
|
2014-03-28 14:00:01 +00:00
|
|
|
|
2014-01-30 14:40:21 +00:00
|
|
|
GES_LAUNCH_COMMAND = "ges-launch-1.0"
|
2014-03-28 14:00:01 +00:00
|
|
|
if "win32" in sys.platform:
|
|
|
|
GES_LAUNCH_COMMAND += ".exe"
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
|
2014-01-30 14:40:21 +00:00
|
|
|
GES_ENCODING_TARGET_COMBINATIONS = [
|
2014-07-16 10:16:03 +00:00
|
|
|
MediaFormatCombination("ogg", "vorbis", "theora"),
|
|
|
|
MediaFormatCombination("webm", "vorbis", "vp8"),
|
|
|
|
MediaFormatCombination("mp4", "mp3", "h264"),
|
|
|
|
MediaFormatCombination("mkv", "vorbis", "h264")]
|
2013-12-31 10:45:07 +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.
|
2014-01-09 08:14:27 +00:00
|
|
|
parts = urlparse.urlsplit(uri, allow_fragments=False)
|
2013-12-31 10:45:07 +00:00
|
|
|
# Make absolutely sure the string is unquoted before quoting again!
|
|
|
|
raw_path = unquote(parts.path)
|
2014-01-10 09:12:13 +00:00
|
|
|
return utils.path2url(raw_path)
|
|
|
|
|
|
|
|
|
2014-07-16 09:39:08 +00:00
|
|
|
class XgesProjectDescriptor(MediaDescriptor):
|
|
|
|
def __init__(self, uri):
|
|
|
|
super(XgesProjectDescriptor, self).__init__()
|
2014-01-10 09:12:13 +00:00
|
|
|
|
2014-07-16 09:39:08 +00:00
|
|
|
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
|
|
|
|
|
2014-07-16 10:50:41 +00:00
|
|
|
def get_path(self):
|
|
|
|
return self._xml_path
|
|
|
|
|
2014-07-16 09:39:08 +00:00
|
|
|
def get_caps(self):
|
|
|
|
raise NotImplemented
|
|
|
|
|
|
|
|
def get_uri(self):
|
|
|
|
return self._uri
|
|
|
|
|
|
|
|
def get_duration(self):
|
|
|
|
if self._duration:
|
|
|
|
print("RETURN %s" % self._duration)
|
|
|
|
return self._duration
|
|
|
|
|
|
|
|
for l in self._root.iter():
|
|
|
|
if l.tag == "timeline":
|
|
|
|
self._duration=long(l.attrib['metadatas'].split("duration=(guint64)")[1].split(" ")[0].split(";")[0])
|
|
|
|
break
|
|
|
|
|
|
|
|
if not self._duration:
|
|
|
|
self.error("%s does not have duration! (setting 2mins)" % self._uri)
|
|
|
|
self._duration = 2 * 60
|
|
|
|
|
|
|
|
print("RETURN %s" % self._duration)
|
|
|
|
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
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
|
2014-01-09 08:14:27 +00:00
|
|
|
class GESTest(GstValidateTest):
|
|
|
|
def __init__(self, classname, options, reporter, project_uri, scenario=None,
|
2013-12-31 10:45:07 +00:00
|
|
|
combination=None):
|
2014-07-16 09:39:08 +00:00
|
|
|
|
2014-01-30 14:40:21 +00:00
|
|
|
super(GESTest, self).__init__(GES_LAUNCH_COMMAND, classname, options, reporter,
|
2014-01-09 08:14:27 +00:00
|
|
|
scenario=scenario)
|
2014-07-16 09:39:08 +00:00
|
|
|
|
|
|
|
self.project = XgesProjectDescriptor(project_uri)
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
def set_sample_paths(self):
|
|
|
|
if not self.options.paths:
|
2014-04-30 13:51:43 +00:00
|
|
|
if self.options.disable_recurse:
|
2013-12-31 10:45:07 +00:00
|
|
|
return
|
2014-07-16 09:39:08 +00:00
|
|
|
paths = [os.path.dirname(self.project.get_media_filepath())]
|
2013-12-31 10:45:07 +00:00
|
|
|
else:
|
|
|
|
paths = self.options.paths
|
|
|
|
|
2014-03-26 10:46:48 +00:00
|
|
|
if not isinstance(paths, list):
|
|
|
|
paths = [paths]
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
for path in paths:
|
2014-03-28 14:00:45 +00:00
|
|
|
# We always want paths separator to be cut with '/' for ges-launch
|
|
|
|
path = path.replace("\\", "/")
|
2014-04-30 13:51:43 +00:00
|
|
|
if not self.options.disable_recurse:
|
|
|
|
self.add_arguments("--sample-path-recurse", quote_uri(path))
|
2013-12-31 10:45:07 +00:00
|
|
|
else:
|
2014-04-30 13:51:43 +00:00
|
|
|
self.add_arguments("--sample-path", quote_uri(path))
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
def build_arguments(self):
|
2014-01-09 08:14:27 +00:00
|
|
|
GstValidateTest.build_arguments(self)
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
if self.options.mute:
|
|
|
|
self.add_arguments(" --mute")
|
|
|
|
|
|
|
|
self.set_sample_paths()
|
2014-07-16 09:39:08 +00:00
|
|
|
self.add_arguments("-l", self.project.get_uri())
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-09 08:14:27 +00:00
|
|
|
|
|
|
|
class GESPlaybackTest(GESTest):
|
|
|
|
def __init__(self, classname, options, reporter, project_uri, scenario):
|
|
|
|
super(GESPlaybackTest, self).__init__(classname, options, reporter,
|
|
|
|
project_uri, scenario=scenario)
|
|
|
|
|
|
|
|
def get_current_value(self):
|
2014-01-30 11:42:25 +00:00
|
|
|
return self.get_current_position()
|
2014-01-09 08:14:27 +00:00
|
|
|
|
|
|
|
|
2014-07-16 10:03:14 +00:00
|
|
|
class GESRenderTest(GESTest, GstValidateEncodingTestInterface):
|
2014-01-09 08:14:27 +00:00
|
|
|
def __init__(self, classname, options, reporter, project_uri, combination):
|
2014-07-16 10:03:14 +00:00
|
|
|
GESTest.__init__(self, classname, options, reporter, project_uri)
|
|
|
|
|
|
|
|
GstValidateEncodingTestInterface.__init__(self, combination, self.project)
|
2014-01-09 08:14:27 +00:00
|
|
|
|
|
|
|
def build_arguments(self):
|
|
|
|
GESTest.build_arguments(self)
|
|
|
|
self._set_rendering_info()
|
|
|
|
|
|
|
|
def _set_rendering_info(self):
|
2014-02-06 16:22:36 +00:00
|
|
|
self.dest_file = path = os.path.join(self.options.dest,
|
|
|
|
self.classname.replace(".render.", os.sep).
|
|
|
|
replace(".", os.sep))
|
|
|
|
utils.mkdir(os.path.dirname(urlparse.urlsplit(self.dest_file).path))
|
2014-01-10 09:12:13 +00:00
|
|
|
if not utils.isuri(self.dest_file):
|
|
|
|
self.dest_file = utils.path2url(self.dest_file)
|
2014-01-09 08:14:27 +00:00
|
|
|
|
2014-07-16 10:03:14 +00:00
|
|
|
profile = self.get_profile(video_restriction="video/x-raw,format=I420")
|
2014-01-09 08:14:27 +00:00
|
|
|
self.add_arguments("-f", profile, "-o", self.dest_file)
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
def check_results(self):
|
2014-06-16 14:46:21 +00:00
|
|
|
if self.result in [Result.PASSED, Result.NOT_RUN] and self.scenario is None:
|
2014-07-16 10:03:14 +00:00
|
|
|
res, msg = self.check_encoded_file()
|
2014-01-09 14:23:38 +00:00
|
|
|
self.set_result(res, msg)
|
2013-12-31 10:45:07 +00:00
|
|
|
else:
|
2014-01-10 09:12:13 +00:00
|
|
|
if self.result == utils.Result.TIMEOUT:
|
2013-12-31 10:45:07 +00:00
|
|
|
missing_eos = False
|
|
|
|
try:
|
2014-07-16 09:39:08 +00:00
|
|
|
if utils.get_duration(self.dest_file) == self.project.get_duration():
|
2013-12-31 10:45:07 +00:00
|
|
|
missing_eos = True
|
|
|
|
except Exception as e:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if missing_eos is True:
|
2014-01-10 09:12:13 +00:00
|
|
|
self.set_result(utils.Result.TIMEOUT, "The rendered file add right duration, MISSING EOS?\n",
|
2014-01-09 14:23:38 +00:00
|
|
|
"failure", e)
|
2013-12-31 10:45:07 +00:00
|
|
|
else:
|
2014-01-09 08:14:27 +00:00
|
|
|
GstValidateTest.check_results(self)
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-09 08:14:27 +00:00
|
|
|
def get_current_value(self):
|
2014-07-16 10:03:14 +00:00
|
|
|
size = self.get_current_size()
|
|
|
|
if size is None:
|
|
|
|
return self.get_current_position()
|
|
|
|
|
|
|
|
return size
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-09 14:23:38 +00:00
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
class GESTestsManager(TestsManager):
|
2013-12-31 10:45:07 +00:00
|
|
|
name = "ges"
|
2014-01-09 08:14:27 +00:00
|
|
|
|
2014-02-12 10:18:14 +00:00
|
|
|
_scenarios = ScenarioManager()
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
def __init__(self):
|
|
|
|
super(GESTestsManager, self).__init__()
|
2014-01-09 14:15:51 +00:00
|
|
|
|
|
|
|
def init(self):
|
2014-01-09 15:57:54 +00:00
|
|
|
try:
|
2014-01-30 14:40:21 +00:00
|
|
|
if "--set-scenario=" in subprocess.check_output([GES_LAUNCH_COMMAND, "--help"]):
|
2014-03-28 14:01:12 +00:00
|
|
|
|
2014-01-09 15:57:54 +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)
|
2014-01-09 14:15:51 +00:00
|
|
|
|
2014-04-30 13:40:10 +00:00
|
|
|
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:""")
|
2014-04-30 09:52:00 +00:00
|
|
|
group.add_argument("-P", "--projects-paths", dest="projects_paths",
|
2014-01-10 09:12:13 +00:00
|
|
|
default=os.path.join(utils.DEFAULT_GST_QA_ASSETS,
|
|
|
|
"ges-projects"),
|
2013-12-31 10:45:07 +00:00
|
|
|
help="Paths in which to look for moved medias")
|
2014-04-30 13:51:43 +00:00
|
|
|
group.add_argument("-r", "--disable-recurse-paths", dest="disable_recurse",
|
2013-12-31 10:45:07 +00:00
|
|
|
default=False, action="store_true",
|
|
|
|
help="Whether to recurse into paths to find medias")
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
def set_settings(self, options, args, reporter):
|
|
|
|
TestsManager.set_settings(self, options, args, reporter)
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
try:
|
2014-01-10 09:12:13 +00:00
|
|
|
os.makedirs(utils.url2path(options.dest)[0])
|
2013-12-31 10:45:07 +00:00
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def list_tests(self):
|
2014-04-02 17:14:30 +00:00
|
|
|
if self.tests:
|
|
|
|
return self.tests
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
projects = list()
|
|
|
|
if not self.args:
|
2013-12-31 10:45:07 +00:00
|
|
|
path = self.options.projects_paths
|
2013-12-31 10:45:07 +00:00
|
|
|
for root, dirs, files in os.walk(path):
|
|
|
|
for f in files:
|
|
|
|
if not f.endswith(".xges"):
|
|
|
|
continue
|
2014-01-10 09:12:13 +00:00
|
|
|
projects.append(utils.path2url(os.path.join(path, root, f)))
|
2013-12-31 10:45:07 +00:00
|
|
|
else:
|
|
|
|
for proj in self.args:
|
2014-04-30 09:13:51 +00:00
|
|
|
if not utils.isuri(proj):
|
|
|
|
proj = utils.path2url(proj)
|
|
|
|
|
|
|
|
if os.path.exists(proj):
|
2013-12-31 10:45:07 +00:00
|
|
|
projects.append(proj)
|
2014-04-30 09:13:51 +00:00
|
|
|
|
2014-02-12 10:18:14 +00:00
|
|
|
SCENARIOS = ["play_15s",
|
2014-05-19 17:42:46 +00:00
|
|
|
"scrub_forward_seeking",
|
|
|
|
"scrub_backward_seeking"]
|
2013-12-31 10:45:07 +00:00
|
|
|
for proj in projects:
|
|
|
|
# First playback casses
|
2014-02-12 10:18:14 +00:00
|
|
|
for scenario_name in SCENARIOS:
|
|
|
|
scenario = self._scenarios.get_scenario(scenario_name)
|
2014-03-28 14:01:12 +00:00
|
|
|
if scenario is None:
|
|
|
|
continue
|
2014-01-24 10:41:25 +00:00
|
|
|
classname = "ges.playback.%s.%s" % (scenario.name,
|
|
|
|
os.path.basename(proj).replace(".xges", ""))
|
2014-01-22 23:15:54 +00:00
|
|
|
self.add_test(GESPlaybackTest(classname,
|
|
|
|
self.options,
|
|
|
|
self.reporter,
|
|
|
|
proj,
|
|
|
|
scenario=scenario)
|
2013-12-31 10:45:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# And now rendering casses
|
2014-01-30 14:40:21 +00:00
|
|
|
for comb in GES_ENCODING_TARGET_COMBINATIONS:
|
2013-12-31 10:45:07 +00:00
|
|
|
classname = "ges.render.%s.%s" % (str(comb).replace(' ', '_'),
|
2014-01-09 08:14:27 +00:00
|
|
|
os.path.splitext(os.path.basename(proj))[0])
|
2014-01-22 23:15:54 +00:00
|
|
|
self.add_test(GESRenderTest(classname, self.options,
|
|
|
|
self.reporter, proj,
|
|
|
|
combination=comb)
|
2013-12-31 10:45:07 +00:00
|
|
|
)
|
2014-04-02 17:14:30 +00:00
|
|
|
|
|
|
|
return self.tests
|