2013-01-29 12:09:21 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-02-05 08:49:13 +00:00
|
|
|
// TODO(hlundin): The functionality in this file should be moved into one or
|
|
|
|
|
// several classes.
|
|
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <assert.h>
|
2014-10-07 05:30:04 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
#include <limits.h> // For ULONG_MAX returned by strtoul.
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <stdio.h>
|
2014-10-07 05:30:04 +00:00
|
|
|
#include <stdlib.h> // For strtoul.
|
2013-08-05 16:22:53 +00:00
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <iostream>
|
2016-02-14 09:28:33 -08:00
|
|
|
#include <memory>
|
2015-09-08 03:28:46 -07:00
|
|
|
#include <limits>
|
2013-01-29 12:09:21 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
2016-02-09 06:47:39 -08:00
|
|
|
#include "gflags/gflags.h"
|
2014-10-07 05:30:04 +00:00
|
|
|
#include "webrtc/base/checks.h"
|
Revert of Safe numeric library: base/numerics (copied from Chromium) (patchset #11 id:250001 of https://codereview.webrtc.org/1753293002/ )
Reason for revert:
Looks like the Chrome iOS build is broken because of these two changes. So I'm going to have to revert. Here's the error:
https://build.chromium.org/p/tryserver.chromium.mac/builders/ios_rel_device_ninja/builds/185624/steps/compile/logs/stdio
FAILED: rm -f arch/libsafe_numerics.arm64.a && ./gyp-mac-tool filter-libtool libtool -static -o arch/libsafe_numerics.arm64.a
error: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: no files specified
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
FAILED: rm -f arch/libsafe_numerics.armv7.a && ./gyp-mac-tool filter-libtool libtool -static -o arch/libsafe_numerics.armv7.a
error: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: no files specified
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
ninja: build stopped: subcommand failed.
Original issue's description:
> Safe numeric library added: base/numerics (copied from Chromium)
>
> This copies the contents (unittest excluded) of base/numerics in
> chromium to base/numerics in webrtc. Files added:
> - safe_conversions.h
> - safe_conversions_impl.h
> - safe_math.h
> - safe_math_impl.h
>
> A really old version of safe_conversions[_impl].h previously existed in
> base/, this has been deleted and sources using it have been updated
> to include the new base/numerics/safe_converions.h.
>
> This CL also adds a DEPS file to webrtc/base.
>
> NOPRESUBMIT=True
> BUG=webrtc:5548, webrtc:5623
>
> Committed: https://crrev.com/de1c81b2d2196be611674aa6019b9db3a9329042
> Cr-Commit-Position: refs/heads/master@{#11907}
TBR=kjellander@webrtc.org,kwiberg@webrtc.org,tina.legrand@webrtc.org,hbos@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5548, webrtc:5623
Review URL: https://codereview.webrtc.org/1792613002 .
Cr-Commit-Position: refs/heads/master@{#11965}
2016-03-11 17:12:32 -08:00
|
|
|
#include "webrtc/base/safe_conversions.h"
|
2016-05-25 07:37:43 -07:00
|
|
|
#include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h"
|
2015-11-18 23:07:57 +01:00
|
|
|
#include "webrtc/modules/audio_coding/codecs/pcm16b/pcm16b.h"
|
2015-10-29 11:31:02 +01:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/include/neteq.h"
|
2014-06-09 08:10:28 +00:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h"
|
2014-11-24 14:50:53 +00:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/tools/output_audio_file.h"
|
|
|
|
|
#include "webrtc/modules/audio_coding/neteq/tools/output_wav_file.h"
|
2014-08-11 12:29:38 +00:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/tools/packet.h"
|
2015-09-08 03:28:46 -07:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/tools/rtc_event_log_source.h"
|
2014-08-11 12:29:38 +00:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/include/module_common_types.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/trace.h"
|
2015-09-08 03:28:46 -07:00
|
|
|
#include "webrtc/test/rtp_file_reader.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
#include "webrtc/test/testsupport/fileutils.h"
|
|
|
|
|
#include "webrtc/typedefs.h"
|
|
|
|
|
|
2016-05-24 06:14:57 -07:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
2014-10-07 05:30:04 +00:00
|
|
|
namespace {
|
2015-01-26 19:59:32 +00:00
|
|
|
|
2014-10-07 05:30:04 +00:00
|
|
|
// Parses the input string for a valid SSRC (at the start of the string). If a
|
|
|
|
|
// valid SSRC is found, it is written to the output variable |ssrc|, and true is
|
|
|
|
|
// returned. Otherwise, false is returned.
|
|
|
|
|
bool ParseSsrc(const std::string& str, uint32_t* ssrc) {
|
|
|
|
|
if (str.empty())
|
2014-10-07 07:18:36 +00:00
|
|
|
return true;
|
2014-10-07 05:30:04 +00:00
|
|
|
int base = 10;
|
|
|
|
|
// Look for "0x" or "0X" at the start and change base to 16 if found.
|
|
|
|
|
if ((str.compare(0, 2, "0x") == 0) || (str.compare(0, 2, "0X") == 0))
|
|
|
|
|
base = 16;
|
|
|
|
|
errno = 0;
|
|
|
|
|
char* end_ptr;
|
|
|
|
|
unsigned long value = strtoul(str.c_str(), &end_ptr, base);
|
|
|
|
|
if (value == ULONG_MAX && errno == ERANGE)
|
|
|
|
|
return false; // Value out of range for unsigned long.
|
|
|
|
|
if (sizeof(unsigned long) > sizeof(uint32_t) && value > 0xFFFFFFFF)
|
|
|
|
|
return false; // Value out of range for uint32_t.
|
|
|
|
|
if (end_ptr - str.c_str() < static_cast<ptrdiff_t>(str.length()))
|
|
|
|
|
return false; // Part of the string was not parsed.
|
|
|
|
|
*ssrc = static_cast<uint32_t>(value);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
// Flag validators.
|
2015-01-26 19:59:32 +00:00
|
|
|
bool ValidatePayloadType(const char* flagname, int32_t value) {
|
2013-01-29 12:09:21 +00:00
|
|
|
if (value >= 0 && value <= 127) // Value is ok.
|
|
|
|
|
return true;
|
|
|
|
|
printf("Invalid value for --%s: %d\n", flagname, static_cast<int>(value));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-26 19:59:32 +00:00
|
|
|
bool ValidateSsrcValue(const char* flagname, const std::string& str) {
|
2014-10-07 05:30:04 +00:00
|
|
|
uint32_t dummy_ssrc;
|
|
|
|
|
return ParseSsrc(str, &dummy_ssrc);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
// Define command line flags.
|
|
|
|
|
DEFINE_int32(pcmu, 0, "RTP payload type for PCM-u");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool pcmu_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_pcmu, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(pcma, 8, "RTP payload type for PCM-a");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool pcma_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_pcma, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(ilbc, 102, "RTP payload type for iLBC");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool ilbc_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_ilbc, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(isac, 103, "RTP payload type for iSAC");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool isac_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_isac, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(isac_swb, 104, "RTP payload type for iSAC-swb (32 kHz)");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool isac_swb_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_isac_swb, &ValidatePayloadType);
|
2014-11-03 15:19:58 +00:00
|
|
|
DEFINE_int32(opus, 111, "RTP payload type for Opus");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool opus_dummy =
|
2014-11-03 15:19:58 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_opus, &ValidatePayloadType);
|
2013-01-29 12:09:21 +00:00
|
|
|
DEFINE_int32(pcm16b, 93, "RTP payload type for PCM16b-nb (8 kHz)");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool pcm16b_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_pcm16b, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(pcm16b_wb, 94, "RTP payload type for PCM16b-wb (16 kHz)");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool pcm16b_wb_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_pcm16b_wb, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(pcm16b_swb32, 95, "RTP payload type for PCM16b-swb32 (32 kHz)");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool pcm16b_swb32_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_pcm16b_swb32, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(pcm16b_swb48, 96, "RTP payload type for PCM16b-swb48 (48 kHz)");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool pcm16b_swb48_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_pcm16b_swb48, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(g722, 9, "RTP payload type for G.722");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool g722_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_g722, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(avt, 106, "RTP payload type for AVT/DTMF");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool avt_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_avt, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(red, 117, "RTP payload type for redundant audio (RED)");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool red_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_red, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(cn_nb, 13, "RTP payload type for comfort noise (8 kHz)");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool cn_nb_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_cn_nb, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(cn_wb, 98, "RTP payload type for comfort noise (16 kHz)");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool cn_wb_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_cn_wb, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(cn_swb32, 99, "RTP payload type for comfort noise (32 kHz)");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool cn_swb32_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_cn_swb32, &ValidatePayloadType);
|
|
|
|
|
DEFINE_int32(cn_swb48, 100, "RTP payload type for comfort noise (48 kHz)");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool cn_swb48_dummy =
|
2013-01-29 12:09:21 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_cn_swb48, &ValidatePayloadType);
|
|
|
|
|
DEFINE_bool(codec_map, false, "Prints the mapping between RTP payload type and "
|
|
|
|
|
"codec");
|
2014-02-05 08:49:13 +00:00
|
|
|
DEFINE_string(replacement_audio_file, "",
|
|
|
|
|
"A PCM file that will be used to populate ""dummy"" RTP packets");
|
2014-10-07 05:30:04 +00:00
|
|
|
DEFINE_string(ssrc,
|
|
|
|
|
"",
|
|
|
|
|
"Only use packets with this SSRC (decimal or hex, the latter "
|
|
|
|
|
"starting with 0x)");
|
2015-01-26 19:59:32 +00:00
|
|
|
const bool hex_ssrc_dummy =
|
2014-10-07 05:30:04 +00:00
|
|
|
google::RegisterFlagValidator(&FLAGS_ssrc, &ValidateSsrcValue);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Maps a codec type to a printable name string.
|
2016-05-24 06:14:57 -07:00
|
|
|
std::string CodecName(NetEqDecoder codec) {
|
2013-01-29 12:09:21 +00:00
|
|
|
switch (codec) {
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderPCMu:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "PCM-u";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderPCMa:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "PCM-a";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderILBC:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "iLBC";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderISAC:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "iSAC";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderISACswb:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "iSAC-swb (32 kHz)";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderOpus:
|
2014-11-03 15:19:58 +00:00
|
|
|
return "Opus";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderPCM16B:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "PCM16b-nb (8 kHz)";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderPCM16Bwb:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "PCM16b-wb (16 kHz)";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderPCM16Bswb32kHz:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "PCM16b-swb32 (32 kHz)";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderPCM16Bswb48kHz:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "PCM16b-swb48 (48 kHz)";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderG722:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "G.722";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderRED:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "redundant audio (RED)";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderAVT:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "AVT/DTMF";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderCNGnb:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "comfort noise (8 kHz)";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderCNGwb:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "comfort noise (16 kHz)";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderCNGswb32kHz:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "comfort noise (32 kHz)";
|
2016-05-24 06:14:57 -07:00
|
|
|
case NetEqDecoder::kDecoderCNGswb48kHz:
|
2013-01-29 12:09:21 +00:00
|
|
|
return "comfort noise (48 kHz)";
|
|
|
|
|
default:
|
|
|
|
|
assert(false);
|
|
|
|
|
return "undefined";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 21:28:22 +00:00
|
|
|
void RegisterPayloadType(NetEq* neteq,
|
2016-05-24 06:14:57 -07:00
|
|
|
NetEqDecoder codec,
|
2015-12-09 06:20:58 -08:00
|
|
|
const std::string& name,
|
2015-02-23 21:28:22 +00:00
|
|
|
google::int32 flag) {
|
2015-12-09 06:20:58 -08:00
|
|
|
if (neteq->RegisterPayloadType(codec, name, static_cast<uint8_t>(flag))) {
|
2015-02-23 21:28:22 +00:00
|
|
|
std::cerr << "Cannot register payload type " << flag << " as "
|
|
|
|
|
<< CodecName(codec) << std::endl;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
// Registers all decoders in |neteq|.
|
|
|
|
|
void RegisterPayloadTypes(NetEq* neteq) {
|
|
|
|
|
assert(neteq);
|
2016-05-24 06:14:57 -07:00
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderPCMu, "pcmu", FLAGS_pcmu);
|
|
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderPCMa, "pcma", FLAGS_pcma);
|
|
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderILBC, "ilbc", FLAGS_ilbc);
|
|
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderISAC, "isac", FLAGS_isac);
|
|
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderISACswb, "isac-swb",
|
2015-10-29 06:20:28 -07:00
|
|
|
FLAGS_isac_swb);
|
2016-05-24 06:14:57 -07:00
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderOpus, "opus", FLAGS_opus);
|
|
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderPCM16B, "pcm16-nb",
|
2015-10-29 06:20:28 -07:00
|
|
|
FLAGS_pcm16b);
|
2016-05-24 06:14:57 -07:00
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderPCM16Bwb, "pcm16-wb",
|
2015-10-29 06:20:28 -07:00
|
|
|
FLAGS_pcm16b_wb);
|
2016-05-24 06:14:57 -07:00
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderPCM16Bswb32kHz,
|
2015-12-09 06:20:58 -08:00
|
|
|
"pcm16-swb32", FLAGS_pcm16b_swb32);
|
2016-05-24 06:14:57 -07:00
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderPCM16Bswb48kHz,
|
2015-12-09 06:20:58 -08:00
|
|
|
"pcm16-swb48", FLAGS_pcm16b_swb48);
|
2016-05-24 06:14:57 -07:00
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderG722, "g722", FLAGS_g722);
|
|
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderAVT, "avt", FLAGS_avt);
|
|
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderRED, "red", FLAGS_red);
|
|
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderCNGnb, "cng-nb",
|
2015-12-09 06:20:58 -08:00
|
|
|
FLAGS_cn_nb);
|
2016-05-24 06:14:57 -07:00
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderCNGwb, "cng-wb",
|
2015-12-09 06:20:58 -08:00
|
|
|
FLAGS_cn_wb);
|
2016-05-24 06:14:57 -07:00
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderCNGswb32kHz, "cng-swb32",
|
|
|
|
|
FLAGS_cn_swb32);
|
|
|
|
|
RegisterPayloadType(neteq, NetEqDecoder::kDecoderCNGswb48kHz, "cng-swb48",
|
|
|
|
|
FLAGS_cn_swb48);
|
2015-02-23 21:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-24 06:14:57 -07:00
|
|
|
void PrintCodecMappingEntry(NetEqDecoder codec, google::int32 flag) {
|
2015-02-23 21:28:22 +00:00
|
|
|
std::cout << CodecName(codec) << ": " << flag << std::endl;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PrintCodecMapping() {
|
2016-05-24 06:14:57 -07:00
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMu, FLAGS_pcmu);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMa, FLAGS_pcma);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderILBC, FLAGS_ilbc);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderISAC, FLAGS_isac);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderISACswb, FLAGS_isac_swb);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderOpus, FLAGS_opus);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16B, FLAGS_pcm16b);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bwb, FLAGS_pcm16b_wb);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb32kHz,
|
2015-10-29 06:20:28 -07:00
|
|
|
FLAGS_pcm16b_swb32);
|
2016-05-24 06:14:57 -07:00
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb48kHz,
|
2015-10-29 06:20:28 -07:00
|
|
|
FLAGS_pcm16b_swb48);
|
2016-05-24 06:14:57 -07:00
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderG722, FLAGS_g722);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT, FLAGS_avt);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderRED, FLAGS_red);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGnb, FLAGS_cn_nb);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGwb, FLAGS_cn_wb);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb32kHz, FLAGS_cn_swb32);
|
|
|
|
|
PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb48kHz, FLAGS_cn_swb48);
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
2014-02-05 08:49:13 +00:00
|
|
|
|
2015-02-23 21:28:22 +00:00
|
|
|
bool IsComfortNoise(uint8_t payload_type) {
|
|
|
|
|
return payload_type == FLAGS_cn_nb || payload_type == FLAGS_cn_wb ||
|
|
|
|
|
payload_type == FLAGS_cn_swb32 || payload_type == FLAGS_cn_swb48;
|
2015-01-26 19:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CodecSampleRate(uint8_t payload_type) {
|
2015-02-23 21:28:22 +00:00
|
|
|
if (payload_type == FLAGS_pcmu || payload_type == FLAGS_pcma ||
|
|
|
|
|
payload_type == FLAGS_ilbc || payload_type == FLAGS_pcm16b ||
|
|
|
|
|
payload_type == FLAGS_cn_nb)
|
2015-01-26 19:59:32 +00:00
|
|
|
return 8000;
|
2015-02-23 21:28:22 +00:00
|
|
|
if (payload_type == FLAGS_isac || payload_type == FLAGS_pcm16b_wb ||
|
|
|
|
|
payload_type == FLAGS_g722 || payload_type == FLAGS_cn_wb)
|
2015-01-26 19:59:32 +00:00
|
|
|
return 16000;
|
2015-02-23 21:28:22 +00:00
|
|
|
if (payload_type == FLAGS_isac_swb || payload_type == FLAGS_pcm16b_swb32 ||
|
|
|
|
|
payload_type == FLAGS_cn_swb32)
|
2015-01-26 19:59:32 +00:00
|
|
|
return 32000;
|
2015-02-23 21:28:22 +00:00
|
|
|
if (payload_type == FLAGS_opus || payload_type == FLAGS_pcm16b_swb48 ||
|
|
|
|
|
payload_type == FLAGS_cn_swb48)
|
2015-01-26 19:59:32 +00:00
|
|
|
return 48000;
|
2015-02-23 21:28:22 +00:00
|
|
|
if (payload_type == FLAGS_avt || payload_type == FLAGS_red)
|
|
|
|
|
return 0;
|
|
|
|
|
return -1;
|
2015-01-26 19:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CodecTimestampRate(uint8_t payload_type) {
|
2015-02-23 21:28:22 +00:00
|
|
|
return (payload_type == FLAGS_g722) ? 8000 : CodecSampleRate(payload_type);
|
2015-01-26 19:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-24 06:14:57 -07:00
|
|
|
size_t ReplacePayload(InputAudioFile* replacement_audio_file,
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<int16_t[]>* replacement_audio,
|
|
|
|
|
std::unique_ptr<uint8_t[]>* payload,
|
2015-01-26 19:59:32 +00:00
|
|
|
size_t* payload_mem_size_bytes,
|
|
|
|
|
size_t* frame_size_samples,
|
|
|
|
|
WebRtcRTPHeader* rtp_header,
|
2016-05-24 06:14:57 -07:00
|
|
|
const Packet* next_packet) {
|
2015-01-26 19:59:32 +00:00
|
|
|
size_t payload_len = 0;
|
|
|
|
|
// Check for CNG.
|
2015-02-23 21:28:22 +00:00
|
|
|
if (IsComfortNoise(rtp_header->header.payloadType)) {
|
2015-01-26 19:59:32 +00:00
|
|
|
// If CNG, simply insert a zero-energy one-byte payload.
|
2014-02-05 08:49:13 +00:00
|
|
|
if (*payload_mem_size_bytes < 1) {
|
|
|
|
|
(*payload).reset(new uint8_t[1]);
|
|
|
|
|
*payload_mem_size_bytes = 1;
|
|
|
|
|
}
|
|
|
|
|
(*payload)[0] = 127; // Max attenuation of CNG.
|
|
|
|
|
payload_len = 1;
|
|
|
|
|
} else {
|
2014-08-11 12:29:38 +00:00
|
|
|
assert(next_packet->virtual_payload_length_bytes() > 0);
|
|
|
|
|
// Check if payload length has changed.
|
|
|
|
|
if (next_packet->header().sequenceNumber ==
|
|
|
|
|
rtp_header->header.sequenceNumber + 1) {
|
|
|
|
|
if (*frame_size_samples !=
|
|
|
|
|
next_packet->header().timestamp - rtp_header->header.timestamp) {
|
|
|
|
|
*frame_size_samples =
|
|
|
|
|
next_packet->header().timestamp - rtp_header->header.timestamp;
|
|
|
|
|
(*replacement_audio).reset(
|
|
|
|
|
new int16_t[*frame_size_samples]);
|
|
|
|
|
*payload_mem_size_bytes = 2 * *frame_size_samples;
|
|
|
|
|
(*payload).reset(new uint8_t[*payload_mem_size_bytes]);
|
2014-02-05 08:49:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Get new speech.
|
|
|
|
|
assert((*replacement_audio).get());
|
|
|
|
|
if (CodecTimestampRate(rtp_header->header.payloadType) !=
|
|
|
|
|
CodecSampleRate(rtp_header->header.payloadType) ||
|
|
|
|
|
rtp_header->header.payloadType == FLAGS_red ||
|
|
|
|
|
rtp_header->header.payloadType == FLAGS_avt) {
|
|
|
|
|
// Some codecs have different sample and timestamp rates. And neither
|
|
|
|
|
// RED nor DTMF is supported for replacement.
|
|
|
|
|
std::cerr << "Codec not supported for audio replacement." <<
|
|
|
|
|
std::endl;
|
2016-05-24 06:14:57 -07:00
|
|
|
Trace::ReturnTrace();
|
2014-02-05 08:49:13 +00:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
assert(*frame_size_samples > 0);
|
|
|
|
|
if (!replacement_audio_file->Read(*frame_size_samples,
|
|
|
|
|
(*replacement_audio).get())) {
|
2014-08-11 12:29:38 +00:00
|
|
|
std::cerr << "Could not read replacement audio file." << std::endl;
|
2016-05-24 06:14:57 -07:00
|
|
|
Trace::ReturnTrace();
|
2014-02-05 08:49:13 +00:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
// Encode it as PCM16.
|
|
|
|
|
assert((*payload).get());
|
|
|
|
|
payload_len = WebRtcPcm16b_Encode((*replacement_audio).get(),
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
*frame_size_samples,
|
2014-02-05 08:49:13 +00:00
|
|
|
(*payload).get());
|
|
|
|
|
assert(payload_len == 2 * *frame_size_samples);
|
|
|
|
|
// Change payload type to PCM16.
|
|
|
|
|
switch (CodecSampleRate(rtp_header->header.payloadType)) {
|
|
|
|
|
case 8000:
|
2015-02-02 23:54:03 +00:00
|
|
|
rtp_header->header.payloadType = static_cast<uint8_t>(FLAGS_pcm16b);
|
2014-02-05 08:49:13 +00:00
|
|
|
break;
|
|
|
|
|
case 16000:
|
2015-02-02 23:54:03 +00:00
|
|
|
rtp_header->header.payloadType = static_cast<uint8_t>(FLAGS_pcm16b_wb);
|
2014-02-05 08:49:13 +00:00
|
|
|
break;
|
|
|
|
|
case 32000:
|
2015-02-02 23:54:03 +00:00
|
|
|
rtp_header->header.payloadType =
|
|
|
|
|
static_cast<uint8_t>(FLAGS_pcm16b_swb32);
|
2014-02-05 08:49:13 +00:00
|
|
|
break;
|
|
|
|
|
case 48000:
|
2015-02-02 23:54:03 +00:00
|
|
|
rtp_header->header.payloadType =
|
|
|
|
|
static_cast<uint8_t>(FLAGS_pcm16b_swb48);
|
2014-02-05 08:49:13 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
std::cerr << "Payload type " <<
|
|
|
|
|
static_cast<int>(rtp_header->header.payloadType) <<
|
|
|
|
|
" not supported or unknown." << std::endl;
|
2016-05-24 06:14:57 -07:00
|
|
|
Trace::ReturnTrace();
|
2014-02-05 08:49:13 +00:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return payload_len;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-26 19:59:32 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
|
static const int kOutputBlockSizeMs = 10;
|
|
|
|
|
|
|
|
|
|
std::string program_name = argv[0];
|
|
|
|
|
std::string usage = "Tool for decoding an RTP dump file using NetEq.\n"
|
|
|
|
|
"Run " + program_name + " --helpshort for usage.\n"
|
|
|
|
|
"Example usage:\n" + program_name +
|
|
|
|
|
" input.rtp output.{pcm, wav}\n";
|
|
|
|
|
google::SetUsageMessage(usage);
|
|
|
|
|
google::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
|
|
|
|
|
|
if (FLAGS_codec_map) {
|
|
|
|
|
PrintCodecMapping();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (argc != 3) {
|
|
|
|
|
if (FLAGS_codec_map) {
|
|
|
|
|
// We have already printed the codec map. Just end the program.
|
2014-02-05 08:49:13 +00:00
|
|
|
return 0;
|
2015-01-26 19:59:32 +00:00
|
|
|
}
|
|
|
|
|
// Print usage information.
|
|
|
|
|
std::cout << google::ProgramUsage();
|
|
|
|
|
return 0;
|
2014-02-05 08:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-26 19:59:32 +00:00
|
|
|
printf("Input file: %s\n", argv[1]);
|
2015-09-08 03:28:46 -07:00
|
|
|
|
|
|
|
|
bool is_rtp_dump = false;
|
2016-05-24 06:14:57 -07:00
|
|
|
std::unique_ptr<PacketSource> file_source;
|
|
|
|
|
RtcEventLogSource* event_log_source = nullptr;
|
|
|
|
|
if (RtpFileSource::ValidRtpDump(argv[1]) ||
|
|
|
|
|
RtpFileSource::ValidPcap(argv[1])) {
|
2015-11-03 00:32:09 -08:00
|
|
|
is_rtp_dump = true;
|
2016-05-24 06:14:57 -07:00
|
|
|
file_source.reset(RtpFileSource::Create(argv[1]));
|
2015-09-08 03:28:46 -07:00
|
|
|
} else {
|
2016-05-24 06:14:57 -07:00
|
|
|
event_log_source = RtcEventLogSource::Create(argv[1]);
|
2015-09-08 03:28:46 -07:00
|
|
|
file_source.reset(event_log_source);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-26 19:59:32 +00:00
|
|
|
assert(file_source.get());
|
|
|
|
|
|
|
|
|
|
// Check if an SSRC value was provided.
|
|
|
|
|
if (!FLAGS_ssrc.empty()) {
|
|
|
|
|
uint32_t ssrc;
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK(ParseSsrc(FLAGS_ssrc, &ssrc)) << "Flag verification has failed.";
|
2015-01-26 19:59:32 +00:00
|
|
|
file_source->SelectSsrc(ssrc);
|
2014-02-05 08:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-26 19:59:32 +00:00
|
|
|
// Check if a replacement audio file was provided, and if so, open it.
|
|
|
|
|
bool replace_payload = false;
|
2016-05-24 06:14:57 -07:00
|
|
|
std::unique_ptr<InputAudioFile> replacement_audio_file;
|
2015-01-26 19:59:32 +00:00
|
|
|
if (!FLAGS_replacement_audio_file.empty()) {
|
|
|
|
|
replacement_audio_file.reset(
|
2016-05-24 06:14:57 -07:00
|
|
|
new InputAudioFile(FLAGS_replacement_audio_file));
|
2015-01-26 19:59:32 +00:00
|
|
|
replace_payload = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read first packet.
|
2016-05-24 06:14:57 -07:00
|
|
|
std::unique_ptr<Packet> packet(file_source->NextPacket());
|
2015-01-26 19:59:32 +00:00
|
|
|
if (!packet) {
|
|
|
|
|
printf(
|
|
|
|
|
"Warning: input file is empty, or the filters did not match any "
|
|
|
|
|
"packets\n");
|
2016-05-24 06:14:57 -07:00
|
|
|
Trace::ReturnTrace();
|
2015-01-26 19:59:32 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2015-09-08 03:28:46 -07:00
|
|
|
if (packet->payload_length_bytes() == 0 && !replace_payload) {
|
|
|
|
|
std::cerr << "Warning: input file contains header-only packets, but no "
|
|
|
|
|
<< "replacement file is specified." << std::endl;
|
2016-05-24 06:14:57 -07:00
|
|
|
Trace::ReturnTrace();
|
2015-09-08 03:28:46 -07:00
|
|
|
return -1;
|
|
|
|
|
}
|
2015-01-26 19:59:32 +00:00
|
|
|
|
|
|
|
|
// Check the sample rate.
|
|
|
|
|
int sample_rate_hz = CodecSampleRate(packet->header().payloadType);
|
|
|
|
|
if (sample_rate_hz <= 0) {
|
|
|
|
|
printf("Warning: Invalid sample rate from RTP packet.\n");
|
2016-05-24 06:14:57 -07:00
|
|
|
Trace::ReturnTrace();
|
2015-01-26 19:59:32 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Open the output file now that we know the sample rate. (Rate is only needed
|
|
|
|
|
// for wav files.)
|
|
|
|
|
// Check output file type.
|
|
|
|
|
std::string output_file_name = argv[2];
|
2016-05-24 06:14:57 -07:00
|
|
|
std::unique_ptr<AudioSink> output;
|
2015-01-26 19:59:32 +00:00
|
|
|
if (output_file_name.size() >= 4 &&
|
|
|
|
|
output_file_name.substr(output_file_name.size() - 4) == ".wav") {
|
|
|
|
|
// Open a wav file.
|
2016-05-24 06:14:57 -07:00
|
|
|
output.reset(new OutputWavFile(output_file_name, sample_rate_hz));
|
2014-02-05 08:49:13 +00:00
|
|
|
} else {
|
2015-01-26 19:59:32 +00:00
|
|
|
// Open a pcm file.
|
2016-05-24 06:14:57 -07:00
|
|
|
output.reset(new OutputAudioFile(output_file_name));
|
2015-01-26 19:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::cout << "Output file: " << argv[2] << std::endl;
|
|
|
|
|
|
|
|
|
|
// Enable tracing.
|
2016-05-24 06:14:57 -07:00
|
|
|
Trace::CreateTrace();
|
|
|
|
|
Trace::SetTraceFile((OutputPath() + "neteq_trace.txt").c_str());
|
|
|
|
|
Trace::set_level_filter(kTraceAll);
|
2015-01-26 19:59:32 +00:00
|
|
|
|
|
|
|
|
// Initialize NetEq instance.
|
|
|
|
|
NetEq::Config config;
|
|
|
|
|
config.sample_rate_hz = sample_rate_hz;
|
2016-05-25 07:37:43 -07:00
|
|
|
NetEq* neteq =
|
|
|
|
|
NetEq::Create(config, CreateBuiltinAudioDecoderFactory());
|
2015-01-26 19:59:32 +00:00
|
|
|
RegisterPayloadTypes(neteq);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set up variables for audio replacement if needed.
|
2016-05-24 06:14:57 -07:00
|
|
|
std::unique_ptr<Packet> next_packet;
|
2015-01-26 19:59:32 +00:00
|
|
|
bool next_packet_available = false;
|
|
|
|
|
size_t input_frame_size_timestamps = 0;
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<int16_t[]> replacement_audio;
|
|
|
|
|
std::unique_ptr<uint8_t[]> payload;
|
2015-01-26 19:59:32 +00:00
|
|
|
size_t payload_mem_size_bytes = 0;
|
|
|
|
|
if (replace_payload) {
|
|
|
|
|
// Initially assume that the frame size is 30 ms at the initial sample rate.
|
|
|
|
|
// This value will be replaced with the correct one as soon as two
|
|
|
|
|
// consecutive packets are found.
|
|
|
|
|
input_frame_size_timestamps = 30 * sample_rate_hz / 1000;
|
|
|
|
|
replacement_audio.reset(new int16_t[input_frame_size_timestamps]);
|
|
|
|
|
payload_mem_size_bytes = 2 * input_frame_size_timestamps;
|
|
|
|
|
payload.reset(new uint8_t[payload_mem_size_bytes]);
|
2016-05-24 22:50:47 -07:00
|
|
|
next_packet = file_source->NextPacket();
|
2015-01-26 19:59:32 +00:00
|
|
|
assert(next_packet);
|
|
|
|
|
next_packet_available = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is the main simulation loop.
|
|
|
|
|
// Set the simulation clock to start immediately with the first packet.
|
2015-09-08 03:28:46 -07:00
|
|
|
int64_t start_time_ms = rtc::checked_cast<int64_t>(packet->time_ms());
|
|
|
|
|
int64_t time_now_ms = start_time_ms;
|
|
|
|
|
int64_t next_input_time_ms = time_now_ms;
|
|
|
|
|
int64_t next_output_time_ms = time_now_ms;
|
2015-01-26 19:59:32 +00:00
|
|
|
if (time_now_ms % kOutputBlockSizeMs != 0) {
|
|
|
|
|
// Make sure that next_output_time_ms is rounded up to the next multiple
|
|
|
|
|
// of kOutputBlockSizeMs. (Legacy bit-exactness.)
|
|
|
|
|
next_output_time_ms +=
|
|
|
|
|
kOutputBlockSizeMs - time_now_ms % kOutputBlockSizeMs;
|
|
|
|
|
}
|
2015-09-08 03:28:46 -07:00
|
|
|
|
|
|
|
|
bool packet_available = true;
|
|
|
|
|
bool output_event_available = true;
|
|
|
|
|
if (!is_rtp_dump) {
|
|
|
|
|
next_output_time_ms = event_log_source->NextAudioOutputEventMs();
|
|
|
|
|
if (next_output_time_ms == std::numeric_limits<int64_t>::max())
|
|
|
|
|
output_event_available = false;
|
|
|
|
|
start_time_ms = time_now_ms =
|
|
|
|
|
std::min(next_input_time_ms, next_output_time_ms);
|
|
|
|
|
}
|
|
|
|
|
while (packet_available || output_event_available) {
|
|
|
|
|
// Advance time to next event.
|
|
|
|
|
time_now_ms = std::min(next_input_time_ms, next_output_time_ms);
|
2015-01-26 19:59:32 +00:00
|
|
|
// Check if it is time to insert packet.
|
|
|
|
|
while (time_now_ms >= next_input_time_ms && packet_available) {
|
|
|
|
|
assert(packet->virtual_payload_length_bytes() > 0);
|
|
|
|
|
// Parse RTP header.
|
|
|
|
|
WebRtcRTPHeader rtp_header;
|
|
|
|
|
packet->ConvertHeader(&rtp_header);
|
|
|
|
|
const uint8_t* payload_ptr = packet->payload();
|
|
|
|
|
size_t payload_len = packet->payload_length_bytes();
|
|
|
|
|
if (replace_payload) {
|
|
|
|
|
payload_len = ReplacePayload(replacement_audio_file.get(),
|
|
|
|
|
&replacement_audio,
|
|
|
|
|
&payload,
|
|
|
|
|
&payload_mem_size_bytes,
|
|
|
|
|
&input_frame_size_timestamps,
|
|
|
|
|
&rtp_header,
|
|
|
|
|
next_packet.get());
|
|
|
|
|
payload_ptr = payload.get();
|
|
|
|
|
}
|
2015-09-08 03:28:46 -07:00
|
|
|
int error = neteq->InsertPacket(
|
2015-11-11 10:34:00 -08:00
|
|
|
rtp_header, rtc::ArrayView<const uint8_t>(payload_ptr, payload_len),
|
2015-09-08 03:28:46 -07:00
|
|
|
static_cast<uint32_t>(packet->time_ms() * sample_rate_hz / 1000));
|
2015-01-26 19:59:32 +00:00
|
|
|
if (error != NetEq::kOK) {
|
|
|
|
|
if (neteq->LastError() == NetEq::kUnknownRtpPayloadType) {
|
|
|
|
|
std::cerr << "RTP Payload type "
|
|
|
|
|
<< static_cast<int>(rtp_header.header.payloadType)
|
|
|
|
|
<< " is unknown." << std::endl;
|
|
|
|
|
std::cerr << "Use --codec_map to view default mapping." << std::endl;
|
|
|
|
|
std::cerr << "Use --helpshort for information on how to make custom "
|
|
|
|
|
"mappings." << std::endl;
|
|
|
|
|
} else {
|
|
|
|
|
std::cerr << "InsertPacket returned error code " << neteq->LastError()
|
|
|
|
|
<< std::endl;
|
|
|
|
|
std::cerr << "Header data:" << std::endl;
|
|
|
|
|
std::cerr << " PT = "
|
|
|
|
|
<< static_cast<int>(rtp_header.header.payloadType)
|
|
|
|
|
<< std::endl;
|
|
|
|
|
std::cerr << " SN = " << rtp_header.header.sequenceNumber
|
|
|
|
|
<< std::endl;
|
|
|
|
|
std::cerr << " TS = " << rtp_header.header.timestamp << std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get next packet from file.
|
2016-05-24 22:50:47 -07:00
|
|
|
std::unique_ptr<Packet> temp_packet = file_source->NextPacket();
|
2015-01-26 19:59:32 +00:00
|
|
|
if (temp_packet) {
|
2016-05-24 22:50:47 -07:00
|
|
|
packet = std::move(temp_packet);
|
2015-09-08 03:28:46 -07:00
|
|
|
if (replace_payload) {
|
|
|
|
|
// At this point |packet| contains the packet *after* |next_packet|.
|
|
|
|
|
// Swap Packet objects between |packet| and |next_packet|.
|
|
|
|
|
packet.swap(next_packet);
|
|
|
|
|
// Swap the status indicators unless they're already the same.
|
|
|
|
|
if (packet_available != next_packet_available) {
|
|
|
|
|
packet_available = !packet_available;
|
|
|
|
|
next_packet_available = !next_packet_available;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
next_input_time_ms = rtc::checked_cast<int64_t>(packet->time_ms());
|
2015-01-26 19:59:32 +00:00
|
|
|
} else {
|
2015-09-08 03:28:46 -07:00
|
|
|
// Set next input time to the maximum value of int64_t to prevent the
|
|
|
|
|
// time_now_ms from becoming stuck at the final value.
|
|
|
|
|
next_input_time_ms = std::numeric_limits<int64_t>::max();
|
2015-01-26 19:59:32 +00:00
|
|
|
packet_available = false;
|
|
|
|
|
}
|
2016-05-24 22:50:47 -07:00
|
|
|
RTC_DCHECK(!temp_packet); // Must have transferred to another variable.
|
2015-01-26 19:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if it is time to get output audio.
|
2015-09-08 03:28:46 -07:00
|
|
|
while (time_now_ms >= next_output_time_ms && output_event_available) {
|
2016-05-24 06:14:57 -07:00
|
|
|
AudioFrame out_frame;
|
2016-05-12 13:51:28 -07:00
|
|
|
bool muted;
|
|
|
|
|
int error = neteq->GetAudio(&out_frame, &muted);
|
|
|
|
|
RTC_CHECK(!muted);
|
2015-01-26 19:59:32 +00:00
|
|
|
if (error != NetEq::kOK) {
|
|
|
|
|
std::cerr << "GetAudio returned error code " <<
|
|
|
|
|
neteq->LastError() << std::endl;
|
|
|
|
|
} else {
|
2016-03-04 10:34:21 -08:00
|
|
|
sample_rate_hz = out_frame.sample_rate_hz_;
|
2015-01-26 19:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write to file.
|
|
|
|
|
// TODO(hlundin): Make writing to file optional.
|
2016-03-04 10:34:21 -08:00
|
|
|
if (!output->WriteArray(out_frame.data_, out_frame.samples_per_channel_ *
|
|
|
|
|
out_frame.num_channels_)) {
|
2015-01-26 19:59:32 +00:00
|
|
|
std::cerr << "Error while writing to file" << std::endl;
|
2016-05-24 06:14:57 -07:00
|
|
|
Trace::ReturnTrace();
|
2015-01-26 19:59:32 +00:00
|
|
|
exit(1);
|
|
|
|
|
}
|
2015-09-08 03:28:46 -07:00
|
|
|
if (is_rtp_dump) {
|
|
|
|
|
next_output_time_ms += kOutputBlockSizeMs;
|
|
|
|
|
if (!packet_available)
|
|
|
|
|
output_event_available = false;
|
|
|
|
|
} else {
|
|
|
|
|
next_output_time_ms = event_log_source->NextAudioOutputEventMs();
|
|
|
|
|
if (next_output_time_ms == std::numeric_limits<int64_t>::max())
|
|
|
|
|
output_event_available = false;
|
|
|
|
|
}
|
2015-01-26 19:59:32 +00:00
|
|
|
}
|
2014-02-05 08:49:13 +00:00
|
|
|
}
|
2015-01-26 19:59:32 +00:00
|
|
|
printf("Simulation done\n");
|
2015-09-08 03:28:46 -07:00
|
|
|
printf("Produced %i ms of audio\n",
|
|
|
|
|
static_cast<int>(time_now_ms - start_time_ms));
|
2015-01-26 19:59:32 +00:00
|
|
|
|
|
|
|
|
delete neteq;
|
2016-05-24 06:14:57 -07:00
|
|
|
Trace::ReturnTrace();
|
2015-01-26 19:59:32 +00:00
|
|
|
return 0;
|
2014-02-05 08:49:13 +00:00
|
|
|
}
|
2016-05-24 06:14:57 -07:00
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|