Commit 04e9853a authored by Luca Barbato's avatar Luca Barbato

wmavoice: return meaningful error codes

parent 7d65e960
...@@ -354,7 +354,7 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx) ...@@ -354,7 +354,7 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
av_log(ctx, AV_LOG_ERROR, av_log(ctx, AV_LOG_ERROR,
"Invalid extradata size %d (should be 46)\n", "Invalid extradata size %d (should be 46)\n",
ctx->extradata_size); ctx->extradata_size);
return -1; return AVERROR_INVALIDDATA;
} }
flags = AV_RL32(ctx->extradata + 18); flags = AV_RL32(ctx->extradata + 18);
s->spillover_bitsize = 3 + av_ceil_log2(ctx->block_align); s->spillover_bitsize = 3 + av_ceil_log2(ctx->block_align);
...@@ -377,7 +377,7 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx) ...@@ -377,7 +377,7 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
av_log(ctx, AV_LOG_ERROR, av_log(ctx, AV_LOG_ERROR,
"Invalid denoise filter strength %d (max=11)\n", "Invalid denoise filter strength %d (max=11)\n",
s->denoise_strength); s->denoise_strength);
return -1; return AVERROR_INVALIDDATA;
} }
s->denoise_tilt_corr = !!(flags & 0x40); s->denoise_tilt_corr = !!(flags & 0x40);
s->dc_level = (flags >> 7) & 0xF; s->dc_level = (flags >> 7) & 0xF;
...@@ -399,7 +399,7 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx) ...@@ -399,7 +399,7 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
init_get_bits(&s->gb, ctx->extradata + 22, (ctx->extradata_size - 22) << 3); init_get_bits(&s->gb, ctx->extradata + 22, (ctx->extradata_size - 22) << 3);
if (decode_vbmtree(&s->gb, s->vbm_tree) < 0) { if (decode_vbmtree(&s->gb, s->vbm_tree) < 0) {
av_log(ctx, AV_LOG_ERROR, "Invalid VBM tree; broken extradata?\n"); av_log(ctx, AV_LOG_ERROR, "Invalid VBM tree; broken extradata?\n");
return -1; return AVERROR_INVALIDDATA;
} }
s->min_pitch_val = ((ctx->sample_rate << 8) / 400 + 50) >> 8; s->min_pitch_val = ((ctx->sample_rate << 8) / 400 + 50) >> 8;
...@@ -407,7 +407,7 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx) ...@@ -407,7 +407,7 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
pitch_range = s->max_pitch_val - s->min_pitch_val; pitch_range = s->max_pitch_val - s->min_pitch_val;
if (pitch_range <= 0) { if (pitch_range <= 0) {
av_log(ctx, AV_LOG_ERROR, "Invalid pitch range; broken extradata?\n"); av_log(ctx, AV_LOG_ERROR, "Invalid pitch range; broken extradata?\n");
return -1; return AVERROR_INVALIDDATA;
} }
s->pitch_nbits = av_ceil_log2(pitch_range); s->pitch_nbits = av_ceil_log2(pitch_range);
s->last_pitch_val = 40; s->last_pitch_val = 40;
...@@ -422,7 +422,7 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx) ...@@ -422,7 +422,7 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
"Unsupported samplerate %d (min=%d, max=%d)\n", "Unsupported samplerate %d (min=%d, max=%d)\n",
ctx->sample_rate, min_sr, max_sr); // 322-22097 Hz ctx->sample_rate, min_sr, max_sr); // 322-22097 Hz
return -1; return AVERROR(ENOSYS);
} }
s->block_conv_table[0] = s->min_pitch_val; s->block_conv_table[0] = s->min_pitch_val;
...@@ -432,7 +432,7 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx) ...@@ -432,7 +432,7 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
s->block_delta_pitch_hrange = (pitch_range >> 3) & ~0xF; s->block_delta_pitch_hrange = (pitch_range >> 3) & ~0xF;
if (s->block_delta_pitch_hrange <= 0) { if (s->block_delta_pitch_hrange <= 0) {
av_log(ctx, AV_LOG_ERROR, "Invalid delta pitch hrange; broken extradata?\n"); av_log(ctx, AV_LOG_ERROR, "Invalid delta pitch hrange; broken extradata?\n");
return -1; return AVERROR_INVALIDDATA;
} }
s->block_delta_pitch_nbits = 1 + av_ceil_log2(s->block_delta_pitch_hrange); s->block_delta_pitch_nbits = 1 + av_ceil_log2(s->block_delta_pitch_hrange);
s->block_pitch_range = s->block_conv_table[2] + s->block_pitch_range = s->block_conv_table[2] +
...@@ -1447,7 +1447,7 @@ static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx, ...@@ -1447,7 +1447,7 @@ static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx,
if (bd_idx < 0) { if (bd_idx < 0) {
av_log(ctx, AV_LOG_ERROR, av_log(ctx, AV_LOG_ERROR,
"Invalid frame type VLC code, skipping\n"); "Invalid frame type VLC code, skipping\n");
return -1; return AVERROR_INVALIDDATA;
} }
block_nsamples = MAX_FRAMESIZE / frame_descs[bd_idx].n_blocks; block_nsamples = MAX_FRAMESIZE / frame_descs[bd_idx].n_blocks;
...@@ -1644,7 +1644,7 @@ static void stabilize_lsps(double *lsps, int num) ...@@ -1644,7 +1644,7 @@ static void stabilize_lsps(double *lsps, int num)
* does not modify the state of the bitreader; it * does not modify the state of the bitreader; it
* only uses it to copy the current stream position * only uses it to copy the current stream position
* @param s WMA Voice decoding context private data * @param s WMA Voice decoding context private data
* @return -1 if unsupported, 1 on not enough bits or 0 if OK. * @return < 0 on error, 1 on not enough bits or 0 if OK.
*/ */
static int check_bits_for_superframe(GetBitContext *orig_gb, static int check_bits_for_superframe(GetBitContext *orig_gb,
WMAVoiceContext *s) WMAVoiceContext *s)
...@@ -1662,7 +1662,7 @@ static int check_bits_for_superframe(GetBitContext *orig_gb, ...@@ -1662,7 +1662,7 @@ static int check_bits_for_superframe(GetBitContext *orig_gb,
if (get_bits_left(gb) < 14) if (get_bits_left(gb) < 14)
return 1; return 1;
if (!get_bits1(gb)) if (!get_bits1(gb))
return -1; // WMAPro-in-WMAVoice superframe return AVERROR(ENOSYS); // WMAPro-in-WMAVoice superframe
if (get_bits1(gb)) skip_bits(gb, 12); // number of samples in superframe if (get_bits1(gb)) skip_bits(gb, 12); // number of samples in superframe
if (s->has_residual_lsps) { // residual LSPs (for all frames) if (s->has_residual_lsps) { // residual LSPs (for all frames)
if (get_bits_left(gb) < s->sframe_lsp_bitsize) if (get_bits_left(gb) < s->sframe_lsp_bitsize)
...@@ -1680,7 +1680,7 @@ static int check_bits_for_superframe(GetBitContext *orig_gb, ...@@ -1680,7 +1680,7 @@ static int check_bits_for_superframe(GetBitContext *orig_gb,
} }
bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)]; bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)];
if (bd_idx < 0) if (bd_idx < 0)
return -1; // invalid frame type VLC code return AVERROR_INVALIDDATA; // invalid frame type VLC code
frame_desc = &frame_descs[bd_idx]; frame_desc = &frame_descs[bd_idx];
if (frame_desc->acb_type == ACB_TYPE_ASYMMETRIC) { if (frame_desc->acb_type == ACB_TYPE_ASYMMETRIC) {
if (get_bits_left(gb) < s->pitch_nbits) if (get_bits_left(gb) < s->pitch_nbits)
...@@ -1758,7 +1758,8 @@ static int synth_superframe(AVCodecContext *ctx, AVFrame *frame, ...@@ -1758,7 +1758,8 @@ static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,
if ((res = check_bits_for_superframe(gb, s)) == 1) { if ((res = check_bits_for_superframe(gb, s)) == 1) {
*got_frame_ptr = 0; *got_frame_ptr = 0;
return 1; return 1;
} } else if (res < 0)
return res;
/* First bit is speech/music bit, it differentiates between WMAVoice /* First bit is speech/music bit, it differentiates between WMAVoice
* speech samples (the actual codec) and WMAVoice music samples, which * speech samples (the actual codec) and WMAVoice music samples, which
...@@ -1775,7 +1776,7 @@ static int synth_superframe(AVCodecContext *ctx, AVFrame *frame, ...@@ -1775,7 +1776,7 @@ static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,
av_log(ctx, AV_LOG_ERROR, av_log(ctx, AV_LOG_ERROR,
"Superframe encodes >480 samples (%d), not allowed\n", "Superframe encodes >480 samples (%d), not allowed\n",
n_samples); n_samples);
return -1; return AVERROR_INVALIDDATA;
} }
} }
/* Parse LSPs, if global for the superframe (can also be per-frame). */ /* Parse LSPs, if global for the superframe (can also be per-frame). */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment