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

Unified Diff: components/copresence/mediums/audio/audio_manager_impl.cc

Issue 786523003: Fixing audioFail fail (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 | « components/copresence/mediums/audio/audio_manager_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/copresence/mediums/audio/audio_manager_impl.cc
diff --git a/components/copresence/mediums/audio/audio_manager_impl.cc b/components/copresence/mediums/audio/audio_manager_impl.cc
index fadfdf9847ef7bb5426bd91dd26b84ae2f3f223c..6d9f1d3d87eed39c8f61296016bb49140dbca757 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);
« no previous file with comments | « components/copresence/mediums/audio/audio_manager_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698