Example #1
0
    ///<summary>
    /// Constructor for a capture card device.
    ///</summary>
    ///<param name="device">A crossbar device for a supported capture card.</param>
    public TvCardHDPVR(DsDevice device)
      : base(device)
    {
      // Determine what type of card this is.
      if (device.Name.Contains("Colossus"))
      {
        Match match = Regex.Match(device.Name, @".*?(\d+)$");
        int deviceNumber = 0;
        if (match.Success)
        {
          deviceNumber = Convert.ToInt32(match.Groups[1].Value);
        }
        _deviceType = "Colossus";
        _crossbarDeviceName = device.Name;
        _captureDeviceName = "Hauppauge Colossus Capture " + deviceNumber;
        _encoderDeviceName = "Hauppauge Colossus TS Encoder " + deviceNumber;
      }

      _mapSubChannels = new Dictionary<Int32, BaseSubChannel>();
      _supportsSubChannels = true;
      _minChannel = 0;
      _maxChannel = 128;
      _camType = CamType.Default;
      _conditionalAccess = null;
      _cardType = CardType.Analog;
      _epgGrabbing = false;
      _configuration = Configuration.readConfiguration(_cardId, _name, _devicePath);
      Configuration.writeConfiguration(_configuration);
    }
Example #2
0
 /// <summary>
 /// Reloads the quality control configuration
 /// </summary>
 public void ReloadCardConfiguration()
 {
   if (_qualityControl != null)
   {
     _configuration = Configuration.readConfiguration(_cardId, _name, _devicePath);
     Configuration.writeConfiguration(_configuration);
     _qualityControl.SetConfiguration(_configuration);
   }
 }
