adaptivedemux: add connection-speed property

Allows to set a bitrate directly instead of measuring it internally
based on the received chunks. The connection-speed was removed from
mssdemux and hlsdemux as it is now in the base class
This commit is contained in:
Thiago Santos 2015-02-17 10:03:44 -03:00
parent 34c9c86ab7
commit e9ab79dc36
6 changed files with 32 additions and 54 deletions

View file

@ -63,14 +63,12 @@ enum
PROP_FRAGMENTS_CACHE,
PROP_BITRATE_LIMIT,
PROP_CONNECTION_SPEED,
PROP_LAST
};
#define DEFAULT_FRAGMENTS_CACHE 1
#define DEFAULT_FAILED_COUNT 3
#define DEFAULT_BITRATE_LIMIT 0.8
#define DEFAULT_CONNECTION_SPEED 0
/* GObject */
static void gst_hls_demux_set_property (GObject * object, guint prop_id,
@ -177,12 +175,6 @@ gst_hls_demux_class_init (GstHLSDemuxClass * klass)
0, 1, DEFAULT_BITRATE_LIMIT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_CONNECTION_SPEED,
g_param_spec_uint ("connection-speed", "Connection Speed",
"Network connection speed in kbps (0 = unknown)",
0, G_MAXUINT / 1000, DEFAULT_CONNECTION_SPEED,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
element_class->change_state = GST_DEBUG_FUNCPTR (gst_hls_demux_change_state);
gst_element_class_add_pad_template (element_class,
@ -232,7 +224,6 @@ gst_hls_demux_init (GstHLSDemux * demux)
/* Properties */
demux->bitrate_limit = DEFAULT_BITRATE_LIMIT;
demux->connection_speed = DEFAULT_CONNECTION_SPEED;
}
static void
@ -247,9 +238,6 @@ gst_hls_demux_set_property (GObject * object, guint prop_id,
case PROP_BITRATE_LIMIT:
demux->bitrate_limit = g_value_get_float (value);
break;
case PROP_CONNECTION_SPEED:
demux->connection_speed = g_value_get_uint (value) * 1000;
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -269,9 +257,6 @@ gst_hls_demux_get_property (GObject * object, guint prop_id, GValue * value,
case PROP_BITRATE_LIMIT:
g_value_set_float (value, demux->bitrate_limit);
break;
case PROP_CONNECTION_SPEED:
g_value_set_uint (value, demux->connection_speed / 1000);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -488,13 +473,13 @@ gst_hls_demux_process_manifest (GstAdaptiveDemux * demux, GstBuffer * buf)
GError *err = NULL;
/* TODO seems like something that could be simplified */
if (hlsdemux->connection_speed == 0) {
if (demux->connection_speed == 0) {
GST_M3U8_CLIENT_LOCK (hlsdemux->client);
child = hlsdemux->client->main->current_variant->data;
GST_M3U8_CLIENT_UNLOCK (hlsdemux->client);
} else {
GList *tmp = gst_m3u8_client_get_playlist_for_bitrate (hlsdemux->client,
hlsdemux->connection_speed);
demux->connection_speed);
child = GST_M3U8 (tmp->data);
}
@ -1074,11 +1059,6 @@ gst_hls_demux_change_playlist (GstHLSDemux * demux, guint max_bitrate,
stream = adaptive_demux->streams->data;
/* If user specifies a connection speed never use a playlist with a bandwidth
* superior than it */
if (demux->connection_speed != 0 && max_bitrate > demux->connection_speed)
max_bitrate = demux->connection_speed;
previous_variant = demux->client->main->current_variant;
current_variant = gst_m3u8_client_get_playlist_for_bitrate (demux->client,
max_bitrate);

View file

@ -76,7 +76,6 @@ struct _GstHLSDemux
/* Properties */
gfloat bitrate_limit; /* limit of the available bitrate to use */
guint connection_speed; /* Network connection speed in kbps (0 = unknown) */
/* Streaming task */
gint64 next_download;

View file

@ -77,7 +77,6 @@
GST_DEBUG_CATEGORY (mssdemux_debug);
#define DEFAULT_CONNECTION_SPEED 0
#define DEFAULT_MAX_QUEUE_SIZE_BUFFERS 0
#define DEFAULT_BITRATE_LIMIT 0.8
@ -85,7 +84,6 @@ enum
{
PROP_0,
PROP_CONNECTION_SPEED,
PROP_MAX_QUEUE_SIZE_BUFFERS,
PROP_BITRATE_LIMIT,
PROP_LAST
@ -166,12 +164,6 @@ gst_mss_demux_class_init (GstMssDemuxClass * klass)
gobject_class->set_property = gst_mss_demux_set_property;
gobject_class->get_property = gst_mss_demux_get_property;
g_object_class_install_property (gobject_class, PROP_CONNECTION_SPEED,
g_param_spec_uint ("connection-speed", "Connection Speed",
"Network connection speed in kbps (0 = unknown)",
0, G_MAXUINT / 1000, DEFAULT_CONNECTION_SPEED,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
#ifndef GST_REMOVE_DEPRECATED
g_object_class_install_property (gobject_class, PROP_MAX_QUEUE_SIZE_BUFFERS,
g_param_spec_uint ("max-queue-size-buffers", "Max queue size in buffers",
@ -250,14 +242,6 @@ gst_mss_demux_set_property (GObject * object, guint prop_id,
GstMssDemux *mssdemux = GST_MSS_DEMUX (object);
switch (prop_id) {
case PROP_CONNECTION_SPEED:
GST_OBJECT_LOCK (mssdemux);
mssdemux->connection_speed = g_value_get_uint (value) * 1000;
mssdemux->update_bitrates = TRUE;
GST_DEBUG_OBJECT (mssdemux, "Connection speed set to %" G_GUINT64_FORMAT,
mssdemux->connection_speed);
GST_OBJECT_UNLOCK (mssdemux);
break;
case PROP_MAX_QUEUE_SIZE_BUFFERS:
mssdemux->data_queue_max_size = g_value_get_uint (value);
break;
@ -277,9 +261,6 @@ gst_mss_demux_get_property (GObject * object, guint prop_id, GValue * value,
GstMssDemux *mssdemux = GST_MSS_DEMUX (object);
switch (prop_id) {
case PROP_CONNECTION_SPEED:
g_value_set_uint (value, mssdemux->connection_speed / 1000);
break;
case PROP_MAX_QUEUE_SIZE_BUFFERS:
g_value_set_uint (value, mssdemux->data_queue_max_size);
break;
@ -416,11 +397,9 @@ gst_mss_demux_setup_streams (GstAdaptiveDemux * demux)
return FALSE;
}
GST_INFO_OBJECT (mssdemux, "Changing max bitrate to %" G_GUINT64_FORMAT,
mssdemux->connection_speed);
gst_mss_manifest_change_bitrate (mssdemux->manifest,
mssdemux->connection_speed);
mssdemux->update_bitrates = FALSE;
GST_INFO_OBJECT (mssdemux, "Changing max bitrate to %u",
demux->connection_speed);
gst_mss_manifest_change_bitrate (mssdemux->manifest, demux->connection_speed);
for (iter = streams; iter; iter = g_slist_next (iter)) {
GstPad *srcpad = NULL;
@ -508,9 +487,6 @@ gst_mss_demux_stream_select_bitrate (GstAdaptiveDemuxStream * stream,
gboolean ret = FALSE;
bitrate *= mssdemux->bitrate_limit;
if (mssdemux->connection_speed) {
bitrate = MIN (mssdemux->connection_speed, bitrate);
}
GST_DEBUG_OBJECT (stream->pad,
"Using stream download bitrate %" G_GUINT64_FORMAT, bitrate);

View file

@ -70,10 +70,7 @@ struct _GstMssDemux {
guint n_videos;
guint n_audios;
gboolean update_bitrates;
/* properties */
guint64 connection_speed; /* in bps */
guint data_queue_max_size;
gfloat bitrate_limit;
};

View file

@ -87,11 +87,13 @@ GST_DEBUG_CATEGORY (adaptivedemux_debug);
#define MAX_DOWNLOAD_ERROR_COUNT 3
#define DEFAULT_FAILED_COUNT 3
#define DEFAULT_LOOKBACK_FRAGMENTS 3
#define DEFAULT_CONNECTION_SPEED 0
enum
{
PROP_0,
PROP_LOOKBACK_FRAGMENTS,
PROP_CONNECTION_SPEED,
PROP_LAST
};
@ -227,6 +229,11 @@ gst_adaptive_demux_set_property (GObject * object, guint prop_id,
case PROP_LOOKBACK_FRAGMENTS:
demux->num_lookback_fragments = g_value_get_uint (value);
break;
case PROP_CONNECTION_SPEED:
demux->connection_speed = g_value_get_uint (value) * 1000;
GST_DEBUG_OBJECT (demux, "Connection speed set to %u",
demux->connection_speed);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -243,6 +250,9 @@ gst_adaptive_demux_get_property (GObject * object, guint prop_id,
case PROP_LOOKBACK_FRAGMENTS:
g_value_set_uint (value, demux->num_lookback_fragments);
break;
case PROP_CONNECTION_SPEED:
g_value_set_uint (value, demux->connection_speed / 1000);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -277,6 +287,12 @@ gst_adaptive_demux_class_init (GstAdaptiveDemuxClass * klass)
1, G_MAXUINT, DEFAULT_LOOKBACK_FRAGMENTS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class, PROP_CONNECTION_SPEED,
g_param_spec_uint ("connection-speed", "Connection Speed",
"Network connection speed in kbps (0 = calculate from downloaded"
" fragments)", 0, G_MAXUINT / 1000, DEFAULT_CONNECTION_SPEED,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gstelement_class->change_state = gst_adaptive_demux_change_state;
gstbin_class->handle_message = gst_adaptive_demux_handle_message;
@ -323,7 +339,9 @@ gst_adaptive_demux_init (GstAdaptiveDemux * demux,
gst_pad_set_chain_function (demux->sinkpad,
GST_DEBUG_FUNCPTR (gst_adaptive_demux_sink_chain));
/* Properties */
demux->num_lookback_fragments = DEFAULT_LOOKBACK_FRAGMENTS;
demux->connection_speed = DEFAULT_CONNECTION_SPEED;
gst_element_add_pad (GST_ELEMENT (demux), demux->sinkpad);
}
@ -702,7 +720,8 @@ gst_adaptive_demux_expose_streams (GstAdaptiveDemux * demux,
}
if (first_segment)
demux->segment.start = demux->segment.position = demux->segment.time = min_pts;
demux->segment.start = demux->segment.position = demux->segment.time =
min_pts;
for (iter = demux->streams; iter; iter = g_list_next (iter)) {
GstAdaptiveDemuxStream *stream = iter->data;
@ -1260,6 +1279,12 @@ gst_adaptive_demux_stream_update_current_bitrate (GstAdaptiveDemux * demux,
/* Conservative approach, make sure we don't upgrade too fast */
stream->current_download_rate = MIN (average_bitrate, fragment_bitrate);
if (demux->connection_speed) {
GST_LOG_OBJECT (demux, "Connection-speed is set to %u kbps, using it",
demux->connection_speed / 1000);
return demux->connection_speed;
}
return stream->current_download_rate;
}

View file

@ -192,6 +192,7 @@ struct _GstAdaptiveDemux
gchar *manifest_base_uri;
guint num_lookback_fragments;
guint connection_speed;
gboolean have_group_id;
guint group_id;