mirror of
https://code.videolan.org/videolan/vlc
synced 2024-10-15 08:37:59 +02:00
rtp: helpers to parse a=fmtp lines
This commit is contained in:
parent
77eab7cd4a
commit
2ba4b4e5e2
@ -28,6 +28,8 @@ librtp_plugin_la_LIBADD += libvlc_srtp.la $(GCRYPT_LIBS)
|
|||||||
librtp_plugin_la_DEPENDENCIES += libvlc_srtp.la
|
librtp_plugin_la_DEPENDENCIES += libvlc_srtp.la
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
noinst_HEADERS += access/rtp/fmtp.h
|
||||||
|
|
||||||
# RTP payload parser plugins
|
# RTP payload parser plugins
|
||||||
rtpparsedir = $(accessdir)/rtp
|
rtpparsedir = $(accessdir)/rtp
|
||||||
rtpparse_LTLIBRARIES = \
|
rtpparse_LTLIBRARIES = \
|
||||||
|
106
modules/access/rtp/fmtp.h
Normal file
106
modules/access/rtp/fmtp.h
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/**
|
||||||
|
* @file fmtp.h
|
||||||
|
* @brief SDP format parameters (fmtp) helpers
|
||||||
|
*/
|
||||||
|
/*****************************************************************************
|
||||||
|
* Copyright © 2022 Rémi Denis-Courmont
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2.1
|
||||||
|
* 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser 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 <errno.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static inline
|
||||||
|
const char *vlc_sdp_fmtp_get_str(const struct vlc_sdp_pt *desc,
|
||||||
|
const char *name, size_t *restrict lenp)
|
||||||
|
{
|
||||||
|
const char *p = desc->parameters;
|
||||||
|
size_t namelen = strlen(name);
|
||||||
|
|
||||||
|
while (p != NULL) {
|
||||||
|
p += strspn(p, " ");
|
||||||
|
|
||||||
|
if (strncmp(p, name, namelen) == 0 && p[namelen] == '=') {
|
||||||
|
p += namelen + 1;
|
||||||
|
*lenp = strcspn(p, ";");
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = strchr(p, ';');
|
||||||
|
if (p != NULL)
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int vlc_sdp_fmtp_get_ull(const struct vlc_sdp_pt *desc, const char *name,
|
||||||
|
unsigned long long *restrict res)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
const char *n = vlc_sdp_fmtp_get_str(desc, name, &len);
|
||||||
|
if (n == NULL)
|
||||||
|
return -ENOENT;
|
||||||
|
if (len == 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
char *end;
|
||||||
|
unsigned long long ull = strtoull(n, &end, 10);
|
||||||
|
if (end != n + len)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
*res = ull;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
int vlc_sdp_fmtp_get_u16(const struct vlc_sdp_pt *desc, const char *name,
|
||||||
|
uint16_t *restrict res)
|
||||||
|
{
|
||||||
|
unsigned long long ull;
|
||||||
|
int err = vlc_sdp_fmtp_get_ull(desc, name, &ull);
|
||||||
|
if (err == 0) {
|
||||||
|
if (ull >> 16)
|
||||||
|
return -ERANGE;
|
||||||
|
|
||||||
|
*res = ull;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
int vlc_sdp_fmtp_get_u8(const struct vlc_sdp_pt *desc, const char *name,
|
||||||
|
uint8_t *restrict res)
|
||||||
|
{
|
||||||
|
unsigned long long ull;
|
||||||
|
int err = vlc_sdp_fmtp_get_ull(desc, name, &ull);
|
||||||
|
if (err == 0) {
|
||||||
|
if (ull >> 8)
|
||||||
|
return -ERANGE;
|
||||||
|
|
||||||
|
*res = ull;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define vlc_sdp_fmtp_get(desc, name, vp) \
|
||||||
|
_Generic (*(vp), \
|
||||||
|
uint16_t: vlc_sdp_fmtp_get_u16(desc, name, (uint16_t *)(vp)), \
|
||||||
|
uint8_t: vlc_sdp_fmtp_get_u8(desc, name, (uint8_t *)(vp)))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user