Etterna 0.74.4
Loading...
Searching...
No Matches
MovieTexture_FFMpeg.h
1/* MovieTexture_FFMpeg - FFMpeg movie renderer. */
2
3#ifndef RAGE_MOVIE_TEXTURE_FFMPEG_H
4#define RAGE_MOVIE_TEXTURE_FFMPEG_H
5
6#include "MovieTexture_Generic.h"
7struct RageSurface;
8
9namespace avcodec {
10extern "C" {
11#include <libavformat/avformat.h>
12#include <libswscale/swscale.h>
13#include <libavutil/pixdesc.h>
14}
15};
16
17#define STEPMANIA_FFMPEG_BUFFER_SIZE 4096
18static const int sws_flags = SWS_BICUBIC; // XXX: Reasonable default?
19
21{
22 public:
24
25 static void RegisterProtocols();
26 static RageSurface* AVCodecCreateCompatibleSurface(
27 int iTextureWidth,
28 int iTextureHeight,
29 bool bPreferHighColor,
30 int& iAVTexfmt,
31 MovieDecoderPixelFormatYCbCr& fmtout);
32};
33
35{
36 public:
37 virtual RageMovieTexture* Create(const RageTextureID& ID,
38 std::string& sError);
39 static RageSurface* AVCodecCreateCompatibleSurface(
40 int iTextureWidth,
41 int iTextureHeight,
42 bool bPreferHighColor,
43 int& iAVTexfmt,
44 MovieDecoderPixelFormatYCbCr& fmtout);
45};
46
48{
49 public:
52
53 std::string Open(const std::string& sFile);
54 void Close();
55 void Rewind();
56
57 void GetFrame(RageSurface* pOut);
58 int DecodeFrame(float fTargetTime);
59
60 int GetWidth() const { return m_pStream->codec->width; }
61 int GetHeight() const { return m_pStream->codec->height; }
62
63 RageSurface* CreateCompatibleSurface(int iTextureWidth,
64 int iTextureHeight,
65 bool bPreferHighColor,
66 MovieDecoderPixelFormatYCbCr& fmtout);
67
68 float GetTimestamp() const;
69 float GetFrameDuration() const;
70
71 private:
72 void Init();
73 std::string OpenCodec();
74 int ReadPacket();
75 int DecodePacket(float fTargetTime);
76
77 avcodec::AVStream* m_pStream;
78 avcodec::AVFrame* m_Frame;
79 avcodec::PixelFormat m_AVTexfmt; /* PixelFormat of output surface */
80 avcodec::SwsContext* m_swsctx;
81
82 avcodec::AVFormatContext* m_fctx;
83 float m_fTimestamp;
84 float m_fTimestampOffset;
85 float m_fLastFrameDelay;
86 int m_iFrameNumber;
87
88 unsigned char* m_buffer;
89 avcodec::AVIOContext* m_avioContext;
90
91 avcodec::AVPacket m_Packet;
92 int m_iCurrentPacketOffset;
93 float m_fLastFrame;
94
95 /* 0 = no EOF
96 * 1 = EOF from ReadPacket
97 * 2 = EOF from ReadPacket and DecodePacket */
98 int m_iEOF;
99};
100
101static struct AVPixelFormat_t
102{
103 int bpp;
104 uint32_t masks[4];
105 avcodec::PixelFormat pf;
106 bool bHighColor;
107 bool bByteSwapOnLittleEndian;
108 MovieDecoderPixelFormatYCbCr YUV;
109} AVPixelFormats[] = { {
110 32,
111 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF },
112 avcodec::PIX_FMT_YUYV422,
113 false, /* N/A */
114 true,
115 PixelFormatYCbCr_YUYV422,
116 },
117 {
118 32,
119 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF },
120 avcodec::PIX_FMT_BGRA,
121 true,
122 true,
123 PixelFormatYCbCr_Invalid,
124 },
125 {
126 32,
127 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 },
128 avcodec::PIX_FMT_ARGB,
129 true,
130 true,
131 PixelFormatYCbCr_Invalid,
132 },
133 /*
134 {
135 32,
136 { 0x000000FF,
137 0x0000FF00,
138 0x00FF0000,
139 0xFF000000 },
140 avcodec::PIX_FMT_ABGR,
141 true,
142 true,
143 PixelFormatYCbCr_Invalid,
144 },
145 {
146 32,
147 { 0xFF000000,
148 0x00FF0000,
149 0x0000FF00,
150 0x000000FF },
151 avcodec::PIX_FMT_RGBA,
152 true,
153 true,
154 PixelFormatYCbCr_Invalid,
155 }, */
156 {
157 24,
158 { 0xFF0000, 0x00FF00, 0x0000FF, 0x000000 },
159 avcodec::PIX_FMT_RGB24,
160 true,
161 true,
162 PixelFormatYCbCr_Invalid,
163 },
164 {
165 24,
166 { 0x0000FF, 0x00FF00, 0xFF0000, 0x000000 },
167 avcodec::PIX_FMT_BGR24,
168 true,
169 true,
170 PixelFormatYCbCr_Invalid,
171 },
172 {
173 16,
174 { 0x7C00, 0x03E0, 0x001F, 0x0000 },
175 avcodec::PIX_FMT_RGB555,
176 false,
177 false,
178 PixelFormatYCbCr_Invalid,
179 },
180 { 0,
181 { 0, 0, 0, 0 },
182 avcodec::PIX_FMT_NB,
183 true,
184 false,
185 PixelFormatYCbCr_Invalid } };
186
187#endif
Definition MovieTexture_FFMpeg.h:48
Definition MovieTexture_Generic.h:20
Definition MovieTexture_FFMpeg.h:21
Definition MovieTexture_Generic.h:83
Definition MovieTexture_FFMpeg.h:35
Definition MovieTexture.h:37
Definition MovieTexture.h:12
Definition RageSurface.h:90
Definition RageTextureID.h:12