[FFmpeg-devel] [PATCH 2/2] Skip last samples in frame if needed

Jakub Stachowski qbast at go2.pl
Wed May 2 19:59:04 CEST 2012


---
 libavcodec/wmalosslessdec.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c
index c1e5480..b77d576 100644
--- a/libavcodec/wmalosslessdec.c
+++ b/libavcodec/wmalosslessdec.c
@@ -977,8 +977,16 @@ static int decode_subframe(WmallDecodeCtx *s)
 
     /* Write to proper output buffer depending on bit-depth */
     for (i = 0; i < s->channels_for_cur_subframe; i++) {
+        int already_written;
         int c = s->channel_indexes_for_cur_subframe[i];
-        int subframe_len = s->channel[c].subframe_len[s->channel[c].cur_subframe];
+        
+        if (s->bits_per_sample == 16) 
+            already_written = (s->samples_16[c] - ((int16_t *)s->frame.data[0] + c)) / s->num_channels;
+        else
+            already_written = (s->samples_32[c] - ((int32_t *)s->frame.data[0] + c)) / s->num_channels;
+
+        int subframe_len = FFMIN(s->frame.nb_samples - already_written, s->channel[c].subframe_len[s->channel[c].cur_subframe]);
+
 
         for (j = 0; j < subframe_len; j++) {
             if (s->bits_per_sample == 16) {
@@ -1056,6 +1064,11 @@ static int decode_frame(WmallDecodeCtx *s)
         if (get_bits1(gb)) {
             skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
             av_dlog(s->avctx, "end skip: %i\n", skip);
+            s->frame.nb_samples -= skip;
+            if (s->frame.nb_samples<0) {
+                av_log(s->avctx, AV_LOG_ERROR,"negative number of samples\n");
+                return AVERROR_INVALIDDATA;
+           }
         }
 
     }
-- 
1.7.7



More information about the ffmpeg-devel mailing list