Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(806)

Unified Diff: webrtc/modules/audio_coding/acm2/audio_coding_module.cc

Issue 2119393002: Fixed time moving backwards in the AudioCodingModule. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Updated Dtx tests that moved the input timestamp backwards to not do that. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/checks.h ('k') | webrtc/modules/audio_coding/test/TestVADDTX.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/audio_coding/acm2/audio_coding_module.cc
diff --git a/webrtc/modules/audio_coding/acm2/audio_coding_module.cc b/webrtc/modules/audio_coding/acm2/audio_coding_module.cc
index 6170d187bab14ab53b62fe9795c6c56332040c0a..b394c591567926b151b00a62c861f7f7bc35bbd1 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<uint32_t>(
@@ -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<uint32_t>(in_frame.samples_per_channel_);
expected_codec_ts_ += static_cast<uint32_t>(in_frame.samples_per_channel_);
- *ptr_out = &in_frame;
return 0;
}
« no previous file with comments | « webrtc/base/checks.h ('k') | webrtc/modules/audio_coding/test/TestVADDTX.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698