OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "webrtc/base/pathutils.h" | 40 #include "webrtc/base/pathutils.h" |
41 #include "webrtc/base/stream.h" | 41 #include "webrtc/base/stream.h" |
42 #include "webrtc/base/stringutils.h" | 42 #include "webrtc/base/stringutils.h" |
43 #include "webrtc/base/testutils.h" | 43 #include "webrtc/base/testutils.h" |
44 | 44 |
45 namespace cricket { | 45 namespace cricket { |
46 | 46 |
47 ///////////////////////////////////////////////////////////////////////// | 47 ///////////////////////////////////////////////////////////////////////// |
48 // Implementation of RawRtpPacket | 48 // Implementation of RawRtpPacket |
49 ///////////////////////////////////////////////////////////////////////// | 49 ///////////////////////////////////////////////////////////////////////// |
50 void RawRtpPacket::WriteToByteBuffer( | 50 void RawRtpPacket::WriteToByteBuffer(uint32_t in_ssrc, |
51 uint32 in_ssrc, rtc::ByteBuffer *buf) const { | 51 rtc::ByteBuffer* buf) const { |
52 if (!buf) return; | 52 if (!buf) return; |
53 | 53 |
54 buf->WriteUInt8(ver_to_cc); | 54 buf->WriteUInt8(ver_to_cc); |
55 buf->WriteUInt8(m_to_pt); | 55 buf->WriteUInt8(m_to_pt); |
56 buf->WriteUInt16(sequence_number); | 56 buf->WriteUInt16(sequence_number); |
57 buf->WriteUInt32(timestamp); | 57 buf->WriteUInt32(timestamp); |
58 buf->WriteUInt32(in_ssrc); | 58 buf->WriteUInt32(in_ssrc); |
59 buf->WriteBytes(payload, sizeof(payload)); | 59 buf->WriteBytes(payload, sizeof(payload)); |
60 } | 60 } |
61 | 61 |
62 bool RawRtpPacket::ReadFromByteBuffer(rtc::ByteBuffer* buf) { | 62 bool RawRtpPacket::ReadFromByteBuffer(rtc::ByteBuffer* buf) { |
63 if (!buf) return false; | 63 if (!buf) return false; |
64 | 64 |
65 bool ret = true; | 65 bool ret = true; |
66 ret &= buf->ReadUInt8(&ver_to_cc); | 66 ret &= buf->ReadUInt8(&ver_to_cc); |
67 ret &= buf->ReadUInt8(&m_to_pt); | 67 ret &= buf->ReadUInt8(&m_to_pt); |
68 ret &= buf->ReadUInt16(&sequence_number); | 68 ret &= buf->ReadUInt16(&sequence_number); |
69 ret &= buf->ReadUInt32(×tamp); | 69 ret &= buf->ReadUInt32(×tamp); |
70 ret &= buf->ReadUInt32(&ssrc); | 70 ret &= buf->ReadUInt32(&ssrc); |
71 ret &= buf->ReadBytes(payload, sizeof(payload)); | 71 ret &= buf->ReadBytes(payload, sizeof(payload)); |
72 return ret; | 72 return ret; |
73 } | 73 } |
74 | 74 |
75 bool RawRtpPacket::SameExceptSeqNumTimestampSsrc( | 75 bool RawRtpPacket::SameExceptSeqNumTimestampSsrc(const RawRtpPacket& packet, |
76 const RawRtpPacket& packet, uint16 seq, uint32 ts, uint32 ssc) const { | 76 uint16_t seq, |
| 77 uint32_t ts, |
| 78 uint32_t ssc) const { |
77 return sequence_number == seq && | 79 return sequence_number == seq && |
78 timestamp == ts && | 80 timestamp == ts && |
79 ver_to_cc == packet.ver_to_cc && | 81 ver_to_cc == packet.ver_to_cc && |
80 m_to_pt == packet.m_to_pt && | 82 m_to_pt == packet.m_to_pt && |
81 ssrc == ssc && | 83 ssrc == ssc && |
82 0 == memcmp(payload, packet.payload, sizeof(payload)); | 84 0 == memcmp(payload, packet.payload, sizeof(payload)); |
83 } | 85 } |
84 | 86 |
85 ///////////////////////////////////////////////////////////////////////// | 87 ///////////////////////////////////////////////////////////////////////// |
86 // Implementation of RawRtcpPacket | 88 // Implementation of RawRtcpPacket |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 {0x80, 0, 2, "RTCP0001"}, | 129 {0x80, 0, 2, "RTCP0001"}, |
128 {0x80, 0, 2, "RTCP0002"}, | 130 {0x80, 0, 2, "RTCP0002"}, |
129 {0x80, 0, 2, "RTCP0003"}, | 131 {0x80, 0, 2, "RTCP0003"}, |
130 }; | 132 }; |
131 | 133 |
132 size_t RtpTestUtility::GetTestPacketCount() { | 134 size_t RtpTestUtility::GetTestPacketCount() { |
133 return std::min(ARRAY_SIZE(kTestRawRtpPackets), | 135 return std::min(ARRAY_SIZE(kTestRawRtpPackets), |
134 ARRAY_SIZE(kTestRawRtcpPackets)); | 136 ARRAY_SIZE(kTestRawRtcpPackets)); |
135 } | 137 } |
136 | 138 |
137 bool RtpTestUtility::WriteTestPackets( | 139 bool RtpTestUtility::WriteTestPackets(size_t count, |
138 size_t count, bool rtcp, uint32 rtp_ssrc, RtpDumpWriter* writer) { | 140 bool rtcp, |
| 141 uint32_t rtp_ssrc, |
| 142 RtpDumpWriter* writer) { |
139 if (!writer || count > GetTestPacketCount()) return false; | 143 if (!writer || count > GetTestPacketCount()) return false; |
140 | 144 |
141 bool result = true; | 145 bool result = true; |
142 uint32 elapsed_time_ms = 0; | 146 uint32_t elapsed_time_ms = 0; |
143 for (size_t i = 0; i < count && result; ++i) { | 147 for (size_t i = 0; i < count && result; ++i) { |
144 rtc::ByteBuffer buf; | 148 rtc::ByteBuffer buf; |
145 if (rtcp) { | 149 if (rtcp) { |
146 kTestRawRtcpPackets[i].WriteToByteBuffer(&buf); | 150 kTestRawRtcpPackets[i].WriteToByteBuffer(&buf); |
147 } else { | 151 } else { |
148 kTestRawRtpPackets[i].WriteToByteBuffer(rtp_ssrc, &buf); | 152 kTestRawRtpPackets[i].WriteToByteBuffer(rtp_ssrc, &buf); |
149 } | 153 } |
150 | 154 |
151 RtpDumpPacket dump_packet(buf.Data(), buf.Length(), elapsed_time_ms, rtcp); | 155 RtpDumpPacket dump_packet(buf.Data(), buf.Length(), elapsed_time_ms, rtcp); |
152 elapsed_time_ms += kElapsedTimeInterval; | 156 elapsed_time_ms += kElapsedTimeInterval; |
153 result &= (rtc::SR_SUCCESS == writer->WritePacket(dump_packet)); | 157 result &= (rtc::SR_SUCCESS == writer->WritePacket(dump_packet)); |
154 } | 158 } |
155 return result; | 159 return result; |
156 } | 160 } |
157 | 161 |
158 bool RtpTestUtility::VerifyTestPacketsFromStream( | 162 bool RtpTestUtility::VerifyTestPacketsFromStream(size_t count, |
159 size_t count, rtc::StreamInterface* stream, uint32 ssrc) { | 163 rtc::StreamInterface* stream, |
| 164 uint32_t ssrc) { |
160 if (!stream) return false; | 165 if (!stream) return false; |
161 | 166 |
162 uint32 prev_elapsed_time = 0; | 167 uint32_t prev_elapsed_time = 0; |
163 bool result = true; | 168 bool result = true; |
164 stream->Rewind(); | 169 stream->Rewind(); |
165 RtpDumpLoopReader reader(stream); | 170 RtpDumpLoopReader reader(stream); |
166 for (size_t i = 0; i < count && result; ++i) { | 171 for (size_t i = 0; i < count && result; ++i) { |
167 // Which loop and which index in the loop are we reading now. | 172 // Which loop and which index in the loop are we reading now. |
168 size_t loop = i / GetTestPacketCount(); | 173 size_t loop = i / GetTestPacketCount(); |
169 size_t index = i % GetTestPacketCount(); | 174 size_t index = i % GetTestPacketCount(); |
170 | 175 |
171 RtpDumpPacket packet; | 176 RtpDumpPacket packet; |
172 result &= (rtc::SR_SUCCESS == reader.ReadPacket(&packet)); | 177 result &= (rtc::SR_SUCCESS == reader.ReadPacket(&packet)); |
173 // Check the elapsed time of the dump packet. | 178 // Check the elapsed time of the dump packet. |
174 result &= (packet.elapsed_time >= prev_elapsed_time); | 179 result &= (packet.elapsed_time >= prev_elapsed_time); |
175 prev_elapsed_time = packet.elapsed_time; | 180 prev_elapsed_time = packet.elapsed_time; |
176 | 181 |
177 // Check the RTP or RTCP packet. | 182 // Check the RTP or RTCP packet. |
178 rtc::ByteBuffer buf(reinterpret_cast<const char*>(&packet.data[0]), | 183 rtc::ByteBuffer buf(reinterpret_cast<const char*>(&packet.data[0]), |
179 packet.data.size()); | 184 packet.data.size()); |
180 if (packet.is_rtcp()) { | 185 if (packet.is_rtcp()) { |
181 // RTCP packet. | 186 // RTCP packet. |
182 RawRtcpPacket rtcp_packet; | 187 RawRtcpPacket rtcp_packet; |
183 result &= rtcp_packet.ReadFromByteBuffer(&buf); | 188 result &= rtcp_packet.ReadFromByteBuffer(&buf); |
184 result &= rtcp_packet.EqualsTo(kTestRawRtcpPackets[index]); | 189 result &= rtcp_packet.EqualsTo(kTestRawRtcpPackets[index]); |
185 } else { | 190 } else { |
186 // RTP packet. | 191 // RTP packet. |
187 RawRtpPacket rtp_packet; | 192 RawRtpPacket rtp_packet; |
188 result &= rtp_packet.ReadFromByteBuffer(&buf); | 193 result &= rtp_packet.ReadFromByteBuffer(&buf); |
189 result &= rtp_packet.SameExceptSeqNumTimestampSsrc( | 194 result &= rtp_packet.SameExceptSeqNumTimestampSsrc( |
190 kTestRawRtpPackets[index], | 195 kTestRawRtpPackets[index], |
191 static_cast<uint16>(kTestRawRtpPackets[index].sequence_number + | 196 static_cast<uint16_t>(kTestRawRtpPackets[index].sequence_number + |
192 loop * GetTestPacketCount()), | 197 loop * GetTestPacketCount()), |
193 static_cast<uint32>(kTestRawRtpPackets[index].timestamp + | 198 static_cast<uint32_t>(kTestRawRtpPackets[index].timestamp + |
194 loop * kRtpTimestampIncrease), | 199 loop * kRtpTimestampIncrease), |
195 ssrc); | 200 ssrc); |
196 } | 201 } |
197 } | 202 } |
198 | 203 |
199 stream->Rewind(); | 204 stream->Rewind(); |
200 return result; | 205 return result; |
201 } | 206 } |
202 | 207 |
203 bool RtpTestUtility::VerifyPacket(const RtpDumpPacket* dump, | 208 bool RtpTestUtility::VerifyPacket(const RtpDumpPacket* dump, |
204 const RawRtpPacket* raw, | 209 const RawRtpPacket* raw, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 rtc::Pathname path = testing::GetTalkDirectory(); | 269 rtc::Pathname path = testing::GetTalkDirectory(); |
265 EXPECT_FALSE(path.empty()); // must be run from inside "talk" | 270 EXPECT_FALSE(path.empty()); // must be run from inside "talk" |
266 #endif | 271 #endif |
267 path.AppendFolder("media/testdata/"); | 272 path.AppendFolder("media/testdata/"); |
268 path.SetFilename(filename); | 273 path.SetFilename(filename); |
269 return path.pathname(); | 274 return path.pathname(); |
270 } | 275 } |
271 | 276 |
272 // Loads the image with the specified prefix and size into |out|. | 277 // Loads the image with the specified prefix and size into |out|. |
273 bool LoadPlanarYuvTestImage(const std::string& prefix, | 278 bool LoadPlanarYuvTestImage(const std::string& prefix, |
274 int width, int height, uint8* out) { | 279 int width, |
| 280 int height, |
| 281 uint8_t* out) { |
275 std::stringstream ss; | 282 std::stringstream ss; |
276 ss << prefix << "." << width << "x" << height << "_P420.yuv"; | 283 ss << prefix << "." << width << "x" << height << "_P420.yuv"; |
277 | 284 |
278 rtc::scoped_ptr<rtc::FileStream> stream( | 285 rtc::scoped_ptr<rtc::FileStream> stream( |
279 rtc::Filesystem::OpenFile(rtc::Pathname( | 286 rtc::Filesystem::OpenFile(rtc::Pathname( |
280 GetTestFilePath(ss.str())), "rb")); | 287 GetTestFilePath(ss.str())), "rb")); |
281 if (!stream) { | 288 if (!stream) { |
282 return false; | 289 return false; |
283 } | 290 } |
284 | 291 |
285 rtc::StreamResult res = | 292 rtc::StreamResult res = |
286 stream->ReadAll(out, I420_SIZE(width, height), NULL, NULL); | 293 stream->ReadAll(out, I420_SIZE(width, height), NULL, NULL); |
287 return (res == rtc::SR_SUCCESS); | 294 return (res == rtc::SR_SUCCESS); |
288 } | 295 } |
289 | 296 |
290 // Dumps the YUV image out to a file, for visual inspection. | 297 // Dumps the YUV image out to a file, for visual inspection. |
291 // PYUV tool can be used to view dump files. | 298 // PYUV tool can be used to view dump files. |
292 void DumpPlanarYuvTestImage(const std::string& prefix, const uint8* img, | 299 void DumpPlanarYuvTestImage(const std::string& prefix, |
293 int w, int h) { | 300 const uint8_t* img, |
| 301 int w, |
| 302 int h) { |
294 rtc::FileStream fs; | 303 rtc::FileStream fs; |
295 char filename[256]; | 304 char filename[256]; |
296 rtc::sprintfn(filename, sizeof(filename), "%s.%dx%d_P420.yuv", | 305 rtc::sprintfn(filename, sizeof(filename), "%s.%dx%d_P420.yuv", |
297 prefix.c_str(), w, h); | 306 prefix.c_str(), w, h); |
298 fs.Open(filename, "wb", NULL); | 307 fs.Open(filename, "wb", NULL); |
299 fs.Write(img, I420_SIZE(w, h), NULL, NULL); | 308 fs.Write(img, I420_SIZE(w, h), NULL, NULL); |
300 } | 309 } |
301 | 310 |
302 // Dumps the ARGB image out to a file, for visual inspection. | 311 // Dumps the ARGB image out to a file, for visual inspection. |
303 // ffplay tool can be used to view dump files. | 312 // ffplay tool can be used to view dump files. |
304 void DumpPlanarArgbTestImage(const std::string& prefix, const uint8* img, | 313 void DumpPlanarArgbTestImage(const std::string& prefix, |
305 int w, int h) { | 314 const uint8_t* img, |
| 315 int w, |
| 316 int h) { |
306 rtc::FileStream fs; | 317 rtc::FileStream fs; |
307 char filename[256]; | 318 char filename[256]; |
308 rtc::sprintfn(filename, sizeof(filename), "%s.%dx%d_ARGB.raw", | 319 rtc::sprintfn(filename, sizeof(filename), "%s.%dx%d_ARGB.raw", |
309 prefix.c_str(), w, h); | 320 prefix.c_str(), w, h); |
310 fs.Open(filename, "wb", NULL); | 321 fs.Open(filename, "wb", NULL); |
311 fs.Write(img, ARGB_SIZE(w, h), NULL, NULL); | 322 fs.Write(img, ARGB_SIZE(w, h), NULL, NULL); |
312 } | 323 } |
313 | 324 |
314 bool VideoFrameEqual(const VideoFrame* frame0, const VideoFrame* frame1) { | 325 bool VideoFrameEqual(const VideoFrame* frame0, const VideoFrame* frame1) { |
315 const uint8* y0 = frame0->GetYPlane(); | 326 const uint8_t* y0 = frame0->GetYPlane(); |
316 const uint8* u0 = frame0->GetUPlane(); | 327 const uint8_t* u0 = frame0->GetUPlane(); |
317 const uint8* v0 = frame0->GetVPlane(); | 328 const uint8_t* v0 = frame0->GetVPlane(); |
318 const uint8* y1 = frame1->GetYPlane(); | 329 const uint8_t* y1 = frame1->GetYPlane(); |
319 const uint8* u1 = frame1->GetUPlane(); | 330 const uint8_t* u1 = frame1->GetUPlane(); |
320 const uint8* v1 = frame1->GetVPlane(); | 331 const uint8_t* v1 = frame1->GetVPlane(); |
321 | 332 |
322 for (size_t i = 0; i < frame0->GetHeight(); ++i) { | 333 for (size_t i = 0; i < frame0->GetHeight(); ++i) { |
323 if (0 != memcmp(y0, y1, frame0->GetWidth())) { | 334 if (0 != memcmp(y0, y1, frame0->GetWidth())) { |
324 return false; | 335 return false; |
325 } | 336 } |
326 y0 += frame0->GetYPitch(); | 337 y0 += frame0->GetYPitch(); |
327 y1 += frame1->GetYPitch(); | 338 y1 += frame1->GetYPitch(); |
328 } | 339 } |
329 | 340 |
330 for (size_t i = 0; i < frame0->GetChromaHeight(); ++i) { | 341 for (size_t i = 0; i < frame0->GetChromaHeight(); ++i) { |
331 if (0 != memcmp(u0, u1, frame0->GetChromaWidth())) { | 342 if (0 != memcmp(u0, u1, frame0->GetChromaWidth())) { |
332 return false; | 343 return false; |
333 } | 344 } |
334 if (0 != memcmp(v0, v1, frame0->GetChromaWidth())) { | 345 if (0 != memcmp(v0, v1, frame0->GetChromaWidth())) { |
335 return false; | 346 return false; |
336 } | 347 } |
337 u0 += frame0->GetUPitch(); | 348 u0 += frame0->GetUPitch(); |
338 v0 += frame0->GetVPitch(); | 349 v0 += frame0->GetVPitch(); |
339 u1 += frame1->GetUPitch(); | 350 u1 += frame1->GetUPitch(); |
340 v1 += frame1->GetVPitch(); | 351 v1 += frame1->GetVPitch(); |
341 } | 352 } |
342 | 353 |
343 return true; | 354 return true; |
344 } | 355 } |
345 | 356 |
346 cricket::StreamParams CreateSimStreamParams( | 357 cricket::StreamParams CreateSimStreamParams( |
347 const std::string& cname, const std::vector<uint32>& ssrcs) { | 358 const std::string& cname, |
| 359 const std::vector<uint32_t>& ssrcs) { |
348 cricket::StreamParams sp; | 360 cricket::StreamParams sp; |
349 cricket::SsrcGroup sg(cricket::kSimSsrcGroupSemantics, ssrcs); | 361 cricket::SsrcGroup sg(cricket::kSimSsrcGroupSemantics, ssrcs); |
350 sp.ssrcs = ssrcs; | 362 sp.ssrcs = ssrcs; |
351 sp.ssrc_groups.push_back(sg); | 363 sp.ssrc_groups.push_back(sg); |
352 sp.cname = cname; | 364 sp.cname = cname; |
353 return sp; | 365 return sp; |
354 } | 366 } |
355 | 367 |
356 // There should be an rtx_ssrc per ssrc. | 368 // There should be an rtx_ssrc per ssrc. |
357 cricket::StreamParams CreateSimWithRtxStreamParams( | 369 cricket::StreamParams CreateSimWithRtxStreamParams( |
358 const std::string& cname, const std::vector<uint32>& ssrcs, | 370 const std::string& cname, |
359 const std::vector<uint32>& rtx_ssrcs) { | 371 const std::vector<uint32_t>& ssrcs, |
| 372 const std::vector<uint32_t>& rtx_ssrcs) { |
360 cricket::StreamParams sp = CreateSimStreamParams(cname, ssrcs); | 373 cricket::StreamParams sp = CreateSimStreamParams(cname, ssrcs); |
361 for (size_t i = 0; i < ssrcs.size(); ++i) { | 374 for (size_t i = 0; i < ssrcs.size(); ++i) { |
362 sp.ssrcs.push_back(rtx_ssrcs[i]); | 375 sp.ssrcs.push_back(rtx_ssrcs[i]); |
363 std::vector<uint32> fid_ssrcs; | 376 std::vector<uint32_t> fid_ssrcs; |
364 fid_ssrcs.push_back(ssrcs[i]); | 377 fid_ssrcs.push_back(ssrcs[i]); |
365 fid_ssrcs.push_back(rtx_ssrcs[i]); | 378 fid_ssrcs.push_back(rtx_ssrcs[i]); |
366 cricket::SsrcGroup fid_group(cricket::kFidSsrcGroupSemantics, fid_ssrcs); | 379 cricket::SsrcGroup fid_group(cricket::kFidSsrcGroupSemantics, fid_ssrcs); |
367 sp.ssrc_groups.push_back(fid_group); | 380 sp.ssrc_groups.push_back(fid_group); |
368 } | 381 } |
369 return sp; | 382 return sp; |
370 } | 383 } |
371 | 384 |
372 } // namespace cricket | 385 } // namespace cricket |
OLD | NEW |