I left the muxer name as "oss". I did this because it is the only supported audio recording muxer in ffmpeg, so everywhere it talks about hardware audio recording in the docs, it uses '-f oss -i <device>'. this will also allow any scripts which use ffmpeg to record audio (-f oss -i /dev/audio) to continue to work as long as aucat isn't running.
-- jake...@sdf.lonestar.org SDF Public Access UNIX System - http://sdf.lonestar.org Index: Makefile =================================================================== RCS file: /cvs/ports/graphics/ffmpeg/Makefile,v retrieving revision 1.50 diff -N -u -p Makefile --- Makefile 2 Sep 2009 11:50:56 -0000 1.50 +++ Makefile 21 Apr 2010 13:24:05 -0000 @@ -4,7 +4,7 @@ COMMENT= audio/video converter and streamer with bktr( V= 20080620 DISTNAME= ffmpeg-svn-${V} -PKGNAME= ffmpeg-${V}p12 +PKGNAME= ffmpeg-${V}p13 SHARED_LIBS= avutil 6.0 \ avcodec 13.1 \ avformat 12.0 \ @@ -38,7 +38,7 @@ LIB_DEPENDS= SDL.>=4::devel/sdl \ Imlib2::graphics/imlib2 \ bz2.>=10::archivers/bzip2 -WANTLIB= X11 Xext c freetype m ogg oil-0.3 ossaudio pthread z +WANTLIB= X11 Xext c freetype m ogg oil-0.3 pthread sndio z USE_X11= Yes USE_GMAKE= Yes @@ -53,7 +53,7 @@ LIBavutil_EXTRALIBS=-lm LIBavcodec_EXTRALIBS=-L${LOCALBASE}/lib -lfaac -lfaad -lmp3lame -lvorbis -lvorbisenc -la52 -lschroedinger-1.0 -loil-0.3 -ltheora -logg -lx264 -lz -lm -pthread -Wl,-rpath,${LOCALBASE}/lib LIBavformat_EXTRALIBS=-L${LOCALBASE}/lib -lbz2 -lm -Wl,-rpath,${LOCALBASE}/lib LIBpostproc_EXTRALIBS=-lm -LIBavdevice_EXTRALIBS=-L${X11BASE}/lib -lX11 -lXext -lossaudio -lm -Wl,-rpath,${LOCALBASE}/lib -Wl,-rpath,${X11BASE}/lib +LIBavdevice_EXTRALIBS=-L${X11BASE}/lib -lX11 -lXext -lsndio -lm -Wl,-rpath,${LOCALBASE}/lib -Wl,-rpath,${X11BASE}/lib LIBswscale_EXTRALIBS=-lm # configure wants a directory it can execute files in Index: patches/patch-configure =================================================================== RCS file: /cvs/ports/graphics/ffmpeg/patches/patch-configure,v retrieving revision 1.21 diff -N -u -p patches/patch-configure --- patches/patch-configure 8 Sep 2008 23:28:28 -0000 1.21 +++ patches/patch-configure 21 Apr 2010 13:24:05 -0000 @@ -1,7 +1,30 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 brad Exp $ ---- configure.orig Fri Jun 20 22:40:11 2008 -+++ configure Sun Sep 7 00:17:23 2008 -@@ -884,7 +884,7 @@ rtp_muxer_deps="network rtp_protocol" +--- configure.orig Fri Jun 20 19:40:11 2008 ++++ configure Wed Apr 21 05:04:39 2010 +@@ -766,12 +766,11 @@ HAVE_LIST=" + sdl + sdl_video_size + socklen_t +- soundcard_h ++ sndio_h + poll_h + sys_mman_h + sys_resource_h + sys_select_h +- sys_soundcard_h + termios_h + threads + winsock2_h +@@ -877,14 +876,14 @@ libdc1394_demuxer_deps="libdc1394" + libnut_demuxer_deps="libnut" + libnut_muxer_deps="libnut" + mp3_demuxer_deps="mpegaudio_parser" +-oss_demuxer_deps_any="soundcard_h sys_soundcard_h" +-oss_muxer_deps_any="soundcard_h sys_soundcard_h" ++oss_demuxer_deps_any="sndio_h" ++oss_muxer_deps_any="sndio_h" + redir_demuxer_deps="network" + rtp_muxer_deps="network rtp_protocol" rtsp_demuxer_deps="sdp_demuxer" sdp_demuxer_deps="rtp_protocol mpegts_demuxer" v4l_demuxer_deps="linux_videodev_h" @@ -10,7 +33,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b vfwcap_demuxer_deps="capCreateCaptureWindow" vfwcap_demuxer_extralibs="-lvfw32" x11_grab_device_demuxer_deps="x11grab XShmCreateImage" -@@ -934,6 +934,10 @@ cpu="generic" +@@ -934,6 +933,10 @@ cpu="generic" # OS target_os=$(tolower $(uname -s)) @@ -21,7 +44,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b # libraries enable bzlib enable zlib -@@ -953,9 +957,9 @@ enable stripping +@@ -953,9 +956,9 @@ enable stripping vhook="default" # build settings @@ -33,7 +56,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b FFSERVERLDFLAGS=-Wl,-E LIBPREF="lib" LIBSUF=".a" -@@ -965,7 +969,7 @@ SLIBPREF="lib" +@@ -965,7 +968,7 @@ SLIBPREF="lib" SLIBSUF=".so" SLIBNAME='$(SLIBPREF)$(FULLNAME)$(SLIBSUF)' SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)' @@ -42,7 +65,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b LIB_INSTALL_EXTRA_CMD='$(RANLIB) "$(LIBDIR)/$(LIBNAME)"' # gcc stupidly only outputs the basename of targets with -MM -@@ -1130,7 +1134,7 @@ EOF +@@ -1130,7 +1133,7 @@ EOF arch="powerpc" enable fast_64bit ;; @@ -51,7 +74,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b arch="mips" ;; sun4u|sparc64) -@@ -1140,13 +1144,13 @@ EOF +@@ -1140,13 +1143,13 @@ EOF sparc) arch="sparc" ;; @@ -68,20 +91,24 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b arch="parisc" enable fast_64bit ;; -@@ -1213,9 +1217,9 @@ case $target_os in +@@ -1213,11 +1216,11 @@ case $target_os in disable need_memalign LIBOBJFLAGS='$(PIC)' SHFLAGS='-shared' - SLIBNAME='$(SLIBPREF)$(FULLNAME)$(SLIBSUF).$(LIBVERSION)' - SLIBNAME_WITH_VERSION='$(SLIBNAME)' - SLIBNAME_WITH_MAJOR='$(SLIBNAME)' +- oss_demuxer_extralibs="-lossaudio" +- oss_muxer_extralibs="-lossaudio" + #SLIBNAME='$(SLIBPREF)$(FULLNAME)$(SLIBSUF).$(LIBVERSION)' + #SLIBNAME_WITH_VERSION='$(SLIBNAME)' + #SLIBNAME_WITH_MAJOR='$(SLIBNAME)' - oss_demuxer_extralibs="-lossaudio" - oss_muxer_extralibs="-lossaudio" ++ oss_demuxer_extralibs="-lsndio" ++ oss_muxer_extralibs="-lsndio" ;; -@@ -1501,7 +1505,7 @@ fi + freebsd) + disable need_memalign +@@ -1501,7 +1504,7 @@ fi check_cc <<EOF || die "Symbol mangling check failed." int ff_extern; EOF @@ -90,7 +117,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b extern_prefix=${sym%%ff_extern*} check_asm inline_asm '""' -@@ -1531,16 +1535,16 @@ fi +@@ -1531,16 +1534,16 @@ fi # check for assembler specific support @@ -117,7 +144,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b # check for SIMD availability -@@ -1582,10 +1586,14 @@ enabled vis && add_cflags "-mcpu=ultrasparc -mtune=ult +@@ -1582,10 +1585,14 @@ enabled vis && add_cflags "-mcpu=ultrasparc -mtune=ult # --- # big/little-endian test @@ -135,7 +162,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b # --- # check availability of some header files -@@ -1607,7 +1615,7 @@ check_func2 windows.h GetProcessTimes +@@ -1607,7 +1614,7 @@ check_func2 windows.h GetProcessTimes check_header byteswap.h check_header conio.h check_header dlfcn.h @@ -144,7 +171,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b check_header sys/mman.h check_header sys/resource.h check_header termios.h -@@ -1717,10 +1725,10 @@ if test "$target_os" = cygwin -o "$target_os" = mingw3 +@@ -1717,10 +1724,10 @@ if test "$target_os" = cygwin -o "$target_os" = mingw3 echo fi @@ -159,7 +186,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b check_foo_config imlib2 imlib2 Imlib2.h imlib_load_font check_foo_config freetype2 freetype ft2build.h FT_Init_FreeType -@@ -1756,7 +1764,7 @@ fi +@@ -1756,7 +1763,7 @@ fi texi2html -version > /dev/null 2>&1 && enable texi2html || disable texi2html @@ -168,7 +195,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b ########################################## # Network check -@@ -1791,6 +1799,7 @@ EOF +@@ -1791,6 +1798,7 @@ EOF check_header linux/videodev.h check_header linux/videodev2.h @@ -176,7 +203,17 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b check_func2 "windows.h vfw.h" capCreateCaptureWindow -lvfw32 -@@ -1831,7 +1840,7 @@ enabled extra_warnings && check_cflags -Winline +@@ -1803,8 +1811,7 @@ check_func2 "windows.h vfw.h" capCreateCaptureWindow - + check_header dev/video/bktr/ioctl_bt848.h; } || + check_header dev/ic/bt8xx.h + +-check_header sys/soundcard.h +-check_header soundcard.h ++check_header sndio.h + + # deal with the X11 frame grabber + enabled x11grab && +@@ -1831,7 +1838,7 @@ enabled extra_warnings && check_cflags -Winline # add some linker flags check_ldflags -Wl,--warn-common check_ldflags $LDLATEFLAGS @@ -185,7 +222,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b if enabled small; then check_cflags -Os # not all compilers support -Os -@@ -2204,8 +2213,7 @@ Version: $version +@@ -2204,8 +2211,7 @@ Version: $version Requires: $(disabled shared && echo $requires) Requires.private: $(enabled shared && echo $requires) Conflicts: @@ -195,7 +232,7 @@ $OpenBSD: patch-configure,v 1.21 2008/09/08 23:28:28 b Cflags: -I\${includedir} EOF cat <<EOF > $name/$name-uninstalled.pc -@@ -2224,17 +2232,17 @@ Cflags: -I\${includedir} +@@ -2224,17 +2230,17 @@ Cflags: -I\${includedir} EOF } Index: patches/patch-libavdevice_audio_c =================================================================== RCS file: patches/patch-libavdevice_audio_c diff -N -u -p patches/patch-libavdevice_audio_c --- /dev/null 21 Apr 2010 07:24:05 -0000 +++ patches/patch-libavdevice_audio_c 21 Apr 2010 13:24:05 -0000 @@ -0,0 +1,253 @@ +$OpenBSD$ +--- libavdevice/audio.c.orig Fri Jun 20 19:40:10 2008 ++++ libavdevice/audio.c Wed Apr 21 06:21:34 2010 +@@ -25,16 +25,12 @@ + #include <stdint.h> + #include <string.h> + #include <errno.h> +-#ifdef HAVE_SOUNDCARD_H +-#include <soundcard.h> +-#else +-#include <sys/soundcard.h> +-#endif + #include <unistd.h> + #include <fcntl.h> +-#include <sys/ioctl.h> + #include <sys/time.h> + ++#include <sndio.h> ++ + #include "libavutil/log.h" + #include "libavcodec/avcodec.h" + #include "libavformat/avformat.h" +@@ -42,7 +38,7 @@ + #define AUDIO_BLOCK_SIZE 4096 + + typedef struct { +- int fd; ++ struct sio_hdl *hdl; + int sample_rate; + int channels; + int frame_size; /* in bytes ! */ +@@ -50,20 +46,28 @@ typedef struct { + int flip_left : 1; + uint8_t buffer[AUDIO_BLOCK_SIZE]; + int buffer_ptr; ++ long long hwpos, softpos; + } AudioData; + ++static void movecb(void *addr, int delta) ++{ ++ AudioData *s = addr; ++ ++ s->hwpos += delta * s->channels * 2; /* always 16-bit */ ++} ++ + static int audio_open(AudioData *s, int is_output, const char *audio_device) + { +- int audio_fd; +- int tmp, err; ++ struct sio_hdl *hdl; ++ struct sio_par par, gpar; + char *flip = getenv("AUDIO_FLIP_LEFT"); + + if (is_output) +- audio_fd = open(audio_device, O_WRONLY); ++ hdl = sio_open(audio_device, SIO_PLAY, 0); + else +- audio_fd = open(audio_device, O_RDONLY); +- if (audio_fd < 0) { +- av_log(NULL, AV_LOG_ERROR, "%s: %s\n", audio_device, strerror(errno)); ++ hdl = sio_open(audio_device, SIO_REC, 0); ++ if (hdl == NULL) { ++ av_log(NULL, AV_LOG_ERROR, "could not open sndio device\n"); + return AVERROR(EIO); + } + +@@ -71,85 +75,58 @@ static int audio_open(AudioData *s, int is_output, con + s->flip_left = 1; + } + +- /* non blocking mode */ +- if (!is_output) +- fcntl(audio_fd, F_SETFL, O_NONBLOCK); +- + s->frame_size = AUDIO_BLOCK_SIZE; +-#if 0 +- tmp = (NB_FRAGMENTS << 16) | FRAGMENT_BITS; +- err = ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &tmp); +- if (err < 0) { +- perror("SNDCTL_DSP_SETFRAGMENT"); +- } +-#endif + +- /* select format : favour native format */ +- err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp); ++ sio_initpar(&par); ++ par.bits = 16; ++ par.sig = 1; ++ par.le = SIO_LE_NATIVE; ++ if (is_output) ++ par.pchan = s->channels; ++ else ++ par.rchan = s->channels; ++ par.rate = s->sample_rate; + +-#ifdef WORDS_BIGENDIAN +- if (tmp & AFMT_S16_BE) { +- tmp = AFMT_S16_BE; +- } else if (tmp & AFMT_S16_LE) { +- tmp = AFMT_S16_LE; +- } else { +- tmp = 0; ++ if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &gpar)) { ++ av_log(NULL, AV_LOG_ERROR, "error setting sndio parameters\n"); ++ goto fail; + } +-#else +- if (tmp & AFMT_S16_LE) { +- tmp = AFMT_S16_LE; +- } else if (tmp & AFMT_S16_BE) { +- tmp = AFMT_S16_BE; +- } else { +- tmp = 0; ++ ++ if (gpar.bits != 16 || gpar.sig != 1 || gpar.le != SIO_LE_NATIVE || ++ (is_output && (gpar.pchan != 1 && gpar.pchan != 2)) || ++ (!is_output && (gpar.rchan != 1 && gpar.rchan != 2)) ) { ++ av_log(NULL, AV_LOG_ERROR, "could not set appropriate sndio parameters\n"); ++ goto fail; + } +-#endif + +- switch(tmp) { +- case AFMT_S16_LE: ++ if (SIO_LE_NATIVE) + s->codec_id = CODEC_ID_PCM_S16LE; +- break; +- case AFMT_S16_BE: ++ else + s->codec_id = CODEC_ID_PCM_S16BE; +- break; +- default: +- av_log(NULL, AV_LOG_ERROR, "Soundcard does not support 16 bit sample format\n"); +- close(audio_fd); +- return AVERROR(EIO); +- } +- err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp); +- if (err < 0) { +- av_log(NULL, AV_LOG_ERROR, "SNDCTL_DSP_SETFMT: %s\n", strerror(errno)); +- goto fail; +- } ++ if (is_output) ++ s->channels = gpar.pchan; ++ else ++ s->channels = gpar.rchan; ++ s->sample_rate = gpar.rate; + +- tmp = (s->channels == 2); +- err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp); +- if (err < 0) { +- av_log(NULL, AV_LOG_ERROR, "SNDCTL_DSP_STEREO: %s\n", strerror(errno)); +- goto fail; +- } +- if (tmp) +- s->channels = 2; ++ sio_onmove(hdl, movecb, s); + +- tmp = s->sample_rate; +- err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &tmp); +- if (err < 0) { +- av_log(NULL, AV_LOG_ERROR, "SNDCTL_DSP_SPEED: %s\n", strerror(errno)); ++ if (!sio_start(hdl)) { ++ av_log(NULL, AV_LOG_ERROR, "could not start sndio\n"); + goto fail; + } +- s->sample_rate = tmp; /* store real sample rate */ +- s->fd = audio_fd; + ++ s->hdl = hdl; ++ + return 0; + fail: +- close(audio_fd); ++ sio_close(hdl); + return AVERROR(EIO); + } + + static int audio_close(AudioData *s) + { +- close(s->fd); ++ sio_close(s->hdl); + return 0; + } + +@@ -186,12 +163,13 @@ static int audio_write_packet(AVFormatContext *s1, AVP + s->buffer_ptr += len; + if (s->buffer_ptr >= AUDIO_BLOCK_SIZE) { + for(;;) { +- ret = write(s->fd, s->buffer, AUDIO_BLOCK_SIZE); ++ ret = sio_write(s->hdl, s->buffer, AUDIO_BLOCK_SIZE); + if (ret > 0) + break; +- if (ret < 0 && (errno != EAGAIN && errno != EINTR)) ++ if (ret == 0 && sio_eof(s->hdl)) + return AVERROR(EIO); + } ++ s->softpos += ret; + s->buffer_ptr = 0; + } + buf += len; +@@ -247,47 +225,27 @@ static int audio_read_packet(AVFormatContext *s1, AVPa + AudioData *s = s1->priv_data; + int ret, bdelay; + int64_t cur_time; +- struct audio_buf_info abufi; + + if (av_new_packet(pkt, s->frame_size) < 0) + return AVERROR(EIO); + for(;;) { +- struct timeval tv; +- fd_set fds; +- +- tv.tv_sec = 0; +- tv.tv_usec = 30 * 1000; /* 30 msecs -- a bit shorter than 1 frame at 30fps */ +- +- FD_ZERO(&fds); +- FD_SET(s->fd, &fds); +- +- /* This will block until data is available or we get a timeout */ +- (void) select(s->fd + 1, &fds, 0, 0, &tv); +- +- ret = read(s->fd, pkt->data, pkt->size); ++ ret = sio_read(s->hdl, pkt->data, pkt->size); + if (ret > 0) + break; +- if (ret == -1 && (errno == EAGAIN || errno == EINTR)) { ++ if (ret == 0 && sio_eof(s->hdl)) { + av_free_packet(pkt); + pkt->size = 0; + pkt->pts = av_gettime(); + return 0; + } +- if (!(ret == 0 || (ret == -1 && (errno == EAGAIN || errno == EINTR)))) { +- av_free_packet(pkt); +- return AVERROR(EIO); +- } + } + pkt->size = ret; ++ s->softpos += ret; + + /* compute pts of the start of the packet */ + cur_time = av_gettime(); +- bdelay = ret; +- if (ioctl(s->fd, SNDCTL_DSP_GETISPACE, &abufi) == 0) { +- bdelay += abufi.bytes; +- } +- /* subtract time represented by the number of bytes in the audio fifo */ +- cur_time -= (bdelay * 1000000LL) / (s->sample_rate * s->channels); ++ ++ bdelay = ret + s->hwpos - s->softpos; + + /* convert to wanted units */ + pkt->pts = cur_time;