[pitivi] Update audio track restriction caps on project changes



commit ffe5eb17283785015276d5a1b06715e2b6293673
Author: Thibault Saunier <tsaunier gnome org>
Date:   Thu Nov 2 13:07:36 2017 -0300

    Update audio track restriction caps on project changes
    
    Otherwise there is inconsistancy about what the timeline produce
    and what the user want. For example if the user want 6 channels (5.1
    audio input), what happens without this change is that the timeline
    output stereo audio, and when rendering this is upmixed to 5.1, but
    obviously the positionning is wrong.
    
    Fixes T3471
    
    Reviewed-by: Alex Băluț <<alexandru balut gmail com>>
    Differential Revision: https://phabricator.freedesktop.org/D1875

 pitivi/project.py           |   26 +++++++++++++++++++-------
 pitivi/timeline/timeline.py |    2 +-
 pitivi/utils/misc.py        |    4 ++--
 tests/test_project.py       |   25 +++++++++++++++++++++++++
 tests/test_utils.py         |    4 ++--
 5 files changed, 49 insertions(+), 12 deletions(-)
---
diff --git a/pitivi/project.py b/pitivi/project.py
index 9ca5ba8..75fbd34 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -93,6 +93,7 @@ for i in range(2, GLib.MAXINT):
 # a project.
 IGNORED_PROPS = ["name", "parent"]
 
+
 class ProjectManager(GObject.Object, Loggable):
     """The project manager.
 
@@ -1461,22 +1462,33 @@ class Project(Loggable, GES.Project):
     def update_restriction_caps(self):
         # Get the height/width without rendering settings applied
         width, height = self.getVideoWidthAndHeight()
-        caps = Gst.Caps.new_empty_simple("video/x-raw")
+        videocaps = Gst.Caps.new_empty_simple("video/x-raw")
+
+        videocaps.set_value("width", width)
+        videocaps.set_value("height", height)
+        videocaps.set_value("framerate", self.videorate)
 
-        caps.set_value("width", width)
-        caps.set_value("height", height)
-        caps.set_value("framerate", self.videorate)
+        audiocaps = Gst.Caps.new_empty_simple("audio/x-raw")
+        audiocaps.set_value("rate", self.audiorate)
+        audiocaps.set_value("channels", self.audiochannels)
         for track in self.ges_timeline.get_tracks():
             if isinstance(track, GES.VideoTrack):
-                track.set_restriction_caps(caps)
+                track.set_restriction_caps(videocaps)
+            elif isinstance(track, GES.AudioTrack):
+                track.set_restriction_caps(audiocaps)
 
         if self.app:
             self.app.write_action(
                 "set-track-restriction-caps",
-                caps=caps.to_string(),
+                caps=videocaps.to_string(),
                 track_type=GES.TrackType.VIDEO.value_nicks[0])
 
-        self.pipeline.flushSeek()
+            self.app.write_action(
+                "set-track-restriction-caps",
+                caps=audiocaps.to_string(),
+                track_type=GES.TrackType.AUDIO.value_nicks[0])
+
+        self.pipeline.commit_timeline()
 
     def addUris(self, uris):
         """Adds assets asynchronously.
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index d20ed23..9cf0064 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -1880,7 +1880,7 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
 
             self.ruler.setProjectFrameRate(self._framerate)
 
-        if item == "width" or item == "height" or item == "videorate":
+        if item in ["width", "height", "videorate", "rate", "channels"]:
             project.update_restriction_caps()
 
     def _projectLoadedCb(self, unused_project_manager, project):
diff --git a/pitivi/utils/misc.py b/pitivi/utils/misc.py
index 0f7cfdd..eaf5e31 100644
--- a/pitivi/utils/misc.py
+++ b/pitivi/utils/misc.py
@@ -402,8 +402,8 @@ def fixate_caps_with_default_values(template, restrictions, default_values,
             res.append_structure(prev_vals[0])
             res.mini_object.refcount += 1
             res = res.fixate()
-            log.debug("utils", "Returning previous caps as we have a corresponding"
-                      " version of them: %s", res)
+            log.debug("utils", "Returning previous caps %s as it is fully compatible"
+                      " with the template", res)
             return res
 
         log.debug("utils", "Adding %s to resulting caps", struct)
diff --git a/tests/test_project.py b/tests/test_project.py
index e5d8b2a..6913062 100644
--- a/tests/test_project.py
+++ b/tests/test_project.py
@@ -493,6 +493,31 @@ class TestProjectSettings(common.TestCase):
         project.videopar = Gst.Fraction(2, 7)
         self.assertEqual(Gst.Fraction(2, 7), project.videopar)
 
+    def testSetAudioProp(self):
+        timeline = common.create_timeline_container()
+        project = timeline.app.project_manager.current_project
+        project.addUris([common.get_sample_uri("mp3_sample.mp3")])
+
+        audio_track = [t for t in project.ges_timeline.tracks if isinstance(t, GES.AudioTrack)][0]
+        mainloop = common.create_main_loop()
+
+        def progress_cb(project, progress, estimated_time):
+            if progress == 100:
+                mainloop.quit()
+
+        project.connect_after("asset-loading-progress", progress_cb)
+        mainloop.run()
+
+        expected = Gst.Caps("audio/x-raw,channels=(int)2,rate=(int)44100")
+        ccaps = audio_track.props.restriction_caps
+        self.assertTrue(ccaps.is_equal_fixed(expected), "%s != %s" % (ccaps, expected))
+
+        project.audiochannels = 6
+
+        expected = Gst.Caps("audio/x-raw,channels=(int)6,rate=(int)44100")
+        ccaps = audio_track.props.restriction_caps
+        self.assertTrue(ccaps.is_equal_fixed(expected), "%s != %s" % (ccaps, expected))
+
     def testInitialization(self):
         mainloop = common.create_main_loop()
         uris = collections.deque([
diff --git a/tests/test_utils.py b/tests/test_utils.py
index e218100..dcbe15c 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -134,12 +134,12 @@ class TestMiscUtils(TestCase):
                 " audio/x-raw, channel-mask=(bitmask)0x0000000000000c0f, channels=(int)6, rate=(int){ 48000, 
44100, 32000 }, layout=(string)interleaved, format=(string)F32LE;"
                 " audio/x-raw, channel-mask=(bitmask)0x000000000000003f, channels=(int)6, rate=(int){ 48000, 
44100, 32000 }, layout=(string)interleaved, format=(string)F32LE;")
 
-        audio_defaults = {'channels': Gst.IntRange(range(1, 2147483647)),
+        audio_defaults = {"channels": Gst.IntRange(range(1, 2147483647)),
                           "rate": Gst.IntRange(range(8000, GLib.MAXINT))}
 
         dataset = [
             (voaacenc_caps, yt_audiorest, audio_defaults, None, Gst.Caps("audio/x-raw, 
channels=2,rate=48000,channel-mask=(bitmask)0x03")),
-            (vorbis_caps, None, audio_defaults, None, Gst.Caps('audio/x-raw,channels=1,rate=8000')),
+            (vorbis_caps, None, audio_defaults, None, Gst.Caps("audio/x-raw,channels=1,rate=8000")),
             (avenc_ac3_caps, None, audio_defaults, Gst.Caps("audio/x-raw, channels=(int)6, 
rate=(int)44100"), Gst.Caps("audio/x-raw, channels=(int)6, rate=(int)44100")),
         ]
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]