1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "modules/remote_bitrate_estimator/tools/bwe_rtp.h"
12
13 #include <stdio.h>
14
15 #include <set>
16 #include <sstream>
17 #include <string>
18
19 #include "absl/flags/flag.h"
20 #include "absl/flags/parse.h"
21 #include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
22 #include "test/rtp_file_reader.h"
23
24 ABSL_FLAG(std::string,
25 extension_type,
26 "abs",
27 "Extension type, either abs for absolute send time or tsoffset "
28 "for timestamp offset.");
ExtensionType()29 std::string ExtensionType() {
30 return absl::GetFlag(FLAGS_extension_type);
31 }
32
33 ABSL_FLAG(int, extension_id, 3, "Extension id.");
ExtensionId()34 int ExtensionId() {
35 return absl::GetFlag(FLAGS_extension_id);
36 }
37
38 ABSL_FLAG(std::string, input_file, "", "Input file.");
InputFile()39 std::string InputFile() {
40 return absl::GetFlag(FLAGS_input_file);
41 }
42
43 ABSL_FLAG(std::string,
44 ssrc_filter,
45 "",
46 "Comma-separated list of SSRCs in hexadecimal which are to be "
47 "used as input to the BWE (only applicable to pcap files).");
SsrcFilter()48 std::set<uint32_t> SsrcFilter() {
49 std::string ssrc_filter_string = absl::GetFlag(FLAGS_ssrc_filter);
50 if (ssrc_filter_string.empty())
51 return std::set<uint32_t>();
52 std::stringstream ss;
53 std::string ssrc_filter = ssrc_filter_string;
54 std::set<uint32_t> ssrcs;
55
56 // Parse the ssrcs in hexadecimal format.
57 ss << std::hex << ssrc_filter;
58 uint32_t ssrc;
59 while (ss >> ssrc) {
60 ssrcs.insert(ssrc);
61 ss.ignore(1, ',');
62 }
63 return ssrcs;
64 }
65
ParseArgsAndSetupRtpReader(int argc,char ** argv,std::unique_ptr<webrtc::test::RtpFileReader> & rtp_reader,webrtc::RtpHeaderExtensionMap & rtp_header_extensions)66 bool ParseArgsAndSetupRtpReader(
67 int argc,
68 char** argv,
69 std::unique_ptr<webrtc::test::RtpFileReader>& rtp_reader,
70 webrtc::RtpHeaderExtensionMap& rtp_header_extensions) {
71 absl::ParseCommandLine(argc, argv);
72 std::string filename = InputFile();
73
74 std::set<uint32_t> ssrc_filter = SsrcFilter();
75 fprintf(stderr, "Filter on SSRC: ");
76 for (auto& s : ssrc_filter) {
77 fprintf(stderr, "0x%08x, ", s);
78 }
79 fprintf(stderr, "\n");
80 if (filename.substr(filename.find_last_of('.')) == ".pcap") {
81 fprintf(stderr, "Opening as pcap\n");
82 rtp_reader.reset(webrtc::test::RtpFileReader::Create(
83 webrtc::test::RtpFileReader::kPcap, filename.c_str(), SsrcFilter()));
84 } else {
85 fprintf(stderr, "Opening as rtp\n");
86 rtp_reader.reset(webrtc::test::RtpFileReader::Create(
87 webrtc::test::RtpFileReader::kRtpDump, filename.c_str()));
88 }
89 if (!rtp_reader) {
90 fprintf(stderr, "Cannot open input file %s\n", filename.c_str());
91 return false;
92 }
93 fprintf(stderr, "Input file: %s\n\n", filename.c_str());
94
95 webrtc::RTPExtensionType extension = webrtc::kRtpExtensionAbsoluteSendTime;
96 if (ExtensionType() == "tsoffset") {
97 extension = webrtc::kRtpExtensionTransmissionTimeOffset;
98 fprintf(stderr, "Extension: toffset\n");
99 } else if (ExtensionType() == "abs") {
100 fprintf(stderr, "Extension: abs\n");
101 } else {
102 fprintf(stderr, "Unknown extension type\n");
103 return false;
104 }
105
106 rtp_header_extensions.RegisterByType(ExtensionId(), extension);
107
108 return true;
109 }
110