Fix Telemetry media seek action flakiness.
[chromium-blink-merge.git] / media / base / audio_splicer.h
blob50445b2d54c889018341772e7d2b686ce1fe84e3
1 // Copyright (c) 2012 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.
5 #ifndef MEDIA_BASE_AUDIO_SPLICER_H_
6 #define MEDIA_BASE_AUDIO_SPLICER_H_
8 #include <deque>
10 #include "base/memory/ref_counted.h"
11 #include "media/base/audio_timestamp_helper.h"
12 #include "media/base/media_export.h"
14 namespace media {
16 class AudioBuffer;
17 class AudioDecoderConfig;
19 // Helper class that handles filling gaps and resolving overlaps.
20 class MEDIA_EXPORT AudioSplicer {
21 public:
22 AudioSplicer(int samples_per_second);
23 ~AudioSplicer();
25 // Resets the splicer state by clearing the output buffers queue,
26 // and resetting the timestamp helper.
27 void Reset();
29 // Adds a new buffer full of samples or end of stream buffer to the splicer.
30 // Returns true if the buffer was accepted. False is returned if an error
31 // occurred.
32 bool AddInput(const scoped_refptr<AudioBuffer>& input);
34 // Returns true if the splicer has a buffer to return.
35 bool HasNextBuffer() const;
37 // Removes the next buffer from the output buffer queue and returns it.
38 // This should only be called if HasNextBuffer() returns true.
39 scoped_refptr<AudioBuffer> GetNextBuffer();
41 private:
42 void AddOutputBuffer(const scoped_refptr<AudioBuffer>& buffer);
44 AudioTimestampHelper output_timestamp_helper_;
46 // Minimum gap size needed before the splicer will take action to
47 // fill a gap. This avoids periodically inserting and then dropping samples
48 // when the buffer timestamps are slightly off because of timestamp rounding
49 // in the source content. Unit is frames.
50 int min_gap_size_;
52 std::deque<scoped_refptr<AudioBuffer> > output_buffers_;
53 bool received_end_of_stream_;
55 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioSplicer);
58 } // namespace media
60 #endif