static void
gst_shout2send_set_metadata (GstShout2send * shout2send)
{
  const GstTagList *user_tags;
  GstTagList *copy;
  char *tempmetadata;
  shout_metadata_t *pmetadata;

  g_return_if_fail (shout2send != NULL);
  user_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (shout2send));
  if ((shout2send->tags == NULL) && (user_tags == NULL)) {
    return;
  }
  copy = gst_tag_list_merge (user_tags, shout2send->tags,
      gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (shout2send)));
  /* lets get the artist and song tags */
  tempmetadata = NULL;
  gst_tag_list_foreach ((GstTagList *) copy, set_shout_metadata,
      (gpointer) & tempmetadata);
  if (tempmetadata) {
    pmetadata = shout_metadata_new ();
    shout_metadata_add (pmetadata, "song", tempmetadata);
    shout_set_metadata (shout2send->conn, pmetadata);
    shout_metadata_free (pmetadata);
  }

  gst_tag_list_unref (copy);
}
Exemple #2
0
void Shouter::do_refresh_metadata() {
    shout_metadata_t* metadata = shout_metadata_new();
    if(metadata != NULL) {

        std::string title = source->get_metadata("title");
        std::string artist = source->get_metadata("artist");
        std::string length = source->get_metadata("length");
        std::string album = source->get_metadata("album");

	if(album.empty())
	    album="NO ALBUM";
	if(title.empty())
	    title="NO TITLE";
	if(artist.empty())
	    artist="NO ARTIST";

        std::string song = album + " - " + title + " - " + artist;

        shout_metadata_add(metadata,"song", song.c_str());

        shout_set_metadata(shout,metadata);

        std::cout << "song: " << song << "\n";

        shout_metadata_free(metadata);
    }
}
Exemple #3
0
static void _setSong() {
    shout_metadata_t *metadata = NULL;

    if (song == NULL) {
        return;
    }
    
    metadata = shout_metadata_new();
    if (!metadata) {
        printf("Failed to allocate MD\n");
        exit(1);
    }
    
    if (shout_metadata_add(metadata, "song", song) != SHOUTERR_SUCCESS) {
        printf("Failed to set MD\n");
        exit(1);
    }
    
    if (shout_set_metadata(shout, metadata) != SHOUTERR_SUCCESS) {
        printf("Failed to associate MD\n");
        exit(1);
    }
    
    shout_metadata_free(metadata);
}
Exemple #4
0
static PyObject* pshoutobj_set_metadata(ShoutObject* self, PyObject* args) {
  shout_metadata_t* metadata;
  PyObject* dict;
  PyObject* key;
  PyObject* val;
  const char* skey;
  const char* sval;
  int i = 0;
  int rc;

  if (!(metadata = shout_metadata_new())) {
    PyErr_NoMemory();
    return NULL;
  }

  if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict))
    return NULL;

  while (PyDict_Next(dict, &i, &key, &val)) {
    if (!PyString_Check(key)) {
      PyErr_SetString(PyExc_TypeError, "Dictionary key must be string");
      shout_metadata_free(metadata);
      return NULL;
    }
    if (!PyString_Check(val)) {
      PyErr_SetString(PyExc_TypeError, "Dictionary value must be string");
      shout_metadata_free(metadata);
      return NULL;
    }

    skey = PyString_AsString(key);
    sval = PyString_AsString(val);

    if ((rc = shout_metadata_add(metadata, skey, sval)) != SHOUTERR_SUCCESS) {
      if (rc == SHOUTERR_MALLOC)
	PyErr_NoMemory();
      else if (rc == SHOUTERR_INSANE)
	PyErr_SetString(PyExc_TypeError, "Dictionary key must not be empty");
      shout_metadata_free(metadata);
      return NULL;
    }
  }

  rc = shout_set_metadata(self->conn, metadata);
  shout_metadata_free(metadata);

  if (rc != SHOUTERR_SUCCESS) {
    PyErr_SetString(ShoutError, "Metadata not supported in this connection");
    return NULL;
  }

  return Py_BuildValue("i", 1);
}
static struct shout_data *new_shout_data(void)
{
	struct shout_data *ret = g_new(struct shout_data, 1);

