gboolean
gst_v4l2_tuner_set_frequency (GstV4l2Object * v4l2object,
    GstTunerChannel * channel, gulong frequency)
{
  GstV4l2TunerChannel *v4l2channel = GST_V4L2_TUNER_CHANNEL (channel);
  gint chan;

  /* assert that we're opened and that we're using a known item */
  g_return_val_if_fail (GST_V4L2_IS_OPEN (v4l2object), FALSE);
  g_return_val_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel,
          GST_TUNER_CHANNEL_FREQUENCY), FALSE);
  g_return_val_if_fail (gst_v4l2_tuner_contains_channel (v4l2object,
          v4l2channel), FALSE);

  if (v4l2object->get_in_out_func (v4l2object, &chan)) {
    if (chan == GST_V4L2_TUNER_CHANNEL (channel)->index &&
        GST_TUNER_CHANNEL_HAS_FLAG (channel, GST_TUNER_CHANNEL_FREQUENCY)) {
      if (gst_v4l2_set_frequency (v4l2object, v4l2channel->tuner, frequency)) {
        gst_tuner_frequency_changed (GST_TUNER (v4l2object->element), channel,
            frequency);
        return TRUE;
      }
    }
  }

  return FALSE;
}
Exemple #2
0
/******************************************************
 * gst_v4l2_set_frequency():
 *   set frequency
 * return value: TRUE on success, FALSE on error
 ******************************************************/
gboolean
gst_v4l2_set_frequency (GstV4l2Object * v4l2object,
    gint tunernum, gulong frequency)
{
  struct v4l2_frequency freq = { 0, };

  GstTunerChannel *channel;

  GST_DEBUG_OBJECT (v4l2object->element,
      "setting current tuner frequency to %lu", frequency);

  if (!GST_V4L2_IS_OPEN (v4l2object))
    return FALSE;

  channel = gst_tuner_get_channel (GST_TUNER (v4l2object->element));

  freq.tuner = tunernum;
  /* fill in type - ignore error */
  v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_FREQUENCY, &freq);
  freq.frequency = frequency / channel->freq_multiplicator;

  if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_S_FREQUENCY, &freq) < 0)
    goto freq_failed;

  return TRUE;

  /* ERRORS */
