Coder Social home page Coder Social logo

gphoto2.cr's Introduction

gphoto2.cr's People

Contributors

sija avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gphoto2.cr's Issues

Invalid memory access while using Context#error_callback

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

Support calling timeout functions

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.

v0.1

Meta-ticket for v0.1 release

Port:

  • enumeration

Camera:

  • selection
  • reading abilities
  • capture & preview
  • filesystem operations
  • events (like waiting for a file being added)
  • reading config tree
  • writing config settings

Building on linux

/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`

Calling Camera#file fails for queued calls

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

#finalize vs #close mismatch

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.