Search in sources :

Example 1 with SmilResponse

use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.

the class VideoEditorTest method setUpClass.

/**
 * Copies test files to the local file system, since jmf is not able to access movies from the resource section of a
 * bundle.
 *
 * @throws Exception
 *           if setup fails
 */
@BeforeClass
public static void setUpClass() throws Exception {
    /* Set up the 2 tracks for merging */
    track1 = TrackImpl.fromURI(VideoEditorTest.class.getResource(mediaResource).toURI());
    track1.setIdentifier("track-1");
    track1.setFlavor(new MediaPackageElementFlavor("source", "presentater"));
    track1.setMimeType(MimeTypes.MJPEG);
    track1.addStream(new VideoStreamImpl());
    track1.setDuration(movieDuration);
    track2 = TrackImpl.fromURI(VideoEditorTest.class.getResource(mediaResource).toURI());
    track2.setIdentifier("track-2");
    track2.setFlavor(new MediaPackageElementFlavor("source", "presentater"));
    track2.setMimeType(MimeTypes.MJPEG);
    track2.addStream(new VideoStreamImpl());
    track2.setDuration(movieDuration);
    /* Start of Smil mockups */
    URL mediaUrl = VideoEditorTest.class.getResource(mediaResource);
    URL smilUrl = VideoEditorTest.class.getResource(smilResource);
    String smilString = IOUtils.toString(smilUrl);
    String trackParamGroupId = "pg-a6d8e576-495f-44c7-8ed7-b5b47c807f0f";
    SmilMediaParam param1 = EasyMock.createNiceMock(SmilMediaParam.class);
    EasyMock.expect(param1.getName()).andReturn("track-id").anyTimes();
    EasyMock.expect(param1.getValue()).andReturn("track-1").anyTimes();
    EasyMock.expect(param1.getId()).andReturn("param-e2f41e7d-caba-401b-a03a-e524296cb235").anyTimes();
    SmilMediaParam param2 = EasyMock.createNiceMock(SmilMediaParam.class);
    EasyMock.expect(param2.getName()).andReturn("track-src").anyTimes();
    EasyMock.expect(param2.getValue()).andReturn("file:" + mediaUrl.getPath()).anyTimes();
    EasyMock.expect(param2.getId()).andReturn("param-1bd5e839-0a74-4310-b1d2-daba07914f79").anyTimes();
    SmilMediaParam param3 = EasyMock.createNiceMock(SmilMediaParam.class);
    EasyMock.expect(param3.getName()).andReturn("track-flavor").anyTimes();
    EasyMock.expect(param3.getValue()).andReturn("source/presenter").anyTimes();
    EasyMock.expect(param3.getId()).andReturn("param-1bd5e839-0a74-4310-b1d2-daba07914f79").anyTimes();
    EasyMock.replay(param1, param2, param3);
    List<SmilMediaParam> params = new ArrayList<SmilMediaParam>();
    params.add(param1);
    params.add(param2);
    params.add(param3);
    SmilMediaParamGroup group1 = EasyMock.createNiceMock(SmilMediaParamGroup.class);
    EasyMock.expect(group1.getParams()).andReturn(params).anyTimes();
    EasyMock.expect(group1.getId()).andReturn(trackParamGroupId).anyTimes();
    EasyMock.replay(group1);
    List<SmilMediaParamGroup> paramGroups = new ArrayList<SmilMediaParamGroup>();
    paramGroups.add(group1);
    SmilHead head = EasyMock.createNiceMock(SmilHead.class);
    EasyMock.expect(head.getParamGroups()).andReturn(paramGroups).anyTimes();
    EasyMock.replay(head);
    SmilMediaElement object1 = EasyMock.createNiceMock(SmilMediaElement.class);
    EasyMock.expect(object1.isContainer()).andReturn(false).anyTimes();
    EasyMock.expect(object1.getParamGroup()).andReturn(trackParamGroupId).anyTimes();
    EasyMock.expect(object1.getClipBeginMS()).andReturn(1000L).anyTimes();
    EasyMock.expect(object1.getClipEndMS()).andReturn(12000L).anyTimes();
    EasyMock.expect(object1.getSrc()).andReturn(mediaUrl.toURI()).anyTimes();
    EasyMock.replay(object1);
    SmilMediaElement object2 = EasyMock.createNiceMock(SmilMediaElement.class);
    EasyMock.expect(object2.isContainer()).andReturn(false).anyTimes();
    EasyMock.expect(object2.getParamGroup()).andReturn(trackParamGroupId).anyTimes();
    EasyMock.expect(object2.getClipBeginMS()).andReturn(1000L).anyTimes();
    EasyMock.expect(object2.getClipEndMS()).andReturn(13000L).anyTimes();
    EasyMock.expect(object2.getSrc()).andReturn(mediaUrl.toURI()).anyTimes();
    EasyMock.replay(object2);
    List<SmilMediaObject> objects = new ArrayList<SmilMediaObject>();
    objects.add(object1);
    objects.add(object2);
    SmilMediaContainer objectContainer = EasyMock.createNiceMock(SmilMediaContainer.class);
    EasyMock.expect(objectContainer.isContainer()).andReturn(true).anyTimes();
    EasyMock.expect(objectContainer.getContainerType()).andReturn(SmilMediaContainer.ContainerType.PAR).anyTimes();
    EasyMock.expect(objectContainer.getElements()).andReturn(objects).anyTimes();
    EasyMock.replay(objectContainer);
    List<SmilMediaObject> containerObjects = new ArrayList<SmilMediaObject>();
    containerObjects.add(objectContainer);
    SmilBody body = EasyMock.createNiceMock(SmilBody.class);
    EasyMock.expect(body.getMediaElements()).andReturn(containerObjects).anyTimes();
    EasyMock.replay(body);
    smil = EasyMock.createNiceMock(Smil.class);
    EasyMock.expect(smil.get(trackParamGroupId)).andReturn(group1).anyTimes();
    EasyMock.expect(smil.getBody()).andReturn(body).anyTimes();
    EasyMock.expect(smil.getHead()).andReturn(head).anyTimes();
    EasyMock.expect(smil.toXML()).andReturn(smilString).anyTimes();
    EasyMock.expect(smil.getId()).andReturn("s-ec404c2a-5092-4cd4-8717-7b7bbc244656").anyTimes();
    EasyMock.replay(smil);
    SmilResponse response = EasyMock.createNiceMock(SmilResponse.class);
    EasyMock.expect(response.getSmil()).andReturn(smil).anyTimes();
    EasyMock.replay(response);
    smilService = EasyMock.createNiceMock(SmilService.class);
    EasyMock.expect(smilService.fromXml((String) EasyMock.anyObject())).andReturn(response).anyTimes();
    EasyMock.replay(smilService);
/* End of Smil mockups */
}
Also used : SmilMediaParam(org.opencastproject.smil.entity.media.param.api.SmilMediaParam) ArrayList(java.util.ArrayList) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URL(java.net.URL) SmilService(org.opencastproject.smil.api.SmilService) SmilHead(org.opencastproject.smil.entity.api.SmilHead) SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilBody(org.opencastproject.smil.entity.api.SmilBody) Smil(org.opencastproject.smil.entity.api.Smil) SmilMediaElement(org.opencastproject.smil.entity.media.element.api.SmilMediaElement) SmilMediaObject(org.opencastproject.smil.entity.media.api.SmilMediaObject) SmilMediaParamGroup(org.opencastproject.smil.entity.media.param.api.SmilMediaParamGroup) SmilMediaContainer(org.opencastproject.smil.entity.media.container.api.SmilMediaContainer) BeforeClass(org.junit.BeforeClass)

Example 2 with SmilResponse

use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.

the class SmilServiceImplTest method testAddClip.

/**
 * Test of addClip(s) methods, of class SmilServiceImpl.
 */
@Test
public void testAddClip() throws Exception {
    TrackImpl videoTrack = new TrackImpl();
    videoTrack.setIdentifier("track-1");
    videoTrack.setFlavor(new MediaPackageElementFlavor("source", "presentation"));
    videoTrack.setURI(new URI("http://hostname/video.mp4"));
    videoTrack.addStream(new VideoStreamImpl());
    videoTrack.setDuration(1000000000000L);
    SmilResponse smilResponse = smilService.createNewSmil();
    smilResponse = smilService.addParallel(smilResponse.getSmil());
    SmilMediaContainer par = (SmilMediaContainer) smilResponse.getEntity();
    // add video track into parallel element
    smilResponse = smilService.addClip(smilResponse.getSmil(), par.getId(), videoTrack, 1000L, 1000000L);
    // logger.info(smilResponse.getSmil().toXML());
    SmilMediaObject media = null;
    for (SmilObject entity : smilResponse.getEntities()) {
        if (entity instanceof SmilMediaObject) {
            media = (SmilMediaObject) entity;
            break;
        }
    }
    assertNotNull(media);
    assertEquals(media.getId(), ((SmilMediaContainer) smilResponse.getSmil().getBody().getMediaElements().get(0)).getElements().get(0).getId());
    assertTrue(media instanceof SmilMediaVideoImpl);
    assertSame(((SmilMediaElement) media).getMediaType(), SmilMediaElement.MediaType.VIDEO);
    // 1000 milliseconds = 1 second
    assertEquals(1000L, ((SmilMediaElement) media).getClipBeginMS());
    // duration is 1000000 milliseconds = 1000 soconds
    // start + duration = 1s + 1000s = 1001s
    assertEquals(1001000L, ((SmilMediaElement) media).getClipEndMS());
    TrackImpl audioTrack = new TrackImpl();
    audioTrack.setIdentifier("track-2");
    audioTrack.setFlavor(new MediaPackageElementFlavor("source", "presenter"));
    audioTrack.setURI(new URI("http://hostname/audio.mp3"));
    audioTrack.addStream(new AudioStreamImpl());
    audioTrack.setDuration(1000000000000L);
    // add audio track into parallel element
    smilResponse = smilService.addClip(smilResponse.getSmil(), par.getId(), audioTrack, 1000L, 1000000L);
    // logger.info(smilResponse.getSmil().toXML());
    media = null;
    for (SmilObject entity : smilResponse.getEntities()) {
        if (entity instanceof SmilMediaObject) {
            media = (SmilMediaObject) entity;
            break;
        }
    }
    assertNotNull(media);
    assertEquals(media.getId(), ((SmilMediaContainer) smilResponse.getSmil().getBody().getMediaElements().get(0)).getElements().get(1).getId());
    assertTrue(media instanceof SmilMediaAudioImpl);
    assertSame(((SmilMediaElement) media).getMediaType(), SmilMediaElement.MediaType.AUDIO);
    // 1000 milliseconds = 1 second
    assertEquals(1000L, ((SmilMediaElement) media).getClipBeginMS());
    // duration is 1000000 milliseconds = 1000 soconds
    // start + duration = 1s + 1000s = 1001s
    assertEquals(1001000L, ((SmilMediaElement) media).getClipEndMS());
    // add new par
    smilResponse = smilService.addParallel(smilResponse.getSmil());
    par = (SmilMediaContainer) smilResponse.getEntity();
    // add tracks (as array) to par
    smilResponse = smilService.addClips(smilResponse.getSmil(), par.getId(), new Track[] { audioTrack, videoTrack }, 15000L, 1000L);
    // logger.info(smilResponse.getSmil().toXML());
    assertSame(2, smilResponse.getEntitiesCount());
    assertTrue(smilResponse.getEntities()[0] instanceof SmilMediaElement);
    // get audio element
    SmilMediaElement mediaElement = (SmilMediaElement) smilResponse.getEntities()[0];
    assertTrue(mediaElement.getMediaType() == SmilMediaElement.MediaType.AUDIO);
    // 15000ms = 15s
    assertEquals(15000L, mediaElement.getClipBeginMS());
    // start + duration = 15s + 1s = 16s
    assertEquals(16000L, mediaElement.getClipEndMS());
    // get video element
    mediaElement = (SmilMediaElement) smilResponse.getEntities()[1];
    assertTrue(mediaElement.getMediaType() == SmilMediaElement.MediaType.VIDEO);
    // 15000ms = 15s
    assertEquals(15000L, mediaElement.getClipBeginMS());
    // start + duration = 15s + 1s = 16s
    assertEquals(16000L, mediaElement.getClipEndMS());
}
Also used : SmilMediaVideoImpl(org.opencastproject.smil.entity.media.element.SmilMediaVideoImpl) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) SmilObject(org.opencastproject.smil.entity.api.SmilObject) AudioStreamImpl(org.opencastproject.mediapackage.track.AudioStreamImpl) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilMediaAudioImpl(org.opencastproject.smil.entity.media.element.SmilMediaAudioImpl) SmilMediaObject(org.opencastproject.smil.entity.media.api.SmilMediaObject) SmilMediaElement(org.opencastproject.smil.entity.media.element.api.SmilMediaElement) Track(org.opencastproject.mediapackage.Track) SmilMediaContainer(org.opencastproject.smil.entity.media.container.api.SmilMediaContainer) Test(org.junit.Test)

