Search in sources :

Example 6 with JobBarrier

use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.

the class VideoSegmenterTest method testAnalyzeOptimization.

@Test
public void testAnalyzeOptimization() throws Exception {
    Job receipt = vsegmenter1.segment(track1);
    JobBarrier jobBarrier = new JobBarrier(null, serviceRegistry1, 1000, receipt);
    jobBarrier.waitForJobs();
    Catalog catalog = (Catalog) MediaPackageElementParser.getFromXml(receipt.getPayload());
    Mpeg7Catalog mpeg7 = new Mpeg7CatalogImpl(catalog.getURI().toURL().openStream());
    // Is there multimedia content in the mpeg7?
    assertTrue("Audiovisual content was expected", mpeg7.hasVideoContent());
    assertNotNull("Audiovisual content expected", mpeg7.multimediaContent().next().elements().hasNext());
    MultimediaContentType contentType = mpeg7.multimediaContent().next().elements().next();
    // Is there at least one segment?
    TemporalDecomposition<? extends Segment> segments = contentType.getTemporalDecomposition();
    Iterator<? extends Segment> si = segments.segments();
    assertTrue(si.hasNext());
    // Is the error of optimization small enough?
    int segmentCounter = 0;
    for (; si.hasNext(); ++segmentCounter) {
        si.next();
    }
    float error = Math.abs((segmentCounter - vsegmenter1.prefNumber) / (float) vsegmenter1.prefNumber);
    assertTrue("Error of Optimization is too big", error <= vsegmenter1.maxError);
}
Also used : Mpeg7Catalog(org.opencastproject.metadata.mpeg7.Mpeg7Catalog) Mpeg7CatalogImpl(org.opencastproject.metadata.mpeg7.Mpeg7CatalogImpl) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) MultimediaContentType(org.opencastproject.metadata.mpeg7.MultimediaContentType) Catalog(org.opencastproject.mediapackage.Catalog) Mpeg7Catalog(org.opencastproject.metadata.mpeg7.Mpeg7Catalog) Test(org.junit.Test)

Example 7 with JobBarrier

use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.

the class VideoSegmenterTest method testAnalyze.

@Test
public void testAnalyze() throws Exception {
    Job receipt = vsegmenter.segment(track);
    JobBarrier jobBarrier = new JobBarrier(null, serviceRegistry, 1000, receipt);
    jobBarrier.waitForJobs();
    Catalog catalog = (Catalog) MediaPackageElementParser.getFromXml(receipt.getPayload());
    Mpeg7Catalog mpeg7 = new Mpeg7CatalogImpl(catalog.getURI().toURL().openStream());
    // Is there multimedia content in the mpeg7?
    assertTrue("Audiovisual content was expected", mpeg7.hasVideoContent());
    assertNotNull("Audiovisual content expected", mpeg7.multimediaContent().next().elements().hasNext());
    MultimediaContentType contentType = mpeg7.multimediaContent().next().elements().next();
    // Is there at least one segment?
    TemporalDecomposition<? extends Segment> segments = contentType.getTemporalDecomposition();
    Iterator<? extends Segment> si = segments.segments();
    assertTrue(si.hasNext());
    Segment firstSegment = si.next();
    MediaTime firstSegmentMediaTime = firstSegment.getMediaTime();
    long startTime = firstSegmentMediaTime.getMediaTimePoint().getTimeInMilliseconds();
    long duration = firstSegmentMediaTime.getMediaDuration().getDurationInMilliseconds();
    assertEquals("Unexpected start time of first segment", 0, startTime);
    assertEquals("Unexpected duration of first segment", firstSegmentDuration, duration);
    // What about the second one?
    assertTrue("Video is expected to have more than one segment", si.hasNext());
    Segment secondSegment = si.next();
    MediaTime secondSegmentMediaTime = secondSegment.getMediaTime();
    startTime = secondSegmentMediaTime.getMediaTimePoint().getTimeInMilliseconds();
    duration = secondSegmentMediaTime.getMediaDuration().getDurationInMilliseconds();
    assertEquals("Unexpected start time of second segment", firstSegmentDuration, startTime);
    assertEquals("Unexpected duration of second segment", secondSegmentDuration, duration);
    // There should be no third segment
    assertFalse("Found an unexpected third video segment", si.hasNext());
}
Also used : Mpeg7Catalog(org.opencastproject.metadata.mpeg7.Mpeg7Catalog) MediaTime(org.opencastproject.metadata.mpeg7.MediaTime) Mpeg7CatalogImpl(org.opencastproject.metadata.mpeg7.Mpeg7CatalogImpl) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) MultimediaContentType(org.opencastproject.metadata.mpeg7.MultimediaContentType) Catalog(org.opencastproject.mediapackage.Catalog) Mpeg7Catalog(org.opencastproject.metadata.mpeg7.Mpeg7Catalog) Segment(org.opencastproject.metadata.mpeg7.Segment) Test(org.junit.Test)

