Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9192848
  • 博文数量: 1728
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 19870
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1728)

文章存档

2024年(4)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: 其他平台

2018-02-09 13:54:18


次佳解决办法

在/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内核组件,是系统发出声音最低层的软件系统,可以视为(或者就是)驱动.

PulseAudioESD是两个声音服务器,简单说,软件要发声就先发消息给声音服务器,然后声音服务器经过处理(主要是多条音频流的混音),然后发给驱动控制声音设备发出声音.

选用pulseaudio+alsa好处就是解决混音和声卡独占问题 

声音服务器并不是必须的,你可以跳过esdpulseaudio直接控制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


点击(此处)折叠或打开

  1. #ifdef HAVE_CONFIG_H
  2. #include <config.h>
  3. #endif
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7. #include <errno.h>
  8. #include <fcntl.h>
  9. #include <pulse/simple.h>
  10. #include <pulse/error.h>
  11. #define BUFSIZE 1024
  12. int main(int argc, char*argv[]) {
  13. /* The Sample format to use */
  14. static const pa_sample_spec ss = {
  15. .format = PA_SAMPLE_S16LE,
  16. .rate = 44100,
  17. .channels = 2
  18. };
  19. pa_simple *s = NULL;
  20. int ret = 1;
  21. int error;
  22. /* replace STDIN with the specified file if needed */
  23. if (argc > 1) {
  24. int fd;
  25. if ((fd = open(argv[1], O_RDONLY)) < 0) {
  26. fprintf(stderr, __FILE__": open() failed: %s\n", strerror(errno));
  27. goto finish;
  28. }
  29. if (dup2(fd, STDIN_FILENO) < 0) {
  30. fprintf(stderr, __FILE__": dup2() failed: %s\n", strerror(errno));
  31. goto finish;
  32. }
  33. close(fd);
  34. }
  35. /* Create a new playback stream */
  36. if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) {
  37. fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
  38. goto finish;
  39. }
  40. for (;;) {
  41. uint8_t buf[BUFSIZE];
  42. ssize_t r;
  43. #if 0
  44. pa_usec_t latency;
  45. if ((latency = pa_simple_get_latency(s, &error)) == (pa_usec_t) -1) {
  46. fprintf(stderr, __FILE__": pa_simple_get_latency() failed: %s\n", pa_strerror(error));
  47. goto finish;
  48. }
  49. fprintf(stderr, "%0.0f usec \r", (float)latency);
  50. #endif
  51. /* Read some data ... */
  52. if ((r = read(STDIN_FILENO, buf, sizeof(buf))) <= 0) {
  53. if (r == 0) /* EOF */
  54. break;
  55. fprintf(stderr, __FILE__": read() failed: %s\n", strerror(errno));
  56. goto finish;
  57. }
  58. /* ... and play it */
  59. if (pa_simple_write(s, buf, (size_t) r, &error) < 0) {
  60. fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(error));
  61. goto finish;
  62. }
  63. }
  64. /* Make sure that every single sample was played */
  65. if (pa_simple_drain(s, &error) < 0) {
  66. fprintf(stderr, __FILE__": pa_simple_drain() failed: %s\n", pa_strerror(error));
  67. goto finish;
  68. }
  69. ret = 0;
  70. finish:
  71. if (s)
  72. pa_simple_free(s);
  73. return ret;
  74. }
A simple recording tool using the simple API

点击(此处)折叠或打开

  1. #ifdef HAVE_CONFIG_H
  2. #include <config.h>
  3. #endif
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7. #include <errno.h>
  8. #include <pulse/simple.h>
  9. #include <pulse/error.h>
  10. #define BUFSIZE 1024
  11. /* A simple routine calling UNIX write() in a loop */
  12. static ssize_t loop_write(int fd, const void*data, size_t size) {
  13. ssize_t ret = 0;
  14. while (size > 0) {
  15. ssize_t r;
  16. if ((r = write(fd, data, size)) < 0)
  17. return r;
  18. if (r == 0)
  19. break;
  20. ret += r;
  21. data = (const uint8_t*) data + r;
  22. size -= (size_t) r;
  23. }
  24. return ret;
  25. }
  26. int main(int argc, char*argv[]) {
  27. /* The sample type to use */
  28. static const pa_sample_spec ss = {
  29. .format = PA_SAMPLE_S16LE,
  30. .rate = 44100,
  31. .channels = 2
  32. };
  33. pa_simple *s = NULL;
  34. int ret = 1;
  35. int error;
  36. /* Create the recording stream */
  37. if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) {
  38. fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
  39. goto finish;
  40. }
  41. for (;;) {
  42. uint8_t buf[BUFSIZE];
  43. /* Record some data ... */
  44. if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) {
  45. fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error));
  46. goto finish;
  47. }
  48. /* And write it to STDOUT */
  49. if (loop_write(STDOUT_FILENO, buf, sizeof(buf)) != sizeof(buf)) {
  50. fprintf(stderr, __FILE__": write() failed: %s\n", strerror(errno));
  51. goto finish;
  52. }
  53. }
  54. ret = 0;
  55. finish:
  56. if (s)
  57. pa_simple_free(s);
  58. return ret;
  59. }






阅读(9435) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~