feat: adopt IINA-style playback window

This commit is contained in:
2026-10-10 01:35:49 +02:00
parent df2456f559
commit 462cb52eb2
8 changed files with 654 additions and 76 deletions
+3
View File
@@ -18,6 +18,9 @@ public:
bool configure_audio(std::string &error);
bool start(std::string &error);
void pause();
// Atomic target gain; callback slews to it within 240 frames (5 ms).
void set_volume(float normalized0to1) noexcept;
float volume() const noexcept;
// Called with audio stopped. Clears audio and video from the old timeline.
void reset();
std::size_t write(const float *samples, std::size_t frames, double pts);
+10
View File
@@ -748,6 +748,16 @@ bool player_seek(Player *player, double seconds) {
bool player_close(Player *player) {
return submit(player, [=] { return player->enqueue({Action::Close, {}}); });
}
bool player_set_volume(Player *player, float normalized0to1) {
if (!std::isfinite(normalized0to1) || normalized0to1 < 0 || normalized0to1 > 1) return false;
return submit(player, [=] {
player->output.set_volume(normalized0to1);
return true;
});
}
float player_get_volume(Player *player) {
return player ? player->output.volume() : 0;
}
PlayerState player_get_state(Player *player) {
try {
if (player) {
+6 -1
View File
@@ -21,7 +21,7 @@ typedef struct PlayerState {
char error[512];
} PlayerState;
// Commands are asynchronous. False means invalid input or a full command queue.
// Playback commands are asynchronous. False means invalid input or a full command queue.
// Paths are copied before returning. All other calls require a live handle.
Player *player_create(void);
bool player_open(Player *player, const char *path);
@@ -29,6 +29,11 @@ bool player_play(Player *player);
bool player_pause(Player *player);
bool player_seek(Player *player, double seconds);
bool player_close(Player *player);
// Synchronous, thread-safe gain; survives open, seek, and close. Zero mutes.
// Rejects null handles and non-finite/out-of-range values without changing gain.
bool player_set_volume(Player *player, float normalized0to1);
// Returns the target gain immediately; zero for a null handle.
float player_get_volume(Player *player);
PlayerState player_get_state(Player *player);
// Joins the worker and stops audio; never invoke from an audio callback.
void player_destroy(Player *player);