| 1 | /* |
| 2 | * test-integration-bininpipeline.cc |
| 3 | * |
| 4 | * Created on: 5 sie 2013 |
| 5 | * Author: loganek |
| 6 | */ |
| 7 | |
| 8 | #include "mmtest.h" |
| 9 | #include <gstreamermm.h> |
| 10 | #include <glibmm/main.h> |
| 11 | |
| 12 | using namespace Gst; |
| 13 | using Glib::RefPtr; |
| 14 | |
| 15 | class CustomBin : public Bin |
| 16 | { |
| 17 | private: |
| 18 | RefPtr<Element> source_file; |
| 19 | RefPtr<Element> queue; |
| 20 | RefPtr<GhostPad> src_pad; |
| 21 | protected: |
| 22 | explicit CustomBin(const Glib::ustring& name) |
| 23 | : Bin(name) |
| 24 | { |
| 25 | source_file = ElementFactory::create_element("filesrc", "source-file"); |
| 26 | queue = ElementFactory::create_element("queue"); |
| 27 | |
| 28 | add(source_file); |
| 29 | add(queue); |
| 30 | source_file->link(queue); |
| 31 | |
| 32 | src_pad = add_ghost_pad(queue, "src", "src"); |
| 33 | src_pad->set_active(true); |
| 34 | } |
| 35 | public: |
| 36 | virtual ~CustomBin() {} |
| 37 | |
| 38 | static RefPtr<CustomBin> create(const Glib::ustring& name) |
| 39 | { |
| 40 | return RefPtr<CustomBin>(new CustomBin(name)); |
| 41 | } |
| 42 | |
| 43 | void set_location(const Glib::ustring& filename) |
| 44 | { |
| 45 | source_file->set_property("location", filename); |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | RefPtr<Glib::MainLoop> mainloop; |
| 50 | |
| 51 | bool on_bus_message(const RefPtr<Bus>&, const Glib::RefPtr<Message>& message) |
| 52 | { |
| 53 | switch(message->get_message_type()) |
| 54 | { |
| 55 | case MESSAGE_EOS: |
| 56 | mainloop->quit(); |
| 57 | return false; |
| 58 | case MESSAGE_ERROR: |
| 59 | mainloop->quit(); |
| 60 | return false; |
| 61 | default: |
| 62 | break; |
| 63 | } |
| 64 | |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | TEST(IntegrationBinInPipelineTest, CustomBinShouldCorrectPassThroughImage) |
| 69 | { |
| 70 | Glib::ustring input_png = "/home/loganek/repos/gstreamermm/tests/resources/input-image.png", |
| 71 | output_jpg = "test-integration-bininpipeline-output-image.jpg"; |
| 72 | |
| 73 | mainloop = Glib::MainLoop::create(); |
| 74 | MM_ASSERT_TRUE(mainloop); |
| 75 | RefPtr<CustomBin> custom_bin = CustomBin::create("file-png-decoder"); |
| 76 | MM_ASSERT_TRUE(custom_bin); |
| 77 | RefPtr<Element> queue = ElementFactory::create_element("queue"); |
| 78 | MM_ASSERT_TRUE(queue); |
| 79 | RefPtr<Element> file_sink = ElementFactory::create_element("filesink", "file-sink"); |
| 80 | MM_ASSERT_TRUE(file_sink); |
| 81 | RefPtr<Pipeline> pipeline = Pipeline::create("image-converter-pipeline"); |
| 82 | MM_ASSERT_TRUE(custom_bin); |
| 83 | |
| 84 | ASSERT_NO_THROW(pipeline->add(custom_bin)->add(queue)->add(file_sink)); |
| 85 | ASSERT_NO_THROW(custom_bin->link(queue)->link(file_sink)); |
| 86 | |
| 87 | Glib::RefPtr<Gst::Bus> bus = pipeline->get_bus(); |
| 88 | MM_ASSERT_TRUE(bus); |
| 89 | bus->add_watch(sigc::ptr_fun(&on_bus_message)); |
| 90 | |
| 91 | custom_bin->set_location(input_png); |
| 92 | |
| 93 | file_sink->set_property("location", output_jpg); |
| 94 | |
| 95 | pipeline->set_state(STATE_PLAYING); |
| 96 | |
| 97 | mainloop->run(); |
| 98 | |
| 99 | pipeline->set_state(Gst::STATE_NULL); |
| 100 | } |