annotate stream/stream_rtp.c @ 24747:4147969ee500

10l fix compilation with v4l2
author iive
date Sat, 13 Oct 2007 19:57:51 +0000
parents d261f5109660
children c1d17bd6683c
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 RTP, 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 #include "rtp.h"
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
29
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
30 static int
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
31 rtp_streaming_read (int fd, char *buffer,
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
32 int size, streaming_ctrl_t *streaming_ctrl)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
33 {
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
34 return read_rtp_from_server (fd, buffer, size);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
35 }
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
36
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
37 static int
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
38 rtp_streaming_start (stream_t *stream)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
39 {
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
40 streaming_ctrl_t *streaming_ctrl;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
41 int fd;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
42
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
43 if (!stream)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
44 return -1;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
45
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
46 streaming_ctrl = stream->streaming_ctrl;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
47 fd = stream->fd;
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 if (fd < 0)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
50 {
19318
a3ddd3320b47 removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents: 19313
diff changeset
51 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
52 if (fd < 0)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
53 return -1;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
54 stream->fd = fd;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
55 }
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 streaming_ctrl->streaming_read = rtp_streaming_read;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
58 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
59 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
60 streaming_ctrl->buffering = 0;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
61 streaming_ctrl->status = streaming_playing_e;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
62
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
63 return 0;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
64 }
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
65
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
66 static int
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
67 rtp_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
68 {
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
69 URL_t *url;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
70 extern int network_bandwidth;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
71
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
72 mp_msg (MSGT_OPEN, MSGL_INFO, "STREAM_RTP, URL: %s\n", stream->url);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
73 stream->streaming_ctrl = streaming_ctrl_new ();
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
74 if (!stream->streaming_ctrl)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
75 return STREAM_ERROR;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
76
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
77 stream->streaming_ctrl->bandwidth = network_bandwidth;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
78 url = url_new (stream->url);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
79 stream->streaming_ctrl->url = check4proxies (url);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
80
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
81 if (url->port == 0)
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 mp_msg (MSGT_NETWORK, MSGL_ERR,
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
84 "You must enter a port number for RTP streams!\n");
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
85 streaming_ctrl_free (stream->streaming_ctrl);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
86 stream->streaming_ctrl = NULL;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
87
24257
d261f5109660 cosmetics: typo fix UNSUPORTED --> UNSUPPORTED
diego
parents: 19318
diff changeset
88 return STREAM_UNSUPPORTED;
19313
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
89 }
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 if (rtp_streaming_start (stream) < 0)
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
92 {
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
93 mp_msg (MSGT_NETWORK, MSGL_ERR, "rtp_streaming_start failed\n");
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
94 streaming_ctrl_free (stream->streaming_ctrl);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
95 stream->streaming_ctrl = NULL;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
96
24257
d261f5109660 cosmetics: typo fix UNSUPORTED --> UNSUPPORTED
diego
parents: 19318
diff changeset
97 return STREAM_UNSUPPORTED;
19313
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
98 }
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
99
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
100 stream->type = STREAMTYPE_STREAM;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
101 fixup_network_stream_cache (stream);
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
102
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
103 return STREAM_OK;
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
104 }
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
105
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
106 stream_info_t stream_info_rtp = {
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
107 "MPEG over RTP streaming",
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
108 "rtp",
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
109 "Dave Chapman, Benjamin Zores",
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
110 "native rtp support",
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
111 rtp_stream_open,
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
112 { "rtp", NULL},
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
113 NULL,
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
114 0 // Urls are an option string
0792ad01e9bf split rtp stack, udp input layer and rtp input layer from rtp.c
ben
parents:
diff changeset
115 };