1. 程式人生 > >[RK3288][Android6.0] 除錯筆記 --- Audio驅動層判斷錄音資料是否異常

[RK3288][Android6.0] 除錯筆記 --- Audio驅動層判斷錄音資料是否異常

Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92

之前有提到上層可以通過dump pcm資料檢視波形來確定錄音取樣的資料是否正常,這裡給出驅動層檢視方法。

當一次傳輸完成後會呼叫dmaengine_pcm_dma_complete(),而rockchip其實已經添加了除錯方法,只是在本檔案中把巨集CONFIG_ARCH_ROCKCHIP關閉了。
static void dmaengine_pcm_dma_complete(void *arg)
{
	struct snd_pcm_substream *substream = arg;
	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
//本檔案中被undef了,要自己開啟。
#ifdef CONFIG_ARCH_ROCKCHIP
	if(debug_audio_timeout){
		struct snd_pcm_runtime *runtime = substream->runtime;
		static ktime_t before = {0},after = {0};
		s64 t;
		before = after;
		after = ktime_get();
		//t就是一次DMA傳輸完成時間間隔。
		t = ktime_to_us(ktime_sub(after, before));
		//右邊的表示理論DMA一次傳輸需要的時間,單位是us,+32可能是rk經過測試之後可以容忍的出錯幀數。
		//當條件成立的時候,說明DMA沒出完完成,這時就會有問題了。
		if(t > (snd_pcm_lib_period_bytes(substream)/4+32)*1000*1000/runtime->rate
			&& t != ktime_to_us(after)) // (23220)4096/4/44100 + 32/44100
		{
				//當在kmsg中頻繁看到這條Log音訊應該有異常了。
				printk(KERN_DEBUG "Time out:: Audio DMA buffdone time out!!! the time = %lld!\n", t);
		}
		//printk(KERN_DEBUG "audio DMA callback time = %lld\n", t);
	}
#endif
	prtd->pos += snd_pcm_lib_period_bytes(substream);
	if (prtd->pos >= snd_pcm_lib_buffer_bytes(substream))
		prtd->pos = 0;

	snd_pcm_period_elapsed(substream);
}