Debian Codegraph @

examples/audio_video_muxer/main.cc

raw symbols SCIP
1 /*
2 * main.cc
3 *
4 * Created on: Aug 14, 2013
5 * Author: m.kolny
6 */
7
8 #include <gstreamermm.h>
9 #include <iostream>
10 #include <glibmm/main.h>
11
12 using namespace Gst;
13 using Glib::RefPtr;
14
15 RefPtr<Element> video_parser, audio_parser;
16 RefPtr<Glib::MainLoop> main_loop;
17
18 bool on_bus_message(const RefPtr<Gst::Bus>&, const RefPtr<Message>& message)
19 {
20 switch(message->get_message_type())
21 {
22 case Gst::MESSAGE_EOS:
23 std::cout << std::endl << "End of stream" << std::endl;
24 main_loop->quit();
25 return false;
26 case Gst::MESSAGE_ERROR:
27 {
28 Glib::Error error;
29 std::string debug_message;
30 RefPtr<MessageError>::cast_static(message)->parse(error, debug_message);
31 std::cerr << "Error: " << error.what() << std::endl << debug_message << std::endl;
32 main_loop->quit();
33 return false;
34 }
35 default:
36 break;
37 }
38
39 return true;
40 }
41
42 void on_demux_pad_added(const RefPtr<Pad>& newPad)
43 {
44 std::cout << "Dynamic pad created. Linking demuxer/decoder." << std::endl;
45 RefPtr<Pad> sinkPad = video_parser->get_static_pad("sink");
46 PadLinkReturn ret = newPad->link(sinkPad);
47
48 if (ret != PAD_LINK_OK && ret != PAD_LINK_WAS_LINKED)
49 {
50 std::cerr << "Linking of pads " << newPad->get_name() << " and " <<
51 sinkPad->get_name() << " failed." << std::endl;
52 }
53 }
54
55 int main(int argc, char** argv)
56 {
57 if (argc < 3)
58 {
59 std::cout << "Usage: " << argv[0] << " <Ogg/Vorbis filename>"
60 " <mp3 filename> <mkv output filename>" << std::endl;
61 return 1;
62 }
63
64 init(argc, argv);
65
66 RefPtr<Pipeline> pipeline = Pipeline::create("play-pipeline");
67 main_loop = Glib::MainLoop::create();
68 RefPtr<Bus> bus = pipeline->get_bus();
69 bus->add_watch(sigc::ptr_fun(&on_bus_message));
70
71 #ifndef GSTREAMERMM_DISABLE_DEPRECATED
72 RefPtr<FileSrc> video_source = FileSrc::create(),
73 audio_source = FileSrc::create();
74 RefPtr<FileSink> filesink = FileSink::create();
75 #else
76 RefPtr<Element> video_source = ElementFactory::create_element("filesrc"),
77 audio_source = ElementFactory::create_element("filesrc"),
78 filesink = ElementFactory::create_element("filesink");
79 #endif
80
81 RefPtr<Element> ogg_demuxer = ElementFactory::create_element("oggdemux");
82 audio_parser = ElementFactory::create_element("mad");
83
84 RefPtr<Element> audiosink = ElementFactory::create_element("autoaudiosink"),
85 videosink = ElementFactory::create_element("autovideosink");
86
87 RefPtr<Element> muxer = ElementFactory::create_element("matroskamux");
88
89
90 video_parser = ElementFactory::create_element("theoraparse");
91
92 if (!video_source || !ogg_demuxer || !video_parser || !videosink || !pipeline || !audio_parser || !audio_source)
93 {
94 std::cout << "One element could not be created." << std::endl;
95 return 1;
96 }
97
98 #ifndef GSTREAMERMM_DISABLE_DEPRECATED
99 video_source->property_location() = argv[1];
100 audio_source->property_location() = argv[2];
101 filesink->property_location() = argv[3];
102 #else
103 video_source->set_property<Glib::ustring>("location", argv[1]);
104 audio_source->set_property<Glib::ustring>("location", argv[2]);
105 filesink->set_property<Glib::ustring>("location", argv[3]);
106 #endif
107
108 pipeline->add(video_source)->
109 add(ogg_demuxer)->
110 add(video_parser)->
111 add(audio_source)->
112 add(audio_parser)->
113 add(muxer)->
114 add(filesink);
115
116 ogg_demuxer->signal_pad_added().connect(sigc::ptr_fun(&on_demux_pad_added));
117
118 video_source->link(ogg_demuxer);
119 video_parser->link(muxer);
120 audio_source->link(audio_parser)->link(muxer);
121 muxer->link(filesink);
122
123 pipeline->set_state(STATE_PLAYING);
124
125 main_loop->run();
126
127 pipeline->set_state(STATE_NULL);
128
129 return 0;
130 }