~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libavformat/rtpproto.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-25 15:47:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080225154712-qvr11ekcea4c9ry8
Tags: 1.1.6-0.1ubuntu1
* Merge from debian-multimedia (LP: #120003), Ubuntu Changes:
 - For ffmpeg-related build-deps, remove cvs from package names.
 - Standards-Version 3.7.3
 - Maintainer Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * RTP network protocol
3
3
 * Copyright (c) 2002 Fabrice Bellard.
4
4
 *
5
 
 * This library is free software; you can redistribute it and/or
 
5
 * This file is part of FFmpeg.
 
6
 *
 
7
 * FFmpeg is free software; you can redistribute it and/or
6
8
 * modify it under the terms of the GNU Lesser General Public
7
9
 * License as published by the Free Software Foundation; either
8
 
 * version 2 of the License, or (at your option) any later version.
 
10
 * version 2.1 of the License, or (at your option) any later version.
9
11
 *
10
 
 * This library is distributed in the hope that it will be useful,
 
12
 * FFmpeg is distributed in the hope that it will be useful,
11
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
15
 * Lesser General Public License for more details.
14
16
 *
15
17
 * You should have received a copy of the GNU Lesser General Public
16
 
 * License along with this library; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 * License along with FFmpeg; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
20
 */
19
21
#include "avformat.h"
20
22
 
21
23
#include <unistd.h>
22
24
#include <stdarg.h>
23
 
#include <sys/types.h>
24
 
#include <sys/socket.h>
25
 
#include <netinet/in.h>
26
 
#ifndef __BEOS__
27
 
# include <arpa/inet.h>
28
 
#else
29
 
# include "barpainet.h"
30
 
#endif
31
 
#include <netdb.h>
 
25
#include "network.h"
32
26
#include <fcntl.h>
33
27
 
34
28
#define RTP_TX_BUF_SIZE  (64 * 1024)
56
50
 
57
51
    char buf[1024];
58
52
    char path[1024];
59
 
    
60
 
    url_split(NULL, 0, hostname, sizeof(hostname), &port, 
 
53
 
 
54
    url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port,
61
55
              path, sizeof(path), uri);
62
56
 
63
57
    snprintf(buf, sizeof(buf), "udp://%s:%d%s", hostname, port, path);
87
81
}
88
82
 
89
83
static void build_udp_url(char *buf, int buf_size,
90
 
                          const char *hostname, int port,
91
 
                          int local_port, int multicast, int ttl)
 
84
                          const char *hostname, int port,
 
85
                          int local_port, int multicast, int ttl)
92
86
{
93
87
    snprintf(buf, buf_size, "udp://%s:%d", hostname, port);
94
88
    if (local_port >= 0)
101
95
 
102
96
/*
103
97
 * url syntax: rtp://host:port[?option=val...]
104
 
 * option: 'multicast=1' : enable multicast 
 
98
 * option: 'multicast=1' : enable multicast
105
99
 *         'ttl=n'       : set the ttl value (for multicast only)
106
100
 *         'localport=n' : set the local port to n
107
101
 *
114
108
    char buf[1024];
115
109
    char path[1024];
116
110
    const char *p;
117
 
    
 
111
 
118
112
    is_output = (flags & URL_WRONLY);
119
113
 
120
114
    s = av_mallocz(sizeof(RTPContext));
121
115
    if (!s)
122
 
        return -ENOMEM;
 
116
        return AVERROR(ENOMEM);
123
117
    h->priv_data = s;
124
 
    
125
 
    url_split(NULL, 0, hostname, sizeof(hostname), &port, 
 
118
 
 
119
    url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port,
126
120
              path, sizeof(path), uri);
127
121
    /* extract parameters */
128
122
    is_multicast = 0;
147
141
    /* XXX: need to open another connexion if the port is not even */
148
142
 
149
143
    /* well, should suppress localport in path */
150
 
    
 
144
 
151
145
    build_udp_url(buf, sizeof(buf),
152
146
                  hostname, port + 1, local_port + 1, is_multicast, ttl);
153
147
    if (url_open(&s->rtcp_hd, buf, flags) < 0)
154
148
        goto fail;
155
 
    
 
149
 
156
150
    /* just to ease handle access. XXX: need to suppress direct handle
157
151
       access */
158
152
    s->rtp_fd = udp_get_file_handle(s->rtp_hd);
159
153
    s->rtcp_fd = udp_get_file_handle(s->rtcp_hd);
160
154
 
161
 
    h->max_packet_size = url_get_max_packet_size(s->rtp_hd); 
 
155
    h->max_packet_size = url_get_max_packet_size(s->rtp_hd);
162
156
    h->is_streamed = 1;
163
157
    return 0;
164
158
 
168
162
    if (s->rtcp_hd)
169
163
        url_close(s->rtcp_hd);
170
164
    av_free(s);
171
 
    return -EIO;
 
165
    return AVERROR_IO;
172
166
}
173
167
 
174
168
static int rtp_read(URLContext *h, uint8_t *buf, int size)
175
169
{
176
170
    RTPContext *s = h->priv_data;
177
171
    struct sockaddr_in from;
178
 
    int from_len, len, fd_max, n;
 
172
    socklen_t from_len;
 
173
    int len, fd_max, n;
179
174
    fd_set rfds;
180
175
#if 0
181
176
    for(;;) {
185
180
        if (len < 0) {
186
181
            if (errno == EAGAIN || errno == EINTR)
187
182
                continue;
188
 
            return -EIO;
 
183
            return AVERROR_IO;
189
184
        }
190
185
        break;
191
186
    }
208
203
                if (len < 0) {
209
204
                    if (errno == EAGAIN || errno == EINTR)
210
205
                        continue;
211
 
                    return -EIO;
 
206
                    return AVERROR_IO;
212
207
                }
213
208
                break;
214
209
            }
220
215
                if (len < 0) {
221
216
                    if (errno == EAGAIN || errno == EINTR)
222
217
                        continue;
223
 
                    return -EIO;
 
218
                    return AVERROR_IO;
224
219
                }
225
220
                break;
226
221
            }
235
230
    RTPContext *s = h->priv_data;
236
231
    int ret;
237
232
    URLContext *hd;
238
 
    
 
233
 
239
234
    if (buf[1] >= 200 && buf[1] <= 204) {
240
235
        /* RTCP payload type */
241
236
        hd = s->rtcp_hd;