Skip to content

Commit

Permalink
support for webassembly
Browse files Browse the repository at this point in the history
  • Loading branch information
soliton4 committed Jun 25, 2018
1 parent 2b350d0 commit d32f9de
Show file tree
Hide file tree
Showing 38 changed files with 332 additions and 253 deletions.
Binary file modified Decoder/avc.bc
Binary file not shown.
17 changes: 1 addition & 16 deletions Decoder/js/avc.js

Large diffs are not rendered by default.

Binary file removed Decoder/js/avc.js.mem
Binary file not shown.
Binary file added Decoder/js/avc.wasm
Binary file not shown.
5 changes: 4 additions & 1 deletion Decoder/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#'-m32',
'-O3',
#'-Dxxx2yyy'
'--memory-init-file', '0',
'--memory-init-file', '1',
'--llvm-opts', '3',
'--llvm-lto', '3',
'-s', 'NO_EXIT_RUNTIME=1',
Expand Down Expand Up @@ -109,3 +109,6 @@
f3 = open(os.path.join("..", "templates", 'DecoderPost.js'));
f.write(f3.read());

asmfile = open(os.path.join('..','Player','avc.wasm'), "w")
amsfilein = open(os.path.join(JS_DIR, 'avc.wasm'));
asmfile.write(amsfilein.read());
Binary file modified Decoder/obj/Decoder.o
Binary file not shown.
Binary file modified Decoder/obj/H264SwDecApi.o
Binary file not shown.
Binary file modified Decoder/obj/extraFlags.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_byte_stream.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_cavlc.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_conceal.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_deblocking.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_decoder.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_dpb.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_image.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_inter_prediction.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_intra_prediction.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_macroblock_layer.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_nal_unit.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_neighbour.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_pic_order_cnt.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_pic_param_set.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_reconstruct.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_seq_param_set.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_slice_data.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_slice_group_map.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_slice_header.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_storage.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_stream.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_transform.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_util.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_vlc.o
Binary file not shown.
Binary file modified Decoder/obj/h264bsd_vui.o
Binary file not shown.
2 changes: 2 additions & 0 deletions Decoder/src/Decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void broadwayPlayStream(u32 length) {


u32 broadwayInit() {

H264SwDecRet ret;
#ifdef DISABLE_OUTPUT_REORDERING
u32 disableOutputReordering = 1;
Expand All @@ -87,6 +88,7 @@ u32 broadwayInit() {
}

picDecodeNumber = picDisplayNumber = 1;

return 0;
}

Expand Down
289 changes: 163 additions & 126 deletions Player/Decoder.js

Large diffs are not rendered by default.

Binary file added Player/avc.wasm
Binary file not shown.
267 changes: 158 additions & 109 deletions templates/DecoderPost.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
return Module;
})();
// return Module;
//})();

var resultModule = global.Module || Module;
var resultModule;
if (typeof global !== "undefined"){
if (global.Module){
resultModule = global.Module;
};
};
if (typeof Module != "undefined"){
resultModule = Module;
};

resultModule._broadwayOnHeadersDecoded = par_broadwayOnHeadersDecoded;
resultModule._broadwayOnPictureDecoded = par_broadwayOnPictureDecoded;

return resultModule;
var moduleIsReady = false;
var cbFun;
var moduleReady = function(){
moduleIsReady = true;
if (cbFun){
cbFun(resultModule);
}
};

resultModule.onRuntimeInitialized = function(){
moduleReady(resultModule);
};
return function(callback){
if (moduleIsReady){
callback(resultModule);
}else{
cbFun = callback;
};
};
};