Example #3
0
    /// <summary>
    /// Builds the directshow graph for this analog tvcard
    /// </summary>
    public override void BuildGraph()
    {
      if (_cardId == 0)
      {
        GetPreloadBitAndCardId();
        _configuration = Configuration.readConfiguration(_cardId, _name, _devicePath);
        Configuration.writeConfiguration(_configuration);
      }

      _lastSignalUpdate = DateTime.MinValue;
      _tunerLocked = false;
      Log.Log.WriteFile("HDPVR: build graph");
      try
      {
        if (_graphState != GraphState.Idle)
        {
          Log.Log.WriteFile("HDPVR: graph already built!");
          throw new TvException("Graph already built");
        }
        _graphBuilder = (IFilterGraph2)new FilterGraph();
        _rotEntry = new DsROTEntry(_graphBuilder);
        _capBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
        _capBuilder.SetFiltergraph(_graphBuilder);
        AddCrossBarFilter();
        AddCaptureFilter();
        AddEncoderFilter();
        AddTsWriterFilterToGraph();
        _qualityControl = QualityControlFactory.createQualityControl(_configuration, _filterEncoder, _filterCapture,
                                                                     null, null);
        if (_qualityControl == null)
        {
          Log.Log.WriteFile("HDPVR: No quality control support found");
        }

        _graphState = GraphState.Created;
        _configuration.Graph.Crossbar.Name = _crossBarDevice.Name;
        _configuration.Graph.Crossbar.VideoPinMap = _videoPinMap;
        _configuration.Graph.Crossbar.AudioPinMap = _audioPinMap;
        _configuration.Graph.Crossbar.VideoPinRelatedAudioMap = _videoPinRelatedAudioMap;
        _configuration.Graph.Crossbar.VideoOut = _videoOutPinIndex;
        _configuration.Graph.Crossbar.AudioOut = _audioOutPinIndex;
        _configuration.Graph.Capture.Name = _captureDevice.Name;
        _configuration.Graph.Capture.FrameRate = -1d;
        _configuration.Graph.Capture.ImageHeight = -1;
        _configuration.Graph.Capture.ImageWidth = -1;
        Configuration.writeConfiguration(_configuration);
      }
      catch (Exception ex)
      {
        Log.Log.Write(ex);
        Dispose();
        _graphState = GraphState.Idle;
        throw;
      }
    }
    public override void OnSectionActivated()
    {
      base.OnSectionActivated();
      mpComboBoxSensitivity.SelectedIndex = 1;
      UpdateStatus();
      TvBusinessLayer layer = new TvBusinessLayer();
      mpComboBoxCountry.SelectedIndex = Int32.Parse(layer.GetSetting("analog" + _cardNumber + "Country", "0").Value);
      mpComboBoxSource.SelectedIndex = Int32.Parse(layer.GetSetting("analog" + _cardNumber + "Source", "0").Value);
      checkBoxCreateSignalGroup.Checked =
        (layer.GetSetting("analog" + _cardNumber + "createsignalgroup", "false").Value == "true");
      checkBoxCreateSignalGroup.Text = "Create \"" + TvConstants.TvGroupNames.Analog + "\" group";

      _cardName = RemoteControl.Instance.CardName(_cardNumber);
      _devicePath = RemoteControl.Instance.CardDevice(_cardNumber);
      if (!String.IsNullOrEmpty(_cardName) && !String.IsNullOrEmpty(_devicePath))
      {
        _configuration = Configuration.readConfiguration(_cardNumber, _cardName, _devicePath);
        customValue.Value = _configuration.CustomQualityValue;
        customValuePeak.Value = _configuration.CustomPeakQualityValue;
        SetBitRateModes();
        SetBitRate();
        SetVideoProcAmp(_configuration.Graph.Capture.VideoProcAmpValues);
        SetVideoDecoder();
        SetStreamConfig();
      }
      else
      {
        SetVideoProcAmp(new Dictionary<VideoProcAmpProperty, VideoQuality>());
        videoStandardComboBox.Enabled = false;
        resolutionComboBox.Enabled = false;
        frameRateComboBox.Enabled = false;
      }
    }
    private void DoTvScan()
    {
      int channelsNew = 0;
      int channelsUpdated = 0;

      string buttonText = mpButtonScanTv.Text;
      checkButton.Enabled = false;
      try
      {
        _isScanning = true;
        _stopScanning = false;
        mpButtonScanTv.Text = "Cancel...";
        RemoteControl.Instance.EpgGrabberEnabled = false;
        TvBusinessLayer layer = new TvBusinessLayer();
        Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
        mpComboBoxCountry.Enabled = false;
        mpComboBoxSource.Enabled = false;
        mpComboBoxSensitivity.Enabled = false;
        checkBoxCreateSignalGroup.Enabled = false;
        checkBoxNoMerge.Enabled = false;
        mpButtonScanRadio.Enabled = false;
        mpButtonAddSvideoChannels.Enabled = false;
        mpListView1.Items.Clear();
        CountryCollection countries = new CountryCollection();
        IUser user = new User();
        user.CardId = _cardNumber;
        AnalogChannel temp = new AnalogChannel();
        temp.TunerSource = mpComboBoxSource.SelectedIndex == 0 ? TunerInputType.Antenna : TunerInputType.Cable;
        temp.VideoSource = AnalogChannel.VideoInputType.Tuner;
        temp.AudioSource = AnalogChannel.AudioInputType.Tuner;
        temp.Country = countries.Countries[mpComboBoxCountry.SelectedIndex];
        temp.IsRadio = false;
        temp.IsTv = true;
        TvResult tuneResult = RemoteControl.Instance.Tune(ref user, temp, -1);
        if (tuneResult == TvResult.SWEncoderMissing)
        {
          Log.Error("analog: DoTvScan error (missing software encoder)");
          MessageBox.Show("Please install a supported audio/video encoder for your software analog card",
                          "Unable to scan", MessageBoxButtons.OK, MessageBoxIcon.Error);
          return;
        }
        if (tuneResult == TvResult.GraphBuildingFailed)
        {
          Log.Error("analog: DoTvScan error (missing software encoder)");
          MessageBox.Show(
            "The graph building. Mostly your card is not supported by TvServer. Please create a report in our forum",
            "Unable to scan", MessageBoxButtons.OK, MessageBoxIcon.Error);
          return;
        }
        if (string.IsNullOrEmpty(_configuration.Graph.Capture.Name))
        {
          _configuration = Configuration.readConfiguration(_cardNumber, _cardName, _devicePath);
          ReCheckSettings();
        }
        int minChannel = RemoteControl.Instance.MinChannel(_cardNumber);
        int maxChannel = RemoteControl.Instance.MaxChannel(_cardNumber);
        if (maxChannel <= 0)
        {
          maxChannel = mpComboBoxSource.SelectedIndex == 0 ? 69 : 125;
        }
        if (minChannel < 0)
          minChannel = 1;
        Log.Info("Min channel = {0}. Max channel = {1}", minChannel, maxChannel);
        for (int channelNr = minChannel; channelNr <= maxChannel; channelNr++)
        {
          if (_stopScanning)
            return;
          float percent = ((float)((channelNr - minChannel)) / (maxChannel - minChannel));
          percent *= 100f;
          if (percent > 100f)
            percent = 100f;
          if (percent < 0)
            percent = 0f;
          progressBar1.Value = (int)percent;
          AnalogChannel channel = new AnalogChannel();
          channel.TunerSource = mpComboBoxSource.SelectedIndex == 0 ? TunerInputType.Antenna : TunerInputType.Cable;
          channel.Country = countries.Countries[mpComboBoxCountry.SelectedIndex];
          channel.ChannelNumber = channelNr;
          channel.IsTv = true;
          channel.IsRadio = false;
          channel.VideoSource = AnalogChannel.VideoInputType.Tuner;
          channel.AudioSource = AnalogChannel.AudioInputType.Automatic;
          string line = String.Format("channel:{0} source:{1} ", channel.ChannelNumber, mpComboBoxSource.SelectedItem);
          ListViewItem item = mpListView1.Items.Add(new ListViewItem(line));
          item.EnsureVisible();

          IChannel[] channels = RemoteControl.Instance.Scan(_cardNumber, channel);
          UpdateStatus();
          if (channels == null || channels.Length == 0)
          {
            if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
            {
              line = String.Format("channel:{0} source:{1} : No Signal", channel.ChannelNumber,
                                   mpComboBoxSource.SelectedItem);
              item.Text = line;
              item.ForeColor = Color.Red;
              continue;
            }
            line = String.Format("channel:{0} source:{1} : Nothing found", channel.ChannelNumber,
                                 mpComboBoxSource.SelectedItem);
            item.Text = line;
            item.ForeColor = Color.Red;
            continue;
          }
          bool exists = false;
          channel = (AnalogChannel)channels[0];
          if (channel.Name == "")
            channel.Name = String.Format(channel.ChannelNumber.ToString());
          Channel dbChannel = null;
          if (checkBoxNoMerge.Checked)
          {
            dbChannel = layer.AddNewChannel(channel.Name);
          }
          else
          {
            IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channel.Name, 0);
            if (tuningDetails != null && tuningDetails.Count > 0)
            {
              dbChannel = tuningDetails[0].ReferencedChannel();
            }

            if (dbChannel != null)
            {
              exists = true;
            }
            else
            {
              dbChannel = layer.AddNewChannel(channel.Name);
            }
          }
          dbChannel.IsTv = channel.IsTv;
          dbChannel.IsRadio = channel.IsRadio;
          dbChannel.Persist();
          layer.AddTuningDetails(dbChannel, channel);
          layer.MapChannelToCard(card, dbChannel, false);

          if (dbChannel.IsTv)
          {
            layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
            if (checkBoxCreateSignalGroup.Checked)
            {
              layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.Analog);
            }
          }
          if (dbChannel.IsRadio)
          {
            layer.AddChannelToGroup(dbChannel, TvConstants.RadioGroupNames.AllChannels);
            if (checkBoxCreateSignalGroup.Checked)
            {
              layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.Analog);
            }
          }

          if (exists)
          {
            line = String.Format("channel:{0} source:{1} : Channel update found - {2}", channel.ChannelNumber,
                                 mpComboBoxSource.SelectedItem, channel.Name);
            channelsUpdated++;
          }
          else
          {
            line = String.Format("channel:{0} source:{1} : New channel found - {2}", channel.ChannelNumber,
                                 mpComboBoxSource.SelectedItem, channel.Name);
            channelsNew++;
          }
          item.Text = line;
        }
      }
      catch (TvExceptionSWEncoderMissing)
      {
        Log.Error("analog: DoTvScan error (missing software encoder)");
        MessageBox.Show("Please install a supported audio/video encoder for your software analog card", "Unable to scan",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
      catch (TvExceptionGraphBuildingFailed)
      {
        Log.Error("analog: DoTvScan error (missing software encoder)");
        MessageBox.Show(
          "The graph building. Mostly your card is not supported by TvServer. Please create a report in our forum",
          "Unable to scan", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
      catch (Exception ex)
      {
        Log.Error("analog: DoTvScan error ({0})", ex.StackTrace);
        MessageBox.Show(string.Format("Generic error: {0}", ex.Message), "Unable to scan", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
      }
      finally
      {
        IUser user = new User();
        user.CardId = _cardNumber;
        RemoteControl.Instance.StopCard(user);
        RemoteControl.Instance.EpgGrabberEnabled = true;
        mpButtonScanTv.Text = buttonText;
        progressBar1.Value = 100;
        mpComboBoxCountry.Enabled = true;
        mpComboBoxSource.Enabled = true;
        mpComboBoxSensitivity.Enabled = true;
        checkBoxCreateSignalGroup.Enabled = true;
        checkBoxNoMerge.Enabled = true;
        mpButtonScanTv.Enabled = true;
        mpButtonScanRadio.Enabled = true;
        mpButtonAddSvideoChannels.Enabled = true;
        _isScanning = false;
        checkButton.Enabled = true;
      }
      ListViewItem lastItem =
        mpListView1.Items.Add(
          new ListViewItem(String.Format("Total tv channels new:{0} updated:{1}", channelsNew, channelsUpdated)));
      lastItem.EnsureVisible();
    }
    private void mpButton1_Click(object sender, EventArgs e)
    {
      if (string.IsNullOrEmpty(_configuration.Graph.Crossbar.Name))
      {
        IUser user = new User();
        user.CardId = _cardNumber;
        AnalogChannel temp = new AnalogChannel();
        temp.TunerSource = TunerInputType.Antenna;
        temp.VideoSource = AnalogChannel.VideoInputType.Tuner;
        temp.AudioSource = AnalogChannel.AudioInputType.Tuner;
        temp.IsRadio = false;
        temp.IsTv = true;
        RemoteControl.Instance.Tune(ref user, temp, -1);
        _configuration = Configuration.readConfiguration(_cardNumber, _cardName, _devicePath);
        if (string.IsNullOrEmpty(_configuration.Graph.Crossbar.Name))
        {
          MessageBox.Show(this, "The S-Video channels could not be detected.");
          return;
        }
        ReCheckSettings();
      }

      TvBusinessLayer layer = new TvBusinessLayer();
      Dictionary<AnalogChannel.VideoInputType, int> videoPinMap = _configuration.Graph.Crossbar.VideoPinMap;
      AnalogChannel tuningDetail;
      Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
      Channel dbChannel;
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.VideoInput1))
      {
        string channelName = "CVBS#1 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.VideoInput1;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.VideoInput2))
      {
        string channelName = "CVBS#2 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.VideoInput2;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.VideoInput3))
      {
        string channelName = "CVBS#3 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.VideoInput3;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.SvhsInput1))
      {
        string channelName = "S-Video#1 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.SvhsInput1;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.SvhsInput2))
      {
        string channelName = "S-Video#2 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.SvhsInput2;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.SvhsInput3))
      {
        string channelName = "S-Video#3 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.SvhsInput3;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.RgbInput1))
      {
        string channelName = "RGB#1 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.RgbInput1;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.RgbInput2))
      {
        string channelName = "RGB#2 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.RgbInput2;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.RgbInput3))
      {
        string channelName = "RGB#3 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.RgbInput3;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.YRYBYInput1))
      {
        string channelName = "YRYBY#1 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.YRYBYInput1;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.YRYBYInput2))
      {
        string channelName = "YRYBY#2 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.YRYBYInput2;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.YRYBYInput3))
      {
        string channelName = "YRYBY#3 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.YRYBYInput3;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.HdmiInput1))
      {
        string channelName = "HDMI#1 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.HdmiInput1;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.HdmiInput2))
      {
        string channelName = "HDMI#2 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.HdmiInput2;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.HdmiInput3))
      {
        string channelName = "HDMI#3 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.HdmiInput3;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      MessageBox.Show(this, "Channels added.");
    }
 private void checkButton_Click(object sender, EventArgs e)
 {
   IUser user;
   try
   {
     TvBusinessLayer layer = new TvBusinessLayer();
     Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
     if (card.Enabled == false)
     {
       MessageBox.Show(this, "Card is disabled, please enable the card before checking quality control");
       return;
     }
     else if (!RemoteControl.Instance.CardPresent(card.IdCard))
     {
       MessageBox.Show(this, "Card is not found, please make sure card is present before checking quality control");
       return;
     }
     // Check if the card is locked for scanning.
     if (RemoteControl.Instance.IsCardInUse(_cardNumber, out user))
     {
       MessageBox.Show(this,
                       "Card is locked. Checking quality control not possible at the moment ! Perhaps you are scanning an other part of a hybrid card.");
       return;
     }
     user = new User();
     user.CardId = _cardNumber;
     AnalogChannel temp = new AnalogChannel();
     temp.VideoSource = AnalogChannel.VideoInputType.Tuner;
     temp.AudioSource = AnalogChannel.AudioInputType.Tuner;
     temp.IsRadio = false;
     temp.IsTv = true;
     RemoteControl.Instance.Tune(ref user, temp, -1);
     if (RemoteControl.Instance.SupportsQualityControl(_cardNumber))
     {
       _cardName = RemoteControl.Instance.CardName(_cardNumber);
       _devicePath = RemoteControl.Instance.CardDevice(_cardNumber);
       bitRateModeGroup.Enabled = RemoteControl.Instance.SupportsBitRateModes(_cardNumber);
       if (RemoteControl.Instance.SupportsPeakBitRateMode(_cardNumber))
       {
         vbrPeakPlayback.Enabled = true;
         vbrPeakRecord.Enabled = true;
       }
       else
       {
         vbrPeakPlayback.Enabled = false;
         vbrPeakRecord.Enabled = false;
       }
       if (RemoteControl.Instance.SupportsBitRate(_cardNumber))
       {
         bitRate.Enabled = true;
         customSettingsGroup.Enabled = true;
         customValue.Enabled = true;
         customValuePeak.Enabled = true;
       }
       else
       {
         bitRate.Enabled = false;
         customSettingsGroup.Enabled = false;
         customValue.Enabled = false;
         customValuePeak.Enabled = false;
       }
       _configuration = Configuration.readConfiguration(_cardNumber, _cardName, _devicePath);
       customValue.Value = _configuration.CustomQualityValue;
       customValuePeak.Value = _configuration.CustomPeakQualityValue;
       SetBitRateModes();
       SetBitRate();
       ReCheckSettings();
     }
     else
     {
       Log.WriteFile("Card doesn't support quality control");
       MessageBox.Show("The used encoder doesn't support quality control.",
                       "MediaPortal - TV Server management console", MessageBoxButtons.OK, MessageBoxIcon.Information);
       if (string.IsNullOrEmpty(_configuration.Graph.Capture.Name))
       {
         _configuration = Configuration.readConfiguration(_cardNumber, _cardName, _devicePath);
         ReCheckSettings();
       }
     }
   }
   finally
   {
     user = new User();
     user.CardId = _cardNumber;
     RemoteControl.Instance.StopCard(user);
   }
 }
 private void mpButtonScanRadio_Click(object sender, EventArgs e)
 {
   if (_isScanning == false)
   {
     TvBusinessLayer layer = new TvBusinessLayer();
     Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
     if (card.Enabled == false)
     {
       MessageBox.Show(this, "Card is disabled, please enable the card before scanning");
       return;
     }
     if (!RemoteControl.Instance.CardPresent(card.IdCard))
     {
       MessageBox.Show(this, "Card is not found, please make sure card is present before scanning");
       return;
     }
     // Check if the card is locked for scanning.
     IUser user;
     if (RemoteControl.Instance.IsCardInUse(_cardNumber, out user))
     {
       MessageBox.Show(this,
                       "Card is locked. Scanning not possible at the moment ! Perhaps you are scanning an other part of a hybrid card.");
       return;
     }
     AnalogChannel radioChannel = new AnalogChannel();
     radioChannel.Frequency = 96000000;
     radioChannel.IsRadio = true;
     radioChannel.VideoSource = AnalogChannel.VideoInputType.Tuner;
     radioChannel.AudioSource = AnalogChannel.AudioInputType.Automatic;
     if (!RemoteControl.Instance.CanTune(_cardNumber, radioChannel))
     {
       MessageBox.Show(this, "The Tv Card does not support radio");
       return;
     }
     if (string.IsNullOrEmpty(_configuration.Graph.Capture.Name))
     {
       _configuration = Configuration.readConfiguration(_cardNumber, _cardName, _devicePath);
       ReCheckSettings();
     }
     Thread scanThread = new Thread(DoRadioScan);
     scanThread.Name = "Analog Radio scan thread";
     scanThread.Start();
   }
   else
   {
     _stopScanning = true;
   }
 }
Example #9
0
 /// <summary>
 /// Saves the configuration object in a xml file
 /// </summary>
 /// <param name="configuration">Configuration object to be saved</param>
 public static void writeConfiguration(Configuration configuration)
 {
   if (configuration != null && configuration.CardId != 0)
   {
     String fileName = GetFileName(configuration.Name, configuration.CardId);
     XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8);
     writer.Formatting = Formatting.Indented;
     writer.Indentation = 1;
     writer.IndentChar = (char)9;
     writer.WriteStartDocument(true);
     writer.WriteStartElement("configuration"); //<configuration>
     writer.WriteAttributeString("version", "2");
     writer.WriteStartElement("card"); //<card>
     writer.WriteAttributeString("cardId", XmlConvert.ToString(configuration.CardId));
     writer.WriteAttributeString("name", configuration.Name);
     writer.WriteStartElement("device"); //<device>
     writer.WriteElementString("path", configuration.DevicePath);
     writer.WriteEndElement(); //</device>
     configuration.Graph.WriteGraph(writer);
     writer.WriteStartElement("qualityControl"); //<qualityControl>
     writer.WriteStartElement("customSettings"); //<customSettings>
     writer.WriteAttributeString("value", XmlConvert.ToString(configuration.CustomQualityValue));
     writer.WriteAttributeString("peakValue", XmlConvert.ToString(configuration.CustomPeakQualityValue));
     writer.WriteEndElement(); //</customSettings>
     writer.WriteStartElement("playback"); //<playback>
     writer.WriteAttributeString("mode", XmlConvert.ToString((int)configuration.PlaybackQualityMode));
     writer.WriteAttributeString("type", XmlConvert.ToString((int)configuration.PlaybackQualityType));
     writer.WriteEndElement(); //</playback>
     writer.WriteStartElement("record"); //<record>
     writer.WriteAttributeString("mode", XmlConvert.ToString((int)configuration.RecordQualityMode));
     writer.WriteAttributeString("type", XmlConvert.ToString((int)configuration.RecordQualityType));
     writer.WriteEndElement(); //</record>
     writer.WriteEndElement(); //</qualityControl>
     writer.WriteEndElement(); //</card>
     writer.WriteEndElement(); //</configuration>
     writer.WriteEndDocument();
     writer.Close();
   }
 }
Example #10
0
    /// <summary>
    /// Loads the configuration from a xml file
    /// </summary>
    /// <param name="name">Name of the card</param>
    /// <param name="cardId">Unique id of the card</param>
    /// <param name="devicePath">The device path of the card</param>
    /// <returns>Configuration object</returns>
    public static Configuration readConfiguration(int cardId, string name, string devicePath)
    {
      Configuration _configuration = new Configuration();
      String fileName = GetFileName(name, cardId);
      _configuration.Name = name;
      _configuration.DevicePath = devicePath;
      _configuration.CardId = cardId;
      if (cardId != 0 && File.Exists(fileName))
      {
        try
        {
          XmlDocument doc = new XmlDocument();
          doc.Load(fileName);
          if (doc.DocumentElement != null)
          {
            XmlNode cardNode = doc.DocumentElement.SelectSingleNode("/configuration/card");
            _configuration.CardId = int.Parse(cardNode.Attributes["cardId"].Value);
            if (_configuration.CardId != cardId)
            {
              File.Delete(fileName);
              _configuration = new Configuration();
              _configuration.Name = name;
              _configuration.DevicePath = devicePath;
              _configuration.CardId = cardId;
              return _configuration;
            }
            _configuration.Name = cardNode.Attributes["name"].Value;
            if (_configuration.Name != name)
            {
              File.Delete(fileName);
              _configuration = new Configuration();
              _configuration.Name = name;
              _configuration.DevicePath = devicePath;
              _configuration.CardId = cardId;
              return _configuration;
            }
            XmlNode node = cardNode.SelectSingleNode("device/path");
            _configuration.DevicePath = node.InnerText;
            if (!_configuration.DevicePath.Equals(devicePath))
            {
              File.Delete(fileName);
              _configuration = new Configuration();
              _configuration.Name = name;
              _configuration.DevicePath = devicePath;
              _configuration.CardId = cardId;
              return _configuration;
            }

            node = cardNode.SelectSingleNode("qualityControl");
            XmlNode tempNode = node.SelectSingleNode("customSettings");
            _configuration.CustomQualityValue = int.Parse(tempNode.Attributes["value"].Value);
            _configuration.CustomPeakQualityValue = int.Parse(tempNode.Attributes["peakValue"].Value);
            tempNode = node.SelectSingleNode("playback");
            int tempValue = int.Parse(tempNode.Attributes["mode"].Value);
            if (tempValue < 0 || tempValue > 2)
            {
              tempValue = 0;
            }
            _configuration.PlaybackQualityMode = (VIDEOENCODER_BITRATE_MODE)tempValue;
            tempValue = int.Parse(tempNode.Attributes["type"].Value);
            if (tempValue < 1 || tempValue > 6)
            {
              tempValue = 1;
            }
            _configuration.PlaybackQualityType = (QualityType)tempValue;
            tempNode = node.SelectSingleNode("record");
            tempValue = int.Parse(tempNode.Attributes["mode"].Value);
            if (tempValue < 0 || tempValue > 2)
            {
              tempValue = 0;
            }
            _configuration.RecordQualityMode = (VIDEOENCODER_BITRATE_MODE)tempValue;
            tempValue = int.Parse(tempNode.Attributes["type"].Value);
            if (tempValue < 1 || tempValue > 6)
            {
              tempValue = 1;
            }
            _configuration.RecordQualityType = (QualityType)tempValue;
            _configuration.Graph = Graph.CreateInstance(cardNode.SelectSingleNode("graph"));
          }
        }
        catch
        {
          Log.Log.WriteFile("Error while reading analog card configuration file");
          _configuration = new Configuration();
          _configuration.Name = name;
          _configuration.DevicePath = devicePath;
          _configuration.CardId = cardId;
          _configuration.Graph = Graph.CreateInstance(null);
        }
      }
      else
      {
        _configuration.Graph = Graph.CreateInstance(null);
      }
      return _configuration;
    }
 ///<summary>
 /// Constrcutor for the analog
 ///</summary>
 ///<param name="device">Tuner Device</param>
 public TvCardAnalog(DsDevice device)
   : base(device)
 {
   _parameters = new ScanParameters();
   _mapSubChannels = new Dictionary<int, BaseSubChannel>();
   _supportsSubChannels = true;
   _minChannel = 0;
   _maxChannel = 128;
   _camType = CamType.Default;
   _conditionalAccess = null;
   _cardType = CardType.Analog;
   _epgGrabbing = false;
   _configuration = Configuration.readConfiguration(_cardId, _name, _devicePath);
   Configuration.writeConfiguration(_configuration);
 }
    /// <summary>
    /// Builds the directshow graph for this analog tvcard
    /// </summary>
    public override void BuildGraph()
    {
      if (_cardId == 0)
      {
        GetPreloadBitAndCardId();
        _configuration = Configuration.readConfiguration(_cardId, _name, _devicePath);
        Configuration.writeConfiguration(_configuration);
      }
      _lastSignalUpdate = DateTime.MinValue;
      _tunerLocked = false;
      Log.Log.WriteFile("analog: build graph");
      try
      {
        if (_graphState != GraphState.Idle)
        {
          Log.Log.WriteFile("analog: Graph already build");
          throw new TvException("Graph already build");
        }
        //create a new filter graph
        _graphBuilder = (IFilterGraph2)new FilterGraph();
        _rotEntry = new DsROTEntry(_graphBuilder);
        _capBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
        _capBuilder.SetFiltergraph(_graphBuilder);
        Graph graph = _configuration.Graph;
        _tuner = new Tuner(_device);
        if (!_tuner.CreateFilterInstance(graph, _graphBuilder))
        {
          Log.Log.Error("analog: unable to add tv tuner filter");
          throw new TvException("Analog: unable to add tv tuner filter");
        }
        _minChannel = _tuner.MinChannel;
        _maxChannel = _tuner.MaxChannel;
        //add the wdm crossbar device and connect tvtuner->crossbar
        _crossbar = new Crossbar();
        if (!_crossbar.CreateFilterInstance(graph, _graphBuilder, _tuner))
        {
          Log.Log.Error("analog: unable to add tv crossbar filter");
          throw new TvException("Analog: unable to add tv crossbar filter");
        }
        //add the tv audio tuner device and connect it to the crossbar
        _tvAudio = new TvAudio();
        if (!_tvAudio.CreateFilterInstance(graph, _graphBuilder, _tuner, _crossbar))
        {
          Log.Log.Error("analog: unable to add tv audio tuner filter");
          throw new TvException("Analog: unable to add tv audio tuner filter");
        }
        //add the tv capture device and connect it to the crossbar
        _capture = new Capture();
        if (!_capture.CreateFilterInstance(graph, _capBuilder, _graphBuilder, _tuner, _crossbar, _tvAudio))
        {
          Log.Log.Error("analog: unable to add capture filter");
          throw new TvException("Analog: unable to add capture filter");
        }
        Configuration.writeConfiguration(_configuration);
        _teletext = new TeletextComponent();
        if (_capture.SupportsTeletext)
        {
          if (!_teletext.CreateFilterInstance(graph, _graphBuilder, _capture))
          {
            Log.Log.Error("analog: unable to setup teletext filters");
            throw new TvException("Analog: unable to setup teletext filters");
          }
        }
        Configuration.writeConfiguration(_configuration);
        _encoder = new Encoder();
        if (!_encoder.CreateFilterInstance(_graphBuilder, _tuner, _tvAudio, _crossbar, _capture))
        {
          Log.Log.Error("analog: unable to add encoding filter");
          throw new TvException("Analog: unable to add capture filter");
        }
        Log.Log.WriteFile("analog: Check quality control");
        _qualityControl = QualityControlFactory.createQualityControl(_configuration, _encoder.VideoEncoderFilter,
                                                                     _capture.VideoFilter, _encoder.MultiplexerFilter,
                                                                     _encoder.VideoCompressorFilter);
        if (_qualityControl == null)
        {
          Log.Log.WriteFile("analog: No quality control support found");
          //If a hauppauge analog card, set bitrate to default
          //As the graph is stopped, we don't need to pass in the deviceID
          //However, if we wish to change quality for a live graph, the deviceID must be passed in
          if (_tunerDevice != null && _capture.VideoFilter != null)
          {
            if (_capture.VideoCaptureName.Contains("Hauppauge"))
            {
              Hauppauge _hauppauge = new Hauppauge(_capture.VideoFilter, string.Empty);
              _hauppauge.SetStream(103);
              _hauppauge.SetAudioBitRate(384);
              _hauppauge.SetVideoBitRate(6000, 8000, true);
              int min, max;
              bool vbr;
              _hauppauge.GetVideoBitRate(out min, out max, out vbr);
              Log.Log.Write("Hauppauge set video parameters - Max kbps: {0}, Min kbps: {1}, VBR {2}", max, min, vbr);
              _hauppauge.Dispose();
              _hauppauge = null;
            }
          }
        }

        if (!AddTsFileSink())
        {
          throw new TvException("Analog: unable to add mpfilewriter");
        }
        Log.Log.WriteFile("analog: Graph is built");
        FilterGraphTools.SaveGraphFile(_graphBuilder, "analog.grf");
        ReloadCardConfiguration();
        _graphState = GraphState.Created;
      }
      catch (TvExceptionSWEncoderMissing ex)
      {
        Log.Log.Write(ex);
        Dispose();
        _graphState = GraphState.Idle;
        throw;
      }
      catch (Exception ex)
      {
        Log.Log.Write(ex);
        Dispose();
        _graphState = GraphState.Idle;
        throw new TvExceptionGraphBuildingFailed("Graph building failed", ex);
      }
    }