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

Unified Diff: media/base/audio_latency.cc

Issue 2750543003: Support AudioContextOptions latencyHint as double. (Closed)
Patch Set: More updates based on reviewer comments. Created 3 years, 9 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..bcf7bbb68283125f645049590c2957f2d9e5865d 100644
--- a/media/base/audio_latency.cc
+++ b/media/base/audio_latency.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "build/build_config.h"
+#include "media/base/audio_parameters.h"
namespace media {
@@ -126,4 +127,22 @@ int AudioLatency::GetInteractiveBufferSize(int hardware_buffer_size) {
return hardware_buffer_size;
}
+int AudioLatency::GetExactBufferSize(base::TimeDelta duration,
+ const AudioParameters& hardware_params) {
+ const int hardware_buffer_size = hardware_params.frames_per_buffer();
+ const double requested_buffer_size =
+ duration.InSecondsF() * hardware_params.sample_rate();
+
+ // Round up the requested size to the nearest multiple of the hardware size
+ const int buffer_size =
+ std::ceil(std::max(requested_buffer_size, 1.0) / hardware_buffer_size) *
+ hardware_buffer_size;
o1ka 2017/03/29 10:56:05 It's actually not the nearest multiply (round), bu
Andrew MacPherson 2017/03/30 08:07:18 This was my intent but since both you and dalecurt
+
+ const double twenty_ms_size = 2.0 * hardware_params.sample_rate() / 100;
+ const int max_buffer_size =
+ std::ceil(twenty_ms_size / hardware_buffer_size) * hardware_buffer_size;
o1ka 2017/03/29 10:56:05 In fact, we are just limiting |duration| to 20 ms,
DaleCurtis 2017/03/29 22:42:41 Hmm, this wasn't what I was proposing. I was propo
Andrew MacPherson 2017/03/30 08:07:18 Sorry, my mistake here. I can remove this but I be
DaleCurtis 2017/03/30 18:53:46 This should be removed from this code. We don't wa
+
+ return std::max(std::min(buffer_size, max_buffer_size), hardware_buffer_size);
+}
o1ka 2017/03/29 10:56:05 Dale - Is our intention to use multiplies of HW bu
DaleCurtis 2017/03/29 22:42:41 Yes, I think that should be okay and likely will r
DaleCurtis 2017/03/29 22:42:41 Yes, I think that should be okay and likely will r
Andrew MacPherson 2017/03/30 08:07:18 Ok, I've updated GetHighLatencyBufferSize() to alw
+
} // 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