View | Details | Raw Unified | Return to bug 270237 | Differences between
and this patch

Collapse All | Expand All

(-)cmake/modules/FindFFMPEG.cmake (-8 / +8 lines)
Lines 151-164 Link Here
151
  set(REQUIRED_FFMPEG_VERSION undef)
151
  set(REQUIRED_FFMPEG_VERSION undef)
152
else()
152
else()
153
  # required ffmpeg library versions
153
  # required ffmpeg library versions
154
  set(REQUIRED_FFMPEG_VERSION 4.4.1)
154
  set(REQUIRED_FFMPEG_VERSION 6.0.0)
155
  set(_avcodec_ver ">=58.134.100")
155
  set(_avcodec_ver ">=60.2.100")
156
  set(_avfilter_ver ">=7.110.100")
156
  set(_avfilter_ver ">=9.3.100")
157
  set(_avformat_ver ">=58.76.100")
157
  set(_avformat_ver ">=60.3.100")
158
  set(_avutil_ver ">=56.70.100")
158
  set(_avutil_ver ">=58.2.100")
159
  set(_postproc_ver ">=55.9.100")
159
  set(_postproc_ver ">=57.1.100")
160
  set(_swresample_ver ">=3.9.100")
160
  set(_swresample_ver ">=4.10.100")
161
  set(_swscale_ver ">=5.9.100")
161
  set(_swscale_ver ">=7.1.100")
162
endif()
162
endif()
163
163
164
# Allows building with external ffmpeg not found in system paths,
164
# Allows building with external ffmpeg not found in system paths,
(-)tools/buildsteps/windows/patches/0001-ffmpeg-windows-configure-detect-openssl.patch (-1 / +1 lines)
Lines 11-17 Link Here
11
index d7a3f507e8..4b85e881b1 100755
11
index d7a3f507e8..4b85e881b1 100755
12
--- a/configure
12
--- a/configure
13
+++ b/configure
13
+++ b/configure
14
@@ -6530,6 +6530,8 @@ enabled openssl           && { check_pkg_config openssl openssl openssl/ssl.h OP
14
@@ -6728,6 +6728,8 @@ enabled openssl           && { check_pkg_config openssl openssl openssl/ssl.h OP
15
                                check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto ||
15
                                check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto ||
16
                                check_lib openssl openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
16
                                check_lib openssl openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
17
                                check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
17
                                check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
(-)tools/buildsteps/windows/patches/0002-ffmpeg-windows-configure-fix-zlib-conflict.patch (-3 / +3 lines)
Lines 11-26 Link Here
11
index 4b85e881b1..da457705d1 100755
11
index 4b85e881b1..da457705d1 100755
12
--- a/configure
12
--- a/configure
13
+++ b/configure
13
+++ b/configure
14
@@ -7627,6 +7627,9 @@ print_config CONFIG_ "$config_files" $CONFIG_LIST       \
14
@@ -7825,6 +7825,9 @@ print_config CONFIG_ "$config_files" $CONFIG_LIST       \
15
 print_config CONFIG_ "$config_files" $CONFIG_LIST       \
15
                                      $CONFIG_EXTRA      \
16
                                      $CONFIG_EXTRA      \
16
                                      $ALL_COMPONENTS    \
17
 
17
 
18
+echo "#if defined(HAVE_UNISTD_H) && HAVE_UNISTD_H == 0" >> $TMPH
18
+echo "#if defined(HAVE_UNISTD_H) && HAVE_UNISTD_H == 0" >> $TMPH
19
+echo "#undef HAVE_UNISTD_H" >> $TMPH
19
+echo "#undef HAVE_UNISTD_H" >> $TMPH
20
+echo "#endif" >> $TMPH
20
+echo "#endif" >> $TMPH
21
 echo "#endif /* FFMPEG_CONFIG_H */" >> $TMPH
21
 echo "#endif /* FFMPEG_CONFIG_H */" >> $TMPH
22
 echo "endif # FFMPEG_CONFIG_MAK" >> ffbuild/config.mak
23
 
22
 
23
 # Do not overwrite an unchanged config.h to avoid superfluous rebuilds.
24
-- 
24
-- 
25
2.29.2
25
2.29.2
26
26
(-)tools/buildsteps/windows/patches/0003-ffmpeg-windows-configure-allow-building-static.patch (-2 / +2 lines)
Lines 11-17 Link Here
11
index da457705d1..e3a8f45ff4 100755
11
index da457705d1..e3a8f45ff4 100755
12
--- a/configure
12
--- a/configure
13
+++ b/configure
13
+++ b/configure
14
@@ -5440,6 +5440,8 @@ case $target_os in
14
@@ -5566,6 +5566,8 @@ case $target_os in
15
         enabled shared && ! enabled small && test_cmd $windres --version && enable gnu_windres
15
         enabled shared && ! enabled small && test_cmd $windres --version && enable gnu_windres
16
         enabled x86_32 && check_ldflags -Wl,--large-address-aware
16
         enabled x86_32 && check_ldflags -Wl,--large-address-aware
17
         shlibdir_default="$bindir_default"
17
         shlibdir_default="$bindir_default"
Lines 20-26 Link Here
20
         SLIBPREF=""
20
         SLIBPREF=""
21
         SLIBSUF=".dll"
21
         SLIBSUF=".dll"
22
         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
22
         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
23
@@ -5489,6 +5491,8 @@ case $target_os in
23
@@ -5615,6 +5617,8 @@ case $target_os in
24
         fi
24
         fi
25
         enabled x86_32 && check_ldflags -LARGEADDRESSAWARE
25
         enabled x86_32 && check_ldflags -LARGEADDRESSAWARE
26
         shlibdir_default="$bindir_default"
26
         shlibdir_default="$bindir_default"
(-)tools/buildsteps/windows/patches/0004-ffmpeg-windows-configure-detect-libdav1d.patch (-1 / +1 lines)
Lines 11-17 Link Here
11
index e3a8f45ff4..983d7e1078 100755
11
index e3a8f45ff4..983d7e1078 100755
12
--- a/configure
12
--- a/configure
13
+++ b/configure
13
+++ b/configure
14
@@ -6358,7 +6358,7 @@ enabled libcelt           && require libcelt celt/celt.h celt_decode -lcelt0 &&
14
@@ -6541,7 +6541,7 @@ enabled libcelt           && require libcelt celt/celt.h celt_decode -lcelt0 &&
15
                                die "ERROR: libcelt must be installed and version must be >= 0.11.0."; }
15
                                die "ERROR: libcelt must be installed and version must be >= 0.11.0."; }
16
 enabled libcaca           && require_pkg_config libcaca caca caca.h caca_create_canvas
16
 enabled libcaca           && require_pkg_config libcaca caca caca.h caca_create_canvas
17
 enabled libcodec2         && require libcodec2 codec2/codec2.h codec2_create -lcodec2
17
 enabled libcodec2         && require libcodec2 codec2/codec2.h codec2_create -lcodec2
(-)tools/depends/target/ffmpeg/CMakeLists.txt (+1 lines)
Lines 92-97 Link Here
92
elseif(CORE_SYSTEM_NAME STREQUAL darwin_embedded)
92
elseif(CORE_SYSTEM_NAME STREQUAL darwin_embedded)
93
  list(APPEND ffmpeg_conf --disable-crystalhd
93
  list(APPEND ffmpeg_conf --disable-crystalhd
94
                          --enable-videotoolbox
94
                          --enable-videotoolbox
95
                          --disable-filter=yadif_videotoolbox
95
                          --target-os=darwin
96
                          --target-os=darwin
96
              )
97
              )
97
elseif(CORE_SYSTEM_NAME STREQUAL osx)
98
elseif(CORE_SYSTEM_NAME STREQUAL osx)
(-)tools/depends/target/ffmpeg/FFMPEG-VERSION (-3 / +3 lines)
Lines 1-5 Link Here
1
LIBNAME=ffmpeg
1
LIBNAME=ffmpeg
2
BASE_URL=https://github.com/xbmc/FFmpeg
2
VERSION=6.0
3
VERSION=4.4.1-Nexus-Alpha1
4
ARCHIVE=$(LIBNAME)-$(VERSION).tar.gz
3
ARCHIVE=$(LIBNAME)-$(VERSION).tar.gz
5
SHA512=8beb04d577b5251e74b0d52f4d130997a8ba94bbd488c7c8309e6b45095c27807e150212888ce3a384b23dff52f8df1a7bde5407bae924ddc363f8125c0616c5
4
SHA512=b3214328f2792364353f38c6b46a71d4970c071d8656b20780abf0e02950167d0933eae825c09102cf8fb19fc679ac444bf1f41a448b624eaa5ea6b0f0bdf4f5
5
(-)xbmc/cdrip/EncoderFFmpeg.cpp (-66 / +53 lines)
Lines 11-16 Link Here
11
#include "ServiceBroker.h"
11
#include "ServiceBroker.h"
12
#include "addons/Addon.h"
12
#include "addons/Addon.h"
13
#include "addons/AddonManager.h"
13
#include "addons/AddonManager.h"
14
#include "cores/FFmpeg.h"
14
#include "settings/Settings.h"
15
#include "settings/Settings.h"
15
#include "settings/SettingsComponent.h"
16
#include "settings/SettingsComponent.h"
16
#include "utils/StringUtils.h"
17
#include "utils/StringUtils.h"
Lines 19-42 Link Here
19
#include "utils/log.h"
20
#include "utils/log.h"
20
21
21
using namespace KODI::CDRIP;
22
using namespace KODI::CDRIP;
23
using FFMPEG_HELP_TOOLS::FFMpegErrorToString;
24
using FFMPEG_HELP_TOOLS::FFMpegException;
22
25
23
namespace
24
{
25
26
struct EncoderException : public std::exception
27
{
28
  std::string s;
29
  template<typename... Args>
30
  EncoderException(const std::string& fmt, Args&&... args)
31
    : s(StringUtils::Format(fmt, std::forward<Args>(args)...))
32
  {
33
  }
34
  ~EncoderException() throw() {} // Updated
35
  const char* what() const throw() { return s.c_str(); }
36
};
37
38
} /* namespace */
39
40
bool CEncoderFFmpeg::Init()
26
bool CEncoderFFmpeg::Init()
41
{
27
{
42
  try
28
  try
Lines 54-60 Link Here
54
    }
40
    }
55
    else
41
    else
56
    {
42
    {
57
      throw EncoderException("Could not get add-on: {}", addonId);
43
      throw FFMpegException("Could not get add-on: {}", addonId);
58
    }
44
    }
59
45
60
    // Hack fix about PTS on generated files.
46
    // Hack fix about PTS on generated files.
Lines 66-115 Link Here
66
    else if (addonId == "audioencoder.kodi.builtin.wma")
52
    else if (addonId == "audioencoder.kodi.builtin.wma")
67
      m_samplesCountMultiply = 1000;
53
      m_samplesCountMultiply = 1000;
68
    else
54
    else
69
      throw EncoderException("Internal add-on id \"{}\" not known as usable", addonId);
55
      throw FFMpegException("Internal add-on id \"{}\" not known as usable", addonId);
70
56
71
    const std::string filename = URIUtils::GetFileName(m_strFile);
57
    const std::string filename = URIUtils::GetFileName(m_strFile);
72
58
73
    m_formatCtx = avformat_alloc_context();
59
    m_formatCtx = avformat_alloc_context();
74
    if (!m_formatCtx)
60
    if (!m_formatCtx)
75
      throw EncoderException("Could not allocate output format context");
61
      throw FFMpegException("Could not allocate output format context");
76
62
77
    m_bcBuffer = static_cast<uint8_t*>(av_malloc(BUFFER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE));
63
    m_bcBuffer = static_cast<uint8_t*>(av_malloc(BUFFER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE));
78
    if (!m_bcBuffer)
64
    if (!m_bcBuffer)
79
      throw EncoderException("Could not allocate buffer");
65
      throw FFMpegException("Could not allocate buffer");
80
66
81
    m_formatCtx->pb = avio_alloc_context(m_bcBuffer, BUFFER_SIZE, AVIO_FLAG_WRITE, this, nullptr,
67
    m_formatCtx->pb = avio_alloc_context(m_bcBuffer, BUFFER_SIZE, AVIO_FLAG_WRITE, this, nullptr,
82
                                         avio_write_callback, avio_seek_callback);
68
                                         avio_write_callback, avio_seek_callback);
83
    if (!m_formatCtx->pb)
69
    if (!m_formatCtx->pb)
84
      throw EncoderException("Failed to allocate ByteIOContext");
70
      throw FFMpegException("Failed to allocate ByteIOContext");
85
71
86
    /* Guess the desired container format based on the file extension. */
72
    /* Guess the desired container format based on the file extension. */
87
    m_formatCtx->oformat = av_guess_format(nullptr, filename.c_str(), nullptr);
73
    m_formatCtx->oformat = av_guess_format(nullptr, filename.c_str(), nullptr);
88
    if (!m_formatCtx->oformat)
74
    if (!m_formatCtx->oformat)
89
      throw EncoderException("Could not find output file format");
75
      throw FFMpegException("Could not find output file format");
90
76
91
    m_formatCtx->url = av_strdup(filename.c_str());
77
    m_formatCtx->url = av_strdup(filename.c_str());
92
    if (!m_formatCtx->url)
78
    if (!m_formatCtx->url)
93
      throw EncoderException("Could not allocate url");
79
      throw FFMpegException("Could not allocate url");
94
80
95
    /* Find the encoder to be used by its name. */
81
    /* Find the encoder to be used by its name. */
96
    AVCodec* codec = avcodec_find_encoder(m_formatCtx->oformat->audio_codec);
82
    const AVCodec* codec = avcodec_find_encoder(m_formatCtx->oformat->audio_codec);
97
    if (!codec)
83
    if (!codec)
98
      throw EncoderException("Unable to find a suitable FFmpeg encoder");
84
      throw FFMpegException("Unable to find a suitable FFmpeg encoder");
99
85
100
    /* Create a new audio stream in the output file container. */
86
    /* Create a new audio stream in the output file container. */
101
    m_stream = avformat_new_stream(m_formatCtx, nullptr);
87
    m_stream = avformat_new_stream(m_formatCtx, nullptr);
102
    if (!m_stream)
88
    if (!m_stream)
103
      throw EncoderException("Failed to allocate AVStream context");
89
      throw FFMpegException("Failed to allocate AVStream context");
104
90
105
    m_codecCtx = avcodec_alloc_context3(codec);
91
    m_codecCtx = avcodec_alloc_context3(codec);
106
    if (!m_codecCtx)
92
    if (!m_codecCtx)
107
      throw EncoderException("Failed to allocate the encoder context");
93
      throw FFMpegException("Failed to allocate the encoder context");
108
94
109
    /* Set the basic encoder parameters.
95
    /* Set the basic encoder parameters.
110
     * The input file's sample rate is used to avoid a sample rate conversion. */
96
     * The input file's sample rate is used to avoid a sample rate conversion. */
111
    m_codecCtx->channels = m_iInChannels;
97
    av_channel_layout_uninit(&m_codecCtx->ch_layout);
112
    m_codecCtx->channel_layout = av_get_default_channel_layout(m_iInChannels);
98
    av_channel_layout_default(&m_codecCtx->ch_layout, m_iInChannels);
113
    m_codecCtx->sample_rate = m_iInSampleRate;
99
    m_codecCtx->sample_rate = m_iInSampleRate;
114
    m_codecCtx->sample_fmt = codec->sample_fmts[0];
100
    m_codecCtx->sample_fmt = codec->sample_fmts[0];
115
    m_codecCtx->bit_rate = bitrate;
101
    m_codecCtx->bit_rate = bitrate;
Lines 128-141 Link Here
128
114
129
    int err = avcodec_open2(m_codecCtx, codec, nullptr);
115
    int err = avcodec_open2(m_codecCtx, codec, nullptr);
130
    if (err < 0)
116
    if (err < 0)
131
      throw EncoderException("Failed to open the codec {} (error '{}')",
117
      throw FFMpegException("Failed to open the codec {} (error '{}')",
132
                             codec->long_name ? codec->long_name : codec->name,
118
                            codec->long_name ? codec->long_name : codec->name,
133
                             FFmpegErrorToString(err));
119
                            FFMpegErrorToString(err));
134
120
135
    err = avcodec_parameters_from_context(m_stream->codecpar, m_codecCtx);
121
    err = avcodec_parameters_from_context(m_stream->codecpar, m_codecCtx);
136
    if (err < 0)
122
    if (err < 0)
137
      throw EncoderException("Failed to copy encoder parameters to output stream (error '{}')",
123
      throw FFMpegException("Failed to copy encoder parameters to output stream (error '{}')",
138
                             FFmpegErrorToString(err));
124
                            FFMpegErrorToString(err));
139
125
140
    m_inFormat = GetInputFormat(m_iInBitsPerSample);
126
    m_inFormat = GetInputFormat(m_iInBitsPerSample);
141
    m_outFormat = m_codecCtx->sample_fmt;
127
    m_outFormat = m_codecCtx->sample_fmt;
Lines 150-193 Link Here
150
136
151
    m_bufferFrame = av_frame_alloc();
137
    m_bufferFrame = av_frame_alloc();
152
    if (!m_bufferFrame || !m_buffer)
138
    if (!m_bufferFrame || !m_buffer)
153
      throw EncoderException("Failed to allocate necessary buffers");
139
      throw FFMpegException("Failed to allocate necessary buffers");
154
140
155
    m_bufferFrame->nb_samples = m_codecCtx->frame_size;
141
    m_bufferFrame->nb_samples = m_codecCtx->frame_size;
156
    m_bufferFrame->format = m_inFormat;
142
    m_bufferFrame->format = m_inFormat;
157
    m_bufferFrame->channel_layout = m_codecCtx->channel_layout;
143
144
    av_channel_layout_uninit(&m_bufferFrame->ch_layout);
145
    av_channel_layout_copy(&m_bufferFrame->ch_layout, &m_codecCtx->ch_layout);
146
158
    m_bufferFrame->sample_rate = m_codecCtx->sample_rate;
147
    m_bufferFrame->sample_rate = m_codecCtx->sample_rate;
159
148
160
    err = av_frame_get_buffer(m_bufferFrame, 0);
149
    err = av_frame_get_buffer(m_bufferFrame, 0);
161
    if (err < 0)
150
    if (err < 0)
162
      throw EncoderException("Could not allocate output frame samples (error '{}')",
151
      throw FFMpegException("Could not allocate output frame samples (error '{}')",
163
                             FFmpegErrorToString(err));
152
                            FFMpegErrorToString(err));
164
153
165
    avcodec_fill_audio_frame(m_bufferFrame, m_iInChannels, m_inFormat, m_buffer, m_neededBytes, 0);
154
    avcodec_fill_audio_frame(m_bufferFrame, m_iInChannels, m_inFormat, m_buffer, m_neededBytes, 0);
166
155
167
    if (m_needConversion)
156
    if (m_needConversion)
168
    {
157
    {
169
      m_swrCtx = swr_alloc_set_opts(nullptr, m_codecCtx->channel_layout, m_outFormat,
158
      int ret = swr_alloc_set_opts2(&m_swrCtx, &m_codecCtx->ch_layout, m_outFormat,
170
                                    m_codecCtx->sample_rate, m_codecCtx->channel_layout, m_inFormat,
159
                                    m_codecCtx->sample_rate, &m_codecCtx->ch_layout, m_inFormat,
171
                                    m_codecCtx->sample_rate, 0, nullptr);
160
                                    m_codecCtx->sample_rate, 0, nullptr);
172
      if (!m_swrCtx || swr_init(m_swrCtx) < 0)
161
      if (ret || swr_init(m_swrCtx) < 0)
173
        throw EncoderException("Failed to initialize the resampler");
162
        throw FFMpegException("Failed to initialize the resampler");
174
163
175
      m_resampledBufferSize =
164
      m_resampledBufferSize =
176
          av_samples_get_buffer_size(nullptr, m_iInChannels, m_neededFrames, m_outFormat, 0);
165
          av_samples_get_buffer_size(nullptr, m_iInChannels, m_neededFrames, m_outFormat, 0);
177
      m_resampledBuffer = static_cast<uint8_t*>(av_malloc(m_resampledBufferSize));
166
      m_resampledBuffer = static_cast<uint8_t*>(av_malloc(m_resampledBufferSize));
178
      m_resampledFrame = av_frame_alloc();
167
      m_resampledFrame = av_frame_alloc();
179
      if (!m_resampledBuffer || !m_resampledFrame)
168
      if (!m_resampledBuffer || !m_resampledFrame)
180
        throw EncoderException("Failed to allocate a frame for resampling");
169
        throw FFMpegException("Failed to allocate a frame for resampling");
181
170
182
      m_resampledFrame->nb_samples = m_neededFrames;
171
      m_resampledFrame->nb_samples = m_neededFrames;
183
      m_resampledFrame->format = m_outFormat;
172
      m_resampledFrame->format = m_outFormat;
184
      m_resampledFrame->channel_layout = m_codecCtx->channel_layout;
173
      av_channel_layout_uninit(&m_resampledFrame->ch_layout);
174
      av_channel_layout_copy(&m_resampledFrame->ch_layout, &m_codecCtx->ch_layout);
185
      m_resampledFrame->sample_rate = m_codecCtx->sample_rate;
175
      m_resampledFrame->sample_rate = m_codecCtx->sample_rate;
186
176
187
      err = av_frame_get_buffer(m_resampledFrame, 0);
177
      err = av_frame_get_buffer(m_resampledFrame, 0);
188
      if (err < 0)
178
      if (err < 0)
189
        throw EncoderException("Could not allocate output resample frame samples (error '{}')",
179
        throw FFMpegException("Could not allocate output resample frame samples (error '{}')",
190
                               FFmpegErrorToString(err));
180
                              FFMpegErrorToString(err));
191
181
192
      avcodec_fill_audio_frame(m_resampledFrame, m_iInChannels, m_outFormat, m_resampledBuffer,
182
      avcodec_fill_audio_frame(m_resampledFrame, m_iInChannels, m_outFormat, m_resampledBuffer,
193
                               m_resampledBufferSize, 0);
183
                               m_resampledBufferSize, 0);
Lines 204-210 Link Here
204
    /* write the header */
194
    /* write the header */
205
    err = avformat_write_header(m_formatCtx, nullptr);
195
    err = avformat_write_header(m_formatCtx, nullptr);
206
    if (err != 0)
196
    if (err != 0)
207
      throw EncoderException("Failed to write the header (error '{}')", FFmpegErrorToString(err));
197
      throw FFMpegException("Failed to write the header (error '{}')", FFMpegErrorToString(err));
208
198
209
    CLog::Log(LOGDEBUG, "CEncoderFFmpeg::{} - Successfully initialized with muxer {} and codec {}",
199
    CLog::Log(LOGDEBUG, "CEncoderFFmpeg::{} - Successfully initialized with muxer {} and codec {}",
210
              __func__,
200
              __func__,
Lines 212-227 Link Here
212
                                              : m_formatCtx->oformat->name,
202
                                              : m_formatCtx->oformat->name,
213
              codec->long_name ? codec->long_name : codec->name);
203
              codec->long_name ? codec->long_name : codec->name);
214
  }
204
  }
215
  catch (EncoderException& caught)
205
  catch (const FFMpegException& caught)
216
  {
206
  {
217
    CLog::Log(LOGERROR, "CEncoderFFmpeg::{} - {}", __func__, caught.what());
207
    CLog::Log(LOGERROR, "CEncoderFFmpeg::{} - {}", __func__, caught.what());
218
208
219
    av_freep(&m_buffer);
209
    av_freep(&m_buffer);
210
    av_channel_layout_uninit(&m_bufferFrame->ch_layout);
220
    av_frame_free(&m_bufferFrame);
211
    av_frame_free(&m_bufferFrame);
221
    swr_free(&m_swrCtx);
212
    swr_free(&m_swrCtx);
213
    av_channel_layout_uninit(&m_resampledFrame->ch_layout);
222
    av_frame_free(&m_resampledFrame);
214
    av_frame_free(&m_resampledFrame);
223
    av_freep(&m_resampledBuffer);
215
    av_freep(&m_resampledBuffer);
224
    av_free(m_bcBuffer);
216
    av_free(m_bcBuffer);
217
    av_channel_layout_uninit(&m_codecCtx->ch_layout);
225
    avcodec_free_context(&m_codecCtx);
218
    avcodec_free_context(&m_codecCtx);
226
    if (m_formatCtx)
219
    if (m_formatCtx)
227
    {
220
    {
Lines 299-305 Link Here
299
      if (swr_convert(m_swrCtx, m_resampledFrame->data, m_neededFrames,
292
      if (swr_convert(m_swrCtx, m_resampledFrame->data, m_neededFrames,
300
                      const_cast<const uint8_t**>(m_bufferFrame->extended_data),
293
                      const_cast<const uint8_t**>(m_bufferFrame->extended_data),
301
                      m_neededFrames) < 0)
294
                      m_neededFrames) < 0)
302
        throw EncoderException("Error resampling audio");
295
        throw FFMpegException("Error resampling audio");
303
296
304
      frame = m_resampledFrame;
297
      frame = m_resampledFrame;
305
    }
298
    }
Lines 316-323 Link Here
316
    m_bufferSize = 0;
309
    m_bufferSize = 0;
317
    err = avcodec_send_frame(m_codecCtx, frame);
310
    err = avcodec_send_frame(m_codecCtx, frame);
318
    if (err < 0)
311
    if (err < 0)
319
      throw EncoderException("Error sending a frame for encoding (error '{}')", __func__,
312
      throw FFMpegException("Error sending a frame for encoding (error '{}')",
320
                             FFmpegErrorToString(err));
313
                            FFMpegErrorToString(err));
321
314
322
    while (err >= 0)
315
    while (err >= 0)
323
    {
316
    {
Lines 329-347 Link Here
329
      }
322
      }
330
      else if (err < 0)
323
      else if (err < 0)
331
      {
324
      {
332
        throw EncoderException("Error during encoding (error '{}')", __func__,
325
        throw FFMpegException("Error during encoding (error '{}')", FFMpegErrorToString(err));
333
                               FFmpegErrorToString(err));
334
      }
326
      }
335
327
336
      err = av_write_frame(m_formatCtx, pkt);
328
      err = av_write_frame(m_formatCtx, pkt);
337
      if (err < 0)
329
      if (err < 0)
338
        throw EncoderException("Failed to write the frame data (error '{}')", __func__,
330
        throw FFMpegException("Failed to write the frame data (error '{}')",
339
                               FFmpegErrorToString(err));
331
                              FFMpegErrorToString(err));
340
332
341
      av_packet_unref(pkt);
333
      av_packet_unref(pkt);
342
    }
334
    }
343
  }
335
  }
344
  catch (EncoderException& caught)
336
  catch (const FFMpegException& caught)
345
  {
337
  {
346
    CLog::Log(LOGERROR, "CEncoderFFmpeg::{} - {}", __func__, caught.what());
338
    CLog::Log(LOGERROR, "CEncoderFFmpeg::{} - {}", __func__, caught.what());
347
  }
339
  }
Lines 366-373 Link Here
366
358
367
    /* Flush if needed */
359
    /* Flush if needed */
368
    av_freep(&m_buffer);
360
    av_freep(&m_buffer);
361
    av_channel_layout_uninit(&m_bufferFrame->ch_layout);
369
    av_frame_free(&m_bufferFrame);
362
    av_frame_free(&m_bufferFrame);
370
    swr_free(&m_swrCtx);
363
    swr_free(&m_swrCtx);
364
    av_channel_layout_uninit(&m_resampledFrame->ch_layout);
371
    av_frame_free(&m_resampledFrame);
365
    av_frame_free(&m_resampledFrame);
372
    av_freep(&m_resampledBuffer);
366
    av_freep(&m_resampledBuffer);
373
    m_needConversion = false;
367
    m_needConversion = false;
Lines 379-384 Link Here
379
373
380
    /* cleanup */
374
    /* cleanup */
381
    av_free(m_bcBuffer);
375
    av_free(m_bcBuffer);
376
    av_channel_layout_uninit(&m_codecCtx->ch_layout);
382
    avcodec_free_context(&m_codecCtx);
377
    avcodec_free_context(&m_codecCtx);
383
    av_freep(&m_formatCtx->pb);
378
    av_freep(&m_formatCtx->pb);
384
    avformat_free_context(m_formatCtx);
379
    avformat_free_context(m_formatCtx);
Lines 400-413 Link Here
400
    case 32:
395
    case 32:
401
      return AV_SAMPLE_FMT_S32;
396
      return AV_SAMPLE_FMT_S32;
402
    default:
397
    default:
403
      throw EncoderException("Invalid input bits per sample");
398
      throw FFMpegException("Invalid input bits per sample");
404
  }
399
  }
405
}
406
407
std::string CEncoderFFmpeg::FFmpegErrorToString(int err)
408
{
409
  std::string text;
410
  text.reserve(AV_ERROR_MAX_STRING_SIZE);
411
  av_strerror(err, text.data(), AV_ERROR_MAX_STRING_SIZE);
412
  return text;
413
}
400
}
(-)xbmc/cdrip/EncoderFFmpeg.h (-1 lines)
Lines 39-45 Link Here
39
  void SetTag(const std::string& tag, const std::string& value);
39
  void SetTag(const std::string& tag, const std::string& value);
40
  bool WriteFrame();
40
  bool WriteFrame();
41
  AVSampleFormat GetInputFormat(int inBitsPerSample);
41
  AVSampleFormat GetInputFormat(int inBitsPerSample);
42
  std::string FFmpegErrorToString(int err);
43
42
44
  AVFormatContext* m_formatCtx{nullptr};
43
  AVFormatContext* m_formatCtx{nullptr};
45
  AVCodecContext* m_codecCtx{nullptr};
44
  AVCodecContext* m_codecCtx{nullptr};
(-)xbmc/cores/AudioEngine/Encoders/AEEncoderFFmpeg.cpp (-49 / +84 lines)
Lines 10-23 Link Here
10
#define DTS_ENCODE_BITRATE 1411200
10
#define DTS_ENCODE_BITRATE 1411200
11
11
12
#include "cores/AudioEngine/Encoders/AEEncoderFFmpeg.h"
12
#include "cores/AudioEngine/Encoders/AEEncoderFFmpeg.h"
13
#include "cores/AudioEngine/Utils/AEUtil.h"
13
14
#include "ServiceBroker.h"
14
#include "ServiceBroker.h"
15
#include "utils/log.h"
15
#include "cores/AudioEngine/Utils/AEUtil.h"
16
#include "cores/FFmpeg.h"
16
#include "settings/Settings.h"
17
#include "settings/Settings.h"
17
#include "settings/SettingsComponent.h"
18
#include "settings/SettingsComponent.h"
18
#include <string.h>
19
#include "utils/log.h"
20
21
extern "C"
22
{
23
#include <libavutil/channel_layout.h>
24
}
25
19
#include <cassert>
26
#include <cassert>
27
#include <string.h>
20
28
29
using FFMPEG_HELP_TOOLS::FFMpegErrorToString;
30
using FFMPEG_HELP_TOOLS::FFMpegException;
31
21
CAEEncoderFFmpeg::CAEEncoderFFmpeg() : m_CodecCtx(NULL), m_SwrCtx(NULL)
32
CAEEncoderFFmpeg::CAEEncoderFFmpeg() : m_CodecCtx(NULL), m_SwrCtx(NULL)
22
{
33
{
23
}
34
}
Lines 26-31 Link Here
26
{
37
{
27
  Reset();
38
  Reset();
28
  swr_free(&m_SwrCtx);
39
  swr_free(&m_SwrCtx);
40
  av_channel_layout_uninit(&m_CodecCtx->ch_layout);
29
  avcodec_free_context(&m_CodecCtx);
41
  avcodec_free_context(&m_CodecCtx);
30
}
42
}
31
43
Lines 81-87 Link Here
81
93
82
  bool ac3 = CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_AUDIOOUTPUT_AC3PASSTHROUGH);
94
  bool ac3 = CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_AUDIOOUTPUT_AC3PASSTHROUGH);
83
95
84
  AVCodec *codec = NULL;
96
  const AVCodec* codec = nullptr;
85
97
86
  /* fallback to ac3 if we support it, we might not have DTS support */
98
  /* fallback to ac3 if we support it, we might not have DTS support */
87
  if (ac3)
99
  if (ac3)
Lines 102-108 Link Here
102
114
103
  m_CodecCtx->bit_rate = m_BitRate;
115
  m_CodecCtx->bit_rate = m_BitRate;
104
  m_CodecCtx->sample_rate = format.m_sampleRate;
116
  m_CodecCtx->sample_rate = format.m_sampleRate;
105
  m_CodecCtx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK;
117
  av_channel_layout_uninit(&m_CodecCtx->ch_layout);
