!501 提交metartc hap cpp/include/yangplayer目录下代码

Merge pull request !501 from ohms9108/commit05
This commit is contained in:
强盗偷夜壶 2024-11-22 09:36:05 +00:00 committed by Gitee
commit 4e1370df6e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
45 changed files with 1927 additions and 0 deletions

View File

@ -0,0 +1,75 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANG_CONFIG_H_
#define INCLUDE_YANG_CONFIG_H_
#include "yang_config_os.h"
#define Yang_Enable_Datachannel 1
#define Yang_Enable_Openh264 1
#define Yang_Enable_Json 1
#if Yang_OS_WIN
#define Yang_Enable_Openssl 1
#define Yang_Enable_GPU_Encoding 0
#define Yang_Enable_Phtread 0
#else
#define Yang_Enable_Openssl 1
#define Yang_Enable_GPU_Encoding 0
#define Yang_Enable_Phtread 1
#endif
#define Yang_StreamName_Lenght 128
#define Yang_Enable_H265_Encoding 1
#define Yang_Enable_MJpeg_Encoding 0
#define Yang_Enable_AV1_Encoding 0
#define Yang_Enable_RTC_Audio 1
#define Yang_Enable_RTC_Video 1
#define Yang_Enable_Tcp_Srs 1
#define Yang_Enable_Embbed 0
#define Yang_Enable_10bit 0
#define Yang_Enable_Dtls 1 //default:using dtls
#define Yang_Enable_TWCC 0
#if Yang_OS_WIN
#define Yang_Enable_H264Decoder 0
#define Yang_Enable_H264Decoder_So 1
#define Yang_Enable_FfmpegSo 0
#else
#define Yang_Enable_H264Decoder 1
#if !Yang_OS_ANDROID
#define Yang_Enable_H264Decoder_So 0
#else
#define Yang_Enable_H264Decoder_So 0
#endif
#define Yang_Enable_FfmpegSo 0
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
#define Yang_Little_Endian 0
#else
#define Yang_Little_Endian 1
#endif
#define Yang_Enable_Timer_Phtread 0
#define Yang_Enable_Ffmpeg_Codec 1
//option lib
#define Yang_Enable_PicUtilFfmpeg 0
#define Yang_Enable_Websockets 1 //using libwebsockets
#define Yang_Enable_Curl 0 //using libcurl
#define Yang_Enable_RtcpXr 0
#define Yang_Rtp_I_Withmeta 0
#define Yang_CTimer_Epoll_Timeout 200
#endif /* INCLUDE_YANG_CONFIG_H_ */

View File

@ -0,0 +1,98 @@
//
// Copyright (c) 2019-2023 yanggaofeng
//
#ifndef INCLUDE_YANGJSON_YANGJSON_H_
#define INCLUDE_YANGJSON_YANGJSON_H_
#include <yangutil/yangtype.h>
typedef struct YangJson
{
struct YangJson *next;
struct YangJson *prev;
struct YangJson *child;
int type;
char *valuestring;
int valueint;
double valuedouble;
char *string;
uint8_t* outString;
} YangJson;
typedef struct{
YangJson* session;
int (*getArraySize)(const YangJson *array);
YangJson * (*getArrayItem)(const YangJson *array, int index);
YangJson * (*getObjectItem)(const YangJson * const object, const char * const string);
YangJson * (*getObjectItemCaseSensitive)(const YangJson * const object, const char * const string);
yangbool (*hasObjectItem)(const YangJson *object, const char *string);
const char * (*getErrorPtr)(void);
char * (*getStringValue)(const YangJson * const item);
double (*getNumberValue)(const YangJson * const item);
yangbool (*isInvalid)(const YangJson * const item);
yangbool (*isFalse)(const YangJson * const item);
yangbool (*isTrue)(const YangJson * const item);
yangbool (*isBool)(const YangJson * const item);
yangbool (*isNull)(const YangJson * const item);
yangbool (*isNumber)(const YangJson * const item);
yangbool (*isString)(const YangJson * const item);
yangbool (*isArray)(const YangJson * const item);
yangbool (*isObject)(const YangJson * const item);
yangbool (*isRaw)(const YangJson * const item);
}YangJsonReader;
typedef struct{
YangJson* session;
YangJson * (*createNull)(void);
YangJson * (*createTrue)(void);
YangJson * (*createFalse)(void);
YangJson * (*createBool)(yangbool boolean);
YangJson * (*createNumber)(double num);
YangJson * (*createString)(const char *string);
YangJson* (*createRaw)(const char *raw);
YangJson* (*createArray)(void);
YangJson* (*createObject)(void);
YangJson* (*addNullToObject)(YangJson * const object, const char * const name);
YangJson* (*addTrueToObject)(YangJson * const object, const char * const name);
YangJson* (*addFalseToObject)(YangJson * const object, const char * const name);
YangJson* (*addBoolToObject)(YangJson * const object, const char * const name, const yangbool boolean);
YangJson* (*addNumberToObject)(YangJson * const object, const char * const name, const double number);
YangJson* (*addStringToObject)(YangJson * const object, const char * const name, const char * const string);
YangJson* (*addRawToObject)(YangJson * const object, const char * const name, const char * const raw);
YangJson* (*addObjectToObject)(YangJson * const object, const char * const name);
YangJson* (*addArrayToObject)(YangJson * const object, const char * const name);
char * (*print)(YangJson *item);
char * (*printUnformatted)(YangJson *item);
char * (*printBuffered)(YangJson *item, int prebuffer, yangbool fmt);
//void (*free)(void *object);
}YangJsonWriter;
#ifdef __cplusplus
extern "C"{
#endif
int32_t yang_create_jsonReader(YangJsonReader* reader,char* jsonStr);
void yang_destroy_jsonReader(YangJsonReader* reader);
int32_t yang_create_jsonWriter(YangJsonWriter* writer);
void yang_destroy_jsonWriter(YangJsonWriter* writer);
#ifdef __cplusplus
}
#endif
#endif /* INCLUDE_YANGJSON_YANGJSON_H_ */

View File

@ -0,0 +1,20 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef YANGPLAYER_INCLUDE_YANGPLAYFACTORY_H_
#define YANGPLAYER_INCLUDE_YANGPLAYFACTORY_H_
#include <yangaudiodev/YangAudioPlay.h>
enum YangAudioPlayType{
Yang_AP_SDL,
Yang_AP_ALSA,
};
class YangPlayFactory {
public:
YangPlayFactory();
virtual ~YangPlayFactory();
YangAudioPlay* createAudioPlay(YangAudioInfo *pcontext);
YangAudioPlay *createAudioPlay(YangAudioPlayType paet,YangAudioInfo *pcontext);
};
#endif /* YANGPLAYER_INCLUDE_YANGPLAYFACTORY_H_ */

View File

@ -0,0 +1,34 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef MeetingPlayoBase_H
#define MeetingPlayoBase_H
#include <yangplayer/YangPlayerDecoder.h>
#include <yangplayer/YangPlayerPlay.h>
#include <vector>
#include "yangutil/buffer/YangAudioEncoderBuffer.h"
#include "yangutil/buffer/YangAudioPlayBuffer.h"
#include "yangutil/buffer/YangVideoDecoderBuffer.h"
using namespace std;
class YangPlayerBase
{
public:
YangPlayerBase();
virtual ~YangPlayerBase();
YangPlayerDecoder *m_ydb;
YangPlayerPlay *m_ypb;
void startAudioDecoder(YangAudioEncoderBuffer *prr);
void startVideoDecoder(YangVideoDecoderBuffer *prr);
void init(YangContext* audio);
void startAudioPlay(YangContext* paudio);
void stopAll();
protected:
private:
};
#endif // ZBBASE_H

View File

@ -0,0 +1,39 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef YANGAPP_YANGDECODERAPP_H_
#define YANGAPP_YANGDECODERAPP_H_
#include <yangdecoder/YangAudioDecoderHandle.h>
#include <yangdecoder/YangVideoDecoderHandle.h>
#include <vector>
using namespace std;
class YangPlayerDecoder {
public:
YangPlayerDecoder(YangContext* pcontext);
virtual ~YangPlayerDecoder();
void initAudioDecoder(YangAudioPlayBuffer* metaAudioPlayBuffer);
void initVideoDecoder();
void setInVideoBuffer(YangVideoDecoderBuffer *pvel);
void setInAudioBuffer(YangAudioEncoderBuffer *pael);
YangVideoBuffer* getOutVideoBuffer();
YangAudioPlayBuffer* getOutAudioBuffer();
void startAudioDecoder();
void startVideoDecoder();
void setRoomState(int32_t pst);
void stopAll();
YangVideoDecoderHandle *m_videoDec;
private:
YangContext *m_context;
YangVideoBuffer* m_out_videoBuffer;
YangAudioPlayBuffer* m_out_audioBuffer;
YangAudioDecoderHandle *m_audioDec;
};
#endif /* YANGAPP_YANGDECODERAPP_H_ */

