1 /*****************************************************************
3 | Platinum - Frame Stream
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
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 /*----------------------------------------------------------------------
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
),
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 +---------------------------------------------------------------------*/
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
));
79 /*----------------------------------------------------------------------
80 | PLT_InputFrameStream::FillBuffer
81 +---------------------------------------------------------------------*/
83 PLT_InputFrameStream::FillBuffer()
86 m_Part
.SetDataSize(0);
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
+ "--");
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("");
108 /*----------------------------------------------------------------------
109 | PLT_InputFrameStream::Read
110 +---------------------------------------------------------------------*/
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) {
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
);