118
  av_channel_layout_from_mask(&m_CodecCtx->ch_layout, AV_CH_LAYOUT_5POINT1_BACK);
106
119
107
  /* select a suitable data format */
120
  /* select a suitable data format */
108
  if (codec->sample_fmts)
121
  if (codec->sample_fmts)
Lines 179-200 Link Here
179
          LOGERROR,
192
          LOGERROR,
180
          "CAEEncoderFFmpeg::Initialize - Unable to find a suitable data format for the codec ({})",
193
          "CAEEncoderFFmpeg::Initialize - Unable to find a suitable data format for the codec ({})",
181
          m_CodecName);
194
          m_CodecName);
195
      av_channel_layout_uninit(&m_CodecCtx->ch_layout);
182
      avcodec_free_context(&m_CodecCtx);
196
      avcodec_free_context(&m_CodecCtx);
183
      return false;
197
      return false;
184
    }
198
    }
185
  }
199
  }
186
200
187
  m_CodecCtx->channels = BuildChannelLayout(m_CodecCtx->channel_layout, m_Layout);
201
  uint64_t mask = m_CodecCtx->ch_layout.u.mask;
202
  av_channel_layout_uninit(&m_CodecCtx->ch_layout);
203
  av_channel_layout_from_mask(&m_CodecCtx->ch_layout, mask);
204
  m_CodecCtx->ch_layout.nb_channels = BuildChannelLayout(mask, m_Layout);
188
205
189
  /* open the codec */
206
  /* open the codec */
190
  if (avcodec_open2(m_CodecCtx, codec, NULL))
207
  if (avcodec_open2(m_CodecCtx, codec, NULL))
191
  {
208
  {
209
    av_channel_layout_uninit(&m_CodecCtx->ch_layout);
192
    avcodec_free_context(&m_CodecCtx);
210
    avcodec_free_context(&m_CodecCtx);
193
    return false;
211
    return false;
194
  }
212
  }
195
213
196
  format.m_frames = m_CodecCtx->frame_size;
214
  format.m_frames = m_CodecCtx->frame_size;
197
  format.m_frameSize = m_CodecCtx->channels * (CAEUtil::DataFormatToBits(format.m_dataFormat) >> 3);
215
  int channels = m_CodecCtx->ch_layout.nb_channels;
216
  format.m_frameSize = channels * (CAEUtil::DataFormatToBits(format.m_dataFormat) >> 3);
198
  format.m_channelLayout = m_Layout;
217
  format.m_channelLayout = m_Layout;
199
218
200
  m_CurrentFormat = format;
219
  m_CurrentFormat = format;
Lines 204-217 Link Here
204
223
205
  if (m_NeedConversion)
224
  if (m_NeedConversion)
206
  {
225
  {
207
    m_SwrCtx = swr_alloc_set_opts(NULL,
226
    int ret = swr_alloc_set_opts2(&m_SwrCtx, &m_CodecCtx->ch_layout, m_CodecCtx->sample_fmt,
208
                      m_CodecCtx->channel_layout, m_CodecCtx->sample_fmt, m_CodecCtx->sample_rate,
227
                                  m_CodecCtx->sample_rate, &m_CodecCtx->ch_layout,
209
                      m_CodecCtx->channel_layout, AV_SAMPLE_FMT_FLT, m_CodecCtx->sample_rate,
228
                                  AV_SAMPLE_FMT_FLT, m_CodecCtx->sample_rate, 0, NULL);
210
                      0, NULL);
229
    if (ret || swr_init(m_SwrCtx) < 0)
211
    if (!m_SwrCtx || swr_init(m_SwrCtx) < 0)
212
    {
230
    {
213
      CLog::Log(LOGERROR, "CAEEncoderFFmpeg::Initialize - Failed to initialise resampler.");
231
      CLog::Log(LOGERROR, "CAEEncoderFFmpeg::Initialize - Failed to initialise resampler.");
214
      swr_free(&m_SwrCtx);
232
      swr_free(&m_SwrCtx);
233
      av_channel_layout_uninit(&m_CodecCtx->ch_layout);
215
      avcodec_free_context(&m_CodecCtx);
234
      avcodec_free_context(&m_CodecCtx);
216
      return false;
235
      return false;
217
    }
236
    }
Lines 242-303 Link Here
242
261
243
int CAEEncoderFFmpeg::Encode(uint8_t *in, int in_size, uint8_t *out, int out_size)
262
int CAEEncoderFFmpeg::Encode(uint8_t *in, int in_size, uint8_t *out, int out_size)
244
{
263
{
245
  int got_output;
264
  int size = 0;
246
  AVFrame *frame;
265
  int err = AVERROR_UNKNOWN;
266
  AVFrame* frame = nullptr;
267
  AVPacket* pkt = nullptr;
247
268
248
  if (!m_CodecCtx)
269
  if (!m_CodecCtx)
249
    return 0;
270
    return size;
250
271
251
  /* allocate the input frame
272
  try
252
   * sadly, we have to alloc/dealloc it everytime since we have no guarantee the
273
  {
253
   * data argument will be constant over iterated calls and the frame needs to
274
    /* allocate the input frame and output packet
254
   * setup pointers inside data */
275
     * sadly, we have to alloc/dealloc it everytime since we have no guarantee the
255
  frame = av_frame_alloc();
276
     * data argument will be constant over iterated calls and the frame needs to
256
  if (!frame)
277
     * setup pointers inside data */
257
    return 0;
278
    frame = av_frame_alloc();
279
    pkt = av_packet_alloc();
280
    if (!frame || !pkt)
281
      throw FFMpegException(
282
          "Failed to allocate \"AVFrame\" or \"AVPacket\" for encoding (error '{}')",
283
          strerror(errno));
258
284
259
  frame->nb_samples = m_CodecCtx->frame_size;
285
    frame->nb_samples = m_CodecCtx->frame_size;
260
  frame->format = m_CodecCtx->sample_fmt;
286
    frame->format = m_CodecCtx->sample_fmt;
261
  frame->channel_layout = m_CodecCtx->channel_layout;
287
    av_channel_layout_uninit(&frame->ch_layout);
262
  frame->channels = m_CodecCtx->channels;
288
    av_channel_layout_copy(&frame->ch_layout, &m_CodecCtx->ch_layout);
289
    int channelNum = m_CodecCtx->ch_layout.nb_channels;
263
290
264
  avcodec_fill_audio_frame(frame, m_CodecCtx->channels, m_CodecCtx->sample_fmt,
291
    avcodec_fill_audio_frame(frame, channelNum, m_CodecCtx->sample_fmt, in, in_size, 0);
265
                    in, in_size, 0);
266
292
267
  /* initialize the output packet */
293
    pkt->size = out_size;
268
  AVPacket* pkt = av_packet_alloc();
294
    pkt->data = out;
269
  if (!pkt)
270
  {
271
    CLog::Log(LOGERROR, "CAEEncoderFFmpeg::{} - av_packet_alloc failed: {}", __FUNCTION__,
272
              strerror(errno));
273
    av_frame_free(&frame);
274
    return 0;
275
  }
276
295
277
  pkt->size = out_size;
296
    /* encode it */
278
  pkt->data = out;
297
    err = avcodec_send_frame(m_CodecCtx, frame);
298
    if (err < 0)
299
      throw FFMpegException("Error sending a frame for encoding (error '{}')",
300
                            FFMpegErrorToString(err));
279
301
280
  /* encode it */
302
    while (err >= 0)
281
  int ret = avcodec_encode_audio2(m_CodecCtx, pkt, frame, &got_output);
303
    {
304
      err = avcodec_receive_packet(m_CodecCtx, pkt);
305
      if (err == AVERROR(EAGAIN) || err == AVERROR_EOF)
306
      {
307
        av_channel_layout_uninit(&frame->ch_layout);
308
        av_frame_free(&frame);
309
        av_packet_free(&pkt);
310
        return (err == AVERROR(EAGAIN)) ? -1 : 0;
311
      }
312
      else if (err < 0)
313
      {
314
        throw FFMpegException("Error during encoding (error '{}')", FFMpegErrorToString(err));
315
      }
282
316
283
  int size = pkt->size;
317
      av_packet_unref(pkt);
318
    }
284
319
320
    size = pkt->size;
321
  }
322
  catch (const FFMpegException& caught)
323
  {
324
    CLog::Log(LOGERROR, "CAEEncoderFFmpeg::{} - {}", __func__, caught.what());
325
  }
326
285
  /* free temporary data */
327
  /* free temporary data */
286
  av_frame_free(&frame);
328
  av_frame_free(&frame);
287
329
288
  /* free the packet */
330
  /* free the packet */
289
  av_packet_free(&pkt);
331
  av_packet_free(&pkt);
290
332
291
  if (ret < 0 || !got_output)
292
  {
293
    CLog::Log(LOGERROR, "CAEEncoderFFmpeg::Encode - Encoding failed");
294
    return 0;
295
  }
296
297
  /* return the number of frames used */
333
  /* return the number of frames used */
298
  return size;
334
  return size;
299
}
335
}
300
301
336
302
int CAEEncoderFFmpeg::GetData(uint8_t **data)
337
int CAEEncoderFFmpeg::GetData(uint8_t **data)
303
{
338
{
(-)xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp (-12 / +16 lines)
Lines 16-32 Link Here
16
#include "ActiveAESound.h"
16
#include "ActiveAESound.h"
17
#include "ActiveAEStream.h"
17
#include "ActiveAEStream.h"
18
#include "ServiceBroker.h"
18
#include "ServiceBroker.h"
19
#include "cores/AudioEngine/AEResampleFactory.h"
20
#include "cores/AudioEngine/Encoders/AEEncoderFFmpeg.h"
19
#include "cores/AudioEngine/Interfaces/IAudioCallback.h"
21
#include "cores/AudioEngine/Interfaces/IAudioCallback.h"
20
#include "cores/AudioEngine/Utils/AEUtil.h"
21
#include "cores/AudioEngine/Utils/AEStreamData.h"
22
#include "cores/AudioEngine/Utils/AEStreamData.h"
22
#include "cores/AudioEngine/Utils/AEStreamInfo.h"
23
#include "cores/AudioEngine/Utils/AEStreamInfo.h"
23
#include "cores/AudioEngine/AEResampleFactory.h"
24
#include "cores/AudioEngine/Utils/AEUtil.h"
24
#include "cores/AudioEngine/Encoders/AEEncoderFFmpeg.h"
25
26
#include "settings/Settings.h"
25
#include "settings/Settings.h"
27
#include "settings/SettingsComponent.h"
26
#include "settings/SettingsComponent.h"
28
#include "windowing/WinSystem.h"
29
#include "utils/log.h"
27
#include "utils/log.h"
28
#include "windowing/WinSystem.h"
30
29
31
using namespace std::chrono_literals;
30
using namespace std::chrono_literals;
32
31
Lines 3043-3050 Link Here
3043
  AVFormatContext *fmt_ctx = nullptr;
3042
  AVFormatContext *fmt_ctx = nullptr;
3044
  AVCodecContext *dec_ctx = nullptr;
3043
  AVCodecContext *dec_ctx = nullptr;
3045
  AVIOContext *io_ctx;
3044
  AVIOContext *io_ctx;
3046
  AVInputFormat *io_fmt = nullptr;
3045
  const AVInputFormat* io_fmt = nullptr;
3047
  AVCodec *dec = nullptr;
3046
  const AVCodec* dec = nullptr;
3048
  SampleConfig config;
3047
  SampleConfig config;
3049
3048
3050
  // No custom deleter until sound is registered
3049
  // No custom deleter until sound is registered
Lines 3096-3103 Link Here
3096
      AVCodecID codecId = fmt_ctx->streams[0]->codecpar->codec_id;
3095
      AVCodecID codecId = fmt_ctx->streams[0]->codecpar->codec_id;
3097
      dec = avcodec_find_decoder(codecId);
3096
      dec = avcodec_find_decoder(codecId);
3098
      config.sample_rate = fmt_ctx->streams[0]->codecpar->sample_rate;
3097
      config.sample_rate = fmt_ctx->streams[0]->codecpar->sample_rate;
3099
      config.channels = fmt_ctx->streams[0]->codecpar->channels;
3098
      config.channels = fmt_ctx->streams[0]->codecpar->ch_layout.nb_channels;
3100
      config.channel_layout = fmt_ctx->streams[0]->codecpar->channel_layout;
3099
      config.channel_layout = fmt_ctx->streams[0]->codecpar->ch_layout.u.mask;
3101
    }
3100
    }
3102
  }
3101
  }
3103
  if (dec == nullptr)
3102
  if (dec == nullptr)
Lines 3113-3122 Link Here
3113
3112
3114
  dec_ctx = avcodec_alloc_context3(dec);
3113
  dec_ctx = avcodec_alloc_context3(dec);
3115
  dec_ctx->sample_rate = config.sample_rate;
3114
  dec_ctx->sample_rate = config.sample_rate;
3116
  dec_ctx->channels = config.channels;
3115
  AVChannelLayout layout = {};
3117
  if (!config.channel_layout)
3116
  if (!config.channel_layout)
3118
    config.channel_layout = av_get_default_channel_layout(config.channels);
3117
    av_channel_layout_default(&layout, config.channels);
3119
  dec_ctx->channel_layout = config.channel_layout;
3118
  else
3119
    av_channel_layout_from_mask(&layout, config.channel_layout);
3120
  config.channel_layout = layout.u.mask;
3121
  av_channel_layout_copy(&dec_ctx->ch_layout, &layout);
3122
  av_channel_layout_uninit(&layout);
3120
3123
3121
  AVPacket* avpkt = av_packet_alloc();
3124
  AVPacket* avpkt = av_packet_alloc();
3122
  if (!avpkt)
3125
  if (!avpkt)
Lines 3183-3188 Link Here
3183
3186
3184
  av_packet_free(&avpkt);
3187
  av_packet_free(&avpkt);
3185
  av_frame_free(&decoded_frame);
3188
  av_frame_free(&decoded_frame);
3189
  av_channel_layout_uninit(&dec_ctx->ch_layout);
3186
  avcodec_free_context(&dec_ctx);
3190
  avcodec_free_context(&dec_ctx);
3187
  avformat_close_input(&fmt_ctx);
3191
  avformat_close_input(&fmt_ctx);
3188
  if (io_ctx)
3192
  if (io_ctx)
(-)xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEFilter.cpp (-7 / +15 lines)
Lines 12-19 Link Here
12
#include <algorithm>
12
#include <algorithm>
13
13
14
extern "C" {
14
extern "C" {
15
#include <libavfilter/avfilter.h>
16
#include <libavcodec/avcodec.h>
15
#include <libavcodec/avcodec.h>
16
#include <libavfilter/avfilter.h>
17
#include <libavfilter/buffersink.h>
17
#include <libavfilter/buffersink.h>
18
#include <libavfilter/buffersrc.h>
18
#include <libavfilter/buffersrc.h>
19
#include <libswresample/swresample.h>
19
#include <libswresample/swresample.h>
Lines 171-177 Link Here
171
  }
171
  }
172
172
173
  if (m_pOutFrame)
173
  if (m_pOutFrame)
174
  {
175
    av_channel_layout_uninit(&m_pOutFrame->ch_layout);
174
    av_frame_free(&m_pOutFrame);
176
    av_frame_free(&m_pOutFrame);
177
  }
175
178
176
  if (m_pConvertFrame)
179
  if (m_pConvertFrame)
177
    av_frame_free(&m_pConvertFrame);
180
    av_frame_free(&m_pConvertFrame);
Lines 205-214 Link Here
205
    if (!frame)
208
    if (!frame)
206
      return -1;
209
      return -1;
207
210
208
    int channels = av_get_channel_layout_nb_channels(m_channelLayout);
211
    av_channel_layout_uninit(&frame->ch_layout);
209
212
    av_channel_layout_from_mask(&frame->ch_layout, m_channelLayout);
210
    frame->channel_layout = m_channelLayout;
213
    int channels = frame->ch_layout.nb_channels;
211
    frame->channels = channels;
212
    frame->sample_rate = m_sampleRate;
214
    frame->sample_rate = m_sampleRate;
213
    frame->nb_samples = src_samples;
215
    frame->nb_samples = src_samples;
214
    frame->format = m_sampleFormat;
216
    frame->format = m_sampleFormat;
Lines 224-229 Link Here
224
                             src_buffer[0], src_bufsize, 16);
226
                             src_buffer[0], src_bufsize, 16);
225
    if (result < 0)
227
    if (result < 0)
