海思中fifo的使用及c语言中fifo的使用以及c中关于字符串的说明%s以及strlen注意问题
来源:互联网 发布:qq浏览器mac版什么内核 编辑:程序博客网 时间:2024/06/07 18:35
题记:最近在调试想把海思的视频数据先存储到fifo中,然后取数据的时候再从fifo中取出数据,这样来进一步使得视频播放更加流畅。
1 实现fifo的demo
//============================================================================// Name : FIFOTest01.cpp// Author : frank// Version :// Copyright : Your copyright notice// Description : Hello World in C++, Ansi-style//============================================================================//http://blog.chinaunix.net/uid-12045105-id-2963178.html#include <iostream>#include <string.h>#include <stdio.h>using namespace std;#define BUFSIZE 1024#define WR 1 //写数据标志#define RD 0 //读数据标志typedef struct FifoType{ unsigned char buffer[BUFSIZE]; /* Circular buffer */ unsigned int w_idx; /* Index of write */ unsigned int r_idx; /* Index of read */ }*pFifoType;unsigned char data [1024] ; unsigned char *fifoctl(pFifoType priv , unsigned char *data ,const unsigned char flag) { unsigned char temp[BUFSIZE]; //unsigned int widx = 0; //widx = priv->w_idx; // int len;/* Save the old index before proceeding */ if (flag == WR) //write data { int len = strlen((char *)data); //cout << data << endl; memcpy(priv->buffer,data,len); } else //read data { unsigned char *p; p = priv->buffer; int len = strlen((char *)p); memcpy(temp,priv->buffer,len); priv->r_idx = (priv->r_idx + 1); } return temp; }int main(){ <span style="color:#ff0000;">//刚开始调试的时候出现 unsigned char [1024] 输出乱码。说明是在栈内存中存储数据,数据量较小,那么可以在堆内存中申请可以放到//全局变量或者new 出来,在堆内存中比较大</span> //unsigned char data = new unsigned char[]; for(int i=0;i<3;i++) { pFifoType priv = new FifoType; priv->r_idx = 0; priv->w_idx = 0; unsigned char send [] = "00a4908fgghabcdefghilcsbcdabcdabcdefjifeghiebcdefgh"; fifoctl(priv,send,WR); unsigned char *p; p = fifoctl(priv,data,RD); printf("p = %s\n",p); //cout << p << endl; delete priv; priv = NULL; } return 0;}这个fifo,还没有写全,还要有判断是否buffer的标志。注意看红色的字体部分内容。
2 在海思中加的fifo
pFifoType priv = new FifoType;fFrameSize = 0;for(unsigned int j =0;j< stStream.u32PackCount;j++){printf("len=%d",stStream.pstPack[j].u32Len[0]);for (int i = 0; i < 10; i++) {printf(" %02x", *(stStream.pstPack[j].pu8Addr[0]+ i));}printf("\n");printf("flag run");fifoctl(priv,stStream.pstPack[j].pu8Addr[0],stStream.pstPack[j].u32Len[0],WR);printf("step01\n");unsigned char *fifo_p;fifo_p = fifoctl(priv,fifo_data,stStream.pstPack[j].u32Len[0],RD);printf("step02\n");memmove(fTo + fFrameSize, fifo_p,stStream.pstPack[j].u32Len[0]);printf("step03\n");//fFrameSize += stStream.pstPack[j].u32Len[0];}delete priv;
其中,fifo.cpp的内容是:
#include <iostream>#include <string.h>#include "fifo.h"#include <stdio.h>using namespace std; unsigned char *fifoctl(pFifoType priv , unsigned char data[] ,int fifo_len,const unsigned char flag) { unsigned char temp[BUFSIZE]; //unsigned int widx = 0; //widx = priv->w_idx; // int len;/* Save the old index before proceeding */ if (flag == WR) //write data { /*for (int i = 0; i < 10; i++) { printf("%02x", *(data+ i));//z这个地方打印出来的数据是000000016742001e95a8 }*/ memcpy(priv->fifo_buffer,data,fifo_len); printf("fifo_len= %d",fifo_len); } else //read data { unsigned char *p; p = priv->fifo_buffer; memcpy(temp,priv->fifo_buffer,fifo_len); printf("read len = %d",fifo_len); priv->r_idx = (priv->r_idx + 1); } return temp; }讲下在调试的时候出现的问题:
问题1:用%s,打印的数据没有,因为我的数据包的开头是00 00 01 ,而%s打印的时候遇到\n和0(null),就会停止。所以,如果printf("for2 stStream->pstPack[0].pu8Addr= %s\n",stStream.pstPack[j].pu8Addr[0]);是没有数据的。必须改用%x ,char str[10]={'a','v','c','d',0,'e','f',0,0....} strlen 计算出的 字符串长度是4,写的是0 而不是‘0’。。记住。
问题2 :对于unsigned char data[10],在堆内存和栈内存中,申请的地址不通,如果是全局变量或者是New出来的那么就申请的
较大,。如果是局部变量就会申请的小。
3 未完待续
感觉这样写的fifo是没用用的,必须要通过一线线程编码然后将数据包放到fifo里面,另外一个主线程,也就是要live555发送的线程,对获得的数据进行发送,这就需要对fifo的数据的管理非常的严格,对有多少数据读进去,多少数据读出来,然后什么交给live555多少数据,都要明白才行。看看接下来的时候能搞定吗。
现在不知道我用fifo到底能不能达到我想要的目的,我最终目的是可以根据网络状态来改变码流,从而改变码率。
0 0
- 海思中fifo的使用及c语言中fifo的使用以及c中关于字符串的说明%s以及strlen注意问题
- fifo的c语言实现
- C语言下使用ringbuffer实现任意数据类型的FIFO
- C语言下使用ringbuffer实现任意数据类型的FIFO
- xilinx fifo核使用时注意的问题
- C语言有名管道fifo的创建及运用
- [string]C语言中字符串使用需注意的地方
- FIFO 的使用
- linux FIFO的使用
- FIFO核的使用
- c语言中指针的用法以及注意的地方
- C语言中realloc()使用的说明
- 关于FIFO的深度问题
- linux下c编程系统调用之有名管道FIFO函数的使用及案例
- [2]Vivado中异步FIFO的实现和使用
- c语言中关于隐式类型转换的相关说明以及用法
- C语言中字符串系列函数的实现以及注意事项
- C语言中数组以及处理字符串的函数
- URAL 1207 || Median on the Plane(将平面偶数点集均分
- Tzl_C#金字塔_virtual使用总结
- JUnit 总结
- C#读取XML文件——自定义类
- jQuery Validation插件onfocosout/onkeyup出错的解决方法[Uncaught TypeError: undefined is not a function中文资料不好找]
- 海思中fifo的使用及c语言中fifo的使用以及c中关于字符串的说明%s以及strlen注意问题
- OpenFire源码学习之十九:在openfire中使用redis插件(上)
- [HDU4927] Series 1 && 高精度+组合数
- 采药问题
- java 6 JVM参数选项大全(中文版)
- vs舒适的开发字体和颜色设置
- 单片机设计的计数器(秒表)
- stucts <s:fielderror>标签
- mysql的分组查询、分组统计