46 #include "gstreamer_control.h"
49 static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data)
55 switch (GST_MESSAGE_TYPE(msg))
57 case GST_MESSAGE_ERROR:
62 gst_message_parse_error (msg, &error, &debug);
65 gchar *message = NULL;
66 if (error->message != NULL)
68 gint malloc_size = strlen(error->message) + 20;
69 message = malloc(
sizeof(
char) * malloc_size);
72 memset(message,
'\0',malloc_size);
73 g_snprintf(message, malloc_size,_(
"gstreamer error: %s"),error->message);
83 case GST_MESSAGE_WARNING:
88 gst_message_parse_warning(msg, &error, &debug);
91 gchar *message = NULL;
92 if (error->message != NULL)
94 gint malloc_size = strlen(error->message) + 20;
95 message = malloc(
sizeof(
char) * malloc_size);
98 memset(message,
'\0',malloc_size);
99 g_snprintf(message, malloc_size,_(
"Warning: %s"),error->message);
106 g_error_free (error);
109 case GST_MESSAGE_INFO:
114 gst_message_parse_info(msg, &error, &debug);
117 gchar *message = NULL;
118 if (error->message != NULL)
120 gint malloc_size = strlen(error->message) + 20;
121 message = malloc(
sizeof(
char) * malloc_size);
124 memset(message,
'\0',malloc_size);
125 g_snprintf(message, malloc_size,_(
"Info: %s"),error->message);
132 g_error_free (error);
135 case GST_MESSAGE_TAG:
137 GstTagList *tag_list = NULL;
138 gst_message_parse_tag(msg, &tag_list);
140 gint number_of_stream = 0;
141 g_object_get(ui->pi->play,
"current-audio", &number_of_stream, NULL);
144 const GValue *val = gst_tag_list_get_value_index(tag_list, GST_TAG_ARTIST,
148 ui->pi->song_artist = g_value_get_string(val);
152 val = gst_tag_list_get_value_index(tag_list, GST_TAG_TITLE, number_of_stream);
155 ui->pi->song_title = g_value_get_string(val);
159 val = gst_tag_list_get_value_index(tag_list, GST_TAG_BITRATE, number_of_stream);
162 ui->pi->rate = g_value_get_uint(val);
187 gint number_of_stream = 0;
188 g_object_get(ui->pi->play,
"current-audio", &number_of_stream, NULL);
191 GList *streaminfo = NULL;
192 g_object_get(ui->pi->play,
"stream-info", &streaminfo, NULL);
194 gchar rate_str[32] = {
'\0' };
195 gchar freq_str[32] = {
'\0' };
196 gchar nch_str[32] = {
'\0' };
198 gchar *_Kbps = _(
"Kbps");
199 gchar *_Khz = _(
"Khz");
201 GObject *
object = g_list_nth_data(streaminfo, number_of_stream);
204 GstObject *obj = NULL;
205 g_object_get(G_OBJECT(
object),
"object", &obj, NULL);
208 GstCaps *caps = NULL;
209 g_object_get(obj,
"caps", &caps, NULL);
213 GstStructure *structure = NULL;
214 structure = gst_caps_get_structure(caps, number_of_stream);
217 gst_structure_get_int(structure,
"rate", &freq);
218 gst_structure_get_int(structure,
"channels", &nch);
220 gst_caps_unref(caps);
223 g_snprintf(rate_str, 32,
"%d", ui->pi->rate / 1000);
224 g_snprintf(freq_str, 32,
"%d", freq / 1000);
228 snprintf(nch_str, 32,
"%s", _(
"stereo"));
232 snprintf(nch_str, 32,
"%s", _(
"mono"));
236 if (ui->pi->rate != 0)
238 g_snprintf(total_infos,512,
"%s %s %s %s %s", rate_str,_Kbps,freq_str, _Khz,nch_str);
242 total_infos[0] =
'\0';
258 return strdup(fname);
275 if (pi->song_artist || pi->song_title)
277 gint title_size = 20;
281 title_size += strlen(pi->song_artist);
286 title_size += strlen(pi->song_title);
289 gchar *title = malloc(
sizeof(
char) * title_size);
290 memset(title,
'\0', title_size);
292 if (pi->song_artist && pi->song_title)
294 g_snprintf(title, title_size,
"%s - %s", pi->song_artist, pi->song_title);
296 else if (pi->song_title && !pi->song_artist)
298 g_snprintf(title, title_size,
"%s", pi->song_title);
300 else if (pi->song_artist && !pi->song_title)
302 g_snprintf(title, title_size,
"%s", pi->song_artist);
311 gchar *file = strrchr(fname, G_DIR_SEPARATOR);
314 gchar *alloced_file = strdup(file+1);
338 GstQuery *query = gst_query_new_position(GST_FORMAT_TIME);
341 if (gst_element_query(ui->pi->play, query))
343 gst_query_parse_position(query, NULL, &time);
346 gst_query_unref(query);
348 return (gint) (time / GST_MSECOND);
357 gst_object_unref(ui->pi->play);
360 gst_init(NULL, NULL);
363 gst_default_registry_add_path(
"./");
366 ui->pi->play = gst_element_factory_make(
"playbin",
"play");
373 gtk_widget_show_all(ui->gui->playlist_box);
375 ui->pi->_gstreamer_is_running = TRUE;
376 ui->pi->bus = gst_pipeline_get_bus(GST_PIPELINE(ui->pi->play));
377 gst_bus_add_watch(ui->pi->bus, bus_call, ui);
378 gst_object_unref(ui->pi->bus);
382 GList *song_list = g_list_append(NULL, strdup(fname));
384 g_list_foreach(song_list, (GFunc)g_free, NULL);
385 g_list_free(song_list);
405 if (pi->song_title) { pi->song_title = NULL; }
406 if (pi->song_artist) { pi->song_artist = NULL; }
415 while ((song = g_list_nth_data(list, i)) != NULL)
425 gchar *uri = g_filename_to_uri(song, NULL, NULL);
426 g_object_set(G_OBJECT(ui->pi->play),
"uri", uri, NULL);
427 if (uri) { g_free(uri); }
440 g_object_set(G_OBJECT(ui->pi->play),
"volume", (
double) volume / 100.0 * 2, NULL);
455 g_object_get(G_OBJECT(ui->pi->play),
"volume", &volume, NULL);
456 return (gint) (volume / 2 * 100);
470 return ui->pi->_gstreamer_is_running;
482 gst_element_get_state(ui->pi->play, &state, NULL, GST_CLOCK_TIME_NONE);
484 if (state == GST_STATE_PAUSED)
501 gst_element_get_state(ui->pi->play, &state, NULL, GST_CLOCK_TIME_NONE);
502 if (state == GST_STATE_PLAYING)
507 gst_element_set_state(ui->pi->play, GST_STATE_PLAYING);
518 gst_element_set_state(ui->pi->play, GST_STATE_NULL);
530 gst_element_get_state(ui->pi->play, &state, NULL, GST_CLOCK_TIME_NONE);
532 if (state == GST_STATE_PLAYING)
534 gst_element_set_state(ui->pi->play, GST_STATE_PAUSED);
560 gst_element_seek(ui->pi->play,
561 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
562 GST_SEEK_TYPE_SET, position * GST_MSECOND, 0, 0);
573 GstQuery *query = gst_query_new_duration(GST_FORMAT_TIME);
576 if (gst_element_query(ui->pi->play, query))
579 gst_query_parse_duration(query, NULL, &total_time);
580 time = (gint) (total_time / GST_MSECOND);
583 gst_query_unref(query);
597 gst_element_get_state(ui->pi->play, &state, NULL, GST_CLOCK_TIME_NONE);
598 if ((state == GST_STATE_PLAYING) || (state == GST_STATE_PAUSED))
611 gst_element_set_state(ui->pi->play, GST_STATE_NULL);
614 ui->pi->_gstreamer_is_running = FALSE;
gchar * get_input_filename(gui_state *gui)
Get the name of the input file.
void add_playlist_file(const gchar *name, ui_state *ui)
add a row to the table
void gstreamer_select_last_file(ui_state *ui)
selects the last file in the playlist
gint gstreamer_get_time_elapsed(ui_state *ui)
returns elapsed time
gint gstreamer_get_playlist_number(ui_state *ui)
returns the number of songs of the playlist
void gstreamer_start(ui_state *ui)
starts gstreamer
void gstreamer_play_last_file(ui_state *ui)
plays the last file of the playlist
gint gstreamer_is_playing(ui_state *ui)
returns TRUE if gstreamer is playing, else FALSE
gchar * gstreamer_get_filename(ui_state *ui)
returns the filename
void gstreamer_quit(ui_state *ui)
quits player
void gstreamer_next(ui_state *ui)
changes to next song
gchar * gstreamer_get_title_song(ui_state *ui)
returns the title of the song
gint gstreamer_is_paused(ui_state *ui)
returns TRUE if gstreamer is paused, if not, FALSE
gint gstreamer_get_total_time(ui_state *ui)
returns total time of the current song
void put_status_message(const gchar *text, ui_state *ui)
Output a info message to the status message bar.
void gstreamer_get_song_infos(gchar *total_infos, ui_state *ui)
Gets information about the< song.
void gstreamer_play(ui_state *ui)
plays a song
void gstreamer_start_with_songs(GList *list, ui_state *ui)
starts gstreamer with songs
void gstreamer_stop(ui_state *ui)
stops a song
void gstreamer_jump(gint position, ui_state *ui)
jump to time
gint gstreamer_get_volume(ui_state *ui)
returns volume
void gstreamer_set_volume(gint volume, ui_state *ui)
sets volume
void gstreamer_add_files(GList *list, ui_state *ui)
add files to the gstreamer playlist
void gstreamer_pause(ui_state *ui)
pause a song
void gstreamer_prev(ui_state *ui)
changes to previous song
gint gstreamer_is_running(ui_state *ui)
returns TRUE if gstreamer is running; if not, FALSE