videoWorkerTrain.worker.js 16 KB

1
  1. !function(t){var e={};function r(n){if(e[n])return e[n].exports;var a=e[n]={i:n,l:!1,exports:{}};return t[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var a in t)r.d(n,a,function(e){return t[e]}.bind(null,a));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";function n(t){return(n="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}if(r.r(e),"undefined"==typeof a)var a={};a.MD5=function(t){function e(t){var e=(t>>>0).toString(16);return"00000000".substr(0,8-e.length)+e}function r(t,e,r){return t&e|~t&r}function a(t,e,r){return r&t|~r&e}function i(t,e,r){return t^e^r}function o(t,e,r){return e^(t|~r)}function _(t,e){return t[e+3]<<24|t[e+2]<<16|t[e+1]<<8|t[e]}function u(t){for(var e=[],r=0;r<t.length;r++)if(t.charCodeAt(r)<=127)e.push(t.charCodeAt(r));else for(var n=encodeURIComponent(t.charAt(r)).substr(1).split("%"),a=0;a<n.length;a++)e.push(parseInt(n[a],16));return e}function f(t){for(var e=new Array(t.length),r=0;r<t.length;r++)e[r]=t[r];return e}var p=null,c=null;function s(t,e){return 4294967295&t+e}return"string"==typeof t?p=u(t):t.constructor==Array?0===t.length?p=t:"string"==typeof t[0]?p=function(t){for(var e=[],r=0;r<t.length;r++)e=e.concat(u(t[r]));return e}(t):"number"==typeof t[0]?p=t:c=n(t[0]):"undefined"!=typeof ArrayBuffer?t instanceof ArrayBuffer?p=f(new Uint8Array(t)):t instanceof Uint8Array||t instanceof Int8Array?p=f(t):t instanceof Uint32Array||t instanceof Int32Array||t instanceof Uint16Array||t instanceof Int16Array||t instanceof Float32Array||t instanceof Float64Array?p=f(new Uint8Array(t.buffer)):c=n(t):c=n(t),c&&alert("MD5 type mismatch, cannot process "+c),function(){function t(t,e,r,n){var a,i,o=v;v=y,y=h,h=s(h,(a=s(d,s(t,s(e,r))))<<(i=n)&4294967295|a>>>32-i),d=o}var n=p.length;p.push(128);var u=p.length%64;if(u>56){for(var f=0;f<64-u;f++)p.push(0);u=p.length%64}for(f=0;f<56-u;f++)p.push(0);p=p.concat(function(t){for(var e=[],r=0;r<8;r++)e.push(255&t),t>>>=8;return e}(8*n));var c=1732584193,l=4023233417,m=2562383102,g=271733878,d=0,h=0,y=0,v=0;for(f=0;f<p.length/64;f++){d=c;var b=64*f;t(r(h=l,y=m,v=g),3614090360,_(p,b),7),t(r(h,y,v),3905402710,_(p,b+4),12),t(r(h,y,v),606105819,_(p,b+8),17),t(r(h,y,v),3250441966,_(p,b+12),22),t(r(h,y,v),4118548399,_(p,b+16),7),t(r(h,y,v),1200080426,_(p,b+20),12),t(r(h,y,v),2821735955,_(p,b+24),17),t(r(h,y,v),4249261313,_(p,b+28),22),t(r(h,y,v),1770035416,_(p,b+32),7),t(r(h,y,v),2336552879,_(p,b+36),12),t(r(h,y,v),4294925233,_(p,b+40),17),t(r(h,y,v),2304563134,_(p,b+44),22),t(r(h,y,v),1804603682,_(p,b+48),7),t(r(h,y,v),4254626195,_(p,b+52),12),t(r(h,y,v),2792965006,_(p,b+56),17),t(r(h,y,v),1236535329,_(p,b+60),22),t(a(h,y,v),4129170786,_(p,b+4),5),t(a(h,y,v),3225465664,_(p,b+24),9),t(a(h,y,v),643717713,_(p,b+44),14),t(a(h,y,v),3921069994,_(p,b),20),t(a(h,y,v),3593408605,_(p,b+20),5),t(a(h,y,v),38016083,_(p,b+40),9),t(a(h,y,v),3634488961,_(p,b+60),14),t(a(h,y,v),3889429448,_(p,b+16),20),t(a(h,y,v),568446438,_(p,b+36),5),t(a(h,y,v),3275163606,_(p,b+56),9),t(a(h,y,v),4107603335,_(p,b+12),14),t(a(h,y,v),1163531501,_(p,b+32),20),t(a(h,y,v),2850285829,_(p,b+52),5),t(a(h,y,v),4243563512,_(p,b+8),9),t(a(h,y,v),1735328473,_(p,b+28),14),t(a(h,y,v),2368359562,_(p,b+48),20),t(i(h,y,v),4294588738,_(p,b+20),4),t(i(h,y,v),2272392833,_(p,b+32),11),t(i(h,y,v),1839030562,_(p,b+44),16),t(i(h,y,v),4259657740,_(p,b+56),23),t(i(h,y,v),2763975236,_(p,b+4),4),t(i(h,y,v),1272893353,_(p,b+16),11),t(i(h,y,v),4139469664,_(p,b+28),16),t(i(h,y,v),3200236656,_(p,b+40),23),t(i(h,y,v),681279174,_(p,b+52),4),t(i(h,y,v),3936430074,_(p,b),11),t(i(h,y,v),3572445317,_(p,b+12),16),t(i(h,y,v),76029189,_(p,b+24),23),t(i(h,y,v),3654602809,_(p,b+36),4),t(i(h,y,v),3873151461,_(p,b+48),11),t(i(h,y,v),530742520,_(p,b+60),16),t(i(h,y,v),3299628645,_(p,b+8),23),t(o(h,y,v),4096336452,_(p,b),6),t(o(h,y,v),1126891415,_(p,b+28),10),t(o(h,y,v),2878612391,_(p,b+56),15),t(o(h,y,v),4237533241,_(p,b+20),21),t(o(h,y,v),1700485571,_(p,b+48),6),t(o(h,y,v),2399980690,_(p,b+12),10),t(o(h,y,v),4293915773,_(p,b+40),15),t(o(h,y,v),2240044497,_(p,b+4),21),t(o(h,y,v),1873313359,_(p,b+32),6),t(o(h,y,v),4264355552,_(p,b+60),10),t(o(h,y,v),2734768916,_(p,b+24),15),t(o(h,y,v),1309151649,_(p,b+52),21),t(o(h,y,v),4149444226,_(p,b+16),6),t(o(h,y,v),3174756917,_(p,b+44),10),t(o(h,y,v),718787259,_(p,b+8),15),t(o(h,y,v),3951481745,_(p,b+36),21),c=s(c,d),l=s(l,h),m=s(m,y),g=s(g,v)}return function(t,r,n,a){for(var i="",o=0,_=0,u=3;u>=0;u--)o=255&(_=arguments[u]),o<<=8,o|=255&(_>>>=8),o<<=8,o|=255&(_>>>=8),o<<=8,i+=e(o|=_>>>=8);return i}(g,m,l,c).toUpperCase()}()};var i={log:function(){},error:function(){},count:function(){},info:function(){}};(function(){function t(){}t.createFromElementId=function(e){for(var r=document.getElementById(e),n="",a=r.firstChild;a;)3===a.nodeType&&(n+=a.textContent),a=a.nextSibling;var i=new t;return i.type=r.type,i.source=n,i},t.createFromSource=function(e,r){var n=new t;return n.type=e,n.source=r,n}})(),function(){function t(t){this.gl=t,this.program=this.gl.createProgram()}t.prototype={attach:function(t){this.gl.attachShader(this.program,t.shader)},link:function(){this.gl.linkProgram(this.program)},use:function(){this.gl.useProgram(this.program)},getAttributeLocation:function(t){return this.gl.getAttribLocation(this.program,t)},setMatrixUniform:function(t,e){var r=this.gl.getUniformLocation(this.program,t);this.gl.uniformMatrix4fv(r,!1,e)}}}(),function(){var t=null;function e(t,e,r){this.gl=t,this.size=e,this.texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.texture),this.format=r||t.LUMINANCE,t.texImage2D(t.TEXTURE_2D,0,this.format,e.w,e.h,0,this.format,t.UNSIGNED_BYTE,null),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)}e.prototype={fill:function(t,e){var r=this.gl;r.bindTexture(r.TEXTURE_2D,this.texture),e?r.texSubImage2D(r.TEXTURE_2D,0,0,0,this.size.w,this.size.h,this.format,r.UNSIGNED_BYTE,t):r.texImage2D(r.TEXTURE_2D,0,this.format,this.size.w,this.size.h,0,this.format,r.UNSIGNED_BYTE,t)},bind:function(e,r,n){var a=this.gl;t||(t=[a.TEXTURE0,a.TEXTURE1,a.TEXTURE2]),a.activeTexture(t[e]),a.bindTexture(a.TEXTURE_2D,this.texture),a.uniform1i(a.getUniformLocation(r.program,n),e)}}}();var o=function(){this.map={}};o.prototype={put:function(t,e){this.map[t]=e},get:function(t){return this.map[t]},containsKey:function(t){return t in this.map},containsValue:function(t){for(var e in this.map)if(this.map[e]===t)return!0;return!1},isEmpty:function(t){return 0===this.size()},clear:function(){for(var t in this.map)delete this.map[t]},remove:function(t){delete this.map[t]},keys:function(){var t=new Array;for(var e in this.map)t.push(e);return t},values:function(){var t=new Array;for(var e in this.map)t.push(this.map[e]);return t},size:function(){var t=0;for(var e in this.map)t++;return t}};var _=o;var u=function(){var t,e,r,n,a,o,_,u,f,p=null,c=new Uint8Array,s=!1;function l(){p=Module._OpenDecoder(0,0,0),l.prototype.setIsFirstFrame(!1)}return l.prototype={init:function(){i.log("H264 Decoder init")},setOutputSize:function(t){u!=2*t&&(u=2*t,f=Module._malloc(u),c=new Uint8Array(Module.HEAPU8.buffer,f,u))},decode:function(i,f){if(t=Date.now(),e=new Uint8Array(i),c.set(e),r=Module._FrameAlloc(),Module._DecodeFrame(p,c.byteOffset,i.byteLength,u,r),n=Date.now()-t,o=Module._getYLength(r),a=Module._getHeight(r),!l.prototype.isFirstFrame())return l.prototype.setIsFirstFrame(!0),{firstFrame:!0};if(o>0&&a>0){t=Date.now();var s=new Uint8Array(c);return _={data:s,option:{yaddr:Module._getY(r),uaddr:Module._getU(r),vaddr:Module._getV(r),ylen:o,height:a,beforeDecoding:t},width:o,height:a,codecType:"h264",decodingTime:n,frameType:f},Module._FrameFree(r),_}},setIsFirstFrame:function(t){s=t},isFirstFrame:function(){return s},free:function(){Module._free(f),f=null}},new l};importScripts("./../module/ffmpegasm.js"),addEventListener("message",function(t){var e=t.data;switch(p=t.data.channelId,e.type){case"MediaData":null===f&&(f=new s),e.data.rtspInterleave[1],f.parseRTPData(e.data.payload)}},!1),Module.onRuntimeInitialized=function(){Module._RegisterAll(),c("WorkerReady")};var f=null,p=null;function c(t,e,r){var n={type:t,data:e,channelId:p,option:r};"canvasRender"===t?postMessage(n,[e.buffer]):postMessage(n)}var s=function(){var t=new l,e=0,r=null;function n(){this.decoder=new u}return n.prototype={init:function(t){},parseRTPData:function(n){var a=null,i={},o=n[22],_=(n[11]<<24)+(n[10]<<16)+(n[9]<<8)+n[8]>>>0,u=n.subarray(24+o,n.length-8),f=n.subarray(n.length-8,n.length),p=(f[7],f[6],f[5],f[4],(n[19]<<24)+(n[18]<<16)+(n[17]<<8)+n[16]>>>0),s=Date.UTC("20"+(p>>>26),(p>>>22&15)-1,p>>>17&31,p>>>12&31,p>>>6&63,63&p)/1e3,l=[];s+=(new Date).getTimezoneOffset()/60*3600;for(var m=0;m<=u.length;)if(0==u[m])if(0==u[m+1])if(1==u[m+2]){if(l.push(m),5==(31&u[m+=3])||1==(31&u[m]))break}else 0==u[m+2]?m++:m+=3;else m+=2;else m+=1;for(m=0;m<l.length;m++)switch(a=u.subarray(l[m]+3,l[m+1]),31&u[l[m]+3]){default:break;case 1:"P",l[m]-1;break;case 5:"I",l[m]-1;break;case 28:break;case 7:t.parse(a),r=t.getSizeInfo().decodeSize;break;case 8:case 6:case 9:}e!==r&&(this.decoder.free(),e=r,this.decoder.setOutputSize(e)),i.frameData=null,i.frameData=this.decoder.decode(u),null!=i.frameData&&null!=i.frameData.data&&(i.frameData.option.time=s,i.frameData.option.frameNo=_,c("canvasRender",i.frameData.data,i.frameData.option))}},new n};function l(){var t=7,e=7,r=2,n=3,a=4,i=5,o=8,u=16,f=32,p=255,c=0,s=null;function l(){c=0,s=new _}function m(r,a){var i=a,o=c+i>>n;return i=c+a&t,r[o]>>e-(i&e)&1}function g(t,e){var r=c>>n,a=8*(r+1)-c;if(a<8)for(var i=0;i<3;i++){var o=t[r+i];o=0==i?o>>a<<a:2==i?o&255>>8-a|1<<a:0,t.set([o],r+i)}else t.set([0],r),t.set([1],r+1)}function d(t,e){var r=0;if(1===e)r=m(t,0);else for(var n=0;n<e;n++)r=(r<<1)+m(t,n);return c+=e,r}function h(t,e){for(var n=0,a=0,i=e;c+i<8*t.length&&!m(t,i++);)n++;if(0===n)return c+=1,0;a=1<<n;for(var o=n-1;o>=0;o--,i++)a|=m(t,i)<<o;return c+=n*r+1,a-1}function y(t,e){var n=h(t,e);return 1&n?(n+1)/r:-n/r}function v(t){s.put("cpb_cnt_minus1",h(t,0)),s.put("bit_rate_scale",d(t,a)),s.put("cpb_size_scale",d(t,a));for(var e=s.get("cpb_cnt_minus1"),r=new Array(e),n=new Array(e),o=new Array(e),_=0;_<=e;_++)r[_]=h(t,0),n[_]=h(t,0),o[_]=d(t,1);s.put("bit_rate_value_minus1",r),s.put("cpb_size_value_minus1",n),s.put("cbr_flag",o),s.put("initial_cpb_removal_delay_length_minus1",d(t,i)),s.put("cpb_removal_delay_length_minus1",d(t,i)),s.put("dpb_output_delay_length_minus1",d(t,i)),s.put("time_offset_length",d(t,i))}return l.prototype={parse:function(t){c=0,s.clear(),s.put("forbidden_zero_bit",d(t,1)),s.put("nal_ref_idc",d(t,r)),s.put("nal_unit_type",d(t,i)),s.put("profile_idc",d(t,o)),s.put("profile_compatibility",d(t,o)),s.put("level_idc",d(t,o)),s.put("seq_parameter_set_id",h(t,0));var e=s.get("profile_idc");if((100===e||110===e||122===e||244===e||44===e||83===e||86===e||118===e||128===e||138===e||139===e||134===e)&&(s.put("chroma_format_idc",h(t,0)),s.get("chroma_format_idc")===n&&s.put("separate_colour_plane_flag",d(t,1)),s.put("bit_depth_luma_minus8",h(t,0)),s.put("bit_depth_chroma_minus8",h(t,0)),s.put("qpprime_y_zero_transform_bypass_flag",d(t,1)),s.put("seq_scaling_matrix_present_flag",d(t,1)),s.get("seq_scaling_matrix_present_flag"))){for(var a=s.get("chroma_format_idc")!==n?o:12,_=new Array(a),l=0;l<a;l++)if(_[l]=d(t,1),_[l])for(var m=l<6?u:64,b=8,T=8,E=0;E<m;E++)T&&(T=(b+y(t,0)+256)%256),b=0===T?b:T;s.put("seq_scaling_list_present_flag",_)}if(s.put("log2_max_frame_num_minus4",h(t,0)),s.put("pic_order_cnt_type",h(t,0)),0===s.get("pic_order_cnt_type"))s.put("log2_max_pic_order_cnt_lsb_minus4",h(t,0));else if(1===s.get("pic_order_cnt_type")){s.put("delta_pic_order_always_zero_flag",d(t,1)),s.put("offset_for_non_ref_pic",y(t,0)),s.put("offset_for_top_to_bottom_field",y(t,0)),s.put("num_ref_frames_in_pic_order_cnt_cycle",h(t,0));for(var w=0;w<s.get("num_ref_frames_in_pic_order_cnt_cycle");w++)s.put("num_ref_frames_in_pic_order_cnt_cycle",y(t,0))}return s.put("num_ref_frames",h(t,0)),s.put("gaps_in_frame_num_value_allowed_flag",d(t,1)),s.put("pic_width_in_mbs_minus1",h(t,0)),s.put("pic_height_in_map_units_minus1",h(t,0)),s.put("frame_mbs_only_flag",d(t,1)),0===s.get("frame_mbs_only_flag")&&s.put("mb_adaptive_frame_field_flag",d(t,1)),s.put("direct_8x8_interence_flag",d(t,1)),s.put("frame_cropping_flag",d(t,1)),1===s.get("frame_cropping_flag")&&(s.put("frame_cropping_rect_left_offset",h(t,0)),s.put("frame_cropping_rect_right_offset",h(t,0)),s.put("frame_cropping_rect_top_offset",h(t,0)),s.put("frame_cropping_rect_bottom_offset",h(t,0))),s.put("vui_parameters_present_flag",d(t,1)),s.get("vui_parameters_present_flag")&&function(t){s.put("aspect_ratio_info_present_flag",d(t,1)),s.get("aspect_ratio_info_present_flag")&&(s.put("aspect_ratio_idc",d(t,o)),s.get("aspect_ratio_idc")===p&&(g(t),s.put("sar_width",d(t,u)),g(t),s.put("sar_height",d(t,u)))),s.put("overscan_info_present_flag",d(t,1)),s.get("overscan_info_present_flag")&&s.put("overscan_appropriate_flag",d(t,1)),s.put("video_signal_type_present_flag",d(t,1)),s.get("video_signal_type_present_flag")&&(s.put("video_format",d(t,n)),s.put("video_full_range_flag",d(t,1)),s.put("colour_description_present_flag",d(t,1)),s.get("colour_description_present_flag")&&(s.put("colour_primaries",d(t,o)),s.put("transfer_characteristics",d(t,o)),s.put("matrix_coefficients",d(t,o)))),s.put("chroma_loc_info_present_flag",d(t,1)),s.get("chroma_loc_info_present_flag")&&(s.put("chroma_sample_loc_type_top_field",h(t,0)),s.put("chroma_sample_loc_type_bottom_field",h(t,0))),s.put("timing_info_present_flag",d(t,1)),s.get("timing_info_present_flag")&&(s.put("num_units_in_tick",d(t,f)),s.put("time_scale",d(t,f)),s.put("fixed_frame_rate_flag",d(t,1))),s.put("nal_hrd_parameters_present_flag",d(t,1)),s.get("nal_hrd_parameters_present_flag")&&v(t),s.put("vcl_hrd_parameters_present_flag",d(t,1)),s.get("vcl_hrd_parameters_present_flag")&&v(t),(s.get("nal_hrd_parameters_present_flag")||s.get("vcl_hrd_parameters_present_flag"))&&s.put("low_delay_hrd_flag",d(t,1)),s.put("pic_struct_present_flag",d(t,1)),s.put("bitstream_restriction_flag",d(t,1)),s.get("bitstream_restriction_flag")&&(s.put("motion_vectors_over_pic_boundaries_flag",d(t,1)),s.put("max_bytes_per_pic_denom",h(t,0)),s.put("max_bits_per_mb_denom",h(t,0)))}(t),!0},getSizeInfo:function(){var t=0,e=0;0===s.get("chroma_format_idc")?t=e=0:1===s.get("chroma_format_idc")?t=e=r:s.get("chroma_format_idc")===r?(t=r,e=1):s.get("chroma_format_idc")===n&&(0===s.get("separate_colour_plane_flag")?t=e=1:1===s.get("separate_colour_plane_flag")&&(t=e=0));var a=s.get("pic_width_in_mbs_minus1")+1,i=s.get("pic_height_in_map_units_minus1")+1,o=(r-s.get("frame_mbs_only_flag"))*i,_=0,f=0,p=0,c=0;1===s.get("frame_cropping_flag")&&(_=s.get("frame_cropping_rect_left_offset"),f=s.get("frame_cropping_rect_right_offset"),p=s.get("frame_cropping_rect_top_offset"),c=s.get("frame_cropping_rect_bottom_offset"));var l=a*u*(o*u);return{width:a*u-t*(_+f),height:o*u-e*(r-s.get("frame_mbs_only_flag"))*(p+c),decodeSize:l}},getSpsValue:function(t){return s.get(t)},getCodecInfo:function(){return s.get("profile_idc").toString(u)+(s.get("profile_compatibility")<15?"0"+s.get("profile_compatibility").toString(u):s.get("profile_compatibility").toString(u))+s.get("level_idc").toString(u)}},new l}}]);