[FFmpeg-devel] [PATCH 15/19] 8svx: simplify and fix return value.

Nicolas George nicolas.george at normalesup.org
Sun Jul 29 15:57:33 CEST 2012


Do not rely on avctx->frame_number, use a local variable instead.
Ensure that the number of samples in the first frame comes from
an exact number of decoded bytes.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavcodec/8svx.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/8svx.c b/libavcodec/8svx.c
index 3ebc330..fff05b8 100644
--- a/libavcodec/8svx.c
+++ b/libavcodec/8svx.c
@@ -106,7 +106,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
                                  int *got_frame_ptr, AVPacket *avpkt)
 {
     EightSvxContext *esc = avctx->priv_data;
-    int n, out_data_size, ret;
+    int n, out_data_size, ret, nb_start_val = 0;
     uint8_t *src, *dst;
 
     /* decode and interleave the first packet */
@@ -141,6 +141,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
                 buf += buf_size / avctx->channels;
                 dst += n / avctx->channels - 1;
             }
+            nb_start_val = avctx->channels;
         } else {
             deinterleaved_samples = avpkt->data;
         }
@@ -154,7 +155,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
 
     /* get output buffer */
     av_assert1(!(esc->samples_size % avctx->channels || esc->samples_idx % avctx->channels));
-    esc->frame.nb_samples = FFMIN(MAX_FRAME_SIZE, esc->samples_size - esc->samples_idx)  / avctx->channels;
+    esc->frame.nb_samples = (FFMIN(MAX_FRAME_SIZE, esc->samples_size - esc->samples_idx) + nb_start_val) / avctx->channels;
     if ((ret = avctx->get_buffer(avctx, &esc->frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
@@ -170,9 +171,8 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
         *dst++ = *src++ + 128;
     esc->samples_idx += out_data_size;
 
-    return esc->table ?
-        (avctx->frame_number == 0)*2 + out_data_size / 2 :
-        out_data_size;
+    av_assert1(!esc->table || !((out_data_size + nb_start_val) % 2));
+    return esc->table ? (out_data_size + nb_start_val) / 2 : out_data_size;
 }
 
 static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list