clapper-app: Apply "adaptive-start-bitrate" on startup

Watch for "adaptive-bandwidth" changes during adaptive streaming, use these to
set "adaptive-start-bitrate" player property, so we do not always start streaming
from some constant bitrate value which might not be the best for everyone.

Additionally, store last value in GSettings on app exit and also add a command
line arg to set this too.
This commit is contained in:
Rafał Dzięgiel
2024-11-15 23:18:38 +01:00
parent e4045b98b3
commit 22430620a8
3 changed files with 21 additions and 1 deletions

View File

@@ -144,6 +144,8 @@ clapper_app_apply_options_to_window (ClapperAppWindow *dest_window, GVariantDict
clapper_player_set_mute (dest_player, option_bool); clapper_player_set_mute (dest_player, option_bool);
if (clapper_app_options_get ("speed", "d", options, src_player_obj, settings, &option_dbl)) if (clapper_app_options_get ("speed", "d", options, src_player_obj, settings, &option_dbl))
clapper_player_set_speed (dest_player, PERCENTAGE_ROUND (CLAMP (option_dbl, 0.05, 2.0))); clapper_player_set_speed (dest_player, PERCENTAGE_ROUND (CLAMP (option_dbl, 0.05, 2.0)));
if (clapper_app_options_get ("adaptive-start-bitrate", "i", options, src_player_obj, settings, &option_int))
clapper_player_set_adaptive_start_bitrate (dest_player, option_int);
if (clapper_app_options_get ("progression-mode", "i", options, src_queue_obj, settings, &option_int)) if (clapper_app_options_get ("progression-mode", "i", options, src_queue_obj, settings, &option_int))
clapper_queue_set_progression_mode (clapper_player_get_queue (dest_player), CLAMP (option_int, 0, 4)); clapper_queue_set_progression_mode (clapper_player_get_queue (dest_player), CLAMP (option_int, 0, 4));
if (clapper_app_options_get ("subtitles-enabled", "b", NULL, src_player_obj, settings, &option_bool)) if (clapper_app_options_get ("subtitles-enabled", "b", NULL, src_player_obj, settings, &option_bool))
@@ -196,6 +198,8 @@ _store_settings_from_window (ClapperAppApplication *self, ClapperAppWindow *app_
g_settings_set_double (self->settings, "volume", clapper_player_get_volume (player)); g_settings_set_double (self->settings, "volume", clapper_player_get_volume (player));
g_settings_set_boolean (self->settings, "mute", clapper_player_get_mute (player)); g_settings_set_boolean (self->settings, "mute", clapper_player_get_mute (player));
g_settings_set_double (self->settings, "speed", clapper_player_get_speed (player)); g_settings_set_double (self->settings, "speed", clapper_player_get_speed (player));
g_settings_set_int (self->settings, "adaptive-start-bitrate",
CLAMP (clapper_player_get_adaptive_bandwidth (player) * 0.8, 0, G_MAXINT));
g_settings_set_boolean (self->settings, "subtitles-enabled", clapper_player_get_subtitles_enabled (player)); g_settings_set_boolean (self->settings, "subtitles-enabled", clapper_player_get_subtitles_enabled (player));
g_settings_set_int (self->settings, "progression-mode", clapper_queue_get_progression_mode (queue)); g_settings_set_int (self->settings, "progression-mode", clapper_queue_get_progression_mode (queue));
@@ -676,6 +680,7 @@ clapper_app_application_constructed (GObject *object)
{ "enqueue", 0, 0, G_OPTION_ARG_NONE, NULL, _("Add media to queue in primary application instance"), NULL }, { "enqueue", 0, 0, G_OPTION_ARG_NONE, NULL, _("Add media to queue in primary application instance"), NULL },
{ "volume", 0, 0, G_OPTION_ARG_DOUBLE, NULL, _("Audio volume to set (0 - 2.0 range)"), NULL }, { "volume", 0, 0, G_OPTION_ARG_DOUBLE, NULL, _("Audio volume to set (0 - 2.0 range)"), NULL },
{ "speed", 0, 0, G_OPTION_ARG_DOUBLE, NULL, _("Playback speed to set (0.05 - 2.0 range)"), NULL }, { "speed", 0, 0, G_OPTION_ARG_DOUBLE, NULL, _("Playback speed to set (0.05 - 2.0 range)"), NULL },
{ "adaptive-start-bitrate", 0, 0, G_OPTION_ARG_INT, NULL, _("Initial bitrate for adaptive streaming"), NULL },
{ "progression-mode", 0, 0, G_OPTION_ARG_INT, NULL, _("Initial queue progression mode (0=none, 1=consecutive, 2=repeat-item, 3=carousel, 4=shuffle)"), NULL }, { "progression-mode", 0, 0, G_OPTION_ARG_INT, NULL, _("Initial queue progression mode (0=none, 1=consecutive, 2=repeat-item, 3=carousel, 4=shuffle)"), NULL },
{ "fullscreen", 'f', 0, G_OPTION_ARG_NONE, NULL, _("Set window to be fullscreen"), NULL }, { "fullscreen", 'f', 0, G_OPTION_ARG_NONE, NULL, _("Set window to be fullscreen"), NULL },
{ "video-filter", 0, 0, G_OPTION_ARG_STRING, NULL, _("Video filter to use (\"none\" to disable)"), NULL }, { "video-filter", 0, 0, G_OPTION_ARG_STRING, NULL, _("Video filter to use (\"none\" to disable)"), NULL },

View File

@@ -151,6 +151,15 @@ _queue_current_item_changed_cb (ClapperQueue *queue,
gst_clear_object (&current_item); gst_clear_object (&current_item);
} }
static void
_player_adaptive_bandwidth_changed_cb (ClapperPlayer *player,
GParamSpec *pspec G_GNUC_UNUSED, gpointer *user_data G_GNUC_UNUSED)
{
/* Do not take whole bandwidth */
clapper_player_set_adaptive_start_bitrate (player,
clapper_player_get_adaptive_bandwidth (player) * 0.8);
}
static gboolean static gboolean
_get_seek_method_mapping (GValue *value, _get_seek_method_mapping (GValue *value,
GVariant *variant, gpointer user_data G_GNUC_UNUSED) GVariant *variant, gpointer user_data G_GNUC_UNUSED)
@@ -1280,10 +1289,12 @@ clapper_app_window_constructed (GObject *object)
clapper_player_set_autoplay (player, TRUE); clapper_player_set_autoplay (player, TRUE);
/* No need to also call this here, as item is selected /* No need to also call these here, as they only change
* after application window is contructed */ * after application window is contructed */
g_signal_connect (queue, "notify::current-item", g_signal_connect (queue, "notify::current-item",
G_CALLBACK (_queue_current_item_changed_cb), self); G_CALLBACK (_queue_current_item_changed_cb), self);
g_signal_connect (player, "notify::adaptive-bandwidth",
G_CALLBACK (_player_adaptive_bandwidth_changed_cb), NULL);
g_settings_bind (self->settings, "audio-offset", g_settings_bind (self->settings, "audio-offset",
player, "audio-offset", G_SETTINGS_BIND_GET); player, "audio-offset", G_SETTINGS_BIND_GET);

View File

@@ -49,6 +49,10 @@
<default>1.0</default> <default>1.0</default>
<summary>Stores last speed value to apply on startup</summary> <summary>Stores last speed value to apply on startup</summary>
</key> </key>
<key name="adaptive-start-bitrate" type="i">
<default>1600000</default>
<summary>Stores initial adaptive streaming bitrate to apply on startup</summary>
</key>
<key name="progression-mode" type="i"> <key name="progression-mode" type="i">
<default>1</default> <default>1</default>
<summary>Stores last queue progression mode used to apply on startup</summary> <summary>Stores last queue progression mode used to apply on startup</summary>