Files
android/libwvdrmengine/cdm/core/src/policy_timers.cpp
Rahul Frias 6a1f050ffc Update Widevine Copyright header for core CDM
[ Merge of http://go/wvgerrit/108064 ]

The Widevine License Agreement has been renamed to use inclusive
language. This covers files in the core directory.

Bug: 168562298
Test: verified compilation (comment only change)
Change-Id: I8ae5a10cbfdf7faae6a2735e57b33729763f10b8
2020-10-21 12:05:05 -07:00

111 lines
3.5 KiB
C++

// Copyright 2020 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
#include "policy_timers.h"
#include <limits.h>
#include <string>
#include "log.h"
using video_widevine::License;
namespace wvcdm {
void PolicyTimers::SetLicense(const video_widevine::License& license) {
policy_.Clear();
if (license.has_license_start_time())
license_start_time_ = license.license_start_time();
}
void PolicyTimers::DecryptionEvent(int64_t current_time) {
last_playback_time_ = current_time;
}
int64_t PolicyTimers::GetPlaybackDurationRemaining(int64_t current_time) {
const int64_t playback_duration = policy_.playback_duration_seconds();
if (playback_duration == 0) return LLONG_MAX;
if (playback_start_time_ == 0) return playback_duration;
const int64_t playback_expiry_time = playback_duration + playback_start_time_;
if (playback_expiry_time < current_time) return 0;
const int64_t policy_playback_duration = policy_.playback_duration_seconds();
return std::min(playback_expiry_time - current_time,
policy_playback_duration);
}
bool PolicyTimers::GetSecondsSinceStarted(int64_t current_time,
int64_t* seconds_since_started) {
if (seconds_since_started == nullptr) {
LOGE("|seconds_since_started| not provided");
return false;
}
if (playback_start_time_ == 0) return false;
*seconds_since_started = current_time - playback_start_time_;
return (*seconds_since_started >= 0) ? true : false;
}
bool PolicyTimers::GetSecondsSinceLastPlayed(
int64_t current_time, int64_t* seconds_since_last_played) {
if (seconds_since_last_played == nullptr) {
LOGE("|seconds_since_last_played| not provided");
return false;
}
if (last_playback_time_ == 0) return false;
*seconds_since_last_played = current_time - last_playback_time_;
return (*seconds_since_last_played >= 0) ? true : false;
}
bool PolicyTimers::IsLicenseForFuture(int64_t current_time) {
return current_time < license_start_time_;
}
bool PolicyTimers::UpdateExpirationTime(int64_t current_time,
int64_t* expiry_time) {
if (expiry_time == nullptr) {
LOGE("|expiry_time| mot provided");
return false;
}
*expiry_time =
GetExpiryTime(current_time,
/* ignore_soft_enforce_playback_duration */ false);
const bool has_expiry_time_been_updated =
!last_expiry_time_set_ || *expiry_time != last_expiry_time_;
if (has_expiry_time_been_updated) last_expiry_time_ = *expiry_time;
last_expiry_time_set_ = true;
return has_expiry_time_been_updated;
}
bool PolicyTimers::HasRenewalDelayExpired(int64_t current_time) {
return policy_.can_renew() && (policy_.renewal_delay_seconds() > 0) &&
(license_start_time_ + policy_.renewal_delay_seconds() <=
current_time);
}
bool PolicyTimers::HasRenewalRetryIntervalExpired(int64_t current_time) {
return policy_.can_renew() &&
(policy_.renewal_retry_interval_seconds() > 0) &&
(next_renewal_time_ <= current_time);
}
void PolicyTimers::UpdateRenewalRequest(int64_t current_time) {
next_renewal_time_ = current_time + policy_.renewal_retry_interval_seconds();
}
bool PolicyTimers::HasRenewalRecoveryDurationExpired(int64_t current_time) {
return (policy_.renewal_recovery_duration_seconds() > 0) &&
(license_start_time_ + policy_.renewal_recovery_duration_seconds() <=
current_time);
}
} // namespace wvcdm