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

Side by Side Diff: chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.h

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

Powered by Google App Engine
This is Rietveld 408576698