Search in sources :

Example 1 with LiveChannelStat

use of com.aliyun.oss.model.LiveChannelStat in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testGetLiveChannelStatWithoutPushflow.

@Test
public void testGetLiveChannelStatWithoutPushflow() {
    final String liveChannel = "normal-get-live-channel-stat-without-pushflow";
    try {
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel);
        ossClient.createLiveChannel(createLiveChannelRequest);
        LiveChannelStat liveChannelStat = ossClient.getLiveChannelStat(bucketName, liveChannel);
        Assert.assertEquals(liveChannelStat.getPushflowStatus(), PushflowStatus.Idle);
        Assert.assertNull(liveChannelStat.getConnectedDate());
        Assert.assertNull(liveChannelStat.getRemoteAddress());
        Assert.assertNull(liveChannelStat.getVideoStat());
        Assert.assertNull(liveChannelStat.getAudioStat());
        Assert.assertEquals(liveChannelStat.getRequestId().length(), REQUEST_ID_LEN);
        ossClient.setLiveChannelStatus(bucketName, liveChannel, LiveChannelStatus.Disabled);
        liveChannelStat = ossClient.getLiveChannelStat(bucketName, liveChannel);
        Assert.assertEquals(liveChannelStat.getPushflowStatus(), PushflowStatus.Disabled);
        Assert.assertNull(liveChannelStat.getConnectedDate());
        Assert.assertNull(liveChannelStat.getRemoteAddress());
        Assert.assertNull(liveChannelStat.getVideoStat());
        Assert.assertNull(liveChannelStat.getAudioStat());
        Assert.assertEquals(liveChannelStat.getRequestId().length(), REQUEST_ID_LEN);
        ossClient.deleteLiveChannel(bucketName, liveChannel);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) LiveChannelStat(com.aliyun.oss.model.LiveChannelStat) OSSException(com.aliyun.oss.OSSException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 2 with LiveChannelStat

use of com.aliyun.oss.model.LiveChannelStat in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testGetLiveChannelStat.

@Ignore
public void testGetLiveChannelStat() {
    final String liveChannel = "normal-get-live-channel-stat";
    try {
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel);
        ossClient.createLiveChannel(createLiveChannelRequest);
        ossClient.setBucketAcl(bucketName, CannedAccessControlList.PublicReadWrite);
        // Manually enable pusing streaming with following cmd.
        // ./ffmpeg \-re \-i allstar.flv \-c copy \-f flv "rtmp://oss-live-channel-2.demo-oss-cn-shenzhen.aliyuncs.com/live/normal-get-live-channel-stat?playlistName=playlist.m3u8"
        Thread.sleep(5 * 1000);
        LiveChannelStat liveChannelStat = ossClient.getLiveChannelStat(bucketName, liveChannel);
        Assert.assertEquals(liveChannelStat.getPushflowStatus(), PushflowStatus.Live);
        Assert.assertNotNull(liveChannelStat.getConnectedDate());
        Assert.assertTrue(liveChannelStat.getRemoteAddress().length() >= new String("0.0.0.0:0").length());
        Assert.assertEquals(liveChannelStat.getVideoStat().getWidth(), 672);
        Assert.assertEquals(liveChannelStat.getVideoStat().getHeight(), 378);
        Assert.assertEquals(liveChannelStat.getVideoStat().getFrameRate(), 29);
        Assert.assertTrue(liveChannelStat.getVideoStat().getBandWidth() > 50000);
        Assert.assertEquals(liveChannelStat.getVideoStat().getCodec(), "H264");
        Assert.assertTrue(liveChannelStat.getAudioStat().getBandWidth() > 4000);
        Assert.assertEquals(liveChannelStat.getAudioStat().getSampleRate(), 22050);
        Assert.assertEquals(liveChannelStat.getAudioStat().getCodec(), "AAC");
        ossClient.deleteLiveChannel(bucketName, liveChannel);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) LiveChannelStat(com.aliyun.oss.model.LiveChannelStat) OSSException(com.aliyun.oss.OSSException) ParseException(java.text.ParseException) Ignore(org.junit.Ignore)

Example 3 with LiveChannelStat

use of com.aliyun.oss.model.LiveChannelStat in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseGetLiveChannelStat.

/**
 * Unmarshall get live channel stat response body to corresponding result.
 */
public static LiveChannelStat parseGetLiveChannelStat(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        LiveChannelStat result = new LiveChannelStat();
        result.setPushflowStatus(PushflowStatus.parse(root.getChildText("Status")));
        if (root.getChild("ConnectedTime") != null) {
            result.setConnectedDate(DateUtil.parseIso8601Date(root.getChildText("ConnectedTime")));
        }
        if (root.getChild("RemoteAddr") != null) {
            result.setRemoteAddress(root.getChildText("RemoteAddr"));
        }
        Element videoElem = root.getChild("Video");
        if (videoElem != null) {
            VideoStat videoStat = new VideoStat();
            videoStat.setWidth(Integer.parseInt(videoElem.getChildText("Width")));
            videoStat.setHeight(Integer.parseInt(videoElem.getChildText("Height")));
            videoStat.setFrameRate(Integer.parseInt(videoElem.getChildText("FrameRate")));
            videoStat.setBandWidth(Integer.parseInt(videoElem.getChildText("Bandwidth")));
            videoStat.setCodec(videoElem.getChildText("Codec"));
            result.setVideoStat(videoStat);
        }
        Element audioElem = root.getChild("Audio");
        if (audioElem != null) {
            AudioStat audioStat = new AudioStat();
            audioStat.setBandWidth(Integer.parseInt(audioElem.getChildText("Bandwidth")));
            audioStat.setSampleRate(Integer.parseInt(audioElem.getChildText("SampleRate")));
            audioStat.setCodec(audioElem.getChildText("Codec"));
            result.setAudioStat(audioStat);
        }
        return result;
    } catch (JDOMParseException e) {
        throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
    } catch (Exception e) {
        throw new ResponseParseException(e.getMessage(), e);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) AudioStat(com.aliyun.oss.model.LiveChannelStat.AudioStat) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) VideoStat(com.aliyun.oss.model.LiveChannelStat.VideoStat) LiveChannelStat(com.aliyun.oss.model.LiveChannelStat) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Aggregations

LiveChannelStat (com.aliyun.oss.model.LiveChannelStat)3 ParseException (java.text.ParseException)3 OSSException (com.aliyun.oss.OSSException)2 CreateLiveChannelRequest (com.aliyun.oss.model.CreateLiveChannelRequest)2 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 AudioStat (com.aliyun.oss.model.LiveChannelStat.AudioStat)1 VideoStat (com.aliyun.oss.model.LiveChannelStat.VideoStat)1 Element (org.jdom.Element)1 JDOMParseException (org.jdom.input.JDOMParseException)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1