/* * Copyright (c) 2012 Yoann Blein * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include #include #include #include namespace Swift { JingleRTPDescriptionParser::JingleRTPDescriptionParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0), parsingBandwidth(false) { } void JingleRTPDescriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == 0) { const std::string& media = attributes.getAttributeValue("media").get_value_or(""); getPayloadInternal()->setMedia(mediaTypeFromString(media)); } if (level == 1) { if (element == "bandwidth") { parsingBandwidth = true; bandwidthType = attributes.getAttributeValue("type").get_value_or(""); } else { PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); if (payloadParserFactory) { currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); } } } if (level >= 1 && currentPayloadParser && !parsingBandwidth) { currentPayloadParser->handleStartElement(element, ns, attributes); } ++level; } void JingleRTPDescriptionParser::handleEndElement(const std::string& element, const std::string& ns) { --level; if (element == "bandwidth") { parsingBandwidth = false; getPayloadInternal()->setBandwidth(bandwidthType, bandwidthValue); } else if (currentPayloadParser) { if (level >= 1) { currentPayloadParser->handleEndElement(element, ns); } if (level == 1) { RTPPayloadType::ref payloadType = boost::dynamic_pointer_cast(currentPayloadParser->getPayload()); if (payloadType) { getPayloadInternal()->addPayloadType(*payloadType); } } } } void JingleRTPDescriptionParser::handleCharacterData(const std::string& data) { if (level == 2 && parsingBandwidth) { bandwidthValue += data; } } JingleRTPDescription::MediaType JingleRTPDescriptionParser::mediaTypeFromString(const std::string& media) { if (media == "audio") { return JingleRTPDescription::Audio; } else if (media == "video") { return JingleRTPDescription::Video; } else { return JingleRTPDescription::Unknown; } } }