Search in sources :

Example 91 with MediaPackageElementFlavor

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);
}
Also used : HashMap(java.util.HashMap) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) VideoStream(org.opencastproject.mediapackage.VideoStream) Fraction(org.apache.commons.lang3.math.Fraction) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Track(org.opencastproject.mediapackage.Track)

Example 92 with MediaPackageElementFlavor

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);
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) SimpleElementSelector(org.opencastproject.mediapackage.selector.SimpleElementSelector) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor)

Example 93 with MediaPackageElementFlavor

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);
}
Also used : HashMap(java.util.HashMap) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 94 with MediaPackageElementFlavor

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);
}
Also used : HashMap(java.util.HashMap) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 95 with MediaPackageElementFlavor

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);
}
Also used : HashMap(java.util.HashMap) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Aggregations

MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)109 MediaPackage (org.opencastproject.mediapackage.MediaPackage)49 Track (org.opencastproject.mediapackage.Track)34 URI (java.net.URI)31 Test (org.junit.Test)31 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)28 IOException (java.io.IOException)27 NotFoundException (org.opencastproject.util.NotFoundException)27 ArrayList (java.util.ArrayList)26 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)26 HashMap (java.util.HashMap)23 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)22 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)22 Job (org.opencastproject.job.api.Job)21 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)19 InputStream (java.io.InputStream)18 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)17 TrackSelector (org.opencastproject.mediapackage.selector.TrackSelector)16 File (java.io.File)13 Catalog (org.opencastproject.mediapackage.Catalog)13