ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "test/mock_audio_encoder.h" |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 12 | |
| 13 | namespace webrtc { |
| 14 | |
ossu | eb1fde4 | 2017-05-02 06:46:30 -0700 | [diff] [blame] | 15 | MockAudioEncoder::MockAudioEncoder() = default; |
| 16 | MockAudioEncoder::~MockAudioEncoder() { |
| 17 | Die(); |
| 18 | } |
| 19 | |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 20 | MockAudioEncoder::FakeEncoding::FakeEncoding( |
| 21 | const AudioEncoder::EncodedInfo& info) |
ossu | eb1fde4 | 2017-05-02 06:46:30 -0700 | [diff] [blame] | 22 | : info_(info) {} |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 23 | |
| 24 | MockAudioEncoder::FakeEncoding::FakeEncoding(size_t encoded_bytes) { |
| 25 | info_.encoded_bytes = encoded_bytes; |
| 26 | } |
| 27 | |
| 28 | AudioEncoder::EncodedInfo MockAudioEncoder::FakeEncoding::operator()( |
| 29 | uint32_t timestamp, |
| 30 | rtc::ArrayView<const int16_t> audio, |
| 31 | rtc::Buffer* encoded) { |
| 32 | encoded->SetSize(encoded->size() + info_.encoded_bytes); |
| 33 | return info_; |
| 34 | } |
| 35 | |
ossu | eb1fde4 | 2017-05-02 06:46:30 -0700 | [diff] [blame] | 36 | MockAudioEncoder::CopyEncoding::~CopyEncoding() = default; |
| 37 | |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 38 | MockAudioEncoder::CopyEncoding::CopyEncoding( |
| 39 | AudioEncoder::EncodedInfo info, |
| 40 | rtc::ArrayView<const uint8_t> payload) |
ossu | eb1fde4 | 2017-05-02 06:46:30 -0700 | [diff] [blame] | 41 | : info_(info), payload_(payload) {} |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 42 | |
| 43 | MockAudioEncoder::CopyEncoding::CopyEncoding( |
| 44 | rtc::ArrayView<const uint8_t> payload) |
| 45 | : payload_(payload) { |
| 46 | info_.encoded_bytes = payload_.size(); |
| 47 | } |
| 48 | |
| 49 | AudioEncoder::EncodedInfo MockAudioEncoder::CopyEncoding::operator()( |
| 50 | uint32_t timestamp, |
| 51 | rtc::ArrayView<const int16_t> audio, |
| 52 | rtc::Buffer* encoded) { |
| 53 | RTC_CHECK(encoded); |
| 54 | RTC_CHECK_LE(info_.encoded_bytes, payload_.size()); |
| 55 | encoded->AppendData(payload_.data(), info_.encoded_bytes); |
| 56 | return info_; |
| 57 | } |
| 58 | |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 59 | } // namespace webrtc |