This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Sound write fails



Hi All,

This is with regards to a capturing and rendering solution that we are developing. We are facing a problem when rendering audio data. We find that the write to the sound device fails after a certain interval of time. Described below is a brief of our implementation:

 

We have a function that fetches encoded frames of data, decodes them and writes the same to a sound device. The functions that achieve this are:

  1. Loader_getFrame();
  2. Adec1_process();
  3. Sound_write();

 

This implementation runs fine for some time but then the call to Sound_write() fails with error returned as DMAI_EIO. The duration after which the error occurs is random in nature. Sometimes it occurs in a few minutes, and sometimes after a few hours. On debugging further we found that the DMAI framework returns the error as:

 

[Sound] Error writing data to sound device(Input/output error)

 

To avoid this error we have tried various work-arounds as:

  1. writing data to the sound device in a separate thread
  2. accumulating a certain amount of data before giving it to sound write
  3. using buffers in ping-pong fashion to give to sound device so that the buffer into which the data is decoded does not overlap with the buffer that is been written to the sound device.

 

But, we have not succeeded as yet in resolving the issue. Kindly guide us as to how we should implement the solution to avoid this error. Details of our development environment are:

1. Development on DM6467-t processor

2.dvsdk version 3_10_00_16

3.dmai version 2_10_00_10

Let me know if anyone requires any further details. Thanking all in advance. Awaiting an early reply.

Regards,

