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 "abstractmediastream.h"
24
#include "abstractmediastream_p.h"
25
#include "mediaobjectinterface.h"
26
#include "mediaobject_p.h"
27
#include "streaminterface_p.h"
28
29
#ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
30
31
QT_BEGIN_NAMESPACE
32
33
namespace Phonon
34
{
35
36
AbstractMediaStream::AbstractMediaStream(QObject *parent)
37
    : QObject(parent),
38
    d_ptr(new AbstractMediaStreamPrivate)
39
{
40
    d_ptr->q_ptr = this;
41
}
42
43
AbstractMediaStream::AbstractMediaStream(AbstractMediaStreamPrivate &dd, QObject *parent)
44
    : QObject(parent),
45
    d_ptr(&dd)
46
{
47
    d_ptr->q_ptr = this;
48
}
49
50
AbstractMediaStream::~AbstractMediaStream()
51
{
52
}
53
54
qint64 AbstractMediaStream::streamSize() const
55
{
56
    return d_ptr->streamSize;
57
}
58
59
void AbstractMediaStream::setStreamSize(qint64 newSize)
60
{
61
    d_ptr->setStreamSize(newSize);
62
}
63
64
void AbstractMediaStreamPrivate::setStreamSize(qint64 newSize)
65
{
66
    streamSize = newSize;
67
    if (streamInterface) {
68
        streamInterface->setStreamSize(newSize);
69
    }
70
}
71
72
bool AbstractMediaStream::streamSeekable() const
73
{
74
    return d_ptr->streamSeekable;
75
}
76
77
void AbstractMediaStream::setStreamSeekable(bool s)
78
{
79
    d_ptr->setStreamSeekable(s);
80
}
81
82
void AbstractMediaStreamPrivate::setStreamSeekable(bool s)
83
{
84
    streamSeekable = s;
85
    if (streamInterface) {
86
        streamInterface->setStreamSeekable(s);
87
    }
88
}
89
90
void AbstractMediaStream::writeData(const QByteArray &data)
91
{
92
    d_ptr->writeData(data);
93
}
94
95
void AbstractMediaStreamPrivate::writeData(const QByteArray &data)
96
{
97
    if (ignoreWrites) {
98
        return;
99
    }
100
    Q_ASSERT(streamInterface);
101
    streamInterface->writeData(data);
102
}
103
104
void AbstractMediaStream::endOfData()
105
{
106
    d_ptr->endOfData();
107
}
108
109
void AbstractMediaStreamPrivate::endOfData()
110
{
111
    if (streamInterface) {
112
        streamInterface->endOfData();
113
    }
114
}
115
116
void AbstractMediaStream::error(Phonon::ErrorType type, const QString &text)
117
{
118
    Q_D(AbstractMediaStream);
119
    d->errorType = type;
120
    d->errorText = text;
121
    if (d->mediaObjectPrivate) {
122
        // TODO: MediaObject might be in a different thread
123
        d->mediaObjectPrivate->streamError(type, text);
124
    }
125
}
126
127
void AbstractMediaStream::enoughData()
128
{
129
}
130
131
void AbstractMediaStream::seekStream(qint64)
132
{
133
    Q_ASSERT(!d_ptr->streamSeekable);
134
}
135
136
AbstractMediaStreamPrivate::~AbstractMediaStreamPrivate()
137
{
138
    if (mediaObjectPrivate) {
139
        // TODO: MediaObject might be in a different thread
140
        mediaObjectPrivate->removeDestructionHandler(this);
141
    }
142
    if (streamInterface) {
143
        // TODO: StreamInterface might be in a different thread
144
        streamInterface->d->disconnectMediaStream();
145
    }
146
}
147
148
void AbstractMediaStreamPrivate::setStreamInterface(StreamInterface *iface)
149
{
150
    Q_Q(AbstractMediaStream);
151
    streamInterface = iface;
152
    if (!iface) {
153
        // our subclass might be just about to call writeData, so tell it we have enoughData and
154
        // ignore the next writeData calls
155
        q->enoughData();
156
        ignoreWrites = true;
157
        return;
158
    }
159
    if (ignoreWrites) {
160
        ignoreWrites = false;
161
        // we had a StreamInterface before. The new StreamInterface expects us to start reading from
162
        // position 0
163
        q->reset();
164
    } else {
165
        iface->setStreamSize(streamSize);
166
        iface->setStreamSeekable(streamSeekable);
167
    }
168
}
169
170
void AbstractMediaStreamPrivate::setMediaObjectPrivate(MediaObjectPrivate *mop)
171
{
172
    // TODO: MediaObject might be in a different thread
173
    mediaObjectPrivate = mop;
174
    mediaObjectPrivate->addDestructionHandler(this);
175
    if (!errorText.isEmpty()) {
176
        mediaObjectPrivate->streamError(errorType, errorText);
177
    }
178
}
179
180
void AbstractMediaStreamPrivate::phononObjectDestroyed(MediaNodePrivate *bp)
181
{
182
    // TODO: MediaObject might be in a different thread
183
    Q_ASSERT(bp == mediaObjectPrivate);
184
    Q_UNUSED(bp);
185
    mediaObjectPrivate = 0;
186
}
187
188
} // namespace Phonon
189
190
191
QT_END_NAMESPACE
192
193
#include "moc_abstractmediastream.cpp"
194
195
#endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM
196
197
// vim: sw=4 sts=4 et tw=100