[FFmpeg-devel] [PATCH] normalize calls to ff_alloc_packet2

James Zern jzern at google.com
Wed Mar 6 20:11:00 CET 2013


- check ret < 0
- remove excessive error log
---
 libavcodec/aacenc.c          | 4 +---
 libavcodec/ac3enc_template.c | 2 +-
 libavcodec/adpcmenc.c        | 2 +-
 libavcodec/alacenc.c         | 2 +-
 libavcodec/dcaenc.c          | 2 +-
 libavcodec/flacenc.c         | 2 +-
 libavcodec/g722enc.c         | 2 +-
 libavcodec/g723_1.c          | 2 +-
 libavcodec/g726.c            | 2 +-
 libavcodec/libaacplus.c      | 2 +-
 libavcodec/libfaac.c         | 4 +---
 libavcodec/libfdk-aacenc.c   | 2 +-
 libavcodec/libgsm.c          | 2 +-
 libavcodec/libmp3lame.c      | 2 +-
 libavcodec/libopencore-amr.c | 2 +-
 libavcodec/libspeexenc.c     | 2 +-
 libavcodec/libtwolame.c      | 2 +-
 libavcodec/libvo-aacenc.c    | 2 +-
 libavcodec/libvo-amrwbenc.c  | 2 +-
 libavcodec/libvorbisenc.c    | 2 +-
 libavcodec/mpegaudioenc.c    | 2 +-
 libavcodec/nellymoserenc.c   | 2 +-
 libavcodec/pcm.c             | 2 +-
 libavcodec/ra144enc.c        | 2 +-
 libavcodec/roqaudioenc.c     | 2 +-
 libavcodec/sonic.c           | 2 +-
 libavcodec/vorbisenc.c       | 2 +-
 libavcodec/wmaenc.c          | 2 +-
 28 files changed, 28 insertions(+), 32 deletions(-)

diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 5711d01..420d0ce 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -570,10 +570,8 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         }
         start_ch += chans;
     }
-    if ((ret = ff_alloc_packet2(avctx, avpkt, 8192 * s->channels))) {
-        av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
+    if ((ret = ff_alloc_packet2(avctx, avpkt, 8192 * s->channels)) < 0)
         return ret;
-    }
     do {
         int frame_bits;
 
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index fb6aad9..0389c2e 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -435,7 +435,7 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, AVPacket *avpkt,
 
     ff_ac3_quantize_mantissas(s);
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size)) < 0)
         return ret;
     ff_ac3_output_frame(s, avpkt->data);
 
diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c
index 8caedf7..59f016b 100644
--- a/libavcodec/adpcmenc.c
+++ b/libavcodec/adpcmenc.c
@@ -494,7 +494,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         pkt_size = (2 + avctx->channels * (22 + 4 * (frame->nb_samples - 1)) + 7) / 8;
     else
         pkt_size = avctx->block_align;
-    if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size)) < 0)
         return ret;
     dst = avpkt->data;
 
diff --git a/libavcodec/alacenc.c b/libavcodec/alacenc.c
index 61bb65a..4ee558c 100644
--- a/libavcodec/alacenc.c
+++ b/libavcodec/alacenc.c
@@ -613,7 +613,7 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     else
         max_frame_size = s->max_coded_frame_size;
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * max_frame_size)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * max_frame_size)) < 0)
         return ret;
 
     /* use verbatim mode for compression_level 0 */
diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index 2c9daee..4799ef4 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -497,7 +497,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     const int16_t *samples;
     int ret, real_channel = 0;
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, DCA_MAX_FRAME_SIZE + DCA_HEADER_SIZE)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, DCA_MAX_FRAME_SIZE + DCA_HEADER_SIZE)) < 0)
         return ret;
 
     samples = (const int16_t *)frame->data[0];
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index bbdeaad..354a0f7 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -1276,7 +1276,7 @@ static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         }
     }
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, frame_bytes)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, frame_bytes)) < 0)
         return ret;
 
     out_bytes = write_frame(s, avpkt);
diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index 39f83dc..3c47054 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -368,7 +368,7 @@ static int g722_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     int nb_samples, out_size, ret;
 
     out_size = (frame->nb_samples + 1) / 2;
-    if ((ret = ff_alloc_packet2(avctx, avpkt, out_size)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, out_size)) < 0)
         return ret;
 
     nb_samples = frame->nb_samples - (frame->nb_samples & 1);
diff --git a/libavcodec/g723_1.c b/libavcodec/g723_1.c
index 1af2992..d2cde8a 100644
--- a/libavcodec/g723_1.c
+++ b/libavcodec/g723_1.c
@@ -2458,7 +2458,7 @@ static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         offset += LPC_ORDER;
     }
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, 24)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, 24)) < 0)
         return ret;
 
     *got_packet_ptr = 1;
diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index 638a737..995d40a 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -362,7 +362,7 @@ static int g726_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     int i, ret, out_size;
 
     out_size = (frame->nb_samples * c->code_size + 7) / 8;
-    if ((ret = ff_alloc_packet2(avctx, avpkt, out_size)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, out_size)) < 0)
         return ret;
     init_put_bits(&pb, avpkt->data, avpkt->size);
 
diff --git a/libavcodec/libaacplus.c b/libavcodec/libaacplus.c
index e9e50f8..05c9e38 100644
--- a/libavcodec/libaacplus.c
+++ b/libavcodec/libaacplus.c
@@ -104,7 +104,7 @@ static int aacPlus_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     int32_t *input_buffer = (int32_t *)frame->data[0];
     int ret;
 
-    if ((ret = ff_alloc_packet2(avctx, pkt, s->max_output_bytes)))
+    if ((ret = ff_alloc_packet2(avctx, pkt, s->max_output_bytes)) < 0)
         return ret;
 
     pkt->size = aacplusEncEncode(s->aacplus_handle, input_buffer,
diff --git a/libavcodec/libfaac.c b/libavcodec/libfaac.c
index bf226af..43de22a 100644
--- a/libavcodec/libfaac.c
+++ b/libavcodec/libfaac.c
@@ -184,10 +184,8 @@ static int Faac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     int num_samples  = frame ? frame->nb_samples : 0;
     void *samples    = frame ? frame->data[0]    : NULL;
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, (7 + 768) * avctx->channels))) {
-        av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
+    if ((ret = ff_alloc_packet2(avctx, avpkt, (7 + 768) * avctx->channels)) < 0)
         return ret;
-    }
 
     bytes_written = faacEncEncode(s->faac_handle, samples,
                                   num_samples * avctx->channels,
diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
index d76b215..e4710f6 100644
--- a/libavcodec/libfdk-aacenc.c
+++ b/libavcodec/libfdk-aacenc.c
@@ -339,7 +339,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     }
 
     /* The maximum packet size is 6144 bits aka 768 bytes per channel. */
-    if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels))))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels))) < 0)
         return ret;
 
     out_ptr                   = avpkt->data;
diff --git a/libavcodec/libgsm.c b/libavcodec/libgsm.c
index 470cd61..328c7c7 100644
--- a/libavcodec/libgsm.c
+++ b/libavcodec/libgsm.c
@@ -107,7 +107,7 @@ static int libgsm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     gsm_signal *samples = (gsm_signal *)frame->data[0];
     struct gsm_state *state = avctx->priv_data;
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, avctx->block_align)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, avctx->block_align)) < 0)
         return ret;
 
     switch(avctx->codec_id) {
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 034fee7..e60856c 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -254,7 +254,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     av_dlog(avctx, "in:%d packet-len:%d index:%d\n", avctx->frame_size, len,
             s->buffer_index);
     if (len <= s->buffer_index) {
-        if ((ret = ff_alloc_packet2(avctx, avpkt, len)))
+        if ((ret = ff_alloc_packet2(avctx, avpkt, len)) < 0)
             return ret;
         memcpy(avpkt->data, s->buffer, len);
         s->buffer_index -= len;
diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index 6877f4c..f52d160 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -247,7 +247,7 @@ static int amr_nb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         s->enc_bitrate = avctx->bit_rate;
     }
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, 32)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, 32)) < 0)
         return ret;
 
     if (frame) {
diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
index 23ebe72..051dce6 100644
--- a/libavcodec/libspeexenc.c
+++ b/libavcodec/libspeexenc.c
@@ -304,7 +304,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     /* write output if all frames for the packet have been encoded */
     if (s->pkt_frame_count == s->frames_per_packet) {
         s->pkt_frame_count = 0;
-        if ((ret = ff_alloc_packet2(avctx, avpkt, speex_bits_nbytes(&s->bits))))
+        if ((ret = ff_alloc_packet2(avctx, avpkt, speex_bits_nbytes(&s->bits))) < 0)
             return ret;
         ret = speex_bits_write(&s->bits, avpkt->data, avpkt->size);
         speex_bits_reset(&s->bits);
diff --git a/libavcodec/libtwolame.c b/libavcodec/libtwolame.c
index b57fbc9..8858714 100644
--- a/libavcodec/libtwolame.c
+++ b/libavcodec/libtwolame.c
@@ -94,7 +94,7 @@ static int twolame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     TWOLAMEContext *s = avctx->priv_data;
     int ret;
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE)) < 0)
         return ret;
 
     if (frame) {
diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c
index 1414aad..10f292b 100644
--- a/libavcodec/libvo-aacenc.c
+++ b/libavcodec/libvo-aacenc.c
@@ -161,7 +161,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
             return ret;
     }
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels))))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels))) < 0)
         return ret;
 
     input.Buffer  = samples;
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index eaf632d..4294374 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -121,7 +121,7 @@ static int amr_wb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     const int16_t *samples = (const int16_t *)frame->data[0];
     int size, ret;
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, MAX_PACKET_SIZE)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, MAX_PACKET_SIZE)) < 0)
         return ret;
 
     if (s->last_bitrate != avctx->bit_rate) {
diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c
index 188c8cc..1c0dab6 100644
--- a/libavcodec/libvorbisenc.c
+++ b/libavcodec/libvorbisenc.c
@@ -348,7 +348,7 @@ static int oggvorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
     av_fifo_generic_read(s->pkt_fifo, &op, sizeof(ogg_packet), NULL);
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, op.bytes)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, op.bytes)) < 0)
         return ret;
     av_fifo_generic_read(s->pkt_fifo, avpkt->data, op.bytes, NULL);
 
diff --git a/libavcodec/mpegaudioenc.c b/libavcodec/mpegaudioenc.c
index 75436f8..3634513 100644
--- a/libavcodec/mpegaudioenc.c
+++ b/libavcodec/mpegaudioenc.c
@@ -754,7 +754,7 @@ static int MPA_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     }
     compute_bit_allocation(s, smr, bit_alloc, &padding);
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, MPA_MAX_CODED_FRAME_SIZE)) < 0)
         return ret;
 
     init_put_bits(&s->pb, avpkt->data, avpkt->size);
diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c
index 121bd38..a8c96fa 100644
--- a/libavcodec/nellymoserenc.c
+++ b/libavcodec/nellymoserenc.c
@@ -401,7 +401,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         s->last_frame = 1;
     }
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, NELLY_BLOCK_LEN)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, NELLY_BLOCK_LEN)) < 0)
         return ret;
     encode_block(s, avpkt->data, avpkt->size);
 
diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index bae338d..4a8a4f7 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -107,7 +107,7 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     n           = frame->nb_samples * avctx->channels;
     samples     = (const short *)frame->data[0];
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size)) < 0)
         return ret;
     dst = avpkt->data;
 
diff --git a/libavcodec/ra144enc.c b/libavcodec/ra144enc.c
index bbd7b68..21d38dc 100644
--- a/libavcodec/ra144enc.c
+++ b/libavcodec/ra144enc.c
@@ -458,7 +458,7 @@ static int ra144_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     if (ractx->last_frame)
         return 0;
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, FRAMESIZE)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, FRAMESIZE)) < 0)
         return ret;
 
     /**
diff --git a/libavcodec/roqaudioenc.c b/libavcodec/roqaudioenc.c
index ed5481f..ba020d0 100644
--- a/libavcodec/roqaudioenc.c
+++ b/libavcodec/roqaudioenc.c
@@ -173,7 +173,7 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     else
         data_size = avctx->channels * avctx->frame_size;
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, ROQ_HEADER_SIZE + data_size)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, ROQ_HEADER_SIZE + data_size)) < 0)
         return ret;
     out = avpkt->data;
 
diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c
index 0bc8428..ae54388 100644
--- a/libavcodec/sonic.c
+++ b/libavcodec/sonic.c
@@ -632,7 +632,7 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     int ret;
     const short *samples = (const int16_t*)frame->data[0];
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size * 5 + 1000)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size * 5 + 1000)) < 0)
         return ret;
 
     init_put_bits(&pb, avpkt->data, avpkt->size);
diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index 22b6681..b8752d6 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -1028,7 +1028,7 @@ static int vorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         return 0;
     samples = 1 << (venc->log2_blocksize[0] - 1);
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, 8192)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, 8192)) < 0)
         return ret;
 
     init_put_bits(&pb, avpkt->data, avpkt->size);
diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c
index 0ee5dda..e151095 100644
--- a/libavcodec/wmaenc.c
+++ b/libavcodec/wmaenc.c
@@ -366,7 +366,7 @@ static int encode_superframe(AVCodecContext *avctx, AVPacket *avpkt,
         }
     }
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * MAX_CODED_SUPERFRAME_SIZE)))
+    if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * MAX_CODED_SUPERFRAME_SIZE)) < 0)
         return ret;
 
     total_gain= 128;
-- 
1.8.1.3



More information about the ffmpeg-devel mailing list