Skip to content

Commit 285dee9

Browse files
committed
[ZH][LINUX] Add FFmpegVideoPlayer as video backend (#714)
1 parent f44428b commit 285dee9

File tree

3 files changed

+686
-2
lines changed

3 files changed

+686
-2
lines changed

GeneralsMD/Code/GameEngineDevice/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ find_package(FFMPEG)
235235
if(FFMPEG_FOUND)
236236
target_sources(z_gameenginedevice PRIVATE
237237
Include/VideoDevice/FFmpeg/FFmpegFile.h
238-
#Include/VideoDevice/FFmpeg/FFmpegVideoPlayer.h
238+
Include/VideoDevice/FFmpeg/FFmpegVideoPlayer.h
239239
Source/VideoDevice/FFmpeg/FFmpegFile.cpp
240-
#Source/VideoDevice/FFmpeg/FFmpegVideoPlayer.cpp
240+
Source/VideoDevice/FFmpeg/FFmpegVideoPlayer.cpp
241241
)
242242

243243
target_include_directories(z_gameenginedevice PRIVATE ${FFMPEG_INCLUDE_DIRS})
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
** Command & Conquer Generals Zero Hour(tm)
3+
** Copyright 2025 TheSuperHackers
4+
**
5+
** This program is free software: you can redistribute it and/or modify
6+
** it under the terms of the GNU General Public License as published by
7+
** the Free Software Foundation, either version 3 of the License, or
8+
** (at your option) any later version.
9+
**
10+
** This program is distributed in the hope that it will be useful,
11+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
** GNU General Public License for more details.
14+
**
15+
** You should have received a copy of the GNU General Public License
16+
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
////////////////////////////////////////////////////////////////////////////////
20+
// //
21+
// (c) 2001-2003 Electronic Arts Inc. //
22+
// //
23+
////////////////////////////////////////////////////////////////////////////////
24+
25+
//////// FFmpegVideoPlayer.h ///////////////////////////
26+
// Stephan Vedder, April 2025
27+
/////////////////////////////////////////////////
28+
29+
#pragma once
30+
31+
#ifndef __VIDEODEVICE_FFMPEGDEVICE_H_
32+
#define __VIDEODEVICE_FFMPEGDEVICE_H_
33+
34+
35+
//----------------------------------------------------------------------------
36+
// Includes
37+
//----------------------------------------------------------------------------
38+
39+
#include "GameClient/VideoPlayer.h"
40+
41+
//----------------------------------------------------------------------------
42+
// Forward References
43+
//----------------------------------------------------------------------------
44+
45+
class FFmpegFile;
46+
struct AVFrame;
47+
struct SwsContext;
48+
49+
//----------------------------------------------------------------------------
50+
// Type Defines
51+
//----------------------------------------------------------------------------
52+
53+
//===============================
54+
// FFmpegVideoStream
55+
//===============================
56+
57+
class FFmpegVideoStream : public VideoStream
58+
{
59+
friend class FFmpegVideoPlayer;
60+
61+
protected:
62+
Bool m_good = true; ///< Is the stream valid
63+
Bool m_gotFrame = false; ///< Is the frame ready to be displayed
64+
AVFrame *m_frame = nullptr; ///< Current frame
65+
SwsContext *m_swsContext = nullptr;///< SWSContext for scaling
66+
FFmpegFile *m_ffmpegFile; ///< The AVUI abstraction ///< Bink streaming handle;
67+
Char *m_memFile; ///< Pointer to memory resident file
68+
UnsignedInt64 m_startTime = 0; ///< Time the stream started
69+
UnsignedByte * m_audioBuffer = nullptr;///< Audio buffer for the stream
70+
71+
FFmpegVideoStream(FFmpegFile* file); ///< only BinkVideoPlayer can create these
72+
virtual ~FFmpegVideoStream();
73+
74+
static void onFrame(AVFrame *frame, int stream_idx, int stream_type, void *user_data);
75+
public:
76+
77+
virtual void update( void ); ///< Update bink stream
78+
79+
virtual Bool isFrameReady( void ); ///< Is the frame ready to be displayed
80+
virtual void frameDecompress( void ); ///< Render current frame in to buffer
81+
virtual void frameRender( VideoBuffer *buffer ); ///< Render current frame in to buffer
82+
virtual void frameNext( void ); ///< Advance to next frame
83+
virtual Int frameIndex( void ); ///< Returns zero based index of current frame
84+
virtual Int frameCount( void ); ///< Returns the total number of frames in the stream
85+
virtual void frameGoto( Int index ); ///< Go to the spcified frame index
86+
virtual Int height( void ); ///< Return the height of the video
87+
virtual Int width( void ); ///< Return the width of the video
88+
89+
90+
};
91+
92+
//===============================
93+
// FFmpegVideoPlayer
94+
//===============================
95+
/**
96+
* FFmpeg video playback code.
97+
*/
98+
//===============================
99+
100+
class FFmpegVideoPlayer : public VideoPlayer
101+
{
102+
103+
protected:
104+
105+
VideoStreamInterface* createStream( File* file );
106+
107+
public:
108+
109+
// subsytem requirements
110+
virtual void init( void ); ///< Initialize video playback code
111+
virtual void reset( void ); ///< Reset video playback
112+
virtual void update( void ); ///< Services all audio tasks. Should be called frequently
113+
114+
virtual void deinit( void ); ///< Close down player
115+
116+
117+
FFmpegVideoPlayer();
118+
~FFmpegVideoPlayer();
119+
120+
// service
121+
virtual void loseFocus( void ); ///< Should be called when application loses focus
122+
virtual void regainFocus( void ); ///< Should be called when application regains focus
123+
124+
virtual VideoStreamInterface* open( AsciiString movieTitle ); ///< Open video file for playback
125+
virtual VideoStreamInterface* load( AsciiString movieTitle ); ///< Load video file in to memory for playback
126+
127+
virtual void notifyVideoPlayerOfNewProvider( Bool nowHasValid );
128+
virtual void initializeBinkWithMiles( void );
129+
};
130+
131+
132+
//----------------------------------------------------------------------------
133+
// Inlining
134+
//----------------------------------------------------------------------------
135+
136+
137+
#endif // __VIDEODEVICE_FFMPEGDEVICE_H_

0 commit comments

Comments
 (0)