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 "test/mock_audio_encoder.h"
12 
13 namespace webrtc {
14 
15 MockAudioEncoder::MockAudioEncoder() = default;
16 MockAudioEncoder::~MockAudioEncoder() = default;
17 
FakeEncoding(const AudioEncoder::EncodedInfo & info)18 MockAudioEncoder::FakeEncoding::FakeEncoding(
19     const AudioEncoder::EncodedInfo& info)
20     : info_(info) {}
21 
FakeEncoding(size_t encoded_bytes)22 MockAudioEncoder::FakeEncoding::FakeEncoding(size_t encoded_bytes) {
23   info_.encoded_bytes = encoded_bytes;
24 }
25 
operator ()(uint32_t timestamp,rtc::ArrayView<const int16_t> audio,rtc::Buffer * encoded)26 AudioEncoder::EncodedInfo MockAudioEncoder::FakeEncoding::operator()(
27     uint32_t timestamp,
28     rtc::ArrayView<const int16_t> audio,
29     rtc::Buffer* encoded) {
30   encoded->SetSize(encoded->size() + info_.encoded_bytes);
31   return info_;
32 }
33 
34 MockAudioEncoder::CopyEncoding::~CopyEncoding() = default;
35 
CopyEncoding(AudioEncoder::EncodedInfo info,rtc::ArrayView<const uint8_t> payload)36 MockAudioEncoder::CopyEncoding::CopyEncoding(
37     AudioEncoder::EncodedInfo info,
38     rtc::ArrayView<const uint8_t> payload)
39     : info_(info), payload_(payload) {}
40 
CopyEncoding(rtc::ArrayView<const uint8_t> payload)41 MockAudioEncoder::CopyEncoding::CopyEncoding(
42     rtc::ArrayView<const uint8_t> payload)
43     : payload_(payload) {
44   info_.encoded_bytes = payload_.size();
45 }
46 
operator ()(uint32_t timestamp,rtc::ArrayView<const int16_t> audio,rtc::Buffer * encoded)47 AudioEncoder::EncodedInfo MockAudioEncoder::CopyEncoding::operator()(
48     uint32_t timestamp,
49     rtc::ArrayView<const int16_t> audio,
50     rtc::Buffer* encoded) {
51   RTC_CHECK(encoded);
52   RTC_CHECK_LE(info_.encoded_bytes, payload_.size());
53   encoded->AppendData(payload_.data(), info_.encoded_bytes);
54   return info_;
55 }
56 
57 }  // namespace webrtc
58