def test_recovery(self): """Checks the recovery mechanism.""" pipe = Pipeline(common.create_pitivi_mock()) pipe.set_timeline(GES.Timeline()) pipeline_died_cb = mock.Mock() pipe.connect("died", pipeline_died_cb) with mock.patch.object(pipe, "set_state") as set_state: pipe.pause() set_state.assert_called_once_with(Gst.State.PAUSED) self.assertEqual(pipe._attempted_recoveries, 0) self.assertFalse(pipeline_died_cb.called) for i in range(MAX_RECOVERIES): with mock.patch.object(pipe, "set_state") as set_state: set_state.return_value = Gst.StateChangeReturn.SUCCESS self.post_fake_error_message(pipe) set_state.assert_has_calls( [mock.call(Gst.State.NULL), mock.call(Gst.State.PAUSED)]) self.assertEqual(set_state.call_count, 2) self.assertEqual(pipe._attempted_recoveries, i + 1) self.assertFalse(pipeline_died_cb.called) with mock.patch.object(pipe, "set_state") as set_state: self.post_fake_error_message(pipe) set_state.assert_not_called() self.assertTrue(pipeline_died_cb.called) self.assertEqual(pipe._attempted_recoveries, MAX_RECOVERIES)
def __init__(self, uri): timeline = GES.Timeline() trackv = GES.Track.video_raw_new() self.layer = GES.Layer() self.pipeline = GES.TimelinePipeline() self.pipeline.add_timeline(timeline) timeline.add_track(trackv) timeline.add_layer(self.layer) GES.Asset.new_async(GES.UriClip, uri, None, self.discoveredCb, None) self.loop = GLib.MainLoop() self.loop.run()
def __init__(self, uri): timeline = GES.Timeline() trackv = GES.Track.video_raw_new() layer = GES.Layer() self.pipeline = GES.TimelinePipeline() self.pipeline.add_timeline(timeline) timeline.add_track(trackv) timeline.add_layer(layer) src = GES.UriClip.new(uri=uri) src.set_start(long(0)) src.set_duration(long(10 * Gst.SECOND)) print src layer.add_object(src)
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 testTimeline(self, timeline): timeline.set_easing_duration(600) Gst.init([]) GES.init() self.project = GES.Project(uri=None, extractable_type=GES.Timeline) bTimeline = GES.Timeline() bTimeline.add_track(GES.Track.audio_raw_new()) bTimeline.add_track(GES.Track.video_raw_new()) self.bTimeline = bTimeline timeline.setTimeline(bTimeline) layer = GES.Layer() bTimeline.add_layer(layer) self.bTimeline = bTimeline self.project.connect("asset-added", self._doAssetAddedCb, layer) self.project.create_asset("file://" + sys.argv[2], GES.UriClip)
def test_async_done_not_received(self): """Checks the recovery when the ASYNC_DONE message timed out.""" ges_timeline = GES.Timeline() self.assertTrue(ges_timeline.add_track(GES.VideoTrack.new())) ges_layer = ges_timeline.append_layer() uri = common.get_sample_uri("tears_of_steel.webm") asset = GES.UriClipAsset.request_sync(uri) ges_clip = asset.extract() self.assertTrue(ges_layer.add_clip(ges_clip)) self.assertFalse(ges_timeline.is_empty()) pipe = Pipeline(app=common.create_pitivi_mock()) pipe.set_timeline(ges_timeline) self.assertFalse(pipe._busy_async) self.assertEqual(pipe._recovery_state, SimplePipeline.RecoveryState.NOT_RECOVERING) # Pretend waiting for async-done timed out. # We mock set_state because we don't actually care about the state, # and setting the state to PAUSED could show a video window. with mock.patch.object(pipe, "set_state"): pipe._async_done_not_received_cb() # Make sure the pipeline started a watchdog timer waiting for async-done # as part of setting the state from NULL to PAUSED. self.assertTrue(pipe._busy_async) self.assertEqual(pipe._attempted_recoveries, 1) self.assertEqual(pipe._recovery_state, SimplePipeline.RecoveryState.STARTED_RECOVERING) # Pretend the state changed to READY. message = mock.Mock() message.type = Gst.MessageType.STATE_CHANGED message.src = pipe._pipeline message.parse_state_changed.return_value = (Gst.State.NULL, Gst.State.READY, Gst.State.PAUSED) pipe._busMessageCb(None, message) # Pretend the state changed to PAUSED. message.parse_state_changed.return_value = (Gst.State.READY, Gst.State.PAUSED, Gst.State.VOID_PENDING) self.assertEqual(pipe._next_seek, None) pipe._busMessageCb(None, message) self.assertEqual(pipe._recovery_state, SimplePipeline.RecoveryState.SEEKED_AFTER_RECOVERING) self.assertTrue(pipe._busy_async) # The pipeline should have tried to seek back to the last position. self.assertEqual(pipe._next_seek, 0) # Pretend the state change (to PAUSED) async operation succeeded. message.type = Gst.MessageType.ASYNC_DONE with mock.patch.object(pipe, "get_state") as get_state: get_state.return_value = (0, Gst.State.PAUSED, 0) pipe._busMessageCb(None, message) self.assertEqual(pipe._recovery_state, SimplePipeline.RecoveryState.NOT_RECOVERING) # Should still be busy because of seeking to _next_seek. self.assertTrue(pipe._busy_async) self.assertIsNone(pipe._next_seek) # Pretend the seek async operation finished. message.type = Gst.MessageType.ASYNC_DONE pipe._busMessageCb(None, message) self.assertEqual(pipe._recovery_state, SimplePipeline.RecoveryState.NOT_RECOVERING) self.assertFalse(pipe._busy_async) self.assertIsNone(pipe._next_seek)