void MMS_Audio_Init() { MMRESULT status; LPWAVEOUTCAPS lpCaps; if( waveOutGetNumDevs() < 1 ) { fprintf(stderr,"Audio disabled - No Multimedia Services compatible audio devices available\n"); return; } /* Figure out device capabilities - Just use device 0 for now */ if((lpCaps = (LPWAVEOUTCAPS)mmeAllocMem(sizeof(WAVEOUTCAPS))) == NULL ) { fprintf(stderr,"Failed to allocate WAVEOUTCAPS struct\n"); return; } status = waveOutGetDevCaps( 0, lpCaps, sizeof(WAVEOUTCAPS)); if( status != MMSYSERR_NOERROR ) { fprintf(stderr,"waveOutGetDevCaps failed - status = %d\n", status); } mmeFreeMem(lpCaps); }
static void MME_CloseDevice(_THIS) { if (this->hidden != NULL) { MMRESULT result; if (this->hidden->mixbuf) { result = mmeFreeBuffer(this->hidden->mixbuf); if (result != MMSYSERR_NOERROR) SetMMerror("mmeFreeBuffer", result); this->hidden->mixbuf = NULL; } if (this->hidden->shm) { if (this->hidden->shm->sound) { result = waveOutClose(this->hidden->shm->sound); if (result != MMSYSERR_NOERROR) SetMMerror("waveOutClose()", result); mmeProcessCallbacks(); } result = mmeFreeMem(this->hidden->shm); if (result != MMSYSERR_NOERROR) SetMMerror("mmeFreeMem()", result); this->hidden->shm = NULL; } SDL_free(this->hidden); this->hidden = NULL; } }
void close_sound(void) { if (have_sound) { mmeFreeMem(WaveHeader); mmeFreeBuffer(mme_audiobuf); waveOutClose(mme_handle); } mme_handle=0; }
MmeGrabber::~MmeGrabber() { /* fprintf(stderr, "vic: Called MmeGrabber::~MmeGrabber\n"); */ if (valid_) { if (running_) stop(); mmeFreeMem(vh_); videoClose(handle_); } }
inline int MmeGrabber::mme_error(MMRESULT code, const char* msg) const { if (code != DV_ERR_OK) { char *buffer; if(buffer=(char *)mmeAllocMem(MAXERRORLENGTH)) { videoGetErrorText(handle_,code,buffer,MAXERRORLENGTH); fprintf(stderr, "vic: %s - %s (%d)\n", msg, buffer, code); mmeFreeMem(buffer); } return (1); } return (0); }
void MmeGrabber::init() { int size; MMRESULT s; /* fprintf(stderr, "vic: Called MmeGrabber::init\n"); */ /* * Allocate & zero some memory for the video header and bitmap * info header. We allocate it as a single block to keep it * all in one shared memory segment. * (Make sure everything's aligned on quadword boundaries) */ size = ((sizeof(*bmh)+sizeof(void*)-1) / sizeof(void*)) * sizeof(void*); bmh = (info*)mmeAllocMem(size+sizeof(*vh_)); if (bmh == 0) { fprintf(stderr, "vic: cannot allocate mme memory\n"); valid_ = 0; return; } memset(bmh, 0, size+sizeof(*vh_)); vh_ = (VIDEOHDR*)((char*)bmh+size); if (server_ < 0) { server_ = mmeServerFileDescriptor(); link(server_, TK_READABLE); } return; bail: mmeFreeMem(bmh); bmh = 0; videoClose(handle_); vh_ = 0; valid_ = 0; /*XXX*/ }
static void MME_CloseAudio(_THIS) { MMRESULT result; if ( mixbuf ) { result = mmeFreeBuffer(mixbuf); if (result != MMSYSERR_NOERROR ) SetMMerror("mmeFreeBuffer", result); mixbuf = NULL; } if ( shm ) { if ( shm->sound ) { result = waveOutClose(shm->sound); if (result != MMSYSERR_NOERROR ) SetMMerror("waveOutClose()", result); mmeProcessCallbacks(); } result = mmeFreeMem(shm); if (result != MMSYSERR_NOERROR ) SetMMerror("mmeFreeMem()", result); shm = NULL; } }
void MmeGrabber::startup() { MMRESULT s; int size; /* fprintf(stderr, "vic: Called MmeGrabber::startup\n"); */ if (running_) return; if(port_) { s=videoSetPortNum(handle_,port_); if (mme_error(s, "couldn't configure mme")) goto bail; } if(standard_) { s=videoSetStandard(handle_,standard_); if (mme_error(s, "couldn't configure mme")) goto bail; } s = videoConfigure(handle_, DVM_FORMAT, VIDEO_CONFIGURE_GET|VIDEO_CONFIGURE_MIN, 0, bmh, sizeof(*bmh), 0, 0); size = bmh->b.bmi.biSizeImage;/*XXX ridiculously large*/ s = videoConfigure(handle_, DVM_FORMAT, VIDEO_CONFIGURE_SET, 0, bmh, sizeof(*bmh), 0, 0); if (mme_error(s, "couldn't configure mme")) goto bail; #ifdef notdef size = 320 * 240 * 3; #endif vh_->lpData = (LPSTR)mmeAllocBuffer(size); if (vh_->lpData == 0) { fprintf(stderr, "vic: couldn't allocate mme frame memory\n"); goto bail; } vh_->dwBufferLength = size; s = videoStreamInit(handle_, 1000000 /*10fps - ignored */, mme_callback, 0, CALLBACK_FUNCTION); if (mme_error(s, "couldn't initialize mme stream\n")) return; s = videoStreamPrepareHeader(handle_, vh_, sizeof(*vh_)); if (mme_error(s, "couldn't prepare mme video hdr")) return; s = videoStreamStart(handle_); if (mme_error(s, "couldn't start mme video stream\n")) return; running_ = 1; frameclock_ = gettimeofday_usecs(); outstanding_ = 0; last_grab_ = 0; grab(); return; bail: mmeFreeMem(bmh); bmh = 0; videoClose(handle_); vh_ = 0; valid_ = 0; }
int init_sound (void) { int rate; int dspbits; int channels; MMRESULT status; LPPCMWAVEFORMAT waveformat; if (currprefs.sound_maxbsiz < 128 || currprefs.sound_maxbsiz > 16384) { fprintf(stderr, "Sound buffer size %d out of range.\n", currprefs.sound_maxbsiz); currprefs.sound_maxbsiz = 8192; } sndbufsize = currprefs.sound_maxbsiz; dspbits = currprefs.sound_bits; rate = currprefs.sound_freq; channels = 1; if((waveformat = (LPPCMWAVEFORMAT) mmeAllocMem(sizeof(PCMWAVEFORMAT))) == NULL ) { fprintf(stderr, "Failed to allocate PCMWAVEFORMAT struct\n"); return 0; } waveformat->wf.nSamplesPerSec = rate; waveformat->wf.nChannels = channels; waveformat->wBitsPerSample = dspbits; waveformat->wf.wFormatTag = WAVE_FORMAT_PCM; bytes_per_sample = waveformat->wf.nChannels * (waveformat->wBitsPerSample/8); waveformat->wf.nBlockAlign = bytes_per_sample; waveformat->wf.nAvgBytesPerSec = bytes_per_sample * waveformat->wf.nSamplesPerSec; /* Open the audio device with desired rate/format */ status = waveOutOpen( &mme_handle, WAVE_MAPPER, (LPWAVEFORMAT)waveformat, (void (*)())mme_callback, (unsigned int)NULL, CALLBACK_FUNCTION | WAVE_OPEN_SHAREABLE ); mmeFreeMem(waveformat); if(status != MMSYSERR_NOERROR) { fprintf(stderr, "waveOutOpen failed - status = %d\n", status); return 0; } /* Allocate wave header for use in write */ if((WaveHeader = (LPWAVEHDR) mmeAllocMem(sizeof(WAVEHDR))) == NULL ) { fprintf(stderr, "Failed to allocate WAVEHDR struct\n"); return 0; } /* Allocate shared audio buffer for communicating with audio device */ if ((mme_audiobuf = (LPSTR) mmeAllocBuffer(sndbufsize*SOUND_NUMBUF*bytes_per_sample*2)) == NULL) { fprintf(stderr, "Failed to allocate shared audio buffer\n"); mmeFreeMem(WaveHeader); return 0; } sndbuffer = mme_audiobuf; obtained_freq = rate; if (dspbits == 16) { init_sound_table16 (); sample_handler = sample16_handler; } else { init_sound_table8 (); sample_handler = sample8_handler; } sound_available = 1; printf ("Sound driver found and configured for %d bits at %d Hz, buffer is %d bytes\n", dspbits, rate, sndbufsize); mme_sndbufpt = sndbufpt = sndbuffer; return 1; }