View File

@ -0,0 +1,22 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGPLAYER_YANGPLAYERHANDLE_H_
#define INCLUDE_YANGPLAYER_YANGPLAYERHANDLE_H_
#include <yangutil/buffer/YangVideoBuffer.h>
#include <yangutil/sys/YangSysMessageI.h>
#include <yangutil/yangavinfotype.h>
class YangPlayerHandle {
public:
YangPlayerHandle(){};
virtual ~YangPlayerHandle(){};
virtual YangVideoBuffer* getVideoBuffer()=0;
virtual int play(char* url)=0;
virtual int32_t playRtc(int32_t puid,char* localIp, char* server, int32_t pport,char* app,char* stream)=0;
virtual int32_t playRtc(int32_t puid,char* url)=0;
virtual void stopPlay()=0;
static YangPlayerHandle* createPlayerHandle(YangContext* pcontext,YangSysMessageI* pmessage);
};
#endif /* INCLUDE_YANGPLAYER_YANGPLAYERHANDLE_H_ */

View File

@ -0,0 +1,51 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef YANGAPP_YANGPLAYAPP_H_
#define YANGAPP_YANGPLAYAPP_H_
#include <yangutil/buffer/YangAudioPlayBuffer.h>
#include <yangutil/buffer/YangVideoBuffer.h>
#include <yangavutil/audio/YangRtcAec.h>
#include <yangdecoder/YangVideoDecoderHandles.h>
#include <yangaudiodev/linux/YangAudioPlayLinux.h>
#include <yangaudiodev/mac/YangAudioPlayMac.h>
#include <yangaudiodev/win/YangWinAudioApiRender.h>
#include <yangaudiodev/android/YangAudioPlayAndroid.h>
#include <vector>
using namespace std;
class YangPlayerPlay {
public:
YangPlayerPlay();
virtual ~YangPlayerPlay();
void initAudioPlay(YangContext* paudio);
void startAudioPlay();
void setInAudioList(YangAudioPlayBuffer *paudioList);
void stopAll();
private:
#if Yang_OS_WIN
YangWinAudioApiRender *m_audioPlay;
#else
#if Yang_OS_ANDROID
YangAudioPlayAndroid *m_audioPlay;
#else
#if Yang_OS_APPLE
YangAudioPlayMac *m_audioPlay;
#else
YangAudioPlayLinux *m_audioPlay;
#endif
#endif
#endif
int32_t vm_audio_player_start;
};
#endif /* YANGAPP_YANGPLAYAPP_H_ */

View File

@ -0,0 +1,42 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef YANGPLAYER_INCLUDE_YANGWINPLAYFACTROY_H_
#define YANGPLAYER_INCLUDE_YANGWINPLAYFACTROY_H_
#include <yangutil/yangavinfotype.h>
class YangPainter{
public:
YangPainter();
virtual ~YangPainter();
virtual void draw(void *win,YangRect *prect,YangColor *pcolor)=0;
};
class YangWinPlay{
public:
YangWinPlay();
virtual ~YangWinPlay();
virtual void init(void* pid)=0;
virtual void initBg(int32_t pwid,int32_t phei)=0;
virtual void initVideo(int32_t pwid,int32_t phei,YangYuvType sdfe)=0;
virtual void initText(char *pname,YangColor *pcolor)=0;
virtual void reInitVideo(int32_t pwid,int32_t phei,YangYuvType sdfe)=0;
virtual void reInitText(char *pname,YangColor *pcolor)=0;
virtual void renderPreview(uint8_t* pdata)=0;
virtual void render(uint8_t* pdata)=0;
virtual void render(uint8_t* pdata,int64_t ptimestamp)=0;
virtual void renderBg(YangColor *pcolor)=0;
int32_t m_width,m_height;
};
class YangWinPlayFactroy {
public:
YangWinPlayFactroy();
virtual ~YangWinPlayFactroy();
YangPainter *createPainter();
YangWinPlay *createWinPlay();
};
#endif /* YANGPLAYER_INCLUDE_YANGWINPLAYFACTROY_H_ */

View File

@ -0,0 +1,90 @@

//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef YANGAPP_YangPushCapture_H_
#define YANGAPP_YangPushCapture_H_
#include <yangutil/yangtype.h>
#include <yangaudiodev/YangAudioCapture.h>
#include <yangutil/sys/YangThread2.h>
#include <yangcapture/YangMultiVideoCapture.h>
#include <yangcapture/YangScreenCapture.h>
#include <yangutil/buffer/YangAudioBuffer.h>
#include <yangutil/buffer/YangVideoBuffer.h>
#include <yangavutil/audio/YangRtcAec.h>
#include <yangutil/buffer/YangAudioPlayBuffer.h>
class YangPushCapture :public YangThread {
public:
YangPushCapture(YangContext *pcontext);
virtual ~YangPushCapture();
public:
void startCamera();
void stopCamera();
void setScreenInterval(int32_t pinterval);
void setDrawmouse(bool isDraw);
void startVideoCaptureState();
void startScreenCaptureState();
void stopVideoCaptureState();
void stopScreenCaptureState();
int32_t initVideo();
void startVideoCapture();
void startScreenCapture();
YangVideoBuffer * getOutVideoBuffer();
YangVideoBuffer * getPreVideoBuffer();
YangVideoBuffer * getScreenOutVideoBuffer();
YangVideoBuffer * getScreenPreVideoBuffer();
void stopAll();
void change(int32_t st);
#if Yang_Enable_Vr
void addVr();
void delVr();
#endif
private:
YangAudioCapture *m_audioCapture;
YangMultiVideoCapture *m_videoCapture;
YangVideoBuffer *m_out_videoBuffer;
YangVideoBuffer *m_pre_videoBuffer;
YangVideoBuffer *m_screen_pre_videoBuffer;
YangVideoBuffer *m_screen_out_videoBuffer;
YangScreenCapture* m_screenCapture;
YangContext *m_context;
YangAudioBuffer *m_out_audioBuffer;
#if Yang_Enable_Vr
YangVideoBuffer *m_out_vr_pre_videoBuffer;
#endif
public:
void stop();
int32_t m_isStart;
protected:
void run();
#if Yang_Enable_Vr
void startLoop();
#else
void startLoop(){};
#endif
void stopLoop();
void initVr();
int32_t m_isConvert;
public:
int32_t initAudio(YangPreProcess *pp);
void startAudioCapture();
YangAudioBuffer* getOutAudioBuffer();
void stopAudioCaptureState();
void startAudioCaptureState();
void setAec(YangRtcAec *paec);
void setInAudioBuffer(vector<YangAudioPlayBuffer*> *pbuf);
};
#endif /* YANGAPP_YANGCAPTUREAPP_H_ */

View File

@ -0,0 +1,28 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGPUSH_YANGPUSHCOMMON_H_
#define INCLUDE_YANGPUSH_YANGPUSHCOMMON_H_
#define Yang_VideoSrc_Camera 0
#define Yang_VideoSrc_Screen 1
#define Yang_VideoSrc_OutInterface 2
enum YangPushMessageType {
YangM_Push_StartAudioCapture,
YangM_Push_StartVideoCapture,
YangM_Push_StartScreenCapture,
YangM_Push_StartOutCapture,
YangM_Push_Connect,
YangM_Push_Connect_Whip,
YangM_Push_Disconnect,
YangM_Push_Record_Start,
YangM_Push_Record_Stop,
YangM_Push_SwitchToCamera,
YangM_Push_SwitchToScreen,
YangM_Sys_Setvr,
YangM_Sys_UnSetvr
};
#endif /* INCLUDE_YANGPUSH_YANGPUSHCOMMON_H_ */

View File

