diff --git a/BUILD.gn b/BUILD.gn index c889955538..418ff1ba83 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -52,6 +52,7 @@ if (!build_with_chromium) { "modules:modules_unittests", "modules/audio_coding:audio_coding_tests", "modules/audio_processing:audio_processing_tests", + "modules/remote_bitrate_estimator:rtp_to_text", "modules/rtp_rtcp:test_packet_masks_metrics", "modules/video_capture:video_capture_internal_impl", "pc:peerconnection_unittests", diff --git a/modules/remote_bitrate_estimator/BUILD.gn b/modules/remote_bitrate_estimator/BUILD.gn index 65b46ba9c8..d6fe053b3c 100644 --- a/modules/remote_bitrate_estimator/BUILD.gn +++ b/modules/remote_bitrate_estimator/BUILD.gn @@ -75,6 +75,22 @@ if (!build_with_chromium) { "../../rtc_base:rtc_base_approved", "../../test:rtp_test_utils", "../rtp_rtcp", + "//third_party/abseil-cpp/absl/flags:flag", + "//third_party/abseil-cpp/absl/flags:parse", + ] + } + + rtc_executable("rtp_to_text") { + testonly = true + sources = [ + "tools/rtp_to_text.cc", + ] + deps = [ + ":bwe_rtp", + "../../modules/rtp_rtcp", + "../../rtc_base:macromagic", + "../../rtc_base:stringutils", + "../../test:rtp_test_utils", ] } } diff --git a/modules/remote_bitrate_estimator/tools/bwe_rtp.cc b/modules/remote_bitrate_estimator/tools/bwe_rtp.cc index 0e435ebe68..aa60b15388 100644 --- a/modules/remote_bitrate_estimator/tools/bwe_rtp.cc +++ b/modules/remote_bitrate_estimator/tools/bwe_rtp.cc @@ -16,40 +16,39 @@ #include #include +#include "absl/flags/flag.h" +#include "absl/flags/parse.h" #include "modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h" #include "modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h" #include "modules/rtp_rtcp/include/rtp_header_parser.h" -#include "rtc_base/flags.h" #include "test/rtp_file_reader.h" -namespace flags { - -WEBRTC_DEFINE_string( - extension_type, - "abs", - "Extension type, either abs for absolute send time or tsoffset " - "for timestamp offset."); +ABSL_FLAG(std::string, + extension_type, + "abs", + "Extension type, either abs for absolute send time or tsoffset " + "for timestamp offset."); std::string ExtensionType() { - return static_cast(FLAG_extension_type); + return absl::GetFlag(FLAGS_extension_type); } -WEBRTC_DEFINE_int(extension_id, 3, "Extension id."); +ABSL_FLAG(int, extension_id, 3, "Extension id."); int ExtensionId() { - return static_cast(FLAG_extension_id); + return absl::GetFlag(FLAGS_extension_id); } -WEBRTC_DEFINE_string(input_file, "", "Input file."); +ABSL_FLAG(std::string, input_file, "", "Input file."); std::string InputFile() { - return static_cast(FLAG_input_file); + return absl::GetFlag(FLAGS_input_file); } -WEBRTC_DEFINE_string( - ssrc_filter, - "", - "Comma-separated list of SSRCs in hexadecimal which are to be " - "used as input to the BWE (only applicable to pcap files)."); +ABSL_FLAG(std::string, + ssrc_filter, + "", + "Comma-separated list of SSRCs in hexadecimal which are to be " + "used as input to the BWE (only applicable to pcap files)."); std::set SsrcFilter() { - std::string ssrc_filter_string = static_cast(FLAG_ssrc_filter); + std::string ssrc_filter_string = absl::GetFlag(FLAGS_ssrc_filter); if (ssrc_filter_string.empty()) return std::set(); std::stringstream ss; @@ -66,9 +65,6 @@ std::set SsrcFilter() { return ssrcs; } -WEBRTC_DEFINE_bool(help, false, "Print this message."); -} // namespace flags - bool ParseArgsAndSetupEstimator(int argc, char** argv, webrtc::Clock* clock, @@ -77,16 +73,10 @@ bool ParseArgsAndSetupEstimator(int argc, webrtc::RtpHeaderParser** parser, webrtc::RemoteBitrateEstimator** estimator, std::string* estimator_used) { - if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) { - return 1; - } - if (flags::FLAG_help) { - rtc::FlagList::Print(nullptr, false); - return 0; - } - std::string filename = flags::InputFile(); + absl::ParseCommandLine(argc, argv); + std::string filename = InputFile(); - std::set ssrc_filter = flags::SsrcFilter(); + std::set ssrc_filter = SsrcFilter(); fprintf(stderr, "Filter on SSRC: "); for (auto& s : ssrc_filter) { fprintf(stderr, "0x%08x, ", s); @@ -95,8 +85,7 @@ bool ParseArgsAndSetupEstimator(int argc, if (filename.substr(filename.find_last_of('.')) == ".pcap") { fprintf(stderr, "Opening as pcap\n"); *rtp_reader = webrtc::test::RtpFileReader::Create( - webrtc::test::RtpFileReader::kPcap, filename.c_str(), - flags::SsrcFilter()); + webrtc::test::RtpFileReader::kPcap, filename.c_str(), SsrcFilter()); } else { fprintf(stderr, "Opening as rtp\n"); *rtp_reader = webrtc::test::RtpFileReader::Create( @@ -109,10 +98,10 @@ bool ParseArgsAndSetupEstimator(int argc, fprintf(stderr, "Input file: %s\n\n", filename.c_str()); webrtc::RTPExtensionType extension = webrtc::kRtpExtensionAbsoluteSendTime; - if (flags::ExtensionType() == "tsoffset") { + if (ExtensionType() == "tsoffset") { extension = webrtc::kRtpExtensionTransmissionTimeOffset; fprintf(stderr, "Extension: toffset\n"); - } else if (flags::ExtensionType() == "abs") { + } else if (ExtensionType() == "abs") { fprintf(stderr, "Extension: abs\n"); } else { fprintf(stderr, "Unknown extension type\n"); @@ -121,7 +110,7 @@ bool ParseArgsAndSetupEstimator(int argc, // Setup the RTP header parser and the bitrate estimator. *parser = webrtc::RtpHeaderParser::Create(); - (*parser)->RegisterRtpHeaderExtension(extension, flags::ExtensionId()); + (*parser)->RegisterRtpHeaderExtension(extension, ExtensionId()); if (estimator) { switch (extension) { case webrtc::kRtpExtensionAbsoluteSendTime: { diff --git a/modules/remote_bitrate_estimator/tools/bwe_rtp_play.cc b/modules/remote_bitrate_estimator/tools/bwe_rtp_play.cc deleted file mode 100644 index dac50ec387..0000000000 --- a/modules/remote_bitrate_estimator/tools/bwe_rtp_play.cc +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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. - */ - -#include - -#include - -#include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" -#include "modules/remote_bitrate_estimator/tools/bwe_rtp.h" -#include "modules/rtp_rtcp/include/rtp_header_parser.h" -#include "rtc_base/format_macros.h" -#include "test/rtp_file_reader.h" - -class Observer : public webrtc::RemoteBitrateObserver { - public: - explicit Observer(webrtc::Clock* clock) : clock_(clock) {} - - // Called when a receive channel group has a new bitrate estimate for the - // incoming streams. - virtual void OnReceiveBitrateChanged(const std::vector& ssrcs, - uint32_t bitrate) { - printf("[%u] Num SSRCs: %d, bitrate: %u\n", - static_cast(clock_->TimeInMilliseconds()), - static_cast(ssrcs.size()), bitrate); - } - - virtual ~Observer() {} - - private: - webrtc::Clock* clock_; -}; - -int main(int argc, char* argv[]) { - webrtc::test::RtpFileReader* reader; - webrtc::RemoteBitrateEstimator* estimator; - webrtc::RtpHeaderParser* parser; - std::string estimator_used; - webrtc::SimulatedClock clock(0); - Observer observer(&clock); - if (!ParseArgsAndSetupEstimator(argc, argv, &clock, &observer, &reader, - &parser, &estimator, &estimator_used)) { - return -1; - } - std::unique_ptr rtp_reader(reader); - std::unique_ptr rtp_parser(parser); - std::unique_ptr rbe(estimator); - - // Process the file. - int packet_counter = 0; - int64_t next_rtp_time_ms = 0; - int64_t first_rtp_time_ms = -1; - int abs_send_time_count = 0; - int ts_offset_count = 0; - webrtc::test::RtpPacket packet; - if (!rtp_reader->NextPacket(&packet)) { - printf("No RTP packet found\n"); - return 0; - } - first_rtp_time_ms = packet.time_ms; - packet.time_ms = packet.time_ms - first_rtp_time_ms; - while (true) { - if (next_rtp_time_ms <= clock.TimeInMilliseconds()) { - if (!parser->IsRtcp(packet.data, packet.length)) { - webrtc::RTPHeader header; - parser->Parse(packet.data, packet.length, &header); - if (header.extension.hasAbsoluteSendTime) - ++abs_send_time_count; - if (header.extension.hasTransmissionTimeOffset) - ++ts_offset_count; - size_t packet_length = packet.length; - // Some RTP dumps only include the header, in which case packet.length - // is equal to the header length. In those cases packet.original_length - // usually contains the original packet length. - if (packet.original_length > 0) { - packet_length = packet.original_length; - } - rbe->IncomingPacket(clock.TimeInMilliseconds(), - packet_length - header.headerLength, header); - ++packet_counter; - } - if (!rtp_reader->NextPacket(&packet)) { - break; - } - packet.time_ms = packet.time_ms - first_rtp_time_ms; - next_rtp_time_ms = packet.time_ms; - } - int64_t time_until_process_ms = rbe->TimeUntilNextProcess(); - if (time_until_process_ms <= 0) { - rbe->Process(); - } - int64_t time_until_next_event = - std::min(rbe->TimeUntilNextProcess(), - next_rtp_time_ms - clock.TimeInMilliseconds()); - clock.AdvanceTimeMilliseconds(std::max(time_until_next_event, 0)); - } - printf("Parsed %d packets\nTime passed: %" PRId64 " ms\n", packet_counter, - clock.TimeInMilliseconds()); - printf("Estimator used: %s\n", estimator_used.c_str()); - printf("Packets with absolute send time: %d\n", abs_send_time_count); - printf("Packets with timestamp offset: %d\n", ts_offset_count); - printf("Packets with no extension: %d\n", - packet_counter - ts_offset_count - abs_send_time_count); - return 0; -}