123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace Live\Lib;
- use Dever;
- Dever::apply('sdk/qiniu', 'live');
- class Qiniu
- {
- private $stream;
- private $config;
- private $space;
-
- public function __construct($config)
- {
- $this->config = $config;
- $mac = new \Qiniu\Pili\Mac($this->config['appkey'], $this->config['appsecret']);
- $client = new \Qiniu\Pili\Client($mac);
- $this->space = $client->hub($this->config['space']);
- }
-
- public function create($name)
- {
- $result = $this->space->create($name);
- return $this->getInfo($name);
- }
-
- public function get($name)
- {
- if (!$this->stream) {
- $this->stream = $this->space->stream($name);
- }
- return $this->stream;
- }
-
- public function getInfo($name)
- {
- $stream = $this->get($name);
- return $stream->info();
- }
-
- public function getLiveStatus($name)
- {
- $stream = $this->get($name);
- return $stream->liveStatus();
- }
-
- public function gets($prefix = '', $limit = 10000)
- {
- return $this->space->listStreams($prefix, $limit, '');
- }
-
- public function getLives($prefix = '', $limit = 10000)
- {
- return $this->space->listLiveStreams($prefix, $limit, '');
- }
-
- public function start($name = '')
- {
- $stream = $this->get($name);
- $stream->enable();
- return $this->getLiveStatus($name);
- }
-
- public function stop($name = '', $num = 120)
- {
- $stream = $this->get($name);
- $stream->disable(time() + $num);
- return $this->getLiveStatus($name);
- }
-
- public function save($name, $start, $end)
- {
- $stream = $this->get($name);
- return $stream->saveas(array("format" => "mp4"), $start, $end);
- }
-
- public function savePic($name)
- {
- $stream = $this->get($name);
- return $stream->snapshot(array("format" => "jpg"));
- }
-
- public function history($name)
- {
- $stream = $this->get($name);
- return $stream->historyActivity(0, 0);
- }
-
- public function update($name, $convert)
- {
- $stream = $this->get($name);
- $stream->updateConverts($convert);
- return $stream->info();
- }
-
- public function getRtmp($name, $time = 3600)
- {
- $url = \Qiniu\Pili\RTMPPublishURL("publish-rtmp.test.com", $this->config['space'], $name, 3600, $this->config['appkey'], $this->config['appsecret']);
- return $url;
- }
-
- public function getPlay($name)
- {
-
- $url['rtmp'] = $this->getRtmpPlay($name);
- $url['hls'] = $this->getHlsPlay($name);
- $url['hdl'] = $this->getHdlPlay($name);
- $url['pic'] = $this->getPicPlay($name);
- return $url;
- }
-
- public function getRtmpPlay($name)
- {
- $url = \Qiniu\Pili\RTMPPlayURL("live-rtmp.test.com", $this->config['space'], $name);
- return $url;
- }
-
- public function getHlsPlay($name)
- {
- $url = \Qiniu\Pili\HLSPlayURL("live-hls.test.com", $this->config['space'], $name);
- return $url;
- }
-
- public function getHdlPlay($name)
- {
- $url = \Qiniu\Pili\HDLPlayURL("live-hdl.test.com", $this->config['space'], $name);
- return $url;
- }
-
- public function getPicPlay($name)
- {
- $url = \Qiniu\Pili\SnapshotPlayURL("live-snapshot.test.com", $this->config['space'], $name);
- return $url;
- }
- }
|