| OLD | NEW |
| 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 CONTENT_RENDERER_MEDIA_TRACK_AUDIO_RENDERER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_TRACK_AUDIO_RENDERER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_TRACK_AUDIO_RENDERER_H_ | 6 #define CONTENT_RENDERER_MEDIA_TRACK_AUDIO_RENDERER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 20 #include "content/public/renderer/media_stream_audio_renderer.h" | 20 #include "content/public/renderer/media_stream_audio_renderer.h" |
| 21 #include "content/public/renderer/media_stream_audio_sink.h" | 21 #include "content/public/renderer/media_stream_audio_sink.h" |
| 22 #include "media/base/audio_renderer_sink.h" | 22 #include "media/base/audio_renderer_sink.h" |
| 23 #include "media/base/output_device.h" | 23 #include "media/base/output_device.h" |
| 24 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 24 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 25 | 25 |
| 26 namespace media { | 26 namespace media { |
| 27 class AudioBus; | 27 class AudioBus; |
| 28 class AudioShifter; | 28 class AudioShifter; |
| 29 class AudioOutputDevice; | |
| 30 class AudioParameters; | 29 class AudioParameters; |
| 31 } | 30 } |
| 32 | 31 |
| 33 namespace content { | 32 namespace content { |
| 34 | 33 |
| 35 // TrackAudioRenderer is a MediaStreamAudioRenderer for plumbing audio data | 34 // TrackAudioRenderer is a MediaStreamAudioRenderer for plumbing audio data |
| 36 // generated from either local or remote (but not PeerConnection/WebRTC-sourced) | 35 // generated from either local or remote (but not PeerConnection/WebRTC-sourced) |
| 37 // MediaStreamAudioTracks to an audio output device, reconciling differences in | 36 // MediaStreamAudioTracks to an audio output device, reconciling differences in |
| 38 // the rates of production and consumption of the audio data. Note that remote | 37 // the rates of production and consumption of the audio data. Note that remote |
| 39 // PeerConnection-sourced tracks are NOT rendered by this implementation (see | 38 // PeerConnection-sourced tracks are NOT rendered by this implementation (see |
| 40 // MediaStreamRendererFactoryImpl). | 39 // MediaStreamRendererFactoryImpl). |
| 41 // | 40 // |
| 42 // This class uses AudioDeviceFactory to create media::AudioOutputDevices and | 41 // This class uses AudioDeviceFactory to create media::AudioRendererSink and |
| 43 // owns/manages their lifecycles. Output devices are automatically re-created | 42 // owns/manages their lifecycles. Output devices are automatically re-created |
| 44 // in response to audio format changes, or use of the SwitchOutputDevice() API | 43 // in response to audio format changes, or use of the SwitchOutputDevice() API |
| 45 // by client code. | 44 // by client code. |
| 46 // | 45 // |
| 47 // Audio data is feed-in from the source via calls to OnData(). The | 46 // Audio data is feed-in from the source via calls to OnData(). The |
| 48 // internally-owned media::AudioOutputDevice calls Render() to pull-out that | 47 // internally-owned media::AudioOutputDevice calls Render() to pull-out that |
| 49 // audio data. However, because of clock differences and other environmental | 48 // audio data. However, because of clock differences and other environmental |
| 50 // factors, the audio will inevitably feed-in at a rate different from the rate | 49 // factors, the audio will inevitably feed-in at a rate different from the rate |
| 51 // it is being rendered-out. media::AudioShifter is used to buffer, stretch | 50 // it is being rendered-out. media::AudioShifter is used to buffer, stretch |
| 52 // and skip audio to maintain time synchronization between the producer and | 51 // and skip audio to maintain time synchronization between the producer and |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 135 |
| 137 // The render view and frame in which the audio is rendered into |sink_|. | 136 // The render view and frame in which the audio is rendered into |sink_|. |
| 138 const int playout_render_frame_id_; | 137 const int playout_render_frame_id_; |
| 139 const int session_id_; | 138 const int session_id_; |
| 140 | 139 |
| 141 // MessageLoop associated with the single thread that performs all control | 140 // MessageLoop associated with the single thread that performs all control |
| 142 // tasks. Set to the MessageLoop that invoked the ctor. | 141 // tasks. Set to the MessageLoop that invoked the ctor. |
| 143 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 142 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 144 | 143 |
| 145 // The sink (destination) for rendered audio. | 144 // The sink (destination) for rendered audio. |
| 146 scoped_refptr<media::AudioOutputDevice> sink_; | 145 scoped_refptr<media::AudioRendererSink> sink_; |
| 147 | 146 |
| 148 // This does all the synchronization/resampling/smoothing. | 147 // This does all the synchronization/resampling/smoothing. |
| 149 scoped_ptr<media::AudioShifter> audio_shifter_; | 148 scoped_ptr<media::AudioShifter> audio_shifter_; |
| 150 | 149 |
| 151 // These track the time duration of all the audio rendered so far by this | 150 // These track the time duration of all the audio rendered so far by this |
| 152 // instance. |prior_elapsed_render_time_| tracks the time duration of all | 151 // instance. |prior_elapsed_render_time_| tracks the time duration of all |
| 153 // audio rendered before the last format change. |num_samples_rendered_| | 152 // audio rendered before the last format change. |num_samples_rendered_| |
| 154 // tracks the number of audio samples rendered since the last format change. | 153 // tracks the number of audio samples rendered since the last format change. |
| 155 base::TimeDelta prior_elapsed_render_time_; | 154 base::TimeDelta prior_elapsed_render_time_; |
| 156 int64_t num_samples_rendered_; | 155 int64_t num_samples_rendered_; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 180 | 179 |
| 181 // Used to DCHECK that some methods are called on the audio thread. | 180 // Used to DCHECK that some methods are called on the audio thread. |
| 182 base::ThreadChecker audio_thread_checker_; | 181 base::ThreadChecker audio_thread_checker_; |
| 183 | 182 |
| 184 DISALLOW_COPY_AND_ASSIGN(TrackAudioRenderer); | 183 DISALLOW_COPY_AND_ASSIGN(TrackAudioRenderer); |
| 185 }; | 184 }; |
| 186 | 185 |
| 187 } // namespace content | 186 } // namespace content |
| 188 | 187 |
| 189 #endif // CONTENT_RENDERER_MEDIA_TRACK_AUDIO_RENDERER_H_ | 188 #endif // CONTENT_RENDERER_MEDIA_TRACK_AUDIO_RENDERER_H_ |
| OLD | NEW |