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

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

Issue 8980008: Integrate HTMLMediaElement with Web Audio API's MediaElementAudioSourceNode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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 // Audio rendering unit utilizing AudioDevice. 5 // Audio rendering unit utilizing AudioDevice.
6 // 6 //
7 // This class lives inside three threads during it's lifetime, namely: 7 // This class lives inside three threads during it's lifetime, namely:
8 // 1. Render thread. 8 // 1. Render thread.
9 // This object is created on the render thread. 9 // This object is created on the render thread.
10 // 2. Pipeline thread 10 // 2. Pipeline thread
11 // OnInitialize() is called here with the audio format. 11 // OnInitialize() is called here with the audio format.
12 // Play/Pause/Seek also happens here. 12 // Play/Pause/Seek also happens here.
13 // 3. Audio thread created by the AudioDevice. 13 // 3. Audio thread created by the AudioDevice.
14 // Render() is called here where audio data is decoded into raw PCM data. 14 // Render() is called here where audio data is decoded into raw PCM data.
15 15
16 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_IMPL_H_ 16 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_IMPL_H_
17 #define CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_IMPL_H_ 17 #define CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_IMPL_H_
18 #pragma once 18 #pragma once
19 19
20 #include <vector> 20 #include <vector>
21 21
22 #include "base/gtest_prod_util.h" 22 #include "base/gtest_prod_util.h"
23 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
24 #include "base/synchronization/lock.h" 24 #include "base/synchronization/lock.h"
25 #include "content/renderer/media/audio_device.h" 25 #include "content/renderer/media/audio_device.h"
26 #include "media/audio/audio_io.h" 26 #include "media/audio/audio_io.h"
27 #include "media/audio/audio_parameters.h" 27 #include "media/audio/audio_parameters.h"
28 #include "media/base/audio_renderer_sink.h"
28 #include "media/filters/audio_renderer_base.h" 29 #include "media/filters/audio_renderer_base.h"
29 30
30 class AudioMessageFilter; 31 class AudioMessageFilter;
31 32
32 class CONTENT_EXPORT AudioRendererImpl 33 class CONTENT_EXPORT AudioRendererImpl
33 : public media::AudioRendererBase, 34 : public media::AudioRendererBase,
34 public AudioDevice::RenderCallback { 35 public media::AudioRendererSink::RenderCallback {
35 public: 36 public:
36 // Methods called on Render thread ------------------------------------------ 37 // Methods called on Render thread ------------------------------------------
37 AudioRendererImpl(); 38 // An AudioRendererSink is used as the destination for the rendered audio.
39 explicit AudioRendererImpl(media::AudioRendererSink* sink);
38 virtual ~AudioRendererImpl(); 40 virtual ~AudioRendererImpl();
39 41
40 // Methods called on pipeline thread ---------------------------------------- 42 // Methods called on pipeline thread ----------------------------------------
41 // media::Filter implementation. 43 // media::Filter implementation.
42 virtual void SetPlaybackRate(float rate) OVERRIDE; 44 virtual void SetPlaybackRate(float rate) OVERRIDE;
43 virtual void Pause(const base::Closure& callback) OVERRIDE; 45 virtual void Pause(const base::Closure& callback) OVERRIDE;
44 virtual void Seek(base::TimeDelta time, 46 virtual void Seek(base::TimeDelta time,
45 const media::FilterStatusCB& cb) OVERRIDE; 47 const media::FilterStatusCB& cb) OVERRIDE;
46 virtual void Play(const base::Closure& callback) OVERRIDE; 48 virtual void Play(const base::Closure& callback) OVERRIDE;
47 49
(...skipping 19 matching lines...) Expand all
67 // Helper methods. 69 // Helper methods.
68 // Convert number of bytes to duration of time using information about the 70 // Convert number of bytes to duration of time using information about the
69 // number of channels, sample rate and sample bits. 71 // number of channels, sample rate and sample bits.
70 base::TimeDelta ConvertToDuration(int bytes); 72 base::TimeDelta ConvertToDuration(int bytes);
71 73
72 // Methods called on pipeline thread ---------------------------------------- 74 // Methods called on pipeline thread ----------------------------------------
73 void DoPlay(); 75 void DoPlay();
74 void DoPause(); 76 void DoPause();
75 void DoSeek(); 77 void DoSeek();
76 78
77 // AudioDevice::RenderCallback implementation. 79 // media::AudioRendererSink::RenderCallback implementation.
78 virtual size_t Render(const std::vector<float*>& audio_data, 80 virtual size_t Render(const std::vector<float*>& audio_data,
79 size_t number_of_frames, 81 size_t number_of_frames,
80 size_t audio_delay_milliseconds) OVERRIDE; 82 size_t audio_delay_milliseconds) OVERRIDE;
81 83
82 // Accessors used by tests. 84 // Accessors used by tests.
83 base::Time earliest_end_time() const { 85 base::Time earliest_end_time() const {
84 return earliest_end_time_; 86 return earliest_end_time_;
85 } 87 }
86 88
87 void set_earliest_end_time(const base::Time& earliest_end_time) { 89 void set_earliest_end_time(const base::Time& earliest_end_time) {
88 earliest_end_time_ = earliest_end_time; 90 earliest_end_time_ = earliest_end_time;
89 } 91 }
90 92
91 uint32 bytes_per_second() const { 93 uint32 bytes_per_second() const {
92 return bytes_per_second_; 94 return bytes_per_second_;
93 } 95 }
94 96
95 // Estimate earliest time when current buffer can stop playing. 97 // Estimate earliest time when current buffer can stop playing.
96 void UpdateEarliestEndTime(int bytes_filled, 98 void UpdateEarliestEndTime(int bytes_filled,
97 base::TimeDelta request_delay, 99 base::TimeDelta request_delay,
98 base::Time time_now); 100 base::Time time_now);
99 101
100 // Used to calculate audio delay given bytes. 102 // Used to calculate audio delay given bytes.
101 uint32 bytes_per_second_; 103 uint32 bytes_per_second_;
102 104
103 // A flag that indicates this filter is called to stop. 105 // A flag that indicates this filter is called to stop.
104 bool stopped_; 106 bool stopped_;
105 107
106 // audio_device_ is the sink (destination) for rendered audio. 108 // The sink (destination) for rendered audio.
107 scoped_refptr<AudioDevice> audio_device_; 109 scoped_refptr<media::AudioRendererSink> sink_;
110
111 // Set to true when OnInitialize() is called.
112 bool is_initialized_;
108 113
109 // We're supposed to know amount of audio data OS or hardware buffered, but 114 // We're supposed to know amount of audio data OS or hardware buffered, but
110 // that is not always so -- on my Linux box 115 // that is not always so -- on my Linux box
111 // AudioBuffersState::hardware_delay_bytes never reaches 0. 116 // AudioBuffersState::hardware_delay_bytes never reaches 0.
112 // 117 //
113 // As a result we cannot use it to find when stream ends. If we just ignore 118 // As a result we cannot use it to find when stream ends. If we just ignore
114 // buffered data we will notify host that stream ended before it is actually 119 // buffered data we will notify host that stream ended before it is actually
115 // did so, I've seen it done ~140ms too early when playing ~150ms file. 120 // did so, I've seen it done ~140ms too early when playing ~150ms file.
116 // 121 //
117 // Instead of trying to invent OS-specific solution for each and every OS we 122 // Instead of trying to invent OS-specific solution for each and every OS we
118 // are supporting, use simple workaround: every time we fill the buffer we 123 // are supporting, use simple workaround: every time we fill the buffer we
119 // remember when it should stop playing, and do not assume that buffer is 124 // remember when it should stop playing, and do not assume that buffer is
120 // empty till that time. Workaround is not bulletproof, as we don't exactly 125 // empty till that time. Workaround is not bulletproof, as we don't exactly
121 // know when that particular data would start playing, but it is much better 126 // know when that particular data would start playing, but it is much better
122 // than nothing. 127 // than nothing.
123 base::Time earliest_end_time_; 128 base::Time earliest_end_time_;
124 129
125 AudioParameters audio_parameters_; 130 AudioParameters audio_parameters_;
126 131
127 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); 132 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl);
128 }; 133 };
129 134
130 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_IMPL_H_ 135 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698