test/testnativecocoa.m
author Sam Lantinga <slouken@libsdl.org>
Sun, 07 Jul 2019 09:10:56 -0700
changeset 12928 3c4a4b1077cd
parent 3057 089a77aebb7d
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 #include "testnative.h"
     3 
     4 #ifdef TEST_NATIVE_COCOA
     5 
     6 #include <Cocoa/Cocoa.h>
     7 
     8 static void *CreateWindowCocoa(int w, int h);
     9 static void DestroyWindowCocoa(void *window);
    10 
    11 NativeWindowFactory CocoaWindowFactory = {
    12     "cocoa",
    13     CreateWindowCocoa,
    14     DestroyWindowCocoa
    15 };
    16 
    17 static void *CreateWindowCocoa(int w, int h)
    18 {
    19     NSAutoreleasePool *pool;
    20     NSWindow *nswindow;
    21     NSRect rect;
    22     unsigned int style;
    23 
    24     pool = [[NSAutoreleasePool alloc] init];
    25 
    26     rect.origin.x = 0;
    27     rect.origin.y = 0;
    28     rect.size.width = w;
    29     rect.size.height = h;
    30     rect.origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - rect.origin.y - rect.size.height;
    31 
    32     style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
    33 
    34     nswindow = [[NSWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE];
    35     [nswindow makeKeyAndOrderFront:nil];
    36 
    37     [pool release];
    38 
    39     return nswindow;
    40 }
    41 
    42 static void DestroyWindowCocoa(void *window)
    43 {
    44     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    45     NSWindow *nswindow = (NSWindow *)window;
    46 
    47     [nswindow close];
    48     [pool release];
    49 }
    50 
    51 #endif