Skip to content

Commit

Permalink
modify by comment
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertYue19900425 committed Nov 3, 2016
1 parent 2e32cbd commit 80c1a12
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 223 deletions.
73 changes: 73 additions & 0 deletions samples/Image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
require_once __DIR__ . '/Common.php';

use OSS\OssClient;
use OSS\Core\OssException;

$bucketName = Common::getBucketName();
$object = "example.jpg";
$ossClient = Common::getOssClient();
$download_file = "download.jpg";
if (is_null($ossClient)) exit(1);
//*******************************简单使用***************************************************************

$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
'x-oss-process' => "image/resize,m_fixed,h_100,w_100", );
$ossClient->getObject($bucketName, $object, $options);
printImage("imageResize",$download_file);

$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
'x-oss-process' => "image/crop,w_100,h_100,x_100,y_100,r_1", );
$ossClient->getObject($bucketName, $object, $options);
printImage("iamgeCrop", $download_file);

$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
'x-oss-process' => "image/rotate,90", );
$ossClient->getObject($bucketName, $object, $options);
printImage("imageRotate", $download_file);

$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
'x-oss-process' => "image/sharpen,100", );
$ossClient->getObject($bucketName, $object, $options);
printImage("imageSharpen", $download_file);

$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
'x-oss-process' => "image/watermark,text_SGVsbG8g5Zu-54mH5pyN5YqhIQ", );
$ossClient->getObject($bucketName, $object, $options);
printImage("imageWatermark", $download_file);

$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
'x-oss-process' => "image/format,png", );
$ossClient->getObject($bucketName, $object, $options);
printImage("imageFormat", $download_file);

$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
'x-oss-process' => "image/resize,m_fixed,w_100,h_100", );
$ossClient->getObject($bucketName, $object, $options);
printImage("imageTofile", $download_file);

/**
生成一个带签名的可用于浏览器直接打开的url, URL的有效期是3600秒
*/
$timeout = 3600;
$options = array(
'x-oss-process' => "image/resize,m_lfit,h_100,w_100",
);
$signedUrl = $ossClient->signUrl($bucketName, $object, $timeout, "GET", $options);
Common::println("bucket $bucket rtmp url: \n" . $signedUrl);

function printImage($func, $imageFile)
{
$array = getimagesize($imageFile);
Common::println("$func, image width: " . $array[0]);
Common::println("$func, image height: " . $array[1]);
Common::println("$func, image type: " . ($array[2] === 2 ? 'jpg' : 'png'));
Common::println("$func, image size: " . ceil(filesize($imageFile)));
}
73 changes: 44 additions & 29 deletions samples/LiveChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
//******************************* 简单使用 *******************************************************