freq_failed:
  {
    GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
        (_("Failed to set current tuner frequency for device '%s' to %lu Hz."),
            v4l2object->videodev, frequency), GST_ERROR_SYSTEM);
    return FALSE;
  }
}
gboolean
gst_v4l2_tuner_set_norm (GstV4l2Object * v4l2object, GstTunerNorm * norm)
{
  GstV4l2TunerNorm *v4l2norm = GST_V4L2_TUNER_NORM (norm);

  /* assert that we're opened and that we're using a known item */
  g_return_val_if_fail (GST_V4L2_IS_OPEN (v4l2object), FALSE);
  g_return_val_if_fail (gst_v4l2_tuner_contains_norm (v4l2object, v4l2norm),
      FALSE);

  if (gst_v4l2_set_norm (v4l2object, v4l2norm->index)) {
    gst_tuner_norm_changed (GST_TUNER (v4l2object->element), norm);
    if (v4l2object->update_fps_func)
      v4l2object->update_fps_func (v4l2object);
    return TRUE;
  }

  return FALSE;

}
gboolean
gst_v4l2_tuner_set_channel (GstV4l2Object * v4l2object,
    GstTunerChannel * channel)
{
  GstV4l2TunerChannel *v4l2channel = GST_V4L2_TUNER_CHANNEL (channel);

  /* assert that we're opened and that we're using a known item */
  g_return_val_if_fail (GST_V4L2_IS_OPEN (v4l2object), FALSE);
  g_return_val_if_fail (gst_v4l2_tuner_contains_channel (v4l2object,
          v4l2channel), FALSE);

  if (v4l2object->set_in_out_func (v4l2object, v4l2channel->index)) {
    gst_tuner_channel_changed (GST_TUNER (v4l2object->element), channel);
    /* can FPS change here? */
    return TRUE;
  }

  return FALSE;

}
Exemple #5
0
static void
run_options (char opt)
{
  int res;

  switch (opt) {
    case 'f':
    {
      GstTuner *tuner = GST_TUNER (source);
      GstTunerChannel *channel;
      guint freq;

      channel = gst_tuner_get_channel (tuner);

      freq = gst_tuner_get_frequency (tuner, channel);

      printf ("\ntype the new frequency (current = %u) (-1 to cancel): ", freq);
      res = scanf ("%u", &freq);
      if (res != 1 || freq != -1)
        gst_tuner_set_frequency (tuner, channel, freq);
    }
      break;
    case 'n':
    {
      GstTuner *tuner = GST_TUNER (source);
      const GList *item, *list;
      const GstTunerNorm *current_norm;
      GstTunerNorm *norm = NULL;
      gint index, next_norm;


      list = gst_tuner_list_norms (tuner);

      current_norm = gst_tuner_get_norm (tuner);

      printf ("\nlist of norms:\n");
      for (item = list, index = 0; item != NULL; item = item->next, ++index) {
        norm = item->data;
        if (current_norm == norm) {
          printf (" * %u - %s\n", index, norm->label);
        } else {
          printf ("   %u - %s\n", index, norm->label);
        }
      }
      printf ("\ntype the number of norm you want (-1 to cancel): ");
      res = scanf ("%d", &next_norm);
      if (res != 1 || next_norm < 0) {
        break;
      }
      if (index <= next_norm) {
        printf ("Norm %d not available\n", next_norm);
        break;
      }
      for (item = list, index = 0; item != NULL && index <= next_norm;
          item = item->next, ++index) {
        norm = item->data;
      }
      if (norm)
        gst_tuner_set_norm (tuner, norm);
    }
      break;
    case 'i':
    {
      GstTuner *tuner = GST_TUNER (source);
      const GList *item, *list;
      const GstTunerChannel *current_channel;
      GstTunerChannel *channel = NULL;
      gint index, next_channel;


      list = gst_tuner_list_channels (tuner);

      current_channel = gst_tuner_get_channel (tuner);

      printf ("\nlist of inputs:\n");
      for (item = list, index = 0; item != NULL; item = item->next, ++index) {
        channel = item->data;
        if (current_channel == channel) {
          printf (" * %u - %s\n", index, channel->label);
        } else {
          printf ("   %u - %s\n", index, channel->label);
        }
      }
      printf ("\ntype the number of input you want (-1 to cancel): ");
      res = scanf ("%d", &next_channel);
      if (res != 1 || next_channel < 0) {
        break;
      }
      if (index <= next_channel) {
        printf ("Input %d not available\n", next_channel);
        break;
      }
      for (item = list, index = 0; item != NULL && index <= next_channel;
          item = item->next, ++index) {
        channel = item->data;
      }
      if (channel)
        gst_tuner_set_channel (tuner, channel);
    }
      break;
    case 'e':
      gst_element_set_state (pipeline, GST_STATE_NULL);
      g_main_loop_quit (loop);
      printf ("Bye\n");
      g_thread_exit (0);
      break;
    case 'c':
    {
      GstColorBalance *balance = GST_COLOR_BALANCE (source);
      const GList *controls;
      GstColorBalanceChannel *channel;
      const GList *item;
      gint index, new_value;

      controls = gst_color_balance_list_channels (balance);

      printf ("\n");

      if (controls == NULL) {
        printf ("There is no list of colorbalance controls\n");
        goto done;
      }

      if (controls) {
        printf ("list of controls:\n");
        for (item = controls, index = 0; item != NULL;
            item = item->next, ++index) {
          channel = item->data;
          printf ("   %u - %s (%d - %d) = %d\n", index, channel->label,
              channel->min_value, channel->max_value,
              gst_color_balance_get_value (balance, channel));
        }
        printf ("\ntype the number of color control you want (-1 to cancel): ");
        res = scanf ("%d", &new_value);
        if (res != 1 || new_value == -1)
          break;
        for (item = controls, index = 0; item != NULL && index <= new_value;
            item = item->next, ++index) {
          channel = item->data;
        }
        printf ("   %u - %s (%d - %d) = %d, type the new value: ", index - 1,
            channel->label, channel->min_value, channel->max_value,
            gst_color_balance_get_value (balance, channel));
        res = scanf ("%d", &new_value);
        if (res != 1 || new_value == -1)
          break;
        gst_color_balance_set_value (balance, channel, new_value);
      }
    }
    case 'v':
    {
      GstVideoOrientation *vidorient = GST_VIDEO_ORIENTATION (source);
      gboolean flip = FALSE;
      gint center = 0;

      printf ("\n");

      if (gst_video_orientation_get_hflip (vidorient, &flip)) {
        gint new_value;

        printf ("Horizontal flip is %s\n", flip ? "on" : "off");
        printf ("\ntype 1 to toggle (-1 to cancel): ");
        res = scanf ("%d", &new_value);
        if (res != 1 || new_value == 1) {
          flip = !flip;
          if (gst_video_orientation_set_hflip (vidorient, flip)) {
            gst_video_orientation_get_hflip (vidorient, &flip);
            printf ("Now horizontal flip is %s\n", flip ? "on" : "off");
          } else {
            printf ("Error toggling horizontal flip\n");
          }
        } else {
        }
      } else {
        printf ("Horizontal flip control not available\n");
      }

      if (gst_video_orientation_get_vflip (vidorient, &flip)) {
        gint new_value;

        printf ("\nVertical flip is %s\n", flip ? "on" : "off");
        printf ("\ntype 1 to toggle (-1 to cancel): ");
        res = scanf ("%d", &new_value);
        if (res != 1 || new_value == 1) {
          flip = !flip;
          if (gst_video_orientation_set_vflip (vidorient, flip)) {
            gst_video_orientation_get_vflip (vidorient, &flip);
            printf ("Now vertical flip is %s\n", flip ? "on" : "off");
          } else {
            printf ("Error toggling vertical flip\n");
          }
        } else {
        }
      } else {
        printf ("Vertical flip control not available\n");
      }

      if (gst_video_orientation_get_hcenter (vidorient, &center)) {
        printf ("Horizontal center is %d\n", center);
        printf ("\ntype the new horizontal center value (-1 to cancel): ");
        res = scanf ("%d", &center);
        if (res != 1 || center != -1) {
          if (gst_video_orientation_set_hcenter (vidorient, center)) {
            gst_video_orientation_get_hcenter (vidorient, &center);
            printf ("Now horizontal center is %d\n", center);
          } else {
            printf ("Error setting horizontal center\n");
          }
        } else {
        }
      } else {
        printf ("Horizontal center control not available\n");
      }

      if (gst_video_orientation_get_vcenter (vidorient, &center)) {
        printf ("Vertical center is %d\n", center);
        printf ("\ntype the new vertical center value (-1 to cancel): ");
        res = scanf ("%d", &center);
        if (res != 1 || center != -1) {
          if (gst_video_orientation_set_vcenter (vidorient, center)) {
            gst_video_orientation_get_vcenter (vidorient, &center);
            printf ("Now vertical center is %d\n", center);
          } else {
            printf ("Error setting vertical center\n");
          }
        } else {
        }
      } else {
        printf ("Vertical center control not available\n");
      }

    }
      break;
      break;
    default:
      if (opt != 10)
        printf ("error: invalid option %c", opt);
      break;
  }

done:

  return;

}