diff --git a/webrtc/base/checks.h b/webrtc/base/checks.h index 681361a3d2..e66c061186 100644 --- a/webrtc/base/checks.h +++ b/webrtc/base/checks.h @@ -220,7 +220,8 @@ class FatalMessage { // remainder is zero. template inline T CheckedDivExact(T a, T b) { - RTC_CHECK_EQ(a % b, static_cast(0)); + RTC_CHECK_EQ(a % b, static_cast(0)) << a << " is not evenly divisible by " + << b; return a / b; } diff --git a/webrtc/modules/audio_coding/acm2/audio_coding_module.cc b/webrtc/modules/audio_coding/acm2/audio_coding_module.cc index 6170d187ba..b394c59156 100644 --- a/webrtc/modules/audio_coding/acm2/audio_coding_module.cc +++ b/webrtc/modules/audio_coding/acm2/audio_coding_module.cc @@ -472,6 +472,11 @@ int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) { if (!HaveValidEncoder("Process")) return -1; + if(!first_frame_) { + RTC_DCHECK_GT(input_data.input_timestamp, last_timestamp_) + << "Time should not move backwards"; + } + // Scale the timestamp to the codec's RTP timestamp rate. uint32_t rtp_timestamp = first_frame_ ? input_data.input_timestamp @@ -752,7 +757,8 @@ int AudioCodingModuleImpl::PreprocessToAddData(const AudioFrame& in_frame, expected_codec_ts_ = in_frame.timestamp_; first_10ms_data_ = true; } else if (in_frame.timestamp_ != expected_in_ts_) { - // TODO(turajs): Do we need a warning here. + LOG(LS_WARNING) << "Unexpected input timestamp: " << in_frame.timestamp_ + << ", expected: " << expected_in_ts_; expected_codec_ts_ += (in_frame.timestamp_ - expected_in_ts_) * static_cast( @@ -764,9 +770,19 @@ int AudioCodingModuleImpl::PreprocessToAddData(const AudioFrame& in_frame, if (!down_mix && !resample) { // No pre-processing is required. + if (expected_in_ts_ == expected_codec_ts_) { + // If we've never resampled, we can use the input frame as-is + *ptr_out = &in_frame; + } else { + // Otherwise we'll need to alter the timestamp. Since in_frame is const, + // we'll have to make a copy of it. + preprocess_frame_.CopyFrom(in_frame); + preprocess_frame_.timestamp_ = expected_codec_ts_; + *ptr_out = &preprocess_frame_; + } + expected_in_ts_ += static_cast(in_frame.samples_per_channel_); expected_codec_ts_ += static_cast(in_frame.samples_per_channel_); - *ptr_out = &in_frame; return 0; } diff --git a/webrtc/modules/audio_coding/test/TestVADDTX.cc b/webrtc/modules/audio_coding/test/TestVADDTX.cc index 4f53e47cac..541dfc3c45 100644 --- a/webrtc/modules/audio_coding/test/TestVADDTX.cc +++ b/webrtc/modules/audio_coding/test/TestVADDTX.cc @@ -101,12 +101,11 @@ void TestVadDtx::Run(std::string in_filename, int frequency, int channels, } uint16_t frame_size_samples = in_file.PayloadLength10Ms(); - uint32_t time_stamp = 0x12345678; AudioFrame audio_frame; while (!in_file.EndOfFile()) { in_file.Read10MsData(audio_frame); - audio_frame.timestamp_ = time_stamp; - time_stamp += frame_size_samples; + audio_frame.timestamp_ = time_stamp_; + time_stamp_ += frame_size_samples; EXPECT_GE(acm_send_->Add10MsData(audio_frame), 0); bool muted; acm_receive_->PlayoutData10Ms(kOutputFreqHz, &audio_frame, &muted); diff --git a/webrtc/modules/audio_coding/test/TestVADDTX.h b/webrtc/modules/audio_coding/test/TestVADDTX.h index 893babc4e0..b7e987137c 100644 --- a/webrtc/modules/audio_coding/test/TestVADDTX.h +++ b/webrtc/modules/audio_coding/test/TestVADDTX.h @@ -72,6 +72,7 @@ class TestVadDtx : public ACMTest { std::unique_ptr acm_receive_; std::unique_ptr channel_; std::unique_ptr monitor_; + uint32_t time_stamp_ = 0x12345678; }; // TestWebRtcVadDtx is to verify that the WebRTC VAD/DTX perform as they should.