Index: ao_alsa.c =================================================================== RCS file: /cvsroot/mplayer/main/libao2/ao_alsa.c,v retrieving revision 1.2 diff -u -r1.2 ao_alsa.c --- ao_alsa.c 11 Jun 2004 15:20:49 -0000 1.2 +++ ao_alsa.c 27 Jun 2004 21:08:05 -0000 @@ -53,7 +53,6 @@ static snd_pcm_format_t alsa_format; static snd_pcm_hw_params_t *alsa_hwparams; static snd_pcm_sw_params_t *alsa_swparams; -static char *alsa_device; /* possible 4096, original 8192 * was only needed for calculating chunksize? */ @@ -77,7 +76,7 @@ static int set_block_mode; static int alsa_can_pause = 0; -#define ALSA_DEVICE_SIZE 48 +#define ALSA_DEVICE_SIZE 256 #undef BUFFERTIME #undef SET_CHUNKSIZE @@ -100,27 +99,15 @@ snd_mixer_elem_t *elem; snd_mixer_selem_id_t *sid; - static char *mix_name = NULL; - static char *card = NULL; + static char *mix_name = "PCM"; + static char *card = "default"; long pmin, pmax; long get_vol, set_vol; float calc_vol, diff, f_multi; - if(mix_name == NULL){ - if(mixer_device) { - card = strdup(mixer_device); - mix_name = strchr(card, '/'); - if(mix_name) { - *mix_name++ = 0; - } else { - mix_name = "PCM"; - } - } else { - mix_name = "PCM"; - card = "default"; - } - } + if(mixer_channel) mix_name = mixer_channel; + if(mixer_device) card = mixer_device; if(ao_data.format == AFMT_AC3) return CONTROL_TRUE; @@ -225,6 +212,9 @@ int device_set = 0; int dir = 0; snd_pcm_uframes_t bufsize; + char alsa_device[ALSA_DEVICE_SIZE + 1]; + // make sure alsa_device is null-terminated even when using strncpy etc. + memset(alsa_device, 0, ALSA_DEVICE_SIZE + 1); mp_msg(MSGT_AO,MSGL_V,"alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, channels, audio_out_format_name(format)); @@ -343,19 +333,18 @@ if ((i3 < i2-1) && (strcmp(*(token_str+i3+1), "noblock") != 0) && (strcmp(*(token_str+i3+1), "mmap") != 0)) { char *tmp; - alsa_device = alloca(ALSA_DEVICE_SIZE); snprintf(alsa_device, ALSA_DEVICE_SIZE, "hw:%s", *(token_str+(i3+1))); if ((tmp = strrchr(alsa_device, '.')) && isdigit(*(tmp+1))) *tmp = ','; device_set = 1; } else { - alsa_device = *(token_str+i3); + strncpy (alsa_device, token_str[i3], ALSA_DEVICE_SIZE); device_set = 1; } } else if (device_set == 0 && (!ao_mmap || !ao_noblock)) { - alsa_device = *(token_str+i3); + strncpy (alsa_device, token_str[i3], ALSA_DEVICE_SIZE); device_set = 1; } } @@ -364,8 +353,6 @@ /* in any case for multichannel playback we should select * appropriate device */ - char devstr[128]; - switch (channels) { case 1: case 2: @@ -374,18 +361,18 @@ case 4: if (alsa_format == SND_PCM_FORMAT_FLOAT_LE) // hack - use the converter plugin - strcpy(devstr, "plug:surround40"); + strncpy(alsa_device, "plug:surround40", ALSA_DEVICE_SIZE); else - strcpy(devstr, "surround40"); - alsa_device = devstr; + strncpy(alsa_device, "surround40", ALSA_DEVICE_SIZE); + device_set = 1; mp_msg(MSGT_AO,MSGL_V,"alsa-init: device set to surround40\n"); break; case 6: if (alsa_format == SND_PCM_FORMAT_FLOAT_LE) - strcpy(devstr, "plug:surround51"); + strncpy(alsa_device, "plug:surround51", ALSA_DEVICE_SIZE); else - strcpy(devstr, "surround51"); - alsa_device = devstr; + strncpy(alsa_device, "surround51", ALSA_DEVICE_SIZE); + device_set = 1; mp_msg(MSGT_AO,MSGL_V,"alsa-init: device set to surround51\n"); break; default: @@ -400,7 +387,6 @@ * 'iec958' */ if (format == AFMT_AC3) { - char devstr[128]; unsigned char s[4]; //int err, c; //unused @@ -415,27 +401,30 @@ s[2] = 0; s[3] = IEC958_AES3_CON_FS_48000; - sprintf(devstr, "iec958:AES0=0x%x,AES1=0x%x,AES2=0x%x,AES3=0x%x", + snprintf(alsa_device, ALSA_DEVICE_SIZE, + "iec958:AES0=0x%x,AES1=0x%x,AES2=0x%x,AES3=0x%x", s[0], s[1], s[2], s[3]); + device_set = 1; mp_msg(MSGT_AO,MSGL_V,"alsa-spdif-init: playing AC3, %i channels\n", channels); break; case 4: - strcpy(devstr, "surround40"); + strncpy(alsa_device, "surround40", ALSA_DEVICE_SIZE); + device_set = 1; break; case 6: - strcpy(devstr, "surround51"); + strncpy(alsa_device, "surround51", ALSA_DEVICE_SIZE); + device_set = 1; break; default: mp_msg(MSGT_AO,MSGL_ERR,"alsa-spdif-init: %d channels are not supported\n", channels); } - alsa_device = devstr; } - if (alsa_device == NULL) + if (!device_set) { int tmp_device, tmp_subdevice, err; @@ -444,11 +433,6 @@ mp_msg(MSGT_AO,MSGL_ERR,"alsa-init: memory allocation error: %s\n", snd_strerror(err)); } - if ((alsa_device = alloca(ALSA_DEVICE_SIZE)) == NULL) - { - mp_msg(MSGT_AO,MSGL_ERR,"alsa-init: memory allocation error: %s\n", strerror(errno)); - } - if ((tmp_device = snd_pcm_info_get_device(alsa_info)) < 0) { mp_msg(MSGT_AO,MSGL_ERR,"alsa-init: can't get device\n"); @@ -762,7 +746,6 @@ } else { alsa_handler = NULL; - alsa_device = NULL; mp_msg(MSGT_AO,MSGL_INFO,"alsa-uninit: pcm closed\n"); } }