~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavformat/rtsp.c

  • Committer: Gauvain Pocentek
  • Date: 2012-03-06 11:59:12 UTC
  • mfrom: (66.1.15 precise)
  • Revision ID: gauvain@pocentek.net-20120306115912-h9d6kt9j0l532oo5
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* New upstream snapshot
* upload to unstable
* Build against external libmpeg2
* drop 51_FTBFS_arm.patch again
* no longer build depend on libcdparanoia-dev on the Hurd
* Fix FTBFS on the hurd.
  Thanks to Samuel Thibault <sthibault@debian.org> (Closes: #654974)
* Fix FTBFS on arm
* New upstream snapshot, Closes: #650339, #643621, #481807
* Imported Upstream version 1.0~rc4+svn34492
* Bump standards version
* Bump dependency on libav >= 4:0.8~, Closes: #653887
* Fix build-indep
* Build mplayer-gui again, Closes: #568514
* Drop debian/all-lang-config-mak.sh, no longer needed
* include .dfsg1 in version number
* remove get-orig-source target
* no longer prune compiler flags from the environment
* No longer advertise nor build 3fdx, mga and dxr3 backends,
  Closes: #496106, #442181, #533546
* beautify mplayer version identification string
* Brown paperbag upload.
* Next try to fix build failure on sparce after recent binutils change.
* Brown paperbag upload.
* Really fix build failure on sparc after recent binutils change.
* Properly set Replaces/Conflicts on mplayer2{,-dbg} to avoid
  file overwrite errors.
* Adjust versioning of mplayer listed in the mplayer-dbg's Depends field.
* Fix build failure on sparc after recent binutils change.
* Urgency medium bumped because of RC-level bugfix
  and speeding up x264 transition.
* Update to my @debian.org email.
* Upload to unstable
* Enable joystick support on Linux only, Closes: #638408
* Rebuild fixes toolchain issue on arm, Closes: #637077
* New upstream snapshot
* following the discussion started by Diego Biurrun <diego@biurrun.de>
  in debian-devel, I have prepared a new packaging of 'mplayer'
  (with code that comes from CVS)
* the upstream tar.bz cannot be distributed by Debian, since it contains
   CSS code; so I am repackaging it 
* I have tried my best to address all known issues:
  - the package contains the detailed Copyright made by Diego Biurrun 
  - the package does not contain CSS code, or  AFAIK other code on which 
     there is active patent enforcement
  - there is a script  debian/cvs-changelog.sh  that shows all changes
     done to files included in this source.
    This should comply with GPLv2 sec 2.a  (in spirit if not in letter)
    For this reason, the source code contains CVS directories.
* needs   make (>= 3.80) for 'html-chunked-$(1)' in DOCS/xml/Makefile

* some corrections, as suggested Diego Biurrun
  - binary codecs should go into /usr/lib/codecs (upstream default)
  - better template 'mplayer/install_codecs'
  - an empty 'font=' in mplayer.conf breaks mplayer: postinst corrected
* correction in 'mplayer/cfgnote'
* better mplayer.postinst and mplayer.config

* New upstream release
* better debian/copyright file
* do not ship a skin
* New upstream release
* changed DEB_BUILD_OPTIONS to DEB_BUILD_CONFIGURE ,
  DEB_BUILD_OPTIONS is used as in debian policy
* use gcc-3.4
* changed xlibs-dev to a long list of dependencies, for Debian/etch
* try to adhere to  http://www.mplayerhq.hu/DOCS/tech/binary-packaging.txt
  (see README.Debian for details)
* removed dependency on xlibmesa-dev, disabled opengl
* New upstream release
* Simon McVittie <hacks@pseudorandom.co.uk> wonderful work:
- Work around Debian bug #267442 (glibc's sys/uio.h and gcc's altivec.h have
  conflicting uses for __vector) by re-ordering #includes
- Fix potential symlink attack in ./configure
- Disable support for binary codecs on platforms for which those codecs
  aren't available; also disable the corresponding Debconf note when it's
  inappropriate
- Changed Build-Depends: so it works in pbuilder
- Explicitly build-depend on libjpeg62-dev, libfontconfig1-dev,
  libungif4-dev 
- Tweak debian/rules to avoid certain errors being ignored
- Use --language=all
* provide a target  'debian/rules get-orig-source' 
  that recreates the orig.tar.gz ; then use the above orig.tar.gz
* rewrote some parts of debian/rules
* don't clean and recompile docs if upstream ships them
* mplayer-doc was shipping too much stuff
* translated man pages where not installed properly
* compile with libdv4-dev
* correct README.Debian
* Forgot build-dep on libtheora
* Must not depend on libxvidcore
* New upstream release
* new release.
* rc1 to become 0.90
* new pre-release
* new pre-release
* gtk bug fixed.
* new release.
* version bumped
* 0.60 pre2 release
* 0.60 pre-release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "libavutil/base64.h"
23
23
#include "libavutil/avstring.h"
24
24
#include "libavutil/intreadwrite.h"
 
