FFmpeg Merges WebRTC Support

4 months ago 32
11

/*

2-

* TLS/SSL Protocol

2+

* TLS/DTLS/SSL Protocol

33

* Copyright (c) 2011 Martin Storsjo

4+

* Copyright (c) 2025 Jack Lau

45

*

56

* This file is part of FFmpeg.

67

*

@@ -22,10 +23,27 @@

2223

#ifndef AVFORMAT_TLS_H

2324

#define AVFORMAT_TLS_H

242526+

#include "libavutil/bprint.h"

2527

#include "libavutil/opt.h"

26282729

#include "url.h"

283031+

/**

32+

* Maximum size limit of a certificate and private key size.

33+

*/

34+

#define MAX_CERTIFICATE_SIZE 8192

35+36+

enum DTLSState {

37+

DTLS_STATE_NONE,

38+39+

/* Whether DTLS handshake is finished. */

40+

DTLS_STATE_FINISHED,

41+

/* Whether DTLS session is closed. */

42+

DTLS_STATE_CLOSED,

43+

/* Whether DTLS handshake is failed. */

44+

DTLS_STATE_FAILED,

45+

};

46+2947

typedef struct TLSShared {

3048

char *ca_file;

3149

int verify;

@@ -40,6 +58,25 @@ typedef struct TLSShared {

4058

int numerichost;

41594260

URLContext *tcp;

61+62+

int is_dtls;

63+64+

enum DTLSState state;

65+66+

int use_external_udp;

67+

URLContext *udp;

68+69+

/* The fingerprint of certificate, used in SDP offer. */

70+

char *fingerprint;

71+72+

/* The certificate and private key content used for DTLS handshake */

73+

char* cert_buf;

74+

char* key_buf;

75+

/**

76+

* The size of RTP packet, should generally be set to MTU.

77+

* Note that pion requires a smaller value, for example, 1200.

78+

*/

79+

int mtu;

4380

} TLSShared;

44814582

#define TLS_OPTFL (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM)

@@ -51,10 +88,27 @@ typedef struct TLSShared {

5188

{"key_file", "Private key file", offsetof(pstruct, options_field . key_file), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \

5289

{"listen", "Listen for incoming connections", offsetof(pstruct, options_field . listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \

5390

{"verifyhost", "Verify against a specific hostname", offsetof(pstruct, options_field . host), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \

54-

{"http_proxy", "Set proxy to tunnel through", offsetof(pstruct, options_field . http_proxy), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }

91+

{"http_proxy", "Set proxy to tunnel through", offsetof(pstruct, options_field . http_proxy), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \

92+

{"use_external_udp", "Use external UDP from muxer or demuxer", offsetof(pstruct, options_field . use_external_udp), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 1, .flags = TLS_OPTFL }, \

93+

{"mtu", "Maximum Transmission Unit", offsetof(pstruct, options_field . mtu), AV_OPT_TYPE_INT, { .i64 = 0}, INT64_MIN, INT64_MAX, .flags = TLS_OPTFL}, \

94+

{"fingerprint", "The optional fingerprint for DTLS", offsetof(pstruct, options_field . fingerprint), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL}, \

95+

{"cert_buf", "The optional certificate buffer for DTLS", offsetof(pstruct, options_field . cert_buf), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL}, \

96+

{"key_buf", "The optional private key buffer for DTLS", offsetof(pstruct, options_field . key_buf), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL}

55975698

int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options);

5799100+

int ff_url_read_all(const char *url, AVBPrint *bp);

101+102+

int ff_dtls_set_udp(URLContext *h, URLContext *udp);

103+104+

int ff_dtls_export_materials(URLContext *h, char *dtls_srtp_materials, size_t materials_sz);

105+106+

int ff_dtls_state(URLContext *h);

107+108+

int ff_ssl_read_key_cert(char *key_url, char *cert_url, char *key_buf, size_t key_sz, char *cert_buf, size_t cert_sz, char **fingerprint);

109+110+

int ff_ssl_gen_key_cert(char *key_buf, size_t key_sz, char *cert_buf, size_t cert_sz, char **fingerprint);

111+58112

void ff_gnutls_init(void);

59113

void ff_gnutls_deinit(void);

60114
Read Entire Article