Revision e9dea59f

View differences:

libavformat/Makefile
159 159
                                            rtp_aac.o     \
160 160
                                            rtpenc_h264.o \
161 161
                                            avc.o
162
OBJS-$(CONFIG_RTSP_DEMUXER)              += rtsp.o
162
OBJS-$(CONFIG_RTSP_DEMUXER)              += rdt.o rtsp.o
163 163
OBJS-$(CONFIG_SDP_DEMUXER)               += rtsp.o rtp.o rtpdec.o rtp_h264.o
164 164
OBJS-$(CONFIG_SEGAFILM_DEMUXER)          += segafilm.o
165 165
OBJS-$(CONFIG_SHORTEN_DEMUXER)           += raw.o
libavformat/rdt.c
1
/*
2
 * Realmedia RTSP protocol (RDT) support.
3
 * Copyright (c) 2007 Ronald S. Bultje
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
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
20
 */
21

  
22
/**
23
 * @file rdt.c
24
 * @brief Realmedia RTSP protocol (RDT) support
25
 * @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
26
 */
27

  
28
#include "avformat.h"
29
#include "libavutil/avstring.h"
30
#include "rdt.h"
31
#include "libavutil/base64.h"
32
#include "libavutil/md5.h"
33
#include "rm.h"
34
#include "internal.h"
35

  
36
void
37
ff_rdt_calc_response_and_checksum(char response[41], char chksum[9],
38
                                  const char *challenge)
39
{
40
    int ch_len = strlen (challenge), i;
41
    unsigned char zres[16],
42
        buf[64] = { 0xa1, 0xe9, 0x14, 0x9d, 0x0e, 0x6b, 0x3b, 0x59 };
43
#define XOR_TABLE_SIZE 37
44
    const unsigned char xor_table[XOR_TABLE_SIZE] = {
45
        0x05, 0x18, 0x74, 0xd0, 0x0d, 0x09, 0x02, 0x53,
46
        0xc0, 0x01, 0x05, 0x05, 0x67, 0x03, 0x19, 0x70,
47
        0x08, 0x27, 0x66, 0x10, 0x10, 0x72, 0x08, 0x09,
48
        0x63, 0x11, 0x03, 0x71, 0x08, 0x08, 0x70, 0x02,
49
        0x10, 0x57, 0x05, 0x18, 0x54 };
50

  
51
    /* some (length) checks */
52
    if (ch_len == 40) /* what a hack... */
53
        ch_len = 32;
54
    else if (ch_len > 56)
55
        ch_len = 56;
56
    memcpy(buf + 8, challenge, ch_len);
57

  
58
    /* xor challenge bytewise with xor_table */
59
    for (i = 0; i < XOR_TABLE_SIZE; i++)
60
        buf[8 + i] ^= xor_table[i];
61

  
62
    av_md5_sum(zres, buf, 64);
63
    ff_data_to_hex(response, zres, 16);
64
    for (i=0;i<32;i++) response[i] = tolower(response[i]);
65

  
66
    /* add tail */
67
    strcpy (response + 32, "01d0a8e3");
68

  
69
    /* calculate checksum */
70
    for (i = 0; i < 8; i++)
71
        chksum[i] = response[i * 4];
72
    chksum[8] = 0;
73
}
libavformat/rdt.h
1
/*
2
 * Realmedia RTSP (RDT) definitions
3
 * Copyright (c) 2007 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
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
20
 */
21

  
22
#ifndef AVFORMAT_RDT_H
23
#define AVFORMAT_RDT_H
24

  
25
/**
26
 * Calculate the response (RealChallenge2 in the RTSP header) to the
27
 * challenge (RealChallenge1 in the RTSP header from the Real/Helix
28
 * server), which is used as some sort of client validation.
29
 *
30
 * @param response pointer to response buffer, it should be at least 41 bytes
31
 *                 (40 data + 1 zero) bytes long.
32
 * @param chksum pointer to buffer containing a checksum of the response,
33
 *               it should be at least 9 (8 data + 1 zero) bytes long.
34
 * @param challenge pointer to the RealChallenge1 value provided by the
35
 *                  server.
36
 */
