Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: webrtc/media/base/testutils.cc

Issue 1821083002: Split ByteBuffer into writer/reader objects. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/media/base/testutils.h ('k') | webrtc/media/base/videoengine_unittest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 14 matching lines...) Expand all
25 #include "webrtc/media/base/rtpdump.h" 25 #include "webrtc/media/base/rtpdump.h"
26 #include "webrtc/media/base/videocapturer.h" 26 #include "webrtc/media/base/videocapturer.h"
27 #include "webrtc/media/base/videoframe.h" 27 #include "webrtc/media/base/videoframe.h"
28 28
29 namespace cricket { 29 namespace cricket {
30 30
31 ///////////////////////////////////////////////////////////////////////// 31 /////////////////////////////////////////////////////////////////////////
32 // Implementation of RawRtpPacket 32 // Implementation of RawRtpPacket
33 ///////////////////////////////////////////////////////////////////////// 33 /////////////////////////////////////////////////////////////////////////
34 void RawRtpPacket::WriteToByteBuffer(uint32_t in_ssrc, 34 void RawRtpPacket::WriteToByteBuffer(uint32_t in_ssrc,
35 rtc::ByteBuffer* buf) const { 35 rtc::ByteBufferWriter* buf) const {
36 if (!buf) return; 36 if (!buf) return;
37 37
38 buf->WriteUInt8(ver_to_cc); 38 buf->WriteUInt8(ver_to_cc);
39 buf->WriteUInt8(m_to_pt); 39 buf->WriteUInt8(m_to_pt);
40 buf->WriteUInt16(sequence_number); 40 buf->WriteUInt16(sequence_number);
41 buf->WriteUInt32(timestamp); 41 buf->WriteUInt32(timestamp);
42 buf->WriteUInt32(in_ssrc); 42 buf->WriteUInt32(in_ssrc);
43 buf->WriteBytes(payload, sizeof(payload)); 43 buf->WriteBytes(payload, sizeof(payload));
44 } 44 }
45 45
46 bool RawRtpPacket::ReadFromByteBuffer(rtc::ByteBuffer* buf) { 46 bool RawRtpPacket::ReadFromByteBuffer(rtc::ByteBufferReader* buf) {
47 if (!buf) return false; 47 if (!buf) return false;
48 48
49 bool ret = true; 49 bool ret = true;
50 ret &= buf->ReadUInt8(&ver_to_cc); 50 ret &= buf->ReadUInt8(&ver_to_cc);
51 ret &= buf->ReadUInt8(&m_to_pt); 51 ret &= buf->ReadUInt8(&m_to_pt);
52 ret &= buf->ReadUInt16(&sequence_number); 52 ret &= buf->ReadUInt16(&sequence_number);
53 ret &= buf->ReadUInt32(&timestamp); 53 ret &= buf->ReadUInt32(&timestamp);
54 ret &= buf->ReadUInt32(&ssrc); 54 ret &= buf->ReadUInt32(&ssrc);
55 ret &= buf->ReadBytes(payload, sizeof(payload)); 55 ret &= buf->ReadBytes(payload, sizeof(payload));
56 return ret; 56 return ret;
57 } 57 }
58 58
59 bool RawRtpPacket::SameExceptSeqNumTimestampSsrc(const RawRtpPacket& packet, 59 bool RawRtpPacket::SameExceptSeqNumTimestampSsrc(const RawRtpPacket& packet,
60 uint16_t seq, 60 uint16_t seq,
61 uint32_t ts, 61 uint32_t ts,
62 uint32_t ssc) const { 62 uint32_t ssc) const {
63 return sequence_number == seq && 63 return sequence_number == seq &&
64 timestamp == ts && 64 timestamp == ts &&
65 ver_to_cc == packet.ver_to_cc && 65 ver_to_cc == packet.ver_to_cc &&
66 m_to_pt == packet.m_to_pt && 66 m_to_pt == packet.m_to_pt &&
67 ssrc == ssc && 67 ssrc == ssc &&
68 0 == memcmp(payload, packet.payload, sizeof(payload)); 68 0 == memcmp(payload, packet.payload, sizeof(payload));
69 } 69 }
70 70
71 ///////////////////////////////////////////////////////////////////////// 71 /////////////////////////////////////////////////////////////////////////
72 // Implementation of RawRtcpPacket 72 // Implementation of RawRtcpPacket
73 ///////////////////////////////////////////////////////////////////////// 73 /////////////////////////////////////////////////////////////////////////
74 void RawRtcpPacket::WriteToByteBuffer(rtc::ByteBuffer *buf) const { 74 void RawRtcpPacket::WriteToByteBuffer(rtc::ByteBufferWriter *buf) const {
75 if (!buf) return; 75 if (!buf) return;
76 76
77 buf->WriteUInt8(ver_to_count); 77 buf->WriteUInt8(ver_to_count);
78 buf->WriteUInt8(type); 78 buf->WriteUInt8(type);
79 buf->WriteUInt16(length); 79 buf->WriteUInt16(length);
80 buf->WriteBytes(payload, sizeof(payload)); 80 buf->WriteBytes(payload, sizeof(payload));
81 } 81 }
82 82
83 bool RawRtcpPacket::ReadFromByteBuffer(rtc::ByteBuffer* buf) { 83 bool RawRtcpPacket::ReadFromByteBuffer(rtc::ByteBufferReader* buf) {
84 if (!buf) return false; 84 if (!buf) return false;
85 85
86 bool ret = true; 86 bool ret = true;
87 ret &= buf->ReadUInt8(&ver_to_count); 87 ret &= buf->ReadUInt8(&ver_to_count);
88 ret &= buf->ReadUInt8(&type); 88 ret &= buf->ReadUInt8(&type);
89 ret &= buf->ReadUInt16(&length); 89 ret &= buf->ReadUInt16(&length);
90 ret &= buf->ReadBytes(payload, sizeof(payload)); 90 ret &= buf->ReadBytes(payload, sizeof(payload));
91 return ret; 91 return ret;
92 } 92 }
93 93
(...skipping 28 matching lines...) Expand all
122 122
123 bool RtpTestUtility::WriteTestPackets(size_t count, 123 bool RtpTestUtility::WriteTestPackets(size_t count,
124 bool rtcp, 124 bool rtcp,
125 uint32_t rtp_ssrc, 125 uint32_t rtp_ssrc,
126 RtpDumpWriter* writer) { 126 RtpDumpWriter* writer) {
127 if (!writer || count > GetTestPacketCount()) return false; 127 if (!writer || count > GetTestPacketCount()) return false;
128 128
129 bool result = true; 129 bool result = true;
130 uint32_t elapsed_time_ms = 0; 130 uint32_t elapsed_time_ms = 0;
131 for (size_t i = 0; i < count && result; ++i) { 131 for (size_t i = 0; i < count && result; ++i) {
132 rtc::ByteBuffer buf; 132 rtc::ByteBufferWriter buf;
133 if (rtcp) { 133 if (rtcp) {
134 kTestRawRtcpPackets[i].WriteToByteBuffer(&buf); 134 kTestRawRtcpPackets[i].WriteToByteBuffer(&buf);
135 } else { 135 } else {
136 kTestRawRtpPackets[i].WriteToByteBuffer(rtp_ssrc, &buf); 136 kTestRawRtpPackets[i].WriteToByteBuffer(rtp_ssrc, &buf);
137 } 137 }
138 138
139 RtpDumpPacket dump_packet(buf.Data(), buf.Length(), elapsed_time_ms, rtcp); 139 RtpDumpPacket dump_packet(buf.Data(), buf.Length(), elapsed_time_ms, rtcp);
140 elapsed_time_ms += kElapsedTimeInterval; 140 elapsed_time_ms += kElapsedTimeInterval;
141 result &= (rtc::SR_SUCCESS == writer->WritePacket(dump_packet)); 141 result &= (rtc::SR_SUCCESS == writer->WritePacket(dump_packet));
142 } 142 }
(...skipping 14 matching lines...) Expand all
157 size_t loop = i / GetTestPacketCount(); 157 size_t loop = i / GetTestPacketCount();
158 size_t index = i % GetTestPacketCount(); 158 size_t index = i % GetTestPacketCount();
159 159
160 RtpDumpPacket packet; 160 RtpDumpPacket packet;
161 result &= (rtc::SR_SUCCESS == reader.ReadPacket(&packet)); 161 result &= (rtc::SR_SUCCESS == reader.ReadPacket(&packet));
162 // Check the elapsed time of the dump packet. 162 // Check the elapsed time of the dump packet.
163 result &= (packet.elapsed_time >= prev_elapsed_time); 163 result &= (packet.elapsed_time >= prev_elapsed_time);
164 prev_elapsed_time = packet.elapsed_time; 164 prev_elapsed_time = packet.elapsed_time;
165 165
166 // Check the RTP or RTCP packet. 166 // Check the RTP or RTCP packet.
167 rtc::ByteBuffer buf(reinterpret_cast<const char*>(&packet.data[0]), 167 rtc::ByteBufferReader buf(reinterpret_cast<const char*>(&packet.data[0]),
168 packet.data.size()); 168 packet.data.size());
169 if (packet.is_rtcp()) { 169 if (packet.is_rtcp()) {
170 // RTCP packet. 170 // RTCP packet.
171 RawRtcpPacket rtcp_packet; 171 RawRtcpPacket rtcp_packet;
172 result &= rtcp_packet.ReadFromByteBuffer(&buf); 172 result &= rtcp_packet.ReadFromByteBuffer(&buf);
173 result &= rtcp_packet.EqualsTo(kTestRawRtcpPackets[index]); 173 result &= rtcp_packet.EqualsTo(kTestRawRtcpPackets[index]);
174 } else { 174 } else {
175 // RTP packet. 175 // RTP packet.
176 RawRtpPacket rtp_packet; 176 RawRtpPacket rtp_packet;
177 result &= rtp_packet.ReadFromByteBuffer(&buf); 177 result &= rtp_packet.ReadFromByteBuffer(&buf);
178 result &= rtp_packet.SameExceptSeqNumTimestampSsrc( 178 result &= rtp_packet.SameExceptSeqNumTimestampSsrc(
179 kTestRawRtpPackets[index], 179 kTestRawRtpPackets[index],
180 static_cast<uint16_t>(kTestRawRtpPackets[index].sequence_number + 180 static_cast<uint16_t>(kTestRawRtpPackets[index].sequence_number +
181 loop * GetTestPacketCount()), 181 loop * GetTestPacketCount()),
182 static_cast<uint32_t>(kTestRawRtpPackets[index].timestamp + 182 static_cast<uint32_t>(kTestRawRtpPackets[index].timestamp +
183 loop * kRtpTimestampIncrease), 183 loop * kRtpTimestampIncrease),
184 ssrc); 184 ssrc);
185 } 185 }
186 } 186 }
187 187
188 stream->Rewind(); 188 stream->Rewind();
189 return result; 189 return result;
190 } 190 }
191 191
192 bool RtpTestUtility::VerifyPacket(const RtpDumpPacket* dump, 192 bool RtpTestUtility::VerifyPacket(const RtpDumpPacket* dump,
193 const RawRtpPacket* raw, 193 const RawRtpPacket* raw,
194 bool header_only) { 194 bool header_only) {
195 if (!dump || !raw) return false; 195 if (!dump || !raw) return false;
196 196
197 rtc::ByteBuffer buf; 197 rtc::ByteBufferWriter buf;
198 raw->WriteToByteBuffer(RtpTestUtility::kDefaultSsrc, &buf); 198 raw->WriteToByteBuffer(RtpTestUtility::kDefaultSsrc, &buf);
199 199
200 if (header_only) { 200 if (header_only) {
201 size_t header_len = 0; 201 size_t header_len = 0;
202 dump->GetRtpHeaderLen(&header_len); 202 dump->GetRtpHeaderLen(&header_len);
203 return header_len == dump->data.size() && 203 return header_len == dump->data.size() &&
204 buf.Length() > dump->data.size() && 204 buf.Length() > dump->data.size() &&
205 0 == memcmp(buf.Data(), &dump->data[0], dump->data.size()); 205 0 == memcmp(buf.Data(), &dump->data[0], dump->data.size());
206 } else { 206 } else {
207 return buf.Length() == dump->data.size() && 207 return buf.Length() == dump->data.size() &&
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 std::vector<uint32_t> fid_ssrcs; 360 std::vector<uint32_t> fid_ssrcs;
361 fid_ssrcs.push_back(ssrcs[i]); 361 fid_ssrcs.push_back(ssrcs[i]);
362 fid_ssrcs.push_back(rtx_ssrcs[i]); 362 fid_ssrcs.push_back(rtx_ssrcs[i]);
363 cricket::SsrcGroup fid_group(cricket::kFidSsrcGroupSemantics, fid_ssrcs); 363 cricket::SsrcGroup fid_group(cricket::kFidSsrcGroupSemantics, fid_ssrcs);
364 sp.ssrc_groups.push_back(fid_group); 364 sp.ssrc_groups.push_back(fid_group);
365 } 365 }
366 return sp; 366 return sp;
367 } 367 }
368 368
369 } // namespace cricket 369 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/media/base/testutils.h ('k') | webrtc/media/base/videoengine_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698