Search in sources :

Example 1 with SmilObject

use of org.opencastproject.smil.entity.api.SmilObject 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 2 with SmilObject

use of org.opencastproject.smil.entity.api.SmilObject in project opencast by opencast.

the class SmilMediaElementImpl method putAllChilds.

/**
 * {@inheritDoc}
 */
@Override
public void putAllChilds(List<SmilObject> elements) {
    for (SmilObject child : getParams()) {
        elements.add(child);
        ((SmilObjectImpl) child).putAllChilds(elements);
    }
}
Also used : SmilObjectImpl(org.opencastproject.smil.entity.SmilObjectImpl) SmilObject(org.opencastproject.smil.entity.api.SmilObject)

Example 3 with SmilObject

use of org.opencastproject.smil.entity.api.SmilObject in project opencast by opencast.

the class SmilResponseImplTest method testGetEntities.

/**
 * Test of getEntities method, of class SmilResponseImpl.
 */
@Test
public void testGetEntities() throws Exception {
    Smil smil = new SmilImpl();
    SmilResponse response = new SmilResponseImpl(smil);
    try {
        response.getEntities();
        fail("getEntities should fail, if entity count is zero");
    } catch (SmilException ex) {
    }
    response = new SmilResponseImpl(smil, smil.getBody());
    try {
        SmilObject[] entities = response.getEntities();
        assertSame(1, entities.length);
        assertSame(smil.getBody(), entities[0]);
    } catch (SmilException ex) {
        fail("getEntities should not throw an Exception if some entities are set");
    }
    response = new SmilResponseImpl(smil, new SmilObject[] { smil.getHead(), smil.getBody() });
    try {
        SmilObject[] entities = response.getEntities();
        assertSame(2, entities.length);
        assertSame(smil.getHead(), entities[0]);
        assertSame(smil.getBody(), entities[1]);
    } catch (SmilException ex) {
        fail("getEntities should not throw an Exception if some entities are set");
    }
}
Also used : SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilImpl(org.opencastproject.smil.entity.SmilImpl) SmilObject(org.opencastproject.smil.entity.api.SmilObject) Smil(org.opencastproject.smil.entity.api.Smil) SmilException(org.opencastproject.smil.api.SmilException) Test(org.junit.Test)

Example 4 with SmilObject

use of org.opencastproject.smil.entity.api.SmilObject in project opencast by opencast.

the class SmilImpl method removeElement.

/**
 * {@inheritDoc}
 */
@Override
public SmilObject removeElement(String elementId) {
    SmilObject child = null;
    if (head.getId().equals(elementId)) {
        child = head;
        head = null;
        return child;
    }
    if (body.getId().equals(elementId)) {
        child = body;
        body = null;
        return child;
    }
    child = ((SmilObjectImpl) head).removeElement(elementId);
    if (child != null) {
        return child;
    }
    child = ((SmilObjectImpl) body).removeElement(elementId);
    if (child != null && child instanceof SmilMediaElement) {
        // media elements can reference paramGroup element
        // remove linked paramGroup, if it is not referenced by another element
        String paramGroupId = ((SmilMediaElement) child).getParamGroup();
        if (paramGroupId != null && !paramGroupId.isEmpty()) {
            List<SmilObject> childs = new LinkedList<SmilObject>();
            putAllChilds(childs);
            for (SmilObject c : childs) {
                if (c instanceof SmilMediaElement && paramGroupId.equals(((SmilMediaElement) c).getParamGroup())) {
                    // set paramGroup to null, to prevent delete operation
                    paramGroupId = null;
                    break;
                }
            }
            if (paramGroupId != null) {
                removeElement(paramGroupId);
            }
        }
    }
    return child;
}
Also used : SmilObject(org.opencastproject.smil.entity.api.SmilObject) SmilMediaElement(org.opencastproject.smil.entity.media.element.api.SmilMediaElement) LinkedList(java.util.LinkedList)

Example 5 with SmilObject

use of org.opencastproject.smil.entity.api.SmilObject in project opencast by opencast.

the class SmilMediaContainerImpl method putAllChilds.

/**
 * {@inheritDoc}
 */
@Override
public void putAllChilds(List<SmilObject> elements) {
    for (SmilObject child : getElements()) {
        elements.add(child);
        ((SmilObjectImpl) child).putAllChilds(elements);
    }
}
Also used : SmilObjectImpl(org.opencastproject.smil.entity.SmilObjectImpl) SmilObject(org.opencastproject.smil.entity.api.SmilObject)

Aggregations

SmilObject (org.opencastproject.smil.entity.api.SmilObject)14 SmilResponse (org.opencastproject.smil.api.SmilResponse)6 Test (org.junit.Test)5 SmilImpl (org.opencastproject.smil.entity.SmilImpl)3 SmilObjectImpl (org.opencastproject.smil.entity.SmilObjectImpl)3 Smil (org.opencastproject.smil.entity.api.Smil)3 SmilMediaElement (org.opencastproject.smil.entity.media.element.api.SmilMediaElement)3 URI (java.net.URI)2 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)2 Track (org.opencastproject.mediapackage.Track)2 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)2 VideoStreamImpl (org.opencastproject.mediapackage.track.VideoStreamImpl)2 SmilException (org.opencastproject.smil.api.SmilException)2 SmilMediaObject (org.opencastproject.smil.entity.media.api.SmilMediaObject)2 SmilMediaContainer (org.opencastproject.smil.entity.media.container.api.SmilMediaContainer)2 SmilMediaVideoImpl (org.opencastproject.smil.entity.media.element.SmilMediaVideoImpl)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 AudioStreamImpl (org.opencastproject.mediapackage.track.AudioStreamImpl)1 SmilMeta (org.opencastproject.smil.entity.api.SmilMeta)1