one more spelling fix
[mplayer/glamo.git] / stream / stream_rtp.c
blob214ebf2257869b826c8a56e0d36b23c9ff06cdae
1 /*
2 * Copyright (C) 2006 Benjamin Zores
3 * Stream layer for MPEG over RTP, 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"
28 #include "rtp.h"
30 static int
31 rtp_streaming_read (int fd, char *buffer,
32 int size, streaming_ctrl_t *streaming_ctrl)
34 return read_rtp_from_server (fd, buffer, size);
37 static int
38 rtp_streaming_start (stream_t *stream)
40 streaming_ctrl_t *streaming_ctrl;
41 int fd;
43 if (!stream)
44 return -1;
46 streaming_ctrl = stream->streaming_ctrl;
47 fd = stream->fd;
49 if (fd < 0)
51 fd = udp_open_socket (streaming_ctrl->url);
52 if (fd < 0)
53 return -1;
54 stream->fd = fd;
57 streaming_ctrl->streaming_read = rtp_streaming_read;
58 streaming_ctrl->streaming_seek = nop_streaming_seek;
59 streaming_ctrl->prebuffer_size = 64 * 1024; /* 64 KBytes */
60 streaming_ctrl->buffering = 0;
61 streaming_ctrl->status = streaming_playing_e;
63 return 0;
66 static int
67 rtp_stream_open (stream_t *stream, int mode, void *opts, int *file_format)
69 URL_t *url;
70 extern int network_bandwidth;
72 mp_msg (MSGT_OPEN, MSGL_INFO, "STREAM_RTP, URL: %s\n", stream->url);
73 stream->streaming_ctrl = streaming_ctrl_new ();
74 if (!stream->streaming_ctrl)
75 return STREAM_ERROR;
77 stream->streaming_ctrl->bandwidth = network_bandwidth;
78 url = url_new (stream->url);
79 stream->streaming_ctrl->url = check4proxies (url);
81 if (url->port == 0)
83 mp_msg (MSGT_NETWORK, MSGL_ERR,
84 "You must enter a port number for RTP streams!\n");
85 streaming_ctrl_free (stream->streaming_ctrl);
86 stream->streaming_ctrl = NULL;
88 return STREAM_UNSUPORTED;
91 if (rtp_streaming_start (stream) < 0)
93 mp_msg (MSGT_NETWORK, MSGL_ERR, "rtp_streaming_start failed\n");
94 streaming_ctrl_free (stream->streaming_ctrl);
95 stream->streaming_ctrl = NULL;
97 return STREAM_UNSUPORTED;
100 stream->type = STREAMTYPE_STREAM;
101 fixup_network_stream_cache (stream);
103 return STREAM_OK;
106 stream_info_t stream_info_rtp = {
107 "MPEG over RTP streaming",
108 "rtp",
109 "Dave Chapman, Benjamin Zores",
110 "native rtp support",
111 rtp_stream_open,
112 { "rtp", NULL},
113 NULL,
114 0 // Urls are an option string