Преглед на файлове

Z991239-2910 #comment [localmediaplayer] 优化音频设备操作流程

陈礼鹏80274480 преди 3 години
родител
ревизия
834913cafa
променени са 2 файла, в които са добавени 27 реда и са изтрити 27 реда
  1. 26 26
      Other/libmediaplayer/audio.cpp
  2. 1 1
      Other/libmediaplayer/player.h

+ 26 - 26
Other/libmediaplayer/audio.cpp

@@ -358,32 +358,33 @@ static int open_audio_playing(void *arg)
 	wanted_spec.callback = sdl_audio_callback;          // 回调函数,若为NULL,则应使用SDL_QueueAudio()机制
     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);
-	int i = 0;
-	for (; 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, "%s matched audio device name is %s.", is->paudiodev, strdevname);
-			break;
+	if (NULL == strdevname) {
+		int iaudioapeaker = SDL_GetNumAudioDevices(0);
+		is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "audio output device number is %d.", iaudioapeaker);
+		int i = 0;
+		for (; 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, "%s matched audio device name is %s.", is->paudiodev, strdevname);
+				break;
+			}
 		}
+		if (i == iaudioapeaker) {
+			is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "matched audio device name (%s) failed!", strdevname ? strdevname : "null");
+		}
+
+		{
+			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);
+			}
+		}
+		is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "current audio driver name is %s.", SDL_GetCurrentAudioDriver());
 	}
-	if (i == iaudioapeaker){
-		is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "matched audio device name (%s) failed!", strdevname ? strdevname : "null");
-	}
-	
-	//{
-	//	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);
-	//	}
-	//}
-	is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "current audio driver name is %s.", SDL_GetCurrentAudioDriver());
 
 	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());
@@ -414,8 +415,7 @@ static int open_audio_playing(void *arg)
 
 	SDL_PauseAudioDevice(audio_dev, 0);
 
-	while (false == is->baudio_finished)
-	{
+	while (false == is->baudio_finished){
 		SDL_Delay(1);
 	}
 

+ 1 - 1
Other/libmediaplayer/player.h

@@ -263,7 +263,7 @@ void set_clock_at(play_clock_t *c, double pts, int serial, double time);
 void set_clock(play_clock_t *c, double pts, int serial);
 
 static SDL_AudioDeviceID audio_dev;
-
+static const char* strdevname = NULL;
 class CMediaPlayer
 {
 public: