annotate stream/stream_udp.c @ 22998:85343b921fef

Fix preprocessor conditionals: libdvdnav includes libdvdread and configure enables libdvdread support if libdvdnav is found. There is no need to check separately in the source with the preprocessor.
author diego
date Wed, 18 Apr 2007 09:56:24 +0000
parents a3ddd3320b47
children d261f5109660
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19313
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
1 /*
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
2 * Copyright (C) 2006 Benjamin Zores
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
3 * Stream layer for MPEG over UDP, based on previous work from Dave Chapman
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
4 *
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
8 * (at your option) any later version.
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
9 *
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
13 * GNU General Public License for more details.
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
14 *
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
16 * along with this program; if not, write to the Free Software Foundation,
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
18 */
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
19
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
20 #include "config.h"
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
21
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
22 #include <stdlib.h>
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
23 #include <string.h>
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
24
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
25 #include "stream.h"
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
26 #include "url.h"
19318
a3ddd3320b47 removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents: 19313
diff changeset
27 #include "udp.h"
19313
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
28
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
29 static int
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
30 udp_streaming_start (stream_t *stream)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
31 {
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
32 streaming_ctrl_t *streaming_ctrl;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
33 int fd;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
34
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
35 if (!stream)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
36 return -1;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
37
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
38 streaming_ctrl = stream->streaming_ctrl;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
39 fd = stream->fd;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
40
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
41 if (fd < 0)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
42 {
19318
a3ddd3320b47 removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents: 19313
diff changeset
43 fd = udp_open_socket (streaming_ctrl->url);
19313
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
44 if (fd < 0)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
45 return -1;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
46 stream->fd = fd;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
47 }
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
48
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
49 streaming_ctrl->streaming_read = nop_streaming_read;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
50 streaming_ctrl->streaming_seek = nop_streaming_seek;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
51 streaming_ctrl->prebuffer_size = 64 * 1024; /* 64 KBytes */
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
52 streaming_ctrl->buffering = 0;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
53 streaming_ctrl->status = streaming_playing_e;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
54
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
55 return 0;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
56 }
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
57
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
58 static int
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
59 udp_stream_open (stream_t *stream, int mode, void *opts, int *file_format)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
60 {
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
61 URL_t *url;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
62 extern int network_bandwidth;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
63
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
64 mp_msg (MSGT_OPEN, MSGL_INFO, "STREAM_UDP, URL: %s\n", stream->url);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
65 stream->streaming_ctrl = streaming_ctrl_new ();
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
66 if (!stream->streaming_ctrl)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
67 return STREAM_ERROR;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
68
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
69 stream->streaming_ctrl->bandwidth = network_bandwidth;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
70 url = url_new (stream->url);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
71 stream->streaming_ctrl->url = check4proxies (url);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
72
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
73 if (url->port == 0)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
74 {
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
75 mp_msg (MSGT_NETWORK, MSGL_ERR,
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
76 "You must enter a port number for UDP streams!\n");
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
77 streaming_ctrl_free (stream->streaming_ctrl);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
78 stream->streaming_ctrl = NULL;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
79
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
80 return STREAM_UNSUPORTED;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
81 }
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
82
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
83 if (udp_streaming_start (stream) < 0)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
84 {
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
85 mp_msg (MSGT_NETWORK, MSGL_ERR, "udp_streaming_start failed\n");
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
86 streaming_ctrl_free (stream->streaming_ctrl);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
87 stream->streaming_ctrl = NULL;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
88
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
89 return STREAM_UNSUPORTED;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
90 }
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
91
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
92 stream->type = STREAMTYPE_STREAM;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
93 fixup_network_stream_cache (stream);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
94
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
95 return STREAM_OK;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
96 }
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
97
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
98 stream_info_t stream_info_udp = {
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
99 "MPEG over UDP streaming",
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
100 "udp",
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
101 "Dave Chapman, Benjamin Zores",
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
102 "native udp support",
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
103 udp_stream_open,
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
104 { "udp", NULL},
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
105 NULL,
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
106 0 // Urls are an option string
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
107 };