Search in sources :

Example 66 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class ComposerServiceImpl method image.

@Override
public Job image(Track sourceTrack, String profileId, Map<String, String> properties) throws EncoderException, MediaPackageException {
    if (sourceTrack == null)
        throw new IllegalArgumentException("SourceTrack cannot be null");
    List<String> arguments = new ArrayList<String>();
    arguments.add(profileId);
    arguments.add(MediaPackageElementParser.getAsXml(sourceTrack));
    arguments.add(Boolean.FALSE.toString());
    arguments.add(getPropertiesAsString(properties));
    try {
        final EncodingProfile profile = profileScanner.getProfile(profileId);
        return serviceRegistry.createJob(JOB_TYPE, Operation.Image.toString(), arguments, profile.getJobLoad());
    } catch (ServiceRegistryException e) {
        throw new EncoderException("Unable to create a job", e);
    }
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) ArrayList(java.util.ArrayList) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 67 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class ComposerServiceImpl method convertImage.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.composer.api.ComposerService#convertImage(org.opencastproject.mediapackage.Attachment,
 *      java.lang.String)
 */
@Override
public Job convertImage(Attachment image, String profileId) throws EncoderException, MediaPackageException {
    if (image == null)
        throw new IllegalArgumentException("Source image cannot be null");
    String[] parameters = new String[2];
    parameters[0] = profileId;
    parameters[1] = MediaPackageElementParser.getAsXml(image);
    try {
        final EncodingProfile profile = profileScanner.getProfile(profileId);
        return serviceRegistry.createJob(JOB_TYPE, Operation.ImageConversion.toString(), Arrays.asList(parameters), profile.getJobLoad());
    } catch (ServiceRegistryException e) {
        throw new EncoderException("Unable to create a job", e);
    }
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 68 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class ComposerServiceImpl method image.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.composer.api.ComposerService#image(Track, String, double...)
 */
@Override
public Job image(Track sourceTrack, String profileId, double... times) throws EncoderException, MediaPackageException {
    if (sourceTrack == null)
        throw new IllegalArgumentException("SourceTrack cannot be null");
    if (times.length == 0)
        throw new IllegalArgumentException("At least one time argument has to be specified");
    List<String> parameters = new ArrayList<>();
    parameters.add(profileId);
    parameters.add(MediaPackageElementParser.getAsXml(sourceTrack));
    parameters.add(Boolean.TRUE.toString());
    for (double time : times) {
        parameters.add(Double.toString(time));
    }
    try {
        final EncodingProfile profile = profileScanner.getProfile(profileId);
        return serviceRegistry.createJob(JOB_TYPE, Operation.Image.toString(), parameters, profile.getJobLoad());
    } catch (ServiceRegistryException e) {
        throw new EncoderException("Unable to create a job", e);
    }
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) ArrayList(java.util.ArrayList) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 69 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class ComposerServiceImpl method process.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
 */
@Override
protected String process(Job job) throws ServiceRegistryException {
    String operation = job.getOperation();
    List<String> arguments = job.getArguments();
    try {
        Operation op = Operation.valueOf(operation);
        Track firstTrack;
        Track secondTrack;
        String encodingProfile = arguments.get(0);
        final String serialized;
        switch(op) {
            case Encode:
                firstTrack = (Track) MediaPackageElementParser.getFromXml(arguments.get(1));
                serialized = encode(job, Collections.map(tuple("video", firstTrack)), encodingProfile).map(MediaPackageElementParser.getAsXml()).getOrElse("");
                break;
            case ParallelEncode:
                firstTrack = (Track) MediaPackageElementParser.getFromXml(arguments.get(1));
                serialized = MediaPackageElementParser.getArrayAsXml(parallelEncode(job, firstTrack, encodingProfile));
                break;
            case Image:
                firstTrack = (Track) MediaPackageElementParser.getFromXml(arguments.get(1));
                List<Attachment> resultingElements;
                if (Boolean.parseBoolean(arguments.get(2))) {
                    double[] times = new double[arguments.size() - 3];
                    for (int i = 3; i < arguments.size(); i++) {
                        times[i - 3] = Double.parseDouble(arguments.get(i));
                    }
                    resultingElements = image(job, firstTrack, encodingProfile, times);
                } else {
                    Map<String, String> properties = parseProperties(arguments.get(3));
                    resultingElements = image(job, firstTrack, encodingProfile, properties);
                }
                serialized = MediaPackageElementParser.getArrayAsXml(resultingElements);
                break;
            case ImageConversion:
                Attachment sourceImage = (Attachment) MediaPackageElementParser.getFromXml(arguments.get(1));
                serialized = convertImage(job, sourceImage, encodingProfile).map(MediaPackageElementParser.getAsXml()).getOrElse("");
                break;
            case Mux:
                firstTrack = (Track) MediaPackageElementParser.getFromXml(arguments.get(1));
                secondTrack = (Track) MediaPackageElementParser.getFromXml(arguments.get(2));
                serialized = mux(job, firstTrack, secondTrack, encodingProfile).map(MediaPackageElementParser.getAsXml()).getOrElse("");
                break;
            case Trim:
                firstTrack = (Track) MediaPackageElementParser.getFromXml(arguments.get(1));
                long start = Long.parseLong(arguments.get(2));
                long duration = Long.parseLong(arguments.get(3));
                serialized = trim(job, firstTrack, encodingProfile, start, duration).map(MediaPackageElementParser.getAsXml()).getOrElse("");
                break;
            case Composite:
                Attachment watermarkAttachment;
                firstTrack = (Track) MediaPackageElementParser.getFromXml(arguments.get(LOWER_TRACK_INDEX));
                Layout lowerLayout = Serializer.layout(JsonObj.jsonObj(arguments.get(LOWER_TRACK_LAYOUT_INDEX)));
                LaidOutElement<Track> lowerLaidOutElement = new LaidOutElement<>(firstTrack, lowerLayout);
                Option<LaidOutElement<Track>> upperLaidOutElement = Option.none();
                if (NOT_AVAILABLE.equals(arguments.get(UPPER_TRACK_INDEX)) && NOT_AVAILABLE.equals(arguments.get(UPPER_TRACK_LAYOUT_INDEX))) {
                    logger.trace("This composite action does not use a second track.");
                } else {
                    secondTrack = (Track) MediaPackageElementParser.getFromXml(arguments.get(UPPER_TRACK_INDEX));
                    Layout upperLayout = Serializer.layout(JsonObj.jsonObj(arguments.get(UPPER_TRACK_LAYOUT_INDEX)));
                    upperLaidOutElement = Option.option(new LaidOutElement<Track>(secondTrack, upperLayout));
                }
                Dimension compositeTrackSize = Serializer.dimension(JsonObj.jsonObj(arguments.get(COMPOSITE_TRACK_SIZE_INDEX)));
                String backgroundColor = arguments.get(BACKGROUND_COLOR_INDEX);
                Option<LaidOutElement<Attachment>> watermarkOption = Option.none();
                if (arguments.size() == 9) {
                    watermarkAttachment = (Attachment) MediaPackageElementParser.getFromXml(arguments.get(WATERMARK_INDEX));
                    Layout watermarkLayout = Serializer.layout(JsonObj.jsonObj(arguments.get(WATERMARK_LAYOUT_INDEX)));
                    watermarkOption = Option.some(new LaidOutElement<>(watermarkAttachment, watermarkLayout));
                }
                serialized = composite(job, compositeTrackSize, lowerLaidOutElement, upperLaidOutElement, watermarkOption, encodingProfile, backgroundColor).map(MediaPackageElementParser.getAsXml()).getOrElse("");
                break;
            case Concat:
                String dimensionString = arguments.get(1);
                String frameRateString = arguments.get(2);
                Dimension outputDimension = null;
                if (StringUtils.isNotBlank(dimensionString))
                    outputDimension = Serializer.dimension(JsonObj.jsonObj(dimensionString));
                float outputFrameRate = NumberUtils.toFloat(frameRateString, -1.0f);
                List<Track> tracks = new ArrayList<>();
                for (int i = 3; i < arguments.size(); i++) {
                    tracks.add(i - 3, (Track) MediaPackageElementParser.getFromXml(arguments.get(i)));
                }
                serialized = concat(job, tracks, encodingProfile, outputDimension, outputFrameRate).map(MediaPackageElementParser.getAsXml()).getOrElse("");
                break;
            case ImageToVideo:
                Attachment image = (Attachment) MediaPackageElementParser.getFromXml(arguments.get(1));
                double time = Double.parseDouble(arguments.get(2));
                serialized = imageToVideo(job, image, encodingProfile, time).map(MediaPackageElementParser.getAsXml()).getOrElse("");
                break;
            default:
                throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
        }
        return serialized;
    } catch (IllegalArgumentException e) {
        throw new ServiceRegistryException(String.format("Cannot handle operations of type '%s'", operation), e);
    } catch (IndexOutOfBoundsException e) {
        throw new ServiceRegistryException(String.format("Invalid arguments for operation '%s'", operation), e);
    } catch (Exception e) {
        throw new ServiceRegistryException(String.format("Error handling operation '%s'", operation), e);
    }
}
Also used : ArrayList(java.util.ArrayList) Attachment(org.opencastproject.mediapackage.Attachment) LaidOutElement(org.opencastproject.composer.api.LaidOutElement) Dimension(org.opencastproject.composer.layout.Dimension) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) MediaInspectionException(org.opencastproject.inspection.api.MediaInspectionException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) EncoderException(org.opencastproject.composer.api.EncoderException) Layout(org.opencastproject.composer.layout.Layout) Track(org.opencastproject.mediapackage.Track)

Example 70 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class PartialImportWorkflowOperationHandler method getSilentAudio.

private Track getSilentAudio(final double time, final List<MediaPackageElement> elementsToClean, final Long operationId) throws EncoderException, MediaPackageException, WorkflowOperationException, NotFoundException, IOException {
    final URI uri = workspace.putInCollection(COLLECTION_ID, operationId + "-silent", new ByteArrayInputStream(EMPTY_VALUE.getBytes()));
    final Attachment emptyAttachment = (Attachment) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().elementFromURI(uri, Type.Attachment, MediaPackageElementFlavor.parseFlavor("audio/silent"));
    elementsToClean.add(emptyAttachment);
    final Job silentAudioJob = composerService.imageToVideo(emptyAttachment, SILENT_AUDIO_PROFILE, time);
    if (!waitForStatus(silentAudioJob).isSuccess())
        throw new WorkflowOperationException("Silent audio job did not complete successfully");
    // Get the latest copy
    try {
        for (final String payload : getPayload(serviceRegistry, silentAudioJob)) {
            final Track silentAudio = (Track) MediaPackageElementParser.getFromXml(payload);
            elementsToClean.add(silentAudio);
            return silentAudio;
        }
        // none
        throw new WorkflowOperationException(format("Job %s has no payload or cannot be updated", silentAudioJob));
    } catch (ServiceRegistryException ex) {
        throw new WorkflowOperationException(ex);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Attachment(org.opencastproject.mediapackage.Attachment) Job(org.opencastproject.job.api.Job) URI(java.net.URI) Track(org.opencastproject.mediapackage.Track) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Aggregations

ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)99 NotFoundException (org.opencastproject.util.NotFoundException)61 ConfigurationException (org.osgi.service.cm.ConfigurationException)41 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)30 URISyntaxException (java.net.URISyntaxException)29 Job (org.opencastproject.job.api.Job)29 PersistenceException (javax.persistence.PersistenceException)26 RollbackException (javax.persistence.RollbackException)26 TrustedHttpClientException (org.opencastproject.security.api.TrustedHttpClientException)26 NoResultException (javax.persistence.NoResultException)25 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)25 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)24 EntityManager (javax.persistence.EntityManager)22 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 URI (java.net.URI)16 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)14 DistributionException (org.opencastproject.distribution.api.DistributionException)13 Attachment (org.opencastproject.mediapackage.Attachment)12 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)12