[shotwell] gphoto: Don't copy buffer when creating input stream from CameraFile
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell] gphoto: Don't copy buffer when creating input stream from CameraFile
- Date: Thu, 18 May 2017 20:26:28 +0000 (UTC)
commit e6ffdef23a0a93d2e658366b4902e0e864b60967
Author: Jens Georg <mail jensge org>
Date: Thu May 18 22:25:15 2017 +0200
gphoto: Don't copy buffer when creating input stream from CameraFile
src/camera/GPhoto.vala | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/src/camera/GPhoto.vala b/src/camera/GPhoto.vala
index 5acc4a3..fb0fd4a 100644
--- a/src/camera/GPhoto.vala
+++ b/src/camera/GPhoto.vala
@@ -251,17 +251,20 @@ namespace GPhoto {
throw new GPhotoError.LIBRARY("[%d] Error retrieving file object for %s/%s: %s",
(int) res, folder, filename, res.as_string());
- // if entire file fits in memory, return a stream from that ... can't merely wrap
- // MemoryInputStream around the camera_file buffer, as that will be destroyed when the
- // function returns
+ // if entire file fits in memory, return a stream from that ...
+ // The camera_file is set as data on the object to keep it alive while
+ // the MemoryInputStream is alive.
unowned uint8 *data;
ulong data_len;
res = camera_file.get_data_and_size(out data, out data_len);
if (res == Result.OK) {
- uint8[] buffer = new uint8[data_len];
- Memory.copy(buffer, data, buffer.length);
+ unowned uint8[] buffer = (uint8[])data;
+ buffer.length = (int) data_len;
- return new MemoryInputStream.from_data(buffer, on_mins_destroyed);
+ var mis = new MemoryInputStream.from_data(buffer, () => {});
+ mis.set_data<GPhoto.CameraFile>("camera-file", camera_file);
+
+ return mis;
}
// if not stored in memory, try copying it to a temp file and then reading out of that
@@ -274,10 +277,6 @@ namespace GPhoto {
return temp.read(null);
}
- private static void on_mins_destroyed(void *data) {
- free(data);
- }
-
// Returns a buffer with the requested file, if within reason. Use load_file for larger files.
public uint8[]? load_file_into_buffer(Context context, Camera camera, string folder,
string filename, CameraFileType filetype) throws Error {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]