one more spelling fix
[mplayer/glamo.git] / stream / stream_udp.c
blob466241c85dcee2e51d4b8d4e7a7fdcd5d0108f3b
1 /*
2 * Copyright (C) 2006 Benjamin Zores
3 * Stream layer for MPEG over UDP, based on previous work from Dave Chapman
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "config.h"
22 #include <stdlib.h>
23 #include <string.h>
25 #include "stream.h"
26 #include "url.h"
27 #include "udp.h"
29 static int
30 udp_streaming_start (stream_t *stream)
32 streaming_ctrl_t *streaming_ctrl;
33 int fd;
35 if (!stream)
36 return -1;
38 streaming_ctrl = stream->streaming_ctrl;
39 fd = stream->fd;
41 if (fd < 0)
43 fd = udp_open_socket (streaming_ctrl->url);
44 if (fd < 0)
45 return -1;
46 stream->fd = fd;
49 streaming_ctrl->streaming_read = nop_streaming_read;
50 streaming_ctrl->streaming_seek = nop_streaming_seek;
51 streaming_ctrl->prebuffer_size = 64 * 1024; /* 64 KBytes */
52 streaming_ctrl->buffering = 0;
53 streaming_ctrl->status = streaming_playing_e;
55 return 0;
58 static int
59 udp_stream_open (stream_t *stream, int mode, void *opts, int *file_format)
61 URL_t *url;
62 extern int network_bandwidth;
64 mp_msg (MSGT_OPEN, MSGL_INFO, "STREAM_UDP, URL: %s\n", stream->url);
65 stream->streaming_ctrl = streaming_ctrl_new ();
66 if (!stream->streaming_ctrl)
67 return STREAM_ERROR;
69 stream->streaming_ctrl->bandwidth = network_bandwidth;
70 url = url_new (stream->url);
71 stream->streaming_ctrl->url = check4proxies (url);
73 if (url->port == 0)
75 mp_msg (MSGT_NETWORK, MSGL_ERR,
76 "You must enter a port number for UDP streams!\n");
77 streaming_ctrl_free (stream->streaming_ctrl);
78 stream->streaming_ctrl = NULL;
80 return STREAM_UNSUPORTED;
83 if (udp_streaming_start (stream) < 0)
85 mp_msg (MSGT_NETWORK, MSGL_ERR, "udp_streaming_start failed\n");
86 streaming_ctrl_free (stream->streaming_ctrl);
87 stream->streaming_ctrl = NULL;
89 return STREAM_UNSUPORTED;
92 stream->type = STREAMTYPE_STREAM;
93 fixup_network_stream_cache (stream);
95 return STREAM_OK;
98 stream_info_t stream_info_udp = {
99 "MPEG over UDP streaming",
100 "udp",
101 "Dave Chapman, Benjamin Zores",
102 "native udp support",
103 udp_stream_open,
104 { "udp", NULL},
105 NULL,
106 0 // Urls are an option string