/**
putLiveChannel
创建一个直播频道
频道的名称是test_rtmp_live。直播生成的m3u8文件叫做test.m3u8,该索引文件包含3片ts文件,每片ts文件的时长为5秒(这只是一个建议值,具体的时长取决于关键帧)。
*/
$config = new LiveChannelConfig(array(
'name' => 'live-1',
'description' => 'live channel 1',
'name' => 'test_rtmp_live',
'description' => 'live channel test',
'type' => 'HLS',
'fragDuration' => 10,
'fragCount' => 5,
Expand All @@ -30,7 +31,9 @@
"playurls: ". $info->getPlayUrls()[0] . "\n");

/**
listLiveChannel
对创建好的频道,可以使用listBucketLiveChannels来进行列举已达到管理的目的。
prefix可以按照前缀过滤list出来的频道。
max_keys表示迭代器内部一次list出来的频道的最大数量,这个值最大不能超过1000,不填写的话默认为100。
*/
$list = $ossClient->listBucketLiveChannels($bucket);
Common::println("bucket $bucket listLiveChannel:\n" .
Expand All @@ -41,21 +44,21 @@
"list live channel getNextMarker: ". $list->getNextMarker() . "\n" .
"list live channel list: ". $list->getChannelList()[0]->getName() . "\n");

/**getLiveChannelUrl
/**
创建直播频道之后拿到推流用的play_url(rtmp推流的url,如果Bucket不是公共读写权限那么还需要带上签名,见下文示例)和观流用的publish_url(推流产生的m3u8文件的url)
*/
$url = $ossClient->getLiveChannelUrl($bucket, "live-1");
Common::println("bucket $bucket rtmp url: \n" . $url);
$play_url = $ossClient->signRtmpUrl($bucket, "test_rtmp_live");
Common::println("bucket $bucket rtmp url: \n" . $play_url);

/**
putLiveChannelStatus
创建好直播频道,如果想把这个频道禁用掉(断掉正在推的流或者不再允许向一个地址推流),应该使用putLiveChannelStatus接口,将频道的status改成“disabled”,如果要将一个禁用状态的频道启用,那么也是调用这个接口,将status改成“enabled”
*/
$resp = $ossClient->putLiveChannelStatus($bucket, "live-1", "enabled");
$resp = $ossClient->putLiveChannelStatus($bucket, "test_rtmp_live", "enabled");

/**
getLiveChannelInfo
创建好直播频道之后调用getLiveChannelInfo可以得到频道相关的信息
*/
$info = $ossClient->getLiveChannelInfo($bucket, 'live-1');
$info = $ossClient->getLiveChannelInfo($bucket, 'test_rtmp_live');
Common::println("bucket $bucket listLiveChannel:\n" .
"live channel info description: ". $info->getDescription() . "\n" .
"live channel info status: ". $info->getStatus() . "\n" .
Expand All @@ -65,21 +68,31 @@
"live channel info playListName: ". $info->getPlayListName() . "\n");

/**
getLiveChannelHistory
如果想查看一个频道历史推流记录,可以调用getLiveChannelHistory。目前最多可以看到10次推流的记录
*/
$history = $ossClient->getLiveChannelHistory($bucket, "live-1");
$history = $ossClient->getLiveChannelHistory($bucket, "test_rtmp_live");
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");
foreach($history->getLiveRecordList() as $recordList)
{
Common::println("bucket $bucket liveChannelHistory:\n" .
"live channel history startTime: ". $revordList->getStartTime() . "\n" .
"live channel history endTime: ". $recordList->getEndTime() . "\n" .
"live channel history remoteAddr: ". $recordList->getRemoteAddr() . "\n");
}

//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
对于正在推流的频道调用get_live_channel_stat可以获得流的状态信息。
如果频道正在推流,那么stat_result中的所有字段都有意义。
如果频道闲置或者处于“disabled”状态,那么status为“Idle”或“Disabled”,其他字段无意义。
*/
$status = $ossClient->getLiveChannelStatus($bucket, "live-1");
$status = $ossClient->getLiveChannelStatus($bucket, "test_rtmp_live");
Common::println("bucket $bucket listLiveChannel:\n" .
"live channel status status: ". $status->getStatus() . "\n" .
"live channel status ConnectedTime: ". $status->getConnectedTime() . "\n" .
Expand All @@ -93,16 +106,18 @@
"live channel status AdioCodec: ". $status->getAudioCodec() . "\n");

/**
postVodPlaylist
依赖ts文件,必须先推流
如果希望利用直播推流产生的ts文件生成一个点播列表,可以使用postVodPlaylist方法。
指定起始时间为当前时间减去60秒,结束时间为当前时间,这意味着将生成一个长度为60秒的点播视频。
播放列表指定为“vod_playlist.m3u8”,也就是说这个接口调用成功之后会在OSS上生成一个名叫“vod_playlist.m3u8”的播放列表文件。
*/
/*$info = $ossClient->postVodPlaylist($bucket,
"live-1", "playback.m3u8",
array('StartTime' => '1476844172',
'EndTime' => '1476864172')
$current_time = time();
$info = $ossClient->postVodPlaylist($bucket,
"test_rtmp_live", "vod_playlist.m3u8",
array('StartTime' => $current_time - 60,
'EndTime' => $current_time)
);
*/

/**
deleteLiveChannel
如果一个直播频道已经不打算再使用了,那么可以调用delete_live_channel来删除频道。
*/
$info = $ossClient->deleteBucketLiveChannel($bucket, "live-1");
$info = $ossClient->deleteBucketLiveChannel($bucket, "test_rtmp_live");
7 changes: 3 additions & 4 deletions src/OSS/Model/GetLiveChannelHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
/**
* Class GetLiveChannelHistory
* @package OSS\Model
*
*/
class GetLiveChannelHistory implements XmlConfig
{
private $liveRecordList = array();

public function getLiveRecordList()
public function getLiveRecordList()
{
return $this->liveRecordList;
}
Expand All @@ -32,4 +29,6 @@ public function serializeToXml()
{
throw new OssException("Not implemented.");
}

private $liveRecordList = array();
}
15 changes: 7 additions & 8 deletions src/OSS/Model/GetLiveChannelInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@
/**
* 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;
Expand Down Expand Up @@ -66,4 +58,11 @@ public function serializeToXml()
{
throw new OssException("Not implemented.");
}

private $description;
private $status;
private $type;
private $fragDuration;
private $fragCount;
private $playlistName;
}
32 changes: 16 additions & 16 deletions src/OSS/Model/GetLiveChannelStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,9 @@
/**
* 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;
Expand Down Expand Up @@ -104,4 +88,20 @@ public function serializeToXml()
{
throw new OssException("Not implemented.");
}

private $status;
private $connectedTime;
private $remoteAddr;

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

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


}
16 changes: 8 additions & 8 deletions src/OSS/Model/LiveChannelConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
*/
class LiveChannelConfig implements XmlConfig
{
private $name;
private $description;
private $status;
private $type;
private $fragDuration;
private $fragCount;
private $playListName;

public function __construct($option = array())
{
if (isset($option['name'])) {
Expand Down Expand Up @@ -132,4 +124,12 @@ public function __toString()
{
return $this->serializeToXml();
}

private $name;
private $description;
private $status = "enabled";
private $type;
private $fragDuration = 5;
private $fragCount = 3;
private $playListName = "playlist.m3u8";
}
8 changes: 4 additions & 4 deletions src/OSS/Model/LiveChannelHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
*/
class LiveChannelHistory implements XmlConfig
{
private $startTime;
private $endTime;
private $remoteAddr;

public function __construct()
{
}
Expand Down Expand Up @@ -56,4 +52,8 @@ public function serializeToXml()
{
throw new OssException("Not implemented.");
}

private $startTime;
private $endTime;
private $remoteAddr;
}
14 changes: 7 additions & 7 deletions src/OSS/Model/LiveChannelInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
*/
class LiveChannelInfo implements XmlConfig
{
private $name;
private $description;
private $publishUrls;
private $playUrls;
private $status;
private $lastModified;

public function __construct($name = null, $description = null)
{
$this->name = $name;
Expand Down Expand Up @@ -104,4 +97,11 @@ public function serializeToXml()
{
throw new OssException("Not implemented.");
}

private $name;
private $description;
private $publishUrls;
private $playUrls;
private $status;
private $lastModified;
}
Loading

0 comments on commit 80c1a12

Please sign in to comment.