[Spice-devel] [PATCH spice-server 09/15] Factor out dcc_stream_stop()
Jonathon Jongsma
jjongsma at redhat.com
Fri Oct 20 21:13:14 UTC 2017
Separate the channel code from the channel client code. Move the channel
client code to a new function.
Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
---
server/dcc.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
server/dcc.h | 1 +
server/stream.c | 56 +++-----------------------------------------------------
3 files changed, 58 insertions(+), 53 deletions(-)
diff --git a/server/dcc.c b/server/dcc.c
index 00bc28b92..13166645c 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -1732,3 +1732,57 @@ void dcc_create_stream(DisplayChannelClient *dcc, Stream *stream)
#endif
}
+static void stream_agent_stats_print(StreamAgent *agent)
+{
+#ifdef STREAM_STATS
+ StreamStats *stats = &agent->stats;
+ double passed_mm_time = (stats->end - stats->start) / 1000.0;
+ VideoEncoderStats encoder_stats = {0};
+
+ if (agent->video_encoder) {
+ agent->video_encoder->get_stats(agent->video_encoder, &encoder_stats);
+ }
+
+ spice_debug("stream=%p dim=(%dx%d) #in-frames=%"PRIu64" #in-avg-fps=%.2f #out-frames=%"PRIu64" "
+ "out/in=%.2f #drops=%"PRIu64" (#pipe=%"PRIu64" #fps=%"PRIu64") out-avg-fps=%.2f "
+ "passed-mm-time(sec)=%.2f size-total(MB)=%.2f size-per-sec(Mbps)=%.2f "
+ "size-per-frame(KBpf)=%.2f avg-quality=%.2f "
+ "start-bit-rate(Mbps)=%.2f end-bit-rate(Mbps)=%.2f",
+ agent, agent->stream->width, agent->stream->height,
+ stats->num_input_frames,
+ stats->num_input_frames / passed_mm_time,
+ stats->num_frames_sent,
+ (stats->num_frames_sent + 0.0) / stats->num_input_frames,
+ stats->num_drops_pipe +
+ stats->num_drops_fps,
+ stats->num_drops_pipe,
+ stats->num_drops_fps,
+ stats->num_frames_sent / passed_mm_time,
+ passed_mm_time,
+ stats->size_sent / 1024.0 / 1024.0,
+ ((stats->size_sent * 8.0) / (1024.0 * 1024)) / passed_mm_time,
+ stats->size_sent / 1000.0 / stats->num_frames_sent,
+ encoder_stats.avg_quality,
+ encoder_stats.starting_bit_rate / (1024.0 * 1024),
+ encoder_stats.cur_bit_rate / (1024.0 * 1024));
+#endif
+}
+
+void dcc_stream_stop(DisplayChannelClient *dcc, int stream_id)
+{
+ StreamAgent *stream_agent = dcc_get_stream_agent(dcc, stream_id);
+ region_clear(&stream_agent->vis_region);
+ region_clear(&stream_agent->clip);
+ if (stream_agent->video_encoder) {
+ uint64_t stream_bit_rate = stream_agent->video_encoder->get_bit_rate(stream_agent->video_encoder);
+
+ if (stream_bit_rate > dcc_get_max_stream_bit_rate(dcc)) {
+ spice_debug("old max-bit-rate=%.2f new=%.2f",
+ dcc_get_max_stream_bit_rate(dcc) / 8.0 / 1024.0 / 1024.0,
+ stream_bit_rate / 8.0 / 1024.0 / 1024.0);
+ dcc_set_max_stream_bit_rate(dcc, stream_bit_rate);
+ }
+ }
+ red_channel_client_pipe_add(RED_CHANNEL_CLIENT(dcc), stream_destroy_item_new(stream_agent));
+ stream_agent_stats_print(stream_agent);
+}
diff --git a/server/dcc.h b/server/dcc.h
index 0119c57df..5fb61a605 100644
--- a/server/dcc.h
+++ b/server/dcc.h
@@ -203,6 +203,7 @@ void dcc_set_max_stream_bit_rate(DisplayChannelClient *dcc, uint64_t rate);
gboolean dcc_is_low_bandwidth(DisplayChannelClient *dcc);
GArray *dcc_get_preferred_video_codecs_for_encoding(DisplayChannelClient *dcc);
void dcc_update_streams_max_latency(DisplayChannelClient *dcc, StreamAgent *remove_agent);
+void dcc_stream_stop(DisplayChannelClient *dcc, int stream_id);
typedef struct RedStreamClipItem {
RedPipeItem base;
diff --git a/server/stream.c b/server/stream.c
index f45a92feb..c3cdd6707 100644
--- a/server/stream.c
+++ b/server/stream.c
@@ -27,68 +27,18 @@
#define FOREACH_STREAMS(display, item) \
RING_FOREACH(item, &(display)->priv->streams)
-static void stream_agent_stats_print(StreamAgent *agent)
-{
-#ifdef STREAM_STATS
- StreamStats *stats = &agent->stats;
- double passed_mm_time = (stats->end - stats->start) / 1000.0;
- VideoEncoderStats encoder_stats = {0};
-
- if (agent->video_encoder) {
- agent->video_encoder->get_stats(agent->video_encoder, &encoder_stats);
- }
-
- spice_debug("stream=%p dim=(%dx%d) #in-frames=%"PRIu64" #in-avg-fps=%.2f #out-frames=%"PRIu64" "
- "out/in=%.2f #drops=%"PRIu64" (#pipe=%"PRIu64" #fps=%"PRIu64") out-avg-fps=%.2f "
- "passed-mm-time(sec)=%.2f size-total(MB)=%.2f size-per-sec(Mbps)=%.2f "
- "size-per-frame(KBpf)=%.2f avg-quality=%.2f "
- "start-bit-rate(Mbps)=%.2f end-bit-rate(Mbps)=%.2f",
- agent, agent->stream->width, agent->stream->height,
- stats->num_input_frames,
- stats->num_input_frames / passed_mm_time,
- stats->num_frames_sent,
- (stats->num_frames_sent + 0.0) / stats->num_input_frames,
- stats->num_drops_pipe +
- stats->num_drops_fps,
- stats->num_drops_pipe,
- stats->num_drops_fps,
- stats->num_frames_sent / passed_mm_time,
- passed_mm_time,
- stats->size_sent / 1024.0 / 1024.0,
- ((stats->size_sent * 8.0) / (1024.0 * 1024)) / passed_mm_time,
- stats->size_sent / 1000.0 / stats->num_frames_sent,
- encoder_stats.avg_quality,
- encoder_stats.starting_bit_rate / (1024.0 * 1024),
- encoder_stats.cur_bit_rate / (1024.0 * 1024));
-#endif
-}
void stream_stop(DisplayChannel *display, Stream *stream)
{
DisplayChannelClient *dcc;
+ int stream_id = display_channel_get_stream_id(display, stream);
spice_return_if_fail(ring_item_is_linked(&stream->link));
spice_return_if_fail(!stream->current);
- spice_debug("stream %d", display_channel_get_stream_id(display, stream));
+ spice_debug("stream %d", stream_id);
FOREACH_DCC(display, dcc) {
- StreamAgent *stream_agent;
-
- stream_agent = dcc_get_stream_agent(dcc, display_channel_get_stream_id(display, stream));
- region_clear(&stream_agent->vis_region);
- region_clear(&stream_agent->clip);
- if (stream_agent->video_encoder) {
- uint64_t stream_bit_rate = stream_agent->video_encoder->get_bit_rate(stream_agent->video_encoder);
-
- if (stream_bit_rate > dcc_get_max_stream_bit_rate(dcc)) {
- spice_debug("old max-bit-rate=%.2f new=%.2f",
- dcc_get_max_stream_bit_rate(dcc) / 8.0 / 1024.0 / 1024.0,
- stream_bit_rate / 8.0 / 1024.0 / 1024.0);
- dcc_set_max_stream_bit_rate(dcc, stream_bit_rate);
- }
- }
- red_channel_client_pipe_add(RED_CHANNEL_CLIENT(dcc), stream_destroy_item_new(stream_agent));
- stream_agent_stats_print(stream_agent);
+ dcc_stream_stop(dcc, stream_id);
}
display->priv->streams_size_total -= stream->width * stream->height;
ring_remove(&stream->link);
--
2.13.6
More information about the Spice-devel
mailing list