OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/base/checks.h" | 11 #include "webrtc/base/checks.h" |
12 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" | 12 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
13 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" | 13 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
15 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h" | 15 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h" |
16 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 16 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
17 #include "webrtc/test/layer_filtering_transport.h" | 17 #include "webrtc/test/layer_filtering_transport.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 namespace test { | 20 namespace test { |
21 | 21 |
22 LayerFilteringTransport::LayerFilteringTransport( | 22 LayerFilteringTransport::LayerFilteringTransport( |
23 const FakeNetworkPipe::Config& config, | 23 const FakeNetworkPipe::Config& config, |
24 uint8_t vp8_video_payload_type, | 24 uint8_t vp8_video_payload_type, |
25 uint8_t vp9_video_payload_type, | 25 uint8_t vp9_video_payload_type, |
26 uint8_t tl_discard_threshold, | 26 int selected_tl, |
27 uint8_t sl_discard_threshold) | 27 int selected_sl) |
28 : test::DirectTransport(config), | 28 : test::DirectTransport(config), |
29 vp8_video_payload_type_(vp8_video_payload_type), | 29 vp8_video_payload_type_(vp8_video_payload_type), |
30 vp9_video_payload_type_(vp9_video_payload_type), | 30 vp9_video_payload_type_(vp9_video_payload_type), |
31 tl_discard_threshold_(tl_discard_threshold), | 31 selected_tl_(selected_tl), |
32 sl_discard_threshold_(sl_discard_threshold), | 32 selected_sl_(selected_sl), |
33 current_seq_num_(10000) { | 33 discarded_last_packet_(false) { |
34 } // TODO(ivica): random seq num? | 34 } |
| 35 |
| 36 bool LayerFilteringTransport::DiscardedLastPacket() const { |
| 37 return discarded_last_packet_; |
| 38 } |
| 39 |
| 40 uint16_t LayerFilteringTransport::NextSequenceNumber(uint32_t ssrc) { |
| 41 auto it = current_seq_nums_.find(ssrc); |
| 42 if (it == current_seq_nums_.end()) |
| 43 return current_seq_nums_[ssrc] = 10000; |
| 44 else |
| 45 return ++it->second; |
| 46 } |
35 | 47 |
36 bool LayerFilteringTransport::SendRtp(const uint8_t* packet, | 48 bool LayerFilteringTransport::SendRtp(const uint8_t* packet, |
37 size_t length, | 49 size_t length, |
38 const PacketOptions& options) { | 50 const PacketOptions& options) { |
39 if (tl_discard_threshold_ == 0 && sl_discard_threshold_ == 0) { | 51 if (selected_tl_ == -1 && selected_sl_ == -1) { |
40 // Nothing to change, forward the packet immediately. | 52 // Nothing to change, forward the packet immediately. |
41 return test::DirectTransport::SendRtp(packet, length, options); | 53 return test::DirectTransport::SendRtp(packet, length, options); |
42 } | 54 } |
43 | 55 |
44 bool set_marker_bit = false; | 56 bool set_marker_bit = false; |
45 rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create()); | 57 rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create()); |
46 RTPHeader header; | 58 RTPHeader header; |
47 parser->Parse(packet, length, &header); | 59 parser->Parse(packet, length, &header); |
48 | 60 |
49 if (header.payloadType == vp8_video_payload_type_ || | 61 if (header.payloadType == vp8_video_payload_type_ || |
50 header.payloadType == vp9_video_payload_type_) { | 62 header.payloadType == vp9_video_payload_type_) { |
51 const uint8_t* payload = packet + header.headerLength; | 63 const uint8_t* payload = packet + header.headerLength; |
52 RTC_DCHECK_GT(length, header.headerLength); | 64 RTC_DCHECK_GT(length, header.headerLength); |
53 const size_t payload_length = length - header.headerLength; | 65 const size_t payload_length = length - header.headerLength; |
54 RTC_DCHECK_GT(payload_length, header.paddingLength); | 66 RTC_DCHECK_GT(payload_length, header.paddingLength); |
55 const size_t payload_data_length = payload_length - header.paddingLength; | 67 const size_t payload_data_length = payload_length - header.paddingLength; |
56 | 68 |
57 const bool is_vp8 = header.payloadType == vp8_video_payload_type_; | 69 const bool is_vp8 = header.payloadType == vp8_video_payload_type_; |
58 rtc::scoped_ptr<RtpDepacketizer> depacketizer( | 70 rtc::scoped_ptr<RtpDepacketizer> depacketizer( |
59 RtpDepacketizer::Create(is_vp8 ? kRtpVideoVp8 : kRtpVideoVp9)); | 71 RtpDepacketizer::Create(is_vp8 ? kRtpVideoVp8 : kRtpVideoVp9)); |
60 RtpDepacketizer::ParsedPayload parsed_payload; | 72 RtpDepacketizer::ParsedPayload parsed_payload; |
61 if (depacketizer->Parse(&parsed_payload, payload, payload_data_length)) { | 73 if (depacketizer->Parse(&parsed_payload, payload, payload_data_length)) { |
62 const uint8_t temporalIdx = | 74 const int temporal_idx = static_cast<int>( |
63 is_vp8 ? parsed_payload.type.Video.codecHeader.VP8.temporalIdx | 75 is_vp8 ? parsed_payload.type.Video.codecHeader.VP8.temporalIdx |
64 : parsed_payload.type.Video.codecHeader.VP9.temporal_idx; | 76 : parsed_payload.type.Video.codecHeader.VP9.temporal_idx); |
65 const uint8_t spatialIdx = | 77 const int spatial_idx = static_cast<int>( |
66 is_vp8 ? kNoSpatialIdx | 78 is_vp8 ? kNoSpatialIdx |
67 : parsed_payload.type.Video.codecHeader.VP9.spatial_idx; | 79 : parsed_payload.type.Video.codecHeader.VP9.spatial_idx); |
68 if (sl_discard_threshold_ > 0 && | 80 if (selected_sl_ >= 0 && |
69 spatialIdx == sl_discard_threshold_ - 1 && | 81 spatial_idx == selected_sl_ && |
70 parsed_payload.type.Video.codecHeader.VP9.end_of_frame) { | 82 parsed_payload.type.Video.codecHeader.VP9.end_of_frame) { |
71 // This layer is now the last in the superframe. | 83 // This layer is now the last in the superframe. |
72 set_marker_bit = true; | 84 set_marker_bit = true; |
73 } | 85 } |
74 if ((tl_discard_threshold_ > 0 && temporalIdx != kNoTemporalIdx && | 86 if ((selected_tl_ >= 0 && temporal_idx != kNoTemporalIdx && |
75 temporalIdx >= tl_discard_threshold_) || | 87 temporal_idx > selected_tl_) || |
76 (sl_discard_threshold_ > 0 && spatialIdx != kNoSpatialIdx && | 88 (selected_sl_ >= 0 && spatial_idx != kNoSpatialIdx && |
77 spatialIdx >= sl_discard_threshold_)) { | 89 spatial_idx > selected_sl_)) { |
78 return true; // Discard the packet. | 90 discarded_last_packet_ = true; |
| 91 return true; |
79 } | 92 } |
80 } else { | 93 } else { |
81 RTC_NOTREACHED() << "Parse error"; | 94 RTC_NOTREACHED() << "Parse error"; |
82 } | 95 } |
83 } | 96 } |
84 | 97 |
85 uint8_t temp_buffer[IP_PACKET_SIZE]; | 98 uint8_t temp_buffer[IP_PACKET_SIZE]; |
86 memcpy(temp_buffer, packet, length); | 99 memcpy(temp_buffer, packet, length); |
87 | 100 |
88 // We are discarding some of the packets (specifically, whole layers), so | 101 // We are discarding some of the packets (specifically, whole layers), so |
89 // make sure the marker bit is set properly, and that sequence numbers are | 102 // make sure the marker bit is set properly, and that sequence numbers are |
90 // continuous. | 103 // continuous. |
91 if (set_marker_bit) { | 104 if (set_marker_bit) { |
92 temp_buffer[1] |= kRtpMarkerBitMask; | 105 temp_buffer[1] |= kRtpMarkerBitMask; |
93 } | 106 } |
94 ByteWriter<uint16_t>::WriteBigEndian(&temp_buffer[2], current_seq_num_); | |
95 | 107 |
96 ++current_seq_num_; // Increase only if packet not discarded. | 108 uint16_t seq_num = NextSequenceNumber(header.ssrc); |
97 | 109 ByteWriter<uint16_t>::WriteBigEndian(&temp_buffer[2], seq_num); |
98 return test::DirectTransport::SendRtp(temp_buffer, length, options); | 110 return test::DirectTransport::SendRtp(temp_buffer, length, options); |
99 } | 111 } |
100 | 112 |
101 } // namespace test | 113 } // namespace test |
102 } // namespace webrtc | 114 } // namespace webrtc |
OLD | NEW |