diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-10-27 13:11:32 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-10-27 13:11:32 +0100 |
| commit | 982933e31681d05b1d3addac5a9eff58ea4579c5 (patch) | |
| tree | e67f3be9532d8e5e4c6bafbe67c1ddb2a9bc89a2 /src/lib | |
| parent | 895b386b6751afd3d068155f4ea71e762297672a (diff) | |
Protect cross-thread access to _pending_images.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/ffmpeg_file_encoder.cc | 9 | ||||
| -rw-r--r-- | src/lib/ffmpeg_file_encoder.h | 1 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/lib/ffmpeg_file_encoder.cc b/src/lib/ffmpeg_file_encoder.cc index e6f38df35..8083ac7e7 100644 --- a/src/lib/ffmpeg_file_encoder.cc +++ b/src/lib/ffmpeg_file_encoder.cc @@ -278,7 +278,12 @@ 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); + DCPOMATIC_ASSERT (_pending_images.find(image->data()[0]) != _pending_images.end()); + _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); @@ -422,7 +427,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 d763c7eaf..9f1e75b68 100644 --- a/src/lib/ffmpeg_file_encoder.h +++ b/src/lib/ffmpeg_file_encoder.h @@ -90,6 +90,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; |
