Search in sources :

Example 6 with VideoStreamImpl

use of org.opencastproject.mediapackage.track.VideoStreamImpl in project opencast by opencast.

the class LiveScheduleServiceImpl method buildStreamingTrack.

Track buildStreamingTrack(String uriString, MediaPackageElementFlavor flavor, String mimeType, String resolution, long duration) throws URISyntaxException {
    URI uri = new URI(uriString);
    MediaPackageElementBuilder elementBuilder = MediaPackageElementBuilderFactory.newInstance().newElementBuilder();
    MediaPackageElement element = elementBuilder.elementFromURI(uri, MediaPackageElement.Type.Track, flavor);
    TrackImpl track = (TrackImpl) element;
    // Set duration and mime type
    track.setDuration(duration);
    track.setLive(true);
    track.setMimeType(MimeTypes.parseMimeType(mimeType));
    VideoStreamImpl video = new VideoStreamImpl("video-" + flavor.getType() + "-" + flavor.getSubtype());
    // Set video resolution
    String[] dimensions = resolution.split("x");
    video.setFrameWidth(Integer.parseInt(dimensions[0]));
    video.setFrameHeight(Integer.parseInt(dimensions[1]));
    track.addStream(video);
    logger.debug("Creating live track element of flavor {}, resolution {}, and url {}", new Object[] { flavor, resolution, uriString });
    return track;
}
Also used : MediaPackageElementBuilder(org.opencastproject.mediapackage.MediaPackageElementBuilder) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) URI(java.net.URI)

Example 7 with VideoStreamImpl

use of org.opencastproject.mediapackage.track.VideoStreamImpl in project opencast by opencast.

the class TimelinePreviewsServiceImplTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    track = TrackImpl.fromURI(TimelinePreviewsServiceImplTest.class.getResource(mediaResource).toURI());
    track.setFlavor(MediaPackageElements.PRESENTATION_SOURCE);
    track.setMimeType(MimeTypes.MJPEG);
    track.addStream(new VideoStreamImpl());
    track.setDuration(mediaDuration);
    track.setIdentifier(IdBuilderFactory.newInstance().newIdBuilder().createNew().compact());
}
Also used : VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) BeforeClass(org.junit.BeforeClass)

Example 8 with VideoStreamImpl

use of org.opencastproject.mediapackage.track.VideoStreamImpl in project opencast by opencast.

the class AnalyzeTracksWorkflowOperationHandlerTest method testStart.

@Test
public void testStart() throws MediaPackageException, WorkflowOperationException {
    MediaPackage mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    VideoStreamImpl videoStream = new VideoStreamImpl("234");
    videoStream.setFrameWidth(1280);
    videoStream.setFrameHeight(720);
    videoStream.setFrameRate(30.0f);
    TrackImpl track = new TrackImpl();
    track.setFlavor(MediaPackageElementFlavor.parseFlavor("presenter/source"));
    track.addStream(videoStream);
    JobContext jobContext = EasyMock.createMock(JobContext.class);
    EasyMock.replay(jobContext);
    WorkflowOperationInstance operationInstance = EasyMock.createMock(WorkflowOperationInstance.class);
    String[][] config = { { AnalyzeTracksWorkflowOperationHandler.OPT_SOURCE_FLAVOR, "*/source" }, { AnalyzeTracksWorkflowOperationHandler.OPT_VIDEO_ASPECT, "4/3,16/9" } };
    for (String[] cfg : config) {
        EasyMock.expect(operationInstance.getConfiguration(cfg[0])).andReturn(cfg[1]).anyTimes();
    }
    EasyMock.expect(operationInstance.getConfiguration(AnalyzeTracksWorkflowOperationHandler.OPT_FAIL_NO_TRACK)).andReturn("true");
    EasyMock.expect(operationInstance.getConfiguration(AnalyzeTracksWorkflowOperationHandler.OPT_FAIL_NO_TRACK)).andReturn("false").anyTimes();
    EasyMock.replay(operationInstance);
    WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
    EasyMock.expect(workflowInstance.getId()).andReturn(0L).anyTimes();
    EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(operationInstance).anyTimes();
    EasyMock.replay(workflowInstance);
    // With no matching track (should fail)
    try {
        operationHandler.start(workflowInstance, jobContext);
        fail();
    } catch (WorkflowOperationException e) {
        logger.info("Fail on no tracks works");
    }
    WorkflowOperationResult workflowOperationResult = operationHandler.start(workflowInstance, jobContext);
    Map<String, String> properties = workflowOperationResult.getProperties();
    assertTrue(properties.isEmpty());
    // With matching track
    mediaPackage.add(track);
    workflowOperationResult = operationHandler.start(workflowInstance, jobContext);
    properties = workflowOperationResult.getProperties();
    String[][] props = { { "presenter_source_media", "true" }, { "presenter_source_audio", "false" }, { "presenter_source_aspect", "16/9" }, { "presenter_source_resolution_y", "720" }, { "presenter_source_resolution_x", "1280" }, { "presenter_source_aspect_snap", "16/9" }, { "presenter_source_video", "true" }, { "presenter_source_framerate", "30.0" } };
    for (String[] prop : props) {
        assertEquals(prop[1], properties.get(prop[0]));
    }
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) JobContext(org.opencastproject.job.api.JobContext) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 9 with VideoStreamImpl

