LiveRTMP
##RTSP视频源进行RTMP直播
/* NVSource从RTSPClient获取数据后回调给上层 */
int Easy_APICALL __RTSPSourceCallBack( int _chid, void *_chPtr, int _mediatype, char *pbuf, RTSP_FRAME_INFO *frameinfo)
{
if (NULL != frameinfo)
{
if (frameinfo->height==1088) frameinfo->height=1080;
else if (frameinfo->height==544) frameinfo->height=540;
}
Easy_Bool bRet = 0;
int iRet = 0;
//目前只处理视频
if (_mediatype == EASY_SDK_VIDEO_FRAME_FLAG)
{
if(frameinfo && frameinfo->length)
{
if( frameinfo->type == EASY_SDK_VIDEO_FRAME_I)
{
if(g_rtmpPusher.rtmpHandle == 0)
{
g_rtmpPusher.rtmpHandle = EasyRTMP_Create();
bRet = EasyRTMP_Connect(g_rtmpPusher.rtmpHandle, SRTMP);
if (!bRet)
{
printf("Fail to EasyRTMP_Connect ...\n");
}
EASY_MEDIA_INFO_T mediaInfo;
memset(&mediaInfo, 0, sizeof(EASY_MEDIA_INFO_T));
mediaInfo.u32VideoFps = 25;
mediaInfo.u32AudioSamplerate = 8000;
iRet = EasyRTMP_InitMetadata(g_rtmpPusher.rtmpHandle, &mediaInfo, 1024);
if (iRet < 0)
{
printf("Fail to InitMetadata ...\n");
}
}
EASY_AV_Frame avFrame;
memset(&avFrame, 0, sizeof(EASY_AV_Frame));
avFrame.u32AVFrameFlag = EASY_SDK_VIDEO_FRAME_FLAG;
avFrame.u32AVFrameLen = frameinfo->length;
avFrame.pBuffer = (unsigned char*)pbuf;
avFrame.u32VFrameType = EASY_SDK_VIDEO_FRAME_I;
avFrame.u32TimestampSec = frameinfo->timestamp_sec;
avFrame.u32TimestampUsec = frameinfo->timestamp_usec;
iRet = EasyRTMP_SendPacket(g_rtmpPusher.rtmpHandle, &avFrame);
if (iRet < 0)
{
printf("Fail to EasyRTMP_SendH264Packet(I-frame) ...\n");
}
else
{
printf("I");
}
}
else
{
if(g_rtmpPusher.rtmpHandle)
{
EASY_AV_Frame avFrame;
memset(&avFrame, 0, sizeof(EASY_AV_Frame));
avFrame.u32AVFrameFlag = EASY_SDK_VIDEO_FRAME_FLAG;
avFrame.u32AVFrameLen = frameinfo->length-4;
avFrame.pBuffer = (unsigned char*)pbuf+4;
avFrame.u32VFrameType = EASY_SDK_VIDEO_FRAME_P;
avFrame.u32TimestampSec = frameinfo->timestamp_sec;
avFrame.u32TimestampUsec = frameinfo->timestamp_usec;
iRet = EasyRTMP_SendPacket(g_rtmpPusher.rtmpHandle, &avFrame);
if (iRet < 0)
{
printf("Fail to EasyRTMP_SendH264Packet(P-frame) ...\n");
}
else
{
printf("P");
}
}
}
}
}
else if (_mediatype == EASY_SDK_AUDIO_FRAME_FLAG)
{
EASY_AV_Frame avFrame;
memset(&avFrame, 0x00, sizeof(EASY_AV_Frame));
avFrame.u32AVFrameFlag = EASY_SDK_AUDIO_FRAME_FLAG;
avFrame.u32TimestampSec = frameinfo->timestamp_sec;
avFrame.u32TimestampUsec = frameinfo->timestamp_usec;
if(frameinfo->codec == EASY_SDK_AUDIO_CODEC_AAC)
{
avFrame.pBuffer = (Easy_U8*)(pbuf);
avFrame.u32AVFrameLen = frameinfo->length;
printf("*");
iRet = EasyRTMP_SendPacket(g_rtmpPusher.rtmpHandle, &avFrame);
}
else if ((frameinfo->codec == EASY_SDK_AUDIO_CODEC_G711A) || (frameinfo->codec == EASY_SDK_AUDIO_CODEC_G711U) || (frameinfo->codec == EASY_SDK_AUDIO_CODEC_G726))
{
if(EasyInitAACEncoder(frameinfo) == 0)
{
memset(g_rtmpPusher.m_pAACEncBufer, 0, 64*1024);
unsigned int iAACBufferLen = 0;
if(Easy_AACEncoder_Encode(g_rtmpPusher.m_pAACEncoderHandle, (unsigned char*)pbuf, frameinfo->length, g_rtmpPusher.m_pAACEncBufer, &iAACBufferLen) > 0)
{
printf("*");
avFrame.pBuffer = (Easy_U8*)(g_rtmpPusher.m_pAACEncBufer);
avFrame.u32AVFrameLen = iAACBufferLen;
iRet = EasyRTMP_SendPacket(g_rtmpPusher.rtmpHandle, &avFrame);
}
}
}
}
return 0;
}
技术交流QQ群:615081503