@Test public void testStart() throws MediaPackageException, WorkflowOperationException { MediaPackage mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew(); VideoStreamImpl videoStream = new VideoStreamImpl("234"); videoStream.setFrameWidth(1280); videoStream.setFrameHeight(720); TrackImpl track = new TrackImpl(); track.setFlavor(MediaPackageElementFlavor.parseFlavor("presenter/source")); track.addStream(videoStream); JobContext jobContext = EasyMock.createMock(JobContext.class); EasyMock.replay(jobContext); WorkflowOperationInstance operationInstance = EasyMock.createMock(WorkflowOperationInstance.class); String[][] config = { { ProbeResolutionWorkflowOperationHandler.OPT_SOURCE_FLAVOR, "*/source"}, { ProbeResolutionWorkflowOperationHandler.OPT_VAR_PREFIX + "aspect", "1280x720,1280x700"}, { ProbeResolutionWorkflowOperationHandler.OPT_VAL_PREFIX + "aspect", "16/9"}, { ProbeResolutionWorkflowOperationHandler.OPT_VAR_PREFIX + "is_720", "1280x720,1280x700"}, { ProbeResolutionWorkflowOperationHandler.OPT_VAR_PREFIX + "is_1080", "1920x1080"}}; Set<String> keys = new HashSet<>(); for (String[] cfg: config) { keys.add(cfg[0]); EasyMock.expect(operationInstance.getConfiguration(cfg[0])).andReturn(cfg[1]).anyTimes(); } EasyMock.expect(operationInstance.getConfigurationKeys()).andReturn(keys).anyTimes(); EasyMock.replay(operationInstance); WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class); EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes(); EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(operationInstance).anyTimes(); EasyMock.replay(workflowInstance); assertEquals(null, operationHandler.start(workflowInstance, jobContext).getProperties()); mediaPackage.add(track); WorkflowOperationResult workflowOperationResult = operationHandler.start(workflowInstance, jobContext); Map<String, String> properties = workflowOperationResult.getProperties(); String[][] props = { {"presenter_source_aspect", "16/9"}, {"presenter_source_is_720", "true"}, {"presenter_source_is_1080", null}}; for (String[] prop: props) { assertEquals(prop[1], properties.get(prop[0])); } }
@Override public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { logger.info("Running probe-resolution workflow operation"); final MediaPackage mediaPackage = workflowInstance.getMediaPackage(); final String sourceFlavorName = getConfig(workflowInstance, OPT_SOURCE_FLAVOR); final MediaPackageElementFlavor sourceFlavor = MediaPackageElementFlavor.parseFlavor(sourceFlavorName); final Track[] tracks = mediaPackage.getTracks(sourceFlavor); if (tracks.length <= 0) { logger.info("No tracks with specified flavor ({}).", sourceFlavorName); return createResult(mediaPackage, Action.CONTINUE); } Map<Fraction, Set<String>> resolutionMapping = new HashMap<>(); for (String key: workflowInstance.getCurrentOperation().getConfigurationKeys()) { if (key.startsWith(OPT_VAR_PREFIX)) { String varName = key.substring(OPT_VAR_PREFIX.length()); for (Fraction resolution: getResolutions(getConfig(workflowInstance, key))) { if (!resolutionMapping.containsKey(resolution)) { resolutionMapping.put(resolution, new HashSet<String>()); } resolutionMapping.get(resolution).add(varName); } } } Map<String, String> valueMapping = new HashMap<>(); for (String key: workflowInstance.getCurrentOperation().getConfigurationKeys()) { if (key.startsWith(OPT_VAL_PREFIX)) { String varName = key.substring(OPT_VAL_PREFIX.length()); valueMapping.put(varName, getConfig(workflowInstance, key)); } } Map<String, String> properties = new HashMap<String, String>(); for (Track track : tracks) { final String flavor = toVariableName(track.getFlavor()); if (track.hasVideo()) { for (VideoStream video: ((TrackImpl) track).getVideo()) { Fraction resolution = Fraction.getFraction(video.getFrameWidth(), video.getFrameHeight()); if (resolutionMapping.containsKey(resolution)) { for (String varName : resolutionMapping.get(resolution)) { String value = valueMapping.containsKey(varName) ? valueMapping.get(varName) : "true"; properties.put(flavor + varName, value); } } } } } logger.info("Finished workflow operation adding the properties: {}", properties); return createResult(mediaPackage, properties, Action.CONTINUE, 0); }
ProbeResolutionWorkflowOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { logger.info("Running probe-resolution workflow operation"); final MediaPackage mediaPackage = workflowInstance.getMediaPackage(); final String sourceFlavorName = getConfig(workflowInstance, OPT_SOURCE_FLAVOR); final MediaPackageElementFlavor sourceFlavor = MediaPackageElementFlavor.parseFlavor(sourceFlavorName); final Track[] tracks = mediaPackage.getTracks(sourceFlavor); if (tracks.length <= 0) { logger.info("No tracks with specified flavor ({}).", sourceFlavorName); return createResult(mediaPackage, Action.CONTINUE); } Map<Fraction, Set<String>> resolutionMapping = new HashMap<>(); for (String key: workflowInstance.getCurrentOperation().getConfigurationKeys()) { if (key.startsWith(OPT_VAR_PREFIX)) { String varName = key.substring(OPT_VAR_PREFIX.length()); for (Fraction resolution: getResolutions(getConfig(workflowInstance, key))) { if (!resolutionMapping.containsKey(resolution)) { resolutionMapping.put(resolution, new HashSet<String>()); } resolutionMapping.get(resolution).add(varName); } } } Map<String, String> valueMapping = new HashMap<>(); for (String key: workflowInstance.getCurrentOperation().getConfigurationKeys()) { if (key.startsWith(OPT_VAL_PREFIX)) { String varName = key.substring(OPT_VAL_PREFIX.length()); valueMapping.put(varName, getConfig(workflowInstance, key)); } } Map<String, String> properties = new HashMap<String, String>(); for (Track track : tracks) { final String flavor = toVariableName(track.getFlavor()); if (track.hasVideo()) { for (VideoStream video: ((TrackImpl) track).getVideo()) { Fraction resolution = Fraction.getFraction(video.getFrameWidth(), video.getFrameHeight()); if (resolutionMapping.containsKey(resolution)) { for (String varName : resolutionMapping.get(resolution)) { String value = valueMapping.containsKey(varName) ? valueMapping.get(varName) : "true"; properties.put(flavor + varName, value); } } } } } logger.info("Finished workflow operation adding the properties: {}", properties); return createResult(mediaPackage, properties, Action.CONTINUE, 0); } }
ProbeResolutionWorkflowOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { logger.info("Running probe-resolution workflow operation"); final MediaPackage mediaPackage = workflowInstance.getMediaPackage(); final String sourceFlavorName = getConfig(workflowInstance, OPT_SOURCE_FLAVOR); final MediaPackageElementFlavor sourceFlavor = MediaPackageElementFlavor.parseFlavor(sourceFlavorName); final Track[] tracks = mediaPackage.getTracks(sourceFlavor); if (tracks.length <= 0) { logger.info("No tracks with specified flavor ({}).", sourceFlavorName); return createResult(mediaPackage, Action.CONTINUE); } Map<Fraction, Set<String>> resolutionMapping = new HashMap<>(); for (String key: workflowInstance.getCurrentOperation().getConfigurationKeys()) { if (key.startsWith(OPT_VAR_PREFIX)) { String varName = key.substring(OPT_VAR_PREFIX.length()); for (Fraction resolution: getResolutions(getConfig(workflowInstance, key))) { if (!resolutionMapping.containsKey(resolution)) { resolutionMapping.put(resolution, new HashSet<String>()); } resolutionMapping.get(resolution).add(varName); } } } Map<String, String> valueMapping = new HashMap<>(); for (String key: workflowInstance.getCurrentOperation().getConfigurationKeys()) { if (key.startsWith(OPT_VAL_PREFIX)) { String varName = key.substring(OPT_VAL_PREFIX.length()); valueMapping.put(varName, getConfig(workflowInstance, key)); } } Map<String, String> properties = new HashMap<String, String>(); for (Track track : tracks) { final String flavor = toVariableName(track.getFlavor()); if (track.hasVideo()) { for (VideoStream video: ((TrackImpl) track).getVideo()) { Fraction resolution = Fraction.getFraction(video.getFrameWidth(), video.getFrameHeight()); if (resolutionMapping.containsKey(resolution)) { for (String varName : resolutionMapping.get(resolution)) { String value = valueMapping.containsKey(varName) ? valueMapping.get(varName) : "true"; properties.put(flavor + varName, value); } } } } } logger.info("Finished workflow operation adding the properties: {}", properties); return createResult(mediaPackage, properties, Action.CONTINUE, 0); }  }
ProbeResolutionWorkflowOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { logger.info("Running probe-resolution workflow operation"); final MediaPackage mediaPackage = workflowInstance.getMediaPackage(); final String sourceFlavorName = getConfig(workflowInstance, OPT_SOURCE_FLAVOR); final MediaPackageElementFlavor sourceFlavor = MediaPackageElementFlavor.parseFlavor(sourceFlavorName); final Track[] tracks = mediaPackage.getTracks(sourceFlavor); if (tracks.length <= 0) { logger.info("No tracks with specified flavor ({}).", sourceFlavorName); return createResult(mediaPackage, Action.CONTINUE); } Map<Fraction, Set<String>> resolutionMapping = new HashMap<>(); for (String key: workflowInstance.getCurrentOperation().getConfigurationKeys()) { if (key.startsWith(OPT_VAR_PREFIX)) { String varName = key.substring(OPT_VAR_PREFIX.length()); for (Fraction resolution: getResolutions(getConfig(workflowInstance, key))) { if (!resolutionMapping.containsKey(resolution)) { resolutionMapping.put(resolution, new HashSet<String>()); } resolutionMapping.get(resolution).add(varName); } } } Map<String, String> valueMapping = new HashMap<>(); for (String key: workflowInstance.getCurrentOperation().getConfigurationKeys()) { if (key.startsWith(OPT_VAL_PREFIX)) { String varName = key.substring(OPT_VAL_PREFIX.length()); valueMapping.put(varName, getConfig(workflowInstance, key)); } } Map<String, String> properties = new HashMap<String, String>(); for (Track track : tracks) { final String flavor = toVariableName(track.getFlavor()); if (track.hasVideo()) { for (VideoStream video: ((TrackImpl) track).getVideo()) { Fraction resolution = Fraction.getFraction(video.getFrameWidth(), video.getFrameHeight()); if (resolutionMapping.containsKey(resolution)) { for (String varName : resolutionMapping.get(resolution)) { String value = valueMapping.containsKey(varName) ? valueMapping.get(varName) : "true"; properties.put(flavor + varName, value); } } } } } logger.info("Finished workflow operation adding the properties: {}", properties); return createResult(mediaPackage, properties, Action.CONTINUE, 0); }  @Override WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context); }
ProbeResolutionWorkflowOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { logger.info("Running probe-resolution workflow operation"); final MediaPackage mediaPackage = workflowInstance.getMediaPackage(); final String sourceFlavorName = getConfig(workflowInstance, OPT_SOURCE_FLAVOR); final MediaPackageElementFlavor sourceFlavor = MediaPackageElementFlavor.parseFlavor(sourceFlavorName); final Track[] tracks = mediaPackage.getTracks(sourceFlavor); if (tracks.length <= 0) { logger.info("No tracks with specified flavor ({}).", sourceFlavorName); return createResult(mediaPackage, Action.CONTINUE); } Map<Fraction, Set<String>> resolutionMapping = new HashMap<>(); for (String key: workflowInstance.getCurrentOperation().getConfigurationKeys()) { if (key.startsWith(OPT_VAR_PREFIX)) { String varName = key.substring(OPT_VAR_PREFIX.length()); for (Fraction resolution: getResolutions(getConfig(workflowInstance, key))) { if (!resolutionMapping.containsKey(resolution)) { resolutionMapping.put(resolution, new HashSet<String>()); } resolutionMapping.get(resolution).add(varName); } } } Map<String, String> valueMapping = new HashMap<>(); for (String key: workflowInstance.getCurrentOperation().getConfigurationKeys()) { if (key.startsWith(OPT_VAL_PREFIX)) { String varName = key.substring(OPT_VAL_PREFIX.length()); valueMapping.put(varName, getConfig(workflowInstance, key)); } } Map<String, String> properties = new HashMap<String, String>(); for (Track track : tracks) { final String flavor = toVariableName(track.getFlavor()); if (track.hasVideo()) { for (VideoStream video: ((TrackImpl) track).getVideo()) { Fraction resolution = Fraction.getFraction(video.getFrameWidth(), video.getFrameHeight()); if (resolutionMapping.containsKey(resolution)) { for (String varName : resolutionMapping.get(resolution)) { String value = valueMapping.containsKey(varName) ? valueMapping.get(varName) : "true"; properties.put(flavor + varName, value); } } } } } logger.info("Finished workflow operation adding the properties: {}", properties); return createResult(mediaPackage, properties, Action.CONTINUE, 0); }  @Override WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context);  }