use of org.opencastproject.mediapackage.track.AudioStreamImpl 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.AudioStreamImpl 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.AudioStreamImpl in project opencast by opencast.
the class NormalizeAudioWorkflowOperationHandler method extendAudioStream.
private void extendAudioStream(TrackImpl trackToExtend, TrackImpl audioTrackSource) {
AudioStreamImpl extendStream = (AudioStreamImpl) trackToExtend.getAudio().get(0);
AudioStream sourceStream = audioTrackSource.getAudio().get(0);
extendStream.setPkLevDb(sourceStream.getPkLevDb());
extendStream.setRmsLevDb(sourceStream.getRmsLevDb());
extendStream.setRmsPkDb(sourceStream.getRmsPkDb());
}
use of org.opencastproject.mediapackage.track.AudioStreamImpl 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());
}
use of org.opencastproject.mediapackage.track.AudioStreamImpl in project opencast by opencast.
the class SoxServiceImpl method addAudioMetadata.
private Track addAudioMetadata(Track audioTrack, List<String> metadata) {
TrackImpl track = (TrackImpl) audioTrack;
List<AudioStream> audio = track.getAudio();
if (audio.size() == 0) {
audio.add(new AudioStreamImpl());
logger.info("No audio streams found created new audio stream");
}
AudioStreamImpl audioStream = (AudioStreamImpl) audio.get(0);
if (audio.size() > 1)
logger.info("Multiple audio streams found, take first audio stream {}", audioStream);
for (String value : metadata) {
if (value.startsWith("Pk lev dB")) {
Float pkLevDb = new Float(StringUtils.substringAfter(value, "Pk lev dB").trim());
audioStream.setPkLevDb(pkLevDb);
} else if (value.startsWith("RMS lev dB")) {
Float rmsLevDb = new Float(StringUtils.substringAfter(value, "RMS lev dB").trim());
audioStream.setRmsLevDb(rmsLevDb);
} else if (value.startsWith("RMS Pk dB")) {
Float rmsPkDb = new Float(StringUtils.substringAfter(value, "RMS Pk dB").trim());
audioStream.setRmsPkDb(rmsPkDb);
}
}
return track;
}
Aggregations