一种循环缓冲区的VC++实现
来源:互联网 发布:淘宝网男背心 编辑:程序博客网 时间:2024/05/16 08:50
应用背景:
此循环缓冲区用于缓冲实时流媒体数据,以不定长度的数据块为存取单位,符合FIFO规则。
特征:
1、封装成了一个类,便于代码重用;
2、采用Mutex作为读取同步机制;
3、可设置缓冲区内的最多块的数量;
源代码在这里下载:
http://download.csdn.net/detail/qwertyuj/3865070
下面是类的定义:
/**********************************************************// Name: imgBufferOprations.h// Description: define a CImageBufferClass class// Wrote by: Jianxin, Isoftstone corp.// Version: v0.2//---------------------------------------------------------// This class **********************************************************/#include <Windows.h>#include <queue>#include <assert.h>#include <iostream>using namespace std;#defineIMG263_BUFFER_SIZE1024 * 300//1M. images buffer size#defineMAXCOUNT_FRAMES_IN_BUFFER15struct image263InBufferInfoUnit {UINTdata_head;//image's beginning position in the buffer UINTdata_size;//ending position in buffer of one imageBOOLisBlockCrossBorder;UINT32timestamp;//Maybe some new items will be added here later, depends on experiment result};class CImageBufferClass{public://methodsCImageBufferClass();//constructor~CImageBufferClass();//destructor//-----------------------------------------------// Return next image in the buffer//-----------------------------------------------BOOL getNextImageInBuffer(BYTE* dataRead, UINT* dataSizeRead, UINT32* timestamp);//-----------------------------------------------// put an image into the buffer//-----------------------------------------------BOOL putOneImageIntoBuffer(BYTE* dataTobeWrote, UINT dataSizeTobeWrote, UINT32 timestamp);//-----------------------------------------------// Return the size of free space in the buffer//-----------------------------------------------UINT getFreeSpaceSizeInBuffer();//-----------------------------------------------// //-----------------------------------------------UINT getFrameCountInBuffer();//-----------------------------------------------// //-----------------------------------------------INT getActiveInfoUnitCount();//-----------------------------------------------// //-----------------------------------------------BOOL isImgQueueEmpty();private://variables#if _DEBUGBYTE img263Buffer[IMG263_BUFFER_SIZE];#elseBYTE* img263Buffer;//buffer for storing received images#endifBOOL isBufferBorderCrossed;UINT img263BufferData_head;//beginning of image data in bufferUINT freespace_head;//end of image data in bufferqueue<image263InBufferInfoUnit *> imageInfoUnitQueue;INT activeInfoUnitCount;HANDLE hMutex;//Mutex for buffer reading and writing sycprivate://methods//--------------------------------------------------------// Write image data to buffer//--------------------------------------------------------BOOL writeImageIntoImgBuffer(image263InBufferInfoUnit *imageToWrite, BYTE* dataTobeWrote);//---------------------------------------------------------// Read image data from buffer. //---------------------------------------------------------BOOL readImageFromImgBuffer(image263InBufferInfoUnit *imageBeRead,BYTE* dataRead, UINT* dataSizeRead);//-----------------------------------------------// Initialization//-----------------------------------------------void Initialization();//-----------------------------------------------// Check if the buffer in a good condition//-----------------------------------------------BOOL checkBufferIfNormal();//-----------------------------------------------// Delete oldest image in the buffer//-----------------------------------------------// If the buffer is full before writing a new image,// we should delete the oldest images in the buffer.// run this routine once, results in the oldest image// be deleted.//-----------------------------------------------void deleteOldestImageInBuffer(image263InBufferInfoUnit * imageToDeleteInfo);//-----------------------------------------------// See if next image to be write into buffer // need store it cross the border//-----------------------------------------------BOOL doesNeedCrossBorder(UINT dataSizeTobeWrote);//-----------------------------------------------// //-----------------------------------------------BOOL isImgBufferEmpty();};
- 一种循环缓冲区的VC++实现
- 循环缓冲区C++的一种实现
- 循环buffer的一种实现
- 循环缓冲区的C语言实现
- OBS解读-动态循环缓冲区的实现
- 队列实现循环缓冲区
- 队列实现循环缓冲区
- 循环缓冲区的定义
- 简单的双线程数组循环队列缓冲区的实现
- Objective-C实现循环缓冲区
- 循环队列一种实现
- 循环缓冲区的一点笔记
- 串口实用的循环缓冲区
- 串口实用的循环缓冲区
- 如何实现一个循环缓冲区模型
- 如何实现一个循环缓冲区模型
- 如何实现一个循环缓冲区模型
- 如何实现一个循环缓冲区模型
- Linux设备驱动子系统- I2C
- latex论文字体调整
- Delphi中慎用StrToDate函数
- 研究生生活
- Class文件内容及常量池
- 一种循环缓冲区的VC++实现
- 解决afxcontrolbars.h 无法找到的问题
- 所有权链接
- Delphi拼装SQL语句应该注意的地方
- EssModel 和 astah community
- 换底板2-之核心板
- 获取数组的固定长度的子数组
- 转一篇写得很好的关于iptables原理和流程的文章
- 页面和后台servlet中都设置成utf-8了,Ajax还是乱码