Skip to content

Commit

Permalink
TWCCMan evaluates recovery pct for FEC
Browse files Browse the repository at this point in the history
Major rework of twcc manager internals
caused by need to evaluate recovery
percentage in case of FEC.

Sent Packet structs are stored
GstQueueArray to keep their pointers
persistent. TWCC feedback parser creates
a list of packets updated by this
feedback, which then is passed into
statistic gathering context.

Then the remaining work is done in
get_windowed_stats call.
  • Loading branch information
MishaBaranov committed Jul 8, 2024
1 parent e271b0c commit 0b04a8b
Show file tree
Hide file tree
Showing 10 changed files with 1,503 additions and 411 deletions.
136 changes: 136 additions & 0 deletions subprojects/gst-plugins-base/gst-libs/gst/rtp/gstrtprepairmeta.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/* GStreamer
* Copyright (C) <2024> Mikhail Baranov <[email protected]>
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "gstrtprepairmeta.h"
#include <string.h>

static gboolean gst_rtp_repair_meta_init(GstRTPRepairMeta * meta,
G_GNUC_UNUSED gpointer params, G_GNUC_UNUSED GstBuffer * buffer);
static void gst_rtp_repair_meta_free(GstRTPRepairMeta *meta,
G_GNUC_UNUSED GstBuffer *buffer);


GType gst_rtp_repair_meta_api_get_type(void)
{
static GType type = 0;
static const gchar *tags[] = {NULL};

if (g_once_init_enter(&type)) {
GType _type = gst_meta_api_type_register("GstRTPRepairMetaAPI", tags);
g_once_init_leave(&type, _type);
}

return type;
}

const GstMetaInfo *gst_rtp_repair_meta_get_info(void)
{
static const GstMetaInfo *meta_info = NULL;

if (g_once_init_enter(&meta_info)) {
const GstMetaInfo *mi = gst_meta_register( GST_RTP_REPAIR_META_API_TYPE,
"GstRTPRepairMeta",
sizeof(GstRTPRepairMeta),
(GstMetaInitFunction) gst_rtp_repair_meta_init,
(GstMetaFreeFunction) gst_rtp_repair_meta_free,
NULL );
g_once_init_leave(&meta_info, mi);
}

return meta_info;
}

GstRTPRepairMeta *gst_buffer_get_rtp_repair_meta(GstBuffer *buffer)
{
return (GstRTPRepairMeta *)gst_buffer_get_meta(buffer,
gst_rtp_repair_meta_api_get_type());
}

GstRTPRepairMeta *gst_buffer_add_rtp_repair_meta(GstBuffer *buffer,
const guint32 ssrc, const guint16 *seqnum, guint seqnum_count)
{
GstRTPRepairMeta *repair_meta = (GstRTPRepairMeta *) gst_buffer_add_meta (buffer,
GST_RTP_REPAIR_META_INFO, NULL);
if (repair_meta == NULL) {
return NULL;
}

repair_meta->ssrc = ssrc;
g_array_insert_vals (repair_meta->seqnums, 0, seqnum, seqnum_count);

return repair_meta;
}

gboolean gst_buffer_repairs_seqnum(GstBuffer *buffer, guint16 seqnum, guint32 ssrc)
{
GstRTPRepairMeta *repair_meta = gst_buffer_get_rtp_repair_meta(buffer);
if (repair_meta) {
if (repair_meta->ssrc != ssrc) {
return FALSE;
}

for (guint i = 0; i < repair_meta->seqnums->len; i++) {
guint16 stored_seqnum = g_array_index(repair_meta->seqnums, guint16, i);
if (stored_seqnum == seqnum) {
return TRUE;
}
}
}
return FALSE;
}

gboolean gst_buffer_get_repair_seqnums(GstBuffer *buffer, guint32 *ssrc,
GArray **seqnums)
{
GstRTPRepairMeta *repair_meta = gst_buffer_get_rtp_repair_meta(buffer);
if (repair_meta && repair_meta->seqnums->len > 0) {
if (ssrc) {
*ssrc = repair_meta->ssrc;
}
if (seqnums) {
*seqnums = g_array_ref (repair_meta->seqnums);
}
return TRUE;
} else {
*ssrc = 0;
*seqnums = NULL;
}
return FALSE;
}

static gboolean
gst_rtp_repair_meta_init(GstRTPRepairMeta * meta, G_GNUC_UNUSED gpointer params,
G_GNUC_UNUSED GstBuffer * buffer)
{
meta->ssrc = 0;
meta->seqnums = g_array_new(FALSE, FALSE, sizeof(guint16));

return TRUE;
}

static void
gst_rtp_repair_meta_free(GstRTPRepairMeta *meta,
G_GNUC_UNUSED GstBuffer *buffer)
{
g_array_unref (meta->seqnums);
}
63 changes: 63 additions & 0 deletions subprojects/gst-plugins-base/gst-libs/gst/rtp/gstrtprepairmeta.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* GStreamer
* Copyright (C) <2024> Mikhail Baranov <[email protected]>
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#ifndef __GST_RTP_REPAIR_META_H__
#define __GST_RTP_REPAIR_META_H__

#include <gst/gst.h>
#include <glib.h>
#include <gst/rtp/rtp-prelude.h>

G_BEGIN_DECLS

#define GST_RTP_REPAIR_META_API_TYPE (gst_rtp_repair_meta_api_get_type())
#define GST_RTP_REPAIR_META_INFO (gst_rtp_repair_meta_get_info())
typedef struct _GstRTPRepairMeta GstRTPRepairMeta;

struct _GstRTPRepairMeta
{
GstMeta meta;

guint32 ssrc;
GArray *seqnums;
};

GST_RTP_API
GType gst_rtp_repair_meta_api_get_type (void);

GST_RTP_API
GstRTPRepairMeta * gst_buffer_add_rtp_repair_meta (GstBuffer *buffer, const guint32 ssrc,
const guint16 *seqnum, guint seqnum_count);

GST_RTP_API
GstRTPRepairMeta * gst_buffer_get_rtp_repair_meta (GstBuffer * buffer);

GST_RTP_API
gboolean gst_buffer_repairs_seqnum(GstBuffer *buffer, guint16 seqnum, guint32 ssrc);

GST_RTP_API
gboolean gst_buffer_get_repair_seqnums(GstBuffer *buffer, guint32 * ssrc,
GArray ** seqnums);

GST_RTP_API
const GstMetaInfo * gst_rtp_repair_meta_get_info (void);

G_END_DECLS

#endif /* __GST_RTP_REPAIR_META_H__ */
2 changes: 2 additions & 0 deletions subprojects/gst-plugins-base/gst-libs/gst/rtp/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ rtp_sources = files([
'gstrtppayloads.c',
'gstrtphdrext.c',
'gstrtpmeta.c',
'gstrtprepairmeta.c',
'gstrtpbaseaudiopayload.c',
'gstrtpbasepayload.c',
'gstrtpbasedepayload.c'
Expand All @@ -18,6 +19,7 @@ rtp_headers = files([
'gstrtpdefs.h',
'gstrtphdrext.h',
'gstrtpmeta.h',
'gstrtprepairmeta.h',
'gstrtppayloads.h',
'rtp-prelude.h',
'rtp.h',
Expand Down
17 changes: 14 additions & 3 deletions subprojects/gst-plugins-good/gst/rtpmanager/gstrtprtxsend.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include "gstrtprtxsend.h"
#include "rtpstats.h"
#include <gst/rtp/gstrtprepairmeta.h>

GST_DEBUG_CATEGORY_STATIC (gst_rtp_rtx_send_debug);
#define GST_CAT_DEFAULT gst_rtp_rtx_send_debug
Expand Down Expand Up @@ -765,22 +766,32 @@ gst_rtp_rtx_buffer_new (GstRtpRtxSend * rtx, GstBuffer * buffer, guint8 padlen)
SSRCRtxData *data;
guint32 ssrc;
guint16 seqnum;
guint32 orig_ssrc;
guint16 orig_seqnum;
guint8 fmtp;

gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp);

/* get needed data from GstRtpRtxSend */
ssrc = gst_rtp_buffer_get_ssrc (&rtp);
data = gst_rtp_rtx_send_get_ssrc_data (rtx, ssrc);
orig_ssrc = gst_rtp_buffer_get_ssrc (&rtp);
data = gst_rtp_rtx_send_get_ssrc_data (rtx, orig_ssrc);
ssrc = data->rtx_ssrc;
seqnum = data->next_seqnum++;
fmtp = GPOINTER_TO_UINT (g_hash_table_lookup (rtx->rtx_pt_map,
GUINT_TO_POINTER (gst_rtp_buffer_get_payload_type (&rtp))));

orig_seqnum = gst_rtp_buffer_get_seq (&rtp);

GST_DEBUG_OBJECT (rtx, "creating rtx buffer, orig seqnum: %u, "
"rtx seqnum: %u, rtx ssrc: %X", gst_rtp_buffer_get_seq (&rtp),
"rtx seqnum: %u, rtx ssrc: %X", orig_seqnum,
seqnum, ssrc);

GstRTPRepairMeta *repair_meta = gst_buffer_add_rtp_repair_meta (new_buffer,
orig_ssrc, &orig_seqnum, 1);
GST_DEBUG_OBJECT (rtx, "%p, %d", repair_meta->seqnums,
repair_meta->seqnums->len);


/* gst_rtp_buffer_map does not map the payload so do it now */
gst_rtp_buffer_get_payload (&rtp);

Expand Down
1 change: 1 addition & 0 deletions subprojects/gst-plugins-good/gst/rtpmanager/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ rtpmanager_sources = [
'rtpstats.c',
'rtptimerqueue.c',
'rtptwcc.c',
'rtpreceptionstats.c',
'gstrtpsession.c',
'gstrtpfunnel.c',
'gstrtpst2022-1-fecdec.c',
Expand Down
Loading

0 comments on commit 0b04a8b

Please sign in to comment.