46#include "gstreamer_control.h"
49static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data)
53 switch (GST_MESSAGE_TYPE(msg))
55 case GST_MESSAGE_ERROR:
60 gst_message_parse_error (msg, &error, &debug);
63 gchar *message = NULL;
64 if (error->message != NULL)
66 gint malloc_size = strlen(error->message) + 20;
67 message = malloc(
sizeof(
char) * malloc_size);
70 memset(message,
'\0',malloc_size);
71 g_snprintf(message, malloc_size,_(
"gstreamer error: %s"),error->message);
73 put_status_message_in_idle(message, ui);
81 case GST_MESSAGE_WARNING:
86 gst_message_parse_warning(msg, &error, &debug);
89 gchar *message = NULL;
90 if (error->message != NULL)
92 gint malloc_size = strlen(error->message) + 20;
93 message = malloc(
sizeof(
char) * malloc_size);
96 memset(message,
'\0',malloc_size);
97 g_snprintf(message, malloc_size,_(
"Warning: %s"),error->message);
99 put_status_message_in_idle(message, ui);
104 g_error_free (error);
107 case GST_MESSAGE_INFO:
112 gst_message_parse_info(msg, &error, &debug);
115 gchar *message = NULL;
116 if (error->message != NULL)
118 gint malloc_size = strlen(error->message) + 20;
119 message = malloc(
sizeof(
char) * malloc_size);
122 memset(message,
'\0',malloc_size);
123 g_snprintf(message, malloc_size,_(
"Info: %s"),error->message);
125 put_status_message_in_idle(message, ui);
130 g_error_free (error);
133 case GST_MESSAGE_TAG:
135 GstTagList *tag_list = NULL;
136 gst_message_parse_tag(msg, &tag_list);
138 gint number_of_stream = 0;
139 g_object_get(ui->pi->play,
"current-audio", &number_of_stream, NULL);
142 const GValue *val = gst_tag_list_get_value_index(tag_list, GST_TAG_ARTIST,
146 ui->pi->song_artist = g_value_get_string(val);
150 val = gst_tag_list_get_value_index(tag_list, GST_TAG_TITLE, number_of_stream);
153 ui->pi->song_title = g_value_get_string(val);
157 val = gst_tag_list_get_value_index(tag_list, GST_TAG_BITRATE, number_of_stream);
160 ui->pi->rate = g_value_get_uint(val);
183 gint current_audio_stream = 0;
184 g_object_get(ui->pi->play,
"current-audio", ¤t_audio_stream, NULL);
186 gchar rate_str[32] = {
'\0' };
187 gchar freq_str[32] = {
'\0' };
188 gchar nch_str[32] = {
'\0' };
190 gchar *_Kbps = _(
"Kbps");
191 gchar *_Khz = _(
"Khz");
193 GstCaps *caps = NULL;
196 g_signal_emit_by_name(ui->pi->play,
"get-audio-pad", current_audio_stream, &pad);
199 caps = gst_pad_get_current_caps(pad);
204 GstStructure *structure = NULL;
205 structure = gst_caps_get_structure(caps, 0);
207 gst_structure_get_int(structure,
"rate", &freq);
208 gst_structure_get_int(structure,
"channels", &nch);
210 gst_caps_unref(caps);
212 g_snprintf(rate_str, 32,
"%d", ui->pi->rate / 1000);
213 g_snprintf(freq_str, 32,
"%d", freq / 1000);
217 snprintf(nch_str, 32,
"%s", _(
"stereo"));
221 snprintf(nch_str, 32,
"%s", _(
"mono"));
225 if (ui->pi->rate != 0)
227 g_snprintf(total_infos,512,
"%s %s %s %s %s", rate_str,_Kbps,freq_str, _Khz,nch_str);
231 total_infos[0] =
'\0';
247 return strdup(fname);
264 if (pi->song_artist || pi->song_title)
266 gint title_size = 20;
270 title_size += strlen(pi->song_artist);
275 title_size += strlen(pi->song_title);
278 gchar *title = malloc(
sizeof(
char) * title_size);
279 memset(title,
'\0', title_size);
281 if (pi->song_artist && pi->song_title)
283 g_snprintf(title, title_size,
"%s - %s", pi->song_artist, pi->song_title);
285 else if (pi->song_title && !pi->song_artist)
287 g_snprintf(title, title_size,
"%s", pi->song_title);
289 else if (pi->song_artist && !pi->song_title)
291 g_snprintf(title, title_size,
"%s", pi->song_artist);
300 gchar *file = strrchr(fname, G_DIR_SEPARATOR);
303 gchar *alloced_file = strdup(file+1);
327 GstQuery *query = gst_query_new_position(GST_FORMAT_TIME);
330 if (gst_element_query(ui->pi->play, query))
332 gst_query_parse_position(query, NULL, &time);
335 gst_query_unref(query);
337 return (gint) (time / GST_MSECOND);
346 gst_object_unref(ui->pi->play);
349 gst_init(NULL, NULL);
351 ui->pi->play = gst_element_factory_make(
"playbin",
"playbin");
358 gtk_widget_show_all(ui->gui->playlist_box);
360 ui->pi->_gstreamer_is_running = TRUE;
361 ui->pi->bus = gst_pipeline_get_bus(GST_PIPELINE(ui->pi->play));
362 gst_bus_add_watch(ui->pi->bus, bus_call, ui);
363 gst_object_unref(ui->pi->bus);
367 GList *song_list = g_list_append(NULL, strdup(fname));
369 g_list_foreach(song_list, (GFunc)g_free, NULL);
370 g_list_free(song_list);
390 if (pi->song_title) { pi->song_title = NULL; }
391 if (pi->song_artist) { pi->song_artist = NULL; }
399 gst_element_get_state(ui->pi->play, &state, NULL, GST_CLOCK_TIME_NONE);
400 gst_element_set_state(ui->pi->play, GST_STATE_NULL);
404 while ((song = g_list_nth_data(list, i)) != NULL)
414 gchar *uri = g_filename_to_uri(song, NULL, NULL);
415 g_object_set(G_OBJECT(ui->pi->play),
"uri", uri, NULL);
416 if (uri) { g_free(uri); }
421 if (state == GST_STATE_PLAYING)
423 gst_element_set_state(ui->pi->play, GST_STATE_PLAYING);
425 else if (state == GST_STATE_PAUSED)
427 gst_element_set_state(ui->pi->play, GST_STATE_PAUSED);
438 g_object_set(G_OBJECT(ui->pi->play),
"volume", (
double) volume / 100.0 * 2, NULL);
453 g_object_get(G_OBJECT(ui->pi->play),
"volume", &volume, NULL);
454 return (gint) (volume / 2 * 100);
468 return ui->pi->_gstreamer_is_running;
480 gst_element_get_state(ui->pi->play, &state, NULL, GST_CLOCK_TIME_NONE);
482 if (state == GST_STATE_PAUSED)
499 gst_element_get_state(ui->pi->play, &state, NULL, GST_CLOCK_TIME_NONE);
500 if (state == GST_STATE_PLAYING)
505 gst_element_set_state(ui->pi->play, GST_STATE_PLAYING);
516 gst_element_set_state(ui->pi->play, GST_STATE_NULL);
528 gst_element_get_state(ui->pi->play, &state, NULL, GST_CLOCK_TIME_NONE);
530 if (state == GST_STATE_PLAYING)
534 gst_element_set_state(ui->pi->play, GST_STATE_PAUSED);
563 gst_element_seek(ui->pi->play,
564 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
565 GST_SEEK_TYPE_SET, position * GST_MSECOND, 0, 0);
576 GstQuery *query = gst_query_new_duration(GST_FORMAT_TIME);
579 if (gst_element_query(ui->pi->play, query))
582 gst_query_parse_duration(query, NULL, &total_time);
583 time = (gint) (total_time / GST_MSECOND);
586 gst_query_unref(query);
600 gst_element_get_state(ui->pi->play, &state, NULL, GST_CLOCK_TIME_NONE);
601 if ((state == GST_STATE_PLAYING) || (state == GST_STATE_PAUSED))
614 gst_element_set_state(ui->pi->play, GST_STATE_NULL);
617 ui->pi->_gstreamer_is_running = FALSE;
void gstreamer_select_last_file(ui_state *ui)
selects the last file in the playlist
void gstreamer_prev(ui_state *ui)
changes to previous song
void gstreamer_add_files(GList *list, ui_state *ui)
add files to the gstreamer playlist
gint gstreamer_get_time_elapsed(ui_state *ui)
returns elapsed time
void gstreamer_stop(ui_state *ui)
stops a song
void gstreamer_get_song_infos(gchar *total_infos, ui_state *ui)
Gets information about the song.
gint gstreamer_get_total_time(ui_state *ui)
returns total time of the current song
gint gstreamer_is_paused(ui_state *ui)
returns TRUE if gstreamer is paused, if not, FALSE
void gstreamer_jump(gint position, ui_state *ui)
jump to time
void gstreamer_quit(ui_state *ui)
quits player
void gstreamer_pause(ui_state *ui)
pause a song
void gstreamer_play(ui_state *ui)
plays a song
gint gstreamer_is_playing(ui_state *ui)
returns TRUE if gstreamer is playing, else FALSE
void gstreamer_next(ui_state *ui)
changes to next song
void gstreamer_play_last_file(ui_state *ui)
plays the last file of the playlist
gint gstreamer_is_running(ui_state *ui)
returns TRUE if gstreamer is running; if not, FALSE
void gstreamer_start(ui_state *ui)
starts gstreamer
void gstreamer_start_with_songs(GList *list, ui_state *ui)
starts gstreamer with songs
gchar * gstreamer_get_filename(ui_state *ui)
returns the filename
gint gstreamer_get_volume(ui_state *ui)
returns volume
gchar * gstreamer_get_title_song(ui_state *ui)
returns the title of the song
void gstreamer_set_volume(gint volume, ui_state *ui)
sets volume
gint gstreamer_get_playlist_number(ui_state *ui)
returns the number of songs of the playlist
gchar * get_input_filename(gui_state *gui)
Get the name of the input file.
void put_status_message(const gchar *text, ui_state *ui)
Output a info message to the status message bar.
void add_playlist_file(const gchar *name, ui_state *ui)
add a row to the table