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_) { |
| 33 // A gap in the timestamp sequence is detected. Skip the same number of |
| 34 // samples from the file. |
| 35 uint32_t jump = timestamp_to_decode - *next_timestamp_from_input_; |
| 36 RTC_CHECK(input_->Seek(jump)); |
| 37 } |
| 38 |
| 39 RTC_CHECK(input_->Read(static_cast<size_t>(samples_to_decode), decoded)); |
| 40 next_timestamp_from_input_ = |
| 41 rtc::Optional<uint32_t>(timestamp_to_decode + samples_to_decode); |
| 42 |
| 43 if (stereo_) { |
| 44 InputAudioFile::DuplicateInterleaved(decoded, samples_to_decode, 2, |
| 45 decoded); |
| 46 samples_to_decode *= 2; |
| 47 } |
| 48 |
| 49 *speech_type = kSpeech; |
| 50 return samples_to_decode; |
| 51 } |
| 52 |
| 53 void FakeDecodeFromFile::PrepareEncoded(uint32_t timestamp, |
| 54 size_t samples, |
| 55 rtc::ArrayView<uint8_t> encoded) { |
| 56 RTC_CHECK_GE(encoded.size(), 8u); |
| 57 ByteWriter<uint32_t>::WriteLittleEndian(&encoded[0], timestamp); |
| 58 ByteWriter<uint32_t>::WriteLittleEndian(&encoded[4], |
| 59 rtc::checked_cast<uint32_t>(samples)); |
| 60 } |
| 61 |
| 62 } // namespace test |
| 63 } // namespace webrtc |
OLD | NEW |