1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-27 01:22:30 +00:00

fixed spdif

spdif device depends now on the given subdevice
was hardcoded to hw:0,2 before
fixed opt-parsing for hw:x,y like opts
seperated initialization of spdif from common init as it was
probably intended before


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@6703 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
joyping 2002-07-11 10:20:54 +00:00
parent 5319a8118a
commit 51b5404658
2 changed files with 350 additions and 310 deletions

View File

@ -69,10 +69,9 @@ static int set_block_mode;
snd_pcm_t * snd_pcm_t *
spdif_init(int acard, int adevice) spdif_init(char *pcm_name)
{ {
//char *pcm_name = "hw:0,2"; /* first card second device */ //char *pcm_name = "hw:0,2"; /* first card second device */
char pcm_name[255];
static snd_aes_iec958_t spdif; static snd_aes_iec958_t spdif;
snd_pcm_info_t *info; snd_pcm_info_t *info;
snd_pcm_t *handler; snd_pcm_t *handler;
@ -81,11 +80,6 @@ spdif_init(int acard, int adevice)
unsigned int rate = 48000; unsigned int rate = 48000;
int err, c; int err, c;
if (err = snprintf(&pcm_name[0], 11, "hw:%1d,%1d", acard, adevice) <= 0)
{
return NULL;
}
if ((err = snd_pcm_open(&handler, pcm_name, SND_PCM_STREAM_PLAYBACK, 0)) < 0) if ((err = snd_pcm_open(&handler, pcm_name, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
{ {
fprintf(stderr, "open: %s\n", snd_strerror(err)); fprintf(stderr, "open: %s\n", snd_strerror(err));
@ -128,11 +122,11 @@ spdif_init(int acard, int adevice)
sprintf(ctl_name, "hw:%d", ctl_card); sprintf(ctl_name, "hw:%d", ctl_card);
printf("hw:%d\n", ctl_card); printf("hw:%d\n", ctl_card);
if ((err = snd_ctl_open(&ctl_handler, ctl_name, 0)) < 0) { if ((err = snd_ctl_open(&ctl_handler, ctl_name, 0)) < 0) {
fprintf(stderr, "Unable to open the control interface '%s': %s", ctl_name, snd_strerror(err)); fprintf(stderr, "Unable to open the control interface '%s': %s\n", ctl_name, snd_strerror(err));
goto __diga_end; goto __diga_end;
} }
if ((err = snd_ctl_elem_write(ctl_handler, ctl)) < 0) { if ((err = snd_ctl_elem_write(ctl_handler, ctl)) < 0) {
fprintf(stderr, "Unable to update the IEC958 control: %s", snd_strerror(err)); fprintf(stderr, "Unable to update the IEC958 control: %s\n", snd_strerror(err));
goto __diga_end; goto __diga_end;
} }
snd_ctl_close(ctl_handler); snd_ctl_close(ctl_handler);
@ -302,6 +296,7 @@ static int init(int rate_hz, int channels, int format, int flags)
int period_val; int period_val;
snd_pcm_info_t *alsa_info; snd_pcm_info_t *alsa_info;
char *str_block_mode; char *str_block_mode;
int device_set = 0;
printf("alsa-init: testing and bugreports are welcome.\n"); printf("alsa-init: testing and bugreports are welcome.\n");
printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz,
@ -402,10 +397,22 @@ static int init(int rate_hz, int channels, int format, int flags)
ao_noblock = 1; ao_noblock = 1;
} }
else if (strcmp(*(token_str+i3), "hw") == 0) { else if (strcmp(*(token_str+i3), "hw") == 0) {
alsa_device = *(token_str+i3); if ((i3 < i2-1) && (strcmp(*(token_str+i3+1), "noblock") != 0) && (strcmp(*(token_str+i3+1), "mmap") != 0)) {
//printf("next tok = %s\n", *(token_str+(i3+1)));
alsa_device = alloca(ALSA_DEVICE_SIZE);
snprintf(alsa_device, ALSA_DEVICE_SIZE, "hw:%s", *(token_str+(i3+1)));
device_set = 1;
} }
else if (!alsa_device || !ao_mmap || !ao_noblock) { else {
//printf("setting hw\n");
alsa_device = *(token_str+i3); alsa_device = *(token_str+i3);
device_set = 1;
}
}
else if (device_set == 0 && (!ao_mmap || !ao_noblock)) {
//printf("setting common, %s\n", *(token_str+i3));
alsa_device = *(token_str+i3);
device_set = 1;
} }
} }
} }
@ -448,14 +455,27 @@ static int init(int rate_hz, int channels, int format, int flags)
} }
snd_pcm_info_free(alsa_info); snd_pcm_info_free(alsa_info);
}
printf("alsa-init: %d soundcard%s found, using: %s\n", cards+1, printf("alsa-init: %d soundcard%s found, using: %s\n", cards+1,
(cards >= 0) ? "" : "s", alsa_device); (cards >= 0) ? "" : "s", alsa_device);
} else if (strcmp(alsa_device, "help") == 0) {
printf("alsa-help: available options are:\n");
printf(" mmap: sets mmap-mode\n");
printf(" noblock: sets noblock-mode\n");
printf(" device-name: sets device name\n");
printf(" example -ao alsa9:mmap:noblock:hw:0,3 sets noblock-mode,\n");
printf(" mmap-mode and the device-name as first card third device\n");
return(0);
} else {
printf("alsa-init: soundcard set to %s\n", alsa_device);
}
if (format == AFMT_AC3) { // switch for spdif
// Try to initialize the SPDIF interface // Try to initialize the SPDIF interface
alsa_handler = spdif_init(0, 2); if (format == AFMT_AC3) {
if (device_set)
alsa_handler = spdif_init(alsa_device);
else
alsa_handler = spdif_init("hw:0,2");
} }
//setting modes for block or nonblock-mode //setting modes for block or nonblock-mode
@ -470,9 +490,8 @@ static int init(int rate_hz, int channels, int format, int flags)
str_block_mode = "block-mode"; str_block_mode = "block-mode";
} }
//modes = 0, SND_PCM_NONBLOCK, SND_PCM_ASYNC
if (!alsa_handler) { if (!alsa_handler) {
//modes = 0, SND_PCM_NONBLOCK, SND_PCM_ASYNC
if ((err = snd_pcm_open(&alsa_handler, alsa_device, SND_PCM_STREAM_PLAYBACK, open_mode)) < 0) if ((err = snd_pcm_open(&alsa_handler, alsa_device, SND_PCM_STREAM_PLAYBACK, open_mode)) < 0)
{ {
if (ao_noblock) { if (ao_noblock) {
@ -489,7 +508,6 @@ static int init(int rate_hz, int channels, int format, int flags)
return(0); return(0);
} }
} }
}
if ((err = snd_pcm_nonblock(alsa_handler, set_block_mode)) < 0) { if ((err = snd_pcm_nonblock(alsa_handler, set_block_mode)) < 0) {
printf("alsa-init: error set block-mode %s\n", snd_strerror(err)); printf("alsa-init: error set block-mode %s\n", snd_strerror(err));
@ -665,6 +683,8 @@ static int init(int rate_hz, int channels, int format, int flags)
printf("alsa9: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n", printf("alsa9: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n",
ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize, ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize,
snd_pcm_format_description(alsa_format)); snd_pcm_format_description(alsa_format));
} // end switch alsa_handler (spdif)
return(1); return(1);
} // end init } // end init

View File

@ -69,10 +69,9 @@ static int set_block_mode;
snd_pcm_t * snd_pcm_t *
spdif_init(int acard, int adevice) spdif_init(char *pcm_name)
{ {
//char *pcm_name = "hw:0,2"; /* first card second device */ //char *pcm_name = "hw:0,2"; /* first card second device */
char pcm_name[255];
static snd_aes_iec958_t spdif; static snd_aes_iec958_t spdif;
snd_pcm_info_t *info; snd_pcm_info_t *info;
snd_pcm_t *handler; snd_pcm_t *handler;
@ -81,11 +80,6 @@ spdif_init(int acard, int adevice)
unsigned int rate = 48000; unsigned int rate = 48000;
int err, c; int err, c;
if (err = snprintf(&pcm_name[0], 11, "hw:%1d,%1d", acard, adevice) <= 0)
{
return NULL;
}
if ((err = snd_pcm_open(&handler, pcm_name, SND_PCM_STREAM_PLAYBACK, 0)) < 0) if ((err = snd_pcm_open(&handler, pcm_name, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
{ {
fprintf(stderr, "open: %s\n", snd_strerror(err)); fprintf(stderr, "open: %s\n", snd_strerror(err));
@ -128,11 +122,11 @@ spdif_init(int acard, int adevice)
sprintf(ctl_name, "hw:%d", ctl_card); sprintf(ctl_name, "hw:%d", ctl_card);
printf("hw:%d\n", ctl_card); printf("hw:%d\n", ctl_card);
if ((err = snd_ctl_open(&ctl_handler, ctl_name, 0)) < 0) { if ((err = snd_ctl_open(&ctl_handler, ctl_name, 0)) < 0) {
fprintf(stderr, "Unable to open the control interface '%s': %s", ctl_name, snd_strerror(err)); fprintf(stderr, "Unable to open the control interface '%s': %s\n", ctl_name, snd_strerror(err));
goto __diga_end; goto __diga_end;
} }
if ((err = snd_ctl_elem_write(ctl_handler, ctl)) < 0) { if ((err = snd_ctl_elem_write(ctl_handler, ctl)) < 0) {
fprintf(stderr, "Unable to update the IEC958 control: %s", snd_strerror(err)); fprintf(stderr, "Unable to update the IEC958 control: %s\n", snd_strerror(err));
goto __diga_end; goto __diga_end;
} }
snd_ctl_close(ctl_handler); snd_ctl_close(ctl_handler);
@ -302,6 +296,7 @@ static int init(int rate_hz, int channels, int format, int flags)
int period_val; int period_val;
snd_pcm_info_t *alsa_info; snd_pcm_info_t *alsa_info;
char *str_block_mode; char *str_block_mode;
int device_set = 0;
printf("alsa-init: testing and bugreports are welcome.\n"); printf("alsa-init: testing and bugreports are welcome.\n");
printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz,
@ -402,10 +397,22 @@ static int init(int rate_hz, int channels, int format, int flags)
ao_noblock = 1; ao_noblock = 1;
} }
else if (strcmp(*(token_str+i3), "hw") == 0) { else if (strcmp(*(token_str+i3), "hw") == 0) {
alsa_device = *(token_str+i3); if ((i3 < i2-1) && (strcmp(*(token_str+i3+1), "noblock") != 0) && (strcmp(*(token_str+i3+1), "mmap") != 0)) {
//printf("next tok = %s\n", *(token_str+(i3+1)));
alsa_device = alloca(ALSA_DEVICE_SIZE);
snprintf(alsa_device, ALSA_DEVICE_SIZE, "hw:%s", *(token_str+(i3+1)));
device_set = 1;
} }
else if (!alsa_device || !ao_mmap || !ao_noblock) { else {
//printf("setting hw\n");
alsa_device = *(token_str+i3); alsa_device = *(token_str+i3);
device_set = 1;
}
}
else if (device_set == 0 && (!ao_mmap || !ao_noblock)) {
//printf("setting common, %s\n", *(token_str+i3));
alsa_device = *(token_str+i3);
device_set = 1;
} }
} }
} }
@ -448,14 +455,27 @@ static int init(int rate_hz, int channels, int format, int flags)
} }
snd_pcm_info_free(alsa_info); snd_pcm_info_free(alsa_info);
}
printf("alsa-init: %d soundcard%s found, using: %s\n", cards+1, printf("alsa-init: %d soundcard%s found, using: %s\n", cards+1,
(cards >= 0) ? "" : "s", alsa_device); (cards >= 0) ? "" : "s", alsa_device);
} else if (strcmp(alsa_device, "help") == 0) {
printf("alsa-help: available options are:\n");
printf(" mmap: sets mmap-mode\n");
printf(" noblock: sets noblock-mode\n");
printf(" device-name: sets device name\n");
printf(" example -ao alsa9:mmap:noblock:hw:0,3 sets noblock-mode,\n");
printf(" mmap-mode and the device-name as first card third device\n");
return(0);
} else {
printf("alsa-init: soundcard set to %s\n", alsa_device);
}
if (format == AFMT_AC3) { // switch for spdif
// Try to initialize the SPDIF interface // Try to initialize the SPDIF interface
alsa_handler = spdif_init(0, 2); if (format == AFMT_AC3) {
if (device_set)
alsa_handler = spdif_init(alsa_device);
else
alsa_handler = spdif_init("hw:0,2");
} }
//setting modes for block or nonblock-mode //setting modes for block or nonblock-mode
@ -470,9 +490,8 @@ static int init(int rate_hz, int channels, int format, int flags)
str_block_mode = "block-mode"; str_block_mode = "block-mode";
} }
//modes = 0, SND_PCM_NONBLOCK, SND_PCM_ASYNC
if (!alsa_handler) { if (!alsa_handler) {
//modes = 0, SND_PCM_NONBLOCK, SND_PCM_ASYNC
if ((err = snd_pcm_open(&alsa_handler, alsa_device, SND_PCM_STREAM_PLAYBACK, open_mode)) < 0) if ((err = snd_pcm_open(&alsa_handler, alsa_device, SND_PCM_STREAM_PLAYBACK, open_mode)) < 0)
{ {
if (ao_noblock) { if (ao_noblock) {
@ -489,7 +508,6 @@ static int init(int rate_hz, int channels, int format, int flags)
return(0); return(0);
} }
} }
}
if ((err = snd_pcm_nonblock(alsa_handler, set_block_mode)) < 0) { if ((err = snd_pcm_nonblock(alsa_handler, set_block_mode)) < 0) {
printf("alsa-init: error set block-mode %s\n", snd_strerror(err)); printf("alsa-init: error set block-mode %s\n", snd_strerror(err));
@ -665,6 +683,8 @@ static int init(int rate_hz, int channels, int format, int flags)
printf("alsa9: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n", printf("alsa9: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n",
ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize, ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize,
snd_pcm_format_description(alsa_format)); snd_pcm_format_description(alsa_format));
} // end switch alsa_handler (spdif)
return(1); return(1);
} // end init } // end init