contrib: ffmpeg 6.0

Change-Id: Ib5ff688d4ad6127e97d15ddcdd28368a3eb5d5cc
This commit is contained in:
Aline Gondim Santos
2023-03-01 11:44:22 -03:00
committed by Adrien Béraud
parent dad5e42cf8
commit fc975f0cac
33 changed files with 168 additions and 145 deletions

View File

@ -1 +1 @@
3ea683f3a3cb9cd3f27c953655240ae3b5981e2103876a1c9d66fcdce02d4e0c9205aed78829de0c5577fd6414f32a662b472b329cb516fc5212381c71a9bd74 ffmpeg-n5.0.tar.gz
14d4b6d9ee60a861120c34082b61ec449235f53b93fa3c5fdca1d4b8033f34ac56ad3a4a83e8b19a4578879703b9d47c0d15a861ac10759d1f144e7e18f0ad93 ffmpeg-n6.0.tar.gz

View File

@ -1,8 +1,8 @@
diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c
index 2a97811d18..40ee7b8fec 100644
index 9b9a610343..8ec5bfc1ad 100644
--- a/libavcodec/libopusdec.c
+++ b/libavcodec/libopusdec.c
@@ -43,6 +43,8 @@
@@ -45,6 +45,8 @@ struct libopus_context {
#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
int apply_phase_inv;
#endif
@ -11,7 +11,7 @@ index 2a97811d18..40ee7b8fec 100644
};
#define OPUS_HEAD_SIZE 19
@@ -134,6 +136,8 @@
@@ -141,6 +143,8 @@ static av_cold int libopus_decode_init(AVCodecContext *avc)
/* Decoder delay (in samples) at 48kHz */
avc->delay = avc->internal->skip_samples = opus->pre_skip;
@ -20,10 +20,10 @@ index 2a97811d18..40ee7b8fec 100644
return 0;
}
@@ -155,25 +159,81 @@
@@ -161,27 +165,82 @@ static int libopus_decode(AVCodecContext *avc, AVFrame *frame,
int *got_frame_ptr, AVPacket *pkt)
{
struct libopus_context *opus = avc->priv_data;
AVFrame *frame = data;
- int ret, nb_samples;
+ uint8_t *outptr;
+ int ret, nb_samples = 0, nb_lost_samples = 0, nb_samples_left;
@ -98,8 +98,8 @@ index 2a97811d18..40ee7b8fec 100644
- return ff_opus_error_to_averror(nb_samples);
+ opus_strerror(ret));
+ return ff_opus_error_to_averror(ret);
+ }
+
}
+ nb_samples += ret;
+
+ if (opus->decode_fec)
@ -110,10 +110,11 @@ index 2a97811d18..40ee7b8fec 100644
+ } else {
+ opus->expected_next_pts = pkt->pts + nb_samples;
+ }
}
+ }
#ifndef OPUS_SET_GAIN
@@ -214,6 +274,7 @@
{
int i = avc->ch_layout.nb_channels * nb_samples;
@@ -220,6 +279,7 @@ static const AVOption libopusdec_options[] = {
#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
{ "apply_phase_inv", "Apply intensity stereo phase inversion", OFFSET(apply_phase_inv), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
#endif
@ -121,3 +122,6 @@ index 2a97811d18..40ee7b8fec 100644
{ NULL },
};
--
2.34.1

View File

@ -0,0 +1,21 @@
---
libavcodec/nvenc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 8a28454042..c091fe2d31 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1853,7 +1853,8 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx)
p_nvenc->nvEncEncodePicture(ctx->nvencoder, &params);
}
- reorder_queue_flush(ctx->reorder_queue);
+ if (ctx->reorder_queue)
+ reorder_queue_flush(ctx->reorder_queue);
av_fifo_freep2(&ctx->reorder_queue);
av_fifo_freep2(&ctx->output_surface_ready_queue);
av_fifo_freep2(&ctx->output_surface_queue);
--
2.34.1

View File

