diff --git a/Makefile b/Makefile index 49c78d8..811b110 100644 --- a/Makefile +++ b/Makefile @@ -28,12 +28,6 @@ main: $(PLUGINSDEP) $(PLUGINS) #lib -ln -s $(PBUILDIRD)/libantd.$(EXT) . $(CC) $(PCFLAGS) $(PLUGINSDEP) $(PLUGINLIBS) -shared -o $(PBUILDIRD)/$(basename $@).$(EXT) -web: - emcc -o $(WEB_BUILD_PATH)/wvnc_asm.js -I wasm/libjpeg/ -I wasm/zlib wasm/decoder.c \ - wasm/libjpeg/.libs/libjpeg.a wasm/zlib/libz.a \ - -O3 -s ALLOW_MEMORY_GROWTH=1 -s WASM=1 -s NO_EXIT_RUNTIME=1 -s \ - 'EXTRA_EXPORTED_RUNTIME_METHODS=["cwrap"]' - clean: #libclean -rm -f *.o *.$(EXT) $(PBUILDIRD)/$(PLUGINS) diff --git a/test/Makefile b/test/Makefile index 9580cfb..c915346 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,6 +1,6 @@ LDFLAGS="-L/usr/local/opt/jpeg-turbo/lib" CPPFLAGS="-I/usr/local/opt/jpeg-turbo/include" -main: miniviewer +main: gcc viewer.c -D_REENTRANT $(CPPFLAGS) -I/usr/include/SDL2 $(LDFLAGS) -lSDL2 -lvncclient -o viewer miniviewer: diff --git a/test/viewer b/test/viewer index 3d1db1d..244b3b1 100755 Binary files a/test/viewer and b/test/viewer differ diff --git a/test/viewer.c b/test/viewer.c index 8d280af..9228427 100644 --- a/test/viewer.c +++ b/test/viewer.c @@ -2,7 +2,7 @@ * @example SDLvncviewer.c */ -#include +#include #include #include diff --git a/wasm/decoder.c b/wasm/decoder.c deleted file mode 100644 index 9cf3407..0000000 --- a/wasm/decoder.c +++ /dev/null @@ -1,212 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "emscripten.h" -/* -* This file is the decoder for the wvnc data -* received on the client side, it will be complied -* to web assembly to be used on the browser -*/ - -typedef struct{ - uint8_t r; - uint8_t g; - uint8_t b; -} raw_pixel_t; -EMSCRIPTEN_KEEPALIVE -uint8_t* create_buffer(int size) { - return malloc(size); -} -/*destroy buffer*/ -EMSCRIPTEN_KEEPALIVE -void destroy_buffer(uint8_t* p) { - free(p); -} -int decode_zlib(uint8_t* in,int size_in, uint8_t* out, int size_out) -{ - z_stream dstream; - dstream.zalloc = Z_NULL; - dstream.zfree = Z_NULL; - dstream.opaque = Z_NULL; - dstream.next_in = in; - dstream.avail_in = size_in; - dstream.avail_out = size_out; - dstream.next_out = out; - inflateInit(&dstream); - inflate(&dstream, Z_FINISH); - inflateEnd(&dstream); - return dstream.total_out; -} - - -int decode_jpeg(uint8_t* in,int size_in, uint8_t* out) -{ - struct jpeg_decompress_struct cinfo = {0}; - struct jpeg_error_mgr jerror = {0}; - cinfo.err = jpeg_std_error(&jerror); - jpeg_create_decompress(&cinfo); - jpeg_mem_src(&cinfo, in, size_in); - // check if the jpeg is valid - int rc = jpeg_read_header(&cinfo, TRUE); - if (rc != 1) { - printf("Cannot read JPEG header"); - return 0; - } - //cinfo.out_color_space = JCS_RGB; - //cinfo.dct_method = JDCT_ISLOW; - jpeg_start_decompress(&cinfo); - int width = cinfo.output_width; - int height = cinfo.output_height; - int osize = width*height*3; - int row_stride = width * 3; - //printf("width %d, height %d %d\n", width, height, cinfo.output_components); - uint8_t * tmp = (uint8_t*) malloc(osize); - uint8_t * line_buffer[1]; - int index; - while( cinfo.output_scanline < height ){ - line_buffer[0] = tmp +(cinfo.output_scanline) * row_stride; - jpeg_read_scanlines(&cinfo, line_buffer, 1); - } - jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - for(int j = 0; j < height; j++) - { - for(int i = 0; i < width; i++) - { - index = j*width*4 + i*4; - memcpy(out + index, tmp + j*width*3 + i*3, 3); - *(out + index + 3) = 255; - } - } - //copy - //memcpy(out, tmp, osize); - //free - free(tmp); - return osize; -} - - -int decode_raw(uint8_t* in,int size, int depth, uint8_t* out) -{ - if(depth != 24 && depth != 16) - { - printf("Depth % d is not supported\n", depth); - return 0; - } - int components = depth/8; - int npixels = size / components; - int outsize = npixels*4; - unsigned int value = 0; - uint8_t* tmp = (uint8_t*) malloc(outsize); - raw_pixel_t px; - for(int i = 0; i < npixels; i++) - { - value = 0; - for(int j=0; j < components; j++ ) - value = (in[i * components + j] << (j*8)) | value ; - // lookup for pixel - - switch (depth) - { - case 24: - px.r = value & 0xFF; - px.g = (value >> 8) & 0xFF; - px.b = (value >> 16) & 0xFF; - break; - case 16: - px.r = (value & 0x1F) * (255 / 31); - px.g = ((value >> 5) & 0x3F) * (255 / 63); - px.b = ((value >> 11) & 0x1F) * (255 / 31); - break; - default: - break; - } - tmp[i*4] = px.r; - tmp[i*4+1] = px.g; - tmp[i*4+2] = px.b; - tmp[i*4+3] = 255; - } - memcpy(out, tmp, outsize); - free(tmp); - return outsize; -} - -void update_buffer(uint8_t* fb, uint8_t* data, int x, int y, int w, int h, int bw) -{ - //printf("update buffer\n"); - //copy line by line - uint8_t *src_ptr, *dest_ptr; - for(int j = 0; j < h; j++) - { - src_ptr = data + (j*w*4); - dest_ptr = fb + ((j+y)*bw*4 + x*4); - memcpy(dest_ptr, src_ptr, w*4); - } -} - -EMSCRIPTEN_KEEPALIVE -uint8_t* decode(uint8_t* data, int data_size, int depth, int size_out) -{ - uint8_t flag = data[9]; - //printf("x %d y %d w %d h %d flag %d\n",x,y,w,h,flag); - uint8_t* encoded_data = data + 10; - uint8_t* decoded_data = NULL; - int ret = 0; - if(flag == 0x0 && depth == 32) - { - return encoded_data; - } - else - { - decoded_data = (uint8_t*) malloc(size_out); - switch (flag) - { - case 0x0: // raw 24 or 16 bits - ret = decode_raw(encoded_data,data_size,depth, decoded_data); - break; - case 0x1: // jpeg data - ret = decode_jpeg(encoded_data, data_size, decoded_data); - break; - case 0x2: // zlib data - ret = decode_zlib(encoded_data, data_size, decoded_data, size_out); - if(ret > 0 && depth != 32) - ret = decode_raw(decoded_data,ret,depth, decoded_data); - break; - case 0x3: // jpeg and zlib data - ret = decode_zlib(encoded_data, data_size, decoded_data, size_out); - if(ret > 0) - ret = decode_jpeg(decoded_data, ret, decoded_data); - break; - default: - if(decoded_data) free(decoded_data); - return NULL; - } - // write decoded data to buffer - return decoded_data; - } -} - -/*decode the data format*/ -EMSCRIPTEN_KEEPALIVE -int update(uint8_t* fb, uint8_t* data, int data_size, int bw, int bh, int depth) -{ - int x,y,w,h; - uint8_t flag; - // data [0] is commad - x = data[1] | (data[2] << 8); - y = data[3] | (data[4] << 8); - w = data[5] | (data[6] << 8); - h = data[7] | (data[8] << 8); - flag = data[9]; - uint8_t* decoded_data = decode(data, data_size, depth, w*h*4); - if(decoded_data) - update_buffer(fb,decoded_data,x,y,w,h,bw); - if(flag != 0x0 || depth != 32) free(decoded_data); - else - printf("Cannot decode data\n"); - return 1; - -} diff --git a/wasm/dep.sh b/wasm/dep.sh deleted file mode 100755 index 073e49a..0000000 --- a/wasm/dep.sh +++ /dev/null @@ -1,39 +0,0 @@ -#! /bin/bash -# Make sure the emsdk is installed and worked -echo "Preparing libjpeg..." -if [ -d "libjpeg" ]; then - rm -r libjpeg -fi -if [ -d "zlib" ]; then - rm -r zlib -fi -wget http://www.ijg.org/files/jpegsrc.v9c.tar.gz -mkdir libjpeg -tar xvzf jpegsrc.v9c.tar.gz -C ./libjpeg --strip-components=1 -rm jpegsrc.v9c.tar.gz -cd libjpeg -emconfigure ./configure -emmake make -## Using libjpeg-turbo -#git clone https://github.com/libjpeg-turbo/libjpeg-turbo -#mv libjpeg-turbo libjpeg -#cd libjpeg -#mkdir build -#cd build -#emcmake cmake ../ -#emmake make -cd ../ -echo "Preparinf Zlib..." -wget https://zlib.net/zlib-1.2.11.tar.gz -mkdir zlib -tar xvzf zlib-1.2.11.tar.gz -C ./zlib --strip-components=1 -rm zlib-1.2.11.tar.gz -cd zlib -emconfigure ./configure -os=`uname -s` -if [ "$os" = "Darwin" ]; then - sed -i -e 's/AR=libtool/AR=emar/g' Makefile - sed -i -e 's/ARFLAGS=-o/ARFLAGS=rc/g' Makefile -fi -# TODO modify make file using sed if macos -emmake make \ No newline at end of file diff --git a/wasm/wvnc_asm.js b/wasm/wvnc_asm.js deleted file mode 100644 index d6111bf..0000000 --- a/wasm/wvnc_asm.js +++ /dev/null @@ -1,4 +0,0 @@ -var Module=typeof Module!=="undefined"?Module:{};var moduleOverrides={};var key;for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}Module["arguments"]=[];Module["thisProgram"]="./this.program";Module["quit"]=(function(status,toThrow){throw toThrow});Module["preRun"]=[];Module["postRun"]=[];var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_IS_SHELL=false;ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}else{return scriptDirectory+path}}if(ENVIRONMENT_IS_NODE){scriptDirectory=__dirname+"/";var nodeFS;var nodePath;Module["read"]=function shell_read(filename,binary){var ret;if(!nodeFS)nodeFS=require("fs");if(!nodePath)nodePath=require("path");filename=nodePath["normalize"](filename);ret=nodeFS["readFileSync"](filename);return binary?ret:ret.toString()};Module["readBinary"]=function readBinary(filename){var ret=Module["read"](filename,true);if(!ret.buffer){ret=new Uint8Array(ret)}assert(ret.buffer);return ret};if(process["argv"].length>1){Module["thisProgram"]=process["argv"][1].replace(/\\/g,"/")}Module["arguments"]=process["argv"].slice(2);if(typeof module!=="undefined"){module["exports"]=Module}process["on"]("uncaughtException",(function(ex){if(!(ex instanceof ExitStatus)){throw ex}}));process["on"]("unhandledRejection",(function(reason,p){process["exit"](1)}));Module["quit"]=(function(status){process["exit"](status)});Module["inspect"]=(function(){return"[Emscripten Module object]"})}else if(ENVIRONMENT_IS_SHELL){if(typeof read!="undefined"){Module["read"]=function shell_read(f){return read(f)}}Module["readBinary"]=function readBinary(f){var data;if(typeof readbuffer==="function"){return new Uint8Array(readbuffer(f))}data=read(f,"binary");assert(typeof data==="object");return data};if(typeof scriptArgs!="undefined"){Module["arguments"]=scriptArgs}else if(typeof arguments!="undefined"){Module["arguments"]=arguments}if(typeof quit==="function"){Module["quit"]=(function(status){quit(status)})}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WEB){if(document.currentScript){scriptDirectory=document.currentScript.src}}else{scriptDirectory=self.location.href}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.lastIndexOf("/")+1)}else{scriptDirectory=""}Module["read"]=function shell_read(url){var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};if(ENVIRONMENT_IS_WORKER){Module["readBinary"]=function readBinary(url){var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}Module["readAsync"]=function readAsync(url,onload,onerror){var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=function xhr_onload(){if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}onerror()};xhr.onerror=onerror;xhr.send(null)};Module["setWindowTitle"]=(function(title){document.title=title})}else{}var out=Module["print"]||(typeof console!=="undefined"?console.log.bind(console):typeof print!=="undefined"?print:null);var err=Module["printErr"]||(typeof printErr!=="undefined"?printErr:typeof console!=="undefined"&&console.warn.bind(console)||out);for(key in moduleOverrides){if(moduleOverrides.hasOwnProperty(key)){Module[key]=moduleOverrides[key]}}moduleOverrides=undefined;var STACK_ALIGN=16;function staticAlloc(size){var ret=STATICTOP;STATICTOP=STATICTOP+size+15&-16;return ret}function dynamicAlloc(size){var ret=HEAP32[DYNAMICTOP_PTR>>2];var end=ret+size+15&-16;HEAP32[DYNAMICTOP_PTR>>2]=end;if(end>=TOTAL_MEMORY){var success=enlargeMemory();if(!success){HEAP32[DYNAMICTOP_PTR>>2]=ret;return 0}}return ret}function alignMemory(size,factor){if(!factor)factor=STACK_ALIGN;var ret=size=Math.ceil(size/factor)*factor;return ret}var asm2wasmImports={"f64-rem":(function(x,y){return x%y}),"debugger":(function(){debugger})};var functionPointers=new Array(0);var GLOBAL_BASE=1024;var ABORT=false;var EXITSTATUS=0;function assert(condition,text){if(!condition){abort("Assertion failed: "+text)}}function getCFunc(ident){var func=Module["_"+ident];assert(func,"Cannot call unknown function "+ident+", make sure it is exported");return func}var JSfuncs={"stackSave":(function(){stackSave()}),"stackRestore":(function(){stackRestore()}),"arrayToC":(function(arr){var ret=stackAlloc(arr.length);writeArrayToMemory(arr,ret);return ret}),"stringToC":(function(str){var ret=0;if(str!==null&&str!==undefined&&str!==0){var len=(str.length<<2)+1;ret=stackAlloc(len);stringToUTF8(str,ret,len)}return ret})};var toC={"string":JSfuncs["stringToC"],"array":JSfuncs["arrayToC"]};function ccall(ident,returnType,argTypes,args,opts){function convertReturnValue(ret){if(returnType==="string")return Pointer_stringify(ret);if(returnType==="boolean")return Boolean(ret);return ret}var func=getCFunc(ident);var cArgs=[];var stack=0;if(args){for(var i=0;i>0];hasUtf|=t;if(t==0&&!length)break;i++;if(length&&i==length)break}if(!length)length=i;var ret="";if(hasUtf<128){var MAX_CHUNK=1024;var curr;while(length>0){curr=String.fromCharCode.apply(String,HEAPU8.subarray(ptr,ptr+Math.min(length,MAX_CHUNK)));ret=ret?ret+curr:curr;ptr+=MAX_CHUNK;length-=MAX_CHUNK}return ret}return UTF8ToString(ptr)}var UTF8Decoder=typeof TextDecoder!=="undefined"?new TextDecoder("utf8"):undefined;function UTF8ArrayToString(u8Array,idx){var endPtr=idx;while(u8Array[endPtr])++endPtr;if(endPtr-idx>16&&u8Array.subarray&&UTF8Decoder){return UTF8Decoder.decode(u8Array.subarray(idx,endPtr))}else{var u0,u1,u2,u3,u4,u5;var str="";while(1){u0=u8Array[idx++];if(!u0)return str;if(!(u0&128)){str+=String.fromCharCode(u0);continue}u1=u8Array[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}u2=u8Array[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u3=u8Array[idx++]&63;if((u0&248)==240){u0=(u0&7)<<18|u1<<12|u2<<6|u3}else{u4=u8Array[idx++]&63;if((u0&252)==248){u0=(u0&3)<<24|u1<<18|u2<<12|u3<<6|u4}else{u5=u8Array[idx++]&63;u0=(u0&1)<<30|u1<<24|u2<<18|u3<<12|u4<<6|u5}}}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}}}function UTF8ToString(ptr){return UTF8ArrayToString(HEAPU8,ptr)}function stringToUTF8Array(str,outU8Array,outIdx,maxBytesToWrite){if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;outU8Array[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;outU8Array[outIdx++]=192|u>>6;outU8Array[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;outU8Array[outIdx++]=224|u>>12;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}else if(u<=2097151){if(outIdx+3>=endIdx)break;outU8Array[outIdx++]=240|u>>18;outU8Array[outIdx++]=128|u>>12&63;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}else if(u<=67108863){if(outIdx+4>=endIdx)break;outU8Array[outIdx++]=248|u>>24;outU8Array[outIdx++]=128|u>>18&63;outU8Array[outIdx++]=128|u>>12&63;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}else{if(outIdx+5>=endIdx)break;outU8Array[outIdx++]=252|u>>30;outU8Array[outIdx++]=128|u>>24&63;outU8Array[outIdx++]=128|u>>18&63;outU8Array[outIdx++]=128|u>>12&63;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}}outU8Array[outIdx]=0;return outIdx-startIdx}function stringToUTF8(str,outPtr,maxBytesToWrite){return stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite)}function lengthBytesUTF8(str){var len=0;for(var i=0;i=55296&&u<=57343)u=65536+((u&1023)<<10)|str.charCodeAt(++i)&1023;if(u<=127){++len}else if(u<=2047){len+=2}else if(u<=65535){len+=3}else if(u<=2097151){len+=4}else if(u<=67108863){len+=5}else{len+=6}}return len}var UTF16Decoder=typeof TextDecoder!=="undefined"?new TextDecoder("utf-16le"):undefined;function allocateUTF8(str){var size=lengthBytesUTF8(str)+1;var ret=_malloc(size);if(ret)stringToUTF8Array(str,HEAP8,ret,size);return ret}var WASM_PAGE_SIZE=65536;var ASMJS_PAGE_SIZE=16777216;function alignUp(x,multiple){if(x%multiple>0){x+=multiple-x%multiple}return x}var buffer,HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateGlobalBuffer(buf){Module["buffer"]=buffer=buf}function updateGlobalBufferViews(){Module["HEAP8"]=HEAP8=new Int8Array(buffer);Module["HEAP16"]=HEAP16=new Int16Array(buffer);Module["HEAP32"]=HEAP32=new Int32Array(buffer);Module["HEAPU8"]=HEAPU8=new Uint8Array(buffer);Module["HEAPU16"]=HEAPU16=new Uint16Array(buffer);Module["HEAPU32"]=HEAPU32=new Uint32Array(buffer);Module["HEAPF32"]=HEAPF32=new Float32Array(buffer);Module["HEAPF64"]=HEAPF64=new Float64Array(buffer)}var STATIC_BASE,STATICTOP,staticSealed;var STACK_BASE,STACKTOP,STACK_MAX;var DYNAMIC_BASE,DYNAMICTOP_PTR;STATIC_BASE=STATICTOP=STACK_BASE=STACKTOP=STACK_MAX=DYNAMIC_BASE=DYNAMICTOP_PTR=0;staticSealed=false;function abortOnCannotGrowMemory(){abort("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+TOTAL_MEMORY+", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")}function enlargeMemory(){abortOnCannotGrowMemory()}var TOTAL_STACK=Module["TOTAL_STACK"]||5242880;var TOTAL_MEMORY=Module["TOTAL_MEMORY"]||16777216;if(TOTAL_MEMORY0){var callback=callbacks.shift();if(typeof callback=="function"){callback();continue}var func=callback.func;if(typeof func==="number"){if(callback.arg===undefined){Module["dynCall_v"](func)}else{Module["dynCall_vi"](func,callback.arg)}}else{func(callback.arg===undefined?null:callback.arg)}}}var __ATPRERUN__=[];var __ATINIT__=[];var __ATMAIN__=[];var __ATEXIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;var runtimeExited=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function ensureInitRuntime(){if(runtimeInitialized)return;runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function preMain(){callRuntimeCallbacks(__ATMAIN__)}function exitRuntime(){callRuntimeCallbacks(__ATEXIT__);runtimeExited=true}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}function writeArrayToMemory(array,buffer){HEAP8.set(array,buffer)}function writeAsciiToMemory(str,buffer,dontAddNull){for(var i=0;i>0]=str.charCodeAt(i)}if(!dontAddNull)HEAP8[buffer>>0]=0}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}}function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}Module["preloadedImages"]={};Module["preloadedAudios"]={};var dataURIPrefix="data:application/octet-stream;base64,";function isDataURI(filename){return String.prototype.startsWith?filename.startsWith(dataURIPrefix):filename.indexOf(dataURIPrefix)===0}function integrateWasmJS(){var wasmTextFile="wvnc_asm.wast";var wasmBinaryFile="wvnc_asm.wasm";var asmjsCodeFile="wvnc_asm.temp.asm.js";if(!isDataURI(wasmTextFile)){wasmTextFile=locateFile(wasmTextFile)}if(!isDataURI(wasmBinaryFile)){wasmBinaryFile=locateFile(wasmBinaryFile)}if(!isDataURI(asmjsCodeFile)){asmjsCodeFile=locateFile(asmjsCodeFile)}var wasmPageSize=64*1024;var info={"global":null,"env":null,"asm2wasm":asm2wasmImports,"parent":Module};var exports=null;function mergeMemory(newBuffer){var oldBuffer=Module["buffer"];if(newBuffer.byteLength>2]=poolPtr;HEAP32[environ>>2]=envPtr}else{envPtr=HEAP32[environ>>2];poolPtr=HEAP32[envPtr>>2]}var strings=[];var totalSize=0;for(var key in ENV){if(typeof ENV[key]==="string"){var line=key+"="+ENV[key];strings.push(line);totalSize+=line.length}}if(totalSize>TOTAL_ENV_SIZE){throw new Error("Environment size exceeded TOTAL_ENV_SIZE!")}var ptrSize=4;for(var i=0;i>2]=poolPtr;poolPtr+=line.length+1}HEAP32[envPtr+strings.length*ptrSize>>2]=0}var SYSCALLS={varargs:0,get:(function(varargs){SYSCALLS.varargs+=4;var ret=HEAP32[SYSCALLS.varargs-4>>2];return ret}),getStr:(function(){var ret=Pointer_stringify(SYSCALLS.get());return ret}),get64:(function(){var low=SYSCALLS.get(),high=SYSCALLS.get();if(low>=0)assert(high===0);else assert(high===-1);return low}),getZero:(function(){assert(SYSCALLS.get()===0)})};function ___syscall140(which,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.getStreamFromFD(),offset_high=SYSCALLS.get(),offset_low=SYSCALLS.get(),result=SYSCALLS.get(),whence=SYSCALLS.get();var offset=offset_low;FS.llseek(stream,offset,whence);HEAP32[result>>2]=stream.position;if(stream.getdents&&offset===0&&whence===0)stream.getdents=null;return 0}catch(e){if(typeof FS==="undefined"||!(e instanceof FS.ErrnoError))abort(e);return-e.errno}}function ___syscall146(which,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.get(),iov=SYSCALLS.get(),iovcnt=SYSCALLS.get();var ret=0;if(!___syscall146.buffers){___syscall146.buffers=[null,[],[]];___syscall146.printChar=(function(stream,curr){var buffer=___syscall146.buffers[stream];assert(buffer);if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer,0));buffer.length=0}else{buffer.push(curr)}})}for(var i=0;i>2];var len=HEAP32[iov+(i*8+4)>>2];for(var j=0;j>2]=value;return value}function _jconst_fancy_upsample_avx2(){err("missing function: jconst_fancy_upsample_avx2");abort(-1)}function _jconst_fancy_upsample_sse2(){err("missing function: jconst_fancy_upsample_sse2");abort(-1)}function _jconst_idct_float_sse(){err("missing function: jconst_idct_float_sse");abort(-1)}function _jconst_idct_float_sse2(){err("missing function: jconst_idct_float_sse2");abort(-1)}function _jconst_idct_ifast_sse2(){err("missing function: jconst_idct_ifast_sse2");abort(-1)}function _jconst_idct_islow_avx2(){err("missing function: jconst_idct_islow_avx2");abort(-1)}function _jconst_idct_islow_sse2(){err("missing function: jconst_idct_islow_sse2");abort(-1)}function _jconst_idct_red_sse2(){err("missing function: jconst_idct_red_sse2");abort(-1)}function _jconst_merged_upsample_avx2(){err("missing function: jconst_merged_upsample_avx2");abort(-1)}function _jconst_merged_upsample_sse2(){err("missing function: jconst_merged_upsample_sse2");abort(-1)}function _jconst_ycc_rgb_convert_avx2(){err("missing function: jconst_ycc_rgb_convert_avx2");abort(-1)}function _jconst_ycc_rgb_convert_sse2(){err("missing function: jconst_ycc_rgb_convert_sse2");abort(-1)}DYNAMICTOP_PTR=staticAlloc(4);STACK_BASE=STACKTOP=alignMemory(STATICTOP);STACK_MAX=STACK_BASE+TOTAL_STACK;DYNAMIC_BASE=alignMemory(STACK_MAX);HEAP32[DYNAMICTOP_PTR>>2]=DYNAMIC_BASE;staticSealed=true;Module["wasmTableSize"]=308;Module["wasmMaxTableSize"]=308;Module.asmGlobalArg={};Module.asmLibraryArg={"abort":abort,"enlargeMemory":enlargeMemory,"getTotalMemory":getTotalMemory,"abortOnCannotGrowMemory":abortOnCannotGrowMemory,"___buildEnvironment":___buildEnvironment,"___setErrNo":___setErrNo,"___syscall140":___syscall140,"___syscall146":___syscall146,"___syscall54":___syscall54,"___syscall6":___syscall6,"_emscripten_memcpy_big":_emscripten_memcpy_big,"_exit":_exit,"_getenv":_getenv,"_jpeg_simd_cpu_support":_jpeg_simd_cpu_support,"_jsimd_h2v1_extbgr_merged_upsample_avx2":_jsimd_h2v1_extbgr_merged_upsample_avx2,"_jsimd_h2v1_extbgr_merged_upsample_mmx":_jsimd_h2v1_extbgr_merged_upsample_mmx,"_jsimd_h2v1_extbgr_merged_upsample_sse2":_jsimd_h2v1_extbgr_merged_upsample_sse2,"_jsimd_h2v1_extbgrx_merged_upsample_avx2":_jsimd_h2v1_extbgrx_merged_upsample_avx2,"_jsimd_h2v1_extbgrx_merged_upsample_mmx":_jsimd_h2v1_extbgrx_merged_upsample_mmx,"_jsimd_h2v1_extbgrx_merged_upsample_sse2":_jsimd_h2v1_extbgrx_merged_upsample_sse2,"_jsimd_h2v1_extrgb_merged_upsample_avx2":_jsimd_h2v1_extrgb_merged_upsample_avx2,"_jsimd_h2v1_extrgb_merged_upsample_mmx":_jsimd_h2v1_extrgb_merged_upsample_mmx,"_jsimd_h2v1_extrgb_merged_upsample_sse2":_jsimd_h2v1_extrgb_merged_upsample_sse2,"_jsimd_h2v1_extrgbx_merged_upsample_avx2":_jsimd_h2v1_extrgbx_merged_upsample_avx2,"_jsimd_h2v1_extrgbx_merged_upsample_mmx":_jsimd_h2v1_extrgbx_merged_upsample_mmx,"_jsimd_h2v1_extrgbx_merged_upsample_sse2":_jsimd_h2v1_extrgbx_merged_upsample_sse2,"_jsimd_h2v1_extxbgr_merged_upsample_avx2":_jsimd_h2v1_extxbgr_merged_upsample_avx2,"_jsimd_h2v1_extxbgr_merged_upsample_mmx":_jsimd_h2v1_extxbgr_merged_upsample_mmx,"_jsimd_h2v1_extxbgr_merged_upsample_sse2":_jsimd_h2v1_extxbgr_merged_upsample_sse2,"_jsimd_h2v1_extxrgb_merged_upsample_avx2":_jsimd_h2v1_extxrgb_merged_upsample_avx2,"_jsimd_h2v1_extxrgb_merged_upsample_mmx":_jsimd_h2v1_extxrgb_merged_upsample_mmx,"_jsimd_h2v1_extxrgb_merged_upsample_sse2":_jsimd_h2v1_extxrgb_merged_upsample_sse2,"_jsimd_h2v1_fancy_upsample_avx2":_jsimd_h2v1_fancy_upsample_avx2,"_jsimd_h2v1_fancy_upsample_mmx":_jsimd_h2v1_fancy_upsample_mmx,"_jsimd_h2v1_fancy_upsample_sse2":_jsimd_h2v1_fancy_upsample_sse2,"_jsimd_h2v1_merged_upsample_avx2":_jsimd_h2v1_merged_upsample_avx2,"_jsimd_h2v1_merged_upsample_mmx":_jsimd_h2v1_merged_upsample_mmx,"_jsimd_h2v1_merged_upsample_sse2":_jsimd_h2v1_merged_upsample_sse2,"_jsimd_h2v1_upsample_avx2":_jsimd_h2v1_upsample_avx2,"_jsimd_h2v1_upsample_mmx":_jsimd_h2v1_upsample_mmx,"_jsimd_h2v1_upsample_sse2":_jsimd_h2v1_upsample_sse2,"_jsimd_h2v2_extbgr_merged_upsample_avx2":_jsimd_h2v2_extbgr_merged_upsample_avx2,"_jsimd_h2v2_extbgr_merged_upsample_mmx":_jsimd_h2v2_extbgr_merged_upsample_mmx,"_jsimd_h2v2_extbgr_merged_upsample_sse2":_jsimd_h2v2_extbgr_merged_upsample_sse2,"_jsimd_h2v2_extbgrx_merged_upsample_avx2":_jsimd_h2v2_extbgrx_merged_upsample_avx2,"_jsimd_h2v2_extbgrx_merged_upsample_mmx":_jsimd_h2v2_extbgrx_merged_upsample_mmx,"_jsimd_h2v2_extbgrx_merged_upsample_sse2":_jsimd_h2v2_extbgrx_merged_upsample_sse2,"_jsimd_h2v2_extrgb_merged_upsample_avx2":_jsimd_h2v2_extrgb_merged_upsample_avx2,"_jsimd_h2v2_extrgb_merged_upsample_mmx":_jsimd_h2v2_extrgb_merged_upsample_mmx,"_jsimd_h2v2_extrgb_merged_upsample_sse2":_jsimd_h2v2_extrgb_merged_upsample_sse2,"_jsimd_h2v2_extrgbx_merged_upsample_avx2":_jsimd_h2v2_extrgbx_merged_upsample_avx2,"_jsimd_h2v2_extrgbx_merged_upsample_mmx":_jsimd_h2v2_extrgbx_merged_upsample_mmx,"_jsimd_h2v2_extrgbx_merged_upsample_sse2":_jsimd_h2v2_extrgbx_merged_upsample_sse2,"_jsimd_h2v2_extxbgr_merged_upsample_avx2":_jsimd_h2v2_extxbgr_merged_upsample_avx2,"_jsimd_h2v2_extxbgr_merged_upsample_mmx":_jsimd_h2v2_extxbgr_merged_upsample_mmx,"_jsimd_h2v2_extxbgr_merged_upsample_sse2":_jsimd_h2v2_extxbgr_merged_upsample_sse2,"_jsimd_h2v2_extxrgb_merged_upsample_avx2":_jsimd_h2v2_extxrgb_merged_upsample_avx2,"_jsimd_h2v2_extxrgb_merged_upsample_mmx":_jsimd_h2v2_extxrgb_merged_upsample_mmx,"_jsimd_h2v2_extxrgb_merged_upsample_sse2":_jsimd_h2v2_extxrgb_merged_upsample_sse2,"_jsimd_h2v2_fancy_upsample_avx2":_jsimd_h2v2_fancy_upsample_avx2,"_jsimd_h2v2_fancy_upsample_mmx":_jsimd_h2v2_fancy_upsample_mmx,"_jsimd_h2v2_fancy_upsample_sse2":_jsimd_h2v2_fancy_upsample_sse2,"_jsimd_h2v2_merged_upsample_avx2":_jsimd_h2v2_merged_upsample_avx2,"_jsimd_h2v2_merged_upsample_mmx":_jsimd_h2v2_merged_upsample_mmx,"_jsimd_h2v2_merged_upsample_sse2":_jsimd_h2v2_merged_upsample_sse2,"_jsimd_h2v2_upsample_avx2":_jsimd_h2v2_upsample_avx2,"_jsimd_h2v2_upsample_mmx":_jsimd_h2v2_upsample_mmx,"_jsimd_h2v2_upsample_sse2":_jsimd_h2v2_upsample_sse2,"_jsimd_idct_2x2_mmx":_jsimd_idct_2x2_mmx,"_jsimd_idct_2x2_sse2":_jsimd_idct_2x2_sse2,"_jsimd_idct_4x4_mmx":_jsimd_idct_4x4_mmx,"_jsimd_idct_4x4_sse2":_jsimd_idct_4x4_sse2,"_jsimd_idct_float_3dnow":_jsimd_idct_float_3dnow,"_jsimd_idct_float_sse":_jsimd_idct_float_sse,"_jsimd_idct_float_sse2":_jsimd_idct_float_sse2,"_jsimd_idct_ifast_mmx":_jsimd_idct_ifast_mmx,"_jsimd_idct_ifast_sse2":_jsimd_idct_ifast_sse2,"_jsimd_idct_islow_avx2":_jsimd_idct_islow_avx2,"_jsimd_idct_islow_mmx":_jsimd_idct_islow_mmx,"_jsimd_idct_islow_sse2":_jsimd_idct_islow_sse2,"_jsimd_ycc_extbgr_convert_avx2":_jsimd_ycc_extbgr_convert_avx2,"_jsimd_ycc_extbgr_convert_mmx":_jsimd_ycc_extbgr_convert_mmx,"_jsimd_ycc_extbgr_convert_sse2":_jsimd_ycc_extbgr_convert_sse2,"_jsimd_ycc_extbgrx_convert_avx2":_jsimd_ycc_extbgrx_convert_avx2,"_jsimd_ycc_extbgrx_convert_mmx":_jsimd_ycc_extbgrx_convert_mmx,"_jsimd_ycc_extbgrx_convert_sse2":_jsimd_ycc_extbgrx_convert_sse2,"_jsimd_ycc_extrgb_convert_avx2":_jsimd_ycc_extrgb_convert_avx2,"_jsimd_ycc_extrgb_convert_mmx":_jsimd_ycc_extrgb_convert_mmx,"_jsimd_ycc_extrgb_convert_sse2":_jsimd_ycc_extrgb_convert_sse2,"_jsimd_ycc_extrgbx_convert_avx2":_jsimd_ycc_extrgbx_convert_avx2,"_jsimd_ycc_extrgbx_convert_mmx":_jsimd_ycc_extrgbx_convert_mmx,"_jsimd_ycc_extrgbx_convert_sse2":_jsimd_ycc_extrgbx_convert_sse2,"_jsimd_ycc_extxbgr_convert_avx2":_jsimd_ycc_extxbgr_convert_avx2,"_jsimd_ycc_extxbgr_convert_mmx":_jsimd_ycc_extxbgr_convert_mmx,"_jsimd_ycc_extxbgr_convert_sse2":_jsimd_ycc_extxbgr_convert_sse2,"_jsimd_ycc_extxrgb_convert_avx2":_jsimd_ycc_extxrgb_convert_avx2,"_jsimd_ycc_extxrgb_convert_mmx":_jsimd_ycc_extxrgb_convert_mmx,"_jsimd_ycc_extxrgb_convert_sse2":_jsimd_ycc_extxrgb_convert_sse2,"_jsimd_ycc_rgb_convert_avx2":_jsimd_ycc_rgb_convert_avx2,"_jsimd_ycc_rgb_convert_mmx":_jsimd_ycc_rgb_convert_mmx,"_jsimd_ycc_rgb_convert_sse2":_jsimd_ycc_rgb_convert_sse2,"DYNAMICTOP_PTR":DYNAMICTOP_PTR,"STACKTOP":STACKTOP,"_jconst_fancy_upsample_avx2":_jconst_fancy_upsample_avx2,"_jconst_fancy_upsample_sse2":_jconst_fancy_upsample_sse2,"_jconst_idct_float_sse":_jconst_idct_float_sse,"_jconst_idct_float_sse2":_jconst_idct_float_sse2,"_jconst_idct_ifast_sse2":_jconst_idct_ifast_sse2,"_jconst_idct_islow_avx2":_jconst_idct_islow_avx2,"_jconst_idct_islow_sse2":_jconst_idct_islow_sse2,"_jconst_idct_red_sse2":_jconst_idct_red_sse2,"_jconst_merged_upsample_avx2":_jconst_merged_upsample_avx2,"_jconst_merged_upsample_sse2":_jconst_merged_upsample_sse2,"_jconst_ycc_rgb_convert_avx2":_jconst_ycc_rgb_convert_avx2,"_jconst_ycc_rgb_convert_sse2":_jconst_ycc_rgb_convert_sse2};var asm=Module["asm"](Module.asmGlobalArg,Module.asmLibraryArg,buffer);Module["asm"]=asm;var ___emscripten_environ_constructor=Module["___emscripten_environ_constructor"]=(function(){return Module["asm"]["___emscripten_environ_constructor"].apply(null,arguments)});var ___errno_location=Module["___errno_location"]=(function(){return Module["asm"]["___errno_location"].apply(null,arguments)});var _create_buffer=Module["_create_buffer"]=(function(){return Module["asm"]["_create_buffer"].apply(null,arguments)});var _destroy_buffer=Module["_destroy_buffer"]=(function(){return Module["asm"]["_destroy_buffer"].apply(null,arguments)});var _free=Module["_free"]=(function(){return Module["asm"]["_free"].apply(null,arguments)});var _malloc=Module["_malloc"]=(function(){return Module["asm"]["_malloc"].apply(null,arguments)});var _update=Module["_update"]=(function(){return Module["asm"]["_update"].apply(null,arguments)});var stackAlloc=Module["stackAlloc"]=(function(){return Module["asm"]["stackAlloc"].apply(null,arguments)});var stackRestore=Module["stackRestore"]=(function(){return Module["asm"]["stackRestore"].apply(null,arguments)});var stackSave=Module["stackSave"]=(function(){return Module["asm"]["stackSave"].apply(null,arguments)});var dynCall_vi=Module["dynCall_vi"]=(function(){return Module["asm"]["dynCall_vi"].apply(null,arguments)});Module["asm"]=asm;Module["cwrap"]=cwrap;function ExitStatus(status){this.name="ExitStatus";this.message="Program terminated with exit("+status+")";this.status=status}ExitStatus.prototype=new Error;ExitStatus.prototype.constructor=ExitStatus;var initialStackTop;dependenciesFulfilled=function runCaller(){if(!Module["calledRun"])run();if(!Module["calledRun"])dependenciesFulfilled=runCaller};function run(args){args=args||Module["arguments"];if(runDependencies>0){return}preRun();if(runDependencies>0)return;if(Module["calledRun"])return;function doRun(){if(Module["calledRun"])return;Module["calledRun"]=true;if(ABORT)return;ensureInitRuntime();preMain();if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout((function(){setTimeout((function(){Module["setStatus"]("")}),1);doRun()}),1)}else{doRun()}}Module["run"]=run;function exit(status,implicit){if(implicit&&Module["noExitRuntime"]&&status===0){return}if(Module["noExitRuntime"]){}else{ABORT=true;EXITSTATUS=status;STACKTOP=initialStackTop;exitRuntime();if(Module["onExit"])Module["onExit"](status)}Module["quit"](status,new ExitStatus(status))}function abort(what){if(Module["onAbort"]){Module["onAbort"](what)}if(what!==undefined){out(what);err(what);what=JSON.stringify(what)}else{what=""}ABORT=true;EXITSTATUS=1;throw"abort("+what+"). Build with -s ASSERTIONS=1 for more info."}Module["abort"]=abort;if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}Module["noExitRuntime"]=true;run() - - - diff --git a/wasm/wvnc_asm.wasm b/wasm/wvnc_asm.wasm deleted file mode 100644 index 553d9ec..0000000 Binary files a/wasm/wvnc_asm.wasm and /dev/null differ diff --git a/wvnc.c b/wvnc.c index 2872215..a6c04d5 100644 --- a/wvnc.c +++ b/wvnc.c @@ -499,7 +499,6 @@ void *consume_client(void *ptr, wvnc_cmd_t header) uint8_t cmd = header.cmd; uint16_t size = header.size; wvnc_user_data_t *user_data = get_user_data(ptr); - //LOG("Data size is %d\n", size); uint8_t *data; // in case of string switch (cmd) @@ -533,12 +532,36 @@ void *consume_client(void *ptr, wvnc_cmd_t header) //LOG("Key is %c\n", header.data[0]); SendKeyEvent(user_data->vncl, header.data[0] | (header.data[1] << 8), header.data[2]?TRUE:FALSE); break; + case 0x07: + SendClientCutText(user_data->vncl, header.data, strlen(header.data)); + break; default: return vnc_fatal(user_data, "Unknown client command"); } return NULL; } +static void got_clipboard(rfbClient *cl, const char *text, int len) +{ + LOG("received clipboard text '%s'\n", text); + void *data = rfbClientGetClientData(cl, identify()); + wvnc_user_data_t *user_data = get_user_data(data); + uint8_t* cmd = (uint8_t*) malloc(len+1); + cmd[0] = 0x85; + memcpy(cmd+1, text, len); + ws_b(user_data->client,cmd,len+1); + free(cmd); + uint8_t *ack = (uint8_t *)process(user_data, 1); + if (!ack || !(*ack)) + { + LOG("Fail to set client clipboard\n"); + if (ack) + free(ack); + return; + } + free(ack); +} + void handle(void *cl, const char *m, const char *rqp, dictionary rq) { if (ws_enable(rq)) @@ -567,7 +590,7 @@ void handle(void *cl, const char *m, const char *rqp, dictionary rq) vncl->GetPassword = get_password; //cl->HandleKeyboardLedState=kbd_leds; //cl->HandleTextChat=text_chat; - //cl->GotXCutText = got_selection; + vncl->GotXCutText = got_clipboard; vncl->GetCredential = get_credential; vncl->listenPort = LISTEN_PORT_OFFSET; vncl->listen6Port = LISTEN_PORT_OFFSET;