Search in sources :

Example 1 with EncodingProfileImpl

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");
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) EncodingProfileList(org.opencastproject.composer.api.EncodingProfileList) HttpResponse(org.apache.http.HttpResponse) EncodingProfileImpl(org.opencastproject.composer.api.EncodingProfileImpl) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) EncoderException(org.opencastproject.composer.api.EncoderException)

Example 2 with EncodingProfileImpl

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;
}
Also used : ConfigurationException(org.opencastproject.util.ConfigurationException) ArrayList(java.util.ArrayList) EncodingProfileImpl(org.opencastproject.composer.api.EncodingProfileImpl) HashMap(java.util.HashMap) Map(java.util.Map) MimeType(org.opencastproject.util.MimeType) ConfigurationException(org.opencastproject.util.ConfigurationException) IOException(java.io.IOException)

Example 3 with EncodingProfileImpl

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);
}
Also used : TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) ComposerService(org.opencastproject.composer.api.ComposerService) VideoStream(org.opencastproject.mediapackage.VideoStream) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) EncodingProfileImpl(org.opencastproject.composer.api.EncodingProfileImpl) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Example 4 with EncodingProfileImpl

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);
}
Also used : MediaPackageElementBuilder(org.opencastproject.mediapackage.MediaPackageElementBuilder) JobImpl(org.opencastproject.job.api.JobImpl) ComposerService(org.opencastproject.composer.api.ComposerService) ArrayList(java.util.ArrayList) EncodingProfileList(org.opencastproject.composer.api.EncodingProfileList) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) Dimension(org.opencastproject.composer.layout.Dimension) EncodingProfileImpl(org.opencastproject.composer.api.EncodingProfileImpl) Before(org.junit.Before)

Aggregations

EncodingProfileImpl (org.opencastproject.composer.api.EncodingProfileImpl)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ComposerService (org.opencastproject.composer.api.ComposerService)2 EncodingProfileList (org.opencastproject.composer.api.EncodingProfileList)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpResponse (org.apache.http.HttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 Before (org.junit.Before)1 Test (org.junit.Test)1 EncoderException (org.opencastproject.composer.api.EncoderException)1 EncodingProfile (org.opencastproject.composer.api.EncodingProfile)1 Dimension (org.opencastproject.composer.layout.Dimension)1 JobImpl (org.opencastproject.job.api.JobImpl)1 MediaPackageElementBuilder (org.opencastproject.mediapackage.MediaPackageElementBuilder)1 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)1 Track (org.opencastproject.mediapackage.Track)1 VideoStream (org.opencastproject.mediapackage.VideoStream)1 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)1