1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include <QtMultimedia/private/qtmultimediaglobal_p.h>
41#include <QtCore/qvariant.h>
42#include <QtCore/qdebug.h>
43
44#if defined(HAVE_WIDGETS)
45#include <QtWidgets/qwidget.h>
46#endif
47
48#include "qgstreamerplayerservice.h"
49#include "qgstreamermetadataprovider.h"
50#include "qgstreameravailabilitycontrol.h"
51
52#if defined(HAVE_WIDGETS)
53#include <private/qgstreamervideowidget_p.h>
54#endif
55#include <private/qgstreamervideowindow_p.h>
56#include <private/qgstreamervideorenderer_p.h>
57
58#include "qgstreamerstreamscontrol.h"
59#include <private/qgstreameraudioprobecontrol_p.h>
60#include <private/qgstreamervideoprobecontrol_p.h>
61#include <private/qgstreamerplayersession_p.h>
62#include <private/qgstreamerplayercontrol_p.h>
63
64#include <private/qmediaplaylistnavigator_p.h>
65#include <qmediaplaylist.h>
66#include <private/qmediaresourceset_p.h>
67
68QT_BEGIN_NAMESPACE
69
70QGstreamerPlayerService::QGstreamerPlayerService(QObject *parent)
71 : QMediaService(parent)
72{
73 m_session = new QGstreamerPlayerSession(this);
74 m_control = new QGstreamerPlayerControl(m_session, this);
75 m_metaData = new QGstreamerMetaDataProvider(m_session, this);
76 m_streamsControl = new QGstreamerStreamsControl(m_session,this);
77 m_availabilityControl = new QGStreamerAvailabilityControl(m_control->resources(), this);
78 m_videoRenderer = new QGstreamerVideoRenderer(this);
79 m_videoWindow = new QGstreamerVideoWindow(this);
80 // If the GStreamer video sink is not available, don't provide the video window control since
81 // it won't work anyway.
82 if (!m_videoWindow->videoSink()) {
83 delete m_videoWindow;
84 m_videoWindow = 0;
85 }
86
87#if defined(HAVE_WIDGETS)
88 m_videoWidget = new QGstreamerVideoWidgetControl(this);
89
90 // If the GStreamer video sink is not available, don't provide the video widget control since
91 // it won't work anyway.
92 // QVideoWidget will fall back to QVideoRendererControl in that case.
93 if (!m_videoWidget->videoSink()) {
94 delete m_videoWidget;
95 m_videoWidget = 0;
96 }
97#endif
98}
99
100QGstreamerPlayerService::~QGstreamerPlayerService()
101{
102}
103
104QMediaControl *QGstreamerPlayerService::requestControl(const char *name)
105{
106 if (qstrcmp(str1: name,QMediaPlayerControl_iid) == 0)
107 return m_control;
108
109 if (qstrcmp(str1: name,QMetaDataReaderControl_iid) == 0)
110 return m_metaData;
111
112 if (qstrcmp(str1: name,QMediaStreamsControl_iid) == 0)
113 return m_streamsControl;
114
115 if (qstrcmp(str1: name, QMediaAvailabilityControl_iid) == 0)
116 return m_availabilityControl;
117
118 if (qstrcmp(str1: name, QMediaVideoProbeControl_iid) == 0) {
119 if (!m_videoProbeControl) {
120 increaseVideoRef();
121 m_videoProbeControl = new QGstreamerVideoProbeControl(this);
122 m_session->addProbe(probe: m_videoProbeControl);
123 }
124 m_videoProbeControl->ref.ref();
125 return m_videoProbeControl;
126 }
127
128 if (qstrcmp(str1: name, QMediaAudioProbeControl_iid) == 0) {
129 if (!m_audioProbeControl) {
130 m_audioProbeControl = new QGstreamerAudioProbeControl(this);
131 m_session->addProbe(probe: m_audioProbeControl);
132 }
133 m_audioProbeControl->ref.ref();
134 return m_audioProbeControl;
135 }
136
137 if (!m_videoOutput) {
138 if (qstrcmp(str1: name, QVideoRendererControl_iid) == 0)
139 m_videoOutput = m_videoRenderer;
140 else if (qstrcmp(str1: name, QVideoWindowControl_iid) == 0)
141 m_videoOutput = m_videoWindow;
142#if defined(HAVE_WIDGETS)
143 else if (qstrcmp(str1: name, QVideoWidgetControl_iid) == 0)
144 m_videoOutput = m_videoWidget;
145#endif
146
147 if (m_videoOutput) {
148 increaseVideoRef();
149 m_control->setVideoOutput(m_videoOutput);
150 return m_videoOutput;
151 }
152 }
153
154 return 0;
155}
156
157void QGstreamerPlayerService::releaseControl(QMediaControl *control)
158{
159 if (!control) {
160 return;
161 } else if (control == m_videoOutput) {
162 m_videoOutput = 0;
163 m_control->setVideoOutput(0);
164 decreaseVideoRef();
165 } else if (control == m_videoProbeControl && !m_videoProbeControl->ref.deref()) {
166 m_session->removeProbe(probe: m_videoProbeControl);
167 delete m_videoProbeControl;
168 m_videoProbeControl = 0;
169 decreaseVideoRef();
170 } else if (control == m_audioProbeControl && !m_audioProbeControl->ref.deref()) {
171 m_session->removeProbe(probe: m_audioProbeControl);
172 delete m_audioProbeControl;
173 m_audioProbeControl = 0;
174 }
175}
176
177void QGstreamerPlayerService::increaseVideoRef()
178{
179 m_videoReferenceCount++;
180 if (m_videoReferenceCount == 1) {
181 m_control->resources()->setVideoEnabled(true);
182 }
183}
184
185void QGstreamerPlayerService::decreaseVideoRef()
186{
187 m_videoReferenceCount--;
188 if (m_videoReferenceCount == 0) {
189 m_control->resources()->setVideoEnabled(false);
190 }
191}
192
193QT_END_NAMESPACE
194

source code of qtmultimedia/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp