adaptivedemux: add bitrate-limit property

Move the property from subclasses to adaptivedemux, it allows
selecing the percentage of the measured bitrate to be used when
selecting stream bitrates
This commit is contained in:
Thiago Santos 2015-02-17 10:40:06 -03:00
parent 00bdac51a3
commit f7a1649c77
6 changed files with 26 additions and 47 deletions

View file

@ -62,13 +62,11 @@ enum
PROP_0,
PROP_FRAGMENTS_CACHE,
PROP_BITRATE_LIMIT,
PROP_LAST
};
#define DEFAULT_FRAGMENTS_CACHE 1
#define DEFAULT_FAILED_COUNT 3
#define DEFAULT_BITRATE_LIMIT 0.8
/* GObject */
static void gst_hls_demux_set_property (GObject * object, guint prop_id,
@ -168,13 +166,6 @@ gst_hls_demux_class_init (GstHLSDemuxClass * klass)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
#endif
g_object_class_install_property (gobject_class, PROP_BITRATE_LIMIT,
g_param_spec_float ("bitrate-limit",
"Bitrate limit in %",
"Limit of the available bitrate to use when switching to alternates.",
0, 1, DEFAULT_BITRATE_LIMIT,
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,
@ -222,22 +213,15 @@ gst_hls_demux_init (GstHLSDemux * demux)
demux->do_typefind = TRUE;
/* Properties */
demux->bitrate_limit = DEFAULT_BITRATE_LIMIT;
}
static void
gst_hls_demux_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstHLSDemux *demux = GST_HLS_DEMUX (object);
switch (prop_id) {
case PROP_FRAGMENTS_CACHE:
break;
case PROP_BITRATE_LIMIT:
demux->bitrate_limit = g_value_get_float (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -248,15 +232,10 @@ static void
gst_hls_demux_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
GstHLSDemux *demux = GST_HLS_DEMUX (object);
switch (prop_id) {
case PROP_FRAGMENTS_CACHE:
g_value_set_uint (value, 1);
break;
case PROP_BITRATE_LIMIT:
g_value_set_float (value, demux->bitrate_limit);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -385,8 +364,7 @@ gst_hls_demux_seek (GstAdaptiveDemux * demux, GstEvent * seek)
hlsdemux->new_playlist = TRUE;
hlsdemux->do_typefind = TRUE;
/* TODO why not continue using the same? that was being used up to now? */
gst_hls_demux_change_playlist (hlsdemux, bitrate * hlsdemux->bitrate_limit,
NULL);
gst_hls_demux_change_playlist (hlsdemux, bitrate, NULL);
}
GST_M3U8_CLIENT_LOCK (hlsdemux->client);
@ -785,8 +763,7 @@ gst_hls_demux_select_bitrate (GstAdaptiveDemuxStream * stream, guint64 bitrate)
if (demux->segment.rate != 1.0)
return FALSE;
gst_hls_demux_change_playlist (hlsdemux, bitrate * hlsdemux->bitrate_limit,
&changed);
gst_hls_demux_change_playlist (hlsdemux, bitrate, &changed);
if (changed)
gst_hls_demux_setup_streams (GST_ADAPTIVE_DEMUX_CAST (hlsdemux));
return changed;

View file

@ -74,8 +74,6 @@ struct _GstHLSDemux
gboolean do_typefind; /* Whether we need to typefind the next buffer */
gboolean new_playlist; /* Whether a new playlist is about to start and pads should be switched */
/* Properties */
gfloat bitrate_limit; /* limit of the available bitrate to use */
/* Streaming task */
gint64 next_download;

View file

@ -85,7 +85,6 @@ enum
PROP_0,
PROP_MAX_QUEUE_SIZE_BUFFERS,
PROP_BITRATE_LIMIT,
PROP_LAST
};
@ -173,13 +172,6 @@ gst_mss_demux_class_init (GstMssDemuxClass * klass)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
#endif
g_object_class_install_property (gobject_class, PROP_BITRATE_LIMIT,
g_param_spec_float ("bitrate-limit",
"Bitrate limit in %",
"Limit of the available bitrate to use when switching to alternates.",
0, 1, DEFAULT_BITRATE_LIMIT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gstadaptivedemux_class->process_manifest = gst_mss_demux_process_manifest;
gstadaptivedemux_class->is_live = gst_mss_demux_is_live;
gstadaptivedemux_class->get_duration = gst_mss_demux_get_duration;
@ -205,7 +197,6 @@ static void
gst_mss_demux_init (GstMssDemux * mssdemux)
{
mssdemux->data_queue_max_size = DEFAULT_MAX_QUEUE_SIZE_BUFFERS;
mssdemux->bitrate_limit = DEFAULT_BITRATE_LIMIT;
gst_adaptive_demux_set_stream_struct_size (GST_ADAPTIVE_DEMUX_CAST (mssdemux),
sizeof (GstMssDemuxStream));
@ -245,9 +236,6 @@ gst_mss_demux_set_property (GObject * object, guint prop_id,
case PROP_MAX_QUEUE_SIZE_BUFFERS:
mssdemux->data_queue_max_size = g_value_get_uint (value);
break;
case PROP_BITRATE_LIMIT:
mssdemux->bitrate_limit = g_value_get_float (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -264,9 +252,6 @@ gst_mss_demux_get_property (GObject * object, guint prop_id, GValue * value,
case PROP_MAX_QUEUE_SIZE_BUFFERS:
g_value_set_uint (value, mssdemux->data_queue_max_size);
break;
case PROP_BITRATE_LIMIT:
g_value_set_float (value, mssdemux->bitrate_limit);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -482,12 +467,9 @@ static gboolean
gst_mss_demux_stream_select_bitrate (GstAdaptiveDemuxStream * stream,
guint64 bitrate)
{
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (stream->demux);
GstMssDemuxStream *mssstream = (GstMssDemuxStream *) stream;
gboolean ret = FALSE;
bitrate *= mssdemux->bitrate_limit;
GST_DEBUG_OBJECT (stream->pad,
"Using stream download bitrate %" G_GUINT64_FORMAT, bitrate);

View file

@ -72,7 +72,6 @@ struct _GstMssDemux {
/* properties */
guint data_queue_max_size;
gfloat bitrate_limit;
};
struct _GstMssDemuxClass {

View file

@ -88,12 +88,14 @@ GST_DEBUG_CATEGORY (adaptivedemux_debug);
#define DEFAULT_FAILED_COUNT 3
#define DEFAULT_LOOKBACK_FRAGMENTS 3
#define DEFAULT_CONNECTION_SPEED 0
#define DEFAULT_BITRATE_LIMIT 0.8
enum
{
PROP_0,
PROP_LOOKBACK_FRAGMENTS,
PROP_CONNECTION_SPEED,
PROP_BITRATE_LIMIT,
PROP_LAST
};
@ -234,6 +236,9 @@ gst_adaptive_demux_set_property (GObject * object, guint prop_id,
GST_DEBUG_OBJECT (demux, "Connection speed set to %u",
demux->connection_speed);
break;
case PROP_BITRATE_LIMIT:
demux->bitrate_limit = g_value_get_float (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -253,6 +258,9 @@ gst_adaptive_demux_get_property (GObject * object, guint prop_id,
case PROP_CONNECTION_SPEED:
g_value_set_uint (value, demux->connection_speed / 1000);
break;
case PROP_BITRATE_LIMIT:
g_value_set_float (value, demux->bitrate_limit);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -293,6 +301,14 @@ gst_adaptive_demux_class_init (GstAdaptiveDemuxClass * klass)
" fragments)", 0, G_MAXUINT / 1000, DEFAULT_CONNECTION_SPEED,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/* FIXME 2.0: rename this property to bandwidth-usage or any better name */
g_object_class_install_property (gobject_class, PROP_BITRATE_LIMIT,
g_param_spec_float ("bitrate-limit",
"Bitrate limit in %",
"Limit of the available bitrate to use when switching to alternates.",
0, 1, DEFAULT_BITRATE_LIMIT,
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;
@ -341,6 +357,7 @@ gst_adaptive_demux_init (GstAdaptiveDemux * demux,
/* Properties */
demux->num_lookback_fragments = DEFAULT_LOOKBACK_FRAGMENTS;
demux->bitrate_limit = DEFAULT_BITRATE_LIMIT;
demux->connection_speed = DEFAULT_CONNECTION_SPEED;
gst_element_add_pad (GST_ELEMENT (demux), demux->sinkpad);
@ -1285,6 +1302,10 @@ gst_adaptive_demux_stream_update_current_bitrate (GstAdaptiveDemux * demux,
return demux->connection_speed;
}
stream->current_download_rate *= demux->bitrate_limit;
GST_DEBUG_OBJECT (demux, "Bitrate after bitrate limit (%0.2f): %"
G_GUINT64_FORMAT, demux->bitrate_limit, stream->current_download_rate);
return stream->current_download_rate;
}

View file

@ -142,7 +142,7 @@ struct _GstAdaptiveDemuxStream
gint64 download_chunk_start_time;
gint64 download_total_time;
gint64 download_total_bytes;
gint current_download_rate;
guint64 current_download_rate;
/* Per fragment download information */
guint64 fragment_total_time;
@ -191,7 +191,9 @@ struct _GstAdaptiveDemux
gchar *manifest_uri;
gchar *manifest_base_uri;
/* Properties */
guint num_lookback_fragments;
gfloat bitrate_limit; /* limit of the available bitrate to use */
guint connection_speed;
gboolean have_group_id;