introduce
In this series, I plan to spend a lot of time explaining my gitee project audio and video player. In this project, you can learn audio and video decapsulation, decoding, and SDL rendering related knowledge. If you are interested in the source code, please check out the audio and video player based on FFmpeg and SDL
If you don’t understand this article, you can refer to my previous article Audio and Video Project— Audio and Video Player Analysis Based on FFmpeg and SDL (16)
parse
Following the above, we continue to analyze the fill_audio_pcm function
av_fast_malloc(&is->audio_buf1, &is->audio_buf1_size, out_bytes);
int len2 = swr_convert(is->swr_ctx, out, out_samples, in, frame->nb_samples);
if(len2 < 0){
return;
}
is->audio_buf = is->audio_buf1;
is->audio_buf_size = av_samples_get_buffer_size(NULL, is->dst_tgt.channels, len2, is->dst_tgt.fmt, 1);
av_fast_malloc reallocates the buffer size.
swr_convert switches the sampling rate
Then assign values to some variables
}else {
audio_size = av_samples_get_buffer_size(NULL, is->dst_tgt.channels, frame->nb_samples, (enum AVSampleFormat) frame->format, 1);
av_fast_malloc(&is->audio_buf1, &is->audio_buf1_size, audio_size);
is->audio_buf = is->audio_buf1;
is->audio_buf_size = audio_size;
memcpy(is->audio_buf, frame->data[0], audio_size);
}
If swrcontext is not allocated successfully, perform the above operation.
Okay, that’s all for today, and the rest will be analyzed below.
If you want to know what happened next, please listen to the breakdown next time.