Commit d68a557d authored by Marton Balint's avatar Marton Balint

ffplay: use SDL2 audio API

It allows us to specify what kind of audio parameter changes are allowed.

Should fix ticket #6721.
Signed-off-by: 's avatarMarton Balint <cus@passwd.hu>
parent cb618da8
...@@ -362,6 +362,7 @@ static AVPacket flush_pkt; ...@@ -362,6 +362,7 @@ static AVPacket flush_pkt;
static SDL_Window *window; static SDL_Window *window;
static SDL_Renderer *renderer; static SDL_Renderer *renderer;
static SDL_RendererInfo renderer_info = {0}; static SDL_RendererInfo renderer_info = {0};
static SDL_AudioDeviceID audio_dev;
static const struct TextureFormatEntry { static const struct TextureFormatEntry {
enum AVPixelFormat format; enum AVPixelFormat format;
...@@ -1192,7 +1193,7 @@ static void stream_component_close(VideoState *is, int stream_index) ...@@ -1192,7 +1193,7 @@ static void stream_component_close(VideoState *is, int stream_index)
switch (codecpar->codec_type) { switch (codecpar->codec_type) {
case AVMEDIA_TYPE_AUDIO: case AVMEDIA_TYPE_AUDIO:
decoder_abort(&is->auddec, &is->sampq); decoder_abort(&is->auddec, &is->sampq);
SDL_CloseAudio(); SDL_CloseAudioDevice(audio_dev);
decoder_destroy(&is->auddec); decoder_destroy(&is->auddec);
swr_free(&is->swr_ctx); swr_free(&is->swr_ctx);
av_freep(&is->audio_buf1); av_freep(&is->audio_buf1);
...@@ -2451,7 +2452,7 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len) ...@@ -2451,7 +2452,7 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
else { else {
memset(stream, 0, len1); memset(stream, 0, len1);
if (!is->muted && is->audio_buf) if (!is->muted && is->audio_buf)
SDL_MixAudio(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1, is->audio_volume); SDL_MixAudioFormat(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, AUDIO_S16SYS, len1, is->audio_volume);
} }
len -= len1; len -= len1;
stream += len1; stream += len1;
...@@ -2496,7 +2497,7 @@ static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb ...@@ -2496,7 +2497,7 @@ static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb
wanted_spec.samples = FFMAX(SDL_AUDIO_MIN_BUFFER_SIZE, 2 << av_log2(wanted_spec.freq / SDL_AUDIO_MAX_CALLBACKS_PER_SEC)); wanted_spec.samples = FFMAX(SDL_AUDIO_MIN_BUFFER_SIZE, 2 << av_log2(wanted_spec.freq / SDL_AUDIO_MAX_CALLBACKS_PER_SEC));
wanted_spec.callback = sdl_audio_callback; wanted_spec.callback = sdl_audio_callback;
wanted_spec.userdata = opaque; wanted_spec.userdata = opaque;
while (SDL_OpenAudio(&wanted_spec, &spec) < 0) { while (!(audio_dev = SDL_OpenAudioDevice(NULL, 0, &wanted_spec, &spec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_CHANNELS_CHANGE))) {
av_log(NULL, AV_LOG_WARNING, "SDL_OpenAudio (%d channels, %d Hz): %s\n", av_log(NULL, AV_LOG_WARNING, "SDL_OpenAudio (%d channels, %d Hz): %s\n",
wanted_spec.channels, wanted_spec.freq, SDL_GetError()); wanted_spec.channels, wanted_spec.freq, SDL_GetError());
wanted_spec.channels = next_nb_channels[FFMIN(7, wanted_spec.channels)]; wanted_spec.channels = next_nb_channels[FFMIN(7, wanted_spec.channels)];
...@@ -2659,7 +2660,7 @@ static int stream_component_open(VideoState *is, int stream_index) ...@@ -2659,7 +2660,7 @@ static int stream_component_open(VideoState *is, int stream_index)
} }
if ((ret = decoder_start(&is->auddec, audio_thread, is)) < 0) if ((ret = decoder_start(&is->auddec, audio_thread, is)) < 0)
goto out; goto out;
SDL_PauseAudio(0); SDL_PauseAudioDevice(audio_dev, 0);
break; break;
case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_VIDEO:
is->video_stream = stream_index; is->video_stream = stream_index;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment