sija / gphoto2.cr Goto Github PK
View Code? Open in Web Editor NEWCrystal shard wrapping libgphoto2
Home Page: https://sija.github.io/gphoto2.cr/
License: MIT License
Crystal shard wrapping libgphoto2
Home Page: https://sija.github.io/gphoto2.cr/
License: MIT License
v0.1
releaseSome of the candidates would be CameraWidget
, Entry
or CameraFile
.
We'd also need some #reset
method for clearing out those.
in ./src/gphoto2/camera_widget.cr:66: no overload matches 'GPhoto2::DateCameraWidget#set_value' with type String
When trying to access CameraFile#get_data_and_size
on disconnected camera.
Exception log:
2016-08-12 00:14:33 +0200 200 GET /cameras/ypBMNRNh0xq75z/fs/store_00010001/DCIM/101APPLE/IMG_1480.JPG 455.75ms
DEBUG [gphoto2.cr] -- [4544243908] *GPhoto2::CameraFile#new:Pointer(LibGPhoto2::CameraFile) +36 -- {rc} = {0}
DEBUG [libgphoto2] -- Getting file info for 'IMG_1480.JPG' in '/store_00010001/DCIM/101APPLE'...
DEBUG [libgphoto2] -- Getting information about 'IMG_1480.JPG' in '/store_00010001/DCIM/101APPLE'...
DEBUG [libgphoto2] -- Lookup folder /store_00010001/DCIM/101APPLE file IMG_1480.JPG
DEBUG [libgphoto2] -- Lookup folder '/store_00010001/DCIM/101APPLE'...
DEBUG [gphoto2.cr] -- [4544249263] *GPhoto2::CameraFile#get_info:GPhoto2::CameraFileInfo +4863 -- {rc} = {0}
DEBUG [libgphoto2] -- Getting file info for 'IMG_1480.JPG' in '/store_00010001/DCIM/101APPLE'...
DEBUG [libgphoto2] -- Getting information about 'IMG_1480.JPG' in '/store_00010001/DCIM/101APPLE'...
DEBUG [libgphoto2] -- Lookup folder /store_00010001/DCIM/101APPLE file IMG_1480.JPG
DEBUG [libgphoto2] -- Lookup folder '/store_00010001/DCIM/101APPLE'...
DEBUG [gphoto2.cr] -- [4544249263] *GPhoto2::CameraFile#get_info:GPhoto2::CameraFileInfo +4863 -- {rc} = {0}
DEBUG [libgphoto2] -- Getting file 'IMG_1480.JPG' in folder '/store_00010001/DCIM/101APPLE'...
DEBUG [libgphoto2] -- Getting file 'IMG_1480.JPG' from folder '/store_00010001/DCIM/101APPLE' (type 1)...
DEBUG [libgphoto2] -- Lookup folder /store_00010001/DCIM/101APPLE file IMG_1480.JPG
DEBUG [libgphoto2] -- Lookup folder '/store_00010001/DCIM/101APPLE'...
DEBUG [libgphoto2] -- Downloading 'IMG_1480.JPG' from folder '/store_00010001/DCIM/101APPLE'...
DEBUG [libgphoto2] -- (storage=0x00010001, handle=0x00000000)
DEBUG [libgphoto2] -- (storage=0x00010001, handle=0x00000001)
DEBUG [libgphoto2] -- (storage=0x00010001, handle=0x00000032)
DEBUG [libgphoto2] -- Getting file 'IMG_1480.JPG'.
DEBUG [libgphoto2] -- Sending PTP_OC 0x1009 (Get object) request...
ERROR [libgphoto2] -- 'libusb_bulk_transfer (port->pl->dh, port->settings.usb.outep, (unsigned char*)bytes, size, &curwritten, port->timeout)' failed: No such device (it may have been disconnected) (-4)
ERROR [libgphoto2] -- Writing 16 = 0x10 bytes to port failed: Could not find the requested device on the USB port (-52)
ERROR [libgphoto2] -- PTP_OC 0x1009 sending req failed: Could not find the requested device on the USB port (-52)
ERROR [libgphoto2] -- 'ret' failed: 'PTP I/O Error' (0x02ff)
ERROR [libgphoto2] -- PTP I/O Error
Invalid memory access (signal 11) at address 0x0
[4543072923] *CallStack::print_backtrace:Int32 +107
[4542975527] __crystal_sigfault_handler +55
[140735736141098] _sigtramp +26
Used by just 2 (sierra & kodak) drivers, might be not worth implementing.
In many places, like CameraWidget
for instance: https://github.com/gphoto/libgphoto2/blob/548e52bb598fd8d38ca4a0ec3f619e936517bdf1/libgphoto2/gphoto2-widget.c#L177
Refs #16
In Crystal #finalize
method acts like a destructor, called when the object is being collected by GC but in some of the classes we use it also to free up C (mostly libgphoto2) resources which might introduce bugs later on—or not?
crystal doc
Based on gp_camera_get_storageinfo
.
Like below:
camera.on :file_added do |event|
# ...
end
There are plenty places where those might happen, might be related to #14.
Sth along the lines of:
private def set_timeout_funcs
start_func = ->(camera_ptr : LibGPhoto2::Camera*, timeout : LibC::UInt, func : LibGPhoto2::CameraTimeoutFunc, data : Void*) {
# can we use .as() for GC-ed crystal object without blowing up?
camera = data.as?(Camera) || return LibGPhoto2::GP_ERROR
return LibGPhoto2::GP_ERROR if camera_ptr != camera.ptr
spawn do
loop do
# break if camera.disposed?
sleep timeout.seconds
# GPhoto2.check! ?
func.call(camera.to_unsafe, camera.context.to_unsafe)
end
end
camera_ptr.value.hash
}
stop_func = ->(camera_ptr : LibGPhoto2::Camera*, id : LibC::UInt, data : Void*) {
# how do we cleanup, if at all?
}
# Need to use `@ptr` instead of `self`, since we call
# `#init` inside of overridden `#ptr` method.
LibGPhoto2.gp_camera_set_timeout_funcs(@ptr, start_func, stop_func, self.as(Void*))
end
References:
From what I've seen in libgphoto2 codebase, the only camera driver currently using this feature is Konica.
See CameraList
, CameraFolder
...
/usr/bin/ld: cannot find -llibgphoto2
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc -o "/home/sija/.cache/crystal/crystal-run-spec.tmp" "${@}" -rdynamic -llibgphoto2 -lxml2 -lpcre -lm -lgc -lpthread /opt/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`
It happens when (there's no SD card inside? and) we try to use CameraFile
which might be unavailable at the time.
Below test code:
queue = [] of CameraFile
# ...
queue.each &.save
Results in:
Unspecified error (GPhoto2::Error)
[4491010242] *CallStack::unwind:Array(Pointer(Void)) +82
[4491010145] *CallStack#initialize:Array(Pointer(Void)) +17
[4491010104] *CallStack::new:CallStack +40
[4490990009] *raise<GPhoto2::Error>:NoReturn +25
[4491164503] *GPhoto2::check!<Int32>:Int32 +919
[4491237226] *GPhoto2::Camera@GPhoto2::Camera::Filesystem#file_get<GPhoto2::CameraFile, LibGPhoto2::CameraFileType>:GPhoto2::CameraFile +250
[4491236967] *GPhoto2::Camera@GPhoto2::Camera::Filesystem#file_get<GPhoto2::CameraFile>:GPhoto2::CameraFile +39
[4491236921] *GPhoto2::Camera@GPhoto2::Camera::Filesystem#file<GPhoto2::CameraFile>:GPhoto2::CameraFile +9
[4491425206] *GPhoto2::CameraFile#data_and_size:Tuple(Pointer(UInt8), UInt64) +134
[4491425040] *GPhoto2::CameraFile#data:Pointer(UInt8) +32
[4491424949] *GPhoto2::CameraFile#to_slice:Slice(UInt8) +21
[4491424546] *GPhoto2::CameraFile#save:Nil +130
[4490921895] __crystal_main +2583
[4490974088] main +40
https://github.com/Sija/gphoto2.cr/blob/master/src/gphoto2/camera_folder.cr#L32
CameraFolder.new(@camera, File.join(@path, name))
https://github.com/Sija/gphoto2.cr/blob/master/src/gphoto2/camera/event.cr#L29
CameraFolder.new(self, File.join(path.folder, path.name))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.