📄 ao_oss.c
字号:
/********************************************** * Dawn Light Player * * ao_oss.c * * Created by kf701 * 22:44:23 02/29/08 CST * * $Id: ao_oss.c 168 2008-03-21 02:50:01Z kf701 $ **********************************************/#if ENABLE_AO_OSS#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/ioctl.h>#include <sys/soundcard.h>#include "avoutput.h"#include "global.h"static char *dsp_dev = "/dev/dsp";static char *mixer_dev = "/dev/mixer";static int dsp;static int format2oss(int format){ switch (format) { case SAMPLE_FMT_U8: return AFMT_U8; case SAMPLE_FMT_S16: return AFMT_S16_LE;#ifdef AFMT_S24_LE case SAMPLE_FMT_S24: return AFMT_S24_LE;#endif#ifdef AFMT_S32_LE case SAMPLE_FMT_S32: return AFMT_S32_LE;#endif#ifdef AFMT_FLOAT case SAMPLE_FMT_FLT: return AFMT_FLOAT;#endif } return -1;}static int ao_oss_init(void){ int i; dsp = open(dsp_dev, O_WRONLY); if ( dsp < 0 ) { av_log(NULL, AV_LOG_ERROR, "open oss device faild\n"); return -1; } i = dlpctxp->sample_rate; ioctl (dsp, SNDCTL_DSP_SPEED, &i); i = format2oss(dlpctxp->sample_fmt); ioctl(dsp, SNDCTL_DSP_SETFMT, &i); i = dlpctxp->channels; if ( i > 2 ) i = 2; ioctl(dsp, SNDCTL_DSP_CHANNELS, &i); return 0;}static int ao_oss_uninit(void){ close(dsp); return 0;}static void ao_oss_play(AVSample *s){ write(dsp, s->data, s->size);}static int ao_oss_control(int cmd, void *arg){ int mixer, value; switch (cmd) { case AO_GET_VOLUME: { mixer = open(mixer_dev, O_RDWR); if ( mixer < 0 ) return 0; ioctl(mixer, MIXER_READ(0), &value); close( mixer ); return value / 257; } case AO_ADD_VOLUME: { mixer = open(mixer_dev, O_RDWR); if ( mixer < 0 ) return 0; ioctl(mixer, MIXER_READ(0), &value); value = (value / 257 + 5) * 257; ioctl(mixer, MIXER_WRITE(0), &value); av_log(NULL, AV_LOG_INFO, "Change Volume to %d \r", value/257); close( mixer ); break; } case AO_SUB_VOLUME: { mixer = open(mixer_dev, O_RDWR); if ( mixer < 0 ) return 0; ioctl(mixer, MIXER_READ(0), &value); value = (value / 257 - 5) * 257; if ( value < 0 ) value = 0; ioctl(mixer, MIXER_WRITE(0), &value); av_log(NULL, AV_LOG_INFO, "Change Volume to %d \r", value/257); close( mixer ); break; } default: { av_log(NULL, AV_LOG_INFO, "OSS control CMD not support now!\n"); break; } } return 0;}ao_t ao_oss ={ .id = AO_ID_OSS, .name = "oss", .ao_init = ao_oss_init, .ao_uninit = ao_oss_uninit, .ao_play = ao_oss_play, .ao_getspace = NULL, .ao_control = ao_oss_control,};#endif /* ENABLE_AO_OSS */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -