[Spice-devel] [PATCH server 2/3] mjpeg_encoder: add mjpeg_encoder_get_stats

Yonit Halperin yhalperi at redhat.com
Mon Jun 24 12:38:04 PDT 2013


---
 server/mjpeg_encoder.c | 11 +++++++++++
 server/mjpeg_encoder.h |  7 +++++++
 2 files changed, 18 insertions(+)

diff --git a/server/mjpeg_encoder.c b/server/mjpeg_encoder.c
index 4460322..92aef27 100644
--- a/server/mjpeg_encoder.c
+++ b/server/mjpeg_encoder.c
@@ -169,6 +169,7 @@ struct MJpegEncoder {
     void *cbs_opaque;
 
     /* stats */
+    uint64_t starting_bit_rate;
     uint64_t avg_quality;
     uint32_t num_frames;
 };
@@ -195,6 +196,8 @@ MJpegEncoder *mjpeg_encoder_new(int bit_rate_control, uint64_t starting_bit_rate
     enc->first_frame = TRUE;
     enc->rate_control_is_active = bit_rate_control;
     enc->rate_control.byte_rate = starting_bit_rate / 8;
+    enc->starting_bit_rate = starting_bit_rate;
+
     if (bit_rate_control) {
         struct timespec time;
 
@@ -1259,3 +1262,11 @@ uint64_t mjpeg_encoder_get_bit_rate(MJpegEncoder *encoder)
 {
     return encoder->rate_control.byte_rate * 8;
 }
+
+void mjpeg_encoder_get_stats(MJpegEncoder *encoder, MJpegEncoderStats *stats)
+{
+    spice_assert(encoder != NULL && stats != NULL);
+    stats->starting_bit_rate = encoder->starting_bit_rate;
+    stats->cur_bit_rate = mjpeg_encoder_get_bit_rate(encoder);
+    stats->avg_quality = (double)encoder->avg_quality / encoder->num_frames;
+}
diff --git a/server/mjpeg_encoder.h b/server/mjpeg_encoder.h
index 310d289..741ea1c 100644
--- a/server/mjpeg_encoder.h
+++ b/server/mjpeg_encoder.h
@@ -43,6 +43,12 @@ typedef struct MJpegEncoderRateControlCbs {
     void (*update_client_playback_delay)(void *opaque, uint32_t delay_ms);
 } MJpegEncoderRateControlCbs;
 
+typedef struct MJpegEncoderStats {
+    uint64_t starting_bit_rate;
+    uint64_t cur_bit_rate;
+    double avg_quality;
+} MJpegEncoderStats;
+
 MJpegEncoder *mjpeg_encoder_new(int bit_rate_control, uint64_t starting_bit_rate,
                                 MJpegEncoderRateControlCbs *cbs, void *opaque);
 void mjpeg_encoder_destroy(MJpegEncoder *encoder);
@@ -103,5 +109,6 @@ void mjpeg_encoder_client_stream_report(MJpegEncoder *encoder,
 void mjpeg_encoder_notify_server_frame_drop(MJpegEncoder *encoder);
 
 uint64_t mjpeg_encoder_get_bit_rate(MJpegEncoder *encoder);
+void mjpeg_encoder_get_stats(MJpegEncoder *encoder, MJpegEncoderStats *stats);
 
 #endif
-- 
1.8.1.4



More information about the Spice-devel mailing list