blob: ce480c1554dac7038d1b3c6cedb57dd1b9649732 [file] [log] [blame]
stefan@webrtc.orgb082ade2013-11-18 11:45:11 +00001/*
2 * Copyright (c) 2013 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#ifndef WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_
11#define WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_
12
13#include <string>
14
Peter Boströmf2f82832015-05-01 13:00:41 +020015#include "webrtc/base/criticalsection.h"
Peter Boström8c38e8b2015-11-26 17:45:47 +010016#include "webrtc/base/platform_thread.h"
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000017#include "webrtc/base/scoped_ptr.h"
stefan@webrtc.orgb082ade2013-11-18 11:45:11 +000018#include "webrtc/modules/audio_device/include/fake_audio_device.h"
stefan@webrtc.orgb082ade2013-11-18 11:45:11 +000019#include "webrtc/typedefs.h"
20
21namespace webrtc {
22
23class Clock;
Peter Boström64c03662015-04-08 11:24:19 +020024class EventTimerWrapper;
stefan@webrtc.orgb082ade2013-11-18 11:45:11 +000025class FileWrapper;
26class ModuleFileUtility;
stefan@webrtc.orgb082ade2013-11-18 11:45:11 +000027
28namespace test {
29
30class FakeAudioDevice : public FakeAudioDeviceModule {
31 public:
32 FakeAudioDevice(Clock* clock, const std::string& filename);
33
34 virtual ~FakeAudioDevice();
35
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000036 int32_t Init() override;
37 int32_t RegisterAudioCallback(AudioTransport* callback) override;
stefan@webrtc.orgb082ade2013-11-18 11:45:11 +000038
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000039 bool Playing() const override;
40 int32_t PlayoutDelay(uint16_t* delay_ms) const override;
41 bool Recording() const override;
stefan@webrtc.orgb082ade2013-11-18 11:45:11 +000042
43 void Start();
44 void Stop();
45
46 private:
47 static bool Run(void* obj);
48 void CaptureAudio();
49
50 static const uint32_t kFrequencyHz = 16000;
Peter Kastingdce40cf2015-08-24 14:52:23 -070051 static const size_t kBufferSizeBytes = 2 * kFrequencyHz;
stefan@webrtc.orgb082ade2013-11-18 11:45:11 +000052
53 AudioTransport* audio_callback_;
54 bool capturing_;
55 int8_t captured_audio_[kBufferSizeBytes];
56 int8_t playout_buffer_[kBufferSizeBytes];
57 int64_t last_playout_ms_;
58
59 Clock* clock_;
Peter Boström64c03662015-04-08 11:24:19 +020060 rtc::scoped_ptr<EventTimerWrapper> tick_;
pbos5ad935c2016-01-25 03:52:44 -080061 rtc::CriticalSection lock_;
Peter Boström8c38e8b2015-11-26 17:45:47 +010062 rtc::PlatformThread thread_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000063 rtc::scoped_ptr<ModuleFileUtility> file_utility_;
64 rtc::scoped_ptr<FileWrapper> input_stream_;
stefan@webrtc.orgb082ade2013-11-18 11:45:11 +000065};
66} // namespace test
67} // namespace webrtc
68
69#endif // WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_