Ejemplo n.º 1
0
bool
audio_format_parse(struct audio_format *dest, const char *src,
		   bool mask, GError **error_r)
{
	uint32_t rate;
	enum sample_format sample_format;
	uint8_t channels;

	audio_format_clear(dest);

	/* parse sample rate */

#if GCC_CHECK_VERSION(4,7)
	/* workaround -Wmaybe-uninitialized false positive */
	rate = 0;
#endif

	if (!parse_sample_rate(src, mask, &rate, &src, error_r))
		return false;

	if (*src++ != ':') {
		g_set_error(error_r, audio_parser_quark(), 0,
			    "Sample format missing");
		return false;
	}

	/* parse sample format */

#if GCC_CHECK_VERSION(4,7)
	/* workaround -Wmaybe-uninitialized false positive */
	sample_format = SAMPLE_FORMAT_UNDEFINED;
#endif

	if (!parse_sample_format(src, mask, &sample_format, &src, error_r))
		return false;

	if (*src++ != ':') {
		g_set_error(error_r, audio_parser_quark(), 0,
			    "Channel count missing");
		return false;
	}

	/* parse channel count */

	if (!parse_channel_count(src, mask, &channels, &src, error_r))
		return false;

	if (*src != 0) {
		g_set_error(error_r, audio_parser_quark(), 0,
			    "Extra data after channel count: %s", src);
		return false;
	}

	audio_format_init(dest, rate, sample_format, channels);
	assert(mask ? audio_format_mask_valid(dest)
	       : audio_format_valid(dest));

	return true;
}
Ejemplo n.º 2
0
bool
audio_format_parse(struct audio_format *dest, const char *src,
		   bool mask, GError **error_r)
{
	uint32_t rate;
	enum sample_format sample_format;
	uint8_t channels;

	audio_format_clear(dest);

	/* parse sample rate */

	if (!parse_sample_rate(src, mask, &rate, &src, error_r))
		return false;

	if (*src++ != ':') {
		g_set_error(error_r, audio_parser_quark(), 0,
			    "Sample format missing");
		return false;
	}

	/* parse sample format */

	if (!parse_sample_format(src, mask, &sample_format, &src, error_r))
		return false;

	if (*src++ != ':') {
		g_set_error(error_r, audio_parser_quark(), 0,
			    "Channel count missing");
		return false;
	}

	/* parse channel count */

	if (!parse_channel_count(src, mask, &channels, &src, error_r))
		return false;

	if (*src != 0) {
		g_set_error(error_r, audio_parser_quark(), 0,
			    "Extra data after channel count: %s", src);
		return false;
	}

	audio_format_init(dest, rate, sample_format, channels);
	assert(mask ? audio_format_mask_valid(dest)
	       : audio_format_valid(dest));

	return true;
}