Example 3 with SmilResponse

use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.

the class SmilServiceImplTest method testRemoveSmilElement.

/**
 * Test of removeSmilElement method, of class SmilServiceImpl.
 */
@Test
public void testRemoveSmilElement() throws Exception {
    SmilResponse smilResponse = smilService.fromXml(TEST_SMIL);
    assertNotNull(smilResponse.getSmil());
    SmilMediaContainer par = (SmilMediaContainer) smilResponse.getSmil().getBody().getMediaElements().get(0);
    assertSame(2, par.getElements().size());
    // remove first element from parallel
    smilResponse = smilService.removeSmilElement(smilResponse.getSmil(), par.getElements().get(0).getId());
    assertTrue(smilResponse.getEntity() instanceof SmilMediaElement);
    assertSame(2, smilResponse.getSmil().getBody().getMediaElements().size());
    par = (SmilMediaContainer) smilResponse.getSmil().getBody().getMediaElements().get(0);
    assertSame(1, par.getElements().size());
    // remove parallel from smil
    smilResponse = smilService.removeSmilElement(smilResponse.getSmil(), par.getId());
    assertSame(1, smilResponse.getSmil().getBody().getMediaElements().size());
    assertEquals(par.getId(), smilResponse.getEntity().getId());
    // remove the same parallel again
    // should not fail
    // response should return the same smil without entities
    smilResponse = smilService.removeSmilElement(smilResponse.getSmil(), par.getId());
    assertSame(1, smilResponse.getSmil().getBody().getMediaElements().size());
    assertSame(0, smilResponse.getEntitiesCount());
}
Also used : SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilMediaElement(org.opencastproject.smil.entity.media.element.api.SmilMediaElement) SmilMediaContainer(org.opencastproject.smil.entity.media.container.api.SmilMediaContainer) Test(org.junit.Test)

