persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
VideoController Class Reference

Streams video frames and multiplexed QOA audio from a single .vid file. More...

#include <VideoController.hpp>

Collaboration diagram for VideoController:

Public Member Functions

void init (std::string iFileName, ae::q20_12_t iFps, ViewState iNextState)
 Opens and prepares a video stream.
ViewState update ()
 Advances playback: pumps audio, displays the next due frame and reads ahead.
void cleanup ()
 Stops playback and releases the file, audio stream and frame buffer.
void stopInternalAudio ()
 Shuts down and frees the internal audio player.

Static Public Member Functions

static void create ()
 Creates the singleton instance if it does not exist.
static void destroy ()
 Destroys the singleton instance and releases all video resources.
static VideoController * getInstance ()

Private Member Functions

 VideoController ()=default
 ~VideoController ()
bool refillBuffer ()
 Reads one audio chunk (into the audio ring) and one video frame.
void pumpAudio ()
 Feeds the maxmod stream; a no-op when no audio is active.
void setEOF ()
 Marks end of file and tells the audio player no more data will arrive.
int clockFrame () const
 Computes the frame that should be on screen now.

Private Attributes

ViewState nextState = ViewState::DEFAULT
 State returned when playback ends.
uint8_t fpsInt = 24
 Frame rate in whole fps (from the header or fallback).
FILE * videoFile = nullptr
 Open .vid file handle.
bool fileEOF = false
 True once the file (or a read) is exhausted.
int64_t currentFrame = 0
 Index of the next frame to display.
int8_t bg = -1
 Background id returned by bgInit().
uint8_t * ramBuffer = nullptr
 Ring buffer holding FRAMES_TO_BUFFER decoded frames.
uint16_t readIndex = 0
 Ring slot of the next frame to display.
uint16_t writeIndex = 0
 Ring slot the next frame is read into.
uint16_t framesAvailable = 0
 Number of frames currently buffered.
uint16_t frameW = 0
 Frame width in pixels.
uint16_t frameH = 0
 Frame height in pixels.
uint8_t bpp = 0
 Bytes per pixel (1 = 8-bit paletted, 2 = 16-bit).
uint32_t frameSize = 0
 Size of one frame in bytes.
uint32_t bufferSize = 0
 Total size of the frame ring buffer in bytes.
VideoAudio * aud = nullptr
 Internal audio player; non-null while audio is active.
bool haveChunkHeader = false
 True if the current chunk's audio size has been read.
uint32_t pendingAudioSize = 0
 Audio bytes still to be read for the current chunk.
uint32_t silentVblanks = 0
 Pacing clock (vblanks) used when there is no audio.

Static Private Attributes

static VideoController * instance = nullptr
 Singleton instance.

Detailed Description

Streams video frames and multiplexed QOA audio from a single .vid file.

Audio is decoded and streamed by a private QOA/maxmod player inside this class (AudioManager is not used for playback). The audio clock drives frame pacing; files without audio use a vblank clock instead.

The controller is a singleton and owns its file handle, frame buffer and audio player.

Definition at line 51 of file VideoController.hpp.

Constructor & Destructor Documentation

◆ VideoController()

VideoController::VideoController ( )
privatedefault
Here is the caller graph for this function:

◆ ~VideoController()

VideoController::~VideoController ( )
inlineprivate

Definition at line 90 of file VideoController.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ cleanup()

void VideoController::cleanup ( )

Stops playback and releases the file, audio stream and frame buffer.

Definition at line 609 of file VideoController.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clockFrame()

int VideoController::clockFrame ( ) const
private

Computes the frame that should be on screen now.

Returns
Expected frame index from the audio clock, or from the vblank clock if there is no audio.

Definition at line 322 of file VideoController.cpp.

Here is the caller graph for this function:

◆ create()

void VideoController::create ( )
static

Creates the singleton instance if it does not exist.

Definition at line 269 of file VideoController.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy()

void VideoController::destroy ( )
static

Destroys the singleton instance and releases all video resources.

Definition at line 277 of file VideoController.cpp.

◆ getInstance()

VideoController * VideoController::getInstance ( )
static
Returns
The process-wide video controller instance (created on demand).

Definition at line 286 of file VideoController.cpp.

Here is the call graph for this function:

◆ init()

void VideoController::init ( std::string iFileName,
ae::q20_12_t iFps,
ViewState iNextState )

Opens and prepares a video stream.

Reads the .vid header, configures the display background, allocates the frame buffer, starts the internal audio player (if the file has audio) and prefills the buffers. Any previous playback is released first.

Parameters
iFileNameVideo filename relative to the data video directory.
iFpsFallback frame rate when the file has no header.
iNextStateView state returned by update() after playback completes.

Definition at line 331 of file VideoController.cpp.

Here is the call graph for this function:

◆ pumpAudio()

void VideoController::pumpAudio ( )
private

Feeds the maxmod stream; a no-op when no audio is active.

Definition at line 295 of file VideoController.cpp.

Here is the caller graph for this function:

◆ refillBuffer()

bool VideoController::refillBuffer ( )
private

Reads one audio chunk (into the audio ring) and one video frame.

Stops without reading if the frame buffer or audio ring is full.

Returns
true if a video frame was read.

Definition at line 475 of file VideoController.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setEOF()

void VideoController::setEOF ( )
private

Marks end of file and tells the audio player no more data will arrive.

Definition at line 313 of file VideoController.cpp.

Here is the caller graph for this function:

◆ stopInternalAudio()

void VideoController::stopInternalAudio ( )

Shuts down and frees the internal audio player.

Definition at line 303 of file VideoController.cpp.

Here is the caller graph for this function:

◆ update()

ViewState VideoController::update ( )

Advances playback: pumps audio, displays the next due frame and reads ahead.

Returns
ViewState::KEEP_CURRENT while playing, or the state passed to init() once finished.

Definition at line 550 of file VideoController.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ aud

VideoAudio* VideoController::aud = nullptr
private

Internal audio player; non-null while audio is active.

Definition at line 117 of file VideoController.hpp.

◆ bg

int8_t VideoController::bg = -1
private

Background id returned by bgInit().

Definition at line 102 of file VideoController.hpp.

◆ bpp

uint8_t VideoController::bpp = 0
private

Bytes per pixel (1 = 8-bit paletted, 2 = 16-bit).

Definition at line 112 of file VideoController.hpp.

◆ bufferSize

uint32_t VideoController::bufferSize = 0
private

Total size of the frame ring buffer in bytes.

Definition at line 114 of file VideoController.hpp.

◆ currentFrame

int64_t VideoController::currentFrame = 0
private

Index of the next frame to display.

Definition at line 101 of file VideoController.hpp.

◆ fileEOF

bool VideoController::fileEOF = false
private

True once the file (or a read) is exhausted.

Definition at line 100 of file VideoController.hpp.

◆ fpsInt

uint8_t VideoController::fpsInt = 24
private

Frame rate in whole fps (from the header or fallback).

Definition at line 97 of file VideoController.hpp.

◆ frameH

uint16_t VideoController::frameH = 0
private

Frame height in pixels.

Definition at line 111 of file VideoController.hpp.

◆ framesAvailable

uint16_t VideoController::framesAvailable = 0
private

Number of frames currently buffered.

Definition at line 107 of file VideoController.hpp.

◆ frameSize

uint32_t VideoController::frameSize = 0
private

Size of one frame in bytes.

Definition at line 113 of file VideoController.hpp.

◆ frameW

uint16_t VideoController::frameW = 0
private

Frame width in pixels.

Definition at line 110 of file VideoController.hpp.

◆ haveChunkHeader

bool VideoController::haveChunkHeader = false
private

True if the current chunk's audio size has been read.

Definition at line 118 of file VideoController.hpp.

◆ instance

VideoController * VideoController::instance = nullptr
staticprivate

Singleton instance.

Definition at line 94 of file VideoController.hpp.

◆ nextState

ViewState VideoController::nextState = ViewState::DEFAULT
private

State returned when playback ends.

Definition at line 96 of file VideoController.hpp.

◆ pendingAudioSize

uint32_t VideoController::pendingAudioSize = 0
private

Audio bytes still to be read for the current chunk.

Definition at line 119 of file VideoController.hpp.

◆ ramBuffer

uint8_t* VideoController::ramBuffer = nullptr
private

Ring buffer holding FRAMES_TO_BUFFER decoded frames.

Definition at line 104 of file VideoController.hpp.

◆ readIndex

uint16_t VideoController::readIndex = 0
private

Ring slot of the next frame to display.

Definition at line 105 of file VideoController.hpp.

◆ silentVblanks

uint32_t VideoController::silentVblanks = 0
private

Pacing clock (vblanks) used when there is no audio.

Definition at line 120 of file VideoController.hpp.

◆ videoFile

FILE* VideoController::videoFile = nullptr
private

Open .vid file handle.

Definition at line 99 of file VideoController.hpp.

◆ writeIndex

uint16_t VideoController::writeIndex = 0
private

Ring slot the next frame is read into.

Definition at line 106 of file VideoController.hpp.


The documentation for this class was generated from the following files: