[RFC,spice-streaming-agent,2/2] spice-streaming-agent: fully reset the capture loop on start/stop requests

Submitted by Kevin Pouget on July 31, 2019, 8:36 a.m.

Details

Message ID 20190731083636.21493-4-kpouget@redhat.com
State New
Headers show
Series "Series without cover letter" ( rev: 2 1 ) in Spice

Not browsing as part of any series.

Commit Message

Kevin Pouget July 31, 2019, 8:36 a.m.
With this patch, spice-streaming-agent exits the frame-sending loop
when START/STOP requests are received. This allows the recomputation
of the most suitable capture/encoding plugin, that may have been
updated with START/STOP message.
---
 src/spice-streaming-agent.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
index 49f5dc4..3626ecc 100644
--- a/src/spice-streaming-agent.cpp
+++ b/src/spice-streaming-agent.cpp
@@ -126,6 +126,7 @@  private:
 };
 
 static bool streaming_requested = false;
+static bool reset_requested = false;
 static bool quit_requested = false;
 static std::set<SpiceVideoCodecType> client_codecs;
 
@@ -169,6 +170,7 @@  static void read_command_from_device(StreamPort &stream_port)
         StartStopMessage msg = in_message.get_payload<StartStopMessage>();
         streaming_requested = msg.start_streaming;
         client_codecs = msg.client_codecs;
+        reset_requested = true;
 
         syslog(LOG_INFO, "GOT START_STOP message -- request to %s streaming",
                streaming_requested ? "START" : "STOP");
@@ -240,13 +242,16 @@  do_capture(StreamPort &stream_port, FrameLog &frame_log, ConcreteAgent &agent)
         if (quit_requested) {
             return;
         }
+        reset_requested = false;
 
         syslog(LOG_INFO, "streaming starts now");
         uint64_t time_last = 0;
 
         std::unique_ptr<FrameCapture> capture(agent.GetBestFrameCapture(client_codecs));
         if (!capture) {
-            throw std::runtime_error("cannot find a suitable capture system");
+            syslog(LOG_ERR, "Error cannot find a suitable capture system");
+            streaming_requested = false;
+            continue;
         }
 
         std::vector<DeviceDisplayInfo> display_info;
@@ -275,7 +280,7 @@  do_capture(StreamPort &stream_port, FrameLog &frame_log, ConcreteAgent &agent)
             syslog(LOG_ERR, "Empty device display info from the plugin");
         }
 
-        while (!quit_requested && streaming_requested) {
+        while (!quit_requested && streaming_requested && !reset_requested) {
             if (++frame_count % 100 == 0) {
                 syslog(LOG_DEBUG, "SENT %d frames", frame_count);
             }