tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

bwe_rtp.cc (3489B)


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