diff --git a/base/logging.cc b/base/logging.cc index 5a159ff4f3a0..df473b4b4a46 100644 --- a/base/logging.cc +++ b/base/logging.cc @@ -15,11 +15,11 @@ #include "starboard/client_porting/eztime/eztime.h" #include "starboard/common/log.h" #include "starboard/common/mutex.h" +#include "starboard/common/time.h" #include "starboard/configuration.h" #include "starboard/configuration_constants.h" #include "starboard/file.h" #include "starboard/system.h" -#include "starboard/time.h" typedef SbFile FileHandle; typedef SbMutex MutexHandle; #else @@ -210,7 +210,7 @@ int32_t CurrentProcessId() { uint64_t TickCount() { #if defined(STARBOARD) - return static_cast(SbTimeGetMonotonicNow()); + return starboard::CurrentMonotonicTime(); #else #if defined(OS_WIN) return GetTickCount(); diff --git a/base/time/time_now_starboard.cc b/base/time/time_now_starboard.cc index 88928462c285..ca4ef81085e7 100644 --- a/base/time/time_now_starboard.cc +++ b/base/time/time_now_starboard.cc @@ -21,6 +21,7 @@ #include "starboard/client_porting/poem/eztime_poem.h" #include "starboard/common/log.h" +#include "starboard/common/time.h" #include "starboard/time.h" #include "starboard/types.h" @@ -30,7 +31,8 @@ namespace base { namespace subtle { Time TimeNowIgnoringOverride() { - return Time() + TimeDelta::FromMicroseconds(SbTimeGetNow()); + return Time() + TimeDelta::FromMicroseconds( + starboard::PosixTimeToWindowsTime(starboard::CurrentPosixTime())); } Time TimeNowFromSystemTimeIgnoringOverride() { @@ -43,7 +45,8 @@ Time TimeNowFromSystemTimeIgnoringOverride() { namespace subtle { TimeTicks TimeTicksNowIgnoringOverride() { - return TimeTicks() + TimeDelta::FromMicroseconds(SbTimeGetMonotonicNow()); + return TimeTicks() + TimeDelta::FromMicroseconds( + starboard::CurrentMonotonicTime()); } } // namespace subtle diff --git a/cobalt/base/statistics.h b/cobalt/base/statistics.h index b154573f4d15..13c489115d42 100644 --- a/cobalt/base/statistics.h +++ b/cobalt/base/statistics.h @@ -42,7 +42,7 @@ inline int64_t DefaultSampleToValueFunc(int64_t dividend, int64_t divisor) { // by `SampleToValueFunc` using its dividend and divisor. // // Example usages: -// 1. Set dividends to bytes in int and divisors to SbTime, to track the +// 1. Set dividends to bytes in int and divisors to int64_t, to track the // statistics of bandwidth. // 2. Set the divisor to always be 1, to track the statistics of a count or a // duration. diff --git a/cobalt/base/wrap_main.h b/cobalt/base/wrap_main.h index bfdab781f912..4ec9248fbf59 100644 --- a/cobalt/base/wrap_main.h +++ b/cobalt/base/wrap_main.h @@ -42,7 +42,7 @@ typedef int (*MainFunction)(int argc, char** argv); // A start-style function. typedef void (*StartFunction)(int argc, char** argv, const char* link, const base::Closure& quit_closure, - SbTimeMonotonic timestamp); + int64_t timestamp); // A function type that can be called at shutdown. typedef void (*StopFunction)(); @@ -53,8 +53,7 @@ typedef void (*EventFunction)(const SbEvent* event); // No-operation function that can be passed into start_function if no start work // is needed. void NoopStartFunction(int argc, char** argv, const char* link, - const base::Closure& quit_closure, - SbTimeMonotonic timestamp) {} + const base::Closure& quit_closure, int64_t timestamp) {} // No-operation function that can be passed into event_function if no other // event handling work is needed. diff --git a/cobalt/bindings/testing/bindings_sandbox_main.cc b/cobalt/bindings/testing/bindings_sandbox_main.cc index 3e57a223ab7d..e1e0facc12b9 100644 --- a/cobalt/bindings/testing/bindings_sandbox_main.cc +++ b/cobalt/bindings/testing/bindings_sandbox_main.cc @@ -29,8 +29,7 @@ namespace { cobalt::script::StandaloneJavascriptRunner* g_javascript_runner = NULL; void StartApplication(int argc, char** argv, const char* link, - const base::Closure& quit_closure, - SbTimeMonotonic timestamp) { + const base::Closure& quit_closure, int64_t timestamp) { scoped_refptr test_window = new Window(); cobalt::script::JavaScriptEngine::Options javascript_engine_options; diff --git a/cobalt/bindings/testing/date_bindings_test.cc b/cobalt/bindings/testing/date_bindings_test.cc index 9b4c420effb1..00048e2743ee 100644 --- a/cobalt/bindings/testing/date_bindings_test.cc +++ b/cobalt/bindings/testing/date_bindings_test.cc @@ -17,6 +17,7 @@ #include "cobalt/bindings/testing/bindings_test_base.h" #include "cobalt/bindings/testing/interface_with_date.h" #include "starboard/client_porting/eztime/eztime.h" +#include "starboard/common/time.h" #include "starboard/time_zone.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -77,7 +78,8 @@ TEST_F(DateBindingsTest, PosixEpoch) { EvaluateScript("Date.now();", &result); auto js_now_ms = std::stoll(result); - auto posix_now_ms = SbTimeToPosix(SbTimeGetNow()) / kSbTimeMillisecond; + auto posix_now_ms = + starboard::CurrentPosixTime() / base::Time::kMicrosecondsPerMillisecond; EXPECT_LT(std::abs(posix_now_ms - js_now_ms), 1000); } @@ -104,15 +106,14 @@ TEST_F(DateBindingsTest, StarboardTimeZone) { } TEST_F(DateBindingsTest, TimezoneOffset) { - EzTimeExploded ez_exploded; - - auto eztt = EzTimeTFromSbTime(SbTimeGetNow()); - EzTimeTExplodeLocal(&eztt, &ez_exploded); - // ez_exploded is already local time, use UTC method to convert to + EzTimeT ezttnow = static_cast(starboard::CurrentPosixTime() / + base::Time::kMicrosecondsPerSecond); + EzTimeExploded ez_exploded_local; + EzTimeTExplodeLocal(&ezttnow, &ez_exploded_local); + // ez_exploded_local is already local time, use UTC method to convert to // EzTimeT. - EzTimeT local_time_minutes = EzTimeTImplodeUTC(&ez_exploded) / 60; - EzTimeT utc_minutes = EzTimeTFromSbTime(SbTimeGetNow()) / 60; - EzTimeT timezone_offset = utc_minutes - local_time_minutes; + EzTimeT local_time_minutes = EzTimeTImplodeUTC(&ez_exploded_local) / 60; + EzTimeT utc_minutes = ezttnow / 60; std::string result; EvaluateScript("new Date().getTimezoneOffset();", &result); diff --git a/cobalt/browser/application.cc b/cobalt/browser/application.cc index 1f73882376c2..569fff3b416d 100644 --- a/cobalt/browser/application.cc +++ b/cobalt/browser/application.cc @@ -83,7 +83,6 @@ #include "starboard/extension/crash_handler.h" #include "starboard/extension/installation_manager.h" #include "starboard/system.h" -#include "starboard/time.h" #include "url/gurl.h" #if SB_IS(EVERGREEN) @@ -626,7 +625,7 @@ ssize_t Application::available_memory_ = 0; int64 Application::lifetime_in_ms_ = 0; Application::Application(const base::Closure& quit_closure, bool should_preload, - SbTimeMonotonic timestamp) + int64_t timestamp) : message_loop_(base::MessageLoop::current()), quit_closure_(quit_closure) { DCHECK(!quit_closure_.is_null()); if (should_preload) { @@ -1066,7 +1065,7 @@ Application::~Application() { network_module_.reset(); } -void Application::Start(SbTimeMonotonic timestamp) { +void Application::Start(int64_t timestamp) { if (base::MessageLoop::current() != message_loop_) { message_loop_->task_runner()->PostTask( FROM_HERE, @@ -1182,7 +1181,7 @@ void Application::HandleStarboardEvent(const SbEvent* starboard_event) { } void Application::OnApplicationEvent(SbEventType event_type, - SbTimeMonotonic timestamp) { + int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "Application::OnApplicationEvent()"); DCHECK_CALLED_ON_VALID_THREAD(application_event_thread_checker_); @@ -1462,8 +1461,7 @@ void Application::OnDeepLinkConsumedCallback(const std::string& link) { } } -void Application::DispatchDeepLink(const char* link, - SbTimeMonotonic timestamp) { +void Application::DispatchDeepLink(const char* link, int64_t timestamp) { if (!link || *link == 0) { return; } @@ -1491,7 +1489,7 @@ void Application::DispatchDeepLink(const char* link, void Application::DispatchDeepLinkIfNotConsumed() { std::string deep_link; - SbTimeMonotonic timestamp; + int64_t timestamp; // This block exists to ensure that the lock is held while accessing // unconsumed_deep_link_. { diff --git a/cobalt/browser/application.h b/cobalt/browser/application.h index 501521991b91..572e2b358693 100644 --- a/cobalt/browser/application.h +++ b/cobalt/browser/application.h @@ -30,7 +30,6 @@ #include "cobalt/network/network_module.h" #include "cobalt/persistent_storage/persistent_settings.h" #include "cobalt/system_window/system_window.h" -#include "starboard/time.h" #if SB_IS(EVERGREEN) #include "cobalt/updater/updater_module.h" #endif @@ -55,11 +54,11 @@ class Application { // The passed in |quit_closure| can be called internally by the Application // to signal that it would like to quit. Application(const base::Closure& quit_closure, bool should_preload, - SbTimeMonotonic timestamp); + int64_t timestamp); virtual ~Application(); // Start from a preloaded state. - void Start(SbTimeMonotonic timestamp); + void Start(int64_t timestamp); void Quit(); void HandleStarboardEvent(const SbEvent* event); @@ -70,7 +69,7 @@ class Application { void OnNetworkEvent(const base::Event* event); // Called to handle an application event. - void OnApplicationEvent(SbEventType event_type, SbTimeMonotonic timestamp); + void OnApplicationEvent(SbEventType event_type, int64_t timestamp); // Called to handle a window size change event. void OnWindowSizeChangedEvent(const base::Event* event); @@ -175,8 +174,8 @@ class Application { void UpdatePeriodicStats(); void DispatchEventInternal(base::Event* event); - base::Optional preload_timestamp_; - base::Optional start_timestamp_; + base::Optional preload_timestamp_; + base::Optional start_timestamp_; // Json PrefStore used for persistent settings. std::unique_ptr persistent_settings_; @@ -204,13 +203,13 @@ class Application { // Lock for access to unconsumed_deep_link_ from different threads. base::Lock unconsumed_deep_link_lock_; - SbTimeMonotonic deep_link_timestamp_ = 0; + int64_t deep_link_timestamp_ = 0; // Called when deep links are consumed. void OnDeepLinkConsumedCallback(const std::string& link); // Dispatch events for deep links. - void DispatchDeepLink(const char* link, SbTimeMonotonic timestamp); + void DispatchDeepLink(const char* link, int64_t timestamp); void DispatchDeepLinkIfNotConsumed(); diff --git a/cobalt/browser/browser_module.cc b/cobalt/browser/browser_module.cc index f44b2b2672fc..dc3e0386f604 100644 --- a/cobalt/browser/browser_module.cc +++ b/cobalt/browser/browser_module.cc @@ -58,10 +58,10 @@ #include "cobalt/web/navigator_ua_data.h" #include "starboard/atomic.h" #include "starboard/common/string.h" +#include "starboard/common/time.h" #include "starboard/configuration.h" #include "starboard/extension/graphics.h" #include "starboard/system.h" -#include "starboard/time.h" #include "third_party/icu/source/i18n/unicode/timezone.h" #if SB_HAS(CORE_DUMP_HANDLER_SUPPORT) @@ -88,8 +88,10 @@ struct NonTrivialGlobalVariables { NonTrivialGlobalVariables::NonTrivialGlobalVariables() { last_render_timestamp = &cobalt::timestamp::g_last_render_timestamp; - SbAtomicNoBarrier_Exchange64(last_render_timestamp, - static_cast(SbTimeGetNow())); + SbAtomicNoBarrier_Exchange64( + last_render_timestamp, + static_cast( + starboard::PosixTimeToWindowsTime(starboard::CurrentPosixTime()))); } base::LazyInstance::DestructorAtExit @@ -1578,7 +1580,7 @@ void BrowserModule::SetProxy(const std::string& proxy_rules) { network_module_->SetProxy(proxy_rules); } -void BrowserModule::Blur(SbTimeMonotonic timestamp) { +void BrowserModule::Blur(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "BrowserModule::Blur()"); DCHECK_EQ(base::MessageLoop::current(), self_message_loop_); DCHECK(application_state_ == base::kApplicationStateStarted); @@ -1592,7 +1594,7 @@ void BrowserModule::Blur(SbTimeMonotonic timestamp) { } } -void BrowserModule::Conceal(SbTimeMonotonic timestamp) { +void BrowserModule::Conceal(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "BrowserModule::Conceal()"); DCHECK_EQ(base::MessageLoop::current(), self_message_loop_); DCHECK(application_state_ == base::kApplicationStateBlurred); @@ -1600,7 +1602,7 @@ void BrowserModule::Conceal(SbTimeMonotonic timestamp) { ConcealInternal(timestamp); } -void BrowserModule::Freeze(SbTimeMonotonic timestamp) { +void BrowserModule::Freeze(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "BrowserModule::Freeze()"); DCHECK_EQ(base::MessageLoop::current(), self_message_loop_); DCHECK(application_state_ == base::kApplicationStateConcealed); @@ -1608,7 +1610,7 @@ void BrowserModule::Freeze(SbTimeMonotonic timestamp) { FreezeInternal(timestamp); } -void BrowserModule::Unfreeze(SbTimeMonotonic timestamp) { +void BrowserModule::Unfreeze(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "BrowserModule::Unfreeze()"); DCHECK_EQ(base::MessageLoop::current(), self_message_loop_); DCHECK(application_state_ == base::kApplicationStateFrozen); @@ -1617,7 +1619,7 @@ void BrowserModule::Unfreeze(SbTimeMonotonic timestamp) { NavigatePendingURL(); } -void BrowserModule::Reveal(SbTimeMonotonic timestamp) { +void BrowserModule::Reveal(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "BrowserModule::Reveal()"); DCHECK_EQ(base::MessageLoop::current(), self_message_loop_); DCHECK(application_state_ == base::kApplicationStateConcealed); @@ -1625,7 +1627,7 @@ void BrowserModule::Reveal(SbTimeMonotonic timestamp) { RevealInternal(timestamp); } -void BrowserModule::Focus(SbTimeMonotonic timestamp) { +void BrowserModule::Focus(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "BrowserModule::Focus()"); DCHECK_EQ(base::MessageLoop::current(), self_message_loop_); DCHECK(application_state_ == base::kApplicationStateBlurred); @@ -1696,9 +1698,10 @@ void BrowserModule::OnWebModuleRendererSubmissionRasterized() { #if defined(COBALT_CHECK_RENDER_TIMEOUT) void BrowserModule::OnPollForRenderTimeout(const GURL& url) { - SbTime last_render_timestamp = static_cast(SbAtomicAcquire_Load64( + int64_t last_render_timestamp = static_cast(SbAtomicAcquire_Load64( non_trivial_global_variables.Get().last_render_timestamp)); - base::Time last_render = base::Time::FromSbTime(last_render_timestamp); + base::Time last_render = base::Time::FromDeltaSinceWindowsEpoch( + base::TimeDelta::FromMicroseconds(last_render_timestamp)); bool timeout_expiration = base::Time::Now() - base::TimeDelta::FromSeconds( kLastRenderTimeoutSeconds) > last_render; @@ -1720,7 +1723,7 @@ void BrowserModule::OnPollForRenderTimeout(const GURL& url) { #endif SbAtomicNoBarrier_Exchange64( non_trivial_global_variables.Get().last_render_timestamp, - static_cast(kSbTimeMax)); + static_cast(kSbInt64Max)); if (SbSystemGetRandomUInt64() < kRenderTimeoutErrorPercentage * (UINT64_MAX / 100)) { OnError(url, std::string("Rendering Timeout")); @@ -1889,7 +1892,7 @@ void BrowserModule::UpdateScreenSize() { } } -void BrowserModule::ConcealInternal(SbTimeMonotonic timestamp) { +void BrowserModule::ConcealInternal(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "BrowserModule::ConcealInternal()"); FOR_EACH_OBSERVER(LifecycleObserver, lifecycle_observers_, Conceal(GetResourceProvider(), timestamp)); @@ -1917,7 +1920,7 @@ void BrowserModule::ConcealInternal(SbTimeMonotonic timestamp) { } } -void BrowserModule::FreezeInternal(SbTimeMonotonic timestamp) { +void BrowserModule::FreezeInternal(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "BrowserModule::FreezeInternal()"); FreezeMediaModule(); // First freeze all our web modules which implies that they will release @@ -1930,7 +1933,7 @@ void BrowserModule::FreezeInternal(SbTimeMonotonic timestamp) { } } -void BrowserModule::RevealInternal(SbTimeMonotonic timestamp) { +void BrowserModule::RevealInternal(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "BrowserModule::RevealInternal()"); DCHECK(!renderer_module_); if (!system_window_) { @@ -1954,7 +1957,7 @@ void BrowserModule::RevealInternal(SbTimeMonotonic timestamp) { } } -void BrowserModule::UnfreezeInternal(SbTimeMonotonic timestamp) { +void BrowserModule::UnfreezeInternal(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "BrowserModule::UnfreezeInternal()"); // Set the Stub resource provider to media module and to web module // at Concealed state. @@ -2243,7 +2246,7 @@ scoped_refptr BrowserModule::CreateH5vccCallback( return scoped_refptr(h5vcc_object); } -void BrowserModule::SetDeepLinkTimestamp(SbTimeMonotonic timestamp) { +void BrowserModule::SetDeepLinkTimestamp(int64_t timestamp) { if (base::MessageLoop::current() != self_message_loop_) { self_message_loop_->task_runner()->PostTask( FROM_HERE, base::Bind(&BrowserModule::SetDeepLinkTimestamp, diff --git a/cobalt/browser/browser_module.h b/cobalt/browser/browser_module.h index abf05fd8f5e0..1745acf9c815 100644 --- a/cobalt/browser/browser_module.h +++ b/cobalt/browser/browser_module.h @@ -71,7 +71,6 @@ #include "cobalt/web/web_settings.h" #include "cobalt/webdriver/session_driver.h" #include "starboard/configuration.h" -#include "starboard/time.h" #include "starboard/window.h" #include "url/gurl.h" @@ -193,12 +192,12 @@ class BrowserModule { void SetProxy(const std::string& proxy_rules); // LifecycleObserver-similar interface. - void Blur(SbTimeMonotonic timestamp); - void Conceal(SbTimeMonotonic timestamp); - void Freeze(SbTimeMonotonic timestamp); - void Unfreeze(SbTimeMonotonic timestamp); - void Reveal(SbTimeMonotonic timestamp); - void Focus(SbTimeMonotonic timestamp); + void Blur(int64_t timestamp); + void Conceal(int64_t timestamp); + void Freeze(int64_t timestamp); + void Unfreeze(int64_t timestamp); + void Reveal(int64_t timestamp); + void Focus(int64_t timestamp); // Gets current application state. base::ApplicationState GetApplicationState(); @@ -242,7 +241,7 @@ class BrowserModule { std::map& map); // Pass the deeplink timestamp from Starboard. - void SetDeepLinkTimestamp(SbTimeMonotonic timestamp); + void SetDeepLinkTimestamp(int64_t timestamp); private: #if SB_HAS(CORE_DUMP_HANDLER_SUPPORT) @@ -456,19 +455,19 @@ class BrowserModule { // Does all the steps for half of a Conceal that happen prior to // the app state update. - void ConcealInternal(SbTimeMonotonic timestamp); + void ConcealInternal(int64_t timestamp); // Does all the steps for half of a Freeze that happen prior to // the app state update. - void FreezeInternal(SbTimeMonotonic timestamp); + void FreezeInternal(int64_t timestamp); // Does all the steps for half of a Reveal that happen prior to // the app state update. - void RevealInternal(SbTimeMonotonic timestamp); + void RevealInternal(int64_t timestamp); // Does all the steps for half of a Unfreeze that happen prior to // the app state update. - void UnfreezeInternal(SbTimeMonotonic timestamp); + void UnfreezeInternal(int64_t timestamp); // Check debug console, splash screen and web module if they are // ready to freeze at Concealed state. If so, call SystemRequestFreeze diff --git a/cobalt/browser/debug_console.h b/cobalt/browser/debug_console.h index c77e1eca6479..8193d832c38a 100644 --- a/cobalt/browser/debug_console.h +++ b/cobalt/browser/debug_console.h @@ -95,21 +95,21 @@ class DebugConsole : public LifecycleObserver { } // LifecycleObserver implementation. - void Blur(SbTimeMonotonic timestamp) override { web_module_->Blur(0); } + void Blur(int64_t timestamp) override { web_module_->Blur(0); } void Conceal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) override { + int64_t timestamp) override { web_module_->Conceal(resource_provider, 0); } - void Freeze(SbTimeMonotonic timestamp) override { web_module_->Freeze(0); } + void Freeze(int64_t timestamp) override { web_module_->Freeze(0); } void Unfreeze(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) override { + int64_t timestamp) override { web_module_->Unfreeze(resource_provider, 0); } void Reveal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) override { + int64_t timestamp) override { web_module_->Reveal(resource_provider, 0); } - void Focus(SbTimeMonotonic timestamp) override { web_module_->Focus(0); } + void Focus(int64_t timestamp) override { web_module_->Focus(0); } void ReduceMemory() { web_module_->ReduceMemory(); } diff --git a/cobalt/browser/lifecycle_observer.h b/cobalt/browser/lifecycle_observer.h index 499bb10de441..a2ff462b53d1 100644 --- a/cobalt/browser/lifecycle_observer.h +++ b/cobalt/browser/lifecycle_observer.h @@ -26,32 +26,32 @@ namespace browser { class LifecycleObserver : public base::CheckedObserver { public: // Blurs from Started, staying visible and retaining graphics resources. - virtual void Blur(SbTimeMonotonic timestamp) = 0; + virtual void Blur(int64_t timestamp) = 0; // Conceals from Blurred, transitioning to invisible but background tasks can // still be running. virtual void Conceal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) = 0; + int64_t timestamp) = 0; // Freezes from Concealed, and releases its reference to the ResourceProvider, // additionally releasing all references to any resources created from // it. This method must only be called if the object has previously been // Concealed. - virtual void Freeze(SbTimeMonotonic timestamp) = 0; + virtual void Freeze(int64_t timestamp) = 0; // Unfreezes from Frozen, with a new ResourceProvider. This method must only // be called if the object has previously been Frozen. virtual void Unfreeze(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) = 0; + int64_t timestamp) = 0; // Reveals from Concealed, going back into partially-obscured state. This // method must only be called if the object has previously been Concealed. virtual void Reveal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) = 0; + int64_t timestamp) = 0; // Focuses, going back to the Started state, and continuing to use the same // ResourceProvider and graphics resources. - virtual void Focus(SbTimeMonotonic timestamp) = 0; + virtual void Focus(int64_t timestamp) = 0; protected: virtual ~LifecycleObserver() {} diff --git a/cobalt/browser/main.cc b/cobalt/browser/main.cc index ff13b37b9368..252793fcea7c 100644 --- a/cobalt/browser/main.cc +++ b/cobalt/browser/main.cc @@ -57,8 +57,7 @@ bool CheckForAndExecuteStartupSwitches() { } void PreloadApplication(int argc, char** argv, const char* link, - const base::Closure& quit_closure, - SbTimeMonotonic timestamp) { + const base::Closure& quit_closure, int64_t timestamp) { if (CheckForAndExecuteStartupSwitches()) { SbSystemRequestStop(0); return; @@ -71,8 +70,7 @@ void PreloadApplication(int argc, char** argv, const char* link, } void StartApplication(int argc, char** argv, const char* link, - const base::Closure& quit_closure, - SbTimeMonotonic timestamp) { + const base::Closure& quit_closure, int64_t timestamp) { if (CheckForAndExecuteStartupSwitches()) { SbSystemRequestStop(0); return; diff --git a/cobalt/browser/splash_screen.h b/cobalt/browser/splash_screen.h index 3fc12021a412..7fe75305473b 100644 --- a/cobalt/browser/splash_screen.h +++ b/cobalt/browser/splash_screen.h @@ -57,21 +57,21 @@ class SplashScreen : public LifecycleObserver { } // LifecycleObserver implementation. - void Blur(SbTimeMonotonic timestamp) override { web_module_->Blur(0); } + void Blur(int64_t timestamp) override { web_module_->Blur(0); } void Conceal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) override { + int64_t timestamp) override { web_module_->Conceal(resource_provider, 0); } - void Freeze(SbTimeMonotonic timestamp) override { web_module_->Freeze(0); } + void Freeze(int64_t timestamp) override { web_module_->Freeze(0); } void Unfreeze(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) override { + int64_t timestamp) override { web_module_->Unfreeze(resource_provider, 0); } void Reveal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) override { + int64_t timestamp) override { web_module_->Reveal(resource_provider, 0); } - void Focus(SbTimeMonotonic timestamp) override { web_module_->Focus(0); } + void Focus(int64_t timestamp) override { web_module_->Focus(0); } void ReduceMemory() { web_module_->ReduceMemory(); } diff --git a/cobalt/browser/web_module.cc b/cobalt/browser/web_module.cc index c955f83591d4..10d47c95726c 100644 --- a/cobalt/browser/web_module.cc +++ b/cobalt/browser/web_module.cc @@ -246,20 +246,19 @@ class WebModule::Impl { // Sets the application state, asserts preconditions to transition to that // state, and dispatches any precipitate web events. - void SetApplicationState(base::ApplicationState state, - SbTimeMonotonic timestamp); + void SetApplicationState(base::ApplicationState state, int64_t timestamp); // See LifecycleObserver. These functions do not implement the interface, but // have the same basic function. - void Blur(SbTimeMonotonic timestamp); + void Blur(int64_t timestamp); void Conceal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp); - void Freeze(SbTimeMonotonic timestamp); + int64_t timestamp); + void Freeze(int64_t timestamp); void Unfreeze(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp); + int64_t timestamp); void Reveal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp); - void Focus(SbTimeMonotonic timestamp); + int64_t timestamp); + void Focus(int64_t timestamp); void ReduceMemory(); @@ -277,8 +276,8 @@ class WebModule::Impl { scoped_refptr* render_tree); void SetApplicationStartOrPreloadTimestamp(bool is_preload, - SbTimeMonotonic timestamp); - void SetDeepLinkTimestamp(SbTimeMonotonic timestamp); + int64_t timestamp); + void SetDeepLinkTimestamp(int64_t timestamp); void SetUnloadEventTimingInfo(base::TimeTicks start_time, base::TimeTicks end_time); @@ -1003,15 +1002,15 @@ void WebModule::Impl::DoSynchronousLayoutAndGetRenderTree( if (render_tree) *render_tree = tree; } -void WebModule::Impl::SetApplicationStartOrPreloadTimestamp( - bool is_preload, SbTimeMonotonic timestamp) { +void WebModule::Impl::SetApplicationStartOrPreloadTimestamp(bool is_preload, + int64_t timestamp) { DCHECK(window_); DCHECK(window_->performance()); window_->performance()->SetApplicationStartOrPreloadTimestamp(is_preload, timestamp); } -void WebModule::Impl::SetDeepLinkTimestamp(SbTimeMonotonic timestamp) { +void WebModule::Impl::SetDeepLinkTimestamp(int64_t timestamp) { DCHECK(window_); window_->performance()->SetDeepLinkTimestamp(timestamp); } @@ -1088,7 +1087,7 @@ void WebModule::Impl::SetMediaModule(media::MediaModule* media_module) { } void WebModule::Impl::SetApplicationState(base::ApplicationState state, - SbTimeMonotonic timestamp) { + int64_t timestamp) { window_->SetApplicationState(state, timestamp); } @@ -1118,13 +1117,13 @@ void WebModule::Impl::OnStopDispatchEvent( layout_manager_->IsRenderTreePending()); } -void WebModule::Impl::Blur(SbTimeMonotonic timestamp) { +void WebModule::Impl::Blur(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "WebModule::Impl::Blur()"); SetApplicationState(base::kApplicationStateBlurred, timestamp); } void WebModule::Impl::Conceal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) { + int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "WebModule::Impl::Conceal()"); SetResourceProvider(resource_provider); @@ -1161,7 +1160,7 @@ void WebModule::Impl::Conceal(render_tree::ResourceProvider* resource_provider, } } -void WebModule::Impl::Freeze(SbTimeMonotonic timestamp) { +void WebModule::Impl::Freeze(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "WebModule::Impl::Freeze()"); SetApplicationState(base::kApplicationStateFrozen, timestamp); @@ -1171,7 +1170,7 @@ void WebModule::Impl::Freeze(SbTimeMonotonic timestamp) { } void WebModule::Impl::Unfreeze(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) { + int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "WebModule::Impl::Unfreeze()"); synchronous_loader_interrupt_->Reset(); DCHECK(resource_provider); @@ -1181,7 +1180,7 @@ void WebModule::Impl::Unfreeze(render_tree::ResourceProvider* resource_provider, } void WebModule::Impl::Reveal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) { + int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "WebModule::Impl::Reveal()"); synchronous_loader_interrupt_->Reset(); DCHECK(resource_provider); @@ -1196,7 +1195,7 @@ void WebModule::Impl::Reveal(render_tree::ResourceProvider* resource_provider, SetApplicationState(base::kApplicationStateBlurred, timestamp); } -void WebModule::Impl::Focus(SbTimeMonotonic timestamp) { +void WebModule::Impl::Focus(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "WebModule::Impl::Focus()"); synchronous_loader_interrupt_->Reset(); SetApplicationState(base::kApplicationStateStarted, timestamp); @@ -1577,7 +1576,7 @@ void WebModule::SetRemoteTypefaceCacheCapacity(int64_t bytes) { impl_->SetRemoteTypefaceCacheCapacity(bytes); } -void WebModule::Blur(SbTimeMonotonic timestamp) { +void WebModule::Blur(int64_t timestamp) { synchronous_loader_interrupt_.Signal(); #if defined(ENABLE_DEBUGGER) // We normally need to block here so that the call doesn't return until the @@ -1602,7 +1601,7 @@ void WebModule::Blur(SbTimeMonotonic timestamp) { } void WebModule::Conceal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) { + int64_t timestamp) { synchronous_loader_interrupt_.Signal(); // We must block here so that the call doesn't return until the web // application has had a chance to process the whole event. @@ -1611,7 +1610,7 @@ void WebModule::Conceal(render_tree::ResourceProvider* resource_provider, impl_->Conceal(resource_provider, timestamp); } -void WebModule::Freeze(SbTimeMonotonic timestamp) { +void WebModule::Freeze(int64_t timestamp) { // We must block here so that the call doesn't return until the web // application has had a chance to process the whole event. POST_AND_BLOCK_TO_ENSURE_IMPL_ON_THREAD(Freeze, timestamp); @@ -1619,7 +1618,7 @@ void WebModule::Freeze(SbTimeMonotonic timestamp) { } void WebModule::Unfreeze(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) { + int64_t timestamp) { // We must block here so that the call doesn't return until the web // application has had a chance to process the whole event. POST_AND_BLOCK_TO_ENSURE_IMPL_ON_THREAD(Unfreeze, resource_provider, @@ -1628,14 +1627,14 @@ void WebModule::Unfreeze(render_tree::ResourceProvider* resource_provider, } void WebModule::Reveal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) { + int64_t timestamp) { // We must block here so that the call doesn't return until the web // application has had a chance to process the whole event. POST_AND_BLOCK_TO_ENSURE_IMPL_ON_THREAD(Reveal, resource_provider, timestamp); impl_->Reveal(resource_provider, timestamp); } -void WebModule::Focus(SbTimeMonotonic timestamp) { +void WebModule::Focus(int64_t timestamp) { // We must block here so that the call doesn't return until the web // application has had a chance to process the whole event. POST_AND_BLOCK_TO_ENSURE_IMPL_ON_THREAD(Focus, timestamp); @@ -1678,8 +1677,8 @@ void WebModule::DoSynchronousLayoutAndGetRenderTree( impl_->DoSynchronousLayoutAndGetRenderTree(render_tree); } -void WebModule::SetApplicationStartOrPreloadTimestamp( - bool is_preload, SbTimeMonotonic timestamp) { +void WebModule::SetApplicationStartOrPreloadTimestamp(bool is_preload, + int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "WebModule::SetApplicationStartOrPreloadTimestamp()"); POST_TO_ENSURE_IMPL_ON_THREAD(SetApplicationStartOrPreloadTimestamp, @@ -1687,7 +1686,7 @@ void WebModule::SetApplicationStartOrPreloadTimestamp( impl_->SetApplicationStartOrPreloadTimestamp(is_preload, timestamp); } -void WebModule::SetDeepLinkTimestamp(SbTimeMonotonic timestamp) { +void WebModule::SetDeepLinkTimestamp(int64_t timestamp) { TRACE_EVENT0("cobalt::browser", "WebModule::SetDeepLinkTimestamp()"); POST_AND_BLOCK_TO_ENSURE_IMPL_ON_THREAD(SetDeepLinkTimestamp, timestamp); impl_->SetDeepLinkTimestamp(timestamp); diff --git a/cobalt/browser/web_module.h b/cobalt/browser/web_module.h index 28fa71409d5d..c781d298d732 100644 --- a/cobalt/browser/web_module.h +++ b/cobalt/browser/web_module.h @@ -364,15 +364,15 @@ class WebModule : public base::MessageLoop::DestructionObserver, } // LifecycleObserver implementation - void Blur(SbTimeMonotonic timestamp) override; + void Blur(int64_t timestamp) override; void Conceal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) override; - void Freeze(SbTimeMonotonic timestamp) override; + int64_t timestamp) override; + void Freeze(int64_t timestamp) override; void Unfreeze(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) override; + int64_t timestamp) override; void Reveal(render_tree::ResourceProvider* resource_provider, - SbTimeMonotonic timestamp) override; - void Focus(SbTimeMonotonic timestamp) override; + int64_t timestamp) override; + void Focus(int64_t timestamp) override; // Attempt to reduce overall memory consumption. Called in response to a // system indication that memory usage is nearing a critical level. @@ -394,8 +394,8 @@ class WebModule : public base::MessageLoop::DestructionObserver, // Pass the application preload or start timestamps from Starboard. void SetApplicationStartOrPreloadTimestamp(bool is_preload, - SbTimeMonotonic timestamp); - void SetDeepLinkTimestamp(SbTimeMonotonic timestamp); + int64_t timestamp); + void SetDeepLinkTimestamp(int64_t timestamp); // From base::MessageLoop::DestructionObserver. void WillDestroyCurrentMessageLoop() override; diff --git a/cobalt/demos/simple_sandbox/simple_sandbox.cc b/cobalt/demos/simple_sandbox/simple_sandbox.cc index 5c2d32c73059..5d6d965641b7 100644 --- a/cobalt/demos/simple_sandbox/simple_sandbox.cc +++ b/cobalt/demos/simple_sandbox/simple_sandbox.cc @@ -30,7 +30,7 @@ class SimpleSandbox { static void StartApplication(int argc, char** argv, const char* link, const base::Closure& quit_closure, - SbTimeMonotonic timestamp); + int64_t timestamp); static void StopApplication(); @@ -44,7 +44,7 @@ class SimpleSandbox { // static void SimpleSandbox::StartApplication(int argc, char** argv, const char* link, const base::Closure& quit_closure, - SbTimeMonotonic timestamp) { + int64_t timestamp) { LOG(INFO) << "SimpleSandbox::StartApplication"; SimpleSandbox::GetInstance()->thread()->Start(); diff --git a/cobalt/dom/document.cc b/cobalt/dom/document.cc index 6fb63cdc46cf..cf0b3fa1ecd5 100644 --- a/cobalt/dom/document.cc +++ b/cobalt/dom/document.cc @@ -64,6 +64,7 @@ #include "cobalt/web/custom_event.h" #include "cobalt/web/dom_exception.h" #include "cobalt/web/message_event.h" +#include "starboard/common/time.h" using cobalt::cssom::ViewportSize; @@ -904,12 +905,12 @@ void Document::UpdateUiNavigation() { } bool Document::TrySetUiNavFocusElement(const void* focus_element, - SbTimeMonotonic time) { - if (ui_nav_focus_element_update_time_ > time) { + int64_t monotonic_time) { + if (ui_nav_focus_element_update_time_ > monotonic_time) { // A later focus update was already issued. return false; } - ui_nav_focus_element_update_time_ = time; + ui_nav_focus_element_update_time_ = monotonic_time; ui_nav_focus_element_ = focus_element; return true; } diff --git a/cobalt/dom/document.h b/cobalt/dom/document.h index 0a7a4d9bab1c..2b4cb56919a0 100644 --- a/cobalt/dom/document.h +++ b/cobalt/dom/document.h @@ -56,7 +56,6 @@ #include "cobalt/script/exception_state.h" #include "cobalt/script/wrappable.h" #include "cobalt/web/event.h" -#include "starboard/time.h" #include "url/gurl.h" namespace cobalt { @@ -333,7 +332,8 @@ class Document : public Node, // Track UI navigation system's focus element. const void* ui_nav_focus_element() const { return ui_nav_focus_element_; } - bool TrySetUiNavFocusElement(const void* focus_element, SbTimeMonotonic time); + bool TrySetUiNavFocusElement(const void* focus_element, + int64_t monotonic_time); // Track HTML elements that are UI navigation items. This facilitates updating // their layout information as needed. @@ -635,9 +635,9 @@ class Document : public Node, // not meant to be dereferenced. const void* ui_nav_focus_element_ = nullptr; - // Since UI navigation involves multiple threads, use a timestamp to help - // filter out obsolete focus changes. - SbTimeMonotonic ui_nav_focus_element_update_time_ = 0; + // Since UI navigation involves multiple threads, use a monotonic timestamp to + // help filter out obsolete focus changes. + int64_t ui_nav_focus_element_update_time_ = 0; // Track all HTMLElements in this document which are UI navigation items. // These should be raw pointers to avoid affecting the elements' ref counts. diff --git a/cobalt/dom/html_element.cc b/cobalt/dom/html_element.cc index 9ddbdcb1a8a2..8fb491d66b0e 100644 --- a/cobalt/dom/html_element.cc +++ b/cobalt/dom/html_element.cc @@ -65,6 +65,7 @@ #include "cobalt/loader/resource_cache.h" #include "cobalt/math/clamp.h" #include "cobalt/web/csp_delegate.h" +#include "starboard/common/time.h" #include "third_party/icu/source/common/unicode/uchar.h" #include "third_party/icu/source/common/unicode/utf8.h" @@ -92,9 +93,9 @@ const char* kPerformanceResourceTimingInitiatorType = "img"; void UiNavCallbackHelper( scoped_refptr task_runner, - base::Callback callback) { - task_runner->PostTask(FROM_HERE, - base::Bind(callback, SbTimeGetMonotonicNow())); + base::Callback callback) { + task_runner->PostTask( + FROM_HERE, base::Bind(callback, starboard::CurrentMonotonicTime())); } struct NonTrivialStaticFields { @@ -1229,25 +1230,25 @@ void HTMLElement::InvalidateLayoutBoxes() { directionality_ = base::nullopt; } -void HTMLElement::OnUiNavBlur(SbTimeMonotonic time) { +void HTMLElement::OnUiNavBlur(int64_t monotonic_time) { if (node_document() && node_document()->ui_nav_focus_element() == this) { - if (node_document()->TrySetUiNavFocusElement(nullptr, time)) { + if (node_document()->TrySetUiNavFocusElement(nullptr, monotonic_time)) { Blur(); } } } -void HTMLElement::OnUiNavFocus(SbTimeMonotonic time) { +void HTMLElement::OnUiNavFocus(int64_t monotonic_time) { // Suppress the focus event if this is already focused -- i.e. the HTMLElement // initiated the focus change that resulted in this call to OnUiNavFocus. if (node_document() && node_document()->ui_nav_focus_element() != this) { - if (node_document()->TrySetUiNavFocusElement(this, time)) { + if (node_document()->TrySetUiNavFocusElement(this, monotonic_time)) { Focus(); } } } -void HTMLElement::OnUiNavScroll(SbTimeMonotonic /* time */) { +void HTMLElement::OnUiNavScroll(int64_t /* monotonic_time */) { Document* document = node_document(); if (document->hidden()) { return; @@ -1498,8 +1499,8 @@ void HTMLElement::UpdateUiNavigationFocus() { // suppressing the Blur call for the previously focused HTMLElement and the // Focus call for this HTMLElement as a result of OnUiNavBlur / OnUiNavFocus // callbacks that result from initiating the UI navigation focus change. - if (node_document()->TrySetUiNavFocusElement(html_element, - SbTimeGetMonotonicNow())) { + if (node_document()->TrySetUiNavFocusElement( + html_element, starboard::CurrentMonotonicTime())) { html_element->ui_nav_item_->Focus(); } break; @@ -2296,8 +2297,8 @@ void HTMLElement::ReleaseUiNavigationItem() { node_document()->RemoveUiNavigationElement(this); node_document()->set_ui_nav_needs_layout(true); if (node_document()->ui_nav_focus_element() == this) { - if (node_document()->TrySetUiNavFocusElement(nullptr, - SbTimeGetMonotonicNow())) { + if (node_document()->TrySetUiNavFocusElement( + nullptr, starboard::CurrentMonotonicTime())) { ui_nav_item_->UnfocusAll(); } } diff --git a/cobalt/dom/html_element.h b/cobalt/dom/html_element.h index e2a6949a51da..199dbd6672a0 100644 --- a/cobalt/dom/html_element.h +++ b/cobalt/dom/html_element.h @@ -45,7 +45,6 @@ #include "cobalt/dom/pseudo_element.h" #include "cobalt/loader/image/image_cache.h" #include "cobalt/ui_navigation/nav_item.h" -#include "starboard/time.h" namespace cobalt { namespace dom { @@ -459,9 +458,9 @@ class HTMLElement : public Element, public cssom::MutationObserver { void InvalidateLayoutBoxes(); // Handle UI navigation events. - void OnUiNavBlur(SbTimeMonotonic time); - void OnUiNavFocus(SbTimeMonotonic time); - void OnUiNavScroll(SbTimeMonotonic time); + void OnUiNavBlur(int64_t monotonic_time); + void OnUiNavFocus(int64_t monotonic_time); + void OnUiNavScroll(int64_t monotonic_time); bool locked_for_focus_; diff --git a/cobalt/dom/html_link_element.cc b/cobalt/dom/html_link_element.cc index 011000b2a8b8..a37ccb799e2f 100644 --- a/cobalt/dom/html_link_element.cc +++ b/cobalt/dom/html_link_element.cc @@ -31,6 +31,7 @@ #include "cobalt/dom/html_element_context.h" #include "cobalt/dom/window.h" #include "cobalt/web/csp_delegate.h" +#include "starboard/common/time.h" #include "url/gurl.h" namespace cobalt { @@ -317,11 +318,11 @@ void HTMLLinkElement::OnSplashscreenLoaded(Document* document, void HTMLLinkElement::OnStylesheetLoaded(Document* document, const std::string& content) { - auto before_parse_micros = SbTimeGetMonotonicNow(); + auto before_parse_micros = starboard::CurrentMonotonicTime(); scoped_refptr css_style_sheet = document->html_element_context()->css_parser()->ParseStyleSheet( content, base::SourceLocation(href(), 1, 1)); - auto after_parse_micros = SbTimeGetMonotonicNow(); + auto after_parse_micros = starboard::CurrentMonotonicTime(); auto css_kb = content.length() / 1000; // Only measure non-trivial CSS sizes and ignore non-HTTP schemes (e.g., // file://), which are primarily used for debug purposes. diff --git a/cobalt/dom/html_media_element.cc b/cobalt/dom/html_media_element.cc index da10b2e91781..dd5cadacff7c 100644 --- a/cobalt/dom/html_media_element.cc +++ b/cobalt/dom/html_media_element.cc @@ -384,7 +384,7 @@ float HTMLMediaElement::duration() const { } base::Time HTMLMediaElement::GetStartDate() const { - MLOG() << start_date_.ToSbTime(); + MLOG() << start_date_.ToDeltaSinceWindowsEpoch().InMicroseconds(); return start_date_; } diff --git a/cobalt/dom/html_style_element.cc b/cobalt/dom/html_style_element.cc index 323b5d7c9a45..5f9c215384c5 100644 --- a/cobalt/dom/html_style_element.cc +++ b/cobalt/dom/html_style_element.cc @@ -22,6 +22,7 @@ #include "cobalt/dom/document.h" #include "cobalt/dom/html_element_context.h" #include "cobalt/web/csp_delegate.h" +#include "starboard/common/time.h" namespace cobalt { namespace dom { @@ -91,11 +92,11 @@ void HTMLStyleElement::Process() { const std::string& text = content.value_or(base::EmptyString()); if (bypass_csp || csp_delegate->AllowInline(web::CspDelegate::kStyle, inline_style_location_, text)) { - auto before_parse_micros = SbTimeGetMonotonicNow(); + auto before_parse_micros = starboard::CurrentMonotonicTime(); scoped_refptr css_style_sheet = document->html_element_context()->css_parser()->ParseStyleSheet( text, inline_style_location_); - auto after_parse_micros = SbTimeGetMonotonicNow(); + auto after_parse_micros = starboard::CurrentMonotonicTime(); auto css_kb = text.length() / 1000; // Only measure non-trivial css sizes and inlined HTML style elements. if (css_kb > 0 && diff --git a/cobalt/dom/performance.cc b/cobalt/dom/performance.cc index 68b89900ca70..ed8ba6c35fe7 100644 --- a/cobalt/dom/performance.cc +++ b/cobalt/dom/performance.cc @@ -617,17 +617,17 @@ void Performance::CreatePerformanceResourceTiming( } void Performance::SetApplicationState(base::ApplicationState state, - SbTimeMonotonic timestamp) { + int64_t timestamp) { lifecycle_timing_->SetApplicationState(state, timestamp); } -void Performance::SetApplicationStartOrPreloadTimestamp( - bool is_preload, SbTimeMonotonic timestamp) { +void Performance::SetApplicationStartOrPreloadTimestamp(bool is_preload, + int64_t timestamp) { lifecycle_timing_->SetApplicationStartOrPreloadTimestamp(is_preload, timestamp); } -void Performance::SetDeepLinkTimestamp(SbTimeMonotonic timestamp) { +void Performance::SetDeepLinkTimestamp(int64_t timestamp) { lifecycle_timing_->SetDeepLinkTimestamp(timestamp); } diff --git a/cobalt/dom/performance.h b/cobalt/dom/performance.h index eb720c8d9c9d..fff56fb0b0db 100644 --- a/cobalt/dom/performance.h +++ b/cobalt/dom/performance.h @@ -132,13 +132,12 @@ class Performance : public web::EventTarget { const scoped_refptr& observer, const PerformanceObserverInit& options); - void SetApplicationState(base::ApplicationState state, - SbTimeMonotonic timestamp); + void SetApplicationState(base::ApplicationState state, int64_t timestamp); void SetApplicationStartOrPreloadTimestamp(bool is_preload, - SbTimeMonotonic timestamp); + int64_t timestamp); - void SetDeepLinkTimestamp(SbTimeMonotonic timestamp); + void SetDeepLinkTimestamp(int64_t timestamp); void TraceMembers(script::Tracer* tracer) override; DEFINE_WRAPPABLE_TYPE(Performance); diff --git a/cobalt/dom/performance_lifecycle_timing.cc b/cobalt/dom/performance_lifecycle_timing.cc index 5387e1607c6e..779e69af1535 100644 --- a/cobalt/dom/performance_lifecycle_timing.cc +++ b/cobalt/dom/performance_lifecycle_timing.cc @@ -16,6 +16,7 @@ #include "cobalt/dom/performance_lifecycle_timing.h" #include "cobalt/dom/performance.h" +#include "starboard/common/time.h" namespace cobalt { namespace dom { @@ -40,10 +41,14 @@ std::string TranslateApplicationStateToString(base::ApplicationState state) { return "INVALID_APPLICATION_STATE"; } -DOMHighResTimeStamp ConvertSbTimeMonotonicToDOMHiResTimeStamp( - const DOMHighResTimeStamp time_origin, SbTimeMonotonic monotonic_time) { - SbTimeMonotonic time_delta = SbTimeGetNow() - SbTimeGetMonotonicNow(); - base::Time base_time = base::Time::FromSbTime(time_delta + monotonic_time); +DOMHighResTimeStamp ConvertMonotonicTimestampToDOMHiResTimeStamp( + const DOMHighResTimeStamp time_origin, int64_t monotonic_time) { + // Current delta from Windows epoch. + int64_t time_delta = + starboard::PosixTimeToWindowsTime(starboard::CurrentPosixTime()) - + starboard::CurrentMonotonicTime(); + base::Time base_time = base::Time::FromDeltaSinceWindowsEpoch( + base::TimeDelta::FromMicroseconds(time_delta + monotonic_time)); return ClampTimeStampMinimumResolution( base_time.ToJsTime() - time_origin, Performance::kPerformanceTimerMinResolutionInMicroseconds); @@ -101,7 +106,7 @@ std::string PerformanceLifecycleTiming::last_state() const { } void PerformanceLifecycleTiming::SetApplicationState( - base::ApplicationState state, SbTimeMonotonic timestamp) { + base::ApplicationState state, int64_t timestamp) { switch (state) { case base::kApplicationStateBlurred: if (GetCurrentState() == base::kApplicationStateStarted || @@ -155,7 +160,7 @@ void PerformanceLifecycleTiming::SetApplicationState( } void PerformanceLifecycleTiming::SetApplicationStartOrPreloadTimestamp( - bool is_preload, SbTimeMonotonic timestamp) { + bool is_preload, int64_t timestamp) { if (is_preload) { lifecycle_timing_info_.app_preload = timestamp; SetLifecycleTimingInfoState(base::kApplicationStateConcealed); @@ -165,8 +170,7 @@ void PerformanceLifecycleTiming::SetApplicationStartOrPreloadTimestamp( } } -void PerformanceLifecycleTiming::SetDeepLinkTimestamp( - SbTimeMonotonic timestamp) { +void PerformanceLifecycleTiming::SetDeepLinkTimestamp(int64_t timestamp) { lifecycle_timing_info_.app_deeplink = timestamp; } @@ -181,9 +185,10 @@ void PerformanceLifecycleTiming::SetLifecycleTimingInfoState( } DOMHighResTimeStamp PerformanceLifecycleTiming::ReportDOMHighResTimeStamp( - SbTimeMonotonic timestamp) const { + int64_t timestamp) const { if (timestamp != 0) { - return ConvertSbTimeMonotonicToDOMHiResTimeStamp(time_origin_, timestamp); + return ConvertMonotonicTimestampToDOMHiResTimeStamp(time_origin_, + timestamp); } return PerformanceEntry::start_time(); } diff --git a/cobalt/dom/performance_lifecycle_timing.h b/cobalt/dom/performance_lifecycle_timing.h index e9ab9e3c943e..8a548ec7ecaf 100644 --- a/cobalt/dom/performance_lifecycle_timing.h +++ b/cobalt/dom/performance_lifecycle_timing.h @@ -51,29 +51,27 @@ class PerformanceLifecycleTiming : public PerformanceEntry { return PerformanceEntry::kLifecycle; } - void SetApplicationState(base::ApplicationState state, - SbTimeMonotonic timestamp); + void SetApplicationState(base::ApplicationState state, int64_t timestamp); void SetApplicationStartOrPreloadTimestamp(bool is_preload, - SbTimeMonotonic timestamp); - void SetDeepLinkTimestamp(SbTimeMonotonic timestamp); + int64_t timestamp); + void SetDeepLinkTimestamp(int64_t timestamp); DEFINE_WRAPPABLE_TYPE(PerformanceLifecycleTiming); private: void SetLifecycleTimingInfoState(base::ApplicationState state); - DOMHighResTimeStamp ReportDOMHighResTimeStamp( - SbTimeMonotonic timestamp) const; + DOMHighResTimeStamp ReportDOMHighResTimeStamp(int64_t timestamp) const; base::ApplicationState GetCurrentState() const; struct LifecycleTimingInfo { - SbTimeMonotonic app_preload = 0; - SbTimeMonotonic app_start = 0; - SbTimeMonotonic app_blur = 0; - SbTimeMonotonic app_conceal = 0; - SbTimeMonotonic app_focus = 0; - SbTimeMonotonic app_reveal = 0; - SbTimeMonotonic app_freeze = 0; - SbTimeMonotonic app_unfreeze = 0; - SbTimeMonotonic app_deeplink = 0; + int64_t app_preload = 0; + int64_t app_start = 0; + int64_t app_blur = 0; + int64_t app_conceal = 0; + int64_t app_focus = 0; + int64_t app_reveal = 0; + int64_t app_freeze = 0; + int64_t app_unfreeze = 0; + int64_t app_deeplink = 0; base::ApplicationState current_state = base::kApplicationStateStopped; base::ApplicationState last_state = base::kApplicationStateStopped; diff --git a/cobalt/dom/serialized_algorithm_runner.h b/cobalt/dom/serialized_algorithm_runner.h index 0d8122ac385e..f28e8ecd876c 100644 --- a/cobalt/dom/serialized_algorithm_runner.h +++ b/cobalt/dom/serialized_algorithm_runner.h @@ -28,7 +28,7 @@ #include "base/threading/thread_task_runner_handle.h" #include "base/trace_event/trace_event.h" #include "starboard/common/mutex.h" -#include "starboard/time.h" +#include "starboard/common/time.h" namespace cobalt { namespace dom { @@ -90,20 +90,21 @@ class SerializedAlgorithmRunner { // Crash if we are trying to re-acquire again on the same thread. CHECK_NE(acquired_thread_id_, SbThreadGetId()); - SbTime start = SbTimeGetMonotonicNow(); - SbTime wait_interval = kSbTimeMillisecond; - constexpr SbTime kMaxWaitInterval = kSbTimeMillisecond * 16; + int64_t start_usec = starboard::CurrentMonotonicTime(); + int64_t wait_interval_usec = 1000; + constexpr int64_t kMaxWaitIntervalUsec = 1000 * 16; // 16ms. for (;;) { if (mutex_.AcquireTry()) { break; } - SbThreadSleep(wait_interval); + SbThreadSleep(wait_interval_usec); // Double the wait interval upon every failure, but cap it at - // kMaxWaitInterval. - wait_interval = std::min(wait_interval * 2, kMaxWaitInterval); - // Crash if we've been waiting for too long. - CHECK_LT(SbTimeGetMonotonicNow() - start, kSbTimeSecond); + // kMaxWaitIntervalUsec. + wait_interval_usec = + std::min(wait_interval_usec * 2, kMaxWaitIntervalUsec); + // Crash if we've been waiting for too long (1 second). + CHECK_LT(starboard::CurrentMonotonicTime() - start_usec, 1000000); } acquired_thread_id_ = SbThreadGetId(); } diff --git a/cobalt/dom/source_buffer_metrics.cc b/cobalt/dom/source_buffer_metrics.cc index 82aed8df600e..8ff030bdec88 100644 --- a/cobalt/dom/source_buffer_metrics.cc +++ b/cobalt/dom/source_buffer_metrics.cc @@ -17,8 +17,10 @@ #include #include "base/logging.h" +#include "base/time/time.h" #include "cobalt/base/statistics.h" #include "starboard/common/string.h" +#include "starboard/common/time.h" #include "starboard/once.h" #include "starboard/types.h" @@ -29,8 +31,10 @@ namespace dom { namespace { -int GetBandwidth(std::size_t size, SbTimeMonotonic duration) { - return duration == 0 ? 0 : size * kSbTimeSecond / duration; +int GetBandwidth(std::size_t size, int64_t duration_us) { + return duration_us == 0 + ? 0 + : size * base::Time::kMicrosecondsPerSecond / duration_us; } int64_t GetBandwidthForStatistics(int64_t size, int64_t duration) { @@ -38,7 +42,7 @@ int64_t GetBandwidthForStatistics(int64_t size, int64_t duration) { } using BandwidthStatistics = - base::Statistics; + base::Statistics; class StatisticsWrapper { public: @@ -66,7 +70,7 @@ void SourceBufferMetrics::StartTracking() { DCHECK(!is_tracking_); is_tracking_ = true; - wall_start_time_ = SbTimeGetMonotonicNow(); + wall_start_time_ = starboard::CurrentMonotonicTime(); thread_start_time_ = SbTimeIsTimeThreadNowSupported() ? SbTimeGetMonotonicThreadNow() : -1; } @@ -79,8 +83,8 @@ void SourceBufferMetrics::EndTracking(std::size_t size_appended) { DCHECK(is_tracking_); is_tracking_ = false; - SbTimeMonotonic wall_duration = SbTimeGetMonotonicNow() - wall_start_time_; - SbTimeMonotonic thread_duration = + int64_t wall_duration = starboard::CurrentMonotonicTime() - wall_start_time_; + int64_t thread_duration = SbTimeIsTimeThreadNowSupported() ? SbTimeGetMonotonicThreadNow() - thread_start_time_ : 0; diff --git a/cobalt/dom/source_buffer_metrics.h b/cobalt/dom/source_buffer_metrics.h index 766ebace20ed..bfafceffc71f 100644 --- a/cobalt/dom/source_buffer_metrics.h +++ b/cobalt/dom/source_buffer_metrics.h @@ -15,7 +15,7 @@ #ifndef COBALT_DOM_SOURCE_BUFFER_METRICS_H_ #define COBALT_DOM_SOURCE_BUFFER_METRICS_H_ -#include "starboard/time.h" +#include "starboard/types.h" namespace cobalt { namespace dom { @@ -50,15 +50,15 @@ class SourceBufferMetrics { SourceBufferMetrics(const SourceBufferMetrics&) = delete; SourceBufferMetrics& operator=(const SourceBufferMetrics&) = delete; - SbTimeMonotonic wall_start_time_ = 0; - SbTimeMonotonic thread_start_time_ = 0; + int64_t wall_start_time_ = 0; + int64_t thread_start_time_ = 0; const bool is_primary_video_; bool is_tracking_ = false; size_t total_size_ = 0; - SbTime total_thread_time_ = 0; - SbTime total_wall_time_ = 0; + int64_t total_thread_time_ = 0; + int64_t total_wall_time_ = 0; int max_thread_bandwidth_ = 0; int min_thread_bandwidth_ = INT_MAX; int max_wall_bandwidth_ = 0; diff --git a/cobalt/dom/window.cc b/cobalt/dom/window.cc index 8ff1bd9e3fbb..70a8c0ea3897 100644 --- a/cobalt/dom/window.cc +++ b/cobalt/dom/window.cc @@ -479,7 +479,7 @@ void Window::InjectEvent(const scoped_refptr& event) { } void Window::SetApplicationState(base::ApplicationState state, - SbTimeMonotonic timestamp) { + int64_t timestamp) { html_element_context()->application_lifecycle_state()->SetApplicationState( state); if (timestamp == 0) return; diff --git a/cobalt/dom/window.h b/cobalt/dom/window.h index 5bbf76b89d5d..a8008403243f 100644 --- a/cobalt/dom/window.h +++ b/cobalt/dom/window.h @@ -337,8 +337,7 @@ class Window : public web::WindowOrWorkerGlobalScope, // Sets the current application state, forwarding on to the // ApplicationLifecycleState associated with it and its document, causing // precipitate events to be dispatched. - void SetApplicationState(base::ApplicationState state, - SbTimeMonotonic timestamp); + void SetApplicationState(base::ApplicationState state, int64_t timestamp); // ApplicationLifecycleState::Observer implementation. void OnWindowFocusChanged(bool has_focus) override; diff --git a/cobalt/input/input_device_manager_desktop.cc b/cobalt/input/input_device_manager_desktop.cc index f86c46f437c9..573902d0cda6 100644 --- a/cobalt/input/input_device_manager_desktop.cc +++ b/cobalt/input/input_device_manager_desktop.cc @@ -42,7 +42,7 @@ namespace { void UpdateEventInit(const system_window::InputEvent* input_event, web::EventInit* event) { if (input_event->timestamp() != 0) { - // Convert SbTimeMonotonic to DOMTimeStamp. + // Convert monotonic int64_t to DOMTimeStamp. event->set_time_stamp( cobalt::web::Event::GetEventTime(input_event->timestamp())); } diff --git a/cobalt/media/base/cval_stats.cc b/cobalt/media/base/cval_stats.cc index 9ee4acf279be..8a3ad835f1a6 100644 --- a/cobalt/media/base/cval_stats.cc +++ b/cobalt/media/base/cval_stats.cc @@ -16,6 +16,8 @@ #include +#include "starboard/common/time.h" + namespace cobalt { namespace media { @@ -32,21 +34,21 @@ CValContainer::CValContainer(std::string name, minimum_{"Media." + name + ".Minimum", 0, "Minimum sample in microseconds."} {} -void CValContainer::UpdateCVal(SbTime event_timing) { - latest_ = event_timing; +void CValContainer::UpdateCVal(int64_t event_time_usec) { + latest_ = event_time_usec; accumulated_sample_count_++; if (!first_sample_added_) { - minimum_ = event_timing; - maximum_ = event_timing; + minimum_ = event_time_usec; + maximum_ = event_time_usec; first_sample_added_ = true; } - samples_[sample_write_index_] = event_timing; + samples_[sample_write_index_] = event_time_usec; sample_write_index_ = (sample_write_index_ + 1) % kMaxSamples; if (accumulated_sample_count_ % max_samples_before_calculation_ == 0) { - std::vector copy; + std::vector copy; int copy_size = std::min(accumulated_sample_count_, kMaxSamples); copy.reserve(copy_size); copy.assign(samples_, samples_ + copy_size); @@ -88,7 +90,7 @@ void CValStats::StartTimer(MediaTiming event_type, if (!enabled_) return; running_timers_[std::make_pair(event_type, pipeline_identifier)] = - SbTimeGetMonotonicNow(); + starboard::CurrentMonotonicTime(); } void CValStats::StopTimer(MediaTiming event_type, @@ -98,7 +100,7 @@ void CValStats::StopTimer(MediaTiming event_type, auto key = std::make_pair(event_type, pipeline_identifier); DCHECK(running_timers_.find(key) != running_timers_.end()); - SbTime time_taken = SbTimeGetMonotonicNow() - running_timers_[key]; + int64_t time_taken = starboard::CurrentMonotonicTime() - running_timers_[key]; auto cval_container = cval_containers_.find(event_type); if (cval_container != cval_containers_.end()) { cval_container->second.UpdateCVal(time_taken); diff --git a/cobalt/media/base/cval_stats.h b/cobalt/media/base/cval_stats.h index 2ae30993f6b0..e37c3099db90 100644 --- a/cobalt/media/base/cval_stats.h +++ b/cobalt/media/base/cval_stats.h @@ -47,7 +47,7 @@ class CValContainer { void StartTimer(); void StopTimer(); - void UpdateCVal(SbTime event_time); + void UpdateCVal(int64_t event_time_usec); // for testing only size_t GetSampleIndex() { return sample_write_index_; } @@ -60,19 +60,19 @@ class CValContainer { std::string cval_name_; private: - base::CVal latest_; - base::CVal average_; - base::CVal maximum_; - base::CVal median_; - base::CVal minimum_; + base::CVal latest_; + base::CVal average_; + base::CVal maximum_; + base::CVal median_; + base::CVal minimum_; - SbTime samples_[kMaxSamples]; + int64_t samples_[kMaxSamples]; size_t sample_write_index_{0}; size_t accumulated_sample_count_{0}; bool first_sample_added_{false}; - SbTime latest_time_start_{0}; - SbTime latest_time_stop_{0}; + int64_t latest_time_start_{0}; + int64_t latest_time_stop_{0}; }; class CValStats { @@ -90,7 +90,7 @@ class CValStats { private: std::map cval_containers_; - std::map, SbTime> running_timers_; + std::map, int64_t> running_timers_; bool enabled_{false}; }; diff --git a/cobalt/media/base/cval_stats_test.cc b/cobalt/media/base/cval_stats_test.cc index ceba32024d9a..a6fc19131a7d 100644 --- a/cobalt/media/base/cval_stats_test.cc +++ b/cobalt/media/base/cval_stats_test.cc @@ -29,7 +29,7 @@ const char kCValnameMinimum[] = "Media.SbPlayerCreateTime.Minimum"; const char kPipelineIdentifier[] = "test_pipeline"; -constexpr SbTime kSleepTime = 50; // 50 microseconds +constexpr int64_t kSleepTime = 50; // 50 microseconds namespace cobalt { namespace media { diff --git a/cobalt/media/base/format_support_query_metrics.cc b/cobalt/media/base/format_support_query_metrics.cc index 45fb348dfe3c..d769123d14db 100644 --- a/cobalt/media/base/format_support_query_metrics.cc +++ b/cobalt/media/base/format_support_query_metrics.cc @@ -19,6 +19,7 @@ #include "base/logging.h" #include "base/strings/string_util.h" #include "starboard/common/string.h" +#include "starboard/common/time.h" namespace cobalt { namespace media { @@ -31,7 +32,7 @@ std::string CreateQueryDescription(const char* query_name, const std::string& mime_type, const std::string& key_system, SbMediaSupportType support_type, - SbTimeMonotonic query_duration) { + int64_t query_duration) { auto get_support_type_str = [](SbMediaSupportType support_type) { switch (support_type) { case kSbMediaSupportTypeNotSupported: @@ -55,22 +56,22 @@ std::string CreateQueryDescription(const char* query_name, } // namespace // static -SbTimeMonotonic FormatSupportQueryMetrics::cached_query_durations_ +int64_t FormatSupportQueryMetrics::cached_query_durations_ [kMaxCachedQueryDurations] = {}; char FormatSupportQueryMetrics::max_query_description_ [kMaxQueryDescriptionLength] = {}; -SbTimeMonotonic FormatSupportQueryMetrics::max_query_duration_ = 0; -SbTimeMonotonic FormatSupportQueryMetrics::total_query_duration_ = 0; +int64_t FormatSupportQueryMetrics::max_query_duration_ = 0; +int64_t FormatSupportQueryMetrics::total_query_duration_ = 0; int FormatSupportQueryMetrics::total_num_queries_ = 0; FormatSupportQueryMetrics::FormatSupportQueryMetrics() { - start_time_ = SbTimeGetMonotonicNow(); + start_time_ = starboard::CurrentMonotonicTime(); } void FormatSupportQueryMetrics::RecordAndLogQuery( const char* query_name, const std::string& mime_type, const std::string& key_system, SbMediaSupportType support_type) { - SbTimeMonotonic query_duration = SbTimeGetMonotonicNow() - start_time_; + int64_t query_duration = starboard::CurrentMonotonicTime() - start_time_; total_query_duration_ += query_duration; std::string query_description = CreateQueryDescription( diff --git a/cobalt/media/base/format_support_query_metrics.h b/cobalt/media/base/format_support_query_metrics.h index 7343e1454620..8cec87e8e92d 100644 --- a/cobalt/media/base/format_support_query_metrics.h +++ b/cobalt/media/base/format_support_query_metrics.h @@ -18,7 +18,6 @@ #include #include "starboard/media.h" -#include "starboard/time.h" namespace cobalt { namespace media { @@ -52,13 +51,13 @@ class FormatSupportQueryMetrics { static constexpr int kMaxCachedQueryDurations = 150; static constexpr int kMaxQueryDescriptionLength = 350; - static SbTimeMonotonic cached_query_durations_[kMaxCachedQueryDurations]; + static int64_t cached_query_durations_[kMaxCachedQueryDurations]; static char max_query_description_[kMaxQueryDescriptionLength]; - static SbTimeMonotonic max_query_duration_; - static SbTimeMonotonic total_query_duration_; + static int64_t max_query_duration_; + static int64_t total_query_duration_; static int total_num_queries_; - SbTimeMonotonic start_time_ = 0; + int64_t start_time_ = 0; }; #endif // defined(COBALT_BUILD_TYPE_GOLD) diff --git a/cobalt/media/base/sbplayer_bridge.cc b/cobalt/media/base/sbplayer_bridge.cc index e6beb248c27d..a09628c30f59 100644 --- a/cobalt/media/base/sbplayer_bridge.cc +++ b/cobalt/media/base/sbplayer_bridge.cc @@ -29,6 +29,7 @@ #include "starboard/common/media.h" #include "starboard/common/player.h" #include "starboard/common/string.h" +#include "starboard/common/time.h" #include "starboard/configuration.h" #include "starboard/memory.h" #include "starboard/once.h" @@ -45,7 +46,7 @@ using starboard::GetPlayerOutputModeName; class StatisticsWrapper { public: static StatisticsWrapper* GetInstance(); - base::Statistics startup_latency{ + base::Statistics startup_latency{ "Media.PlaybackStartupLatency"}; }; @@ -105,8 +106,10 @@ void SetDiscardPadding( CobaltExtensionEnhancedAudioMediaAudioSampleInfo* sample_info) { DCHECK(sample_info); - sample_info->discarded_duration_from_front = discard_padding.first.ToSbTime(); - sample_info->discarded_duration_from_back = discard_padding.second.ToSbTime(); + sample_info->discarded_duration_from_front = + discard_padding.first.InMicroseconds(); + sample_info->discarded_duration_from_back = + discard_padding.second.InMicroseconds(); } void SetDiscardPadding( @@ -115,8 +118,10 @@ void SetDiscardPadding( DCHECK(sample_info); #if SB_API_VERSION >= 15 - sample_info->discarded_duration_from_front = discard_padding.first.ToSbTime(); - sample_info->discarded_duration_from_back = discard_padding.second.ToSbTime(); + sample_info->discarded_duration_from_front = + discard_padding.first.InMicroseconds(); + sample_info->discarded_duration_from_back = + discard_padding.second.InMicroseconds(); #endif // SB_API_VERSION >= 15} } @@ -693,7 +698,7 @@ void SbPlayerBridge::CreateUrlPlayer(const std::string& url) { FormatSupportQueryMetrics::PrintAndResetMetrics(); } - player_creation_time_ = SbTimeGetMonotonicNow(); + player_creation_time_ = starboard::CurrentMonotonicTime(); cval_stats_->StartTimer(MediaTiming::SbPlayerCreate, pipeline_identifier_); player_ = sbplayer_interface_->CreateUrlPlayer( @@ -743,7 +748,7 @@ void SbPlayerBridge::CreatePlayer() { FormatSupportQueryMetrics::PrintAndResetMetrics(); } - player_creation_time_ = SbTimeGetMonotonicNow(); + player_creation_time_ = starboard::CurrentMonotonicTime(); SbPlayerCreationParam creation_param = {}; creation_param.drm_system = drm_system_; @@ -888,10 +893,10 @@ void SbPlayerBridge::WriteBuffersInternal( } if (sample_type == kSbMediaTypeAudio && first_audio_sample_time_ == 0) { - first_audio_sample_time_ = SbTimeGetMonotonicNow(); + first_audio_sample_time_ = starboard::CurrentMonotonicTime(); } else if (sample_type == kSbMediaTypeVideo && first_video_sample_time_ == 0) { - first_video_sample_time_ = SbTimeGetMonotonicNow(); + first_video_sample_time_ = starboard::CurrentMonotonicTime(); } gathered_sbplayer_sample_infos_drm_info.push_back(SbDrmSampleInfo()); @@ -1099,7 +1104,7 @@ void SbPlayerBridge::OnPlayerStatus(SbPlayer player, SbPlayerState state, ++ticket_; } if (sb_player_state_initialized_time_ == 0) { - sb_player_state_initialized_time_ = SbTimeGetMonotonicNow(); + sb_player_state_initialized_time_ = starboard::CurrentMonotonicTime(); } sbplayer_interface_->Seek(player_, preroll_timestamp_.InMicroseconds(), ticket_); @@ -1109,10 +1114,10 @@ void SbPlayerBridge::OnPlayerStatus(SbPlayer player, SbPlayerState state, } if (state == kSbPlayerStatePrerolling && sb_player_state_prerolling_time_ == 0) { - sb_player_state_prerolling_time_ = SbTimeGetMonotonicNow(); + sb_player_state_prerolling_time_ = starboard::CurrentMonotonicTime(); } else if (state == kSbPlayerStatePresenting && sb_player_state_presenting_time_ == 0) { - sb_player_state_presenting_time_ = SbTimeGetMonotonicNow(); + sb_player_state_presenting_time_ = starboard::CurrentMonotonicTime(); #if !defined(COBALT_BUILD_TYPE_GOLD) LogStartupLatency(); #endif // !defined(COBALT_BUILD_TYPE_GOLD) @@ -1295,20 +1300,20 @@ void SbPlayerBridge::LogStartupLatency() const { set_drm_system_ready_cb_time_ - player_creation_time_); } - SbTime first_event_time = + int64_t first_event_time = std::max(player_creation_time_, set_drm_system_ready_cb_time_); - SbTime player_initialization_time_delta = + int64_t player_initialization_time_delta = sb_player_state_initialized_time_ - first_event_time; - SbTime player_preroll_time_delta = + int64_t player_preroll_time_delta = sb_player_state_prerolling_time_ - sb_player_state_initialized_time_; - SbTime first_audio_sample_time_delta = std::max( - first_audio_sample_time_ - sb_player_state_prerolling_time_, SbTime(0)); - SbTime first_video_sample_time_delta = std::max( - first_video_sample_time_ - sb_player_state_prerolling_time_, SbTime(0)); - SbTime player_presenting_time_delta = + int64_t first_audio_sample_time_delta = std::max( + first_audio_sample_time_ - sb_player_state_prerolling_time_, int64_t()); + int64_t first_video_sample_time_delta = std::max( + first_video_sample_time_ - sb_player_state_prerolling_time_, int64_t()); + int64_t player_presenting_time_delta = sb_player_state_presenting_time_ - std::max(first_audio_sample_time_, first_video_sample_time_); - SbTime startup_latency = sb_player_state_presenting_time_ - first_event_time; + int64_t startup_latency = sb_player_state_presenting_time_ - first_event_time; StatisticsWrapper::GetInstance()->startup_latency.AddSample(startup_latency, 1); diff --git a/cobalt/media/base/sbplayer_bridge.h b/cobalt/media/base/sbplayer_bridge.h index a48e53c4cf11..bf3858ec69ef 100644 --- a/cobalt/media/base/sbplayer_bridge.h +++ b/cobalt/media/base/sbplayer_bridge.h @@ -147,7 +147,7 @@ class SbPlayerBridge { SbDecodeTarget GetCurrentSbDecodeTarget(); SbPlayerOutputMode GetSbPlayerOutputMode(); - void RecordSetDrmSystemReadyTime(SbTimeMonotonic timestamp) { + void RecordSetDrmSystemReadyTime(int64_t timestamp) { set_drm_system_ready_cb_time_ = timestamp; } @@ -306,13 +306,13 @@ class SbPlayerBridge { std::string player_creation_error_message_; // Variables related to tracking player startup latencies. - SbTimeMonotonic set_drm_system_ready_cb_time_ = -1; - SbTimeMonotonic player_creation_time_ = 0; - SbTimeMonotonic sb_player_state_initialized_time_ = 0; - SbTimeMonotonic sb_player_state_prerolling_time_ = 0; - SbTimeMonotonic first_audio_sample_time_ = 0; - SbTimeMonotonic first_video_sample_time_ = 0; - SbTimeMonotonic sb_player_state_presenting_time_ = 0; + int64_t set_drm_system_ready_cb_time_ = -1; + int64_t player_creation_time_ = 0; + int64_t sb_player_state_initialized_time_ = 0; + int64_t sb_player_state_prerolling_time_ = 0; + int64_t first_audio_sample_time_ = 0; + int64_t first_video_sample_time_ = 0; + int64_t sb_player_state_presenting_time_ = 0; #if SB_HAS(PLAYER_WITH_URL) const bool is_url_based_; diff --git a/cobalt/media/base/sbplayer_interface.cc b/cobalt/media/base/sbplayer_interface.cc index df33c907bc28..84b35c7a074f 100644 --- a/cobalt/media/base/sbplayer_interface.cc +++ b/cobalt/media/base/sbplayer_interface.cc @@ -59,7 +59,7 @@ void DefaultSbPlayerInterface::Destroy(SbPlayer player) { SbPlayerDestroy(player); } -void DefaultSbPlayerInterface::Seek(SbPlayer player, SbTime seek_to_timestamp, +void DefaultSbPlayerInterface::Seek(SbPlayer player, int64_t seek_to_timestamp, int ticket) { #if SB_API_VERSION >= 15 SbPlayerSeek(player, seek_to_timestamp, ticket); diff --git a/cobalt/media/base/sbplayer_interface.h b/cobalt/media/base/sbplayer_interface.h index d9a31744ee3f..4d18813fb042 100644 --- a/cobalt/media/base/sbplayer_interface.h +++ b/cobalt/media/base/sbplayer_interface.h @@ -40,7 +40,7 @@ class SbPlayerInterface { virtual SbPlayerOutputMode GetPreferredOutputMode( const SbPlayerCreationParam* creation_param) = 0; virtual void Destroy(SbPlayer player) = 0; - virtual void Seek(SbPlayer player, SbTime seek_to_timestamp, int ticket) = 0; + virtual void Seek(SbPlayer player, int64_t seek_to_timestamp, int ticket) = 0; virtual bool IsEnhancedAudioExtensionEnabled() const = 0; virtual void WriteSamples(SbPlayer player, SbMediaType sample_type, @@ -108,7 +108,7 @@ class DefaultSbPlayerInterface final : public SbPlayerInterface { SbPlayerOutputMode GetPreferredOutputMode( const SbPlayerCreationParam* creation_param) override; void Destroy(SbPlayer player) override; - void Seek(SbPlayer player, SbTime seek_to_timestamp, int ticket) override; + void Seek(SbPlayer player, int64_t seek_to_timestamp, int ticket) override; bool IsEnhancedAudioExtensionEnabled() const override; void WriteSamples(SbPlayer player, SbMediaType sample_type, const SbPlayerSampleInfo* sample_infos, diff --git a/cobalt/media/base/sbplayer_pipeline.cc b/cobalt/media/base/sbplayer_pipeline.cc index 8b2962832fff..b2ae585f0253 100644 --- a/cobalt/media/base/sbplayer_pipeline.cc +++ b/cobalt/media/base/sbplayer_pipeline.cc @@ -26,6 +26,7 @@ #include "cobalt/base/startup_timer.h" #include "starboard/common/media.h" #include "starboard/common/string.h" +#include "starboard/common/time.h" #include "starboard/configuration_constants.h" #include "third_party/chromium/media/base/bind_to_current_loop.h" #include "third_party/chromium/media/base/channel_layout.h" @@ -90,13 +91,13 @@ bool HasRemoteAudioOutputs( // When playback rate is 2x, an 0.5 seconds of write duration effectively only // lasts for 0.25 seconds and causes audio underflow, and the function will // adjust it to 1 second in this case. -SbTime AdjustWriteDurationForPlaybackRate(SbTime write_duration, - float playback_rate) { +int64_t AdjustWriteDurationForPlaybackRate(int64_t write_duration, + float playback_rate) { if (playback_rate <= 1.0) { return write_duration; } - return static_cast(write_duration * playback_rate); + return static_cast(write_duration * playback_rate); } } // namespace @@ -109,7 +110,7 @@ SbPlayerPipeline::SbPlayerPipeline( bool allow_resume_after_suspend, bool allow_batched_sample_write, bool force_punch_out_by_default, #if SB_API_VERSION >= 15 - SbTime audio_write_duration_local, SbTime audio_write_duration_remote, + int64_t audio_write_duration_local, int64_t audio_write_duration_remote, #endif // SB_API_VERSION >= 15 MediaLog* media_log, MediaMetricsProvider* media_metrics_provider, DecodeTargetProvider* decode_target_provider) @@ -438,8 +439,8 @@ void SbPlayerPipeline::SetVolume(float volume) { } void SbPlayerPipeline::StoreMediaTime(TimeDelta media_time) { - last_media_time_ = media_time.ToSbTime(); - last_time_media_time_retrieved_ = SbTimeGetNow(); + last_media_time_ = media_time.InMicroseconds(); + last_time_media_time_retrieved_ = starboard::CurrentPosixTime(); } TimeDelta SbPlayerPipeline::GetMediaTime() { @@ -474,11 +475,11 @@ TimeDelta SbPlayerPipeline::GetMediaTime() { &statistics_.video_frames_dropped, &media_time); // Guarantee that we report monotonically increasing media time - if (media_time.ToSbTime() < last_media_time_) { + if (media_time.InMicroseconds() < last_media_time_) { if (retrograde_media_time_counter_ == 0) { DLOG(WARNING) << "Received retrograde media time, new:" - << media_time.ToSbTime() << ", last: " << last_media_time_ - << "."; + << media_time.InMicroseconds() + << ", last: " << last_media_time_ << "."; } media_time = base::TimeDelta::FromMicroseconds(last_media_time_); retrograde_media_time_counter_++; @@ -1046,7 +1047,7 @@ void SbPlayerPipeline::OnDemuxerStreamRead( for (const auto& buffer : buffers) { playback_statistics_.OnAudioAU(buffer); if (!buffer->end_of_stream()) { - timestamp_of_last_written_audio_ = buffer->timestamp().ToSbTime(); + timestamp_of_last_written_audio_ = buffer->timestamp().InMicroseconds(); } } } else { @@ -1084,7 +1085,7 @@ void SbPlayerPipeline::OnNeedData(DemuxerStream::Type type, } // If we haven't checked the media time recently, update it now. - if (SbTimeGetNow() - last_time_media_time_retrieved_ > + if (starboard::CurrentPosixTime() - last_time_media_time_retrieved_ > kMediaTimeCheckInterval) { GetMediaTime(); } @@ -1093,12 +1094,12 @@ void SbPlayerPipeline::OnNeedData(DemuxerStream::Type type, // after the player has received enough audio for preroll, taking into // account that our estimate of playback time might be behind by // |kMediaTimeCheckInterval|. - if (timestamp_of_last_written_audio_ - seek_time_.ToSbTime() > + if (timestamp_of_last_written_audio_ - seek_time_.InMicroseconds() > AdjustWriteDurationForPlaybackRate(audio_write_duration_for_preroll_, playback_rate_)) { // The estimated time ahead of playback may be negative if no audio has // been written. - SbTime time_ahead_of_playback = + int64_t time_ahead_of_playback = timestamp_of_last_written_audio_ - last_media_time_; auto adjusted_write_duration = AdjustWriteDurationForPlaybackRate( audio_write_duration_, playback_rate_); @@ -1333,7 +1334,7 @@ void SbPlayerPipeline::ResumeTask(PipelineWindow window, DCHECK(suspended_); if (!suspended_) { - last_resume_time_ = SbTimeGetMonotonicNow(); + last_resume_time_ = starboard::CurrentMonotonicTime(); done_event->Signal(); return; } @@ -1371,7 +1372,7 @@ void SbPlayerPipeline::ResumeTask(PipelineWindow window, } suspended_ = false; - last_resume_time_ = SbTimeGetMonotonicNow(); + last_resume_time_ = starboard::CurrentMonotonicTime(); done_event->Signal(); } @@ -1391,8 +1392,8 @@ std::string SbPlayerPipeline::AppendStatisticsString( } std::string SbPlayerPipeline::GetTimeInformation() const { - auto round_time_in_seconds = [](const SbTime time) { - const int64_t seconds = time / kSbTimeSecond; + auto round_time_in_seconds = [](const int64_t time) { + const int64_t seconds = time / base::Time::kMicrosecondsPerSecond; if (seconds < 15) { return seconds / 5 * 5; } @@ -1400,18 +1401,18 @@ std::string SbPlayerPipeline::GetTimeInformation() const { return seconds / 15 * 15; } if (seconds < 3600) { - return std::max(static_cast(60), seconds / 600 * 600); + return std::max(static_cast(60), seconds / 600 * 600); } - return std::max(static_cast(3600), seconds / 18000 * 18000); + return std::max(static_cast(3600), seconds / 18000 * 18000); }; std::string time_since_start = - std::to_string( - round_time_in_seconds(base::StartupTimer::TimeElapsed().ToSbTime())) + + std::to_string(round_time_in_seconds( + base::StartupTimer::TimeElapsed().InMicroseconds())) + "s"; std::string time_since_resume = last_resume_time_ != -1 - ? std::to_string(round_time_in_seconds(SbTimeGetMonotonicNow() - - last_resume_time_)) + + ? std::to_string(round_time_in_seconds( + starboard::CurrentMonotonicTime() - last_resume_time_)) + "s" : "null"; return "time since app start: " + time_since_start + @@ -1421,7 +1422,7 @@ std::string SbPlayerPipeline::GetTimeInformation() const { void SbPlayerPipeline::RunSetDrmSystemReadyCB( DrmSystemReadyCB drm_system_ready_cb) { TRACE_EVENT0("cobalt::media", "SbPlayerPipeline::RunSetDrmSystemReadyCB"); - set_drm_system_ready_cb_time_ = SbTimeGetMonotonicNow(); + set_drm_system_ready_cb_time_ = starboard::CurrentMonotonicTime(); set_drm_system_ready_cb_.Run(drm_system_ready_cb); } diff --git a/cobalt/media/base/sbplayer_pipeline.h b/cobalt/media/base/sbplayer_pipeline.h index dc851c818d4a..7bbe1534ba4b 100644 --- a/cobalt/media/base/sbplayer_pipeline.h +++ b/cobalt/media/base/sbplayer_pipeline.h @@ -34,7 +34,6 @@ #include "cobalt/media/base/sbplayer_bridge.h" #include "cobalt/media/base/sbplayer_set_bounds_helper.h" #include "starboard/configuration_constants.h" -#include "starboard/time.h" #include "third_party/chromium/media/base/audio_decoder_config.h" #include "third_party/chromium/media/base/decoder_buffer.h" #include "third_party/chromium/media/base/demuxer.h" @@ -64,7 +63,7 @@ class MEDIA_EXPORT SbPlayerPipeline : public Pipeline, bool allow_resume_after_suspend, bool allow_batched_sample_write, bool force_punch_out_by_default, #if SB_API_VERSION >= 15 - SbTime audio_write_duration_local, SbTime audio_write_duration_remote, + int64_t audio_write_duration_local, int64_t audio_write_duration_remote, #endif // SB_API_VERSION >= 15 MediaLog* media_log, MediaMetricsProvider* media_metrics_provider, DecodeTargetProvider* decode_target_provider); @@ -312,34 +311,36 @@ class MEDIA_EXPORT SbPlayerPipeline : public Pipeline, DecodeTargetProvider* decode_target_provider_; #if SB_API_VERSION >= 15 - const SbTime audio_write_duration_local_; - const SbTime audio_write_duration_remote_; + const int64_t audio_write_duration_local_; + const int64_t audio_write_duration_remote_; // The two variables below should always contain the same value. They are // kept as separate variables so we can keep the existing implementation as // is, which simplifies the implementation across multiple Starboard versions. - SbTime audio_write_duration_ = 0; - SbTime audio_write_duration_for_preroll_ = audio_write_duration_; + int64_t audio_write_duration_ = 0; + int64_t audio_write_duration_for_preroll_ = audio_write_duration_; #else // SB_API_VERSION >= 15 // Read audio from the stream if |timestamp_of_last_written_audio_| is less // than |seek_time_| + |audio_write_duration_for_preroll_|, this effectively // allows 10 seconds of audio to be written to the SbPlayer after playback // startup or seek. - SbTime audio_write_duration_for_preroll_ = 10 * kSbTimeSecond; + int64_t audio_write_duration_for_preroll_ = + 10 * base::Time::kMicrosecondsPerSecond; // Don't read audio from the stream more than |audio_write_duration_| ahead of // the current media time during playing. - SbTime audio_write_duration_ = kSbTimeSecond; + int64_t audio_write_duration_ = 1 * base::Time::kMicrosecondsPerSecond; #endif // SB_API_VERSION >= 15 // Only call GetMediaTime() from OnNeedData if it has been // |kMediaTimeCheckInterval| since the last call to GetMediaTime(). - static const SbTime kMediaTimeCheckInterval = 0.1 * kSbTimeSecond; + static const int64_t kMediaTimeCheckInterval = + 0.1 * base::Time::kMicrosecondsPerSecond; // Timestamp for the last written audio. - SbTime timestamp_of_last_written_audio_ = 0; + int64_t timestamp_of_last_written_audio_ = 0; // Last media time reported by GetMediaTime(). - base::CVal last_media_time_; - // Time when we last checked the media time. - SbTime last_time_media_time_retrieved_ = 0; + base::CVal last_media_time_; + // Timestamp microseconds when we last checked the media time. + uint64_t last_time_media_time_retrieved_ = 0; // Counter for retrograde media time. size_t retrograde_media_time_counter_ = 0; // The maximum video playback capabilities required for the playback. @@ -347,9 +348,9 @@ class MEDIA_EXPORT SbPlayerPipeline : public Pipeline, PlaybackStatistics playback_statistics_; - SbTimeMonotonic last_resume_time_ = -1; + int64_t last_resume_time_ = -1; - SbTimeMonotonic set_drm_system_ready_cb_time_ = -1; + int64_t set_drm_system_ready_cb_time_ = -1; DISALLOW_COPY_AND_ASSIGN(SbPlayerPipeline); }; diff --git a/cobalt/media/decoder_buffer_allocator.cc b/cobalt/media/decoder_buffer_allocator.cc index dab023a6178b..55e2dcfd4462 100644 --- a/cobalt/media/decoder_buffer_allocator.cc +++ b/cobalt/media/decoder_buffer_allocator.cc @@ -176,7 +176,7 @@ int DecoderBufferAllocator::GetBufferPadding() const { #endif // SB_API_VERSION >= 14 } -SbTime DecoderBufferAllocator::GetBufferGarbageCollectionDurationThreshold() +int64_t DecoderBufferAllocator::GetBufferGarbageCollectionDurationThreshold() const { return SbMediaGetBufferGarbageCollectionDurationThreshold(); } diff --git a/cobalt/media/decoder_buffer_allocator.h b/cobalt/media/decoder_buffer_allocator.h index 68ba5de85838..7a5b806a762b 100644 --- a/cobalt/media/decoder_buffer_allocator.h +++ b/cobalt/media/decoder_buffer_allocator.h @@ -46,7 +46,7 @@ class DecoderBufferAllocator : public ::media::DecoderBuffer::Allocator, int GetAudioBufferBudget() const override; int GetBufferAlignment() const override; int GetBufferPadding() const override; - SbTime GetBufferGarbageCollectionDurationThreshold() const override; + int64_t GetBufferGarbageCollectionDurationThreshold() const override; int GetProgressiveBufferBudget(SbMediaVideoCodec codec, int resolution_width, int resolution_height, int bits_per_pixel) const override; diff --git a/cobalt/media/media_module.h b/cobalt/media/media_module.h index cc5db7122807..6b629b88b27a 100644 --- a/cobalt/media/media_module.h +++ b/cobalt/media/media_module.h @@ -133,8 +133,8 @@ class MediaModule : public WebMediaPlayerFactory, bool force_punch_out_by_default_ = false; #if SB_API_VERSION >= 15 - SbTime audio_write_duration_local_ = kSbPlayerWriteDurationLocal; - SbTime audio_write_duration_remote_ = kSbPlayerWriteDurationRemote; + int64_t audio_write_duration_local_ = kSbPlayerWriteDurationLocal; + int64_t audio_write_duration_remote_ = kSbPlayerWriteDurationRemote; #endif // SB_API_VERSION >= 15 DecoderBufferAllocator decoder_buffer_allocator_; diff --git a/cobalt/media/player/web_media_player_impl.cc b/cobalt/media/player/web_media_player_impl.cc index 6941c04d3d83..50c4efd55975 100644 --- a/cobalt/media/player/web_media_player_impl.cc +++ b/cobalt/media/player/web_media_player_impl.cc @@ -121,7 +121,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl( bool allow_resume_after_suspend, bool allow_batched_sample_write, bool force_punch_out_by_default, #if SB_API_VERSION >= 15 - SbTime audio_write_duration_local, SbTime audio_write_duration_remote, + int64_t audio_write_duration_local, int64_t audio_write_duration_remote, #endif // SB_API_VERSION >= 15 ::media::MediaLog* const media_log) : pipeline_thread_("media_pipeline"), @@ -486,7 +486,8 @@ base::Time WebMediaPlayerImpl::GetStartDate() const { base::TimeDelta start_date = pipeline_->GetMediaStartDate(); - return base::Time::FromSbTime(start_date.InMicroseconds()); + return base::Time::FromDeltaSinceWindowsEpoch( + base::TimeDelta::FromMicroseconds(start_date.InMicroseconds())); } #endif // SB_HAS(PLAYER_WITH_URL) diff --git a/cobalt/media/player/web_media_player_impl.h b/cobalt/media/player/web_media_player_impl.h index adb7ed2a577b..df4b17640c15 100644 --- a/cobalt/media/player/web_media_player_impl.h +++ b/cobalt/media/player/web_media_player_impl.h @@ -113,8 +113,8 @@ class WebMediaPlayerImpl : public WebMediaPlayer, bool allow_batched_sample_write, bool force_punch_out_by_default, #if SB_API_VERSION >= 15 - SbTime audio_write_duration_local, - SbTime audio_write_duration_remote, + int64_t audio_write_duration_local, + int64_t audio_write_duration_remote, #endif // SB_API_VERSION >= 15 ::media::MediaLog* const media_log); ~WebMediaPlayerImpl() override; diff --git a/cobalt/media/progressive/demuxer_extension_wrapper.cc b/cobalt/media/progressive/demuxer_extension_wrapper.cc index 03b8b8ab1e09..cf3b2a98060b 100644 --- a/cobalt/media/progressive/demuxer_extension_wrapper.cc +++ b/cobalt/media/progressive/demuxer_extension_wrapper.cc @@ -626,7 +626,7 @@ base::TimeDelta DemuxerExtensionWrapper::GetStartTime() const { } base::Time DemuxerExtensionWrapper::GetTimelineOffset() const { - const SbTime reported_time = impl_->GetTimelineOffset(impl_->user_data); + const int64_t reported_time = impl_->GetTimelineOffset(impl_->user_data); return reported_time == 0 ? base::Time() : base::Time::FromDeltaSinceWindowsEpoch( diff --git a/cobalt/media/progressive/demuxer_extension_wrapper_test.cc b/cobalt/media/progressive/demuxer_extension_wrapper_test.cc index d199aa4d1f50..8888f05141ad 100644 --- a/cobalt/media/progressive/demuxer_extension_wrapper_test.cc +++ b/cobalt/media/progressive/demuxer_extension_wrapper_test.cc @@ -108,8 +108,8 @@ class MockCobaltExtensionDemuxer { public: MOCK_METHOD0(Initialize, CobaltExtensionDemuxerStatus()); MOCK_METHOD1(Seek, CobaltExtensionDemuxerStatus(int64_t seek_time_us)); - MOCK_METHOD0(GetStartTime, SbTime()); - MOCK_METHOD0(GetTimelineOffset, SbTime()); + MOCK_METHOD0(GetStartTime, int64_t()); + MOCK_METHOD0(GetTimelineOffset, int64_t()); MOCK_METHOD3(Read, void(CobaltExtensionDemuxerStreamType type, CobaltExtensionDemuxerReadCB read_cb, void* read_cb_user_data)); @@ -117,7 +117,7 @@ class MockCobaltExtensionDemuxer { bool(CobaltExtensionDemuxerAudioDecoderConfig* config)); MOCK_METHOD1(GetVideoConfig, bool(CobaltExtensionDemuxerVideoDecoderConfig* config)); - MOCK_METHOD0(GetDuration, SbTime()); + MOCK_METHOD0(GetDuration, int64_t()); // Pure C functions to be used in CobaltExtensionDemuxer. These expect // |user_data| to be a pointer to a MockCobaltExtensionDemuxer. @@ -131,11 +131,11 @@ class MockCobaltExtensionDemuxer { seek_time_us); } - static SbTime GetStartTimeImpl(void* user_data) { + static int64_t GetStartTimeImpl(void* user_data) { return static_cast(user_data)->GetStartTime(); } - static SbTime GetTimelineOffsetImpl(void* user_data) { + static int64_t GetTimelineOffsetImpl(void* user_data) { return static_cast(user_data) ->GetTimelineOffset(); } @@ -158,7 +158,7 @@ class MockCobaltExtensionDemuxer { config); } - static SbTime GetDurationImpl(void* user_data) { + static int64_t GetDurationImpl(void* user_data) { return static_cast(user_data)->GetDuration(); } }; diff --git a/cobalt/media/progressive/progressive_demuxer.cc b/cobalt/media/progressive/progressive_demuxer.cc index 932b45e04099..9e457fdedcf5 100644 --- a/cobalt/media/progressive/progressive_demuxer.cc +++ b/cobalt/media/progressive/progressive_demuxer.cc @@ -385,7 +385,8 @@ void ProgressiveDemuxer::AllocateBuffer() { VideoConfig().visible_rect().size().width(), VideoConfig().visible_rect().size().height(), kBitDepth); int progressive_duration_cap_in_seconds = - SbMediaGetBufferGarbageCollectionDurationThreshold() / kSbTimeSecond; + SbMediaGetBufferGarbageCollectionDurationThreshold() / + base::Time::kMicrosecondsPerSecond; const int kEstimatedBufferCountPerSeconds = 70; int progressive_buffer_count_cap = progressive_duration_cap_in_seconds * kEstimatedBufferCountPerSeconds; diff --git a/cobalt/media/sandbox/web_media_player_sandbox.cc b/cobalt/media/sandbox/web_media_player_sandbox.cc index cfa4a2827475..17f82833f8af 100644 --- a/cobalt/media/sandbox/web_media_player_sandbox.cc +++ b/cobalt/media/sandbox/web_media_player_sandbox.cc @@ -25,6 +25,7 @@ #include "base/message_loop/message_loop.h" #include "base/path_service.h" #include "base/threading/platform_thread.h" +#include "base/time/time.h" #include "cobalt/base/wrap_main.h" #include "cobalt/media/sandbox/format_guesstimator.h" #include "cobalt/media/sandbox/media_sandbox.h" @@ -196,8 +197,8 @@ class Application { media_sandbox_.RegisterFrameCB( base::Bind(&Application::FrameCB, base::Unretained(this))); - timer_event_id_ = - SbEventSchedule(Application::OnTimer, this, kSbTimeSecond / 10); + timer_event_id_ = SbEventSchedule(Application::OnTimer, this, + base::Time::kMicrosecondsPerSecond / 10); } void InitializeAdaptivePlayback( @@ -266,8 +267,8 @@ class Application { media_sandbox_.RegisterFrameCB( base::Bind(&Application::FrameCB, base::Unretained(this))); - timer_event_id_ = - SbEventSchedule(Application::OnTimer, this, kSbTimeSecond / 10); + timer_event_id_ = SbEventSchedule(Application::OnTimer, this, + base::Time::kMicrosecondsPerSecond / 10); } void InitializeProgressivePlayback(const FormatGuesstimator& guesstimator) { @@ -283,8 +284,8 @@ class Application { media_sandbox_.RegisterFrameCB( base::Bind(&Application::FrameCB, base::Unretained(this))); - timer_event_id_ = - SbEventSchedule(Application::OnTimer, this, kSbTimeSecond / 10); + timer_event_id_ = SbEventSchedule(Application::OnTimer, this, + base::Time::kMicrosecondsPerSecond / 10); } static void OnTimer(void* context) { @@ -317,8 +318,8 @@ class Application { } base::RunLoop().RunUntilIdle(); - timer_event_id_ = - SbEventSchedule(Application::OnTimer, this, kSbTimeSecond / 10); + timer_event_id_ = SbEventSchedule(Application::OnTimer, this, + base::Time::kMicrosecondsPerSecond / 10); } void OnChunkDemuxerOpened(ChunkDemuxer* chunk_demuxer) { diff --git a/cobalt/media_session/BUILD.gn b/cobalt/media_session/BUILD.gn index 2ef1ceaf6aca..8e5fee29fd28 100644 --- a/cobalt/media_session/BUILD.gn +++ b/cobalt/media_session/BUILD.gn @@ -37,6 +37,7 @@ static_library("media_session") { "//cobalt/math", "//cobalt/script", "//starboard:starboard_headers_only", + "//starboard/common", ] } diff --git a/cobalt/media_session/media_session.h b/cobalt/media_session/media_session.h index 4814c9ee42a7..ba1827651d7c 100644 --- a/cobalt/media_session/media_session.h +++ b/cobalt/media_session/media_session.h @@ -31,7 +31,7 @@ #include "cobalt/script/callback_function.h" #include "cobalt/script/script_value.h" #include "cobalt/script/wrappable.h" -#include "starboard/time.h" +#include "starboard/common/time.h" namespace cobalt { namespace media_session { @@ -96,8 +96,8 @@ class MediaSession : public script::Wrappable { void OnChanged(); // Returns a time representing right now - may be overridden for testing. - virtual SbTimeMonotonic GetMonotonicNow() const { - return SbTimeGetMonotonicNow(); + virtual int64_t GetMonotonicNow() const { + return starboard::CurrentMonotonicTime(); } ActionMap action_map_; @@ -106,7 +106,7 @@ class MediaSession : public script::Wrappable { MediaSessionPlaybackState playback_state_; scoped_refptr task_runner_; bool is_change_task_queued_; - SbTimeMonotonic last_position_updated_time_; + int64_t last_position_updated_time_; base::Optional media_position_state_; DISALLOW_COPY_AND_ASSIGN(MediaSession); diff --git a/cobalt/media_session/media_session_client.cc b/cobalt/media_session/media_session_client.cc index ab740dead22d..121ecc611a77 100644 --- a/cobalt/media_session/media_session_client.cc +++ b/cobalt/media_session/media_session_client.cc @@ -22,7 +22,7 @@ #include "base/logging.h" #include "cobalt/media_session/media_image.h" #include "cobalt/script/sequence.h" -#include "starboard/time.h" +#include "starboard/common/time.h" namespace cobalt { namespace media_session { @@ -62,17 +62,17 @@ void GuessMediaPositionState(MediaSessionState* session_state, if (std::isfinite(duration)) { position_state.set_duration(duration); } else if (std::isinf(duration)) { - position_state.set_duration(kSbTimeMax); + position_state.set_duration(kSbInt64Max); } else { position_state.set_duration(0.0); } position_state.set_playback_rate((*guess_player)->GetPlaybackRate()); position_state.set_position((*guess_player)->GetCurrentTime()); - *session_state = MediaSessionState(session_state->metadata(), - SbTimeGetMonotonicNow(), position_state, - session_state->actual_playback_state(), - session_state->available_actions()); + *session_state = MediaSessionState( + session_state->metadata(), starboard::CurrentMonotonicTime(), + position_state, session_state->actual_playback_state(), + session_state->available_actions()); } } } // namespace diff --git a/cobalt/media_session/media_session_client.h b/cobalt/media_session/media_session_client.h index 54817e40044f..3c174982fcb3 100644 --- a/cobalt/media_session/media_session_client.h +++ b/cobalt/media_session/media_session_client.h @@ -26,7 +26,6 @@ #include "cobalt/media_session/media_session_action_details.h" #include "cobalt/media_session/media_session_state.h" #include "starboard/extension/media_session.h" -#include "starboard/time.h" namespace cobalt { namespace media_session { diff --git a/cobalt/media_session/media_session_state.cc b/cobalt/media_session/media_session_state.cc index 0a81f025ef79..f577a261313b 100644 --- a/cobalt/media_session/media_session_state.cc +++ b/cobalt/media_session/media_session_state.cc @@ -21,7 +21,7 @@ namespace media_session { MediaSessionState::MediaSessionState( base::Optional metadata, - SbTimeMonotonic last_position_updated_time, + int64_t last_position_updated_time, const base::Optional& media_position_state, MediaSessionPlaybackState actual_playback_state, AvailableActionsSet available_actions) @@ -30,38 +30,39 @@ MediaSessionState::MediaSessionState( actual_playback_state_(actual_playback_state), available_actions_(available_actions) { if (media_position_state) { - double duration = media_position_state->duration(); - duration_ = (duration >= static_cast(kSbTimeMax)) - ? kSbTimeMax - : static_cast(duration * kSbTimeSecond); + double duration = media_position_state->duration(); // represents seconds + duration_usec_ = (duration >= static_cast(kSbInt64Max)) + ? kSbInt64Max + : static_cast( + duration * base::Time::kMicrosecondsPerSecond); actual_playback_rate_ = (actual_playback_state_ == kMediaSessionPlaybackStatePaused) ? 0.0 : media_position_state->playback_rate(); - last_position_ = static_cast( - media_position_state->position() * kSbTimeSecond); + last_position_usec_ = static_cast( + media_position_state->position() * base::Time::kMicrosecondsPerSecond); } } -SbTimeMonotonic MediaSessionState::GetCurrentPlaybackPosition( - SbTimeMonotonic monotonic_now) const { - SbTimeMonotonic time_elapsed = monotonic_now - last_position_updated_time_; - time_elapsed = static_cast( - static_cast(time_elapsed) * actual_playback_rate_); - SbTimeMonotonic position = time_elapsed + last_position_; - return std::max(static_cast(0), - std::min(duration(), position)); +int64_t MediaSessionState::GetCurrentPlaybackPosition( + int64_t monotonic_now) const { + int64_t time_elapsed = monotonic_now - last_position_updated_time_; + time_elapsed = static_cast(static_cast(time_elapsed) * + actual_playback_rate_); + int64_t position_usec = time_elapsed + last_position_usec_; + return std::max(int64_t(), std::min(duration(), position_usec)); } bool MediaSessionState::operator==(const MediaSessionState& other) const { return other.last_position_updated_time_ == last_position_updated_time_ && other.actual_playback_state_ == actual_playback_state_ && other.available_actions_ == available_actions_ && - other.duration_ == duration_ && + other.duration_usec_ == duration_usec_ && other.actual_playback_rate_ == actual_playback_rate_ && - other.last_position_ == last_position_ && other.metadata_ == metadata_; + other.last_position_usec_ == last_position_usec_ && + other.metadata_ == metadata_; } bool MediaSessionState::operator!=(const MediaSessionState& other) const { return !(*this == other); diff --git a/cobalt/media_session/media_session_state.h b/cobalt/media_session/media_session_state.h index 65148b4b0758..09b48aa57a08 100644 --- a/cobalt/media_session/media_session_state.h +++ b/cobalt/media_session/media_session_state.h @@ -18,11 +18,12 @@ #include #include "base/optional.h" +#include "base/time/time.h" #include "cobalt/media_session/media_metadata_init.h" #include "cobalt/media_session/media_position_state.h" #include "cobalt/media_session/media_session_action.h" #include "cobalt/media_session/media_session_playback_state.h" -#include "starboard/time.h" +#include "starboard/common/time.h" namespace cobalt { namespace media_session { @@ -36,7 +37,7 @@ class MediaSessionState { MediaSessionState( base::Optional metadata, - SbTimeMonotonic last_position_updated_time, + int64_t last_position_updated_time, const base::Optional& media_position_state, MediaSessionPlaybackState actual_playback_state, AvailableActionsSet available_actions); @@ -59,14 +60,13 @@ class MediaSessionState { // Returns the position of the current playback. // https://wicg.github.io/mediasession/#current-playback-position // Returns the position - SbTimeMonotonic current_playback_position() const { - return GetCurrentPlaybackPosition(SbTimeGetMonotonicNow()); + int64_t current_playback_position() const { + return GetCurrentPlaybackPosition(starboard::CurrentMonotonicTime()); } // Returns the position of the current playback, given the current time. - // This may be used for testing without calling |SbTimeGetMonotonicNow|. - SbTimeMonotonic GetCurrentPlaybackPosition( - SbTimeMonotonic monotonic_now) const; + // This may be used for testing without calling |CurrentMonotonicTime|. + int64_t GetCurrentPlaybackPosition(int64_t monotonic_now) const; // Returns a coefficient of the current playback rate. e.g. 1.0 is normal // forward playback, negative for reverse playback, and 0.0 when paused. @@ -74,10 +74,10 @@ class MediaSessionState { double actual_playback_rate() const { return actual_playback_rate_; } // Returns the duration of the currently playing media. 0 if no media is - // playing or the web app has not reported the position state. kSbTimeMax if + // playing or the web app has not reported the position state. kSbInt64Max if // there is no defined duration such as live playback. // https://wicg.github.io/mediasession/#dom-mediapositionstate-duration - SbTimeMonotonic duration() const { return duration_; } + int64_t duration() const { return duration_usec_; } // Returns the actual playback state. // https://wicg.github.io/mediasession/#actual-playback-state @@ -95,10 +95,10 @@ class MediaSessionState { private: base::Optional metadata_; - SbTimeMonotonic last_position_updated_time_ = 0; - SbTimeMonotonic last_position_ = 0; + int64_t last_position_updated_time_ = 0; + int64_t last_position_usec_ = 0; double actual_playback_rate_ = 0.0; - SbTimeMonotonic duration_ = 0; + int64_t duration_usec_ = 0; MediaSessionPlaybackState actual_playback_state_ = kMediaSessionPlaybackStateNone; AvailableActionsSet available_actions_; diff --git a/cobalt/media_session/media_session_test.cc b/cobalt/media_session/media_session_test.cc index 43f34ed64c02..23eb737e1819 100644 --- a/cobalt/media_session/media_session_test.cc +++ b/cobalt/media_session/media_session_test.cc @@ -19,15 +19,16 @@ #include "base/message_loop/message_loop.h" #include "base/run_loop.h" +#include "base/time/time.h" #include "cobalt/bindings/testing/script_object_owner.h" #include "cobalt/media_session/media_session_client.h" #include "cobalt/script/callback_function.h" #include "cobalt/script/script_value.h" #include "cobalt/script/testing/fake_script_value.h" #include "cobalt/script/wrappable.h" +#include "starboard/common/time.h" #include "starboard/extension/media_session.h" #include "starboard/thread.h" -#include "starboard/time.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -72,7 +73,7 @@ class MockMediaSessionClient : public MediaSessionClient { if (current_change_count != session_change_count_) { break; } - SbThreadSleep(kSbTimeMillisecond); + SbThreadSleep(1000); // 1ms } } MediaSessionState GetMediaSessionState() const { return session_state_; } @@ -90,7 +91,7 @@ class MockMediaSession : public MediaSession { return static_cast(media_session_client()); } - MOCK_CONST_METHOD0(GetMonotonicNow, SbTimeMonotonic()); + MOCK_CONST_METHOD0(GetMonotonicNow, int64_t()); }; MATCHER_P(SeekTime, time, "") { @@ -419,7 +420,7 @@ TEST(MediaSessionTest, PositionState) { MediaSessionState state; - SbTimeMonotonic start_time = 1111111111; + int64_t start_time = 1111111111; base::Optional position_state; position_state.emplace(); @@ -433,8 +434,8 @@ TEST(MediaSessionTest, PositionState) { // Position state not yet reported state = session->mock_session_client()->GetMediaSessionState(); - EXPECT_EQ(0, - state.GetCurrentPlaybackPosition(start_time + 999 * kSbTimeSecond)); + EXPECT_EQ(0, state.GetCurrentPlaybackPosition( + start_time + 999 * base::Time::kMicrosecondsPerSecond)); EXPECT_EQ(0, state.duration()); EXPECT_EQ(0.0, state.actual_playback_rate()); @@ -444,11 +445,13 @@ TEST(MediaSessionTest, PositionState) { session->SetPositionState(position_state); session->mock_session_client()->WaitForSessionStateChange(); state = session->mock_session_client()->GetMediaSessionState(); - EXPECT_EQ((10 + 50) * kSbTimeSecond, - state.GetCurrentPlaybackPosition(start_time + 50 * kSbTimeSecond)); - EXPECT_EQ(100 * kSbTimeSecond, - state.GetCurrentPlaybackPosition(start_time + 150 * kSbTimeSecond)); - EXPECT_EQ(100 * kSbTimeSecond, state.duration()); + EXPECT_EQ((10 + 50) * base::Time::kMicrosecondsPerSecond, + state.GetCurrentPlaybackPosition( + start_time + 50 * base::Time::kMicrosecondsPerSecond)); + EXPECT_EQ(100 * base::Time::kMicrosecondsPerSecond, + state.GetCurrentPlaybackPosition( + start_time + 150 * base::Time::kMicrosecondsPerSecond)); + EXPECT_EQ(100 * base::Time::kMicrosecondsPerSecond, state.duration()); EXPECT_EQ(1.0, state.actual_playback_rate()); // Fast playback @@ -457,11 +460,13 @@ TEST(MediaSessionTest, PositionState) { session->SetPositionState(position_state); session->mock_session_client()->WaitForSessionStateChange(); state = session->mock_session_client()->GetMediaSessionState(); - EXPECT_EQ((10 + 2 * 20) * kSbTimeSecond, - state.GetCurrentPlaybackPosition(start_time + 20 * kSbTimeSecond)); - EXPECT_EQ(100 * kSbTimeSecond, - state.GetCurrentPlaybackPosition(start_time + 50 * kSbTimeSecond)); - EXPECT_EQ(100 * kSbTimeSecond, state.duration()); + EXPECT_EQ((10 + 2 * 20) * base::Time::kMicrosecondsPerSecond, + state.GetCurrentPlaybackPosition( + start_time + 20 * base::Time::kMicrosecondsPerSecond)); + EXPECT_EQ(100 * base::Time::kMicrosecondsPerSecond, + state.GetCurrentPlaybackPosition( + start_time + 50 * base::Time::kMicrosecondsPerSecond)); + EXPECT_EQ(100 * base::Time::kMicrosecondsPerSecond, state.duration()); EXPECT_EQ(2.0, state.actual_playback_rate()); // Reverse playback @@ -470,11 +475,13 @@ TEST(MediaSessionTest, PositionState) { session->SetPositionState(position_state); session->mock_session_client()->WaitForSessionStateChange(); state = session->mock_session_client()->GetMediaSessionState(); - EXPECT_EQ(0 * kSbTimeSecond, - state.GetCurrentPlaybackPosition(start_time + 20 * kSbTimeSecond)); - EXPECT_EQ((10 - 3) * kSbTimeSecond, - state.GetCurrentPlaybackPosition(start_time + 3 * kSbTimeSecond)); - EXPECT_EQ(100 * kSbTimeSecond, state.duration()); + EXPECT_EQ(0 * base::Time::kMicrosecondsPerSecond, + state.GetCurrentPlaybackPosition( + start_time + 20 * base::Time::kMicrosecondsPerSecond)); + EXPECT_EQ((10 - 3) * base::Time::kMicrosecondsPerSecond, + state.GetCurrentPlaybackPosition( + start_time + 3 * base::Time::kMicrosecondsPerSecond)); + EXPECT_EQ(100 * base::Time::kMicrosecondsPerSecond, state.duration()); EXPECT_EQ(-1.0, state.actual_playback_rate()); // Indefinite duration (live) playback @@ -484,9 +491,11 @@ TEST(MediaSessionTest, PositionState) { session->SetPositionState(position_state); session->mock_session_client()->WaitForSessionStateChange(); state = session->mock_session_client()->GetMediaSessionState(); - EXPECT_EQ(10 * kSbTimeSecond + 1 * kSbTimeDay, - state.GetCurrentPlaybackPosition(start_time + 1 * kSbTimeDay)); - EXPECT_EQ(kSbTimeMax, state.duration()); + EXPECT_EQ(10 * base::Time::kMicrosecondsPerSecond + + 1 * base::Time::kMicrosecondsPerDay, + state.GetCurrentPlaybackPosition( + start_time + 1 * base::Time::kMicrosecondsPerDay)); + EXPECT_EQ(kSbInt64Max, state.duration()); EXPECT_EQ(1.0, state.actual_playback_rate()); // Paused playback @@ -495,9 +504,10 @@ TEST(MediaSessionTest, PositionState) { session->set_playback_state(kMediaSessionPlaybackStatePaused); session->mock_session_client()->WaitForSessionStateChange(); state = session->mock_session_client()->GetMediaSessionState(); - EXPECT_EQ(10 * kSbTimeSecond, - state.GetCurrentPlaybackPosition(start_time + 999 * kSbTimeSecond)); - EXPECT_EQ(kSbTimeMax, state.duration()); + EXPECT_EQ(10 * base::Time::kMicrosecondsPerSecond, + state.GetCurrentPlaybackPosition( + start_time + 999 * base::Time::kMicrosecondsPerSecond)); + EXPECT_EQ(kSbInt64Max, state.duration()); EXPECT_EQ(0.0, state.actual_playback_rate()); session->set_playback_state(kMediaSessionPlaybackStatePlaying); @@ -506,8 +516,8 @@ TEST(MediaSessionTest, PositionState) { session->SetPositionState(base::nullopt); session->mock_session_client()->WaitForSessionStateChange(); state = session->mock_session_client()->GetMediaSessionState(); - EXPECT_EQ(0, - state.GetCurrentPlaybackPosition(start_time + 999 * kSbTimeSecond)); + EXPECT_EQ(0, state.GetCurrentPlaybackPosition( + start_time + 999 * base::Time::kMicrosecondsPerSecond)); EXPECT_EQ(0, state.duration()); EXPECT_EQ(0.0, state.actual_playback_rate()); diff --git a/cobalt/network/network_module.cc b/cobalt/network/network_module.cc index e80a7daa2634..aac1e379e4fa 100644 --- a/cobalt/network/network_module.cc +++ b/cobalt/network/network_module.cc @@ -144,7 +144,7 @@ void NetworkModule::Initialize(const std::string& user_agent_string, if (command_line->HasSwitch(switches::kMaxNetworkDelay)) { base::StringToInt64( command_line->GetSwitchValueASCII(switches::kMaxNetworkDelay), - &options_.max_network_delay); + &options_.max_network_delay_usec); } #if defined(ENABLE_NETWORK_LOGGING) diff --git a/cobalt/network/network_module.h b/cobalt/network/network_module.h index 80b0179bff2c..7dbfab9ba680 100644 --- a/cobalt/network/network_module.h +++ b/cobalt/network/network_module.h @@ -76,7 +76,7 @@ class NetworkModule : public base::MessageLoop::DestructionObserver { https_requirement(network::kHTTPSRequired), cors_policy(network::kCORSRequired), preferred_language("en-US"), - max_network_delay(0), + max_network_delay_usec(0), persistent_settings(nullptr) {} net::StaticCookiePolicy::Type cookie_policy; bool ignore_certificate_errors; @@ -84,7 +84,7 @@ class NetworkModule : public base::MessageLoop::DestructionObserver { network::CORSPolicy cors_policy; std::string preferred_language; std::string custom_proxy; - SbTime max_network_delay; + int64_t max_network_delay_usec; persistent_storage::PersistentSettings* persistent_settings; storage::StorageManager::Options storage_manager_options; }; @@ -110,7 +110,9 @@ class NetworkModule : public base::MessageLoop::DestructionObserver { const std::string& preferred_language() const { return options_.preferred_language; } - SbTime max_network_delay() const { return options_.max_network_delay; } + int64_t max_network_delay_usec() const { + return options_.max_network_delay_usec; + } scoped_refptr url_request_context_getter() const { return url_request_context_getter_; } diff --git a/cobalt/renderer/backend/graphics_system_test.cc b/cobalt/renderer/backend/graphics_system_test.cc index eedee79b3d8e..3287058649a0 100644 --- a/cobalt/renderer/backend/graphics_system_test.cc +++ b/cobalt/renderer/backend/graphics_system_test.cc @@ -20,8 +20,8 @@ #include "base/optional.h" #include "cobalt/renderer/backend/default_graphics_system.h" #include "cobalt/renderer/backend/graphics_context.h" +#include "starboard/common/time.h" #include "starboard/log.h" -#include "starboard/time.h" #include "testing/gtest/include/gtest/gtest.h" namespace cobalt { @@ -43,30 +43,29 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsSystemCanBeInitializedOften) { graphics_system = CreateDefaultGraphicsSystem(); graphics_system.reset(); - SbTimeMonotonic start = SbTimeGetMonotonicNow(); + int64_t start = starboard::CurrentMonotonicTime(); for (int i = 0; i < kReferenceCount; ++i) { graphics_system = CreateDefaultGraphicsSystem(); graphics_system.reset(); } - SbTimeMonotonic time_per_initialization = - (SbTimeGetMonotonicNow() - start) / kReferenceCount; - SB_LOG(INFO) << "Measured duration " - << time_per_initialization / kSbTimeMillisecond + int64_t time_per_initialization_usec = + (starboard::CurrentMonotonicTime() - start) / kReferenceCount; + SB_LOG(INFO) << "Measured duration " << time_per_initialization_usec / 1000 << "ms per initialization."; // Graphics system initializations should not take more than the maximum of // 200ms or three times as long as the time we just measured. - SbTimeMonotonic maximum_time_per_initialization = - std::max(3 * time_per_initialization, 200 * kSbTimeMillisecond); + int64_t maximum_time_usec_per_initialization = + std::max(3 * time_per_initialization_usec, 200 * 1000); // 200ms - SbTimeMonotonic last = SbTimeGetMonotonicNow(); + int64_t last = starboard::CurrentMonotonicTime(); for (int i = 0; i < 20; ++i) { graphics_system = CreateDefaultGraphicsSystem(); graphics_system.reset(); - SbTimeMonotonic now = SbTimeGetMonotonicNow(); - SB_LOG(INFO) << "Test duration " << (now - last) / kSbTimeMillisecond - << "ms."; - ASSERT_LT(now - last, maximum_time_per_initialization); + int64_t now = starboard::CurrentMonotonicTime(); + int64_t elapsed_time_usec = now - last; + SB_LOG(INFO) << "Test duration " << elapsed_time_usec / 1000 << "ms."; + ASSERT_LT(elapsed_time_usec, maximum_time_usec_per_initialization); last = now; } } @@ -84,7 +83,7 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsContextCanBeInitializedOften) { graphics_context.reset(); graphics_system.reset(); - SbTimeMonotonic start = SbTimeGetMonotonicNow(); + int64_t start = starboard::CurrentMonotonicTime(); for (int i = 0; i < kReferenceCount; ++i) { graphics_system = CreateDefaultGraphicsSystem(); graphics_context = graphics_system->CreateGraphicsContext(); @@ -92,18 +91,17 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsContextCanBeInitializedOften) { graphics_context.reset(); graphics_system.reset(); } - SbTimeMonotonic time_per_initialization = - kSbTimeMillisecond + (SbTimeGetMonotonicNow() - start) / kReferenceCount; - SB_LOG(INFO) << "Measured duration " - << time_per_initialization / kSbTimeMillisecond + int64_t time_per_initialization_usec = + 1000 + (starboard::CurrentMonotonicTime() - start) / kReferenceCount; + SB_LOG(INFO) << "Measured duration " << time_per_initialization_usec / 1000 << "ms per initialization."; // Graphics system and context initializations should not take more than the // maximum of 200ms or three times as long as the time we just measured. - SbTimeMonotonic maximum_time_per_initialization = - std::max(3 * time_per_initialization, 200 * kSbTimeMillisecond); + int64_t maximum_time_usec_per_initialization = + std::max(3 * time_per_initialization_usec, 200 * 1000); // 200ms - SbTimeMonotonic last = SbTimeGetMonotonicNow(); + int64_t last = starboard::CurrentMonotonicTime(); for (int i = 0; i < 20; ++i) { graphics_system = CreateDefaultGraphicsSystem(); graphics_context = graphics_system->CreateGraphicsContext(); @@ -111,10 +109,10 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsContextCanBeInitializedOften) { graphics_context.reset(); graphics_system.reset(); - SbTimeMonotonic now = SbTimeGetMonotonicNow(); - SB_LOG(INFO) << "Test duration " << (now - last) / kSbTimeMillisecond - << "ms."; - ASSERT_LT(now - last, maximum_time_per_initialization); + int64_t now = starboard::CurrentMonotonicTime(); + int64_t elapsed_time_usec = now - last; + SB_LOG(INFO) << "Test duration " << elapsed_time_usec / 1000 << "ms."; + ASSERT_LT(elapsed_time_usec, maximum_time_usec_per_initialization); last = now; } } diff --git a/cobalt/renderer/rasterizer/skia/skia/src/ports/SkTime_cobalt.cc b/cobalt/renderer/rasterizer/skia/skia/src/ports/SkTime_cobalt.cc index d2739e63b6ca..834b8adfdb2e 100644 --- a/cobalt/renderer/rasterizer/skia/skia/src/ports/SkTime_cobalt.cc +++ b/cobalt/renderer/rasterizer/skia/skia/src/ports/SkTime_cobalt.cc @@ -16,7 +16,7 @@ #include "SkTime.h" #include "SkTypes.h" #include "base/time/time.h" -#include "starboard/time.h" +#include "starboard/common/time.h" // Taken from SkTime.cpp. void SkTime::DateTime::toISO8601(SkString* dst) const { @@ -51,6 +51,4 @@ void SkTime::GetDateTime(DateTime* dt) { dt->fSecond = SkToU8(exploded.second); } -double SkTime::GetNSecs() { - return SbTimeGetMonotonicNow() * kSbTimeNanosecondsPerMicrosecond; -} +double SkTime::GetNSecs() { return starboard::CurrentMonotonicTime() * 1000; } diff --git a/cobalt/renderer/sandbox/renderer_sandbox_main.cc b/cobalt/renderer/sandbox/renderer_sandbox_main.cc index 7e9a845932a5..12922a3b6d94 100644 --- a/cobalt/renderer/sandbox/renderer_sandbox_main.cc +++ b/cobalt/renderer/sandbox/renderer_sandbox_main.cc @@ -83,8 +83,7 @@ RendererSandbox::RendererSandbox() RendererSandbox* g_renderer_sandbox = NULL; void StartApplication(int argc, char** argv, const char* link, - const base::Closure& quit_closure, - SbTimeMonotonic timestamp) { + const base::Closure& quit_closure, int64_t timestamp) { DCHECK(!g_renderer_sandbox); g_renderer_sandbox = new RendererSandbox(); DCHECK(g_renderer_sandbox); diff --git a/cobalt/script/v8c/v8c.cc b/cobalt/script/v8c/v8c.cc index ed69e68004ca..918324381671 100644 --- a/cobalt/script/v8c/v8c.cc +++ b/cobalt/script/v8c/v8c.cc @@ -76,8 +76,7 @@ void SetupBindings(GlobalEnvironment* global_environment) { cobalt::script::StandaloneJavascriptRunner* g_javascript_runner = NULL; void StartApplication(int argc, char** argv, const char* /*link */, - const base::Closure& quit_closure, - SbTimeMonotonic timestamp) { + const base::Closure& quit_closure, int64_t timestamp) { DCHECK(!g_javascript_runner); g_javascript_runner = new cobalt::script::StandaloneJavascriptRunner( base::ThreadTaskRunnerHandle::Get()); diff --git a/cobalt/site/docs/codelabs/starboard_extensions/codelab.md b/cobalt/site/docs/codelabs/starboard_extensions/codelab.md index e1f8d21bcaa2..464c7c48f802 100644 --- a/cobalt/site/docs/codelabs/starboard_extensions/codelab.md +++ b/cobalt/site/docs/codelabs/starboard_extensions/codelab.md @@ -559,9 +559,9 @@ typedef struct StarboardExtensionPleasantryApi { #include +#include "starboard/common/time.h" #include "starboard/extension/pleasantry.h" #include "starboard/system.h" -#include "starboard/time.h" namespace starboard { namespace shared { @@ -577,7 +577,7 @@ const char* kFarewells[] = { }; const char* GetFarewell() { - srand (SbTimeGetNow()); + srand (starboard::CurrentPosixTime()); int pseudo_random_index = rand() % SB_ARRAY_SIZE_INT(kFarewells); return kFarewells[pseudo_random_index]; } @@ -629,7 +629,7 @@ const void* GetPleasantryApi() { + void PreloadApplication(int argc, char** argv, const char* link, const base::Closure& quit_closure, - SbTimeMonotonic timestamp) { + int64_t timestamp) { @@ -77,6 +87,14 @@ void StartApplication(int argc, char** argv, const char* link, return; } diff --git a/cobalt/speech/microphone_fake.cc b/cobalt/speech/microphone_fake.cc index b245d981645f..66f0c27556f6 100644 --- a/cobalt/speech/microphone_fake.cc +++ b/cobalt/speech/microphone_fake.cc @@ -26,7 +26,6 @@ #include "cobalt/audio/audio_file_reader.h" #include "starboard/common/file.h" #include "starboard/memory.h" -#include "starboard/time.h" namespace cobalt { namespace speech { diff --git a/cobalt/speech/sandbox/speech_sandbox_main.cc b/cobalt/speech/sandbox/speech_sandbox_main.cc index cc67b41f42b3..7b9196d14085 100644 --- a/cobalt/speech/sandbox/speech_sandbox_main.cc +++ b/cobalt/speech/sandbox/speech_sandbox_main.cc @@ -30,8 +30,7 @@ SpeechSandbox* g_speech_sandbox = NULL; // The timeout is optional. If it is not set or set to 0, the application // doesn't shut down. void StartApplication(int argc, char** argv, const char* link, - const base::Closure& quit_closure, - SbTimeMonotonic timestamp) { + const base::Closure& quit_closure, int64_t timestamp) { if (argc != 3 && argc != 2) { LOG(ERROR) << "Usage: " << argv[0] << "