Exemplo n.º 1
0
roar_vs_t * roar_vs_new_simple(const char * server, const char * name, int rate, int channels, int codec, int bits, int dir, int * error) {
    roar_vs_t * vss = roar_vs_new(server, name, error);
    int ret;

    if (vss == NULL)
        return NULL;

    memset(&(vss->info), 0, sizeof(vss->info));

    vss->info.rate     = rate;
    vss->info.channels = channels;
    vss->info.codec    = codec;
    vss->info.bits     = bits;

    ret = roar_vs_stream(vss, &(vss->info), dir, error);

    if (ret == -1) {
        roar_vs_close(vss, ROAR_VS_TRUE, NULL);
        return NULL;
    }

    return vss;
}
Exemplo n.º 2
0
static void
roar_cancel(void *data)
{
	roar_t * self = data;

	g_mutex_lock(self->lock);
	if (self->vss != NULL)
	{
		roar_vs_t *vss = self->vss;
		self->vss = NULL;
		roar_vs_close(vss, ROAR_VS_TRUE, &(self->err));
		self->alive = false;

		vss = roar_vs_new_from_con(&(self->con), &(self->err));
		if (vss)
		{
			roar_vs_stream(vss, &(self->info), ROAR_DIR_PLAY, &(self->err));
			roar_vs_role(vss, self->role, &(self->err));
			self->vss = vss;
			self->alive = true;
		}
	}
	g_mutex_unlock(self->lock);
}
Exemplo n.º 3
0
Arquivo: roar.c Projeto: Brijen/cmus
static int op_roar_open(sample_format_t sf, const channel_position_t *channel_map)
{
    struct roar_audio_info info;
    int ret;

    memset(&info, 0, sizeof(info));

    ROAR_DBG("op_roar_open(*) = ?");

    format = sf;

    info.rate = sf_get_rate(sf);
    info.channels = sf_get_channels(sf);
    info.bits = sf_get_bits(sf);

    if (sf_get_bigendian(sf)) {
        if (sf_get_signed(sf)) {
            info.codec = ROAR_CODEC_PCM_S_BE;
        } else {
            info.codec = ROAR_CODEC_PCM_U_BE;
        }
    } else {
        if (sf_get_signed(sf)) {
            info.codec = ROAR_CODEC_PCM_S_LE;
        } else {
            info.codec = ROAR_CODEC_PCM_U_LE;
        }
    }

    ROAR_DBG("op_roar_open(*) = ?");

    if (roar_libroar_set_server(host) == -1) {
        ROAR_DBG("op_roar_open(*) = ?");

        roar_err_to_errno();
        return -OP_ERROR_ERRNO;
    }

    if ( roar_simple_connect2(&con, NULL, "C* Music Player (cmus)", ROAR_ENUM_FLAG_NONBLOCK, 0) == -1 ) {
        ROAR_DBG("op_roar_open(*) = ?");

        roar_err_to_errno();
        return -OP_ERROR_ERRNO;
    }

    vss = roar_vs_new_from_con(&con, &err);
    if (vss == NULL) {
        ROAR_DBG("op_roar_open(*) = ?");

        roar_disconnect(&con);

        _err_to_errno();
        return -OP_ERROR_ERRNO;
    }

    if (roar_vs_stream(vss, &info, ROAR_DIR_PLAY, &err) == -1) {
        ROAR_DBG("op_roar_open(*) = ?");

        roar_disconnect(&con);

        _err_to_errno();
        return -OP_ERROR_ERRNO;
    }

    ROAR_DBG("op_roar_open(*) = ?");

    if (roar_vs_buffer(vss, 2048*8, &err) == -1) {
        roar_vs_close(vss, ROAR_VS_TRUE, NULL);
        roar_disconnect(&con);
        _err_to_errno();
        return -OP_ERROR_ERRNO;
    }

    ROAR_DBG("op_roar_open(*) = ?");

    ret = _set_role();
    if (ret != 0) {
        roar_vs_close(vss, ROAR_VS_TRUE, NULL);
        roar_disconnect(&con);
        _err_to_errno();
        return ret;
    }

    ROAR_DBG("op_roar_open(*) = ?");

    if (roar_vs_blocking(vss, ROAR_VS_FALSE, &err) == -1) {
        /* FIXME: handle this error */
    }

    ROAR_DBG("op_roar_open(*) = 0");

    return 0;
}
Exemplo n.º 4
0
input_module_t *roar_open_module(module_param_t *params)
{
    input_module_t *mod = calloc(1, sizeof(input_module_t));
    im_roar_state *s;
    module_param_t *current;
    const char * server = NULL;
    int    dir    = ROAR_DIR_MONITOR;
    enum { MD_NONE = 0, MD_FILE = 1, MD_STREAM = 2 } use_metadata = MD_STREAM;
    int err;

    mod->getdata = roar_read;
    mod->handle_event = event_handler;
    mod->metadata_update = metadata_update;

    mod->internal = calloc(1, sizeof(im_roar_state));
    s = mod->internal;

    if(roar_profile2info(&s->info, "default") == -1)
    {
        LOG_ERROR1("Failed to get default audio profile: %s",
                roar_error2str(roar_error));
        return NULL;
    }
    s->info.bits = 16;

    s->vss       = NULL;

    s->plugins   = roar_plugincontainer_new_simple(IM_ROAR_APPNAME, IM_ROAR_ABIVERSION);
    if (!s->plugins)
    {
        LOG_ERROR1("Failed to create plugin container: %s",
                roar_error2str(roar_error));
        return NULL;
    }

    thread_mutex_create(&s->metadatalock);

    current = params;

    while(current)
    {
        if(!strcmp(current->name, "rate"))
            s->info.rate = roar_str2rate(current->value);
        else if(!strcmp(current->name, "channels"))
            s->info.channels = roar_str2channels(current->value);
        else if(!strcmp(current->name, "codec"))
            s->info.codec = roar_str2codec(current->value);
        else if(!strcmp(current->name, "aiprofile")) {
            if (roar_profile2info(&s->info, current->value) == -1) {
                LOG_WARN2("Can not get audio info profile %s: %s", current->value, roar_error2str(roar_error));
            }
            s->info.bits = 16;
        } else if(!strcmp(current->name, "dir")) {
            if ( !strcasecmp(current->value, "monitor") ) {
                dir = ROAR_DIR_MONITOR;
            } else if ( !strcasecmp(current->value, "record") ) {
                dir = ROAR_DIR_RECORD;
            } else {
                LOG_WARN2("Unknown value %s for parameter %s for roar module", current->value, current->name);
            }
        } else if(!strcmp(current->name, "device") || !strcmp(current->name, "server"))
            server = current->value;
        else if(!strcmp(current->name, "metadata")) {
            if ( !strcasecmp(current->value, "none") ) {
                use_metadata = MD_NONE;
            } else if ( !strcasecmp(current->value, "file") ) {
                use_metadata = MD_FILE;
            } else if ( !strcasecmp(current->value, "stream") ) {
                use_metadata = MD_STREAM;
            } else {
                use_metadata = atoi(current->value);
            }
        } else if(!strcmp(current->name, "metadatafilename")) {
            ices_config->metadata_filename = current->value;
            use_metadata = MD_FILE;
        } else if(!strcmp(current->name, "plugin")) {
            roar_plugin_load(mod, current->value);
        } else
            LOG_WARN1("Unknown parameter %s for roar module", current->name);

        current = current->next;
    }

    mod->type = ICES_INPUT_PCM;

    switch (s->info.codec) {
        case ROAR_CODEC_PCM_LE:
          mod->subtype = INPUT_PCM_LE_16;
         break;
        case ROAR_CODEC_PCM_BE:
          mod->subtype = INPUT_PCM_BE_16;
         break;
        case ROAR_CODEC_OGG_GENERAL:
          LOG_WARN0("Codec may not work, specify ogg_vorbis for Vorbis streaming");
        case ROAR_CODEC_OGG_VORBIS:
          mod->type = ICES_INPUT_VORBIS;
          // we do not set mod->subtype here, strange design ices2 has...
         break;
        case -1:
         LOG_ERROR0("Unknown Codec");
         return NULL;
        default:
         LOG_ERROR1("Unsupported Codec: %s", roar_codec2str(s->info.codec));
         return NULL;
    }

    roar_plugincontainer_appsched_trigger(s->plugins, ROAR_DL_APPSCHED_INIT);

    /* Open the VS connection */
    if ( (s->vss = roar_vs_new(server, IM_ROAR_PROGNAME, &err)) == NULL ) {
        LOG_ERROR2("Failed to open sound server %s: %s",
                server, roar_vs_strerr(err));
        goto fail;
    }

    /* Now, set the required parameters on that device */
    if ( roar_vs_stream(s->vss, &s->info, dir, &err) == -1 ) { 
        LOG_ERROR2("Failed to create a new stream on sound server %s: %s",
                server, roar_vs_strerr(err));
        goto fail;
    }

    if ( _set_flags(roar_vs_connection_obj(s->vss, NULL), roar_vs_stream_obj(s->vss, NULL),
                                ROAR_FLAG_META, ROAR_RESET_FLAG) != 0 ) {
        LOG_WARN0("Can not reset metadata flag from stream");
    }

    /* We're done, and we didn't fail! */
    LOG_INFO3("Opened sound server at %s at %d channel(s), %d Hz", 
            server, s->info.channels, s->info.rate);

    switch (use_metadata) {
     case MD_NONE:
      break;
     case MD_FILE:
        LOG_INFO0("Starting metadata update thread");
        if(ices_config->metadata_filename)
            thread_create("im_roar-metadata", metadata_thread_signal, mod, 1);
        else
            thread_create("im_roar-metadata", metadata_thread_stdin, mod, 1);
      break;
     case MD_STREAM:
        if ( _set_flags(roar_vs_connection_obj(s->vss, NULL), roar_vs_stream_obj(s->vss, NULL),
                                    ROAR_FLAG_META, ROAR_SET_FLAG) != 0 ) {
            LOG_WARN0("Can not set metadata flag from stream");
        }
      break;
    }

    return mod;

fail:
    close_module(mod); /* safe, this checks for valid contents */
    return NULL;
}
Exemplo n.º 5
0
static bool
roar_open(void *data, struct audio_format *audio_format, GError **error)
{
	roar_t * self = data;
	g_mutex_lock(self->lock);

	if (roar_simple_connect(&(self->con), self->host, self->name) < 0)
	{
		g_set_error(error, roar_output_quark(), 0,
				"Failed to connect to Roar server");
		g_mutex_unlock(self->lock);
		return false;
	}

	self->vss = roar_vs_new_from_con(&(self->con), &(self->err));

	if (self->vss == NULL || self->err != ROAR_ERROR_NONE)
	{
		g_set_error(error, roar_output_quark(), 0,
				"Failed to connect to server");
		g_mutex_unlock(self->lock);
		return false;
	}

	self->info.rate = audio_format->sample_rate;
	self->info.channels = audio_format->channels;
	self->info.codec = ROAR_CODEC_PCM_S;

	switch (audio_format->format)
	{
		case SAMPLE_FORMAT_S8:
			self->info.bits = 8;
			break;
		case SAMPLE_FORMAT_S16:
			self->info.bits = 16;
			break;
		case SAMPLE_FORMAT_S24:
			self->info.bits = 24;
			break;
		case SAMPLE_FORMAT_S24_P32:
			self->info.bits = 32;
			audio_format->format = SAMPLE_FORMAT_S32;
			break;
		case SAMPLE_FORMAT_S32:
			self->info.bits = 32;
			break;
		default:
			self->info.bits = 16;
			audio_format->format = SAMPLE_FORMAT_S16;
	}
	audio_format->reverse_endian = 0;

	if (roar_vs_stream(self->vss, &(self->info), ROAR_DIR_PLAY,
				&(self->err)) < 0)
	{
		g_set_error(error, roar_output_quark(), 0, "Failed to start stream");
		g_mutex_unlock(self->lock);
		return false;
	}
	roar_vs_role(self->vss, self->role, &(self->err));
	self->alive = true;

	g_mutex_unlock(self->lock);
	return true;
}