Example 8 with JobBarrier

use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.

the class VideoSegmenterTest method testAnalyzeOptimizedList.

@Test
public void testAnalyzeOptimizedList() throws Exception {
    Job receipt = vsegmenter.segment(track);
    JobBarrier jobBarrier = new JobBarrier(null, serviceRegistry, 1000, receipt);
    jobBarrier.waitForJobs();
    Catalog catalog = (Catalog) MediaPackageElementParser.getFromXml(receipt.getPayload());
    Mpeg7Catalog mpeg7 = new Mpeg7CatalogImpl(catalog.getURI().toURL().openStream());
    List<OptimizationStep> optimizedList = new LinkedList<OptimizationStep>();
    OptimizationStep firstStep = new OptimizationStep(10, 0.015f, 46, 41, mpeg7, null);
    OptimizationStep secondStep = new OptimizationStep(10, 0.167f, 34, 41, mpeg7, null);
    OptimizationStep thirdStep = new OptimizationStep(10, 0.011f, 44, 41, mpeg7, null);
    OptimizationStep fourthStep = new OptimizationStep(10, 0.200f, 23, 41, mpeg7, null);
    // ~  0.122
    float error1 = (46 - 41) / (float) 41;
    // ~ -0.171
    float error2 = (34 - 41) / (float) 41;
    // ~  0.073
    float error3 = (44 - 41) / (float) 41;
    // ~ -0.439
    float error4 = (23 - 41) / (float) 41;
    optimizedList.add(firstStep);
    optimizedList.add(secondStep);
    optimizedList.add(thirdStep);
    optimizedList.add(fourthStep);
    Collections.sort(optimizedList);
    // check if the errors were calculated correctly and  whether the elements are in the correct order
    assertEquals("first element of optimized list incorrect", error3, optimizedList.get(0).getError(), 0.0001f);
    assertEquals("second element of optimized list incorrect", error1, optimizedList.get(1).getError(), 0.0001f);
    assertEquals("third element of optimized list incorrect", error4, optimizedList.get(2).getError(), 0.0001f);
    assertEquals("fourth element of optimized list incorrect", error2, optimizedList.get(3).getError(), 0.0001f);
    assertTrue("first error in optimized list is not positive", optimizedList.get(0).getError() >= 0);
    assertTrue("second error in optimized list is not bigger than first", optimizedList.get(1).getError() > optimizedList.get(0).getError());
    assertTrue("third error in optimized list is not negative", optimizedList.get(2).getError() < 0);
    assertTrue("fourth error in optimized list is smaller than third", optimizedList.get(3).getError() > optimizedList.get(2).getError());
}
Also used : Mpeg7Catalog(org.opencastproject.metadata.mpeg7.Mpeg7Catalog) Mpeg7CatalogImpl(org.opencastproject.metadata.mpeg7.Mpeg7CatalogImpl) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) Catalog(org.opencastproject.mediapackage.Catalog) Mpeg7Catalog(org.opencastproject.metadata.mpeg7.Mpeg7Catalog) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 9 with JobBarrier

