1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/*
* Copyright (c) Linux community.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "media-profiles.h"
#include "log.h"
// Get media-profiles from the GNOME's media library (from the libgnome-media-dev package).
// You can find these values in the the GConf registry.
// Start gconf-editor and browse to: system -> gstreamer -> 0.10 -> audio -> profiles.
// Keep a list of supported media profiles (audio formats)
static GList *media_profiles_list = NULL;
void media_profiles_init() {
LOG_DEBUG("Init media-profiles.c.\n");
// Init GNOME's media profiles module
gnome_media_profiles_init(NULL);
}
void media_profiles_exit() {
LOG_DEBUG("Clean up media-profiles.c.\n");
// Clean up. Free the list, do not touch data items.
if (media_profiles_list)
g_list_free(media_profiles_list);
media_profiles_list = NULL;
}
void media_profiles_load() {
// Load _active_ media profiles (audio formats)
if (media_profiles_list) return;
// Ref: http://www.susaaland.dk/sharedoc/gnome-media-2.10.2/ChangeLog
media_profiles_list = gm_audio_profile_get_active_list();
}
GMAudioProfile *media_profiles_get_profile(gchar *id) {
// Return media profile for the given id.
// See: gconf-editor, key: system -> gstreamer -> 0.10 -> audio -> profiles.
GMAudioProfile *profile = gm_audio_profile_lookup(id);
// Do not free this value.
return profile;
}
gchar *media_profiles_get_extension(gchar *id) {
// Return file extension (such as .mp3, .ogg, .m4a) for the given profile id.
// See: gconf-editor, key: system -> gstreamer -> 0.10 -> audio -> profiles (value for extension).
const gchar *extension = NULL;
GMAudioProfile *profile = gm_audio_profile_lookup(id);
if (profile)
extension = gm_audio_profile_get_extension(profile);
// The caller should g_free() this value
return g_strdup(extension);
}
gchar *media_profiles_get_pipeline(gchar *id) {
// Return partial GStreamer pipeline for the given id.
// See: gconf-editor, key: system -> gstreamer -> 0.10 -> audio -> profiles (value for pipeline).
const gchar *pipeline = NULL;
GMAudioProfile *profile = gm_audio_profile_lookup(id);
if (profile)
pipeline = gm_audio_profile_get_pipeline(profile);
// The caller should g_free() this value
return g_strdup(pipeline);
}
void media_profiles_add_data(GtkListStore *store) {
// Fill the list store with _active_ media profiles (audio format ids and names).
media_profiles_load();
GtkTreeIter iter;
GList *item = g_list_first(media_profiles_list);
while (item) {
GMAudioProfile *profile = (GMAudioProfile*)item->data;
const gchar *id = gm_audio_profile_get_id(profile);
const gchar *name = gm_audio_profile_get_name(profile);
const gchar *extension = gm_audio_profile_get_extension(profile);
// Typical audio format list is
// CD Quality, AAC (.m4a)
// CD Quality, Lossless (.flac)
// CD Quality, Lossy (.ogg)
// CD Quality, MP2 (.mp2)
// CD Quality, MP3 (.mp3)
// Voice, Lossless (.wav)
// Voice, Lossy (.spx)
gchar *e = g_utf8_strup(extension, -1);
gchar *n = g_utf8_strdown(name, -1);
gchar *txt = g_strdup_printf(".%s (%s)", e, n);
// Add OGG type "CD Quality, Lossy" as first (becomes default)
if (!g_strcmp0(extension, "ogg") || !g_strcmp0(extension, "oga")) {
gtk_list_store_prepend(GTK_LIST_STORE(store), &iter);
} else {
// Add last
gtk_list_store_append(GTK_LIST_STORE(store), &iter);
}
gtk_list_store_set(GTK_LIST_STORE(store), &iter, 0, id, 1, txt, -1);
g_free(txt);
g_free(e);
g_free(n);
item = g_list_next(item);
}
}
gchar *media_profiles_get_selected_id(GtkWidget *widget) {
// Return selected GMAudioProfile id (audio format id)
GtkComboBox *combo = GTK_COMBO_BOX(widget);
g_return_val_if_fail (GTK_IS_COMBO_BOX(combo), NULL);
GtkTreeIter iter;
gchar *id = NULL;
if (!gtk_combo_box_get_active_iter(combo, &iter)) return NULL;
gtk_tree_model_get(gtk_combo_box_get_model(combo), &iter, COL_PROFILE_ID, &id, -1);
// The caller should g_free() this value
return id;
}
GtkWidget *media_profiles_create_combobox() {
// Create a GtkComboBox with N_PROFILE_COLUMNS. Populate it with supported audio formats.
// Create list store
GtkListStore *store = gtk_list_store_new(N_PROFILE_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
// Get audio formats (media profiles) and add to the store
media_profiles_add_data(store);
GtkWidget *combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
// Unref store
g_object_unref(store);
// "Id" column, invisible
GtkCellRenderer *cell = gtk_cell_renderer_text_new();
g_object_set(cell, "visible", 0, NULL);
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell, "text", COL_PROFILE_ID, NULL);
// "Name" column, visible
cell = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell, "text", COL_PROFILE_TXT, NULL);
return combo;
}
|