def test_thumb_interval(self):
        """Checks the `thumb_interval` property."""
        ges_elem = mock.Mock()
        ges_elem.props.uri = common.get_sample_uri("1sec_simpsons_trailer.mp4")
        ges_elem.props.id = common.get_sample_uri("1sec_simpsons_trailer.mp4")
        previewer = VideoPreviewer(ges_elem, 94)
        previewer.thumb_width = 1  # Just so it's not None.

        def run_thumb_interval(interval):
            """Runs thumb_interval."""
            with mock.patch(
                    "pitivi.utils.timeline.Zoomable.pixelToNs") as pixel_to_ns:
                pixel_to_ns.return_value = interval
                return previewer.thumb_interval

        self.assertEqual(run_thumb_interval(1), THUMB_PERIOD)
        self.assertEqual(run_thumb_interval(THUMB_PERIOD - 1), THUMB_PERIOD)
        self.assertEqual(run_thumb_interval(THUMB_PERIOD), THUMB_PERIOD)

        self.assertEqual(run_thumb_interval(THUMB_PERIOD + 1),
                         2 * THUMB_PERIOD)
        self.assertEqual(run_thumb_interval(2 * THUMB_PERIOD - 1),
                         2 * THUMB_PERIOD)
        self.assertEqual(run_thumb_interval(2 * THUMB_PERIOD),
                         2 * THUMB_PERIOD)
Exemple #2
0
 def test_scanning(self):
     """Checks the scanning of the URIs."""
     valid_uri = common.get_sample_uri("tears_of_steel.webm")
     uris = self._scan([valid_uri,
                        common.get_sample_uri("missing.webm"),
                        "http://pitivi.org/very_real.webm"])
     self.assertEqual(len(uris), 1, uris)
     self.assertIn(valid_uri, uris)
Exemple #3
0
 def test_scanning(self):
     """Checks the scanning of the URIs."""
     valid_uri = common.get_sample_uri("tears_of_steel.webm")
     uris = self._scan([valid_uri,
                        common.get_sample_uri("missing.webm"),
                        "http://pitivi.org/very_real.webm"])
     self.assertEqual(len(uris), 1, uris)
     self.assertIn(valid_uri, uris)
    def test_containment(self):
        """Checks the __contains/getitem/setitem__ methods."""
        with tempfile.TemporaryDirectory() as tmpdirname:
            with mock.patch("pitivi.timeline.previewers.xdg_cache_home"
                            ) as xdg_cache_home:
                xdg_cache_home.return_value = tmpdirname
                sample_uri = common.get_sample_uri("1sec_simpsons_trailer.mp4")
                thumb_cache = ThumbnailCache(sample_uri)
                self.assertFalse(Gst.SECOND in thumb_cache)
                with self.assertRaises(KeyError):
                    # pylint: disable=pointless-statement
                    thumb_cache[Gst.SECOND]

                pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB,
                                              False, 8,
                                              int(THUMB_HEIGHT * 1280 / 544),
                                              THUMB_HEIGHT)
                thumb_cache[Gst.SECOND] = pixbuf
                self.assertTrue(Gst.SECOND in thumb_cache)
                self.assertIsNotNone(thumb_cache[Gst.SECOND])
                thumb_cache.commit()

                thumb_cache = ThumbnailCache(sample_uri)
                self.assertTrue(Gst.SECOND in thumb_cache)
                self.assertIsNotNone(thumb_cache[Gst.SECOND])
Exemple #5
0
    def test_async_done_not_received(self):
        """Checks the recovery when the ASYNC_DONE message timed out."""
        ges_timeline = GES.Timeline.new()
        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)
Exemple #6
0
    def testSaveProjectWithRemovedProxy(self):
        sample_name = "30fps_numeroted_frames_red.mkv"
        with common.cloned_sample(sample_name):
            self.check_import([sample_name])

            project = self.app.project_manager.current_project
            asset = GES.UriClipAsset.request_sync(common.get_sample_uri(sample_name))
            target = asset.get_proxy_target()
            self.assertEqual(set(project.list_assets(GES.Extractable)), set([target, asset]))

            # Remove the asset
            self.medialibrary.remove_assets_action.emit("activate", None)

            # Make sure that the project has not assets anymore
            self.assertEqual(project.list_assets(GES.Extractable), [])

            # Save the project and reload it, making sure there is no asset
            # in that new project
            project_uri = Gst.filename_to_uri(tempfile.NamedTemporaryFile().name)
            project.save(project.ges_timeline, project_uri, None, True)

            self._customSetUp(project_uri)
            self.assertNotEqual(project, self.app.project_manager.current_project)
            project = self.app.project_manager.current_project
            self.assertEqual(project.list_assets(GES.Extractable), [])
    def testSetAudioProp(self):
        timeline = common.create_timeline_container()
        project = timeline.app.project_manager.current_project
        project.addUris([common.get_sample_uri("mp3_sample.mp3")])

        audio_track = [
            t for t in project.ges_timeline.tracks
            if isinstance(t, GES.AudioTrack)
        ][0]
        mainloop = common.create_main_loop()

        def progress_cb(project, progress, estimated_time):
            if progress == 100:
                mainloop.quit()

        project.connect_after("asset-loading-progress", progress_cb)
        mainloop.run()

        expected = Gst.Caps("audio/x-raw,channels=(int)2,rate=(int)44100")
        ccaps = audio_track.props.restriction_caps
        self.assertTrue(ccaps.is_equal_fixed(expected),
                        "%s != %s" % (ccaps, expected))

        project.audiochannels = 6

        expected = Gst.Caps("audio/x-raw,channels=(int)6,rate=(int)44100")
        ccaps = audio_track.props.restriction_caps
        self.assertTrue(ccaps.is_equal_fixed(expected),
                        "%s != %s" % (ccaps, expected))
    def __check_simple(self, left_click_also_seeks):
        timeline_container = create_timeline_container()
        timeline = timeline_container.timeline
        timeline.app.settings.leftClickAlsoSeeks = left_click_also_seeks
        ges_layer = timeline.ges_timeline.append_layer()
        asset = GES.UriClipAsset.request_sync(
            common.get_sample_uri("1sec_simpsons_trailer.mp4"))
        ges_clip1 = ges_layer.add_asset(asset, 0 * Gst.SECOND, 0,
            1 * Gst.SECOND, GES.TrackType.UNKNOWN)
        ges_clip2 = ges_layer.add_asset(asset, 1 * Gst.SECOND, 0,
            1 * Gst.SECOND, GES.TrackType.UNKNOWN)

        event = mock.Mock()
        event.get_button.return_value = (True, 1)
        timeline._seek = mock.Mock()
        timeline._seek.return_value = True
        timeline.get_clicked_layer_and_pos = mock.Mock()

        with mock.patch.object(Gtk, "get_event_widget") as get_event_widget:
            get_event_widget.return_value = timeline

            # Simulate click on first and shift+click on second clip.
            timeline.get_clicked_layer_and_pos.return_value = (ges_layer, 0.5 * Gst.SECOND)
            timeline._button_release_event_cb(None, event)
            timeline.get_parent()._shiftMask = True
            timeline.get_clicked_layer_and_pos.return_value = (ges_layer, 1.5 * Gst.SECOND)
            timeline._button_release_event_cb(None, event)
            self.__check_selected([ges_clip1, ges_clip2], [])
Exemple #9
0
 def test_missing_uri_displayed(self):
     with common.cloned_sample():
         asset_uri = common.get_sample_uri("missing.png")
         with common.created_project_file(asset_uri) as uri:
             self._customSetUp(project_uri=uri)
     self.assertTrue(
         self.medialibrary._import_warning_infobar.props.visible)
Exemple #10
0
    def load_project_with_missing_proxy(self):
        """Loads a project with missing proxies."""
        uris = [common.get_sample_uri("1sec_simpsons_trailer.mp4")]
        proxy_uri = uris[0] + ".232417.proxy.mkv"
        PROJECT_STR = """<ges version='0.3'>
  <project properties='properties;' metadatas='metadatas, name=(string)&quot;New\ Project&quot;, author=(string)Unknown, render-scale=(double)100;'>
    <encoding-profiles>
    </encoding-profiles>
    <ressources>
      <asset id='%(uri)s' extractable-type-name='GESUriClip' properties='properties, supported-formats=(int)6, duration=(guint64)1228000000;' metadatas='metadatas, audio-codec=(string)&quot;MPEG-4\ AAC\ audio&quot;, maximum-bitrate=(uint)130625, bitrate=(uint)130625, datetime=(datetime)2007-02-19T05:03:04Z, encoder=(string)Lavf54.6.100, container-format=(string)&quot;ISO\ MP4/M4A&quot;, video-codec=(string)&quot;H.264\ /\ AVC&quot;, file-size=(guint64)232417;'  proxy-id='file:///home/thiblahute/devel/pitivi/flatpak/pitivi/tests/samples/1sec_simpsons_trailer.mp4.232417.proxy.mkv' />
      <asset id='%(proxy_uri)s' extractable-type-name='GESUriClip' properties='properties, supported-formats=(int)6, duration=(guint64)1228020833;' metadatas='metadatas, container-format=(string)Matroska, audio-codec=(string)Opus, language-code=(string)en, encoder=(string)Lavf54.6.100, bitrate=(uint)64000, video-codec=(string)&quot;Motion\ JPEG&quot;, file-size=(guint64)4695434;' />
    </ressources>
    <timeline properties='properties, auto-transition=(boolean)true, snapping-distance=(guint64)0;' metadatas='metadatas, duration=(guint64)0;'>
      <track caps='video/x-raw(ANY)' track-type='4' track-id='0' properties='properties, async-handling=(boolean)false, message-forward=(boolean)true, caps=(string)&quot;video/x-raw\(ANY\)&quot;, restriction-caps=(string)&quot;video/x-raw\,\ width\=\(int\)720\,\ height\=\(int\)576\,\ framerate\=\(fraction\)25/1&quot;, mixing=(boolean)true;' metadatas='metadatas;'/>
      <track caps='audio/x-raw(ANY)' track-type='2' track-id='1' properties='properties, async-handling=(boolean)false, message-forward=(boolean)true, caps=(string)&quot;audio/x-raw\(ANY\)&quot;, restriction-caps=(string)&quot;audio/x-raw\,\ format\=\(string\)S32LE\,\ channels\=\(int\)2\,\ rate\=\(int\)44100\,\ layout\=\(string\)interleaved&quot;, mixing=(boolean)true;' metadatas='metadatas;'/>
      <layer priority='0' properties='properties, auto-transition=(boolean)true;' metadatas='metadatas, volume=(float)1;'>
        <clip id='0' asset-id='%(proxy_uri)s' type-name='GESUriClip' layer-priority='0' track-types='6' start='0' duration='1228000000' inpoint='0' rate='0' properties='properties, name=(string)uriclip0, mute=(boolean)false, is-image=(boolean)false;' >
          <source track-id='1' children-properties='properties, GstVolume::mute=(boolean)false, GstVolume::volume=(double)1;'>
            <binding type='direct' source_type='interpolation' property='volume' mode='1' track_id='1' values =' 0:0.10000000000000001  1228000000:0.10000000000000001 '/>
          </source>
          <source track-id='0' children-properties='properties, GstFramePositioner::alpha=(double)1, GstDeinterlace::fields=(int)0, GstFramePositioner::height=(int)720, GstDeinterlace::mode=(int)0, GstFramePositioner::posx=(int)0, GstFramePositioner::posy=(int)0, GstDeinterlace::tff=(int)0, GstFramePositioner::width=(int)1280;'>
            <binding type='direct' source_type='interpolation' property='alpha' mode='1' track_id='0' values =' 0:1  1228000000:1 '/>
          </source>
        </clip>
      </layer>
      <groups>
      </groups>
    </timeline>
</project>
</ges>""" % {"uri": uris[0], "proxy_uri": proxy_uri}
        app = common.create_pitivi(proxyingStrategy=ProxyingStrategy.ALL)
        proxy_manager = app.proxy_manager
        project_manager = app.project_manager

        mainloop = common.create_main_loop()

        unused, xges_path = tempfile.mkstemp(suffix=".xges")
        proj_uri = "file://" + os.path.abspath(xges_path)
        app.project_manager.saveProject(uri=proj_uri)
        medialib = medialibrary.MediaLibraryWidget(app)

        with open(proj_uri[len("file://"):], "w") as f:
            f.write(PROJECT_STR)

        # Remove proxy
        common.clean_proxy_samples()

        def closing_project_cb(*args, **kwargs):
            # Do not ask whether to save project on closing.
            return True

        def proxy_ready_cb(proxy_manager, asset, proxy):
            self.assertEqual(proxy.props.id, proxy_uri)
            mainloop.quit()

        project_manager.connect("closing-project", closing_project_cb)
        proxy_manager.connect_after("proxy-ready", proxy_ready_cb)

        app.project_manager.loadProject(proj_uri)
        return mainloop, app, medialib, proxy_uri
Exemple #11
0
    def test_prop_keyframe(self):
        """Checks the keyframe button effect."""
        uri = common.get_sample_uri("tears_of_steel.webm")
        asset = GES.UriClipAsset.request_sync(uri)
        ges_clip = asset.extract()

        # Add the clip to a timeline so it gets tracks.
        timeline = common.create_timeline_container()
        self.app = timeline.app
        ges_timeline = timeline.ges_timeline
        ges_timeline.append_layer()
        ges_layer, = ges_timeline.get_layers()
        ges_layer.add_clip(ges_clip)

        self._register_alpha_widget(
            ("black_sens_adjustment", "GstAlpha::black-sensitivity", "GstAlpha::black-sensitivity::keyframe"))
        ges_clip.add(self.alpha_effect)
        track_element = self.element_settings_widget._GstElementSettingsWidget__get_track_element_of_same_type(
            self.alpha_effect)
        prop_keyframe_button = \
            list(self.element_settings_widget._GstElementSettingsWidget__widgets_by_keyframe_button.keys())[0]

        # Control the self.prop property on the timeline
        prop_keyframe_button.set_active(True)
        self.assertEqual(track_element.ui_element._TimelineElement__controlledProperty, self.prop)
        # Revert to controlling the default property
        prop_keyframe_button.set_active(False)
        self.assertNotEqual(track_element.ui_element._TimelineElement__controlledProperty, self.prop)
Exemple #12
0
    def test_prop_keyframe(self):
        """Checks the keyframe button effect."""
        uri = common.get_sample_uri("tears_of_steel.webm")
        asset = GES.UriClipAsset.request_sync(uri)
        ges_clip = asset.extract()

        # Add the clip to a timeline so it gets tracks.
        timeline = common.create_timeline_container()
        self.app = timeline.app
        ges_timeline = timeline.ges_timeline
        ges_timeline.append_layer()
        ges_layer, = ges_timeline.get_layers()
        ges_layer.add_clip(ges_clip)

        self._register_alpha_widget(
            ("black_sens_adjustment", "GstAlpha::black-sensitivity",
             "GstAlpha::black-sensitivity::keyframe"))
        ges_clip.add(self.alpha_effect)
        track_element = self.element_settings_widget._GstElementSettingsWidget__get_track_element_of_same_type(
            self.alpha_effect)
        prop_keyframe_button = \
            list(self.element_settings_widget._GstElementSettingsWidget__widgets_by_keyframe_button.keys())[0]

        # Control the self.prop property on the timeline
        prop_keyframe_button.set_active(True)
        self.assertEqual(
            track_element.ui_element._TimelineElement__controlledProperty,
            self.prop)
        # Revert to controlling the default property
        prop_keyframe_button.set_active(False)
        self.assertNotEqual(
            track_element.ui_element._TimelineElement__controlledProperty,
            self.prop)
