Exemple #1
0
static int
set_station_by_step (struct pvr_t *pvr, int step, int v4lAction)
{
  if (!pvr || !pvr->stationlist.list)
    return -1;

  if (pvr->stationlist.enabled >= abs (step))
  {
    int gotcha = 0;
    int chidx = pvr->chan_idx + step;

    while (!gotcha)
    {
      chidx = (chidx + pvr->stationlist.used) % pvr->stationlist.used;

      mp_msg (MSGT_OPEN, MSGL_DBG2,
              "%s Offset switch: current %d, enabled %d, step %d -> %d\n",
              LOG_LEVEL_V4L2, pvr->chan_idx,
              pvr->stationlist.enabled, step, chidx);

      if (!pvr->stationlist.list[chidx].enabled)
      {
        mp_msg (MSGT_OPEN, MSGL_DBG2,
                "%s Switch disabled to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2,
                pvr->stationlist.list[chidx].name,
                pvr->stationlist.list[chidx].freq,
                pvr->stationlist.list[chidx].station);
        chidx += FFSIGN (step);
      }
      else
        gotcha = 1;
    }

    pvr->freq = pvr->stationlist.list[chidx].freq;
    pvr->chan_idx_last = pvr->chan_idx;
    pvr->chan_idx = chidx;

    mp_msg (MSGT_OPEN, MSGL_INFO,
            "%s Switch to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2,
            pvr->stationlist.list[chidx].name,
            pvr->stationlist.list[chidx].freq,
            pvr->stationlist.list[chidx].station);

    if (v4lAction)
      return set_v4l2_freq (pvr);

    return (pvr->freq > 0) ? 0 : -1;
  }

  mp_msg (MSGT_OPEN, MSGL_ERR,
          "%s Ooops couldn't set freq by channel entry step %d to current %d, enabled %d\n", LOG_LEVEL_V4L2,
          step, pvr->chan_idx, pvr->stationlist.enabled);

  return -1;
}
Exemple #2
0
static int
force_freq_step (struct pvr_t *pvr, int step)
{
  int freq;

  if (!pvr)
    return -1;

  freq = pvr->freq+step;

  if (freq)
  {
    MP_INFO(pvr, "%s Force Frequency %d + %d = %d \n", LOG_LEVEL_V4L2,
            pvr->freq, step, freq);

    pvr->freq = freq;

    return set_v4l2_freq (pvr);
  }

  return -1;
}
Exemple #3
0
static int
set_station_by_channelname_or_freq (struct pvr_t *pvr, const char *channel,
                                    int freq, int v4lAction)
{
  int i = 0;

  if (!pvr || !pvr->stationlist.list)
    return -1;

  if (0 >= pvr->stationlist.enabled)
  {
    mp_msg (MSGT_OPEN, MSGL_WARN,
            "%s No enabled station, cannot switch channel/frequency\n",
            LOG_LEVEL_V4L2);
    return -1;
  }

  if (channel)
  {
    /* select by channel */
    for (i = 0; i < pvr->stationlist.used ; i++)
    {
      if (!strcasecmp (pvr->stationlist.list[i].name, channel))
      {
        if (!pvr->stationlist.list[i].enabled)
        {
          mp_msg (MSGT_OPEN, MSGL_WARN,
                  "%s Switch disabled to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2,
                  pvr->stationlist.list[i].name,
                  pvr->stationlist.list[i].freq,
                  pvr->stationlist.list[i].station);

          return -1;
        }

        pvr->freq = pvr->stationlist.list[i].freq;
        pvr->chan_idx_last = pvr->chan_idx;
        pvr->chan_idx = i;
        break;
      }
    }
  }
  else if (freq >= 0)
  {
    /* select by freq */
    for (i = 0; i < pvr->stationlist.used; i++)
    {
      if (pvr->stationlist.list[i].freq == freq)
      {
        if (!pvr->stationlist.list[i].enabled)
        {
          mp_msg (MSGT_OPEN, MSGL_WARN,
                  "%s Switch disabled to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2,
                  pvr->stationlist.list[i].name,
                  pvr->stationlist.list[i].freq,
                  pvr->stationlist.list[i].station);

          return -1;
        }

        pvr->freq = pvr->stationlist.list[i].freq;
        pvr->chan_idx_last = pvr->chan_idx;
        pvr->chan_idx = i;
        break;
      }
    }
  }

  if (i >= pvr->stationlist.used)
  {
    if (channel)
      mp_msg (MSGT_OPEN, MSGL_WARN,
              "%s unable to find channel %s\n", LOG_LEVEL_V4L2, channel);
    else
      mp_msg (MSGT_OPEN, MSGL_WARN,
              "%s unable to find frequency %d\n", LOG_LEVEL_V4L2, freq);
    return -1;
  }

  mp_msg (MSGT_OPEN, MSGL_INFO,
          "%s Switch to user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2,
          pvr->stationlist.list[i].name,
          pvr->stationlist.list[i].freq,
          pvr->stationlist.list[i].station);

  if (v4lAction)
    return set_v4l2_freq (pvr);

  return (pvr->freq > 0) ? 0 : -1;
}
Exemple #4
0
static int
set_v4l2_settings (struct pvr_t *pvr)
{
  if (!pvr)
    return -1;

  if (pvr->dev_fd < 0)
    return -1;

  /* -tv noaudio */
  if (pvr->mute)
  {
    struct v4l2_control ctrl;
    ctrl.id = V4L2_CID_AUDIO_MUTE;
    ctrl.value = 1;
    if (ioctl (pvr->dev_fd, VIDIOC_S_CTRL, &ctrl) < 0)
    {
      mp_msg (MSGT_OPEN, MSGL_ERR,
              "%s can't mute (%s).\n", LOG_LEVEL_V4L2, strerror (errno));
      return -1;
    }
  }

  /* -tv input=x */
  if (pvr->input != 0)
  {
    if (ioctl (pvr->dev_fd, VIDIOC_S_INPUT, &pvr->input) < 0)
    {
      mp_msg (MSGT_OPEN, MSGL_ERR,
              "%s can't set input (%s)\n", LOG_LEVEL_V4L2, strerror (errno));
      return -1;
    }
  }

  /* -tv normid=x */
  if (pvr->normid != -1)
  {
    struct v4l2_standard std;
    std.index = pvr->normid;

    if (ioctl (pvr->dev_fd, VIDIOC_ENUMSTD, &std) < 0)
    {
      mp_msg (MSGT_OPEN, MSGL_ERR,
              "%s can't set norm (%s)\n", LOG_LEVEL_V4L2, strerror (errno));
      return -1;
    }

    mp_msg (MSGT_OPEN, MSGL_V,
            "%s set norm to %s\n", LOG_LEVEL_V4L2, std.name);

    if (ioctl (pvr->dev_fd, VIDIOC_S_STD, &std.id) < 0)
    {
      mp_msg (MSGT_OPEN, MSGL_ERR,
              "%s can't set norm (%s)\n", LOG_LEVEL_V4L2, strerror (errno));
      return -1;
    }
  }

  /* -tv brightness=x */
  if (pvr->brightness != 0)
  {
    struct v4l2_control ctrl;
    ctrl.id = V4L2_CID_BRIGHTNESS;
    ctrl.value = pvr->brightness;

    if (ctrl.value < 0)
      ctrl.value = 0;
    if (ctrl.value > 255)
      ctrl.value = 255;

    if (ioctl (pvr->dev_fd, VIDIOC_S_CTRL, &ctrl) < 0)
    {
      mp_msg (MSGT_OPEN, MSGL_ERR,
              "%s can't set brightness to %d (%s).\n",
              LOG_LEVEL_V4L2, ctrl.value, strerror (errno));
      return -1;
    }
  }

  /* -tv contrast=x */
  if (pvr->contrast != 0)
  {
    struct v4l2_control ctrl;
    ctrl.id = V4L2_CID_CONTRAST;
    ctrl.value = pvr->contrast;

    if (ctrl.value < 0)
      ctrl.value = 0;
    if (ctrl.value > 127)
      ctrl.value = 127;

    if (ioctl (pvr->dev_fd, VIDIOC_S_CTRL, &ctrl) < 0)
    {
      mp_msg (MSGT_OPEN, MSGL_ERR,
              "%s can't set contrast to %d (%s).\n",
              LOG_LEVEL_V4L2, ctrl.value, strerror (errno));
      return -1;
    }
  }

  /* -tv hue=x */
  if (pvr->hue != 0)
  {
    struct v4l2_control ctrl;
    ctrl.id = V4L2_CID_HUE;
    ctrl.value = pvr->hue;

    if (ctrl.value < -128)
      ctrl.value = -128;
    if (ctrl.value > 127)
      ctrl.value = 127;

    if (ioctl (pvr->dev_fd, VIDIOC_S_CTRL, &ctrl) < 0)
    {
      mp_msg (MSGT_OPEN, MSGL_ERR,
              "%s can't set hue to %d (%s).\n",
              LOG_LEVEL_V4L2, ctrl.value, strerror (errno));
      return -1;
    }
  }

  /* -tv saturation=x */
  if (pvr->saturation != 0)
  {
    struct v4l2_control ctrl;
    ctrl.id = V4L2_CID_SATURATION;
    ctrl.value = pvr->saturation;

    if (ctrl.value < 0)
      ctrl.value = 0;
    if (ctrl.value > 127)
      ctrl.value = 127;

    if (ioctl (pvr->dev_fd, VIDIOC_S_CTRL, &ctrl) < 0)
    {
      mp_msg (MSGT_OPEN, MSGL_ERR,
              "%s can't set saturation to %d (%s).\n",
              LOG_LEVEL_V4L2, ctrl.value, strerror (errno));
      return -1;
    }
  }

  /* -tv width=x:height=y */
  if (pvr->width && pvr->height)
  {
    struct v4l2_format vfmt;
    vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    vfmt.fmt.pix.width = pvr->width;
    vfmt.fmt.pix.height = pvr->height;

    if (ioctl (pvr->dev_fd, VIDIOC_S_FMT, &vfmt) < 0)
    {
      mp_msg (MSGT_OPEN, MSGL_ERR,
              "%s can't set resolution to %dx%d (%s).\n",
              LOG_LEVEL_V4L2, pvr->width, pvr->height, strerror (errno));
      return -1;
    }
  }

  if (pvr->freq < 0)
  {
    int freq = get_v4l2_freq (pvr);
    mp_msg (MSGT_OPEN, MSGL_INFO,
            "%s Using current set frequency %d, to set channel\n",
            LOG_LEVEL_V4L2, freq);

    if (0 < freq)
      return set_station_by_channelname_or_freq (pvr, NULL, freq, 1);
  }

  if (0 < pvr->freq)
    return set_v4l2_freq (pvr) ;

  return 0;
}