Libav
Data Structures | Macros | Functions | Variables
udp.c File Reference

UDP protocol. More...

#include "avformat.h"
#include "avio_internal.h"
#include "libavutil/parseutils.h"
#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "internal.h"
#include "network.h"
#include "os_support.h"
#include "url.h"

Go to the source code of this file.

Data Structures

struct  UDPContext
 

Macros

#define _BSD_SOURCE   /* Needed for using struct ip_mreq with recent glibc */
 
#define IPV6_ADD_MEMBERSHIP   IPV6_JOIN_GROUP
 
#define IPV6_DROP_MEMBERSHIP   IPV6_LEAVE_GROUP
 
#define UDP_TX_BUF_SIZE   32768
 
#define UDP_MAX_PKT_SIZE   65536
 
#define OFFSET(x)   offsetof(UDPContext, x)
 
#define D   AV_OPT_FLAG_DECODING_PARAM
 
#define E   AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static void log_net_error (void *ctx, int level, const char *prefix)
 
static int udp_set_multicast_ttl (int sockfd, int mcastTTL, struct sockaddr *addr)
 
static int udp_join_multicast_group (int sockfd, struct sockaddr *addr)
 
static int udp_leave_multicast_group (int sockfd, struct sockaddr *addr)
 
static struct addrinfoudp_resolve_host (URLContext *h, const char *hostname, int port, int type, int family, int flags)
 
static int udp_set_multicast_sources (URLContext *h, int sockfd, struct sockaddr *addr, int addr_len, char **sources, int nb_sources, int include)
 
static int udp_set_url (URLContext *h, struct sockaddr_storage *addr, const char *hostname, int port)
 
static int udp_socket_create (URLContext *h, struct sockaddr_storage *addr, socklen_t *addr_len, const char *localaddr)
 
static int udp_port (struct sockaddr_storage *addr, int addr_len)
 
int ff_udp_set_remote_url (URLContext *h, const char *uri)
 If no filename is given to av_open_input_file because you want to get the local port first, then you must call this function to set the remote server address. More...
 
int ff_udp_get_local_port (URLContext *h)
 Return the local port used by the UDP connection. More...
 
static int udp_get_file_handle (URLContext *h)
 Return the udp file handle for select() usage to wait for several RTP streams at the same time. More...
 
static int parse_source_list (char *buf, char **sources, int *num_sources, int max_sources)
 
static int udp_open (URLContext *h, const char *uri, int flags)
 
static int udp_read (URLContext *h, uint8_t *buf, int size)
 
static int udp_write (URLContext *h, const uint8_t *buf, int size)
 
static int udp_close (URLContext *h)
 

Variables

static const AVOption options []
 
static const AVClass udp_class
 
const URLProtocol ff_udp_protocol
 

Detailed Description

UDP protocol.

Definition in file udp.c.

Macro Definition Documentation

◆ _BSD_SOURCE

#define _BSD_SOURCE   /* Needed for using struct ip_mreq with recent glibc */

Definition at line 27 of file udp.c.

◆ IPV6_ADD_MEMBERSHIP

#define IPV6_ADD_MEMBERSHIP   IPV6_JOIN_GROUP

Definition at line 40 of file udp.c.

Referenced by udp_join_multicast_group().

◆ IPV6_DROP_MEMBERSHIP

#define IPV6_DROP_MEMBERSHIP   IPV6_LEAVE_GROUP

Definition at line 41 of file udp.c.

Referenced by udp_leave_multicast_group().

◆ UDP_TX_BUF_SIZE

#define UDP_TX_BUF_SIZE   32768

Definition at line 61 of file udp.c.

Referenced by udp_open().

◆ UDP_MAX_PKT_SIZE

#define UDP_MAX_PKT_SIZE   65536

Definition at line 62 of file udp.c.

Referenced by udp_open().

◆ OFFSET

#define OFFSET (   x)    offsetof(UDPContext, x)

Definition at line 64 of file udp.c.

◆ D

Definition at line 65 of file udp.c.

◆ E

Definition at line 66 of file udp.c.

Function Documentation

◆ log_net_error()

static void log_net_error ( void ctx,
int  level,
const char *  prefix 
)
static

◆ udp_set_multicast_ttl()

static int udp_set_multicast_ttl ( int  sockfd,
int  mcastTTL,
struct sockaddr *  addr 
)
static

Definition at line 94 of file udp.c.

Referenced by udp_open().

◆ udp_join_multicast_group()

static int udp_join_multicast_group ( int  sockfd,
struct sockaddr *  addr 
)
static

Definition at line 116 of file udp.c.

Referenced by udp_open().

◆ udp_leave_multicast_group()

static int udp_leave_multicast_group ( int  sockfd,
struct sockaddr *  addr 
)
static

Definition at line 145 of file udp.c.

Referenced by udp_close().

◆ udp_resolve_host()

static struct addrinfo* udp_resolve_host ( URLContext h,
const char *  hostname,
int  port,
int  type,
int  family,
int  flags 
)
static

Definition at line 174 of file udp.c.

Referenced by udp_set_multicast_sources(), udp_set_url(), and udp_socket_create().

◆ udp_set_multicast_sources()

static int udp_set_multicast_sources ( URLContext h,
int  sockfd,
struct sockaddr *  addr,
int  addr_len,
char **  sources,
int  nb_sources,
int  include 
)
static

