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

Side by Side Diff: media/audio/audio_output_device.cc

Issue 2038053002: Change audio render thread checking to use new AudioRendererSink::BelongsToRendererThread() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review (tommi@). Created 4 years, 6 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/audio/audio_output_device.h" 5 #include "media/audio/audio_output_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 21 matching lines...) Expand all
32 base::SharedMemoryHandle memory, 32 base::SharedMemoryHandle memory,
33 int memory_length, 33 int memory_length,
34 AudioRendererSink::RenderCallback* render_callback); 34 AudioRendererSink::RenderCallback* render_callback);
35 ~AudioThreadCallback() override; 35 ~AudioThreadCallback() override;
36 36
37 void MapSharedMemory() override; 37 void MapSharedMemory() override;
38 38
39 // Called whenever we receive notifications about pending data. 39 // Called whenever we receive notifications about pending data.
40 void Process(uint32_t pending_data) override; 40 void Process(uint32_t pending_data) override;
41 41
42 // Returns whether the current thread is the audio device thread or not.
43 // Will always return true if DCHECKs are not enabled.
44 bool CurrentThreadIsAudioDeviceThread();
45
42 private: 46 private:
43 AudioRendererSink::RenderCallback* render_callback_; 47 AudioRendererSink::RenderCallback* render_callback_;
44 std::unique_ptr<AudioBus> output_bus_; 48 std::unique_ptr<AudioBus> output_bus_;
45 uint64_t callback_num_; 49 uint64_t callback_num_;
46 50
47 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); 51 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback);
48 }; 52 };
49 53
50 AudioOutputDevice::AudioOutputDevice( 54 AudioOutputDevice::AudioOutputDevice(
51 std::unique_ptr<AudioOutputIPC> ipc, 55 std::unique_ptr<AudioOutputIPC> ipc,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 OutputDeviceInfo AudioOutputDevice::GetOutputDeviceInfo() { 147 OutputDeviceInfo AudioOutputDevice::GetOutputDeviceInfo() {
144 CHECK(!task_runner()->BelongsToCurrentThread()); 148 CHECK(!task_runner()->BelongsToCurrentThread());
145 did_receive_auth_.Wait(); 149 did_receive_auth_.Wait();
146 return OutputDeviceInfo(AudioDeviceDescription::UseSessionIdToSelectDevice( 150 return OutputDeviceInfo(AudioDeviceDescription::UseSessionIdToSelectDevice(
147 session_id_, device_id_) 151 session_id_, device_id_)
148 ? matched_device_id_ 152 ? matched_device_id_
149 : device_id_, 153 : device_id_,
150 device_status_, output_params_); 154 device_status_, output_params_);
151 } 155 }
152 156
157 bool AudioOutputDevice::CurrentThreadIsRenderingThread() {
158 // Since this function is supposed to be called on the rendering thread,
DaleCurtis 2016/06/14 17:07:49 Hmm, seems like this should have a DCHECK(CurrentT
Henrik Grunell 2016/06/14 19:33:41 Yes, a failure could be confusing if that happens.
DaleCurtis 2016/06/14 20:07:16 I'd just add some text to the DCHECK() on the audi
Henrik Grunell 2016/06/15 07:17:54 Done.
159 // it's safe to access |audio_callback_| here. It will always be valid when
160 // the rendering thread is running.
161 return audio_callback_->CurrentThreadIsAudioDeviceThread();
162 }
163
153 void AudioOutputDevice::RequestDeviceAuthorizationOnIOThread() { 164 void AudioOutputDevice::RequestDeviceAuthorizationOnIOThread() {
154 DCHECK(task_runner()->BelongsToCurrentThread()); 165 DCHECK(task_runner()->BelongsToCurrentThread());
155 DCHECK_EQ(state_, IDLE); 166 DCHECK_EQ(state_, IDLE);
156 state_ = AUTHORIZING; 167 state_ = AUTHORIZING;
157 ipc_->RequestDeviceAuthorization(this, session_id_, device_id_, 168 ipc_->RequestDeviceAuthorization(this, session_id_, device_id_,
158 security_origin_); 169 security_origin_);
159 } 170 }
160 171
161 void AudioOutputDevice::CreateStreamOnIOThread(const AudioParameters& params) { 172 void AudioOutputDevice::CreateStreamOnIOThread(const AudioParameters& params) {
162 DCHECK(task_runner()->BelongsToCurrentThread()); 173 DCHECK(task_runner()->BelongsToCurrentThread());
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 << " frames_skipped:" << frames_skipped; 454 << " frames_skipped:" << frames_skipped;
444 455
445 // Update the audio-delay measurement, inform about the number of skipped 456 // Update the audio-delay measurement, inform about the number of skipped
446 // frames, and ask client to render audio. Since |output_bus_| is wrapping 457 // frames, and ask client to render audio. Since |output_bus_| is wrapping
447 // the shared memory the Render() call is writing directly into the shared 458 // the shared memory the Render() call is writing directly into the shared
448 // memory. 459 // memory.
449 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), 460 render_callback_->Render(output_bus_.get(), std::round(frames_delayed),
450 frames_skipped); 461 frames_skipped);
451 } 462 }
452 463
464 bool AudioOutputDevice::AudioThreadCallback::
465 CurrentThreadIsAudioDeviceThread() {
466 return thread_checker_.CalledOnValidThread();
467 }
468
453 } // namespace media 469 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698