Merge pull request #26220 from 78andyp/blurayfixes
[xbmc.git] / lib / libUPnP / Platinum / Source / Extras / PltFrameStream.cpp
blob2b3b3e1bcca231e1407c3f47b4abbfaa7e0587a5
1 /*****************************************************************
3 | Platinum - Frame 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 /*----------------------------------------------------------------------
36 | includes
37 +---------------------------------------------------------------------*/
38 #include "PltFrameStream.h"
40 NPT_SET_LOCAL_LOGGER("platinum.core.framestream")
42 /*----------------------------------------------------------------------
43 | PLT_InputFrameStream::PLT_InputFrameStream
44 +---------------------------------------------------------------------*/
45 PLT_InputFrameStream::PLT_InputFrameStream(NPT_Reference<PLT_FrameBuffer>& frame_buffer,
46 const char* boundary) :
47 m_FrameBuffer(frame_buffer),
48 m_LastFrameIndex(0),
49 m_Boundary(boundary),
50 m_Eos(false)
52 m_FrameBuffer->AddReader();
55 /*----------------------------------------------------------------------
56 | PLT_InputFrameStream::~PLT_InputFrameStream
57 +---------------------------------------------------------------------*/
58 PLT_InputFrameStream::~PLT_InputFrameStream()
60 m_FrameBuffer->RemoveReader();
63 /*----------------------------------------------------------------------
64 | PLT_InputFrameStream::GetAvailable
65 +---------------------------------------------------------------------*/
66 NPT_Result
67 PLT_InputFrameStream::GetAvailable(NPT_LargeSize& available)
69 NPT_CHECK_WARNING(m_Part.GetAvailable(available));
71 if (available == 0 && !m_Eos) {
72 NPT_CHECK_WARNING(FillBuffer());
73 NPT_CHECK_WARNING(m_Part.GetAvailable(available));
76 return NPT_SUCCESS;
79 /*----------------------------------------------------------------------
80 | PLT_InputFrameStream::FillBuffer
81 +---------------------------------------------------------------------*/
82 NPT_Result
83 PLT_InputFrameStream::FillBuffer()
85 // reset memorystream
86 m_Part.SetDataSize(0);
88 // fetch next frame
89 NPT_DataBuffer frame;
90 NPT_Result result = m_FrameBuffer->GetNextFrame(m_LastFrameIndex, frame);
92 // error (EOS) or empty frame means we're done
93 if (NPT_FAILED(result) || frame.GetDataSize() == 0) {
94 m_Part.WriteLine("--" + m_Boundary + "--");
95 m_Eos = true;
96 return NPT_SUCCESS;
99 m_Part.WriteLine("--" + m_Boundary);
100 m_Part.WriteLine("Content-Type: " + NPT_String(m_FrameBuffer->GetMimeType()));
101 m_Part.WriteLine("Content-Length: "+NPT_String::FromInteger(frame.GetDataSize()));
102 m_Part.WriteLine("");
103 m_Part.Write(frame.GetData(), frame.GetDataSize());
104 m_Part.WriteLine("");
105 return NPT_SUCCESS;
108 /*----------------------------------------------------------------------
109 | PLT_InputFrameStream::Read
110 +---------------------------------------------------------------------*/
111 NPT_Result
112 PLT_InputFrameStream::Read(void* buffer,
113 NPT_Size bytes_to_read,
114 NPT_Size* bytes_read /*= 0*/)
117 if (bytes_read) *bytes_read = 0;
119 if (bytes_to_read == 0) {
120 return NPT_SUCCESS;
123 // make sure we have data
124 NPT_LargeSize available;
125 NPT_CHECK_WARNING(GetAvailable(available));
127 return m_Part.Read(buffer, bytes_to_read, bytes_read);