-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVideoShmSrcImpl.cpp
118 lines (102 loc) · 3.11 KB
/
VideoShmSrcImpl.cpp
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* VideoShmSrcImpl.cpp
*
* (c) 2016 Vasilis Liaskovitis -- [email protected]
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
* (c) 2012 Jean-Sebastien Senecal
* (c) 2004 Mathieu Guindon, Julien Keable
* Based on code from Drone http://github.com/sofian/drone
* Based on code from the GStreamer Tutorials http://docs.gstreamer.com/display/GstSDK/Tutorials
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "VideoShmSrcImpl.h"
#include <cstring>
#include <iostream>
namespace mmp {
VideoShmSrcImpl::VideoShmSrcImpl() :
_shmsrc0(NULL),
_gdpdepay0(NULL),
_pollSource(NULL),
_attached(false)
{
}
bool VideoShmSrcImpl::getAttached()
{
return _attached;
}
void VideoShmSrcImpl::setAttached(bool attach)
{
_attached = attach;
}
gboolean
gstPollShmsrc (void *user_data)
{
VideoShmSrcImpl *p = (VideoShmSrcImpl*) user_data;
if (g_file_test(p->getUri().toUtf8().constData(), G_FILE_TEST_EXISTS) &&
! p->getAttached())
{
if (! p->setPlayState(true))
{
qDebug() << "tried to attach, but starting pipeline failed!" << endl;
return false;
}
p->setAttached(true);
}
return true;
}
bool VideoShmSrcImpl::loadMovie(const QString& path) {
VideoImpl::loadMovie(path);
_shmsrc0 = gst_element_factory_make ("shmsrc", "shmsrc0");
_gdpdepay0 = gst_element_factory_make ("gdpdepay", "gdpdepay0");
_pollSource = g_timeout_source_new (500);
g_source_set_callback (_pollSource,
gstPollShmsrc,
this,
NULL);
g_source_attach (_pollSource, g_main_context_default());
g_source_unref (_pollSource);
if (! _shmsrc0 || ! _gdpdepay0)
{
qWarning() << "Not all elements could be created." << endl;
if (! _shmsrc0) g_printerr("_shmsrc0");
if (! _gdpdepay0) g_printerr("_gdpdepay0");
unloadMovie();
return -1;
}
gst_bin_add_many (GST_BIN(_pipeline), _shmsrc0, _gdpdepay0, NULL);
if (! gst_element_link_many (_shmsrc0, _gdpdepay0, _queue0, NULL))
{
qWarning() << "Could not link shmsrc, deserializer and video queue." << endl;
}
QByteArray ba = path.toLocal8Bit();
gchar* uri = (gchar*) path.toUtf8().constData();
uri = (gchar*) ba.data();
//qDebug() << "LIVE mode" << uri;
g_object_set (_shmsrc0, "socket-path", uri, NULL);
g_object_set (_shmsrc0, "is-live", TRUE, NULL);
_videoIsConnected = true;
return TRUE;
}
VideoShmSrcImpl::~VideoShmSrcImpl()
{
// Unref the shmsrc poller.
if (_pollSource)
{
g_source_unref(_pollSource);
_pollSource = NULL;
}
}
}