Permalink
Browse files

Added subtitle HTTP header support for SamsungAllShare (thanks,

SamiMakinen!)
  • Loading branch information...
1 parent c53f249 commit ff77c71d5e8b58f46c1a351e17212f6a315edc8a @Raptor399 Raptor399 committed Dec 31, 2011
View
@@ -20,6 +20,7 @@ Changelog:
Added support for WDHD Live and AirAv app (thanks, ehM.Deee!)
Migrated PMS source to GitHub (https://github.com/ps3mediaserver/ps3mediaserver)
Added commit information
+ Added subtitle HTTP header support for SamsungAllShare (thanks, SamiMakinen!)
2011-11-20 - 1.50.0
@@ -223,6 +223,13 @@ ChunkedTransfer = false
# settings will be used.
CustomMencoderQualitySettings =
+# SubtitleHttpHeader: Some devices recognize a custom HTTP header for
+# retrieving the contents of a subtitles file. Set this option to the name of
+# that custom header and PMS will send the URL for the subtitles file in that
+# header (e.g. Samsung devices recognize the "CaptionInfo.sec" header).
+# Default value is "", which means PMS will not send such header information.
+SubtitleHttpHeader =
+
#-----------------------------------------------------------------------------
# IMAGES
#
@@ -43,3 +43,4 @@ MaxVideoHeight=0
MimeTypesChanges=audio/wav=audio/L16|video/x-matroska=video/avi|video/x-flv=video/mp4|audio/mp3=audio/L16|video/mp4=video/mpeg
TranscodeExtensions=flv,wav
StreamExtensions=mkv,mp3,mp4,avi,mov
+SubtitleHttpHeader=CaptionInfo.sec
@@ -249,6 +249,7 @@ public boolean isFDSSDP() {
private static final String SHOW_SUB_METADATA = "ShowSubMetadata";
private static final String DLNA_TREE_HACK = "CreateDLNATreeFaster";
private static final String CHUNKED_TRANSFER = "ChunkedTransfer";
+ private static final String SUBTITLE_HTTP_HEADER = "SubtitleHttpHeader";
// Sony devices require JPG thumbnails
private static final String FORCE_JPG_THUMBNAILS = "ForceJPGThumbnails";
@@ -728,6 +729,17 @@ public long getTranscodedSize() {
return getLong(TRANSCODED_SIZE, 0);
}
+ /**
+ * Some devices (e.g. Samsung) recognize a custom HTTP header for retrieving
+ * the contents of a subtitles file. This method will return the name of that
+ * custom HTTP header, or "" if no such header exists. Default value is "".
+ *
+ * @return The name of the custom HTTP header.
+ */
+ public String getSubtitleHttpHeader() {
+ return getString(SUBTITLE_HTTP_HEADER, "");
+ }
+
private int getInt(String key, int def) {
try {
return configuration.getInt(key, def);
@@ -31,6 +31,7 @@
import net.pms.PMS;
import net.pms.configuration.RendererConfiguration;
import net.pms.dlna.DLNAMediaInfo;
+import net.pms.dlna.DLNAMediaSubtitle;
import net.pms.dlna.DLNAResource;
import net.pms.dlna.Range;
import net.pms.external.StartStopListenerDelegate;
@@ -186,8 +187,12 @@ public void answer(OutputStream output, StartStopListenerDelegate startStopListe
output(output, "TransferMode.DLNA.ORG: " + transferMode);
}
if (files.size() == 1) {
+ // DNLAresource was found.
+ dlna = files.get(0);
String fileName = argument.substring(argument.lastIndexOf("/") + 1);
+
if (fileName.startsWith("thumbnail0000")) {
+ // This is a request for a thumbnail file.
output(output, "Content-Type: " + files.get(0).getThumbnailContentType());
output(output, "Accept-Ranges: bytes");
output(output, "Expires: " + getFUTUREDATE() + " GMT");
@@ -196,16 +201,50 @@ public void answer(OutputStream output, StartStopListenerDelegate startStopListe
files.get(0).checkThumbnail();
}
inputStream = files.get(0).getThumbnailInputStream();
+ } else if (fileName.indexOf("subtitle0000") > -1) {
+ // This is a request for a subtitle file
+ output(output, "Content-Type: text/plain");
+ output(output, "Expires: " + getFUTUREDATE() + " GMT");
+ List<DLNAMediaSubtitle> subs = dlna.getMedia().getSubtitlesCodes();
+
+ if (subs != null && !subs.isEmpty()) {
+ // TODO: maybe loop subs to get the requested subtitle type instead of using the first one
+ DLNAMediaSubtitle sub = subs.get(0);
+ inputStream = new java.io.FileInputStream(sub.getFile());
+ }
} else {
- dlna = files.get(0);
+ // This is a request for a regular file.
String name = dlna.getDisplayName(mediaRenderer);
inputStream = dlna.getInputStream(Range.create(lowRange, highRange, timeseek, timeRangeEnd), mediaRenderer);
if (inputStream == null) {
// No inputStream indicates that transcoding / remuxing probably crashed.
logger.error("There is no inputstream to return for " + name);
} else {
output(output, "Content-Type: " + getRendererMimeType(dlna.mimeType(), mediaRenderer));
- final DLNAMediaInfo media = dlna.getMedia();
+
+ // Some renderers (like Samsung devices) allow a custom header for a subtitle URL
+ String subtitleHttpHeader = mediaRenderer.getSubtitleHttpHeader();
+
+ if (subtitleHttpHeader != null && !"".equals(subtitleHttpHeader)) {
+ // Device allows a custom subtitle HTTP header; construct it
+ List<DLNAMediaSubtitle> subs = dlna.getMedia().getSubtitlesCodes();
+
+ if (subs != null && !subs.isEmpty()) {
+ DLNAMediaSubtitle sub = subs.get(0);
+
+ int type = sub.getType();
+
+ if (type < DLNAMediaSubtitle.subExtensions.length) {
+ String strType = DLNAMediaSubtitle.subExtensions[type - 1];
+ String subtitleUrl = "http://" + PMS.get().getServer().getHost()
+ + ':' + PMS.get().getServer().getPort() + "/get/"
+ + id + "/subtitle0000." + strType;
+ output(output, subtitleHttpHeader + ": " + subtitleUrl);
+ }
+ }
+ }
+
+ final DLNAMediaInfo media = dlna.getMedia();
if (media != null) {
if (StringUtils.isNotBlank(media.getContainer())) {
name += " [container: " + media.getContainer() + "]";
@@ -30,6 +30,7 @@
import net.pms.PMS;
import net.pms.configuration.RendererConfiguration;
import net.pms.dlna.DLNAMediaInfo;
+import net.pms.dlna.DLNAMediaSubtitle;
import net.pms.dlna.DLNAResource;
import net.pms.dlna.Range;
import net.pms.external.StartStopListenerDelegate;
@@ -271,7 +272,7 @@ public ChannelFuture answer(
String fileName = argument.substring(argument.lastIndexOf("/") + 1);
if (fileName.startsWith("thumbnail0000")) {
- // This a is request for a thumbnail file.
+ // This is a request for a thumbnail file.
output.setHeader(HttpHeaders.Names.CONTENT_TYPE, files.get(0).getThumbnailContentType());
output.setHeader(HttpHeaders.Names.ACCEPT_RANGES, "bytes");
output.setHeader(HttpHeaders.Names.EXPIRES, getFUTUREDATE() + " GMT");
@@ -282,6 +283,17 @@ public ChannelFuture answer(
}
inputStream = dlna.getThumbnailInputStream();
+ } else if (fileName.indexOf("subtitle0000") > -1) {
+ // This is a request for a subtitle file
+ output.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
+ output.setHeader(HttpHeaders.Names.EXPIRES, getFUTUREDATE() + " GMT");
+ List<DLNAMediaSubtitle> subs = dlna.getMedia().getSubtitlesCodes();
+
+ if (subs != null && !subs.isEmpty()) {
+ // TODO: maybe loop subs to get the requested subtitle type instead of using the first one
+ DLNAMediaSubtitle sub = subs.get(0);
+ inputStream = new java.io.FileInputStream(sub.getFile());
+ }
} else {
// This is a request for a regular file.
@@ -299,7 +311,30 @@ public ChannelFuture answer(
}
inputStream = dlna.getInputStream(Range.create(lowRange, highRange, range.getStart(), range.getEnd()), mediaRenderer);
- String name = dlna.getDisplayName(mediaRenderer);
+
+ // Some renderers (like Samsung devices) allow a custom header for a subtitle URL
+ String subtitleHttpHeader = mediaRenderer.getSubtitleHttpHeader();
+
+ if (subtitleHttpHeader != null && !"".equals(subtitleHttpHeader)) {
+ // Device allows a custom subtitle HTTP header; construct it
+ List<DLNAMediaSubtitle> subs = dlna.getMedia().getSubtitlesCodes();
+
+ if (subs != null && !subs.isEmpty()) {
+ DLNAMediaSubtitle sub = subs.get(0);
+
+ int type = sub.getType();
+
+ if (type < DLNAMediaSubtitle.subExtensions.length) {
+ String strType = DLNAMediaSubtitle.subExtensions[type - 1];
+ String subtitleUrl = "http://" + PMS.get().getServer().getHost()
+ + ':' + PMS.get().getServer().getPort() + "/get/"
+ + id + "/subtitle0000." + strType;
+ output.setHeader(subtitleHttpHeader, subtitleUrl);
+ }
+ }
+ }
+
+ String name = dlna.getDisplayName(mediaRenderer);
if (inputStream == null) {
// No inputStream indicates that transcoding / remuxing probably crashed.

2 comments on commit ff77c71

Contributor

SubJunk replied Jan 9, 2012

starts playing broken record
Space-indentation
Space-indentation
Space-indentation
Space-indentation
Space-indentation

Member

Raptor399 replied Jan 9, 2012

Blasted copy / paste code. :-(
Fixed in 287fc7a

Please sign in to comment.