Protect cross-thread access to _pending_images.
authorCarl Hetherington <cth@carlh.net>
Sun, 27 Oct 2019 12:11:32 +0000 (13:11 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 27 Oct 2019 12:11:32 +0000 (13:11 +0100)
src/lib/ffmpeg_file_encoder.cc
src/lib/ffmpeg_file_encoder.h

index e6f38df354e7b9acab2fec78ee3252d910cf9ed4..8083ac7e7dbab19919b13629292cd8b2716e6acd 100644 (file)
@@ -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);
        }
index d763c7eaf7c05a02fd0cc58b4b5598e7a4bf8785..9f1e75b686b76f32d67778a36403c0f77704ff07 100644 (file)
@@ -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;