Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
briantting committed Apr 30, 2024
2 parents 4f3733f + c21f78e commit 235899e
Show file tree
Hide file tree
Showing 24 changed files with 225 additions and 77 deletions.
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ files: |
starboard|
tools/metrics/actions/cobalt|
tools/metrics/histograms/metadata/cobalt|
tools/testing|
)/
| ^[^/]+$ # files in the root
)
Expand Down Expand Up @@ -176,7 +175,7 @@ repos:
pass_filenames: false
always_run: true
stages: [push]
args: [-m, unittest, tools/download_from_gcs_test.py]
args: [-m, unittest, cobalt/tools/download_from_gcs_test.py]
- id: test-python3-compatibility
name: Test Python 3 Compatibility
description: Checks that scripts can be run in Python 3
Expand Down
20 changes: 20 additions & 0 deletions cobalt/media/base/sbplayer_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "base/compiler_specific.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/trace_event/trace_event.h"
#include "cobalt/base/statistics.h"
#include "cobalt/media/base/format_support_query_metrics.h"
Expand Down Expand Up @@ -273,6 +274,7 @@ SbPlayerBridge::SbPlayerBridge(
}
if (video_config.IsValidConfig()) {
UpdateVideoConfig(video_config, video_mime_type);
SendColorSpaceHistogram();
}

output_mode_ = ComputeSbPlayerOutputMode(default_output_mode);
Expand Down Expand Up @@ -1360,5 +1362,23 @@ void SbPlayerBridge::LogStartupLatency() const {
// clang-format on
}

void SbPlayerBridge::SendColorSpaceHistogram() const {
using base::UmaHistogramEnumeration;

const auto& cs_info = video_config_.color_space_info();

if (video_stream_info_.color_metadata.bits_per_channel > 8) {
UmaHistogramEnumeration("Cobalt.Media.HDR.Primaries", cs_info.primaries);
UmaHistogramEnumeration("Cobalt.Media.HDR.Transfer", cs_info.transfer);
UmaHistogramEnumeration("Cobalt.Media.HDR.Matrix", cs_info.matrix);
UmaHistogramEnumeration("Cobalt.Media.HDR.Range", cs_info.range);
} else {
UmaHistogramEnumeration("Cobalt.Media.SDR.Primaries", cs_info.primaries);
UmaHistogramEnumeration("Cobalt.Media.SDR.Transfer", cs_info.transfer);
UmaHistogramEnumeration("Cobalt.Media.SDR.Matrix", cs_info.matrix);
UmaHistogramEnumeration("Cobalt.Media.SDR.Range", cs_info.range);
}
}

} // namespace media
} // namespace cobalt
1 change: 1 addition & 0 deletions cobalt/media/base/sbplayer_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class SbPlayerBridge {
SbPlayerOutputMode default_output_mode) const;

void LogStartupLatency() const;
void SendColorSpaceHistogram() const;

