use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.
the class SmilServiceRest method removeSmilElement.
@POST
@Path("remove")
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
@RestQuery(name = "remove", description = "Remove an element with given Id from SMIL.", restParameters = { @RestParameter(name = "smil", description = "SMIL document.", isRequired = true, type = RestParameter.Type.TEXT), @RestParameter(name = "elementId", description = "Id of element to remove.", isRequired = true, type = RestParameter.Type.STRING) }, returnDescription = "Returns SMIL document without an element with given Id " + "(if SMIL document contains an element with given Id, this will be returned as entity).", reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "Removing element from SMIL successfull."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "SMIL document not valid.") })
public Response removeSmilElement(@FormParam("smil") String smil, @FormParam("elementId") String elementId) {
SmilResponse smilResponse = null;
try {
smilResponse = smilService.fromXml(smil);
smilResponse = smilService.removeSmilElement(smilResponse.getSmil(), elementId);
return Response.ok(smilResponse).build();
} catch (SmilException ex) {
logger.info(ex.getMessage(), ex);
return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("SMIL document invalid.").build();
}
}
use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.
the class ToolsEndpoint method createSmilCuttingCatalog.
/**
* Creates a SMIL cutting catalog based on the passed editing information and the media package.
*
* @param editingInfo
* the editing information
* @param mediaPackage
* the media package
* @return a SMIL catalog
* @throws SmilException
* if creating the SMIL catalog failed
*/
Smil createSmilCuttingCatalog(final EditingInfo editingInfo, final MediaPackage mediaPackage) throws SmilException {
// Create initial SMIL catalog
SmilResponse smilResponse = smilService.createNewSmil(mediaPackage);
// Add tracks to the SMIL catalog
ArrayList<Track> tracks = new ArrayList<>();
for (final String trackId : editingInfo.getConcatTracks()) {
Track track = mediaPackage.getTrack(trackId);
if (track == null) {
Opt<Track> trackOpt = getInternalPublication(mediaPackage).toStream().bind(new Fn<Publication, List<Track>>() {
@Override
public List<Track> apply(Publication a) {
return Arrays.asList(a.getTracks());
}
}).filter(new Fn<Track, Boolean>() {
@Override
public Boolean apply(Track a) {
return trackId.equals(a.getIdentifier());
}
}).head();
if (trackOpt.isNone())
throw new IllegalStateException(format("The track '%s' doesn't exist in media package '%s'", trackId, mediaPackage));
track = trackOpt.get();
}
tracks.add(track);
}
for (Tuple<Long, Long> segment : editingInfo.getConcatSegments()) {
smilResponse = smilService.addParallel(smilResponse.getSmil());
final String parentId = smilResponse.getEntity().getId();
final Long duration = segment.getB() - segment.getA();
smilResponse = smilService.addClips(smilResponse.getSmil(), parentId, tracks.toArray(new Track[tracks.size()]), segment.getA(), duration);
}
return smilResponse.getSmil();
}
use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.
the class ToolsEndpointTest method setUpClass.
@BeforeClass
public static void setUpClass() throws Exception {
/* Start of Smil mockups */
// Ugly, but strictly the smil APIs
String trackSrc = "http://mh-allinone.localdomain/archive/archive/mediapackage/0f2a2ada-0584-4d4d-a248-111f654aa217/6ec443e7-b097-4470-a618-5e0d848f5252/0/track.mp4";
URL smilUrl = ToolsEndpoint.class.getResource("/tools/smil1.xml");
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(trackSrc).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("presenter/work").anyTimes();
EasyMock.expect(param3.getId()).andReturn("param-1bd5e839-0a74-4310-b1d2-daba07914f79").anyTimes();
EasyMock.replay(param1, param2, param3);
List<SmilMediaParam> params = new ArrayList<>();
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<>();
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(0L).anyTimes();
EasyMock.expect(object1.getClipEndMS()).andReturn(2449L).anyTimes();
EasyMock.expect(object1.getSrc()).andReturn(new URI(trackSrc)).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(4922L).anyTimes();
EasyMock.expect(object2.getClipEndMS()).andReturn(11284L).anyTimes();
EasyMock.expect(object2.getSrc()).andReturn(new URI(trackSrc)).anyTimes();
EasyMock.replay(object2);
SmilMediaElement object3 = EasyMock.createNiceMock(SmilMediaElement.class);
EasyMock.expect(object3.isContainer()).andReturn(false).anyTimes();
EasyMock.expect(object3.getParamGroup()).andReturn(trackParamGroupId).anyTimes();
EasyMock.expect(object3.getClipBeginMS()).andReturn(14721L).anyTimes();
EasyMock.expect(object3.getClipEndMS()).andReturn(15963L).anyTimes();
EasyMock.expect(object3.getSrc()).andReturn(new URI(trackSrc)).anyTimes();
EasyMock.replay(object3);
SmilMediaElement object4 = EasyMock.createNiceMock(SmilMediaElement.class);
EasyMock.expect(object4.isContainer()).andReturn(false).anyTimes();
EasyMock.expect(object4.getParamGroup()).andReturn(trackParamGroupId).anyTimes();
EasyMock.expect(object4.getClipBeginMS()).andReturn(15963L).anyTimes();
EasyMock.expect(object4.getClipEndMS()).andReturn(20132L).anyTimes();
EasyMock.expect(object4.getSrc()).andReturn(new URI(trackSrc)).anyTimes();
EasyMock.replay(object4);
List<SmilMediaObject> objects1 = new ArrayList<>();
objects1.add(object1);
List<SmilMediaObject> objects2 = new ArrayList<>();
objects2.add(object2);
List<SmilMediaObject> objects3 = new ArrayList<>();
objects3.add(object3);
List<SmilMediaObject> objects4 = new ArrayList<>();
objects4.add(object4);
SmilMediaContainer objectContainer1 = EasyMock.createNiceMock(SmilMediaContainer.class);
EasyMock.expect(objectContainer1.isContainer()).andReturn(true).anyTimes();
EasyMock.expect(objectContainer1.getContainerType()).andReturn(SmilMediaContainer.ContainerType.PAR).anyTimes();
EasyMock.expect(objectContainer1.getElements()).andReturn(objects1).anyTimes();
EasyMock.replay(objectContainer1);
SmilMediaContainer objectContainer2 = EasyMock.createNiceMock(SmilMediaContainer.class);
EasyMock.expect(objectContainer2.isContainer()).andReturn(true).anyTimes();
EasyMock.expect(objectContainer2.getContainerType()).andReturn(SmilMediaContainer.ContainerType.PAR).anyTimes();
EasyMock.expect(objectContainer2.getElements()).andReturn(objects2).anyTimes();
EasyMock.replay(objectContainer2);
SmilMediaContainer objectContainer3 = EasyMock.createNiceMock(SmilMediaContainer.class);
EasyMock.expect(objectContainer3.isContainer()).andReturn(true).anyTimes();
EasyMock.expect(objectContainer3.getContainerType()).andReturn(SmilMediaContainer.ContainerType.PAR).anyTimes();
EasyMock.expect(objectContainer3.getElements()).andReturn(objects3).anyTimes();
EasyMock.replay(objectContainer3);
SmilMediaContainer objectContainer4 = EasyMock.createNiceMock(SmilMediaContainer.class);
EasyMock.expect(objectContainer4.isContainer()).andReturn(true).anyTimes();
EasyMock.expect(objectContainer4.getContainerType()).andReturn(SmilMediaContainer.ContainerType.PAR).anyTimes();
EasyMock.expect(objectContainer4.getElements()).andReturn(objects4).anyTimes();
EasyMock.replay(objectContainer4);
List<SmilMediaObject> containerObjects = new ArrayList<>();
containerObjects.add(objectContainer1);
containerObjects.add(objectContainer2);
containerObjects.add(objectContainer3);
containerObjects.add(objectContainer4);
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 smilService = EasyMock.createNiceMock(SmilService.class);
EasyMock.expect(smilService.fromXml((String) EasyMock.anyObject())).andReturn(response).anyTimes();
EasyMock.replay(smilService);
/* End of Smil API mockups */
endpoint = new ToolsEndpoint();
endpoint.setSmilService(smilService);
AdminUIConfiguration adminUIConfiguration = new AdminUIConfiguration();
Hashtable<String, String> dictionary = new Hashtable<>();
dictionary.put(AdminUIConfiguration.OPT_PREVIEW_SUBTYPE, "preview");
dictionary.put(AdminUIConfiguration.OPT_WAVEFORM_SUBTYPE, "waveform");
dictionary.put(AdminUIConfiguration.OPT_SMIL_CATALOG_FLAVOR, "smil/cutting");
dictionary.put(AdminUIConfiguration.OPT_SMIL_SILENCE_FLAVOR, "*/silence");
adminUIConfiguration.updated(dictionary);
endpoint.setAdminUIConfiguration(adminUIConfiguration);
}
use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.
the class VideoEditorWorkflowOperationHandler method replaceAllTracksWith.
protected Smil replaceAllTracksWith(Smil smil, Track[] otherTracks) throws SmilException {
SmilResponse smilResponse;
try {
// copy SMIL to work with
smilResponse = smilService.fromXml(smil.toXML());
} catch (Exception ex) {
throw new SmilException("Can not parse SMIL files.");
}
long start;
long end;
// iterate over all elements inside SMIL body
for (SmilMediaObject elem : smil.getBody().getMediaElements()) {
start = -1L;
end = -1L;
// body should contain par elements (container)
if (elem.isContainer()) {
// iterate over all elements in container
for (SmilMediaObject child : ((SmilMediaContainer) elem).getElements()) {
// second depth should contain media elements like audio or video
if (!child.isContainer() && child instanceof SmilMediaElement) {
SmilMediaElement media = (SmilMediaElement) child;
start = media.getClipBeginMS();
end = media.getClipEndMS();
// remove it
smilResponse = smilService.removeSmilElement(smilResponse.getSmil(), media.getId());
}
}
if (start != -1L && end != -1L) {
// add the new tracks inside
smilResponse = smilService.addClips(smilResponse.getSmil(), elem.getId(), otherTracks, start, end - start);
}
} else if (elem instanceof SmilMediaElement) {
throw new SmilException("Media elements inside SMIL body are not supported yet.");
}
}
return smilResponse.getSmil();
}
use of org.opencastproject.smil.api.SmilResponse in project opencast by opencast.
the class SmilServiceImplTest method testCreateNewSmil.
/**
* Test of createNewSmil methods, of class SmilServiceImpl.
*/
@Test
public void testCreateNewSmil() {
SmilResponse smilResponse = smilService.createNewSmil();
assertNotNull(smilResponse);
Smil smil = smilResponse.getSmil();
assertNotNull(smil);
// TODO: test with MediaPackage
}
Aggregations