PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/package/app/app/infra/cdl/kdl/KDLMediaInfoLoader.php

https://bitbucket.org/pandaos/kaltura
PHP | 241 lines | 186 code | 11 blank | 44 comment | 28 complexity | c0cc70e3889d33b32e5d4a0c6eab2852 MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-2.0, LGPL-3.0, JSON, MPL-2.0-no-copyleft-exception, Apache-2.0
  1. <?php
  2. include_once("StringTokenizer.php");
  3. include_once("KDLMediaDataSet.php");
  4. include_once 'KDLUtils.php';
  5. /* ---------------------------
  6. * KDLMediaInfoLoader
  7. */
  8. class KDLMediaInfoLoader extends StringTokenizer {
  9. public function __construct(/*string*/ $str) {
  10. parent::__construct($str, "\t\n");
  11. }
  12. public function __destruct() {
  13. unset($this);
  14. }
  15. /* .........................
  16. * Load
  17. */
  18. function Load(&$dataSet) {
  19. $fieldCnt=0;
  20. $streamsCnt = 0;
  21. $streamsColStr = null;
  22. $section = "general";
  23. $sectionID = 0;
  24. while ($this->hasMoreTokens()) {
  25. $tok = strtolower(trim($this->nextToken()));
  26. if(strrpos($tok, ":") == false){
  27. $sectionID = strchr($tok,"#");
  28. if($sectionID) {
  29. $sectionID = trim($sectionID,"#");
  30. }
  31. else
  32. $sectionID = 0;
  33. if(strstr($tok,"general")==true)
  34. $section = "general";
  35. else if(strstr($tok,KDLConstants::VideoIndex)==true)
  36. $section = KDLConstants::VideoIndex;
  37. else if(strstr($tok,KDLConstants::AudioIndex)==true)
  38. $section = KDLConstants::AudioIndex;
  39. else if(strstr($tok,KDLConstants::ImageIndex)==true)
  40. $section = KDLConstants::ImageIndex;
  41. else
  42. $section = $tok;
  43. $streamsCnt++;
  44. if($streamsColStr===null)
  45. $streamsColStr = $tok;
  46. else
  47. $streamsColStr = $streamsColStr.",".$tok;
  48. }
  49. else if($sectionID<=1) {
  50. $key = trim(substr($tok, 0, strpos($tok, ":")) );
  51. $val = trim(substr(strstr($tok, ":"),1));
  52. switch($section) {
  53. case "general":
  54. $this->loadContainerSet($dataSet->_container, $key, $val);
  55. break;
  56. case KDLConstants::VideoIndex:
  57. $this->loadVideoSet($dataSet->_video, $key, $val);
  58. break;
  59. case KDLConstants::ImageIndex:
  60. $this->loadVideoSet($dataSet->_image, $key, $val);
  61. break;
  62. case KDLConstants::AudioIndex:
  63. $this->loadAudioSet($dataSet->_audio, $key, $val);
  64. break;
  65. }
  66. $fieldCnt++;
  67. }
  68. }
  69. if($dataSet->_container!=null){
  70. $streamsColStr = "1+".$streamsCnt.":".$streamsColStr;
  71. }
  72. else
  73. $streamsColStr = "0+".$streamsCnt.":".$streamsColStr;
  74. $dataSet->_streamsCollectionStr = $streamsColStr;
  75. kLog::log("StreamsColStr- ".$dataSet->_streamsCollectionStr);
  76. }
  77. /* ------------------------------
  78. * loadAudioSet
  79. */
  80. private function loadAudioSet(&$audioData, $key, $val) {
  81. if($audioData=="")
  82. $audioData = new KDLAudioData();
  83. switch($key) {
  84. case "channel(s)":
  85. $audioData->_channels = KDLUtils::trima($val);
  86. settype($audioData->_channels, "integer");
  87. break;
  88. case "sampling rate":
  89. $audioData->_sampleRate = KDLUtils::trima($val);
  90. settype($audioData->_sampleRate, "float");
  91. if($audioData->_sampleRate<1000)
  92. $audioData->_sampleRate *= 1000;
  93. break;
  94. case "resolution":
  95. $audioData->_resolution = KDLUtils::trima($val);
  96. settype($audioData->_resolution, "integer");
  97. break;
  98. default:
  99. $this->loadBaseSet($audioData, $key, $val);
  100. break;
  101. }
  102. }
  103. /* .........................
  104. * loadVideoSet
  105. */
  106. private function loadVideoSet(&$videoData, $key, $val) {
  107. if($videoData=="")
  108. $videoData = new KDLVideoData();
  109. switch($key) {
  110. case "width":
  111. $videoData->_width = KDLUtils::trima($val);
  112. settype($videoData->_width, "integer");
  113. break;
  114. case "height":
  115. $videoData->_height = KDLUtils::trima($val);
  116. settype($videoData->_height, "integer");
  117. break;
  118. case "frame rate":
  119. $videoData->_frameRate = KDLUtils::trima($val);
  120. settype($videoData->_frameRate, "float");
  121. break;
  122. case "display aspect ratio":
  123. $val = KDLUtils::trima($val);
  124. if(strstr($val, ":")==true){
  125. $darW = trim(substr($val, 0, strpos($val, ":")) );
  126. $darH = trim(substr(strstr($val, ":"),1));
  127. if($darH>0)
  128. $videoData->_dar = $darW/$darH;
  129. else
  130. $videoData->_dar = null;
  131. }
  132. else if(strstr($val, "/")==true){
  133. $darW = trim(substr($val, 0, strpos($val, "/")));
  134. $darH = trim(substr(strstr($val, "/"),1));
  135. if($darW>0)
  136. $videoData->_dar = $darW/$darH;
  137. else
  138. $videoData->_dar = null;
  139. }
  140. else if($val) {
  141. $videoData->_dar = (float)$val;
  142. }
  143. /*
  144. $val = $this->trima($val);
  145. if(strstr($val, ":")==true){
  146. $darW = trim(substr($val, 0, strpos($val, ":")));
  147. $darH = trim(substr(strstr($val, ":"),1));
  148. if($darW>0)
  149. $mediaInfo->videoDar = $darW / $darH;
  150. else
  151. $mediaInfo->videoDar = null;
  152. }
  153. else if(strstr($val, "/")==true){
  154. $darW = trim(substr($val, 0, strpos($val, "/")));
  155. $darH = trim(substr(strstr($val, "/"),1));
  156. if($darW>0)
  157. $mediaInfo->videoDar = $darW / $darH;
  158. else
  159. $mediaInfo->videoDar = null;
  160. }
  161. else if($val) {
  162. $mediaInfo->videoDar = (float)$val;
  163. }
  164. break;
  165. */
  166. break;
  167. case "rotation":
  168. $videoData->_rotation = KDLUtils::trima($val);
  169. settype($videoData->_rotation, "integer");
  170. break;
  171. case "scan type":
  172. $scanType = KDLUtils::trima($val);
  173. if($scanType!="progressive") {
  174. $videoData->_scanType=1;
  175. }
  176. else {
  177. $videoData->_scanType=0;
  178. }
  179. // settype($videoData->_rotation, "integer");
  180. break;
  181. default:
  182. $this->loadBaseSet($videoData, $key, $val);
  183. break;
  184. }
  185. }
  186. /* .........................
  187. * loadContainerSet
  188. */
  189. private function loadContainerSet(&$containerData, $key, $val) {
  190. if($containerData=="")
  191. $containerData = new KDLContainerData();
  192. switch($key) {
  193. case "file size":
  194. $containerData->_fileSize = KDLUtils::convertValue2kbits(KDLUtils::trima($val));
  195. break;
  196. case "complete name":
  197. $containerData->_fileName = $val;
  198. break;
  199. default:
  200. $this->loadBaseSet($containerData, $key, $val);
  201. break;
  202. }
  203. }
  204. // .........................
  205. // loadBaseSet
  206. //
  207. private function loadBaseSet(&$baseData, $key, $val)
  208. {
  209. switch($key) {
  210. case "codec id":
  211. $baseData->_id = $val;
  212. break;
  213. case "format":
  214. $baseData->_format = $val;
  215. break;
  216. case "duration":
  217. $baseData->_duration = KDLUtils::convertDuration2msec($val);
  218. break;
  219. case "bit rate":
  220. $baseData->_bitRate = KDLUtils::convertValue2kbits(KDLUtils::trima($val));
  221. break;
  222. default:
  223. //echo "<br>". "key=". $key . " val=" . $val . "<br>";
  224. $baseData->_params[$key] = $val;
  225. break;
  226. }
  227. }
  228. }
  229. ?>