Search in sources :

Example 1 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class ComposerRestService method parallelencode.

/**
 * Encodes a track to multiple tracks in parallel.
 *
 * @param sourceTrackAsXml
 *          The source track
 * @param profileId
 *          The profile to use in encoding this track
 * @return A response containing the job for this encoding job in the response body.
 * @throws Exception
 */
@POST
@Path("parallelencode")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "parallelencode", description = "Starts an encoding process, based on the specified encoding profile ID and the track", pathParameters = {}, restParameters = { @RestParameter(description = "The track containing the stream", isRequired = true, name = "sourceTrack", type = Type.TEXT, defaultValue = "${this.videoTrackDefault}"), @RestParameter(description = "The encoding profile to use", isRequired = true, name = "profileId", type = Type.STRING, defaultValue = "mp4-medium.http") }, reponses = { @RestResponse(description = "Results in an xml document containing the job for the encoding task", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "")
public Response parallelencode(@FormParam("sourceTrack") String sourceTrackAsXml, @FormParam("profileId") String profileId) throws Exception {
    // Ensure that the POST parameters are present
    if (sourceTrackAsXml == null || profileId == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity("sourceTrack and profileId must not be null").build();
    }
    // Deserialize the track
    MediaPackageElement sourceTrack = MediaPackageElementParser.getFromXml(sourceTrackAsXml);
    if (!Track.TYPE.equals(sourceTrack.getElementType())) {
        return Response.status(Response.Status.BAD_REQUEST).entity("sourceTrack element must be of type track").build();
    }
    // Asynchronously encode the specified tracks
    Job job = composerService.parallelEncode((Track) sourceTrack, profileId);
    if (job == null)
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Encoding failed").build();
    return Response.ok().entity(new JaxbJob(job)).build();
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) JaxbJob(org.opencastproject.job.api.JaxbJob) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 2 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class ComposerRestService method image.

/**
 * Encodes a track in a media package.
 *
 * @param sourceTrackXml
 *          The source track
 * @param profileId
 *          The profile to use in encoding this track
 * @param times
 *          one or more times in seconds separated by comma
 * @return A {@link Response} with the resulting track in the response body
 * @throws Exception
 */
@POST
@Path("image")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "image", description = "Starts an image extraction process, based on the specified encoding profile ID and the source track", restParameters = { @RestParameter(description = "The track containing the video stream", isRequired = true, name = "sourceTrack", type = Type.TEXT, defaultValue = "${this.videoTrackDefault}"), @RestParameter(description = "The encoding profile to use", isRequired = true, name = "profileId", type = Type.STRING, defaultValue = "player-preview.http"), @RestParameter(description = "The number of seconds (many numbers can be specified, separated by semicolon) into the video to extract the image", isRequired = false, name = "time", type = Type.STRING), @RestParameter(description = "An optional set of key=value\\n properties", isRequired = false, name = "properties", type = TEXT) }, reponses = { @RestResponse(description = "Results in an xml document containing the image attachment", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "If required parameters aren't set or if sourceTrack isn't from the type Track", responseCode = HttpServletResponse.SC_BAD_REQUEST) }, returnDescription = "The image extraction job")
public Response image(@FormParam("sourceTrack") String sourceTrackXml, @FormParam("profileId") String profileId, @FormParam("time") String times, @FormParam("properties") LocalHashMap localMap) throws Exception {
    // Ensure that the POST parameters are present
    if (StringUtils.isBlank(sourceTrackXml) || StringUtils.isBlank(profileId))
        return Response.status(Response.Status.BAD_REQUEST).entity("sourceTrack and profileId must not be null").build();
    // Deserialize the source track
    MediaPackageElement sourceTrack = MediaPackageElementParser.getFromXml(sourceTrackXml);
    if (!Track.TYPE.equals(sourceTrack.getElementType()))
        return Response.status(Response.Status.BAD_REQUEST).entity("sourceTrack element must be of type track").build();
    boolean timeBased = false;
    double[] timeArray = null;
    if (StringUtils.isNotBlank(times)) {
        // parse time codes
        try {
            timeArray = parseTimeArray(times);
        } catch (Exception e) {
            return Response.status(Response.Status.BAD_REQUEST).entity("could not parse times: invalid format").build();
        }
        timeBased = true;
    } else if (localMap == null) {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
    try {
        // Asynchronously encode the specified tracks
        Job job;
        if (timeBased) {
            job = composerService.image((Track) sourceTrack, profileId, timeArray);
        } else {
            job = composerService.image((Track) sourceTrack, profileId, localMap.getMap());
        }
        return Response.ok().entity(new JaxbJob(job)).build();
    } catch (EncoderException e) {
        logger.warn("Unable to extract image(s): " + e.getMessage());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) JaxbJob(org.opencastproject.job.api.JaxbJob) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) NotFoundException(org.opencastproject.util.NotFoundException) EncoderException(org.opencastproject.composer.api.EncoderException) Track(org.opencastproject.mediapackage.Track) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 3 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class ComposerRestService method mux.

/**
 * Encodes a track.
 *
 * @param audioSourceTrackXml
 *          The audio source track
 * @param videoSourceTrackXml
 *          The video source track
 * @param profileId
 *          The profile to use in encoding this track
 * @return A response containing the job for this encoding job in the response body.
 * @throws Exception
 */
@POST
@Path("mux")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "mux", description = "Starts an encoding process, which will mux the two tracks using the given encoding profile", restParameters = { @RestParameter(description = "The track containing the audio stream", isRequired = true, name = "sourceAudioTrack", type = Type.TEXT, defaultValue = "${this.audioTrackDefault}"), @RestParameter(description = "The track containing the video stream", isRequired = true, name = "sourceVideoTrack", type = Type.TEXT, defaultValue = "${this.videoTrackDefault}"), @RestParameter(description = "The encoding profile to use", isRequired = true, name = "profileId", type = Type.STRING, defaultValue = "mp4-medium.http") }, reponses = { @RestResponse(description = "Results in an xml document containing the job for the encoding task", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "If required parameters aren't set or if the source tracks aren't from the type Track", responseCode = HttpServletResponse.SC_BAD_REQUEST) }, returnDescription = "")
public Response mux(@FormParam("audioSourceTrack") String audioSourceTrackXml, @FormParam("videoSourceTrack") String videoSourceTrackXml, @FormParam("profileId") String profileId) throws Exception {
    // Ensure that the POST parameters are present
    if (StringUtils.isBlank(audioSourceTrackXml) || StringUtils.isBlank(videoSourceTrackXml) || StringUtils.isBlank(profileId)) {
        return Response.status(Response.Status.BAD_REQUEST).entity("audioSourceTrack, videoSourceTrack, and profileId must not be null").build();
    }
    // Deserialize the audio track
    MediaPackageElement audioSourceTrack = MediaPackageElementParser.getFromXml(audioSourceTrackXml);
    if (!Track.TYPE.equals(audioSourceTrack.getElementType()))
        return Response.status(Response.Status.BAD_REQUEST).entity("audioSourceTrack must be of type track").build();
    // Deserialize the video track
    MediaPackageElement videoSourceTrack = MediaPackageElementParser.getFromXml(videoSourceTrackXml);
    if (!Track.TYPE.equals(videoSourceTrack.getElementType()))
        return Response.status(Response.Status.BAD_REQUEST).entity("videoSourceTrack must be of type track").build();
    try {
        // Asynchronously encode the specified tracks
        Job job = composerService.mux((Track) videoSourceTrack, (Track) audioSourceTrack, profileId);
        return Response.ok().entity(new JaxbJob(job)).build();
    } catch (EncoderException e) {
        logger.warn("Unable to mux tracks: " + e.getMessage());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) JaxbJob(org.opencastproject.job.api.JaxbJob) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 4 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class ComposerRestService method composite.

/**
 * Compose two videos into one with an optional watermark.
 *
 * @param compositeSizeJson
 *          The composite track dimension as JSON
 * @param lowerTrackXml
 *          The lower track of the composition as XML
 * @param lowerLayoutJson
 *          The lower layout as JSON
 * @param upperTrackXml
 *          The upper track of the composition as XML
 * @param upperLayoutJson
 *          The upper layout as JSON
 * @param watermarkAttachmentXml
 *          The watermark image attachment of the composition as XML
 * @param watermarkLayoutJson
 *          The watermark layout as JSON
 * @param profileId
 *          The encoding profile to use
 * @param background
 *          The background color
 * @return A {@link Response} with the resulting track in the response body
 * @throws Exception
 */
@POST
@Path("composite")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "composite", description = "Starts a video compositing process, based on the specified resolution, encoding profile ID, the source elements and their layouts", restParameters = { @RestParameter(description = "The resolution size of the resulting video as JSON", isRequired = true, name = "compositeSize", type = Type.STRING), @RestParameter(description = "The lower source track containing the lower video", isRequired = true, name = "lowerTrack", type = Type.TEXT), @RestParameter(description = "The lower layout containing the JSON definition of the layout", isRequired = true, name = "lowerLayout", type = Type.TEXT), @RestParameter(description = "The upper source track containing the upper video", isRequired = false, name = "upperTrack", type = Type.TEXT), @RestParameter(description = "The upper layout containing the JSON definition of the layout", isRequired = false, name = "upperLayout", type = Type.TEXT), @RestParameter(description = "The watermark source attachment containing watermark image", isRequired = false, name = "watermarkTrack", type = Type.TEXT), @RestParameter(description = "The watermark layout containing the JSON definition of the layout", isRequired = false, name = "watermarkLayout", type = Type.TEXT), @RestParameter(description = "The background color", isRequired = false, name = "background", type = Type.TEXT, defaultValue = "black"), @RestParameter(description = "The encoding profile to use", isRequired = true, name = "profileId", type = Type.STRING) }, reponses = { @RestResponse(description = "Results in an xml document containing the compound video track", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "If required parameters aren't set or if the source elements aren't from the right type", responseCode = HttpServletResponse.SC_BAD_REQUEST) }, returnDescription = "")
public Response composite(@FormParam("compositeSize") String compositeSizeJson, @FormParam("lowerTrack") String lowerTrackXml, @FormParam("lowerLayout") String lowerLayoutJson, @FormParam("upperTrack") String upperTrackXml, @FormParam("upperLayout") String upperLayoutJson, @FormParam("watermarkAttachment") String watermarkAttachmentXml, @FormParam("watermarkLayout") String watermarkLayoutJson, @FormParam("profileId") String profileId, @FormParam("background") @DefaultValue("black") String background) throws Exception {
    // Ensure that the POST parameters are present
    if (StringUtils.isBlank(compositeSizeJson) || StringUtils.isBlank(lowerTrackXml) || StringUtils.isBlank(lowerLayoutJson) || StringUtils.isBlank(profileId))
        return Response.status(Response.Status.BAD_REQUEST).entity("One of the required parameters must not be null").build();
    // Deserialize the source elements
    MediaPackageElement lowerTrack = MediaPackageElementParser.getFromXml(lowerTrackXml);
    Layout lowerLayout = Serializer.layout(JsonObj.jsonObj(lowerLayoutJson));
    if (!Track.TYPE.equals(lowerTrack.getElementType()))
        return Response.status(Response.Status.BAD_REQUEST).entity("lowerTrack element must be of type track").build();
    LaidOutElement<Track> lowerLaidOutElement = new LaidOutElement<Track>((Track) lowerTrack, lowerLayout);
    Option<LaidOutElement<Track>> upperLaidOutElement = Option.<LaidOutElement<Track>>none();
    if (StringUtils.isNotBlank(upperTrackXml)) {
        MediaPackageElement upperTrack = MediaPackageElementParser.getFromXml(upperTrackXml);
        Layout upperLayout = Serializer.layout(JsonObj.jsonObj(upperLayoutJson));
        if (!Track.TYPE.equals(upperTrack.getElementType())) {
            return Response.status(Response.Status.BAD_REQUEST).entity("upperTrack element must be of type track").build();
        }
        upperLaidOutElement = Option.option(new LaidOutElement<Track>((Track) upperTrack, upperLayout));
    }
    Option<LaidOutElement<Attachment>> watermarkLaidOutElement = Option.<LaidOutElement<Attachment>>none();
    if (StringUtils.isNotBlank(watermarkAttachmentXml)) {
        Layout watermarkLayout = Serializer.layout(JsonObj.jsonObj(watermarkLayoutJson));
        MediaPackageElement watermarkAttachment = MediaPackageElementParser.getFromXml(watermarkAttachmentXml);
        if (!Attachment.TYPE.equals(watermarkAttachment.getElementType()))
            return Response.status(Response.Status.BAD_REQUEST).entity("watermarkTrack element must be of type track").build();
        watermarkLaidOutElement = Option.some(new LaidOutElement<Attachment>((Attachment) watermarkAttachment, watermarkLayout));
    }
    Dimension compositeTrackSize = Serializer.dimension(JsonObj.jsonObj(compositeSizeJson));
    try {
        // Asynchronously composite the specified source elements
        Job job = composerService.composite(compositeTrackSize, upperLaidOutElement, lowerLaidOutElement, watermarkLaidOutElement, profileId, background);
        return Response.ok().entity(new JaxbJob(job)).build();
    } catch (EncoderException e) {
        logger.warn("Unable to composite video: " + e.getMessage());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) Layout(org.opencastproject.composer.layout.Layout) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) JaxbJob(org.opencastproject.job.api.JaxbJob) LaidOutElement(org.opencastproject.composer.api.LaidOutElement) Dimension(org.opencastproject.composer.layout.Dimension) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Track(org.opencastproject.mediapackage.Track) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 5 with JaxbJob

