Here is a diff to fix building stepmania against newer FFmpeg.
Index: Makefile =================================================================== RCS file: /home/cvs/ports/games/stepmania/Makefile,v retrieving revision 1.35 diff -u -p -u -p -r1.35 Makefile --- Makefile 5 Nov 2022 17:10:21 -0000 1.35 +++ Makefile 7 May 2023 00:11:27 -0000 @@ -6,16 +6,15 @@ CATEGORIES = games emulators DISTNAME = stepmania-5.0.12 HOMEPAGE = http://www.stepmania.com -REVISION = 0 - GH_ACCOUNT = stepmania GH_PROJECT = stepmania GH_TAGNAME = v5.0.12 +REVISION = 1 +EPOCH = 0 DEBUG_PACKAGES = ${BUILD_PACKAGES} # Code base is mostly BSD, with a few tidbits GPL PERMIT_PACKAGE = Yes MAINTAINER = Marc Espie <[email protected]> -EPOCH = 0 MODULES = devel/cmake CONFIGURE_STYLE = cmake Index: patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_cpp =================================================================== RCS file: /home/cvs/ports/games/stepmania/patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_cpp,v retrieving revision 1.3 diff -u -p -u -p -r1.3 patch-src_arch_MovieTexture_MovieTexture_FFMpeg_cpp --- patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_cpp 11 Mar 2022 19:04:58 -0000 1.3 +++ patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_cpp 7 May 2023 02:46:25 -0000 @@ -1,24 +1,267 @@ -Update API usage to deal with current vs new FFmpeg API. +- Allow linking against system libraries for almost everything + b8a79cd0f61c0109b68a23a324c45891851bcc4c +- Fix file leak in MovieTexture_FFMpeg.cpp + ece6812b4bfe92d7936514f19d47422edd50a60b + +- Fix building with newer FFmpeg + https://github.com/stepmania/stepmania/pull/2247 Index: src/arch/MovieTexture/MovieTexture_FFMpeg.cpp --- src/arch/MovieTexture/MovieTexture_FFMpeg.cpp.orig +++ src/arch/MovieTexture/MovieTexture_FFMpeg.cpp -@@ -445,7 +445,7 @@ RString MovieDecoder_FFMpeg::Open( RString sFile ) +@@ -109,6 +109,10 @@ MovieDecoder_FFMpeg::MovieDecoder_FFMpeg() + { + FixLilEndian(); + ++ m_swsctx = NULL; ++ m_avioContext = NULL; ++ m_buffer = NULL; ++ m_pStreamCodec = NULL; + m_fctx = NULL; + m_pStream = NULL; + m_iCurrentPacketOffset = -1; +@@ -119,16 +123,37 @@ MovieDecoder_FFMpeg::MovieDecoder_FFMpeg() + + MovieDecoder_FFMpeg::~MovieDecoder_FFMpeg() + { ++ Init(); ++} ++ ++void MovieDecoder_FFMpeg::Init() ++{ + if( m_iCurrentPacketOffset != -1 ) + { + avcodec::av_free_packet( &m_Packet ); + m_iCurrentPacketOffset = -1; + } ++ ++ m_iEOF = 0; ++ m_fTimestamp = 0; ++ m_fLastFrameDelay = 0; ++ m_iFrameNumber = -1; /* decode one frame and you're on the 0th */ ++ m_fTimestampOffset = 0; ++ m_fLastFrame = 0; + if (m_swsctx) + { + avcodec::sws_freeContext(m_swsctx); + m_swsctx = NULL; + } ++ m_swsctx = NULL; ++ // Note: m_avioContext->buffer refers to m_buffer, but ffmpeg sometimes ++ // reallocates the buffer to change the size, and in that case our m_buffer ++ // pointer is freed already, so we instead check m_avioContext->buffer ++ // to free m_buffer ++ if (m_avioContext && m_avioContext->buffer != NULL) { ++ avcodec::av_free(m_avioContext->buffer); ++ } ++ m_buffer = NULL; + if (m_avioContext != NULL ) + { + RageFile *file = (RageFile *)m_avioContext->opaque; +@@ -136,29 +161,14 @@ MovieDecoder_FFMpeg::~MovieDecoder_FFMpeg() + delete file; + avcodec::av_free(m_avioContext); + } +- if ( m_buffer != NULL ) +- { +- avcodec::av_free(m_buffer); +- } +-} +- +-void MovieDecoder_FFMpeg::Init() +-{ +- m_iEOF = 0; +- m_fTimestamp = 0; +- m_fLastFrameDelay = 0; +- m_iFrameNumber = -1; /* decode one frame and you're on the 0th */ +- m_fTimestampOffset = 0; +- m_fLastFrame = 0; +- m_swsctx = NULL; + m_avioContext = NULL; +- m_buffer = NULL; +- +- if( m_iCurrentPacketOffset != -1 ) ++#if LIBAVCODEC_VERSION_MAJOR >= 58 ++ if ( m_pStreamCodec != NULL) + { +- avcodec::av_free_packet( &m_Packet ); +- m_iCurrentPacketOffset = -1; ++ avcodec::avcodec_free_context(&m_pStreamCodec); + } ++ m_pStreamCodec = NULL; ++#endif + } + + /* Read until we get a frame, EOF or error. Return -1 on error, 0 on EOF, 1 if we have a frame. */ +@@ -265,16 +275,23 @@ int MovieDecoder_FFMpeg::DecodePacket( float fTargetTi + bool bSkipThisFrame = + fTargetTime != -1 && + GetTimestamp() + GetFrameDuration() < fTargetTime && +- (m_pStream->codec->frame_number % 2) == 0; ++ (m_pStreamCodec->frame_number % 2) == 0; + + int iGotFrame; ++ int len; + /* Hack: we need to send size = 0 to flush frames at the end, but we have + * to give it a buffer to read from since it tries to read anyway. */ + m_Packet.data = m_Packet.size ? m_Packet.data : NULL; +- int len = avcodec::avcodec_decode_video2( +- m_pStream->codec, ++#if LIBAVCODEC_VERSION_MAJOR < 58 ++ len = avcodec::avcodec_decode_video2( ++ m_pStreamCodec, + m_Frame, &iGotFrame, + &m_Packet ); ++#else ++ len = m_Packet.size; ++ avcodec::avcodec_send_packet(m_pStreamCodec, &m_Packet); ++ iGotFrame = !avcodec::avcodec_receive_frame(m_pStreamCodec, m_Frame); ++#endif + + if( len < 0 ) + { +@@ -333,9 +350,15 @@ int MovieDecoder_FFMpeg::DecodePacket( float fTargetTi + + void MovieDecoder_FFMpeg::GetFrame( RageSurface *pSurface ) + { ++#if LIBAVCODEC_VERSION_MAJOR < 58 + avcodec::AVPicture pict; + pict.data[0] = (unsigned char *) pSurface->pixels; + pict.linesize[0] = pSurface->pitch; ++#else ++ avcodec::AVFrame pict; ++ pict.data[0] = (unsigned char *) pSurface->pixels; ++ pict.linesize[0] = pSurface->pitch; ++#endif + + /* XXX 1: Do this in one of the Open() methods instead? + * XXX 2: The problem of doing this in Open() is that m_AVTexfmt is not +@@ -344,12 +367,12 @@ void MovieDecoder_FFMpeg::GetFrame( RageSurface *pSurf + if( m_swsctx == NULL ) + { + m_swsctx = avcodec::sws_getCachedContext( m_swsctx, +- GetWidth(), GetHeight(), m_pStream->codec->pix_fmt, ++ GetWidth(), GetHeight(), m_pStreamCodec->pix_fmt, + GetWidth(), GetHeight(), m_AVTexfmt, + sws_flags, NULL, NULL, NULL ); + if( m_swsctx == NULL ) + { +- LOG->Warn("Cannot initialize sws conversion context for (%d,%d) %d->%d", GetWidth(), GetHeight(), m_pStream->codec->pix_fmt, m_AVTexfmt); ++ LOG->Warn("Cannot initialize sws conversion context for (%d,%d) %d->%d", GetWidth(), GetHeight(), m_pStreamCodec->pix_fmt, m_AVTexfmt); + return; + } + } +@@ -384,8 +407,10 @@ void MovieTexture_FFMpeg::RegisterProtocols() + return; + Done = true; + ++#if LIBAVCODEC_VERSION_MAJOR < 58 + avcodec::avcodec_register_all(); + avcodec::av_register_all(); ++#endif + } + + static int AVIORageFile_ReadPacket( void *opaque, uint8_t *buf, int buf_size ) +@@ -413,6 +438,8 @@ RString MovieDecoder_FFMpeg::Open( RString sFile ) + { + MovieTexture_FFMpeg::RegisterProtocols(); + ++ Close(); ++ + m_fctx = avcodec::avformat_alloc_context(); + if( !m_fctx ) + return "AVCodec: Couldn't allocate context"; +@@ -444,54 +471,76 @@ RString MovieDecoder_FFMpeg::Open( RString sFile ) + m_fctx->streams[stream_idx] == NULL ) return "Couldn't find any video streams"; m_pStream = m_fctx->streams[stream_idx]; ++#if LIBAVCODEC_VERSION_MAJOR >= 58 ++ m_pStreamCodec = avcodec::avcodec_alloc_context3(NULL); ++ if (avcodec::avcodec_parameters_to_context(m_pStreamCodec, m_pStream->codecpar) < 0) ++ return ssprintf("Could not get context from parameters"); ++#else ++ m_pStreamCodec = m_pStream->codec; ++#endif - if( m_pStream->codec->codec_id == avcodec::CODEC_ID_NONE ) -+ if( m_pStream->codec->codec_id == avcodec::AV_CODEC_ID_NONE ) - return ssprintf( "Unsupported codec %08x", m_pStream->codec->codec_tag ); +- return ssprintf( "Unsupported codec %08x", m_pStream->codec->codec_tag ); ++ if( m_pStreamCodec->codec_id == avcodec::CODEC_ID_NONE ) ++ return ssprintf( "Unsupported codec %08x", m_pStreamCodec->codec_tag ); RString sError = OpenCodec(); -@@ -473,9 +473,6 @@ RString MovieDecoder_FFMpeg::OpenCodec() - m_pStream->codec->workaround_bugs = 1; - m_pStream->codec->idct_algo = FF_IDCT_AUTO; - m_pStream->codec->error_concealment = 3; -- -- if( pCodec->capabilities & CODEC_CAP_DR1 ) + if( !sError.empty() ) + return ssprintf( "AVCodec (%s): %s", sFile.c_str(), sError.c_str() ); + +- LOG->Trace( "Bitrate: %i", m_pStream->codec->bit_rate ); +- LOG->Trace( "Codec pixel format: %s", avcodec::av_get_pix_fmt_name(m_pStream->codec->pix_fmt) ); ++ LOG->Trace( "Bitrate: %i", static_cast<int>(m_pStreamCodec->bit_rate) ); ++ LOG->Trace( "Codec pixel format: %s", avcodec::av_get_pix_fmt_name(m_pStreamCodec->pix_fmt) ); + + return RString(); + } + + RString MovieDecoder_FFMpeg::OpenCodec() + { +- Init(); ++ if (m_iCurrentPacketOffset != -1) { ++ avcodec::av_free_packet(&m_Packet); ++ m_iCurrentPacketOffset = -1; ++ } + ++ m_iEOF = 0; ++ m_fTimestamp = 0; ++ m_fLastFrameDelay = 0; ++ m_iFrameNumber = -1; /* decode one frame and you're on the 0th */ ++ m_fTimestampOffset = 0; ++ m_fLastFrame = 0; ++ + ASSERT( m_pStream != NULL ); +- if( m_pStream->codec->codec ) +- avcodec::avcodec_close( m_pStream->codec ); ++ if( m_pStreamCodec->codec ) ++ avcodec::avcodec_close( m_pStreamCodec ); + +- avcodec::AVCodec *pCodec = avcodec::avcodec_find_decoder( m_pStream->codec->codec_id ); ++#if LIBAVCODEC_VERSION_MAJOR >= 59 ++ const ++#endif ++ avcodec::AVCodec *pCodec = avcodec::avcodec_find_decoder( m_pStreamCodec->codec_id ); + if( pCodec == NULL ) +- return ssprintf( "Couldn't find decoder %i", m_pStream->codec->codec_id ); ++ return ssprintf( "Couldn't find decoder %i", m_pStreamCodec->codec_id ); + +- m_pStream->codec->workaround_bugs = 1; +- m_pStream->codec->idct_algo = FF_IDCT_AUTO; +- m_pStream->codec->error_concealment = 3; ++ m_pStreamCodec->workaround_bugs = 1; ++ m_pStreamCodec->idct_algo = FF_IDCT_AUTO; ++ m_pStreamCodec->error_concealment = 3; + ++#if LIBAVCODEC_VERSION_MAJOR < 58 + if( pCodec->capabilities & CODEC_CAP_DR1 ) - m_pStream->codec->flags |= CODEC_FLAG_EMU_EDGE; ++ m_pStreamCodec->flags |= CODEC_FLAG_EMU_EDGE; ++#endif LOG->Trace("Opening codec %s", pCodec->name ); + +- int ret = avcodec::avcodec_open2( m_pStream->codec, pCodec, NULL ); ++ int ret = avcodec::avcodec_open2( m_pStreamCodec, pCodec, NULL ); + if( ret < 0 ) + return RString( averr_ssprintf(ret, "Couldn't open codec \"%s\"", pCodec->name) ); +- ASSERT( m_pStream->codec->codec != NULL ); ++ ASSERT( m_pStreamCodec->codec != NULL ); + + return RString(); + } + + void MovieDecoder_FFMpeg::Close() + { +- if( m_pStream && m_pStream->codec->codec ) ++ if( m_pStream && m_pStreamCodec->codec ) + { +- avcodec::avcodec_close( m_pStream->codec ); ++ avcodec::avcodec_close( m_pStreamCodec ); + m_pStream = NULL; + } Index: patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_h =================================================================== RCS file: /home/cvs/ports/games/stepmania/patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_h,v retrieving revision 1.2 diff -u -p -u -p -r1.2 patch-src_arch_MovieTexture_MovieTexture_FFMpeg_h --- patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_h 11 Mar 2022 19:04:58 -0000 1.2 +++ patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_h 7 May 2023 02:46:31 -0000 @@ -1,99 +1,51 @@ +- Allow linking against system libraries for almost everything + b8a79cd0f61c0109b68a23a324c45891851bcc4c + +- Fix building with newer FFmpeg + https://github.com/stepmania/stepmania/pull/2247 + Index: src/arch/MovieTexture/MovieTexture_FFMpeg.h --- src/arch/MovieTexture/MovieTexture_FFMpeg.h.orig +++ src/arch/MovieTexture/MovieTexture_FFMpeg.h -@@ -64,7 +64,7 @@ class MovieDecoder_FFMpeg: public MovieDecoder (privat +@@ -13,6 +13,22 @@ namespace avcodec + #include <libavformat/avformat.h> + #include <libswscale/swscale.h> + #include <libavutil/pixdesc.h> ++ #include <libavcodec/avcodec.h> ++ ++ #if LIBAVCODEC_VERSION_MAJOR >= 58 ++ #define av_free_packet av_packet_unref ++ #define PixelFormat AVPixelFormat ++ #define PIX_FMT_YUYV422 AV_PIX_FMT_YUYV422 ++ #define PIX_FMT_BGRA AV_PIX_FMT_BGRA ++ #define PIX_FMT_ARGB AV_PIX_FMT_ARGB ++ #define PIX_FMT_ABGR AV_PIX_FMT_ABGR ++ #define PIX_FMT_RGBA AV_PIX_FMT_RGBA ++ #define PIX_FMT_RGB24 AV_PIX_FMT_RGB24 ++ #define PIX_FMT_BGR24 AV_PIX_FMT_BGR24 ++ #define PIX_FMT_RGB555 AV_PIX_FMT_RGB555 ++ #define PIX_FMT_NB AV_PIX_FMT_NB ++ #define CODEC_ID_NONE AV_CODEC_ID_NONE ++ #endif + } + }; + +@@ -48,8 +64,8 @@ class MovieDecoder_FFMpeg: public MovieDecoder (public + void GetFrame( RageSurface *pOut ); + int DecodeFrame( float fTargetTime ); + +- int GetWidth() const { return m_pStream->codec->width; } +- int GetHeight() const { return m_pStream->codec->height; } ++ int GetWidth() const { return m_pStreamCodec->width; } ++ int GetHeight() const { return m_pStreamCodec->height; } - avcodec::AVStream *m_pStream; + RageSurface *CreateCompatibleSurface( int iTextureWidth, int iTextureHeight, bool bPreferHighColor, MovieDecoderPixelFormatYCbCr &fmtout ); + +@@ -66,6 +82,7 @@ class MovieDecoder_FFMpeg: public MovieDecoder (public avcodec::AVFrame *m_Frame; -- avcodec::PixelFormat m_AVTexfmt; /* PixelFormat of output surface */ -+ avcodec::AVPixelFormat m_AVTexfmt; /* PixelFormat of output surface */ + avcodec::PixelFormat m_AVTexfmt; /* PixelFormat of output surface */ avcodec::SwsContext *m_swsctx; ++ avcodec::AVCodecContext *m_pStreamCodec; avcodec::AVFormatContext *m_fctx; -@@ -90,7 +90,7 @@ static struct AVPixelFormat_t - { - int bpp; - uint32_t masks[4]; -- avcodec::PixelFormat pf; -+ avcodec::AVPixelFormat pf; - bool bHighColor; - bool bByteSwapOnLittleEndian; - MovieDecoderPixelFormatYCbCr YUV; -@@ -101,7 +101,7 @@ static struct AVPixelFormat_t - 0x00FF0000, - 0x0000FF00, - 0x000000FF }, -- avcodec::PIX_FMT_YUYV422, -+ avcodec::AV_PIX_FMT_YUYV422, - false, /* N/A */ - true, - PixelFormatYCbCr_YUYV422, -@@ -112,7 +112,7 @@ static struct AVPixelFormat_t - 0x00FF0000, - 0xFF000000, - 0x000000FF }, -- avcodec::PIX_FMT_BGRA, -+ avcodec::AV_PIX_FMT_BGRA, - true, - true, - PixelFormatYCbCr_Invalid, -@@ -123,7 +123,7 @@ static struct AVPixelFormat_t - 0x0000FF00, - 0x000000FF, - 0xFF000000 }, -- avcodec::PIX_FMT_ARGB, -+ avcodec::AV_PIX_FMT_ARGB, - true, - true, - PixelFormatYCbCr_Invalid, -@@ -135,7 +135,7 @@ static struct AVPixelFormat_t - 0x0000FF00, - 0x00FF0000, - 0xFF000000 }, -- avcodec::PIX_FMT_ABGR, -+ avcodec::AV_PIX_FMT_ABGR, - true, - true, - PixelFormatYCbCr_Invalid, -@@ -146,7 +146,7 @@ static struct AVPixelFormat_t - 0x00FF0000, - 0x0000FF00, - 0x000000FF }, -- avcodec::PIX_FMT_RGBA, -+ avcodec::AV_PIX_FMT_RGBA, - true, - true, - PixelFormatYCbCr_Invalid, -@@ -157,7 +157,7 @@ static struct AVPixelFormat_t - 0x00FF00, - 0x0000FF, - 0x000000 }, -- avcodec::PIX_FMT_RGB24, -+ avcodec::AV_PIX_FMT_RGB24, - true, - true, - PixelFormatYCbCr_Invalid, -@@ -168,7 +168,7 @@ static struct AVPixelFormat_t - 0x00FF00, - 0xFF0000, - 0x000000 }, -- avcodec::PIX_FMT_BGR24, -+ avcodec::AV_PIX_FMT_BGR24, - true, - true, - PixelFormatYCbCr_Invalid, -@@ -179,12 +179,12 @@ static struct AVPixelFormat_t - 0x03E0, - 0x001F, - 0x0000 }, -- avcodec::PIX_FMT_RGB555, -+ avcodec::AV_PIX_FMT_RGB555, - false, - false, - PixelFormatYCbCr_Invalid, - }, -- { 0, { 0,0,0,0 }, avcodec::PIX_FMT_NB, true, false, PixelFormatYCbCr_Invalid } -+ { 0, { 0,0,0,0 }, avcodec::AV_PIX_FMT_NB, true, false, PixelFormatYCbCr_Invalid } - }; - - #endif + float m_fTimestamp;
