- return p_block;
- }
-
- return NULL;
-}
-
-/*****************************************************************************
- * CloseVideoEncoder: ffmpeg video encoder destruction
- *****************************************************************************/
-void E_(CloseVideoEncoder)( vlc_object_t *p_this )
-{
- encoder_t *p_enc = (encoder_t *)p_this;
- encoder_sys_t *p_sys = p_enc->p_sys;
-
- avcodec_close( p_sys->p_context );
- free( p_sys->p_context );
- free( p_sys->p_buffer_out );
- free( p_sys );
-}
-
-/*****************************************************************************
- * OpenAudioEncoder: probe the encoder
- *****************************************************************************/
-int E_(OpenAudioEncoder)( vlc_object_t *p_this )
-{
- encoder_t *p_enc = (encoder_t *)p_this;
- encoder_sys_t *p_sys;
- AVCodecContext *p_context;
- AVCodec *p_codec;
- int i_codec_id, i_cat;
- char *psz_namecodec;
-
- if( !E_(GetFfmpegCodec)( p_enc->i_fourcc, &i_cat, &i_codec_id,
- &psz_namecodec ) )
- {
- return VLC_EGENERIC;
- }
-
- if( i_cat != AUDIO_ES )
- {
- msg_Err( p_enc, "\"%s\" is not an audio encoder", psz_namecodec );
- return VLC_EGENERIC;
- }
-
- /* Initialization must be done before avcodec_find_decoder() */
- E_(InitLibavcodec)(p_this);
-
- p_codec = avcodec_find_encoder( i_codec_id );
- if( !p_codec )
- {
- msg_Err( p_enc, "cannot find encoder %s", psz_namecodec );
- return VLC_EGENERIC;
- }
-
- /* Allocate the memory needed to store the decoder's structure */
- if( ( p_sys = (encoder_sys_t *)malloc(sizeof(encoder_sys_t)) ) == NULL )
- {
- msg_Err( p_enc, "out of memory" );
- return VLC_EGENERIC;
- }
- p_enc->p_sys = p_sys;
- p_sys->p_codec = p_codec;
-
- p_enc->pf_header = NULL;
- p_enc->pf_encode_audio = EncodeAudio;
- p_enc->format.audio.i_format = VLC_FOURCC('s','1','6','n');
-
- p_sys->p_context = p_context = avcodec_alloc_context();
- p_context->bit_rate = p_enc->i_bitrate;
- p_context->sample_rate = p_enc->format.audio.i_rate;
- p_context->channels =
- aout_FormatNbChannels( &p_enc->format.audio );
-
- /* Make sure we get extradata filled by the encoder */
- p_context->extradata_size = 0;
- p_context->extradata = NULL;
- p_context->flags |= CODEC_FLAG_GLOBAL_HEADER;
-
- if( avcodec_open( p_context, p_codec ) < 0 )
- {
- if( p_context->channels > 2 )
- {
- p_context->channels = 2;
- //id->f_dst.i_channels = 2;
- if( avcodec_open( p_context, p_codec ) < 0 )
- {
- msg_Err( p_enc, "cannot open encoder" );
- return VLC_EGENERIC;
- }
- msg_Warn( p_enc, "stereo mode selected (codec limitation)" );
- }
- else