X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmux%2Fasf.c;h=e6a21a77819e43a611ce62d7f696d1b19d324719;hb=ea93da268c6617a0c5c98a2125b9aa27eba19d6d;hp=e03d9d9f55f0d28b315d2af4e64b528b9047eff2;hpb=4f028428053d0342c55deb6ba8b8da114c6a0caa;p=vlc diff --git a/modules/mux/asf.c b/modules/mux/asf.c index e03d9d9f55..e6a21a7781 100644 --- a/modules/mux/asf.c +++ b/modules/mux/asf.c @@ -26,7 +26,12 @@ * Preamble *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include #include @@ -56,9 +61,12 @@ static void Close ( vlc_object_t * ); #define RATING_LONGTEXT N_("\"Rating\" to put in ASF comments." ) #define PACKETSIZE_TEXT N_("Packet Size") #define PACKETSIZE_LONGTEXT N_("ASF packet size -- default is 4096 bytes") +#define BITRATE_TEXT N_("Bitrate override") +#define BITRATE_LONGTEXT N_("Do not try to guess ASF bitrate. Setting this, allows you to control how Windows Media Player will cache streamed content. Set to audio+video bitrate in bytes") + vlc_module_begin(); - set_description( _("ASF muxer") ); + set_description( N_("ASF muxer") ); set_category( CAT_SOUT ); set_subcategory( SUBCAT_SOUT_MUX ); set_shortname( "ASF" ); @@ -69,23 +77,26 @@ vlc_module_begin(); set_callbacks( Open, Close ); add_string( SOUT_CFG_PREFIX "title", "", NULL, TITLE_TEXT, TITLE_LONGTEXT, - VLC_TRUE ); + true ); add_string( SOUT_CFG_PREFIX "author", "", NULL, AUTHOR_TEXT, - AUTHOR_LONGTEXT, VLC_TRUE ); + AUTHOR_LONGTEXT, true ); add_string( SOUT_CFG_PREFIX "copyright","", NULL, COPYRIGHT_TEXT, - COPYRIGHT_LONGTEXT, VLC_TRUE ); + COPYRIGHT_LONGTEXT, true ); add_string( SOUT_CFG_PREFIX "comment", "", NULL, COMMENT_TEXT, - COMMENT_LONGTEXT, VLC_TRUE ); + COMMENT_LONGTEXT, true ); add_string( SOUT_CFG_PREFIX "rating", "", NULL, RATING_TEXT, - RATING_LONGTEXT, VLC_TRUE ); - add_integer( "sout-asf-packet-size", 4096, NULL, PACKETSIZE_TEXT, PACKETSIZE_LONGTEXT, VLC_TRUE ); + RATING_LONGTEXT, true ); + add_integer( SOUT_CFG_PREFIX "packet-size", 4096, NULL, PACKETSIZE_TEXT, + PACKETSIZE_LONGTEXT, true ); + add_integer( SOUT_CFG_PREFIX "bitrate-override", 0, NULL, BITRATE_TEXT, + BITRATE_LONGTEXT, true ); vlc_module_end(); /***************************************************************************** * Locales prototypes *****************************************************************************/ -static const char *ppsz_sout_options[] = { +static const char *const ppsz_sout_options[] = { "title", "author", "copyright", "comment", "rating", NULL }; @@ -104,7 +115,7 @@ typedef struct vlc_fourcc_t i_fourcc; /* for video */ const char *psz_name; /* codec name */ int i_blockalign; /* for audio only */ - vlc_bool_t b_audio_correction; + bool b_audio_correction; int i_sequence; @@ -124,18 +135,19 @@ struct sout_mux_sys_t mtime_t i_dts_last; mtime_t i_preroll_time; int64_t i_bitrate; + int64_t i_bitrate_override; int i_track; asf_track_t track[MAX_ASF_TRACKS]; - vlc_bool_t b_write_header; + bool b_write_header; block_t *pk; int i_pk_used; int i_pk_frame; mtime_t i_pk_dts; - vlc_bool_t b_asf_http; + bool b_asf_http; int i_seq; /* meta data */ @@ -148,7 +160,7 @@ struct sout_mux_sys_t static int MuxGetStream( sout_mux_t *, int *pi_stream, mtime_t *pi_dts ); -static block_t *asf_header_create( sout_mux_t *, vlc_bool_t ); +static block_t *asf_header_create( sout_mux_t *, bool ); static block_t *asf_packet_create( sout_mux_t *, asf_track_t *, block_t * ); static block_t *asf_stream_end_create( sout_mux_t *); static block_t *asf_packet_flush( sout_mux_t * ); @@ -201,12 +213,16 @@ static int Open( vlc_object_t *p_this ) p_sys->i_dts_last = 0; p_sys->i_preroll_time = 2000; p_sys->i_bitrate = 0; + p_sys->i_bitrate_override = 0; p_sys->i_seq = 0; - p_sys->b_write_header = VLC_TRUE; + p_sys->b_write_header = true; p_sys->i_track = 0; p_sys->i_packet_size = config_GetInt( p_mux, "sout-asf-packet-size" ); + p_sys->i_bitrate_override = config_GetInt( p_mux, "sout-asf-bitrate-override" ); msg_Dbg( p_mux, "Packet size %d", p_sys->i_packet_size); + if (p_sys->i_bitrate_override) + msg_Dbg( p_mux, "Bitrate override %"PRId64, p_sys->i_bitrate_override); p_sys->i_packet_count= 0; /* Generate a random fid */ @@ -267,9 +283,9 @@ static void Close( vlc_object_t * p_this ) } /* rewrite header */ - if( !sout_AccessOutSeek( p_mux->p_access, 0 ) ) + if( sout_AccessOutSeek( p_mux->p_access, 0 ) == VLC_SUCCESS ) { - out = asf_header_create( p_mux, VLC_FALSE ); + out = asf_header_create( p_mux, false ); sout_AccessOutWrite( p_mux->p_access, out ); } @@ -287,20 +303,20 @@ static void Close( vlc_object_t * p_this ) static int Control( sout_mux_t *p_mux, int i_query, va_list args ) { sout_mux_sys_t *p_sys = p_mux->p_sys; - vlc_bool_t *pb_bool; + bool *pb_bool; char **ppsz; switch( i_query ) { case MUX_CAN_ADD_STREAM_WHILE_MUXING: - pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t * ); - if( p_sys->b_asf_http ) *pb_bool = VLC_TRUE; - else *pb_bool = VLC_FALSE; + pb_bool = (bool*)va_arg( args, bool * ); + if( p_sys->b_asf_http ) *pb_bool = true; + else *pb_bool = false; return VLC_SUCCESS; case MUX_GET_ADD_STREAM_WAIT: - pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t * ); - *pb_bool = VLC_TRUE; + pb_bool = (bool*)va_arg( args, bool * ); + *pb_bool = true; return VLC_SUCCESS; case MUX_GET_MIME: @@ -377,23 +393,23 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) case VLC_FOURCC( 'w', 'm', 'a', '1' ): tk->psz_name = "Windows Media Audio v1"; tk->i_tag = WAVE_FORMAT_WMA1; - tk->b_audio_correction = VLC_TRUE; + tk->b_audio_correction = true; break; case VLC_FOURCC( 'w', 'm', 'a', ' ' ): case VLC_FOURCC( 'w', 'm', 'a', '2' ): tk->psz_name= "Windows Media Audio (v2) 7, 8 and 9 Series"; tk->i_tag = WAVE_FORMAT_WMA2; - tk->b_audio_correction = VLC_TRUE; + tk->b_audio_correction = true; break; case VLC_FOURCC( 'w', 'm', 'a', 'p' ): tk->psz_name = "Windows Media Audio 9 Professional"; tk->i_tag = WAVE_FORMAT_WMAP; - tk->b_audio_correction = VLC_TRUE; + tk->b_audio_correction = true; break; case VLC_FOURCC( 'w', 'm', 'a', 'l' ): tk->psz_name = "Windows Media Audio 9 Lossless"; tk->i_tag = WAVE_FORMAT_WMAL; - tk->b_audio_correction = VLC_TRUE; + tk->b_audio_correction = true; break; /* raw codec */ case VLC_FOURCC( 'u', '8', ' ', ' ' ): @@ -475,6 +491,8 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) { p_sys->i_bitrate += 512000; } + if (p_sys->i_bitrate_override) + p_sys->i_bitrate = p_sys->i_bitrate_override; break; } case VIDEO_ES: @@ -559,6 +577,8 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) { p_sys->i_bitrate += 1000000; } + if (p_sys->i_bitrate_override) + p_sys->i_bitrate = p_sys->i_bitrate_override; break; } default: @@ -577,6 +597,27 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) *****************************************************************************/ static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input ) { + /* if bitrate ain't defined in commanline, reduce it when tracks are deleted + */ + sout_mux_sys_t *p_sys = p_mux->p_sys; + asf_track_t *tk = p_input->p_sys; + if(!p_sys->i_bitrate_override) + { + if( tk->i_cat == AUDIO_ES ) + { + if( p_input->p_fmt->i_bitrate > 24000 ) + p_sys->i_bitrate -= p_input->p_fmt->i_bitrate; + else + p_sys->i_bitrate -= 512000; + } + else if(tk->i_cat == VIDEO_ES ) + { + if( p_input->p_fmt->i_bitrate > 50000 ) + p_sys->i_bitrate -= p_input->p_fmt->i_bitrate; + else + p_sys->i_bitrate -= 1000000; + } + } msg_Dbg( p_mux, "removing input" ); return VLC_SUCCESS; } @@ -590,12 +631,12 @@ static int Mux( sout_mux_t *p_mux ) if( p_sys->b_write_header ) { - block_t *out = asf_header_create( p_mux, VLC_TRUE ); + block_t *out = asf_header_create( p_mux, true ); out->i_flags |= BLOCK_FLAG_HEADER; sout_AccessOutWrite( p_mux->p_access, out ); - p_sys->b_write_header = VLC_FALSE; + p_sys->b_write_header = false; } for( ;; ) @@ -803,7 +844,7 @@ static void asf_chunk_add( bo_t *bo, bo_addle_u16( bo, i_len + 8 ); } -static block_t *asf_header_create( sout_mux_t *p_mux, vlc_bool_t b_broadcast ) +static block_t *asf_header_create( sout_mux_t *p_mux, bool b_broadcast ) { sout_mux_sys_t *p_sys = p_mux->p_sys; asf_track_t *tk;