8.4 Multimedia Processing and Applications
This section mainly answers frequently asked questions related to video codec, audio processing, and other multimedia functions on the D-Robotics RDK board.
Video Codec
Q1: When decoding an RTSP video stream on the development board, an error is reported (as shown in the figure below). What could be the possible reason?
A: Common causes and solutions for RTSP video stream decoding errors are as follows:
- The stream lacks PPS and SPS parameter information:
- Cause: The RTSP stream (especially in H.264 format) pushed by the streaming server must contain
PPS(Picture Parameter Set) andSPS(Sequence Parameter Set) information. The decoder requires this information to correctly parse the video. - Solution:
- If you are using
ffmpegto stream from a video file (e.g.,.mp4,.avi), it is recommended to add the-bsf:v h264_mp4toannexb(H.264 Bitstream Filter: MP4 to Annex B) option to the command (Note: In newer versions of ffmpeg,-vbsfhas been replaced by-bsf:v). This filter automatically addsPPSandSPSinformation to the stream. Exampleffmpegstreaming command:(Replaceffmpeg -re -stream_loop -1 -i xxx.mp4 -c:v copy -bsf:v h264_mp4toannexb -f rtsp rtsp://192.168.1.195:8554/h264_streamxxx.mp4with your video filename and the RTSP server addressrtsp://192.168.1.195:8554/h264_streamwith the actual address.)
- If you are using
- Cause: The RTSP stream (especially in H.264 format) pushed by the streaming server must contain
- Resolution support limitations:
- Currently, decoding of RTSP video streams on RDK boards may only support specific resolutions, such as 1080p (1920x1080). Please confirm whether your RTSP stream's resolution falls within this supported range. Consult the documentation for your specific board model for an accurate support list.
- Streaming software compatibility:
- Direct streaming with VLC is not recommended: Using VLC software to directly push an RTSP stream may not be successfully decoded by the RDK. This is because VLC, in some configurations, may not actively add or ensure the presence of
PPSandSPSinformation during streaming. It is recommended to useffmpegor other professional streaming tools that ensure the integrity of stream parameters.
- Direct streaming with VLC is not recommended: Using VLC software to directly push an RTSP stream may not be successfully decoded by the RDK. This is because VLC, in some configurations, may not actively add or ensure the presence of
Audio FAQs
Q1: The examples use tinyalsa. What do its various parameters represent, and how are they used?
A: tinyalsa is a lightweight audio library primarily used in Android and embedded Linux systems. It provides a simplified interface to ALSA (Advanced Linux Sound Architecture), making it easier for developers to perform audio processing.
Below are some commonly used tinyalsa commands and their parameter meanings:
- List all sound cards:
This command lists all recognized sound cards and their controls in the system. If the
tinymix -ltinymix -lcommand does not work, you can directlycat /proc/asound/cardsto check. - List controls for a specific sound card:
Here,
tinymix -c <card_number> -l<card_number>is the index of the sound card. This command lists all controls for the specified sound card. The exact command may vary depending on the version of tinymix; you can try commands liketinymix -D <card_number> controls. - Get the value of a specific control:
This command displays the current value of a control on the specified sound card. For example:
tinymix -c <card_number> <control_name>This will display the current value of the control namedtinymix -c 0 'ADC PGA Gain'ADC PGA Gainon sound card 0. - Set the value of a specific control:
This command sets the value of a control on the specified sound card. For example:
tinymix -c <card_number> <control_name> <value>This sets thetinymix -c 0 'ADC PGA Gain' 80%ADC PGA Gaincontrol on sound card 0 to 80%. - View current audio status:
This command displays the current audio status of the specified sound card, including the current values of all controls.
tinymix -c <card_number> -s - Play an audio file:
This command plays the specified audio file.
tinyplay <file_name><file_name>is the path and name of the audio file. For example:This will play the specified audio file.tinyplay /path/to/audio.wav - Record audio:
This command records audio and saves it to the specified file. The parameter meanings are as follows:
tinycap <file_name> -D <card_number> -d <device_number> -c <channels> -b <bit_depth> -r <sample_rate> -p <period_size> -n <periods> -t <duration><file_name>: The name of the recorded audio file.-D <card_number>: Specifies the sound card index.-d <device_number>: Specifies the device index (usually a PCM device).-c <channels>: Specifies the number of recording channels (e.g., 2 for stereo, 4 for four-channel).-b <bit_depth>: Specifies the audio bit depth (e.g., 16 for 16-bit).-r <sample_rate>: Specifies the sample rate (e.g., 48000 for 48kHz).-p <period_size>: Specifies the period size (in frames).-n <periods>: Specifies the number of periods.-t <duration>: Specifies the recording duration (in seconds).- Example:
This command records 2-channel, 16-bit, 48kHz audio using device 1 of sound card 0, for a duration of 5 seconds, and saves it astinycap ./recorded_audio.wav -D 0 -d 1 -c 2 -b 16 -r 48000 -p 512 -n 4 -t 5recorded_audio.wav.
Q2: How to distinguish between and use USB sound cards and onboard sound cards on an RDK board, especially when multiple audio devices are connected simultaneously?
A: When both an onboard sound card (e.g., via an audio daughter board) and a USB sound card are connected to an RDK board, the Linux audio system (ALSA) assigns them different sound card indices. You need to know the correct sound card index to precisely control a specific audio device.
-
View recognized sound cards and their indices: Use the following command to list all recognized sound cards in the system along with their corresponding indices and names:
cat /proc/asound/cardsExample output (assuming the USB sound card is registered first, followed by the onboard sound card):
0 [RC08 ]: USB-Audio - ROCWARE RC08
ROCWARE RC08 at usb-xhci-hcd.2.auto-1.2, high speed
1 [duplexaudio ]: simple-card - duplex-audio
duplex-audioIn this example:
- The USB sound card
ROCWARE RC08is assigned sound card index 0. - The onboard sound card
duplexaudio(often the name for the RDK audio daughter board) is assigned sound card index 1. - Note: The allocation order of sound card indices can change due to factors like device insertion order or driver loading order. If a USB sound card is inserted after system boot, it may receive a larger index.
- The USB sound card
-
Specify the sound card when using
amixerortinymix:- When using tools like
amixer(ALSA Mixer command-line utility) ortinymixto view or adjust audio parameters, if you do not specify the card and device numbers, they typically operate on the sound card with index 0 by default. - To operate on a specific sound card, use the
-c <card_number>(or-c<card_number>) parameter to specify the sound card index, and possibly the-D hw:<card_number>or-d <device_number>parameters. - View controls for a specific sound card (e.g., the onboard sound card with index 1 from the example above):
amixer -c 1 controls
# Or using the hardware device name: amixer -D hw:1 controls - Get or set the value of a control on a specific sound card (e.g., get the value of the first control named 'ADC PGA Gain' on onboard sound card index 1):
To set the value, use
amixer -c 1 sget 'ADC PGA Gain',0ssetinstead ofsget, for example:amixer -c 1 sset 'ADC PGA Gain',0 80%.
- When using tools like
Using the methods above, you can accurately identify and control different audio devices connected to your RDK board.
Q3: How can the audio daughter board of the RDK X3 series coexist and be used simultaneously with a USB sound card (e.g., having PulseAudio recognize and manage them)?
A: If you wish to use both the onboard audio daughter board (e.g., based on the WM8960 chip) and an external USB sound card simultaneously on the RDK X3, and have higher-level audio services like PulseAudio recognize and manage them, some configuration may be necessary.
The following steps use the WM8960 audio daughter board and a USB full-duplex sound card as examples:
-
Ensure the audio daughter board works correctly:
- First, following the tutorial for the specific audio daughter board, ensure its driver is loaded correctly and that it can record and play audio normally when used alone.
-
Connect the USB sound card and identify newly added nodes:
- Connect the USB sound card to a USB port on the RDK X3. Wait for the system to load the driver.
- Observe the newly added PCM device nodes in the
/dev/snd/directory. ALSA creates nodes for each PCM device (playback, capture) of each sound card.Example output (assumingls /dev/snd/controlC0,pcmC0D0c,pcmC0D0p,pcmC0D1c,pcmC0D1pare nodes for the audio daughter board, andpcmC1D0c,pcmC1D0pare nodes for the newly connected USB sound card):In this example:by-path controlC0 pcmC0D0c pcmC0D0p pcmC0D1c pcmC0D1p pcmC1D0c pcmC1D0p timerpcmC0...typically corresponds to sound card 0 (card 0).D0cindicates the capture endpoint of device 0,D0pindicates the playback endpoint of device 0.D1c,D1pmight represent a second PCM device on sound card 0 (e.g., HDMI audio output).pcmC1D0c,pcmC1D0pcorrespond to sound card 1 (card 1), the newly connected USB sound card. If the USB sound card is full-duplex and has a single PCM device, it typically presents one capture endpoint and one playback endpoint.
-
Modify the PulseAudio configuration file (
/etc/pulse/default.pa):- To allow PulseAudio to load and use both sound cards simultaneously, you need to edit its default configuration file.
- Locate the section of the file that loads the ALSA sound card sources (for capture) and sinks (for playback), typically within the
.ifexists module-udev-detect.soblock or the.elseblock. - After the existing
load-module module-alsa-sourceandload-module module-alsa-sinklines, add new loading directives for your USB sound card (assuming it is sound card 1, device 0, confirm usingcat /proc/asound/cards).
Example modification to
/etc/pulse/default.pa:# ... (Rest of the file) ...
.ifexists module-udev-detect.so
# load-module module-udev-detect tsched=0 # Or a similar line
### Existing ALSA Sink/Source for onboard audio (card 0)
### Adjust device=hw:X,Y according to your actual onboard sound card configuration
### For example, if onboard playback is card 0, device 1; onboard capture is card 0, device 0
load-module module-alsa-sink device=hw:0,1 mmap=false tsched=0 fragments=2 fragment_size=960 rate=48000 channels=2 rewind_safeguard=960
load-module module-alsa-source device=hw:0,0 mmap=false tsched=0 fragments=2 fragment_size=960 rate=48000 channels=2
### Add these lines for the USB sound card (assuming it's card 1, device 0 for both playback and capture)
### Note: device=hw:1,0 here is based on the inference from `ls /dev/snd/` and `cat /proc/asound/cards`,
### You need to confirm the actual card number (X) for the USB sound card using `cat /proc/asound/cards`,
### and confirm its playback/capture device number (Y) using `aplay -l` / `arecord -l`.
load-module module-alsa-sink device=hw:1,0 # For USB sound card playback
load-module module-alsa-source device=hw:1,0 # For USB sound card capture
.else
# ... (Fallback configuration if udev-detect is not available) ...
# You might need to add similar lines here if this block is active
### Fallback sink
load-module module-alsa-sink # Default sink
### Fallback source
load-module module-alsa-source device=hw:0,0 # Example for onboard capture
### Add for USB sound card if udev is not used
# load-module module-alsa-sink device=hw:1,0
# load-module module-alsa-source device=hw:1,0
.endif
# ... (Rest of the file) ...Important Notes:
Xindevice=hw:X,Yis the sound card number, andYis the PCM device number. You need to determine the actualXandYvalues for your USB sound card based on the output ofcat /proc/asound/cards(to see card X) andaplay -l/arecord -l(to see device Y).- Parameters like
mmap=false tsched=0 fragments=2 fragment_size=960 rate=48000 channels=2 rewind_safeguard=960in the example above are optimized for specific audio daughter boards. For a USB sound card, you may not need many of these parameters; you could try using onlydevice=hw:X,Yfirst. If you encounter audio stuttering or popping, you can try adjusting these parameters.
-
Save the configuration and reboot:
- Save the modifications to the
/etc/pulse/default.pafile. - Reboot the RDK development board to allow PulseAudio to reload the configuration.
- Alternatively, try restarting the PulseAudio service (if you know how and your system supports it, e.g.,
systemctl --user restart pulseaudio.serviceorpulseaudio -k && pulseaudio --start), though rebooting the board might be cleaner.
- Save the modifications to the
After rebooting, you should be able to see input and output devices for both sound cards in the system's sound settings (if using a desktop environment) or via pactl list sources / pactl list sinks, and select which one to use.