25
#include "libavutil/mathematics.h"
25
26
#include "libavutil/parseutils.h"
26
27
#include "libavutil/random_seed.h"
27
28
#include "libavutil/dict.h"
 
29
#include "libavutil/opt.h"
28
30
#include "avformat.h"
29
31
#include "avio_internal.h"
30
32
 
32
34
#if HAVE_POLL_H
33
35
#include <poll.h>
34
36
#endif
35
 
#include <strings.h>
36
37
#include "internal.h"
37
38
#include "network.h"
38
39
#include "os_support.h"
44
45
#include "rtpdec_formats.h"
45
46
#include "rtpenc_chain.h"
46
47
#include "url.h"
 
48
#include "rtpenc.h"
47
49
 
48
50
//#define DEBUG
49
51
 
55
57
#define SDP_MAX_SIZE 16384
56
58
#define RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH
57
59
 
 
60
#define OFFSET(x) offsetof(RTSPState, x)
 
61
#define DEC AV_OPT_FLAG_DECODING_PARAM
 
62
#define ENC AV_OPT_FLAG_ENCODING_PARAM
 
63
 
 
64
#define RTSP_FLAG_OPTS(name, longname) \
 
65
    { name, longname, OFFSET(rtsp_flags), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC, "rtsp_flags" }, \
 
66
    { "filter_src", "Only receive packets from the negotiated peer IP", 0, AV_OPT_TYPE_CONST, {RTSP_FLAG_FILTER_SRC}, 0, 0, DEC, "rtsp_flags" }
 
67
 
 
68
#define RTSP_MEDIATYPE_OPTS(name, longname) \
 
69
    { name, longname, OFFSET(media_type_mask), AV_OPT_TYPE_FLAGS, { (1 << (AVMEDIA_TYPE_DATA+1)) - 1 }, INT_MIN, INT_MAX, DEC, "allowed_media_types" }, \
 
70
    { "video", "Video", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_VIDEO}, 0, 0, DEC, "allowed_media_types" }, \
 
71
    { "audio", "Audio", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_AUDIO}, 0, 0, DEC, "allowed_media_types" }, \
 
72
    { "data", "Data", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_DATA}, 0, 0, DEC, "allowed_media_types" }
 
73
 
 
74
const AVOption ff_rtsp_options[] = {
 
75
    { "initial_pause",  "Don't start playing the stream immediately", OFFSET(initial_pause), AV_OPT_TYPE_INT, {0}, 0, 1, DEC },
 
76
    FF_RTP_FLAG_OPTS(RTSPState, rtp_muxer_flags),
 
77
    { "rtsp_transport", "RTSP transport protocols", OFFSET(lower_transport_mask), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC|ENC, "rtsp_transport" }, \
 
78
    { "udp", "UDP", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_UDP}, 0, 0, DEC|ENC, "rtsp_transport" }, \
 
79
    { "tcp", "TCP", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_TCP}, 0, 0, DEC|ENC, "rtsp_transport" }, \
 
80
    { "udp_multicast", "UDP multicast", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_UDP_MULTICAST}, 0, 0, DEC, "rtsp_transport" },
 
81
    { "http", "HTTP tunneling", 0, AV_OPT_TYPE_CONST, {(1 << RTSP_LOWER_TRANSPORT_HTTP)}, 0, 0, DEC, "rtsp_transport" },
 
82
    RTSP_FLAG_OPTS("rtsp_flags", "RTSP flags"),
 
83
    RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
 
84
    { NULL },
 
85
};
 
86
 
 
87
static const AVOption sdp_options[] = {
 
88
    RTSP_FLAG_OPTS("sdp_flags", "SDP flags"),
 
89
    RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
 
90
    { NULL },
 
91
};
 
92
 
 
93
static const AVOption rtp_options[] = {
 
94
    RTSP_FLAG_OPTS("rtp_flags", "RTP flags"),
 
95
    { NULL },
 
96
};
 
97
 
58
98
static void get_word_until_chars(char *buf, int buf_size,
59
99
                                 const char *sep, const char **pp)
60
100
{
132
172
        return;
133
173
    codec->codec_id          = handler->codec_id;
134
174
    rtsp_st->dynamic_handler = handler;
135
 
    if (handler->alloc)
 
175
    if (handler->alloc) {
136
176
        rtsp_st->dynamic_protocol_context = handler->alloc();
 
177
        if (!rtsp_st->dynamic_protocol_context)
 
178
            rtsp_st->dynamic_handler = NULL;
 
179
    }
137
180
}
138
181
 
139
182
/* parse the rtpmap description: <codec_name>/<clock_rate>[/<other params>] */
185
228
        codec->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS;
186
229
        if (i > 0) {
187
230
            codec->sample_rate = i;
188
 
            av_set_pts_info(st, 32, 1, codec->sample_rate);
 
231
            avpriv_set_pts_info(st, 32, 1, codec->sample_rate);
189
232
            get_word_sep(buf, sizeof(buf), "/", &p);
190
233
            i = atoi(buf);
191
234
            if (i > 0)
203
246
    case AVMEDIA_TYPE_VIDEO:
204
247
        av_log(s, AV_LOG_DEBUG, "video codec set to: %s\n", c_name);
205
248
        if (i > 0)
206
 
            av_set_pts_info(st, 32, 1, i);
 
249
            avpriv_set_pts_info(st, 32, 1, i);
207
250
        break;
208
251
    default:
209
252
        break;
210
253
    }
 
254
    if (rtsp_st->dynamic_handler && rtsp_st->dynamic_handler->init)
 
255
        rtsp_st->dynamic_handler->init(s, st->index,
 
256
                                       rtsp_st->dynamic_protocol_context);
211
257
    return 0;
212
258
}
213
259
 
293
339
    case 'm':
294
340
        /* new stream */
295
341
        s1->skip_media = 0;
 
342
        codec_type = AVMEDIA_TYPE_UNKNOWN;
296
343
        get_word(st_type, sizeof(st_type), &p);
297
344
        if (!strcmp(st_type, "audio")) {
298
345
            codec_type = AVMEDIA_TYPE_AUDIO;
300
347
            codec_type = AVMEDIA_TYPE_VIDEO;
301
348
        } else if (!strcmp(st_type, "application")) {
302
349
            codec_type = AVMEDIA_TYPE_DATA;
303
 
        } else {
 
350
        }
 
351
        if (codec_type == AVMEDIA_TYPE_UNKNOWN || !(rt->media_type_mask & (1 << codec_type))) {
304
352
            s1->skip_media = 1;
305
353
            return;
306
354
        }
325
373
        if (!strcmp(ff_rtp_enc_name(rtsp_st->sdp_payload_type), "MP2T")) {
326
374
            /* no corresponding stream */
327
375
        } else {
328
 
            st = av_new_stream(s, rt->nb_rtsp_streams - 1);
 
376
            st = avformat_new_stream(s, NULL);
329
377
            if (!st)
330
378
                return;
 
379
            st->id = rt->nb_rtsp_streams - 1;
331
380
            rtsp_st->stream_index = st->index;
332
381
            st->codec->codec_type = codec_type;
333
382
            if (rtsp_st->sdp_payload_type < RTP_PT_PRIVATE) {
336
385
                ff_rtp_get_codec_info(st->codec, rtsp_st->sdp_payload_type);
337
386
                if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
338
387
                    st->codec->sample_rate > 0)
339
 
                    av_set_pts_info(st, 32, 1, st->codec->sample_rate);
 
388
                    avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate);
340
389
                /* Even static payload types may need a custom depacketizer */
341
390
                handler = ff_rtp_handler_find_by_id(
342
391
                              rtsp_st->sdp_payload_type, st->codec->codec_type);
343
392
                init_rtp_handler(handler, rtsp_st, st->codec);
 
393
                if (handler && handler->init)
 
394
                    handler->init(s, st->index,
 
395
                                  rtsp_st->dynamic_protocol_context);
344
396
            }
345
397
        }
346
398
        /* put a default control url */
428
480
    }
429
481
}
430
482
 
431
 
/**
432
 
 * Parse the sdp description and allocate the rtp streams and the
433
 
 * pollfd array used for udp ones.
434
 
 */
435
 
 
436
483
int ff_sdp_parse(AVFormatContext *s, const char *content)
437
484
{
438
485
    RTSPState *rt = s->priv_data;
505
552
            } else if (rt->transport == RTSP_TRANSPORT_RDT && CONFIG_RTPDEC)
506
553
                ff_rdt_parse_close(rtsp_st->transport_priv);
507
554
            else if (CONFIG_RTPDEC)
508
 
                rtp_parse_close(rtsp_st->transport_priv);
 
555
                ff_rtp_parse_close(rtsp_st->transport_priv);
509
556
        }
510
557
        rtsp_st->transport_priv = NULL;
511
558
        if (rtsp_st->rtp_handle)
533
580
    }
534
581
    av_free(rt->rtsp_streams);
535
582
    if (rt->asf_ctx) {
536
 
        av_close_input_stream (rt->asf_ctx);
537
 
        rt->asf_ctx = NULL;
 
583
        avformat_close_input(&rt->asf_ctx);
538
584
    }
539
585
    av_free(rt->p);
540
586
    av_free(rt->recvbuf);
