2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_MOCK_MOCK_EXTERNAL_DECODER_PCM16B_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_MOCK_MOCK_EXTERNAL_DECODER_PCM16B_H_
14 #include "webrtc/modules/audio_coding/neteq/interface/audio_decoder.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "webrtc/base/constructormagic.h"
18 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h"
19 #include "webrtc/typedefs.h"
24 using ::testing::Invoke;
26 // Implement an external version of the PCM16b decoder. This is a copy from
27 // audio_decoder_impl.{cc, h}.
28 class ExternalPcm16B : public AudioDecoder {
30 explicit ExternalPcm16B(enum NetEqDecoder type)
31 : AudioDecoder(type) {
34 virtual int Decode(const uint8_t* encoded, size_t encoded_len,
35 int16_t* decoded, SpeechType* speech_type) {
37 int16_t ret = WebRtcPcm16b_DecodeW16(
38 state_, reinterpret_cast<int16_t*>(const_cast<uint8_t*>(encoded)),
39 static_cast<int16_t>(encoded_len), decoded, &temp_type);
40 *speech_type = ConvertSpeechType(temp_type);
44 virtual int Init() { return 0; }
47 DISALLOW_COPY_AND_ASSIGN(ExternalPcm16B);
50 // Create a mock of ExternalPcm16B which delegates all calls to the real object.
51 // The reason is that we can then track that the correct calls are being made.
52 class MockExternalPcm16B : public ExternalPcm16B {
54 explicit MockExternalPcm16B(enum NetEqDecoder type)
55 : ExternalPcm16B(type),
57 // By default, all calls are delegated to the real object.
58 ON_CALL(*this, Decode(_, _, _, _))
59 .WillByDefault(Invoke(&real_, &ExternalPcm16B::Decode));
60 ON_CALL(*this, HasDecodePlc())
61 .WillByDefault(Invoke(&real_, &ExternalPcm16B::HasDecodePlc));
62 ON_CALL(*this, DecodePlc(_, _))
63 .WillByDefault(Invoke(&real_, &ExternalPcm16B::DecodePlc));
64 ON_CALL(*this, Init())
65 .WillByDefault(Invoke(&real_, &ExternalPcm16B::Init));
66 ON_CALL(*this, IncomingPacket(_, _, _, _, _))
67 .WillByDefault(Invoke(&real_, &ExternalPcm16B::IncomingPacket));
68 ON_CALL(*this, ErrorCode())
69 .WillByDefault(Invoke(&real_, &ExternalPcm16B::ErrorCode));
70 ON_CALL(*this, codec_type())
71 .WillByDefault(Invoke(&real_, &ExternalPcm16B::codec_type));
73 virtual ~MockExternalPcm16B() { Die(); }
75 MOCK_METHOD0(Die, void());
77 int(const uint8_t* encoded, size_t encoded_len, int16_t* decoded,
78 SpeechType* speech_type));
79 MOCK_CONST_METHOD0(HasDecodePlc,
81 MOCK_METHOD2(DecodePlc,
82 int(int num_frames, int16_t* decoded));
85 MOCK_METHOD5(IncomingPacket,
86 int(const uint8_t* payload, size_t payload_len,
87 uint16_t rtp_sequence_number, uint32_t rtp_timestamp,
88 uint32_t arrival_timestamp));
89 MOCK_METHOD0(ErrorCode,
91 MOCK_CONST_METHOD0(codec_type,
99 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_MOCK_MOCK_EXTERNAL_DECODER_PCM16B_H_