int ossPrimitiveFileOp::Open(const char *pFilePath, unsigned int options) { int rc = 0; int mode = O_RDWR; if (options & OSS_PRIMITIVE_FILE_OP_READ_ONLY) { mode = O_RDONLY; } else if (options & OSS_PRIMITIVE_FILE_OP_WRITE_ONLY) { mode = O_WRONLY; } if (options & OSS_PRIMITIVE_FILE_OP_OPEN_EXISTING) { } else if (options & OSS_PRIMITIVE_FILE_OP_OPEN_ALWAYS) { mode |= O_CREAT; } if (options & OSS_PRIMITIVE_FILE_OP_OPEN_TRUNC) { mode |= O_TRUNC; } do { _fileHandle = oss_open(pFilePath, mode, 0644); } while((-1 == _fileHandle) && (EINTR == errno)); if (_fileHandle <= OSS_INVALID_HANDLE_FD_VALUE) { rc = errno; goto error; } error: return rc; }
static RD_BOOL oss_open_in(void) { if (!oss_open(O_RDONLY)) return False; return True; }
static RD_BOOL oss_open_out(void) { if (!oss_open(O_WRONLY)) return False; return True; }
static void oss_close_in(void) { oss_close(); if (dsp_mode == O_RDWR) { if (oss_open(O_WRONLY)) oss_restore_format(); } }
static void oss_close_out(void) { oss_close(); if (dsp_mode == O_RDWR) { if (oss_open(O_RDONLY)) oss_restore_format(); } /* Ack all remaining packets */ while (!rdpsnd_queue_empty()) rdpsnd_queue_next(0); }
int svc_init_audio(unsigned int rate, unsigned int frame_size) { input_audio_data = svc_audio_data_create(frame_size); output_audio_data = svc_audio_data_create(frame_size); oss_open(rate); fs = frame_size; running = 1; thread_create(&rt, reader, NULL); thread_detach(rt); assert(rt > 0); return 0; }
/* "Public" function, called from a libspotify callback */ G_MODULE_EXPORT int audio_delivery(const sp_audioformat* format, const void* frames, int num_frames) { int ret; g_mutex_lock(&g_oss_mutex); /* What are we supposed to do here? */ if (num_frames == 0) { /* Pause: close the device */ if (g_oss_fd != -1) oss_close(); ret = 0; } else { if (g_oss_fd == -1) { /* Some frames to play, but the device is closed: open it and set it up */ oss_open(); oss_setup(format); } /* Is the device ready to be written to? */ ret = poll(&g_pfd, 1, 0); if (ret == -1) g_error("Can't poll OSS device: %s", g_strerror(errno)); else if (ret != 0) { /* Ok, we can write to the device without blocking */ ret = write(g_oss_fd, frames, g_oss_frame_size * num_frames); if (ret == -1) g_error("Can't write to OSS device: %s", g_strerror(errno)); ret /= g_oss_frame_size; } } g_mutex_unlock(&g_oss_mutex); return ret; }
static int oss_play_open(struct voss_backend *pbe, const char *devname, int samplerate, int bufsize, int *pchannels, int *pformat) { return (oss_open(pbe, devname, samplerate, bufsize, pchannels, pformat, O_WRONLY, 0)); }
static void * oss_thread(void *p){ MSSndCard *card=(MSSndCard*)p; OssData *d=(OssData*)card->data; int bsize=0; uint8_t *rtmpbuff=NULL; uint8_t *wtmpbuff=NULL; int err; mblk_t *rm=NULL; d->pcmfd=oss_open(d->pcmdev,d->bits,d->stereo,d->rate,&bsize); if (d->pcmfd>=0){ rtmpbuff=(uint8_t*)malloc(bsize); wtmpbuff=(uint8_t*)malloc(bsize); if(rtmpbuff == NULL || wtmpbuff == NULL) { free(rtmpbuff); free(wtmpbuff); return NULL; } } while(d->read_started || d->write_started){ if (d->pcmfd>=0){ if (d->read_started){ struct timeval timeout; fd_set read_fds; audio_buf_info info; if (rm==NULL) rm=allocb(bsize,0); timeout.tv_sec = 0; timeout.tv_usec = 0; FD_ZERO( &read_fds ); FD_SET( d->pcmfd, &read_fds ); if( select( d->pcmfd + 1, &read_fds, NULL, NULL, &timeout ) == -1 ) { } if (FD_ISSET( d->pcmfd, &read_fds ) && ioctl( d->pcmfd, SNDCTL_DSP_GETISPACE, &info ) != -1) { if (info.bytes>=bsize) { err=read(d->pcmfd,rm->b_wptr,bsize); if (err<0){ ms_warning("Fail to read %i bytes from soundcard: %s", bsize,strerror(errno)); }else{ rm->b_wptr+=err; ms_mutex_lock(&d->mutex); putq(&d->rq,rm); ms_mutex_unlock(&d->mutex); rm=NULL; } } else { timeout.tv_sec = 0; timeout.tv_usec = 5000; select(0, 0, NULL, NULL, &timeout ); } } else { timeout.tv_sec = 0; timeout.tv_usec = 5000; select(0, 0, NULL, NULL, &timeout ); } }else { int sz = read(d->pcmfd,rtmpbuff,bsize); if( sz!=bsize) ms_warning("sound device read returned %i !",sz); } if (d->write_started){ audio_buf_info info; if( ms_bufferizer_get_avail(d->bufferizer)>=bsize && ioctl( d->pcmfd, SNDCTL_DSP_GETOSPACE, &info ) == 0 ) { if( info.fragstotal - info.fragments > 15 ) { static int c=0; /* drop the fragment if the buffer starts to fill up */ /* we got too much data: I prefer to empty the incoming buffer */ while (ms_bufferizer_get_avail(d->bufferizer)>bsize*4){ ms_mutex_lock(&d->mutex); err=ms_bufferizer_read(d->bufferizer,wtmpbuff,bsize); err=ms_bufferizer_read(d->bufferizer,wtmpbuff,bsize); err=ms_bufferizer_read(d->bufferizer,wtmpbuff,bsize); err=ms_bufferizer_read(d->bufferizer,wtmpbuff,bsize); ms_mutex_unlock(&d->mutex); c=c+err*4; ms_warning("drop fragment when buffer gets too much data (%i - discarded:%i)", info.fragstotal - info.fragments, c); if (err==0) break; } }else { ms_mutex_lock(&d->mutex); err=ms_bufferizer_read(d->bufferizer,wtmpbuff,bsize); ms_mutex_unlock(&d->mutex); err=write(d->pcmfd,wtmpbuff,bsize); if (err<0){ ms_warning("Fail to write %i bytes from soundcard: %s", bsize,strerror(errno)); } } } }else { int sz; memset(wtmpbuff,0,bsize); sz = write(d->pcmfd,wtmpbuff,bsize); if( sz!=bsize) ms_warning("sound device write returned %i !",sz); } }else usleep(20000); } if (d->pcmfd>=0) { close(d->pcmfd); d->pcmfd=-1; } free(rtmpbuff); free(wtmpbuff); if (rm!=NULL) freemsg(rm); /*reset to default parameters */ //d->bits=16; //d->rate=8000; //d->stereo=FALSE; return NULL; }
static int oss_rec_open(struct voss_backend *pbe, const char *devname, int samplerate, int *pchannels, int *pformat) { return (oss_open(pbe, devname, samplerate, pchannels, pformat, O_RDONLY)); }
ao_instance_t * ao_oss6_open (void) { return oss_open (DCA_3F2R | DCA_LFE); }
ao_instance_t * ao_oss4_open (void) { return oss_open (DCA_2F2R); }
ao_instance_t * ao_ossdolby_open (void) { return oss_open (DCA_DOLBY); }
ao_instance_t * ao_oss_open (void) { return oss_open (DCA_STEREO); }