| 1 | /* |
| 2 | * utils.cc |
| 3 | * |
| 4 | * Created on: Aug 5, 2013 |
| 5 | * Author: m.kolny |
| 6 | */ |
| 7 | |
| 8 | #include <gstreamermm.h> |
| 9 | #include <gstreamermm/videotestsrc.h> |
| 10 | #include <gstreamermm/filesink.h> |
| 11 | #include <glibmm/main.h> |
| 12 | #include "utils.h" |
| 13 | |
| 14 | using Glib::RefPtr; |
| 15 | using namespace Gst; |
| 16 | using namespace std; |
| 17 | |
| 18 | RefPtr<Glib::MainLoop> utils_mainloop; |
| 19 | |
| 20 | bool utils_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 | utils_mainloop->quit(); |
| 26 | return false; |
| 27 | case Gst::MESSAGE_ERROR: |
| 28 | utils_mainloop->quit(); |
| 29 | return false; |
| 30 | default: |
| 31 | break; |
| 32 | } |
| 33 | |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | void GenerateSampleOggFile(int num_buffers, const Glib::ustring& filename) |
| 38 | { |
| 39 | RefPtr<Pipeline> pipeline = Pipeline::create("create-ogg"); |
| 40 | RefPtr<Element> source = ElementFactory::create_element("videotestsrc", "testsource"); |
| 41 | RefPtr<Element> encoder = ElementFactory::create_element("theoraenc"), |
| 42 | muxer = ElementFactory::create_element("oggmux"); |
| 43 | RefPtr<Element> sink = ElementFactory::create_element("filesink", "fsink"); |
| 44 | //RefPtr<Element> sink = ElementFactory::create_element("xvimagesink"); |
| 45 | |
| 46 | Glib::RefPtr<Gst::Bus> bus = pipeline->get_bus(); |
| 47 | bus->add_watch(sigc::ptr_fun(&utils_on_bus_message)); |
| 48 | |
| 49 | utils_mainloop = Glib::MainLoop::create(); |
| 50 | |
| 51 | pipeline->add(source)->add(encoder)->add(muxer)->add(sink); |
| 52 | |
| 53 | source->set_property("num_buffers", num_buffers); |
| 54 | sink->set_property("location", filename); |
| 55 | |
| 56 | muxer->link(sink); |
| 57 | source->link(encoder); |
| 58 | encoder->link(muxer); |
| 59 | |
| 60 | pipeline->set_state(Gst::STATE_PLAYING); |
| 61 | |
| 62 | utils_mainloop->run(); |
| 63 | pipeline->set_state(Gst::STATE_NULL); |
| 64 | } |
| 65 | |
| 66 | bool FilesEqual(const string& filename1, const string& filename2) |
| 67 | { |
| 68 | std::ifstream f1(filename1, ios::binary), |
| 69 | f2(filename2, ios::binary); |
| 70 | |
| 71 | string buf(istreambuf_iterator<char>(f1), |
| 72 | (istreambuf_iterator<char>())); |
| 73 | |
| 74 | return equal(buf.begin(), buf.end(), |
| 75 | string(istreambuf_iterator<char>(f2), |
| 76 | (istreambuf_iterator<char>())).begin()); |
| 77 | } |