| 1 |
/* |
| 2 |
* test-integration-seekonstartup.cc |
| 3 |
* |
| 4 |
* Created on: 5 sie 2013 |
| 5 |
* Author: loganek |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "mmtest.h" |
| 9 |
#include <gstreamermm.h> |
| 10 |
#include <gstreamermm/fakesink.h> |
| 11 |
#include <glibmm/main.h> |
| 12 |
#include "utils.h" |
| 13 |
|
| 14 |
using namespace Gst; |
| 15 |
using Glib::RefPtr; |
| 16 |
|
| 17 |
RefPtr<Glib::MainLoop> mainloop; |
| 18 |
RefPtr<Bus> bus; |
| 19 |
RefPtr<Pipeline> pipeline; |
| 20 |
RefPtr<Pad> sink_pad; |
| •21 |
static gint counter; |
| 22 |
bool prerolled = false; |
| 23 |
gboolean was_check = 0; |
| 24 |
|
| 25 |
bool on_timeout() |
| 26 |
{ |
| 27 |
gint64 pos; |
| 28 |
|
| 29 |
if (pipeline->query_position(FORMAT_TIME, pos)) |
| 30 |
{ |
| 31 |
EXPECT_EQ(2000000000, pos); |
| 32 |
g_atomic_int_set(&was_check, 1); |
| 33 |
was_check = true; |
| 34 |
|
| 35 |
return FALSE; |
| 36 |
} |
| 37 |
|
| 38 |
return TRUE; |
| 39 |
} |
| 40 |
|
| 41 |
void dec_counter() |
| 42 |
{ |
| 43 |
if (prerolled) |
| 44 |
return; |
| 45 |
|
| 46 |
if (g_atomic_int_dec_and_test (&counter)) |
| 47 |
{ |
| 48 |
prerolled = true; |
| 49 |
bus->post(MessageApplication::create(pipeline, Structure("empty"))); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
PadProbeReturn cb_blocked (const RefPtr <Pad>& /* pad */, const PadProbeInfo& /* info */) |
| 54 |
{ |
| 55 |
if (prerolled) |
| 56 |
return PAD_PROBE_REMOVE; |
| 57 |
|
| 58 |
dec_counter(); |
| 59 |
|
| 60 |
return PAD_PROBE_OK; |
| 61 |
} |
| 62 |
|
| 63 |
bool on_bus_message(const RefPtr<Bus>&, const Glib::RefPtr<Message>& message) |
| 64 |
{ |
| 65 |
switch(message->get_message_type()) |
| 66 |
{ |
| 67 |
case MESSAGE_EOS: |
| 68 |
mainloop->quit(); |
| 69 |
return false; |
| 70 |
case MESSAGE_ERROR: |
| 71 |
mainloop->quit(); |
| 72 |
return false; |
| 73 |
case GST_MESSAGE_APPLICATION: |
| 74 |
pipeline->seek(1.0, FORMAT_TIME, |
| 75 |
(SeekFlags)(SEEK_FLAG_FLUSH | SEEK_FLAG_ACCURATE), |
| 76 |
SEEK_TYPE_SET, 2 * SECOND, |
| 77 |
SEEK_TYPE_SET, 3 * SECOND); |
| 78 |
pipeline->set_state(STATE_PLAYING); |
| 79 |
break; |
| 80 |
default: |
| 81 |
break; |
| 82 |
} |
| 83 |
|
| 84 |
return true; |
| 85 |
} |
| 86 |
|
| 87 |
void on_pad_added(const RefPtr<Pad>& newPad) |
| 88 |
{ |
| 89 |
if (prerolled) |
| 90 |
return; |
| 91 |
|
| 92 |
g_atomic_int_inc(&counter); |
| 93 |
|
| 94 |
newPad->add_probe(PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, sigc::ptr_fun(&cb_blocked)); |
| 95 |
|
| 96 |
PadLinkReturn ret = newPad->link(sink_pad); |
| 97 |
|
| 98 |
MM_ASSERT_TRUE(PAD_LINK_OK == ret || PAD_LINK_WAS_LINKED == ret); |
| 99 |
} |
| 100 |
|
| 101 |
void no_more_pads() |
| 102 |
{ |
| 103 |
if (prerolled) |
| 104 |
return; |
| 105 |
|
| 106 |
dec_counter(); |
| 107 |
} |
| 108 |
|
| 109 |
TEST(IntegrationSeekOnStartupTest, SeekToPositionWhenPipelineStarts) |
| 110 |
{ |
| 111 |
Glib::ustring input_filename = "seek-on-startup-test.ogg"; |
| 112 |
|
| 113 |
GenerateSampleOggFile(100, input_filename); |
| 114 |
|
| 115 |
mainloop = Glib::MainLoop::create(); |
| 116 |
pipeline = Pipeline::create("seekonstartup-pipeline"); |
| 117 |
MM_ASSERT_TRUE(pipeline); |
| 118 |
bus = pipeline->get_bus(); |
| 119 |
MM_ASSERT_TRUE(bus); |
| 120 |
bus->add_watch(sigc::ptr_fun(&on_bus_message)); |
| 121 |
|
| 122 |
RefPtr<Element> src = ElementFactory::create_element("uridecodebin"), |
| 123 |
csp = ElementFactory::create_element("videoconvert"), |
| 124 |
vs = ElementFactory::create_element("videoscale"), |
| 125 |
sink = ElementFactory::create_element("ximagesink"); |
| 126 |
|
| 127 |
MM_ASSERT_TRUE(src); |
| 128 |
MM_ASSERT_TRUE(csp); |
| 129 |
MM_ASSERT_TRUE(vs); |
| 130 |
MM_ASSERT_TRUE(sink); |
| 131 |
|
| 132 |
ASSERT_NO_THROW(src->set_property("uri", URIHandler::filename_to_uri(input_filename))); |
| 133 |
|
| 134 |
ASSERT_NO_THROW(pipeline->add(src)->add(csp)->add(vs)->add(sink)); |
| 135 |
ASSERT_NO_THROW(csp->link(vs)->link(sink)); |
| 136 |
|
| 137 |
sink_pad = csp->get_static_pad("sink"); |
| 138 |
|
| 139 |
g_atomic_int_set(&counter, 1); |
| 140 |
|
| 141 |
src->signal_pad_added().connect(sigc::ptr_fun(&on_pad_added)); |
| 142 |
src->signal_no_more_pads().connect(sigc::ptr_fun(&no_more_pads)); |
| 143 |
|
| 144 |
pipeline->set_state(STATE_PAUSED); |
| 145 |
|
| 146 |
Glib::signal_timeout().connect(sigc::ptr_fun(&on_timeout), 0); |
| 147 |
mainloop->run(); |
| 148 |
|
| 149 |
pipeline->set_state(Gst::STATE_NULL); |
| 150 |
|
| 151 |
MM_ASSERT_TRUE(was_check); |
| 152 |
|
| 153 |
remove(input_filename.c_str()); |
| 154 |
} |