Exemple #13
0
    def test_control_source_value_changed(self):
        uri = common.get_sample_uri("tears_of_steel.webm")
        asset = GES.UriClipAsset.request_sync(uri)
        clip = asset.extract()
        self.layer.add_clip(clip)
        source = clip.get_children(False)[1]
        self.assertTrue(isinstance(source, GES.VideoUriSource))

        control_source = GstController.InterpolationControlSource()
        control_source.props.mode = GstController.InterpolationMode.LINEAR
        self.assert_control_source_values(control_source, [], [])

        source.set_control_source(control_source, "alpha", "direct")
        self.assert_control_source_values(control_source, [1, 1],
                                          [0, 2003000000])

        self.assertTrue(control_source.set(Gst.SECOND * 0.5, 0.2))
        self.assert_control_source_values(control_source, [1, 0.2, 1],
                                          [0, Gst.SECOND * 0.5, 2003000000])

        with self.action_log.started("keyframe changed"):
            self.assertTrue(control_source.set(Gst.SECOND * 0.5, 0.9))
        self.assert_control_source_values(control_source, [1, 0.9, 1],
                                          [0, Gst.SECOND * 0.5, 2003000000])

        self.action_log.undo()
        self.assert_control_source_values(control_source, [1, 0.2, 1],
                                          [0, Gst.SECOND * 0.5, 2003000000])

        self.action_log.redo()
        self.assert_control_source_values(control_source, [1, 0.9, 1],
                                          [0, Gst.SECOND * 0.5, 2003000000])
Exemple #14
0
    def test_asset_added_signal(self):
        app = common.create_pitivi()
        self.assertTrue(app.project_manager.newBlankProject())

        project = app.project_manager.current_project
        proxy_manager = app.proxy_manager

        mainloop = common.create_main_loop()

        def asset_added_cb(project, asset, assets):
            assets.append(asset)

        assets = []
        project.connect("asset-added", asset_added_cb, assets)

        def proxy_ready_cb(unused_proxy_manager, asset, proxy):
            mainloop.quit()

        proxy_manager.connect("proxy-ready", proxy_ready_cb)

        uris = [common.get_sample_uri("tears_of_steel.webm")]
        project.addUris(uris)

        mainloop.run()

        self.assertEqual(len(assets), 1, assets)
Exemple #15
0
    def test_launching_rendering(self):
        """Checks no exception is raised when clicking the render button."""
        timeline_container = common.create_timeline_container()
        app = timeline_container.app
        project = app.project_manager.current_project

        mainloop = common.create_main_loop()

        def asset_added_cb(project, asset):  # pylint: disable=missing-docstring
            mainloop.quit()

        project.connect("asset-added", asset_added_cb)
        uris = [common.get_sample_uri("tears_of_steel.webm")]
        project.addUris(uris)
        mainloop.run()

        layer, = project.ges_timeline.get_layers()
        layer.add_asset(project.list_assets(GES.UriClip)[0],
                        0, 0, Gst.CLOCK_TIME_NONE, GES.TrackType.UNKNOWN)

        from pitivi.render import RenderDialog, RenderingProgressDialog

        with mock.patch.object(Gtk.Builder, "__new__"):
            dialog = RenderDialog(app, project)
        with mock.patch.object(dialog, "startAction"):
            with mock.patch.object(RenderingProgressDialog, "__new__"):
                with mock.patch.object(dialog, "_pipeline"):
                    dialog._renderButtonClickedCb(None)
    def __check_simple(self, left_click_also_seeks):
        timeline_container = create_timeline_container()
        timeline = timeline_container.timeline
        timeline.app.settings.leftClickAlsoSeeks = left_click_also_seeks
        ges_layer = timeline.ges_timeline.append_layer()
        asset = GES.UriClipAsset.request_sync(
            common.get_sample_uri("1sec_simpsons_trailer.mp4"))
        ges_clip1 = ges_layer.add_asset(asset, 0 * Gst.SECOND, 0,
                                        1 * Gst.SECOND, GES.TrackType.UNKNOWN)
        ges_clip2 = ges_layer.add_asset(asset, 1 * Gst.SECOND, 0,
                                        1 * Gst.SECOND, GES.TrackType.UNKNOWN)

        event = mock.Mock()
        event.get_button.return_value = (True, 1)
        timeline._seek = mock.Mock()
        timeline._seek.return_value = True
        timeline.get_clicked_layer_and_pos = mock.Mock()

        with mock.patch.object(Gtk, "get_event_widget") as get_event_widget:
            get_event_widget.return_value = timeline

            # Simulate click on first and shift+click on second clip.
            timeline.get_clicked_layer_and_pos.return_value = (ges_layer, 0.5 *
                                                               Gst.SECOND)
            timeline._button_release_event_cb(None, event)
            timeline.get_parent()._shiftMask = True
            timeline.get_clicked_layer_and_pos.return_value = (ges_layer, 1.5 *
                                                               Gst.SECOND)
            timeline._button_release_event_cb(None, event)
            self.__check_selected([ges_clip1, ges_clip2], [])
    def test_regenerate_scaled_proxy(self):
        sample_name = "30fps_numeroted_frames_red.mkv"
        with common.cloned_sample(sample_name):
            self.check_import([sample_name],
                              proxying_strategy=ProxyingStrategy.NOTHING)
            asset = self.medialibrary.store[0].asset
            asset_uri = common.get_sample_uri(sample_name)

            # Create scaled proxy
            proxy = self.check_add_proxy(asset, scaled=True)
            proxy_uri = self.app.proxy_manager.get_proxy_uri(asset,
                                                             scaled=True)

            # Change target resolution and trigger regeneration (1/4 Asset width)
            self.app.project_manager.current_project.scaled_proxy_width = 80
            self.app.project_manager.current_project.scaled_proxy_height = 60

            self.app.project_manager.current_project.regenerate_scaled_proxies(
            )
            self.assertTrue("Proxy creation progress:" in
                            self.medialibrary.store[0].infotext)
            self.mainloop.run()

            proxy = self.medialibrary.store[0].asset
            self.assertNotEqual(proxy.props.id, proxy_uri)

            stream = proxy.get_info().get_video_streams()[0]
            resolution = [stream.get_width(), stream.get_height()]
            self.assertEqual(resolution, [80, 60])
            self.assertEqual(proxy.props.proxy_target.props.id, asset_uri)

            # Delete proxy
            self.check_disable_proxy(proxy, asset, delete=True)
            self.assertFalse(os.path.exists(Gst.uri_get_location(proxy_uri)))
    def test_save_project_with_removed_proxy(self):
        sample_name = "30fps_numeroted_frames_red.mkv"
        with common.cloned_sample(sample_name):
            self.check_import([sample_name])

            project = self.app.project_manager.current_project
            asset = GES.UriClipAsset.request_sync(
                common.get_sample_uri(sample_name))
            target = asset.get_proxy_target()
            self.assertEqual(set(project.list_assets(GES.Extractable)),
                             set([target, asset]))

            # Remove the asset
            self.medialibrary.remove_assets_action.emit("activate", None)

            # Make sure that the project has not assets anymore
            self.assertEqual(project.list_assets(GES.Extractable), [])

            # Save the project and reload it, making sure there is no asset
            # in that new project
            project_uri = Gst.filename_to_uri(
                tempfile.NamedTemporaryFile().name)
            project.save(project.ges_timeline, project_uri, None, True)

            self._custom_set_up(project_uri)
            self.assertNotEqual(project,
                                self.app.project_manager.current_project)
            project = self.app.project_manager.current_project
            self.assertEqual(project.list_assets(GES.Extractable), [])
