Use ByteReader/ByteWriter instead of rtputility and manual shift/add.

BUG=
R=stefan@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/41289004

Cr-Commit-Position: refs/heads/master@{#8761}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8761 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
sprang@webrtc.org 2015-03-17 16:42:49 +00:00
parent 09098dabd3
commit 779c3d16b9
16 changed files with 163 additions and 249 deletions

View File

@ -13,8 +13,8 @@
#include <assert.h>
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/logging.h"
@ -179,7 +179,7 @@ int32_t FecReceiverImpl::AddReceivedRedPacket(
payload_data_length - REDHeaderLength);
received_packet->pkt->length = payload_data_length - REDHeaderLength;
received_packet->ssrc =
RtpUtility::BufferToUWord32(&incoming_rtp_packet[8]);
ByteReader<uint32_t>::ReadBigEndian(&incoming_rtp_packet[8]);
} else {
// copy the RTP header

View File

@ -10,6 +10,7 @@
#include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
namespace webrtc {
@ -86,9 +87,9 @@ void FrameGenerator::BuildRtpHeader(uint8_t* data, const RTPHeader* header) {
data[0] = 0x80; // Version 2.
data[1] = header->payloadType;
data[1] |= (header->markerBit ? kRtpMarkerBitMask : 0);
RtpUtility::AssignUWord16ToBuffer(data + 2, header->sequenceNumber);
RtpUtility::AssignUWord32ToBuffer(data + 4, header->timestamp);
RtpUtility::AssignUWord32ToBuffer(data + 8, header->ssrc);
ByteWriter<uint16_t>::WriteBigEndian(data + 2, header->sequenceNumber);
ByteWriter<uint32_t>::WriteBigEndian(data + 4, header->timestamp);
ByteWriter<uint32_t>::WriteBigEndian(data + 8, header->ssrc);
}
} // namespace webrtc

View File

@ -18,8 +18,8 @@
#include <iterator>
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
#include "webrtc/system_wrappers/interface/logging.h"
namespace webrtc {
@ -230,7 +230,7 @@ void ForwardErrorCorrection::GenerateFecBitStrings(
Packet* media_packet = *media_list_it;
// Assign network-ordered media payload length.
RtpUtility::AssignUWord16ToBuffer(
ByteWriter<uint16_t>::WriteBigEndian(
media_payload_length, media_packet->length - kRtpHeaderSize);
fec_packet_length = media_packet->length + fec_rtp_offset;
@ -432,7 +432,7 @@ void ForwardErrorCorrection::GenerateFecUlpHeaders(
// -- ULP header --
// Copy the payload size to the protection length field.
// (We protect the entire packet.)
RtpUtility::AssignUWord16ToBuffer(
ByteWriter<uint16_t>::WriteBigEndian(
&generated_fec_packets_[i].data[10],
generated_fec_packets_[i].length - kFecHeaderSize - ulp_header_size);
@ -537,7 +537,7 @@ void ForwardErrorCorrection::InsertFECPacket(
fec_packet->ssrc = rx_packet->ssrc;
const uint16_t seq_num_base =
RtpUtility::BufferToUWord16(&fec_packet->pkt->data[2]);
ByteReader<uint16_t>::ReadBigEndian(&fec_packet->pkt->data[2]);
const uint16_t maskSizeBytes =
(fec_packet->pkt->data[0] & 0x40) ? kMaskSizeLBitSet
: kMaskSizeLBitClear; // L bit set?
@ -650,7 +650,7 @@ void ForwardErrorCorrection::InitRecovery(const FecPacket* fec_packet,
// Copy FEC payload, skipping the ULP header.
memcpy(&recovered->pkt->data[kRtpHeaderSize],
&fec_packet->pkt->data[kFecHeaderSize + ulp_header_size],
RtpUtility::BufferToUWord16(protection_length));
ByteReader<uint16_t>::ReadBigEndian(protection_length));
// Copy the length recovery field.
memcpy(recovered->length_recovery, &fec_packet->pkt->data[8], 2);
// Copy the first 2 bytes of the FEC header.
@ -658,7 +658,8 @@ void ForwardErrorCorrection::InitRecovery(const FecPacket* fec_packet,
// Copy the 5th to 8th bytes of the FEC header.
memcpy(&recovered->pkt->data[4], &fec_packet->pkt->data[4], 4);
// Set the SSRC field.
RtpUtility::AssignUWord32ToBuffer(&recovered->pkt->data[8], fec_packet->ssrc);
ByteWriter<uint32_t>::WriteBigEndian(&recovered->pkt->data[8],
fec_packet->ssrc);
}
void ForwardErrorCorrection::FinishRecovery(RecoveredPacket* recovered) {
@ -667,11 +668,12 @@ void ForwardErrorCorrection::FinishRecovery(RecoveredPacket* recovered) {
recovered->pkt->data[0] &= 0xbf; // Clear the 2nd bit.
// Set the SN field.
RtpUtility::AssignUWord16ToBuffer(&recovered->pkt->data[2],
recovered->seq_num);
ByteWriter<uint16_t>::WriteBigEndian(&recovered->pkt->data[2],
recovered->seq_num);
// Recover the packet length.
recovered->pkt->length =
RtpUtility::BufferToUWord16(recovered->length_recovery) + kRtpHeaderSize;
ByteReader<uint16_t>::ReadBigEndian(recovered->length_recovery) +
kRtpHeaderSize;
}
void ForwardErrorCorrection::XorPackets(const Packet* src_packet,
@ -686,8 +688,8 @@ void ForwardErrorCorrection::XorPackets(const Packet* src_packet,
}
// XOR with the network-ordered payload size.
uint8_t media_payload_length[2];
RtpUtility::AssignUWord16ToBuffer(media_payload_length,
src_packet->length - kRtpHeaderSize);
ByteWriter<uint16_t>::WriteBigEndian(media_payload_length,
src_packet->length - kRtpHeaderSize);
dst_packet->length_recovery[0] ^= media_payload_length[0];
dst_packet->length_recovery[1] ^= media_payload_length[1];

View File

@ -10,6 +10,7 @@
#include "webrtc/modules/rtp_rtcp/source/producer_fec.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
@ -61,7 +62,8 @@ void RedPacket::CreateHeader(const uint8_t* rtp_header, size_t header_length,
void RedPacket::SetSeqNum(int seq_num) {
assert(seq_num >= 0 && seq_num < (1<<16));
RtpUtility::AssignUWord16ToBuffer(&data_[2], seq_num);
ByteWriter<uint16_t>::WriteBigEndian(&data_[2], seq_num);
}
void RedPacket::AssignPayload(const uint8_t* payload, size_t length) {

View File

@ -10,7 +10,7 @@
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/system_wrappers/interface/logging.h"
using webrtc::RTCPUtility::kBtDlrr;
@ -61,15 +61,15 @@ void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) {
buffer[(*offset)++] = value;
}
void AssignUWord16(uint8_t* buffer, size_t* offset, uint16_t value) {
RtpUtility::AssignUWord16ToBuffer(buffer + *offset, value);
ByteWriter<uint16_t>::WriteBigEndian(buffer + *offset, value);
*offset += 2;
}
void AssignUWord24(uint8_t* buffer, size_t* offset, uint32_t value) {
RtpUtility::AssignUWord24ToBuffer(buffer + *offset, value);
ByteWriter<uint32_t, 3>::WriteBigEndian(buffer + *offset, value);
*offset += 3;
}
void AssignUWord32(uint8_t* buffer, size_t* offset, uint32_t value) {
RtpUtility::AssignUWord32ToBuffer(buffer + *offset, value);
ByteWriter<uint32_t>::WriteBigEndian(buffer + *offset, value);
*offset += 4;
}

View File

@ -17,6 +17,7 @@
#include <algorithm> // min
#include "webrtc/common_types.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/logging.h"
@ -556,24 +557,24 @@ int32_t RTCPSender::BuildSR(const FeedbackState& feedback_state,
pos++;
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// NTP
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, NTPsec);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, NTPsec);
pos += 4;
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, NTPfrac);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, NTPfrac);
pos += 4;
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, RTPtime);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, RTPtime);
pos += 4;
//sender's packet count
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos,
feedback_state.packets_sent);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos,
feedback_state.packets_sent);
pos += 4;
//sender's octet count
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos,
feedback_state.media_bytes_sent);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos,
feedback_state.media_bytes_sent);
pos += 4;
uint8_t numberOfReportBlocks = 0;
@ -589,7 +590,7 @@ int32_t RTCPSender::BuildSR(const FeedbackState& feedback_state,
rtcpbuffer[posNumberOfReportBlocks] += numberOfReportBlocks;
uint16_t len = uint16_t((pos/4) -1);
RtpUtility::AssignUWord16ToBuffer(rtcpbuffer + 2, len);
ByteWriter<uint16_t>::WriteBigEndian(rtcpbuffer + 2, len);
return 0;
}
@ -615,7 +616,7 @@ int32_t RTCPSender::BuildSDEC(uint8_t* rtcpbuffer, int& pos) {
pos++;
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// CNAME = 1
@ -650,7 +651,7 @@ int32_t RTCPSender::BuildSDEC(uint8_t* rtcpbuffer, int& pos) {
uint32_t SSRC = it->first;
// Add SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, SSRC);
pos += 4;
// CNAME = 1
@ -681,7 +682,8 @@ int32_t RTCPSender::BuildSDEC(uint8_t* rtcpbuffer, int& pos) {
}
// in 32-bit words minus one and we don't count the header
uint16_t buffer_length = (SDESLength / 4) - 1;
RtpUtility::AssignUWord16ToBuffer(rtcpbuffer + SDESLengthPos, buffer_length);
ByteWriter<uint16_t>::WriteBigEndian(rtcpbuffer + SDESLengthPos,
buffer_length);
return 0;
}
@ -704,7 +706,7 @@ int32_t RTCPSender::BuildRR(uint8_t* rtcpbuffer,
pos++;
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
uint8_t numberOfReportBlocks = 0;
@ -719,7 +721,7 @@ int32_t RTCPSender::BuildRR(uint8_t* rtcpbuffer,
rtcpbuffer[posNumberOfReportBlocks] += numberOfReportBlocks;
uint16_t len = uint16_t((pos)/4 -1);
RtpUtility::AssignUWord16ToBuffer(rtcpbuffer + 2, len);
ByteWriter<uint16_t>::WriteBigEndian(rtcpbuffer + 2, len);
return 0;
}
@ -770,8 +772,8 @@ RTCPSender::BuildExtendedJitterReport(
rtcpbuffer[pos++]=(uint8_t)(1);
// Add inter-arrival jitter
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos,
jitterTransmissionTimeOffset);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos,
jitterTransmissionTimeOffset);
pos += 4;
return 0;
}
@ -794,11 +796,11 @@ RTCPSender::BuildPLI(uint8_t* rtcpbuffer, int& pos)
rtcpbuffer[pos++]=(uint8_t)(2);
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// Add the remote SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _remoteSSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _remoteSSRC);
pos += 4;
return 0;
}
@ -824,7 +826,7 @@ int32_t RTCPSender::BuildFIR(uint8_t* rtcpbuffer,
rtcpbuffer[pos++] = (uint8_t)(4);
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// RFC 5104 4.3.1.2. Semantics
@ -835,7 +837,7 @@ int32_t RTCPSender::BuildFIR(uint8_t* rtcpbuffer,
rtcpbuffer[pos++] = (uint8_t)0;
// Additional Feedback Control Information (FCI)
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _remoteSSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _remoteSSRC);
pos += 4;
rtcpbuffer[pos++] = (uint8_t)(_sequenceNumberFIR);
@ -868,18 +870,18 @@ int32_t RTCPSender::BuildSLI(uint8_t* rtcpbuffer, int& pos, uint8_t pictureID) {
rtcpbuffer[pos++]=(uint8_t)(3);
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// Add the remote SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _remoteSSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _remoteSSRC);
pos += 4;
// Add first, number & picture ID 6 bits
// first = 0, 13 - bits
// number = 0x1fff, 13 - bits only ones for now
uint32_t sliField = (0x1fff << 6)+ (0x3f & pictureID);
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, sliField);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, sliField);
pos += 4;
return 0;
}
@ -931,11 +933,11 @@ int32_t RTCPSender::BuildRPSI(uint8_t* rtcpbuffer,
rtcpbuffer[pos++]=size;
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// Add the remote SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _remoteSSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _remoteSSRC);
pos += 4;
// calc padding length
@ -988,11 +990,11 @@ RTCPSender::BuildREMB(uint8_t* rtcpbuffer, int& pos)
rtcpbuffer[pos++]=remb_ssrcs_.size() + 4;
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// Remote SSRC must be 0
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, 0);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, 0);
pos += 4;
rtcpbuffer[pos++]='R';
@ -1019,7 +1021,7 @@ RTCPSender::BuildREMB(uint8_t* rtcpbuffer, int& pos)
for (size_t i = 0; i < remb_ssrcs_.size(); i++)
{
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, remb_ssrcs_[i]);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, remb_ssrcs_[i]);
pos += 4;
}
return 0;
@ -1105,7 +1107,7 @@ int32_t RTCPSender::BuildTMMBR(ModuleRtpRtcpImpl* rtp_rtcp_module,
rtcpbuffer[pos++]=(uint8_t)(4);
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// RFC 5104 4.2.1.2. Semantics
@ -1117,7 +1119,7 @@ int32_t RTCPSender::BuildTMMBR(ModuleRtpRtcpImpl* rtp_rtcp_module,
rtcpbuffer[pos++]=(uint8_t)0;
// Additional Feedback Control Information (FCI)
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _remoteSSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _remoteSSRC);
pos += 4;
uint32_t bitRate = _tmmbr_Send*1000;
@ -1165,7 +1167,7 @@ RTCPSender::BuildTMMBN(uint8_t* rtcpbuffer, int& pos)
pos++;
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// RFC 5104 4.2.2.2. Semantics
@ -1183,7 +1185,7 @@ RTCPSender::BuildTMMBN(uint8_t* rtcpbuffer, int& pos)
if (boundingSet->Tmmbr(n) > 0)
{
uint32_t tmmbrSSRC = boundingSet->Ssrc(n);
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, tmmbrSSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, tmmbrSSRC);
pos += 4;
uint32_t bitRate = boundingSet->Tmmbr(n) * 1000;
@ -1236,11 +1238,11 @@ RTCPSender::BuildAPP(uint8_t* rtcpbuffer, int& pos)
rtcpbuffer[pos++]=(uint8_t)(length);
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// Add our application name
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _appName);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _appName);
pos += 4;
// Add the data
@ -1272,11 +1274,11 @@ int32_t RTCPSender::BuildNACK(uint8_t* rtcpbuffer,
rtcpbuffer[pos++]=(uint8_t)(3); //setting it to one kNACK signal as default
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// Add the remote SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _remoteSSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _remoteSSRC);
pos += 4;
// Build NACK bitmasks and write them to the RTCP message.
@ -1300,9 +1302,9 @@ int32_t RTCPSender::BuildNACK(uint8_t* rtcpbuffer,
}
// Write the sequence number and the bitmask to the packet.
assert(pos + 4 < IP_PACKET_SIZE);
RtpUtility::AssignUWord16ToBuffer(rtcpbuffer + pos, nack);
ByteWriter<uint16_t>::WriteBigEndian(rtcpbuffer + pos, nack);
pos += 2;
RtpUtility::AssignUWord16ToBuffer(rtcpbuffer + pos, bitmask);
ByteWriter<uint16_t>::WriteBigEndian(rtcpbuffer + pos, bitmask);
pos += 2;
numOfNackFields++;
}
@ -1340,12 +1342,12 @@ int32_t RTCPSender::BuildBYE(uint8_t* rtcpbuffer, int& pos) {
rtcpbuffer[pos++] = (uint8_t)(1 + csrcs_.size());
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// add CSRCs
for (size_t i = 0; i < csrcs_.size(); i++) {
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, csrcs_[i]);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, csrcs_[i]);
pos += 4;
}
@ -1375,7 +1377,7 @@ int32_t RTCPSender::BuildReceiverReferenceTime(uint8_t* buffer,
buffer[pos++] = 4; // XR packet length.
// Add our own SSRC.
RtpUtility::AssignUWord32ToBuffer(buffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(buffer + pos, _SSRC);
pos += 4;
// 0 1 2 3
@ -1395,9 +1397,9 @@ int32_t RTCPSender::BuildReceiverReferenceTime(uint8_t* buffer,
buffer[pos++] = 2; // Block length.
// NTP timestamp.
RtpUtility::AssignUWord32ToBuffer(buffer + pos, ntp_sec);
ByteWriter<uint32_t>::WriteBigEndian(buffer + pos, ntp_sec);
pos += 4;
RtpUtility::AssignUWord32ToBuffer(buffer + pos, ntp_frac);
ByteWriter<uint32_t>::WriteBigEndian(buffer + pos, ntp_frac);
pos += 4;
return 0;
@ -1418,7 +1420,7 @@ int32_t RTCPSender::BuildDlrr(uint8_t* buffer,
buffer[pos++] = 5; // XR packet length.
// Add our own SSRC.
RtpUtility::AssignUWord32ToBuffer(buffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(buffer + pos, _SSRC);
pos += 4;
// 0 1 2 3
@ -1443,11 +1445,11 @@ int32_t RTCPSender::BuildDlrr(uint8_t* buffer,
buffer[pos++] = 3; // Block length.
// NTP timestamp.
RtpUtility::AssignUWord32ToBuffer(buffer + pos, info.sourceSSRC);
ByteWriter<uint32_t>::WriteBigEndian(buffer + pos, info.sourceSSRC);
pos += 4;
RtpUtility::AssignUWord32ToBuffer(buffer + pos, info.lastRR);
ByteWriter<uint32_t>::WriteBigEndian(buffer + pos, info.lastRR);
pos += 4;
RtpUtility::AssignUWord32ToBuffer(buffer + pos, info.delaySinceLastRR);
ByteWriter<uint32_t>::WriteBigEndian(buffer + pos, info.delaySinceLastRR);
pos += 4;
return 0;
@ -1473,7 +1475,7 @@ RTCPSender::BuildVoIPMetric(uint8_t* rtcpbuffer, int& pos)
pos++;
// Add our own SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _SSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _SSRC);
pos += 4;
// Add a VoIP metrics block
@ -1483,7 +1485,7 @@ RTCPSender::BuildVoIPMetric(uint8_t* rtcpbuffer, int& pos)
rtcpbuffer[pos++]=8;
// Add the remote SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + pos, _remoteSSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + pos, _remoteSSRC);
pos += 4;
rtcpbuffer[pos++] = _xrVoIPMetric.lossRate;
@ -2034,33 +2036,33 @@ int32_t RTCPSender::WriteReportBlocksToBuffer(
RTCPReportBlock* reportBlock = it->second;
if (reportBlock) {
// Remote SSRC
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + position, remoteSSRC);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + position, remoteSSRC);
position += 4;
// fraction lost
rtcpbuffer[position++] = reportBlock->fractionLost;
// cumulative loss
RtpUtility::AssignUWord24ToBuffer(rtcpbuffer + position,
reportBlock->cumulativeLost);
ByteWriter<uint32_t, 3>::WriteBigEndian(rtcpbuffer + position,
reportBlock->cumulativeLost);
position += 3;
// extended highest seq_no, contain the highest sequence number received
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + position,
reportBlock->extendedHighSeqNum);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + position,
reportBlock->extendedHighSeqNum);
position += 4;
// Jitter
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + position,
reportBlock->jitter);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + position,
reportBlock->jitter);
position += 4;
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + position,
reportBlock->lastSR);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + position,
reportBlock->lastSR);
position += 4;
RtpUtility::AssignUWord32ToBuffer(rtcpbuffer + position,
reportBlock->delaySinceLastSR);
ByteWriter<uint32_t>::WriteBigEndian(rtcpbuffer + position,
reportBlock->delaySinceLastSR);
position += 4;
}
}

View File

@ -11,8 +11,8 @@
#include <list>
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
using webrtc::ForwardErrorCorrection;
@ -866,7 +866,7 @@ void RtpFecTest::ReceivedPackets(const PacketList& packet_list, int* loss_mask,
// For media packets, the sequence number and marker bit is
// obtained from RTP header. These were set in ConstructMediaPackets().
received_packet->seq_num =
webrtc::RtpUtility::BufferToUWord16(&packet->data[2]);
webrtc::ByteReader<uint16_t>::ReadBigEndian(&packet->data[2]);
} else {
// The sequence number, marker bit, and ssrc number are defined in the
// RTP header of the FEC packet, which is not constructed in this test.
@ -921,11 +921,11 @@ int RtpFecTest::ConstructMediaPacketsSeqNum(int num_media_packets,
// Only push one (fake) frame to the FEC.
media_packet->data[1] &= 0x7f;
webrtc::RtpUtility::AssignUWord16ToBuffer(&media_packet->data[2],
sequence_number);
webrtc::RtpUtility::AssignUWord32ToBuffer(&media_packet->data[4],
time_stamp);
webrtc::RtpUtility::AssignUWord32ToBuffer(&media_packet->data[8], ssrc_);
webrtc::ByteWriter<uint16_t>::WriteBigEndian(&media_packet->data[2],
sequence_number);
webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[4],
time_stamp);
webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[8], ssrc_);
// Generate random values for payload.
for (size_t j = 12; j < media_packet->length; ++j) {

View File

@ -11,8 +11,8 @@
#include <string.h>
#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_format_h264.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
namespace webrtc {
namespace {
@ -240,7 +240,7 @@ void RtpPacketizerH264::NextAggregatePacket(uint8_t* buffer,
*bytes_to_send += kNalHeaderSize;
while (packet.aggregated) {
// Add NAL unit length field.
RtpUtility::AssignUWord16ToBuffer(&buffer[index], packet.size);
ByteWriter<uint16_t>::WriteBigEndian(&buffer[index], packet.size);
index += kLengthFieldSize;
*bytes_to_send += kLengthFieldSize;
// Add NAL unit.

View File

@ -10,6 +10,7 @@
#include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/system_wrappers/interface/logging.h"
namespace webrtc {
@ -260,9 +261,9 @@ bool RTPPayloadRegistry::RestoreOriginalPacket(uint8_t** restored_packet,
*packet_length -= kRtxHeaderSize;
// Replace the SSRC and the sequence number with the originals.
RtpUtility::AssignUWord16ToBuffer(*restored_packet + 2,
original_sequence_number);
RtpUtility::AssignUWord32ToBuffer(*restored_packet + 8, original_ssrc);
ByteWriter<uint16_t>::WriteBigEndian(*restored_packet + 2,
original_sequence_number);
ByteWriter<uint32_t>::WriteBigEndian(*restored_packet + 8, original_ssrc);
CriticalSectionScoped cs(crit_sect_.get());

View File

@ -13,6 +13,7 @@
#include <stdlib.h> // srand
#include "webrtc/modules/rtp_rtcp/interface/rtp_cvo.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
@ -1109,15 +1110,15 @@ size_t RTPSender::CreateRtpHeader(uint8_t* header,
if (marker_bit) {
header[1] |= kRtpMarkerBitMask; // Marker bit is set.
}
RtpUtility::AssignUWord16ToBuffer(header + 2, sequence_number);
RtpUtility::AssignUWord32ToBuffer(header + 4, timestamp);
RtpUtility::AssignUWord32ToBuffer(header + 8, ssrc);
ByteWriter<uint16_t>::WriteBigEndian(header + 2, sequence_number);
ByteWriter<uint32_t>::WriteBigEndian(header + 4, timestamp);
ByteWriter<uint32_t>::WriteBigEndian(header + 8, ssrc);
int32_t rtp_header_length = kRtpHeaderLength;
if (csrcs.size() > 0) {
uint8_t *ptr = &header[rtp_header_length];
for (size_t i = 0; i < csrcs.size(); ++i) {
RtpUtility::AssignUWord32ToBuffer(ptr, csrcs[i]);
ByteWriter<uint32_t>::WriteBigEndian(ptr, csrcs[i]);
ptr += 4;
}
header[0] = (header[0] & 0xf0) | csrcs.size();
@ -1179,7 +1180,8 @@ uint16_t RTPSender::BuildRTPHeaderExtension(uint8_t* data_buffer,
const uint32_t kHeaderLength = kRtpOneByteHeaderLength;
// Add extension ID (0xBEDE).
RtpUtility::AssignUWord16ToBuffer(data_buffer, kRtpOneByteHeaderExtensionId);
ByteWriter<uint16_t>::WriteBigEndian(data_buffer,
kRtpOneByteHeaderExtensionId);
// Add extensions.
uint16_t total_block_length = 0;
@ -1223,8 +1225,8 @@ uint16_t RTPSender::BuildRTPHeaderExtension(uint8_t* data_buffer,
total_block_length += padding_bytes;
}
// Set header length (in number of Word32, header excluded).
RtpUtility::AssignUWord16ToBuffer(data_buffer + kPosLength,
total_block_length / 4);
ByteWriter<uint16_t>::WriteBigEndian(data_buffer + kPosLength,
total_block_length / 4);
// Total added length.
return kHeaderLength + total_block_length;
}
@ -1258,8 +1260,8 @@ uint8_t RTPSender::BuildTransmissionTimeOffsetExtension(
size_t pos = 0;
const uint8_t len = 2;
data_buffer[pos++] = (id << 4) + len;
RtpUtility::AssignUWord24ToBuffer(data_buffer + pos,
transmission_time_offset_);
ByteWriter<int32_t, 3>::WriteBigEndian(data_buffer + pos,
transmission_time_offset_);
pos += 3;
assert(pos == kTransmissionTimeOffsetLength);
return kTransmissionTimeOffsetLength;
@ -1320,7 +1322,8 @@ uint8_t RTPSender::BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const {
size_t pos = 0;
const uint8_t len = 2;
data_buffer[pos++] = (id << 4) + len;
RtpUtility::AssignUWord24ToBuffer(data_buffer + pos, absolute_send_time_);
ByteWriter<uint32_t, 3>::WriteBigEndian(data_buffer + pos,
absolute_send_time_);
pos += 3;
assert(pos == kAbsoluteSendTimeLength);
return kAbsoluteSendTimeLength;
@ -1372,8 +1375,8 @@ uint8_t RTPSender::BuildTransportSequenceNumberExtension(
size_t pos = 0;
const uint8_t len = 1;
data_buffer[pos++] = (id << 4) + len;
RtpUtility::AssignUWord16ToBuffer(data_buffer + pos,
transport_sequence_number_);
ByteWriter<uint16_t>::WriteBigEndian(data_buffer + pos,
transport_sequence_number_);
pos += 2;
assert(pos == kTransportSequenceNumberLength);
return kTransportSequenceNumberLength;
@ -1444,8 +1447,8 @@ void RTPSender::UpdateTransmissionTimeOffset(uint8_t* rtp_packet,
return;
}
// Update transmission offset field (converting to a 90 kHz timestamp).
RtpUtility::AssignUWord24ToBuffer(rtp_packet + block_pos + 1,
time_diff_ms * 90); // RTP timestamp.
ByteWriter<int32_t, 3>::WriteBigEndian(rtp_packet + block_pos + 1,
time_diff_ms * 90); // RTP timestamp.
}
bool RTPSender::UpdateAudioLevel(uint8_t* rtp_packet,
@ -1560,8 +1563,8 @@ void RTPSender::UpdateAbsoluteSendTime(uint8_t* rtp_packet,
}
// Update absolute send time field (convert ms to 24-bit unsigned with 18 bit
// fractional part).
RtpUtility::AssignUWord24ToBuffer(rtp_packet + block_pos + 1,
((now_ms << 18) / 1000) & 0x00ffffff);
ByteWriter<uint32_t, 3>::WriteBigEndian(rtp_packet + block_pos + 1,
((now_ms << 18) / 1000) & 0x00ffffff);
}
void RTPSender::SetSendingStatus(bool enabled) {
@ -1786,15 +1789,15 @@ void RTPSender::BuildRtxPacket(uint8_t* buffer, size_t* length,
// Replace sequence number.
uint8_t *ptr = data_buffer_rtx + 2;
RtpUtility::AssignUWord16ToBuffer(ptr, sequence_number_rtx_++);
ByteWriter<uint16_t>::WriteBigEndian(ptr, sequence_number_rtx_++);
// Replace SSRC.
ptr += 6;
RtpUtility::AssignUWord32ToBuffer(ptr, ssrc_rtx_);
ByteWriter<uint32_t>::WriteBigEndian(ptr, ssrc_rtx_);
// Add OSN (original sequence number).
ptr = data_buffer_rtx + rtp_header.headerLength;
RtpUtility::AssignUWord16ToBuffer(ptr, rtp_header.sequenceNumber);
ByteWriter<uint16_t>::WriteBigEndian(ptr, rtp_header.sequenceNumber);
ptr += 2;
// Add original payload data.

View File

@ -13,6 +13,7 @@
#include <assert.h> //assert
#include <string.h> //memcpy
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/system_wrappers/interface/trace_event.h"
namespace webrtc {
@ -313,8 +314,8 @@ int32_t RTPSenderAudio::SendAudio(
return -1;
}
uint32_t REDheader = (timestampOffset << 10) + blockLength;
RtpUtility::AssignUWord24ToBuffer(dataBuffer + rtpHeaderLength,
REDheader);
ByteWriter<uint32_t>::WriteBigEndian(dataBuffer + rtpHeaderLength,
REDheader);
rtpHeaderLength += 3;
dataBuffer[rtpHeaderLength++] = fragmentation->fragmentationPlType[0];
@ -471,7 +472,7 @@ RTPSenderAudio::SendTelephoneEventPacket(bool ended,
// First byte is Event number, equals key number
dtmfbuffer[12] = _dtmfKey;
dtmfbuffer[13] = E|R|volume;
RtpUtility::AssignUWord16ToBuffer(dtmfbuffer + 14, duration);
ByteWriter<uint16_t>::WriteBigEndian(dtmfbuffer + 14, duration);
TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"),
"Audio::SendTelephoneEvent", "timestamp",

View File

@ -15,10 +15,10 @@
#include <string.h>
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/rtp_rtcp/source/producer_fec.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_format_vp8.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/logging.h"
#include "webrtc/system_wrappers/interface/trace_event.h"
@ -195,7 +195,7 @@ int32_t RTPSenderVideo::SendRTPIntraRequest() {
data[2] = 0;
data[3] = 1; // length
RtpUtility::AssignUWord32ToBuffer(data + 4, _rtpSender.SSRC());
ByteWriter<uint32_t>::WriteBigEndian(data + 4, _rtpSender.SSRC());
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"),
"Video::IntraRequest", "seqnum",

View File

@ -29,6 +29,7 @@
#include <stdio.h>
#endif
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/system_wrappers/interface/tick_util.h"
#include "webrtc/system_wrappers/interface/logging.h"
@ -125,65 +126,6 @@ bool StringCompare(const char* str1, const char* str2,
}
#endif
/* for RTP/RTCP
All integer fields are carried in network byte order, that is, most
significant byte (octet) first. AKA big-endian.
*/
void AssignUWord32ToBuffer(uint8_t* dataBuffer, uint32_t value) {
#if defined(WEBRTC_ARCH_LITTLE_ENDIAN)
dataBuffer[0] = static_cast<uint8_t>(value >> 24);
dataBuffer[1] = static_cast<uint8_t>(value >> 16);
dataBuffer[2] = static_cast<uint8_t>(value >> 8);
dataBuffer[3] = static_cast<uint8_t>(value);
#else
uint32_t* ptr = reinterpret_cast<uint32_t*>(dataBuffer);
ptr[0] = value;
#endif
}
void AssignUWord24ToBuffer(uint8_t* dataBuffer, uint32_t value) {
#if defined(WEBRTC_ARCH_LITTLE_ENDIAN)
dataBuffer[0] = static_cast<uint8_t>(value >> 16);
dataBuffer[1] = static_cast<uint8_t>(value >> 8);
dataBuffer[2] = static_cast<uint8_t>(value);
#else
dataBuffer[0] = static_cast<uint8_t>(value);
dataBuffer[1] = static_cast<uint8_t>(value >> 8);
dataBuffer[2] = static_cast<uint8_t>(value >> 16);
#endif
}
void AssignUWord16ToBuffer(uint8_t* dataBuffer, uint16_t value) {
#if defined(WEBRTC_ARCH_LITTLE_ENDIAN)
dataBuffer[0] = static_cast<uint8_t>(value >> 8);
dataBuffer[1] = static_cast<uint8_t>(value);
#else
uint16_t* ptr = reinterpret_cast<uint16_t*>(dataBuffer);
ptr[0] = value;
#endif
}
uint16_t BufferToUWord16(const uint8_t* dataBuffer) {
#if defined(WEBRTC_ARCH_LITTLE_ENDIAN)
return (dataBuffer[0] << 8) + dataBuffer[1];
#else
return *reinterpret_cast<const uint16_t*>(dataBuffer);
#endif
}
uint32_t BufferToUWord24(const uint8_t* dataBuffer) {
return (dataBuffer[0] << 16) + (dataBuffer[1] << 8) + dataBuffer[2];
}
uint32_t BufferToUWord32(const uint8_t* dataBuffer) {
#if defined(WEBRTC_ARCH_LITTLE_ENDIAN)
return (dataBuffer[0] << 24) + (dataBuffer[1] << 16) + (dataBuffer[2] << 8) +
dataBuffer[3];
#else
return *reinterpret_cast<const uint32_t*>(dataBuffer);
#endif
}
size_t Word32Align(size_t size) {
uint32_t remainder = size % 4;
if (remainder != 0)
@ -294,10 +236,8 @@ bool RtpHeaderParser::ParseRtcp(RTPHeader* header) const {
const size_t len = (_ptrRTPDataBegin[2] << 8) + _ptrRTPDataBegin[3];
const uint8_t* ptr = &_ptrRTPDataBegin[4];
uint32_t SSRC = *ptr++ << 24;
SSRC += *ptr++ << 16;
SSRC += *ptr++ << 8;
SSRC += *ptr++;
uint32_t SSRC = ByteReader<uint32_t>::ReadBigEndian(ptr);
ptr += 4;
header->payloadType = PT;
header->ssrc = SSRC;
@ -329,15 +269,11 @@ bool RtpHeaderParser::Parse(RTPHeader& header,
const uint8_t* ptr = &_ptrRTPDataBegin[4];
uint32_t RTPTimestamp = *ptr++ << 24;
RTPTimestamp += *ptr++ << 16;
RTPTimestamp += *ptr++ << 8;
RTPTimestamp += *ptr++;
uint32_t RTPTimestamp = ByteReader<uint32_t>::ReadBigEndian(ptr);
ptr += 4;
uint32_t SSRC = *ptr++ << 24;
SSRC += *ptr++ << 16;
SSRC += *ptr++ << 8;
SSRC += *ptr++;
uint32_t SSRC = ByteReader<uint32_t>::ReadBigEndian(ptr);
ptr += 4;
if (V != kRtpExpectedVersion) {
return false;
@ -358,10 +294,8 @@ bool RtpHeaderParser::Parse(RTPHeader& header,
header.paddingLength = P ? *(_ptrRTPDataEnd - 1) : 0;
for (uint8_t i = 0; i < CC; ++i) {
uint32_t CSRC = *ptr++ << 24;
CSRC += *ptr++ << 16;
CSRC += *ptr++ << 8;
CSRC += *ptr++;
uint32_t CSRC = ByteReader<uint32_t>::ReadBigEndian(ptr);
ptr += 4;
header.arrOfCSRCs[i] = CSRC;
}
@ -401,12 +335,13 @@ bool RtpHeaderParser::Parse(RTPHeader& header,
header.headerLength += 4;
uint16_t definedByProfile = *ptr++ << 8;
definedByProfile += *ptr++;
uint16_t definedByProfile = ByteReader<uint16_t>::ReadBigEndian(ptr);
ptr += 2;
size_t XLen = *ptr++ << 8;
XLen += *ptr++; // in 32 bit words
XLen *= 4; // in octs
// in 32 bit words
size_t XLen = ByteReader<uint16_t>::ReadBigEndian(ptr);
ptr += 2;
XLen *= 4; // in bytes
if (static_cast<size_t>(remain) < (4 + XLen)) {
return false;
@ -470,15 +405,8 @@ void RtpHeaderParser::ParseOneByteExtensionHeader(
// | ID | len=2 | transmission offset |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
int32_t transmissionTimeOffset = ptr[0] << 16;
transmissionTimeOffset += ptr[1] << 8;
transmissionTimeOffset += ptr[2];
header.extension.transmissionTimeOffset =
transmissionTimeOffset;
if (transmissionTimeOffset & 0x800000) {
// Negative offset, correct sign for Word24 to Word32.
header.extension.transmissionTimeOffset |= 0xFF000000;
}
ByteReader<int32_t, 3>::ReadBigEndian(ptr);
header.extension.hasTransmissionTimeOffset = true;
break;
}
@ -515,10 +443,8 @@ void RtpHeaderParser::ParseOneByteExtensionHeader(
// | ID | len=2 | absolute send time |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
uint32_t absoluteSendTime = ptr[0] << 16;
absoluteSendTime += ptr[1] << 8;
absoluteSendTime += ptr[2];
header.extension.absoluteSendTime = absoluteSendTime;
header.extension.absoluteSendTime =
ByteReader<uint32_t, 3>::ReadBigEndian(ptr);
header.extension.hasAbsoluteSendTime = true;
break;
}
@ -528,11 +454,11 @@ void RtpHeaderParser::ParseOneByteExtensionHeader(
<< "Incorrect coordination of video coordination len: " << len;
return;
}
// 0 1
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | ID | len=0 |0 0 0 0 C F R R|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// 0 1
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | ID | len=0 |0 0 0 0 C F R R|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
header.extension.hasVideoRotation = true;
header.extension.videoRotation = ptr[0];
break;

View File

@ -66,31 +66,6 @@ namespace RtpUtility {
const char* str2,
const uint32_t length);
void AssignUWord32ToBuffer(uint8_t* dataBuffer, uint32_t value);
void AssignUWord24ToBuffer(uint8_t* dataBuffer, uint32_t value);
void AssignUWord16ToBuffer(uint8_t* dataBuffer, uint16_t value);
/**
* Converts a network-ordered two-byte input buffer to a host-ordered value.
* \param[in] dataBuffer Network-ordered two-byte buffer to convert.
* \return Host-ordered value.
*/
uint16_t BufferToUWord16(const uint8_t* dataBuffer);
/**
* Converts a network-ordered three-byte input buffer to a host-ordered value.
* \param[in] dataBuffer Network-ordered three-byte buffer to convert.
* \return Host-ordered value.
*/
uint32_t BufferToUWord24(const uint8_t* dataBuffer);
/**
* Converts a network-ordered four-byte input buffer to a host-ordered value.
* \param[in] dataBuffer Network-ordered four-byte buffer to convert.
* \return Host-ordered value.
*/
uint32_t BufferToUWord32(const uint8_t* dataBuffer);
// Round up to the nearest size that is a multiple of 4.
size_t Word32Align(size_t size);

View File

@ -18,8 +18,8 @@
#include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
#include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h"
namespace {
@ -89,9 +89,9 @@ class RtpRtcpVideoTest : public ::testing::Test {
uint32_t sequence_number) {
dataBuffer[0] = static_cast<uint8_t>(0x80); // version 2
dataBuffer[1] = static_cast<uint8_t>(kPayloadType);
RtpUtility::AssignUWord16ToBuffer(dataBuffer + 2, sequence_number);
RtpUtility::AssignUWord32ToBuffer(dataBuffer + 4, timestamp);
RtpUtility::AssignUWord32ToBuffer(dataBuffer + 8, 0x1234); // SSRC.
ByteWriter<uint16_t>::WriteBigEndian(dataBuffer + 2, sequence_number);
ByteWriter<uint32_t>::WriteBigEndian(dataBuffer + 4, timestamp);
ByteWriter<uint32_t>::WriteBigEndian(dataBuffer + 8, 0x1234); // SSRC.
size_t rtpHeaderLength = 12;
return rtpHeaderLength;
}

View File

@ -26,7 +26,7 @@
#include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h"
#include "webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/test/testsupport/fileutils.h"
//#define VERBOSE_OUTPUT
@ -259,10 +259,11 @@ TEST(FecTest, FecTest) {
// Only push one (fake) frame to the FEC.
mediaPacket->data[1] &= 0x7f;
RtpUtility::AssignUWord16ToBuffer(&mediaPacket->data[2], seqNum);
RtpUtility::AssignUWord32ToBuffer(&mediaPacket->data[4],
timeStamp);
RtpUtility::AssignUWord32ToBuffer(&mediaPacket->data[8], ssrc);
ByteWriter<uint16_t>::WriteBigEndian(&mediaPacket->data[2],
seqNum);
ByteWriter<uint32_t>::WriteBigEndian(&mediaPacket->data[4],
timeStamp);
ByteWriter<uint32_t>::WriteBigEndian(&mediaPacket->data[8], ssrc);
// Generate random values for payload
for (size_t j = 12; j < mediaPacket->length; ++j) {
mediaPacket->data[j] = static_cast<uint8_t>(rand() % 256);
@ -301,7 +302,7 @@ TEST(FecTest, FecTest) {
memcpy(receivedPacket->pkt->data, mediaPacket->data,
mediaPacket->length);
receivedPacket->seq_num =
RtpUtility::BufferToUWord16(&mediaPacket->data[2]);
ByteReader<uint16_t>::ReadBigEndian(&mediaPacket->data[2]);
receivedPacket->is_fec = false;
}
mediaPacketIdx++;