562
608
                                            rtsp_st->dynamic_protocol_context,
563
609
                                            rtsp_st->dynamic_handler);
564
610
    else if (CONFIG_RTPDEC)
565
 
        rtsp_st->transport_priv = rtp_parse_open(s, st, rtsp_st->rtp_handle,
 
611
        rtsp_st->transport_priv = ff_rtp_parse_open(s, st, rtsp_st->rtp_handle,
566
612
                                         rtsp_st->sdp_payload_type,
567
613
            (rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP || !s->max_delay)
568
614
            ? 0 : RTP_REORDER_QUEUE_DEFAULT_SIZE);
571
617
         return AVERROR(ENOMEM);
572
618
    } else if (rt->transport != RTSP_TRANSPORT_RDT && CONFIG_RTPDEC) {
573
619
        if (rtsp_st->dynamic_handler) {
574
 
            rtp_parse_set_dynamic_protocol(rtsp_st->transport_priv,
575
 
                                           rtsp_st->dynamic_protocol_context,
576
 
                                           rtsp_st->dynamic_handler);
 
620
            ff_rtp_parse_set_dynamic_protocol(rtsp_st->transport_priv,
 
621
                                              rtsp_st->dynamic_protocol_context,
 
622
                                              rtsp_st->dynamic_handler);
577
623
        }
578
624
    }
579
625
 
622
668
 
623
669
        get_word_sep(transport_protocol, sizeof(transport_protocol),
624
670
                     "/", &p);
625
 
        if (!strcasecmp (transport_protocol, "rtp")) {
 
671
        if (!av_strcasecmp (transport_protocol, "rtp")) {
626
672
            get_word_sep(profile, sizeof(profile), "/;,", &p);
627
673
            lower_transport[0] = '\0';
628
674
            /* rtp/avp/<protocol> */
631
677
                             ";,", &p);
632
678
            }
633
679
            th->transport = RTSP_TRANSPORT_RTP;
634
 
        } else if (!strcasecmp (transport_protocol, "x-pn-tng") ||
635
 
                   !strcasecmp (transport_protocol, "x-real-rdt")) {
 
680
        } else if (!av_strcasecmp (transport_protocol, "x-pn-tng") ||
 
681
                   !av_strcasecmp (transport_protocol, "x-real-rdt")) {
636
682
            /* x-pn-tng/<protocol> */
637
683
            get_word_sep(lower_transport, sizeof(lower_transport), "/;,", &p);
638
684
            profile[0] = '\0';
639
685
            th->transport = RTSP_TRANSPORT_RDT;
640
686
        }
641
 
        if (!strcasecmp(lower_transport, "TCP"))
 
687
        if (!av_strcasecmp(lower_transport, "TCP"))
642
688
            th->lower_transport = RTSP_LOWER_TRANSPORT_TCP;
643
689
        else
644
690
            th->lower_transport = RTSP_LOWER_TRANSPORT_UDP;
812
858
        if (strstr(p, "GET_PARAMETER") &&
813
859
            method && !strcmp(method, "OPTIONS"))
814
860
            rt->get_parameter_supported = 1;
 
861
    } else if (av_stristart(p, "x-Accept-Dynamic-Rate:", &p) && rt) {
 
862
        p += strspn(p, SPACE_CHARS);
 
863
        rt->accept_dynamic_rate = atoi(p);
815
864
    }
816
865
}
817
866
 
1050
1099
    return 0;
1051
1100
}
1052
1101
 
1053
 
/**
1054
 
 * @return 0 on success, <0 on error, 1 if protocol is unavailable.
1055
 
 */
1056
1102
int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
1057
1103
                              int lower_transport, const char *real_challenge)
1058
1104
{
1059
1105
    RTSPState *rt = s->priv_data;
1060
 
    int rtx, j, i, err, interleave = 0;
 
1106
    int rtx = 0, j, i, err, interleave = 0;
1061
1107
    RTSPStream *rtsp_st;
1062
1108
    RTSPMessageHeader reply1, *reply = &reply1;
1063
1109
    char cmd[2048];
1078
1124
    for (j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) {
1079
1125
        char transport[2048];
1080
1126
 
1081
 
        /**
 
1127
        /*
1082
1128
         * WMS serves all UDP data over a single connection, the RTX, which
1083
1129
         * isn't necessarily the first in the SDP but has to be the first
1084
1130
         * to be set up, else the second/third SETUP will fail with a 461.
1118
1164
                                "?localport=%d", j);
1119
1165
                    /* we will use two ports per rtp stream (rtp and rtcp) */
1120
1166
                    j += 2;
1121
 
                    if (ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE) == 0)
 
1167
                    if (ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE,
 
1168
                                   &s->interrupt_callback, NULL) == 0)
1122
1169
                        goto rtp_opened;
1123
1170
                }