Exemple #19
0
    def test_good_for_track_element(self):
        """Tests the good_for_track_element method."""
        uri = get_sample_uri("tears_of_steel.webm")
        asset = GES.UriClipAsset.request_sync(uri)
        ges_clip = asset.extract()

        # Add the clip to a timeline so it gets tracks.
        ges_timeline = create_timeline_container().timeline.ges_timeline
        ges_timeline.append_layer()
        ges_layer, = ges_timeline.get_layers()
        ges_layer.add_clip(ges_clip)
        track_elements = dict([
            (track_element.get_track_type(), track_element)
            for track_element in ges_clip.get_children(recursive=True)
        ])
        audio_track_element = track_elements[GES.TrackType.AUDIO]
        video_track_element = track_elements[GES.TrackType.VIDEO]

        effect_info = EffectInfo(None, AUDIO_EFFECT, None, None, None)
        self.assertTrue(
            effect_info.good_for_track_element(audio_track_element))
        self.assertFalse(
            effect_info.good_for_track_element(video_track_element))

        effect_info = EffectInfo(None, VIDEO_EFFECT, None, None, None)
        self.assertFalse(
            effect_info.good_for_track_element(audio_track_element))
        self.assertTrue(
            effect_info.good_for_track_element(video_track_element))
Exemple #20
0
    def test_asset_added(self):
        uris = [common.get_sample_uri("tears_of_steel.webm")]
        mainloop = common.create_main_loop()

        def loaded_cb(unused_project, unused_timeline):
            self.project.addUris(uris)

        self.project.connect_after("loaded", loaded_cb)

        def progress_cb(unused_project, progress, unused_estimated_time):
            if progress == 100:
                mainloop.quit()

        self.project.connect_after("asset-loading-progress", progress_cb)

        mainloop.run()

        self.assertTrue(self.action_log.has_assets_operations())
        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 1)
        self.action_log.undo()
        self.assertFalse(self.action_log.has_assets_operations())
        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 0)
        self.action_log.redo()
        self.assertTrue(self.action_log.has_assets_operations())
        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 1)
Exemple #21
0
    def test_asset_added_signal(self):
        app = common.create_pitivi()
        self.assertTrue(app.project_manager.newBlankProject())

        project = app.project_manager.current_project
        proxy_manager = app.proxy_manager

        mainloop = common.create_main_loop()

        def asset_added_cb(project, asset, assets):
            assets.append(asset)

        assets = []
        project.connect("asset-added", asset_added_cb, assets)

        def proxy_ready_cb(unused_proxy_manager, asset, proxy):
            mainloop.quit()

        proxy_manager.connect("proxy-ready", proxy_ready_cb)

        uris = [common.get_sample_uri("tears_of_steel.webm")]
        project.addUris(uris)

        mainloop.run()

        self.assertEqual(len(assets), 1, assets)
Exemple #22
0
    def test_select_missing_asset(self):
        """Exercise the MissingAssetDialog when loading a project."""
        app = common.create_pitivi(proxyingStrategy=ProxyingStrategy.NOTHING,
                                   FCpreviewWidth=640,
                                   FCpreviewHeight=480)

        proj_uri = self.create_project_file_from_xges(
            app, """<ges version='0.3'>
            <project properties='properties;' metadatas='metadatas;'>
                <ressources>
                    <asset id='file://this/is/a/moved/asset.mp4' extractable-type-name='GESUriClip'
                        properties='properties, supported-formats=(int)6, duration=(guint64)1228000000;' metadatas='metadatas' />
                </ressources>
            </project>
            </ges>""")
        project_manager = app.project_manager

        # Use a cloned sample so the asset is not in GES's asset cache.
        # This combination of calls can lead to a mainloop freeze:
        # - MissingAssetDialog.get_new_uri() through the "missing-uri" signal handler,
        # - MissingAssetDialog.run() through MissingAssetDialog.get_new_uri(),
        # - GES.UriClipAsset.request_sync() through PreviewWidget.preview_uri,
        with common.cloned_sample("1sec_simpsons_trailer.mp4"):
            asset_uri = common.get_sample_uri("1sec_simpsons_trailer.mp4")

            mainloop = common.create_main_loop()

            def missing_uri_cb(project_manager, project, unused_error, asset):
                with mock.patch.object(MissingAssetDialog,
                                       "set_transient_for"):
                    mad = MissingAssetDialog(app, asset, asset.get_id())
                mad._chooser.select_uri(asset_uri)
                # Close the dialog when idle so get_new_uri does not get stuck.
                GLib.idle_add(mad.close)
                uri = mad.get_new_uri()
                return uri

            project_manager.connect("missing-uri", missing_uri_cb)

            preview_loaded_for_uri = ""

            def preview_uri(preview_widget, uri):
                nonlocal preview_loaded_for_uri
                original_preview_uri(preview_widget, uri)
                # If it gets past the original_preview_uri call, it's all fine!
                preview_loaded_for_uri = uri
                mainloop.quit()

            original_preview_uri = PreviewWidget.preview_uri
            PreviewWidget.preview_uri = preview_uri
            try:
                # Our mainloop timeout mechanism cannot be used,
                # because the mainloop gets blocked.
                with common.checked_operation_duration(seconds=2):
                    project_manager.load_project(proj_uri)
                    mainloop.run()
                self.assertEqual(preview_loaded_for_uri, asset_uri)
            finally:
                PreviewWidget.preview_uri = original_preview_uri
 def testCheckMediaTypesWhenNoUI(self):
     ges_layer = GES.Layer()
     png = common.get_sample_uri("flat_colour1_640x480.png")
     video_clip = GES.UriClipAsset.request_sync(png).extract()
     self.assertTrue(ges_layer.add_clip(video_clip))
     self.assertEqual(len(ges_layer.get_clips()), 1)
     timeline = Timeline(container=None, app=None)
     layer = Layer(ges_layer, timeline)
 def addClipsSimple(self, timeline, num_clips):
     layer = timeline.ges_timeline.append_layer()
     asset = GES.UriClipAsset.request_sync(
         common.get_sample_uri("tears_of_steel.webm"))
     clips = [layer.add_asset(asset, i * 10, 0, 10, GES.TrackType.UNKNOWN)
              for i in range(num_clips)]
     self.assertEqual(len(clips), num_clips)
     return clips
    def add_clip(self, layer, start, inpoint=0, duration=10, clip_type=GES.TrackType.UNKNOWN):
        """Creates a clip on the specified layer."""
        asset = GES.UriClipAsset.request_sync(
            common.get_sample_uri("tears_of_steel.webm"))
        clip = layer.add_asset(asset, start, inpoint, duration, clip_type)
        self.assertIsNotNone(clip)

        return clip
Exemple #26
0
 def test_scanning_dir(self):
     """Checks the scanning of the directory URIs."""
     assets_dir = os.path.dirname(os.path.abspath(__file__))
     valid_dir_uri = Gst.filename_to_uri(os.path.join(assets_dir, "samples"))
     uris = [valid_dir_uri]
     received_uris = self._scan(uris)
     self.assertGreater(len(received_uris), 1, received_uris)
     valid_uri = common.get_sample_uri("tears_of_steel.webm")
     self.assertIn(valid_uri, received_uris)
Exemple #27
0
 def test_scanning_dir(self):
     """Checks the scanning of the directory URIs."""
     assets_dir = os.path.dirname(os.path.abspath(__file__))
     valid_dir_uri = Gst.filename_to_uri(os.path.join(assets_dir, "samples"))
     uris = [valid_dir_uri]
     received_uris = self._scan(uris)
     self.assertGreater(len(received_uris), 1, received_uris)
     valid_uri = common.get_sample_uri("tears_of_steel.webm")
     self.assertIn(valid_uri, received_uris)
