Skip to content

Commit

Permalink
Merge pull request #745 from GodTamIt/surround-audio
Browse files Browse the repository at this point in the history
Use `AudioContext` to test audio channels count
  • Loading branch information
nielsvanvelzen authored Jan 16, 2025
2 parents b8862e1 + 9121cba commit 881c568
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
17 changes: 7 additions & 10 deletions src/components/codecSupportHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ export function hasAC3Support(): boolean {
}

/**
* Checks if the device can play any surround codecs.
*
* Potentially, we could guess that systems with E-AC-3 or AC-3
* will mostly support 6ch pcm, and if any generation of cast devices
* is actually capable of decoding e.g. aac 6ch, we can return true here
* and give it a shot.
* @returns true if surround codecs can be played
* Checks for the number of audio channels supported on the device.
* @returns The maximum number of audio channels supported.
*/
export function hasSurroundSupport(): boolean {
// This will turn on surround support if passthrough is available.
return hasAC3Support();
export function getMaxAudioChannels(): number {
const audioCtx = new window.AudioContext();

// Make sure we allow at least 1 channel, in case of some bad output.
return Math.max(audioCtx.destination.maxChannelCount, 1);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/components/deviceprofileBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { ProfileConditionValue } from '@jellyfin/sdk/lib/generated-client/models
import { SubtitleDeliveryMethod } from '@jellyfin/sdk/lib/generated-client/models/subtitle-delivery-method';
import { DeviceIds, getActiveDeviceId } from './castDevices';
import {
hasSurroundSupport,
hasTextTrackSupport,
hasVP8Support,
hasVP9Support,
Expand All @@ -30,7 +29,8 @@ import {
getSupportedHLSVideoCodecs,
getSupportedHLSAudioCodecs,
getSupportedWebMAudioCodecs,
getSupportedAudioCodecs
getSupportedAudioCodecs,
getMaxAudioChannels
} from './codecSupportHelper';

interface ProfileOptions {
Expand Down Expand Up @@ -289,7 +289,7 @@ function getTranscodingProfiles(): TranscodingProfile[] {
const TranscodingProfiles: TranscodingProfile[] = [];

const hlsAudioCodecs = getSupportedHLSAudioCodecs();
const audioChannels: number = hasSurroundSupport() ? 6 : 2;
const audioChannels: number = getMaxAudioChannels();

if (profileOptions.enableHls) {
TranscodingProfiles.push({
Expand Down

0 comments on commit 881c568

Please sign in to comment.