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.

198 lines
6.2 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], CONTINUE_PLAY = true, imageElement = null, nextFrameIndex = 0, jpegUrl, jpegFiles = null, autoloop = false, fps =1, ran=null;
  19. var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || window.setTimeout;
  20. function showNextFrame() {
  21. if (imageElement) {
  22. if (jpegUrl) {
  23. URL.revokeObjectURL(jpegUrl);
  24. }
  25. jpegUrl = URL.createObjectURL(jpegFiles[nextFrameIndex++]);
  26. imageElement.onload = function() {
  27. if (imageElement) {
  28. if (autoloop || nextFrameIndex < jpegFiles.length) {
  29. nextFrameIndex = (nextFrameIndex === jpegFiles.length) ? 0 : nextFrameIndex;
  30. ran.value = nextFrameIndex;
  31. if( CONTINUE_PLAY )
  32. setTimeout(function() {
  33. requestAnimationFrame(showNextFrame);
  34. }, 1000/fps);
  35. }
  36. }
  37. };
  38. imageElement.setAttribute('src', jpegUrl);
  39. };
  40. };
  41. function splitMJPEG(mjpegUrl, callback) {
  42. var xhr = new XMLHttpRequest();
  43. xhr.open('GET', mjpegUrl, true);
  44. xhr.overrideMimeType('application/octet-stream');
  45. xhr.responseType = 'arraybuffer';
  46. xhr.onload = function(event) {
  47. var array = new Uint8Array(xhr.response),
  48. startIndex,
  49. jpegs = [];
  50. for (var i=0, ii=array.length; i<ii; ++i) {
  51. if (array[i] === JPEG_MAGIG_NUMBER[0] && array[i+1] === JPEG_MAGIG_NUMBER[1] && array[i+2] === JPEG_MAGIG_NUMBER[2]) {
  52. if (i>0 && typeof startIndex === 'number') {
  53. jpegs.push(new Blob([array.subarray(startIndex, i)], {type: 'image/jpeg'}));
  54. }
  55. startIndex = i;
  56. }
  57. }
  58. callback(jpegs);
  59. };
  60. xhr.send();
  61. };
  62. function playMJPEGInternal(wrapperElement, mjpegUrl, fp, aloop) {
  63. fps = (typeof fp === 'number') ? fp : DEFAULT_FPS;
  64. autoloop = (typeof aloop === 'boolean') ? aloop : DEFAULT_AUTOLOOP;
  65. var playbackFinished = false;
  66. imageElement = document.createElement('img');
  67. var dWE = document.createElement('div');
  68. dWE.setAttribute( 'id', 'wrpo_'+wrapperElement.id );
  69. var W = wrapperElement.clientWidth;
  70. var H = ( W / 16 ) * 9;
  71. 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;" );
  72. dWE.appendChild(imageElement);
  73. imageElement.setAttribute('style', "width:100%;");
  74. wrapperElement.appendChild( dWE );
  75. //alert('SLADKIY_BUBALEKH:'+ W + " " + H );
  76. //Show SLADKIY_BUBALEKH
  77. splitMJPEG(mjpegUrl, function( Files ) {
  78. jpegFiles = Files;
  79. //Hide SLADKIY_BUBALEKH -> or error!
  80. //alert( jpegFiles.length );
  81. var ctlDIV = document.createElement('div');
  82. ctlDIV.setAttribute( 'id', 'ctl_'+wrapperElement.id );
  83. ctlDIV.setAttribute( 'class', 'player_controls' );
  84. var btn = document.createElement('div');
  85. btn.setAttribute( 'id', 'btn_play_stop'+wrapperElement.id );
  86. btn.setAttribute( 'onclick', "stop_mjpeg('btn_play_stop"+wrapperElement.id+"');" );
  87. btn.classList.add('pl_ctl_btn');
  88. btn.classList.add('stop_button');
  89. ctlDIV.appendChild(btn);
  90. ran = document.createElement('input');
  91. ran.setAttribute( 'type', "range" );
  92. ran.setAttribute( 'id', 'range_'+wrapperElement.id );
  93. ran.setAttribute( 'step','1');
  94. ran.setAttribute( 'min','0');
  95. ran.setAttribute( 'max', jpegFiles.length );
  96. ran.setAttribute( 'value','0');
  97. ran.setAttribute( 'style','margin-left: 10px;width: 80%;' );
  98. ran.setAttribute( 'oninput', "setpos_mjpeg(this.value);" );
  99. ran.setAttribute( 'onchange', "setpos_s_mjpeg(this.value);" );
  100. ctlDIV.appendChild(ran);
  101. btn = document.createElement('div');
  102. btn.setAttribute( 'id', 'btn_loop'+wrapperElement.id );
  103. btn.setAttribute( 'onclick', "stop_loop_mjpeg('btn_loop"+wrapperElement.id+"');" );
  104. btn.classList.add('pl_ctl_btn');
  105. btn.classList.add('loop');
  106. ctlDIV.appendChild(btn);
  107. dWE.appendChild(ctlDIV);
  108. if (jpegFiles.length > 0) {
  109. if( CONTINUE_PLAY ) setTimeout(function() {
  110. requestAnimationFrame(showNextFrame);
  111. }, 1000/fps);
  112. } else {
  113. alert('Error Loading Video');
  114. };
  115. });
  116. return {
  117. finish: function() {
  118. if (imageElement) {
  119. imageElement.src = '';
  120. wrapperElement.removeChild(imageElement);
  121. imageElement = undefined;
  122. }
  123. },
  124. pause: function(){
  125. CONTINUE_PLAY = false;
  126. },
  127. play: function( fromBegin ){
  128. if(typeof fromBegin === 'number') {
  129. nextFrameIndex = fromBegin;
  130. nextFrameIndex = (nextFrameIndex === jpegFiles.length) ? 0 : nextFrameIndex;
  131. };
  132. CONTINUE_PLAY = true;
  133. setTimeout(function() {
  134. requestAnimationFrame( showNextFrame);
  135. }, 1000/fps);
  136. },
  137. alertInfo: function(){
  138. alert( jpegFiles.length );
  139. }
  140. };
  141. };
  142. // optionally make available as jQuery plugin
  143. if (typeof $ === 'function') {
  144. $.fn.clipchamp_mjpeg_player = function(mjpegUrl, fps, autoloop, callback) {
  145. if (typeof mjpegUrl === 'string') {
  146. if (typeof callback === 'function') {
  147. return this.each(function() {
  148. callback($(this)[0], playMJPEGInternal($(this)[0], mjpegUrl, fps, autoloop));
  149. });
  150. } else {
  151. throw new Error('Callback must be given and must be a function');
  152. }
  153. } else {
  154. throw new Error('MJPEG URL must be a string');
  155. }
  156. }
  157. }
  158. // optionally provide AMD module definition
  159. if (typeof define === 'function') {
  160. define('jquery.clipchamp.mjpeg.player', [], function() {
  161. return {
  162. playMJPEG: function(wrapperElement, mjpegUrl, fps, autoloop) {
  163. if (wrapperElement instanceof Element) {
  164. if (typeof mjpegUrl === 'string') {
  165. return playMJPEGInternal(wrapperElement, mjpegUrl, fps, autoloop);
  166. } else {
  167. throw new Error('MJPEG URL must be a string');
  168. }
  169. } else {
  170. throw new Error('No parent element was given');
  171. }
  172. }
  173. };
  174. });
  175. }
  176. } )
  177. (typeof jQuery === 'function' ? jQuery : undefined);