OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 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/media/base/testutils.h" | 11 #include "webrtc/media/base/testutils.h" |
12 | 12 |
13 #include <math.h> | 13 #include <math.h> |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <memory> | 15 #include <memory> |
16 | 16 |
17 #include "webrtc/api/video/video_frame.h" | 17 #include "webrtc/api/video/video_frame.h" |
18 #include "webrtc/base/bytebuffer.h" | 18 #include "webrtc/base/bytebuffer.h" |
19 #include "webrtc/base/fileutils.h" | 19 #include "webrtc/base/fileutils.h" |
20 #include "webrtc/base/gunit.h" | 20 #include "webrtc/base/gunit.h" |
21 #include "webrtc/base/pathutils.h" | 21 #include "webrtc/base/pathutils.h" |
22 #include "webrtc/base/stream.h" | 22 #include "webrtc/base/stream.h" |
23 #include "webrtc/base/stringutils.h" | 23 #include "webrtc/base/stringutils.h" |
24 #include "webrtc/base/testutils.h" | 24 #include "webrtc/base/testutils.h" |
25 #include "webrtc/media/base/rtpdump.h" | |
26 #include "webrtc/media/base/videocapturer.h" | 25 #include "webrtc/media/base/videocapturer.h" |
27 | 26 |
28 namespace cricket { | 27 namespace cricket { |
29 | 28 |
30 ///////////////////////////////////////////////////////////////////////// | 29 ///////////////////////////////////////////////////////////////////////// |
31 // Implementation of RawRtpPacket | 30 // Implementation of RawRtpPacket |
32 ///////////////////////////////////////////////////////////////////////// | 31 ///////////////////////////////////////////////////////////////////////// |
33 void RawRtpPacket::WriteToByteBuffer(uint32_t in_ssrc, | 32 void RawRtpPacket::WriteToByteBuffer(uint32_t in_ssrc, |
34 rtc::ByteBufferWriter* buf) const { | 33 rtc::ByteBufferWriter* buf) const { |
35 if (!buf) return; | 34 if (!buf) return; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return ret; | 89 return ret; |
91 } | 90 } |
92 | 91 |
93 bool RawRtcpPacket::EqualsTo(const RawRtcpPacket& packet) const { | 92 bool RawRtcpPacket::EqualsTo(const RawRtcpPacket& packet) const { |
94 return ver_to_count == packet.ver_to_count && | 93 return ver_to_count == packet.ver_to_count && |
95 type == packet.type && | 94 type == packet.type && |
96 length == packet.length && | 95 length == packet.length && |
97 0 == memcmp(payload, packet.payload, sizeof(payload)); | 96 0 == memcmp(payload, packet.payload, sizeof(payload)); |
98 } | 97 } |
99 | 98 |
100 ///////////////////////////////////////////////////////////////////////// | |
101 // Implementation of class RtpTestUtility | |
102 ///////////////////////////////////////////////////////////////////////// | |
103 const RawRtpPacket RtpTestUtility::kTestRawRtpPackets[] = { | |
104 {0x80, 0, 0, 0, RtpTestUtility::kDefaultSsrc, "RTP frame 0"}, | |
105 {0x80, 0, 1, 30, RtpTestUtility::kDefaultSsrc, "RTP frame 1"}, | |
106 {0x80, 0, 2, 30, RtpTestUtility::kDefaultSsrc, "RTP frame 1"}, | |
107 {0x80, 0, 3, 60, RtpTestUtility::kDefaultSsrc, "RTP frame 2"} | |
108 }; | |
109 const RawRtcpPacket RtpTestUtility::kTestRawRtcpPackets[] = { | |
110 // The Version is 2, the Length is 2, and the payload has 8 bytes. | |
111 {0x80, 0, 2, "RTCP0000"}, | |
112 {0x80, 0, 2, "RTCP0001"}, | |
113 {0x80, 0, 2, "RTCP0002"}, | |
114 {0x80, 0, 2, "RTCP0003"}, | |
115 }; | |
116 | |
117 size_t RtpTestUtility::GetTestPacketCount() { | |
118 return std::min(arraysize(kTestRawRtpPackets), | |
119 arraysize(kTestRawRtcpPackets)); | |
120 } | |
121 | |
122 bool RtpTestUtility::WriteTestPackets(size_t count, | |
123 bool rtcp, | |
124 uint32_t rtp_ssrc, | |
125 RtpDumpWriter* writer) { | |
126 if (!writer || count > GetTestPacketCount()) return false; | |
127 | |
128 bool result = true; | |
129 uint32_t elapsed_time_ms = 0; | |
130 for (size_t i = 0; i < count && result; ++i) { | |
131 rtc::ByteBufferWriter buf; | |
132 if (rtcp) { | |
133 kTestRawRtcpPackets[i].WriteToByteBuffer(&buf); | |
134 } else { | |
135 kTestRawRtpPackets[i].WriteToByteBuffer(rtp_ssrc, &buf); | |
136 } | |
137 | |
138 RtpDumpPacket dump_packet(buf.Data(), buf.Length(), elapsed_time_ms, rtcp); | |
139 elapsed_time_ms += kElapsedTimeInterval; | |
140 result &= (rtc::SR_SUCCESS == writer->WritePacket(dump_packet)); | |
141 } | |
142 return result; | |
143 } | |
144 | |
145 bool RtpTestUtility::VerifyTestPacketsFromStream(size_t count, | |
146 rtc::StreamInterface* stream, | |
147 uint32_t ssrc) { | |
148 if (!stream) return false; | |
149 | |
150 uint32_t prev_elapsed_time = 0; | |
151 bool result = true; | |
152 stream->Rewind(); | |
153 RtpDumpLoopReader reader(stream); | |
154 for (size_t i = 0; i < count && result; ++i) { | |
155 // Which loop and which index in the loop are we reading now. | |
156 size_t loop = i / GetTestPacketCount(); | |
157 size_t index = i % GetTestPacketCount(); | |
158 | |
159 RtpDumpPacket packet; | |
160 result &= (rtc::SR_SUCCESS == reader.ReadPacket(&packet)); | |
161 // Check the elapsed time of the dump packet. | |
162 result &= (packet.elapsed_time >= prev_elapsed_time); | |
163 prev_elapsed_time = packet.elapsed_time; | |
164 | |
165 // Check the RTP or RTCP packet. | |
166 rtc::ByteBufferReader buf(reinterpret_cast<const char*>(&packet.data[0]), | |
167 packet.data.size()); | |
168 if (packet.is_rtcp()) { | |
169 // RTCP packet. | |
170 RawRtcpPacket rtcp_packet; | |
171 result &= rtcp_packet.ReadFromByteBuffer(&buf); | |
172 result &= rtcp_packet.EqualsTo(kTestRawRtcpPackets[index]); | |
173 } else { | |
174 // RTP packet. | |
175 RawRtpPacket rtp_packet; | |
176 result &= rtp_packet.ReadFromByteBuffer(&buf); | |
177 result &= rtp_packet.SameExceptSeqNumTimestampSsrc( | |
178 kTestRawRtpPackets[index], | |
179 static_cast<uint16_t>(kTestRawRtpPackets[index].sequence_number + | |
180 loop * GetTestPacketCount()), | |
181 static_cast<uint32_t>(kTestRawRtpPackets[index].timestamp + | |
182 loop * kRtpTimestampIncrease), | |
183 ssrc); | |
184 } | |
185 } | |
186 | |
187 stream->Rewind(); | |
188 return result; | |
189 } | |
190 | |
191 bool RtpTestUtility::VerifyPacket(const RtpDumpPacket* dump, | |
192 const RawRtpPacket* raw, | |
193 bool header_only) { | |
194 if (!dump || !raw) return false; | |
195 | |
196 rtc::ByteBufferWriter buf; | |
197 raw->WriteToByteBuffer(RtpTestUtility::kDefaultSsrc, &buf); | |
198 | |
199 if (header_only) { | |
200 size_t header_len = 0; | |
201 dump->GetRtpHeaderLen(&header_len); | |
202 return header_len == dump->data.size() && | |
203 buf.Length() > dump->data.size() && | |
204 0 == memcmp(buf.Data(), &dump->data[0], dump->data.size()); | |
205 } else { | |
206 return buf.Length() == dump->data.size() && | |
207 0 == memcmp(buf.Data(), &dump->data[0], dump->data.size()); | |
208 } | |
209 } | |
210 | |
211 // Implementation of VideoCaptureListener. | 99 // Implementation of VideoCaptureListener. |
212 VideoCapturerListener::VideoCapturerListener(VideoCapturer* capturer) | 100 VideoCapturerListener::VideoCapturerListener(VideoCapturer* capturer) |
213 : capturer_(capturer), | 101 : capturer_(capturer), |
214 last_capture_state_(CS_STARTING), | 102 last_capture_state_(CS_STARTING), |
215 frame_count_(0), | 103 frame_count_(0), |
216 frame_width_(0), | 104 frame_width_(0), |
217 frame_height_(0), | 105 frame_height_(0), |
218 resolution_changed_(false) { | 106 resolution_changed_(false) { |
219 capturer->SignalStateChange.connect(this, | 107 capturer->SignalStateChange.connect(this, |
220 &VideoCapturerListener::OnStateChange); | 108 &VideoCapturerListener::OnStateChange); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 cricket::StreamParams sp; | 163 cricket::StreamParams sp; |
276 cricket::SsrcGroup sg(cricket::kFecFrSsrcGroupSemantics, | 164 cricket::SsrcGroup sg(cricket::kFecFrSsrcGroupSemantics, |
277 {primary_ssrc, flexfec_ssrc}); | 165 {primary_ssrc, flexfec_ssrc}); |
278 sp.ssrcs = {primary_ssrc}; | 166 sp.ssrcs = {primary_ssrc}; |
279 sp.ssrc_groups.push_back(sg); | 167 sp.ssrc_groups.push_back(sg); |
280 sp.cname = cname; | 168 sp.cname = cname; |
281 return sp; | 169 return sp; |
282 } | 170 } |
283 | 171 |
284 } // namespace cricket | 172 } // namespace cricket |
OLD | NEW |