0
|
1 |
/* This file is part of the KDE project.
|
|
2 |
|
|
3 |
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
|
|
5 |
This library is free software: you can redistribute it and/or modify
|
|
6 |
it under the terms of the GNU Lesser General Public License as published by
|
|
7 |
the Free Software Foundation, either version 2.1 or 3 of the License.
|
|
8 |
|
|
9 |
This library is distributed in the hope that it will be useful,
|
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
GNU Lesser General Public License for more details.
|
|
13 |
|
|
14 |
You should have received a copy of the GNU Lesser General Public License
|
|
15 |
along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "streamreader.h"
|
|
19 |
#include <QtCore/QMutex>
|
|
20 |
#include <phonon/streaminterface.h>
|
|
21 |
|
|
22 |
QT_BEGIN_NAMESPACE
|
|
23 |
|
|
24 |
namespace Phonon
|
|
25 |
{
|
|
26 |
namespace Gstreamer
|
|
27 |
{
|
|
28 |
|
|
29 |
bool StreamReader::read(quint64 pos, int length, char * buffer)
|
|
30 |
{
|
|
31 |
if (currentPos() - currentBufferSize() != pos) {
|
|
32 |
if (!streamSeekable())
|
|
33 |
return false;
|
|
34 |
setCurrentPos(pos);
|
|
35 |
}
|
|
36 |
|
|
37 |
while (currentBufferSize() < length) {
|
|
38 |
int oldSize = currentBufferSize();
|
|
39 |
needData();
|
|
40 |
if (oldSize == currentBufferSize())
|
|
41 |
return false; // We didn't get any data
|
|
42 |
}
|
|
43 |
|
|
44 |
qMemCopy(buffer, m_buffer.data(), length);
|
|
45 |
//truncate the buffer
|
|
46 |
m_buffer = m_buffer.mid(pos);
|
|
47 |
return true;
|
|
48 |
}
|
|
49 |
|
|
50 |
}
|
|
51 |
}
|
|
52 |
|
|
53 |
QT_END_NAMESPACE
|