From 1256e7277961d068f796de30d36977e6b80882e1 Mon Sep 17 00:00:00 2001 From: Andrew Udvare Date: Mon, 11 Feb 2019 17:07:09 -0500 Subject: [PATCH] Linux build fixes --- src/arch/MovieTexture/MovieTexture_FFMpeg.cpp | 96 ++++++++++++------- src/arch/MovieTexture/MovieTexture_FFMpeg.h | 36 +++++-- src/arch/Threads/Threads_Pthreads.cpp | 5 +- src/arch/Threads/Threads_Pthreads.h | 5 +- 4 files changed, 96 insertions(+), 46 deletions(-) diff --git a/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp b/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp index bdf23563c9..8aec20d37f 100644 --- a/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp +++ b/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp @@ -14,7 +14,7 @@ static void FixLilEndian() #if defined(ENDIAN_LITTLE) static bool Initialized = false; if( Initialized ) - return; + return; Initialized = true; for( int i = 0; i < AVPixelFormats[i].bpp; ++i ) @@ -90,7 +90,7 @@ RageSurface *RageMovieTextureDriver_FFMpeg::AVCodecCreateCompatibleSurface( int break; ASSERT( AVPixelFormats[iAVTexfmtIndex].bpp != 0 ); } - + const AVPixelFormat_t *pfd = &AVPixelFormats[iAVTexfmtIndex]; iAVTexfmt = pfd->pf; fmtout = pfd->YUV; @@ -140,6 +140,12 @@ MovieDecoder_FFMpeg::~MovieDecoder_FFMpeg() { avcodec::av_free(m_buffer); } +#if LIBAVCODEC_VERSION_MAJOR >= 58 + if ( m_pStreamCodec != NULL) + { + avcodec::avcodec_free_context(&m_pStreamCodec); + } +#endif } void MovieDecoder_FFMpeg::Init() @@ -231,7 +237,7 @@ int MovieDecoder_FFMpeg::ReadPacket() /* EOF. */ m_iEOF = 1; m_Packet.size = 0; - + return 0; } @@ -262,19 +268,26 @@ int MovieDecoder_FFMpeg::DecodePacket( float fTargetTime ) if( m_Packet.size == 0 && m_iFrameNumber == -1 ) return 0; /* eof */ - bool bSkipThisFrame = + 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 +346,15 @@ int MovieDecoder_FFMpeg::DecodePacket( float fTargetTime ) 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 +363,12 @@ void MovieDecoder_FFMpeg::GetFrame( RageSurface *pSurface ) 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; } } @@ -366,7 +385,7 @@ static RString averr_ssprintf( int err, const char *fmt, ... ) va_list va; va_start(va, fmt); RString s = vssprintf( fmt, va ); - va_end(va); + va_end(va); size_t errbuf_size = 512; char* errbuf = new char[errbuf_size]; @@ -384,8 +403,10 @@ void MovieTexture_FFMpeg::RegisterProtocols() return; Done = true; +#if !FF_API_NEXT avcodec::avcodec_register_all(); avcodec::av_register_all(); +#endif } static int AVIORageFile_ReadPacket( void *opaque, uint8_t *buf, int buf_size ) @@ -396,27 +417,27 @@ static int AVIORageFile_ReadPacket( void *opaque, uint8_t *buf, int buf_size ) static int64_t AVIORageFile_Seek( void *opaque, int64_t offset, int whence ) { - RageFile *f = (RageFile *)opaque; + RageFile *f = (RageFile *)opaque; if( whence == AVSEEK_SIZE ) return f->GetFileSize(); - + if( whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END ) { LOG->Trace("Error: unsupported seek whence: %d", whence); return -1; } - + return f->Seek( (int) offset, whence ); } RString MovieDecoder_FFMpeg::Open( RString sFile ) { MovieTexture_FFMpeg::RegisterProtocols(); - + m_fctx = avcodec::avformat_alloc_context(); if( !m_fctx ) return "AVCodec: Couldn't allocate context"; - + RageFile *f = new RageFile; if( !f->Open(sFile, RageFile::READ) ) @@ -444,16 +465,23 @@ 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 ) - 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(); 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(m_pStreamCodec->bit_rate) ); + LOG->Trace( "Codec pixel format: %s", avcodec::av_get_pix_fmt_name(m_pStreamCodec->pix_fmt) ); return RString(); } @@ -463,35 +491,37 @@ RString MovieDecoder_FFMpeg::OpenCodec() Init(); 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 ); + 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; } @@ -534,7 +564,7 @@ REGISTER_MOVIE_TEXTURE_CLASS( FFMpeg ); /* * (c) 2003-2005 Glenn Maynard * All rights reserved. - * + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -544,7 +574,7 @@ REGISTER_MOVIE_TEXTURE_CLASS( FFMpeg ); * copyright notice(s) and this permission notice appear in all copies of * the Software and that both the above copyright notice(s) and this * permission notice appear in supporting documentation. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF diff --git a/src/arch/MovieTexture/MovieTexture_FFMpeg.h b/src/arch/MovieTexture/MovieTexture_FFMpeg.h index f4d25efbef..c092b765fc 100644 --- a/src/arch/MovieTexture/MovieTexture_FFMpeg.h +++ b/src/arch/MovieTexture/MovieTexture_FFMpeg.h @@ -13,6 +13,21 @@ namespace avcodec #include #include #include + + #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 +63,8 @@ class MovieDecoder_FFMpeg: public MovieDecoder 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; } RageSurface *CreateCompatibleSurface( int iTextureWidth, int iTextureHeight, bool bPreferHighColor, MovieDecoderPixelFormatYCbCr &fmtout ); @@ -66,6 +81,7 @@ class MovieDecoder_FFMpeg: public MovieDecoder avcodec::AVFrame *m_Frame; avcodec::PixelFormat m_AVTexfmt; /* PixelFormat of output surface */ avcodec::SwsContext *m_swsctx; + avcodec::AVCodecContext *m_pStreamCodec; avcodec::AVFormatContext *m_fctx; float m_fTimestamp; @@ -106,7 +122,7 @@ static struct AVPixelFormat_t true, PixelFormatYCbCr_YUYV422, }, - { + { 32, { 0x0000FF00, 0x00FF0000, @@ -117,7 +133,7 @@ static struct AVPixelFormat_t true, PixelFormatYCbCr_Invalid, }, - { + { 32, { 0x00FF0000, 0x0000FF00, @@ -129,7 +145,7 @@ static struct AVPixelFormat_t PixelFormatYCbCr_Invalid, }, /* - { + { 32, { 0x000000FF, 0x0000FF00, @@ -140,7 +156,7 @@ static struct AVPixelFormat_t true, PixelFormatYCbCr_Invalid, }, - { + { 32, { 0xFF000000, 0x00FF0000, @@ -151,7 +167,7 @@ static struct AVPixelFormat_t true, PixelFormatYCbCr_Invalid, }, */ - { + { 24, { 0xFF0000, 0x00FF00, @@ -162,7 +178,7 @@ static struct AVPixelFormat_t true, PixelFormatYCbCr_Invalid, }, - { + { 24, { 0x0000FF, 0x00FF00, @@ -192,7 +208,7 @@ static struct AVPixelFormat_t /* * (c) 2003-2005 Glenn Maynard * All rights reserved. - * + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -202,7 +218,7 @@ static struct AVPixelFormat_t * copyright notice(s) and this permission notice appear in all copies of * the Software and that both the above copyright notice(s) and this * permission notice appear in supporting documentation. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF diff --git a/src/arch/Threads/Threads_Pthreads.cpp b/src/arch/Threads/Threads_Pthreads.cpp index 872d057f7f..0689974e61 100644 --- a/src/arch/Threads/Threads_Pthreads.cpp +++ b/src/arch/Threads/Threads_Pthreads.cpp @@ -1,6 +1,8 @@ #include "global.h" #include "Threads_Pthreads.h" +#include "RageLog.h" #include "RageTimer.h" +#include "RageThreads.h" #include "RageUtil.h" #include #include @@ -17,6 +19,7 @@ void ThreadImpl_Pthreads::Halt( bool Kill ) { + (void)Kill; /* Linux: * Send a SIGSTOP to the thread. If we send a SIGKILL, pthreads will * "helpfully" propagate it to the other threads, and we'll get killed, too. @@ -105,7 +108,7 @@ ThreadImpl *MakeThread( int (*pFunc)(void *pData), void *pData, uint64_t *piThre } else { // Abbreviate the name by taking the first 6, last 7 // characters and adding '..' in the middle. - LOG->Trace( "Truncated thread name due to size limit of %d: %s", + LOG->Trace( "Truncated thread name due to size limit of %zu: %s", maxNameLen, rawname ); snprintf( thread->name, maxNameLen, "%.6s..%s", rawname, &rawname[strlen(rawname) - 7] ); diff --git a/src/arch/Threads/Threads_Pthreads.h b/src/arch/Threads/Threads_Pthreads.h index 5a3969399f..f0efec8a26 100644 --- a/src/arch/Threads/Threads_Pthreads.h +++ b/src/arch/Threads/Threads_Pthreads.h @@ -10,6 +10,7 @@ class ThreadImpl_Pthreads: public ThreadImpl { public: pthread_t thread; + mutable char name[16]; /* Linux: * Keep a list of child PIDs, so we can send them SIGKILL. This has @@ -99,7 +100,7 @@ class SemaImpl_Pthreads: public SemaImpl /* * (c) 2001-2004 Glenn Maynard * All rights reserved. - * + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -109,7 +110,7 @@ class SemaImpl_Pthreads: public SemaImpl * copyright notice(s) and this permission notice appear in all copies of * the Software and that both the above copyright notice(s) and this * permission notice appear in supporting documentation. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF