use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.
the class WowzaAdaptiveStreamingDistributionRestService method distribute.
@POST
@Path("/")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "distribute", description = "Distribute a media package element to this distribution channel", returnDescription = "The job that can be used to track the distribution", 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 distribute as Json Array['IdOne','IdTwo']", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the distribution job"), @RestResponse(responseCode = SC_NO_CONTENT, description = "There is no streaming distribution service available") })
public Response distribute(@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.distribute(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 distribute element: {}", e.getMessage());
return status(Status.BAD_REQUEST).build();
} catch (Exception e) {
logger.warn("Error distributing element", e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.
the class AwsS3DistributionRestService 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 = "elementId", isRequired = true, description = "The element to retract", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the retraction job") })
public Response retract(@FormParam("mediapackage") String mediaPackageXml, @FormParam("channelId") String channelId, @FormParam("elementId") String elementId) throws Exception {
Job job = null;
try {
Gson gson = new Gson();
Set<String> setElementIds = gson.fromJson(elementId, new TypeToken<Set<String>>() {
}.getType());
MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
job = service.retract(channelId, mediapackage, setElementIds);
} 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 media package {}, element {} from aws s3 channel: {}", mediaPackageXml, elementId, e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
return Response.ok(new JaxbJob(job)).build();
}
use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.
the class DownloadDistributionRestService 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 = "elementId", isRequired = true, description = "The element to retract. The Id or multiple Ids as JSON Array ( ['IdOne','IdTwo'] )", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the retraction job") })
public Response retract(@FormParam("mediapackage") String mediaPackageXml, @FormParam("elementId") String elementId, @FormParam("channelId") String channelId) throws Exception {
try {
Gson gson = new Gson();
Set<String> setElementIds = gson.fromJson(elementId, new TypeToken<Set<String>>() {
}.getType());
final MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
final Job job = service.retract(channelId, mediapackage, setElementIds);
return ok(new JaxbJob(job));
} 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 download channel: {}", mediaPackageXml, e);
return serverError();
}
}
use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.
the class ComposerRestService method imageToVideo.
/**
* Transforms an image attachment to a video track
*
* @param sourceAttachmentXml
* The source image attachment
* @param profileId
* The profile to use for encoding
* @param timeString
* the length of the resulting video track in seconds
* @return A {@link Response} with the resulting track in the response body
* @throws Exception
*/
@POST
@Path("imagetovideo")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "imagetovideo", description = "Starts an image converting process to a video, based on the specified encoding profile ID and the source image attachment", restParameters = { @RestParameter(description = "The resulting video time in seconds", isRequired = false, name = "time", type = Type.STRING, defaultValue = "1"), @RestParameter(description = "The attachment containing the image to convert", isRequired = true, name = "sourceAttachment", type = Type.TEXT), @RestParameter(description = "The encoding profile to use", isRequired = true, name = "profileId", type = Type.STRING) }, reponses = { @RestResponse(description = "Results in an xml document containing the video track", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "If required parameters aren't set or if sourceAttachment isn't from the type Attachment", responseCode = HttpServletResponse.SC_BAD_REQUEST) }, returnDescription = "")
public Response imageToVideo(@FormParam("sourceAttachment") String sourceAttachmentXml, @FormParam("profileId") String profileId, @FormParam("time") @DefaultValue("1") String timeString) throws Exception {
// Ensure that the POST parameters are present
if (StringUtils.isBlank(sourceAttachmentXml) || StringUtils.isBlank(profileId))
return Response.status(Response.Status.BAD_REQUEST).entity("sourceAttachment and profileId must not be null").build();
// parse time
Double time;
try {
time = Double.parseDouble(timeString);
} catch (Exception e) {
logger.info("Unable to parse time {} as long value!", timeString);
return Response.status(Response.Status.BAD_REQUEST).entity("Could not parse time: invalid format").build();
}
// Deserialize the source track
MediaPackageElement sourceAttachment = MediaPackageElementParser.getFromXml(sourceAttachmentXml);
if (!Attachment.TYPE.equals(sourceAttachment.getElementType()))
return Response.status(Response.Status.BAD_REQUEST).entity("sourceAttachment element must be of type attachment").build();
try {
// Asynchronously convert the specified attachment to a video
Job job = composerService.imageToVideo((Attachment) sourceAttachment, profileId, time);
return Response.ok().entity(new JaxbJob(job)).build();
} catch (EncoderException e) {
logger.warn("Unable to convert image to video: " + e.getMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.opencastproject.job.api.JaxbJob in project opencast by opencast.
the class ComposerRestService method trim.
/**
* Trims a track to a new length.
*
* @param sourceTrackAsXml
* The source track
* @param profileId
* the encoding profile to use for trimming
* @param start
* the new trimming start time
* @param duration
* the new video duration
* @return A response containing the job for this encoding job in the response body.
* @throws Exception
*/
@POST
@Path("trim")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "trim", description = "Starts a trimming process, based on the specified track, start time and duration in ms", 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 for trimming", isRequired = true, name = "profileId", type = Type.STRING, defaultValue = "trim.work"), @RestParameter(description = "The start time in milisecond", isRequired = true, name = "start", type = Type.STRING, defaultValue = "0"), @RestParameter(description = "The duration in milisecond", isRequired = true, name = "duration", type = Type.STRING, defaultValue = "10000") }, reponses = { @RestResponse(description = "Results in an xml document containing the job for the trimming task", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "If the start time is negative or exceeds the track duration", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "If the duration is negative or, including the new start time, exceeds the track duration", responseCode = HttpServletResponse.SC_BAD_REQUEST) }, returnDescription = "")
public Response trim(@FormParam("sourceTrack") String sourceTrackAsXml, @FormParam("profileId") String profileId, @FormParam("start") long start, @FormParam("duration") long duration) throws Exception {
// Ensure that the POST parameters are present
if (StringUtils.isBlank(sourceTrackAsXml) || StringUtils.isBlank(profileId))
return Response.status(Response.Status.BAD_REQUEST).entity("sourceTrack and profileId must not be null").build();
// Deserialize the track
MediaPackageElement sourceElement = MediaPackageElementParser.getFromXml(sourceTrackAsXml);
if (!Track.TYPE.equals(sourceElement.getElementType()))
return Response.status(Response.Status.BAD_REQUEST).entity("sourceTrack element must be of type track").build();
// Make sure the trim times make sense
Track sourceTrack = (Track) sourceElement;
if (sourceTrack.getDuration() == null)
return Response.status(Response.Status.BAD_REQUEST).entity("sourceTrack element does not have a duration").build();
if (start < 0) {
start = 0;
} else if (duration <= 0) {
duration = (sourceTrack.getDuration() - start);
} else if (start + duration > sourceTrack.getDuration()) {
duration = (sourceTrack.getDuration() - start);
}
try {
// Asynchronously encode the specified tracks
Job job = composerService.trim(sourceTrack, profileId, start, duration);
return Response.ok().entity(new JaxbJob(job)).build();
} catch (EncoderException e) {
logger.warn("Unable to trim the track: " + e.getMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
Aggregations