1 /*****************************************************************************
2 * livehttp.c: Live HTTP Streaming
3 *****************************************************************************
4 * Copyright © 2001, 2002, 2013 VLC authors and VideoLAN
5 * Copyright © 2009-2010 by Keary Griffin
7 * Authors: Keary Griffin <kearygriffin at gmail.com>
8 * Ilkka Ollakka <ileoo at videolan dot org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
33 #include <sys/types.h>
41 #include <vlc_common.h>
42 #include <vlc_plugin.h>
44 #include <vlc_block.h>
46 #include <vlc_strings.h>
47 #include <vlc_charset.h>
50 #include <vlc_gcrypt.h>
55 # define O_LARGEFILE 0
58 #define STR_ENDLIST "#EXT-X-ENDLIST\n"
60 #define MAX_RENAME_RETRIES 10
62 /*****************************************************************************
64 *****************************************************************************/
65 static int Open ( vlc_object_t * );
66 static void Close( vlc_object_t * );
68 #define SOUT_CFG_PREFIX "sout-livehttp-"
69 #define SEGLEN_TEXT N_("Segment length")
70 #define SEGLEN_LONGTEXT N_("Length of TS stream segments")
72 #define SPLITANYWHERE_TEXT N_("Split segments anywhere")
73 #define SPLITANYWHERE_LONGTEXT N_("Don't require a keyframe before splitting "\
74 "a segment. Needed for audio only.")
76 #define NUMSEGS_TEXT N_("Number of segments")
77 #define NUMSEGS_LONGTEXT N_("Number of segments to include in index")
79 #define NOCACHE_TEXT N_("Allow cache")
80 #define NOCACHE_LONGTEXT N_("Add EXT-X-ALLOW-CACHE:NO directive in playlist-file if this is disabled")
82 #define INDEX_TEXT N_("Index file")
83 #define INDEX_LONGTEXT N_("Path to the index file to create")
85 #define INDEXURL_TEXT N_("Full URL to put in index file")
86 #define INDEXURL_LONGTEXT N_("Full URL to put in index file. "\
87 "Use #'s to represent segment number")
89 #define DELSEGS_TEXT N_("Delete segments")
90 #define DELSEGS_LONGTEXT N_("Delete segments when they are no longer needed")
92 #define RATECONTROL_TEXT N_("Use muxers rate control mechanism")
94 #define KEYURI_TEXT N_("AES key URI to place in playlist")
95 #define KEYURI_LONGTEXT N_("Location from where client will retrieve the stream decryption key")
97 #define KEYFILE_TEXT N_("AES key file")
98 #define KEYFILE_LONGTEXT N_("File containing the 16 bytes encryption key")
100 #define RANDOMIV_TEXT N_("Use randomized IV for encryption")
101 #define RANDOMIV_LONGTEXT N_("Generate IV instead using segment-number as IV")
104 set_description( N_("HTTP Live streaming output") )
105 set_shortname( N_("LiveHTTP" ))
106 add_shortcut( "livehttp" )
107 set_capability( "sout access", 0 )
108 set_category( CAT_SOUT )
109 set_subcategory( SUBCAT_SOUT_ACO )
110 add_integer( SOUT_CFG_PREFIX "seglen", 10, SEGLEN_TEXT, SEGLEN_LONGTEXT, false )
111 add_integer( SOUT_CFG_PREFIX "numsegs", 0, NUMSEGS_TEXT, NUMSEGS_LONGTEXT, false )
112 add_bool( SOUT_CFG_PREFIX "splitanywhere", false,
113 SPLITANYWHERE_TEXT, SPLITANYWHERE_LONGTEXT, true )
114 add_bool( SOUT_CFG_PREFIX "delsegs", true,
115 DELSEGS_TEXT, DELSEGS_LONGTEXT, true )
116 add_bool( SOUT_CFG_PREFIX "ratecontrol", false,
117 RATECONTROL_TEXT, RATECONTROL_TEXT, true )
118 add_bool( SOUT_CFG_PREFIX "caching", false,
119 NOCACHE_TEXT, NOCACHE_LONGTEXT, true )
120 add_bool( SOUT_CFG_PREFIX "generate-iv", false,
121 RANDOMIV_TEXT, RANDOMIV_LONGTEXT, true )
122 add_string( SOUT_CFG_PREFIX "index", NULL,
123 INDEX_TEXT, INDEX_LONGTEXT, false )
124 add_string( SOUT_CFG_PREFIX "index-url", NULL,
125 INDEXURL_TEXT, INDEXURL_LONGTEXT, false )
126 add_string( SOUT_CFG_PREFIX "key-uri", NULL,
127 KEYURI_TEXT, KEYURI_TEXT, true )
128 add_loadfile( SOUT_CFG_PREFIX "key-file", NULL,
129 KEYFILE_TEXT, KEYFILE_LONGTEXT, true )
130 set_callbacks( Open, Close )
134 /*****************************************************************************
135 * Exported prototypes
136 *****************************************************************************/
137 static const char *const ppsz_sout_options[] = {
152 static ssize_t Write( sout_access_out_t *, block_t * );
153 static int Seek ( sout_access_out_t *, off_t );
154 static int Control( sout_access_out_t *, int, va_list );
156 typedef struct output_segment
162 uint32_t i_segment_number;
165 struct sout_access_out_sys_t
167 char *psz_cursegPath;
175 block_t *block_buffer;
180 bool b_splitanywhere;
184 gcry_cipher_hd_t aes_ctx;
186 uint8_t stuffing_bytes[16];
187 ssize_t stuffing_size;
188 vlc_array_t *segments_t;
191 static int CryptSetup( sout_access_out_t *p_access );
192 /*****************************************************************************
193 * Open: open the file
194 *****************************************************************************/
195 static int Open( vlc_object_t *p_this )
197 sout_access_out_t *p_access = (sout_access_out_t*)p_this;
198 sout_access_out_sys_t *p_sys;
201 config_ChainParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg );
203 if( !p_access->psz_path )
205 msg_Err( p_access, "no file name specified" );
209 if( unlikely( !( p_sys = malloc ( sizeof( *p_sys ) ) ) ) )
212 p_sys->i_seglen = var_GetInteger( p_access, SOUT_CFG_PREFIX "seglen" );
213 /* Try to get within asked segment length */
214 p_sys->i_seglenm = CLOCK_FREQ * p_sys->i_seglen;
215 p_sys->block_buffer = NULL;
217 p_sys->i_numsegs = var_GetInteger( p_access, SOUT_CFG_PREFIX "numsegs" );
218 p_sys->b_splitanywhere = var_GetBool( p_access, SOUT_CFG_PREFIX "splitanywhere" );
219 p_sys->b_delsegs = var_GetBool( p_access, SOUT_CFG_PREFIX "delsegs" );
220 p_sys->b_ratecontrol = var_GetBool( p_access, SOUT_CFG_PREFIX "ratecontrol") ;
221 p_sys->b_caching = var_GetBool( p_access, SOUT_CFG_PREFIX "caching") ;
222 p_sys->b_generate_iv = var_GetBool( p_access, SOUT_CFG_PREFIX "generate-iv") ;
224 p_sys->segments_t = vlc_array_new();
226 p_sys->stuffing_size = 0;
228 p_sys->psz_indexPath = NULL;
229 psz_idx = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "index" );
233 psz_tmp = str_format_time( psz_idx );
240 path_sanitize( psz_tmp );
241 p_sys->psz_indexPath = psz_tmp;
242 vlc_unlink( p_sys->psz_indexPath );
245 p_sys->psz_indexUrl = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "index-url" );
247 p_access->p_sys = p_sys;
249 if( CryptSetup( p_access ) < 0 )
251 free( p_sys->psz_indexUrl );
252 free( p_sys->psz_indexPath );
254 msg_Err( p_access, "Encryption init failed" );
258 p_sys->i_handle = -1;
259 p_sys->i_segment = 0;
260 p_sys->psz_cursegPath = NULL;
262 p_access->pf_write = Write;
263 p_access->pf_seek = Seek;
264 p_access->pf_control = Control;
269 /************************************************************************
270 * CryptSetup: Initialize encryption
271 ************************************************************************/
272 static int CryptSetup( sout_access_out_t *p_access )
274 sout_access_out_sys_t *p_sys = p_access->p_sys;
277 p_sys->key_uri = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "key-uri" );
278 if( !p_sys->key_uri ) /*No key uri, assume no encryption wanted*/
280 msg_Dbg( p_access, "No key uri, no encryption");
285 /*Setup encryption cipher*/
286 gcry_error_t err = gcry_cipher_open( &p_sys->aes_ctx, GCRY_CIPHER_AES,
287 GCRY_CIPHER_MODE_CBC, 0 );
290 msg_Err( p_access, "Openin AES Cipher failed: %s", gpg_strerror(err));
294 char *keyfile = var_InheritString( p_access, SOUT_CFG_PREFIX "key-file" );
295 if( unlikely(keyfile == NULL) )
297 msg_Err( p_access, "No key-file, no encryption" );
301 int keyfd = vlc_open( keyfile, O_RDONLY | O_NONBLOCK );
302 if( unlikely( keyfd == -1 ) )
304 msg_Err( p_access, "Unable to open keyfile %s: %m", keyfile );
310 ssize_t keylen = read( keyfd, key, 16 );
315 msg_Err( p_access, "No key at least 16 octects (you provided %zd), no encryption", keylen );
319 err = gcry_cipher_setkey( p_sys->aes_ctx, key, 16 );
322 msg_Err(p_access, "Setting AES key failed: %s", gpg_strerror(err));
323 gcry_cipher_close( p_sys->aes_ctx);
327 if( p_sys->b_generate_iv )
328 vlc_rand_bytes( p_sys->aes_ivs, sizeof(uint8_t)*16);
333 /************************************************************************
334 * CryptKey: Set encryption IV to current segment number
335 ************************************************************************/
336 static int CryptKey( sout_access_out_t *p_access, uint32_t i_segment )
338 sout_access_out_sys_t *p_sys = p_access->p_sys;
340 if( !p_sys->b_generate_iv )
342 /* Use segment number as IV if randomIV isn't selected*/
343 memset( p_sys->aes_ivs, 0, 16 * sizeof(uint8_t));
344 p_sys->aes_ivs[15] = i_segment & 0xff;
345 p_sys->aes_ivs[14] = (i_segment >> 8 ) & 0xff;
346 p_sys->aes_ivs[13] = (i_segment >> 16 ) & 0xff;
347 p_sys->aes_ivs[12] = (i_segment >> 24 ) & 0xff;
350 gcry_error_t err = gcry_cipher_setiv( p_sys->aes_ctx,
354 msg_Err(p_access, "Setting AES IVs failed: %s", gpg_strerror(err) );
355 gcry_cipher_close( p_sys->aes_ctx);
362 #define SEG_NUMBER_PLACEHOLDER "#"
363 /*****************************************************************************
364 * formatSegmentPath: create segment path name based on seg #
365 *****************************************************************************/
366 static char *formatSegmentPath( char *psz_path, uint32_t i_seg, bool b_sanitize )
369 char *psz_firstNumSign;
371 if ( ! ( psz_result = str_format_time( psz_path ) ) )
374 psz_firstNumSign = psz_result + strcspn( psz_result, SEG_NUMBER_PLACEHOLDER );
375 if ( *psz_firstNumSign )
378 int i_cnt = strspn( psz_firstNumSign, SEG_NUMBER_PLACEHOLDER );
381 *psz_firstNumSign = '\0';
382 ret = asprintf( &psz_newResult, "%s%0*d%s", psz_result, i_cnt, i_seg, psz_firstNumSign + i_cnt );
386 psz_result = psz_newResult;
390 path_sanitize( psz_result );
395 static void destroySegment( output_segment_t *segment )
397 free( segment->psz_filename );
398 free( segment->psz_duration );
399 free( segment->psz_uri );
400 free( segment->psz_key_uri );
404 /************************************************************************
405 * updateIndexAndDel: If necessary, update index file & delete old segments
406 ************************************************************************/
407 static int updateIndexAndDel( sout_access_out_t *p_access, sout_access_out_sys_t *p_sys, bool b_isend )
412 if ( p_sys->i_numsegs == 0 || p_sys->i_segment < p_sys->i_numsegs )
415 i_firstseg = ( p_sys->i_segment - p_sys->i_numsegs ) + 1;
417 // First update index
418 if ( p_sys->psz_indexPath )
423 if ( asprintf( &psz_idxTmp, "%s.tmp", p_sys->psz_indexPath ) < 0)
426 fp = vlc_fopen( psz_idxTmp, "wt");
429 msg_Err( p_access, "cannot open index file `%s'", psz_idxTmp );
434 if ( fprintf( fp, "#EXTM3U\n#EXT-X-TARGETDURATION:%zu\n#EXT-X-VERSION:3\n#EXT-X-ALLOW-CACHE:%s"
435 "%s\n#EXT-X-MEDIA-SEQUENCE:%"PRIu32"\n", p_sys->i_seglen,
436 p_sys->b_caching ? "YES" : "NO",
437 p_sys->i_numsegs > 0 ? "" : b_isend ? "\n#EXT-X-PLAYLIST-TYPE:VOD" : "\n#EXT-X-PLAYLIST-TYPE:EVENT",
448 if( p_sys->b_generate_iv )
450 unsigned long long iv_hi = 0, iv_lo = 0;
451 for( unsigned short i = 0; i < 8; i++ )
453 iv_hi |= p_sys->aes_ivs[i] & 0xff;
455 iv_lo |= p_sys->aes_ivs[8+i] & 0xff;
458 ret = fprintf( fp, "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\",IV=0X%16.16llx%16.16llx\n",
459 p_sys->key_uri, iv_hi, iv_lo );
462 ret = fprintf( fp, "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\"\n", p_sys->key_uri );
472 for ( uint32_t i = i_firstseg; i <= p_sys->i_segment; i++ )
474 //scale to 0..numsegs-1
475 uint32_t index = i-i_firstseg;
477 output_segment_t *segment = (output_segment_t *)vlc_array_item_at_index( p_sys->segments_t, index );
479 val = fprintf( fp, "#EXTINF:%s,\n%s\n", segment->psz_duration, segment->psz_uri);
489 if ( fputs ( STR_ENDLIST, fp ) < 0)
499 val = vlc_rename ( psz_idxTmp, p_sys->psz_indexPath);
503 vlc_unlink( psz_idxTmp );
504 msg_Err( p_access, "Error moving LiveHttp index file" );
507 msg_Dbg( p_access, "LiveHttpIndexComplete: %s" , p_sys->psz_indexPath );
512 // Then take care of deletion
513 while( p_sys->b_delsegs && p_sys->i_numsegs && ( (vlc_array_count( p_sys->segments_t ) ) >= p_sys->i_numsegs ) )
515 output_segment_t *segment = vlc_array_item_at_index( p_sys->segments_t, 0 );
516 vlc_array_remove( p_sys->segments_t, 0 );
517 if ( segment->psz_filename )
519 vlc_unlink( segment->psz_filename );
521 destroySegment( segment );
528 /*****************************************************************************
529 * closeCurrentSegment: Close the segment file
530 *****************************************************************************/
531 static void closeCurrentSegment( sout_access_out_t *p_access, sout_access_out_sys_t *p_sys, bool b_isend )
533 if ( p_sys->i_handle >= 0 )
535 output_segment_t *segment = (output_segment_t *)vlc_array_item_at_index( p_sys->segments_t, vlc_array_count( p_sys->segments_t ) - 1 );
539 size_t pad = 16 - p_sys->stuffing_size;
540 memset(&p_sys->stuffing_bytes[p_sys->stuffing_size], pad, pad);
541 gcry_error_t err = gcry_cipher_encrypt( p_sys->aes_ctx, p_sys->stuffing_bytes, 16, NULL, 0 );
544 msg_Err( p_access, "Couldn't encrypt 16 bytes: %s", gpg_strerror(err) );
546 int ret = write( p_sys->i_handle, p_sys->stuffing_bytes, 16 );
548 msg_Err( p_access, "Couldn't write 16 bytes" );
550 p_sys->stuffing_size = 0;
554 close( p_sys->i_handle );
555 p_sys->i_handle = -1;
557 if( ! ( us_asprintf( &segment->psz_duration, "%.2f", p_sys->f_seglen ) ) )
559 msg_Err( p_access, "Couldn't set duration on closed segment");
563 segment->i_segment_number = p_sys->i_segment;
565 if ( p_sys->psz_cursegPath )
567 msg_Dbg( p_access, "LiveHttpSegmentComplete: %s (%"PRIu32")" , p_sys->psz_cursegPath, p_sys->i_segment );
568 free( p_sys->psz_cursegPath );
569 p_sys->psz_cursegPath = 0;
570 updateIndexAndDel( p_access, p_sys, b_isend );
575 /*****************************************************************************
576 * Close: close the target
577 *****************************************************************************/
578 static void Close( vlc_object_t * p_this )
580 sout_access_out_t *p_access = (sout_access_out_t*)p_this;
581 sout_access_out_sys_t *p_sys = p_access->p_sys;
583 msg_Dbg( p_access, "Flushing buffer to last file");
584 bool crypted = false;
585 while( p_sys->block_buffer )
587 if( p_sys->key_uri && !crypted)
589 if( p_sys->stuffing_size )
591 p_sys->block_buffer = block_Realloc( p_sys->block_buffer, p_sys->stuffing_size, p_sys->block_buffer->i_buffer );
592 if( unlikely(!p_sys->block_buffer) )
594 memcpy( p_sys->block_buffer->p_buffer, p_sys->stuffing_bytes, p_sys->stuffing_size );
595 p_sys->stuffing_size = 0;
597 size_t original = p_sys->block_buffer->i_buffer;
598 size_t padded = (original + 15 ) & ~15;
599 size_t pad = padded - original;
602 p_sys->stuffing_size = 16 - pad;
603 p_sys->block_buffer->i_buffer -= p_sys->stuffing_size;
604 memcpy( p_sys->stuffing_bytes, &p_sys->block_buffer->p_buffer[p_sys->block_buffer->i_buffer], p_sys->stuffing_size );
607 gcry_error_t err = gcry_cipher_encrypt( p_sys->aes_ctx,
608 p_sys->block_buffer->p_buffer, p_sys->block_buffer->i_buffer, NULL, 0 );
611 msg_Err( p_access, "Encryption failure: %s ", gpg_strerror(err) );
616 ssize_t val = write( p_sys->i_handle, p_sys->block_buffer->p_buffer, p_sys->block_buffer->i_buffer );
619 if ( errno == EINTR )
621 block_ChainRelease ( p_sys->block_buffer);
624 if( !p_sys->block_buffer->p_next )
626 p_sys->f_seglen = (float)( p_sys->block_buffer->i_length / (1000000)) +
627 (float)(p_sys->block_buffer->i_dts - p_sys->i_opendts) / CLOCK_FREQ;
630 if ( likely( (size_t)val >= p_sys->block_buffer->i_buffer ) )
632 block_t *p_next = p_sys->block_buffer->p_next;
633 block_Release (p_sys->block_buffer);
634 p_sys->block_buffer = p_next;
639 p_sys->block_buffer->p_buffer += val;
640 p_sys->block_buffer->i_buffer -= val;
644 closeCurrentSegment( p_access, p_sys, true );
648 gcry_cipher_close( p_sys->aes_ctx );
649 free( p_sys->key_uri );
652 while( vlc_array_count( p_sys->segments_t ) > 0 )
654 output_segment_t *segment = vlc_array_item_at_index( p_sys->segments_t, 0 );
655 vlc_array_remove( p_sys->segments_t, 0 );
656 destroySegment( segment );
658 vlc_array_destroy( p_sys->segments_t );
660 free( p_sys->psz_indexUrl );
661 free( p_sys->psz_indexPath );
664 msg_Dbg( p_access, "livehttp access output closed" );
667 static int Control( sout_access_out_t *p_access, int i_query, va_list args )
669 sout_access_out_sys_t *p_sys = p_access->p_sys;
673 case ACCESS_OUT_CONTROLS_PACE:
675 bool *pb = va_arg( args, bool * );
676 *pb = !p_sys->b_ratecontrol;
687 /*****************************************************************************
688 * openNextFile: Open the segment file
689 *****************************************************************************/
690 static ssize_t openNextFile( sout_access_out_t *p_access, sout_access_out_sys_t *p_sys )
694 uint32_t i_newseg = p_sys->i_segment + 1;
696 /* Create segment and fill it info that we can (everything excluding duration */
697 output_segment_t *segment = (output_segment_t*)malloc(sizeof(output_segment_t));
698 if( unlikely( !segment ) )
701 memset( segment, 0 , sizeof( output_segment_t ) );
703 segment->i_segment_number = i_newseg;
704 segment->psz_filename = formatSegmentPath( p_access->psz_path, i_newseg, true );
705 char *psz_idxFormat = p_sys->psz_indexUrl ? p_sys->psz_indexUrl : p_access->psz_path;
706 segment->psz_uri = formatSegmentPath( psz_idxFormat , i_newseg, true );
708 if ( unlikely( !segment->psz_filename ) )
710 msg_Err( p_access, "Format segmentpath failed");
716 fd = vlc_open( segment->psz_filename, O_WRONLY | O_CREAT | O_LARGEFILE |
720 msg_Err( p_access, "cannot open `%s' (%m)", segment->psz_filename );
721 destroySegment( segment );
725 vlc_array_append( p_sys->segments_t, segment);
729 segment->psz_key_uri = strdup( p_sys->key_uri );
730 CryptKey( p_access, i_newseg );
732 msg_Dbg( p_access, "Successfully opened livehttp file: %s (%"PRIu32")" , segment->psz_filename, i_newseg );
734 p_sys->psz_cursegPath = strdup(segment->psz_filename);
735 p_sys->i_handle = fd;
736 p_sys->i_segment = i_newseg;
740 /*****************************************************************************
741 * Write: standard write on a file descriptor.
742 *****************************************************************************/
743 static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
746 sout_access_out_sys_t *p_sys = p_access->p_sys;
751 if ( ( p_sys->b_splitanywhere || ( p_buffer->i_flags & BLOCK_FLAG_HEADER ) ) )
753 bool crypted = false;
754 block_t *output = p_sys->block_buffer;
755 p_sys->block_buffer = NULL;
758 if( p_sys->i_handle > 0 &&
759 ( p_buffer->i_dts - p_sys->i_opendts +
760 p_buffer->i_length * CLOCK_FREQ / INT64_C(1000000)
761 ) >= p_sys->i_seglenm )
762 closeCurrentSegment( p_access, p_sys, false );
764 if ( p_sys->i_handle < 0 )
766 p_sys->i_opendts = output ? output->i_dts : p_buffer->i_dts;
767 if ( openNextFile( p_access, p_sys ) < 0 )
773 if( p_sys->key_uri && !crypted )
775 if( p_sys->stuffing_size )
777 output = block_Realloc( output, p_sys->stuffing_size, output->i_buffer );
778 if( unlikely(!output ) )
780 memcpy( output->p_buffer, p_sys->stuffing_bytes, p_sys->stuffing_size );
781 p_sys->stuffing_size = 0;
783 size_t original = output->i_buffer;
784 size_t padded = (output->i_buffer + 15 ) & ~15;
785 size_t pad = padded - original;
788 p_sys->stuffing_size = 16-pad;
789 output->i_buffer -= p_sys->stuffing_size;
790 memcpy(p_sys->stuffing_bytes, &output->p_buffer[output->i_buffer], p_sys->stuffing_size);
793 gcry_error_t err = gcry_cipher_encrypt( p_sys->aes_ctx,
794 output->p_buffer, output->i_buffer, NULL, 0 );
797 msg_Err( p_access, "Encryption failure: %s ", gpg_strerror(err) );
803 ssize_t val = write( p_sys->i_handle, output->p_buffer, output->i_buffer );
806 if ( errno == EINTR )
808 block_ChainRelease ( p_buffer );
812 (float)output->i_length / INT64_C(1000000) +
813 (float)(output->i_dts - p_sys->i_opendts) / CLOCK_FREQ;
815 if ( (size_t)val >= output->i_buffer )
817 block_t *p_next = output->p_next;
818 block_Release (output);
824 output->p_buffer += val;
825 output->i_buffer -= val;
831 p_temp = p_buffer->p_next;
832 p_buffer->p_next = NULL;
833 block_ChainAppend( &p_sys->block_buffer, p_buffer );
840 /*****************************************************************************
841 * Seek: seek to a specific location in a file
842 *****************************************************************************/
843 static int Seek( sout_access_out_t *p_access, off_t i_pos )
846 msg_Err( p_access, "livehttp sout access cannot seek" );