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