static int rtp_streaming_start (stream_t *stream) { streaming_ctrl_t *streaming_ctrl; int fd; if (!stream) return -1; streaming_ctrl = stream->streaming_ctrl; fd = stream->fd; if (fd < 0) { fd = udp_open_socket (streaming_ctrl->url); if (fd < 0) return -1; stream->fd = fd; } streaming_ctrl->streaming_read = rtp_streaming_read; streaming_ctrl->streaming_seek = nop_streaming_seek; streaming_ctrl->prebuffer_size = 64 * 1024; /* 64 KBytes */ streaming_ctrl->buffering = 0; streaming_ctrl->status = streaming_playing_e; return 0; }
/* make an UDP client connection to a host Inputs: <host> the host, host==NULL means broadcast <port> the port # Outputs: <serv_addr> the info of the client Return: the socket */ int udp_make_client(char *host, int port, struct sockaddr_in *serv_addr) { int fd; unsigned int ip; if (host) ip = inet_addr(host); else ip = 0xFFFFFFFF; /* broadcast */ fd = udp_open_socket(ip, port, serv_addr); if (fd > 0) { if (bind_interface(fd, 0, 0)) { /* fail to bind local address for this client */ closesocket(fd); fd = -1; } else { if (!host) { const int val = 1; setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (const char*) &val, sizeof(val)); } dbgprintf ("connected to %s at port %hu", inet_ntoa (serv_addr->sin_addr), port); } } return fd; }
/* start an UDP server at a port Inputs: <iface> the binding address <port> the port # <serv_addr> the info of the server Return: the socket */ int udp_startup_server(unsigned int iface, int port, struct sockaddr_in *serv_addr) { int fd; fd = udp_open_socket(0, port, serv_addr); if (fd > 0) { if (bind_interface(fd, iface, port)) { /* fail to bind to local */ closesocket(fd); fd = -1; } else { serv_addr->sin_addr.s_addr = iface? iface:lookup_localhost_ip(); /* host ip */ dbgprintf ("startup a UDP server at port %d fd %d",port,fd); } } return fd; }