annotate rdt.c @ 6363:c22c9c5b1588 libavformat

Nit: fix weird spacing.
author stefano
date Wed, 11 Aug 2010 09:13:58 +0000
parents 2048bf728893
children
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 /**
5969
178de7695c6c Remove explicit filename from Doxygen @file commands.
diego
parents: 5923
diff changeset
23 * @file
3876
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"
4388
80f21f72d7d6 Split rtp.h in rtp.h, rtpdec.h, and rtpenc.h
lucabe
parents: 4387
diff changeset
30 #include "rtpdec.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"
4872
304a0ea063f0 Rename bitstream.h to get_bits.h.
stefano
parents: 4736
diff changeset
36 #include "libavcodec/get_bits.h"
3876
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
37
3979
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
38 struct RDTDemuxContext {
4048
e35f52a277d7 Document 'ic' variable. See "[PATCH] RDT/Realmedia patches #2" thread in ML.
rbultje
parents: 4042
diff changeset
39 AVFormatContext *ic; /**< the containing (RTSP) demux context */
4052
302cc68489e4 Change RDTDemuxContext->st into an array of streams, which will make future
rbultje
parents: 4050
diff changeset
40 /** Each RDT stream-set (represented by one RTSPStream) can contain
302cc68489e4 Change RDTDemuxContext->st into an array of streams, which will make future
rbultje
parents: 4050
diff changeset
41 * multiple streams (of the same content, but with possibly different
302cc68489e4 Change RDTDemuxContext->st into an array of streams, which will make future
rbultje
parents: 4050
diff changeset
42 * codecs/bitrates). Each such stream is represented by one AVStream
302cc68489e4 Change RDTDemuxContext->st into an array of streams, which will make future
rbultje
parents: 4050
diff changeset
43 * in the AVFormatContext, and this variable points to the offset in
302cc68489e4 Change RDTDemuxContext->st into an array of streams, which will make future
rbultje
parents: 4050
diff changeset
44 * that array such that the first is the first stream of this set. */
302cc68489e4 Change RDTDemuxContext->st into an array of streams, which will make future
rbultje
parents: 4050
diff changeset
45 AVStream **streams;
302cc68489e4 Change RDTDemuxContext->st into an array of streams, which will make future
rbultje
parents: 4050
diff changeset
46 int n_streams; /**< streams with identifical content in this set */
3979
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
47 void *dynamic_protocol_context;
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
48 DynamicPayloadPacketHandlerProc parse_packet;
4042
463f85165b2a Change type of prev_stream_id from uint32_t to int, since it has a max size
rbultje
parents: 4041
diff changeset
49 uint32_t prev_timestamp;
4053
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
50 int prev_set_id, prev_stream_id;
3979
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
51 };
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 RDTDemuxContext *
4050
7bc64c735f8b Change function prototype from taking an AVStream to taking an index to the
rbultje
parents: 4048
diff changeset
54 ff_rdt_parse_open(AVFormatContext *ic, int first_stream_of_set_idx,
3979
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
55 void *priv_data, RTPDynamicProtocolHandler *handler)
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
56 {
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
57 RDTDemuxContext *s = av_mallocz(sizeof(RDTDemuxContext));
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
58 if (!s)
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
59 return NULL;
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
60
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
61 s->ic = ic;
4052
302cc68489e4 Change RDTDemuxContext->st into an array of streams, which will make future
rbultje
parents: 4050
diff changeset
62 s->streams = &ic->streams[first_stream_of_set_idx];
302cc68489e4 Change RDTDemuxContext->st into an array of streams, which will make future
rbultje
parents: 4050
diff changeset
63 do {
302cc68489e4 Change RDTDemuxContext->st into an array of streams, which will make future
rbultje
parents: 4050
diff changeset
64 s->n_streams++;
302cc68489e4 Change RDTDemuxContext->st into an array of streams, which will make future
rbultje
parents: 4050
diff changeset
65 } while (first_stream_of_set_idx + s->n_streams < ic->nb_streams &&
302cc68489e4 Change RDTDemuxContext->st into an array of streams, which will make future
rbultje
parents: 4050
diff changeset
66 s->streams[s->n_streams]->priv_data == s->streams[0]->priv_data);
4025
4a266106f604 Rename variables in ff_rdt_parse_header() and callers to match the
rbultje
parents: 4023
diff changeset
67 s->prev_set_id = -1;
4053
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
68 s->prev_stream_id = -1;
4025
4a266106f604 Rename variables in ff_rdt_parse_header() and callers to match the
rbultje
parents: 4023
diff changeset
69 s->prev_timestamp = -1;
5504
e15a959963f1 handler can be NULL if we did not support this dynamic format (codec).
rbultje
parents: 5119
diff changeset
70 s->parse_packet = handler ? handler->parse_packet : NULL;
3979
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
71 s->dynamic_protocol_context = priv_data;
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
72
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
73 return s;
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
74 }
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
75
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
76 void
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
77 ff_rdt_parse_close(RDTDemuxContext *s)
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
78 {
4163
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
79 int i;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
80
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
81 for (i = 1; i < s->n_streams; i++)
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
82 s->streams[i]->priv_data = NULL;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
83
3979
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
84 av_free(s);
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
85 }
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
86
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
87 struct PayloadContext {
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
88 AVFormatContext *rmctx;
6356
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
89 int nb_rmst;
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
90 RMStream **rmst;
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
91 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
92 unsigned int mlti_data_size;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
93 char buffer[RTP_MAX_PACKET_LENGTH + FF_INPUT_BUFFER_PADDING_SIZE];
4134
d74875f9b3d4 Change audio_pkt_cnt from an array into a single field, since only a single
rbultje
parents: 4133
diff changeset
94 int audio_pkt_cnt; /**< remaining audio packets in rmdec */
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
95 };
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
96
3876
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
97 void
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
98 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
99 const char *challenge)
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
100 {
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
101 int ch_len = strlen (challenge), i;
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
102 unsigned char zres[16],
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
103 buf[64] = { 0xa1, 0xe9, 0x14, 0x9d, 0x0e, 0x6b, 0x3b, 0x59 };
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
104 #define XOR_TABLE_SIZE 37
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
105 const unsigned char xor_table[XOR_TABLE_SIZE] = {
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
106 0x05, 0x18, 0x74, 0xd0, 0x0d, 0x09, 0x02, 0x53,
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
107 0xc0, 0x01, 0x05, 0x05, 0x67, 0x03, 0x19, 0x70,
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
108 0x08, 0x27, 0x66, 0x10, 0x10, 0x72, 0x08, 0x09,
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
109 0x63, 0x11, 0x03, 0x71, 0x08, 0x08, 0x70, 0x02,
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
110 0x10, 0x57, 0x05, 0x18, 0x54 };
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
111
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
112 /* some (length) checks */
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
113 if (ch_len == 40) /* what a hack... */
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
114 ch_len = 32;
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
115 else if (ch_len > 56)
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
116 ch_len = 56;
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
117 memcpy(buf + 8, challenge, ch_len);
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
118
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
119 /* xor challenge bytewise with xor_table */
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
120 for (i = 0; i < XOR_TABLE_SIZE; i++)
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
121 buf[8 + i] ^= xor_table[i];
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
122
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
123 av_md5_sum(zres, buf, 64);
5883
fd37c39041cd Add a lowercase parameter to ff_data_to_hex
mstorsjo
parents: 5504
diff changeset
124 ff_data_to_hex(response, zres, 16, 1);
3876
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
125
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
126 /* add tail */
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
127 strcpy (response + 32, "01d0a8e3");
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
128
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
129 /* calculate checksum */
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
130 for (i = 0; i < 8; i++)
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
131 chksum[i] = response[i * 4];
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
132 chksum[8] = 0;
1026953d4ffe Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
diff changeset
133 }
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
134
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
135 static int
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
136 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
137 {
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
138 ByteIOContext pb;
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
139 int size;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
140 uint32_t tag;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
141
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
142 /**
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
143 * Layout of the MLTI chunk:
6219
a036426dc8e6 Remove angular brackets from Doxygen comments; Doxygen confuses them for HTML.
diego
parents: 5969
diff changeset
144 * 4: MLTI
a036426dc8e6 Remove angular brackets from Doxygen comments; Doxygen confuses them for HTML.
diego
parents: 5969
diff changeset
145 * 2: number of streams
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
146 * Then for each stream ([number_of_streams] times):
6219
a036426dc8e6 Remove angular brackets from Doxygen comments; Doxygen confuses them for HTML.
diego
parents: 5969
diff changeset
147 * 2: mdpr index
a036426dc8e6 Remove angular brackets from Doxygen comments; Doxygen confuses them for HTML.
diego
parents: 5969
diff changeset
148 * 2: number of mdpr chunks
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
149 * Then for each mdpr chunk ([number_of_mdpr_chunks] times):
6219
a036426dc8e6 Remove angular brackets from Doxygen comments; Doxygen confuses them for HTML.
diego
parents: 5969
diff changeset
150 * 4: size
a036426dc8e6 Remove angular brackets from Doxygen comments; Doxygen confuses them for HTML.
diego
parents: 5969
diff changeset
151 * [size]: data
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
152 * 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
153 * 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
154 * 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
155 */
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
156 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
157 return -1;
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
158 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
159 NULL, NULL, NULL, NULL);
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
160 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
161 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
162 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
163
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
164 /* 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
165 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
166 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
167 return -1;
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
168 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
169 chunk_nr = get_be16(&pb);
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
170 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
171
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
172 /* read MDPR chunks */
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
173 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
174 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
175 return -1;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
176 while (chunk_nr--)
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
177 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
178 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
179 } else {
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
180 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
181 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
182 }
4165
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
183 if (ff_rm_read_mdpr_codecdata(rdt->rmctx, &pb, st, rdt->rmst[st->index], size) < 0)
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
184 return -1;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
185
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
186 return 0;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
187 }
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
188
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
189 /**
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
190 * Actual data handling.
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
191 */
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
192
3962
72efef66f566 This patch refactors RDT packet header parsing so that it can be used in
rbultje
parents: 3959
diff changeset
193 int
72efef66f566 This patch refactors RDT packet header parsing so that it can be used in
rbultje
parents: 3959
diff changeset
194 ff_rdt_parse_header(const uint8_t *buf, int len,
4038
69cdec2e03b2 Prefix all ff_rdt_parse_header() arguments with a p, preparing for local
rbultje
parents: 4037
diff changeset
195 int *pset_id, int *pseq_no, int *pstream_id,
69cdec2e03b2 Prefix all ff_rdt_parse_header() arguments with a p, preparing for local
rbultje
parents: 4037
diff changeset
196 int *pis_keyframe, uint32_t *ptimestamp)
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
197 {
4039
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
198 GetBitContext gb;
4040
b22f5462903e Read optional components of the RDT packet header, such as extended setID
rbultje
parents: 4039
diff changeset
199 int consumed = 0, set_id, seq_no, stream_id, is_keyframe,
b22f5462903e Read optional components of the RDT packet header, such as extended setID
rbultje
parents: 4039
diff changeset
200 len_included, need_reliable;
4039
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
201 uint32_t timestamp;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
202
4032
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
203 /* skip status packets */
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
204 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
205 int pkt_len;
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
206
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
207 if (!(buf[0] & 0x80))
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
208 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
209
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
210 pkt_len = AV_RB16(buf+3);
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
211 buf += pkt_len;
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
212 len -= pkt_len;
7c85b7921e61 Change status packet skipping to be more spec-compliant. See discussion in
rbultje
parents: 4030
diff changeset
213 consumed += pkt_len;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
214 }
4040
b22f5462903e Read optional components of the RDT packet header, such as extended setID
rbultje
parents: 4039
diff changeset
215 if (len < 16)
3962
72efef66f566 This patch refactors RDT packet header parsing so that it can be used in
rbultje
parents: 3959
diff changeset
216 return -1;
4023
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
217 /**
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
218 * Layout of the header (in bits):
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
219 * 1: len_included
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
220 * 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
221 * 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
222 * 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
223 * by stream status packets
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
224 * 1: need_reliable
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
225 * 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
226 * 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
227 * 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
228 * set, according to the Real documentation [1]
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
229 * 5: set_id
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
230 * 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
231 * different codecs or bitrates
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
232 * 1: is_reliable
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
233 * 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
234 * loss
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
235 * 16: seq_no
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
236 * 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
237 * 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
238 * 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
239 * if (len_included) {
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
240 * 16: packet_len
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
241 * } else {
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
242 * packet_len = remainder of UDP/TCP frame
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
243 * }
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
244 * 1: is_back_to_back
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
245 * 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
246 * packets, according to the Real documentation [1]
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
247 * 1: is_slow_data
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
248 * 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
249 * 5: stream_id
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
250 * 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
251 * 1: is_no_keyframe
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
252 * 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
253 * 32: timestamp (PTS)
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
254 * if (set_id == 0x1F) {
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
255 * 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
256 * }
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
257 * if (need_reliable) {
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
258 * 16: reliable_seq_no
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
259 * Reliable sequence number (see need_reliable)
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
260 * }
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
261 * if (stream_id == 0x3F) {
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
262 * 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
263 * }
175eeb7a88d5 Add comment describing the RDT packet header. See discussion in "[PATCH]
rbultje
parents: 3979
diff changeset
264 * [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
265 * [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
266 * 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
267 */
4039
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
268 init_get_bits(&gb, buf, len << 3);
4040
b22f5462903e Read optional components of the RDT packet header, such as extended setID
rbultje
parents: 4039
diff changeset
269 len_included = get_bits1(&gb);
b22f5462903e Read optional components of the RDT packet header, such as extended setID
rbultje
parents: 4039
diff changeset
270 need_reliable = get_bits1(&gb);
4039
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
271 set_id = get_bits(&gb, 5);
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
272 skip_bits(&gb, 1);
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
273 seq_no = get_bits(&gb, 16);
4040
b22f5462903e Read optional components of the RDT packet header, such as extended setID
rbultje
parents: 4039
diff changeset
274 if (len_included)
b22f5462903e Read optional components of the RDT packet header, such as extended setID
rbultje
parents: 4039
diff changeset
275 skip_bits(&gb, 16);
4039
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
276 skip_bits(&gb, 2);
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
277 stream_id = get_bits(&gb, 5);
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
278 is_keyframe = !get_bits1(&gb);
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
279 timestamp = get_bits_long(&gb, 32);
4040
b22f5462903e Read optional components of the RDT packet header, such as extended setID
rbultje
parents: 4039
diff changeset
280 if (set_id == 0x1f)
b22f5462903e Read optional components of the RDT packet header, such as extended setID
rbultje
parents: 4039
diff changeset
281 set_id = get_bits(&gb, 16);
b22f5462903e Read optional components of the RDT packet header, such as extended setID
rbultje
parents: 4039
diff changeset
282 if (need_reliable)
4041
8281f6046ab2 Reindent after r15853.
rbultje
parents: 4040
diff changeset
283 skip_bits(&gb, 16);
4040
b22f5462903e Read optional components of the RDT packet header, such as extended setID
rbultje
parents: 4039
diff changeset
284 if (stream_id == 0x1f)
b22f5462903e Read optional components of the RDT packet header, such as extended setID
rbultje
parents: 4039
diff changeset
285 stream_id = get_bits(&gb, 16);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
286
4039
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
287 if (pset_id) *pset_id = set_id;
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
288 if (pseq_no) *pseq_no = seq_no;
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
289 if (pstream_id) *pstream_id = stream_id;
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
290 if (pis_keyframe) *pis_keyframe = is_keyframe;
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
291 if (ptimestamp) *ptimestamp = timestamp;
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
292
c126ba3df59c Change header reading implementation to using get_bits() instead of directly
rbultje
parents: 4038
diff changeset
293 return consumed + (get_bits_count(&gb) >> 3);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
294 }
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
295
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
296 /**< 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
297 static int
4387
5c42816e12c6 Add "AVFormatContext *ctx" (that being the RTSP demuxer's) as first argument
rbultje
parents: 4331
diff changeset
298 rdt_parse_packet (AVFormatContext *ctx, PayloadContext *rdt, AVStream *st,
3976
64056a0c38ce Change function prototype of RTPDynamicPayloadHandler.parse_packet() to
rbultje
parents: 3975
diff changeset
299 AVPacket *pkt, uint32_t *timestamp,
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
300 const uint8_t *buf, int len, int flags)
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
301 {
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
302 int seq = 1, res;
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
303 ByteIOContext pb;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
304
4096
233ba738a68e Don't access RMContext directly in rdt.c. Rather, use the return value of
rbultje
parents: 4067
diff changeset
305 if (rdt->audio_pkt_cnt == 0) {
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
306 int pos;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
307
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
308 init_put_byte(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
4589
df35708c640a Don't (ab)use PKT_FLAG_* in RTP code, since the two have virtually nothing
rbultje
parents: 4388
diff changeset
309 flags = (flags & RTP_FLAG_KEY) ? 2 : 0;
4165
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
310 res = ff_rm_parse_packet (rdt->rmctx, &pb, st, rdt->rmst[st->index], len, pkt,
5119
bb9cdd9ad9de Don't use a pointer-to-flags/timestamp in ff_rm_parse_packet(); the function
rbultje
parents: 5113
diff changeset
311 &seq, flags, *timestamp);
4037
5f65cbe25494 Fix memleak caused by the fact that url_open_buf() allocates a context
rbultje
parents: 4036
diff changeset
312 pos = url_ftell(&pb);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
313 if (res < 0)
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
314 return res;
4734
dfcf66d4a613 Remove packet returning in ff_rm_parse_packet() if we're using the packet
rbultje
parents: 4589
diff changeset
315 if (res > 0) {
dfcf66d4a613 Remove packet returning in ff_rm_parse_packet() if we're using the packet
rbultje
parents: 4589
diff changeset
316 if (st->codec->codec_id == CODEC_ID_AAC) {
4736
c0e7d62efe9c Reindent after r18010.
rbultje
parents: 4734
diff changeset
317 memcpy (rdt->buffer, buf + pos, len - pos);
c0e7d62efe9c Reindent after r18010.
rbultje
parents: 4734
diff changeset
318 rdt->rmctx->pb = av_alloc_put_byte (rdt->buffer, len - pos, 0,
c0e7d62efe9c Reindent after r18010.
rbultje
parents: 4734
diff changeset
319 NULL, NULL, NULL, NULL);
4734
dfcf66d4a613 Remove packet returning in ff_rm_parse_packet() if we're using the packet
rbultje
parents: 4589
diff changeset
320 }
dfcf66d4a613 Remove packet returning in ff_rm_parse_packet() if we're using the packet
rbultje
parents: 4589
diff changeset
321 goto get_cache;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
322 }
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
323 } else {
4734
dfcf66d4a613 Remove packet returning in ff_rm_parse_packet() if we're using the packet
rbultje
parents: 4589
diff changeset
324 get_cache:
4135
fd0fc1e26d82 Add audio_pkt_cnt return value to ff_rm_retrieve_cache(). See discussion in
rbultje
parents: 4134
diff changeset
325 rdt->audio_pkt_cnt =
4136
e29f278b7831 Reindent after r16368.
rbultje
parents: 4135
diff changeset
326 ff_rm_retrieve_cache (rdt->rmctx, rdt->rmctx->pb,
4165
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
327 st, rdt->rmst[st->index], pkt);
4134
d74875f9b3d4 Change audio_pkt_cnt from an array into a single field, since only a single
rbultje
parents: 4133
diff changeset
328 if (rdt->audio_pkt_cnt == 0 &&
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
329 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
330 av_freep(&rdt->rmctx->pb);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
331 }
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
332 pkt->stream_index = st->index;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
333 pkt->pts = *timestamp;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
334
4134
d74875f9b3d4 Change audio_pkt_cnt from an array into a single field, since only a single
rbultje
parents: 4133
diff changeset
335 return rdt->audio_pkt_cnt > 0;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
336 }
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
337
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
338 int
3979
e6bf0896a019 Implement RDTDemuxContext, which contains RDT-specific data (similar to
rbultje
parents: 3976
diff changeset
339 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
340 const uint8_t *buf, int len)
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
341 {
4029
9a0a46d465ae Add is_keyframe param to ff_rdt_parse_header(). See ML discussion in
rbultje
parents: 4025
diff changeset
342 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
343 uint32_t timestamp;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
344 int rv= 0;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
345
3963
dbe779f54647 Use parse_packet vfunc in RTPDynamicProtocolHandler instead of hardcoding
rbultje
parents: 3962
diff changeset
346 if (!s->parse_packet)
dbe779f54647 Use parse_packet vfunc in RTPDynamicProtocolHandler instead of hardcoding
rbultje
parents: 3962
diff changeset
347 return -1;
dbe779f54647 Use parse_packet vfunc in RTPDynamicProtocolHandler instead of hardcoding
rbultje
parents: 3962
diff changeset
348
4053
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
349 if (!buf && s->prev_stream_id != -1) {
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
350 /* return the next packets, if any */
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
351 timestamp= 0; ///< Should not be used if buf is NULL, but should be set to the timestamp of the packet returned....
4387
5c42816e12c6 Add "AVFormatContext *ctx" (that being the RTSP demuxer's) as first argument
rbultje
parents: 4331
diff changeset
352 rv= s->parse_packet(s->ic, s->dynamic_protocol_context,
4053
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
353 s->streams[s->prev_stream_id],
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
354 pkt, &timestamp, NULL, 0, flags);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
355 return rv;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
356 }
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
357
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
358 if (len < 12)
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
359 return -1;
4029
9a0a46d465ae Add is_keyframe param to ff_rdt_parse_header(). See ML discussion in
rbultje
parents: 4025
diff changeset
360 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
361 if (rv < 0)
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
362 return rv;
4053
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
363 if (is_keyframe &&
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
364 (set_id != s->prev_set_id || timestamp != s->prev_timestamp ||
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
365 stream_id != s->prev_stream_id)) {
4589
df35708c640a Don't (ab)use PKT_FLAG_* in RTP code, since the two have virtually nothing
rbultje
parents: 4388
diff changeset
366 flags |= RTP_FLAG_KEY;
4025
4a266106f604 Rename variables in ff_rdt_parse_header() and callers to match the
rbultje
parents: 4023
diff changeset
367 s->prev_set_id = set_id;
4a266106f604 Rename variables in ff_rdt_parse_header() and callers to match the
rbultje
parents: 4023
diff changeset
368 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
369 }
4053
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
370 s->prev_stream_id = stream_id;
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
371 buf += rv;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
372 len -= rv;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
373
4053
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
374 if (s->prev_stream_id >= s->n_streams) {
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
375 s->prev_stream_id = -1;
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
376 return -1;
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
377 }
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
378
4387
5c42816e12c6 Add "AVFormatContext *ctx" (that being the RTSP demuxer's) as first argument
rbultje
parents: 4331
diff changeset
379 rv = s->parse_packet(s->ic, s->dynamic_protocol_context,
4053
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
380 s->streams[s->prev_stream_id],
06642e6ba288 Implement rule-number parsing, the initial step in stream (and bitrate)
rbultje
parents: 4052
diff changeset
381 pkt, &timestamp, buf, len, flags);
3905
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
382
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
383 return rv;
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
384 }
91987686113d Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents: 3903
diff changeset
385
3903
aeb79f68ba7e Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents: 3902
diff changeset
386 void
3959
ed6f6aa977ec Remove access to rdt_data struct in functions called outside of the
rbultje
parents: 3905
diff changeset
387 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
388 int stream_nr, int rule_nr)
aeb79f68ba7e Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents: 3902
diff changeset
389 {
3959
ed6f6aa977ec Remove access to rdt_data struct in functions called outside of the
rbultje
parents: 3905
diff changeset
390 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
391 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
392 }
ed6f6aa977ec Remove access to rdt_data struct in functions called outside of the
rbultje
parents: 3905
diff changeset
393
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
394 static unsigned char *
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
395 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
396 {
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
397 unsigned char *target;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
398 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
399 if (*p == '\"') {
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
400 p++;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
401 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
402 }
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
403 *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
404 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
405 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
406 return target;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
407 }
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
408
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
409 static int
4067
8adccfc01be3 Change function prototype of the sdp_parse_a_line in DynamicProtocolHandler.
rbultje
parents: 4053
diff changeset
410 rdt_parse_sdp_line (AVFormatContext *s, int st_index,
8adccfc01be3 Change function prototype of the sdp_parse_a_line in DynamicProtocolHandler.
rbultje
parents: 4053
diff changeset
411 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
412 {
4067
8adccfc01be3 Change function prototype of the sdp_parse_a_line in DynamicProtocolHandler.
rbultje
parents: 4053
diff changeset
413 AVStream *stream = s->streams[st_index];
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
414 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
415
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
416 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
417 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
418 } 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
419 stream->first_dts = atoi(p);
4165
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
420 else if (av_strstart(p, "ASMRuleBook:string;", &p)) {
5923
b26e694441e1 Remove dead initialization.
rbultje
parents: 5910
diff changeset
421 int n, first = -1;
4165
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
422
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
423 for (n = 0; n < s->nb_streams; n++)
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
424 if (s->streams[n]->priv_data == stream->priv_data) {
6356
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
425 int count = s->streams[n]->index + 1;
4165
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
426 if (first == -1) first = n;
6356
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
427 if (rdt->nb_rmst < count) {
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
428 RMStream **rmst= av_realloc(rdt->rmst, count*sizeof(*rmst));
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
429 if (!rmst)
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
430 return AVERROR(ENOMEM);
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
431 memset(rmst + rdt->nb_rmst, 0,
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
432 (count - rdt->nb_rmst) * sizeof(*rmst));
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
433 rdt->rmst = rmst;
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
434 rdt->nb_rmst = count;
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
435 }
4165
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
436 rdt->rmst[s->streams[n]->index] = ff_rm_alloc_rmstream();
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
437 rdt_load_mdpr(rdt, s->streams[n], (n - first) * 2);
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
438
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
439 if (s->streams[n]->codec->codec_id == CODEC_ID_AAC)
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
440 s->streams[n]->codec->frame_size = 1; // FIXME
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
441 }
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
442 }
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
443
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
444 return 0;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
445 }
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
446
4164
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
447 static void
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
448 real_parse_asm_rule(AVStream *st, const char *p, const char *end)
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
449 {
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
450 do {
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
451 /* can be either averagebandwidth= or AverageBandwidth= */
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
452 if (sscanf(p, " %*1[Aa]verage%*1[Bb]andwidth=%d", &st->codec->bit_rate) == 1)
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
453 break;
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
454 if (!(p = strchr(p, ',')) || p > end)
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
455 p = end;
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
456 p++;
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
457 } while (p < end);
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
458 }
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
459
4163
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
460 static AVStream *
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
461 add_dstream(AVFormatContext *s, AVStream *orig_st)
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
462 {
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
463 AVStream *st;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
464
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
465 if (!(st = av_new_stream(s, 0)))
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
466 return NULL;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
467 st->codec->codec_type = orig_st->codec->codec_type;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
468 st->priv_data = orig_st->priv_data;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
469 st->first_dts = orig_st->first_dts;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
470
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
471 return st;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
472 }
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
473
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
474 static void
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
475 real_parse_asm_rulebook(AVFormatContext *s, AVStream *orig_st,
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
476 const char *p)
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
477 {
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
478 const char *end;
6356
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
479 int n_rules = 0, odd = 0;
4163
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
480 AVStream *st;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
481
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
482 /**
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
483 * The ASMRuleBook contains a list of comma-separated strings per rule,
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
484 * and each rule is separated by a ;. The last one also has a ; at the
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
485 * end so we can use it as delimiter.
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
486 * Every rule occurs twice, once for when the RTSP packet header marker
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
487 * is set and once for if it isn't. We only read the first because we
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
488 * don't care much (that's what the "odd" variable is for).
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
489 * Each rule contains a set of one or more statements, optionally
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
490 * preceeded by a single condition. If there's a condition, the rule
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
491 * starts with a '#'. Multiple conditions are merged between brackets,
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
492 * so there are never multiple conditions spread out over separate
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
493 * statements. Generally, these conditions are bitrate limits (min/max)
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
494 * for multi-bitrate streams.
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
495 */
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
496 if (*p == '\"') p++;
6356
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
497 while (1) {
4163
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
498 if (!(end = strchr(p, ';')))
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
499 break;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
500 if (!odd && end != p) {
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
501 if (n_rules > 0)
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
502 st = add_dstream(s, orig_st);
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
503 else
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
504 st = orig_st;
6356
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
505 if (!st)
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
506 break;
4164
56b7ebdf9ef4 Parse the bitrate field in the ASMRuleBook ("AverageBandwidth") to fill in
rbultje
parents: 4163
diff changeset
507 real_parse_asm_rule(st, p, end);
4163
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
508 n_rules++;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
509 }
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
510 p = end + 1;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
511 odd ^= 1;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
512 }
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
513 }
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
514
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
515 void
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
516 ff_real_parse_sdp_a_line (AVFormatContext *s, int stream_index,
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
517 const char *line)
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
518 {
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
519 const char *p = line;
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
520
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
521 if (av_strstart(p, "ASMRuleBook:string;", &p))
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
522 real_parse_asm_rulebook(s, s->streams[stream_index], p);
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
523 }
8d6512cbd657 Parse the ASMRuleBook SDP line to dynamically create one new AVStream for
rbultje
parents: 4138
diff changeset
524
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
525 static PayloadContext *
5113
75e51cba276e Use named initializers and use new/free_context() instead of extradata()
rbultje
parents: 4872
diff changeset
526 rdt_new_context (void)
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
527 {
3975
44561554cb7e Rename RTP payload contexts to PayloadContext, suggested by Luca in
rbultje
parents: 3963
diff changeset
528 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
529
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
530 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
531
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
532 return rdt;
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
533 }
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
534
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
535 static void
5113
75e51cba276e Use named initializers and use new/free_context() instead of extradata()
rbultje
parents: 4872
diff changeset
536 rdt_free_context (PayloadContext *rdt)
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
537 {
4165
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
538 int i;
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
539
6356
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
540 for (i = 0; i < rdt->nb_rmst; i++)
4165
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
541 if (rdt->rmst[i]) {
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
542 ff_rm_free_rmstream(rdt->rmst[i]);
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
543 av_freep(&rdt->rmst[i]);
8b294ed0bd65 Parse the OpaqueData field for every AVStream represented by this "set of
rbultje
parents: 4164
diff changeset
544 }
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
545 if (rdt->rmctx)
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
546 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
547 av_freep(&rdt->mlti_data);
6356
2048bf728893 get ride of MAX_STREAMS limit in RDT
aurel
parents: 6219
diff changeset
548 av_freep(&rdt->rmst);
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
549 av_free(rdt);
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
550 }
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
551
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
552 #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
553 static RTPDynamicProtocolHandler ff_rdt_ ## n ## _handler = { \
5113
75e51cba276e Use named initializers and use new/free_context() instead of extradata()
rbultje
parents: 4872
diff changeset
554 .enc_name = s, \
75e51cba276e Use named initializers and use new/free_context() instead of extradata()
rbultje
parents: 4872
diff changeset
555 .codec_type = t, \
75e51cba276e Use named initializers and use new/free_context() instead of extradata()
rbultje
parents: 4872
diff changeset
556 .codec_id = CODEC_ID_NONE, \
75e51cba276e Use named initializers and use new/free_context() instead of extradata()
rbultje
parents: 4872
diff changeset
557 .parse_sdp_a_line = rdt_parse_sdp_line, \
75e51cba276e Use named initializers and use new/free_context() instead of extradata()
rbultje
parents: 4872
diff changeset
558 .open = rdt_new_context, \
75e51cba276e Use named initializers and use new/free_context() instead of extradata()
rbultje
parents: 4872
diff changeset
559 .close = rdt_free_context, \
75e51cba276e Use named initializers and use new/free_context() instead of extradata()
rbultje
parents: 4872
diff changeset
560 .parse_packet = 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
561 };
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
562
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5883
diff changeset
563 RDT_HANDLER(live_video, "x-pn-multirate-realvideo-live", AVMEDIA_TYPE_VIDEO);
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5883
diff changeset
564 RDT_HANDLER(live_audio, "x-pn-multirate-realaudio-live", AVMEDIA_TYPE_AUDIO);
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5883
diff changeset
565 RDT_HANDLER(video, "x-pn-realvideo", AVMEDIA_TYPE_VIDEO);
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5883
diff changeset
566 RDT_HANDLER(audio, "x-pn-realaudio", AVMEDIA_TYPE_AUDIO);
3902
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
567
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
568 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
569 {
5f9bec099c69 Add dynamic payload handlers to rdt.c. These follow the same API as the ones
rbultje
parents: 3876
diff changeset
570 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
571 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
572 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
573 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
574 }