public void monitor() { final Device d = getDevice(uuid); monitor = new Thread( new Runnable() { @Override public void run() { String id = data.get("InstanceID"); while (active && !"STOPPED".equals(data.get("TransportState"))) { UPNPHelper.sleep(1000); // if (DEBUG) LOGGER.debug("InstanceID: " + id); for (ActionArgumentValue o : getPositionInfo(d, id)) { data.put(o.getArgument().getName(), o.toString()); // if (DEBUG) LOGGER.debug(o.getArgument().getName() + ": " + // o.toString()); } alert(); } if (!active) { data.put("TransportState", "STOPPED"); alert(); } } }, "UPNP-" + d.getDetails().getFriendlyName()); monitor.start(); }
public static boolean isNonRenderer(InetAddress socket) { Device d = getDevice(socket); boolean b = (d != null && !isMediaRenderer(d)); if (b) { LOGGER.debug("Device at {} is {}: {}", socket, d.getType(), d.toString()); } return b; }
protected synchronized boolean addRenderer(Device d) { if (d != null) { String uuid = getUUID(d); if (isMediaRenderer(d) && rendererFound(d, uuid) != null) { LOGGER.debug("Adding device: {} {}", d.getType(), d.toString()); rendererMap.mark(uuid, ACTIVE, true); subscribeAll(d, uuid); rendererReady(uuid); return true; } } return false; }
public static Map<String, String> getDeviceDetails(Device d) { if (d == null) { return null; } DeviceDetails dev = d.getDetails(); ManufacturerDetails man = dev.getManufacturerDetails(); ModelDetails model = dev.getModelDetails(); LinkedHashMap<String, String> details = new LinkedHashMap<>(); details.put("friendlyName", dev.getFriendlyName()); details.put("address", getURL(d).getHost()); details.put("udn", getUUID(d)); Object detail; if ((detail = man.getManufacturer()) != null) { details.put("manufacturer", (String) detail); } if ((detail = model.getModelName()) != null) { details.put("modelName", (String) detail); } if ((detail = model.getModelNumber()) != null) { details.put("modelNumber", (String) detail); } if ((detail = model.getModelDescription()) != null) { details.put("modelDescription", (String) detail); } if ((detail = man.getManufacturerURI()) != null) { details.put("manufacturerURL", detail.toString()); } if ((detail = model.getModelURI()) != null) { details.put("modelURL", detail.toString()); } return details; }
public static List<String> getServiceNames(Device d) { ArrayList<String> services = new ArrayList<>(); for (Service s : d.getServices()) { services.add(s.getServiceId().getId()); } return services; }
public static boolean isMediaRenderer(Device d) { String t = d.getType().getType(); for (DeviceType r : mediaRendererTypes) { if (r.getType().equals(t)) { return true; } } return false; }
protected void subscribeAll(Device d, String uuid) { String name = getFriendlyName(d); int ctrl = 0; for (Service s : d.getServices()) { String sid = s.getServiceId().getId(); LOGGER.debug("Subscribing to " + sid + " service on " + name); if (sid.contains("AVTransport")) { ctrl |= AVT; } else if (sid.contains("RenderingControl")) { ctrl |= RC; } upnpService.getControlPoint().execute(new SubscriptionCB(s)); } rendererMap.mark(uuid, RENEW, false); rendererMap.mark(uuid, CONTROLS, ctrl); }
// Convenience functions for sending various upnp service requests public static ActionInvocation send( final Device dev, String instanceID, String service, String action, String... args) { Service svc = dev.findService(ServiceId.valueOf("urn:upnp-org:serviceId:" + service)); final String uuid = getUUID(dev); if (svc != null) { Action x = svc.getAction(action); String name = getFriendlyName(dev); boolean log = !action.equals("GetPositionInfo"); if (x != null) { ActionInvocation a = new ActionInvocation(x); a.setInput("InstanceID", instanceID); for (int i = 0; i < args.length; i += 2) { a.setInput(args[i], args[i + 1]); } if (log) { LOGGER.debug("Sending upnp {}.{} {} to {}[{}]", service, action, args, name, instanceID); } new ActionCallback(a, upnpService.getControlPoint()) { @Override public void success(ActionInvocation invocation) { rendererMap.mark(uuid, ACTIVE, true); } @Override public void failure( ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { LOGGER.debug("Action failed: {}", defaultMsg); rendererMap.mark(uuid, ACTIVE, false); } }.run(); if (log) { for (ActionArgumentValue arg : a.getOutput()) { LOGGER.debug( "Received from {}[{}]: {}={}", name, instanceID, arg.getArgument().getName(), arg.toString()); } } return a; } } return null; }
public static String getDeviceIcon(Device d, int maxHeight) { URL base = getURL(d); Icon icon = null; String url = null; int maxH = maxHeight == 0 ? 99999 : maxHeight, height = 0; for (Icon i : d.getIcons()) { int h = i.getHeight(); if (h < maxH && h > height) { icon = i; height = h; } } try { url = icon != null ? new URL(base, icon.getUri().toString()).toString() : null; } catch (Exception e) { } LOGGER.debug("Device icon: " + url); return url; }
public static URL getURL(Device d) { return d instanceof RemoteDevice ? ((RemoteDevice) d).getIdentity().getDescriptorURL() : d.getDetails().getBaseURL(); }
public static String getUUID(Device d) { return d.getIdentity().getUdn().toString(); }
public static String getFriendlyName(Device d) { return d.getDetails().getFriendlyName(); }