]> git.sesse.net Git - cubemap/blob - vlc-metacube.diff
Fix the vertical label of the cubemap_input Munin plugin.
[cubemap] / vlc-metacube.diff
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 * );
6  
7  
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 );
15  
16  
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 )
29  vlc_module_end ()
30  
31 @@ -80,7 +82,7 @@ vlc_module_end ()
32   * Exported prototypes
33   *****************************************************************************/
34  static const char *const ppsz_sout_options[] = {
35 -    "user", "pwd", "mime", NULL
36 +    "user", "pwd", "mime", "metacube", NULL
37  };
38  
39  static ssize_t Write( sout_access_out_t *, block_t * );
40 @@ -114,6 +116,8 @@ static int Open( vlc_object_t *p_this )
41      char                *psz_pwd;
42      char                *psz_mime;
43  
44 +    bool                    b_metacube;
45 +
46      if( !( p_sys = p_access->p_sys =
47                  malloc( sizeof( sout_access_out_sys_t ) ) ) )
48          return VLC_ENOMEM ;
49 @@ -188,10 +192,12 @@ static int Open( vlc_object_t *p_this )
50      {
51          psz_mime = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "mime" );
52      }
53 +        
54 +    b_metacube = var_GetBool( p_access, SOUT_CFG_PREFIX "metacube" );
55  
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 );
60      free( psz_user );
61      free( psz_pwd );
62      free( psz_mime );
63 @@ -263,8 +269,9 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
64      while( p_buffer )
65      {
66          block_t *p_next;
67 -
68 -        if( p_buffer->i_flags & BLOCK_FLAG_HEADER )
69 +        bool b_header_block = p_buffer->i_flags & BLOCK_FLAG_HEADER;
70 +        
71 +        if( b_header_block )
72          {
73              /* gather header */
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 )
76          }
77  
78          i_len += p_buffer->i_buffer;
79 +
80          /* send data */
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 );
84  
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
91 @@ -39,6 +39,7 @@
92  #include <vlc_charset.h>
93  #include <vlc_url.h>
94  #include <vlc_mime.h>
95 +#include <metacube.h>
96  #include "../libvlc.h"
97  
98  #include <string.h>
99 @@ -66,6 +67,7 @@
100  #endif
101  
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 );
104  
105  /* each host run in his own thread */
106  struct httpd_host_t
107 @@ -621,6 +623,7 @@ struct httpd_stream_t
108      httpd_url_t *url;
109  
110      char    *psz_mime;
111 +    bool    b_metacube;
112  
113      /* Header to send as first packet */
114      uint8_t *p_header;
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 )
118              {
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 )
123 +                {
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 );
128 +
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 );
133 +                }
134 +                else
135 +                {
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 );
139 +                }
140              }
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 );
145          }
146          httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" );
147 +        if ( stream->b_metacube )
148 +        {
149 +            httpd_MsgAdd( answer, "Content-encoding",  "metacube");
150 +        }
151          return VLC_SUCCESS;
152      }
153  }
154  
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,
159 +                                 bool b_metacube )
160  {
161      httpd_stream_t *stream = xmalloc( sizeof( httpd_stream_t ) );
162  
163 @@ -783,6 +806,7 @@ httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
164      {
165          stream->psz_mime = strdup( vlc_mime_Ext2Mime( psz_url ) );
166      }
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 )
172      return VLC_SUCCESS;
173  }
174  
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 )
177  {
178 -    int i_count;
179 -    int i_pos;
180 -
181 -    if( i_data < 0 || p_data == NULL )
182 -    {
183 -        return VLC_SUCCESS;
184 -    }
185 -    vlc_mutex_lock( &stream->lock );
186 -
187 -    /* save this pointer (to be used by new connection) */
188 -    stream->i_buffer_last_pos = stream->i_buffer_pos;
189 -
190 -    i_pos = stream->i_buffer_pos % stream->i_buffer_size;
191 -    i_count = i_data;
192 +    int i_pos = stream->i_buffer_pos % stream->i_buffer_size;
193 +    int i_count = i_data;
194      while( i_count > 0)
195      {
196          int i_copy;
197 @@ -850,6 +862,31 @@ int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data )
198      }
199  
200      stream->i_buffer_pos += i_data;
201 +}
202 +
203 +int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data, bool b_header )
204 +{
205 +    if( i_data < 0 || p_data == NULL )
206 +    {
207 +        return VLC_SUCCESS;
208 +    }
209 +    vlc_mutex_lock( &stream->lock );
210 +
211 +    /* save this pointer (to be used by new connection) */
212 +    stream->i_buffer_last_pos = stream->i_buffer_pos;
213 +
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 );
218 +        if ( b_header ) {
219 +            hdr.flags = htonl( METACUBE_FLAGS_HEADER );
220 +        } else {
221 +            hdr.flags = htonl( 0 );
222 +        }
223 +        httpd_AppendData( stream, (uint8_t *)&hdr, sizeof(hdr) );
224 +    }
225 +    httpd_AppendData( stream, p_data, i_data );
226  
227      vlc_mutex_unlock( &stream->lock );
228      return VLC_SUCCESS;
229 diff --git a/include/metacube.h b/include/metacube.h
230 new file mode 100644
231 index 0000000..b40a42e
232 --- /dev/null
233 +++ b/include/metacube.h
234 @@ -0,0 +1,17 @@
235 +#ifndef _METACUBE_H
236 +#define _METACUBE_H
237 +
238 +/* Definitions for the Metacube protocol, used to communicate with Cubemap. */
239 +
240 +#include <stdlib.h>
241 +
242 +#define METACUBE_SYNC "\\o/_metacube_\\o/"  /* 16 bytes long. */
243 +#define METACUBE_FLAGS_HEADER 0x1
244 +
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_*. */
249 +};
250 +
251 +#endif  /* !defined(_METACUBE_H) */