1124
1171
            }
1125
1172
 
1126
 
#if 0
1127
 
            /* then try on any port */
1128
 
            if (ffurl_open(&rtsp_st->rtp_handle, "rtp://", AVIO_FLAG_READ) < 0) {
1129
 
                err = AVERROR_INVALIDDATA;
1130
 
                goto fail;
1131
 
            }
1132
 
#else
1133
1173
            av_log(s, AV_LOG_ERROR, "Unable to open an input RTP port\n");
1134
1174
            err = AVERROR(EIO);
1135
1175
            goto fail;
1136
 
#endif
1137
1176
 
1138
1177
        rtp_opened:
1139
 
            port = rtp_get_local_rtp_port(rtsp_st->rtp_handle);
 
1178
            port = ff_rtp_get_local_rtp_port(rtsp_st->rtp_handle);
1140
1179
        have_port:
1141
1180
            snprintf(transport, sizeof(transport) - 1,
1142
1181
                     "%s/UDP;", trans_pref);
1151
1190
 
1152
1191
        /* RTP/TCP */
1153
1192
        else if (lower_transport == RTSP_LOWER_TRANSPORT_TCP) {
1154
 
            /** For WMS streams, the application streams are only used for
 
1193
            /* For WMS streams, the application streams are only used for
1155
1194
             * UDP. When trying to set it up for TCP streams, the server
1156
1195
             * will return an error. Therefore, we skip those streams. */
1157
1196
            if (rt->server_type == RTSP_SERVER_WMS &&
1180
1219
        snprintf(cmd, sizeof(cmd),
1181
1220
                 "Transport: %s\r\n",
1182
1221
                 transport);
 
1222
        if (rt->accept_dynamic_rate)
 
1223
            av_strlcat(cmd, "x-Dynamic-Rate: 0\r\n", sizeof(cmd));
1183
1224
        if (i == 0 && rt->server_type == RTSP_SERVER_REAL && CONFIG_RTPDEC) {
1184
1225
            char real_res[41], real_csum[9];
1185
1226
            ff_rdt_calc_response_and_checksum(real_res, real_csum,
1228
1269
        case RTSP_LOWER_TRANSPORT_UDP: {
1229
1270
            char url[1024], options[30] = "";
1230
1271
 
1231
 
            if (rt->filter_source)
 
1272
            if (rt->rtsp_flags & RTSP_FLAG_FILTER_SRC)
1232
1273
                av_strlcpy(options, "?connect=1", sizeof(options));
1233
1274
            /* Use source address if specified */
1234
1275
            if (reply->transports[0].source[0]) {
1240
1281
                            reply->transports[0].server_port_min, "%s", options);
1241
1282
            }
1242
1283
            if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) &&
1243
 
                rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) {
 
1284
                ff_rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) {
1244
1285
                err = AVERROR_INVALIDDATA;
1245
1286
                goto fail;
1246
1287
            }
1250
1291
             */
1251
1292
            if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && s->iformat &&
1252
1293
                CONFIG_RTPDEC)
1253
 
                rtp_send_punch_packets(rtsp_st->rtp_handle);
 
1294
                ff_rtp_send_punch_packets(rtsp_st->rtp_handle);
1254
1295
            break;
1255
1296
        }
1256
1297
        case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: {
1271
1312
                        namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
1272
1313
            ff_url_join(url, sizeof(url), "rtp", NULL, namebuf,
1273
1314
                        port, "?ttl=%d", ttl);
1274
 
            if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE) < 0) {
 
1315
            if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
 
1316
                           &s->interrupt_callback, NULL) < 0) {
1275
1317
                err = AVERROR_INVALIDDATA;
1276
1318
                goto fail;
1277
1319
            }
1318
1360
 
1319
1361
    if (!ff_network_init())
1320
1362
        return AVERROR(EIO);
 
1363
 
 
1364
    rt->control_transport = RTSP_MODE_PLAIN;
 
1365
    if (rt->lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_HTTP)) {
 
1366
        rt->lower_transport_mask = 1 << RTSP_LOWER_TRANSPORT_TCP;
 
1367
        rt->control_transport = RTSP_MODE_TUNNEL;
 
1368
    }
 
1369
    /* Only pass through valid flags from here */
 
1370
    rt->lower_transport_mask &= (1 << RTSP_LOWER_TRANSPORT_NB) - 1;
 
1371
 
1321
1372
redirect:
1322
 
    rt->control_transport = RTSP_MODE_PLAIN;
 
1373
    lower_transport_mask = rt->lower_transport_mask;
1323
1374
    /* extract hostname and port */
1324
1375
    av_url_split(NULL, 0, auth, sizeof(auth),
1325
1376
                 host, sizeof(host), &port, path, sizeof(path), s->filename);
1329
1380
    if (port < 0)
