Mercurial > projects > hoofbaby
comparison deps/Platinum/Source/Devices/FrameStreamer/PltFrameStream.cpp @ 0:3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
author | fraserofthenight |
---|---|
date | Mon, 06 Jul 2009 08:06:28 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3425707ddbf6 |
---|---|
1 /***************************************************************** | |
2 | | |
3 | Platinum - Frame Stream | |
4 | | |
5 | Copyright (c) 2004-2008, Plutinosoft, LLC. | |
6 | All rights reserved. | |
7 | http://www.plutinosoft.com | |
8 | | |
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. | |
13 | | |
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 | | |
21 | This program is distributed in the hope that it will be useful, | |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | GNU General Public License for more details. | |
25 | | |
26 | You should have received a copy of the GNU General Public License | |
27 | along with this program; see the file LICENSE.txt. If not, write to | |
28 | the Free Software Foundation, Inc., | |
29 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
30 | http://www.gnu.org/licenses/gpl-2.0.html | |
31 | | |
32 ****************************************************************/ | |
33 | |
34 /*---------------------------------------------------------------------- | |
35 | includes | |
36 +---------------------------------------------------------------------*/ | |
37 #include "PltFrameStream.h" | |
38 | |
39 NPT_SET_LOCAL_LOGGER("platinum.core.framestream") | |
40 | |
41 /*---------------------------------------------------------------------- | |
42 | PLT_InputFrameStream::PLT_InputFrameStream | |
43 +---------------------------------------------------------------------*/ | |
44 PLT_InputFrameStream::PLT_InputFrameStream(PLT_FrameBuffer& frame_buffer, | |
45 const char* boundary) : | |
46 m_FrameBuffer(frame_buffer), | |
47 m_LastFrameIndex(0), | |
48 m_Boundary(boundary), | |
49 m_Eos(false) | |
50 { | |
51 } | |
52 | |
53 /*---------------------------------------------------------------------- | |
54 | PLT_InputFrameStream::~PLT_InputFrameStream | |
55 +---------------------------------------------------------------------*/ | |
56 PLT_InputFrameStream::~PLT_InputFrameStream() | |
57 { | |
58 } | |
59 | |
60 /*---------------------------------------------------------------------- | |
61 | PLT_InputFrameStream::GetAvailable | |
62 +---------------------------------------------------------------------*/ | |
63 NPT_Result | |
64 PLT_InputFrameStream::GetAvailable(NPT_LargeSize& available) | |
65 { | |
66 NPT_CHECK_WARNING(m_Part.GetAvailable(available)); | |
67 | |
68 if (available == 0 && !m_Eos) { | |
69 NPT_CHECK_WARNING(FillBuffer()); | |
70 NPT_CHECK_WARNING(m_Part.GetAvailable(available)); | |
71 } | |
72 | |
73 return NPT_SUCCESS; | |
74 } | |
75 | |
76 /*---------------------------------------------------------------------- | |
77 | PLT_InputFrameStream::FillBuffer | |
78 +---------------------------------------------------------------------*/ | |
79 NPT_Result | |
80 PLT_InputFrameStream::FillBuffer() | |
81 { | |
82 // reset memorystream | |
83 m_Part.SetSize(0); | |
84 | |
85 // fetch next frame | |
86 NPT_DataBuffer frame; | |
87 NPT_CHECK_WARNING(m_FrameBuffer.GetNextFrame(m_LastFrameIndex, frame)); | |
88 | |
89 // empty frame means we're done | |
90 if (frame.GetDataSize() == 0) { | |
91 m_Part.WriteLine("--" + m_Boundary + "--"); | |
92 m_Eos = true; | |
93 return NPT_SUCCESS; | |
94 } | |
95 | |
96 m_Part.WriteLine("--" + m_Boundary); | |
97 m_Part.WriteLine("Content-Type: image/jpeg"); | |
98 m_Part.WriteLine("Content-Length: "+NPT_String::FromInteger(frame.GetDataSize())); | |
99 m_Part.WriteLine(""); | |
100 m_Part.Write(frame.GetData(), frame.GetDataSize()); | |
101 m_Part.WriteLine(""); | |
102 return NPT_SUCCESS; | |
103 } | |
104 | |
105 /*---------------------------------------------------------------------- | |
106 | PLT_InputFrameStream::Read | |
107 +---------------------------------------------------------------------*/ | |
108 NPT_Result | |
109 PLT_InputFrameStream::Read(void* buffer, | |
110 NPT_Size bytes_to_read, | |
111 NPT_Size* bytes_read /*= 0*/) | |
112 { | |
113 | |
114 if (bytes_read) *bytes_read = 0; | |
115 | |
116 if (bytes_to_read == 0) { | |
117 return NPT_SUCCESS; | |
118 } | |
119 | |
120 // make sure we have data | |
121 NPT_LargeSize available; | |
122 NPT_CHECK_WARNING(GetAvailable(available)); | |
123 | |
124 return m_Part.Read(buffer, bytes_to_read, bytes_read); | |
125 } |