From c86bbbaa9348b868e94c021426abcc2f5e0144b0 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Wed, 4 Mar 2015 16:02:42 +0000 Subject: [PATCH] Add speech flag to EncodedInfo The flag indicates if the encoded bitstream is speech or comfort noise. COAUTHOR=kwiberg@webrtc.org R=jmarusic@webrtc.org Review URL: https://webrtc-codereview.appspot.com/42629004 Cr-Commit-Position: refs/heads/master@{#8598} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8598 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/audio_coding/codecs/audio_encoder.h | 4 +++- webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc | 1 + .../audio_coding/codecs/cng/audio_encoder_cng_unittest.cc | 5 +++++ .../modules/audio_coding/codecs/opus/audio_encoder_opus.cc | 1 + .../audio_coding/codecs/red/audio_encoder_copy_red.cc | 1 + 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/webrtc/modules/audio_coding/codecs/audio_encoder.h b/webrtc/modules/audio_coding/codecs/audio_encoder.h index 738669d480..c0ec2109c3 100644 --- a/webrtc/modules/audio_coding/codecs/audio_encoder.h +++ b/webrtc/modules/audio_coding/codecs/audio_encoder.h @@ -27,12 +27,14 @@ class AudioEncoder { : encoded_bytes(0), encoded_timestamp(0), payload_type(0), - send_even_if_empty(false) {} + send_even_if_empty(false), + speech(true) {} size_t encoded_bytes; uint32_t encoded_timestamp; int payload_type; bool send_even_if_empty; + bool speech; }; // This is the main struct for auxiliary encoding information. Each encoded diff --git a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc index e14ac932dd..14b210c3ec 100644 --- a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc +++ b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc @@ -150,6 +150,7 @@ void AudioEncoderCng::EncodeInternal(uint32_t rtp_timestamp, info->encoded_timestamp = first_timestamp_in_buffer_; info->payload_type = cng_payload_type_; info->send_even_if_empty = true; + info->speech = false; last_frame_active_ = false; break; } diff --git a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng_unittest.cc b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng_unittest.cc index 03e7ba06bb..c5d436eb8f 100644 --- a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng_unittest.cc +++ b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng_unittest.cc @@ -261,6 +261,7 @@ TEST_F(AudioEncoderCngTest, EncodePassive) { if ((i % (config_.sid_frame_interval_ms / 10)) < kBlocksPerFrame) { // If so, verify that we got a CNG encoding. EXPECT_EQ(kCngPayloadType, encoded_info_.payload_type); + EXPECT_FALSE(encoded_info_.speech); EXPECT_EQ(static_cast(config_.num_cng_coefficients) + 1, encoded_info_.encoded_bytes); EXPECT_EQ(expected_timestamp, encoded_info_.encoded_timestamp); @@ -282,19 +283,23 @@ TEST_F(AudioEncoderCngTest, MixedActivePassive) { EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _, _, _)) .Times(6); EXPECT_TRUE(CheckMixedActivePassive(Vad::kActive, Vad::kActive)); + EXPECT_TRUE(encoded_info_.speech); // First half of the frame is active speech. EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _, _, _)) .Times(6); EXPECT_TRUE(CheckMixedActivePassive(Vad::kActive, Vad::kPassive)); + EXPECT_TRUE(encoded_info_.speech); // Second half of the frame is active speech. EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _, _, _)) .Times(6); EXPECT_TRUE(CheckMixedActivePassive(Vad::kPassive, Vad::kActive)); + EXPECT_TRUE(encoded_info_.speech); // All of the frame is passive speech. Expect no calls to |mock_encoder_|. EXPECT_FALSE(CheckMixedActivePassive(Vad::kPassive, Vad::kPassive)); + EXPECT_FALSE(encoded_info_.speech); } // These tests verify that the audio is partitioned into larger blocks before diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc index 4739018f73..e4779aa0b8 100644 --- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc +++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc @@ -202,6 +202,7 @@ void AudioEncoderOpus::EncodeInternal(uint32_t rtp_timestamp, info->payload_type = payload_type_; // Allows Opus to send empty packets. info->send_even_if_empty = true; + info->speech = r > 0; } } // namespace webrtc diff --git a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc index afc6391daf..92e1c0b371 100644 --- a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc +++ b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc @@ -88,6 +88,7 @@ void AudioEncoderCopyRed::EncodeInternal(uint32_t rtp_timestamp, CHECK(secondary_encoded_); memcpy(secondary_encoded_.get(), encoded, info->encoded_bytes); secondary_info_ = *info; + DCHECK_EQ(info->speech, info->redundant[0].speech); } // Update main EncodedInfo. info->payload_type = red_payload_type_;