Mercurial > libavcodec.hg
changeset 9651:e5ea408f6e2a libavcodec
cosmetics: Move functions around so that encoding and decoding functions are
grouped together. This will save some #ifdefs.
author | diego |
---|---|
date | Fri, 15 May 2009 17:34:26 +0000 |
parents | 531474d55492 |
children | 356079de3642 |
files | libamr.c |
diffstat | 1 files changed, 66 insertions(+), 66 deletions(-) [+] |
line wrap: on
line diff
--- a/libamr.c Fri May 15 17:22:41 2009 +0000 +++ b/libamr.c Fri May 15 17:34:26 2009 +0000 @@ -148,6 +148,58 @@ return 0; } +static av_cold int amr_nb_decode_close(AVCodecContext * avctx) +{ + AMRContext *s = avctx->priv_data; + + Decoder_Interface_exit(s->decState); + return 0; +} + +static int amr_nb_decode_frame(AVCodecContext * avctx, + void *data, int *data_size, + AVPacket *avpkt) +{ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + AMRContext *s = avctx->priv_data; + const uint8_t*amrData=buf; + static const uint8_t block_size[16]={ 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; + enum Mode dec_mode; + int packet_size; + + /* av_log(NULL,AV_LOG_DEBUG,"amr_decode_frame buf=%p buf_size=%d frameCount=%d!!\n",buf,buf_size,s->frameCount); */ + + dec_mode = (buf[0] >> 3) & 0x000F; + packet_size = block_size[dec_mode]+1; + + 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; + } + + s->frameCount++; + /* av_log(NULL,AV_LOG_DEBUG,"packet_size=%d amrData= 0x%X %X %X %X\n",packet_size,amrData[0],amrData[1],amrData[2],amrData[3]); */ + /* call decoder */ + Decoder_Interface_Decode(s->decState, amrData, data, 0); + *data_size=160*2; + + return packet_size; +} + +AVCodec libamr_nb_decoder = +{ + "libamr_nb", + CODEC_TYPE_AUDIO, + CODEC_ID_AMR_NB, + sizeof(AMRContext), + amr_nb_decode_init, + NULL, + amr_nb_decode_close, + amr_nb_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("libamr-nb Adaptive Multi-Rate (AMR) Narrow-Band"), +}; + static av_cold int amr_nb_encode_init(AVCodecContext * avctx) { AMRContext *s = avctx->priv_data; @@ -185,14 +237,6 @@ return 0; } -static av_cold int amr_nb_decode_close(AVCodecContext * avctx) -{ - AMRContext *s = avctx->priv_data; - - Decoder_Interface_exit(s->decState); - return 0; -} - static av_cold int amr_nb_encode_close(AVCodecContext * avctx) { AMRContext *s = avctx->priv_data; @@ -202,37 +246,6 @@ return 0; } -static int amr_nb_decode_frame(AVCodecContext * avctx, - void *data, int *data_size, - AVPacket *avpkt) -{ - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; - AMRContext *s = avctx->priv_data; - const uint8_t*amrData=buf; - static const uint8_t block_size[16]={ 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; - enum Mode dec_mode; - int packet_size; - - /* av_log(NULL,AV_LOG_DEBUG,"amr_decode_frame buf=%p buf_size=%d frameCount=%d!!\n",buf,buf_size,s->frameCount); */ - - dec_mode = (buf[0] >> 3) & 0x000F; - packet_size = block_size[dec_mode]+1; - - 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; - } - - s->frameCount++; - /* av_log(NULL,AV_LOG_DEBUG,"packet_size=%d amrData= 0x%X %X %X %X\n",packet_size,amrData[0],amrData[1],amrData[2],amrData[3]); */ - /* call decoder */ - Decoder_Interface_Decode(s->decState, amrData, data, 0); - *data_size=160*2; - - return packet_size; -} - static int amr_nb_encode_frame(AVCodecContext *avctx, unsigned char *frame/*out*/, int buf_size, void *data/*in*/) { @@ -255,19 +268,6 @@ return written; } -AVCodec libamr_nb_decoder = -{ - "libamr_nb", - CODEC_TYPE_AUDIO, - CODEC_ID_AMR_NB, - sizeof(AMRContext), - amr_nb_decode_init, - NULL, - amr_nb_decode_close, - amr_nb_decode_frame, - .long_name = NULL_IF_CONFIG_SMALL("libamr-nb Adaptive Multi-Rate (AMR) Narrow-Band"), -}; - AVCodec libamr_nb_encoder = { "libamr_nb", @@ -395,6 +395,20 @@ return size; } +AVCodec libamr_wb_encoder = +{ + "libamr_wb", + CODEC_TYPE_AUDIO, + CODEC_ID_AMR_WB, + sizeof(AMRWBContext), + amr_wb_encode_init, + amr_wb_encode_frame, + amr_wb_encode_close, + NULL, + .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("libamr-wb Adaptive Multi-Rate (AMR) Wide-Band"), +}; + static av_cold int amr_wb_decode_init(AVCodecContext * avctx) { AMRWBContext *s = avctx->priv_data; @@ -465,18 +479,4 @@ .long_name = NULL_IF_CONFIG_SMALL("libamr-wb Adaptive Multi-Rate (AMR) Wide-Band"), }; -AVCodec libamr_wb_encoder = -{ - "libamr_wb", - CODEC_TYPE_AUDIO, - CODEC_ID_AMR_WB, - sizeof(AMRWBContext), - amr_wb_encode_init, - amr_wb_encode_frame, - amr_wb_encode_close, - NULL, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, - .long_name = NULL_IF_CONFIG_SMALL("libamr-wb Adaptive Multi-Rate (AMR) Wide-Band"), -}; - #endif //CONFIG_LIBAMR_WB