On Sat, 25 Feb 2012 00:05:56 -0500, Justin Ruggles <[email protected]> wrote: > --- > libavcodec/libvorbis.c | 112 > ++++++++++++++++++++++++++++++++---------------- > 1 files changed, 75 insertions(+), 37 deletions(-) > > diff --git a/libavcodec/libvorbis.c b/libavcodec/libvorbis.c > index b60b1f0..736612f 100644 > --- a/libavcodec/libvorbis.c > +++ b/libavcodec/libvorbis.c > @@ -61,45 +61,61 @@ static const AVOption options[] = { > }; > static const AVClass class = { "libvorbis", av_default_item_name, options, > LIBAVUTIL_VERSION_INT }; > > +static int vorbis_error_to_averror(int ov_err) > +{ > + switch (ov_err) { > + case OV_EFAULT: return AVERROR_BUG; > + case OV_EINVAL: return AVERROR(EINVAL); > + case OV_EIMPL: return AVERROR(EINVAL); > + default: return AVERROR_UNKNOWN; > + } > +} > + > static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext > *avccontext) > { > OggVorbisContext *context = avccontext->priv_data; > double cfreq; > + int ret; > > if (avccontext->flags & CODEC_FLAG_QSCALE) { > /* variable bitrate */ > - if (vorbis_encode_setup_vbr(vi, avccontext->channels, > - avccontext->sample_rate, > - avccontext->global_quality / > (float)FF_QP2LAMBDA / 10.0)) > - return -1; > + float q = avccontext->global_quality / (float)FF_QP2LAMBDA; > + if ((ret = vorbis_encode_setup_vbr(vi, avccontext->channels, > + avccontext->sample_rate, > + q / 10.0))) > + return vorbis_error_to_averror(ret); > } else { > int minrate = avccontext->rc_min_rate > 0 ? avccontext->rc_min_rate > : -1; > int maxrate = avccontext->rc_min_rate > 0 ? avccontext->rc_max_rate > : -1; > > /* constant bitrate */ > - if (vorbis_encode_setup_managed(vi, avccontext->channels, > - avccontext->sample_rate, minrate, > - avccontext->bit_rate, maxrate)) > - return -1; > + if ((ret = vorbis_encode_setup_managed(vi, avccontext->channels, > + avccontext->sample_rate, > minrate, > + avccontext->bit_rate, > maxrate))) > + return vorbis_error_to_averror(ret); > > /* variable bitrate by estimate, disable slow rate management */ > if (minrate == -1 && maxrate == -1) > - if (vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL)) > - return -1; > + if ((ret = vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL))) > + return vorbis_error_to_averror(ret); > } > > /* cutoff frequency */ > if (avccontext->cutoff > 0) { > cfreq = avccontext->cutoff / 1000.0; > - if (vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)) > - return -1; > + if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq))) > + return vorbis_error_to_averror(ret); > } > > if (context->iblock) { > - vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->iblock); > + if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, > &context->iblock))) > + return vorbis_error_to_averror(ret); > } > > - return vorbis_encode_setup_init(vi); > + if ((ret = vorbis_encode_setup_init(vi))) > + return vorbis_error_to_averror(ret); > + > + return 0; > } > > /* How many bytes are needed for a buffer of length 'l' */ > @@ -108,32 +124,64 @@ static int xiph_len(int l) > return 1 + l / 255 + l; > } > > +static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext) > +{ > + OggVorbisContext *context = avccontext->priv_data; > +/* ogg_packet op ; */ > + > + vorbis_analysis_wrote(&context->vd, 0); /* notify vorbisenc this is EOF > */ > + > + vorbis_block_clear(&context->vb); > + vorbis_dsp_clear(&context->vd); > + vorbis_info_clear(&context->vi); > + > + av_freep(&avccontext->coded_frame); > + av_freep(&avccontext->extradata); > + > + return 0; > +} > + > static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) > { > OggVorbisContext *context = avccontext->priv_data; > ogg_packet header, header_comm, header_code; > uint8_t *p; > unsigned int offset; > + int ret; > > vorbis_info_init(&context->vi); > - if (oggvorbis_init_encoder(&context->vi, avccontext) < 0) { > + if ((ret = oggvorbis_init_encoder(&context->vi, avccontext))) { > av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: > init_encoder failed\n"); > - return -1; > + ret = vorbis_error_to_averror(ret);
Wait, this one is already converted to AVERROR. -- Anton Khirnov _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
