| 1 | #include <gstreamermm.h> |
| 2 | #include <glibmm/main.h> |
| 3 | #include <iostream> |
| 4 | #include <stdlib.h> |
| 5 | |
| 6 | Glib::RefPtr<Glib::MainLoop> mainloop; |
| 7 | |
| 8 | bool on_bus_message(const Glib::RefPtr<Gst::Bus>& /* bus */, |
| 9 | const Glib::RefPtr<Gst::Message>& message) |
| 10 | { |
| 11 | switch(message->get_message_type()) { |
| 12 | case Gst::MESSAGE_EOS: |
| 13 | std::cout << std::endl << "End of stream" << std::endl; |
| 14 | mainloop->quit(); |
| 15 | return false; |
| 16 | case Gst::MESSAGE_ERROR: |
| 17 | { |
| 18 | std::cerr << "Error." << std::endl; |
| 19 | mainloop->quit(); |
| 20 | return false; |
| 21 | } |
| 22 | default: |
| 23 | break; |
| 24 | } |
| 25 | |
| 26 | return true; |
| 27 | } |
| 28 | |
| 29 | int main(int argc, char** argv) |
| 30 | { |
| 31 | Gst::init(argc, argv); |
| 32 | Glib::RefPtr<Gst::Pipeline> pipeline; |
| 33 | |
| 34 | if(argc < 3) |
| 35 | { |
| 36 | std::cout << "Usage: " << argv[0] << " <input ogg file> <output ogg file>" << std::endl; |
| 37 | return EXIT_FAILURE; |
| 38 | } |
| 39 | |
| 40 | #ifndef GSTREAMERMM_DISABLE_DEPRECATED |
| 41 | Glib::RefPtr<Gst::FileSrc> filesrc = Gst::FileSrc::create(); |
| 42 | Glib::RefPtr<Gst::FileSink> filesink = Gst::FileSink::create(); |
| 43 | #else |
| 44 | Glib::RefPtr<Gst::Element> filesrc = Gst::ElementFactory::create_element("filesrc"); |
| 45 | Glib::RefPtr<Gst::Element> filesink = Gst::ElementFactory::create_element("filesink"); |
| 46 | #endif |
| 47 | |
| 48 | if(!filesrc || !filesink) |
| 49 | { |
| 50 | std::cerr << "The FileSrc or FileSink element could not be created." << std::endl; |
| 51 | return EXIT_FAILURE; |
| 52 | } |
| 53 | |
| 54 | #ifndef GSTREAMERMM_DISABLE_DEPRECATED |
| 55 | filesrc->property_location() = argv[1]; |
| 56 | filesink->property_location() = argv[2]; |
| 57 | #else |
| 58 | filesrc->set_property<Glib::ustring>("location", argv[1]); |
| 59 | filesink->set_property<Glib::ustring>("location", argv[2]); |
| 60 | #endif |
| 61 | |
| 62 | mainloop = Glib::MainLoop::create(); |
| 63 | pipeline = Gst::Pipeline::create("rewriter"); |
| 64 | |
| 65 | Glib::RefPtr<Gst::Bus> bus = pipeline->get_bus(); |
| 66 | bus->add_watch(sigc::ptr_fun(&on_bus_message)); |
| 67 | |
| 68 | pipeline->add(filesrc)->add(filesink); |
| 69 | |
| 70 | std::cout << "Setting to PLAYING." << std::endl; |
| 71 | pipeline->set_state(Gst::STATE_PLAYING); |
| 72 | filesrc->link(filesink); |
| 73 | std::cout << "Running." << std::endl; |
| 74 | mainloop->run(); |
| 75 | |
| 76 | std::cout << "Returned. Setting state to NULL." << std::endl; |
| 77 | pipeline->set_state(Gst::STATE_NULL); |
| 78 | |
| 79 | return EXIT_SUCCESS; |
| 80 | } |