OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ | 5 #ifndef CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ |
6 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ | 6 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ |
7 | 7 |
8 #include <alsa/asoundlib.h> | 8 #include <alsa/asoundlib.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 public: | 57 public: |
58 using OnReadyToDeleteCb = base::Callback<void(InputQueue*)>; | 58 using OnReadyToDeleteCb = base::Callback<void(InputQueue*)>; |
59 | 59 |
60 virtual ~InputQueue() {} | 60 virtual ~InputQueue() {} |
61 | 61 |
62 // Returns the sample rate of this stream *before* data is resampled to | 62 // Returns the sample rate of this stream *before* data is resampled to |
63 // match the sample rate expected by the mixer. The returned value must be | 63 // match the sample rate expected by the mixer. The returned value must be |
64 // positive. | 64 // positive. |
65 virtual int input_samples_per_second() const = 0; | 65 virtual int input_samples_per_second() const = 0; |
66 | 66 |
67 // This number will be used to scale the stream before it is mixed. The | |
68 // result must be in the range (0.0, 1.0]. | |
69 virtual float volume_multiplier() const = 0; | |
70 | |
71 // Returns true if the stream is primary. Primary streams will be given | 67 // Returns true if the stream is primary. Primary streams will be given |
72 // precedence for sample rates and will dictate when data is polled. | 68 // precedence for sample rates and will dictate when data is polled. |
73 virtual bool primary() const = 0; | 69 virtual bool primary() const = 0; |
74 | 70 |
75 // Returns true if PrepareToDelete() has been called. | 71 // Returns true if PrepareToDelete() has been called. |
76 virtual bool IsDeleting() const = 0; | 72 virtual bool IsDeleting() const = 0; |
77 | 73 |
78 // Initializes the InputQueue after the mixer is set up. At this point the | 74 // Initializes the InputQueue after the mixer is set up. At this point the |
79 // input can correctly determine the mixer's output sample rate. | 75 // input can correctly determine the mixer's output sample rate. |
80 virtual void Initialize(const MediaPipelineBackendAlsa::RenderingDelay& | 76 virtual void Initialize(const MediaPipelineBackendAlsa::RenderingDelay& |
81 mixer_rendering_delay) = 0; | 77 mixer_rendering_delay) = 0; |
82 | 78 |
83 // Returns the maximum number of frames that can be read from this input | 79 // Returns the maximum number of frames that can be read from this input |
84 // stream without filling with zeros. This should return 0 if the queue is | 80 // stream without filling with zeros. This should return 0 if the queue is |
85 // empty and EOS has not been queued. | 81 // empty and EOS has not been queued. |
86 virtual int MaxReadSize() = 0; | 82 virtual int MaxReadSize() = 0; |
87 | 83 |
88 // Pulls data from the input stream. The input stream should populate |dest| | 84 // Pulls data from the input stream. The input stream should populate |dest| |
89 // with |frames| frames of data to be mixed. The mixer expects data to be | 85 // with |frames| frames of data to be mixed. The mixer expects data to be |
90 // at a sample rate of |output_samples_per_second()|, so each input stream | 86 // at a sample rate of |output_samples_per_second()|, so each input stream |
91 // should resample as necessary before returning. |frames| is guaranteed to | 87 // should resample as necessary before returning. |frames| is guaranteed to |
92 // be no larger than the value returned by the most recent call to | 88 // be no larger than the value returned by the most recent call to |
93 // MaxReadSize(), and |dest->frames()| shall be >= |frames|. | 89 // MaxReadSize(), and |dest->frames()| shall be >= |frames|. |
94 virtual void GetResampledData(::media::AudioBus* dest, int frames) = 0; | 90 virtual void GetResampledData(::media::AudioBus* dest, int frames) = 0; |
95 | 91 |
| 92 // Scale |frames| frames at |src| by the current volume (smoothing as |
| 93 // needed). Add the scaled result to |dest|. |
| 94 virtual void VolumeScaleAccumulate(const float* src, |
| 95 int frames, |
| 96 float* dest) = 0; |
| 97 |
96 // This is called for every InputQueue when the mixer writes data to ALSA | 98 // This is called for every InputQueue when the mixer writes data to ALSA |
97 // for any of its input streams. | 99 // for any of its input streams. |
98 virtual void AfterWriteFrames( | 100 virtual void AfterWriteFrames( |
99 const MediaPipelineBackendAlsa::RenderingDelay& | 101 const MediaPipelineBackendAlsa::RenderingDelay& |
100 mixer_rendering_delay) = 0; | 102 mixer_rendering_delay) = 0; |
101 | 103 |
102 // This will be called when a fatal error occurs in the mixer. | 104 // This will be called when a fatal error occurs in the mixer. |
103 virtual void SignalError(StreamMixerAlsaInput::MixerError error) = 0; | 105 virtual void SignalError(StreamMixerAlsaInput::MixerError error) = 0; |
104 | 106 |
105 // Notifies the input that it is being removed by the upper layers, and | 107 // Notifies the input that it is being removed by the upper layers, and |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 std::unique_ptr<AudioFilterInterface> pre_loopback_filter_; | 240 std::unique_ptr<AudioFilterInterface> pre_loopback_filter_; |
239 std::unique_ptr<AudioFilterInterface> post_loopback_filter_; | 241 std::unique_ptr<AudioFilterInterface> post_loopback_filter_; |
240 | 242 |
241 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa); | 243 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsa); |
242 }; | 244 }; |
243 | 245 |
244 } // namespace media | 246 } // namespace media |
245 } // namespace chromecast | 247 } // namespace chromecast |
246 | 248 |
247 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ | 249 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_H_ |
OLD | NEW |