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

Side by Side Diff: content/renderer/media/webrtc_local_audio_track_unittest.cc

Issue 12741012: base: Support setting thread priorities generically. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove static initializers. Created 7 years, 7 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
« no previous file with comments | « chrome_frame/chrome_frame_automation.h ('k') | media/audio/audio_device_thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/synchronization/waitable_event.h" 5 #include "base/synchronization/waitable_event.h"
6 #include "base/test/test_timeouts.h" 6 #include "base/test/test_timeouts.h"
7 #include "content/renderer/media/webrtc_audio_capturer.h" 7 #include "content/renderer/media/webrtc_audio_capturer.h"
8 #include "content/renderer/media/webrtc_local_audio_track.h" 8 #include "content/renderer/media/webrtc_local_audio_track.h"
9 #include "media/audio/audio_parameters.h" 9 #include "media/audio/audio_parameters.h"
10 #include "media/base/audio_bus.h" 10 #include "media/base/audio_bus.h"
(...skipping 12 matching lines...) Expand all
23 ACTION_P(SignalEvent, event) { 23 ACTION_P(SignalEvent, event) {
24 event->Signal(); 24 event->Signal();
25 } 25 }
26 26
27 // A simple thread that we use to fake the audio thread which provides data to 27 // A simple thread that we use to fake the audio thread which provides data to
28 // the |WebRtcAudioCapturer|. 28 // the |WebRtcAudioCapturer|.
29 class FakeAudioThread : public base::PlatformThread::Delegate { 29 class FakeAudioThread : public base::PlatformThread::Delegate {
30 public: 30 public:
31 explicit FakeAudioThread(const scoped_refptr<WebRtcAudioCapturer>& capturer) 31 explicit FakeAudioThread(const scoped_refptr<WebRtcAudioCapturer>& capturer)
32 : capturer_(capturer), 32 : capturer_(capturer),
33 thread_(base::kNullThreadHandle), 33 thread_(),
34 closure_(false, false) { 34 closure_(false, false) {
35 DCHECK(capturer); 35 DCHECK(capturer);
36 audio_bus_ = media::AudioBus::Create(capturer_->audio_parameters()); 36 audio_bus_ = media::AudioBus::Create(capturer_->audio_parameters());
37 } 37 }
38 38
39 virtual ~FakeAudioThread() { DCHECK(!thread_); } 39 virtual ~FakeAudioThread() { DCHECK(thread_.is_null()); }
40 40
41 // base::PlatformThread::Delegate: 41 // base::PlatformThread::Delegate:
42 virtual void ThreadMain() OVERRIDE { 42 virtual void ThreadMain() OVERRIDE {
43 while (true) { 43 while (true) {
44 if (closure_.IsSignaled()) 44 if (closure_.IsSignaled())
45 return; 45 return;
46 46
47 media::AudioCapturerSource::CaptureCallback* callback = 47 media::AudioCapturerSource::CaptureCallback* callback =
48 static_cast<media::AudioCapturerSource::CaptureCallback*>(capturer_); 48 static_cast<media::AudioCapturerSource::CaptureCallback*>(capturer_);
49 audio_bus_->Zero(); 49 audio_bus_->Zero();
50 callback->Capture(audio_bus_.get(), 0, 0); 50 callback->Capture(audio_bus_.get(), 0, 0);
51 51
52 // Sleep 1ms to yield the resource for the main thread. 52 // Sleep 1ms to yield the resource for the main thread.
53 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); 53 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
54 } 54 }
55 } 55 }
56 56
57 void Start() { 57 void Start() {
58 base::PlatformThread::CreateWithPriority( 58 base::PlatformThread::CreateWithPriority(
59 0, this, &thread_, base::kThreadPriority_RealtimeAudio); 59 0, this, &thread_, base::kThreadPriority_RealtimeAudio);
60 CHECK(thread_ != base::kNullThreadHandle); 60 CHECK(!thread_.is_null());
61 } 61 }
62 62
63 void Stop() { 63 void Stop() {
64 closure_.Signal(); 64 closure_.Signal();
65 base::PlatformThread::Join(thread_); 65 base::PlatformThread::Join(thread_);
66 thread_ = base::kNullThreadHandle; 66 thread_ = base::PlatformThreadHandle();
67 } 67 }
68 68
69 private: 69 private:
70 scoped_ptr<media::AudioBus> audio_bus_; 70 scoped_ptr<media::AudioBus> audio_bus_;
71 scoped_refptr<WebRtcAudioCapturer> capturer_; 71 scoped_refptr<WebRtcAudioCapturer> capturer_;
72 base::PlatformThreadHandle thread_; 72 base::PlatformThreadHandle thread_;
73 base::WaitableEvent closure_; 73 base::WaitableEvent closure_;
74 DISALLOW_COPY_AND_ASSIGN(FakeAudioThread); 74 DISALLOW_COPY_AND_ASSIGN(FakeAudioThread);
75 }; 75 };
76 76
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); 232 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout()));
233 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); 233 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout()));
234 234
235 track_1->RemoveSink(sink_1.get()); 235 track_1->RemoveSink(sink_1.get());
236 track_2->RemoveSink(sink_2.get()); 236 track_2->RemoveSink(sink_2.get());
237 track_1 = NULL; 237 track_1 = NULL;
238 track_2 = NULL; 238 track_2 = NULL;
239 } 239 }
240 240
241 } // namespace content 241 } // namespace content
OLDNEW
« no previous file with comments | « chrome_frame/chrome_frame_automation.h ('k') | media/audio/audio_device_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698