-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry pick PR #1663: [android] Support KEY_MAX_INPUT_SIZE configurab…
…le from the webapp (#2314) Refer to the original PR: #1663 1. Add HTMLVideoElement.setMaxVideoInputSize(max_video_input_size) to allow the web app to explicitly set the maximum size in bytes of a buffer of data for video described by android MediaFormat. 2. If the setting value is 0, it uses the default value. 3. This uses the SbThreadLocal to store max_video_input_size, which allows each player to acquire its input size from webapp. 4. This implementation includes setting max_video_input_size per player, i.e., each player can configure its max_video_input_size. b/176923480 Co-authored-by: Bo-Rong Chen <[email protected]>
- Loading branch information
1 parent
54ff8b9
commit 5902022
Showing
40 changed files
with
630 additions
and
79 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
cobalt/demos/content/configure-max-video-input-size/configure-max-video-input-size.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
98 changes: 98 additions & 0 deletions
98
cobalt/demos/content/configure-max-video-input-size/configure-max-video-input-size.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.