Add hw acceleration, improve video performance

This commit is contained in:
markmental 2026-03-27 23:19:42 -04:00
commit 7c5d82e124
13 changed files with 273 additions and 72 deletions

View file

@ -272,7 +272,7 @@ static int queue_audio_frame(Player *player,
: audio_frame->best_effort_timestamp * av_q2d(audio_time_base);
frame_duration = (double) sample_count / (double) out_rate;
queued_limit = (int) (player_audio_bytes_per_second(player) * 0.12);
queued_limit = (int) (player_audio_bytes_per_second(player) * 0.18);
while (!should_stop(player) && (int) SDL_GetQueuedAudioSize(player->audio_device) > queued_limit) {
SDL_Delay(2);
}
@ -420,7 +420,7 @@ static int decode_thread_main(void *userdata) {
goto cleanup;
}
seek_seconds = channel_live_position(channel, player->app_start_time, time(NULL));
seek_seconds = channel_live_position_precise(channel, player->app_start_ticks, SDL_GetTicks64());
if (channel->duration_seconds > 0.0) {
int64_t seek_target = (int64_t) (seek_seconds / av_q2d(time_base));
avformat_seek_file(format_context, video_stream_index, INT64_MIN, seek_target, INT64_MAX, 0);
@ -583,7 +583,7 @@ static void player_stop_thread(Player *player) {
player->thread = NULL;
}
int player_init(Player *player, const ChannelList *channels, time_t app_start_time) {
int player_init(Player *player, const ChannelList *channels, Uint64 app_start_ticks) {
if (!player || !channels) {
return -1;
}
@ -591,7 +591,7 @@ int player_init(Player *player, const ChannelList *channels, time_t app_start_ti
memset(player, 0, sizeof(*player));
player->channels = channels;
player->current_index = -1;
player->app_start_time = app_start_time;
player->app_start_ticks = app_start_ticks;
player->audio_mutex = SDL_CreateMutex();
player->clock_mutex = SDL_CreateMutex();
player->error_mutex = SDL_CreateMutex();
@ -692,7 +692,7 @@ int player_consume_synced_frame(Player *player, FrameData *out, double clock_sec
return 0;
}
late_tolerance = SDL_GetTicks() < player->catchup_until ? 0.180 : 0.090;
late_tolerance = SDL_GetTicks() < player->catchup_until ? 0.220 : 0.130;
while (frame_queue_peek_first(&player->frame_queue, &candidate)) {
if (candidate.pts_seconds < clock_seconds - late_tolerance) {
@ -728,15 +728,15 @@ int player_consume_synced_frame(Player *player, FrameData *out, double clock_sec
return 0;
}
double player_live_position(const Player *player, time_t now) {
double player_live_position(const Player *player, Uint64 now_ticks) {
if (!player || !player->channels || player->current_index < 0 || player->current_index >= player->channels->count) {
return 0.0;
}
return channel_live_position(&player->channels->items[player->current_index], player->app_start_time, now);
return channel_live_position_precise(&player->channels->items[player->current_index], player->app_start_ticks, now_ticks);
}
double player_get_sync_clock(Player *player, time_t now) {
double player_get_sync_clock(Player *player, Uint64 now_ticks) {
double clock_seconds;
double queued_seconds = 0.0;
double bytes_per_second;
@ -747,12 +747,12 @@ double player_get_sync_clock(Player *player, time_t now) {
}
if (!player->has_audio_stream || player->audio_device == 0) {
return player_live_position(player, now);
return player_live_position(player, now_ticks);
}
bytes_per_second = player_audio_bytes_per_second(player);
if (bytes_per_second <= 0.0) {
return player_live_position(player, now);
return player_live_position(player, now_ticks);
}
SDL_LockMutex(player->clock_mutex);
@ -761,7 +761,7 @@ double player_get_sync_clock(Player *player, time_t now) {
SDL_UnlockMutex(player->clock_mutex);
if (!audio_started) {
return player_live_position(player, now);
return player_live_position(player, now_ticks);
}
queued_seconds = (double) SDL_GetQueuedAudioSize(player->audio_device) / bytes_per_second;