662
社区成员




while ((pack = GetNextPacket()) != NULL)
{
if((int)pack->GetPayloadType() == 2)
{
if(pack->HasMarker())//如果是最后一包 ;
{
if (m_current_size == 0)
{
CRTPSessionUtils::DecodeOneFrame(pack->GetPayloadData(),(int)pack->GetPayloadLength());
}else{
CRTPSessionUtils::DecodeOneFrame(m_buffer,m_current_size);//解码一帧数据;
}
m_current_size = 0;
}
else{
memcpy(m_buffer + m_current_size,pack->GetPayloadData(),pack->GetPayloadLength());
m_current_size += pack->GetPayloadLength();
}
}
DeletePacket(pack);
}
void CRTPSessionUtils::DecodeOneFrame(uint8_t *pBuffer,int dwBufsize)
{
CRTPSessionUtils::packet.data = pBuffer;
CRTPSessionUtils::packet.size = dwBufsize;
avcodec_decode_video2(CRTPSessionUtils::pCodecCtx,CRTPSessionUtils::pFrame,&(CRTPSessionUtils::frameFinished),&(CRTPSessionUtils::packet));//对packet中的帧进行解码
if (CRTPSessionUtils::frameFinished)
{
int newSize = 152064;
unsigned char *buf = new unsigned char[newSize];
buffer_current_frame= new uint8_t[newSize];
int height = CRTPSessionUtils::pCodecCtx->height;
int width = CRTPSessionUtils::pCodecCtx->width;
int a=0,i;
for (i=0; i<height; i++)
{
memcpy(buf+a,CRTPSessionUtils::pFrame->data[0] + i * CRTPSessionUtils::pFrame->linesize[0], width);
a+=width;
}
for (i=0; i<height/2; i++)
{
memcpy(buf+a,CRTPSessionUtils::pFrame->data[1] + i * CRTPSessionUtils::pFrame->linesize[1], width/2);
a+=width/2;
}
for (i=0; i<height/2; i++)
{
memcpy(buf+a,CRTPSessionUtils::pFrame->data[2] + i * CRTPSessionUtils::pFrame->linesize[2], width/2);
a+=width/2;
}
memcpy(buffer_current_frame,buf,newSize);
bufferIsNull = true;
delete [] buf;
}
}