File: main.cc

package info (click to toggle)
gstreamermm-1.0 1.10.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,488 kB
  • sloc: xml: 68,148; cpp: 6,109; sh: 4,187; makefile: 243; perl: 236
file content (98 lines) | stat: -rw-r--r-- 2,263 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * main.cc
 *
 *  Created on: Aug 19, 2013
 *      Author: m.kolny
 */
#include <gstreamermm.h>
#include <glibmm/main.h>
#include <iostream>

using namespace Gst;
using Glib::RefPtr;

RefPtr<Element> src;
RefPtr<Element> convert;
RefPtr<Pipeline> pipeline;
RefPtr<Glib::MainLoop> main_loop;

bool on_timeout()
{
	static int pattern = 0;
	src->set_state(STATE_NULL);
	pipeline->remove(src);
	src = ElementFactory::create_element("videotestsrc");
	pattern = (pattern == 0) ? 18 : 0;
	src->property("pattern",  pattern);
	pipeline->add(src);
	src->link(convert);
	src->set_state(STATE_PLAYING);

	return true;
}

int main(int argc, char** argv)
{
	if (argc < 2)
	{
		std::cout << "Usage: " << argv[0] << " <avi output filename>" << std::endl;
		return 1;
	}

	init(argc, argv);
	main_loop = Glib::MainLoop::create();

	pipeline = Pipeline::create("effects-pipeline");

	if (!pipeline)
	{
		std::cout << "Cannot create pipeline element." << std::endl;
		return 1;
	}

	RefPtr<Element> queue1 = ElementFactory::create_element("queue"),
			queue2 = ElementFactory::create_element("queue"),
			tee = ElementFactory::create_element("tee"),
			autosink = ElementFactory::create_element("autovideosink"),
			sink = ElementFactory::create_element("filesink"),
			muxer = ElementFactory::create_element("avimux");

	src = ElementFactory::create_element("videotestsrc");
	src->property<int>("num-buffers", 100);
	sink->property<Glib::ustring>("location", argv[1]);
	convert = ElementFactory::create_element("videoconvert");

	if (!queue1 || !queue2 || !tee || !autosink ||
			!sink || !muxer || !src || !sink || !convert)
	{
		std::cout << "Cannot create one of the elements." << std::endl;
		return 1;
	}

	try
	{
		pipeline->add(src)->add(convert)->add(tee)->add(queue1)
				->add(autosink)->add(queue2)->add(muxer)->add(sink);

		src->link(convert)->link(tee)->link(queue1)->link(autosink);
		tee->link(queue2)->link(muxer)->link(sink);
	}
	catch (const std::exception& ex)
	{
		std::cout << "Exception occured during preparing pipeline. Message: " << ex.what() << std::endl;
		return 1;
	}

	pipeline->set_state(STATE_PLAYING);

	Glib::signal_timeout().connect(sigc::ptr_fun(&on_timeout), 2000);
	main_loop->run();

	pipeline->set_state(STATE_NULL);

  return 0;
}