mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-13 21:28:01 +02:00
libvorbis: proper error logging and return.
This commit is contained in:
parent
42a1f1d7a8
commit
0098e79f8a
@ -61,38 +61,59 @@ static const AVOption options[] = {
|
|||||||
};
|
};
|
||||||
static const AVClass class = { "libvorbis", av_default_item_name, options, LIBAVUTIL_VERSION_INT };
|
static const AVClass class = { "libvorbis", av_default_item_name, options, LIBAVUTIL_VERSION_INT };
|
||||||
|
|
||||||
|
static const char * error(int oggerr, int *averr)
|
||||||
|
{
|
||||||
|
switch (oggerr) {
|
||||||
|
case OV_EFAULT: *averr = AVERROR(EFAULT); return "internal error";
|
||||||
|
case OV_EIMPL: *averr = AVERROR(EINVAL); return "not supported";
|
||||||
|
case OV_EINVAL: *averr = AVERROR(EINVAL); return "invalid request";
|
||||||
|
default: *averr = AVERROR(EINVAL); return "unknown error";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext)
|
static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext)
|
||||||
{
|
{
|
||||||
OggVorbisContext *context = avccontext->priv_data;
|
OggVorbisContext *context = avccontext->priv_data;
|
||||||
double cfreq;
|
double cfreq;
|
||||||
|
int r;
|
||||||
|
|
||||||
if (avccontext->flags & CODEC_FLAG_QSCALE) {
|
if (avccontext->flags & CODEC_FLAG_QSCALE) {
|
||||||
/* variable bitrate */
|
/* variable bitrate */
|
||||||
if (vorbis_encode_setup_vbr(vi, avccontext->channels,
|
float quality = avccontext->global_quality / (float)FF_QP2LAMBDA;
|
||||||
|
r = vorbis_encode_setup_vbr(vi, avccontext->channels,
|
||||||
avccontext->sample_rate,
|
avccontext->sample_rate,
|
||||||
avccontext->global_quality / (float)FF_QP2LAMBDA / 10.0))
|
quality / 10.0);
|
||||||
return -1;
|
if (r) {
|
||||||
|
av_log(avccontext, AV_LOG_ERROR,
|
||||||
|
"Unable to set quality to %g: %s\n", quality, error(r, &r));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
int minrate = avccontext->rc_min_rate > 0 ? avccontext->rc_min_rate : -1;
|
int minrate = avccontext->rc_min_rate > 0 ? avccontext->rc_min_rate : -1;
|
||||||
int maxrate = avccontext->rc_min_rate > 0 ? avccontext->rc_max_rate : -1;
|
int maxrate = avccontext->rc_min_rate > 0 ? avccontext->rc_max_rate : -1;
|
||||||
|
|
||||||
/* constant bitrate */
|
/* constant bitrate */
|
||||||
if (vorbis_encode_setup_managed(vi, avccontext->channels,
|
r = vorbis_encode_setup_managed(vi, avccontext->channels,
|
||||||
avccontext->sample_rate, minrate,
|
avccontext->sample_rate, minrate,
|
||||||
avccontext->bit_rate, maxrate))
|
avccontext->bit_rate, maxrate);
|
||||||
return -1;
|
if (r) {
|
||||||
|
av_log(avccontext, AV_LOG_ERROR,
|
||||||
|
"Unable to set CBR to %d: %s\n", avccontext->bit_rate,
|
||||||
|
error(r, &r));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/* variable bitrate by estimate, disable slow rate management */
|
/* variable bitrate by estimate, disable slow rate management */
|
||||||
if (minrate == -1 && maxrate == -1)
|
if (minrate == -1 && maxrate == -1)
|
||||||
if (vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL))
|
if (vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL))
|
||||||
return -1;
|
return AVERROR(EINVAL); /* should not happen */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cutoff frequency */
|
/* cutoff frequency */
|
||||||
if (avccontext->cutoff > 0) {
|
if (avccontext->cutoff > 0) {
|
||||||
cfreq = avccontext->cutoff / 1000.0;
|
cfreq = avccontext->cutoff / 1000.0;
|
||||||
if (vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq))
|
if (vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq))
|
||||||
return -1;
|
return AVERROR(EINVAL); /* should not happen */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context->iblock) {
|
if (context->iblock) {
|
||||||
@ -143,11 +164,13 @@ static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext)
|
|||||||
ogg_packet header, header_comm, header_code;
|
ogg_packet header, header_comm, header_code;
|
||||||
uint8_t *p;
|
uint8_t *p;
|
||||||
unsigned int offset;
|
unsigned int offset;
|
||||||
|
int r;
|
||||||
|
|
||||||
vorbis_info_init(&context->vi);
|
vorbis_info_init(&context->vi);
|
||||||
if (oggvorbis_init_encoder(&context->vi, avccontext) < 0) {
|
r = oggvorbis_init_encoder(&context->vi, avccontext);
|
||||||
av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder failed\n");
|
if (r < 0) {
|
||||||
return -1;
|
av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init failed\n");
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
vorbis_analysis_init(&context->vd, &context->vi);
|
vorbis_analysis_init(&context->vd, &context->vi);
|
||||||
vorbis_block_init(&context->vd, &context->vb);
|
vorbis_block_init(&context->vd, &context->vb);
|
||||||
@ -228,8 +251,8 @@ static int oggvorbis_encode_frame(AVCodecContext *avccontext,
|
|||||||
if (op.bytes == 1 && op.e_o_s)
|
if (op.bytes == 1 && op.e_o_s)
|
||||||
continue;
|
continue;
|
||||||
if (context->buffer_index + sizeof(ogg_packet) + op.bytes > BUFFER_SIZE) {
|
if (context->buffer_index + sizeof(ogg_packet) + op.bytes > BUFFER_SIZE) {
|
||||||
av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow.");
|
av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow.\n");
|
||||||
return -1;
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet));
|
memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet));
|
||||||
context->buffer_index += sizeof(ogg_packet);
|
context->buffer_index += sizeof(ogg_packet);
|
||||||
@ -249,8 +272,8 @@ static int oggvorbis_encode_frame(AVCodecContext *avccontext,
|
|||||||
//FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate
|
//FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate
|
||||||
|
|
||||||
if (l > buf_size) {
|
if (l > buf_size) {
|
||||||
av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow.");
|
av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow.\n");
|
||||||
return -1;
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(packets, op2->packet, l);
|
memcpy(packets, op2->packet, l);
|
||||||
|
Loading…
Reference in New Issue
Block a user