所有網絡流轉換通用SDK EasyStream

EasyStream介紹
EasyStream SDK使用
EasyStream系列1之rtsp轉rtmp
EasyStream系列2之rtmp轉rtsp
EasyStream系列3之rtsp轉rtsp
EasyStream系列4之rtmp轉rtmp
EasyStream系列5之本地文件轉rtsp
EasyStream系列6之本地文件轉rtmp
EasyStream系列7之錄製rtsp流
EasyStream系列8之錄製rtmp流
EasyStream系列9之directshow轉rtsp
EasyStream系列10之directshow轉rtmp
EasyStream系列11之錄製directshow視頻

所有網絡流轉換通用SDK EasyStream

這裏寫圖片描述
如上圖所示,EasyStream的sdk包含兩部分,一部分是拉流的sdk,另一部分是推流的sdk。sdk內部通過url標識來自動判斷推,拉流的協議。

拉流sdk

主要負責獲取rtsp,rtmp,本地視頻等音視頻數據,調用者通過視頻流回調函數獲取音視頻數據。

#ifndef _Pull_Stream_API_H
#define _Pull_Stream_API_H
#include "StreamType.h"
typedef int (STREAM_API_APICALL *PullStreamCallBack)(Pull_Stream_Handle handle,char *pBuf,int nlen,STREAM_FRAME_INFO *pInfo,void *pContext);
typedef int (STREAM_API_APICALL *PullStreamEventCallBack)(Pull_Stream_Handle handle,PULL_EVENT_TYPE event,void *pContext);



//拉流初始化,整個進程只調用一次
STREAM_API int STREAM_API_APICALL  PULL_StreamInit();   
//打開流,purl可以是rtmp,rtsp,本地mp4或ts
STREAM_API int STREAM_API_APICALL  PULL_OpenStream(Pull_Stream_Handle *handle, char *purl);
//關閉流
STREAM_API int STREAM_API_APICALL  PULL_CloseStream(Pull_Stream_Handle handle);
//設置音視頻數據流回調
STREAM_API int STREAM_API_APICALL  PULL_SetStreamCallback(Pull_Stream_Handle handle,PullStreamCallBack pCallback,void* pContext);
//設置音視頻流事件回調(上下線通知)
STREAM_API int STREAM_API_APICALL  PULL_SetStreamEventCallback(Pull_Stream_Handle handle,PullStreamEventCallBack pCallback,void* pContext);
//獲取上下文參數,供PUSH相關函數(PUSH_Init)使用
STREAM_API void * STREAM_API_APICALL  PULL_GetPullContext(Pull_Stream_Handle handle);
//獲取視頻參數信息
STREAM_API int STREAM_API_APICALL  PULL_GetVideoInfo(Pull_Stream_Handle handle, STREAM_VIDEO_INFO &videoInfo);
//獲取音頻參數信息
STREAM_API int STREAM_API_APICALL  PULL_GetAudioInfo(Pull_Stream_Handle handle, STREAM_AUDIO_INFO &audioInfo);


#endif

推流SDK

主要負責將獲取到的音視頻流數據以rtsp,rtmp方式推送到流媒體服務器上,或者保存到本地。

#ifndef _Push_Stream_API_H
#define _Push_Stream_API_H
#include "StreamType.h"

typedef int (STREAM_API_APICALL *PushStreamEventCallBack)(Push_Stream_Handle handle,PUSH_EVENT_TYPE event,void* pContext);

//推送初始化,整個進程只調用一次
STREAM_API int STREAM_API_APICALL  PUSH_StreamInit();   
//設置推送地址,注意pullcontext是PULL_GetPullContext獲取到的上下文
STREAM_API bool STREAM_API_APICALL PUSH_Init(Push_Stream_Handle *handle,char*pDest,void *pullContext);
//設置推送事件,推送過程中服務器掉線或上線都有提示
STREAM_API int STREAM_API_APICALL  PUSH_SetEventCallback(Push_Stream_Handle handle,PushStreamEventCallBack pCallback,void *pullContext);
//推送視頻
STREAM_API bool STREAM_API_APICALL PUSH_PushVideoData(Push_Stream_Handle handle,char *pBuffer,int nlen,long long pts,long long dts,bool bKey);
//推送音頻
STREAM_API bool STREAM_API_APICALL PUSH_PushAudioData(Push_Stream_Handle handle,char *pBuffer,int nlen,long long pts,long long dts);
//釋放資源
STREAM_API bool STREAM_API_APICALL PUSH_Uninit(Push_Stream_Handle handle);
#endif

sdk如何使用?

sdk使用方法非常簡單,詳見如下代碼。使用者只需要使用一套sdk,就能完成rtsp,rtmp,本地文件之間的相互轉發。

#include "PullStreamAPI.h"
#include "PushStreamAPI.h"
Pull_Stream_Handle pullHandle = NULL;
Pull_Stream_Handle pullHandle2 = NULL;

Push_Stream_Handle  pushHandle = NULL;
Push_Stream_Handle  pushHandle2 = NULL;

int STREAM_API_APICALL StreamCallBack(Pull_Stream_Handle handle,char *pBuf,int nlen,STREAM_FRAME_INFO *pInfo,void *pContext);
int _tmain(int argc, _TCHAR* argv[])
{
    //初始化
    PUSH_StreamInit();
    PULL_StreamInit();

    //拉流
    int nret = PULL_OpenStream(&pullHandle,"rtmp://live.hkstv.hk.lxdns.com/live/hks");

    //推流(保存到本地)
    PUSH_Init(&pushHandle,"1.ts",PULL_GetPullContext(pullHandle));

    //從回調中獲取拉流數據
    PULL_SetStreamCallback(pullHandle,StreamCallBack,NULL);

    getchar();
    return 0;
}

int STREAM_API_APICALL StreamCallBack(Pull_Stream_Handle handle, char *pBuf,int nlen,STREAM_FRAME_INFO *pInfo ,void *pContext)
{


    if (handle == pullHandle)
    {
        char buf[100] ={0};
        sprintf(buf,"======type:%d,size:%d,key:%d\n",pInfo->streamType,nlen,pInfo->bKey);
        printf(buf);
        if (pInfo->streamType == emStreamVideo)
        {
            //推送視頻數據
            PUSH_PushVideoData(pushHandle,pBuf,nlen,pInfo->pts,pInfo->dts,pInfo->bKey);
        }
        else if (pInfo->streamType == emStreamAudio)
        {
            //推送音頻數據
            PUSH_PushAudioData(pushHandle,pBuf,nlen,pInfo->pts,pInfo->dts);
        }

    }
    return 0;
}


軟件下載地址

http://download.csdn.net/download/sunxiaopengsun/10244537

sdk下載地址

http://download.csdn.net/download/sunxiaopengsun/10244548
歡迎加入qq 136414264羣討論

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章