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

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: use CreateEmptyBuffer 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 #include <memory>
10
8 #include "base/bind.h" 11 #include "base/bind.h"
9 #include "base/location.h" 12 #include "base/location.h"
10 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input.h" 13 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input.h"
11 #include "chromecast/media/cma/decoder/cast_audio_decoder.h" 14 #include "chromecast/media/cma/decoder/cast_audio_decoder.h"
12 #include "chromecast/public/media/decoder_config.h" 15 #include "chromecast/public/media/decoder_config.h"
13 #include "chromecast/public/media/media_pipeline_backend.h" 16 #include "chromecast/public/media/media_pipeline_backend.h"
14 #include "chromecast/public/media/media_pipeline_device_params.h" 17 #include "chromecast/public/media/media_pipeline_device_params.h"
15 18
16 namespace base { 19 namespace base {
17 class SingleThreadTaskRunner; 20 class SingleThreadTaskRunner;
18 } // namespace base 21 } // namespace base
19 22
23 namespace media {
24 class AudioBus;
25 class AudioRendererAlgorithm;
26 } // namespace media
27
20 namespace chromecast { 28 namespace chromecast {
21 namespace media { 29 namespace media {
22 class DecoderBufferBase; 30 class DecoderBufferBase;
23 class MediaPipelineBackendAlsa; 31 class MediaPipelineBackendAlsa;
24 32
25 class AudioDecoderAlsa : public MediaPipelineBackend::AudioDecoder, 33 class AudioDecoderAlsa : public MediaPipelineBackend::AudioDecoder,
26 public StreamMixerAlsaInput::Delegate { 34 public StreamMixerAlsaInput::Delegate {
27 public: 35 public:
28 using BufferStatus = MediaPipelineBackend::BufferStatus; 36 using BufferStatus = MediaPipelineBackend::BufferStatus;
29 37
30 explicit AudioDecoderAlsa(MediaPipelineBackendAlsa* backend); 38 explicit AudioDecoderAlsa(MediaPipelineBackendAlsa* backend);
31 ~AudioDecoderAlsa() override; 39 ~AudioDecoderAlsa() override;
32 40
33 void Initialize(); 41 void Initialize();
34 bool Start(int64_t start_pts); 42 bool Start(int64_t start_pts);
35 void Stop(); 43 void Stop();
36 bool Pause(); 44 bool Pause();
37 bool Resume(); 45 bool Resume();
46 bool SetPlaybackRate(float rate);
38 47
39 int64_t current_pts() const { return current_pts_; } 48 int64_t current_pts() const { return current_pts_; }
40 49
41 // MediaPipelineBackend::AudioDecoder implementation: 50 // MediaPipelineBackend::AudioDecoder implementation:
42 void SetDelegate( 51 void SetDelegate(
43 MediaPipelineBackend::Decoder::Delegate* delegate) override; 52 MediaPipelineBackend::Decoder::Delegate* delegate) override;
44 BufferStatus PushBuffer(CastDecoderBuffer* buffer) override; 53 BufferStatus PushBuffer(CastDecoderBuffer* buffer) override;
45 void GetStatistics(Statistics* statistics) override; 54 void GetStatistics(Statistics* statistics) override;
46 bool SetConfig(const AudioConfig& config) override; 55 bool SetConfig(const AudioConfig& config) override;
47 bool SetVolume(float multiplier) override; 56 bool SetVolume(float multiplier) override;
48 RenderingDelay GetRenderingDelay() override; 57 RenderingDelay GetRenderingDelay() override;
49 58
50 private: 59 private:
60 struct RateShifterInfo {
61 explicit RateShifterInfo(float playback_rate);
62
63 double rate;
64 double input_frames;
65 int64_t output_frames;
66 };
67
51 // StreamMixerAlsaInput::Delegate implementation: 68 // StreamMixerAlsaInput::Delegate implementation:
52 void OnWritePcmCompletion(BufferStatus status, 69 void OnWritePcmCompletion(BufferStatus status,
53 const RenderingDelay& delay) override; 70 const RenderingDelay& delay) override;
54 void OnMixerError(MixerError error) override; 71 void OnMixerError(MixerError error) override;
55 72
56 void CleanUpPcm(); 73 void CleanUpPcm();
57 void CreateDecoder(); 74 void CreateDecoder();
75 void CreateRateShifter(int samples_per_second);
58 void OnDecoderInitialized(bool success); 76 void OnDecoderInitialized(bool success);
59 void OnBufferDecoded(uint64_t input_bytes, 77 void OnBufferDecoded(uint64_t input_bytes,
60 CastAudioDecoder::Status status, 78 CastAudioDecoder::Status status,
61 const scoped_refptr<DecoderBufferBase>& decoded); 79 const scoped_refptr<DecoderBufferBase>& decoded);
80 void PushRateShifted();
81 void PushMorePcm();
62 void RunEos(); 82 void RunEos();
63 bool BypassDecoder() const; 83 bool BypassDecoder() const;
64 bool ShouldStartClock() const; 84 bool ShouldStartClock() const;
65 void UpdateStatistics(Statistics delta); 85 void UpdateStatistics(Statistics delta);
66 86
67 MediaPipelineBackendAlsa* const backend_; 87 MediaPipelineBackendAlsa* const backend_;
68 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 88 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
69 MediaPipelineBackend::Decoder::Delegate* delegate_; 89 MediaPipelineBackend::Decoder::Delegate* delegate_;
70 90
71 Statistics stats_; 91 Statistics stats_;
72 bool is_eos_; 92
73 bool error_; 93 bool pending_buffer_complete_;
94 bool got_eos_;
95 bool pushed_eos_;
96 bool mixer_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_;
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_mixer_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
« no previous file with comments | « chromecast/media/cma/backend/alsa/DEPS ('k') | chromecast/media/cma/backend/alsa/audio_decoder_alsa.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698