Java Code Examples for org.kurento.client.PlayerEndpoint#play()
The following examples show how to use
org.kurento.client.PlayerEndpoint#play() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RtpEndpointAsyncTest.java From kurento-java with Apache License 2.0 | 6 votes |
@Test public void testRtpEndpointSimulatingAndroidSdp() throws InterruptedException { PlayerEndpoint player = new PlayerEndpoint.Builder(pipeline, URL_BARCODES).build(); RtpEndpoint rtpEndpoint = new RtpEndpoint.Builder(pipeline).build(); String requestSdp = "v=0\r\n" + "o=- 12345 12345 IN IP4 95.125.31.136\r\n" + "s=-\r\n" + "c=IN IP4 95.125.31.136\r\n" + "t=0 0\r\n" + "m=video 52126 RTP/AVP 96 97 98\r\n" + "a=rtpmap:96 H264/90000\r\n" + "a=rtpmap:97 MP4V-ES/90000\r\n" + "a=rtpmap:98 H263-1998/90000\r\n" + "a=recvonly\r\n" + "b=AS:384\r\n"; rtpEndpoint.processOffer(requestSdp); player.connect(rtpEndpoint, MediaType.VIDEO); player.play(); // just a little bit of time before destroying Thread.sleep(2000); }
Example 2
Source File: SdpBaseTest.java From kurento-java with Apache License 2.0 | 6 votes |
@Test public void testRtpEndpointSimulatingAndroidSdp() throws InterruptedException { PlayerEndpoint player = new PlayerEndpoint.Builder(pipeline, URL_BARCODES).build(); String requestSdp = "v=0\r\n" + "o=- 12345 12345 IN IP4 95.125.31.136\r\n" + "s=-\r\n" + "c=IN IP4 95.125.31.136\r\n" + "t=0 0\r\n" + "m=video 52126 RTP/AVP 96 97 98\r\n" + "a=rtpmap:96 H264/90000\r\n" + "a=rtpmap:97 MP4V-ES/90000\r\n" + "a=rtpmap:98 H263-1998/90000\r\n" + "a=recvonly\r\n" + "b=AS:384\r\n"; player.connect(sdp, MediaType.VIDEO); sdp.processOffer(requestSdp); player.play(); // just a little bit of time before destroying Thread.sleep(2000); }
Example 3
Source File: PlayerMultiplePauseTest.java From kurento-java with Apache License 2.0 | 5 votes |
@Test public void testPlayerMultiplePause() throws Exception { // Test data final String mediaUrl = "http://" + getTestFilesHttpPath() + "/video/60sec/red.webm"; final Color expectedColor = Color.RED; final int playTimeSeconds = 2; final int pauseTimeSeconds = 2; final int numPauses = 30; // Media Pipeline MediaPipeline mp = kurentoClient.createMediaPipeline(); PlayerEndpoint playerEp = new PlayerEndpoint.Builder(mp, mediaUrl).build(); WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).build(); playerEp.connect(webRtcEp); // WebRTC in receive-only mode getPage().subscribeEvents("playing"); getPage().initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY); playerEp.play(); Assert.assertTrue("Not received media (timeout waiting playing event)", getPage().waitForEvent("playing")); for (int i = 0; i < numPauses; i++) { // Assert color Assert.assertTrue("The color of the video should be " + expectedColor, getPage().similarColor(expectedColor)); // Pause and wait playerEp.pause(); Thread.sleep(TimeUnit.SECONDS.toMillis(pauseTimeSeconds)); // Resume video playerEp.play(); Thread.sleep(TimeUnit.SECONDS.toMillis(playTimeSeconds)); } // Release Media Pipeline mp.release(); }
Example 4
Source File: EventTagTest.java From kurento-java with Apache License 2.0 | 5 votes |
@Test public void testEventWithoutTag() throws Exception { MediaPipeline mp = kurentoClient.createMediaPipeline(); final CountDownLatch eventReceived = new CountDownLatch(1); PlayerEndpoint player = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/10sec/red.webm") .build(); player.addTag("test_1", "value_1"); player.addTag("test_2", "value_2"); player.addTag("test_3", "value_3"); player.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() { @Override public void onEvent(EndOfStreamEvent event) { List<Tag> tags = event.getTags(); if (tags.size() == 0) { eventReceived.countDown(); } } }); player.play(); // Guard time to reproduce the whole video if (!eventReceived.await(TIMEOUT, TimeUnit.SECONDS)) { Assert.fail("Event not received"); } }
Example 5
Source File: RepositoryRecorderTest.java From kurento-java with Apache License 2.0 | 5 votes |
private void launchBrowser(WebRtcEndpoint webRtcEp, PlayerEndpoint playerEp, RecorderEndpoint recorderEp) throws InterruptedException { getPage().subscribeEvents("playing"); getPage().initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY); playerEp.play(); final CountDownLatch eosLatch = new CountDownLatch(1); playerEp.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() { @Override public void onEvent(EndOfStreamEvent event) { eosLatch.countDown(); } }); if (recorderEp != null) { recorderEp.record(); } // Assertions Assert.assertTrue("Not received media (timeout waiting playing event)", getPage().waitForEvent("playing")); Assert.assertTrue("The color of the video should be black", getPage().similarColor(Color.BLACK)); Assert.assertTrue("Not received EOS event in player", eosLatch.await(getPage().getTimeout(), TimeUnit.SECONDS)); double currentTime = getPage().getCurrentTime(); Assert.assertTrue( "Error in play time (expected: " + PLAYTIME + " sec, real: " + currentTime + " sec)", getPage().compare(PLAYTIME, currentTime)); }
Example 6
Source File: TransactionTest.java From kurento-java with Apache License 2.0 | 5 votes |
@Test public void creationInTransaction() throws InterruptedException, ExecutionException { // Pipeline creation (transaction) Transaction tx1 = kurentoClient.beginTransaction(); MediaPipeline pipeline = kurentoClient.createMediaPipeline(tx1); PlayerEndpoint player = new PlayerEndpoint.Builder(pipeline, "http://" + getTestFilesHttpPath() + "/video/format/small.webm").useEncodedMedia().build(tx1); HttpPostEndpoint httpEndpoint = new HttpPostEndpoint.Builder(pipeline).build(tx1); player.connect(tx1, httpEndpoint); TFuture<String> url1 = httpEndpoint.getUrl(tx1); tx1.commit(); // End pipeline creation // Explicit transaction Transaction tx2 = pipeline.beginTransaction(); player.play(tx2); TFuture<String> url2 = httpEndpoint.getUrl(tx2); pipeline.release(tx2); tx2.commit(); // End explicit transaction assertThat(url1.get(), is(url2.get())); }
Example 7
Source File: RecorderSwitchWebRtcWebRtcAndPlayerTest.java From kurento-java with Apache License 2.0 | 4 votes |
public void doTestWithPlayer(MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec, String expectedAudioCodec, String extension, String mediaUrlPlayer) throws Exception { // Media Pipeline #1 getPage(BROWSER2).close(); MediaPipeline mp = kurentoClient.createMediaPipeline(); final CountDownLatch errorPipelinelatch = new CountDownLatch(1); mp.addErrorListener(new EventListener<ErrorEvent>() { @Override public void onEvent(ErrorEvent event) { msgError = "Description:" + event.getDescription() + "; Error code:" + event.getType(); errorPipelinelatch.countDown(); } }); WebRtcEndpoint webRtcEpRed = new WebRtcEndpoint.Builder(mp).build(); PlayerEndpoint playerEp = new PlayerEndpoint.Builder(mp, mediaUrlPlayer).build(); String recordingFile = getRecordUrl(extension); RecorderEndpoint recorderEp = new RecorderEndpoint.Builder(mp, recordingFile) .withMediaProfile(mediaProfileSpecType).build(); // Test execution getPage(BROWSER1).subscribeLocalEvents("playing"); long startWebrtc = System.currentTimeMillis(); getPage(BROWSER1).initWebRtc(webRtcEpRed, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_ONLY); webRtcEpRed.connect(recorderEp); recorderEp.record(); Assert.assertTrue("Not received media (timeout waiting playing event)", getPage(BROWSER1).waitForEvent("playing")); long webrtcRedConnectionTime = System.currentTimeMillis() - startWebrtc; Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER); startWebrtc = System.currentTimeMillis(); playerEp.play(); playerEp.connect(recorderEp); long playerEpConnectionTime = System.currentTimeMillis() - startWebrtc; Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER); webRtcEpRed.connect(recorderEp); Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER); // Release Media Pipeline #1 saveGstreamerDot(mp); final CountDownLatch recorderLatch = new CountDownLatch(1); recorderEp.stopAndWait(new Continuation<Void>() { @Override public void onSuccess(Void result) throws Exception { recorderLatch.countDown(); } @Override public void onError(Throwable cause) throws Exception { recorderLatch.countDown(); } }); Assert.assertTrue("Not stop properly", recorderLatch.await(getPage(BROWSER1).getTimeout(), TimeUnit.SECONDS)); mp.release(); Assert.assertTrue(msgError, errorPipelinelatch.getCount() == 1); final long playtime = PLAYTIME + TimeUnit.MILLISECONDS.toSeconds((2 * webrtcRedConnectionTime) + playerEpConnectionTime); checkRecordingFile(recordingFile, BROWSER3, EXPECTED_COLORS, playtime, expectedVideoCodec, expectedAudioCodec); success = true; }
Example 8
Source File: RecorderPlayerOneToManyTest.java From kurento-java with Apache License 2.0 | 4 votes |
public void doTest(final MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec, String expectedAudioCodec, final String extension) throws Exception { MediaPipeline mp = null; // Media Pipeline mp = kurentoClient.createMediaPipeline(); final PlayerEndpoint playerEp = new PlayerEndpoint.Builder(mp, getPlayerUrl("/video/60sec/ball.webm")).build(); final RecorderEndpoint[] recorder = new RecorderEndpoint[numViewers]; final String[] recordingFile = new String[numViewers]; playerEp.play(); ExecutorService executor = Executors.newFixedThreadPool(numViewers); final CountDownLatch latch = new CountDownLatch(numViewers); final MediaPipeline pipeline = mp; for (int j = 0; j < numViewers; j++) { final int i = j; executor.execute(new Runnable() { @Override public void run() { try { // N recorders recordingFile[i] = getRecordUrl("-recorder" + i + extension); recorder[i] = new RecorderEndpoint.Builder(pipeline, recordingFile[i]) .withMediaProfile(mediaProfileSpecType).build(); playerEp.connect(recorder[i]); // Start record recorder[i].record(); // Wait play time Thread.sleep(PLAYTIME_MS); // Stop record recorder[i].stopAndWait(); // Guard time to stop recording Thread.sleep(4000); } catch (Throwable t) { log.error("Exception in receiver " + i, t); } latch.countDown(); } }); } // Wait to finish all recordings latch.await(); // Assessments for (int j = 0; j < numViewers; j++) { AssertMedia.assertCodecs(recordingFile[j], expectedVideoCodec, expectedAudioCodec); AssertMedia.assertDuration(recordingFile[j], PLAYTIME_MS, THRESHOLD_MS); } // Release Media Pipeline if (mp != null) { mp.release(); } }
Example 9
Source File: FaceOverlayFilterTest.java From kurento-java with Apache License 2.0 | 4 votes |
/** * Test if a {@link FaceOverlayFilter} can be created in the KMS. The filter is pipelined with a * {@link PlayerEndpoint}, which feeds video to the filter. This test depends on the correct * behaviour of the player and its events. * * @throws InterruptedException */ @Test public void testFaceOverlayFilter() throws InterruptedException { PlayerEndpoint player = new PlayerEndpoint.Builder(pipeline, URL_POINTER_DETECTOR).build(); player.connect(overlayFilter); AsyncEventManager<EndOfStreamEvent> async = new AsyncEventManager<>("EndOfStream event"); player.addEndOfStreamListener(async.getMediaEventListener()); player.play(); async.waitForResult(); player.stop(); player.release(); }
Example 10
Source File: CompositeAudioRecorderTest.java From kurento-java with Apache License 2.0 | 4 votes |
@Test public void testCompositeRecorder() throws Exception { // MediaPipeline MediaPipeline mp = kurentoClient.createMediaPipeline(); PlayerEndpoint playerRed = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/red.webm") .build(); PlayerEndpoint playerGreen = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/green.webm").build(); PlayerEndpoint playerBlue = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/blue.webm").build(); Composite composite = new Composite.Builder(mp).build(); HubPort hubPort1 = new HubPort.Builder(composite).build(); HubPort hubPort2 = new HubPort.Builder(composite).build(); HubPort hubPort3 = new HubPort.Builder(composite).build(); playerRed.connect(hubPort1); playerGreen.connect(hubPort2, MediaType.AUDIO); playerBlue.connect(hubPort3, MediaType.AUDIO); PlayerEndpoint playerWhite = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/white.webm").build(); HubPort hubPort4 = new HubPort.Builder(composite).build(); playerWhite.connect(hubPort4, MediaType.AUDIO); HubPort hubPort5 = new HubPort.Builder(composite).build(); String recordingFile = getDefaultOutputFile(EXTENSION_WEBM); RecorderEndpoint recorderEp = new RecorderEndpoint.Builder(mp, Protocol.FILE + recordingFile).build(); hubPort5.connect(recorderEp); playerRed.play(); playerGreen.play(); playerBlue.play(); playerWhite.play(); recorderEp.record(); Thread.sleep(RECORDTIME * 1000); final CountDownLatch recorderLatch = new CountDownLatch(1); recorderEp.stopAndWait(new Continuation<Void>() { @Override public void onSuccess(Void result) throws Exception { recorderLatch.countDown(); } @Override public void onError(Throwable cause) throws Exception { recorderLatch.countDown(); } }); Assert.assertTrue("Not stop properly", recorderLatch.await(getPage().getTimeout(), TimeUnit.SECONDS)); playerRed.stop(); playerGreen.stop(); playerBlue.stop(); playerWhite.stop(); mp.release(); // Media Pipeline #2 MediaPipeline mp2 = kurentoClient.createMediaPipeline(); PlayerEndpoint playerEp2 = new PlayerEndpoint.Builder(mp2, Protocol.FILE + recordingFile).build(); WebRtcEndpoint webRtcEp2 = new WebRtcEndpoint.Builder(mp2).build(); playerEp2.connect(webRtcEp2); // Playing the recording launchBrowser(mp, webRtcEp2, playerEp2, null, EXPECTED_VIDEO_CODEC_WEBM, EXPECTED_AUDIO_CODEC_WEBM, recordingFile, Color.RED, 0, 0, PLAYTIME); // Release Media Pipeline #2 mp2.release(); success = true; }
Example 11
Source File: CompositePlayerTest.java From kurento-java with Apache License 2.0 | 4 votes |
@Test public void testCompositePlayer() throws Exception { // Media Pipeline MediaPipeline mp = kurentoClient.createMediaPipeline(); PlayerEndpoint playerRed = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/red.webm") .build(); PlayerEndpoint playerGreen = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/green.webm").build(); PlayerEndpoint playerBlue = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/blue.webm").build(); Composite composite = new Composite.Builder(mp).build(); HubPort hubPort1 = new HubPort.Builder(composite).build(); HubPort hubPort2 = new HubPort.Builder(composite).build(); HubPort hubPort3 = new HubPort.Builder(composite).build(); playerRed.connect(hubPort1); playerGreen.connect(hubPort2); playerBlue.connect(hubPort3); PlayerEndpoint playerWhite = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/white.webm").build(); HubPort hubPort4 = new HubPort.Builder(composite).build(); playerWhite.connect(hubPort4); WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).build(); HubPort hubPort5 = new HubPort.Builder(composite).build(); hubPort5.connect(webRtcEp); // Test execution getPage().subscribeEvents("playing"); getPage().initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY); playerRed.play(); playerGreen.play(); playerBlue.play(); playerWhite.play(); // Assertions Assert.assertTrue("Not received media (timeout waiting playing event)", getPage().waitForEvent("playing")); Assert.assertTrue("Upper left part of the video must be red", getPage().similarColorAt(Color.RED, 0, 0)); Assert.assertTrue("Upper right part of the video must be green", getPage().similarColorAt(Color.GREEN, 450, 0)); Assert.assertTrue("Lower left part of the video must be blue", getPage().similarColorAt(Color.BLUE, 0, 450)); Assert.assertTrue("Lower right part of the video must be white", getPage().similarColorAt(Color.WHITE, 450, 450)); // Guard time to see the composite result Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME)); // Release Media Pipeline mp.release(); }
Example 12
Source File: BaseRecorder.java From kurento-java with Apache License 2.0 | 4 votes |
protected void checkRecordingFile(String recordingFile, String browserName, Color[] expectedColors, long playTime, String expectedVideoCodec, String expectedAudioCodec) throws InterruptedException { // Checking continuity of the audio Timer gettingStats = new Timer(); final CountDownLatch errorContinuityAudiolatch = new CountDownLatch(1); waitForFileExists(recordingFile); MediaPipeline mp = kurentoClient.createMediaPipeline(); PlayerEndpoint playerEp = new PlayerEndpoint.Builder(mp, recordingFile).build(); WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).build(); playerEp.connect(webRtcEp); // Playing the recording WebRtcTestPage checkPage = getPage(browserName); checkPage.setThresholdTime(checkPage.getThresholdTime() * 2); checkPage.subscribeEvents("playing"); checkPage.initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY); final CountDownLatch eosLatch = new CountDownLatch(1); playerEp.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() { @Override public void onEvent(EndOfStreamEvent event) { eosLatch.countDown(); } }); playerEp.play(); // Assertions in recording final String messageAppend = "[played file with media pipeline]"; Assert.assertTrue( "Not received media in the recording (timeout waiting playing event) " + messageAppend, checkPage.waitForEvent("playing")); checkPage.activatePeerConnectionInboundStats("webRtcPeer.peerConnection"); gettingStats.schedule(new CheckAudioTimerTask(errorContinuityAudiolatch, checkPage), 100, 200); for (Color color : expectedColors) { Assert.assertTrue("The color of the recorded video should be " + color + " " + messageAppend, checkPage.similarColorAt(color, 50, 50)); } Assert.assertTrue("Not received EOS event in player", eosLatch.await(checkPage.getTimeout(), TimeUnit.SECONDS)); gettingStats.cancel(); double currentTime = checkPage.getCurrentTime(); Assert.assertTrue("Error in play time in the recorded video (expected: " + playTime + " sec, real: " + currentTime + " sec) " + messageAppend, checkPage.compare(playTime, currentTime)); Assert.assertTrue("Check audio. There were more than 2 seconds without receiving packets", errorContinuityAudiolatch.getCount() == 1); AssertMedia.assertCodecs(recordingFile, expectedVideoCodec, expectedAudioCodec); AssertMedia.assertDuration(recordingFile, TimeUnit.SECONDS.toMillis(playTime), TimeUnit.SECONDS.toMillis(checkPage.getThresholdTime())); mp.release(); }
Example 13
Source File: BaseRecorder.java From kurento-java with Apache License 2.0 | 4 votes |
protected void launchBrowser(MediaPipeline mp, WebRtcEndpoint webRtcEp, PlayerEndpoint playerEp, RecorderEndpoint recorderEp, String expectedVideoCodec, String expectedAudioCodec, String recordingFile, Color expectedColor, int xColor, int yColor, int playTime) throws InterruptedException { Timer gettingStats = new Timer(); final CountDownLatch errorContinuityAudiolatch = new CountDownLatch(1); getPage().subscribeEvents("playing"); getPage().initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY); playerEp.play(); final CountDownLatch eosLatch = new CountDownLatch(1); playerEp.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() { @Override public void onEvent(EndOfStreamEvent event) { eosLatch.countDown(); } }); if (recorderEp != null) { recorderEp.record(); } // Assertions String inRecording = recorderEp == null ? " in the recording" : ""; Assert.assertTrue("Not received media (timeout waiting playing event)" + inRecording, getPage().waitForEvent("playing")); if (recorderEp == null) { // Checking continuity of the audio getPage().activatePeerConnectionInboundStats("webRtcPeer.peerConnection"); gettingStats.schedule(new CheckAudioTimerTask(errorContinuityAudiolatch, getPage()), 100, 200); } Assert.assertTrue( "Color at coordinates " + xColor + "," + yColor + " must be " + expectedColor + inRecording, getPage().similarColorAt(expectedColor, xColor, yColor)); Assert.assertTrue("Not received EOS event in player" + inRecording, eosLatch.await(getPage().getTimeout(), TimeUnit.SECONDS)); final CountDownLatch recorderLatch = new CountDownLatch(1); if (recorderEp != null) { saveGstreamerDot(mp); recorderEp.stopAndWait(new Continuation<Void>() { @Override public void onSuccess(Void result) throws Exception { recorderLatch.countDown(); } @Override public void onError(Throwable cause) throws Exception { recorderLatch.countDown(); } }); Assert.assertTrue("Not stop properly", recorderLatch.await(getPage().getTimeout(), TimeUnit.SECONDS)); // Wait until file exists waitForFileExists(recordingFile); AssertMedia.assertCodecs(recordingFile, expectedVideoCodec, expectedAudioCodec); AssertMedia.assertDuration(recordingFile, TimeUnit.SECONDS.toMillis(playTime), TimeUnit.SECONDS.toMillis(getPage().getThresholdTime())); } else { gettingStats.cancel(); getPage().stopPeerConnectionInboundStats("webRtcPeer.peerConnection"); double currentTime = getPage().getCurrentTime(); Assert.assertTrue("Error in play time in the recorded video (expected: " + playTime + " sec, real: " + currentTime + " sec) " + inRecording, getPage().compare(playTime, currentTime)); if (recorderEp == null) { Assert.assertTrue("Check audio. There were more than 2 seconds without receiving packets", errorContinuityAudiolatch.getCount() == 1); } } }
Example 14
Source File: ZBarFilterTest.java From kurento-java with Apache License 2.0 | 4 votes |
@Test public void testCodeFoundEvent() throws InterruptedException { PlayerEndpoint player = new PlayerEndpoint.Builder(pipeline, URL_BARCODES).build(); player.connect(zbar); AsyncEventManager<CodeFoundEvent> async = new AsyncEventManager<>("CodeFound event"); zbar.addCodeFoundListener(async.getMediaEventListener()); player.play(); async.waitForResult(); player.stop(); player.release(); }
Example 15
Source File: RecorderPlayerSwitchSequentialTest.java From kurento-java with Apache License 2.0 | 4 votes |
public void doTest(MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec, String expectedAudioCodec, String extension) throws Exception { final CountDownLatch recorderLatch = new CountDownLatch(1); MediaPipeline mp = null; // Media Pipeline mp = kurentoClient.createMediaPipeline(); PlayerEndpoint playerEp1 = new PlayerEndpoint.Builder(mp, getPlayerUrl("/video/60sec/ball.webm")).build(); PlayerEndpoint playerEp2 = new PlayerEndpoint.Builder(mp, getPlayerUrl("/video/60sec/smpte.webm")).build(); String recordingFile = getRecordUrl(extension); RecorderEndpoint recorderEp = new RecorderEndpoint.Builder(mp, recordingFile) .withMediaProfile(mediaProfileSpecType).build(); // Start play and record playerEp1.play(); playerEp2.play(); recorderEp.record(); // Switch players for (int i = 0; i < SWITCH_TIMES; i++) { if (i % 2 == 0) { playerEp1.connect(recorderEp); } else { playerEp2.connect(recorderEp); } Thread.sleep(SWITCH_RATE_MS); } // Stop play and record playerEp1.stop(); playerEp2.stop(); recorderEp.stop(new Continuation<Void>() { @Override public void onSuccess(Void result) throws Exception { recorderLatch.countDown(); } @Override public void onError(Throwable cause) throws Exception { recorderLatch.countDown(); } }); Assert.assertTrue("Not stop properly", recorderLatch.await(TIMEOUT, TimeUnit.SECONDS)); // Assessments long expectedTimeMs = SWITCH_TIMES * SWITCH_RATE_MS; AssertMedia.assertCodecs(recordingFile, expectedVideoCodec, expectedAudioCodec); AssertMedia.assertDuration(recordingFile, expectedTimeMs, THRESHOLD_MS); // Release Media Pipeline if (mp != null) { mp.release(); } }
Example 16
Source File: PlayerSwitchTest.java From kurento-java with Apache License 2.0 | 4 votes |
@Test public void testPlayerSwitch() throws Exception { // Media Pipeline MediaPipeline mp = kurentoClient.createMediaPipeline(); PlayerEndpoint playerRed = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/format/chrome.mp4").build(); WebRtcEndpoint webRtcEndpoint = new WebRtcEndpoint.Builder(mp).build(); // Test execution getPage().subscribeEvents("playing"); getPage().initWebRtc(webRtcEndpoint, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY); // red playerRed.connect(webRtcEndpoint); playerRed.play(); getPage().subscribeEvents("playing"); Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER); PlayerEndpoint playerGreen = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/format/fiware.mkv").build(); // green playerGreen.connect(webRtcEndpoint); playerGreen.play(); Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER); // blue PlayerEndpoint playerBlue = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/format/sintel.webm").build(); playerBlue.connect(webRtcEndpoint); playerBlue.play(); Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER); // ball PlayerEndpoint playerBall = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/format/rabbit.mov").build(); playerBall.connect(webRtcEndpoint); playerBall.play(); Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER); // rtsp PlayerEndpoint playerRtsp = new PlayerEndpoint.Builder(mp, "rtsp://195.55.223.100/axis-media/media.amp").build(); playerRtsp.connect(webRtcEndpoint); playerRtsp.play(); Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER); // Assertions Assert.assertTrue("Not received media (timeout waiting playing event)", getPage().waitForEvent("playing")); double currentTime = getPage().getCurrentTime(); Assert.assertTrue( "Error in play time (expected: " + PLAYTIME + " sec, real: " + currentTime + " sec)", getPage().compare(PLAYTIME, currentTime)); // Release Media Pipeline mp.release(); }
Example 17
Source File: PlayerFaceOverlayTest.java From kurento-java with Apache License 2.0 | 4 votes |
@Test public void testPlayerFaceOverlay() throws Exception { // Test data final int playTimeSeconds = 30; final String mediaUrl = "http://" + getTestFilesHttpPath() + "/video/filter/fiwarecut.mp4"; final Color expectedColor = Color.RED; final int xExpectedColor = 420; final int yExpectedColor = 45; final String imgOverlayUrl = "http://" + getTestFilesHttpPath() + "/img/red-square.png"; final float offsetXPercent = -0.2F; final float offsetYPercent = -1.2F; final float widthPercent = 1.6F; final float heightPercent = 1.6F; // Media Pipeline MediaPipeline mp = kurentoClient.createMediaPipeline(); PlayerEndpoint playerEp = new PlayerEndpoint.Builder(mp, mediaUrl).build(); WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).build(); FaceOverlayFilter filter = new FaceOverlayFilter.Builder(mp).build(); filter.setOverlayedImage(imgOverlayUrl, offsetXPercent, offsetYPercent, widthPercent, heightPercent); playerEp.connect(filter); filter.connect(webRtcEp); final CountDownLatch eosLatch = new CountDownLatch(1); playerEp.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() { @Override public void onEvent(EndOfStreamEvent event) { eosLatch.countDown(); } }); // Test execution getPage().subscribeEvents("playing"); getPage().initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY); playerEp.play(); // Assertions Assert.assertTrue("Not received media (timeout waiting playing event)", getPage().waitForEvent("playing")); Assert.assertTrue( "Color at coordinates " + xExpectedColor + "," + yExpectedColor + " must be " + expectedColor, getPage().similarColorAt(expectedColor, xExpectedColor, yExpectedColor)); Assert.assertTrue("Not received EOS event in player", eosLatch.await(getPage().getTimeout(), TimeUnit.SECONDS)); double currentTime = getPage().getCurrentTime(); Assert.assertTrue( "Error in play time (expected: " + playTimeSeconds + " sec, real: " + currentTime + " sec)", getPage().compare(playTimeSeconds, currentTime)); // Release Media Pipeline mp.release(); }
Example 18
Source File: PlayerEndTest.java From kurento-java with Apache License 2.0 | 4 votes |
public void doTest(PlayerOperation playerOperation) throws Exception { // Test data final String mediaUrl = "http://" + getTestFilesHttpPath() + "/video/format/small.webm"; final int guardTimeSeconds = 10; // Media Pipeline MediaPipeline mp = kurentoClient.createMediaPipeline(); PlayerEndpoint playerEp = new PlayerEndpoint.Builder(mp, mediaUrl).build(); WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).build(); playerEp.connect(webRtcEp); // Subscription to EOS event final boolean[] eos = new boolean[1]; eos[0] = false; playerEp.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() { @Override public void onEvent(EndOfStreamEvent event) { log.error("EOS event received: {} {}", event.getType(), event.getTimestamp()); eos[0] = true; } }); // WebRTC in receive-only mode getPage().subscribeEvents("playing"); getPage().initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY); playerEp.play(); Assert.assertTrue("Not received media (timeout waiting playing event)", getPage().waitForEvent("playing")); // Stop/release stream and wait x seconds switch (playerOperation) { case STOP: playerEp.stop(); break; case RELEASE: playerEp.release(); break; } Thread.sleep(TimeUnit.SECONDS.toMillis(guardTimeSeconds)); // Verify that EOS event has not being received Assert.assertFalse("EOS event has been received. " + "This should not be happenning because the stream has been stopped", eos[0]); // Release Media Pipeline mp.release(); }
Example 19
Source File: EventTagTest.java From kurento-java with Apache License 2.0 | 4 votes |
@Test public void testEventTag() throws Exception { MediaPipeline mp = kurentoClient.createMediaPipeline(); final CountDownLatch eventReceived = new CountDownLatch(TAG_SIZE); PlayerEndpoint player = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/10sec/red.webm") .build(); player.addTag("test_1", "value_1"); player.addTag("test_2", "value_2"); player.addTag("test_3", "value_3"); player.setSendTagsInEvents(true); player.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() { @Override public void onEvent(EndOfStreamEvent event) { List<Tag> tags = event.getTags(); for (Tag tag : tags) { if (tag.getKey().compareTo("test_1") == 0) { if (tag.getValue().compareTo("value_1") == 0) { eventReceived.countDown(); } } else if (tag.getKey().compareTo("test_2") == 0) { if (tag.getValue().compareTo("value_2") == 0) { eventReceived.countDown(); } } else if (tag.getKey().compareTo("test_3") == 0) { if (tag.getValue().compareTo("value_3") == 0) { eventReceived.countDown(); } } } } }); player.play(); // Guard time to reproduce the whole video if (!eventReceived.await(TIMEOUT, TimeUnit.SECONDS)) { Assert.fail("Event not received"); } }
Example 20
Source File: AlphaBlendingPlayerTest.java From kurento-java with Apache License 2.0 | 4 votes |
@Test public void testAlphaBlendingPlayer() throws Exception { // Media Pipeline MediaPipeline mp = kurentoClient.createMediaPipeline(); PlayerEndpoint playerRed = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/red.webm") .build(); PlayerEndpoint playerGreen = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/green.webm").build(); PlayerEndpoint playerBlue = new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/blue.webm").build(); AlphaBlending alphaBlending = new AlphaBlending.Builder(mp).build(); HubPort hubPort1 = new HubPort.Builder(alphaBlending).build(); HubPort hubPort2 = new HubPort.Builder(alphaBlending).build(); HubPort hubPort3 = new HubPort.Builder(alphaBlending).build(); playerRed.connect(hubPort1); playerGreen.connect(hubPort2); playerBlue.connect(hubPort3); HubPort hubPort4 = new HubPort.Builder(alphaBlending).build(); WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).build(); hubPort4.connect(webRtcEp); alphaBlending.setMaster(hubPort1, 1); alphaBlending.setPortProperties(0F, 0F, 8, 0.2F, 0.2F, hubPort2); alphaBlending.setPortProperties(0.4F, 0.4F, 7, 0.2F, 0.2F, hubPort3); getPage().subscribeEvents("playing"); getPage().initWebRtc(webRtcEp, WebRtcChannel.VIDEO_ONLY, WebRtcMode.RCV_ONLY); playerRed.play(); playerGreen.play(); playerBlue.play(); Thread.sleep(2000); Assert.assertTrue("Not received media (timeout waiting playing event)", getPage().waitForEvent("playing")); Thread.sleep(2000); // Assertions Assert.assertTrue("Upper left part of the video must be blue", getPage().similarColorAt(Color.GREEN, 0, 0)); Assert.assertTrue("Lower right part of the video must be red", getPage().similarColorAt(Color.RED, 315, 235)); Assert.assertTrue("Center of the video must be blue", getPage().similarColorAt(Color.BLUE, 160, 120)); // alphaBlending.setMaster(hubPort3, 1); alphaBlending.setPortProperties(0.8F, 0.8F, 7, 0.2F, 0.2F, hubPort3); Assert.assertTrue("Lower right part of the video must be blue", getPage().similarColorAt(Color.BLUE, 315, 235)); Assert.assertTrue("Center of the video must be red", getPage().similarColorAt(Color.RED, 160, 120)); Thread.sleep(PLAYTIME * 1000); }