Merge pull request #26220 from 78andyp/blurayfixes
[xbmc.git] / lib / libUPnP / Platinum / Source / Extras / PltRingBufferStream.h
blobbd56b8a0b44bc79f586c98a4ab4d91a62091d4a2
1 /*****************************************************************
3 | Platinum - Ring buffer stream
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
6 | All rights reserved.
7 | http://www.plutinosoft.com
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 | licensing@plutinosoft.com
22 | This program is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
27 | You should have received a copy of the GNU General Public License
28 | along with this program; see the file LICENSE.txt. If not, write to
29 | the Free Software Foundation, Inc.,
30 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 | http://www.gnu.org/licenses/gpl-2.0.html
33 ****************************************************************/
35 #ifndef _PLT_RING_BUFFER_STREAM_H_
36 #define _PLT_RING_BUFFER_STREAM_H_
38 /*----------------------------------------------------------------------
39 | includes
40 +---------------------------------------------------------------------*/
41 #include "Neptune.h"
43 /*----------------------------------------------------------------------
44 | PLT_RingBufferStream class
45 +---------------------------------------------------------------------*/
46 class PLT_RingBufferStream : public NPT_DelegatingInputStream,
47 public NPT_DelegatingOutputStream
49 public:
50 PLT_RingBufferStream(NPT_Size buffer_size = 4096, bool blocking = true);
51 PLT_RingBufferStream(NPT_RingBufferReference& buffer, bool blocking = true);
52 ~PLT_RingBufferStream() override;
54 // methods
55 bool IsAborted() { return m_Aborted; }
57 // NPT_InputStream methods
58 NPT_Result Read(void* buffer,
59 NPT_Size bytes_to_read,
60 NPT_Size* bytes_read = NULL) override;
61 NPT_Result GetSize(NPT_LargeSize& size) override {
62 NPT_COMPILER_UNUSED(size);
63 return NPT_ERROR_NOT_SUPPORTED;
65 NPT_Result GetSpace(NPT_LargeSize& space) {
66 NPT_AutoLock autoLock(m_Lock);
67 space = m_RingBuffer->GetSpace();
68 return NPT_SUCCESS;
70 NPT_Result GetAvailable(NPT_LargeSize& available) override {
71 NPT_AutoLock autoLock(m_Lock);
72 available = m_RingBuffer->GetAvailable();
73 return NPT_SUCCESS;
76 // NPT_OutputStream methods
77 NPT_Result Write(const void* buffer,
78 NPT_Size bytes_to_write,
79 NPT_Size* bytes_written = NULL) override;
80 NPT_Result Flush() override;
81 NPT_Result SetEOS();
82 NPT_Result Abort();
84 protected:
85 // NPT_DelegatingInputStream methods
86 NPT_Result InputSeek(NPT_Position offset) override {
87 NPT_COMPILER_UNUSED(offset);
88 return NPT_ERROR_NOT_SUPPORTED;
90 NPT_Result InputTell(NPT_Position& offset) override {
91 NPT_AutoLock autoLock(m_Lock);
92 offset = m_TotalBytesRead;
93 return NPT_SUCCESS;
96 // NPT_DelegatingOutputStream methods
97 NPT_Result OutputSeek(NPT_Position offset) override {
98 NPT_COMPILER_UNUSED(offset);
99 return NPT_ERROR_NOT_SUPPORTED;
101 NPT_Result OutputTell(NPT_Position& offset) override {
102 NPT_AutoLock autoLock(m_Lock);
103 offset = m_TotalBytesWritten;
104 return NPT_SUCCESS;
107 private:
108 NPT_RingBufferReference m_RingBuffer;
109 NPT_Offset m_TotalBytesRead;
110 NPT_Offset m_TotalBytesWritten;
111 NPT_Mutex m_Lock;
112 bool m_Blocking;
113 bool m_Eos;
114 bool m_Aborted;
117 typedef NPT_Reference<PLT_RingBufferStream> PLT_RingBufferStreamReference;
119 #endif // _PLT_RING_BUFFER_STREAM_H_