Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
6.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
3 years ago
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * jQuery Clipchamp MJPEG Player Plugin v0.0.1
  3. * https://github.com/clipchamp/jquery-clipchamp-mjpeg-player-plugin
  4. *
  5. * Plays back MJPEG files produced by the clipchamp
  6. * online video converter, online video compressor, and
  7. * webcam recorder.
  8. *
  9. * Copyright 2015 zfaas Pty Ltd (clipchamp.com)
  10. * https://clipchamp.com
  11. * https://zfaas.com
  12. *
  13. * Released under the MIT license
  14. */
  15. (function($) {
  16. var DEFAULT_FPS = 15,
  17. DEFAULT_AUTOLOOP = true,
  18. JPEG_MAGIG_NUMBER = [0xff, 0xd8, 0xff],
  19. CONTINUE_PLAY = true,
  20. imageElement = null,
  21. nextFrameIndex = 0,
  22. jpegUrl,
  23. jpegFiles = null,
  24. autoloop = false,
  25. fps =1,
  26. ran=null,
  27. timerBOBA = null;
  28. var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || window.setTimeout;
  29. function showNextFrame() {
  30. if (imageElement) {
  31. if (jpegUrl) {
  32. URL.revokeObjectURL(jpegUrl);
  33. }
  34. jpegUrl = URL.createObjectURL(jpegFiles[nextFrameIndex++]);
  35. imageElement.onload = function() {
  36. if (imageElement) {
  37. if (autoloop || nextFrameIndex < jpegFiles.length) {
  38. nextFrameIndex = (nextFrameIndex === jpegFiles.length) ? 0 : nextFrameIndex;
  39. if( ( nextFrameIndex % fps ) == 0 ) ran.value = nextFrameIndex;
  40. if( CONTINUE_PLAY ) {
  41. if( timerBOBA == null ){
  42. timerBOBA = setInterval(
  43. //setTimeout(
  44. function() {
  45. requestAnimationFrame(showNextFrame);
  46. }, 1000/fps);
  47. };
  48. } else {
  49. if( timerBOBA!= null ){
  50. clearInterval( timerBOBA );
  51. timerBOBA = null;
  52. };
  53. };
  54. }
  55. }
  56. };
  57. imageElement.setAttribute('src', jpegUrl);
  58. };
  59. };
  60. function splitMJPEG(mjpegUrl, callback) {
  61. var xhr = new XMLHttpRequest();
  62. xhr.open('GET', mjpegUrl, true);
  63. xhr.overrideMimeType('application/octet-stream');
  64. xhr.responseType = 'arraybuffer';
  65. xhr.onload = function(event) {
  66. var array = new Uint8Array(xhr.response),
  67. startIndex,
  68. jpegs = [];
  69. for (var i=0, ii=array.length; i<ii; ++i) {
  70. if (array[i] === JPEG_MAGIG_NUMBER[0] && array[i+1] === JPEG_MAGIG_NUMBER[1] && array[i+2] === JPEG_MAGIG_NUMBER[2]) {
  71. if (i>0 && typeof startIndex === 'number') {
  72. jpegs.push(new Blob([array.subarray(startIndex, i)], {type: 'image/jpeg'}));
  73. }
  74. startIndex = i;
  75. }
  76. }
  77. callback(jpegs);
  78. };
  79. xhr.send();
  80. };
  81. function playMJPEGInternal(wrapperElement, mjpegUrl, fp, aloop) {
  82. fps = (typeof fp === 'number') ? fp : DEFAULT_FPS;
  83. autoloop = (typeof aloop === 'boolean') ? aloop : DEFAULT_AUTOLOOP;
  84. var playbackFinished = false;
  85. imageElement = document.createElement('img');
  86. var dWE = document.createElement('div');
  87. dWE.setAttribute( 'id', 'wrpo_'+wrapperElement.id );
  88. var W = wrapperElement.clientWidth;
  89. var H = ( W / 16 ) * 9;
  90. dWE.setAttribute( 'style', "display: block; width: 100%; height: "+H+"px; background-color: #000; background-image:url('/style/assets/loading_red_cube.gif');background-position: center;background-repeat: no-repeat;" );
  91. dWE.appendChild(imageElement);
  92. imageElement.setAttribute('style', "width:100%;");
  93. wrapperElement.appendChild( dWE );
  94. //alert('SLADKIY_BUBALEKH:'+ W + " " + H );
  95. //Show SLADKIY_BUBALEKH
  96. splitMJPEG(mjpegUrl, function( Files ) {
  97. jpegFiles = Files;
  98. //Hide SLADKIY_BUBALEKH -> or error!
  99. //alert( jpegFiles.length );
  100. var ctlDIV = document.createElement('div');
  101. ctlDIV.setAttribute( 'id', 'ctl_'+wrapperElement.id );
  102. ctlDIV.setAttribute( 'class', 'player_controls' );
  103. var btn = document.createElement('div');
  104. btn.setAttribute( 'id', 'btn_play_stop'+wrapperElement.id );
  105. btn.setAttribute( 'onclick', "stop_mjpeg('btn_play_stop"+wrapperElement.id+"');" );
  106. btn.classList.add('pl_ctl_btn');
  107. btn.classList.add('stop_button');
  108. ctlDIV.appendChild(btn);
  109. ran = document.createElement('input');
  110. ran.setAttribute( 'type', "range" );
  111. ran.setAttribute( 'id', 'range_'+wrapperElement.id );
  112. ran.setAttribute( 'step','1');
  113. ran.setAttribute( 'min','0');
  114. ran.setAttribute( 'max', jpegFiles.length );
  115. ran.setAttribute( 'value','0');
  116. ran.setAttribute( 'style','margin-left: 10px;width: 80%;' );
  117. ran.setAttribute( 'oninput', "setpos_mjpeg(this.value);" );
  118. ran.setAttribute( 'onchange', "setpos_s_mjpeg(this.value);" );
  119. ctlDIV.appendChild(ran);
  120. btn = document.createElement('div');
  121. btn.setAttribute( 'id', 'btn_loop'+wrapperElement.id );
  122. btn.setAttribute( 'onclick', "stop_loop_mjpeg('btn_loop"+wrapperElement.id+"');" );
  123. btn.classList.add('pl_ctl_btn');
  124. btn.classList.add('loop');
  125. ctlDIV.appendChild(btn);
  126. dWE.appendChild(ctlDIV);
  127. if (jpegFiles.length > 0) {
  128. if( CONTINUE_PLAY ) {
  129. if( timerBOBA == null ){
  130. timerBOBA = setInterval(
  131. //setTimeout(
  132. function() {
  133. requestAnimationFrame(showNextFrame);
  134. }, 1000/fps);
  135. };
  136. } else {
  137. if( timerBOBA!= null ){
  138. clearInterval( timerBOBA );
  139. timerBOBA = null;
  140. };
  141. };
  142. //if( CONTINUE_PLAY ) setTimeout(function() {
  143. // requestAnimationFrame(showNextFrame);
  144. //}, 1000/fps);
  145. } else {
  146. alert('Error Loading Video');
  147. };
  148. });
  149. return {
  150. finish: function() {
  151. if (imageElement) {
  152. imageElement.src = '';
  153. wrapperElement.removeChild(imageElement);
  154. imageElement = undefined;
  155. }
  156. },
  157. pause: function(){
  158. CONTINUE_PLAY = false;
  159. },
  160. play: function( fromBegin ){
  161. if(typeof fromBegin === 'number') {
  162. nextFrameIndex = fromBegin;
  163. nextFrameIndex = (nextFrameIndex === jpegFiles.length) ? 0 : nextFrameIndex;
  164. };
  165. CONTINUE_PLAY = true;
  166. setTimeout(function() {
  167. requestAnimationFrame( showNextFrame);
  168. }, 1000/fps);
  169. },
  170. alertInfo: function(){
  171. alert( jpegFiles.length );
  172. }
  173. };
  174. };
  175. // optionally make available as jQuery plugin
  176. if (typeof $ === 'function') {
  177. $.fn.clipchamp_mjpeg_player = function(mjpegUrl, fps, autoloop, callback) {
  178. if (typeof mjpegUrl === 'string') {
  179. if (typeof callback === 'function') {
  180. return this.each(function() {
  181. callback($(this)[0], playMJPEGInternal($(this)[0], mjpegUrl, fps, autoloop));
  182. });
  183. } else {
  184. throw new Error('Callback must be given and must be a function');
  185. }
  186. } else {
  187. throw new Error('MJPEG URL must be a string');
  188. }
  189. }
  190. }
  191. // optionally provide AMD module definition
  192. if (typeof define === 'function') {
  193. define('jquery.clipchamp.mjpeg.player', [], function() {
  194. return {
  195. playMJPEG: function(wrapperElement, mjpegUrl, fps, autoloop) {
  196. if (wrapperElement instanceof Element) {
  197. if (typeof mjpegUrl === 'string') {
  198. return playMJPEGInternal(wrapperElement, mjpegUrl, fps, autoloop);
  199. } else {
  200. throw new Error('MJPEG URL must be a string');
  201. }
  202. } else {
  203. throw new Error('No parent element was given');
  204. }
  205. }
  206. };
  207. });
  208. }
  209. } )
  210. (typeof jQuery === 'function' ? jQuery : undefined);