From 2493ad1cb5834eaf985ff489d5997756138918a2 Mon Sep 17 00:00:00 2001
From: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Date: Wed, 7 Oct 2015 09:39:44 -0400
Subject: [PATCH] video: reuse scaler

Video scaler now follows sink lifecycle

Issue: #81116
Change-Id: Ibb053991b265131e1f63e1b2a169821e1d0f3bae
---
 src/manager.cpp                |  1 +
 src/media/video/sinkclient.cpp | 10 ++++++----
 src/media/video/sinkclient.h   |  3 +++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/manager.cpp b/src/manager.cpp
index 6da67fb820..c9ce4c0fd2 100644
--- a/src/manager.cpp
+++ b/src/manager.cpp
@@ -66,6 +66,7 @@ using random_device = std::random_device;
 
 #ifdef RING_VIDEO
 #include "client/videomanager.h"
+#include "video/video_scaler.h"
 #endif
 
 #include "conference.h"
diff --git a/src/media/video/sinkclient.cpp b/src/media/video/sinkclient.cpp
index 0b9e584290..a5e63e4801 100644
--- a/src/media/video/sinkclient.cpp
+++ b/src/media/video/sinkclient.cpp
@@ -30,13 +30,13 @@
 #include "shm_header.h"
 #endif // HAVE_SHM
 
-#include "video_scaler.h"
 #include "media_buffer.h"
 #include "logger.h"
 #include "noncopyable.h"
 #include "client/ring_signal.h"
 #include "dring/videomanager_interface.h"
 #include "libav_utils.h"
+#include "video_scaler.h"
 
 #ifndef _WIN32
 #include <sys/mman.h>
@@ -297,11 +297,14 @@ SinkClient::stop() noexcept
 
 #endif // !HAVE_SHM
 
-SinkClient::SinkClient(const std::string& id, bool mixer) : id_ {id}, mixer_(mixer)
+SinkClient::SinkClient(const std::string& id, bool mixer)
+    : id_ {id}
+    , mixer_(mixer)
 #ifdef DEBUG_FPS
     , frameCount_(0u)
     , lastFrameDebug_(std::chrono::system_clock::now())
 #endif
+    , scaler_(new VideoScaler())
 {}
 
 void
@@ -327,7 +330,6 @@ SinkClient::update(Observable<std::shared_ptr<VideoFrame>>* /*obs*/,
 
     if (target_.pull) {
         VideoFrame dst;
-        VideoScaler scaler;
         const int width = f->width();
         const int height = f->height();
 #ifndef __APPLE__
@@ -343,7 +345,7 @@ SinkClient::update(Observable<std::shared_ptr<VideoFrame>>* /*obs*/,
                 buffer_ptr->width = width;
                 buffer_ptr->height = height;
                 dst.setFromMemory(buffer_ptr->ptr, format, width, height);
-                scaler.scale(*f, dst);
+                scaler_->scale(*f, dst);
                 target_.push(std::move(buffer_ptr));
             }
         }
diff --git a/src/media/video/sinkclient.h b/src/media/video/sinkclient.h
index 91168a238c..608ed04d56 100644
--- a/src/media/video/sinkclient.h
+++ b/src/media/video/sinkclient.h
@@ -39,6 +39,8 @@ namespace ring { namespace video {
 class ShmHolder;
 #endif // HAVE_SHM
 
+class VideoScaler;
+
 class SinkClient : public VideoFramePassiveReader
 {
     public:
@@ -68,6 +70,7 @@ class SinkClient : public VideoFramePassiveReader
         const bool mixer_;
         bool started_ {false}; // used to arbitrate client's stop signal.
         DRing::SinkTarget target_;
+        std::unique_ptr<VideoScaler> scaler_;
 
 #ifdef DEBUG_FPS
         unsigned frameCount_;
-- 
GitLab