use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.

the class WowzaAdaptiveStreamingDistributionRestService method retract.

@POST
@Path("/retract")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "retract", description = "Retract a media package element from this distribution channel", returnDescription = "The job that can be used to track the retraction", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The mediapackage", type = Type.TEXT), @RestParameter(name = "channelId", isRequired = true, description = "The publication channel ID", type = Type.TEXT), @RestParameter(name = "elementIds", isRequired = true, description = "The elements to retract as Json Array['IdOne','IdTwo']", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the retraction job"), @RestResponse(responseCode = SC_NO_CONTENT, description = "There is no streaming distribution service available") })
public Response retract(@FormParam("mediapackage") String mediaPackageXml, @FormParam("channelId") String channelId, @FormParam("elementIds") String elementIds) throws Exception {
    Job job = null;
    try {
        Set<String> setElementIds = gson.fromJson(elementIds, new TypeToken<Set<String>>() {
        }.getType());
        MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
        job = service.retract(channelId, mediapackage, setElementIds);
        if (job == null) {
            return Response.noContent().build();
        } else {
            return Response.ok(new JaxbJob(job)).build();
        }
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to retract element: {}", e.getMessage());
        return status(Status.BAD_REQUEST).build();
    } catch (Exception e) {
        logger.warn("Unable to retract mediapackage '{}' from streaming channel: {}", new Object[] { mediaPackageXml, e });
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) JaxbJob(org.opencastproject.job.api.JaxbJob) MediaPackage(org.opencastproject.mediapackage.MediaPackage) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

JaxbJob (org.opencastproject.job.api.JaxbJob)35 Job (org.opencastproject.job.api.Job)31 POST (javax.ws.rs.POST)26 Path (javax.ws.rs.Path)26 Produces (javax.ws.rs.Produces)26 RestQuery (org.opencastproject.util.doc.rest.RestQuery)26 MediaPackage (org.opencastproject.mediapackage.MediaPackage)14 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)10 TypeToken (com.google.gson.reflect.TypeToken)8 Gson (com.google.gson.Gson)7 Test (org.junit.Test)6 EncoderException (org.opencastproject.composer.api.EncoderException)6 Track (org.opencastproject.mediapackage.Track)5 Response (javax.ws.rs.core.Response)4 JobImpl (org.opencastproject.job.api.JobImpl)3 NotFoundException (org.opencastproject.util.NotFoundException)3 IOException (java.io.IOException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Dimension (org.opencastproject.composer.layout.Dimension)2 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)2