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

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

Issue 1647773002: MediaStream audio sourcing: Bypass audio processing for non-WebRTC cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NOT FOR REVIEW -- This will be broken-up across multiple CLs. Created 4 years, 10 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
« no previous file with comments | « media/base/audio_fifo.h ('k') | media/base/audio_rechunker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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_RECHUNKER_H_
6 #define MEDIA_BASE_AUDIO_RECHUNKER_H_
7
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "media/base/audio_bus.h"
13 #include "media/base/media_export.h"
14
15 namespace media {
16
17 // Yet another FIFO for audio data that re-chunks audio to a desired buffer
18 // size. Unlike AudioFifo and AudioBlockFifo, this FIFO cannot overflow: The
19 // client is required to provide a callback that is called synchronously during
20 // a push whenever enough data becomes available. In addition, this FIFO
21 // shifts reference timestamps to account for any samples that were pending in
22 // internal buffers from prior pushes. This implementation eliminates redundant
23 // memory copies when the input buffer size always matches the desired buffer
24 // size.
25 class MEDIA_EXPORT AudioRechunker final {
26 public:
27 using RechunkedAudioCallback =
28 base::Callback<void(const AudioBus& output,
29 base::TimeDelta reference_timestamp)>;
30
31 // Creates a new AudioRechunker that re-chunks audio into the required
32 // |output_duration| and delivers it by running |callback|.
33 AudioRechunker(base::TimeDelta output_duration,
34 const RechunkedAudioCallback& callback);
35
36 ~AudioRechunker();
37
38 int sample_rate() const { return sample_rate_; }
39
40 // Returns the number of frames in each AudioBus delivered to the
41 // RechunkedAudioCallback.
42 int output_frames() const { return output_frames_; }
43
44 // Must be called at least once before the first call to Push(). May be
45 // called later just before each audio format change. Returns true if it is
46 // possible to EXACTLY re-chunk audio to the required |output_duration|
47 // provided to the constructor, false otherwise (e.g., 22050 Hz audio cannot
48 // be divided evenly into 10 ms chunks).
49 bool SetSampleRate(int sample_rate);
50
51 // Pushes all audio channel data from |input_bus| through the FIFO. This will
52 // result in zero, one, or multiple synchronous calls to the
53 // RechunkedAudioCallback provided in the constructor.
54 void Push(const AudioBus& input_bus, base::TimeDelta reference_timestamp);
55
56 private:
57 const base::TimeDelta output_duration_;
58 const RechunkedAudioCallback callback_;
59
60 // These are computed in each call to SetSampleRate().
61 int sample_rate_;
62 int output_frames_;
63
64 // Queue of frames pending for delivery.
65 scoped_ptr<AudioBus> audio_queue_;
66 int pending_frames_;
67
68 DISALLOW_COPY_AND_ASSIGN(AudioRechunker);
69 };
70
71 } // namespace media
72
73 #endif // MEDIA_BASE_AUDIO_RECHUNKER_H_
OLDNEW
« no previous file with comments | « media/base/audio_fifo.h ('k') | media/base/audio_rechunker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698