summaryrefslogtreecommitdiff
path: root/test/gstreamer/gstreamer_single_stream_test.cpp
blob: 3ef2d323678f3ab7a59c19fb4caa71c3942066ca (plain)
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
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2021, Vedant Paranjape
 *
 * GStreamer single stream capture test
 */

#include <iostream>
#include <unistd.h>

#include <gst/gst.h>

#include "gstreamer_test.h"
#include "test.h"

using namespace std;

class GstreamerSingleStreamTest : public GstreamerTest, public Test
{
public:
	GstreamerSingleStreamTest()
		: GstreamerTest()
	{
	}

protected:
	int init() override
	{
		if (status_ != TestPass)
			return status_;

		fakesink_ = gst_element_factory_make("fakesink", nullptr);
		if (!fakesink_) {
			g_printerr("Your installation is missing 'fakesink'\n");
			return TestFail;
		}
		g_object_ref_sink(fakesink_);

		return createPipeline();
	}

	int run() override
	{
		/* Build the pipeline */
		gst_bin_add_many(GST_BIN(pipeline_), libcameraSrc_, fakesink_, nullptr);
		if (!gst_element_link(libcameraSrc_, fakesink_)) {
			g_printerr("Elements could not be linked.\n");
			return TestFail;
		}

		if (startPipeline() != TestPass)
			return TestFail;

		if (processEvent() != TestPass)
			return TestFail;

		return TestPass;
	}

	void cleanup() override
	{
		g_clear_object(&fakesink_);
	}

private:
	GstElement *fakesink_;
};

TEST_REGISTER(GstreamerSingleStreamTest)