From 3df27e289bb93703aa6b47fc0019f7d9a19c339e Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 7 Feb 2023 00:03:51 +0100 Subject: [PATCH] Brought back deprecated code for older ffmpeg builds Signed-off-by: Alexis Maiquez --- src/WallpaperEngine/Audio/CAudioStream.cpp | 23 +++++++++++++++++++++- src/WallpaperEngine/Audio/CAudioStream.h | 4 ++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/WallpaperEngine/Audio/CAudioStream.cpp b/src/WallpaperEngine/Audio/CAudioStream.cpp index 710b150..ebd08a2 100644 --- a/src/WallpaperEngine/Audio/CAudioStream.cpp +++ b/src/WallpaperEngine/Audio/CAudioStream.cpp @@ -197,8 +197,12 @@ void CAudioStream::loadCustomContent (const char* filename) void CAudioStream::initialize () { +#if FF_API_FIFO_OLD_API // allocate the FIFO buffer this->m_queue->packetList = av_fifo_alloc2 (1, sizeof (MyAVPacketList), AV_FIFO_FLAG_AUTO_GROW); +#else + this->m_queue->packetList = av_fifo_alloc (sizeof (MyAVPacketList)); +#endif // setup the queue information this->m_queue->mutex = SDL_CreateMutex (); @@ -233,9 +237,17 @@ bool CAudioStream::doQueue (AVPacket* pkt) { MyAVPacketList entry { pkt }; +#if FF_API_FIFO_OLD_API // write the entry if possible if (av_fifo_write (this->m_queue->packetList, &entry, 1) < 0) return false; +#else + if (av_fifo_space (this->m_queue->packetList) < sizeof (entry)) + if (av_fifo_grow (this->m_queue->packetList, sizeof (entry)) < 0) + return false; + + av_fifo_generic_write (this->m_queue->packetList, &entry, sizeof (entry), nullptr); +#endif this->m_queue->nb_packets ++; this->m_queue->size += entry.packet->size + sizeof (entry); @@ -254,8 +266,17 @@ void CAudioStream::dequeuePacket (AVPacket* output) while (g_KeepRunning) { + int ret = -1; + +#if FF_API_FIFO_OLD_API + ret = av_fifo_read (this->m_queue->packetList, &entry, 1); +#else + if (av_fifo_size (this->m_queue->packetList) >= sizeof (entry)) + ret = av_fifo_generic_read (this->n_queue->packetList, &entry, sizeof (entry), nullptr); +#endif + // enough data available, read it - if (av_fifo_read (this->m_queue->packetList, &entry, 1) >= 0) + if (ret >= 0) { this->m_queue->nb_packets --; this->m_queue->size -= entry.packet->size + sizeof (entry); diff --git a/src/WallpaperEngine/Audio/CAudioStream.h b/src/WallpaperEngine/Audio/CAudioStream.h index 3c4652f..90da77d 100644 --- a/src/WallpaperEngine/Audio/CAudioStream.h +++ b/src/WallpaperEngine/Audio/CAudioStream.h @@ -81,7 +81,11 @@ namespace WallpaperEngine::Audio struct PacketQueue { + #if FF_API_FIFO_OLD_API AVFifo* packetList; + #else + AVFifoBuffer* packetList; + #endif int nb_packets; int size; int64_t duration;