}
RootFolder root = parent.getRoot(RemoteUtil.userName(t), t);
if (root == null) {
throw new IOException("Unknown root");
}
Headers h = t.getRequestHeaders();
for(String h1: h.keySet()) {
LOGGER.debug("key "+h1+"="+h.get(h1));
}
String id = RemoteUtil.getId(path, t);
id = RemoteUtil.strip(id);
RendererConfiguration r = render;
if (render == null) {
r = root.getDefaultRenderer();
}
List<DLNAResource> res = root.getDLNAResources(id, false, 0, 0, r);
if (res.size() != 1) {
// another error
LOGGER.debug("media unkonwn");
throw new IOException("Bad id");
}
long len = res.get(0).length();
Range range = RemoteUtil.parseRange(t.getRequestHeaders(), len);
String mime = root.getDefaultRenderer().getMimeType(res.get(0).mimeType());
DLNAResource dlna = res.get(0);
DLNAMediaInfo m = dlna.getMedia();
if(mime.equals(FormatConfiguration.MIMETYPE_AUTO) && m != null && m.getMimeType() != null) {
mime = m.getMimeType();
}
if (dlna.getFormat().isVideo()) {
if (flash) {
mime = "video/flash";
dlna.setPlayer(new WebPlayer(WebPlayer.FLASH));
} else if (!RemoteUtil.directmime(mime)) {
mime = RemoteUtil.MIME_TRANS;
dlna.setPlayer(new WebPlayer(WebPlayer.TRANS));
}
else {
dlna.setPlayer(null);
}
}
LOGGER.debug("dumping media " + mime + " " + res);
InputStream in = dlna.getInputStream(range, root.getDefaultRenderer());
Headers hdr = t.getResponseHeaders();
hdr.add("Content-Type", mime);
hdr.add("Accept-Ranges", "bytes");
hdr.add("Server", PMS.get().getServerName());
hdr.add("Connection", "keep-alive");
t.sendResponseHeaders(200, 0);
OutputStream os = t.getResponseBody();
StartStopListenerDelegate startStop = new StartStopListenerDelegate(t.getRemoteAddress().getHostString());
PMS.get().getFrame().setStatusLine("Serving " + dlna.getName());
startStop.start(dlna);