Exemple #28
0
    def test_ungroup_group_clip(self):
        self.setup_timeline_container()
        timeline = self.timeline_container.timeline

        uri = common.get_sample_uri("tears_of_steel.webm")
        asset = GES.UriClipAsset.request_sync(uri)
        clip = asset.extract()
        self.layer.add_clip(clip)
        clips = list(self.getTimelineClips())
        self.assertEqual(len(clips), 1, clips)
        self.assertEqual(len(clips[0].get_children(False)), 2)

        timeline.selection.select([clip])
        timeline.resetSelectionGroup()
        timeline.current_group.add(clip)
        self.timeline_container.ungroup_action.activate(None)
        clips = list(self.getTimelineClips())
        self.assertEqual(len(clips), 2, clips)
        self.assertEqual(len(clips[0].get_children(False)), 1)
        self.assertEqual(len(clips[1].get_children(False)), 1)

        timeline.selection.select(clips)
        timeline.resetSelectionGroup()
        for clip in clips:
            timeline.current_group.add(clip)
        self.timeline_container.group_action.activate(None)
        clips = list(self.getTimelineClips())
        self.assertEqual(len(clips), 1, clips)
        self.assertEqual(len(clips[0].get_children(False)), 2)

        for i in range(2):
            # Undo grouping.
            self.action_log.undo()
            clips = list(self.getTimelineClips())
            self.assertEqual(len(clips), 2, clips)
            self.assertEqual(len(clips[0].get_children(False)), 1)
            self.assertEqual(len(clips[1].get_children(False)), 1)

            # Undo ungrouping.
            self.action_log.undo()
            clips = list(self.getTimelineClips())
            self.assertEqual(len(clips), 1, clips)
            self.assertEqual(len(clips[0].get_children(False)), 2)

            # Redo ungrouping.
            self.action_log.redo()
            clips = list(self.getTimelineClips())
            self.assertEqual(len(clips), 2, clips)
            self.assertEqual(len(clips[0].get_children(False)), 1)
            self.assertEqual(len(clips[1].get_children(False)), 1)

            # Redo grouping.
            self.action_log.redo()
            clips = list(self.getTimelineClips())
            self.assertEqual(len(clips), 1, clips)
            self.assertEqual(len(clips[0].get_children(False)), 2)
Exemple #29
0
    def test_ungroup_group_clip(self):
        self.setup_timeline_container()
        timeline = self.timeline_container.timeline

        uri = common.get_sample_uri("tears_of_steel.webm")
        asset = GES.UriClipAsset.request_sync(uri)
        clip = asset.extract()
        self.layer.add_clip(clip)
        clips = list(self.getTimelineClips())
        self.assertEqual(len(clips), 1, clips)
        self.assertEqual(len(clips[0].get_children(False)), 2)

        timeline.selection.select([clip])
        timeline.resetSelectionGroup()
        timeline.current_group.add(clip)
        self.timeline_container.ungroup_action.activate(None)
        clips = list(self.getTimelineClips())
        self.assertEqual(len(clips), 2, clips)
        self.assertEqual(len(clips[0].get_children(False)), 1)
        self.assertEqual(len(clips[1].get_children(False)), 1)

        timeline.selection.select(clips)
        timeline.resetSelectionGroup()
        for clip in clips:
            timeline.current_group.add(clip)
        self.timeline_container.group_action.activate(None)
        clips = list(self.getTimelineClips())
        self.assertEqual(len(clips), 1, clips)
        self.assertEqual(len(clips[0].get_children(False)), 2)

        for i in range(2):
            # Undo grouping.
            self.action_log.undo()
            clips = list(self.getTimelineClips())
            self.assertEqual(len(clips), 2, clips)
            self.assertEqual(len(clips[0].get_children(False)), 1)
            self.assertEqual(len(clips[1].get_children(False)), 1)

            # Undo ungrouping.
            self.action_log.undo()
            clips = list(self.getTimelineClips())
            self.assertEqual(len(clips), 1, clips)
            self.assertEqual(len(clips[0].get_children(False)), 2)

            # Redo ungrouping.
            self.action_log.redo()
            clips = list(self.getTimelineClips())
            self.assertEqual(len(clips), 2, clips)
            self.assertEqual(len(clips[0].get_children(False)), 1)
            self.assertEqual(len(clips[1].get_children(False)), 1)

            # Redo grouping.
            self.action_log.redo()
            clips = list(self.getTimelineClips())
            self.assertEqual(len(clips), 1, clips)
            self.assertEqual(len(clips[0].get_children(False)), 2)
 def addClipsSimple(self, timeline, num_clips):
     layer = timeline.ges_timeline.append_layer()
     asset = GES.UriClipAsset.request_sync(
         common.get_sample_uri("tears_of_steel.webm"))
     clips = [
         layer.add_asset(asset, i * 10, 0, 10, GES.TrackType.UNKNOWN)
         for i in range(num_clips)
     ]
     self.assertEqual(len(clips), num_clips)
     return clips
Exemple #31
0
    def testInitialization(self):
        mainloop = common.create_main_loop()
        uris = collections.deque([
            common.get_sample_uri("flat_colour1_640x480.png"),
            common.get_sample_uri("tears_of_steel.webm"),
            common.get_sample_uri("1sec_simpsons_trailer.mp4")
        ])

        def loaded_cb(project, timeline):
            project.addUris([uris.popleft()])

        def progress_cb(project, progress, estimated_time):
            if progress == 100:
                if uris:
                    project.addUris([uris.popleft()])
                else:
                    mainloop.quit()

        # Create a blank project and add some assets.
        project = common.create_project()
        self.assertTrue(project._has_default_video_settings)
        self.assertTrue(project._has_default_audio_settings)

        project.connect_after("loaded", loaded_cb)
        project.connect_after("asset-loading-progress", progress_cb)

        mainloop.run()

        assets = project.list_assets(GES.UriClip)
        self.assertEqual(3, len(assets), assets)

        self.assertFalse(project._has_default_video_settings)
        self.assertFalse(project._has_default_audio_settings)

        # The audio settings should match tears_of_steel.webm
        self.assertEqual(1, project.audiochannels)
        self.assertEqual(44100, project.audiorate)

        # The video settings should match tears_of_steel.webm
        self.assertEqual(960, project.videowidth)
        self.assertEqual(400, project.videoheight)
        self.assertEqual(Gst.Fraction(24, 1), project.videorate)
        self.assertEqual(Gst.Fraction(1, 1), project.videopar)
    def __loading_failure(self, has_proxy):
        mainloop = common.create_main_loop()

        app = common.create_pitivi_mock(lastProjectFolder="/tmp",
                                        edgeSnapDeadband=32)
        app.project_manager = ProjectManager(app)
        editorperspective = EditorPerspective(app)
        editorperspective.setup_ui()
        editorperspective.viewer = mock.MagicMock()
        editorperspective.medialibrary._import_warning_infobar = mock.MagicMock(
        )
        editorperspective.clipconfig.effect_expander._infobar = mock.MagicMock(
        )

        def __pm_missing_uri_cb(project_manager, project, error, asset):
            nonlocal mainloop
            nonlocal editorperspective
            nonlocal self
            nonlocal app
            nonlocal has_proxy

            with mock.patch.object(MissingAssetDialog,
                                   "__new__") as constructor:
                failed_cb = mock.MagicMock()
                app.project_manager.connect("new-project-failed", failed_cb)

                dialog = constructor.return_value
                dialog.get_new_uri.return_value = None

                # Call the actual callback
                app.proxy_manager.checkProxyLoadingSucceeded =  \
                    mock.MagicMock(return_value=has_proxy)

                editorperspective._projectManagerMissingUriCb(
                    project_manager, project, error, asset)

                self.assertTrue(constructor.called)
                self.assertTrue(dialog.get_new_uri.called)
                self.assertEqual(failed_cb.called, not has_proxy)

            app.project_manager.connect(
                "missing-uri", editorperspective._projectManagerMissingUriCb)
            mainloop.quit()

        disconnectAllByFunc(app.project_manager,
                            editorperspective._projectManagerMissingUriCb)

        app.project_manager.connect("missing-uri", __pm_missing_uri_cb)

        with common.cloned_sample():
            asset_uri = common.get_sample_uri("missing.png")
            with common.created_project_file(asset_uri) as uri:
                app.project_manager.load_project(uri)

        mainloop.run()
