EasyPusher如何推送纯音频RTSP流媒体数据

来源:互联网 发布:win7仿mac os x主题包 编辑:程序博客网 时间:2024/06/05 16:41

EasyPusher介绍

EasyPusher是简单、高效、稳定的一款标准RTSP/RTP协议直播推送库,支持将H.264/G.711/G.726/AAC等音视频数据推送到RTSP流媒体服务器进行低延时直播或者视频通信,支持Windows、Linux、ARM、Android、iOS等平台,EasyPusher配套EasyDarwin流媒体服务器、EasyPlayer播放器适用于特殊行业的低延时应急指挥需求。
最近有一些朋友需要纯音频数据的流媒体服务,于是小二就用EasyPusher尝试了。惊奇的发现EasyPusher底层是完全支持这种需求的,可以发送音视频、纯音频、纯视频的流。上层对EasyPusher SDK初始化需要提前做,不能像原来那样等到视频第一个关键帧来了之后才初始化。因为对于纯音频的时候,没有视频流,自然永远等不到视频关键帧。

Demo代码

如下代码是我基于GitHub上EasyPusher的EasyPusher_RTSP的Demo代码修改的。纯音频的时候,将EasyPusher SDK初始化提前。 同时将视频帧的数据屏蔽了,是否屏蔽已经无所谓,因为纯音频的时候已经没有视频帧数据啦。

/* EasyRTSPClient Callback */int Easy_APICALL __RTSPSourceCallBack( int _chid, void *_chPtr, int _mediatype, char *pbuf, RTSP_FRAME_INFO *frameinfo){    if((fPusherHandle == 0) && (fSourceMediaInfo != NULL))    {        EASY_MEDIA_INFO_T mediainfo;        memset(&mediainfo, 0x00, sizeof(EASY_MEDIA_INFO_T));        memcpy(&mediainfo, fSourceMediaInfo, sizeof(EASY_MEDIA_INFO_T));        fPusherHandle = EasyPusher_Create();        EasyPusher_SetEventCallback(fPusherHandle, __EasyPusher_Callback, 0, NULL);        EasyPusher_StartStream(fPusherHandle, ConfigIP, atoi(ConfigPort), ConfigName, "admin", "admin", &mediainfo, 1024, false);//1M缓冲区        printf("*** live streaming url:rtsp://%s:%d/%s ***\n", ConfigIP, atoi(ConfigPort), ConfigName);    }    /*if (_mediatype == EASY_SDK_VIDEO_FRAME_FLAG)    {        if(frameinfo && frameinfo->length)        {            EASY_AV_Frame  avFrame;            memset(&avFrame, 0x00, sizeof(EASY_AV_Frame));            avFrame.u32AVFrameLen = frameinfo->length;            avFrame.pBuffer = (unsigned char*)pbuf;            avFrame.u32VFrameType = frameinfo->type;            avFrame.u32AVFrameFlag = EASY_SDK_VIDEO_FRAME_FLAG;            avFrame.u32TimestampSec = frameinfo->timestamp_sec;            avFrame.u32TimestampUsec = frameinfo->timestamp_usec;            EasyPusher_PushFrame(fPusherHandle, &avFrame);        }       }*/    if (_mediatype == EASY_SDK_AUDIO_FRAME_FLAG)    {        if(fPusherHandle == 0 ) return 0;        if(frameinfo && frameinfo->length)        {            EASY_AV_Frame  avFrame;            memset(&avFrame, 0x00, sizeof(EASY_AV_Frame));            avFrame.u32AVFrameLen = frameinfo->length;            avFrame.pBuffer = (unsigned char*)pbuf;            avFrame.u32VFrameType = frameinfo->type;            avFrame.u32AVFrameFlag = EASY_SDK_AUDIO_FRAME_FLAG;            avFrame.u32TimestampSec = frameinfo->timestamp_sec;            avFrame.u32TimestampUsec = frameinfo->timestamp_usec;            EasyPusher_PushFrame(fPusherHandle, &avFrame);        }       }    if (_mediatype == EASY_SDK_MEDIA_INFO_FLAG)    {        if((pbuf != NULL) && (fSourceMediaInfo == NULL))        {            fSourceMediaInfo = new EASY_MEDIA_INFO_T();            memcpy(fSourceMediaInfo, pbuf, sizeof(EASY_MEDIA_INFO_T));        }    }    return 0;}

下载

EasyDarwin服务器下载:https://github.com/EasyDarwin/EasyDarwin或者国内镜像http://git.oschina.net/easydarwin/EasyDarwin
EasyPusher 下载:https://github.com/EasyDarwin/EasyPusher

获取更多信息

邮件:support@easydarwin.org

WEB:www.EasyDarwin.org

QQ交流群:465901074

Copyright © EasyDarwin.org 2012-2017

EasyDarwin

阅读全文
0 0