1330
1381
        port = RTSP_DEFAULT_PORT;
1331
1382
 
 
1383
#if FF_API_RTSP_URL_OPTIONS
1332
1384
    /* search for options */
1333
1385
    option_list = strrchr(path, '?');
1334
1386
    if (option_list) {
1336
1388
         * the options back into the same string. */
1337
1389
        filename = option_list;
1338
1390
        while (option_list) {
 
1391
            int handled = 1;
1339
1392
            /* move the option pointer */
1340
1393
            option = ++option_list;
1341
1394
            option_list = strchr(option_list, '&');
1353
1406
                lower_transport_mask |= (1<< RTSP_LOWER_TRANSPORT_TCP);
1354
1407
                rt->control_transport = RTSP_MODE_TUNNEL;
1355
1408
            } else if (!strcmp(option, "filter_src")) {
1356
 
                rt->filter_source = 1;
 
1409
                rt->rtsp_flags |= RTSP_FLAG_FILTER_SRC;
1357
1410
            } else {
1358
1411
                /* Write options back into the buffer, using memmove instead
1359
1412
                 * of strcpy since the strings may overlap. */
1361
1414
                memmove(++filename, option, len);
1362
1415
                filename += len;
1363
1416
                if (option_list) *filename = '&';
 
1417
                handled = 0;
1364
1418
            }
 
1419
            if (handled)
 
1420
                av_log(s, AV_LOG_WARNING, "Options passed via URL are "
 
1421
                                          "deprecated, use -rtsp_transport "
 
1422
                                          "and -rtsp_flags instead.\n");
1365
1423
        }
1366
1424
        *filename = 0;
1367
1425
    }
 
1426
#endif
1368
1427
 
1369
1428
    if (!lower_transport_mask)
1370
1429
        lower_transport_mask = (1 << RTSP_LOWER_TRANSPORT_NB) - 1;
1398
1457
                 av_get_random_seed(), av_get_random_seed());
1399
1458
 
1400
1459
        /* GET requests */
1401
 
        if (ffurl_alloc(&rt->rtsp_hd, httpname, AVIO_FLAG_READ) < 0) {
 
1460
        if (ffurl_alloc(&rt->rtsp_hd, httpname, AVIO_FLAG_READ,
 
1461
                        &s->interrupt_callback) < 0) {
1402
1462
            err = AVERROR(EIO);
1403
1463
            goto fail;
1404
1464
        }
1410
1470
                 "Pragma: no-cache\r\n"
1411
1471
                 "Cache-Control: no-cache\r\n",
1412
1472
                 sessioncookie);
1413
 
        ff_http_set_headers(rt->rtsp_hd, headers);
 
1473
        av_opt_set(rt->rtsp_hd->priv_data, "headers", headers, 0);
1414
1474
 
1415
1475
        /* complete the connection */
1416
 
        if (ffurl_connect(rt->rtsp_hd)) {
 
1476
        if (ffurl_connect(rt->rtsp_hd, NULL)) {
1417
1477
            err = AVERROR(EIO);
1418
1478
            goto fail;
1419
1479
        }
1420
1480
 
1421
1481
        /* POST requests */
1422
 
        if (ffurl_alloc(&rt->rtsp_hd_out, httpname, AVIO_FLAG_WRITE) < 0 ) {
 
1482
        if (ffurl_alloc(&rt->rtsp_hd_out, httpname, AVIO_FLAG_WRITE,
 
1483
                        &s->interrupt_callback) < 0 ) {
1423
1484
            err = AVERROR(EIO);
1424
1485
            goto fail;
1425
1486
        }
1433
1494
                 "Content-Length: 32767\r\n"
1434
1495
                 "Expires: Sun, 9 Jan 1972 00:00:00 GMT\r\n",
1435
1496
                 sessioncookie);
1436
 
        ff_http_set_headers(rt->rtsp_hd_out, headers);
1437
 
        ff_http_set_chunked_transfer_encoding(rt->rtsp_hd_out, 0);
 
1497
        av_opt_set(rt->rtsp_hd_out->priv_data, "headers", headers, 0);
 
1498
        av_opt_set(rt->rtsp_hd_out->priv_data, "chunked_post", "0", 0);
1438
1499
 
1439
1500
        /* Initialize the authentication state for the POST session. The HTTP
1440
1501
         * protocol implementation doesn't properly handle multi-pass
1455
1516
        ff_http_init_auth_state(rt->rtsp_hd_out, rt->rtsp_hd);
1456
1517
 
1457
1518
        /* complete the connection */
1458
 
        if (ffurl_connect(rt->rtsp_hd_out)) {
 
1519
        if (ffurl_connect(rt->rtsp_hd_out, NULL)) {
1459
1520
            err = AVERROR(EIO);
1460
1521
            goto fail;
1461
1522
        }
1462
1523
    } else {
1463
1524
        /* open the tcp connection */
1464
1525
        ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL);
1465
 
        if (ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE) < 0) {
 
1526
        if (ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE,
 
1527
                       &s->interrupt_callback, NULL) < 0) {
1466
1528
            err = AVERROR(EIO);
1467
1529
            goto fail;
1468
1530
        }
