| 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_INPUT_IMPL_H_ | 5 #ifndef CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_INPUT_IMPL_H_ |
| 6 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_INPUT_IMPL_H_ | 6 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_INPUT_IMPL_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | |
| 11 | 10 |
| 12 #include "base/callback.h" | 11 #include "base/callback.h" |
| 13 #include "base/macros.h" | 12 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 16 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 17 #include "chromecast/media/cma/backend/alsa/media_pipeline_backend_alsa.h" | 16 #include "chromecast/media/cma/backend/alsa/media_pipeline_backend_alsa.h" |
| 18 #include "chromecast/media/cma/backend/alsa/slew_volume.h" | 17 #include "chromecast/media/cma/backend/alsa/slew_volume.h" |
| 19 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h" | 18 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h" |
| 20 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input.h" | 19 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input.h" |
| 21 | 20 |
| 22 namespace base { | 21 namespace base { |
| 23 class SingleThreadTaskRunner; | 22 class SingleThreadTaskRunner; |
| 24 } // namespace base | 23 } // namespace base |
| 25 | 24 |
| 26 namespace media { | 25 namespace media { |
| 27 class AudioBus; | 26 class AudioBus; |
| 28 class MultiChannelResampler; | 27 class MultiChannelResampler; |
| 29 } // namespace media | 28 } // namespace media |
| 30 | 29 |
| 31 namespace chromecast { | 30 namespace chromecast { |
| 32 namespace media { | 31 namespace media { |
| 33 | 32 |
| 34 class FilterGroup; | |
| 35 | |
| 36 // Input queue implementation for StreamMixerAlsa. Each input source pushes | 33 // Input queue implementation for StreamMixerAlsa. Each input source pushes |
| 37 // frames to an instance of StreamMixerAlsaInputImpl; this then signals the | 34 // frames to an instance of StreamMixerAlsaInputImpl; this then signals the |
| 38 // mixer to pull as much data as possible from all input queues, and mix it and | 35 // mixer to pull as much data as possible from all input queues, and mix it and |
| 39 // write it out to the ALSA stack. The delegate's OnWritePcmCompletion() method | 36 // write it out to the ALSA stack. The delegate's OnWritePcmCompletion() method |
| 40 // is called (on the caller thread) whenever data has been successfully added to | 37 // is called (on the caller thread) whenever data has been successfully added to |
| 41 // the queue (this may not happen immediately if the queue's maximum size limit | 38 // the queue (this may not happen immediately if the queue's maximum size limit |
| 42 // has been exceeded). | 39 // has been exceeded). |
| 43 // | 40 // |
| 44 // If an input is being resampled, it is conservative about how much data it can | 41 // If an input is being resampled, it is conservative about how much data it can |
| 45 // provide to be written. This is because the resampler buffers some data | 42 // provide to be written. This is because the resampler buffers some data |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 kStatePaused, // Currently paused. | 83 kStatePaused, // Currently paused. |
| 87 kStateGotEos, // Got the end-of-stream buffer (normal playback). | 84 kStateGotEos, // Got the end-of-stream buffer (normal playback). |
| 88 kStateFinalFade, // Fading out to a deleted state. | 85 kStateFinalFade, // Fading out to a deleted state. |
| 89 kStateDeleted, // Told the mixer to delete this. | 86 kStateDeleted, // Told the mixer to delete this. |
| 90 kStateError, // A mixer error occurred, this is unusable now. | 87 kStateError, // A mixer error occurred, this is unusable now. |
| 91 }; | 88 }; |
| 92 | 89 |
| 93 StreamMixerAlsaInputImpl(StreamMixerAlsaInput::Delegate* delegate, | 90 StreamMixerAlsaInputImpl(StreamMixerAlsaInput::Delegate* delegate, |
| 94 int input_samples_per_second, | 91 int input_samples_per_second, |
| 95 bool primary, | 92 bool primary, |
| 96 const std::string& device_id, | |
| 97 StreamMixerAlsa* mixer); | 93 StreamMixerAlsa* mixer); |
| 98 | 94 |
| 99 ~StreamMixerAlsaInputImpl() override; | 95 ~StreamMixerAlsaInputImpl() override; |
| 100 | 96 |
| 101 // Queues some PCM data to be mixed. |data| must be in planar float format. | 97 // Queues some PCM data to be mixed. |data| must be in planar float format. |
| 102 void WritePcm(const scoped_refptr<DecoderBufferBase>& data); | 98 void WritePcm(const scoped_refptr<DecoderBufferBase>& data); |
| 103 | 99 |
| 104 // Sets the pause state of this stream. | 100 // Sets the pause state of this stream. |
| 105 void SetPaused(bool paused); | 101 void SetPaused(bool paused); |
| 106 | 102 |
| 107 // Sets the volume multiplier for this stream. If |multiplier| < 0, sets the | 103 // Sets the volume multiplier for this stream. If |multiplier| < 0, sets the |
| 108 // volume multiplier to 0. If |multiplier| > 1, sets the volume multiplier | 104 // volume multiplier to 0. If |multiplier| > 1, sets the volume multiplier |
| 109 // to 1. | 105 // to 1. |
| 110 void SetVolumeMultiplier(float multiplier); | 106 void SetVolumeMultiplier(float multiplier); |
| 111 | 107 |
| 112 // Prevents any further calls to the delegate (ie, called when the delegate | 108 // Prevents any further calls to the delegate (ie, called when the delegate |
| 113 // is being destroyed). | 109 // is being destroyed). |
| 114 void PreventDelegateCalls(); | 110 void PreventDelegateCalls(); |
| 115 | 111 |
| 116 State state() const { return state_; } | 112 State state() const { return state_; } |
| 117 | 113 |
| 118 private: | 114 private: |
| 119 // StreamMixerAlsa::InputQueue implementation: | 115 // StreamMixerAlsa::InputQueue implementation: |
| 120 int input_samples_per_second() const override; | 116 int input_samples_per_second() const override; |
| 121 bool primary() const override; | 117 bool primary() const override; |
| 122 std::string device_id() const override; | |
| 123 bool IsDeleting() const override; | 118 bool IsDeleting() const override; |
| 124 void Initialize(const MediaPipelineBackendAlsa::RenderingDelay& | 119 void Initialize(const MediaPipelineBackendAlsa::RenderingDelay& |
| 125 mixer_rendering_delay) override; | 120 mixer_rendering_delay) override; |
| 126 void set_filter_group(FilterGroup* filter_group) override; | |
| 127 FilterGroup* filter_group() override; | |
| 128 int MaxReadSize() override; | 121 int MaxReadSize() override; |
| 129 void GetResampledData(::media::AudioBus* dest, int frames) override; | 122 void GetResampledData(::media::AudioBus* dest, int frames) override; |
| 130 void OnSkipped() override; | 123 void OnSkipped() override; |
| 131 void VolumeScaleAccumulate(bool repeat_transition, | 124 void VolumeScaleAccumulate(bool repeat_transition, |
| 132 const float* src, | 125 const float* src, |
| 133 int frames, | 126 int frames, |
| 134 float* dest) override; | 127 float* dest) override; |
| 135 void AfterWriteFrames(const MediaPipelineBackendAlsa::RenderingDelay& | 128 void AfterWriteFrames(const MediaPipelineBackendAlsa::RenderingDelay& |
| 136 mixer_rendering_delay) override; | 129 mixer_rendering_delay) override; |
| 137 void SignalError(StreamMixerAlsaInput::MixerError error) override; | 130 void SignalError(StreamMixerAlsaInput::MixerError error) override; |
| 138 void PrepareToDelete(const OnReadyToDeleteCb& delete_cb) override; | 131 void PrepareToDelete(const OnReadyToDeleteCb& delete_cb) override; |
| 139 | 132 |
| 140 // Tells the mixer to delete |this|. Makes sure not to call |delete_cb_| more | 133 // Tells the mixer to delete |this|. Makes sure not to call |delete_cb_| more |
| 141 // than once for |this|. | 134 // than once for |this|. |
| 142 void DeleteThis(); | 135 void DeleteThis(); |
| 143 MediaPipelineBackendAlsa::RenderingDelay QueueData( | 136 MediaPipelineBackendAlsa::RenderingDelay QueueData( |
| 144 const scoped_refptr<DecoderBufferBase>& data); | 137 const scoped_refptr<DecoderBufferBase>& data); |
| 145 void PostPcmCallback(const MediaPipelineBackendAlsa::RenderingDelay& delay); | 138 void PostPcmCallback(const MediaPipelineBackendAlsa::RenderingDelay& delay); |
| 146 void DidQueueData(bool end_of_stream); | 139 void DidQueueData(bool end_of_stream); |
| 147 void ReadCB(int frame_delay, ::media::AudioBus* output); | 140 void ReadCB(int frame_delay, ::media::AudioBus* output); |
| 148 void FillFrames(int frame_delay, ::media::AudioBus* output, int frames); | 141 void FillFrames(int frame_delay, ::media::AudioBus* output, int frames); |
| 149 int NormalFadeFrames(); | 142 int NormalFadeFrames(); |
| 150 void FadeIn(::media::AudioBus* dest, int frames); | 143 void FadeIn(::media::AudioBus* dest, int frames); |
| 151 void FadeOut(::media::AudioBus* dest, int frames); | 144 void FadeOut(::media::AudioBus* dest, int frames); |
| 152 void PostError(StreamMixerAlsaInput::MixerError error); | 145 void PostError(StreamMixerAlsaInput::MixerError error); |
| 153 | 146 |
| 154 StreamMixerAlsaInput::Delegate* const delegate_; | 147 StreamMixerAlsaInput::Delegate* const delegate_; |
| 155 const int input_samples_per_second_; | 148 const int input_samples_per_second_; |
| 156 const bool primary_; | 149 const bool primary_; |
| 157 std::string device_id_; | |
| 158 StreamMixerAlsa* const mixer_; | 150 StreamMixerAlsa* const mixer_; |
| 159 FilterGroup* filter_group_; | |
| 160 const scoped_refptr<base::SingleThreadTaskRunner> mixer_task_runner_; | 151 const scoped_refptr<base::SingleThreadTaskRunner> mixer_task_runner_; |
| 161 const scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | 152 const scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
| 162 | 153 |
| 163 double resample_ratio_; | 154 double resample_ratio_; |
| 164 | 155 |
| 165 State state_; | 156 State state_; |
| 166 SlewVolume slew_volume_; | 157 SlewVolume slew_volume_; |
| 167 | 158 |
| 168 base::Lock queue_lock_; // Lock for the following queue-related members. | 159 base::Lock queue_lock_; // Lock for the following queue-related members. |
| 169 scoped_refptr<DecoderBufferBase> pending_data_; | 160 scoped_refptr<DecoderBufferBase> pending_data_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 187 base::WeakPtr<StreamMixerAlsaInputImpl> weak_this_; | 178 base::WeakPtr<StreamMixerAlsaInputImpl> weak_this_; |
| 188 base::WeakPtrFactory<StreamMixerAlsaInputImpl> weak_factory_; | 179 base::WeakPtrFactory<StreamMixerAlsaInputImpl> weak_factory_; |
| 189 | 180 |
| 190 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsaInputImpl); | 181 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsaInputImpl); |
| 191 }; | 182 }; |
| 192 | 183 |
| 193 } // namespace media | 184 } // namespace media |
| 194 } // namespace chromecast | 185 } // namespace chromecast |
| 195 | 186 |
| 196 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_INPUT_IMPL_H_ | 187 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_INPUT_IMPL_H_ |
| OLD | NEW |