stefan@webrtc.org | e028410 | 2013-11-18 11:45:11 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | #include "webrtc/modules/audio_device/include/fake_audio_device.h" |
| 16 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 17 | #include "webrtc/typedefs.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | class Clock; |
| 22 | class CriticalSectionWrapper; |
| 23 | class EventWrapper; |
| 24 | class FileWrapper; |
| 25 | class ModuleFileUtility; |
| 26 | class ThreadWrapper; |
| 27 | |
| 28 | namespace test { |
| 29 | |
| 30 | class FakeAudioDevice : public FakeAudioDeviceModule { |
| 31 | public: |
| 32 | FakeAudioDevice(Clock* clock, const std::string& filename); |
| 33 | |
| 34 | virtual ~FakeAudioDevice(); |
| 35 | |
| 36 | virtual int32_t Init() OVERRIDE; |
| 37 | virtual int32_t RegisterAudioCallback(AudioTransport* callback) OVERRIDE; |
| 38 | |
| 39 | virtual bool Playing() const OVERRIDE; |
| 40 | virtual int32_t PlayoutDelay(uint16_t* delay_ms) const OVERRIDE; |
| 41 | virtual bool Recording() const OVERRIDE; |
| 42 | |
| 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; |
| 51 | static const uint32_t kBufferSizeBytes = 2 * kFrequencyHz; |
| 52 | |
| 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_; |
| 60 | scoped_ptr<EventWrapper> tick_; |
| 61 | scoped_ptr<CriticalSectionWrapper> lock_; |
| 62 | scoped_ptr<ThreadWrapper> thread_; |
| 63 | scoped_ptr<ModuleFileUtility> file_utility_; |
| 64 | scoped_ptr<FileWrapper> input_stream_; |
| 65 | }; |
| 66 | } // namespace test |
| 67 | } // namespace webrtc |
| 68 | |
| 69 | #endif // WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ |