ddnet/src/engine/shared/video.h
Robert Müller 07e18ebecb Replace most global variables in engine sound with member variables
Most variables used in the sound engine were static globals, as they are used in the static sound mixing function. The global variables are replaced by member variables, by passing the sound interface as user-data for the SDL mixing callback. The `Mix` function is made a public member function of `ISound` instead of being exposed using `ISoundMixFunc GetSoundMixFunc()`.

This allows to remove the direct dependency of the engine sound on the engine video, by instead passing the sound mixing function as a lambda to the engine video in the engine client.

The old WavPack reader function interface does support passing a user-data pointer to the callback function, so global variables are still used here.
2023-09-21 23:52:13 +02:00

42 lines
1 KiB
C++

#ifndef ENGINE_SHARED_VIDEO_H
#define ENGINE_SHARED_VIDEO_H
#include <base/system.h>
#include <functional>
typedef std::function<void(short *pFinalOut, unsigned Frames)> ISoundMixFunc;
class IVideo
{
public:
virtual ~IVideo(){};
virtual void Start() = 0;
virtual void Stop() = 0;
virtual void Pause(bool Pause) = 0;
virtual bool IsRecording() = 0;
virtual void NextVideoFrame() = 0;
virtual void NextVideoFrameThread() = 0;
virtual void NextAudioFrame(ISoundMixFunc Mix) = 0;
virtual void NextAudioFrameTimeline(ISoundMixFunc Mix) = 0;
static IVideo *Current() { return ms_pCurrentVideo; }
static int64_t Time() { return ms_Time; }
static float LocalTime() { return ms_LocalTime; }
static void SetLocalStartTime(int64_t LocalStartTime) { ms_LocalStartTime = LocalStartTime; }
static void SetFPS(int FPS) { ms_TickTime = time_freq() / FPS; }
protected:
static IVideo *ms_pCurrentVideo;
static int64_t ms_Time;
static int64_t ms_LocalStartTime;
static float ms_LocalTime;
static int64_t ms_TickTime;
};
#endif