mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1379265 - Add C++ bindings for rsdparsa; r=bwc
MozReview-Commit-ID: FdhpTT5wzwI --HG-- extra : rebase_source : e2c0c58dfe41e25df101ec52bca0b092bc330246
This commit is contained in:
parent
9a973356aa
commit
cecd8dd288
120
media/webrtc/signaling/src/sdp/RsdparsaSdp.cpp
Normal file
120
media/webrtc/signaling/src/sdp/RsdparsaSdp.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "signaling/src/sdp/RsdparsaSdp.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "nsError.h"
|
||||
|
||||
|
||||
#include "signaling/src/sdp/SdpErrorHolder.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpInc.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpMediaSection.h"
|
||||
|
||||
#ifdef CRLF
|
||||
#undef CRLF
|
||||
#endif
|
||||
#define CRLF "\r\n"
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
RsdparsaSdp::RsdparsaSdp(RsdparsaSessionHandle session, const SdpOrigin& origin)
|
||||
: mSession(Move(session))
|
||||
, mOrigin(origin)
|
||||
{
|
||||
RsdparsaSessionHandle attributeSession(sdp_new_reference(mSession.get()));
|
||||
mAttributeList.reset(new RsdparsaSdpAttributeList(Move(attributeSession)));
|
||||
|
||||
size_t section_count = sdp_media_section_count(mSession.get());
|
||||
for (size_t level = 0; level < section_count; level++) {
|
||||
RustMediaSection* mediaSection = sdp_get_media_section(mSession.get(),
|
||||
level);
|
||||
if (!mediaSection) {
|
||||
MOZ_ASSERT(false, "sdp_get_media_section failed because level was out of"
|
||||
" bounds, but we did a bounds check!");
|
||||
break;
|
||||
}
|
||||
RsdparsaSessionHandle newSession(sdp_new_reference(mSession.get()));
|
||||
RsdparsaSdpMediaSection* sdpMediaSection;
|
||||
sdpMediaSection = new RsdparsaSdpMediaSection(level,
|
||||
Move(newSession),
|
||||
mediaSection,
|
||||
mAttributeList.get());
|
||||
mMediaSections.values.push_back(sdpMediaSection);
|
||||
}
|
||||
}
|
||||
|
||||
const SdpOrigin&
|
||||
RsdparsaSdp::GetOrigin() const
|
||||
{
|
||||
return mOrigin;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
RsdparsaSdp::GetBandwidth(const std::string& type) const
|
||||
{
|
||||
return get_sdp_bandwidth(mSession.get(), type.c_str());
|
||||
}
|
||||
|
||||
const SdpMediaSection&
|
||||
RsdparsaSdp::GetMediaSection(size_t level) const
|
||||
{
|
||||
if (level > mMediaSections.values.size()) {
|
||||
MOZ_CRASH();
|
||||
}
|
||||
return *mMediaSections.values[level];
|
||||
}
|
||||
|
||||
SdpMediaSection&
|
||||
RsdparsaSdp::GetMediaSection(size_t level)
|
||||
{
|
||||
if (level > mMediaSections.values.size()) {
|
||||
MOZ_CRASH();
|
||||
}
|
||||
return *mMediaSections.values[level];
|
||||
}
|
||||
|
||||
SdpMediaSection&
|
||||
RsdparsaSdp::AddMediaSection(SdpMediaSection::MediaType mediaType,
|
||||
SdpDirectionAttribute::Direction dir,
|
||||
uint16_t port,
|
||||
SdpMediaSection::Protocol protocol,
|
||||
sdp::AddrType addrType, const std::string& addr)
|
||||
{
|
||||
//TODO: See Bug 1436080
|
||||
MOZ_CRASH("Method not implemented");
|
||||
}
|
||||
|
||||
void
|
||||
RsdparsaSdp::Serialize(std::ostream& os) const
|
||||
{
|
||||
os << "v=0" << CRLF << mOrigin << "s=-" << CRLF;
|
||||
|
||||
// We don't support creating i=, u=, e=, p=
|
||||
// We don't generate c= at the session level (only in media)
|
||||
|
||||
BandwidthVec* bwVec = sdp_get_session_bandwidth_vec(mSession.get());
|
||||
char *bwString = sdp_serialize_bandwidth(bwVec);
|
||||
if (bwString) {
|
||||
os << bwString;
|
||||
sdp_free_string(bwString);
|
||||
}
|
||||
|
||||
os << "t=0 0" << CRLF;
|
||||
|
||||
// We don't support r= or z=
|
||||
|
||||
// attributes
|
||||
os << *mAttributeList;
|
||||
|
||||
// media sections
|
||||
for (const SdpMediaSection* msection : mMediaSections.values) {
|
||||
os << *msection;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
82
media/webrtc/signaling/src/sdp/RsdparsaSdp.h
Normal file
82
media/webrtc/signaling/src/sdp/RsdparsaSdp.h
Normal file
@ -0,0 +1,82 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef _RSDPARSA_SDP_H_
|
||||
#define _RSDPARSA_SDP_H_
|
||||
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
#include "signaling/src/common/PtrVector.h"
|
||||
|
||||
#include "signaling/src/sdp/Sdp.h"
|
||||
|
||||
#include "signaling/src/sdp/RsdparsaSdpMediaSection.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpAttributeList.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpInc.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpGlue.h"
|
||||
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
class RsdparsaSdpParser;
|
||||
class SdpErrorHolder;
|
||||
|
||||
class RsdparsaSdp final : public Sdp
|
||||
{
|
||||
friend class RsdparsaSdpParser;
|
||||
|
||||
public:
|
||||
explicit RsdparsaSdp(RsdparsaSessionHandle session, const SdpOrigin& origin);
|
||||
|
||||
const SdpOrigin& GetOrigin() const override;
|
||||
|
||||
// Note: connection information is always retrieved from media sections
|
||||
uint32_t GetBandwidth(const std::string& type) const override;
|
||||
|
||||
size_t
|
||||
GetMediaSectionCount() const override
|
||||
{
|
||||
return sdp_media_section_count(mSession.get());
|
||||
}
|
||||
|
||||
const SdpAttributeList&
|
||||
GetAttributeList() const override
|
||||
{
|
||||
return *mAttributeList;
|
||||
}
|
||||
|
||||
SdpAttributeList&
|
||||
GetAttributeList() override
|
||||
{
|
||||
return *mAttributeList;
|
||||
}
|
||||
|
||||
const SdpMediaSection& GetMediaSection(size_t level) const
|
||||
override;
|
||||
|
||||
SdpMediaSection& GetMediaSection(size_t level) override;
|
||||
|
||||
SdpMediaSection& AddMediaSection(
|
||||
SdpMediaSection::MediaType media, SdpDirectionAttribute::Direction dir,
|
||||
uint16_t port, SdpMediaSection::Protocol proto, sdp::AddrType addrType,
|
||||
const std::string& addr) override;
|
||||
|
||||
void Serialize(std::ostream&) const override;
|
||||
|
||||
private:
|
||||
RsdparsaSdp() : mOrigin("", 0, 0, sdp::kIPv4, "") {}
|
||||
|
||||
RsdparsaSessionHandle mSession;
|
||||
SdpOrigin mOrigin;
|
||||
UniquePtr<RsdparsaSdpAttributeList> mAttributeList;
|
||||
PtrVector<RsdparsaSdpMediaSection> mMediaSections;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
1023
media/webrtc/signaling/src/sdp/RsdparsaSdpAttributeList.cpp
Normal file
1023
media/webrtc/signaling/src/sdp/RsdparsaSdpAttributeList.cpp
Normal file
File diff suppressed because it is too large
Load Diff
158
media/webrtc/signaling/src/sdp/RsdparsaSdpAttributeList.h
Normal file
158
media/webrtc/signaling/src/sdp/RsdparsaSdpAttributeList.h
Normal file
@ -0,0 +1,158 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef _RSDPARSA_SDP_ATTRIBUTE_LIST_H_
|
||||
#define _RSDPARSA_SDP_ATTRIBUTE_LIST_H_
|
||||
|
||||
#include "signaling/src/sdp/RsdparsaSdpGlue.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpInc.h"
|
||||
#include "signaling/src/sdp/SdpAttributeList.h"
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
class RsdparsaSdp;
|
||||
class RsdparsaSdpMediaSection;
|
||||
class SdpErrorHolder;
|
||||
|
||||
class RsdparsaSdpAttributeList : public SdpAttributeList
|
||||
{
|
||||
friend class RsdparsaSdpMediaSection;
|
||||
friend class RsdparsaSdp;
|
||||
|
||||
public:
|
||||
// Make sure we don't hide the default arg thunks
|
||||
using SdpAttributeList::HasAttribute;
|
||||
using SdpAttributeList::GetAttribute;
|
||||
|
||||
bool HasAttribute(AttributeType type,
|
||||
bool sessionFallback) const override;
|
||||
const SdpAttribute* GetAttribute(AttributeType type,
|
||||
bool sessionFallback) const override;
|
||||
void SetAttribute(SdpAttribute* attr) override;
|
||||
void RemoveAttribute(AttributeType type) override;
|
||||
void Clear() override;
|
||||
uint32_t Count() const override;
|
||||
|
||||
const SdpConnectionAttribute& GetConnection() const override;
|
||||
const SdpFingerprintAttributeList& GetFingerprint() const override;
|
||||
const SdpGroupAttributeList& GetGroup() const override;
|
||||
const SdpOptionsAttribute& GetIceOptions() const override;
|
||||
const SdpRtcpAttribute& GetRtcp() const override;
|
||||
const SdpRemoteCandidatesAttribute& GetRemoteCandidates() const override;
|
||||
const SdpSetupAttribute& GetSetup() const override;
|
||||
const SdpSsrcAttributeList& GetSsrc() const override;
|
||||
const SdpSsrcGroupAttributeList& GetSsrcGroup() const override;
|
||||
const SdpDtlsMessageAttribute& GetDtlsMessage() const override;
|
||||
|
||||
// These attributes can appear multiple times, so the returned
|
||||
// classes actually represent a collection of values.
|
||||
const std::vector<std::string>& GetCandidate() const override;
|
||||
const SdpExtmapAttributeList& GetExtmap() const override;
|
||||
const SdpFmtpAttributeList& GetFmtp() const override;
|
||||
const SdpImageattrAttributeList& GetImageattr() const override;
|
||||
const SdpSimulcastAttribute& GetSimulcast() const override;
|
||||
const SdpMsidAttributeList& GetMsid() const override;
|
||||
const SdpMsidSemanticAttributeList& GetMsidSemantic() const override;
|
||||
const SdpRidAttributeList& GetRid() const override;
|
||||
const SdpRtcpFbAttributeList& GetRtcpFb() const override;
|
||||
const SdpRtpmapAttributeList& GetRtpmap() const override;
|
||||
const SdpSctpmapAttributeList& GetSctpmap() const override;
|
||||
|
||||
// These attributes are effectively simple types, so we'll make life
|
||||
// easy by just returning their value.
|
||||
uint32_t GetSctpPort() const override;
|
||||
uint32_t GetMaxMessageSize() const override;
|
||||
const std::string& GetIcePwd() const override;
|
||||
const std::string& GetIceUfrag() const override;
|
||||
const std::string& GetIdentity() const override;
|
||||
const std::string& GetLabel() const override;
|
||||
unsigned int GetMaxptime() const override;
|
||||
const std::string& GetMid() const override;
|
||||
unsigned int GetPtime() const override;
|
||||
|
||||
SdpDirectionAttribute::Direction GetDirection() const override;
|
||||
|
||||
void Serialize(std::ostream&) const override;
|
||||
|
||||
virtual ~RsdparsaSdpAttributeList();
|
||||
|
||||
private:
|
||||
explicit RsdparsaSdpAttributeList(RsdparsaSessionHandle session)
|
||||
: mSession(Move(session))
|
||||
, mSessionAttributes(nullptr)
|
||||
, mIsVideo(false)
|
||||
, mAttributes()
|
||||
{
|
||||
RustAttributeList* attributes = get_sdp_session_attributes(mSession.get());
|
||||
LoadAll(attributes);
|
||||
}
|
||||
|
||||
RsdparsaSdpAttributeList(RsdparsaSessionHandle session,
|
||||
const RustMediaSection* const msection,
|
||||
const RsdparsaSdpAttributeList* sessionAttributes)
|
||||
: mSession(Move(session))
|
||||
, mSessionAttributes(sessionAttributes)
|
||||
, mAttributes()
|
||||
{
|
||||
mIsVideo = sdp_rust_get_media_type(msection) == RustSdpMediaValue::kRustVideo;
|
||||
RustAttributeList* attributes = sdp_get_media_attribute_list(msection);
|
||||
LoadAll(attributes);
|
||||
}
|
||||
|
||||
static const std::string kEmptyString;
|
||||
static const size_t kNumAttributeTypes = SdpAttribute::kLastAttribute + 1;
|
||||
|
||||
const RsdparsaSessionHandle mSession;
|
||||
const RsdparsaSdpAttributeList* mSessionAttributes;
|
||||
bool mIsVideo;
|
||||
|
||||
bool
|
||||
AtSessionLevel() const
|
||||
{
|
||||
return !mSessionAttributes;
|
||||
}
|
||||
|
||||
bool IsAllowedHere(SdpAttribute::AttributeType type);
|
||||
void LoadAll(RustAttributeList* attributeList);
|
||||
void LoadAttribute(RustAttributeList* attributeList, AttributeType type);
|
||||
void LoadIceUfrag(RustAttributeList* attributeList);
|
||||
void LoadIcePwd(RustAttributeList* attributeList);
|
||||
void LoadIdentity(RustAttributeList* attributeList);
|
||||
void LoadIceOptions(RustAttributeList* attributeList);
|
||||
void LoadFingerprint(RustAttributeList* attributeList);
|
||||
void LoadSetup(RustAttributeList* attributeList);
|
||||
void LoadSsrc(RustAttributeList* attributeList);
|
||||
void LoadRtpmap(RustAttributeList* attributeList);
|
||||
void LoadFmtp(RustAttributeList* attributeList);
|
||||
void LoadPtime(RustAttributeList* attributeList);
|
||||
void LoadFlags(RustAttributeList* attributeList);
|
||||
void LoadMid(RustAttributeList* attributeList);
|
||||
void LoadMsid(RustAttributeList* attributeList);
|
||||
void LoadMsidSemantics(RustAttributeList* attributeList);
|
||||
void LoadGroup(RustAttributeList* attributeList);
|
||||
void LoadRtcp(RustAttributeList* attributeList);
|
||||
void LoadImageattr(RustAttributeList* attributeList);
|
||||
void LoadSctpmaps(RustAttributeList* attributeList);
|
||||
void LoadDirection(RustAttributeList* attributeList);
|
||||
void LoadRemoteCandidates(RustAttributeList* attributeList);
|
||||
void LoadRids(RustAttributeList* attributeList);
|
||||
void LoadExtmap(RustAttributeList* attributeList);
|
||||
|
||||
void WarnAboutMisplacedAttribute(SdpAttribute::AttributeType type,
|
||||
uint32_t lineNumber,
|
||||
SdpErrorHolder& errorHolder);
|
||||
|
||||
|
||||
SdpAttribute* mAttributes[kNumAttributeTypes];
|
||||
|
||||
RsdparsaSdpAttributeList(const RsdparsaSdpAttributeList& orig) = delete;
|
||||
RsdparsaSdpAttributeList& operator=(const RsdparsaSdpAttributeList& rhs) = delete;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
48
media/webrtc/signaling/src/sdp/RsdparsaSdpGlue.cpp
Normal file
48
media/webrtc/signaling/src/sdp/RsdparsaSdpGlue.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#include <string>
|
||||
|
||||
#include "signaling/src/sdp/RsdparsaSdpInc.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpGlue.h"
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
std::string convertStringView(StringView str)
|
||||
{
|
||||
if (nullptr == str.buf) {
|
||||
return std::string();
|
||||
} else {
|
||||
return std::string(str.buf, str.len);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> convertStringVec(StringVec* vec)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
size_t len = string_vec_len(vec);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
StringView view;
|
||||
string_vec_get_view(vec, i, &view);
|
||||
ret.push_back(convertStringView(view));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
sdp::AddrType convertAddressType(RustSdpAddrType addrType)
|
||||
{
|
||||
switch(addrType) {
|
||||
case RustSdpAddrType::kRustAddrNone:
|
||||
return sdp::kAddrTypeNone;
|
||||
case RustSdpAddrType::kRustAddrIp4:
|
||||
return sdp::kIPv4;
|
||||
case RustSdpAddrType::kRustAddrIp6:
|
||||
return sdp::kIPv6;
|
||||
}
|
||||
|
||||
MOZ_CRASH("unknown address type");
|
||||
}
|
||||
|
||||
}
|
31
media/webrtc/signaling/src/sdp/RsdparsaSdpGlue.h
Normal file
31
media/webrtc/signaling/src/sdp/RsdparsaSdpGlue.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#ifndef _RUSTSDPGLUE_H_
|
||||
#define _RUSTSDPGLUE_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "signaling/src/sdp/Sdp.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpInc.h"
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
struct FreeRustSdpSession {
|
||||
void operator()(RustSdpSession* aSess) { sdp_free_session(aSess); }
|
||||
};
|
||||
|
||||
typedef UniquePtr<RustSdpSession, FreeRustSdpSession> RsdparsaSessionHandle;
|
||||
|
||||
std::string convertStringView(StringView str);
|
||||
std::vector<std::string> convertStringVec(StringVec* vec);
|
||||
sdp::AddrType convertAddressType(RustSdpAddrType addr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
289
media/webrtc/signaling/src/sdp/RsdparsaSdpInc.h
Normal file
289
media/webrtc/signaling/src/sdp/RsdparsaSdpInc.h
Normal file
@ -0,0 +1,289 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#ifndef _RUSTSDPINC_H_
|
||||
#define _RUSTSDPINC_H_
|
||||
|
||||
#include "nsError.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct BandwidthVec;
|
||||
struct RustSdpSession;
|
||||
struct RustSdpError;
|
||||
struct RustMediaSection;
|
||||
struct RustAttributeList;
|
||||
struct StringVec;
|
||||
struct U32Vec;
|
||||
struct RustHeapString;
|
||||
|
||||
enum class RustSdpAddrType {
|
||||
kRustAddrNone,
|
||||
kRustAddrIp4,
|
||||
kRustAddrIp6
|
||||
};
|
||||
|
||||
struct RustIpAddr {
|
||||
RustSdpAddrType addrType;
|
||||
char unicastAddr[50];
|
||||
};
|
||||
|
||||
struct StringView {
|
||||
char* buf;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
struct RustSdpConnection {
|
||||
RustIpAddr addr;
|
||||
uint8_t ttl;
|
||||
uint64_t amount;
|
||||
};
|
||||
|
||||
struct RustSdpOrigin {
|
||||
StringView username;
|
||||
uint64_t sessionId;
|
||||
uint64_t sessionVersion;
|
||||
RustIpAddr addr;
|
||||
};
|
||||
|
||||
enum class RustSdpMediaValue {
|
||||
kRustAudio,
|
||||
kRustVideo,
|
||||
kRustApplication
|
||||
};
|
||||
|
||||
enum class RustSdpProtocolValue {
|
||||
kRustRtpSavpf,
|
||||
kRustUdpTlsRtpSavpf,
|
||||
kRustTcpTlsRtpSavpf,
|
||||
kRustDtlsSctp,
|
||||
kRustUdpDtlsSctp,
|
||||
kRustTcpDtlsSctp,
|
||||
};
|
||||
|
||||
enum class RustSdpFormatType {
|
||||
kRustIntegers,
|
||||
kRustStrings
|
||||
};
|
||||
|
||||
struct RustSdpAttributeFingerprint {
|
||||
StringView hashAlgorithm;
|
||||
StringView fingerprint;
|
||||
};
|
||||
|
||||
enum class RustSdpSetup {
|
||||
kRustActive,
|
||||
kRustActpass,
|
||||
kRustHoldconn,
|
||||
kRustPassive
|
||||
};
|
||||
|
||||
struct RustSdpAttributeSsrc {
|
||||
uint32_t id;
|
||||
StringView attribute;
|
||||
StringView value;
|
||||
};
|
||||
|
||||
struct RustSdpAttributeRtpmap {
|
||||
uint8_t payloadType;
|
||||
StringView codecName;
|
||||
uint32_t frequency;
|
||||
uint32_t channels;
|
||||
};
|
||||
|
||||
struct RustSdpAttributeFmtp {
|
||||
uint8_t payloadType;
|
||||
StringView codecName;
|
||||
StringVec* tokens;
|
||||
};
|
||||
|
||||
struct RustSdpAttributeFlags {
|
||||
bool iceLite;
|
||||
bool rtcpMux;
|
||||
bool bundleOnly;
|
||||
bool endOfCandidates;
|
||||
};
|
||||
|
||||
struct RustSdpAttributeMsid {
|
||||
StringView id;
|
||||
StringView appdata;
|
||||
};
|
||||
|
||||
struct RustSdpAttributeMsidSemantic {
|
||||
StringView semantic;
|
||||
StringVec* msids;
|
||||
};
|
||||
|
||||
enum class RustSdpAttributeGroupSemantic {
|
||||
kRustLipSynchronization,
|
||||
kRustFlowIdentification,
|
||||
kRustSingleReservationFlow,
|
||||
kRustAlternateNetworkAddressType,
|
||||
kRustForwardErrorCorrection,
|
||||
kRustDecodingDependency,
|
||||
kRustBundle,
|
||||
};
|
||||
|
||||
struct RustSdpAttributeGroup {
|
||||
RustSdpAttributeGroupSemantic semantic;
|
||||
StringVec* tags;
|
||||
};
|
||||
|
||||
struct RustSdpAttributeRtcp {
|
||||
uint32_t port;
|
||||
RustIpAddr unicastAddr;
|
||||
};
|
||||
|
||||
struct RustSdpAttributeSctpmap {
|
||||
uint32_t port;
|
||||
uint32_t channels;
|
||||
};
|
||||
|
||||
enum class RustDirection {
|
||||
kRustRecvonly,
|
||||
kRustSendonly,
|
||||
kRustSendrecv,
|
||||
kRustInactive
|
||||
};
|
||||
|
||||
struct RustSdpAttributeRemoteCandidate {
|
||||
uint32_t component;
|
||||
RustIpAddr address;
|
||||
uint32_t port;
|
||||
};
|
||||
|
||||
// TODO: Add field indicating whether direction was specified
|
||||
// See Bug 1438536.
|
||||
struct RustSdpAttributeExtmap {
|
||||
uint16_t id;
|
||||
RustDirection direction;
|
||||
StringView url;
|
||||
StringView extensionAttributes;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
||||
size_t string_vec_len(const StringVec* vec);
|
||||
nsresult string_vec_get_view(const StringVec* vec, size_t index,
|
||||
StringView* str);
|
||||
|
||||
size_t u32_vec_len(const U32Vec* vec);
|
||||
nsresult u32_vec_get(const U32Vec* vec, size_t index, uint32_t* ret);
|
||||
|
||||
void sdp_free_string(char* string);
|
||||
|
||||
nsresult parse_sdp(const char* sdp, uint32_t length, bool fail_on_warning,
|
||||
RustSdpSession** ret, RustSdpError** err);
|
||||
RustSdpSession* sdp_new_reference(RustSdpSession* aSess);
|
||||
void sdp_free_session(RustSdpSession* ret);
|
||||
size_t sdp_get_error_line_num(const RustSdpError* err);
|
||||
StringView sdp_get_error_message(const RustSdpError* err);
|
||||
void sdp_free_error(RustSdpError* err);
|
||||
|
||||
RustSdpOrigin sdp_get_origin(const RustSdpSession* aSess);
|
||||
|
||||
uint32_t get_sdp_bandwidth(const RustSdpSession* aSess,
|
||||
const char* aBandwidthType);
|
||||
BandwidthVec* sdp_get_session_bandwidth_vec(const RustSdpSession* aSess);
|
||||
BandwidthVec* sdp_get_media_bandwidth_vec(const RustMediaSection* aMediaSec);
|
||||
char* sdp_serialize_bandwidth(const BandwidthVec* bandwidths);
|
||||
bool sdp_session_has_connection(const RustSdpSession* aSess);
|
||||
nsresult sdp_get_session_connection(const RustSdpSession* aSess,
|
||||
RustSdpConnection* ret);
|
||||
RustAttributeList* get_sdp_session_attributes(const RustSdpSession* aSess);
|
||||
|
||||
size_t sdp_media_section_count(const RustSdpSession* aSess);
|
||||
RustMediaSection* sdp_get_media_section(const RustSdpSession* aSess,
|
||||
size_t aLevel);
|
||||
RustSdpMediaValue sdp_rust_get_media_type(const RustMediaSection* aMediaSec);
|
||||
RustSdpProtocolValue
|
||||
sdp_get_media_protocol(const RustMediaSection* aMediaSec);
|
||||
RustSdpFormatType sdp_get_format_type(const RustMediaSection* aMediaSec);
|
||||
StringVec* sdp_get_format_string_vec(const RustMediaSection* aMediaSec);
|
||||
U32Vec* sdp_get_format_u32_vec(const RustMediaSection* aMediaSec);
|
||||
uint32_t sdp_get_media_port(const RustMediaSection* aMediaSec);
|
||||
uint32_t sdp_get_media_port_count(const RustMediaSection* aMediaSec);
|
||||
uint32_t sdp_get_media_bandwidth(const RustMediaSection* aMediaSec,
|
||||
const char* aBandwidthType);
|
||||
bool sdp_media_has_connection(const RustMediaSection* aMediaSec);
|
||||
nsresult sdp_get_media_connection(const RustMediaSection* aMediaSec,
|
||||
RustSdpConnection* ret);
|
||||
|
||||
RustAttributeList*
|
||||
sdp_get_media_attribute_list(const RustMediaSection* aMediaSec);
|
||||
|
||||
nsresult sdp_get_iceufrag(const RustAttributeList* aList, StringView* ret);
|
||||
nsresult sdp_get_icepwd(const RustAttributeList* aList, StringView* ret);
|
||||
nsresult sdp_get_identity(const RustAttributeList* aList, StringView* ret);
|
||||
nsresult sdp_get_iceoptions(const RustAttributeList* aList, StringVec** ret);
|
||||
|
||||
size_t sdp_get_fingerprint_count(const RustAttributeList* aList);
|
||||
void sdp_get_fingerprints(const RustAttributeList* aList, size_t listSize,
|
||||
RustSdpAttributeFingerprint* ret);
|
||||
|
||||
nsresult sdp_get_setup(const RustAttributeList* aList, RustSdpSetup* ret);
|
||||
|
||||
size_t sdp_get_ssrc_count(const RustAttributeList* aList);
|
||||
void sdp_get_ssrcs(const RustAttributeList* aList,
|
||||
size_t listSize, RustSdpAttributeSsrc* ret);
|
||||
|
||||
size_t sdp_get_rtpmap_count(const RustAttributeList* aList);
|
||||
void sdp_get_rtpmaps(const RustAttributeList* aList, size_t listSize,
|
||||
RustSdpAttributeRtpmap* ret);
|
||||
|
||||
size_t sdp_get_fmtp_count(const RustAttributeList* aList);
|
||||
size_t sdp_get_fmtp(const RustAttributeList* aList, size_t listSize,
|
||||
RustSdpAttributeFmtp* ret);
|
||||
|
||||
int64_t sdp_get_ptime(const RustAttributeList* aList);
|
||||
|
||||
RustSdpAttributeFlags sdp_get_attribute_flags(const RustAttributeList* aList);
|
||||
|
||||
nsresult sdp_get_mid(const RustAttributeList* aList, StringView* ret);
|
||||
|
||||
size_t sdp_get_msid_count(const RustAttributeList* aList);
|
||||
void sdp_get_msids(const RustAttributeList* aList, size_t listSize,
|
||||
RustSdpAttributeMsid* ret);
|
||||
|
||||
size_t sdp_get_msid_semantic_count(RustAttributeList* aList);
|
||||
void sdp_get_msid_semantics(const RustAttributeList* aList, size_t listSize,
|
||||
RustSdpAttributeMsidSemantic* ret);
|
||||
|
||||
size_t sdp_get_group_count(const RustAttributeList* aList);
|
||||
nsresult sdp_get_groups(const RustAttributeList* aList, size_t listSize,
|
||||
RustSdpAttributeGroup* ret);
|
||||
|
||||
nsresult sdp_get_rtcp(const RustAttributeList* aList,
|
||||
RustSdpAttributeRtcp* ret);
|
||||
|
||||
size_t sdp_get_imageattr_count(const RustAttributeList* aList);
|
||||
void sdp_get_imageattrs(const RustAttributeList* aList, size_t listSize,
|
||||
StringView* ret);
|
||||
|
||||
size_t sdp_get_sctpmap_count(const RustAttributeList* aList);
|
||||
void sdp_get_sctpmaps(const RustAttributeList* aList, size_t listSize,
|
||||
RustSdpAttributeSctpmap* ret);
|
||||
|
||||
RustDirection sdp_get_direction(const RustAttributeList* aList);
|
||||
|
||||
|
||||
size_t sdp_get_remote_candidate_count(const RustAttributeList* aList);
|
||||
void sdp_get_remote_candidates(const RustAttributeList* aList,
|
||||
size_t listSize,
|
||||
RustSdpAttributeRemoteCandidate* ret);
|
||||
|
||||
size_t sdp_get_rid_count(const RustAttributeList* aList);
|
||||
void sdp_get_rids(const RustAttributeList* aList, size_t listSize,
|
||||
StringView* ret);
|
||||
|
||||
|
||||
size_t sdp_get_extmap_count(const RustAttributeList* aList);
|
||||
void sdp_get_extmaps(const RustAttributeList* aList, size_t listSize,
|
||||
RustSdpAttributeExtmap* ret);
|
||||
|
||||
} //extern "C"
|
||||
|
||||
#endif
|
235
media/webrtc/signaling/src/sdp/RsdparsaSdpMediaSection.cpp
Normal file
235
media/webrtc/signaling/src/sdp/RsdparsaSdpMediaSection.cpp
Normal file
@ -0,0 +1,235 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// Bug 1433534 tracks cleaning up the TODOs in the file
|
||||
|
||||
#include "signaling/src/sdp/SdpMediaSection.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpMediaSection.h"
|
||||
|
||||
#include "signaling/src/sdp/RsdparsaSdpGlue.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpInc.h"
|
||||
|
||||
#include <ostream>
|
||||
#include "signaling/src/sdp/SdpErrorHolder.h"
|
||||
|
||||
#ifdef CRLF
|
||||
#undef CRLF
|
||||
#endif
|
||||
#define CRLF "\r\n"
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
RsdparsaSdpMediaSection::RsdparsaSdpMediaSection(size_t level,
|
||||
RsdparsaSessionHandle session, const RustMediaSection* const section,
|
||||
const RsdparsaSdpAttributeList* sessionLevel)
|
||||
: SdpMediaSection(level), mSession(Move(session)),
|
||||
mSection(section)
|
||||
{
|
||||
switch(sdp_rust_get_media_type(section)) {
|
||||
case RustSdpMediaValue::kRustAudio:
|
||||
mMediaType = kAudio;
|
||||
break;
|
||||
case RustSdpMediaValue::kRustVideo:
|
||||
mMediaType = kVideo;
|
||||
break;
|
||||
case RustSdpMediaValue::kRustApplication:
|
||||
mMediaType = kApplication;
|
||||
break;
|
||||
}
|
||||
|
||||
RsdparsaSessionHandle attributeSession(sdp_new_reference(mSession.get()));
|
||||
mAttributeList.reset(new RsdparsaSdpAttributeList(Move(attributeSession),
|
||||
section,
|
||||
sessionLevel));
|
||||
|
||||
LoadFormats();
|
||||
LoadConnection();
|
||||
}
|
||||
|
||||
unsigned int
|
||||
RsdparsaSdpMediaSection::GetPort() const
|
||||
{
|
||||
return sdp_get_media_port(mSection);
|
||||
}
|
||||
|
||||
void
|
||||
RsdparsaSdpMediaSection::SetPort(unsigned int port)
|
||||
{
|
||||
// TODO, see Bug 1433093
|
||||
}
|
||||
|
||||
unsigned int
|
||||
RsdparsaSdpMediaSection::GetPortCount() const
|
||||
{
|
||||
return sdp_get_media_port_count(mSection);
|
||||
}
|
||||
|
||||
SdpMediaSection::Protocol
|
||||
RsdparsaSdpMediaSection::GetProtocol() const
|
||||
{
|
||||
switch(sdp_get_media_protocol(mSection)) {
|
||||
case RustSdpProtocolValue::kRustRtpSavpf:
|
||||
return kRtpSavpf;
|
||||
case RustSdpProtocolValue::kRustUdpTlsRtpSavpf:
|
||||
return kUdpTlsRtpSavpf;
|
||||
case RustSdpProtocolValue::kRustTcpTlsRtpSavpf:
|
||||
return kTcpTlsRtpSavpf;
|
||||
case RustSdpProtocolValue::kRustDtlsSctp:
|
||||
return kDtlsSctp;
|
||||
case RustSdpProtocolValue::kRustUdpDtlsSctp:
|
||||
return kUdpDtlsSctp;
|
||||
case RustSdpProtocolValue::kRustTcpDtlsSctp:
|
||||
return kTcpDtlsSctp;
|
||||
}
|
||||
|
||||
MOZ_CRASH("invalid media protocol");
|
||||
}
|
||||
|
||||
const SdpConnection&
|
||||
RsdparsaSdpMediaSection::GetConnection() const
|
||||
{
|
||||
MOZ_ASSERT(mConnection);
|
||||
return *mConnection;
|
||||
}
|
||||
|
||||
SdpConnection&
|
||||
RsdparsaSdpMediaSection::GetConnection()
|
||||
{
|
||||
MOZ_ASSERT(mConnection);
|
||||
return *mConnection;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
RsdparsaSdpMediaSection::GetBandwidth(const std::string& type) const
|
||||
{
|
||||
return sdp_get_media_bandwidth(mSection, type.c_str());
|
||||
}
|
||||
|
||||
const std::vector<std::string>&
|
||||
RsdparsaSdpMediaSection::GetFormats() const
|
||||
{
|
||||
return mFormats;
|
||||
}
|
||||
|
||||
const SdpAttributeList&
|
||||
RsdparsaSdpMediaSection::GetAttributeList() const
|
||||
{
|
||||
return *mAttributeList;
|
||||
}
|
||||
|
||||
SdpAttributeList&
|
||||
RsdparsaSdpMediaSection::GetAttributeList()
|
||||
{
|
||||
return *mAttributeList;
|
||||
}
|
||||
|
||||
SdpDirectionAttribute
|
||||
RsdparsaSdpMediaSection::GetDirectionAttribute() const
|
||||
{
|
||||
return SdpDirectionAttribute(mAttributeList->GetDirection());
|
||||
}
|
||||
|
||||
void
|
||||
RsdparsaSdpMediaSection::AddCodec(const std::string& pt,
|
||||
const std::string& name,
|
||||
uint32_t clockrate, uint16_t channels)
|
||||
{
|
||||
//TODO: see Bug 1438289
|
||||
}
|
||||
|
||||
void
|
||||
RsdparsaSdpMediaSection::ClearCodecs()
|
||||
{
|
||||
|
||||
//TODO: see Bug 1438289
|
||||
}
|
||||
|
||||
void
|
||||
RsdparsaSdpMediaSection::AddDataChannel(const std::string& name, uint16_t port,
|
||||
uint16_t streams, uint32_t message_size)
|
||||
{
|
||||
//TODO: See 1438290
|
||||
}
|
||||
|
||||
void
|
||||
RsdparsaSdpMediaSection::Serialize(std::ostream& os) const
|
||||
{
|
||||
os << "m=" << mMediaType << " " << GetPort();
|
||||
if (GetPortCount()) {
|
||||
os << "/" << GetPortCount();
|
||||
}
|
||||
os << " " << GetProtocol();
|
||||
for (auto i = mFormats.begin(); i != mFormats.end(); ++i) {
|
||||
os << " " << (*i);
|
||||
}
|
||||
os << CRLF;
|
||||
|
||||
// We dont do i=
|
||||
|
||||
if (mConnection) {
|
||||
os << *mConnection;
|
||||
}
|
||||
|
||||
BandwidthVec* bwVec = sdp_get_media_bandwidth_vec(mSection);
|
||||
char* bwString = sdp_serialize_bandwidth(bwVec);
|
||||
if (bwString) {
|
||||
os << bwString;
|
||||
sdp_free_string(bwString);
|
||||
}
|
||||
|
||||
// We dont do k= because they're evil
|
||||
|
||||
os << *mAttributeList;
|
||||
}
|
||||
|
||||
void
|
||||
RsdparsaSdpMediaSection::LoadFormats()
|
||||
{
|
||||
RustSdpFormatType formatType = sdp_get_format_type(mSection);
|
||||
if (formatType == RustSdpFormatType::kRustIntegers) {
|
||||
U32Vec* vec = sdp_get_format_u32_vec(mSection);
|
||||
size_t len = u32_vec_len(vec);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
uint32_t val;
|
||||
u32_vec_get(vec, i, &val);
|
||||
mFormats.push_back(std::to_string(val));
|
||||
}
|
||||
} else {
|
||||
StringVec* vec = sdp_get_format_string_vec(mSection);
|
||||
mFormats = convertStringVec(vec);
|
||||
}
|
||||
}
|
||||
|
||||
UniquePtr<SdpConnection> convertRustConnection(RustSdpConnection conn)
|
||||
{
|
||||
std::string addr(conn.addr.unicastAddr);
|
||||
sdp::AddrType type = convertAddressType(conn.addr.addrType);
|
||||
return MakeUnique<SdpConnection>(type, addr, conn.ttl, conn.amount);
|
||||
}
|
||||
|
||||
void
|
||||
RsdparsaSdpMediaSection::LoadConnection()
|
||||
{
|
||||
RustSdpConnection conn;
|
||||
nsresult nr;
|
||||
if (sdp_media_has_connection(mSection)) {
|
||||
nr = sdp_get_media_connection(mSection, &conn);
|
||||
if (NS_SUCCEEDED(nr)) {
|
||||
mConnection = convertRustConnection(conn);
|
||||
}
|
||||
} else if (sdp_session_has_connection(mSession.get())){
|
||||
// TODO: rsdparsa needs to ensure there is a connection at the session level
|
||||
// if it is missing at a media level. See Bug 1438539.
|
||||
nr = sdp_get_session_connection(mSession.get(), &conn);
|
||||
if (NS_SUCCEEDED(nr)) {
|
||||
mConnection = convertRustConnection(conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
81
media/webrtc/signaling/src/sdp/RsdparsaSdpMediaSection.h
Normal file
81
media/webrtc/signaling/src/sdp/RsdparsaSdpMediaSection.h
Normal file
@ -0,0 +1,81 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef _RUSTSDPMEDIASECTION_H_
|
||||
#define _RUSTSDPMEDIASECTION_H_
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpInc.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpGlue.h"
|
||||
#include "signaling/src/sdp/SdpMediaSection.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpAttributeList.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
class RsdparsaSdp;
|
||||
class SdpErrorHolder;
|
||||
|
||||
class RsdparsaSdpMediaSection final : public SdpMediaSection
|
||||
{
|
||||
friend class RsdparsaSdp;
|
||||
|
||||
public:
|
||||
~RsdparsaSdpMediaSection() {}
|
||||
|
||||
MediaType
|
||||
GetMediaType() const override
|
||||
{
|
||||
return mMediaType;
|
||||
}
|
||||
|
||||
unsigned int GetPort() const override;
|
||||
void SetPort(unsigned int port) override;
|
||||
unsigned int GetPortCount() const override;
|
||||
Protocol GetProtocol() const override;
|
||||
const SdpConnection& GetConnection() const override;
|
||||
SdpConnection& GetConnection() override;
|
||||
uint32_t GetBandwidth(const std::string& type) const override;
|
||||
const std::vector<std::string>& GetFormats() const override;
|
||||
|
||||
const SdpAttributeList& GetAttributeList() const override;
|
||||
SdpAttributeList& GetAttributeList() override;
|
||||
SdpDirectionAttribute GetDirectionAttribute() const override;
|
||||
|
||||
void AddCodec(const std::string& pt, const std::string& name,
|
||||
uint32_t clockrate, uint16_t channels) override;
|
||||
void ClearCodecs() override;
|
||||
|
||||
void AddDataChannel(const std::string& name, uint16_t port,
|
||||
uint16_t streams, uint32_t message_size) override;
|
||||
|
||||
void Serialize(std::ostream&) const override;
|
||||
|
||||
private:
|
||||
RsdparsaSdpMediaSection(size_t level,
|
||||
RsdparsaSessionHandle session,
|
||||
const RustMediaSection* const section,
|
||||
const RsdparsaSdpAttributeList* sessionLevel);
|
||||
|
||||
void LoadFormats();
|
||||
void LoadConnection();
|
||||
|
||||
RsdparsaSessionHandle mSession;
|
||||
const RustMediaSection* mSection;
|
||||
|
||||
MediaType mMediaType;
|
||||
std::vector<std::string> mFormats;
|
||||
|
||||
UniquePtr<SdpConnection> mConnection;
|
||||
|
||||
UniquePtr<RsdparsaSdpAttributeList> mAttributeList;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
53
media/webrtc/signaling/src/sdp/RsdparsaSdpParser.cpp
Normal file
53
media/webrtc/signaling/src/sdp/RsdparsaSdpParser.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsError.h"
|
||||
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
#include "signaling/src/sdp/Sdp.h"
|
||||
#include "signaling/src/sdp/SdpEnum.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdp.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpParser.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpInc.h"
|
||||
#include "signaling/src/sdp/RsdparsaSdpGlue.h"
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
UniquePtr<Sdp>
|
||||
RsdparsaSdpParser::Parse(const std::string &sdpText)
|
||||
{
|
||||
ClearParseErrors();
|
||||
const char* rawString = sdpText.c_str();
|
||||
RustSdpSession* result;
|
||||
RustSdpError* err;
|
||||
nsresult rv = parse_sdp(rawString, sdpText.length() + 1, false,
|
||||
&result, &err);
|
||||
if (rv != NS_OK) {
|
||||
// TODO: err should eventually never be null if rv != NS_OK
|
||||
// see Bug 1433529
|
||||
if (err != nullptr) {
|
||||
size_t line = sdp_get_error_line_num(err);
|
||||
std::string errMsg = convertStringView(sdp_get_error_message(err));
|
||||
sdp_free_error(err);
|
||||
AddParseError(line, errMsg);
|
||||
} else {
|
||||
AddParseError(0, "Unhandled Rsdparsa parsing error");
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
RsdparsaSessionHandle uniqueResult;
|
||||
uniqueResult.reset(result);
|
||||
RustSdpOrigin rustOrigin = sdp_get_origin(uniqueResult.get());
|
||||
sdp::AddrType addrType = convertAddressType(rustOrigin.addr.addrType);
|
||||
SdpOrigin origin(convertStringView(rustOrigin.username),
|
||||
rustOrigin.sessionId, rustOrigin.sessionVersion,
|
||||
addrType, std::string(rustOrigin.addr.unicastAddr));
|
||||
return MakeUnique<RsdparsaSdp>(Move(uniqueResult), origin);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
35
media/webrtc/signaling/src/sdp/RsdparsaSdpParser.h
Normal file
35
media/webrtc/signaling/src/sdp/RsdparsaSdpParser.h
Normal file
@ -0,0 +1,35 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef _RUSTSDPPARSER_H_
|
||||
#define _RUSTSDPPARSER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
#include "signaling/src/sdp/Sdp.h"
|
||||
#include "signaling/src/sdp/SdpErrorHolder.h"
|
||||
|
||||
namespace mozilla
|
||||
{
|
||||
|
||||
class RsdparsaSdpParser final : public SdpErrorHolder
|
||||
{
|
||||
public:
|
||||
RsdparsaSdpParser() {}
|
||||
virtual ~RsdparsaSdpParser() {}
|
||||
|
||||
/**
|
||||
* This parses the provided text into an SDP object.
|
||||
* This returns a nullptr-valued pointer if things go poorly.
|
||||
*/
|
||||
UniquePtr<Sdp> Parse(const std::string& sdpText);
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
@ -37,8 +37,15 @@ UNIFIED_SOURCES += [
|
||||
'SipccSdpParser.cpp',
|
||||
]
|
||||
|
||||
# Multiple definitions of "logTag" mean we can't use unified build here.
|
||||
SOURCES += [
|
||||
# Building these as part of the unified build leads to multiply defined
|
||||
# symbols on windows.
|
||||
'RsdparsaSdp.cpp',
|
||||
'RsdparsaSdpAttributeList.cpp',
|
||||
'RsdparsaSdpGlue.cpp',
|
||||
'RsdparsaSdpMediaSection.cpp',
|
||||
'RsdparsaSdpParser.cpp',
|
||||
# Multiple definitions of "logTag" mean we can't use unified build here.
|
||||
'sipcc/cpr_string.c',
|
||||
'sipcc/sdp_access.c',
|
||||
'sipcc/sdp_attr.c',
|
||||
|
Loading…
Reference in New Issue
Block a user