[Spice-devel] [PATCH 11/22] Make streaming_requested a method in Stream

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


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

Until we have a proper separation of input messages, it makes sense to
have the Stream class deal with this flag.

Signed-off-by: Christophe de Dinechin <dinechin at redhat.com>
---
 src/spice-streaming-agent.cpp | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
index 403e65c..8494a8b 100644
--- a/src/spice-streaming-agent.cpp
+++ b/src/spice-streaming-agent.cpp
@@ -84,6 +84,7 @@ public:
     }
 
     const codecs_t &client_codecs() { return codecs; }
+    bool streaming_requested() { return is_streaming; }
 
     int read_command(bool blocking);
     size_t write_all(const void *buf, const size_t len);
@@ -101,14 +102,14 @@ private:
     void read_command_from_device(void);
 
 private:
-    int streamfd = -1;
     std::mutex mutex;
     codecs_t codecs;
+    int streamfd = -1;
+    bool is_streaming = false;
 };
 
 }} // namespace spice::streaming_agent
 
-static bool streaming_requested = false;
 static bool quit_requested = false;
 static bool log_binary = false;
 
@@ -141,9 +142,9 @@ void Stream::handle_stream_start_stop(uint32_t len)
         throw std::runtime_error("read command from device FAILED -- read " + std::to_string(n) +
                                  " expected " + std::to_string(len));
     }
-    streaming_requested = (msg[0] != 0); /* num_codecs */
+    is_streaming = (msg[0] != 0); /* num_codecs */
     syslog(LOG_INFO, "GOT START_STOP message -- request to %s streaming\n",
-           streaming_requested ? "START" : "STOP");
+           is_streaming ? "START" : "STOP");
     codecs.clear();
     for (int i = 1; i <= msg[0]; ++i) {
         codecs.insert((SpiceVideoCodecType) msg[i]);
@@ -423,7 +424,7 @@ do_capture(Stream &stream, const char *streamport, FILE *f_log)
 {
     unsigned int frame_count = 0;
     while (!quit_requested) {
-        while (!quit_requested && !streaming_requested) {
+        while (!quit_requested && !stream.streaming_requested()) {
             if (stream.read_command(true) < 0) {
                 syslog(LOG_ERR, "FAILED to read command\n");
                 return;
@@ -442,7 +443,7 @@ do_capture(Stream &stream, const char *streamport, FILE *f_log)
             throw std::runtime_error("cannot find a suitable capture system");
         }
 
-        while (!quit_requested && streaming_requested) {
+        while (!quit_requested && stream.streaming_requested()) {
             if (++frame_count % 100 == 0) {
                 syslog(LOG_DEBUG, "SENT %d frames\n", frame_count);
             }
-- 
2.13.5 (Apple Git-94)



More information about the Spice-devel mailing list