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

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

文章分类

全部博文(1727)

文章存档

2024年(2)

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)

分类: 其他平台

2021-04-15 12:24:45

需求:
一个部分做mp3的解码, 然后给一个单独的pcm播放器用.
这样需要 app_a 不断解码mp3 到 内存区, 然后pcm_player 从内存区不断获取.

本来想用 mmap, (mmap是可以做到多进程读写同步的.). 但是
点击(此处)折叠或打开
  1. https://blog.csdn.net/The_Time_Runner/article/details/107050300

  2. mmap针对Windows和Unix的版本在具体实现上有所不同,对于Windows版本,当length参数比file本身size大的时候,会自动扩展file为指定length大小;而Unix版本不支持自动扩展,即length只能小于等于size of file,如果超出size,则会报错。

  3. 只能刚刚开始时就创建足够大的文件.
所以想下使用 tmpfs 时比较合适的. 

点击(此处)折叠或打开

  1. https://blog.csdn.net/u011285208/article/details/90752148

  2. tmpfs是一种虚拟内存文件系统正如这个定义它最大的特点就是它的存储空间在VM里面. 由于tmpfs使用的是VM,因此它比硬盘的速度肯定要快,因此我们可以利用这个优点使用它来提升机器的性能

点击(此处)折叠或打开

  1. /* reader */
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdint.h>
  6. #include <ctype.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <fcntl.h>
  10. #include <stdio.h>
  11. #include <limits.h>
  12. #include <errno.h>
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15. #include <fcntl.h>

  16. #define FILE_TMPFS "/run/user/1000/tmpfs.file"
  17. #define TIME_SPLICE 100

  18. int main(void)
  19. {
  20.     int fd = -1;
  21.     while (fd < 0) {
  22.         fd = open(FILE_TMPFS, O_RDONLY);
  23.         if (fd < 0) {
  24.          usleep(100000);
  25.          continue;
  26.      }    
  27.     }
  28.   
  29.   char line[256];
  30.   int idx = 0;
  31.   uint32_t timeout = 0;
  32.   while (1) {
  33.       idx = read(fd, line, 8);
  34.       line[8] = 0;
  35.       if (idx < 0) {
  36.           fprintf(stderr, "read failed. [%d]", idx);
  37.           break;        
  38.       }
  39.       else if (idx > 0) {
  40.               fprintf(stderr, "[%s]\n", line);
  41.               timeout = 0;
  42.       }
  43.       else { // ==0, timeout
  44.           timeout += TIME_SPLICE;
  45.           if (timeout > 1000) {
  46.               fprintf(stderr, "read timeout. [%d]\n", timeout);
  47.               break;    
  48.        }
  49.     }
  50.       usleep(TIME_SPLICE * 1000);
  51.   }
  52.   
  53.   close(fd);  
  54.   return 0;    
  55. }

点击(此处)折叠或打开

  1. #define _GNU_SOURCE

  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdint.h>
  6. #include <ctype.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <fcntl.h>
  10. #include <stdio.h>
  11. #include <limits.h>
  12. #include <errno.h>
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15. #include <fcntl.h>

  16. #define FILE_TMPFS "/run/user/1000/tmpfs.file"

  17. int main(void)
  18. {
  19.     int fd = open(FILE_TMPFS, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  20.     if (fd < 0) {
  21.      fprintf(stderr, "open error. [%s]\n", strerror(errno));    
  22.      return -1;
  23.   }    
  24.   
  25.   char line[256];
  26.   uint32_t idx = 0;
  27.   while (idx < 10) {
  28.       sprintf(line, "%08x", idx++);
  29.       write(fd, line, strlen(line));
  30.       sleep(1);
  31.   }
  32.   
  33.   syncfs(fd);
  34.   close(fd);
  35.   fprintf(stderr, "writer finished. close file-desc");
  36.   
  37.   sleep(10);
  38.   unlink(FILE_TMPFS);
  39.   
  40.   return 0;    
  41. }






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