|
@@ -372,29 +372,31 @@ static int open_audio_playing(void *arg)
|
|
|
wanted_spec.userdata = is; // 提供给回调函数的参数
|
|
|
|
|
|
int iaudioapeaker = SDL_GetNumAudioDevices(0);
|
|
|
+ const char* strdevname = NULL;
|
|
|
is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "audio output device number is %d.", iaudioapeaker);
|
|
|
for (int i = 0; i < iaudioapeaker; i++) {
|
|
|
is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "device id %d audio device name is %s.", i, SDL_GetAudioDeviceName(i, 0));
|
|
|
+ if (is->paudiodev && strstr(SDL_GetAudioDeviceName(i, 0), is->paudiodev)){
|
|
|
+ strdevname = SDL_GetAudioDeviceName(i, 0);
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "mathed audio device name is %s.", strdevname);
|
|
|
+ }
|
|
|
}
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "current audio driver name is %s.", SDL_GetCurrentAudioDriver());
|
|
|
+ //{
|
|
|
+ // int inum = SDL_GetNumAudioDrivers();
|
|
|
+ // int i = 0;
|
|
|
+ // is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "Audio Drivers number is %d.", inum);
|
|
|
+ // for (; i < inum; i++) {
|
|
|
+ // const char* drivername = SDL_GetAudioDriver(i);
|
|
|
+ // is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "[%d] Audio Drivers name is %s.", i, drivername);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
|
|
|
- if (SDL_OpenAudio(&wanted_spec, &actual_spec) < 0){
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_OpenAudio() failed: %s.", SDL_GetError());
|
|
|
- return -1;
|
|
|
- }
|
|
|
- else {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "-----------SDL_OpenAudio() success:");
|
|
|
+ //SDL_AudioDeviceID audio_dev = 0;
|
|
|
+ while (!(audio_dev = SDL_OpenAudioDevice(strdevname, 0, &wanted_spec, &actual_spec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_CHANNELS_CHANGE))){
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "SDL_OpenAudio (%d channels, %d Hz): %s",wanted_spec.channels, wanted_spec.freq, SDL_GetError());
|
|
|
}
|
|
|
|
|
|
- //SDL_AudioDeviceID idev = 0;
|
|
|
- //idev = SDL_OpenAudioDevice(NULL, 0, &wanted_spec, &actual_spec, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
|
|
|
- //if (0 == idev) {
|
|
|
- // is->rvc_hostapi->Debug("SDL Open Audio Device failed: %s.", SDL_GetError());
|
|
|
- // return -1;
|
|
|
- //}
|
|
|
- //else {
|
|
|
- // is->rvc_hostapi->Debug("-----------SDL Open Audio Device{id=%d} success.", idev);
|
|
|
- //}
|
|
|
-
|
|
|
// 2.2 根据SDL音频参数构建音频重采样参数
|
|
|
// wanted_spec是期望的参数,actual_spec是实际的参数,wanted_spec和auctual_spec都是SDL中的参数。
|
|
|
// 此处audio_param是FFmpeg中的参数,此参数应保证是SDL播放支持的参数,后面重采样要用到此参数
|
|
@@ -409,8 +411,8 @@ static int open_audio_playing(void *arg)
|
|
|
is->audio_param_tgt.bytes_per_sec = av_samples_get_buffer_size(NULL, actual_spec.channels, actual_spec.freq, is->audio_param_tgt.fmt, 1);
|
|
|
if (is->audio_param_tgt.bytes_per_sec <= 0 || is->audio_param_tgt.frame_size <= 0){
|
|
|
is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "av_samples_get_buffer_size failed.");
|
|
|
- //SDL_CloseAudioDevice(idev);
|
|
|
- SDL_CloseAudio();
|
|
|
+ SDL_CloseAudioDevice(audio_dev);
|
|
|
+ //SDL_CloseAudio();
|
|
|
return -1;
|
|
|
}
|
|
|
is->audio_param_src = is->audio_param_tgt;
|
|
@@ -422,15 +424,15 @@ static int open_audio_playing(void *arg)
|
|
|
// 打开音频设备后默认未启动回调处理,通过调用SDL_PauseAudio(0)来启动回调处理。
|
|
|
// 这样就可以在打开音频设备后先为回调函数安全初始化数据,一切就绪后再启动音频回调。
|
|
|
// 在暂停期间,会将静音值往音频设备写。
|
|
|
- SDL_PauseAudio(0);
|
|
|
- //SDL_PauseAudioDevice(idev, 0);
|
|
|
+ //SDL_PauseAudio(0);
|
|
|
+ SDL_PauseAudioDevice(audio_dev, 0);
|
|
|
|
|
|
while (is->abort_request == 0){
|
|
|
SDL_Delay(1);
|
|
|
}
|
|
|
is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "----------%s:%d before SDL Close Audio", __FUNCTION__, __LINE__);
|
|
|
- SDL_CloseAudio();
|
|
|
- //SDL_CloseAudioDevice(idev);
|
|
|
+ //SDL_CloseAudio();
|
|
|
+ SDL_CloseAudioDevice(audio_dev);
|
|
|
is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "---------%s:%d after SDL Close Audio", __FUNCTION__, __LINE__);
|
|
|
|
|
|
return 0;
|
|
@@ -487,7 +489,8 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
|
|
|
//is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "on_audio_volume success.");
|
|
|
}
|
|
|
//is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "audio uVolume is %d.", ivolume);
|
|
|
- SDL_MixAudio(stream, (uint8_t*)is->p_audio_frm + is->audio_cp_index, len1, ivolume);
|
|
|
+ //SDL_MixAudio(stream, (uint8_t*)is->p_audio_frm + is->audio_cp_index, len1, ivolume);
|
|
|
+ SDL_MixAudioFormat(stream, (uint8_t*)is->p_audio_frm + is->audio_cp_index, AUDIO_S16SYS, len1, ivolume);
|
|
|
}
|
|
|
else{
|
|
|
SDL_memset(stream, 0, len1);
|