FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/fifo.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "libavutil/log.h"
#include "libavutil/time.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 UDPLITE_SEND_CSCOV   10
 
#define UDPLITE_RECV_CSCOV   11
 
#define IPPROTO_UDPLITE   136
 
#define HAVE_PTHREAD_CANCEL   0
 
#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 UDP_HEADER_SIZE   8
 
#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, struct sockaddr *local_addr)
 
static int udp_leave_multicast_group (int sockfd, struct sockaddr *addr, struct sockaddr *local_addr)
 
static struct addrinfoudp_resolve_host (const char *hostname, int port, int type, int family, int flags)
 
static int udp_set_multicast_sources (int sockfd, struct sockaddr *addr, int addr_len, char **sources, int nb_sources, int include)
 
static int udp_set_url (struct sockaddr_storage *addr, const char *hostname, int port)
 
static int udp_socket_create (UDPContext *s, 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.
 
int ff_udp_get_local_port (URLContext *h)
 Return the local port used by the UDP connection.
 
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.
 
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 udplite_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_context_class
 
static const AVClass udplite_context_class
 
URLProtocol ff_udp_protocol
 
URLProtocol ff_udplite_protocol
 

Detailed Description

UDP protocol.

Definition in file udp.c.

Macro Definition Documentation

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

Definition at line 27 of file udp.c.

#define UDPLITE_SEND_CSCOV   10

Definition at line 49 of file udp.c.

Referenced by udp_open().

#define UDPLITE_RECV_CSCOV   11

Definition at line 50 of file udp.c.

Referenced by udp_open().

#define IPPROTO_UDPLITE   136

Definition at line 54 of file udp.c.

Referenced by udp_open(), and udp_socket_create().

#define HAVE_PTHREAD_CANCEL   0

Definition at line 62 of file udp.c.

Referenced by udp_open().

#define IPV6_ADD_MEMBERSHIP   IPV6_JOIN_GROUP

Definition at line 66 of file udp.c.

Referenced by udp_join_multicast_group().

#define IPV6_DROP_MEMBERSHIP   IPV6_LEAVE_GROUP

Definition at line 67 of file udp.c.

Referenced by udp_leave_multicast_group().

#define UDP_TX_BUF_SIZE   32768

Definition at line 70 of file udp.c.

Referenced by udp_open().

#define UDP_MAX_PKT_SIZE   65536

Definition at line 71 of file udp.c.

Referenced by udp_open().

#define UDP_HEADER_SIZE   8

Definition at line 72 of file udp.c.

Referenced by udplite_open().

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

Definition at line 107 of file udp.c.

Definition at line 108 of file udp.c.

Definition at line 109 of file udp.c.

Function Documentation

static void log_net_error ( void ctx,
int  level,
const char *  prefix 
)
static
static int udp_set_multicast_ttl ( int  sockfd,
int  mcastTTL,
struct sockaddr *  addr 
)
static

Definition at line 148 of file udp.c.

Referenced by udp_open().

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

Definition at line 170 of file udp.c.

Referenced by udp_open().

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

Definition at line 202 of file udp.c.

Referenced by udp_close().

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

Definition at line 234 of file udp.c.

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

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

Definition at line 260 of file udp.c.

Referenced by udp_open().

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

Definition at line 333 of file udp.c.

Referenced by ff_udp_set_remote_url().

static int udp_socket_create ( UDPContext s,
struct sockaddr_storage addr,
socklen_t *  addr_len,
const char *  localaddr 
)
static

Definition at line 348 of file udp.c.

Referenced by udp_open().

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

Definition at line 388 of file udp.c.

Referenced by udp_open().

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 'overrun_nonfatal=1': survive in case of circular buffer overrun

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

Definition at line 418 of file udp.c.

Referenced by ff_rtp_set_remote_url(), and udp_open().

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 457 of file udp.c.

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

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 468 of file udp.c.

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

Definition at line 533 of file udp.c.

Referenced by udp_open().

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

Definition at line 556 of file udp.c.

Referenced by udplite_open().

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

Definition at line 834 of file udp.c.

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

Definition at line 844 of file udp.c.

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

Definition at line 903 of file udp.c.

static int udp_close ( URLContext h)
static

Definition at line 924 of file udp.c.

Variable Documentation

const AVOption options[]
static
Initial value:
= {
{"buffer_size", "set packet buffer size in bytes", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, D|E },
{"localport", "set local port to bind to", OFFSET(local_port), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, D|E },
{"localaddr", "choose local IP address", OFFSET(local_addr), AV_OPT_TYPE_STRING, {.str = ""}, 0, 0, D|E },
{"udplite_coverage", "choose UDPLite head size which should be validated by checksum", OFFSET(udplite_coverage), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, D|E },
{"pkt_size", "set size of UDP packets", OFFSET(packet_size), AV_OPT_TYPE_INT, {.i64 = 1472}, 0, INT_MAX, D|E },
{"reuse", "explicitly allow or disallow reusing UDP sockets", OFFSET(reuse_socket), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D|E },
{"broadcast", "explicitly allow or disallow broadcast destination", OFFSET(is_broadcast), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, E },
{"ttl", "set the time to live value (for multicast only)", OFFSET(ttl), AV_OPT_TYPE_INT, {.i64 = 16}, 0, INT_MAX, E },
{"connect", "set if connect() should be called on socket", OFFSET(is_connected), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D|E },
{"fifo_size", "set the UDP receiving circular buffer size, expressed as a number of packets with size of 188 bytes", OFFSET(circular_buffer_size), AV_OPT_TYPE_INT, {.i64 = 7*4096}, 0, INT_MAX, D },
{"overrun_nonfatal", "survive in case of UDP receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D },
{"timeout", "set raise error timeout (only in read mode)", OFFSET(timeout), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, D },
}

Definition at line 110 of file udp.c.

const AVClass udp_context_class
static
Initial value:
= {
.class_name = "udp",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 127 of file udp.c.

const AVClass udplite_context_class
static
Initial value:
= {
.class_name = "udplite",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 134 of file udp.c.

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_context_class,
}

Definition at line 946 of file udp.c.

URLProtocol ff_udplite_protocol
Initial value:
= {
.name = "udplite",
.url_open = udplite_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 = &udplite_context_class,
}

Definition at line 958 of file udp.c.