次佳解决办法
在/etc/pulse/client.conf中,您可以取消注释行autospawn=yes并将”no”替换为yes。当然,应该可以在主目录的.pulse目录中设置它。
更简洁的方法是在.pulse目录中创建一个client.conf,然后将行”autospawn=no”放入其中。完成自己需要做的事情后,最好先关闭autospawn。
第三种解决办法
/////////////////////////////////////////////////////////
http://blog.csdn.net/ccf19881030/article/details/9097875
ALSA(高级Linux声音体系)是为声卡提供驱动的Linux内核组件,是系统发出声音最低层的软件系统,可以视为(或者就是)驱动.
而PulseAudio和ESD是两个声音服务器,简单说,软件要发声就先发消息给声音服务器,然后声音服务器经过处理(主要是多条音频流的混音),然后发给驱动控制声音设备发出声音.
选用pulseaudio+alsa的好处就是解决混音和声卡独占问题
声音服务器并不是必须的,你可以跳过esd和pulseaudio直接控制alsa,只是没有了单独的声音控制以及混音功能.有的同学说了,不对啊,我就能混音,其实那是因为alsa自带了一个很简单的混音器dmix,这也是混音常常出问题,常常声卡独占的原因.用 pulseaudio 代替 alsa 自带的 dmix 可以明显减小 mpd 的 cpu 占用。
和ALSA不同,PulseAudio可以在多个操作系统中运行,包括其他的POSIX平台和微软的Windows。也就是说如果你建立一个是用PulseAudio的应用程序而非ALSA,把这个应用移植到另一个平台会很容易。
Music Player Daemon (MPD)是一个小巧的,功能强大的服务器端音乐播放器。在其网络协议下,通过添加插件和音乐库可以播放大量格式的音乐文件。除了播放之外,他还能管理播放列表,管理音乐数据库。由于是后台进程,所以需要一个单独的客户端。
ffmpeg -thread_queue_size 128 -f x11grab -video_size 800*600 -framerate 30 -i :1.0 -f video4linux2 -video_size 400x300 -framerate 30 -i /dev/video0 -f alsa -ac 2 -i pulse -filter_complex '[0:v][1:v]overlay=x=main_w-overlay_w-10:y=main_h-overlay_h-10[out]' -map '[out]' -map 2:a -vcodec libx264 -acodec ac3 test6.mp4
如何配置pulseaudio
apt-cache show pulseaudio-utils
系统内的配置文件在于
/etc/pulse/client.conf daemon.conf default.pa system.pa
主要通过工具
paplay - Playback a WAV file via a PulseAudio sink.
pacat - Cat raw audio data to a PulseAudio sink.
parec - Cat raw audio data from a PulseAudio source.
pacmd - Connect to PulseAudio's built-in command line control interface.
pactl - Send a control command to a PulseAudio server.
padsp - /dev/dsp wrapper to transparently support OSS applications.
pax11publish - Store/retrieve PulseAudio default server/sink/source settings in the X11 root window.
$ pactl set-sink-volume 0 +3%
$ pactl set-sink-volume 0 -3%
$ pactl set-sink-mute 0 toggle
restart pulse audio
$ pulseaudio -k
$ pulseaudio --start
安装音频库客户端软件libpulse-dev
Package libpulse-dev:PulseAudio client development headers and libraries
使用如下命令:
sudo apt-get install libpulse-dev
安装时会提示依赖于下面这几个软件,一并安装即可:
libavahi-client-dev libavahi-common-dev libpulse-mainloop-glib0 libpulse0
编译时
-lpulse -lpulsecommon-1.1 -lpulse-simple
一下demo的使用 ./xxxx x
.wav
pulseaudio库的使用(同步simple API)
pulseaudio官网有关于pulseaudio的API doxygen使用手册,网址如下:
1、播音sample
A simple playback tool using the simple API
-
#ifdef HAVE_CONFIG_H
-
#include <config.h>
-
#endif
-
#include <stdio.h>
-
#include <unistd.h>
-
#include <string.h>
-
#include <errno.h>
-
#include <fcntl.h>
-
#include <pulse/simple.h>
-
#include <pulse/error.h>
-
#define BUFSIZE 1024
-
int main(int argc, char*argv[]) {
-
/* The Sample format to use */
-
static const pa_sample_spec ss = {
-
.format = PA_SAMPLE_S16LE,
-
.rate = 44100,
-
.channels = 2
-
};
-
pa_simple *s = NULL;
-
int ret = 1;
-
int error;
-
/* replace STDIN with the specified file if needed */
-
if (argc > 1) {
-
int fd;
-
if ((fd = open(argv[1], O_RDONLY)) < 0) {
-
fprintf(stderr, __FILE__": open() failed: %s\n", strerror(errno));
-
goto finish;
-
}
-
if (dup2(fd, STDIN_FILENO) < 0) {
-
fprintf(stderr, __FILE__": dup2() failed: %s\n", strerror(errno));
-
goto finish;
-
}
-
close(fd);
-
}
-
/* Create a new playback stream */
-
if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) {
-
fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
-
goto finish;
-
}
-
for (;;) {
-
uint8_t buf[BUFSIZE];
-
ssize_t r;
-
#if 0
-
pa_usec_t latency;
-
if ((latency = pa_simple_get_latency(s, &error)) == (pa_usec_t) -1) {
-
fprintf(stderr, __FILE__": pa_simple_get_latency() failed: %s\n", pa_strerror(error));
-
goto finish;
-
}
-
fprintf(stderr, "%0.0f usec \r", (float)latency);
-
#endif
-
/* Read some data ... */
-
if ((r = read(STDIN_FILENO, buf, sizeof(buf))) <= 0) {
-
if (r == 0) /* EOF */
-
break;
-
fprintf(stderr, __FILE__": read() failed: %s\n", strerror(errno));
-
goto finish;
-
}
-
/* ... and play it */
-
if (pa_simple_write(s, buf, (size_t) r, &error) < 0) {
-
fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(error));
-
goto finish;
-
}
-
}
-
/* Make sure that every single sample was played */
-
if (pa_simple_drain(s, &error) < 0) {
-
fprintf(stderr, __FILE__": pa_simple_drain() failed: %s\n", pa_strerror(error));
-
goto finish;
-
}
-
ret = 0;
-
finish:
-
if (s)
-
pa_simple_free(s);
-
return ret;
-
}
A simple recording tool using the simple API
-
#ifdef HAVE_CONFIG_H
-
#include <config.h>
-
#endif
-
#include <stdio.h>
-
#include <unistd.h>
-
#include <string.h>
-
#include <errno.h>
-
#include <pulse/simple.h>
-
#include <pulse/error.h>
-
#define BUFSIZE 1024
-
/* A simple routine calling UNIX write() in a loop */
-
static ssize_t loop_write(int fd, const void*data, size_t size) {
-
ssize_t ret = 0;
-
while (size > 0) {
-
ssize_t r;
-
if ((r = write(fd, data, size)) < 0)
-
return r;
-
if (r == 0)
-
break;
-
ret += r;
-
data = (const uint8_t*) data + r;
-
size -= (size_t) r;
-
}
-
return ret;
-
}
-
int main(int argc, char*argv[]) {
-
/* The sample type to use */
-
static const pa_sample_spec ss = {
-
.format = PA_SAMPLE_S16LE,
-
.rate = 44100,
-
.channels = 2
-
};
-
pa_simple *s = NULL;
-
int ret = 1;
-
int error;
-
/* Create the recording stream */
-
if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) {
-
fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
-
goto finish;
-
}
-
for (;;) {
-
uint8_t buf[BUFSIZE];
-
/* Record some data ... */
-
if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) {
-
fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error));
-
goto finish;
-
}
-
/* And write it to STDOUT */
-
if (loop_write(STDOUT_FILENO, buf, sizeof(buf)) != sizeof(buf)) {
-
fprintf(stderr, __FILE__": write() failed: %s\n", strerror(errno));
-
goto finish;
-
}
-
}
-
ret = 0;
-
finish:
-
if (s)
-
pa_simple_free(s);
-
return ret;
-
}
阅读(10153) | 评论(0) | 转发(0) |