public void testPlayerCrowdDetector() throws Exception {
// Media Pipeline
MediaPipeline mp = pipelineFactory.create();
PlayerEndpoint playerEP = mp.newPlayerEndpoint(
"http://files.kurento.org/video/crowd.mp4").build();
HttpGetEndpoint httpEP = mp.newHttpGetEndpoint().terminateOnEOS()
.build();
List<RegionOfInterest> rois = newArrayList();
List<RelativePoint> points = new ArrayList<RelativePoint>();
points.add(new RelativePoint(0, 0));
points.add(new RelativePoint((float) 0.5, 0));
points.add(new RelativePoint((float) 0.5, (float) 0.5));
points.add(new RelativePoint(0, (float) 0.5));
RegionOfInterestConfig config = new RegionOfInterestConfig();
config.setFluidityLevelMin(10);
config.setFluidityLevelMed(35);
config.setFluidityLevelMax(65);
config.setFluidityNumFramesToEvent(5);
config.setOccupancyLevelMin(10);
config.setOccupancyLevelMed(35);
config.setOccupancyLevelMax(65);
config.setOccupancyNumFramesToEvent(5);
config.setSendOpticalFlowEvent(false);
config.setOpticalFlowNumFramesToEvent(3);
config.setOpticalFlowNumFramesToReset(3);
config.setOpticalFlowAngleOffset(0);
rois.add(new RegionOfInterest(points, config, "roi0"));
CrowdDetectorFilter crowdDetectorFilter = mp.newCrowdDetectorFilter(
rois).build();
playerEP.connect(crowdDetectorFilter);
crowdDetectorFilter.connect(httpEP);
final List<EndOfStreamEvent> eosEvents = new ArrayList<>();
playerEP.addEndOfStreamListener(new MediaEventListener<EndOfStreamEvent>() {
@Override
public void onEvent(EndOfStreamEvent event) {
eosEvents.add(event);
}
});
final List<CrowdDetectorOccupancyEvent> crowdDetectedOccupancyEvents = new ArrayList<>();
final List<CrowdDetectorFluidityEvent> crowdDetectedFluidityEvents = new ArrayList<>();
crowdDetectorFilter
.addCrowdDetectorOccupancyListener(new MediaEventListener<CrowdDetectorOccupancyEvent>() {
@Override
public void onEvent(CrowdDetectorOccupancyEvent event) {
crowdDetectedOccupancyEvents.add(event);
}
});
crowdDetectorFilter
.addCrowdDetectorFluidityListener(new MediaEventListener<CrowdDetectorFluidityEvent>() {
@Override
public void onEvent(CrowdDetectorFluidityEvent event) {
crowdDetectedFluidityEvents.add(event);
}
});
// Test execution
try (BrowserClient browser = new BrowserClient.Builder()
.browser(Browser.CHROME).client(Client.PLAYER).build()) {
browser.setURL(httpEP.getUrl());
browser.subscribeEvents("playing", "ended");
playerEP.play();
browser.start();
// Assertions