~ubuntu-branches/ubuntu/trusty/phonon/trusty-updates

« back to all changes in this revision

Viewing changes to ds9/qasyncreader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Modestas Vainius
  • Date: 2011-03-11 21:39:20 UTC
  • mfrom: (6.1.4 experimental)
  • Revision ID: james.westby@ubuntu.com-20110311213920-pvkmqc1gdpy88uzx
Tags: 4:4.6.0really4.4.4-2
* Drop phonon-backends-dbg from phonon-dbg Recommends/Breaks. No longer
  needed.
* Readd packaging copyright/licensing to debian/copyright.
* Bump libphonon-dev Breaks/Replaces to << 4:4.6.0really4.4.4 for
  libphononexperimental-dev. experimental/avcaptureinterface.h header which
  used to be there up to 4.4.4 (see changelog below).
* Switch debian/rules build engine to dhmk (qt-kde-team/2/*):
  - build-depend on pkg-kde-tools >= 0.11;
  - port debian/rules to dhmk keeping it dh compatible as much as possible.
* Drop unused ${shlibs:Depends} from libphonon-dev and
  libphononexperimental-dev packages.
* Add README.Debian to phonon-backend-null package.
* Remove phonon-backend-null.lintian-overrides: phonon-backend-null is no
  longer and empty package due to README.Debian (see above).
* Release to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 <QtCore/QFile>
19
 
 
20
 
#include "qasyncreader.h"
21
 
#include "qbasefilter.h"
22
 
 
23
 
QT_BEGIN_NAMESPACE
24
 
 
25
 
namespace Phonon
26
 
{
27
 
    namespace DS9
28
 
    {
29
 
        QAsyncReader::QAsyncReader(QBaseFilter *parent, const QVector<AM_MEDIA_TYPE> &mediaTypes) : QPin(parent, PINDIR_OUTPUT, mediaTypes)
30
 
        {
31
 
        }
32
 
 
33
 
        QAsyncReader::~QAsyncReader()
34
 
        {
35
 
        }
36
 
 
37
 
        STDMETHODIMP QAsyncReader::QueryInterface(REFIID iid, void **out)
38
 
        {
39
 
            if (!out) {
40
 
                return E_POINTER;
41
 
            }
42
 
 
43
 
            if (iid == IID_IAsyncReader) {
44
 
                AddRef();
45
 
                *out = static_cast<IAsyncReader*>(this);
46
 
                return S_OK;
47
 
            }
48
 
 
49
 
            return QPin::QueryInterface(iid, out);
50
 
        }
51
 
 
52
 
        STDMETHODIMP_(ULONG) QAsyncReader::AddRef()
53
 
        {
54
 
            return QPin::AddRef();
55
 
        }
56
 
 
57
 
        STDMETHODIMP_(ULONG) QAsyncReader::Release()
58
 
        {
59
 
            return QPin::Release();
60
 
        }
61
 
 
62
 
 
63
 
        STDMETHODIMP QAsyncReader::RequestAllocator(IMemAllocator *preferred, ALLOCATOR_PROPERTIES *prop,IMemAllocator **actual)
64
 
        {
65
 
            ALLOCATOR_PROPERTIES prop2;
66
 
 
67
 
            if (prop->cbAlign == 0) {
68
 
                prop->cbAlign = 1; //align on 1 char
69
 
            }
70
 
 
71
 
            if (preferred && preferred->SetProperties(prop, &prop2) == S_OK) {
72
 
                preferred->AddRef();
73
 
                *actual = preferred;
74
 
                return S_OK;
75
 
            }
76
 
 
77
 
            //we should try to create one memory allocator ourselves here
78
 
            return E_FAIL;
79
 
        }
80
 
 
81
 
        STDMETHODIMP QAsyncReader::Request(IMediaSample *sample,DWORD_PTR user)
82
 
        {
83
 
            QMutexLocker mutexLocker(&m_mutexWait);
84
 
            QWriteLocker locker(&m_lock);
85
 
            if (m_flushing) {
86
 
                return VFW_E_WRONG_STATE;
87
 
            }
88
 
 
89
 
            m_requestQueue.enqueue(AsyncRequest(sample, user));
90
 
            m_requestWait.wakeOne();
91
 
            return S_OK;
92
 
        }
93
 
 
94
 
        STDMETHODIMP QAsyncReader::WaitForNext(DWORD timeout, IMediaSample **sample, DWORD_PTR *user)
95
 
        {
96
 
            QMutexLocker locker(&m_mutexWait);
97
 
            if (!sample ||!user) {
98
 
                return E_POINTER;
99
 
            }
100
 
 
101
 
            *sample = 0;
102
 
            *user = 0;
103
 
 
104
 
            AsyncRequest r = getNextRequest();
105
 
 
106
 
            if (r.sample == 0) {
107
 
                //there is no request in the queue
108
 
                if (isFlushing()) {
109
 
                    return VFW_E_WRONG_STATE;
110
 
                } else {
111
 
                    //First we need to lock the mutex
112
 
                    if (m_requestWait.wait(&m_mutexWait, timeout) == false) {
113
 
                        return VFW_E_TIMEOUT;
114
 
                    }
115
 
                    if (isFlushing()) {
116
 
                        return VFW_E_WRONG_STATE;
117
 
                    }
118
 
 
119
 
                    r = getNextRequest();
120
 
                }
121
 
            }
122
 
 
123
 
            //at this point we're sure to have a request to proceed
124
 
            if (r.sample == 0) {
125
 
                return E_FAIL;
126
 
            }
127
 
 
128
 
            *sample = r.sample;
129
 
            *user = r.user;
130
 
 
131
 
            return SyncReadAligned(r.sample);
132
 
        }
133
 
 
134
 
        STDMETHODIMP QAsyncReader::BeginFlush()
135
 
        {
136
 
            QMutexLocker mutexLocker(&m_mutexWait);
137
 
            QWriteLocker locker(&m_lock);
138
 
            m_flushing = true;
139
 
            m_requestWait.wakeOne();
140
 
            return S_OK;
141
 
        }
142
 
 
143
 
        STDMETHODIMP QAsyncReader::EndFlush()
144
 
        {
145
 
            QWriteLocker locker(&m_lock);
146
 
            m_flushing = false;
147
 
            return S_OK;
148
 
        }
149
 
 
150
 
        STDMETHODIMP QAsyncReader::SyncReadAligned(IMediaSample *sample)
151
 
        {
152
 
            if (!sample) {
153
 
                return E_POINTER;
154
 
            }
155
 
 
156
 
            REFERENCE_TIME start = 0,
157
 
                stop = 0;
158
 
            HRESULT hr = sample->GetTime(&start, &stop);
159
 
            if(FAILED(hr)) {
160
 
                return hr;
161
 
            }
162
 
 
163
 
            LONGLONG startPos = start / 10000000;
164
 
            LONG length = static_cast<LONG>((stop - start) / 10000000);
165
 
 
166
 
            BYTE *buffer;
167
 
            hr = sample->GetPointer(&buffer);
168
 
            if(FAILED(hr)) {
169
 
                return hr;
170
 
            }
171
 
 
172
 
            LONG actual = 0;
173
 
            read(startPos, length, buffer, &actual);
174
 
 
175
 
            return sample->SetActualDataLength(actual);
176
 
        }
177
 
 
178
 
        STDMETHODIMP QAsyncReader::SyncRead(LONGLONG pos, LONG length, BYTE *buffer)
179
 
        {
180
 
            return read(pos, length, buffer, 0);
181
 
        }
182
 
 
183
 
 
184
 
        //addition
185
 
        QAsyncReader::AsyncRequest QAsyncReader::getNextRequest()
186
 
        {
187
 
            QWriteLocker locker(&m_lock);
188
 
            AsyncRequest ret;
189
 
            if (!m_requestQueue.isEmpty()) {
190
 
                ret = m_requestQueue.dequeue();
191
 
            }
192
 
 
193
 
            return ret;
194
 
        }
195
 
    }
196
 
}
197
 
 
198
 
QT_END_NAMESPACE