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

Side by Side Diff: webrtc/test/rtp_file_reader.cc

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 class RtpFileReaderImpl : public RtpFileReader { 63 class RtpFileReaderImpl : public RtpFileReader {
64 public: 64 public:
65 virtual bool Init(const std::string& filename, 65 virtual bool Init(const std::string& filename,
66 const std::set<uint32_t>& ssrc_filter) = 0; 66 const std::set<uint32_t>& ssrc_filter) = 0;
67 }; 67 };
68 68
69 class InterleavedRtpFileReader : public RtpFileReaderImpl { 69 class InterleavedRtpFileReader : public RtpFileReaderImpl {
70 public: 70 public:
71 virtual ~InterleavedRtpFileReader() { 71 virtual ~InterleavedRtpFileReader() {
72 if (file_ != NULL) { 72 if (file_ != nullptr) {
73 fclose(file_); 73 fclose(file_);
74 file_ = NULL; 74 file_ = nullptr;
75 } 75 }
76 } 76 }
77 77
78 virtual bool Init(const std::string& filename, 78 virtual bool Init(const std::string& filename,
79 const std::set<uint32_t>& ssrc_filter) { 79 const std::set<uint32_t>& ssrc_filter) {
80 file_ = fopen(filename.c_str(), "rb"); 80 file_ = fopen(filename.c_str(), "rb");
81 if (file_ == NULL) { 81 if (file_ == nullptr) {
82 printf("ERROR: Can't open file: %s\n", filename.c_str()); 82 printf("ERROR: Can't open file: %s\n", filename.c_str());
83 return false; 83 return false;
84 } 84 }
85 return true; 85 return true;
86 } 86 }
87 virtual bool NextPacket(RtpPacket* packet) { 87 virtual bool NextPacket(RtpPacket* packet) {
88 assert(file_ != NULL); 88 assert(file_ != nullptr);
89 packet->length = RtpPacket::kMaxPacketBufferSize; 89 packet->length = RtpPacket::kMaxPacketBufferSize;
90 uint32_t len = 0; 90 uint32_t len = 0;
91 TRY(ReadUint32(&len, file_)); 91 TRY(ReadUint32(&len, file_));
92 if (packet->length < len) { 92 if (packet->length < len) {
93 FATAL() << "Packet is too large to fit: " << len << " bytes vs " 93 FATAL() << "Packet is too large to fit: " << len << " bytes vs "
94 << packet->length 94 << packet->length
95 << " bytes allocated. Consider increasing the buffer " 95 << " bytes allocated. Consider increasing the buffer "
96 "size"; 96 "size";
97 } 97 }
98 if (fread(packet->data, 1, len, file_) != len) 98 if (fread(packet->data, 1, len, file_) != len)
99 return false; 99 return false;
100 100
101 packet->length = len; 101 packet->length = len;
102 packet->original_length = len; 102 packet->original_length = len;
103 packet->time_ms = time_ms_; 103 packet->time_ms = time_ms_;
104 time_ms_ += 5; 104 time_ms_ += 5;
105 return true; 105 return true;
106 } 106 }
107 107
108 private: 108 private:
109 FILE* file_ = NULL; 109 FILE* file_ = nullptr;
110 int64_t time_ms_ = 0; 110 int64_t time_ms_ = 0;
111 }; 111 };
112 112
113 // Read RTP packets from file in rtpdump format, as documented at: 113 // Read RTP packets from file in rtpdump format, as documented at:
114 // http://www.cs.columbia.edu/irt/software/rtptools/ 114 // http://www.cs.columbia.edu/irt/software/rtptools/
115 class RtpDumpReader : public RtpFileReaderImpl { 115 class RtpDumpReader : public RtpFileReaderImpl {
116 public: 116 public:
117 RtpDumpReader() : file_(NULL) {} 117 RtpDumpReader() : file_(nullptr) {}
118 virtual ~RtpDumpReader() { 118 virtual ~RtpDumpReader() {
119 if (file_ != NULL) { 119 if (file_ != nullptr) {
120 fclose(file_); 120 fclose(file_);
121 file_ = NULL; 121 file_ = nullptr;
122 } 122 }
123 } 123 }
124 124
125 bool Init(const std::string& filename, 125 bool Init(const std::string& filename,
126 const std::set<uint32_t>& ssrc_filter) override { 126 const std::set<uint32_t>& ssrc_filter) override {
127 file_ = fopen(filename.c_str(), "rb"); 127 file_ = fopen(filename.c_str(), "rb");
128 if (file_ == NULL) { 128 if (file_ == nullptr) {
129 printf("ERROR: Can't open file: %s\n", filename.c_str()); 129 printf("ERROR: Can't open file: %s\n", filename.c_str());
130 return false; 130 return false;
131 } 131 }
132 132
133 char firstline[kFirstLineLength + 1] = {0}; 133 char firstline[kFirstLineLength + 1] = {0};
134 if (fgets(firstline, kFirstLineLength, file_) == NULL) { 134 if (fgets(firstline, kFirstLineLength, file_) == nullptr) {
135 LOG(LS_INFO) << "Can't read from file"; 135 LOG(LS_INFO) << "Can't read from file";
136 return false; 136 return false;
137 } 137 }
138 if (strncmp(firstline, "#!rtpplay", 9) == 0) { 138 if (strncmp(firstline, "#!rtpplay", 9) == 0) {
139 if (strncmp(firstline, "#!rtpplay1.0", 12) != 0) { 139 if (strncmp(firstline, "#!rtpplay1.0", 12) != 0) {
140 LOG(LS_INFO) << "Wrong rtpplay version, must be 1.0"; 140 LOG(LS_INFO) << "Wrong rtpplay version, must be 1.0";
141 return false; 141 return false;
142 } 142 }
143 } else if (strncmp(firstline, "#!RTPencode", 11) == 0) { 143 } else if (strncmp(firstline, "#!RTPencode", 11) == 0) {
144 if (strncmp(firstline, "#!RTPencode1.0", 14) != 0) { 144 if (strncmp(firstline, "#!RTPencode1.0", 14) != 0) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } else if (r == kResultSkip) { \ 234 } else if (r == kResultSkip) { \
235 return kResultSkip; \ 235 return kResultSkip; \
236 } \ 236 } \
237 } while (0) 237 } while (0)
238 238
239 // Read RTP packets from file in tcpdump/libpcap format, as documented at: 239 // Read RTP packets from file in tcpdump/libpcap format, as documented at:
240 // http://wiki.wireshark.org/Development/LibpcapFileFormat 240 // http://wiki.wireshark.org/Development/LibpcapFileFormat
241 class PcapReader : public RtpFileReaderImpl { 241 class PcapReader : public RtpFileReaderImpl {
242 public: 242 public:
243 PcapReader() 243 PcapReader()
244 : file_(NULL), 244 : file_(nullptr),
245 swap_pcap_byte_order_(false), 245 swap_pcap_byte_order_(false),
246 #ifdef WEBRTC_ARCH_BIG_ENDIAN 246 #ifdef WEBRTC_ARCH_BIG_ENDIAN
247 swap_network_byte_order_(false), 247 swap_network_byte_order_(false),
248 #else 248 #else
249 swap_network_byte_order_(true), 249 swap_network_byte_order_(true),
250 #endif 250 #endif
251 read_buffer_(), 251 read_buffer_(),
252 packets_by_ssrc_(), 252 packets_by_ssrc_(),
253 packets_(), 253 packets_(),
254 next_packet_it_() { 254 next_packet_it_() {
255 } 255 }
256 256
257 virtual ~PcapReader() { 257 virtual ~PcapReader() {
258 if (file_ != NULL) { 258 if (file_ != nullptr) {
259 fclose(file_); 259 fclose(file_);
260 file_ = NULL; 260 file_ = nullptr;
261 } 261 }
262 } 262 }
263 263
264 bool Init(const std::string& filename, 264 bool Init(const std::string& filename,
265 const std::set<uint32_t>& ssrc_filter) override { 265 const std::set<uint32_t>& ssrc_filter) override {
266 return Initialize(filename, ssrc_filter) == kResultSuccess; 266 return Initialize(filename, ssrc_filter) == kResultSuccess;
267 } 267 }
268 268
269 int Initialize(const std::string& filename, 269 int Initialize(const std::string& filename,
270 const std::set<uint32_t>& ssrc_filter) { 270 const std::set<uint32_t>& ssrc_filter) {
271 file_ = fopen(filename.c_str(), "rb"); 271 file_ = fopen(filename.c_str(), "rb");
272 if (file_ == NULL) { 272 if (file_ == nullptr) {
273 printf("ERROR: Can't open file: %s\n", filename.c_str()); 273 printf("ERROR: Can't open file: %s\n", filename.c_str());
274 return kResultFail; 274 return kResultFail;
275 } 275 }
276 276
277 if (ReadGlobalHeader() < 0) { 277 if (ReadGlobalHeader() < 0) {
278 return kResultFail; 278 return kResultFail;
279 } 279 }
280 280
281 int total_packet_count = 0; 281 int total_packet_count = 0;
282 uint32_t stream_start_ms = 0; 282 uint32_t stream_start_ms = 0;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 401
402 int32_t this_zone; // GMT to local correction. 402 int32_t this_zone; // GMT to local correction.
403 uint32_t sigfigs; // Accuracy of timestamps. 403 uint32_t sigfigs; // Accuracy of timestamps.
404 uint32_t snaplen; // Max length of captured packets, in octets. 404 uint32_t snaplen; // Max length of captured packets, in octets.
405 uint32_t network; // Data link type. 405 uint32_t network; // Data link type.
406 TRY_PCAP(Read(&this_zone, false)); 406 TRY_PCAP(Read(&this_zone, false));
407 TRY_PCAP(Read(&sigfigs, false)); 407 TRY_PCAP(Read(&sigfigs, false));
408 TRY_PCAP(Read(&snaplen, false)); 408 TRY_PCAP(Read(&snaplen, false));
409 TRY_PCAP(Read(&network, false)); 409 TRY_PCAP(Read(&network, false));
410 410
411 // Accept only LINKTYPE_NULL and LINKTYPE_ETHERNET. 411 // Accept only LINKTYPE_null and LINKTYPE_ETHERNET.
412 // See: http://www.tcpdump.org/linktypes.html 412 // See: http://www.tcpdump.org/linktypes.html
413 if (network != kLinktypeNull && network != kLinktypeEthernet) { 413 if (network != kLinktypeNull && network != kLinktypeEthernet) {
414 return kResultFail; 414 return kResultFail;
415 } 415 }
416 416
417 return kResultSuccess; 417 return kResultSuccess;
418 } 418 }
419 419
420 int ReadPacket(int32_t* next_packet_pos, 420 int ReadPacket(int32_t* next_packet_pos,
421 uint32_t stream_start_ms, 421 uint32_t stream_start_ms,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 SsrcMap packets_by_ssrc_; 632 SsrcMap packets_by_ssrc_;
633 std::vector<RtpPacketMarker> packets_; 633 std::vector<RtpPacketMarker> packets_;
634 PacketIterator next_packet_it_; 634 PacketIterator next_packet_it_;
635 635
636 RTC_DISALLOW_COPY_AND_ASSIGN(PcapReader); 636 RTC_DISALLOW_COPY_AND_ASSIGN(PcapReader);
637 }; 637 };
638 638
639 RtpFileReader* RtpFileReader::Create(FileFormat format, 639 RtpFileReader* RtpFileReader::Create(FileFormat format,
640 const std::string& filename, 640 const std::string& filename,
641 const std::set<uint32_t>& ssrc_filter) { 641 const std::set<uint32_t>& ssrc_filter) {
642 RtpFileReaderImpl* reader = NULL; 642 RtpFileReaderImpl* reader = nullptr;
643 switch (format) { 643 switch (format) {
644 case kPcap: 644 case kPcap:
645 reader = new PcapReader(); 645 reader = new PcapReader();
646 break; 646 break;
647 case kRtpDump: 647 case kRtpDump:
648 reader = new RtpDumpReader(); 648 reader = new RtpDumpReader();
649 break; 649 break;
650 case kLengthPacketInterleaved: 650 case kLengthPacketInterleaved:
651 reader = new InterleavedRtpFileReader(); 651 reader = new InterleavedRtpFileReader();
652 break; 652 break;
653 } 653 }
654 if (!reader->Init(filename, ssrc_filter)) { 654 if (!reader->Init(filename, ssrc_filter)) {
655 delete reader; 655 delete reader;
656 return NULL; 656 return nullptr;
657 } 657 }
658 return reader; 658 return reader;
659 } 659 }
660 660
661 RtpFileReader* RtpFileReader::Create(FileFormat format, 661 RtpFileReader* RtpFileReader::Create(FileFormat format,
662 const std::string& filename) { 662 const std::string& filename) {
663 return RtpFileReader::Create(format, filename, std::set<uint32_t>()); 663 return RtpFileReader::Create(format, filename, std::set<uint32_t>());
664 } 664 }
665 665
666 } // namespace test 666 } // namespace test
667 } // namespace webrtc 667 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698