Date: Mon, 23 Sep 2019 07:08:22 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r512612 - in head/multimedia/mplayer: . files Message-ID: <201909230708.x8N78MKF059937@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Mon Sep 23 07:08:22 2019 New Revision: 512612 URL: https://svnweb.freebsd.org/changeset/ports/512612 Log: Fix OSS audio playback of some videos after SVN r351847. Make sure mplayer sets a sensible fragment and buffer size. Discussed with: riggs@ Tested by: naddy@ Approved by: pi Modified: head/multimedia/mplayer/Makefile head/multimedia/mplayer/files/patch-libao2_ao__oss.c Modified: head/multimedia/mplayer/Makefile ============================================================================== --- head/multimedia/mplayer/Makefile Mon Sep 23 06:20:40 2019 (r512611) +++ head/multimedia/mplayer/Makefile Mon Sep 23 07:08:22 2019 (r512612) @@ -3,7 +3,7 @@ PORTNAME= mplayer PORTVERSION= ${MPLAYER_PORT_VERSION}.${MPLAYER_SNAPSHOT_DATE:S/-//g} -PORTREVISION= 2 +PORTREVISION= 3 CATEGORIES= multimedia audio MAINTAINER= riggs@FreeBSD.org Modified: head/multimedia/mplayer/files/patch-libao2_ao__oss.c ============================================================================== --- head/multimedia/mplayer/files/patch-libao2_ao__oss.c Mon Sep 23 06:20:40 2019 (r512611) +++ head/multimedia/mplayer/files/patch-libao2_ao__oss.c Mon Sep 23 07:08:22 2019 (r512612) @@ -33,7 +33,64 @@ #endif #ifdef AFMT_U32_LE case AFMT_U32_LE: return AF_FORMAT_U32_LE; -@@ -441,10 +453,30 @@ static void uninit(int immed){ +@@ -217,6 +229,48 @@ static int control(int cmd,void *arg){ + return CONTROL_UNKNOWN; + } + ++static void setfragment(int audio_fd) ++{ ++ int buffer_bytes = ao_data.channels * ao_data.samplerate; ++ int block_size = 0; ++ ++ switch (ao_data.format & AF_FORMAT_BITS_MASK) { ++ case AF_FORMAT_8BIT: ++ break; ++ case AF_FORMAT_16BIT: ++ buffer_bytes *= 2; ++ break; ++ case AF_FORMAT_24BIT: ++ buffer_bytes *= 3; ++ break; ++ case AF_FORMAT_32BIT: ++ buffer_bytes *= 4; ++ break; ++ } ++ buffer_bytes *= 0.050; ++ ++ if(ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &block_size)==0){ ++ int setfrag; ++ /* make block size power of two */ ++ while (block_size & (block_size - 1)) ++ block_size += block_size & ~(block_size - 1); ++ /* set number of fragments */ ++ setfrag = ((buffer_bytes + block_size - 1) / block_size) << 16; ++ /* need at least double buffering */ ++ if (setfrag < (2 << 16)) ++ setfrag = (2 << 16); ++ /* set block size in power of two */ ++ while (block_size) { ++ setfrag++; ++ block_size /= 2; ++ } ++ /* try to set a total buffer of 50ms */ ++ if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &setfrag)==-1){ ++ mp_msg(MSGT_AO,MSGL_V,"audio_setup: setfragment %d failed\n", setfrag); ++ } ++ } ++} ++ + // open & setup audio device + // return: 1=success 0=fail + static int init(int rate,int channels,int format,int flags){ +@@ -364,6 +418,7 @@ ac3_retry: + mp_msg(MSGT_AO,MSGL_WARN, "OSS: Failed setting sample-rate %i %s\n", rate, strerror(errno)); + mp_msg(MSGT_AO,MSGL_V,"audio_setup: using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate); + } ++ setfragment(audio_fd); + + if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){ + int r=0; +@@ -441,10 +496,30 @@ static void uninit(int immed){ audio_fd = -1; } @@ -64,7 +121,7 @@ uninit(1); audio_fd=open(dsp, O_WRONLY); if(audio_fd < 0){ -@@ -456,6 +488,7 @@ static void reset(void){ +@@ -456,6 +531,7 @@ static void reset(void){ fcntl(audio_fd, F_SETFD, FD_CLOEXEC); #endif @@ -72,13 +129,14 @@ oss_format = format2oss(ao_data.format); if(AF_FORMAT_IS_AC3(ao_data.format)) fail |= ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate) == -1; -@@ -467,14 +500,14 @@ static void reset(void){ +@@ -467,14 +543,15 @@ static void reset(void){ int c = ao_data.channels-1; fail |= ioctl (audio_fd, SNDCTL_DSP_STEREO, &c) == -1; } - fail |= ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate) == -1; } - mp_msg(MSGT_AO,MSGL_WARN, "OSS: Reset failed\n"); ++ setfragment(audio_fd); + restorevol(); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201909230708.x8N78MKF059937>