static SDL_Window *window;
static SDL_Renderer *renderer;
+static SDL_RendererInfo renderer_info = {0};
+static SDL_AudioDeviceID audio_dev;
static const struct TextureFormatEntry {
enum AVPixelFormat format;
switch (codecpar->codec_type) {
case AVMEDIA_TYPE_AUDIO:
decoder_abort(&is->auddec, &is->sampq);
- SDL_CloseAudio();
+ SDL_CloseAudioDevice(audio_dev);
decoder_destroy(&is->auddec);
swr_free(&is->swr_ctx);
av_freep(&is->audio_buf1);
h = default_height;
}
- if (!window) {
- int flags = SDL_WINDOW_SHOWN;
- if (!window_title)
- window_title = input_filename;
- if (is_full_screen)
- flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
- if (borderless)
- flags |= SDL_WINDOW_BORDERLESS;
- else
- flags |= SDL_WINDOW_RESIZABLE;
- window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, flags);
- SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
- if (window) {
- SDL_RendererInfo info;
- renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
- if (!renderer) {
- av_log(NULL, AV_LOG_WARNING, "Failed to initialize a hardware accelerated renderer: %s\n", SDL_GetError());
- renderer = SDL_CreateRenderer(window, -1, 0);
- }
- if (renderer) {
- if (!SDL_GetRendererInfo(renderer, &info))
- av_log(NULL, AV_LOG_VERBOSE, "Initialized %s renderer.\n", info.name);
- }
- }
- } else {
- SDL_SetWindowSize(window, w, h);
- }
+ if (!window_title)
+ window_title = input_filename;
+ SDL_SetWindowTitle(window, window_title);
- if (!window || !renderer) {
- av_log(NULL, AV_LOG_FATAL, "SDL: could not set video mode - exiting\n");
- do_exit(is);
- }
+ SDL_SetWindowSize(window, w, h);
+ SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
+ if (is_full_screen)
+ SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
+ SDL_ShowWindow(window);
is->width = w;
is->height = h;
/* display the current picture, if any */
static void video_display(VideoState *is)
{
- if (!window)
+ if (!is->width)
video_open(is);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
AVCodecParameters *codecpar = is->video_st->codecpar;
AVRational fr = av_guess_frame_rate(is->ic, is->video_st, NULL);
AVDictionaryEntry *e = NULL;
- int i;
+ int nb_pix_fmts = 0;
+ int i, j;
- for (i = 0; i < FF_ARRAY_ELEMS(pix_fmts); i++)
- pix_fmts[i] = sdl_texture_format_map[i].format;
+ for (i = 0; i < renderer_info.num_texture_formats; i++) {
+ for (j = 0; j < FF_ARRAY_ELEMS(sdl_texture_format_map) - 1; j++) {
+ if (renderer_info.texture_formats[i] == sdl_texture_format_map[j].texture_fmt) {
+ pix_fmts[nb_pix_fmts++] = sdl_texture_format_map[j].format;
+ break;
+ }
+ }
+ }
+ pix_fmts[nb_pix_fmts] = AV_PIX_FMT_NONE;
while ((e = av_dict_get(sws_dict, "", e, AV_DICT_IGNORE_SUFFIX))) {
if (!strcmp(e->key, "sws_flags")) {
else {
memset(stream, 0, len1);
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;
stream += len1;
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.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",
wanted_spec.channels, wanted_spec.freq, SDL_GetError());
wanted_spec.channels = next_nb_channels[FFMIN(7, wanted_spec.channels)];
}
if ((ret = decoder_start(&is->auddec, audio_thread, is)) < 0)
goto out;
- SDL_PauseAudio(0);
+ SDL_PauseAudioDevice(audio_dev, 0);
break;
case AVMEDIA_TYPE_VIDEO:
is->video_stream = stream_index;
av_init_packet(&flush_pkt);
flush_pkt.data = (uint8_t *)&flush_pkt;
+ if (!display_disable) {
+ int flags = SDL_WINDOW_HIDDEN;
+ if (borderless)
+ flags |= SDL_WINDOW_BORDERLESS;
+ else
+ flags |= SDL_WINDOW_RESIZABLE;
+ window = SDL_CreateWindow(program_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, default_width, default_height, flags);
+ SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
+ if (window) {
+ renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
+ if (!renderer) {
+ av_log(NULL, AV_LOG_WARNING, "Failed to initialize a hardware accelerated renderer: %s\n", SDL_GetError());
+ renderer = SDL_CreateRenderer(window, -1, 0);
+ }
+ if (renderer) {
+ if (!SDL_GetRendererInfo(renderer, &renderer_info))
+ av_log(NULL, AV_LOG_VERBOSE, "Initialized %s renderer.\n", renderer_info.name);
+ }
+ }
+ if (!window || !renderer || !renderer_info.num_texture_formats) {
+ av_log(NULL, AV_LOG_FATAL, "Failed to create window or renderer: %s", SDL_GetError());
+ do_exit(NULL);
+ }
+ }
+
is = stream_open(input_filename, file_iformat);
if (!is) {
av_log(NULL, AV_LOG_FATAL, "Failed to initialize VideoState!\n");