226
    {
228
    {
229
      av_channel_layout_uninit(&frame->ch_layout);
227
      av_frame_free(&frame);
230
      av_frame_free(&frame);
228
      CLog::Log(LOGERROR, "CActiveAEFilter::ProcessFilter - avcodec_fill_audio_frame failed");
231
      CLog::Log(LOGERROR, "CActiveAEFilter::ProcessFilter - avcodec_fill_audio_frame failed");
229
      m_filterEof = true;
232
      m_filterEof = true;
Lines 231-236 Link Here
231
    }
234
    }
232
235
233
    result = av_buffersrc_write_frame(m_pFilterCtxIn, frame);
236
    result = av_buffersrc_write_frame(m_pFilterCtxIn, frame);
237
    av_channel_layout_uninit(&frame->ch_layout);
234
    av_frame_free(&frame);
238
    av_frame_free(&frame);
235
    if (result < 0)
239
    if (result < 0)
236
    {
240
    {
Lines 284-290 Link Here
284
    {
288
    {
285
      av_frame_unref(m_pOutFrame);
289
      av_frame_unref(m_pOutFrame);
286
      m_pOutFrame->format = m_sampleFormat;
290
      m_pOutFrame->format = m_sampleFormat;
287
      m_pOutFrame->channel_layout = m_channelLayout;
291
      av_channel_layout_uninit(&m_pOutFrame->ch_layout);
292
      av_channel_layout_from_mask(&m_pOutFrame->ch_layout, m_channelLayout);
288
      m_pOutFrame->sample_rate = m_sampleRate;
293
      m_pOutFrame->sample_rate = m_sampleRate;
289
      result = swr_convert_frame(m_pConvertCtx, m_pOutFrame, m_pConvertFrame);
294
      result = swr_convert_frame(m_pConvertCtx, m_pOutFrame, m_pConvertFrame);
290
      av_frame_unref(m_pConvertFrame);
295
      av_frame_unref(m_pConvertFrame);
Lines 302-308 Link Here
302
307
303
  if (m_hasData)
308
  if (m_hasData)
304
  {
309
  {
305
    int channels = av_get_channel_layout_nb_channels(m_channelLayout);
310
    AVChannelLayout layout = {};
311
    av_channel_layout_from_mask(&layout, m_channelLayout);
312
    int channels = layout.nb_channels;
313
    av_channel_layout_uninit(&layout);
306
    int planes = av_sample_fmt_is_planar(m_sampleFormat) ? channels : 1;
314
    int planes = av_sample_fmt_is_planar(m_sampleFormat) ? channels : 1;
307
    int samples = std::min(dst_samples, m_pOutFrame->nb_samples - m_sampleOffset);
315
    int samples = std::min(dst_samples, m_pOutFrame->nb_samples - m_sampleOffset);
308
    int bytes = samples * av_get_bytes_per_sample(m_sampleFormat) * channels / planes;
316
    int bytes = samples * av_get_bytes_per_sample(m_sampleFormat) * channels / planes;
(-)xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEResampleFFMPEG.cpp (-8 / +27 lines)
Lines 49-63 Link Here
49
    m_doesResample = true;
49
    m_doesResample = true;
50
50
51
  if (m_dst_chan_layout == 0)
51
  if (m_dst_chan_layout == 0)
52
    m_dst_chan_layout = av_get_default_channel_layout(m_dst_channels);
52
  {
53
    AVChannelLayout layout = {};
54
    av_channel_layout_default(&layout, m_dst_channels);
55
    m_dst_chan_layout = layout.u.mask;
56
    av_channel_layout_uninit(&layout);
57
  }
53
  if (m_src_chan_layout == 0)
58
  if (m_src_chan_layout == 0)
54
    m_src_chan_layout = av_get_default_channel_layout(m_src_channels);
59
  {
60
    AVChannelLayout layout = {};
61
    av_channel_layout_default(&layout, m_src_channels);
62
    m_src_chan_layout = layout.u.mask;
63
    av_channel_layout_uninit(&layout);
64
  }
55
65
56
  m_pContext = swr_alloc_set_opts(NULL, m_dst_chan_layout, m_dst_fmt, m_dst_rate,
66
  AVChannelLayout dstChLayout = {};
57
                                                        m_src_chan_layout, m_src_fmt, m_src_rate,
67
  AVChannelLayout srcChLayout = {};
58
                                                        0, NULL);
59
68
60
  if (!m_pContext)
69
  av_channel_layout_from_mask(&dstChLayout, m_dst_chan_layout);
70
  av_channel_layout_from_mask(&srcChLayout, m_src_chan_layout);
71
72
  int ret = swr_alloc_set_opts2(&m_pContext, &dstChLayout, m_dst_fmt, m_dst_rate, &srcChLayout,
73
                                m_src_fmt, m_src_rate, 0, NULL);
74
75
  if (ret)
61
  {
76
  {
62
    CLog::Log(LOGERROR, "CActiveAEResampleFFMPEG::Init - create context failed");
77
    CLog::Log(LOGERROR, "CActiveAEResampleFFMPEG::Init - create context failed");
63
    return false;
78
    return false;
Lines 126-135 Link Here
126
  else if (upmix && m_src_channels == 2 && m_dst_channels > 2)
141
  else if (upmix && m_src_channels == 2 && m_dst_channels > 2)
127
  {
142
  {
128
    memset(m_rematrix, 0, sizeof(m_rematrix));
143
    memset(m_rematrix, 0, sizeof(m_rematrix));
144
    av_channel_layout_uninit(&dstChLayout);
145
    av_channel_layout_from_mask(&dstChLayout, m_dst_chan_layout);
129
    for (int out=0; out<m_dst_channels; out++)
146
    for (int out=0; out<m_dst_channels; out++)
130
    {
147
    {
131
      uint64_t out_chan = av_channel_layout_extract_channel(m_dst_chan_layout, out);
148
      AVChannel outChan = av_channel_layout_channel_from_index(&dstChLayout, out);
132
      switch(out_chan)
149
      switch (outChan)
133
      {
150
      {
134
        case AV_CH_FRONT_LEFT:
151
        case AV_CH_FRONT_LEFT:
135
        case AV_CH_BACK_LEFT:
152
        case AV_CH_BACK_LEFT:
Lines 153-158 Link Here
153
          break;
170
          break;
154
      }
171
      }
155
    }
172
    }
173
174
    av_channel_layout_uninit(&dstChLayout);
156
175
157
    if (swr_set_matrix(m_pContext, (const double*)m_rematrix, AE_CH_MAX) < 0)
176
    if (swr_set_matrix(m_pContext, (const double*)m_rematrix, AE_CH_MAX) < 0)
158
    {
177
    {
(-)xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.cpp (-1 / +1 lines)
Lines 88-94 Link Here
88
  for(unsigned int i=0; i<m_format.m_channelLayout.Count(); i++)
88
  for(unsigned int i=0; i<m_format.m_channelLayout.Count(); i++)
89
  {
89
  {
90
    avLast = avCur;
90
    avLast = avCur;
91
    avCur = CAEUtil::GetAVChannel(m_format.m_channelLayout[i]);
91
    avCur = CAEUtil::GetAVChannelMask(m_format.m_channelLayout[i]);
92
    if(avCur < avLast)
92
    if(avCur < avLast)
93
    {
93
    {
94
      needRemap = true;
94
      needRemap = true;
(-)xbmc/cores/AudioEngine/Utils/AEUtil.cpp (-26 / +52 lines)
Lines 19-28 Link Here
19
#include <xmmintrin.h>
19
#include <xmmintrin.h>
20
#endif
20
#endif
21
21
22
extern "C" {
23
#include <libavutil/channel_layout.h>
24
}
25
26
void AEDelayStatus::SetDelay(double d)
22
void AEDelayStatus::SetDelay(double d)
27
{
23
{
28
  delay = d;
24
  delay = d;
Lines 550-583 Link Here
550
  }
546
  }
551
}
547
}
552
548
553
uint64_t CAEUtil::GetAVChannel(enum AEChannel aechannel)
549
uint64_t CAEUtil::GetAVChannelMask(enum AEChannel aechannel)
554
{
550
{
551
  enum AVChannel ch = GetAVChannel(aechannel);
552
  if (ch == AV_CHAN_NONE)
553
    return 0;
554
  return (1ULL << ch);
555
}
556
557
enum AVChannel CAEUtil::GetAVChannel(enum AEChannel aechannel)
558
{
555
  switch (aechannel)
559
  switch (aechannel)
556
  {
560
  {
557
  case AE_CH_FL:   return AV_CH_FRONT_LEFT;
561
    case AE_CH_FL:
558
  case AE_CH_FR:   return AV_CH_FRONT_RIGHT;
562
      return AV_CHAN_FRONT_LEFT;
559
  case AE_CH_FC:   return AV_CH_FRONT_CENTER;
563
    case AE_CH_FR:
560
  case AE_CH_LFE:  return AV_CH_LOW_FREQUENCY;
564
      return AV_CHAN_FRONT_RIGHT;
561
  case AE_CH_BL:   return AV_CH_BACK_LEFT;
565
    case AE_CH_FC:
562
  case AE_CH_BR:   return AV_CH_BACK_RIGHT;
566
      return AV_CHAN_FRONT_CENTER;
563
  case AE_CH_FLOC: return AV_CH_FRONT_LEFT_OF_CENTER;
567
    case AE_CH_LFE:
564
  case AE_CH_FROC: return AV_CH_FRONT_RIGHT_OF_CENTER;
568
      return AV_CHAN_LOW_FREQUENCY;
565
  case AE_CH_BC:   return AV_CH_BACK_CENTER;
569
    case AE_CH_BL:
566
  case AE_CH_SL:   return AV_CH_SIDE_LEFT;
570
      return AV_CHAN_BACK_LEFT;
567
  case AE_CH_SR:   return AV_CH_SIDE_RIGHT;
571
    case AE_CH_BR:
568
  case AE_CH_TC:   return AV_CH_TOP_CENTER;
572
      return AV_CHAN_BACK_RIGHT;
569
  case AE_CH_TFL:  return AV_CH_TOP_FRONT_LEFT;
573
    case AE_CH_FLOC:
570
  case AE_CH_TFC:  return AV_CH_TOP_FRONT_CENTER;
574
      return AV_CHAN_FRONT_LEFT_OF_CENTER;
571
  case AE_CH_TFR:  return AV_CH_TOP_FRONT_RIGHT;
575
    case AE_CH_FROC:
572
  case AE_CH_TBL:  return AV_CH_TOP_BACK_LEFT;
576
      return AV_CHAN_FRONT_RIGHT_OF_CENTER;
573
  case AE_CH_TBC:  return AV_CH_TOP_BACK_CENTER;
577
    case AE_CH_BC:
574
  case AE_CH_TBR:  return AV_CH_TOP_BACK_RIGHT;
578
      return AV_CHAN_BACK_CENTER;
575
  default:
579
    case AE_CH_SL:
576
    return 0;
580
      return AV_CHAN_SIDE_LEFT;
581
    case AE_CH_SR:
582
      return AV_CHAN_SIDE_RIGHT;
583
    case AE_CH_TC:
584
      return AV_CHAN_TOP_CENTER;
585
    case AE_CH_TFL:
586
      return AV_CHAN_TOP_FRONT_LEFT;
587
    case AE_CH_TFC:
588
      return AV_CHAN_TOP_FRONT_CENTER;
589
    case AE_CH_TFR:
590
      return AV_CHAN_TOP_FRONT_RIGHT;
591
    case AE_CH_TBL:
592
      return AV_CHAN_TOP_BACK_LEFT;
593
    case AE_CH_TBC:
594
      return AV_CHAN_TOP_BACK_CENTER;
595
    case AE_CH_TBR:
596
      return AV_CHAN_TOP_BACK_RIGHT;
597
    default:
598
      return AV_CHAN_NONE;
577
  }
599
  }
578
}
600
}
579
601
580
int CAEUtil::GetAVChannelIndex(enum AEChannel aechannel, uint64_t layout)
602
int CAEUtil::GetAVChannelIndex(enum AEChannel aechannel, uint64_t layout)
581
{
603
{
582
  return av_get_channel_layout_channel_index(layout, GetAVChannel(aechannel));
604
  AVChannelLayout ch_layout = {};
605
  av_channel_layout_from_mask(&ch_layout, layout);
606
  int idx = av_channel_layout_index_from_channel(&ch_layout, GetAVChannel(aechannel));
607
  av_channel_layout_uninit(&ch_layout);
608
  return idx;
583
}
609
}
(-)xbmc/cores/AudioEngine/Utils/AEUtil.h (-1 / +3 lines)
Lines 13-18 Link Here
13
#include <math.h>
13
#include <math.h>
14
14
15
extern "C" {
15
extern "C" {
16
#include <libavutil/channel_layout.h>
16
#include <libavutil/samplefmt.h>
17
#include <libavutil/samplefmt.h>
17
}
18
}
18
19
Lines 171-176 Link Here
171
  static uint64_t GetAVChannelLayout(const CAEChannelInfo &info);
172
  static uint64_t GetAVChannelLayout(const CAEChannelInfo &info);
172
  static CAEChannelInfo GetAEChannelLayout(uint64_t layout);
173
  static CAEChannelInfo GetAEChannelLayout(uint64_t layout);
173
  static AVSampleFormat GetAVSampleFormat(AEDataFormat format);
174
  static AVSampleFormat GetAVSampleFormat(AEDataFormat format);
174
  static uint64_t GetAVChannel(enum AEChannel aechannel);
175
  static uint64_t GetAVChannelMask(enum AEChannel aechannel);
176
  static enum AVChannel GetAVChannel(enum AEChannel aechannel);
175
  static int GetAVChannelIndex(enum AEChannel aechannel, uint64_t layout);
177
  static int GetAVChannelIndex(enum AEChannel aechannel, uint64_t layout);
176
};
178
};
(-)xbmc/cores/FFmpeg.cpp (+143 lines)
Lines 16-26 Link Here
16
#include "utils/StringUtils.h"
16
#include "utils/StringUtils.h"
17
#include "utils/log.h"
17
#include "utils/log.h"
18
18
19
extern "C"
20
{
21
#include <libavcodec/bsf.h>
22
}
23
19
#include <map>
24
#include <map>
20
#include <mutex>
25
#include <mutex>
21
26
22
static thread_local CFFmpegLog* CFFmpegLogTls;
27
static thread_local CFFmpegLog* CFFmpegLogTls;
23
28
29
namespace FFMPEG_HELP_TOOLS
30
{
31
32
std::string FFMpegErrorToString(int err)
33
{
34
  std::string text;
35
  text.resize(AV_ERROR_MAX_STRING_SIZE);
36
  av_strerror(err, text.data(), AV_ERROR_MAX_STRING_SIZE);
37
  return text;
38
}
39
40
} // namespace FFMPEG_HELP_TOOLS
41
24
void CFFmpegLog::SetLogLevel(int level)
42
void CFFmpegLog::SetLogLevel(int level)
25
{
43
{
26
  CFFmpegLog::ClearLogLevel();
44
  CFFmpegLog::ClearLogLevel();
Lines 117-119 Link Here
117
  buffer.erase(0, start);
135
  buffer.erase(0, start);
118
}
136
}
119
137
138
std::tuple<uint8_t*, int> GetPacketExtradata(const AVPacket* pkt,
139
                                             const AVCodecParserContext* parserCtx,
140
                                             AVCodecContext* codecCtx)
141
{
142
  constexpr int FF_MAX_EXTRADATA_SIZE = ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE);
143
144
  if (!pkt)
145
    return std::make_tuple(nullptr, 0);
146
147
  uint8_t* extraData = nullptr;
148
  int extraDataSize = 0;
149
150
  /* extract_extradata bitstream filter is implemented only
151
   * for certain codecs, as noted in discussion of PR#21248
152
   */
153
154
  AVCodecID codecId = codecCtx->codec_id;
155
156
  // clang-format off
157
  if (
158
    codecId != AV_CODEC_ID_MPEG1VIDEO &&
159
    codecId != AV_CODEC_ID_MPEG2VIDEO &&
160
    codecId != AV_CODEC_ID_H264 &&
161
    codecId != AV_CODEC_ID_HEVC &&
162
    codecId != AV_CODEC_ID_MPEG4 &&
163
    codecId != AV_CODEC_ID_VC1 &&
164
    codecId != AV_CODEC_ID_AV1 &&
165
    codecId != AV_CODEC_ID_AVS2 &&
166
    codecId != AV_CODEC_ID_AVS3 &&
167
    codecId != AV_CODEC_ID_CAVS
168
  )
169
    // clang-format on
170
    return std::make_tuple(nullptr, 0);
171
172
  const AVBitStreamFilter* f = av_bsf_get_by_name("extract_extradata");
173
  if (!f)
174
    return std::make_tuple(nullptr, 0);
175
176
  AVBSFContext* bsf = nullptr;
177
  int ret = av_bsf_alloc(f, &bsf);
178
  if (ret < 0)
179
    return std::make_tuple(nullptr, 0);
180
181
  bsf->par_in->codec_id = codecId;
182
183
  ret = av_bsf_init(bsf);
184
  if (ret < 0)
185
  {
186
    av_bsf_free(&bsf);
187
    return std::make_tuple(nullptr, 0);
188
  }
189
190
  AVPacket* dstPkt = av_packet_alloc();
191
  if (!dstPkt)
192
  {
193
    CLog::LogF(LOGERROR, "failed to allocate packet");
194
195
    av_bsf_free(&bsf);
196
    return std::make_tuple(nullptr, 0);
197
  }
198
  AVPacket* pktRef = dstPkt;
199
200
  ret = av_packet_ref(pktRef, pkt);
201
  if (ret < 0)
202
  {
203
    av_bsf_free(&bsf);
204
    av_packet_free(&dstPkt);
205
    return std::make_tuple(nullptr, 0);
206
  }
207
208
  ret = av_bsf_send_packet(bsf, pktRef);
209
  if (ret < 0)
210
  {
211
    av_packet_unref(pktRef);
212
    av_bsf_free(&bsf);
213
    av_packet_free(&dstPkt);
214
    return std::make_tuple(nullptr, 0);
215
  }
216
217
  ret = 0;
218
  while (ret >= 0)
219
  {
220
    ret = av_bsf_receive_packet(bsf, pktRef);
221
    if (ret < 0)
222
    {
223
      if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
224
        break;
225
226
      continue;
227
    }
228
229
    size_t retExtraDataSize = 0;
230
    uint8_t* retExtraData =
231
        av_packet_get_side_data(pktRef, AV_PKT_DATA_NEW_EXTRADATA, &retExtraDataSize);
232
    if (retExtraData && retExtraDataSize > 0 && retExtraDataSize < FF_MAX_EXTRADATA_SIZE)
233
    {
234
      extraData = static_cast<uint8_t*>(av_malloc(retExtraDataSize + AV_INPUT_BUFFER_PADDING_SIZE));
235
      if (!extraData)
236
      {
237
        CLog::LogF(LOGERROR, "failed to allocate {} bytes for extradata", retExtraDataSize);
238
239
        av_packet_unref(pktRef);
240
        av_bsf_free(&bsf);
241
        av_packet_free(&dstPkt);
242
        return std::make_tuple(nullptr, 0);
243
      }
244
245
      CLog::LogF(LOGDEBUG, "fetching extradata, extradata_size({})", retExtraDataSize);
246
247
      memcpy(extraData, retExtraData, retExtraDataSize);
248
      memset(extraData + retExtraDataSize, 0, AV_INPUT_BUFFER_PADDING_SIZE);
249
      extraDataSize = retExtraDataSize;
250
251
      av_packet_unref(pktRef);
252
      break;
253
    }
254
255
    av_packet_unref(pktRef);
256
  }
257
258
  av_bsf_free(&bsf);
259
  av_packet_free(&dstPkt);
260
261
  return std::make_tuple(extraData, extraDataSize);
262
}
(-)xbmc/cores/FFmpeg.h (+24 lines)
Lines 10-15 Link Here
10
10
11
#include "ServiceBroker.h"
11
#include "ServiceBroker.h"
12
#include "utils/CPUInfo.h"
12
#include "utils/CPUInfo.h"
13
#include "utils/StringUtils.h"
13
14
14
extern "C" {
15
extern "C" {
15
#include <libavcodec/avcodec.h>
16
#include <libavcodec/avcodec.h>
Lines 21-26 Link Here
21
#include <libpostproc/postprocess.h>
22
#include <libpostproc/postprocess.h>
22
}
23
}
23
24
25
#include <tuple>
26
27
namespace FFMPEG_HELP_TOOLS
28
{
29
30
struct FFMpegException : public std::exception
31
{
32
  std::string s;
33
  template<typename... Args>
34
  FFMpegException(const std::string& fmt, Args&&... args)
35
    : s(StringUtils::Format(fmt, std::forward<Args>(args)...))
36
  {
37
  }
38
  const char* what() const noexcept override { return s.c_str(); }
39
};
40
41
std::string FFMpegErrorToString(int err);
42
43
} // namespace FFMPEG_HELP_TOOLS
44
24
inline int PPCPUFlags()
45
inline int PPCPUFlags()
25
{
46
{
26
  unsigned int cpuFeatures = CServiceBroker::GetCPUInfo()->GetCPUFeatures();
47
  unsigned int cpuFeatures = CServiceBroker::GetCPUInfo()->GetCPUFeatures();
Lines 51-53 Link Here
51
  int level;
72
  int level;
52
};
73
};
53
74
75
std::tuple<uint8_t*, int> GetPacketExtradata(const AVPacket* pkt,
76
                                             const AVCodecParserContext* parserCtx,
77
                                             AVCodecContext* codecCtx);
(-)xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp (-21 / +44 lines)
Lines 7-20 Link Here
7
 */
7
 */
8
8
9
#include "DVDAudioCodecFFmpeg.h"
9
#include "DVDAudioCodecFFmpeg.h"
10
#include "ServiceBroker.h"
10
11
#include "../../DVDStreamInfo.h"
11
#include "../../DVDStreamInfo.h"
12
#include "utils/log.h"
12
#include "DVDCodecs/DVDCodecs.h"
13
#include "ServiceBroker.h"
14
#include "cores/AudioEngine/Utils/AEUtil.h"
15
#include "cores/FFmpeg.h"
13
#include "settings/AdvancedSettings.h"
16
#include "settings/AdvancedSettings.h"
14
#include "settings/Settings.h"
17
#include "settings/Settings.h"
15
#include "settings/SettingsComponent.h"
18
#include "settings/SettingsComponent.h"
16
#include "DVDCodecs/DVDCodecs.h"
19
#include "utils/log.h"
17
#include "cores/AudioEngine/Utils/AEUtil.h"
18
20
19
extern "C" {
21
extern "C" {
20
#include <libavutil/opt.h>
22
#include <libavutil/opt.h>
Lines 44-50 Link Here
44
    return false;
46
    return false;
45
  }
47
  }
46
48
47
  AVCodec* pCodec = NULL;
49
  const AVCodec* pCodec = nullptr;
48
  bool allowdtshddecode = true;
50
  bool allowdtshddecode = true;
49
51
50
  // set any special options
52
  // set any special options
Lines 71-83 Link Here
71
  m_pCodecContext->debug = 0;
73
  m_pCodecContext->debug = 0;
72
  m_pCodecContext->workaround_bugs = 1;
74
  m_pCodecContext->workaround_bugs = 1;
73
75
76
#if LIBAVCODEC_VERSION_MAJOR < 60
74
  if (pCodec->capabilities & AV_CODEC_CAP_TRUNCATED)
77
  if (pCodec->capabilities & AV_CODEC_CAP_TRUNCATED)
75
    m_pCodecContext->flags |= AV_CODEC_FLAG_TRUNCATED;
78
    m_pCodecContext->flags |= AV_CODEC_FLAG_TRUNCATED;
79
#endif
76
80
77
  m_matrixEncoding = AV_MATRIX_ENCODING_NONE;
81
  m_matrixEncoding = AV_MATRIX_ENCODING_NONE;
78
  m_channels = 0;
82
  m_channels = 0;
79
  m_pCodecContext->channels = hints.channels;
83
  av_channel_layout_uninit(&m_pCodecContext->ch_layout);
80
  m_hint_layout = hints.channellayout;
84
85
  if (hints.channels > 0 && hints.channellayout > 0)
86
  {
87
    m_pCodecContext->ch_layout.order = AV_CHANNEL_ORDER_NATIVE;
88
    m_pCodecContext->ch_layout.nb_channels = hints.channels;
89
    m_pCodecContext->ch_layout.u.mask = hints.channellayout;
90
  }
91
  else if (hints.channels > 0)
92
  {
93
    av_channel_layout_default(&m_pCodecContext->ch_layout, hints.channels);
94
  }
95
96
  m_hint_layout = m_pCodecContext->ch_layout.u.mask;
97
81
  m_pCodecContext->sample_rate = hints.samplerate;
98
  m_pCodecContext->sample_rate = hints.samplerate;
82
  m_pCodecContext->block_align = hints.blockalign;
99
  m_pCodecContext->block_align = hints.blockalign;
83
  m_pCodecContext->bit_rate = hints.bitrate;
100
  m_pCodecContext->bit_rate = hints.bitrate;
Lines 259-270 Link Here
259
    m_format.m_frameSize = m_format.m_channelLayout.Count() *
276
    m_format.m_frameSize = m_format.m_channelLayout.Count() *
260
                           CAEUtil::DataFormatToBits(m_format.m_dataFormat) >> 3;
277
                           CAEUtil::DataFormatToBits(m_format.m_dataFormat) >> 3;
261
278
262
    int planes = av_sample_fmt_is_planar(m_pCodecContext->sample_fmt) ? m_pFrame->channels : 1;
279
    int channels = m_pFrame->ch_layout.nb_channels;
280
    int planes = av_sample_fmt_is_planar(m_pCodecContext->sample_fmt) ? channels : 1;
281
263
    for (int i=0; i<planes; i++)
282
    for (int i=0; i<planes; i++)
264
      dst[i] = m_pFrame->extended_data[i];
283
      dst[i] = m_pFrame->extended_data[i];
265
284
266
    return m_pFrame->nb_samples * m_pFrame->channels *
285
    return m_pFrame->nb_samples * channels * av_get_bytes_per_sample(m_pCodecContext->sample_fmt);
267
           av_get_bytes_per_sample(m_pCodecContext->sample_fmt);
268
  }
286
  }
269
287
270
  return 0;
288
  return 0;
Lines 278-284 Link Here
278
296
279
int CDVDAudioCodecFFmpeg::GetChannels()
297
int CDVDAudioCodecFFmpeg::GetChannels()
280
{
298
{
281
  return m_pCodecContext->channels;
299
  return m_pCodecContext->ch_layout.nb_channels;
282
}
300
}
283
301
284
int CDVDAudioCodecFFmpeg::GetSampleRate()
302
int CDVDAudioCodecFFmpeg::GetSampleRate()
Lines 345-372 Link Here
345
363
346
void CDVDAudioCodecFFmpeg::BuildChannelMap()
364
void CDVDAudioCodecFFmpeg::BuildChannelMap()
347
{
365
{
348
  if (m_channels == m_pCodecContext->channels && m_layout == m_pCodecContext->channel_layout)
366
  int codecChannels = m_pCodecContext->ch_layout.nb_channels;
367
  uint64_t codecChannelLayout = m_pCodecContext->ch_layout.u.mask;
368
  if (m_channels == codecChannels && m_layout == codecChannelLayout)
349
    return; //nothing to do here
369
    return; //nothing to do here
350
370
351
  m_channels = m_pCodecContext->channels;
371
  m_channels = codecChannels;
352
  m_layout   = m_pCodecContext->channel_layout;
372
  m_layout = codecChannelLayout;
353
373
354
  int64_t layout;
374
  int64_t layout;
355
375
356
  int bits = count_bits(m_pCodecContext->channel_layout);
376
  int bits = count_bits(codecChannelLayout);
357
  if (bits == m_pCodecContext->channels)
377
  if (bits == codecChannels)
358
    layout = m_pCodecContext->channel_layout;
378
    layout = codecChannelLayout;
359
  else
379
  else
360
  {
380
  {
361
    CLog::Log(LOGINFO,
381
    CLog::Log(LOGINFO,
362
              "CDVDAudioCodecFFmpeg::GetChannelMap - FFmpeg reported {} channels, but the layout "
382
              "CDVDAudioCodecFFmpeg::GetChannelMap - FFmpeg reported {} channels, but the layout "
363
              "contains {} - trying hints",
383
              "contains {} - trying hints",
364
              m_pCodecContext->channels, bits);
384
              codecChannels, bits);
365
    if (static_cast<int>(count_bits(m_hint_layout)) == m_pCodecContext->channels)
385
    if (static_cast<int>(count_bits(m_hint_layout)) == codecChannels)
366
      layout = m_hint_layout;
386
      layout = m_hint_layout;
367
    else
387
    else
368
    {
388
    {
369
      layout = av_get_default_channel_layout(m_pCodecContext->channels);
389
      AVChannelLayout def_layout = {};
390
      av_channel_layout_default(&def_layout, codecChannels);
391
      layout = def_layout.u.mask;
392
      av_channel_layout_uninit(&def_layout);
370
      CLog::Log(LOGINFO, "Using default layout...");
393
      CLog::Log(LOGINFO, "Using default layout...");
371
    }
394
    }
372
  }
395
  }
Lines 392-398 Link Here
392
  if (layout & AV_CH_TOP_BACK_CENTER      ) m_channelLayout += AE_CH_BC  ;
415
  if (layout & AV_CH_TOP_BACK_CENTER      ) m_channelLayout += AE_CH_BC  ;
393
  if (layout & AV_CH_TOP_BACK_RIGHT       ) m_channelLayout += AE_CH_BR  ;
416
  if (layout & AV_CH_TOP_BACK_RIGHT       ) m_channelLayout += AE_CH_BR  ;
394
417
395
  m_channels = m_pCodecContext->channels;
418
  m_channels = codecChannels;
396
}
419
}
397
420
398
CAEChannelInfo CDVDAudioCodecFFmpeg::GetChannelMap()
421
CAEChannelInfo CDVDAudioCodecFFmpeg::GetChannelMap()
(-)xbmc/cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlayCodecFFmpeg.cpp (-1 / +2 lines)
Lines 10-15 Link Here
10
10
11
#include "DVDOverlayImage.h"
11
#include "DVDOverlayImage.h"
12
#include "DVDStreamInfo.h"
12
#include "DVDStreamInfo.h"
13
#include "cores/FFmpeg.h"
13
#include "cores/VideoPlayer/Interface/DemuxPacket.h"
14
#include "cores/VideoPlayer/Interface/DemuxPacket.h"
14
#include "cores/VideoPlayer/Interface/TimingConstants.h"
15
#include "cores/VideoPlayer/Interface/TimingConstants.h"
15
#include "utils/EndianSwap.h"
16
#include "utils/EndianSwap.h"
Lines 39-45 Link Here
39
  if (hints.codec == AV_CODEC_ID_EIA_608)
40
  if (hints.codec == AV_CODEC_ID_EIA_608)
40
    return false;
41
    return false;
41
42
42
  AVCodec* pCodec = avcodec_find_decoder(hints.codec);
43
  const AVCodec* pCodec = avcodec_find_decoder(hints.codec);
43
  if (!pCodec)
44
  if (!pCodec)
44
  {
45
  {
45
    CLog::Log(LOGDEBUG, "{} - Unable to find codec {}", __FUNCTION__, hints.codec);
46
    CLog::Log(LOGDEBUG, "{} - Unable to find codec {}", __FUNCTION__, hints.codec);
(-)xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp (-33 / +26 lines)
Lines 12-17 Link Here
12
#include "DVDCodecs/DVDFactoryCodec.h"
12
#include "DVDCodecs/DVDFactoryCodec.h"
13
#include "DVDStreamInfo.h"
13
#include "DVDStreamInfo.h"
14
#include "ServiceBroker.h"
14
#include "ServiceBroker.h"
15
#include "cores/FFmpeg.h"
15
#include "cores/VideoPlayer/Interface/TimingConstants.h"
16
#include "cores/VideoPlayer/Interface/TimingConstants.h"
16
#include "cores/VideoPlayer/VideoRenderers/RenderManager.h"
17
#include "cores/VideoPlayer/VideoRenderers/RenderManager.h"
17
#include "cores/VideoSettings.h"
18
#include "cores/VideoSettings.h"
Lines 27-38 Link Here
27
#include <mutex>
28
#include <mutex>
28
29
29
extern "C" {
30
extern "C" {
30
#include <libavutil/opt.h>
31
#include <libavutil/mastering_display_metadata.h>
32
#include <libavfilter/avfilter.h>
31
#include <libavfilter/avfilter.h>
33
#include <libavfilter/buffersink.h>
32
#include <libavfilter/buffersink.h>
34
#include <libavfilter/buffersrc.h>
33
#include <libavfilter/buffersrc.h>
34
#include <libavutil/mastering_display_metadata.h>
35
#include <libavutil/opt.h>
35
#include <libavutil/pixdesc.h>
36
#include <libavutil/pixdesc.h>
37
#include <libavutil/video_enc_params.h>
36
}
38
}
37
39
38
#ifndef TARGET_POSIX
40
#ifndef TARGET_POSIX
Lines 327-333 Link Here
327
  m_hints = hints;
329
  m_hints = hints;
328
  m_options = options;
330
  m_options = options;
329
331
330
  AVCodec* pCodec = nullptr;
332
  const AVCodec* pCodec = nullptr;
331
333
332
  m_iOrientation = hints.orientation;
334
  m_iOrientation = hints.orientation;
333
335
Lines 367-372 Link Here
367
  m_pCodecContext->workaround_bugs = FF_BUG_AUTODETECT;
369
  m_pCodecContext->workaround_bugs = FF_BUG_AUTODETECT;
368
  m_pCodecContext->get_format = GetFormat;
370
  m_pCodecContext->get_format = GetFormat;
369
  m_pCodecContext->codec_tag = hints.codec_tag;
371
  m_pCodecContext->codec_tag = hints.codec_tag;
372
  m_pCodecContext->flags = AV_CODEC_FLAG_COPY_OPAQUE;
370
373
371
  // setup threading model
374
  // setup threading model
372
  if (!(hints.codecOptions & CODEC_FORCE_SOFTWARE))
375
  if (!(hints.codecOptions & CODEC_FORCE_SOFTWARE))
Lines 543-561 Link Here
543
  CLog::Log(LOGDEBUG, "CDVDVideoCodecFFmpeg - Updated codec: {}", m_name);
546
  CLog::Log(LOGDEBUG, "CDVDVideoCodecFFmpeg - Updated codec: {}", m_name);
544
}
547
}
545
548
546
union pts_union
547
{
548
  double  pts_d;
549
  int64_t pts_i;
550
};
551
552
static int64_t pts_dtoi(double pts)
553
{
554
  pts_union u;
555
  u.pts_d = pts;
556
  return u.pts_i;
557
}
558
559
bool CDVDVideoCodecFFmpeg::AddData(const DemuxPacket &packet)
549
bool CDVDVideoCodecFFmpeg::AddData(const DemuxPacket &packet)
560
{
550
{
561
  if (!m_pCodecContext)
551
  if (!m_pCodecContext)
Lines 573-579 Link Here
573
    m_started = true;
563
    m_started = true;
574
564
575
  m_dts = packet.dts;
565
  m_dts = packet.dts;
576
  m_pCodecContext->reordered_opaque = pts_dtoi(packet.pts);
577
566
578
  AVPacket* avpkt = av_packet_alloc();
567
  AVPacket* avpkt = av_packet_alloc();
579
  if (!avpkt)
568
  if (!avpkt)
Lines 1048-1071 Link Here
1048
  pVideoPicture->qscale_type = 0;
1037
  pVideoPicture->qscale_type = 0;
1049
1038
1050
  AVFrameSideData* sd;
1039
  AVFrameSideData* sd;
1051
  sd = av_frame_get_side_data(m_pFrame, AV_FRAME_DATA_QP_TABLE_PROPERTIES);
1040
1041
  // https://github.com/FFmpeg/FFmpeg/blob/991d417692/doc/APIchanges#L18-L20
1042
  sd = av_frame_get_side_data(m_pFrame, AV_FRAME_DATA_VIDEO_ENC_PARAMS);
1052
  if (sd)
1043
  if (sd)
1053
  {
1044
  {
1054
    struct qp_properties
1045
    unsigned int mb_h = (m_pFrame->height + 15) / 16;
1055
    {
1046
    unsigned int mb_w = (m_pFrame->width + 15) / 16;
1056
      int stride;
1047
    unsigned int nb_mb = mb_h * mb_w;
1057
      int type;
1048
    unsigned int block_idx;
1058
    };
1059
1049
1060
    auto qp = reinterpret_cast<qp_properties*>(sd->data);
1050
    auto par = reinterpret_cast<AVVideoEncParams*>(sd->data);
1061
1051
    if (par->type == AV_VIDEO_ENC_PARAMS_MPEG2 && (par->nb_blocks == 0 || par->nb_blocks == nb_mb))
1062
    sd = av_frame_get_side_data(m_pFrame, AV_FRAME_DATA_QP_TABLE_DATA);
1063
    if (sd && sd->buf && qp)
1064
    {
1052
    {
1065
      // this seems wrong but it's what ffmpeg does internally
1053
      pVideoPicture->qstride = mb_w;
1066
      pVideoPicture->qp_table = reinterpret_cast<int8_t*>(sd->buf->data);
1054
      pVideoPicture->qscale_type = par->type;
1067
      pVideoPicture->qstride = qp->stride;
1055
      pVideoPicture->qp_table = static_cast<int8_t*>(av_malloc(nb_mb));
1068
      pVideoPicture->qscale_type = qp->type;
1056
      for (block_idx = 0; block_idx < nb_mb; block_idx++)
1057
      {
1058
        AVVideoBlockParams* b = av_video_enc_params_block(par, block_idx);
1059
        pVideoPicture->qp_table[block_idx] = par->qp + b->delta_qp;
1060
      }
1069
    }
1061
    }
1070
  }
1062
  }
1071
1063
Lines 1159-1166 Link Here
1159
  const AVFilter* outFilter = avfilter_get_by_name("buffersink"); // should be last filter in the graph for now
1151
  const AVFilter* outFilter = avfilter_get_by_name("buffersink"); // should be last filter in the graph for now
1160
1152
1161
  std::string args = StringUtils::Format(
1153
  std::string args = StringUtils::Format(
1162
      "{}:{}:{}:{}:{}:{}:{}", m_pCodecContext->width, m_pCodecContext->height,
1154
      "video_size={}x{}:pix_fmt={}:time_base={}/{}:pixel_aspect={}/{}", m_pCodecContext->width,
1163
      m_pCodecContext->pix_fmt, m_pCodecContext->time_base.num ? m_pCodecContext->time_base.num : 1,
1155
      m_pCodecContext->height, m_pCodecContext->pix_fmt,
1156
      m_pCodecContext->time_base.num ? m_pCodecContext->time_base.num : 1,
1164
      m_pCodecContext->time_base.num ? m_pCodecContext->time_base.den : 1,
1157
      m_pCodecContext->time_base.num ? m_pCodecContext->time_base.den : 1,
1165
      m_pCodecContext->sample_aspect_ratio.num != 0 ? m_pCodecContext->sample_aspect_ratio.num : 1,
1158
      m_pCodecContext->sample_aspect_ratio.num != 0 ? m_pCodecContext->sample_aspect_ratio.num : 1,
1166
      m_pCodecContext->sample_aspect_ratio.num != 0 ? m_pCodecContext->sample_aspect_ratio.den : 1);
1159
      m_pCodecContext->sample_aspect_ratio.num != 0 ? m_pCodecContext->sample_aspect_ratio.den : 1);
(-)xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoPPFFmpeg.cpp (+2 lines)
Lines 118-123 Link Here
118
                 m_pMode, m_pContext,
118
                 m_pMode, m_pContext,
119
                 pSource->pict_type | pSource->qscale_type ? PP_PICT_TYPE_QP2 : 0);
119
                 pSource->pict_type | pSource->qscale_type ? PP_PICT_TYPE_QP2 : 0);
120
120
121
  // https://github.com/FFmpeg/FFmpeg/blob/991d417692/doc/APIchanges#L18-L20
122
  av_free(pSource->qp_table);
121
123
122
  pPicture->SetParams(*pSource);
124
  pPicture->SetParams(*pSource);
123
  if (pPicture->videoBuffer)
125
  if (pPicture->videoBuffer)
(-)xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp (-3 / +2 lines)
Lines 973-979 Link Here
973
  m_event.Set();
973
  m_event.Set();
974
  m_avD3D11Context = av_d3d11va_alloc_context();
974
  m_avD3D11Context = av_d3d11va_alloc_context();
975
  m_avD3D11Context->cfg = reinterpret_cast<D3D11_VIDEO_DECODER_CONFIG*>(av_mallocz(sizeof(D3D11_VIDEO_DECODER_CONFIG)));
975
  m_avD3D11Context->cfg = reinterpret_cast<D3D11_VIDEO_DECODER_CONFIG*>(av_mallocz(sizeof(D3D11_VIDEO_DECODER_CONFIG)));
976
  m_avD3D11Context->surface = reinterpret_cast<ID3D11VideoDecoderOutputView**>(av_mallocz_array(32, sizeof(ID3D11VideoDecoderOutputView*)));
976
  m_avD3D11Context->surface = reinterpret_cast<ID3D11VideoDecoderOutputView**>(
977
      av_calloc(32, sizeof(ID3D11VideoDecoderOutputView*)));
977
  m_bufferPool.reset();
978
  m_bufferPool.reset();
978
979
979
  DX::Windowing()->Register(this);
980
  DX::Windowing()->Register(this);
Lines 1537-1544 Link Here
1537
    m_state = DXVA_RESET;
1538
    m_state = DXVA_RESET;
1538
    return -1;
1539
    return -1;
1539
  }
1540
  }
1540
1541
  pic->reordered_opaque = avctx->reordered_opaque;
1542
1541
1543
  for (unsigned i = 0; i < 4; i++)
1542
  for (unsigned i = 0; i < 4; i++)
1544
  {
1543
  {
(-)xbmc/cores/VideoPlayer/DVDCodecs/Video/VAAPI.cpp (-6 / +8 lines)
Lines 868-874 Link Here
868
  }
868
  }
869
  pic->buf[0] = buffer;
869
  pic->buf[0] = buffer;
870
870
871
  pic->reordered_opaque = avctx->reordered_opaque;
872
  va->Acquire();
871
  va->Acquire();
873
  return 0;
872
  return 0;
874
}
873
}
Lines 1259-1265 Link Here
1259
1258
1260
IHardwareDecoder* CDecoder::Create(CDVDStreamInfo &hint, CProcessInfo &processInfo, AVPixelFormat fmt)
1259
IHardwareDecoder* CDecoder::Create(CDVDStreamInfo &hint, CProcessInfo &processInfo, AVPixelFormat fmt)
1261
{
1260
{
1262
  if (fmt == AV_PIX_FMT_VAAPI_VLD && CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(SETTING_VIDEOPLAYER_USEVAAPI))
1261
  // https://github.com/FFmpeg/FFmpeg/blob/56450a0ee4fdda160f4039fc2ae33edfd27765c9/doc/APIchanges#L18-L26
1262
  if (fmt == AV_PIX_FMT_VAAPI &&
1263
      CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(SETTING_VIDEOPLAYER_USEVAAPI))
1263
    return new VAAPI::CDecoder(processInfo);
1264
    return new VAAPI::CDecoder(processInfo);
1264
1265
1265
  return nullptr;
1266
  return nullptr;
Lines 2966-2975 Link Here
2966
  const AVFilter* srcFilter = avfilter_get_by_name("buffer");
2967
  const AVFilter* srcFilter = avfilter_get_by_name("buffer");
2967
  const AVFilter* outFilter = avfilter_get_by_name("buffersink");
2968
  const AVFilter* outFilter = avfilter_get_by_name("buffersink");
2968
2969
2969
  std::string args = StringUtils::Format("{}:{}:{}:{}:{}:{}:{}", m_config.vidWidth,
2970
  std::string args =
2970
                                         m_config.vidHeight, AV_PIX_FMT_NV12, 1, 1,
2971
      StringUtils::Format("video_size={}x{}:pix_fmt={}:time_base={}/{}:pixel_aspect={}/{}",
2971
                                         (m_config.aspect.num != 0) ? m_config.aspect.num : 1,
2972
                          m_config.vidWidth, m_config.vidHeight, AV_PIX_FMT_NV12, 1, 1,
2972
                                         (m_config.aspect.num != 0) ? m_config.aspect.den : 1);
2973
                          (m_config.aspect.num != 0) ? m_config.aspect.num : 1,
2974
                          (m_config.aspect.num != 0) ? m_config.aspect.den : 1);
2973
2975
2974
  if (avfilter_graph_create_filter(&m_pFilterIn, srcFilter, "src", args.c_str(), NULL, m_pFilterGraph) < 0)
2976
  if (avfilter_graph_create_filter(&m_pFilterIn, srcFilter, "src", args.c_str(), NULL, m_pFilterGraph) < 0)
2975
  {
2977
  {
(-)xbmc/cores/VideoPlayer/DVDCodecs/Video/VDPAU.cpp (-1 lines)
Lines 1045-1051 Link Here
1045
  }
1045
  }
1046
  pic->buf[0] = buffer;
1046
  pic->buf[0] = buffer;
1047
1047
1048
  pic->reordered_opaque= avctx->reordered_opaque;
1049
  return 0;
1048
  return 0;
1050
}
1049
}
1051
1050
(-)xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp (-24 / +26 lines)
Lines 10-22 Link Here
10
10
11
#include "DVDDemuxUtils.h"
11
#include "DVDDemuxUtils.h"
12
#include "DVDInputStreams/DVDInputStream.h"
12
#include "DVDInputStreams/DVDInputStream.h"
13
#include "cores/FFmpeg.h"
13
#include "cores/VideoPlayer/Interface/TimingConstants.h"
14
#include "cores/VideoPlayer/Interface/TimingConstants.h"
14
#include "utils/log.h"
15
#include "utils/log.h"
15
16
17
#include <tuple>
16
#include <utility>
18
#include <utility>
17
19
18
#define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
19
20
class CDemuxStreamClientInternal
20
class CDemuxStreamClientInternal
21
{
21
{
22
public:
22
public:
Lines 130-136 Link Here
130
130
131
  if (stream->m_context == nullptr)
131
  if (stream->m_context == nullptr)
132
  {
132
  {
133
    AVCodec *codec = avcodec_find_decoder(st->codec);
133
    const AVCodec* codec = avcodec_find_decoder(st->codec);
134
    if (codec == nullptr)
134
    if (codec == nullptr)
135
    {
135
    {
136
      CLog::Log(LOGERROR, "{} - can't find decoder", __FUNCTION__);
136
      CLog::Log(LOGERROR, "{} - can't find decoder", __FUNCTION__);
Lines 149-165 Link Here
149
    stream->m_context->time_base.den = DVD_TIME_BASE;
149
    stream->m_context->time_base.den = DVD_TIME_BASE;
150
  }
150
  }
151
151
152
  if (stream->m_parser_split && stream->m_parser->parser->split)
152
  if (stream->m_parser_split && stream->m_parser && stream->m_parser->parser)
153
  {
153
  {
154
    int len = stream->m_parser->parser->split(stream->m_context, pkt->pData, pkt->iSize);
154
    AVPacket* avpkt = av_packet_alloc();
155
    if (len > 0 && len < FF_MAX_EXTRADATA_SIZE)
155
    if (!avpkt)
156
    {
156
    {
157
      CLog::LogF(LOGERROR, "av_packet_alloc failed: {}", strerror(errno));
158
      return false;
159
    }
160
161
    avpkt->data = pkt->pData;
162
    avpkt->size = pkt->iSize;
163
    avpkt->dts = avpkt->pts = AV_NOPTS_VALUE;
164
165
    auto [retExtraData, len] = GetPacketExtradata(avpkt, stream->m_parser, stream->m_context);
166
    if (len > 0)
167
    {
157
      st->changes++;
168
      st->changes++;
158
      st->disabled = false;
169
      st->disabled = false;
159
      st->ExtraSize = len;
170
      st->ExtraSize = len;
160
      st->ExtraData = std::make_unique<uint8_t[]>(len + AV_INPUT_BUFFER_PADDING_SIZE);
171
      st->ExtraData = std::unique_ptr<uint8_t[]>(retExtraData);
161
      memcpy(st->ExtraData.get(), pkt->pData, len);
162
      memset(st->ExtraData.get() + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
163
      stream->m_parser_split = false;
172
      stream->m_parser_split = false;
164
      change = true;
173
      change = true;
165
      CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - split extradata");
174
      CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - split extradata");
Lines 167-187 Link Here
167
      // Allow ffmpeg to transport codec information to stream->m_context
176
      // Allow ffmpeg to transport codec information to stream->m_context
168
      if (!avcodec_open2(stream->m_context, stream->m_context->codec, nullptr))
177
      if (!avcodec_open2(stream->m_context, stream->m_context->codec, nullptr))
169
      {
178
      {
170
        AVPacket* avpkt = av_packet_alloc();
171
        if (!avpkt)
172
        {
173
          CLog::Log(LOGERROR, "CDVDDemuxClient::{} - av_packet_alloc failed: {}", __FUNCTION__,
174
                    strerror(errno));
175
          return false;
176
        }
177
        avpkt->data = pkt->pData;
178
        avpkt->size = pkt->iSize;
179
        avpkt->dts = avpkt->pts = AV_NOPTS_VALUE;
180
        avcodec_send_packet(stream->m_context, avpkt);
179
        avcodec_send_packet(stream->m_context, avpkt);
181
        avcodec_close(stream->m_context);
180
        avcodec_close(stream->m_context);
182
        av_packet_free(&avpkt);
183
      }
181
      }
184
    }
182
    }
183
184
    av_packet_free(&avpkt);
185
  }
185
  }
186
186
187
  uint8_t *outbuf = nullptr;
187
  uint8_t *outbuf = nullptr;
Lines 219-228 Link Here
219
      case STREAM_AUDIO:
219
      case STREAM_AUDIO:
220
      {
220
      {
221
        CDemuxStreamClientInternalTpl<CDemuxStreamAudio>* sta = static_cast<CDemuxStreamClientInternalTpl<CDemuxStreamAudio>*>(st);
221
        CDemuxStreamClientInternalTpl<CDemuxStreamAudio>* sta = static_cast<CDemuxStreamClientInternalTpl<CDemuxStreamAudio>*>(st);
222
        if (stream->m_context->channels != sta->iChannels && stream->m_context->channels != 0)
222
        int streamChannels = stream->m_context->ch_layout.nb_channels;
223
        if (streamChannels != sta->iChannels && streamChannels != 0)
223
        {
224
        {
224
          CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - ({}) channels changed from {} to {}", st->uniqueId, sta->iChannels, stream->m_context->channels);
225
          CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - ({}) channels changed from {} to {}",
225
          sta->iChannels = stream->m_context->channels;
226
                    st->uniqueId, sta->iChannels, streamChannels);
227
          sta->iChannels = streamChannels;
226
          sta->changes++;
228
          sta->changes++;
227
          sta->disabled = false;
229
          sta->disabled = false;
228
        }
230
        }
Lines 234-240 Link Here
234
          sta->changes++;
236
          sta->changes++;
235
          sta->disabled = false;
237
          sta->disabled = false;
236
        }
238
        }
237
        if (stream->m_context->channels)
239
        if (streamChannels)
238
          st->changes = -1; // stop parsing
240
          st->changes = -1; // stop parsing
239
        break;
241
        break;
240
      }
242
      }
(-)xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp (-76 / +63 lines)
Lines 34-43 Link Here
34
34
35
#include <mutex>
35
#include <mutex>
36
#include <sstream>
36
#include <sstream>
37
#include <tuple>
37
#include <utility>
38
#include <utility>
38
39
39
extern "C"
40
extern "C"
40
{
41
{
42
#include "libavutil/channel_layout.h"
41
#include "libavutil/pixdesc.h"
43
#include "libavutil/pixdesc.h"
42
}
44
}
43
45
Lines 104-111 Link Here
104
}
106
}
105
} // namespace
107
} // namespace
106
108
107
#define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
108
109
std::string CDemuxStreamAudioFFmpeg::GetStreamName()
109
std::string CDemuxStreamAudioFFmpeg::GetStreamName()
110
{
110
{
111
  if (!m_stream)
111
  if (!m_stream)
Lines 235-241 Link Here
235
235
236
bool CDVDDemuxFFmpeg::Open(const std::shared_ptr<CDVDInputStream>& pInput, bool fileinfo)
236
bool CDVDDemuxFFmpeg::Open(const std::shared_ptr<CDVDInputStream>& pInput, bool fileinfo)
237
{
237
{
238
  AVInputFormat* iformat = NULL;
238
  const AVInputFormat* iformat = nullptr;
239
  std::string strFile;
239
  std::string strFile;
240
  m_streaminfo = !pInput->IsRealtime() && !m_reopen;
240
  m_streaminfo = !pInput->IsRealtime() && !m_reopen;
241
  m_reopen = false;
241
  m_reopen = false;
Lines 323-329 Link Here
323
    }
323
    }
324
    if (result < 0)
324
    if (result < 0)
325
    {
325
    {
326
      m_pFormatContext->flags |= AVFMT_FLAG_PRIV_OPT;
327
      if (avformat_open_input(&m_pFormatContext, strFile.c_str(), iformat, &options) < 0)
326
      if (avformat_open_input(&m_pFormatContext, strFile.c_str(), iformat, &options) < 0)
328
      {
327
      {
329
        CLog::Log(LOGDEBUG, "Error, could not open file {}", CURL::GetRedacted(strFile));
328
        CLog::Log(LOGDEBUG, "Error, could not open file {}", CURL::GetRedacted(strFile));
Lines 335-341 Link Here
335
      avformat_close_input(&m_pFormatContext);
334
      avformat_close_input(&m_pFormatContext);
336
      m_pFormatContext = avformat_alloc_context();
335
      m_pFormatContext = avformat_alloc_context();
337
      m_pFormatContext->interrupt_callback = int_cb;
336
      m_pFormatContext->interrupt_callback = int_cb;
338
      m_pFormatContext->flags &= ~AVFMT_FLAG_PRIV_OPT;
339
      AVDictionary* options = GetFFMpegOptionsFromInput();
337
      AVDictionary* options = GetFFMpegOptionsFromInput();
340
      av_dict_set_int(&options, "load_all_variants", 0, AV_OPT_SEARCH_CHILDREN);
338
      av_dict_set_int(&options, "load_all_variants", 0, AV_OPT_SEARCH_CHILDREN);
341
      if (avformat_open_input(&m_pFormatContext, strFile.c_str(), iformat, &options) < 0)
339
      if (avformat_open_input(&m_pFormatContext, strFile.c_str(), iformat, &options) < 0)
Lines 422-430 Link Here
422
          // is present, we assume it is PCM audio.
420
          // is present, we assume it is PCM audio.
423
          // AC3 is always wrapped in iec61937 (ffmpeg "spdif"), while DTS
421
          // AC3 is always wrapped in iec61937 (ffmpeg "spdif"), while DTS
424
          // may be just padded.
422
          // may be just padded.
425
          AVInputFormat* iformat2;
423
          const AVInputFormat* iformat2 = av_find_input_format("spdif");
426
          iformat2 = av_find_input_format("spdif");
427
428
          if (iformat2 && iformat2->read_probe(&pd) > AVPROBE_SCORE_MAX / 4)
424
          if (iformat2 && iformat2->read_probe(&pd) > AVPROBE_SCORE_MAX / 4)
429
          {
425
          {
430
            iformat = iformat2;
426
            iformat = iformat2;
Lines 544-555 Link Here
544
    m_streaminfo = true;
540
    m_streaminfo = true;
545
  }
541
  }
546
542
547
  if (iformat && (strcmp(iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") == 0))
548
  {
549
    if (URIUtils::IsRemote(strFile))
550
      m_pFormatContext->iformat->flags |= AVFMT_NOGENSEARCH;
551
  }
552
553
  // we need to know if this is matroska, avi or sup later
543
  // we need to know if this is matroska, avi or sup later
554
  m_bMatroska = strncmp(m_pFormatContext->iformat->name, "matroska", 8) == 0;	// for "matroska.webm"
544
  m_bMatroska = strncmp(m_pFormatContext->iformat->name, "matroska", 8) == 0;	// for "matroska.webm"
555
  m_bAVI = strcmp(m_pFormatContext->iformat->name, "avi") == 0;
545
  m_bAVI = strcmp(m_pFormatContext->iformat->name, "avi") == 0;
Lines 604-612 Link Here
604
  // if format can be nonblocking, let's use that
594
  // if format can be nonblocking, let's use that
605
  m_pFormatContext->flags |= AVFMT_FLAG_NONBLOCK;
595
  m_pFormatContext->flags |= AVFMT_FLAG_NONBLOCK;
606
596
607
  // deprecated, will be always set in future versions
608
  m_pFormatContext->flags |= AVFMT_FLAG_KEEP_SIDE_DATA;
609
610
  UpdateCurrentPTS();
597
  UpdateCurrentPTS();
611
598
612
  // select the correct program if requested
599
  // select the correct program if requested
Lines 647-653 Link Here
647
          {
634
          {
648
            int idx = m_pFormatContext->programs[i]->stream_index[j];
635
            int idx = m_pFormatContext->programs[i]->stream_index[j];
649
            AVStream* st = m_pFormatContext->streams[idx];
636
            AVStream* st = m_pFormatContext->streams[idx];
650
            if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->codec_info_nb_frames > 0) ||
637
            // Related to https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210429143825.53040-1-jamrial@gmail.com/
638
            // has been replaced with AVSTREAM_EVENT_FLAG_NEW_PACKETS.
639
            if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
640
                 (st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)) ||
651
                (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate > 0))
641
                (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate > 0))
652
            {
642
            {
653
              nProgram = i;
643
              nProgram = i;
Lines 1218-1225 Link Here
1218
    else if (stream->type == STREAM_AUDIO)
1208
    else if (stream->type == STREAM_AUDIO)
1219
    {
1209
    {
1220
      CDemuxStreamAudioFFmpeg* audiostream = dynamic_cast<CDemuxStreamAudioFFmpeg*>(stream);
1210
      CDemuxStreamAudioFFmpeg* audiostream = dynamic_cast<CDemuxStreamAudioFFmpeg*>(stream);
1221
      if (audiostream && (audiostream->iChannels != m_pFormatContext->streams[pPacket->iStreamId]->codecpar->channels ||
1211
      int codecparChannels =
1222
          audiostream->iSampleRate != m_pFormatContext->streams[pPacket->iStreamId]->codecpar->sample_rate))
1212
          m_pFormatContext->streams[pPacket->iStreamId]->codecpar->ch_layout.nb_channels;
1213
      if (audiostream && (audiostream->iChannels != codecparChannels ||
1214
                          audiostream->iSampleRate !=
1215
                              m_pFormatContext->streams[pPacket->iStreamId]->codecpar->sample_rate))
1223
      {
1216
      {
1224
        // content has changed
1217
        // content has changed
1225
        stream = AddStream(pPacket->iStreamId);
1218
        stream = AddStream(pPacket->iStreamId);
Lines 1401-1409 Link Here
1401
  if (idx >= 0)
1394
  if (idx >= 0)
1402
  {
1395
  {
1403
    AVStream* stream = m_pFormatContext->streams[idx];
1396
    AVStream* stream = m_pFormatContext->streams[idx];
1404
    if (stream && stream->cur_dts != (int64_t)AV_NOPTS_VALUE)
1397
1398
    if (stream && m_pkt.pkt.dts != (int64_t)AV_NOPTS_VALUE)
1405
    {
1399
    {
1406
      double ts = ConvertTimestamp(stream->cur_dts, stream->time_base.den, stream->time_base.num);
1400
      double ts = ConvertTimestamp(m_pkt.pkt.dts, stream->time_base.den, stream->time_base.num);
1407
      m_currentPts = ts;
1401
      m_currentPts = ts;
1408
    }
1402
    }
1409
  }
1403
  }
Lines 1614-1627 Link Here
1614
      {
1608
      {
1615
        CDemuxStreamAudioFFmpeg* st = new CDemuxStreamAudioFFmpeg(pStream);
1609
        CDemuxStreamAudioFFmpeg* st = new CDemuxStreamAudioFFmpeg(pStream);
1616
        stream = st;
1610
        stream = st;
1617
        st->iChannels = pStream->codecpar->channels;
1611
        int codecparChannels = pStream->codecpar->ch_layout.nb_channels;
1612
        int codecparChannelLayout = pStream->codecpar->ch_layout.u.mask;
1613
        st->iChannels = codecparChannels;
1614
        st->iChannelLayout = codecparChannelLayout;
1618
        st->iSampleRate = pStream->codecpar->sample_rate;
1615
        st->iSampleRate = pStream->codecpar->sample_rate;
1619
        st->iBlockAlign = pStream->codecpar->block_align;
1616
        st->iBlockAlign = pStream->codecpar->block_align;
1620
        st->iBitRate = static_cast<int>(pStream->codecpar->bit_rate);
1617
        st->iBitRate = static_cast<int>(pStream->codecpar->bit_rate);
1621
        st->iBitsPerSample = pStream->codecpar->bits_per_raw_sample;
1618
        st->iBitsPerSample = pStream->codecpar->bits_per_raw_sample;
1622
        st->iChannelLayout = pStream->codecpar->channel_layout;
1623
        char buf[32] = {};
1619
        char buf[32] = {};
1624
        av_get_channel_layout_string(buf, 31, st->iChannels, st->iChannelLayout);
1620
        // https://github.com/FFmpeg/FFmpeg/blob/6ccc3989d15/doc/APIchanges#L50-L53
1621
        AVChannelLayout layout = {};
1622
        av_channel_layout_from_mask(&layout, st->iChannelLayout);
1623
        av_channel_layout_describe(&layout, buf, sizeof(buf));
1624
        av_channel_layout_uninit(&layout);
1625
        st->m_channelLayoutName = buf;
1625
        st->m_channelLayoutName = buf;
1626
        if (st->iBitsPerSample == 0)
1626
        if (st->iBitsPerSample == 0)
1627
          st->iBitsPerSample = pStream->codecpar->bits_per_coded_sample;
1627
          st->iBitsPerSample = pStream->codecpar->bits_per_coded_sample;
Lines 1663-1678 Link Here
1663
          st->iFpsScale = 0;
1663
          st->iFpsScale = 0;
1664
        }
1664
        }
1665
1665
1666
        if (pStream->codec_info_nb_frames > 0 &&
1667
            pStream->codec_info_nb_frames <= 2 &&
1668
            m_pInput->IsStreamType(DVDSTREAM_TYPE_DVD))
1669
        {
1670
          CLog::Log(LOGDEBUG, "{} - fps may be unreliable since ffmpeg decoded only {} frame(s)",
1671
                    __FUNCTION__, pStream->codec_info_nb_frames);
1672
          st->iFpsRate  = 0;
1673
          st->iFpsScale = 0;
1674
        }
1675
1676
        st->iWidth = pStream->codecpar->width;
1666
        st->iWidth = pStream->codecpar->width;
1677
        st->iHeight = pStream->codecpar->height;
1667
        st->iHeight = pStream->codecpar->height;
1678
        st->fAspect = SelectAspect(pStream, st->bForcedAspect);
1668
        st->fAspect = SelectAspect(pStream, st->bForcedAspect);
Lines 1693-1699 Link Here
1693
        st->colorRange = pStream->codecpar->color_range;
1683
        st->colorRange = pStream->codecpar->color_range;
1694
        st->hdr_type = DetermineHdrType(pStream);
1684
        st->hdr_type = DetermineHdrType(pStream);
1695
1685
1696
        int size = 0;
1686
        // https://github.com/FFmpeg/FFmpeg/blob/release/5.0/doc/APIchanges
1687
        size_t size = 0;
1697
        uint8_t* side_data = nullptr;
1688
        uint8_t* side_data = nullptr;
1698
1689
1699
        side_data = av_stream_get_side_data(pStream, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, &size);
1690
        side_data = av_stream_get_side_data(pStream, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, &size);
Lines 2103-2109 Link Here
2103
      return strName;
2094
      return strName;
2104
    }
2095
    }
2105
2096
2106
    AVCodec* codec = avcodec_find_decoder(stream->codec);
2097
    const AVCodec* codec = avcodec_find_decoder(stream->codec);
2107
    if (codec)
2098
    if (codec)
2108
      strName = avcodec_get_name(codec->id);
2099
      strName = avcodec_get_name(codec->id);
2109
  }
2100
  }
Lines 2158-2165 Link Here
2158
    if (m_pFormatContext->streams[idx]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
2149
    if (m_pFormatContext->streams[idx]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
2159
    {
2150
    {
2160
      CDemuxStreamAudioFFmpeg* audiostream = dynamic_cast<CDemuxStreamAudioFFmpeg*>(stream);
2151
      CDemuxStreamAudioFFmpeg* audiostream = dynamic_cast<CDemuxStreamAudioFFmpeg*>(stream);
2161
      if (audiostream &&
2152
      int codecparChannels = m_pFormatContext->streams[idx]->codecpar->ch_layout.nb_channels;
2162
          m_pFormatContext->streams[idx]->codecpar->channels != audiostream->iChannels)
2153
      if (audiostream && codecparChannels != audiostream->iChannels)
2163
      {
2154
      {
2164
        return true;
2155
        return true;
2165
      }
2156
      }
Lines 2279-2285 Link Here
2279
2270
2280
      parser->second->m_parserCtx = av_parser_init(st->codecpar->codec_id);
2271
      parser->second->m_parserCtx = av_parser_init(st->codecpar->codec_id);
2281
2272
2282
      AVCodec* codec = avcodec_find_decoder(st->codecpar->codec_id);
2273
      const AVCodec* codec = avcodec_find_decoder(st->codecpar->codec_id);
2283
      if (codec == nullptr)
2274
      if (codec == nullptr)
2284
      {
2275
      {
2285
        CLog::Log(LOGERROR, "{} - can't find decoder", __FUNCTION__);
2276
        CLog::Log(LOGERROR, "{} - can't find decoder", __FUNCTION__);
Lines 2295-2339 Link Here
2295
2286
2296
    if (parser->second->m_parserCtx &&
2287
    if (parser->second->m_parserCtx &&
2297
        parser->second->m_parserCtx->parser &&
2288
        parser->second->m_parserCtx->parser &&
2298
        parser->second->m_parserCtx->parser->split &&
2299
        !st->codecpar->extradata)
2289
        !st->codecpar->extradata)
2300
    {
2290
    {
2301
      int i = parser->second->m_parserCtx->parser->split(parser->second->m_codecCtx, pkt->data, pkt->size);
2291
      auto [retExtraData, i] =
2302
      if (i > 0 && i < FF_MAX_EXTRADATA_SIZE)
2292
          GetPacketExtradata(pkt, parser->second->m_parserCtx, parser->second->m_codecCtx);
2293
      if (i > 0)
2303
      {
2294
      {
2304
        st->codecpar->extradata = (uint8_t*)av_malloc(i + AV_INPUT_BUFFER_PADDING_SIZE);
2295
        st->codecpar->extradata_size = i;
2305
        if (st->codecpar->extradata)
2296
        st->codecpar->extradata = retExtraData;
2297
2298
        if (parser->second->m_parserCtx->parser->parser_parse)
2306
        {
2299
        {
2307
          CLog::Log(LOGDEBUG,
2300
          parser->second->m_codecCtx->extradata = st->codecpar->extradata;
2308
                    "CDVDDemuxFFmpeg::ParsePacket() fetching extradata, extradata_size({})", i);
2301
          parser->second->m_codecCtx->extradata_size = st->codecpar->extradata_size;
2309
          st->codecpar->extradata_size = i;
2302
          const uint8_t* outbufptr;
2310
          memcpy(st->codecpar->extradata, pkt->data, i);
2303
          int bufSize;
2311
          memset(st->codecpar->extradata + i, 0, AV_INPUT_BUFFER_PADDING_SIZE);
2304
          parser->second->m_parserCtx->flags |= PARSER_FLAG_COMPLETE_FRAMES;
2305
          parser->second->m_parserCtx->parser->parser_parse(parser->second->m_parserCtx,
2306
                                                            parser->second->m_codecCtx, &outbufptr,
2307
                                                            &bufSize, pkt->data, pkt->size);
2308
          parser->second->m_codecCtx->extradata = nullptr;
2309
          parser->second->m_codecCtx->extradata_size = 0;
2312
2310
2313
          if (parser->second->m_parserCtx->parser->parser_parse)
2311
          if (parser->second->m_parserCtx->width != 0)
2314
          {
2312
          {
2315
            parser->second->m_codecCtx->extradata = st->codecpar->extradata;
2313
            st->codecpar->width = parser->second->m_parserCtx->width;
2316
            parser->second->m_codecCtx->extradata_size = st->codecpar->extradata_size;
2314
            st->codecpar->height = parser->second->m_parserCtx->height;
2317
            const uint8_t* outbufptr;
2318
            int bufSize;
2319
            parser->second->m_parserCtx->flags |= PARSER_FLAG_COMPLETE_FRAMES;
2320
            parser->second->m_parserCtx->parser->parser_parse(parser->second->m_parserCtx,
2321
                                                              parser->second->m_codecCtx,
2322
                                                              &outbufptr, &bufSize,
2323
                                                              pkt->data, pkt->size);
2324
            parser->second->m_codecCtx->extradata = nullptr;
2325
            parser->second->m_codecCtx->extradata_size = 0;
2326
2327
            if (parser->second->m_parserCtx->width != 0)
2328
            {
2329
              st->codecpar->width = parser->second->m_parserCtx->width;
2330
              st->codecpar->height = parser->second->m_parserCtx->height;
2331
            }
2332
            else
2333
            {
2334
              CLog::Log(LOGERROR, "CDVDDemuxFFmpeg::ParsePacket() invalid width/height");
2335
            }
2336
          }
2315
          }
2316
          else
2317
          {
2318
            CLog::Log(LOGERROR, "CDVDDemuxFFmpeg::ParsePacket() invalid width/height");
2319
          }
2337
        }
2320
        }
2338
      }
2321
      }
2339
    }
2322
    }
Lines 2357-2363 Link Here
2357
        {
2340
        {
2358
          if (!m_startTime)
2341
          if (!m_startTime)
2359
          {
2342
          {
2360
            m_startTime = av_rescale(st->cur_dts, st->time_base.num, st->time_base.den) - 0.000001;
2343
            m_startTime =
2344
                av_rescale(m_pkt.pkt.dts, st->time_base.num, st->time_base.den) - 0.000001;
2361
            m_seekStream = idx;
2345
            m_seekStream = idx;
2362
          }
2346
          }
2363
          return TRANSPORT_STREAM_STATE::READY;
2347
          return TRANSPORT_STREAM_STATE::READY;
Lines 2377-2383 Link Here
2377
        {
2361
        {
2378
          if (!m_startTime)
2362
          if (!m_startTime)
2379
          {
2363
          {
2380
            m_startTime = av_rescale(st->cur_dts, st->time_base.num, st->time_base.den) - 0.000001;
2364
            m_startTime =
2365
                av_rescale(m_pkt.pkt.dts, st->time_base.num, st->time_base.den) - 0.000001;
2381
            m_seekStream = i;
2366
            m_seekStream = i;
2382
          }
2367
          }
2383
          return TRANSPORT_STREAM_STATE::READY;
2368
          return TRANSPORT_STREAM_STATE::READY;
Lines 2410-2416 Link Here
2410
        {
2395
        {
2411
          if (!m_startTime)
2396
          if (!m_startTime)
2412
          {
2397
          {
2413
            m_startTime = av_rescale(st->cur_dts, st->time_base.num, st->time_base.den) - 0.000001;
2398
            m_startTime =
2399
                av_rescale(m_pkt.pkt.dts, st->time_base.num, st->time_base.den) - 0.000001;
2414
            m_seekStream = idx;
2400
            m_seekStream = idx;
2415
          }
2401
          }
2416
          return TRANSPORT_STREAM_STATE::READY;
2402
          return TRANSPORT_STREAM_STATE::READY;
Lines 2430-2436 Link Here
2430
        {
2416
        {
2431
          if (!m_startTime)
2417
          if (!m_startTime)
2432
          {
2418
          {
2433
            m_startTime = av_rescale(st->cur_dts, st->time_base.num, st->time_base.den) - 0.000001;
2419
            m_startTime =
2420
                av_rescale(m_pkt.pkt.dts, st->time_base.num, st->time_base.den) - 0.000001;
2434
            m_seekStream = i;
2421
            m_seekStream = i;
2435
          }
2422
          }
2436
          return TRANSPORT_STREAM_STATE::READY;
2423
          return TRANSPORT_STREAM_STATE::READY;
(-)xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp (-1 / +2 lines)
Lines 12-17 Link Here
12
#include "addons/addoninfo/AddonType.h"
12
#include "addons/addoninfo/AddonType.h"
13
#include "addons/binary-addons/AddonDll.h"
13
#include "addons/binary-addons/AddonDll.h"
14
#include "addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h"
14
#include "addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h"
15
#include "cores/FFmpeg.h"
15
#include "cores/VideoPlayer/DVDDemuxers/DVDDemux.h"
16
#include "cores/VideoPlayer/DVDDemuxers/DVDDemux.h"
16
#include "cores/VideoPlayer/DVDDemuxers/DVDDemuxUtils.h"
17
#include "cores/VideoPlayer/DVDDemuxers/DVDDemuxUtils.h"
17
#include "cores/VideoPlayer/Interface/DemuxCrypto.h"
18
#include "cores/VideoPlayer/Interface/DemuxCrypto.h"
Lines 392-398 Link Here
392
    return nullptr;
393
    return nullptr;
393
394
394
  std::string codecName(stream->m_codecName);
395
  std::string codecName(stream->m_codecName);
395
  AVCodec* codec = nullptr;
396
  const AVCodec* codec = nullptr;
396
397
397
  if (stream->m_streamType != INPUTSTREAM_TYPE_TELETEXT &&
398
  if (stream->m_streamType != INPUTSTREAM_TYPE_TELETEXT &&
398
      stream->m_streamType != INPUTSTREAM_TYPE_RDS && stream->m_streamType != INPUTSTREAM_TYPE_ID3)
399
      stream->m_streamType != INPUTSTREAM_TYPE_RDS && stream->m_streamType != INPUTSTREAM_TYPE_ID3)
(-)xbmc/filesystem/AudioBookFileDirectory.cpp (-1 / +2 lines)
Lines 11-16 Link Here
11
#include "TextureDatabase.h"
11
#include "TextureDatabase.h"
12
#include "URL.h"
12
#include "URL.h"
13
#include "Util.h"
13
#include "Util.h"
14
#include "cores/FFmpeg.h"
14
#include "filesystem/File.h"
15
#include "filesystem/File.h"
15
#include "guilib/LocalizeStrings.h"
16
#include "guilib/LocalizeStrings.h"
16
#include "music/tags/MusicInfoTag.h"
17
#include "music/tags/MusicInfoTag.h"
Lines 149-155 Link Here
149
150
150
  m_ioctx->max_packet_size = 32768;
151
  m_ioctx->max_packet_size = 32768;
151
152
152
  AVInputFormat* iformat=nullptr;
153
  const AVInputFormat* iformat = nullptr;
153
  av_probe_input_buffer(m_ioctx, &iformat, url.Get().c_str(), nullptr, 0, 0);
154
  av_probe_input_buffer(m_ioctx, &iformat, url.Get().c_str(), nullptr, 0, 0);
154
155
155
  bool contains = false;
156
  bool contains = false;
(-)xbmc/guilib/FFmpegImage.cpp (-5 / +6 lines)
Lines 52-58 Link Here
52
  AVFrame* frame_temporary = nullptr;
52
  AVFrame* frame_temporary = nullptr;
53
  SwsContext* sws = nullptr;
53
  SwsContext* sws = nullptr;
54
  AVCodecContext* avOutctx = nullptr;
54
  AVCodecContext* avOutctx = nullptr;
55
  AVCodec* codec = nullptr;
55
  const AVCodec* codec = nullptr;
56
  ~ThumbDataManagement()
56
  ~ThumbDataManagement()
57
  {
57
  {
58
    av_free(intermediateBuffer);
58
    av_free(intermediateBuffer);
Lines 198-204 Link Here
198
  bool is_png = (bufSize > 3 && buffer[1] == 'P' && buffer[2] == 'N' && buffer[3] == 'G');
198
  bool is_png = (bufSize > 3 && buffer[1] == 'P' && buffer[2] == 'N' && buffer[3] == 'G');
199
  bool is_tiff = (bufSize > 2 && buffer[0] == 'I' && buffer[1] == 'I' && buffer[2] == '*');
199
  bool is_tiff = (bufSize > 2 && buffer[0] == 'I' && buffer[1] == 'I' && buffer[2] == '*');
200
200
201
  AVInputFormat* inp = nullptr;
201
  const AVInputFormat* inp = nullptr;
202
  if (is_jpeg)
202
  if (is_jpeg)
203
    inp = av_find_input_format("image2");
203
    inp = av_find_input_format("image2");
204
  else if (m_strMimeType == "image/apng")
204
  else if (m_strMimeType == "image/apng")
Lines 236-242 Link Here
236
    return false;
236
    return false;
237
  }
237
  }
238
  AVCodecParameters* codec_params = m_fctx->streams[0]->codecpar;
238
  AVCodecParameters* codec_params = m_fctx->streams[0]->codecpar;
239
  AVCodec* codec = avcodec_find_decoder(codec_params->codec_id);
239
  const AVCodec* codec = avcodec_find_decoder(codec_params->codec_id);
240
  m_codec_ctx = avcodec_alloc_context3(codec);
240
  m_codec_ctx = avcodec_alloc_context3(codec);
241
  if (!m_codec_ctx)
241
  if (!m_codec_ctx)
242
  {
242
  {
Lines 294-300 Link Here
294
    return nullptr;
294
    return nullptr;
295
  }
295
  }
296
  //we need milliseconds
296
  //we need milliseconds
297
  frame->pkt_duration = av_rescale_q(frame->pkt_duration, m_fctx->streams[0]->time_base, AVRational{ 1, 1000 });
297
  frame->duration =
298
      av_rescale_q(frame->duration, m_fctx->streams[0]->time_base, AVRational{1, 1000});
298
  m_height = frame->height;
299
  m_height = frame->height;
299
  m_width = frame->width;
300
  m_width = frame->width;
300
  m_originalWidth = m_width;
301
  m_originalWidth = m_width;
Lines 745-751 Link Here
745
  if (avframe == nullptr)
746
  if (avframe == nullptr)
746
    return nullptr;
747
    return nullptr;
747
  std::shared_ptr<Frame> frame(new Frame());
748
  std::shared_ptr<Frame> frame(new Frame());
748
  frame->m_delay = (unsigned int)avframe->pkt_duration;
749
  frame->m_delay = (unsigned int)avframe->duration;
749
  frame->m_pitch = avframe->width * 4;
750
  frame->m_pitch = avframe->width * 4;
750
  frame->m_pImage = (unsigned char*) av_malloc(avframe->height * frame->m_pitch);
751
  frame->m_pImage = (unsigned char*) av_malloc(avframe->height * frame->m_pitch);
751
  DecodeFrame(avframe, avframe->width, avframe->height, frame->m_pitch, frame->m_pImage);
752
  DecodeFrame(avframe, avframe->width, avframe->height, frame->m_pitch, frame->m_pImage);
(-)xbmc/music/tags/MusicInfoTagLoaderFFmpeg.cpp (-1 / +1 lines)
Lines 58-64 Link Here
58
  if (file.IoControl(IOCTRL_SEEK_POSSIBLE, NULL) != 1)
58
  if (file.IoControl(IOCTRL_SEEK_POSSIBLE, NULL) != 1)
59
    ioctx->seekable = 0;
59
    ioctx->seekable = 0;
60
60
61
  AVInputFormat* iformat=NULL;
61
  const AVInputFormat* iformat = nullptr;
62
  av_probe_input_buffer(ioctx, &iformat, strFileName.c_str(), NULL, 0, 0);
62
  av_probe_input_buffer(ioctx, &iformat, strFileName.c_str(), NULL, 0, 0);
63
63
64
  if (avformat_open_input(&fctx, strFileName.c_str(), iformat, NULL) < 0)
64
  if (avformat_open_input(&fctx, strFileName.c_str(), iformat, NULL) < 0)
(-)xbmc/video/tags/VideoTagLoaderFFmpeg.cpp (-1 / +1 lines)
Lines 65-71 Link Here
65
  if (m_file->IoControl(IOCTRL_SEEK_POSSIBLE, nullptr) != 1)
65
  if (m_file->IoControl(IOCTRL_SEEK_POSSIBLE, nullptr) != 1)
66
    m_ioctx->seekable = 0;
66
    m_ioctx->seekable = 0;
67
67
68
  AVInputFormat* iformat = nullptr;
68
  const AVInputFormat* iformat = nullptr;
69
  av_probe_input_buffer(m_ioctx, &iformat, m_item.GetPath().c_str(), nullptr, 0, 0);
69
  av_probe_input_buffer(m_ioctx, &iformat, m_item.GetPath().c_str(), nullptr, 0, 0);
70
  if (avformat_open_input(&m_fctx, m_item.GetPath().c_str(), iformat, nullptr) < 0)
70
  if (avformat_open_input(&m_fctx, m_item.GetPath().c_str(), iformat, nullptr) < 0)
71
  {
71
  {

Return to bug 270237