persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
VideoController.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <aegis/ndsTypes.hpp>
5#include <aegis/types.hpp>
6
7#include <nds.h>
8#include <stdio.h>
9#include <string>
10
12constexpr uint8_t FRAMES_TO_BUFFER = 15;
13
15constexpr uint8_t READS_PER_UPDATE = 3;
16
18constexpr uint16_t AUDIO_CHUNK_MAX = 16384;
19
25constexpr uint16_t VIDEO_READ_SLICE = 16384;
26
28constexpr uint8_t VIDEO_AUDIO_STREAM_MS = 100;
29
36constexpr int8_t VIDEO_SYNC_OFFSET_MS = 0;
37
39struct VideoAudio;
40
52{
53 public:
55 static void create();
56
58 static void destroy();
59
62
74 void init(std::string iFileName, ae::q20_12_t iFps, ViewState iNextState);
75
81
83 void cleanup();
84
86 void stopInternalAudio();
87
88 private:
89 VideoController() = default;
91 {
92 cleanup();
93 }
95
97 uint8_t fpsInt = 24;
98
99 FILE* videoFile = nullptr;
100 bool fileEOF = false;
101 int64_t currentFrame = 0;
102 int8_t bg = -1;
103
104 uint8_t* ramBuffer = nullptr;
105 uint16_t readIndex = 0;
106 uint16_t writeIndex = 0;
107 uint16_t framesAvailable = 0;
108
109 // dynamic video variables
110 uint16_t frameW = 0;
111 uint16_t frameH = 0;
112 uint8_t bpp = 0;
113 uint32_t frameSize = 0;
114 uint32_t bufferSize = 0;
115
116 // multiplexed audio
117 VideoAudio* aud = nullptr;
118 bool haveChunkHeader = false;
119 uint32_t pendingAudioSize = 0;
120 uint32_t silentVblanks = 0;
121
129 bool refillBuffer();
130
132 void pumpAudio();
133
135 void setEOF();
136
141 int clockFrame() const;
142};
ViewState
Definition StateTypes.hpp:4
constexpr uint16_t AUDIO_CHUNK_MAX
Maximum audio payload (bytes) in one per-frame chunk. Must match MAX_AUDIO_CHUNK in video2vid....
constexpr uint8_t FRAMES_TO_BUFFER
Number of decoded video frames held in the RAM ring buffer.
constexpr uint8_t VIDEO_AUDIO_STREAM_MS
Length of the maxmod audio stream buffer in ms. Larger tolerates slower SD reads.
constexpr int8_t VIDEO_SYNC_OFFSET_MS
Fine A/V sync offset in ms.
constexpr uint8_t READS_PER_UPDATE
Maximum frame reads per update(). Reads stop early if a frame is already due.
constexpr uint16_t VIDEO_READ_SLICE
Size (bytes) of each SD card read slice when loading a video frame.
static void create()
Creates the singleton instance if it does not exist.
void pumpAudio()
Feeds the maxmod stream; a no-op when no audio is active.
VideoAudio * aud
Internal audio player; non-null while audio is active.
uint32_t frameSize
Size of one frame in bytes.
void stopInternalAudio()
Shuts down and frees the internal audio player.
uint8_t * ramBuffer
Ring buffer holding FRAMES_TO_BUFFER decoded frames.
static VideoController * instance
Singleton instance.
void cleanup()
Stops playback and releases the file, audio stream and frame buffer.
FILE * videoFile
Open .vid file handle.
static VideoController * getInstance()
uint16_t frameW
Frame width in pixels.
int64_t currentFrame
Index of the next frame to display.
ViewState update()
Advances playback: pumps audio, displays the next due frame and reads ahead.
ViewState nextState
State returned when playback ends.
bool haveChunkHeader
True if the current chunk's audio size has been read.
uint16_t writeIndex
Ring slot the next frame is read into.
uint32_t pendingAudioSize
Audio bytes still to be read for the current chunk.
void setEOF()
Marks end of file and tells the audio player no more data will arrive.
bool refillBuffer()
Reads one audio chunk (into the audio ring) and one video frame.
static void destroy()
Destroys the singleton instance and releases all video resources.
void init(std::string iFileName, ae::q20_12_t iFps, ViewState iNextState)
Opens and prepares a video stream.
int8_t bg
Background id returned by bgInit().
uint32_t silentVblanks
Pacing clock (vblanks) used when there is no audio.
bool fileEOF
True once the file (or a read) is exhausted.
int clockFrame() const
Computes the frame that should be on screen now.
VideoController()=default
uint16_t framesAvailable
Number of frames currently buffered.
uint8_t bpp
Bytes per pixel (1 = 8-bit paletted, 2 = 16-bit).
uint16_t frameH
Frame height in pixels.
uint32_t bufferSize
Total size of the frame ring buffer in bytes.
uint8_t fpsInt
Frame rate in whole fps (from the header or fallback).
uint16_t readIndex
Ring slot of the next frame to display.