Skip to content
Browse files

Update support for Genpix tuners.

- refactor the existing implementation, adding support for tone burst (simple DiSEqC) and raw DiSEqC commands (motor control)
- add full support for the official BDA driver, including raw DiSEqC, tone burst and custom tuning

Nothing is tested at this point.
  • Loading branch information...
1 parent 0a00344 commit 20137e170e752c5125dab4a7791bbf7eb09ded4f @mm1352000 mm1352000 committed Jan 6, 2012
View
40 TvEngine3/TVLibrary/TVLibrary/Implementations/DVB/ConditionalAccess/ConditionalAccess.cs
@@ -59,7 +59,8 @@ public class ConditionalAccess : IDisposable
private readonly GenericATSC _isgenericatsc;
private readonly ViXSATSC _isvixsatsc;
private readonly ConexantBDA _conexant;
- private readonly GenPixBDA _genpix;
+ private readonly Genpix _genpix;
+ private readonly GenpixOpenSource _genpixOpenSource;
private readonly TeVii _TeVii;
private readonly DigitalDevices _DigitalDevices;
@@ -264,21 +265,24 @@ public IHardwareProvider HWProvider
Release.DisposeToNull(ref _conexant);
Release.DisposeToNull(ref _winTvCiModule);
- Log.Log.WriteFile("Check for GenPix BDA based card");
- _genpix = new GenPixBDA(tunerFilter);
- if (_genpix.IsGenPix)
+ Log.Log.WriteFile("Check for Genpix with standard BDA driver");
+ _genpix = new Genpix(tunerFilter);
+ if (_genpix.IsGenpix)
{
- Log.Log.WriteFile("GenPix BDA card detected");
- Log.Log.WriteFile("Check for Hauppauge WinTV CI");
- if (winTvUsbCiFilter != null)
- {
- Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
- _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
- }
+ _HWProvider = _genpix;
+ _diSEqCMotor = new DiSEqCMotor(_genpix);
return;
}
Release.DisposeToNull(ref _genpix);
- Release.DisposeToNull(ref _winTvCiModule);
+
+ Log.Log.WriteFile("Check for Genpix with open source driver");
+ _genpixOpenSource = new GenpixOpenSource(tunerFilter);
+ if (_genpixOpenSource.IsGenpixOpenSource)
+ {
+ _diSEqCMotor = new DiSEqCMotor(_genpixOpenSource);
+ return;
+ }
+ Release.DisposeToNull(ref _genpixOpenSource);
Log.Log.WriteFile("Check for Generic DVB-S card");
_genericbdas = new GenericBDAS(tunerFilter);
@@ -750,7 +754,12 @@ public bool SendDiseqcCommand(ScanParameters parameters, DVBSChannel channel)
}
if (_genpix != null)
{
- _genpix.SendDiseqCommand(parameters, channel);
+ _genpix.SendDiseqcCommand(parameters, channel);
+ System.Threading.Thread.Sleep(100);
+ }
+ if (_genpixOpenSource != null)
+ {
+ _genpixOpenSource.SendDiseqcCommand(parameters, channel);
System.Threading.Thread.Sleep(100);
}
if (_TeVii != null)
@@ -846,6 +855,10 @@ public DVBSChannel SetDVBS2Modulation(ScanParameters parameters, DVBSChannel cha
//Log.Log.WriteFile("Trying to set DVB-S2 modulation...");
try
{
+ if (_genpix != null)
+ {
+ return (DVBSChannel)_genpix.SetTuningParameters(channel as DVBSChannel);
+ }
if (_twinhan != null)
{
//DVB-S2 modulation parameters for Twinhan
@@ -1106,6 +1119,7 @@ public void Dispose()
Release.Dispose(_isgenericatsc);
Release.Dispose(_isvixsatsc);
Release.Dispose(_genpix);
+ Release.Dispose(_genpixOpenSource);
Release.Dispose(_winTvCiModule);
Release.Dispose(_twinhan);
Release.Dispose(_profred);
View
197 TvEngine3/TVLibrary/TVLibrary/Implementations/DVB/DisEqC/GenPixBDA.cs
@@ -1,197 +0,0 @@
-#region Copyright (C) 2005-2011 Team MediaPortal
-
-// Copyright (C) 2005-2011 Team MediaPortal
-// http://www.team-mediaportal.com
-//
-// MediaPortal is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 2 of the License, or
-// (at your option) any later version.
-//
-// MediaPortal is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MediaPortal. If not, see <http://www.gnu.org/licenses/>.
-
-#endregion
-
-using System;
-using System.Runtime.InteropServices;
-using DirectShowLib;
-using DirectShowLib.BDA;
-using TvLibrary.Channels;
-
-namespace TvLibrary.Implementations.DVB
-{
- /// <summary>
- /// Handles the DiSEqC interface for GenPix BDA driver devices
- /// </summary>
- public class GenPixBDA : IDisposable
- {
- #region constants
-
- //Guid used to extend the feature of the BDA driver - {0B5221EB-F4C4-4976-B959-EF74427464D9}
- private readonly Guid BdaTunerExtentionProperties = new Guid(0x0B5221EB, 0xF4C4, 0x4976, 0xB9, 0x59, 0xEF, 0x74,
- 0x42, 0x74, 0x64, 0xD9);
-
- #endregion
-
- #region variables
-
- private readonly bool _isGenPix;
- private readonly IntPtr _ptrDiseqc = IntPtr.Zero;
- private readonly IntPtr _ptrTempInstance = IntPtr.Zero;
- private readonly IKsPropertySet _propertySet;
-
- #endregion
-
- #region enums
-
- private enum enSimpleToneBurst
- {
- SEC_MINI_A = 0x00,
- SEC_MINI_B = 0x01
- }
-
- #endregion
-
- #region structs
-
- /// <summary>
- /// Sets up the DiSEqC struct for GenPix DVB-S cards.
- /// </summary>
- [StructLayout(LayoutKind.Sequential), ComVisible(true)]
- private unsafe class DISEQC_COMMAND
- {
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public byte[] ucMessage;
- public byte ucMessageLength;
-
- public DISEQC_COMMAND()
- {
- ucMessage = new byte[6];
- }
- }
-
- #endregion
-
- /// <summary>
- /// Initializes a new instance of the <see cref="GenPixBDA"/> class.
- /// </summary>
- /// <param name="tunerFilter">The tuner filter.</param>
- public GenPixBDA(IBaseFilter tunerFilter)
- {
- //check the filter name
- FilterInfo tInfo;
- tunerFilter.QueryFilterInfo(out tInfo);
- Log.Log.Debug("GenPix tuner filter name: {0}", tInfo.achName);
- //check the pin name
- IPin pin = DsFindPin.ByDirection(tunerFilter, PinDirection.Output, 0);
- PinInfo pInfo;
- pin.QueryPinInfo(out pInfo);
- Log.Log.Debug("GenPix tuner filter pin name: {0}", pInfo.name);
- if (pin != null)
- {
- _propertySet = pin as IKsPropertySet;
- if (_propertySet != null)
- {
- KSPropertySupport supported;
- _propertySet.QuerySupported(BdaTunerExtentionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_DISEQC,
- out supported);
- if ((supported & KSPropertySupport.Set) != 0)
- {
- Log.Log.Debug("GenPix BDA: DVB-S card found!");
- _isGenPix = true;
- _ptrDiseqc = Marshal.AllocCoTaskMem(1024);
- _ptrTempInstance = Marshal.AllocCoTaskMem(1024);
- }
- else
- {
- Log.Log.Debug("GenPix BDA: DVB-S card NOT found!");
- _isGenPix = false;
- }
- }
- }
- else
- Log.Log.Info("GenPix BDA: tuner pin not found!");
- }
-
- /// <summary>
- /// Gets a value indicating whether this instance is a GenPix based card.
- /// </summary>
- /// <value>
- /// <c>true</c> if this instance is GenPix; otherwise, <c>false</c>.
- /// </value>
- public bool IsGenPix
- {
- get { return _isGenPix; }
- }
-
- /// <summary>
- /// Sends the diseq command.
- /// </summary>
- /// <param name="channel">The channel.</param>
- /// <param name="parameters">The channels scanning parameters.</param>
- public void SendDiseqCommand(ScanParameters parameters, DVBSChannel channel)
- {
- if (_isGenPix == false)
- return;
- Log.Log.Debug("SendDiseqc: {0},{1}", parameters.ToString(), channel.ToString());
-
- //bit 0 (1) : 0=low band, 1 = hi band
- //bit 1 (2) : 0=vertical, 1 = horizontal
- //bit 3 (4) : 0=satellite position A, 1=satellite position B
- //bit 4 (8) : 0=switch option A, 1=switch option B
- // LNB option position
- // 1 A A
- // 2 A B
- // 3 B A
- // 4 B B
- int antennaNr = BandTypeConverter.GetAntennaNr(channel);
- bool hiBand = BandTypeConverter.IsHiBand(channel, parameters);
- bool isHorizontal = ((channel.Polarisation == Polarisation.LinearH) ||
- (channel.Polarisation == Polarisation.CircularL));
- byte cmd = 0xf0;
- cmd |= (byte)(hiBand ? 1 : 0);
- cmd |= (byte)((isHorizontal) ? 2 : 0);
- cmd |= (byte)((antennaNr - 1) << 2);
-
- DISEQC_COMMAND DiseqcCommand = new DISEQC_COMMAND();
- DiseqcCommand.ucMessage[0] = 0xE0; //framing byte
- DiseqcCommand.ucMessage[1] = 0x10; //address byte
- DiseqcCommand.ucMessage[2] = 0x38; //command byte
- DiseqcCommand.ucMessage[3] = cmd; //data byte (port group 0)
- DiseqcCommand.ucMessage[4] = 0; //Need not fill this up
- DiseqcCommand.ucMessage[5] = 0; //Need not fill this up
- DiseqcCommand.ucMessageLength = 4; //Number of Valid bytes in the Command.
-
- Marshal.StructureToPtr(DiseqcCommand, _ptrDiseqc, false);
- //get the length of the structure command - usually 7 bytes.
- int len = Marshal.SizeOf(DiseqcCommand);
-
- string txt = "";
- for (int i = 0; i < len; ++i)
- txt += String.Format("0x{0:X} ", Marshal.ReadByte(_ptrDiseqc, i));
- Log.Log.Debug("GenPix: SendDiseqCommand: {0} with length {1}", txt, len);
- //set the DisEqC command to the tuner pin
- int hr = _propertySet.Set(BdaTunerExtentionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_DISEQC,
- _ptrTempInstance, 32, _ptrDiseqc, len);
- if (hr != 0)
- {
- Log.Log.Info("GenPix: SendDiseqCommand returned: 0x{0:X} - {1}{2}", hr, HResult.GetDXErrorString(hr),
- DsError.GetErrorText(hr));
- }
- }
-
- /// <summary>
- /// Disposes COM task memory resources
- /// </summary>
- public void Dispose()
- {
- Marshal.FreeCoTaskMem(_ptrDiseqc);
- Marshal.FreeCoTaskMem(_ptrTempInstance);
- }
- }
-}
View
539 TvEngine3/TVLibrary/TVLibrary/Implementations/DVB/DisEqC/Genpix.cs
@@ -0,0 +1,539 @@
+#region Copyright (C) 2005-2011 Team MediaPortal
+
+// Copyright (C) 2005-2011 Team MediaPortal
+// http://www.team-mediaportal.com
+//
+// MediaPortal is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// MediaPortal is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MediaPortal. If not, see <http://www.gnu.org/licenses/>.
+
+#endregion
+
+using System;
+using System.Runtime.InteropServices;
+using DirectShowLib;
+using DirectShowLib.BDA;
+using TvLibrary.Channels;
+using TvLibrary.Hardware;
+using TvLibrary.Interfaces;
+
+namespace TvLibrary.Implementations.DVB
+{
+ /// <summary>
+ /// A class for handling DiSEqC for Genpix tuners using the standard BDA driver.
+ /// </summary>
+ public class Genpix : ICustomTuning, IDiSEqCController, IHardwareProvider, IDisposable
+ {
+ #region enums
+
+ private enum BdaExtensionProperty : int
+ {
+ Tune = 0, // For custom tuning implementation.
+ Diseqc, // For DiSEqC messaging.
+ SignalStatus, // For retrieving signal quality, strength, lock status and the actual frequency.
+ }
+
+ private enum GenpixToneBurst : byte
+ {
+ ToneBurst = 0,
+ DataBurst
+ }
+
+ private enum GenpixSwitchPort : uint
+ {
+ None = 0,
+
+ // DiSEqC 1.0
+ PortA,
+ PortB,
+ PortC,
+ PortD,
+
+ // Tone burst (simple DiSEqc)
+ ToneBurst,
+ DataBurst,
+
+ //------------------------------
+ // Legacy Dish Network switches
+ //------------------------------
+ // SW21 - a 2-in-1 out switch.
+ Sw21PortA,
+ Sw21PortB,
+
+ // SW42 - a 2 x 2-in-1 out switch with slightly different
+ // switching commands to the SW21.
+ Sw42PortA,
+ Sw42PortB,
+
+ // SW44???
+ SW44PortB,
+
+ // SW64 - a 6-in-4 out switch, usually used for connecting
+ // 3 satellites (both polarities) to 4 independent receivers.
+ Sw64PortA_Odd,
+ Sw64PortA_Even,
+ Sw64PortB_Odd,
+ Sw64PortB_Even,
+ Sw64PortC_Odd,
+ Sw64PortC_Even,
+
+ // Twin LNB - a dual head LNB with multiple independent outputs.
+ TwinLnbSatA,
+ TwinLnbSatB,
+
+ // Quad LNB???
+ QuadLnbSatB
+ }
+
+ #endregion
+
+ #region structs
+
+ [StructLayout(LayoutKind.Sequential), ComVisible(true)]
+ private struct BdaExtensionParams
+ {
+ public UInt32 Frequency; // unit = MHz
+ public UInt32 LnbLowBandLof; // unit = MHz
+ public UInt32 LnbHighBandLof; // unit = MHz
+ public UInt32 LnbSwitchFrequency; // unit = MHz
+ public UInt32 SymbolRate; // unit = ksps
+ public Polarisation Polarisation;
+ public ModulationType Modulation;
+ public BinaryConvolutionCodeRate InnerFecRate;
+ public GenpixSwitchPort SwitchPort;
+
+ public UInt32 DiseqcRepeats; // Set to zero to send once, one to send twice, two to send three times etc.
+
+ public UInt32 DiseqcMessageLength;
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxDiseqcMessageLength)]
+ public byte[] DiseqcMessage;
+ public bool DiseqcForceHighVoltage;
+
+ public UInt32 SignalStrength; // range = 0 - 100%
+ public UInt32 SignalQuality; // range = 0 - 100%
+ public bool SignalIsLocked;
+ }
+
+ #endregion
+
+ #region constants
+
+ private static readonly Guid BdaExtensionPropertySet = new Guid(0xdf981009, 0x0d8a, 0x430e, 0xa8, 0x03, 0x17, 0xc5, 0x14, 0xdc, 0x8e, 0xc0);
+
+ private const int InstanceSize = 32;
+
+ private const int BdaExtensionParamsSize = 68;
+ private const int MaxDiseqcMessageLength = 8;
+
+ #endregion
+
+ #region variables
+
+ private readonly bool _isGenpix = false;
+ private readonly IntPtr _generalBuffer = IntPtr.Zero;
+ private readonly IntPtr _instanceBuffer = IntPtr.Zero;
+ private readonly IKsPropertySet _propertySet = null;
+
+ #endregion
+
+ /// <summary>
+ /// Initialises a new instance of the <see cref="Genpix"/> class.
+ /// </summary>
+ /// <param name="tunerFilter">The tuner filter.</param>
+ public Genpix(IBaseFilter tunerFilter)
+ {
+ _propertySet = tunerFilter as IKsPropertySet;
+ if (_propertySet == null)
+ {
+ return;
+ }
+
+ KSPropertySupport support;
+ _propertySet.QuerySupported(BdaExtensionPropertySet, (int)BdaExtensionProperty.Diseqc, out support);
+ if ((support & KSPropertySupport.Set) != 0)
+ {
+ Log.Log.Debug("Genpix: supported tuner detected");
+ _isGenpix = true;
+ _generalBuffer = Marshal.AllocCoTaskMem(BdaExtensionParamsSize);
+ _instanceBuffer = Marshal.AllocCoTaskMem(InstanceSize);
+ }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether this tuner is a Genpix tuner using the standard BDA driver.
+ /// </summary>
+ /// <value><c>true</c> if this tuner is a Genpix tuner using the standard BDA driver, otherwise <c>false</c></value>
+ public bool IsGenpix
+ {
+ get
+ {
+ return _isGenpix;
+ }
+ }
+
+ /// <summary>
+ /// Control whether tone/data burst and 22 kHz legacy tone are used.
+ /// </summary>
+ /// <param name="toneBurstState">The tone/data burst state.</param>
+ /// <param name="tone22kState">The 22 kHz legacy tone state.</param>
+ /// <returns><c>true</c> if the tone state is set successfully, otherwise <c>false</c></returns>
+ public bool SetToneState(ToneBurst toneBurstState, Tone22k tone22kState)
+ {
+ Log.Log.Debug("Genpix: set tone state, burst = {0}, 22 kHz = {1}", toneBurstState, tone22kState);
+
+ if (toneBurstState == ToneBurst.Off)
+ {
+ // The Genpix driver doesn't have any explicit way to control the
+ // legacy tone state - the state is set based on the 3 LNB parameters.
+ return true;
+ }
+
+ // The driver interprets sending a DiSEqC message with length zero as
+ // a tone burst command.
+ BdaExtensionParams command = new BdaExtensionParams();
+ command.DiseqcMessageLength = 0;
+ command.DiseqcRepeats = 0;
+ command.DiseqcForceHighVoltage = false;
+ command.DiseqcMessage = new byte[MaxDiseqcMessageLength];
+ if (toneBurstState == ToneBurst.ToneBurst)
+ {
+ command.DiseqcMessage[0] = (byte)GenpixToneBurst.ToneBurst;
+ }
+ else if (toneBurstState == ToneBurst.DataBurst)
+ {
+ command.DiseqcMessage[0] = (byte)GenpixToneBurst.DataBurst;
+ }
+
+ Marshal.StructureToPtr(command, _generalBuffer, true);
+ int hr = _propertySet.Set(BdaExtensionPropertySet, (int)BdaExtensionProperty.Diseqc,
+ _instanceBuffer, InstanceSize,
+ _generalBuffer, BdaExtensionParamsSize
+ );
+ if (hr == 0)
+ {
+ Log.Log.Debug("Genpix: result = success");
+ return true;
+ }
+
+ Log.Log.Debug("Genpix: result = failure, hr = 0x{0:x} ({1})", hr, HResult.GetDXErrorString(hr));
+ return false;
+ }
+
+ /// <summary>
+ /// Set tuning parameters that can or could not previously be set through BDA interfaces.
+ /// </summary>
+ /// <param name="channel">The channel to tune.</param>
+ /// <returns>The channel with parameters adjusted as necessary.</returns>
+ public DVBBaseChannel SetTuningParameters(DVBBaseChannel channel)
+ {
+ Log.Log.Debug("Genpix: set tuning parameters");
+ DVBSChannel ch = channel as DVBSChannel;
+ if (ch == null)
+ {
+ return channel;
+ }
+
+ // Genpix tuners support modulation types that many other
+ // tuners do not. The DSS packet format is not handled by
+ // TsWriter or TsReader. I'm unsure about DC II.
+ // QPSK => DVB-S QPSK
+ // 16 QAM => Turbo FEC QPSK
+ // 8 PSK => Turbo FEC 8 PSK
+ // DirecTV => DSS QPSK
+ // 32 QAM => DC II Combo
+ // 64 QAM => DC II Split (I)
+ // 80 QAM => DC II Split (Q)
+ // 96 QAM => DC II OQPSK
+ if (ch.ModulationType == ModulationType.ModNotSet)
+ {
+ ch.ModulationType = ModulationType.ModQpsk;
+ }
+ Log.Log.Debug(" modulation = {0}", ch.ModulationType);
+ return ch as DVBBaseChannel;
+ }
+
+ #region ICustomTuning members
+
+ /// <summary>
+ /// Check if the custom tune method supports tuning for a given channel.
+ /// </summary>
+ /// <param name="channel">The channel to check.</param>
+ /// <returns><c>true</c> if the custom tune method supports tuning the channel, otherwise <c>false</c></returns>
+ public bool SupportsTuningForChannel(IChannel channel)
+ {
+ // Tuning is only supported for DVB-S channels.
+ if (channel is DVBSChannel)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Tune to a channel using the custom tune method.
+ /// </summary>
+ /// <param name="channel">The channel.</param>
+ /// <param name="parameters">The scan parameters.</param>
+ /// <returns><c>true</c> if tuning is successful, otherwise <c>false</c></returns>
+ public bool CustomTune(IChannel channel, ScanParameters parameters)
+ {
+ Log.Log.Debug("Genpix: tune to channel");
+ if (!SupportsTuningForChannel(channel))
+ {
+ Log.Log.Debug("Genpix: custom tuning not supported for this channel");
+ return false;
+ }
+
+ DVBSChannel ch = channel as DVBSChannel;
+ int lnbLowLof;
+ int lnbHighLof;
+ int lnbSwitchFrequency;
+ BandTypeConverter.GetDefaultLnbSetup(parameters, ch.BandType, out lnbLowLof, out lnbHighLof, out lnbSwitchFrequency);
+ BdaExtensionParams command = new BdaExtensionParams();
+ command.Frequency = (uint)ch.Frequency / 1000;
+ command.LnbLowBandLof = (uint)lnbLowLof;
+ command.LnbHighBandLof = (uint)lnbHighLof;
+ command.LnbSwitchFrequency = (uint)lnbSwitchFrequency;
+ command.SymbolRate = (uint)ch.SymbolRate;
+ command.Polarisation = ch.Polarisation;
+ command.Modulation = ch.ModulationType;
+ command.InnerFecRate = ch.InnerFecRate;
+ command.SwitchPort = GenpixSwitchPort.None;
+ command.DiseqcRepeats = 0;
+
+ Marshal.StructureToPtr(command, _generalBuffer, true);
+ DVB_MMI.DumpBinary(_generalBuffer, 0, BdaExtensionParamsSize);
+
+ int hr = _propertySet.Set(BdaExtensionPropertySet, (int)BdaExtensionProperty.Tune,
+ _instanceBuffer, InstanceSize,
+ _generalBuffer, BdaExtensionParamsSize
+ );
+ if (hr == 0)
+ {
+ Log.Log.Debug("Genpix: result = success");
+ return true;
+ }
+
+ Log.Log.Debug("Genpix: result = failure, hr = 0x{0:x} ({1})", hr, HResult.GetDXErrorString(hr));
+ return false;
+ }
+
+ #endregion
+
+ #region IDiSEqCController members
+
+ /// <summary>
+ /// Send the appropriate DiSEqC 1.0 switch command to switch to a given channel.
+ /// </summary>
+ /// <param name="parameters">The scan parameters.</param>
+ /// <param name="channel">The channel.</param>
+ /// <returns><c>true</c> if the command is successfully sent, otherwise <c>false</c></returns>
+ public bool SendDiseqcCommand(ScanParameters parameters, DVBSChannel channel)
+ {
+ bool successDiseqc = true;
+ bool isHighBand = BandTypeConverter.IsHiBand(channel, parameters);
+ ToneBurst toneBurst = ToneBurst.Off;
+ if (channel.DisEqc == DisEqcType.SimpleA)
+ {
+ toneBurst = ToneBurst.ToneBurst;
+ }
+ else if (channel.DisEqc == DisEqcType.SimpleB)
+ {
+ toneBurst = ToneBurst.DataBurst;
+ }
+ else if (channel.DisEqc != DisEqcType.None)
+ {
+ int antennaNr = BandTypeConverter.GetAntennaNr(channel);
+ bool isHorizontal = ((channel.Polarisation == Polarisation.LinearH) ||
+ (channel.Polarisation == Polarisation.CircularL));
+ byte command = 0xf0;
+ command |= (byte)(isHighBand ? 1 : 0);
+ command |= (byte)((isHorizontal) ? 2 : 0);
+ command |= (byte)((antennaNr - 1) << 2);
+ successDiseqc = SendDiSEqCCommand(new byte[4] { 0xe0, 0x10, 0x38, command });
+ }
+
+ Tone22k tone22k = Tone22k.Off;
+ if (isHighBand)
+ {
+ tone22k = Tone22k.On;
+ }
+ bool successTone = SetToneState(toneBurst, tone22k);
+
+ return (successDiseqc && successTone);
+ }
+
+ /// <summary>
+ /// Send a DiSEqC command.
+ /// </summary>
+ /// <param name="command">The DiSEqC command to send.</param>
+ /// <returns><c>true</c> if the command is successfully sent, otherwise <c>false</c></returns>
+ public bool SendDiSEqCCommand(byte[] command)
+ {
+ Log.Log.Debug("Genpix: send DiSEqC command");
+
+ if (command.Length > MaxDiseqcMessageLength)
+ {
+ Log.Log.Debug("Genpix: command too long, length = {0}", command.Length);
+ return false;
+ }
+
+ BdaExtensionParams message = new BdaExtensionParams();
+ message.DiseqcMessageLength = 0;
+ message.DiseqcRepeats = 0;
+ message.DiseqcForceHighVoltage = false;
+ message.DiseqcMessage = new byte[MaxDiseqcMessageLength];
+ for (int i = 0; i < command.Length; i++)
+ {
+ message.DiseqcMessage[i] = command[i];
+ }
+
+ Marshal.StructureToPtr(message, _generalBuffer, true);
+ int hr = _propertySet.Set(BdaExtensionPropertySet, (int)BdaExtensionProperty.Diseqc,
+ _instanceBuffer, InstanceSize,
+ _generalBuffer, BdaExtensionParamsSize
+ );
+ if (hr == 0)
+ {
+ Log.Log.Debug("Genpix: result = success");
+ return true;
+ }
+
+ Log.Log.Debug("Genpix: result = failure, hr = 0x{0:x} ({1})", hr, HResult.GetDXErrorString(hr));
+ return false;
+ }
+
+ /// <summary>
+ /// Get a reply to a previously sent DiSEqC command. This function is untested.
+ /// </summary>
+ /// <param name="reply">The reply message.</param>
+ /// <returns><c>true</c> if a reply is successfully received, otherwise <c>false</c></returns>
+ public bool ReadDiSEqCCommand(out byte[] reply)
+ {
+ Log.Log.Debug("Genpix: read DiSEqC command");
+ // Not supported...
+ reply = null;
+ return false;
+ }
+
+ #endregion
+
+ #region IHardwareProvider members
+
+ /// <summary>
+ /// Initialise the hardware provider.
+ /// </summary>
+ /// <param name="tunerFilter">The tuner filter.</param>
+ public void Init(IBaseFilter tunerFilter)
+ {
+ // Not implemented.
+ }
+
+ /// <summary>
+ /// Get or set a custom device index. Not applicable for Genpix tuners.
+ /// </summary>
+ public int DeviceIndex
+ {
+ get
+ {
+ return 0;
+ }
+ set
+ {
+ }
+ }
+
+ /// <summary>
+ /// Get or set the tuner device path. Not applicable for Genpix tuners.
+ /// </summary>
+ public String DevicePath
+ {
+ get
+ {
+ return "";
+ }
+ set
+ {
+ }
+ }
+
+ /// <summary>
+ /// Get the provider loading priority.
+ /// </summary>
+ public int Priority
+ {
+ get
+ {
+ return 10;
+ }
+ }
+
+ /// <summary>
+ /// Checks if hardware is supported and open the device.
+ /// </summary>
+ public void CheckAndOpen()
+ {
+ // Not implemented.
+ }
+
+ /// <summary>
+ /// Returns the name of the provider.
+ /// </summary>
+ public String Provider
+ {
+ get
+ {
+ return "Genpix";
+ }
+ }
+
+ /// <summary>
+ /// Returns the result of detection. If false the provider should be disposed.
+ /// </summary>
+ public bool IsSupported
+ {
+ get
+ {
+ return _isGenpix;
+ }
+ }
+
+ /// <summary>
+ /// Returns the provider capabilities.
+ /// </summary>
+ public CapabilitiesType Capabilities
+ {
+ get
+ {
+ return CapabilitiesType.None;
+ }
+ }
+
+ #endregion
+
+ #region IDisposable member
+
+ /// <summary>
+ /// Free unmanaged memory buffers.
+ /// </summary>
+ public void Dispose()
+ {
+ if (_isGenpix)
+ {
+ Marshal.FreeCoTaskMem(_generalBuffer);
+ Marshal.FreeCoTaskMem(_instanceBuffer);
+ }
+ }
+
+ #endregion
+ }
+}
View
286 TvEngine3/TVLibrary/TVLibrary/Implementations/DVB/DisEqC/GenpixOpenSource.cs
@@ -0,0 +1,286 @@
+#region Copyright (C) 2005-2011 Team MediaPortal
+
+// Copyright (C) 2005-2011 Team MediaPortal
+// http://www.team-mediaportal.com
+//
+// MediaPortal is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// MediaPortal is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MediaPortal. If not, see <http://www.gnu.org/licenses/>.
+
+#endregion
+
+using System;
+using System.Runtime.InteropServices;
+using DirectShowLib;
+using DirectShowLib.BDA;
+using TvLibrary.Channels;
+
+namespace TvLibrary.Implementations.DVB
+{
+ /// <summary>
+ /// A class for handling DiSEqC Genpix tuners using the open source BDA
+ /// driver available from http://sourceforge.net/projects/genpixskywalker/
+ /// and http://sourceforge.net/projects/bdaskywalker/.
+ /// </summary>
+ public class GenpixOpenSource : IDiSEqCController, IDisposable
+ {
+ #region enums
+
+ private enum BdaExtensionProperty : int
+ {
+ Diseqc = 0
+ }
+
+ private enum GenpixToneBurst : byte
+ {
+ ToneBurst = 0,
+ DataBurst
+ }
+
+ #endregion
+
+ #region structs
+
+ [StructLayout(LayoutKind.Sequential), ComVisible(true)]
+ private struct DiseqcMessage
+ {
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxDiseqcMessageLength)]
+ public byte[] Message;
+ public byte MessageLength;
+ }
+
+ #endregion
+
+ #region constants
+
+ private static readonly Guid BdaExtensionPropertySet = new Guid(0x0b5221eb, 0xf4c4, 0x4976, 0xb9, 0x59, 0xef, 0x74, 0x42, 0x74, 0x64, 0xd9);
+
+ private const int InstanceSize = 32;
+
+ private const int DiseqcMessageSize = 7;
+ private const int MaxDiseqcMessageLength = 6;
+
+ #endregion
+
+ #region variables
+
+ private bool _isGenpixOpenSource = false;
+ private IntPtr _diseqcBuffer = IntPtr.Zero;
+ private IntPtr _instanceBuffer = IntPtr.Zero;
+ private IKsPropertySet _propertySet = null;
+
+ #endregion
+
+ /// <summary>
+ /// Initialises a new instance of the <see cref="GenpixOpenSource"/> class.
+ /// </summary>
+ /// <param name="tunerFilter">The tuner filter.</param>
+ public GenpixOpenSource(IBaseFilter tunerFilter)
+ {
+ if (tunerFilter == null)
+ {
+ return;
+ }
+ IPin pin = DsFindPin.ByDirection(tunerFilter, PinDirection.Output, 0);
+ _propertySet = pin as IKsPropertySet;
+ if (_propertySet == null)
+ {
+ return;
+ }
+
+ KSPropertySupport support;
+ _propertySet.QuerySupported(BdaExtensionPropertySet, (int)BdaExtensionProperty.Diseqc, out support);
+ if ((support & KSPropertySupport.Set) != 0)
+ {
+ Log.Log.Debug("Genpix (Open Source): supported tuner detected");
+ _isGenpixOpenSource = true;
+ _diseqcBuffer = Marshal.AllocCoTaskMem(DiseqcMessageSize);
+ _instanceBuffer = Marshal.AllocCoTaskMem(InstanceSize);
+ }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether this tuner is a Genpix tuner using the open source driver.
+ /// </summary>
+ /// <value><c>true</c> if this tuner is a Genpix tuner using the open source driver, otherwise <c>false</c></value>
+ public bool IsGenpixOpenSource
+ {
+ get
+ {
+ return _isGenpixOpenSource;
+ }
+ }
+
+ /// <summary>
+ /// Control whether tone/data burst and 22 kHz legacy tone are used.
+ /// </summary>
+ /// <param name="toneBurstState">The tone/data burst state.</param>
+ /// <param name="tone22kState">The 22 kHz legacy tone state.</param>
+ /// <returns><c>true</c> if the tone state is set successfully, otherwise <c>false</c></returns>
+ public bool SetToneState(ToneBurst toneBurstState, Tone22k tone22kState)
+ {
+ Log.Log.Debug("Genpix (Open Source): set tone state, burst = {0}, 22 kHz = {1}", toneBurstState, tone22kState);
+
+ if (toneBurstState == ToneBurst.Off)
+ {
+ // The Genpix open source driver doesn't have any explicit way to
+ // control the legacy tone state - the state is set based on the
+ // 3 LNB parameters.
+ return true;
+ }
+
+ // The driver interprets sending a DiSEqC message with length one as
+ // a tone burst command.
+ DiseqcMessage message = new DiseqcMessage();
+ message.MessageLength = 1;
+ message.Message = new byte[MaxDiseqcMessageLength];
+ if (toneBurstState == ToneBurst.ToneBurst)
+ {
+ message.Message[0] = (byte)GenpixToneBurst.ToneBurst;
+ }
+ else if (toneBurstState == ToneBurst.DataBurst)
+ {
+ message.Message[0] = (byte)GenpixToneBurst.DataBurst;
+ }
+
+ Marshal.StructureToPtr(message, _diseqcBuffer, true);
+ int hr = _propertySet.Set(BdaExtensionPropertySet, (int)BdaExtensionProperty.Diseqc,
+ _instanceBuffer, InstanceSize,
+ _diseqcBuffer, DiseqcMessageSize
+ );
+ if (hr == 0)
+ {
+ Log.Log.Debug("Genpix (Open Source): result = success");
+ return true;
+ }
+
+ Log.Log.Debug("Genpix (Open Source): result = failure, hr = 0x{0:x} ({1})", hr, HResult.GetDXErrorString(hr));
+ return false;
+ }
+
+ #region IDiSEqCController members
+
+ /// <summary>
+ /// Send the appropriate DiSEqC 1.0 switch command to switch to a given channel.
+ /// </summary>
+ /// <param name="parameters">The scan parameters.</param>
+ /// <param name="channel">The channel.</param>
+ /// <returns><c>true</c> if the command is successfully sent, otherwise <c>false</c></returns>
+ public bool SendDiseqcCommand(ScanParameters parameters, DVBSChannel channel)
+ {
+ bool successDiseqc = true;
+ bool isHighBand = BandTypeConverter.IsHiBand(channel, parameters);
+ ToneBurst toneBurst = ToneBurst.Off;
+ if (channel.DisEqc == DisEqcType.SimpleA)
+ {
+ toneBurst = ToneBurst.ToneBurst;
+ }
+ else if (channel.DisEqc == DisEqcType.SimpleB)
+ {
+ toneBurst = ToneBurst.DataBurst;
+ }
+ else if (channel.DisEqc != DisEqcType.None)
+ {
+ int antennaNr = BandTypeConverter.GetAntennaNr(channel);
+ bool isHorizontal = ((channel.Polarisation == Polarisation.LinearH) ||
+ (channel.Polarisation == Polarisation.CircularL));
+ byte command = 0xf0;
+ command |= (byte)(isHighBand ? 1 : 0);
+ command |= (byte)((isHorizontal) ? 2 : 0);
+ command |= (byte)((antennaNr - 1) << 2);
+ successDiseqc = SendDiSEqCCommand(new byte[4] { 0xe0, 0x10, 0x38, command });
+ }
+
+ Tone22k tone22k = Tone22k.Off;
+ if (isHighBand)
+ {
+ tone22k = Tone22k.On;
+ }
+ bool successTone = SetToneState(toneBurst, tone22k);
+
+ return (successDiseqc && successTone);
+ }
+
+ /// <summary>
+ /// Send a DiSEqC command.
+ /// </summary>
+ /// <param name="command">The DiSEqC command to send.</param>
+ /// <returns><c>true</c> if the command is successfully sent, otherwise <c>false</c></returns>
+ public bool SendDiSEqCCommand(byte[] command)
+ {
+ Log.Log.Debug("Genpix (Open Source): send DiSEqC command");
+
+ if (command.Length > MaxDiseqcMessageLength)
+ {
+ Log.Log.Debug("Genpix (Open Source): command too long, length = {0}", command.Length);
+ return false;
+ }
+
+ DiseqcMessage message = new DiseqcMessage();
+ message.MessageLength = (byte)command.Length;
+ message.Message = new byte[MaxDiseqcMessageLength];
+ for (int i = 0; i < command.Length; i++)
+ {
+ message.Message[i] = command[i];
+ }
+
+ Marshal.StructureToPtr(message, _diseqcBuffer, true);
+ int hr = _propertySet.Set(BdaExtensionPropertySet, (int)BdaExtensionProperty.Diseqc,
+ _instanceBuffer, InstanceSize,
+ _diseqcBuffer, DiseqcMessageSize
+ );
+ if (hr == 0)
+ {
+ Log.Log.Debug("Genpix (Open Source): result = success");
+ return true;
+ }
+
+ Log.Log.Debug("Genpix (Open Source): result = failure, hr = 0x{0:x} ({1})", hr, HResult.GetDXErrorString(hr));
+ return false;
+ }
+
+ /// <summary>
+ /// Get a reply to a previously sent DiSEqC command. This function is untested.
+ /// </summary>
+ /// <param name="reply">The reply message.</param>
+ /// <returns><c>true</c> if a reply is successfully received, otherwise <c>false</c></returns>
+ public bool ReadDiSEqCCommand(out byte[] reply)
+ {
+ Log.Log.Debug("Genpix (Open Source): read DiSEqC command");
+ // Not supported...
+ reply = null;
+ return false;
+ }
+
+ #endregion
+
+ #region IDisposable member
+
+ /// <summary>
+ /// Free unmanaged memory buffers.
+ /// </summary>
+ public void Dispose()
+ {
+ if (_propertySet != null)
+ {
+ Release.ComObject(_propertySet);
+ }
+ if (_isGenpixOpenSource)
+ {
+ Marshal.FreeCoTaskMem(_diseqcBuffer);
+ Marshal.FreeCoTaskMem(_instanceBuffer);
+ }
+ }
+
+ #endregion
+ }
+}
View
3 TvEngine3/TVLibrary/TVLibrary/TVLibrary.csproj
@@ -108,10 +108,11 @@
<Compile Include="Implementations\DVB\ConditionalAccess\DigitalDevices\DigitalDevices.cs" />
<Compile Include="Implementations\DVB\ConditionalAccess\ProfRed\ProfRed.cs" />
<Compile Include="Implementations\DVB\DisEqC\ConexantBDA.cs" />
+ <Compile Include="Implementations\DVB\DisEqC\Genpix.cs" />
<Compile Include="Implementations\DVB\DisEqC\TeVii.cs" />
<Compile Include="Implementations\DVB\QAM\GenericATSC.cs" />
<Compile Include="Implementations\DVB\DisEqC\GenericBDAS.cs" />
- <Compile Include="Implementations\DVB\DisEqC\GenPixBDA.cs" />
+ <Compile Include="Implementations\DVB\DisEqC\GenpixOpenSource.cs" />
<Compile Include="Implementations\DVB\ConditionalAccess\HaupPauge\Hauppauge.cs" />
<Compile Include="Implementations\DVB\ConditionalAccess\HaupPauge\WinTvCiModule.cs" />
<Compile Include="Implementations\DVB\ConditionalAccess\KNC\KNCAPI.cs" />

0 comments on commit 20137e1

Please sign in to comment.
Something went wrong with that request. Please try again.