return (function(){
Expand Down Expand Up @@ -36,6 +62,9 @@
var fakeWindow = {
};

var toU8Array;
var toU32Array;

var onPicFun = function ($buffer, width, height) {
var buffer = this.pictureBuffers[$buffer];
if (!buffer) {
Expand Down Expand Up @@ -116,138 +145,158 @@
}.bind(this);
};

var Module = getModule.apply(fakeWindow, [function () {
var ModuleCallback = getModule.apply(fakeWindow, [function () {
}, onPicFun]);


var HEAP8 = Module.HEAP8;
var HEAPU8 = Module.HEAPU8;
var HEAP16 = Module.HEAP16;
var HEAP32 = Module.HEAP32;


var MAX_STREAM_BUFFER_LENGTH = 1024 * 1024;

// from old constructor
Module._broadwayInit();

/**
* Creates a typed array from a HEAP8 pointer.
*/
function toU8Array(ptr, length) {
return HEAPU8.subarray(ptr, ptr + length);
};
function toU32Array(ptr, length) {
//var tmp = HEAPU8.subarray(ptr, ptr + (length * 4));
return new Uint32Array(HEAPU8.buffer, ptr, length);
var instance = this;
this.onPictureDecoded = function (buffer, width, height, infos) {

};
this.streamBuffer = toU8Array(Module._broadwayCreateStream(MAX_STREAM_BUFFER_LENGTH), MAX_STREAM_BUFFER_LENGTH);
this.pictureBuffers = {};
// collect extra infos that are provided with the nal units
this.infoAr = [];

this.onPictureDecoded = function (buffer, width, height, infos) {

this.onDecoderReady = function(){};

var bufferedCalls = [];
this.decode = function decode(typedAr, parInfo, copyDoneFun) {
bufferedCalls.push([typedAr, parInfo, copyDoneFun]);
};

/**
ModuleCallback(function(Module){
var HEAP8 = Module.HEAP8;
var HEAPU8 = Module.HEAPU8;
var HEAP16 = Module.HEAP16;
var HEAP32 = Module.HEAP32;
// from old constructor
Module._broadwayInit();

/**
* Creates a typed array from a HEAP8 pointer.
*/
toU8Array = function(ptr, length) {
return HEAPU8.subarray(ptr, ptr + length);
};
toU32Array = function(ptr, length) {
//var tmp = HEAPU8.subarray(ptr, ptr + (length * 4));
return new Uint32Array(HEAPU8.buffer, ptr, length);
};
instance.streamBuffer = toU8Array(Module._broadwayCreateStream(MAX_STREAM_BUFFER_LENGTH), MAX_STREAM_BUFFER_LENGTH);
instance.pictureBuffers = {};
// collect extra infos that are provided with the nal units
instance.infoAr = [];

/**
* Decodes a stream buffer. This may be one single (unframed) NAL unit without the
* start code, or a sequence of NAL units with framing start code prefixes. This
* function overwrites stream buffer allocated by the codec with the supplied buffer.
*/

var sliceNum = 0;
if (this.options.sliceMode){
sliceNum = this.options.sliceNum;

this.decode = function decode(typedAr, parInfo, copyDoneFun) {
this.infoAr.push(parInfo);
parInfo.startDecoding = nowValue();
var nals = parInfo.nals;
var i;
if (!nals){
nals = [];
parInfo.nals = nals;
var l = typedAr.length;
var foundSomething = false;
var lastFound = 0;
var lastStart = 0;
for (i = 0; i < l; ++i){
if (typedAr[i] === 1){
if (
typedAr[i - 1] === 0 &&
typedAr[i - 2] === 0
){
var startPos = i - 2;
if (typedAr[i - 3] === 0){
startPos = i - 3;
};
// its a nal;
if (foundSomething){
nals.push({
offset: lastFound,
end: startPos,
type: typedAr[lastStart] & 31
});
};
lastFound = startPos;
lastStart = startPos + 3;
if (typedAr[i - 3] === 0){
lastStart = startPos + 4;

var sliceNum = 0;
if (instance.options.sliceMode){
sliceNum = instance.options.sliceNum;

instance.decode = function decode(typedAr, parInfo, copyDoneFun) {
instance.infoAr.push(parInfo);
parInfo.startDecoding = nowValue();
var nals = parInfo.nals;
var i;
if (!nals){
nals = [];
parInfo.nals = nals;
var l = typedAr.length;
var foundSomething = false;
var lastFound = 0;
var lastStart = 0;
for (i = 0; i < l; ++i){
if (typedAr[i] === 1){
if (
typedAr[i - 1] === 0 &&
typedAr[i - 2] === 0
){
var startPos = i - 2;
if (typedAr[i - 3] === 0){
startPos = i - 3;
};
// its a nal;
if (foundSomething){
nals.push({
offset: lastFound,
end: startPos,
type: typedAr[lastStart] & 31
});
};
lastFound = startPos;
lastStart = startPos + 3;
if (typedAr[i - 3] === 0){
lastStart = startPos + 4;
};
foundSomething = true;
};
foundSomething = true;
};
};
if (foundSomething){
nals.push({
offset: lastFound,
end: i,
type: typedAr[lastStart] & 31
});
};
};
if (foundSomething){
nals.push({
offset: lastFound,
end: i,
type: typedAr[lastStart] & 31
});
};
};

var currentSlice = 0;
var playAr;
var offset = 0;
for (i = 0; i < nals.length; ++i){
if (nals[i].type === 1 || nals[i].type === 5){
if (currentSlice === sliceNum){

var currentSlice = 0;
var playAr;
var offset = 0;
for (i = 0; i < nals.length; ++i){
if (nals[i].type === 1 || nals[i].type === 5){
if (currentSlice === sliceNum){
playAr = typedAr.subarray(nals[i].offset, nals[i].end);
instance.streamBuffer[offset] = 0;
offset += 1;
instance.streamBuffer.set(playAr, offset);
offset += playAr.length;
};
currentSlice += 1;
}else{
playAr = typedAr.subarray(nals[i].offset, nals[i].end);
this.streamBuffer[offset] = 0;
instance.streamBuffer[offset] = 0;
offset += 1;
this.streamBuffer.set(playAr, offset);
instance.streamBuffer.set(playAr, offset);
offset += playAr.length;
Module._broadwayPlayStream(offset);
offset = 0;
};
currentSlice += 1;
}else{
playAr = typedAr.subarray(nals[i].offset, nals[i].end);
this.streamBuffer[offset] = 0;
offset += 1;
this.streamBuffer.set(playAr, offset);
offset += playAr.length;
Module._broadwayPlayStream(offset);
offset = 0;
};
copyDoneFun();
Module._broadwayPlayStream(offset);
};

}else{
instance.decode = function decode(typedAr, parInfo) {
// console.info("Decoding: " + buffer.length);
// collect infos
if (parInfo){
instance.infoAr.push(parInfo);
parInfo.startDecoding = nowValue();
};

instance.streamBuffer.set(typedAr);
Module._broadwayPlayStream(typedAr.length);
};
copyDoneFun();
Module._broadwayPlayStream(offset);
};

}else{
this.decode = function decode(typedAr, parInfo) {
// console.info("Decoding: " + buffer.length);
// collect infos
if (parInfo){
this.infoAr.push(parInfo);
parInfo.startDecoding = nowValue();
if (bufferedCalls.length){
var bi = 0;
for (bi = 0; bi < bufferedCalls.length; ++bi){
instance.decode(bufferedCalls[bi][0], bufferedCalls[bi][1], bufferedCalls[bi][2]);
};

this.streamBuffer.set(typedAr);
Module._broadwayPlayStream(typedAr.length);
bufferedCalls = [];
};
};

instance.onDecoderReady(instance);

});


};

Expand Down
5 changes: 4 additions & 1 deletion templates/DecoderPre.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
};




var getModule = function(par_broadwayOnHeadersDecoded, par_broadwayOnPictureDecoded){


Expand All @@ -58,5 +60,6 @@
*/

var Module = (function(){
//var Module = (function(){


0 comments on commit d32f9de

Please sign in to comment.