[pitivi] proxy: Refactor code into asset_can_be_proxied
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] proxy: Refactor code into asset_can_be_proxied
- Date: Thu, 10 Oct 2019 02:16:48 +0000 (UTC)
commit 2314e9f124db37f3dbbb663acda7f07fce64c9ea
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Thu Oct 10 00:54:33 2019 +0200
proxy: Refactor code into asset_can_be_proxied
pitivi/project.py | 11 ++---------
pitivi/utils/proxy.py | 11 +++++++++++
tests/test_proxy.py | 27 +++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 9 deletions(-)
---
diff --git a/pitivi/project.py b/pitivi/project.py
index 2b63f24f..611eae35 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -1565,12 +1565,7 @@ class Project(Loggable, GES.Project):
proxy_manager = self.app.proxy_manager
originals = []
for asset in assets:
- if scaled:
- is_proxied = proxy_manager.is_scaled_proxy(asset) and \
- not proxy_manager.asset_matches_target_res(asset)
- else:
- is_proxied = proxy_manager.is_hq_proxy(asset)
- if not is_proxied:
+ if proxy_manager.asset_can_be_proxied(asset, scaled):
target = asset.get_proxy_target()
uri = proxy_manager.getProxyUri(asset, scaled=scaled)
if target and target.props.id == uri:
@@ -1578,9 +1573,7 @@ class Project(Loggable, GES.Project):
" its recreation")
target.unproxy(asset)
- if not asset.is_image():
- # The asset is not a proxy and not an image.
- originals.append(asset)
+ originals.append(asset)
if originals:
with self.app.action_log.started("Proxying assets"):
diff --git a/pitivi/utils/proxy.py b/pitivi/utils/proxy.py
index a086430e..2a9277b0 100644
--- a/pitivi/utils/proxy.py
+++ b/pitivi/utils/proxy.py
@@ -397,6 +397,17 @@ class ProxyManager(GObject.Object, Loggable):
self.info("%s does not need proxy", asset.get_id())
return False
+ def asset_can_be_proxied(self, asset, scaled=False):
+ """Returns whether the asset is not a proxy nor a proper proxy."""
+ if asset.is_image():
+ return False
+
+ if scaled:
+ return not self.is_scaled_proxy(asset) or \
+ self.asset_matches_target_res(asset)
+ else:
+ return not self.is_hq_proxy(asset)
+
def __startTranscoder(self, transcoder):
self.debug("Starting %s", transcoder.props.src_uri)
if self._start_proxying_time == 0:
diff --git a/tests/test_proxy.py b/tests/test_proxy.py
index 819f47d5..8e0888ef 100644
--- a/tests/test_proxy.py
+++ b/tests/test_proxy.py
@@ -110,3 +110,30 @@ class TestProxyManager(common.TestCase):
app.project_manager.current_project.scaled_proxy_height = stream.get_height() + dh
matches = dw >= 0 and dh >= 0
self.assertEqual(app.proxy_manager.asset_matches_target_res(asset), matches, (dw, dh))
+
+ def test_asset_can_be_proxied(self):
+ """Checks the asset_can_be_proxied method."""
+ app = common.create_pitivi_mock()
+ manager = app.proxy_manager
+
+ uri = common.get_sample_uri("flat_colour3_320x180.png")
+ image = GES.UriClipAsset.request_sync(uri)
+ self.assertFalse(manager.asset_can_be_proxied(image))
+
+ uri = common.get_sample_uri("30fps_numeroted_frames_blue.webm")
+ video = GES.UriClipAsset.request_sync(uri)
+ self.assertTrue(manager.asset_can_be_proxied(video, scaled=True))
+ self.assertTrue(manager.asset_can_be_proxied(video))
+ with mock.patch.object(manager, "is_hq_proxy") as hq:
+ hq.return_value = True
+ self.assertTrue(manager.asset_can_be_proxied(video, scaled=True))
+ self.assertFalse(manager.asset_can_be_proxied(video))
+ with mock.patch.object(manager, "is_scaled_proxy") as scaled:
+ scaled.return_value = True
+ with mock.patch.object(manager, "asset_matches_target_res") as matches:
+ matches.return_value = False
+ self.assertFalse(manager.asset_can_be_proxied(video, scaled=True))
+ self.assertTrue(manager.asset_can_be_proxied(video))
+ matches.return_value = True
+ self.assertTrue(manager.asset_can_be_proxied(video, scaled=True))
+ self.assertTrue(manager.asset_can_be_proxied(video))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]