Skip to content

Commit

Permalink
Merge branch 'main' into xb1
Browse files Browse the repository at this point in the history
  • Loading branch information
isarkis authored Jan 30, 2024
2 parents e73887e + 18ebe18 commit d1663fc
Show file tree
Hide file tree
Showing 2,856 changed files with 116,045 additions and 84,940 deletions.
14 changes: 7 additions & 7 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
/tools/metrics/ @joeltine

# Temporary monitoring for merges to Chromium upstreams
/base/ @andrewsavage1
/build/ @andrewsavage1
/crypto/ @andrewsavage1
/net/ @andrewsavage1
/third_party/abseil-cpp/ @andrewsavage1
/third_party/modp_b64/ @andrewsavage1
/url/ @andrewsavage1
/base/ @andrewsavage1 @youtube/cobalt-3p-repository-owners
/build/ @andrewsavage1 @youtube/cobalt-3p-repository-owners
/crypto/ @andrewsavage1 @youtube/cobalt-3p-repository-owners
/net/ @andrewsavage1 @youtube/cobalt-3p-repository-owners
/third_party/abseil-cpp/ @andrewsavage1 @youtube/cobalt-3p-repository-owners
/third_party/modp_b64/ @andrewsavage1 @youtube/cobalt-3p-repository-owners
/url/ @andrewsavage1 @youtube/cobalt-3p-repository-owners
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
steps:
- uses: kaidokert/[email protected]
timeout-minutes: 30
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11
java-version: 17
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3 #v1.0.6
- name: Build with Gradle
Expand Down
1 change: 0 additions & 1 deletion base/time/time_now_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "base/time/time_override.h"
#include "build/build_config.h"

#include "starboard/client_porting/poem/eztime_poem.h"
#include "starboard/common/log.h"
#include "starboard/common/time.h"
#include "starboard/types.h"
Expand Down
1 change: 0 additions & 1 deletion cobalt/build/cobalt_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def GetTestTargets(self):
'overlay_info_test',
'persistent_settings_test',
'png_utils_test',
'poem_unittests',
'js_profiler_test',
'renderer_test',
'render_tree_test',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<!--
| Copyright 2024 The Cobalt Authors. All Rights Reserved.
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
-->

<html>
<head>
<title>Configure Max Video Input Size</title>
<style>
body {
background-color: #0f0;
}
video {
height: 240px;
width: 426px;
}
</style>
</head>
<body>
<script type="text/javascript" src="configure-max-video-input-size.js"></script>
<div id="ui-layer">
<div class="item">
<video id="video1"></video>
</div>
<div class="item">
<video id="video2" muted="1" style="background-color: #4285F4">
</video>
</div>
</div>
<br>
<div id="status"></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright 2024 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

var audioData;
var videoData;

let status_div;

function downloadMediaData(downloadedCallback) {
var xhr = new XMLHttpRequest;

xhr.onload = function() {
audioData = xhr.response;
console.log("Downloaded " + audioData.byteLength + " of audio data.");

xhr.onload = function() {
videoData = xhr.response;
console.log("Downloaded " + videoData.byteLength + " of video data.");
downloadedCallback();
}

xhr.open("GET", "vp9-720p.webm", true);
xhr.send();
}

xhr.open("GET", "dash-audio.mp4", true);
xhr.responseType = "arraybuffer";
xhr.send();
}

function playVideoOn(videoElement) {
var ms = new MediaSource;
ms.addEventListener('sourceopen', function() {
console.log("Creating SourceBuffer objects.");
var audioBuffer = ms.addSourceBuffer('audio/mp4; codecs="mp4a.40.2"');
var videoBuffer = ms.addSourceBuffer('video/webm; codecs="vp9"');
audioBuffer.addEventListener("updateend", function() {
audioBuffer.abort();
videoBuffer.addEventListener("updateend", function() {
setTimeout(function() {
videoBuffer.addEventListener("updateend", function() {
videoBuffer.abort();
ms.endOfStream();
videoElement.ontimeupdate = function() {
if (videoElement.currentTime > 10) {
console.log("Stop playback.");
videoElement.src = '';
videoElement.load();
videoElement.ontimeupdate = null;
}
}
console.log("Start playback.");
videoElement.play();
});
videoBuffer.appendBuffer(videoData.slice(1024));
}, 5000);
});
videoBuffer.appendBuffer(videoData.slice(0, 1024));
});
audioBuffer.appendBuffer(audioData);
});

console.log("Attaching MediaSource to video element.");
videoElement.src = URL.createObjectURL(ms);
}