@ -0,0 +1,19 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGPUSH_YANGPUSHFACTORY_H_
#define INCLUDE_YANGPUSH_YANGPUSHFACTORY_H_
#include <yangpush/YangPushHandle.h>
#include <yangutil/sys/YangSysMessageHandle.h>
#include <yangpush/YangSendVideoI.h>
class YangPushFactory {
public:
YangPushFactory();
virtual ~YangPushFactory();
YangPushHandle* createPushHandle(bool hasAudio,bool initVideo,int pvideotype,YangVideoInfo *screenvideo, YangVideoInfo *outvideo,YangContext* pcontext,YangSysMessageI* pmessage);
YangSysMessageHandle* createPushMessageHandle(bool hasAudio,bool initVideo,int pvideotype,YangVideoInfo *screenvideo, YangVideoInfo *outvideo,YangContext* pcontext,YangSysMessageI* pmessage,YangSysMessageHandleI* pmessagehandle);
YangVideoBuffer* getPreVideoBuffer(YangSysMessageHandle* pmessageHandle);
YangSendVideoI* getSendVideo(YangSysMessageHandle* pmessageHandle);
};
#endif /* INCLUDE_YANGPUSH_YANGPUSHFACTORY_H_ */

View File

@ -0,0 +1,29 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGPUSH_YANGPUSHHANDLE_H_
#define INCLUDE_YANGPUSH_YANGPUSHHANDLE_H_
#include <yangutil/buffer/YangVideoBuffer.h>
#include <yangutil/yangavinfotype.h>
#include <yangutil/sys/YangSysMessageI.h>
#include <yangpush/YangPushCommon.h>
#include <yangpush/YangSendVideoI.h>
#include <string>
class YangPushHandle {
public:
YangPushHandle();
virtual ~YangPushHandle();
virtual int publish(char* url,yangbool isWhip)=0;
virtual void disconnect()=0;
virtual void init()=0;
virtual void changeSrc(int videoSrcType,bool pisinit)=0;
virtual YangVideoBuffer* getPreVideoBuffer()=0;
virtual YangSendVideoI* getSendVideo()=0;
};
#endif /* INCLUDE_YANGPUSH_YANGPUSHHANDLE_H_ */

View File

@ -0,0 +1,78 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef YangPushPublish_H
#define YangPushPublish_H
#include <yangutil/buffer/YangAudioEncoderBuffer.h>
#include <yangutil/buffer/YangVideoEncoderBuffer.h>
#include <yangutil/buffer/YangAudioBuffer.h>
#include <yangutil/buffer/YangVideoBuffer.h>
#include <yangpush/YangPushCapture.h>
#include <yangpush/YangPushEncoder.h>
#include <yangpush/YangRtcPublish.h>
class YangPushPublish: public YangSendRequestCallback {
public:
YangPushPublish(YangContext *pcontext);
virtual ~YangPushPublish();
void setCaptureType(int pct);
void startCamera();
void stopCamera();
void setScreenInterval(int32_t pinterval);
void setDrawmouse(bool isDraw);
void setRtcNetBuffer(YangRtcPublish *prr, YangVideoEncoderBuffer *in_VideoBuffer);
void startPubVideo();
void startPubAudio();
void initAudioEncoding();
void initVideoEncoding();
void setVideoInfo(YangVideoInfo *pvideo);
int32_t startAudioCapture();
int32_t startVideoCapture();
void initVideoMeeting();
void startAudioEncoding();
void startVideoEncoding();
void deleteVideoEncoding();
void startAudioCaptureState();
void startVideoCaptureState();
void stopAudioCaptureState();
void stopVideoCaptureState();
void stopScreenCaptureState();
YangVideoBuffer* getPreVideoBuffer();
YangVideoBuffer* getOutPreVideoBuffer();
YangVideoBuffer* getOutVideoBuffer();
void stopAll();
void setInAudioBuffer(vector<YangAudioPlayBuffer*> *pbuf);
void change(int32_t st);
void sendRequest(int32_t puid, uint32_t ssrc, YangRequestType req);
void sendMsgToEncoder(YangRequestType req);
YangPushCapture* getPushCapture();
protected:
private:
YangVideoBuffer* m_outVideoBuffer;
YangVideoBuffer* m_outPreVideoBuffer;
private:
YangContext *m_context;
YangPushEncoder *m_encoder;
YangPushCapture *m_capture;
YangVideoInfo *m_videoInfo;
int32_t isStartAudioCapture, isStartVideoCapture, isStartScreenCapture;
int32_t isStartAudioEncoder, isStartVideoEncoder;
void stopAudioState();
void stopVideoState();
void initCapture();
int m_captureType;
};
#endif //

View File

@ -0,0 +1,57 @@

//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef SRC_YANGMEETING_INCLUDE_YangRtcPublish_H_
#define SRC_YANGMEETING_INCLUDE_YangRtcPublish_H_
#include <yangrtc/YangPeerConnection2.h>
#include <string>
#include <yangutil/sys/YangThread2.h>
#include <yangutil/sys/YangSysMessageI.h>
#include <yangutil/buffer/YangAudioEncoderBuffer.h>
#include <yangutil/buffer/YangVideoEncoderBuffer.h>
#include <vector>
using namespace std;
class YangRtcPublish: public YangThread {
public:
YangRtcPublish(YangContext *pcontext);
virtual ~YangRtcPublish();
int32_t init(char* url);
int32_t init(int32_t nettype, char* server, int32_t pport,char* app,char* stream);
int32_t connectServer(int32_t puid);
int32_t connectMediaServer();
int32_t disConnectMediaServer();
int32_t reconnectMediaServer();
void setInVideoMetaData(YangVideoMeta *pvmd);
void setInAudioList(YangAudioEncoderBuffer *pbuf);
void setInVideoList(YangVideoEncoderBuffer *pbuf);
int32_t stopPublishAudioData();
int32_t stopPublishVideoData();
int32_t publishMsg(YangFrame* msgFrame);
int32_t receiveMsg(YangFrame* msgFrame);
int32_t m_netState;
int32_t isPublished;
int32_t m_isStart;
void stop();
protected:
void run();
void handleError(int32_t perrCode);
void startLoop();
void startLoop_h265();
YangContext *m_context;
YangVideoMeta *m_vmd;
YangVideoEncoderBuffer *m_in_videoBuffer;
YangAudioEncoderBuffer *m_in_audioBuffer;
int32_t m_isConvert;
int32_t m_isInit;
int32_t m_audioEncoderType;
std::vector<YangPeerConnection2*> m_pushs;
private:
int32_t m_transType;
int32_t notifyState;
};
#endif /* SRC_YANGMEETING_INCLUDE_YangRtcPublish_H_ */

View File

@ -0,0 +1,18 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGPUSH_YANGSENDVIDEOI_H_
#define INCLUDE_YANGPUSH_YANGSENDVIDEOI_H_
#include <stdint.h>
class YangSendVideoI{
public:
YangSendVideoI(){};
virtual ~YangSendVideoI(){};
virtual void putVideoRgba(uint8_t* data,int len,int64_t timestamp)=0;
virtual void putVideoI420(uint8_t* data,int len,int64_t timestamp)=0;
};
#endif /* INCLUDE_YANGPUSH_YANGSENDVIDEOI_H_ */

View File

@ -0,0 +1,38 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGRTC_YANGMETACONNECTION_H_
#define INCLUDE_YANGRTC_YANGMETACONNECTION_H_
#include <yangutil/yangavctype.h>
typedef struct{
void *session;
void (*init)(void* session,int32_t sample,int32_t channel,int32_t echopath);
void (*closeAec)(void* session);
void (*echoCapture)(void* session,short *rec, short *out);
void (*preprocessRun)(void* session,short *pcm);
void (*echoStateReset)(void* session);
void (*echoPlayback)(void* session,short *play);
void (*echoCancellation)(void* session,const short *rec, const short *play,
short *out);
}YangAec;
typedef struct {
void* session;
void (*init)(void* session,YangStreamConfig* stream,void* user);
int32_t (*initParam)(void* session,char* url,YangStreamDirection opt);
void (*parseHeader)(YangVideoCodec codec,uint8_t *buf, uint8_t *src, int32_t *hLen);
int32_t (*connectSfuServer)(void* session,int32_t mediaServer);
int32_t (*close)(void* session);
void (*setExtradata)(void* session,YangVideoCodec codec,uint8_t *extradata,int32_t extradata_size);
int32_t (*on_audio)(void* session,YangFrame* audioFrame);
int32_t (*on_video)(void* session,YangFrame* videoFrame);
int32_t (*on_message)(void* session,YangFrame* videoFrame);
int32_t (*isConnected)(void* session);
int32_t (*recvvideoNotify)(void* session, YangRtcMessageType mess);
}YangMetaConnection;
void yang_create_metaConnection(YangMetaConnection* metaconn);
void yang_destroy_metaConnection(YangMetaConnection* metaconn);
void yang_create_aec(YangAec* aec);
void yang_destroy_aec(YangAec* aec);
#endif /* INCLUDE_YANGRTC_YANGMETACONNECTION_H_ */

