/* 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 DOM_MEDIA_WEBRTC_SDP_RSDPARSASDPGLUE_H_ #define DOM_MEDIA_WEBRTC_SDP_RSDPARSASDPGLUE_H_ #include #include #include #include #include "SdpEnum.h" #include "mozilla/Assertions.h" #include "mozilla/UniquePtr.h" #include "nsTArray.h" #include "sdp/RsdparsaSdpInc.h" #include "sdp/SdpMediaSectionImpl.h" namespace mozilla { struct FreeRustSdpSession { void operator()(sdp::ffi::SdpSession* aSess) { sdp_free_session(aSess); } }; using RsdparsaSessionHandle = UniquePtr; template std::span convertRustSpan(sdp::ffi::RustSpan s) { if (!s.buffer) { return std::span(); } return std::span(s.buffer, s.len); } inline std::string_view convertStringView(sdp::ffi::StringView str) { if (!str.buffer) { return std::string_view(); } return std::string_view(reinterpret_cast(str.buffer), str.len); } inline std::string convertAddress(const sdp::ffi::RustAddress& address) { if (address.is_fqdn) { return std::string(convertStringView(address.fqdn)); } return std::string(reinterpret_cast(address.ip_address)); } inline sdp::AddrType convertAddressType(sdp::ffi::RustAddressType type) { switch (type) { case sdp::ffi::RustAddressType::IP4: return sdp::kIPv4; case sdp::ffi::RustAddressType::IP6: return sdp::kIPv6; } MOZ_CRASH("unknown address type"); } inline std::pair convertExplicitlyTypedAddress( const sdp::ffi::RustExplicitlyTypedAddress& address) { return std::make_pair(convertAddressType(address.address_type), convertAddress(address.address)); } inline void convertBandwidths( const sdp::ffi::Vec* aBandwidths, SdpBandwidths& aTarget) { AutoTArray bandwidths; sdp_get_bandwidths(aBandwidths, &bandwidths); for (const auto& bandwidth : bandwidths) { aTarget[std::string(convertStringView(bandwidth.name))] = bandwidth.value; } } } // namespace mozilla #endif