Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.h" | |
| 12 | |
| 13 #include "webrtc/base/checks.h" | |
| 14 #include "webrtc/base/safe_conversions.h" | |
| 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | |
| 16 | |
| 17 namespace webrtc { | |
| 18 namespace test { | |
| 19 | |
| 20 int FakeDecodeFromFile::DecodeInternal(const uint8_t* encoded, | |
| 21 size_t encoded_len, | |
| 22 int /*sample_rate_hz*/, | |
| 23 int16_t* decoded, | |
| 24 SpeechType* speech_type) { | |
| 25 RTC_CHECK_GE(encoded_len, 8u); | |
| 26 uint32_t timestamp_to_decode = | |
| 27 ByteReader<uint32_t>::ReadLittleEndian(encoded); | |
| 28 uint32_t samples_to_decode = | |
| 29 ByteReader<uint32_t>::ReadLittleEndian(&encoded[4]); | |
| 30 | |
| 31 if (next_timestamp_from_input_ && | |
| 32 timestamp_to_decode != *next_timestamp_from_input_) { | |
|
ivoc
2016/06/14 16:39:56
Why would this happen?
hlundin-webrtc
2016/06/17 10:30:08
This happens when packets are lost (through simula
| |
| 33 uint32_t jump = timestamp_to_decode - *next_timestamp_from_input_; | |
| 34 RTC_CHECK(input_->Seek(jump)); | |
| 35 } | |
| 36 | |
| 37 RTC_CHECK(input_->Read(static_cast<size_t>(samples_to_decode), decoded)); | |
| 38 next_timestamp_from_input_ = | |
| 39 rtc::Optional<uint32_t>(timestamp_to_decode + samples_to_decode); | |
| 40 | |
| 41 if (stereo_) { | |
| 42 InputAudioFile::DuplicateInterleaved(decoded, samples_to_decode, 2, | |
| 43 decoded); | |
| 44 samples_to_decode *= 2; | |
| 45 } | |
| 46 | |
| 47 *speech_type = kSpeech; | |
| 48 return samples_to_decode; | |
| 49 } | |
| 50 | |
| 51 void FakeDecodeFromFile::PrepareEncoded(uint32_t timestamp, | |
| 52 size_t samples, | |
| 53 rtc::ArrayView<uint8_t> encoded) { | |
| 54 RTC_CHECK_GE(encoded.size(), 8u); | |
| 55 ByteWriter<uint32_t>::WriteLittleEndian(&encoded[0], timestamp); | |
| 56 ByteWriter<uint32_t>::WriteLittleEndian(&encoded[4], | |
| 57 rtc::checked_cast<uint32_t>(samples)); | |
| 58 } | |
| 59 | |
| 60 } // namespace test | |
| 61 } // namespace webrtc | |
| OLD | NEW |