Search in sources :

Example 1 with SmilBodyImpl

use of org.opencastproject.smil.entity.SmilBodyImpl in project opencast by opencast.

the class SmilServiceImpl method addParallel.

/**
 * {@inheritDoc}
 */
@Override
public SmilResponse addParallel(Smil smil, String parentId) throws SmilException {
    SmilMediaContainer par = new SmilMediaParallelImpl();
    ((SmilBodyImpl) smil.getBody()).addMediaElement(par, parentId);
    return new SmilResponseImpl(smil, par);
}
Also used : SmilBodyImpl(org.opencastproject.smil.entity.SmilBodyImpl) SmilMediaParallelImpl(org.opencastproject.smil.entity.media.container.SmilMediaParallelImpl) SmilMediaContainer(org.opencastproject.smil.entity.media.container.api.SmilMediaContainer)

Example 2 with SmilBodyImpl

use of org.opencastproject.smil.entity.SmilBodyImpl in project opencast by opencast.

the class SmilServiceImpl method addSequence.

/**
 * {@inheritDoc}
 */
@Override
public SmilResponse addSequence(Smil smil, String parentId) throws SmilException {
    SmilMediaContainer seq = new SmilMediaSequenceImpl();
    ((SmilBodyImpl) smil.getBody()).addMediaElement(seq, parentId);
    return new SmilResponseImpl(smil, seq);
}
Also used : SmilMediaSequenceImpl(org.opencastproject.smil.entity.media.container.SmilMediaSequenceImpl) SmilBodyImpl(org.opencastproject.smil.entity.SmilBodyImpl) SmilMediaContainer(org.opencastproject.smil.entity.media.container.api.SmilMediaContainer)

Example 3 with SmilBodyImpl

use of org.opencastproject.smil.entity.SmilBodyImpl in project opencast by opencast.

the class SmilServiceImpl method addClip.

/**
 * {@inheritDoc}
 */
@Override
public SmilResponse addClip(Smil smil, String parentId, Track track, long start, long duration, String pgId) throws SmilException {
    if (start < 0) {
        throw new SmilException("Start position should be positive.");
    }
    if (duration < 0) {
        throw new SmilException("Duration should be positive.");
    }
    if (track.getURI() == null) {
        throw new SmilException("Track URI isn't set.");
    }
    if (track.getFlavor() == null) {
        throw new SmilException("Track flavor isn't set.");
    }
    if (track.getDuration() != null) {
        if (!track.hasAudio() && !track.hasVideo()) {
            throw new SmilException("Track should have at least one audio or video stream.");
        }
        if (start >= track.getDuration()) {
            throw new SmilException("Start value is bigger than track length.");
        }
        if (start + duration > track.getDuration()) {
            duration = track.getDuration() - start;
        }
    }
    SmilMediaParamGroup trackParamGroup = null;
    for (SmilMediaParamGroup paramGroup : smil.getHead().getParamGroups()) {
        // support for adding multiple tracks to the same param group
        if (pgId != null && paramGroup.getId().equals(pgId.trim())) {
            trackParamGroup = paramGroup;
            break;
        }
        SmilMediaParam param = ((SmilMediaParamGroupImpl) paramGroup).getParamByName(SmilMediaParam.PARAM_NAME_TRACK_ID);
        if (param != null && param.getValue().equals(track.getIdentifier())) {
            trackParamGroup = paramGroup;
            break;
        }
    }
    boolean newTrack = trackParamGroup == null;
    if (newTrack) {
        // add paramgroup for new Track
        trackParamGroup = new SmilMediaParamGroupImpl();
        ((SmilMediaParamGroupImpl) trackParamGroup).addParam(SmilMediaParam.PARAM_NAME_TRACK_ID, track.getIdentifier());
        ((SmilMediaParamGroupImpl) trackParamGroup).addParam(SmilMediaParam.PARAM_NAME_TRACK_SRC, track.getURI().toString());
        ((SmilMediaParamGroupImpl) trackParamGroup).addParam(SmilMediaParam.PARAM_NAME_TRACK_FLAVOR, track.getFlavor().toString());
        ((SmilHeadImpl) smil.getHead()).addParamGroup(trackParamGroup);
    }
    SmilMeta durationMeta = null;
    for (SmilMeta meta : smil.getHead().getMetas()) {
        if (SmilMeta.SMIL_META_NAME_TRACK_DURATION.equals(meta.getName())) {
            durationMeta = meta;
            break;
        }
    }
    if (track.getDuration() != null) {
        // set track-duration meta if not set or the trackduration is longer than old value
        if (durationMeta == null) {
            ((SmilHeadImpl) smil.getHead()).addMeta(SmilMeta.SMIL_META_NAME_TRACK_DURATION, String.format("%dms", track.getDuration()));
        } else {
            long durationOld = Long.parseLong(durationMeta.getContent().replace("ms", ""));
            if (track.getDuration() > durationOld) {
                ((SmilHeadImpl) smil.getHead()).addMeta(SmilMeta.SMIL_META_NAME_TRACK_DURATION, String.format("%dms", track.getDuration()));
            }
        }
    }
    SmilMediaElementImpl media = null;
    if (track.hasVideo()) {
        media = new SmilMediaVideoImpl(track.getURI(), start, start + duration);
    } else if (track.hasAudio()) {
        media = new SmilMediaAudioImpl(track.getURI(), start, start + duration);
    } else {
        media = new SmilMediaReferenceImpl(track.getURI(), start, start + duration);
    }
    media.setParamGroup(trackParamGroup.getId());
    if (parentId == null || "".equals(parentId)) {
        parentId = smil.getBody().getId();
    }
    // add new media element
    ((SmilBodyImpl) smil.getBody()).addMediaElement(media, parentId);
    if (newTrack) {
        return new SmilResponseImpl(smil, new SmilObject[] { media, trackParamGroup });
    } else {
        return new SmilResponseImpl(smil, media);
    }
}
Also used : SmilMediaElementImpl(org.opencastproject.smil.entity.media.element.SmilMediaElementImpl) SmilMediaVideoImpl(org.opencastproject.smil.entity.media.element.SmilMediaVideoImpl) SmilMediaParam(org.opencastproject.smil.entity.media.param.api.SmilMediaParam) SmilMediaReferenceImpl(org.opencastproject.smil.entity.media.element.SmilMediaReferenceImpl) SmilMeta(org.opencastproject.smil.entity.api.SmilMeta) SmilMediaParamGroupImpl(org.opencastproject.smil.entity.media.param.SmilMediaParamGroupImpl) SmilHeadImpl(org.opencastproject.smil.entity.SmilHeadImpl) SmilBodyImpl(org.opencastproject.smil.entity.SmilBodyImpl) SmilMediaAudioImpl(org.opencastproject.smil.entity.media.element.SmilMediaAudioImpl) SmilException(org.opencastproject.smil.api.SmilException) SmilMediaParamGroup(org.opencastproject.smil.entity.media.param.api.SmilMediaParamGroup)

Aggregations

SmilBodyImpl (org.opencastproject.smil.entity.SmilBodyImpl)3 SmilMediaContainer (org.opencastproject.smil.entity.media.container.api.SmilMediaContainer)2 SmilException (org.opencastproject.smil.api.SmilException)1 SmilHeadImpl (org.opencastproject.smil.entity.SmilHeadImpl)1 SmilMeta (org.opencastproject.smil.entity.api.SmilMeta)1 SmilMediaParallelImpl (org.opencastproject.smil.entity.media.container.SmilMediaParallelImpl)1 SmilMediaSequenceImpl (org.opencastproject.smil.entity.media.container.SmilMediaSequenceImpl)1 SmilMediaAudioImpl (org.opencastproject.smil.entity.media.element.SmilMediaAudioImpl)1 SmilMediaElementImpl (org.opencastproject.smil.entity.media.element.SmilMediaElementImpl)1 SmilMediaReferenceImpl (org.opencastproject.smil.entity.media.element.SmilMediaReferenceImpl)1 SmilMediaVideoImpl (org.opencastproject.smil.entity.media.element.SmilMediaVideoImpl)1 SmilMediaParamGroupImpl (org.opencastproject.smil.entity.media.param.SmilMediaParamGroupImpl)1 SmilMediaParam (org.opencastproject.smil.entity.media.param.api.SmilMediaParam)1 SmilMediaParamGroup (org.opencastproject.smil.entity.media.param.api.SmilMediaParamGroup)1