Skip to content

Commit

Permalink
add live channel interface
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertYue19900425 committed Oct 24, 2016
1 parent eb8f8cf commit 8ff611e
Show file tree
Hide file tree
Showing 17 changed files with 908 additions and 31 deletions.
6 changes: 6 additions & 0 deletions config4Test.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
export OSS_ACCESS_KEY_ID=mFuuivpsrtPlLPcT
export OSS_ACCESS_KEY_SECRET=AiiUWXVcAf2I92vkhZg31K9Cx2TTeH
export OSS_ENDPOINT=oss-cn-shenzhen.aliyuncs.com
export OSS_BUCKET=php-sdk-test-bucket-6
echo "done..."
Binary file added samples/.LiveChannel.php.swp
Binary file not shown.
8 changes: 4 additions & 4 deletions samples/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/
final class Config
{
const OSS_ACCESS_ID = '';
const OSS_ACCESS_KEY = '';
const OSS_ENDPOINT = '';
const OSS_TEST_BUCKET = '';
const OSS_ACCESS_ID = 'mFuuivpsrtPlLPcT';
const OSS_ACCESS_KEY = 'AiiUWXVcAf2I92vkhZg31K9Cx2TTeH';
const OSS_ENDPOINT = 'oss-cn-shenzhen.aliyuncs.com';
const OSS_TEST_BUCKET = 'yueqiankun-rtmp';
}
89 changes: 89 additions & 0 deletions samples/LiveChannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
require_once __DIR__ . '/Common.php';

use OSS\OssClient;
use OSS\Core\OssException;
use OSS\Model\LiveChannelConfig;

$bucket = Common::getBucketName();
$ossClient = Common::getOssClient();
if (is_null($ossClient)) exit(1);

//******************************* 简单使用 *******************************************************

//putLiveChannel
$config = new LiveChannelConfig(array(
'name' => 'live-1',
'description' => 'live channel 1',
'type' => 'HLS',
'fragDuration' => 10,
'fragCount' => 5,
'playListName' => 'hello'
));
$info = $ossClient->putBucketLiveChannel($bucket, $config);
Common::println("bucket $bucket liveChannel created:\n" .
"live channel name: ". $info->getName() . "\n" .
"live channel description: ". $info->getDescription() . "\n" .
"publishurls: ". $info->getPublishUrls()[0] . "\n" .
"playurls: ". $info->getPlayUrls()[0] . "\n");

//listLiveChannel
$list = $ossClient->listBucketLiveChannels($bucket);
Common::println("bucket $bucket listLiveChannel:\n" .
"list live channel prefix: ". $list->getPrefix() . "\n" .
"list live channel marker: ". $list->getMarker() . "\n" .
"list live channel maxkey: ". $list->getMaxKeys() . "\n" .
"list live channel IsTruncated: ". $list->getIsTruncated() . "\n" .
"list live channel getNextMarker: ". $list->getNextMarker() . "\n" .
"list live channel list: ". $list->getChannelList()[0]->getName() . "\n");

//getLiveChannelUrl
$url = $ossClient->getLiveChannelUrl($bucket, "live-1");
Common::println("bucket $bucket rtmp url: \n" . $url);

//putLiveChannelStatus
$resp = $ossClient->putLiveChannelStatus($bucket, "live-1", "enabled");

//getLiveChannelInfo
$info = $ossClient->getLiveChannelInfo($bucket, 'live-1');
Common::println("bucket $bucket listLiveChannel:\n" .
"live channel info description: ". $info->getDescription() . "\n" .
"live channel info status: ". $info->getStatus() . "\n" .
"live channel info type: ". $info->getType() . "\n" .
"live channel info fragDuration: ". $info->getFragDuration() . "\n" .
"live channel info fragCount: ". $info->getFragCount() . "\n" .
"live channel info playListName: ". $info->getPlayListName() . "\n");

//getLiveChannelHistory
$history = $ossClient->getLiveChannelHistory($bucket, "live-1");
if (count($history->getLiveRecordList()) != 0)
{
Common::println("bucket $bucket liveChannelHistory:\n" .
"live channel history startTime: ". $history->getLiveRecordList()[0]->getStartTime() . "\n" .
"live channel history endTime: ". $history->getLiveRecordList()[0]->getEndTime() . "\n" .
"live channel history remoteAddr: ". $history->getLiveRecordList()[0]->getRemoteAddr() . "\n");
}

