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 23:42:57 +0000 (00:42 +0100)
src/lib/ffmpeg_file_encoder.cc
src/lib/ffmpeg_file_encoder.h

index d7a56f01eb95ccb311bd15c1e883c525e9e08ac5..abde0c153f433a754fc77c2ac253cfe2bdac67af 100644 (file)
@@ -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);
        }
index 8b9d0b67c2a7269af994690ca52ede24a6880bc2..a0c17c84680b20ba628a4f0418c7d2d1b0c8d840 100644 (file)
@@ -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;