use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.
the class AnalyzeTracksWorkflowOperationHandler method start.
@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
logger.info("Running analyze-tracks workflow operation on workflow {}", workflowInstance.getId());
final MediaPackage mediaPackage = workflowInstance.getMediaPackage();
final String sourceFlavor = getConfig(workflowInstance, OPT_SOURCE_FLAVOR);
Map<String, String> properties = new HashMap<>();
final MediaPackageElementFlavor flavor = MediaPackageElementFlavor.parseFlavor(sourceFlavor);
final Track[] tracks = mediaPackage.getTracks(flavor);
if (tracks.length <= 0) {
if (BooleanUtils.toBoolean(getConfig(workflowInstance, OPT_FAIL_NO_TRACK, "false"))) {
throw new WorkflowOperationException("No matching tracks for flavor " + sourceFlavor);
}
logger.info("No tracks with specified flavors ({}) to analyse.", sourceFlavor);
return createResult(mediaPackage, properties, Action.CONTINUE, 0);
}
List<Fraction> aspectRatios = getAspectRatio(getConfig(workflowInstance, OPT_VIDEO_ASPECT, ""));
for (Track track : tracks) {
final String varName = toVariableName(track.getFlavor());
properties.put(varName + "_media", "true");
properties.put(varName + "_video", Boolean.toString(track.hasVideo()));
properties.put(varName + "_audio", Boolean.toString(track.hasAudio()));
// Check resolution
if (track.hasVideo()) {
for (VideoStream video : ((TrackImpl) track).getVideo()) {
// Set resolution variables
properties.put(varName + "_resolution_x", video.getFrameWidth().toString());
properties.put(varName + "_resolution_y", video.getFrameHeight().toString());
Fraction trackAspect = Fraction.getReducedFraction(video.getFrameWidth(), video.getFrameHeight());
properties.put(varName + "_aspect", trackAspect.toString());
properties.put(varName + "_framerate", video.getFrameRate().toString());
// Check if we should fall back to nearest defined aspect ratio
if (!aspectRatios.isEmpty()) {
trackAspect = getNearestAspectRatio(trackAspect, aspectRatios);
properties.put(varName + "_aspect_snap", trackAspect.toString());
}
}
}
}
logger.info("Finished analyze-tracks workflow operation adding the properties: {}", properties);
return createResult(mediaPackage, properties, Action.CONTINUE, 0);
}
use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.
the class CloneWorkflowOperationHandler method start.
/**
* {@inheritDoc}
*/
@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
logger.debug("Running clone workflow operation on workflow {}", workflowInstance.getId());
MediaPackage mediaPackage = workflowInstance.getMediaPackage();
WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation();
// Check which tags have been configured
String sourceTagsOption = StringUtils.trimToNull(currentOperation.getConfiguration(OPT_SOURCE_TAGS));
String sourceFlavorOption = StringUtils.trimToNull(currentOperation.getConfiguration(OPT_SOURCE_FLAVOR));
String targetFlavorOption = StringUtils.trimToNull(currentOperation.getConfiguration(OPT_TARGET_FLAVOR));
AbstractMediaPackageElementSelector<MediaPackageElement> elementSelector = new SimpleElementSelector();
// Make sure either one of tags or flavors are provided
if (StringUtils.isBlank(sourceTagsOption) && StringUtils.isBlank(sourceFlavorOption)) {
logger.info("No source tags or flavors have been specified, not matching anything. Operation will be skipped.");
return createResult(mediaPackage, Action.SKIP);
}
// if no source-favor is specified, all flavors will be checked for given tags
if (sourceFlavorOption == null) {
sourceFlavorOption = "*/*";
}
StringBuilder sb = new StringBuilder();
sb.append("Parameters passed to clone workflow operation:");
sb.append("\n source-tags: ").append(sourceTagsOption);
sb.append("\n source-flavor: ").append(sourceFlavorOption);
sb.append("\n target-flavor: ").append(targetFlavorOption);
logger.debug(sb.toString());
// Select the source flavors
MediaPackageElementFlavor sourceFlavor = MediaPackageElementFlavor.parseFlavor(sourceFlavorOption);
elementSelector.addFlavor(sourceFlavor);
// Select the source tags
for (String tag : asList(sourceTagsOption)) {
elementSelector.addTag(tag);
}
// Look for elements matching the tags and the flavor
Collection<MediaPackageElement> elements = elementSelector.select(mediaPackage, true);
// Check the the number of element returned
if (elements.size() == 0) {
// If no one found, we skip the operation
logger.debug("No matching elements found, skipping operation.");
return createResult(workflowInstance.getMediaPackage(), Action.SKIP);
} else {
logger.debug("Copy " + elements.size() + " elements to new flavor: {}", targetFlavorOption);
MediaPackageElementFlavor targetFlavor = MediaPackageElementFlavor.parseFlavor(targetFlavorOption);
for (MediaPackageElement element : elements) {
MediaPackageElementFlavor flavor;
// Take subtype either from option or from element (if option is *)
String subtype;
if ("*".equals(targetFlavor.getSubtype()))
subtype = element.getFlavor().getSubtype();
else
subtype = targetFlavor.getSubtype();
// Take type either from option or from element (if option is *)
if ("*".equals(targetFlavor.getType()))
flavor = new MediaPackageElementFlavor(element.getFlavor().getType(), subtype);
else
flavor = new MediaPackageElementFlavor(targetFlavor.getType(), subtype);
// Copy element and set new flavor
MediaPackageElement newElement = copyElement(element);
newElement.setFlavor(flavor);
mediaPackage.add(newElement);
}
}
return createResult(workflowInstance.getMediaPackage(), Action.CONTINUE);
}
use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.
the class CloneWorkflowOperationHandlerTest method testWildcardTargetFlavorTypeAndSubtype.
@Test
public void testWildcardTargetFlavorTypeAndSubtype() throws Exception {
// operation configuration
Map<String, String> configurations = new HashMap<String, String>();
configurations.put(CloneWorkflowOperationHandler.OPT_SOURCE_FLAVOR, "*/source");
configurations.put(CloneWorkflowOperationHandler.OPT_TARGET_FLAVOR, "*/*");
// run the operation handler
WorkflowOperationResult result = getWorkflowOperationResult(mp, configurations);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackageElementFlavor newFlavor = MediaPackageElementFlavor.parseFlavor("presentation/source");
Assert.assertTrue(result.getMediaPackage().getElementsByFlavor(newFlavor).length == 2);
newFlavor = MediaPackageElementFlavor.parseFlavor("presenter/source");
Assert.assertTrue(result.getMediaPackage().getElementsByFlavor(newFlavor).length == 2);
}
use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.
the class CloneWorkflowOperationHandlerTest method testWildcardTargetFlavorSubtype.
@Test
public void testWildcardTargetFlavorSubtype() throws Exception {
// operation configuration
Map<String, String> configurations = new HashMap<String, String>();
configurations.put(CloneWorkflowOperationHandler.OPT_SOURCE_FLAVOR, "*/source");
configurations.put(CloneWorkflowOperationHandler.OPT_TARGET_FLAVOR, "targettype/*");
// run the operation handler
WorkflowOperationResult result = getWorkflowOperationResult(mp, configurations);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackageElementFlavor newFlavor = MediaPackageElementFlavor.parseFlavor("targettype/source");
Assert.assertTrue(result.getMediaPackage().getElementsByFlavor(newFlavor).length == 2);
}
use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.
the class CloneWorkflowOperationHandlerTest method testWildcardSourceFlavor.
@Test
public void testWildcardSourceFlavor() throws Exception {
// operation configuration
Map<String, String> configurations = new HashMap<String, String>();
configurations.put(CloneWorkflowOperationHandler.OPT_SOURCE_FLAVOR, "*/source");
configurations.put(CloneWorkflowOperationHandler.OPT_TARGET_FLAVOR, "*/target");
// run the operation handler
WorkflowOperationResult result = getWorkflowOperationResult(mp, configurations);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackageElementFlavor newFlavor = MediaPackageElementFlavor.parseFlavor("*/target");
Assert.assertTrue(result.getMediaPackage().getElementsByFlavor(newFlavor).length == 2);
}
Aggregations