Fix no_size_t_to_int_warning in rtp_rtcp:rtp_rtcp_format target
Change types in interface to plain int. When putting values into raw buffer / structures with small types, use rtc::dchecked_cast. BUG=webrtc:1348 Review-Url: https://codereview.webrtc.org/3013623002 Cr-Commit-Position: refs/heads/master@{#19813}
This commit is contained in:
parent
87443ee3e6
commit
772bd8b6a7
@ -34,9 +34,6 @@ rtc_source_set("rtp_rtcp_format") {
|
||||
"../../rtc_base:rtc_base_approved",
|
||||
"../../system_wrappers",
|
||||
]
|
||||
|
||||
# TODO(crbug.com/webrtc/1348): Fix this warning.
|
||||
configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
|
||||
}
|
||||
|
||||
rtc_static_library("rtp_rtcp") {
|
||||
|
||||
@ -29,23 +29,23 @@ struct RtpExtensionSize {
|
||||
class RtpHeaderExtensionMap {
|
||||
public:
|
||||
static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone;
|
||||
static constexpr uint8_t kInvalidId = 0;
|
||||
static constexpr int kInvalidId = 0;
|
||||
|
||||
RtpHeaderExtensionMap();
|
||||
explicit RtpHeaderExtensionMap(rtc::ArrayView<const RtpExtension> extensions);
|
||||
|
||||
template <typename Extension>
|
||||
bool Register(uint8_t id) {
|
||||
bool Register(int id) {
|
||||
return Register(id, Extension::kId, Extension::kUri);
|
||||
}
|
||||
bool RegisterByType(uint8_t id, RTPExtensionType type);
|
||||
bool RegisterByUri(uint8_t id, const std::string& uri);
|
||||
bool RegisterByType(int id, RTPExtensionType type);
|
||||
bool RegisterByUri(int id, const std::string& uri);
|
||||
|
||||
bool IsRegistered(RTPExtensionType type) const {
|
||||
return GetId(type) != kInvalidId;
|
||||
}
|
||||
// Return kInvalidType if not found.
|
||||
RTPExtensionType GetType(uint8_t id) const {
|
||||
RTPExtensionType GetType(int id) const {
|
||||
RTC_DCHECK_GE(id, kMinId);
|
||||
RTC_DCHECK_LE(id, kMaxId);
|
||||
return types_[id];
|
||||
@ -61,15 +61,15 @@ class RtpHeaderExtensionMap {
|
||||
rtc::ArrayView<const RtpExtensionSize> extensions) const;
|
||||
|
||||
// TODO(danilchap): Remove use of the functions below.
|
||||
int32_t Register(RTPExtensionType type, uint8_t id) {
|
||||
int32_t Register(RTPExtensionType type, int id) {
|
||||
return RegisterByType(id, type) ? 0 : -1;
|
||||
}
|
||||
int32_t Deregister(RTPExtensionType type);
|
||||
|
||||
private:
|
||||
static constexpr uint8_t kMinId = 1;
|
||||
static constexpr uint8_t kMaxId = 14;
|
||||
bool Register(uint8_t id, RTPExtensionType type, const char* uri);
|
||||
static constexpr int kMinId = 1;
|
||||
static constexpr int kMaxId = 14;
|
||||
bool Register(int id, RTPExtensionType type, const char* uri);
|
||||
|
||||
RTPExtensionType types_[kMaxId + 1];
|
||||
uint8_t ids_[kRtpExtensionNumberOfExtensions];
|
||||
|
||||
@ -51,9 +51,9 @@ static_assert(arraysize(kExtensions) ==
|
||||
} // namespace
|
||||
|
||||
constexpr RTPExtensionType RtpHeaderExtensionMap::kInvalidType;
|
||||
constexpr uint8_t RtpHeaderExtensionMap::kInvalidId;
|
||||
constexpr uint8_t RtpHeaderExtensionMap::kMinId;
|
||||
constexpr uint8_t RtpHeaderExtensionMap::kMaxId;
|
||||
constexpr int RtpHeaderExtensionMap::kInvalidId;
|
||||
constexpr int RtpHeaderExtensionMap::kMinId;
|
||||
constexpr int RtpHeaderExtensionMap::kMaxId;
|
||||
|
||||
RtpHeaderExtensionMap::RtpHeaderExtensionMap() {
|
||||
for (auto& type : types_)
|
||||
@ -69,7 +69,7 @@ RtpHeaderExtensionMap::RtpHeaderExtensionMap(
|
||||
RegisterByUri(extension.id, extension.uri);
|
||||
}
|
||||
|
||||
bool RtpHeaderExtensionMap::RegisterByType(uint8_t id, RTPExtensionType type) {
|
||||
bool RtpHeaderExtensionMap::RegisterByType(int id, RTPExtensionType type) {
|
||||
for (const ExtensionInfo& extension : kExtensions)
|
||||
if (type == extension.type)
|
||||
return Register(id, extension.type, extension.uri);
|
||||
@ -77,12 +77,12 @@ bool RtpHeaderExtensionMap::RegisterByType(uint8_t id, RTPExtensionType type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RtpHeaderExtensionMap::RegisterByUri(uint8_t id, const std::string& uri) {
|
||||
bool RtpHeaderExtensionMap::RegisterByUri(int id, const std::string& uri) {
|
||||
for (const ExtensionInfo& extension : kExtensions)
|
||||
if (uri == extension.uri)
|
||||
return Register(id, extension.type, extension.uri);
|
||||
LOG(LS_WARNING) << "Unknown extension uri:'" << uri
|
||||
<< "', id: " << static_cast<int>(id) << '.';
|
||||
<< "', id: " << id << '.';
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ int32_t RtpHeaderExtensionMap::Deregister(RTPExtensionType type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RtpHeaderExtensionMap::Register(uint8_t id,
|
||||
bool RtpHeaderExtensionMap::Register(int id,
|
||||
RTPExtensionType type,
|
||||
const char* uri) {
|
||||
RTC_DCHECK_GT(type, kRtpExtensionNone);
|
||||
@ -122,19 +122,19 @@ bool RtpHeaderExtensionMap::Register(uint8_t id,
|
||||
|
||||
if (id < kMinId || id > kMaxId) {
|
||||
LOG(LS_WARNING) << "Failed to register extension uri:'" << uri
|
||||
<< "' with invalid id:" << static_cast<int>(id) << ".";
|
||||
<< "' with invalid id:" << id << ".";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GetType(id) == type) { // Same type/id pair already registered.
|
||||
LOG(LS_VERBOSE) << "Reregistering extension uri:'" << uri
|
||||
<< "', id:" << static_cast<int>(id);
|
||||
<< "', id:" << id;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (GetType(id) != kInvalidType) { // |id| used by another extension type.
|
||||
LOG(LS_WARNING) << "Failed to register extension uri:'" << uri
|
||||
<< "', id:" << static_cast<int>(id)
|
||||
<< "', id:" << id
|
||||
<< ". Id already in use by extension type "
|
||||
<< static_cast<int>(GetType(id));
|
||||
return false;
|
||||
@ -142,7 +142,8 @@ bool RtpHeaderExtensionMap::Register(uint8_t id,
|
||||
RTC_DCHECK(!IsRegistered(type));
|
||||
|
||||
types_[id] = type;
|
||||
ids_[type] = id;
|
||||
// There is a run-time check above id fits into uint8_t.
|
||||
ids_[type] = static_cast<uint8_t>(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include "webrtc/rtc_base/checks.h"
|
||||
#include "webrtc/rtc_base/logging.h"
|
||||
#include "webrtc/rtc_base/random.h"
|
||||
#include "webrtc/rtc_base/safe_conversions.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace rtp {
|
||||
@ -30,7 +31,7 @@ constexpr size_t kOneByteHeaderSize = 1;
|
||||
constexpr size_t kDefaultPacketSize = 1500;
|
||||
} // namespace
|
||||
|
||||
constexpr size_t Packet::kMaxExtensionHeaders;
|
||||
constexpr int Packet::kMaxExtensionHeaders;
|
||||
constexpr int Packet::kMinExtensionId;
|
||||
constexpr int Packet::kMaxExtensionId;
|
||||
|
||||
@ -78,7 +79,7 @@ Packet::Packet(const ExtensionManager* extensions, size_t capacity)
|
||||
Packet::~Packet() {}
|
||||
|
||||
void Packet::IdentifyExtensions(const ExtensionManager& extensions) {
|
||||
for (size_t i = 0; i < kMaxExtensionHeaders; ++i)
|
||||
for (int i = 0; i < kMaxExtensionHeaders; ++i)
|
||||
extension_entries_[i].type = extensions.GetType(i + 1);
|
||||
}
|
||||
|
||||
@ -242,7 +243,7 @@ void Packet::SetCsrcs(const std::vector<uint32_t>& csrcs) {
|
||||
RTC_DCHECK_LE(csrcs.size(), 0x0fu);
|
||||
RTC_DCHECK_LE(kFixedHeaderSize + 4 * csrcs.size(), capacity());
|
||||
payload_offset_ = kFixedHeaderSize + 4 * csrcs.size();
|
||||
WriteAt(0, (data()[0] & 0xF0) | csrcs.size());
|
||||
WriteAt(0, (data()[0] & 0xF0) | rtc::dchecked_cast<uint8_t>(csrcs.size()));
|
||||
size_t offset = kFixedHeaderSize;
|
||||
for (uint32_t csrc : csrcs) {
|
||||
ByteWriter<uint32_t>::WriteBigEndian(WriteAt(offset), csrc);
|
||||
@ -328,12 +329,14 @@ rtc::ArrayView<uint8_t> Packet::AllocateRawExtension(int id, size_t length) {
|
||||
kOneByteExtensionId);
|
||||
}
|
||||
|
||||
WriteAt(extensions_offset + extensions_size_, (id << 4) | (length - 1));
|
||||
uint8_t one_byte_header = rtc::dchecked_cast<uint8_t>(id) << 4;
|
||||
one_byte_header |= rtc::dchecked_cast<uint8_t>(length - 1);
|
||||
WriteAt(extensions_offset + extensions_size_, one_byte_header);
|
||||
|
||||
extension_entry->offset =
|
||||
extensions_offset + extensions_size_ + kOneByteHeaderSize;
|
||||
extension_entry->length = length;
|
||||
extensions_size_ = new_extensions_size;
|
||||
extension_entry->offset = rtc::dchecked_cast<uint16_t>(
|
||||
extensions_offset + extensions_size_ + kOneByteHeaderSize);
|
||||
extension_entry->length = rtc::dchecked_cast<uint8_t>(length);
|
||||
extensions_size_ = rtc::dchecked_cast<uint16_t>(new_extensions_size);
|
||||
|
||||
// Update header length field.
|
||||
uint16_t extensions_words = (extensions_size_ + 3) / 4; // Wrap up to 32bit.
|
||||
@ -497,8 +500,9 @@ bool Packet::ParseBuffer(const uint8_t* buffer, size_t size) {
|
||||
}
|
||||
|
||||
extensions_size_ += kOneByteHeaderSize;
|
||||
extension_entries_[idx].offset = extension_offset + extensions_size_;
|
||||
extension_entries_[idx].length = length;
|
||||
extension_entries_[idx].offset =
|
||||
rtc::dchecked_cast<uint16_t>(extension_offset + extensions_size_);
|
||||
extension_entries_[idx].length = rtc::dchecked_cast<uint16_t>(length);
|
||||
extensions_size_ += length;
|
||||
}
|
||||
}
|
||||
@ -527,7 +531,7 @@ rtc::ArrayView<const uint8_t> Packet::FindExtension(ExtensionType type) const {
|
||||
|
||||
rtc::ArrayView<uint8_t> Packet::AllocateExtension(ExtensionType type,
|
||||
size_t length) {
|
||||
for (size_t i = 0; i < kMaxExtensionHeaders; ++i) {
|
||||
for (int i = 0; i < kMaxExtensionHeaders; ++i) {
|
||||
if (extension_entries_[i].type == type) {
|
||||
int extension_id = i + 1;
|
||||
return AllocateRawExtension(extension_id, length);
|
||||
|
||||
@ -26,7 +26,7 @@ class Packet {
|
||||
public:
|
||||
using ExtensionType = RTPExtensionType;
|
||||
using ExtensionManager = RtpHeaderExtensionMap;
|
||||
static constexpr size_t kMaxExtensionHeaders = 14;
|
||||
static constexpr int kMaxExtensionHeaders = 14;
|
||||
static constexpr int kMinExtensionId = 1;
|
||||
static constexpr int kMaxExtensionId = 14;
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
|
||||
#include "webrtc/rtc_base/safe_conversions.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -23,7 +24,7 @@ void RtpPacketReceived::GetHeader(RTPHeader* header) const {
|
||||
header->timestamp = Timestamp();
|
||||
header->ssrc = Ssrc();
|
||||
std::vector<uint32_t> csrcs = Csrcs();
|
||||
header->numCSRCs = csrcs.size();
|
||||
header->numCSRCs = rtc::dchecked_cast<uint8_t>(csrcs.size());
|
||||
for (size_t i = 0; i < csrcs.size(); ++i) {
|
||||
header->arrOfCSRCs[i] = csrcs[i];
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user