Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into mediasourceattachme…
Browse files Browse the repository at this point in the history
…nt-interface
  • Loading branch information
at-ninja committed May 31, 2024
2 parents 5750095 + 6c4e2dd commit bd28366
Show file tree
Hide file tree
Showing 181 changed files with 1,174 additions and 630 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ permissions: {}
jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Install clang-format Dependencies
run: |
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
github.event.label.name == 'runtest' ||
github.event.label.name == 'on_device'
)
timeout-minutes: 10
steps:
- id: checkout
uses: kaidokert/[email protected]
Expand Down Expand Up @@ -148,6 +149,7 @@ jobs:
runs-on: [self-hosted, linux-runner]
permissions:
packages: write
timeout-minutes: 30
steps:
- name: Checkout files
uses: kaidokert/[email protected]
Expand Down Expand Up @@ -184,6 +186,7 @@ jobs:
permissions:
packages: write
runs-on: [self-hosted, linux-runner]
timeout-minutes: 30
steps:
- name: Checkout files
uses: kaidokert/[email protected]
Expand Down Expand Up @@ -231,6 +234,7 @@ jobs:
# However, dind container ends up having / folder mounted on overlay
# filesystem, whereas /__w which contains Cobalt source code is on tmpfs.
TMPDIR: /__w/_temp
timeout-minutes: 60
steps:
- name: Checkout
uses: kaidokert/[email protected]
Expand Down Expand Up @@ -367,6 +371,7 @@ jobs:
HOME: /root
COBALT_EVERGREEN_LOADER: ${{needs.initialize.outputs.evergreen_loader}}
MODULAR_BUILD: ${{ inputs.modular && 1 || 0 }}
timeout-minutes: 90
steps:
- name: Checkout
uses: kaidokert/[email protected]
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/main_win.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
github.event.label.name == 'runtest' ||
github.event.label.name == 'on_device'
)
timeout-minutes: 10
steps:
- id: Checkout
uses: kaidokert/[email protected] # Temporary version
Expand Down Expand Up @@ -133,6 +134,7 @@ jobs:
permissions:
packages: write
runs-on: windows-2019
timeout-minutes: 120
steps:
- name: Checkout files
uses: kaidokert/[email protected]
Expand Down Expand Up @@ -167,6 +169,7 @@ jobs:
platform: ${{ fromJson(needs.initialize.outputs.platforms) }}
include: ${{ fromJson(needs.initialize.outputs.includes) }}
config: [devel, debug, qa, gold]
timeout-minutes: 90
steps:
- name: Checkout
uses: kaidokert/[email protected]
Expand Down Expand Up @@ -204,6 +207,7 @@ jobs:
include: ${{ fromJson(needs.initialize.outputs.includes) }}
env:
MODULAR_BUILD: ${{ inputs.modular && 1 || 0 }}
timeout-minutes: 90
steps:
- name: Checkout
uses: kaidokert/[email protected]
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
python-version: ['3.8', '3.11']
fail-fast: false
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
- name: Checkout
uses: kaidokert/[email protected]
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
# Needed to publish results and get a badge (see publish_results below).
id-token: write

timeout-minutes: 15
steps:
- name: "Checkout code"
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion base/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "starboard/file.h"
#include "starboard/system.h"
typedef SbFile FileHandle;
typedef SbMutex MutexHandle;
typedef pthread_mutex_t MutexHandle;
#else
#if BUILDFLAG(IS_WIN)
#include <io.h>
Expand Down
9 changes: 9 additions & 0 deletions base/synchronization/condition_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@
#include "base/synchronization/lock.h"

