Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: webrtc/test/fake_audio_device.cc

Issue 1674413004: Added A/V sync tests with drifting clocks. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: drift replaced by speed Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/test/fake_audio_device.h" 11 #include "webrtc/test/fake_audio_device.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webrtc/base/platform_thread.h" 16 #include "webrtc/base/platform_thread.h"
17 #include "webrtc/modules/media_file/media_file_utility.h" 17 #include "webrtc/modules/media_file/media_file_utility.h"
18 #include "webrtc/system_wrappers/include/clock.h" 18 #include "webrtc/system_wrappers/include/clock.h"
19 #include "webrtc/system_wrappers/include/event_wrapper.h" 19 #include "webrtc/system_wrappers/include/event_wrapper.h"
20 #include "webrtc/system_wrappers/include/file_wrapper.h" 20 #include "webrtc/system_wrappers/include/file_wrapper.h"
21 21
22 namespace webrtc { 22 namespace webrtc {
23 namespace test { 23 namespace test {
24 24
25 FakeAudioDevice::FakeAudioDevice(Clock* clock, const std::string& filename) 25 FakeAudioDevice::FakeAudioDevice(Clock* clock,
26 const std::string& filename,
27 float speed)
26 : audio_callback_(NULL), 28 : audio_callback_(NULL),
27 capturing_(false), 29 capturing_(false),
28 captured_audio_(), 30 captured_audio_(),
29 playout_buffer_(), 31 playout_buffer_(),
32 speed_(speed),
30 last_playout_ms_(-1), 33 last_playout_ms_(-1),
31 clock_(clock), 34 drifting_clock_(clock, speed),
35 clock_(speed == DriftingClock::kNoDrift ? clock : &drifting_clock_),
pbos-webrtc 2016/02/10 13:28:14 Just always use the drifting clock if it's a no-op
danilchap 2016/02/10 15:50:19 Simplified. After few failed tries to explain my r
32 tick_(EventTimerWrapper::Create()), 36 tick_(EventTimerWrapper::Create()),
33 thread_(FakeAudioDevice::Run, this, "FakeAudioDevice"), 37 thread_(FakeAudioDevice::Run, this, "FakeAudioDevice"),
34 file_utility_(new ModuleFileUtility(0)), 38 file_utility_(new ModuleFileUtility(0)),
35 input_stream_(FileWrapper::Create()) { 39 input_stream_(FileWrapper::Create()) {
36 memset(captured_audio_, 0, sizeof(captured_audio_)); 40 memset(captured_audio_, 0, sizeof(captured_audio_));
37 memset(playout_buffer_, 0, sizeof(playout_buffer_)); 41 memset(playout_buffer_, 0, sizeof(playout_buffer_));
38 // Open audio input file as read-only and looping. 42 // Open audio input file as read-only and looping.
39 EXPECT_EQ(0, input_stream_->OpenFile(filename.c_str(), true, true)) 43 EXPECT_EQ(0, input_stream_->OpenFile(filename.c_str(), true, true))
40 << filename; 44 << filename;
41 } 45 }
42 46
43 FakeAudioDevice::~FakeAudioDevice() { 47 FakeAudioDevice::~FakeAudioDevice() {
44 Stop(); 48 Stop();
45 49
46 thread_.Stop(); 50 thread_.Stop();
47 } 51 }
48 52
49 int32_t FakeAudioDevice::Init() { 53 int32_t FakeAudioDevice::Init() {
50 rtc::CritScope cs(&lock_); 54 rtc::CritScope cs(&lock_);
51 if (file_utility_->InitPCMReading(*input_stream_.get()) != 0) 55 if (file_utility_->InitPCMReading(*input_stream_.get()) != 0)
52 return -1; 56 return -1;
53 57
54 if (!tick_->StartTimer(true, 10)) 58 if (!tick_->StartTimer(true, 10 / speed_))
55 return -1; 59 return -1;
56 thread_.Start(); 60 thread_.Start();
57 thread_.SetPriority(rtc::kHighPriority); 61 thread_.SetPriority(rtc::kHighPriority);
58 return 0; 62 return 0;
59 } 63 }
60 64
61 int32_t FakeAudioDevice::RegisterAudioCallback(AudioTransport* callback) { 65 int32_t FakeAudioDevice::RegisterAudioCallback(AudioTransport* callback) {
62 rtc::CritScope cs(&lock_); 66 rtc::CritScope cs(&lock_);
63 audio_callback_ = callback; 67 audio_callback_ = callback;
64 return 0; 68 return 0;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 rtc::CritScope cs(&lock_); 139 rtc::CritScope cs(&lock_);
136 capturing_ = true; 140 capturing_ = true;
137 } 141 }
138 142
139 void FakeAudioDevice::Stop() { 143 void FakeAudioDevice::Stop() {
140 rtc::CritScope cs(&lock_); 144 rtc::CritScope cs(&lock_);
141 capturing_ = false; 145 capturing_ = false;
142 } 146 }
143 } // namespace test 147 } // namespace test
144 } // namespace webrtc 148 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698