Search in sources :

Example 81 with MediaPackage

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++);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Date(java.util.Date)

Example 82 with MediaPackage

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();
    }
}
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)

Example 83 with MediaPackage

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());
}
Also used : ArrayList(java.util.ArrayList) Catalog(org.opencastproject.mediapackage.Catalog) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) MediaPackageReferenceImpl(org.opencastproject.mediapackage.MediaPackageReferenceImpl) Job(org.opencastproject.job.api.Job) Track(org.opencastproject.mediapackage.Track)

Example 84 with MediaPackage

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);
}
Also used : JobImpl(org.opencastproject.job.api.JobImpl) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) Attachment(org.opencastproject.mediapackage.Attachment) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) MediaPackageBuilderImpl(org.opencastproject.mediapackage.MediaPackageBuilderImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl) WaveformService(org.opencastproject.waveform.api.WaveformService) Job(org.opencastproject.job.api.Job) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 85 with MediaPackage

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())));
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

MediaPackage (org.opencastproject.mediapackage.MediaPackage)407 Test (org.junit.Test)180 NotFoundException (org.opencastproject.util.NotFoundException)108 Job (org.opencastproject.job.api.Job)89 Date (java.util.Date)82 IOException (java.io.IOException)77 URI (java.net.URI)74 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)72 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)70 ArrayList (java.util.ArrayList)69 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)60 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)59 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)55 Path (javax.ws.rs.Path)53 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)52 RestQuery (org.opencastproject.util.doc.rest.RestQuery)52 Track (org.opencastproject.mediapackage.Track)48 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)48 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)45 HashSet (java.util.HashSet)43