diff options
author | iovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a> | 2007-01-29 05:49:07 +0000 |
---|---|---|
committer | iovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a> | 2007-01-29 05:49:07 +0000 |
commit | 46028c7ea0c7cd37d6c5e6c6196978afc950dce4 (patch) | |
tree | 94943bfa739d6611e17584383f84f72ec832b021 /recordmydesktop/src | |
parent | c1a890715d4791b75b9512c1d9b02cb691c5de39 (diff) |
Added support for compilation with OSS, instead of ALSA.
git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@267 f606c939-3180-4ac9-a4b8-4b8779d57d0a
Diffstat (limited to 'recordmydesktop/src')
-rw-r--r-- | recordmydesktop/src/cache_audio.c | 11 | ||||
-rw-r--r-- | recordmydesktop/src/capture_sound.c | 44 | ||||
-rw-r--r-- | recordmydesktop/src/encode_sound_buffer.c | 9 | ||||
-rw-r--r-- | recordmydesktop/src/initialize_data.c | 9 | ||||
-rw-r--r-- | recordmydesktop/src/load_cache.c | 14 | ||||
-rw-r--r-- | recordmydesktop/src/opendev.c | 47 | ||||
-rw-r--r-- | recordmydesktop/src/parseargs.c | 4 |
7 files changed, 129 insertions, 9 deletions
diff --git a/recordmydesktop/src/cache_audio.c b/recordmydesktop/src/cache_audio.c index c8a71da..178bb7c 100644 --- a/recordmydesktop/src/cache_audio.c +++ b/recordmydesktop/src/cache_audio.c @@ -30,8 +30,10 @@ void *CacheSoundBuffer(ProgData *pdata){ //It's sound is tiny compared to that of image, so //compressing would reducethe overall size by only an //insignificant fraction. +#ifdef HAVE_LIBASOUND int framesize=((snd_pcm_format_width(SND_PCM_FORMAT_S16_LE))/8)* pdata->args.channels; +#endif pthread_mutex_t smut; pthread_mutex_init(&smut,NULL); while((pdata->running)){ @@ -55,10 +57,13 @@ void *CacheSoundBuffer(ProgData *pdata){ //advance the list pdata->sound_buffer=pdata->sound_buffer->next; pthread_mutex_unlock(&pdata->sound_buffer_mutex); - - fwrite(buff->data,pdata->periodsize*framesize,1, +#ifdef HAVE_LIBASOUND + fwrite(buff->data,1,pdata->periodsize*framesize, pdata->cache_data->afp); - +#else + fwrite(buff->data,1,pdata->args.buffsize, + pdata->cache_data->afp); +#endif pdata->avd-=pdata->periodtime; diff --git a/recordmydesktop/src/capture_sound.c b/recordmydesktop/src/capture_sound.c index 32f2638..d9bb340 100644 --- a/recordmydesktop/src/capture_sound.c +++ b/recordmydesktop/src/capture_sound.c @@ -29,9 +29,11 @@ void *CaptureSound(ProgData *pdata){ +#ifdef HAVE_LIBASOUND int frames=pdata->periodsize; int framesize=((snd_pcm_format_width(SND_PCM_FORMAT_S16_LE))/8)* pdata->args.channels; +#endif pthread_mutex_t pmut; pthread_mutex_init(&pmut,NULL); @@ -42,6 +44,7 @@ void *CaptureSound(ProgData *pdata){ int sret=0; SndBuffer *newbuf,*tmp; if(Paused){ +#ifdef HAVE_LIBASOUND if(!pdata->hard_pause){ snd_pcm_pause(pdata->sound_handle,1); pthread_cond_wait(&pdata->pause_cond,&pmut); @@ -68,14 +71,33 @@ void *CaptureSound(ProgData *pdata){ pthread_exit(&errno); } } +#else + close(pdata->sound_handle); + pthread_cond_wait(&pdata->pause_cond,&pmut); + pdata->sound_handle= + OpenDev(pdata->args.device, + pdata->args.channels, + pdata->args.frequency); + if(pdata->sound_handle<0){ + fprintf(stderr,"Couldn't reopen sound device.Exiting\n"); + pdata->running=0; + errno=3; + pthread_exit(&errno); + } +#endif } //create new buffer newbuf=(SndBuffer *)malloc(sizeof(SndBuffer *)); +#ifdef HAVE_LIBASOUND newbuf->data=(signed char *)malloc(frames*framesize); +#else + newbuf->data=(signed char *)malloc(pdata->args.buffsize); +#endif newbuf->next=NULL; //read data into new buffer +#ifdef HAVE_LIBASOUND while(sret<frames){ int temp_sret=snd_pcm_readi(pdata->sound_handle, newbuf->data+framesize*sret, @@ -94,7 +116,23 @@ void *CaptureSound(ProgData *pdata){ else sret+=temp_sret; } - +#else + sret=0; + //oss recording loop + do{ + int temp_sret=read(pdata->sound_handle, + &newbuf->data[sret], + pdata->args.buffsize); + if(temp_sret<0){ + fprintf(stderr,"An error occured while reading from soundcard" + "%s\n" + "Error description:\n" + "%s\n",pdata->args.device,strerror(errno)); + } + else + sret+=temp_sret; + }while(sret<pdata->args.buffsize); +#endif //queue the new buffer pthread_mutex_lock(&pdata->sound_buffer_mutex); tmp=pdata->sound_buffer; @@ -111,7 +149,11 @@ void *CaptureSound(ProgData *pdata){ //signal that there are data to be proccessed pthread_cond_signal(&pdata->sound_data_read); } +#ifdef HAVE_LIBASOUND snd_pcm_close(pdata->sound_handle); +#else + close(pdata->sound_handle); +#endif pthread_exit(&errno); } diff --git a/recordmydesktop/src/encode_sound_buffer.c b/recordmydesktop/src/encode_sound_buffer.c index 828855c..2ea76cc 100644 --- a/recordmydesktop/src/encode_sound_buffer.c +++ b/recordmydesktop/src/encode_sound_buffer.c @@ -28,8 +28,11 @@ #include <recordmydesktop.h> void *EncodeSoundBuffer(ProgData *pdata){ - +#ifdef HAVE_LIBASOUND int sampread=pdata->periodsize; +#else + int sampread=pdata->args.buffsize>>1; +#endif pthread_mutex_t smut; pthread_mutex_init(&smut,NULL); pdata->v_encoding_clean=0; @@ -97,7 +100,11 @@ void *EncodeSoundBuffer(ProgData *pdata){ void SyncEncodeSoundBuffer(ProgData *pdata,signed char *buff){ float **vorbis_buffer; int count=0,i,j; +#ifdef HAVE_LIBASOUND int sampread=(buff!=NULL)?pdata->periodsize:0; +#else + int sampread=(buff!=NULL)?(pdata->args.buffsize>>1):0; +#endif vorbis_buffer=vorbis_analysis_buffer(&pdata->enc_data->m_vo_dsp,sampread); for(i=0;i<sampread;i++){ for(j=0;j<pdata->args.channels;j++){ diff --git a/recordmydesktop/src/initialize_data.c b/recordmydesktop/src/initialize_data.c index 4830c83..8d86856 100644 --- a/recordmydesktop/src/initialize_data.c +++ b/recordmydesktop/src/initialize_data.c @@ -119,6 +119,7 @@ int InitializeData(ProgData *pdata, AllPlanes); } if(!pdata->args.nosound){ +#ifdef HAVE_LIBASOUND pdata->sound_handle=OpenDev( pdata->args.device, &pdata->args.channels, &pdata->args.frequency, @@ -127,6 +128,14 @@ int InitializeData(ProgData *pdata, &pdata->periodtime, &pdata->hard_pause); if(pdata->sound_handle==NULL){ +#else + pdata->sound_handle=OpenDev(pdata->args.device, + pdata->args.channels, + pdata->args.frequency); + pdata->periodtime=(1000000*pdata->args.buffsize)/ + ((pdata->args.channels<<1)*pdata->args.frequency); + if(pdata->sound_handle<0){ +#endif fprintf(stderr,"Error while opening/configuring soundcard %s\n" "Try running with the --no-sound or specify a " "correct device.\n", diff --git a/recordmydesktop/src/load_cache.c b/recordmydesktop/src/load_cache.c index 6098bc7..a5b1581 100644 --- a/recordmydesktop/src/load_cache.c +++ b/recordmydesktop/src/load_cache.c @@ -131,10 +131,14 @@ void *LoadCache(ProgData *pdata){ blocknum_x=pdata->enc_data->yuv.y_width/Y_UNIT_WIDTH, blocknum_y=pdata->enc_data->yuv.y_height/Y_UNIT_WIDTH, blockszy=Y_UNIT_BYTES,//size of y plane block in bytes - blockszuv=UV_UNIT_BYTES,//size of u,v plane blocks in bytes - framesize=((snd_pcm_format_width(SND_PCM_FORMAT_S16_LE))/8)* + blockszuv=UV_UNIT_BYTES;//size of u,v plane blocks in bytes +#ifdef HAVE_LIBASOUND + int framesize=((snd_pcm_format_width(SND_PCM_FORMAT_S16_LE))/8)* pdata->args.channels;//audio frame size signed char *sound_data=(signed char *)malloc(pdata->periodsize*framesize); +#else + signed char *sound_data=(signed char *)malloc(pdata->args.buffsize); +#endif u_int32_t YBlocks[(yuv->y_width*yuv->y_height)/Y_UNIT_BYTES], UBlocks[(yuv->uv_width*yuv->uv_height)/UV_UNIT_BYTES], VBlocks[(yuv->uv_width*yuv->uv_height)/UV_UNIT_BYTES]; @@ -250,7 +254,11 @@ void *LoadCache(ProgData *pdata){ //audio load and encoding else{ if(!audio_end){ - int nbytes=fread(sound_data,pdata->periodsize*framesize,1,afp); +#ifdef HAVE_LIBASOUND + int nbytes=fread(sound_data,1,pdata->periodsize*framesize,afp); +#else + int nbytes=fread(sound_data,1,pdata->args.buffsize,afp); +#endif if(nbytes<=0) audio_end=1; else diff --git a/recordmydesktop/src/opendev.c b/recordmydesktop/src/opendev.c index 5fc24f7..7810ec6 100644 --- a/recordmydesktop/src/opendev.c +++ b/recordmydesktop/src/opendev.c @@ -29,6 +29,7 @@ #include <recordmydesktop.h> +#ifdef HAVE_LIBASOUND snd_pcm_t *OpenDev( const char *pcm_dev, unsigned int *channels, @@ -114,4 +115,50 @@ snd_pcm_t *OpenDev( const char *pcm_dev, return mhandle; } +#else +int OpenDev( const char *pcm_dev, + unsigned int channels, + unsigned int frequency){ + int fd ; + fd=open(pcm_dev,O_RDONLY); + + if(fd!=-1){ + unsigned int value; + + if(ioctl(fd,SNDCTL_DSP_GETFMTS,&value)<0){ + fprintf(stderr,"Couldn't get audio format list\n"); + return -1; + } + if(value & AFMT_S16_LE){ + value=AFMT_S16_LE; + } + else if(value & AFMT_S16_BE){ + value=AFMT_S16_BE; + } + else{ + fprintf(stderr,"Soundcard doesn't support signed 16-bit-data\n"); + return -1; + } + if(ioctl(fd,SNDCTL_DSP_SETFMT,&value)<0){ + fprintf(stderr,"Couldn't set audio format\n" ); + return -1; + } + value = channels; + if(ioctl(fd,SNDCTL_DSP_CHANNELS,&value)<0){ + fprintf(stderr,"Cannot set the number of channels\n" ); + return -1; + } + value = frequency; + if(ioctl(fd,SNDCTL_DSP_SPEED,&value)<0){ + fprintf(stderr,"Couldn't set audio frequency\n" ); + return -1; + } + if(fcntl(fd,F_SETFL,fcntl(fd,F_GETFL) & ~O_NONBLOCK)<0){ + fprintf(stderr,"Couldn't set audio blocking mode\n" ); + return -1; + } + } + return fd; +} +#endif diff --git a/recordmydesktop/src/parseargs.c b/recordmydesktop/src/parseargs.c index 36dbbea..9cda42b 100644 --- a/recordmydesktop/src/parseargs.c +++ b/recordmydesktop/src/parseargs.c @@ -81,7 +81,9 @@ int ParseArgs(int argc,char **argv,ProgArgs *arg_return){ "\t-buffer-size N\t\tA positive number denoting the desired" " sound buffer size(in frames)\n" - "\t-device SOUND_DEVICE\tSound device(default hw0:0).\n" + "\t-device SOUND_DEVICE\tSound device(default " + DEFAULT_AUDIO_DEVICE + ").\n" "\t--no-sound\t\tDo not record sound.\n\n" "Encoding Options\n" |