use of org.opencastproject.mediapackage.track.VideoStreamImpl in project opencast by opencast.
the class IngestServiceImplTest method setUp.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Before
public void setUp() throws Exception {
FileUtils.forceMkdir(ingestTempDir);
// set up service and mock workspace
wfr = EasyMock.createNiceMock(WorkingFileRepository.class);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlAttachment);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack1);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack2);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog1);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog2);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack1);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack2);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog1);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog2);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlPackage);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlPackageOld);
workflowInstance = EasyMock.createNiceMock(WorkflowInstance.class);
EasyMock.expect(workflowInstance.getId()).andReturn(workflowInstanceID);
EasyMock.expect(workflowInstance.getState()).andReturn(WorkflowState.STOPPED);
final Capture<MediaPackage> mp = EasyMock.newCapture();
workflowService = EasyMock.createNiceMock(WorkflowService.class);
EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), EasyMock.capture(mp), (Map) EasyMock.anyObject())).andReturn(workflowInstance);
EasyMock.expect(workflowInstance.getMediaPackage()).andAnswer(new IAnswer<MediaPackage>() {
@Override
public MediaPackage answer() throws Throwable {
return mp.getValue();
}
});
EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject(), (Map) EasyMock.anyObject())).andReturn(workflowInstance);
EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(workflowInstance);
EasyMock.expect(workflowService.getWorkflowDefinitionById((String) EasyMock.anyObject())).andReturn(new WorkflowDefinitionImpl());
EasyMock.expect(workflowService.getWorkflowById(EasyMock.anyLong())).andReturn(workflowInstance);
SchedulerService schedulerService = EasyMock.createNiceMock(SchedulerService.class);
Map<String, String> properties = new HashMap<>();
properties.put(CaptureParameters.INGEST_WORKFLOW_DEFINITION, "sample");
properties.put("agent-name", "matterhorn-agent");
EasyMock.expect(schedulerService.getCaptureAgentConfiguration(EasyMock.anyString())).andReturn(properties).anyTimes();
EasyMock.expect(schedulerService.getDublinCore(EasyMock.anyString())).andReturn(DublinCores.read(urlCatalog1.toURL().openStream())).anyTimes();
MediaPackage schedulerMediaPackage = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/source-manifest.xml"), "UTF-8"));
EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andReturn(schedulerMediaPackage).anyTimes();
EasyMock.replay(wfr, workflowInstance, workflowService, schedulerService);
User anonymous = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, new DefaultOrganization(), "test"));
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
HttpEntity entity = EasyMock.createMock(HttpEntity.class);
InputStream is = getClass().getResourceAsStream("/av.mov");
byte[] movie = IOUtils.toByteArray(is);
IOUtils.closeQuietly(is);
EasyMock.expect(entity.getContent()).andReturn(new ByteArrayInputStream(movie)).anyTimes();
EasyMock.replay(entity);
StatusLine statusLine = EasyMock.createMock(StatusLine.class);
EasyMock.expect(statusLine.getStatusCode()).andReturn(200).anyTimes();
EasyMock.replay(statusLine);
Header contentDispositionHeader = EasyMock.createMock(Header.class);
EasyMock.expect(contentDispositionHeader.getValue()).andReturn("attachment; filename=fname.mp4").anyTimes();
EasyMock.replay(contentDispositionHeader);
HttpResponse httpResponse = EasyMock.createMock(HttpResponse.class);
EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLine).anyTimes();
EasyMock.expect(httpResponse.getFirstHeader("Content-Disposition")).andReturn(contentDispositionHeader).anyTimes();
EasyMock.expect(httpResponse.getEntity()).andReturn(entity).anyTimes();
EasyMock.replay(httpResponse);
TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
EasyMock.expect(httpClient.execute((HttpGet) EasyMock.anyObject())).andReturn(httpResponse).anyTimes();
EasyMock.replay(httpClient);
AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(new AccessControlList(), AclScope.Series)).anyTimes();
EasyMock.replay(authorizationService);
MediaInspectionService mediaInspectionService = EasyMock.createNiceMock(MediaInspectionService.class);
EasyMock.expect(mediaInspectionService.enrich(EasyMock.anyObject(MediaPackageElement.class), EasyMock.anyBoolean())).andAnswer(new IAnswer<Job>() {
private int i = 0;
@Override
public Job answer() throws Throwable {
TrackImpl element = (TrackImpl) EasyMock.getCurrentArguments()[0];
element.setDuration(20000L);
if (i % 2 == 0) {
element.addStream(new VideoStreamImpl());
} else {
element.addStream(new AudioStreamImpl());
}
i++;
JobImpl succeededJob = new JobImpl();
succeededJob.setStatus(Status.FINISHED);
succeededJob.setPayload(MediaPackageElementParser.getAsXml(element));
return succeededJob;
}
}).anyTimes();
EasyMock.replay(mediaInspectionService);
service = new IngestServiceImpl();
service.setHttpClient(httpClient);
service.setAuthorizationService(authorizationService);
service.setWorkingFileRepository(wfr);
service.setWorkflowService(workflowService);
service.setSecurityService(securityService);
service.setSchedulerService(schedulerService);
service.setMediaInspectionService(mediaInspectionService);
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
serviceRegistry.registerService(service);
service.setServiceRegistry(serviceRegistry);
service.defaultWorkflowDefinionId = "sample";
serviceRegistry.registerService(service);
}
use of org.opencastproject.mediapackage.track.VideoStreamImpl in project opencast by opencast.
the class VideoSegmenterTest method setUpClass.
/**
* Copies test files to the local file system, since jmf is not able to access movies from the resource section of a
* bundle.
*
* @throws Exception
* if setup fails
*/
@BeforeClass
public static void setUpClass() throws Exception {
track = TrackImpl.fromURI(VideoSegmenterTest.class.getResource(mediaResource).toURI());
track.setFlavor(MediaPackageElements.PRESENTATION_SOURCE);
track.setMimeType(MimeTypes.MJPEG);
track.addStream(new VideoStreamImpl());
track.setDuration(new Long(20000));
track1 = TrackImpl.fromURI(VideoSegmenterTest.class.getResource(mediaResource1).toURI());
track1.setFlavor(MediaPackageElements.PRESENTATION_SOURCE);
track1.setMimeType(MimeTypes.MJPEG);
track1.addStream(new VideoStreamImpl());
track1.setDuration(mediaDuration1);
}
use of org.opencastproject.mediapackage.track.VideoStreamImpl in project opencast by opencast.
the class VideoEditorTest method setUpClass.
/**
* Copies test files to the local file system, since jmf is not able to access movies from the resource section of a
* bundle.
*
* @throws Exception
* if setup fails
*/
@BeforeClass
public static void setUpClass() throws Exception {
/* Set up the 2 tracks for merging */
track1 = TrackImpl.fromURI(VideoEditorTest.class.getResource(mediaResource).toURI());
track1.setIdentifier("track-1");
track1.setFlavor(new MediaPackageElementFlavor("source", "presentater"));
track1.setMimeType(MimeTypes.MJPEG);
track1.addStream(new VideoStreamImpl());
track1.setDuration(movieDuration);
track2 = TrackImpl.fromURI(VideoEditorTest.class.getResource(mediaResource).toURI());
track2.setIdentifier("track-2");
track2.setFlavor(new MediaPackageElementFlavor("source", "presentater"));
track2.setMimeType(MimeTypes.MJPEG);
track2.addStream(new VideoStreamImpl());
track2.setDuration(movieDuration);
/* Start of Smil mockups */
URL mediaUrl = VideoEditorTest.class.getResource(mediaResource);
URL smilUrl = VideoEditorTest.class.getResource(smilResource);
String smilString = IOUtils.toString(smilUrl);
String trackParamGroupId = "pg-a6d8e576-495f-44c7-8ed7-b5b47c807f0f";
SmilMediaParam param1 = EasyMock.createNiceMock(SmilMediaParam.class);
EasyMock.expect(param1.getName()).andReturn("track-id").anyTimes();
EasyMock.expect(param1.getValue()).andReturn("track-1").anyTimes();
EasyMock.expect(param1.getId()).andReturn("param-e2f41e7d-caba-401b-a03a-e524296cb235").anyTimes();
SmilMediaParam param2 = EasyMock.createNiceMock(SmilMediaParam.class);
EasyMock.expect(param2.getName()).andReturn("track-src").anyTimes();
EasyMock.expect(param2.getValue()).andReturn("file:" + mediaUrl.getPath()).anyTimes();
EasyMock.expect(param2.getId()).andReturn("param-1bd5e839-0a74-4310-b1d2-daba07914f79").anyTimes();
SmilMediaParam param3 = EasyMock.createNiceMock(SmilMediaParam.class);
EasyMock.expect(param3.getName()).andReturn("track-flavor").anyTimes();
EasyMock.expect(param3.getValue()).andReturn("source/presenter").anyTimes();
EasyMock.expect(param3.getId()).andReturn("param-1bd5e839-0a74-4310-b1d2-daba07914f79").anyTimes();
EasyMock.replay(param1, param2, param3);
List<SmilMediaParam> params = new ArrayList<SmilMediaParam>();
params.add(param1);
params.add(param2);
params.add(param3);
SmilMediaParamGroup group1 = EasyMock.createNiceMock(SmilMediaParamGroup.class);
EasyMock.expect(group1.getParams()).andReturn(params).anyTimes();
EasyMock.expect(group1.getId()).andReturn(trackParamGroupId).anyTimes();
EasyMock.replay(group1);
List<SmilMediaParamGroup> paramGroups = new ArrayList<SmilMediaParamGroup>();
paramGroups.add(group1);
SmilHead head = EasyMock.createNiceMock(SmilHead.class);
EasyMock.expect(head.getParamGroups()).andReturn(paramGroups).anyTimes();
EasyMock.replay(head);
SmilMediaElement object1 = EasyMock.createNiceMock(SmilMediaElement.class);
EasyMock.expect(object1.isContainer()).andReturn(false).anyTimes();
EasyMock.expect(object1.getParamGroup()).andReturn(trackParamGroupId).anyTimes();
EasyMock.expect(object1.getClipBeginMS()).andReturn(1000L).anyTimes();
EasyMock.expect(object1.getClipEndMS()).andReturn(12000L).anyTimes();
EasyMock.expect(object1.getSrc()).andReturn(mediaUrl.toURI()).anyTimes();
EasyMock.replay(object1);
SmilMediaElement object2 = EasyMock.createNiceMock(SmilMediaElement.class);
EasyMock.expect(object2.isContainer()).andReturn(false).anyTimes();
EasyMock.expect(object2.getParamGroup()).andReturn(trackParamGroupId).anyTimes();
EasyMock.expect(object2.getClipBeginMS()).andReturn(1000L).anyTimes();
EasyMock.expect(object2.getClipEndMS()).andReturn(13000L).anyTimes();
EasyMock.expect(object2.getSrc()).andReturn(mediaUrl.toURI()).anyTimes();
EasyMock.replay(object2);
List<SmilMediaObject> objects = new ArrayList<SmilMediaObject>();
objects.add(object1);
objects.add(object2);
SmilMediaContainer objectContainer = EasyMock.createNiceMock(SmilMediaContainer.class);
EasyMock.expect(objectContainer.isContainer()).andReturn(true).anyTimes();
EasyMock.expect(objectContainer.getContainerType()).andReturn(SmilMediaContainer.ContainerType.PAR).anyTimes();
EasyMock.expect(objectContainer.getElements()).andReturn(objects).anyTimes();
EasyMock.replay(objectContainer);
List<SmilMediaObject> containerObjects = new ArrayList<SmilMediaObject>();
containerObjects.add(objectContainer);
SmilBody body = EasyMock.createNiceMock(SmilBody.class);
EasyMock.expect(body.getMediaElements()).andReturn(containerObjects).anyTimes();
EasyMock.replay(body);
smil = EasyMock.createNiceMock(Smil.class);
EasyMock.expect(smil.get(trackParamGroupId)).andReturn(group1).anyTimes();
EasyMock.expect(smil.getBody()).andReturn(body).anyTimes();
EasyMock.expect(smil.getHead()).andReturn(head).anyTimes();
EasyMock.expect(smil.toXML()).andReturn(smilString).anyTimes();
EasyMock.expect(smil.getId()).andReturn("s-ec404c2a-5092-4cd4-8717-7b7bbc244656").anyTimes();
EasyMock.replay(smil);
SmilResponse response = EasyMock.createNiceMock(SmilResponse.class);
EasyMock.expect(response.getSmil()).andReturn(smil).anyTimes();
EasyMock.replay(response);
smilService = EasyMock.createNiceMock(SmilService.class);
EasyMock.expect(smilService.fromXml((String) EasyMock.anyObject())).andReturn(response).anyTimes();
EasyMock.replay(smilService);
/* End of Smil mockups */
}
use of org.opencastproject.mediapackage.track.VideoStreamImpl in project opencast by opencast.
the class AbstractEventEndpoint method streamsToJSON.
private List<Field> streamsToJSON(org.opencastproject.mediapackage.Stream[] streams) {
List<Field> fields = new ArrayList<>();
List<JValue> audioList = new ArrayList<>();
List<JValue> videoList = new ArrayList<>();
for (org.opencastproject.mediapackage.Stream stream : streams) {
// TODO There is a bug with the stream ids, see MH-10325
if (stream instanceof AudioStreamImpl) {
List<Field> audio = new ArrayList<>();
AudioStream audioStream = (AudioStream) stream;
audio.add(f("id", v(audioStream.getIdentifier(), BLANK)));
audio.add(f("type", v(audioStream.getFormat(), BLANK)));
audio.add(f("channels", v(audioStream.getChannels(), BLANK)));
audio.add(f("bitrate", v(audioStream.getBitRate(), BLANK)));
audio.add(f("bitdepth", v(audioStream.getBitDepth(), BLANK)));
audio.add(f("samplingrate", v(audioStream.getSamplingRate(), BLANK)));
audio.add(f("framecount", v(audioStream.getFrameCount(), BLANK)));
audio.add(f("peakleveldb", v(audioStream.getPkLevDb(), BLANK)));
audio.add(f("rmsleveldb", v(audioStream.getRmsLevDb(), BLANK)));
audio.add(f("rmspeakdb", v(audioStream.getRmsPkDb(), BLANK)));
audioList.add(obj(audio));
} else if (stream instanceof VideoStreamImpl) {
List<Field> video = new ArrayList<>();
VideoStream videoStream = (VideoStream) stream;
video.add(f("id", v(videoStream.getIdentifier(), BLANK)));
video.add(f("type", v(videoStream.getFormat(), BLANK)));
video.add(f("bitrate", v(videoStream.getBitRate(), BLANK)));
video.add(f("framerate", v(videoStream.getFrameRate(), BLANK)));
video.add(f("resolution", v(videoStream.getFrameWidth() + "x" + videoStream.getFrameHeight(), BLANK)));
video.add(f("framecount", v(videoStream.getFrameCount(), BLANK)));
video.add(f("scantype", v(videoStream.getScanType(), BLANK)));
video.add(f("scanorder", v(videoStream.getScanOrder(), BLANK)));
videoList.add(obj(video));
} else {
throw new IllegalArgumentException("Stream must be either audio or video");
}
}
fields.add(f("audio", arr(audioList)));
fields.add(f("video", arr(videoList)));
return fields;
}
use of org.opencastproject.mediapackage.track.VideoStreamImpl in project opencast by opencast.
the class SmilServiceImplTest method testAddClip.
/**
* Test of addClip(s) methods, of class SmilServiceImpl.
*/
@Test
public void testAddClip() throws Exception {
TrackImpl videoTrack = new TrackImpl();
videoTrack.setIdentifier("track-1");
videoTrack.setFlavor(new MediaPackageElementFlavor("source", "presentation"));
videoTrack.setURI(new URI("http://hostname/video.mp4"));
videoTrack.addStream(new VideoStreamImpl());
videoTrack.setDuration(1000000000000L);
SmilResponse smilResponse = smilService.createNewSmil();
smilResponse = smilService.addParallel(smilResponse.getSmil());
SmilMediaContainer par = (SmilMediaContainer) smilResponse.getEntity();
// add video track into parallel element
smilResponse = smilService.addClip(smilResponse.getSmil(), par.getId(), videoTrack, 1000L, 1000000L);
// logger.info(smilResponse.getSmil().toXML());
SmilMediaObject media = null;
for (SmilObject entity : smilResponse.getEntities()) {
if (entity instanceof SmilMediaObject) {
media = (SmilMediaObject) entity;
break;
}
}
assertNotNull(media);
assertEquals(media.getId(), ((SmilMediaContainer) smilResponse.getSmil().getBody().getMediaElements().get(0)).getElements().get(0).getId());
assertTrue(media instanceof SmilMediaVideoImpl);
assertSame(((SmilMediaElement) media).getMediaType(), SmilMediaElement.MediaType.VIDEO);
// 1000 milliseconds = 1 second
assertEquals(1000L, ((SmilMediaElement) media).getClipBeginMS());
// duration is 1000000 milliseconds = 1000 soconds
// start + duration = 1s + 1000s = 1001s
assertEquals(1001000L, ((SmilMediaElement) media).getClipEndMS());
TrackImpl audioTrack = new TrackImpl();
audioTrack.setIdentifier("track-2");
audioTrack.setFlavor(new MediaPackageElementFlavor("source", "presenter"));
audioTrack.setURI(new URI("http://hostname/audio.mp3"));
audioTrack.addStream(new AudioStreamImpl());
audioTrack.setDuration(1000000000000L);
// add audio track into parallel element
smilResponse = smilService.addClip(smilResponse.getSmil(), par.getId(), audioTrack, 1000L, 1000000L);
// logger.info(smilResponse.getSmil().toXML());
media = null;
for (SmilObject entity : smilResponse.getEntities()) {
if (entity instanceof SmilMediaObject) {
media = (SmilMediaObject) entity;
break;
}
}
assertNotNull(media);
assertEquals(media.getId(), ((SmilMediaContainer) smilResponse.getSmil().getBody().getMediaElements().get(0)).getElements().get(1).getId());
assertTrue(media instanceof SmilMediaAudioImpl);
assertSame(((SmilMediaElement) media).getMediaType(), SmilMediaElement.MediaType.AUDIO);
// 1000 milliseconds = 1 second
assertEquals(1000L, ((SmilMediaElement) media).getClipBeginMS());
// duration is 1000000 milliseconds = 1000 soconds
// start + duration = 1s + 1000s = 1001s
assertEquals(1001000L, ((SmilMediaElement) media).getClipEndMS());
// add new par
smilResponse = smilService.addParallel(smilResponse.getSmil());
par = (SmilMediaContainer) smilResponse.getEntity();
// add tracks (as array) to par
smilResponse = smilService.addClips(smilResponse.getSmil(), par.getId(), new Track[] { audioTrack, videoTrack }, 15000L, 1000L);
// logger.info(smilResponse.getSmil().toXML());
assertSame(2, smilResponse.getEntitiesCount());
assertTrue(smilResponse.getEntities()[0] instanceof SmilMediaElement);
// get audio element
SmilMediaElement mediaElement = (SmilMediaElement) smilResponse.getEntities()[0];
assertTrue(mediaElement.getMediaType() == SmilMediaElement.MediaType.AUDIO);
// 15000ms = 15s
assertEquals(15000L, mediaElement.getClipBeginMS());
// start + duration = 15s + 1s = 16s
assertEquals(16000L, mediaElement.getClipEndMS());
// get video element
mediaElement = (SmilMediaElement) smilResponse.getEntities()[1];
assertTrue(mediaElement.getMediaType() == SmilMediaElement.MediaType.VIDEO);
// 15000ms = 15s
assertEquals(15000L, mediaElement.getClipBeginMS());
// start + duration = 15s + 1s = 16s
assertEquals(16000L, mediaElement.getClipEndMS());
}
Aggregations