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) { | |
ivica
2015/09/22 16:21:04
Including the patch https://codereview.webrtc.org/
| |
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, size_t length) { | 48 bool LayerFilteringTransport::SendRtp(const uint8_t* packet, size_t length) { |
37 if (tl_discard_threshold_ == 0 && sl_discard_threshold_ == 0) { | 49 if (selected_tl_ == -1 && selected_sl_ == -1) { |
38 // Nothing to change, forward the packet immediately. | 50 // Nothing to change, forward the packet immediately. |
39 return test::DirectTransport::SendRtp(packet, length); | 51 return test::DirectTransport::SendRtp(packet, length); |
40 } | 52 } |
41 | 53 |
42 bool set_marker_bit = false; | 54 bool set_marker_bit = false; |
43 rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create()); | 55 rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create()); |
44 RTPHeader header; | 56 RTPHeader header; |
45 parser->Parse(packet, length, &header); | 57 parser->Parse(packet, length, &header); |
46 | 58 |
47 if (header.payloadType == vp8_video_payload_type_ || | 59 if (header.payloadType == vp8_video_payload_type_ || |
48 header.payloadType == vp9_video_payload_type_) { | 60 header.payloadType == vp9_video_payload_type_) { |
49 const uint8_t* payload = packet + header.headerLength; | 61 const uint8_t* payload = packet + header.headerLength; |
50 RTC_DCHECK_GT(length, header.headerLength); | 62 RTC_DCHECK_GT(length, header.headerLength); |
51 const size_t payload_length = length - header.headerLength; | 63 const size_t payload_length = length - header.headerLength; |
52 RTC_DCHECK_GT(payload_length, header.paddingLength); | 64 RTC_DCHECK_GT(payload_length, header.paddingLength); |
53 const size_t payload_data_length = payload_length - header.paddingLength; | 65 const size_t payload_data_length = payload_length - header.paddingLength; |
54 | 66 |
55 const bool is_vp8 = header.payloadType == vp8_video_payload_type_; | 67 const bool is_vp8 = header.payloadType == vp8_video_payload_type_; |
56 rtc::scoped_ptr<RtpDepacketizer> depacketizer( | 68 rtc::scoped_ptr<RtpDepacketizer> depacketizer( |
57 RtpDepacketizer::Create(is_vp8 ? kRtpVideoVp8 : kRtpVideoVp9)); | 69 RtpDepacketizer::Create(is_vp8 ? kRtpVideoVp8 : kRtpVideoVp9)); |
58 RtpDepacketizer::ParsedPayload parsed_payload; | 70 RtpDepacketizer::ParsedPayload parsed_payload; |
59 if (depacketizer->Parse(&parsed_payload, payload, payload_data_length)) { | 71 if (depacketizer->Parse(&parsed_payload, payload, payload_data_length)) { |
60 const uint8_t temporalIdx = | 72 const int temporal_idx = static_cast<int>( |
61 is_vp8 ? parsed_payload.type.Video.codecHeader.VP8.temporalIdx | 73 is_vp8 ? parsed_payload.type.Video.codecHeader.VP8.temporalIdx |
62 : parsed_payload.type.Video.codecHeader.VP9.temporal_idx; | 74 : parsed_payload.type.Video.codecHeader.VP9.temporal_idx); |
63 const uint8_t spatialIdx = | 75 const int spatial_idx = static_cast<int>( |
64 is_vp8 ? kNoSpatialIdx | 76 is_vp8 ? kNoSpatialIdx |
65 : parsed_payload.type.Video.codecHeader.VP9.spatial_idx; | 77 : parsed_payload.type.Video.codecHeader.VP9.spatial_idx); |
66 if (sl_discard_threshold_ > 0 && | 78 if (selected_sl_ >= 0 && |
67 spatialIdx == sl_discard_threshold_ - 1 && | 79 spatial_idx == selected_sl_ && |
68 parsed_payload.type.Video.codecHeader.VP9.end_of_frame) { | 80 parsed_payload.type.Video.codecHeader.VP9.end_of_frame) { |
69 // This layer is now the last in the superframe. | 81 // This layer is now the last in the superframe. |
70 set_marker_bit = true; | 82 set_marker_bit = true; |
71 } | 83 } |
72 if ((tl_discard_threshold_ > 0 && temporalIdx != kNoTemporalIdx && | 84 if ((selected_tl_ >= 0 && temporal_idx != kNoTemporalIdx && |
73 temporalIdx >= tl_discard_threshold_) || | 85 temporal_idx > selected_tl_) || |
74 (sl_discard_threshold_ > 0 && spatialIdx != kNoSpatialIdx && | 86 (selected_sl_ >= 0 && spatial_idx != kNoSpatialIdx && |
75 spatialIdx >= sl_discard_threshold_)) { | 87 spatial_idx > selected_sl_)) { |
76 return true; // Discard the packet. | 88 discarded_last_packet_ = true; |
89 return true; | |
77 } | 90 } |
78 } else { | 91 } else { |
79 RTC_NOTREACHED() << "Parse error"; | 92 RTC_NOTREACHED() << "Parse error"; |
80 } | 93 } |
81 } | 94 } |
82 | 95 |
83 uint8_t temp_buffer[IP_PACKET_SIZE]; | 96 uint8_t temp_buffer[IP_PACKET_SIZE]; |
84 memcpy(temp_buffer, packet, length); | 97 memcpy(temp_buffer, packet, length); |
85 | 98 |
86 // We are discarding some of the packets (specifically, whole layers), so | 99 // We are discarding some of the packets (specifically, whole layers), so |
87 // make sure the marker bit is set properly, and that sequence numbers are | 100 // make sure the marker bit is set properly, and that sequence numbers are |
88 // continuous. | 101 // continuous. |
89 if (set_marker_bit) { | 102 if (set_marker_bit) { |
90 temp_buffer[1] |= kRtpMarkerBitMask; | 103 temp_buffer[1] |= kRtpMarkerBitMask; |
91 } | 104 } |
92 ByteWriter<uint16_t>::WriteBigEndian(&temp_buffer[2], current_seq_num_); | |
93 | 105 |
94 ++current_seq_num_; // Increase only if packet not discarded. | 106 uint16_t seq_num = NextSequenceNumber(header.ssrc); |
95 | 107 ByteWriter<uint16_t>::WriteBigEndian(&temp_buffer[2], seq_num); |
96 return test::DirectTransport::SendRtp(temp_buffer, length); | 108 return test::DirectTransport::SendRtp(temp_buffer, length); |
97 } | 109 } |
98 | 110 |
99 } // namespace test | 111 } // namespace test |
100 } // namespace webrtc | 112 } // namespace webrtc |
OLD | NEW |