我把代码粘贴过来了,做了些删减。
主要问题就是在AdjustDelay()函数中改头部节点的ref值,但到GetVAData()中拿到这个节点时,打印,引用计数仍是1
改完这个值时,不出AdjustDelay()函数打印ref值,是修改后的,正确的值。
struct SVidNode{
char *buf;
quint64 off;
quint32 len;
quint32 idx;//当前节点索引
quint64 ref;//做引用计数
}
class CVAMng
{
std::mutex mMutex;
std::deque<SVidNode> mFrameList;
char *mpBufPool;
quint64 mBufPoolSize;
quint64 mWritePos;
quint64 mReadPos;
float mDelaySamples;
float mFrameRate;
public:
CVAMng(quint64 VideoMemSize);
~CVAMng();
RETURN_CODE AdjustDelay(int off);
RETURN_CODE PutVAData(const void *pV, quint32 vLen, const void *pA, quin
t32 aSamples, quint32 idx);
RETURN_CODE GetVAData(void *pV, quint32& vLen, void *pA, quint32 aSample
s);
};
CVAMng::CVAMng(quint64 VideoMemSize)
: mBufPoolSize(VideoMemSize)
, mWritePos(0)
, mReadPos(0)
{
mpBufPool = new char[VideoMemSize];
memset(mpBufPool, 0, VideoMemSize);
mAudCache.Init(0);
}
CVAMng::~CVAMng()
{
std::lock_guard<std::mutex> locker(mMutex);
delete []mpBufPool;
mFrameList.clear();
}
RETURN_CODE CVAMng::AdjustDelay(quint32 off)
{
std::lock_guard<std::mutex> locker(mMutex);
if (mFrameList.empty())
return ERR_DONOTHING;
{
SVidNode& vNod = mFrameList.front();
vNod.ref += off;//试验中这样在GetVAData()中拿到的节点的ref仍是1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
return SUCCESS;
}
RETURN_CODE CVAMng::PutVAData(const void *pV, quint32 vLen, const void *pA,
quint32 aSamples, quint32 idx)
{
std::lock_guard<std::mutex> locker(mMutex);
//video
SVidNode vNod;
if (mWritePos + vLen <= mBufPoolSize)
{
memcpy(mpBufPool+mWritePos, pV, vLen);
vNod.off = mWritePos;
}
else
{
mWritePos = 0;
memcpy(mpBufPool, pV, vLen);
vNod.off = 0;
}
vNod.buf = mpBufPool + mWritePos;
vNod.ref = 1;
vNod.idx = idx;
mFrameList.push_back(vNod);
mWritePos += vLen;
return SUCCESS;
}
RETURN_CODE CVAMng::GetVAData(void *pV, quint32 &vLen, void *pA, quint32 aSa
mples)
{
std::lock_guard<std::mutex> locker(mMutex);
if (mFrameList.empty())
return ERR_NOMEMORY;
//video
SVidNode& vNod = mFrameList.front();
if (vNod.buf)
{
memcpy(pV, vNod.buf, vNod.eslen);
vLen = vNod.eslen;
mReadPos = vNod.off;
}
else
{
vLen = 0;
}
//此处打印节点ref,总不是预想值
--vNod.ref;
quint32 ref = vNod.ref;
if (vNod.ref == 0)
mFrameList.pop_front();
return SUCCESS;
}
【 在 here080 (hero080) 的大作中提到: 】
: 怎么用都可以。
: 你“试过了不可以”的代码能不能贴出来让大家批一下?
: 真是急死个人。
: ...................
--
修改:RGB FROM 222.128.182.*
FROM 222.128.182.*