use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class EventsLoader method execute.
private void execute(CSVParser csv) throws Exception {
List<EventEntry> events = parseCSV(csv);
logger.info("Found {} events to populate", events.size());
int i = 1;
final Date now = new Date();
for (EventEntry event : events) {
logger.info("Populating event {}", i);
createSeries(event);
MediaPackage mediaPackage = getBasicMediaPackage(event);
if (now.after(event.getRecordingDate())) {
addWorkflowEntry(mediaPackage);
if (event.isArchive())
addArchiveEntry(mediaPackage);
} else {
addSchedulerEntry(event, mediaPackage);
}
logger.info("Finished populating event {}", i++);
}
}
use of org.opencastproject.mediapackage.MediaPackage 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();
}
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class VideoSegmenterWorkflowOperationHandler method start.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(org.opencastproject.workflow.api.WorkflowInstance,
* JobContext)
*/
public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
logger.debug("Running video segmentation on workflow {}", workflowInstance.getId());
WorkflowOperationInstance operation = workflowInstance.getCurrentOperation();
MediaPackage mediaPackage = workflowInstance.getMediaPackage();
// Find movie track to analyze
String trackFlavor = StringUtils.trimToNull(operation.getConfiguration(PROP_ANALYSIS_TRACK_FLAVOR));
List<String> targetTags = asList(operation.getConfiguration(PROP_TARGET_TAGS));
List<Track> candidates = new ArrayList<Track>();
if (trackFlavor != null)
candidates.addAll(Arrays.asList(mediaPackage.getTracks(MediaPackageElementFlavor.parseFlavor(trackFlavor))));
else
candidates.addAll(Arrays.asList(mediaPackage.getTracks(MediaPackageElements.PRESENTATION_SOURCE)));
// Remove unsupported tracks (only those containing video can be segmented)
Iterator<Track> ti = candidates.iterator();
while (ti.hasNext()) {
Track t = ti.next();
if (!t.hasVideo())
ti.remove();
}
// Found one?
if (candidates.size() == 0) {
logger.info("No matching tracks available for video segmentation in workflow {}", workflowInstance);
return createResult(Action.CONTINUE);
}
// More than one left? Let's be pragmatic...
if (candidates.size() > 1) {
logger.info("Found more than one track to segment, choosing the first one ({})", candidates.get(0));
}
Track track = candidates.get(0);
// Segment the media package
Catalog mpeg7Catalog = null;
Job job = null;
try {
job = videosegmenter.segment(track);
if (!waitForStatus(job).isSuccess()) {
throw new WorkflowOperationException("Video segmentation of " + track + " failed");
}
mpeg7Catalog = (Catalog) MediaPackageElementParser.getFromXml(job.getPayload());
mediaPackage.add(mpeg7Catalog);
mpeg7Catalog.setURI(workspace.moveTo(mpeg7Catalog.getURI(), mediaPackage.getIdentifier().toString(), mpeg7Catalog.getIdentifier(), "segments.xml"));
mpeg7Catalog.setReference(new MediaPackageReferenceImpl(track));
// Add target tags
for (String tag : targetTags) {
mpeg7Catalog.addTag(tag);
}
} catch (Exception e) {
throw new WorkflowOperationException(e);
}
logger.debug("Video segmentation completed");
return createResult(mediaPackage, Action.CONTINUE, job.getQueueTime());
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class WaveformWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
handler = new WaveformWorkflowOperationHandler() {
@Override
protected JobBarrier.Result waitForStatus(Job... jobs) throws IllegalStateException, IllegalArgumentException {
JobBarrier.Result result = EasyMock.createNiceMock(JobBarrier.Result.class);
EasyMock.expect(result.isSuccess()).andReturn(true).anyTimes();
EasyMock.replay(result);
return result;
}
};
track = new TrackImpl();
track.setFlavor(MediaPackageElementFlavor.parseFlavor("xy/source"));
track.setAudio(Arrays.asList(null, null));
MediaPackageBuilder builder = new MediaPackageBuilderImpl();
MediaPackage mediaPackage = builder.createNew();
mediaPackage.setIdentifier(new IdImpl("123-456"));
mediaPackage.add(track);
instance = EasyMock.createNiceMock(WorkflowOperationInstanceImpl.class);
EasyMock.expect(instance.getConfiguration("target-flavor")).andReturn("*/*").anyTimes();
EasyMock.expect(instance.getConfiguration("target-tags")).andReturn("a,b,c").anyTimes();
workflow = EasyMock.createNiceMock(WorkflowInstanceImpl.class);
EasyMock.expect(workflow.getMediaPackage()).andReturn(mediaPackage).anyTimes();
EasyMock.expect(workflow.getCurrentOperation()).andReturn(instance).anyTimes();
Attachment payload = new AttachmentImpl();
payload.setIdentifier("x");
payload.setFlavor(MediaPackageElementFlavor.parseFlavor("xy/source"));
Job job = new JobImpl(0);
job.setPayload(MediaPackageElementParser.getAsXml(payload));
WaveformService waveformService = EasyMock.createNiceMock(WaveformService.class);
EasyMock.expect(waveformService.createWaveformImage(EasyMock.anyObject())).andReturn(job);
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.replay(waveformService, workspace, workflow);
handler.setWaveformService(waveformService);
handler.setWorkspace(workspace);
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AbstractEventEndpoint method getPublicationList.
@GET
@Path("{eventId}/asset/publication/publications.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getPublicationList", description = "Returns a list of publications from the given event as JSON", returnDescription = "The list of publications from the given event as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns a list of publications from the given event as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getPublicationList(@PathParam("eventId") String id) throws Exception {
Opt<Event> optEvent = getIndexService().getEvent(id, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", id);
MediaPackage mp = getIndexService().getEventMediapackage(optEvent.get());
return okJson(arr(getEventPublications(mp.getPublications())));
}
Aggregations