View File

@ -0,0 +1,53 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGRTC_YANGPEERCONNECTION_H_
#define INCLUDE_YANGRTC_YANGPEERCONNECTION_H_
#include <yangutil/yangavinfotype.h>
typedef struct{
void* conn;
YangAVInfo* avinfo;
YangStreamConfig streamconfig;
}YangPeer;
typedef struct {
YangPeer peer;
void (*init)(YangPeer* peer);
YangIceCandidateType (*getIceCandidateType)(YangPeer* peer);
int32_t (*createOffer)(YangPeer* peer, char **psdp);
int32_t (*createAnswer)(YangPeer* peer,char* answer);
int32_t (*createHttpAnswer)(YangPeer* peer,char* answer);
int32_t (*setRemoteDescription)(YangPeer* peer,char* sdp);
int32_t (*connectSfuServer)(YangPeer* peer);//srs zlm
int32_t (*connectWhipWhepServer)(YangPeer* peer,char* url);
int32_t (*close)(YangPeer* peer);
yangbool (*isAlive)(YangPeer* peer);
yangbool (*isConnected)(YangPeer* peer);
YangRtcConnectionState (*getConnectionState)(YangPeer* peer);
int32_t (*on_audio)(YangPeer* peer,YangFrame* audioFrame);
int32_t (*on_video)(YangPeer* peer,YangFrame* videoFrame);
int32_t (*on_message)(YangPeer* peer,YangFrame* msgFrame);
int32_t (*sendRtcMessage)(YangPeer* peer, YangRtcMessageType mess);
}YangPeerConnection;
#ifdef __cplusplus
extern "C"{
#endif
void yang_create_peerConnection(YangPeerConnection* peerconn);
void yang_destroy_peerConnection(YangPeerConnection* peerconn);
int32_t yang_p2p_getHttpSdp(YangIpFamilyType familyType,char* httpIp,int32_t httpPort,char* localSdp,char* remoteSdp);
#ifdef __cplusplus
}
#endif
#endif /* INCLUDE_YANGRTC_YANGPEERCONNECTION_H_ */

View File

@ -0,0 +1,41 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGRTC_YANGPEERCONNECTION2_H_
#define INCLUDE_YANGRTC_YANGPEERCONNECTION2_H_
#include <yangrtc/YangPeerConnection.h>
class YangPeerConnection2 {
public:
YangPeerConnection2(YangAVInfo* avinfo,YangStreamConfig* streamConfig);
virtual ~YangPeerConnection2();
YangStreamConfig* streamConfig;
public:
void init();
//int32_t requestStunServer();
//int32_t requestTurnServer();
int32_t createOffer( char **psdp);
int32_t createAnswer(char* answer);
int32_t createHttpAnswer(char* answer);
int32_t setRemoteDescription(char* sdp);
int32_t connectSfuServer();//srs zlm
int32_t connectWhipServer(char* url);
int32_t close();
int32_t isAlive();
int32_t isConnected();
int32_t on_audio(YangFrame* audioFrame);
int32_t on_video(YangFrame* videoFrame);
int32_t on_message(YangFrame* msgFrame);
int32_t sendRtcMessage( YangRtcMessageType mess);
private:
YangPeerConnection m_conn;
};
#endif /* INCLUDE_YANGRTC_YANGPEERCONNECTION2_H_ */

View File

@ -0,0 +1,49 @@
/*
* YangSslMbedssl.h
*
* Created on: 2022725
* Author: yang
*/
#ifndef INCLUDE_YANGSSL_YANGMBEDTLS_H_
#define INCLUDE_YANGSSL_YANGMBEDTLS_H_
#include <yangutil/yangtype.h>
#include <stdint.h>
#if !Yang_Enable_Openssl
#if Yang_Enable_Dtls
#include <mbedtls/version.h>
#include <mbedtls/ssl.h>
#define Yang_SHA256_Length 32
#if (MBEDTLS_VERSION_NUMBER>0x03000000)
#define Yang_Mbedtls_3 1 //0:mbedtls2.0 1:mbedtls3.0
#else
#define Yang_Mbedtls_3 0 //0:mbedtls2.0 1:mbedtls3.0
#endif
typedef struct{
char fingerprint[128];
yangbool ecdsa_mode;
mbedtls_x509_crt *dtls_cert;
mbedtls_pk_context *dtls_pkey;
}YangCertificate;
#ifdef __cplusplus
extern "C"{
#endif
int32_t yang_hmac_encode(const char* algo, const char* key, const int32_t key_length,
const char* input, const int32_t input_length, char* output, uint32_t* output_length);
int32_t yang_ssl_md5(const uint8_t* keystr,size_t keystrLen,uint8_t* str);
int32_t yang_create_certificate(YangCertificate* cer);
void yang_destroy_certificate(YangCertificate* cer);
void g_yang_create_srtp();
void g_yang_destroy_srtp();
#ifdef __cplusplus
}
#endif
#endif
#endif
#endif /* INCLUDE_YANGSSL_YANGMBEDTLS_H_ */

View File

@ -0,0 +1,44 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGSSL_YANGOPENSSL_H_
#define INCLUDE_YANGSSL_YANGOPENSSL_H_
#include <yangutil/yangtype.h>
#if Yang_Enable_Openssl
#if Yang_Enable_Dtls
#include <openssl/ssl.h>
typedef struct{
int32_t ecdsa_mode;
X509* dtls_cert;
EVP_PKEY* dtls_pkey;
EC_KEY* eckey;
char fingerprint[128];
}YangCertificate;
#ifdef __cplusplus
extern "C"{
#endif
int32_t yang_hmac_encode(const char* algo, const char* key, const int32_t key_length,
const char* input, const int32_t input_length, char* output, uint32_t* output_length);
int32_t yang_ssl_md5(const uint8_t* keystr,size_t keystrLen,uint8_t* key);
int32_t yang_create_certificate(YangCertificate* cer);
void yang_destroy_certificate(YangCertificate* cer);
void g_yang_create_srtp();
void g_yang_destroy_srtp();
#ifdef __cplusplus
}
#endif
#endif
#endif
#endif /* INCLUDE_YANGSSL_YANGOPENSSL_H_ */

View File

@ -0,0 +1,16 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGSSL_YANGSSL_H_
#define INCLUDE_YANGSSL_YANGSSL_H_
#include <yangutil/yangtype.h>
#if Yang_Enable_Openssl
#include <yangssl/YangOpenssl.h>
#else
#include <yangssl/YangMbedtls.h>
#endif
void* yang_get_global_certificate();
void yang_destroy_global_certificate();
#endif /* INCLUDE_YANGSSL_YANGSSL_H_ */

View File

@ -0,0 +1,47 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGSTREAM_YANGSTREAM_H_
#define INCLUDE_YANGSTREAM_YANGSTREAM_H_
#include <yangutil/yangtype.h>
#include <yangstream/YangStreamCapture.h>
#include <yangutil/yangavinfotype.h>
#include "YangStreamType.h"
typedef struct{
int32_t mediaServer;
int32_t transtype;
int32_t streamInit;
int32_t uid;
int32_t audioStream;
int32_t videoStream;
int32_t netState;
void* context;
YangAVInfo* avinfo;
YangStreamConfig streamconfig;
}YangStreamContext;
typedef struct {
YangStreamContext* context;
int32_t (*connectServer)(YangStreamContext* context);
int32_t (*disConnectServer)(YangStreamContext* context);
int32_t (*reconnect)(YangStreamContext* context);
int32_t (*receiveData)(YangStreamContext* context,int32_t *plen);
int32_t (*publishAacheader)(YangStreamContext* context,YangFrame *audioFrame);
int32_t (*publishVideoData)(YangStreamContext* context,YangStreamCapture *videoFrame);
int32_t (*publishAudioData)(YangStreamContext* context,YangStreamCapture *audioFrame);
int32_t (*publishMsg)(YangStreamContext* context,YangFrame *msgFrame);
int32_t (*getConnectState)(YangStreamContext* context);
int32_t (*isconnected)(YangStreamContext* context);
int32_t (*isAlive)(YangStreamContext* context);
int32_t (*sendRtcMessage)(YangStreamContext* context,YangRtcMessageType mess);
}YangStreamHandle;
#ifdef __cplusplus
extern "C"{
#endif
void yang_create_stream(int32_t mediaServer,int32_t transType,YangStreamHandle* streamHandle,YangStreamConfig* streamconfig,YangAVInfo* avinfo) ;
void yang_destroy_stream(YangStreamHandle* stream);
#ifdef __cplusplus
}
#endif
#endif /* INCLUDE_YANGSTREAM_YANGSTREAM_H_ */

View File

@ -0,0 +1,46 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGSTREAM_YANGSTREAMCAPTURE_H_
#define INCLUDE_YANGSTREAM_YANGSTREAMCAPTURE_H_
#include <stdint.h>
#include <yangutil/yangavtype.h>
typedef struct{
void* context;
uint8_t* (*getVideoData)(void* pcontext);
int32_t (*getVideoLen)(void* pcontext);
int32_t (*getVideoFrametype)(void* pcontext);
int64_t (*getVideoTimestamp)(void* pcontext);
uint8_t* (*getAudioData)(void* pcontext);
int32_t (*getAudioLen)(void* pcontext);
int64_t (*getAudioTimestamp)(void* pcontext);
YangAudioCodec (*getAudioType)(void* pcontext);
void (*initVideo)(void* pcontext,int32_t transtype);
void (*setVideoData)(void* pcontext,YangFrame *videoFrame, YangVideoCodec videoType);
void (*setVideoMeta)(void* pcontext,uint8_t *p, int32_t plen, YangVideoCodec videoType);
void (*setMetaTimestamp)(void* pcontext,int64_t timestamp);
void (*setVideoFrametype)(void* pcontext,int32_t frametype);
void (*setAudioData)(void* pcontext,YangFrame *audioFrame);
void (*setAudioMetaData)(void* pcontext,uint8_t *p, int32_t plen);
void (*setAudioFrametype)(void* pcontext,int32_t frametype);
void (*initAudio)(void* pcontext,int32_t transType,int32_t sample,int32_t channel,YangAudioCodec audioType);
YangFrame* (*getVideoFrame)(void* pcontext);
YangFrame* (*getAudioFrame)(void* pcontext);
}YangStreamCapture;
#ifdef __cplusplus
extern "C"{
#endif
void yang_create_streamCapture(YangStreamCapture* stream);
void yang_destroy_streamCapture(YangStreamCapture* stream);
#ifdef __cplusplus
}
#endif
#endif /* INCLUDE_YANGSTREAM_YANGSTREAMCAPTURE_H_ */

View File

@ -0,0 +1,12 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef YANGSTREAM_INCLUDE_YANGSTREAMBASE_H_
#define YANGSTREAM_INCLUDE_YANGSTREAMBASE_H_
#include <yangstream/YangStream.h>
void yang_create_streamHandle(YangStreamHandle* streamHandle,YangStreamConfig* streamconfig,YangAVInfo* pcontext);
void yang_destroy_streamHandle(YangStreamHandle* stream);
#endif /* YANGSTREAM_INCLUDE_YANGSTREAMBASE_H_ */

View File

@ -0,0 +1,54 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGSTREAM_YANGSTREAMMANAGER1_H_
#define INCLUDE_YANGSTREAM_YANGSTREAMMANAGER1_H_
#include <yangstream/YangStreamType.h>
#include <yangstream/YangSynBuffer.h>
#include <yangstream/YangSynBufferManager.h>
#include <vector>
class YangStreamStateNotify{
public:
YangStreamStateNotify(){};
virtual ~YangStreamStateNotify(){};
virtual void streamStateNotify(int32_t puid,YangStreamDirection opt,bool isConnect)=0;
};
class YangStreamManager {
public:
YangStreamManager(YangSynBufferManager* synMgr);
virtual ~YangStreamManager();
public:
YangStreamStateNotify* m_streamState;
int32_t getPlayOnlineCount();
int32_t getPushOnlineCount();
void connectNotify(int32_t puid,YangStreamDirection opt,bool isConnect);
public:
void setMediaConfig(int32_t puid,YangAudioParam* audio,YangVideoParam* video);
void sendRequest(int32_t puid,uint32_t ssrc,YangRequestType req);
void setSendRequestCallback(YangSendRequestCallback* request);
void setDecoderMediaConfigCallback(YangMediaConfigCallback* dec);
void setRenderMediaConfigCallback(YangMediaConfigCallback* render);
int32_t getAudioClock();
int32_t getVideoClock();
private:
YangSendRequestCallback* m_sendRequestCb;
YangMediaConfigCallback* m_mediaConfig_dec;
YangMediaConfigCallback* m_mediaConfig_render;
YangSynBufferManager* m_synMgr;
int32_t m_videoClock;
int32_t m_audioClock;
private:
std::vector<int32_t> m_onlinePlayUsers;
std::vector<int32_t> m_onlinePushUsers;
};
#endif /* INCLUDE_YANGSTREAM_YANGSTREAMMANAGER_H_ */

View File

@ -0,0 +1,29 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef YangStreamType_YangStreamType_H_
#define YangStreamType_YangStreamType_H_
#include <yangutil/yangavtype.h>
#ifdef __cplusplus
class YangMediaConfigCallback {
public:
YangMediaConfigCallback() {};
virtual ~YangMediaConfigCallback() {};
virtual void setMediaConfig(int32_t puid, YangAudioParam *audio,
YangVideoParam *video)=0;
};
class YangSendRequestCallback {
public:
YangSendRequestCallback() {};
virtual ~YangSendRequestCallback() {};
virtual void sendRequest(int32_t puid, uint32_t ssrc,
YangRequestType req)=0;
};
#endif
#endif

View File

@ -0,0 +1,51 @@
//
// Copyright (c) 2019-2023 yanggaofeng
//
#ifndef YANGPLAYER_INCLUDE_YANGAVSYN_H_
#define YANGPLAYER_INCLUDE_YANGAVSYN_H_
#include <yangutil/sys/YangTime.h>
#include <yangutil/yangavtype.h>
#include <yangutil/buffer/YangAudioPlayBuffer.h>
#include <yangavutil/audio/YangAudioMix.h>
#include <yangutil/buffer/YangVideoBuffer.h>
enum YangSynType{
YANG_SYNC_AUDIO_MASTER, /* default choice */
YANG_SYNC_VIDEO_MASTER,
YANG_SYNC_EXTERNAL_CLOCK, /* synchronize to an external clock */
};
#define Yang_Max_Audio_Intervaltime 25
#define Yang_Max_Video_Intervaltime 35
#define Yang_Video_Base_Update_Interval 600000//10*60*1000 //10m
#define Yang_Audio_Base_Update_Interval 5000//10*60*1000 //10m
#define Yang_Video_Cache_time 35
#define Yang_Audio_Cache_time 5
typedef struct{
void* session;
uint8_t* (*getVideoRef)(void* session,YangFrame* pframe);
uint8_t* (*getAudioRef)(void* session,YangFrame* audioFrame);
void (*setInAudioBuffer)(void* session,YangAudioPlayBuffer *paudioList);
void (*setInVideoBuffer)(void* session,YangVideoBuffer *pbuf);
void (*setAudioClock)(void* session,int32_t paudioclock);
void (*setVideoClock)(void* session,int32_t pvideoclock);
void (*setUid)(void* session,int32_t uid);
int32_t (*getUid)(void* session);
int32_t (*getAudioSize)(void* session);
int32_t (*getVideoSize)(void* session);
void (*resetVideoClock)(void* psession);
void (*resetAudioClock)(void* psession);
int32_t (*width)(void* psession);
int32_t (*height)(void* psession);
}YangSynBuffer;
void yang_create_synBuffer(YangSynBuffer* syn);
void yang_destroy_synBuffer(YangSynBuffer* syn);
#endif /* YANGPLAYER_INCLUDE_YANGAVSYN_H_ */

View File

