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

Side by Side Diff: media/base/audio_buffer_converter.h

Issue 177333003: Add support for midstream audio configuration changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ABS
Patch Set: address comments Created 6 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
(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 <deque>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "media/audio/audio_parameters.h"
14 #include "media/base/audio_converter.h"
15 #include "media/base/audio_timestamp_helper.h"
16 #include "media/base/media_export.h"
17
18 namespace media {
19
20 class AudioBuffer;
21 class AudioBus;
22
23 // Takes AudioBuffers in any format and uses an AudioConverter to convert them
24 // to a common format (usually the hardware output format).
25 class AudioBufferConverter : public AudioConverter::InputCallback {
26 public:
27 explicit AudioBufferConverter(const AudioParameters& output_params);
28 virtual ~AudioBufferConverter();
29
30 void AddInput(const scoped_refptr<AudioBuffer>& buffer);
31
32 // Is an output buffer available via GetNextBuffer()?
33 bool HasNextBuffer();
34
35 // This should only be called this is HasNextBuffer() returns true.
36 scoped_refptr<AudioBuffer> GetNextBuffer();
37
38 // Reset internal state.
39 void Reset();
40
41 private:
42 // Callback to provide data to the AudioConverter
43 virtual double ProvideInput(AudioBus* audio_bus, base::TimeDelta buffer_delay)
44 OVERRIDE;
45
46 // Reset the converter in response to a configuration change.
47 void ResetConverter(const scoped_refptr<AudioBuffer>& input_buffer);
48
49 // Perform conversion if we have enough data.
50 void ConvertIfPossible();
51
52 // Flush remaining output
53 void Flush();
54
55 // The output parameters.
56 AudioParameters output_params_;
57
58 // The current input parameters (we cache these to detect configuration
59 // changes, so we know when to reset the AudioConverter).
60 AudioParameters input_params_;
61
62 // Queued up inputs (there will never be all that much data stored here, as
63 // soon as there's enough here to produce an output buffer we will do so).
64 std::list<scoped_refptr<AudioBuffer> > queued_inputs_;
65
66 // Offset into the front element of |queued_inputs_|. A ProvideInput() call
67 // doesn't necessarily always consume an entire buffer.
68 int offset_into_queue_;
69
70 // Buffer of output frames, to be returned by GetNextBuffer().
71 std::deque<scoped_refptr<AudioBuffer> > queued_outputs_;
72
73 // How many frames of input we have in |queued_inputs_|.
74 int input_frames_;
75
76 // Input frames in the AudioConverter's internal buffers.
77 double buffered_input_frames_;
78
79 // Ratio of sample rates, in/out.
80 double sample_rate_ratio_;
DaleCurtis 2014/03/21 23:18:56 io_sample_rate_ratio_ then?
rileya (GONE FROM CHROMIUM) 2014/03/24 18:07:05 Done.
81
82 // Computes 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698