use of org.opencastproject.workflow.api.WorkflowOperationResult in project opencast by opencast.
the class EmailWorkflowOperationHandlerTest method testDefaultBody.
@Test
public void testDefaultBody() throws Exception {
workflowInstance.setTitle("testDefaultBody");
operation.setConfiguration(EmailWorkflowOperationHandler.TO_PROPERTY, DEFAULT_TO);
operation.setConfiguration(EmailWorkflowOperationHandler.CC_PROPERTY, DEFAULT_CC);
operation.setConfiguration(EmailWorkflowOperationHandler.BCC_PROPERTY, DEFAULT_BCC);
operation.setConfiguration(EmailWorkflowOperationHandler.SUBJECT_PROPERTY, DEFAULT_SUBJECT);
WorkflowOperationResult result = operationHandler.start(workflowInstance, null);
Assert.assertEquals(Action.CONTINUE, result.getAction());
Assert.assertEquals(DEFAULT_TO, capturedTo.getValue());
Assert.assertEquals(DEFAULT_CC, capturedCC.getValue());
Assert.assertEquals(DEFAULT_BCC, capturedBCC.getValue());
Assert.assertEquals(DEFAULT_SUBJECT, capturedSubject.getValue());
Assert.assertEquals("Test Media Package(3e7bb56d-2fcc-4efe-9f0e-d6e56422f557)", capturedBody.getValue());
}
use of org.opencastproject.workflow.api.WorkflowOperationResult in project opencast by opencast.
the class AnalyzeAudioWorkflowOperationHandler method analyze.
private WorkflowOperationResult analyze(MediaPackage src, WorkflowOperationInstance operation) throws SoxException, IOException, NotFoundException, MediaPackageException, WorkflowOperationException, EncoderException {
MediaPackage mediaPackage = (MediaPackage) src.clone();
// Check which tags have been configured
String sourceTagsOption = StringUtils.trimToNull(operation.getConfiguration("source-tags"));
String sourceFlavorOption = StringUtils.trimToNull(operation.getConfiguration("source-flavor"));
String sourceFlavorsOption = StringUtils.trimToNull(operation.getConfiguration("source-flavors"));
boolean forceTranscode = BooleanUtils.toBoolean(operation.getConfiguration("force-transcode"));
AbstractMediaPackageElementSelector<Track> elementSelector = new TrackSelector();
// Make sure either one of tags or flavors are provided
if (StringUtils.isBlank(sourceTagsOption) && StringUtils.isBlank(sourceFlavorOption) && StringUtils.isBlank(sourceFlavorsOption)) {
logger.info("No source tags or flavors have been specified, not matching anything");
return createResult(mediaPackage, Action.CONTINUE);
}
// Select the source flavors
for (String flavor : asList(sourceFlavorsOption)) {
try {
elementSelector.addFlavor(MediaPackageElementFlavor.parseFlavor(flavor));
} catch (IllegalArgumentException e) {
throw new WorkflowOperationException("Source flavor '" + flavor + "' is malformed");
}
}
// Support legacy "source-flavor" option
if (StringUtils.isNotBlank(sourceFlavorOption)) {
String flavor = StringUtils.trim(sourceFlavorOption);
try {
elementSelector.addFlavor(MediaPackageElementFlavor.parseFlavor(flavor));
} catch (IllegalArgumentException e) {
throw new WorkflowOperationException("Source flavor '" + flavor + "' is malformed");
}
}
// Select the source tags
for (String tag : asList(sourceTagsOption)) {
elementSelector.addTag(tag);
}
// Look for elements matching the tag
Collection<Track> elements = elementSelector.select(mediaPackage, false);
// Analyze audio for all tracks found
long totalTimeInQueue = 0;
List<URI> cleanupURIs = new ArrayList<URI>();
Map<Job, Track> analyzeJobs = new HashMap<Job, Track>();
try {
for (Track track : elements) {
TrackImpl audioTrack = (TrackImpl) track;
// Skip video only mismatches
if (!track.hasAudio()) {
logger.info("Skipping audio analysis of '{}', since it contains no audio stream", track);
continue;
} else if (track.hasVideo() || forceTranscode) {
audioTrack = (TrackImpl) extractAudioTrack(track);
audioTrack.setAudio(((TrackImpl) track).getAudio());
cleanupURIs.add(audioTrack.getURI());
}
analyzeJobs.put(soxService.analyze(audioTrack), track);
}
if (analyzeJobs.isEmpty()) {
logger.info("No matching tracks found");
return createResult(mediaPackage, Action.CONTINUE);
}
// Wait for the jobs to return
if (!waitForStatus(analyzeJobs.keySet().toArray(new Job[analyzeJobs.size()])).isSuccess())
throw new WorkflowOperationException("One of the analyze jobs did not complete successfully");
// Process the result
for (Map.Entry<Job, Track> entry : analyzeJobs.entrySet()) {
Job job = entry.getKey();
TrackImpl origTrack = (TrackImpl) entry.getValue();
// add this receipt's queue time to the total
totalTimeInQueue += job.getQueueTime();
if (job.getPayload().length() > 0) {
TrackImpl analyzed = (TrackImpl) MediaPackageElementParser.getFromXml(job.getPayload());
// Set metadata on track
origTrack.setAudio(analyzed.getAudio());
} else {
logger.warn("Analyze audio job {} for track {} has no result!", job, origTrack);
}
}
} finally {
// Clean up temporary audio files from workspace
for (URI uri : cleanupURIs) {
workspace.delete(uri);
}
}
WorkflowOperationResult result = createResult(mediaPackage, Action.CONTINUE, totalTimeInQueue);
logger.debug("Analyze audio operation completed");
return result;
}
use of org.opencastproject.workflow.api.WorkflowOperationResult in project opencast by opencast.
the class NormalizeAudioWorkflowOperationHandler method normalize.
private WorkflowOperationResult normalize(MediaPackage src, WorkflowOperationInstance operation) throws SoxException, IOException, NotFoundException, MediaPackageException, WorkflowOperationException, EncoderException {
MediaPackage mediaPackage = (MediaPackage) src.clone();
// Check which tags have been configured
String sourceTagsOption = StringUtils.trimToNull(operation.getConfiguration("source-tags"));
String targetTagsOption = StringUtils.trimToNull(operation.getConfiguration("target-tags"));
String sourceFlavorOption = StringUtils.trimToNull(operation.getConfiguration("source-flavor"));
String sourceFlavorsOption = StringUtils.trimToNull(operation.getConfiguration("source-flavors"));
String targetFlavorOption = StringUtils.trimToNull(operation.getConfiguration("target-flavor"));
String targetDecibelString = StringUtils.trimToNull(operation.getConfiguration("target-decibel"));
if (targetDecibelString == null)
throw new IllegalArgumentException("target-decibel must be specified");
boolean forceTranscode = BooleanUtils.toBoolean(operation.getConfiguration("force-transcode"));
Float targetDecibel;
try {
targetDecibel = new Float(targetDecibelString);
} catch (NumberFormatException e1) {
throw new WorkflowOperationException("Unable to parse target-decibel " + targetDecibelString);
}
AbstractMediaPackageElementSelector<Track> elementSelector = new TrackSelector();
// Make sure either one of tags or flavors are provided
if (StringUtils.isBlank(sourceTagsOption) && StringUtils.isBlank(sourceFlavorOption) && StringUtils.isBlank(sourceFlavorsOption)) {
logger.info("No source tags or flavors have been specified, not matching anything");
return createResult(mediaPackage, Action.CONTINUE);
}
// Select the source flavors
for (String flavor : asList(sourceFlavorsOption)) {
try {
elementSelector.addFlavor(MediaPackageElementFlavor.parseFlavor(flavor));
} catch (IllegalArgumentException e) {
throw new WorkflowOperationException("Source flavor '" + flavor + "' is malformed");
}
}
// Support legacy "source-flavor" option
if (StringUtils.isNotBlank(sourceFlavorOption)) {
String flavor = StringUtils.trim(sourceFlavorOption);
try {
elementSelector.addFlavor(MediaPackageElementFlavor.parseFlavor(flavor));
} catch (IllegalArgumentException e) {
throw new WorkflowOperationException("Source flavor '" + flavor + "' is malformed");
}
}
// Select the source tags
for (String tag : asList(sourceTagsOption)) {
elementSelector.addTag(tag);
}
// Target tags
List<String> targetTags = asList(targetTagsOption);
// Target flavor
MediaPackageElementFlavor targetFlavor = null;
if (StringUtils.isNotBlank(targetFlavorOption)) {
try {
targetFlavor = MediaPackageElementFlavor.parseFlavor(targetFlavorOption);
} catch (IllegalArgumentException e) {
throw new WorkflowOperationException("Target flavor '" + targetFlavorOption + "' is malformed");
}
}
// Look for elements matching the tag
Collection<Track> elements = elementSelector.select(mediaPackage, false);
// Encode all tracks found
long totalTimeInQueue = 0;
List<URI> cleanupURIs = new ArrayList<URI>();
Map<Job, Track> normalizeJobs = new HashMap<Job, Track>();
try {
for (Track track : elements) {
TrackImpl audioTrack = (TrackImpl) track;
// Skip video only mismatches
if (!track.hasAudio()) {
logger.info("Skipping audio normalization of '{}', since it contains no audio stream", track);
continue;
} else if (track.hasVideo() || forceTranscode) {
audioTrack = (TrackImpl) extractAudioTrack(track);
audioTrack.setAudio(((TrackImpl) track).getAudio());
cleanupURIs.add(audioTrack.getURI());
}
// Analyze audio track
if (audioTrack.getAudio().size() < 1 || audioTrack.getAudio().get(0).getRmsLevDb() == null) {
logger.info("Audio track {} has no RMS Lev dB metadata, analyze it first", audioTrack);
Job analyzeJob = soxService.analyze(audioTrack);
if (!waitForStatus(analyzeJob).isSuccess())
throw new WorkflowOperationException("Unable to analyze the audio track " + audioTrack);
audioTrack = (TrackImpl) MediaPackageElementParser.getFromXml(analyzeJob.getPayload());
cleanupURIs.add(audioTrack.getURI());
}
normalizeJobs.put(soxService.normalize(audioTrack, targetDecibel), track);
}
if (normalizeJobs.isEmpty()) {
logger.info("No matching tracks found");
return createResult(mediaPackage, Action.CONTINUE);
}
// Wait for the jobs to return
if (!waitForStatus(normalizeJobs.keySet().toArray(new Job[normalizeJobs.size()])).isSuccess())
throw new WorkflowOperationException("One of the normalize jobs did not complete successfully");
// Process the result
for (Map.Entry<Job, Track> entry : normalizeJobs.entrySet()) {
Job job = entry.getKey();
TrackImpl origTrack = (TrackImpl) entry.getValue();
// add this receipt's queue time to the total
totalTimeInQueue += job.getQueueTime();
if (job.getPayload().length() > 0) {
TrackImpl normalizedAudioTrack = (TrackImpl) MediaPackageElementParser.getFromXml(job.getPayload());
TrackImpl resultTrack = normalizedAudioTrack;
if (origTrack.hasVideo() || forceTranscode) {
cleanupURIs.add(normalizedAudioTrack.getURI());
logger.info("Mux normalized audio track {} to video track {}", normalizedAudioTrack, origTrack);
Job muxAudioVideo = composerService.mux(origTrack, normalizedAudioTrack, SOX_AREPLACE_PROFILE);
if (!waitForStatus(muxAudioVideo).isSuccess())
throw new WorkflowOperationException("Muxing normalized audio track " + normalizedAudioTrack + " to video container " + origTrack + " failed");
resultTrack = (TrackImpl) MediaPackageElementParser.getFromXml(muxAudioVideo.getPayload());
// Set metadata on track
extendAudioStream(resultTrack, normalizedAudioTrack);
}
adjustFlavorAndTags(targetTags, targetFlavor, origTrack, resultTrack);
mediaPackage.addDerived(resultTrack, origTrack);
String fileName = getFileNameFromElements(origTrack, resultTrack);
resultTrack.setURI(workspace.moveTo(resultTrack.getURI(), mediaPackage.getIdentifier().toString(), resultTrack.getIdentifier(), fileName));
} else {
logger.warn("Normalize audio job {} for track {} has no result!", job, origTrack);
}
}
} finally {
// Clean up temporary audio and video files from workspace
for (URI uri : cleanupURIs) {
workspace.delete(uri);
}
}
WorkflowOperationResult result = createResult(mediaPackage, Action.CONTINUE, totalTimeInQueue);
logger.debug("Normalize audio operation completed");
return result;
}
use of org.opencastproject.workflow.api.WorkflowOperationResult in project opencast by opencast.
the class AnalyzeAudioWorkflowOperationHandlerTest method testAudio.
@Test
public void testAudio() throws Exception {
operationInstance.setConfiguration("source-tags", "");
operationInstance.setConfiguration("source-flavor", "*/audio");
operationInstance.setConfiguration("source-flavors", "");
operationInstance.setConfiguration("force-transcode", "false");
WorkflowOperationResult result = operationHandler.start(instance, null);
Assert.assertEquals(Action.CONTINUE, result.getAction());
Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 3, result.getMediaPackage().getElements().length);
Track[] tracks = result.getMediaPackage().getTracks(new MediaPackageElementFlavor("presentation", "audio"));
Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 1, tracks.length);
TrackImpl audioVideo = (TrackImpl) tracks[0];
Assert.assertEquals(-20f, audioVideo.getAudio().get(0).getRmsLevDb().floatValue(), 0.001d);
}
use of org.opencastproject.workflow.api.WorkflowOperationResult in project opencast by opencast.
the class NormalizeAudioWorkflowOperationHandlerTest method testAudioVideo.
@Test
public void testAudioVideo() throws Exception {
operationInstance.setConfiguration("source-tags", "");
operationInstance.setConfiguration("source-flavor", "*/video-audio");
operationInstance.setConfiguration("source-flavors", "");
operationInstance.setConfiguration("target-flavor", "*/normalized");
operationInstance.setConfiguration("target-tags", "norm");
operationInstance.setConfiguration("force-transcode", "false");
operationInstance.setConfiguration("target-decibel", "-30");
WorkflowOperationResult result = operationHandler.start(instance, null);
Assert.assertEquals(Action.CONTINUE, result.getAction());
Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 4, result.getMediaPackage().getElements().length);
Track[] tracks = result.getMediaPackage().getTracks(new MediaPackageElementFlavor("presentation", "normalized"));
Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 1, tracks.length);
Assert.assertTrue(tracks[0].containsTag("norm"));
TrackImpl audioVideo = (TrackImpl) tracks[0];
Assert.assertEquals(-30f, audioVideo.getAudio().get(0).getRmsLevDb().floatValue(), 0.001d);
tracks = result.getMediaPackage().getTracks(new MediaPackageElementFlavor("presentation", "video-audio"));
Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 1, tracks.length);
audioVideo = (TrackImpl) tracks[0];
Assert.assertNull(audioVideo.getAudio().get(0).getRmsLevDb());
}
Aggregations