@ -0,0 +1,32 @@
//
// Copyright (c) 2019-2023 yanggaofeng
//
#ifndef INCLUDE_YANGSTREAM_YANGSYNBUFFERMANAGER_H_
#define INCLUDE_YANGSTREAM_YANGSYNBUFFERMANAGER_H_
#include <yangstream/YangSynBuffer.h>
#include <yangutil/sys/YangVector.h>
yang_vector_declare2(YangSynBuffer)
typedef struct{
yang_thread_mutex_t playBufferMutex;
YangSynBuffer* playBuffer;
YangSynBufferVector2* playBuffers;
}YangSynBufferSession;
typedef struct{
YangSynBufferSession* session;
YangSynBuffer* (*getSynBuffer)(YangSynBufferSession* session,int puid);
int (*getPlayBufferIndex)(YangSynBufferSession* session,int puid);
int32_t (*getAudioDatas)(YangSynBufferSession* session, uint8_t* mixBuf,YangFrame* pframe);
int32_t (*addAudioBuffer)(YangSynBufferSession* session,void* yangAudioPlayBuffer,int32_t puid);
void (*initAudioBuffer)(YangSynBufferSession* session);
void (*removeAllAudioBuffer)(YangSynBufferSession* session);
void (*removeAudioBuffer)(YangSynBufferSession* session,int32_t puid);
}YangSynBufferManager;
void yang_create_synBufferManager(YangSynBufferManager* man);
void yang_destroy_synBufferManager(YangSynBufferManager* man);
#endif /* INCLUDE_YANGSTREAM_YANGSYNBUFFERMANAGER_H_ */

View File

@ -0,0 +1,24 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef ___YangAudioBuffer__
#define ___YangAudioBuffer__
#include <yangutil/buffer/YangMediaBuffer.h>
class YangAudioBuffer:public YangMediaBuffer
{
public:
YangAudioBuffer(int32_t pcacheNum);
~YangAudioBuffer(void);
void putAudio(YangFrame* pframe);
int32_t getAudio(YangFrame* pframe);
uint8_t *getAudioRef(YangFrame* pframe);
void reset();
private:
int32_t m_bufLen;
};
#endif

View File

@ -0,0 +1,25 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef YangAudioEncoderBuffer_H
#define YangAudioEncoderBuffer_H
#include <yangutil/buffer/YangMediaBuffer.h>
class YangAudioEncoderBuffer: public YangMediaBuffer {
public:
YangAudioEncoderBuffer(int32_t paudioCacheNum);
~YangAudioEncoderBuffer(void);
void reset();
void putAudio(YangFrame* audioFrame);
void getAudio(YangFrame* audioFrame);
uint8_t* getAudioRef(YangFrame* pframe);
void putPlayAudio(YangFrame* pframe);
void getPlayAudio(YangFrame* audioFrame);
private:
};
#endif

View File

@ -0,0 +1,27 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef ___YangAudioPlayBuffer1__
#define ___YangAudioPlayBuffer1__
#include <yangutil/buffer/YangMediaBuffer.h>
class YangAudioPlayBuffer:public YangMediaBuffer{
public:
YangAudioPlayBuffer();
~YangAudioPlayBuffer(void);
void putAudio(YangFrame* pframe);
void getAudio(YangFrame* pframe);
uint8_t *getAudios(YangFrame* pframe);
int32_t getFrameTimestamp(int64_t *timestamp);
int64_t getNextTimestamp();
void reset();
private:
int32_t m_bufLen;
};
#endif

View File

@ -0,0 +1,19 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef YangBuffer_YANGRTCUTIL_H_
#define YangBuffer_YANGRTCUTIL_H_
#include <yangutil/yangtype.h>
#ifdef __cplusplus
extern "C"{
#include <yangutil/buffer/YangCBuffer.h>
}
#else
#include <yangutil/buffer/YangCBuffer.h>
#endif
#endif

View File

@ -0,0 +1,72 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGUTIL_BUFFER_YANGCBUFFER_H_
#define INCLUDE_YANGUTIL_BUFFER_YANGCBUFFER_H_
#include <yangutil/yangtype.h>
typedef struct{
// current position at bytes.
char* head;
// the bytes data for buffer to read or write.
char* data;
// the total number of bytes.
int32_t size;
}YangBuffer;
void yang_init_buffer(YangBuffer* buf,char* b, int32_t nn);
void yang_destroy_buffer(YangBuffer* buf);
int32_t yang_buffer_pos(YangBuffer* buf);
// Left bytes in buffer, total size() minus the current pos().
int32_t yang_buffer_left(YangBuffer* buf);
// Whether buffer is empty.
int32_t yang_buffer_empty(YangBuffer* buf);
// Whether buffer is able to supply required size of bytes.
// @remark User should check buffer by require then do read/write.
// @remark Assert the required_size is not negative.
int32_t yang_buffer_require(YangBuffer* buf,int32_t required_size);
void yang_buffer_skip(YangBuffer* buf,int32_t size);
// Write 1bytes char to buffer.
void yang_write_1bytes(YangBuffer* buf,char value);
// Write 2bytes int32_t to buffer.
void yang_write_2bytes(YangBuffer* buf,int16_t value);
void yang_write_le2bytes(YangBuffer* buf,int16_t value);
// Write 4bytes int32_t to buffer.
void yang_write_4bytes(YangBuffer* buf,int32_t value);
void yang_write_le4bytes(YangBuffer* buf,int32_t value);
// Write 3bytes int32_t to buffer.
void yang_write_3bytes(YangBuffer* buf,int32_t value);
void yang_write_le3bytes(YangBuffer* buf,int32_t value);
// Write 8bytes int32_t to buffer.
void yang_write_8bytes(YangBuffer* buf,int64_t value);
void yang_write_le8bytes(YangBuffer* buf,int64_t value);
// Write string to buffer
//void yang_write_string(YangBuffer* buf,std::string value);
// Write bytes to buffer
void yang_write_bytes(YangBuffer* buf,char* data, int32_t size);
void yang_write_cstring(YangBuffer* buf,char* data);
// Read 1bytes char from buffer.
char yang_read_1bytes(YangBuffer* buf);
// Read 2bytes int32_t from buffer.
int16_t yang_read_2bytes(YangBuffer* buf);
int16_t yang_read_le2bytes(YangBuffer* buf);
// Read 3bytes int32_t from buffer.
int32_t yang_read_3bytes(YangBuffer* buf);
int32_t yang_read_le3bytes(YangBuffer* buf);
// Read 4bytes int32_t from buffer.
int32_t yang_read_4bytes(YangBuffer* buf);
int32_t yang_read_le4bytes(YangBuffer* buf);
// Read 8bytes int32_t from buffer.
int64_t yang_read_8bytes(YangBuffer* buf);
int64_t yang_read_le8bytes(YangBuffer* buf);
// Read bytes from buffer, length specifies by param len.
void yang_read_bytes(YangBuffer* buf,char* data, int32_t size);
uint16_t yang_readchar_2bytes(char* buf);
uint32_t yang_readchar_4bytes(char* buf);
#endif /* INCLUDE_YANGUTIL_BUFFER_YANGCBUFFER_H_ */

View File

@ -0,0 +1,43 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef YANGUTIL_BUFFER_YANGBUFFER_H_
#define YANGUTIL_BUFFER_YANGBUFFER_H_
#include <yangutil/sys/YangThread.h>
#include <yangutil/yangtype.h>
#include <yangutil/yangavtype.h>
#define yang_reindex(p) if(p!=NULL) p->resetIndex();
class YangMediaBuffer {
public:
YangMediaBuffer();
virtual ~YangMediaBuffer();
public:
int32_t m_mediaType;
int32_t m_uid;
void resetIndex();
uint32_t size();
protected:
uint32_t m_putIndex;
uint32_t m_getIndex;
uint32_t m_cache_num;
uint32_t m_size;
uint32_t m_nextIndex;
int32_t m_ret;
YangFrame** m_frames;
YangBufferManager* m_bufferManager;
protected:
void initFrames(int pnum,int unitsize);
void putFrame(YangFrame* pframe);
void getFrame(YangFrame* pframe);
void peakFrame(YangFrame* pframe);
YangFrame* getCurFrameRef();
int64_t getNextFrameTimestamp();
uint8_t* getFrameRef(YangFrame* pframe);
private:
yang_thread_mutex_t m_lock;
};
#endif /* YANGUTIL_BUFFER_YANGBUFFER_H_ */

View File