Exemple #33
0
    def testInitialization(self):
        mainloop = common.create_main_loop()
        uris = collections.deque([
            common.get_sample_uri("flat_colour1_640x480.png"),
            common.get_sample_uri("tears_of_steel.webm"),
            common.get_sample_uri("1sec_simpsons_trailer.mp4")])

        def loaded_cb(project, timeline):
            project.addUris([uris.popleft()])

        def progress_cb(project, progress, estimated_time):
            if progress == 100:
                if uris:
                    project.addUris([uris.popleft()])
                else:
                    mainloop.quit()

        # Create a blank project and add some assets.
        project = common.create_project()
        self.assertTrue(project._has_default_video_settings)
        self.assertTrue(project._has_default_audio_settings)

        project.connect_after("loaded", loaded_cb)
        project.connect_after("asset-loading-progress", progress_cb)

        mainloop.run()

        assets = project.list_assets(GES.UriClip)
        self.assertEqual(3, len(assets), assets)

        self.assertFalse(project._has_default_video_settings)
        self.assertFalse(project._has_default_audio_settings)

        # The audio settings should match tears_of_steel.webm
        self.assertEqual(1, project.audiochannels)
        self.assertEqual(44100, project.audiorate)

        # The video settings should match tears_of_steel.webm
        self.assertEqual(960, project.videowidth)
        self.assertEqual(400, project.videoheight)
        self.assertEqual(Gst.Fraction(24, 1), project.videorate)
        self.assertEqual(Gst.Fraction(1, 1), project.videopar)
Exemple #34
0
    def test_adding_overlap_clip(self):
        """Checks asset drag&drop on top of an existing clip."""
        asset = GES.UriClipAsset.request_sync(
            common.get_sample_uri("tears_of_steel.webm"))

        layer, = self.ges_timeline.get_layers()
        layer.add_asset(asset, 0, 0, 10, GES.TrackType.UNKNOWN)
        clips = layer.get_clips()

        self.check_drag_assets_to_timeline(self.ges_timeline.ui, [asset])
        self.assertEqual(layer.get_clips(), clips)
    def test_use_proxy(self):
        # Import an asset.
        uris = [common.get_sample_uri("tears_of_steel.webm")]
        mainloop = common.create_main_loop()

        def loaded_cb(unused_project, unused_timeline):
            # The new project has been loaded, add some assets.
            self.project.addUris(uris)

        self.project.connect_after("loaded", loaded_cb)

        def progress_cb(unused_project, progress, unused_estimated_time):
            if progress == 100:
                # The assets have been loaded.
                mainloop.quit()

        self.project.connect_after("asset-loading-progress", progress_cb)

        mainloop.run()
        self.project.disconnect_by_func(progress_cb)
        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 1)

        # Make sure the asset is not a proxy.
        assets = [GES.UriClipAsset.request_sync(uri) for uri in uris]
        for asset in assets:
            self.assertIsNone(asset.get_proxy_target(), "Asset is proxy")

        # Use proxy instead of the asset.
        mainloop = common.create_main_loop()

        def error_cb(proxy_manager, asset, proxy, error):
            self.fail("Failed to create proxy: %s" % error)

        self.app.proxy_manager.connect("error-preparing-asset", error_cb)

        def proxy_ready_cb(proxy_manager, asset, proxy):
            mainloop.quit()

        self.app.proxy_manager.connect("proxy-ready", proxy_ready_cb)

        self.project.use_proxies_for_assets(assets)
        mainloop.run()

        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 2)

        # Undo proxying.
        self.action_log.undo()
        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 1)

        # Redo proxying.
        self.action_log.redo()
        # Wait for the proxy to be signalled as ready.
        mainloop.run()
        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 2)
Exemple #36
0
    def test_thumb_interval(self):
        """Checks the `thumb_interval` property."""
        ges_elem = mock.Mock()
        ges_elem.props.uri = common.get_sample_uri("1sec_simpsons_trailer.mp4")
        ges_elem.props.id = common.get_sample_uri("1sec_simpsons_trailer.mp4")
        previewer = VideoPreviewer(ges_elem, 94)
        previewer.thumb_width = 1  # Just so it's not None.

        def run_thumb_interval(interval):
            """Runs thumb_interval."""
            with mock.patch("pitivi.utils.timeline.Zoomable.pixelToNs") as pixel_to_ns:
                pixel_to_ns.return_value = interval
                return previewer.thumb_interval

        self.assertEqual(run_thumb_interval(1), THUMB_PERIOD)
        self.assertEqual(run_thumb_interval(THUMB_PERIOD - 1), THUMB_PERIOD)
        self.assertEqual(run_thumb_interval(THUMB_PERIOD), THUMB_PERIOD)

        self.assertEqual(run_thumb_interval(THUMB_PERIOD + 1), 2 * THUMB_PERIOD)
        self.assertEqual(run_thumb_interval(2 * THUMB_PERIOD - 1), 2 * THUMB_PERIOD)
        self.assertEqual(run_thumb_interval(2 * THUMB_PERIOD), 2 * THUMB_PERIOD)
Exemple #37
0
    def test_get(self):
        with self.assertRaises(ValueError):
            ThumbnailCache.get(1)
        with mock.patch("pitivi.timeline.previewers.xdg_cache_home") as xdg_config_home,\
                tempfile.TemporaryDirectory() as temp_dir:
            xdg_config_home.return_value = temp_dir
            sample_uri = common.get_sample_uri("1sec_simpsons_trailer.mp4")
            cache = ThumbnailCache.get(sample_uri)
            self.assertIsNotNone(cache)

            asset = GES.UriClipAsset.request_sync(sample_uri)
            self.assertEqual(ThumbnailCache.get(asset), cache)
    def test_get(self):
        with self.assertRaises(ValueError):
            ThumbnailCache.get(1)
        with mock.patch("pitivi.timeline.previewers.xdg_cache_home") as xdg_config_home,\
                tempfile.TemporaryDirectory() as temp_dir:
            xdg_config_home.return_value = temp_dir
            sample_uri = common.get_sample_uri("1sec_simpsons_trailer.mp4")
            cache = ThumbnailCache.get(sample_uri)
            self.assertIsNotNone(cache)

            asset = GES.UriClipAsset.request_sync(sample_uri)
            self.assertEqual(ThumbnailCache.get(asset), cache)
    def __loading_failure(self, has_proxy):
        mainloop = common.create_main_loop()

        app = common.create_pitivi_mock(lastProjectFolder="/tmp",
                                        edgeSnapDeadband=32)
        app.project_manager = ProjectManager(app)
        editorperspective = EditorPerspective(app)
        editorperspective.setup_ui()
        editorperspective.viewer = mock.MagicMock()
        editorperspective.medialibrary._import_warning_infobar = mock.MagicMock()
        editorperspective.clipconfig.effect_expander._infobar = mock.MagicMock()

        def __pm_missing_uri_cb(project_manager, project, error, asset):
            nonlocal mainloop
            nonlocal editorperspective
            nonlocal self
            nonlocal app
            nonlocal has_proxy

            with mock.patch.object(MissingAssetDialog, "__new__") as constructor:
                failed_cb = mock.MagicMock()
                app.project_manager.connect("new-project-failed", failed_cb)

                dialog = constructor.return_value
                dialog.get_new_uri.return_value = None

                # Call the actual callback
                app.proxy_manager.checkProxyLoadingSucceeded =  \
                    mock.MagicMock(return_value=has_proxy)

                editorperspective._projectManagerMissingUriCb(
                    project_manager, project, error, asset)

                self.assertTrue(constructor.called)
                self.assertTrue(dialog.get_new_uri.called)
                self.assertEqual(failed_cb.called, not has_proxy)

            app.project_manager.connect("missing-uri",
                                        editorperspective._projectManagerMissingUriCb)
            mainloop.quit()

        disconnectAllByFunc(app.project_manager,
                            editorperspective._projectManagerMissingUriCb)

        app.project_manager.connect("missing-uri", __pm_missing_uri_cb)

        with common.cloned_sample():
            asset_uri = common.get_sample_uri("missing.png")
            with common.created_project_file(asset_uri) as uri:
                app.project_manager.load_project(uri)

        mainloop.run()
