~ubuntu-branches/ubuntu/precise/crtmpserver/precise-backports

« back to all changes in this revision

Viewing changes to thelib/src/protocols/rtp/sdp.cpp

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2012-07-04 00:04:40 UTC
  • mfrom: (3.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120704000440-u9x7yhyglqjvspk8
Tags: 1.0~dfsg-3~ubuntu12.04.1
No-change backport to precise (LP: #964153)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
 
1
/*
2
2
 *  Copyright (c) 2010,
3
3
 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com)
4
4
 *
175
175
        return (string) (*this)[SDP_SESSION][SDP_S];
176
176
}
177
177
 
 
178
bool SDP::ParseTransportLine(string raw, Variant &result) {
 
179
        result.Reset();
 
180
 
 
181
        //1. split after ';'
 
182
        vector<string> parts;
 
183
        split(raw, ";", parts);
 
184
 
 
185
        //2. Construct the result
 
186
        for (uint32_t i = 0; i < parts.size(); i++) {
 
187
                string part = parts[i];
 
188
                trim(part);
 
189
                if (part == "")
 
190
                        continue;
 
191
                string::size_type pos = part.find('=');
 
192
                if (pos == string::npos) {
 
193
                        result[lowerCase(part)] = (bool)true;
 
194
                        continue;
 
195
                }
 
196
                result[lowerCase(part.substr(0, pos))] = part.substr(pos + 1);
 
197
        }
 
198
 
 
199
        vector<string> keys;
 
200
        ADD_VECTOR_END(keys, "client_port");
 
201
        ADD_VECTOR_END(keys, "server_port");
 
202
        ADD_VECTOR_END(keys, "interleaved");
 
203
 
 
204
        for (uint32_t i = 0; i < keys.size(); i++) {
 
205
                string key = keys[i];
 
206
                if (!result.HasKey(key))
 
207
                        continue;
 
208
                parts.clear();
 
209
                raw = (string) result[key];
 
210
                split(raw, "-", parts);
 
211
                if ((parts.size() != 2) && (parts.size() != 1)) {
 
212
                        FATAL("Invalid transport line: %s", STR(raw));
 
213
                        return false;
 
214
                }
 
215
                string all = "";
 
216
                uint16_t data = 0;
 
217
                uint16_t rtcp = 0;
 
218
                if (parts.size() == 2) {
 
219
                        data = atoi(STR(parts[0]));
 
220
                        rtcp = atoi(STR(parts[1]));
 
221
                        if (((data % 2) != 0) || ((data + 1) != rtcp)) {
 
222
                                FATAL("Invalid transport line: %s", STR(raw));
 
223
                                return false;
 
224
                        }
 
225
                        all = format("%"PRIu16"-%"PRIu16, data, rtcp);
 
226
                } else {
 
227
                        data = atoi(STR(parts[0]));
 
228
                        all = format("%"PRIu16, data);
 
229
                        rtcp = 0;
 
230
                }
 
231
                if (all != raw) {
 
232
                        FATAL("Invalid transport line: %s", STR(raw));
 
233
                        return false;
 
234
                }
 
235
                result.RemoveKey(key);
 
236
                result[key]["data"] = (uint16_t) data;
 
237
                result[key]["rtcp"] = (uint16_t) rtcp;
 
238
                result[key]["all"] = all;
 
239
        }
 
240
 
 
241
        return true;
 
242
}
 
243
 
178
244
bool SDP::ParseSection(Variant &result, vector<string> &lines,
179
245
                uint32_t start, uint32_t length) {
180
246
        for (uint32_t i = 0; ((i + start) < lines.size()) && (i < length); i++) {