[Spice-devel] [PATCH 16/22] Move the capture loop in the ConcreteAgent

Christophe de Dinechin christophe at dinechin.org
Wed Feb 28 15:43:19 UTC 2018


From: Christophe de Dinechin <dinechin at redhat.com>

The agent is the class ultimately responsible for the capture loop.
This patch also gets rid of a global "agent" variable, reducing
implicitly shared state.

Signed-off-by: Christophe de Dinechin <dinechin at redhat.com>
---
 src/concrete-agent.hpp        |  4 ++++
 src/spice-streaming-agent.cpp | 20 +++++++++-----------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/concrete-agent.hpp b/src/concrete-agent.hpp
index 5bca23b..346ba6c 100644
--- a/src/concrete-agent.hpp
+++ b/src/concrete-agent.hpp
@@ -14,6 +14,9 @@
 namespace spice {
 namespace streaming_agent {
 
+class Stream;
+class FrameLog;
+
 struct ConcreteConfigureOption: ConfigureOption
 {
     ConcreteConfigureOption(const char *name, const char *value)
@@ -33,6 +36,7 @@ public:
     void Register(Plugin& plugin) override;
     const ConfigureOption* Options() const override;
     void LoadPlugins(const std::string &directory);
+    void CaptureLoop(Stream &stream, FrameLog &frame_log);
     // pointer must remain valid
     void AddOption(const char *name, const char *value);
     FrameCapture *GetBestFrameCapture(const std::set<SpiceVideoCodecType>& codecs);
diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
index 9e643bf..1c5b6c1 100644
--- a/src/spice-streaming-agent.cpp
+++ b/src/spice-streaming-agent.cpp
@@ -41,8 +41,6 @@
 
 using namespace spice::streaming_agent;
 
-static ConcreteAgent agent;
-
 namespace spice
 {
 namespace streaming_agent
@@ -488,8 +486,8 @@ static void usage(const char *progname)
     exit(1);
 }
 
-static void
-do_capture(Stream &stream, const char *streamport, FrameLog &frame_log)
+
+void ConcreteAgent::CaptureLoop(Stream &stream, FrameLog &frame_log)
 {
     unsigned int frame_count = 0;
     while (!quit_requested) {
@@ -507,7 +505,7 @@ do_capture(Stream &stream, const char *streamport, FrameLog &frame_log)
         syslog(LOG_INFO, "streaming starts now\n");
         uint64_t time_last = 0;
 
-        std::unique_ptr<FrameCapture> capture(agent.GetBestFrameCapture(stream.client_codecs()));
+        std::unique_ptr<FrameCapture> capture(GetBestFrameCapture(stream.client_codecs()));
         if (!capture) {
             throw std::runtime_error("cannot find a suitable capture system");
         }
@@ -581,6 +579,7 @@ int main(int argc, char* argv[])
 
     setlogmask(logmask);
 
+    ConcreteAgent agent;
     while ((opt = getopt_long(argc, argv, "hp:c:l:d", long_options, NULL)) != -1) {
         switch (opt) {
         case 0:
@@ -618,19 +617,17 @@ int main(int argc, char* argv[])
         }
     }
 
-    // register built-in plugins
-    MjpegPlugin::Register(&agent);
-
-    agent.LoadPlugins(pluginsdir);
-
     register_interrupts();
 
     int ret = EXIT_SUCCESS;
     try {
+        // register built-in plugins
+        MjpegPlugin::Register(&agent);
+        agent.LoadPlugins(pluginsdir);
         Stream stream(streamport);
         FrameLog frame_log(log_filename, log_binary);
         X11CursorThread cursor_thread(stream);
-        do_capture(stream, streamport, frame_log);
+        agent.CaptureLoop(stream, frame_log);
     }
     catch (Error &err) {
         err.syslog();
@@ -640,6 +637,7 @@ int main(int argc, char* argv[])
         syslog(LOG_ERR, "%s\n", err.what());
         ret = EXIT_FAILURE;
     }
+
     closelog();
     return ret;
 }
-- 
2.13.5 (Apple Git-94)



More information about the Spice-devel mailing list