mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-29 21:21:12 +00:00
rtpmanager: Move some duplicated constant and helper function to a single place
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2132>
This commit is contained in:
parent
1eb7f81f9d
commit
02115a5efc
9 changed files with 98 additions and 104 deletions
|
@ -151,6 +151,7 @@
|
|||
#include "rtpsession.h"
|
||||
#include "gstrtpsession.h"
|
||||
#include "gstrtpjitterbuffer.h"
|
||||
#include "gstrtputils.h"
|
||||
|
||||
#include <gst/glib-compat-private.h>
|
||||
|
||||
|
@ -1298,7 +1299,7 @@ get_current_times (GstRtpBin * bin, GstClockTime * running_time,
|
|||
if (bin->use_pipeline_clock) {
|
||||
ntpns = rt;
|
||||
/* add constant to convert from 1970 based time to 1900 based time */
|
||||
ntpns += (2208988800LL * GST_SECOND);
|
||||
ntpns += (GST_RTP_NTP_UNIX_OFFSET * GST_SECOND);
|
||||
} else {
|
||||
switch (bin->ntp_time_source) {
|
||||
case GST_RTP_NTP_TIME_SOURCE_NTP:
|
||||
|
@ -1308,7 +1309,7 @@ get_current_times (GstRtpBin * bin, GstClockTime * running_time,
|
|||
|
||||
/* add constant to convert from 1970 based time to 1900 based time */
|
||||
if (bin->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP)
|
||||
ntpns += (2208988800LL * GST_SECOND);
|
||||
ntpns += (GST_RTP_NTP_UNIX_OFFSET * GST_SECOND);
|
||||
break;
|
||||
}
|
||||
case GST_RTP_NTP_TIME_SOURCE_RUNNING_TIME:
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
#include <gst/rtp/gstrtphdrext.h>
|
||||
|
||||
#include "gstrtpfunnel.h"
|
||||
#include "gstrtputils.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_rtp_funnel_debug);
|
||||
#define GST_CAT_DEFAULT gst_rtp_funnel_debug
|
||||
|
@ -327,29 +328,6 @@ gst_rtp_funnel_set_twcc_ext_id (GstRtpFunnel * funnel, guint8 twcc_ext_id)
|
|||
gst_rtp_header_extension_set_id (funnel->twcc_ext, twcc_ext_id);
|
||||
}
|
||||
|
||||
static guint8
|
||||
_get_extmap_id_for_attribute (const GstStructure * s, const gchar * ext_name)
|
||||
{
|
||||
guint i;
|
||||
guint8 extmap_id = 0;
|
||||
guint n_fields = gst_structure_n_fields (s);
|
||||
|
||||
for (i = 0; i < n_fields; i++) {
|
||||
const gchar *field_name = gst_structure_nth_field_name (s, i);
|
||||
if (g_str_has_prefix (field_name, "extmap-")) {
|
||||
const gchar *str = gst_structure_get_string (s, field_name);
|
||||
if (str && g_strcmp0 (str, ext_name) == 0) {
|
||||
gint64 id = g_ascii_strtoll (field_name + 7, NULL, 10);
|
||||
if (id > 0 && id < 15) {
|
||||
extmap_id = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return extmap_id;
|
||||
}
|
||||
|
||||
#define TWCC_EXTMAP_STR "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"
|
||||
|
||||
static gboolean
|
||||
|
@ -398,7 +376,7 @@ gst_rtp_funnel_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
|||
funnel->twcc_ext =
|
||||
gst_rtp_header_extension_create_from_uri (TWCC_EXTMAP_STR);
|
||||
|
||||
ext_id = _get_extmap_id_for_attribute (s, TWCC_EXTMAP_STR);
|
||||
ext_id = gst_rtp_get_extmap_id_for_attribute (s, TWCC_EXTMAP_STR);
|
||||
if (ext_id > 0) {
|
||||
fpad->has_twcc = TRUE;
|
||||
funnel->twcc_pads++;
|
||||
|
|
|
@ -113,6 +113,7 @@
|
|||
#include "rtpjitterbuffer.h"
|
||||
#include "rtpstats.h"
|
||||
#include "rtptimerqueue.h"
|
||||
#include "gstrtputils.h"
|
||||
|
||||
#include <gst/glib-compat-private.h>
|
||||
|
||||
|
@ -1494,29 +1495,6 @@ _get_cname_ssrc_mappings (GstRtpJitterBuffer * jitterbuffer,
|
|||
}
|
||||
}
|
||||
|
||||
static guint8
|
||||
_get_extmap_id_for_attribute (const GstStructure * s, const gchar * ext_name)
|
||||
{
|
||||
guint i;
|
||||
guint8 extmap_id = 0;
|
||||
guint n_fields = gst_structure_n_fields (s);
|
||||
|
||||
for (i = 0; i < n_fields; i++) {
|
||||
const gchar *field_name = gst_structure_nth_field_name (s, i);
|
||||
if (g_str_has_prefix (field_name, "extmap-")) {
|
||||
const gchar *str = gst_structure_get_string (s, field_name);
|
||||
if (str && g_strcmp0 (str, ext_name) == 0) {
|
||||
gint64 id = g_ascii_strtoll (field_name + 7, NULL, 10);
|
||||
if (id > 0 && id < 15) {
|
||||
extmap_id = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return extmap_id;
|
||||
}
|
||||
|
||||
/*
|
||||
* Must be called with JBUF_LOCK held
|
||||
*/
|
||||
|
@ -1692,7 +1670,7 @@ gst_jitter_buffer_sink_parse_caps (GstRtpJitterBuffer * jitterbuffer,
|
|||
|
||||
_get_cname_ssrc_mappings (jitterbuffer, caps_struct);
|
||||
priv->ntp64_ext_id =
|
||||
_get_extmap_id_for_attribute (caps_struct,
|
||||
gst_rtp_get_extmap_id_for_attribute (caps_struct,
|
||||
GST_RTP_HDREXT_BASE GST_RTP_HDREXT_NTP_64);
|
||||
|
||||
return TRUE;
|
||||
|
|
|
@ -111,6 +111,7 @@
|
|||
|
||||
#include "gstrtpsession.h"
|
||||
#include "rtpsession.h"
|
||||
#include "gstrtputils.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_rtp_session_debug);
|
||||
#define GST_CAT_DEFAULT gst_rtp_session_debug
|
||||
|
@ -1101,7 +1102,7 @@ get_current_times (GstRtpSession * rtpsession, GstClockTime * running_time,
|
|||
if (rtpsession->priv->use_pipeline_clock) {
|
||||
ntpns = rt;
|
||||
/* add constant to convert from 1970 based time to 1900 based time */
|
||||
ntpns += (2208988800LL * GST_SECOND);
|
||||
ntpns += (GST_RTP_NTP_UNIX_OFFSET * GST_SECOND);
|
||||
} else {
|
||||
switch (rtpsession->priv->ntp_time_source) {
|
||||
case GST_RTP_NTP_TIME_SOURCE_NTP:
|
||||
|
@ -1111,7 +1112,7 @@ get_current_times (GstRtpSession * rtpsession, GstClockTime * running_time,
|
|||
|
||||
/* add constant to convert from 1970 based time to 1900 based time */
|
||||
if (rtpsession->priv->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP)
|
||||
ntpns += (2208988800LL * GST_SECOND);
|
||||
ntpns += (GST_RTP_NTP_UNIX_OFFSET * GST_SECOND);
|
||||
break;
|
||||
}
|
||||
case GST_RTP_NTP_TIME_SOURCE_RUNNING_TIME:
|
||||
|
@ -2458,7 +2459,7 @@ gst_rtp_session_chain_send_rtp_common (GstRtpSession * rtpsession,
|
|||
if (rtpsession->priv->use_pipeline_clock) {
|
||||
ntpnstime = running_time;
|
||||
/* add constant to convert from 1970 based time to 1900 based time */
|
||||
ntpnstime += (2208988800LL * GST_SECOND);
|
||||
ntpnstime += (GST_RTP_NTP_UNIX_OFFSET * GST_SECOND);
|
||||
} else {
|
||||
switch (rtpsession->priv->ntp_time_source) {
|
||||
case GST_RTP_NTP_TIME_SOURCE_NTP:
|
||||
|
@ -2494,7 +2495,7 @@ gst_rtp_session_chain_send_rtp_common (GstRtpSession * rtpsession,
|
|||
if (ntpnstime != GST_CLOCK_TIME_NONE
|
||||
&& rtpsession->priv->ntp_time_source ==
|
||||
GST_RTP_NTP_TIME_SOURCE_NTP)
|
||||
ntpnstime += (2208988800LL * GST_SECOND);
|
||||
ntpnstime += (GST_RTP_NTP_UNIX_OFFSET * GST_SECOND);
|
||||
break;
|
||||
}
|
||||
case GST_RTP_NTP_TIME_SOURCE_RUNNING_TIME:
|
||||
|
|
44
subprojects/gst-plugins-good/gst/rtpmanager/gstrtputils.c
Normal file
44
subprojects/gst-plugins-good/gst/rtpmanager/gstrtputils.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2022 Sebastian Dröge <sebastian@centricular.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "gstrtputils.h"
|
||||
|
||||
guint8
|
||||
gst_rtp_get_extmap_id_for_attribute (const GstStructure * s,
|
||||
const gchar * ext_name)
|
||||
{
|
||||
guint i;
|
||||
guint8 extmap_id = 0;
|
||||
guint n_fields = gst_structure_n_fields (s);
|
||||
|
||||
for (i = 0; i < n_fields; i++) {
|
||||
const gchar *field_name = gst_structure_nth_field_name (s, i);
|
||||
if (g_str_has_prefix (field_name, "extmap-")) {
|
||||
const gchar *str = gst_structure_get_string (s, field_name);
|
||||
if (str && g_strcmp0 (str, ext_name) == 0) {
|
||||
gint64 id = g_ascii_strtoll (field_name + 7, NULL, 10);
|
||||
if (id > 0 && id < 15) {
|
||||
extmap_id = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return extmap_id;
|
||||
}
|
34
subprojects/gst-plugins-good/gst/rtpmanager/gstrtputils.h
Normal file
34
subprojects/gst-plugins-good/gst/rtpmanager/gstrtputils.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2022 Sebastian Dröge <sebastian@centricular.com>
|
||||
*
|
||||
* 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_UTILS_H__
|
||||
#define __GST_RTP_UTILS_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_RTP_NTP_UNIX_OFFSET (2208988800LL)
|
||||
|
||||
G_GNUC_INTERNAL guint8
|
||||
gst_rtp_get_extmap_id_for_attribute (const GstStructure * s, const gchar * ext_name);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_RTP_UTILS_H__ */
|
|
@ -24,7 +24,8 @@ rtpmanager_sources = [
|
|||
'gstrtpsession.c',
|
||||
'gstrtpfunnel.c',
|
||||
'gstrtpst2022-1-fecdec.c',
|
||||
'gstrtpst2022-1-fecenc.c'
|
||||
'gstrtpst2022-1-fecenc.c',
|
||||
'gstrtputils.c'
|
||||
]
|
||||
|
||||
gstrtpmanager = library('gstrtpmanager',
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <gst/glib-compat-private.h>
|
||||
|
||||
#include "rtpsession.h"
|
||||
#include "gstrtputils.h"
|
||||
|
||||
GST_DEBUG_CATEGORY (rtp_session_debug);
|
||||
#define GST_CAT_DEFAULT rtp_session_debug
|
||||
|
@ -3177,29 +3178,6 @@ invalid_packet:
|
|||
}
|
||||
}
|
||||
|
||||
static guint8
|
||||
_get_extmap_id_for_attribute (const GstStructure * s, const gchar * ext_name)
|
||||
{
|
||||
guint i;
|
||||
guint8 extmap_id = 0;
|
||||
guint n_fields = gst_structure_n_fields (s);
|
||||
|
||||
for (i = 0; i < n_fields; i++) {
|
||||
const gchar *field_name = gst_structure_nth_field_name (s, i);
|
||||
if (g_str_has_prefix (field_name, "extmap-")) {
|
||||
const gchar *str = gst_structure_get_string (s, field_name);
|
||||
if (str && g_strcmp0 (str, ext_name) == 0) {
|
||||
gint64 id = g_ascii_strtoll (field_name + 7, NULL, 10);
|
||||
if (id > 0 && id < 15) {
|
||||
extmap_id = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return extmap_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* rtp_session_update_send_caps:
|
||||
* @sess: an #RTPSession
|
||||
|
@ -3256,7 +3234,7 @@ rtp_session_update_send_caps (RTPSession * sess, GstCaps * caps)
|
|||
}
|
||||
|
||||
sess->send_ntp64_ext_id =
|
||||
_get_extmap_id_for_attribute (s,
|
||||
gst_rtp_get_extmap_id_for_attribute (s,
|
||||
GST_RTP_HDREXT_BASE GST_RTP_HDREXT_NTP_64);
|
||||
|
||||
rtp_twcc_manager_parse_send_ext_id (sess->twcc, s);
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <gst/base/gstbitreader.h>
|
||||
#include <gst/base/gstbitwriter.h>
|
||||
|
||||
#include "gstrtputils.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_EXTERN (rtp_session_debug);
|
||||
#define GST_CAT_DEFAULT rtp_session_debug
|
||||
|
||||
|
@ -166,34 +168,11 @@ recv_packet_init (RecvPacket * packet, guint16 seqnum, RTPPacketInfo * pinfo)
|
|||
packet->ts = pinfo->current_time;
|
||||
}
|
||||
|
||||
static guint8
|
||||
_get_extmap_id_for_attribute (const GstStructure * s, const gchar * ext_name)
|
||||
{
|
||||
guint i;
|
||||
guint8 extmap_id = 0;
|
||||
guint n_fields = gst_structure_n_fields (s);
|
||||
|
||||
for (i = 0; i < n_fields; i++) {
|
||||
const gchar *field_name = gst_structure_nth_field_name (s, i);
|
||||
if (g_str_has_prefix (field_name, "extmap-")) {
|
||||
const gchar *str = gst_structure_get_string (s, field_name);
|
||||
if (str && g_strcmp0 (str, ext_name) == 0) {
|
||||
gint64 id = g_ascii_strtoll (field_name + 7, NULL, 10);
|
||||
if (id > 0 && id < 15) {
|
||||
extmap_id = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return extmap_id;
|
||||
}
|
||||
|
||||
void
|
||||
rtp_twcc_manager_parse_recv_ext_id (RTPTWCCManager * twcc,
|
||||
const GstStructure * s)
|
||||
{
|
||||
guint8 recv_ext_id = _get_extmap_id_for_attribute (s, TWCC_EXTMAP_STR);
|
||||
guint8 recv_ext_id = gst_rtp_get_extmap_id_for_attribute (s, TWCC_EXTMAP_STR);
|
||||
if (recv_ext_id > 0) {
|
||||
twcc->recv_ext_id = recv_ext_id;
|
||||
GST_INFO ("TWCC enabled for recv using extension id: %u",
|
||||
|
@ -205,7 +184,7 @@ void
|
|||
rtp_twcc_manager_parse_send_ext_id (RTPTWCCManager * twcc,
|
||||
const GstStructure * s)
|
||||
{
|
||||
guint8 send_ext_id = _get_extmap_id_for_attribute (s, TWCC_EXTMAP_STR);
|
||||
guint8 send_ext_id = gst_rtp_get_extmap_id_for_attribute (s, TWCC_EXTMAP_STR);
|
||||
if (send_ext_id > 0) {
|
||||
twcc->send_ext_id = send_ext_id;
|
||||
GST_INFO ("TWCC enabled for send using extension id: %u",
|
||||
|
|
Loading…
Reference in a new issue