Commit 45f3725b authored by atraczyk's avatar atraczyk Committed by gerrit2

audiolayer: use std::chrono for time calculations

- Notification tones for calls incoming when there is a call already
  in progress were using time_t objects to calculate the passage of
  time. This patch implements time_point objects instead, thus
  removing a dependency on sys/time.h which is not available on
  all platforms.
Reviewed-by: Guillaume Roguez's avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
Change-Id: I3850706e2f6ddb3fd5d308148883031a9cd0cb6b
Tuleap: #790
parent 71882bc4
......@@ -41,7 +41,7 @@ AudioLayer::AudioLayer(const AudioPreference &pref)
, urgentRingBuffer_("urgentRingBuffer_id", SIZEBUF, audioFormat_)
, resampler_(new Resampler{audioFormat_.sample_rate})
, inputResampler_(new Resampler{audioInputFormat_.sample_rate})
, lastNotificationTime_(0)
, lastNotificationTime_()
{
urgentRingBuffer_.createReadOffset(RingBufferPool::DEFAULT_ID);
}
......@@ -93,10 +93,10 @@ void AudioLayer::notifyIncomingCall()
if (!Manager::instance().incomingCallsWaiting())
return;
time_t now = time(NULL);
auto now = std::chrono::system_clock::now();
// Notify maximum once every 5 seconds
if (difftime(now, lastNotificationTime_) < 5)
if ((now - lastNotificationTime_) < std::chrono::seconds(5))
return;
lastNotificationTime_ = now;
......
......@@ -29,7 +29,7 @@
#include "dcblocker.h"
#include "noncopyable.h"
#include <sys/time.h>
#include <chrono>
#include <mutex>
#include <vector>
#include <atomic>
......@@ -311,7 +311,7 @@ class AudioLayer {
/**
* Time of the last incoming call notification
*/
time_t lastNotificationTime_;
std::chrono::system_clock::time_point lastNotificationTime_;
};
} // namespace ring
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment