@ -140,8 +140,7 @@ static void hds_free(AVFormatContext *s)
for ( i = 0 ; i < s - > nb_streams ; i + + ) {
for ( i = 0 ; i < s - > nb_streams ; i + + ) {
OutputStream * os = & c - > streams [ i ] ;
OutputStream * os = & c - > streams [ i ] ;
if ( os - > out )
if ( os - > out )
avio_close ( os - > out ) ;
ff_format_io_close ( s , & os - > out ) ;
os - > out = NULL ;
if ( os - > ctx & & os - > ctx_inited )
if ( os - > ctx & & os - > ctx_inited )
av_write_trailer ( os - > ctx ) ;
av_write_trailer ( os - > ctx ) ;
if ( os - > ctx & & os - > ctx - > pb )
if ( os - > ctx & & os - > ctx - > pb )
@ -171,8 +170,7 @@ static int write_manifest(AVFormatContext *s, int final)
snprintf ( filename , sizeof ( filename ) , " %s/index.f4m " , s - > filename ) ;
snprintf ( filename , sizeof ( filename ) , " %s/index.f4m " , s - > filename ) ;
snprintf ( temp_filename , sizeof ( temp_filename ) , " %s/index.f4m.tmp " , s - > filename ) ;
snprintf ( temp_filename , sizeof ( temp_filename ) , " %s/index.f4m.tmp " , s - > filename ) ;
ret = avio_open2 ( & out , temp_filename , AVIO_FLAG_WRITE ,
ret = s - > io_open ( s , & out , temp_filename , AVIO_FLAG_WRITE , NULL ) ;
& s - > interrupt_callback , NULL ) ;
if ( ret < 0 ) {
if ( ret < 0 ) {
av_log ( s , AV_LOG_ERROR , " Unable to open %s for writing \n " , temp_filename ) ;
av_log ( s , AV_LOG_ERROR , " Unable to open %s for writing \n " , temp_filename ) ;
return ret ;
return ret ;
@ -190,7 +188,7 @@ static int write_manifest(AVFormatContext *s, int final)
int b64_size = AV_BASE64_SIZE ( os - > metadata_size ) ;
int b64_size = AV_BASE64_SIZE ( os - > metadata_size ) ;
char * base64 = av_malloc ( b64_size ) ;
char * base64 = av_malloc ( b64_size ) ;
if ( ! base64 ) {
if ( ! base64 ) {
avio_close ( out ) ;
ff_format_io_close ( s , & out ) ;
return AVERROR ( ENOMEM ) ;
return AVERROR ( ENOMEM ) ;
}
}
av_base64_encode ( base64 , b64_size , os - > metadata , os - > metadata_size ) ;
av_base64_encode ( base64 , b64_size , os - > metadata , os - > metadata_size ) ;
@ -203,7 +201,7 @@ static int write_manifest(AVFormatContext *s, int final)
}
}
avio_printf ( out , " </manifest> \n " ) ;
avio_printf ( out , " </manifest> \n " ) ;
avio_flush ( out ) ;
avio_flush ( out ) ;
avio_close ( out ) ;
ff_format_io_close ( s , & out ) ;
return ff_rename ( temp_filename , filename ) ;
return ff_rename ( temp_filename , filename ) ;
}
}
@ -240,8 +238,7 @@ static int write_abst(AVFormatContext *s, OutputStream *os, int final)
" %s/stream%d.abst " , s - > filename , index ) ;
" %s/stream%d.abst " , s - > filename , index ) ;
snprintf ( temp_filename , sizeof ( temp_filename ) ,
snprintf ( temp_filename , sizeof ( temp_filename ) ,
" %s/stream%d.abst.tmp " , s - > filename , index ) ;
" %s/stream%d.abst.tmp " , s - > filename , index ) ;
ret = avio_open2 ( & out , temp_filename , AVIO_FLAG_WRITE ,
ret = s - > io_open ( s , & out , temp_filename , AVIO_FLAG_WRITE , NULL ) ;
& s - > interrupt_callback , NULL ) ;
if ( ret < 0 ) {
if ( ret < 0 ) {
av_log ( s , AV_LOG_ERROR , " Unable to open %s for writing \n " , temp_filename ) ;
av_log ( s , AV_LOG_ERROR , " Unable to open %s for writing \n " , temp_filename ) ;
return ret ;
return ret ;
@ -284,15 +281,14 @@ static int write_abst(AVFormatContext *s, OutputStream *os, int final)
}
}
update_size ( out , afrt_pos ) ;
update_size ( out , afrt_pos ) ;
update_size ( out , 0 ) ;
update_size ( out , 0 ) ;
avio_close ( out ) ;
ff_format_io_close ( s , & out ) ;
return ff_rename ( temp_filename , filename ) ;
return ff_rename ( temp_filename , filename ) ;
}
}
static int init_file ( AVFormatContext * s , OutputStream * os , int64_t start_ts )
static int init_file ( AVFormatContext * s , OutputStream * os , int64_t start_ts )
{
{
int ret , i ;
int ret , i ;
ret = avio_open2 ( & os - > out , os - > temp_filename , AVIO_FLAG_WRITE ,
ret = s - > io_open ( s , & os - > out , os - > temp_filename , AVIO_FLAG_WRITE , NULL ) ;
& s - > interrupt_callback , NULL ) ;
if ( ret < 0 )
if ( ret < 0 )
return ret ;
return ret ;
avio_wb32 ( os - > out , 0 ) ;
avio_wb32 ( os - > out , 0 ) ;
@ -305,14 +301,13 @@ static int init_file(AVFormatContext *s, OutputStream *os, int64_t start_ts)
return 0 ;
return 0 ;
}
}
static void close_file ( OutputStream * os )
static void close_file ( AVFormatContext * s , OutputStream * os )
{
{
int64_t pos = avio_tell ( os - > out ) ;
int64_t pos = avio_tell ( os - > out ) ;
avio_seek ( os - > out , 0 , SEEK_SET ) ;
avio_seek ( os - > out , 0 , SEEK_SET ) ;
avio_wb32 ( os - > out , pos ) ;
avio_wb32 ( os - > out , pos ) ;
avio_flush ( os - > out ) ;
avio_flush ( os - > out ) ;
avio_close ( os - > out ) ;
ff_format_io_close ( s , & os - > out ) ;
os - > out = NULL ;
}
}
static int hds_write_header ( AVFormatContext * s )
static int hds_write_header ( AVFormatContext * s )
@ -476,7 +471,7 @@ static int hds_flush(AVFormatContext *s, OutputStream *os, int final,
avio_flush ( os - > ctx - > pb ) ;
avio_flush ( os - > ctx - > pb ) ;
os - > packets_written = 0 ;
os - > packets_written = 0 ;
close_file ( os ) ;
close_file ( s , os ) ;
snprintf ( target_filename , sizeof ( target_filename ) ,
snprintf ( target_filename , sizeof ( target_filename ) ,
" %s/stream%dSeg1-Frag%d " , s - > filename , index , os - > fragment_index ) ;
" %s/stream%dSeg1-Frag%d " , s - > filename , index , os - > fragment_index ) ;