Index: webrtc/test/layer_filtering_transport.cc |
diff --git a/webrtc/test/layer_filtering_transport.cc b/webrtc/test/layer_filtering_transport.cc |
index a4ebf47f93ae559e024b5981814f38941977934b..5533a4cd468df63e4a89e93684305c829a1bb12a 100644 |
--- a/webrtc/test/layer_filtering_transport.cc |
+++ b/webrtc/test/layer_filtering_transport.cc |
@@ -9,9 +9,7 @@ |
*/ |
#include "webrtc/base/checks.h" |
-#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.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_format.h" |
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
#include "webrtc/test/layer_filtering_transport.h" |
@@ -24,33 +22,35 @@ LayerFilteringTransport::LayerFilteringTransport( |
Call* send_call, |
uint8_t vp8_video_payload_type, |
uint8_t vp9_video_payload_type, |
- uint8_t tl_discard_threshold, |
- uint8_t sl_discard_threshold) |
+ int selected_tl, |
+ int selected_sl) |
: test::DirectTransport(config, send_call), |
vp8_video_payload_type_(vp8_video_payload_type), |
vp9_video_payload_type_(vp9_video_payload_type), |
- tl_discard_threshold_(tl_discard_threshold), |
- sl_discard_threshold_(sl_discard_threshold) {} |
+ selected_tl_(selected_tl), |
+ selected_sl_(selected_sl), |
+ discarded_last_packet_(false) {} |
-uint16_t LayerFilteringTransport::NextSequenceNumber(uint32_t ssrc) { |
- auto it = current_seq_nums_.find(ssrc); |
- if (it == current_seq_nums_.end()) |
- return current_seq_nums_[ssrc] = 10000; |
- return ++it->second; |
+bool LayerFilteringTransport::DiscardedLastPacket() const { |
+ return discarded_last_packet_; |
} |
bool LayerFilteringTransport::SendRtp(const uint8_t* packet, |
size_t length, |
const PacketOptions& options) { |
- if (tl_discard_threshold_ == 0 && sl_discard_threshold_ == 0) { |
+ if (selected_tl_ == -1 && selected_sl_ == -1) { |
// Nothing to change, forward the packet immediately. |
return test::DirectTransport::SendRtp(packet, length, options); |
} |
bool set_marker_bit = false; |
- rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create()); |
+ RtpUtility::RtpHeaderParser parser(packet, length); |
RTPHeader header; |
- parser->Parse(packet, length, &header); |
+ parser.Parse(header); |
+ |
+ RTC_DCHECK_LE(length, static_cast<size_t>(IP_PACKET_SIZE)); |
+ uint8_t temp_buffer[IP_PACKET_SIZE]; |
+ memcpy(temp_buffer, packet, length); |
if (header.payloadType == vp8_video_payload_type_ || |
header.payloadType == vp9_video_payload_type_) { |
@@ -65,40 +65,38 @@ bool LayerFilteringTransport::SendRtp(const uint8_t* packet, |
RtpDepacketizer::Create(is_vp8 ? kRtpVideoVp8 : kRtpVideoVp9)); |
RtpDepacketizer::ParsedPayload parsed_payload; |
if (depacketizer->Parse(&parsed_payload, payload, payload_data_length)) { |
- const uint8_t temporalIdx = |
+ const int temporal_idx = static_cast<int>( |
is_vp8 ? parsed_payload.type.Video.codecHeader.VP8.temporalIdx |
- : parsed_payload.type.Video.codecHeader.VP9.temporal_idx; |
- const uint8_t spatialIdx = |
+ : parsed_payload.type.Video.codecHeader.VP9.temporal_idx); |
+ const int spatial_idx = static_cast<int>( |
is_vp8 ? kNoSpatialIdx |
- : parsed_payload.type.Video.codecHeader.VP9.spatial_idx; |
- if (sl_discard_threshold_ > 0 && |
- spatialIdx == sl_discard_threshold_ - 1 && |
+ : parsed_payload.type.Video.codecHeader.VP9.spatial_idx); |
+ if (selected_sl_ >= 0 && spatial_idx == selected_sl_ && |
parsed_payload.type.Video.codecHeader.VP9.end_of_frame) { |
// This layer is now the last in the superframe. |
set_marker_bit = true; |
- } |
- if ((tl_discard_threshold_ > 0 && temporalIdx != kNoTemporalIdx && |
- temporalIdx >= tl_discard_threshold_) || |
- (sl_discard_threshold_ > 0 && spatialIdx != kNoSpatialIdx && |
- spatialIdx >= sl_discard_threshold_)) { |
- return true; // Discard the packet. |
+ } else if ((selected_tl_ >= 0 && temporal_idx != kNoTemporalIdx && |
+ temporal_idx > selected_tl_) || |
+ (selected_sl_ >= 0 && spatial_idx != kNoSpatialIdx && |
+ spatial_idx > selected_sl_)) { |
+ // Truncate packet to a padding packet. |
+ length = header.headerLength + 1; |
+ temp_buffer[0] |= (1 << 5); // P = 1. |
+ temp_buffer[1] &= 0x7F; // M = 0. |
+ discarded_last_packet_ = true; |
+ temp_buffer[header.headerLength] = 1; // One byte of padding. |
} |
} else { |
RTC_NOTREACHED() << "Parse error"; |
} |
} |
- uint8_t temp_buffer[IP_PACKET_SIZE]; |
- memcpy(temp_buffer, packet, length); |
- |
// We are discarding some of the packets (specifically, whole layers), so |
// make sure the marker bit is set properly, and that sequence numbers are |
// continuous. |
if (set_marker_bit) |
temp_buffer[1] |= kRtpMarkerBitMask; |
- uint16_t seq_num = NextSequenceNumber(header.ssrc); |
- ByteWriter<uint16_t>::WriteBigEndian(&temp_buffer[2], seq_num); |
return test::DirectTransport::SendRtp(temp_buffer, length, options); |
} |