/// <summary>
 /// Initializes a new instance of the <see cref="TvDvbChannel"/> class.
 /// </summary>
 public TvDvbChannel()
 {
   _cancelled = false;
   _listenCA = false;
   _eventPMT = new ManualResetEvent(false);
   _eventCA = new ManualResetEvent(false);
   _graphState = GraphState.Created;
   _teletextDecoder = new DVBTeletext();
   _packetHeader = new TSHelperTools.TSHeader();
   _tsHelper = new TSHelperTools();
   _channelInfo = new ChannelInfo();
   _pmtPid = -1;
   _subChannelId = 0;
   _timeshiftFileName = "";
   _recordingFileName = "";
   _pmtData = null;
   _pmtLength = 0;
 }
    /// <summary>
    /// Initializes a new instance of the <see cref="TvDvbChannel"/> class.
    /// </summary>
    /// <param name="graphBuilder">The graph builder.</param>
    /// <param name="ca">The ca.</param>
    /// <param name="mdplugs">The mdplugs class.</param>
    /// <param name="tif">The tif filter.</param>
    /// <param name="tsWriter">The ts writer filter.</param>
    /// <param name="subChannelId">The subchannel id</param>
    /// <param name="channel">The corresponding channel</param>
    public TvDvbChannel(IFilterGraph2 graphBuilder, ConditionalAccess ca, MDPlugs mdplugs, IBaseFilter tif,
                        IBaseFilter tsWriter, int subChannelId, IChannel channel)
    {
      _cancelled = false;
      _listenCA = false;
      _eventPMT = new ManualResetEvent(false);
      _eventCA = new ManualResetEvent(false);
      _graphState = GraphState.Created;
      _graphBuilder = graphBuilder;
      _conditionalAccess = ca;
      _mdplugs = mdplugs;
      _filterTIF = tif;
      _teletextDecoder = new DVBTeletext();
      _packetHeader = new TSHelperTools.TSHeader();
      _tsHelper = new TSHelperTools();
      _channelInfo = new ChannelInfo();
      _pmtPid = -1;
      _subChannelIndex = -1;
      _tsFilterInterface = (ITsFilter)tsWriter;
      _tsFilterInterface.AddChannel(ref _subChannelIndex);

      Log.Log.WriteFile("TvDvbChannel ctor new subchIndex:{0}", _subChannelIndex);

      _subChannelId = subChannelId;
      _conditionalAccess.AddSubChannel(_subChannelId, channel);
      _timeshiftFileName = "";
      _recordingFileName = "";
      _pmtData = null;
      _pmtLength = 0;
    }
    /// <summary>
    /// processes a single transport packet
    /// Called from BufferCB
    /// </summary>
    /// <param name="ptr">pointer to the transport packet</param>
    public void ProcessPacket(IntPtr ptr)
    {
      if (ptr == IntPtr.Zero) return;

      _packetHeader = _tsHelper.GetHeader(ptr);
      if (_packetHeader.SyncByte != 0x47)
      {
        Log.Log.WriteFile("packet sync error");
        return;
      }
      if (_packetHeader.TransportError)
      {
        Log.Log.WriteFile("packet transport error");
        return;
      }
      // teletext
      //if (_grabTeletext)
      {
        if (_teletextDecoder != null)
        {
          _teletextDecoder.SaveData(ptr);
        }
      }
    }