Exemple #40
0
 def test_check_media_types_when_no_control_ui(self):
     ges_layer = GES.Layer()
     png = common.get_sample_uri("flat_colour1_640x480.png")
     video_clip = GES.UriClipAsset.request_sync(png).extract()
     self.assertTrue(ges_layer.add_clip(video_clip))
     self.assertEqual(len(ges_layer.get_clips()), 1)
     timeline_container = common.create_timeline_container()
     timeline = timeline_container.timeline
     # This will add widgets for the clips in ges_layer and
     # the layer will use checkMediaTypes which updates the
     # height of layer.control_ui, which now it should not be set.
     self.assertFalse(hasattr(ges_layer, "control_ui"))
     unused_layer = Layer(ges_layer, timeline)
Exemple #41
0
    def test_waveform_creation(self):
        """Checks the waveform generation."""
        sample_name = "1sec_simpsons_trailer.mp4"
        self.runCheckImport([sample_name])

        sample_uri = common.get_sample_uri(sample_name)
        wavefile = get_wavefile_location_for_uri(sample_uri)
        self.assertTrue(os.path.exists(wavefile), wavefile)

        with open(wavefile, "rb") as fsamples:
            samples = list(numpy.load(fsamples))

        self.assertEqual(samples, SIMPSON_WAVFORM_VALUES)
Exemple #42
0
 def test_check_media_types_when_no_control_ui(self):
     ges_layer = GES.Layer()
     png = common.get_sample_uri("flat_colour1_640x480.png")
     video_clip = GES.UriClipAsset.request_sync(png).extract()
     self.assertTrue(ges_layer.add_clip(video_clip))
     self.assertEqual(len(ges_layer.get_clips()), 1)
     timeline_container = common.create_timeline_container()
     timeline = timeline_container.timeline
     # This will add widgets for the clips in ges_layer and
     # the layer will use checkMediaTypes which updates the
     # height of layer.control_ui, which now it should not be set.
     self.assertFalse(hasattr(ges_layer, "control_ui"))
     unused_layer = Layer(ges_layer, timeline)
Exemple #43
0
    def test_image_size(self):
        """Checks the `image_size` property."""
        with tempfile.TemporaryDirectory() as tmpdirname:
            with mock.patch("pitivi.timeline.previewers.xdg_cache_home") as xdg_cache_home:
                xdg_cache_home.return_value = tmpdirname
                sample_uri = common.get_sample_uri("1sec_simpsons_trailer.mp4")
                thumb_cache = ThumbnailCache(sample_uri)
                self.assertEqual(thumb_cache.image_size, (0, 0))

                pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB,
                                              False, 8, 20, 10)
                thumb_cache[0] = pixbuf
                self.assertEqual(thumb_cache.image_size, (20, 10))
Exemple #44
0
    def test_use_proxy(self):
        # Import an asset.
        uris = [common.get_sample_uri("tears_of_steel.webm")]
        mainloop = common.create_main_loop()

        def loaded_cb(unused_project, unused_timeline):
            # The new project has been loaded, add some assets.
            self.project.addUris(uris)
        self.project.connect_after("loaded", loaded_cb)

        def progress_cb(unused_project, progress, unused_estimated_time):
            if progress == 100:
                # The assets have been loaded.
                mainloop.quit()
        self.project.connect_after("asset-loading-progress", progress_cb)

        mainloop.run()
        self.project.disconnect_by_func(progress_cb)
        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 1)

        # Make sure the asset is not a proxy.
        assets = [GES.UriClipAsset.request_sync(uri) for uri in uris]
        for asset in assets:
            self.assertIsNone(asset.get_proxy_target(), "Asset is proxy")

        # Use proxy instead of the asset.
        mainloop = common.create_main_loop()

        def error_cb(proxy_manager, asset, proxy, error):
            self.fail("Failed to create proxy: %s" % error)
        self.app.proxy_manager.connect("error-preparing-asset", error_cb)

        def proxy_ready_cb(proxy_manager, asset, proxy):
            mainloop.quit()
        self.app.proxy_manager.connect("proxy-ready", proxy_ready_cb)

        self.project.use_proxies_for_assets(assets)
        mainloop.run()

        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 2)

        # Undo proxying.
        self.action_log.undo()
        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 1)

        # Redo proxying.
        self.action_log.redo()
        # Wait for the proxy to be signalled as ready.
        mainloop.run()
        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 2)
    def test_image_size(self):
        """Checks the `image_size` property."""
        with tempfile.TemporaryDirectory() as tmpdirname:
            with mock.patch("pitivi.timeline.previewers.xdg_cache_home"
                            ) as xdg_cache_home:
                xdg_cache_home.return_value = tmpdirname
                sample_uri = common.get_sample_uri("1sec_simpsons_trailer.mp4")
                thumb_cache = ThumbnailCache(sample_uri)
                self.assertEqual(thumb_cache.image_size, (None, None))

                pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, False,
                                              8, 20, 10)
                thumb_cache[0] = pixbuf
                self.assertEqual(thumb_cache.image_size, (20, 10))
Exemple #46
0
    def test_waveform_creation(self):
        """Checks the waveform generation."""
        sample_name = "1sec_simpsons_trailer.mp4"
        with common.cloned_sample(sample_name):
            self.check_import([sample_name])

            sample_uri = common.get_sample_uri(sample_name)
            wavefile = get_wavefile_location_for_uri(sample_uri)

        self.assertTrue(os.path.exists(wavefile), wavefile)

        with open(wavefile, "rb") as fsamples:
            samples = list(numpy.load(fsamples))

        self.assertEqual(samples, SIMPSON_WAVFORM_VALUES)
Exemple #47
0
    def stopUsingProxies(self, delete_proxies=False):
        sample_name = "30fps_numeroted_frames_red.mkv"
        self.runCheckImport([sample_name])

        asset_uri = common.get_sample_uri(sample_name)
        proxy = self.medialibrary.storemodel[0][medialibrary.COL_ASSET]

        self.assertEqual(proxy.props.proxy_target.props.id, asset_uri)

        self.app.project_manager.current_project.disableProxiesForAssets(
            [proxy], delete_proxies)
        self.assertEqual(len(self.medialibrary.storemodel),
                         len(self.samples))

        self.assertEqual(self.medialibrary.storemodel[0][medialibrary.COL_URI],
                         asset_uri)
Exemple #48
0
    def test_group_ungroup_clips(self):
        self.setup_timeline_container()

        clip1 = common.create_test_clip(GES.TitleClip)
        clip1.set_start(0 * Gst.SECOND)
        clip1.set_duration(1 * Gst.SECOND)

        uri = common.get_sample_uri("tears_of_steel.webm")
        asset = GES.UriClipAsset.request_sync(uri)
        clip2 = asset.extract()
        clip2.props.start = 1 * Gst.SECOND

        self.assertTrue(self.layer.add_clip(clip1))
        self.assertTrue(self.layer.add_clip(clip2))
        # The selection does not care about GES.Groups, only about GES.Clips.
        self.timeline_container.timeline.selection.select([clip1, clip2])
        self.assertEqual(clip1.props.timeline, self.layer.get_timeline())
        self.assertEqual(clip2.props.timeline, self.layer.get_timeline())

        self.timeline_container.group_action.activate(None)
        self.assertTrue(isinstance(clip1.get_parent(), GES.Group))
        self.assertEqual(clip1.get_parent(), clip2.get_parent())

        self.timeline_container.ungroup_action.activate(None)
        self.assertIsNone(clip1.get_parent())
        self.assertIsNone(clip2.get_parent())

        for i in range(4):
            # Undo ungrouping.
            self.action_log.undo()
            self.assertTrue(isinstance(clip1.get_parent(), GES.Group))
            self.assertEqual(clip1.get_parent(), clip2.get_parent())

            # Undo grouping.
            self.action_log.undo()
            self.assertIsNone(clip1.get_parent())
            self.assertIsNone(clip2.get_parent())

            # Redo grouping.
            self.action_log.redo()
            self.assertTrue(isinstance(clip1.get_parent(), GES.Group))
            self.assertEqual(clip1.get_parent(), clip2.get_parent())

            # Redo ungrouping.
            self.action_log.redo()
            self.assertIsNone(clip1.get_parent())
            self.assertIsNone(clip2.get_parent())
