annotate rdt.c @ 4037:5f65cbe25494 libavformat

Fix memleak caused by the fact that url_open_buf() allocates a context when calling, but url_close_buf() doesn't free it. The better solution is to not allocate it at all, init it with init_put_byte() and then not have to close it at all. In the case where we do need to hold it around for longer than within the function context, we allocate it with av_alloc_put_byte() and free it with av_free() instead. Discussed in ML thread "[PATCH] fix small memleak in rdt.c".
author rbultje
date Mon, 17 Nov 2008 14:23:20 +0000
parents 1349c277efbd
children 69cdec2e03b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3876
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
1 /*
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
2 * Realmedia RTSP protocol (RDT) support.
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
3 * Copyright (c) 2007 Ronald S. Bultje
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
4 *
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
5 * This file is part of FFmpeg.
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
6 *
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
11 *
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
15 * Lesser General Public License for more details.
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
16 *
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
20 */
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
21
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
22 /**
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
23 * @file rdt.c
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
24 * @brief Realmedia RTSP protocol (RDT) support
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
25 * @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
26 */
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
27
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
28 #include "avformat.h"
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
29 #include "libavutil/avstring.h"
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
30 #include "rtp_internal.h"
3876
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
31 #include "rdt.h"
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
32 #include "libavutil/base64.h"
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
33 #include "libavutil/md5.h"
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
34 #include "rm.h"
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
35 #include "internal.h"
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
36
3979
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
37 struct RDTDemuxContext {
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
38 AVFormatContext *ic;
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
39 AVStream *st;
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
40 void *dynamic_protocol_context;
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
41 DynamicPayloadPacketHandlerProc parse_packet;
4025
4a266106f604 Rename variables in ff_rdt_parse_header() and callers to match the
rbultje
parents: 4023
diff changeset
42 uint32_t prev_set_id, prev_timestamp;
3979
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
43 };
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
44
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
45 RDTDemuxContext *
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
46 ff_rdt_parse_open(AVFormatContext *ic, AVStream *st,
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
47 void *priv_data, RTPDynamicProtocolHandler *handler)
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
48 {
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
49 RDTDemuxContext *s = av_mallocz(sizeof(RDTDemuxContext));
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
50 if (!s)
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
51 return NULL;
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
52
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
53 s->ic = ic;
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
54 s->st = st;
4025
4a266106f604 Rename variables in ff_rdt_parse_header() and callers to match the
rbultje
parents: 4023
diff changeset
55 s->prev_set_id = -1;
4a266106f604 Rename variables in ff_rdt_parse_header() and callers to match the
rbultje
parents: 4023
diff changeset
56 s->prev_timestamp = -1;
3979
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
57 s->parse_packet = handler->parse_packet;
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
58 s->dynamic_protocol_context = priv_data;
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
59
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
60 return s;
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
61 }
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
62
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
63 void
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
64 ff_rdt_parse_close(RDTDemuxContext *s)
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
65 {
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
66 av_free(s);
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
67 }
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
68
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
69 struct PayloadContext {
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
70 AVFormatContext *rmctx;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
71 uint8_t *mlti_data;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
72 unsigned int mlti_data_size;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
73 char buffer[RTP_MAX_PACKET_LENGTH + FF_INPUT_BUFFER_PADDING_SIZE];
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
74 };
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
75
3876
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
76 void
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
77 ff_rdt_calc_response_and_checksum(char response[41], char chksum[9],
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
78 const char *challenge)
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
79 {
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
80 int ch_len = strlen (challenge), i;
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
81 unsigned char zres[16],
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
82 buf[64] = { 0xa1, 0xe9, 0x14, 0x9d, 0x0e, 0x6b, 0x3b, 0x59 };
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
83 #define XOR_TABLE_SIZE 37
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
84 const unsigned char xor_table[XOR_TABLE_SIZE] = {
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
85 0x05, 0x18, 0x74, 0xd0, 0x0d, 0x09, 0x02, 0x53,
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
86 0xc0, 0x01, 0x05, 0x05, 0x67, 0x03, 0x19, 0x70,
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
87 0x08, 0x27, 0x66, 0x10, 0x10, 0x72, 0x08, 0x09,
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
88 0x63, 0x11, 0x03, 0x71, 0x08, 0x08, 0x70, 0x02,
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
89 0x10, 0x57, 0x05, 0x18, 0x54 };
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
90
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
91 /* some (length) checks */
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
92 if (ch_len == 40) /* what a hack... */
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
93 ch_len = 32;
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
94 else if (ch_len > 56)
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
95 ch_len = 56;
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
96 memcpy(buf + 8, challenge, ch_len);
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
97
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
98 /* xor challenge bytewise with xor_table */
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
99 for (i = 0; i < XOR_TABLE_SIZE; i++)
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
100 buf[8 + i] ^= xor_table[i];
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
101
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
102 av_md5_sum(zres, buf, 64);
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
103 ff_data_to_hex(response, zres, 16);
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
104 for (i=0;i<32;i++) response[i] = tolower(response[i]);
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
105
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
106 /* add tail */
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
107 strcpy (response + 32, "01d0a8e3");
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
108
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
109 /* calculate checksum */
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
110 for (i = 0; i < 8; i++)
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
111 chksum[i] = response[i * 4];
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
112 chksum[8] = 0;
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
113 }
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
114
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
115 static int
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
116 rdt_load_mdpr (PayloadContext *rdt, AVStream *st, int rule_nr)
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
117 {
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
118 ByteIOContext pb;
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
119 int size;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
120 uint32_t tag;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
121
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
122 /**
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
123 * Layout of the MLTI chunk:
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
124 * 4:MLTI
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
125 * 2:<number of streams>
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
126 * Then for each stream ([number_of_streams] times):
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
127 * 2:<mdpr index>
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
128 * 2:<number of mdpr chunks>
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
129 * Then for each mdpr chunk ([number_of_mdpr_chunks] times):
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
130 * 4:<size>
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
131 * [size]:<data>
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
132 * we skip MDPR chunks until we reach the one of the stream
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
133 * we're interested in, and forward that ([size]+[data]) to
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
134 * the RM demuxer to parse the stream-specific header data.
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
135 */
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
136 if (!rdt->mlti_data)
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
137 return -1;
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
138 init_put_byte(&pb, rdt->mlti_data, rdt->mlti_data_size, 0,
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
139 NULL, NULL, NULL, NULL);
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
140 tag = get_le32(&pb);
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
141 if (tag == MKTAG('M', 'L', 'T', 'I')) {
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
142 int num, chunk_nr;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
143
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
144 /* read index of MDPR chunk numbers */
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
145 num = get_be16(&pb);
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
146 if (rule_nr < 0 || rule_nr >= num)
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
147 return -1;
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
148 url_fskip(&pb, rule_nr * 2);
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
149 chunk_nr = get_be16(&pb);
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
150 url_fskip(&pb, (num - 1 - rule_nr) * 2);
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
151
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
152 /* read MDPR chunks */
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
153 num = get_be16(&pb);
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
154 if (chunk_nr >= num)
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
155 return -1;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
156 while (chunk_nr--)
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
157 url_fskip(&pb, get_be32(&pb));
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
158 size = get_be32(&pb);
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
159 } else {
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
160 size = rdt->mlti_data_size;
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
161 url_fseek(&pb, 0, SEEK_SET);
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
162 }
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
163 if (ff_rm_read_mdpr_codecdata(rdt->rmctx, &pb, st, size) < 0)
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
164 return -1;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
165
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
166 return 0;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
167 }
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
168
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
169 /**
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
170 * Actual data handling.
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
171 */
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
172
3962
72efef66f566 This patch refactors RDT packet header parsing so that it can be used in
rbultje
parents: 3959
diff changeset
173 int
72efef66f566 This patch refactors RDT packet header parsing so that it can be used in
rbultje
parents: 3959
diff changeset
174 ff_rdt_parse_header(const uint8_t *buf, int len,
4029
9a0a46d465ae Add is_keyframe param to ff_rdt_parse_header(). See ML discussion in
rbultje
parents: 4025
diff changeset
175 int *set_id, int *seq_no, int *stream_id,
9a0a46d465ae Add is_keyframe param to ff_rdt_parse_header(). See ML discussion in
rbultje
parents: 4025
diff changeset
176 int *is_keyframe, uint32_t *timestamp)
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
177 {
3962
72efef66f566 This patch refactors RDT packet header parsing so that it can be used in
rbultje
parents: 3959
diff changeset
178 int consumed = 10;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
179
4032
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
180 /* skip status packets */
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
181 while (len >= 5 && buf[1] == 0xFF /* status packet */) {
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
182 int pkt_len;
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
183
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
184 if (!(buf[0] & 0x80))
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
185 return -1; /* not followed by a data packet */
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
186
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
187 pkt_len = AV_RB16(buf+3);
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
188 buf += pkt_len;
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
189 len -= pkt_len;
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
190 consumed += pkt_len;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
191 }
3962
72efef66f566 This patch refactors RDT packet header parsing so that it can be used in
rbultje
parents: 3959
diff changeset
192 if (len < 10)
72efef66f566 This patch refactors RDT packet header parsing so that it can be used in
rbultje
parents: 3959
diff changeset
193 return -1;
4023
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
194 /**
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
195 * Layout of the header (in bits):
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
196 * 1: len_included
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
197 * Flag indicating whether this header includes a length field;
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
198 * this can be used to concatenate multiple RDT packets in a
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
199 * single UDP/TCP data frame and is used to precede RDT data
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
200 * by stream status packets
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
201 * 1: need_reliable
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
202 * Flag indicating whether this header includes a "reliable
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
203 * sequence number"; these are apparently sequence numbers of
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
204 * data packets alone. For data packets, this flag is always
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
205 * set, according to the Real documentation [1]
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
206 * 5: set_id
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
207 * ID of a set of streams of identical content, possibly with
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
208 * different codecs or bitrates
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
209 * 1: is_reliable
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
210 * Flag set for certain streams deemed less tolerable for packet
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
211 * loss
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
212 * 16: seq_no
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
213 * Packet sequence number; if >=0xFF00, this is a non-data packet
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
214 * containing stream status info, the second byte indicates the
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
215 * type of status packet (see wireshark docs / source code [2])
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
216 * if (len_included) {
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
217 * 16: packet_len
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
218 * } else {
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
219 * packet_len = remainder of UDP/TCP frame
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
220 * }
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
221 * 1: is_back_to_back
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
222 * Back-to-Back flag; used for timing, set for one in every 10
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
223 * packets, according to the Real documentation [1]
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
224 * 1: is_slow_data
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
225 * Slow-data flag; currently unused, according to Real docs [1]
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
226 * 5: stream_id
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
227 * ID of the stream within this particular set of streams
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
228 * 1: is_no_keyframe
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
229 * Non-keyframe flag (unset if packet belongs to a keyframe)
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
230 * 32: timestamp (PTS)
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
231 * if (set_id == 0x1F) {
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
232 * 16: set_id (extended set-of-streams ID; see set_id)
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
233 * }
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
234 * if (need_reliable) {
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
235 * 16: reliable_seq_no
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
236 * Reliable sequence number (see need_reliable)
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
237 * }
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
238 * if (stream_id == 0x3F) {
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
239 * 16: stream_id (extended stream ID; see stream_id)
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
240 * }
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
241 * [1] https://protocol.helixcommunity.org/files/2005/devdocs/RDT_Feature_Level_20.txt
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
242 * [2] http://www.wireshark.org/docs/dfref/r/rdt.html and
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
243 * http://anonsvn.wireshark.org/viewvc/trunk/epan/dissectors/packet-rdt.c
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
244 */
4030
c7354edc3496 Reindent after r15833.
rbultje
parents: 4029
diff changeset
245 if (set_id) *set_id = (buf[0]>>1) & 0x1f;
c7354edc3496 Reindent after r15833.
rbultje
parents: 4029
diff changeset
246 if (seq_no) *seq_no = AV_RB16(buf+1);
c7354edc3496 Reindent after r15833.
rbultje
parents: 4029
diff changeset
247 if (timestamp) *timestamp = AV_RB32(buf+4);
c7354edc3496 Reindent after r15833.
rbultje
parents: 4029
diff changeset
248 if (stream_id) *stream_id = (buf[3]>>1) & 0x1f;
4029
9a0a46d465ae Add is_keyframe param to ff_rdt_parse_header(). See ML discussion in
rbultje
parents: 4025
diff changeset
249 if (is_keyframe) *is_keyframe = !(buf[3] & 0x1);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
250
3962
72efef66f566 This patch refactors RDT packet header parsing so that it can be used in
rbultje
parents: 3959
diff changeset
251 return consumed;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
252 }
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
253
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
254 /**< return 0 on packet, no more left, 1 on packet, 1 on partial packet... */
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
255 static int
3976
64056a0c38ce Change function prototype of RTPDynamicPayloadHandler.parse_packet() to
rbultje
parents: 3975
diff changeset
256 rdt_parse_packet (PayloadContext *rdt, AVStream *st,
64056a0c38ce Change function prototype of RTPDynamicPayloadHandler.parse_packet() to
rbultje
parents: 3975
diff changeset
257 AVPacket *pkt, uint32_t *timestamp,
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
258 const uint8_t *buf, int len, int flags)
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
259 {
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
260 int seq = 1, res;
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
261 ByteIOContext pb;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
262 RMContext *rm = rdt->rmctx->priv_data;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
263
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
264 if (rm->audio_pkt_cnt == 0) {
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
265 int pos;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
266
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
267 init_put_byte(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
268 flags = (flags & PKT_FLAG_KEY) ? 2 : 0;
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
269 res = ff_rm_parse_packet (rdt->rmctx, &pb, st, len, pkt,
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
270 &seq, &flags, timestamp);
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
271 pos = url_ftell(&pb);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
272 if (res < 0)
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
273 return res;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
274 if (rm->audio_pkt_cnt > 0 &&
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
275 st->codec->codec_id == CODEC_ID_AAC) {
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
276 memcpy (rdt->buffer, buf + pos, len - pos);
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
277 rdt->rmctx->pb = av_alloc_put_byte (rdt->buffer, len - pos, 0,
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
278 NULL, NULL, NULL, NULL);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
279 }
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
280 } else {
4036
1349c277efbd Add ByteIOContext argument to public ff_rm_* functions so that we can
rbultje
parents: 4032
diff changeset
281 ff_rm_retrieve_cache (rdt->rmctx, rdt->rmctx->pb, st, pkt);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
282 if (rm->audio_pkt_cnt == 0 &&
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
283 st->codec->codec_id == CODEC_ID_AAC)
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
284 av_freep(&rdt->rmctx->pb);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
285 }
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
286 pkt->stream_index = st->index;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
287 pkt->pts = *timestamp;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
288
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
289 return rm->audio_pkt_cnt > 0;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
290 }
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
291
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
292 int
3979
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
293 ff_rdt_parse_packet(RDTDemuxContext *s, AVPacket *pkt,
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
294 const uint8_t *buf, int len)
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
295 {
4029
9a0a46d465ae Add is_keyframe param to ff_rdt_parse_header(). See ML discussion in
rbultje
parents: 4025
diff changeset
296 int seq_no, flags = 0, stream_id, set_id, is_keyframe;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
297 uint32_t timestamp;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
298 int rv= 0;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
299
3963
dbe779f54647 Use parse_packet vfunc in RTPDynamicProtocolHandler instead of hardcoding
rbultje
parents: 3962
diff changeset
300 if (!s->parse_packet)
dbe779f54647 Use parse_packet vfunc in RTPDynamicProtocolHandler instead of hardcoding
rbultje
parents: 3962
diff changeset
301 return -1;
dbe779f54647 Use parse_packet vfunc in RTPDynamicProtocolHandler instead of hardcoding
rbultje
parents: 3962
diff changeset
302
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
303 if (!buf) {
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
304 /* return the next packets, if any */
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
305 timestamp= 0; ///< Should not be used if buf is NULL, but should be set to the timestamp of the packet returned....
3976
64056a0c38ce Change function prototype of RTPDynamicPayloadHandler.parse_packet() to
rbultje
parents: 3975
diff changeset
306 rv= s->parse_packet(s->dynamic_protocol_context,
64056a0c38ce Change function prototype of RTPDynamicPayloadHandler.parse_packet() to
rbultje
parents: 3975
diff changeset
307 s->st, pkt, &timestamp, NULL, 0, flags);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
308 return rv;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
309 }
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
310
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
311 if (len < 12)
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
312 return -1;
4029
9a0a46d465ae Add is_keyframe param to ff_rdt_parse_header(). See ML discussion in
rbultje
parents: 4025
diff changeset
313 rv = ff_rdt_parse_header(buf, len, &set_id, &seq_no, &stream_id, &is_keyframe, &timestamp);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
314 if (rv < 0)
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
315 return rv;
4029
9a0a46d465ae Add is_keyframe param to ff_rdt_parse_header(). See ML discussion in
rbultje
parents: 4025
diff changeset
316 if (is_keyframe && (set_id != s->prev_set_id || timestamp != s->prev_timestamp)) {
3962
72efef66f566 This patch refactors RDT packet header parsing so that it can be used in
rbultje
parents: 3959
diff changeset
317 flags |= PKT_FLAG_KEY;
4025
4a266106f604 Rename variables in ff_rdt_parse_header() and callers to match the
rbultje
parents: 4023
diff changeset
318 s->prev_set_id = set_id;
4a266106f604 Rename variables in ff_rdt_parse_header() and callers to match the
rbultje
parents: 4023
diff changeset
319 s->prev_timestamp = timestamp;
3962
72efef66f566 This patch refactors RDT packet header parsing so that it can be used in
rbultje
parents: 3959
diff changeset
320 }
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
321 buf += rv;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
322 len -= rv;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
323
3976
64056a0c38ce Change function prototype of RTPDynamicPayloadHandler.parse_packet() to
rbultje
parents: 3975
diff changeset
324 rv = s->parse_packet(s->dynamic_protocol_context,
64056a0c38ce Change function prototype of RTPDynamicPayloadHandler.parse_packet() to
rbultje
parents: 3975
diff changeset
325 s->st, pkt, &timestamp, buf, len, flags);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
326
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
327 return rv;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
328 }
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
329
3903
aeb79f68ba7e Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents: 3902
diff changeset
330 void
3959
ed6f6aa977ec Remove access to rdt_data struct in functions called outside of the
rbultje
parents: 3905
diff changeset
331 ff_rdt_subscribe_rule (char *cmd, int size,
3903
aeb79f68ba7e Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents: 3902
diff changeset
332 int stream_nr, int rule_nr)
aeb79f68ba7e Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents: 3902
diff changeset
333 {
3959
ed6f6aa977ec Remove access to rdt_data struct in functions called outside of the
rbultje
parents: 3905
diff changeset
334 av_strlcatf(cmd, size, "stream=%d;rule=%d,stream=%d;rule=%d",
ed6f6aa977ec Remove access to rdt_data struct in functions called outside of the
rbultje
parents: 3905
diff changeset
335 stream_nr, rule_nr * 2, stream_nr, rule_nr * 2 + 1);
ed6f6aa977ec Remove access to rdt_data struct in functions called outside of the
rbultje
parents: 3905
diff changeset
336 }
ed6f6aa977ec Remove access to rdt_data struct in functions called outside of the
rbultje
parents: 3905
diff changeset
337
ed6f6aa977ec Remove access to rdt_data struct in functions called outside of the
rbultje
parents: 3905
diff changeset
338 void
3979
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
339 ff_rdt_subscribe_rule2 (RDTDemuxContext *s, char *cmd, int size,
3959
ed6f6aa977ec Remove access to rdt_data struct in functions called outside of the
rbultje
parents: 3905
diff changeset
340 int stream_nr, int rule_nr)
ed6f6aa977ec Remove access to rdt_data struct in functions called outside of the
rbultje
parents: 3905
diff changeset
341 {
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
342 PayloadContext *rdt = s->dynamic_protocol_context;
3903
aeb79f68ba7e Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents: 3902
diff changeset
343
3959
ed6f6aa977ec Remove access to rdt_data struct in functions called outside of the
rbultje
parents: 3905
diff changeset
344 rdt_load_mdpr(rdt, s->st, rule_nr * 2);
3903
aeb79f68ba7e Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents: 3902
diff changeset
345 }
aeb79f68ba7e Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents: 3902
diff changeset
346
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
347 static unsigned char *
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
348 rdt_parse_b64buf (unsigned int *target_len, const char *p)
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
349 {
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
350 unsigned char *target;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
351 int len = strlen(p);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
352 if (*p == '\"') {
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
353 p++;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
354 len -= 2; /* skip embracing " at start/end */
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
355 }
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
356 *target_len = len * 3 / 4;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
357 target = av_mallocz(*target_len + FF_INPUT_BUFFER_PADDING_SIZE);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
358 av_base64_decode(target, p, *target_len);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
359 return target;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
360 }
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
361
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
362 static int
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
363 rdt_parse_sdp_line (AVStream *stream, PayloadContext *rdt, const char *line)
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
364 {
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
365 const char *p = line;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
366
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
367 if (av_strstart(p, "OpaqueData:buffer;", &p)) {
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
368 rdt->mlti_data = rdt_parse_b64buf(&rdt->mlti_data_size, p);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
369 } else if (av_strstart(p, "StartTime:integer;", &p))
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
370 stream->first_dts = atoi(p);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
371
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
372 return 0;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
373 }
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
374
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
375 static PayloadContext *
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
376 rdt_new_extradata (void)
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
377 {
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
378 PayloadContext *rdt = av_mallocz(sizeof(PayloadContext));
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
379
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
380 av_open_input_stream(&rdt->rmctx, NULL, "", &rdt_demuxer, NULL);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
381
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
382 return rdt;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
383 }
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
384
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
385 static void
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
386 rdt_free_extradata (PayloadContext *rdt)
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
387 {
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
388 if (rdt->rmctx)
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
389 av_close_input_stream(rdt->rmctx);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
390 av_freep(&rdt->mlti_data);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
391 av_free(rdt);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
392 }
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
393
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
394 #define RDT_HANDLER(n, s, t) \
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
395 static RTPDynamicProtocolHandler ff_rdt_ ## n ## _handler = { \
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
396 s, \
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
397 t, \
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
398 CODEC_ID_NONE, \
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
399 rdt_parse_sdp_line, \
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
400 rdt_new_extradata, \
3963
dbe779f54647 Use parse_packet vfunc in RTPDynamicProtocolHandler instead of hardcoding
rbultje
parents: 3962
diff changeset
401 rdt_free_extradata, \
dbe779f54647 Use parse_packet vfunc in RTPDynamicProtocolHandler instead of hardcoding
rbultje
parents: 3962
diff changeset
402 rdt_parse_packet \
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
403 };
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
404
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
405 RDT_HANDLER(live_video, "x-pn-multirate-realvideo-live", CODEC_TYPE_VIDEO);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
406 RDT_HANDLER(live_audio, "x-pn-multirate-realaudio-live", CODEC_TYPE_AUDIO);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
407 RDT_HANDLER(video, "x-pn-realvideo", CODEC_TYPE_VIDEO);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
408 RDT_HANDLER(audio, "x-pn-realaudio", CODEC_TYPE_AUDIO);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
409
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
410 void av_register_rdt_dynamic_payload_handlers(void)
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
411 {
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
412 ff_register_dynamic_payload_handler(&ff_rdt_video_handler);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
413 ff_register_dynamic_payload_handler(&ff_rdt_audio_handler);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
414 ff_register_dynamic_payload_handler(&ff_rdt_live_video_handler);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
415 ff_register_dynamic_payload_handler(&ff_rdt_live_audio_handler);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
416 }