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 | |
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
-rw-r--r-- | recordmydesktop/INSTALL | 12 | ||||
-rw-r--r-- | recordmydesktop/configure.ac | 55 | ||||
-rw-r--r-- | recordmydesktop/doc/recordmydesktop.1 | 6 | ||||
-rw-r--r-- | recordmydesktop/include/rmdfunc.h | 22 | ||||
-rw-r--r-- | recordmydesktop/include/rmdmacro.h | 9 | ||||
-rw-r--r-- | recordmydesktop/include/rmdtypes.h | 17 | ||||
-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 |
13 files changed, 226 insertions, 33 deletions
diff --git a/recordmydesktop/INSTALL b/recordmydesktop/INSTALL index 14de910..227629f 100644 --- a/recordmydesktop/INSTALL +++ b/recordmydesktop/INSTALL @@ -20,7 +20,6 @@ If you got a release tarball, to compile the program you have to go through the You will need the development headers(i.e. packages ending with -dev or -devel depending on the distribution you use) for the following: -alsa (libasound) X libICE-dev libSM-dev @@ -31,6 +30,13 @@ libogg libvorbis libtheora +If you want to compile with ALSA support, you will also +need the libasound headers.If they are not found, OSS +will be used and you must have the sys/soundcard.h header. +To use OSS regardless of whether or not you have the ALSA +headers, you can use the --enable-oss switch during +configuration. + Last, you need the regular headers, plus the ones for pthreads @@ -40,8 +46,4 @@ Of the above, the most likely to be missing are probably those of libXdamage and but any recent linux distribution should offer an easy way to get them. -Compiling on *BSD or other *nix flavors is not going to work(because of the alsa dependency) -but it shouldn't be too much of a hassle to change that(at least by disabling sound capture). -Future versions might include support for OSS-based sound capture. -If you are interested in this please let me know. diff --git a/recordmydesktop/configure.ac b/recordmydesktop/configure.ac index 16cb218..4661b60 100644 --- a/recordmydesktop/configure.ac +++ b/recordmydesktop/configure.ac @@ -32,10 +32,17 @@ if test "x$x_includes" != "x" && test "x$x_includes" != xNONE ; then CFLAGS="-I$x_includes $CFLAGS"; fi - +AC_ARG_ENABLE(oss, + [ --enable-oss[=yes] compile with OSS(don't check for ALSA))], + [case "${enableval}" in + yes) oss=true ;; + no) oss=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-oss) ;; + esac],[oss=false]) AC_CHECK_HEADER([alsa/asoundlib.h]) -AC_CHECK_HEADERS([sys/time.h unistd.h vorbis/vorbisfile.h ]) +AC_CHECK_HEADER([sys/soundcard.h]) +AC_CHECK_HEADERS([sys/time.h unistd.h vorbis/vorbisfile.h fcntl.h]) @@ -52,16 +59,27 @@ AC_CHECK_LIB([SM],[SmcOpenConnection],,AC_MSG_ERROR([Can't find libSM]),) AC_CHECK_LIB([X11],[XOpenDisplay],,AC_MSG_ERROR([Can't find libX11]), -L$x_libraries $X_PRE_LIBS) AC_CHECK_LIB([Xext],[XShmQueryVersion],,AC_MSG_ERROR([Can't find libXext])) -AC_CHECK_LIB([Xfixes], [XFixesQueryExtension],,AC_MSG_ERROR([Can't find libXfixes])) -AC_CHECK_LIB([Xdamage], [XDamageQueryExtension],,AC_MSG_ERROR([Can't find libXdamage])) -AC_CHECK_LIB([vorbis],[vorbis_info_clear],,AC_MSG_ERROR([Can't find libvorbis])) -AC_CHECK_LIB([vorbisfile],[ov_open],,AC_MSG_ERROR([Can't find libvorbisfile]),-lvorbis) -AC_CHECK_LIB([vorbisenc],[vorbis_encode_init],,AC_MSG_ERROR([Can't find libvorbisenc]),-lvorbis) +AC_CHECK_LIB([Xfixes], [XFixesQueryExtension],, + AC_MSG_ERROR([Can't find libXfixes])) +AC_CHECK_LIB([Xdamage], [XDamageQueryExtension],, + AC_MSG_ERROR([Can't find libXdamage])) +AC_CHECK_LIB([vorbis],[vorbis_info_clear],, + AC_MSG_ERROR([Can't find libvorbis])) +AC_CHECK_LIB([vorbisfile],[ov_open],, + AC_MSG_ERROR([Can't find libvorbisfile]),-lvorbis) +AC_CHECK_LIB([vorbisenc],[vorbis_encode_init],, + AC_MSG_ERROR([Can't find libvorbisenc]),-lvorbis) AC_CHECK_LIB([ogg],[ogg_stream_init],,AC_MSG_ERROR([Can't find libogg])) -AC_CHECK_LIB([theora],[theora_encode_YUVin],,AC_MSG_ERROR([Can't find libtheora])) -AC_CHECK_LIB([pthread],[pthread_mutex_lock],,AC_MSG_ERROR([Can't find libpthread])) -AC_CHECK_LIB([asound],[snd_pcm_drain],,AC_MSG_ERROR([Can't find libasound])) - +AC_CHECK_LIB([theora],[theora_encode_YUVin],, + AC_MSG_ERROR([Can't find libtheora])) +AC_CHECK_LIB([pthread],[pthread_mutex_lock],, + AC_MSG_ERROR([Can't find libpthread])) +if test x$oss = xfalse; then + AC_CHECK_LIB([asound],[snd_pcm_drain],, + audio_backend="OSS") +else + audio_backend="OSS" +fi # Checks for typedefs, structures, and compiler characteristics. @@ -76,3 +94,18 @@ AC_CONFIG_FILES([Makefile doc/Makefile ]) AC_OUTPUT +echo "" +echo "" +echo "" +echo "" +echo "****************************************" +echo "" +if test x$audio_backend = xOSS; then + echo "Audio driver that will be used: OSS" +else + echo "Audio driver that will be used: ALSA" +fi +echo "" +echo "****************************************" +echo "" +echo "" diff --git a/recordmydesktop/doc/recordmydesktop.1 b/recordmydesktop/doc/recordmydesktop.1 index 1b0003c..bb1de6c 100644 --- a/recordmydesktop/doc/recordmydesktop.1 +++ b/recordmydesktop/doc/recordmydesktop.1 @@ -141,7 +141,7 @@ The following error codes indicate the nature of the error: .br 9 Cannot connect to Xserver. .br -10 Color depth is not 24bpp. +10 Color depth is not 32, 24 or 16bpp. .br 11 Improper window specification. .br @@ -262,12 +262,12 @@ Sound Options: .TP .B \-buffer\-size N(number>0) - A positive number denoting the desired sound buffer size(in frames). + A positive number denoting the desired sound buffer size(in frames for ALSA, bytes for OSS). .br .TP .B \-device SOUND_DEVICE - Sound device(default hw0:0). + Sound device(default hw0:0 or /dev/dsp, depending on whether ALSA or OSS is used). .br .TP .B diff --git a/recordmydesktop/include/rmdfunc.h b/recordmydesktop/include/rmdfunc.h index a4908d5..2f41c4d 100644 --- a/recordmydesktop/include/rmdfunc.h +++ b/recordmydesktop/include/rmdfunc.h @@ -283,9 +283,9 @@ void *CaptureSound(ProgData *pdata); * \param pdata ProgData struct containing all program data */ void *EncodeSoundBuffer(ProgData *pdata); - +#ifdef HAVE_LIBASOUND /** -* Try to open sound device, with the desired parameters, +* Try to open (alsa) sound device, with the desired parameters, * and place the obtained ones on their place * * \param pcm_dev name of the device @@ -314,6 +314,24 @@ snd_pcm_t *OpenDev( const char *pcm_dev, snd_pcm_uframes_t *periodsize, unsigned int *periodtime, int *hardpause); +#else +/** +* Try to open (OSS) sound device, with the desired parameters. +* +* +* \param pcm_dev name of the device +* +* \param channels desired number of channels +* +* \param frequency desired frequency +* +* +* \returns file descriptor of open device,-1 on failure +*/ +int OpenDev( const char *pcm_dev, + unsigned int channels, + unsigned int frequency); +#endif /** * Initialize theora,vorbis encoders, and their respective ogg streams. * diff --git a/recordmydesktop/include/rmdmacro.h b/recordmydesktop/include/rmdmacro.h index c14785f..1fe06a4 100644 --- a/recordmydesktop/include/rmdmacro.h +++ b/recordmydesktop/include/rmdmacro.h @@ -99,6 +99,11 @@ #define Y_UNIT_BYTES 0x0100 #define UV_UNIT_BYTES 0x0040 +#ifdef HAVE_LIBASOUND + #define DEFAULT_AUDIO_DEVICE "hw:0,0" +#else + #define DEFAULT_AUDIO_DEVICE "/dev/dsp" +#endif #define CLIP_EVENT_AREA(e,brwin,wgeom){\ if(((e)->area.x<=(brwin)->rgeom.x)&&((e)->area.y<=(brwin)->rgeom.y)&&\ @@ -208,8 +213,8 @@ (args)->shared_thres=75;\ (args)->have_dummy_cursor=0;\ (args)->xfixes_cursor=1;\ - (args)->device=(char *)malloc(8);\ - strcpy((args)->device,"hw:0,0");\ + (args)->device=(char *)malloc(strlen(DEFAULT_AUDIO_DEVICE)+1);\ + strcpy((args)->device,DEFAULT_AUDIO_DEVICE);\ (args)->fps=15;\ (args)->channels=1;\ (args)->frequency=22050;\ diff --git a/recordmydesktop/include/rmdtypes.h b/recordmydesktop/include/rmdtypes.h index 7da30e9..5430ef4 100644 --- a/recordmydesktop/include/rmdtypes.h +++ b/recordmydesktop/include/rmdtypes.h @@ -60,7 +60,13 @@ #include <vorbis/codec.h> #include <vorbis/vorbisenc.h> #include <ogg/ogg.h> -#include <alsa/asoundlib.h> + +#ifdef HAVE_LIBASOUND + #include <alsa/asoundlib.h> +#else + #include <sys/ioctl.h> + #include <sys/soundcard.h> +#endif //this type exists only //for comparing the planes at caching. @@ -137,7 +143,11 @@ typedef struct _ProgArgs{ unsigned int frequency; //desired frequency (default 22050) unsigned int channels; //no of channels(default 2) char *device; //default sound device +#ifdef HAVE_LIBASOUND snd_pcm_uframes_t buffsize; //buffer size(in frames) for sound capturing +#else + u_int32_t buffsize; +#endif int nosound; //do not record sound(default 0) int noshared; //do not use shared memory extension(default 1) int nocondshared; //do not use shared memory on large image aquititions @@ -283,8 +293,13 @@ typedef struct _ProgData{ v_encoding_clean; int v_enc_thread_waiting, //these indicate a wait th_enc_thread_waiting; //condition on the above cond vars +#ifdef HAVE_LIBASOUND snd_pcm_t *sound_handle; snd_pcm_uframes_t periodsize; +#else + int sound_handle; + u_int32_t periodsize; +#endif }ProgData; 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" |