use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.
the class SmilServiceImplTest method testFromXml.
/**
* Test of fromXml methods, of class SmilServiceImpl.
*/
@Test
public void testFromXml() throws Exception {
SmilResponse smilResponse = smilService.fromXml(TEST_SMIL);
assertNotNull(smilResponse.getSmil());
Smil smil = smilResponse.getSmil();
// test head
assertSame(2, smil.getHead().getParamGroups().size());
// test body
assertSame(2, smil.getBody().getMediaElements().size());
assertTrue(smil.getBody().getMediaElements().get(0) instanceof SmilMediaParallelImpl);
assertTrue(smil.getBody().getMediaElements().get(1) instanceof SmilMediaParallelImpl);
SmilMediaContainer par = (SmilMediaContainer) smil.getBody().getMediaElements().get(0);
assertSame(2, par.getElements().size());
assertTrue(par.getElements().get(0) instanceof SmilMediaVideoImpl);
assertTrue(par.getElements().get(1) instanceof SmilMediaAudioImpl);
}
use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.
the class SmilServiceImplTest method testAddClipWithInvalidTrackURI.
@Test(expected = SmilException.class)
public void testAddClipWithInvalidTrackURI() throws Exception {
TrackImpl videoTrack = new TrackImpl();
videoTrack.setIdentifier("track-1");
videoTrack.setFlavor(new MediaPackageElementFlavor("source", "presentation"));
videoTrack.addStream(new VideoStreamImpl());
videoTrack.setDuration(Long.MAX_VALUE);
// no track URI set
SmilResponse smilResponse = smilService.createNewSmil();
smilResponse = smilService.addClip(smilResponse.getSmil(), null, videoTrack, 0, 10);
fail("SmilException schould be thrown if you try to add an invalid track.");
}
use of org.opencastproject.smil.api.SmilResponse 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());
}
use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.
the class SmilServiceImplTest method testAddSequence.
/**
* Test of addSequence methods, of class SmilServiceImpl.
*/
@Test
public void testAddSequence() throws Exception {
SmilResponse smilResponse = smilService.createNewSmil();
smilResponse = smilService.addSequence(smilResponse.getSmil());
assertNotNull(smilResponse.getSmil().getBody().getMediaElements().get(0));
assertEquals(smilResponse.getSmil().getBody().getMediaElements().get(0), smilResponse.getEntity());
assertTrue(smilResponse.getSmil().getBody().getMediaElements().get(0) instanceof SmilMediaSequenceImpl);
SmilMediaContainer par = (SmilMediaContainer) smilResponse.getEntity();
assertTrue(par.isContainer());
assertSame(SmilMediaContainer.ContainerType.SEQ, par.getContainerType());
smilResponse = smilService.addSequence(smilResponse.getSmil(), smilResponse.getEntity().getId());
assertNotNull(smilResponse.getSmil().getBody().getMediaElements().get(0));
assertTrue(smilResponse.getSmil().getBody().getMediaElements().get(0) instanceof SmilMediaSequenceImpl);
SmilMediaContainer parent = (SmilMediaContainer) smilResponse.getSmil().getBody().getMediaElements().get(0);
assertNotNull(parent.getElements().get(0));
assertTrue(parent.getElements().get(0) instanceof SmilMediaSequenceImpl);
assertEquals(parent.getElements().get(0).getId(), smilResponse.getEntity().getId());
// logger.info(((SmilImpl)smilResponse.getSmil()).toXML());
}
use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.
the class SmilServiceImplTest method testAddClipStartValueBiggerThanDuration.
@Test(expected = SmilException.class)
public void testAddClipStartValueBiggerThanDuration() 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(new Long(1000));
SmilResponse smilResponse = smilService.createNewSmil();
smilResponse = smilService.addClip(smilResponse.getSmil(), null, videoTrack, 1000, 10);
fail("Sequence start value is equal track duration but SmilService does not throw an SmilException.");
}
Aggregations