def test_commit_timeline_after(self): """Checks the recovery mechanism.""" pipe = Pipeline(common.create_pitivi_mock()) timeline = GES.Timeline() pipe.set_timeline(timeline) with mock.patch.object(pipe, "get_state") as get_state: get_state.return_value = (0, Gst.State.PAUSED, 0) with mock.patch.object(timeline, "commit") as commit: with pipe.commit_timeline_after(): pipe.commit_timeline() self.assertEqual(commit.call_count, 1) with mock.patch.object(timeline, "commit") as commit: with pipe.commit_timeline_after(): self.assertEqual(pipe._prevent_commits, 1) with pipe.commit_timeline_after(): self.assertEqual(pipe._prevent_commits, 2) pipe.commit_timeline() self.assertEqual(commit.call_count, 0) self.assertEqual(commit.call_count, 1)
def test_commit_timeline_after(self): """Checks the recovery mechanism.""" pipe = Pipeline(common.create_pitivi_mock()) timeline = GES.Timeline() pipe.set_timeline(timeline) with mock.patch.object(pipe, "getState") as get_state: get_state.return_value = (0, Gst.State.PAUSED, 0) with mock.patch.object(timeline, "commit") as commit: with pipe.commit_timeline_after(): pipe.commit_timeline() self.assertEqual(commit.call_count, 1) with mock.patch.object(timeline, "commit") as commit: with pipe.commit_timeline_after(): self.assertEqual(pipe._prevent_commits, 1) with pipe.commit_timeline_after(): self.assertEqual(pipe._prevent_commits, 2) pipe.commit_timeline() self.assertEqual(commit.call_count, 0) self.assertEqual(commit.call_count, 1)
class ClapMixer(object): def __init__(self): self.__timeline = GES.Timeline.new() self.__timeline.add_track(GES.AudioTrack.new()) self.pipeline = Pipeline() self.pipeline.set_timeline(self.__timeline) self.__clap_asset = None self.__clap_layer = None self.__asset_layer = None self.reset() GES.Asset.request_async(GES.UriClip, CLAP_ASSET, None, self.__clap_discovered_cb, None) def set_asset(self, asset): if self.__asset_layer is not None: self.__timeline.remove_layer(self.__asset_layer) if asset is None: return self.__asset_layer = self.__timeline.append_layer() self.__asset_layer.add_asset(asset, 0, 0, Gst.CLOCK_TIME_NONE, GES.TrackType.AUDIO) if self.pipeline.getState() in (Gst.State.PAUSED, Gst.State.PLAYING): self.pipeline.commit_timeline() def set_positions(self, positions): self.__positions = positions if self.__clap_asset: self.__setup_claps() def reset(self): self.pipeline.pause() # nle isn't thread-safe below PAUSED self.pipeline.get_state(timeout=Gst.CLOCK_TIME_NONE) self.pipeline.simple_seek(0) self.set_positions(None) self.set_asset(None) def __setup_claps(self): if self.__clap_layer is not None: self.__timeline.remove_layer(self.__clap_layer) self.__clap_layer = self.__timeline.append_layer() if self.__positions is None: return for position in self.__positions: self.__clap_layer.add_asset(self.__clap_asset, position, 0, Gst.CLOCK_TIME_NONE, GES.TrackType.AUDIO) if self.pipeline.getState() in (Gst.State.PAUSED, Gst.State.PLAYING): self.pipeline.commit_timeline() def __clap_discovered_cb(self, asset, result, unused): self.__clap_asset = asset self.__setup_claps()