From 1577911d7575a02257ec5d2edaa278f3d78c3d22 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 4 Oct 2022 19:16:44 -0300 Subject: [PATCH] validate: launcher: Keep variable framerate from input when possible But disable it if forcing a framerate for some reason Fixing our support for variable framerate in the encoding profile serialization format. Part-of: --- .../validate/launcher/apps/gstvalidate.py | 16 +++++++++++-- .../gst-devtools/validate/launcher/baseclasses.py | 26 +++++++++++++++++----- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/subprojects/gst-devtools/validate/launcher/apps/gstvalidate.py b/subprojects/gst-devtools/validate/launcher/apps/gstvalidate.py index 0fcb400..46188f8 100644 --- a/subprojects/gst-devtools/validate/launcher/apps/gstvalidate.py +++ b/subprojects/gst-devtools/validate/launcher/apps/gstvalidate.py @@ -17,6 +17,7 @@ # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, # Boston, MA 02110-1301, USA. import argparse +from fractions import Fraction import os import copy import sys @@ -34,7 +35,7 @@ from launcher.loggable import Loggable, error from launcher.baseclasses import GstValidateTest, Test, \ ScenarioManager, NamedDic, GstValidateTestsGenerator, \ GstValidateMediaDescriptor, GstValidateEncodingTestInterface, \ - GstValidateBaseTestManager, MediaDescriptor, MediaFormatCombination + GstValidateBaseTestManager, MediaDescriptor, MediaFormatCombination, VariableFramerateMode from launcher.utils import path2url, url2path, DEFAULT_TIMEOUT, which, \ GST_SECOND, Result, Protocols, mkdir, printc, Colors, get_data_file, \ @@ -819,7 +820,18 @@ class GstValidateTranscodingTest(GstValidateTest, GstValidateEncodingTestInterfa if urllib.parse.urlparse(self.dest_file).scheme == "": self.dest_file = path2url(self.dest_file) - profile = self.get_profile() + variable_framerate = VariableFramerateMode.DISABLED + if self.media_descriptor.get_num_tracks("video") == 1: + caps, = [c for (t, c) in self.media_descriptor.get_tracks_caps() if t == 'video'] + framerate = None + for struct, _ in GstCaps.new_from_str(caps): + framerate = struct.get("framerate", None) + if framerate is not None and \ + framerate.numerator == 0 and framerate.denominator == 1: + variable_framerate = VariableFramerateMode.AUTO + break + + profile = self.get_profile(variable_framerate=variable_framerate) self.add_arguments("-o", profile) def build_arguments(self): diff --git a/subprojects/gst-devtools/validate/launcher/baseclasses.py b/subprojects/gst-devtools/validate/launcher/baseclasses.py index 3bd95b5..16c47cd 100644 --- a/subprojects/gst-devtools/validate/launcher/baseclasses.py +++ b/subprojects/gst-devtools/validate/launcher/baseclasses.py @@ -19,6 +19,7 @@ """ Class representing tests and test managers. """ +from enum import Enum import importlib.util import json import os @@ -43,7 +44,7 @@ import uuid from itertools import cycle from fractions import Fraction -from .utils import which +from .utils import GstCaps, which from . import reporters from . import loggable from .loggable import Loggable @@ -1218,6 +1219,12 @@ class GstValidateTest(Test): return result +class VariableFramerateMode(Enum): + DISABLED = 1 + ENABLED = 2 + AUTO = 3 + + class GstValidateEncodingTestInterface(object): DURATION_TOLERANCE = GST_SECOND / 4 @@ -1243,7 +1250,9 @@ class GstValidateEncodingTestInterface(object): def _get_profile_full(self, muxer, venc, aenc, video_restriction=None, audio_restriction=None, audio_presence=0, - video_presence=0, variable_framerate=False): + video_presence=0, + variable_framerate=VariableFramerateMode.DISABLED): + ret = "" if muxer: ret += muxer @@ -1254,9 +1263,14 @@ class GstValidateEncodingTestInterface(object): ret += venc props = "" if video_presence: - props += 'presence=%s,' % str(video_presence) - if variable_framerate: - props += 'variable-framerate=true,' + props += 'presence=%s|' % str(video_presence) + if variable_framerate == VariableFramerateMode.AUTO: + if video_restriction and "framerate" in video_restriction: + variable_framerate = VariableFramerateMode.DISABLED + else: + variable_framerate = VariableFramerateMode.ENABLED + if variable_framerate == VariableFramerateMode.ENABLED: + props += 'variable-framerate=true|' if props: ret = ret + '|' + props[:-1] if aenc: @@ -1270,7 +1284,7 @@ class GstValidateEncodingTestInterface(object): return ret.replace("::", ":") def get_profile(self, video_restriction=None, audio_restriction=None, - variable_framerate=False): + variable_framerate=VariableFramerateMode.DISABLED): vcaps = self.combination.get_video_caps() acaps = self.combination.get_audio_caps() if video_restriction is None: -- 2.7.4