Comments (3)
This issue has affected me as well, though the length of time before the error occurs varies wildly: sometimes it happens instantly upon program start, sometimes it takes several minutes, sometimes longer.
from picamera.
Okay, finally gotten to the bottom of this and a fix will be forthcoming shortly. But it's probably worth documenting as it's an interesting one...
The issue is indeed caused by a race condition, and it's been there since day one. However, being a race condition it requires specific timing for the bug to manifest. In the case of earlier versions of picamera (and I think even in raspistill too) the main thread is sufficiently fast in disabling the background encoder thread that the bug had little or no chance of appearing.
One extra "if" statement was introduced in release 1.0 and it seems this was just enough to push the main thread into being slow enough for the bug to appear. Specifically, once the camera is set to capture, the encoder callback is repeatedly until a full frame has been captured. Once a full frame has been captured, it appears the encoder callback is called once more (for what purpose I'm not sure, but it's not for writing anything to the file). Only the main thread can disable the port (shutting down the background encoder thread), so once the encoder callback notices the end of the frame it wakes up the main thread (via a semaphore) to disable the port.
In the vast majority of cases, the main thread wakes up quickly, disables the port, and everything is fine. But one in every few thousand calls (in picamera 1.0), the main thread is a little slow and the extraneous post-frame-end call to the encoder callback (mentioned above), is already running when the port gets disabled. Crucially, the port has to be disabled immediately before the call to mmal_port_send_buffer because before this is a check that the port is enabled (which must pass in order for the call to mmal_port_send_buffer to occur). This is the location of the race condition.
To fix the race condition I've done a couple of things. Firstly, we no longer check whether the port is enabled when recycling the buffers - we just assume it. Secondly, we use the internal flag in the encoder ("stopped") to ensure that, after frame-end is encountered, any subsequent calls to the encoder's callback are ignored. As the flag is only set within the encoder thread, or when the encoder thread is guaranteed not to be running, no race condition is introduced.
The test suite is currently running (mostly to make sure I haven't broken any edge cases as this is a change to the base encoder class) and if it passes, I'll push the fix for anyone desperate to get it early. Otherwise, it'll be in a release just before the weekend (hopefully with a couple of other minor bits if I can get them done in time).
from picamera.
Well, as it turned out I did break a couple of things (split recording for one). They're fixed now but I didn't quite make the release before the weekend. Instead there should be one later today after I've knocked off a couple of doc related tasks
from picamera.
Related Issues (20)
- Easy way to tap off frames pre-encoding
- python3-picamera package depends on python3-numpy
- What is the default intra-frame period? HOT 2
- Limited running time HOT 1
- Not supported in bullseye Raspberry Pi OS version HOT 3
- Jumping exposure time on Raspberry Pi HQ camera HOT 1
- [Docmentation] How to find out the Bayer pattern from the CFA layout HOT 2
- Can one access both frames from the OPQV-dual stream and output the difference in real time? HOT 2
- libmmal.so: cannot open shared object file: No such file or directory HOT 6
- Frame freezes whilst try display/save high resolution frame HOT 1
- shutter_speed TypeError HOT 12
- Cannot install on development machine
- No such file or directory HOT 1
- PiCamera start_preview blocks indefinitely
- Realtime Motion Detection Latency
- Camera eposure time doubled from shutter speed?
- Is the `PiBayerArray.flush` method unpacking data correctly?
- 4.16. Raw Bayer data captures - Example Code - Assertion Error
- mjk
- stereo mode: how to switch camera sides HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from picamera.