test/testdropfile.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 07 Jul 2019 09:10:56 -0700
changeset 12928 3c4a4b1077cd
parent 12925 c6c6e400a007
permissions -rw-r--r--
Fixed bug 4710 - audio/alsa: avoid configuring hardware parameters with only a single period

Anthony Pesch

The previous code first configured the period size using snd_pcm_hw_par-
ams_set_period_size_near. Then, it further narrowed the configuration
space by calling snd_pcm_hw_params_set_buffer_size_near using a buffer
size of 2 times the _requested_ period size in order to try and get a
configuration with only 2 periods. If the configured period size was
larger than the requested size, the second call could inadvertently
narrow the configuration space to contain only a single period.

Rather than fixing the call to snd_pcm_hw_params_set_buffer_size_near
to use a size of 2 times the configured period size, the code has been
changed to use snd_pcm_hw_params_set_periods_min in order to more
clearly explain the intent.
     1 /*
     2   Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
     3 
     4   This software is provided 'as-is', without any express or implied
     5   warranty.  In no event will the authors be held liable for any damages
     6   arising from the use of this software.
     7 
     8   Permission is granted to anyone to use this software for any purpose,
     9   including commercial applications, and to alter it and redistribute it
    10   freely.
    11 */
    12 
    13 #include <stdlib.h>
    14 #include <stdio.h>
    15 
    16 #include "SDL_test_common.h"
    17 
    18 static SDLTest_CommonState *state;
    19 
    20 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    21 static void
    22 quit(int rc)
    23 {
    24     SDLTest_CommonQuit(state);
    25     exit(rc);
    26 }
    27 
    28 int
    29 main(int argc, char *argv[])
    30 {
    31     int i, done;
    32     SDL_Event event;
    33 
    34     /* Enable standard application logging */
    35     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    36 
    37     /* Initialize test framework */
    38     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    39     if (!state) {
    40         return 1;
    41     }
    42 
    43     for (i = 1; i < argc;) {
    44         int consumed;
    45 
    46         consumed = SDLTest_CommonArg(state, i);
    47         /* needed voodoo to allow app to launch via OS X Finder */
    48         if (SDL_strncmp(argv[i], "-psn", 4)==0) {
    49             consumed = 1;
    50         }
    51         if (consumed == 0) {
    52             consumed = -1;
    53         }
    54         if (consumed < 0) {
    55             SDLTest_CommonLogUsage(state, argv[0], NULL);
    56             quit(1);
    57         }
    58         i += consumed;
    59     }
    60     if (!SDLTest_CommonInit(state)) {
    61         quit(2);
    62     }
    63 
    64     for (i = 0; i < state->num_windows; ++i) {
    65         SDL_Renderer *renderer = state->renderers[i];
    66         SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    67         SDL_RenderClear(renderer);
    68         SDL_RenderPresent(renderer);
    69     }
    70 
    71     SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
    72 
    73     /* Main render loop */
    74     done = 0;
    75     while (!done) {
    76         /* Check for events */
    77         while (SDL_PollEvent(&event)) {
    78             if (event.type == SDL_DROPBEGIN) {
    79                 SDL_Log("Drop beginning on window %u", (unsigned int) event.drop.windowID);
    80             } else if (event.type == SDL_DROPCOMPLETE) {
    81                 SDL_Log("Drop complete on window %u", (unsigned int) event.drop.windowID);
    82             } else if ((event.type == SDL_DROPFILE) || (event.type == SDL_DROPTEXT)) {
    83                 const char *typestr = (event.type == SDL_DROPFILE) ? "File" : "Text";
    84                 char *dropped_filedir = event.drop.file;
    85                 SDL_Log("%s dropped on window %u: %s", typestr, (unsigned int) event.drop.windowID, dropped_filedir);
    86                 /* Normally you'd have to do this, but this is freed in SDLTest_CommonEvent() */
    87                 /*SDL_free(dropped_filedir);*/
    88             }
    89 
    90             SDLTest_CommonEvent(state, &event, &done);
    91         }
    92     }
    93 
    94     quit(0);
    95     /* keep the compiler happy ... */
    96     return(0);
    97 }
    98 
    99 /* vi: set ts=4 sw=4 expandtab: */