Skip to content

Commit

Permalink
Improved subtitle control logic
Browse files Browse the repository at this point in the history
Makes use of the newly defined method, class, and renderer configuration
option to control the decisions of whether video/subtitles should be
streamed and/or transcoded.

The general logic is to prioritise streaming of both video and
subtitles. If video is not supported, then both video and subtitles will
be transcoded.

For external subtitles, it is possible to over-ride the
transcoding of subtitles (i.e. stream subtitles along with transcoded
video) through the renderer configuration. Embedded subtitles do not
offer this feature.
  • Loading branch information
StreamHD committed Jan 29, 2012
1 parent b9bc7c8 commit 26facab
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
27 changes: 19 additions & 8 deletions src/main/java/net/pms/dlna/DLNAResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,16 +540,20 @@ public void addChild(DLNAResource child) {
forceTranscode = child.getExt().skip(PMS.getConfiguration().getForceTranscode(), getDefaultRenderer() != null ? getDefaultRenderer().getTranscodedExtensions() : null);
}

boolean hasEmbeddedSubs = false;
if (child.getMedia() != null) {
for (DLNAMediaSubtitle s : child.getMedia().getSubtitlesCodes()) {
hasEmbeddedSubs |= s.getSubType().equals("Embedded");
}
}

boolean hasSubsToTranscode = false;
if (!PMS.getConfiguration().isMencoderDisableSubs()) {
hasSubsToTranscode = (PMS.getConfiguration().getUseSubtitles() && child.isSrtFile()) || hasEmbeddedSubs;
// Favour streaming over transcoding if there are subs that can be streamed.
if (PMS.getConfiguration().getUseSubtitles() && child.getMedia().getSubtitlesCodes().hasExternalSubsToHandle()
|| child.getMedia().getSubtitlesCodes().hasEmbeddedSubsToHandle()) {
hasSubsToTranscode = true;
}
if (child.getMedia().getSubtitlesCodes().hasStreamableEmbeddedSubs(getDefaultRenderer())) {
hasSubsToTranscode = false;
}
if (PMS.getConfiguration().getUseSubtitles() && child.getMedia().getSubtitlesCodes().hasStreamableExternalSubs(getDefaultRenderer())) {
hasSubsToTranscode = false;
child.setStreamExternalSubs(true);
}
}

boolean isIncompatible = false;
Expand All @@ -564,6 +568,13 @@ public void addChild(DLNAResource child) {
// or 3- FFmpeg support and the file is not ps3 compatible (need to remove this ?) and no SkipTranscode extension forced by user
// or 4- There's some sub files or embedded subs to deal with and no SkipTranscode extension forced by user
if (forceTranscode || !isSkipTranscode() && (forceTranscodeV2 || isIncompatible || hasSubsToTranscode)) {

if (PMS.getConfiguration().getUseSubtitles() && child.getMedia().getSubtitlesCodes().hasSkipTranscodeSubs(getDefaultRenderer())) {
child.setStreamExternalSubs(true);
} else {
child.setStreamExternalSubs(false);
}

child.setPlayer(pl);
LOGGER.trace("Switching " + child.getName() + " to player " + pl.toString() + " for transcoding");
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/pms/encoders/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import javax.swing.JComponent;

import net.pms.PMS;
import net.pms.configuration.PmsConfiguration;
import net.pms.configuration.RendererConfiguration;
import net.pms.dlna.DLNAMediaAudio;
Expand Down Expand Up @@ -185,6 +186,14 @@ public void setAudioAndSubs(String fileName, DLNAMediaInfo media, OutputParams p
currentLang = params.aid.getLang();
}

// The media contains external subtitles which should be streamed directly to the
// renderer. Do not transcode them.
if (PMS.getConfiguration().getUseSubtitles() && media != null && params.mediaRenderer != null && media.getSubtitlesCodes().hasSkipTranscodeSubs(params.mediaRenderer)) {
logger.trace("Stream subtitles to: " + params.mediaRenderer.getRendererName());
params.sid = null;
return;
}

if (params.sid != null && params.sid.getId() == -1) {
logger.trace("Don't want subtitles!");
params.sid = null;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/pms/network/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.pms.configuration.RendererConfiguration;
import net.pms.dlna.DLNAMediaInfo;
import net.pms.dlna.DLNAMediaSubtitle;
import net.pms.dlna.DLNAMediaSubtitleList;
import net.pms.dlna.DLNAResource;
import net.pms.dlna.Range;
import net.pms.external.StartStopListenerDelegate;
Expand Down Expand Up @@ -225,9 +226,9 @@ public void answer(OutputStream output, StartStopListenerDelegate startStopListe
// Some renderers (like Samsung devices) allow a custom header for a subtitle URL
String subtitleHttpHeader = mediaRenderer.getSubtitleHttpHeader();

if (subtitleHttpHeader != null && !"".equals(subtitleHttpHeader)) {
if (subtitleHttpHeader != null && !"".equals(subtitleHttpHeader) && dlna.StreamExternalSubs()) {
// Device allows a custom subtitle HTTP header; construct it
List<DLNAMediaSubtitle> subs = dlna.getMedia().getSubtitlesCodes();
DLNAMediaSubtitleList subs = dlna.getMedia().getSubtitlesCodes();

if (subs != null && !subs.isEmpty()) {
DLNAMediaSubtitle sub = subs.get(0);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/pms/network/RequestV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.pms.configuration.RendererConfiguration;
import net.pms.dlna.DLNAMediaInfo;
import net.pms.dlna.DLNAMediaSubtitle;
import net.pms.dlna.DLNAMediaSubtitleList;
import net.pms.dlna.DLNAResource;
import net.pms.dlna.Range;
import net.pms.external.StartStopListenerDelegate;
Expand Down Expand Up @@ -315,9 +316,9 @@ public ChannelFuture answer(
// Some renderers (like Samsung devices) allow a custom header for a subtitle URL
String subtitleHttpHeader = mediaRenderer.getSubtitleHttpHeader();

if (subtitleHttpHeader != null && !"".equals(subtitleHttpHeader)) {
if (subtitleHttpHeader != null && !"".equals(subtitleHttpHeader) && dlna.StreamExternalSubs()) {
// Device allows a custom subtitle HTTP header; construct it
List<DLNAMediaSubtitle> subs = dlna.getMedia().getSubtitlesCodes();
DLNAMediaSubtitleList subs = dlna.getMedia().getSubtitlesCodes();

if (subs != null && !subs.isEmpty()) {
DLNAMediaSubtitle sub = subs.get(0);
Expand Down

0 comments on commit 26facab

Please sign in to comment.