use of org.opencastproject.mediapackage.track.VideoStreamImpl in project opencast by opencast.

the class TrackBuilderPlugin method elementFromManifest.

/**
 * @see org.opencastproject.mediapackage.elementbuilder.MediaPackageElementBuilderPlugin#elementFromManifest(org.w3c.dom.Node,
 *      org.opencastproject.mediapackage.MediaPackageSerializer)
 */
@Override
public MediaPackageElement elementFromManifest(Node elementNode, MediaPackageSerializer serializer) throws UnsupportedElementException {
    String id = null;
    MimeType mimeType = null;
    MediaPackageElementFlavor flavor = null;
    TrackImpl.StreamingProtocol transport = null;
    String reference = null;
    URI url = null;
    long size = -1;
    Checksum checksum = null;
    try {
        // id
        id = (String) xpath.evaluate("@id", elementNode, XPathConstants.STRING);
        // url
        url = serializer.decodeURI(new URI(xpath.evaluate("url/text()", elementNode).trim()));
        // reference
        reference = (String) xpath.evaluate("@ref", elementNode, XPathConstants.STRING);
        // size
        String trackSize = xpath.evaluate("size/text()", elementNode).trim();
        if (!"".equals(trackSize))
            size = Long.parseLong(trackSize);
        // flavor
        String flavorValue = (String) xpath.evaluate("@type", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(flavorValue))
            flavor = MediaPackageElementFlavor.parseFlavor(flavorValue);
        // transport
        String transportValue = (String) xpath.evaluate("@transport", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(transportValue))
            transport = TrackImpl.StreamingProtocol.valueOf(transportValue);
        // checksum
        String checksumValue = (String) xpath.evaluate("checksum/text()", elementNode, XPathConstants.STRING);
        String checksumType = (String) xpath.evaluate("checksum/@type", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(checksumValue) && checksumType != null)
            checksum = Checksum.create(checksumType.trim(), checksumValue.trim());
        // mimetype
        String mimeTypeValue = (String) xpath.evaluate("mimetype/text()", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(mimeTypeValue))
            mimeType = MimeTypes.parseMimeType(mimeTypeValue);
        // 
        // Build the track
        TrackImpl track = TrackImpl.fromURI(url);
        if (StringUtils.isNotBlank(id))
            track.setIdentifier(id);
        // Add url
        track.setURI(url);
        // Add reference
        if (StringUtils.isNotEmpty(reference))
            track.referTo(MediaPackageReferenceImpl.fromString(reference));
        // Set size
        if (size > 0)
            track.setSize(size);
        // Set checksum
        if (checksum != null)
            track.setChecksum(checksum);
        // Set mimetpye
        if (mimeType != null)
            track.setMimeType(mimeType);
        if (flavor != null)
            track.setFlavor(flavor);
        // set transport
        if (transport != null)
            track.setTransport(transport);
        // description
        String description = (String) xpath.evaluate("description/text()", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotBlank(description))
            track.setElementDescription(description.trim());
        // tags
        NodeList tagNodes = (NodeList) xpath.evaluate("tags/tag", elementNode, XPathConstants.NODESET);
        for (int i = 0; i < tagNodes.getLength(); i++) {
            track.addTag(tagNodes.item(i).getTextContent());
        }
        // duration
        try {
            String strDuration = (String) xpath.evaluate("duration/text()", elementNode, XPathConstants.STRING);
            if (StringUtils.isNotEmpty(strDuration)) {
                long duration = Long.parseLong(strDuration.trim());
                track.setDuration(duration);
            }
        } catch (NumberFormatException e) {
            throw new UnsupportedElementException("Duration of track " + url + " is malformatted");
        }
        // is live
        String strLive = (String) xpath.evaluate("live/text()", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(strLive)) {
            boolean live = Boolean.parseBoolean(strLive.trim());
            track.setLive(live);
        }
        // audio settings
        Node audioSettingsNode = (Node) xpath.evaluate("audio", elementNode, XPathConstants.NODE);
        if (audioSettingsNode != null && audioSettingsNode.hasChildNodes()) {
            try {
                AudioStreamImpl as = AudioStreamImpl.fromManifest(createStreamID(track), audioSettingsNode, xpath);
                track.addStream(as);
            } catch (IllegalStateException e) {
                throw new UnsupportedElementException("Illegal state encountered while reading audio settings from " + url + ": " + e.getMessage());
            } catch (XPathException e) {
                throw new UnsupportedElementException("Error while parsing audio settings from " + url + ": " + e.getMessage());
            }
        }
        // video settings
        Node videoSettingsNode = (Node) xpath.evaluate("video", elementNode, XPathConstants.NODE);
        if (videoSettingsNode != null && videoSettingsNode.hasChildNodes()) {
            try {
                VideoStreamImpl vs = VideoStreamImpl.fromManifest(createStreamID(track), videoSettingsNode, xpath);
                track.addStream(vs);
            } catch (IllegalStateException e) {
                throw new UnsupportedElementException("Illegal state encountered while reading video settings from " + url + ": " + e.getMessage());
            } catch (XPathException e) {
                throw new UnsupportedElementException("Error while parsing video settings from " + url + ": " + e.getMessage());
            }
        }
        return track;
    } catch (XPathExpressionException e) {
        throw new UnsupportedElementException("Error while reading track information from manifest: " + e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        throw new UnsupportedElementException("Unsupported digest algorithm: " + e.getMessage());
    } catch (URISyntaxException e) {
        throw new UnsupportedElementException("Error while reading presenter track " + url + ": " + e.getMessage());
    }
}
Also used : XPathException(javax.xml.xpath.XPathException) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) AudioStreamImpl(org.opencastproject.mediapackage.track.AudioStreamImpl) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URISyntaxException(java.net.URISyntaxException) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) MimeType(org.opencastproject.util.MimeType) UnsupportedElementException(org.opencastproject.mediapackage.UnsupportedElementException) Checksum(org.opencastproject.util.Checksum)

