Skip to content

Commit

Permalink
ASimb pull request hzeller#203
Browse files Browse the repository at this point in the history
  • Loading branch information
mchalain committed Jun 26, 2020
1 parent 9de0a29 commit 77da512
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions src/output_gstreamer.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
#include "upnp_connmgr.h"
#include "output_module.h"

void output_gstreamer_initlib(void) __attribute__((constructor));

static double buffer_duration = 0.0; /* Buffer disbled by default, see #182 */

static void scan_mime_list(void)
Expand Down Expand Up @@ -160,6 +158,15 @@ static void output_gstreamer_set_uri(const char *uri,
}

static int output_gstreamer_play(output_transition_cb_t callback) {
Log_info("gstreamer", "PLAY requested");

//ASimb: the following lines ensure, that no empty URI
// is transmitted to the GStreamer
if (gsuri_==NULL) {
Log_info("gstreamer", "setting play state failed (No URI to play)");
return -1;
}

play_trans_callback_ = callback;
if (get_current_player_state() != GST_STATE_PAUSED) {
if (gst_element_set_state(player_, GST_STATE_READY) ==
Expand All @@ -178,6 +185,7 @@ static int output_gstreamer_play(output_transition_cb_t callback) {
}

static int output_gstreamer_stop(void) {
Log_info("gstreamer", "STOP requested");
if (gst_element_set_state(player_, GST_STATE_READY) ==
GST_STATE_CHANGE_FAILURE) {
return -1;
Expand All @@ -187,6 +195,7 @@ static int output_gstreamer_stop(void) {
}

static int output_gstreamer_pause(void) {
Log_info("gstreamer", "PAUSE requested");
if (gst_element_set_state(player_, GST_STATE_PAUSED) ==
GST_STATE_CHANGE_FAILURE) {
return -1;
Expand All @@ -195,7 +204,8 @@ static int output_gstreamer_pause(void) {
}
}

static int output_gstreamer_seek(int64_t position_nanos) {
static int output_gstreamer_seek(gint64 position_nanos) {
Log_info("gstreamer", "SEEK requested");
if (gst_element_seek(player_, 1.0, GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH,
GST_SEEK_TYPE_SET, position_nanos,
Expand Down Expand Up @@ -285,14 +295,28 @@ static gboolean my_bus_callback(GstBus * bus, GstMessage * msg,
free(gsuri_);
gsuri_ = gs_next_uri_;
gs_next_uri_ = NULL;
gst_element_set_state(player_, GST_STATE_READY);
//ASimb: ensure, that gstreamer REALLY stops
while (get_current_player_state() != GST_STATE_READY) {
gst_element_set_state(player_, GST_STATE_READY);
}
Log_info("gstreamer", "%s: starting next stream (NextURI)", msgSrcName);
g_object_set(G_OBJECT(player_), "uri", gsuri_, NULL);
gst_element_set_state(player_, GST_STATE_PLAYING);
if (play_trans_callback_) {
play_trans_callback_(PLAY_STARTED_NEXT_STREAM);
}
} else if (play_trans_callback_) {
play_trans_callback_(PLAY_STOPPED);
} else {
//ASimb: the following second line is needed to ensure,
// that the GStreamer really stops
Log_info("gstreamer", "%s: No further stream available", msgSrcName);
gst_element_set_state(player_, GST_STATE_READY);

if (play_trans_callback_) {
play_trans_callback_(PLAY_STOPPED);
}
//ASimb: URI has to cleared
free(gsuri_);
gsuri_ = NULL;
}
break;

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

Log_info("gstreamer", "about-to-finish cb: setting uri %s",
gs_next_uri_);
free(gsuri_);
gsuri_ = gs_next_uri_;
gs_next_uri_ = NULL;
if (gsuri_ != NULL) {
g_object_set(G_OBJECT(player_), "uri", gsuri_, NULL);
if (play_trans_callback_) {
// TODO(hzeller): can we figure out when we _actually_
// start playing this ? there are probably a couple
// of seconds between now and actual start.
play_trans_callback_(PLAY_STARTED_NEXT_STREAM);
}
}
//ASimb: not needed any more due to sampling-rate-problem
// free(gsuri_);
// gsuri_ = gs_next_uri_;
// gs_next_uri_ = NULL;
// if (gsuri_ != NULL) {
// g_object_set(G_OBJECT(player_), "uri", gsuri_, NULL);
// if (play_trans_callback_) {
// // TODO(hzeller): can we figure out when we _actually_
// // start playing this ? there are probably a couple
// // of seconds between now and actual start.
// play_trans_callback_(PLAY_STARTED_NEXT_STREAM);
// }
// }
}

static int output_gstreamer_init(void)
Expand Down Expand Up @@ -590,9 +615,9 @@ static int output_gstreamer_init(void)
static const char *output_gstreamer_version(char *buffer, size_t len)
{
snprintf(buffer, len, "%d.%d.%d (glib-%d.%d.%d; gstreamer-%d.%d.%d)",
MOD_MAJOR_VERSION, MOD_MINOR_VERSION, MOD_MICRO_VERSION,
GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION,
GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO);
MOD_MAJOR_VERSION, MOD_MINOR_VERSION, MOD_MICRO_VERSION,
GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION,
GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO);
return buffer;
}

Expand All @@ -618,6 +643,8 @@ static struct output_module gstreamer_output = {
.next = NULL,
};

void output_gstreamer_initlib(void) __attribute__((constructor));

void output_gstreamer_initlib(void)
{
#if !GLIB_CHECK_VERSION(2,32,0)
Expand Down

0 comments on commit 77da512

Please sign in to comment.