├── .gitignore
├── .gitmodules
├── .npmignore
├── LICENSE
├── LICENSE-VP8
├── Makefile
├── README.md
├── badge.svg
├── benchmarks
├── benchmark.build.js
├── benchmark.js
├── index.html
└── style.css
├── build-templates
├── OGVVideoDecoder.js
└── jsvpx.js
├── builds
├── jsvpx.js
└── ogv-decoder-video-vp8.js
├── examples
├── media
│ └── Curiosity's_Seven_Minutes_of_Terror.ogv.240p.webm
└── ogv-simple
│ └── index.html
├── package.json
├── test
├── browser-tests.build.js
├── browser-tests.js
├── compare-hashes.js
├── index.html
├── test-vector-list.js
└── test.js
├── util
└── c_utils.js
├── vp8
├── common
│ ├── blockd.js
│ ├── coefupdateprobs.js
│ ├── default_coef_probs.js
│ ├── entropy.js
│ ├── entropymode.js
│ ├── entropymv.js
│ ├── filter.js
│ ├── findnearmv.js
│ ├── idctllm.js
│ ├── loopfilter_filters.js
│ ├── modecont.js
│ ├── mv.js
│ ├── onyxc_int.js
│ ├── quant_common.js
│ ├── reconinter.js
│ ├── reconintra.js
│ ├── reconintra4x4.js
│ ├── setupintrarecon.js
│ ├── vp8_entropymodedata.js
│ └── vp8_loopfilter.js
├── decoder
│ ├── dboolhuff.js
│ ├── decodeframe.js
│ ├── decodemv.js
│ ├── detokenize.js
│ ├── onyxc_int.js
│ ├── onyxd_if.js
│ ├── onyxd_int.js
│ └── treereader.js
└── vp8_js_iface.js
├── vpx
├── vpx_codec.js
├── vpx_decoder.js
└── vpx_image.js
├── vpx_dsp
└── bitreader.js
└── webpack.config.js
/.gitignore:
--------------------------------------------------------------------------------
1 | nbproject
2 | node_modules
3 | builds
4 | examples/ogv-simple/dist
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "vp8-test-vectors"]
2 | path = vp8-test-vectors
3 | url = https://github.com/webmproject/vp8-test-vectors.git
4 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | benchmarks
2 | build-templates
3 | output-vectors
4 | test
5 | examples
6 | vp8-test-vectors
7 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 jscodec
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/LICENSE-VP8:
--------------------------------------------------------------------------------
1 | Copyright (c) 2010, The WebM Project authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in
12 | the documentation and/or other materials provided with the
13 | distribution.
14 |
15 | * Neither the name of Google, nor the WebM Project, nor the names
16 | of its contributors may be used to endorse or promote products
17 | derived from this software without specific prior written
18 | permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | examples : examples/ogv-simple/index.html
2 | rm -rf ogv-simple/dist
3 | cp -R node_modules/ogv/dist examples/ogv-simple
4 | cp builds/ogv-decoder-video-vp8.js examples/ogv-simple/dist
5 |
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # jsvpx
2 |
3 | jsvpx is a full implementation of libvpx in Javascript. In contrast to other crosscompiled decoders, jsvpx is fully written in Javascript.
4 |
5 | The reason for a full reimplementation as opposed to a simple cross compile, is because video decoding computation is very repetative, and as of now, cross compiled modules can only be single threaded. The project is still in early stages, but now ready to expore multithreading options including WebWorkers or WebGL, possible SIMD, even though it may only work for FireFox (at least for the near future).
6 |
7 | ## Project Status
8 | Vp8 is now working! Still in experimental stages. Output hashes finally match the vp8 test vectors.
9 | Now working on figuring out a few speed issues.
10 |
11 | Works best in Safari.
12 |
13 | Check out a running demo on ogv.js:
14 | http://jscodec.com/ogv-example/#file=Curiosity's_Seven_Minutes_of_Terror.ogv&size=360p.webm
15 |
16 | Based of code from John Koleszar's dixie libvpx branch : https://github.com/webmproject/libvpx/tree/dixie/vpx ,
17 | and Dominik Homberger's : https://github.com/dominikhlbg/vp8-webm-javascript-decoder.
18 |
19 |
20 | Currently moving towards the direction of the main branch.
21 |
22 | Looking to try some interesting things with webworkers, or perhaps some GPU.
23 |
24 | ### ChangeLog
25 | * v0.0.2
26 | * Added browser unit tests in test folder : http://jscodec.com/jsvpx-tests/
27 | * Added comprehensive benchmark tool : http://jscodec.com/jsvpx-benchmark/
28 | * Various Bug Fixes
29 | * Better memory handling
30 | * Improved dequantization
31 |
32 | ### Current TODO
33 | * Figure out whats causing the slow parts, (Probably splitmode prediction)
34 | * Start testing out some webworkers
35 | * Lots of code cleaning to do
36 |
37 | ### Future Planned Work
38 | * Frame corruption/interpolation for missing frames
39 | * Vp9
40 | * Finish filling this out...
41 |
42 | ## Usage
43 |
44 | ### Installation
45 | Make sure to have npm, and git installed. Clone repository, then use:
46 |
47 | For npm modules:
48 | ```
49 | npm install
50 | ```
51 |
52 | To pull all git modules:
53 | ``` git submodule update --init ```
54 |
55 | To Build simply use:
56 | ``` npm run-script build ```
57 |
58 |
59 |
60 | ### Validation
61 | To validate, use
62 |
63 | `npm run-script test`
64 |
65 |
66 | ### API
67 | The main api is written to closely resemble the C style api of the original libvpx library. In the build-templates folder, you can find various templates for other API's and builds.
68 |
69 | #### jsvpx api
70 | This is the simplest most, most user friendly api. It's usage is more like the traditional javascript api.
71 | ```javascript
72 | var decoder = new jsvpx();
73 | var rawFrame = decoder.decode(compressedFrame);
74 |
75 | if(rawFrame){
76 | //do something with it
77 | }
78 | ```
79 |
80 | ##### jsvpx api demos:
81 | Running on Dominik's **vp8-webm-javascript-decoder:**
82 |
83 | Link to source using jsvpx:
84 |
85 | https://github.com/brianxautumn/vp8-webm-javascript-decoder/tree/JsVpx
86 |
87 | Link to live demo:
88 |
89 | http://jscodec.com/vp8-webm-javascript-decoder/vpxdec.html
90 |
91 |
92 |
93 | #### ogv.js
94 |
95 | * To try with ogv, simply copy ogv-decoder-video-vp8 out of the builds directory and paste it over the generated one.
--------------------------------------------------------------------------------
/badge.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | tests
14 | tests
15 | 1574/1574
16 | 1574/1574
17 |
18 |
19 |
--------------------------------------------------------------------------------
/benchmarks/benchmark.js:
--------------------------------------------------------------------------------
1 | google.charts.load('current', {packages: ['corechart', 'bar']});
2 | var testVectors = require('../test/test-vector-list.js');
3 |
4 | var select = $('#vector-select');
5 | for(var val in testVectors) {
6 | $(' ', {value: val, text: testVectors[val]}).appendTo(select);
7 | }
8 |
9 |
10 | var _ = require('lodash');
11 | var process = require('process');
12 | var Benchmark = require('benchmark');
13 |
14 | var blankFormat = {
15 | videoFormat: {
16 | cropLeft: null,
17 | cropTop: null,
18 | cropWidth: null,
19 | cropHeight: null,
20 | displayWidth: null,
21 | displayHeight: null
22 | }
23 | };
24 |
25 | var Benchmark = require('benchmark');
26 | Benchmark = Benchmark.runInContext({_: _, process: process});
27 | window.Benchmark = Benchmark;
28 |
29 | var emscriptenDecoder = new OGVDecoderVideoVP8(blankFormat);
30 | emscriptenDecoder.init(function () {});
31 |
32 | var ivf = require('jsivf');
33 | var jsvpx = require('../build-templates/OgVVideoDecoder.js');
34 |
35 | var benchmarkOptions = {
36 | maxTime: 1000000,
37 | async: true
38 | };
39 |
40 |
41 | var suite = new Benchmark.Suite(benchmarkOptions);
42 | var vectorFolder = '../vp8-test-vectors/';
43 | var compressedFrames = [];
44 | window.comprehensiveTestFrames = [];
45 |
46 |
47 |
48 | var decoder = new jsvpx(blankFormat);
49 |
50 |
51 | document.getElementById('run').onclick = function () {
52 | console.log("Starting Experiments");
53 | //document.getElementById('gear').style.display = 'block';
54 |
55 | $("#gear").show("slow", function () {
56 | //loadVector(0);
57 | $("#results").hide("slow", function () {
58 | comprehensiveTestFrames = []; //todo: make this not suck and preload vectors
59 | loadVector(select.val());
60 | });
61 | });
62 |
63 | };
64 |
65 | function loadVector(vectorNumber) {
66 |
67 |
68 |
69 | var file = testVectors[vectorNumber];
70 | var vectorLoader = new XMLHttpRequest();
71 | vectorLoader.open("GET", vectorFolder + file, true);
72 | vectorLoader.responseType = "arraybuffer";
73 |
74 | vectorLoader.onload = function (event) {
75 | //demux all the frames and append them to the compressed Frames array
76 | var demuxer = new ivf();
77 |
78 | demuxer.receiveBuffer(vectorLoader.response);
79 | demuxer.parseHeader();
80 |
81 | for (var i = 0; i < demuxer.frameCount; i++) {
82 | comprehensiveTestFrames.push(demuxer.processFrame());
83 | }
84 |
85 | suite.run();
86 | };
87 |
88 | vectorLoader.send(null);
89 | }
90 |
91 | suite.add("JsVpx", function () {
92 |
93 | for (var i = 0; i < comprehensiveTestFrames.length; i++) {
94 |
95 | decoder.processFrame(comprehensiveTestFrames[i], function () {});
96 |
97 | }
98 |
99 | });
100 |
101 | suite.add("Emscripten", function () {
102 |
103 | for (var i = 0; i < comprehensiveTestFrames.length; i++) {
104 | emscriptenDecoder.processFrame(comprehensiveTestFrames[i], function () {});
105 | }
106 |
107 | });
108 |
109 | suite.on('complete', function () {
110 | var benchTest1 = this[0];
111 | var benchTest2 = this[1];
112 | $("#gear").hide("slow", function () {
113 | document.getElementById('mean1').innerHTML = benchTest1.stats.mean.toFixed(3) + "ms";
114 | document.getElementById('error1').innerHTML = "±" + benchTest1.stats.moe.toFixed(2) + "%";
115 | document.getElementById('stderror1').innerHTML = benchTest1.stats.sem.toFixed(3) + "ms";
116 | document.getElementById('variance1').innerHTML = benchTest1.stats.variance.toFixed(3) + "ms";
117 | document.getElementById('deviation1').innerHTML = benchTest1.stats.deviation.toFixed(3) + "ms";
118 | document.getElementById('change').innerHTML = (benchTest1.stats.mean / benchTest2.stats.mean ).toFixed(3);
119 |
120 | document.getElementById('mean2').innerHTML = benchTest2.stats.mean.toFixed(3) + "ms";
121 | document.getElementById('error2').innerHTML = "±" + benchTest2.stats.moe.toFixed(2) + "%";
122 | document.getElementById('stderror2').innerHTML = benchTest2.stats.sem.toFixed(3) + "ms";
123 | document.getElementById('variance2').innerHTML = benchTest2.stats.variance.toFixed(3) + "ms";
124 | document.getElementById('deviation2').innerHTML = benchTest2.stats.deviation.toFixed(3) + "ms";
125 | $("#results").show("slow", function () {
126 |
127 | });
128 | });
129 | console.warn(decoder.frameBuffer);
130 | console.warn(emscriptenDecoder.frameBuffer);
131 | console.warn(this);
132 | if (benchTest1.aborted)
133 | console.warn(benchTest1.error.stack);
134 |
135 | updateChart(this[0], this[1]);
136 |
137 | });
138 |
139 | function updateChart(bench1, bench2) {
140 | var options = {
141 | title: "JsVpx vs Emscripten",
142 | //width: 600,
143 | height: 400,
144 | bar: {groupWidth: "95%"},
145 | legend: {position: "none"},
146 | vAxis:{
147 | minValue : 0
148 | }
149 | };
150 |
151 | var data = google.visualization.arrayToDataTable([
152 | ['Decoder', 'Avg Time', {role: 'style'}],
153 | ['JsVpx', bench1.stats.mean, 'red'],
154 | ['Emscripten', bench2.stats.mean, 'silver']
155 |
156 | ]);
157 | var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
158 | chart.draw(data, options);
159 | }
--------------------------------------------------------------------------------
/benchmarks/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Jsvpx Benchmarks
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
jsvpx
22 |
benchmark tool
23 |
24 |
25 |
26 |
27 |
28 |
29 | Run Benchmark
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | Jsvpx
50 |
51 |
52 |
53 |
54 |
55 | Mean
56 |
57 |
58 |
59 |
60 | Margin of Error
61 |
62 |
63 |
64 |
65 |
66 | Standard Error
67 |
68 |
69 |
70 |
71 |
72 | Variance
73 |
74 |
75 |
76 |
77 |
78 | Deviation
79 |
80 |
81 |
82 |
83 |
84 | Ratio
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 | Emscripten
95 |
96 |
97 |
98 |
99 |
100 | Mean
101 |
102 |
103 |
104 |
105 | Margin of Error
106 |
107 |
108 |
109 |
110 |
111 | Standard Error
112 |
113 |
114 |
115 |
116 |
117 | Variance
118 |
119 |
120 |
121 |
122 |
123 | Deviation
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
--------------------------------------------------------------------------------
/benchmarks/style.css:
--------------------------------------------------------------------------------
1 | .home{
2 | background-color: #F27127;
3 | border-width: 0 0 2px 0;
4 | border-style: solid;
5 | border-color: #2a2a2a;
6 | }
7 |
8 | .text-center{
9 | textalign:center;
10 | }
11 |
12 | .jumbotron{
13 | background:transparent;
14 | }
15 |
16 | .top{
17 | background-color: #F27127;
18 | }
19 |
20 | section{
21 | padding : 100px 0;
22 | }
23 |
24 | .controls{
25 | background-color: #2a2a2a;
26 | }
27 |
28 | #gear{
29 | font-size : 150px;
30 | display: none;
31 | }
32 |
33 | .result-title{
34 | font-weight: bolder;
35 | font-size: 20px;
36 | }
37 |
38 | .result-value{
39 | font-size: 20px;
40 | }
41 |
42 | @-webkit-keyframes spin {
43 | from {
44 | -webkit-transform: rotate(0deg);
45 | }
46 | to {
47 | -webkit-transform: rotate(360deg);
48 | }
49 | }
50 |
51 | #gear {
52 |
53 | -webkit-animation-name: spin;
54 | -webkit-animation-iteration-count: infinite;
55 | -webkit-animation-timing-function: linear;
56 | -webkit-animation-duration: 3s;
57 | }
58 | /**********************************
59 | * BUTTONS
60 | **********************************/
61 |
62 |
63 | .btn-outline{
64 | display: inline-block;
65 | background: #f6f6f6;
66 | margin: 15px 0;
67 | padding: 5px;
68 | border-radius: 4px;
69 | }
70 |
71 | .btn-flare{
72 | transition: all 0.3s ease;
73 | background: #F27127;
74 | border-color: #F27127;
75 | color: #2a2a2a;
76 | font-weight: bold;
77 | font-size: 36px;
78 | padding: 10px 32px;
79 | white-space: normal;
80 | }
81 |
82 | .btn-flare:hover{
83 | background: #2a2a2a;
84 | border-color: #2a2a2a;
85 | color: #F27127;
86 | }
87 |
88 | .btn-flare-light{
89 | transition: all 0.3s ease;
90 | background: white;
91 | border-color: white;
92 | color: #2a2a2a;
93 | font-weight: bold;
94 | font-size: 36px;
95 | padding: 10px 32px;
96 | white-space: normal;
97 | }
98 |
99 | .btn-flare-light:hover{
100 | background: #2a2a2a;
101 | border-color: white;
102 | color: white;
103 | }
104 |
105 |
106 | #vector-select-wrap{
107 | display:block;
108 | }
109 |
110 | #vector-select{
111 |
112 | }
--------------------------------------------------------------------------------
/build-templates/OGVVideoDecoder.js:
--------------------------------------------------------------------------------
1 | var jsvpx = require('../vpx/vpx_decoder.js');
2 |
3 | var vpx_codec = require('../vpx/vpx_codec.js');
4 | var vpx_codec_ctx_t = vpx_codec.vpx_codec_ctx_t;
5 |
6 |
7 | var getTimestamp;
8 | if (typeof performance === 'undefined' || typeof performance.now === 'undefined') {
9 | getTimestamp = Date.now;
10 | } else {
11 | getTimestamp = performance.now.bind(performance);
12 | }
13 |
14 | class OGVDecoderVideoVP8 {
15 |
16 | constructor(options) {
17 | this.cpuTime = 0;
18 | this.loadedMetadata = true;
19 | this.frameBuffer = null;
20 | this.videoFormat = options.videoFormat || null;
21 |
22 |
23 | this.iface = jsvpx.ifaces[0].iface; // get jsvp8 decoder
24 | var cfg = null;
25 | var flags = null;
26 | this.decoder = new vpx_codec_ctx_t();
27 |
28 | jsvpx.vpx_codec_dec_init(this.decoder, this.iface, cfg, flags);//ctx, iface, cfg, flags
29 |
30 |
31 | }
32 |
33 | init(callback) {
34 | console.warn("STARTING CODEC JSVPX");
35 | callback();
36 | }
37 |
38 | processHeader(data, callback) {
39 | //console.error("PROCESS HEADER");
40 | this.loadedMetadata = true;
41 | callback(0);
42 | }
43 |
44 | processFrame(buf, callback) {
45 |
46 | var start = getTimestamp();
47 |
48 | var data = new Uint8Array(buf);
49 |
50 |
51 | var iter = null; //vpx_codec_iter_t
52 |
53 | var user_priv;
54 | var deadline;
55 |
56 | jsvpx.vpx_codec_decode(this.decoder, data, data.length, user_priv, deadline);
57 |
58 | var img = jsvpx.vpx_codec_get_frame(this.decoder, iter);
59 |
60 | if (img) {
61 | var offsets = img.planes_off;
62 |
63 | var imgData = img.img_data;
64 |
65 | var videoFormat = this.videoFormat;
66 | /*
67 | * * foundImage = 1;
68 | ogvjs_callback_frame(image->planes[0], image->stride[0],
69 | image->planes[1], image->stride[1],
70 | image->planes[2], image->stride[2],
71 | image->w, image->d_h,
72 | image->w >> 1, image->d_h >> 1); // @todo pixel format
73 | }
74 | return foundImage;
75 | */
76 |
77 | this.frameBuffer = {
78 | // @fixme what to do about the crop coordinates if resolution changes? can this happen in webm land? what about if ogv gets a new steam?
79 | format: {
80 | width: img.d_w + 2, // this is wierd, ogv is cropping it at the wrong spot and making a green line
81 | height: img.d_h,
82 | chromaWidth: img.d_w >> 1,
83 | chromaHeight: img.d_h >> 1,
84 | cropLeft: videoFormat.cropLeft,
85 | cropTop: videoFormat.cropTop,
86 | cropWidth: videoFormat.cropWidth,
87 | cropHeight: videoFormat.cropHeight,
88 | displayWidth: videoFormat.displayWidth,
89 | displayHeight: videoFormat.displayHeight
90 | },
91 | y: {
92 | bytes: imgData.subarray(offsets[0], offsets[1]),
93 | stride: img.stride[0]
94 | },
95 | u: {
96 | bytes: imgData.subarray(offsets[1], offsets[2]),
97 | stride: img.stride[1]
98 | },
99 | v: {
100 | bytes: imgData.subarray(offsets[2]),
101 | stride: img.stride[2]
102 | }
103 | };
104 |
105 | }
106 |
107 | var delta = (getTimestamp() - start);
108 | this.cpuTime += delta;
109 | callback(1);
110 | }
111 |
112 | close() {
113 |
114 | }
115 | }
116 |
117 |
118 |
119 | if (typeof window !== 'undefined') {
120 | window.OGVDecoderVideoVP8 = OGVDecoderVideoVP8;
121 | } else if (typeof self !== 'undefined') {
122 | self.OGVDecoderVideoVP8 = OGVDecoderVideoVP8;
123 | }
124 |
125 | module.exports = OGVDecoderVideoVP8;
--------------------------------------------------------------------------------
/build-templates/jsvpx.js:
--------------------------------------------------------------------------------
1 | var jsvpx = require('../vpx/vpx_decoder.js');
2 |
3 | var vpx_codec = require('../vpx/vpx_codec.js');
4 | var vpx_codec_ctx_t = vpx_codec.vpx_codec_ctx_t;
5 |
6 |
7 | /**
8 | * Javascript style interface
9 | */
10 |
11 | class JsVpx {
12 |
13 | constructor() {
14 |
15 | this.iface = jsvpx.ifaces[0].iface; // get jsvp8 decoder
16 | var cfg = null;
17 | var flags = null;
18 | this.decoder = new vpx_codec_ctx_t();
19 |
20 | jsvpx.vpx_codec_dec_init(this.decoder, this.iface, cfg, flags);//ctx, iface, cfg, flags
21 |
22 | }
23 |
24 | decode(buf) {
25 | var data = new Uint8Array(buf);
26 | var iter = null; //vpx_codec_iter_t
27 |
28 | var user_priv;
29 | var deadline;
30 |
31 | jsvpx.vpx_codec_decode(this.decoder, data, data.length, user_priv, deadline);
32 |
33 | var img = jsvpx.vpx_codec_get_frame(this.decoder, iter);
34 |
35 | if (img) {
36 | return img;
37 | }
38 |
39 | }
40 |
41 | }
42 |
43 | module.exports = JsVpx;
--------------------------------------------------------------------------------
/examples/media/Curiosity's_Seven_Minutes_of_Terror.ogv.240p.webm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jscodec/jsvpx/c2e2ddf339e634436b282b5ad38e66f78727d702/examples/media/Curiosity's_Seven_Minutes_of_Terror.ogv.240p.webm
--------------------------------------------------------------------------------
/examples/ogv-simple/index.html:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 | TODO supply a title
10 |
11 |
12 |
13 |
14 |
15 |
16 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jsvpx",
3 | "version": "0.0.4",
4 | "keywords": [
5 | "webm",
6 | "vp8",
7 | "vp9",
8 | "ogv.js"
9 | ],
10 | "description": "Javascript implementation of libvpx",
11 | "scripts": {
12 | "build": "webpack",
13 | "build-benchmark": "USE_BENCHMARK=true webpack",
14 | "test": "mocha test/test.js --timeout 20000"
15 | },
16 | "author": "Brian Parra",
17 | "contributors": [
18 | "Brion Vibber "
19 | ],
20 | "repository": {
21 | "type": "git",
22 | "url": "https://github.com/jscodec/jsvpx.git"
23 | },
24 | "devDependencies": {
25 | "babel-cli": "6.10.1",
26 | "babel-preset-es2015": "6.9.0",
27 | "browserify": "^13.0.1",
28 | "browserify-shim": "^3.5.0",
29 | "envify": "3.4.1",
30 | "gentelella": "^1.3.0",
31 | "js-md5": "^0.4.1",
32 | "jsivf": "^0.0.2",
33 | "mocha": "^3.1.2",
34 | "ogv": "^1.3.0",
35 | "qunitjs": "^2.1.1",
36 | "uglify-js": "2.7.0",
37 | "webpack": "^1.13.3",
38 | "webpack-closure-compiler": "^2.1.3",
39 | "benchmark": "^2.1.3",
40 | "microtime": "2.1.2",
41 | "lodash" : "4.17.4"
42 | },
43 | "main": "builds/jsvpx.js",
44 | "license": "MIT"
45 | }
46 |
--------------------------------------------------------------------------------
/test/browser-tests.js:
--------------------------------------------------------------------------------
1 | var ivf = require('jsivf');
2 | var md5 = require('js-md5');
3 | var jsvpx = require('../build-templates/jsvpx.js');
4 | //var QUnit = require('qunitjs');
5 |
6 | var testVectors = [
7 | 'vp80-00-comprehensive-001.ivf',
8 | 'vp80-00-comprehensive-002.ivf',
9 | 'vp80-00-comprehensive-003.ivf',
10 | 'vp80-00-comprehensive-004.ivf',
11 | 'vp80-00-comprehensive-005.ivf',
12 | 'vp80-00-comprehensive-006.ivf',
13 | 'vp80-00-comprehensive-007.ivf',
14 | 'vp80-00-comprehensive-008.ivf',
15 | 'vp80-00-comprehensive-009.ivf',
16 | 'vp80-00-comprehensive-010.ivf',
17 | 'vp80-00-comprehensive-011.ivf',
18 | 'vp80-00-comprehensive-012.ivf',
19 | 'vp80-00-comprehensive-013.ivf',
20 | 'vp80-00-comprehensive-014.ivf',
21 | 'vp80-00-comprehensive-015.ivf',
22 | 'vp80-00-comprehensive-016.ivf',
23 | 'vp80-00-comprehensive-017.ivf',
24 | 'vp80-00-comprehensive-018.ivf',
25 | 'vp80-01-intra-1400.ivf',
26 | 'vp80-01-intra-1411.ivf',
27 | 'vp80-01-intra-1416.ivf',
28 | 'vp80-01-intra-1417.ivf',
29 | 'vp80-02-inter-1402.ivf',
30 | 'vp80-02-inter-1412.ivf',
31 | 'vp80-02-inter-1418.ivf',
32 | 'vp80-02-inter-1424.ivf',
33 | 'vp80-03-segmentation-01.ivf',
34 | 'vp80-03-segmentation-02.ivf',
35 | 'vp80-03-segmentation-03.ivf',
36 | 'vp80-03-segmentation-04.ivf',
37 | 'vp80-03-segmentation-1401.ivf',
38 | 'vp80-03-segmentation-1403.ivf',
39 | 'vp80-03-segmentation-1407.ivf',
40 | 'vp80-03-segmentation-1408.ivf',
41 | 'vp80-03-segmentation-1409.ivf',
42 | 'vp80-03-segmentation-1410.ivf',
43 | 'vp80-03-segmentation-1413.ivf',
44 | 'vp80-03-segmentation-1414.ivf',
45 | 'vp80-03-segmentation-1415.ivf',
46 | 'vp80-03-segmentation-1425.ivf',
47 | 'vp80-03-segmentation-1426.ivf',
48 | 'vp80-03-segmentation-1427.ivf',
49 | 'vp80-03-segmentation-1432.ivf',
50 | 'vp80-03-segmentation-1435.ivf',
51 | 'vp80-03-segmentation-1436.ivf',
52 | 'vp80-03-segmentation-1437.ivf',
53 | 'vp80-03-segmentation-1441.ivf',
54 | 'vp80-03-segmentation-1442.ivf',
55 | 'vp80-04-partitions-1404.ivf',
56 | 'vp80-04-partitions-1405.ivf',
57 | 'vp80-04-partitions-1406.ivf',
58 | 'vp80-05-sharpness-1428.ivf',
59 | 'vp80-05-sharpness-1429.ivf',
60 | 'vp80-05-sharpness-1430.ivf',
61 | 'vp80-05-sharpness-1431.ivf',
62 | 'vp80-05-sharpness-1433.ivf',
63 | 'vp80-05-sharpness-1434.ivf',
64 | 'vp80-05-sharpness-1438.ivf',
65 | 'vp80-05-sharpness-1439.ivf',
66 | 'vp80-05-sharpness-1440.ivf',
67 | 'vp80-05-sharpness-1443.ivf'
68 | ];
69 |
70 | function pad(num, size) {
71 | var s = num + "";
72 | while (s.length < size)
73 | s = "0" + s;
74 | return s;
75 | }
76 |
77 | var vectorFolder = '../vp8-test-vectors/';
78 | var output = document.getElementById('output');
79 |
80 | var vector = 'vp80-00-comprehensive-001.ivf';
81 |
82 |
83 | for (var i = 0; i < testVectors.length; i++) {
84 | loadTest(testVectors[i]);
85 | console.warn(testVectors[i]);
86 | }
87 |
88 | function loadTest(vectorFile) {
89 |
90 |
91 |
92 |
93 | QUnit.test(vectorFile, function (assert) {
94 | var done = assert.async();
95 |
96 | var testVectorRequest = new XMLHttpRequest();
97 | testVectorRequest.open("GET", vectorFolder + vectorFile, true);
98 | testVectorRequest.responseType = "arraybuffer";
99 |
100 | testVectorRequest.onload = function (event) {
101 | runTest(testVectorRequest.response, vectorFile, done);
102 | };
103 | testVectorRequest.send(null);
104 | });
105 |
106 |
107 |
108 |
109 | }
110 |
111 | function runTest(buffer, vectorFile, callback) {
112 | var demuxer = new ivf();
113 |
114 | demuxer.receiveBuffer(buffer);
115 | demuxer.parseHeader();
116 |
117 | var decoder = new jsvpx();
118 | var outData = "";
119 |
120 | for (var i = 0; i < demuxer.frameCount; i++) {
121 | var testImg = decoder.decode(demuxer.processFrame());
122 | if (testImg) {
123 | var offsets = testImg.planes_off;
124 | var y_off = offsets[0];
125 | var u_off = offsets[1];
126 | var v_off = offsets[2];
127 |
128 |
129 | var mainHash = md5.create();
130 |
131 | for (var y = 0; y < testImg.d_h; y++) {
132 | mainHash.update(testImg.img_data.subarray(y_off, y_off + testImg.d_w));
133 | y_off += testImg.stride[0];
134 | }
135 |
136 | var chromaHeight = ((1 + testImg.d_h) / 2) | 0;
137 | var chromaWidth = ((1 + testImg.d_w) / 2) | 0;
138 |
139 |
140 | //UPDATING MAIN HASH U
141 | u_off = offsets[1];
142 | for (var y = 0; y < chromaHeight; y++) //testImg.d_h
143 | {
144 |
145 |
146 | mainHash.update(testImg.img_data.subarray(u_off, u_off + chromaWidth));
147 | u_off += testImg.stride[1];
148 | }
149 |
150 | //UPDATING MAIN HASH V
151 | v_off = offsets[2];
152 | for (var y = 0; y < chromaHeight; y++) //testImg.d_h
153 | {
154 |
155 | mainHash.update(testImg.img_data.subarray(v_off, v_off + chromaWidth));
156 | v_off += testImg.stride[2];
157 | }
158 |
159 |
160 | outData += mainHash.hex() + " " + vectorFile.split('.')[0] + "-";
161 | outData += testImg.d_w + "x" + testImg.d_h;
162 | outData += "-" + pad((i + 1), 4);
163 | outData += ".i420";
164 | outData += "\n";
165 |
166 | }
167 |
168 |
169 | }
170 |
171 |
172 |
173 | //output.innerHTML = outData;
174 |
175 |
176 |
177 | var validationRecordRequest = new XMLHttpRequest();
178 | validationRecordRequest.open("GET", vectorFolder + vectorFile + '.md5', true);
179 | validationRecordRequest.responseType = "text";
180 | validationRecordRequest.onload = function (event) {
181 | var validData = validationRecordRequest.response;
182 | QUnit.assert.strictEqual(outData, validData, "Md5 Vector Comparison");
183 | callback();
184 | };
185 | validationRecordRequest.send(null);
186 | //});
187 |
188 |
189 |
190 |
191 |
192 |
193 | }
194 |
--------------------------------------------------------------------------------
/test/compare-hashes.js:
--------------------------------------------------------------------------------
1 |
2 | //Unit Tests
3 | "use strict";
4 | var assert = require('assert');
5 | var readline = require('readline');
6 | var fs = require('fs');
7 | var path = require('path');
8 |
9 | describe('Comparing hashes', function () {
10 | var testFiles = fs.readdirSync("output-vectors");
11 |
12 | for (var key in testFiles) {
13 | if (path.extname(testFiles[key]) === ".md5") {
14 | it('Hash File Match : ' + testFiles[key], function () {
15 | var md5Data = fs.readFileSync("vp8-test-vectors/" + testFiles[key]).toString();
16 | var outputData = fs.readFileSync("output-vectors/" + testFiles[key]).toString();
17 | assert.equal(md5Data, outputData);
18 | });
19 | }
20 |
21 | }
22 | });
--------------------------------------------------------------------------------
/test/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Browser Vp8 Validation Tests
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/test/test-vector-list.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | 'vp80-00-comprehensive-001.ivf',
3 | 'vp80-00-comprehensive-002.ivf',
4 | 'vp80-00-comprehensive-003.ivf',
5 | 'vp80-00-comprehensive-004.ivf',
6 | 'vp80-00-comprehensive-005.ivf',
7 | 'vp80-00-comprehensive-006.ivf',
8 | 'vp80-00-comprehensive-007.ivf',
9 | 'vp80-00-comprehensive-008.ivf',
10 | 'vp80-00-comprehensive-009.ivf',
11 | 'vp80-00-comprehensive-010.ivf',
12 | 'vp80-00-comprehensive-011.ivf',
13 | 'vp80-00-comprehensive-012.ivf',
14 | 'vp80-00-comprehensive-013.ivf',
15 | 'vp80-00-comprehensive-014.ivf',
16 | 'vp80-00-comprehensive-015.ivf',
17 | 'vp80-00-comprehensive-016.ivf',
18 | 'vp80-00-comprehensive-017.ivf',
19 | 'vp80-00-comprehensive-018.ivf',
20 | 'vp80-01-intra-1400.ivf',
21 | 'vp80-01-intra-1411.ivf',
22 | 'vp80-01-intra-1416.ivf',
23 | 'vp80-01-intra-1417.ivf',
24 | 'vp80-02-inter-1402.ivf',
25 | 'vp80-02-inter-1412.ivf',
26 | 'vp80-02-inter-1418.ivf',
27 | 'vp80-02-inter-1424.ivf',
28 | 'vp80-03-segmentation-01.ivf',
29 | 'vp80-03-segmentation-02.ivf',
30 | 'vp80-03-segmentation-03.ivf',
31 | 'vp80-03-segmentation-04.ivf',
32 | 'vp80-03-segmentation-1401.ivf',
33 | 'vp80-03-segmentation-1403.ivf',
34 | 'vp80-03-segmentation-1407.ivf',
35 | 'vp80-03-segmentation-1408.ivf',
36 | 'vp80-03-segmentation-1409.ivf',
37 | 'vp80-03-segmentation-1410.ivf',
38 | 'vp80-03-segmentation-1413.ivf',
39 | 'vp80-03-segmentation-1414.ivf',
40 | 'vp80-03-segmentation-1415.ivf',
41 | 'vp80-03-segmentation-1425.ivf',
42 | 'vp80-03-segmentation-1426.ivf',
43 | 'vp80-03-segmentation-1427.ivf',
44 | 'vp80-03-segmentation-1432.ivf',
45 | 'vp80-03-segmentation-1435.ivf',
46 | 'vp80-03-segmentation-1436.ivf',
47 | 'vp80-03-segmentation-1437.ivf',
48 | 'vp80-03-segmentation-1441.ivf',
49 | 'vp80-03-segmentation-1442.ivf',
50 | 'vp80-04-partitions-1404.ivf',
51 | 'vp80-04-partitions-1405.ivf',
52 | 'vp80-04-partitions-1406.ivf',
53 | 'vp80-05-sharpness-1428.ivf',
54 | 'vp80-05-sharpness-1429.ivf',
55 | 'vp80-05-sharpness-1430.ivf',
56 | 'vp80-05-sharpness-1431.ivf',
57 | 'vp80-05-sharpness-1433.ivf',
58 | 'vp80-05-sharpness-1434.ivf',
59 | 'vp80-05-sharpness-1438.ivf',
60 | 'vp80-05-sharpness-1439.ivf',
61 | 'vp80-05-sharpness-1440.ivf',
62 | 'vp80-05-sharpness-1443.ivf'
63 | ];
64 |
--------------------------------------------------------------------------------
/test/test.js:
--------------------------------------------------------------------------------
1 | const assert = require('assert');
2 | const ivf = require('jsivf');
3 | const fs = require('fs');
4 | const path = require('path');
5 | const md5 = require('js-md5');
6 |
7 | const JsVpx = require('../build-templates/jsvpx.js');
8 | const vectorPath = 'vp8-test-vectors/';
9 |
10 | function pad(num, size) {
11 | var s = num + "";
12 | while (s.length < size)
13 | s = "0" + s;
14 | return s;
15 | }
16 |
17 | function testWrapper(ivfDataFile) {
18 | it('Testing vector Vector : ' + ivfDataFile, function () {
19 | var basename = ivfDataFile.substring(0, ivfDataFile.indexOf('.'));
20 |
21 | var data = fs.readFileSync(vectorPath + ivfDataFile);
22 | var demuxer = new ivf();
23 |
24 | demuxer.receiveBuffer(data);
25 | demuxer.parseHeader();
26 |
27 | const jsvpx = new JsVpx();
28 | let md5OutputData = '';
29 |
30 | for (var i = 0; i < demuxer.frameCount; i++) {
31 | var data = new Uint8Array(demuxer.processFrame());
32 | var testImg = jsvpx.decode(data);
33 | if (testImg) {
34 | var offsets = testImg.planes_off;
35 | var y_off = offsets[0];
36 | var u_off = offsets[1];
37 | var v_off = offsets[2];
38 |
39 | var mainHash = md5.create();
40 |
41 | for (var y = 0; y < testImg.d_h; y++) {
42 | mainHash.update(testImg.img_data.subarray(y_off, y_off + testImg.d_w));
43 | y_off += testImg.stride[0];
44 | }
45 |
46 | var chromaHeight = ((1 + testImg.d_h) / 2) | 0;
47 | var chromaWidth = ((1 + testImg.d_w) / 2) | 0;
48 |
49 | //UPDATING MAIN HASH U
50 | u_off = offsets[1];
51 | for (var y = 0; y < chromaHeight; y++) {
52 | mainHash.update(testImg.img_data.subarray(u_off, u_off + chromaWidth));
53 | u_off += testImg.stride[1];
54 | }
55 |
56 | //UPDATING MAIN HASH V
57 | v_off = offsets[2];
58 | for (var y = 0; y < chromaHeight; y++) {
59 | mainHash.update(testImg.img_data.subarray(v_off, v_off + chromaWidth));
60 | v_off += testImg.stride[2];
61 | }
62 |
63 | var outData = mainHash.hex() + " " + basename + "-";
64 | outData += testImg.d_w + "x" + testImg.d_h;
65 | outData += "-" + pad(jsvpx.decoder.priv.temp_pbi.frame_cnt, 4);
66 | outData += ".i420";
67 | outData += "\n";
68 | md5OutputData += outData;
69 | }
70 | }
71 | var md5Data = fs.readFileSync("vp8-test-vectors/" + basename + ".ivf.md5").toString();
72 | assert.equal(md5Data, md5OutputData);
73 | });
74 | }
75 |
76 | describe('Running Test Vector Unit Tests', function () {
77 | var vectorPath = './vp8-test-vectors/';
78 | var testFiles = fs.readdirSync(vectorPath);
79 | if (!testFiles.length) {
80 | throw new Error('No test vectors; may need to run "git submodule update --init"');
81 | }
82 | for (var key in testFiles) {
83 | var file = testFiles[key];
84 | if (path.extname(file) !== ".ivf")
85 | continue;
86 | testWrapper(file);
87 | }
88 | });
89 |
--------------------------------------------------------------------------------
/util/c_utils.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var MV_PROB_CNT = 19;
4 |
5 | function copy_entropy_values(header, otherHeader) {
6 |
7 | var probs = otherHeader.coeff_probs.data_32;
8 | var to = header.coeff_probs.data_32;
9 | //header.coeff_probs = otherHeader.coeff_probs.slice(0);
10 | //for (var i = 0; i < 264; i++)
11 | to.set(probs);
12 |
13 | //load mv probs
14 | probs = otherHeader.mv_probs;
15 | //header can probably be done faster
16 | //for (var i = 0; i < MV_PROB_CNT; i++)
17 | header.mv_probs[0].set(probs[0]);
18 |
19 | //for (var i = 0; i < MV_PROB_CNT; i++)
20 | header.mv_probs[1].set(probs[1]);
21 |
22 | //load y mode probs
23 | probs = otherHeader.y_mode_probs_32;
24 | header.y_mode_probs_32[0] = probs[0];
25 |
26 |
27 |
28 | //load uv mode probs
29 | probs = otherHeader.uv_mode_probs;
30 | //for (var i = 0; i < 3; i++)
31 | header.uv_mode_probs[0] = probs[0];
32 | header.uv_mode_probs[1] = probs[1];
33 | header.uv_mode_probs[2] = probs[2];
34 |
35 |
36 | header.prob_inter = otherHeader.prob_inter;
37 | header.prob_last = otherHeader.prob_inter;
38 | header.prob_gf = otherHeader.prob_inter;
39 | }
40 |
41 | function memset(ptr, ptr_off, value, num) {
42 |
43 | var i = num;
44 | while (i--)
45 | ptr[ptr_off + i] = value;
46 |
47 | }
48 |
49 | function memset_32(ptr, ptr_off, value, num) {
50 |
51 | var i = num;//>> 2;
52 | var ptr_off_32 = ptr_off >> 2;
53 | var ptr_32 = ptr.data_32;
54 | var value_32 = value | value << 8 | value << 16 | value << 24;
55 |
56 | var num_32 = num >> 2;
57 | for (var i = 0; i < num_32; i++) {
58 | ptr_32[ptr_off_32 + (i >> 2)] = value_32;
59 | }
60 |
61 | }
62 |
63 | function memcpy(dst, dst_off, src, src_off, num) {
64 | dst.set(src.subarray(src_off, src_off + num), dst_off);
65 | /*
66 | var i = num;
67 | while (i--) {
68 | dst[dst_off + i] = src[src_off + i];
69 | }
70 | */
71 | return dst;
72 |
73 | }
74 |
75 |
76 | module.exports = {};
77 | module.exports.copy_entropy_values = copy_entropy_values;
78 | module.exports.memset = memset;
79 | module.exports.memset_32 = memset_32;
80 | module.exports.memcpy = memcpy;
81 |
--------------------------------------------------------------------------------
/vp8/common/blockd.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var MotionVector = require('./mv.js');
3 |
4 | //left_context_index
5 | var vp8_block2left =
6 | new Uint8Array([
7 | 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
8 | 4, 4, 5, 5, 6, 6, 7, 7, 8
9 | ]);
10 |
11 | //above_context_index
12 | var vp8_block2above =
13 | new Uint8Array([
14 | 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
15 | 4, 5, 4, 5, 6, 7, 6, 7, 8
16 | ]);
17 |
18 |
19 |
20 |
21 | var MAX_PARTITIONS = 8;
22 |
23 | //FRAGMENT_DATA
24 | //supposed to go in VP8D_COMP
25 | class FRAGMENT_DATA {
26 |
27 | constructor(decoder) {
28 | this.decoder = decoder;
29 | this.partitions = 0;
30 | this.partition_sz = new Int32Array(MAX_PARTITIONS);
31 |
32 | }
33 |
34 | }
35 |
36 |
37 |
38 |
39 | /*
40 | * likely MB_MODE_INFO
41 | */
42 | class MODE_INFO {
43 | //MB_MODE_INFO
44 | constructor() {
45 | //mv_mbmi_info
46 |
47 | this.mbmi = {
48 | y_mode: 0,
49 | uv_mode: 0,
50 | ref_frame: 0,
51 | is_4x4: 0,
52 | mv: MotionVector.create(),
53 | partitioning: 0,
54 | mb_skip_coeff: 0,
55 | need_mc_border: 0,
56 | segment_id: 0,
57 | eob_mask: 0
58 | };
59 |
60 | this.bmi = null;
61 |
62 |
63 | }
64 |
65 | init_split_mode() {
66 | var mvs = new Array(16);
67 | var i = 16;
68 | while (i--)
69 | mvs[i] = MotionVector.create();
70 |
71 | //Only needed for spit mode, maybe can skip initialization unless splitt mode is on
72 | this.bmi =
73 | {
74 | mvs: mvs,
75 | modes: new Uint8Array(16)//16,'todo:enum prediction_mode')
76 | };
77 | }
78 | }
79 |
80 | /*
81 | */
82 | class MACROBLOCKD {
83 |
84 | constructor(decoder) {
85 | this.decoder = decoder;
86 | this.enabled = 0;
87 | this.update_data = 0;
88 | this.update_map = 0;
89 | this.abs = 0;
90 | this.tree_probs = new Uint32Array(3);
91 | this.lf_level = new Int32Array(4);
92 | this.lf_level_64 = new Float64Array(this.lf_level.buffer);
93 | this.quant_idx = new Int32Array(4);
94 | this.quant_idx_64 = new Float64Array(this.quant_idx.buffer);
95 |
96 |
97 | }
98 | }
99 |
100 |
101 |
102 |
103 |
104 | module.exports = {};
105 |
106 | module.exports.vp8_block2left = vp8_block2left;
107 | module.exports.vp8_block2above = vp8_block2above;
108 | module.exports.MACROBLOCKD = MACROBLOCKD;
109 | module.exports.FRAGMENT_DATA = FRAGMENT_DATA;
110 | module.exports.MODE_INFO = MODE_INFO;
--------------------------------------------------------------------------------
/vp8/common/coefupdateprobs.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /*
3 | * File: coefupdateprobs
4 | */
5 | var vp8_coef_update_probs = new Uint8Array([
6 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
7 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
8 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
9 | 255, 255, 255, 176, 246, 255, 255, 255, 255, 255,
10 | 255, 255, 255, 255, 223, 241, 252, 255, 255, 255,
11 | 255, 255, 255, 255, 255, 249, 253, 253, 255, 255,
12 | 255, 255, 255, 255, 255, 255, 255, 244, 252, 255,
13 | 255, 255, 255, 255, 255, 255, 255, 234, 254, 254,
14 | 255, 255, 255, 255, 255, 255, 255, 255, 253, 255,
15 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
16 | 246, 254, 255, 255, 255, 255, 255, 255, 255, 255,
17 | 239, 253, 254, 255, 255, 255, 255, 255, 255, 255,
18 | 255, 254, 255, 254, 255, 255, 255, 255, 255, 255,
19 | 255, 255, 255, 248, 254, 255, 255, 255, 255, 255,
20 | 255, 255, 255, 251, 255, 254, 255, 255, 255, 255,
21 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
22 | 255, 255, 255, 255, 255, 255, 253, 254, 255, 255,
23 | 255, 255, 255, 255, 255, 255, 251, 254, 254, 255,
24 | 255, 255, 255, 255, 255, 255, 255, 254, 255, 254,
25 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 254,
26 | 253, 255, 254, 255, 255, 255, 255, 255, 255, 250,
27 | 255, 254, 255, 254, 255, 255, 255, 255, 255, 255,
28 | 254, 255, 255, 255, 255, 255, 255, 255, 255, 255,
29 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
30 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
31 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
32 | 255, 255, 255, 255, 217, 255, 255, 255, 255, 255,
33 | 255, 255, 255, 255, 255, 225, 252, 241, 253, 255,
34 | 255, 254, 255, 255, 255, 255, 234, 250, 241, 250,
35 | 253, 255, 253, 254, 255, 255, 255, 255, 254, 255,
36 | 255, 255, 255, 255, 255, 255, 255, 255, 223, 254,
37 | 254, 255, 255, 255, 255, 255, 255, 255, 255, 238,
38 | 253, 254, 254, 255, 255, 255, 255, 255, 255, 255,
39 | 255, 248, 254, 255, 255, 255, 255, 255, 255, 255,
40 | 255, 249, 254, 255, 255, 255, 255, 255, 255, 255,
41 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
42 | 255, 255, 255, 255, 253, 255, 255, 255, 255, 255,
43 | 255, 255, 255, 255, 247, 254, 255, 255, 255, 255,
44 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
45 | 255, 255, 255, 255, 255, 255, 255, 253, 254, 255,
46 | 255, 255, 255, 255, 255, 255, 255, 252, 255, 255,
47 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
48 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
49 | 254, 254, 255, 255, 255, 255, 255, 255, 255, 255,
50 | 253, 255, 255, 255, 255, 255, 255, 255, 255, 255,
51 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
52 | 255, 255, 255, 254, 253, 255, 255, 255, 255, 255,
53 | 255, 255, 255, 250, 255, 255, 255, 255, 255, 255,
54 | 255, 255, 255, 255, 254, 255, 255, 255, 255, 255,
55 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
56 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
57 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
58 | 255, 255, 255, 255, 255, 255, 255, 255, 186, 251,
59 | 250, 255, 255, 255, 255, 255, 255, 255, 255, 234,
60 | 251, 244, 254, 255, 255, 255, 255, 255, 255, 255,
61 | 251, 251, 243, 253, 254, 255, 254, 255, 255, 255,
62 | 255, 255, 253, 254, 255, 255, 255, 255, 255, 255,
63 | 255, 255, 236, 253, 254, 255, 255, 255, 255, 255,
64 | 255, 255, 255, 251, 253, 253, 254, 254, 255, 255,
65 | 255, 255, 255, 255, 255, 254, 254, 255, 255, 255,
66 | 255, 255, 255, 255, 255, 254, 254, 254, 255, 255,
67 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
68 | 255, 255, 255, 255, 255, 255, 255, 255, 254, 255,
69 | 255, 255, 255, 255, 255, 255, 255, 255, 254, 254,
70 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 254,
71 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
72 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
73 | 255, 254, 255, 255, 255, 255, 255, 255, 255, 255,
74 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
75 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
76 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
77 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
78 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
79 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
80 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
81 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
82 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
83 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
84 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
85 | 255, 255, 248, 255, 255, 255, 255, 255, 255, 255,
86 | 255, 255, 255, 250, 254, 252, 254, 255, 255, 255,
87 | 255, 255, 255, 255, 248, 254, 249, 253, 255, 255,
88 | 255, 255, 255, 255, 255, 255, 253, 253, 255, 255,
89 | 255, 255, 255, 255, 255, 255, 246, 253, 253, 255,
90 | 255, 255, 255, 255, 255, 255, 255, 252, 254, 251,
91 | 254, 254, 255, 255, 255, 255, 255, 255, 255, 254,
92 | 252, 255, 255, 255, 255, 255, 255, 255, 255, 248,
93 | 254, 253, 255, 255, 255, 255, 255, 255, 255, 255,
94 | 253, 255, 254, 254, 255, 255, 255, 255, 255, 255,
95 | 255, 255, 251, 254, 255, 255, 255, 255, 255, 255,
96 | 255, 255, 245, 251, 254, 255, 255, 255, 255, 255,
97 | 255, 255, 255, 253, 253, 254, 255, 255, 255, 255,
98 | 255, 255, 255, 255, 255, 251, 253, 255, 255, 255,
99 | 255, 255, 255, 255, 255, 252, 253, 254, 255, 255,
100 | 255, 255, 255, 255, 255, 255, 255, 254, 255, 255,
101 | 255, 255, 255, 255, 255, 255, 255, 255, 252, 255,
102 | 255, 255, 255, 255, 255, 255, 255, 255, 249, 255,
103 | 254, 255, 255, 255, 255, 255, 255, 255, 255, 255,
104 | 255, 254, 255, 255, 255, 255, 255, 255, 255, 255,
105 | 255, 255, 253, 255, 255, 255, 255, 255, 255, 255,
106 | 255, 250, 255, 255, 255, 255, 255, 255, 255, 255,
107 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
108 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
109 | 255, 255, 255, 255, 254, 255, 255, 255, 255, 255,
110 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
111 | 255, 255, 255, 255, 255, 255]);
112 |
113 | module.exports = vp8_coef_update_probs;
--------------------------------------------------------------------------------
/vp8/common/default_coef_probs.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var default_coef_probs = new Uint8Array([128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 253, 136, 254, 255, 228, 219, 128, 128, 128, 128, 128, 189, 129, 242, 255, 227, 213, 255, 219, 128, 128, 128, 106, 126, 227, 252, 214, 209, 255, 255, 128, 128, 128, 1, 98, 248, 255, 236, 226, 255, 255, 128, 128, 128, 181, 133, 238, 254, 221, 234, 255, 154, 128, 128, 128, 78, 134, 202, 247, 198, 180, 255, 219, 128, 128, 128, 1, 185, 249, 255, 243, 255, 128, 128, 128, 128, 128, 184, 150, 247, 255, 236, 224, 128, 128, 128, 128, 128, 77, 110, 216, 255, 236, 230, 128, 128, 128, 128, 128, 1, 101, 251, 255, 241, 255, 128, 128, 128, 128, 128, 170, 139, 241, 252, 236, 209, 255, 255, 128, 128, 128, 37, 116, 196, 243, 228, 255, 255, 255, 128, 128, 128, 1, 204, 254, 255, 245, 255, 128, 128, 128, 128, 128, 207, 160, 250, 255, 238, 128, 128, 128, 128, 128, 128, 102, 103, 231, 255, 211, 171, 128, 128, 128, 128, 128, 1, 152, 252, 255, 240, 255, 128, 128, 128, 128, 128, 177, 135, 243, 255, 234, 225, 128, 128, 128, 128, 128, 80, 129, 211, 255, 194, 224, 128, 128, 128, 128, 128, 1, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128, 246, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 198, 35, 237, 223, 193, 187, 162, 160, 145, 155, 62, 131, 45, 198, 221, 172, 176, 220, 157, 252, 221, 1, 68, 47, 146, 208, 149, 167, 221, 162, 255, 223, 128, 1, 149, 241, 255, 221, 224, 255, 255, 128, 128, 128, 184, 141, 234, 253, 222, 220, 255, 199, 128, 128, 128, 81, 99, 181, 242, 176, 190, 249, 202, 255, 255, 128, 1, 129, 232, 253, 214, 197, 242, 196, 255, 255, 128, 99, 121, 210, 250, 201, 198, 255, 202, 128, 128, 128, 23, 91, 163, 242, 170, 187, 247, 210, 255, 255, 128, 1, 200, 246, 255, 234, 255, 128, 128, 128, 128, 128, 109, 178, 241, 255, 231, 245, 255, 255, 128, 128, 128, 44, 130, 201, 253, 205, 192, 255, 255, 128, 128, 128, 1, 132, 239, 251, 219, 209, 255, 165, 128, 128, 128, 94, 136, 225, 251, 218, 190, 255, 255, 128, 128, 128, 22, 100, 174, 245, 186, 161, 255, 199, 128, 128, 128, 1, 182, 249, 255, 232, 235, 128, 128, 128, 128, 128, 124, 143, 241, 255, 227, 234, 128, 128, 128, 128, 128, 35, 77, 181, 251, 193, 211, 255, 205, 128, 128, 128, 1, 157, 247, 255, 236, 231, 255, 255, 128, 128, 128, 121, 141, 235, 255, 225, 227, 255, 255, 128, 128, 128, 45, 99, 188, 251, 195, 217, 255, 224, 128, 128, 128, 1, 1, 251, 255, 213, 255, 128, 128, 128, 128, 128, 203, 1, 248, 255, 255, 128, 128, 128, 128, 128, 128, 137, 1, 177, 255, 224, 255, 128, 128, 128, 128, 128, 253, 9, 248, 251, 207, 208, 255, 192, 128, 128, 128, 175, 13, 224, 243, 193, 185, 249, 198, 255, 255, 128, 73, 17, 171, 221, 161, 179, 236, 167, 255, 234, 128, 1, 95, 247, 253, 212, 183, 255, 255, 128, 128, 128, 239, 90, 244, 250, 211, 209, 255, 255, 128, 128, 128, 155, 77, 195, 248, 188, 195, 255, 255, 128, 128, 128, 1, 24, 239, 251, 218, 219, 255, 205, 128, 128, 128, 201, 51, 219, 255, 196, 186, 128, 128, 128, 128, 128, 69, 46, 190, 239, 201, 218, 255, 228, 128, 128, 128, 1, 191, 251, 255, 255, 128, 128, 128, 128, 128, 128, 223, 165, 249, 255, 213, 255, 128, 128, 128, 128, 128, 141, 124, 248, 255, 255, 128, 128, 128, 128, 128, 128, 1, 16, 248, 255, 255, 128, 128, 128, 128, 128, 128, 190, 36, 230, 255, 236, 255, 128, 128, 128, 128, 128, 149, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128, 1, 226, 255, 128, 128, 128, 128, 128, 128, 128, 128, 247, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128, 240, 128, 255, 128, 128, 128, 128, 128, 128, 128, 128, 1, 134, 252, 255, 255, 128, 128, 128, 128, 128, 128, 213, 62, 250, 255, 255, 128, 128, 128, 128, 128, 128, 55, 93, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 202, 24, 213, 235, 186, 191, 220, 160, 240, 175, 255, 126, 38, 182, 232, 169, 184, 228, 174, 255, 187, 128, 61, 46, 138, 219, 151, 178, 240, 170, 255, 216, 128, 1, 112, 230, 250, 199, 191, 247, 159, 255, 255, 128, 166, 109, 228, 252, 211, 215, 255, 174, 128, 128, 128, 39, 77, 162, 232, 172, 180, 245, 178, 255, 255, 128, 1, 52, 220, 246, 198, 199, 249, 220, 255, 255, 128, 124, 74, 191, 243, 183, 193, 250, 221, 255, 255, 128, 24, 71, 130, 219, 154, 170, 243, 182, 255, 255, 128, 1, 182, 225, 249, 219, 240, 255, 224, 128, 128, 128, 149, 150, 226, 252, 216, 205, 255, 171, 128, 128, 128, 28, 108, 170, 242, 183, 194, 254, 223, 255, 255, 128, 1, 81, 230, 252, 204, 203, 255, 192, 128, 128, 128, 123, 102, 209, 247, 188, 196, 255, 233, 128, 128, 128, 20, 95, 153, 243, 164, 173, 255, 203, 128, 128, 128, 1, 222, 248, 255, 216, 213, 128, 128, 128, 128, 128, 168, 175, 246, 252, 235, 205, 255, 255, 128, 128, 128, 47, 116, 215, 255, 211, 212, 255, 255, 128, 128, 128, 1, 121, 236, 253, 212, 214, 255, 255, 128, 128, 128, 141, 84, 213, 252, 201, 202, 255, 219, 128, 128, 128, 42, 80, 160, 240, 162, 185, 255, 205, 128, 128, 128, 1, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128, 244, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128, 238, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128]);
3 | default_coef_probs.data_32 = new Uint32Array(default_coef_probs.buffer);
4 | default_coef_probs.data_64 = new Float64Array(default_coef_probs.buffer);
5 |
6 | module.exports = default_coef_probs;
7 |
8 |
--------------------------------------------------------------------------------
/vp8/common/entropy.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var default_coef_probs = require('./default_coef_probs.js');
3 | var default_coef_probs_32 = default_coef_probs.data_32;
4 |
5 |
6 | function vp8_default_coef_probs(pc) {
7 |
8 | //for (var i = 0; i < 1056; i++)
9 | //pc.entropy_hdr.coeff_probs[i] = default_coef_probs[i];
10 |
11 | /*
12 | var to = pc.entropy_hdr.coeff_probs.data_32;
13 | for (var i = 0; i < 264; i++)
14 | to[i] = default_coef_probs_32[i];
15 | */
16 | pc.entropy_hdr.coeff_probs.data_32.set(default_coef_probs_32);
17 | /*
18 | var to = pc.entropy_hdr.coeff_probs.data_64;
19 | for (var i = 0; i < 132; i++)
20 | to[i] = default_coef_probs_64[i];
21 | */
22 | }
23 |
24 | module.exports = {
25 | vp8_default_coef_probs : vp8_default_coef_probs
26 | };
--------------------------------------------------------------------------------
/vp8/common/entropymode.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var DC_PRED = 0;
3 | var V_PRED = 1;
4 | var H_PRED = 2; /* horizontal prediction */
5 | var TM_PRED = 3; /* Truemotion prediction */
6 | var B_PRED = 4; /* block based prediction, each block has its own prediction mode */
7 | var NEARESTMV = 5;
8 | var NEARMV = 6;
9 | var ZEROMV = 7;
10 | var NEWMV = 8;
11 | var SPLITMV = 9;
12 | var MB_MODE_COUNT = 10;
13 |
14 | var B_DC_PRED = 0, /* average of above and left pixels */
15 | B_TM_PRED = 1,
16 | B_VE_PRED = 2, /* vertical prediction */
17 | B_HE_PRED = 3, /* horizontal prediction */
18 |
19 | B_LD_PRED = 4,
20 | B_RD_PRED = 5,
21 | B_VR_PRED = 6,
22 | B_VL_PRED = 7,
23 | B_HD_PRED = 8,
24 | B_HU_PRED = 9,
25 | LEFT4X4 = 10,
26 | ABOVE4X4 = 11,
27 | ZERO4X4 = 12,
28 | NEW4X4 = 13,
29 | B_MODE_COUNT = 14
30 | ;//} B_PREDICTION_MODE;
31 |
32 | //b_mode_tree in dixie version
33 | var vp8_bmode_tree =
34 | new Int32Array([
35 | -B_DC_PRED, 2, /* 0 = DC_NODE */
36 | -B_TM_PRED, 4, /* 1 = TM_NODE */
37 | -B_VE_PRED, 6, /* 2 = VE_NODE */
38 | 8, 12, /* 3 = COM_NODE */
39 | -B_HE_PRED, 10, /* 4 = HE_NODE */
40 | -B_RD_PRED, -B_VR_PRED, /* 5 = RD_NODE */
41 | -B_LD_PRED, 14, /* 6 = LD_NODE */
42 | -B_VL_PRED, 16, /* 7 = VL_NODE */
43 | -B_HD_PRED, -B_HU_PRED /* 8 = HD_NODE */
44 | ]);
45 |
46 | //kf_y_mode_tree in dixie version
47 | var vp8_kf_ymode_tree =
48 | new Int32Array([
49 | -B_PRED, 2,
50 | 4, 6,
51 | -DC_PRED, -V_PRED,
52 | -H_PRED, -TM_PRED
53 | ]);
54 |
55 | var vp8_ymode_tree =
56 | new Int32Array([
57 | -DC_PRED, 2,
58 | 4, 6,
59 | -V_PRED, -H_PRED,
60 | -TM_PRED, -B_PRED
61 | ]);
62 |
63 | var vp8_uv_mode_tree =
64 | new Int32Array([
65 | -DC_PRED, 2,
66 | -V_PRED, 4,
67 | -H_PRED, -TM_PRED
68 | ]);
69 |
70 | var vp8_mv_ref_tree = new Int32Array([
71 | -ZEROMV, 2,
72 | -NEARESTMV, 4,
73 | -NEARMV, 6,
74 | -NEWMV, -SPLITMV
75 | ]);
76 |
77 | var vp8_sub_mv_ref_tree = new Int32Array([
78 | -LEFT4X4, 2,
79 | -ABOVE4X4, 4,
80 | -ZERO4X4, -NEW4X4
81 | ]);
82 |
83 | var vp8_small_mvtree =
84 | new Int32Array([
85 | 2, 8,
86 | 4, 6,
87 | -0, -1,
88 | -2, -3,
89 | 10, 12,
90 | -4, -5,
91 | -6, -7
92 | ]);
93 |
94 | var vp8_mbsplit_tree = new Int32Array([
95 | -3, 2,
96 | -2, 4,
97 | -0, -1
98 | ]);
99 |
100 | var vp8_mbsplits =
101 | [
102 | new Int32Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]),
103 | new Int32Array([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]),
104 | new Int32Array([0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3]),
105 | new Int32Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
106 | ];
107 |
108 | var vp8_sub_mv_ref_prob2 =
109 | [
110 | new Int32Array([147, 136, 18]),
111 | new Int32Array([106, 145, 1]),
112 | new Int32Array([179, 121, 1]),
113 | new Int32Array([223, 1, 34]),
114 | new Int32Array([208, 1, 1])
115 | ];
116 |
117 | //vp8_mbsplit_probs
118 | var vp8_mbsplit_probs = new Uint8Array([110, 111, 150]);
119 |
120 |
121 | // k_default_y_mode_probs
122 | var vp8_ymode_prob = new Uint8Array([112, 86, 140, 37]);
123 | var vp8_ymode_prob_32 = new Uint32Array(vp8_ymode_prob.buffer);
124 |
125 | //k_default_uv_mode_probs
126 | var vp8_uv_mode_prob = new Uint8Array([162, 101, 204]);
127 |
128 | //kf_uv_mode_probs
129 | var vp8_kf_uv_mode_prob = new Uint8Array([142, 114, 183]);
130 |
131 | //kf_y_mode_probs
132 | var vp8_kf_ymode_prob = new Uint8Array([145, 156, 163, 128]);
133 |
134 | //default_b_mode_probs
135 | var vp8_bmode_prob = new Uint8Array([120, 90, 79, 133, 87, 85, 80, 111, 151]);
136 |
137 | function vp8_init_mbmode_probs(x) {
138 |
139 | var probs = vp8_ymode_prob;
140 | x.entropy_hdr.y_mode_probs_32[0] = vp8_ymode_prob_32[0];
141 | /*
142 | probs = vp8_uv_mode_prob;
143 | //for (var i = 0; i < 3; i++)
144 | x.entropy_hdr.uv_mode_probs[0] = probs[0];
145 | x.entropy_hdr.uv_mode_probs[1] = probs[1];
146 | x.entropy_hdr.uv_mode_probs[2] = probs[2];
147 | */
148 | x.entropy_hdr.uv_mode_probs.set(vp8_uv_mode_prob);
149 | }
150 |
151 | module.exports = {};
152 | module.exports.vp8_bmode_tree = vp8_bmode_tree;
153 | module.exports.vp8_kf_ymode_tree = vp8_kf_ymode_tree;
154 | module.exports.vp8_uv_mode_tree = vp8_uv_mode_tree;
155 | module.exports.vp8_kf_uv_mode_prob = vp8_kf_uv_mode_prob;
156 | module.exports.vp8_kf_ymode_prob = vp8_kf_ymode_prob;
157 | module.exports.vp8_uv_mode_prob = vp8_uv_mode_prob;
158 | module.exports.vp8_bmode_prob = vp8_bmode_prob;
159 | module.exports.vp8_ymode_prob = vp8_ymode_prob;
160 | module.exports.vp8_ymode_tree = vp8_ymode_tree;
161 | module.exports.vp8_mbsplit_probs = vp8_mbsplit_probs;
162 | module.exports.vp8_mv_ref_tree = vp8_mv_ref_tree;
163 | module.exports.vp8_sub_mv_ref_tree = vp8_sub_mv_ref_tree;
164 | module.exports.vp8_small_mvtree = vp8_small_mvtree;
165 | module.exports.vp8_mbsplit_tree = vp8_mbsplit_tree;
166 | module.exports.vp8_mbsplits = vp8_mbsplits;
167 | module.exports.vp8_sub_mv_ref_prob2 = vp8_sub_mv_ref_prob2;
168 | module.exports.vp8_init_mbmode_probs = vp8_init_mbmode_probs;
--------------------------------------------------------------------------------
/vp8/common/entropymv.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 |
4 | //k_mv_entropy_update_probs
5 | var vp8_mv_update_probs =
6 | [
7 | new Uint8Array([
8 | 237,
9 | 246,
10 | 253, 253, 254, 254, 254, 254, 254,
11 | 254, 254, 254, 254, 254, 250, 250, 252, 254, 254
12 | ]),
13 | new Uint8Array([
14 | 231,
15 | 243,
16 | 245, 253, 254, 254, 254, 254, 254,
17 | 254, 254, 254, 254, 254, 251, 251, 254, 254, 254
18 | ])
19 | ];
20 |
21 |
22 | //k_default_mv_probs
23 | var vp8_default_mv_context =
24 | [
25 | new Uint8Array([// row
26 | 162, // is short
27 | 128, // sign
28 | 225, 146, 172, 147, 214, 39, 156, // short tree
29 | 128, 129, 132, 75, 145, 178, 206, 239, 254, 254 // long bits
30 | ]),
31 | new Uint8Array([
32 | 164,
33 | 128,
34 | 204, 170, 119, 235, 140, 230, 228,
35 | 128, 130, 130, 74, 148, 180, 203, 236, 254, 254
36 |
37 | ])
38 | ];
39 |
40 |
41 |
42 | module.exports = {};
43 | module.exports.vp8_mv_update_probs = vp8_mv_update_probs;
44 | module.exports.vp8_default_mv_context = vp8_default_mv_context;
45 |
--------------------------------------------------------------------------------
/vp8/common/filter.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | //bilinear_filters
3 | var vp8_bilinear_filters =
4 | [
5 | new Int16Array([0, 0, 128, 0, 0, 0]),
6 | new Int16Array([0, 0, 112, 16, 0, 0]),
7 | new Int16Array([0, 0, 96, 32, 0, 0]),
8 | new Int16Array([0, 0, 80, 48, 0, 0]),
9 | new Int16Array([0, 0, 64, 64, 0, 0]),
10 | new Int16Array([0, 0, 48, 80, 0, 0]),
11 | new Int16Array([0, 0, 32, 96, 0, 0]),
12 | new Int16Array([0, 0, 16, 112, 0, 0])
13 | ];
14 | vp8_bilinear_filters[0].shape = 1;
15 | vp8_bilinear_filters[1].shape = 1;
16 | vp8_bilinear_filters[2].shape = 1;
17 | vp8_bilinear_filters[3].shape = 1;
18 | vp8_bilinear_filters[4].shape = 1;
19 | vp8_bilinear_filters[5].shape = 1;
20 | vp8_bilinear_filters[6].shape = 1;
21 | vp8_bilinear_filters[7].shape = 1;
22 |
23 | // sixtap_filters
24 | var vp8_sub_pel_filters =
25 | [
26 | new Int16Array([0, 0, 128, 0, 0, 0]),
27 | new Int16Array([0, -6, 123, 12, -1, 0]),
28 | new Int16Array([2, -11, 108, 36, -8, 1]),
29 | new Int16Array([0, -9, 93, 50, -6, 0]),
30 | new Int16Array([3, -16, 77, 77, -16, 3]),
31 | new Int16Array([0, -6, 50, 93, -9, 0]),
32 | new Int16Array([1, -8, 36, 108, -11, 2]),
33 | new Int16Array([0, -1, 12, 123, -6, 0])
34 | ];
35 | vp8_sub_pel_filters[0].shape = 1;
36 | vp8_sub_pel_filters[1].shape = 2;
37 | vp8_sub_pel_filters[2].shape = 0;
38 | vp8_sub_pel_filters[3].shape = 2;
39 | vp8_sub_pel_filters[4].shape = 0;
40 | vp8_sub_pel_filters[5].shape = 2;
41 | vp8_sub_pel_filters[6].shape = 0;
42 | vp8_sub_pel_filters[7].shape = 2;
43 |
44 |
45 | var VP8_FILTER_SHIFT = 7;
46 |
47 | function filter_block2d_first_pass(output,
48 | src, src_ptr,
49 | reference_stride, vp8_filter) {
50 |
51 | var r = 0, c = 0;
52 | var Temp = 0;
53 | var output_off = 0;
54 |
55 | var filter0 = vp8_filter[0] | 0;
56 | var filter1 = vp8_filter[1] | 0;
57 | var filter2 = vp8_filter[2] | 0;
58 | var filter3 = vp8_filter[3] | 0;
59 | var filter4 = vp8_filter[4] | 0;
60 | var filter5 = vp8_filter[5] | 0;
61 |
62 | for (r = 0; r < 9; r++) {
63 | for (c = 0; c < 4; c++){
64 | Temp = (src[src_ptr - 2] * filter0) +
65 | (src[src_ptr - 1] * filter1) +
66 | (src[src_ptr] * filter2) +
67 | (src[src_ptr + 1] * filter3) +
68 | (src[src_ptr + 2] * filter4) +
69 | (src[src_ptr + 3] * filter5) +
70 | 64;
71 |
72 |
73 | Temp >>= VP8_FILTER_SHIFT;
74 |
75 | Temp = Math.min(Math.max(Temp, 0), 255);
76 |
77 | output[output_off + c] = Temp;
78 | src_ptr++;
79 | }
80 |
81 | src_ptr += reference_stride - 4;
82 | output_off += 16;
83 | }
84 | }
85 |
86 | function filter_block2d_first_pass_shape_2(output,
87 | src, src_ptr,
88 | reference_stride, vp8_filter) {
89 |
90 | var r = 0, c = 0;
91 | var Temp = 0;
92 | var output_off = 0;
93 |
94 | var filter1 = vp8_filter[1] | 0;
95 | var filter2 = vp8_filter[2] | 0;
96 | var filter3 = vp8_filter[3] | 0;
97 | var filter4 = vp8_filter[4] | 0;
98 |
99 |
100 | for (r = 0; r < 9; r++) {
101 | for (c = 0; c < 4; c++){
102 | Temp =
103 | (src[src_ptr - 1] * filter1) +
104 | (src[src_ptr] * filter2) +
105 | (src[src_ptr + 1] * filter3) +
106 | (src[src_ptr + 2] * filter4) +
107 |
108 | 64;
109 |
110 |
111 | Temp >>= VP8_FILTER_SHIFT;
112 | /*
113 | if (Temp < 0) {
114 | Temp = 0;
115 | } else if (Temp > 255) {
116 | Temp = 255;
117 | }
118 | */
119 |
120 | Temp = Math.min(Math.max(Temp, 0), 255);
121 |
122 |
123 |
124 | output[output_off + c] = Temp;
125 | src_ptr++;
126 | }
127 |
128 | src_ptr += reference_stride - 4;
129 | output_off += 16;
130 | }
131 | }
132 |
133 | function filter_block2d_first_pass_shape_1(output,
134 | src, src_ptr,
135 | reference_stride, vp8_filter) {
136 |
137 | var r = 0, c = 0;
138 | var Temp = 0;
139 | var output_off = 0;
140 |
141 | var filter2 = vp8_filter[2] | 0;
142 | var filter3 = vp8_filter[3] | 0;
143 |
144 | for (r = 0; r < 9; r++) {
145 | for (c = 0; c < 4; c++){
146 | Temp =
147 | (src[src_ptr] * filter2) +
148 | (src[src_ptr + 1] * filter3) +
149 | 64;
150 |
151 |
152 | Temp >>= VP8_FILTER_SHIFT;
153 | /*
154 | if (Temp < 0) {
155 | Temp = 0;
156 | } else if (Temp > 255) {
157 | Temp = 255;
158 | }
159 | */
160 | Temp = Math.min(Math.max(Temp, 0), 255);
161 |
162 | output[output_off + c] = Temp;
163 | src_ptr++;
164 | }
165 |
166 | src_ptr += reference_stride - 4;
167 | output_off += 16;
168 | }
169 | }
170 |
171 | function filter_block2d_second_pass(output,
172 | output_off,
173 | output_stride,
174 | reference,
175 | cols,
176 | rows,
177 | filter
178 | ) {
179 |
180 | var reference_off = 32;
181 | var r = 0, c = 0, Temp = 0;
182 | var filter0 = filter[0] | 0;
183 | var filter1 = filter[1] | 0;
184 | var filter2 = filter[2] | 0;
185 | var filter3 = filter[3] | 0;
186 | var filter4 = filter[4] | 0;
187 | var filter5 = filter[5] | 0;
188 |
189 | for (r = 0; r < rows; r++) {
190 | for (c = 0; c < cols; c++) {
191 | Temp = (reference[reference_off - 32] * filter0) +
192 | (reference[reference_off - 16] * filter1) +
193 | (reference[reference_off] * filter2) +
194 | (reference[reference_off + 16] * filter3) +
195 | (reference[reference_off + 32] * filter4) +
196 | (reference[reference_off + 48] * filter5) +
197 | 64;
198 | Temp >>= 7;
199 | /*
200 | if (Temp < 0) {
201 | Temp = 0;
202 | } else if (Temp > 255) {
203 | Temp = 255;
204 | }
205 | */
206 |
207 | Temp = Math.min(Math.max(Temp, 0), 255);
208 | output[output_off + c] = Temp;
209 |
210 | reference_off++;
211 | }
212 |
213 | reference_off += 16 - cols;
214 | output_off += output_stride;
215 | }
216 |
217 | }
218 |
219 | function filter_block2d_second_pass_shape_1(output,
220 | output_off,
221 | output_stride,
222 | reference,
223 | cols,
224 | rows,
225 | filter
226 | ) {
227 |
228 | var reference_off = 32;
229 |
230 | var r = 0, c = 0, Temp = 0;
231 | var filter2 = filter[2] | 0;
232 | var filter3 = filter[3] | 0;
233 |
234 | for (r = 0; r < rows; r++) {
235 | for (c = 0; c < cols; c++) {
236 | Temp =
237 | (reference[reference_off] * filter2) +
238 | (reference[reference_off + 16] * filter3) +
239 | 64;
240 | Temp >>= 7;
241 |
242 | /*
243 | if (Temp < 0) {
244 | Temp = 0;
245 | } else if (Temp > 255) {
246 | Temp = 255;
247 | }
248 | */
249 | Temp = Math.min(Math.max(Temp, 0), 255);
250 |
251 | output[output_off + c] = Temp;
252 |
253 | reference_off++;
254 | }
255 |
256 | reference_off += 16 - cols;
257 | output_off += output_stride;
258 | }
259 |
260 | }
261 |
262 | function filter_block2d_second_pass_shape_2(output,
263 | output_off,
264 | output_stride,
265 | reference,
266 | cols,
267 | rows,
268 | filter
269 | ) {
270 | var r = 0, c = 0, Temp = 0;
271 |
272 | var reference_off = 32;
273 |
274 | var filter1 = filter[1] | 0;
275 | var filter2 = filter[2] | 0;
276 | var filter3 = filter[3] | 0;
277 | var filter4 = filter[4] | 0;
278 |
279 | for (r = 0; r < rows; r++) {
280 | for (c = 0; c < cols; c++) {
281 | Temp =
282 | (reference[reference_off - 16] * filter1) +
283 | (reference[reference_off] * filter2) +
284 | (reference[reference_off + 16] * filter3) +
285 | (reference[reference_off + 32] * filter4) +
286 | 64;
287 | Temp >>= 7;
288 | /*
289 | if (Temp < 0) {
290 | Temp = 0;
291 | } else if (Temp > 255) {
292 | Temp = 255;
293 | }
294 | */
295 | Temp = Math.min(Math.max(Temp, 0), 255);
296 | output[output_off + c] = Temp;
297 |
298 | reference_off++;
299 | }
300 |
301 | reference_off += 16 - cols;
302 | output_off += output_stride;
303 | }
304 | }
305 |
306 | //likely filter_block2d
307 | var temp = new Uint8Array(336);
308 |
309 | function filter_block2d(output, output_off,
310 | output_stride, reference,
311 | reference_off, reference_stride,
312 | cols, rows,
313 | mx, my, filters) {
314 |
315 |
316 | if (filters[mx].shape === 1) {
317 |
318 | filter_block2d_first_pass_shape_1(temp,
319 | reference, reference_off - 2 * reference_stride, reference_stride,
320 | filters[mx]);
321 | } else if(filters[mx].shape === 2) {
322 | filter_block2d_first_pass_shape_2(temp,
323 | reference, reference_off - 2 * reference_stride, reference_stride,
324 | filters[mx]);
325 | } else {
326 | filter_block2d_first_pass(temp,
327 | reference, reference_off - 2 * reference_stride, reference_stride,
328 | filters[mx]);
329 | }
330 |
331 | if (filters[my].shape === 1) {
332 |
333 | filter_block2d_second_pass_shape_1(output, output_off, output_stride,
334 | temp, 4, 4, filters[my]);
335 | } else if (filters[my].shape === 2) {
336 | filter_block2d_second_pass_shape_2(output, output_off, output_stride,
337 | temp, 4, 4, filters[my]);
338 | } else {
339 | filter_block2d_second_pass(output, output_off, output_stride,
340 | temp, 4, 4, filters[my]);
341 | }
342 |
343 |
344 | }
345 |
346 |
347 |
348 | //subpixel_predict
349 | function filter_block(return_off,
350 | output,
351 | output_off,
352 | reference,
353 | reference_off,
354 | stride,
355 | mv_,
356 | filters) {
357 |
358 | //reference_off += ((mv_.y >> 3) * stride) + (mv_.x >> 3);
359 |
360 | if (mv_.as_int[0])
361 | {
362 | filter_block2d(output, output_off, stride, reference, reference_off, stride, 4, 4, mv_.x & 7, mv_.y & 7,
363 | filters);
364 |
365 | }
366 |
367 |
368 | }
369 |
370 | module.exports = {};
371 | module.exports.vp8_sub_pel_filters = vp8_sub_pel_filters;
372 | module.exports.vp8_bilinear_filters = vp8_bilinear_filters;
373 | module.exports.filter_block2d_first_pass = filter_block2d_first_pass;
374 | module.exports.filter_block2d_second_pass = filter_block2d_second_pass;
375 | module.exports.sixtap_2d = filter_block2d;
376 | module.exports.filter_block = filter_block;
377 | module.exports.filter_block2d = filter_block2d;
378 |
--------------------------------------------------------------------------------
/vp8/common/findnearmv.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var MotionVector = require('./mv.js');
3 |
4 | var DC_PRED = 0;
5 | var V_PRED = 1;
6 | var H_PRED = 2;
7 | var TM_PRED = 3;
8 | var B_PRED = 4;
9 |
10 | var DC_PRED = 0;
11 | var V_PRED = 1;
12 | var H_PRED = 2;
13 | var TM_PRED = 3;
14 | var B_PRED = 4;
15 |
16 |
17 | var B_DC_PRED = 0; /* average of above and left pixels */
18 | var B_TM_PRED = 1;
19 | var B_VE_PRED = 2; /* vertical prediction */
20 | var B_HE_PRED = 3; /* horizontal prediction */
21 |
22 |
23 | function mv_bias(mb, sign_bias, ref_frame, mv) {
24 |
25 | if (sign_bias[mb.mbmi.ref_frame] ^ sign_bias[ref_frame]) {
26 | mv.as_row_col[0] *= -1;
27 | mv.as_row_col[1] *= -1;
28 | }
29 |
30 | }
31 |
32 | function above_block_mode(cur_mb, cur_mb_ptr, b, mi_stride) {
33 |
34 | if (!(b >> 2)) {
35 |
36 | cur_mb_ptr -= mi_stride;
37 |
38 | switch (cur_mb[cur_mb_ptr].mbmi.y_mode) {
39 | case B_PRED: return cur_mb[cur_mb_ptr].bmi.modes[b + 12];
40 | case DC_PRED: return B_DC_PRED;
41 | case V_PRED: return B_VE_PRED;
42 | case H_PRED: return B_HE_PRED;
43 | case TM_PRED: return B_TM_PRED;
44 | default: return B_DC_PRED;
45 | }
46 | }
47 |
48 | return cur_mb[cur_mb_ptr].bmi.modes[b - 4];
49 | }
50 |
51 |
52 |
53 | function left_block_mode(cur_mb, cur_mb_ptr, b) {
54 |
55 | if (!(b & 3)){
56 | cur_mb_ptr -= 1;
57 | switch (cur_mb[cur_mb_ptr].mbmi.y_mode) {
58 | case DC_PRED: return B_DC_PRED;
59 | case V_PRED: return B_VE_PRED;
60 | case H_PRED: return B_HE_PRED;
61 | case TM_PRED: return B_TM_PRED;
62 | case B_PRED: return cur_mb[cur_mb_ptr].bmi.modes[b + 3];
63 | default: return B_DC_PRED;
64 | }
65 | }
66 |
67 | return cur_mb[cur_mb_ptr].bmi.modes[b - 1];
68 | }
69 |
70 | module.exports = {};
71 | module.exports.left_block_mode = left_block_mode;
72 | module.exports.above_block_mode = above_block_mode;
--------------------------------------------------------------------------------
/vp8/common/idctllm.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 |
4 |
5 |
6 | function CLAMP_255(x) {
7 | return Math.min(Math.max(x, 0), 255);
8 | }
9 |
10 | var cospi8sqrt2minus1 = 20091;
11 | var sinpi8sqrt2 = 35468; // (<<15 + 2700)
12 | var output = new Int16Array(16);
13 | var output_32 = new Uint32Array(output.buffer);
14 | var output_32_i = new Int32Array(output.buffer);
15 | output.data_32 = output_32;
16 | output.data_32_i = output_32_i;
17 | //
18 | //vp8_short_inv_walsh4x4_c
19 | function vp8_short_inv_walsh4x4_c(input, input_off, mb_dqcoeff_ptr) {
20 |
21 | //var mb_dqcoeff_ptr = input_off;
22 |
23 | var output_off = 0;
24 | var i;
25 | var a1, b1, c1, d1;
26 | var a2, b2, c2, d2;
27 | var ip = input;
28 | var ip_off = input_off;
29 | var op = output;
30 | var op_off = 0;
31 |
32 | var ip0 = 0;
33 | var ip1 = 0;
34 | var ip2 = 0;
35 | var ip3 = 0;
36 | var ip12 = 0;
37 | var ip8 = 0;
38 | var ip4 = 0;
39 |
40 | for (i = 0; i < 4; i++)
41 | {
42 | ip0 = ip[ip_off];
43 | ip4 = ip[ip_off + 4];
44 | ip8 = ip[ip_off + 8];
45 | ip12 = ip[ip_off + 12];
46 |
47 |
48 | a1 = (ip0 + ip12) | 0;
49 | b1 = (ip4 + ip8) | 0;
50 | c1 = (ip4 - ip8) | 0;
51 | d1 = (ip0 - ip12) | 0;
52 |
53 | op[op_off] = a1 + b1;
54 | op[op_off + 4] = c1 + d1;
55 | op[op_off + 8] = a1 - b1;
56 | op[op_off + 12] = d1 - c1;
57 | ip_off++;
58 | op_off++;
59 | }
60 |
61 |
62 |
63 | ip = output;
64 | ip_off = output_off;
65 | op = output;
66 | op_off = output_off;
67 |
68 | var data_32 = ip.data_32;
69 | var ip_32 = 0;
70 | /*
71 | for (i = 0; i < 4; i++)
72 | {
73 |
74 | ip_32 = data_32[ip_off >> 1];
75 | ip1 = ((ip_32 >> 16));
76 | ip0 = ((ip_32 << 16) >> 16);
77 |
78 | ip_32 = data_32[(ip_off + 2) >> 1];
79 | ip3 = ((ip_32 >> 16));
80 | ip2 = ((ip_32 << 16) >> 16);
81 |
82 | a1 = ip0 + ip3;
83 | b1 = ip1 + ip2;
84 | c1 = ip1 - ip2;
85 | d1 = ip0 - ip3;
86 |
87 | a2 = a1 + b1;
88 | b2 = c1 + d1;
89 | c2 = a1 - b1;
90 | d2 = d1 - c1;
91 |
92 | output_32[op_off >> 1] = ((a2 + 3) >> 3) & 0xFFFF | (((b2 + 3) >> 3) << 16);
93 | output_32[(op_off + 2) >> 1] = ((c2 + 3) >> 3) & 0xFFFF | (((d2 + 3) >> 3) << 16);
94 |
95 |
96 | ip_off += 4;
97 | op_off += 4;
98 | }*/
99 | var output_off_32 = op_off >> 1;
100 | var ip_off_32 = ip_off >> 1;
101 | //Loop 1
102 | ip_32 = data_32[ip_off_32];
103 | ip1 = ((ip_32 >> 16));
104 | ip0 = ((ip_32 << 16) >> 16);
105 |
106 | ip_32 = data_32[ip_off_32 + 1];
107 | ip3 = ((ip_32 >> 16));
108 | ip2 = ((ip_32 << 16) >> 16);
109 |
110 | a1 = ip0 + ip3;
111 | b1 = ip1 + ip2;
112 | c1 = ip1 - ip2;
113 | d1 = ip0 - ip3;
114 |
115 | a2 = a1 + b1;
116 | b2 = c1 + d1;
117 | c2 = a1 - b1;
118 | d2 = d1 - c1;
119 |
120 | output_32[output_off_32] = ((a2 + 3) >> 3) & 0xFFFF | (((b2 + 3) >> 3) << 16);
121 | output_32[output_off_32 + 1] = ((c2 + 3) >> 3) & 0xFFFF | (((d2 + 3) >> 3) << 16);
122 |
123 |
124 |
125 | //Loop 2
126 | ip_32 = data_32[ip_off_32 + 2];
127 | ip1 = ((ip_32 >> 16));
128 | ip0 = ((ip_32 << 16) >> 16);
129 |
130 | ip_32 = data_32[ip_off_32 + 3];
131 | ip3 = ((ip_32 >> 16));
132 | ip2 = ((ip_32 << 16) >> 16);
133 |
134 | a1 = ip0 + ip3;
135 | b1 = ip1 + ip2;
136 | c1 = ip1 - ip2;
137 | d1 = ip0 - ip3;
138 |
139 | a2 = a1 + b1;
140 | b2 = c1 + d1;
141 | c2 = a1 - b1;
142 | d2 = d1 - c1;
143 |
144 | output_32[output_off_32 + 2] = ((a2 + 3) >> 3) & 0xFFFF | (((b2 + 3) >> 3) << 16);
145 | output_32[output_off_32 + 3] = ((c2 + 3) >> 3) & 0xFFFF | (((d2 + 3) >> 3) << 16);
146 |
147 |
148 |
149 |
150 | //Loop 3
151 | ip_32 = data_32[ip_off_32 + 4];
152 | ip1 = ((ip_32 >> 16));
153 | ip0 = ((ip_32 << 16) >> 16);
154 |
155 | ip_32 = data_32[ip_off_32 + 5];
156 | ip3 = ((ip_32 >> 16));
157 | ip2 = ((ip_32 << 16) >> 16);
158 |
159 | a1 = ip0 + ip3;
160 | b1 = ip1 + ip2;
161 | c1 = ip1 - ip2;
162 | d1 = ip0 - ip3;
163 |
164 | a2 = a1 + b1;
165 | b2 = c1 + d1;
166 | c2 = a1 - b1;
167 | d2 = d1 - c1;
168 |
169 | output_32[output_off_32 + 4] = ((a2 + 3) >> 3) & 0xFFFF | (((b2 + 3) >> 3) << 16);
170 | output_32[output_off_32 + 5] = ((c2 + 3) >> 3) & 0xFFFF | (((d2 + 3) >> 3) << 16);
171 |
172 |
173 |
174 | //loop 4
175 | ip_32 = data_32[ip_off_32 + 6];
176 | ip1 = ((ip_32 >> 16));
177 | ip0 = ((ip_32 << 16) >> 16);
178 |
179 | ip_32 = data_32[ip_off_32 + 7];
180 | ip3 = ((ip_32 >> 16));
181 | ip2 = ((ip_32 << 16) >> 16);
182 |
183 | a1 = ip0 + ip3;
184 | b1 = ip1 + ip2;
185 | c1 = ip1 - ip2;
186 | d1 = ip0 - ip3;
187 |
188 | a2 = a1 + b1;
189 | b2 = c1 + d1;
190 | c2 = a1 - b1;
191 | d2 = d1 - c1;
192 |
193 | output_32[output_off_32 + 6] = ((a2 + 3) >> 3) & 0xFFFF | (((b2 + 3) >> 3) << 16);
194 | output_32[output_off_32 + 7] = ((c2 + 3) >> 3) & 0xFFFF | (((d2 + 3) >> 3) << 16);
195 |
196 |
197 |
198 | //var mb_dqcoeff = input;
199 |
200 | //for (i = 0; i < 16; i++) {
201 | //coeffs[coeffs_off + i * 16] = y2[i]; //no y2_off need
202 | // input[mb_dqcoeff_ptr + (i << 4)] = output[i];
203 | //}
204 | input[mb_dqcoeff_ptr + 0] = output[0];
205 | input[mb_dqcoeff_ptr + 16] = output[1];
206 | input[mb_dqcoeff_ptr + 32] = output[2];
207 | input[mb_dqcoeff_ptr + 48] = output[3];
208 | input[mb_dqcoeff_ptr + 64] = output[4];
209 | input[mb_dqcoeff_ptr + 80] = output[5];
210 | input[mb_dqcoeff_ptr + 96] = output[6];
211 | input[mb_dqcoeff_ptr + 112] = output[7];
212 | input[mb_dqcoeff_ptr + 128] = output[8];
213 | input[mb_dqcoeff_ptr + 144] = output[9];
214 | input[mb_dqcoeff_ptr + 160] = output[10];
215 | input[mb_dqcoeff_ptr + 176] = output[11];
216 | input[mb_dqcoeff_ptr + 192] = output[12];
217 | input[mb_dqcoeff_ptr + 208] = output[13];
218 | input[mb_dqcoeff_ptr + 224] = output[14];
219 | input[mb_dqcoeff_ptr + 240] = output[15];
220 |
221 | }
222 |
223 | var tmp = new Int16Array(16);
224 | var shortpitch = 4;
225 | var shortpitch2 = 8;
226 | var shortpitch3 = 12;
227 |
228 | function vp8_short_idct4x4llm_c(recon, recon_off, predict, predict_off, stride, coeffs, coeffs_off) {
229 |
230 | var i = 0;
231 | var a1 = 0, b1 = 0, c1 = 0, d1 = 0, temp1 = 0, temp2 = 0;
232 | var tmp_off = 0;
233 |
234 |
235 |
236 | //START IDCT
237 | var ip = coeffs;
238 | var ip_off = coeffs_off;
239 | var op = tmp;
240 | var op_off = tmp_off;
241 |
242 |
243 | for (i = 0; i < 4; i++) {
244 | var ip_0 = ip[ip_off];
245 | var ip_4 = ip[ip_off + 4];
246 | var ip_12 = ip[ip_off + 12];
247 | var ip_8 = ip[ip_off + 8];
248 |
249 | a1 = ip_0 + ip_8;
250 | b1 = ip_0 - ip_8;
251 |
252 | temp1 = (ip_4 * sinpi8sqrt2) >> 16;
253 | temp2 = ip_12 + ((ip_12 * cospi8sqrt2minus1/* + rounding */) >> 16);
254 | c1 = temp1 - temp2;
255 |
256 | temp1 = ip_4 + ((ip_4 * cospi8sqrt2minus1) >> 16);
257 | temp2 = (ip_12 * sinpi8sqrt2) >> 16;
258 | d1 = temp1 + temp2;
259 |
260 | op[op_off] = a1 + d1;
261 | op[op_off + shortpitch3] = a1 - d1;
262 |
263 | op[op_off + shortpitch] = b1 + c1;
264 | op[op_off + shortpitch2] = b1 - c1;
265 |
266 | ip_off++;
267 | op_off++;
268 | }
269 |
270 | //END IDCT
271 |
272 | coeffs = tmp;
273 | coeffs_off = tmp_off;
274 | var recon_32 = recon.data_32;
275 | var r0, r1, r2, r3;
276 | var p0, p1, p2, p3;
277 | var p32;
278 |
279 | for (i = 0; i < 4; i++) {
280 |
281 |
282 | var coeffs_0 = coeffs[coeffs_off];
283 | var coeff_1 = coeffs[coeffs_off + 1];
284 | var coeffs_2 = coeffs[coeffs_off + 2];
285 | var coeff_3 = coeffs[coeffs_off + 3];
286 |
287 |
288 |
289 | a1 = coeffs_0 + coeffs_2;
290 | b1 = coeffs_0 - coeffs_2;
291 |
292 | temp1 = (coeff_1 * sinpi8sqrt2) >> 16;
293 | temp2 = coeff_3 + ((coeff_3 * cospi8sqrt2minus1) >> 16);
294 | c1 = temp1 - temp2;
295 |
296 | temp1 = coeff_1 + ((coeff_1 * cospi8sqrt2minus1) >> 16);
297 | temp2 = (coeff_3 * sinpi8sqrt2) >> 16;
298 | d1 = temp1 + temp2;
299 |
300 |
301 | p0 = predict[predict_off];
302 | p1 = predict[predict_off + 1];
303 | p2 = predict[predict_off + 2];
304 | p3 = predict[predict_off + 3];
305 |
306 |
307 |
308 | r0 = CLAMP_255(p0 + ((a1 + d1 + 4) >> 3));
309 | r1 = CLAMP_255(p1 + ((b1 + c1 + 4) >> 3));
310 | r2 = CLAMP_255(p2 + ((b1 - c1 + 4) >> 3));
311 | r3 = CLAMP_255(p3 + ((a1 - d1 + 4) >> 3));
312 | recon_32[recon_off >> 2] = r0 | r1 << 8 | r2 << 16 | r3 << 24;
313 |
314 |
315 |
316 | coeffs_off += 4;
317 | recon_off += stride;
318 | predict_off += stride;
319 | }
320 |
321 | //clamp might be at the end
322 | }
323 |
324 | module.exports = {};
325 | module.exports.vp8_short_inv_walsh4x4_c = vp8_short_inv_walsh4x4_c;
326 | module.exports.vp8_short_idct4x4llm_c = vp8_short_idct4x4llm_c;
327 |
--------------------------------------------------------------------------------
/vp8/common/loopfilter_filters.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | //var abs = Math.abs;
4 |
5 | function abs(value ){
6 | return (value ^ (value >> 31)) - (value >> 31);
7 | }
8 |
9 | function saturate_int8(x) {
10 |
11 | //return min(max(x, -128), 127);
12 | return Math.min(Math.max(x, -128), 127);
13 |
14 | }
15 |
16 | function saturate_uint8(x) {
17 | //return min(max(x, 0), 255);
18 | return Math.min(Math.max(x, 0), 255);
19 | }
20 |
21 | //possible vp8_simple_filter
22 | function vp8_filter(pixels, pixels_off, stride, use_outer_taps) {
23 | var stride2 = 2 * stride;
24 | var p1 = pixels[pixels_off - stride2];
25 | var p0 = pixels[pixels_off - stride];
26 | var q0 = pixels[pixels_off];
27 | var q1 = pixels[pixels_off + stride];
28 |
29 | var a = 0;
30 | var f1 = 0;
31 | var f2 = 0;
32 |
33 | a = 3 * (q0 - p0);
34 |
35 | if (use_outer_taps)
36 | a += saturate_int8(p1 - q1);
37 |
38 | a = saturate_int8(a);
39 |
40 |
41 | if((a + 4) > 127){
42 | f1 = 15;
43 | f2 = 15;
44 | }else{
45 | f1 = (a + 4) >> 3;
46 | f2 = (a + 3) >> 3;
47 | }
48 |
49 |
50 | p0 = saturate_uint8(p0 + f2);
51 | q0 = saturate_uint8(q0 - f1);
52 |
53 | if (!use_outer_taps)
54 | {
55 |
56 | a = (f1 + 1) >> 1;
57 | p1 = saturate_uint8(p1 + a);
58 | q1 = saturate_uint8(q1 - a);
59 | }
60 |
61 | pixels[pixels_off - stride2] = p1;
62 | pixels[pixels_off - stride] = p0;
63 | pixels[pixels_off] = q0;
64 | pixels[pixels_off + stride] = q1;
65 | }
66 |
67 | function vp8_filter_2(pixels, pixels_off, use_outer_taps) {
68 | //console.warn(pixels_off);
69 | var pixels_16 = pixels.data_16[(pixels_off - 2)/2];
70 | var p1 = pixels_16 & 0xFF;
71 | var p0 = (pixels_16 >> 8 )& 0xFF;
72 |
73 | pixels_16 = pixels.data_16[(pixels_off)/2];
74 | var q0 = pixels_16 & 0xFF;
75 | var q1 = (pixels_16 >> 8 )& 0xFF;
76 |
77 | var a = 0;
78 | var f1 = 0;
79 | var f2 = 0;
80 |
81 | a = 3 * (q0 - p0);
82 |
83 | if (use_outer_taps)
84 | a += saturate_int8(p1 - q1);
85 |
86 | a = saturate_int8(a);
87 |
88 |
89 | if((a + 4) > 127){
90 | f1 = 15;
91 | f2 = 15;
92 | }else{
93 | f1 = (a + 4) >> 3;
94 | f2 = (a + 3) >> 3;
95 | }
96 |
97 |
98 | p0 = saturate_uint8(p0 + f2);
99 | q0 = saturate_uint8(q0 - f1);
100 |
101 | if (!use_outer_taps)
102 | {
103 |
104 | a = (f1 + 1) >> 1;
105 | p1 = saturate_uint8(p1 + a);
106 | q1 = saturate_uint8(q1 - a);
107 | }
108 |
109 | pixels[pixels_off - 2] = p1;
110 | pixels[pixels_off - 1] = p0;
111 | pixels[pixels_off] = q0;
112 | pixels[pixels_off + 1] = q1;
113 | }
114 |
115 |
116 | //vp8_loop_filter_simple_bh
117 | function vp8_loop_filter_bhs_c(y, y_ptr, y_stride, blimit) {
118 | vp8_loop_filter_simple_horizontal_edge_c(y, y_ptr + 4 * y_stride, y_stride, blimit);
119 | vp8_loop_filter_simple_horizontal_edge_c(y, y_ptr + 8 * y_stride, y_stride, blimit);
120 | vp8_loop_filter_simple_horizontal_edge_c(y, y_ptr + 12 * y_stride, y_stride, blimit);
121 | }
122 |
123 | //vp8_loop_filter_mbh_c
124 |
125 | function vp8_loop_filter_simple_horizontal_edge_c(src, src_off, stride, filter_limit) {
126 | var i = 0;
127 |
128 | for (i = 0; i < 16; i++) {
129 | if (simple_threshold(src, src_off, stride, filter_limit) === 1)
130 | vp8_filter(src, src_off, stride, 1);
131 |
132 | src_off += 1;
133 | }
134 | }
135 |
136 | function simple_threshold(pixels, pixels_off, stride, filter_limit) {
137 | var p1 = pixels[pixels_off - (stride << 1)];
138 | var p0 = pixels[pixels_off - stride];
139 | var q0 = pixels[pixels_off];
140 | var q1 = pixels[pixels_off + stride];
141 |
142 | return (((abs(p0 - q0) << 1) + (abs(p1 - q1) >> 1)) <= filter_limit) | 0;
143 | }
144 |
145 | function vp8_loop_filter_bvs_c(y, y_off, stride, b_limit) {
146 | vp8_loop_filter_simple_vertical_edge_c(y, y_off + 4, stride, b_limit);
147 | vp8_loop_filter_simple_vertical_edge_c(y, y_off + 8, stride, b_limit);
148 | vp8_loop_filter_simple_vertical_edge_c(y, y_off + 12, stride, b_limit);
149 | }
150 |
151 | function vp8_loop_filter_simple_vertical_edge_c(src, src_off, stride, filter_limit) {
152 | var i = 0;
153 |
154 | for (i = 0; i < 16; i++) {
155 | if (simple_threshold(src, src_off, 1, filter_limit))
156 | vp8_filter(src, src_off, 1, 1);
157 |
158 | src_off += stride;
159 | }
160 | }
161 | /*
162 | function vp8_loop_filter_simple_horizontal_edge_c(src, src_off, stride, filter_limit) {
163 |
164 | var i = 0;
165 |
166 | for (i = 0; i < 16; i++) {
167 | if (simple_threshold(src, src_off, 1, filter_limit))
168 | vp8_filter(src, src_off, 1, 1);
169 |
170 | src_off += stride;
171 |
172 | }
173 |
174 | }
175 | */
176 |
177 | function vp8_loop_filter_mbv(y, y_off, u_off, v_off, stride, uv_stride, edge_limit, interior_limit, hev_threshold) {
178 | //vp8_loop_filter_mbv
179 | filter_mb_v_edge(y, y_off, stride, edge_limit + 2,
180 | interior_limit, hev_threshold, 2);
181 | filter_mb_v_edge(y, u_off, uv_stride, edge_limit + 2,
182 | interior_limit, hev_threshold, 1);
183 | filter_mb_v_edge(y, v_off, uv_stride, edge_limit + 2,
184 | interior_limit, hev_threshold, 1);
185 | }
186 |
187 | function filter_mb_v_edge(src,
188 | src_off,
189 | stride,
190 | edge_limit,
191 | interior_limit,
192 | hev_threshold,
193 | size) {
194 | var i = 0;
195 |
196 | var length = size << 3;
197 | for (i = 0; i < length; i++) {
198 | if (normal_threshold(src, src_off, 1, edge_limit, interior_limit)) {
199 | if (high_edge_variance(src, src_off, 1, hev_threshold))
200 | vp8_filter(src, src_off, 1 , 1);
201 | else
202 | filter_mb_edge(src, src_off, 1);
203 | }
204 |
205 | src_off += stride;
206 | }
207 | }
208 |
209 |
210 | function normal_threshold(pixels, pixels_off, stride, E, I) {
211 |
212 | if (simple_threshold(pixels, pixels_off, stride, 2 * E + I) === 0)
213 | return 0;
214 |
215 | var p3 = pixels[pixels_off - 4 * stride];
216 | var p2 = pixels[pixels_off - 3 * stride];
217 |
218 | if (abs(p3 - p2) > I)
219 | return 0;
220 |
221 | var p1 = pixels[pixels_off - 2 * stride];
222 |
223 |
224 | if (abs(p2 - p1) > I)
225 | return 0;
226 |
227 | var p0 = pixels[pixels_off - stride];
228 |
229 | if(abs(p1 - p0) > I)
230 | return 0;
231 |
232 | var q2 = pixels[pixels_off + 2 * stride];
233 | var q3 = pixels[pixels_off + 3 * stride];
234 |
235 | if(abs(q3 - q2) > I)
236 | return 0;
237 |
238 | var q0 = pixels[pixels_off];
239 | var q1 = pixels[pixels_off + stride];
240 |
241 | if(abs(q2 - q1) > I)
242 | return 0;
243 |
244 |
245 | return abs(q1 - q0) <= I;
246 |
247 | }
248 |
249 |
250 | //vp8_mbfilter
251 | function filter_mb_edge(pixels, pixels_off, stride) {
252 | //var p3 = pixels[pixels_off -4*stride];
253 |
254 | var stride2 = stride << 1;
255 | var stride3 = 3 * stride;
256 |
257 | var p2 = pixels[pixels_off - stride3];
258 | var p1 = pixels[pixels_off - stride2];
259 | var p0 = pixels[pixels_off - stride];
260 | var q0 = pixels[pixels_off];
261 | var q1 = pixels[pixels_off + stride];
262 | var q2 = pixels[pixels_off + stride2];
263 | var w = 0, a = 0;
264 |
265 | w = saturate_int8(saturate_int8(p1 - q1) + 3 * (q0 - p0));
266 |
267 | a = (27 * w + 63) >> 7;
268 | p0 = saturate_uint8(p0 + a);
269 | q0 = saturate_uint8(q0 - a);
270 |
271 | a = (18 * w + 63) >> 7;
272 | p1 = saturate_uint8(p1 + a);
273 | q1 = saturate_uint8(q1 - a);
274 |
275 | a = (9 * w + 63) >> 7;
276 | p2 = saturate_uint8(p2 + a);
277 | q2 = saturate_uint8(q2 - a);
278 |
279 | pixels[pixels_off - stride3] = p2;
280 | pixels[pixels_off - stride2] = p1;
281 | pixels[pixels_off - stride] = p0;
282 | pixels[pixels_off] = q0;
283 | pixels[pixels_off + stride] = q1;
284 | pixels[pixels_off + stride2] = q2;
285 |
286 | }
287 |
288 |
289 | function high_edge_variance(pixels, pixels_off, stride, hev_threshold) {
290 |
291 | var p1 = pixels[pixels_off - 2 * stride];
292 | var p0 = pixels[pixels_off - stride];
293 |
294 |
295 | if(abs(p1 - p0) > hev_threshold)
296 | return 1;
297 |
298 | var q0 = pixels[pixels_off];
299 | var q1 = pixels[pixels_off + stride];
300 |
301 | return abs(q1 - q0) > hev_threshold;
302 |
303 | }
304 |
305 | function vp8_loop_filter_bv_c(y, y_off, u_off, v_off, stride, uv_stride, edge_limit, interior_limit, hev_threshold) {
306 | var dat = y;
307 | filter_subblock_v_edge(y, y_off + 4, stride, edge_limit,
308 | interior_limit, hev_threshold, 2);
309 |
310 | filter_subblock_v_edge(dat, y_off + 8, stride, edge_limit,
311 | interior_limit, hev_threshold, 2);
312 |
313 | filter_subblock_v_edge(dat, y_off + 12, stride, edge_limit,
314 | interior_limit, hev_threshold, 2);
315 |
316 | filter_subblock_v_edge(dat, u_off + 4, uv_stride, edge_limit,
317 | interior_limit, hev_threshold, 1);
318 |
319 | filter_subblock_v_edge(dat, v_off + 4, uv_stride, edge_limit,
320 | interior_limit, hev_threshold, 1);
321 | }
322 |
323 |
324 | function filter_subblock_v_edge(src, src_off, stride, edge_limit, interior_limit, hev_threshold, size) {
325 | var i = 0;
326 | var limit = 8 * size;
327 | for (i = 0; i < limit; i++) {
328 |
329 | if (normal_threshold(src, src_off, 1, edge_limit, interior_limit))
330 |
331 | vp8_filter(src, src_off, 1, high_edge_variance(src, src_off, 1, hev_threshold));
332 |
333 |
334 | src_off += stride;
335 | }
336 |
337 |
338 | }
339 |
340 | module.exports = {};
341 | module.exports.vp8_filter = vp8_filter;
342 | module.exports.vp8_loop_filter_bhs_c = vp8_loop_filter_bhs_c;
343 | module.exports.vp8_loop_filter_bvs_c = vp8_loop_filter_bvs_c;
344 | module.exports.vp8_loop_filter_simple_horizontal_edge_c = vp8_loop_filter_simple_horizontal_edge_c;
345 | module.exports.vp8_loop_filter_simple_vertical_edge_c = vp8_loop_filter_simple_vertical_edge_c;
346 | module.exports.vp8_loop_filter_mbv = vp8_loop_filter_mbv;
347 | module.exports.vp8_loop_filter_bv_c = vp8_loop_filter_bv_c;
348 | module.exports.filter_mb_edge = filter_mb_edge;
349 | module.exports.normal_threshold = normal_threshold;
350 | module.exports.high_edge_variance = high_edge_variance;
--------------------------------------------------------------------------------
/vp8/common/modecont.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /*
3 | var vp8_mode_contexts =
4 | [
5 | new Uint8Array([7, 1, 1, 143]),
6 | new Uint8Array([14, 18, 14, 107]),
7 | new Uint8Array([135, 64, 57, 68]),
8 | new Uint8Array([60, 56, 128, 65]),
9 | new Uint8Array([159, 134, 128, 34]),
10 | new Uint8Array([234, 188, 128, 28])
11 |
12 | ];
13 | */
14 | var vp8_mode_contexts = new Uint8Array(
15 | [7, 1, 1, 143,
16 | 14, 18, 14, 107,
17 | 135, 64, 57, 68,
18 | 60, 56, 128, 65,
19 | 159, 134, 128, 34,
20 | 234, 188, 128, 28]);
21 | module.exports = vp8_mode_contexts;
--------------------------------------------------------------------------------
/vp8/common/mv.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | class MotionVector {
4 |
5 | constructor() {
6 | this.as_row_col = new Int16Array(2);
7 | this.as_int = new Uint32Array(this.as_row_col.buffer);
8 | }
9 |
10 | static create(){
11 | var as_row_col = new Int16Array(2);
12 | var as_int = new Uint32Array(as_row_col.buffer);
13 | return {
14 | 'as_row_col' : as_row_col,
15 | 'as_int' : as_int
16 | };
17 | }
18 | }
19 |
20 | module.exports = MotionVector;
--------------------------------------------------------------------------------
/vp8/common/onyxc_int.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var MV_PROB_CNT =19;
4 |
5 | class FRAME_CONTEXT {
6 | //FRAME_CONTEXT
7 | constructor(decoder) {
8 | this.decoder = decoder;
9 | //coeff_probs [BLOCK_TYPES][COEFF_BANDS]
10 | //[PREV_COEFF_CONTEXTS][ENTROPY_NODES]
11 | //Coeff probs gets treated as a pointer later so cant use multi array anyway
12 | this.coeff_probs = new Uint8Array(1056);
13 | this.coeff_probs.data_32 = new Uint32Array(this.coeff_probs.buffer);
14 | this.coeff_probs.data_64 = new Float64Array(this.coeff_probs.buffer);
15 |
16 | //MV_CONTEXT
17 | this.mv_probs = [
18 | new Uint8Array(MV_PROB_CNT), //mv_component_probs_t
19 | new Uint8Array(MV_PROB_CNT) //mv_component_probs_t
20 | ];
21 | this.coeff_skip_enabled = 0;
22 | this.coeff_skip_prob = 0;
23 | this.y_mode_probs = new Uint8Array(4);
24 | this.y_mode_probs_32 = new Uint32Array(this.y_mode_probs.buffer);
25 | this.uv_mode_probs = new Uint8Array(3);
26 | this.prob_inter = 0;
27 | this.prob_last = 0;
28 | this.prob_gf = 0;
29 |
30 | }
31 |
32 | }
33 | var RECON_CLAMP_NOTREQUIRED = 0;
34 | var RECON_CLAMP_REQUIRED = 1
35 |
36 | var NORMAL_LOOPFILTER = 0;
37 | var SIMPLE_LOOPFILTER = 1;
38 |
39 | var NUM_YV12_BUFFERS = 4;
40 |
41 |
42 | /**
43 | * @classdesc VP8Common
44 | * merge all other headers here
45 | * alias VP8_COMMON
46 | * vpx_codec_ctx_t
47 | * file onyxc_int.h
48 | * @property {number} is_keyframe is it a keyframe
49 | * @property {number} show_frame should the frame be shown
50 | * @property {number} part0_sz the partition size of 0
51 | * @property {number} frame_size_updated indicates if need a resolution update
52 | */
53 | class VP8_COMMON {
54 |
55 |
56 | constructor() {
57 |
58 | this.error;
59 |
60 | this.Width = 0;
61 | this.Height = 0;
62 | this.horiz_scale = 0;
63 | this.vert_scale = 0;
64 |
65 | this.frame_to_show;
66 | this.yv12_fb = new Array(NUM_YV12_BUFFERS);
67 | this.fb_idx_ref_cnt = [0 ,0 ,0 ,0];
68 |
69 | this.clamp_type = RECON_CLAMP_NOTREQUIRED;
70 |
71 | this.entropy_hdr = new FRAME_CONTEXT();
72 | this.saved_entropy = new FRAME_CONTEXT();
73 |
74 |
75 | this.is_keyframe = 0;
76 | this.is_experimental = 0;
77 |
78 | this.show_frame = 0;
79 |
80 |
81 |
82 | this.frame_size_updated = 0;
83 |
84 | this.mode_info_stride = 0;
85 |
86 | //line 108
87 | this.base_qindex = 0;
88 |
89 | this.delta_update = 0;
90 |
91 |
92 | this.y1dc_delta_q = 0;
93 | this.y2dc_delta_q = 0;
94 | this.y2ac_delta_q = 0;
95 | this.uvdc_delta_q = 0;
96 | this.uvac_delta_q = 0;
97 |
98 | this.mip; // MODE_INFO
99 | this.mi; //MODE_INFO
100 | this.prev_mip;
101 | this.prev_mi;
102 |
103 | this.show_frame_mi;
104 |
105 | //Filter information
106 | this.filter_type = NORMAL_LOOPFILTER;
107 |
108 |
109 |
110 | this.lf_info = null;
111 |
112 | this.level = 0;
113 | this.sharpness = 0;
114 | this.last_sharpness_level = 0;
115 |
116 | this.delta_enabled = 0;
117 | this.ref_delta = new Int32Array(4);
118 | this.mode_delta = new Int32Array(4);
119 |
120 | //reference information
121 | this.refresh_last = 0;
122 | this.refresh_gf = 0;
123 | this.refresh_arf = 0;
124 |
125 | this.copy_gf = 0;
126 | this.copy_arf = 0;
127 |
128 | this.refresh_entropy_probs = 0;
129 |
130 | this.sign_bias = new Int32Array(4);
131 |
132 |
133 | this.current_video_frame = 0;
134 |
135 | this.version = 0;
136 | }
137 |
138 | }//vpx_codec_ctx_t
139 |
140 |
141 | module.exports = VP8_COMMON;
--------------------------------------------------------------------------------
/vp8/common/quant_common.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var dc_qlookup =
4 | new Int32Array([
5 | 4, 5, 6, 7, 8, 9, 10, 10,
6 | 11, 12, 13, 14, 15, 16, 17, 17,
7 | 18, 19, 20, 20, 21, 21, 22, 22,
8 | 23, 23, 24, 25, 25, 26, 27, 28,
9 | 29, 30, 31, 32, 33, 34, 35, 36,
10 | 37, 37, 38, 39, 40, 41, 42, 43,
11 | 44, 45, 46, 46, 47, 48, 49, 50,
12 | 51, 52, 53, 54, 55, 56, 57, 58,
13 | 59, 60, 61, 62, 63, 64, 65, 66,
14 | 67, 68, 69, 70, 71, 72, 73, 74,
15 | 75, 76, 76, 77, 78, 79, 80, 81,
16 | 82, 83, 84, 85, 86, 87, 88, 89,
17 | 91, 93, 95, 96, 98, 100, 101, 102,
18 | 104, 106, 108, 110, 112, 114, 116, 118,
19 | 122, 124, 126, 128, 130, 132, 134, 136,
20 | 138, 140, 143, 145, 148, 151, 154, 157
21 | ]);
22 |
23 | var dc_qlookup2 =
24 | new Int32Array([
25 | 4, 5, 6, 7, 8, 9, 10, 10,
26 | 11, 12, 13, 14, 15, 16, 17, 17,
27 | 18, 19, 20, 20, 21, 21, 22, 22,
28 | 23, 23, 24, 25, 25, 26, 27, 28,
29 | 29, 30, 31, 32, 33, 34, 35, 36,
30 | 37, 37, 38, 39, 40, 41, 42, 43,
31 | 44, 45, 46, 46, 47, 48, 49, 50,
32 | 51, 52, 53, 54, 55, 56, 57, 58,
33 | 59, 60, 61, 62, 63, 64, 65, 66,
34 | 67, 68, 69, 70, 71, 72, 73, 74,
35 | 75, 76, 76, 77, 78, 79, 80, 81,
36 | 82, 83, 84, 85, 86, 87, 88, 89,
37 | 91, 93, 95, 96, 98, 100, 101, 102,
38 | 104, 106, 108, 110, 112, 114, 116, 118,
39 | 122, 124, 126, 128, 130, 132, 132, 132,
40 | 132, 132, 132, 132, 132, 132, 132, 132
41 | ]);
42 |
43 | var dc_qlookup3 =
44 | new Int32Array([8,10,12,14,16,18,20,20,22,24,26,28,30,32,34,34,36,38,40,40,42,42,44,44,46,46,48,50,50,52,54,56,58,60,62,64,66,68,70,72,74,74,76,78,80,82,84,86,88,90,92,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,152,154,156,158,160,162,164,166,168,170,172,174,176,178,182,186,190,192,196,200,202,204,208,212,216,220,224,228,232,236,244,248,252,256,260,264,268,272,276,280,286,290,296,302,308,314]);
45 | //ac_q_lookup
46 | var ac_qlookup =
47 | new Int32Array([
48 | 4, 5, 6, 7, 8, 9, 10, 11,
49 | 12, 13, 14, 15, 16, 17, 18, 19,
50 | 20, 21, 22, 23, 24, 25, 26, 27,
51 | 28, 29, 30, 31, 32, 33, 34, 35,
52 | 36, 37, 38, 39, 40, 41, 42, 43,
53 | 44, 45, 46, 47, 48, 49, 50, 51,
54 | 52, 53, 54, 55, 56, 57, 58, 60,
55 | 62, 64, 66, 68, 70, 72, 74, 76,
56 | 78, 80, 82, 84, 86, 88, 90, 92,
57 | 94, 96, 98, 100, 102, 104, 106, 108,
58 | 110, 112, 114, 116, 119, 122, 125, 128,
59 | 131, 134, 137, 140, 143, 146, 149, 152,
60 | 155, 158, 161, 164, 167, 170, 173, 177,
61 | 181, 185, 189, 193, 197, 201, 205, 209,
62 | 213, 217, 221, 225, 229, 234, 239, 245,
63 | 249, 254, 259, 264, 269, 274, 279, 284
64 | ]);
65 |
66 | var ac_qlookup2 = new Int32Array([8,8,9,10,12,13,15,17,18,20,21,23,24,26,27,29,31,32,34,35,37,38,40,41,43,44,46,48,49,51,52,54,55,57,58,60,62,63,65,66,68,69,71,72,74,75,77,79,80,82,83,85,86,88,89,93,96,99,102,105,108,111,114,117,120,124,127,130,133,136,139,142,145,148,151,155,158,161,164,167,170,173,176,179,184,189,193,198,203,207,212,217,221,226,230,235,240,244,249,254,258,263,268,274,280,286,292,299,305,311,317,323,330,336,342,348,354,362,370,379,385,393,401,409,416,424,432,440]);
67 |
68 |
69 | function vp8_dc_quant(QIndex, Delta) {
70 | var retval = 0;
71 |
72 | QIndex = QIndex + Delta;
73 |
74 | if (QIndex > 127) {
75 | return 157;
76 | } else if (QIndex < 0) {
77 | return 4;
78 | }
79 |
80 | return dc_qlookup[QIndex];
81 | }
82 |
83 | function vp8_dc2quant(QIndex, Delta) {
84 | var retval = 0;
85 |
86 | QIndex = QIndex + Delta;
87 |
88 | if (QIndex > 127) {
89 | return 314;
90 | } else if (QIndex < 0) {
91 | return 8;
92 | }
93 |
94 | retval = dc_qlookup3[QIndex];
95 | return retval;
96 | }
97 |
98 | function vp8_dc_uv_quant(QIndex, Delta) {
99 | var retval = 0;
100 |
101 | QIndex = QIndex + Delta;
102 |
103 | if (QIndex > 127) {
104 | return 132;
105 | } else if (QIndex < 0) {
106 | return 4;
107 | }
108 |
109 | return dc_qlookup2[QIndex];
110 | }
111 |
112 | function vp8_ac_yquant(QIndex) {
113 | var retval = 0;
114 |
115 | if (QIndex > 127) {
116 | return 284;
117 | } else if (QIndex < 0) {
118 | return 4;
119 | }
120 |
121 | return ac_qlookup[QIndex];
122 | }
123 |
124 | function vp8_ac2quant(QIndex, Delta) {
125 | var retval = 0;
126 |
127 | QIndex = QIndex + Delta;
128 |
129 | if (QIndex > 127) {
130 | return 440;
131 | } else if (QIndex < 0) {
132 | return 8;
133 | }
134 |
135 | return ac_qlookup2[QIndex];
136 | }
137 |
138 | function vp8_ac_uv_quant(QIndex, Delta) {
139 | var retval = 0;
140 |
141 | QIndex = QIndex + Delta;
142 |
143 | if (QIndex > 127) {
144 | return 284;
145 | } else if (QIndex < 0) {
146 | return 4;
147 | }
148 |
149 | return ac_qlookup[QIndex];
150 | }
151 |
152 |
153 | module.exports = {};
154 | module.exports.vp8_dc_quant = vp8_dc_quant;
155 | module.exports.vp8_dc2quant = vp8_dc2quant;
156 | module.exports.vp8_dc_uv_quant = vp8_dc_uv_quant;
157 | module.exports.vp8_ac_yquant = vp8_ac_yquant;
158 | module.exports.vp8_ac2quant = vp8_ac2quant;
159 | module.exports.vp8_ac_uv_quant = vp8_ac_uv_quant;
--------------------------------------------------------------------------------
/vp8/common/reconinter.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var MotionVector = require('../common/mv.js');
3 |
4 | var filter = require('../common/filter.js');
5 | var filter_block2d = filter.filter_block2d;
6 |
7 | var SPLITMV = 9;
8 |
9 | var idctllm = require('../common/idctllm.js');
10 | var vp8_short_inv_walsh4x4_c = idctllm.vp8_short_inv_walsh4x4_c;
11 | var vp8_short_idct4x4llm_c = idctllm.vp8_short_idct4x4llm_c;
12 |
13 | var c_utils = require('../../util/c_utils.js');
14 | var memset = c_utils.memset;
15 | var memcpy = c_utils.memcpy;
16 |
17 |
18 |
19 |
20 | //Keep from having to redeclare this
21 | var chroma_mv = [
22 | MotionVector.create(),
23 | MotionVector.create(),
24 | MotionVector.create(),
25 | MotionVector.create()
26 | ];
27 |
28 |
29 | //build_inter_predictors4b
30 | function predict_inter_emulated_edge(ctx,
31 | img, coeffs, coeffs_off, mbi, mb_col, mb_row) {
32 |
33 |
34 | var emul_block = ctx.frame_strg[0].img.img_data;
35 | var emul_block_off = ctx.frame_strg[0].img.img_data_off;
36 |
37 | var reference = 0;
38 | var reference_off = 0;
39 | var output = 0;
40 | var output_off = 0;
41 | var reference_offset = 0;
42 | var w = 0, h = 0, x = 0, y = 0, b = 0;
43 |
44 |
45 |
46 | var ref_frame = mbi.mbmi.ref_frame;
47 |
48 | var u = img.u, v = img.v;
49 | var u_off = img.u_off;
50 | var v_off = img.v_off;
51 | var full_pixel = (ctx.common.version === 3) + 0;
52 |
53 | x = mb_col << 4;
54 | y = mb_row << 4;
55 | w = ctx.mb_cols << 4;
56 | h = ctx.mb_rows << 4;
57 |
58 | output = img.y;
59 | output_off = img.y_off;
60 |
61 | reference_off = output_off + reference_offset;
62 | var mode = mbi.mbmi.y_mode;
63 | var mvs = mbi.bmi.mvs;
64 |
65 | reference_offset = ctx.ref_frame_offsets[ref_frame];
66 | reference = ctx.ref_frame_offsets_[ref_frame];
67 |
68 |
69 |
70 | // Luma
71 | for (b = 0; b < 16; b++) {
72 |
73 | var ymv;
74 |
75 | if (mode !== SPLITMV)
76 | ymv = mbi.mbmi.mv;
77 | else
78 | ymv = mvs[b];
79 |
80 | recon_1_edge_block(output, output_off, emul_block, emul_block_off, reference, reference_off, img.stride,
81 | ymv, ctx.subpixel_filters,
82 | coeffs, coeffs_off, mbi, x, y, w, h, b);
83 |
84 | x += 4;
85 | output_off += 4;
86 | reference_off += 4;
87 |
88 | if ((b & 3) === 3) {
89 | x -= 16;
90 | y += 4;
91 | output_off += (img.stride << 2) - 16;
92 | reference_off += (img.stride << 2) - 16;
93 | }
94 |
95 | }
96 |
97 | x = mb_col << 4;
98 | y = mb_row << 4;
99 |
100 | // Chroma
101 | x >>= 1;
102 | y >>= 1;
103 | w >>= 1;
104 | h >>= 1;
105 |
106 | //if (mbi.mbmi.y_mode !== SPLITMV)
107 | //{
108 | var uv_stride_4_8 = 4 * img.uv_stride - 8;
109 |
110 | for (b = 0; b < 4; b++) {
111 |
112 | recon_1_edge_block(u, u_off, emul_block, emul_block_off, reference, u_off + reference_offset, //u
113 | img.uv_stride,
114 | chroma_mv[b], ctx.subpixel_filters,
115 | coeffs, coeffs_off, mbi, x, y, w, h, b + 16);
116 |
117 |
118 | recon_1_edge_block(v, v_off, emul_block, emul_block_off, reference, v_off + reference_offset, //v
119 | img.uv_stride,
120 | chroma_mv[b], ctx.subpixel_filters,
121 | coeffs, coeffs_off, mbi, x, y, w, h, b + 20);
122 |
123 |
124 | u_off += 4;
125 | v_off += 4;
126 | x += 4;
127 |
128 | if ((b & 1) === 1) {
129 | x -= 8;
130 | y += 4;
131 | u_off += uv_stride_4_8;
132 | v_off += uv_stride_4_8;
133 | }
134 |
135 | }
136 | //}
137 |
138 | }
139 |
140 |
141 |
142 | function build_4x4uvmvs(mbi, full_pixel) {
143 | var mvs = mbi.bmi.mvs;
144 | for (var i = 0; i < 2; ++i) {
145 | for (var j = 0; j < 2; ++j) {
146 |
147 | var b = (i << 3) + (j << 1);
148 | var chroma_ptr = (i << 1) + j;
149 | var chroma_mv_cache = chroma_mv[chroma_ptr];
150 |
151 | var temp = 0;
152 |
153 |
154 |
155 | temp = mvs[b].as_row_col[0] +
156 | mvs[b + 1].as_row_col[0] +
157 | mvs[b + 4].as_row_col[0] +
158 | mvs[b + 5].as_row_col[0];
159 |
160 | if (temp < 0)
161 | temp -= 4;
162 | else
163 | temp += 4;
164 |
165 | chroma_mv_cache.as_row_col[0] = (temp / 8 ) | 0;
166 |
167 | temp = mvs[b].as_row_col[1] +
168 | mvs[b + 1].as_row_col[1] +
169 | mvs[b + 4].as_row_col[1] +
170 | mvs[b + 5].as_row_col[1];
171 |
172 | if (temp < 0)
173 | temp -= 4;
174 | else
175 | temp += 4;
176 |
177 | chroma_mv_cache.as_row_col[1] = (temp / 8) | 0;
178 |
179 | if (full_pixel === 1) {
180 | chroma_mv_cache.as_int[0] &= 0xFFF8FFF8;
181 |
182 | }
183 |
184 |
185 | }
186 | }
187 | }
188 |
189 |
190 |
191 |
192 | function build_mc_border(dst, dst_off, src, src_off, stride, x, y, b_w, b_h, w, h) {
193 | var ref_row = 0;
194 | var ref_row_off = 0;
195 |
196 | /* Get a pointer to the start of the real data for this row */
197 | ref_row = src;
198 | ref_row_off = src_off - x - y * stride;
199 |
200 | if (y >= h)
201 | ref_row_off += (h - 1) * stride;
202 | else if (y > 0)
203 | ref_row_off += y * stride;
204 |
205 | do {
206 | var left = 0, right = 0, copy = 0;
207 |
208 |
209 | if (x < 0) {
210 | left = -x;
211 | } else {
212 | left = 0;
213 | }
214 |
215 | if (left > b_w)
216 | left = b_w;
217 |
218 | if (x + b_w > w)
219 | right = x + b_w - w;
220 |
221 | if (right > b_w)
222 | right = b_w;
223 |
224 | copy = b_w - left - right;
225 |
226 | if (left > 0)
227 | memset(dst, dst_off, ref_row[ref_row_off], left);
228 |
229 | if (copy > 0)
230 | memcpy(dst, dst_off + left, ref_row, ref_row_off + x + left, copy);
231 |
232 | if (right > 0)
233 | memset(dst, dst_off + left + copy, ref_row[ref_row_off + w - 1], right);
234 |
235 | dst_off += stride;
236 | y++;
237 |
238 | if (y < h && y > 0)
239 | ref_row_off += stride;
240 | } while (--b_h);
241 | }
242 |
243 | var uvmv = MotionVector.create();
244 | //Slowest thing :(
245 | function predict_inter(ctx, img, coeffs, coeffs_off, mbi) {
246 | var y, u , v;
247 | var y = u = v = img.y;
248 | var y_off = img.y_off;
249 | var u_off = img.u_off;
250 | var v_off = img.v_off;
251 | var reference;
252 | var reference_offset = 0;
253 |
254 | var full_pixel = (ctx.common.version === 3) + 0;
255 | var b = 0;
256 |
257 | var mbmi_cache = mbi.mbmi;
258 | var mode = mbmi_cache.y_mode;
259 |
260 |
261 | reference_offset = ctx.ref_frame_offsets[mbi.mbmi.ref_frame];
262 | reference = ctx.ref_frame_offsets_[mbi.mbmi.ref_frame];
263 | var stride = img.stride;
264 | var subpixel_filters = ctx.subpixel_filters;
265 |
266 | var mvs = mbi.bmi.mvs;
267 | var mv = mbmi_cache.mv;
268 | for (b = 0; b < 16; b++) {
269 | var ymv;
270 |
271 | if (mode !== SPLITMV)
272 | ymv = mv;
273 | else
274 | ymv = mvs[b];
275 |
276 |
277 | recon_1_block(y, y_off, reference, y_off + reference_offset, stride, //y
278 | ymv, subpixel_filters, coeffs, coeffs_off, mbi, b);
279 | y_off += 4;
280 |
281 | if ((b & 3) === 3)
282 | y_off += (img.stride << 2) - 16;
283 | }
284 |
285 | var uv_stride = img.uv_stride;
286 |
287 | for (b = 0; b < 4; b++) {
288 |
289 |
290 | recon_1_block(u, u_off, reference, u_off + reference_offset, //u
291 | uv_stride, chroma_mv[b],
292 | subpixel_filters, coeffs, coeffs_off, mbi, b + 16);
293 |
294 | recon_1_block(v, v_off, reference, v_off + reference_offset, //v
295 | uv_stride, chroma_mv[b],
296 | subpixel_filters, coeffs, coeffs_off, mbi, b + 20);
297 |
298 | u_off += 4;
299 | v_off += 4;
300 |
301 | if ((b & 1) === 1)
302 | {
303 | u_off += (uv_stride << 2) - 8;
304 | v_off += (uv_stride << 2) - 8;
305 | }
306 |
307 | }
308 |
309 |
310 |
311 | }
312 |
313 |
314 | //build_inter_predictors2b
315 | function recon_1_block(output, output_off, reference, reference_off, stride, mv, filters, coeffs, coeffs_off, mbi, b) {
316 | var predict = reference;
317 | var predict_off = reference_off;
318 | var mx = 0, my = 0;
319 |
320 | if (mv.as_int[0]) {
321 |
322 | mx = mv.as_row_col[0] & 7;
323 | my = mv.as_row_col[1] & 7;
324 |
325 | reference_off += ((mv.as_row_col[1] >> 3) * stride) + (mv.as_row_col[0] >> 3);
326 |
327 |
328 |
329 | filter_block2d(output, output_off, stride, reference, reference_off, stride, 4, 4, mx, my,
330 | filters);
331 |
332 | predict = output;
333 | predict_off = output_off;
334 |
335 |
336 | } else {
337 | predict_off = reference_off;
338 | }
339 |
340 | vp8_short_idct4x4llm_c(output, output_off, predict, predict_off, stride, coeffs, coeffs_off + 16 * b);
341 |
342 | }
343 |
344 | function recon_1_edge_block(output, output_off,
345 | emul_block, emul_block_off, reference, reference_off, stride, mv_, filters, coeffs,
346 | coeffs_off, mbi, x, y, w, h, start_b) {
347 |
348 | var predict = reference;
349 | var predict_off = reference_off;
350 | var b = start_b;
351 | var b_w = 4;
352 | var b_h = 4;
353 | var mx = 0, my = 0;
354 |
355 | x += mv_.as_row_col[0] >> 3;
356 | y += mv_.as_row_col[1] >> 3;
357 |
358 |
359 |
360 | if (x < 2 || x + b_w - 1 + 3 >= w || y < 2 || y + b_h - 1 + 3 >= h) {
361 |
362 | reference_off += (mv_.as_row_col[0] >> 3) + (mv_.as_row_col[1] >> 3) * stride;
363 | build_mc_border(emul_block, emul_block_off,
364 | reference, reference_off - 2 - (stride << 1), stride,
365 | x - 2, y - 2, b_w + 5, b_h + 5, w, h);
366 | reference = emul_block;
367 | reference_off = emul_block_off + (stride << 1) + 2;
368 | reference_off -= (mv_.as_row_col[0] >> 3) + (mv_.as_row_col[1] >> 3) * stride;
369 |
370 | }
371 |
372 |
373 |
374 |
375 | if (mv_.as_int[0]) {
376 |
377 | mx = mv_.as_row_col[0] & 7;
378 | my = mv_.as_row_col[1] & 7;
379 |
380 |
381 | reference_off += ((mv_.as_row_col[1] >> 3) * stride) + (mv_.as_row_col[0] >> 3);
382 |
383 |
384 |
385 |
386 | filter_block2d(output, output_off, stride, reference, reference_off, stride, 4, 4, mx, my,
387 | filters);
388 |
389 | predict = output;
390 | predict_off = output_off;
391 |
392 | } else {
393 | reference_off += ((mv_.as_row_col[1] >> 3) * stride) + (mv_.as_row_col[0] >> 3);
394 | predict = reference;
395 | predict_off = reference_off;
396 |
397 | }
398 |
399 |
400 | vp8_short_idct4x4llm_c(output, output_off, predict, predict_off, stride, coeffs, coeffs_off + 16 * b);
401 |
402 | }
403 |
404 | function build_inter4x4_predictors_mb(){
405 |
406 | }
407 |
408 | function vp8_build_inter16x16_predictors_mb(mbi, full_pixel) {
409 |
410 | var mbmi_cache = mbi.mbmi;
411 |
412 | uvmv.as_int[0] = mbmi_cache.mv.as_int[0];
413 |
414 | if (mbi.mbmi.need_mc_border === 1) {
415 | var x = uvmv.as_row_col[0];
416 | var y = uvmv.as_row_col[1] ;
417 | uvmv.as_row_col[0] = (x + 1 + ((x >> 31) << 1)) / 2;
418 | uvmv.as_row_col[1] = (y + 1 + ((y >> 31) << 1)) / 2;
419 |
420 | } else {
421 | uvmv.as_row_col[0] = (uvmv.as_row_col[0] + 1) >> 1;
422 | uvmv.as_row_col[1] = (uvmv.as_row_col[1] + 1) >> 1;
423 | }
424 |
425 | if (full_pixel) {
426 | uvmv.as_int[0] &= 0xFFF8FFF8;
427 | }
428 |
429 | chroma_mv[0].as_int[0] =
430 | chroma_mv[1].as_int[0] =
431 | chroma_mv[2].as_int[0] =
432 | chroma_mv[3].as_int[0] = uvmv.as_int[0];
433 |
434 | }
435 |
436 | //xd->subpixel_predict8x8 = vp8_sixtap_predict8x8;
437 | function vp8_build_inter_predictors_mb(ctx,
438 | img, coeffs, coeffs_off, mbi, mb_col, mb_row) {
439 |
440 |
441 | var y, u, v;
442 | var y = u = v = img.y;
443 | var y_off = img.y_off;
444 | var u_off = img.u_off;
445 | var v_off = img.v_off;
446 | var reference;
447 | var reference_offset = 0;
448 |
449 | var full_pixel = (ctx.common.version === 3) + 0;
450 | var b = 0;
451 |
452 | var mbmi_cache = mbi.mbmi;
453 |
454 | if (mbmi_cache.y_mode !== SPLITMV) {
455 |
456 | vp8_short_inv_walsh4x4_c(coeffs, coeffs_off + 384, coeffs_off);
457 | vp8_build_inter16x16_predictors_mb(mbi, full_pixel);
458 |
459 |
460 | } else {
461 |
462 | build_4x4uvmvs(mbi, full_pixel);
463 | build_inter4x4_predictors_mb();
464 | }
465 |
466 |
467 | if (mbi.mbmi.need_mc_border === 1)
468 | predict_inter_emulated_edge(ctx, img, coeffs, coeffs_off, mbi, mb_col, mb_row);
469 |
470 | else
471 | predict_inter(ctx, img, coeffs, coeffs_off, mbi);
472 |
473 | }
474 |
475 | module.exports = {};
476 | module.exports.predict_inter_emulated_edge = predict_inter_emulated_edge;
477 | module.exports.predict_inter = predict_inter;
478 | module.exports.vp8_build_inter_predictors_mb = vp8_build_inter_predictors_mb;
--------------------------------------------------------------------------------
/vp8/common/reconintra.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var reconintra4x4 = require('./reconintra4x4.js');
4 | var intra_prediction_down_copy = reconintra4x4.intra_prediction_down_copy;
5 |
6 | var DC_PRED = 0;
7 | var V_PRED = 1;
8 | var H_PRED = 2;
9 | var TM_PRED = 3;
10 | var B_PRED = 4;
11 |
12 |
13 |
14 |
15 | var B_DC_PRED = 0;
16 | var B_TM_PRED = 1;
17 | var B_VE_PRED = 2;
18 | var B_HE_PRED = 3;
19 | var B_LD_PRED = 4;
20 | var B_RD_PRED = 5;
21 | var B_VR_PRED = 6;
22 | var B_VL_PRED = 7;
23 | var B_HD_PRED = 8;
24 | var B_HU_PRED = 9;
25 |
26 | var idctllm = require('../common/idctllm.js');
27 | var vp8_short_inv_walsh4x4_c = idctllm.vp8_short_inv_walsh4x4_c;
28 | var vp8_short_idct4x4llm_c = idctllm.vp8_short_idct4x4llm_c;
29 |
30 | function CLAMP_255(x) {
31 | return Math.min(Math.max(x, 0), 255);
32 | }
33 |
34 |
35 | function predict_tm_16x16(predict, predict_off, stride){
36 | predict_tm_nxn(predict, predict_off, stride, 16);
37 | }
38 |
39 |
40 | function predict_v_8x8(predict, predict_off, stride) {
41 | predict_v_nxn(predict, predict_off, stride, 8);
42 | }
43 |
44 | function predict_h_16x16(predict, predict_off, stride) {
45 | predict_h_nxn(predict, predict_off, stride, 16);
46 | }
47 |
48 | function predict_v_16x16(predict, predict_off, stride)
49 | {
50 | predict_v_nxn(predict, predict_off, stride, 16);
51 | }
52 |
53 |
54 | function predict_tm_8x8(predict, predict_off, stride)
55 | {
56 | predict_tm_nxn(predict, predict_off, stride, 8);
57 | }
58 |
59 | function predict_h_8x8(predict, predict_off, stride)
60 | {
61 | predict_h_nxn(predict, predict_off, stride, 8);
62 | }
63 |
64 |
65 | function predict_tm_8x8(predict, predict_off, stride)
66 | {
67 | predict_tm_nxn(predict, predict_off, stride, 8);
68 | }
69 |
70 |
71 | //likely vp8_build_intra_predictors_mbuv_s
72 | function predict_intra_chroma(predict_u,
73 | predict_u_off,
74 | predict_v,
75 | predict_v_off,
76 | stride,
77 | mbi,
78 | coeffs,
79 | coeffs_off) {
80 | var i = 0;
81 |
82 |
83 | switch (mbi.mbmi.uv_mode)
84 | {
85 |
86 | case DC_PRED:
87 |
88 | //line84
89 | predict_dc_nxn(predict_u, predict_u_off, stride, 8);
90 | predict_dc_nxn(predict_v, predict_v_off, stride, 8);
91 | break;
92 | case V_PRED:
93 | predict_v_8x8(predict_u, predict_u_off, stride);
94 | predict_v_8x8(predict_v, predict_v_off, stride);
95 | break;
96 | case H_PRED:
97 | predict_h_8x8(predict_u, predict_u_off, stride);
98 | predict_h_8x8(predict_v, predict_v_off, stride);
99 | break;
100 | case TM_PRED:
101 | predict_tm_8x8(predict_u, predict_u_off, stride);
102 | predict_tm_8x8(predict_v, predict_v_off, stride);
103 | break;
104 | default:
105 |
106 | }
107 |
108 | coeffs_off += 256;
109 | var stride4_8 = stride * 4 - 8;
110 | //likely line 178
111 | for (i = 16; i < 20; i++) {
112 | vp8_short_idct4x4llm_c(predict_u, predict_u_off, predict_u, predict_u_off, stride, coeffs, coeffs_off);
113 | coeffs_off += 16;
114 | predict_u_off += 4;
115 |
116 | if (i & 1)
117 | predict_u_off += stride4_8;
118 | }
119 |
120 | for (i = 20; i < 24; i++) {
121 | vp8_short_idct4x4llm_c(predict_v, predict_v_off, predict_v, predict_v_off, stride, coeffs, coeffs_off);
122 | coeffs_off += 16;
123 | predict_v_off += 4;
124 |
125 | if (i & 1)
126 | predict_v_off += stride4_8;
127 | }
128 |
129 | }
130 |
131 | function predict_v_nxn(predict, predict_off, stride, n) {
132 | var above = predict;
133 | var above_off = (predict_off - stride) | 0;
134 | var i = 0, j = 0;
135 | var istride = 0;
136 | for (i = 0; i < n; i++) {
137 | istride = i * stride;
138 | for (j = 0; j < n; j++)
139 | predict[predict_off + istride + j] = above[above_off + j];
140 | }
141 | }
142 |
143 | function predict_h_nxn(predict, predict_off, stride, n) {
144 | var left = predict;
145 | var left_off = (predict_off - 1) | 0;
146 | var i = 0;
147 | var j = 0;
148 |
149 | var istride = 0;
150 | var predic_pixel = 0;
151 |
152 | for (i = 0; i < n; i++) {
153 | istride = i * stride;
154 | predic_pixel = left[left_off + i * stride];
155 | for (j = 0; j < n; j++)
156 | predict[predict_off + istride + j] = predic_pixel;
157 | }
158 | }
159 |
160 |
161 | function predict_dc_nxn(predict, predict_off, stride, n) {
162 | n = n | 0;
163 | var left = predict;
164 | var left_off = predict_off - 1;
165 | var above = predict;
166 | var above_off = predict_off - stride;
167 | var i = 0, j = 0;
168 | var dc = 0;
169 |
170 | for (i = 0; i < n; i++) {
171 | dc += left[left_off] + above[above_off + i];
172 | left_off += stride;
173 | }
174 |
175 | switch (n) {
176 | case 16:
177 | dc = ((dc + 16) >> 5);
178 | break;
179 | case 8:
180 | dc = ((dc + 8) >> 4);
181 | break;
182 | case 4:
183 | dc = ((dc + 4) >> 3);
184 | break;
185 | }
186 |
187 | for (i = 0; i < n; i++)
188 | for (j = 0; j < n; j++)
189 | predict[predict_off + i * stride + j] = dc;
190 | }
191 |
192 | function predict_tm_nxn(predict, predict_off, stride, n) {
193 | /* Transposes the left column to the top row for later consumption
194 | * by the idct/recon stage
195 | */
196 | var left = predict;
197 | var left_off = predict_off - 1;
198 | var above = predict;
199 | var above_off = predict_off - stride;
200 | var p = above[above_off - 1];
201 | var i = 0, j = 0;
202 |
203 | for (j = 0; j < n; j++)
204 | {
205 | for (i = 0; i < n; i++)
206 | predict[predict_off + i] = CLAMP_255(left[left_off] + above[above_off + i] - p);//*left //CLAMP_255
207 |
208 | predict_off += stride;
209 | left_off += stride;
210 | }
211 | }
212 |
213 |
214 | //possibly vp8_build_intra_predictors_mby_s
215 | function predict_intra_luma(predict,
216 | predict_off,
217 | stride,
218 | mbi,
219 | coeffs,
220 | coeffs_off) {
221 |
222 | if (mbi.mbmi.y_mode === B_PRED)
223 | b_pred(predict, predict_off, stride, mbi, coeffs, coeffs_off);
224 |
225 | else
226 | {
227 | var i = 0;
228 |
229 | switch (mbi.mbmi.y_mode)
230 | {
231 | case DC_PRED:
232 | predict_dc_nxn(predict, predict_off, stride, 16);
233 | break;
234 | case V_PRED:
235 | predict_v_16x16(predict, predict_off, stride);
236 | break;
237 | case H_PRED:
238 | predict_h_16x16(predict, predict_off, stride);
239 | break;
240 | case TM_PRED:
241 | predict_tm_16x16(predict, predict_off, stride);
242 | break;
243 | default:
244 |
245 | }
246 |
247 |
248 | vp8_short_inv_walsh4x4_c(coeffs, coeffs_off + 384, coeffs_off);
249 |
250 | for (i = 0; i < 16; i++)
251 | {
252 | vp8_short_idct4x4llm_c(predict, predict_off, predict, predict_off, stride, coeffs, coeffs_off);
253 | coeffs_off += 16;
254 | predict_off += 4;
255 |
256 | if ((i & 3) === 3)
257 | predict_off += (stride << 2) - 16;
258 | }
259 |
260 | }
261 |
262 | }
263 |
264 | //found in reconintra4x4
265 | //likeley line 183
266 | function b_pred(predict, predict_off, stride, mbi, coeffs, coeffs_off) {
267 |
268 | var i = 0;
269 |
270 | intra_prediction_down_copy(predict, predict_off, stride);
271 |
272 |
273 | //line 165 in decode frame
274 | var modes = mbi.bmi.modes;
275 | for (i = 0; i < 16; i++) {
276 | var b_predict = predict;
277 | var b_predict_off = predict_off + ((i & 3) << 2);
278 |
279 |
280 | switch (modes[i])
281 | {
282 | case B_DC_PRED:
283 | predict_dc_nxn(b_predict, b_predict_off, stride, 4);
284 | break;
285 | case B_TM_PRED:
286 | predict_tm_nxn(b_predict, b_predict_off, stride, 4);
287 | break;
288 | case B_VE_PRED:
289 | predict_ve_4x4(b_predict, b_predict_off, stride);
290 | break;
291 | case B_HE_PRED:
292 | predict_he_4x4(b_predict, b_predict_off, stride);
293 | break;
294 | case B_LD_PRED:
295 | predict_ld_4x4(b_predict, b_predict_off, stride);
296 | break;
297 | case B_RD_PRED:
298 | predict_rd_4x4(b_predict, b_predict_off, stride);
299 | break;
300 | case B_VR_PRED:
301 | predict_vr_4x4(b_predict, b_predict_off, stride);
302 | break;
303 | case B_VL_PRED:
304 | predict_vl_4x4(b_predict, b_predict_off, stride);
305 | break;
306 | case B_HD_PRED:
307 | predict_hd_4x4(b_predict, b_predict_off, stride);
308 | break;
309 | case B_HU_PRED:
310 | predict_hu_4x4(b_predict, b_predict_off, stride);
311 | break;
312 | }
313 |
314 | vp8_short_idct4x4llm_c(b_predict, b_predict_off, b_predict, b_predict_off, stride, coeffs, coeffs_off);
315 | coeffs_off += 16;
316 |
317 | if ((i & 3) === 3) {
318 | predict_off += stride * 4;
319 | }
320 |
321 | }
322 |
323 | }
324 |
325 |
326 | function predict_hd_4x4(predict, predict_off, stride) {
327 | var left = predict;
328 | var left_off = predict_off - 1;
329 | var above = predict;
330 | var above_off = predict_off - stride;
331 | var pred0 = 0, pred1 = 0, pred2 = 0, pred3 = 0, pred4 = 0, pred5 = 0, pred6 = 0,
332 | pred7 = 0, pred8 = 0, pred9 = 0;
333 |
334 | var abovem1 = above[above_off - 1] | 0;
335 | var above0 = above[above_off] | 0;
336 | var above1 = above[above_off + 1] | 0;
337 | var above2 = above[above_off + 2] | 0;
338 | var stride2 = stride << 1;
339 | var stride3 = stride * 3;
340 |
341 | var left0 = left[left_off]|0;
342 | var left1 = left[left_off + stride]|0;
343 | var left2 = left[left_off + stride2]|0;
344 | var left3 = left[left_off + stride3]|0;
345 |
346 | var pred_32 = predict.data_32;
347 |
348 | pred0 = (left0 + abovem1 + 1) >> 1;
349 | pred1 = (left0 + 2 * abovem1 + above0 + 2) >> 2;
350 | pred2 = (above[above_off - 1] + 2 * above0 + above1 + 2) >> 2;
351 | pred3 = (above0 + (above1 << 1) + above2 + 2) >> 2;
352 | pred_32[predict_off >> 2] = pred0 | (pred1 << 8) | (pred2 << 16) | (pred3 << 24);
353 | predict_off += stride;
354 |
355 | pred4 = (left1 + left0 + 1) >> 1;
356 | pred5 = (left1 + 2 * left0 + abovem1 + 2) >> 2;
357 | pred_32[predict_off >> 2] = pred4 | (pred5 << 8) | (pred0 << 16) | (pred1 << 24);
358 | predict_off += stride;
359 |
360 |
361 | pred6 = (left2 + left1 + 1) >> 1;
362 | pred7 = (left2 + 2 * left1 + left0 + 2) >> 2;
363 | pred_32[predict_off >> 2] = pred6 | (pred7 << 8) | (pred4 << 16) | (pred5 << 24);
364 | predict_off += stride;
365 |
366 |
367 |
368 | pred8 = (left3 + left2 + 1) >> 1;
369 | pred9 = (left3 + 2 * left2 + left1 + 2) >> 2;
370 |
371 |
372 | pred_32[predict_off >> 2] = pred8 | (pred9 << 8) | (pred6 << 16) | (pred7 << 24);
373 | }
374 |
375 |
376 | function predict_vr_4x4(predict, predict_off, stride) {
377 | var left = predict;
378 | var left_off = predict_off - 1;
379 | var above = predict;
380 | var above_off = predict_off - stride;
381 | var pred0 = 0, pred1 = 0, pred2 = 0, pred3 = 0, pred4 = 0, pred5 = 0, pred6 = 0,
382 | pred7 = 0, pred8 = 0, pred9 = 0;
383 |
384 | var above_32 = above.data_32[above_off >> 2];
385 | var above0 = above_32 & 0xFF;
386 | var above1 = (above_32 >> 8) & 0xFF;
387 | var above2 = (above_32 >> 16) & 0xFF;
388 | var above3 = (above_32 >> 24) & 0xFF;
389 | var above_m1 = above[above_off - 1];
390 |
391 | var left0 = left[left_off + 0];
392 |
393 | pred0 = (above[above_off - 1] + above0 + 1) >> 1;
394 | pred1 = (above0 + above1 + 1) >> 1;
395 | pred2 = (above1 + above2 + 1) >> 1;
396 | pred3 = (above2 + above3 + 1) >> 1;
397 |
398 | predict.data_32[predict_off >> 2] = pred0 | (pred1 << 8) | (pred2 << 16) | (pred3 << 24);
399 | predict_off += stride;
400 |
401 | pred4 = (left[left_off + 0] + 2 * above_m1 + above0 + 2) >> 2;
402 | pred5 = (above_m1 + 2 * above0 + above1 + 2) >> 2;
403 | pred6 = (above0 + 2 * above1 + above2 + 2) >> 2;
404 | pred7 = (above1 + 2 * above2 + above[above_off + 3] + 2) >> 2;
405 |
406 | predict.data_32[predict_off >> 2] = pred4 | (pred5 << 8) | (pred6 << 16) | (pred7 << 24);
407 |
408 | predict_off += stride;
409 |
410 | pred8 = (left[left_off + stride] + 2 * left0 + above[above_off - 1] + 2) >> 2;
411 |
412 |
413 | predict.data_32[predict_off >> 2] = pred8 | (pred0 << 8) | (pred1 << 16) | (pred2 << 24);
414 |
415 | predict_off += stride;
416 |
417 | pred9 = (left[left_off + stride * 2] + 2 * left[left_off + stride] + left0 + 2) >> 2;
418 |
419 |
420 | predict.data_32[predict_off >> 2] = pred9 | (pred4 << 8) | (pred5 << 16) | (pred6 << 24);
421 | }
422 |
423 |
424 | function predict_rd_4x4(predict, predict_off, stride) {
425 | var left = predict;
426 | var left_off = predict_off - 1;
427 | var above = predict;
428 | var above_off = predict_off - stride;
429 | var pred0 = 0, pred1 = 0, pred2 = 0, pred3 = 0, pred4 = 0, pred5 = 0, pred6 = 0;
430 |
431 | var above_32 = above.data_32[above_off >> 2];
432 | var above0 = above_32 & 0xFF;
433 | var above1 = (above_32 >> 8) & 0xFF;
434 | var above2 = (above_32 >> 16) & 0xFF;
435 | var above3 = (above_32 >> 24) & 0xFF;
436 |
437 | var left0 = left[left_off];
438 | var left1 = left[left_off + stride];
439 | var left2 = left[left_off + stride * 2];
440 |
441 | pred0 = (left[left_off + 0] + 2 * above[above_off - 1] + above0 + 2) >> 2;
442 | pred1 = (above[above_off - 1] + 2 * above0 + above1 + 2) >> 2;
443 | pred2 = (above0 + 2 * above1 + above2 + 2) >> 2;
444 | pred3 = (above1 + 2 * above2 + above3 + 2) >> 2;
445 |
446 | predict.data_32[predict_off >> 2] = pred0 | (pred1 << 8) | (pred2 << 16) | (pred3 << 24);
447 |
448 |
449 | predict_off += stride;
450 |
451 | pred4 = (left1 + 2 * left0 + above[above_off - 1] + 2) >> 2;
452 |
453 | predict.data_32[predict_off >> 2] = pred4 | (pred0 << 8) | (pred1 << 16) | (pred2 << 24);
454 |
455 | predict_off += stride;
456 |
457 | pred5 = (left2 + 2 * left1 + left0 + 2) >> 2;
458 |
459 |
460 | predict.data_32[predict_off >> 2] = pred5 | (pred4 << 8) | (pred0 << 16) | (pred1 << 24);
461 | predict_off += stride;
462 |
463 | pred6 = (left[left_off + stride * 3] + 2 * left2 + left1 + 2) >> 2;
464 |
465 |
466 | predict.data_32[predict_off >> 2] = pred6 | (pred5 << 8) | (pred4 << 16) | (pred0 << 24);
467 | }
468 |
469 |
470 | function predict_ve_4x4(predict, predict_off, stride) {
471 | var above = predict;
472 | var above_32 = predict.data_32;
473 | var above_off = predict_off - stride;
474 | var i = 0, j = 0;
475 |
476 | var above_temp = above_32[above_off >> 2] | 0;
477 | var above0 = above_temp & 0xFF; //above[above_off] | 0;//
478 | var above1 = (above_temp >> 8) & 0xFF; //above[above_off + 1] | 0; //
479 | var above2 = (above_temp >> 16) & 0xFF; // above[above_off + 2] | 0; //
480 | var above3 = (above_temp >> 24) & 0xFF; //above[above_off + 3] | 0;//
481 |
482 | var pred1 = (above[above_off - 1] + (above0 << 1) + above1 + 2) >> 2;
483 | var pred2 = (above0 + (above1 << 1) + above2 + 2) >> 2;
484 | var pred3 = (above1 + (above2 << 1) + above3 + 2) >> 2;
485 | var pred4 = (above2 + (above3 << 1) + above[above_off + 4] + 2) >> 2;
486 |
487 | predict.data_32[predict_off >> 2] = pred1 | (pred2 << 8) | (pred3 << 16) | (pred4 << 24);
488 |
489 | var istride = 0;// i * stride;
490 | for (i = 1; i < 4; i++) {
491 | istride = i * stride;
492 | for (j = 0; j < 4; j++) {
493 | predict[predict_off + istride + j] = predict[predict_off + j];
494 | }
495 | }
496 | }
497 |
498 |
499 | function predict_he_4x4(predict, predict_off, stride) {
500 | var left = predict;
501 | var left_off = predict_off - 1;
502 | var above_32 = predict.data_32;
503 |
504 | var temp = (left[left_off - stride] + 2 * left[left_off] + left[left_off + stride] + 2) >> 2;
505 | above_32[predict_off >> 2] = temp | (temp << 8) | (temp << 16) | (temp << 24);
506 |
507 | predict_off += stride;
508 | left_off += stride;
509 |
510 |
511 | temp = (left[left_off - stride] + 2 * left[left_off] + left[left_off + stride] + 2) >> 2;
512 | above_32[predict_off >> 2] = temp | (temp << 8) | (temp << 16) | (temp << 24);
513 |
514 | predict_off += stride;
515 | left_off += stride;
516 |
517 | temp = (left[left_off - stride] + 2 * left[left_off] + left[left_off + stride] + 2) >> 2;
518 |
519 | above_32[predict_off >> 2] = temp | (temp << 8) | (temp << 16) | (temp << 24);
520 | predict_off += stride;
521 | left_off += stride;
522 |
523 | temp = (left[left_off - stride] + 2 * left[left_off] + left[left_off + 0] + 2) >> 2;
524 | above_32[predict_off >> 2] = temp | (temp << 8) | (temp << 16) | (temp << 24);
525 | }
526 |
527 |
528 | function predict_hu_4x4(predict, predict_off, stride) {
529 | var left = predict;
530 | var left_off = predict_off - 1;
531 | var pred0 = 0, pred1 = 0, pred2 = 0, pred3 = 0, pred4 = 0, pred5 = 0, pred6 = 0;
532 |
533 | var stride3 = (stride * 3) | 0;
534 | var stride2 = (stride << 1);
535 | var left0 = left[left_off];
536 | var left1 = left[left_off + stride];
537 | var left2 = left[left_off + stride * 2];
538 | var left3 = left[left_off + stride * 3];
539 |
540 | pred0 = (left0 + left1 + 1) >> 1;
541 | pred1 = (left0 + 2 * left1 + left2 + 2) >> 2;
542 | pred2 = (left1 + left2 + 1) >> 1;
543 | pred3 = (left1 + 2 * left2 + left3 + 2) >> 2;
544 |
545 | predict.data_32[predict_off >> 2] = pred0 | pred1 << 8 | pred2 << 16 | pred3 << 24;
546 |
547 | predict_off += stride;
548 |
549 |
550 |
551 | //predict[predict_off + 0] = pred2;
552 | //predict[predict_off + 1] = pred3;
553 | pred4 = (left2 + left3 + 1) >> 1;
554 | pred5 = (left2 + 2 * left3 + left3 + 2) >> 2;
555 |
556 | predict.data_32[predict_off >> 2] = pred2 | pred3 << 8 | pred4 << 16 | pred5 << 24;
557 | predict_off += stride;
558 |
559 | pred6 = left3;
560 |
561 |
562 | predict.data_32[predict_off >> 2] = pred4 | pred5 << 8 | pred6 << 16 | pred6 << 24;
563 | predict_off += stride;
564 |
565 |
566 | predict.data_32[predict_off >> 2] = pred6 | pred6 << 8 | pred6 << 16 | pred6 << 24;
567 | }
568 |
569 |
570 | function predict_ld_4x4(predict, predict_off, stride) {
571 | var above = predict;
572 | var above_off = predict_off - stride;
573 | var pred0 = 0, pred1 = 0, pred2 = 0, pred3 = 0, pred4 = 0, pred5 = 0, pred6 = 0;
574 |
575 | var above_32 = predict.data_32;
576 | var above_32_value = above_32[above_off >> 2];
577 | var above0 = above_32_value & 0xFF; //above[above_off] | 0;
578 | var above1 = (above_32_value >> 8) & 0xFF; // above[above_off + 1] | 0;
579 | var above2 = (above_32_value >> 16) & 0xFF; //above[above_off + 2] | 0;
580 | var above3 = (above_32_value >> 24) & 0xFF;
581 |
582 | above_32_value = above_32[(above_off >> 2) + 1];
583 | var above4 = above_32_value & 0xFF; //above[above_off] | 0;
584 | var above5 = (above_32_value >> 8) & 0xFF; // above[above_off + 1] | 0;
585 | var above6 = (above_32_value >> 16) & 0xFF; //above[above_off + 2] | 0;
586 | var above7 = (above_32_value >> 24) & 0xFF;
587 |
588 | pred0 = (above0 + (above1 << 1) + above2 + 2) >> 2;
589 | pred1 = (above1 + (above2 << 1) + above3 + 2) >> 2;
590 | pred2 = (above2 + (above3 << 1) + above4 + 2) >> 2;
591 | pred3 = (above3 + (above4 << 1) + above5 + 2) >> 2;
592 |
593 | predict.data_32[predict_off >> 2] = pred0 | (pred1 << 8) | (pred2 << 16) | (pred3 << 24);
594 | predict_off += stride;
595 |
596 |
597 | pred4 = (above4 + 2 * above5 + above6 + 2) >> 2;
598 | predict.data_32[predict_off >> 2] = pred1 | (pred2 << 8) | (pred3 << 16) | (pred4 << 24);
599 |
600 | predict_off += stride;
601 |
602 |
603 | pred5 = (above5 + (above6 << 1) + above7 + 2) >> 2;
604 | predict.data_32[predict_off >> 2] = pred2 | (pred3 << 8) | (pred4 << 16) | (pred5 << 24);
605 |
606 | predict_off += stride;
607 |
608 |
609 | pred6 = (above6 + 2 * above7 + above7 + 2) >> 2;
610 | predict.data_32[predict_off >> 2] = pred3 | (pred4 << 8) | (pred5 << 16) | (pred6 << 24);
611 |
612 | }
613 |
614 |
615 | function predict_vl_4x4(predict, predict_off, stride) {
616 | var above = predict;
617 | var above_off = predict_off - stride;
618 | var pred0 = 0, pred1 = 0, pred2 = 0, pred3 = 0, pred4 = 0, pred5 = 0, pred6 = 0,
619 | pred7 = 0, pred8 = 0, pred9 = 0;
620 |
621 | var above_32 = above.data_32[above_off >> 2];
622 | var above0 = above_32 & 0xFF;
623 | var above1 = (above_32 >> 8) & 0xFF;
624 | var above2 = (above_32 >> 16) & 0xFF;
625 | var above3 = (above_32 >> 24) & 0xFF;
626 |
627 | above_32 = above.data_32[(above_off >> 2) + 1];
628 | var above4 = above_32 & 0xFF; //above[above_off] | 0;
629 | var above5 = (above_32 >> 8) & 0xFF; // above[above_off + 1] | 0;
630 | var above6 = (above_32 >> 16) & 0xFF; //above[above_off + 2] | 0;
631 | var above7 = (above_32 >> 24) & 0xFF;
632 |
633 |
634 | pred0 = (above0 + above1 + 1) >> 1;
635 | pred1 = (above1 + above2 + 1) >> 1;
636 | pred2 = (above2 + above3 + 1) >> 1;
637 | pred3 = (above[above_off + 3] + above4 + 1) >> 1;
638 |
639 | predict.data_32[predict_off >> 2] = pred0 | pred1 << 8 | pred2 << 16 | pred3 << 24;
640 |
641 | predict_off += stride;
642 |
643 | pred4 = (above0 + 2 * above1 + above2 + 2) >> 2;
644 | pred5 = (above1 + 2 * above2 + above3 + 2) >> 2;
645 | pred6 = (above2 + 2 * above3 + above4 + 2) >> 2;
646 | pred7 = (above3 + 2 * above4 + above5 + 2) >> 2;
647 |
648 | predict.data_32[predict_off >> 2] = pred4 | pred5 << 8 | pred6 << 16 | pred7 << 24;
649 |
650 | predict_off += stride;
651 |
652 |
653 | pred8 = (above4 + 2 * above5 + above6 + 2) >> 2;
654 |
655 | predict.data_32[predict_off >> 2] = pred1 | pred2 << 8 | pred3 << 16 | pred8 << 24;
656 |
657 | predict_off += stride;
658 |
659 |
660 | pred8 = (above5 + 2 * above6 + above7 + 2) >> 2;
661 |
662 | predict.data_32[predict_off >> 2] = pred5 | pred6 << 8 | pred7 << 16 | pred8 << 24;
663 | }
664 |
665 |
666 | module.exports = {};
667 | module.exports.predict_intra_chroma = predict_intra_chroma;
668 | module.exports.predict_intra_luma = predict_intra_luma;
669 |
--------------------------------------------------------------------------------
/vp8/common/reconintra4x4.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | //intra_prediction_down_copy in reconintra4x4
4 | function intra_prediction_down_copy(recon, recon_off, stride) {
5 | /* Copy the four pixels above-right of subblock 3 to
6 | * above-right of subblocks 7, 11, and 15
7 | */
8 |
9 | var copy = (recon);
10 | var copy_off = (recon_off + 16 - stride);//*(void *)
11 |
12 | var i;
13 | var copy_32 = copy.data_32;
14 | var tmp_32 = copy_32[copy_off >> 2];
15 |
16 | copy_off += stride << 2;
17 |
18 | copy_32[copy_off >> 2] = tmp_32;
19 |
20 | copy_off += stride << 2;
21 |
22 | copy_32[copy_off >> 2] = tmp_32;
23 |
24 | copy_off += stride << 2;
25 |
26 | copy_32[copy_off >> 2] = tmp_32;
27 |
28 | }
29 |
30 |
31 | module.exports = {};
32 | module.exports.intra_prediction_down_copy = intra_prediction_down_copy;
--------------------------------------------------------------------------------
/vp8/common/setupintrarecon.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 |
4 |
5 | var c_utils = require('../../util/c_utils.js');
6 | var memset = c_utils.memset;
7 |
8 | /*
9 | if (start_col === 0) {
10 | //vp8_setup_intra_recon
11 | fixup_left(img.y, img.y_off, 16, img.stride, row, mbi[mbi_off].base.y_mode);
12 | fixup_left(img.u, img.u_off, 8, img.uv_stride, row, mbi[mbi_off].base.uv_mode);
13 | fixup_left(img.v, img.v_off, 8, img.uv_stride, row, mbi[mbi_off].base.uv_mode);
14 |
15 | //doesnt seem to do anything
16 | //if (row === 0)
17 | // img.y[img.y_off - img.stride - 1]= 127;
18 | //console.warn(img.y_off - img.stride - 1);
19 | }
20 | */
21 | //var dc_pred_set = new Uint8Array([129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129]);
22 | function vp8_setup_intra_recon(predict, y_off, u_off, v_off, y_stride, uv_stride) {
23 | //The left column of out-of-frame pixels is taken to be 129,
24 | // unless we're doing DC_PRED, in which case we duplicate the
25 | // above row, unless this is also row 0, in which case we use
26 | // 129.
27 | //
28 | var y_buffer = predict;
29 | var y_off = (y_off - 1);
30 | var i = 0;
31 | /* Need to re-set the above row, in case the above MB was
32 | * DC_PRED.
33 | */
34 | y_off -= y_stride;
35 |
36 | //for (i = -1; i < 16; i++) {
37 | //y_buffer[y_off] = 129;
38 | //y_buffer.set(dc_pred_set, y_off);
39 | // y_off += y_stride;
40 | //}
41 |
42 | /*
43 | var u_buffer = predict;
44 | var u_off = (u_off - 1);
45 |
46 | u_off -= uv_stride;
47 |
48 | for (i = 0; i < 8; i++) {
49 | y_buffer[y_off] = 129;//*
50 | y_off += y_stride;
51 | }
52 |
53 | var u_buffer = predict;
54 | var u_off = (u_off - 1);
55 |
56 |
57 | u_off -= uv_stride;
58 |
59 | for (i = -1; i < 8; i++) {
60 | u_buffer[u_off] = 129;//*
61 | u_off += uv_stride;
62 | }
63 | */
64 | }
65 |
66 | function vp8_setup_intra_recon_top_line(ybf) {
67 | //console.log(ybf.planes_off[0]);
68 | var data = ybf.img_data;
69 |
70 | var uv_ptr = ybf.planes_off[1] - 1 - ybf.uv_stride;
71 | var uv_length = (ybf.d_w >> 1) + 5;
72 |
73 | // TODO: This is being doubled somewhere else, find it!
74 | //memset(data, ybf.planes_off[0] - 1 - ybf.stride, 127, ybf.d_w + 5);//ybf.y_width + 5
75 | //memset(data, uv_ptr, 127, uv_length);
76 |
77 |
78 | }
79 |
80 |
81 | module.exports = {};
82 | module.exports.vp8_setup_intra_recon = vp8_setup_intra_recon;
83 | module.exports.vp8_setup_intra_recon_top_line = vp8_setup_intra_recon_top_line;
--------------------------------------------------------------------------------
/vp8/common/vp8_entropymodedata.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | //k_default_y_mode_probs
4 | var vp8_ymode_prob = new Uint8Array([112, 86, 140, 37]);
5 |
6 | var vp8_kf_bmode_prob = new Uint8Array([
7 | /* left mode 0 */ 231, 120, 48, 89, 115, 113, 120, 152, 112,
8 | /* left mode 1 */ 152, 179, 64, 126, 170, 118, 46, 70, 95,
9 | /* left mode 2 */ 175, 69, 143, 80, 85, 82, 72, 155, 103,
10 | /* left mode 3 */ 56, 58, 10, 171, 218, 189, 17, 13, 152,
11 | /* left mode 4 */ 144, 71, 10, 38, 171, 213, 144, 34, 26,
12 | /* left mode 5 */ 114, 26, 17, 163, 44, 195, 21, 10, 173,
13 | /* left mode 6 */ 121, 24, 80, 195, 26, 62, 44, 64, 85,
14 | /* left mode 7 */ 170, 46, 55, 19, 136, 160, 33, 206, 71,
15 | /* left mode 8 */ 63, 20, 8, 114, 114, 208, 12, 9, 226,
16 | /* left mode 9 */ 81, 40, 11, 96, 182, 84, 29, 16, 36,
17 | /* left mode 0 */ 134, 183, 89, 137, 98, 101, 106, 165, 148,
18 | /* left mode 1 */ 72, 187, 100, 130, 157, 111, 32, 75, 80,
19 | /* left mode 2 */ 66, 102, 167, 99, 74, 62, 40, 234, 128,
20 | /* left mode 3 */ 41, 53, 9, 178, 241, 141, 26, 8, 107,
21 | /* left mode 4 */ 104, 79, 12, 27, 217, 255, 87, 17, 7,
22 | /* left mode 5 */ 74, 43, 26, 146, 73, 166, 49, 23, 157,
23 | /* left mode 6 */ 65, 38, 105, 160, 51, 52, 31, 115, 128,
24 | /* left mode 7 */ 87, 68, 71, 44, 114, 51, 15, 186, 23,
25 | /* left mode 8 */ 47, 41, 14, 110, 182, 183, 21, 17, 194,
26 | /* left mode 9 */ 66, 45, 25, 102, 197, 189, 23, 18, 22,
27 | /* left mode 0 */ 88, 88, 147, 150, 42, 46, 45, 196, 205,
28 | /* left mode 1 */ 43, 97, 183, 117, 85, 38, 35, 179, 61,
29 | /* left mode 2 */ 39, 53, 200, 87, 26, 21, 43, 232, 171,
30 | /* left mode 3 */ 56, 34, 51, 104, 114, 102, 29, 93, 77,
31 | /* left mode 4 */ 107, 54, 32, 26, 51, 1, 81, 43, 31,
32 | /* left mode 5 */ 39, 28, 85, 171, 58, 165, 90, 98, 64,
33 | /* left mode 6 */ 34, 22, 116, 206, 23, 34, 43, 166, 73,
34 | /* left mode 7 */ 68, 25, 106, 22, 64, 171, 36, 225, 114,
35 | /* left mode 8 */ 34, 19, 21, 102, 132, 188, 16, 76, 124,
36 | /* left mode 9 */ 62, 18, 78, 95, 85, 57, 50, 48, 51,
37 | /* left mode 0 */ 193, 101, 35, 159, 215, 111, 89, 46, 111,
38 | /* left mode 1 */ 60, 148, 31, 172, 219, 228, 21, 18, 111,
39 | /* left mode 2 */ 112, 113, 77, 85, 179, 255, 38, 120, 114,
40 | /* left mode 3 */ 40, 42, 1, 196, 245, 209, 10, 25, 109,
41 | /* left mode 4 */ 100, 80, 8, 43, 154, 1, 51, 26, 71,
42 | /* left mode 5 */ 88, 43, 29, 140, 166, 213, 37, 43, 154,
43 | /* left mode 6 */ 61, 63, 30, 155, 67, 45, 68, 1, 209,
44 | /* left mode 7 */ 142, 78, 78, 16, 255, 128, 34, 197, 171,
45 | /* left mode 8 */ 41, 40, 5, 102, 211, 183, 4, 1, 221,
46 | /* left mode 9 */ 51, 50, 17, 168, 209, 192, 23, 25, 82,
47 | /* left mode 0 */ 125, 98, 42, 88, 104, 85, 117, 175, 82,
48 | /* left mode 1 */ 95, 84, 53, 89, 128, 100, 113, 101, 45,
49 | /* left mode 2 */ 75, 79, 123, 47, 51, 128, 81, 171, 1,
50 | /* left mode 3 */ 57, 17, 5, 71, 102, 57, 53, 41, 49,
51 | /* left mode 4 */ 115, 21, 2, 10, 102, 255, 166, 23, 6,
52 | /* left mode 5 */ 38, 33, 13, 121, 57, 73, 26, 1, 85,
53 | /* left mode 6 */ 41, 10, 67, 138, 77, 110, 90, 47, 114,
54 | /* left mode 7 */ 101, 29, 16, 10, 85, 128, 101, 196, 26,
55 | /* left mode 8 */ 57, 18, 10, 102, 102, 213, 34, 20, 43,
56 | /* left mode 9 */ 117, 20, 15, 36, 163, 128, 68, 1, 26,
57 | /* left mode 0 */ 138, 31, 36, 171, 27, 166, 38, 44, 229,
58 | /* left mode 1 */ 67, 87, 58, 169, 82, 115, 26, 59, 179,
59 | /* left mode 2 */ 63, 59, 90, 180, 59, 166, 93, 73, 154,
60 | /* left mode 3 */ 40, 40, 21, 116, 143, 209, 34, 39, 175,
61 | /* left mode 4 */ 57, 46, 22, 24, 128, 1, 54, 17, 37,
62 | /* left mode 5 */ 47, 15, 16, 183, 34, 223, 49, 45, 183,
63 | /* left mode 6 */ 46, 17, 33, 183, 6, 98, 15, 32, 183,
64 | /* left mode 7 */ 65, 32, 73, 115, 28, 128, 23, 128, 205,
65 | /* left mode 8 */ 40, 3, 9, 115, 51, 192, 18, 6, 223,
66 | /* left mode 9 */ 87, 37, 9, 115, 59, 77, 64, 21, 47,
67 | /* left mode 0 */ 104, 55, 44, 218, 9, 54, 53, 130, 226,
68 | /* left mode 1 */ 64, 90, 70, 205, 40, 41, 23, 26, 57,
69 | /* left mode 2 */ 54, 57, 112, 184, 5, 41, 38, 166, 213,
70 | /* left mode 3 */ 30, 34, 26, 133, 152, 116, 10, 32, 134,
71 | /* left mode 4 */ 75, 32, 12, 51, 192, 255, 160, 43, 51,
72 | /* left mode 5 */ 39, 19, 53, 221, 26, 114, 32, 73, 255,
73 | /* left mode 6 */ 31, 9, 65, 234, 2, 15, 1, 118, 73,
74 | /* left mode 7 */ 88, 31, 35, 67, 102, 85, 55, 186, 85,
75 | /* left mode 8 */ 56, 21, 23, 111, 59, 205, 45, 37, 192,
76 | /* left mode 9 */ 55, 38, 70, 124, 73, 102, 1, 34, 98,
77 | /* left mode 0 */ 102, 61, 71, 37, 34, 53, 31, 243, 192,
78 | /* left mode 1 */ 69, 60, 71, 38, 73, 119, 28, 222, 37,
79 | /* left mode 2 */ 68, 45, 128, 34, 1, 47, 11, 245, 171,
80 | /* left mode 3 */ 62, 17, 19, 70, 146, 85, 55, 62, 70,
81 | /* left mode 4 */ 75, 15, 9, 9, 64, 255, 184, 119, 16,
82 | /* left mode 5 */ 37, 43, 37, 154, 100, 163, 85, 160, 1,
83 | /* left mode 6 */ 63, 9, 92, 136, 28, 64, 32, 201, 85,
84 | /* left mode 7 */ 86, 6, 28, 5, 64, 255, 25, 248, 1,
85 | /* left mode 8 */ 56, 8, 17, 132, 137, 255, 55, 116, 128,
86 | /* left mode 9 */ 58, 15, 20, 82, 135, 57, 26, 121, 40,
87 | /* left mode 0 */ 164, 50, 31, 137, 154, 133, 25, 35, 218,
88 | /* left mode 1 */ 51, 103, 44, 131, 131, 123, 31, 6, 158,
89 | /* left mode 2 */ 86, 40, 64, 135, 148, 224, 45, 183, 128,
90 | /* left mode 3 */ 22, 26, 17, 131, 240, 154, 14, 1, 209,
91 | /* left mode 4 */ 83, 12, 13, 54, 192, 255, 68, 47, 28,
92 | /* left mode 5 */ 45, 16, 21, 91, 64, 222, 7, 1, 197,
93 | /* left mode 6 */ 56, 21, 39, 155, 60, 138, 23, 102, 213,
94 | /* left mode 7 */ 85, 26, 85, 85, 128, 128, 32, 146, 171,
95 | /* left mode 8 */ 18, 11, 7, 63, 144, 171, 4, 4, 246,
96 | /* left mode 9 */ 35, 27, 10, 146, 174, 171, 12, 26, 128,
97 | /* left mode 0 */ 190, 80, 35, 99, 180, 80, 126, 54, 45,
98 | /* left mode 1 */ 85, 126, 47, 87, 176, 51, 41, 20, 32,
99 | /* left mode 2 */ 101, 75, 128, 139, 118, 146, 116, 128, 85,
100 | /* left mode 3 */ 56, 41, 15, 176, 236, 85, 37, 9, 62,
101 | /* left mode 4 */ 146, 36, 19, 30, 171, 255, 97, 27, 20,
102 | /* left mode 5 */ 71, 30, 17, 119, 118, 255, 17, 18, 138,
103 | /* left mode 6 */ 101, 38, 60, 138, 55, 70, 43, 26, 142,
104 | /* left mode 7 */ 138, 45, 61, 62, 219, 1, 81, 188, 64,
105 | /* left mode 8 */ 32, 41, 20, 117, 151, 142, 20, 21, 163,
106 | /* left mode 9 */ 112, 19, 12, 61, 195, 128, 48, 4, 24
107 |
108 | ]);
109 | module.exports = {};
110 | module.exports.vp8_kf_bmode_prob = vp8_kf_bmode_prob;
111 | module.exports.vp8_ymode_prob = vp8_ymode_prob;
--------------------------------------------------------------------------------
/vp8/common/vp8_loopfilter.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var loopfilter_filters = require('./loopfilter_filters.js');
4 | var vp8_filter = loopfilter_filters.vp8_filter;
5 | var vp8_loop_filter_bhs_c = loopfilter_filters.vp8_loop_filter_bhs_c;
6 | var vp8_loop_filter_simple_horizontal_edge_c = loopfilter_filters.vp8_loop_filter_simple_horizontal_edge_c;
7 | var vp8_loop_filter_bvs_c = loopfilter_filters.vp8_loop_filter_bvs_c;
8 | var vp8_loop_filter_simple_vertical_edge_c = loopfilter_filters.vp8_loop_filter_simple_vertical_edge_c;
9 | var vp8_loop_filter_mbv = loopfilter_filters.vp8_loop_filter_mbv;
10 | var vp8_loop_filter_bv_c = loopfilter_filters.vp8_loop_filter_bv_c;
11 | var filter_mb_edge = loopfilter_filters.filter_mb_edge;
12 | var normal_threshold = loopfilter_filters.normal_threshold;
13 | var high_edge_variance = loopfilter_filters.high_edge_variance;
14 |
15 | var CURRENT_FRAME = 0;
16 |
17 | var VPX_PLANE_Y = 0; /**< Y (Luminance) plane */
18 | var VPX_PLANE_U = 1; /**< U (Chroma) plane */
19 | var VPX_PLANE_V = 2; /**< V (Chroma) plane */
20 |
21 | var PLANE_Y = VPX_PLANE_Y;
22 | var PLANE_U = VPX_PLANE_U;
23 | var PLANE_V = VPX_PLANE_V;
24 |
25 | var B_PRED = 4; /* block mbmid prediction, each block has its own prediction mode */
26 | var ZEROMV = 7;
27 | var SPLITMV = 9;
28 |
29 | var edge_limit = new Int32Array([0]), interior_limit = new Int32Array([0]), hev_threshold = new Int32Array([0]);
30 |
31 | function vp8_loop_filter_row_simple(ctx, row) {
32 | var y = 0;
33 | var y_off = 0;
34 | var stride = 0;
35 | var mbi;
36 | var mbi_off = 0;//='mb_info'
37 | var col = 0;
38 |
39 | /* Adjust pointers mbmid on row, start_col */
40 | stride = ctx.ref_frames[CURRENT_FRAME].img.stride[PLANE_Y];
41 | y = ctx.ref_frames[CURRENT_FRAME].img.img_data;
42 | y_off = ctx.ref_frames[CURRENT_FRAME].img.planes_off[PLANE_Y];
43 | y_off += (stride * row) << 4;
44 |
45 |
46 | mbi = ctx.mb_info_rows;
47 | mbi_off = ctx.mb_info_rows_off[1 + row];
48 | //console.log(mbi[mbi_off]);
49 | var mb_cols = ctx.mb_cols;
50 |
51 |
52 |
53 | for (col = 0; col < mb_cols; col++) {
54 |
55 |
56 | // TODO: only need to recalculate every MB if segmentation is
57 | // enabled.
58 |
59 | calculate_filter_parameters(ctx, mbi[mbi_off], edge_limit,
60 | interior_limit, hev_threshold);
61 |
62 |
63 |
64 | if (edge_limit[0]) {
65 |
66 |
67 | var filter_subblocks = (mbi[mbi_off].mbmi.eob_mask
68 | || mbi[mbi_off].mbmi.y_mode == SPLITMV
69 | || mbi[mbi_off].mbmi.y_mode == B_PRED) + 0;
70 |
71 | var mb_limit = (edge_limit[0] + 2) * 2 + interior_limit[0];
72 | var b_limit = edge_limit[0] * 2 + interior_limit[0];
73 |
74 | if (col > 0)
75 | vp8_loop_filter_simple_vertical_edge_c(y, y_off, stride, mb_limit);
76 |
77 | if (filter_subblocks)
78 | {
79 | //vp8_loop_filter_simple_bv vp8_loop_filter_bvs_c
80 | vp8_loop_filter_bvs_c(y, y_off, stride, b_limit);
81 |
82 | //filter_v_edge_simple(y, y_off + 4, stride, b_limit);
83 | //filter_v_edge_simple(y, y_off + 8, stride, b_limit);
84 | //filter_v_edge_simple(y, y_off + 12, stride, b_limit);
85 |
86 | }
87 |
88 | if (row > 0)
89 | vp8_loop_filter_simple_horizontal_edge_c(y, y_off, stride, mb_limit);
90 |
91 | if (filter_subblocks)
92 | {
93 | vp8_loop_filter_bhs_c(y, y_off, stride, b_limit);
94 | }
95 |
96 | }
97 |
98 | y_off += 16;
99 | mbi_off++;
100 | }
101 |
102 | }
103 | var edge_limit_cache = new Uint8Array([0]), interior_limit_cache = new Uint8Array([0]), hev_threshold_cache = new Uint8Array([0]);
104 |
105 | function vp8_loop_filter_row_normal(ctx, row, start_col, num_cols) {
106 |
107 | var y = 0, u = 0, v = 0;
108 | var y_off = 0, u_off = 0, v_off = 0;
109 | var stride = 0, uv_stride = 0;
110 | var mbi;
111 | var mbi_off = 0;//='mb_info'
112 | var col = 0;
113 |
114 | /* Adjust pointers mbmid on row, start_col */
115 | var currentImg = ctx.ref_frames[CURRENT_FRAME].img;
116 | stride = currentImg.stride[PLANE_Y];
117 | y = u = v = currentImg.img_data;
118 | uv_stride = currentImg.stride[PLANE_U];
119 | y_off = currentImg.planes_off[PLANE_Y];
120 | u_off = currentImg.planes_off[PLANE_U];
121 | v_off = currentImg.planes_off[PLANE_V];
122 | y_off += (stride * row) * 16;
123 | u_off += (uv_stride * row) * 8;
124 | v_off += (uv_stride * row) * 8;
125 | mbi = ctx.mb_info_rows; //[1 + row];
126 | mbi_off = ctx.mb_info_rows_off[1 + row];
127 |
128 |
129 | for (col = 0; col < num_cols; col++)
130 | {
131 | //var edge_limit = [0], interior_limit = [0], hev_threshold = [0];
132 | var edge_limit = edge_limit_cache, interior_limit = interior_limit_cache, hev_threshold = hev_threshold_cache;
133 | // TODO: only need to recalculate every MB if segmentation is
134 | // enabled.
135 |
136 |
137 | calculate_filter_parameters(ctx, mbi[mbi_off], edge_limit,
138 | interior_limit, hev_threshold);
139 |
140 | edge_limit = edge_limit[0], interior_limit = interior_limit[0], hev_threshold = hev_threshold[0];
141 |
142 |
143 | if (edge_limit)
144 | {
145 | var use_filter = mbi[mbi_off].mbmi.eob_mask
146 | || mbi[mbi_off].mbmi.y_mode === SPLITMV
147 | || mbi[mbi_off].mbmi.y_mode === B_PRED;
148 |
149 | if (col > 0)
150 | vp8_loop_filter_mbv(y, y_off, u_off, v_off, stride, uv_stride, edge_limit, interior_limit, hev_threshold);
151 |
152 |
153 | //vp8_loop_filter_bv_c
154 | if (use_filter)
155 | {
156 |
157 | vp8_loop_filter_bv_c(y, y_off, u_off, v_off, stride, uv_stride, edge_limit, interior_limit, hev_threshold);
158 |
159 | }
160 |
161 | //vp8_loop_filter_bhs_c
162 | if (row > 0) {
163 | //vp8_loop_filter_simple_horizontal_edge_c
164 | filter_mb_h_edge(y, y_off, stride, edge_limit + 2,
165 | interior_limit, hev_threshold, 2);
166 | filter_mb_h_edge(u, u_off, uv_stride, edge_limit + 2,
167 | interior_limit, hev_threshold, 1);
168 | filter_mb_h_edge(v, v_off, uv_stride, edge_limit + 2,
169 | interior_limit, hev_threshold, 1);
170 | }
171 |
172 | if (use_filter)
173 | {
174 | filter_subblock_h_edge(y, y_off + 4 * stride, stride,
175 | edge_limit, interior_limit,
176 | hev_threshold, 2);
177 | filter_subblock_h_edge(y, y_off + 8 * stride, stride,
178 | edge_limit, interior_limit,
179 | hev_threshold, 2);
180 | filter_subblock_h_edge(y, y_off + 12 * stride, stride,
181 | edge_limit, interior_limit,
182 | hev_threshold, 2);
183 | filter_subblock_h_edge(u, u_off + 4 * uv_stride, uv_stride,
184 | edge_limit, interior_limit,
185 | hev_threshold, 1);
186 | filter_subblock_h_edge(v, v_off + 4 * uv_stride, uv_stride,
187 | edge_limit, interior_limit,
188 | hev_threshold, 1);
189 | }
190 |
191 | }
192 |
193 | y_off += 16;
194 | u_off += 8;
195 | v_off += 8;
196 | mbi_off++;
197 | }
198 |
199 | }
200 |
201 | function calculate_filter_parameters(ctx,
202 | mbi,
203 | edge_limit_,
204 | interior_limit_,
205 | hev_threshold_) {
206 | var filter_level = 0, interior_limit = 0, hev_threshold = 0;
207 |
208 | /* Reference code/spec seems to conflate filter_level and
209 | * edge_limit
210 | */
211 |
212 | filter_level = ctx.common.level;
213 | //console.warn(mbi);
214 |
215 | if (ctx.segment_hdr.enabled === 1)
216 | {
217 | if (!ctx.segment_hdr.abs)
218 | filter_level += ctx.segment_hdr.lf_level[mbi.mbmi.segment_id];
219 | else
220 | filter_level = ctx.segment_hdr.lf_level[mbi.mbmi.segment_id];
221 | }
222 |
223 |
224 |
225 |
226 | if (ctx.common.delta_enabled)
227 | {
228 | filter_level +=
229 | ctx.common.ref_delta[mbi.mbmi.ref_frame];
230 |
231 | if (mbi.mbmi.ref_frame === CURRENT_FRAME)
232 | {
233 | if (mbi.mbmi.y_mode === B_PRED)
234 | filter_level += ctx.common.mode_delta[0];
235 | } else if (mbi.mbmi.y_mode === ZEROMV)
236 | filter_level += ctx.common.mode_delta[1];
237 | else if (mbi.mbmi.y_mode === SPLITMV)
238 | filter_level += ctx.common.mode_delta[3];
239 | else
240 | filter_level += ctx.common.mode_delta[2];
241 | }
242 |
243 | if (filter_level > 63)
244 | filter_level = 63;
245 | else if (filter_level < 0)
246 | filter_level = 0;
247 |
248 | interior_limit = filter_level;
249 |
250 | if (ctx.common.sharpness)
251 | {
252 | interior_limit >>= ctx.common.sharpness > 4 ? 2 : 1;
253 |
254 | if (interior_limit > 9 - ctx.common.sharpness)
255 | interior_limit = 9 - ctx.common.sharpness;
256 | }
257 |
258 |
259 |
260 |
261 |
262 | if (interior_limit < 1)
263 | interior_limit = 1;
264 |
265 | if (filter_level >= 15) {
266 | hev_threshold = 1;
267 | } else {
268 | hev_threshold = 0;
269 | }
270 |
271 | if (filter_level >= 40)
272 | hev_threshold++;
273 |
274 | if (filter_level >= 20 && !ctx.common.is_keyframe)
275 | hev_threshold++;
276 |
277 | edge_limit_[0] = filter_level;
278 | interior_limit_[0] = interior_limit;
279 | hev_threshold_[0] = hev_threshold;
280 |
281 | }
282 |
283 |
284 |
285 | function filter_mb_h_edge(src, src_off, stride,
286 | edge_limit, interior_limit, hev_threshold, size) {
287 | var i = 0;
288 |
289 | var length = size << 3;
290 | for (i = 0; i < length; i++) {
291 | if (normal_threshold(src, src_off, stride, edge_limit, interior_limit))
292 | {
293 | if (high_edge_variance(src, src_off, stride, hev_threshold))
294 | vp8_filter(src, src_off, stride, 1);
295 | else
296 | filter_mb_edge(src, src_off, stride);
297 | }
298 |
299 | src_off += 1;
300 | }
301 | }
302 |
303 | function filter_subblock_h_edge(src,
304 | src_off,
305 | stride,
306 | edge_limit,
307 | interior_limit,
308 | hev_threshold,
309 | size) {
310 | var i = 0;
311 | var length = size << 3;
312 | for (i = 0; i < length; i++) {
313 | if (normal_threshold(src, src_off, stride, edge_limit, interior_limit))
314 | vp8_filter(src, src_off, stride,
315 | high_edge_variance(src, src_off, stride,
316 | hev_threshold));
317 |
318 | src_off += 1;
319 | }
320 | }
321 |
322 |
323 | module.exports = {};
324 | module.exports.vp8_loop_filter_row_normal = vp8_loop_filter_row_normal;
325 | module.exports.vp8_loop_filter_row_simple = vp8_loop_filter_row_simple;
--------------------------------------------------------------------------------
/vp8/decoder/dboolhuff.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var bitreader = require('../../vpx_dsp/bitreader.js');
4 | var vpx_read = bitreader.vpx_read;
5 | var vpx_read_bit = bitreader.vpx_read_bit;
6 |
7 | class BOOL_DECODER {
8 |
9 | constructor() {
10 | this.range = 0;
11 | this.value = 0;
12 | this.input = 0;
13 | this.ptr = 0; //dont need
14 | this.input_len = 0;
15 | this.bit_count = 0;
16 | this.buffer_end;
17 | this.decrypt_cb;
18 | this.decrypt_state;
19 | this.clear_buffer;
20 | }
21 |
22 | get_uint(bits){
23 | return bool_get_uint(this, bits);
24 | }
25 |
26 | get_int(bits){
27 | return bool_get_int(this, bits);
28 | }
29 |
30 | maybe_get_int(bits){
31 | return bool_maybe_get_int(this, bits);
32 | }
33 |
34 | }
35 |
36 | function vp8dx_start_decode(bool, start_partition, ptr, sz) {
37 |
38 | if (sz >= 2) {
39 | bool.value = (start_partition[ptr] << 8) | start_partition[ptr + 1];
40 | bool.input = start_partition;
41 | bool.ptr = (ptr + 2) | 0;
42 | bool.input_len = (sz - 2) | 0;
43 | } else {
44 | bool.value = 0;
45 | bool.input = null;
46 | bool.input_len = 0;
47 | }
48 |
49 | bool.range = 255;
50 | bool.bit_count = 0;
51 | }
52 |
53 | function get_uint(bool, bits) {
54 | var z = 0;
55 | var bit = 0;
56 |
57 | for (bit = bits - 1; bit >= 0; bit--) {
58 | z |= (vpx_read_bit(bool) << bit);
59 | }
60 |
61 | return z;
62 | }
63 | var bool_get_uint = get_uint;
64 |
65 | /*
66 | * bool_get_int
67 | * vp8_decode_value
68 | * @param {type} bits
69 | * @returns {BoolDecoder.get_int.z|Number}
70 | */
71 | function bool_get_int(bool, bits) {
72 | var z = 0;
73 | var bit = 0;
74 |
75 | for (bit = bits - 1; bit >= 0; bit--)
76 | {
77 | z |= (vpx_read_bit(bool) << bit);
78 | }
79 |
80 | return vpx_read_bit(bool) ? -z : z;
81 | }
82 |
83 | function maybe_get_int(bool, bits) {
84 |
85 | return vpx_read_bit(bool) ? bool.get_int(bits) : 0;
86 | }
87 |
88 | var bool_maybe_get_int = maybe_get_int;
89 |
90 | module.exports = {};
91 | module.exports.vp8dx_start_decode = vp8dx_start_decode;
92 | module.exports.bool_get_int = bool_get_int;
93 | //module.exports.maybe_get_int = maybe_get_int;
94 |
95 | module.exports.BOOL_DECODER = BOOL_DECODER;
96 |
97 |
--------------------------------------------------------------------------------
/vp8/decoder/detokenize.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var blockd = require('../common/blockd.js');
4 | var vp8_block2left = blockd.vp8_block2left;
5 | var vp8_block2above = blockd.vp8_block2above;
6 |
7 | var bitreader = require('../../vpx_dsp/bitreader.js');
8 | var vpx_read = bitreader.vpx_read;
9 | var vpx_read_bit = bitreader.vpx_read_bit;
10 |
11 | var c_utils = require('../../util/c_utils.js');
12 | var memset = c_utils.memset;
13 |
14 | var B_PRED = 4;
15 | var SPLITMV = 9;
16 |
17 | var TOKEN_BLOCK_Y1 = 0;
18 | var TOKEN_BLOCK_UV = 1;
19 | var TOKEN_BLOCK_Y2 = 2;
20 | var TOKEN_BLOCK_TYPES = 3;
21 |
22 | var EOB_CONTEXT_NODE = 0;
23 | var ZERO_CONTEXT_NODE = 1;
24 | var ONE_CONTEXT_NODE = 2;
25 | var LOW_VAL_CONTEXT_NODE = 3;
26 | var TWO_CONTEXT_NODE = 4;
27 | var THREE_CONTEXT_NODE = 5;
28 | var HIGH_LOW_CONTEXT_NODE = 6;
29 | var CAT_ONE_CONTEXT_NODE = 7;
30 | var CAT_THREEFOUR_CONTEXT_NODE = 8;
31 | var CAT_THREE_CONTEXT_NODE = 9;
32 | var CAT_FIVE_CONTEXT_NODE = 10;
33 |
34 |
35 | var DCT_VAL_CATEGORY1 = 5;
36 | var DCT_VAL_CATEGORY2 = 6;
37 | var DCT_VAL_CATEGORY3 = 7;
38 | var DCT_VAL_CATEGORY4 = 8;
39 | var DCT_VAL_CATEGORY5 = 9;
40 | var DCT_VAL_CATEGORY6 = 10;
41 |
42 |
43 | var ENTROPY_NODES = 11;
44 |
45 | /**
46 | * Comparable to vp8_reset_mb_tokens_context
47 | * @param {type} left
48 | * @param {type} above
49 | * @param {type} mode
50 | * @returns {null}
51 | */
52 | var context_clear = new Uint32Array(8);
53 | function vp8_reset_mb_tokens_context(left, above, mode) {
54 | /* Reset the macroblock context on the left and right. We have to
55 | * preserve the context of the second order block if this mode
56 | * would not have updated it.
57 | */
58 | left.set(context_clear);
59 | above.set(context_clear);
60 | //memset(left, 0, 0, 8);
61 | //memset(above, 0, 0, 8);
62 |
63 |
64 |
65 | if (mode !== B_PRED && mode !== SPLITMV) {
66 | left[8] = 0;
67 | above[8] = 0;
68 | }
69 | }
70 |
71 |
72 |
73 | function X(n) {
74 | return ((n) * 33); //PREV_COEF_CONTEXTS * ENTROPY_NODES
75 | }
76 |
77 | var bands_x =
78 | new Int32Array([
79 | X(0), X(1), X(2), X(3), X(6), X(4), X(5), X(6),
80 | X(6), X(6), X(6), X(6), X(6), X(6), X(6), X(7)
81 | ]);
82 |
83 | var extrabits =
84 | [
85 | {min_val: 0, length: -1, probs: new Uint8Array([0, 0, 0, 0, 0, 0,
86 | 0, 0, 0, 0, 0, 0])}, //ZERO_TOKEN
87 | {min_val: 1, length: 0, probs: new Uint8Array([0, 0, 0, 0, 0, 0,
88 | 0, 0, 0, 0, 0, 0])}, //ONE_TOKEN
89 | {min_val: 2, length: 0, probs: new Uint8Array([0, 0, 0, 0, 0, 0,
90 | 0, 0, 0, 0, 0, 0])}, //TWO_TOKEN
91 | {min_val: 3, length: 0, probs: new Uint8Array([0, 0, 0, 0, 0, 0,
92 | 0, 0, 0, 0, 0, 0])}, //THREE_TOKEN
93 | {min_val: 4, length: 0, probs: new Uint8Array([0, 0, 0, 0, 0, 0,
94 | 0, 0, 0, 0, 0, 0])}, //FOUR_TOKEN
95 | {min_val: 5, length: 0, probs: new Uint8Array([159, 0, 0, 0, 0, 0,
96 | 0, 0, 0, 0, 0, 0])}, //DCT_VAL_CATEGORY1
97 | {min_val: 7, length: 1, probs: new Uint8Array([145, 165, 0, 0, 0, 0,
98 | 0, 0, 0, 0, 0, 0])}, //DCT_VAL_CATEGORY2
99 | {min_val: 11, length: 2, probs: new Uint8Array([140, 148, 173, 0, 0, 0,
100 | 0, 0, 0, 0, 0, 0])}, //DCT_VAL_CATEGORY3
101 | {min_val: 19, length: 3, probs: new Uint8Array([135, 140, 155, 176, 0, 0,
102 | 0, 0, 0, 0, 0, 0])}, //DCT_VAL_CATEGORY4
103 | {min_val: 35, length: 4, probs: new Uint8Array([130, 134, 141, 157, 180, 0,
104 | 0, 0, 0, 0, 0, 0])}, //DCT_VAL_CATEGORY5
105 | {min_val: 67, length: 10, probs: new Uint8Array([129, 130, 133, 140, 153, 177,
106 | 196, 230, 243, 254, 254, 0])}, //DCT_VAL_CATEGORY6
107 | {min_val: 0, length: -1, probs: new Uint8Array([0, 0, 0, 0, 0, 0,
108 | 0, 0, 0, 0, 0, 0])} // EOB TOKEN
109 | ];
110 |
111 | var zigzag = new Uint32Array([
112 | 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15
113 | ]);
114 |
115 | var BLOCK_LOOP = 0, DO_WHILE = 1, CHECK_0_ = 2, CAT_FIVE_CONTEXT_NODE_0_ = 3, CAT_THREEFOUR_CONTEXT_NODE_0_ = 4, CAT_THREE_CONTEXT_NODE_0_ = 5, HIGH_LOW_CONTEXT_NODE_0_ = 6, CAT_ONE_CONTEXT_NODE_0_ = 7, LOW_VAL_CONTEXT_NODE_0_ = 8, THREE_CONTEXT_NODE_0_ = 9, TWO_CONTEXT_NODE_0_ = 10, ONE_CONTEXT_NODE_0_ = 11, BLOCK_FINISHED = 12, END = 13;
116 |
117 |
118 | var i = 0, stopp = 0, type = 0;
119 | var c = 0, t = 0, v = 0;
120 | var val = 0, bits_count = 0;
121 | var eob_mask = 0;
122 | var b_tokens = 0;
123 | var b_tokens_off = 0;//* /* tokens for this block */
124 | var type_probs = 0;
125 | var type_probs_off = 0;//* /* probabilities for this block type */
126 | var prob = 0;
127 | var prob_off = 0;//*
128 | var dqf = 0;
129 | var global_bool;
130 | var goto_;
131 |
132 | function DECODE_AND_APPLYSIGN(value_to_sign) {
133 |
134 | if (vpx_read_bit(global_bool) === 1) {
135 | v = -value_to_sign * dqf[(!!c) + 0];
136 | } else {
137 | v = value_to_sign * dqf[(!!c) + 0];
138 | }
139 | }
140 |
141 | function DECODE_AND_BRANCH_IF_ZERO(probability, branch) {
142 | if (!vpx_read(global_bool, probability)) {
143 | goto_ = branch;
144 | return 1;
145 | }
146 | }
147 |
148 | function DECODE_EXTRABIT_AND_ADJUST_VAL(t, bits_count) {
149 | val += vpx_read(global_bool, extrabits[t].probs[bits_count]) << bits_count;
150 | }
151 |
152 |
153 | function DECODE_AND_LOOP_IF_ZERO(probability, branch) {
154 | if (!vpx_read(global_bool, probability))
155 | {
156 | prob_off = type_probs_off;
157 | if (c < 15) {
158 | ++c;
159 | prob_off += bands_x[c] | 0;
160 | goto_ = branch;
161 | return 1;
162 | } else {
163 | goto_ = BLOCK_FINISHED;
164 | return 1; /*for malformed input */
165 | }
166 | }
167 | }
168 |
169 | function DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val) {
170 | DECODE_AND_APPLYSIGN(val);
171 | prob_off = type_probs_off + 22;//(ENTROPY_NODES * 2)
172 | if (c < 15) {
173 | b_tokens[b_tokens_off + zigzag[c]] = v;
174 | ++c;
175 | goto_ = DO_WHILE;
176 | return 1;
177 | }
178 | b_tokens[b_tokens_off + zigzag[15]] = v;
179 | goto_ = BLOCK_FINISHED;
180 | return 1;
181 | }
182 |
183 |
184 | function decode_mb_tokens(bool, left,
185 | above,
186 | tokens,
187 | tokens_off,
188 | mode,
189 | probs, factor) {
190 |
191 | global_bool = bool;
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 | //*
202 |
203 | eob_mask = 0;
204 |
205 | if (mode !== B_PRED && mode !== SPLITMV)
206 | {
207 | i = 24;
208 | stopp = 24;
209 | type = 1;
210 | b_tokens = tokens;
211 | b_tokens_off = tokens_off + 384;
212 | dqf = factor[TOKEN_BLOCK_Y2];
213 | } else {
214 | i = 0;
215 | stopp = 16;
216 | type = 3;
217 | b_tokens = tokens;
218 | b_tokens_off = tokens_off;
219 | dqf = factor[TOKEN_BLOCK_Y1];
220 | }
221 |
222 | /* Save a pointer to the coefficient probs for the current type.
223 | * Need to repeat this whenever type changes.
224 | */
225 | type_probs = probs; /*[type][0][0];*/
226 | type_probs_off = type * 264; //COEF_BANDS * PREV_COEF_CONTEXTS * ENTROPY_NODES; //8 * 3 * 11
227 |
228 | goto_ = BLOCK_LOOP;
229 | do {
230 | if (goto_ === BLOCK_LOOP) {
231 | t = left[vp8_block2left[i]] + above[vp8_block2above[i]];
232 | c = (!type) + 0; /* all blocks start at 0 except type 0, which starts
233 | * at 1. */
234 |
235 | prob = type_probs;
236 | prob_off = type_probs_off;
237 | prob_off += t * ENTROPY_NODES;
238 |
239 | goto_ = DO_WHILE;
240 | }
241 | if (goto_ === DO_WHILE) {
242 | prob_off += bands_x[c];
243 | if (DECODE_AND_BRANCH_IF_ZERO(prob[prob_off + EOB_CONTEXT_NODE], BLOCK_FINISHED))
244 | continue;
245 |
246 | goto_ = CHECK_0_;
247 | }
248 | if (goto_ === CHECK_0_) {
249 | if (DECODE_AND_LOOP_IF_ZERO(prob[prob_off + ZERO_CONTEXT_NODE], CHECK_0_) === 1)
250 | continue;
251 | if (DECODE_AND_BRANCH_IF_ZERO(prob[prob_off + ONE_CONTEXT_NODE],
252 | ONE_CONTEXT_NODE_0_) === 1)
253 | continue;
254 | if (DECODE_AND_BRANCH_IF_ZERO(prob[prob_off + LOW_VAL_CONTEXT_NODE],
255 | LOW_VAL_CONTEXT_NODE_0_) === 1)
256 | continue;
257 | if (DECODE_AND_BRANCH_IF_ZERO(prob[prob_off + HIGH_LOW_CONTEXT_NODE],
258 | HIGH_LOW_CONTEXT_NODE_0_) === 1)
259 | continue;
260 | if (DECODE_AND_BRANCH_IF_ZERO(prob[prob_off + CAT_THREEFOUR_CONTEXT_NODE],
261 | CAT_THREEFOUR_CONTEXT_NODE_0_) === 1)
262 | continue;
263 | if (DECODE_AND_BRANCH_IF_ZERO(prob[prob_off + CAT_FIVE_CONTEXT_NODE],
264 | CAT_FIVE_CONTEXT_NODE_0_) === 1)
265 | continue;
266 | val = extrabits[DCT_VAL_CATEGORY6].min_val;
267 | bits_count = extrabits[DCT_VAL_CATEGORY6].length;
268 |
269 | do
270 | {
271 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY6, bits_count);
272 | bits_count--;
273 | } while (bits_count >= 0);
274 |
275 | if (DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val) === 1)
276 | continue;
277 |
278 | }
279 | if (goto_ === CAT_FIVE_CONTEXT_NODE_0_) {
280 | val = extrabits[DCT_VAL_CATEGORY5].min_val;
281 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 4);
282 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 3);
283 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 2);
284 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 1);
285 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 0);
286 | if (DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val) === 1)
287 | continue;
288 |
289 | }
290 | if (goto_ === CAT_THREEFOUR_CONTEXT_NODE_0_) {
291 | if (DECODE_AND_BRANCH_IF_ZERO(prob[prob_off + CAT_THREE_CONTEXT_NODE],
292 | CAT_THREE_CONTEXT_NODE_0_) === 1)
293 | continue;
294 | val = extrabits[DCT_VAL_CATEGORY4].min_val;
295 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 3);
296 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 2);
297 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 1);
298 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 0);
299 | if (DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val) === 1)
300 | continue;
301 |
302 | }
303 | if (goto_ === CAT_THREE_CONTEXT_NODE_0_) {
304 | val = extrabits[DCT_VAL_CATEGORY3].min_val;
305 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY3, 2);
306 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY3, 1);
307 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY3, 0);
308 | if (DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val) === 1)
309 | continue;
310 |
311 | }
312 | if (goto_ === HIGH_LOW_CONTEXT_NODE_0_) {
313 | if (DECODE_AND_BRANCH_IF_ZERO(prob[prob_off + CAT_ONE_CONTEXT_NODE],
314 | CAT_ONE_CONTEXT_NODE_0_) === 1)
315 | continue;
316 |
317 | val = extrabits[DCT_VAL_CATEGORY2].min_val;
318 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY2, 1);
319 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY2, 0);
320 | if (DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val) === 1)
321 | continue;
322 |
323 | }
324 | if (goto_ === CAT_ONE_CONTEXT_NODE_0_) {
325 | val = extrabits[DCT_VAL_CATEGORY1].min_val;
326 | DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY1, 0);
327 | if (DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val) === 1)
328 | continue;
329 |
330 | }
331 | if (goto_ === LOW_VAL_CONTEXT_NODE_0_) {
332 | if (DECODE_AND_BRANCH_IF_ZERO(prob[prob_off + TWO_CONTEXT_NODE],
333 | TWO_CONTEXT_NODE_0_))
334 | continue;
335 | if (DECODE_AND_BRANCH_IF_ZERO(prob[prob_off + THREE_CONTEXT_NODE],
336 | THREE_CONTEXT_NODE_0_))
337 | continue;
338 | if (DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(4))
339 | continue;
340 |
341 | }
342 | if (goto_ === THREE_CONTEXT_NODE_0_) {
343 | if (DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(3))
344 | continue;
345 |
346 | }
347 | if (goto_ === TWO_CONTEXT_NODE_0_) {
348 | if (DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(2))
349 | continue;
350 |
351 | }
352 | if (goto_ === ONE_CONTEXT_NODE_0_) {
353 | DECODE_AND_APPLYSIGN(1);
354 | prob_off = type_probs_off + ENTROPY_NODES;
355 |
356 | if (c < 15)
357 | {
358 | b_tokens[b_tokens_off + zigzag[c]] = v;
359 | ++c;
360 | goto_ = DO_WHILE;
361 | continue;
362 | }
363 |
364 | b_tokens[b_tokens_off + zigzag[15]] = v;
365 | goto_ = BLOCK_FINISHED;
366 | }
367 | if (goto_ === BLOCK_FINISHED) {
368 | eob_mask = (eob_mask | ((c > 1) + 0 << i)) >>> 0;
369 | t = (c != !type) + 0; // any nonzero data?
370 | eob_mask = (eob_mask | (t << 31)) >>> 0;//intBitLeft(t , 31);
371 |
372 | left[vp8_block2left[i]] = above[vp8_block2above[i]] = t;
373 | b_tokens_off += 16;
374 |
375 | i++;
376 |
377 | if (i < stopp) {
378 | goto_ = BLOCK_LOOP;
379 | continue;
380 | }
381 |
382 | if (i === 25)
383 | {
384 | type = 0;
385 | i = 0;
386 | stopp = 16;
387 | type_probs_off = type << 8;//type_probs = probs[type][0][0]; //COEF_BANDS * PREV_COEF_CONTEXTS * ENTROPY_NODES
388 | b_tokens_off = tokens_off;
389 | dqf = factor[TOKEN_BLOCK_Y1];
390 | goto_ = BLOCK_LOOP;
391 | continue;
392 | }
393 |
394 | if (i === 16)
395 | {
396 | type = 2;
397 | type_probs_off = type * 264;//type_probs = probs[type][0][0];
398 | stopp = 24;
399 | dqf = factor[TOKEN_BLOCK_UV];
400 | goto_ = BLOCK_LOOP;
401 | continue;
402 | }
403 | }
404 | goto_ = END;
405 | } while (goto_ !== END);
406 |
407 | return eob_mask;
408 | }
409 |
410 | module.exports = {};
411 | module.exports.decode_mb_tokens = decode_mb_tokens;
412 | module.exports.vp8_reset_mb_tokens_context = vp8_reset_mb_tokens_context;
--------------------------------------------------------------------------------
/vp8/decoder/onyxc_int.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | /**
4 | * file onyxc_int
5 | */
6 | var NUM_YV12_BUFFERS = 4;
7 | var MAX_MB_SEGMENTS = 4;
8 |
9 | class dequant_factors {
10 | constructor() {
11 | this.quant_idx = 0;
12 | this.factor = [
13 | new Int16Array([0, 0]), //Y1
14 | new Int16Array([0, 0]), // UV
15 | new Int16Array([0, 0]) //Y2
16 | ];
17 | }
18 | }
19 |
20 | class VP8_COMMON {
21 |
22 | constructor() {
23 | this.error = 0;
24 |
25 | this.dequant_factors = new Array(MAX_MB_SEGMENTS);
26 | for (var i = 0; i < MAX_MB_SEGMENTS; i ++)
27 | this.dequant_factors[i] = new dequant_factors();
28 |
29 | this.Width;
30 | this.Height;
31 | this.horiz_scale;
32 | this.vert_scale;
33 |
34 | this.clamp_type; //CLAMP_TYPE
35 |
36 | this.frame_to_show; // YV12_BUFFER_CONFIG
37 |
38 | this.yv12_fb = new Array(NUM_YV12_BUFFERS);//YV12_BUFFER_CONFIG
39 | this.fb_idx_ref_cnt = new Array(NUM_YV12_BUFFERS);
40 | this.new_fb_idx = 0;
41 | this.lst_fb_idx = 0;
42 | this.gld_fb_idx = 0;
43 | this.alt_fb_idx = 0;
44 |
45 | this.temp_scale_frame;// YV12_BUFFER_CONFIG
46 |
47 |
48 | this.last_frame_type; // FRAME_TYPE - Save last frame's frame type for motion search.
49 | this.frame_type; //FRAME_TYPE
50 | }
51 |
52 | }
53 |
54 | module.exports = VP8_COMMON;
--------------------------------------------------------------------------------
/vp8/decoder/onyxd_if.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var decodeframe = require('./decodeframe');
4 | var vp8_decode_frame = decodeframe.vp8_decode_frame;
5 |
6 | var CURRENT_FRAME = 0;
7 | var LAST_FRAME = 1;
8 | var GOLDEN_FRAME = 2;
9 | var ALTREF_FRAME = 3;
10 | var NUM_REF_FRAMES = 4;
11 |
12 | function vp8_dixie_release_ref_frame(rcimg) {
13 |
14 | if (rcimg) {
15 | if (rcimg.ref_cnt === 0)
16 | throw "ERROR :(";
17 | rcimg.ref_cnt--;
18 | }
19 |
20 | }
21 |
22 | function vp8_dixie_ref_frame(rcimg) {
23 |
24 | rcimg.ref_cnt++;
25 | return rcimg;
26 |
27 | }
28 |
29 | function vp8dx_receive_compressed_data(pbi, size, source, time_stamp){
30 |
31 | var retcode = 0;
32 | //console.log("Compressed data called");
33 | retcode = vp8_decode_frame(source , pbi);
34 |
35 | swap_frame_buffers(pbi);
36 |
37 | }
38 |
39 |
40 | //vp8_dixie_release_ref_frame
41 | //vp8_dixie_ref_frame
42 | function ref_cnt_fb(buf, idx, new_idx) {
43 | if (buf[idx] > 0)
44 | buf[idx]--;
45 |
46 | idx = new_idx;
47 |
48 | buf[new_idx]++;
49 | }
50 |
51 | function swap_frame_buffers(cm){
52 | var err = 0;
53 |
54 |
55 |
56 | /* Handle reference frame updates */
57 | if (cm.common.copy_arf === 1) {
58 |
59 | vp8_dixie_release_ref_frame(cm.ref_frames[ALTREF_FRAME]);
60 | cm.ref_frames[ALTREF_FRAME] =
61 | vp8_dixie_ref_frame(cm.ref_frames[LAST_FRAME]);
62 |
63 |
64 | //ref_cnt_fb( ALTREF_FRAME, LAST_FRAME);
65 | } else if (cm.common.copy_arf === 2) {
66 |
67 | vp8_dixie_release_ref_frame(cm.ref_frames[ALTREF_FRAME]);
68 | cm.ref_frames[ALTREF_FRAME] =
69 | vp8_dixie_ref_frame(cm.ref_frames[GOLDEN_FRAME]);
70 |
71 | }
72 |
73 |
74 |
75 | if (cm.common.copy_gf === 1)
76 | {
77 | vp8_dixie_release_ref_frame(cm.ref_frames[GOLDEN_FRAME]);
78 | cm.ref_frames[GOLDEN_FRAME] =
79 | vp8_dixie_ref_frame(cm.ref_frames[LAST_FRAME]);
80 | } else if (cm.common.copy_gf === 2)
81 | {
82 | vp8_dixie_release_ref_frame(cm.ref_frames[GOLDEN_FRAME]);
83 | cm.ref_frames[GOLDEN_FRAME] =
84 | vp8_dixie_ref_frame(cm.ref_frames[ALTREF_FRAME]);
85 | }
86 |
87 | if (cm.common.refresh_gf === 1)
88 | {
89 | vp8_dixie_release_ref_frame(cm.ref_frames[GOLDEN_FRAME]);
90 | cm.ref_frames[GOLDEN_FRAME] =
91 | vp8_dixie_ref_frame(cm.ref_frames[CURRENT_FRAME]);
92 | }
93 |
94 | if (cm.common.refresh_arf === 1)
95 | {
96 | vp8_dixie_release_ref_frame(cm.ref_frames[ALTREF_FRAME]);
97 | cm.ref_frames[ALTREF_FRAME] =
98 | vp8_dixie_ref_frame(cm.ref_frames[CURRENT_FRAME]);
99 | }
100 |
101 | if (cm.common.refresh_last === 1)
102 | {
103 | vp8_dixie_release_ref_frame(cm.ref_frames[LAST_FRAME]);
104 | cm.ref_frames[LAST_FRAME] =
105 | vp8_dixie_ref_frame(cm.ref_frames[CURRENT_FRAME]);
106 | }
107 |
108 |
109 |
110 | }
111 |
112 |
113 | module.exports = {
114 | vp8dx_receive_compressed_data:vp8dx_receive_compressed_data
115 | };
--------------------------------------------------------------------------------
/vp8/decoder/onyxd_int.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var VP8_COMMON = require('../common/onyxc_int');
3 |
4 | var dboolhuff = require('./dboolhuff.js');
5 | var BoolDecoder = dboolhuff.BOOL_DECODER;
6 |
7 |
8 | var blockd = require('../common/blockd.js');
9 | var MACROBLOCKD = blockd.MACROBLOCKD;
10 | var FRAGMENT_DATA = blockd.FRAGMENT_DATA;
11 | var mb_info = blockd.MODE_INFO;
12 |
13 | var vpx_image = require('../../vpx/vpx_image.js');
14 | var vpx_image_t = vpx_image.vpx_image_t;
15 |
16 |
17 | var CURRENT_FRAME = 0;
18 | var LAST_FRAME = 1;
19 | var GOLDEN_FRAME = 2;
20 | var ALTREF_FRAME = 3;
21 | var NUM_REF_FRAMES = 4;
22 |
23 | var MAX_PARTITIONS = 8;
24 | var MAX_MB_SEGMENTS = 4;
25 |
26 |
27 |
28 |
29 | var MAX_FB_MT_DEC = 32;
30 |
31 | Uint8Array.prototype.ptr = 0;
32 |
33 | class frame_buffers {
34 | /*
35 | * this struct will be populated with frame buffer management
36 | * info in future commits. */
37 |
38 | // decoder instances
39 | constructor() {
40 | this.pbi = new Array(MAX_FB_MT_DEC);//VP8D_COMP
41 | }
42 |
43 | }
44 | ;
45 |
46 |
47 | var ref_cnt_img = function () {
48 | this.img = new vpx_image_t();
49 | this.ref_cnt = 0;
50 | };
51 |
52 |
53 |
54 | //possibly line 65 vp8common
55 | class dequant_factors {
56 | constructor() {
57 | this.quant_idx = 0;
58 | this.factor = [
59 | new Int16Array([0, 0]), //Y1
60 | new Int16Array([0, 0]), // UV
61 | new Int16Array([0, 0]) //Y2
62 | ];
63 |
64 | }
65 | }
66 |
67 |
68 |
69 | class token_decoder {
70 |
71 | constructor() {
72 | this.bool = new BoolDecoder();
73 | this.left_token_entropy_ctx = new Int32Array(9);
74 | this.coeffs = null;
75 | }
76 |
77 | }
78 |
79 |
80 |
81 |
82 | //VP8D_COMP
83 | class VP8D_COMP {
84 |
85 | constructor() {
86 |
87 | this.frame_cnt = 0;
88 |
89 | this.cpuTime = 0;
90 |
91 | this.saved_entropy_valid = 0;
92 |
93 | this.mb_info_rows_storage = null; //**
94 | this.mb_info_rows_storage_off = 0;
95 | this.mb_info_rows_storage_object = (mb_info); //new
96 | this.mb_info_rows = null; //mb_info**
97 | this.mb_info_rows_off = 0;
98 | this.above_token_entropy_ctx = null;
99 | //this.above_token_entropy_ctx_object = (token_entropy_ctx_t); //*
100 |
101 | this.common = new VP8_COMMON();
102 | this.boolDecoder = new BoolDecoder();
103 | this.segment_hdr = new MACROBLOCKD(this);
104 | this.token_hdr = new FRAGMENT_DATA(this);
105 |
106 |
107 |
108 | this.tokens = new Array(MAX_PARTITIONS);
109 | for (var i = 0; i < MAX_PARTITIONS; i ++)
110 | this.tokens[i] = new token_decoder();
111 |
112 |
113 |
114 | this.frame_strg = [
115 | {
116 | img: new vpx_image_t(),
117 | ref_cnt: 0
118 | },
119 | {
120 | img: new vpx_image_t(),
121 | ref_cnt: 0
122 | },
123 | {
124 | img: new vpx_image_t(),
125 | ref_cnt: 0
126 | },
127 | {
128 | img: new vpx_image_t(),
129 | ref_cnt: 0
130 | }
131 | ];
132 |
133 |
134 | this.ref_frames = new Array(NUM_REF_FRAMES);
135 | for (var i = 0; i < NUM_REF_FRAMES; i ++)
136 | this.ref_frames[i] = new ref_cnt_img();
137 |
138 | this.dequant_factors = new Array(MAX_MB_SEGMENTS);
139 | for (var i = 0; i < MAX_MB_SEGMENTS; i ++)
140 | this.dequant_factors[i] = new dequant_factors();
141 |
142 |
143 |
144 |
145 |
146 | this.ref_frame_offsets = new Uint32Array([0, 0, 0, 0]);
147 | this.ref_frame = null;
148 | this.ref_frame_offsets_ = [0, 0, 0, 0];
149 | this.subpixel_filters = null;
150 |
151 | this.img_avail;
152 | this.img;
153 |
154 | }
155 |
156 |
157 |
158 | /**
159 | * vp8_alloc_frame_buffers
160 | * vp8_dixie_modemv_init
161 | * @returns {undefined}
162 | */
163 | modemv_init() {
164 | var mbi_w = 0;
165 | var mbi_h = 0;
166 | var i = 0;
167 | var mbi = mbi_cache;
168 |
169 |
170 | mbi_w = this.mb_cols + 1; /* For left border col */
171 | mbi_h = this.mb_rows + 1; /* For above border row */
172 |
173 | this.common.mode_info_stride = this.mb_cols + 1;
174 |
175 | if (this.common.frame_size_updated === 1) {
176 | this.mb_info_storage = null;
177 | this.mb_info_rows_storage = null;
178 |
179 | var length = mbi_w * mbi_h;
180 | this.mb_info_storage = new Array(length);
181 |
182 |
183 | for (var i = 0; i < length; i ++)
184 | this.mb_info_storage[i] = new mb_info();
185 |
186 | this.mb_info_storage_off = 0;
187 |
188 | this.mb_info_rows_off = new Uint32Array(mbi_h);
189 | }
190 |
191 |
192 |
193 | var ptr = 1;
194 |
195 | for (i = 0; i < mbi_h; i++) {
196 | this.mb_info_rows_off[i] = ptr;
197 | ptr = (ptr + mbi_w) | 0;
198 | }
199 |
200 |
201 | this.mb_info_rows = this.mb_info_storage;
202 | //this.mb_info_rows_off = this.mb_info_rows_storage_off;
203 | }
204 |
205 |
206 | }
207 |
208 | var mbi_cache = new mb_info();
209 |
210 | module.exports = VP8D_COMP;
--------------------------------------------------------------------------------
/vp8/decoder/treereader.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var bitreader = require('../../vpx_dsp/bitreader.js');
4 | var vpx_read = bitreader.vpx_read;
5 |
6 |
7 | function vp8_treed_read(r, t, p, p_off) {
8 |
9 | var i = 0;
10 |
11 |
12 | while ((i = t[ i + vpx_read(r, p[p_off + (i >> 1)])]) > 0) {}
13 |
14 |
15 |
16 |
17 | return (-i) | 0;
18 | }
19 |
20 | module.exports = vp8_treed_read;
--------------------------------------------------------------------------------
/vp8/vp8_js_iface.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var VP8D_COMP = require('./decoder/onyxd_int.js');
4 | var onyxd_if = require('./decoder/onyxd_if');
5 | var vp8dx_receive_compressed_data = onyxd_if.vp8dx_receive_compressed_data;
6 |
7 |
8 | class vpx_codec_alg_priv{
9 |
10 | constructor(){
11 |
12 | this.base; //vpx_codec_priv_t
13 | this.cfg;
14 | this.si; //vp8_stream_info_t
15 | this.decoder_init;
16 | this.postproc_cfg_set;
17 | this.postproc_cfg;
18 |
19 | this.decrypt_cb;
20 | this.decrypt_state;
21 | this.img;
22 | this.img_setup;
23 | this.yv12_frame_buffers; //frame_buffers
24 | this.user_priv;
25 | this.fragments; //FRAGMENT_DATA
26 | this.temp_pbi = null;
27 |
28 | }
29 |
30 | }
31 |
32 | function vp8_peek_si(){
33 |
34 | }
35 |
36 | function vp8_get_si(){
37 |
38 | }
39 |
40 | function vp8_decode(ctx, data, data_sz , user_priv , deadline){
41 | var res = 0; //VPX_CODEC_OK
42 | var resolution_change = 0;
43 | var w, h;
44 | //console.warn("decoding!");
45 | /*
46 | * if (!ctx->fragments.enabled && (data == NULL && data_sz == 0)) {
47 | return 0;
48 | }
49 | */
50 |
51 | //if (update_fragments(ctx, data, data_sz, &res) <= 0) return res;
52 |
53 | //w = ctx.si.w;
54 | //h = ctx.si.h;
55 |
56 | //res = vp8_peek_si_internal(ctx->fragments.ptrs[0], ctx->fragments.sizes[0],
57 | // &ctx->si, ctx->decrypt_cb, ctx->decrypt_state);
58 |
59 | // if ((ctx->si.h != h) || (ctx->si.w != w)) resolution_change = 1;
60 |
61 | if (!res && !ctx.decoder_init) {
62 |
63 | }
64 |
65 | //line 399
66 | if (!ctx.temp_pbi) {
67 |
68 | var pbi = new VP8D_COMP();//this goes in frame buffers
69 | ctx.temp_pbi = pbi;
70 | }
71 |
72 | vp8dx_receive_compressed_data(ctx.temp_pbi, data_sz, data, deadline);
73 |
74 | return res;
75 |
76 | }
77 |
78 | function vp8_get_frame(decoder, iter) {
79 | if (decoder.priv.temp_pbi.common.show_frame) {
80 | return decoder.priv.temp_pbi.ref_frames[0].img;
81 | }
82 | return null;
83 | }
84 |
85 | function vp8_init_ctx(ctx) {
86 | var priv = new vpx_codec_alg_priv();
87 | ctx.priv = priv;
88 | ctx.priv.init_flags = ctx.init_flags;
89 | //priv.si.sz = size of (priv.si)
90 | ctx.priv.decrypt_cb = null;
91 | ctx.priv.decrypt_state = null;
92 |
93 | if (ctx.config.dec) {
94 | // Update the reference to the config structure to an internal copy.
95 | priv.cfg = ctx.config.dec;
96 | ctx.config.dec = priv.cfg;
97 | }
98 |
99 | return 0;
100 | }
101 |
102 | function vp8_init(ctx, data) {
103 |
104 | var res; // = VPX_CODEC_OK;
105 | var priv = null;
106 |
107 |
108 | //vp8_rtcd();
109 | // vpx_dsp_rtcd();
110 | //vpx_scale_rtcd();
111 |
112 | if (!ctx.priv) {
113 | vp8_init_ctx(ctx);
114 | priv = ctx.priv;
115 |
116 | //priv.fragments.count = 0;
117 |
118 | //priv->fragments.enabled =
119 | //(priv->base.init_flags & VPX_CODEC_USE_INPUT_FRAGMENTS);
120 | } else {
121 | priv = ctx.priv;
122 | }
123 |
124 | }
125 |
126 | //vpx_codec_iface vpx_codec_internal.h
127 |
128 | var vpx_codec_vp8_js = {
129 | name: "jscodec VP8 Decoder",
130 | abi_version : 0,
131 | caps : null,
132 | destroy : null,
133 | dec: {
134 | peek_si: vp8_peek_si,
135 | get_si: vp8_get_si,
136 | decode: vp8_decode,
137 | get_frame: vp8_get_frame
138 | },
139 | init : vp8_init
140 | };//CODEC_INTERFACE
141 |
142 | module.exports = vpx_codec_vp8_js;
--------------------------------------------------------------------------------
/vpx/vpx_codec.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 |
4 |
5 | class vpx_codec_ctx {
6 |
7 | constructor() {
8 | this.name; //Printable interface name
9 | this.iface; //vpx_codec_iface_t
10 | this.err; //vpx_codec_err_t /**< Last returned error */
11 | this.err_detail; /**< Detailed info, if available */
12 | this.init_flags; // Flags passed at init time //vpx_codec_flags_t
13 | this.config = {
14 | vpx_codec_dec_cfg : null
15 | };
16 |
17 |
18 | this.priv; //vpx_codec_priv_t Algorithm private storage
19 | }
20 |
21 | }
22 |
23 | module.exports = {};
24 | module.exports.vpx_codec_ctx_t = vpx_codec_ctx; //vpx_codec_ctx_t
--------------------------------------------------------------------------------
/vpx/vpx_decoder.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /**
3 | *
4 | * This file provides our highest level interface into the decoders
5 | */
6 |
7 | //possibly move interfaces to vp8dx
8 | var ifaces = [
9 | {
10 | name: "jsvp8",
11 | iface : require('../vp8/vp8_js_iface.js')
12 | }
13 | ];
14 |
15 | var VPX_CODEC_ABI_VERSION = 1;//temp
16 | var VPX_DECODER_ABI_VERSION = VPX_CODEC_ABI_VERSION + 3;
17 |
18 |
19 | function get_alg_priv(ctx) {
20 | return ctx.priv;
21 | }
22 |
23 |
24 | function vpx_codec_dec_init(ctx, iface, cfg, flags){
25 |
26 | return vpx_codec_dec_init_ver(ctx, iface, cfg, flags , VPX_DECODER_ABI_VERSION);
27 |
28 | }
29 |
30 | /**
31 | *
32 | * @param {type} ctx
33 | * @param {vpx_codec_iface_t} iface vpx_codec_vp8_dx_algo
34 | * @param {type} cfg
35 | * @param {type} flags
36 | * @param {type} ver
37 | * @returns {undefined}
38 | */
39 | function vpx_codec_dec_init_ver(ctx, iface, cfg, flags, ver){
40 |
41 | //iface.init()
42 | //console.log("Initializing decoder");
43 | //clear the ctx
44 | ctx.iface = iface;
45 | ctx.name = iface.name;
46 | ctx.priv = null;
47 | ctx.init_flags = flags;
48 | ctx.config.dec = cfg;
49 |
50 |
51 | ctx.iface.init(ctx, null);
52 | }
53 |
54 |
55 | function vpx_codec_peek_stream_info(){
56 |
57 | }
58 |
59 | function vpx_codec_get_stream_info(){
60 |
61 | }
62 |
63 | //line 104
64 | function vpx_codec_decode(ctx, data, data_sz, user_priv, deadline) {
65 | var res = 0;
66 |
67 | //if (!ctx || (!data && data_sz) || (data && !data_sz))
68 | // res = VPX_CODEC_INVALID_PARAM;
69 | //else if (!ctx.iface || !ctx.priv)
70 | // res = VPX_CODEC_ERROR;
71 | //else {
72 | //get_alg_priv(ctx)
73 | res = ctx.iface.dec.decode(get_alg_priv(ctx), data, data_sz, user_priv,
74 | deadline);
75 | //console.log("NOW DECODING");
76 | //}
77 |
78 | //return SAVE_STATUS(ctx, res);
79 | }
80 |
81 | function vpx_codec_get_frame(ctx, iter){
82 | var img;
83 |
84 | img = ctx.iface.dec.get_frame(ctx, iter);
85 |
86 | return img;
87 | }
88 |
89 | function vpx_codec_put_frame_cb_fn_t(){
90 |
91 | }
92 |
93 | function vpx_codec_register_put_frame_cb(){
94 |
95 | }
96 |
97 | function vpx_codec_register_put_slice_cb(){
98 |
99 | }
100 |
101 | module.exports = {
102 | ifaces : ifaces,
103 | vpx_codec_dec_init : vpx_codec_dec_init,
104 | vpx_codec_dec_init_ver : vpx_codec_dec_init_ver,
105 | vpx_codec_peek_stream_info : vpx_codec_peek_stream_info,
106 | vpx_codec_get_stream_info : vpx_codec_get_stream_info,
107 | vpx_codec_decode : vpx_codec_decode,
108 | vpx_codec_get_frame : vpx_codec_get_frame,
109 | vpx_codec_put_frame_cb_fn_t : vpx_codec_put_frame_cb_fn_t,
110 | vpx_codec_register_put_frame_cb : vpx_codec_register_put_frame_cb,
111 | vpx_codec_register_put_slice_cb : vpx_codec_register_put_slice_cb
112 | };
--------------------------------------------------------------------------------
/vpx/vpx_image.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 |
4 | var VPX_IMG_FMT_PLANAR = 0x100;
5 | var VPX_IMG_FMT_UV_FLIP = 0x200;
6 | var VPX_IMG_FMT_HAS_ALPHA = 0x400;
7 |
8 | //Image format codes
9 | var VPX_IMG_FMT_NONE = 0;
10 | var VPX_IMG_FMT_RGB24 = 1;
11 | var VPX_IMG_FMT_RGB32 = 2;
12 | var VPX_IMG_FMT_RGB565 = 3;
13 | var VPX_IMG_FMT_RGB555 = 4;
14 | var VPX_IMG_FMT_UYVY = 5;
15 | var VPX_IMG_FMT_YUY2 = 6;
16 | var VPX_IMG_FMT_YVYU = 7;
17 | var VPX_IMG_FMT_BGR24 = 8;
18 | var VPX_IMG_FMT_RGB32_LE = 9;
19 | var VPX_IMG_FMT_ARGB = 10;
20 | var VPX_IMG_FMT_ARGB_LE = 11;
21 | var VPX_IMG_FMT_RGB565_LE = 12;
22 | var VPX_IMG_FMT_RGB555_LE = 13;
23 | var VPX_IMG_FMT_YV12 = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 1;
24 | var VPX_IMG_FMT_I420 = VPX_IMG_FMT_PLANAR | 2;
25 | var VPX_IMG_FMT_VPXYV12 = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 3;
26 | var VPX_IMG_FMT_VPXI420 = VPX_IMG_FMT_PLANAR | 4;
27 |
28 | var VPX_PLANE_PACKED = 0; /**< To be used for all packed formats */
29 | var VPX_PLANE_Y = 0; /**< Y (Luminance) plane */
30 | var VPX_PLANE_U = 1; /**< U (Chroma) plane */
31 | var VPX_PLANE_V = 2; /**< V (Chroma) plane */
32 | var VPX_PLANE_ALPHA = 3; /**< A (Transparency) plane */
33 | var PLANE_PACKED = VPX_PLANE_PACKED;
34 | var PLANE_Y = VPX_PLANE_Y;
35 | var PLANE_U = VPX_PLANE_U;
36 | var PLANE_V = VPX_PLANE_V;
37 | var PLANE_ALPHA = VPX_PLANE_ALPHA;
38 |
39 |
40 | Uint8ClampedArray.prototype.data_32 = null;
41 | Uint8Array.prototype.data_32 = null;
42 | /**
43 | * typedef struct vpx_image
44 | * vpx_image_t is alias for vpx_image
45 | */
46 | class vpx_image_t {
47 |
48 | constructor() {
49 | this.fmt = 0; //can probably be uint
50 |
51 | /* Image storage dimensions */
52 | this.w = 0; // uint struct0
53 | this.h = 0; // uint struct1
54 |
55 | /* Image display dimensions */
56 | this.d_w = 0; //uint struct2
57 | this.d_h = 0; //uint struct3
58 |
59 | /* Chroma subsampling info */
60 | this.x_chroma_shift = 0; //uint
61 | this.y_chroma_shift = 0; // uint
62 |
63 | //this.planes = [0,0,0,0];//yuva
64 | this.planes_off = new Int32Array(4); // yuva
65 | this.stride = new Int32Array(4);
66 |
67 | this.bps = 0; // int
68 | this.user_priv = 0;
69 |
70 | this.img_data = null;
71 | this.img_data_off = 0; //uint
72 | this.img_data_owner = 0; //int
73 | this.self_allocd = 0; //int
74 |
75 | }
76 | }
77 |
78 |
79 | function vpx_img_set_rect(img, x, y, w, h) {
80 | var data = 0;
81 | var data_off = 0;
82 |
83 | if (x + w <= img.w && y + h <= img.h) {
84 | img.d_w = w;
85 | img.d_h = h;
86 |
87 | /* Calculate plane pointers */
88 | if ((img.fmt & VPX_IMG_FMT_PLANAR) === 0) {
89 | img.img_data_off + (x * img.bps >> 3 + y * img.stride[VPX_PLANE_PACKED]) | 0;
90 | } else {
91 | data = img.img_data;
92 | data_off = img.img_data_off;
93 |
94 | if (img.fmt & VPX_IMG_FMT_HAS_ALPHA) {
95 | img.planes_off[VPX_PLANE_ALPHA] =
96 | data_off + x + y * img.stride[VPX_PLANE_ALPHA];
97 | data_off += img.h * img.stride[VPX_PLANE_ALPHA];
98 | }
99 |
100 |
101 | img.planes_off[VPX_PLANE_Y] = data_off + x + y * img.stride[VPX_PLANE_Y];
102 | data_off += img.h * img.stride[VPX_PLANE_Y];
103 |
104 | if (!(img.fmt & VPX_IMG_FMT_UV_FLIP)) {
105 | img.planes_off[VPX_PLANE_U] = data_off
106 | + (x >> img.x_chroma_shift)
107 | + (y >> img.y_chroma_shift) * img.stride[VPX_PLANE_U];
108 | data_off += (img.h >> img.y_chroma_shift) * img.stride[VPX_PLANE_U];
109 | img.planes_off[VPX_PLANE_V] = data_off
110 | + (x >> img.x_chroma_shift)
111 | + (y >> img.y_chroma_shift) * img.stride[VPX_PLANE_V];
112 | } else {
113 | img.planes_off[VPX_PLANE_V] = data_off
114 | + (x >> img.x_chroma_shift)
115 | + (y >> img.y_chroma_shift) * img.stride[VPX_PLANE_V];
116 | data_off += (img.h >> img.y_chroma_shift) * img.stride[VPX_PLANE_V];
117 | img.planes_off[VPX_PLANE_U] = data_off
118 | + (x >> img.x_chroma_shift)
119 | + (y >> img.y_chroma_shift) * img.stride[VPX_PLANE_U];
120 | }
121 | }
122 |
123 | return 0;
124 | }
125 |
126 | return -1;
127 | }
128 |
129 |
130 | function img_alloc_helper(img, fmt, d_w, d_h, stride_align, img_data) {
131 | var h = 0;
132 | var w = 0;
133 | var s = 0;
134 | var xcs = 0;
135 | var ycs = 0;
136 | var bps = 0;
137 | var align = 0;
138 |
139 | /* Treat align==0 like align==1 */
140 | if (!stride_align)
141 | stride_align = 1;
142 |
143 | /* Validate alignment (must be power of 2) */
144 | if (stride_align & (stride_align - 1))
145 | console.warn('Invalid stride align');
146 |
147 | /* Get sample size for img format */
148 | switch (fmt) {
149 | case VPX_IMG_FMT_RGB32:
150 | case VPX_IMG_FMT_RGB32_LE:
151 | case VPX_IMG_FMT_ARGB:
152 | case VPX_IMG_FMT_ARGB_LE:
153 | bps = 32;
154 | break;
155 | case VPX_IMG_FMT_RGB24:
156 | case VPX_IMG_FMT_BGR24:
157 | bps = 24;
158 | break;
159 | case VPX_IMG_FMT_RGB565:
160 | case VPX_IMG_FMT_RGB565_LE:
161 | case VPX_IMG_FMT_RGB555:
162 | case VPX_IMG_FMT_RGB555_LE:
163 | case VPX_IMG_FMT_UYVY:
164 | case VPX_IMG_FMT_YUY2:
165 | case VPX_IMG_FMT_YVYU:
166 | bps = 16;
167 | break;
168 | case VPX_IMG_FMT_I420:
169 | case VPX_IMG_FMT_YV12:
170 | case VPX_IMG_FMT_VPXI420:
171 | case VPX_IMG_FMT_VPXYV12:
172 | bps = 12;
173 | break;
174 | default:
175 | bps = 16;
176 | break;
177 | }
178 |
179 | /* Get chroma shift values for img format */
180 | switch (fmt) {
181 | case VPX_IMG_FMT_I420:
182 | case VPX_IMG_FMT_YV12:
183 | case VPX_IMG_FMT_VPXI420:
184 | case VPX_IMG_FMT_VPXYV12:
185 | xcs = 1;
186 | break;
187 | default:
188 | xcs = 0;
189 | break;
190 | }
191 |
192 | switch (fmt) {
193 | case VPX_IMG_FMT_I420:
194 | case VPX_IMG_FMT_YV12:
195 | case VPX_IMG_FMT_VPXI420:
196 | case VPX_IMG_FMT_VPXYV12:
197 | ycs = 1;
198 | break;
199 | default:
200 | ycs = 0;
201 | break;
202 | }
203 |
204 | /* Calculate storage sizes given the chroma subsampling */
205 | align = ((1 << xcs) - 1) | 0;
206 | w = ((d_w + align) & ~align) | 0;
207 | align = ((1 << ycs) - 1) | 0;
208 | h = ((d_h + align) & ~align) | 0;
209 | s = ((fmt & VPX_IMG_FMT_PLANAR) ? w : bps * w >> 3) | 0;
210 | s = ((s + stride_align - 1) & ~(stride_align - 1)) | 0;
211 |
212 | /* Allocate the new image */
213 |
214 | //todo: reset
215 |
216 |
217 | img.img_data = img_data;
218 |
219 | if (img_data === null) {
220 |
221 | } else {
222 | var size = 0;
223 | if ((fmt & VPX_IMG_FMT_PLANAR) === 0) {
224 | size = h * s;
225 | } else {
226 |
227 | size = (h * w * bps) >> 3;
228 | }
229 | //img.img_data = new Uint8ClampedArray(size);
230 | img.img_data = new Uint8Array(size);
231 | img.img_data.data_32 = new Uint32Array(img.img_data.buffer);
232 | img.img_data.data_16 = new Uint16Array(img.img_data.buffer);
233 | img.img_data_owner = 1;
234 | }
235 |
236 |
237 | img.fmt = fmt;
238 | img.w = w;
239 | img.h = h;
240 | img.x_chroma_shift = xcs;
241 | img.y_chroma_shift = ycs;
242 | img.bps = bps;
243 |
244 | /* Calculate strides */
245 | img.stride[VPX_PLANE_Y] = img.stride[VPX_PLANE_ALPHA] = s;
246 | img.stride[VPX_PLANE_U] = img.stride[VPX_PLANE_V] = s >> xcs;
247 |
248 | /* Default viewport to entire image */
249 | if (vpx_img_set_rect(img, 0, 0, d_w, d_h) === 0)
250 | return img;
251 |
252 | }
253 |
254 |
255 | module.exports = {};
256 | module.exports.vpx_img_set_rect = vpx_img_set_rect;
257 | module.exports.img_alloc_helper = img_alloc_helper;
258 | module.exports.vpx_image_t = vpx_image_t;
--------------------------------------------------------------------------------
/vpx_dsp/bitreader.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 |
4 | /**
5 | * vp8dx_decode_bool
6 | * bool_get
7 | * @param {type} prob
8 | * @returns {Number}
9 | * vpx_read(vpx_reader *r, int prob)
10 | */
11 | function vpx_read(r, prob) {
12 |
13 | var split = 1 + (((r.range - 1) * prob) >> 8);
14 | var SPLIT = split << 8;
15 | var retval = 0;
16 |
17 | if (r.value >= SPLIT) {
18 | retval = 1;
19 | r.range -= split;
20 | r.value -= SPLIT;
21 | } else {
22 | retval = 0;
23 | r.range = split;
24 | }
25 |
26 | while (r.range < 128) {
27 | r.value <<= 1;
28 | r.range <<= 1;
29 | if (++r.bit_count === 8) {
30 | r.bit_count = 0;
31 | if (r.input_len) {
32 | r.value |= r.input[r.ptr++];
33 | r.input_len--;
34 | }
35 | }
36 | }
37 | return retval;
38 | }
39 |
40 |
41 | function vpx_read_bit(r) {
42 |
43 | return vpx_read(r, 128);
44 |
45 | }
46 |
47 | function vpx_read_literal(r, bits) {
48 | var z = 0;
49 | var bit = 0;
50 |
51 | for (bit = bits - 1; bit >= 0; bit--) {
52 | z |= (vpx_read_bit(r) << bit);
53 | }
54 |
55 | return z;
56 | }
57 |
58 | module.exports = {};
59 | module.exports.vpx_read_bit = vpx_read_bit;
60 | module.exports.vpx_read = vpx_read;
61 | module.exports.vpx_read_literal = vpx_read_literal;
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | const ClosureCompilerPlugin = require('webpack-closure-compiler');
2 | const path = require('path');
3 |
4 | var BrowserTests = {
5 | entry: [
6 | path.join(__dirname, 'test', 'browser-tests.js')
7 | ],
8 | output: {
9 | path: path.join(__dirname, 'test'),
10 | filename: 'browser-tests.build.js'
11 | }
12 | };
13 |
14 | var OGVVideoDecoder = {
15 | entry: [
16 | path.join(__dirname, 'build-templates', 'OGVVideoDecoder.js')
17 | ],
18 | output: {
19 | path: path.join(__dirname, 'builds'),
20 | filename: 'ogv-decoder-video-vp8.js'
21 | },
22 |
23 | plugins: [
24 |
25 | new ClosureCompilerPlugin({
26 | compiler: {
27 | compilation_level: 'SIMPLE'
28 | },
29 | concurrency: 3,
30 | })
31 |
32 | ]
33 |
34 | };
35 |
36 | var JsVpx = {
37 | mode: 'production',
38 | entry: [
39 | path.join(__dirname, 'build-templates', 'jsvpx.js')
40 | ],
41 | output: {
42 | path: path.join(__dirname, 'builds'),
43 | filename: 'jsvpx.js',
44 | library: 'JsVpx',
45 | libraryTarget: 'commonjs2',
46 | },
47 | plugins: [
48 | new ClosureCompilerPlugin({
49 | compiler: {
50 | compilation_level: 'SIMPLE'
51 | },
52 | concurrency: 3,
53 | })
54 | ]
55 | };
56 |
57 | var JsVpxBenchmark = {
58 | entry: [
59 | path.join(__dirname, 'benchmarks', 'benchmark.js')
60 | ],
61 | output: {
62 | path: path.join(__dirname, 'benchmarks'),
63 | filename: 'benchmark.build.js'
64 | },
65 | module: {
66 | noParse: [
67 | path.resolve(__dirname, './node_modules/benchmark/benchmark.js'),
68 | ]
69 | },
70 | };
71 |
72 |
73 | if (process.env) {
74 | if (process.env.USE_BENCHMARK === "true") {
75 | module.exports = [JsVpxBenchmark];
76 | } else {
77 | module.exports = [OGVVideoDecoder, JsVpx, BrowserTests];
78 | }
79 | }
--------------------------------------------------------------------------------