#include <unistd.h>
#include <alsa/asoundlib.h>
#include <alsa/pcm_external.h>
+#include <alsa/pcm_plugin.h>
#include <ffmpeg/avcodec.h>
struct a52_ctx {
snd_config_iterator_t i, next;
int err;
const char *card = NULL;
+ const char *pcm_string = NULL;
unsigned int rate = 48000;
unsigned int bitrate = 448;
unsigned int channels = 6;
}
continue;
}
+ if (strcmp(id, "slavepcm") == 0) {
+ if (snd_config_get_string(n, &pcm_string) < 0) {
+ SNDERR("a52 slavepcm must be a string");
+ return -EINVAL;
+ }
+ continue;
+ }
if (strcmp(id, "rate") == 0) {
long val;
if (snd_config_get_integer(n, &val) < 0) {
goto error;
}
- snprintf(devstr, sizeof(devstr),
- "plug:iec958:{AES0 0x%x AES1 0x%x AES2 0x%x AES3 0x%x %s%s}",
- IEC958_AES0_CON_EMPHASIS_NONE | IEC958_AES0_NONAUDIO |
- IEC958_AES0_CON_NOT_COPYRIGHT,
- IEC958_AES1_CON_ORIGINAL | IEC958_AES1_CON_PCM_CODER,
- 0, rate == 48000 ? IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100,
- card ? " CARD " : "",
- card ? card : "");
-
- err = snd_pcm_open(&rec->slave, devstr, stream, mode);
- if (err < 0)
- goto error;
+ if (! pcm_string) {
+ snprintf(devstr, sizeof(devstr),
+ "iec958:{AES0 0x%x AES1 0x%x AES2 0x%x AES3 0x%x %s%s}",
+ IEC958_AES0_CON_EMPHASIS_NONE | IEC958_AES0_NONAUDIO |
+ IEC958_AES0_CON_NOT_COPYRIGHT,
+ IEC958_AES1_CON_ORIGINAL | IEC958_AES1_CON_PCM_CODER,
+ 0, rate == 48000 ? IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100,
+ card ? " CARD " : "",
+ card ? card : "");
+ err = snd_pcm_open(&rec->slave, devstr, stream, mode);
+ if (err < 0)
+ goto error;
+ /* in case the slave doesn't support S16 format */
+ err = snd_pcm_linear_open(&rec->slave, NULL, SND_PCM_FORMAT_S16,
+ rec->slave, 1);
+ if (err < 0)
+ goto error;
+ } else {
+ err = snd_pcm_open(&rec->slave, pcm_string, stream, mode);
+ if (err < 0)
+ goto error;
+ }
rec->io.version = SND_PCM_IOPLUG_VERSION;
rec->io.name = "A52 Output Plugin";
The output PCM becomes "iec958:{CARD=$CARD}" with extra AESx
settings. When omitted, the default card is used.
+- The "slavepcm" option specifies a string of the slave PCM
+ explicitly. This is useful if a device has no proper SPDIF
+ configuration (e.g. usb-audio), or if you want to pass your own PCM
+ definition. This option is exclusive with "card" option.
+
- The "rate" option specifies the input/output sample rate in HZ.
The accepted rate is either 44100 or 48000.
When omitted, 48000 is used.
format S16_BE
}
+For using slavepcm option,
+
+ pcm.mypcm {
+ card 1
+ device 2
+ }
+
+ pcm.myout {
+ type a52
+ slavepcm "mypcm"
+ }
+
The plugin reads always S16 format (i.e. native-endian) as input, so
you'd need plug layer appropriately to covert it.