function setupPlayerHandler() {
// Setup one primary player and one sub player.
// i = 0: primary player, buffer size is 3110500
// i = 1: sub player, buffer size is 777000
const maxVideoInputSizes = [3110500, 777000];
videoElements = document.getElementsByTagName('video');
status_div = document.getElementById('status');
status_div.innerHTML += 'Video Get Element By Id...<br>';
for(let i = 0; i < maxVideoInputSizes.length; i++) {
if (videoElements[i].setMaxVideoInputSize && i < videoElements.length) {
videoElements[i].setMaxVideoInputSize(maxVideoInputSizes[i]);
status_div.innerHTML += 'Set Max Video Input Size of Video Element '+ i + ' to '+ maxVideoInputSizes[i] + '<br>';
}
if (i == 1 && videoElements[i].setMaxVideoCapabilities) {
videoElements[i].setMaxVideoCapabilities("width=1920; height=1080");
}
playVideoOn(videoElements[i]);
}
}

downloadMediaData(setupPlayerHandler);
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions cobalt/dom/html_media_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ bool OriginIsSafe(loader::RequestMode request_mode, const GURL& resource_url,

HTMLMediaElement::HTMLMediaElement(Document* document, base::Token tag_name)
: HTMLElement(document, tag_name),
max_video_input_size_(0),
load_state_(kWaitingForSource),
ALLOW_THIS_IN_INITIALIZER_LIST(event_queue_(this)),
playback_rate_(1.f),
Expand Down Expand Up @@ -1665,6 +1666,10 @@ std::string HTMLMediaElement::MaxVideoCapabilities() const {
return max_video_capabilities_;
}

int HTMLMediaElement::MaxVideoInputSize() const {
return max_video_input_size_;
}

bool HTMLMediaElement::PreferDecodeToTexture() {
TRACE_EVENT0("cobalt::dom", "HTMLMediaElement::PreferDecodeToTexture()");

Expand Down Expand Up @@ -1760,5 +1765,20 @@ void HTMLMediaElement::SetMaxVideoCapabilities(
max_video_capabilities_ = max_video_capabilities;
}

void HTMLMediaElement::SetMaxVideoInputSize(
unsigned int max_video_input_size,
script::ExceptionState* exception_state) {
if (GetAttribute("src").value_or("").length() > 0) {
LOG(WARNING) << "Cannot set max_video_input_size after src is defined.";
web::DOMException::Raise(web::DOMException::kInvalidStateErr,
exception_state);
return;
}

LOG(INFO) << "max_video_input_size is changed from " << max_video_input_size_
<< " to " << max_video_input_size;
max_video_input_size_ = static_cast<int>(max_video_input_size);
}

} // namespace dom
} // namespace cobalt
7 changes: 7 additions & 0 deletions cobalt/dom/html_media_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class HTMLMediaElement : public HTMLElement,
return !max_video_capabilities_.empty();
}

// Set max video input size.
void SetMaxVideoInputSize(unsigned int max_video_input_size,
script::ExceptionState* exception_state);

DEFINE_WRAPPABLE_TYPE(HTMLMediaElement);
void TraceMembers(script::Tracer* tracer) override;

