From 9e3f21605d28586001d733e143cc2a848ef3fe4a Mon Sep 17 00:00:00 2001
From: philippegorley <philippe.gorley@savoirfairelinux.com>
Date: Tue, 6 Nov 2018 17:02:25 -0500
Subject: [PATCH] api: add way to get renderer info

Adds ability to retrieve the shm renderer info from a call id, in case
the client is launched mid call (else it can't show the call).

SinkClient now keeps track of its width and height.

Change-Id: Ie43c196c60de5e22825fc71ff404e99bbfbe9402
Gitlab: #59
Reviewed-by: Sebastien Blin <sebastien.blin@savoirfairelinux.com>
---
 bin/dbus/cx.ring.Ring.VideoManager.xml | 11 +++++++++++
 bin/dbus/dbusvideomanager.cpp          |  6 ++++++
 bin/dbus/dbusvideomanager.h            |  1 +
 configure.ac                           |  2 +-
 doc/doxygen/core-doc.cfg.in            |  2 +-
 src/client/videomanager.cpp            | 20 ++++++++++++++++++++
 src/dring/media_const.h                |  7 +++++++
 src/dring/videomanager_interface.h     |  1 +
 src/media/video/sinkclient.cpp         |  2 ++
 src/media/video/sinkclient.h           | 10 ++++++++++
 10 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/bin/dbus/cx.ring.Ring.VideoManager.xml b/bin/dbus/cx.ring.Ring.VideoManager.xml
index 5e3390a1b3..c1b648a841 100644
--- a/bin/dbus/cx.ring.Ring.VideoManager.xml
+++ b/bin/dbus/cx.ring.Ring.VideoManager.xml
@@ -110,6 +110,17 @@
             </arg>
         </method>
 
+        <method name="getRenderer" tp:name-for-bindings="getRenderer">
+            <tp:docstring>Returns a map of information about a call's renderer.</tp:docstring>
+            <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/>
+            <arg type="s" name="callId" direction="in">
+                <tp:docstring>Call ID to get info about.</tp:docstring>
+            </arg>
+            <arg type="a{ss}" name="map" direction="out">
+                <tp:docstring>Map containing renderer info, with empty strings and "0" if not found.</tp:docstring>
+            </arg>
+        </method>
+
         <signal name="deviceEvent" tp:name-for-bindings="deviceEvent">
            <tp:docstring>Signal triggered by changes in the detected v4l2 devices, e.g. a camera being unplugged.</tp:docstring>
         </signal>
diff --git a/bin/dbus/dbusvideomanager.cpp b/bin/dbus/dbusvideomanager.cpp
index 744e9ebba4..09c15bc6b8 100644
--- a/bin/dbus/dbusvideomanager.cpp
+++ b/bin/dbus/dbusvideomanager.cpp
@@ -97,6 +97,12 @@ DBusVideoManager::setDecodingAccelerated(const bool& state)
     DRing::setDecodingAccelerated(state);
 }
 
+std::map<std::string, std::string>
+DBusVideoManager::getRenderer(const std::string& callId)
+{
+    return DRing::getRenderer(callId);
+}
+
 std::string
 DBusVideoManager::startLocalRecorder(const bool& audioOnly, const std::string& filepath)
 {
diff --git a/bin/dbus/dbusvideomanager.h b/bin/dbus/dbusvideomanager.h
index 2148eb89d8..ff719a96d5 100644
--- a/bin/dbus/dbusvideomanager.h
+++ b/bin/dbus/dbusvideomanager.h
@@ -63,6 +63,7 @@ class DRING_PUBLIC DBusVideoManager :
         bool hasCameraStarted();
         bool getDecodingAccelerated();
         void setDecodingAccelerated(const bool& state);
+        std::map<std::string, std::string> getRenderer(const std::string& callId);
         std::string startLocalRecorder(const bool& audioOnly, const std::string& filepath);
         void stopLocalRecorder(const std::string& filepath);
 };
diff --git a/configure.ac b/configure.ac
index 668d866500..f05b9efdce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ dnl Ring - configure.ac for automake 1.9 and autoconf 2.59
 
 dnl Process this file with autoconf to produce a configure script.
 AC_PREREQ([2.65])
-AC_INIT([Ring Daemon],[7.0.0],[ring@gnu.org],[ring])
+AC_INIT([Ring Daemon],[7.1.0],[ring@gnu.org],[ring])
 
 AC_COPYRIGHT([[Copyright (c) Savoir-faire Linux 2004-2018]])
 AC_REVISION([$Revision$])
diff --git a/doc/doxygen/core-doc.cfg.in b/doc/doxygen/core-doc.cfg.in
index 6f871db8e0..131f33f799 100644
--- a/doc/doxygen/core-doc.cfg.in
+++ b/doc/doxygen/core-doc.cfg.in
@@ -31,7 +31,7 @@ PROJECT_NAME           = "Ring Daemon"
 # This could be handy for archiving the generated documentation or
 # if some version control system is used.
 
