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

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

Issue 2557513002: [Chromecast] Add support for different playback rates to ALSA backend (Closed)
Patch Set: Created 4 years 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_AUDIO_DECODER_ALSA_H_ 5 #ifndef CHROMECAST_MEDIA_CMA_BACKEND_ALSA_AUDIO_DECODER_ALSA_H_
6 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_AUDIO_DECODER_ALSA_H_ 6 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_AUDIO_DECODER_ALSA_H_
7 7
8 #include <deque>
9
8 #include "base/bind.h" 10 #include "base/bind.h"
9 #include "base/location.h" 11 #include "base/location.h"
10 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input.h" 12 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input.h"
11 #include "chromecast/media/cma/decoder/cast_audio_decoder.h" 13 #include "chromecast/media/cma/decoder/cast_audio_decoder.h"
12 #include "chromecast/public/media/decoder_config.h" 14 #include "chromecast/public/media/decoder_config.h"
13 #include "chromecast/public/media/media_pipeline_backend.h" 15 #include "chromecast/public/media/media_pipeline_backend.h"
14 #include "chromecast/public/media/media_pipeline_device_params.h" 16 #include "chromecast/public/media/media_pipeline_device_params.h"
15 17
16 namespace base { 18 namespace base {
17 class SingleThreadTaskRunner; 19 class SingleThreadTaskRunner;
18 } // namespace base 20 } // namespace base
19 21
22 namespace media {
23 class AudioBus;
24 class AudioRendererAlgorithm;
25 } // namespace media
26
20 namespace chromecast { 27 namespace chromecast {
21 namespace media { 28 namespace media {
22 class DecoderBufferBase; 29 class DecoderBufferBase;
23 class MediaPipelineBackendAlsa; 30 class MediaPipelineBackendAlsa;
24 31
25 class AudioDecoderAlsa : public MediaPipelineBackend::AudioDecoder, 32 class AudioDecoderAlsa : public MediaPipelineBackend::AudioDecoder,
26 public StreamMixerAlsaInput::Delegate { 33 public StreamMixerAlsaInput::Delegate {
27 public: 34 public:
28 using BufferStatus = MediaPipelineBackend::BufferStatus; 35 using BufferStatus = MediaPipelineBackend::BufferStatus;
29 36
30 explicit AudioDecoderAlsa(MediaPipelineBackendAlsa* backend); 37 explicit AudioDecoderAlsa(MediaPipelineBackendAlsa* backend);
31 ~AudioDecoderAlsa() override; 38 ~AudioDecoderAlsa() override;
32 39
33 void Initialize(); 40 void Initialize();
34 bool Start(int64_t start_pts); 41 bool Start(int64_t start_pts);
35 void Stop(); 42 void Stop();
36 bool Pause(); 43 bool Pause();
37 bool Resume(); 44 bool Resume();
45 bool SetPlaybackRate(float rate);
38 46
39 int64_t current_pts() const { return current_pts_; } 47 int64_t current_pts() const { return current_pts_; }
40 48
41 // MediaPipelineBackend::AudioDecoder implementation: 49 // MediaPipelineBackend::AudioDecoder implementation:
42 void SetDelegate( 50 void SetDelegate(
43 MediaPipelineBackend::Decoder::Delegate* delegate) override; 51 MediaPipelineBackend::Decoder::Delegate* delegate) override;
44 BufferStatus PushBuffer(CastDecoderBuffer* buffer) override; 52 BufferStatus PushBuffer(CastDecoderBuffer* buffer) override;
45 void GetStatistics(Statistics* statistics) override; 53 void GetStatistics(Statistics* statistics) override;
46 bool SetConfig(const AudioConfig& config) override; 54 bool SetConfig(const AudioConfig& config) override;
47 bool SetVolume(float multiplier) override; 55 bool SetVolume(float multiplier) override;
48 RenderingDelay GetRenderingDelay() override; 56 RenderingDelay GetRenderingDelay() override;
49 57
50 private: 58 private:
59 struct RateShifterInfo {
60 RateShifterInfo(float playback_rate);
slan 2016/12/07 00:22:27 nit: explicit Also, can we do a default ctor here
kmackay 2016/12/07 22:59:58 Added explicit; I don't think a default constructo
slan 2016/12/09 00:05:31 Yeah, I'm silly.
61
62 double rate;
63 double input_frames;
64 int64_t output_frames;
65 };
66
51 // StreamMixerAlsaInput::Delegate implementation: 67 // StreamMixerAlsaInput::Delegate implementation:
52 void OnWritePcmCompletion(BufferStatus status, 68 void OnWritePcmCompletion(BufferStatus status,
53 const RenderingDelay& delay) override; 69 const RenderingDelay& delay) override;
54 void OnMixerError(MixerError error) override; 70 void OnMixerError(MixerError error) override;
55 71
56 void CleanUpPcm(); 72 void CleanUpPcm();
57 void CreateDecoder(); 73 void CreateDecoder();
74 void CreateRateShifter(int samples_per_second);
58 void OnDecoderInitialized(bool success); 75 void OnDecoderInitialized(bool success);
59 void OnBufferDecoded(uint64_t input_bytes, 76 void OnBufferDecoded(uint64_t input_bytes,
60 CastAudioDecoder::Status status, 77 CastAudioDecoder::Status status,
61 const scoped_refptr<DecoderBufferBase>& decoded); 78 const scoped_refptr<DecoderBufferBase>& decoded);
79 void PushRateShifted();
80 void PushMorePcm();
62 void RunEos(); 81 void RunEos();
63 bool BypassDecoder() const; 82 bool BypassDecoder() const;
64 bool ShouldStartClock() const; 83 bool ShouldStartClock() const;
65 void UpdateStatistics(Statistics delta); 84 void UpdateStatistics(Statistics delta);
66 85
67 MediaPipelineBackendAlsa* const backend_; 86 MediaPipelineBackendAlsa* const backend_;
68 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 87 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
69 MediaPipelineBackend::Decoder::Delegate* delegate_; 88 MediaPipelineBackend::Decoder::Delegate* delegate_;
70 89
71 Statistics stats_; 90 Statistics stats_;
72 bool is_eos_; 91
92 bool pending_write_pcm_;
halliwell 2016/12/06 17:27:59 Seems like this is mostly redundant (corresponds t
slan 2016/12/07 00:22:27 Yes, after grepping for this value, it does seem t
kmackay 2016/12/07 22:59:58 input_frames can be 0 sometimes. I added a (negati
93 bool pending_buffer_complete_;
94 bool got_eos_;
95 bool pushed_eos_;
73 bool error_; 96 bool error_;
74 97
75 AudioConfig config_; 98 AudioConfig config_;
76 std::unique_ptr<CastAudioDecoder> decoder_; 99 std::unique_ptr<CastAudioDecoder> decoder_;
77 100
101 std::unique_ptr<::media::AudioRendererAlgorithm> rate_shifter_;
halliwell 2016/12/06 17:27:59 nit, should be including <memory>
kmackay 2016/12/07 22:59:58 Done.
102 std::deque<RateShifterInfo> rate_shifter_info_;
103 std::unique_ptr<::media::AudioBus> rate_shifter_output_;
104
78 int64_t current_pts_; 105 int64_t current_pts_;
79 int64_t last_buffer_pts_;
80 106
81 std::unique_ptr<StreamMixerAlsaInput> mixer_input_; 107 std::unique_ptr<StreamMixerAlsaInput> mixer_input_;
82 RenderingDelay last_known_delay_; 108 RenderingDelay last_known_delay_;
109 int64_t pending_output_frames_;
83 float volume_multiplier_; 110 float volume_multiplier_;
84 111
85 base::WeakPtrFactory<AudioDecoderAlsa> weak_factory_; 112 base::WeakPtrFactory<AudioDecoderAlsa> weak_factory_;
86 113
87 DISALLOW_COPY_AND_ASSIGN(AudioDecoderAlsa); 114 DISALLOW_COPY_AND_ASSIGN(AudioDecoderAlsa);
88 }; 115 };
89 116
90 } // namespace media 117 } // namespace media
91 } // namespace chromecast 118 } // namespace chromecast
92 119
93 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_AUDIO_DECODER_ALSA_H_ 120 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_AUDIO_DECODER_ALSA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698