37
void ff_rdt_calc_response_and_checksum(char response[41], char chksum[9],
38
                                       const char *challenge);
39

  
40
#endif /* AVFORMAT_RDT_H */
libavformat/rtsp.c
32 32
#include "rtsp.h"
33 33

  
34 34
#include "rtp_internal.h"
35
#include "rdt.h"
35 36

  
36 37
//#define DEBUG
37 38
//#define DEBUG_RTP_TCP
......
870 871
 * @returns 0 on success, <0 on error, 1 if protocol is unavailable.
871 872
 */
872 873
static int
873
make_setup_request (AVFormatContext *s, const char *host, int port, int protocol)
874
make_setup_request (AVFormatContext *s, const char *host, int port,
875
                    int protocol, const char *real_challenge)
874 876
{
875 877
    RTSPState *rt = s->priv_data;
876 878
    int j, i, err;
......
878 880
    AVStream *st;
879 881
    RTSPHeader reply1, *reply = &reply1;
880 882
    char cmd[2048];
883
    const char *trans_pref;
884

  
885
    if (rt->server_type == RTSP_SERVER_RDT)
886
        trans_pref = "x-pn-tng";
887
    else
888
        trans_pref = "RTP/AVP";
881 889

  
882 890
    /* for each stream, make the setup request */
883 891
    /* XXX: we assume the same server is used for the control of each
......
918 926
            if (transport[0] != '\0')
919 927
                av_strlcat(transport, ",", sizeof(transport));
920 928
            snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1,
921
                     "RTP/AVP/UDP;unicast;client_port=%d-%d",
922
                     port, port + 1);
929
                     "%s/UDP;unicast;client_port=%d",
930
                     trans_pref, port);
931
            if (rt->server_type == RTSP_SERVER_RTP)
932
                av_strlcatf(transport, sizeof(transport), "-%d", port + 1);
923 933
        }
924 934

  
925 935
        /* RTP/TCP */
......
927 937
            if (transport[0] != '\0')
928 938
                av_strlcat(transport, ",", sizeof(transport));
929 939
            snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1,
930
                     "RTP/AVP/TCP");
940
                     "%s/TCP", trans_pref);
931 941
        }
932 942

  
933 943
        else if (protocol == RTSP_PROTOCOL_RTP_UDP_MULTICAST) {
......
935 945
                av_strlcat(transport, ",", sizeof(transport));
936 946
            snprintf(transport + strlen(transport),
937 947
                     sizeof(transport) - strlen(transport) - 1,
938
                     "RTP/AVP/UDP;multicast");
948
                     "%s/UDP;multicast", trans_pref);
939 949
        }
950
        if (rt->server_type == RTSP_SERVER_RDT)
951
            av_strlcat(transport, ";mode=play", sizeof(transport));
940 952
        snprintf(cmd, sizeof(cmd),
941 953
                 "SETUP %s RTSP/1.0\r\n"
942 954
                 "Transport: %s\r\n",
943 955
                 rtsp_st->control_url, transport);
956
        if (i == 0 && rt->server_type == RTSP_SERVER_RDT) {
957
            char real_res[41], real_csum[9];
958
            ff_rdt_calc_response_and_checksum(real_res, real_csum,
959
                                              real_challenge);
960
            av_strlcatf(cmd, sizeof(cmd),
961
                        "If-Match: %s\r\n"
962
                        "RealChallenge2: %s, sd=%s\r\n",
963
                        rt->session_id, real_res, real_csum);
964
        }
944 965
        rtsp_send_cmd(s, cmd, reply, NULL);
945 966
        if (reply->status_code == 461 /* Unsupported protocol */ && i == 0) {
946 967
            err = 1;
......
1155 1176
    do {
1156 1177
        int protocol = ff_log2_tab[protocol_mask & ~(protocol_mask - 1)];
1157 1178

  
1158
        err = make_setup_request(s, host, port, protocol);
1179
        err = make_setup_request(s, host, port, protocol,
1180
                                 rt->server_type == RTSP_SERVER_RDT ?
1181
                                     real_challenge : NULL);
1159 1182
        if (err < 0)
1160 1183
            goto fail;
1161 1184
        protocol_mask &= ~(1 << protocol);

Also available in: Unified diff