[Spice-devel] [PATCH] Make celt to be optional

Liang Guo bluestonechina at gmail.com
Mon Jun 11 23:04:38 PDT 2012


Like patch [1] for spice, This patch will make celt to be
optional for spice-gtk.

[1] http://lists.freedesktop.org/archives/spice-devel/2012-June/009410.html

Signed-off-by: Liang Guo <guoliang at debian.org>
---
 configure.ac           |   24 +++++++++++++++++++-----
 gtk/channel-playback.c |   23 ++++++++++++++++++-----
 gtk/channel-record.c   |   37 ++++++++++++++++++++++++-------------
 3 个文件被修改,插入 61 行(+),删除 23 行(-)

diff --git a/configure.ac b/configure.ac
index 09129b7..e218f2d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,11 +95,24 @@ AC_SUBST(PIXMAN_CFLAGS)
 AC_SUBST(PIXMAN_LIBS)
 SPICE_GLIB_REQUIRES+=" pixman-1 >= 0.17.7"
 
-PKG_CHECK_MODULES(CELT051, celt051 >= 0.5.1.1)
-AC_SUBST(CELT051_CFLAGS)
-AC_SUBST(CELT051_LIBS)
-AC_SUBST(CELT051_LIBDIR)
-SPICE_GLIB_REQUIRES+=" celt051 >= 0.5.1.1"
+AC_ARG_ENABLE([celt],
+  AS_HELP_STRING([--enable-celt=@<:@yes/no@:>@],
+                 [Enable celt support @<:@default=yes@:>@]),
+  [],
+  [enable_celt="yes"])
+
+if test "x$enable_celt" = "xno"; then
+  AM_CONDITIONAL(WITH_CELT051, false)
+else
+  PKG_CHECK_MODULES(CELT051, celt051 >= 0.5.1.1)
+  AC_SUBST(CELT051_CFLAGS)
+  AC_SUBST(CELT051_LIBS)
+  AC_SUBST(CELT051_LIBDIR)
+  SPICE_GLIB_REQUIRES+=" celt051 >= 0.5.1.1"
+  AC_DEFINE(HAVE_CELT051, [1], [Define if celt codec])
+  AM_CONDITIONAL(WITH_CELT051, true)
+fi
+
 
 PKG_CHECK_MODULES(SSL, openssl)
 AC_SUBST(SSL_CFLAGS)
