[FFmpeg-cvslog] libopencore-amr, libvo-amrwbenc: Only check the bitrate when changed
Martin Storsjö
git at videolan.org
Thu Apr 14 03:24:38 CEST 2011
ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Wed Apr 13 11:03:19 2011 +0300| [3dd82afc748df0f1c49b76e1cd4ea6e35b1001a5] | committer: Martin Storsjö
libopencore-amr, libvo-amrwbenc: Only check the bitrate when changed
Also rename the incorrectly named enc_bitrate to enc_mode, use the
enc_bitrate variable for storing the last chosen bitrate.
This avoids continuous warning log messages if not using an
exactly matching bitrate, while still allowing changing bitrate
at any point.
Signed-off-by: Martin Storsjö <martin at martin.st>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3dd82afc748df0f1c49b76e1cd4ea6e35b1001a5
---
libavcodec/libopencore-amr.c | 13 +++++++++----
libavcodec/libvo-amrwbenc.c | 9 +++++++--
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index e6216c9..c8b3a2c 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -81,6 +81,7 @@ typedef struct AMRContext {
void *dec_state;
void *enc_state;
int enc_bitrate;
+ int enc_mode;
} AMRContext;
static av_cold int amr_nb_decode_init(AVCodecContext *avctx)
@@ -181,7 +182,8 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
return -1;
}
- s->enc_bitrate = get_bitrate_mode(avctx->bit_rate, avctx);
+ s->enc_mode = get_bitrate_mode(avctx->bit_rate, avctx);
+ s->enc_bitrate = avctx->bit_rate;
return 0;
}
@@ -202,12 +204,15 @@ static int amr_nb_encode_frame(AVCodecContext *avctx,
AMRContext *s = avctx->priv_data;
int written;
- s->enc_bitrate = get_bitrate_mode(avctx->bit_rate, avctx);
+ if (s->enc_bitrate != avctx->bit_rate) {
+ s->enc_mode = get_bitrate_mode(avctx->bit_rate, avctx);
+ s->enc_bitrate = avctx->bit_rate;
+ }
- written = Encoder_Interface_Encode(s->enc_state, s->enc_bitrate, data,
+ written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, data,
frame, 0);
av_dlog(avctx, "amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",
- written, s->enc_bitrate, frame[0]);
+ written, s->enc_mode, frame[0]);
return written;
}
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index b194bf0..d3db5f8 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -27,6 +27,7 @@
typedef struct AMRWBContext {
void *state;
int mode;
+ int last_bitrate;
int allow_dtx;
} AMRWBContext;
@@ -70,7 +71,8 @@ static av_cold int amr_wb_encode_init(AVCodecContext *avctx)
return AVERROR(ENOSYS);
}
- s->mode = get_wb_bitrate_mode(avctx->bit_rate, avctx);
+ s->mode = get_wb_bitrate_mode(avctx->bit_rate, avctx);
+ s->last_bitrate = avctx->bit_rate;
avctx->frame_size = 320;
avctx->coded_frame = avcodec_alloc_frame();
@@ -97,7 +99,10 @@ static int amr_wb_encode_frame(AVCodecContext *avctx,
AMRWBContext *s = avctx->priv_data;
int size;
- s->mode = get_wb_bitrate_mode(avctx->bit_rate, avctx);
+ if (s->last_bitrate != avctx->bit_rate) {
+ s->mode = get_wb_bitrate_mode(avctx->bit_rate, avctx);
+ s->last_bitrate = avctx->bit_rate;
+ }
size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx);
return size;
}
More information about the ffmpeg-cvslog
mailing list