#if defined(STARBOARD)
#if SB_API_VERSION < 16
#include "starboard/condition_variable.h"
#else
#include <pthread.h>
#endif // SB_API_VERSION < 16
#else
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#include <pthread.h>
#endif
Expand Down Expand Up @@ -118,8 +122,13 @@ class BASE_EXPORT ConditionVariable {

private:
#if defined(STARBOARD)
#if SB_API_VERSION < 16
SbConditionVariable condition_;
SbMutex* user_mutex_;
#else
pthread_cond_t condition_;
pthread_mutex_t* user_mutex_;
#endif // SB_API_VERSION < 16
#elif BUILDFLAG(IS_WIN)
CHROME_CONDITION_VARIABLE cv_;
const raw_ptr<CHROME_SRWLOCK> srwlock_;
Expand Down
54 changes: 53 additions & 1 deletion base/synchronization/condition_variable_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,34 @@ ConditionVariable::ConditionVariable(Lock* user_lock)
user_lock_(user_lock)
#endif
{
#if SB_API_VERSION < 16
bool result = SbConditionVariableCreate(&condition_, user_mutex_);
DCHECK(result);
#else
#if !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT)
pthread_condattr_t attribute;
pthread_condattr_init(&attribute);
pthread_condattr_setclock(&attribute, CLOCK_MONOTONIC);

int result = pthread_cond_init(&condition_, &attribute);
DCHECK(result == 0);

pthread_condattr_destroy(&attribute);
#else
int result = pthread_cond_init(&condition_, nullptr);
DCHECK(result == 0);
#endif // !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT)
#endif // SB_API_VERSION < 16
}

ConditionVariable::~ConditionVariable() {
#if SB_API_VERSION < 16
bool result = SbConditionVariableDestroy(&condition_);
DCHECK(result);
#else
int result = pthread_cond_destroy(&condition_);
DCHECK(result == 0);
#endif // SB_API_VERSION < 16
}

void ConditionVariable::Wait() {
Expand All @@ -48,9 +69,14 @@ void ConditionVariable::Wait() {
#if DCHECK_IS_ON()
user_lock_->CheckHeldAndUnmark();
#endif
SbConditionVariableResult result =
#if SB_API_VERSION < 16
SbConditionVariableResult result =
SbConditionVariableWait(&condition_, user_mutex_);
DCHECK(SbConditionVariableIsSignaled(result));
#else
int result = pthread_cond_wait(&condition_, user_mutex_);
DCHECK(result == 0);
#endif // SB_API_VERSION < 16
#if DCHECK_IS_ON()
user_lock_->CheckUnheldAndMark();
#endif
Expand All @@ -66,22 +92,48 @@ void ConditionVariable::TimedWait(const TimeDelta& max_time) {
#if DCHECK_IS_ON()
user_lock_->CheckHeldAndUnmark();
#endif
#if SB_API_VERSION < 16
SbConditionVariableResult result =
SbConditionVariableWaitTimed(&condition_, user_mutex_, duration);
DCHECK_NE(kSbConditionVariableFailed, result);
#else
#if !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT)
int64_t timeout_time_usec = starboard::CurrentMonotonicTime();
#else
int64_t timeout_time_usec = starboard::CurrentPosixTime();
#endif // !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT)
timeout_time_usec += max_time.InMicroseconds();

struct timespec timeout;
timeout.tv_sec = timeout_time_usec / 1000'000;
timeout.tv_nsec = (timeout_time_usec % 1000'000) * 1000;

int result = pthread_cond_timedwait(&condition_, user_mutex_, &timeout);
DCHECK(result == 0 || result == ETIMEDOUT);
#endif
#if DCHECK_IS_ON()
user_lock_->CheckUnheldAndMark();
#endif
}

void ConditionVariable::Broadcast() {
#if SB_API_VERSION < 16
bool result = SbConditionVariableBroadcast(&condition_);
DCHECK(result);
#else
int result = pthread_cond_broadcast(&condition_);
DCHECK(result == 0);
#endif // SB_API_VERSION < 16
}

void ConditionVariable::Signal() {
#if SB_API_VERSION < 16
bool result = SbConditionVariableSignal(&condition_);
DCHECK(result);
#else
int result = pthread_cond_signal(&condition_);
DCHECK(result == 0);
#endif // SB_API_VERSION < 16
}

} // namespace base
18 changes: 18 additions & 0 deletions base/synchronization/lock_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#include "build/build_config.h"

#if defined(STARBOARD)
#if SB_API_VERSION < 16
#include "starboard/common/mutex.h"
#else
#include <pthread.h>
#endif
#include "base/check_op.h"
#elif BUILDFLAG(IS_WIN)
#include "base/win/windows_types.h"
Expand Down Expand Up @@ -49,7 +53,11 @@ class BASE_EXPORT LockImpl {
friend class base::win::internal::ScopedHandleVerifier;

#if defined(STARBOARD)
#if SB_API_VERSION < 16
using NativeHandle = SbMutex;
#else
using NativeHandle = pthread_mutex_t;
#endif // SB_API_VERSION < 16
#elif BUILDFLAG(IS_WIN)
using NativeHandle = CHROME_SRWLOCK;
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
Expand Down Expand Up @@ -100,14 +108,24 @@ void LockImpl::Lock() {

#if defined(STARBOARD)
bool LockImpl::Try() {
#if SB_API_VERSION < 16
SbMutexResult result = SbMutexAcquireTry(&native_handle_);
DCHECK_NE(kSbMutexDestroyed, result);
return SbMutexIsSuccess(result);
#else
int result = pthread_mutex_trylock(&native_handle_);
return result == 0;
#endif // SB_API_VERSION < 16
}

void LockImpl::Unlock() {
#if SB_API_VERSION < 16
bool result = SbMutexRelease(&native_handle_);
DCHECK(result);
#else
int result = pthread_mutex_unlock(&native_handle_);
DCHECK(result == 0);
#endif //SB_API_VERSION < 16
}
#elif BUILDFLAG(IS_WIN)
bool LockImpl::Try() {
Expand Down
20 changes: 19 additions & 1 deletion base/synchronization/lock_impl_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,42 @@
#include "base/synchronization/lock_impl.h"

#include "base/check_op.h"
#include "starboard/common/mutex.h"

#if SB_API_VERSION < 16
#include "starboard/mutex.h"
#endif // SB_API_VERSION < 16

namespace base {
namespace internal {

LockImpl::LockImpl() {
#if SB_API_VERSION < 16
bool result = SbMutexCreate(&native_handle_);
DCHECK(result);
#else
int result = pthread_mutex_init(&native_handle_, nullptr);
DCHECK_EQ(result, 0);
#endif // SB_API_VERSION < 16
}

LockImpl::~LockImpl() {
#if SB_API_VERSION < 16
bool result = SbMutexDestroy(&native_handle_);
DCHECK(result);
#else
int result = pthread_mutex_destroy(&native_handle_);
DCHECK_EQ(result, 0);
#endif // SB_API_VERSION < 16
}

void LockImpl::LockInternal() {
#if SB_API_VERSION < 16
SbMutexResult result = SbMutexAcquire(&native_handle_);
DCHECK_NE(kSbMutexDestroyed, result);
#else
int result = pthread_mutex_lock(&native_handle_);
DCHECK_EQ(result, 0);
#endif // SB_API_VERSION < 16
}

} // namespace internal
Expand Down
9 changes: 4 additions & 5 deletions chrome/updater/unzipper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "starboard/common/time.h"
#include "third_party/zlib/google/zip.h"

namespace cobalt {
Expand All @@ -25,10 +24,10 @@ class UnzipperImpl : public update_client::Unzipper {
void Unzip(const base::FilePath& zip_path,
const base::FilePath& output_path,
UnzipCompleteCallback callback) override {
int64_t time_before_unzip = starboard::CurrentMonotonicTime();
int64_t time_before_unzip = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
std::move(callback).Run(zip::Unzip(zip_path, output_path));
int64_t time_unzip_took_usec =
starboard::CurrentMonotonicTime() - time_before_unzip;
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - time_before_unzip;
LOG(INFO) << "Unzip file path = " << zip_path;
LOG(INFO) << "output_path = " << output_path;
LOG(INFO) << "Unzip took "
Expand All @@ -39,10 +38,10 @@ class UnzipperImpl : public update_client::Unzipper {
#if defined(IN_MEMORY_UPDATES)
void Unzip(const std::string& zip_str, const base::FilePath& output_path,
UnzipCompleteCallback callback) override {
int64_t time_before_unzip = starboard::CurrentMonotonicTime();
int64_t time_before_unzip = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
std::move(callback).Run(zip::Unzip(zip_str, output_path));
int64_t time_unzip_took_usec =
starboard::CurrentMonotonicTime() - time_before_unzip;
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - time_before_unzip;
LOG(INFO) << "Unzip from string";
LOG(INFO) << "output_path = " << output_path;
LOG(INFO) << "Unzip took "
Expand Down
1 change: 0 additions & 1 deletion cobalt/base/localized_strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/optional.h"
#include "starboard/common/file.h"
#include "starboard/system.h"
#include "starboard/types.h"

Expand Down
7 changes: 3 additions & 4 deletions cobalt/bindings/testing/date_bindings_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#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"
Expand Down Expand Up @@ -79,7 +78,7 @@ TEST_F(DateBindingsTest, PosixEpoch) {
EvaluateScript("Date.now();", &result);
auto js_now_ms = std::stoll(result);
auto posix_now_ms =
starboard::CurrentPosixTime() / base::Time::kMicrosecondsPerMillisecond;
(base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds();
EXPECT_LT(std::abs(posix_now_ms - js_now_ms), 1000);
}

Expand All @@ -106,8 +105,8 @@ TEST_F(DateBindingsTest, StarboardTimeZone) {
}

TEST_F(DateBindingsTest, TimezoneOffset) {
EzTimeT ezttnow = static_cast<EzTimeT>(starboard::CurrentPosixTime() /
base::Time::kMicrosecondsPerSecond);
EzTimeT ezttnow = static_cast<EzTimeT>(
(base::Time::Now() - base::Time::UnixEpoch()).InSeconds());
EzTimeExploded ez_exploded_local;
EzTimeTExplodeLocal(&ezttnow, &ez_exploded_local);
// ez_exploded_local is already local time, use UTC method to convert to
Expand Down
Loading

0 comments on commit bd28366

Please sign in to comment.