Chromium Code Reviews| 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 while (!ssrc_filter.empty()) { | |
| 60 ss << std::hex << ssrc_filter; | |
| 61 uint32_t ssrc; | |
| 62 ss >> ssrc; | |
| 63 ssrcs.insert(ssrc); | |
| 64 size_t pos = ssrc_filter.find(","); | |
| 65 if (pos == std::string::npos || pos + 1 >= ssrc_filter.size()) | |
| 66 break; | |
| 67 ssrc_filter = ssrc_filter.substr(pos + 1); | |
| 68 ss.str(""); | |
| 69 } | |
| 70 return ssrcs; | |
| 71 } | |
| 72 } // namespace flags | |
| 73 | |
| 24 bool ParseArgsAndSetupEstimator(int argc, | 74 bool ParseArgsAndSetupEstimator(int argc, |
| 25 char** argv, | 75 char** argv, |
| 26 webrtc::Clock* clock, | 76 webrtc::Clock* clock, |
| 27 webrtc::RemoteBitrateObserver* observer, | 77 webrtc::RemoteBitrateObserver* observer, |
| 28 webrtc::test::RtpFileReader** rtp_reader, | 78 webrtc::test::RtpFileReader** rtp_reader, |
| 29 webrtc::RtpHeaderParser** parser, | 79 webrtc::RtpHeaderParser** parser, |
| 30 webrtc::RemoteBitrateEstimator** estimator, | 80 webrtc::RemoteBitrateEstimator** estimator, |
| 31 std::string* estimator_used) { | 81 std::string* estimator_used) { |
| 32 *rtp_reader = webrtc::test::RtpFileReader::Create( | 82 google::ParseCommandLineFlags(&argc, &argv, true); |
| 33 webrtc::test::RtpFileReader::kRtpDump, argv[3]); | 83 std::string filename = flags::InputFile(); |
| 84 | |
| 85 std::set<uint32_t> ssrc_filter = flags::SsrcFilter(); | |
| 86 fprintf(stderr, "Filter on SSRC: "); | |
| 87 for (auto& s : ssrc_filter) { | |
| 88 fprintf(stderr, "0x%08x, ", s); | |
| 89 } | |
| 90 fprintf(stderr, "\n"); | |
| 91 if (filename.substr(filename.find_last_of(".") + 1).substr(0, 4) == "pcap") { | |
|
pbos-webrtc
2015/07/15 14:50:26
filename.substr(filename.find_last_offind_last_of(
| |
| 92 fprintf(stderr, "Opening as pcap\n"); | |
| 93 *rtp_reader = webrtc::test::RtpFileReader::Create( | |
| 94 webrtc::test::RtpFileReader::kPcap, filename.c_str(), | |
| 95 flags::SsrcFilter()); | |
| 96 } else { | |
| 97 fprintf(stderr, "Opening as rtp\n"); | |
| 98 *rtp_reader = webrtc::test::RtpFileReader::Create( | |
| 99 webrtc::test::RtpFileReader::kRtpDump, filename.c_str()); | |
| 100 } | |
| 34 if (!*rtp_reader) { | 101 if (!*rtp_reader) { |
| 35 fprintf(stderr, "Cannot open input file %s\n", argv[3]); | 102 fprintf(stderr, "Cannot open input file %s\n", filename.c_str()); |
| 36 return false; | 103 return false; |
| 37 } | 104 } |
| 38 fprintf(stderr, "Input file: %s\n\n", argv[3]); | 105 fprintf(stderr, "Input file: %s\n\n", filename.c_str()); |
| 106 | |
| 39 webrtc::RTPExtensionType extension = webrtc::kRtpExtensionAbsoluteSendTime; | 107 webrtc::RTPExtensionType extension = webrtc::kRtpExtensionAbsoluteSendTime; |
| 40 | 108 if (flags::ExtensionType() == "tsoffset") { |
| 41 if (strncmp("tsoffset", argv[1], 8) == 0) { | |
| 42 extension = webrtc::kRtpExtensionTransmissionTimeOffset; | 109 extension = webrtc::kRtpExtensionTransmissionTimeOffset; |
| 43 fprintf(stderr, "Extension: toffset\n"); | 110 fprintf(stderr, "Extension: toffset\n"); |
| 111 } else if (flags::ExtensionType() == "abs") { | |
| 112 fprintf(stderr, "Extension: abs\n"); | |
| 44 } else { | 113 } else { |
| 45 fprintf(stderr, "Extension: abs\n"); | 114 fprintf(stderr, "Unknown extension type\n"); |
| 115 return false; | |
| 46 } | 116 } |
| 47 int id = atoi(argv[2]); | |
| 48 | 117 |
| 49 // Setup the RTP header parser and the bitrate estimator. | 118 // Setup the RTP header parser and the bitrate estimator. |
| 50 *parser = webrtc::RtpHeaderParser::Create(); | 119 *parser = webrtc::RtpHeaderParser::Create(); |
| 51 (*parser)->RegisterRtpHeaderExtension(extension, id); | 120 (*parser)->RegisterRtpHeaderExtension(extension, flags::ExtensionId()); |
| 52 if (estimator) { | 121 if (estimator) { |
| 53 switch (extension) { | 122 switch (extension) { |
| 54 case webrtc::kRtpExtensionAbsoluteSendTime: { | 123 case webrtc::kRtpExtensionAbsoluteSendTime: { |
| 55 *estimator = new webrtc::RemoteBitrateEstimatorAbsSendTime( | 124 *estimator = new webrtc::RemoteBitrateEstimatorAbsSendTime( |
| 56 observer, clock, kMinBitrateBps); | 125 observer, clock, kMinBitrateBps); |
| 57 *estimator_used = "AbsoluteSendTimeRemoteBitrateEstimator"; | 126 *estimator_used = "AbsoluteSendTimeRemoteBitrateEstimator"; |
| 58 break; | 127 break; |
| 59 } | 128 } |
| 60 case webrtc::kRtpExtensionTransmissionTimeOffset: { | 129 case webrtc::kRtpExtensionTransmissionTimeOffset: { |
| 61 *estimator = new webrtc::RemoteBitrateEstimatorSingleStream( | 130 *estimator = new webrtc::RemoteBitrateEstimatorSingleStream( |
| 62 observer, clock, kMinBitrateBps); | 131 observer, clock, kMinBitrateBps); |
| 63 *estimator_used = "RemoteBitrateEstimator"; | 132 *estimator_used = "RemoteBitrateEstimator"; |
| 64 break; | 133 break; |
| 65 } | 134 } |
| 66 default: | 135 default: |
| 67 assert(false); | 136 assert(false); |
| 68 } | 137 } |
| 69 } | 138 } |
| 70 return true; | 139 return true; |
| 71 } | 140 } |
| OLD | NEW |