[gstreamermm: 138/167] added tests - check seeking



commit 9e5ce603fac6a98b68d6cbf1f7c92e9176d0d23a
Author: Marcin Kolny [loganek] <marcin kolny gmail com>
Date:   Mon Aug 5 23:31:34 2013 +0200

    added tests - check seeking

 .gitignore                                        |    1 +
 tests/Makefile.am                                 |    4 +-
 tests/regression/test-regression-seekonstartup.cc |  161 +++++++++++++++++++++
 3 files changed, 165 insertions(+), 1 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index eacc9c1..2f0a742 100644
--- a/.gitignore
+++ b/.gitignore
@@ -480,6 +480,7 @@ test-plugin-pushsrc
 test-plugin-register
 
 test-regression-rewritefile
+test-regression-seekonstartup
 test-regression-videoduration
 
 # tools/
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4ecaf72..7a8f368 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,7 +24,8 @@ check_PROGRAMS = test-caps test-buffer test-bus test-caps test-pad \
                  test-ghostpad \
                  test-query test-structure test-taglist test-plugin-appsink \
                  test-plugin-appsrc test-plugin-register test-plugin-pushsrc \
-                 test-regression-rewritefile test-regression-videoduration
+                 test-regression-rewritefile test-regression-seekonstartup \
+                 test-regression-videoduration
 
 # Include run of test programs in check:
 TESTS = $(check_PROGRAMS)
@@ -46,4 +47,5 @@ test_plugin_pushsrc_SOURCES                   = plugins/test-plugin-pushsrc.cc 
$(TEST_MAIN_SOURC
 test_plugin_register_SOURCES           = plugins/test-plugin-register.cc $(TEST_MAIN_SOURCE)
 
 test_regression_rewritefile_SOURCES = regression/test-regression-rewritefile.cc $(TEST_MAIN_SOURCE) 
$(TEST_REGRESSION_UTILS)
+test_regression_seekonstartup_SOURCES = regression/test-regression-seekonstartup.cc $(TEST_MAIN_SOURCE) 
$(TEST_REGRESSION_UTILS)
 test_regression_videoduration_SOURCES = regression/test-regression-videoduration.cc $(TEST_MAIN_SOURCE) 
$(TEST_REGRESSION_UTILS)
diff --git a/tests/regression/test-regression-seekonstartup.cc 
b/tests/regression/test-regression-seekonstartup.cc
new file mode 100644
index 0000000..6e38a9b
--- /dev/null
+++ b/tests/regression/test-regression-seekonstartup.cc
@@ -0,0 +1,161 @@
+/*
+ * test-regression-seekonstartup.cc
+ *
+ *  Created on: 5 sie 2013
+ *      Author: loganek
+ */
+
+#include <gtest/gtest.h>
+#include <gstreamermm.h>
+#include <gstreamermm/fakesink.h>
+#include <glibmm.h>
+#include "utils.h"
+
+using namespace Gst;
+using Glib::RefPtr;
+
+RefPtr<Glib::MainLoop> mainloop;
+RefPtr<Bus> bus;
+RefPtr<Pipeline> pipeline;
+RefPtr<Pad> sink_pad;
+static volatile gint counter;
+bool prerolled = false;
+bool was_check = false;
+
+bool on_timeout()
+{
+    gint64 pos;
+
+    if (pipeline->query_position(FORMAT_TIME, pos))
+    {
+        EXPECT_EQ(2000000000, pos);
+        g_atomic_int_set(&was_check, 1);
+        was_check = true;
+
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+void dec_counter()
+{
+    if (prerolled)
+        return;
+
+    if (g_atomic_int_dec_and_test (&counter))
+    {
+        prerolled = true;
+        bus->post(MessageApplication::create(pipeline));
+    }
+}
+
+PadProbeReturn cb_blocked (const RefPtr <Pad>& pad, const PadProbeInfo& info)
+{
+  if (prerolled)
+    return PAD_PROBE_REMOVE;
+
+  dec_counter();
+
+  return PAD_PROBE_OK;
+}
+
+bool on_bus_message(const RefPtr<Bus>&, const Glib::RefPtr<Message>& message)
+{
+    switch(message->get_message_type())
+    {
+        case MESSAGE_EOS:
+            mainloop->quit();
+            return false;
+        case MESSAGE_ERROR:
+        {
+            mainloop->quit();
+            return false;
+        }
+        case GST_MESSAGE_APPLICATION:
+        {
+            pipeline->seek(1.0, FORMAT_TIME,
+                    (SeekFlags)(SEEK_FLAG_FLUSH | SEEK_FLAG_ACCURATE),
+                    SEEK_TYPE_SET, 2 * SECOND,
+                    SEEK_TYPE_SET, 3 * SECOND);
+              pipeline->set_state(STATE_PLAYING);
+
+            break;
+          }
+        default:
+            break;
+    }
+    return true;
+}
+
+void on_pad_added(const RefPtr<Pad>& newPad)
+{
+    if (prerolled)
+        return;
+
+    g_atomic_int_inc(&counter);
+
+    newPad->add_probe(PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, sigc::ptr_fun(&cb_blocked));
+
+    PadLinkReturn ret = newPad->link(sink_pad);
+
+    ASSERT_TRUE(PAD_LINK_OK == ret || PAD_LINK_WAS_LINKED == ret);
+}
+
+void no_more_pads()
+{
+    if (prerolled)
+        return;
+
+    dec_counter();
+}
+
+TEST(RegressionSeekOnStartupTest, SeekToPositionWhenPipelineStarts)
+{
+    Glib::ustring input_filename = "test.ogg";
+
+    GenerateSampleOggFile(100, input_filename);
+
+    mainloop = Glib::MainLoop::create();
+    pipeline = Pipeline::create("seekonstartup-pipeline");
+    ASSERT_TRUE(pipeline);
+    bus = pipeline->get_bus();
+    ASSERT_TRUE(bus);
+    bus->add_watch(sigc::ptr_fun(&on_bus_message));
+
+    RefPtr<Element> src = ElementFactory::create_element("uridecodebin"),
+            csp = ElementFactory::create_element("videoconvert"),
+            vs = ElementFactory::create_element("videoscale"),
+            sink = ElementFactory::create_element("autovideosink");
+
+    ASSERT_TRUE(src);
+    ASSERT_TRUE(csp);
+    ASSERT_TRUE(vs);
+    ASSERT_TRUE(sink);
+
+    src->set_property("uri", Glib::ustring("file:///home/loganek/test.ogg"));
+
+    ASSERT_NO_THROW(pipeline->add(src)->add(csp)->add(vs)->add(sink));
+    ASSERT_NO_THROW(csp->link(vs)->link(sink));
+
+    sink_pad = csp->get_static_pad("sink");
+
+    g_atomic_int_set(&counter, 1);
+
+    src->signal_pad_added().connect(sigc::ptr_fun(&on_pad_added));
+    src->signal_no_more_pads().connect(sigc::ptr_fun(&no_more_pads));
+
+    pipeline->set_state(STATE_PAUSED);
+
+    Glib::signal_timeout().connect(sigc::ptr_fun(&on_timeout), 0);
+    mainloop->run();
+
+    pipeline->set_state(Gst::STATE_NULL);
+
+    ASSERT_TRUE(was_check);
+
+    remove(input_filename.c_str());
+}
+
+
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]