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

Unified Diff: webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.cc

Issue 2275903002: Make FakeDecodeFromFile handle codec-internal CNG (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing compile errors Created 4 years, 4 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
Index: webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.cc
diff --git a/webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.cc b/webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.cc
index 9ca5fb810bd64f21298680634793cc1b53a55ae5..29beed5644f31402bda6d74d75fde25b676d4ab3 100644
--- a/webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.cc
+++ b/webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.cc
@@ -19,14 +19,37 @@ namespace test {
int FakeDecodeFromFile::DecodeInternal(const uint8_t* encoded,
size_t encoded_len,
- int /*sample_rate_hz*/,
+ int sample_rate_hz,
int16_t* decoded,
SpeechType* speech_type) {
- RTC_CHECK_GE(encoded_len, 8u);
+ if (encoded_len == 0) {
+ // Decoder is asked to produce codec-internal comfort noise.
+ RTC_DCHECK(!encoded); // NetEq always sends nullptr in this case.
+ RTC_DCHECK(cng_mode_);
+ RTC_DCHECK_GT(last_decoded_length_, 0u);
+ std::fill_n(decoded, last_decoded_length_, 0);
+ *speech_type = kComfortNoise;
+ return last_decoded_length_;
+ }
+
+ RTC_CHECK_GE(encoded_len, 12u);
uint32_t timestamp_to_decode =
ByteReader<uint32_t>::ReadLittleEndian(encoded);
uint32_t samples_to_decode =
ByteReader<uint32_t>::ReadLittleEndian(&encoded[4]);
+ if (samples_to_decode == 0) {
+ // Number of samples in packet is unknown.
+ if (last_decoded_length_ > 0) {
+ // Use length of last decoded packet, but since this is the total for all
+ // channels, we have to divide by 2 in the stereo case.
+ samples_to_decode = rtc::CheckedDivExact(
+ last_decoded_length_, static_cast<size_t>(stereo_ ? 2uL : 1uL));
+ } else {
+ // This is the first packet to decode, and we do not know the length of
+ // it. Set it to 10 ms.
+ samples_to_decode = rtc::CheckedDivExact(sample_rate_hz, 100);
+ }
+ }
if (next_timestamp_from_input_ &&
timestamp_to_decode != *next_timestamp_from_input_) {
@@ -36,10 +59,23 @@ int FakeDecodeFromFile::DecodeInternal(const uint8_t* encoded,
RTC_CHECK(input_->Seek(jump));
}
- RTC_CHECK(input_->Read(static_cast<size_t>(samples_to_decode), decoded));
next_timestamp_from_input_ =
rtc::Optional<uint32_t>(timestamp_to_decode + samples_to_decode);
+ uint32_t original_payload_size_bytes =
+ ByteReader<uint32_t>::ReadLittleEndian(&encoded[8]);
+ if (original_payload_size_bytes == 1) {
+ // This is a comfort noise payload.
+ RTC_DCHECK_GT(last_decoded_length_, 0u);
+ std::fill_n(decoded, last_decoded_length_, 0);
+ *speech_type = kComfortNoise;
+ cng_mode_ = true;
+ return last_decoded_length_;
+ }
+
+ cng_mode_ = false;
+ RTC_CHECK(input_->Read(static_cast<size_t>(samples_to_decode), decoded));
+
if (stereo_) {
InputAudioFile::DuplicateInterleaved(decoded, samples_to_decode, 2,
decoded);
@@ -47,16 +83,19 @@ int FakeDecodeFromFile::DecodeInternal(const uint8_t* encoded,
}
*speech_type = kSpeech;
- return samples_to_decode;
+ return last_decoded_length_ = samples_to_decode;
}
void FakeDecodeFromFile::PrepareEncoded(uint32_t timestamp,
size_t samples,
+ size_t original_payload_size_bytes,
rtc::ArrayView<uint8_t> encoded) {
- RTC_CHECK_GE(encoded.size(), 8u);
+ RTC_CHECK_GE(encoded.size(), 12u);
ByteWriter<uint32_t>::WriteLittleEndian(&encoded[0], timestamp);
ByteWriter<uint32_t>::WriteLittleEndian(&encoded[4],
rtc::checked_cast<uint32_t>(samples));
+ ByteWriter<uint32_t>::WriteLittleEndian(
+ &encoded[8], rtc::checked_cast<uint32_t>(original_payload_size_bytes));
}
} // namespace test

Powered by Google App Engine
This is Rietveld 408576698