Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_BASE_AUDIO_BUFFER_CONVERTER | |
| 6 #define MEDIA_BASE_AUDIO_BUFFER_CONVERTER | |
| 7 | |
| 8 #include "base/memory/ref_counted.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/time/time.h" | |
| 11 #include "media/audio/audio_parameters.h" | |
| 12 #include "media/base/audio_converter.h" | |
| 13 #include "media/base/audio_timestamp_helper.h" | |
| 14 #include "media/base/media_export.h" | |
| 15 | |
| 16 namespace media { | |
| 17 | |
| 18 class AudioBuffer; | |
| 19 class AudioBus; | |
| 20 | |
| 21 // Takes AudioBuffers in any format and uses an AudioConverter to convert them | |
| 22 // to a common format (usually the hardware output format). | |
| 23 class AudioBufferConverter : public AudioConverter::InputCallback { | |
| 24 public: | |
|
DaleCurtis
2014/03/20 01:36:26
1 space indent, no line after. I'd just run "git
rileya (GONE FROM CHROMIUM)
2014/03/21 20:58:49
Fixed.
| |
| 25 | |
| 26 AudioBufferConverter(const AudioParameters& output_params); | |
|
DaleCurtis
2014/03/20 01:36:26
explicit
rileya (GONE FROM CHROMIUM)
2014/03/21 20:58:49
Done.
| |
| 27 virtual ~AudioBufferConverter(); | |
| 28 | |
| 29 void AddInput(const scoped_refptr<AudioBuffer>& buffer); | |
| 30 | |
| 31 bool HasNextBuffer(); | |
| 32 scoped_refptr<AudioBuffer> GetNextBuffer(); | |
| 33 | |
| 34 private: | |
|
DaleCurtis
2014/03/20 01:36:26
ditto on style
rileya (GONE FROM CHROMIUM)
2014/03/21 20:58:49
Fixed.
| |
| 35 | |
| 36 // Callback to provide data to the AudioConverter | |
| 37 virtual double ProvideInput(AudioBus* audio_bus, base::TimeDelta buffer_delay) | |
| 38 OVERRIDE; | |
| 39 | |
| 40 // Reset the converter in response to a configuration change. | |
| 41 void ResetConverter(const AudioParameters& input_params); | |
| 42 | |
| 43 // Determine the AudioParameters of an AudioBuffer. | |
| 44 AudioParameters AudioBufferToAudioParameters( | |
| 45 const scoped_refptr<AudioBuffer>& buffer); | |
| 46 | |
| 47 // Get an AudioBuffer from |audio_converter_|. | |
| 48 scoped_refptr<AudioBuffer> Convert(); | |
| 49 | |
| 50 // Flush remaining output | |
| 51 void Flush(); | |
| 52 | |
| 53 // Is |new_params| a config change from |input_params_|? | |
| 54 bool IsConfigChange(const AudioParameters& new_params); | |
| 55 | |
| 56 // The output parameters. | |
| 57 AudioParameters output_params_; | |
| 58 | |
| 59 // The current input parameters (we cache these to detect configuration | |
| 60 // changes, so we know when to reset the AudioConverter). | |
| 61 AudioParameters input_params_; | |
| 62 | |
| 63 // Ratio of sample rates between input and output params (we use this to | |
| 64 // compute how many frames of output we'll get out of a given number of | |
| 65 // input frames). | |
| 66 double sample_rate_ratio_; | |
| 67 | |
| 68 // Queued up inputs (there will never be all that much data stored here, as | |
| 69 // soon as there's enough here to produce an output buffer we will do so. | |
| 70 std::list<scoped_refptr<AudioBuffer> > queued_inputs_; | |
| 71 | |
| 72 // Offset into the front element of |queued_inputs_|. A ProvideInput() call | |
| 73 // doesn't necessarily always consume an entire buffer. | |
| 74 int offset_into_queue_; | |
|
rileya (GONE FROM CHROMIUM)
2014/03/20 00:55:11
This probably needs a better name.
| |
| 75 | |
| 76 // Buffer of output frames, to be returned by GetNextBuffer(). | |
| 77 std::list<scoped_refptr<AudioBuffer> > queued_outputs_; | |
|
DaleCurtis
2014/03/20 01:36:26
deque?
rileya (GONE FROM CHROMIUM)
2014/03/21 20:58:49
Sounds good. Done.
| |
| 78 | |
| 79 // How many frames of input we have on hand. | |
| 80 int input_frames_; | |
| 81 | |
| 82 // Compute timestamps in terms of the output sample rate. | |
| 83 AudioTimestampHelper timestamp_helper_; | |
| 84 | |
| 85 // Are we flushing everything, without regard for providing AudioConverter | |
| 86 // full AudioBuses in ProvideInput()? | |
| 87 bool is_flushing_; | |
| 88 | |
| 89 // The AudioConverter which does the real work here. | |
| 90 scoped_ptr<AudioConverter> audio_converter_; | |
| 91 }; | |
| 92 | |
| 93 } // namespace media | |
| 94 | |
| 95 #endif // MEDIA_BASE_AUDIO_BUFFER_CONVERTER | |
| OLD | NEW |