Example 10 with VideoStreamImpl

use of org.opencastproject.mediapackage.track.VideoStreamImpl in project opencast by opencast.

the class MediaPackageJaxbSerializationTest method testJaxbSerialization.

@Test
public void testJaxbSerialization() throws Exception {
    // Build a media package
    MediaPackageElementBuilder elementBuilder = MediaPackageElementBuilderFactory.newInstance().newElementBuilder();
    MediaPackage mp = new MediaPackageImpl(new IdImpl("123"));
    Attachment attachment = (Attachment) elementBuilder.elementFromURI(new URI("http://opencastproject.org/index.html"), Type.Attachment, Attachment.FLAVOR);
    attachment.setChecksum(Checksum.create(ChecksumType.DEFAULT_TYPE, "123456abcd"));
    mp.add(attachment);
    Catalog cat1 = (Catalog) elementBuilder.elementFromURI(new URI("http://opencastproject.org/index.html"), Catalog.TYPE, MediaPackageElements.EPISODE);
    cat1.setChecksum(Checksum.create(ChecksumType.DEFAULT_TYPE, "7891011abcd"));
    mp.add(cat1);
    Catalog cat2 = (Catalog) elementBuilder.elementFromURI(new URI("http://opencastproject.org/index.html"), Catalog.TYPE, MediaPackageElements.EPISODE);
    cat2.setChecksum(Checksum.create(ChecksumType.DEFAULT_TYPE, "7891011abcd"));
    mp.addDerived(cat2, cat1);
    TrackImpl track = (TrackImpl) elementBuilder.elementFromURI(new URI("http://opencastproject.org/video.mpg"), Track.TYPE, MediaPackageElements.PRESENTER_SOURCE);
    track.addStream(new VideoStreamImpl("video-stream-1"));
    track.addStream(new VideoStreamImpl("video-stream-2"));
    mp.add(track);
    // Serialize the media package
    String xml = MediaPackageParser.getAsXml(mp);
    assertNotNull(xml);
    // Serialize the media package as JSON
    String json = MediaPackageParser.getAsJSON(mp);
    assertNotNull(json);
    // Deserialize the media package
    MediaPackage deserialized = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(IOUtils.toInputStream(xml, "UTF-8"));
    // Ensure that the deserialized mediapackage is correct
    assertEquals(2, deserialized.getCatalogs().length);
    assertEquals(1, deserialized.getAttachments().length);
    assertEquals(1, deserialized.getTracks().length);
    assertEquals(2, deserialized.getTracks()[0].getStreams().length);
    assertEquals(1, deserialized.getCatalogs(new MediaPackageReferenceImpl(cat1)).length);
}
Also used : TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Test(org.junit.Test)

Aggregations

VideoStreamImpl (org.opencastproject.mediapackage.track.VideoStreamImpl)17 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)12 Test (org.junit.Test)9 URI (java.net.URI)7 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)7 SmilResponse (org.opencastproject.smil.api.SmilResponse)6 AudioStreamImpl (org.opencastproject.mediapackage.track.AudioStreamImpl)4 BeforeClass (org.junit.BeforeClass)3 MediaPackage (org.opencastproject.mediapackage.MediaPackage)3 SmilMediaObject (org.opencastproject.smil.entity.media.api.SmilMediaObject)3 SmilMediaContainer (org.opencastproject.smil.entity.media.container.api.SmilMediaContainer)3 SmilMediaElement (org.opencastproject.smil.entity.media.element.api.SmilMediaElement)3 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)3 ArrayList (java.util.ArrayList)2 JobContext (org.opencastproject.job.api.JobContext)2 Track (org.opencastproject.mediapackage.Track)2 VideoStream (org.opencastproject.mediapackage.VideoStream)2 AccessControlList (org.opencastproject.security.api.AccessControlList)2 Field (com.entwinemedia.fn.data.json.Field)1 JValue (com.entwinemedia.fn.data.json.JValue)1