Example 4 with SmilResponse

use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.

the class SilenceDetectionServiceImpl method generateSmil.

/**
 * Create a smil from given parameters.
 *
 * @param segments media segment list with timestamps
 * @param referenceTracks tracks to put as media segment source files
 * @return generated smil
 * @throws SmilException if smil creation failed
 */
protected Smil generateSmil(MediaSegments segments, List<Track> referenceTracks) throws SmilException {
    SmilResponse smilResponse = smilService.createNewSmil();
    Track[] referenceTracksArr = referenceTracks.toArray(new Track[referenceTracks.size()]);
    for (MediaSegment segment : segments.getMediaSegments()) {
        smilResponse = smilService.addParallel(smilResponse.getSmil());
        String parId = smilResponse.getEntity().getId();
        smilResponse = smilService.addClips(smilResponse.getSmil(), parId, referenceTracksArr, segment.getSegmentStart(), segment.getSegmentStop() - segment.getSegmentStart());
    }
    return smilResponse.getSmil();
}
Also used : MediaSegment(org.opencastproject.silencedetection.api.MediaSegment) SmilResponse(org.opencastproject.smil.api.SmilResponse) Track(org.opencastproject.mediapackage.Track)

Example 5 with SmilResponse

use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.

the class SmilResponseImplTest method testXml.

/**
 * Test of toXml and fromXml methods, of class SmilResponseImpl.
 */
@Test
public void testXml() throws Exception {
    Smil smil = new SmilImpl();
    SmilResponse response = new SmilResponseImpl(smil, new SmilObject[] { smil.getHead(), smil.getBody() });
    try {
        String xml = response.toXml();
        // logger.info(xml);
        assertNotNull(xml);
        // test xml contains smil element
        assertTrue(xml.contains("<smil"));
        // test xml contains head entity
        assertTrue(xml.contains("entity><head"));
        // test xml contains body entity
        assertTrue(xml.contains("entity><body"));
        SmilResponse responseUnmarshalled = SmilResponseImpl.fromXml(xml);
        assertNotNull(responseUnmarshalled);
        // test smil object id
        assertEquals(response.getSmil().getId(), responseUnmarshalled.getSmil().getId());
        // test entities
        assertSame(response.getEntitiesCount(), responseUnmarshalled.getEntitiesCount());
        assertEquals(response.getEntities()[0].getId(), responseUnmarshalled.getEntities()[0].getId());
        assertEquals(response.getEntities()[1].getId(), responseUnmarshalled.getEntities()[1].getId());
    } catch (JAXBException ex) {
        fail("can't (de-)serialize SmilResponse");
    }
}
Also used : SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilImpl(org.opencastproject.smil.entity.SmilImpl) JAXBException(javax.xml.bind.JAXBException) Smil(org.opencastproject.smil.entity.api.Smil) Test(org.junit.Test)

Aggregations

SmilResponse (org.opencastproject.smil.api.SmilResponse)30 Test (org.junit.Test)16 Smil (org.opencastproject.smil.entity.api.Smil)11 SmilMediaContainer (org.opencastproject.smil.entity.media.container.api.SmilMediaContainer)10 SmilException (org.opencastproject.smil.api.SmilException)8 URI (java.net.URI)7 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)7 Track (org.opencastproject.mediapackage.Track)7 SmilMediaElement (org.opencastproject.smil.entity.media.element.api.SmilMediaElement)7 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)6 VideoStreamImpl (org.opencastproject.mediapackage.track.VideoStreamImpl)6 SmilObject (org.opencastproject.smil.entity.api.SmilObject)6 SmilMediaObject (org.opencastproject.smil.entity.media.api.SmilMediaObject)6 ArrayList (java.util.ArrayList)5 POST (javax.ws.rs.POST)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)5 SmilImpl (org.opencastproject.smil.entity.SmilImpl)5 SmilMediaParamGroup (org.opencastproject.smil.entity.media.param.api.SmilMediaParamGroup)4