Skip to content

Commit fc80842

Browse files
committed
Do not use channel_layout in StreamReader
We only care about the number of channels, so no need to create channel_layout. One can directly pass the number of channels to filter. Also int64 channel_layout is a deprecated attributes.
1 parent ea437b3 commit fc80842

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

src/libtorio/ffmpeg/filter_graph.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ std::string get_audio_src_args(
2222
AVSampleFormat format,
2323
AVRational time_base,
2424
int sample_rate,
25-
uint64_t channel_layout) {
25+
int nb_channels) {
2626
char args[512];
2727
std::snprintf(
2828
args,
2929
sizeof(args),
30-
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%" PRIx64,
30+
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%dc",
3131
time_base.num,
3232
time_base.den,
3333
sample_rate,
3434
av_get_sample_fmt_name(format),
35-
channel_layout);
35+
nb_channels);
3636
return std::string(args);
3737
}
3838

@@ -66,10 +66,10 @@ void FilterGraph::add_audio_src(
6666
AVSampleFormat format,
6767
AVRational time_base,
6868
int sample_rate,
69-
uint64_t channel_layout) {
69+
int nb_channels) {
7070
add_src(
7171
avfilter_get_by_name("abuffer"),
72-
get_audio_src_args(format, time_base, sample_rate, channel_layout));
72+
get_audio_src_args(format, time_base, sample_rate, nb_channels));
7373
}
7474

7575
void FilterGraph::add_video_src(

src/libtorio/ffmpeg/filter_graph.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FilterGraph {
4747
AVSampleFormat format,
4848
AVRational time_base,
4949
int sample_rate,
50-
uint64_t channel_layout);
50+
int nb_channels);
5151

5252
void add_video_src(
5353
AVPixelFormat format,

src/libtorio/ffmpeg/stream_reader/post_process.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ FilterGraphFactory get_audio_factory(
1919
return [fmt = codec_ctx->sample_fmt,
2020
time_base,
2121
rate = codec_ctx->sample_rate,
22-
channel_layout = codec_ctx->channel_layout](
23-
const std::string& filter_desc) -> FilterGraph {
22+
nb_channels =
23+
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(58, 2, 100)
24+
codec_ctx->ch_layout.nb_channels
25+
#else
26+
codec_ctx->channels
27+
#endif
28+
](const std::string& filter_desc) -> FilterGraph {
2429
FilterGraph f;
25-
f.add_audio_src(fmt, time_base, rate, channel_layout);
30+
f.add_audio_src(fmt, time_base, rate, nb_channels);
2631
f.add_audio_sink();
2732
f.add_process(filter_desc);
2833
f.create_filter();

src/libtorio/ffmpeg/stream_reader/stream_processor.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,6 @@ void open_codec(
140140
av_dict_set(&opts, "threads", "1", 0);
141141
}
142142

143-
if (!codec_ctx->channel_layout) {
144-
codec_ctx->channel_layout =
145-
av_get_default_channel_layout(codec_ctx->channels);
146-
}
147-
148143
int ret = avcodec_open2(codec_ctx, codec_ctx->codec, &opts);
149144
clean_up_dict(opts);
150145
TORCH_CHECK(

0 commit comments

Comments
 (0)