Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate protection against multi-access lockup #4

Closed
waveform80 opened this issue Oct 18, 2013 · 8 comments
Closed

Investigate protection against multi-access lockup #4

waveform80 opened this issue Oct 18, 2013 · 8 comments
Assignees
Milestone

Comments

@waveform80
Copy link
Owner

A thread on the Pi Camera forum indicates it may be possible to guard against lockup of the camera when multiple processes attempt to access it:

While fumbling with vcdbg syms and vdbg dump 0xdec02020 (the address of cam_alloc_alloc_count), I found that when the camera is not being used, the value of cam_alloc_alloc_count is 0, and when in use, it is 1.
Now to find an appropriate place to implement a test for this to prevent crashing the camera.

This should be added to PiCamera.__init__ but looks like it'll require a bit more header translation, hence it won't make it into 0.5, but should be added before 1.0.

@ghost ghost assigned waveform80 Oct 18, 2013
@waveform80
Copy link
Owner Author

Unfortunately, this requires root access. Moreover, as the follow-on message in the thread indicates, while it would protect against MMAL-based apps simultaneously accessing the camera, it wouldn't protect against OpenMAX-based apps. For now, the best we can reasonably do (without requiring root access, which is excessive for such a minor feature) is simply ensure the class itself isn't accidentally instantiated multiple times.

waveform80 added a commit that referenced this issue Oct 21, 2013
@SnowLeopard71
Copy link

Thought I'd clarify: Checking the value of cam_alloc_alloc_count will show if the camera is in use whether it by OpenMAX or MMAL libraries. My followup in the thread was unclear in that sense (and a vain attempt to get some kind of fix put into the firmware that prevents a lockup that requires a reboot).
root access is required because read-write access is required on /dev/vc-mem (read only doesn't work). Changing permissions can allow vcdbg to work without requiring root.

@waveform80
Copy link
Owner Author

Ah, thanks for the clarification! Given that quite a lot of people seem to run python+picamera as root (probably for things like GPIO access), and given the technique would cover MMAL and OpenMAX, I've decided this ought to be reinstated as a goal for 1.0. The root access requirement can be made tentative (much like the led property): if we have access to /dev/vc-mem we can perform the check and bail if it fails, if we don't have access we can fall back to simply guarding against multiple instantiations of the class itself as a best-effort.

@waveform80 waveform80 reopened this Nov 4, 2013
@waveform80
Copy link
Owner Author

Hah! Just as I was coding up stuff for reading the ref-count from /dev/vc-mem I see James' comment on raspberrypi/userland#39 indicating it's fixed in the firmware. I suppose I could still include something for users of older firmware, but to be honest I'd rather encourage people to upgrade to the latest firmware (especially seeing as it fixes a bunch of other issues too)

@bennywoochi
Copy link

Hello Dave,
I'm using your livestream on the raspberry PI. Everything is working fine. But if I want to make a picture wiht the following command: raspistill -o image.jpg during the live stream is running I get the following error message:

mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
mmal: camera component couldn't be enabled
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates

Can you help me?
Is it possible to create pictures or videos during the livestream?

Thank you!

@waveform80
Copy link
Owner Author

It is possible, but only from within the same process; i.e. if one process (pistreaming or some picamera script) is using the camera, another process (like raspistill or raspivid) can't. However, the camera can produce JPEGs while recording video as shown in this recipe so if you can adjust your script to do both, you should be good to go.

@bennywoochi
Copy link

Thank you Dave. In what file I have to add this code?
import picamera

with picamera.PiCamera() as camera:
camera.resolution = (800, 600)
camera.start_preview()
camera.start_recording('foo.h264')
camera.wait_recording(10)
camera.capture('foo.jpg', use_video_port=True)
camera.wait_recording(10)
camera.stop_recording()

Thanks!

@waveform80
Copy link
Owner Author

Well, it's not quite a matter of just copying and pasting that code somewhere - you need to understand what it does and then use that technique in whatever script you're working with. So, firstly when you say you're using a "livestream" what script is that exactly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants