Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions Library/TeamTalkLib/avstream/FFmpegResampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,21 @@ bool FFMPEGResampler::Init()
if(m_ctx != nullptr)
return false;

m_ctx = swr_alloc_set_opts(nullptr,
GetOutputFormat().channels == 2?
AV_CH_LAYOUT_STEREO :
AV_CH_LAYOUT_MONO,
AV_SAMPLE_FMT_S16,
GetOutputFormat().samplerate,
GetInputFormat().channels == 2?
AV_CH_LAYOUT_STEREO :
AV_CH_LAYOUT_MONO,
AV_SAMPLE_FMT_S16,
GetInputFormat().samplerate,
0,
nullptr);
if(m_ctx == nullptr)
AVChannelLayout out_ch_layout = {};
av_channel_layout_default(&out_ch_layout, GetOutputFormat().channels);
AVChannelLayout in_ch_layout = {};
av_channel_layout_default(&in_ch_layout, GetInputFormat().channels);

int ret = swr_alloc_set_opts2(&m_ctx,
&out_ch_layout,
AV_SAMPLE_FMT_S16,
GetOutputFormat().samplerate,
&in_ch_layout,
AV_SAMPLE_FMT_S16,
GetInputFormat().samplerate,
0,
nullptr);
if(ret < 0 || m_ctx == nullptr)
return false;

return swr_init(m_ctx) >= 0;
Expand Down
83 changes: 55 additions & 28 deletions Library/TeamTalkLib/avstream/FFmpegStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static void FillMediaFileProp(AVFormatContext *fmt_ctx,
{
if (aud_dec_ctx != nullptr)
{
out_prop.audio = media::AudioFormat(aud_dec_ctx->sample_rate, aud_dec_ctx->channels);
out_prop.audio = media::AudioFormat(aud_dec_ctx->sample_rate, aud_dec_ctx->ch_layout.nb_channels);
}

if ((vid_dec_ctx != nullptr) && video_stream_index >= 0)
Expand Down Expand Up @@ -635,7 +635,7 @@ int64_t FFmpegStreamer::ProcessAudioBuffer(AVFilterContext* aud_buffersink_ctx,
frame_timestamp -= start_offset;
}

int const n_channels = av_get_channel_layout_nb_channels(filt_frame->channel_layout);
int const n_channels = filt_frame->ch_layout.nb_channels;
auto* audio_data = reinterpret_cast<short*>(filt_frame->data[0]);

AudioFrame media_frame;
Expand Down Expand Up @@ -741,28 +741,27 @@ AVFilterGraph* CreateAudioFilterGraph(AVFormatContext *fmt_ctx,

const AVFilter *abuffersrc = avfilter_get_by_name("abuffer");
const AVFilter *abuffersink = avfilter_get_by_name("abuffersink");
AVFilterInOut *outputs = avfilter_inout_alloc(); //TODO: Free??
AVFilterInOut *inputs = avfilter_inout_alloc(); //TODO: Free??
const enum AVSampleFormat OUT_SAMPLE_FMTS[] = { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE };
int64_t out_channel_layouts[] = { -1, -1 };
int out_sample_rates[] = { out_samplerate, -1 };
AVFilterInOut *outputs = avfilter_inout_alloc();
AVFilterInOut *inputs = avfilter_inout_alloc();
const AVFilterLink *outlink = nullptr;
char args[512];
char filter_descr[100];
char ch_layout_str[64];
int ret = 0;
AVRational const time_base = fmt_ctx->streams[audio_stream_index]->time_base;
out_channel_layouts[0] = (out_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO);
AVChannelLayout out_ch_layout = {};
av_channel_layout_default(&out_ch_layout, out_channels);

filter_graph = avfilter_graph_alloc();

/* buffer audio source: the decoded frames from the decoder will be inserted here. */
if (aud_dec_ctx->channel_layout == 0u)
aud_dec_ctx->channel_layout = av_get_default_channel_layout(aud_dec_ctx->channels);
if (aud_dec_ctx->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
av_channel_layout_default(&aud_dec_ctx->ch_layout, aud_dec_ctx->ch_layout.nb_channels);

av_channel_layout_describe(&aud_dec_ctx->ch_layout, ch_layout_str, sizeof(ch_layout_str));
snprintf(args, sizeof(args),
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%x",
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%s",
time_base.num, time_base.den, aud_dec_ctx->sample_rate,
av_get_sample_fmt_name(aud_dec_ctx->sample_fmt), (unsigned)aud_dec_ctx->channel_layout);
av_get_sample_fmt_name(aud_dec_ctx->sample_fmt), ch_layout_str);

ret = avfilter_graph_create_filter(&aud_buffersrc_ctx, abuffersrc, "in",
args, nullptr, filter_graph);
Expand All @@ -772,33 +771,52 @@ AVFilterGraph* CreateAudioFilterGraph(AVFormatContext *fmt_ctx,
}

/* buffer audio sink: to terminate the filter chain. */
ret = avfilter_graph_create_filter(&aud_buffersink_ctx, abuffersink, "out",
nullptr, nullptr, filter_graph);
if (ret < 0) {
aud_buffersink_ctx = avfilter_graph_alloc_filter(filter_graph, abuffersink, "out");
if (!aud_buffersink_ctx) {
MYTRACE(ACE_TEXT("Cannot create audio buffer sink\n"));
ret = AVERROR(ENOMEM);
goto error;
}

ret = av_opt_set_int_list(aud_buffersink_ctx, "sample_fmts", OUT_SAMPLE_FMTS, -1,
AV_OPT_SEARCH_CHILDREN);
{
const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16 };
ret = av_opt_set_array(aud_buffersink_ctx, "sample_formats",
AV_OPT_SEARCH_CHILDREN,
0, 1, AV_OPT_TYPE_SAMPLE_FMT, sample_fmts);
}
if (ret < 0) {
MYTRACE(ACE_TEXT("Failed to set output sample fmt\n"));
goto error;
}

ret = av_opt_set_int_list(aud_buffersink_ctx, "channel_layouts", out_channel_layouts, -1,
AV_OPT_SEARCH_CHILDREN);
{
const AVChannelLayout channel_layouts[] = { out_ch_layout };
ret = av_opt_set_array(aud_buffersink_ctx, "channel_layouts",
AV_OPT_SEARCH_CHILDREN,
0, 1, AV_OPT_TYPE_CHLAYOUT, channel_layouts);
}
if (ret < 0) {
MYTRACE(ACE_TEXT("Cannot set output channel layout\n"));
goto error;
}
ret = av_opt_set_int_list(aud_buffersink_ctx, "sample_rates", out_sample_rates, -1,
AV_OPT_SEARCH_CHILDREN);

{
const int samplerates[] = { out_samplerate };
ret = av_opt_set_array(aud_buffersink_ctx, "samplerates",
AV_OPT_SEARCH_CHILDREN,
0, 1, AV_OPT_TYPE_INT, samplerates);
}
if (ret < 0) {
MYTRACE(ACE_TEXT("Cannot set output sample rate\n"));
goto error;
}

ret = avfilter_init_dict(aud_buffersink_ctx, nullptr);
if (ret < 0) {
MYTRACE(ACE_TEXT("Cannot initialize audio buffer sink\n"));
goto error;
}

/* Endpoints for the filter graph. */
outputs->name = av_strdup("in");
outputs->filter_ctx = aud_buffersrc_ctx;
Expand Down Expand Up @@ -863,7 +881,6 @@ AVFilterGraph* CreateVideoFilterGraph(AVFormatContext *fmt_ctx,
AVFilterInOut *outputs = avfilter_inout_alloc();
AVFilterInOut *inputs = avfilter_inout_alloc();
AVRational const time_base = fmt_ctx->streams[video_stream_index]->time_base;
const enum AVPixelFormat PIX_FMTS[] = { output_pixfmt, AV_PIX_FMT_NONE };
char filters_descr[100];

snprintf(filters_descr, sizeof(filters_descr), "scale=%d:%d",
Expand All @@ -888,20 +905,30 @@ AVFilterGraph* CreateVideoFilterGraph(AVFormatContext *fmt_ctx,
}

/* buffer video sink: to terminate the filter chain. */
ret = avfilter_graph_create_filter(&vid_buffersink_ctx, buffersink, "out",
nullptr, nullptr, filter_graph);
if (ret < 0) {
vid_buffersink_ctx = avfilter_graph_alloc_filter(filter_graph, buffersink, "out");
if (!vid_buffersink_ctx) {
MYTRACE(ACE_TEXT("Cannot create buffer sink\n"));
ret = AVERROR(ENOMEM);
goto error;
}

ret = av_opt_set_int_list(vid_buffersink_ctx, "pix_fmts", PIX_FMTS,
AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
{
const enum AVPixelFormat pixel_formats[] = { output_pixfmt };
ret = av_opt_set_array(vid_buffersink_ctx, "pixel_formats",
AV_OPT_SEARCH_CHILDREN,
0, 1, AV_OPT_TYPE_PIXEL_FMT, pixel_formats);
}
if (ret < 0) {
MYTRACE(ACE_TEXT("Cannot set output pixel format\n"));
goto error;
}

ret = avfilter_init_dict(vid_buffersink_ctx, nullptr);
if (ret < 0) {
MYTRACE(ACE_TEXT("Cannot initialize video buffer sink\n"));
goto error;
}

/* Endpoints for the filter graph. */
outputs->name = av_strdup("in");
outputs->filter_ctx = vid_buffersrc_ctx;
Expand Down
10 changes: 5 additions & 5 deletions Library/TeamTalkLib/build/ffmpeg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

ExternalProject_Add(ffmpeg-arm64-src
GIT_REPOSITORY https://github.com/FFmpeg/FFmpeg.git
GIT_TAG n6.1.4
GIT_TAG n8.0.1
GIT_SHALLOW TRUE
UPDATE_COMMAND ""
PREFIX ${TOOLCHAIN_BUILD_PREFIX}/ffmpeg-arm64
Expand Down Expand Up @@ -52,7 +52,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

ExternalProject_Add(ffmpeg-intel-src
GIT_REPOSITORY https://github.com/FFmpeg/FFmpeg.git
GIT_TAG n6.1.4
GIT_TAG n8.0.1
GIT_SHALLOW TRUE
UPDATE_COMMAND ""
PREFIX ${TOOLCHAIN_BUILD_PREFIX}/ffmpeg-intel
Expand Down Expand Up @@ -267,7 +267,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "iOS")

ExternalProject_Add(ffmpeg-src
GIT_REPOSITORY https://github.com/FFmpeg/FFmpeg.git
GIT_TAG n6.1.4
GIT_TAG n8.0.1
GIT_SHALLOW TRUE
UPDATE_COMMAND ""
PREFIX ${TOOLCHAIN_BUILD_PREFIX}/ffmpeg
Expand Down Expand Up @@ -353,7 +353,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if (TOOLCHAIN_BUILD_EXTERNALPROJECTS)
ExternalProject_Add(ffmpeg-src
GIT_REPOSITORY https://github.com/FFmpeg/FFmpeg.git
GIT_TAG n6.1.4
GIT_TAG n8.0.1
GIT_SHALLOW TRUE
UPDATE_COMMAND ""
PREFIX ${TOOLCHAIN_BUILD_PREFIX}/ffmpeg
Expand Down Expand Up @@ -469,7 +469,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Android")

ExternalProject_Add(ffmpeg-src
GIT_REPOSITORY https://github.com/FFmpeg/FFmpeg.git
GIT_TAG n6.1.4
GIT_TAG n8.0.1
GIT_SHALLOW TRUE
UPDATE_COMMAND ""
PREFIX ${TOOLCHAIN_BUILD_PREFIX}/ffmpeg
Expand Down
Loading