102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
movies.c File Reference
#include <dttr_pcdogs.h>
#include "../graphics/graphics_private.h"
#include "hooks_private.h"
#include "movies_private.h"
#include "sidecar_private.h"
#include <dttr_log.h>
#include <dttr_path.h>
#include <sds.h>
#include <SDL3/SDL.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/channel_layout.h>
#include <libavutil/error.h>
#include <libavutil/samplefmt.h>
#include <libswresample/swresample.h>
#include <libswscale/swscale.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  movie_state

Macros

#define AUDIO_CHANNELS   2
#define AUDIO_FORMAT   AV_SAMPLE_FMT_S16
#define AUDIO_QUEUE_LIMIT_MS   500
#define AUDIO_DRAIN_LIMIT_MS   750

Functions

static BOOL movie_play_file_detour (const char *movie_path, char use_alt_video_rect)
static void reset_movie_state (dttr_movie_result result)
static const char * movie_error_string (const int err)
static void reset_video_buffer ()
static void close_audio ()
static void close_movie ()
static AVCodecContext * open_codec (const AVStream *stream)
static bool prepare_audio ()
static bool open_movie (const char *path)
static double video_pts_seconds (const int64_t pts)
static void set_next_video_time (const double pts)
static double frame_pts_seconds (const AVFrame *frame)
static double packet_pts_seconds (const AVPacket *packet)
static bool queue_video_frame (const AVFrame *frame)
static bool queue_audio_frame (const AVFrame *frame)
static bool receive_video_frame ()
static void receive_audio_frames ()
static bool drain_eof ()
static void send_packet ()
static bool decode_until_video_frame ()
void dttr_movies_init ()
bool dttr_movies_hooks_init (const DTTR_Mods_Context *ctx)
void dttr_movies_hooks_cleanup (const DTTR_Mods_Context *)
void dttr_movies_cleanup ()
void dttr_movies_start (const char *path)
void dttr_movies_tick ()
bool dttr_movies_handle_event (const SDL_Event *event)
dttr_movie_result dttr_movies_stop ()
bool dttr_movies_is_playing ()
int32_t dttr_movies_hook_movie_play_file_callback (const char *path, const int32_t use_alt_rect)

Variables

static DTTR_Core_PatchGroupmovie_patch_group
static movie_state movie
static AVFrame * video_frame = NULL
static AVFrame * audio_frame = NULL
static AVPacket * packet = NULL

Macro Definition Documentation

◆ AUDIO_CHANNELS

#define AUDIO_CHANNELS   2

Definition at line 35 of file movies.c.

Referenced by prepare_audio(), and queue_audio_frame().

◆ AUDIO_DRAIN_LIMIT_MS

#define AUDIO_DRAIN_LIMIT_MS   750

Definition at line 38 of file movies.c.

Referenced by drain_eof().

◆ AUDIO_FORMAT

#define AUDIO_FORMAT   AV_SAMPLE_FMT_S16

Definition at line 36 of file movies.c.

Referenced by prepare_audio(), and queue_audio_frame().

◆ AUDIO_QUEUE_LIMIT_MS

#define AUDIO_QUEUE_LIMIT_MS   500

Definition at line 37 of file movies.c.

Referenced by queue_audio_frame().

Function Documentation

◆ close_audio()

void close_audio ( )
static

Definition at line 108 of file movies.c.

References movie, and NULL.

Referenced by close_movie().

◆ close_movie()

void close_movie ( )
static

◆ decode_until_video_frame()

bool decode_until_video_frame ( )
static

◆ drain_eof()

bool drain_eof ( )
static

◆ dttr_movies_cleanup()

void dttr_movies_cleanup ( )

Definition at line 635 of file movies.c.

References audio_frame, close_movie(), DTTR_LOG_INFO, packet, and video_frame.

Referenced by cleanup_runtime().

◆ dttr_movies_handle_event()

bool dttr_movies_handle_event ( const SDL_Event * event)

◆ dttr_movies_hook_movie_play_file_callback()

int32_t dttr_movies_hook_movie_play_file_callback ( const char * path,
const int32_t use_alt_rect )

◆ dttr_movies_hooks_cleanup()

void dttr_movies_hooks_cleanup ( const DTTR_Mods_Context * ctx)

