web-gphoto2 icon indicating copy to clipboard operation
web-gphoto2 copied to clipboard

Cannot stop live-view after starting it

Open icheered opened this issue 2 years ago • 6 comments

Camera: Nikon D5300

When starting the viewfinder (live-view) the camera raises the mirror and you can capturePreviewAsBlob at high speed. When trying to disable the viewfinder it will error:

Error: libapi.mjs?v=263350c0:9 Uncaught (in promise) Error: I/O in progress

My first guess is that it has something to do with the scheduling of events like @RReverser mentions in his blog.

Notes

  1. I can still change other settings like ISO while in liveview.
  2. Using the gphoto2 CLI I can enable and disable liveview as normal
  3. Updating libgphoto2 to the latest version does not fix the issue

icheered avatar Oct 09 '23 13:10 icheered

I'm also always got

Could not refresh preview: Error: Unspecified error
    at throw_msg (libapi.mjs?v=54d10e0e:9:16162)
    at libapi.wasm:0xe8f33
    at ret.<computed> (libapi.mjs?v=54d10e0e:9:125562)
    at invoke_vi (libapi.mjs?v=54d10e0e:9:191780)
    at libapi.wasm:0xe28c0
    at libapi.wasm:0xc70ff
    at libapi.wasm:0xe8cfc
    at ret.<computed> (libapi.mjs?v=54d10e0e:9:125562)
    at Object.doRewind (libapi.mjs?v=54d10e0e:9:126851)
    at libapi.mjs?v=54d10e0e:9:127444

Is there any reference?

irvandikky avatar Oct 09 '23 16:10 irvandikky

When trying to disable the viewfinder it will error:

What do you mean by disabling the viewfinder? Manually on the camera? Or somehow via the API?

RReverser avatar Oct 09 '23 16:10 RReverser

Via the API. I call camera.setConfigValue() with name='viewfinder' and value='1' which raises the mirror (audible), but when calling the function again but with value='0' to lower the mirror again it will give the previously mentioned "I/O in progress" error.

This is the settings object that I retrieve from the camera:

    "name": "viewfinder",
    "info": "",
    "label": "Nikon Viewfinder",
    "readonly": false,
    "type": "toggle",
    "value": "0",
    "category": "actions"
}

icheered avatar Oct 09 '23 17:10 icheered

Just to be sure, are you awaiting the promise from setConfigValue before continuing?

RReverser avatar Oct 09 '23 17:10 RReverser

Basically yeah, this sounds like typical scheduling problem. That #schedule wrapper in the API should take care of it and make sure that you're not trying to lower the mirror in the middle of a frame capture. If it doesn't, then either the uiTimeout needs to be increased or there is some other ordering bug.

RReverser avatar Oct 09 '23 17:10 RReverser

not trying to lower the mirror in the middle of a frame capture

FWIW this doesn't happen in official CLI because they are not thread-safe, run in single-threaded mode and from their PoV all USB operations are blocking so can't execute concurrently in principle.

In our case it's async APIs under the hood which is why the promise queue is needed - if kinda acts like a mutex, ensuring that no operations overlap, otherwise you get the mentioned "device busy" issue.

RReverser avatar Oct 09 '23 17:10 RReverser