Moonlight-XboxOG latest
Moonlight Xbox OG is a port of the Moonlight Game Streaming client to the original Xbox console.
streaming::FfmpegStreamBackend Class Reference

Owns the FFmpeg decode and SDL presentation state for one stream. More...

#include <src/streaming/ffmpeg_stream_backend.h>

Public Member Functions

std::string build_overlay_status_line () const
 Build a short user-visible media status line.
 
void cleanup_audio_decoder ()
 Clean up all FFmpeg audio decode resources.
 
void cleanup_video_decoder ()
 Clean up all FFmpeg video decode resources.
 
void decode_and_play_audio_sample (const char *sampleData, int sampleLength)
 Decode and queue one Moonlight Opus audio payload.
 
bool ensure_audio_resampler ()
 Ensure the audio resampler matches the current decoded frame.
 
 FfmpegStreamBackend ()=default
 Construct an empty backend.
 
 FfmpegStreamBackend (const FfmpegStreamBackend &)=delete
 
bool has_decoded_video () const
 Report whether at least one decoded video frame is available.
 
bool has_unrendered_video_frame () const
 Report whether a newly decoded video frame has not been presented yet.
 
int initialize_audio_decoder (int audioConfiguration, const OPUS_MULTISTREAM_CONFIGURATION *opusConfig, int arFlags)
 Initialize the FFmpeg Opus decoder and SDL playback device.
 
void initialize_callbacks (DECODER_RENDERER_CALLBACKS *videoCallbacks, AUDIO_RENDERER_CALLBACKS *audioCallbacks) const
 Populate Moonlight callback tables for this backend.
 
std::uint64_t milliseconds_since_last_decoded_video_frame (std::uint64_t nowMicroseconds) const
 Return how long it has been since FFmpeg published a decoded video frame.
 
FfmpegStreamBackendoperator= (const FfmpegStreamBackend &)=delete
 
bool render_latest_video_frame (SDL_Renderer *renderer, int screenWidth, int screenHeight, bool allowDirectFramebuffer=true)
 Render the latest decoded video frame to the supplied renderer.
 
void set_audio_playback_enabled (bool enabled)
 Configure whether streamed audio should be decoded and played locally.
 
int setup_video_decoder (int videoFormat, int width, int height, int redrawRate, int drFlags)
 Initialize the FFmpeg H.264 decoder for Moonlight video callbacks.
 
void shutdown ()
 Release all FFmpeg, SDL, and cached frame resources.
 
void start_audio_playback ()
 Start SDL audio playback.
 
void start_video_decoder ()
 Start the video decode path.
 
void stop_audio_playback ()
 Stop SDL audio playback.
 
void stop_video_decoder ()
 Stop the video decode path.
 
 ~FfmpegStreamBackend ()
 Destroy the backend and release all resources.
 

Detailed Description

Owns the FFmpeg decode and SDL presentation state for one stream.

The backend exposes Moonlight-compatible callback tables for video and audio, decodes H.264 video and Opus stereo audio with FFmpeg, presents the most recent decoded frame through SDL, and queues decoded PCM samples to SDL audio.

Member Function Documentation

◆ build_overlay_status_line()

std::string streaming::FfmpegStreamBackend::build_overlay_status_line ( ) const

Build a short user-visible media status line.

Returns
Summary of decoded video and queued audio state.

◆ decode_and_play_audio_sample()

void streaming::FfmpegStreamBackend::decode_and_play_audio_sample ( const char * sampleData,
int sampleLength )

Decode and queue one Moonlight Opus audio payload.

Parameters
sampleDataEncoded Opus payload.
sampleLengthEncoded payload size in bytes.

◆ ensure_audio_resampler()

bool streaming::FfmpegStreamBackend::ensure_audio_resampler ( )

Ensure the audio resampler matches the current decoded frame.

Returns
True when the resampler is ready for audio conversion.

◆ has_decoded_video()

bool streaming::FfmpegStreamBackend::has_decoded_video ( ) const

Report whether at least one decoded video frame is available.

Returns
True when a decoded frame is ready for presentation.

◆ has_unrendered_video_frame()

bool streaming::FfmpegStreamBackend::has_unrendered_video_frame ( ) const

Report whether a newly decoded video frame has not been presented yet.

Returns
True when rendering would present a newer decoded frame.

◆ initialize_audio_decoder()

int streaming::FfmpegStreamBackend::initialize_audio_decoder ( int audioConfiguration,
const OPUS_MULTISTREAM_CONFIGURATION * opusConfig,
int arFlags )

Initialize the FFmpeg Opus decoder and SDL playback device.

Parameters
audioConfigurationNegotiated Moonlight audio configuration.
opusConfigNegotiated Opus multistream parameters.
arFlagsMoonlight audio renderer flags.
Returns
Zero on success.

◆ initialize_callbacks()

void streaming::FfmpegStreamBackend::initialize_callbacks ( DECODER_RENDERER_CALLBACKS * videoCallbacks,
AUDIO_RENDERER_CALLBACKS * audioCallbacks ) const

Populate Moonlight callback tables for this backend.

Parameters
videoCallbacksOutput video callback table.
audioCallbacksOutput audio callback table.

◆ milliseconds_since_last_decoded_video_frame()

std::uint64_t streaming::FfmpegStreamBackend::milliseconds_since_last_decoded_video_frame ( std::uint64_t nowMicroseconds) const

Return how long it has been since FFmpeg published a decoded video frame.

Parameters
nowMicrosecondsCurrent platform monotonic time.
Returns
Milliseconds since the last decoded frame, or zero before a frame is published.

◆ render_latest_video_frame()

bool streaming::FfmpegStreamBackend::render_latest_video_frame ( SDL_Renderer * renderer,
int screenWidth,
int screenHeight,
bool allowDirectFramebuffer = true )

Render the latest decoded video frame to the supplied renderer.

Parameters
rendererSDL renderer used by the stream session.
screenWidthCurrent renderer output width.
screenHeightCurrent renderer output height.
allowDirectFramebufferTrue when platform-specific direct presentation may bypass SDL's renderer.
Returns
True when a decoded frame was available and rendered.

◆ set_audio_playback_enabled()

void streaming::FfmpegStreamBackend::set_audio_playback_enabled ( bool enabled)

Configure whether streamed audio should be decoded and played locally.

Parameters
enabledTrue to decode and play Opus audio on the Xbox.

◆ setup_video_decoder()

int streaming::FfmpegStreamBackend::setup_video_decoder ( int videoFormat,
int width,
int height,
int redrawRate,
int drFlags )

Initialize the FFmpeg H.264 decoder for Moonlight video callbacks.

Parameters
videoFormatNegotiated Moonlight video format.
widthNegotiated stream width.
heightNegotiated stream height.
redrawRateNegotiated redraw rate.
drFlagsMoonlight decoder flags.
Returns
Zero on success.

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