1482
1544
        cmd[0] = 0;
1483
1545
        if (rt->server_type == RTSP_SERVER_REAL)
1484
1546
            av_strlcat(cmd,
1485
 
                       /**
 
1547
                       /*
1486
1548
                        * The following entries are required for proper
1487
1549
                        * streaming from a Realmedia server. They are
1488
1550
                        * interdependent in some way although we currently
1489
1551
                        * don't quite understand how. Values were copied
1490
1552
                        * from mplayer SVN r23589.
1491
 
                        * @param CompanyID is a 16-byte ID in base64
1492
 
                        * @param ClientChallenge is a 16-byte ID in hex
 
1553
                        *   ClientChallenge is a 16-byte ID in hex
 
1554
                        *   CompanyID is a 16-byte ID in base64
1493
1555
                        */
1494
1556
                       "ClientChallenge: 9e26d33f2984236010ef6253fb1887f7\r\n"
1495
1557
                       "PlayerStarttime: [28/03/2003:22:50:23 00:00]\r\n"
1506
1568
        if (rt->server_type != RTSP_SERVER_REAL && reply->real_challenge[0]) {
1507
1569
            rt->server_type = RTSP_SERVER_REAL;
1508
1570
            continue;
1509
 
        } else if (!strncasecmp(reply->server, "WMServer/", 9)) {
 
1571
        } else if (!av_strncasecmp(reply->server, "WMServer/", 9)) {
1510
1572
            rt->server_type = RTSP_SERVER_WMS;
1511
1573
        } else if (rt->server_type == RTSP_SERVER_REAL)
1512
1574
            strcpy(real_challenge, reply->real_challenge);
1567
1629
    struct pollfd *p = rt->p;
1568
1630
 
1569
1631
    for (;;) {
1570
 
        if (url_interrupt_cb())
 
1632
        if (ff_check_interrupt(&s->interrupt_callback))
1571
1633
            return AVERROR_EXIT;
1572
1634
        if (wait_end && wait_end - av_gettime() < 0)
1573
1635
            return AVERROR(EAGAIN);
1584
1646
            if (rtsp_st->rtp_handle) {
1585
1647
                p[max_p].fd = ffurl_get_file_handle(rtsp_st->rtp_handle);
1586
1648
                p[max_p++].events = POLLIN;
1587
 
                p[max_p].fd = rtp_get_rtcp_file_handle(rtsp_st->rtp_handle);
 
1649
                p[max_p].fd = ff_rtp_get_rtcp_file_handle(rtsp_st->rtp_handle);
1588
1650
                p[max_p++].events = POLLIN;
1589
1651
            }
1590
1652
        }
1639
1701
        if (rt->transport == RTSP_TRANSPORT_RDT) {
1640
1702
            ret = ff_rdt_parse_packet(rt->cur_transport_priv, pkt, NULL, 0);
1641
1703
        } else
1642
 
            ret = rtp_parse_packet(rt->cur_transport_priv, pkt, NULL, 0);
 
1704
            ret = ff_rtp_parse_packet(rt->cur_transport_priv, pkt, NULL, 0);
1643
1705
        if (ret == 0) {
1644
1706
            rt->cur_transport_priv = NULL;
1645
1707
            return 0;
1687
1749
    case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:
1688
1750
        len = udp_read_packet(s, &rtsp_st, rt->recvbuf, RECVBUF_SIZE, wait_end);
1689
1751
        if (len > 0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP)
1690
 
            rtp_check_and_send_back_rr(rtsp_st->transport_priv, len);
 
1752
            ff_rtp_check_and_send_back_rr(rtsp_st->transport_priv, len);
1691
1753
        break;
1692
1754
    }
1693
1755
    if (len == AVERROR(EAGAIN) && first_queue_st &&
1694
1756
        rt->transport == RTSP_TRANSPORT_RTP) {
1695
1757
        rtsp_st = first_queue_st;
1696
 
        ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, NULL, 0);
 
1758
        ret = ff_rtp_parse_packet(rtsp_st->transport_priv, pkt, NULL, 0);
1697
1759
        goto end;
1698
1760
    }
1699
1761
    if (len < 0)
1703
1765
    if (rt->transport == RTSP_TRANSPORT_RDT) {
1704
1766
        ret = ff_rdt_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len);
1705
1767
    } else {
1706
 
        ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len);
 
1768
        ret = ff_rtp_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len);
