summaryrefslogtreecommitdiffstats
path: root/components/copresence
diff options
context:
space:
mode:
authorckehoe <ckehoe@chromium.org>2014-12-05 17:48:43 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-06 01:49:02 +0000
commit0844918913dc08661f01990b838faf4f8ffcb8af (patch)
tree0ec24fcce9da92e3f9abb7ff0e8bc9852029002f /components/copresence
parentf98986c03fb7047364b9e8bd8c3f74622a315802 (diff)
downloadchromium_src-0844918913dc08661f01990b838faf4f8ffcb8af.zip
chromium_src-0844918913dc08661f01990b838faf4f8ffcb8af.tar.gz
chromium_src-0844918913dc08661f01990b838faf4f8ffcb8af.tar.bz2
Fixing audioFail fail
BUG=437966 Review URL: https://codereview.chromium.org/786523003 Cr-Commit-Position: refs/heads/master@{#307141}
Diffstat (limited to 'components/copresence')
-rw-r--r--components/copresence/mediums/audio/audio_manager_impl.cc17
-rw-r--r--components/copresence/mediums/audio/audio_manager_impl.h7
2 files changed, 19 insertions, 5 deletions
diff --git a/components/copresence/mediums/audio/audio_manager_impl.cc b/components/copresence/mediums/audio/audio_manager_impl.cc
index fadfdf9..6d9f1d3 100644
--- a/components/copresence/mediums/audio/audio_manager_impl.cc
+++ b/components/copresence/mediums/audio/audio_manager_impl.cc
@@ -12,6 +12,7 @@
#include "base/logging.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
+#include "base/time/time.h"
#include "components/copresence/mediums/audio/audio_player_impl.h"
#include "components/copresence/mediums/audio/audio_recorder_impl.h"
#include "components/copresence/public/copresence_constants.h"
@@ -36,6 +37,7 @@ std::string FromUrlSafe(std::string token) {
const int kSampleExpiryTimeMs = 60 * 60 * 1000; // 60 minutes.
const int kMaxSamples = 10000;
+const int kTokenTimeoutMs = 2000;
} // namespace
@@ -48,8 +50,6 @@ AudioManagerImpl::AudioManagerImpl()
playing_[INAUDIBLE] = false;
recording_[AUDIBLE] = false;
recording_[INAUDIBLE] = false;
- heard_own_token_[AUDIBLE] = false;
- heard_own_token_[INAUDIBLE] = false;
player_[AUDIBLE] = nullptr;
player_[INAUDIBLE] = nullptr;
@@ -107,6 +107,7 @@ AudioManagerImpl::~AudioManagerImpl() {
void AudioManagerImpl::StartPlaying(AudioType type) {
DCHECK(type == AUDIBLE || type == INAUDIBLE);
playing_[type] = true;
+ started_playing_[type] = base::Time::Now();
// If we don't have our token encoded yet, this check will be false, for now.
// Once our token is encoded, OnTokenEncoded will call UpdateToken, which
// will call this code again (if we're still supposed to be playing).
@@ -170,7 +171,15 @@ bool AudioManagerImpl::IsPlaying(AudioType type) {
}
bool AudioManagerImpl::IsPlayingTokenHeard(AudioType type) {
- return heard_own_token_[type];
+ base::TimeDelta tokenTimeout =
+ base::TimeDelta::FromMilliseconds(kTokenTimeoutMs);
+
+ // This is a bit of a hack. If we haven't been playing long enough,
+ // return true to avoid tripping an audio fail alarm.
+ if (base::Time::Now() - started_playing_[type] < tokenTimeout)
+ return true;
+
+ return base::Time::Now() - heard_own_token_[type] < tokenTimeout;
}
// Private methods.
@@ -188,7 +197,7 @@ void AudioManagerImpl::OnTokensFound(const std::vector<AudioToken>& tokens) {
for (const auto& token : tokens) {
AudioType type = token.audible ? AUDIBLE : INAUDIBLE;
if (playing_token_[type] == token.token)
- heard_own_token_[type] = true;
+ heard_own_token_[type] = base::Time::Now();
if (recording_[AUDIBLE] && token.audible) {
tokens_to_report.push_back(token);
diff --git a/components/copresence/mediums/audio/audio_manager_impl.h b/components/copresence/mediums/audio/audio_manager_impl.h
index 82f8cf4..6c4b848 100644
--- a/components/copresence/mediums/audio/audio_manager_impl.h
+++ b/components/copresence/mediums/audio/audio_manager_impl.h
@@ -16,6 +16,10 @@
#include "components/copresence/public/copresence_constants.h"
#include "components/copresence/timed_map.h"
+namespace base {
+class Time;
+}
+
namespace copresence {
class AudioPlayer;
@@ -94,7 +98,8 @@ class AudioManagerImpl final : public AudioManager {
// Indexed using enum AudioType.
std::string playing_token_[2];
- bool heard_own_token_[2];
+ base::Time started_playing_[2];
+ base::Time heard_own_token_[2];
// Cache that holds the encoded samples. After reaching its limit, the cache
// expires the oldest samples first.