// The following variables are initialized in the ctor and never changed.
#if SB_HAS(PLAYER_WITH_URL)
Expand Down
2 changes: 1 addition & 1 deletion cobalt/media/testing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import("//cobalt/media/testing/data/sha1_files.gni")
action("cobalt_media_download_test_data") {
install_content = true

script = "//tools/download_from_gcs.py"
script = "//cobalt/tools/download_from_gcs.py"

sha_sources = []
foreach(sha1_file, sha1_files) {
Expand Down
2 changes: 1 addition & 1 deletion cobalt/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ copy("renderer_copy_lottie_test_data") {
action("renderer_download_lottie_test_data") {
install_content = true

script = "//tools/download_from_gcs.py"
script = "//cobalt/tools/download_from_gcs.py"

inputs = [
"$_lottie_resource_path/finger_print-expected.png.sha1",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import tempfile
import unittest

from tools import download_from_gcs
from cobalt.tools import download_from_gcs

_BUCKET = 'chromium-clang-format'
_HASH_FILE_EXT = '.sha1'
Expand Down
2 changes: 1 addition & 1 deletion components/crx_file/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if (is_starboard) {
action("crx_file_download_test_data") {
install_content = true

script = "//tools/download_from_gcs.py"
script = "//cobalt/tools/download_from_gcs.py"

sha_sources = []
foreach(sha1_file, sha1_files) {
Expand Down
2 changes: 1 addition & 1 deletion download_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
except ImportError:
import urllib2 as urllib

from tools import download_from_gcs
from cobalt.tools import download_from_gcs


def DownloadGerritCommitMsgHook(force=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ TEST(PosixConditionVariableWaitTest, SunnyDayAutoInit) {
PTHREAD_MUTEX_INITIALIZER,
PTHREAD_COND_INITIALIZER};
// Start the thread.
SbThread thread =
SbThreadCreate(0, kSbThreadNoPriority, kSbThreadNoAffinity, true, NULL,
posix::TakeThenSignalEntryPoint, &context);
pthread_t thread = 0;
pthread_create(&thread, NULL, posix::TakeThenSignalEntryPoint, &context);

EXPECT_EQ(pthread_mutex_lock(&context.mutex), 0);

Expand All @@ -65,7 +64,7 @@ TEST(PosixConditionVariableWaitTest, SunnyDayAutoInit) {
EXPECT_EQ(pthread_mutex_unlock(&context.mutex), 0);

// Now we wait for the thread to exit.
EXPECT_TRUE(SbThreadJoin(thread, NULL));
EXPECT_TRUE(pthread_join(thread, NULL) == 0);
EXPECT_EQ(pthread_cond_destroy(&context.condition), 0);
EXPECT_EQ(pthread_mutex_destroy(&context.mutex), 0);
}
Expand All @@ -74,10 +73,9 @@ TEST(PosixConditionVariableWaitTest, SunnyDay) {
const int kMany = kSbMaxThreads > 64 ? 64 : kSbMaxThreads;
posix::WaiterContext context;

std::vector<SbThread> threads(kMany);
std::vector<pthread_t> threads(kMany);
for (int i = 0; i < kMany; ++i) {
threads[i] = SbThreadCreate(0, kSbThreadNoPriority, kSbThreadNoAffinity,
true, NULL, posix::WaiterEntryPoint, &context);
pthread_create(&threads[i], NULL, posix::WaiterEntryPoint, &context);
}

for (int i = 0; i < kMany; ++i) {
Expand All @@ -89,7 +87,8 @@ TEST(PosixConditionVariableWaitTest, SunnyDay) {

// Now we wait for the threads to exit.
for (int i = 0; i < kMany; ++i) {
EXPECT_TRUE(SbThreadJoin(threads[i], NULL)) << "thread = " << threads[i];
EXPECT_TRUE(pthread_join(threads[i], NULL) == 0)
<< "thread = " << threads[i];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ struct timespec CalculateDelayTimestamp(int64_t delay, bool use_monotonic) {
void DoSunnyDay(posix::TakeThenSignalContext* context,
bool check_timeout,
bool use_monotonic) {
SbThread thread =
SbThreadCreate(0, kSbThreadNoPriority, kSbThreadNoAffinity, true, NULL,
posix::TakeThenSignalEntryPoint, context);
pthread_t thread = 0;
pthread_create(&thread, NULL, posix::TakeThenSignalEntryPoint, context);

const int64_t kDelayUs = 10'000; // 10ms
// Allow two-millisecond-level precision.
Expand Down Expand Up @@ -156,7 +155,7 @@ void DoSunnyDay(posix::TakeThenSignalContext* context,
}

// Now we wait for the thread to exit.
EXPECT_TRUE(SbThreadJoin(thread, NULL));
EXPECT_TRUE(pthread_join(thread, NULL) == 0);
EXPECT_EQ(pthread_cond_destroy(&context->condition), 0);
EXPECT_EQ(pthread_mutex_destroy(&context->mutex), 0);
}
Expand Down Expand Up @@ -212,9 +211,8 @@ TEST(PosixConditionVariableWaitTimedTest, FLAKY_SunnyDayNearMaxTime) {
EXPECT_EQ(pthread_mutex_init(&context.mutex, NULL), 0);

InitCondition(&context.condition, false /* use_monotonic */);
SbThread thread =
SbThreadCreate(0, kSbThreadNoPriority, kSbThreadNoAffinity, true, NULL,
posix::TakeThenSignalEntryPoint, &context);
pthread_t thread = 0;
pthread_create(&thread, NULL, posix::TakeThenSignalEntryPoint, &context);

EXPECT_EQ(pthread_mutex_lock(&context.mutex), 0);

Expand Down Expand Up @@ -243,7 +241,7 @@ TEST(PosixConditionVariableWaitTimedTest, FLAKY_SunnyDayNearMaxTime) {
EXPECT_EQ(pthread_mutex_unlock(&context.mutex), 0);

// Now we wait for the thread to exit.
EXPECT_TRUE(SbThreadJoin(thread, NULL));
EXPECT_TRUE(pthread_join(thread, NULL) == 0);
EXPECT_EQ(pthread_cond_destroy(&context.condition), 0);
EXPECT_EQ(pthread_mutex_destroy(&context.mutex), 0);
}
Expand Down
7 changes: 3 additions & 4 deletions starboard/nplb/posix_compliance/posix_mutex_acquire_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ TEST(PosixMutexAcquireTest, SunnyDayContended) {
TestContext context;
EXPECT_EQ(pthread_mutex_init(&context.mutex, NULL), 0);
const int kThreads = 4;
SbThread threads[kThreads];
pthread_t threads[kThreads];
for (int i = 0; i < kThreads; ++i) {
threads[i] = SbThreadCreate(0, kSbThreadNoPriority, kSbThreadNoAffinity,
true, NULL, EntryPoint, &context);
pthread_create(&threads[i], NULL, EntryPoint, &context);
}

for (int i = 0; i < kLoops; ++i) {
Expand All @@ -64,7 +63,7 @@ TEST(PosixMutexAcquireTest, SunnyDayContended) {

// Join other threads and clean up.
for (int i = 0; i < kThreads; ++i) {
EXPECT_TRUE(SbThreadJoin(threads[i], NULL));
EXPECT_TRUE(pthread_join(threads[i], NULL) == 0);
}
EXPECT_EQ(pthread_mutex_destroy(&context.mutex), 0);
EXPECT_EQ(0, context.count);
Expand Down
11 changes: 5 additions & 6 deletions starboard/nplb/posix_compliance/posix_mutex_acquire_try_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct TestContext {
};

void* EntryPoint(void* parameter) {
pthread_setname_np(pthread_self(), nplb::kThreadName);
TestContext* context = static_cast<TestContext*>(parameter);
context->was_locked_ = (pthread_mutex_trylock(context->mutex_) == 0);
return NULL;
Expand Down Expand Up @@ -60,13 +61,11 @@ TEST(PosixMutexAcquireTryTest, RainyDayReentrant) {
EXPECT_EQ(pthread_mutex_trylock(&mutex), 0);

TestContext context(&mutex);
// TODO: Migrate to pthread_create when available.
SbThread thread =
SbThreadCreate(0, kSbThreadNoPriority, kSbThreadNoAffinity, true,
nplb::kThreadName, &EntryPoint, &context);
pthread_t thread = 0;
pthread_create(&thread, NULL, &EntryPoint, &context);

EXPECT_TRUE(SbThreadIsValid(thread));
EXPECT_TRUE(SbThreadJoin(thread, NULL));
EXPECT_TRUE(thread != 0);
EXPECT_TRUE(pthread_join(thread, NULL) == 0);
EXPECT_FALSE(context.was_locked_);
EXPECT_EQ(pthread_mutex_unlock(&mutex), 0);
EXPECT_EQ(pthread_mutex_destroy(&mutex), 0);
Expand Down
10 changes: 5 additions & 5 deletions starboard/nplb/posix_compliance/posix_once_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ struct RunPosixOnceContext {
};

void* RunPosixOnceEntryPoint(void* context) {
pthread_setname_np(pthread_self(), posix::kThreadName);

RunPosixOnceContext* run_sbonce_context =
reinterpret_cast<RunPosixOnceContext*>(context);

Expand All @@ -98,7 +100,7 @@ void* RunPosixOnceEntryPoint(void* context) {
// initialization routine got called exactly one time.
TEST(PosixOnceTest, SunnyDayMultipleThreadsInit) {
const int kMany = kSbMaxThreads;
std::vector<SbThread> threads(kMany);
std::vector<pthread_t> threads(kMany);

const int kIterationCount = 10;
for (int i = 0; i < kIterationCount; ++i) {
Expand All @@ -107,9 +109,7 @@ TEST(PosixOnceTest, SunnyDayMultipleThreadsInit) {

s_global_value = 0;
for (int j = 0; j < kMany; ++j) {
threads[j] =
SbThreadCreate(0, kSbThreadNoPriority, kSbThreadNoAffinity, true,
posix::kThreadName, RunPosixOnceEntryPoint, &context);
pthread_create(&threads[j], NULL, RunPosixOnceEntryPoint, &context);
}

// Wait for all threads to finish initializing and become ready, then
Expand All @@ -127,7 +127,7 @@ TEST(PosixOnceTest, SunnyDayMultipleThreadsInit) {
// Signal threads to beginWait for all threads to complete.
for (int i = 0; i < kMany; ++i) {
void* result;
SbThreadJoin(threads[i], &result);
pthread_join(threads[i], &result);
}

EXPECT_EQ(s_global_value, 1);
Expand Down
12 changes: 7 additions & 5 deletions starboard/nplb/posix_compliance/posix_socket_send_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// this is hooked up to something.

#include <fcntl.h>
#include <pthread.h>
#include <unistd.h>
#include "starboard/nplb/posix_compliance/posix_socket_helpers.h"
#include "starboard/thread.h"
Expand All @@ -40,6 +41,8 @@ void* PosixSocketSendToServerSocketEntryPoint(void* trio_as_void_ptr) {
char* send_buf = new char[kBufSize];
memset(send_buf, 0, kBufSize);

pthread_setname_np(pthread_self(), "SendToTest");

// Continue sending to the socket until it fails to send. It's expected that
// SbSocketSendTo will fail when the server socket closes, but the application
// should not terminate.
Expand Down Expand Up @@ -95,17 +98,16 @@ TEST(PosixSocketSendTest, RainyDaySendToClosedSocket) {

// Start a thread to write to the client socket.
const bool kJoinable = true;
SbThread send_thread =
SbThreadCreate(0, kSbThreadNoPriority, kSbThreadNoAffinity, kJoinable,
"SendToTest", PosixSocketSendToServerSocketEntryPoint,
static_cast<void*>(&trio_as_void_ptr));
pthread_t send_thread = 0;
pthread_create(&send_thread, NULL, PosixSocketSendToServerSocketEntryPoint,
static_cast<void*>(&trio_as_void_ptr));

// Close the client, which should cause writes to the server socket to fail.
EXPECT_TRUE(close(client_socket_fd) == 0);

// Wait for the thread to exit and check the last socket error.
void* thread_result;
EXPECT_TRUE(SbThreadJoin(send_thread, &thread_result));
EXPECT_TRUE(pthread_join(send_thread, &thread_result) == 0);

// TODO: errno: EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno
// == EPIPE);
Expand Down
12 changes: 7 additions & 5 deletions starboard/nplb/posix_compliance/posix_socket_sendto_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// this is hooked up to something.

#include <fcntl.h>
#include <pthread.h>
#include <unistd.h>

#include "starboard/nplb/posix_compliance/posix_socket_helpers.h"
Expand All @@ -41,6 +42,8 @@ void* PosixSocketSendToServerSocketEntryPoint(void* trio_as_void_ptr) {
char* send_buf = new char[kBufSize];
memset(send_buf, 0, kBufSize);

pthread_setname_np(pthread_self(), "SendToTest");

// Continue sending to the socket until it fails to send. It's expected that
// SbSocketSendTo will fail when the server socket closes, but the application
// should not terminate.
Expand Down Expand Up @@ -98,17 +101,16 @@ TEST(PosixSocketSendtoTest, RainyDaySendToClosedSocket) {

// Start a thread to write to the client socket.
const bool kJoinable = true;
SbThread send_thread =
SbThreadCreate(0, kSbThreadNoPriority, kSbThreadNoAffinity, kJoinable,
"SendToTest", PosixSocketSendToServerSocketEntryPoint,
static_cast<void*>(&trio_as_void_ptr));
pthread_t send_thread = 0;
pthread_create(&send_thread, NULL, PosixSocketSendToServerSocketEntryPoint,
static_cast<void*>(&trio_as_void_ptr));

// Close the client, which should cause writes to the server socket to fail.
EXPECT_TRUE(close(client_socket_fd) == 0);

// Wait for the thread to exit and check the last socket error.
void* thread_result;
EXPECT_TRUE(SbThreadJoin(send_thread, &thread_result));
EXPECT_TRUE(pthread_join(send_thread, &thread_result) == 0);

// TODO: errno: EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno
// == EPIPE);
Expand Down
Loading

0 comments on commit 235899e

Please sign in to comment.