Skip to content

Commit 77da512

Browse files
committed
ASimb pull request hzeller#203
1 parent 9de0a29 commit 77da512

File tree

1 file changed

+48
-21
lines changed

1 file changed

+48
-21
lines changed

src/output_gstreamer.c

+48-21
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
#include "upnp_connmgr.h"
4242
#include "output_module.h"
4343

44-
void output_gstreamer_initlib(void) __attribute__((constructor));
45-
4644
static double buffer_duration = 0.0; /* Buffer disbled by default, see #182 */
4745

4846
static void scan_mime_list(void)
@@ -160,6 +158,15 @@ static void output_gstreamer_set_uri(const char *uri,
160158
}
161159

162160
static int output_gstreamer_play(output_transition_cb_t callback) {
161+
Log_info("gstreamer", "PLAY requested");
162+
163+
//ASimb: the following lines ensure, that no empty URI
164+
// is transmitted to the GStreamer
165+
if (gsuri_==NULL) {
166+
Log_info("gstreamer", "setting play state failed (No URI to play)");
167+
return -1;
168+
}
169+
163170
play_trans_callback_ = callback;
164171
if (get_current_player_state() != GST_STATE_PAUSED) {
165172
if (gst_element_set_state(player_, GST_STATE_READY) ==
@@ -178,6 +185,7 @@ static int output_gstreamer_play(output_transition_cb_t callback) {
178185
}
179186

180187
static int output_gstreamer_stop(void) {
188+
Log_info("gstreamer", "STOP requested");
181189
if (gst_element_set_state(player_, GST_STATE_READY) ==
182190
GST_STATE_CHANGE_FAILURE) {
183191
return -1;
@@ -187,6 +195,7 @@ static int output_gstreamer_stop(void) {
187195
}
188196

189197
static int output_gstreamer_pause(void) {
198+
Log_info("gstreamer", "PAUSE requested");
190199
if (gst_element_set_state(player_, GST_STATE_PAUSED) ==
191200
GST_STATE_CHANGE_FAILURE) {
192201
return -1;
@@ -195,7 +204,8 @@ static int output_gstreamer_pause(void) {
195204
}
196205
}
197206

198-
static int output_gstreamer_seek(int64_t position_nanos) {
207+
static int output_gstreamer_seek(gint64 position_nanos) {
208+
Log_info("gstreamer", "SEEK requested");
199209
if (gst_element_seek(player_, 1.0, GST_FORMAT_TIME,
200210
GST_SEEK_FLAG_FLUSH,
201211
GST_SEEK_TYPE_SET, position_nanos,
@@ -285,14 +295,28 @@ static gboolean my_bus_callback(GstBus * bus, GstMessage * msg,
285295
free(gsuri_);
286296
gsuri_ = gs_next_uri_;
287297
gs_next_uri_ = NULL;
288-
gst_element_set_state(player_, GST_STATE_READY);
298+
//ASimb: ensure, that gstreamer REALLY stops
299+
while (get_current_player_state() != GST_STATE_READY) {
300+
gst_element_set_state(player_, GST_STATE_READY);
301+
}
302+
Log_info("gstreamer", "%s: starting next stream (NextURI)", msgSrcName);
289303
g_object_set(G_OBJECT(player_), "uri", gsuri_, NULL);
290304
gst_element_set_state(player_, GST_STATE_PLAYING);
291305
if (play_trans_callback_) {
292306
play_trans_callback_(PLAY_STARTED_NEXT_STREAM);
293307
}
294-
} else if (play_trans_callback_) {
295-
play_trans_callback_(PLAY_STOPPED);
308+
} else {
309+
//ASimb: the following second line is needed to ensure,
310+
// that the GStreamer really stops
311+
Log_info("gstreamer", "%s: No further stream available", msgSrcName);
312+
gst_element_set_state(player_, GST_STATE_READY);
313+
314+
if (play_trans_callback_) {
315+
play_trans_callback_(PLAY_STOPPED);
316+
}
317+
//ASimb: URI has to cleared
318+
free(gsuri_);
319+
gsuri_ = NULL;
296320
}
297321
break;
298322

@@ -483,18 +507,19 @@ static void prepare_next_stream(GstElement *obj, gpointer userdata) {
483507

484508
Log_info("gstreamer", "about-to-finish cb: setting uri %s",
485509
gs_next_uri_);
486-
free(gsuri_);
487-
gsuri_ = gs_next_uri_;
488-
gs_next_uri_ = NULL;
489-
if (gsuri_ != NULL) {
490-
g_object_set(G_OBJECT(player_), "uri", gsuri_, NULL);
491-
if (play_trans_callback_) {
492-
// TODO(hzeller): can we figure out when we _actually_
493-
// start playing this ? there are probably a couple
494-
// of seconds between now and actual start.
495-
play_trans_callback_(PLAY_STARTED_NEXT_STREAM);
496-
}
497-
}
510+
//ASimb: not needed any more due to sampling-rate-problem
511+
// free(gsuri_);
512+
// gsuri_ = gs_next_uri_;
513+
// gs_next_uri_ = NULL;
514+
// if (gsuri_ != NULL) {
515+
// g_object_set(G_OBJECT(player_), "uri", gsuri_, NULL);
516+
// if (play_trans_callback_) {
517+
// // TODO(hzeller): can we figure out when we _actually_
518+
// // start playing this ? there are probably a couple
519+
// // of seconds between now and actual start.
520+
// play_trans_callback_(PLAY_STARTED_NEXT_STREAM);
521+
// }
522+
// }
498523
}
499524

500525
static int output_gstreamer_init(void)
@@ -590,9 +615,9 @@ static int output_gstreamer_init(void)
590615
static const char *output_gstreamer_version(char *buffer, size_t len)
591616
{
592617
snprintf(buffer, len, "%d.%d.%d (glib-%d.%d.%d; gstreamer-%d.%d.%d)",
593-
MOD_MAJOR_VERSION, MOD_MINOR_VERSION, MOD_MICRO_VERSION,
594-
GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION,
595-
GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO);
618+
MOD_MAJOR_VERSION, MOD_MINOR_VERSION, MOD_MICRO_VERSION,
619+
GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION,
620+
GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO);
596621
return buffer;
597622
}
598623

@@ -618,6 +643,8 @@ static struct output_module gstreamer_output = {
618643
.next = NULL,
619644
};
620645

646+
void output_gstreamer_initlib(void) __attribute__((constructor));
647+
621648
void output_gstreamer_initlib(void)
622649
{
623650
#if !GLIB_CHECK_VERSION(2,32,0)

0 commit comments

Comments
 (0)