1e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org/*
2e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org *
4e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org *  Use of this source code is governed by a BSD-style license
5e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org *  that can be found in the LICENSE file in the root of the source
6e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org *  tree. An additional intellectual property rights grant can be found
7e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org *  in the file PATENTS.  All contributing project authors may
8e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
9e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org */
10e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org#ifndef WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_
11e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org#define WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_
12e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
13e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org#include <string>
14e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
15e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org#include "webrtc/modules/audio_device/include/fake_audio_device.h"
16e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org#include "webrtc/system_wrappers/interface/scoped_ptr.h"
17e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org#include "webrtc/typedefs.h"
18e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
19e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.orgnamespace webrtc {
20e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
21e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.orgclass Clock;
22e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.orgclass CriticalSectionWrapper;
23e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.orgclass EventWrapper;
24e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.orgclass FileWrapper;
25e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.orgclass ModuleFileUtility;
26e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.orgclass ThreadWrapper;
27e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
28e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.orgnamespace test {
29e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
30e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.orgclass FakeAudioDevice : public FakeAudioDeviceModule {
31e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org public:
32e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  FakeAudioDevice(Clock* clock, const std::string& filename);
33e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
34e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  virtual ~FakeAudioDevice();
35e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
36e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  virtual int32_t Init() OVERRIDE;
37e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  virtual int32_t RegisterAudioCallback(AudioTransport* callback) OVERRIDE;
38e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
39e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  virtual bool Playing() const OVERRIDE;
40e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  virtual int32_t PlayoutDelay(uint16_t* delay_ms) const OVERRIDE;
41e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  virtual bool Recording() const OVERRIDE;
42e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
43e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  void Start();
44e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  void Stop();
45e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
46e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org private:
47e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  static bool Run(void* obj);
48e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  void CaptureAudio();
49e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
50e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  static const uint32_t kFrequencyHz = 16000;
51e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  static const uint32_t kBufferSizeBytes = 2 * kFrequencyHz;
52e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
53e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  AudioTransport* audio_callback_;
54e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  bool capturing_;
55e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  int8_t captured_audio_[kBufferSizeBytes];
56e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  int8_t playout_buffer_[kBufferSizeBytes];
57e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  int64_t last_playout_ms_;
58e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
59e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  Clock* clock_;
60e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  scoped_ptr<EventWrapper> tick_;
61e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  scoped_ptr<CriticalSectionWrapper> lock_;
62e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  scoped_ptr<ThreadWrapper> thread_;
63e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  scoped_ptr<ModuleFileUtility> file_utility_;
64e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org  scoped_ptr<FileWrapper> input_stream_;
65e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org};
66e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org}  // namespace test
67e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org}  // namespace webrtc
68e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org
69e028410838cd976c75e379b3c2e2eb0ac52b3c99stefan@webrtc.org#endif  // WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_
70