📄 gstpipeline.c
字号:
GstClockTime observed, lower, upper, base, stream; GstClock *clock; pipeline = gst_element_factory_make ("pipeline", "pipeline"); fakesrc = gst_element_factory_make ("fakesrc", "fakesrc"); fakesink = gst_element_factory_make ("fakesink", "fakesink"); fail_unless (pipeline && fakesrc && fakesink, "couldn't make elements"); g_object_set (fakesrc, "is-live", (gboolean) TRUE, NULL); gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL); gst_element_link (fakesrc, fakesink); sink = gst_element_get_pad (fakesink, "sink"); gst_pad_add_buffer_probe (sink, G_CALLBACK (sink_pad_probe), &observed); fail_unless (gst_element_set_state (pipeline, GST_STATE_PAUSED) == GST_STATE_CHANGE_NO_PREROLL, "expected no-preroll from live pipeline"); clock = gst_system_clock_obtain (); fail_unless (clock && GST_IS_CLOCK (clock), "i want a clock dammit"); gst_pipeline_use_clock (GST_PIPELINE (pipeline), clock); fail_unless (gst_pipeline_get_last_stream_time (GST_PIPELINE (pipeline)) == 0, "stream time doesn't start off at 0"); probe_lock = g_mutex_new (); probe_cond = g_cond_new (); /* test the first: that base time is being distributed correctly, timestamps are correct relative to the running clock and base time */ { lower = gst_clock_get_time (clock); observed = GST_CLOCK_TIME_NONE; gst_element_set_state (pipeline, GST_STATE_PLAYING); fail_unless (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_SUCCESS, "failed state change"); g_mutex_lock (probe_lock); while (observed == GST_CLOCK_TIME_NONE) g_cond_wait (probe_cond, probe_lock); g_mutex_unlock (probe_lock); /* now something a little more than lower was distributed as the base time, * and the buffer was timestamped between 0 and upper-base */ base = gst_element_get_base_time (pipeline); fail_if (base == GST_CLOCK_TIME_NONE); /* set stream time */ gst_element_set_state (pipeline, GST_STATE_PAUSED); /* pulling upper here makes sure that the pipeline's new stream time has already been computed */ upper = gst_clock_get_time (clock); fail_unless (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_NO_PREROLL, "failed state change"); fail_if (observed == GST_CLOCK_TIME_NONE, "no timestamp recorded"); fail_unless (base >= lower, "early base time: %" GST_TIME_FORMAT " < %" GST_TIME_FORMAT, GST_TIME_ARGS (base), GST_TIME_ARGS (lower)); fail_unless (upper >= base, "bogus base time: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT, GST_TIME_ARGS (base), GST_TIME_ARGS (upper)); stream = gst_pipeline_get_last_stream_time (GST_PIPELINE (pipeline)); fail_unless (stream > 0, "bogus new stream time: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT, GST_TIME_ARGS (stream), GST_TIME_ARGS (0)); fail_unless (stream <= upper, "bogus new stream time: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT, GST_TIME_ARGS (stream), GST_TIME_ARGS (upper)); fail_unless (observed <= stream, "timestamps outrun stream time: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT, GST_TIME_ARGS (observed), GST_TIME_ARGS (stream)); fail_unless (observed >= 0, "early timestamp: %" GST_TIME_FORMAT " < %" GST_TIME_FORMAT, GST_TIME_ARGS (observed), GST_TIME_ARGS (lower - base)); fail_unless (observed <= upper - base, "late timestamp: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT, GST_TIME_ARGS (observed), GST_TIME_ARGS (upper - base)); } /* test the second: that the base time is redistributed when we go to PLAYING again */ { GstClockID clock_id; GstClockTime oldbase = base, oldstream = stream; /* let some time pass */ clock_id = gst_clock_new_single_shot_id (clock, upper + WAIT_TIME); fail_unless (gst_clock_id_wait (clock_id, NULL) == GST_CLOCK_OK, "unexpected clock_id_wait return"); gst_clock_id_unref (clock_id); lower = gst_clock_get_time (clock); fail_if (lower == GST_CLOCK_TIME_NONE); observed = GST_CLOCK_TIME_NONE; fail_unless (lower >= upper + WAIT_TIME, "clock did not advance?"); gst_element_set_state (pipeline, GST_STATE_PLAYING); fail_unless (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_SUCCESS, "failed state change"); g_mutex_lock (probe_lock); while (observed == GST_CLOCK_TIME_NONE) g_cond_wait (probe_cond, probe_lock); g_mutex_unlock (probe_lock); /* now the base time should have advanced by more than WAIT_TIME compared * to what it was. The buffer will be timestamped between the last stream * time and upper minus base. */ base = gst_element_get_base_time (pipeline); fail_if (base == GST_CLOCK_TIME_NONE); /* set stream time */ gst_element_set_state (pipeline, GST_STATE_PAUSED); /* new stream time already set */ upper = gst_clock_get_time (clock); fail_unless (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_NO_PREROLL, "failed state change"); fail_if (observed == GST_CLOCK_TIME_NONE, "no timestamp recorded"); stream = gst_pipeline_get_last_stream_time (GST_PIPELINE (pipeline)); fail_unless (base >= oldbase + WAIT_TIME, "base time not reset"); fail_unless (upper >= base + stream, "bogus base time: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT, GST_TIME_ARGS (base), GST_TIME_ARGS (upper)); fail_unless (lower >= base); fail_unless (observed >= lower - base, "early timestamp: %" GST_TIME_FORMAT " < %" GST_TIME_FORMAT, GST_TIME_ARGS (observed), GST_TIME_ARGS (lower - base)); fail_unless (observed <= upper - base, "late timestamp: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT, GST_TIME_ARGS (observed), GST_TIME_ARGS (upper - base)); fail_unless (stream - oldstream <= upper - lower, "insufficient stream time: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT, GST_TIME_ARGS (observed), GST_TIME_ARGS (upper)); } /* test the third: that if I set CLOCK_TIME_NONE as the stream time, that the base time is not changed */ { GstClockID clock_id; GstClockTime oldbase = base, oldobserved = observed; GstClockReturn ret; /* let some time pass */ clock_id = gst_clock_new_single_shot_id (clock, upper + WAIT_TIME); ret = gst_clock_id_wait (clock_id, NULL); fail_unless (ret == GST_CLOCK_OK, "unexpected clock_id_wait return %d", ret); gst_clock_id_unref (clock_id); lower = gst_clock_get_time (clock); observed = GST_CLOCK_TIME_NONE; fail_unless (lower >= upper + WAIT_TIME, "clock did not advance?"); /* bling */ gst_pipeline_set_new_stream_time (GST_PIPELINE (pipeline), GST_CLOCK_TIME_NONE); gst_element_set_state (pipeline, GST_STATE_PLAYING); fail_unless (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_SUCCESS, "failed state change"); g_mutex_lock (probe_lock); while (observed == GST_CLOCK_TIME_NONE) g_cond_wait (probe_cond, probe_lock); g_mutex_unlock (probe_lock); /* now the base time should be the same as it was, and the timestamp should * be more than WAIT_TIME past what it was. */ base = gst_element_get_base_time (pipeline); /* set stream time */ gst_element_set_state (pipeline, GST_STATE_PAUSED); /* new stream time already set */ upper = gst_clock_get_time (clock); fail_unless (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_NO_PREROLL, "failed state change"); fail_if (observed == GST_CLOCK_TIME_NONE, "no timestamp recorded"); fail_unless (gst_pipeline_get_last_stream_time (GST_PIPELINE (pipeline)) == GST_CLOCK_TIME_NONE, "stream time was reset"); fail_unless (base == oldbase, "base time was reset"); fail_unless (observed >= lower - base, "early timestamp: %" GST_TIME_FORMAT " < %" GST_TIME_FORMAT, GST_TIME_ARGS (observed), GST_TIME_ARGS (lower - base)); fail_unless (observed <= upper - base, "late timestamp: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT, GST_TIME_ARGS (observed), GST_TIME_ARGS (upper - base)); fail_unless (observed - oldobserved >= WAIT_TIME, "insufficient tstamp delta: %" GST_TIME_FORMAT " > %" GST_TIME_FORMAT, GST_TIME_ARGS (observed), GST_TIME_ARGS (oldobserved)); } gst_object_unref (sink); gst_object_unref (clock); gst_object_unref (pipeline);}GST_END_TEST;Suite *gst_pipeline_suite (void){ Suite *s = suite_create ("GstPipeline"); TCase *tc_chain = tcase_create ("pipeline tests"); tcase_set_timeout (tc_chain, 0); suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_async_state_change_empty); tcase_add_test (tc_chain, test_async_state_change_fake_ready); tcase_add_test (tc_chain, test_async_state_change_fake); tcase_add_test (tc_chain, test_get_bus); tcase_add_test (tc_chain, test_bus); tcase_add_test (tc_chain, test_base_time); return s;}GST_CHECK_MAIN (gst_pipeline);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -