1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

check SupportsDirectStream

This commit is contained in:
Luke Pulverenti 2015-03-17 00:08:09 -04:00
parent 4794068650
commit e3091927f0

View file

@ -272,7 +272,7 @@
return supportsTextTracks; return supportsTextTracks;
}; };
self.canPlayVideoDirect = function (mediaSource, videoStream, audioStream, subtitleStream, maxWidth, bitrate) { self.getVideoDirectPlayMethod = function (mediaSource, videoStream, audioStream, subtitleStream, maxWidth, bitrate) {
if (!mediaSource) { if (!mediaSource) {
throw new Error('Null mediaSource'); throw new Error('Null mediaSource');
@ -280,34 +280,34 @@
if (!videoStream) { if (!videoStream) {
console.log('Cannot direct play without videoStream info'); console.log('Cannot direct play without videoStream info');
return false; return null;
} }
if (mediaSource.Protocol.toLowerCase() == "rtmp" || mediaSource.Protocol.toLowerCase() == "rtsp") { if (mediaSource.Protocol.toLowerCase() == "rtmp" || mediaSource.Protocol.toLowerCase() == "rtsp") {
//console.log('Transcoding because the content is not a video file'); //console.log('Transcoding because the content is not a video file');
return false; return null;
} }
if (mediaSource.VideoType && mediaSource.VideoType != "VideoFile") { if (mediaSource.VideoType && mediaSource.VideoType != "VideoFile") {
//console.log('Transcoding because the content is not a video file'); //console.log('Transcoding because the content is not a video file');
return false; return null;
} }
var isH264 = (videoStream.Codec || '').toLowerCase().indexOf('h264') != -1; var isH264 = (videoStream.Codec || '').toLowerCase().indexOf('h264') != -1;
if (!isH264) { if (!isH264) {
console.log('Transcoding because the content is not h264'); console.log('Transcoding because the content is not h264');
return false; return null;
} }
if (audioStream && !canPlayAudioStreamDirect(audioStream)) { if (audioStream && !canPlayAudioStreamDirect(audioStream)) {
console.log('Transcoding because the audio cannot be played directly.'); console.log('Transcoding because the audio cannot be played directly.');
return false; return null;
} }
if (subtitleStream && (!subtitleStream.SupportsExternalStream || !subtitleStream.IsTextSubtitleStream || !self.supportsTextTracks())) { if (subtitleStream && (!subtitleStream.SupportsExternalStream || !subtitleStream.IsTextSubtitleStream || !self.supportsTextTracks())) {
console.log('Transcoding because subtitles are required'); console.log('Transcoding because subtitles are required');
return false; return null;
} }
if (videoStream.IsCabac != null && !videoStream.IsCabac) { if (videoStream.IsCabac != null && !videoStream.IsCabac) {
@ -317,27 +317,27 @@
if (!videoStream.Width) { if (!videoStream.Width) {
console.log('Transcoding because resolution is unknown'); console.log('Transcoding because resolution is unknown');
return false; return null;
} }
if (videoStream.Width > maxWidth) { if (videoStream.Width > maxWidth) {
console.log('Transcoding because resolution is too high'); console.log('Transcoding because resolution is too high');
return false; return null;
} }
if (videoStream && videoStream.IsAnamorphic) { if (videoStream && videoStream.IsAnamorphic) {
console.log('Transcoding because video is anamorphic'); console.log('Transcoding because video is anamorphic');
return false; return null;
} }
if (!mediaSource.Bitrate) { if (!mediaSource.Bitrate) {
console.log('Transcoding because bitrate is unknown'); console.log('Transcoding because bitrate is unknown');
return false; return null;
} }
if (mediaSource.Bitrate > bitrate) { if (mediaSource.Bitrate > bitrate) {
console.log('Transcoding because bitrate is too high'); console.log('Transcoding because bitrate is too high');
return false; return null;
} }
var extension = (mediaSource.Container || '').toLowerCase(); var extension = (mediaSource.Container || '').toLowerCase();
@ -347,20 +347,27 @@
// only support high, baseline variants and main variants // only support high, baseline variants and main variants
if (isH264 && profile != 'high' && profile.indexOf('baseline') == -1 && profile.indexOf('main') == -1) { if (isH264 && profile != 'high' && profile.indexOf('baseline') == -1 && profile.indexOf('main') == -1) {
console.log('Transcoding because of unsupported h264 profile'); console.log('Transcoding because of unsupported h264 profile');
return false; return null;
} }
if (mediaSource.Protocol == 'Http') { if (mediaSource.Protocol == 'Http') {
if (Dashboard.isConnectMode()) { if (Dashboard.isConnectMode()) {
return false; return null;
} }
return 'DirectPlay';
}
if (extension == 'mp4') {
return 'DirectStream';
} }
if (extension == 'm4v' || extension == 'mkv') { if (extension == 'm4v' || extension == 'mkv') {
return $.browser.chrome != null; if ($.browser.chrome) {
return 'DirectStream';
}
} }
return extension == 'mp4'; return null;
}; };
self.getFinalVideoParams = function (mediaSource, maxWidth, bitrate, audioStreamIndex, subtitleStreamIndex, transcodingExtension) { self.getFinalVideoParams = function (mediaSource, maxWidth, bitrate, audioStreamIndex, subtitleStreamIndex, transcodingExtension) {
@ -379,14 +386,14 @@
return stream.Index === subtitleStreamIndex && stream.Type == 'Subtitle'; return stream.Index === subtitleStreamIndex && stream.Type == 'Subtitle';
})[0]; })[0];
var canPlayDirect = self.canPlayVideoDirect(mediaSource, videoStream, audioStream, subtitleStream, maxWidth, bitrate); var directPlayMethod = self.getVideoDirectPlayMethod(mediaSource, videoStream, audioStream, subtitleStream, maxWidth, bitrate);
var audioBitrate = bitrate >= 700000 ? 192000 : 64000; var audioBitrate = bitrate >= 700000 ? 192000 : 64000;
var videoBitrate = bitrate - audioBitrate; var videoBitrate = bitrate - audioBitrate;
var params = { var params = {
isStatic: canPlayDirect, isStatic: directPlayMethod != null,
maxWidth: maxWidth, maxWidth: maxWidth,
audioCodec: transcodingExtension == '.webm' ? 'vorbis' : 'aac', audioCodec: transcodingExtension == '.webm' ? 'vorbis' : 'aac',
videoCodec: transcodingExtension == '.webm' ? 'vpx' : 'h264', videoCodec: transcodingExtension == '.webm' ? 'vpx' : 'h264',
@ -542,14 +549,21 @@
return s.Type == 'Audio'; return s.Type == 'Audio';
})[0]; })[0];
return self.canPlayVideoDirect(v, videoStream, audioStream, null, maxAllowedWidth, bitrateSetting); var directPlayMethod = self.getVideoDirectPlayMethod(v, videoStream, audioStream, null, maxAllowedWidth, bitrateSetting);
if (directPlayMethod == 'DirectPlay') {
return true;
}
return v.SupportsDirectStream && directPlayMethod == 'DirectStream';
})[0]; })[0];
} else { } else {
optimalVersion = versions.filter(function (v) { optimalVersion = versions.filter(function (v) {
return canPlayAudioMediaSourceDirect(v); return v.SupportsDirectStream && canPlayAudioMediaSourceDirect(v);
})[0]; })[0];
} }