diff options
author | Vinod Koul <vkoul@kernel.org> | 2020-03-24 12:32:48 +0530 |
---|---|---|
committer | Vinod Koul <vkoul@kernel.org> | 2020-03-24 12:32:48 +0530 |
commit | cd8f897672916b75ab95a5a6e8b094e91c6d5213 (patch) | |
tree | 97c6a16428b1bf90f712ac79948f419ea27c1530 | |
parent | b1a8b075f1349e97ca16777e292c3fb6ccd18aa0 (diff) |
fcplay: hack test for wma, alac and apetest/codecs
Signed-off-by: Vinod Koul <vkoul@kernel.org>
-rw-r--r-- | src/utils-lgpl/fcplay.c | 99 |
1 files changed, 96 insertions, 3 deletions
diff --git a/src/utils-lgpl/fcplay.c b/src/utils-lgpl/fcplay.c index 83d48a0..b94faee 100644 --- a/src/utils-lgpl/fcplay.c +++ b/src/utils-lgpl/fcplay.c @@ -38,9 +38,12 @@ static const struct { { "REAL", SND_AUDIOCODEC_REAL }, { "VORBIS", SND_AUDIOCODEC_VORBIS }, { "FLAC", SND_AUDIOCODEC_FLAC }, + { "WMA", SND_AUDIOCODEC_WMA }, { "IEC61937", SND_AUDIOCODEC_IEC61937 }, { "G723_1", SND_AUDIOCODEC_G723_1 }, { "G729", SND_AUDIOCODEC_G729 }, + { "ALAC", SND_AUDIOCODEC_ALAC }, + { "APE", SND_AUDIOCODEC_APE }, /* BESPOKE isn't defined on older kernels */ #ifdef SND_AUDIOCODEC_BESPOKE { "BESPOKE", SND_AUDIOCODEC_BESPOKE }, @@ -165,8 +168,9 @@ static int get_codec_id(int codec_id) return SND_AUDIOCODEC_MP3; case AV_CODEC_ID_AAC: return SND_AUDIOCODEC_AAC; - case AV_CODEC_ID_WMAV1: case AV_CODEC_ID_WMAV2: + case AV_CODEC_ID_WMAPRO: + case AV_CODEC_ID_WMALOSSLESS: return SND_AUDIOCODEC_WMA; case AV_CODEC_ID_VORBIS: return SND_AUDIOCODEC_VORBIS; @@ -181,6 +185,10 @@ static int get_codec_id(int codec_id) return SND_AUDIOCODEC_AMRWB; case AV_CODEC_ID_PCM_S16LE ... AV_CODEC_ID_PCM_S16BE_PLANAR: return SND_AUDIOCODEC_PCM; + case AV_CODEC_ID_ALAC: + return SND_AUDIOCODEC_ALAC; + case AV_CODEC_ID_APE: + return SND_AUDIOCODEC_APE; default: fprintf(stderr, "Not supported AVcodec: %d\n", codec_id); exit(EXIT_FAILURE); @@ -190,9 +198,12 @@ static int get_codec_id(int codec_id) static int parse_file(char *file, struct snd_codec *codec) { AVFormatContext *ctx = NULL; + AVCodecContext *enc = NULL; AVStream *stream; char errbuf[50]; int err = 0, i, filled = 0; + int bit_rate; + int bits_per_sample; err = avformat_open_input(&ctx, file, NULL, NULL); if (err < 0) { @@ -216,12 +227,24 @@ static int parse_file(char *file, struct snd_codec *codec) if (verbose) fprintf(stderr, "Streams: %d\n", ctx->nb_streams); + enc = avcodec_alloc_context3(NULL); + if (!enc) { + fprintf(stderr, "Failed to alloc codec context\n"); + return -ENOMEM; + } + for (i = 0; i < ctx->nb_streams; i++) { stream = ctx->streams[i]; if (verbose) fprintf(stderr, "StreamType: %d", stream->codecpar->codec_type); + err = avcodec_parameters_to_context(enc, stream->codecpar); + if (err) { + fprintf(stderr, "avcodec_parameters_to_context failed\n"); + goto exit; + } + if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { fprintf(stderr, "Stream:%d is audio type\n", i); @@ -231,7 +254,10 @@ static int parse_file(char *file, struct snd_codec *codec) codec->ch_in = stream->codecpar->channels; codec->ch_out = stream->codecpar->channels; codec->sample_rate = stream->codecpar->sample_rate; - codec->bit_rate = ctx->bit_rate; + bits_per_sample = av_get_bits_per_sample(enc->codec_id); + bit_rate = bits_per_sample ? + enc->sample_rate * enc->channels * bits_per_sample : enc->bit_rate; + codec->bit_rate = bit_rate; codec->profile = stream->codecpar->profile; codec->format = 0; /* need codec format type */ codec->align = stream->codecpar->block_align; @@ -251,6 +277,26 @@ static int parse_file(char *file, struct snd_codec *codec) codec->options.flac_d.min_frame_size = 11; codec->options.flac_d.max_frame_size = 8192*4; } + + if (codec->id == SND_AUDIOCODEC_WMA) { + switch (enc->codec_tag) { + case 0x161: + codec->profile = SND_AUDIOPROFILE_WMA9; + break; + case 0x162: + codec->profile = SND_AUDIOPROFILE_WMA9_PRO; + break; + case 0x163: + codec->profile = SND_AUDIOPROFILE_WMA9_LOSSLESS; + break; + case 0x166: + codec->profile = SND_AUDIOPROFILE_WMA10; + break; + case 0x167: + codec->profile = SND_AUDIOPROFILE_WMA10_LOSSLESS; + break; + } + } } if (verbose) { @@ -272,6 +318,9 @@ static int parse_file(char *file, struct snd_codec *codec) fprintf(stderr, " Max Frame Size %d", codec->options.flac_d.max_frame_size); } + if (codec->id == SND_AUDIOCODEC_WMA) { + fprintf(stderr, " Profile: %x", codec->profile); + } fprintf(stderr, "\n"); } } @@ -311,7 +360,51 @@ void play_samples(char *name, unsigned int card, unsigned int device, memset(&codec, 0, sizeof(codec)); memset(&config, 0, sizeof(config)); - parse_file(name, &codec); +#if 0 + //parse_file(name, &codec); + codec.id = SND_AUDIOCODEC_ALAC; + codec.ch_in = 2; + codec.ch_out = 2; + codec.options.alac_d.frame_length = 4096; + codec.options.alac_d.compatible_version = 0; + codec.options.alac_d.pb = 40; + codec.options.alac_d.mb = 10; + codec.options.alac_d.kb = 14; + codec.sample_rate = 44100; + codec.options.alac_d.max_run = 255; + codec.options.alac_d.max_frame_bytes = 9530; + codec.bit_rate = 534580; + codec.id = SND_AUDIOCODEC_APE; + codec.ch_in = 2; + codec.ch_out = 2; + codec.sample_rate = 44100; + codec.options.ape_d.compatible_version = 3990; + codec.options.ape_d.compression_level = 2000; + codec.options.ape_d.format_flags = 0; + codec.options.ape_d.blocks_per_frame =73728; + codec.options.ape_d.final_frame_blocks = 62209; + codec.options.ape_d.total_frames = 75; + codec.options.ape_d.seek_table_present = 1; + codec.id = SND_AUDIOCODEC_WMA; + codec.ch_in = 2; + codec.ch_out = 2; + codec.profile = SND_AUDIOPROFILE_WMA9; + codec.bit_rate = 24078*8; + codec.align = 8192; + codec.sample_rate = 48000; + codec.options.wma_d.encoder_option = 15; +#endif +//#if 0 + codec.id = SND_AUDIOCODEC_WMA; + codec.ch_in = 2; + codec.ch_out = 2; + codec.profile = SND_AUDIOPROFILE_WMA9_PRO; + codec.bit_rate = 48000*8; + codec.align = 16834; + codec.sample_rate = 48000; + codec.options.wma_d.encoder_option = 224; +//#endif + config.codec = &codec; |