Definition at line 204 of file udp.c.

Referenced by udp_open().

◆ udp_set_url()

static int udp_set_url ( URLContext h,
struct sockaddr_storage addr,
const char *  hostname,
int  port 
)
static

Definition at line 278 of file udp.c.

Referenced by ff_udp_set_remote_url().

◆ udp_socket_create()

static int udp_socket_create ( URLContext h,
struct sockaddr_storage addr,
socklen_t *  addr_len,
const char *  localaddr 
)
static

Definition at line 294 of file udp.c.

Referenced by udp_open().

◆ udp_port()

static int udp_port ( struct sockaddr_storage addr,
int  addr_len 
)
static

Definition at line 333 of file udp.c.

Referenced by udp_open().

◆ ff_udp_set_remote_url()

int ff_udp_set_remote_url ( URLContext h,
const char *  uri 
)

If no filename is given to av_open_input_file because you want to get the local port first, then you must call this function to set the remote server address.

url syntax: udp://host:port[?option=val...] option: 'ttl=n' : set the ttl value (for multicast only) 'localport=n' : set the local port 'pkt_size=n' : set max packet size 'reuse=1' : enable reusing the socket

Parameters
hmedia file context
uriof the remote server
Returns
zero if no error.

Definition at line 362 of file udp.c.

Referenced by ff_rtp_set_remote_url(), and udp_open().

◆ ff_udp_get_local_port()

int ff_udp_get_local_port ( URLContext h)

Return the local port used by the UDP connection.

Parameters
hmedia file context
Returns
the local port number

Definition at line 401 of file udp.c.

Referenced by ff_rtp_get_local_rtcp_port(), ff_rtp_get_local_rtp_port(), and rtp_open().

◆ udp_get_file_handle()

static int udp_get_file_handle ( URLContext h)
static

Return the udp file handle for select() usage to wait for several RTP streams at the same time.

Parameters
hmedia file context

Definition at line 412 of file udp.c.

◆ parse_source_list()

static int parse_source_list ( char *  buf,
char **  sources,
int *  num_sources,
int  max_sources 
)
static

Definition at line 418 of file udp.c.

Referenced by udp_open().

◆ udp_open()

static int udp_open ( URLContext h,
const char *  uri,
int  flags 
)
static

Definition at line 441 of file udp.c.

◆ udp_read()

static int udp_read ( URLContext h,
uint8_t buf,
int  size 
)
static

Definition at line 643 of file udp.c.

◆ udp_write()

static int udp_write ( URLContext h,
const uint8_t buf,
int  size 
)
static

Definition at line 657 of file udp.c.

◆ udp_close()

static int udp_close ( URLContext h)
static

Definition at line 678 of file udp.c.

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{ "ttl", "Time to live (in milliseconds, multicast only)", OFFSET(ttl), AV_OPT_TYPE_INT, { .i64 = 16 }, 0, INT_MAX, .flags = D|E },
{ "buffer_size", "System data size (in bytes)", OFFSET(buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
{ "local_port", "Local port", OFFSET(local_port), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
{ "reuse_socket", "Reuse socket", OFFSET(reuse_socket), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, .flags = D|E },
{ "connect", "Connect socket", OFFSET(is_connected), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = D|E },
{ "pkt_size", "Maximum packet size", OFFSET(pkt_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
{ "localaddr", "Local address", OFFSET(localaddr), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E },
{ "sources", "Source list", OFFSET(sources), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E },
{ "block", "Block list", OFFSET(block), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E },
{ NULL }
}
static int16_t block[64]
Definition: dct.c:97
#define E
Definition: udp.c:66
#define D
Definition: udp.c:65
#define OFFSET(x)
Definition: udp.c:64
NULL
Definition: eval.c:55

Definition at line 67 of file udp.c.

◆ udp_class

const AVClass udp_class
static
Initial value:
= {
.class_name = "udp",
.item_name = av_default_item_name,
.option = options,
}
static const AVOption options[]
Definition: udp.c:67
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
av_default_item_name
Definition: dnxhdenc.c:55

Definition at line 80 of file udp.c.

◆ ff_udp_protocol

const URLProtocol ff_udp_protocol
Initial value:
= {
.name = "udp",
.url_open = udp_open,
.url_read = udp_read,
.url_write = udp_write,
.url_close = udp_close,
.url_get_file_handle = udp_get_file_handle,
.priv_data_size = sizeof(UDPContext),
.priv_data_class = &udp_class,
}
static int udp_open(URLContext *h, const char *uri, int flags)
Definition: udp.c:441
#define URL_PROTOCOL_FLAG_NETWORK
Definition: url.h:34
static int flags
Definition: log.c:50
static int udp_close(URLContext *h)
Definition: udp.c:678
static int udp_get_file_handle(URLContext *h)
Return the udp file handle for select() usage to wait for several RTP streams at the same time...
Definition: udp.c:412
Definition: udp.c:44
static int udp_read(URLContext *h, uint8_t *buf, int size)
Definition: udp.c:643
static const AVClass udp_class
Definition: udp.c:80
static int udp_write(URLContext *h, const uint8_t *buf, int size)
Definition: udp.c:657

Definition at line 688 of file udp.c.