X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=vlc-metacube.diff;fp=vlc-metacube.diff;h=0d965a1a3d32d4d5959a5d80244f32cf8a4048f6;hp=0000000000000000000000000000000000000000;hb=aa3c6213114be76ab3adcfc3eeeed7865c746280;hpb=93bcb482a3f433504aa794441ea4a69aede345ff diff --git a/vlc-metacube.diff b/vlc-metacube.diff new file mode 100644 index 0000000..0d965a1 --- /dev/null +++ b/vlc-metacube.diff @@ -0,0 +1,251 @@ +diff --git a/include/vlc_httpd.h b/include/vlc_httpd.h +index 6100dd0..46d557a 100644 +--- a/include/vlc_httpd.h ++++ b/include/vlc_httpd.h +@@ -135,10 +135,10 @@ VLC_API void httpd_RedirectDelete( httpd_redirect_t * ); + + + typedef struct httpd_stream_t httpd_stream_t; +-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; ++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; + VLC_API void httpd_StreamDelete( httpd_stream_t * ); + VLC_API int httpd_StreamHeader( httpd_stream_t *, uint8_t *p_data, int i_data ); +-VLC_API int httpd_StreamSend( httpd_stream_t *, uint8_t *p_data, int i_data ); ++VLC_API int httpd_StreamSend( httpd_stream_t *, uint8_t *p_data, int i_data, bool b_header ); + + + /* Msg functions facilities */ +diff --git a/modules/access_output/http.c b/modules/access_output/http.c +index 61095f5..95dd705 100644 +--- a/modules/access_output/http.c ++++ b/modules/access_output/http.c +@@ -72,6 +72,8 @@ vlc_module_begin () + PASS_TEXT, PASS_LONGTEXT, true ) + add_string( SOUT_CFG_PREFIX "mime", "", + MIME_TEXT, MIME_LONGTEXT, true ) ++ add_bool( SOUT_CFG_PREFIX "metacube", false, ++ "Use the metacube protocol", "Use the metacube protocol", true ) + set_callbacks( Open, Close ) + vlc_module_end () + +@@ -80,7 +82,7 @@ vlc_module_end () + * Exported prototypes + *****************************************************************************/ + static const char *const ppsz_sout_options[] = { +- "user", "pwd", "mime", NULL ++ "user", "pwd", "mime", "metacube", NULL + }; + + static ssize_t Write( sout_access_out_t *, block_t * ); +@@ -114,6 +116,8 @@ static int Open( vlc_object_t *p_this ) + char *psz_pwd; + char *psz_mime; + ++ bool b_metacube; ++ + if( !( p_sys = p_access->p_sys = + malloc( sizeof( sout_access_out_sys_t ) ) ) ) + return VLC_ENOMEM ; +@@ -188,10 +192,12 @@ static int Open( vlc_object_t *p_this ) + { + psz_mime = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "mime" ); + } ++ ++ b_metacube = var_GetBool( p_access, SOUT_CFG_PREFIX "metacube" ); + + p_sys->p_httpd_stream = + httpd_StreamNew( p_sys->p_httpd_host, path, psz_mime, +- psz_user, psz_pwd ); ++ psz_user, psz_pwd, b_metacube ); + free( psz_user ); + free( psz_pwd ); + free( psz_mime ); +@@ -263,8 +269,9 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer ) + while( p_buffer ) + { + block_t *p_next; +- +- if( p_buffer->i_flags & BLOCK_FLAG_HEADER ) ++ bool b_header_block = p_buffer->i_flags & BLOCK_FLAG_HEADER; ++ ++ if( b_header_block ) + { + /* gather header */ + if( p_sys->b_header_complete ) +@@ -295,9 +302,10 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer ) + } + + i_len += p_buffer->i_buffer; ++ + /* send data */ + i_err = httpd_StreamSend( p_sys->p_httpd_stream, p_buffer->p_buffer, +- p_buffer->i_buffer ); ++ p_buffer->i_buffer, b_header_block ); + + p_next = p_buffer->p_next; + block_Release( p_buffer ); +diff --git a/src/network/httpd.c b/src/network/httpd.c +index f76c47c..dcda968 100644 +--- a/src/network/httpd.c ++++ b/src/network/httpd.c +@@ -39,6 +39,7 @@ + #include + #include + #include ++#include + #include "../libvlc.h" + + #include +@@ -66,6 +67,7 @@ + #endif + + static void httpd_ClientClean( httpd_client_t *cl ); ++static void httpd_AppendData( httpd_stream_t *stream, uint8_t *p_data, int i_data ); + + /* each host run in his own thread */ + struct httpd_host_t +@@ -621,6 +623,7 @@ struct httpd_stream_t + httpd_url_t *url; + + char *psz_mime; ++ bool b_metacube; + + /* Header to send as first packet */ + uint8_t *p_header; +@@ -712,9 +715,24 @@ static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys, + /* Send the header */ + if( stream->i_header > 0 ) + { +- answer->i_body = stream->i_header; +- answer->p_body = xmalloc( stream->i_header ); +- memcpy( answer->p_body, stream->p_header, stream->i_header ); ++ if ( stream->b_metacube ) ++ { ++ struct metacube_block_header hdr; ++ memcpy( hdr.sync, METACUBE_SYNC, sizeof(METACUBE_SYNC) ); ++ hdr.size = htonl( stream->i_header ); ++ hdr.flags = htonl( METACUBE_FLAGS_HEADER ); ++ ++ answer->i_body = stream->i_header + sizeof( hdr ); ++ answer->p_body = xmalloc( answer->i_body ); ++ memcpy( answer->p_body, &hdr, sizeof( hdr ) ); ++ memcpy( answer->p_body + sizeof( hdr ), stream->p_header, stream->i_header ); ++ } ++ else ++ { ++ answer->i_body = stream->i_header; ++ answer->p_body = xmalloc( stream->i_header ); ++ memcpy( answer->p_body, stream->p_header, stream->i_header ); ++ } + } + answer->i_body_offset = stream->i_buffer_last_pos; + vlc_mutex_unlock( &stream->lock ); +@@ -758,13 +776,18 @@ static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys, + httpd_MsgAdd( answer, "Content-type", "%s", stream->psz_mime ); + } + httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" ); ++ if ( stream->b_metacube ) ++ { ++ httpd_MsgAdd( answer, "Content-encoding", "metacube"); ++ } + return VLC_SUCCESS; + } + } + + httpd_stream_t *httpd_StreamNew( httpd_host_t *host, + const char *psz_url, const char *psz_mime, +- const char *psz_user, const char *psz_password ) ++ const char *psz_user, const char *psz_password, ++ bool b_metacube ) + { + httpd_stream_t *stream = xmalloc( sizeof( httpd_stream_t ) ); + +@@ -783,6 +806,7 @@ httpd_stream_t *httpd_StreamNew( httpd_host_t *host, + { + stream->psz_mime = strdup( vlc_mime_Ext2Mime( psz_url ) ); + } ++ stream->b_metacube = b_metacube; + stream->i_header = 0; + stream->p_header = NULL; + stream->i_buffer_size = 5000000; /* 5 Mo per stream */ +@@ -819,22 +843,10 @@ int httpd_StreamHeader( httpd_stream_t *stream, uint8_t *p_data, int i_data ) + return VLC_SUCCESS; + } + +-int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data ) ++static void httpd_AppendData( httpd_stream_t *stream, uint8_t *p_data, int i_data ) + { +- int i_count; +- int i_pos; +- +- if( i_data < 0 || p_data == NULL ) +- { +- return VLC_SUCCESS; +- } +- vlc_mutex_lock( &stream->lock ); +- +- /* save this pointer (to be used by new connection) */ +- stream->i_buffer_last_pos = stream->i_buffer_pos; +- +- i_pos = stream->i_buffer_pos % stream->i_buffer_size; +- i_count = i_data; ++ int i_pos = stream->i_buffer_pos % stream->i_buffer_size; ++ int i_count = i_data; + while( i_count > 0) + { + int i_copy; +@@ -850,6 +862,31 @@ int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data ) + } + + stream->i_buffer_pos += i_data; ++} ++ ++int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data, bool b_header ) ++{ ++ if( i_data < 0 || p_data == NULL ) ++ { ++ return VLC_SUCCESS; ++ } ++ vlc_mutex_lock( &stream->lock ); ++ ++ /* save this pointer (to be used by new connection) */ ++ stream->i_buffer_last_pos = stream->i_buffer_pos; ++ ++ if ( stream->b_metacube ) { ++ struct metacube_block_header hdr; ++ memcpy( hdr.sync, METACUBE_SYNC, sizeof(METACUBE_SYNC) ); ++ hdr.size = htonl( i_data ); ++ if ( b_header ) { ++ hdr.flags = htonl( METACUBE_FLAGS_HEADER ); ++ } else { ++ hdr.flags = htonl( 0 ); ++ } ++ httpd_AppendData( stream, (uint8_t *)&hdr, sizeof(hdr) ); ++ } ++ httpd_AppendData( stream, p_data, i_data ); + + vlc_mutex_unlock( &stream->lock ); + return VLC_SUCCESS; +diff --git a/include/metacube.h b/include/metacube.h +new file mode 100644 +index 0000000..b40a42e +--- /dev/null ++++ b/include/metacube.h +@@ -0,0 +1,17 @@ ++#ifndef _METACUBE_H ++#define _METACUBE_H ++ ++/* Definitions for the Metacube protocol, used to communicate with Cubemap. */ ++ ++#include ++ ++#define METACUBE_SYNC "\\o/_metacube_\\o/" /* 16 bytes long. */ ++#define METACUBE_FLAGS_HEADER 0x1 ++ ++struct metacube_block_header { ++ char sync[16]; /* METACUBE_SYNC */ ++ uint32_t size; /* Network byte order. Does not include header. */ ++ uint32_t flags; /* Network byte order. METACUBE_FLAGS_*. */ ++}; ++ ++#endif /* !defined(_METACUBE_H) */