File indexing completed on 2024-05-05 04:44:41

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2008 Matthias Kretz <kretz@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) version 3, or any
0008     later version accepted by the membership of KDE e.V. (or its
0009     successor approved by the membership of KDE e.V.), Nokia Corporation 
0010     (or its successors, if any) and the KDE Free Qt Foundation, which shall
0011     act as a proxy defined in Section 6 of version 3 of the license.
0012 
0013     This library is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     Lesser General Public License for more details.
0017 
0018     You should have received a copy of the GNU Lesser General Public 
0019     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0020 
0021 */
0022 
0023 #ifndef PHONON_STREAMEVENTQUEUE_P_H
0024 #define PHONON_STREAMEVENTQUEUE_P_H
0025 
0026 #include <QVariant>
0027 #include "lockfreequeue_p.h"
0028 
0029 namespace Phonon
0030 {
0031 
0032 class StreamEventQueue
0033 {
0034     public:
0035         StreamEventQueue();
0036         ~StreamEventQueue();
0037 
0038         void setBackendCommandHandler(LockFreeQueueBase::DataReadyHandler *);
0039         void setFrontendCommandHandler(LockFreeQueueBase::DataReadyHandler *);
0040 
0041         enum CommandType {
0042             // Frontend -> Backend
0043             SetStreamSize,
0044             SetSeekable,
0045             Write,
0046             EndOfData,
0047             SeekDone,
0048             ResetDone,
0049             ConnectDone,
0050 
0051             // Backend -> Frontend
0052             NeedData,
0053             EnoughData,
0054             Seek,
0055             Reset,
0056             Connect
0057         };
0058 
0059         struct Command
0060         {
0061             inline Command(CommandType &c, const QVariant &d) : data(d), command(c) {}
0062             inline Command() {}
0063             QVariant data;
0064             CommandType command;
0065         };
0066 
0067         // called from AbstractMediaStream thread
0068         void sendToBackend(CommandType, const QVariant & = QVariant());
0069         bool nextCommandForFrontend(Command *);
0070 
0071         // called from StreamInterface thread
0072         void sendToFrontend(CommandType, const QVariant & = QVariant());
0073         bool nextCommandForBackend(Command *);
0074 
0075         void ref() { m_references.ref(); }
0076         void deref() { if (!m_references.deref()) delete this; }
0077 
0078     private:
0079         LockFreeQueue<Command, LockFreeQueueBase::KeepNodePoolMemoryManagement> m_forBackend;
0080         LockFreeQueue<Command, LockFreeQueueBase::KeepNodePoolMemoryManagement> m_forFrontend;
0081         int m_dropWriteCommands;
0082         int m_connecting;
0083         QAtomicInt m_references;
0084 };
0085 
0086 } // namespace Phonon
0087 
0088 #endif // PHONON_STREAMEVENTQUEUE_P_H