comparison utils.c @ 4351:1e251b54cba2 libavcodec

avcodec_decode_audio2() difference to avcodec_decode_audio() is that the user can pass the allocated size of the output buffer to the decoder and the decoder can check if theres enough space
author michael
date Sun, 14 Jan 2007 23:50:06 +0000
parents a3a9e4996276
children 22827cd6b228
comparison
equal deleted inserted replaced
4350:a3a9e4996276 4351:1e251b54cba2
916 916
917 /* decode an audio frame. return -1 if error, otherwise return the 917 /* decode an audio frame. return -1 if error, otherwise return the
918 *number of bytes used. If no frame could be decompressed, 918 *number of bytes used. If no frame could be decompressed,
919 *frame_size_ptr is zero. Otherwise, it is the decompressed frame 919 *frame_size_ptr is zero. Otherwise, it is the decompressed frame
920 *size in BYTES. */ 920 *size in BYTES. */
921 int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, 921 int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
922 int *frame_size_ptr, 922 int *frame_size_ptr,
923 uint8_t *buf, int buf_size) 923 uint8_t *buf, int buf_size)
924 { 924 {
925 int ret; 925 int ret;
926 926
927 *frame_size_ptr= 0; 927 //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
928 if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
929 av_log(avctx, AV_LOG_ERROR, "buffer smaller then AVCODEC_MAX_AUDIO_FRAME_SIZE\n");
930 return -1;
931 }
932 if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
933 *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t) ||
934 *frame_size_ptr < buf_size){
935 av_log(avctx, AV_LOG_ERROR, "buffer too small\n");
936 return -1;
937 }
928 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){ 938 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
929 ret = avctx->codec->decode(avctx, samples, frame_size_ptr, 939 ret = avctx->codec->decode(avctx, samples, frame_size_ptr,
930 buf, buf_size); 940 buf, buf_size);
931 avctx->frame_number++; 941 avctx->frame_number++;
932 }else 942 }else{
933 ret= 0; 943 ret= 0;
944 *frame_size_ptr=0;
945 }
934 return ret; 946 return ret;
935 } 947 }
948
949 #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
950 int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
951 int *frame_size_ptr,
952 uint8_t *buf, int buf_size){
953 *frame_size_ptr= AVCODEC_MAX_AUDIO_FRAME_SIZE;
954 return avcodec_decode_audio2(avctx, samples, frame_size_ptr, buf, buf_size);
955 }
956 #endif
957
936 958
937 /* decode a subtitle message. return -1 if error, otherwise return the 959 /* decode a subtitle message. return -1 if error, otherwise return the
938 *number of bytes used. If no subtitle could be decompressed, 960 *number of bytes used. If no subtitle could be decompressed,
939 *got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */ 961 *got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */
940 int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub, 962 int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,