$OpenBSD: patch-stream_tvi_bsdbt848_c,v 1.2 2009/10/11 13:36:23 edd Exp $ --- stream/tvi_bsdbt848.c.orig Tue May 12 19:58:57 2009 +++ stream/tvi_bsdbt848.c Sat Jul 11 06:45:32 2009 @@ -37,9 +37,10 @@ #include #include #include +#include #include -#ifdef CONFIG_SUN_AUDIO +#if defined(CONFIG_SUN_AUDIO) && !defined(CONFIG_SNDIO_AUDIO) #include #endif @@ -51,6 +52,9 @@ #include IOCTL_BT848_H_NAME #endif +#if defined(CONFIG_SNDIO_AUDIO) +#include +#else #ifdef HAVE_SYS_SOUNDCARD_H #include #else @@ -60,6 +64,7 @@ #include #endif #endif +#endif #include "libaf/af_format.h" #include "libmpcodecs/img_format.h" @@ -89,7 +94,12 @@ typedef struct { /* Audio */ char *dspdev; int dspready; +#if defined(CONFIG_SNDIO_AUDIO) + struct sio_hdl *hdl; + struct sio_par spar, gpar; +#else int dspfd; +#endif int dspsamplesize; int dspstereo; int dspspeed; @@ -206,7 +216,9 @@ static tvi_handle_t *tvi_init_bsdbt848(tv_param_t* tv_ /* set audio device name */ if (!tv_param->adevice) -#ifdef CONFIG_SUN_AUDIO +#if defined(CONFIG_SNDIO_AUDIO) + priv->dspdev = NULL; +#elif defined(CONFIG_SUN_AUDIO) priv->dspdev = strdup("/dev/sound"); #else priv->dspdev = strdup("/dev/dsp"); @@ -315,12 +327,19 @@ static int control(priv_t *priv, int cmd, void *arg) { int dspspeed = *(int *)arg; +#if defined(CONFIG_SNDIO_AUDIO) + sio_initpar(&priv->spar); + priv->spar.rate = dspspeed; + if(!sio_setpar(priv->hdl, &priv->spar)) { printf("sio_setpar failed at %d\n", __LINE__); } + if(!sio_getpar(priv->hdl, &priv->gpar)) { printf("sio_getpar failed at %d\n", __LINE__); } + dspspeed = priv->gpar.rate; +#else if(ioctl(priv->dspfd, SNDCTL_DSP_SPEED, &dspspeed) == -1) { mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_Bt848InvalidAudioRate, strerror(errno)); return TVI_CONTROL_FALSE; } - +#endif priv->dspspeed = dspspeed; priv->dspframesize = priv->dspspeed*priv->dspsamplesize/8/ @@ -629,12 +648,46 @@ priv->dspready = TRUE; priv->dspsamplesize = 16; priv->dspstereo = 1; priv->dspspeed = 44100; +#if !defined(CONFIG_SNDIO_AUDIO) priv->dspfmt = AFMT_S16_LE; +#endif priv->dspbytesread = 0; priv->dsprate = priv->dspspeed * priv->dspsamplesize/8*(priv->dspstereo+1); priv->dspframesize = priv->dspspeed*priv->dspsamplesize/8/priv->fps * (priv->dspstereo+1); +#if defined(CONFIG_SNDIO_AUDIO) + +if((priv->hdl = sio_open(priv->dspdev, SIO_REC, 0) == NULL)) + { + mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_Bt848ErrorOpeningDspDev, strerror(errno)); + priv->dspready = FALSE; + } + +sio_initpar(&priv->spar); +priv->spar.rchan = priv->dspstereo + 1; +priv->spar.rate = priv->dspspeed; +priv->spar.bits = priv->dspsamplesize; +priv->spar.le = 1; +priv->spar.sig = 1; + +if((priv->dspready == TRUE) && + (!sio_setpar(priv->hdl, &priv->spar))) + { + mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_Bt848ErrorConfiguringDsp, strerror(errno)); + sio_close(priv->hdl); + priv->dspready = FALSE; + } + +if(!sio_start(priv->hdl)) + { + mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_Bt848ErrorConfiguringDsp, strerror(errno)); + sio_close(priv->hdl); + priv->dspready = FALSE; + } + +#else + if((priv->dspfd = open (priv->dspdev, O_RDONLY, 0)) < 0) { mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_Bt848ErrorOpeningDspDev, strerror(errno)); @@ -660,6 +713,8 @@ if((priv->dspready == TRUE) && priv->dspready = FALSE; } +#endif + return 1; } @@ -684,7 +739,9 @@ if(ioctl(priv->btfd, METEORSSIGNAL, &marg) < 0) return 0; } +#if !defined(CONFIG_SNDIO_AUDIO) read(priv->dspfd, &tmp, 2); +#endif gettimeofday(&curtime, NULL); @@ -723,10 +780,15 @@ if(ioctl(priv->btfd, METEORCAPTUR, &marg) < 0 ) return 0; } -close(priv->btfd); +#if defined(CONFIG_SNDIO_AUDIO) +sio_close(priv->hdl); +priv->hdl = NULL; +#else close(priv->dspfd); - priv->dspfd = -1; +#endif + +close(priv->btfd); priv->btfd = -1; priv->dspready = priv->videoready = FALSE; @@ -806,11 +868,19 @@ gettimeofday(&curtime, NULL); /* Get exactly one frame of audio, which forces video sync to audio.. */ +#if defined(CONFIG_SNDIO_AUDIO) +bytesread=sio_read(priv->hdl, buffer, len); +#else bytesread=read(priv->dspfd, buffer, len); +#endif while(bytesread < len) { +#if defined(CONFIG_SNDIO_AUDIO) + ret=sio_read(priv->hdl, &buffer[bytesread], len-bytesread); +#else ret=read(priv->dspfd, &buffer[bytesread], len-bytesread); +#endif if(ret == -1) { @@ -845,13 +915,16 @@ return priv->dspbytesread * 1.0 / priv->dsprate; static int get_audio_framesize(priv_t *priv) { int bytesavail; -#ifdef CONFIG_SUN_AUDIO +#if defined(CONFIG_SUN_AUDIO) && !defined(CONFIG_SNDIO_AUDIO) struct audio_info auinf; #endif if(priv->dspready == FALSE) return 0; -#ifdef CONFIG_SUN_AUDIO +#if defined(CONFIG_SNDIO_AUDIO) +sio_getpar(priv->hdl, &priv->gpar); +bytesavail = priv->gpar.round * priv->gpar.bps; +#elif defined(CONFIG_SUN_AUDIO) if(ioctl(priv->dspfd, AUDIO_GETINFO, &auinf) < 0) { mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_Bt848IoctlFailed, "AUDIO_GETINFO", strerror(errno));