[06/12] libopencore-amr, libvo-amrwbenc: Return proper error return codes in most places

Message ID 1302645498-12642-6-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö April 12, 2011, 9:58 p.m.
---
 libavcodec/libopencore-amr.c |   16 ++++++++--------
 libavcodec/libvo-amrwbenc.c  |    8 ++++----
 2 files changed, 12 insertions(+), 12 deletions(-)

Comments

Ronald Bultje April 12, 2011, 11:38 p.m. | #1
Hi,

On Tue, Apr 12, 2011 at 5:58 PM, Martin Storsjö <martin@martin.st> wrote:
> ---
>  libavcodec/libopencore-amr.c |   16 ++++++++--------
>  libavcodec/libvo-amrwbenc.c  |    8 ++++----
>  2 files changed, 12 insertions(+), 12 deletions(-)

All OK.

>     if (avctx->sample_rate != 8000) {
>         av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n");
> -        return -1;
> +        return AVERROR(ENOSYS);
>     }

That (and similar checks for samplerate elsewhere) are a little crazy,
for me personally a warning would be good enough. But I won't insist
that it be changed, just thought it was weird...

Ronald

Patch

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index e6958c9..8a8c18b 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -90,7 +90,7 @@  static av_cold int amr_nb_decode_init(AVCodecContext *avctx)
 
     if (avctx->channels > 1) {
         av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n");
-        return -1;
+        return AVERROR(ENOSYS);
     }
 
     return 0;
@@ -121,7 +121,7 @@  static int amr_nb_decode_frame(AVCodecContext *avctx, void *data,
     if (packet_size > buf_size) {
         av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n",
                buf_size, packet_size);
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     /* call decoder */
@@ -149,12 +149,12 @@  static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
 
     if (avctx->sample_rate != 8000) {
         av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n");
-        return -1;
+        return AVERROR(ENOSYS);
     }
 
     if (avctx->channels != 1) {
         av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
-        return -1;
+        return AVERROR(ENOSYS);
     }
 
     avctx->frame_size  = 160;
@@ -168,7 +168,7 @@  static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
 
     if ((s->enc_bitrate = getBitrateMode(avctx->bit_rate)) < 0) {
         av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported);
-        return -1;
+        return AVERROR(ENOSYS);
     }
 
     return 0;
@@ -192,7 +192,7 @@  static int amr_nb_encode_frame(AVCodecContext *avctx,
 
     if ((s->enc_bitrate = getBitrateMode(avctx->bit_rate)) < 0) {
         av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported);
-        return -1;
+        return AVERROR(ENOSYS);
     }
 
     written = Encoder_Interface_Encode(s->enstate, s->enc_bitrate, data,
@@ -236,7 +236,7 @@  static av_cold int amr_wb_decode_init(AVCodecContext *avctx)
 
     if (avctx->channels > 1) {
         av_log(avctx, AV_LOG_ERROR, "amr_wb: multichannel decoding not supported\n");
-        return -1;
+        return AVERROR(ENOSYS);
     }
 
     return 0;
@@ -263,7 +263,7 @@  static int amr_wb_decode_frame(AVCodecContext *avctx, void *data,
     if (packet_size > buf_size) {
         av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n",
                buf_size, packet_size + 1);
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     D_IF_decode(s->state, amrData, data, _good_frame);
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index 661a15d..a5e8f39 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -65,17 +65,17 @@  static av_cold int amr_wb_encode_init(AVCodecContext *avctx)
 
     if (avctx->sample_rate != 16000) {
         av_log(avctx, AV_LOG_ERROR, "Only 16000Hz sample rate supported\n");
-        return -1;
+        return AVERROR(ENOSYS);
     }
 
     if (avctx->channels != 1) {
         av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
-        return -1;
+        return AVERROR(ENOSYS);
     }
 
     if ((s->mode = getWBBitrateMode(avctx->bit_rate)) < 0) {
         av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported);
-        return -1;
+        return AVERROR(ENOSYS);
     }
 
     avctx->frame_size  = 320;
@@ -105,7 +105,7 @@  static int amr_wb_encode_frame(AVCodecContext *avctx,
 
     if ((s->mode = getWBBitrateMode(avctx->bit_rate)) < 0) {
         av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported);
-        return -1;
+        return AVERROR(ENOSYS);
     }
     size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx);
     return size;