2014-04-14 18:42:23 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/neteq/tools/rtp_file_source.h"
|
2014-04-14 18:42:23 +00:00
|
|
|
|
|
|
|
|
#include <string.h>
|
2022-07-20 12:53:07 +02:00
|
|
|
|
|
|
|
|
#include "absl/strings/string_view.h"
|
2018-03-30 13:48:43 +02:00
|
|
|
#ifndef WIN32
|
2014-04-14 18:42:23 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-14 09:28:33 -08:00
|
|
|
#include <memory>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/neteq/tools/packet.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "test/rtp_file_reader.h"
|
2014-04-14 18:42:23 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2022-07-20 12:53:07 +02:00
|
|
|
RtpFileSource* RtpFileSource::Create(absl::string_view file_name,
|
2018-10-11 16:51:23 +02:00
|
|
|
absl::optional<uint32_t> ssrc_filter) {
|
|
|
|
|
RtpFileSource* source = new RtpFileSource(ssrc_filter);
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK(source->OpenFile(file_name));
|
2014-04-14 18:42:23 +00:00
|
|
|
return source;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-20 12:53:07 +02:00
|
|
|
bool RtpFileSource::ValidRtpDump(absl::string_view file_name) {
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<RtpFileReader> temp_file(
|
2015-11-03 00:32:09 -08:00
|
|
|
RtpFileReader::Create(RtpFileReader::kRtpDump, file_name));
|
|
|
|
|
return !!temp_file;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-20 12:53:07 +02:00
|
|
|
bool RtpFileSource::ValidPcap(absl::string_view file_name) {
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<RtpFileReader> temp_file(
|
2015-11-03 00:32:09 -08:00
|
|
|
RtpFileReader::Create(RtpFileReader::kPcap, file_name));
|
|
|
|
|
return !!temp_file;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 18:42:23 +00:00
|
|
|
RtpFileSource::~RtpFileSource() {}
|
|
|
|
|
|
|
|
|
|
bool RtpFileSource::RegisterRtpHeaderExtension(RTPExtensionType type,
|
|
|
|
|
uint8_t id) {
|
2019-08-29 16:39:05 +02:00
|
|
|
return rtp_header_extension_map_.RegisterByType(id, type);
|
2014-04-14 18:42:23 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-24 22:50:47 -07:00
|
|
|
std::unique_ptr<Packet> RtpFileSource::NextPacket() {
|
2014-10-02 08:19:38 +00:00
|
|
|
while (true) {
|
2014-11-26 15:50:30 +00:00
|
|
|
RtpPacket temp_packet;
|
2014-10-02 08:19:38 +00:00
|
|
|
if (!rtp_reader_->NextPacket(&temp_packet)) {
|
2014-06-18 12:20:31 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2015-09-18 01:28:05 -07:00
|
|
|
if (temp_packet.original_length == 0) {
|
2014-06-18 12:20:31 +00:00
|
|
|
// May be an RTCP packet.
|
|
|
|
|
// Read the next one.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-09-17 17:06:18 +02:00
|
|
|
auto packet = std::make_unique<Packet>(
|
2021-06-16 14:23:22 +02:00
|
|
|
rtc::CopyOnWriteBuffer(temp_packet.data, temp_packet.length),
|
|
|
|
|
temp_packet.original_length, temp_packet.time_ms,
|
2019-08-29 16:39:05 +02:00
|
|
|
&rtp_header_extension_map_);
|
2014-06-18 12:20:31 +00:00
|
|
|
if (!packet->valid_header()) {
|
Fix a bug in RtcEventLogSource
A recent change (https://codereview.webrtc.org/2855143002/) introduced
a bug in RtcEventLogSource::NextPacket(). The rtp_packet_index_ must
be incremented when a valid packet is found and delivered. Otherwise,
the same packet will be delivered over and over again.
The recent change also altered the way that audio packets are sifted out. Now, the RTP header is always parsed before discarding any non-audio packets. This means that RtpHeaderParser::Parse is always called, also with video packets, which sometimes contain padding. When header-only dumps (such as RtcEventLogs) are created, the payload is stripped, and the payload length is equal to
the RTP header length. However, if the original packet was padded, the
RTP header will carry information about this padding length, and the
parser will check that the pyaload length is at least the header +
padding. This is not the case for header-only dumps, and the parser will return an error. In this CL, we ignore that error when a header-only packet has padding length larger than 0.
BUG=webrtc:7538
Review-Url: https://codereview.webrtc.org/2912323003
Cr-Commit-Position: refs/heads/master@{#18385}
2017-06-01 07:41:11 -07:00
|
|
|
continue;
|
2014-06-18 12:20:31 +00:00
|
|
|
}
|
2014-10-02 08:19:38 +00:00
|
|
|
if (filter_.test(packet->header().payloadType) ||
|
2018-10-11 16:51:23 +02:00
|
|
|
(ssrc_filter_ && packet->header().ssrc != *ssrc_filter_)) {
|
2014-06-26 19:07:04 +00:00
|
|
|
// This payload type should be filtered out. Continue to the next packet.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-05-24 22:50:47 -07:00
|
|
|
return packet;
|
2014-04-14 18:42:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-11 16:51:23 +02:00
|
|
|
RtpFileSource::RtpFileSource(absl::optional<uint32_t> ssrc_filter)
|
|
|
|
|
: PacketSource(), ssrc_filter_(ssrc_filter) {}
|
2014-04-14 18:42:23 +00:00
|
|
|
|
2022-07-20 12:53:07 +02:00
|
|
|
bool RtpFileSource::OpenFile(absl::string_view file_name) {
|
2014-10-02 08:19:38 +00:00
|
|
|
rtp_reader_.reset(RtpFileReader::Create(RtpFileReader::kRtpDump, file_name));
|
|
|
|
|
if (rtp_reader_)
|
|
|
|
|
return true;
|
|
|
|
|
rtp_reader_.reset(RtpFileReader::Create(RtpFileReader::kPcap, file_name));
|
|
|
|
|
if (!rtp_reader_) {
|
2020-11-17 14:50:54 +01:00
|
|
|
RTC_FATAL()
|
|
|
|
|
<< "Couldn't open input file as either a rtpdump or .pcap. Note "
|
|
|
|
|
<< "that .pcapng is not supported.";
|
2014-04-14 18:42:23 +00:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|