diff options
author | sr55 <[email protected]> | 2020-02-07 20:04:34 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2020-02-07 20:04:34 +0000 |
commit | b436ec04facbb390431738d37856e887fd2155e8 (patch) | |
tree | b9c0673db490aba2374a3b758531c1fe1ddfe3e8 | |
parent | 4b2b5c36bae5c88e8106c5df5283717d11c46e90 (diff) |
WinGui: AutoPassthru is now implemented using libhb using hb_autopassthru_get_encoder. This should solve a number of issues around selection. Fixes #2627 and #2611
6 files changed, 96 insertions, 9 deletions
diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs index d728809e3..83390faa0 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs @@ -211,6 +211,13 @@ namespace HandBrake.Interop.Interop return AudioEncoders.SingleOrDefault(e => e.Id == codecId); } + public static HBAudioEncoder GetAutoPassthruEncoder(int inputCodec, int copyMask, int fallback, int muxer) + { + int encoder = HBFunctions.hb_autopassthru_get_encoder(inputCodec, copyMask, fallback, muxer); + + return GetAudioEncoder(encoder); + } + /// <summary> /// Gets the video encoder with the specified short name. /// </summary> @@ -659,5 +666,52 @@ namespace HandBrake.Interop.Interop { return hbFunctions.hb_audio_compression_get_default((uint)encoder.Id); } + + public static uint BuildCopyMask(bool audioAllowMP3Pass, bool audioAllowAACPass, bool audioAllowAC3Pass, bool audioAllowDTSPass, bool audioAllowDTSHDPass, bool audioAllowEac3Pass, bool audioAllowFlacPass, bool audioAllowTruehdPass) + { + uint mask = 0; + + if (audioAllowMP3Pass) + { + mask |= NativeConstants.HB_ACODEC_MP3_PASS; + } + + if (audioAllowAACPass) + { + mask |= NativeConstants.HB_ACODEC_AAC_PASS; + } + + if (audioAllowAC3Pass) + { + mask |= NativeConstants.HB_ACODEC_AC3_PASS; + } + + if (audioAllowDTSPass) + { + mask |= NativeConstants.HB_ACODEC_DCA_PASS; + } + + if (audioAllowDTSHDPass) + { + mask |= NativeConstants.HB_ACODEC_DCA_HD_PASS; + } + + if (audioAllowEac3Pass) + { + mask |= NativeConstants.HB_ACODEC_EAC3_PASS; + } + + if (audioAllowFlacPass) + { + mask |= NativeConstants.HB_ACODEC_FLAC_PASS; + } + + if (audioAllowTruehdPass) + { + mask |= NativeConstants.HB_ACODEC_TRUEHD_PASS; + } + + return mask; + } } } diff --git a/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs b/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs index 26dfd3d8d..742f63aea 100644 --- a/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs +++ b/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs @@ -162,6 +162,9 @@ namespace HandBrake.Interop.Interop.HbLib [DllImport("hb", EntryPoint = "hb_audio_can_apply_drc2", CallingConvention = CallingConvention.Cdecl)] public static extern int hb_audio_can_apply_drc2(IntPtr handle, int title_index, int audio_index, int encoder); + [DllImport("hb", EntryPoint = "hb_autopassthru_get_encoder", CallingConvention = CallingConvention.Cdecl)] + public static extern int hb_autopassthru_get_encoder(int in_codec, int copy_mask, int fallback, int muxer); + [DllImport("hb", EntryPoint = "hb_mixdown_is_supported", CallingConvention = CallingConvention.Cdecl)] public static extern int hb_mixdown_is_supported(int mixdown, uint codec, ulong layout); diff --git a/win/CS/HandBrake.Interop/Interop/HbLib/NativeConstants.cs b/win/CS/HandBrake.Interop/Interop/HbLib/NativeConstants.cs index 3e0e7f012..b0e5d876d 100644 --- a/win/CS/HandBrake.Interop/Interop/HbLib/NativeConstants.cs +++ b/win/CS/HandBrake.Interop/Interop/HbLib/NativeConstants.cs @@ -24,6 +24,18 @@ namespace HandBrake.Interop.Interop.HbLib public const uint HB_ACODEC_PASS_FLAG = 0x40000000; public const uint HB_ACODEC_PASS_MASK = (HB_ACODEC_AC3 | HB_ACODEC_DCA | HB_ACODEC_DCA_HD | HB_ACODEC_FFAAC | HB_ACODEC_FFEAC3 | HB_ACODEC_FFFLAC | HB_ACODEC_MP3 | HB_ACODEC_FFTRUEHD); + public const uint HB_ACODEC_MASK = 0x07FFFF01; + public const uint HB_ACODEC_AUTO_PASS = (HB_ACODEC_PASS_FLAG | HB_ACODEC_PASS_MASK); + public const uint HB_ACODEC_ANY = (HB_ACODEC_PASS_FLAG | HB_ACODEC_MASK); + public const uint HB_ACODEC_AAC_PASS = (HB_ACODEC_PASS_FLAG | HB_ACODEC_FFAAC); + public const uint HB_ACODEC_AC3_PASS = (HB_ACODEC_PASS_FLAG | HB_ACODEC_AC3); + public const uint HB_ACODEC_DCA_PASS = (HB_ACODEC_PASS_FLAG | HB_ACODEC_DCA); + public const uint HB_ACODEC_DCA_HD_PASS = (HB_ACODEC_PASS_FLAG | HB_ACODEC_DCA_HD); + public const uint HB_ACODEC_EAC3_PASS = (HB_ACODEC_PASS_FLAG | HB_ACODEC_FFEAC3); + public const uint HB_ACODEC_FLAC_PASS = (HB_ACODEC_PASS_FLAG | HB_ACODEC_FFFLAC); + public const uint HB_ACODEC_MP3_PASS = (HB_ACODEC_PASS_FLAG | HB_ACODEC_MP3); + public const uint HB_ACODEC_TRUEHD_PASS = (HB_ACODEC_PASS_FLAG | HB_ACODEC_FFTRUEHD); + // VideoEncoders public const uint HB_VCODEC_QSV_H264 = 0x0000100; public const uint HB_VCODEC_QSV_H265 = 0x0000200; diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs index 458d60ece..a5111ce6c 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs @@ -123,18 +123,36 @@ namespace HandBrakeWPF.Services.Encode.Model.Models /// <param name="fallback"> /// An encoder to fall back to. /// </param> - public AudioTrack(AudioBehaviourTrack track, Audio sourceTrack, AudioEncoder fallback) + public AudioTrack(AudioBehaviourTrack track, Audio sourceTrack, AllowedPassthru fallback, OutputFormat container) { AudioEncoder chosenEncoder = track.Encoder; HBAudioEncoder encoderInfo = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper<AudioEncoder>.GetShortName(track.Encoder)); if (track.IsPassthru && (sourceTrack.Codec & encoderInfo.Id) == 0) { - chosenEncoder = fallback; + chosenEncoder = fallback.AudioEncoderFallback; } if (track.IsPassthru && chosenEncoder == AudioEncoder.Passthrough) { - chosenEncoder = fallback; + HBAudioEncoder fallbackEncoderInfo = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper<AudioEncoder>.GetShortName(fallback.AudioEncoderFallback)); + + if (fallbackEncoderInfo != null) + { + int format = HandBrakeEncoderHelpers.GetContainer(EnumHelper<OutputFormat>.GetShortName(container)).Id; + int copyMask = checked((int)HandBrakeEncoderHelpers.BuildCopyMask( + fallback.AudioAllowMP3Pass, + fallback.AudioAllowAACPass, + fallback.AudioAllowAC3Pass, + fallback.AudioAllowDTSPass, + fallback.AudioAllowDTSHDPass, + fallback.AudioAllowEAC3Pass, + fallback.AudioAllowFlacPass, + fallback.AudioAllowTrueHDPass)); + + HBAudioEncoder autoPassthruEncoderOption = HandBrakeEncoderHelpers.GetAutoPassthruEncoder(sourceTrack.Codec, copyMask, fallbackEncoderInfo.Id, format); + AudioEncoder autoPassthru = EnumHelper<AudioEncoder>.GetValue(autoPassthruEncoderOption.ShortName); + chosenEncoder = autoPassthru; + } } encoderInfo = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper<AudioEncoder>.GetShortName(chosenEncoder)); diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/OutputFormat.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/OutputFormat.cs index e9eb3c53a..5ee20aed6 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/OutputFormat.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/OutputFormat.cs @@ -17,15 +17,15 @@ namespace HandBrakeWPF.Services.Encode.Model.Models public enum OutputFormat { [DisplayName("MP4")] - [ShortName("mp4")] + [ShortName("av_mp4")] Mp4 = 0, [DisplayName("MKV")] - [ShortName("mkv")] + [ShortName("av_mkv")] Mkv, [DisplayName("WebM")] - [ShortName("webm")] + [ShortName("av_webm")] WebM } } diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs index cdf494c69..37d9e8ee9 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs @@ -437,7 +437,7 @@ namespace HandBrakeWPF.ViewModels AudioBehaviourTrack template = this.AudioBehaviours.BehaviourTracks.FirstOrDefault();
if (this.CanAddTrack(template, track, this.Task.AllowedPassthruOptions.AudioEncoderFallback))
{
- this.Task.AudioTracks.Add( template != null ? new AudioTrack(template, track, this.Task.AllowedPassthruOptions.AudioEncoderFallback) : new AudioTrack { ScannedTrack = track });
+ this.Task.AudioTracks.Add( template != null ? new AudioTrack(template, track, this.Task.AllowedPassthruOptions, this.Task.OutputFormat) : new AudioTrack { ScannedTrack = track });
}
break;
case AudioTrackDefaultsMode.AllTracks:
@@ -445,7 +445,7 @@ namespace HandBrakeWPF.ViewModels {
if (this.CanAddTrack(tmpl, track, this.Task.AllowedPassthruOptions.AudioEncoderFallback))
{
- this.Task.AudioTracks.Add(tmpl != null ? new AudioTrack(tmpl, track, this.Task.AllowedPassthruOptions.AudioEncoderFallback) : new AudioTrack { ScannedTrack = track });
+ this.Task.AudioTracks.Add(tmpl != null ? new AudioTrack(tmpl, track, this.Task.AllowedPassthruOptions, this.Task.OutputFormat) : new AudioTrack { ScannedTrack = track });
}
}
@@ -497,7 +497,7 @@ namespace HandBrakeWPF.ViewModels Audio sourceTrack = this.GetPreferredAudioTrack();
if (this.CanAddTrack(track, sourceTrack, this.Task.AllowedPassthruOptions.AudioEncoderFallback))
{
- this.Task.AudioTracks.Add(new AudioTrack(track, sourceTrack, this.Task.AllowedPassthruOptions.AudioEncoderFallback));
+ this.Task.AudioTracks.Add(new AudioTrack(track, sourceTrack, this.Task.AllowedPassthruOptions, this.Task.OutputFormat));
}
}
|