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