validate:tools: Cleanup how we check result of rendering test

Factor out a method in the utils, and make use of it for both ges-launch and
gst-validate-transcode
This commit is contained in:
Thibault Saunier 2014-01-09 15:23:38 +01:00
parent ff30c6ba3c
commit 446e5c88c2
3 changed files with 56 additions and 26 deletions

View file

@ -23,7 +23,8 @@ from urllib import unquote
from gi.repository import GES, Gst, GLib from gi.repository import GES, Gst, GLib
from baseclasses import GstValidateTest, TestsManager from baseclasses import GstValidateTest, TestsManager
from utils import MediaFormatCombination, get_profile, Result, get_current_position, \ from utils import MediaFormatCombination, get_profile, Result, get_current_position, \
get_current_size, DEFAULT_GST_QA_ASSETS get_current_size, DEFAULT_GST_QA_ASSETS, which, \
compare_rendered_with_original, get_duration
DURATION_TOLERANCE = Gst.SECOND / 2 DURATION_TOLERANCE = Gst.SECOND / 2
DEFAULT_GES_LAUNCH = "ges-launch-1.0" DEFAULT_GES_LAUNCH = "ges-launch-1.0"
@ -134,38 +135,27 @@ class GESRenderTest(GESTest):
def check_results(self): def check_results(self):
if self.process.returncode == 0: if self.process.returncode == 0:
try: res, msg = compare_rendered_with_original(self.duration, self.dest_file)
asset = GES.UriClipAsset.request_sync(self.dest_file) self.set_result(res, msg)
if self.duration - DURATION_TOLERANCE <= asset.get_duration() \
<= self.duration + DURATION_TOLERANCE:
self.set_result(Result.FAILURE, "Duration of encoded file is "
" wrong (%s instead of %s)" %
(Gst.TIME_ARGS(self.duration),
Gst.TIME_ARGS(asset.get_duration())),
"wrong-duration")
else:
self.set_result(Result.PASSED)
except GLib.Error as e:
self.set_result(Result.FAILURE, "Wrong rendered file", "failure", e)
else: else:
if self.result == Result.TIMEOUT: if self.result == Result.TIMEOUT:
missing_eos = False missing_eos = False
try: try:
asset = GES.UriClipAsset.request_sync(self.dest_file) if get_duration(self.dest_file) == self.duration:
if asset.get_duration() == self.duration:
missing_eos = True missing_eos = True
except Exception as e: except Exception as e:
pass pass
if missing_eos is True: if missing_eos is True:
self.set_result(Result.TIMEOUT, "The rendered file add right duration, MISSING EOS?\n", self.set_result(Result.TIMEOUT, "The rendered file add right duration, MISSING EOS?\n",
"failure", e) "failure", e)
else: else:
GstValidateTest.check_results(self) GstValidateTest.check_results(self)
def get_current_value(self): def get_current_value(self):
return get_current_size(self) return get_current_size(self)
class GESTestsManager(TestsManager): class GESTestsManager(TestsManager):
name = "ges" name = "ges"

View file

