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 <memory> | 11 #include <memory> |
12 | 12 |
13 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 13 #include "webrtc/modules/rtp_rtcp/include/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/rtc_base/checks.h" | 17 #include "webrtc/rtc_base/checks.h" |
18 #include "webrtc/test/layer_filtering_transport.h" | 18 #include "webrtc/test/layer_filtering_transport.h" |
19 #include "webrtc/test/rtp_file_reader.h" | |
ilnik
2017/08/23 08:24:25
Why reader is needed here?
sprang_webrtc
2017/08/23 10:32:05
Oops. Autocomplete. rtp_file_writer was included f
| |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 namespace test { | 22 namespace test { |
22 | 23 |
23 LayerFilteringTransport::LayerFilteringTransport( | 24 LayerFilteringTransport::LayerFilteringTransport( |
24 SingleThreadedTaskQueueForTesting* task_queue, | 25 SingleThreadedTaskQueueForTesting* task_queue, |
25 const FakeNetworkPipe::Config& config, | 26 const FakeNetworkPipe::Config& config, |
26 Call* send_call, | 27 Call* send_call, |
27 uint8_t vp8_video_payload_type, | 28 uint8_t vp8_video_payload_type, |
28 uint8_t vp9_video_payload_type, | 29 uint8_t vp9_video_payload_type, |
29 int selected_tl, | 30 int selected_tl, |
30 int selected_sl, | 31 int selected_sl, |
31 const std::map<uint8_t, MediaType>& payload_type_map) | 32 const std::map<uint8_t, MediaType>& payload_type_map, |
33 std::unique_ptr<test::RtpFileWriter> rtp_file_writer) | |
32 : DirectTransport(task_queue, config, send_call, payload_type_map), | 34 : DirectTransport(task_queue, config, send_call, payload_type_map), |
33 vp8_video_payload_type_(vp8_video_payload_type), | 35 vp8_video_payload_type_(vp8_video_payload_type), |
34 vp9_video_payload_type_(vp9_video_payload_type), | 36 vp9_video_payload_type_(vp9_video_payload_type), |
35 selected_tl_(selected_tl), | 37 selected_tl_(selected_tl), |
36 selected_sl_(selected_sl), | 38 selected_sl_(selected_sl), |
37 discarded_last_packet_(false) {} | 39 discarded_last_packet_(false), |
40 start_ms_(rtc::TimeMillis()), | |
41 rtp_file_writer_(std::move(rtp_file_writer)) {} | |
38 | 42 |
39 bool LayerFilteringTransport::DiscardedLastPacket() const { | 43 bool LayerFilteringTransport::DiscardedLastPacket() const { |
40 return discarded_last_packet_; | 44 return discarded_last_packet_; |
41 } | 45 } |
42 | 46 |
43 bool LayerFilteringTransport::SendRtp(const uint8_t* packet, | 47 bool LayerFilteringTransport::SendRtp(const uint8_t* packet, |
44 size_t length, | 48 size_t length, |
45 const PacketOptions& options) { | 49 const PacketOptions& options) { |
50 RtpPacket rtp_packet; | |
51 RTC_DCHECK_LE(length, IP_PACKET_SIZE); | |
52 memcpy(rtp_packet.data, packet, length); | |
53 rtp_packet.length = length; | |
54 rtp_packet.original_length = length; | |
55 rtp_packet.time_ms = rtc::TimeMillis() - start_ms_; | |
56 | |
46 if (selected_tl_ == -1 && selected_sl_ == -1) { | 57 if (selected_tl_ == -1 && selected_sl_ == -1) { |
47 // Nothing to change, forward the packet immediately. | 58 // Nothing to change, forward the packet immediately. |
59 if (rtp_file_writer_.get()) | |
60 rtp_file_writer_->WritePacket(&rtp_packet); | |
48 return test::DirectTransport::SendRtp(packet, length, options); | 61 return test::DirectTransport::SendRtp(packet, length, options); |
49 } | 62 } |
50 | 63 |
51 bool set_marker_bit = false; | 64 bool set_marker_bit = false; |
52 RtpUtility::RtpHeaderParser parser(packet, length); | 65 RtpUtility::RtpHeaderParser parser(packet, length); |
53 RTPHeader header; | 66 RTPHeader header; |
54 parser.Parse(&header); | 67 parser.Parse(&header); |
55 | 68 |
56 RTC_DCHECK_LE(length, IP_PACKET_SIZE); | |
57 uint8_t temp_buffer[IP_PACKET_SIZE]; | |
58 memcpy(temp_buffer, packet, length); | |
59 | |
60 if (header.payloadType == vp8_video_payload_type_ || | 69 if (header.payloadType == vp8_video_payload_type_ || |
61 header.payloadType == vp9_video_payload_type_) { | 70 header.payloadType == vp9_video_payload_type_) { |
62 const uint8_t* payload = packet + header.headerLength; | 71 const uint8_t* payload = packet + header.headerLength; |
63 RTC_DCHECK_GT(length, header.headerLength); | 72 RTC_DCHECK_GT(length, header.headerLength); |
64 const size_t payload_length = length - header.headerLength; | 73 const size_t payload_length = length - header.headerLength; |
65 RTC_DCHECK_GT(payload_length, header.paddingLength); | 74 RTC_DCHECK_GT(payload_length, header.paddingLength); |
66 const size_t payload_data_length = payload_length - header.paddingLength; | 75 const size_t payload_data_length = payload_length - header.paddingLength; |
67 | 76 |
68 const bool is_vp8 = header.payloadType == vp8_video_payload_type_; | 77 const bool is_vp8 = header.payloadType == vp8_video_payload_type_; |
69 std::unique_ptr<RtpDepacketizer> depacketizer( | 78 std::unique_ptr<RtpDepacketizer> depacketizer( |
70 RtpDepacketizer::Create(is_vp8 ? kRtpVideoVp8 : kRtpVideoVp9)); | 79 RtpDepacketizer::Create(is_vp8 ? kRtpVideoVp8 : kRtpVideoVp9)); |
71 RtpDepacketizer::ParsedPayload parsed_payload; | 80 RtpDepacketizer::ParsedPayload parsed_payload; |
72 if (depacketizer->Parse(&parsed_payload, payload, payload_data_length)) { | 81 if (depacketizer->Parse(&parsed_payload, payload, payload_data_length)) { |
73 const int temporal_idx = static_cast<int>( | 82 const int temporal_idx = static_cast<int>( |
74 is_vp8 ? parsed_payload.type.Video.codecHeader.VP8.temporalIdx | 83 is_vp8 ? parsed_payload.type.Video.codecHeader.VP8.temporalIdx |
75 : parsed_payload.type.Video.codecHeader.VP9.temporal_idx); | 84 : parsed_payload.type.Video.codecHeader.VP9.temporal_idx); |
76 const int spatial_idx = static_cast<int>( | 85 const int spatial_idx = static_cast<int>( |
77 is_vp8 ? kNoSpatialIdx | 86 is_vp8 ? kNoSpatialIdx |
78 : parsed_payload.type.Video.codecHeader.VP9.spatial_idx); | 87 : parsed_payload.type.Video.codecHeader.VP9.spatial_idx); |
79 if (selected_sl_ >= 0 && spatial_idx == selected_sl_ && | 88 if (selected_sl_ >= 0 && spatial_idx == selected_sl_ && |
80 parsed_payload.type.Video.codecHeader.VP9.end_of_frame) { | 89 parsed_payload.type.Video.codecHeader.VP9.end_of_frame) { |
81 // This layer is now the last in the superframe. | 90 // This layer is now the last in the superframe. |
82 set_marker_bit = true; | 91 set_marker_bit = true; |
83 } else if ((selected_tl_ >= 0 && temporal_idx != kNoTemporalIdx && | 92 } else if ((selected_tl_ >= 0 && temporal_idx != kNoTemporalIdx && |
84 temporal_idx > selected_tl_) || | 93 temporal_idx > selected_tl_) || |
85 (selected_sl_ >= 0 && spatial_idx != kNoSpatialIdx && | 94 (selected_sl_ >= 0 && spatial_idx != kNoSpatialIdx && |
86 spatial_idx > selected_sl_)) { | 95 spatial_idx > selected_sl_)) { |
87 // Truncate packet to a padding packet. | 96 // Truncate packet to a padding packet. |
88 length = header.headerLength + 1; | 97 length = header.headerLength + 1; |
89 temp_buffer[0] |= (1 << 5); // P = 1. | 98 rtp_packet.data[0] |= (1 << 5); // P = 1. |
90 temp_buffer[1] &= 0x7F; // M = 0. | 99 rtp_packet.data[1] &= 0x7F; // M = 0. |
91 discarded_last_packet_ = true; | 100 discarded_last_packet_ = true; |
92 temp_buffer[header.headerLength] = 1; // One byte of padding. | 101 rtp_packet.data[header.headerLength] = 1; // One byte of padding. |
93 } | 102 } |
94 } else { | 103 } else { |
95 RTC_NOTREACHED() << "Parse error"; | 104 RTC_NOTREACHED() << "Parse error"; |
96 } | 105 } |
97 } | 106 } |
98 | 107 |
99 // We are discarding some of the packets (specifically, whole layers), so | 108 // We are discarding some of the packets (specifically, whole layers), so |
100 // make sure the marker bit is set properly, and that sequence numbers are | 109 // make sure the marker bit is set properly, and that sequence numbers are |
101 // continuous. | 110 // continuous. |
102 if (set_marker_bit) | 111 if (set_marker_bit) |
103 temp_buffer[1] |= kRtpMarkerBitMask; | 112 rtp_packet.data[1] |= kRtpMarkerBitMask; |
104 | 113 |
105 return test::DirectTransport::SendRtp(temp_buffer, length, options); | 114 if (rtp_file_writer_.get()) |
115 rtp_file_writer_->WritePacket(&rtp_packet); | |
116 | |
117 return test::DirectTransport::SendRtp(rtp_packet.data, length, options); | |
106 } | 118 } |
107 | 119 |
108 } // namespace test | 120 } // namespace test |
109 } // namespace webrtc | 121 } // namespace webrtc |
OLD | NEW |