目标:
关注声音回调函数与 声音解码函数的关系
关注视频帧调用过程
未完成
测试案列:
测试平台:
测试代码:
首先来说,为什么可以出声音,我认为是这个函数 SDL_pauseAudio 的行为.
### 关注声音回调函数与 解码的关系
用数据来说话,分别在两个位置下断点
位置一是:audio_callback函数位置
位置二是:audio_decode_frame解码函数位置
让我们来看看实际的代码:
~~~
void audio_callback(void *userdata, Uint8 *stream, int len) {
AVCodecContext *aCodecCtx = (AVCodecContext *)userdata;
int len1, audio_size;
static uint8_t audio_buf[(MAX_AUDIO_FRAME_SIZE * 3) / 2];
static unsigned int audio_buf_size = 0;
static unsigned int audio_buf_index = 0;
while(len > 0) {
if(audio_buf_index >= audio_buf_size) {
~~~
~~~
/* We have already sent all our data; get more */
audio_size = audio_decode_frame(aCodecCtx, audio_buf, audio_buf_size);//请特别注意。
~~~
~~~
if(audio_size < 0) {
/* If error, output silence */
audio_buf_size = 1024; // arbitrary?
memset(audio_buf, 0, audio_buf_size);
} else {
audio_buf_size = audio_size;
}
audio_buf_index = 0;
}
~~~
~~~
len1 = audio_buf_size - audio_buf_index;
if(len1 > len)
len1 = len;
memcpy(stream, (uint8_t *)audio_buf + audio_buf_index, len1);
len -= len1;
stream += len1;
audio_buf_index += len1;
}
}
~~~
结果如下,可以看到至少4次audio_decode_frame后,系统将会调用 回调函数。这样的回调会周期性发生。
有同学会问,为什么是4次?我想要么是给系统回调的声音buffer放满了,要么是audio_callback 定时调用。
~~~
Function: audio_callback(void *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_callback(void *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_callback(void *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_callback(void *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_callback(void *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
Function: audio_decode_frame(AVCodecContext *, unsigned char *, int), Thread: 0x81B8 Win32 线程
~~~
### 关注视频帧调用过程
之所以贴在这里,想以后再分析,再给出结果。
理论上,12个时刻,应该对应12个不同的帧,但是结果不是,看看以下结果(用notepad++处理后,用于统计个数)。
~~~
Search "video" (11 hits in 1 file)
new 2 (11 hits)
Line 120: read one video frame
Line 286: read one video frame
Line 291: read one video frame
Line 292: read one video frame
Line 293: read one video frame
Line 294: read one video frame
Line 295: read one video frame
Line 296: read one video frame
Line 297: read one video frame
Line 298: read one video frame
Line 299: read one video frame
Search "audio" (288 hits in 1 file)
~~~
###未完成
其他:看看第一次调用audio_callback时,是否遇到返回为空的情形。
其他:请打印出每次解码出的buffer大小,尤其注意那个中间连续调用五次解码的过程。
其他:是否可以结合dump出的文件信息,量化分析过程。