OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/base/filter_host.h" | 5 #include "media/base/filter_host.h" |
6 #include "media/filters/audio_renderer_impl.h" | 6 #include "media/filters/audio_renderer_impl.h" |
7 | 7 |
8 namespace media { | 8 namespace media { |
9 | 9 |
10 // We'll try to fill 4096 samples per buffer, which is roughly ~92ms of audio | 10 // We'll try to fill 4096 samples per buffer, which is roughly ~92ms of audio |
11 // data for a 44.1kHz audio source. | 11 // data for a 44.1kHz audio source. |
12 static const size_t kSamplesPerBuffer = 8*1024; | 12 static const size_t kSamplesPerBuffer = 8*1024; |
13 | 13 |
14 AudioRendererImpl::AudioRendererImpl() | 14 AudioRendererImpl::AudioRendererImpl() |
15 : AudioRendererBase(kDefaultMaxQueueSize), | 15 : AudioRendererBase(), |
16 playback_rate_(0.0f), | |
17 stream_(NULL) { | 16 stream_(NULL) { |
18 } | 17 } |
19 | 18 |
20 AudioRendererImpl::~AudioRendererImpl() { | 19 AudioRendererImpl::~AudioRendererImpl() { |
21 // Close down the audio device. | 20 // Close down the audio device. |
22 if (stream_) { | 21 if (stream_) { |
23 stream_->Stop(); | 22 stream_->Stop(); |
24 stream_->Close(); | 23 stream_->Close(); |
25 } | 24 } |
26 } | 25 } |
27 | 26 |
28 bool AudioRendererImpl::IsMediaFormatSupported( | 27 bool AudioRendererImpl::IsMediaFormatSupported( |
29 const MediaFormat& media_format) { | 28 const MediaFormat& media_format) { |
30 int channels; | 29 int channels; |
31 int sample_rate; | 30 int sample_rate; |
32 int sample_bits; | 31 int sample_bits; |
33 return AudioManager::GetAudioManager()->HasAudioDevices() && | 32 return AudioManager::GetAudioManager()->HasAudioDevices() && |
34 ParseMediaFormat(media_format, &channels, &sample_rate, &sample_bits); | 33 ParseMediaFormat(media_format, &channels, &sample_rate, &sample_bits); |
35 } | 34 } |
36 | 35 |
37 void AudioRendererImpl::SetPlaybackRate(float rate) { | 36 void AudioRendererImpl::SetPlaybackRate(float rate) { |
38 // TODO(fbarchard): limit rate to reasonable values | 37 // TODO(fbarchard): limit rate to reasonable values |
39 playback_rate_ = rate; | 38 AudioRendererBase::SetPlaybackRate(rate); |
40 | 39 |
41 static bool started = false; | 40 static bool started = false; |
42 if (rate > 0.0f && !started && stream_) | 41 if (rate > 0.0f && !started && stream_) |
43 stream_->Start(this); | 42 stream_->Start(this); |
44 } | 43 } |
45 | 44 |
46 void AudioRendererImpl::SetVolume(float volume) { | 45 void AudioRendererImpl::SetVolume(float volume) { |
47 if (stream_) | 46 if (stream_) |
48 stream_->SetVolume(volume, volume); | 47 stream_->SetVolume(volume, volume); |
49 } | 48 } |
50 | 49 |
51 size_t AudioRendererImpl::OnMoreData(AudioOutputStream* stream, void* dest_void, | 50 size_t AudioRendererImpl::OnMoreData(AudioOutputStream* stream, void* dest_void, |
52 size_t len) { | 51 size_t len) { |
53 // TODO(scherkus): handle end of stream. | 52 // TODO(scherkus): handle end of stream. |
54 if (!stream_) | 53 if (!stream_) |
55 return 0; | 54 return 0; |
56 | 55 |
57 // TODO(scherkus): Maybe change OnMoreData to pass in char/uint8 or similar. | 56 // TODO(scherkus): Maybe change OnMoreData to pass in char/uint8 or similar. |
58 // TODO(fbarchard): Waveout_output_win.h should handle zero length buffers | 57 // TODO(fbarchard): Waveout_output_win.h should handle zero length buffers |
59 // without clicking. | 58 // without clicking. |
60 return FillBuffer(static_cast<uint8*>(dest_void), len, | 59 return FillBuffer(static_cast<uint8*>(dest_void), len, base::TimeDelta()); |
61 playback_rate_, base::TimeDelta()); | |
62 } | 60 } |
63 | 61 |
64 void AudioRendererImpl::OnClose(AudioOutputStream* stream) { | 62 void AudioRendererImpl::OnClose(AudioOutputStream* stream) { |
65 // TODO(scherkus): implement OnClose. | 63 // TODO(scherkus): implement OnClose. |
66 NOTIMPLEMENTED(); | 64 NOTIMPLEMENTED(); |
67 } | 65 } |
68 | 66 |
69 void AudioRendererImpl::OnError(AudioOutputStream* stream, int code) { | 67 void AudioRendererImpl::OnError(AudioOutputStream* stream, int code) { |
70 // TODO(scherkus): implement OnError. | 68 // TODO(scherkus): implement OnError. |
71 NOTIMPLEMENTED(); | 69 NOTIMPLEMENTED(); |
(...skipping 22 matching lines...) Expand all Loading... |
94 } | 92 } |
95 return true; | 93 return true; |
96 } | 94 } |
97 | 95 |
98 void AudioRendererImpl::OnStop() { | 96 void AudioRendererImpl::OnStop() { |
99 if (stream_) | 97 if (stream_) |
100 stream_->Stop(); | 98 stream_->Stop(); |
101 } | 99 } |
102 | 100 |
103 } // namespace media | 101 } // namespace media |
OLD | NEW |