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

Unified Diff: remoting/host/audio_capturer_win.cc

Issue 10825368: Modified Windows buffer size to avoid audio glitches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 4 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/audio_capturer_win.cc
diff --git a/remoting/host/audio_capturer_win.cc b/remoting/host/audio_capturer_win.cc
index c648a0ab0727c5c776e51a9bf66db3c4100bc8e4..03bd426b7747f0af2ad9f0f85d23fc416cca8be5 100644
--- a/remoting/host/audio_capturer_win.cc
+++ b/remoting/host/audio_capturer_win.cc
@@ -9,6 +9,7 @@
#include <mmreg.h>
#include <mmsystem.h>
+#include <algorithm>
#include <stdlib.h>
#include "base/basictypes.h"
@@ -27,13 +28,20 @@ const int kChannels = 2;
const int kBitsPerSample = 16;
const int kBitsPerByte = 8;
// Conversion factor from 100ns to 1ms.
-const int kHnsToMs = 10000;
+const int k100nsPerMillisecond = 10000;
// Tolerance for catching packets of silence. If all samples have absolute
// value less than this threshold, the packet will be counted as a packet of
// silence. A value of 2 was chosen, because Windows can give samples of 1 and
// -1, even when no audio is playing.
const int kSilenceThreshold = 2;
+
+// Lower bound for timer intervals, in milliseconds.
+const int kMinTimerInterval = 30;
Sergey Ulanov 2012/08/16 23:06:12 might be better to call it kMinTimerIntervalMs
+
+// Upper bound for the timer precision error, in milliseconds.
+// Timers are supposed to be accurate to 20ms, so we use 30ms to be safe.
+const int kMaxExpectedTimerLag = 30;
Sergey Ulanov 2012/08/16 23:06:12 Same here, add units in the name.
} // namespace
namespace remoting {
@@ -128,8 +136,12 @@ bool AudioCapturerWin::Start(const PacketCapturedCallback& callback) {
LOG(ERROR) << "IAudioClient::GetDevicePeriod failed. Error " << hr;
return false;
}
+ // We round up, if |device_period| / |k100nsPerMillisecond|
+ // is not a whole number.
+ int device_period_in_milliseconds =
Sergey Ulanov 2012/08/16 23:06:12 nit: can call device_period_ms
+ 1 + ((device_period - 1) / k100nsPerMillisecond);
audio_device_period_ = base::TimeDelta::FromMilliseconds(
Sergey Ulanov 2012/08/16 23:06:12 rename it to capture_period_ as you've changed the
- device_period / kChannels / kHnsToMs);
+ std::max(device_period_in_milliseconds, kMinTimerInterval));
// Get the wave format.
hr = audio_client_->GetMixFormat(&wave_format_ex_);
@@ -193,12 +205,14 @@ bool AudioCapturerWin::Start(const PacketCapturedCallback& callback) {
}
// Initialize the IAudioClient.
- hr = audio_client_->Initialize(AUDCLNT_SHAREMODE_SHARED,
- AUDCLNT_STREAMFLAGS_LOOPBACK,
- 0,
- 0,
- wave_format_ex_,
- NULL);
+ hr = audio_client_->Initialize(
+ AUDCLNT_SHAREMODE_SHARED,
+ AUDCLNT_STREAMFLAGS_LOOPBACK,
+ (kMaxExpectedTimerLag + audio_device_period_.InMilliseconds()) *
Sergey Ulanov 2012/08/16 23:06:12 nit: might be better to move this expression into
+ k100nsPerMillisecond,
+ 0,
+ wave_format_ex_,
+ NULL);
if (FAILED(hr)) {
LOG(ERROR) << "Failed to initialize IAudioClient. Error " << hr;
return false;
@@ -275,8 +289,8 @@ void AudioCapturerWin::DoCapture() {
}
if (!IsPacketOfSilence(
- reinterpret_cast<const int16*>(data),
- frames * kChannels)) {
+ reinterpret_cast<const int16*>(data),
+ frames * kChannels)) {
scoped_ptr<AudioPacket> packet =
scoped_ptr<AudioPacket>(new AudioPacket());
packet->add_data(data, frames * wave_format_ex_->nBlockAlign);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698