19a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org/*
29a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
39a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *
49a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *  Use of this source code is governed by a BSD-style license
59a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *  that can be found in the LICENSE file in the root of the source
69a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *  tree. An additional intellectual property rights grant can be found
79a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *  in the file PATENTS.  All contributing project authors may
89a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
99a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org */
109a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
11e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_MOCK_MOCK_EXTERNAL_DECODER_PCM16B_H_
12e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_MOCK_MOCK_EXTERNAL_DECODER_PCM16B_H_
139a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
14e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#include "webrtc/modules/audio_coding/neteq/interface/audio_decoder.h"
159a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
1649d62206ededc5905d6121d42fdcce8ed665b2c0kjellander@webrtc.org#include "testing/gmock/include/gmock/gmock.h"
17774b3d38a4a0f1a8ec08972a3c543cb5d607ce13henrike@webrtc.org#include "webrtc/base/constructormagic.h"
189a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org#include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h"
199a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org#include "webrtc/typedefs.h"
209a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
219a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgnamespace webrtc {
229a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
239a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgusing ::testing::_;
249a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgusing ::testing::Invoke;
259a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
269a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// Implement an external version of the PCM16b decoder. This is a copy from
279a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// audio_decoder_impl.{cc, h}.
289a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgclass ExternalPcm16B : public AudioDecoder {
299a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org public:
309a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  explicit ExternalPcm16B(enum NetEqDecoder type)
319a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      : AudioDecoder(type) {
329a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
339a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
349a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  virtual int Decode(const uint8_t* encoded, size_t encoded_len,
359a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                     int16_t* decoded, SpeechType* speech_type) {
369a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    int16_t temp_type;
379a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    int16_t ret = WebRtcPcm16b_DecodeW16(
389a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        state_, reinterpret_cast<int16_t*>(const_cast<uint8_t*>(encoded)),
399a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        static_cast<int16_t>(encoded_len), decoded, &temp_type);
409a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    *speech_type = ConvertSpeechType(temp_type);
419a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    return ret;
429a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
439a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
449a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  virtual int Init() { return 0; }
459a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
469a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org private:
479a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  DISALLOW_COPY_AND_ASSIGN(ExternalPcm16B);
489a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org};
499a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
509a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// Create a mock of ExternalPcm16B which delegates all calls to the real object.
519a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// The reason is that we can then track that the correct calls are being made.
529a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgclass MockExternalPcm16B : public ExternalPcm16B {
539a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org public:
549a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  explicit MockExternalPcm16B(enum NetEqDecoder type)
559a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      : ExternalPcm16B(type),
569a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        real_(type) {
579a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    // By default, all calls are delegated to the real object.
589a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    ON_CALL(*this, Decode(_, _, _, _))
599a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        .WillByDefault(Invoke(&real_, &ExternalPcm16B::Decode));
609a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    ON_CALL(*this, HasDecodePlc())
619a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        .WillByDefault(Invoke(&real_, &ExternalPcm16B::HasDecodePlc));
629a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    ON_CALL(*this, DecodePlc(_, _))
639a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        .WillByDefault(Invoke(&real_, &ExternalPcm16B::DecodePlc));
649a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    ON_CALL(*this, Init())
659a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        .WillByDefault(Invoke(&real_, &ExternalPcm16B::Init));
669a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    ON_CALL(*this, IncomingPacket(_, _, _, _, _))
679a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        .WillByDefault(Invoke(&real_, &ExternalPcm16B::IncomingPacket));
689a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    ON_CALL(*this, ErrorCode())
699a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        .WillByDefault(Invoke(&real_, &ExternalPcm16B::ErrorCode));
709a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    ON_CALL(*this, codec_type())
719a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        .WillByDefault(Invoke(&real_, &ExternalPcm16B::codec_type));
729a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
739a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  virtual ~MockExternalPcm16B() { Die(); }
749a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
759a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  MOCK_METHOD0(Die, void());
769a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  MOCK_METHOD4(Decode,
779a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      int(const uint8_t* encoded, size_t encoded_len, int16_t* decoded,
789a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          SpeechType* speech_type));
799a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  MOCK_CONST_METHOD0(HasDecodePlc,
809a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      bool());
819a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  MOCK_METHOD2(DecodePlc,
829a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      int(int num_frames, int16_t* decoded));
839a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  MOCK_METHOD0(Init,
849a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      int());
859a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  MOCK_METHOD5(IncomingPacket,
869a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      int(const uint8_t* payload, size_t payload_len,
879a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          uint16_t rtp_sequence_number, uint32_t rtp_timestamp,
889a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          uint32_t arrival_timestamp));
899a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  MOCK_METHOD0(ErrorCode,
909a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      int());
919a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  MOCK_CONST_METHOD0(codec_type,
929a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      NetEqDecoder());
939a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
949a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org private:
959a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  ExternalPcm16B real_;
969a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org};
979a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
989a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org}  // namespace webrtc
99e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#endif  // WEBRTC_MODULES_AUDIO_CODING_NETEQ_MOCK_MOCK_EXTERNAL_DECODER_PCM16B_H_
100