Skip to content

Commit

Permalink
fix secondary audio
Browse files Browse the repository at this point in the history
Browsers (Chrome, Firefox) can only play the first track,
even if the second track is the default.

Ignore default flag when testing on secondary audio.

External audio tracks are not secondary.
  • Loading branch information
dmitrylyzo authored and dannymichel committed Nov 2, 2022
1 parent 4d892f1 commit 1716a6c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
9 changes: 3 additions & 6 deletions MediaBrowser.Model/Dlna/StreamBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,9 +1085,6 @@ private static int GetMaxAudioBitrateForTotalBitrate(long totalBitrate)
bool? isInterlaced = videoStream?.IsInterlaced;
string videoCodecTag = videoStream?.CodecTag;
bool? isAvc = videoStream?.IsAVC;
// Audio
var defaultLanguage = audioStream?.Language ?? string.Empty;
var defaultMarked = audioStream?.IsDefault ?? false;

TransportStreamTimestamp? timestamp = videoStream == null ? TransportStreamTimestamp.None : mediaSource.Timestamp;
int? packetLength = videoStream?.PacketLength;
Expand Down Expand Up @@ -1119,7 +1116,7 @@ private static int GetMaxAudioBitrateForTotalBitrate(long totalBitrate)
.SelectMany(codecProfile => checkVideoConditions(codecProfile.Conditions)));

// Check audiocandidates profile conditions
var audioStreamMatches = candidateAudioStreams.ToDictionary(s => s, audioStream => CheckVideoAudioStreamDirectPlay(options, mediaSource, container, audioStream, defaultLanguage, defaultMarked));
var audioStreamMatches = candidateAudioStreams.ToDictionary(s => s, audioStream => CheckVideoAudioStreamDirectPlay(options, mediaSource, container, audioStream));

TranscodeReason subtitleProfileReasons = 0;
if (subtitleStream != null)
Expand Down Expand Up @@ -1240,10 +1237,10 @@ private static int GetMaxAudioBitrateForTotalBitrate(long totalBitrate)
return (Profile: null, PlayMethod: null, AudioStreamIndex: null, TranscodeReasons: failureReasons);
}

private TranscodeReason CheckVideoAudioStreamDirectPlay(VideoOptions options, MediaSourceInfo mediaSource, string container, MediaStream audioStream, string language, bool isDefault)
private TranscodeReason CheckVideoAudioStreamDirectPlay(VideoOptions options, MediaSourceInfo mediaSource, string container, MediaStream audioStream)
{
var profile = options.Profile;
var audioFailureConditions = GetProfileConditionsForVideoAudio(profile.CodecProfiles, container, audioStream.Codec, audioStream.Channels, audioStream.BitRate, audioStream.SampleRate, audioStream.BitDepth, audioStream.Profile, !audioStream.IsDefault);
var audioFailureConditions = GetProfileConditionsForVideoAudio(profile.CodecProfiles, container, audioStream.Codec, audioStream.Channels, audioStream.BitRate, audioStream.SampleRate, audioStream.BitDepth, audioStream.Profile, mediaSource.IsSecondaryAudio(audioStream));

var audioStreamFailureReasons = AggregateFailureConditions(mediaSource, profile, "VideoAudioCodecProfile", audioFailureConditions);
if (audioStream?.IsExternal == true)
Expand Down
10 changes: 3 additions & 7 deletions MediaBrowser.Model/Dto/MediaSourceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,15 @@ public MediaStream GetMediaStream(MediaStreamType type, int index)

public bool? IsSecondaryAudio(MediaStream stream)
{
// Look for the first audio track marked as default
foreach (var currentStream in MediaStreams)
if (stream.IsExternal)
{
if (currentStream.Type == MediaStreamType.Audio && currentStream.IsDefault)
{
return currentStream.Index != stream.Index;
}
return false;
}

// Look for the first audio track
foreach (var currentStream in MediaStreams)
{
if (currentStream.Type == MediaStreamType.Audio)
if (currentStream.Type == MediaStreamType.Audio && !currentStream.IsExternal)
{
return currentStream.Index != stream.Index;
}
Expand Down

0 comments on commit 1716a6c

Please sign in to comment.