@@ -618,6 +631,7 @@ AC_MSG_NOTICE([
         SASL support:             ${enable_sasl}
         Smartcard support:        ${enable_smartcard}
         USB redirection support:  ${have_usbredir}
+        CELT support:             ${enable_celt}
         Gtk:                      $GTK_API_VERSION
 
         Now type 'make' to build $PACKAGE
diff --git a/gtk/channel-playback.c b/gtk/channel-playback.c
index 61501c8..d4e50cc 100644
--- a/gtk/channel-playback.c
+++ b/gtk/channel-playback.c
@@ -15,7 +15,6 @@
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
-#include <celt051/celt.h>
 
 #include "spice-client.h"
 #include "spice-common.h"
@@ -24,6 +23,10 @@
 
 #include "spice-marshal.h"
 
+#if HAVE_CELT051
+#include <celt051/celt.h>
+#endif
+
 /**
  * SECTION:channel-playback
  * @short_description: audio stream for playback
@@ -48,8 +51,10 @@
 
 struct _SpicePlaybackChannelPrivate {
     int                         mode;
+#if HAVE_CELT051
     CELTMode                    *celt_mode;
     CELTDecoder                 *celt_decoder;
+#endif
     guint32                     frame_count;
     guint32                     last_time;
     guint8                      nchannels;
@@ -85,8 +90,10 @@ static void spice_playback_handle_msg(SpiceChannel *channel, SpiceMsgIn *msg);
 
 static void spice_playback_channel_reset_capabilities(SpiceChannel *channel)
 {
+#ifdef HAVE_CELT051
     if (!g_getenv("SPICE_DISABLE_CELT"))
         spice_channel_set_capability(SPICE_CHANNEL(channel), SPICE_PLAYBACK_CAP_CELT_0_5_1);
+#endif
     spice_channel_set_capability(SPICE_CHANNEL(channel), SPICE_PLAYBACK_CAP_VOLUME);
 }
 
@@ -99,6 +106,7 @@ static void spice_playback_channel_init(SpicePlaybackChannel *channel)
 
 static void spice_playback_channel_finalize(GObject *obj)
 {
+#if HAVE_CELT051
     SpicePlaybackChannelPrivate *c = SPICE_PLAYBACK_CHANNEL(obj)->priv;
 
     if (c->celt_decoder) {
@@ -110,9 +118,9 @@ static void spice_playback_channel_finalize(GObject *obj)
         celt051_mode_destroy(c->celt_mode);
         c->celt_mode = NULL;
     }
-
     g_free(c->volume);
     c->volume = NULL;
+#endif
 
     if (G_OBJECT_CLASS(spice_playback_channel_parent_class)->finalize)
         G_OBJECT_CLASS(spice_playback_channel_parent_class)->finalize(obj);
@@ -163,8 +171,8 @@ static void spice_playback_channel_set_property(GObject      *gobject,
 /* main or coroutine context */
 static void spice_playback_channel_reset(SpiceChannel *channel, gboolean migrating)
 {
+#ifdef HAVE_CELT051
     SpicePlaybackChannelPrivate *c = SPICE_PLAYBACK_CHANNEL(channel)->priv;
-
     if (c->celt_decoder) {
         celt051_decoder_destroy(c->celt_decoder);
         c->celt_decoder = NULL;
@@ -174,7 +182,7 @@ static void spice_playback_channel_reset(SpiceChannel *channel, gboolean migrati
         celt051_mode_destroy(c->celt_mode);
         c->celt_mode = NULL;
     }
-
+#endif
     SPICE_CHANNEL_CLASS(spice_playback_channel_parent_class)->channel_reset(channel, migrating);
 }
 
@@ -359,6 +367,7 @@ static void playback_handle_data(SpiceChannel *channel, SpiceMsgIn *in)
         emit_main_context(channel, SPICE_PLAYBACK_DATA,
                           packet->data, packet->data_size);
         break;
+#ifdef  HAVE_CELT051
     case SPICE_AUDIO_DATA_MODE_CELT_0_5_1: {
         celt_int16_t pcm[256 * 2];
 
@@ -374,6 +383,7 @@ static void playback_handle_data(SpiceChannel *channel, SpiceMsgIn *in)
                           (uint8_t *)pcm, sizeof(pcm));
         break;
     }
+#endif
     default:
         g_warning("%s: unhandled mode", __FUNCTION__);
         break;
@@ -409,8 +419,9 @@ static void playback_handle_start(SpiceChannel *channel, SpiceMsgIn *in)
 {
     SpicePlaybackChannelPrivate *c = SPICE_PLAYBACK_CHANNEL(channel)->priv;
     SpiceMsgPlaybackStart *start = spice_msg_in_parsed(in);
+#ifdef HAVE_CELT051
     int celt_mode_err;
-
+#endif
     SPICE_DEBUG("%s: fmt %d channels %d freq %d time %d", __FUNCTION__,
             start->format, start->channels, start->frequency, start->time);
 
@@ -422,6 +433,7 @@ static void playback_handle_start(SpiceChannel *channel, SpiceMsgIn *in)
         emit_main_context(channel, SPICE_PLAYBACK_START,
                           start->format, start->channels, start->frequency);
         break;
+#ifdef HAVE_CELT051
     case SPICE_AUDIO_DATA_MODE_CELT_0_5_1: {
         /* TODO: only support one setting now */
         int frame_size = 256;
@@ -441,6 +453,7 @@ static void playback_handle_start(SpiceChannel *channel, SpiceMsgIn *in)
                           start->format, start->channels, start->frequency);
         break;
     }
+#endif
     default:
         g_warning("%s: unhandled mode", __FUNCTION__);
         break;
diff --git a/gtk/channel-record.c b/gtk/channel-record.c
index 0ae9e4c..b2cd327 100644
--- a/gtk/channel-record.c
+++ b/gtk/channel-record.c
@@ -15,7 +15,6 @@
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
-#include <celt051/celt.h>
 
 #include "spice-client.h"
 #include "spice-common.h"
@@ -24,6 +23,10 @@
 #include "spice-marshal.h"
 #include "spice-session-priv.h"
 
+#if HAVE_CELT051
+#include <celt051/celt.h>
+#endif
+
 /**
  * SECTION:channel-record
  * @short_description: audio stream for recording
@@ -51,8 +54,10 @@
 struct _SpiceRecordChannelPrivate {
     int                         mode;
     gboolean                    started;
+#ifdef HAVE_CELT051
     CELTMode                    *celt_mode;
     CELTEncoder                 *celt_encoder;
+#endif
     gsize                       frame_bytes;
     guint8                      *last_frame;
     gsize                       last_frame_current;
@@ -91,8 +96,10 @@ static void channel_up(SpiceChannel *channel);
 
 static void spice_record_channel_reset_capabilities(SpiceChannel *channel)
 {
+#ifdef HAVE_CELT051
     if (!g_getenv("SPICE_DISABLE_CELT"))
         spice_channel_set_capability(SPICE_CHANNEL(channel), SPICE_RECORD_CAP_CELT_0_5_1);
+#endif
     spice_channel_set_capability(SPICE_CHANNEL(channel), SPICE_RECORD_CAP_VOLUME);
 }
 
@@ -109,7 +116,7 @@ static void spice_record_channel_finalize(GObject *obj)
 
     g_free(c->last_frame);
     c->last_frame = NULL;
-
+#ifdef HAVE_CELT051
     if (c->celt_encoder) {
         celt051_encoder_destroy(c->celt_encoder);
         c->celt_encoder = NULL;
@@ -119,7 +126,7 @@ static void spice_record_channel_finalize(GObject *obj)
         celt051_mode_destroy(c->celt_mode);
         c->celt_mode = NULL;
     }
-
+#endif
     g_free(c->volume);
     c->volume = NULL;
 
@@ -175,7 +182,7 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
 
     g_free(c->last_frame);
     c->last_frame = NULL;
-
+#ifdef HAVE_CELT051
     if (c->celt_encoder) {
         celt051_encoder_destroy(c->celt_encoder);
         c->celt_encoder = NULL;
@@ -185,7 +192,7 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
         celt051_mode_destroy(c->celt_mode);
         c->celt_mode = NULL;
     }
-
+#endif
     SPICE_CHANNEL_CLASS(spice_record_channel_parent_class)->channel_reset(channel, migrating);
 }
 
@@ -324,12 +331,13 @@ static void channel_up(SpiceChannel *channel)
     SpiceRecordChannelPrivate *rc;
 
     rc = SPICE_RECORD_CHANNEL(channel)->priv;
+    rc->mode = SPICE_AUDIO_DATA_MODE_RAW;
+#ifdef HAVE_CELT051
     if (!g_getenv("SPICE_DISABLE_CELT") &&
         spice_channel_test_capability(channel, SPICE_RECORD_CAP_CELT_0_5_1)) {
         rc->mode = SPICE_AUDIO_DATA_MODE_CELT_0_5_1;
-    } else {
-        rc->mode = SPICE_AUDIO_DATA_MODE_RAW;
-    }
+    } 
+#endif
 }
 
 /* main context */
@@ -363,9 +371,10 @@ void spice_record_send_data(SpiceRecordChannel *channel, gpointer data,
 {
     SpiceRecordChannelPrivate *rc;
     SpiceMsgcRecordPacket p = {0, };
+#ifdef HAVE_CELT051
     int celt_compressed_frame_bytes = FRAME_SIZE * CELT_BIT_RATE / 44100 / 8;
     uint8_t *celt_buf = NULL;
-
+#endif
     g_return_if_fail(channel != NULL);
     g_return_if_fail(spice_channel_get_read_only(SPICE_CHANNEL(channel)) == FALSE);
 
@@ -376,10 +385,10 @@ void spice_record_send_data(SpiceRecordChannel *channel, gpointer data,
         spice_record_start_mark(channel, time);
         rc->started = TRUE;
     }
-
+#ifdef HAVE_CELT051
     if (rc->mode == SPICE_AUDIO_DATA_MODE_CELT_0_5_1)
         celt_buf = g_alloca(celt_compressed_frame_bytes);
-
+#endif
     p.time = time;
 
     while (bytes > 0) {
@@ -411,7 +420,7 @@ void spice_record_send_data(SpiceRecordChannel *channel, gpointer data,
             rc->last_frame_current = n;
             break;
         }
-
+#ifdef HAVE_CELT051
         if (rc->mode == SPICE_AUDIO_DATA_MODE_CELT_0_5_1) {
             frame_size = celt051_encode(rc->celt_encoder, (celt_int16_t *)frame, NULL, celt_buf,
                                celt_compressed_frame_bytes);
@@ -421,7 +430,7 @@ void spice_record_send_data(SpiceRecordChannel *channel, gpointer data,
             }
             frame = celt_buf;
         }
-
+#endif
         msg = spice_msg_out_new(SPICE_CHANNEL(channel), SPICE_MSGC_RECORD_DATA);
         msg->marshallers->msgc_record_data(msg->marshaller, &p);
         spice_marshaller_add(msg->marshaller, frame, frame_size);
@@ -457,6 +466,7 @@ static void record_handle_start(SpiceChannel *channel, SpiceMsgIn *in)
         emit_main_context(channel, SPICE_RECORD_START,
                           start->format, start->channels, start->frequency);
         break;
+#ifdef HAVE_CELT051
     case SPICE_AUDIO_DATA_MODE_CELT_0_5_1: {
         int celt_mode_err;
 
@@ -478,6 +488,7 @@ static void record_handle_start(SpiceChannel *channel, SpiceMsgIn *in)
                           start->format, start->channels, start->frequency);
         break;
     }
+#endif
     default:
         g_warning("%s: unhandled mode %d", __FUNCTION__, c->mode);
         break;
-- 
1.7.10



More information about the Spice-devel mailing list