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

Unified Diff: media/base/audio_discard_helper.h

Issue 259453003: Introduce AudioDiscardHelper. Refactor audio decoders to use it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix x64 type. Created 6 years, 8 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
« no previous file with comments | « media/base/audio_buffer.h ('k') | media/base/audio_discard_helper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/audio_discard_helper.h
diff --git a/media/base/audio_discard_helper.h b/media/base/audio_discard_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..388cbd421a380f8ac5646ac3c87dc060bb04774f
--- /dev/null
+++ b/media/base/audio_discard_helper.h
@@ -0,0 +1,63 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_BASE_AUDIO_DISCARD_HELPER_H_
+#define MEDIA_BASE_AUDIO_DISCARD_HELPER_H_
+
+#include "base/memory/ref_counted.h"
+#include "base/time/time.h"
+#include "media/base/audio_timestamp_helper.h"
+#include "media/base/buffers.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+class AudioBuffer;
+class DecoderBuffer;
+
+// Helper class for managing timestamps and discard events around decoding.
+class MEDIA_EXPORT AudioDiscardHelper {
+ public:
+ explicit AudioDiscardHelper(int sample_rate);
+ ~AudioDiscardHelper();
+
+ // Converts a TimeDelta to a frame count based on the constructed sample rate.
+ // |duration| must be positive.
+ size_t TimeDeltaToFrames(base::TimeDelta duration) const;
+
+ // Resets internal state and indicates that |initial_discard| of upcoming
+ // frames should be discarded.
+ void Reset(size_t initial_discard);
+
+ // Applies discard padding from the encoded buffer along with any initial
+ // discards. |decoded_buffer| may be NULL, if not the timestamp and duration
+ // will be set after discards are applied. Returns true if |decoded_buffer|
+ // exists after processing discard events. Returns false if |decoded_buffer|
+ // was NULL, is completely discarded, or a processing error occurs.
+ //
+ // If AudioDiscardHelper is not initialized() the timestamp of the first
+ // |encoded_buffer| will be used as the basis for all future timestamps set on
+ // |decoded_buffer|s. If the first buffer has a negative timestamp it will be
+ // clamped to zero.
+ bool ProcessBuffers(const scoped_refptr<DecoderBuffer>& encoded_buffer,
+ const scoped_refptr<AudioBuffer>& decoded_buffer);
+
+ // Whether any buffers have been processed.
+ bool initialized() const {
+ return timestamp_helper_.base_timestamp() != kNoTimestamp();
+ }
+
+ private:
+ const int sample_rate_;
+ AudioTimestampHelper timestamp_helper_;
+
+ size_t discard_frames_;
+ base::TimeDelta last_input_timestamp_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(AudioDiscardHelper);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_AUDIO_DISCARD_HELPER_H_
« no previous file with comments | « media/base/audio_buffer.h ('k') | media/base/audio_discard_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698