//getLiveChannelStatus
$status = $ossClient->getLiveChannelStatus($bucket, "live-1");
Common::println("bucket $bucket listLiveChannel:\n" .
"live channel status status: ". $status->getStatus() . "\n" .
"live channel status ConnectedTime: ". $status->getConnectedTime() . "\n" .
"live channel status VideoWidth: ". $status->getVideoWidth() . "\n" .
"live channel status VideoHeight: ". $status->getVideoHeight() . "\n" .
"live channel status VideoFrameRate: ". $status->getVideoFrameRate() . "\n" .
"live channel status VideoBandwidth: ". $status->getVideoBandwidth() . "\n" .
"live channel status VideoCodec: ". $status->getVideoCodec() . "\n" .
"live channel status AudioBandwidth: ". $status->getAudioBandwidth() . "\n" .
"live channel status AudioSampleRate: ". $status->getAudioSampleRate() . "\n" .
"live channel status AdioCodec: ". $status->getAudioCodec() . "\n");

//postVodPlaylist
$info = $ossClient->postVodPlaylist($bucket,
"live-1", "playback.m3u8",
array('StartTime' => '1476844172',
'EndTime' => '1476864172')
);

//deleteLiveChannel
$info = $ossClient->deleteBucketLiveChannel($bucket, "live-1");
1 change: 1 addition & 0 deletions samples/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ function listAllObjects($ossClient, $bucket)
printf($e->getMessage() . "\n");
return;
}
print("\n***********\n");
// 得到nextMarker,从上一次listObjects读到的最后一个文件的下一个文件开始继续获取文件列表
$nextMarker = $listObjectInfo->getNextMarker();
$listObject = $listObjectInfo->getObjectList();
Expand Down
48 changes: 48 additions & 0 deletions samples/test4Url.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
require_once __DIR__ . '/Common.php';

use OSS\OssClient;
use OSS\Core\OssException;
use OSS\Model\LiveChannelConfig;

$bucket = Common::getBucketName();
$ossClient = Common::getOssClient();
if (is_null($ossClient)) exit(1);

//******************************* 简单使用 *******************************************************

//putLiveChannel
$config = new LiveChannelConfig(array(
'name' => 'live-1',
'description' => 'live channel 1',
'type' => 'HLS',
'fragDuration' => 10,
'fragCount' => 5,
'playListName' => 'hello'
));
$info = $ossClient->putBucketLiveChannel($bucket, $config);
Common::println("bucket $bucket liveChannel created:\n" .
"live channel name: ". $info->getName() . "\n" .
"live channel description: ". $info->getDescription() . "\n" .
"publishurls: ". $info->getPublishUrls()[0] . "\n" .
"playurls: ". $info->getPlayUrls()[0] . "\n");

//listLiveChannel
$list = $ossClient->listBucketLiveChannels($bucket);
Common::println("bucket $bucket listLiveChannel:\n" .
"list live channel prefix: ". $list->getPrefix() . "\n" .
"list live channel marker: ". $list->getMarker() . "\n" .
"list live channel maxkey: ". $list->getMaxKeys() . "\n" .
"list live channel IsTruncated: ". $list->getIsTruncated() . "\n" .
"list live channel getNextMarker: ". $list->getNextMarker() . "\n" .
"list live channel count: ". count($list->getChannelList()) . "\n" .
"list live channel list: ". $list->getChannelList()[0]->getName() . "\n");

//getLiveChannelUrl
$url = $ossClient->getLiveChannelUrl($bucket, "live-1");
Common::println("bucket $bucket rtmp url: \n" . $url);

system(" sudo ffmpeg \-re \-i ./allstar.flv \-c copy \-f flv \"$url\" ");

