-
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.
[android] Support KEY_MAX_INPUT_SIZE configurable from the webapp
1. Add an h5vcc setting "Media.MaxInputSize" to allow the web app to explicitly set the MediaFormat.KEY_MAX_INPUT_SIZE. 2. This can also be set via MIME attribute "maxinputsize". 3. Use -1 for default value. It the setting value is smaller than default value, it will be ignored. b/176923480
- Loading branch information
Showing
29 changed files
with
289 additions
and
24 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
cobalt/demos/content/configure-max-input-size/configure-max-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 2023 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 Input Size</title> | ||
<style> | ||
body { | ||
background-color: #0f0; | ||
} | ||
video { | ||
height: 240px; | ||
width: 426px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<script type="text/javascript" src="configure-max-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> |
91 changes: 91 additions & 0 deletions
91
cobalt/demos/content/configure-max-input-size/configure-max-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,91 @@ | ||
// Copyright 2023 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 nextVideoElementIndex = 0; | ||
var audioData; | ||
var videoData; | ||
|
||
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 setupKeyHandler() { | ||
const maxInputSizes = [3110500, 777000]; | ||
videoElements = document.getElementsByTagName('video'); | ||
for(let i = 0; i < videoElements.length; i++) { | ||
if (videoElements[i].setMaxInputSize && i < maxInputSizes.length) { | ||
videoElements[i].setMaxInputSize(maxInputSizes[i]); | ||
} | ||
if (i != 0 && videoElements[i].setMaxVideoCapabilities) { | ||
videoElements[i].setMaxVideoCapabilities("width=1920; height=1080"); | ||
} | ||
playVideoOn(videoElements[i]); | ||
} | ||
} | ||
|
||
downloadMediaData(setupKeyHandler); |
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.