esp32-cam-mjpeg-multiclient icon indicating copy to clipboard operation
esp32-cam-mjpeg-multiclient copied to clipboard

Race hazard accessing camera between motion/static stream threads

Open fridgemagnet3 opened this issue 1 year ago • 1 comments

There is, I think, a race hazard if you have clients using the MPJEG stream and static picture URL at the same time in that that that it is possible for both threads to be accessing the camera object at the same time. This can then result in bad things happening with regard to the memory buffer pointer returned from the camera class. I can very quickly crash the board under these conditions.

I think you need a semaphore around the camera object accesses - the attached patch seems to work for me.

Cheers,

Jon.

cam_race_hazard.diff.gz

fridgemagnet3 avatar Jan 19 '24 10:01 fridgemagnet3

I actually did not care about static picture taking in this code at all. It is kind of a leftover from the example it was built upon. The goal of this POC was to make multi-client video streaming work on VLC, Blynk App video feed and browsers. So yeah, please go ahead and improve! Thank you.

arkhipenko avatar Jan 19 '24 12:01 arkhipenko