-PROJECT_NUMBER         = 7.0.0
+PROJECT_NUMBER         = 7.1.0
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer
diff --git a/src/client/videomanager.cpp b/src/client/videomanager.cpp
index ccbc94ef09..3f723675d3 100644
--- a/src/client/videomanager.cpp
+++ b/src/client/videomanager.cpp
@@ -34,6 +34,7 @@
 #include "video/sinkclient.h"
 #include "client/ring_signal.h"
 #include "audio/ringbufferpool.h"
+#include "dring/media_const.h"
 
 #include <functional>
 #include <memory>
@@ -349,6 +350,25 @@ registerSinkTarget(const std::string& sinkId, const SinkTarget& target)
        RING_WARN("No sink found for id '%s'", sinkId.c_str());
 }
 
+std::map<std::string, std::string>
+getRenderer(const std::string& callId)
+{
+   if (auto sink = ring::Manager::instance().getSinkClient(callId))
+       return {
+           {DRing::Media::Details::CALL_ID,  callId},
+           {DRing::Media::Details::SHM_PATH, sink->openedName()},
+           {DRing::Media::Details::WIDTH,    ring::to_string(sink->getWidth())},
+           {DRing::Media::Details::HEIGHT,   ring::to_string(sink->getHeight())},
+       };
+   else
+       return {
+           {DRing::Media::Details::CALL_ID,  callId},
+           {DRing::Media::Details::SHM_PATH, ""},
+           {DRing::Media::Details::WIDTH,    "0"},
+           {DRing::Media::Details::HEIGHT,   "0"},
+       };
+}
+
 bool
 getDecodingAccelerated()
 {
diff --git a/src/dring/media_const.h b/src/dring/media_const.h
index 8e542a83f3..1bd40414ab 100644
--- a/src/dring/media_const.h
+++ b/src/dring/media_const.h
@@ -40,6 +40,13 @@ namespace Details {
 
 constexpr static char MEDIA_TYPE_AUDIO[] = "MEDIA_TYPE_AUDIO";
 constexpr static char MEDIA_TYPE_VIDEO[] = "MEDIA_TYPE_VIDEO";
+
+// Renderer and Shm info
+constexpr static char CALL_ID [] = "CALL_ID";
+constexpr static char SHM_PATH[] = "SHM_PATH";
+constexpr static char WIDTH   [] = "WIDTH";
+constexpr static char HEIGHT  [] = "HEIGHT";
+
 }
 
 } //namespace DRing::Media
diff --git a/src/dring/videomanager_interface.h b/src/dring/videomanager_interface.h
index 7bf40be7ce..d849be2c46 100644
--- a/src/dring/videomanager_interface.h
+++ b/src/dring/videomanager_interface.h
@@ -150,6 +150,7 @@ DRING_PUBLIC bool hasCameraStarted();
 DRING_PUBLIC bool switchInput(const std::string& resource);
 DRING_PUBLIC bool switchToCamera();
 DRING_PUBLIC void registerSinkTarget(const std::string& sinkId, const SinkTarget& target);
+DRING_PUBLIC std::map<std::string, std::string> getRenderer(const std::string& callId);
 
 DRING_PUBLIC std::string startLocalRecorder(const bool& audioOnly, const std::string& filepath);
 DRING_PUBLIC void stopLocalRecorder(const std::string& filepath);
diff --git a/src/media/video/sinkclient.cpp b/src/media/video/sinkclient.cpp
index aa267404f9..ef4265a911 100644
--- a/src/media/video/sinkclient.cpp
+++ b/src/media/video/sinkclient.cpp
@@ -365,6 +365,8 @@ SinkClient::update(Observable<std::shared_ptr<VideoFrame>>* /*obs*/,
 void
 SinkClient::setFrameSize(int width, int height)
 {
+    width_ = width;
+    height_ = height;
     if (width > 0 and height > 0) {
         RING_WARN("Start sink <%s / %s>, size=%dx%d, mixer=%u",
                  getId().c_str(), openedName().c_str(), width, height, mixer_);
diff --git a/src/media/video/sinkclient.h b/src/media/video/sinkclient.h
index 32b5c92c2e..8068e8623c 100644
--- a/src/media/video/sinkclient.h
+++ b/src/media/video/sinkclient.h
@@ -54,6 +54,14 @@ class SinkClient : public VideoFramePassiveReader
 
         std::string openedName() const noexcept;
 
+        int getWidth() const noexcept {
+            return width_;
+        }
+
+        int getHeight() const noexcept {
+            return height_;
+        }
+
         // as VideoFramePassiveReader
         void update(Observable<std::shared_ptr<ring::VideoFrame>>*,
                     const std::shared_ptr<ring::VideoFrame>&) override;
@@ -70,6 +78,8 @@ class SinkClient : public VideoFramePassiveReader
     private:
         const std::string id_;
         const bool mixer_;
+        int width_ {0};
+        int height_ {0};
         bool started_ {false}; // used to arbitrate client's stop signal.
         DRing::SinkTarget target_;
         std::unique_ptr<VideoScaler> scaler_;
-- 
GitLab