validate: Add a scenarios that switchs subtitle track
authorThibault Saunier <tsaunier@gnome.org>
Tue, 29 Apr 2014 17:04:46 +0000 (19:04 +0200)
committerThibault Saunier <tsaunier@gnome.org>
Fri, 2 May 2014 16:30:22 +0000 (18:30 +0200)
+ Make it easier and cleaner to tell that a switch is actually disabling
a track type.

And run the scenario in gst-validate-launcher by default

validate/data/Makefile.am
validate/data/switch_subtitle_track.scenario [new file with mode: 0644]
validate/tools/launcher/apps/gst-validate.py
validate/tools/launcher/baseclasses.py

index 3fb2628..4703371 100644 (file)
@@ -15,6 +15,7 @@ scenarios_DATA = simple_seeks.scenario \
                  force_key_unit.scenario\
                  seek_with_stop.scenario\
                  switch_audio_track_while_paused.scenario\
+                 switch_subtitle_track.scenario\
                  switch_audio_track.scenario
 
 EXTRA_DIST = simple_seeks.scenario \
@@ -33,4 +34,5 @@ EXTRA_DIST = simple_seeks.scenario \
              force_key_unit.scenario\
              seek_with_stop.scenario\
              switch_audio_track_while_paused.scenario\
+             switch_subtitle_track.scenario\
              switch_audio_track.scenario
diff --git a/validate/data/switch_subtitle_track.scenario b/validate/data/switch_subtitle_track.scenario
new file mode 100644 (file)
index 0000000..0ba7ed3
--- /dev/null
@@ -0,0 +1,3 @@
+description, summary="Change subtitle track at 1 second while playing back", min-subtitle-track=2, duration=5.0
+switch-track, playback_time=1.0, type=text, index=(string)+1
+stop, playback_time=5.0
index 447f02e..c0372a1 100644 (file)
@@ -62,13 +62,13 @@ class MediaDescriptor(Loggable):
                 return True
         return False
 
-    def get_num_audio_tracks(self):
-        naudio = 0
+    def get_num_tracks(self, track_type):
+        n = 0
         for stream in self.media_xml.findall("streams")[0].findall("stream"):
-            if stream.attrib["type"] == "audio":
-                naudio += 1
+            if stream.attrib["type"] == track_type:
+                n += 1
 
-        return naudio
+        return n
 
     def is_compatible(self, scenario):
         if scenario.seeks() and (not self.is_seekable() or self.is_image()):
@@ -76,11 +76,13 @@ class MediaDescriptor(Loggable):
                        scenario, self.get_uri())
             return False
 
-        if self.get_num_audio_tracks() < scenario.get_min_audio_tracks():
-            self.debug("%s -- %s | At least %s audio track needed  < %s"
-                       % (scenario, self.get_uri(),
-                          scenario.get_min_audio_tracks(), self.get_num_audio_tracks()))
-            return False
+        for track_type in ['audio', 'subtitle']:
+            if self.get_num_tracks(track_type) < scenario.get_min_tracks(track_type):
+                self.debug("%s -- %s | At least %s %s track needed  < %s"
+                           % (scenario, self.get_uri(), track_type,
+                              scenario.get_min_tracks(track_type),
+                              self.get_num_tracks(track_type)))
+                return False
 
         return True
 
@@ -155,6 +157,7 @@ G_V_SCENARIOS = {Protocols.FILE: ["play_15s",
                                   "seek_with_stop",
                                   "switch_audio_track",
                                   "switch_audio_track_while_paused",
+                                  "switch_subtitle_track",
                                   "scrub_forward_seeking"],
                  Protocols.HTTP: ["play_15s",
                                   "fast_forward",
@@ -163,6 +166,7 @@ G_V_SCENARIOS = {Protocols.FILE: ["play_15s",
                                   "seek_with_stop",
                                   "switch_audio_track",
                                   "switch_audio_track_while_paused",
+                                  "switch_subtitle_track",
                                   "reverse_playback"],
                  Protocols.HLS: ["play_15s",
                                  "fast_forward",
@@ -170,6 +174,7 @@ G_V_SCENARIOS = {Protocols.FILE: ["play_15s",
                                  "seek_with_stop",
                                   "switch_audio_track",
                                   "switch_audio_track_while_paused",
+                                  "switch_subtitle_track",
                                  "seek_backward"],
                  }
 
index a2fc5e3..540d2db 100644 (file)
@@ -678,11 +678,14 @@ class Scenario(object):
         if hasattr(self, "reverse_playback"):
             return bool(self.seek)
 
+        return False
+
 
-    def get_min_audio_tracks(self):
-        if hasattr(self, "min_audio_track"):
-            return int(self.min_audio_track)
-        return 0
+    def get_min_tracks(self, track_type):
+        try:
+            return int(getattr(self, "min_%s_track" % track_type))
+        except AttributeError:
+            return 0
 
 
 class ScenarioManager(Loggable):