Package com.kurento.kmf.test.content

Source Code of com.kurento.kmf.test.content.ContentApiPlayerTest$PlayerRedirect

/*
* (C) Copyright 2014 Kurento (http://kurento.org/)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public License
* (LGPL) version 2.1 which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-2.1.html
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
package com.kurento.kmf.test.content;

import java.awt.Color;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.junit.Assert;
import org.junit.Test;

import com.kurento.kmf.content.HttpPlayerHandler;
import com.kurento.kmf.content.HttpPlayerService;
import com.kurento.kmf.content.HttpPlayerSession;
import com.kurento.kmf.media.HttpGetEndpoint;
import com.kurento.kmf.media.MediaPipeline;
import com.kurento.kmf.media.PlayerEndpoint;
import com.kurento.kmf.test.base.ContentApiTest;
import com.kurento.kmf.test.client.Browser;
import com.kurento.kmf.test.client.BrowserClient;
import com.kurento.kmf.test.client.Client;

/**
*
* <strong>Description</strong>: Test of an HTTP Player.<br/>
* <strong>Pipeline</strong>:
* <ul>
* <li>PlayerEndpoint -> HttpGetEndpoint</li>
* </ul>
* <strong>Pass criteria</strong>:
* <ul>
* <li>Timeout waiting playing event</li>
* <li>Timeout waiting ended event</li>
* <li>Play time must be at least 8 seconds</li>
* <li>The color of the video should be red</li>
* </ul>
*
* @author Micael Gallego (micael.gallego@gmail.com)
* @author Boni Garcia (bgarcia@gsyc.es)
* @since 4.2.3
*/
public class ContentApiPlayerTest extends ContentApiTest {

  private static final String HANDLER = "/player";

  @HttpPlayerService(path = HANDLER, redirect = false, useControlProtocol = false)
  public static class PlayerRedirect extends HttpPlayerHandler {

    private PlayerEndpoint playerEP;

    @Override
    public void onContentRequest(HttpPlayerSession session)
        throws Exception {
      MediaPipeline mp = session.getMediaPipelineFactory().create();
      playerEP = mp.newPlayerEndpoint(
          "http://files.kurento.org/video/10sec/red.webm").build();
      HttpGetEndpoint httpEP = mp.newHttpGetEndpoint().terminateOnEOS()
          .build();
      playerEP.connect(httpEP);
      session.start(httpEP);

      terminateLatch = new CountDownLatch(1);
    }

    @Override
    public void onContentStarted(HttpPlayerSession session)
        throws Exception {
      playerEP.play();
    }

    @Override
    public void onSessionTerminated(HttpPlayerSession session, int code,
        String reason) throws Exception {
      super.onSessionTerminated(session, code, reason);
      terminateLatch.countDown();
    }
  }

  @Test
  public void testPlayer() throws InterruptedException {
    try (BrowserClient browser = new BrowserClient.Builder()
        .browser(Browser.CHROME).client(Client.PLAYER).build()) {
      browser.setURL(HANDLER);
      browser.subscribeEvents("playing", "ended");
      browser.start();

      // Assertions
      Assert.assertTrue("Timeout waiting playing event",
          browser.waitForEvent("playing"));
      Assert.assertTrue("Timeout waiting ended event",
          browser.waitForEvent("ended"));
      Assert.assertTrue("Play time must be at least 8 seconds",
          browser.getCurrentTime() >= 8);
      Assert.assertTrue("The color of the video should be red",
          browser.colorSimilarTo(Color.RED));

      // Ending session in order
      browser.stop();
      Assert.assertTrue(
          "Timeout waiting onSessionTerminated",
          terminateLatch.await(browser.getTimeout(), TimeUnit.SECONDS));
    }
  }
}
TOP

Related Classes of com.kurento.kmf.test.content.ContentApiPlayerTest$PlayerRedirect

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.