資源簡介
接收RTP包保存為h264文件
代碼片段和文件信息
#include?“H264Decoder.h“
enum?PluginCodec_ReturnCoderFlags?{
PluginCodec_ReturnCoderLastframe??????=?1????//?indicates?when?video?codec?returns?last?data?for?frame
PluginCodec_ReturnCoderiframe?????????=?2????//?indicates?when?video?returns?I?frame
PluginCodec_ReturnCoderRequestiframe??=?4????//?indicates?when?video?decoder?request?I?frame?for?resync
PluginCodec_ReturnCoderBufferTooSmall?=?8?????//?indicates?when?output?buffer?is?not?large?enough?to?receive
//?the?data?another?call?to?get_output_data_size?is?required
};
?#define?snprintf??_snprintf
H264Decoder::H264Decoder(int?portIndex)
{
snprintf(ssName?sizeof(ssName)
“main_decode_%d_%d_%d.264“?GetCurrentProcessId()GetCurrentThreadId()portIndex);
fp?=?fopen(ssName“wb+“);
_gotiframe?=?false;
_gotAGoodframe?=?false;
_frameCounter?=?0;?
_skippedframeCounter?=?0;
_rxH264frame?=?new?H264frame();
//dong?trace
//PTRACE(1NULL?“H264Decoder“);
}
H264Decoder::~H264Decoder()
{
delete(_rxH264frame);
fflush(fp);
fclose(fp);
}
bool?H264Decoder::Transcode(const?void?*?fromPtr
??int?&?fromLen
??unsigned?&?flags)
{
RTPframe?srcRTP((const?u_char?*)fromPtr?fromLen);
if?(!_rxH264frame->SetFromRTPframe(srcRTP?flags))?{
_rxH264frame->BeginNewframe();
flags?=?(_gotAGoodframe???requestiframe?:?0);
_gotAGoodframe?=?false;
return?true;
}
if?(srcRTP.GetMarker()==0)
{
return?true;
}?
if?(_rxH264frame->GetframeSize()==0)
{
_rxH264frame->BeginNewframe();
/*TRACE(4?“H264\tDecoder\tGot?an?empty?frame?-?skipping“);*/
_skippedframeCounter++;
flags?=?(_gotAGoodframe???requestiframe?:?0);
_gotAGoodframe?=?false;
return?true;
}
//?look?and?see?if?we?have?read?an?I?frame.
if?(_gotiframe?==?0)
{
if?(!_rxH264frame->IsSync())
{
/*TRACE(1?“H264\tDecoder\tWaiting?for?an?I-frame“);*/
_rxH264frame->BeginNewframe();
flags?=?(_gotAGoodframe???requestiframe?:?0);
_gotAGoodframe?=?false;
return?true;
}
_gotiframe?=?1;
}
uint32_t?bytesUsed?=?0;??
//ck?to?instead?with?8168
////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(_rxH264frame->Isgoodframe())
{
fwrite(_rxH264frame->GetframePtr()?+?bytesUsed_rxH264frame->GetframeSize()?-?bytesUsed1fp);
fflush(fp);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
_rxH264frame->BeginNewframe();
int?gotPicture?=?1;
/*gotPicture?used?to?show?the?decoder‘s?status*/
if?(!gotPicture)?
{
/*TRACE(1?“H264\tDecoder\tDecoded?“< _skippedframeCounter++;
flags?=?(_gotAGoodframe???requestiframe?:?0);
_gotAGoodframe?=?false;
return?true;
}
flags?=?PluginCodec_ReturnCoderLastframe;
_frameCounter++;
_gotAGoodframe?=?true;
return?true;
}
評(píng)論
共有 條評(píng)論