From f9da2ea7534cc8603951d44ad8c4ce4497c5c851 Mon Sep 17 00:00:00 2001 From: randomengy Date: Wed, 11 Jun 2014 03:45:16 +0000 Subject: Interop: Fixed a bug that was causing crashes on AAC passthrough. We were clobbering the private data section with zeroes. Also added support for passing through a track if it's possible. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6210 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../HandBrakeInterop/HandBrakeInstance.cs | 29 +++++++++++++++++++--- .../HandBrakeInterop/HbLib/NativeConstants.cs | 2 +- .../HandBrakeInterop/Model/Encoders.cs | 13 +++++++++- .../Model/Encoding/AudioEncoding.cs | 5 ++++ .../Model/Encoding/HBAudioEncoder.cs | 6 ++--- .../HandBrakeInterop/Model/SourceSubtitle.cs | 2 +- .../HandBrakeInterop/Model/SrtSubtitle.cs | 18 ++++++-------- 7 files changed, 55 insertions(+), 20 deletions(-) (limited to 'win/CS') diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs index bfd0c44de..521f5912a 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs @@ -11,6 +11,7 @@ namespace HandBrake.Interop { using System; using System.Collections.Generic; + using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; @@ -1284,6 +1285,8 @@ namespace HandBrake.Interop nativeJob.maxWidth = profile.MaxWidth; nativeJob.maxHeight = profile.MaxHeight; + nativeJob.modulus = 2; + break; case Anamorphic.Strict: nativeJob.anamorphic.mode = 1; @@ -1421,7 +1424,10 @@ namespace HandBrake.Interop foreach (Tuple outputTrack in outputTrackList) { - audioList.Add(this.ConvertAudioBack(outputTrack.Item1, titleAudio[outputTrack.Item2 - 1], numTracks++, allocatedMemory)); + AudioEncoding encoding = outputTrack.Item1; + int trackNumber = outputTrack.Item2; + + audioList.Add(this.ConvertAudioBack(encoding, titleAudio[trackNumber - 1], numTracks++, allocatedMemory)); } NativeList nativeAudioList = InteropUtilities.ToHandBrakeListFromList(audioList); @@ -1483,6 +1489,7 @@ namespace HandBrake.Interop { var subtitleConfig = new hb_subtitle_config_s(); + subtitleConfig.dest = srtSubtitle.BurnedIn ? hb_subtitle_config_s_subdest.RENDERSUB : hb_subtitle_config_s_subdest.PASSTHRUSUB; subtitleConfig.src_codeset = srtSubtitle.CharacterCode; subtitleConfig.src_filename = srtSubtitle.FileName; subtitleConfig.offset = srtSubtitle.Offset; @@ -1766,13 +1773,24 @@ namespace HandBrake.Interop throw new InvalidOperationException("Could not find audio encoder " + encoding.Name); } + bool isPassthrough = encoder.IsPassthrough; + + uint outputCodec = (uint)encoder.Id; + if (encoding.PassthroughIfPossible && + encoder.Id == baseStruct.config.input.codec && + (encoder.Id & NativeConstants.HB_ACODEC_PASS_MASK) > 0) + { + outputCodec |= NativeConstants.HB_ACODEC_PASS_FLAG; + isPassthrough = true; + } + nativeAudio.config.output.track = outputTrack; - nativeAudio.config.output.codec = (uint)encoder.Id; + nativeAudio.config.output.codec = outputCodec; nativeAudio.config.output.compression_level = -1; nativeAudio.config.output.samplerate = nativeAudio.config.input.samplerate; nativeAudio.config.output.dither_method = -1; - if (!encoder.IsPassthrough) + if (!isPassthrough) { if (encoding.SampleRateRaw != 0) { @@ -1824,7 +1842,10 @@ namespace HandBrake.Interop allocatedMemory.Add(encodingNamePtr); } - nativeAudio.padding = new byte[MarshalingConstants.AudioPaddingBytes]; + if (nativeAudio.padding == null) + { + nativeAudio.padding = new byte[MarshalingConstants.AudioPaddingBytes]; + } return nativeAudio; } diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/NativeConstants.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/NativeConstants.cs index 45637e9a4..7e17a199b 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/NativeConstants.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/NativeConstants.cs @@ -29,7 +29,7 @@ namespace HandBrake.Interop.HbLib public const uint HB_ACODEC_FFFLAC24 = 0x00200000; public const uint HB_ACODEC_FDK_AAC = 0x00400000; public const uint HB_ACODEC_FDK_HAAC = 0x00800000; - public const uint HB_ACODEC_FF_MASK = 0x00FF2000; + public const uint HB_ACODEC_FF_MASK = 0x00FF2800; public const uint HB_ACODEC_PASS_FLAG = 0x40000000; public const uint HB_ACODEC_PASS_MASK = (HB_ACODEC_MP3 | HB_ACODEC_FFAAC | HB_ACODEC_DCA_HD | HB_ACODEC_AC3 | HB_ACODEC_DCA); public const uint HB_ACODEC_AUTO_PASS = (HB_ACODEC_PASS_MASK | HB_ACODEC_PASS_FLAG); diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs index ecf1b775a..f27fad285 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs @@ -177,7 +177,18 @@ namespace HandBrake.Interop.Model return containers; } - } + } + + /// + /// Gets a value indicating whether SRT subtitles can be burnt in. + /// + public static bool CanBurnSrt + { + get + { + return HBFunctions.hb_subtitle_can_burn((int)hb_subtitle_s_subsource.SRTSUB) > 0; + } + } /// /// Gets the audio encoder with the specified short name. diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/AudioEncoding.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/AudioEncoding.cs index c6ac28ea5..7aa211c8d 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/AudioEncoding.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/AudioEncoding.cs @@ -36,6 +36,11 @@ namespace HandBrake.Interop.Model.Encoding /// public string Encoder { get; set; } + /// + /// Will pass through the track if it maches the codec type. + /// + public bool PassthroughIfPossible { get; set; } + /// /// Gets or sets the encode rate type (bitrate or quality). /// diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBAudioEncoder.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBAudioEncoder.cs index 478e309a6..6bcd8e0d7 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBAudioEncoder.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBAudioEncoder.cs @@ -49,7 +49,7 @@ namespace HandBrake.Interop.Model.Encoding public int Id { get; set; } /// - /// Gets a value indicating whether is passthrough. + /// Gets a value indicating whether the encoder is passthrough. /// public bool IsPassthrough { @@ -70,7 +70,7 @@ namespace HandBrake.Interop.Model.Encoding public string ShortName { get; set; } /// - /// Gets a value indicating whether supports compression. + /// Gets a value indicating whether the encoder supports compression. /// public bool SupportsCompression { @@ -81,7 +81,7 @@ namespace HandBrake.Interop.Model.Encoding } /// - /// Gets a value indicating whether supports quality. + /// Gets a value indicating whether the encoder supports quality. /// public bool SupportsQuality { diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/SourceSubtitle.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/SourceSubtitle.cs index 2912dec1e..e4bb3c39e 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/SourceSubtitle.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/SourceSubtitle.cs @@ -17,7 +17,7 @@ namespace HandBrake.Interop.Model #region Properties /// - /// Gets or sets a value indicating whether burned in. + /// Gets or sets a value indicating whether the subtitle track should be burned in. /// public bool BurnedIn { get; set; } diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/SrtSubtitle.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/SrtSubtitle.cs index 46cc45f57..9a60c8ab3 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/SrtSubtitle.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/SrtSubtitle.cs @@ -14,18 +14,21 @@ namespace HandBrake.Interop.Model /// public class SrtSubtitle { - #region Properties - /// /// Gets or sets the character code. /// public string CharacterCode { get; set; } /// - /// Gets or sets a value indicating whether default. + /// Gets or sets a value indicating whether the subtitle track should be marked as default. /// public bool Default { get; set; } + /// + /// Gets or sets a value indicating the subtitle track should be burned in. + /// + public bool BurnedIn { get; set; } + /// /// Gets or sets the file name. /// @@ -41,10 +44,6 @@ namespace HandBrake.Interop.Model /// public int Offset { get; set; } - #endregion - - #region Public Methods - /// /// The clone. /// @@ -55,14 +54,13 @@ namespace HandBrake.Interop.Model { return new SrtSubtitle { - Default = this.Default, + Default = this.Default, + BurnedIn = this.BurnedIn, FileName = this.FileName, LanguageCode = this.LanguageCode, CharacterCode = this.CharacterCode, Offset = this.Offset }; } - - #endregion } } \ No newline at end of file -- cgit v1.2.3