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

Side by Side Diff: content/renderer/media/audio_input_device.h

Issue 7661017: Refactor AudioInputDevice to remove race conditions and allow more flexible calling sequences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Removed Stop call in destructor. Added DCHECK instead. Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Low-latency audio capturing unit utilizing audio input stream provided 5 // Low-latency audio capturing unit utilizing audio input stream provided
6 // by browser process through IPC. 6 // by browser process through IPC.
7 // 7 //
8 // Relationship of classes. 8 // Relationship of classes.
9 // 9 //
10 // AudioInputController AudioInputDevice 10 // AudioInputController AudioInputDevice
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "base/basictypes.h" 52 #include "base/basictypes.h"
53 #include "base/memory/scoped_ptr.h" 53 #include "base/memory/scoped_ptr.h"
54 #include "base/shared_memory.h" 54 #include "base/shared_memory.h"
55 #include "base/threading/simple_thread.h" 55 #include "base/threading/simple_thread.h"
56 #include "content/renderer/media/audio_input_message_filter.h" 56 #include "content/renderer/media/audio_input_message_filter.h"
57 57
58 struct AudioParameters; 58 struct AudioParameters;
59 59
60 // TODO(henrika): This class is based on the AudioDevice class and it has 60 // TODO(henrika): This class is based on the AudioDevice class and it has
61 // many components in common. Investigate potential for re-factoring. 61 // many components in common. Investigate potential for re-factoring.
62 // TODO(henrika): Add support for event handling (e.g. OnStateChanged,
63 // OnCaptureStopped etc.) and ensure that we can deliver these notifications
64 // to any clients using this class.
62 class AudioInputDevice 65 class AudioInputDevice
63 : public AudioInputMessageFilter::Delegate, 66 : public AudioInputMessageFilter::Delegate,
64 public base::DelegateSimpleThread::Delegate, 67 public base::DelegateSimpleThread::Delegate,
65 public base::RefCountedThreadSafe<AudioInputDevice> { 68 public base::RefCountedThreadSafe<AudioInputDevice> {
66 public: 69 public:
67 class CaptureCallback { 70 class CaptureCallback {
68 public: 71 public:
69 virtual void Capture(const std::vector<float*>& audio_data, 72 virtual void Capture(const std::vector<float*>& audio_data,
70 size_t number_of_frames, 73 size_t number_of_frames,
71 size_t audio_delay_milliseconds) = 0; 74 size_t audio_delay_milliseconds) = 0;
72 protected: 75 protected:
73 virtual ~CaptureCallback() {} 76 virtual ~CaptureCallback() {}
74 }; 77 };
75 78
76 // Methods called on main render thread ------------------------------------- 79 // Methods called on main render thread -------------------------------------
77 AudioInputDevice(size_t buffer_size, 80 AudioInputDevice(size_t buffer_size,
78 int channels, 81 int channels,
79 double sample_rate, 82 double sample_rate,
80 CaptureCallback* callback); 83 CaptureCallback* callback);
81 virtual ~AudioInputDevice(); 84 virtual ~AudioInputDevice();
82 85
83 // Starts audio capturing. Returns |true| on success. 86 // Starts audio capturing.
84 bool Start(); 87 void Start();
85 88
86 // Stops audio capturing. Returns |true| on success. 89 // Stops audio capturing. Returns |true| on success.
87 bool Stop(); 90 bool Stop();
88 91
89 // Sets the capture volume scaling, with range [0.0, 1.0] inclusive. 92 // Sets the capture volume scaling, with range [0.0, 1.0] inclusive.
90 // Returns |true| on success. 93 // Returns |true| on success.
91 bool SetVolume(double volume); 94 bool SetVolume(double volume);
92 95
93 // Gets the capture volume scaling, with range [0.0, 1.0] inclusive. 96 // Gets the capture volume scaling, with range [0.0, 1.0] inclusive.
94 // Returns |true| on success. 97 // Returns |true| on success.
95 bool GetVolume(double* volume); 98 bool GetVolume(double* volume);
96 99
97 double sample_rate() const { return sample_rate_; } 100 double sample_rate() const { return sample_rate_; }
98 size_t buffer_size() const { return buffer_size_; } 101 size_t buffer_size() const { return buffer_size_; }
99 102
100 // Methods called on IO thread ---------------------------------------------- 103 // Methods called on IO thread ----------------------------------------------
101 // AudioInputMessageFilter::Delegate impl., called by AudioInputMessageFilter 104 // AudioInputMessageFilter::Delegate impl., called by AudioInputMessageFilter
102 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, 105 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle,
103 base::SyncSocket::Handle socket_handle, 106 base::SyncSocket::Handle socket_handle,
104 uint32 length); 107 uint32 length);
105 virtual void OnVolume(double volume); 108 virtual void OnVolume(double volume);
106 109
107 private: 110 private:
108 // Methods called on IO thread ---------------------------------------------- 111 // Methods called on IO thread ----------------------------------------------
109 // The following methods are tasks posted on the IO thread that needs to 112 // The following methods are tasks posted on the IO thread that needs to
110 // be executed on that thread. They interact with AudioInputMessageFilter and 113 // be executed on that thread. They interact with AudioInputMessageFilter and
111 // sends IPC messages on that thread. 114 // sends IPC messages on that thread.
112 void InitializeOnIOThread(const AudioParameters& params); 115 void InitializeOnIOThread(const AudioParameters& params);
113 void StartOnIOThread(); 116 void StartOnIOThread();
114 void ShutDownOnIOThread(); 117 void ShutDownOnIOThread(base::WaitableEvent* completion);
115 void SetVolumeOnIOThread(double volume); 118 void SetVolumeOnIOThread(double volume);
116 119
117 void Send(IPC::Message* message); 120 void Send(IPC::Message* message);
118 121
119 // Method called on the audio thread ---------------------------------------- 122 // Method called on the audio thread ----------------------------------------
120 // Calls the client's callback for capturing audio. 123 // Calls the client's callback for capturing audio.
121 void FireCaptureCallback(); 124 void FireCaptureCallback();
122 125
123 // DelegateSimpleThread::Delegate implementation. 126 // DelegateSimpleThread::Delegate implementation.
124 virtual void Run(); 127 virtual void Run();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // Our stream ID on the message filter. Only modified on the IO thread. 159 // Our stream ID on the message filter. Only modified on the IO thread.
157 int32 stream_id_; 160 int32 stream_id_;
158 161
159 scoped_ptr<base::SharedMemory> shared_memory_; 162 scoped_ptr<base::SharedMemory> shared_memory_;
160 scoped_ptr<base::SyncSocket> socket_; 163 scoped_ptr<base::SyncSocket> socket_;
161 164
162 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); 165 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice);
163 }; 166 };
164 167
165 #endif // CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_ 168 #endif // CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/audio_input_device.cc » ('j') | content/renderer/media/audio_input_device.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698