Expand Down Expand Up @@ -240,6 +244,7 @@ class HTMLMediaElement : public HTMLElement,
void SourceOpened(ChunkDemuxer* chunk_demuxer) override;
std::string SourceURL() const override;
std::string MaxVideoCapabilities() const override;
int MaxVideoInputSize() const override;
bool PreferDecodeToTexture() override;
void EncryptedMediaInitDataEncountered(
const char* init_data_type, const unsigned char* init_data,
Expand All @@ -252,6 +257,8 @@ class HTMLMediaElement : public HTMLElement,

std::string max_video_capabilities_;

int max_video_input_size_;

// Loading state.
enum LoadState { kWaitingForSource, kLoadingFromSrcAttr };
LoadState load_state_;
Expand Down
8 changes: 8 additions & 0 deletions cobalt/dom/html_video_element.idl
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ interface HTMLVideoElement : HTMLMediaElement {
// is the same as the format for the string passed in to
// HTMLMediaElement.canPlayType().
[RaisesException] void setMaxVideoCapabilities(DOMString max_video_capabilities);

// Non standard interface (b/176923480). Set the maximum size in bytes of an
// input buffer for video. This communicates to the platform that the size of
// a single input buffer will not exceed the size passed in this function.
// This function must be called before the src attribute is set on the element,
// otherwise an INVALID_STATE_ERR exception is raised. Use default buffer size
// if set to 0.
[RaisesException] void setMaxVideoInputSize(unsigned long maxVideoInputSize);
};
41 changes: 21 additions & 20 deletions cobalt/media/base/cval_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,40 @@

#include <numeric>

#include "starboard/common/time.h"

namespace cobalt {
namespace media {

CValContainer::CValContainer(std::string name,
int max_samples_before_calculation)
: cval_name_{name},
max_samples_before_calculation_{max_samples_before_calculation},
latest_{"Media." + name + ".Latest", 0, "Latest sample in microseconds."},
average_{"Media." + name + ".Average", 0,
"Average sample in microseconds."},
maximum_{"Media." + name + ".Maximum", 0,
"Maximum sample in microseconds."},
median_{"Media." + name + ".Median", 0, "Median sample in microseconds."},
minimum_{"Media." + name + ".Minimum", 0,
"Minimum sample in microseconds."} {}

void CValContainer::UpdateCVal(int64_t event_time_usec) {
latest_ = event_time_usec;
latest_{
"Media." + name + ".Latest", {}, "Latest sample in microseconds."},
average_{
"Media." + name + ".Average", {}, "Average sample in microseconds."},
maximum_{
"Media." + name + ".Maximum", {}, "Maximum sample in microseconds."},
median_{
"Media." + name + ".Median", {}, "Median sample in microseconds."},
minimum_{
"Media." + name + ".Minimum", {}, "Minimum sample in microseconds."} {
}

void CValContainer::UpdateCVal(TimeDelta event_time) {
latest_ = event_time;
accumulated_sample_count_++;

if (!first_sample_added_) {
minimum_ = event_time_usec;
maximum_ = event_time_usec;
minimum_ = event_time;
maximum_ = event_time;
first_sample_added_ = true;
}

samples_[sample_write_index_] = event_time_usec;
samples_[sample_write_index_] = event_time;
sample_write_index_ = (sample_write_index_ + 1) % kMaxSamples;

if (accumulated_sample_count_ % max_samples_before_calculation_ == 0) {
std::vector<int64_t> copy;
std::vector<TimeDelta> copy;
int copy_size = std::min(accumulated_sample_count_, kMaxSamples);
copy.reserve(copy_size);
copy.assign(samples_, samples_ + copy_size);
Expand All @@ -62,7 +63,7 @@ void CValContainer::UpdateCVal(int64_t event_time_usec) {
minimum_ = std::min(minimum_.value(), copy[0]);
maximum_ = std::max(maximum_.value(), copy[copy.size() - 1]);

auto local_average = std::accumulate(copy.begin(), copy.end(), 0);
auto local_average = std::accumulate(copy.begin(), copy.end(), TimeDelta());
average_ += (local_average - average_.value()) / accumulated_sample_count_;
}
}
Expand Down Expand Up @@ -90,7 +91,7 @@ void CValStats::StartTimer(MediaTiming event_type,
if (!enabled_) return;

running_timers_[std::make_pair(event_type, pipeline_identifier)] =
starboard::CurrentMonotonicTime();
Time::Now();
}

void CValStats::StopTimer(MediaTiming event_type,
Expand All @@ -100,7 +101,7 @@ void CValStats::StopTimer(MediaTiming event_type,
auto key = std::make_pair(event_type, pipeline_identifier);
DCHECK(running_timers_.find(key) != running_timers_.end());

int64_t time_taken = starboard::CurrentMonotonicTime() - running_timers_[key];
TimeDelta time_taken = Time::Now() - running_timers_[key];
auto cval_container = cval_containers_.find(event_type);
if (cval_container != cval_containers_.end()) {
cval_container->second.UpdateCVal(time_taken);
Expand Down
Loading

0 comments on commit d1663fc

Please sign in to comment.