Skip to content

Commit

Permalink
Do not use channel_layout in StreamReader
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mthrok committed Apr 10, 2024
1 parent ea437b3 commit fc80842
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/libtorio/ffmpeg/filter_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ std::string get_audio_src_args(
AVSampleFormat format,
AVRational time_base,
int sample_rate,
uint64_t channel_layout) {
int nb_channels) {
char args[512];
std::snprintf(
args,
sizeof(args),
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%" PRIx64,
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%dc",
time_base.num,
time_base.den,
sample_rate,
av_get_sample_fmt_name(format),
channel_layout);
nb_channels);
return std::string(args);
}

Expand Down Expand Up @@ -66,10 +66,10 @@ void FilterGraph::add_audio_src(
AVSampleFormat format,
AVRational time_base,
int sample_rate,
uint64_t channel_layout) {
int nb_channels) {
add_src(
avfilter_get_by_name("abuffer"),
get_audio_src_args(format, time_base, sample_rate, channel_layout));
get_audio_src_args(format, time_base, sample_rate, nb_channels));
}

void FilterGraph::add_video_src(
Expand Down
2 changes: 1 addition & 1 deletion src/libtorio/ffmpeg/filter_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FilterGraph {
AVSampleFormat format,
AVRational time_base,
int sample_rate,
uint64_t channel_layout);
int nb_channels);

void add_video_src(
AVPixelFormat format,
Expand Down
11 changes: 8 additions & 3 deletions src/libtorio/ffmpeg/stream_reader/post_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ FilterGraphFactory get_audio_factory(
return [fmt = codec_ctx->sample_fmt,
time_base,
rate = codec_ctx->sample_rate,
channel_layout = codec_ctx->channel_layout](
const std::string& filter_desc) -> FilterGraph {
nb_channels =
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(58, 2, 100)
codec_ctx->ch_layout.nb_channels
#else
codec_ctx->channels
#endif
](const std::string& filter_desc) -> FilterGraph {
FilterGraph f;
f.add_audio_src(fmt, time_base, rate, channel_layout);
f.add_audio_src(fmt, time_base, rate, nb_channels);
f.add_audio_sink();
f.add_process(filter_desc);
f.create_filter();
Expand Down
5 changes: 0 additions & 5 deletions src/libtorio/ffmpeg/stream_reader/stream_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,6 @@ void open_codec(
av_dict_set(&opts, "threads", "1", 0);
}

if (!codec_ctx->channel_layout) {
codec_ctx->channel_layout =
av_get_default_channel_layout(codec_ctx->channels);
}

int ret = avcodec_open2(codec_ctx, codec_ctx->codec, &opts);
clean_up_dict(opts);
TORCH_CHECK(
Expand Down

0 comments on commit fc80842

Please sign in to comment.