@ -0,0 +1,42 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef __YangVideoBuffer__
#define __YangVideoBuffer__
#include <yangutil/buffer/YangMediaBuffer.h>
#define yang_get_videoBuffer(x) new YangVideoBuffer(x->width,x->height,x->videoCaptureFormat==YangYuy2?16:12,x->bitDepth==8?1:2)
class YangVideoBuffer:public YangMediaBuffer
{
public:
YangVideoBuffer(int32_t pBitDepthLen);
YangVideoBuffer(int32_t pwid,int32_t phei,YangYuvType ptype,int32_t pBitDepthLen);
~YangVideoBuffer(void);
void initTemp();
void init(int32_t pwid,int32_t phei,YangYuvType ptype);
void reset();
int32_t isPreview=0;
int32_t m_width;
int32_t m_height;
int32_t m_length;
int32_t m_frames;
int32_t m_bitDepthLen;
void putVideo(YangFrame* pframe);
void peakVideo(YangFrame *p_frame);
void getVideo(YangFrame * pframe);
uint8_t *getVideoRef(YangFrame * pframe);
int64_t getTimestamp(int64_t * timestamp);
int64_t getNextTimestamp();
YangFrame *getCurVideoFrame();
protected:
private:
int32_t m_headerLen;
};
#endif

View File

@ -0,0 +1,21 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef __YangVideoDecoderBuffer__
#define __YangVideoDecoderBuffer__
#include <stdint.h>
#include <yangutil/buffer/YangMediaBuffer.h>
class YangVideoDecoderBuffer:public YangMediaBuffer
{
public:
YangVideoDecoderBuffer(int num);
~YangVideoDecoderBuffer(void);
void putEVideo(YangFrame* pframe);
void getEVideo(YangFrame* pframe);
private:
};
#endif

View File

@ -0,0 +1,22 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef __YangVideoEncoderBuffer__
#define __YangVideoEncoderBuffer__
#include <yangutil/buffer/YangMediaBuffer.h>
class YangVideoEncoderBuffer:public YangMediaBuffer
{
public:
YangVideoEncoderBuffer(int32_t pcachenum);
~YangVideoEncoderBuffer(void);
void getEVideo(YangFrame* pframe);
uint8_t * getEVideoRef(YangFrame* frame);
void putEVideo(YangFrame* pframe);
private:
};
#endif

View File

@ -0,0 +1,43 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef YANGUTIL_BUFFER_YANGBUFFER2_H_
#define YANGUTIL_BUFFER_YANGBUFFER2_H_
#include <yangutil/sys/YangThread.h>
#include <yangutil/yangtype.h>
#include <yangutil/yangavtype.h>
#define yang_reindex2(p) if(p!=NULL) p->resetIndex(&p->mediaBuffer);
typedef struct{
int32_t mediaType;
int32_t uid;
uint32_t putIndex;
uint32_t getIndex;
uint32_t cache_num;
uint32_t size;
uint32_t nextIndex;
int32_t ret;
yang_thread_mutex_t mlock;
YangFrame** frames;
uint8_t* bufferManager;
}YangMediaBufferSession2;
typedef struct{
YangMediaBufferSession2 session;
void (*resetIndex)(YangMediaBufferSession2* session);
void (*initFrames)(YangMediaBufferSession2* session,int pnum,int unitsize);
void (*putFrame)(YangMediaBufferSession2* session,YangFrame* pframe);
void (*getFrame)(YangMediaBufferSession2* session,YangFrame* pframe);
YangFrame* (*getCurFrameRef)(YangMediaBufferSession2* session);
int64_t (*getNextFrameTimestamp)(YangMediaBufferSession2* session);
uint8_t* (*getFrameRef)(YangMediaBufferSession2* session,YangFrame* pframe);
}YangMediaBuffer2;
void yang_create_mediaBuffer2(YangMediaBuffer2* buf);
void yang_destroy_mediaBuffer2(YangMediaBuffer2* buf);
#endif /* YANGUTIL_BUFFER_YANGBUFFER_H_ */

View File

@ -0,0 +1,21 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef __YangVideoEncoderBuffer2__
#define __YangVideoEncoderBuffer2__
#include <yangutil/buffer2/YangMediaBuffer2.h>
typedef struct{
YangMediaBuffer2 mediaBuffer;
void (*getEVideo)(YangMediaBuffer2* buf,YangFrame* pframe);
uint8_t * (*getEVideoRef)(YangMediaBuffer2* buf,YangFrame* frame);
void (*putEVideo)(YangMediaBuffer2* buf,YangFrame* pframe);
int32_t (*size)(YangMediaBuffer2* buf);
void (*resetIndex)(YangMediaBuffer2* buf);
}YangVideoEncoderBuffer2;
void yang_create_videoEncoderBuffer2(YangVideoEncoderBuffer2* buf,int pcachenum);
void yang_destroy_videoEncoderBuffer2(YangVideoEncoderBuffer2* buf);
#endif

View File

@ -0,0 +1,45 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGUTIL_YANGAUTOFREE_H_
#define INCLUDE_YANGUTIL_YANGAUTOFREE_H_
#include <yangutil/yangtype.h>
#ifdef __cplusplus
#define YangAutoFree(className, instance) \
impl_YangAutoFree<className> _auto_free_##instance(&instance, false)
#define YangAutoFreeA(className, instance) \
impl_YangAutoFree<className> _auto_free_array_##instance(&instance, true)
template<class T>
class impl_YangAutoFree
{
private:
T** ptr;
bool is_array;
public:
impl_YangAutoFree(T** p, bool array) {
ptr = p;
is_array = array;
}
virtual ~impl_YangAutoFree() {
if (ptr == NULL || *ptr == NULL) {
return;
}
if (is_array) {
delete[] *ptr;
} else {
delete *ptr;
}
*ptr = NULL;
}
};
#endif
#endif /* INCLUDE_YANGUTIL_YANGAUTOFREE_H_ */

View File

@ -0,0 +1,154 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGUTIL_YANGAVCTYPE_H_
#define INCLUDE_YANGUTIL_YANGAVCTYPE_H_
#include <yangutil/yangtype.h>
#define YANG_Frametype_Spspps 9
#define YANG_Frametype_I 1
#define YANG_Frametype_P 0
#define Yang_MJPEG_Header 0x37
typedef enum {
YangRecvonly, YangSendonly, YangSendrecv
}YangStreamDirection;
typedef enum {
Yang_Conn_State_New,
Yang_Conn_State_Connecting,
Yang_Conn_State_Connected,
Yang_Conn_State_Disconnected,
Yang_Conn_State_Failed,
Yang_Conn_State_Closed
}YangRtcConnectionState;
typedef enum YangAudioCodec{
Yang_AED_AAC,
Yang_AED_MP3,
Yang_AED_SPEEX,
Yang_AED_OPUS,
Yang_AED_G711
}YangAudioCodec;
typedef enum YangVideoCodec{
Yang_VED_264,
Yang_VED_265,
Yang_VED_AV1,
Yang_VED_VP8,
Yang_VED_VP9,
Yang_VED_MJPEG
}YangVideoCodec;
typedef enum YangRequestType {
Yang_Req_Sendkeyframe,
Yang_Req_HighLostPacketRate,
Yang_Req_LowLostPacketRate,
Yang_Req_Connected,
Yang_Req_Disconnected
}YangRequestType;
typedef enum YangRtcMessageType{
YangRTC_Decoder_Error
}YangRtcMessageType;
typedef enum{
YangIceHost,
YangIceStun,
YangIceTurn
}YangIceCandidateType;
typedef enum {
YangIceNew,
YangIceSuccess,
YangIceFail
}YangIceCandidateState;
typedef struct{
int32_t mediaType;
int32_t uid;
int32_t frametype;
int32_t nb;
int64_t pts;
int64_t dts;
uint8_t* payload;
}YangFrame;
typedef struct {
enum YangAudioCodec encode;
int32_t sample;
int32_t channel;
int32_t audioClock;
int32_t fec;
}YangAudioParam;
typedef struct {
enum YangVideoCodec encode;
int32_t videoClock;
}YangVideoParam;
typedef struct{
void* context;
int32_t (*sendRtcMessage)(void* context,int puid,YangRtcMessageType mess);
}YangSendRtcMessage;
typedef struct{
YangIpFamilyType familyType;
int32_t serverPort;
uint32_t stunIp;
int32_t stunPort;
uint32_t relayIp;
int32_t relayPort;
char username[64];
char password[64];
char serverIp[64];
}YangIceServer;
typedef struct{
void* context;
void (*sslAlert)(void* context,int32_t uid,char* type,char* desc);
}YangSslCallback;
typedef struct {
void* context;
void (*receiveAudio)(void* context,YangFrame *audioFrame);
void (*receiveVideo)(void* context,YangFrame *videoFrame);
void (*receiveMsg)(void* context,YangFrame *videoFrame);
}YangReceiveCallback;
typedef struct{
void* context;
void (*onIceStateChange)(void* context,int32_t uid,YangIceCandidateType iceCandidateType,YangIceCandidateState iceState);
void (*onConnectionStateChange)(void* context, int32_t uid,YangRtcConnectionState connectionState);
}YangIceCallback;
typedef struct{
void* context;
void (*setMediaConfig)(void* context,int32_t puid,YangAudioParam* audio,YangVideoParam* video);
void (*sendRequest)(void* context,int32_t puid,uint32_t ssrc,YangRequestType req);
}YangRtcCallback;
typedef struct {
int32_t localPort;
int32_t remotePort;
int32_t uid;
yangbool isControlled;
YangStreamDirection streamDirection;
YangSslCallback sslCallback;
YangRtcCallback rtcCallback;
YangReceiveCallback recvCallback;
YangIceCallback iceCallback;
char url[160];
char remoteIp[64];
char app[32];
char stream[Yang_StreamName_Lenght];
}YangStreamConfig;
#endif /* INCLUDE_YANGUTIL_YANGAVCTYPE_H_ */

