}
MediaPipelineFactory mpf = session.getMediaPipelineFactory();
MediaPipeline mp = mpf.create();
session.releaseOnTerminate(mp);
PlayerEndpoint playerEndpoint = mp.newPlayerEndpoint(url).build();
HttpGetEndpoint httpEP = mp.newHttpGetEndpoint().terminateOnEOS()
.build();
if (contentId != null && contentId.equalsIgnoreCase("jack")) {
// Jack Vader Filter
JackVaderFilter filter = mp.newJackVaderFilter().build();
playerEndpoint.connect(filter);
filter.connect(httpEP);
} else if (contentId != null && contentId.equalsIgnoreCase("zbar")) {
// ZBar Filter
ZBarFilter zBarFilter = mp.newZBarFilter().build();
playerEndpoint.connect(zBarFilter);
zBarFilter.connect(httpEP);
session.setAttribute("eventValue", "");
zBarFilter
.addCodeFoundListener(new MediaEventListener<CodeFoundEvent>() {
@Override
public void onEvent(CodeFoundEvent event) {
log.info("Code Found " + event.getValue());
if (session.getAttribute("eventValue")
.toString().equals(event.getValue())) {
return;
}
session.setAttribute("eventValue",
event.getValue());
session.publishEvent(new ContentEvent(event
.getType(), event.getValue()));
}
});
}
else if (contentId != null && contentId.equalsIgnoreCase("crowd")) {
// Crowd Detector Filter
List<RelativePoint> points = new ArrayList<RelativePoint>();
points.add(new RelativePoint(0, 0));
points.add(new RelativePoint(1, 0));
points.add(new RelativePoint(1, 1));
points.add(new RelativePoint(0, 1));
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);
List<RegionOfInterest> rois = newArrayList(new RegionOfInterest(
points, config, "Roi"));
CrowdDetectorFilter crowdDetector = mp.newCrowdDetectorFilter(
rois).build();
playerEndpoint.connect(crowdDetector);
crowdDetector.connect(httpEP);
}
else if (contentId != null && contentId.equalsIgnoreCase("plate")) {
// Plate Detector Filter
PlateDetectorFilter plateDetectorFilter = mp
.newPlateDetectorFilter().build();
playerEndpoint.connect(plateDetectorFilter);
plateDetectorFilter.connect(httpEP);
session.setAttribute("plateValue", "");
plateDetectorFilter
.addPlateDetectedListener(new MediaEventListener<PlateDetectedEvent>() {
@Override
public void onEvent(PlateDetectedEvent event) {
if (session.getAttribute("plateValue")
.toString().equals(event.getPlate())) {
return;
}
session.setAttribute("plateValue",
event.getPlate());
session.publishEvent(new ContentEvent(event
.getType(), event.getPlate()));
}
});
}
else if (contentId != null && contentId.equalsIgnoreCase("pointer")) {
// Pointer Detector Filter
PointerDetectorFilter pointerDetectorFilter = mp
.newPointerDetectorFilter().build();
pointerDetectorFilter
.addWindow(new PointerDetectorWindowMediaParam("goal",
50, 50, 150, 150));
pointerDetectorFilter
.addWindowInListener(new MediaEventListener<WindowInEvent>() {
@Override
public void onEvent(WindowInEvent event) {
session.publishEvent(new ContentEvent(event
.getType(), event.getWindowId()));
}
});
playerEndpoint.connect(pointerDetectorFilter);
pointerDetectorFilter.connect(httpEP);
}
else {
// Player without filter
playerEndpoint.connect(httpEP);
}
session.start(httpEP);
session.setAttribute("player", playerEndpoint);
}