Index: webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.cc |
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.cc b/webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.cc |
index dab5805f98afcc41eaa714d49e4cd8baec5ebe59..b4bd59911f6439337c647093f0b358af52e3af98 100644 |
--- a/webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.cc |
+++ b/webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.cc |
@@ -11,7 +11,9 @@ |
#include "webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.h" |
#include "webrtc/base/checks.h" |
+#include "webrtc/base/logging.h" |
#include "webrtc/modules/audio_coding/codecs/ilbc/ilbc.h" |
+#include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h" |
namespace webrtc { |
@@ -49,6 +51,53 @@ void AudioDecoderIlbc::Reset() { |
WebRtcIlbcfix_Decoderinit30Ms(dec_state_); |
} |
+std::vector<AudioDecoder::ParseResult> AudioDecoderIlbc::ParsePayload( |
+ rtc::Buffer&& payload, |
+ uint32_t timestamp, |
+ bool is_primary) { |
+ std::vector<ParseResult> results; |
+ size_t bytes_per_frame; |
+ int timestamps_per_frame; |
+ if (payload.size() >= 950) { |
+ LOG(LS_WARNING) << "AudioDecoderIlbc::ParsePayload: Payload too large"; |
+ return results; |
+ } |
+ if (payload.size() % 38 == 0) { |
+ // 20 ms frames. |
+ bytes_per_frame = 38; |
+ timestamps_per_frame = 160; |
+ } else if (payload.size() % 50 == 0) { |
+ // 30 ms frames. |
+ bytes_per_frame = 50; |
+ timestamps_per_frame = 240; |
+ } else { |
+ LOG(LS_WARNING) << "AudioDecoderIlbc::ParsePayload: Invalid payload"; |
+ return results; |
+ } |
+ |
+ RTC_DCHECK_EQ(0u, payload.size() % bytes_per_frame); |
+ if (payload.size() == bytes_per_frame) { |
+ std::unique_ptr<EncodedAudioFrame> frame( |
+ new LegacyEncodedAudioFrame(this, std::move(payload), is_primary)); |
+ results.emplace_back(timestamp, is_primary, std::move(frame)); |
+ } else { |
+ size_t byte_offset; |
+ uint32_t timestamp_offset; |
+ for (byte_offset = 0, timestamp_offset = 0; |
+ byte_offset < payload.size(); |
+ byte_offset += bytes_per_frame, |
+ timestamp_offset += timestamps_per_frame) { |
+ rtc::Buffer new_payload(payload.data() + byte_offset, bytes_per_frame); |
+ std::unique_ptr<EncodedAudioFrame> frame(new LegacyEncodedAudioFrame( |
+ this, std::move(new_payload), is_primary)); |
+ results.emplace_back(timestamp + timestamp_offset, is_primary, |
+ std::move(frame)); |
+ } |
+ } |
+ |
+ return results; |
+} |
+ |
int AudioDecoderIlbc::SampleRateHz() const { |
return 8000; |
} |