@ -25,7 +25,8 @@ from loggable import Loggable
from baseclasses import GstValidateTest, TestsManager from baseclasses import GstValidateTest, TestsManager
from utils import MediaFormatCombination, get_profile,\ from utils import MediaFormatCombination, get_profile,\
path2url, get_current_position, get_current_size, \ path2url, get_current_position, get_current_size, \
DEFAULT_TIMEOUT DEFAULT_TIMEOUT, which, GST_SECOND, Result, \
compare_rendered_with_original
DEFAULT_GST_VALIDATE = "gst-validate-1.0" DEFAULT_GST_VALIDATE = "gst-validate-1.0"
@ -94,6 +95,14 @@ class GstValidateTranscodingTest(GstValidateTest):
def get_current_value(self): def get_current_value(self):
return get_current_size(self) return get_current_size(self)
def check_results(self):
if self.process.returncode == 0:
orig_duration = long(self.file_infos.get("media-info", "file-duration"))
res, msg = compare_rendered_with_original(orig_duration, self.dest_file)
self.set_result(res, msg)
else:
GstValidateTest.check_results(self)
class GstValidateManager(TestsManager, Loggable): class GstValidateManager(TestsManager, Loggable):
@ -124,15 +133,13 @@ class GstValidateManager(TestsManager, Loggable):
for uri, config in self._list_uris(): for uri, config in self._list_uris():
for comb in COMBINATIONS: for comb in COMBINATIONS:
classname = "validate.transcode"
classname = "validate.transcode.from_%s.to_%s" % (os.path.splitext(os.path.basename(uri))[0], classname = "validate.transcode.from_%s.to_%s" % (os.path.splitext(os.path.basename(uri))[0],
str(comb).replace(' ', '_')) str(comb).replace(' ', '_'))
self.tests.append(GstValidateTranscodingTest(classname, self.tests.append(GstValidateTranscodingTest(classname,
self.options, self.options,
self.reporter, self.reporter,
comb, comb, uri,
uri, config))
config))
def _check_discovering_info(self, media_info, uri=None): def _check_discovering_info(self, media_info, uri=None):
self.debug("Checking %s", media_info) self.debug("Checking %s", media_info)
@ -225,7 +232,7 @@ class GstValidateManager(TestsManager, Loggable):
if scenario in SEEKING_REQUIERED_SCENARIO: if scenario in SEEKING_REQUIERED_SCENARIO:
if config.getboolean("media-info", "seekable") is False: if config.getboolean("media-info", "seekable") is False:
self.debug("Do not run %s as %s does not support seeking", self.debug("Do not run %s as %s does not support seeking",
scenario, uri) scenario, uri)
continue continue
if self.options.mute: if self.options.mute:

View file

@ -21,12 +21,17 @@
import os import os
import urllib import urllib
import urlparse import urlparse
import tempfile
import subprocess
import ConfigParser
GST_SECOND = 1000000000 GST_SECOND = 1000000000
DEFAULT_TIMEOUT = 10 DEFAULT_TIMEOUT = 10
DEFAULT_GST_QA_ASSETS = os.path.join(os.path.expanduser('~'), "Videos", DEFAULT_GST_QA_ASSETS = os.path.join(os.path.expanduser('~'), "Videos",
"gst-qa-assets") "gst-qa-assets")
DISCOVERER_COMMAND = "gst-discoverer-1.0"
DURATION_TOLERANCE = GST_SECOND / 2
class Result(object): class Result(object):
@ -172,10 +177,11 @@ def get_profile(combination):
################################################## ##################################################
def _parse_position(p): def _parse_position(p):
def parse_gsttimeargs(time): def parse_gsttimeargs(time):
return int(time.split(":")[0]) * 3600 + int(time.split(":")[1]) * 60 + int(time.split(":")[2].split(".")[0]) * 60 return int(time.split(":")[0]) * 3600 + int(time.split(":")[1]) * 60 + int(time.split(":")[2].split(".")[0]) * 60
start_stop = p.replace("<Position: ", '').replace("/>", '').split(" / ") start_stop = p.replace("<Position: ", '').replace("/>", '').split(" / ")
return parse_gsttimeargs(start_stop[0]), parse_gsttimeargs(start_stop[1]) return parse_gsttimeargs(start_stop[0]), parse_gsttimeargs(start_stop[1])
@ -220,3 +226,30 @@ def get_current_size(test):
return position return position
return os.stat(urlparse.urlparse(test.dest_file).path).st_size return os.stat(urlparse.urlparse(test.dest_file).path).st_size
def compare_rendered_with_original(orig_duration, dest_file, tolerance=DURATION_TOLERANCE):
def parse_gsttimeargs(time):
stime = time.split(":")
sns = stime[2].split(".")
stime[2] = sns[0]
stime.append(sns[1])
return (int(stime[0]) * 3600 + int(stime[1]) * 60 + int(stime[2]) * 60) * GST_SECOND + int(stime[3])
try:
res = subprocess.check_output([DISCOVERER_COMMAND, dest_file])
except subprocess.CalledProcessError:
# gst-media-check returns !0 if seeking is not possible, we do not care in that case.
pass
for l in res.split('\n'):
if "Duration: " in l:
duration = parse_gsttimeargs(l.replace("Duration: ", ""))
if orig_duration - tolerance >= duration >= orig_duration + tolerance:
return (Result.FAILED, "Duration of encoded file is "
" wrong (%s instead of %s)" %
(orig_duration / GST_SECOND,
duration / GST_SECOND),
"wrong-duration")
else:
return (Result.PASSED, "")