tests/api-flac-test: convert to new encoding/decoding API

This commit is contained in:
Anton Khirnov 2021-01-27 13:38:00 +01:00
parent ba30fd6c81
commit f942e14884
1 changed files with 27 additions and 15 deletions

View File

@ -113,7 +113,6 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,
uint8_t *raw_in = NULL, *raw_out = NULL; uint8_t *raw_in = NULL, *raw_out = NULL;
int in_offset = 0, out_offset = 0; int in_offset = 0, out_offset = 0;
int result = 0; int result = 0;
int got_output = 0;
int i = 0; int i = 0;
int in_frame_bytes, out_frame_bytes; int in_frame_bytes, out_frame_bytes;
@ -167,24 +166,39 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,
} }
memcpy(raw_in + in_offset, in_frame->data[0], in_frame_bytes); memcpy(raw_in + in_offset, in_frame->data[0], in_frame_bytes);
in_offset += in_frame_bytes; in_offset += in_frame_bytes;
result = avcodec_encode_audio2(enc_ctx, &enc_pkt, in_frame, &got_output); result = avcodec_send_frame(enc_ctx, in_frame);
if (result < 0) { if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error submitting a frame for encoding\n");
return result;
}
while (result >= 0) {
result = avcodec_receive_packet(enc_ctx, &enc_pkt);
if (result == AVERROR(EAGAIN))
break;
else if (result < 0 && result != AVERROR_EOF) {
av_log(NULL, AV_LOG_ERROR, "Error encoding audio frame\n"); av_log(NULL, AV_LOG_ERROR, "Error encoding audio frame\n");
return result; return result;
} }
/* if we get an encoded packet, feed it straight to the decoder */ /* if we get an encoded packet, feed it straight to the decoder */
if (got_output) { result = avcodec_send_packet(dec_ctx, &enc_pkt);
result = avcodec_decode_audio4(dec_ctx, out_frame, &got_output, &enc_pkt); av_packet_unref(&enc_pkt);
if (result < 0) { if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error decoding audio packet\n"); av_log(NULL, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
return result; return result;
} }
if (got_output) { result = avcodec_receive_frame(dec_ctx, out_frame);
if (result != enc_pkt.size) { if (result == AVERROR(EAGAIN)) {
av_log(NULL, AV_LOG_INFO, "Decoder consumed only part of a packet, it is allowed to do so -- need to update this test\n"); result = 0;
return AVERROR_UNKNOWN; continue;
} else if (result == AVERROR(EOF)) {
result = 0;
break;
} else if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error decoding audio packet\n");
return result;
} }
if (in_frame->nb_samples != out_frame->nb_samples) { if (in_frame->nb_samples != out_frame->nb_samples) {
@ -210,8 +224,6 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,
out_offset += out_frame_bytes; out_offset += out_frame_bytes;
} }
} }
av_packet_unref(&enc_pkt);
}
if (memcmp(raw_in, raw_out, out_frame_bytes * NUMBER_OF_AUDIO_FRAMES) != 0) { if (memcmp(raw_in, raw_out, out_frame_bytes * NUMBER_OF_AUDIO_FRAMES) != 0) {
av_log(NULL, AV_LOG_ERROR, "Output differs\n"); av_log(NULL, AV_LOG_ERROR, "Output differs\n");