Use atomic for _video_container_size.
authorCarl Hetherington <cth@carlh.net>
Sat, 10 Sep 2022 15:52:20 +0000 (17:52 +0200)
committerCarl Hetherington <cth@carlh.net>
Sat, 10 Sep 2022 21:20:59 +0000 (23:20 +0200)
src/lib/player.cc
src/lib/player.h

index af963d50dd3fb6e05485c6eab9637f0d99abe157..a6cfd9367102866f75eee399421c3673dad3ea85 100644 (file)
@@ -345,17 +345,15 @@ Player::set_video_container_size (dcp::Size s)
 {
        Change (ChangeType::PENDING, PlayerProperty::VIDEO_CONTAINER_SIZE, false);
 
-       {
-               boost::mutex::scoped_lock lm (_mutex);
-
-               if (s == _video_container_size) {
-                       lm.unlock ();
-                       Change (ChangeType::CANCELLED, PlayerProperty::VIDEO_CONTAINER_SIZE, false);
-                       return;
-               }
+       if (s == _video_container_size) {
+               Change(ChangeType::CANCELLED, PlayerProperty::VIDEO_CONTAINER_SIZE, false);
+               return;
+       }
 
-               _video_container_size = s;
+       _video_container_size = s;
 
+       {
+               boost::mutex::scoped_lock lm (_mutex);
                _black_image = make_shared<Image>(AV_PIX_FMT_RGB24, _video_container_size, Image::Alignment::PADDED);
                _black_image->make_black ();
        }
@@ -870,14 +868,14 @@ Player::open_subtitles_for_frame (DCPTime time) const
                        }
 
                        /* i.image will already have been scaled to fit _video_container_size */
-                       dcp::Size scaled_size (i.rectangle.width * _video_container_size.width, i.rectangle.height * _video_container_size.height);
+                       dcp::Size scaled_size (i.rectangle.width * _video_container_size.load().width, i.rectangle.height * _video_container_size.load().height);
 
                        captions.push_back (
                                PositionImage (
                                        i.image,
                                        Position<int> (
-                                               lrint(_video_container_size.width * i.rectangle.x),
-                                               lrint(_video_container_size.height * i.rectangle.y)
+                                               lrint(_video_container_size.load().width * i.rectangle.x),
+                                               lrint(_video_container_size.load().height * i.rectangle.y)
                                                )
                                        )
                                );
@@ -1140,8 +1138,8 @@ Player::bitmap_text_start (weak_ptr<Piece> weak_piece, weak_ptr<const TextConten
                auto image = sub.image;
 
                /* We will scale the subtitle up to fit _video_container_size */
-               int const width = sub.rectangle.width * _video_container_size.width;
-               int const height = sub.rectangle.height * _video_container_size.height;
+               int const width = sub.rectangle.width * _video_container_size.load().width;
+               int const height = sub.rectangle.height * _video_container_size.load().height;
                if (width == 0 || height == 0) {
                        return;
                }
index 511a579a08baed0f8f0be5a5f46c9a6f78003d54..d586622c4a46ded11a34b540acb371cc9658d7f0 100644 (file)
@@ -83,7 +83,6 @@ public:
        std::vector<std::shared_ptr<dcpomatic::Font>> get_subtitle_fonts ();
        std::list<ReferencedReelAsset> get_reel_assets ();
        dcp::Size video_container_size () const {
-               boost::mutex::scoped_lock lm (_mutex);
                return _video_container_size;
        }
 
@@ -174,7 +173,7 @@ private:
        /** Size of the image we are rendering to; this may be the DCP frame size, or
         *  the size of preview in a window.
         */
-       dcp::Size _video_container_size;
+       boost::atomic<dcp::Size> _video_container_size;
        std::shared_ptr<Image> _black_image;
 
        /** true if the player should ignore all video; i.e. never produce any */