Search in sources :

Example 66 with Track

use of org.opencastproject.mediapackage.Track in project opencast by opencast.

the class SmilServiceRest method addClips.

@POST
@Path("addClips")
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
@RestQuery(name = "addClips", description = "Add new media elements based on given Tracks information and start / duration parameters. " + "ParentId specifies where to put the new media.", restParameters = { @RestParameter(name = "smil", description = "SMIL document where to add new media elements.", isRequired = true, type = RestParameter.Type.TEXT), @RestParameter(name = "parentId", description = "An element Id, were to add new media. ", isRequired = false, type = RestParameter.Type.STRING), @RestParameter(name = "tracks", description = "Tracks (MediaPackageElements) to add as media elements." + "Some information like Track source and flavor will be stored in ParamGroup (in SMIL Head) " + "and referenced by paramGroup media element attribute.", isRequired = true, type = RestParameter.Type.TEXT), @RestParameter(name = "start", description = "Track start position in milliseconds. " + "The start position will be applied to each media element.", isRequired = true, type = RestParameter.Type.INTEGER), @RestParameter(name = "duration", description = "Clip duration in milliseconds (should be positive). " + "The duration will be applied to each media element.", isRequired = true, type = RestParameter.Type.INTEGER) }, returnDescription = "Returns new Smil with new media elements inside " + "(the new media and metadata elements will be returned as response entities).", reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "Add media elements to SMIL successfull."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "SMIL document not valid."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "Tracks are not valid."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "SMIL document doesn't contain an element with given parentId."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "Start plus duration is bigger than Track length.") })
public Response addClips(@FormParam("smil") String smil, @FormParam("parentId") String parentId, @FormParam("tracks") String tracks, @FormParam("start") long start, @FormParam("duration") long duration) {
    SmilResponse smilResponse = null;
    List<Track> tracksList = null;
    try {
        smilResponse = smilService.fromXml(smil);
        tracksList = (List<Track>) MediaPackageElementParser.getArrayFromXml(tracks);
    } catch (SmilException ex) {
        logger.info(ex.getMessage(), ex);
        return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("SMIL document invalid.").build();
    } catch (MediaPackageException ex) {
        logger.error(ex.getMessage(), ex);
        return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("Tracks are not valid.").build();
    }
    Track[] tracksArr = tracksList.toArray(new Track[tracksList.size()]);
    try {
        smilResponse = smilService.addClips(smilResponse.getSmil(), parentId, tracksArr, start, duration);
        return Response.ok(smilResponse).build();
    } catch (SmilException ex) {
        logger.info(ex.getMessage(), ex);
        return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("SMIL document doesn't contain an element with given parentId.").build();
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilException(org.opencastproject.smil.api.SmilException) 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 67 with Track

use of org.opencastproject.mediapackage.Track in project opencast by opencast.

the class ToolsEndpoint method createSmilCuttingCatalog.

/**
 * Creates a SMIL cutting catalog based on the passed editing information and the media package.
 *
 * @param editingInfo
 *          the editing information
 * @param mediaPackage
 *          the media package
 * @return a SMIL catalog
 * @throws SmilException
 *           if creating the SMIL catalog failed
 */
Smil createSmilCuttingCatalog(final EditingInfo editingInfo, final MediaPackage mediaPackage) throws SmilException {
    // Create initial SMIL catalog
    SmilResponse smilResponse = smilService.createNewSmil(mediaPackage);
    // Add tracks to the SMIL catalog
    ArrayList<Track> tracks = new ArrayList<>();
    for (final String trackId : editingInfo.getConcatTracks()) {
        Track track = mediaPackage.getTrack(trackId);
        if (track == null) {
            Opt<Track> trackOpt = getInternalPublication(mediaPackage).toStream().bind(new Fn<Publication, List<Track>>() {

                @Override
                public List<Track> apply(Publication a) {
                    return Arrays.asList(a.getTracks());
                }
            }).filter(new Fn<Track, Boolean>() {

                @Override
                public Boolean apply(Track a) {
                    return trackId.equals(a.getIdentifier());
                }
            }).head();
            if (trackOpt.isNone())
                throw new IllegalStateException(format("The track '%s' doesn't exist in media package '%s'", trackId, mediaPackage));
            track = trackOpt.get();
        }
        tracks.add(track);
    }
    for (Tuple<Long, Long> segment : editingInfo.getConcatSegments()) {
        smilResponse = smilService.addParallel(smilResponse.getSmil());
        final String parentId = smilResponse.getEntity().getId();
        final Long duration = segment.getB() - segment.getA();
        smilResponse = smilService.addClips(smilResponse.getSmil(), parentId, tracks.toArray(new Track[tracks.size()]), segment.getA(), duration);
    }
    return smilResponse.getSmil();
}
Also used : ArrayList(java.util.ArrayList) Fn(com.entwinemedia.fn.Fn) Publication(org.opencastproject.mediapackage.Publication) SmilResponse(org.opencastproject.smil.api.SmilResponse) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) LinkedList(java.util.LinkedList) Track(org.opencastproject.mediapackage.Track)

Example 68 with Track

use of org.opencastproject.mediapackage.Track in project opencast by opencast.

the class LiveScheduleServiceImpl method isSameTrackArray.

private boolean isSameTrackArray(Track[] previous, Track[] current) {
    Set<Track> previousTracks = new HashSet<Track>(Arrays.asList(previous));
    Set<Track> currentTracks = new HashSet<Track>(Arrays.asList(current));
    if (previousTracks.size() != currentTracks.size())
        return false;
    for (Track tp : previousTracks) {
        Iterator<Track> it = currentTracks.iterator();
        while (it.hasNext()) {
            Track tc = it.next();
            if (tp.getURI().equals(tc.getURI()) && tp.getDuration().equals(tc.getDuration())) {
                currentTracks.remove(tc);
                break;
            }
        }
    }
    if (currentTracks.size() > 0)
        return false;
    return true;
}
Also used : Track(org.opencastproject.mediapackage.Track) HashSet(java.util.HashSet)

Example 69 with Track

use of org.opencastproject.mediapackage.Track in project opencast by opencast.

the class LiveScheduleServiceImpl method updateLiveEvent.

boolean updateLiveEvent(MediaPackage previousMp, DublinCoreCatalog episodeDC) throws LiveScheduleException {
    // Get latest mp from the asset manager
    Snapshot snapshot = getSnapshot(previousMp.getIdentifier().toString());
    // will be compared below.
    if (snapshot.getVersion().equals(snapshotVersionCache.getIfPresent(previousMp.getIdentifier()))) {
        logger.debug("Snapshot version {} was created by us so this change is ignored.", snapshot.getVersion());
        return false;
    }
    // Temporary mp
    MediaPackage tempMp = (MediaPackage) snapshot.getMediaPackage().clone();
    // Set duration (used by live tracks)
    setDuration(tempMp, episodeDC);
    // Add live tracks to media package
    addLiveTracks(tempMp, episodeDC.getFirst(DublinCore.PROPERTY_SPATIAL));
    // If same mp, no need to do anything
    if (isSameMediaPackage(previousMp, tempMp)) {
        logger.debug("Live media package {} seems to be the same. Not updating.", previousMp);
        return false;
    }
    logger.info("Updating live media package {}", previousMp);
    // Add and distribute catalogs/acl, this creates a new mp
    MediaPackage mp = addAndDistributeElements(snapshot);
    // Add tracks from tempMp
    for (Track t : tempMp.getTracks()) mp.add(t);
    // Remove publication element that came with the snapshot mp
    removeLivePublicationChannel(mp);
    // Publish mp to engage search index
    publish(mp);
    // Publication channel already there so no need to add
    // Don't leave garbage there!
    retractPreviousElements(previousMp, mp);
    return true;
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Track(org.opencastproject.mediapackage.Track)

Example 70 with Track

use of org.opencastproject.mediapackage.Track in project opencast by opencast.

the class LiveScheduleServiceImpl method createLiveEvent.

boolean createLiveEvent(String mpId, DublinCoreCatalog episodeDC) throws LiveScheduleException {
    try {
        logger.info("Creating live media package {}", mpId);
        // Get latest mp from the asset manager
        Snapshot snapshot = getSnapshot(mpId);
        // Temporary mp
        MediaPackage tempMp = (MediaPackage) snapshot.getMediaPackage().clone();
        // Set duration (used by live tracks)
        setDuration(tempMp, episodeDC);
        // Add live tracks to media package
        addLiveTracks(tempMp, episodeDC.getFirst(DublinCore.PROPERTY_SPATIAL));
        // Add and distribute catalogs/acl, this creates a new mp object
        MediaPackage mp = addAndDistributeElements(snapshot);
        // Add tracks from tempMp
        for (Track t : tempMp.getTracks()) mp.add(t);
        // Publish mp to engage search index
        publish(mp);
        // Add engage-live publication channel to archived mp
        Organization currentOrg = null;
        try {
            currentOrg = organizationService.getOrganization(snapshot.getOrganizationId());
        } catch (NotFoundException e) {
            logger.warn("Organization in snapshot not found: {}", snapshot.getOrganizationId());
        }
        MediaPackage archivedMp = snapshot.getMediaPackage();
        addLivePublicationChannel(currentOrg, archivedMp);
        // Take a snapshot with the publication added and put its version in our local cache
        // so that we ignore notifications for this snapshot version.
        snapshotVersionCache.put(mpId, assetManager.takeSnapshot(archivedMp).getVersion());
        return true;
    } catch (Exception e) {
        throw new LiveScheduleException(e);
    }
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) Organization(org.opencastproject.security.api.Organization) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) Track(org.opencastproject.mediapackage.Track) URISyntaxException(java.net.URISyntaxException) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) DistributionException(org.opencastproject.distribution.api.DistributionException) NotFoundException(org.opencastproject.util.NotFoundException)

Aggregations

Track (org.opencastproject.mediapackage.Track)154 Test (org.junit.Test)56 Job (org.opencastproject.job.api.Job)56 MediaPackage (org.opencastproject.mediapackage.MediaPackage)50 URI (java.net.URI)40 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)34 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)34 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)34 HashMap (java.util.HashMap)29 ArrayList (java.util.ArrayList)27 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)24 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)21 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)20 NotFoundException (org.opencastproject.util.NotFoundException)20 IOException (java.io.IOException)19 TrackSelector (org.opencastproject.mediapackage.selector.TrackSelector)17 Attachment (org.opencastproject.mediapackage.Attachment)16 EncodingProfile (org.opencastproject.composer.api.EncodingProfile)15 Catalog (org.opencastproject.mediapackage.Catalog)15 File (java.io.File)14