[Android] How to support SPDIF input feature?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

[Android] How to support SPDIF input feature?

9,530 次查看
charleshuang
Senior Contributor II

Hi,

We need to enable SPDIF input feature on i.MX6 Android platform.

In the BSP 4.2.2_1.0.0, there are SPDIF related source codes in hardware/imx/alsa/config_spdif.h & hardware/imx/alsa/tinyalsa_hal.c.

I find AUDIO_DEVICE_IN_AUX_DIGITAL device is assigned for SPDIF input, but it seems not work actually when I set attached_input_devices to AUDIO_DEVICE_IN_AUX_DIGITAL in audio_policy.conf.

The logs are as below.

=====

1699:01-02 00:28:39.410 I/OMXPlayer( 2284): Audio source: 1

1700:01-02 00:28:39.410 W/audio_hw_primary( 2284): In channels 1, rate 8000, devices 0x80000020

1701:01-02 00:28:39.410 W/audio_hw_primary( 2284): get_input_buffer_size size = 96, channel_count = 1

1702:01-02 00:28:39.410 W/audio_hw_primary( 2284): get_input_buffer_size size = 96, channel_count = 1

1703:01-02 00:28:39.430 E/AudioPolicyManagerBase( 2284): getDeviceForStrategy() speaker device not found for STRATEGY_SONIFICATION

1704:01-02 00:28:39.430 E/AudioPolicyManagerBase( 2284): getDeviceForStrategy() speaker device not found for STRATEGY_SONIFICATION

1707:01-02 00:28:39.440 I/OMXPlayer( 2284): Set AudioSource start time.

1708:01-02 00:28:39.440 W/audio_hw_primary( 2284): in_set_parameters input_source=1;routing=-2147483616, ret 11

1709:01-02 00:28:39.450 W/audio_hw_primary( 2284): start_input_stream....

1710:01-02 00:28:39.450 W/audio_hw_primary( 2284): card 1, port 0 device 0x20

1711:01-02 00:28:39.450 W/audio_hw_primary( 2284): rate 44100, channel 2 format 2, period_size 0x200

1713:01-02 00:28:41.460 I/OMXPlayer( 2284): OMX.Freescale.std.audio_source.android.sw-based wait command[0:3] timeout.

1718:01-02 00:28:42.040 I/OMXPlayer( 2284): OMX.Freescale.std.audio_source.android.sw-based send command[0:2] timeout.

1722:01-02 00:28:42.580 I/OMXPlayer( 2284): OMX.Freescale.std.audio_source.android.sw-based Time out for Sending Command [2:1], Busy on Command [0:2].

1724:01-02 00:28:42.580 I/OMXPlayer( 2284): OMX.Freescale.std.audio_source.android.sw-based Wait incorrect Command[2:1], ProcessingCmd is [0:2].

1737:01-02 00:28:49.470 W/audio_hw_primary( 2284): ret -1, pcm write 768 error cannot write stream data: I/O error.

1738:01-02 00:28:49.470 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_wrapper error -1

1739:01-02 00:28:49.470 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_convert error -1

1740:01-02 00:28:49.470 W/audio_hw_primary( 2284): ret -1, pcm read error cannot read stream data: I/O error.

1741:01-02 00:28:49.470 W/audio_hw_primary( 2284): ret -1, pcm write 768 error cannot prepare channel: Device or resource busy.

1742:01-02 00:28:49.470 W/audio_hw_primary( 2284): ret -1, pcm write 768 error cannot prepare channel: Device or resource busy.

1743:01-02 00:28:49.480 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_wrapper error -16

1744:01-02 00:28:49.480 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_convert error -16

1745:01-02 00:28:49.480 W/audio_hw_primary( 2284): ret -16, pcm read error cannot prepare channel: Device or resource busy.

1746:01-02 00:28:49.480 W/audio_hw_primary( 2284): ret -1, pcm write 768 error cannot prepare channel: Device or resource busy.

1748:01-02 00:28:49.480 I/OMXPlayer( 2284): OMX.Freescale.std.audio_source.android.sw-based Invalid state transitioin: 3 -> 1.

1752:01-02 00:28:49.490 W/audio_hw_primary( 2284): do_out_standby... 1074310608

1753:01-02 00:28:49.490 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_wrapper error -16

1754:01-02 00:28:49.490 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_convert error -16

1755:01-02 00:28:49.490 W/audio_hw_primary( 2284): ret -16, pcm read error cannot prepare channel: Device or resource busy.

1756:01-02 00:28:49.500 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_wrapper error -16

1757:01-02 00:28:49.500 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_convert error -16

1758:01-02 00:28:49.500 W/audio_hw_primary( 2284): ret -16, pcm read error cannot prepare channel: Device or resource busy.

1759:01-02 00:28:49.520 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_wrapper error -16

1760:01-02 00:28:49.520 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_convert error -16

1761:01-02 00:28:49.520 W/audio_hw_primary( 2284): ret -16, pcm read error cannot prepare channel: Device or resource busy.

1762:01-02 00:28:49.530 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_wrapper error -16

1763:01-02 00:28:49.530 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_convert error -16

1764:01-02 00:28:49.530 W/audio_hw_primary( 2284): ret -16, pcm read error cannot prepare channel: Device or resource busy.

1765:01-02 00:28:49.540 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_wrapper error -16

1766:01-02 00:28:49.540 E/audio_hw_primary( 2284): get_next_buffer() pcm_read_convert error -16

=====

In addition, it also failed when I try to capture SPDIF frame with tinycap.

=====

root@android:/data # tinycap test.wav -D 1 -d 0

Unable to open PCM device (cannot set hw params: Invalid argument)

Captured 0 frames

=====

Thanks,

Daniel

标签 (3)
标记 (2)
0 项奖励
回复
42 回复数

2,028 次查看
sinanakman
Senior Contributor III

Daniel, I am not running Android but I tested sabresd spdif input and under both FSL 3.0.5 as well mainline Linux kernel it works fine.

Hope this helps.

Sinan Akman

0 项奖励
回复

2,028 次查看
danielhung
Contributor III

Sinan Akman,

Thank you. It also works fine on Linux kernel for me.

Daniel

0 项奖励
回复

2,028 次查看
brucequinton
Contributor I

How is it that the SPDIF input works in Linux if the pin isn't connected?

0 项奖励
回复

2,018 次查看
sinanakman
Senior Contributor III

Hi Bruce, in our case we used one of the OTG pins and muxed it for spdif input. We then used a cable

with res/caps between rca and usb and used it for testing spdif input.

Hope this helps.

Sinan Akman

0 项奖励
回复

2,018 次查看
brucequinton
Contributor I

Sinan,

     Thank you for your response, heres a little rundown on what I have been facing...  I have been trying to get SPDIF IN sabreSD working  but I have also been trying on a Wandboard  (because I have one sitting on my desk) I assume I'm getting the IOMUX wrong, I have the hardware visible in the OS (Linux), the codec and drivers load, but I only ever get a IRQ/DMA error in the pcm_lib.c PCM code. I have checked all my settings for DMA and a cat /proc/interrupts shows IRQ 84 which is correct.

I'm using the GPIO_16 pin and have the resistors and Caps to clean up the signal (I know the signal is correct, I have check it on the oscilloscope)

My PAD CTRL is currently set to: 0x090b0 which should put me into a "keeper" state.

To be honest I'm running out of ideas. :smileysad:

Could you show me your PIN and CTRL pad settings you are using?

Regards Bruce Quinton

0 项奖励
回复

2,018 次查看
sinanakman
Senior Contributor III

Hi Bruce, I'll send the setting to you. I think I had them both for FSL 3.0.5 and for mainline. I'll send you the mainline.

Meanwhile, can you check what dma error are you receiving ?

0 项奖励
回复

2,018 次查看
sinanakman
Senior Contributor III

Bruce, here is the dts mod for 3.14-RT :

pinctrl_spdif_4: spdifgrp-4 {

                                                fsl,pins = <                                                      

                                                        MX6QDL_PAD_ENET_RX_ER__SPDIF_IN 0x1b030

                                                >;

                                          };

Let me know if you need any other info.

Regards

Sinan Akman

0 项奖励
回复

2,018 次查看
brucequinton
Contributor I

Sinan, I'll give it a try thank you.

Regards
Bruce Quinton

0 项奖励
回复

2,018 次查看
brucequinton
Contributor I

Morning Sinan,

     Unfortunately I don't receive a detailed error. I know the error is caused when the schedule_timout(wait_time) function is called in pcm_lib the wait is called right after "snd_pcm_stream_unlock_irq". My thought is that the keeper on the control pad is not getting triggered, therefore the the SPDIF receiver doesn't believe its receiving valid data, so it never sets the IRQ, the PCM then times out waiting for the IRQ event and just throws a generic error of "write error (DMA or IRQ trouble?)"

0 项奖励
回复

2,020 次查看
danielhung
Contributor III

We use our own hardware with the spdif pin connected.

As Weidong mentioned, you can't use sabreSD board to test SPDIF funciton.

0 项奖励
回复

2,018 次查看
sinanakman
Senior Contributor III

Hi Daniel, we used OTG socket for spdif in pin on sabreSD board. Please see my reply to Bruce on this.

Thanks

Sinan Akman

0 项奖励
回复

2,028 次查看
YixingKong
Senior Contributor IV

weidong.sun, could you keep following this thread?

Thanks,

Yixing

0 项奖励
回复

2,028 次查看
danielhung
Contributor III

Hi Weidong,

Thanks for reply. I can see the SPDIF device in kernel and SPDIF input/output both works fine in Linux.

The question now is about Android HAL.

The target is to let users can record from SPDIF input device via Sound Recorder application.

Thanks,

Daniel

0 项奖励
回复

2,028 次查看
brucequinton
Contributor I

Hi Weidong and Daniel,
          I came across this post while looking for information on how to use the SPDIF input on a Utilite (which has the CM-MX6 board) I looked through the iomux_mx6q.h file and I believe I have assigned the CPU PAD as mentioned above, I re-compiled the Kernel but I I still get a read/input error when I attempt to open the SPDIF hardware.

To be honest I'm not sure I even need to recompile the kernel but I figured it couldn't hurt. :smileywink: I feel I need to do a lot more reading before I will be able to read the data from my SPDIF input hardware, could either of you give me some direction please?

(I'm not attempting to hijack the thread, so please ignore my post if Daniels question is not answered)

Regards Bruce

0 项奖励
回复

2,028 次查看
danielhung
Contributor III

Hi Bruce,

You may need to check if SPDIF device can be seen in kernel first.

Besides the CPU PADs settings, you have to open the defconfig as well.

CONFIG_SND_MXC_SOC_SPDIF_DAI=y

CONFIG_SND_SOC_IMX_SPDIF=y

CONFIG_SND_SOC_MXC_SPDIF=y

Then, you should be able to see the SPDIF device in kernel log like this.

   ALSA device list:

   #0: sgtl5000-audio

   #1: imx-spdif

   #2: imx-hdmi-soc

Best regards,

Daniel

0 项奖励
回复

2,028 次查看
brucequinton
Contributor I

Daniel,Thank you for the reply. I can now see the #1: imx-spdif in the log but when I attempt to use it I get a read/input error.

Maybe I'm attempting to use it wrong. Would you happen to have a snippet of code that connect to the SPDIF device and stream data (even just to the stdout)

Sorry to ask but I cannot see where I have gone wrong..

thanks again I appreciate to the help.

Regards Bruce Quinton

0 项奖励
回复

2,028 次查看
danielhung
Contributor III

Hi Bruce,

How do you use it? In Linux or Android?

I can play wav file by the following ways. Remember to set correct device & card number for your SPDIF device.

[Linux]

aplay test.wav -D plughw:1,0

[Android]

tinyplay test.wav -D 1 -d 0

Best regards,

Daniel

0 项奖励
回复

2,028 次查看
brucequinton
Contributor I

Sorry, i'm using Linux, I can play a sound file.

I'm having trouble recording from the SPDIF.

Regards Bruce

0 项奖励
回复

2,028 次查看
danielhung
Contributor III

Hi Bruce,

Try this one. It works for me.

# arecord -D plughw:1,0 test.wav -v

Best regards,

Daniel

0 项奖励
回复

2,028 次查看
brucequinton
Contributor I

I get nothing at all, it just builds the wav header and no content. (I have tested that the input has data by using another PC)

if I use
#arecord -D hw:1,0 test.wav -v

I receive the following error: pcm_read:1801: read error: input/output error

Any change you package your kernel and modules into a tar file and shoot them to me?

Regards Bruce

0 项奖励
回复

2,028 次查看
danielhung
Contributor III

Sorry. I cannot share source code to you.

No idea about your question. Maybe you can check the configuration or permission for audio device.

Best regards,

Daniel

0 项奖励
回复