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_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])
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))
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])
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 = ThumbnailCache.get(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 = list(numpy.load(fsamples)) self.assertEqual(samples, SIMPSON_WAVFORM_VALUES)
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 = ThumbnailCache.get(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.assertEqual(samples, SIMPSON_WAVFORM_VALUES)
def __focus_in_event_cb(self, unused_widget, unused_event): ges_timeline = self.timeline_ui.timeline.ges_timeline if not ges_timeline: # Nothing to work with, Pitivi is starting up. return # Commit the timeline so its nested timelines assets are refreshed. ges_timeline.commit() # We need to track the changed assets ourselves. changed_files_uris = ThumbnailCache.update_caches() if changed_files_uris: self.medialibrary.update_asset_thumbs(changed_files_uris) for ges_layer in ges_timeline.get_layers(): for ges_clip in ges_layer.get_clips(): if ges_clip.get_asset().props.id in changed_files_uris: if ges_clip.ui.audio_widget: ges_clip.ui.audio_widget.update_previewer() if ges_clip.ui.video_widget: ges_clip.ui.video_widget.update_previewer()
def testCache(self): c = ThumbnailCache(self.uri, size=32) for i in xrange(0, 64): c[i] = cairo.ImageSurface(cairo.FORMAT_RGB24, 10, 10) assert len(c.cache) == 32 # 31 should be in the Database, but not in the memory direct cache assert not 31 in c.cache assert 31 in c # 32 is in both assert 32 in c.cache # touch the LRU item, and then add something to the queue # the item should still remain in the queue c[32] c[65] = cairo.ImageSurface(cairo.FORMAT_RGB24, 10, 10) assert 32 in c assert 33 not in c.cache