float MediaPlayerPrivate::currentTime() const
{
    if (!m_playBin)
        return 0;

    if (m_errorOccured)
        return 0;

    float ret = 0.0;

    GstQuery* query = gst_query_new_position(GST_FORMAT_TIME);
    if (!gst_element_query(m_playBin, query)) {
        LOG_VERBOSE(Media, "Position query failed...");
        gst_query_unref(query);
        return ret;
    }

    gint64 position;
    gst_query_parse_position(query, 0, &position);
    ret = (float) (position / 1000000000.0);
    LOG_VERBOSE(Media, "Position %" GST_TIME_FORMAT, GST_TIME_ARGS(position));

    gst_query_unref(query);

    return ret;
}
Пример #2
0
bool GstPipe::speed(gdouble speed) {
    g_debug("GstPipeliner::speed %f", speed);
    speed_ = speed;
    GstQuery *query;
    gboolean res;
    // query position
    query = gst_query_new_position(GST_FORMAT_TIME);
    res = gst_element_query(pipeline_, query);
    gint64 cur_pos = 0;
    if (res) {
        gst_query_parse_position(query, nullptr, &cur_pos);

        g_debug("cur pos = %" GST_TIME_FORMAT "\n", GST_TIME_ARGS(cur_pos));
    } else {
        g_warning("position query failed...");
    }
    gst_query_unref(query);
    gboolean ret;
    ret = gst_element_seek(pipeline_,
                           speed,
                           GST_FORMAT_TIME,
                           (GstSeekFlags) (GST_SEEK_FLAG_FLUSH |
                                           GST_SEEK_FLAG_ACCURATE),
                           GST_SEEK_TYPE_SET,
                           cur_pos, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);

    if (!ret)
        g_debug("speed not handled\n");
    return true;
}
Пример #3
0
static VALUE
position_initialize(VALUE self, VALUE format)
{
    GstQuery *query;

    query = gst_query_new_position(RVAL2GST_FORMAT(format));

    G_INITIALIZE(self, query);
    return Qnil;
}
unsigned MediaPlayerPrivateGStreamerBase::videoDecodedByteCount() const
{
    GstQuery* query = gst_query_new_position(GST_FORMAT_BYTES);
    gint64 position = 0;

    if (gst_element_query(m_webkitVideoSink.get(), query))
        gst_query_parse_position(query, 0, &position);

    gst_query_unref(query);
    return static_cast<unsigned>(position);
}
static void
test_position (InsanityTest * test, GstBuffer * buf)
{
  GstQuery *query;
  GstClockTimeDiff diff;

  if (GST_BUFFER_PTS_IS_VALID (buf) == FALSE)
    return;

  if (GST_CLOCK_TIME_IS_VALID (glob_first_pos_point) == FALSE) {
    glob_first_pos_point = gst_segment_to_stream_time (&glob_last_segment,
        glob_last_segment.format, GST_BUFFER_PTS (buf));
  }

  glob_expected_pos = gst_segment_to_stream_time (&glob_last_segment,
      glob_last_segment.format, GST_BUFFER_PTS (buf));

  diff = ABS (GST_CLOCK_DIFF (glob_expected_pos, glob_first_pos_point));

  if (diff < glob_playback_duration * GST_SECOND)
    return;

  query = gst_query_new_position (GST_FORMAT_TIME);

  if (gst_element_query (glob_pipeline, query)) {
    gint64 pos;
    GstFormat fmt;
    GstClockTimeDiff diff;

    gst_query_parse_position (query, &fmt, &pos);
    diff = ABS (GST_CLOCK_DIFF (glob_expected_pos, pos));

    if (diff <= POSITION_THRESHOLD) {
      insanity_test_validate_checklist_item (test, "position-detection", TRUE,
          NULL);
    } else {
      gchar *validate_msg = g_strdup_printf ("Found position: %" GST_TIME_FORMAT
          " expected: %" GST_TIME_FORMAT, GST_TIME_ARGS (pos),
          GST_TIME_ARGS (glob_expected_pos));

      insanity_test_validate_checklist_item (test, "position-detection",
          FALSE, validate_msg);

      g_free (validate_msg);
    }
  } else {
    LOG (test,
        "%s Does not handle position queries (position-detection \"SKIP\")",
        gst_element_factory_get_metadata (gst_element_get_factory
            (glob_demuxer), GST_ELEMENT_METADATA_LONGNAME));
  }

  next_test (test);
}
Пример #6
0
static void
fps_display_sink_init (GstFPSDisplaySink * self,
    GstFPSDisplaySinkClass * g_class)
{
  self->sync = FALSE;
  self->use_text_overlay = TRUE;
  self->video_sink = NULL;

  self->ghost_pad = gst_ghost_pad_new_no_target ("sink", GST_PAD_SINK);
  gst_element_add_pad (GST_ELEMENT (self), self->ghost_pad);

  self->query = gst_query_new_position (GST_FORMAT_TIME);
}
Пример #7
0
void LinVideoDisplayForm::updateProgress()
{
  if (ui->seekSlider->isSliderDown())
  {
    // The user is moving the slider, so don't update it:
    return;
  }

  GstQuery *query;

  // Determine the duration of the stream:
  gint64 duration = dataDialog->getDuration();

  if (duration == 0)
  {
    // Duration not available; no point in continuing any further.
    return;
  }

  gint64 position = 0;

  // Determine the position of the stream:

  query = gst_query_new_position(GST_FORMAT_TIME);

  if (gst_element_query(runningElement, query))
  {
    gst_query_parse_position(query, NULL, &position);
  }

  gst_query_unref(query);

  // Determine the percentage:
  int percentage = (position * 100) / duration;

/*
  QString percentString;
  percentString.setNum(percentage);
  percentString.append("%");
  ui->percentageLabel->setText(percentString);
*/
  ui->seekSlider->setValue(percentage);
}
float MediaPlayerPrivate::currentTime() const
{
    if (!m_playBin)
        return 0;
    // Necessary as sometimes, gstreamer return 0:00 at the EOS
    if (m_isEndReached)
        return m_endTime;

    float ret;

    GstQuery* query = gst_query_new_position(GST_FORMAT_TIME);
    if (gst_element_query(m_playBin, query)) {
        gint64 position;
        gst_query_parse_position(query, NULL, &position);
        ret = (float) (position / 1000000000.0);
        LOG_VERBOSE(Media, "Position %" GST_TIME_FORMAT, GST_TIME_ARGS(position));
    } else {
        LOG_VERBOSE(Media, "Position query failed...");
        ret = 0.0;
    }
    gst_query_unref(query);

    return ret;
}
Пример #9
0
void create_queries()
{
  GstQuery *query;

  /* POSITION */
  {
    GstFormat format;
    gint64 position;
		xmlfile = "gstquery_create_queries";
		std_log(LOG_FILENAME_LINE, "Test Started create_queries");
    query = gst_query_new_position (GST_FORMAT_TIME);
    fail_if (query == NULL);
    fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);

    gst_query_parse_position (query, &format, NULL);
    fail_if (format != GST_FORMAT_TIME);

    gst_query_set_position (query, GST_FORMAT_TIME, 0xdeadbeaf);

    gst_query_parse_position (query, &format, &position);
    fail_if (format != GST_FORMAT_TIME);
    fail_if (position != 0xdeadbeaf);

    gst_query_unref (query);
  }
  /* DURATION */
  {
    GstFormat format;
    gint64 duration;

    query = gst_query_new_duration (GST_FORMAT_TIME);
    fail_if (query == NULL);
    fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);

    gst_query_parse_duration (query, &format, NULL);
    fail_if (format != GST_FORMAT_TIME);

    gst_query_set_duration (query, GST_FORMAT_TIME, 0xdeadbeaf);

    gst_query_parse_duration (query, &format, &duration);
    fail_if (format != GST_FORMAT_TIME);
    fail_if (duration != 0xdeadbeaf);

    gst_query_unref (query);
  }
  {
    /* FIXME make tests for:
     *
     * LATENCY
     * JITTER
     * RATE
     * SEEKING
     * SEGMENT
     * CONVERT
     */
  }
  /* SEGMENT */
  {
    gdouble rate;
    GstFormat format;
    gint64 start, stop;

    format = GST_FORMAT_BYTES;
    query = gst_query_new_segment (format);

    fail_if (query == NULL);
    fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);

    gst_query_parse_segment (query, &rate, &format, &start, &stop);

    /* see if empty gives undefined formats */
    fail_if (rate != 0.0);
    fail_if (format != GST_FORMAT_BYTES);
    fail_if (start != -1);
    fail_if (stop != -1);

    /* change all values */
    gst_query_set_segment (query, 2.0, GST_FORMAT_TIME, 1 * GST_SECOND,
        3 * GST_SECOND);

    gst_query_parse_segment (query, &rate, &format, &start, &stop);

    /* see if the values were changed */
    fail_if (rate != 2.0);
    fail_if (format != GST_FORMAT_TIME);
    fail_if (start != 1 * GST_SECOND);
    fail_if (stop != 3 * GST_SECOND);

    gst_query_unref (query);
  }

  /* FORMATS */
  {
    guint size;
    GstFormat format;

    query = gst_query_new_formats ();
    fail_if (query == NULL);
    fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);

    /* empty */
    gst_query_parse_formats_length (query, &size);
    fail_if (size != 0);

    /* see if empty gives undefined formats */
    gst_query_parse_formats_nth (query, 0, &format);
    fail_if (format != GST_FORMAT_UNDEFINED);
    gst_query_parse_formats_nth (query, 1, &format);
    fail_if (format != GST_FORMAT_UNDEFINED);

    /* set 2 formats */
    gst_query_set_formats (query, 2, GST_FORMAT_TIME, GST_FORMAT_BYTES);

    gst_query_parse_formats_length (query, &size);
    fail_if (size != 2);

    format = GST_FORMAT_UNDEFINED;

    gst_query_parse_formats_nth (query, 0, &format);
    fail_if (format != GST_FORMAT_TIME);
    gst_query_parse_formats_nth (query, 1, &format);
    fail_if (format != GST_FORMAT_BYTES);

    /* out of bounds, should return UNDEFINED */
    gst_query_parse_formats_nth (query, 2, &format);
    fail_if (format != GST_FORMAT_UNDEFINED);

    /* overwrite with 3 formats */
    gst_query_set_formats (query, 3, GST_FORMAT_TIME, GST_FORMAT_BYTES,
        GST_FORMAT_PERCENT);

    gst_query_parse_formats_length (query, &size);
    fail_if (size != 3);

    gst_query_parse_formats_nth (query, 2, &format);
    fail_if (format != GST_FORMAT_PERCENT);

    /* create one from an array */
    {
      static GstFormat formats[] = {
        GST_FORMAT_TIME,
        GST_FORMAT_BYTES,
        GST_FORMAT_PERCENT
      };
      gst_query_set_formatsv (query, 3, formats);

      gst_query_parse_formats_length (query, &size);
      fail_if (size != 3);

      gst_query_parse_formats_nth (query, 0, &format);
      fail_if (format != GST_FORMAT_TIME);
      gst_query_parse_formats_nth (query, 2, &format);
      fail_if (format != GST_FORMAT_PERCENT);
    }
    gst_query_unref (query);
  }
	std_log(LOG_FILENAME_LINE, "Test Successful");
	create_xml(0);


}
Пример #10
0
void test_queries()
{
  GstBin *bin;
  GstElement *src, *sink;
  GstStateChangeReturn ret;
  GstPad *pad;
  GstQuery *dur, *pos;
	xmlfile = "gstquery_test_queries";
  std_log(LOG_FILENAME_LINE, "Test Started test_queries");
  fail_unless ((bin = (GstBin *) gst_pipeline_new (NULL)) != NULL,
      "Could not create pipeline");
  fail_unless ((src = gst_element_factory_make ("fakesrc", NULL)) != NULL,
      "Could not create fakesrc");
  g_object_set (src, "datarate", 200, "sizetype", 2, NULL);

  fail_unless ((sink = gst_element_factory_make ("fakesink", NULL)) != NULL,
      "Could not create fakesink");
  g_object_set (sink, "sync", TRUE, NULL);
  fail_unless ((dur = gst_query_new_duration (GST_FORMAT_BYTES)) != NULL,
      "Could not prepare duration query");
  fail_unless ((pos = gst_query_new_position (GST_FORMAT_BYTES)) != NULL,
      "Could not prepare position query");

  fail_unless (gst_bin_add (bin, src), "Could not add src to bin");
  fail_unless (gst_bin_add (bin, sink), "Could not add sink to bin");
  fail_unless (gst_element_link (src, sink), "could not link src and sink");

  ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
  fail_if (ret == GST_STATE_CHANGE_FAILURE, "Failed to set pipeline PLAYING");
  if (ret == GST_STATE_CHANGE_ASYNC)
    gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_CLOCK_TIME_NONE);

  /* Query the bin */
  fail_unless (gst_element_query (GST_ELEMENT (bin), pos),
      "Could not query pipeline position");
  fail_unless (gst_element_query (GST_ELEMENT (bin), dur),
      "Could not query pipeline duration");

  /* Query elements */
  fail_unless (gst_element_query (GST_ELEMENT (src), pos),
      "Could not query position of fakesrc");
  fail_unless (gst_element_query (GST_ELEMENT (src), pos),
      "Could not query duration of fakesrc");

  fail_unless (gst_element_query (GST_ELEMENT (sink), pos),
      "Could not query position of fakesink");
  fail_unless (gst_element_query (GST_ELEMENT (sink), pos),
      "Could not query duration of fakesink");

  /* Query pads */
  fail_unless ((pad = gst_element_get_pad (src, "src")) != NULL,
      "Could not get source pad of fakesrc");
  fail_unless (gst_pad_query (pad, pos),
      "Could not query position of fakesrc src pad");
  fail_unless (gst_pad_query (pad, dur),
      "Could not query duration of fakesrc src pad");
  gst_object_unref (pad);

  /* We don't query the sink pad of fakesink, it doesn't 
   * handle downstream queries atm, but it might later, who knows? */

  ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
  fail_if (ret == GST_STATE_CHANGE_FAILURE, "Failed to set pipeline NULL");
  if (ret == GST_STATE_CHANGE_ASYNC)
    gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_CLOCK_TIME_NONE);

  gst_query_unref (dur);
  gst_query_unref (pos);
  gst_object_unref (bin);
	std_log(LOG_FILENAME_LINE, "Test Successful");
	create_xml(0);

}
Пример #11
0
PositionQueryPtr PositionQuery::create(Format format)
{
    return PositionQueryPtr::wrap(gst_query_new_position(static_cast<GstFormat>(format)), false);
}