|
@@ -165,7 +165,7 @@ int open_audio_stream(player_stat_t *is)
|
|
|
// 1.2 获取解码器
|
|
|
p_codec = avcodec_find_decoder(p_codec_par->codec_id);
|
|
|
if (NULL == p_codec) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "Cann't find codec!");
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "Cann't find codec!");
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -173,19 +173,19 @@ int open_audio_stream(player_stat_t *is)
|
|
|
// 1.3.1 p_codec_ctx初始化:分配结构体,使用p_codec初始化相应成员为默认值
|
|
|
p_codec_ctx = avcodec_alloc_context3(p_codec);
|
|
|
if (p_codec_ctx == NULL) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "avcodec_alloc_context3() failed.");
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "avcodec_alloc_context3() failed.");
|
|
|
return ret;
|
|
|
}
|
|
|
// 1.3.2 p_codec_ctx初始化:p_codec_par ==> p_codec_ctx,初始化相应成员
|
|
|
ret = avcodec_parameters_to_context(p_codec_ctx, p_codec_par);
|
|
|
if (ret < 0) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "avcodec_parameters_to_context() failed %d.", ret);
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "avcodec_parameters_to_context() failed %d.", ret);
|
|
|
return ret;
|
|
|
}
|
|
|
// 1.3.3 p_codec_ctx初始化:使用p_codec初始化p_codec_ctx,初始化完成
|
|
|
ret = avcodec_open2(p_codec_ctx, p_codec, NULL);
|
|
|
if (ret < 0) {
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "avcodec_open2() failed %d.", ret);
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "avcodec_open2() failed %d.", ret);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -224,7 +224,6 @@ static int audio_resample(player_stat_t *is, int64_t audio_callback_time)
|
|
|
av_usleep(1000);
|
|
|
}
|
|
|
|
|
|
- //is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "%s:%d.", __FUNCTION__, __LINE__);
|
|
|
// 若队列头部可读,则由af指向可读帧
|
|
|
if (!(af = frame_queue_peek_readable(&is->audio_frm_queue))) {
|
|
|
is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "%s:%d user stop flag is %s, function return", __FUNCTION__, __LINE__, is->buser_stop ? "true" : "false");
|
|
@@ -259,7 +258,7 @@ static int audio_resample(player_stat_t *is, int64_t audio_callback_time)
|
|
|
0, NULL);
|
|
|
if (!is->audio_swr_ctx || swr_init(is->audio_swr_ctx) < 0)
|
|
|
{
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!",
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!",
|
|
|
af->frame->sample_rate, av_get_sample_fmt_name((AVSampleFormat)af->frame->format), af->frame->channels,
|
|
|
is->audio_param_tgt.freq, av_get_sample_fmt_name((AVSampleFormat)is->audio_param_tgt.fmt), is->audio_param_tgt.channels);
|
|
|
swr_free(&is->audio_swr_ctx);
|
|
@@ -286,7 +285,7 @@ static int audio_resample(player_stat_t *is, int64_t audio_callback_time)
|
|
|
int out_size = av_samples_get_buffer_size(NULL, is->audio_param_tgt.channels, out_count, (AVSampleFormat)is->audio_param_tgt.fmt, 0);
|
|
|
int len2 = 0;
|
|
|
if (out_size < 0){
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "av_samples_get_buffer_size() failed.");
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "av_samples_get_buffer_size() failed.");
|
|
|
return -1;
|
|
|
}
|
|
|
av_fast_malloc(&is->audio_frm_rwr, &is->audio_frm_rwr_size, out_size);
|
|
@@ -296,12 +295,12 @@ static int audio_resample(player_stat_t *is, int64_t audio_callback_time)
|
|
|
// 音频重采样:返回值是重采样后得到的音频数据中单个声道的样本数
|
|
|
len2 = swr_convert(is->audio_swr_ctx, out, out_count, in, af->frame->nb_samples);
|
|
|
if (len2 < 0){
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "swr_convert() failed.");
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "swr_convert() failed.");
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
if (len2 == out_count){
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "audio buffer is probably too small.");
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "audio buffer is probably too small.");
|
|
|
if (swr_init(is->audio_swr_ctx) < 0)
|
|
|
swr_free(&is->audio_swr_ctx);
|
|
|
}
|
|
@@ -358,14 +357,14 @@ static int open_audio_playing(void *arg)
|
|
|
|
|
|
if (NULL == is->straudiodev) {
|
|
|
int iaudioapeaker = SDL_GetNumAudioDevices(0);
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "audio output device number is %d.", iaudioapeaker);
|
|
|
+ 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));
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "device id %d audio device name is %s.", i, SDL_GetAudioDeviceName(i, 0));
|
|
|
if (is->paudiodev && strstr(SDL_GetAudioDeviceName(i, 0), is->paudiodev)) {
|
|
|
const char* strdevname = SDL_GetAudioDeviceName(i, 0);
|
|
|
is->straudiodev = av_strdup(strdevname);
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "%s matched audio device name is %s.", is->paudiodev, strdevname);
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_INFO, "%s matched audio device name is %s.", is->paudiodev, strdevname);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -382,10 +381,10 @@ static int open_audio_playing(void *arg)
|
|
|
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());
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_INFO, "current audio driver name is %s.", SDL_GetCurrentAudioDriver());
|
|
|
}
|
|
|
|
|
|
- while (!(audio_dev = SDL_OpenAudioDevice(is->straudiodev, 0, &wanted_spec, &actual_spec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_CHANNELS_CHANGE))){
|
|
|
+ while (!(is->m_audio_dev = SDL_OpenAudioDevice(is->straudiodev, 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());
|
|
|
if (!wanted_spec.channels) {
|
|
|
if (!wanted_spec.freq) {
|
|
@@ -395,7 +394,7 @@ static int open_audio_playing(void *arg)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "SDL_OpenAudioDevice success and audio_dev is %d.", audio_dev);
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_INFO, "SDL_OpenAudioDevice success and audio_dev is %d.", is->m_audio_dev);
|
|
|
is->audio_param_tgt.fmt = AV_SAMPLE_FMT_S16;
|
|
|
is->audio_param_tgt.freq = actual_spec.freq;
|
|
|
is->audio_param_tgt.channel_layout = av_get_default_channel_layout(actual_spec.channels);
|
|
@@ -403,11 +402,11 @@ static int open_audio_playing(void *arg)
|
|
|
is->audio_param_tgt.frame_size = av_samples_get_buffer_size(NULL, actual_spec.channels, 1, (AVSampleFormat)is->audio_param_tgt.fmt, 1);
|
|
|
is->audio_param_tgt.bytes_per_sec = av_samples_get_buffer_size(NULL, actual_spec.channels, actual_spec.freq, (AVSampleFormat)is->audio_param_tgt.fmt, 1);
|
|
|
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "audio param target (%d channels, %d Hz, channel_layout(%d), frame_size(%d), bytes_per_sec(%d)).", actual_spec.channels, actual_spec.freq, is->audio_param_tgt.channel_layout, is->audio_param_tgt.frame_size, is->audio_param_tgt.bytes_per_sec);
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_INFO, "audio param target (%d channels, %d Hz, channel_layout(%d), frame_size(%d), bytes_per_sec(%d)).", actual_spec.channels, actual_spec.freq, is->audio_param_tgt.channel_layout, is->audio_param_tgt.frame_size, is->audio_param_tgt.bytes_per_sec);
|
|
|
|
|
|
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(audio_dev);
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_ERROR, "av_samples_get_buffer_size failed.");
|
|
|
+ SDL_CloseAudioDevice(is->m_audio_dev);
|
|
|
return -1;
|
|
|
}
|
|
|
is->audio_param_src = is->audio_param_tgt;
|
|
@@ -415,15 +414,15 @@ static int open_audio_playing(void *arg)
|
|
|
is->audio_frm_size = 0;
|
|
|
is->audio_cp_index = 0;
|
|
|
|
|
|
- SDL_PauseAudioDevice(audio_dev, 0);
|
|
|
+ SDL_PauseAudioDevice(is->m_audio_dev, 0);
|
|
|
|
|
|
SDL_LockMutex(is->audio_play_wait_mutex);
|
|
|
SDL_CondWait(is->audio_play_cond, is->audio_play_wait_mutex);
|
|
|
SDL_UnlockMutex(is->audio_play_wait_mutex);
|
|
|
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "----------%s:%d before SDL Close Audio Device.", __FUNCTION__, __LINE__);
|
|
|
- SDL_CloseAudioDevice(audio_dev);
|
|
|
- is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "---------%s:%d after SDL Close Audio Device.", __FUNCTION__, __LINE__);
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_INFO, "----------%s:%d before SDL Close Audio Device.", __FUNCTION__, __LINE__);
|
|
|
+ SDL_CloseAudioDevice(is->m_audio_dev);
|
|
|
+ is->rvc_hostapi->Debug(MEDIA_LOG_INFO, "---------%s:%d after SDL Close Audio Device", __FUNCTION__, __LINE__);
|
|
|
|
|
|
return 0;
|
|
|
}
|