Tested on amd64 with current ffmpeg. OK rsadowski

On Tue Oct 29, 2024 at 12:31:48PM +0000, Stuart Henderson wrote:
> REVISION needs re-bumping, but otherwise this still applies.
> 
> +cc maintainer
> 
> 
> ----- Forwarded message from Brad Smith <b...@comstyle.com> -----
> 
> From: Brad Smith <b...@comstyle.com>
> Date: Sat, 3 Aug 2024 13:04:01 -0400
> To: ports@openbsd.org
> Subject: UPDATE: OpenSceneGraph - FFmpeg
> 
> Here is a diff to fix building OpenSceneGraph with newer FFmpeg.
> 
> Please test.
> 
> 
> Index: Makefile
> ===================================================================
> RCS file: /cvs/ports/graphics/openscenegraph/Makefile,v
> retrieving revision 1.34
> diff -u -p -u -p -r1.34 Makefile
> --- Makefile  15 Nov 2023 17:55:22 -0000      1.34
> +++ Makefile  3 Aug 2024 16:51:08 -0000
> @@ -10,7 +10,7 @@ GH_ACCOUNT =                openscenegraph
>  GH_PROJECT =         OpenSceneGraph
>  GH_TAGNAME =         OpenSceneGraph-$V
>  DISTNAME =           openscenegraph-${V}
> -REVISION =           5
> +REVISION =           6
>  
>  SUBST_VARS +=                V
>  
> Index: patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_cpp
> ===================================================================
> RCS file: patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_cpp
> diff -N patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_cpp
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_cpp        3 Aug 
> 2024 16:51:08 -0000
> @@ -0,0 +1,83 @@
> +Fix building with newer FFmpeg
> +
> +Index: src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp
> +--- src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp.orig
> ++++ src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp
> +@@ -13,15 +13,6 @@
> + #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000
> + #endif
> + 
> +-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
> +-#define av_frame_alloc  avcodec_alloc_frame
> +-#define av_frame_free  avcodec_free_frame
> +-#endif
> +-
> +-#if LIBAVCODEC_VERSION_MAJOR < 56
> +-   #define AV_CODEC_ID_NONE CODEC_ID_NONE
> +-#endif
> +-
> + namespace osgFFmpeg {
> + 
> + static int decode_audio(AVCodecContext *avctx, int16_t *samples,
> +@@ -32,25 +23,23 @@ static int decode_audio(AVCodecContext *avctx, int16_t
> +                          int out_nb_channels,
> +                          AVSampleFormat out_sample_format)
> + {
> +-#if LIBAVCODEC_VERSION_MAJOR >= 53 || (LIBAVCODEC_VERSION_MAJOR==52 && 
> LIBAVCODEC_VERSION_MINOR>=32)
> +-
> +     AVPacket avpkt;
> +     av_init_packet(&avpkt);
> +     avpkt.data = const_cast<uint8_t *>(buf);
> +     avpkt.size = buf_size;
> + 
> +     AVFrame *frame = av_frame_alloc();
> +-    int ret, got_frame = 0;
> ++    int ret;
> + 
> +     if (!frame)
> +         return AVERROR(ENOMEM);
> + 
> +-    ret = avcodec_decode_audio4(avctx, frame, &got_frame, &avpkt);
> ++    ret = avcodec_receive_frame(avctx, frame);
> + 
> + #ifdef USE_AVRESAMPLE    // libav's AVFrame structure does not contain a 
> 'channels' field
> +-    if (ret >= 0 && got_frame) {
> ++    if (ret >= 0) {
> + #else
> +-    if (ret >= 0 && got_frame && av_frame_get_channels(frame)>0) {
> ++    if (ret >= 0 && frame->channels>0) {
> + #endif
> +         int ch, plane_size;
> +         int planar = av_sample_fmt_is_planar(avctx->sample_fmt);
> +@@ -108,11 +97,6 @@ static int decode_audio(AVCodecContext *avctx, int16_t
> +     }
> +     av_frame_free(&frame);
> +     return ret;
> +-
> +-#else
> +-    // fallback for older versions of ffmpeg that don't have 
> avcodec_decode_audio3.
> +-    return avcodec_decode_audio2(avctx, samples, frame_size_ptr, buf, 
> buf_size);
> +-#endif
> + }
> + 
> + 
> +@@ -151,7 +135,9 @@ void FFmpegDecoderAudio::open(AVStream * const stream,
> +             return;
> + 
> +         m_stream = stream;
> +-        m_context = stream->codec;
> ++        m_codecpar = stream->codecpar;
> ++        const AVCodec* p_codec = avcodec_find_decoder(m_codecpar->codec_id);
> ++        m_context = avcodec_alloc_context3(p_codec);
> + 
> +         m_in_sample_rate = m_context->sample_rate;
> +         m_in_nb_channels = m_context->channels;
> +@@ -214,7 +200,7 @@ printf("### CONVERTING from sample format %s TO %s\n\t
> +             throw std::runtime_error("invalid audio codec");;
> + 
> +         // Find the decoder for the audio stream
> +-        AVCodec * const p_codec = avcodec_find_decoder(m_context->codec_id);
> ++        p_codec = avcodec_find_decoder(m_context->codec_id);
> + 
> +         if (p_codec == 0)
> +             throw std::runtime_error("avcodec_find_decoder() failed");
> Index: patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_hpp
> ===================================================================
> RCS file: patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_hpp
> diff -N patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_hpp
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_hpp        3 Aug 
> 2024 16:51:08 -0000
> @@ -0,0 +1,13 @@
> +Fix building with newer FFmpeg
> +
> +Index: src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp
> +--- src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp.orig
> ++++ src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp
> +@@ -59,6 +59,7 @@ class FFmpegDecoderAudio : public OpenThreads::Thread 
> +     PacketQueue &                       m_packets;
> +     FFmpegClocks &                      m_clocks;
> +     AVStream *                          m_stream;
> ++    AVCodecParameters *                 m_codecpar;
> +     AVCodecContext *                    m_context;
> +     FFmpegPacket                        m_packet;
> +     const uint8_t *                     m_packet_data;
> Index: patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_cpp
> ===================================================================
> RCS file: patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_cpp
> diff -N patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_cpp
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_cpp        3 Aug 
> 2024 16:51:08 -0000
> @@ -0,0 +1,134 @@
> +Fix building with newer FFmpeg
> +
> +Index: src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp
> +--- src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp.orig
> ++++ src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp
> +@@ -62,7 +62,9 @@ FFmpegDecoderVideo::~FFmpegDecoderVideo()
> + void FFmpegDecoderVideo::open(AVStream * const stream)
> + {
> +     m_stream = stream;
> +-    m_context = stream->codec;
> ++    m_codecpar = stream->codecpar;
> ++    const AVCodec* p_codec = avcodec_find_decoder(m_codecpar->codec_id);
> ++    m_context = avcodec_alloc_context3(p_codec);
> + 
> +     // Trust the video size given at this point
> +     // (avcodec_open seems to sometimes return a 0x0 size)
> +@@ -74,11 +76,7 @@ void FFmpegDecoderVideo::open(AVStream * const stream)
> +     m_alpha_channel = (m_context->pix_fmt == AV_PIX_FMT_YUVA420P);
> + 
> +     // Find out the framerate
> +-    #if LIBAVCODEC_VERSION_MAJOR >= 56
> +     m_frame_rate = av_q2d(stream->avg_frame_rate);
> +-    #else
> +-    m_frame_rate = av_q2d(stream->r_frame_rate);
> +-    #endif
> + 
> +     // Find the decoder for the video stream
> +     m_codec = avcodec_find_decoder(m_context->codec_id);
> +@@ -99,11 +97,12 @@ void FFmpegDecoderVideo::open(AVStream * const stream)
> + 
> +     // Allocate converted RGB frame
> +     m_frame_rgba.reset(av_frame_alloc());
> +-    m_buffer_rgba[0].resize(avpicture_get_size(AV_PIX_FMT_RGB24, width(), 
> height()));
> ++    m_buffer_rgba[0].resize(av_image_get_buffer_size(AV_PIX_FMT_RGB24, 
> width(), height(), 1));
> +     m_buffer_rgba[1].resize(m_buffer_rgba[0].size());
> + 
> +     // Assign appropriate parts of the buffer to image planes in 
> m_frame_rgba
> +-    avpicture_fill((AVPicture *) (m_frame_rgba).get(), 
> &(m_buffer_rgba[0])[0], AV_PIX_FMT_RGB24, width(), height());
> ++    AVFrame *avf = m_frame_rgba.get();
> ++    av_image_fill_arrays(avf->data, avf->linesize, &(m_buffer_rgba[0])[0], 
> AV_PIX_FMT_RGB24, width(), height(), 1);
> + 
> +     // Override get_buffer()/release_buffer() from codec context in order 
> to retrieve the PTS of each frame.
> +     m_context->opaque = this;
> +@@ -169,7 +168,7 @@ void FFmpegDecoderVideo::decodeLoop()
> +             int frame_finished = 0;
> + 
> +             // We want to use the entire packet since some codecs will 
> require extra information for decoding
> +-            const int bytes_decoded = avcodec_decode_video2(m_context, 
> m_frame.get(), &frame_finished, &(packet.packet));
> ++            const int bytes_decoded = avcodec_receive_frame(m_context, 
> m_frame.get());
> + 
> +             if (bytes_decoded < 0)
> +                 throw std::runtime_error("avcodec_decode_video failed()");
> +@@ -180,40 +179,9 @@ void FFmpegDecoderVideo::decodeLoop()
> +             // Publish the frame if we have decoded a complete frame
> +             if (frame_finished)
> +             {
> +-#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(57,24,102)
> +-                //ffmpeg-3.0 and below
> +-                AVRational timebase;
> +                 // Find out the frame pts
> +                 if (m_frame->pts != int64_t(AV_NOPTS_VALUE))
> +                 {
> +-                    pts = m_frame->pts;
> +-                    timebase = m_context->time_base;
> +-                }
> +-                else if (packet.packet.dts == int64_t(AV_NOPTS_VALUE) &&
> +-                        m_frame->opaque != 0 &&
> +-                        *reinterpret_cast<const int64_t*>(m_frame->opaque) 
> != int64_t(AV_NOPTS_VALUE))
> +-                {
> +-                    pts = *reinterpret_cast<const 
> int64_t*>(m_frame->opaque);
> +-                    timebase = m_stream->time_base;
> +-                }
> +-                else if (packet.packet.dts != int64_t(AV_NOPTS_VALUE))
> +-                {
> +-                    pts = packet.packet.dts;
> +-                    timebase = m_stream->time_base;
> +-                }
> +-                else
> +-                {
> +-                    pts = 0;
> +-                    timebase = m_context->time_base;
> +-                }
> +-
> +-                pts *= av_q2d(timebase);
> +-
> +-#else
> +-                //above ffmpeg-3.0
> +-                // Find out the frame pts
> +-                if (m_frame->pts != int64_t(AV_NOPTS_VALUE))
> +-                {
> +                     pts = av_q2d(m_stream->time_base) * m_frame->pts;
> +                 }
> +                 else if (packet.packet.dts == int64_t(AV_NOPTS_VALUE) &&
> +@@ -230,7 +198,6 @@ void FFmpegDecoderVideo::decodeLoop()
> +                 {
> +                     pts = 0;
> +                 }
> +-#endif
> +                 const double synched_pts = 
> m_clocks.videoSynchClock(m_frame.get(), 
> av_q2d(av_inv_q(m_context->framerate)), pts);
> +                 const double frame_delay = 
> m_clocks.videoRefreshSchedule(synched_pts);
> + 
> +@@ -283,7 +250,7 @@ void FFmpegDecoderVideo::findAspectRatio()
> +     m_pixel_aspect_ratio = ratio;
> + }
> + 
> +-int FFmpegDecoderVideo::convert(AVPicture *dst, int dst_pix_fmt, AVPicture 
> *src,
> ++int FFmpegDecoderVideo::convert(AVFrame *dst, int dst_pix_fmt, AVFrame *src,
> +             int src_pix_fmt, int src_width, int src_height)
> + {
> +     osg::Timer_t startTick = osg::Timer::instance()->tick();
> +@@ -334,11 +301,11 @@ void FFmpegDecoderVideo::publishFrame(const double del
> +         return;
> + #endif
> + 
> +-    AVPicture * const src = (AVPicture *) m_frame.get();
> +-    AVPicture * const dst = (AVPicture *) m_frame_rgba.get();
> ++    AVFrame * const src = (AVFrame *) m_frame.get();
> ++    AVFrame * const dst = (AVFrame *) m_frame_rgba.get();
> + 
> +     // Assign appropriate parts of the buffer to image planes in 
> m_frame_rgba
> +-    avpicture_fill((AVPicture *) (m_frame_rgba).get(), 
> &(m_buffer_rgba[m_writeBuffer])[0], AV_PIX_FMT_RGB24, width(), height());
> ++    av_image_fill_arrays(dst->data, dst->linesize, 
> &(m_buffer_rgba[m_writeBuffer])[0], AV_PIX_FMT_RGB24, width(), height(), 1);
> + 
> +     // Convert YUVA420p (i.e. YUV420p plus alpha channel) using our own 
> routine
> + 
> +@@ -370,7 +337,7 @@ void FFmpegDecoderVideo::publishFrame(const double del
> + 
> + 
> + 
> +-void FFmpegDecoderVideo::yuva420pToRgba(AVPicture * const dst, AVPicture * 
> const src, int width, int height)
> ++void FFmpegDecoderVideo::yuva420pToRgba(AVFrame * const dst, AVFrame * 
> const src, int width, int height)
> + {
> +     convert(dst, AV_PIX_FMT_RGB24, src, m_context->pix_fmt, width, height);
> + 
> Index: patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_hpp
> ===================================================================
> RCS file: patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_hpp
> diff -N patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_hpp
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_hpp        3 Aug 
> 2024 16:51:08 -0000
> @@ -0,0 +1,28 @@
> +Fix building with newer FFmpeg
> +
> +Index: src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp
> +--- src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp.orig
> ++++ src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp
> +@@ -88,9 +88,9 @@ class FFmpegDecoderVideo : public OpenThreads::Thread 
> +     void findAspectRatio();
> +     void publishFrame(double delay, bool audio_disabled);
> +     double synchronizeVideo(double pts);
> +-    void yuva420pToRgba(AVPicture *dst, AVPicture *src, int width, int 
> height);
> ++    void yuva420pToRgba(AVFrame *dst, AVFrame *src, int width, int height);
> + 
> +-    int convert(AVPicture *dst, int dst_pix_fmt, AVPicture *src,
> ++    int convert(AVFrame *dst, int dst_pix_fmt, AVFrame *src,
> +                 int src_pix_fmt, int src_width, int src_height);
> + 
> + 
> +@@ -100,8 +100,9 @@ class FFmpegDecoderVideo : public OpenThreads::Thread 
> +     PacketQueue &           m_packets;
> +     FFmpegClocks &          m_clocks;
> +     AVStream *              m_stream;
> ++    AVCodecParameters *     m_codecpar;
> +     AVCodecContext *        m_context;
> +-    AVCodec *               m_codec;
> ++    const AVCodec *         m_codec;
> +     const uint8_t *         m_packet_data;
> +     int                     m_bytes_remaining;
> +     int64_t                 m_packet_pts;
> Index: patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoder_cpp
> ===================================================================
> RCS file: patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoder_cpp
> diff -N patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoder_cpp
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoder_cpp     3 Aug 2024 
> 16:51:08 -0000
> @@ -0,0 +1,52 @@
> +Fix building with newer FFmpeg
> +
> +Index: src/osgPlugins/ffmpeg/FFmpegDecoder.cpp
> +--- src/osgPlugins/ffmpeg/FFmpegDecoder.cpp.orig
> ++++ src/osgPlugins/ffmpeg/FFmpegDecoder.cpp
> +@@ -11,12 +11,6 @@
> + #include <string.h>
> + #include <iostream>
> + 
> +-// Changes for FFMpeg version greater than 0.6
> +-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 64, 0)
> +-#define CODEC_TYPE_AUDIO AVMEDIA_TYPE_AUDIO
> +-#define CODEC_TYPE_VIDEO AVMEDIA_TYPE_VIDEO
> +-#endif
> +-
> + #ifdef AVERROR
> + #define AVERROR_IO AVERROR(EIO)
> + #define AVERROR_NUMEXPECTED AVERROR(EDOM)
> +@@ -62,7 +56,11 @@ bool FFmpegDecoder::open(const std::string & filename,
> +     {
> +         // Open video file
> +         AVFormatContext * p_format_context = 0;
> ++#if LIBAVCODEC_VERSION_MAJOR >= 59
> ++        const AVInputFormat *iformat = 0;
> ++#else
> +         AVInputFormat *iformat = 0;
> ++#endif
> + 
> +         if (filename.compare(0, 5, "/dev/")==0)
> +         {
> +@@ -93,7 +91,7 @@ bool FFmpegDecoder::open(const std::string & filename,
> +         }
> +         else
> +         {
> +-            iformat = parameters ? parameters->getFormat() : 0;
> ++            iformat = parameters ? 
> const_cast<AVInputFormat*>(parameters->getFormat()) : 0;
> +             AVIOContext* context = parameters ? parameters->getContext() : 
> 0;
> +             if (context != NULL)
> +             {
> +@@ -304,9 +302,9 @@ bool FFmpegDecoder::readNextPacketNormal()
> +         else
> +         {
> +             // Make the packet data available beyond av_read_frame() 
> logical scope.
> +-            if ((error = av_dup_packet(&packet)) < 0) {
> +-                OSG_FATAL << "av_dup_packet() returned " << 
> AvStrError(error) << std::endl;
> +-                throw std::runtime_error("av_dup_packet() failed");
> ++            if ((error = av_packet_make_refcounted(&packet)) < 0) {
> ++                OSG_FATAL << "av_packet_make_refcounted() returned " << 
> AvStrError(error) << std::endl;
> ++                throw std::runtime_error("av_packet_make_refcounted() 
> failed");
> +             }
> + 
> +             m_pending_packet = FFmpegPacket(packet);
> Index: patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoder_hpp
> ===================================================================
> RCS file: patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoder_hpp
> diff -N patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoder_hpp
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoder_hpp     3 Aug 2024 
> 16:51:08 -0000
> @@ -0,0 +1,19 @@
> +Fix building with newer FFmpeg
> +
> +Index: src/osgPlugins/ffmpeg/FFmpegDecoder.hpp
> +--- src/osgPlugins/ffmpeg/FFmpegDecoder.hpp.orig
> ++++ src/osgPlugins/ffmpeg/FFmpegDecoder.hpp
> +@@ -46,13 +46,8 @@ class FormatContextPtr
> +         {
> +             if (_ptr) 
> +             {
> +-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 17, 0)
> +                 OSG_NOTICE<<"Calling 
> avformat_close_input("<<&_ptr<<")"<<std::endl;
> +                 avformat_close_input(&_ptr);
> +-#else
> +-                OSG_NOTICE<<"Calling 
> av_close_input_file("<<_ptr<<")"<<std::endl;
> +-                av_close_input_file(_ptr);
> +-#endif
> +             }
> +             _ptr = 0;
> +         }
> Index: patches/patch-src_osgPlugins_ffmpeg_FFmpegHeaders_hpp
> ===================================================================
> RCS file: patches/patch-src_osgPlugins_ffmpeg_FFmpegHeaders_hpp
> diff -N patches/patch-src_osgPlugins_ffmpeg_FFmpegHeaders_hpp
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_osgPlugins_ffmpeg_FFmpegHeaders_hpp     3 Aug 2024 
> 16:51:08 -0000
> @@ -0,0 +1,34 @@
> +Fix building with newer FFmpeg
> +
> +Index: src/osgPlugins/ffmpeg/FFmpegHeaders.hpp
> +--- src/osgPlugins/ffmpeg/FFmpegHeaders.hpp.orig
> ++++ src/osgPlugins/ffmpeg/FFmpegHeaders.hpp
> +@@ -5,7 +5,6 @@
> + 
> + extern "C"
> + {
> +-#define FF_API_OLD_SAMPLE_FMT 0
> + #include <errno.h>    // for error codes defined in avformat.h
> + #include <stdint.h>
> + #include <libavcodec/avcodec.h>
> +@@ -44,19 +43,10 @@ extern "C"
> + #endif
> + 
> + #include <libavutil/mathematics.h>
> ++#include <libavutil/imgutils.h>
> + 
> + #ifdef USE_SWSCALE
> +     #include <libswscale/swscale.h>
> +-#endif
> +-
> +-#if LIBAVUTIL_VERSION_INT <  AV_VERSION_INT(50,38,0)
> +-#define AV_SAMPLE_FMT_NONE SAMPLE_FMT_NONE
> +-#define AV_SAMPLE_FMT_U8   SAMPLE_FMT_U8
> +-#define AV_SAMPLE_FMT_S16  SAMPLE_FMT_S16
> +-#define AV_SAMPLE_FMT_S32  SAMPLE_FMT_S32
> +-#define AV_SAMPLE_FMT_FLT  SAMPLE_FMT_FLT
> +-#define AV_SAMPLE_FMT_DBL  SAMPLE_FMT_DBL
> +-#define AV_SAMPLE_FMT_NB   SAMPLE_FMT_NB
> + #endif
> + 
> + }
> Index: patches/patch-src_osgPlugins_ffmpeg_FFmpegPacket_hpp
> ===================================================================
> RCS file: patches/patch-src_osgPlugins_ffmpeg_FFmpegPacket_hpp
> diff -N patches/patch-src_osgPlugins_ffmpeg_FFmpegPacket_hpp
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_osgPlugins_ffmpeg_FFmpegPacket_hpp      3 Aug 2024 
> 16:51:08 -0000
> @@ -0,0 +1,14 @@
> +Fix building with newer FFmpeg
> +
> +Index: src/osgPlugins/ffmpeg/FFmpegPacket.hpp
> +--- src/osgPlugins/ffmpeg/FFmpegPacket.hpp.orig
> ++++ src/osgPlugins/ffmpeg/FFmpegPacket.hpp
> +@@ -42,7 +42,7 @@ namespace osgFFmpeg
> +         void clear()
> +         {
> +             if (packet.data != 0)
> +-                av_free_packet(&packet);
> ++                av_packet_unref(&packet);
> + 
> +             release();
> +         }
> Index: patches/patch-src_osgPlugins_ffmpeg_FFmpegParameters_cpp
> ===================================================================
> RCS file: patches/patch-src_osgPlugins_ffmpeg_FFmpegParameters_cpp
> diff -N patches/patch-src_osgPlugins_ffmpeg_FFmpegParameters_cpp
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_osgPlugins_ffmpeg_FFmpegParameters_cpp  3 Aug 2024 
> 16:51:08 -0000
> @@ -0,0 +1,23 @@
> +Fix building with newer FFmpeg
> +
> +Index: src/osgPlugins/ffmpeg/FFmpegParameters.cpp
> +--- src/osgPlugins/ffmpeg/FFmpegParameters.cpp.orig
> ++++ src/osgPlugins/ffmpeg/FFmpegParameters.cpp
> +@@ -5,17 +5,9 @@
> + #include <iostream>
> + #include <sstream>
> + 
> +-#if LIBAVCODEC_VERSION_MAJOR >= 53
> + extern "C"
> + {
> +     #include <libavutil/parseutils.h>
> +-}
> +-#define av_parse_video_frame_size av_parse_video_size
> +-#define av_parse_video_frame_rate av_parse_video_rate
> +-#endif
> +-
> +-extern "C"
> +-{
> +     #include <libavutil/pixdesc.h>
> + }
> + 
> Index: patches/patch-src_osgPlugins_ffmpeg_FFmpegParameters_hpp
> ===================================================================
> RCS file: patches/patch-src_osgPlugins_ffmpeg_FFmpegParameters_hpp
> diff -N patches/patch-src_osgPlugins_ffmpeg_FFmpegParameters_hpp
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_osgPlugins_ffmpeg_FFmpegParameters_hpp  3 Aug 2024 
> 16:51:08 -0000
> @@ -0,0 +1,23 @@
> +Fix building with newer FFmpeg
> +
> +Index: src/osgPlugins/ffmpeg/FFmpegParameters.hpp
> +--- src/osgPlugins/ffmpeg/FFmpegParameters.hpp.orig
> ++++ src/osgPlugins/ffmpeg/FFmpegParameters.hpp
> +@@ -20,7 +20,7 @@ class FFmpegParameters : public osg::Referenced (publi
> + 
> +     bool isFormatAvailable() const { return m_format!=NULL; }
> +     
> +-    AVInputFormat* getFormat() { return m_format; }
> ++    const AVInputFormat* getFormat() { return m_format; }
> +     AVDictionary** getOptions() { return &m_options; }
> +     void setContext(AVIOContext* context) { m_context = context; }
> +     AVIOContext* getContext() { return m_context; }
> +@@ -29,7 +29,7 @@ class FFmpegParameters : public osg::Referenced (publi
> + 
> + protected:
> + 
> +-    AVInputFormat* m_format;
> ++    const AVInputFormat* m_format;
> +     AVIOContext* m_context;
> +     AVDictionary* m_options;
> + };
> Index: patches/patch-src_osgPlugins_ffmpeg_ReaderWriterFFmpeg_cpp
> ===================================================================
> RCS file: patches/patch-src_osgPlugins_ffmpeg_ReaderWriterFFmpeg_cpp
> diff -N patches/patch-src_osgPlugins_ffmpeg_ReaderWriterFFmpeg_cpp
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_osgPlugins_ffmpeg_ReaderWriterFFmpeg_cpp        3 Aug 
> 2024 16:51:08 -0000
> @@ -0,0 +1,73 @@
> +Fix building with newer FFmpeg
> +
> +Index: src/osgPlugins/ffmpeg/ReaderWriterFFmpeg.cpp
> +--- src/osgPlugins/ffmpeg/ReaderWriterFFmpeg.cpp.orig
> ++++ src/osgPlugins/ffmpeg/ReaderWriterFFmpeg.cpp
> +@@ -19,13 +19,6 @@
> + #include <osgDB/FileNameUtils>
> + #include <osgDB/FileUtils>
> + 
> +-
> +-#if LIBAVCODEC_VERSION_MAJOR >= 53 || \
> +-    (LIBAVCODEC_VERSION_MAJOR==52 && LIBAVCODEC_VERSION_MINOR>=30) || \
> +-    (LIBAVCODEC_VERSION_MAJOR==52 && LIBAVCODEC_VERSION_MINOR==20 && 
> LIBAVCODEC_VERSION_MICRO >= 1)
> +-    #define USE_AV_LOCK_MANAGER
> +-#endif
> +-
> + extern "C" {
> + 
> + static void log_to_osg(void* /*ptr*/, int level, const char *fmt, va_list 
> vl)
> +@@ -113,13 +106,6 @@ class ReaderWriterFFmpeg : public osgDB::ReaderWriter 
> + 
> +         av_log_set_callback(log_to_osg);
> + 
> +-#ifdef USE_AV_LOCK_MANAGER
> +-        // enable thread locking
> +-        av_lockmgr_register(&lockMgr);
> +-#endif
> +-        // Register all FFmpeg formats/codecs
> +-        av_register_all();
> +-
> +         avformat_network_init();
> +     }
> + 
> +@@ -218,39 +204,6 @@ class ReaderWriterFFmpeg : public osgDB::ReaderWriter 
> +             }
> +         }
> +     }
> +-
> +-#ifdef USE_AV_LOCK_MANAGER
> +-    static int lockMgr(void **mutex, enum AVLockOp op)
> +-    {
> +-        // returns are 0 success
> +-        OpenThreads::Mutex **m=(OpenThreads::Mutex**)mutex;
> +-        if (op==AV_LOCK_CREATE)
> +-        {
> +-            *m=new OpenThreads::Mutex;
> +-            return !*m;
> +-        }
> +-        else if (op==AV_LOCK_DESTROY)
> +-        {
> +-            delete *m;
> +-            return 0;
> +-        }
> +-        else if (op==AV_LOCK_OBTAIN)
> +-        {
> +-            (*m)->lock();
> +-            return 0;
> +-        }
> +-        else if (op==AV_LOCK_RELEASE)
> +-        {
> +-            (*m)->unlock();
> +-            return 0;
> +-        }
> +-        else
> +-        {
> +-            return -1;
> +-        }
> +-    }
> +-#endif
> +-
> + };
> + 
> + 
> 
> 
> ----- End forwarded message -----
> 

Reply via email to