mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-02 21:48:55 +00:00
mssdemux: measure bitrate similarly to hlsdemux
new bitrate = (old bitrate + (last fragment bitrate * 3)) / 4
This commit is contained in:
parent
90577c3ae7
commit
99a2e425de
5 changed files with 19 additions and 210 deletions
|
@ -13,13 +13,11 @@ libgstsmoothstreaming_la_LIBADD = \
|
||||||
libgstsmoothstreaming_la_LDFLAGS = ${GST_PLUGIN_LDFLAGS}
|
libgstsmoothstreaming_la_LDFLAGS = ${GST_PLUGIN_LDFLAGS}
|
||||||
libgstsmoothstreaming_la_SOURCES = gstsmoothstreaming-plugin.c \
|
libgstsmoothstreaming_la_SOURCES = gstsmoothstreaming-plugin.c \
|
||||||
gstmssdemux.c \
|
gstmssdemux.c \
|
||||||
gstmssmanifest.c \
|
gstmssmanifest.c
|
||||||
gstdownloadrate.c
|
|
||||||
libgstsmoothstreaming_la_LIBTOOLFLAGS = --tag=disable-static
|
libgstsmoothstreaming_la_LIBTOOLFLAGS = --tag=disable-static
|
||||||
|
|
||||||
noinst_HEADERS = gstmssdemux.h \
|
noinst_HEADERS = gstmssdemux.h \
|
||||||
gstmssmanifest.h \
|
gstmssmanifest.h
|
||||||
gstdownloadrate.h
|
|
||||||
|
|
||||||
Android.mk: Makefile.am $(BUILT_SOURCES)
|
Android.mk: Makefile.am $(BUILT_SOURCES)
|
||||||
androgenizer \
|
androgenizer \
|
||||||
|
|
|
@ -1,113 +0,0 @@
|
||||||
/* GStreamer
|
|
||||||
* Copyright (C) 2011 Andoni Morales Alastruey <ylatuya@gmail.com>
|
|
||||||
* Copyright (C) 2012 Smart TV Alliance
|
|
||||||
* Author: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>, Collabora Ltd.
|
|
||||||
*
|
|
||||||
* gstfragment.c:
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
||||||
* Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
#include "gstdownloadrate.h"
|
|
||||||
|
|
||||||
static void
|
|
||||||
_gst_download_rate_check_remove_rates (GstDownloadRate * rate)
|
|
||||||
{
|
|
||||||
if (rate->max_length == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
while (g_queue_get_length (&rate->queue) > rate->max_length) {
|
|
||||||
guint bitrate = GPOINTER_TO_UINT (g_queue_pop_head (&rate->queue));
|
|
||||||
|
|
||||||
rate->total -= bitrate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_download_rate_init (GstDownloadRate * rate)
|
|
||||||
{
|
|
||||||
g_queue_init (&rate->queue);
|
|
||||||
g_mutex_init (&rate->mutex);
|
|
||||||
rate->total = 0;
|
|
||||||
rate->max_length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_download_rate_deinit (GstDownloadRate * rate)
|
|
||||||
{
|
|
||||||
gst_download_rate_clear (rate);
|
|
||||||
g_mutex_clear (&rate->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_download_rate_set_max_length (GstDownloadRate * rate, gint max_length)
|
|
||||||
{
|
|
||||||
g_mutex_lock (&rate->mutex);
|
|
||||||
rate->max_length = max_length;
|
|
||||||
_gst_download_rate_check_remove_rates (rate);
|
|
||||||
g_mutex_unlock (&rate->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
gint
|
|
||||||
gst_download_rate_get_max_length (GstDownloadRate * rate)
|
|
||||||
{
|
|
||||||
guint ret;
|
|
||||||
g_mutex_lock (&rate->mutex);
|
|
||||||
ret = rate->max_length;
|
|
||||||
g_mutex_unlock (&rate->mutex);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_download_rate_clear (GstDownloadRate * rate)
|
|
||||||
{
|
|
||||||
g_mutex_lock (&rate->mutex);
|
|
||||||
g_queue_clear (&rate->queue);
|
|
||||||
rate->total = 0;
|
|
||||||
g_mutex_unlock (&rate->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_download_rate_add_rate (GstDownloadRate * rate, guint bytes, guint64 time)
|
|
||||||
{
|
|
||||||
guint64 bitrate;
|
|
||||||
g_mutex_lock (&rate->mutex);
|
|
||||||
|
|
||||||
/* convert from bytes / nanoseconds to bits per second */
|
|
||||||
bitrate = G_GUINT64_CONSTANT (8000000000) * bytes / time;
|
|
||||||
|
|
||||||
g_queue_push_tail (&rate->queue, GUINT_TO_POINTER ((guint) bitrate));
|
|
||||||
rate->total += bitrate;
|
|
||||||
|
|
||||||
_gst_download_rate_check_remove_rates (rate);
|
|
||||||
g_mutex_unlock (&rate->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
guint
|
|
||||||
gst_download_rate_get_current_rate (GstDownloadRate * rate)
|
|
||||||
{
|
|
||||||
guint ret;
|
|
||||||
g_mutex_lock (&rate->mutex);
|
|
||||||
if (g_queue_get_length (&rate->queue))
|
|
||||||
ret = rate->total / g_queue_get_length (&rate->queue);
|
|
||||||
else
|
|
||||||
ret = G_MAXUINT;
|
|
||||||
g_mutex_unlock (&rate->mutex);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
/* GStreamer
|
|
||||||
* Copyright (C) 2012 Smart TV Alliance
|
|
||||||
* Author: Thiago Sousa Santos <thiago.sousa.santos@collabora.com>, Collabora Ltd.
|
|
||||||
*
|
|
||||||
* gstdownloadrate.h:
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
||||||
* Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __GST_DOWNLOAD_RATE_H__
|
|
||||||
#define __GST_DOWNLOAD_RATE_H__
|
|
||||||
|
|
||||||
#include <glib-object.h>
|
|
||||||
#include <gst/gst.h>
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
typedef struct _GstDownloadRate GstDownloadRate;
|
|
||||||
|
|
||||||
struct _GstDownloadRate
|
|
||||||
{
|
|
||||||
GQueue queue;
|
|
||||||
GMutex mutex;
|
|
||||||
|
|
||||||
gint max_length;
|
|
||||||
|
|
||||||
guint64 total;
|
|
||||||
};
|
|
||||||
|
|
||||||
void gst_download_rate_init (GstDownloadRate * rate);
|
|
||||||
void gst_download_rate_deinit (GstDownloadRate * rate);
|
|
||||||
|
|
||||||
void gst_download_rate_set_max_length (GstDownloadRate * rate, gint max_length);
|
|
||||||
gint gst_download_rate_get_max_length (GstDownloadRate * rate);
|
|
||||||
|
|
||||||
void gst_download_rate_clear (GstDownloadRate * rate);
|
|
||||||
void gst_download_rate_add_rate (GstDownloadRate * rate, guint bytes, guint64 time);
|
|
||||||
|
|
||||||
guint gst_download_rate_get_current_rate (GstDownloadRate * rate);
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
||||||
#endif /* __GST_DOWNLOAD_RATE_H__ */
|
|
|
@ -81,7 +81,6 @@ GST_DEBUG_CATEGORY (mssdemux_debug);
|
||||||
#define DEFAULT_MAX_QUEUE_SIZE_BUFFERS 0
|
#define DEFAULT_MAX_QUEUE_SIZE_BUFFERS 0
|
||||||
#define DEFAULT_BITRATE_LIMIT 0.8
|
#define DEFAULT_BITRATE_LIMIT 0.8
|
||||||
|
|
||||||
#define DOWNLOAD_RATE_MAX_HISTORY_LENGTH 5
|
|
||||||
#define MAX_DOWNLOAD_ERROR_COUNT 3
|
#define MAX_DOWNLOAD_ERROR_COUNT 3
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -224,9 +223,6 @@ gst_mss_demux_stream_new (GstMssDemux * mssdemux,
|
||||||
stream->pad = srcpad;
|
stream->pad = srcpad;
|
||||||
stream->manifest_stream = manifeststream;
|
stream->manifest_stream = manifeststream;
|
||||||
stream->parent = mssdemux;
|
stream->parent = mssdemux;
|
||||||
gst_download_rate_init (&stream->download_rate);
|
|
||||||
gst_download_rate_set_max_length (&stream->download_rate,
|
|
||||||
DOWNLOAD_RATE_MAX_HISTORY_LENGTH);
|
|
||||||
|
|
||||||
gst_segment_init (&stream->segment, GST_FORMAT_TIME);
|
gst_segment_init (&stream->segment, GST_FORMAT_TIME);
|
||||||
g_cond_init (&stream->fragment_download_cond);
|
g_cond_init (&stream->fragment_download_cond);
|
||||||
|
@ -253,7 +249,6 @@ gst_mss_demux_stream_free (GstMssDemuxStream * stream)
|
||||||
stream->download_task = NULL;
|
stream->download_task = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_download_rate_deinit (&stream->download_rate);
|
|
||||||
if (stream->pending_segment) {
|
if (stream->pending_segment) {
|
||||||
gst_event_unref (stream->pending_segment);
|
gst_event_unref (stream->pending_segment);
|
||||||
stream->pending_segment = NULL;
|
stream->pending_segment = NULL;
|
||||||
|
@ -966,19 +961,28 @@ gst_mss_demux_reconfigure_stream (GstMssDemuxStream * stream)
|
||||||
{
|
{
|
||||||
GstEvent *capsevent = NULL;
|
GstEvent *capsevent = NULL;
|
||||||
GstMssDemux *mssdemux = stream->parent;
|
GstMssDemux *mssdemux = stream->parent;
|
||||||
guint64 new_bitrate;
|
guint64 bitrate = 0;
|
||||||
|
|
||||||
|
if (stream->download_total_time)
|
||||||
|
bitrate =
|
||||||
|
(stream->download_total_bytes * 8) /
|
||||||
|
((double) stream->download_total_time / G_GUINT64_CONSTANT (1000000));
|
||||||
|
|
||||||
|
if (stream->current_download_rate != -1)
|
||||||
|
bitrate = (stream->current_download_rate + bitrate * 3) / 4;
|
||||||
|
if (bitrate > G_MAXINT)
|
||||||
|
bitrate = G_MAXINT;
|
||||||
|
stream->current_download_rate = bitrate;
|
||||||
|
bitrate *= mssdemux->bitrate_limit;
|
||||||
|
|
||||||
new_bitrate =
|
|
||||||
mssdemux->bitrate_limit *
|
|
||||||
gst_download_rate_get_current_rate (&stream->download_rate);
|
|
||||||
if (mssdemux->connection_speed) {
|
if (mssdemux->connection_speed) {
|
||||||
new_bitrate = MIN (mssdemux->connection_speed, new_bitrate);
|
bitrate = MIN (mssdemux->connection_speed, bitrate);
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (stream->pad,
|
GST_DEBUG_OBJECT (stream->pad,
|
||||||
"Current stream download bitrate %" G_GUINT64_FORMAT, new_bitrate);
|
"Current stream download bitrate %" G_GUINT64_FORMAT, bitrate);
|
||||||
|
|
||||||
if (gst_mss_stream_select_bitrate (stream->manifest_stream, new_bitrate)) {
|
if (gst_mss_stream_select_bitrate (stream->manifest_stream, bitrate)) {
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
caps = gst_mss_stream_get_caps (stream->manifest_stream);
|
caps = gst_mss_stream_get_caps (stream->manifest_stream);
|
||||||
|
|
||||||
|
@ -1281,9 +1285,6 @@ gst_mss_demux_stream_download_fragment (GstMssDemuxStream * stream)
|
||||||
gchar *path = NULL;
|
gchar *path = NULL;
|
||||||
gchar *url = NULL;
|
gchar *url = NULL;
|
||||||
GstFlowReturn ret = GST_FLOW_OK;
|
GstFlowReturn ret = GST_FLOW_OK;
|
||||||
#if 0
|
|
||||||
guint64 before_download, after_download;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* special case for not-linked streams */
|
/* special case for not-linked streams */
|
||||||
if (stream->last_ret == GST_FLOW_NOT_LINKED) {
|
if (stream->last_ret == GST_FLOW_NOT_LINKED) {
|
||||||
|
@ -1291,9 +1292,6 @@ gst_mss_demux_stream_download_fragment (GstMssDemuxStream * stream)
|
||||||
stream);
|
stream);
|
||||||
return GST_FLOW_NOT_LINKED;
|
return GST_FLOW_NOT_LINKED;
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
before_download = g_get_real_time ();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
g_mutex_lock (&stream->fragment_download_lock);
|
g_mutex_lock (&stream->fragment_download_lock);
|
||||||
GST_DEBUG_OBJECT (stream->pad, "Getting url for stream");
|
GST_DEBUG_OBJECT (stream->pad, "Getting url for stream");
|
||||||
|
@ -1347,22 +1345,6 @@ gst_mss_demux_stream_download_fragment (GstMssDemuxStream * stream)
|
||||||
}
|
}
|
||||||
return stream->last_ret;
|
return stream->last_ret;
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
after_download = g_get_real_time ();
|
|
||||||
{
|
|
||||||
#ifndef GST_DISABLE_GST_DEBUG
|
|
||||||
guint64 bitrate = (8 * gst_buffer_get_size (buffer) * 1000000LLU) /
|
|
||||||
(after_download - before_download);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (mssdemux,
|
|
||||||
"Measured download bitrate: %s %" G_GUINT64_FORMAT " bps",
|
|
||||||
GST_PAD_NAME (stream->pad), bitrate);
|
|
||||||
gst_download_rate_add_rate (&stream->download_rate,
|
|
||||||
gst_buffer_get_size (buffer),
|
|
||||||
1000 * (after_download - before_download));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return stream->last_ret;
|
return stream->last_ret;
|
||||||
|
|
||||||
|
@ -1489,7 +1471,7 @@ gst_mss_demux_download_loop (GstMssDemuxStream * stream)
|
||||||
default:
|
default:
|
||||||
if (ret <= GST_FLOW_ERROR) {
|
if (ret <= GST_FLOW_ERROR) {
|
||||||
GST_WARNING_OBJECT (mssdemux, "Error while downloading fragment");
|
GST_WARNING_OBJECT (mssdemux, "Error while downloading fragment");
|
||||||
if (++stream->download_error_count >= DOWNLOAD_RATE_MAX_HISTORY_LENGTH) {
|
if (++stream->download_error_count >= MAX_DOWNLOAD_ERROR_COUNT) {
|
||||||
GST_ELEMENT_ERROR (mssdemux, RESOURCE, NOT_FOUND,
|
GST_ELEMENT_ERROR (mssdemux, RESOURCE, NOT_FOUND,
|
||||||
(_("Couldn't download fragments")),
|
(_("Couldn't download fragments")),
|
||||||
("fragment downloading has failed too much consecutive times"));
|
("fragment downloading has failed too much consecutive times"));
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
#include <gst/base/gstdataqueue.h>
|
#include <gst/base/gstdataqueue.h>
|
||||||
#include "gstmssmanifest.h"
|
#include "gstmssmanifest.h"
|
||||||
#include <gst/uridownloader/gsturidownloader.h>
|
#include <gst/uridownloader/gsturidownloader.h>
|
||||||
#include "gstdownloadrate.h"
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
@ -80,8 +79,6 @@ struct _GstMssDemuxStream {
|
||||||
gboolean cancelled;
|
gboolean cancelled;
|
||||||
gboolean restart_download;
|
gboolean restart_download;
|
||||||
|
|
||||||
GstDownloadRate download_rate;
|
|
||||||
|
|
||||||
guint download_error_count;
|
guint download_error_count;
|
||||||
|
|
||||||
/* download tooling */
|
/* download tooling */
|
||||||
|
|
Loading…
Reference in a new issue