summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2022-01-20 16:32:30 -0300
committerJames Almer <jamrial@gmail.com>2022-03-15 09:42:47 -0300
commit7d532f474de2c9dc05e75a8bbb8fc57d11069a8f (patch)
treedf867a5cf431cfd5bc4faff6ff9dc3de1d2ad6ed
parent0995e1f1b31f6e937a1b527407ed3e850f138098 (diff)
tests: convert to new channel layout-API
Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r--libavcodec/tests/avcodec.c2
-rw-r--r--tests/api/api-flac-test.c33
2 files changed, 19 insertions, 16 deletions
diff --git a/libavcodec/tests/avcodec.c b/libavcodec/tests/avcodec.c
index 5d0ff9432c..006fd1ade9 100644
--- a/libavcodec/tests/avcodec.c
+++ b/libavcodec/tests/avcodec.c
@@ -76,7 +76,7 @@ int main(void){
ERR_EXT("Codec %s has unsupported type %s\n",
get_type_string(codec->type));
if (codec->type != AVMEDIA_TYPE_AUDIO) {
- if (codec->channel_layouts || codec->sample_fmts ||
+ if (codec->ch_layouts || codec->sample_fmts ||
codec->supported_samplerates)
ERR("Non-audio codec %s has audio-only fields set\n");
if (codec->capabilities & (AV_CODEC_CAP_SMALL_LAST_FRAME |
diff --git a/tests/api/api-flac-test.c b/tests/api/api-flac-test.c
index b4f52b191f..d1e45acda7 100644
--- a/tests/api/api-flac-test.c
+++ b/tests/api/api-flac-test.c
@@ -50,13 +50,13 @@ static int generate_raw_frame(uint16_t *frame_data, int i, int sample_rate,
}
static int init_encoder(const AVCodec *enc, AVCodecContext **enc_ctx,
- int64_t ch_layout, int sample_rate)
+ const AVChannelLayout *ch_layout, int sample_rate)
{
AVCodecContext *ctx;
int result;
char name_buff[NAME_BUFF_SIZE];
- av_get_channel_layout_string(name_buff, NAME_BUFF_SIZE, 0, ch_layout);
+ av_channel_layout_describe(ch_layout, name_buff, NAME_BUFF_SIZE);
av_log(NULL, AV_LOG_INFO, "channel layout: %s, sample rate: %i\n", name_buff, sample_rate);
ctx = avcodec_alloc_context3(enc);
@@ -67,7 +67,7 @@ static int init_encoder(const AVCodec *enc, AVCodecContext **enc_ctx,
ctx->sample_fmt = AV_SAMPLE_FMT_S16;
ctx->sample_rate = sample_rate;
- ctx->channel_layout = ch_layout;
+ av_channel_layout_copy(&ctx->ch_layout, ch_layout);
result = avcodec_open2(ctx, enc, NULL);
if (result < 0) {
@@ -80,7 +80,7 @@ static int init_encoder(const AVCodec *enc, AVCodecContext **enc_ctx,
}
static int init_decoder(const AVCodec *dec, AVCodecContext **dec_ctx,
- int64_t ch_layout)
+ const AVChannelLayout *ch_layout)
{
AVCodecContext *ctx;
int result;
@@ -92,9 +92,7 @@ static int init_decoder(const AVCodec *dec, AVCodecContext **dec_ctx,
}
ctx->request_sample_fmt = AV_SAMPLE_FMT_S16;
- /* XXX: FLAC ignores it for some reason */
- ctx->request_channel_layout = ch_layout;
- ctx->channel_layout = ch_layout;
+ av_channel_layout_copy(&ctx->ch_layout, ch_layout);
result = avcodec_open2(ctx, dec, NULL);
if (result < 0) {
@@ -131,7 +129,9 @@ static int run_test(const AVCodec *enc, const AVCodec *dec,
in_frame->nb_samples = enc_ctx->frame_size;
in_frame->format = enc_ctx->sample_fmt;
- in_frame->channel_layout = enc_ctx->channel_layout;
+ result = av_channel_layout_copy(&in_frame->ch_layout, &enc_ctx->ch_layout);
+ if (result < 0)
+ return result;
if (av_frame_get_buffer(in_frame, 0) != 0) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate a buffer for input frame\n");
return AVERROR(ENOMEM);
@@ -161,8 +161,8 @@ static int run_test(const AVCodec *enc, const AVCodec *dec,
return result;
generate_raw_frame((uint16_t*)(in_frame->data[0]), i, enc_ctx->sample_rate,
- enc_ctx->channels, enc_ctx->frame_size);
- in_frame_bytes = in_frame->nb_samples * in_frame->channels * sizeof(uint16_t);
+ enc_ctx->ch_layout.nb_channels, enc_ctx->frame_size);
+ in_frame_bytes = in_frame->nb_samples * in_frame->ch_layout.nb_channels * sizeof(uint16_t);
if (in_frame_bytes > in_frame->linesize[0]) {
av_log(NULL, AV_LOG_ERROR, "Incorrect value of input frame linesize\n");
return 1;
@@ -209,7 +209,7 @@ static int run_test(const AVCodec *enc, const AVCodec *dec,
return AVERROR_UNKNOWN;
}
- if (in_frame->channel_layout != out_frame->channel_layout) {
+ if (av_channel_layout_compare(&in_frame->ch_layout, &out_frame->ch_layout)) {
av_log(NULL, AV_LOG_ERROR, "Error frames before and after decoding has different channel layout\n");
return AVERROR_UNKNOWN;
}
@@ -218,7 +218,7 @@ static int run_test(const AVCodec *enc, const AVCodec *dec,
av_log(NULL, AV_LOG_ERROR, "Error frames before and after decoding has different sample format\n");
return AVERROR_UNKNOWN;
}
- out_frame_bytes = out_frame->nb_samples * out_frame->channels * sizeof(uint16_t);
+ out_frame_bytes = out_frame->nb_samples * out_frame->ch_layout.nb_channels * sizeof(uint16_t);
if (out_frame_bytes > out_frame->linesize[0]) {
av_log(NULL, AV_LOG_ERROR, "Incorrect value of output frame linesize\n");
return 1;
@@ -247,7 +247,10 @@ int main(void)
{
const AVCodec *enc = NULL, *dec = NULL;
AVCodecContext *enc_ctx = NULL, *dec_ctx = NULL;
- uint64_t channel_layouts[] = {AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT1_BACK, AV_CH_LAYOUT_SURROUND, AV_CH_LAYOUT_STEREO_DOWNMIX};
+ const AVChannelLayout channel_layouts[] = { AV_CHANNEL_LAYOUT_STEREO,
+ AV_CHANNEL_LAYOUT_5POINT1_BACK,
+ AV_CHANNEL_LAYOUT_SURROUND,
+ AV_CHANNEL_LAYOUT_STEREO_DOWNMIX };
int sample_rates[] = {8000, 44100, 48000, 192000};
int cl, sr;
@@ -265,9 +268,9 @@ int main(void)
for (cl = 0; cl < FF_ARRAY_ELEMS(channel_layouts); cl++) {
for (sr = 0; sr < FF_ARRAY_ELEMS(sample_rates); sr++) {
- if (init_encoder(enc, &enc_ctx, channel_layouts[cl], sample_rates[sr]) != 0)
+ if (init_encoder(enc, &enc_ctx, &channel_layouts[cl], sample_rates[sr]) != 0)
return 1;
- if (init_decoder(dec, &dec_ctx, channel_layouts[cl]) != 0)
+ if (init_decoder(dec, &dec_ctx, &channel_layouts[cl]) != 0)
return 1;
if (run_test(enc, dec, enc_ctx, dec_ctx) != 0)
return 1;