Added isRangeAllowed() function for transcoded sources

This isn't a perfect solution, but it should help increase confidence
that the transcoder in use is likely to produce an approximately
correct-sized stream.
master
Evan Harris 6 years ago
parent e691c80774
commit b28ffb0d1a
No known key found for this signature in database
GPG Key ID: FF3BD4DA59FF9EDC
  1. 6
      airsonic-main/src/main/java/org/airsonic/player/controller/StreamController.java
  2. 32
      airsonic-main/src/main/java/org/airsonic/player/service/TranscodingService.java

@ -159,13 +159,13 @@ public class StreamController {
// Wrangle response length and ranges. // Wrangle response length and ranges.
// //
// Support ranges as long as we're not transcoding; video is always assumed to transcode // Support ranges as long as we're not transcoding blindly; video is always assumed to transcode
if (file.isVideo()) { if (file.isVideo() || ! parameters.isRangeAllowed()) {
// Use chunked transfer; do not accept range requests // Use chunked transfer; do not accept range requests
response.setStatus(HttpServletResponse.SC_OK); response.setStatus(HttpServletResponse.SC_OK);
response.setHeader("Accept-Ranges", "none"); response.setHeader("Accept-Ranges", "none");
} else { } else {
// Not transcoding, partial content permitted because we know the final size // Partial content permitted because either know or expect to be able to predict the final size
long contentLength; long contentLength;
// If range was requested, respond in kind // If range was requested, respond in kind
range = getRange(request, file.getDurationSeconds(), fileLengthExpected); range = getRange(request, file.getDurationSeconds(), fileLengthExpected);

@ -216,6 +216,7 @@ public class TranscodingService {
} }
parameters.setMaxBitRate(maxBitRate); parameters.setMaxBitRate(maxBitRate);
parameters.setRangeAllowed(isRangeAllowed(parameters));
return parameters; return parameters;
} }
@ -487,6 +488,28 @@ public class TranscodingService {
return matches != null && matches.length > 0; return matches != null && matches.length > 0;
} }
private boolean isRangeAllowed(Parameters parameters) {
Transcoding transcoding = parameters.getTranscoding();
List<String> steps = Arrays.asList();
if (transcoding != null) {
steps = Arrays.asList(transcoding.getStep3(), transcoding.getStep2(), transcoding.getStep1());
}
else if (parameters.isDownsample()) {
steps = Arrays.asList(settingsService.getDownsamplingCommand());
}
else {
return true; // neither transcoding or downsampling
}
// Check if last configured step uses the bitrate, if so, range should be pretty safe
for (String step : steps) {
if (step != null) {
return step.contains("%b");
}
}
return false;
}
/** /**
* Returns the directory in which all transcoders are installed. * Returns the directory in which all transcoders are installed.
*/ */
@ -517,6 +540,7 @@ public class TranscodingService {
public static class Parameters { public static class Parameters {
private boolean downsample; private boolean downsample;
private boolean rangeAllowed;
private final MediaFile mediaFile; private final MediaFile mediaFile;
private final VideoTranscodingSettings videoTranscodingSettings; private final VideoTranscodingSettings videoTranscodingSettings;
private Integer maxBitRate; private Integer maxBitRate;
@ -543,6 +567,14 @@ public class TranscodingService {
return transcoding != null; return transcoding != null;
} }
public boolean isRangeAllowed() {
return this.rangeAllowed;
}
public void setRangeAllowed(boolean rangeAllowed) {
this.rangeAllowed = rangeAllowed;
}
public void setTranscoding(Transcoding transcoding) { public void setTranscoding(Transcoding transcoding) {
this.transcoding = transcoding; this.transcoding = transcoding;
} }

Loading…
Cancel
Save