| OLD | NEW |
| 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 |
| 11 #include "webrtc/modules/remote_bitrate_estimator/tools/bwe_rtp.h" | 11 #include "webrtc/modules/remote_bitrate_estimator/tools/bwe_rtp.h" |
| 12 | 12 |
| 13 #include <sstream> |
| 13 #include <stdio.h> | 14 #include <stdio.h> |
| 14 #include <string> | 15 #include <string> |
| 15 | 16 |
| 17 #include "gflags/gflags.h" |
| 16 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s
end_time.h" | 18 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s
end_time.h" |
| 17 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl
e_stream.h" | 19 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl
e_stream.h" |
| 18 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" | 20 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
| 19 #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" | 21 #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" |
| 20 #include "webrtc/test/rtp_file_reader.h" | 22 #include "webrtc/test/rtp_file_reader.h" |
| 21 | 23 |
| 22 const int kMinBitrateBps = 30000; | 24 const int kMinBitrateBps = 30000; |
| 23 | 25 |
| 26 namespace flags { |
| 27 |
| 28 DEFINE_string(extension_type, |
| 29 "abs", |
| 30 "Extension type, either abs for absolute send time or tsoffset " |
| 31 "for timestamp offset."); |
| 32 std::string ExtensionType() { |
| 33 return static_cast<std::string>(FLAGS_extension_type); |
| 34 } |
| 35 |
| 36 DEFINE_int32(extension_id, 3, "Extension id."); |
| 37 int ExtensionId() { |
| 38 return static_cast<int>(FLAGS_extension_id); |
| 39 } |
| 40 |
| 41 DEFINE_string(input_file, "", "Input file."); |
| 42 std::string InputFile() { |
| 43 return static_cast<std::string>(FLAGS_input_file); |
| 44 } |
| 45 |
| 46 DEFINE_string(ssrc_filter, |
| 47 "", |
| 48 "Comma-separated list of SSRCs in hexadecimal which are to be " |
| 49 "used as input to the BWE (only applicable to pcap files)."); |
| 50 std::set<uint32_t> SsrcFilter() { |
| 51 std::string ssrc_filter_string = static_cast<std::string>(FLAGS_ssrc_filter); |
| 52 if (ssrc_filter_string.empty()) |
| 53 return std::set<uint32_t>(); |
| 54 std::stringstream ss; |
| 55 std::string ssrc_filter = ssrc_filter_string; |
| 56 std::set<uint32_t> ssrcs; |
| 57 |
| 58 // Parse the ssrcs in hexadecimal format. |
| 59 ss << std::hex << ssrc_filter; |
| 60 uint32_t ssrc; |
| 61 while (ss >> ssrc) { |
| 62 ssrcs.insert(ssrc); |
| 63 ss.ignore(1, ','); |
| 64 } |
| 65 return ssrcs; |
| 66 } |
| 67 } // namespace flags |
| 68 |
| 24 bool ParseArgsAndSetupEstimator(int argc, | 69 bool ParseArgsAndSetupEstimator(int argc, |
| 25 char** argv, | 70 char** argv, |
| 26 webrtc::Clock* clock, | 71 webrtc::Clock* clock, |
| 27 webrtc::RemoteBitrateObserver* observer, | 72 webrtc::RemoteBitrateObserver* observer, |
| 28 webrtc::test::RtpFileReader** rtp_reader, | 73 webrtc::test::RtpFileReader** rtp_reader, |
| 29 webrtc::RtpHeaderParser** parser, | 74 webrtc::RtpHeaderParser** parser, |
| 30 webrtc::RemoteBitrateEstimator** estimator, | 75 webrtc::RemoteBitrateEstimator** estimator, |
| 31 std::string* estimator_used) { | 76 std::string* estimator_used) { |
| 32 *rtp_reader = webrtc::test::RtpFileReader::Create( | 77 google::ParseCommandLineFlags(&argc, &argv, true); |
| 33 webrtc::test::RtpFileReader::kRtpDump, argv[3]); | 78 std::string filename = flags::InputFile(); |
| 79 |
| 80 std::set<uint32_t> ssrc_filter = flags::SsrcFilter(); |
| 81 fprintf(stderr, "Filter on SSRC: "); |
| 82 for (auto& s : ssrc_filter) { |
| 83 fprintf(stderr, "0x%08x, ", s); |
| 84 } |
| 85 fprintf(stderr, "\n"); |
| 86 if (filename.substr(filename.find_last_of(".")) == ".pcap") { |
| 87 fprintf(stderr, "Opening as pcap\n"); |
| 88 *rtp_reader = webrtc::test::RtpFileReader::Create( |
| 89 webrtc::test::RtpFileReader::kPcap, filename.c_str(), |
| 90 flags::SsrcFilter()); |
| 91 } else { |
| 92 fprintf(stderr, "Opening as rtp\n"); |
| 93 *rtp_reader = webrtc::test::RtpFileReader::Create( |
| 94 webrtc::test::RtpFileReader::kRtpDump, filename.c_str()); |
| 95 } |
| 34 if (!*rtp_reader) { | 96 if (!*rtp_reader) { |
| 35 fprintf(stderr, "Cannot open input file %s\n", argv[3]); | 97 fprintf(stderr, "Cannot open input file %s\n", filename.c_str()); |
| 36 return false; | 98 return false; |
| 37 } | 99 } |
| 38 fprintf(stderr, "Input file: %s\n\n", argv[3]); | 100 fprintf(stderr, "Input file: %s\n\n", filename.c_str()); |
| 101 |
| 39 webrtc::RTPExtensionType extension = webrtc::kRtpExtensionAbsoluteSendTime; | 102 webrtc::RTPExtensionType extension = webrtc::kRtpExtensionAbsoluteSendTime; |
| 40 | 103 if (flags::ExtensionType() == "tsoffset") { |
| 41 if (strncmp("tsoffset", argv[1], 8) == 0) { | |
| 42 extension = webrtc::kRtpExtensionTransmissionTimeOffset; | 104 extension = webrtc::kRtpExtensionTransmissionTimeOffset; |
| 43 fprintf(stderr, "Extension: toffset\n"); | 105 fprintf(stderr, "Extension: toffset\n"); |
| 106 } else if (flags::ExtensionType() == "abs") { |
| 107 fprintf(stderr, "Extension: abs\n"); |
| 44 } else { | 108 } else { |
| 45 fprintf(stderr, "Extension: abs\n"); | 109 fprintf(stderr, "Unknown extension type\n"); |
| 110 return false; |
| 46 } | 111 } |
| 47 int id = atoi(argv[2]); | |
| 48 | 112 |
| 49 // Setup the RTP header parser and the bitrate estimator. | 113 // Setup the RTP header parser and the bitrate estimator. |
| 50 *parser = webrtc::RtpHeaderParser::Create(); | 114 *parser = webrtc::RtpHeaderParser::Create(); |
| 51 (*parser)->RegisterRtpHeaderExtension(extension, id); | 115 (*parser)->RegisterRtpHeaderExtension(extension, flags::ExtensionId()); |
| 52 if (estimator) { | 116 if (estimator) { |
| 53 switch (extension) { | 117 switch (extension) { |
| 54 case webrtc::kRtpExtensionAbsoluteSendTime: { | 118 case webrtc::kRtpExtensionAbsoluteSendTime: { |
| 55 *estimator = new webrtc::RemoteBitrateEstimatorAbsSendTime( | 119 *estimator = new webrtc::RemoteBitrateEstimatorAbsSendTime( |
| 56 observer, clock, kMinBitrateBps); | 120 observer, clock, kMinBitrateBps); |
| 57 *estimator_used = "AbsoluteSendTimeRemoteBitrateEstimator"; | 121 *estimator_used = "AbsoluteSendTimeRemoteBitrateEstimator"; |
| 58 break; | 122 break; |
| 59 } | 123 } |
| 60 case webrtc::kRtpExtensionTransmissionTimeOffset: { | 124 case webrtc::kRtpExtensionTransmissionTimeOffset: { |
| 61 *estimator = new webrtc::RemoteBitrateEstimatorSingleStream( | 125 *estimator = new webrtc::RemoteBitrateEstimatorSingleStream( |
| 62 observer, clock, kMinBitrateBps); | 126 observer, clock, kMinBitrateBps); |
| 63 *estimator_used = "RemoteBitrateEstimator"; | 127 *estimator_used = "RemoteBitrateEstimator"; |
| 64 break; | 128 break; |
| 65 } | 129 } |
| 66 default: | 130 default: |
| 67 assert(false); | 131 assert(false); |
| 68 } | 132 } |
| 69 } | 133 } |
| 70 return true; | 134 return true; |
| 71 } | 135 } |
| OLD | NEW |