Spice-server源码简要分析

本文简要分析了Spice-Server的源码,重点在于流媒体处理,特别是mjpeg-encoder.c和gstreamer-encoder.c中的实现。Spice-Server在qemu中作为库被调用,qemu_spice_init()和qemu_spice_display_init()负责初始化和图形显示。流媒体处理涉及帧率控制、图像质量调整,根据网络状况自适应调整流媒体质量。mjpeg_encoder_start_frame()和mjpeg_encoder_new()是关键函数,前者处理压缩帧,后者定义质量控制。Spice-Server利用libjpeg(或libjpeg-turbo)进行JPEG编码,gstreamer-encoder.c则涉及gstreamer编码器的调用。视频流判断条件为20帧内4帧以上满足条件。

下载地址:https://www.spice-space.org/download/releases/spice-server/spice-0.14.1.tar.bz2
也可以在gitlab下载。https://gitlab.com/spice


spcie-server主要是以一个lib的形势被qemu调用。研究spice的代码,可以先从qemu入手。
阅读qemu的main函数代码,发现关于libspice的调用有两个地方:

qemu_spice_init();  
qemu_spice_display_init();

简单看一下这两个函数的实现:

#include "ui/qemu-spice.h"
ui\spice-core.c

实际上呢是qemu把libspice里面的代码做了封装。

void qemu_spice_init(void)
{
    QemuOpts *opts = QTAILQ_FIRST(&qemu_spice_opts.head);
    const char *password, *str, *x509_dir, *addr,
        *x509_key_password = NULL,
        *x509_dh_file = NULL,
        *tls_ciphers = NULL;
    char *x509_key_file = NULL,
        *x509_cert_file = NULL,
        *x509_cacert_file = NULL;
    int port, tls_port, addr_flags;
    spice_image_compression_t compression;
    spice_wan_compression_t wan_compr;
    bool seamless_migration;

    qemu_thread_get_self(&me);

    if (!opts) {
        return;
    }
    port = qemu_opt_get_number(opts, "port", 0);
    tls_port = qemu_opt_get_number(opts, "tls-port", 0);
    if (port < 0 || port > 65535) {
        error_report("spice port is out of range");
        exit(1);
    }
    if (tls_port < 0 || tls_port > 65535) {
        error_report("spice tls-port is out of range");
        exit(1);
    }
    password = qemu_opt_get(opts, "password");

    if (tls_port) {
        x509_dir = qemu_opt_get(opts, "x509-dir");
        if (!x509_dir) {
            x509_dir = ".";
        }

        str = qemu_opt_get(opts, "x509-key-file");
        if (str) {
            x509_key_file = g_strdup(str);
        } else {
            x509_key_file = g_strdup_printf("%s/%s", x509_dir,
                                            X509_SERVER_KEY_FILE);
        }

        str = qemu_opt_get(opts, "x509-cert-file");
        if (str) {
            x509_cert_file = g_strdup(str);
        } else {
            x509_cert_file = g_strdup_printf("%s/%s", x509_dir,
                                             X509_SERVER_CERT_FILE);
        }

        str = qemu_opt_get(opts, "x509-cacert-file");
        if (str) {
            x509_cacert_file = g_strdup(str);
        } else {
            x509_cacert_file = g_strdup_printf("%s/%s", x509_dir,
                                               X509_CA_CERT_FILE);
        }

   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值