summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-10-27 13:11:32 +0100
committerCarl Hetherington <cth@carlh.net>2019-10-28 00:42:57 +0100
commitba04eca99ebe17f139b2bcf3d9997c57dfeaeeb2 (patch)
tree5e7c0945bdedd95a5e0e88c677e7de4698c18793
parent04368a2e1626cdb62479d45d9eacb20173d3300a (diff)
Protect cross-thread access to _pending_images.
-rw-r--r--src/lib/ffmpeg_file_encoder.cc8
-rw-r--r--src/lib/ffmpeg_file_encoder.h1
2 files changed, 7 insertions, 2 deletions
diff --git a/src/lib/ffmpeg_file_encoder.cc b/src/lib/ffmpeg_file_encoder.cc
index d7a56f01e..abde0c153 100644
--- a/src/lib/ffmpeg_file_encoder.cc
+++ b/src/lib/ffmpeg_file_encoder.cc
@@ -244,7 +244,11 @@ FFmpegFileEncoder::video (shared_ptr<PlayerVideo> video, DCPTime time)
AVFrame* frame = av_frame_alloc ();
DCPOMATIC_ASSERT (frame);
- _pending_images[image->data()[0]] = image;
+ {
+ boost::mutex::scoped_lock lm (_pending_images_mutex);
+ _pending_images[image->data()[0]] = image;
+ }
+
for (int i = 0; i < 3; ++i) {
AVBufferRef* buffer = av_buffer_create(image->data()[i], image->stride()[i] * image->size().height, &buffer_free, this, 0);
frame->buf[i] = av_buffer_ref (buffer);
@@ -378,7 +382,7 @@ FFmpegFileEncoder::buffer_free (void* opaque, uint8_t* data)
void
FFmpegFileEncoder::buffer_free2 (uint8_t* data)
{
- /* XXX: does this need a lock to prevent cross-thread access to _pending_images? */
+ boost::mutex::scoped_lock lm (_pending_images_mutex);
if (_pending_images.find(data) != _pending_images.end()) {
_pending_images.erase (data);
}
diff --git a/src/lib/ffmpeg_file_encoder.h b/src/lib/ffmpeg_file_encoder.h
index 8b9d0b67c..a0c17c846 100644
--- a/src/lib/ffmpeg_file_encoder.h
+++ b/src/lib/ffmpeg_file_encoder.h
@@ -85,6 +85,7 @@ private:
their data have been passed to FFmpeg.
*/
std::map<uint8_t*, boost::shared_ptr<const Image> > _pending_images;
+ boost::mutex _pending_images_mutex;
static int _video_stream_index;
static int _audio_stream_index;