MediaEndpointSessionDescription.cpp [plain text]
#include "config.h"
#include "MediaEndpointSessionDescription.h"
#if ENABLE(WEB_RTC)
#include "SDPProcessor.h"
#include <wtf/NeverDestroyed.h>
namespace WebCore {
#define STRING_FUNCTION(name) \
static const String& name##String() \
{ \
static NeverDestroyed<const String> name { ASCIILiteral(#name) }; \
return name; \
}
STRING_FUNCTION(offer)
STRING_FUNCTION(pranswer)
STRING_FUNCTION(answer)
STRING_FUNCTION(rollback)
Ref<MediaEndpointSessionDescription> MediaEndpointSessionDescription::create(RTCSessionDescription::SdpType type, RefPtr<MediaEndpointSessionConfiguration>&& configuration)
{
return adoptRef(*new MediaEndpointSessionDescription(type, WTFMove(configuration), nullptr));
}
RefPtr<MediaEndpointSessionDescription> MediaEndpointSessionDescription::create(RefPtr<RTCSessionDescription>&& rtcDescription, const SDPProcessor& sdpProcessor, ExceptionCodeWithMessage& exception)
{
RefPtr<MediaEndpointSessionConfiguration> configuration;
SDPProcessor::Result result = sdpProcessor.parse(rtcDescription->sdp(), configuration);
if (result != SDPProcessor::Result::Success) {
if (result == SDPProcessor::Result::ParseError) {
exception.code = INVALID_ACCESS_ERR;
exception.message = ASCIILiteral("SDP content is invalid");
return nullptr;
}
LOG_ERROR("SDPProcessor internal error");
exception.code = ABORT_ERR;
exception.message = ASCIILiteral("Internal error");
return nullptr;
}
return adoptRef(new MediaEndpointSessionDescription(rtcDescription->type(), WTFMove(configuration), WTFMove(rtcDescription)));
}
RefPtr<RTCSessionDescription> MediaEndpointSessionDescription::toRTCSessionDescription(const SDPProcessor& sdpProcessor) const
{
String sdpString;
SDPProcessor::Result result = sdpProcessor.generate(*m_configuration, sdpString);
if (result != SDPProcessor::Result::Success) {
LOG_ERROR("SDPProcessor internal error");
return nullptr;
}
if (m_rtcDescription) {
m_rtcDescription->setSdp(sdpString);
return m_rtcDescription;
}
return RTCSessionDescription::create(m_type, sdpString);
}
const String& MediaEndpointSessionDescription::typeString() const
{
switch (m_type) {
case RTCSessionDescription::SdpType::Offer:
return offerString();
case RTCSessionDescription::SdpType::Pranswer:
return pranswerString();
case RTCSessionDescription::SdpType::Answer:
return answerString();
case RTCSessionDescription::SdpType::Rollback:
return rollbackString();
}
ASSERT_NOT_REACHED();
return emptyString();
}
bool MediaEndpointSessionDescription::isLaterThan(MediaEndpointSessionDescription* other) const
{
return !other || configuration()->sessionVersion() > other->configuration()->sessionVersion();
}
}
#endif // ENABLE(WEB_RTC)