Chromium Code Reviews| Index: webrtc/modules/audio_coding/codecs/split_by_samples.cc |
| diff --git a/webrtc/modules/audio_coding/codecs/split_by_samples.cc b/webrtc/modules/audio_coding/codecs/split_by_samples.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6c4f6796f62486dd695ad94240065ac9f3d9f2ba |
| --- /dev/null |
| +++ b/webrtc/modules/audio_coding/codecs/split_by_samples.cc |
| @@ -0,0 +1,55 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/modules/audio_coding/codecs/split_by_samples.h" |
| + |
| +namespace webrtc { |
| + |
| +namespace internal { |
| + |
| +std::vector<AudioDecoder::PacketSplit> SplitBySamples( |
| + rtc::ArrayView<const uint8_t> payload, |
| + size_t bytes_per_ms, |
| + uint32_t timestamps_per_ms) { |
| + RTC_DCHECK(payload.data()); |
| + std::vector<AudioDecoder::PacketSplit> splits; |
| + size_t split_size_bytes = payload.size(); |
| + |
| + // Find a "chunk size" >= 20 ms and < 40 ms. |
| + size_t min_chunk_size = bytes_per_ms * 20; |
|
kwiberg-webrtc
2016/09/12 02:11:01
const
ossu
2016/09/12 11:26:37
Acknowledged.
|
| + // 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; |
| + } |
| + uint32_t timestamps_per_chunk = static_cast<uint32_t>( |
|
kwiberg-webrtc
2016/09/12 02:11:01
const
ossu
2016/09/12 11:26:37
Acknowledged.
|
| + split_size_bytes * timestamps_per_ms / bytes_per_ms); |
| + AudioDecoder::PacketSplit split = {0, split_size_bytes, 0}; |
| + size_t len = payload.size(); |
| + for (len = payload.size(); |
|
kwiberg-webrtc
2016/09/12 02:11:01
You initialize twice.
ossu
2016/09/12 11:26:37
Would you look at that!
|
| + 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 internal |
| + |
| +} // namespace webrtc |