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

Unified Diff: media/base/audio_latency.cc

Issue 2750543003: Support AudioContextOptions latencyHint as double. (Closed)
Patch Set: Refactor audiocontextoptions LayoutTest. Created 3 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_latency.h ('k') | third_party/WebKit/LayoutTests/webaudio/audiocontextoptions.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/audio_latency.cc
diff --git a/media/base/audio_latency.cc b/media/base/audio_latency.cc
index 5d37edf415213ff72aeb6e9753927abf1dfb8894..61b3724efa48cc36fc8ff7c3a545c95d7ba5bb56 100644
--- a/media/base/audio_latency.cc
+++ b/media/base/audio_latency.cc
@@ -9,6 +9,7 @@
#include <algorithm>
#include "base/logging.h"
+#include "base/time/time.h"
#include "build/build_config.h"
namespace media {
@@ -126,4 +127,19 @@ int AudioLatency::GetInteractiveBufferSize(int hardware_buffer_size) {
return hardware_buffer_size;
}
+int AudioLatency::GetExactBufferSize(base::TimeDelta duration,
+ int sample_rate,
+ int hardware_buffer_size) {
+ const double requested_buffer_size = duration.InSecondsF() * sample_rate;
+
+ DCHECK_NE(0, hardware_buffer_size);
+
+ // Round the requested size to the nearest multiple of the hardware size
+ const int buffer_size =
+ std::round(std::max(requested_buffer_size, 1.0) / hardware_buffer_size) *
+ hardware_buffer_size;
+
+ return std::max(buffer_size, hardware_buffer_size);
+}
+
} // namespace media
« no previous file with comments | « media/base/audio_latency.h ('k') | third_party/WebKit/LayoutTests/webaudio/audiocontextoptions.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698