On 29. jan. 2014 19:44, Tommi Mäkitalo wrote:
> Hi,
>
> I just checked in my implementation of chunked encoding in tntnet.
>
> To use chunked encoding a component can call
> "reply.setChunkedEncoding()". This call sends the http headers and
> starts sending the content collected so far to the client immediately.
> All content created after that is sent in chunks to the client as soon
> as the buffer is filled. The buffer is hard coded 8k big. Calling
> flush() on the stream (reply.out().flush()), sends all content collected
> so far.
>
> The advantage of using chunked encoding is, that content is sent
> immediately to the client and for large components less memory is used
> since the content do not need to be held in memory. The downside is,
> that it is not possible to set additional reply headers in that request
> after chunked encoding is enabled since the headers are already sent to
> the client. This includes session cookies set by tntnet itself when the
> request runs in a new session. Also no exception must occur since tntnet
> has no chance to reply with a internal server error after it has started
> sending the http reply with a http ok return code.
Hi Tommi,
This is great news! This sounds like my project for the coming weekend.
I understand the theoretical concept of sending data in chunks, but I do
need some practical advice.
My goal is to use this feature to send live camera images (not saved to
file) via tntnet so it can be seen as a video stream in the browser.
Let me try to explain how I understand it, maybe you can correct any
misunderstandings/omissions:
I will make a tntnet application with a main program and two ecpp components
vstream.ecpp : the actual video stream using chunked encoding
vcontrol.ecpp : A simple HTML page with a HTML5 tag to contain the
actual video image. This is where I am unsure, i am thinking something
like the code below, where HTML5 <video> tag is used.
<html>
<body>
<h1e>HTML5/Tntnet Video stream Demo</h1>
<video id="sampleMovie" width="640" height="360" preload >
<source src="vstream?<$ q.getUrl() $>" />
</video>
</body>
Does that make sense? If this is not the best way, please advice.
The vstream.ecpp component must at first call reply.setChunkedEncoding()
and probably also reply.setContentType("video/h264);
if the image format is H.264. Or is it necessary to use something else
wrt mime type? I will use FireFox on Kubuntu btw. I'm ok if it just
works in one browser for now.
My understanding is then that the vstream component just loops "forever"
and captures data from the camera and sends each image frame to the
output stream, i.e. to reply.out();
Tntnet will then create 8k chunks from the image data and send to the
browser.
If reply.setChunkedEncoding() was not used, nothing would ever show in
this scenario, because the video would never be complete, right?
Have I understood the setChunkedEncoding() feature correctly?
Best regards
Carsten Arnholm
------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable
security intelligence. It gives you real-time visual feedback on key
security issues and trends. Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general