/*
- * UDP prototype streaming system
+ * FRSH prototype streaming system
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
* This file is part of FFmpeg.
*/
/**
- * @file libavformat/udp.c
- * UDP protocol
+ * @file libavformat/frsh.c
+ * FRSH protocol
*/
#include "avformat.h"
#include <frsh.h>
#include <frsh_core_types.h>
-long int udp_budget, udp_period;
+long int avformat_frsh_budget, avformat_frsh_period;
typedef struct {
- int udp_fd;
+ int frsh_fd;
int ttl;
int buffer_size;
int is_multicast;
frsh_contract_t contract;
frsh_contract_label_t label;
frsh_rel_time_t budget, period;
-} UDPContext;
+} FRSHContext;
-#define UDP_TX_BUF_SIZE 32768
-#define UDP_MAX_PKT_SIZE 65536
+#define FRSH_TX_BUF_SIZE 32768
+#define FRSH_MAX_PKT_SIZE 65536
-static int udp_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr)
+static int frsh_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr)
{
return 0;
}
-static int udp_join_multicast_group(int sockfd, struct sockaddr *addr)
+static int frsh_join_multicast_group(int sockfd, struct sockaddr *addr)
{
return 0;
}
-static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr)
+static int frsh_leave_multicast_group(int sockfd, struct sockaddr *addr)
{
return 0;
}
-static int udp_set_url(struct sockaddr_in *addr, const char *hostname, int port)
+static int frsh_set_url(struct sockaddr_in *addr, const char *hostname, int port)
{
/* set the destination address */
if (resolve_host(&addr->sin_addr, hostname) < 0)
}
static int
-udp_socket_create(UDPContext *s, struct sockaddr_in *addr, int *addr_len)
+frsh_socket_create(FRSHContext *s, struct sockaddr_in *addr, int *addr_len)
{
static long int netcont_num = 0;
- int ret,udp_fd;
+ int ret,frsh_fd;
char netcont_name[20];
addr->sin_family = AF_INET;
*addr_len = sizeof(struct sockaddr_in);
/* set params for contract */
- frsh_network_bytes_to_budget(FRSH_NETPF_FWP, udp_budget, &s->budget);
- s->period = fosa_msec_to_rel_time(udp_period);
+ frsh_network_bytes_to_budget(FRSH_NETPF_FWP, avformat_frsh_budget, &s->budget);
+ s->period = fosa_msec_to_rel_time(avformat_frsh_period);
s->send_pinfo.body = NULL;
- udp_fd = frsh_send_endpoint_create(FRSH_NETPF_FWP,
+ frsh_fd = frsh_send_endpoint_create(FRSH_NETPF_FWP,
s->dest_addr.sin_addr.s_addr,
ntohs(s->dest_addr.sin_port), s->send_pinfo,
&s->sepoint);
- if (udp_fd < 0) {
+ if (frsh_fd < 0) {
return -1;
}
//fwp_endpoint_get_params(s->sepoint->protocol_info.body, &node,
// &port, &attr, &fd);
- return udp_fd;
+ return frsh_fd;
}
-static int udp_port(struct sockaddr_in *addr, int len)
+static int frsh_port(struct sockaddr_in *addr, int len)
{
return ntohs(addr->sin_port);
}
* get the local port first, then you must call this function to set
* the remote server address.
*
- * url syntax: udp://host:port[?option=val...]
+ * url syntax: frsh://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
* @param uri of the remote server
* @return zero if no error.
*/
-int udp_set_remote_url(URLContext *h, const char *uri)
+int frsh_set_remote_url(URLContext *h, const char *uri)
{
- UDPContext *s = h->priv_data;
+ FRSHContext *s = h->priv_data;
char hostname[256];
int port;
url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
/* set the destination address */
- s->dest_addr_len = udp_set_url(&s->dest_addr, hostname, port);
+ s->dest_addr_len = frsh_set_url(&s->dest_addr, hostname, port);
if (s->dest_addr_len < 0) {
return AVERROR(EIO);
}
}
/**
- * Return the local port used by the UDP connexion
+ * Return the local port used by the FRSH connexion
* @param s1 media file context
* @return the local port number
*/
-int udp_get_local_port(URLContext *h)
+int frsh_get_local_port(URLContext *h)
{
- UDPContext *s = h->priv_data;
+ FRSHContext *s = h->priv_data;
return s->local_port;
}
/**
- * Return the udp file handle for select() usage to wait for several RTP
+ * Return the frsh file handle for select() usage to wait for several RTP
* streams at the same time.
* @param h media file context
*/
#if (LIBAVFORMAT_VERSION_MAJOR >= 53)
static
#endif
-int udp_get_file_handle(URLContext *h)
+int frsh_get_file_handle(URLContext *h)
{
- UDPContext *s = h->priv_data;
- return s->udp_fd;
+ FRSHContext *s = h->priv_data;
+ return s->frsh_fd;
}
-/* put it in UDP context */
+/* put it in FRSH context */
/* return non zero if error */
-static int udp_open(URLContext *h, const char *uri, int flags)
+static int frsh_open(URLContext *h, const char *uri, int flags)
{
char hostname[1024];
- int port, udp_fd = -1, tmp;
- UDPContext *s = NULL;
+ int port, frsh_fd = -1, tmp;
+ FRSHContext *s = NULL;
int is_output;
const char *p;
char buf[256];
if(!ff_network_init())
return AVERROR(EIO);
- s = av_mallocz(sizeof(UDPContext));
+ s = av_mallocz(sizeof(FRSHContext));
if (!s)
return AVERROR(ENOMEM);
h->priv_data = s;
s->ttl = 16;
- s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE;
+ s->buffer_size = is_output ? FRSH_TX_BUF_SIZE : FRSH_MAX_PKT_SIZE;
p = strchr(uri, '?');
if (p) {
if (flags & URL_WRONLY)
goto fail;
} else {
- udp_set_remote_url(h, uri);
+ frsh_set_remote_url(h, uri);
}
- udp_fd = udp_socket_create(s, &my_addr, &len);
- if (udp_fd < 0)
+ frsh_fd = frsh_socket_create(s, &my_addr, &len);
+ if (frsh_fd < 0)
goto fail;
#if 0
if (s->reuse_socket)
- if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)
+ if (setsockopt (frsh_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)
goto fail;
/* bind to the local address if not multicast or if the multicast
* bind failed */
- /*if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0)
+ /*if (bind_ret < 0 && bind(frsh_fd,(struct sockaddr *)&my_addr, len) < 0)
goto fail;*/
#endif
len = sizeof(my_addr);
- getsockname(udp_fd, (struct sockaddr *)&my_addr, &len);
- s->local_port = udp_port(&my_addr, len);
+ getsockname(frsh_fd, (struct sockaddr *)&my_addr, &len);
+ s->local_port = frsh_port(&my_addr, len);
if (is_output) {
/* limit the tx buf size to limit latency */
tmp = s->buffer_size;
- if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) {
+ if (setsockopt(frsh_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) {
av_log(NULL, AV_LOG_ERROR, "setsockopt(SO_SNDBUF): %s\n", strerror(errno));
goto fail;
}
} else {
- /* set udp recv buffer size to the largest possible udp packet size to
+ /* set frsh recv buffer size to the largest possible frsh packet size to
* avoid losing data on OSes that set this too low by default. */
tmp = s->buffer_size;
- if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) {
+ if (setsockopt(frsh_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) {
av_log(NULL, AV_LOG_WARNING, "setsockopt(SO_RECVBUF): %s\n", strerror(errno));
}
/* make the socket non-blocking */
- ff_socket_nonblock(udp_fd, 1);
+ ff_socket_nonblock(frsh_fd, 1);
}
- s->udp_fd = udp_fd;
+ s->frsh_fd = frsh_fd;
return 0;
fail:
- if (udp_fd >= 0)
- closesocket(udp_fd);
+ if (frsh_fd >= 0)
+ closesocket(frsh_fd);
av_free(s);
return AVERROR(EIO);
}
-static int udp_read(URLContext *h, uint8_t *buf, int size)
+static int frsh_read(URLContext *h, uint8_t *buf, int size)
{
- UDPContext *s = h->priv_data;
+ FRSHContext *s = h->priv_data;
unsigned int from;
int len;
return frsh_receive_sync(s->repoint, buf, size, &len, &from);
}
-static int udp_write(URLContext *h, uint8_t *buf, int size)
+static int frsh_write(URLContext *h, uint8_t *buf, int size)
{
- UDPContext *s = h->priv_data;
+ FRSHContext *s = h->priv_data;
int ret;
ret = frsh_send_async(s->sepoint, buf, size);
return ret;
}
-static int udp_close(URLContext *h)
+static int frsh_close(URLContext *h)
{
- UDPContext *s = h->priv_data;
+ FRSHContext *s = h->priv_data;
int ret;
frsh_send_endpoint_unbind(s->sepoint);
return ret;
}
-URLProtocol udp_protocol = {
- "udp",
- udp_open,
- udp_read,
- udp_write,
+URLProtocol frsh_protocol = {
+ "frsh",
+ frsh_open,
+ frsh_read,
+ frsh_write,
NULL, /* seek */
- udp_close,
- .url_get_file_handle = udp_get_file_handle,
+ frsh_close,
+ .url_get_file_handle = frsh_get_file_handle,
};