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

Unified Diff: webrtc/modules/audio_coding/codecs/audio_decoder.cc

Issue 2281453002: Moved codec-specific audio packet splitting into decoders. (Closed)
Patch Set: 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/codecs/audio_decoder.cc
diff --git a/webrtc/modules/audio_coding/codecs/audio_decoder.cc b/webrtc/modules/audio_coding/codecs/audio_decoder.cc
index 442ddc1e4b86b081653da168b363bf26e6bc9683..434ac287f1326f822e68c481ab21e8d4ebb3622a 100644
--- a/webrtc/modules/audio_coding/codecs/audio_decoder.cc
+++ b/webrtc/modules/audio_coding/codecs/audio_decoder.cc
@@ -65,6 +65,11 @@ int AudioDecoder::IncomingPacket(const uint8_t* payload,
return 0;
}
+AudioDecoder::PacketSplits AudioDecoder::SplitPacket(const uint8_t* payload,
+ size_t payload_len) const {
+ return {PacketSplit{0, payload_len, 0}};
+}
+
int AudioDecoder::ErrorCode() { return 0; }
int AudioDecoder::PacketDuration(const uint8_t* encoded,
@@ -95,4 +100,42 @@ AudioDecoder::SpeechType AudioDecoder::ConvertSpeechType(int16_t type) {
}
}
+AudioDecoder::PacketSplits AudioDecoder::SplitBySamples(
+ const uint8_t* payload,
+ size_t payload_len,
+ size_t bytes_per_ms,
+ uint32_t timestamps_per_ms) {
kwiberg-webrtc 2016/08/26 12:39:24 This is the sort of function that should have a un
ossu 2016/08/26 13:05:29 It does. Several of them even. Though, granted, it
kwiberg-webrtc 2016/08/26 22:05:13 It's arguably not a unit test of this function in
+ PacketSplits splits;
+ RTC_DCHECK(payload);
+
+ size_t split_size_bytes = payload_len;
+
+ // Find a "chunk size" >= 20 ms and < 40 ms.
+ size_t min_chunk_size = bytes_per_ms * 20;
kwiberg-webrtc 2016/08/26 12:39:24 const
ossu 2016/08/26 13:05:29 Hey, don't blame me, I just clean up around here!
kwiberg-webrtc 2016/08/26 22:05:13 Yeah, I think I wrote this comment before I realiz
+ // Reduce the split size by half as long as |split_size_bytes| is at least
+ // twice the minimum chunk size (so that the resulting size is at least as
+ // large as the minimum chunk size).
+ while (split_size_bytes >= 2 * min_chunk_size) {
+ split_size_bytes >>= 1;
kwiberg-webrtc 2016/08/26 12:39:24 Less cleverly written as split_size_bytes /= 2; I
ossu 2016/08/26 13:05:29 Yeah, I mean the code can be improved but I've aim
kwiberg-webrtc 2016/08/26 22:05:13 sgtm.
+ }
+ uint32_t timestamps_per_chunk = static_cast<uint32_t>(
kwiberg-webrtc 2016/08/26 12:39:24 const
+ split_size_bytes * timestamps_per_ms / bytes_per_ms);
+ PacketSplit split = {0, split_size_bytes, 0};
+ size_t len = payload_len;
+ for (len = payload_len;
+ len >= (2 * split_size_bytes);
+ len -= split_size_bytes) {
+ splits.push_back(split);
+ split.byte_offset += split_size_bytes;
+ split.timestamp_offset += timestamps_per_chunk;
+ }
+
+ if (len > 0) {
+ split.num_bytes = len;
+ splits.push_back(split);
+ }
+
+ return splits;
+}
+
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698