Search in sources :

Example 6 with SmilObject

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

the class SmilMediaParamGroupImpl 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 7 with SmilObject

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

the class SmilMediaParamGroupImpl method addParam.

/**
 * Add given {@link SmilMediaParam}.
 *
 * @param param to add
 */
public void addParam(SmilMediaParam param) {
    if (param == null) {
        return;
    }
    SmilObject p = getElementOrNull(param.getId());
    if (p != null && p instanceof SmilMediaParam) {
        ((SmilMediaParamImpl) p).setName(param.getName());
        ((SmilMediaParamImpl) p).setValue(param.getValue());
    } else {
        params.add(param);
    }
}
Also used : SmilMediaParam(org.opencastproject.smil.entity.media.param.api.SmilMediaParam) SmilObject(org.opencastproject.smil.entity.api.SmilObject)

Example 8 with SmilObject

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

the class SmilServiceImplTest method testAddClipWithParamGroupId.

/**
 * passing a previously created paramGroupId
 */
@Test
public void testAddClipWithParamGroupId() throws Exception {
    // first, create SMIL with 1 par, 1 video
    TrackImpl videoTrack = new TrackImpl();
    videoTrack.setIdentifier("presenter-track-1");
    videoTrack.setFlavor(new MediaPackageElementFlavor("source", "presenter"));
    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);
    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());
    // get param group id
    List<SmilMediaParamGroup> groups = smilResponse.getSmil().getHead().getParamGroups();
    assertEquals(1, groups.size());
    String paramGroupId = groups.get(0).getId();
    // then, create a 2nd par with 1 video with the same param group id
    TrackImpl videoTrack2 = new TrackImpl();
    videoTrack2.setIdentifier("presenter-track-2");
    videoTrack2.setFlavor(new MediaPackageElementFlavor("source2", "presenter"));
    videoTrack2.setURI(new URI("http://hostname/video2.mp4"));
    videoTrack2.addStream(new VideoStreamImpl());
    videoTrack2.setDuration(2000000000000L);
    smilResponse = smilService.addParallel(smilResponse.getSmil());
    SmilMediaContainer par2 = null;
    for (SmilObject entity : smilResponse.getEntities()) {
        if (entity instanceof SmilMediaContainer && !entity.getId().equals(par.getId())) {
            par2 = (SmilMediaContainer) entity;
            break;
        }
    }
    // add video track into parallel element
    smilResponse = smilService.addClip(smilResponse.getSmil(), par2.getId(), videoTrack2, 2000L, 2000000L, paramGroupId);
    SmilMediaObject media2 = null;
    for (SmilObject entity : smilResponse.getEntities()) {
        if (entity instanceof SmilMediaObject && !entity.getId().equals(media.getId())) {
            media2 = (SmilMediaObject) entity;
            break;
        }
    }
    assertNotNull(media2);
    SmilMediaElement mediaElement2 = (SmilMediaElement) ((SmilMediaContainer) smilResponse.getSmil().getBody().getMediaElements().get(1)).getElements().get(0);
    assertEquals(media2.getId(), mediaElement2.getId());
    assertTrue(media2 instanceof SmilMediaVideoImpl);
    assertSame(((SmilMediaElement) media2).getMediaType(), SmilMediaElement.MediaType.VIDEO);
    // 1000 milliseconds = 1 second
    assertEquals(2000L, ((SmilMediaElement) media2).getClipBeginMS());
    // duration is 2000000 milliseconds = 2000 seconds
    // start + duration = 2s + 2000s = 2002s
    assertEquals(2002000L, ((SmilMediaElement) media2).getClipEndMS());
    // make sure there's still 1 param group
    groups = smilResponse.getSmil().getHead().getParamGroups();
    assertEquals(1, groups.size());
    // make sure that the media element has the previous param groupo id
    assertEquals(paramGroupId, mediaElement2.getParamGroup());
}
Also used : SmilMediaVideoImpl(org.opencastproject.smil.entity.media.element.SmilMediaVideoImpl) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) SmilObject(org.opencastproject.smil.entity.api.SmilObject) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilMediaObject(org.opencastproject.smil.entity.media.api.SmilMediaObject) SmilMediaElement(org.opencastproject.smil.entity.media.element.api.SmilMediaElement) SmilMediaParamGroup(org.opencastproject.smil.entity.media.param.api.SmilMediaParamGroup) SmilMediaContainer(org.opencastproject.smil.entity.media.container.api.SmilMediaContainer) Test(org.junit.Test)

Example 9 with SmilObject

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

the class SmilServiceImpl method addClips.

/**
 * {@inheritDoc}
 */
@Override
public SmilResponse addClips(Smil smil, String parentId, Track[] tracks, long start, long duration) throws SmilException {
    List<SmilObject> trackEntities = new ArrayList<SmilObject>(tracks.length);
    List<SmilObject> otherEntities = new ArrayList<SmilObject>(tracks.length);
    for (Track track : tracks) {
        // add single clip and collect entities from response
        SmilResponse response = addClip(smil, parentId, track, start, duration);
        if (response.getEntitiesCount() == 1) {
            trackEntities.add(response.getEntity());
        } else {
            trackEntities.add(response.getEntities()[0]);
            for (int e = 1; e < response.getEntitiesCount(); e++) {
                otherEntities.add(response.getEntities()[e]);
            }
        }
    }
    // merge entities (track entities first)
    SmilObject[] entities = new SmilObject[trackEntities.size() + otherEntities.size()];
    for (int e = 0; e < entities.length; e++) {
        entities[e] = (e < trackEntities.size() ? trackEntities.get(e) : otherEntities.get(e - trackEntities.size()));
    }
    // create new response
    return new SmilResponseImpl(smil, entities);
}
Also used : SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilObject(org.opencastproject.smil.entity.api.SmilObject) ArrayList(java.util.ArrayList) Track(org.opencastproject.mediapackage.Track)

Example 10 with SmilObject

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

the class SmilResponseImplTest method testGetEntitiesCount.

/**
 * Test of getEntitiesCount method, of class SmilResponseImpl.
 */
@Test
public void testGetEntitiesCount() {
    Smil smil = new SmilImpl();
    SmilResponse response = new SmilResponseImpl(smil);
    assertSame(0, response.getEntitiesCount());
    response = new SmilResponseImpl(smil, smil.getBody());
    assertSame(1, response.getEntitiesCount());
    response = new SmilResponseImpl(smil, new SmilObject[] { smil.getHead(), smil.getBody() });
    assertSame(2, response.getEntitiesCount());
}
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) Test(org.junit.Test)

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