Skip to content
Snippets Groups Projects
Commit b8eb10ca authored by Emmanuel Lepage's avatar Emmanuel Lepage
Browse files
parents 967c2faa 62628a02
No related branches found
No related tags found
No related merge requests found
...@@ -61,12 +61,11 @@ static codec_t *codec_create(gint payload, gchar **specs) ...@@ -61,12 +61,11 @@ static codec_t *codec_create(gint payload, gchar **specs)
codec->payload = payload; codec->payload = payload;
codec->name = g_strdup(specs[0]); codec->name = g_strdup(specs[0]);
codec->bitrate = g_strdup(specs[1]); codec->sample_rate = specs[1] ? atoi(specs[1]) : 0;
codec->sample_rate = specs[2] ? atoi(specs[2]) : 0; codec->bitrate = g_strdup(specs[2]);
codec->is_active = TRUE; codec->is_active = TRUE;
g_free(specs[2]); g_strfreev(specs);
g_free(specs);
return codec; return codec;
} }
...@@ -207,7 +206,7 @@ void codec_set_active(codec_t *c, gboolean active) ...@@ -207,7 +206,7 @@ void codec_set_active(codec_t *c, gboolean active)
codec_t* codec_list_get_by_name(gconstpointer name, GQueue *q) codec_t* codec_list_get_by_name(gconstpointer name, GQueue *q)
{ {
GList * c = g_queue_find_custom(q, name, is_name_codecstruct); GList * c = g_queue_find_custom(q, name, is_name_codecstruct);
return c ? (codec_t *) c->data : NULL; return c ? c->data : NULL;
} }
codec_t* codec_list_get_by_payload(int payload, GQueue *q) codec_t* codec_list_get_by_payload(int payload, GQueue *q)
...@@ -253,69 +252,59 @@ void codec_list_move_codec_down(guint codec_index, GQueue **q) ...@@ -253,69 +252,59 @@ void codec_list_move_codec_down(guint codec_index, GQueue **q)
} }
/* FIXME:tmatth: Clean this up, shouldn't have to do all the reallocs /* Returns a list of strings for just the active codecs in a given queue of codecs */
* explicitly if we use a nicer data structure */ static GSList*
static void codec_list_get_active_codecs(GQueue *codecs, gboolean by_payload)
codec_list_update_to_daemon_audio(const account_t *acc)
{ {
guint c = 0; GSList *active = NULL;
for (guint i = 0; i < codecs->length; i++) {
gchar** codecList = NULL; codec_t* currentCodec = g_queue_peek_nth(codecs, i);
// Get all codecs in queue
for (guint i = 0; i < acc->acodecs->length; i++) {
codec_t* currentCodec = g_queue_peek_nth(acc->acodecs, i);
// Save only if active
if (currentCodec && currentCodec->is_active) { if (currentCodec && currentCodec->is_active) {
codecList = (void *) g_realloc(codecList, (c + 1) * sizeof(void *)); if (by_payload)
*(codecList + c) = g_strdup_printf("%d", currentCodec->payload); active = g_slist_append(active, g_strdup_printf("%d", currentCodec->payload));
c++; else
active = g_slist_append(active, g_strdup(currentCodec->name));
}
}
return active;
} }
/* Given a singly linked list of codecs, returns a list of pointers
* to each element in the list's data. No duplication is done so
* the returned list is only valid for the lifetime of the GSList */
static gchar **
get_items_from_list(GSList *codecs)
{
const guint length = g_slist_length(codecs);
/* we add +1 because the last element must be a NULL pointer for d-bus */
gchar **activeCodecsStr = g_new0(gchar*, length + 1);
for (guint i = 0; i < length; ++i)
activeCodecsStr[i] = g_slist_nth_data(codecs, i);
return activeCodecsStr;
} }
// Allocate NULL array at the end for Dbus static void
codecList = (void *) g_realloc(codecList, (c + 1) * sizeof(void*)); codec_list_update_to_daemon_audio(const account_t *acc)
*(codecList + c) = NULL; {
c++; GSList *activeCodecs = codec_list_get_active_codecs(acc->acodecs, TRUE);
gchar **activeCodecsStr = get_items_from_list(activeCodecs);
// call dbus function with array of strings // call dbus function with array of strings
dbus_set_active_audio_codec_list((const gchar**) codecList, acc->accountID); dbus_set_active_audio_codec_list((const gchar **) activeCodecsStr, acc->accountID);
// Delete memory g_free(activeCodecsStr);
for (guint i = 0; i < c; i++) g_slist_free_full(activeCodecs, g_free);
g_free(*(codecList + i));
g_free(codecList);
} }
#ifdef SFL_VIDEO #ifdef SFL_VIDEO
static void codec_list_update_to_daemon_video(const account_t *acc) static void codec_list_update_to_daemon_video(const account_t *acc)
{ {
gchar** codecList = NULL; GSList *activeCodecs = codec_list_get_active_codecs(acc->vcodecs, FALSE);
// Get all codecs in queue gchar **activeCodecsStr = get_items_from_list(activeCodecs);
guint c = 0;
for (guint i = 0; i < acc->vcodecs->length; i++) {
codec_t* currentCodec = g_queue_peek_nth(acc->vcodecs, i);
// Save only if active
if (currentCodec && currentCodec->is_active) {
codecList = (void *) g_realloc(codecList, (c + 1) * sizeof(void *));
*(codecList + c) = g_strdup(currentCodec->name);
c++;
}
}
// Allocate NULL array at the end for Dbus
codecList = (void*) g_realloc(codecList, (c + 1) * sizeof (void*));
*(codecList + c) = NULL;
c++;
// call dbus function with array of strings // call dbus function with array of strings
dbus_set_active_video_codec_list((const gchar**) codecList, acc->accountID); dbus_set_active_video_codec_list((const gchar **) activeCodecsStr, acc->accountID);
g_free(activeCodecsStr);
// Delete memory g_slist_free_full(activeCodecs, g_free);
for (guint i = 0; i < c; i++)
g_free(*(codecList + i));
g_free(codecList);
} }
#endif #endif
......
...@@ -67,6 +67,9 @@ enum { ...@@ -67,6 +67,9 @@ enum {
CODEC_COLUMN_COUNT CODEC_COLUMN_COUNT
}; };
#define KBPS "kbps"
#define KHZ "kHz"
static void codec_move_up(GtkButton *button UNUSED, gpointer data); static void codec_move_up(GtkButton *button UNUSED, gpointer data);
static void codec_move_down(GtkButton *button UNUSED, gpointer data); static void codec_move_down(GtkButton *button UNUSED, gpointer data);
static void active_is_always_recording(void); static void active_is_always_recording(void);
...@@ -97,8 +100,8 @@ preferences_dialog_fill_codec_list(const account_t *account) ...@@ -97,8 +100,8 @@ preferences_dialog_fill_codec_list(const account_t *account)
DEBUG("%s is %sactive", c->name, c->is_active ? "" : "not "); DEBUG("%s is %sactive", c->name, c->is_active ? "" : "not ");
GtkTreeIter iter; GtkTreeIter iter;
gtk_list_store_append(codecStore, &iter); gtk_list_store_append(codecStore, &iter);
gchar *samplerate = g_strdup_printf("%d kHz", c->sample_rate); gchar *samplerate = g_strdup_printf("%d " KHZ, (gint) (c->sample_rate * 0.001));
gchar *bitrate = g_strdup_printf("%s kbps", c->bitrate); gchar *bitrate = g_strdup_printf("%s " KBPS, c->bitrate);
gtk_list_store_set(codecStore, &iter, gtk_list_store_set(codecStore, &iter,
COLUMN_CODEC_ACTIVE, c->is_active, COLUMN_CODEC_ACTIVE, c->is_active,
...@@ -426,23 +429,28 @@ codec_active_toggled(GtkCellRendererToggle *renderer UNUSED, gchar *path, gpoint ...@@ -426,23 +429,28 @@ codec_active_toggled(GtkCellRendererToggle *renderer UNUSED, gchar *path, gpoint
// Get active value and name at iteration // Get active value and name at iteration
gboolean active; gboolean active;
gchar* name; gchar* name;
gchar* srate; gchar* samplerate;
gtk_tree_model_get(model, &iter, COLUMN_CODEC_ACTIVE, &active, gtk_tree_model_get(model, &iter, COLUMN_CODEC_ACTIVE, &active,
COLUMN_CODEC_NAME, &name, COLUMN_CODEC_FREQUENCY, COLUMN_CODEC_NAME, &name, COLUMN_CODEC_FREQUENCY,
&srate, -1); &samplerate, -1);
DEBUG("Selected Codec: %s, %s", name, srate); DEBUG("Selected Codec: %s, %s", name, samplerate);
codec_t* codec = NULL; codec_t* codec = NULL;
if (utf8_case_equal(name,"speex") && utf8_case_equal(srate, "8 kHz")) const gboolean is_speex = utf8_case_equal(name, "speex");
if (is_speex) {
if (utf8_case_equal(samplerate, "8 " KHZ))
codec = codec_list_get_by_payload(110, acc->acodecs); codec = codec_list_get_by_payload(110, acc->acodecs);
else if (utf8_case_equal(name,"speex") && utf8_case_equal(srate,"16 kHz")) else if (utf8_case_equal(samplerate, "16 " KHZ))
codec = codec_list_get_by_payload(111, acc->acodecs); codec = codec_list_get_by_payload(111, acc->acodecs);
else if (utf8_case_equal(name,"speex") && utf8_case_equal(srate, "32 kHz")) else if (utf8_case_equal(samplerate, "32 " KHZ))
codec = codec_list_get_by_payload(112, acc->acodecs); codec = codec_list_get_by_payload(112, acc->acodecs);
else else
codec = codec_list_get_by_name((gconstpointer) name, acc->acodecs); codec = codec_list_get_by_name((gconstpointer) name, acc->acodecs);
} else {
codec = codec_list_get_by_name((gconstpointer) name, acc->acodecs);
}
// Toggle active value // Toggle active value
active = !active; active = !active;
......
...@@ -185,7 +185,7 @@ static void preferences_dialog_fill_codec_list(account_t *a) ...@@ -185,7 +185,7 @@ static void preferences_dialog_fill_codec_list(account_t *a)
codec_t *c = g_queue_peek_nth(list, i); codec_t *c = g_queue_peek_nth(list, i);
if (c) { if (c) {
g_print("%s", c->name); DEBUG("%s", c->name);
gtk_list_store_append(codecStore, &iter); gtk_list_store_append(codecStore, &iter);
gchar *bitrate = g_strdup_printf("%s kbps", c->bitrate); gchar *bitrate = g_strdup_printf("%s kbps", c->bitrate);
...@@ -226,8 +226,8 @@ codec_active_toggled(GtkCellRendererToggle *renderer UNUSED, gchar *path, ...@@ -226,8 +226,8 @@ codec_active_toggled(GtkCellRendererToggle *renderer UNUSED, gchar *path,
gtk_tree_model_get(model, &iter, COLUMN_CODEC_ACTIVE, &active, gtk_tree_model_get(model, &iter, COLUMN_CODEC_ACTIVE, &active,
COLUMN_CODEC_NAME, &name, -1); COLUMN_CODEC_NAME, &name, -1);
g_print("%s\n", name); DEBUG("%s", name);
g_print("%i\n", g_queue_get_length (acc->vcodecs)); DEBUG("video codecs length %i", g_queue_get_length(acc->vcodecs));
codec_t *codec = codec_list_get_by_name((gconstpointer) name, acc->vcodecs); codec_t *codec = codec_list_get_by_name((gconstpointer) name, acc->vcodecs);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment