~ubuntu-branches/ubuntu/precise/ffmpeg-debian/precise

« back to all changes in this revision

Viewing changes to libavformat/udp.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-11-15 19:44:29 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081115194429-zwlw86ht1rctd8z9
Tags: 3:0.svn20081115-1ubuntu1
* merge from debian.
* keep myself in the maintainer field. If you are touching this or the
  'ffmpeg' package in multiverse, please get in touch with me. Both
  source packages come from the same packaging branch.
* drop dependency on faad.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <unistd.h>
30
30
#include "network.h"
31
31
#include "os_support.h"
 
32
#ifdef HAVE_SYS_SELECT_H
 
33
#include <sys/select.h>
 
34
#endif
32
35
 
33
36
#ifndef IPV6_ADD_MEMBERSHIP
34
37
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
44
47
typedef struct {
45
48
    int udp_fd;
46
49
    int ttl;
 
50
    int buffer_size;
47
51
    int is_multicast;
48
52
    int local_port;
49
53
    int reuse_socket;
358
362
 
359
363
    h->priv_data = s;
360
364
    s->ttl = 16;
 
365
    s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE;
 
366
 
361
367
    p = strchr(uri, '?');
362
368
    if (p) {
363
369
        s->reuse_socket = find_info_tag(buf, sizeof(buf), "reuse", p);
370
376
        if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
371
377
            h->max_packet_size = strtol(buf, NULL, 10);
372
378
        }
 
379
        if (find_info_tag(buf, sizeof(buf), "buffer_size", p)) {
 
380
            s->buffer_size = strtol(buf, NULL, 10);
 
381
        }
373
382
    }
374
383
 
375
384
    /* fill the dest addr */
416
425
 
417
426
    if (is_output) {
418
427
        /* limit the tx buf size to limit latency */
419
 
        tmp = UDP_TX_BUF_SIZE;
 
428
        tmp = s->buffer_size;
420
429
        if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) {
421
430
            av_log(NULL, AV_LOG_ERROR, "setsockopt(SO_SNDBUF): %s\n", strerror(errno));
422
431
            goto fail;
424
433
    } else {
425
434
        /* set udp recv buffer size to the largest possible udp packet size to
426
435
         * avoid losing data on OSes that set this too low by default. */
427
 
        tmp = UDP_MAX_PKT_SIZE;
428
 
        setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp));
 
436
        tmp = s->buffer_size;
 
437
        if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) {
 
438
            av_log(NULL, AV_LOG_WARNING, "setsockopt(SO_RECVBUF): %s\n", strerror(errno));
 
439
        }
429
440
    }
430
441
 
431
442
    s->udp_fd = udp_fd;
441
452
{
442
453
    UDPContext *s = h->priv_data;
443
454
    int len;
 
455
    fd_set rfds;
 
456
    int ret;
 
457
    struct timeval tv;
444
458
 
445
459
    for(;;) {
446
 
        len = recv(s->udp_fd, buf, size, 0);
 
460
        if (url_interrupt_cb())
 
461
            return AVERROR(EINTR);
 
462
        FD_ZERO(&rfds);
 
463
        FD_SET(s->udp_fd, &rfds);
 
464
        tv.tv_sec = 0;
 
465
        tv.tv_usec = 100 * 1000;
 
466
        ret = select(s->udp_fd + 1, &rfds, NULL, NULL, &tv);
 
467
        if (ret < 0)
 
468
            return AVERROR(EIO);
 
469
        if (!(ret > 0 && FD_ISSET(s->udp_fd, &rfds)))
 
470
            continue;
 
471
        len = recv(s->udp_fd, buf, size, MSG_DONTWAIT);
447
472
        if (len < 0) {
448
473
            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
449
474
                ff_neterrno() != FF_NETERROR(EINTR))