	ret->shout_conn = shout_new();
	ret->shout_meta = shout_metadata_new();
	ret->bitrate = -1;
	ret->quality = -2.0;
	ret->timeout = DEFAULT_CONN_TIMEOUT;

	return ret;
}
EngineShoutcast::EngineShoutcast(ConfigObject<ConfigValue>* _config)
        : m_pTextCodec(NULL),
          m_pMetaData(),
          m_pShout(NULL),
          m_pShoutMetaData(NULL),
          m_iMetaDataLife(0),
          m_iShoutStatus(0),
          m_iShoutFailures(0),
          m_pConfig(_config),
          m_encoder(NULL),
          m_pShoutcastNeedUpdateFromPrefs(NULL),
          m_pUpdateShoutcastFromPrefs(NULL),
          m_pMasterSamplerate(new ControlObjectSlave("[Master]", "samplerate")),
          m_pShoutcastStatus(new ControlObject(ConfigKey(SHOUTCAST_PREF_KEY, "status"))),
          m_bQuit(false),
          m_custom_metadata(false),
          m_firstCall(false),
          m_format_is_mp3(false),
          m_format_is_ov(false),
          m_protocol_is_icecast1(false),
          m_protocol_is_icecast2(false),
          m_protocol_is_shoutcast(false),
          m_ogg_dynamic_update(false) {

#ifndef __WINDOWS__
    // Ignore SIGPIPE signals that we get when the remote streaming server
    // disconnects.
    signal(SIGPIPE, SIG_IGN);
#endif

    m_pShoutcastStatus->set(SHOUTCAST_DISCONNECTED);
    m_pShoutcastNeedUpdateFromPrefs = new ControlObject(
            ConfigKey(SHOUTCAST_PREF_KEY,"update_from_prefs"));
    m_pUpdateShoutcastFromPrefs = new ControlObjectSlave(
            m_pShoutcastNeedUpdateFromPrefs->getKey());

    // Initialize libshout
    shout_init();

    if (!(m_pShout = shout_new())) {
        errorDialog(tr("Mixxx encountered a problem"), tr("Could not allocate shout_t"));
        return;
    }

    if (!(m_pShoutMetaData = shout_metadata_new())) {
        errorDialog(tr("Mixxx encountered a problem"), tr("Could not allocate shout_metadata_t"));
        return;
    }
    if (shout_set_nonblocking(m_pShout, 1) != SHOUTERR_SUCCESS) {
        errorDialog(tr("Error setting non-blocking mode:"), shout_get_error(m_pShout));
        return;
    }
}
static gboolean
gst_shout2send_connect (GstShout2send * sink)
{
  const char *format =
      (sink->audio_format == SHOUT_FORMAT_VORBIS) ? "vorbis" :
      ((sink->audio_format == SHOUT_FORMAT_MP3) ? "mp3" : "unknown");
#ifdef SHOUT_FORMAT_WEBM
  if (sink->audio_format == SHOUT_FORMAT_WEBM)
    format = "webm";
#endif
  GST_DEBUG_OBJECT (sink, "Connection format is: %s", format);

  if (shout_set_format (sink->conn, sink->audio_format) != SHOUTERR_SUCCESS)
    goto could_not_set_format;

  if (shout_open (sink->conn) != SHOUTERR_SUCCESS)
    goto could_not_connect;

  GST_DEBUG_OBJECT (sink, "connected to server");
  sink->connected = TRUE;

  /* let's set metadata */
  if (sink->songmetadata) {
    shout_metadata_t *pmetadata;

    GST_DEBUG_OBJECT (sink, "shout metadata now: %s", sink->songmetadata);
    pmetadata = shout_metadata_new ();
    shout_metadata_add (pmetadata, "song", sink->songmetadata);
    shout_set_metadata (sink->conn, pmetadata);
    shout_metadata_free (pmetadata);
  }

  return TRUE;

/* ERRORS */
could_not_set_format:
  {
    GST_ELEMENT_ERROR (sink, LIBRARY, SETTINGS, (NULL),
        ("Error setting connection format: %s", shout_get_error (sink->conn)));
    return FALSE;
  }

could_not_connect:
  {
    GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE,
        (_("Could not connect to server")),
        ("shout_open() failed: err=%s", shout_get_error (sink->conn)));
    g_signal_emit (sink, gst_shout2send_signals[SIGNAL_CONNECTION_PROBLEM], 0,
        shout_get_errno (sink->conn));
    return FALSE;
  }
}
static gboolean
gst_shout2send_event (GstBaseSink * sink, GstEvent * event)
{
  GstShout2send *shout2send;
  gboolean ret = TRUE;

  shout2send = GST_SHOUT2SEND (sink);

  GST_LOG_OBJECT (shout2send, "got %s event", GST_EVENT_TYPE_NAME (event));

  switch (GST_EVENT_TYPE (event)) {
    case GST_EVENT_TAG:{
      /* vorbis audio doesnt need metadata setting on the icecast level, only mp3 */
      if (shout2send->tags && shout2send->audio_format == SHOUT_FORMAT_MP3) {
        GstTagList *list;

        gst_event_parse_tag (event, &list);
        GST_DEBUG_OBJECT (shout2send, "tags=%" GST_PTR_FORMAT, list);
        gst_tag_list_insert (shout2send->tags,
            list,
            gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (shout2send)));
        /* lets get the artist and song tags */
        gst_tag_list_foreach ((GstTagList *) list,
            set_shout_metadata, shout2send);
        if (shout2send->songmetadata && shout2send->connected) {
          shout_metadata_t *pmetadata;

          GST_DEBUG_OBJECT (shout2send, "metadata now: %s",
              shout2send->songmetadata);

          pmetadata = shout_metadata_new ();
          shout_metadata_add (pmetadata, "song", shout2send->songmetadata);
          shout_set_metadata (shout2send->conn, pmetadata);
          shout_metadata_free (pmetadata);
        }
      }
      break;
    }
    default:{
      GST_LOG_OBJECT (shout2send, "let base class handle event");
      if (GST_BASE_SINK_CLASS (parent_class)->event) {
        event = gst_event_ref (event);
        ret = GST_BASE_SINK_CLASS (parent_class)->event (sink, event);
      }
      break;
    }
  }

  return ret;
}
static void metadata_update(int delay) {
	ices_stream_t* stream;
	shout_metadata_t* metadata;
	char song[1024];
	char* playlist_metadata;
	char* value;
	int rc;

	if (delay)
		usleep(delay);

	if (!(playlist_metadata = ices_playlist_get_metadata())) {
		if (Title) {
			if (Artist)
				snprintf(song, sizeof(song), "%s - %s", Artist, Title);
			else
				snprintf(song, sizeof(song), "%s", Title);
		} else
			snprintf(song, sizeof(song), "%s", Filename);

		value = song;
	} else
		value = playlist_metadata;

	if (!(metadata = shout_metadata_new())) {
		ices_log_error("Error allocating metadata structure");
		ices_util_free(playlist_metadata);
		return;
	}

	if (shout_metadata_add(metadata, "song", value) != SHOUTERR_SUCCESS) {
		ices_log_error_output("Error adding info to metadata structure");
		ices_util_free(playlist_metadata);
		shout_metadata_free(metadata);
		return;
	}

	for (stream = ices_config.streams; stream; stream = stream->next) {
		rc = shout_set_metadata(stream->conn, metadata);

		if (rc != SHOUTERR_SUCCESS)
			ices_log_error_output("Updating metadata on %s failed.", stream->mount);
		else
			ices_log_debug("Updated metadata on %s to: %s", stream->mount, value);
	}

	ices_util_free(playlist_metadata);
	shout_metadata_free(metadata);
}
Exemple #10
0
int
setMetadata(shout_t *shout, metadata_t *mdata, char **mdata_copy)
{
	shout_metadata_t	*shout_mdata = NULL;
	char			*songInfo;
	const char		*artist, *title;
	int			 ret = SHOUTERR_SUCCESS;

	if (shout == NULL) {
		printf("%s: setMetadata(): Internal error: NULL shout_t\n",
		       __progname);
		abort();
	}

	if (mFlag)
		return (SHOUTERR_SUCCESS);

	if (mdata == NULL)
		return 1;

	if ((shout_mdata = shout_metadata_new()) == NULL) {
		printf("%s: shout_metadata_new(): %s\n", __progname,
		       strerror(ENOMEM));
		exit(1);
	}

	artist = metadata_get_artist(mdata);
	title = metadata_get_title(mdata);

	/*
	 * We can do this, because we know how libshout works. This adds
	 * "charset=UTF-8" to the HTTP metadata update request and has the
	 * desired effect of letting newer-than-2.3.1 versions of Icecast know
	 * which encoding we're using.
	 */
	if (shout_metadata_add(shout_mdata, "charset", "UTF-8") != SHOUTERR_SUCCESS) {
		/* Assume SHOUTERR_MALLOC */
		printf("%s: shout_metadata_add(): %s\n", __progname,
		       strerror(ENOMEM));
		exit(1);
	}

	if ((songInfo = getMetadataString(pezConfig->metadataFormat, mdata)) == NULL) {
		if (artist[0] == '\0' && title[0] == '\0')
			songInfo = xstrdup(metadata_get_string(mdata));
		else
			songInfo = metadata_assemble_string(mdata);
		if (artist[0] != '\0' && title[0] != '\0') {
			if (shout_metadata_add(shout_mdata, "artist", artist) != SHOUTERR_SUCCESS) {
				printf("%s: shout_metadata_add(): %s\n", __progname,
				       strerror(ENOMEM));
				exit(1);
			}
			if (shout_metadata_add(shout_mdata, "title", title) != SHOUTERR_SUCCESS) {
				printf("%s: shout_metadata_add(): %s\n", __progname,
				       strerror(ENOMEM));
				exit(1);
			}
		} else {
			if (shout_metadata_add(shout_mdata, "song", songInfo) != SHOUTERR_SUCCESS) {
				printf("%s: shout_metadata_add(): %s\n", __progname,
				       strerror(ENOMEM));
				exit(1);
			}
		}
	} else if (shout_metadata_add(shout_mdata, "song", songInfo) != SHOUTERR_SUCCESS) {
		printf("%s: shout_metadata_add(): %s\n", __progname,
		       strerror(ENOMEM));
		exit(1);
	}

	if ((ret = shout_set_metadata(shout, shout_mdata)) != SHOUTERR_SUCCESS)
		printf("%s: shout_set_metadata(): %s\n",
		       __progname, shout_get_error(shout));

	shout_metadata_free(shout_mdata);

	if (ret == SHOUTERR_SUCCESS) {
		if (mdata_copy != NULL && *mdata_copy == NULL)
			*mdata_copy = xstrdup(songInfo);
	}

	xfree(songInfo);
	return (ret);
}
Exemple #11
0
int feed_x_pad(uint8_t *data_ptr, uint8_t ci_flag, ni2http_channel_t *chan, uint8_t x_pad_ind, int start_pos)
{
	int ret=0;
	if(x_pad_ind == 1) {
		/* short X-PAD */
		if(data_ptr[0] == 0x00 && data_ptr[1] == 0x00 && data_ptr[2] == 0x00 && data_ptr[3] == 0x00)
			return 0;
		if(fill_dls_pad(data_ptr, ci_flag ? 3 : 4, data_ptr[3] == 0x02 && ci_flag, chan)){
			INFO("chan[%d] song: %s", chan->sid, chan->pad_data);
			shout_metadata_t *metadata = shout_metadata_new();
			shout_metadata_add(metadata, "song", (char *) chan->pad_data);
			shout_set_metadata(chan->shout, metadata);
			shout_metadata_free(metadata);
		}
	}

	if(x_pad_ind != 2)
		return 0;

	if(ci_flag) {
		if(data_ptr[0] == 0x00 && data_ptr[1] == 0x00 && data_ptr[2] == 0x00 && data_ptr[3] == 0x00)
			return 0;

		//uint8_t subchLen = data_ptr[3] & 0x07;
		//uint8_t appTyp = data_ptr[3] >> 3;
		//WARN("FEED_X_PAD: CI=%d: %02x %02x %02x %02x", ci_flag, data_ptr[0], data_ptr[1], data_ptr[2], data_ptr[3]);
		//print_bytes((char*)data_ptr+4-32, 32);

		int data_pos = 3, subfield_idx=0;
		uint8_t sizes[4] = {0,0,0,0};
		uint8_t types[4] = {0,0,0,0};
		uint8_t appTyp, subfieldLen;
		do {
			appTyp = data_ptr[data_pos] & 0x1f;
			subfieldLen = data_ptr[data_pos] >> 5;
			data_pos--;

			if(appTyp == 0x1f) {
				appTyp = data_ptr[data_pos];
				data_pos--;
			}


			if(appTyp != 0) {
				types[subfield_idx] = appTyp;
				sizes[subfield_idx] = pad_sizes_idx[subfieldLen];
				subfield_idx++;
			}

			//WARN("FEED_X_PAD[%d|%d]: appTyp=%d, subchLen=%d", data_pos, subfield_idx, appTyp, pad_sizes_idx[subfieldLen]);

		} while (data_pos >=0 && appTyp != 0);
		//WARN("FEED_X_PAD bytes left=%d", data_pos);

		int idx;
		uint8_t *pad_data_subch_start = data_ptr + (data_pos) + 1; //data_ptr + data_pos;
		for(idx=0;idx<subfield_idx;idx++) {
			pad_data_subch_start -= sizes[idx]; //may be -1;
			if(pad_data_subch_start < data_ptr-start_pos) {
				WARN("X_PAD: BAD pad_data_subch_start: %p, data_ptr=%p, pos=%d, start==%p", pad_data_subch_start, data_ptr, start_pos, data_ptr-start_pos);
				break;
			}

			//FIXME: if next subfield is dls again, then this may not work fine.
			switch(types[idx]) {
			case 0x02:
			case 0x03:
				//WARN("FEED_X_PAD[%d]: appTyp=%d, subchLen=%d:", idx, types[idx], sizes[idx]);
				//print_bytes((char*)pad_data_subch_start, sizes[idx]);
				if(fill_dls_pad(pad_data_subch_start, sizes[idx], types[idx] == 0x02, chan)) {
					INFO("chan[%d] song: %s", chan->sid, chan->pad_data);
					shout_metadata_t *metadata = shout_metadata_new();
					shout_metadata_add(metadata, "song", (char *) chan->pad_data);
					shout_set_metadata(chan->shout, metadata);
					shout_metadata_free(metadata);
				}
				break;
			default:
				//WARN("FEED_X_PAD[%d]: UNUSED appTyp=%d, subchLen=%d:", idx, types[idx], sizes[idx]);
				//print_bytes((char*)pad_data_subch_start, sizes[idx]);
				break;
			}
		}


	} else {
Exemple #12
0
 */
static void raise_nonspecific_shout_error(int errno) {
	rb_raise(cShoutError, "%d", errno);
}

/*
------------------- ShoutMetadata ---------------------
*/

static VALUE cShoutMetadata;

static VALUE _sh_metadata_new(VALUE class) {
        shout_metadata_t *m;
        VALUE meta;

        m = shout_metadata_new();

        meta = Data_Wrap_Struct(class, 0, shout_metadata_free, m);

        rb_obj_call_init(meta, 0, 0);

        return meta;
}

static VALUE _sh_metadata_add(VALUE self, VALUE name, VALUE value) {
        shout_metadata_t *m;
        int err;

        Data_Get_Struct(self, shout_metadata_t, m);
        err = shout_metadata_add(m, STR2CSTR(name), STR2CSTR(value));