View File

@ -0,0 +1,73 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGUTIL_YANGAVTYPE_H265_H_
#define INCLUDE_YANGUTIL_YANGAVTYPE_H265_H_
typedef enum YangHevcNaluType
{
YANG_NAL_UNIT_CODED_SLICE_TRAIL_N = 0,
YANG_NAL_UNIT_CODED_SLICE_TRAIL_R, //1
YANG_NAL_UNIT_CODED_SLICE_TSA_N, //2
YANG_NAL_UNIT_CODED_SLICE_TLA, //3
YANG_NAL_UNIT_CODED_SLICE_STSA_N, //4
YANG_NAL_UNIT_CODED_SLICE_STSA_R, //5
YANG_NAL_UNIT_CODED_SLICE_RADL_N, //6
YANG_NAL_UNIT_CODED_SLICE_DLP, //7
YANG_NAL_UNIT_CODED_SLICE_RASL_N, //8
YANG_NAL_UNIT_CODED_SLICE_TFD, //9
YANG_NAL_UNIT_RESERVED_10,
YANG_NAL_UNIT_RESERVED_11,
YANG_NAL_UNIT_RESERVED_12,
YANG_NAL_UNIT_RESERVED_13,
YANG_NAL_UNIT_RESERVED_14,
YANG_NAL_UNIT_RESERVED_15,
YANG_NAL_UNIT_CODED_SLICE_BLA, //16
YANG_NAL_UNIT_CODED_SLICE_BLANT, //17
YANG_NAL_UNIT_CODED_SLICE_BLA_N_LP, //18
YANG_NAL_UNIT_CODED_SLICE_IDR, //19
YANG_NAL_UNIT_CODED_SLICE_IDR_N_LP, //20
YANG_NAL_UNIT_CODED_SLICE_CRA, //21
YANG_NAL_UNIT_VPS=32, //32
YANG_NAL_UNIT_SPS, // 33
YANG_NAL_UNIT_PPS, //34
YANG_NAL_UNIT_ACCESS_UNIT_DELIMITER, //35
YANG_NAL_UNIT_EOS, //36
YANG_NAL_UNIT_EOB, //37
YANG_NAL_UNIT_FILLER_DATA, //38
YANG_NAL_UNIT_SEI , //39Prefix SEI
YANG_NAL_UNIT_SEI_SUFFIX, //40Suffix SEI
YANG_NAL_UNIT_RESERVED_41,
YANG_NAL_UNIT_RESERVED_42,
YANG_NAL_UNIT_RESERVED_43,
YANG_NAL_UNIT_RESERVED_44,
YANG_NAL_UNIT_RESERVED_45,
YANG_NAL_UNIT_RESERVED_46,
YANG_NAL_UNIT_RESERVED_47,
YANG_NAL_UNIT_UNSPECIFIED_48,
YANG_NAL_UNIT_UNSPECIFIED_49,
YANG_NAL_UNIT_UNSPECIFIED_50,
YANG_NAL_UNIT_UNSPECIFIED_51,
YANG_NAL_UNIT_UNSPECIFIED_52,
YANG_NAL_UNIT_UNSPECIFIED_53,
YANG_NAL_UNIT_UNSPECIFIED_54,
YANG_NAL_UNIT_UNSPECIFIED_55,
YANG_NAL_UNIT_UNSPECIFIED_56,
YANG_NAL_UNIT_UNSPECIFIED_57,
YANG_NAL_UNIT_UNSPECIFIED_58,
YANG_NAL_UNIT_UNSPECIFIED_59,
YANG_NAL_UNIT_UNSPECIFIED_60,
YANG_NAL_UNIT_UNSPECIFIED_61,
YANG_NAL_UNIT_UNSPECIFIED_62,
YANG_NAL_UNIT_UNSPECIFIED_63,
YANG_NAL_UNIT_INVALID,
}YangHevcNaluType;
//for nalu data first byte
//#define YANG_HEVC_NALU_TYPE(code) (YangHevcNaluType)((code & 0x7E)>>1)
#define YANG_HEVC_NALU_TYPE(code) (YangHevcNaluType)((code >> 1) & 0x3F)
#define H265_kFuA 49
#define H265_kStapA 48
#endif /* INCLUDE_YANGUTIL_YANGAVTYPE_H265_H_ */

View File

@ -0,0 +1,13 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGUTIL_YANGFRAMEBUFFER_H_
#define INCLUDE_YANGUTIL_YANGFRAMEBUFFER_H_
void yang_frame_copy(YangFrame* src, YangFrame* dst);
void yang_frame_copy_buffer(YangFrame* src, YangFrame* dst);
void yang_frame_copy_nobuffer(YangFrame* src, YangFrame* dst);
int64_t yang_GetSystemTimeUs();
#endif /* INCLUDE_YANGUTIL_YANGFRAMEBUFFER_H_ */

View File

@ -0,0 +1,49 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGUTIL_YANGMEMORY_H_
#define INCLUDE_YANGUTIL_YANGMEMORY_H_
#include <string.h>
#define yang_memcpy memcpy
#define yang_malloc malloc
#define yang_calloc calloc
#define yangfree free
#define yang_memset memset
#define yang_memmove memmove
#define yang_memcmp memcmp
#define yang_realloc realloc
#define yang_strcat strcat
#define yang_strncat strncat
#define yang_strcpy strcpy
#define yang_strncpy strncpy
#define yang_strlen strlen
#define yang_strnlen strnlen
#define yang_strchr strchr
#define yang_strnchr strnchr
#define yang_strrchr strrchr
#define yang_strcmp strcmp
#define yang_strncmp strncmp
#define yang_printf printf
#define yang_sprintf sprintf
#define yang_snprintf snprintf
#define yang_vsnprintf vsnprintf
#define yang_sscanf sscanf
#define yang_trimstrall trimstrall
#define yang_ltrimstr ltrimstr
#define yang_rtrimstr rtrimstr
#define yang_strstr strstr
#define yang_tolower tolower
#define yang_toupper toupper
#define yang_atoi atoi
#define yang_atol atol
#define yang_static_strlen(string_literal) (sizeof(string_literal) - sizeof(""))
#endif /* INCLUDE_YANGUTIL_YANGMEMORY_H_ */

View File

@ -0,0 +1,22 @@
//
// Copyright (c) 2019-2022 yanggaofeng
//
#ifndef INCLUDE_YANGUTIL_YANGUNISTD_H_
#define INCLUDE_YANGUTIL_YANGUNISTD_H_
#ifdef _MSC_VER
#include <Windows.h>
#define yang_usleep(x) Sleep(x>1000?x/1000:1)
//void yang_usleep(int ns){
// Sleep(ns>1000?ns/1000:1);
//}
#define yang_sleep(x) Sleep(1000*x)
#else
#include <unistd.h>
#define yang_usleep usleep
#define yang_sleep sleep
#endif
#endif /* INCLUDE_YANGUTIL_YANGUNISTD_H_ */