Commit ffe5eb17 authored by Thibault Saunier's avatar Thibault Saunier

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: 's avatarAlex Băluț <&lt;alexandru.balut@gmail.com&gt;>
Differential Revision: https://phabricator.freedesktop.org/D1875
parent 6244f2ed
......@@ -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.
......
......@@ -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):
......
......@@ -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)
......
......@@ -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([
......
......@@ -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")),
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment