Add support for 40 and 60 ms frames to AudioEncoderIlbc
BUG=3926
COAUTHOR:kwiberg@webrtc.org
R=tina.legrand@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/37789004
git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@8182 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc b/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc
index 3fb6022..da72d67 100644
--- a/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc
+++ b/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc
@@ -27,12 +27,16 @@
: payload_type_(config.payload_type),
num_10ms_frames_per_packet_(config.frame_size_ms / 10),
num_10ms_frames_buffered_(0) {
- CHECK(config.frame_size_ms == 20 || config.frame_size_ms == 30)
- << "Frame size must be 20 or 30 ms.";
+ CHECK(config.frame_size_ms == 20 || config.frame_size_ms == 30 ||
+ config.frame_size_ms == 40 || config.frame_size_ms == 60)
+ << "Frame size must be 20, 30, 40, or 60 ms.";
DCHECK_LE(kSampleRateHz / 100 * num_10ms_frames_per_packet_,
kMaxSamplesPerPacket);
CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_));
- CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, config.frame_size_ms));
+ const int encoder_frame_size_ms = config.frame_size_ms > 30
+ ? config.frame_size_ms / 2
+ : config.frame_size_ms;
+ CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms));
}
AudioEncoderIlbc::~AudioEncoderIlbc() {
@@ -57,8 +61,23 @@
size_t max_encoded_bytes,
uint8_t* encoded,
EncodedInfo* info) {
- const size_t expected_output_len =
- num_10ms_frames_per_packet_ == 2 ? 38 : 50;
+ size_t expected_output_len;
+ switch (num_10ms_frames_per_packet_) {
+ case 2:
+ expected_output_len = 38;
+ break;
+ case 3:
+ expected_output_len = 50;
+ break;
+ case 4:
+ expected_output_len = 2 * 38;
+ break;
+ case 6:
+ expected_output_len = 2 * 50;
+ break;
+ default:
+ FATAL();
+ }
DCHECK_GE(max_encoded_bytes, expected_output_len);
// Save timestamp if starting a new packet.
diff --git a/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h b/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h
index 0ecf039..7c2904d 100644
--- a/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h
+++ b/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h
@@ -23,7 +23,9 @@
Config() : payload_type(102), frame_size_ms(30) {}
int payload_type;
- int frame_size_ms;
+ int frame_size_ms; // Valid values are 20, 30, 40, and 60 ms.
+ // Note that frame size 40 ms produces encodings with two 20 ms frames in
+ // them, and frame size 60 ms consists of two 30 ms frames.
};
explicit AudioEncoderIlbc(const Config& config);
@@ -42,7 +44,7 @@
EncodedInfo* info) OVERRIDE;
private:
- static const int kMaxSamplesPerPacket = 240;
+ static const int kMaxSamplesPerPacket = 480;
const int payload_type_;
const int num_10ms_frames_per_packet_;
int num_10ms_frames_buffered_;