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

Side by Side Diff: webrtc/modules/audio_coding/neteq/tools/rtp_file_source.cc

Issue 2005873002: Let PacketSource::NextPacket() return an std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 6 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/modules/audio_coding/neteq/tools/rtp_file_source.h ('k') | no next file » | 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) 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 RtpFileSource::~RtpFileSource() { 49 RtpFileSource::~RtpFileSource() {
50 } 50 }
51 51
52 bool RtpFileSource::RegisterRtpHeaderExtension(RTPExtensionType type, 52 bool RtpFileSource::RegisterRtpHeaderExtension(RTPExtensionType type,
53 uint8_t id) { 53 uint8_t id) {
54 assert(parser_.get()); 54 assert(parser_.get());
55 return parser_->RegisterRtpHeaderExtension(type, id); 55 return parser_->RegisterRtpHeaderExtension(type, id);
56 } 56 }
57 57
58 Packet* RtpFileSource::NextPacket() { 58 std::unique_ptr<Packet> RtpFileSource::NextPacket() {
59 while (true) { 59 while (true) {
60 RtpPacket temp_packet; 60 RtpPacket temp_packet;
61 if (!rtp_reader_->NextPacket(&temp_packet)) { 61 if (!rtp_reader_->NextPacket(&temp_packet)) {
62 return NULL; 62 return NULL;
63 } 63 }
64 if (temp_packet.original_length == 0) { 64 if (temp_packet.original_length == 0) {
65 // May be an RTCP packet. 65 // May be an RTCP packet.
66 // Read the next one. 66 // Read the next one.
67 continue; 67 continue;
68 } 68 }
69 std::unique_ptr<uint8_t[]> packet_memory(new uint8_t[temp_packet.length]); 69 std::unique_ptr<uint8_t[]> packet_memory(new uint8_t[temp_packet.length]);
70 memcpy(packet_memory.get(), temp_packet.data, temp_packet.length); 70 memcpy(packet_memory.get(), temp_packet.data, temp_packet.length);
71 std::unique_ptr<Packet> packet(new Packet( 71 std::unique_ptr<Packet> packet(new Packet(
72 packet_memory.release(), temp_packet.length, 72 packet_memory.release(), temp_packet.length,
73 temp_packet.original_length, temp_packet.time_ms, *parser_.get())); 73 temp_packet.original_length, temp_packet.time_ms, *parser_.get()));
74 if (!packet->valid_header()) { 74 if (!packet->valid_header()) {
75 assert(false); 75 assert(false);
76 return NULL; 76 return NULL;
77 } 77 }
78 if (filter_.test(packet->header().payloadType) || 78 if (filter_.test(packet->header().payloadType) ||
79 (use_ssrc_filter_ && packet->header().ssrc != ssrc_)) { 79 (use_ssrc_filter_ && packet->header().ssrc != ssrc_)) {
80 // This payload type should be filtered out. Continue to the next packet. 80 // This payload type should be filtered out. Continue to the next packet.
81 continue; 81 continue;
82 } 82 }
83 return packet.release(); 83 return packet;
84 } 84 }
85 } 85 }
86 86
87 RtpFileSource::RtpFileSource() 87 RtpFileSource::RtpFileSource()
88 : PacketSource(), 88 : PacketSource(),
89 parser_(RtpHeaderParser::Create()) {} 89 parser_(RtpHeaderParser::Create()) {}
90 90
91 bool RtpFileSource::OpenFile(const std::string& file_name) { 91 bool RtpFileSource::OpenFile(const std::string& file_name) {
92 rtp_reader_.reset(RtpFileReader::Create(RtpFileReader::kRtpDump, file_name)); 92 rtp_reader_.reset(RtpFileReader::Create(RtpFileReader::kRtpDump, file_name));
93 if (rtp_reader_) 93 if (rtp_reader_)
94 return true; 94 return true;
95 rtp_reader_.reset(RtpFileReader::Create(RtpFileReader::kPcap, file_name)); 95 rtp_reader_.reset(RtpFileReader::Create(RtpFileReader::kPcap, file_name));
96 if (!rtp_reader_) { 96 if (!rtp_reader_) {
97 FATAL() << "Couldn't open input file as either a rtpdump or .pcap. Note " 97 FATAL() << "Couldn't open input file as either a rtpdump or .pcap. Note "
98 "that .pcapng is not supported."; 98 "that .pcapng is not supported.";
99 } 99 }
100 return true; 100 return true;
101 } 101 }
102 102
103 } // namespace test 103 } // namespace test
104 } // namespace webrtc 104 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698