Debian Codegraph @

tests/integration/test-integration-videoduration.cc

raw symbols SCIP
1 /*
2 * test-integration-videoduration.cc
3 *
4 * Created on: Aug 5, 2013
5 * Author: m.kolny
6 */
7
8 #include "mmtest.h"
9 #include <gstreamermm.h>
10 #include <glibmm/main.h>
11 #include "utils.h"
12
13 using namespace Gst;
14 using Glib::RefPtr;
15
16 RefPtr<Glib::MainLoop> mainloop;
17 RefPtr<Element> decoder;
18 RefPtr<Gst::Pipeline> pipeline;
19
20 bool on_bus_message(const RefPtr<Bus>&, const Glib::RefPtr<Message>& message)
21 {
22 switch(message->get_message_type())
23 {
24 case Gst::MESSAGE_EOS:
25 mainloop->quit();
26 return false;
27 case Gst::MESSAGE_ERROR:
28 mainloop->quit();
29 return false;
30 default:
31 break;
32 }
33
34 return true;
35 }
36
37 void on_pad_added(const Glib::RefPtr<Gst::Pad>& newPad)
38 {
39 RefPtr<Gst::Pad> sinkPad = decoder->get_static_pad("sink");
40 PadLinkReturn ret = newPad->link(sinkPad);
41
42 MM_ASSERT_TRUE(PAD_LINK_OK == ret || PAD_LINK_WAS_LINKED == ret);
43 }
44
45
46 bool on_timeout()
47 {
48 gint64 len;
49
50 if (pipeline->query_duration(FORMAT_TIME, len))
51 {
52 EXPECT_EQ(333333333, len);
53 return FALSE;
54 }
55
56 return TRUE;
57 }
58
59 TEST(IntegrationVideodurationTest, CreateVideoAndCheckDuration)
60 {
61 Glib::ustring input_filename = "videoduration-test.ogg";
62
63 GenerateSampleOggFile(10, input_filename);
64
65 RefPtr<Element> filesrc = Gst::ElementFactory::create_element("filesrc");
66 MM_ASSERT_TRUE(filesrc);
67
68 filesrc->set_property("location", input_filename);
69
70 mainloop = Glib::MainLoop::create();
71 pipeline = Pipeline::create("rewriter");
72 RefPtr<Element> sink = ElementFactory::create_element("fakesink"),
73 demuxer = ElementFactory::create_element("oggdemux");
74 decoder = ElementFactory::create_element("theoradec");
75 MM_ASSERT_TRUE(sink);
76 MM_ASSERT_TRUE(demuxer);
77 MM_ASSERT_TRUE(decoder);
78
79 RefPtr<Bus> bus = pipeline->get_bus();
80 bus->add_watch(sigc::ptr_fun(&on_bus_message));
81
82 pipeline->add(filesrc)->add(demuxer)->add(decoder)->add(sink);
83 filesrc->link(demuxer);
84 decoder->link(sink);
85
86 demuxer->signal_pad_added().connect(sigc::ptr_fun(&on_pad_added));
87
88 pipeline->set_state(Gst::STATE_PLAYING);
89 Glib::signal_timeout().connect(sigc::ptr_fun(&on_timeout), 0);
90 mainloop->run();
91
92 pipeline->set_state(Gst::STATE_NULL);
93
94 remove(input_filename.c_str());
95 }