[girl] GNOME Internet Radio Locator version 10.0.0
- From: ole <ole src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [girl] GNOME Internet Radio Locator version 10.0.0
- Date: Thu, 4 May 2017 15:11:14 +0000 (UTC)
commit 5367f5f6733865340fb00d194f646e403dc37cf7
Author: Ole Aamot <oka oka no>
Date: Thu May 4 17:10:41 2017 +0200
GNOME Internet Radio Locator version 10.0.0
NEWS | 13 +
README | 7 +
configure.ac | 7 +-
src/Makefile.am | 6 +-
src/girl-gui.c | 5 +-
src/girl-player.c | 821 ++++++++++++++++++++++++++++++++++++++++++++++++----
src/girl-player.h | 37 ++-
src/girl-record.c | 4 -
src/girl-station.c | 6 +-
src/girl.c | 40 +--
src/girl.xml | 24 +-
11 files changed, 851 insertions(+), 119 deletions(-)
---
diff --git a/NEWS b/NEWS
index 4887128..246ecdf 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,16 @@
+==============
+Version 10.0.0
+==============
+
+ * configure.ac: Bump version and add gstreamer pkgconfig dependencies
+ * src/Makefile.am: Add girl-player.[ch]
+ * src/girl-gui.c: Add girl-player functions
+ * src/girl-player.c: Add gst-player functions
+ * src/girl-player.h: Add gst-player functions
+ * src/girl-station.c: Add girl_player_main function call
+ * src/girl.c: Add GstPlayer *player global
+ * src/girl.xml: Add Burst Radio (burstradio.org.uk) and bump version
+
=============
Version 9.9.9
=============
diff --git a/README b/README
index 7bea228..eb8989d 100644
--- a/README
+++ b/README
@@ -1,4 +1,11 @@
================
+GIRL 10.0.0 note
+================
+
+Background playback of 86 radio stations now finally works
+in GNOME Internet Radio Locator. Major release completed.
+
+================
GIRL 9.9.9 notes
================
diff --git a/configure.ac b/configure.ac
index 98545cf..e120b63 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT(girl,9.9.9)
+AC_INIT(girl,10.0.0)
AM_INIT_AUTOMAKE([-Wno-portability 1.11 no-dist-gzip dist-xz tar-ustar subdir-objects])
AM_MAINTAINER_MODE
AC_CONFIG_SRCDIR([src/girl.c])
@@ -71,9 +71,12 @@ PKG_CHECK_MODULES(GIRL,
libgnomeui-2.0 >= 2.0 \
libxml-2.0 >= 2.0 \
gnome-vfs-2.0 >= 2.0 \
+ gstreamer-1.0 >= 1.0 \
+ gstreamer-player-1.0 >= 1.0 \
+ gstreamer-tag-1.0 >= 1.0 \
gstreamer-video-1.0)
-GIRL_PKG_DEPS="gtk+-2.0, glib-2.0, gobject-2.0, libgnome-2.0, libgnomeui-2.0, libxml-2.0, gnome-vfs-2.0,
gstreamer-1.0 gstreamer-video-1.0"
+GIRL_PKG_DEPS="gtk+-2.0, glib-2.0, gobject-2.0, libgnome-2.0, libgnomeui-2.0, libxml-2.0, gnome-vfs-2.0,
gstreamer-1.0 gstreamer-player-1.0 gstreamer-tag-1.0 gstreamer-video-1.0"
GTK_DOC_CHECK([1.16], [--flavour no-tmpl])
diff --git a/src/Makefile.am b/src/Makefile.am
index 2c513da..1b1de04 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,8 +5,6 @@ girl_SOURCES = \
girl-listener.c \
girl-program.c \
girl-player.c \
- girl-player-backend.c \
- girl-player-frontend.c \
girl-record.c \
girl-record-backend.c \
girl-record-frontend.c \
@@ -28,9 +26,9 @@ girl_LDADD = $(GIRL_LIBS)
girldir = $(datadir)/girl
-girl_DATA = girl-9.9.dtd girl-logo.png girl.png girl.xml girl.xsl
+girl_DATA = girl-10.dtd girl-logo.png girl.png girl.xml girl.xsl
-EXTRA_DIST = girl.h girl-station.h girl-stations-map.h girl-tz.h girl-gui.h girl-listener.h girl-player.h
girl-player-globals.h girl-player-frontend.h girl-player-backend.h girl-record.h girl-record-backend.h
girl-record-globals.h girl-record-frontend.h girl-program.h girl-runners.h girl-streams.h girl-9.9.dtd
girl-map.png girl-logo.png girl.png girl.xml girl.xsl
+EXTRA_DIST = girl.h girl-station.h girl-stations-map.h girl-tz.h girl-gui.h girl-listener.h girl-player.h
girl-player-kb.h girl-player-resource.h girl-record.h girl-record-backend.h girl-record-globals.h
girl-record-frontend.h girl-program.h girl-runners.h girl-streams.h girl-10.dtd girl-map.png girl-logo.png
girl.png girl.xml girl.xsl
LDADD = $(GIRL_LIBS)
AM_CFLAGS = $(GIRL_CFLAGS) -g
diff --git a/src/girl-gui.c b/src/girl-gui.c
index 280b5f7..21eb020 100644
--- a/src/girl-gui.c
+++ b/src/girl-gui.c
@@ -44,7 +44,7 @@
#include <gtk/gtkcombobox.h>
#include <glib/gstdio.h>
#include "girl.h"
-#include "girl-player-frontend.h"
+#include "girl-player.h"
#include "girl-gui.h"
#include "girl-program.h"
#include "girl-station.h"
@@ -53,6 +53,7 @@
extern GtkWidget *girl_app;
extern GtkWidget *search_selector;
+extern GstPlayer *player;
GnomeUIInfo toolbar[] = {
GNOMEUIINFO_ITEM_STOCK(N_("New"), N_("Add a new radio station"),
@@ -516,7 +517,7 @@ on_search_matches(GtkEntryCompletion *widget,
girl->selected_station_location,
girl->selected_station_uri);
- girl_player_frontend_stop (girl->player_window, NULL);
+ girl_player_stop (player);
if (GTK_IS_WIDGET(search_selector)) {
gtk_widget_destroy(search_selector);
diff --git a/src/girl-player.c b/src/girl-player.c
index 151e761..c33d733 100644
--- a/src/girl-player.c
+++ b/src/girl-player.c
@@ -1,84 +1,779 @@
-/* $Id$
+/* GStreamer command line playback testing utility
*
- * GNOME Internet Radio Locator
+ * Copyright (C) 2013-2014 Tim-Philipp Müller <tim centricular net>
+ * Copyright (C) 2013 Collabora Ltd.
+ * Copyright (C) 2014 Sebastian Dröge <sebastian centricular com>
+ * Copyright (C) 2015 Brijesh Singh <brijesh ksingh gmail com>
*
- * Copyright (C) 2016, 2017 Ole Aamot Software
+ * 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.
*
- * Author: Ole Aamot <oka oka no>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
+ * 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 General Public License for more details.
+ * 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 General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 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., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
-/* Based on gstplayer from
- * https://github.com/sreerenjb/gstplayer/blob/master/gstplayer.c
- *
- * Copyright (C) 2010 Sreerenj Balachandran.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
+#include <locale.h>
-#include <config.h>
+#include <gst/gst.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <gst/player/player.h>
#include "girl.h"
+#include "girl-player.h"
+#include "girl-player-kb.h"
+
+#define VOLUME_STEPS 20
+
+GST_DEBUG_CATEGORY (play_debug);
+#define GST_CAT_DEFAULT play_debug
-#include "girl-player-frontend.h"
-#include "girl-player-backend.h"
-#include "girl-player-globals.h"
+extern GstPlayer *player;
-extern GirlData *girl;
+static gboolean play_next (GstPlay * play);
+static gboolean play_prev (GstPlay * play);
+static void play_set_relative_volume (GstPlay * play, gdouble volume_step);
void
girl_player_main(gchar *streamuri, gchar *name)
{
gchar *uri = g_strdup(streamuri);
-
- /* if (argc > 1) { */
- /* if (g_strrstr (argv[1],"rtsp://") || g_strrstr (argv[1],"http://") || g_strrstr
(argv[1],"file://")) */
- /* uri = g_strdup (argv[1]); */
- /* else */
- /* uri = g_strdup_printf ("file://%s", argv[1]); */
- /* } */
- /* else { */
- /* g_message ("Specify the media file name..<girl-playerplayer filename>"); */
- /* return 0; */
- /* } */
-
- if (!girl_player_frontend_start (name)) {
- g_message ("Player UI creation failure....");
- exit (0);
- }
- if (!girl_player_backend_start (uri, name)) {
- g_message ("Girl-Player backend creation failure");
- exit (0);
- }
- girl->player_loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (girl->player_loop);
- girl_player_backend_stop (girl->player_loop);
+ player = gst_player_new (NULL, gst_player_g_main_context_signal_dispatcher_new(NULL));
+ girl_player_new(player, streamuri);
+ gst_player_play(player);
girl->player_status = GIRL_PLAYER_TRUE;
exit (0);
}
+
+static void
+end_of_stream_cb (GstPlayer * player, GstPlay * play)
+{
+ g_print ("\n");
+ /* and switch to next item in list */
+ if (!play_next (play)) {
+ g_print ("Reached end of play list.\n");
+ g_main_loop_quit (play->loop);
+ }
+}
+
+static void
+error_cb (GstPlayer * player, GError * err, GstPlay * play)
+{
+ g_printerr ("ERROR %s for %s\n", err->message, play->uris[play->cur_idx]);
+
+ /* if looping is enabled, then disable it else will keep looping forever */
+ play->repeat = FALSE;
+
+ /* try next item in list then */
+ if (!play_next (play)) {
+ g_print ("Reached end of play list.\n");
+ g_main_loop_quit (play->loop);
+ }
+}
+
+static void
+position_updated_cb (GstPlayer * player, GstClockTime pos, GstPlay * play)
+{
+ GstClockTime dur = -1;
+ gchar status[64] = { 0, };
+
+ g_object_get (play->player, "duration", &dur, NULL);
+
+ memset (status, ' ', sizeof (status) - 1);
+
+ if (pos != -1 && dur > 0 && dur != -1) {
+ gchar dstr[32], pstr[32];
+
+ /* FIXME: pretty print in nicer format */
+ g_snprintf (pstr, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (pos));
+ pstr[9] = '\0';
+ g_snprintf (dstr, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (dur));
+ dstr[9] = '\0';
+ g_print ("%s / %s %s\r", pstr, dstr, status);
+ }
+}
+
+static void
+state_changed_cb (GstPlayer * player, GstPlayerState state, GstPlay * play)
+{
+ g_print ("State changed: %s\n", gst_player_state_get_name (state));
+}
+
+static void
+buffering_cb (GstPlayer * player, gint percent, GstPlay * play)
+{
+ g_print ("Buffering: %d\n", percent);
+}
+
+static void
+print_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
+{
+ gint i, num;
+
+ num = gst_tag_list_get_tag_size (list, tag);
+ for (i = 0; i < num; ++i) {
+ const GValue *val;
+
+ val = gst_tag_list_get_value_index (list, tag, i);
+ if (G_VALUE_HOLDS_STRING (val)) {
+ g_print (" %s : %s \n", tag, g_value_get_string (val));
+ } else if (G_VALUE_HOLDS_UINT (val)) {
+ g_print (" %s : %u \n", tag, g_value_get_uint (val));
+ } else if (G_VALUE_HOLDS_DOUBLE (val)) {
+ g_print (" %s : %g \n", tag, g_value_get_double (val));
+ } else if (G_VALUE_HOLDS_BOOLEAN (val)) {
+ g_print (" %s : %s \n", tag,
+ g_value_get_boolean (val) ? "true" : "false");
+ } else if (GST_VALUE_HOLDS_DATE_TIME (val)) {
+ GstDateTime *dt = g_value_get_boxed (val);
+ gchar *dt_str = gst_date_time_to_iso8601_string (dt);
+
+ g_print (" %s : %s \n", tag, dt_str);
+ g_free (dt_str);
+ } else {
+ g_print (" %s : tag of type '%s' \n", tag, G_VALUE_TYPE_NAME (val));
+ }
+ }
+}
+
+static void
+print_video_info (GstPlayerVideoInfo * info)
+{
+ gint fps_n, fps_d;
+ guint par_n, par_d;
+
+ if (info == NULL)
+ return;
+
+ g_print (" width : %d\n", gst_player_video_info_get_width (info));
+ g_print (" height : %d\n", gst_player_video_info_get_height (info));
+ g_print (" max_bitrate : %d\n",
+ gst_player_video_info_get_max_bitrate (info));
+ g_print (" bitrate : %d\n", gst_player_video_info_get_bitrate (info));
+ gst_player_video_info_get_framerate (info, &fps_n, &fps_d);
+ g_print (" framerate : %.2f\n", (gdouble) fps_n / fps_d);
+ gst_player_video_info_get_pixel_aspect_ratio (info, &par_n, &par_d);
+ g_print (" pixel-aspect-ratio %u:%u\n", par_n, par_d);
+}
+
+static void
+print_audio_info (GstPlayerAudioInfo * info)
+{
+ if (info == NULL)
+ return;
+
+ g_print (" sample rate : %d\n",
+ gst_player_audio_info_get_sample_rate (info));
+ g_print (" channels : %d\n", gst_player_audio_info_get_channels (info));
+ g_print (" max_bitrate : %d\n",
+ gst_player_audio_info_get_max_bitrate (info));
+ g_print (" bitrate : %d\n", gst_player_audio_info_get_bitrate (info));
+ g_print (" language : %s\n", gst_player_audio_info_get_language (info));
+}
+
+static void
+print_subtitle_info (GstPlayerSubtitleInfo * info)
+{
+ if (info == NULL)
+ return;
+
+ g_print (" language : %s\n", gst_player_subtitle_info_get_language (info));
+}
+
+static void
+print_all_stream_info (GstPlayerMediaInfo * media_info)
+{
+ guint count = 0;
+ GList *list, *l;
+
+ g_print ("URI : %s\n", gst_player_media_info_get_uri (media_info));
+ g_print ("Duration: %" GST_TIME_FORMAT "\n",
+ GST_TIME_ARGS (gst_player_media_info_get_duration (media_info)));
+ g_print ("Global taglist:\n");
+ if (gst_player_media_info_get_tags (media_info))
+ gst_tag_list_foreach (gst_player_media_info_get_tags (media_info),
+ print_one_tag, NULL);
+ else
+ g_print (" (nil) \n");
+
+ list = gst_player_media_info_get_stream_list (media_info);
+ if (!list)
+ return;
+
+ g_print ("All Stream information\n");
+ for (l = list; l != NULL; l = l->next) {
+ GstTagList *tags = NULL;
+ GstPlayerStreamInfo *stream = (GstPlayerStreamInfo *) l->data;
+
+ g_print (" Stream # %u \n", count++);
+ g_print (" type : %s_%u\n",
+ gst_player_stream_info_get_stream_type (stream),
+ gst_player_stream_info_get_index (stream));
+ tags = gst_player_stream_info_get_tags (stream);
+ g_print (" taglist : \n");
+ if (tags) {
+ gst_tag_list_foreach (tags, print_one_tag, NULL);
+ }
+
+ if (GST_IS_PLAYER_VIDEO_INFO (stream))
+ print_video_info ((GstPlayerVideoInfo *) stream);
+ else if (GST_IS_PLAYER_AUDIO_INFO (stream))
+ print_audio_info ((GstPlayerAudioInfo *) stream);
+ else
+ print_subtitle_info ((GstPlayerSubtitleInfo *) stream);
+ }
+}
+
+static void
+print_all_video_stream (GstPlayerMediaInfo * media_info)
+{
+ GList *list, *l;
+
+ list = gst_player_get_video_streams (media_info);
+ if (!list)
+ return;
+
+ g_print ("All video streams\n");
+ for (l = list; l != NULL; l = l->next) {
+ GstPlayerVideoInfo *info = (GstPlayerVideoInfo *) l->data;
+ GstPlayerStreamInfo *sinfo = (GstPlayerStreamInfo *) info;
+ g_print (" %s_%d #\n", gst_player_stream_info_get_stream_type (sinfo),
+ gst_player_stream_info_get_index (sinfo));
+ print_video_info (info);
+ }
+}
+
+static void
+print_all_subtitle_stream (GstPlayerMediaInfo * media_info)
+{
+ GList *list, *l;
+
+ list = gst_player_get_subtitle_streams (media_info);
+ if (!list)
+ return;
+
+ g_print ("All subtitle streams:\n");
+ for (l = list; l != NULL; l = l->next) {
+ GstPlayerSubtitleInfo *info = (GstPlayerSubtitleInfo *) l->data;
+ GstPlayerStreamInfo *sinfo = (GstPlayerStreamInfo *) info;
+ g_print (" %s_%d #\n", gst_player_stream_info_get_stream_type (sinfo),
+ gst_player_stream_info_get_index (sinfo));
+ print_subtitle_info (info);
+ }
+}
+
+static void
+print_all_audio_stream (GstPlayerMediaInfo * media_info)
+{
+ GList *list, *l;
+
+ list = gst_player_get_audio_streams (media_info);
+ if (!list)
+ return;
+
+ g_print ("All audio streams: \n");
+ for (l = list; l != NULL; l = l->next) {
+ GstPlayerAudioInfo *info = (GstPlayerAudioInfo *) l->data;
+ GstPlayerStreamInfo *sinfo = (GstPlayerStreamInfo *) info;
+ g_print (" %s_%d #\n", gst_player_stream_info_get_stream_type (sinfo),
+ gst_player_stream_info_get_index (sinfo));
+ print_audio_info (info);
+ }
+}
+
+static void
+print_current_tracks (GstPlay * play)
+{
+ GstPlayerAudioInfo *audio = NULL;
+ GstPlayerVideoInfo *video = NULL;
+ GstPlayerSubtitleInfo *subtitle = NULL;
+
+ g_print ("Current video track: \n");
+ video = gst_player_get_current_video_track (play->player);
+ print_video_info (video);
+
+ g_print ("Current audio track: \n");
+ audio = gst_player_get_current_audio_track (play->player);
+ print_audio_info (audio);
+
+ g_print ("Current subtitle track: \n");
+ subtitle = gst_player_get_current_subtitle_track (play->player);
+ print_subtitle_info (subtitle);
+
+ if (audio)
+ g_object_unref (audio);
+
+ if (video)
+ g_object_unref (video);
+
+ if (subtitle)
+ g_object_unref (subtitle);
+}
+
+static void
+print_media_info (GstPlayerMediaInfo * media_info)
+{
+ print_all_stream_info (media_info);
+ g_print ("\n");
+ print_all_video_stream (media_info);
+ g_print ("\n");
+ print_all_audio_stream (media_info);
+ g_print ("\n");
+ print_all_subtitle_stream (media_info);
+}
+
+static void
+media_info_cb (GstPlayer * player, GstPlayerMediaInfo * info, GstPlay * play)
+{
+ static int once = 0;
+
+ if (!once) {
+ print_media_info (info);
+ print_current_tracks (play);
+ once = 1;
+ }
+}
+
+static GstPlay *
+play_new (gchar ** uris, gdouble initial_volume)
+{
+ GstPlay *play;
+
+ play = g_new0 (GstPlay, 1);
+
+ play->uris = uris;
+ play->num_uris = g_strv_length (uris);
+ play->cur_idx = -1;
+
+ play->player =
+ gst_player_new (NULL, gst_player_g_main_context_signal_dispatcher_new
+ (NULL));
+
+ g_signal_connect (play->player, "position-updated",
+ G_CALLBACK (position_updated_cb), play);
+ g_signal_connect (play->player, "state-changed",
+ G_CALLBACK (state_changed_cb), play);
+ g_signal_connect (play->player, "buffering", G_CALLBACK (buffering_cb), play);
+ g_signal_connect (play->player, "end-of-stream",
+ G_CALLBACK (end_of_stream_cb), play);
+ g_signal_connect (play->player, "error", G_CALLBACK (error_cb), play);
+
+ g_signal_connect (play->player, "media-info-updated",
+ G_CALLBACK (media_info_cb), play);
+
+ play->loop = g_main_loop_new (NULL, FALSE);
+ play->desired_state = GST_STATE_PLAYING;
+
+ play_set_relative_volume (play, initial_volume - 1.0);
+
+ return play;
+}
+
+static void
+play_set_relative_volume (GstPlay * play, gdouble volume_step)
+{
+ gdouble volume;
+
+ g_object_get (play->player, "volume", &volume, NULL);
+ volume = round ((volume + volume_step) * VOLUME_STEPS) / VOLUME_STEPS;
+ volume = CLAMP (volume, 0.0, 10.0);
+
+ g_object_set (play->player, "volume", volume, NULL);
+
+ g_print ("Volume: %.0f%% \n", volume * 100);
+}
+
+static gchar *
+play_uri_get_display_name (GstPlayer * player, const gchar * uri)
+{
+ gchar *loc;
+
+ if (gst_uri_has_protocol (uri, "file")) {
+ loc = g_filename_from_uri (uri, NULL, NULL);
+ } else if (gst_uri_has_protocol (uri, "pushfile")) {
+ loc = g_filename_from_uri (uri + 4, NULL, NULL);
+ } else {
+ loc = g_strdup (uri);
+ }
+
+ /* Maybe additionally use glib's filename to display name function */
+ return loc;
+}
+
+void
+play_uri (GstPlayer *player, const gchar * next_uri)
+{
+ gchar *loc;
+
+ play_reset (player);
+
+ loc = play_uri_get_display_name (player, next_uri);
+ g_print ("Now playing %s\n", loc);
+ g_free (loc);
+
+ g_object_set (player, "uri", next_uri, NULL);
+ gst_player_play (player);
+}
+
+/* returns FALSE if we have reached the end of the playlist */
+static gboolean
+play_next (GstPlay * play)
+{
+ if ((play->cur_idx + 1) >= play->num_uris) {
+ if (play->repeat) {
+ g_print ("Looping playlist \n");
+ play->cur_idx = -1;
+ } else
+ return FALSE;
+ }
+
+ play_uri (play, play->uris[++play->cur_idx]);
+ return TRUE;
+}
+
+/* returns FALSE if we have reached the beginning of the playlist */
+static gboolean
+play_prev (GstPlay * play)
+{
+ if (play->cur_idx == 0 || play->num_uris <= 1)
+ return FALSE;
+
+ play_uri (play, play->uris[--play->cur_idx]);
+ return TRUE;
+}
+
+static void
+do_play (GstPlay * play)
+{
+ gint i;
+
+ /* dump playlist */
+ for (i = 0; i < play->num_uris; ++i)
+ GST_INFO ("%4u : %s", i, play->uris[i]);
+
+ if (!play_next (play))
+ return;
+
+ g_main_loop_run (play->loop);
+}
+
+static void
+add_to_playlist (GPtrArray * playlist, const gchar * filename)
+{
+ GDir *dir;
+ gchar *uri;
+
+ if (gst_uri_is_valid (filename)) {
+ g_ptr_array_add (playlist, g_strdup (filename));
+ return;
+ }
+
+ if ((dir = g_dir_open (filename, 0, NULL))) {
+ const gchar *entry;
+
+ /* FIXME: sort entries for each directory? */
+ while ((entry = g_dir_read_name (dir))) {
+ gchar *path;
+
+ path = g_strconcat (filename, G_DIR_SEPARATOR_S, entry, NULL);
+ add_to_playlist (playlist, path);
+ g_free (path);
+ }
+
+ g_dir_close (dir);
+ return;
+ }
+
+ uri = gst_filename_to_uri (filename, NULL);
+ if (uri != NULL)
+ g_ptr_array_add (playlist, uri);
+ else
+ g_warning ("Could not make URI out of filename '%s'", filename);
+}
+
+static void
+shuffle_uris (gchar ** uris, guint num)
+{
+ gchar *tmp;
+ guint i, j;
+
+ if (num < 2)
+ return;
+
+ for (i = 0; i < num; i++) {
+ /* gets equally distributed random number in 0..num-1 [0;num[ */
+ j = g_random_int_range (0, num);
+ tmp = uris[j];
+ uris[j] = uris[i];
+ uris[i] = tmp;
+ }
+}
+
+static void
+restore_terminal (void)
+{
+ gst_play_kb_set_key_handler (NULL, NULL);
+}
+
+static void
+toggle_paused (GstPlay * play)
+{
+ if (play->desired_state == GST_STATE_PLAYING) {
+ play->desired_state = GST_STATE_PAUSED;
+ gst_player_pause (play->player);
+ } else {
+ play->desired_state = GST_STATE_PLAYING;
+ gst_player_play (play->player);
+ }
+}
+
+static void
+relative_seek (GstPlay * play, gdouble percent)
+{
+ gint64 dur = -1, pos = -1;
+
+ g_return_if_fail (percent >= -1.0 && percent <= 1.0);
+
+ g_object_get (play->player, "position", &pos, "duration", &dur, NULL);
+
+ if (dur <= 0) {
+ g_print ("\nCould not seek.\n");
+ return;
+ }
+
+ pos = pos + dur * percent;
+ if (pos < 0)
+ pos = 0;
+ gst_player_seek (play->player, pos);
+}
+
+static void
+keyboard_cb (const gchar * key_input, gpointer user_data)
+{
+ GstPlay *play = (GstPlay *) user_data;
+
+ switch (g_ascii_tolower (key_input[0])) {
+ case 'i':
+ {
+ GstPlayerMediaInfo *media_info = gst_player_get_media_info (play->player);
+ if (media_info) {
+ print_media_info (media_info);
+ g_object_unref (media_info);
+ print_current_tracks (play);
+ }
+ break;
+ }
+ case ' ':
+ toggle_paused (play);
+ break;
+ case 'q':
+ case 'Q':
+ g_main_loop_quit (play->loop);
+ break;
+ case '>':
+ if (!play_next (play)) {
+ g_print ("\nReached end of play list.\n");
+ g_main_loop_quit (play->loop);
+ }
+ break;
+ case '<':
+ play_prev (play);
+ break;
+ case 27: /* ESC */
+ if (key_input[1] == '\0') {
+ g_main_loop_quit (play->loop);
+ break;
+ }
+ /* fall through */
+ default:
+ if (strcmp (key_input, GST_PLAY_KB_ARROW_RIGHT) == 0) {
+ relative_seek (play, +0.08);
+ } else if (strcmp (key_input, GST_PLAY_KB_ARROW_LEFT) == 0) {
+ relative_seek (play, -0.01);
+ } else if (strcmp (key_input, GST_PLAY_KB_ARROW_UP) == 0) {
+ play_set_relative_volume (play, +1.0 / VOLUME_STEPS);
+ } else if (strcmp (key_input, GST_PLAY_KB_ARROW_DOWN) == 0) {
+ play_set_relative_volume (play, -1.0 / VOLUME_STEPS);
+ } else {
+ GST_INFO ("keyboard input:");
+ for (; *key_input != '\0'; ++key_input)
+ GST_INFO (" code %3d", *key_input);
+ }
+ break;
+ }
+}
+
+void
+girl_player_new (GstPlayer * player, const gchar * next_uri)
+{
+ gst_player_set_uri(player, next_uri);
+}
+
+void
+girl_player_stop (GstPlayer *player)
+{
+ gst_player_stop(player);
+}
+
+void
+girl_player_pause (GstPlayer *player)
+{
+ /* FIXME: Unable to quit after pause is called for the first time. */
+#if 0
+ gst_player_pause(player);
+#endif
+}
+
+#if 0
+int
+main (int argc, char **argv)
+{
+ GstPlay *play;
+ GPtrArray *playlist;
+ gboolean print_version = FALSE;
+ gboolean interactive = FALSE; /* FIXME: maybe enable by default? */
+ gboolean shuffle = FALSE;
+ gboolean repeat = FALSE;
+ gdouble volume = 1.0;
+ gchar **filenames = NULL;
+ gchar **uris;
+ guint num, i;
+ GError *err = NULL;
+ GOptionContext *ctx;
+ gchar *playlist_file = NULL;
+ GOptionEntry options[] = {
+ {"version", 0, 0, G_OPTION_ARG_NONE, &print_version,
+ "Print version information and exit", NULL},
+ {"shuffle", 0, 0, G_OPTION_ARG_NONE, &shuffle,
+ "Shuffle playlist", NULL},
+ {"interactive", 0, 0, G_OPTION_ARG_NONE, &interactive,
+ "Interactive control via keyboard", NULL},
+ {"volume", 0, 0, G_OPTION_ARG_DOUBLE, &volume,
+ "Volume", NULL},
+ {"playlist", 0, 0, G_OPTION_ARG_FILENAME, &playlist_file,
+ "Playlist file containing input media files", NULL},
+ {"loop", 0, 0, G_OPTION_ARG_NONE, &repeat, "Repeat all", NULL},
+ {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL},
+ {NULL}
+ };
+
+ g_set_prgname ("gst-play");
+
+ ctx = g_option_context_new ("FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ...");
+ g_option_context_add_main_entries (ctx, options, NULL);
+ g_option_context_add_group (ctx, gst_init_get_option_group ());
+ if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
+ g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
+ g_clear_error (&err);
+ g_option_context_free (ctx);
+ return 1;
+ }
+ g_option_context_free (ctx);
+
+ GST_DEBUG_CATEGORY_INIT (play_debug, "play", 0, "gst-play");
+
+ if (print_version) {
+ gchar *version_str;
+
+ version_str = gst_version_string ();
+ g_print ("%s version %s\n", g_get_prgname (), "1.0");
+ g_print ("%s\n", version_str);
+ g_free (version_str);
+
+ g_free (playlist_file);
+
+ return 0;
+ }
+
+ playlist = g_ptr_array_new ();
+
+ if (playlist_file != NULL) {
+ gchar *playlist_contents = NULL;
+ gchar **lines = NULL;
+
+ if (g_file_get_contents (playlist_file, &playlist_contents, NULL, &err)) {
+ lines = g_strsplit (playlist_contents, "\n", 0);
+ num = g_strv_length (lines);
+
+ for (i = 0; i < num; i++) {
+ if (lines[i][0] != '\0') {
+ GST_LOG ("Playlist[%d]: %s", i + 1, lines[i]);
+ add_to_playlist (playlist, lines[i]);
+ }
+ }
+ g_strfreev (lines);
+ g_free (playlist_contents);
+ } else {
+ g_printerr ("Could not read playlist: %s\n", err->message);
+ g_clear_error (&err);
+ }
+ g_free (playlist_file);
+ playlist_file = NULL;
+ }
+
+ if (playlist->len == 0 && (filenames == NULL || *filenames == NULL)) {
+ g_printerr ("Usage: %s FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ...",
+ "gst-play");
+ g_printerr ("\n\n"),
+ g_printerr ("%s\n\n",
+ "You must provide at least one filename or URI to play.");
+ /* No input provided. Free array */
+ g_ptr_array_free (playlist, TRUE);
+
+ return 1;
+ }
+
+ /* fill playlist */
+ if (filenames != NULL && *filenames != NULL) {
+ num = g_strv_length (filenames);
+ for (i = 0; i < num; ++i) {
+ GST_LOG ("command line argument: %s", filenames[i]);
+ add_to_playlist (playlist, filenames[i]);
+ }
+ g_strfreev (filenames);
+ }
+
+ num = playlist->len;
+ g_ptr_array_add (playlist, NULL);
+
+ uris = (gchar **) g_ptr_array_free (playlist, FALSE);
+
+ if (shuffle)
+ shuffle_uris (uris, num);
+
+ /* prepare */
+ play = play_new (uris, volume);
+ play->repeat = repeat;
+
+ if (interactive) {
+ if (gst_play_kb_set_key_handler (keyboard_cb, play)) {
+ atexit (restore_terminal);
+ } else {
+ g_print ("Interactive keyboard handling in terminal not available.\n");
+ }
+ }
+
+ /* play */
+ do_play (play);
+
+ /* clean up */
+ play_free (play);
+
+ g_print ("\n");
+ gst_deinit ();
+ return 0;
+}
+
+#endif
diff --git a/src/girl-player.h b/src/girl-player.h
index b121604..cd3e2d1 100644
--- a/src/girl-player.h
+++ b/src/girl-player.h
@@ -2,7 +2,7 @@
*
* GNOME Internet Radio Locator
*
- * Copyright (C) 2016 Ole Aamot Software
+ * Copyright (C) 2014, 2015 Ole Aamot Software
*
* Author: Ole Aamot <oka oka no>
*
@@ -21,11 +21,36 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef __GIRL_PLAYER__
-#define __GIRL_PLAYER__
+#ifndef GIRL_PLAYER_H
+#define GIRL_PLAYER_H
-void girl_player_main(gchar *streamuri, gchar *name);
+#include <gst/gst.h>
+#include <gst/player/player.h>
-#endif /* __GIRL_PLAYER__ */
+typedef struct
+{
+ gchar **uris;
+ guint num_uris;
+ gint cur_idx;
-
+ GstPlayer *player;
+ GstState desired_state;
+
+ gboolean repeat;
+
+ GMainLoop *loop;
+} GstPlay;
+
+static void play_uri (GstPlayer * player, const gchar * next_uri);
+
+void girl_player_new (GstPlayer * player, const gchar * next_uri);
+
+void girl_player_new (GstPlayer * player, const gchar * next_uri);
+
+void girl_player_quit (GstPlayer *player);
+
+void girl_player_stop (GstPlayer *player);
+
+void girl_player_pause (GstPlayer *player);
+
+#endif /* GIRL_PLAYER_H */
diff --git a/src/girl-record.c b/src/girl-record.c
index 1dc2d83..4bf1d60 100644
--- a/src/girl-record.c
+++ b/src/girl-record.c
@@ -44,10 +44,6 @@
#include <config.h>
#include "girl.h"
-#include "girl-player-frontend.h"
-#include "girl-player-backend.h"
-#include "girl-player-globals.h"
-
#include "girl-record-backend.h"
#include "girl-record-frontend.h"
diff --git a/src/girl-station.c b/src/girl-station.c
index 45c2607..112393c 100644
--- a/src/girl-station.c
+++ b/src/girl-station.c
@@ -50,6 +50,7 @@ extern GList *girl_listeners;
extern GList *girl_streams;
extern GtkWidget *girl_app;
+extern GstPlayer *player;
void show_error(gchar * msg)
{
@@ -189,7 +190,10 @@ void girl_helper_run(gchar *url, gchar *name, GirlStreamType type, GirlHelperTyp
// girl_player_main(url, girl->selected_station_name);
if (helper == GIRL_STREAM_PLAYER) {
- girl_player_main(url, girl->selected_station_name);
+ player = gst_player_new (NULL, gst_player_g_main_context_signal_dispatcher_new(NULL));
+ girl_player_new(player, url);
+ gst_player_play(player);
+ /* girl_player_main(url, girl->selected_station_name); */
}
if (helper == GIRL_STREAM_RECORD) {
diff --git a/src/girl.c b/src/girl.c
index 58fc901..1b4e8b6 100644
--- a/src/girl.c
+++ b/src/girl.c
@@ -2,7 +2,7 @@
*
* GNOME Internet Radio Locator
*
- * Copyright (C) 2014, 2015 Ole Aamot Software
+ * Copyright (C) 2014, 2015, 2017 Ole Aamot Software
*
* Author: Ole Aamot <oka oka no>
*
@@ -38,13 +38,13 @@
#include "girl-listener.h"
#include "girl-station.h"
#include "girl-program.h"
-#include "girl-player-frontend.h"
-#include "girl-player-backend.h"
-#include "girl-record-frontend.h"
+#include "girl-player.h"
#include "girl-record-backend.h"
GirlData *girl;
+GstPlayer *player;
+
GList *girl_archivers;
GList *girl_listeners;
GList *girl_programs;
@@ -77,16 +77,6 @@ int main(int argc, char *argv[])
exit(1);
}
- if (!girl_player_frontend_init (&argc, &argv)) {
- GIRL_DEBUG_MSG (_("Player Frontend initialization failure..."));
- exit (0);
- }
-
- if (!girl_player_backend_init (&argc, &argv)) {
- GIRL_DEBUG_MSG (_("Player Backend creation failure"));
- exit (0);
- }
-
gst_init(&argc, &argv);
gnome_program_init(PACKAGE, VERSION,
@@ -230,7 +220,7 @@ void on_previous_station_click(GtkWidget * a, gpointer user_data)
void on_next_station_click(GtkWidget * a, gpointer user_data)
{
GList *l = g_list_first(girl_stations);
- girl_player_frontend_stop (girl->player_window, NULL);
+ girl_player_stop(player);
girl->previous_station = (GirlStationInfo*)girl->selected_station;
if (l != NULL) {
GirlStationInfo *station = l->data;
@@ -479,7 +469,7 @@ void on_stations_selector_changed(GtkWidget * a, gpointer user_data)
station->name = g_strdup(g_object_get_data(G_OBJECT(a), "station_name"));
/* girl_history = g_list_add(GLIST(girl_history), (GirlStationInfo *)station); */
- girl_player_frontend_stop(girl->player_window, NULL);
+ girl_player_stop(player);
girl_helper_run(girl->selected_station_uri,
girl->selected_station_name,
GIRL_STREAM_SHOUTCAST,
@@ -639,18 +629,13 @@ void quit_app(GtkWidget * a, gpointer user_data)
gtk_widget_destroy(girl->player_window);
}
/* gtk_widget_destroy(girl->record_window); */
- if (g_main_loop_is_running (girl->player_loop)) {
- girl_player_backend_stop(girl->player_loop);
- girl->player_loop = NULL;
- }
+ girl_player_stop(player);
+ gst_deinit();
+ girl->player_loop = NULL;
if (GTK_IS_WIDGET(girl->record_window)) {
gtk_widget_destroy(girl->record_window);
}
- if (g_main_loop_is_running (girl->record_loop)) {
- girl_record_backend_stop(girl->record_loop);
- girl->record_loop = NULL;
- }
- /* girl_record_backend_stop(girl->record_loop); */
+ girl->record_loop = NULL;
gtk_main_quit();
}
@@ -953,12 +938,15 @@ void on_stop_button_clicked(GtkWidget *a, gpointer user_data)
}
- girl_player_backend_pause();
+ /* girl_player_backend_pause(); */
if (GTK_IS_WIDGET(girl->player_window)) {
gtk_widget_destroy(girl->player_window);
}
+ girl_player_stop(player);
+
if (girl->player_status == GIRL_PLAYER_TRUE) {
+
GIRL_DEBUG_MSG("Playback stopped.\n");
g_subprocess_force_exit(girl->player_subprocess);
// g_spawn_close_pid( girl->player_pid);
diff --git a/src/girl.xml b/src/girl.xml
index e5c1481..d82fde2 100644
--- a/src/girl.xml
+++ b/src/girl.xml
@@ -1,7 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="girl.xsl" ?>
<!DOCTYPE girl SYSTEM "girl-9.9.dtd">
-<girl version="9.9.9">
+<girl version="10">
+ <station band="ONLINE" id="burstradio" lang="en" name="Burst Radio" rank="1.0" type="edu">
+ <frequency uri="http://www.burstradio.org.uk/"></frequency>
+ <location>Bristol, United Kingdom</location>
+ <description lang="en">
+ Welcome to Burst, Bristol University’s student radio station. We broadcast from our studio in the
student’s union 24 hours a day during term times.
+
+ The great thing about Burst is that we are completely run by students. Every aspect of the station
uses student volunteers, passionate about the media and having a good time! We are proud to represent every
corner of life at the University of Bristol – no matter your level of technical knowledge, music interests or
skills, there is something for everyone at Burst!
+ </description>
+ <stream mime="audio/mpeg" uri="http://s.burstradio.org.uk:8000/;" codec="MPEG ADTS, layer III, v1"
samplerate="44100 Hz" channels="JntStereo" bitrate="128 kbps" />
+ <uri>http://www.burstradio.org.uk/</uri>
+ </station>
+
<station band="90.7FM" id="wfuv" lang="en" name="WFUV" rank="1.0" type="edu">
<frequency uri="http://www.wfuv.org/">Bronx, New York City, NY</frequency>
<location>Bronx, New York City, NY</location>
@@ -592,16 +604,6 @@ WUMR has been the University of Memphis broadcasting outlet since 1979, when Sou
<stream mime="audio/mpeg" uri="http://radio.elte.hu:8000/eper24" codec="MPEG 1 Audio, Layer 3 (MP3)"
samplerate="22050 Hz" channels="Mono" bitrate="24 kbps" />
<uri>http://eper.elte.hu/</uri>
</station>
- <!-- Non-streamable as of 2016/07/07
- <station band="ONLINE" id="burstradio" lang="en" name="Burst Radio" rank="1.0" type="edu">
- <frequency uri="http://www.burstradio.co.uk/"></frequency>
- <location>Brighton, United Kingdom</location>
- <description lang="en">Burst aims to capture the essential essence of student life at Brighton
University; distil it and broadcast this elixir to you.</description>
- <stream mime="audio/mpeg" uri="http://burst.brighton.ac.uk:8000/burst.mp3" codec="MPEG 1 Audio, Layer 3
(MP3)" samplerate="22050 Hz" channels="Mono" bitrate="24 kbps" />
- <stream mime="audio/mpeg" uri="http://burst.brighton.ac.uk:8000/burst.mp3" codec="MPEG 1 Audio, Layer 3
(MP3)" samplerate="44100 Hz" channels="Stereo" bitrate="128 kbps" />
- <uri>http://www.burstradio.co.uk/</uri>
- </station>
- -->
<station band="ONLINE" id="fusefm" lang="en" name="Fuse FM" rank="1.0" type="edu">
<frequency uri="http://fusefm.co.uk/"></frequency>
<location>Manchester, United Kingdom</location>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]