~ruther/guix-local

ref: f3d2705f64ac3ef2dcdcd0d48eed413fb1fdab40 guix-local/gnu/packages/patches/stepmania-ffmpeg-compat.patch -rw-r--r-- 3.1 KiB
f3d2705f — Cayetano Santos gnu: ieee-p1076: Move to hdl. 30 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
See [6], [7], and [8].
[6] https://github.com/Tatsh/tatsh-overlay/blob/master/games-arcade/stepmania/files/stepmania-ffmpeg-6.patch
[7] https://github.com/Tatsh/tatsh-overlay/blob/master/games-arcade/stepmania/files/stepmania-ffmpeg-7.patch
[8] https://github.com/Tatsh/tatsh-overlay/blob/master/games-arcade/stepmania/files/stepmania-ffmpeg-8.patch

Hunk #2 is not present in any of these patches, but prevents a segmentation
fault due to freeing unallocated memory.
Hunk #4 was likewise altered to prevent nullptr dereferences.

diff --git a/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp b/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp
index 935ddf324b0..d4eed01d599 100644
--- a/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp
+++ b/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp
@@ -9,6 +9,10 @@

 #include <cerrno>

+#if LIBAVCODEC_VERSION_MAJOR > 59
+#define frame_number frame_num
+#endif
+
 static void FixLilEndian()
 {
 #if defined(ENDIAN_LITTLE)
@@ -118,5 +118,6 @@
 	m_buffer = NULL;
 	m_fctx = nullptr;
 	m_pStream = nullptr;
+	m_pStreamCodec = nullptr;
 	m_iCurrentPacketOffset = -1;
 	m_Frame = avcodec::av_frame_alloc();
@@ -405,7 +405,7 @@ void MovieTexture_FFMpeg::RegisterProtocols()
 		return;
 	Done = true;
 
-#if !FF_API_NEXT
+#if LIBAVCODEC_VERSION_MAJOR < 58
 	avcodec::avcodec_register_all();
 	avcodec::av_register_all();
 #endif
@@ -508,6 +508,16 @@ RString MovieDecoder_FFMpeg::OpenCodec()
+#if LIBAVCODEC_VERSION_MAJOR < 58
 	if( m_pStreamCodec->codec )
 		avcodec::avcodec_close( m_pStreamCodec );
+#else
+	if ( m_pStreamCodec )
+	{
+		avcodec::avcodec_free_context ( &m_pStreamCodec );
+		m_pStreamCodec = avcodec::avcodec_alloc_context3(nullptr);
+		if (avcodec::avcodec_parameters_to_context(m_pStreamCodec, m_pStream->codecpar) < 0)
+			return ssprintf("Could not get context from parameters");
+	}
+#endif
 
-	avcodec::AVCodec *pCodec = avcodec::avcodec_find_decoder( m_pStreamCodec->codec_id );
+	const avcodec::AVCodec *pCodec = avcodec::avcodec_find_decoder( m_pStreamCodec->codec_id );
 	if( pCodec == nullptr )
 		return ssprintf( "Couldn't find decoder %i", m_pStreamCodec->codec_id );
@@ -535,7 +535,7 @@ void MovieDecoder_FFMpeg::Close()
 {
 	if( m_pStream && m_pStreamCodec->codec )
 	{
-		avcodec::avcodec_close( m_pStreamCodec );
+		avcodec::avcodec_free_context( &m_pStreamCodec );
 		m_pStream = nullptr;
 	}

diff --git a/src/arch/MovieTexture/MovieTexture_FFMpeg.h b/src/arch/MovieTexture/MovieTexture_FFMpeg.h
index c092b765fc2..99f5ffcb1be 100644
--- a/src/arch/MovieTexture/MovieTexture_FFMpeg.h
+++ b/src/arch/MovieTexture/MovieTexture_FFMpeg.h
@@ -13,6 +13,7 @@ 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
@@ -32,7 +32,7 @@ namespace avcodec
 };
 
 #define STEPMANIA_FFMPEG_BUFFER_SIZE 4096
-static const int sws_flags = SWS_BICUBIC; // XXX: Reasonable default?
+static const int sws_flags = avcodec::SWS_BICUBIC; // XXX: Reasonable default?
 
 class MovieTexture_FFMpeg: public MovieTexture_Generic
 {