Veenit

  • Hello,

    I was wondering if audio driver is enabled in your kernel or not? Input/Output error can result if the app is not able to open audio device. Can you try running "speaker-test" or
    "arecord -fcd | aplay -cfd" command to verify if you have working ALSA interface.  IIRC, OOB dvsdk demo uses ALSA interface to playback audio and speech. So taking a step back and verifying that you have working setup will help to identify the root cause in your application. DMAI Sound module calls simple ALSA API's to do audio playback/Capture and you have always put some debug to see what is causing this behaviour.

    Thanks

    Brijesh

  • Hi Brijesh,

    We analyzed this problem further and I am posting our findings.

    The playback does work fine for sometime (1 to 2 mins) and then suddenly stops. We found that the Sound_write does not return from wait_for_avail_min() function in pcm_lib.c. It waits for 10 secs in schedule_timeout(msecs_to_jiffies(10000)) before returning an -EIO error. To confirm we enabled debug at the pcm layer and it printed "playback write error (DMA or IRQ trouble?)".

    Subsequently, while analyzing the problem, we added printk msgs in PCM and driver layer, and surprising we found that if we have a printk msg in snd_interval_refine() function in pcm_lib.c, we don't get audio write issue for longer runs (even overnight runs), although it does sometimes happen (rarely).
    snd_interval_refine() gets executed during Sound_create() and is not invoked during Sound_write().

    Does it imply that there is some timing dependency during initialization of the msasp driver?

    Kindly let us know your views on this problem.

    Thanks & Regards,
    Manu

  • Hi Brijesh,

    We tried capturing the state of the McASP device on trigger start and when driver returns an -EIO error. Pasted below is the dump of the registers for your reference.

    XSTAT register (transmitter status register) has 0x14C on startup and has 0x15D on -EIO error which implies that XUNDRN and XLAST bits are set.
    However, how can an underrun occur if Sound_write is waiting for data to be written to the hardware buffer?

    Thanks & Regards,
    Manu Batura

    Just before returning -EIO error:

    MCASP0_PID:0x  100102
    MCASP0_PWRDEMU:0x       0
    MCASP0_PFUNC:0x       0
    MCASP0_PDIR:0x       2
    MCASP0_PDOUT:0x       0
    MCASP0_PDIN:0x90000000
    MCASP0_PDCLR:0x       0
    MCASP0_GBLCTL:0x    1F00
    MCASP0_AMUTE:0x       0
    MCASP0_DLBCTL:0x       0
    MCASP0_DITCTL:0x       0
    MCASP0_RGBLCTL:0x    1F00
    MCASP0_RMASK:0x    FFFF
    MCASP0_RFMT:0x   10074
    MCASP0_AFSRCTL:0x       0
    MCASP0_ACLKRCTL:0x      80
    MCASP0_AHCLKRCTL:0x    8000
    MCASP0_RTDM:0x       0
    MCASP0_RINTCTL:0x       0
    MCASP0_RSTAT:0x     104
    MCASP0_RSLOT:0x       0
    MCASP0_RCLKCHK:0x       0
    MCASP0_XGBLCTL:0x    1F00
    MCASP0_XMASK:0x    FFFF
    MCASP0_XFMT:0x    8074
    MCASP0_AFSXCTL:0x     100
    MCASP0_ACLKXCTL:0x       0
    MCASP0_AHCLKXCTL:0x    8000
    MCASP0_XTDM:0x       3
    MCASP0_XINTCTL:0x       0
    MCASP0_XSTAT:0x     15D
    MCASP0_XSLOT:0x       0
    MCASP0_XCLKCHK:0x       0

    On start trigger:

    MCASP0_PID:0x  100102
    MCASP0_PWRDEMU:0x       0
    MCASP0_PFUNC:0x       0
    MCASP0_PDIR:0x       2
    MCASP0_PDOUT:0x       0
    MCASP0_PDIN:0xB4000000
    MCASP0_PDCLR:0x       0
    MCASP0_GBLCTL:0x       0
    MCASP0_AMUTE:0x       0
    MCASP0_DLBCTL:0x       0
    MCASP0_DITCTL:0x       0
    MCASP0_RGBLCTL:0x       0
    MCASP0_RMASK:0x    FFFF
    MCASP0_RFMT:0x   10074
    MCASP0_AFSRCTL:0x       0
    MCASP0_ACLKRCTL:0x      80
    MCASP0_AHCLKRCTL:0x    8000
    MCASP0_RTDM:0x       0
    MCASP0_RINTCTL:0x       0
    MCASP0_RSTAT:0x     104
    MCASP0_RSLOT:0x       0
    MCASP0_RCLKCHK:0x       0
    MCASP0_XGBLCTL:0x       0
    MCASP0_XMASK:0x    FFFF
    MCASP0_XFMT:0x    8074
    MCASP0_AFSXCTL:0x     100
    MCASP0_ACLKXCTL:0x       0
    MCASP0_AHCLKXCTL:0x    8000
    MCASP0_XTDM:0x       3
    MCASP0_XINTCTL:0x       0
    MCASP0_XSTAT:0x     14C
    MCASP0_XSLOT:0x     17F
    MCASP0_XCLKCHK:0x       0

  • Hello,

    I am not sure who is causing problem here, may be DMAI Sound_write is not calling all the right ALSA LIB API vs some  Driver issue. And do isolate that can i recommend you running "arecord" command on your target to see if this is reproudciable. If the problem is reproduciable with standard arecord command then Linux driver guys can throw some light but if its not reproduciable then probably comapre the API calls between arecord and DMAI Alsa sound module to see what is missing.

    Thanks

    Brijesh

  • Hi Brijesh,

    We have tried to be as explicit as we can wrt the problem and it will help if someone from TI can help us diagnose the problem further.

    A few comments:

    1. Can you please check our queries again. Our problem has no relation to recording, it is a playback issue. Why should we try the "arecord" command?

    2. We were expecting some inputs from TI based on the transmitter status register values that we have posted for both normal and error conditions.

    3. We were expecting some inputs from TI to let us know under what conditions of operation would the driver take the error path that we have explicitly mentioned.

    Thanks & Regards,

    Manu Batura

     

  • Manu,

    Sorry i meant to say "aplay" not "arecord". 

    Thanks

    Brijesh

  • Some further information:

    Our kernel version that we are using is GIT Linux 2.6.32.

    We also tried to run aplay and it works just fine on our custom board. Could it be due to an under-run case that the driver is not able to handle well enough?

  • Some more information:

    We made changes in the buffer management in our application by reimplementing the loader. The problem is now visible only after 13 to 14 hours or if the input stream is corrupted when the Sound write again fails. When the input stream is corrupted, the TS packets are dropped and that can cause the data to reach the decoder in bursts.

    We will continue our investigation at the application level to check for potential sources of problem. However, it will help a lot to understand under what cases does the driver take the error path it does when a sound write issue happens.

  • Hi, Veenit

    Have you solved this problem finally? I encountered a similar problem on DM365 platform.

    Can you give some advice for me ?

  • Hi, all

    I also had similar problems, snd_pcm_lib_read1 return-EIO err.tout = schedule_timeout (10 * HZ); timeout direct return. I think the problem may be due to dma, dma does not generate an interrupt.But this is only my guess that, still being investigated.

    This problem has troubled me for a long time, who know How is it?