All of lore.kernel.org
 help / color / mirror / Atom feed
From: Katsuhiro Suzuki <suzuki.katsuhiro@socionext.com>
To: alsa-devel@alsa-project.org, Vinod Koul <vinod.koul@intel.com>
Cc: Katsuhiro Suzuki <suzuki.katsuhiro@socionext.com>,
	Jassi Brar <jaswinder.singh@linaro.org>,
	Takashi Iwai <tiwai@suse.com>,
	Masami Hiramatsu <masami.hiramatsu@linaro.org>
Subject: [PATCH v2 2/3] cplay: move around MP3 header parsing method
Date: Fri,  2 Feb 2018 13:32:45 +0900	[thread overview]
Message-ID: <20180202043246.10481-2-suzuki.katsuhiro@socionext.com> (raw)
In-Reply-To: <20180202043246.10481-1-suzuki.katsuhiro@socionext.com>

This patch moves MP3 parsing method for -I option, this is for
adding other codec ID in the future.

Signed-off-by: Katsuhiro Suzuki <suzuki.katsuhiro@socionext.com>
---
 src/utils/cplay.c | 69 +++++++++++++++++++++++++++++++++----------------------
 1 file changed, 42 insertions(+), 27 deletions(-)

diff --git a/src/utils/cplay.c b/src/utils/cplay.c
index 1eb21ce..beec45f 100644
--- a/src/utils/cplay.c
+++ b/src/utils/cplay.c
@@ -268,6 +268,42 @@ int main(int argc, char **argv)
 	exit(EXIT_SUCCESS);
 }
 
+void get_codec_mp3(FILE *file, struct compr_config *config,
+		struct snd_codec *codec)
+{
+	size_t read;
+	struct mp3_header header;
+	unsigned int channels, rate, bits;
+
+	read = fread(&header, 1, sizeof(header), file);
+	if (read != sizeof(header)) {
+		fprintf(stderr, "Unable to read header \n");
+		fclose(file);
+		exit(EXIT_FAILURE);
+	}
+
+	if (parse_mp3_header(&header, &channels, &rate, &bits) == -1) {
+		fclose(file);
+		exit(EXIT_FAILURE);
+	}
+
+	codec->id = SND_AUDIOCODEC_MP3;
+	codec->ch_in = channels;
+	codec->ch_out = channels;
+	codec->sample_rate = rate;
+	if (!codec->sample_rate) {
+		fprintf(stderr, "invalid sample rate %d\n", rate);
+		fclose(file);
+		exit(EXIT_FAILURE);
+	}
+	codec->bit_rate = bits;
+	codec->rate_control = 0;
+	codec->profile = 0;
+	codec->level = 0;
+	codec->ch_mode = 0;
+	codec->format = 0;
+}
+
 void play_samples(char *name, unsigned int card, unsigned int device,
 		unsigned long buffer_size, unsigned int frag,
 		unsigned long codec_id)
@@ -275,12 +311,9 @@ void play_samples(char *name, unsigned int card, unsigned int device,
 	struct compr_config config;
 	struct snd_codec codec;
 	struct compress *compress;
-	struct mp3_header header;
 	FILE *file;
 	char *buffer;
 	int size, num_read, wrote;
-	unsigned int channels, rate, bits;
-	size_t read;
 
 	if (verbose)
 		printf("%s: entry\n", __func__);
@@ -290,33 +323,15 @@ void play_samples(char *name, unsigned int card, unsigned int device,
 		exit(EXIT_FAILURE);
 	}
 
-	read = fread(&header, 1, sizeof(header), file);
-	if (read != sizeof(header)) {
-		fprintf(stderr, "Unable to read header \n");
-		fclose(file);
+	switch (codec_id) {
+	case SND_AUDIOCODEC_MP3:
+		get_codec_mp3(file, &config, &codec);
+		break;
+	default:
+		fprintf(stderr, "codec ID %d is not supported\n", codec_id);
 		exit(EXIT_FAILURE);
 	}
 
-	if (parse_mp3_header(&header, &channels, &rate, &bits) == -1) {
-		fclose(file);
-		exit(EXIT_FAILURE);
-	}
-
-	codec.id = SND_AUDIOCODEC_MP3;
-	codec.ch_in = channels;
-	codec.ch_out = channels;
-	codec.sample_rate = rate;
-	if (!codec.sample_rate) {
-		fprintf(stderr, "invalid sample rate %d\n", rate);
-		fclose(file);
-		exit(EXIT_FAILURE);
-	}
-	codec.bit_rate = bits;
-	codec.rate_control = 0;
-	codec.profile = 0;
-	codec.level = 0;
-	codec.ch_mode = 0;
-	codec.format = 0;
 	if ((buffer_size != 0) && (frag != 0)) {
 		config.fragment_size = buffer_size/frag;
 		config.fragments = frag;
-- 
2.15.0

  reply	other threads:[~2018-02-02  4:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-02  4:32 [PATCH v2 1/3] cplay: add option to specify codec ID Katsuhiro Suzuki
2018-02-02  4:32 ` Katsuhiro Suzuki [this message]
2018-02-02  4:32 ` [PATCH v2 3/3] cplay: support IEC61937 format Katsuhiro Suzuki
2018-02-02 17:36 ` [PATCH v2 1/3] cplay: add option to specify codec ID Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180202043246.10481-2-suzuki.katsuhiro@socionext.com \
    --to=suzuki.katsuhiro@socionext.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=jaswinder.singh@linaro.org \
    --cc=masami.hiramatsu@linaro.org \
    --cc=tiwai@suse.com \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.