codec-cfg does not depend on codecs.conf.h, it is used to generate it.
[mplayer/glamo.git] / stream / stream_udp.c
blobc366d8e4a98a64d935494c49093f208435614b24
1 /*
2 * stream layer for MPEG over UDP, based on previous work from Dave Chapman
4 * Copyright (C) 2006 Benjamin Zores
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "config.h"
25 #include <stdlib.h>
26 #include <string.h>
28 #include "stream.h"
29 #include "url.h"
30 #include "udp.h"
32 static int
33 udp_streaming_start (stream_t *stream)
35 streaming_ctrl_t *streaming_ctrl;
36 int fd;
38 if (!stream)
39 return -1;
41 streaming_ctrl = stream->streaming_ctrl;
42 fd = stream->fd;
44 if (fd < 0)
46 fd = udp_open_socket (streaming_ctrl->url);
47 if (fd < 0)
48 return -1;
49 stream->fd = fd;
52 streaming_ctrl->streaming_read = nop_streaming_read;
53 streaming_ctrl->streaming_seek = nop_streaming_seek;
54 streaming_ctrl->prebuffer_size = 64 * 1024; /* 64 KBytes */
55 streaming_ctrl->buffering = 0;
56 streaming_ctrl->status = streaming_playing_e;
58 return 0;
61 static int
62 udp_stream_open (stream_t *stream, int mode, void *opts, int *file_format)
64 URL_t *url;
65 extern int network_bandwidth;
67 mp_msg (MSGT_OPEN, MSGL_INFO, "STREAM_UDP, URL: %s\n", stream->url);
68 stream->streaming_ctrl = streaming_ctrl_new ();
69 if (!stream->streaming_ctrl)
70 return STREAM_ERROR;
72 stream->streaming_ctrl->bandwidth = network_bandwidth;
73 url = url_new (stream->url);
74 stream->streaming_ctrl->url = check4proxies (url);
76 if (url->port == 0)
78 mp_msg (MSGT_NETWORK, MSGL_ERR,
79 "You must enter a port number for UDP streams!\n");
80 streaming_ctrl_free (stream->streaming_ctrl);
81 stream->streaming_ctrl = NULL;
83 return STREAM_UNSUPPORTED;
86 if (udp_streaming_start (stream) < 0)
88 mp_msg (MSGT_NETWORK, MSGL_ERR, "udp_streaming_start failed\n");
89 streaming_ctrl_free (stream->streaming_ctrl);
90 stream->streaming_ctrl = NULL;
92 return STREAM_UNSUPPORTED;
95 stream->type = STREAMTYPE_STREAM;
96 fixup_network_stream_cache (stream);
98 return STREAM_OK;
101 const stream_info_t stream_info_udp = {
102 "MPEG over UDP streaming",
103 "udp",
104 "Dave Chapman, Benjamin Zores",
105 "native udp support",
106 udp_stream_open,
107 { "udp", NULL},
108 NULL,
109 0 // Urls are an option string