| 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> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "chromecast/media/cma/backend/alsa/media_pipeline_backend_alsa.h" | 17 #include "chromecast/media/cma/backend/alsa/media_pipeline_backend_alsa.h" |
| 18 #include "chromecast/media/cma/backend/alsa/slew_volume.h" | 18 #include "chromecast/media/cma/backend/alsa/slew_volume.h" |
| 19 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h" | 19 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h" |
| 20 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input.h" | 20 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input.h" |
| 21 #include "chromecast/public/volume_control.h" |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
| 24 } // namespace base | 25 } // namespace base |
| 25 | 26 |
| 26 namespace media { | 27 namespace media { |
| 27 class AudioBus; | 28 class AudioBus; |
| 28 class MultiChannelResampler; | 29 class MultiChannelResampler; |
| 29 } // namespace media | 30 } // namespace media |
| 30 | 31 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 kStateGotEos, // Got the end-of-stream buffer (normal playback). | 88 kStateGotEos, // Got the end-of-stream buffer (normal playback). |
| 88 kStateFinalFade, // Fading out to a deleted state. | 89 kStateFinalFade, // Fading out to a deleted state. |
| 89 kStateDeleted, // Told the mixer to delete this. | 90 kStateDeleted, // Told the mixer to delete this. |
| 90 kStateError, // A mixer error occurred, this is unusable now. | 91 kStateError, // A mixer error occurred, this is unusable now. |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 StreamMixerAlsaInputImpl(StreamMixerAlsaInput::Delegate* delegate, | 94 StreamMixerAlsaInputImpl(StreamMixerAlsaInput::Delegate* delegate, |
| 94 int input_samples_per_second, | 95 int input_samples_per_second, |
| 95 bool primary, | 96 bool primary, |
| 96 const std::string& device_id, | 97 const std::string& device_id, |
| 98 AudioContentType content_type, |
| 97 StreamMixerAlsa* mixer); | 99 StreamMixerAlsa* mixer); |
| 98 | 100 |
| 99 ~StreamMixerAlsaInputImpl() override; | 101 ~StreamMixerAlsaInputImpl() override; |
| 100 | 102 |
| 101 // Queues some PCM data to be mixed. |data| must be in planar float format. | 103 // Queues some PCM data to be mixed. |data| must be in planar float format. |
| 102 void WritePcm(const scoped_refptr<DecoderBufferBase>& data); | 104 void WritePcm(const scoped_refptr<DecoderBufferBase>& data); |
| 103 | 105 |
| 104 // Sets the pause state of this stream. | 106 // Sets the pause state of this stream. |
| 105 void SetPaused(bool paused); | 107 void SetPaused(bool paused); |
| 106 | 108 |
| 107 // Sets the volume multiplier for this stream. If |multiplier| < 0, sets the | 109 // Sets the volume multiplier for this stream. If |multiplier| < 0, sets the |
| 108 // volume multiplier to 0. If |multiplier| > 1, sets the volume multiplier | 110 // volume multiplier to 0. If |multiplier| > 1, sets the volume multiplier |
| 109 // to 1. | 111 // to 1. |
| 110 void SetVolumeMultiplier(float multiplier); | 112 void SetVolumeMultiplier(float multiplier); |
| 111 | 113 |
| 112 // Prevents any further calls to the delegate (ie, called when the delegate | 114 // Prevents any further calls to the delegate (ie, called when the delegate |
| 113 // is being destroyed). | 115 // is being destroyed). |
| 114 void PreventDelegateCalls(); | 116 void PreventDelegateCalls(); |
| 115 | 117 |
| 116 State state() const { return state_; } | 118 State state() const { return state_; } |
| 117 | 119 |
| 118 private: | 120 private: |
| 119 // StreamMixerAlsa::InputQueue implementation: | 121 // StreamMixerAlsa::InputQueue implementation: |
| 120 int input_samples_per_second() const override; | 122 int input_samples_per_second() const override; |
| 121 bool primary() const override; | 123 bool primary() const override; |
| 122 std::string device_id() const override; | 124 std::string device_id() const override; |
| 125 AudioContentType content_type() const override; |
| 123 bool IsDeleting() const override; | 126 bool IsDeleting() const override; |
| 124 void Initialize(const MediaPipelineBackendAlsa::RenderingDelay& | 127 void Initialize(const MediaPipelineBackendAlsa::RenderingDelay& |
| 125 mixer_rendering_delay) override; | 128 mixer_rendering_delay) override; |
| 126 void set_filter_group(FilterGroup* filter_group) override; | 129 void set_filter_group(FilterGroup* filter_group) override; |
| 127 FilterGroup* filter_group() override; | 130 FilterGroup* filter_group() override; |
| 128 int MaxReadSize() override; | 131 int MaxReadSize() override; |
| 129 void GetResampledData(::media::AudioBus* dest, int frames) override; | 132 void GetResampledData(::media::AudioBus* dest, int frames) override; |
| 130 void OnSkipped() override; | 133 void OnSkipped() override; |
| 131 void VolumeScaleAccumulate(bool repeat_transition, | 134 void VolumeScaleAccumulate(bool repeat_transition, |
| 132 const float* src, | 135 const float* src, |
| 133 int frames, | 136 int frames, |
| 134 float* dest) override; | 137 float* dest) override; |
| 135 void AfterWriteFrames(const MediaPipelineBackendAlsa::RenderingDelay& | 138 void AfterWriteFrames(const MediaPipelineBackendAlsa::RenderingDelay& |
| 136 mixer_rendering_delay) override; | 139 mixer_rendering_delay) override; |
| 137 void SignalError(StreamMixerAlsaInput::MixerError error) override; | 140 void SignalError(StreamMixerAlsaInput::MixerError error) override; |
| 138 void PrepareToDelete(const OnReadyToDeleteCb& delete_cb) override; | 141 void PrepareToDelete(const OnReadyToDeleteCb& delete_cb) override; |
| 142 void SetContentTypeVolume(float volume) override; |
| 143 void SetMuted(bool muted) override; |
| 139 | 144 |
| 140 // Tells the mixer to delete |this|. Makes sure not to call |delete_cb_| more | 145 // Tells the mixer to delete |this|. Makes sure not to call |delete_cb_| more |
| 141 // than once for |this|. | 146 // than once for |this|. |
| 142 void DeleteThis(); | 147 void DeleteThis(); |
| 143 MediaPipelineBackendAlsa::RenderingDelay QueueData( | 148 MediaPipelineBackendAlsa::RenderingDelay QueueData( |
| 144 const scoped_refptr<DecoderBufferBase>& data); | 149 const scoped_refptr<DecoderBufferBase>& data); |
| 145 void PostPcmCallback(const MediaPipelineBackendAlsa::RenderingDelay& delay); | 150 void PostPcmCallback(const MediaPipelineBackendAlsa::RenderingDelay& delay); |
| 146 void DidQueueData(bool end_of_stream); | 151 void DidQueueData(bool end_of_stream); |
| 147 void ReadCB(int frame_delay, ::media::AudioBus* output); | 152 void ReadCB(int frame_delay, ::media::AudioBus* output); |
| 148 void FillFrames(int frame_delay, ::media::AudioBus* output, int frames); | 153 void FillFrames(int frame_delay, ::media::AudioBus* output, int frames); |
| 149 int NormalFadeFrames(); | 154 int NormalFadeFrames(); |
| 150 void FadeIn(::media::AudioBus* dest, int frames); | 155 void FadeIn(::media::AudioBus* dest, int frames); |
| 151 void FadeOut(::media::AudioBus* dest, int frames); | 156 void FadeOut(::media::AudioBus* dest, int frames); |
| 152 void PostError(StreamMixerAlsaInput::MixerError error); | 157 void PostError(StreamMixerAlsaInput::MixerError error); |
| 153 | 158 |
| 154 StreamMixerAlsaInput::Delegate* const delegate_; | 159 StreamMixerAlsaInput::Delegate* const delegate_; |
| 155 const int input_samples_per_second_; | 160 const int input_samples_per_second_; |
| 156 const bool primary_; | 161 const bool primary_; |
| 157 std::string device_id_; | 162 const std::string device_id_; |
| 163 const AudioContentType content_type_; |
| 158 StreamMixerAlsa* const mixer_; | 164 StreamMixerAlsa* const mixer_; |
| 159 FilterGroup* filter_group_; | 165 FilterGroup* filter_group_; |
| 160 const scoped_refptr<base::SingleThreadTaskRunner> mixer_task_runner_; | 166 const scoped_refptr<base::SingleThreadTaskRunner> mixer_task_runner_; |
| 161 const scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | 167 const scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
| 162 | 168 |
| 163 double resample_ratio_; | 169 double resample_ratio_; |
| 164 | 170 |
| 165 State state_; | 171 State state_; |
| 172 |
| 173 float stream_volume_multiplier_; |
| 174 float type_volume_multiplier_; |
| 175 float mute_volume_multiplier_; |
| 166 SlewVolume slew_volume_; | 176 SlewVolume slew_volume_; |
| 167 | 177 |
| 168 base::Lock queue_lock_; // Lock for the following queue-related members. | 178 base::Lock queue_lock_; // Lock for the following queue-related members. |
| 169 scoped_refptr<DecoderBufferBase> pending_data_; | 179 scoped_refptr<DecoderBufferBase> pending_data_; |
| 170 std::deque<scoped_refptr<DecoderBufferBase>> queue_; | 180 std::deque<scoped_refptr<DecoderBufferBase>> queue_; |
| 171 int queued_frames_; | 181 int queued_frames_; |
| 172 double queued_frames_including_resampler_; | 182 double queued_frames_including_resampler_; |
| 173 MediaPipelineBackendAlsa::RenderingDelay mixer_rendering_delay_; | 183 MediaPipelineBackendAlsa::RenderingDelay mixer_rendering_delay_; |
| 174 // End of members that queue_lock_ controls access for. | 184 // End of members that queue_lock_ controls access for. |
| 175 | 185 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 187 base::WeakPtr<StreamMixerAlsaInputImpl> weak_this_; | 197 base::WeakPtr<StreamMixerAlsaInputImpl> weak_this_; |
| 188 base::WeakPtrFactory<StreamMixerAlsaInputImpl> weak_factory_; | 198 base::WeakPtrFactory<StreamMixerAlsaInputImpl> weak_factory_; |
| 189 | 199 |
| 190 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsaInputImpl); | 200 DISALLOW_COPY_AND_ASSIGN(StreamMixerAlsaInputImpl); |
| 191 }; | 201 }; |
| 192 | 202 |
| 193 } // namespace media | 203 } // namespace media |
| 194 } // namespace chromecast | 204 } // namespace chromecast |
| 195 | 205 |
| 196 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_INPUT_IMPL_H_ | 206 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_STREAM_MIXER_ALSA_INPUT_IMPL_H_ |
| OLD | NEW |