Skip to content

Commit

Permalink
Port FFmpeg 7.0.2 to ffmpegdirect Piers
Browse files Browse the repository at this point in the history
From xbmc/xbmc#24972

Signed-off-by: Vasyl Gello <vasek.gello@gmail.com>
  • Loading branch information
basilgello committed Aug 19, 2024
1 parent 13e1460 commit 646ec08
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 163 deletions.
16 changes: 8 additions & 8 deletions FindFFMPEG.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
#

# required ffmpeg library versions
set(REQUIRED_FFMPEG_VERSION 5.0.0)
set(_avcodec_ver ">=59.18.100")
set(_avfilter_ver ">=8.24.100")
set(_avformat_ver ">=59.16.100")
set(_avutil_ver ">=57.17.100")
set(_postproc_ver ">=56.3.100")
set(_swresample_ver ">=4.3.100")
set(_swscale_ver ">=6.4.100")
set(REQUIRED_FFMPEG_VERSION 7.0.0)
set(_avcodec_ver ">=61.3.100")
set(_avfilter_ver ">=10.1.100")
set(_avformat_ver ">=61.1.100")
set(_avutil_ver ">=59.8.100")
set(_postproc_ver ">=58.1.100")
set(_swresample_ver ">=5.1.100")
set(_swscale_ver ">=8.1.100")

