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

Unified Diff: media/base/audio_splicer.h

Issue 156783003: Enhance AudioSplicer to crossfade marked splice frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More tests. Created 6 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 side-by-side diff with in-line comments
Download patch
Index: media/base/audio_splicer.h
diff --git a/media/base/audio_splicer.h b/media/base/audio_splicer.h
index 50445b2d54c889018341772e7d2b686ce1fe84e3..4cbb6d125f10437dd60d828b178f7635b9763ff7 100644
--- a/media/base/audio_splicer.h
+++ b/media/base/audio_splicer.h
@@ -5,52 +5,65 @@
#ifndef MEDIA_BASE_AUDIO_SPLICER_H_
#define MEDIA_BASE_AUDIO_SPLICER_H_
-#include <deque>
-
#include "base/memory/ref_counted.h"
-#include "media/base/audio_timestamp_helper.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
#include "media/base/media_export.h"
namespace media {
class AudioBuffer;
-class AudioDecoderConfig;
+class AudioBus;
+class AudioStreamSanitizer;
// Helper class that handles filling gaps and resolving overlaps.
class MEDIA_EXPORT AudioSplicer {
public:
- AudioSplicer(int samples_per_second);
+ explicit AudioSplicer(int samples_per_second);
~AudioSplicer();
- // Resets the splicer state by clearing the output buffers queue,
- // and resetting the timestamp helper.
+ // Resets the splicer state by clearing the output buffers queue and resetting
+ // the timestamp helper.
void Reset();
// Adds a new buffer full of samples or end of stream buffer to the splicer.
- // Returns true if the buffer was accepted. False is returned if an error
+ // Returns true if the buffer was accepted. False is returned if an error
// occurred.
bool AddInput(const scoped_refptr<AudioBuffer>& input);
// Returns true if the splicer has a buffer to return.
bool HasNextBuffer() const;
- // Removes the next buffer from the output buffer queue and returns it.
- // This should only be called if HasNextBuffer() returns true.
+ // Removes the next buffer from the output buffer queue and returns it; this
+ // should only be called if HasNextBuffer() returns true.
scoped_refptr<AudioBuffer> GetNextBuffer();
+ // Indicates that overlapping buffers are coming up and should be crossfaded.
+ // Once set, all buffers encountered after |splice_timestamp| will be queued
+ // internally until at least 5ms of overlapping buffers are received (or end
+ // of stream, whichever comes first).
+ void SetSpliceTimestamp(base::TimeDelta splice_timestamp);
+
private:
- void AddOutputBuffer(const scoped_refptr<AudioBuffer>& buffer);
+ friend class AudioSplicerTest;
+
+ // Extracts frames to be crossfaded from |pre_splice_sanitizer_| and
+ // |post_splice_sanitizer_| respectively. Transfers partially consumed
+ // buffers into |output_sanitizer_| and drops consumed buffers.
+ void ExtractCrossfadeFromPreSplice(AudioBus* output_bus);
+ // Similar to above, but transfers unused buffers into |output_sanitizer_|.
+ void ExtractCrossfadeFromPostSplice(AudioBus* output_bus);
- AudioTimestampHelper output_timestamp_helper_;
+ // Returns the number of frames for a given duration.
+ int CalculateFrameCountFromDuration(base::TimeDelta duration);
- // Minimum gap size needed before the splicer will take action to
- // fill a gap. This avoids periodically inserting and then dropping samples
- // when the buffer timestamps are slightly off because of timestamp rounding
- // in the source content. Unit is frames.
- int min_gap_size_;
+ const double samples_per_second_;
+ const base::TimeDelta max_crossfade_duration_;
+ base::TimeDelta splice_timestamp_;
- std::deque<scoped_refptr<AudioBuffer> > output_buffers_;
- bool received_end_of_stream_;
+ scoped_ptr<AudioStreamSanitizer> output_sanitizer_;
+ scoped_ptr<AudioStreamSanitizer> pre_splice_sanitizer_;
acolwell GONE FROM CHROMIUM 2014/02/24 21:46:11 nit: Docs for these so it is easier to understand
DaleCurtis 2014/02/26 02:38:45 Done.
+ scoped_ptr<AudioStreamSanitizer> post_splice_sanitizer_;
DISALLOW_IMPLICIT_CONSTRUCTORS(AudioSplicer);
};

Powered by Google App Engine
This is Rietveld 408576698