Commit 12af40bc authored by Alexandru Băluț's avatar Alexandru Băluț

project: Fix restoring the project w/h after render

Sometimes int(x / y) * y != x

Differential Revision: https://phabricator.freedesktop.org/D1927
parent 0e7da200
......@@ -742,6 +742,8 @@ class Project(Loggable, GES.Project):
self._vcodecsettings_cache = {}
# A ((container_profile, aencoder) -> acodecsettings) map.
self._acodecsettings_cache = {}
# Whether the current settings are temporary and should be reverted,
# as they apply only for rendering.
self._has_rendering_values = False
def _scenarioDoneCb(self, scenario):
......@@ -807,23 +809,23 @@ class Project(Loggable, GES.Project):
return
self.set_meta("author", author)
# Encoding related properties
def set_rendering(self, rendering):
"""Sets the a/v restrictions for rendering or for editing."""
self._ensureAudioRestrictions()
self._ensureVideoRestrictions()
video_restrictions = self.video_profile.get_restriction().copy_nth(0)
video_restrictions_struct = video_restrictions[0]
if rendering and self._has_rendering_values != rendering:
width = int(video_restrictions_struct["width"] * self.render_scale / 100)
height = int(video_restrictions_struct["height"] * self.render_scale / 100)
video_restrictions.set_value('width', width)
video_restrictions.set_value('height', height)
elif self._has_rendering_values != rendering:
width = int(video_restrictions_struct["width"] / self.render_scale * 100)
height = int(video_restrictions_struct["height"] / self.render_scale * 100)
if self._has_rendering_values != rendering:
if rendering:
video_restrictions_struct = video_restrictions[0]
self.__width = video_restrictions_struct["width"]
self.__height = video_restrictions_struct["height"]
width = int(self.__width * self.render_scale / 100)
height = int(self.__height * self.render_scale / 100)
else:
width = self.__width
height = self.__height
video_restrictions.set_value("width", width)
video_restrictions.set_value("height", height)
......
......@@ -606,12 +606,12 @@ class TestProjectSettings(common.TestCase):
class TestExportSettings(TestCase):
def testMasterAttributes(self):
self._testMasterAttribute('muxer', dependant_attr='containersettings')
self._testMasterAttribute('vencoder', dependant_attr='vcodecsettings')
self._testMasterAttribute('aencoder', dependant_attr='acodecsettings')
def test_master_attributes(self):
self._check_master_attribute("muxer", dependant_attr="containersettings")
self._check_master_attribute("vencoder", dependant_attr="vcodecsettings")
self._check_master_attribute("aencoder", dependant_attr="acodecsettings")
def _testMasterAttribute(self, attr, dependant_attr):
def _check_master_attribute(self, attr, dependant_attr):
"""Test changing the specified attr has effect on its dependent attr."""
project = common.create_project()
......@@ -645,3 +645,37 @@ class TestExportSettings(TestCase):
setattr(project, attr, attr_value2)
self.assertFalse("key1" in getattr(project, dependant_attr))
self.assertFalse("key2" in getattr(project, dependant_attr))
def test_set_rendering(self):
"""Checks the set_rendering method."""
mainloop = common.create_main_loop()
def loaded_cb(project, timeline):
project.addUris([common.get_sample_uri("tears_of_steel.webm")])
def progress_cb(project, progress, estimated_time):
if progress == 100:
mainloop.quit()
# Create a blank project and add some assets.
project = common.create_project()
project.connect_after("loaded", loaded_cb)
project.connect_after("asset-loading-progress", progress_cb)
mainloop.run()
# The video settings should match tears_of_steel.webm
self.assertEqual(project.videowidth, 960)
self.assertEqual(project.videoheight, 400)
project.render_scale = 3
# Pretend we're rendering.
project.set_rendering(True)
self.assertEqual(project.videowidth, 28)
self.assertEqual(project.videoheight, 12)
# Pretend we're not rendering anymore.
project.set_rendering(False)
self.assertEqual(project.videowidth, 960)
self.assertEqual(project.videoheight, 400)
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