Example #1
0
static gint
xmms_modplug_read (xmms_xform_t *xform, xmms_sample_t *buf, gint len, xmms_error_t *err)
{
	xmms_modplug_data_t *data;

	data = xmms_xform_private_data_get (xform);

	return ModPlug_Read (data->mod, buf, len);
}
Example #2
0
static gint
xmms_mpg123_read (xmms_xform_t *xform, xmms_sample_t *buf, gint len,
                  xmms_error_t *err)
{
	xmms_mpg123_data_t *data;
	int result = MPG123_OK;
	size_t read = 0;

	data = xmms_xform_private_data_get (xform);
	g_return_val_if_fail (data, -1);

	while (read == 0) {
		gint ret = 0;

		if (result == MPG123_NEED_MORE) {
			ret = xmms_xform_read (xform, data->buf, BUFSIZE, err);
			if (ret < 0) {
				return ret;
			} else if (ret == 0) {
				data->eof_found = TRUE;
			}
		}

		result = mpg123_decode (data->decoder, data->buf, (size_t) ret,
		                        buf, len, &read);

		if (result == MPG123_NEED_MORE && data->eof_found) {
			/* We need more data, but there's none available
			 * so libmpg123 apparently missed an EOF */
			result = MPG123_DONE;
			break;
		} else if (result != MPG123_OK && result != MPG123_NEED_MORE) {
			/* This is some uncommon result like EOF, handle outside
			 * the loop */
			break;
		}
	}

	if (result == MPG123_DONE) {
		/* This is just normal EOF reported from libmpg123 */
		XMMS_DBG ("Got EOF while decoding stream");
		return 0;
	} else if (result == MPG123_NEW_FORMAT) {
		/* FIXME: When we can handle format changes, modify this */
		xmms_error_set (err,
		                XMMS_ERROR_GENERIC,
		                "The output format changed, XMMS2 can't handle that");
		return -1;
	} else if (result == MPG123_ERR) {
		xmms_error_set (err,
		                XMMS_ERROR_GENERIC,
		                mpg123_strerror (data->decoder));
		return -1;
	}

	return (gint) read;
}
Example #3
0
static gint
xmms_mpc_read (xmms_xform_t *xform, xmms_sample_t *buffer,
               gint len, xmms_error_t *err)
{
    MPC_SAMPLE_FORMAT internal[MPC_DECODER_BUFFER_LENGTH];
    xmms_mpc_data_t *data;
    mpc_uint32_t ret;
    guint size;

    data = xmms_xform_private_data_get (xform);

    size = MIN (data->buffer->len, len);

#ifdef HAVE_MPCDEC_OLD
    if (size <= 0) {
        ret = mpc_decoder_decode (&data->decoder, internal, NULL, NULL);
        if (ret == -1) {
            xmms_error_set (err, XMMS_ERROR_GENERIC, "Musepack decoder failed");
            return -1;
        }

        ret *= xmms_sample_size_get (XMMS_SAMPLE_FORMAT_FLOAT);
        ret *= data->info.channels;

        g_string_append_len (data->buffer, (gchar *) internal, ret);
    }
#else
    if (size <= 0) {
        mpc_frame_info frame;

        frame.buffer = internal;
        do {
            ret = mpc_demux_decode (data->demux, &frame);
        } while (frame.bits != -1 && frame.samples == 0);

        if (frame.bits == -1 && ret != MPC_STATUS_OK) {
            xmms_error_set (err, XMMS_ERROR_GENERIC, "Musepack decoder failed");
            return -1;
        }
        ret = frame.samples;

        ret *= xmms_sample_size_get (XMMS_SAMPLE_FORMAT_FLOAT);
        ret *= data->info.channels;

        g_string_append_len (data->buffer, (gchar *) internal, ret);
    }
#endif

    /* Update the current size of available data */
    size = MIN (data->buffer->len, len);

    memcpy (buffer, data->buffer->str, size);
    g_string_erase (data->buffer, 0, size);

    return size;
}
Example #4
0
static void
xmms_mpc_cache_streaminfo (xmms_xform_t *xform)
{
    xmms_mpc_data_t *data;
    gint bitrate, duration, filesize;
    gchar buf[8];
    const gchar *metakey;

    g_return_if_fail (xform);

    data = xmms_xform_private_data_get (xform);
    g_return_if_fail (data);

    XMMS_DBG ("stream version = %d", data->info.stream_version);

    metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_SIZE;
    if (xmms_xform_metadata_get_int (xform, metakey, &filesize)) {
        duration = mpc_streaminfo_get_length (&data->info) * 1000;
        metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_DURATION;
        xmms_xform_metadata_set_int (xform, metakey, duration);
    }

    bitrate = (data->info.bitrate) ? data->info.bitrate :
              data->info.average_bitrate;

    metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_BITRATE;
    xmms_xform_metadata_set_int (xform, metakey, bitrate);

    if (data->info.gain_album) {
        g_snprintf (buf, sizeof (buf), "%f",
                    xmms_mpc_normalize_gain ((gdouble) data->info.gain_album));
        metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_GAIN_ALBUM;
        xmms_xform_metadata_set_str (xform, metakey, buf);
    }

    if (data->info.gain_title) {
        g_snprintf (buf, sizeof (buf), "%f",
                    xmms_mpc_normalize_gain ((gdouble) data->info.gain_title));
        metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_GAIN_TRACK;
        xmms_xform_metadata_set_str (xform, metakey, buf);
    }

    if (data->info.peak_album) {
        g_snprintf (buf, sizeof (buf), "%f",
                    xmms_mpc_normalize_peak ((gdouble) data->info.peak_album));
        metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_PEAK_ALBUM;
        xmms_xform_metadata_set_str (xform, metakey, buf);
    }

    if (data->info.peak_title) {
        g_snprintf (buf, sizeof (buf), "%f",
                    xmms_mpc_normalize_peak ((gdouble) data->info.peak_title));
        metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_PEAK_TRACK;
        xmms_xform_metadata_set_str (xform, metakey, buf);
    }
}
Example #5
0
static void
xmms_sndfile_destroy (xmms_xform_t *xform)
{
	g_return_if_fail (xform);

	xmms_sndfile_data_t *data = xmms_xform_private_data_get (xform);

	sf_close (data->sndfile);

	g_free (data);
}
Example #6
0
static void
xmms_wavpack_destroy (xmms_xform_t *xform)
{
	xmms_wavpack_data_t *data;

	g_return_if_fail (xform);

	data = xmms_xform_private_data_get (xform);
	g_return_if_fail (data);

	xmms_wavpack_free_data (data);
}
Example #7
0
static void
xmms_daap_destroy (xmms_xform_t *xform)
{
	xmms_daap_data_t *data;

	data = xmms_xform_private_data_get (xform);

	daap_conn_free (data->conn);

	g_free (data->host);
	g_free (data);
}
Example #8
0
static void
xmms_nulstripper_destroy (xmms_xform_t *xform)
{
	xmms_nulstripper_data_t *data;

	g_return_if_fail (xform);

	data = xmms_xform_private_data_get (xform);
	g_return_if_fail (data);

	g_free (data);
}
Example #9
0
static gint64
xmms_wave_seek (xmms_xform_t *xform, gint64 samples,
                xmms_xform_seek_mode_t whence, xmms_error_t *error)
{
	xmms_wave_data_t *data;
	gint64 offset;
	gint64 ret;

	g_return_val_if_fail (xform, -1);
	g_return_val_if_fail (samples >= 0, -1);
	g_return_val_if_fail (whence == XMMS_XFORM_SEEK_SET, -1);

	data = xmms_xform_private_data_get (xform);
	g_return_val_if_fail (data, -1);

	/* in mp3 mode, the samples argument actually indicates bytes..
	 * thus we've set up bits_per_sample to 8 and channels to 1 to get
	 * expected behaviour. */

	offset = data->header_size;
	offset += samples * (data->bits_per_sample / 8) * data->channels;

	if (offset < data->header_size) {
		xmms_error_set (error, XMMS_ERROR_INVAL,
		                "Trying to seek before start of stream");
		return -1;
	}

	if (offset > data->header_size + data->bytes_total) {
		xmms_error_set (error, XMMS_ERROR_INVAL,
		                "Trying to seek past end of stream");
		return -1;
	}

	ret = xmms_xform_seek (xform, offset, whence, error);

	if (ret == -1) {
		return -1;
	}

	if (ret != offset) {
		XMMS_DBG ("xmms_xform_seek didn't return expected offset "
		          "(%" G_GINT64_FORMAT " != %" G_GINT64_FORMAT ")",
		          ret, offset);
	}

	ret -= data->header_size;

	ret /= (data->bits_per_sample / 8) * data->channels;

	return ret;
}
Example #10
0
static void
xmms_vorbis_destroy (xmms_xform_t *xform)
{
	xmms_vorbis_data_t *data;

	g_return_if_fail (xform);

	data = xmms_xform_private_data_get (xform);
	g_return_if_fail (data);

	ov_clear (&data->vorbisfile);
	g_free (data);
}
Example #11
0
static void
xmms_daap_destroy (xmms_xform_t *xform)
{
    xmms_daap_data_t *data;

    data = xmms_xform_private_data_get (xform);

    g_io_channel_shutdown (data->channel, TRUE, NULL);
    g_io_channel_unref (data->channel);

    g_free (data->host);
    g_free (data);
}
Example #12
0
static void
xmms_opus_destroy (xmms_xform_t *xform)
{
	xmms_opus_data_t *data;

	g_return_if_fail (xform);

	data = xmms_xform_private_data_get (xform);
	g_return_if_fail (data);

	op_free (data->opusfile);
	g_free (data);
}
Example #13
0
static gboolean
xmms_modplug_seek (xmms_xform_t *xform, guint samples)
{
	xmms_modplug_data_t *data;

	g_return_val_if_fail (xform, FALSE);

	data = xmms_xform_private_data_get (xform);

	ModPlug_Seek (data->mod, (int) ((gdouble)1000 * samples / 44100));

	return TRUE;
}
Example #14
0
File: mid1.c Project: chrippa/xmms2
static gint
xmms_mid1_read (xmms_xform_t *xform, xmms_sample_t *buf, gint len, xmms_error_t *err)
{
	xmms_mid1_data_t *data;
	data = xmms_xform_private_data_get (xform);

	if (data->pos + len > data->chunked_data->len)
		len = data->chunked_data->len - data->pos;

	memcpy (buf, &(data->chunked_data->str[data->pos]), len);
	data->pos += len;
	return len;
}
static void
xmms_icymetaint_destroy (xmms_xform_t *xform)
{
	xmms_icymetaint_data_t *data;

	g_return_if_fail (xform);

	data = xmms_xform_private_data_get (xform);
	g_return_if_fail (data);

	g_free (data->metabuffer);

	g_free (data);
}
Example #16
0
static void
xmms_mpg123_destroy (xmms_xform_t *xform)
{
	xmms_mpg123_data_t *data;

	data = xmms_xform_private_data_get (xform);
	g_return_if_fail (data);

	if (data != NULL) {
		mpg123_delete (data->decoder);
		mpg123_delete_pars (data->param);
	}
	g_free (data);
}
Example #17
0
static void
xmms_asf_destroy (xmms_xform_t *xform)
{
    xmms_asf_data_t *data;

    g_return_if_fail (xform);

    data = xmms_xform_private_data_get (xform);
    g_return_if_fail (data);

    g_string_free (data->outbuf, TRUE);
    asf_packet_destroy (data->packet);
    g_free (data);
}
Example #18
0
static gint64
xmms_ofa_seek (xmms_xform_t *xform, gint64 samples,
                      xmms_xform_seek_mode_t whence, xmms_error_t *error)
{
	xmms_ofa_data_t *data;

	data = xmms_xform_private_data_get (xform);

	if (data->run_ofa) {
		xmms_log_info ("Seeking requested, disabling ofa calculation!");
		data->run_ofa = FALSE;
	}
	return xmms_xform_seek (xform, samples, whence, error);
}
Example #19
0
static void
xmms_faad_destroy (xmms_xform_t *xform)
{
	xmms_faad_data_t *data;

	g_return_if_fail (xform);

	data = xmms_xform_private_data_get (xform);
	g_return_if_fail (data);

	NeAACDecClose (data->decoder);
	g_string_free (data->outbuf, TRUE);
	g_free (data);
}
Example #20
0
static gboolean
xmms_mp4_gapless_try_legacy (xmms_xform_t *xform)
{
	xmms_mp4_data_t *data;
	guint64 startsamples, stopsamples;

	g_return_val_if_fail (xform, FALSE);
	data = xmms_xform_private_data_get (xform);
	g_return_val_if_fail (data, FALSE);

	startsamples = mp4ff_get_sample_offset (data->mp4ff, data->track, 0);
	stopsamples = mp4ff_get_track_duration (data->mp4ff, data->track);

	return xmms_mp4_gapless_set (xform, startsamples, stopsamples);
}
static void
xmms_converter_plugin_destroy (xmms_xform_t *xform)
{
	xmms_conv_xform_data_t *data;

	data = xmms_xform_private_data_get (xform);

	if (data) {
		if (data->conv) {
			xmms_object_unref (data->conv);
		}

		g_free (data);
	}
}
Example #22
0
static gint
xmms_sndfile_read (xmms_xform_t *xform, xmms_sample_t *buf, gint len,
                   xmms_error_t *error)
{
	xmms_sndfile_data_t *data;

	g_return_val_if_fail (xform, -1);

	data = xmms_xform_private_data_get (xform);
	g_return_val_if_fail (data, -1);

	sf_count_t read = sf_read_int (data->sndfile, (int*)buf, len/sizeof (int));

	return read * sizeof (int);
}
Example #23
0
static void
xmms_sid_destroy (xmms_xform_t *xform)
{
	xmms_sid_data_t *data;

	data = xmms_xform_private_data_get (xform);
	g_return_if_fail (data);

	sidplay_wrapper_destroy (data->wrapper);

	if (data->buffer)
		g_string_free (data->buffer, TRUE);

	g_free (data);
}
Example #24
0
static void
xmms_midsquash_destroy (xmms_xform_t *xform)
{
	xmms_midsquash_data_t *data;

	g_return_if_fail (xform);

	data = xmms_xform_private_data_get (xform);
	g_return_if_fail (data);

	if (data->midi0_data)
		g_string_free (data->midi0_data, TRUE);

	g_free (data);
}
Example #25
0
static void
xmms_gme_destroy (xmms_xform_t *xform)
{
	xmms_gme_data_t *data;

	g_return_if_fail (xform);

	data = (xmms_gme_data_t *)xmms_xform_private_data_get (xform);
	g_return_if_fail (data);

	if (data->emu)
		gme_delete (data->emu);

	g_free (data);

}
Example #26
0
static gint64
xmms_modplug_seek (xmms_xform_t *xform, gint64 samples,
                xmms_xform_seek_mode_t whence, xmms_error_t *error)
{
	xmms_modplug_data_t *data;

	g_return_val_if_fail (xform, -1);
	g_return_val_if_fail (samples >= 0, -1);
	g_return_val_if_fail (whence == XMMS_XFORM_SEEK_SET, -1);

	data = xmms_xform_private_data_get (xform);

	ModPlug_Seek (data->mod, (int) ((gdouble)1000 * samples / 44100));

	return samples;
}
Example #27
0
static gint
xmms_cdda_read (xmms_xform_t *xform, void *buffer,
                gint len, xmms_error_t *error)
{
	xmms_cdda_data_t *data;
	gint ret;

	g_return_val_if_fail (xform, -1);
	g_return_val_if_fail (buffer, -1);
	g_return_val_if_fail (error, -1);

	data = xmms_xform_private_data_get (xform);
	g_return_val_if_fail (data, -1);

	if (cdio_get_media_changed (data->cdio)) {
		xmms_error_set (error, XMMS_ERROR_GENERIC, "CD ejected");
		return -1;
	}

	if (data->current_lsn >= data->last_lsn) {
		return 0;
	}

	if (data->buf_used == CDIO_CD_FRAMESIZE_RAW) {
		cdio_cddap_read (data->drive, data->read_buf, data->current_lsn, 1);
		data->current_lsn++;
		data->buf_used = 0;
	}

	if (len >= CDIO_CD_FRAMESIZE_RAW) {
		ret = CDIO_CD_FRAMESIZE_RAW - data->buf_used;
		memcpy (buffer, data->read_buf + data->buf_used, ret);
	} else {
		gulong buf_left = CDIO_CD_FRAMESIZE_RAW - data->buf_used;

		if (buf_left < len) {
			memcpy (buffer, data->read_buf + data->buf_used, buf_left);
			ret = buf_left;
		} else {
			memcpy (buffer, data->read_buf + data->buf_used, len);
			ret = len;
		}
	}
	data->buf_used += ret;

	return ret;
}
Example #28
0
static void
xmms_mp4_get_mediainfo (xmms_xform_t *xform)
{
	xmms_mp4_data_t *data;
	const gchar *metakey;
	glong temp;
	gint i, num_items;

	g_return_if_fail (xform);

	data = xmms_xform_private_data_get (xform);
	g_return_if_fail (data);

	if ((temp = mp4ff_get_sample_rate (data->mp4ff, data->track)) > 0) {
		glong srate = temp;

		if ((temp = mp4ff_get_track_duration (data->mp4ff, data->track)) >= 0) {
			glong msec = ((gint64) temp) * 1000 / srate;

			metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_DURATION,
			xmms_xform_metadata_set_int (xform, metakey, msec);
		}
	}

	if ((temp = mp4ff_get_avg_bitrate (data->mp4ff, data->track)) >= 0) {
		metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_BITRATE;
		xmms_xform_metadata_set_int (xform, metakey, temp);
	}

	num_items = mp4ff_meta_get_num_items (data->mp4ff);
	for (i = 0; i < num_items; i++) {
		gchar *key, *value;
		guint length;

		length = mp4ff_meta_get_by_index (data->mp4ff, i, &key, &value);
		if (length > 0) {
			if (!xmms_xform_metadata_mapper_match (xform, key, value, length)) {
				/* iTunSMPB should be handled in xmms_mp4_gapless_try */
				if (0 != g_ascii_strcasecmp (key, "iTunSMPB")) {
					XMMS_DBG ("Unhandled tag '%s' = '%s'", key, value);
				}
			}
			g_free (key);
			g_free (value);
		}
	}
}
Example #29
0
static int
opus_callback_read (void *datasource, unsigned char *ptr, int size)
{
	xmms_opus_data_t *data;
	xmms_xform_t *xform = datasource;
	xmms_error_t error;
	size_t ret;

	g_return_val_if_fail (xform, 0);

	data = xmms_xform_private_data_get (xform);
	g_return_val_if_fail (data, 0);

	ret = xmms_xform_read (xform, ptr, size, &error);

	return ret;
}
Example #30
0
static gint64
xmms_mpg123_seek (xmms_xform_t *xform, gint64 samples,
                  xmms_xform_seek_mode_t whence,
                  xmms_error_t *err)
{
	xmms_mpg123_data_t *data;
	gint64 ret;
	off_t byteoff, samploff;
	int mwhence = -1;

	data = xmms_xform_private_data_get (xform);
	g_return_val_if_fail (data, -1);

	if (whence == XMMS_XFORM_SEEK_SET) {
		mwhence = SEEK_SET;
	} else if (whence == XMMS_XFORM_SEEK_CUR) {
		mwhence = SEEK_CUR;
	} else if (whence == XMMS_XFORM_SEEK_END) {
		mwhence = SEEK_END;
	}

	/* Get needed input position and possibly reached sample offset
	 * from mpg123.
	 */
	samploff = mpg123_feedseek (data->decoder, samples, mwhence,
	                            &byteoff);

	XMMS_DBG ("seeked to %li ... input stream seek following",
	          (long) samploff);

	if (samploff < 0) {
		xmms_error_set (err,
		                XMMS_ERROR_GENERIC,
		                mpg123_strerror (data->decoder));
		return -1;
	}

	/* Seek in input stream. */
	ret = xmms_xform_seek (xform, byteoff, XMMS_XFORM_SEEK_SET, err);
	if (ret < 0) {
		return ret;
	}

	return samploff;
}