1 diff --git a/include/vlc_httpd.h b/include/vlc_httpd.h
2 index 6100dd0..46d557a 100644
3 --- a/include/vlc_httpd.h
4 +++ b/include/vlc_httpd.h
5 @@ -135,10 +135,10 @@ VLC_API void httpd_RedirectDelete( httpd_redirect_t * );
8 typedef struct httpd_stream_t httpd_stream_t;
9 -VLC_API httpd_stream_t * httpd_StreamNew( httpd_host_t *, const char *psz_url, const char *psz_mime, const char *psz_user, const char *psz_password ) VLC_USED;
10 +VLC_API httpd_stream_t * httpd_StreamNew( httpd_host_t *, const char *psz_url, const char *psz_mime, const char *psz_user, const char *psz_password, bool b_metacube ) VLC_USED;
11 VLC_API void httpd_StreamDelete( httpd_stream_t * );
12 VLC_API int httpd_StreamHeader( httpd_stream_t *, uint8_t *p_data, int i_data );
13 -VLC_API int httpd_StreamSend( httpd_stream_t *, uint8_t *p_data, int i_data );
14 +VLC_API int httpd_StreamSend( httpd_stream_t *, uint8_t *p_data, int i_data, bool b_header );
17 /* Msg functions facilities */
18 diff --git a/modules/access_output/http.c b/modules/access_output/http.c
19 index 61095f5..95dd705 100644
20 --- a/modules/access_output/http.c
21 +++ b/modules/access_output/http.c
22 @@ -72,6 +72,8 @@ vlc_module_begin ()
23 PASS_TEXT, PASS_LONGTEXT, true )
24 add_string( SOUT_CFG_PREFIX "mime", "",
25 MIME_TEXT, MIME_LONGTEXT, true )
26 + add_bool( SOUT_CFG_PREFIX "metacube", false,
27 + "Use the metacube protocol", "Use the metacube protocol", true )
28 set_callbacks( Open, Close )
31 @@ -80,7 +82,7 @@ vlc_module_end ()
33 *****************************************************************************/
34 static const char *const ppsz_sout_options[] = {
35 - "user", "pwd", "mime", NULL
36 + "user", "pwd", "mime", "metacube", NULL
39 static ssize_t Write( sout_access_out_t *, block_t * );
40 @@ -114,6 +116,8 @@ static int Open( vlc_object_t *p_this )
46 if( !( p_sys = p_access->p_sys =
47 malloc( sizeof( sout_access_out_sys_t ) ) ) )
49 @@ -188,10 +192,12 @@ static int Open( vlc_object_t *p_this )
51 psz_mime = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "mime" );
54 + b_metacube = var_GetBool( p_access, SOUT_CFG_PREFIX "metacube" );
56 p_sys->p_httpd_stream =
57 httpd_StreamNew( p_sys->p_httpd_host, path, psz_mime,
58 - psz_user, psz_pwd );
59 + psz_user, psz_pwd, b_metacube );
63 @@ -263,8 +269,9 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
68 - if( p_buffer->i_flags & BLOCK_FLAG_HEADER )
69 + bool b_header_block = p_buffer->i_flags & BLOCK_FLAG_HEADER;
71 + if( b_header_block )
74 if( p_sys->b_header_complete )
75 @@ -295,9 +302,10 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
78 i_len += p_buffer->i_buffer;
81 i_err = httpd_StreamSend( p_sys->p_httpd_stream, p_buffer->p_buffer,
82 - p_buffer->i_buffer );
83 + p_buffer->i_buffer, b_header_block );
85 p_next = p_buffer->p_next;
86 block_Release( p_buffer );
87 diff --git a/src/network/httpd.c b/src/network/httpd.c
88 index f76c47c..dcda968 100644
89 --- a/src/network/httpd.c
90 +++ b/src/network/httpd.c
92 #include <vlc_charset.h>
95 +#include <metacube.h>
96 #include "../libvlc.h"
102 static void httpd_ClientClean( httpd_client_t *cl );
103 +static void httpd_AppendData( httpd_stream_t *stream, uint8_t *p_data, int i_data );
105 /* each host run in his own thread */
107 @@ -621,6 +623,7 @@ struct httpd_stream_t
113 /* Header to send as first packet */
115 @@ -712,9 +715,24 @@ static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
116 /* Send the header */
117 if( stream->i_header > 0 )
119 - answer->i_body = stream->i_header;
120 - answer->p_body = xmalloc( stream->i_header );
121 - memcpy( answer->p_body, stream->p_header, stream->i_header );
122 + if ( stream->b_metacube )
124 + struct metacube_block_header hdr;
125 + memcpy( hdr.sync, METACUBE_SYNC, sizeof(METACUBE_SYNC) );
126 + hdr.size = htonl( stream->i_header );
127 + hdr.flags = htonl( METACUBE_FLAGS_HEADER );
129 + answer->i_body = stream->i_header + sizeof( hdr );
130 + answer->p_body = xmalloc( answer->i_body );
131 + memcpy( answer->p_body, &hdr, sizeof( hdr ) );
132 + memcpy( answer->p_body + sizeof( hdr ), stream->p_header, stream->i_header );
136 + answer->i_body = stream->i_header;
137 + answer->p_body = xmalloc( stream->i_header );
138 + memcpy( answer->p_body, stream->p_header, stream->i_header );
141 answer->i_body_offset = stream->i_buffer_last_pos;
142 vlc_mutex_unlock( &stream->lock );
143 @@ -758,13 +776,18 @@ static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
144 httpd_MsgAdd( answer, "Content-type", "%s", stream->psz_mime );
146 httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" );
147 + if ( stream->b_metacube )
149 + httpd_MsgAdd( answer, "Content-encoding", "metacube");
155 httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
156 const char *psz_url, const char *psz_mime,
157 - const char *psz_user, const char *psz_password )
158 + const char *psz_user, const char *psz_password,
161 httpd_stream_t *stream = xmalloc( sizeof( httpd_stream_t ) );
163 @@ -783,6 +806,7 @@ httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
165 stream->psz_mime = strdup( vlc_mime_Ext2Mime( psz_url ) );
167 + stream->b_metacube = b_metacube;
168 stream->i_header = 0;
169 stream->p_header = NULL;
170 stream->i_buffer_size = 5000000; /* 5 Mo per stream */
171 @@ -819,22 +843,10 @@ int httpd_StreamHeader( httpd_stream_t *stream, uint8_t *p_data, int i_data )
175 -int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data )
176 +static void httpd_AppendData( httpd_stream_t *stream, uint8_t *p_data, int i_data )
181 - if( i_data < 0 || p_data == NULL )
183 - return VLC_SUCCESS;
185 - vlc_mutex_lock( &stream->lock );
187 - /* save this pointer (to be used by new connection) */
188 - stream->i_buffer_last_pos = stream->i_buffer_pos;
190 - i_pos = stream->i_buffer_pos % stream->i_buffer_size;
192 + int i_pos = stream->i_buffer_pos % stream->i_buffer_size;
193 + int i_count = i_data;
197 @@ -850,6 +862,31 @@ int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data )
200 stream->i_buffer_pos += i_data;
203 +int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data, bool b_header )
205 + if( i_data < 0 || p_data == NULL )
207 + return VLC_SUCCESS;
209 + vlc_mutex_lock( &stream->lock );
211 + /* save this pointer (to be used by new connection) */
212 + stream->i_buffer_last_pos = stream->i_buffer_pos;
214 + if ( stream->b_metacube ) {
215 + struct metacube_block_header hdr;
216 + memcpy( hdr.sync, METACUBE_SYNC, sizeof(METACUBE_SYNC) );
217 + hdr.size = htonl( i_data );
219 + hdr.flags = htonl( METACUBE_FLAGS_HEADER );
221 + hdr.flags = htonl( 0 );
223 + httpd_AppendData( stream, (uint8_t *)&hdr, sizeof(hdr) );
225 + httpd_AppendData( stream, p_data, i_data );
227 vlc_mutex_unlock( &stream->lock );
229 diff --git a/include/metacube.h b/include/metacube.h
231 index 0000000..b40a42e
233 +++ b/include/metacube.h
238 +/* Definitions for the Metacube protocol, used to communicate with Cubemap. */
242 +#define METACUBE_SYNC "\\o/_metacube_\\o/" /* 16 bytes long. */
243 +#define METACUBE_FLAGS_HEADER 0x1
245 +struct metacube_block_header {
246 + char sync[16]; /* METACUBE_SYNC */
247 + uint32_t size; /* Network byte order. Does not include header. */
248 + uint32_t flags; /* Network byte order. METACUBE_FLAGS_*. */
251 +#endif /* !defined(_METACUBE_H) */