use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.

the class StreamingDistributionServiceTest method testDistribution.

@Test
public void testDistribution() throws Exception {
    // Distribute the mediapackage and all of its elements
    Job job1 = service.distribute("engage-player", mp, "track-1");
    Job job2 = service.distribute("oai-pmh", mp, "track-1");
    JobBarrier jobBarrier = new JobBarrier(null, serviceRegistry, 500, job1, job2);
    jobBarrier.waitForJobs();
    // Add the new elements to the mediapackage
    mp.add(MediaPackageElementParser.getFromXml(job1.getPayload()));
    mp.add(MediaPackageElementParser.getFromXml(job2.getPayload()));
    File mpDir = new File(distributionRoot, PathSupport.path(defaultOrganization.getId(), "engage-player", mp.getIdentifier().compact()));
    File mediaDir = new File(mpDir, "track-1");
    Assert.assertTrue(mediaDir.exists());
    // the filenames are changed to reflect the element ID
    Assert.assertTrue(new File(mediaDir, "media.mov").exists());
}
Also used : Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) File(java.io.File) Test(org.junit.Test)

Example 10 with JobBarrier

use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.

the class ServiceRegistryJpaImplTest method testHostAddedToPriorityListExceptWorkflowType.

@Test
public void testHostAddedToPriorityListExceptWorkflowType() throws Exception {
    if (serviceRegistryJpaImpl.scheduledExecutor != null)
        serviceRegistryJpaImpl.scheduledExecutor.shutdown();
    serviceRegistryJpaImpl.scheduledExecutor = Executors.newScheduledThreadPool(1);
    serviceRegistryJpaImpl.activate(null);
    Hashtable<String, String> properties = new Hashtable<>();
    properties.put("dispatchinterval", "1000");
    serviceRegistryJpaImpl.updated(properties);
    registerTestHostAndService();
    serviceRegistryJpaImpl.registerService(TEST_SERVICE_3, TEST_HOST, TEST_PATH_3);
    Job testJob = serviceRegistryJpaImpl.createJob(TEST_HOST, TEST_SERVICE_3, TEST_OPERATION, null, null, true, null);
    JobBarrier barrier = new JobBarrier(null, serviceRegistryJpaImpl, testJob);
    try {
        barrier.waitForJobs(2000);
        Assert.fail();
    } catch (Exception e) {
        Assert.assertEquals(0, serviceRegistryJpaImpl.dispatchPriorityList.size());
    }
}
Also used : Hashtable(java.util.Hashtable) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) PropertyVetoException(java.beans.PropertyVetoException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) NotFoundException(org.opencastproject.util.NotFoundException) TrustedHttpClientException(org.opencastproject.security.api.TrustedHttpClientException) Test(org.junit.Test)

Aggregations

Job (org.opencastproject.job.api.Job)30 JobBarrier (org.opencastproject.job.api.JobBarrier)30 Test (org.junit.Test)24 MediaPackage (org.opencastproject.mediapackage.MediaPackage)11 SearchQuery (org.opencastproject.search.api.SearchQuery)10 NotFoundException (org.opencastproject.util.NotFoundException)7 Catalog (org.opencastproject.mediapackage.Catalog)6 SearchResult (org.opencastproject.search.api.SearchResult)6 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)6 PropertyVetoException (java.beans.PropertyVetoException)5 File (java.io.File)5 Hashtable (java.util.Hashtable)5 AccessControlEntry (org.opencastproject.security.api.AccessControlEntry)5 TrustedHttpClientException (org.opencastproject.security.api.TrustedHttpClientException)5 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)5 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 MediaInspectionException (org.opencastproject.inspection.api.MediaInspectionException)3 Result (org.opencastproject.job.api.JobBarrier.Result)3 AudioStream (org.opencastproject.mediapackage.AudioStream)3