[FFmpeg-devel] [PATCH] ffplay: factorize expression in audio_decode_frame()

Marton Balint cus at passwd.hu
Sat Jun 30 00:55:43 CEST 2012



On Sat, 30 Jun 2012, Stefano Sabatini wrote:

> On date Saturday 2012-06-30 00:08:06 +0200, Stefano Sabatini encoded:
>> Possibly improve readability.
>> ---
>>  ffplay.c |    5 +++--
>>  1 files changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/ffplay.c b/ffplay.c
>> index 2739f47..2d8395c 100644
>> --- a/ffplay.c
>> +++ b/ffplay.c
>> @@ -1991,6 +1991,7 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr)
>>              if (is->swr_ctx) {
>>                  const uint8_t *in[] = { is->frame->data[0] };
>>                  uint8_t *out[] = {is->audio_buf2};
>> +                int out_count = sizeof(is->audio_buf2) / is->audio_tgt.channels / av_get_bytes_per_sample(is->audio_tgt.fmt);
>>                  if (wanted_nb_samples != is->frame->nb_samples) {
>>                      if (swr_set_compensation(is->swr_ctx, (wanted_nb_samples - is->frame->nb_samples) * is->audio_tgt.freq / dec->sample_rate,
>>                                                  wanted_nb_samples * is->audio_tgt.freq / dec->sample_rate) < 0) {
>> @@ -1998,13 +1999,13 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr)
>>                          break;
>>                      }
>>                  }
>> -                len2 = swr_convert(is->swr_ctx, out, sizeof(is->audio_buf2) / is->audio_tgt.channels / av_get_bytes_per_sample(is->audio_tgt.fmt),
>> +                len2 = swr_convert(is->swr_ctx, out, out_count,
>>                                                  in, is->frame->nb_samples);
>>                  if (len2 < 0) {
>>                      fprintf(stderr, "swr_convert() failed\n");
>>                      break;
>>                  }
>
>> -                if (len2 == sizeof(is->audio_buf2) / is->audio_tgt.channels / av_get_bytes_per_sample(is->audio_tgt.fmt)) {
>> +                if (len2 == out_count) {
>>                      fprintf(stderr, "warning: audio buffer is probably too small\n");
>>                      swr_init(is->swr_ctx);
>>                  }
>
> BTW, what's the purpose of swr_init() here?

It's there to free up any remaining data from the internal buffer of the 
resample context, otherwise we would buffer more and more data with each 
decoded and resampled frame, eating up all the memory we have.

Regards,
Marton

> -- 
> FFmpeg = Fundamental and Fiendish Majestic Purposeless Enhancing Geek
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


More information about the ffmpeg-devel mailing list