//deleteLiveChannel
$info = $ossClient->deleteBucketLiveChannel($bucket, "live-1");
35 changes: 35 additions & 0 deletions src/OSS/Model/GetLiveChannelHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace OSS\Model;
/**
* Class GetLiveChannelHistory
* @package OSS\Model
*
*/
class GetLiveChannelHistory implements XmlConfig
{
private $liveRecordList = array();

public function getLiveRecordList()
{
return $this->liveRecordList;
}

public function parseFromXml($strXml)
{
$xml = simplexml_load_string($strXml);

if (isset($xml->LiveRecord)) {
foreach ($xml->LiveRecord as $record) {
$liveRecord = new LiveChannelHistory();
$liveRecord->parseFromXmlNode($record);
$this->liveRecordList[] = $liveRecord;
}
}
}

public function serializeToXml()
{
throw new OssException("Not implemented.");
}
}
69 changes: 69 additions & 0 deletions src/OSS/Model/GetLiveChannelInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace OSS\Model;
/**
* Class GetLiveChannelInfo
* @package OSS\Model
*
*/
class GetLiveChannelInfo implements XmlConfig
{
private $description;
private $status;
private $type;
private $fragDuration;
private $fragCount;
private $playlistName;

public function getDescription()
{
return $this->description;
}

public function getStatus()
{
return $this->status;
}

public function getType()
{
return $this->type;
}

public function getFragDuration()
{
return $this->fragDuration;
}

public function getFragCount()
{
return $this->fragCount;
}

public function getPlayListName()
{
return $this->playlistName;
}

public function parseFromXml($strXml)
{
$xml = simplexml_load_string($strXml);

$this->description = strval($xml->Description);
$this->status = strval($xml->Status);

if (isset($xml->Target)) {
foreach ($xml->Target as $target) {
$this->type = strval($target->Type);
$this->fragDuration = strval($target->FragDuration);
$this->fragCount = strval($target->FragCount);
$this->playlistName = strval($target->PlaylistName);
}
}
}

public function serializeToXml()
{
throw new OssException("Not implemented.");
}
}
107 changes: 107 additions & 0 deletions src/OSS/Model/GetLiveChannelStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace OSS\Model;
/**
* Class GetLiveChannelStatus
* @package OSS\Model
*
*/
class GetLiveChannelStatus implements XmlConfig
{
private $status;
private $connectedTime;
private $remoteAddr;


private $videoWidth;
private $videoHeight;
private $videoFrameRate;
private $videoBandwidth;
private $videoCodec;

private $audioBandwidth;
private $audioSampleRate;
private $audioCodec;

public function getStatus()
{
return $this->status;
}

public function getConnectedTime()
{
return $this->connectedTime;
}

public function getRemoteAddr()
{
return $this->remoteAddr;
}

public function getVideoWidth()
{
return $this->videoWidth;
}
public function getVideoHeight()
{
return $this->videoHeight;
}
public function getVideoFrameRate()
{
return $this->videoFrameRate;
}
public function getVideoBandwidth()
{
return $this->videoBandwidth;
}
public function getVideoCodec()
{
return $this->videoCodec;
}

public function getAudioBandwidth()
{
return $this->audioBandwidth;
}
public function getAudioSampleRate()
{
return $this->audioSampleRate;
}
public function getAudioCodec()
{
return $this->audioCodec;
}


public function parseFromXml($strXml)
{
$xml = simplexml_load_string($strXml);
$this->status = strval($xml->Status);
$this->connectedTime = strval($xml->ConnectedTime);
$this->remoteAddr = strval($xml->RemoteAddr);

if (isset($xml->Video)) {
foreach ($xml->Video as $video) {
$this->videoWidth = intval($video->Width);
$this->videoHeight = intval($video->Height);
$this->videoFrameRate = intval($video->FrameRate);
$this->videoBandwidth = intval($video->Bandwidth);
$this->videoCodec = strval($video->Codec);
}
}

if (isset($xml->Video)) {
foreach ($xml->Audio as $audio) {
$this->audioBandwidth = intval($audio->Bandwidth);
$this->audioSampleRate = intval($audio->SampleRate);
$this->audioCodec = strval($audio->Codec);
}
}

}

public function serializeToXml()
{
throw new OssException("Not implemented.");
}
}

0 comments on commit 8ff611e

Please sign in to comment.