# Allows building with external ffmpeg not found in system paths,
# without library version checks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ index da457705d1..e3a8f45ff4 100755
--- a/configure
+++ b/configure
@@ -5566,6 +5566,8 @@ case $target_os in
enabled shared && ! enabled small && test_cmd $windres --version && enable gnu_windres
enabled x86_32 && check_ldflags -Wl,--large-address-aware
add_cppflags -DWIN32_LEAN_AND_MEAN
shlibdir_default="$bindir_default"
+ LIBPREF=""
+ LIBSUF=".lib"
SLIBPREF=""
SLIBSUF=".dll"
SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
@@ -5615,6 +5617,8 @@ case $target_os in
fi
enabled x86_32 && check_ldflags -LARGEADDRESSAWARE
add_cppflags -DWIN32_LEAN_AND_MEAN
shlibdir_default="$bindir_default"
+ LIBPREF=""
+ LIBSUF=".lib"
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions depends/common/ffmpeg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ if(NOT WIN32)
list(APPEND EXTRA_CONF --arch=aarch64)
list(APPEND EXTRA_CONF --disable-filter=yadif_videotoolbox)
endif()
list(APPEND EXTRA_CONF --disable-decoder=mpeg_xvmc --disable-crystalhd --enable-videotoolbox
list(APPEND EXTRA_CONF --disable-decoder=mpeg_xvmc --enable-videotoolbox
--target-os=darwin)
elseif(CORE_SYSTEM_NAME STREQUAL osx)
list(APPEND EXTRA_CONF --disable-decoder=mpeg_xvmc --disable-crystalhd --enable-videotoolbox
list(APPEND EXTRA_CONF --disable-decoder=mpeg_xvmc --enable-videotoolbox
--target-os=darwin
--disable-securetransport)
endif()
Expand Down
2 changes: 1 addition & 1 deletion depends/common/ffmpeg/ffmpeg.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9a1fa94608300e835bf89bdfcd7d77deceba67bff3494f609816f84bd69a459e
5eb46d18d664a0ccadf7b0adee03bd3b7fa72893d667f36c69e202a807e6d533
2 changes: 1 addition & 1 deletion depends/common/ffmpeg/ffmpeg.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ffmpeg https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n6.0.tar.gz
ffmpeg https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n7.0.2.tar.gz
125 changes: 34 additions & 91 deletions src/stream/FFmpegStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,74 +1012,7 @@ bool FFmpegStream::OpenWithCURL(const AVInputFormat* iformat)
if (iformat == nullptr)
{
// let ffmpeg decide which demuxer we have to open
bool trySPDIFonly = (m_curlInput->GetContent() == "audio/x-spdif-compressed");

if (!trySPDIFonly)
av_probe_input_buffer(m_ioContext, &iformat, strFile.c_str(), NULL, 0, 0);

// Use the more low-level code in case we have been built against an old
// FFmpeg without the above av_probe_input_buffer(), or in case we only
// want to probe for spdif (DTS or IEC 61937) compressed audio
// specifically, or in case the file is a wav which may contain DTS or
// IEC 61937 (e.g. ac3-in-wav) and we want to check for those formats.
if (trySPDIFonly || (iformat && strcmp(iformat->name, "wav") == 0))
{
AVProbeData pd;
int probeBufferSize = 32768;
std::unique_ptr<uint8_t[]> probe_buffer (new uint8_t[probeBufferSize + AVPROBE_PADDING_SIZE]);

// init probe data
pd.buf = probe_buffer.get();
pd.filename = strFile.c_str();

// read data using avformat's buffers
pd.buf_size = avio_read(m_ioContext, pd.buf, probeBufferSize);
if (pd.buf_size <= 0)
{
Log(LOGLEVEL_ERROR, "%s - error reading from input stream, %s", __FUNCTION__, CURL::GetRedacted(strFile).c_str());
return false;
}
memset(pd.buf + pd.buf_size, 0, AVPROBE_PADDING_SIZE);

// restore position again
avio_seek(m_ioContext , 0, SEEK_SET);

// the advancedsetting is for allowing the user to force outputting the
// 44.1 kHz DTS wav file as PCM, so that an A/V receiver can decode
// it (this is temporary until we handle 44.1 kHz passthrough properly)
if (trySPDIFonly || (iformat && strcmp(iformat->name, "wav") == 0)) // && !CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_VideoPlayerIgnoreDTSinWAV))
{
// check for spdif and dts
// This is used with wav files and audio CDs that may contain
// a DTS or AC3 track padded for S/PDIF playback. If neither of those
// is present, we assume it is PCM audio.
// AC3 is always wrapped in iec61937 (ffmpeg "spdif"), while DTS
// may be just padded.
const AVInputFormat* iformat2 = av_find_input_format("spdif");

if (iformat2 && iformat2->read_probe(&pd) > AVPROBE_SCORE_MAX / 4)
{
iformat = iformat2;
}
else
{
// not spdif or no spdif demuxer, try dts
iformat2 = av_find_input_format("dts");

if (iformat2 && iformat2->read_probe(&pd) > AVPROBE_SCORE_MAX / 4)
{
iformat = iformat2;
}
else if (trySPDIFonly)
{
// not dts either, return false in case we were explicitly
// requested to only check for S/PDIF padded compressed audio
Log(LOGLEVEL_DEBUG, "%s - not spdif or dts file, falling back", __FUNCTION__);
return false;
}
}
}
}
av_probe_input_buffer(m_ioContext, &iformat, strFile.c_str(), NULL, 0, 0);

if (!iformat)
{
Expand Down Expand Up @@ -1535,7 +1468,7 @@ bool FFmpegStream::SeekTime(double time, bool backwards, double* startpts)

if (ret >= 0)
{
if (m_pFormatContext->iformat->read_seek)
if (!(m_pFormatContext->iformat->flags & AVFMT_NOTIMESTAMPS))
m_seekToKeyFrame = true;

m_currentPts = STREAM_NOPTS_VALUE;
Expand Down Expand Up @@ -2059,43 +1992,49 @@ DemuxStream* FFmpegStream::AddStream(int streamIdx)
st->colorRange = pStream->codecpar->color_range;
st->hdr_type = DetermineHdrType(pStream);

// https://github.com/FFmpeg/FFmpeg/blob/release/5.0/doc/APIchanges
size_t size = 0;
uint8_t* side_data = nullptr;
// https://github.com/FFmpeg/FFmpeg/blob/release/7.0/doc/APIchanges
const AVPacketSideData* sideData = nullptr;

if (st->hdr_type == StreamHdrType::HDR_TYPE_DOLBYVISION)
{
side_data = av_stream_get_side_data(pStream, AV_PKT_DATA_DOVI_CONF, &size);
if (side_data && size)

sideData =
av_packet_side_data_get(pStream->codecpar->coded_side_data,
pStream->codecpar->nb_coded_side_data, AV_PKT_DATA_DOVI_CONF);
if (sideData && sideData->size)
{
st->dovi = *reinterpret_cast<AVDOVIDecoderConfigurationRecord*>(side_data);
st->dovi = *reinterpret_cast<const AVDOVIDecoderConfigurationRecord*>(sideData->data);
}
}

side_data = av_stream_get_side_data(pStream, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, &size);
if (side_data && size)
sideData = av_packet_side_data_get(pStream->codecpar->coded_side_data,
pStream->codecpar->nb_coded_side_data,
AV_PKT_DATA_MASTERING_DISPLAY_METADATA);
if (sideData && sideData->size)
{
st->masteringMetaData = std::make_shared<AVMasteringDisplayMetadata>(
*reinterpret_cast<AVMasteringDisplayMetadata*>(side_data));
*reinterpret_cast<const AVMasteringDisplayMetadata*>(sideData->data));
}

side_data = av_stream_get_side_data(pStream, AV_PKT_DATA_CONTENT_LIGHT_LEVEL, &size);
if (side_data && size)
sideData = av_packet_side_data_get(pStream->codecpar->coded_side_data,
pStream->codecpar->nb_coded_side_data,
AV_PKT_DATA_CONTENT_LIGHT_LEVEL);
if (sideData && sideData->size)
{
st->contentLightMetaData = std::make_shared<AVContentLightMetadata>(
*reinterpret_cast<AVContentLightMetadata*>(side_data));
*reinterpret_cast<const AVContentLightMetadata*>(sideData->data));
}

AVDictionaryEntry* rtag = av_dict_get(pStream->metadata, "rotate", NULL, 0);
uint8_t* displayMatrixSideData =
av_stream_get_side_data(pStream, AV_PKT_DATA_DISPLAYMATRIX, nullptr);
if (displayMatrixSideData)
sideData = av_packet_side_data_get(pStream->codecpar->coded_side_data,
pStream->codecpar->nb_coded_side_data,
AV_PKT_DATA_DISPLAYMATRIX);
if (sideData)
{
const double tetha =
av_display_rotation_get(reinterpret_cast<int32_t*>(displayMatrixSideData));
if (!std::isnan(tetha))
const double theta =
av_display_rotation_get(reinterpret_cast<const int32_t*>(sideData->data));
if (!std::isnan(theta))
{
st->iOrientation = ((static_cast<int>(-tetha) % 360) + 360) % 360;
st->iOrientation = ((static_cast<int>(-theta) % 360) + 360) % 360;
}
}

Expand Down Expand Up @@ -2271,15 +2210,19 @@ StreamHdrType FFmpegStream::DetermineHdrType(AVStream* pStream)
{
StreamHdrType hdrType = StreamHdrType::HDR_TYPE_NONE;

if (av_stream_get_side_data(pStream, AV_PKT_DATA_DOVI_CONF, nullptr)) // DoVi
if (av_packet_side_data_get(pStream->codecpar->coded_side_data,
pStream->codecpar->nb_coded_side_data,
AV_PKT_DATA_DOVI_CONF)) // DoVi
hdrType = StreamHdrType::HDR_TYPE_DOLBYVISION;
else if (pStream->codecpar->color_trc == AVCOL_TRC_SMPTE2084) // HDR10
hdrType = StreamHdrType::HDR_TYPE_HDR10;
else if (pStream->codecpar->color_trc == AVCOL_TRC_ARIB_STD_B67) // HLG
hdrType = StreamHdrType::HDR_TYPE_HLG;
// file could be SMPTE2086 which FFmpeg currently returns as unknown
// so use the presence of static metadata to detect it
else if (av_stream_get_side_data(pStream, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, nullptr))
else if (av_packet_side_data_get(pStream->codecpar->coded_side_data,
pStream->codecpar->nb_coded_side_data,
AV_PKT_DATA_MASTERING_DISPLAY_METADATA))
hdrType = StreamHdrType::HDR_TYPE_HDR10;

return hdrType;
Expand Down

0 comments on commit 646ec08

Please sign in to comment.