static int Audio_Available(void) { pa_sample_spec paspec; pa_simple *connection; int available; available = 0; if ( LoadPulseLibrary() < 0 ) { return available; } /* Connect with a dummy format. */ paspec.format = PA_SAMPLE_U8; paspec.rate = 11025; paspec.channels = 1; connection = SDL_NAME(pa_simple_new)( SDL_getenv("PASERVER"), /* server */ "Test stream", /* application name */ PA_STREAM_PLAYBACK, /* playback mode */ SDL_getenv("PADEVICE"), /* device on the server */ "Simple DirectMedia Layer", /* stream description */ &paspec, /* sample format spec */ NULL, /* channel map */ NULL, /* buffering attributes */ NULL /* error code */ ); if ( connection != NULL ) { available = 1; SDL_NAME(pa_simple_free)(connection); } UnloadPulseLibrary(); return(available); }
static int DGA_Available(void) { const char *display; Display *dpy; int available; /* The driver is available is available if the display is local and the DGA 2.0+ extension is available, and we can map mem. */ available = 0; display = NULL; if ( (strncmp(XDisplayName(display), ":", 1) == 0) || (strncmp(XDisplayName(display), "unix:", 5) == 0) ) { dpy = XOpenDisplay(display); if ( dpy ) { int events, errors, major, minor; if ( SDL_NAME(XDGAQueryExtension)(dpy, &events, &errors) && SDL_NAME(XDGAQueryVersion)(dpy, &major, &minor) ) { int screen; screen = DefaultScreen(dpy); if ( (major >= 2) && SDL_NAME(XDGAOpenFramebuffer)(dpy, screen) ) { available = 1; SDL_NAME(XDGACloseFramebuffer)(dpy, screen); } } XCloseDisplay(dpy); } } return(available); }
static int Audio_Available(void) { pa_sample_spec paspec; pa_simple *connection; int available; available = 0; if ( LoadPulseLibrary() < 0 ) { return available; } paspec.format = PA_SAMPLE_U8; paspec.rate = 11025; paspec.channels = 1; connection = SDL_NAME(pa_simple_new)( NULL, "Test stream", PA_STREAM_PLAYBACK, NULL, "Simple DirectMedia Layer", &paspec, NULL, NULL, NULL ); if ( connection != NULL ) { available = 1; SDL_NAME(pa_simple_free)(connection); } UnloadPulseLibrary(); return(available); }
static void ALSA_PlayAudio(_THIS) { int status; snd_pcm_uframes_t frames_left; const Uint8 *sample_buf = (const Uint8 *) mixbuf; const int frame_size = (((int) (this->spec.format & 0xFF)) / 8) * this->spec.channels; swizzle_alsa_channels(this); frames_left = ((snd_pcm_uframes_t) this->spec.samples); while ( frames_left > 0 && this->enabled ) { /* This works, but needs more testing before going live */ /*SDL_NAME(snd_pcm_wait)(pcm_handle, -1);*/ status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, frames_left); if ( status < 0 ) { if ( status == -EAGAIN ) { /* Apparently snd_pcm_recover() doesn't handle this case - does it assume snd_pcm_wait() above? */ SDL_Delay(1); continue; } status = SDL_NAME(snd_pcm_recover)(pcm_handle, status, 0); if ( status < 0 ) { /* Hmm, not much we can do - abort */ fprintf(stderr, "ALSA write failed (unrecoverable): %s\n", SDL_NAME(snd_strerror)(status)); this->enabled = 0; return; } continue; } sample_buf += status * frame_size; frames_left -= status; } }
static int ESD_Init(SDL_AudioDriverImpl * impl) { if (LoadESDLibrary() < 0) { return 0; } else { int connection = 0; /* Don't start ESD if it's not running */ SDL_setenv("ESD_NO_SPAWN", "1", 0); connection = SDL_NAME(esd_open_sound) (NULL); if (connection < 0) { UnloadESDLibrary(); SDL_SetError("ESD: esd_open_sound failed (no audio server?)"); return 0; } SDL_NAME(esd_close) (connection); } /* Set the function pointers */ impl->OpenDevice = ESD_OpenDevice; impl->PlayDevice = ESD_PlayDevice; impl->WaitDevice = ESD_WaitDevice; impl->GetDeviceBuf = ESD_GetDeviceBuf; impl->CloseDevice = ESD_CloseDevice; impl->Deinitialize = ESD_Deinitialize; impl->OnlyHasDefaultOutputDevice = 1; return 1; /* this audio target is available. */ }
static int ARTS_Suspend(void) { const Uint32 abortms = SDL_GetTicks() + 3000; while ( (!SDL_NAME(arts_suspended)()) && (SDL_GetTicks() < abortms) ) { if ( SDL_NAME(arts_suspend)() ) { break; } } return SDL_NAME(arts_suspended)(); }
static void PULSE_CloseAudio(_THIS) { if ( mixbuf != NULL ) { SDL_FreeAudioMem(mixbuf); mixbuf = NULL; } if ( stream != NULL ) { SDL_NAME(pa_simple_drain)(stream, NULL); SDL_NAME(pa_simple_free)(stream); stream = NULL; } }
static void ALSA_CloseAudio(_THIS) { if ( mixbuf != NULL ) { SDL_FreeAudioMem(mixbuf); mixbuf = NULL; } if ( pcm_handle ) { SDL_NAME(snd_pcm_drain)(pcm_handle); SDL_NAME(snd_pcm_close)(pcm_handle); pcm_handle = NULL; } }
static void ARTSC_CloseAudio(_THIS) { if ( mixbuf != NULL ) { SDL_FreeAudioMem(mixbuf); mixbuf = NULL; } if ( stream ) { SDL_NAME(arts_close_stream)(stream); stream = 0; } SDL_NAME(arts_free)(); }
static int DGA_DispatchEvent(_THIS) { int posted; SDL_NAME(XDGAEvent) xevent; XNextEvent(DGA_Display, (XEvent *)&xevent); posted = 0; xevent.type -= DGA_event_base; switch (xevent.type) { /* Mouse motion? */ case MotionNotify: { if ( SDL_VideoSurface ) { posted = SDL_PrivateMouseMotion(0, 1, xevent.xmotion.dx, xevent.xmotion.dy); } } break; /* Mouse button press? */ case ButtonPress: { posted = SDL_PrivateMouseButton(SDL_PRESSED, xevent.xbutton.button, 0, 0); } break; /* Mouse button release? */ case ButtonRelease: { posted = SDL_PrivateMouseButton(SDL_RELEASED, xevent.xbutton.button, 0, 0); } break; /* Key press or release? */ case KeyPress: case KeyRelease: { SDL_keysym keysym; XKeyEvent xkey; SDL_NAME(XDGAKeyEventToXKeyEvent)(&xevent.xkey, &xkey); posted = SDL_PrivateKeyboard((xevent.type == KeyPress), X11_TranslateKey(DGA_Display, &xkey, xkey.keycode, &keysym)); } break; } return(posted); }
static int X11_SetGammaNoLock(_THIS, float red, float green, float blue) { #if SDL_VIDEO_DRIVER_X11_VIDMODE if (use_vidmode >= 200) { SDL_NAME(XF86VidModeGamma) gamma; Bool succeeded; /* Clamp the gamma values */ if ( red < MIN_GAMMA ) { gamma.red = MIN_GAMMA; } else if ( red > MAX_GAMMA ) { gamma.red = MAX_GAMMA; } else { gamma.red = red; } if ( green < MIN_GAMMA ) { gamma.green = MIN_GAMMA; } else if ( green > MAX_GAMMA ) { gamma.green = MAX_GAMMA; } else { gamma.green = green; } if ( blue < MIN_GAMMA ) { gamma.blue = MIN_GAMMA; } else if ( blue > MAX_GAMMA ) { gamma.blue = MAX_GAMMA; } else { gamma.blue = blue; } if ( SDL_GetAppState() & SDL_APPACTIVE ) { succeeded = SDL_NAME(XF86VidModeSetGamma)(SDL_Display, SDL_Screen, &gamma); XSync(SDL_Display, False); } else { gamma_saved[0] = gamma.red; gamma_saved[1] = gamma.green; gamma_saved[2] = gamma.blue; succeeded = True; } if ( succeeded ) { ++gamma_changed; } return succeeded ? 0 : -1; } #endif SDL_SetError("Gamma correction not supported"); return -1; }
static void PULSE_WaitAudio(_THIS) { int size; while(1) { if (SDL_NAME(pa_context_get_state)(context) != PA_CONTEXT_READY || SDL_NAME(pa_stream_get_state)(stream) != PA_STREAM_READY || SDL_NAME(pa_mainloop_iterate)(mainloop, 1, NULL) < 0) { this->enabled = 0; return; } size = SDL_NAME(pa_stream_writable_size)(stream); if (size >= mixlen) return; } }
Bool SDL_NAME(XF86DGAGetVideoLL)( Display* dpy, int screen, int *offset, int *width, int *bank_size, int *ram_size ){ XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); xXF86DGAGetVideoLLReply rep; xXF86DGAGetVideoLLReq *req; XF86DGACheckExtension (dpy, info, False); LockDisplay(dpy); GetReq(XF86DGAGetVideoLL, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGAGetVideoLL; req->screen = screen; if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } *offset = /*(char *)*/rep.offset; *width = rep.width; *bank_size = rep.bank_size; *ram_size = rep.ram_size; UnlockDisplay(dpy); SyncHandle(); return True; }
Bool SDL_NAME(XF86DGAQueryVersion)( Display* dpy, int* majorVersion, int* minorVersion ){ return SDL_NAME(XDGAQueryVersion)(dpy, majorVersion, minorVersion); }
Bool SDL_NAME(XF86DGAQueryExtension) ( Display *dpy, int *event_basep, int *error_basep ){ return SDL_NAME(XDGAQueryExtension)(dpy, event_basep, error_basep); }
Bool SDL_NAME(XF86DGADirectVideo)( Display *dis, int screen, int enable ){ ScrPtr sp; MapPtr mp = NULL; if ((sp = FindScr(dis, screen))) mp = sp->map; if (enable & XF86DGADirectGraphics) { #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ && !defined(__EMX__) if (mp && mp->vaddr) mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ | PROT_WRITE); #endif } else { #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ && !defined(__EMX__) if (mp && mp->vaddr) mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ); #elif defined(Lynx) /* XXX this doesn't allow enable after disable */ smem_create(NULL, mp->vaddr, mp->size + mp->delta, SM_DETACH); smem_remove("XF86DGA"); #endif } SDL_NAME(XF86DGADirectVideoLL)(dis, screen, enable); return 1; }
Bool SDL_NAME(XF86DGAQueryDirectVideo)( Display *dpy, int screen, int *flags ){ XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); xXF86DGAQueryDirectVideoReply rep; xXF86DGAQueryDirectVideoReq *req; XF86DGACheckExtension (dpy, info, False); LockDisplay(dpy); GetReq(XF86DGAQueryDirectVideo, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGAQueryDirectVideo; req->screen = screen; if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } *flags = rep.flags; UnlockDisplay(dpy); SyncHandle(); return True; }
Bool SDL_NAME(XF86DGAGetViewPortSize)( Display* dpy, int screen, int *width, int *height ){ XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); xXF86DGAGetViewPortSizeReply rep; xXF86DGAGetViewPortSizeReq *req; XF86DGACheckExtension (dpy, info, False); LockDisplay(dpy); GetReq(XF86DGAGetViewPortSize, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGAGetViewPortSize; req->screen = screen; if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } *width = rep.width; *height = rep.height; UnlockDisplay(dpy); SyncHandle(); return True; }
static int X11_GetGammaNoLock(_THIS, float *red, float *green, float *blue) { #ifdef XFREE86_VMGAMMA if (use_vidmode >= 200) { SDL_NAME(XF86VidModeGamma) gamma; if (SDL_NAME(XF86VidModeGetGamma)(SDL_Display, SDL_Screen, &gamma)) { *red = gamma.red; *green = gamma.green; *blue = gamma.blue; return 0; } return -1; } #endif return -1; }
static int SDL_FS_Init(SDL_AudioDriverImpl * impl) { if (LoadFusionSoundLibrary() < 0) { return 0; } else { DirectResult ret; ret = SDL_NAME(FusionSoundInit) (NULL, NULL); if (ret) { UnloadFusionSoundLibrary(); SDL_SetError ("FusionSound: SDL_FS_init failed (FusionSoundInit: %d)", ret); return 0; } } /* Set the function pointers */ impl->OpenDevice = SDL_FS_OpenDevice; impl->PlayDevice = SDL_FS_PlayDevice; impl->WaitDevice = SDL_FS_WaitDevice; impl->GetDeviceBuf = SDL_FS_GetDeviceBuf; impl->CloseDevice = SDL_FS_CloseDevice; impl->WaitDone = SDL_FS_WaitDone; impl->Deinitialize = SDL_FS_Deinitialize; impl->OnlyHasDefaultOutputDevice = 1; return 1; /* this audio target is available. */ }
void X11_FreeYUVOverlay(_THIS, SDL_Overlay *overlay) { struct private_yuvhwdata *hwdata; hwdata = overlay->hwdata; if ( hwdata ) { SDL_NAME(XvUngrabPort)(GFX_Display, hwdata->port, CurrentTime); if ( hwdata->yuvshm.shmaddr ) { XShmDetach(GFX_Display, &hwdata->yuvshm); shmdt(hwdata->yuvshm.shmaddr); } if ( hwdata->image ) { XFree(hwdata->image); } free(hwdata); } if ( overlay->pitches ) { free(overlay->pitches); overlay->pitches = NULL; } if ( overlay->pixels ) { free(overlay->pixels); overlay->pixels = NULL; } #ifdef XFREE86_REFRESH_HACK X11_EnableAutoRefresh(this); #endif }
/* This whole function is a hack. :) */ static Uint32 get_video_size(_THIS) { /* This is a non-exported function from libXxf86dga.a */ extern unsigned char *SDL_NAME(XDGAGetMappedMemory)(int screen); FILE *proc; unsigned long mem; unsigned start, stop; char line[BUFSIZ]; Uint32 size; mem = (unsigned long)SDL_NAME(XDGAGetMappedMemory)(DGA_Screen); size = 0; proc = fopen("/proc/self/maps", "r"); if ( proc ) { while ( fgets(line, sizeof(line)-1, proc) ) { sscanf(line, "%x-%x", &start, &stop); if ( start == mem ) { size = (Uint32)((stop-start)/1024); break; } } fclose(proc); } return(size); }
Bool SDL_NAME(XF86DGAViewPortChanged)( Display *dpy, int screen, int n ){ XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); xXF86DGAViewPortChangedReply rep; xXF86DGAViewPortChangedReq *req; XF86DGACheckExtension (dpy, info, False); LockDisplay(dpy); GetReq(XF86DGAViewPortChanged, req); req->reqType = info->codes->major_opcode; req->dgaReqType = X_XF86DGAViewPortChanged; req->screen = screen; req->n = n; if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } UnlockDisplay(dpy); SyncHandle(); return rep.result; }
static int Audio_Available(void) { int connection; int available; available = 0; if ( LoadESDLibrary() < 0 ) { return available; } connection = SDL_NAME(esd_open_sound)(NULL); if ( connection >= 0 ) { available = 1; SDL_NAME(esd_close)(connection); } UnloadESDLibrary(); return(available); }
static void PULSE_PlayAudio(_THIS) { /* Write the audio data */ if ( SDL_NAME(pa_simple_write)(stream, mixbuf, mixlen, NULL) != 0 ) { this->enabled = 0; } }
static void ESD_CloseDevice(_THIS) { if (this->hidden->audio_fd >= 0) { SDL_NAME(esd_close) (this->hidden->audio_fd); } SDL_free(this->hidden->mixbuf); SDL_free(this->hidden); }
static int Audio_Available(void) { int available; int status; snd_pcm_t *handle; available = 0; if (LoadALSALibrary() < 0) { return available; } status = SDL_NAME(snd_pcm_open)(&handle, get_audio_device(2), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); if ( status >= 0 ) { available = 1; SDL_NAME(snd_pcm_close)(handle); } UnloadALSALibrary(); return(available); }
static void ESD_CloseAudio(_THIS) { if ( mixbuf != NULL ) { SDL_FreeAudioMem(mixbuf); mixbuf = NULL; } if ( audio_fd >= 0 ) { SDL_NAME(esd_close)(audio_fd); audio_fd = -1; } }
int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) { struct private_yuvhwdata *hwdata; hwdata = overlay->hwdata; SDL_NAME(XvShmPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC, hwdata->image, 0, 0, overlay->w, overlay->h, dstrect->x, dstrect->y, dstrect->w, dstrect->h, False); XSync(GFX_Display, False); return(0); }
static void PULSE_SetCaption(_THIS, const char *str) { SDL_free(this->hidden->caption); if ((str == NULL) || (*str == '\0')) { str = get_progname(); } this->hidden->caption = SDL_strdup(str); if (context != NULL) { SDL_NAME(pa_context_set_name)(context, this->hidden->caption, caption_set_complete, 0); } }