Commit 139e582f authored by yatinmaan's avatar yatinmaan

Addressed comments

parent e76d4713
Pipeline #71047 failed with stages
in 13 minutes and 59 seconds
......@@ -285,7 +285,7 @@ class PreferencesDialog(Loggable):
self._add_page("_plugins", page)
def __add_proxies_section(self):
"""Adds a section for proxy settings"""
"""Adds a section for proxy settings."""
grid = Gtk.Grid()
grid.set_border_width(SPACING)
......@@ -374,8 +374,7 @@ class PreferencesDialog(Loggable):
project = self.app.project_manager.current_project
label = content.get_children()[0]
label.set_text(_("The setting below only affects new projects by"
" default.\nScaled Proxy resolution for the current project is "
label.set_text(_("Scaled Proxy resolution for the current project is "
"%dx%d px" % (project.scaled_proxy_width,
project.scaled_proxy_height)))
......@@ -383,14 +382,11 @@ class PreferencesDialog(Loggable):
height_input):
project = self.app.project_manager.current_project
width = width_input.getWidgetValue()
height = height_input.getWidgetValue()
project.scaled_proxy_width = width
project.scaled_proxy_height = height
project.scaled_proxy_width = width_input.getWidgetValue()
project.scaled_proxy_height = height_input.getWidgetValue()
self.__update_infobar_content(infobar.get_content_area())
Gtk.Widget.do_hide(infobar)
infobar.hide()
def __set_transcoding_jobs_cb(self, _unused, num_input):
num = num_input.getWidgetValue()
......
......@@ -365,7 +365,7 @@ class AssetThumbnail(Loggable):
icon = icon_theme.load_icon("dialog-question", size, 0)
return icon
def _setState(self):
def _set_state(self):
asset = self.__asset
target = asset.get_proxy_target()
......@@ -387,7 +387,7 @@ class AssetThumbnail(Loggable):
self.state = self.NO_PROXY
def decorate(self):
self._setState()
self._set_state()
if self.state == self.NO_PROXY:
self.small_thumb = self.src_small
self.large_thumb = self.src_large
......@@ -943,7 +943,7 @@ class MediaLibraryWidget(Gtk.Box, Loggable):
self._addAsset(asset)
if self._project.loaded:
self.app.gui.editor.timeline_ui.switchProxies(asset, proxy)
self.app.gui.editor.timeline_ui.switch_proxies(asset, proxy)
def _assetAddedCb(self, unused_project, asset):
"""Checks whether the asset added to the project should be shown."""
......
......@@ -1802,6 +1802,11 @@ class Project(Loggable, GES.Project):
if not aencoder == "" and not aencoder == self.aencoder:
self.aencoder = aencoder
def clips(self):
for layer in self.ges_timeline.get_layers():
for clip in layer.get_clips():
yield clip
@property
def containersettings(self):
cache_key = (self.container_profile, self.muxer)
......
......@@ -436,8 +436,7 @@ class RenderDialog(Loggable):
# the current container format.
self.preferred_vencoder = self.project.vencoder
self.preferred_aencoder = self.project.aencoder
self.__unproxiedClips = {}
self.__unscaled_clips = {}
self.__replaced_assets = {}
self.frame_rate_combo.set_model(frame_rates)
self.channels_combo.set_model(audio_channels)
......@@ -893,7 +892,7 @@ class RenderDialog(Loggable):
self._time_spent_paused = 0
self._pipeline.set_state(Gst.State.NULL)
self.project.set_rendering(False)
self._useProxyAssets()
self._use_proxy_assets()
self._disconnectFromGst()
self._pipeline.set_mode(GES.PipelineFlags.FULL_PREVIEW)
self._pipeline.set_state(Gst.State.PAUSED)
......@@ -941,93 +940,61 @@ class RenderDialog(Loggable):
except GLib.Error as e:
self.warning("GSound failed to play: %s", e)
def __replace_scaled_proxies(self):
replace_all = self.__never_use_proxies.get_active()
for layer in self.app.project_manager.current_project.ges_timeline.get_layers():
for clip in layer.get_clips():
if not isinstance(clip, GES.UriClip):
continue
asset = clip.get_asset()
asset_target = asset.get_proxy_target()
if not asset_target:
# The asset is not a proxy.
continue
if self.app.proxy_manager.is_hq_proxy(asset):
# The asset is not a scaled proxy.
continue
if not replace_all:
# Don't replace scaled proxy if it matches the scale percent
width, height = self.project.getVideoWidthAndHeight(render=True)
stream = asset.get_info().get_video_streams()[0]
asset_res = [stream.get_width(), stream.get_height()]
if asset_res[0] == width and asset_res[1] == height:
continue
# Replace with HQ Proxy if available
hq_proxy = GES.Asset.request(GES.UriClip,
self.app.proxy_manager.getProxyUri(asset_target))
if hq_proxy is not None:
clip.set_asset(hq_proxy)
self.__unscaled_clips[clip] = asset
continue
# Replace with original asset
clip.set_asset(asset_target)
self.__unscaled_clips[clip] = asset
def __maybeUseSourceAsset(self):
self.__replace_scaled_proxies()
if self.__always_use_proxies.get_active():
self.debug("Rendering from proxies, not replacing assets")
return
def _asset_replacement(self, clip):
if not isinstance(clip, GES.UriClip):
return None
for layer in self.app.project_manager.current_project.ges_timeline.get_layers():
for clip in layer.get_clips():
if not isinstance(clip, GES.UriClip):
continue
asset = clip.get_asset()
asset_target = asset.get_proxy_target()
if not asset_target:
# The asset is not a proxy.
return None
asset = clip.get_asset()
asset_target = asset.get_proxy_target()
if not asset_target:
# The asset is not a proxy.
continue
# Replace all proxies
if self.__never_use_proxies.get_active():
return asset_target
if self.__automatically_use_proxies.get_active():
if not self.app.proxy_manager.isAssetFormatWellSupported(
asset_target):
self.info("Original asset %s format not well supported, "
"rendering from proxy.",
asset_target.props.id)
continue
# Use HQ Proxy (or equivalent) only for unsupported assets
if self.__automatically_use_proxies.get_active():
if self.app.proxy_manager.isAssetFormatWellSupported(
asset_target):
return asset_target
else:
proxy_unsupported = True
self.info("Original asset %s format well supported, "
"rendering from real asset.",
asset_target.props.id)
# Use HQ Proxy (or equivalent) whenever available
if self.__always_use_proxies.get_active() or proxy_unsupported:
if self.app.proxy_manager.is_hq_proxy(asset):
return None
if asset_target.get_error():
# The original asset cannot be used.
continue
if self.app.proxy_manager.is_scaled_proxy(asset):
width, height = self.project.getVideoWidthAndHeight(render=True)
stream = asset.get_info().get_video_streams()[0]
asset_res = [stream.get_width(), stream.get_height()]
clip.set_asset(asset_target)
self.info("Using original asset %s (instead of proxy %s)",
asset_target.get_id(),
asset.get_id())
self.__unproxiedClips[clip] = asset
if asset_res[0] == width and asset_res[1] == height:
# Check whether the scaled proxy size matches the render size
# exactly. If the size is same, render from the scaled proxy
# to avoid double scaling.
return None
def _useProxyAssets(self):
for clip, asset in self.__unproxiedClips.items():
self.info("Reverting to using HQ proxy asset %s", asset)
clip.set_asset(asset)
for clip, asset in self.__unscaled_clips.items():
self.info("Reverting to using scaled proxy asset %s", asset)
hq_proxy = GES.Asset.request(GES.UriClip,
self.app.proxy_manager.getProxyUri(asset_target))
return hq_proxy or None
def __replace_proxies(self):
for clip in self.app.project_manager.current_project.clips():
asset = self._asset_replacement(clip)
if asset:
self.__replaced_assets[clip] = clip.get_asset()
clip.set_asset(asset)
def _use_proxy_assets(self):
for clip, asset in self.__replaced_assets.items():
self.info("Reverting to using proxy asset %s", asset)
clip.set_asset(asset)
self.__unproxiedClips = {}
self.__unscaled_clips = {}
self.__replaced_assets = {}
# ------------------- Callbacks ------------------------------------------ #
......@@ -1043,7 +1010,7 @@ class RenderDialog(Loggable):
def _renderButtonClickedCb(self, unused_button):
"""Starts the rendering process."""
self.__maybeUseSourceAsset()
self.__replace_proxies()
self.outfile = os.path.join(self.filebutton.get_uri(),
self.fileentry.get_text())
self.progress = RenderingProgressDialog(self.app, self)
......
......@@ -1338,7 +1338,7 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
# Public API
def switchProxies(self, asset, proxy):
def switch_proxies(self, asset, proxy):
proxied = asset.props.proxy
unproxy = False
......
......@@ -154,7 +154,7 @@ class ProxyManager(GObject.Object, Loggable):
self.error("Not supporting any proxy formats!")
return
def _get_scaled_res(self, asset, max_width, max_height):
def _scale_asset_resolution(self, asset, max_width, max_height):
stream = asset.get_info().get_video_streams()[0]
width = stream.get_width()
height = stream.get_height()
......@@ -162,10 +162,10 @@ class ProxyManager(GObject.Object, Loggable):
if aspect_ratio.numerator >= width or aspect_ratio.denominator >= height:
self.log("Unscalable aspect ratio.")
return(width, height)
return (width, height)
if aspect_ratio.numerator >= max_width or aspect_ratio.denominator >= max_height:
self.log("Cannot scale to target resolution.")
return(width, height)
return (width, height)
if height > max_height:
scaling_factor = max_height // aspect_ratio.denominator
......@@ -258,10 +258,7 @@ class ProxyManager(GObject.Object, Loggable):
@classmethod
def is_proxy_asset(cls, obj):
if cls.is_scaled_proxy(obj) or cls.is_hq_proxy(obj):
return True
return False
return cls.is_scaled_proxy(obj) or cls.is_hq_proxy(obj)
@classmethod
def is_scaled_proxy(cls, obj):
......@@ -313,7 +310,7 @@ class ProxyManager(GObject.Object, Loggable):
if scaled:
max_w = self.app.project_manager.current_project.scaled_proxy_width
max_h = self.app.project_manager.current_project.scaled_proxy_height
t_width, t_height = self._get_scaled_res(asset, max_w, max_h)
t_width, t_height = self._scale_asset_resolution(asset, max_w, max_h)
proxy_res = "%sx%s" % (t_width, t_height)
return "%s.%s.%s.%s" % (asset.get_id(), file_size, proxy_res,
self.scaled_proxy_extension)
......@@ -333,14 +330,11 @@ class ProxyManager(GObject.Object, Loggable):
stream = asset.get_info().get_video_streams()[0]
asset_res = (stream.get_width(), stream.get_height())
target_res = self._get_scaled_res(asset,
target_res = self._scale_asset_resolution(asset,
self.app.project_manager.current_project.scaled_proxy_width,
self.app.project_manager.current_project.scaled_proxy_height)
if asset_res == target_res:
return True
return False
return asset_res == target_res
def __assetNeedsTranscoding(self, asset, scaled=False):
if self.proxyingUnsupported:
......@@ -520,40 +514,37 @@ class ProxyManager(GObject.Object, Loggable):
return True
return False
def is_asset_queued_for_scaling(self, asset):
all_transcoders = self.__running_transcoders + self.__pending_transcoders
for transcoder in all_transcoders:
ext = transcoder.props.dest_uri
scaling = ext.endswith("." + self.scaled_proxy_extension + ".part")
if scaling and asset.props.id == transcoder.props.src_uri:
return True
return False
def is_asset_queued_for_optimization(self, asset):
all_transcoders = self.__running_transcoders + self.__pending_transcoders
for transcoder in all_transcoders:
ext = transcoder.props.dest_uri
optimisation = ext.endswith("." + self.hq_proxy_extension + ".part")
if optimisation and asset.props.id == transcoder.props.src_uri:
return True
return False
def is_asset_queued(self, asset):
def is_asset_queued(self, asset, optimisation=True, scaling=True):
"""Returns whether the specified asset is queued for transcoding.
Args:
asset (GES.Asset): The asset to check.
optimisation(bool): Whether to check optimisation queue
scaling(bool): Whether to check scaling queue
Returns:
bool: True if the asset is being transcoded or pending.
"""
if self.is_asset_queued_for_scaling(asset) or \
self.is_asset_queued_for_optimization(asset):
return True
all_transcoders = self.__running_transcoders + self.__pending_transcoders
is_queued = False
for transcoder in all_transcoders:
transcoder_uri = transcoder.props.dest_uri
scaling_ext = "." + self.scaled_proxy_extension + ".part"
optimisation_ext = "." + self.hq_proxy_extension + ".part"
return False
scaling_transcoder = transcoder_uri.endswith(scaling_ext)
optimisation_transcoder = transcoder_uri.endswith(optimisation_ext)
if transcoder.props.src_uri == asset.props.id:
if optimisation and optimisation_transcoder:
is_queued = True
break
if scaling and scaling_transcoder:
is_queued = True
break
return is_queued
def __createTranscoder(self, asset, width=None, height=None, shadow=False):
self._total_time_to_transcode += asset.get_duration() / Gst.SECOND
......@@ -652,12 +643,12 @@ class ProxyManager(GObject.Object, Loggable):
self.add_job(asset, shadow=True)
if scaled:
if self.is_asset_queued_for_scaling(asset):
if self.is_asset_queued(asset, optimisation=False):
self.log("Asset already queued for scaling: %s", asset)
return
else:
if self.is_asset_queued_for_optimization(asset):
if self.is_asset_queued(asset, scaling=False):
self.log("Asset already queued for optimization: %s", asset)
return
......@@ -684,7 +675,7 @@ class ProxyManager(GObject.Object, Loggable):
if scaled:
w = self.app.project_manager.current_project.scaled_proxy_width
h = self.app.project_manager.current_project.scaled_proxy_height
t_width, t_height = self._get_scaled_res(asset, w, h)
t_width, t_height = self._scale_asset_resolution(asset, w, h)
self.__createTranscoder(asset, width=t_width, height=t_height, shadow=shadow)
else:
self.__createTranscoder(asset, shadow=shadow)
......
......@@ -123,7 +123,7 @@ class BaseTestMediaLibrary(common.TestCase):
was_in_progress = True
try:
old_set_state = medialibrary.AssetThumbnail._setState
old_set_state = medialibrary.AssetThumbnail._set_state
# Check proxy creation progress and thumbnail icon
self.assertFalse("Proxy creation progress:" in
......@@ -135,7 +135,7 @@ class BaseTestMediaLibrary(common.TestCase):
self.medialibrary.storemodel[0][medialibrary.COL_THUMB_DECORATOR].state == no_proxy or
self.medialibrary.storemodel[0][medialibrary.COL_THUMB_DECORATOR].state == unsupported)
medialibrary.AssetThumbnail._setState = check_set_state
medialibrary.AssetThumbnail._set_state = check_set_state
project.use_proxies_for_assets([asset], scaled)
self.assertTrue("Proxy creation progress:" in
......@@ -143,7 +143,7 @@ class BaseTestMediaLibrary(common.TestCase):
self.mainloop.run(timeout_seconds=10)
finally:
medialibrary.AssetThumbnail._setState = old_set_state
medialibrary.AssetThumbnail._set_state = old_set_state
if check_progress:
self.assertTrue(was_in_progress)
......
......@@ -365,7 +365,7 @@ class TestRender(BaseTestMediaLibrary):
# Patch the function that reverts assets to proxies after rendering.
from pitivi.render import RenderDialog
old_use_proxy_assets = RenderDialog._useProxyAssets
old_use_proxy_assets = RenderDialog._use_proxy_assets
def check_use_proxy_assets(self):
nonlocal layer, asset, rendering_asset
......@@ -373,11 +373,11 @@ class TestRender(BaseTestMediaLibrary):
rendering_asset = clip.get_asset()
old_use_proxy_assets(self)
RenderDialog._useProxyAssets = check_use_proxy_assets
RenderDialog._use_proxy_assets = check_use_proxy_assets
dialog = self.create_rendering_dialog(project)
self.render(dialog)
self.mainloop.run(until_empty=True)
RenderDialog._useProxyAssets = old_use_proxy_assets
RenderDialog._use_proxy_assets = old_use_proxy_assets
# Check rendering did not use scaled proxy
self.assertFalse(proxy_manager.is_scaled_proxy(rendering_asset))
......@@ -424,14 +424,14 @@ class TestRender(BaseTestMediaLibrary):
old_use_proxy_assets(self)
try:
old_use_proxy_assets = RenderDialog._useProxyAssets
old_use_proxy_assets = RenderDialog._use_proxy_assets
RenderDialog._useProxyAssets = check_use_proxy_assets
RenderDialog._use_proxy_assets = check_use_proxy_assets
dialog = self.create_rendering_dialog(project)
self.render(dialog)
self.mainloop.run(until_empty=True)
finally:
RenderDialog._useProxyAssets = old_use_proxy_assets
RenderDialog._use_proxy_assets = old_use_proxy_assets
# Check rendering used HQ proxy
self.assertTrue(proxy_manager.is_hq_proxy(rendering_asset))
......
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