use of org.opencastproject.composer.api.EncodingProfileImpl in project opencast by opencast.
the class ComposerServiceRemoteImpl method listProfiles.
/**
* {@inheritDoc}
*
* @see org.opencastproject.composer.api.ComposerService#listProfiles()
*/
@Override
public EncodingProfile[] listProfiles() {
HttpGet get = new HttpGet("/profiles.xml");
HttpResponse response = null;
try {
response = getResponse(get);
if (response != null) {
EncodingProfileList profileList = EncodingProfileBuilder.getInstance().parseProfileList(response.getEntity().getContent());
List<EncodingProfileImpl> list = profileList.getProfiles();
return list.toArray(new EncodingProfile[list.size()]);
}
} catch (Exception e) {
throw new RuntimeException("Unable to list the encoding profiles registered with the remote composer service proxy", e);
} finally {
closeConnection(response);
}
throw new RuntimeException("Unable to list the encoding profiles registered with the remote composer service proxy");
}
use of org.opencastproject.composer.api.EncodingProfileImpl in project opencast by opencast.
the class EncodingProfileScanner method loadProfile.
/**
* Reads the profile from the given properties
*
* @param profile
* @param properties
* @param artifact
* @return the loaded profile or null if profile
* @throws RuntimeException
*/
private EncodingProfile loadProfile(String profile, Properties properties, File artifact) throws ConfigurationException {
List<String> defaultProperties = new ArrayList<>(10);
String name = getDefaultProperty(profile, PROP_NAME, properties, defaultProperties);
if (name == null || "".equals(name))
throw new ConfigurationException("Distribution profile '" + profile + "' is missing a name (" + PROP_NAME + "). (Check web.xml profiles.)");
EncodingProfileImpl df = new EncodingProfileImpl(profile, name, artifact);
// Output Type
String type = getDefaultProperty(profile, PROP_OUTPUT, properties, defaultProperties);
if (StringUtils.isBlank(type))
throw new ConfigurationException("Output type (" + PROP_OUTPUT + ") of profile '" + profile + "' is missing");
try {
df.setOutputType(MediaType.parseString(StringUtils.trimToEmpty(type)));
} catch (IllegalArgumentException e) {
throw new ConfigurationException("Output type (" + PROP_OUTPUT + ") '" + type + "' of profile '" + profile + "' is unknwon");
}
// Suffixes with tags?
List<String> tags = getTags(profile, properties, defaultProperties);
if (tags.size() > 0) {
for (String tag : tags) {
String prop = PROP_SUFFIX + "." + tag;
String suffixObj = getDefaultProperty(profile, prop, properties, defaultProperties);
df.setSuffix(tag, StringUtils.trim(suffixObj));
}
} else {
// Suffix old stile, without tags
String suffixObj = getDefaultProperty(profile, PROP_SUFFIX, properties, defaultProperties);
if (StringUtils.isBlank(suffixObj))
throw new ConfigurationException("Suffix (" + PROP_SUFFIX + ") of profile '" + profile + "' is missing");
df.setSuffix(StringUtils.trim(suffixObj));
}
// Mimetype
String mimeTypeObj = getDefaultProperty(profile, PROP_MIMETYPE, properties, defaultProperties);
if (StringUtils.isNotBlank(mimeTypeObj)) {
MimeType mimeType;
try {
mimeType = MimeTypes.parseMimeType(mimeTypeObj);
} catch (Exception e) {
throw new ConfigurationException("Mime type (" + PROP_MIMETYPE + ") " + mimeTypeObj + " could not be parsed as a mime type! Expressions are not allowed!");
}
df.setMimeType(mimeType.toString());
}
// Applicable to the following track categories
String applicableObj = getDefaultProperty(profile, PROP_APPLICABLE, properties, defaultProperties);
if (StringUtils.isBlank(applicableObj))
throw new ConfigurationException("Input type (" + PROP_APPLICABLE + ") of profile '" + profile + "' is missing");
df.setApplicableType(MediaType.parseString(StringUtils.trimToEmpty(applicableObj)));
String jobLoad = getDefaultProperty(profile, PROP_JOBLOAD, properties, defaultProperties);
if (!StringUtils.isBlank(jobLoad)) {
df.setJobLoad(Float.valueOf(jobLoad));
logger.debug("Setting job load for profile {} to {}", profile, jobLoad);
}
// Look for extensions
String extensionKey = PROP_PREFIX + profile + ".";
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String key = entry.getKey().toString();
if (key.startsWith(extensionKey) && !defaultProperties.contains(key)) {
String k = key.substring(extensionKey.length());
String v = StringUtils.trimToEmpty(entry.getValue().toString());
df.addExtension(k, v);
}
}
return df;
}
use of org.opencastproject.composer.api.EncodingProfileImpl in project opencast by opencast.
the class PartialImportWorkflowOperationHandlerTest method testDetermineDimension.
@Test
public void testDetermineDimension() throws Exception {
// Setup tracks
VideoStreamImpl videoStream = new VideoStreamImpl("test1");
videoStream.setFrameWidth(80);
videoStream.setFrameHeight(30);
VideoStreamImpl videoStream2 = new VideoStreamImpl("test2");
videoStream2.setFrameWidth(101);
videoStream2.setFrameHeight(50);
TrackImpl videoTrack = new TrackImpl();
videoTrack.setURI(URI.create("/test"));
videoTrack.setVideo(Collections.list((VideoStream) videoStream));
TrackImpl videoTrack2 = new TrackImpl();
videoTrack2.setURI(URI.create("/test"));
videoTrack2.setVideo(Collections.list((VideoStream) videoStream2));
List<Track> tracks = Collections.list((Track) videoTrack, (Track) videoTrack2);
EncodingProfileImpl encodingProfile = new EncodingProfileImpl();
encodingProfile.setIdentifier("test");
ComposerService composerService = EasyMock.createMock(ComposerService.class);
EasyMock.expect(composerService.concat(encodingProfile.getIdentifier(), Dimension.dimension(101, 50), tracks.toArray(new Track[tracks.size()]))).andReturn(null).once();
EasyMock.expect(composerService.concat(encodingProfile.getIdentifier(), Dimension.dimension(100, 50), tracks.toArray(new Track[tracks.size()]))).andReturn(null).once();
EasyMock.replay(composerService);
PartialImportWorkflowOperationHandler handler = new PartialImportWorkflowOperationHandler();
handler.setComposerService(composerService);
handler.startConcatJob(encodingProfile, tracks, -1.0F, false);
handler.startConcatJob(encodingProfile, tracks, -1.0F, true);
}
use of org.opencastproject.composer.api.EncodingProfileImpl in project opencast by opencast.
the class ComposerRestServiceTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageElementBuilder builder = MediaPackageElementBuilderFactory.newInstance().newElementBuilder();
// Set up our arguments and return values
audioTrack = (Track) builder.newElement(Track.TYPE, MediaPackageElements.PRESENTATION_SOURCE);
audioTrack.setIdentifier("audio1");
videoTrack = (Track) builder.newElement(Track.TYPE, MediaPackageElements.PRESENTATION_SOURCE);
videoTrack.setIdentifier("video1");
profileId = "profile1";
job = new JobImpl(1);
job.setStatus(Job.Status.QUEUED);
job.setJobType(ComposerService.JOB_TYPE);
profile = new EncodingProfileImpl();
profile.setIdentifier(profileId);
List<EncodingProfileImpl> list = new ArrayList<EncodingProfileImpl>();
list.add(profile);
profileList = new EncodingProfileList(list);
// Train a mock composer with some known behavior
ComposerService composer = EasyMock.createNiceMock(ComposerService.class);
EasyMock.expect(composer.encode(videoTrack, profileId)).andReturn(job).anyTimes();
EasyMock.expect(composer.mux(videoTrack, audioTrack, profileId)).andReturn(job).anyTimes();
EasyMock.expect(composer.listProfiles()).andReturn(list.toArray(new EncodingProfile[list.size()]));
EasyMock.expect(composer.getProfile(profileId)).andReturn(profile);
EasyMock.expect(composer.concat(EasyMock.eq(profileId), EasyMock.eq(new Dimension(640, 480)), (Track) EasyMock.notNull(), (Track) EasyMock.notNull())).andReturn(job);
EasyMock.expect(composer.concat(EasyMock.eq(profileId), EasyMock.eq(new Dimension(640, 480)), EasyMock.gt(0.0f), (Track) EasyMock.notNull(), (Track) EasyMock.notNull())).andReturn(job);
EasyMock.replay(composer);
// Set up the rest endpoint
restService = new ComposerRestService();
restService.setComposerService(composer);
restService.activate(null);
}
Aggregations