From 7f1dfa5b61f526badbccf1e0a250acee033dd3db Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Tue, 2 Dec 2014 12:08:39 +0000 Subject: [PATCH] Adding a payload type to AudioEncoder objects The type is set in the Config struct and is provided in the EncodedInfo output struct from each Encode() call. The audio_decoder_unittest is updated to verify correct propagation of the payload type. BUG=3926 R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/27299004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7780 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../modules/audio_coding/codecs/audio_encoder.h | 1 + .../codecs/g711/audio_encoder_pcm.cc | 2 ++ .../codecs/g711/include/audio_encoder_pcm.h | 17 +++++++++++++++-- .../codecs/g722/audio_encoder_g722.cc | 2 ++ .../codecs/g722/include/audio_encoder_g722.h | 1 + .../codecs/opus/audio_encoder_opus.cc | 6 +++++- .../codecs/opus/interface/audio_encoder_opus.h | 2 ++ .../neteq/audio_decoder_unittest.cc | 9 +++++++++ 8 files changed, 37 insertions(+), 3 deletions(-) diff --git a/webrtc/modules/audio_coding/codecs/audio_encoder.h b/webrtc/modules/audio_coding/codecs/audio_encoder.h index 6f68d5ca1..c0790a263 100644 --- a/webrtc/modules/audio_coding/codecs/audio_encoder.h +++ b/webrtc/modules/audio_coding/codecs/audio_encoder.h @@ -24,6 +24,7 @@ class AudioEncoder { public: struct EncodedInfo { uint32_t encoded_timestamp; + int payload_type; }; virtual ~AudioEncoder() {} diff --git a/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc b/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc index ee8dfebba..7f0cc0d3e 100644 --- a/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc +++ b/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc @@ -29,6 +29,7 @@ int16_t NumSamplesPerFrame(int num_channels, AudioEncoderPcm::AudioEncoderPcm(const Config& config) : num_channels_(config.num_channels), + payload_type_(config.payload_type), num_10ms_frames_per_packet_(config.frame_size_ms / 10), full_frame_samples_(NumSamplesPerFrame(num_channels_, config.frame_size_ms, @@ -73,6 +74,7 @@ bool AudioEncoderPcm::Encode(uint32_t timestamp, int16_t ret = EncodeCall(&speech_buffer_[0], full_frame_samples_, encoded); speech_buffer_.clear(); info->encoded_timestamp = first_timestamp_in_buffer_; + info->payload_type = payload_type_; if (ret < 0) return false; *encoded_bytes = static_cast(ret); diff --git a/webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h b/webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h index b3866f039..71a72c8e8 100644 --- a/webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h +++ b/webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h @@ -20,10 +20,14 @@ namespace webrtc { class AudioEncoderPcm : public AudioEncoder { public: struct Config { - Config() : frame_size_ms(20), num_channels(1) {} - + public: int frame_size_ms; int num_channels; + int payload_type; + + protected: + explicit Config(int pt) + : frame_size_ms(20), num_channels(1), payload_type(pt) {} }; explicit AudioEncoderPcm(const Config& config); @@ -49,6 +53,7 @@ class AudioEncoderPcm : public AudioEncoder { private: static const int kSampleRateHz = 8000; const int num_channels_; + const int payload_type_; const int num_10ms_frames_per_packet_; const int16_t full_frame_samples_; std::vector speech_buffer_; @@ -57,6 +62,10 @@ class AudioEncoderPcm : public AudioEncoder { class AudioEncoderPcmA : public AudioEncoderPcm { public: + struct Config : public AudioEncoderPcm::Config { + Config() : AudioEncoderPcm::Config(8) {} + }; + explicit AudioEncoderPcmA(const Config& config) : AudioEncoderPcm(config) {} protected: @@ -67,6 +76,10 @@ class AudioEncoderPcmA : public AudioEncoderPcm { class AudioEncoderPcmU : public AudioEncoderPcm { public: + struct Config : public AudioEncoderPcm::Config { + Config() : AudioEncoderPcm::Config(0) {} + }; + explicit AudioEncoderPcmU(const Config& config) : AudioEncoderPcm(config) {} protected: diff --git a/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc b/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc index ccc6c778e..d64f8303a 100644 --- a/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc +++ b/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc @@ -33,6 +33,7 @@ AudioEncoderG722::EncoderState::~EncoderState() { AudioEncoderG722::AudioEncoderG722(const Config& config) : num_channels_(config.num_channels), + payload_type_(config.payload_type), num_10ms_frames_per_packet_(config.frame_size_ms / 10), num_10ms_frames_buffered_(0), first_timestamp_in_buffer_(0), @@ -113,6 +114,7 @@ bool AudioEncoderG722::Encode(uint32_t timestamp, } *encoded_bytes = samples_per_channel / 2 * num_channels_; info->encoded_timestamp = first_timestamp_in_buffer_; + info->payload_type = payload_type_; return true; } diff --git a/webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h b/webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h index 8e4de22e7..51cba7b65 100644 --- a/webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h +++ b/webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h @@ -53,6 +53,7 @@ class AudioEncoderG722 : public AudioEncoder { }; const int num_channels_; + const int payload_type_; const int num_10ms_frames_per_packet_; int num_10ms_frames_buffered_; uint32_t first_timestamp_in_buffer_; 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 d7ca1a474..35261bc1d 100644 --- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc +++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc @@ -36,7 +36,9 @@ int16_t CastInt16(size_t x) { } // namespace -AudioEncoderOpus::Config::Config() : frame_size_ms(20), num_channels(1) {} +AudioEncoderOpus::Config::Config() + : frame_size_ms(20), num_channels(1), payload_type(120) { +} bool AudioEncoderOpus::Config::IsOk() const { if (frame_size_ms <= 0 || frame_size_ms % 10 != 0) @@ -49,6 +51,7 @@ bool AudioEncoderOpus::Config::IsOk() const { AudioEncoderOpus::AudioEncoderOpus(const Config& config) : num_10ms_frames_per_packet_(DivExact(config.frame_size_ms, 10)), num_channels_(config.num_channels), + payload_type_(config.payload_type), samples_per_10ms_frame_(DivExact(kSampleRateHz, 100) * num_channels_) { CHECK(config.IsOk()); input_buffer_.reserve(num_10ms_frames_per_packet_ * samples_per_10ms_frame_); @@ -98,6 +101,7 @@ bool AudioEncoderOpus::Encode(uint32_t timestamp, return false; *encoded_bytes = r; info->encoded_timestamp = first_timestamp_in_buffer_; + info->payload_type = payload_type_; return true; } diff --git a/webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h b/webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h index 2071c0f68..3cbb25bfd 100644 --- a/webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h +++ b/webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h @@ -25,6 +25,7 @@ class AudioEncoderOpus : public AudioEncoder { bool IsOk() const; int frame_size_ms; int num_channels; + int payload_type; }; explicit AudioEncoderOpus(const Config& config); @@ -45,6 +46,7 @@ class AudioEncoderOpus : public AudioEncoder { private: const int num_10ms_frames_per_packet_; const int num_channels_; + const int payload_type_; const int samples_per_10ms_frame_; std::vector input_buffer_; OpusEncInst* inst_; diff --git a/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc b/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc index 191e81a96..bbcf9ed3e 100644 --- a/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc @@ -102,6 +102,7 @@ class AudioDecoderTest : public ::testing::Test { data_length_(0), encoded_bytes_(0), channels_(1), + payload_type_(17), decoder_(NULL) {} virtual ~AudioDecoderTest() {} @@ -153,6 +154,7 @@ class AudioDecoderTest : public ::testing::Test { 0, interleaved_input.get(), audio_encoder_->sample_rate_hz() / 100, data_length_ * 2, output, &enc_len_bytes, &encoded_info_)); } + EXPECT_EQ(payload_type_, encoded_info_.payload_type); return static_cast(enc_len_bytes); } @@ -262,6 +264,7 @@ class AudioDecoderTest : public ::testing::Test { size_t data_length_; size_t encoded_bytes_; size_t channels_; + const int payload_type_; AudioEncoder::EncodedInfo encoded_info_; AudioDecoder* decoder_; scoped_ptr audio_encoder_; @@ -275,6 +278,7 @@ class AudioDecoderPcmUTest : public AudioDecoderTest { decoder_ = new AudioDecoderPcmU; AudioEncoderPcmU::Config config; config.frame_size_ms = static_cast(frame_size_ / 8); + config.payload_type = payload_type_; audio_encoder_.reset(new AudioEncoderPcmU(config)); } }; @@ -287,6 +291,7 @@ class AudioDecoderPcmATest : public AudioDecoderTest { decoder_ = new AudioDecoderPcmA; AudioEncoderPcmA::Config config; config.frame_size_ms = static_cast(frame_size_ / 8); + config.payload_type = payload_type_; audio_encoder_.reset(new AudioEncoderPcmA(config)); } }; @@ -485,6 +490,7 @@ class AudioDecoderG722Test : public AudioDecoderTest { assert(decoder_); AudioEncoderG722::Config config; config.frame_size_ms = 10; + config.payload_type = payload_type_; config.num_channels = 1; audio_encoder_.reset(new AudioEncoderG722(config)); } @@ -501,6 +507,7 @@ class AudioDecoderG722StereoTest : public AudioDecoderTest { assert(decoder_); AudioEncoderG722::Config config; config.frame_size_ms = 10; + config.payload_type = payload_type_; config.num_channels = 2; audio_encoder_.reset(new AudioEncoderG722(config)); } @@ -586,6 +593,7 @@ class AudioDecoderOpusTest : public AudioDecoderTest { decoder_ = new AudioDecoderOpus(1); AudioEncoderOpus::Config config; config.frame_size_ms = static_cast(frame_size_) / 48; + config.payload_type = payload_type_; audio_encoder_.reset(new AudioEncoderOpus(config)); } }; @@ -599,6 +607,7 @@ class AudioDecoderOpusStereoTest : public AudioDecoderOpusTest { AudioEncoderOpus::Config config; config.frame_size_ms = static_cast(frame_size_) / 48; config.num_channels = 2; + config.payload_type = payload_type_; audio_encoder_.reset(new AudioEncoderOpus(config)); } };