Skip to content

Commit 7ef4130

Browse files
committed
fix failing tests
1 parent c3146a4 commit 7ef4130

8 files changed

Lines changed: 39 additions & 24 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ XAV_VIDEO_CONVERTER_SO = $(PRIV_DIR)/libxavvideoconverter.so
1414
# XAV_DEBUG_LOGS = -DXAV_DEBUG=1
1515

1616
DECODER_HEADERS = $(XAV_DIR)/xav_decoder.h $(XAV_DIR)/decoder.h $(XAV_DIR)/video_converter.h $(XAV_DIR)/audio_converter.h $(XAV_DIR)/utils.h $(XAV_DIR)/channel_layout.h
17-
DECODER_SOURCES = $(XAV_DIR)/xav_decoder.c $(XAV_DIR)/decoder.c $(XAV_DIR)/video_converter.c $(XAV_DIR)/audio_converter.c $(XAV_DIR)/utils.c
17+
DECODER_SOURCES = $(XAV_DIR)/xav_decoder.c $(XAV_DIR)/decoder.c $(XAV_DIR)/video_converter.c $(XAV_DIR)/audio_converter.c $(XAV_DIR)/utils.c $(XAV_DIR)/channel_layout.c
1818

1919
ENCODER_HEADERS = $(XAV_DIR)/xav_encoder.h $(XAV_DIR)/encoder.h $(XAV_DIR)/utils.h $(XAV_DIR)/channel_layout.h
2020
ENCODER_SOURCES = $(XAV_DIR)/xav_encoder.c $(XAV_DIR)/encoder.c $(XAV_DIR)/utils.c $(XAV_DIR)/channel_layout.c

c_src/xav/channel_layout.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ int xav_get_channel_layout(const char *name, struct ChannelLayout *layout) {
1515
return 1;
1616
}
1717

