[FFmpeg-devel] [PATCH 01/13] lavc/adpcm: THP: handle packets with sample counts not divisible by 14

Paul B Mahol onemda at gmail.com
Thu Jun 18 22:17:06 CEST 2015


Dana 18. 6. 2015. 21:35 osoba "James Almer" <jamrial at gmail.com> napisala je:
>
> On 18/06/15 6:02 AM, Rodger Combs wrote:
> > ---
> >  libavcodec/adpcm.c | 18 +++++++++++++-----
> >  1 file changed, 13 insertions(+), 5 deletions(-)
> >
> > diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
> > index 22b5468..1b35029 100644
> > --- a/libavcodec/adpcm.c
> > +++ b/libavcodec/adpcm.c
> > @@ -642,9 +642,17 @@ static int get_nb_samples(AVCodecContext *avctx,
GetByteContext *gb,
> >          }
> >          has_coded_samples = 1;
> >          bytestream2_skip(gb, 4); // channel size
> > -        *coded_samples  = bytestream2_get_be32(gb);
> > -        *coded_samples -= *coded_samples % 14;
> > -        nb_samples      = (buf_size - (8 + 36 * ch)) / (8 * ch) * 14;
> > +        *coded_samples  = (avctx->codec->id ==
AV_CODEC_ID_ADPCM_THP_LE) ?
>
> Leave it as bytestream2_get_be32(gb) for this patch, then add the thp_le
check in the next,
> where AV_CODEC_ID_ADPCM_THP_LE is introduced.
>
> > +                          bytestream2_get_le32(gb) :
> > +                          bytestream2_get_be32(gb);
> > +        buf_size       -= 8 + 36 * ch;
> > +        buf_size       /= ch;
> > +        nb_samples      = buf_size / 8 * 14;
> > +        if (buf_size % 8 > 1) {
> > +            nb_samples     += (buf_size % 8 - 1) * 2;
> > +            if (*coded_samples & 1)
> > +                nb_samples -= 1;
> > +        }
> >          break;
> >      case AV_CODEC_ID_ADPCM_AFC:
> >          nb_samples = buf_size / (9 * ch) * 16;
> > @@ -1446,7 +1454,7 @@ static int adpcm_decode_frame(AVCodecContext
*avctx, void *data,
> >              samples = samples_p[ch];
> >
> >              /* Read in every sample for this channel.  */
> > -            for (i = 0; i < nb_samples / 14; i++) {
> > +            for (i = 0; i < (nb_samples + 13) / 14; i++) {
> >                  int byte = bytestream2_get_byteu(&gb);
> >                  int index = (byte >> 4) & 7;
> >                  unsigned int exp = byte & 0x0F;
> > @@ -1454,7 +1462,7 @@ static int adpcm_decode_frame(AVCodecContext
*avctx, void *data,
> >                  int factor2 = table[ch][index * 2 + 1];
> >
> >                  /* Decode 14 samples.  */
> > -                for (n = 0; n < 14; n++) {
> > +                for (n = 0; n < 14 && (i * 14 + n < nb_samples); n++) {
> >                      int32_t sampledat;
> >
> >                      if (n & 1) {
> >
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

I think it is second and first patch swapped.


More information about the ffmpeg-devel mailing list