实现了一个 native层读写音频数据时用到的一个 音频数据缓冲区(线程安全的)(c++)

本文档介绍了如何使用C++创建一个线程安全的音频数据缓冲区,该缓冲区在处理native层的音频数据读写时起到关键作用。MediaBuffer.hh包含了缓冲区的定义,而MediaBuffer.cpp则实现了相关的操作,确保在多线程环境下正确地访问和更新缓冲区内容。
摘要由CSDN通过智能技术生成

MediaBuffer.hh:

#ifndef Live555_MediaBuffer_h
#define Live555_MediaBuffer_h

#include <sys/types.h>
//#ifndef _BOOLEAN_HH
//#include "Boolean.hh"
//#endif

#include <pthread.h>

class MediaBuffer{
private:
    unsigned char *m_lpData;         // the whole buffer
    int m_iCapacity;        			// the total size of the buffer
	int m_iWriteOffset;				// where the encode begins to write to
	int m_iWritableSize;				// how many data is available to write
    int m_iReadOffset;      			// where the broadcast begins to read from
    int m_iReadableSize;    			// how many data is available to read
	//pthread_mutex_t m_lock;		// lock
    //pthread_cond_t m_writeCond; // write condition

public:
    pthread_mutex_t m_lock;	// lock
    pthread_cond_t m_readCond;  // read condition

public:
    MediaBuffer(int iCapacity);
    ~MediaBuffer();

public:
	bool hasAvailableDataToWrite() { return m_iWritableSize > 0; }
	bool hasAvail
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值