From 530ab2a9dfb07400c12d8b2e01b1c51967a1f7db Mon Sep 17 00:00:00 2001
From: philippegorley <philippe.gorley@savoirfairelinux.com>
Date: Wed, 7 Jun 2017 12:11:21 -0400
Subject: [PATCH] dring: expose hardware acceleration

Adds a function in the dring API to query and set use of hardware
acceleration. This will let clients set via GUI instead of only
through dring.yml

Change-Id: I94ec612398d89b960fa091c9aebabbbc5ad4acbd
---
 bin/dbus/dbusvideomanager.cpp      | 12 ++++++++++++
 bin/dbus/dbusvideomanager.h        |  2 ++
 src/client/videomanager.cpp        | 19 +++++++++++++++++++
 src/dring/videomanager_interface.h |  3 +++
 src/manager.cpp                    |  9 +++++++--
 src/manager.h                      |  2 --
 src/preferences.cpp                |  4 ----
 src/preferences.h                  |  2 --
 8 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/bin/dbus/dbusvideomanager.cpp b/bin/dbus/dbusvideomanager.cpp
index 6367f6b761..5c968eb2f8 100644
--- a/bin/dbus/dbusvideomanager.cpp
+++ b/bin/dbus/dbusvideomanager.cpp
@@ -84,3 +84,15 @@ DBusVideoManager::hasCameraStarted() -> decltype(DRing::hasCameraStarted())
 {
     return DRing::hasCameraStarted();
 }
+
+bool
+DBusVideoManager::getDecodingAccelerated()
+{
+    return DRing::getDecodingAccelerated();
+}
+
+void
+DBusVideoManager::setDecodingAccelerated(bool state)
+{
+    DRing::setDecodingAccelerated(state);
+}
diff --git a/bin/dbus/dbusvideomanager.h b/bin/dbus/dbusvideomanager.h
index ef4a16170e..119c172dc3 100644
--- a/bin/dbus/dbusvideomanager.h
+++ b/bin/dbus/dbusvideomanager.h
@@ -60,6 +60,8 @@ class DBusVideoManager :
         void stopCamera();
         bool switchInput(const std::string& resource);
         bool hasCameraStarted();
+        bool getDecodingAccelerated();
+        void setDecodingAccelerated(bool state);
 };
 
 #endif // __RING_DBUSVIDEOMANAGER_H__
diff --git a/src/client/videomanager.cpp b/src/client/videomanager.cpp
index 05072f651b..8e966ed185 100644
--- a/src/client/videomanager.cpp
+++ b/src/client/videomanager.cpp
@@ -162,6 +162,25 @@ registerSinkTarget(const std::string& sinkId, const SinkTarget& target)
        RING_WARN("No sink found for id '%s'", sinkId.c_str());
 }
 
+bool
+getDecodingAccelerated()
+{
+#ifdef RING_ACCEL
+    return ring::Manager::instance().videoPreferences.getDecodingAccelerated();
+#else
+    return false;
+#endif
+}
+
+void
+setDecodingAccelerated(bool state)
+{
+#ifdef RING_ACCEL
+    RING_DBG("%s hardware acceleration", (state ? "Enabling" : "Disabling"));
+    ring::Manager::instance().videoPreferences.setDecodingAccelerated(state);
+#endif
+}
+
 #if defined(__ANDROID__) || defined(RING_UWP)
 void
 addVideoDevice(const std::string &node, std::vector<std::map<std::string, std::string>> const * devInfo)
diff --git a/src/dring/videomanager_interface.h b/src/dring/videomanager_interface.h
index e9b85583b9..ee18bd3413 100644
--- a/src/dring/videomanager_interface.h
+++ b/src/dring/videomanager_interface.h
@@ -77,6 +77,9 @@ void* obtainFrame(int length);
 void releaseFrame(void* frame);
 #endif
 
+bool getDecodingAccelerated();
+void setDecodingAccelerated(bool state);
+
 // Video signal type definitions
 struct VideoSignal {
         struct DeviceEvent {
diff --git a/src/manager.cpp b/src/manager.cpp
index b3edbad11e..444dbc6773 100644
--- a/src/manager.cpp
+++ b/src/manager.cpp
@@ -3063,19 +3063,24 @@ Manager::getSinkClient(const std::string& id)
     return nullptr;
 }
 
-#ifdef RING_ACCEL
 bool
 Manager::getDecodingAccelerated() const
 {
+#ifdef RING_ACCEL
     return videoPreferences.getDecodingAccelerated();
+#else
+    return false;
+#endif
 }
 
 void
 Manager::setDecodingAccelerated(bool isAccelerated)
 {
+#ifdef RING_ACCEL
     videoPreferences.setDecodingAccelerated(isAccelerated);
+    saveConfig();
+#endif
 }
-#endif // RING_ACCEL
 #endif // RING_VIDEO
 
 RingBufferPool&
diff --git a/src/manager.h b/src/manager.h
index 6a35fedea2..c9a5407fd1 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -881,11 +881,9 @@ class Manager {
 
         VideoManager& getVideoManager() const;
 
-#ifdef RING_ACCEL
         bool getDecodingAccelerated() const;
 
         void setDecodingAccelerated(bool isAccelerated);
-#endif
 #endif // RING_VIDEO
 
         std::atomic<unsigned> dhtLogLevel {0}; // default = disable
diff --git a/src/preferences.cpp b/src/preferences.cpp
index 9fa90d026d..04c066a699 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -129,10 +129,8 @@ static const char * const TOGGLE_PICKUP_HANGUP_SHORT_KEY = "togglePickupHangup";
 #ifdef RING_VIDEO
 // video preferences
 constexpr const char * const VideoPreferences::CONFIG_LABEL;
-#ifdef RING_ACCEL
 static const char * const DECODING_ACCELERATED_KEY = "decodingAccelerated";
 #endif
-#endif
 
 static const char * const DFT_PULSE_LENGTH_STR = "250"; /** Default DTMF lenght */
 static const char * const ALSA_DFT_CARD    = "0";          /** Default sound card index */
@@ -547,9 +545,7 @@ void ShortcutPreferences::unserialize(const YAML::Node &in)
 
 #ifdef RING_VIDEO
 VideoPreferences::VideoPreferences()
-#ifdef RING_ACCEL
     : decodingAccelerated_(true)
-#endif
 {
 }
 
diff --git a/src/preferences.h b/src/preferences.h
index 9ac97c3052..2a93aca210 100644
--- a/src/preferences.h
+++ b/src/preferences.h
@@ -447,7 +447,6 @@ class VideoPreferences : public Serializable {
         void serialize(YAML::Emitter &out);
         void unserialize(const YAML::Node &in);
 
-#ifdef RING_ACCEL
         bool getDecodingAccelerated() const {
             return decodingAccelerated_;
         }
@@ -455,7 +454,6 @@ class VideoPreferences : public Serializable {
         void setDecodingAccelerated(bool decodingAccelerated) {
             decodingAccelerated_ = decodingAccelerated;
         }
-#endif // RING_ACCEL
 
     private:
         bool decodingAccelerated_;
-- 
GitLab