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

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

Issue 9805001: Move media/audio files into media namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
« no previous file with comments | « content/renderer/media/audio_device.h ('k') | content/renderer/media/audio_device_thread.h » ('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 (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 "content/renderer/media/audio_device.h" 5 #include "content/renderer/media/audio_device.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "content/common/child_process.h" 11 #include "content/common/child_process.h"
12 #include "content/common/media/audio_messages.h" 12 #include "content/common/media/audio_messages.h"
13 #include "content/common/view_messages.h" 13 #include "content/common/view_messages.h"
14 #include "content/renderer/render_thread_impl.h" 14 #include "content/renderer/render_thread_impl.h"
15 #include "media/audio/audio_output_controller.h" 15 #include "media/audio/audio_output_controller.h"
16 #include "media/audio/audio_util.h" 16 #include "media/audio/audio_util.h"
17 17
18 using media::AudioRendererSink; 18 using media::AudioRendererSink;
19 19
20 // Takes care of invoking the render callback on the audio thread. 20 // Takes care of invoking the render callback on the audio thread.
21 // An instance of this class is created for each capture stream in 21 // An instance of this class is created for each capture stream in
22 // OnStreamCreated(). 22 // OnStreamCreated().
23 class AudioDevice::AudioThreadCallback 23 class AudioDevice::AudioThreadCallback
24 : public AudioDeviceThread::Callback { 24 : public AudioDeviceThread::Callback {
25 public: 25 public:
26 AudioThreadCallback(const AudioParameters& audio_parameters, 26 AudioThreadCallback(const media::AudioParameters& audio_parameters,
27 base::SharedMemoryHandle memory, 27 base::SharedMemoryHandle memory,
28 int memory_length, 28 int memory_length,
29 AudioRendererSink::RenderCallback* render_callback); 29 AudioRendererSink::RenderCallback* render_callback);
30 virtual ~AudioThreadCallback(); 30 virtual ~AudioThreadCallback();
31 31
32 virtual void MapSharedMemory() OVERRIDE; 32 virtual void MapSharedMemory() OVERRIDE;
33 33
34 // Called whenever we receive notifications about pending data. 34 // Called whenever we receive notifications about pending data.
35 virtual void Process(int pending_data) OVERRIDE; 35 virtual void Process(int pending_data) OVERRIDE;
36 36
37 private: 37 private:
38 AudioRendererSink::RenderCallback* render_callback_; 38 AudioRendererSink::RenderCallback* render_callback_;
39 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); 39 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback);
40 }; 40 };
41 41
42 AudioDevice::AudioDevice() 42 AudioDevice::AudioDevice()
43 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()), 43 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()),
44 callback_(NULL), 44 callback_(NULL),
45 volume_(1.0), 45 volume_(1.0),
46 stream_id_(0), 46 stream_id_(0),
47 play_on_start_(true), 47 play_on_start_(true),
48 is_started_(false) { 48 is_started_(false) {
49 filter_ = RenderThreadImpl::current()->audio_message_filter(); 49 filter_ = RenderThreadImpl::current()->audio_message_filter();
50 } 50 }
51 51
52 AudioDevice::AudioDevice(const AudioParameters& params, 52 AudioDevice::AudioDevice(const media::AudioParameters& params,
53 RenderCallback* callback) 53 RenderCallback* callback)
54 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()), 54 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()),
55 audio_parameters_(params), 55 audio_parameters_(params),
56 callback_(callback), 56 callback_(callback),
57 volume_(1.0), 57 volume_(1.0),
58 stream_id_(0), 58 stream_id_(0),
59 play_on_start_(true), 59 play_on_start_(true),
60 is_started_(false) { 60 is_started_(false) {
61 filter_ = RenderThreadImpl::current()->audio_message_filter(); 61 filter_ = RenderThreadImpl::current()->audio_message_filter();
62 } 62 }
63 63
64 void AudioDevice::Initialize(const AudioParameters& params, 64 void AudioDevice::Initialize(const media::AudioParameters& params,
65 RenderCallback* callback) { 65 RenderCallback* callback) {
66 CHECK_EQ(0, stream_id_) << 66 CHECK_EQ(0, stream_id_) <<
67 "AudioDevice::Initialize() must be called before Start()"; 67 "AudioDevice::Initialize() must be called before Start()";
68 68
69 CHECK(!callback_); // Calling Initialize() twice? 69 CHECK(!callback_); // Calling Initialize() twice?
70 70
71 audio_parameters_ = params; 71 audio_parameters_ = params;
72 // TODO(xians): We have to hard code the sample format to 16 since the 72 // TODO(xians): We have to hard code the sample format to 16 since the
73 // current audio path does not support sample formats rather than 16bits per 73 // current audio path does not support sample formats rather than 16bits per
74 // channel. Remove it if the problem is fixed. 74 // channel. Remove it if the problem is fixed.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 volume_ = volume; 123 volume_ = volume;
124 124
125 return true; 125 return true;
126 } 126 }
127 127
128 void AudioDevice::GetVolume(double* volume) { 128 void AudioDevice::GetVolume(double* volume) {
129 // Return a locally cached version of the current scaling factor. 129 // Return a locally cached version of the current scaling factor.
130 *volume = volume_; 130 *volume = volume_;
131 } 131 }
132 132
133 void AudioDevice::InitializeOnIOThread(const AudioParameters& params) { 133 void AudioDevice::InitializeOnIOThread(const media::AudioParameters& params) {
134 DCHECK(message_loop()->BelongsToCurrentThread()); 134 DCHECK(message_loop()->BelongsToCurrentThread());
135 // Make sure we don't create the stream more than once. 135 // Make sure we don't create the stream more than once.
136 DCHECK_EQ(0, stream_id_); 136 DCHECK_EQ(0, stream_id_);
137 if (stream_id_) 137 if (stream_id_)
138 return; 138 return;
139 139
140 stream_id_ = filter_->AddDelegate(this); 140 stream_id_ = filter_->AddDelegate(this);
141 Send(new AudioHostMsg_CreateStream(stream_id_, params)); 141 Send(new AudioHostMsg_CreateStream(stream_id_, params));
142 } 142 }
143 143
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 255 }
256 256
257 void AudioDevice::WillDestroyCurrentMessageLoop() { 257 void AudioDevice::WillDestroyCurrentMessageLoop() {
258 LOG(ERROR) << "IO loop going away before the audio device has been stopped"; 258 LOG(ERROR) << "IO loop going away before the audio device has been stopped";
259 ShutDownOnIOThread(); 259 ShutDownOnIOThread();
260 } 260 }
261 261
262 // AudioDevice::AudioThreadCallback 262 // AudioDevice::AudioThreadCallback
263 263
264 AudioDevice::AudioThreadCallback::AudioThreadCallback( 264 AudioDevice::AudioThreadCallback::AudioThreadCallback(
265 const AudioParameters& audio_parameters, 265 const media::AudioParameters& audio_parameters,
266 base::SharedMemoryHandle memory, 266 base::SharedMemoryHandle memory,
267 int memory_length, 267 int memory_length,
268 media::AudioRendererSink::RenderCallback* render_callback) 268 media::AudioRendererSink::RenderCallback* render_callback)
269 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length), 269 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length),
270 render_callback_(render_callback) { 270 render_callback_(render_callback) {
271 } 271 }
272 272
273 AudioDevice::AudioThreadCallback::~AudioThreadCallback() { 273 AudioDevice::AudioThreadCallback::~AudioThreadCallback() {
274 } 274 }
275 275
(...skipping 24 matching lines...) Expand all
300 // to the browser process as float, so we don't lose precision for 300 // to the browser process as float, so we don't lose precision for
301 // audio hardware which has better than 16bit precision. 301 // audio hardware which has better than 16bit precision.
302 int16* data = reinterpret_cast<int16*>(shared_memory_.memory()); 302 int16* data = reinterpret_cast<int16*>(shared_memory_.memory());
303 media::InterleaveFloatToInt16(audio_data_, data, 303 media::InterleaveFloatToInt16(audio_data_, data,
304 audio_parameters_.frames_per_buffer()); 304 audio_parameters_.frames_per_buffer());
305 305
306 // Let the host know we are done. 306 // Let the host know we are done.
307 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, 307 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_,
308 num_frames * audio_parameters_.channels() * sizeof(data[0])); 308 num_frames * audio_parameters_.channels() * sizeof(data[0]));
309 } 309 }
OLDNEW
« no previous file with comments | « content/renderer/media/audio_device.h ('k') | content/renderer/media/audio_device_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698