Definition at line 630 of file movies.c.

References DTTR_Core_PatchGroupRelease(), and movie_patch_group.

Referenced by cleanup_runtime().

◆ dttr_movies_hooks_init()

◆ dttr_movies_init()

void dttr_movies_init ( )

Definition at line 606 of file movies.c.

References audio_frame, DTTR_LOG_ERROR, packet, and video_frame.

Referenced by install_required_sidecar_hooks().

◆ dttr_movies_is_playing()

bool dttr_movies_is_playing ( )

◆ dttr_movies_start()

◆ dttr_movies_stop()

dttr_movie_result dttr_movies_stop ( )

◆ dttr_movies_tick()

◆ frame_pts_seconds()

double frame_pts_seconds ( const AVFrame * frame)
static

Definition at line 315 of file movies.c.

References video_pts_seconds().

Referenced by queue_video_frame().

◆ movie_error_string()

const char * movie_error_string ( const int err)
static

◆ movie_play_file_detour()

BOOL movie_play_file_detour ( const char * movie_path,
char use_alt_video_rect )
static

Definition at line 28 of file movies.c.

References BOOL, and dttr_movies_hook_movie_play_file_callback().

Referenced by dttr_movies_hooks_init().

◆ open_codec()

AVCodecContext * open_codec ( const AVStream * stream)
static

Definition at line 130 of file movies.c.

References ctx, DTTR_LOG_ERROR, movie_error_string(), and NULL.

Referenced by open_movie().

◆ open_movie()

bool open_movie ( const char * path)
static

Definition at line 228 of file movies.c.

References DTTR_LOG_ERROR, movie, movie_error_string(), NULL, open_codec(), and prepare_audio().

Referenced by dttr_movies_start().

◆ packet_pts_seconds()

double packet_pts_seconds ( const AVPacket * packet)
static

Definition at line 320 of file movies.c.

References packet, and video_pts_seconds().

Referenced by send_packet().

◆ prepare_audio()

bool prepare_audio ( )
static

Definition at line 168 of file movies.c.

References AUDIO_CHANNELS, AUDIO_FORMAT, DTTR_LOG_ERROR, movie, movie_error_string(), and NULL.

Referenced by open_movie().

◆ queue_audio_frame()

bool queue_audio_frame ( const AVFrame * frame)
static

◆ queue_video_frame()

bool queue_video_frame ( const AVFrame * frame)
static

Definition at line 325 of file movies.c.

References DTTR_LOG_DEBUG, DTTR_LOG_ERROR, frame_pts_seconds(), h, movie, NULL, set_next_video_time(), size, stride, and w.

Referenced by receive_video_frame().

◆ receive_audio_frames()

void receive_audio_frames ( )
static

Definition at line 475 of file movies.c.

References audio_frame, DTTR_LOG_WARN, movie, movie_error_string(), and queue_audio_frame().

Referenced by decode_until_video_frame(), and drain_eof().

◆ receive_video_frame()

bool receive_video_frame ( )
static

◆ reset_movie_state()

void reset_movie_state ( dttr_movie_result result)
static

Definition at line 79 of file movies.c.

References movie.

Referenced by close_movie().

◆ reset_video_buffer()

void reset_video_buffer ( )
static

Definition at line 98 of file movies.c.

References free, movie, and NULL.

Referenced by close_movie().

◆ send_packet()

◆ set_next_video_time()

void set_next_video_time ( const double pts)
static

Definition at line 299 of file movies.c.

References movie.

Referenced by queue_video_frame(), and send_packet().

◆ video_pts_seconds()

double video_pts_seconds ( const int64_t pts)
static

Definition at line 288 of file movies.c.

References movie.

Referenced by frame_pts_seconds(), and packet_pts_seconds().

Variable Documentation

◆ audio_frame

AVFrame* audio_frame = NULL
static

◆ movie

◆ movie_patch_group

DTTR_Core_PatchGroup* movie_patch_group
static

Definition at line 25 of file movies.c.

Referenced by dttr_movies_hooks_cleanup(), and dttr_movies_hooks_init().

◆ packet

AVPacket* packet = NULL
static

◆ video_frame

AVFrame* video_frame = NULL
static