Skip to content

Commit

Permalink
Deprecate SbTime APIs (partial)
Browse files Browse the repository at this point in the history
- Replace usages of SbTime in multiple directories

b/302733082

Test-On-Device: true
  • Loading branch information
gbournou committed Jan 7, 2024
1 parent 98da637 commit 4bdf3b3
Show file tree
Hide file tree
Showing 230 changed files with 1,241 additions and 1,184 deletions.
2 changes: 1 addition & 1 deletion starboard/common/condition_variable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void ConditionVariable::Wait() const {
mutex_->debugSetAcquired();
}

bool ConditionVariable::WaitTimed(SbTime duration) const {
bool ConditionVariable::WaitTimed(int64_t duration) const {
mutex_->debugSetReleased();
bool was_signaled = SbConditionVariableIsSignaled(
SbConditionVariableWaitTimed(&condition_, mutex_->mutex(), duration));
Expand Down
6 changes: 3 additions & 3 deletions starboard/common/condition_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "starboard/common/mutex.h"
#include "starboard/condition_variable.h"
#include "starboard/time.h"
#include "starboard/types.h"

namespace starboard {
Expand All @@ -39,8 +38,9 @@ class ConditionVariable {

// Returns |true| if this condition variable was signaled. Otherwise |false|
// means that the condition variable timed out. In either case the
// mutex has been re-acquired once this function returns.
bool WaitTimed(SbTime duration) const;
// mutex has been re-acquired once this function returns. The |duration| is
// microseconds.
bool WaitTimed(int64_t duration) const;

void Broadcast() const;
void Signal() const;
Expand Down
1 change: 0 additions & 1 deletion starboard/common/experimental/concurrency_debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "starboard/atomic.h"
#include "starboard/common/log.h"
#include "starboard/common/mutex.h"
#include "starboard/shared/posix/time_internal.h"
#include "starboard/system.h"

namespace starboard {
Expand Down
1 change: 0 additions & 1 deletion starboard/common/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "starboard/common/string.h"
#include "starboard/system.h"
#include "starboard/thread.h"
#include "starboard/time.h"

namespace starboard {
namespace logging {
Expand Down
14 changes: 7 additions & 7 deletions starboard/common/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

#include "starboard/common/condition_variable.h"
#include "starboard/common/mutex.h"
#include "starboard/common/time.h"
#include "starboard/export.h"
#include "starboard/time.h"
#include "starboard/types.h"

namespace starboard {
Expand Down Expand Up @@ -76,19 +76,19 @@ class Queue {
}

// Gets the item at the front of the queue, blocking until there is such an
// item, or the given timeout duration expires, or the queue is woken up. If
// there are multiple waiters, this Queue guarantees that only one waiter will
// receive any given queue item.
T GetTimed(SbTime duration) {
// item, or the given timeout duration (in microseconds) expires, or the queue
// is woken up. If there are multiple waiters, this Queue guarantees that only
// one waiter will receive any given queue item.
T GetTimed(int64_t duration) {
ScopedLock lock(mutex_);
SbTimeMonotonic start = SbTimeGetMonotonicNow();
int64_t start = CurrentMonotonicTime();
while (queue_.empty()) {
if (wake_) {
wake_ = false;
return T();
}

SbTimeMonotonic elapsed = SbTimeGetMonotonicNow() - start;
int64_t elapsed = CurrentMonotonicTime() - start;
if (elapsed >= duration) {
return T();
}
Expand Down
1 change: 0 additions & 1 deletion starboard/common/recursive_mutex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "starboard/common/recursive_mutex.h"
#include "starboard/common/log.h"
#include "starboard/time.h"

namespace starboard {

Expand Down
7 changes: 4 additions & 3 deletions starboard/common/semaphore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "starboard/common/semaphore.h"
#include "starboard/common/time.h"

namespace starboard {

Expand Down Expand Up @@ -46,14 +47,14 @@ bool Semaphore::TakeTry() {
return true;
}

bool Semaphore::TakeWait(SbTime wait_us) {
bool Semaphore::TakeWait(int64_t wait_us) {
if (wait_us <= 0) {
return TakeTry();
}
SbTime expire_time = SbTimeGetMonotonicNow() + wait_us;
int64_t expire_time = CurrentMonotonicTime() + wait_us;
ScopedLock lock(mutex_);
while (permits_ <= 0) {
SbTime remaining_wait_time = expire_time - SbTimeGetMonotonicNow();
int64_t remaining_wait_time = expire_time - CurrentMonotonicTime();
if (remaining_wait_time <= 0) {
return false; // Timed out.
}
Expand Down
5 changes: 2 additions & 3 deletions starboard/common/semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "starboard/common/condition_variable.h"
#include "starboard/common/mutex.h"
#include "starboard/configuration.h"
#include "starboard/time.h"

namespace starboard {

Expand All @@ -43,9 +42,9 @@ class Semaphore {
// is returned then the effects are the same as if Take() had been invoked.
bool TakeTry();

// Same as Take(), but will wait at most, wait_us microseconds.
// Same as Take(), but will wait at most |wait_us| microseconds.
// Returns |false| if the semaphore timed out, |true| otherwise.
bool TakeWait(SbTime wait_us);
bool TakeWait(int64_t wait_us);

private:
Mutex mutex_;
Expand Down
2 changes: 1 addition & 1 deletion starboard/common/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool Socket::SetSendBufferSize(int32_t size) {
return SbSocketSetSendBufferSize(socket_, size);
}

bool Socket::SetTcpKeepAlive(bool value, SbTime period) {
bool Socket::SetTcpKeepAlive(bool value, int64_t period) {
return SbSocketSetTcpKeepAlive(socket_, value, period);
}

Expand Down
2 changes: 1 addition & 1 deletion starboard/common/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Socket {
bool SetReuseAddress(bool value);
bool SetReceiveBufferSize(int32_t size);
bool SetSendBufferSize(int32_t size);
bool SetTcpKeepAlive(bool value, SbTime period);
bool SetTcpKeepAlive(bool value, int64_t period); // period in microseconds.
bool SetTcpNoDelay(bool value);
bool SetTcpWindowScaling(bool value);
bool JoinMulticastGroup(const SbSocketAddress* address);
Expand Down
6 changes: 3 additions & 3 deletions starboard/common/thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ void Thread::Start(const Options& options) {
SB_DCHECK(d_->thread_ != kSbThreadInvalid);
}

void Thread::Sleep(SbTime microseconds) {
void Thread::Sleep(int64_t microseconds) {
SbThreadSleep(microseconds);
}

void Thread::SleepMilliseconds(int value) {
return Sleep(value * kSbTimeMillisecond);
return Sleep(static_cast<int64_t>(value) * 1000);
}

bool Thread::WaitForJoin(SbTime timeout) {
bool Thread::WaitForJoin(int64_t timeout) {
bool joined = d_->join_sema_.TakeWait(timeout);
if (joined) {
SB_DCHECK(d_->join_called_.load());
Expand Down
5 changes: 2 additions & 3 deletions starboard/common/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "starboard/common/scoped_ptr.h"
#include "starboard/configuration.h"
#include "starboard/thread.h"
#include "starboard/time.h"
#include "starboard/types.h"

namespace starboard {
Expand Down Expand Up @@ -65,12 +64,12 @@ class Thread {

protected:
static void* ThreadEntryPoint(void* context);
static void Sleep(SbTime microseconds);
static void Sleep(int64_t microseconds);
static void SleepMilliseconds(int value);

// Waits at most |timeout| microseconds for Join() to be called. If
// Join() was called then return |true|, else |false|.
bool WaitForJoin(SbTime timeout);
bool WaitForJoin(int64_t timeout);
Semaphore* join_sema();
atomic_bool* joined_bool();

Expand Down
7 changes: 3 additions & 4 deletions starboard/condition_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include "starboard/export.h"
#include "starboard/mutex.h"
#include "starboard/time.h"
#include "starboard/types.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -96,13 +95,13 @@ SbConditionVariableWait(SbConditionVariable* condition, SbMutex* mutex);
// undefined if |mutex| is not held.
//
// |timeout_duration|: The maximum amount of time that function should wait
// for |condition|. If the |timeout_duration| value is less than or equal to
// zero, the function returns as quickly as possible with a
// for |condition|, in microseconds. If the |timeout_duration| value is less
// than or equal to zero, the function returns as quickly as possible with a
// kSbConditionVariableTimedOut result.
SB_EXPORT SbConditionVariableResult
SbConditionVariableWaitTimed(SbConditionVariable* condition,
SbMutex* mutex,
SbTime timeout_duration);
int64_t timeout_duration);

// Broadcasts to all current waiters of |condition| to stop waiting. This
// function wakes all of the threads waiting on |condition| while
Expand Down
5 changes: 0 additions & 5 deletions starboard/doc/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ the guidelines follow thusly as follows.
casting the handle back and forth to the pointer type.
* If a word in the name of a type is redundant with the module name, it is
omitted.
* A monotonic time type in the Time module is `SbTimeMonotonic`, not
~~`SbMonotonicTime`, `SbTimeMonotonicTime`, or
`SbTimeMonotonicSbTime`~~.

### Functions

Expand Down Expand Up @@ -188,10 +185,8 @@ namespace at the starboard repository root.
* After the `k`, all constants have `Sb`, the Starboard namespace.
* `kSb`
* After `kSb`, all constants then have the module name.
* `kSbTime`
* `kSbFile`
* After `kSb<module>` comes the rest of the name of the constant.
* `kSbTimeMillisecond`
* `kSbFileInvalid`
* Enum entries are prefixed with the full name of the enum.
* The enum `SbSystemDeviceType` contains entries like
Expand Down
8 changes: 4 additions & 4 deletions starboard/elf_loader/elf_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "starboard/atomic.h"
#include "starboard/common/log.h"
#include "starboard/common/paths.h"
#include "starboard/common/time.h"
#include "starboard/configuration_constants.h"
#include "starboard/elf_loader/elf_loader_impl.h"
#include "starboard/elf_loader/evergreen_config.h"
Expand Down Expand Up @@ -78,12 +79,11 @@ bool ElfLoader::Load(const std::string& library_path,
EvergreenConfig::Create(library_path_.c_str(), content_path_.c_str(),
custom_get_extension);
SB_LOG(INFO) << "evergreen_config: content_path=" << content_path_;
SbTime start_time = SbTimeGetMonotonicNow();
int64_t start_time = CurrentMonotonicTime();
bool res = impl_->Load(library_path_.c_str(), use_compression,
use_memory_mapped_file);
SbTime end_time = SbTimeGetMonotonicNow();
SB_LOG(INFO) << "Loading took: "
<< (end_time - start_time) / kSbTimeMillisecond << " ms";
int64_t end_time = CurrentMonotonicTime();
SB_LOG(INFO) << "Loading took: " << (end_time - start_time) / 1000 << " ms";
return res;
}

Expand Down
4 changes: 1 addition & 3 deletions starboard/elf_loader/exported_symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,10 @@ ExportedSymbols::ExportedSymbols() {
REGISTER_SYMBOL(SbThreadSetName);
REGISTER_SYMBOL(SbThreadSleep);
REGISTER_SYMBOL(SbThreadYield);
REGISTER_SYMBOL(SbTimeGetMonotonicNow);
#if SB_API_VERSION < 16
REGISTER_SYMBOL(SbTimeGetMonotonicNow);
REGISTER_SYMBOL(SbTimeGetMonotonicThreadNow);
#endif // SB_API_VERSION < 16
REGISTER_SYMBOL(SbTimeGetNow);
#if SB_API_VERSION < 16
REGISTER_SYMBOL(SbTimeIsTimeThreadNowSupported);
#endif // SB_API_VERSION < 16
REGISTER_SYMBOL(SbTimeZoneGetCurrent);
Expand Down
5 changes: 2 additions & 3 deletions starboard/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@

#include "starboard/configuration.h"
#include "starboard/export.h"
#include "starboard/time.h"
#include "starboard/types.h"
#include "starboard/window.h"

Expand Down Expand Up @@ -302,7 +301,7 @@ typedef enum SbEventType {
// Structure representing a Starboard event and its data.
typedef struct SbEvent {
SbEventType type;
SbTimeMonotonic timestamp;
int64_t timestamp; // Monotonic time in microseconds.
void* data;
} SbEvent;

Expand Down Expand Up @@ -377,7 +376,7 @@ SB_IMPORT void SbEventHandle(const SbEvent* event);
// possible.
SB_EXPORT SbEventId SbEventSchedule(SbEventCallback callback,
void* context,
SbTime delay);
int64_t delay);

// Cancels the specified |event_id|. Note that this function is a no-op
// if the event already fired. This function can be safely called from any
Expand Down
17 changes: 8 additions & 9 deletions starboard/extension/demuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include <stdint.h>
#include <string.h>

#include "starboard/time.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -284,9 +282,9 @@ typedef struct CobaltExtensionDemuxerBuffer {
// Number of elements in |side_data|.
int64_t side_data_elements;
// Playback time in microseconds.
SbTime pts;
int64_t pts;
// Duration of this buffer in microseconds.
SbTime duration;
int64_t duration;
// True if this buffer contains a keyframe.
bool is_keyframe;
// Signifies the end of the stream. If this is true, the other fields will be
Expand All @@ -310,15 +308,16 @@ typedef struct CobaltExtensionDemuxer {
// fail.
CobaltExtensionDemuxerStatus (*Initialize)(void* user_data);

CobaltExtensionDemuxerStatus (*Seek)(SbTime seek_time, void* user_data);
CobaltExtensionDemuxerStatus (*Seek)(int64_t seek_time, void* user_data);

// Returns the starting time for the media file; it is always positive.
SbTime (*GetStartTime)(void* user_data);
// Returns the starting time -- in microseconds since Windows epoch -- for the
// media file; it is always positive.
int64_t (*GetStartTime)(void* user_data);

// Returns the time -- in microseconds since Windows epoch -- represented by
// presentation timestamp 0. If the timestamps are not associated with a time,
// returns 0.
SbTime (*GetTimelineOffset)(void* user_data);
int64_t (*GetTimelineOffset)(void* user_data);

// Calls |read_cb| with a buffer of type |type| and the user data provided by
// |read_cb_user_data|. |read_cb| is a synchronous function, so the data
Expand Down Expand Up @@ -346,7 +345,7 @@ typedef struct CobaltExtensionDemuxer {
void* user_data);

// Returns the duration, in microseconds.
SbTime (*GetDuration)(void* user_data);
int64_t (*GetDuration)(void* user_data);

// Will be passed to all functions.
void* user_data;
Expand Down
7 changes: 3 additions & 4 deletions starboard/extension/enhanced_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "starboard/drm.h"
#include "starboard/media.h"
#include "starboard/player.h"
#include "starboard/time.h"
#include "starboard/types.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -48,8 +47,8 @@ typedef struct CobaltExtensionEnhancedAudioMediaAudioStreamInfo {
// comment of `SbMediaAudioSampleInfo` in `media.h` for more details.
typedef struct CobaltExtensionEnhancedAudioMediaAudioSampleInfo {
CobaltExtensionEnhancedAudioMediaAudioStreamInfo stream_info;
SbTime discarded_duration_from_front;
SbTime discarded_duration_from_back;
int64_t discarded_duration_from_front; // in microseconds.
int64_t discarded_duration_from_back; // in microseconds.
} CobaltExtensionEnhancedAudioMediaAudioSampleInfo;

// The structure has the same binary layout as `SbMediaVideoStreamInfo` in the
Expand Down Expand Up @@ -82,7 +81,7 @@ typedef struct CobaltExtensionEnhancedAudioPlayerSampleInfo {
SbMediaType type;
const void* buffer;
int buffer_size;
SbTime timestamp;
int64_t timestamp; // Microseconds since Windows epoch UTC.
SbPlayerSampleSideData* side_data;
int side_data_count;
union {
Expand Down
Loading

0 comments on commit 4bdf3b3

Please sign in to comment.