Add lock to _colours since it can be manipulated by a Job thread.
authorCarl Hetherington <cth@carlh.net>
Sat, 26 Jan 2019 19:58:37 +0000 (19:58 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 26 Jan 2019 19:58:37 +0000 (19:58 +0000)
src/lib/ffmpeg_subtitle_stream.cc
src/lib/ffmpeg_subtitle_stream.h

index c3c6c1f8635cc0d0c3c013d464a101f7f5d159ee..da8bafc0af788a3c76328b6b7ef5a54445f2c1f1 100644 (file)
@@ -39,6 +39,7 @@ FFmpegSubtitleStream::FFmpegSubtitleStream (cxml::ConstNodePtr node, int version
        : FFmpegStream (node)
 {
        if (version >= 33) {
+               boost::mutex::scoped_lock lm (_mutex);
                BOOST_FOREACH (cxml::NodePtr i, node->node_children ("Colour")) {
                        _colours[RGBA(i->node_child("From"))] = RGBA (i->node_child("To"));
                }
@@ -50,6 +51,7 @@ FFmpegSubtitleStream::as_xml (xmlpp::Node* root) const
 {
        FFmpegStream::as_xml (root);
 
+       boost::mutex::scoped_lock lm (_mutex);
        for (map<RGBA, RGBA>::const_iterator i = _colours.begin(); i != _colours.end(); ++i) {
                xmlpp::Node* node = root->add_child("Colour");
                i->first.as_xml (node->add_child("From"));
@@ -60,11 +62,13 @@ FFmpegSubtitleStream::as_xml (xmlpp::Node* root) const
 map<RGBA, RGBA>
 FFmpegSubtitleStream::colours () const
 {
+       boost::mutex::scoped_lock lm (_mutex);
        return _colours;
 }
 
 void
 FFmpegSubtitleStream::set_colour (RGBA from, RGBA to)
 {
+       boost::mutex::scoped_lock lm (_mutex);
        _colours[from] = to;
 }
index 064c72f8d6166b1beef064cf16d39bd21fb82e8e..85c4df889bdcf7a88165c28200180fd952c1d851 100644 (file)
@@ -38,5 +38,7 @@ public:
        std::map<RGBA, RGBA> colours () const;
 
 private:
+       /** mutex to protect _colours as it can be set from the "examine FFMpeg subtitles" job thread */
+       mutable boost::mutex _mutex;
        std::map<RGBA, RGBA> _colours;
 };