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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
Index: autoconf/m4/video.m4
===================================================================
--- autoconf/m4/video.m4 (revision 28234)
+++ autoconf/m4/video.m4 (working copy)
@@ -18,51 +18,18 @@
AC_CHECK_FUNC([avcodec_init], have_libavcodec=yes, have_libavcodec=no)
LIBS="$with_ffmpeg/lib/libavformat.a $LIBS"
AC_CHECK_FUNC([guess_format], have_libavformat=yes, have_libavformat=no)
+ LIBS="$with_ffmpeg/lib/libswscale.a $LIBS"
+ AC_CHECK_FUNC([sws_scale], have_libswscale=yes, have_libswscale=no)
else
AC_SEARCH_LIBS(av_free, [avutil], have_libavutil=yes, have_libavutil=no)
AC_SEARCH_LIBS(avcodec_init, [avcodec], have_libavcodec=yes, have_libavcodec=no)
AC_SEARCH_LIBS(guess_format, [avformat], have_libavformat=yes, have_libavformat=no)
+ AC_SEARCH_LIBS(sws_scale, [swscale], have_libswscale=yes, have_libswscale=no)
fi
-
-if test "$have_libavcodec" = "yes"; then
- AC_MSG_CHECKING([for matching libavcodec headers and libs])
- AC_RUN_IFELSE([AC_LANG_SOURCE([[
- #include <ffmpeg/avcodec.h>
- int main()
- {
- return ( LIBAVCODEC_VERSION_INT == avcodec_version() &&
- LIBAVCODEC_BUILD == avcodec_build() ) ? 0:1;
- }
- ]])],[],[have_libavcodec=no],[])
- AC_MSG_RESULT($have_libavcodec)
- if test "$have_libavcodec" = "yes"; then
- AC_MSG_CHECKING([libavcodec revision])
- AC_RUN_IFELSE([AC_LANG_SOURCE([[
- #include <ffmpeg/avcodec.h>
- int main()
- {
- return ( LIBAVCODEC_VERSION_INT == 0x332800 ) ? 0:1;
- }
- ]])],[],[have_libavcodec=no],[])
- AC_MSG_RESULT($have_libavcodec)
- fi
-fi
-
-if test "$have_libavformat" = "yes"; then
- AC_MSG_CHECKING([libavformat revision])
- AC_RUN_IFELSE([AC_LANG_SOURCE([[
- #include <ffmpeg/avformat.h>
- int main()
- {
- return ( LIBAVFORMAT_VERSION_INT == 0x330B00 )? 0:1;
- }
- ]])],[],[have_libavformat=no],[])
- AC_MSG_RESULT($have_libavformat)
-fi
fi
have_ffmpeg=no
-if test "$have_libavutil" = "yes" -a "$have_libavformat" = "yes" -a "$have_libavcodec" = "yes"; then
+if test "$have_libavutil" = "yes" -a "$have_libavformat" = "yes" -a "$have_libavcodec" = "yes" -a "$have_libswscale" = "yes"; then
have_ffmpeg=yes
AC_DEFINE(HAVE_FFMPEG, 1, [FFMPEG support available])
else
Index: src/arch/ArchHooks/ArchHooks_Unix.cpp
===================================================================
--- src/arch/ArchHooks/ArchHooks_Unix.cpp (revision 28234)
+++ src/arch/ArchHooks/ArchHooks_Unix.cpp (working copy)
@@ -18,7 +18,9 @@
#endif
#if defined(HAVE_FFMPEG)
-#include <ffmpeg/avcodec.h>
+extern "C" {
+#include <libavcodec/avcodec.h>
+};
#endif
static bool IsFatalSignal( int signal )
@@ -217,7 +219,7 @@
LOG->Info( "Runtime library: %s", LibcVersion().c_str() );
LOG->Info( "Threads library: %s", ThreadsVersion().c_str() );
#if defined(HAVE_FFMPEG)
- LOG->Info( "libavcodec: %#x (%u)", avcodec_version(), avcodec_build() );
+ LOG->Info( "libavcodec: %#x (%u)", avcodec_version(), avcodec_version() );
#endif
}
Index: src/arch/MovieTexture/MovieTexture_FFMpeg.cpp
===================================================================
--- src/arch/MovieTexture/MovieTexture_FFMpeg.cpp (revision 28234)
+++ src/arch/MovieTexture/MovieTexture_FFMpeg.cpp (working copy)
@@ -11,7 +11,10 @@
namespace avcodec
{
-#include <ffmpeg/avformat.h>
+ extern "C" {
+#include <libavformat/avformat.h>
+#include <libswscale/swscale.h>
+ };
};
#if defined(_MSC_VER) && !defined(XBOX)
@@ -35,6 +38,8 @@
#pragma comment(lib, "ffmpeg/lib/libgcc.a")
#endif
+static const int sws_flags = SWS_BICUBIC; // XXX: Reasonable default?
+
static struct AVPixelFormat_t
{
int bpp;
@@ -270,6 +275,7 @@
avcodec::AVStream *m_pStream;
avcodec::AVFrame m_Frame;
avcodec::PixelFormat m_AVTexfmt; /* PixelFormat of output surface */
+ avcodec::SwsContext *m_swsctx;
float m_fPTS;
avcodec::AVFormatContext *m_fctx;
@@ -311,6 +317,11 @@
avcodec::av_free_packet( &m_Packet );
m_iCurrentPacketOffset = -1;
}
+ if (m_swsctx)
+ {
+ avcodec::sws_freeContext(m_swsctx);
+ m_swsctx = NULL;
+ }
}
void MovieDecoder_FFMpeg::Init()
@@ -322,6 +333,7 @@
m_fPTS = -1;
m_iFrameNumber = -1; /* decode one frame and you're on the 0th */
m_fTimestampOffset = 0;
+ m_swsctx = NULL;
if( m_iCurrentPacketOffset != -1 )
{
@@ -513,9 +525,24 @@
pict.data[0] = (unsigned char *) pSurface->pixels;
pict.linesize[0] = pSurface->pitch;
- avcodec::img_convert( &pict, m_AVTexfmt,
- (avcodec::AVPicture *) &m_Frame, m_pStream->codec->pix_fmt,
- m_pStream->codec->width, m_pStream->codec->height );
+ // XXX: Do this in one of the Open() methods instead?
+ // XXX: The problem of doing this in Open() is that m_AVTexfmt is not already initialized with its correct value.
+ if( m_swsctx == NULL )
+ {
+ m_swsctx = avcodec::sws_getCachedContext( m_swsctx,
+ GetWidth(), GetHeight(), m_pStream->codec->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);
+ return;
+ }
+ }
+
+ avcodec::sws_scale( m_swsctx,
+ m_Frame.data, m_Frame.linesize, 0, GetHeight(),
+ pict.data, pict.linesize );
}
static avcodec::AVStream *FindVideoStream( avcodec::AVFormatContext *m_fctx )
@@ -596,11 +623,11 @@
return f->Write( buf, size );
}
-avcodec::offset_t URLRageFile_seek( avcodec::URLContext *h, avcodec::offset_t pos, int whence )
+int64_t URLRageFile_seek( avcodec::URLContext *h, int64_t pos, int whence )
{
RageFile *f = (RageFile *) h->priv_data;
if( whence == AVSEEK_SIZE )
- return f->Tell();
+ return f->GetFileSize();
if( whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END )
return -1;
@@ -623,6 +650,8 @@
URLRageFile_write,
URLRageFile_seek,
URLRageFile_close,
+ NULL,
+ NULL,
NULL
};
Index: src/arch/MovieTexture/MovieTexture_Theora.cpp
===================================================================
--- src/arch/MovieTexture/MovieTexture_Theora.cpp (revision 28234)
+++ src/arch/MovieTexture/MovieTexture_Theora.cpp (working copy)
@@ -9,7 +9,10 @@
namespace avcodec
{
-#include <ffmpeg/avcodec.h> /* for avcodec::img_convert */
+ extern "C" {
+#include <libavcodec/avcodec.h> /* for avcodec::img_convert */
+#include <libswscale/swscale.h>
+ };
};
// #define HAVE_THEORAEXP
@@ -22,6 +25,8 @@
#pragma comment(lib, OGG_LIB_DIR "theora_static.lib")
#endif
+static const int sws_flags = SWS_BICUBIC; // XXX: Reasonable default?
+
class MovieDecoder_Theora: public MovieDecoder
{
public:
@@ -47,7 +52,8 @@
void Init();
RString ProcessHeaders();
int ReadPage( ogg_page *pOggPage, RString &sError, bool bInitializing );
- void ConvertToSurface( RageSurface *pSurface ) const;
+ void ConvertToSurface( RageSurface *pSurface );
+ void ConvertImage( avcodec::AVPicture &in, avcodec::AVPicture &out, int height );
RageFile m_File;
@@ -61,6 +67,7 @@
avcodec::PixelFormat m_InputPixFmt; /* PixelFormat of YUV input surface */
avcodec::PixelFormat m_OutputPixFmt; /* PixelFormat of RGB output surface */
+ avcodec::SwsContext *m_swsctx;
};
MovieDecoder_Theora::MovieDecoder_Theora()
@@ -71,11 +78,17 @@
memset( &m_TheoraComment, 0, sizeof(m_TheoraComment) );
memset( &m_OggStream, 0, sizeof(m_OggStream) );
memset( &m_TheoraState, 0, sizeof(m_TheoraState) );
+ m_swsctx = NULL;
}
MovieDecoder_Theora::~MovieDecoder_Theora()
{
Close();
+ if (m_swsctx)
+ {
+ avcodec::sws_freeContext(m_swsctx);
+ m_swsctx = NULL;
+ }
}
void MovieDecoder_Theora::Init()
@@ -276,7 +289,30 @@
return RageMovieTextureDriver_FFMpeg::AVCodecCreateCompatibleSurface( iTextureWidth, iTextureHeight, bPreferHighColor, *ConvertValue<int>(&m_OutputPixFmt), fmtout );
}
-void MovieDecoder_Theora::ConvertToSurface( RageSurface *pSurface ) const
+void MovieDecoder_Theora::ConvertImage( avcodec::AVPicture &in, avcodec::AVPicture &out, int height )
+{
+ // XXX: Do we need separate contexts for different heights?
+ // XXX: Do this in one of the Open() methods instead?
+ // XXX: The problem of doing this in Open() is that m_OutputPixFmt is not already initialized with its correct value.
+ if( m_swsctx == NULL )
+ {
+ m_swsctx = avcodec::sws_getCachedContext( m_swsctx,
+ GetWidth(), GetHeight(), m_InputPixFmt,
+ GetWidth(), GetHeight(), m_OutputPixFmt,
+ sws_flags, NULL, NULL, NULL );
+ if( m_swsctx == NULL )
+ {
+ LOG->Warn("Cannot initialize sws conversion context for (%d,%d) %d->%d", GetWidth(), GetHeight(), m_InputPixFmt, m_OutputPixFmt);
+ return;
+ }
+ }
+
+ avcodec::sws_scale( m_swsctx,
+ in.data, in.linesize, 0, height,
+ out.data, out.linesize );
+}
+
+void MovieDecoder_Theora::ConvertToSurface( RageSurface *pSurface )
{
yuv_buffer yuv;
theora_decode_YUVout( (theora_state *) &m_TheoraState, &yuv );
@@ -303,9 +339,7 @@
RGBOut.data[0] = (unsigned char *) pSurface->pixels;
RGBOut.linesize[0] = pSurface->pitch;
- avcodec::img_convert( &RGBOut, m_OutputPixFmt,
- &YUVIn, m_InputPixFmt,
- m_TheoraInfo.frame_width, m_TheoraInfo.frame_height );
+ ConvertImage( YUVIn, RGBOut, m_TheoraInfo.frame_height );
}
float MovieDecoder_Theora::GetSourceAspectRatio() const
@@ -655,9 +689,7 @@
RGBOut.data[0] += RGBOut.linesize[0] * yfrag0;
int iRows = (yfrag_end-yfrag0) + 1;
- avcodec::img_convert( &RGBOut, m_OutputPixFmt,
- &YUVIn, m_InputPixFmt,
- m_TheoraInfo.frame_width, iRows );
+ ConvertImage( YUVIn, RGBOut, iRows );
}
{
|