[FFmpeg-devel] [PATCH 2/3] avformat/whip whep: reanme whip prefix to rtc for common RTC structures
---
libavformat/rtc.c | 564 ++---
libavformat/rtc.h | 60 ++---
libavformat/whip.c | 180 +++
3 files changed, 402 insertions(+), 402 deletions(-)
diff --git a/libavformat/rtc.c b/libavformat/rtc.c
index 2dc0383d3e..8c848b6026 100644
--- a/libavformat/rtc.c
+++ b/libavformat/rtc.c
@@ -97,9 +97,9 @@
#define MAX_UDP_BUFFER_SIZE 4096
/* Referring to Chrome's definition of RTP payload types. */
-#define WHIP_RTP_PAYLOAD_TYPE_H264 106
-#define WHIP_RTP_PAYLOAD_TYPE_OPUS 111
-#define WHIP_RTP_PAYLOAD_TYPE_VIDEO_RTX 105
+#define RTC_RTP_PAYLOAD_TYPE_H264 106
+#define RTC_RTP_PAYLOAD_TYPE_OPUS 111
+#define RTC_RTP_PAYLOAD_TYPE_VIDEO_RTX 105
/**
* The STUN message header, which is 20 bytes long, comprises the
@@ -113,8 +113,8 @@
* In the case of ICE-LITE, these fields are not used; instead, they are
defined
* as constant values.
*/
-#define WHIP_SDP_SESSION_ID "4489045141692799359"
-#define WHIP_SDP_CREATOR_IP "127.0.0.1"
+#define RTC_SDP_SESSION_ID "4489045141692799359"
+#define RTC_SDP_CREATOR_IP "127.0.0.1"
/* Calculate the elapsed time from starttime to endtime in milliseconds. */
#define ELAPSED(starttime, endtime) ((float)(endtime - starttime) / 1000)
@@ -146,23 +146,23 @@ int ff_rtc_is_dtls_packet(uint8_t *b, int size) {
static av_cold int certificate_key_init(AVFormatContext *s)
{
int ret = 0;
-WHIPContext *whip = s->priv_data;
+RTCContext *rtc = s->priv_data;
-if (whip->cert_file && whip->key_file) {
+if (rtc->cert_file && rtc->key_file) {
/* Read the private key and certificate from the file. */
-if ((ret = ff_ssl_read_key_cert(whip->key_file, whip->cert_file,
-whip->key_buf, sizeof(whip->key_buf),
-whip->cert_buf, sizeof(whip->cert_buf),
-&whip->dtls_fingerprint)) < 0) {
+if ((ret = ff_ssl_read_key_cert(rtc->key_file, rtc->cert_file,
+rtc->key_buf, sizeof(rtc->key_buf),
+rtc->cert_buf, sizeof(rtc->cert_buf),
+&rtc->dtls_fingerprint)) < 0) {
av_log(s, AV_LOG_ERROR, "Failed to read DTLS certificate from
cert=%s, key=%s\n",
-whip->cert_file, whip->key_file);
+rtc->cert_file, rtc->key_file);
return ret;
}
} else {
/* Generate a private key to ctx->dtls_pkey and self-signed
certificate. */
-if ((ret = ff_ssl_gen_key_cert(whip->key_buf, sizeof(whip->key_buf),
- whip->cert_buf, sizeof(whip->cert_buf),
- &whip->dtls_fingerprint)) < 0) {
+if ((ret = ff_ssl_gen_key_cert(rtc->key_buf, sizeof(rtc->key_buf),
+ rtc->cert_buf, sizeof(rtc->cert_buf),
+ &rtc->dtls_fingerprint)) < 0) {
av_log(s, AV_LOG_ERROR, "Failed to generate DTLS private key and
certificate\n");
return ret;
}
@@ -173,13 +173,13 @@ static av_cold int certificate_key_init(AVFormatContext
*s)
static av_cold int dtls_initialize(AVFormatContext *s)
{
-WHIPContext *whip = s->priv_data;
-/* reuse the udp created by whip */
-ff_tls_set_external_socket(whip->dtls_uc, whip->udp);
+RTCContext *rtc = s->priv_data;
+/* reuse the udp created by rtc */
+ff_tls_set_external_socket(rtc->dtls_uc, rtc->udp);
/* Make the socket non-blocking */
-ff_socket_nonblock(ffurl_get_file_handle(whip->dtls_uc), 1);
-whip->dtls_uc->flags |= AVIO_FLAG_NONBLOCK;
+ff_socket_nonblock(ffurl_get_file_handle(rtc->dtls_uc), 1);
+rtc->dtls_uc->flags |= AVIO_FLAG_NONBLOCK;
return 0;
}
@@ -190,40 +190,40 @@ static av_cold int dtls_initialize(AVFormatContext *s)
av_cold int ff_rtc_initialize(AVFormatContext *s)
{
int ret, ideal_pkt_size = 532;
-WHIPContext *whip = s->priv_data;
+RTCContext *rtc = s->priv_data;
uint32_t seed;
-whip->whip_starttime = av_gettime_relative();
+rtc->rtc_starttime = av_gettime_relative();
ret = certificate_key_init(s);
if (ret < 0) {
-av_log(whip, AV_LOG_ERROR, "Failed to init certificate and key\n");
+av_log(rtc, AV_LOG_ERROR, "Failed to init certificate and key\n");
return ret;
}
/* Initialize the random number generator. */
seed = av_get_random_seed();
-av_lfg_init(&whip->rnd, seed);
+av_lfg_init(&rtc->rnd, seed);
/* 64 bit tie breaker for ICE-CONTROLLING (RFC 8445 16.1) */
-ret = av_random_bytes((uint8_t *)&whip->ice_tie_breaker,
sizeof(whip->ice_tie_breaker));
+ret = av_random_bytes((uint8_t *)&rtc->ice_tie_breaker,
sizeof(rtc->ice_tie_breaker));
if (ret < 0) {
-av_log(whip, AV_LOG_ERROR, "Couldn't generate random bytes for ICE tie
breaker\n
[FFmpeg-devel] [PATCH 3/3] avformat/whip whep: add whep support
---
configure| 1 +
libavformat/Makefile | 1 +
libavformat/allformats.c | 1 +
libavformat/rtc.c| 895 +--
libavformat/rtc.h| 38 +-
libavformat/rtpdec.c | 6 +-
libavformat/rtpdec.h | 11 +
libavformat/whep.c | 457
libavformat/whip.c | 52 +--
9 files changed, 1374 insertions(+), 88 deletions(-)
create mode 100644 libavformat/whep.c
diff --git a/configure b/configure
index 7828381b5d..6de7173167 100755
--- a/configure
+++ b/configure
@@ -3836,6 +3836,7 @@ wav_demuxer_select="riffdec"
wav_muxer_select="riffenc"
webm_chunk_muxer_select="webm_muxer"
webm_dash_manifest_demuxer_select="matroska_demuxer"
+whep_muxer_deps_any="dtls_protocol"
whip_muxer_deps_any="dtls_protocol"
wtv_demuxer_select="mpegts_demuxer riffdec"
wtv_muxer_select="mpegts_muxer riffenc"
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 9261245755..dadc1321b1 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -640,6 +640,7 @@ OBJS-$(CONFIG_WEBM_CHUNK_MUXER) += webm_chunk.o
OBJS-$(CONFIG_WEBP_MUXER)+= webpenc.o
OBJS-$(CONFIG_WEBVTT_DEMUXER)+= webvttdec.o subtitles.o
OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o
+OBJS-$(CONFIG_WHEP_DEMUXER) += whep.o rtc.o avc.o http.o srtp.o
OBJS-$(CONFIG_WHIP_MUXER)+= whip.o rtc.o avc.o http.o srtp.o
OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o
OBJS-$(CONFIG_WSAUD_MUXER) += westwood_audenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 3a025da3db..cd7e3cc4c4 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -518,6 +518,7 @@ extern const FFOutputFormat ff_webp_muxer;
extern const FFInputFormat ff_webvtt_demuxer;
extern const FFOutputFormat ff_webvtt_muxer;
extern const FFInputFormat ff_wsaud_demuxer;
+extern const FFInputFormat ff_whep_demuxer;
extern const FFOutputFormat ff_whip_muxer;
extern const FFOutputFormat ff_wsaud_muxer;
extern const FFInputFormat ff_wsd_demuxer;
diff --git a/libavformat/rtc.c b/libavformat/rtc.c
index 8c848b6026..57da5487b4 100644
--- a/libavformat/rtc.c
+++ b/libavformat/rtc.c
@@ -19,6 +19,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavcodec/avcodec.h"
+#include "libavcodec/codec_desc.h"
+#include "libavcodec/defs.h"
+#include "libavcodec/h264.h"
+#include "libavcodec/h264_levels.h"
#include "libavutil/time.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/random_seed.h"
@@ -26,18 +31,21 @@
#include "libavutil/hmac.h"
#include "libavutil/mem.h"
#include "libavutil/base64.h"
+#include "libavutil/parseutils.h"
#include "avio_internal.h"
#include "internal.h"
#include "network.h"
#include "http.h"
#include "rtc.h"
+#include "rtp.h"
+#include "rtpdec.h"
/**
* Maximum size limit of a Session Description Protocol (SDP),
* be it an offer or answer.
*/
-#define MAX_SDP_SIZE 8192
+#define MAX_SDP_SIZE 16384
/**
* The size of the Secure Real-time Transport Protocol (SRTP) master key
material
@@ -87,20 +95,31 @@
#define DTLS_VERSION_10 0xfeff
#define DTLS_VERSION_12 0xfefd
-/**
- * Maximum size of the buffer for sending and receiving UDP packets.
- * Please note that this size does not limit the size of the UDP packet that
can be sent.
- * To set the limit for packet size, modify the `pkt_size` parameter.
- * For instance, it is possible to set the UDP buffer to 4096 to send or
receive packets,
- * but please keep in mind that the `pkt_size` option limits the packet size
to 1400.
- */
-#define MAX_UDP_BUFFER_SIZE 4096
-
/* Referring to Chrome's definition of RTP payload types. */
#define RTC_RTP_PAYLOAD_TYPE_H264 106
#define RTC_RTP_PAYLOAD_TYPE_OPUS 111
#define RTC_RTP_PAYLOAD_TYPE_VIDEO_RTX 105
+ /**
+ * The RTP header is 12 bytes long, comprising the Version(1B), PT(1B),
+ * SequenceNumber(2B), Timestamp(4B), and SSRC(4B).
+ * See https://www.rfc-editor.org/rfc/rfc3550#section-5.1
+ */
+#define RTC_RTP_HEADER_SIZE 12
+
+/**
+ * For RTCP, PT is [128, 223] (or without marker [0, 95]). Literally, RTCP
starts
+ * from 64 not 0, so PT is [192, 223] (or without marker [64, 95]), see "RTCP
Control
+ * Packet Types (PT)" at
+ *
https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
+ *
+ * For RTP, the PT is [96, 127], or [224, 255] with marker. See "RTP Payload
Types (PT)
+ * for standard audio and video encodings" at
+ *
https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-1
+ */
+#define RTC_RTCP_PT_START 192
+#define RTC_RTCP_PT_END 223
+
/**
* The STUN message header, which is 20 bytes long, comprises the
* STUNMessageType (1B), MessageLength (2B), MagicCookie (4B),
@@ -129,6 +148,33 @@ enum STUNAttr {
STUN_ATTR_ICE_CONTROLLING = 0x802A, /// ICE controlling role
};
+
[FFmpeg-devel] [PATCH 0/3] avformat/whip whep: Add basic WHEP support based on the WHIP implementation
Add basic WHEP support based on the WHIP implementation - Implemented the core WHEP playback logic. (Note: RTX retransmission handling is not yet supported). - Modified a few interfaces in the RTP demux to allow them to be reused for the WHEP implementation. The series is structured as follows: avformat/whip whep: create rtc for common RTC code shared by whip and whep avformat/whip whep: reanme whip prefix to rtc for common RTC structures avformat/whip whep: add whep support libavformat/Makefile |3 +- libavformat/allformats.c |1 + libavformat/rtc.c| 2057 ++ libavformat/rtc.h| 256 + libavformat/rtpdec.c |6 +- libavformat/rtpdec.h | 11 + libavformat/whep.c | 457 + libavformat/whip.c | 1584 ++--- 8 files changed, 2888 insertions(+), 1487 deletions(-) create mode 100644 libavformat/rtc.c create mode 100644 libavformat/rtc.h create mode 100644 libavformat/whep.c -- 2.51.0 ___ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
[FFmpeg-devel] [PATCH] avformat/whip: Drop invalid group:BUNDLE from SDP in single-stream cases
---
libavformat/whip.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libavformat/whip.c b/libavformat/whip.c
index 472c6dbf16..6ace9240f9 100644
--- a/libavformat/whip.c
+++ b/libavformat/whip.c
@@ -617,12 +617,14 @@ static int generate_sdp_offer(AVFormatContext *s)
"o=FFmpeg %s 2 IN IP4 %s\r\n"
"s=FFmpegPublishSession\r\n"
"t=0 0\r\n"
-"a=group:BUNDLE 0 1\r\n"
"a=extmap-allow-mixed\r\n"
"a=msid-semantic: WMS\r\n",
WHIP_SDP_SESSION_ID,
WHIP_SDP_CREATOR_IP);
+if (whip->audio_par && whip->video_par)
+av_bprintf(&bp, "a=group:BUNDLE 0 1\r\n");
+
if (whip->audio_par) {
if (whip->audio_par->codec_id == AV_CODEC_ID_OPUS)
acodec_name = "opus";
--
2.51.0
___
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
[FFmpeg-devel] [PATCH 2/3] avformat/whip whep: reanme whip prefix to rtc for common RTC structures
---
libavformat/rtc.c | 564 ++---
libavformat/rtc.h | 60 ++---
libavformat/whip.c | 180 +++
3 files changed, 402 insertions(+), 402 deletions(-)
diff --git a/libavformat/rtc.c b/libavformat/rtc.c
index 2dc0383d3e..8c848b6026 100644
--- a/libavformat/rtc.c
+++ b/libavformat/rtc.c
@@ -97,9 +97,9 @@
#define MAX_UDP_BUFFER_SIZE 4096
/* Referring to Chrome's definition of RTP payload types. */
-#define WHIP_RTP_PAYLOAD_TYPE_H264 106
-#define WHIP_RTP_PAYLOAD_TYPE_OPUS 111
-#define WHIP_RTP_PAYLOAD_TYPE_VIDEO_RTX 105
+#define RTC_RTP_PAYLOAD_TYPE_H264 106
+#define RTC_RTP_PAYLOAD_TYPE_OPUS 111
+#define RTC_RTP_PAYLOAD_TYPE_VIDEO_RTX 105
/**
* The STUN message header, which is 20 bytes long, comprises the
@@ -113,8 +113,8 @@
* In the case of ICE-LITE, these fields are not used; instead, they are
defined
* as constant values.
*/
-#define WHIP_SDP_SESSION_ID "4489045141692799359"
-#define WHIP_SDP_CREATOR_IP "127.0.0.1"
+#define RTC_SDP_SESSION_ID "4489045141692799359"
+#define RTC_SDP_CREATOR_IP "127.0.0.1"
/* Calculate the elapsed time from starttime to endtime in milliseconds. */
#define ELAPSED(starttime, endtime) ((float)(endtime - starttime) / 1000)
@@ -146,23 +146,23 @@ int ff_rtc_is_dtls_packet(uint8_t *b, int size) {
static av_cold int certificate_key_init(AVFormatContext *s)
{
int ret = 0;
-WHIPContext *whip = s->priv_data;
+RTCContext *rtc = s->priv_data;
-if (whip->cert_file && whip->key_file) {
+if (rtc->cert_file && rtc->key_file) {
/* Read the private key and certificate from the file. */
-if ((ret = ff_ssl_read_key_cert(whip->key_file, whip->cert_file,
-whip->key_buf, sizeof(whip->key_buf),
-whip->cert_buf, sizeof(whip->cert_buf),
-&whip->dtls_fingerprint)) < 0) {
+if ((ret = ff_ssl_read_key_cert(rtc->key_file, rtc->cert_file,
+rtc->key_buf, sizeof(rtc->key_buf),
+rtc->cert_buf, sizeof(rtc->cert_buf),
+&rtc->dtls_fingerprint)) < 0) {
av_log(s, AV_LOG_ERROR, "Failed to read DTLS certificate from
cert=%s, key=%s\n",
-whip->cert_file, whip->key_file);
+rtc->cert_file, rtc->key_file);
return ret;
}
} else {
/* Generate a private key to ctx->dtls_pkey and self-signed
certificate. */
-if ((ret = ff_ssl_gen_key_cert(whip->key_buf, sizeof(whip->key_buf),
- whip->cert_buf, sizeof(whip->cert_buf),
- &whip->dtls_fingerprint)) < 0) {
+if ((ret = ff_ssl_gen_key_cert(rtc->key_buf, sizeof(rtc->key_buf),
+ rtc->cert_buf, sizeof(rtc->cert_buf),
+ &rtc->dtls_fingerprint)) < 0) {
av_log(s, AV_LOG_ERROR, "Failed to generate DTLS private key and
certificate\n");
return ret;
}
@@ -173,13 +173,13 @@ static av_cold int certificate_key_init(AVFormatContext
*s)
static av_cold int dtls_initialize(AVFormatContext *s)
{
-WHIPContext *whip = s->priv_data;
-/* reuse the udp created by whip */
-ff_tls_set_external_socket(whip->dtls_uc, whip->udp);
+RTCContext *rtc = s->priv_data;
+/* reuse the udp created by rtc */
+ff_tls_set_external_socket(rtc->dtls_uc, rtc->udp);
/* Make the socket non-blocking */
-ff_socket_nonblock(ffurl_get_file_handle(whip->dtls_uc), 1);
-whip->dtls_uc->flags |= AVIO_FLAG_NONBLOCK;
+ff_socket_nonblock(ffurl_get_file_handle(rtc->dtls_uc), 1);
+rtc->dtls_uc->flags |= AVIO_FLAG_NONBLOCK;
return 0;
}
@@ -190,40 +190,40 @@ static av_cold int dtls_initialize(AVFormatContext *s)
av_cold int ff_rtc_initialize(AVFormatContext *s)
{
int ret, ideal_pkt_size = 532;
-WHIPContext *whip = s->priv_data;
+RTCContext *rtc = s->priv_data;
uint32_t seed;
-whip->whip_starttime = av_gettime_relative();
+rtc->rtc_starttime = av_gettime_relative();
ret = certificate_key_init(s);
if (ret < 0) {
-av_log(whip, AV_LOG_ERROR, "Failed to init certificate and key\n");
+av_log(rtc, AV_LOG_ERROR, "Failed to init certificate and key\n");
return ret;
}
/* Initialize the random number generator. */
seed = av_get_random_seed();
-av_lfg_init(&whip->rnd, seed);
+av_lfg_init(&rtc->rnd, seed);
/* 64 bit tie breaker for ICE-CONTROLLING (RFC 8445 16.1) */
-ret = av_random_bytes((uint8_t *)&whip->ice_tie_breaker,
sizeof(whip->ice_tie_breaker));
+ret = av_random_bytes((uint8_t *)&rtc->ice_tie_breaker,
sizeof(rtc->ice_tie_breaker));
if (ret < 0) {
-av_log(whip, AV_LOG_ERROR, "Couldn't generate random bytes for ICE tie
breaker\n
[FFmpeg-devel] [PATCH v3 0/3] avformat/whip whep: Add basic WHEP support based on the WHIP implementation
Add basic WHEP support based on the WHIP implementation - Implemented the core WHEP playback logic. (Note: RTX retransmission handling is not yet supported). - Modified a few interfaces in the RTP demux to allow them to be reused for the WHEP implementation. The series is structured as follows: avformat/whip whep: create rtc for common RTC code shared by whip and whep avformat/whip whep: reanme whip prefix to rtc for common RTC structures avformat/whip whep: add whep support configure|1 + libavformat/Makefile |3 +- libavformat/allformats.c |1 + libavformat/rtc.c| 2057 ++ libavformat/rtc.h| 256 + libavformat/rtpdec.c |6 +- libavformat/rtpdec.h | 11 + libavformat/whep.c | 457 + libavformat/whip.c | 1584 ++--- 9 files changed, 2889 insertions(+), 1487 deletions(-) create mode 100644 libavformat/rtc.c create mode 100644 libavformat/rtc.h create mode 100644 libavformat/whep.c The original v2 series can be found here: https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=15611 The original v1 series can be found here: https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=15659 Changes in v2: - add missing configure modification Changes in v3: - configure: fix build with --disable-openssl -- 2.51.0 ___ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
[FFmpeg-devel] [PATCH 0/3] avformat/whip whep: Add basic WHEP support based on the WHIP implementation
*** BLURB HERE *** baigao (3): avformat/whip whep: create rtc for common RTC code shared by whip and whep avformat/whip whep: reanme whip prefix to rtc for common RTC structures avformat/whip whep: add whep support configure|1 + libavformat/Makefile |3 +- libavformat/allformats.c |1 + libavformat/rtc.c| 2057 ++ libavformat/rtc.h| 256 + libavformat/rtpdec.c |6 +- libavformat/rtpdec.h | 11 + libavformat/whep.c | 457 + libavformat/whip.c | 1584 ++--- 9 files changed, 2889 insertions(+), 1487 deletions(-) create mode 100644 libavformat/rtc.c create mode 100644 libavformat/rtc.h create mode 100644 libavformat/whep.c The original v1 series can be found here: https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=15659 Changes in v2: - add missing configure modification Thansks, baigao -- 2.51.0 ___ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
[FFmpeg-devel] [PATCH 1/3] avformat/whip whep: create rtc for common RTC code shared by whip and whep
---
libavformat/Makefile |2 +-
libavformat/{whip.c => rtc.c} | 856 +---
libavformat/rtc.h | 220 ++
libavformat/whip.c| 1386 +
4 files changed, 264 insertions(+), 2200 deletions(-)
copy libavformat/{whip.c => rtc.c} (59%)
create mode 100644 libavformat/rtc.h
diff --git a/libavformat/Makefile b/libavformat/Makefile
index ed93458f03..9261245755 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -640,7 +640,7 @@ OBJS-$(CONFIG_WEBM_CHUNK_MUXER) += webm_chunk.o
OBJS-$(CONFIG_WEBP_MUXER)+= webpenc.o
OBJS-$(CONFIG_WEBVTT_DEMUXER)+= webvttdec.o subtitles.o
OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o
-OBJS-$(CONFIG_WHIP_MUXER)+= whip.o avc.o http.o srtp.o
+OBJS-$(CONFIG_WHIP_MUXER)+= whip.o rtc.o avc.o http.o srtp.o
OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o
OBJS-$(CONFIG_WSAUD_MUXER) += westwood_audenc.o
OBJS-$(CONFIG_WSD_DEMUXER) += wsddec.o rawdec.o
diff --git a/libavformat/whip.c b/libavformat/rtc.c
similarity index 59%
copy from libavformat/whip.c
copy to libavformat/rtc.c
index e809075643..2dc0383d3e 100644
--- a/libavformat/whip.c
+++ b/libavformat/rtc.c
@@ -1,5 +1,5 @@
/*
- * WebRTC-HTTP ingestion protocol (WHIP) muxer
+ * WebRTC protocol
* Copyright (c) 2023 The FFmpeg Project
*
* This file is part of FFmpeg.
@@ -19,30 +19,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "libavcodec/avcodec.h"
-#include "libavcodec/codec_desc.h"
-#include "libavcodec/h264.h"
-#include "libavcodec/startcode.h"
-#include "libavutil/base64.h"
-#include "libavutil/bprint.h"
+#include "libavutil/time.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/random_seed.h"
#include "libavutil/crc.h"
#include "libavutil/hmac.h"
-#include "libavutil/intreadwrite.h"
-#include "libavutil/lfg.h"
-#include "libavutil/opt.h"
#include "libavutil/mem.h"
-#include "libavutil/random_seed.h"
-#include "libavutil/time.h"
-#include "avc.h"
-#include "nal.h"
+#include "libavutil/base64.h"
+
#include "avio_internal.h"
-#include "http.h"
#include "internal.h"
-#include "mux.h"
#include "network.h"
-#include "rtp.h"
-#include "srtp.h"
-#include "tls.h"
+#include "http.h"
+#include "rtc.h"
/**
* Maximum size limit of a Session Description Protocol (SDP),
@@ -59,16 +48,6 @@
#define DTLS_SRTP_KEY_LEN 16
#define DTLS_SRTP_SALT_LEN 14
-/**
- * The maximum size of the Secure Real-time Transport Protocol (SRTP) HMAC
checksum
- * and padding that is appended to the end of the packet. To calculate the
maximum
- * size of the User Datagram Protocol (UDP) packet that can be sent out,
subtract
- * this size from the `pkt_size`.
- */
-#define DTLS_SRTP_CHECKSUM_LEN 16
-
-#define WHIP_US_PER_MS 1000
-
/**
* If we try to read from UDP and get EAGAIN, we sleep for 5ms and retry up to
10 times.
* This will limit the total duration (in milliseconds, 50ms)
@@ -130,26 +109,6 @@
*/
#define ICE_STUN_HEADER_SIZE 20
-/**
- * The RTP header is 12 bytes long, comprising the Version(1B), PT(1B),
- * SequenceNumber(2B), Timestamp(4B), and SSRC(4B).
- * See https://www.rfc-editor.org/rfc/rfc3550#section-5.1
- */
-#define WHIP_RTP_HEADER_SIZE 12
-
-/**
- * For RTCP, PT is [128, 223] (or without marker [0, 95]). Literally, RTCP
starts
- * from 64 not 0, so PT is [192, 223] (or without marker [64, 95]), see "RTCP
Control
- * Packet Types (PT)" at
- *
https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
- *
- * For RTP, the PT is [96, 127], or [224, 255] with marker. See "RTP Payload
Types (PT)
- * for standard audio and video encodings" at
- *
https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-1
- */
-#define WHIP_RTCP_PT_START 192
-#define WHIP_RTCP_PT_END 223
-
/**
* In the case of ICE-LITE, these fields are not used; instead, they are
defined
* as constant values.
@@ -157,17 +116,6 @@
#define WHIP_SDP_SESSION_ID "4489045141692799359"
#define WHIP_SDP_CREATOR_IP "127.0.0.1"
-/**
- * Refer to RFC 7675 5.1,
- *
- * To prevent expiry of consent, a STUN binding request can be sent
periodically.
- * Implementations SHOULD set a default interval of 5 seconds(5000ms).
- *
- * Consent expires after 30 seconds(3ms).
- */
-#define WHIP_ICE_CONSENT_CHECK_INTERVAL 5000
-#define WHIP_ICE_CONSENT_EXPIRED_TIMER 3
-
/* Calculate the elapsed time from starttime to endtime in milliseconds. */
#define ELAPSED(starttime, endtime) ((float)(endtime - starttime) / 1000)
@@ -181,167 +129,16 @@ enum STUNAttr {
STUN_ATTR_ICE_CONTROLLING = 0x802A, /// ICE controlling role
};
-enum WHIPState {
-WHIP_STATE_NONE,
-
-/* The initial state. */
-WHIP_STATE_INIT,
-/* The muxer has sent the offer to the peer. */
-WHIP_STATE_OFFER,
-/* The muxer h
[FFmpeg-devel] [PATCH 1/3] avformat/whip whep: create rtc for common RTC code shared by whip and whep
---
libavformat/Makefile |2 +-
libavformat/{whip.c => rtc.c} | 856 +---
libavformat/rtc.h | 220 ++
libavformat/whip.c| 1386 +
4 files changed, 264 insertions(+), 2200 deletions(-)
copy libavformat/{whip.c => rtc.c} (59%)
create mode 100644 libavformat/rtc.h
diff --git a/libavformat/Makefile b/libavformat/Makefile
index ed93458f03..9261245755 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -640,7 +640,7 @@ OBJS-$(CONFIG_WEBM_CHUNK_MUXER) += webm_chunk.o
OBJS-$(CONFIG_WEBP_MUXER)+= webpenc.o
OBJS-$(CONFIG_WEBVTT_DEMUXER)+= webvttdec.o subtitles.o
OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o
-OBJS-$(CONFIG_WHIP_MUXER)+= whip.o avc.o http.o srtp.o
+OBJS-$(CONFIG_WHIP_MUXER)+= whip.o rtc.o avc.o http.o srtp.o
OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o
OBJS-$(CONFIG_WSAUD_MUXER) += westwood_audenc.o
OBJS-$(CONFIG_WSD_DEMUXER) += wsddec.o rawdec.o
diff --git a/libavformat/whip.c b/libavformat/rtc.c
similarity index 59%
copy from libavformat/whip.c
copy to libavformat/rtc.c
index e809075643..2dc0383d3e 100644
--- a/libavformat/whip.c
+++ b/libavformat/rtc.c
@@ -1,5 +1,5 @@
/*
- * WebRTC-HTTP ingestion protocol (WHIP) muxer
+ * WebRTC protocol
* Copyright (c) 2023 The FFmpeg Project
*
* This file is part of FFmpeg.
@@ -19,30 +19,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "libavcodec/avcodec.h"
-#include "libavcodec/codec_desc.h"
-#include "libavcodec/h264.h"
-#include "libavcodec/startcode.h"
-#include "libavutil/base64.h"
-#include "libavutil/bprint.h"
+#include "libavutil/time.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/random_seed.h"
#include "libavutil/crc.h"
#include "libavutil/hmac.h"
-#include "libavutil/intreadwrite.h"
-#include "libavutil/lfg.h"
-#include "libavutil/opt.h"
#include "libavutil/mem.h"
-#include "libavutil/random_seed.h"
-#include "libavutil/time.h"
-#include "avc.h"
-#include "nal.h"
+#include "libavutil/base64.h"
+
#include "avio_internal.h"
-#include "http.h"
#include "internal.h"
-#include "mux.h"
#include "network.h"
-#include "rtp.h"
-#include "srtp.h"
-#include "tls.h"
+#include "http.h"
+#include "rtc.h"
/**
* Maximum size limit of a Session Description Protocol (SDP),
@@ -59,16 +48,6 @@
#define DTLS_SRTP_KEY_LEN 16
#define DTLS_SRTP_SALT_LEN 14
-/**
- * The maximum size of the Secure Real-time Transport Protocol (SRTP) HMAC
checksum
- * and padding that is appended to the end of the packet. To calculate the
maximum
- * size of the User Datagram Protocol (UDP) packet that can be sent out,
subtract
- * this size from the `pkt_size`.
- */
-#define DTLS_SRTP_CHECKSUM_LEN 16
-
-#define WHIP_US_PER_MS 1000
-
/**
* If we try to read from UDP and get EAGAIN, we sleep for 5ms and retry up to
10 times.
* This will limit the total duration (in milliseconds, 50ms)
@@ -130,26 +109,6 @@
*/
#define ICE_STUN_HEADER_SIZE 20
-/**
- * The RTP header is 12 bytes long, comprising the Version(1B), PT(1B),
- * SequenceNumber(2B), Timestamp(4B), and SSRC(4B).
- * See https://www.rfc-editor.org/rfc/rfc3550#section-5.1
- */
-#define WHIP_RTP_HEADER_SIZE 12
-
-/**
- * For RTCP, PT is [128, 223] (or without marker [0, 95]). Literally, RTCP
starts
- * from 64 not 0, so PT is [192, 223] (or without marker [64, 95]), see "RTCP
Control
- * Packet Types (PT)" at
- *
https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
- *
- * For RTP, the PT is [96, 127], or [224, 255] with marker. See "RTP Payload
Types (PT)
- * for standard audio and video encodings" at
- *
https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-1
- */
-#define WHIP_RTCP_PT_START 192
-#define WHIP_RTCP_PT_END 223
-
/**
* In the case of ICE-LITE, these fields are not used; instead, they are
defined
* as constant values.
@@ -157,17 +116,6 @@
#define WHIP_SDP_SESSION_ID "4489045141692799359"
#define WHIP_SDP_CREATOR_IP "127.0.0.1"
-/**
- * Refer to RFC 7675 5.1,
- *
- * To prevent expiry of consent, a STUN binding request can be sent
periodically.
- * Implementations SHOULD set a default interval of 5 seconds(5000ms).
- *
- * Consent expires after 30 seconds(3ms).
- */
-#define WHIP_ICE_CONSENT_CHECK_INTERVAL 5000
-#define WHIP_ICE_CONSENT_EXPIRED_TIMER 3
-
/* Calculate the elapsed time from starttime to endtime in milliseconds. */
#define ELAPSED(starttime, endtime) ((float)(endtime - starttime) / 1000)
@@ -181,167 +129,16 @@ enum STUNAttr {
STUN_ATTR_ICE_CONTROLLING = 0x802A, /// ICE controlling role
};
-enum WHIPState {
-WHIP_STATE_NONE,
-
-/* The initial state. */
-WHIP_STATE_INIT,
-/* The muxer has sent the offer to the peer. */
-WHIP_STATE_OFFER,
-/* The muxer h
[FFmpeg-devel] [PATCH 3/3] avformat/whip whep: add whep support
---
libavformat/Makefile | 1 +
libavformat/allformats.c | 1 +
libavformat/rtc.c| 895 +--
libavformat/rtc.h| 38 +-
libavformat/rtpdec.c | 6 +-
libavformat/rtpdec.h | 11 +
libavformat/whep.c | 457
libavformat/whip.c | 52 +--
8 files changed, 1373 insertions(+), 88 deletions(-)
create mode 100644 libavformat/whep.c
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 9261245755..dadc1321b1 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -640,6 +640,7 @@ OBJS-$(CONFIG_WEBM_CHUNK_MUXER) += webm_chunk.o
OBJS-$(CONFIG_WEBP_MUXER)+= webpenc.o
OBJS-$(CONFIG_WEBVTT_DEMUXER)+= webvttdec.o subtitles.o
OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o
+OBJS-$(CONFIG_WHEP_DEMUXER) += whep.o rtc.o avc.o http.o srtp.o
OBJS-$(CONFIG_WHIP_MUXER)+= whip.o rtc.o avc.o http.o srtp.o
OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o
OBJS-$(CONFIG_WSAUD_MUXER) += westwood_audenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 3a025da3db..cd7e3cc4c4 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -518,6 +518,7 @@ extern const FFOutputFormat ff_webp_muxer;
extern const FFInputFormat ff_webvtt_demuxer;
extern const FFOutputFormat ff_webvtt_muxer;
extern const FFInputFormat ff_wsaud_demuxer;
+extern const FFInputFormat ff_whep_demuxer;
extern const FFOutputFormat ff_whip_muxer;
extern const FFOutputFormat ff_wsaud_muxer;
extern const FFInputFormat ff_wsd_demuxer;
diff --git a/libavformat/rtc.c b/libavformat/rtc.c
index 8c848b6026..57da5487b4 100644
--- a/libavformat/rtc.c
+++ b/libavformat/rtc.c
@@ -19,6 +19,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavcodec/avcodec.h"
+#include "libavcodec/codec_desc.h"
+#include "libavcodec/defs.h"
+#include "libavcodec/h264.h"
+#include "libavcodec/h264_levels.h"
#include "libavutil/time.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/random_seed.h"
@@ -26,18 +31,21 @@
#include "libavutil/hmac.h"
#include "libavutil/mem.h"
#include "libavutil/base64.h"
+#include "libavutil/parseutils.h"
#include "avio_internal.h"
#include "internal.h"
#include "network.h"
#include "http.h"
#include "rtc.h"
+#include "rtp.h"
+#include "rtpdec.h"
/**
* Maximum size limit of a Session Description Protocol (SDP),
* be it an offer or answer.
*/
-#define MAX_SDP_SIZE 8192
+#define MAX_SDP_SIZE 16384
/**
* The size of the Secure Real-time Transport Protocol (SRTP) master key
material
@@ -87,20 +95,31 @@
#define DTLS_VERSION_10 0xfeff
#define DTLS_VERSION_12 0xfefd
-/**
- * Maximum size of the buffer for sending and receiving UDP packets.
- * Please note that this size does not limit the size of the UDP packet that
can be sent.
- * To set the limit for packet size, modify the `pkt_size` parameter.
- * For instance, it is possible to set the UDP buffer to 4096 to send or
receive packets,
- * but please keep in mind that the `pkt_size` option limits the packet size
to 1400.
- */
-#define MAX_UDP_BUFFER_SIZE 4096
-
/* Referring to Chrome's definition of RTP payload types. */
#define RTC_RTP_PAYLOAD_TYPE_H264 106
#define RTC_RTP_PAYLOAD_TYPE_OPUS 111
#define RTC_RTP_PAYLOAD_TYPE_VIDEO_RTX 105
+ /**
+ * The RTP header is 12 bytes long, comprising the Version(1B), PT(1B),
+ * SequenceNumber(2B), Timestamp(4B), and SSRC(4B).
+ * See https://www.rfc-editor.org/rfc/rfc3550#section-5.1
+ */
+#define RTC_RTP_HEADER_SIZE 12
+
+/**
+ * For RTCP, PT is [128, 223] (or without marker [0, 95]). Literally, RTCP
starts
+ * from 64 not 0, so PT is [192, 223] (or without marker [64, 95]), see "RTCP
Control
+ * Packet Types (PT)" at
+ *
https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
+ *
+ * For RTP, the PT is [96, 127], or [224, 255] with marker. See "RTP Payload
Types (PT)
+ * for standard audio and video encodings" at
+ *
https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-1
+ */
+#define RTC_RTCP_PT_START 192
+#define RTC_RTCP_PT_END 223
+
/**
* The STUN message header, which is 20 bytes long, comprises the
* STUNMessageType (1B), MessageLength (2B), MagicCookie (4B),
@@ -129,6 +148,33 @@ enum STUNAttr {
STUN_ATTR_ICE_CONTROLLING = 0x802A, /// ICE controlling role
};
+#define OFFSET(x) offsetof(RTCContext, x)
+#define ENC AV_OPT_FLAG_ENCODING_PARAM
+#define DEC AV_OPT_FLAG_DECODING_PARAM
+const AVOption ff_rtc_options[] = {
+{ "handshake_timeout", "Timeout in milliseconds for ICE and DTLS
handshake.", OFFSET(handshake_timeout), AV_OPT_TYPE_INT,{ .i64 = 5000
},-1, INT_MAX, ENC|DEC },
+{ "pkt_size", "The maximum size, in bytes, of RTP packets that
send out", OFFSET(pkt_size), AV_OPT_T
[FFmpeg-devel] [PATCH v3 1/3] avformat/whip whep: create rtc for common RTC code shared by whip and whep
---
libavformat/Makefile |2 +-
libavformat/{whip.c => rtc.c} | 856 +---
libavformat/rtc.h | 220 ++
libavformat/whip.c| 1386 +
4 files changed, 264 insertions(+), 2200 deletions(-)
copy libavformat/{whip.c => rtc.c} (59%)
create mode 100644 libavformat/rtc.h
diff --git a/libavformat/Makefile b/libavformat/Makefile
index ed93458f03..9261245755 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -640,7 +640,7 @@ OBJS-$(CONFIG_WEBM_CHUNK_MUXER) += webm_chunk.o
OBJS-$(CONFIG_WEBP_MUXER)+= webpenc.o
OBJS-$(CONFIG_WEBVTT_DEMUXER)+= webvttdec.o subtitles.o
OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o
-OBJS-$(CONFIG_WHIP_MUXER)+= whip.o avc.o http.o srtp.o
+OBJS-$(CONFIG_WHIP_MUXER)+= whip.o rtc.o avc.o http.o srtp.o
OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o
OBJS-$(CONFIG_WSAUD_MUXER) += westwood_audenc.o
OBJS-$(CONFIG_WSD_DEMUXER) += wsddec.o rawdec.o
diff --git a/libavformat/whip.c b/libavformat/rtc.c
similarity index 59%
copy from libavformat/whip.c
copy to libavformat/rtc.c
index e809075643..2dc0383d3e 100644
--- a/libavformat/whip.c
+++ b/libavformat/rtc.c
@@ -1,5 +1,5 @@
/*
- * WebRTC-HTTP ingestion protocol (WHIP) muxer
+ * WebRTC protocol
* Copyright (c) 2023 The FFmpeg Project
*
* This file is part of FFmpeg.
@@ -19,30 +19,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "libavcodec/avcodec.h"
-#include "libavcodec/codec_desc.h"
-#include "libavcodec/h264.h"
-#include "libavcodec/startcode.h"
-#include "libavutil/base64.h"
-#include "libavutil/bprint.h"
+#include "libavutil/time.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/random_seed.h"
#include "libavutil/crc.h"
#include "libavutil/hmac.h"
-#include "libavutil/intreadwrite.h"
-#include "libavutil/lfg.h"
-#include "libavutil/opt.h"
#include "libavutil/mem.h"
-#include "libavutil/random_seed.h"
-#include "libavutil/time.h"
-#include "avc.h"
-#include "nal.h"
+#include "libavutil/base64.h"
+
#include "avio_internal.h"
-#include "http.h"
#include "internal.h"
-#include "mux.h"
#include "network.h"
-#include "rtp.h"
-#include "srtp.h"
-#include "tls.h"
+#include "http.h"
+#include "rtc.h"
/**
* Maximum size limit of a Session Description Protocol (SDP),
@@ -59,16 +48,6 @@
#define DTLS_SRTP_KEY_LEN 16
#define DTLS_SRTP_SALT_LEN 14
-/**
- * The maximum size of the Secure Real-time Transport Protocol (SRTP) HMAC
checksum
- * and padding that is appended to the end of the packet. To calculate the
maximum
- * size of the User Datagram Protocol (UDP) packet that can be sent out,
subtract
- * this size from the `pkt_size`.
- */
-#define DTLS_SRTP_CHECKSUM_LEN 16
-
-#define WHIP_US_PER_MS 1000
-
/**
* If we try to read from UDP and get EAGAIN, we sleep for 5ms and retry up to
10 times.
* This will limit the total duration (in milliseconds, 50ms)
@@ -130,26 +109,6 @@
*/
#define ICE_STUN_HEADER_SIZE 20
-/**
- * The RTP header is 12 bytes long, comprising the Version(1B), PT(1B),
- * SequenceNumber(2B), Timestamp(4B), and SSRC(4B).
- * See https://www.rfc-editor.org/rfc/rfc3550#section-5.1
- */
-#define WHIP_RTP_HEADER_SIZE 12
-
-/**
- * For RTCP, PT is [128, 223] (or without marker [0, 95]). Literally, RTCP
starts
- * from 64 not 0, so PT is [192, 223] (or without marker [64, 95]), see "RTCP
Control
- * Packet Types (PT)" at
- *
https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
- *
- * For RTP, the PT is [96, 127], or [224, 255] with marker. See "RTP Payload
Types (PT)
- * for standard audio and video encodings" at
- *
https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-1
- */
-#define WHIP_RTCP_PT_START 192
-#define WHIP_RTCP_PT_END 223
-
/**
* In the case of ICE-LITE, these fields are not used; instead, they are
defined
* as constant values.
@@ -157,17 +116,6 @@
#define WHIP_SDP_SESSION_ID "4489045141692799359"
#define WHIP_SDP_CREATOR_IP "127.0.0.1"
-/**
- * Refer to RFC 7675 5.1,
- *
- * To prevent expiry of consent, a STUN binding request can be sent
periodically.
- * Implementations SHOULD set a default interval of 5 seconds(5000ms).
- *
- * Consent expires after 30 seconds(3ms).
- */
-#define WHIP_ICE_CONSENT_CHECK_INTERVAL 5000
-#define WHIP_ICE_CONSENT_EXPIRED_TIMER 3
-
/* Calculate the elapsed time from starttime to endtime in milliseconds. */
#define ELAPSED(starttime, endtime) ((float)(endtime - starttime) / 1000)
@@ -181,167 +129,16 @@ enum STUNAttr {
STUN_ATTR_ICE_CONTROLLING = 0x802A, /// ICE controlling role
};
-enum WHIPState {
-WHIP_STATE_NONE,
-
-/* The initial state. */
-WHIP_STATE_INIT,
-/* The muxer has sent the offer to the peer. */
-WHIP_STATE_OFFER,
-/* The muxer h
[FFmpeg-devel] [PATCH v3 2/3] avformat/whip whep: reanme whip prefix to rtc for common RTC structures
---
libavformat/rtc.c | 564 ++---
libavformat/rtc.h | 60 ++---
libavformat/whip.c | 180 +++
3 files changed, 402 insertions(+), 402 deletions(-)
diff --git a/libavformat/rtc.c b/libavformat/rtc.c
index 2dc0383d3e..8c848b6026 100644
--- a/libavformat/rtc.c
+++ b/libavformat/rtc.c
@@ -97,9 +97,9 @@
#define MAX_UDP_BUFFER_SIZE 4096
/* Referring to Chrome's definition of RTP payload types. */
-#define WHIP_RTP_PAYLOAD_TYPE_H264 106
-#define WHIP_RTP_PAYLOAD_TYPE_OPUS 111
-#define WHIP_RTP_PAYLOAD_TYPE_VIDEO_RTX 105
+#define RTC_RTP_PAYLOAD_TYPE_H264 106
+#define RTC_RTP_PAYLOAD_TYPE_OPUS 111
+#define RTC_RTP_PAYLOAD_TYPE_VIDEO_RTX 105
/**
* The STUN message header, which is 20 bytes long, comprises the
@@ -113,8 +113,8 @@
* In the case of ICE-LITE, these fields are not used; instead, they are
defined
* as constant values.
*/
-#define WHIP_SDP_SESSION_ID "4489045141692799359"
-#define WHIP_SDP_CREATOR_IP "127.0.0.1"
+#define RTC_SDP_SESSION_ID "4489045141692799359"
+#define RTC_SDP_CREATOR_IP "127.0.0.1"
/* Calculate the elapsed time from starttime to endtime in milliseconds. */
#define ELAPSED(starttime, endtime) ((float)(endtime - starttime) / 1000)
@@ -146,23 +146,23 @@ int ff_rtc_is_dtls_packet(uint8_t *b, int size) {
static av_cold int certificate_key_init(AVFormatContext *s)
{
int ret = 0;
-WHIPContext *whip = s->priv_data;
+RTCContext *rtc = s->priv_data;
-if (whip->cert_file && whip->key_file) {
+if (rtc->cert_file && rtc->key_file) {
/* Read the private key and certificate from the file. */
-if ((ret = ff_ssl_read_key_cert(whip->key_file, whip->cert_file,
-whip->key_buf, sizeof(whip->key_buf),
-whip->cert_buf, sizeof(whip->cert_buf),
-&whip->dtls_fingerprint)) < 0) {
+if ((ret = ff_ssl_read_key_cert(rtc->key_file, rtc->cert_file,
+rtc->key_buf, sizeof(rtc->key_buf),
+rtc->cert_buf, sizeof(rtc->cert_buf),
+&rtc->dtls_fingerprint)) < 0) {
av_log(s, AV_LOG_ERROR, "Failed to read DTLS certificate from
cert=%s, key=%s\n",
-whip->cert_file, whip->key_file);
+rtc->cert_file, rtc->key_file);
return ret;
}
} else {
/* Generate a private key to ctx->dtls_pkey and self-signed
certificate. */
-if ((ret = ff_ssl_gen_key_cert(whip->key_buf, sizeof(whip->key_buf),
- whip->cert_buf, sizeof(whip->cert_buf),
- &whip->dtls_fingerprint)) < 0) {
+if ((ret = ff_ssl_gen_key_cert(rtc->key_buf, sizeof(rtc->key_buf),
+ rtc->cert_buf, sizeof(rtc->cert_buf),
+ &rtc->dtls_fingerprint)) < 0) {
av_log(s, AV_LOG_ERROR, "Failed to generate DTLS private key and
certificate\n");
return ret;
}
@@ -173,13 +173,13 @@ static av_cold int certificate_key_init(AVFormatContext
*s)
static av_cold int dtls_initialize(AVFormatContext *s)
{
-WHIPContext *whip = s->priv_data;
-/* reuse the udp created by whip */
-ff_tls_set_external_socket(whip->dtls_uc, whip->udp);
+RTCContext *rtc = s->priv_data;
+/* reuse the udp created by rtc */
+ff_tls_set_external_socket(rtc->dtls_uc, rtc->udp);
/* Make the socket non-blocking */
-ff_socket_nonblock(ffurl_get_file_handle(whip->dtls_uc), 1);
-whip->dtls_uc->flags |= AVIO_FLAG_NONBLOCK;
+ff_socket_nonblock(ffurl_get_file_handle(rtc->dtls_uc), 1);
+rtc->dtls_uc->flags |= AVIO_FLAG_NONBLOCK;
return 0;
}
@@ -190,40 +190,40 @@ static av_cold int dtls_initialize(AVFormatContext *s)
av_cold int ff_rtc_initialize(AVFormatContext *s)
{
int ret, ideal_pkt_size = 532;
-WHIPContext *whip = s->priv_data;
+RTCContext *rtc = s->priv_data;
uint32_t seed;
-whip->whip_starttime = av_gettime_relative();
+rtc->rtc_starttime = av_gettime_relative();
ret = certificate_key_init(s);
if (ret < 0) {
-av_log(whip, AV_LOG_ERROR, "Failed to init certificate and key\n");
+av_log(rtc, AV_LOG_ERROR, "Failed to init certificate and key\n");
return ret;
}
/* Initialize the random number generator. */
seed = av_get_random_seed();
-av_lfg_init(&whip->rnd, seed);
+av_lfg_init(&rtc->rnd, seed);
/* 64 bit tie breaker for ICE-CONTROLLING (RFC 8445 16.1) */
-ret = av_random_bytes((uint8_t *)&whip->ice_tie_breaker,
sizeof(whip->ice_tie_breaker));
+ret = av_random_bytes((uint8_t *)&rtc->ice_tie_breaker,
sizeof(rtc->ice_tie_breaker));
if (ret < 0) {
-av_log(whip, AV_LOG_ERROR, "Couldn't generate random bytes for ICE tie
breaker\n
[FFmpeg-devel] [PATCH v3 3/3] avformat/whip whep: add whep support
---
configure| 1 +
libavformat/Makefile | 1 +
libavformat/allformats.c | 1 +
libavformat/rtc.c| 895 +--
libavformat/rtc.h| 38 +-
libavformat/rtpdec.c | 6 +-
libavformat/rtpdec.h | 11 +
libavformat/whep.c | 457
libavformat/whip.c | 52 +--
9 files changed, 1374 insertions(+), 88 deletions(-)
create mode 100644 libavformat/whep.c
diff --git a/configure b/configure
index 7828381b5d..544daf4079 100755
--- a/configure
+++ b/configure
@@ -3836,6 +3836,7 @@ wav_demuxer_select="riffdec"
wav_muxer_select="riffenc"
webm_chunk_muxer_select="webm_muxer"
webm_dash_manifest_demuxer_select="matroska_demuxer"
+whep_demuxer_deps_any="dtls_protocol"
whip_muxer_deps_any="dtls_protocol"
wtv_demuxer_select="mpegts_demuxer riffdec"
wtv_muxer_select="mpegts_muxer riffenc"
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 9261245755..dadc1321b1 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -640,6 +640,7 @@ OBJS-$(CONFIG_WEBM_CHUNK_MUXER) += webm_chunk.o
OBJS-$(CONFIG_WEBP_MUXER)+= webpenc.o
OBJS-$(CONFIG_WEBVTT_DEMUXER)+= webvttdec.o subtitles.o
OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o
+OBJS-$(CONFIG_WHEP_DEMUXER) += whep.o rtc.o avc.o http.o srtp.o
OBJS-$(CONFIG_WHIP_MUXER)+= whip.o rtc.o avc.o http.o srtp.o
OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o
OBJS-$(CONFIG_WSAUD_MUXER) += westwood_audenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 3a025da3db..cd7e3cc4c4 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -518,6 +518,7 @@ extern const FFOutputFormat ff_webp_muxer;
extern const FFInputFormat ff_webvtt_demuxer;
extern const FFOutputFormat ff_webvtt_muxer;
extern const FFInputFormat ff_wsaud_demuxer;
+extern const FFInputFormat ff_whep_demuxer;
extern const FFOutputFormat ff_whip_muxer;
extern const FFOutputFormat ff_wsaud_muxer;
extern const FFInputFormat ff_wsd_demuxer;
diff --git a/libavformat/rtc.c b/libavformat/rtc.c
index 8c848b6026..57da5487b4 100644
--- a/libavformat/rtc.c
+++ b/libavformat/rtc.c
@@ -19,6 +19,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavcodec/avcodec.h"
+#include "libavcodec/codec_desc.h"
+#include "libavcodec/defs.h"
+#include "libavcodec/h264.h"
+#include "libavcodec/h264_levels.h"
#include "libavutil/time.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/random_seed.h"
@@ -26,18 +31,21 @@
#include "libavutil/hmac.h"
#include "libavutil/mem.h"
#include "libavutil/base64.h"
+#include "libavutil/parseutils.h"
#include "avio_internal.h"
#include "internal.h"
#include "network.h"
#include "http.h"
#include "rtc.h"
+#include "rtp.h"
+#include "rtpdec.h"
/**
* Maximum size limit of a Session Description Protocol (SDP),
* be it an offer or answer.
*/
-#define MAX_SDP_SIZE 8192
+#define MAX_SDP_SIZE 16384
/**
* The size of the Secure Real-time Transport Protocol (SRTP) master key
material
@@ -87,20 +95,31 @@
#define DTLS_VERSION_10 0xfeff
#define DTLS_VERSION_12 0xfefd
-/**
- * Maximum size of the buffer for sending and receiving UDP packets.
- * Please note that this size does not limit the size of the UDP packet that
can be sent.
- * To set the limit for packet size, modify the `pkt_size` parameter.
- * For instance, it is possible to set the UDP buffer to 4096 to send or
receive packets,
- * but please keep in mind that the `pkt_size` option limits the packet size
to 1400.
- */
-#define MAX_UDP_BUFFER_SIZE 4096
-
/* Referring to Chrome's definition of RTP payload types. */
#define RTC_RTP_PAYLOAD_TYPE_H264 106
#define RTC_RTP_PAYLOAD_TYPE_OPUS 111
#define RTC_RTP_PAYLOAD_TYPE_VIDEO_RTX 105
+ /**
+ * The RTP header is 12 bytes long, comprising the Version(1B), PT(1B),
+ * SequenceNumber(2B), Timestamp(4B), and SSRC(4B).
+ * See https://www.rfc-editor.org/rfc/rfc3550#section-5.1
+ */
+#define RTC_RTP_HEADER_SIZE 12
+
+/**
+ * For RTCP, PT is [128, 223] (or without marker [0, 95]). Literally, RTCP
starts
+ * from 64 not 0, so PT is [192, 223] (or without marker [64, 95]), see "RTCP
Control
+ * Packet Types (PT)" at
+ *
https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
+ *
+ * For RTP, the PT is [96, 127], or [224, 255] with marker. See "RTP Payload
Types (PT)
+ * for standard audio and video encodings" at
+ *
https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-1
+ */
+#define RTC_RTCP_PT_START 192
+#define RTC_RTCP_PT_END 223
+
/**
* The STUN message header, which is 20 bytes long, comprises the
* STUNMessageType (1B), MessageLength (2B), MagicCookie (4B),
@@ -129,6 +148,33 @@ enum STUNAttr {
STUN_ATTR_ICE_CONTROLLING = 0x802A, /// ICE controlling role
};
