Phonon

streaminterface.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), Nokia Corporation
10 (or its successors, if any) and the KDE Free Qt Foundation, which shall
11 act as a proxy defined in Section 6 of version 3 of the license.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library. If not, see <http://www.gnu.org/licenses/>.
20
21*/
22
23#include "streaminterface.h"
24#include "streaminterface_p.h"
25#include "abstractmediastream.h"
26#include "abstractmediastream_p.h"
27#include "mediasource_p.h"
28
29#ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
30
31namespace Phonon
32{
33
34StreamInterface::StreamInterface()
35 : d(new StreamInterfacePrivate)
36{
37 d->q = this;
38}
39
40StreamInterface::~StreamInterface()
41{
42 if (d->connected) {
43 AbstractMediaStreamPrivate *dd = d->mediaSource.stream()->d_func();
44 dd->setStreamInterface(nullptr);
45 }
46 delete d;
47}
48
49void StreamInterface::connectToSource(const MediaSource &mediaSource)
50{
51 Q_ASSERT(!d->connected);
52 d->connected = true;
53 d->mediaSource = mediaSource;
54 Q_ASSERT(d->mediaSource.type() == MediaSource::Stream);
55 Q_ASSERT(d->mediaSource.stream());
56 AbstractMediaStreamPrivate *dd = d->mediaSource.stream()->d_func();
57 dd->setStreamInterface(this);
58 // Operations above do not access the stream itself, so they do not need to
59 // use invokeMethod.
60 reset();
61}
62
63// Does not need to use invokeMethod as we are are not accessing the stream.
64void StreamInterfacePrivate::disconnectMediaStream()
65{
66 Q_ASSERT(connected);
67 connected = false;
68
69 // if mediaSource has autoDelete set then it will delete the AbstractMediaStream again who's
70 // destructor is calling us right now
71 mediaSource.setAutoDelete(false);
72
73 mediaSource = MediaSource();
74 q->endOfData();
75 q->setStreamSeekable(false);
76}
77
78void StreamInterface::needData()
79{
80 if (d->mediaSource.type() == MediaSource::Stream) {
81 QMetaObject::invokeMethod(d->mediaSource.stream(), "needData", Qt::QueuedConnection);
82 }
83}
84
85void StreamInterface::enoughData()
86{
87 Q_ASSERT(d->connected);
88 if (d->mediaSource.type() == MediaSource::Stream) {
89 QMetaObject::invokeMethod(d->mediaSource.stream(), "enoughData", Qt::QueuedConnection);
90 }
91}
92
93void StreamInterface::seekStream(qint64 offset)
94{
95 Q_ASSERT(d->connected);
96 if (d->mediaSource.type() == MediaSource::Stream) {
97 QMetaObject::invokeMethod(d->mediaSource.stream(), "seekStream", Qt::QueuedConnection, Q_ARG(qint64, offset));
98 }
99}
100
101void StreamInterface::reset()
102{
103 Q_ASSERT(d->connected);
104 if (d->mediaSource.type() == MediaSource::Stream) {
105 QMetaObject::invokeMethod(d->mediaSource.stream(), "reset", Qt::QueuedConnection);
106 }
107}
108
109} // namespace Phonon
110
111#endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM
112
113
Note that all constructors of this class are implicit, so that you can simply write.
Definition mediasource.h:63
bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret)
QueuedConnection
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:53:28 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.