use of org.opencastproject.smil.entity.api.Smil in project opencast by opencast.
the class VideoEditorServiceEndpoint method processSmil.
@POST
@Path("/process-smil")
@Produces({ MediaType.APPLICATION_XML })
@RestQuery(name = "processsmil", description = "Create smil processing jobs.", returnDescription = "Smil processing jobs.", restParameters = { @RestParameter(name = "smil", type = RestParameter.Type.TEXT, description = "Smil document to process.", isRequired = true) }, reponses = { @RestResponse(description = "Smil processing jobs created successfully.", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Internal server error.", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) })
public Response processSmil(@FormParam("smil") String smilStr) {
Smil smil;
try {
smil = smilService.fromXml(smilStr).getSmil();
List<Job> jobs = videoEditorService.processSmil(smil);
return Response.ok(new JaxbJobList(jobs)).build();
} catch (Exception ex) {
return Response.serverError().entity(ex.getMessage()).build();
}
}
use of org.opencastproject.smil.entity.api.Smil 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 */
}
use of org.opencastproject.smil.entity.api.Smil 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");
}
}
use of org.opencastproject.smil.entity.api.Smil in project opencast by opencast.
the class SmilResponseImplTest method testGetSmil.
/**
* Test of getSmil method, of class SmilResponseImpl.
*/
@Test
public void testGetSmil() {
Smil smil = new SmilImpl();
SmilResponse response = new SmilResponseImpl(smil);
assertEquals(smil, response.getSmil());
}
use of org.opencastproject.smil.entity.api.Smil 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");
}
}
Aggregations