2026-03-27 21:45:40 -04:00
|
|
|
#ifndef PLAYER_H
|
|
|
|
|
#define PLAYER_H
|
|
|
|
|
|
2026-03-30 12:09:11 -04:00
|
|
|
#include <stdint.h>
|
2026-03-27 21:45:40 -04:00
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
#include "channel.h"
|
|
|
|
|
#include "frame_queue.h"
|
|
|
|
|
|
|
|
|
|
typedef struct Player {
|
|
|
|
|
FrameQueue frame_queue;
|
2026-03-30 12:09:11 -04:00
|
|
|
VideoBufferPool video_buffer_pool;
|
2026-03-27 21:45:40 -04:00
|
|
|
SDL_Thread *thread;
|
|
|
|
|
SDL_atomic_t stop_requested;
|
|
|
|
|
const ChannelList *channels;
|
|
|
|
|
int current_index;
|
2026-03-27 23:19:42 -04:00
|
|
|
Uint64 app_start_ticks;
|
2026-03-27 21:45:40 -04:00
|
|
|
Uint32 tuning_blackout_until;
|
2026-03-27 22:59:37 -04:00
|
|
|
SDL_AudioDeviceID audio_device;
|
|
|
|
|
SDL_AudioSpec audio_spec;
|
|
|
|
|
SDL_mutex *audio_mutex;
|
|
|
|
|
SDL_mutex *clock_mutex;
|
|
|
|
|
double latest_audio_end_pts;
|
|
|
|
|
int has_audio_stream;
|
|
|
|
|
int audio_started;
|
|
|
|
|
int preroll_ready;
|
|
|
|
|
Uint32 catchup_until;
|
|
|
|
|
char audio_driver[32];
|
2026-03-27 21:45:40 -04:00
|
|
|
SDL_mutex *error_mutex;
|
|
|
|
|
char last_error[256];
|
2026-03-30 12:09:11 -04:00
|
|
|
uint8_t *audio_convert_buffer;
|
|
|
|
|
int audio_convert_buffer_size;
|
|
|
|
|
int audio_convert_buffer_samples;
|
2026-03-27 21:45:40 -04:00
|
|
|
} Player;
|
|
|
|
|
|
2026-03-27 23:19:42 -04:00
|
|
|
int player_init(Player *player, const ChannelList *channels, Uint64 app_start_ticks);
|
2026-03-27 21:45:40 -04:00
|
|
|
void player_destroy(Player *player);
|
|
|
|
|
int player_tune(Player *player, int channel_index);
|
|
|
|
|
int player_consume_latest_frame(Player *player, FrameData *out);
|
2026-03-27 22:59:37 -04:00
|
|
|
int player_consume_synced_frame(Player *player, FrameData *out, double clock_seconds, double lead_tolerance);
|
2026-03-27 23:19:42 -04:00
|
|
|
double player_live_position(const Player *player, Uint64 now_ticks);
|
|
|
|
|
double player_get_sync_clock(Player *player, Uint64 now_ticks);
|
2026-03-27 22:59:37 -04:00
|
|
|
void player_set_catchup_until(Player *player, Uint32 tick);
|
2026-03-27 21:45:40 -04:00
|
|
|
int player_is_in_blackout(const Player *player);
|
2026-03-27 22:59:37 -04:00
|
|
|
void player_resume_audio(Player *player);
|
2026-03-27 21:45:40 -04:00
|
|
|
void player_get_error(Player *player, char *buffer, size_t buffer_size);
|
|
|
|
|
|
|
|
|
|
#endif
|