From 80c1a1245a8b86a3b96ac9a12bf9829975834a07 Mon Sep 17 00:00:00 2001 From: "qiankun.yqk" Date: Thu, 3 Nov 2016 14:19:22 +0800 Subject: [PATCH] modify by comment --- samples/Image.php | 73 +++++++++++ samples/LiveChannel.php | 73 ++++++----- src/OSS/Model/GetLiveChannelHistory.php | 7 +- src/OSS/Model/GetLiveChannelInfo.php | 15 +-- src/OSS/Model/GetLiveChannelStatus.php | 32 ++--- src/OSS/Model/LiveChannelConfig.php | 16 +-- src/OSS/Model/LiveChannelHistory.php | 8 +- src/OSS/Model/LiveChannelInfo.php | 14 +- src/OSS/Model/LiveChannelListInfo.php | 17 ++- src/OSS/OssClient.php | 27 ++-- tests/OSS/Tests/BucketLiveChannelTest.php | 149 ++++------------------ 11 files changed, 208 insertions(+), 223 deletions(-) create mode 100644 samples/Image.php diff --git a/samples/Image.php b/samples/Image.php new file mode 100644 index 00000000..410fca84 --- /dev/null +++ b/samples/Image.php @@ -0,0 +1,73 @@ + $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))); +} diff --git a/samples/LiveChannel.php b/samples/LiveChannel.php index 10d60d15..3f4af28b 100644 --- a/samples/LiveChannel.php +++ b/samples/LiveChannel.php @@ -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, @@ -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" . @@ -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" . @@ -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" . @@ -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"); diff --git a/src/OSS/Model/GetLiveChannelHistory.php b/src/OSS/Model/GetLiveChannelHistory.php index 7b7abaaf..6643444a 100644 --- a/src/OSS/Model/GetLiveChannelHistory.php +++ b/src/OSS/Model/GetLiveChannelHistory.php @@ -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; } @@ -32,4 +29,6 @@ public function serializeToXml() { throw new OssException("Not implemented."); } + + private $liveRecordList = array(); } diff --git a/src/OSS/Model/GetLiveChannelInfo.php b/src/OSS/Model/GetLiveChannelInfo.php index 2cb2f38b..0b5edfc4 100644 --- a/src/OSS/Model/GetLiveChannelInfo.php +++ b/src/OSS/Model/GetLiveChannelInfo.php @@ -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; @@ -66,4 +58,11 @@ public function serializeToXml() { throw new OssException("Not implemented."); } + + private $description; + private $status; + private $type; + private $fragDuration; + private $fragCount; + private $playlistName; } diff --git a/src/OSS/Model/GetLiveChannelStatus.php b/src/OSS/Model/GetLiveChannelStatus.php index a0b1f94b..2ee7a68b 100644 --- a/src/OSS/Model/GetLiveChannelStatus.php +++ b/src/OSS/Model/GetLiveChannelStatus.php @@ -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; @@ -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; + + } diff --git a/src/OSS/Model/LiveChannelConfig.php b/src/OSS/Model/LiveChannelConfig.php index 6c126d8b..0dc69a3a 100644 --- a/src/OSS/Model/LiveChannelConfig.php +++ b/src/OSS/Model/LiveChannelConfig.php @@ -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'])) { @@ -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"; } diff --git a/src/OSS/Model/LiveChannelHistory.php b/src/OSS/Model/LiveChannelHistory.php index ed166bd8..1c1fd4db 100644 --- a/src/OSS/Model/LiveChannelHistory.php +++ b/src/OSS/Model/LiveChannelHistory.php @@ -8,10 +8,6 @@ */ class LiveChannelHistory implements XmlConfig { - private $startTime; - private $endTime; - private $remoteAddr; - public function __construct() { } @@ -56,4 +52,8 @@ public function serializeToXml() { throw new OssException("Not implemented."); } + + private $startTime; + private $endTime; + private $remoteAddr; } diff --git a/src/OSS/Model/LiveChannelInfo.php b/src/OSS/Model/LiveChannelInfo.php index e1f8861a..c63ec54d 100644 --- a/src/OSS/Model/LiveChannelInfo.php +++ b/src/OSS/Model/LiveChannelInfo.php @@ -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; @@ -104,4 +97,11 @@ public function serializeToXml() { throw new OssException("Not implemented."); } + + private $name; + private $description; + private $publishUrls; + private $playUrls; + private $status; + private $lastModified; } diff --git a/src/OSS/Model/LiveChannelListInfo.php b/src/OSS/Model/LiveChannelListInfo.php index 7a6a7f73..108d2ace 100644 --- a/src/OSS/Model/LiveChannelListInfo.php +++ b/src/OSS/Model/LiveChannelListInfo.php @@ -7,20 +7,11 @@ * * ListBucketLiveChannels接口返回数据 * - * TODO fix link * @package OSS\Model * @link http://help.aliyun.com/document_detail/oss/api-reference/bucket/GetBucket.html */ class LiveChannelListInfo implements XmlConfig { - private $bucketName; - private $prefix; - private $marker; - private $nextMarker; - private $maxKeys; - private $isTruncated; - private $channelList = array(); - /** * @return string */ @@ -105,4 +96,12 @@ public function serializeToXml() { throw new OssException("Not implemented."); } + + private $bucketName; + private $prefix; + private $marker; + private $nextMarker; + private $maxKeys = 100; + private $isTruncated; + private $channelList = array(); } diff --git a/src/OSS/OssClient.php b/src/OSS/OssClient.php index 80d31cc3..630d24f8 100644 --- a/src/OSS/OssClient.php +++ b/src/OSS/OssClient.php @@ -522,7 +522,7 @@ public function deleteBucketCname($bucket, $cname, $options = NULL) } /** - * 为指定Bucket创建直播流 + * 为指定Bucket创建LiveChannel * * @param string $bucket bucket名称 * @param LiveChannelConfig $channelConfig @@ -545,7 +545,7 @@ public function putBucketLiveChannel($bucket, $channelConfig, $options = NULL) $info = $result->getData(); $info->setName($channelConfig->getName()); $info->setDescription($channelConfig->getDescription()); - + return $info; } @@ -611,7 +611,7 @@ public function getLiveChannelStatus($bucket, $channelName, $options = NULL) $options[self::OSS_METHOD] = self::OSS_HTTP_GET; $options[self::OSS_OBJECT] = $channelName; $options[self::OSS_SUB_RESOURCE] = 'live'; - $options[self::OSS_CNAME_COMP] = 'stat'; + $options[self::OSS_LIVE_CHANNEL_PARAMS] = 'stat'; $response = $this->auth($options); $result = new GetLiveChannelStatusResult($response); @@ -619,7 +619,7 @@ public function getLiveChannelStatus($bucket, $channelName, $options = NULL) } /** - * 获取LiveChannel历史信息 + *获取LiveChannel推流记录 * * @param string $bucket bucket名称 * @param string $channelName 指定的LiveChannel @@ -634,7 +634,7 @@ public function getLiveChannelHistory($bucket, $channelName, $options = NULL) $options[self::OSS_METHOD] = self::OSS_HTTP_GET; $options[self::OSS_OBJECT] = $channelName; $options[self::OSS_SUB_RESOURCE] = 'live'; - $options[self::OSS_CNAME_COMP] = 'history'; + $options[self::OSS_LIVE_CHANNEL_PARAMS] = 'history'; $response = $this->auth($options); $result = new GetLiveChannelHistoryResult($response); @@ -642,7 +642,7 @@ public function getLiveChannelHistory($bucket, $channelName, $options = NULL) } /** - * 获取指定Bucket的直播流列表 + *获取指定Bucket下的live channel列表 * * @param string $bucket bucket名称 * @param array $options @@ -695,7 +695,7 @@ public function postVodPlaylist($bucket, $channelName, $playlistName, $options = } /** - * 删除指定Bucket的直播流 + * 删除指定Bucket的LiveChannel * * @param string $bucket bucket名称 * @param string $channelName @@ -717,15 +717,15 @@ public function deleteBucketLiveChannel($bucket, $channelName, $options = NULL) } /** - * 生成签名后的推流地址 + * 生成带签名的推流地址 * * @param string $bucket bucket名称 * @param string $channelName * @param array $options * @throws OssException - * @return null + * @return 推流地址 */ - public function getLiveChannelUrl($bucket, $channelName, $options = NULL) + public function signRtmpUrl($bucket, $channelName, $options = NULL) { $this->precheckCommon($bucket, $channelName, $options, false); $expires = isset($options['expires']) ? intval($options['expires']) : 3600; @@ -2088,12 +2088,13 @@ private function generateSignableQueryStringParam($options) 'response-content-encoding', 'response-expires', 'response-content-disposition', - 'x-oss-process', self::OSS_UPLOAD_ID, self::OSS_CNAME_COMP, + self::OSS_LIVE_CHANNEL_PARAMS, self::OSS_LIVE_CHANNEL_STATUS, self::OSS_LIVE_CHANNEL_START_TIME, - self::OSS_LIVE_CHANNEL_END_TIME + self::OSS_LIVE_CHANNEL_END_TIME, + self::OSS_IMAGE_PROCESS ); foreach ($signableList as $item) { @@ -2305,6 +2306,7 @@ public function setConnectTimeout($connectTimeout) const OSS_UPLOAD_ID = 'uploadId'; const OSS_PART_NUM = 'partNumber'; const OSS_CNAME_COMP = 'comp'; + const OSS_LIVE_CHANNEL_PARAMS = 'comp'; const OSS_LIVE_CHANNEL_STATUS = 'status'; const OSS_LIVE_CHANNEL_START_TIME = 'startTime'; const OSS_LIVE_CHANNEL_END_TIME = 'endTime'; @@ -2370,6 +2372,7 @@ public function setConnectTimeout($connectTimeout) const OSS_MULTI_DELETE = 'delete'; const OSS_OBJECT_COPY_SOURCE = 'x-oss-copy-source'; const OSS_OBJECT_COPY_SOURCE_RANGE = "x-oss-copy-source-range"; + const OSS_IMAGE_PROCESS = "x-oss-process"; //支持STS SecurityToken const OSS_SECURITY_TOKEN = "x-oss-security-token"; const OSS_ACL_TYPE_PRIVATE = 'private'; diff --git a/tests/OSS/Tests/BucketLiveChannelTest.php b/tests/OSS/Tests/BucketLiveChannelTest.php index a1288e43..63bb4aba 100644 --- a/tests/OSS/Tests/BucketLiveChannelTest.php +++ b/tests/OSS/Tests/BucketLiveChannelTest.php @@ -148,9 +148,9 @@ public function testListLiveChannels() public function testDeleteLiveChannel() { - $channelId = 'live-to-delete'; + $channelName = 'live-to-delete'; $config = new LiveChannelConfig(array( - 'name' => $channelId, + 'name' => $channelName, 'description' => 'live channel to delete', 'type' => 'HLS', 'fragDuration' => 10, @@ -159,9 +159,9 @@ public function testDeleteLiveChannel() )); $this->client->putBucketLiveChannel($this->bucketName, $config); - $this->client->deleteBucketLiveChannel($this->bucketName, $channelId); + $this->client->deleteBucketLiveChannel($this->bucketName, $channelName); $list = $this->client->listBucketLiveChannels($this->bucketName, array( - 'prefix' => $channelId + 'prefix' => $channelName )); $this->assertEquals(0, count($list->getChannelList())); @@ -169,10 +169,10 @@ public function testDeleteLiveChannel() public function testGetLiveChannelUrl() { - $channelId = '90475'; + $channelName = '90475'; $bucket = 'douyu'; $now = time(); - $url = $this->client->getLiveChannelUrl($bucket, $channelId, array( + $url = $this->client->signRtmpUrl($bucket, $channelName, array( 'expires' => 900, 'params' => array( 'a' => 'hello', @@ -192,9 +192,9 @@ public function testGetLiveChannelUrl() } public function testLiveChannelInfo() { - $channelId = 'live-to-put-status'; + $channelName = 'live-to-put-status'; $config = new LiveChannelConfig(array( - 'name' => $channelId, + 'name' => $channelName, 'description' => 'test live channel info', 'type' => 'HLS', 'fragDuration' => 10, @@ -203,7 +203,7 @@ public function testLiveChannelInfo() )); $this->client->putBucketLiveChannel($this->bucketName, $config); - $info = $this->client->getLiveChannelInfo($this->bucketName, $channelId); + $info = $this->client->getLiveChannelInfo($this->bucketName, $channelName); $this->assertEquals('test live channel info', $info->getDescription()); $this->assertEquals('enabled', $info->getStatus()); $this->assertEquals('HLS', $info->getType()); @@ -211,18 +211,18 @@ public function testLiveChannelInfo() $this->assertEquals(5, $info->getFragCount()); $this->assertEquals('playlist.m3u8', $info->getPlayListName()); - $this->client->deleteBucketLiveChannel($this->bucketName, $channelId); + $this->client->deleteBucketLiveChannel($this->bucketName, $channelName); $list = $this->client->listBucketLiveChannels($this->bucketName, array( - 'prefix' => $channelId + 'prefix' => $channelName )); $this->assertEquals(0, count($list->getChannelList())); } public function testPutLiveChannelStatus() { - $channelId = 'live-to-put-status'; + $channelName = 'live-to-put-status'; $config = new LiveChannelConfig(array( - 'name' => $channelId, + 'name' => $channelName, 'description' => 'test live channel info', 'type' => 'HLS', 'fragDuration' => 10, @@ -231,19 +231,19 @@ public function testPutLiveChannelStatus() )); $this->client->putBucketLiveChannel($this->bucketName, $config); - $info = $this->client->getLiveChannelInfo($this->bucketName, $channelId); + $info = $this->client->getLiveChannelInfo($this->bucketName, $channelName); $this->assertEquals('test live channel info', $info->getDescription()); $this->assertEquals('enabled', $info->getStatus()); $this->assertEquals('HLS', $info->getType()); $this->assertEquals(10, $info->getFragDuration()); $this->assertEquals(5, $info->getFragCount()); $this->assertEquals('playlist.m3u8', $info->getPlayListName()); - $status = $this->client->getLiveChannelStatus($this->bucketName, $channelId); + $status = $this->client->getLiveChannelStatus($this->bucketName, $channelName); $this->assertEquals('Idle', $status->getStatus()); - $resp = $this->client->putLiveChannelStatus($this->bucketName, $channelId, "disabled"); - $info = $this->client->getLiveChannelInfo($this->bucketName, $channelId); + $resp = $this->client->putLiveChannelStatus($this->bucketName, $channelName, "disabled"); + $info = $this->client->getLiveChannelInfo($this->bucketName, $channelName); $this->assertEquals('test live channel info', $info->getDescription()); $this->assertEquals('disabled', $info->getStatus()); $this->assertEquals('HLS', $info->getType()); @@ -251,22 +251,22 @@ public function testPutLiveChannelStatus() $this->assertEquals(5, $info->getFragCount()); $this->assertEquals('playlist.m3u8', $info->getPlayListName()); - $status = $this->client->getLiveChannelStatus($this->bucketName, $channelId); + $status = $this->client->getLiveChannelStatus($this->bucketName, $channelName); //getLiveChannelInfo $this->assertEquals('Disabled', $status->getStatus()); - $this->client->deleteBucketLiveChannel($this->bucketName, $channelId); + $this->client->deleteBucketLiveChannel($this->bucketName, $channelName); $list = $this->client->listBucketLiveChannels($this->bucketName, array( - 'prefix' => $channelId + 'prefix' => $channelName )); $this->assertEquals(0, count($list->getChannelList())); } public function testLiveChannelHistory() { - $channelId = 'live-test-history'; + $channelName = 'live-test-history'; $config = new LiveChannelConfig(array( - 'name' => $channelId, + 'name' => $channelName, 'description' => 'test live channel info', 'type' => 'HLS', 'fragDuration' => 10, @@ -275,110 +275,7 @@ public function testLiveChannelHistory() )); $this->client->putBucketLiveChannel($this->bucketName, $config); - $history = $this->client->getLiveChannelHistory($this->bucketName, $channelId); + $history = $this->client->getLiveChannelHistory($this->bucketName, $channelName); $this->assertEquals(0, count($history->getLiveRecordList())); } -/**** - public function testGetLiveChannelStatus() - { - $channelId = 'live-1'; - $config = new LiveChannelConfig(array( - 'name' => $channelId, - 'description' => 'live channel to delete', - 'type' => 'HLS', - 'fragDuration' => 10, - 'fragCount' => 5, - 'playListName' => 'hello' - )); - $this->client->putBucketLiveChannel($this->bucketName, $config); - - $status = $this->client->getLiveChannelStatus($this->bucketName, $channelId); - $this->assertEquals('', $status->getStatus()); - $this->assertEquals('', $status->getConnectedTime()); - $this->assertEquals(672, $status->getVideoWidth()); - $this->assertEquals(378, $status->getVideoHeight()); - $this->assertEquals(29, $status->getVideoFrameRate()); - $this->assertEquals(72513, $status->getVideoBandwidth()); - $this->assertEquals('H264', $status->getVideoCodec()); - $this->assertEquals(6519, $status->getAudioBandwidth()); - $this->assertEquals(22050, $status->getAudioSampleRate()); - $this->assertEquals('AAC', $status->getAudioCodec()); - - $this->client->deleteBucketLiveChannel($this->bucketName, $channelId); - $list = $this->client->listBucketLiveChannels($this->bucketName, array( - 'prefix' => $channelId - )); - - $this->assertEquals(0, count($list->getChannelList())); - } -****/ - -/**** public function testLiveChannelHistory() - { - $channelId = 'live-test'; - $config = new LiveChannelConfig(array( - 'name' => $channelId, - 'description' => 'test live channel info', - 'type' => 'HLS', - 'fragDuration' => 10, - 'fragCount' => 5, - 'playListName' => 'hello' - )); - $this->client->putBucketLiveChannel($this->bucketName, $config); - - $url = $this->client->getLiveChannelUrl($this->bucketName, $channelId, array( - 'expires' => 3600, - 'params' => array( - 'playlistName' => 'playlist.m3u8', - ) - )); - system("./ffmpeg \-re \-i ./allstar.flv \-c copy \-f flv '$url' "); - sleep(2); - system("./ffmpeg \-re \-i ./allstar.flv \-c copy \-f flv '$url' "); - - $history = $this->client->getLiveChannelHistory($this->bucketName, $channelId); - $this->assertEquals(2, count($history->getLiveRecordList())); - $this->assertNotEquals('', $history->getLiveRecordList()[0]->getStartTime()); - $this->assertNotEquals('', $history->getLiveRecordList()[0]->getEndTime()); - $this->assertNotEquals('', $history->getLiveRecordList()[0]->getRemoteAddr()); - $this->client->deleteBucketLiveChannel($this->bucketName, $channelId); - } -****/ -/**** public function testPostVodPlayList() - { - $channelId = 'live-test'; - $config = new LiveChannelConfig(array( - 'name' => $channelId, - 'description' => 'live channel to delete', - 'type' => 'HLS', - 'fragDuration' => 10, - 'fragCount' => 5, - 'playListName' => 'hello' - )); - $this->client->putBucketLiveChannel($this->bucketName, $config); - - $url = $this->client->getLiveChannelUrl($this->bucketName, $channelId, array( - 'expires' => 900, - 'params' => array( - 'playlistName' => 'playlist.m3u8', - ) - )); - - system(" sudo ./ffmpeg \-re \-i ./allstar.flv \-c copy \-f flv '$url' "); - sleep(1); - - $ts = time(); - $info = $this->client->postVodPlaylist($this->bucketName, $channelId, "playback.m3u8", - array('StartTime' => $ts - 86400, - 'EndTime' => $ts) - ); - - $this->client->deleteBucketLiveChannel($this->bucketName, $channelId); - $list = $this->client->listBucketLiveChannels($this->bucketName, array( - 'prefix' => $channelId - )); - - $this->assertEquals(0, count($list->getChannelList())); - } -****/ }