Skip to content

Commit 2243062

Browse files
committed
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.
1 parent e4045b9 commit 2243062

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/bin/clapper-app/clapper-app-application.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ clapper_app_apply_options_to_window (ClapperAppWindow *dest_window, GVariantDict
144144
clapper_player_set_mute (dest_player, option_bool);
145145
if (clapper_app_options_get ("speed", "d", options, src_player_obj, settings, &option_dbl))
146146
clapper_player_set_speed (dest_player, PERCENTAGE_ROUND (CLAMP (option_dbl, 0.05, 2.0)));
147+
if (clapper_app_options_get ("adaptive-start-bitrate", "i", options, src_player_obj, settings, &option_int))
148+
clapper_player_set_adaptive_start_bitrate (dest_player, option_int);
147149
if (clapper_app_options_get ("progression-mode", "i", options, src_queue_obj, settings, &option_int))
148150
clapper_queue_set_progression_mode (clapper_player_get_queue (dest_player), CLAMP (option_int, 0, 4));
149151
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_
196198
g_settings_set_double (self->settings, "volume", clapper_player_get_volume (player));
197199
g_settings_set_boolean (self->settings, "mute", clapper_player_get_mute (player));
198200
g_settings_set_double (self->settings, "speed", clapper_player_get_speed (player));
201+
g_settings_set_int (self->settings, "adaptive-start-bitrate",
202+
CLAMP (clapper_player_get_adaptive_bandwidth (player) * 0.8, 0, G_MAXINT));
199203
g_settings_set_boolean (self->settings, "subtitles-enabled", clapper_player_get_subtitles_enabled (player));
200204
g_settings_set_int (self->settings, "progression-mode", clapper_queue_get_progression_mode (queue));
201205

@@ -676,6 +680,7 @@ clapper_app_application_constructed (GObject *object)
676680
{ "enqueue", 0, 0, G_OPTION_ARG_NONE, NULL, _("Add media to queue in primary application instance"), NULL },
677681
{ "volume", 0, 0, G_OPTION_ARG_DOUBLE, NULL, _("Audio volume to set (0 - 2.0 range)"), NULL },
678682
{ "speed", 0, 0, G_OPTION_ARG_DOUBLE, NULL, _("Playback speed to set (0.05 - 2.0 range)"), NULL },
683+
{ "adaptive-start-bitrate", 0, 0, G_OPTION_ARG_INT, NULL, _("Initial bitrate for adaptive streaming"), NULL },
679684
{ "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 },
680685
{ "fullscreen", 'f', 0, G_OPTION_ARG_NONE, NULL, _("Set window to be fullscreen"), NULL },
681686
{ "video-filter", 0, 0, G_OPTION_ARG_STRING, NULL, _("Video filter to use (\"none\" to disable)"), NULL },

src/bin/clapper-app/clapper-app-window.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ _queue_current_item_changed_cb (ClapperQueue *queue,
151151
gst_clear_object (&current_item);
152152
}
153153

154+
static void
155+
_player_adaptive_bandwidth_changed_cb (ClapperPlayer *player,
156+
GParamSpec *pspec G_GNUC_UNUSED, gpointer *user_data G_GNUC_UNUSED)
157+
{
158+
/* Do not take whole bandwidth */
159+
clapper_player_set_adaptive_start_bitrate (player,
160+
clapper_player_get_adaptive_bandwidth (player) * 0.8);
161+
}
162+
154163
static gboolean
155164
_get_seek_method_mapping (GValue *value,
156165
GVariant *variant, gpointer user_data G_GNUC_UNUSED)
@@ -1280,10 +1289,12 @@ clapper_app_window_constructed (GObject *object)
12801289

12811290
clapper_player_set_autoplay (player, TRUE);
12821291

1283-
/* No need to also call this here, as item is selected
1292+
/* No need to also call these here, as they only change
12841293
* after application window is contructed */
12851294
g_signal_connect (queue, "notify::current-item",
12861295
G_CALLBACK (_queue_current_item_changed_cb), self);
1296+
g_signal_connect (player, "notify::adaptive-bandwidth",
1297+
G_CALLBACK (_player_adaptive_bandwidth_changed_cb), NULL);
12871298

12881299
g_settings_bind (self->settings, "audio-offset",
12891300
player, "audio-offset", G_SETTINGS_BIND_GET);

src/bin/clapper-app/data/glib-2.0/schemas/com.github.rafostar.Clapper.gschema.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
<default>1.0</default>
5050
<summary>Stores last speed value to apply on startup</summary>
5151
</key>
52+
<key name="adaptive-start-bitrate" type="i">
53+
<default>1600000</default>
54+
<summary>Stores initial adaptive streaming bitrate to apply on startup</summary>
55+
</key>
5256
<key name="progression-mode" type="i">
5357
<default>1</default>
5458
<summary>Stores last queue progression mode used to apply on startup</summary>

0 commit comments

Comments
 (0)