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

Side by Side Diff: media/base/audio_renderer_mixer_input.h

Issue 1748183006: Add lock to fix race in AudioRendererMixerInput. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 #ifndef MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ 5 #ifndef MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_
6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ 6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/synchronization/lock.h"
12 #include "media/base/audio_converter.h" 13 #include "media/base/audio_converter.h"
13 #include "media/base/audio_renderer_sink.h" 14 #include "media/base/audio_renderer_sink.h"
14 #include "media/base/output_device.h" 15 #include "media/base/output_device.h"
15 #include "url/origin.h" 16 #include "url/origin.h"
16 17
17 namespace media { 18 namespace media {
18 19
19 class AudioRendererMixer; 20 class AudioRendererMixer;
20 21
21 class MEDIA_EXPORT AudioRendererMixerInput 22 class MEDIA_EXPORT AudioRendererMixerInput
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 63
63 // Called by AudioRendererMixer when an error occurs. 64 // Called by AudioRendererMixer when an error occurs.
64 void OnRenderError(); 65 void OnRenderError();
65 66
66 protected: 67 protected:
67 ~AudioRendererMixerInput() override; 68 ~AudioRendererMixerInput() override;
68 69
69 private: 70 private:
70 friend class AudioRendererMixerInputTest; 71 friend class AudioRendererMixerInputTest;
71 72
73 // AudioConverter::InputCallback implementation.
74 double ProvideInput(AudioBus* audio_bus,
75 base::TimeDelta buffer_delay) override;
76
77 // The implementation for these methods is split out to avoid re-entrant
78 // locking when called by multiple internal callers. Re-entrant locking is
79 // not supported with base::Lock.
80 void Stop_Locked();
81 void Play_Locked();
82 void Pause_Locked();
83 void SwitchOutputDevice_Locked(const std::string& device_id,
84 const url::Origin& security_origin,
85 const SwitchOutputDeviceCB& callback);
86
87 // This class is used by both media thread (e.g. SetVolume) and audio device
88 // thread (e.g. ProvideInput).
89 base::Lock lock_;
90
91 // ---------------[ All variables below protected by |lock_| ]---------------
92
72 bool started_; 93 bool started_;
73 bool playing_; 94 bool playing_;
74 double volume_; 95 double volume_;
75 96
76 // AudioConverter::InputCallback implementation.
77 double ProvideInput(AudioBus* audio_bus,
78 base::TimeDelta buffer_delay) override;
79 97
80 // Callbacks provided during construction which allow AudioRendererMixerInput 98 // Callbacks provided during construction which allow AudioRendererMixerInput
81 // to retrieve a mixer during Initialize() and notify when it's done with it. 99 // to retrieve a mixer during Initialize() and notify when it's done with it.
82 const GetMixerCB get_mixer_cb_; 100 const GetMixerCB get_mixer_cb_;
83 const RemoveMixerCB remove_mixer_cb_; 101 const RemoveMixerCB remove_mixer_cb_;
84 102
85 // Callbacks provided during construction which allows AudioRendererMixerInput 103 // Callbacks provided during construction which allows AudioRendererMixerInput
86 // to access hardware output parameters when it is detached from the mixer. 104 // to access hardware output parameters when it is detached from the mixer.
87 const GetHardwareParamsCB get_hardware_params_cb_; 105 const GetHardwareParamsCB get_hardware_params_cb_;
88 106
(...skipping 19 matching lines...) Expand all
108 SwitchOutputDeviceCB pending_switch_callback_; 126 SwitchOutputDeviceCB pending_switch_callback_;
109 std::string pending_switch_device_id_; 127 std::string pending_switch_device_id_;
110 url::Origin pending_switch_security_origin_; 128 url::Origin pending_switch_security_origin_;
111 129
112 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInput); 130 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInput);
113 }; 131 };
114 132
115 } // namespace media 133 } // namespace media
116 134
117 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_ 135 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/audio_renderer_mixer_input.cc » ('j') | media/base/audio_renderer_mixer_input.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698