@ -1,6 +1,6 @@
{
"name": "ffmpeg",
"version": "n5.0",
"version": "n6.0",
"url": "https://git.ffmpeg.org/gitweb/ffmpeg.git/snapshot/__VERSION__.tar.gz",
"deps": [
"vpx",
@ -16,8 +16,8 @@
"libopusdec-enable-FEC.patch",
"windows-configure.patch",
"windows-configure-ffnvcodec.patch",
"windows-configure-libmfx.patch",
"windows-dxgi-support.patch"
"windows-dxgi-support.patch",
"nvenc-fix-reorderqueueflush-crash.patch"
],
"win_patches": [
],

View File

@ -1,4 +1,4 @@
FFMPEG_HASH := n5.0
FFMPEG_HASH := n6.0
FFMPEG_URL := https://git.ffmpeg.org/gitweb/ffmpeg.git/snapshot/$(FFMPEG_HASH).tar.gz
PKGS+=ffmpeg
@ -366,6 +366,7 @@ ffmpeg: ffmpeg-$(FFMPEG_HASH).tar.gz
$(APPLY) $(SRC)/ffmpeg/libopusenc-reload-packet-loss-at-encode.patch
$(APPLY) $(SRC)/ffmpeg/ios-disable-b-frames.patch
$(APPLY) $(SRC)/ffmpeg/screen-sharing-x11-fix.patch
$(APPLY) $(SRC)/ffmpeg/nvenc-fix-reorderqueueflush-crash.patch
$(UPDATE_AUTOCONFIG)
$(MOVE)

View File

@ -17,10 +17,10 @@ index d0fb8a1fc3..4a6defcc78 100755
-if ! disabled ffnvcodec; then
- ffnv_hdr_list="ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h"
- check_pkg_config ffnvcodec "ffnvcodec >= 9.1.23.1" "$ffnv_hdr_list" "" || \
- check_pkg_config ffnvcodec "ffnvcodec >= 9.0.18.3 ffnvcodec < 9.1" "$ffnv_hdr_list" "" || \
- check_pkg_config ffnvcodec "ffnvcodec >= 8.2.15.10 ffnvcodec < 8.3" "$ffnv_hdr_list" "" || \
- check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.11 ffnvcodec < 8.2" "$ffnv_hdr_list" ""
- check_pkg_config ffnvcodec "ffnvcodec >= 12.0.16.0" "$ffnv_hdr_list" "" || \
- check_pkg_config ffnvcodec "ffnvcodec >= 11.1.5.2 ffnvcodec < 12.0" "$ffnv_hdr_list" "" || \
- check_pkg_config ffnvcodec "ffnvcodec >= 11.0.10.2 ffnvcodec < 11.1" "$ffnv_hdr_list" "" || \
- check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.14 ffnvcodec < 8.2" "$ffnv_hdr_list" ""
-fi
-
if enabled_all libglslang libshaderc; then

View File

@ -1,6 +1,6 @@
{
"name": "ffnvcodec",
"version": "5ee2ae591f74f53bd6028344f8690f1558a1f17a",
"version": "n11.1.5.2",
"url": "https://github.com/FFmpeg/nv-codec-headers/archive/__VERSION__.tar.gz",
"deps": [],
"patches": [],

View File

@ -1,5 +1,5 @@
# ffnvcodec
FFNVCODEC_VERSION := n11.1.5.1
FFNVCODEC_VERSION := n11.1.5.2
FFNVCODEC_GITURL := https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
ifeq ($(call need_pkg,"ffnvcodec >= 8"),)

View File

@ -1,10 +1,10 @@
{
"name": "media-sdk",
"version": "intel-mediasdk-19.2.0",
"version": "intel-mediasdk-23.1.2",
"url": "https://github.com/Intel-Media-SDK/MediaSDK/archive/__VERSION__.tar.gz",
"deps": [],
"patches": [],
"win_patches": ["windows-static-lib-build.patch"],
"patches": [ "windows-static-lib-build.patch" ],
"win_patches": [],
"project_paths": ["api/mfx_dispatch/windows/libmfx_vs2015.vcxproj"],
"with_env" : "",
"custom_scripts": {

View File

@ -1,38 +1,58 @@
From 689a7acb36963c8558db3e879e6c22dcaaa535e7 Mon Sep 17 00:00:00 2001
From: Eden Abitbol <eden.abitbol@savoirfairelinux.com>
Date: Tue, 23 Jul 2019 11:30:49 -0400
Subject: [PATCH] Copy build output to correct directory
From a6d3a6c54923e46eef29046b7d1578ba05aaebe1 Mon Sep 17 00:00:00 2001
From: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
Date: Fri, 3 Mar 2023 19:18:28 -0300
Subject: [PATCH] test
---
api/mfx_dispatch/windows/libmfx_vs2015.sln | 7 ++--
.../windows/libmfx_vs2015.vcxproj | 33 +++++++++++++++++--
2 files changed, 35 insertions(+), 5 deletions(-)
.../windows/libmfx_vs2015.vcxproj | 36 +++++++++++++------
1 file changed, 26 insertions(+), 10 deletions(-)
--- a/api/mfx_dispatch/windows/libmfx_vs2015.sln
+++ b/api/mfx_dispatch/windows/libmfx_vs2015.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25420.1
+# Visual Studio 15
+VisualStudioVersion = 15.0.28307.757
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmfx_vs2015", "libmfx_vs2015.vcxproj", "{A9F7AEFB-DC6C-49E8-8E71-5351ABDCE627}"
EndProject
@@ -25,6 +25,9 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {94706D6C-B55B-49AB-B136-337F5E9B2FA3}
+ EndGlobalSection
GlobalSection(DPCodeReviewSolutionGUID) = preSolution
DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000}
EndGlobalSection
diff --git a/api/mfx_dispatch/windows/libmfx_vs2015.vcxproj b/api/mfx_dispatch/windows/libmfx_vs2015.vcxproj
index fdcdf8c0..0b8ca3bc 100644
--- a/api/mfx_dispatch/windows/libmfx_vs2015.vcxproj
+++ b/api/mfx_dispatch/windows/libmfx_vs2015.vcxproj
@@ -79,7 +79,7 @@
@@ -46,14 +46,14 @@
<RootNamespace>libmfx</RootNamespace>
<Keyword>Win32Proj</Keyword>
<ProjectName>libmfx_vs2015</ProjectName>
- <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<WholeProgramOptimization>false</WholeProgramOptimization>
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v141</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<SpectreMitigation>Spectre</SpectreMitigation>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -64,8 +64,8 @@
<WholeProgramOptimization>false</WholeProgramOptimization>
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v141</PlatformToolset>
- <SpectreMitigation>Spectre</SpectreMitigation>
+ <PlatformToolset>v143</PlatformToolset>
+ <SpectreMitigation>false</SpectreMitigation>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
@@ -73,17 +73,17 @@
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v141</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<SpectreMitigation>Spectre</SpectreMitigation>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<CharacterSet>Unicode</CharacterSet>
- <PlatformToolset>v141</PlatformToolset>
- <SpectreMitigation>Spectre</SpectreMitigation>
+ <PlatformToolset>v143</PlatformToolset>
+ <SpectreMitigation>false</SpectreMitigation>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<PropertyGroup>
@ -41,7 +61,7 @@ Subject: [PATCH] Copy build output to correct directory
<IntDir>$(OutDir)..\objs\$(ProjectName)\</IntDir>
<IncludePath>$(MINIDDK_ROOT)\Include\um;$(MINIDDK_ROOT)\Include\shared;$(IncludePath)</IncludePath>
<LibraryPath>$(MINIDDK_ROOT)\Lib\win8\um\x86;$(LibraryPath)</LibraryPath>
@@ -88,7 +88,7 @@
@@ -92,7 +92,7 @@
<TargetName>$(ProjectName)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
@ -50,7 +70,7 @@ Subject: [PATCH] Copy build output to correct directory
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
@@ -199,7 +199,7 @@
@@ -203,7 +203,7 @@
<AdditionalIncludeDirectories>include;..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN64;NDEBUG;_LIB;_ALLOW_MSC_VER_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_RUNTIME_LIBRARY_MISMATCH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
@ -59,31 +79,20 @@ Subject: [PATCH] Copy build output to correct directory
<BufferSecurityCheck>true</BufferSecurityCheck>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
@@ -208,6 +208,33 @@
@@ -212,6 +212,22 @@
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Lib />
+ <Lib>
+ <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
+ <AdditionalDependencies>Advapi32.lib</AdditionalDependencies>
+ </Lib>
+ <PostBuildEvent>
+ <Command>mkdir "$(OutDir)"..\..\..\..\..\..\msvc\include
+
+mkdir "$(OutDir)"..\..\..\..\..\..\msvc\include\mfx
+
+mkdir "$(OutDir)"..\..\..\..\..\..\msvc\lib
+
+mkdir "$(OutDir)"..\..\..\..\..\..\msvc\lib\x64
+
+xcopy /S /Y "$(OutDir)"*.lib "$(OutDir)"..\..\..\..\..\..\msvc\lib\x64
+
+
+
+
+xcopy /S /Y "$(OutDir)"*.pdb "$(OutDir)"..\..\..\..\..\..\msvc\lib\x64
+
+
+xcopy /S /Y $(ProjectDir)..\..\..\api\include\*.h "$(OutDir)"..\..\..\..\..\..\msvc\include\mfx
+</Command>
+ </PostBuildEvent>
@ -94,5 +103,5 @@ Subject: [PATCH] Copy build output to correct directory
<ItemGroup>
<ClCompile Include="src\main.cpp" />
--
2.22.0.windows.1
2.37.1.windows.1

View File

@ -1,6 +1,6 @@
{
"name": "x264",
"version": "5fee86cae91cd7b726db7408a3ed1c4da71fb78c",
"version": "be0cb5426d4b9fecaf2e4b058466322a43f17241",
"url": "https://github.com/ShiftMediaProject/x264/archive/__VERSION__.tar.gz",
"deps": [],
"patches": [],

View File

@ -111,8 +111,7 @@ void
AudioFrame::setFormat(const jami::AudioFormat& format)
{
auto d = pointer();
d->channels = format.nb_channels;
d->channel_layout = av_get_default_channel_layout(format.nb_channels);
av_channel_layout_default(&d->ch_layout, format.nb_channels);
d->sample_rate = format.sample_rate;
d->format = format.sampleFormat;
}
@ -121,7 +120,7 @@ jami::AudioFormat
AudioFrame::getFormat() const
{
return {(unsigned) frame_->sample_rate,
(unsigned) frame_->channels,
(unsigned) frame_->ch_layout.nb_channels,
(AVSampleFormat) frame_->format};
}
@ -149,7 +148,7 @@ AudioFrame::mix(const AudioFrame& frame)
{
auto& f = *pointer();
auto& fIn = *frame.pointer();
if (f.channels != fIn.channels || f.format != fIn.format || f.sample_rate != fIn.sample_rate) {
if (f.ch_layout.nb_channels != fIn.ch_layout.nb_channels || f.format != fIn.format || f.sample_rate != fIn.sample_rate) {
throw std::invalid_argument("Can't mix frames with different formats");
}
if (f.nb_samples == 0) {
@ -160,8 +159,8 @@ AudioFrame::mix(const AudioFrame& frame)
}
AVSampleFormat fmt = (AVSampleFormat) f.format;
bool isPlanar = av_sample_fmt_is_planar(fmt);
unsigned samplesPerChannel = isPlanar ? f.nb_samples : f.nb_samples * f.channels;
unsigned channels = isPlanar ? f.channels : 1;
unsigned samplesPerChannel = isPlanar ? f.nb_samples : f.nb_samples * f.ch_layout.nb_channels;
unsigned channels = isPlanar ? f.ch_layout.nb_channels : 1;
if (fmt == AV_SAMPLE_FMT_S16 || fmt == AV_SAMPLE_FMT_S16P) {
for (unsigned i = 0; i < channels; i++) {
auto c = (int16_t*) f.extended_data[i];
@ -192,8 +191,8 @@ AudioFrame::calcRMS() const
double rms = 0.0;
auto fmt = static_cast<AVSampleFormat>(frame_->format);
bool planar = av_sample_fmt_is_planar(fmt);
int perChannel = planar ? frame_->nb_samples : frame_->nb_samples * frame_->channels;
int channels = planar ? frame_->channels : 1;
int perChannel = planar ? frame_->nb_samples : frame_->nb_samples * frame_->ch_layout.nb_channels;
int channels = planar ? frame_->ch_layout.nb_channels : 1;
if (fmt == AV_SAMPLE_FMT_S16 || fmt == AV_SAMPLE_FMT_S16P) {
for (int c = 0; c < channels; ++c) {
auto buf = reinterpret_cast<int16_t*>(frame_->extended_data[c]);
@ -216,7 +215,7 @@ AudioFrame::calcRMS() const
return 0.0;
}
// divide by the number of multi-byte samples
return sqrt(rms / (frame_->nb_samples * frame_->channels));
return sqrt(rms / (frame_->nb_samples * frame_->ch_layout.nb_channels));
}
#ifdef ENABLE_VIDEO

View File

@ -123,9 +123,8 @@ public:
throw std::runtime_error("Failed to allocate audio codec context");
codec_ctx_->sample_fmt = (AVSampleFormat)frame->format;
codec_ctx_->channel_layout = frame->channel_layout;
codec_ctx_->ch_layout = frame->ch_layout;
codec_ctx_->sample_rate = frame->sample_rate;
codec_ctx_->channels = frame->channels;
if (format_ctx_->oformat->flags & AVFMT_GLOBALHEADER)
codec_ctx_->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

View File

@ -95,10 +95,10 @@ AudioFrameResizer::enqueue(std::shared_ptr<AudioFrame>&& frame)
int ret = 0;
auto f = frame->pointer();
AudioFormat format(f->sample_rate, f->channels, (AVSampleFormat) f->format);
AudioFormat format(f->sample_rate, f->ch_layout.nb_channels, (AVSampleFormat) f->format);
if (format != format_) {
JAMI_ERR() << "Expected " << format_ << ", but got "
<< AudioFormat(f->sample_rate, f->channels, (AVSampleFormat) f->format);
<< AudioFormat(f->sample_rate, f->ch_layout.nb_channels, (AVSampleFormat) f->format);
setFormat(format, frameSize_);
}

View File

@ -348,9 +348,9 @@ AudioBuffer::append(const AudioFrame& audioFrame)
{
auto frame = audioFrame.pointer();
// FIXME we assume frame is s16 interleaved
if (channels() != static_cast<unsigned>(frame->channels)
if (channels() != static_cast<unsigned>(frame->ch_layout.nb_channels)
|| getSampleRate() != frame->sample_rate) {
auto newFormat = AudioFormat {(unsigned) frame->sample_rate, (unsigned) frame->channels};
auto newFormat = AudioFormat {(unsigned) frame->sample_rate, (unsigned) frame->ch_layout.nb_channels};
setFormat(newFormat);
}

View File

@ -401,7 +401,7 @@ CoreLayer::write(AudioUnitRenderActionFlags* ioActionFlags,
if (auto toPlay = getPlayback(currentOutFormat, inNumberFrames)) {
const auto& frame = *toPlay->pointer();
for (unsigned i = 0; i < frame.channels; ++i) {
for (unsigned i = 0; i < frame.ch_layout.nb_channels; ++i) {
std::copy_n((Float32*)frame.extended_data[i], inNumberFrames, (Float32*)ioData->mBuffers[i].mData);
}
} else {

View File

@ -110,7 +110,7 @@ JackLayer::write(const AudioFrame& buffer)
{
auto num_samples = buffer.pointer()->nb_samples;
auto num_bytes = num_samples * sizeof(float);
auto channels = std::min<size_t>(out_ringbuffers_.size(), buffer.pointer()->channels);
auto channels = std::min<size_t>(out_ringbuffers_.size(), buffer.pointer()->ch_layout.nb_channels);
for (size_t i = 0; i < channels; ++i) {
jack_ringbuffer_write(out_ringbuffers_[i],
(const char*) buffer.pointer()->extended_data[i],

View File

@ -267,7 +267,7 @@ OpenSLLayer::engineServicePlay()
sample_buf* buf;
while (player_ and freePlayBufQueue_.front(&buf)) {
if (auto dat = getToPlay(hardwareFormat_, hardwareBuffSize_)) {
buf->size_ = dat->pointer()->nb_samples * dat->pointer()->channels
buf->size_ = dat->pointer()->nb_samples * dat->pointer()->ch_layout.nb_channels
* sizeof(AudioSample);
if (buf->size_ > buf->cap_) {
JAMI_ERR("buf->size_(%zu) > buf->cap_(%zu)", buf->size_, buf->cap_);
@ -300,7 +300,7 @@ OpenSLLayer::engineServiceRing()
sample_buf* buf;
while (ringtone_ and freeRingBufQueue_.front(&buf)) {
if (auto dat = getToRing(hardwareFormat_, hardwareBuffSize_)) {
buf->size_ = dat->pointer()->nb_samples * dat->pointer()->channels
buf->size_ = dat->pointer()->nb_samples * dat->pointer()->ch_layout.nb_channels
* sizeof(AudioSample);
if (buf->size_ > buf->cap_) {
JAMI_ERR("buf->size_(%zu) > buf->cap_(%zu)", buf->size_, buf->cap_);

View File

@ -736,7 +736,7 @@ PortAudioLayer::PortAudioLayerImpl::paOutputCallback(PortAudioLayer& parent,
return paContinue;
}
auto nFrames = toPlay->pointer()->nb_samples * toPlay->pointer()->channels;
auto nFrames = toPlay->pointer()->nb_samples * toPlay->pointer()->ch_layout.nb_channels;
std::copy_n((AudioSample*) toPlay->pointer()->extended_data[0], nFrames, outputBuffer);
return paContinue;
}

View File

@ -50,13 +50,11 @@ Resampler::reinit(const AVFrame* in, const AVFrame* out)
throw std::bad_alloc();
}
av_opt_set_int(swrCtx, "ich", in->channels, 0);
av_opt_set_int(swrCtx, "icl", in->channel_layout, 0);
av_opt_set_chlayout(swrCtx, "ichl", &in->ch_layout, 0);
av_opt_set_int(swrCtx, "isr", in->sample_rate, 0);
av_opt_set_sample_fmt(swrCtx, "isf", static_cast<AVSampleFormat>(in->format), 0);
av_opt_set_int(swrCtx, "och", out->channels, 0);
av_opt_set_int(swrCtx, "ocl", out->channel_layout, 0);
av_opt_set_chlayout(swrCtx, "ochl", &out->ch_layout, 0);
av_opt_set_int(swrCtx, "osr", out->sample_rate, 0);
av_opt_set_sample_fmt(swrCtx, "osf", static_cast<AVSampleFormat>(out->format), 0);
@ -71,10 +69,10 @@ Resampler::reinit(const AVFrame* in, const AVFrame* out)
* LFE downmixing is optional, so any coefficient can be used, we use +6dB for mono and
* +0dB in each channel for stereo.
*/
if (in->channel_layout == AV_CH_LAYOUT_5POINT1
|| in->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) {
if (in->ch_layout.u.mask == AV_CH_LAYOUT_5POINT1
|| in->ch_layout.u.mask == AV_CH_LAYOUT_5POINT1_BACK) {
// NOTE MSVC can't allocate dynamic size arrays on the stack
if (out->channels == 2) {
if (out->ch_layout.nb_channels == 2) {
double matrix[2][6];
// L = 1.0*FL + 0.707*FC + 0.707*BL + 1.0*LFE
matrix[0][0] = 1;
@ -152,8 +150,7 @@ Resampler::resample(const AudioBuffer& dataIn, AudioBuffer& dataOut)
AudioFrame resampled;
auto output = resampled.pointer();
output->sample_rate = dataOut.getSampleRate();
output->channel_layout = av_get_default_channel_layout(dataOut.channels());
output->channels = dataOut.channels();
av_channel_layout_default(&output->ch_layout, dataOut.channels());
output->format = AV_SAMPLE_FMT_S16;
if (resample(input, output) < 0)
@ -162,14 +159,14 @@ Resampler::resample(const AudioBuffer& dataIn, AudioBuffer& dataOut)
dataOut.resize(output->nb_samples);
dataOut.deinterleave(reinterpret_cast<const AudioSample*>(output->extended_data[0]),
output->nb_samples,
output->channels);
output->ch_layout.nb_channels);
}
std::unique_ptr<AudioFrame>
Resampler::resample(std::unique_ptr<AudioFrame>&& in, const AudioFormat& format)
{
if (in->pointer()->sample_rate == (int) format.sample_rate
&& in->pointer()->channels == (int) format.nb_channels
&& in->pointer()->ch_layout.nb_channels == (int) format.nb_channels
&& (AVSampleFormat) in->pointer()->format == format.sampleFormat) {
return std::move(in);
}
@ -191,7 +188,7 @@ Resampler::resample(std::shared_ptr<AudioFrame>&& in, const AudioFormat& format)
}
if (inPtr->sample_rate == (int) format.sample_rate
&& inPtr->channels == (int) format.nb_channels
&& inPtr->ch_layout.nb_channels == (int) format.nb_channels
&& (AVSampleFormat) inPtr->format == format.sampleFormat) {
return std::move(in);
}

View File

@ -47,7 +47,7 @@ public:
*
* Resample from @input format to @output format.
*
* NOTE: sample_rate, channel_layout, and format should be set on @output
* NOTE: sample_rate, ch_layout, and format should be set on @output
*/
int resample(const AVFrame* input, AVFrame* output);

View File

@ -267,7 +267,7 @@ fillWithSilence(AVFrame* frame)
int ret = av_samples_set_silence(frame->extended_data,
0,
frame->nb_samples,
frame->channels,
frame->ch_layout.nb_channels,
(AVSampleFormat) frame->format);
if (ret < 0)
JAMI_ERR() << "Failed to fill frame with silence";

View File

@ -595,8 +595,6 @@ MediaDecoder::prepareDecoderContext()
if (avStream_->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
if (decoderCtx_->framerate.num == 0 || decoderCtx_->framerate.den == 0)
decoderCtx_->framerate = inputParams_.framerate;
if (decoderCtx_->framerate.num == 0 || decoderCtx_->framerate.den == 0)
decoderCtx_->framerate = av_inv_q(decoderCtx_->time_base);
if (decoderCtx_->framerate.num == 0 || decoderCtx_->framerate.den == 0)
decoderCtx_->framerate = {30, 1};
}
@ -643,6 +641,15 @@ MediaDecoder::decode(AVPacket& packet)
#endif
auto frame = f->pointer();
ret = avcodec_receive_frame(decoderCtx_, frame);
// time_base is not set in AVCodecContext for decoding
// fail to set it causes pts to be incorrectly computed down in the function
if (inputDecoder_->type == AVMEDIA_TYPE_VIDEO) {
decoderCtx_->time_base.num = decoderCtx_->framerate.den;
decoderCtx_->time_base.den = decoderCtx_->framerate.num;
} else {
decoderCtx_->time_base.num = 1;
decoderCtx_->time_base.den = decoderCtx_->sample_rate;
}
frame->time_base = decoderCtx_->time_base;
if (resolutionChangedCallback_) {
if (decoderCtx_->width != width_ or decoderCtx_->height != height_) {
@ -663,10 +670,7 @@ MediaDecoder::decode(AVPacket& packet)
frameFinished = 1;
if (frameFinished) {
// channel layout is needed if frame will be resampled
if (!frame->channel_layout)
frame->channel_layout = av_get_default_channel_layout(frame->channels);
if (inputDecoder_->type == AVMEDIA_TYPE_VIDEO)
frame->format = (AVPixelFormat) correctPixFmt(frame->format);
auto packetTimestamp = frame->pts; // in stream time base
frame->pts = av_rescale_q_rnd(av_gettime() - startTime_,

View File

@ -641,14 +641,11 @@ MediaEncoder::prepareEncoderContext(const AVCodec* outputCodec, bool is_video)
encoderCtx->sample_rate = std::max(8000, audioOpts_.sampleRate);
encoderCtx->time_base = AVRational {1, encoderCtx->sample_rate};
if (audioOpts_.nbChannels > 2 || audioOpts_.nbChannels < 1) {
encoderCtx->channels = std::clamp(audioOpts_.nbChannels, 1, 2);
audioOpts_.nbChannels = std::clamp(audioOpts_.nbChannels, 1, 2);
JAMI_ERR() << "[" << encoderName
<< "] Clamping invalid channel count: " << audioOpts_.nbChannels << " -> "
<< encoderCtx->channels;
} else {
encoderCtx->channels = audioOpts_.nbChannels;
<< "] Clamping invalid channel count: " << audioOpts_.nbChannels;
}
encoderCtx->channel_layout = av_get_default_channel_layout(encoderCtx->channels);
av_channel_layout_default(&encoderCtx->ch_layout, audioOpts_.nbChannels);
if (audioOpts_.frameSize) {
encoderCtx->frame_size = audioOpts_.frameSize;
JAMI_DBG() << "[" << encoderName << "] Frame size " << encoderCtx->frame_size;

View File

@ -171,7 +171,7 @@ MediaFilter::feedInput(AVFrame* frame, const std::string& inputName)
if (ms.format != frame->format
|| (ms.isVideo && (ms.width != frame->width || ms.height != frame->height))
|| (!ms.isVideo
&& (ms.sampleRate != frame->sample_rate || ms.nbChannels != frame->channels))) {
&& (ms.sampleRate != frame->sample_rate || ms.nbChannels != frame->ch_layout.nb_channels))) {
ms.update(frame);
if ((ret = reinitialize()) < 0)
return fail("Failed to reinitialize filter with new input parameters", ret);
@ -283,7 +283,7 @@ MediaFilter::initInputFilter(AVFilterInOut* in, const MediaStream& msp)
buffersrc = avfilter_get_by_name("buffer");
} else {
params->sample_rate = msp.sampleRate;
params->channel_layout = av_get_default_channel_layout(msp.nbChannels);
av_channel_layout_default(&params->ch_layout, msp.nbChannels);
buffersrc = avfilter_get_by_name("abuffer");
}

View File

@ -576,7 +576,7 @@ std::string
MediaRecorder::buildAudioFilter(const std::vector<MediaStream>& peers,
const MediaStream& local) const
{
std::string baseFilter = "aresample=osr=48000:ocl=stereo:osf=s16";
std::string baseFilter = "aresample=osr=48000:ochl=stereo:osf=s16";
std::stringstream a;
switch (peers.size()) {

View File

@ -112,7 +112,7 @@ struct MediaStream
format = c->sample_fmt;
isVideo = false;
sampleRate = c->sample_rate;
nbChannels = c->channels;
nbChannels = c->ch_layout.nb_channels;
frameSize = c->frame_size;
break;
default:
@ -144,7 +144,7 @@ struct MediaStream
height = f->height;
} else {
sampleRate = f->sample_rate;
nbChannels = f->channels;
nbChannels = f->ch_layout.nb_channels;
timeBase = rational<int>(1, f->sample_rate);
if (!frameSize)
frameSize = f->nb_samples;

View File

@ -313,7 +313,6 @@ HardwareAccel::setDetails(AVCodecContext* codecCtx)
if (type_ == CODEC_DECODER) {
codecCtx->hw_device_ctx = av_buffer_ref(deviceCtx_);
codecCtx->get_format = getFormatCb;
codecCtx->thread_safe_callbacks = 1;
} else if (type_ == CODEC_ENCODER) {
if (framesCtx_)
// encoder doesn't need a device context, only a frame context

View File

@ -74,8 +74,7 @@ AudioFrameResizerTest::getFrame(int n)
auto frame = std::make_shared<AudioFrame>();
frame->pointer()->format = format_.sampleFormat;
frame->pointer()->sample_rate = format_.sample_rate;
frame->pointer()->channels = format_.nb_channels;
frame->pointer()->channel_layout = av_get_default_channel_layout(format_.nb_channels);
av_channel_layout_default(&frame->pointer()->ch_layout, format_.nb_channels);
frame->pointer()->nb_samples = n;
CPPUNIT_ASSERT(av_frame_get_buffer(frame->pointer(), 0) >= 0);
return frame;

View File

@ -98,8 +98,7 @@ ResamplerTest::testAudioFrame()
auto output = out.pointer();
output->format = AV_SAMPLE_FMT_FLT;
output->sample_rate = 48000;
output->channel_layout = AV_CH_LAYOUT_STEREO;
output->channels = 2;
av_channel_layout_from_mask(&output->ch_layout, AV_CH_LAYOUT_STEREO);
int ret = resampler_->resample(input->pointer(), output);
CPPUNIT_ASSERT_MESSAGE(libav_utils::getError(ret).c_str(), ret >= 0);

View File

@ -81,7 +81,7 @@ MediaDecoderTest::testAudioFile()
decoder_.reset(new MediaDecoder([this](const std::shared_ptr<MediaFrame>&& f) mutable {
CPPUNIT_ASSERT(f->pointer()->sample_rate == decoder_->getStream().sampleRate);
CPPUNIT_ASSERT(f->pointer()->channels == decoder_->getStream().nbChannels);
CPPUNIT_ASSERT(f->pointer()->ch_layout.nb_channels == decoder_->getStream().nbChannels);
}));
DeviceParams dev;
dev.input = filename_;

View File

@ -115,8 +115,7 @@ getAudioFrame(int sampleRate, int nbSamples, int nbChannels)
return nullptr;
frame->format = AV_SAMPLE_FMT_S16;
frame->channels = nbChannels;
frame->channel_layout = av_get_default_channel_layout(nbChannels);
av_channel_layout_default(&frame->ch_layout, nbChannels);
frame->nb_samples = nbSamples;
frame->sample_rate = sampleRate;

View File

@ -116,13 +116,12 @@ static void
fillAudioFrameProps(AVFrame* frame, const MediaStream& ms)
{
frame->format = ms.format;
frame->channel_layout = av_get_default_channel_layout(ms.nbChannels);
av_channel_layout_default(&frame->ch_layout, ms.nbChannels);
frame->nb_samples = ms.frameSize;
frame->sample_rate = ms.sampleRate;
frame->channels = ms.nbChannels;
CPPUNIT_ASSERT(frame->format > AV_SAMPLE_FMT_NONE);
CPPUNIT_ASSERT(frame->nb_samples > 0);
CPPUNIT_ASSERT(frame->channel_layout != 0);
CPPUNIT_ASSERT(frame->ch_layout.u.mask != 0);
}
void
@ -132,7 +131,6 @@ MediaFilterTest::testAudioFilter()
// constants
const constexpr int nbSamples = 100;
const constexpr int64_t channelLayout = AV_CH_LAYOUT_STEREO;
const constexpr int sampleRate = 44100;
const constexpr enum AVSampleFormat format = AV_SAMPLE_FMT_S16;
@ -140,17 +138,16 @@ MediaFilterTest::testAudioFilter()
AudioFrame af;
auto frame = af.pointer();
frame->format = format;
frame->channel_layout = channelLayout;
av_channel_layout_from_mask(&frame->ch_layout, AV_CH_LAYOUT_STEREO);
frame->nb_samples = nbSamples;
frame->sample_rate = sampleRate;
frame->channels = av_get_channel_layout_nb_channels(channelLayout);
// construct the filter parameters
auto params = MediaStream("in1", format, rational<int>(1, sampleRate), sampleRate, frame->channels, nbSamples);
auto params = MediaStream("in1", format, rational<int>(1, sampleRate), sampleRate, frame->ch_layout.nb_channels, nbSamples);
// allocate and fill frame buffers
CPPUNIT_ASSERT(av_frame_get_buffer(frame, 0) >= 0);
fill_samples(reinterpret_cast<uint16_t*>(frame->data[0]), sampleRate, nbSamples, frame->channels, 440.0);
fill_samples(reinterpret_cast<uint16_t*>(frame->data[0]), sampleRate, nbSamples, frame->ch_layout.nb_channels, 440.0);
// prepare filter
std::vector<MediaStream> vec;
@ -190,17 +187,17 @@ MediaFilterTest::testAudioMixing()
fillAudioFrameProps(frame1, vec[0]);
frame1->pts = i * frame1->nb_samples;
CPPUNIT_ASSERT(av_frame_get_buffer(frame1, 0) >= 0);
fill_samples(reinterpret_cast<uint16_t*>(frame1->data[0]), frame1->sample_rate, frame1->nb_samples, frame1->channels, 440.0, t1);
fill_samples(reinterpret_cast<uint16_t*>(frame1->data[0]), frame1->sample_rate, frame1->nb_samples, frame1->ch_layout.nb_channels, 440.0, t1);
fillAudioFrameProps(frame2, vec[1]);
frame2->pts = i * frame2->nb_samples;
CPPUNIT_ASSERT(av_frame_get_buffer(frame2, 0) >= 0);
fill_samples(reinterpret_cast<uint16_t*>(frame2->data[0]), frame2->sample_rate, frame2->nb_samples, frame2->channels, 329.6276, t2);
fill_samples(reinterpret_cast<uint16_t*>(frame2->data[0]), frame2->sample_rate, frame2->nb_samples, frame2->ch_layout.nb_channels, 329.6276, t2);
fillAudioFrameProps(frame3, vec[2]);
frame3->pts = i * frame3->nb_samples;
CPPUNIT_ASSERT(av_frame_get_buffer(frame3, 0) >= 0);
fill_samples(reinterpret_cast<uint16_t*>(frame3->data[0]), frame3->sample_rate, frame3->nb_samples, frame3->channels, 349.2282, t3);
fill_samples(reinterpret_cast<uint16_t*>(frame3->data[0]), frame3->sample_rate, frame3->nb_samples, frame3->ch_layout.nb_channels, 349.2282, t3);
// apply filter
CPPUNIT_ASSERT(filter_->feedInput(frame1, "a1") >= 0);
@ -318,17 +315,16 @@ MediaFilterTest::testReinit()
AudioFrame af;
auto frame = af.pointer();
frame->format = AV_SAMPLE_FMT_S16;
frame->channel_layout = AV_CH_LAYOUT_STEREO;
av_channel_layout_from_mask(&frame->ch_layout, AV_CH_LAYOUT_STEREO);
frame->nb_samples = 100;
frame->sample_rate = 44100;
frame->channels = 2;
// construct the filter parameters with different sample rate
auto params = MediaStream("in1", frame->format, rational<int>(1, 16000), 16000, frame->channels, frame->nb_samples);
auto params = MediaStream("in1", frame->format, rational<int>(1, 16000), 16000, frame->ch_layout.nb_channels, frame->nb_samples);
// allocate and fill frame buffers
CPPUNIT_ASSERT(av_frame_get_buffer(frame, 0) >= 0);
fill_samples(reinterpret_cast<uint16_t*>(frame->data[0]), frame->sample_rate, frame->nb_samples, frame->channels, 440.0);
fill_samples(reinterpret_cast<uint16_t*>(frame->data[0]), frame->sample_rate, frame->nb_samples, frame->ch_layout.nb_channels, 440.0);
// prepare filter
std::vector<MediaStream> vec;