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