LiveChannelXmlTest.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace OSS\Tests;
  3. require_once __DIR__ . '/Common.php';
  4. use OSS\Model\LiveChannelInfo;
  5. use OSS\Model\LiveChannelListInfo;
  6. use OSS\Model\LiveChannelConfig;
  7. use OSS\Model\GetLiveChannelStatus;
  8. use OSS\Model\GetLiveChannelHistory;
  9. class LiveChannelXmlTest extends \PHPUnit_Framework_TestCase
  10. {
  11. private $config = <<<BBBB
  12. <?xml version="1.0" encoding="utf-8"?>
  13. <LiveChannelConfiguration>
  14. <Description>xxx</Description>
  15. <Status>enabled</Status>
  16. <Target>
  17. <Type>hls</Type>
  18. <FragDuration>1000</FragDuration>
  19. <FragCount>5</FragCount>
  20. <PlayListName>hello.m3u8</PlayListName>
  21. </Target>
  22. </LiveChannelConfiguration>
  23. BBBB;
  24. private $info = <<<BBBB
  25. <?xml version="1.0" encoding="utf-8"?>
  26. <CreateLiveChannelResult>
  27. <Name>live-1</Name>
  28. <Description>xxx</Description>
  29. <PublishUrls>
  30. <Url>rtmp://bucket.oss-cn-hangzhou.aliyuncs.com/live/213443245345</Url>
  31. </PublishUrls>
  32. <PlayUrls>
  33. <Url>http://bucket.oss-cn-hangzhou.aliyuncs.com/213443245345/播放列表.m3u8</Url>
  34. </PlayUrls>
  35. <Status>enabled</Status>
  36. <LastModified>2015-11-24T14:25:31.000Z</LastModified>
  37. </CreateLiveChannelResult>
  38. BBBB;
  39. private $list = <<<BBBB
  40. <?xml version="1.0" encoding="utf-8"?>
  41. <ListLiveChannelResult>
  42. <Prefix>xxx</Prefix>
  43. <Marker>yyy</Marker>
  44. <MaxKeys>100</MaxKeys>
  45. <IsTruncated>false</IsTruncated>
  46. <NextMarker>121312132</NextMarker>
  47. <LiveChannel>
  48. <Name>12123214323431</Name>
  49. <Description>xxx</Description>
  50. <PublishUrls>
  51. <Url>rtmp://bucket.oss-cn-hangzhou.aliyuncs.com/live/1</Url>
  52. </PublishUrls>
  53. <PlayUrls>
  54. <Url>http://bucket.oss-cn-hangzhou.aliyuncs.com/1/播放列表.m3u8</Url>
  55. </PlayUrls>
  56. <Status>enabled</Status>
  57. <LastModified>2015-11-24T14:25:31.000Z</LastModified>
  58. </LiveChannel>
  59. <LiveChannel>
  60. <Name>432423432423</Name>
  61. <Description>yyy</Description>
  62. <PublishUrls>
  63. <Url>rtmp://bucket.oss-cn-hangzhou.aliyuncs.com/live/2</Url>
  64. </PublishUrls>
  65. <PlayUrls>
  66. <Url>http://bucket.oss-cn-hangzhou.aliyuncs.com/2/播放列表.m3u8</Url>
  67. </PlayUrls>
  68. <Status>enabled</Status>
  69. <LastModified>2016-11-24T14:25:31.000Z</LastModified>
  70. </LiveChannel>
  71. </ListLiveChannelResult>
  72. BBBB;
  73. private $status = <<<BBBB
  74. <?xml version="1.0" encoding="utf-8"?>
  75. <LiveChannelStat>
  76. <Status>Live</Status>
  77. <ConnectedTime>2016-10-20T14:25:31.000Z</ConnectedTime>
  78. <RemoteAddr>10.1.2.4:47745</RemoteAddr>
  79. <Video>
  80. <Width>1280</Width>
  81. <Height>536</Height>
  82. <FrameRate>24</FrameRate>
  83. <Bandwidth>72513</Bandwidth>
  84. <Codec>H264</Codec>
  85. </Video>
  86. <Audio>
  87. <Bandwidth>6519</Bandwidth>
  88. <SampleRate>44100</SampleRate>
  89. <Codec>AAC</Codec>
  90. </Audio>
  91. </LiveChannelStat>
  92. BBBB;
  93. private $history = <<<BBBB
  94. <?xml version="1.0" encoding="utf-8"?>
  95. <LiveChannelHistory>
  96. <LiveRecord>
  97. <StartTime>2013-11-24T14:25:31.000Z</StartTime>
  98. <EndTime>2013-11-24T15:25:31.000Z</EndTime>
  99. <RemoteAddr>10.101.194.148:56861</RemoteAddr>
  100. </LiveRecord>
  101. <LiveRecord>
  102. <StartTime>2014-11-24T14:25:31.000Z</StartTime>
  103. <EndTime>2014-11-24T15:25:31.000Z</EndTime>
  104. <RemoteAddr>10.101.194.148:56862</RemoteAddr>
  105. </LiveRecord>
  106. <LiveRecord>
  107. <StartTime>2015-11-24T14:25:31.000Z</StartTime>
  108. <EndTime>2015-11-24T15:25:31.000Z</EndTime>
  109. <RemoteAddr>10.101.194.148:56863</RemoteAddr>
  110. </LiveRecord>
  111. </LiveChannelHistory>
  112. BBBB;
  113. public function testLiveChannelStatus()
  114. {
  115. $stat = new GetLiveChannelStatus();
  116. $stat->parseFromXml($this->status);
  117. $this->assertEquals('Live', $stat->getStatus());
  118. $this->assertEquals('2016-10-20T14:25:31.000Z', $stat->getConnectedTime());
  119. $this->assertEquals('10.1.2.4:47745', $stat->getRemoteAddr());
  120. $this->assertEquals(1280, $stat->getVideoWidth());
  121. $this->assertEquals(536, $stat->getVideoHeight());
  122. $this->assertEquals(24, $stat->getVideoFrameRate());
  123. $this->assertEquals(72513, $stat->getVideoBandwidth());
  124. $this->assertEquals('H264', $stat->getVideoCodec());
  125. $this->assertEquals(6519, $stat->getAudioBandwidth());
  126. $this->assertEquals(44100, $stat->getAudioSampleRate());
  127. $this->assertEquals('AAC', $stat->getAudioCodec());
  128. }
  129. public function testLiveChannelHistory()
  130. {
  131. $history = new GetLiveChannelHistory();
  132. $history->parseFromXml($this->history);
  133. $recordList = $history->getLiveRecordList();
  134. $this->assertEquals(3, count($recordList));
  135. $list0 = $recordList[0];
  136. $this->assertEquals('2013-11-24T14:25:31.000Z', $list0->getStartTime());
  137. $this->assertEquals('2013-11-24T15:25:31.000Z', $list0->getEndTime());
  138. $this->assertEquals('10.101.194.148:56861', $list0->getRemoteAddr());
  139. $list1 = $recordList[1];
  140. $this->assertEquals('2014-11-24T14:25:31.000Z', $list1->getStartTime());
  141. $this->assertEquals('2014-11-24T15:25:31.000Z', $list1->getEndTime());
  142. $this->assertEquals('10.101.194.148:56862', $list1->getRemoteAddr());
  143. $list2 = $recordList[2];
  144. $this->assertEquals('2015-11-24T14:25:31.000Z', $list2->getStartTime());
  145. $this->assertEquals('2015-11-24T15:25:31.000Z', $list2->getEndTime());
  146. $this->assertEquals('10.101.194.148:56863', $list2->getRemoteAddr());
  147. }
  148. public function testLiveChannelConfig()
  149. {
  150. $config = new LiveChannelConfig(array('name' => 'live-1'));
  151. $config->parseFromXml($this->config);
  152. $this->assertEquals('xxx', $config->getDescription());
  153. $this->assertEquals('enabled', $config->getStatus());
  154. $this->assertEquals('hls', $config->getType());
  155. $this->assertEquals(1000, $config->getFragDuration());
  156. $this->assertEquals(5, $config->getFragCount());
  157. $this->assertEquals('hello.m3u8', $config->getPlayListName());
  158. $xml = $config->serializeToXml();
  159. $config2 = new LiveChannelConfig(array('name' => 'live-2'));
  160. $config2->parseFromXml($xml);
  161. $this->assertEquals('xxx', $config2->getDescription());
  162. $this->assertEquals('enabled', $config2->getStatus());
  163. $this->assertEquals('hls', $config2->getType());
  164. $this->assertEquals(1000, $config2->getFragDuration());
  165. $this->assertEquals(5, $config2->getFragCount());
  166. $this->assertEquals('hello.m3u8', $config2->getPlayListName());
  167. }
  168. public function testLiveChannelInfo()
  169. {
  170. $info = new LiveChannelInfo(array('name' => 'live-1'));
  171. $info->parseFromXml($this->info);
  172. $this->assertEquals('live-1', $info->getName());
  173. $this->assertEquals('xxx', $info->getDescription());
  174. $this->assertEquals('enabled', $info->getStatus());
  175. $this->assertEquals('2015-11-24T14:25:31.000Z', $info->getLastModified());
  176. $pubs = $info->getPublishUrls();
  177. $this->assertEquals(1, count($pubs));
  178. $this->assertEquals('rtmp://bucket.oss-cn-hangzhou.aliyuncs.com/live/213443245345', $pubs[0]);
  179. $plays = $info->getPlayUrls();
  180. $this->assertEquals(1, count($plays));
  181. $this->assertEquals('http://bucket.oss-cn-hangzhou.aliyuncs.com/213443245345/播放列表.m3u8', $plays[0]);
  182. }
  183. public function testLiveChannelList()
  184. {
  185. $list = new LiveChannelListInfo();
  186. $list->parseFromXml($this->list);
  187. $this->assertEquals('xxx', $list->getPrefix());
  188. $this->assertEquals('yyy', $list->getMarker());
  189. $this->assertEquals(100, $list->getMaxKeys());
  190. $this->assertEquals(false, $list->getIsTruncated());
  191. $this->assertEquals('121312132', $list->getNextMarker());
  192. $channels = $list->getChannelList();
  193. $this->assertEquals(2, count($channels));
  194. $chan1 = $channels[0];
  195. $this->assertEquals('12123214323431', $chan1->getName());
  196. $this->assertEquals('xxx', $chan1->getDescription());
  197. $this->assertEquals('enabled', $chan1->getStatus());
  198. $this->assertEquals('2015-11-24T14:25:31.000Z', $chan1->getLastModified());
  199. $pubs = $chan1->getPublishUrls();
  200. $this->assertEquals(1, count($pubs));
  201. $this->assertEquals('rtmp://bucket.oss-cn-hangzhou.aliyuncs.com/live/1', $pubs[0]);
  202. $plays = $chan1->getPlayUrls();
  203. $this->assertEquals(1, count($plays));
  204. $this->assertEquals('http://bucket.oss-cn-hangzhou.aliyuncs.com/1/播放列表.m3u8', $plays[0]);
  205. $chan2 = $channels[1];
  206. $this->assertEquals('432423432423', $chan2->getName());
  207. $this->assertEquals('yyy', $chan2->getDescription());
  208. $this->assertEquals('enabled', $chan2->getStatus());
  209. $this->assertEquals('2016-11-24T14:25:31.000Z', $chan2->getLastModified());
  210. $pubs = $chan2->getPublishUrls();
  211. $this->assertEquals(1, count($pubs));
  212. $this->assertEquals('rtmp://bucket.oss-cn-hangzhou.aliyuncs.com/live/2', $pubs[0]);
  213. $plays = $chan2->getPlayUrls();
  214. $this->assertEquals(1, count($plays));
  215. $this->assertEquals('http://bucket.oss-cn-hangzhou.aliyuncs.com/2/播放列表.m3u8', $plays[0]);
  216. }
  217. }