Exemple #49
0
    def testLoaded(self):
        mainloop = common.create_main_loop()

        def new_project_loaded_cb(project_manager, project):
            mainloop.quit()

        self.manager.connect("new-project-loaded", new_project_loaded_cb)

        asset_uri = common.get_sample_uri("flat_colour1_640x480.png")
        with common.created_project_file(asset_uri=asset_uri) as uri:
            self.assertTrue(self.manager.loadProject(uri))
            mainloop.run()

        project = self.manager.current_project
        self.assertFalse(project.at_least_one_asset_missing)
        self.assertTrue(project.loaded)
        self.assertFalse(project.hasUnsavedModifications())
Exemple #50
0
    def testMissingUriForwarded(self):
        self.setupApp(app=common.create_pitivi_mock())
        mainloop = common.create_main_loop()

        def missingUriCb(self, project, error, clip_asset, result):
            result[0] = True
            mainloop.quit()

        result = [False]
        self.manager.connect("missing-uri", missingUriCb, result)

        with common.cloned_sample():
            asset_uri = common.get_sample_uri("missing.png")
            with common.created_project_file(asset_uri) as uri:
                self.assertIsNotNone(self.manager.load_project(uri))
                mainloop.run()
        self.assertTrue(result[0], "missing-uri has not been emitted")
Exemple #51
0
    def stop_using_proxies(self, delete_proxies=False):
        sample_name = "30fps_numeroted_frames_red.mkv"
        self.check_import([sample_name])

        asset_uri = common.get_sample_uri(sample_name)
        proxy = self.medialibrary.storemodel[0][medialibrary.COL_ASSET]

        self.assertEqual(proxy.props.proxy_target.props.id, asset_uri)

        project = self.app.project_manager.current_project
        self.assertIn(proxy, project.list_assets(GES.UriClip))
        project.disable_proxies_for_assets([proxy], delete_proxies)
        self.assertNotIn(proxy, project.list_assets(GES.UriClip))
        self.assertEqual(len(self.medialibrary.storemodel),
                         len(self.samples))

        self.assertEqual(self.medialibrary.storemodel[0][medialibrary.COL_URI],
                         asset_uri)
Exemple #52
0
    def test_use_proxy(self):
        # Import an asset.
        uris = [common.get_sample_uri("tears_of_steel.webm")]
        mainloop = common.create_main_loop()

        def commit_cb(unused_action_log, stack):
            self.assertEqual(stack.action_group_name, "Adding assets")
            mainloop.quit()
        self.action_log.connect("commit", commit_cb)

        def loaded_cb(unused_project, unused_timeline):
            self.project.addUris(uris)
        self.project.connect_after("loaded", loaded_cb)

        mainloop.run()
        self.action_log.disconnect_by_func(commit_cb)
        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 1)

        # Make sure the asset is not a proxy.
        assets = [GES.UriClipAsset.request_sync(uri) for uri in uris]
        for asset in assets:
            self.assertIsNone(asset.get_proxy_target(), "Asset is proxy")

        # Use proxy instead of the asset.
        mainloop = common.create_main_loop()

        def error_cb(proxy_manager, asset, proxy, error):
            self.fail("Failed to create proxy: %s" % error)
        self.app.proxy_manager.connect("error-preparing-asset", error_cb)

        def proxy_ready_cb(proxy_manager, asset, proxy):
            uris.remove(asset.props.id)
            if not uris:
                mainloop.quit()
        self.app.proxy_manager.connect("proxy-ready", proxy_ready_cb)

        self.project.useProxiesForAssets(assets)
        mainloop.run()

        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 2)
        self.action_log.undo()
        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 1)
        self.action_log.redo()
        self.assertEqual(len(self.project.list_assets(GES.Extractable)), 2)
Exemple #53
0
    def test_load_project_with_missing_proxy_progress_tracking(self):
        """Checks progress tracking of loading project with missing proxies."""
        from gi.repository import GstTranscoder

        # Disable proxy generation by not making it start ever.
        # This way we are sure it will not finish before we test
        # the state while it is being rebuilt.
        with mock.patch.object(GstTranscoder.Transcoder, "run_async"):
            mainloop, app, medialib, proxy_uri = self.load_project_with_missing_proxy()
            uri = common.get_sample_uri("1sec_simpsons_trailer.mp4")

            app.project_manager.connect("new-project-loaded", lambda x, y: mainloop.quit())
            mainloop.run()

            self.assertEqual(len(medialib.storemodel), 1)
            self.assertEqual(medialib.storemodel[0][medialibrary.COL_ASSET].props.id,
                             uri)
            self.assertEqual(medialib.storemodel[0][medialibrary.COL_THUMB_DECORATOR].state,
                             medialibrary.AssetThumbnail.IN_PROGRESS)
Exemple #54
0
    def testWaveFormAndThumbnailCreated(self):
        sample_name = "1sec_simpsons_trailer.mp4"
        self.runCheckImport([sample_name])

        sample_uri = common.get_sample_uri(sample_name)
        asset = GES.UriClipAsset.request_sync(sample_uri)

        thumb_cache = getThumbnailCache(asset)
        width, height = thumb_cache.getImagesSize()
        self.assertEqual(height, THUMB_HEIGHT)
        self.assertTrue(thumb_cache[0] is not None)
        self.assertTrue(thumb_cache[Gst.SECOND / 2] is not None)

        wavefile = get_wavefile_location_for_uri(sample_uri)
        self.assertTrue(os.path.exists(wavefile), wavefile)

        with open(wavefile, "rb") as fsamples:
            samples = pickle.load(fsamples)

        self.assertTrue(bool(samples))
Exemple #55
0
    def test_insert_on_first_layer(self):
        self.setup_timeline_container()
        uri = common.get_sample_uri("tears_of_steel.webm")
        asset = GES.UriClipAsset.request_sync(uri)
        clip1 = asset.extract()
        self.timeline_container.insert_clips_on_first_layer(clips=[clip1], position=0)
        clips = list(self.getTimelineClips())
        self.assertEqual(len(clips), 1, clips)

        # Undo insert on first layer
        self.action_log.undo()
        clips = list(self.getTimelineClips())
        self.assertEqual(len(clips), 0, clips)

        # Redo insert on first layer
        self.action_log.redo()
        clips = list(self.getTimelineClips())
        self.assertEqual(len(clips), 1, clips)

        # Insert new clip to create a layer
        clip2 = common.create_test_clip(GES.TitleClip)
        clip2.set_start(0 * Gst.SECOND)
        clip2.set_duration(1 * Gst.SECOND)
        self.timeline_container.insert_clips_on_first_layer(clips=[clip2], position=0)
        layers = self.timeline.get_layers()
        self.check_layers([layers[0], self.layer])
        self.assertEqual(layers[0].get_clips(), [clip2])
        self.assertEqual(layers[1].get_clips(), [clip1])

        # Undo insert to create a layer
        self.action_log.undo()
        layers = self.timeline.get_layers()
        self.check_layers([self.layer])
        self.assertEqual(layers[0].get_clips(), [clip1])

        # Redo insert to create a layer
        self.action_log.redo()
        layers = self.timeline.get_layers()
        self.check_layers([layers[0], self.layer])
        self.assertEqual(layers[0].get_clips(), [clip2])
        self.assertEqual(layers[1].get_clips(), [clip1])