Browse Source

Return more precise transcoding reasons

Using the first profile's reason is somewhat arbitrary, as many clients' first profile may not be the most compatible one. For instance, browsers often set WebM as the first profile, which doesn’t support common codecs like H.264 and AAC by design. This causes `VideoCodecNotSupported` and `AudioCodecNotSupported` to be returned, even if the browser supports those codecs. Only use those reasons when all profiles indicate that the codec is not supported.

Signed-off-by: gnattu <gnattuoc@me.com>
gnattu 9 months ago
parent
commit
de8bb15c78
1 changed files with 37 additions and 4 deletions
  1. 37 4
      MediaBrowser.Model/Dlna/StreamBuilder.cs

+ 37 - 4
MediaBrowser.Model/Dlna/StreamBuilder.cs

@@ -1415,16 +1415,49 @@ namespace MediaBrowser.Model.Dlna
                 return profileMatch;
                 return profileMatch;
             }
             }
 
 
+            TranscodeReason inferredReason = 0;
+
             var failureReasons = analyzedProfiles[false]
             var failureReasons = analyzedProfiles[false]
                 .Select(analysis => analysis.Result)
                 .Select(analysis => analysis.Result)
                 .Where(result => !containerSupported || (result.TranscodeReason & TranscodeReason.ContainerNotSupported) == 0)
                 .Where(result => !containerSupported || (result.TranscodeReason & TranscodeReason.ContainerNotSupported) == 0)
-                .FirstOrDefault().TranscodeReason;
-            if (failureReasons == 0)
+                .Select(result => result.TranscodeReason)
+                .ToList();
+
+            if (failureReasons.FirstOrDefault() == 0)
+            {
+                inferredReason = TranscodeReason.DirectPlayError;
+            }
+            else
             {
             {
-                failureReasons = TranscodeReason.DirectPlayError;
+                var videoCodecNotSupportedCount = failureReasons.Count(r => (r & TranscodeReason.VideoCodecNotSupported) != 0);
+                var audioCodecNotSupportedCount = failureReasons.Count(r => (r & TranscodeReason.AudioCodecNotSupported) != 0);
+
+                if (!containerSupported)
+                {
+                    inferredReason |= TranscodeReason.ContainerNotSupported;
+                }
+
+                if (videoCodecNotSupportedCount == failureReasons.Count)
+                {
+                    inferredReason |= TranscodeReason.VideoCodecNotSupported;
+                }
+
+                if (audioCodecNotSupportedCount == failureReasons.Count)
+                {
+                    inferredReason |= TranscodeReason.AudioCodecNotSupported;
+                }
+
+                foreach (var transcodeReason in failureReasons)
+                {
+                    var temp = transcodeReason;
+                    temp &= ~TranscodeReason.ContainerNotSupported;
+                    temp &= ~TranscodeReason.VideoCodecNotSupported;
+                    temp &= ~TranscodeReason.AudioCodecNotSupported;
+                    inferredReason |= temp;
+                }
             }
             }
 
 
-            return (Profile: null, PlayMethod: null, AudioStreamIndex: null, TranscodeReasons: failureReasons);
+            return (Profile: null, PlayMethod: null, AudioStreamIndex: null, TranscodeReasons: inferredReason);
         }
         }
 
 
         private TranscodeReason CheckVideoAudioStreamDirectPlay(MediaOptions options, MediaSourceInfo mediaSource, string container, MediaStream audioStream)
         private TranscodeReason CheckVideoAudioStreamDirectPlay(MediaOptions options, MediaSourceInfo mediaSource, string container, MediaStream audioStream)