Translation system changes part 2: replace macros by strings
[mplayer.git] / stream / stream_rtp.c
blobb48562fbded92e9c1aafcbb1e25d43d23dc13a32
1 /*
2 * stream layer for MPEG over RTP, 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"
31 #include "rtp.h"
33 static int
34 rtp_streaming_read (int fd, char *buffer,
35 int size, streaming_ctrl_t *streaming_ctrl)
37 return read_rtp_from_server (fd, buffer, size);
40 static int
41 rtp_streaming_start (stream_t *stream)
43 streaming_ctrl_t *streaming_ctrl;
44 int fd;
46 if (!stream)
47 return -1;
49 streaming_ctrl = stream->streaming_ctrl;
50 fd = stream->fd;
52 if (fd < 0)
54 fd = udp_open_socket (streaming_ctrl->url);
55 if (fd < 0)
56 return -1;
57 stream->fd = fd;
60 streaming_ctrl->streaming_read = rtp_streaming_read;
61 streaming_ctrl->streaming_seek = nop_streaming_seek;
62 streaming_ctrl->prebuffer_size = 64 * 1024; /* 64 KBytes */
63 streaming_ctrl->buffering = 0;
64 streaming_ctrl->status = streaming_playing_e;
66 return 0;
69 static int
70 rtp_stream_open (stream_t *stream, int mode, void *opts, int *file_format)
72 URL_t *url;
73 extern int network_bandwidth;
75 mp_msg (MSGT_OPEN, MSGL_INFO, "STREAM_RTP, URL: %s\n", stream->url);
76 stream->streaming_ctrl = streaming_ctrl_new ();
77 if (!stream->streaming_ctrl)
78 return STREAM_ERROR;
80 stream->streaming_ctrl->bandwidth = network_bandwidth;
81 url = url_new (stream->url);
82 stream->streaming_ctrl->url = check4proxies (url);
84 if (url->port == 0)
86 mp_msg (MSGT_NETWORK, MSGL_ERR,
87 "You must enter a port number for RTP streams!\n");
88 streaming_ctrl_free (stream->streaming_ctrl);
89 stream->streaming_ctrl = NULL;
91 return STREAM_UNSUPPORTED;
94 if (rtp_streaming_start (stream) < 0)
96 mp_msg (MSGT_NETWORK, MSGL_ERR, "rtp_streaming_start failed\n");
97 streaming_ctrl_free (stream->streaming_ctrl);
98 stream->streaming_ctrl = NULL;
100 return STREAM_UNSUPPORTED;
103 stream->type = STREAMTYPE_STREAM;
104 fixup_network_stream_cache (stream);
106 return STREAM_OK;
109 const stream_info_t stream_info_rtp = {
110 "MPEG over RTP streaming",
111 "rtp",
112 "Dave Chapman, Benjamin Zores",
113 "native rtp support",
114 rtp_stream_open,
115 { "rtp", NULL},
116 NULL,
117 0 // Urls are an option string