1707
1769
        if (ret < 0) {
1708
1770
            /* Either bad packet, or a RTCP packet. Check if the
1709
1771
             * first_rtcp_ntp_time field was initialized. */
1807
1869
                    namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
1808
1870
        ff_url_join(url, sizeof(url), "rtp", NULL,
1809
1871
                    namebuf, rtsp_st->sdp_port,
1810
 
                    "?localport=%d&ttl=%d", rtsp_st->sdp_port,
1811
 
                    rtsp_st->sdp_ttl);
1812
 
        if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE) < 0) {
 
1872
                    "?localport=%d&ttl=%d&connect=%d", rtsp_st->sdp_port,
 
1873
                    rtsp_st->sdp_ttl,
 
1874
                    rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0);
 
1875
        if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
 
1876
                       &s->interrupt_callback, NULL) < 0) {
1813
1877
            err = AVERROR_INVALIDDATA;
1814
1878
            goto fail;
1815
1879
        }
1830
1894
    return 0;
1831
1895
}
1832
1896
 
 
1897
static const AVClass sdp_demuxer_class = {
 
1898
    .class_name     = "SDP demuxer",
 
1899
    .item_name      = av_default_item_name,
 
1900
    .option         = sdp_options,
 
1901
    .version        = LIBAVUTIL_VERSION_INT,
 
1902
};
 
1903
 
1833
1904
AVInputFormat ff_sdp_demuxer = {
1834
 
    "sdp",
1835
 
    NULL_IF_CONFIG_SMALL("SDP"),
1836
 
    sizeof(RTSPState),
1837
 
    sdp_probe,
1838
 
    sdp_read_header,
1839
 
    ff_rtsp_fetch_packet,
1840
 
    sdp_read_close,
 
1905
    .name           = "sdp",
 
1906
    .long_name      = NULL_IF_CONFIG_SMALL("SDP"),
 
1907
    .priv_data_size = sizeof(RTSPState),
 
1908
    .read_probe     = sdp_probe,
 
1909
    .read_header    = sdp_read_header,
 
1910
    .read_packet    = ff_rtsp_fetch_packet,
 
1911
    .read_close     = sdp_read_close,
 
1912
    .priv_class     = &sdp_demuxer_class
1841
1913
};
1842
1914
#endif /* CONFIG_SDP_DEMUXER */
1843
1915
 
1861
1933
    struct sockaddr_storage addr;
1862
1934
    AVIOContext pb;
1863
1935
    socklen_t addrlen = sizeof(addr);
 
1936
    RTSPState *rt = s->priv_data;
1864
1937
 
1865
1938
    if (!ff_network_init())
1866
1939
        return AVERROR(EIO);
1867
1940
 
1868
 
    ret = ffurl_open(&in, s->filename, AVIO_FLAG_READ);
 
1941
    ret = ffurl_open(&in, s->filename, AVIO_FLAG_READ,
 
1942
                     &s->interrupt_callback, NULL);
1869
1943
    if (ret)
1870
1944
        goto fail;
1871
1945
 
1923
1997
    /* sdp_read_header initializes this again */
1924
1998
    ff_network_close();
1925
1999
 
 
2000
    rt->media_type_mask = (1 << (AVMEDIA_TYPE_DATA+1)) - 1;
 
2001
 
1926
2002
    ret = sdp_read_header(s, ap);
1927
2003
    s->pb = NULL;
1928
2004
    return ret;
1934
2010
    return ret;
1935
2011
}
1936
2012
 
 
2013
static const AVClass rtp_demuxer_class = {
 
2014
    .class_name     = "RTP demuxer",
 
2015
    .item_name      = av_default_item_name,
 
2016
    .option         = rtp_options,
 
2017
    .version        = LIBAVUTIL_VERSION_INT,
 
2018
};
 
2019
 
1937
2020
AVInputFormat ff_rtp_demuxer = {
1938
 
    "rtp",
1939
 
    NULL_IF_CONFIG_SMALL("RTP input format"),
1940
 
    sizeof(RTSPState),
1941
 
    rtp_probe,
1942
 
    rtp_read_header,
1943
 
    ff_rtsp_fetch_packet,
1944
 
    sdp_read_close,
 
2021
    .name           = "rtp",
 
2022
    .long_name      = NULL_IF_CONFIG_SMALL("RTP input format"),
 
2023
    .priv_data_size = sizeof(RTSPState),
 
2024
    .read_probe     = rtp_probe,
 
2025
    .read_header    = rtp_read_header,
 
2026
    .read_packet    = ff_rtsp_fetch_packet,
 
2027
    .read_close     = sdp_read_close,
1945
2028
    .flags = AVFMT_NOFILE,
 
2029
    .priv_class     = &rtp_demuxer_class
1946
2030
};
1947
2031
#endif /* CONFIG_RTP_DEMUXER */
1948
2032