18+
int xav_get_channel_layout_from_context(struct ChannelLayout *layout, const AVCodecContext *ctx) {
19+
#if LIBAVUTIL_VERSION_MAJOR >= 58
20+
return av_channel_layout_copy(&layout->layout, &ctx->ch_layout);
21+
#else
22+
layout->layout = ctx->channel_layout;
23+
return 0;
24+
#endif
25+
}
26+
1827
int xav_set_channel_layout(AVCodecContext *ctx, struct ChannelLayout *layout) {
1928
#if LIBAVUTIL_VERSION_MAJOR >= 58
2029
return av_channel_layout_copy(&ctx->ch_layout, &layout->layout);
@@ -24,6 +33,15 @@ int xav_set_channel_layout(AVCodecContext *ctx, struct ChannelLayout *layout) {
2433
#endif
2534
}
2635

36+
int xav_set_default_channel_layout(struct ChannelLayout *layout, int channels) {
37+
#if LIBAVUTIL_VERSION_MAJOR >= 58
38+
av_channel_layout_default(&layout->layout, channels);
39+
#else
40+
layout->layout = av_get_default_channel_layout(channels);
41+
#endif
42+
return 0;
43+
}
44+
2745
int xav_set_frame_channel_layout(AVFrame *frame, struct ChannelLayout *layout) {
2846
#if LIBAVUTIL_VERSION_MAJOR >= 58
2947
return av_channel_layout_copy(&frame->ch_layout, &layout->layout);

c_src/xav/channel_layout.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#ifndef CHANNEL_LAYOUT_H
2-
#define CHANNEL_LAYOUT_H
3-
#include <libavutil/channel_layout.h>
1+
#ifndef XAV_CHANNEL_LAYOUT_H
2+
#define XAV_CHANNEL_LAYOUT_H
43
#include <libavcodec/avcodec.h>
4+
#include <libavutil/channel_layout.h>
55

66
struct ChannelLayout {
77
#if LIBAVUTIL_VERSION_MAJOR >= 58
@@ -12,6 +12,8 @@ struct ChannelLayout {
1212
};
1313

1414
int xav_get_channel_layout(const char *name, struct ChannelLayout *layout);
15+
int xav_get_channel_layout_from_context(struct ChannelLayout *layout, const AVCodecContext *ctx);
1516
int xav_set_channel_layout(AVCodecContext *ctx, struct ChannelLayout *layout);
17+
int xav_set_default_channel_layout(struct ChannelLayout *layout, int channels);
1618
int xav_set_frame_channel_layout(AVFrame *frame, struct ChannelLayout *layout);
1719
#endif

c_src/xav/decoder.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ int decoder_init(struct Decoder *decoder, const AVCodec *codec, int channels) {
2323
}
2424

2525
if (codec->type == AVMEDIA_TYPE_AUDIO && channels != -1) {
26-
decoder->c->channels = channels;
26+
struct ChannelLayout ch_layout;
27+
xav_set_default_channel_layout(&ch_layout, channels);
28+
xav_set_channel_layout(decoder->c, &ch_layout);
2729
}
2830

2931
decoder->frame = av_frame_alloc();

c_src/xav/decoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <libswresample/swresample.h>
33

44
#include "audio_converter.h"
5+
#include "channel_layout.h"
56
#include "utils.h"
67

78
#define MAX_FLUSH_BUFFER 16

c_src/xav/utils.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ ERL_NIF_TERM xav_nif_packet_to_term(ErlNifEnv *env, AVPacket *packet) {
9595
}
9696

9797
int xav_get_nb_channels(const AVFrame *frame) {
98-
#if LIBAVUTIL_VERSION_MAJOR >= 58
99-
return frame->ch_layout.nb_channels;
100-
#else
101-
return frame->channels;
102-
#endif
103-
}
98+
#if LIBAVUTIL_VERSION_MAJOR >= 58
99+
return frame->ch_layout.nb_channels;
100+
#else
101+
return frame->channels;
102+
#endif
103+
}

c_src/xav/xav_decoder.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -347,21 +347,13 @@ static int init_audio_converter(struct XavDecoder *xav_decoder) {
347347
}
348348

349349
struct ChannelLayout in_chlayout, out_chlayout;
350-
#if LIBAVUTIL_VERSION_MAJOR >= 58
351-
in_chlayout.layout = xav_decoder->decoder->c->ch_layout;
352-
if (xav_decoder->out_channels == 0) {
353-
out_chlayout.layout = in_chlayout.layout;
354-
} else {
355-
av_channel_layout_default(&out_chlayout.layout, xav_decoder->out_channels);
356-
}
357-
#else
358-
in_chlayout.layout = xav_decoder->decoder->c->channel_layout;
350+
xav_get_channel_layout_from_context(&in_chlayout, xav_decoder->decoder->c);
351+
359352
if (xav_decoder->out_channels == 0) {
360-
out_chlayout.layout = in_chlayout.layout;
353+
xav_get_channel_layout_from_context(&out_chlayout, xav_decoder->decoder->c);
361354
} else {
362-
out_chlayout.layout = av_get_default_channel_layout(xav_decoder->out_channels);
355+
xav_set_default_channel_layout(&out_chlayout, xav_decoder->out_channels);
363356
}
364-
#endif
365357

366358
return audio_converter_init(xav_decoder->ac, in_chlayout, xav_decoder->decoder->c->sample_rate,
367359
xav_decoder->decoder->c->sample_fmt, out_chlayout, out_sample_rate,

c_src/xav/xav_encoder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ ERL_NIF_TERM encode(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
205205
} else {
206206
frame->pts = pts;
207207
frame->nb_samples = input.size / av_get_bytes_per_sample(xav_encoder->encoder->c->sample_fmt);
208-
208+
209209
int nb_channels = xav_get_nb_channels(frame);
210210
ret = av_samples_fill_arrays(frame->data, frame->linesize, input.data, nb_channels,
211211
frame->nb_samples, xav_encoder->encoder->c->sample_fmt, 1);

0 commit comments

Comments
 (0)