ZegoPlayRecorder
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
LiveRoom.h
Go to the documentation of this file.
1 //
2 // LiveRoom.h
3 // zegoliveroom
4 //
5 // Copyright © 2017年 Zego. All rights reserved.
6 //
7 
8 #ifndef LiveRoom_h
9 #define LiveRoom_h
10 
11 #ifndef ZEGO_API
12 #ifdef WIN32
13 #ifdef ZEGO_EXPORTS
14 #define ZEGO_API __declspec(dllexport)
15 #else
16 #define ZEGO_API __declspec(dllimport)
17 #endif
18 #else
19 #define ZEGO_API __attribute__((visibility("default")))
20 #endif
21 #endif // !ZEGO_API
22 
23 
24 #define ZEGO_MAX_COMMON_LEN (512)
25 #define ZEGO_MAX_USERID_LEN (64)
26 #define ZEGO_MAX_USERNAME_LEN (256)
27 
28 namespace ZEGO
29 {
30  namespace LIVEROOM
31  {
34  {
36  {
37  szUserId[0] = '\0';
38  szUserName[0] = '\0';
39  szStreamId[0] = '\0';
40  szExtraInfo[0] = '\0';
42  }
43 
48  unsigned long uStreamCreateTime;
49  };
50 
53  {
54  StreamAdded = 2001,
55  StreamDeleted = 2002,
56  };
57 
60  {
64  };
65 
68  {
71  };
72 
74  {
78  };
79 
81  {
84  };
85 
87  {
91  };
92 
94  {
96  unsigned int recordDuration;
97  unsigned int fileSize;
98  };
99 
101  {
102  bool videoAndAudioSeperate = false;
106  int externalVideoBitrate = 600000;
107  };
108 
113  {
114  const char *info = nullptr;
115  int xPosition = -1;
116  int yPosition = -1;
117  int nWidth = 0;
118  int nHeight = 0;
119  int fontColor = 0xFFFFFF00;
120  int backgroundColor = 0x3F3F3FFF;
121  };
122 
125  {
127  struct
128  {
129  int top;
130  int left;
131  int bottom;
132  int right;
133  } layout;
134  int layer;
135 
140  int frameFillColor = 0x00000000;
141  const char* pBackgroundImagePath = nullptr;
143  {
144  szStreamID[0] = '\0';
145  }
156  };
157 
160  {
165  };
166 
169  {
171  int width = 0;
172  int height = 0;
173  };
174 
176  {
179  };
180 
183  {
184  const char *imagePath = nullptr;
185  int xPosition = -1;
186  int yPosition = -1;
187  int nWidth = 0;
188  int nHeight = 0;
190  };
191 
192  struct AudioFrame
193  {
195  {
196  frameType = 0;
197  samples = 0;
198  bytesPerSample = 0;
199  channels = 0;
200  sampleRate = 0;
201  timeStamp = 0.0;
202  configLen = 0;
203  bufLen = 0;
204  buffer = 0;
205  }
206 
207  int frameType; //refer to enum FrameType
208  int samples; //PCM:capture pcm samples at this input. AAC:aac encode one frame need samples
209  int bytesPerSample; //bytes per sample = 2 * channels, current bit depth only support 16bit(2 bytes).
210  int channels; //channels, 1 or 2.
211  int sampleRate; //PCM: capture sample rate; AAC: encode sample rate. supported [16k/32k/44.1k/48k]
212  double timeStamp; //time stamp, PCM: 0; AAC: 0 or encode timeStamp, if buffer data only contain special config fill 0.
213  int configLen; //aac special config Len, PCM: 0; AAC: range [0-64]. 0 indicate this frame not contain spcial config.
214  int bufLen; /*buffer Length, PCM bufLen = 2 * samples * channels(only need correct fill samples and channels,
215  not use filed bufLen). AAC encode data len = bufLen - configLen.*/
216  unsigned char* buffer; //data buffer, the caller is responsible for bufer allocate and release
217  };
218 
221  {
247  : bGenerateMp3(false)
249  , nFragmentSeconds(2)
250  , nOutputFps(0)
251  , nOutputBitrate(0)
252  , nOutputWidth(0)
253  , nOutputHeight(0)
254  , nOutputAudioBitrate(80*1000)
255  , pInputStream(0)
256  , nInputStreamCount(0)
257  , nOutputBackgroundColor(0x00000000)
259  , pTimestampConfig(nullptr)
260  , videoAudioSeperateFile(false)
262  , pImageWaterMark(nullptr)
263  , bRecordSoundLevel(false)
264  {
265  szPathAndName[0] = '\0';
266  }
267  };
268 
271  {
289  };
290 
293  {
296  };
297 
299  {
306  };
307 
309  {
310  public:
311  virtual int OnIncomingVideoData(const unsigned char *pData[4],
312  int dataLen[4],
313  int width,
314  int height,
315  int strides[4],
316  VideoPixelFormat format,
317  unsigned long long referenceTime,
318  unsigned int referenceTimeScale) = 0;
319  };
320 
322  {
323  public:
324  virtual int OnRecordAudioFrame(const AudioFrame& audioFrame) = 0;
325  };
326 
328  class ICallback
329  {
330  public:
336  virtual void OnInitSDK(int errorCode) {}
337 
344  virtual void OnLoginRoom(int errorCode, const char *pszRoomID) = 0;
345 
352  virtual void OnLogoutRoom(int errorCode, const char *pszRoomID) {}
353 
362  virtual void OnDisconnect(int errorCode, const char *pszRoomID) = 0;
363 
373  virtual void OnStreamUpdate(ZegoStreamUpdateType type, ZegoStreamInfo *pStreamInfo, unsigned int streamCount, const char *pszRoomID) = 0;
374 
387  virtual void OnPlayQualityUpdate(const char* pszStreamID, int quality, double videoFPS, double videoKBPS) {};
388 
402  virtual void OnPlayQualityUpdate(const char* pszStreamID, int quality, double videoFPS, double videoKBPS, double audioKBPS) {};
403 
410  virtual void OnStreamRecordBegin(const char* pszStreamID, const char *pszPathAndName) = 0;
411 
419  virtual void OnStreamRecordEnd(const char* pszStreamID, const char *pszPathAndName, RecordEndReason reason) = 0;
420 
429  virtual void OnStreamRecordVideoSizeChanged(const char* pszStreamID, int width, int height) {};
430 
438  virtual void OnStreamRecordRemoteMicOperation(const char* pszStreamID, int operation, int reason) {};
439 
446  virtual void OnStreamRecordEvent(const char* pszStreamID, RecordEvent event) {};
447 
456  virtual void OnStreamRecordData(const char* pszStreamID, const char *data, int len) {};
457 
466  virtual void OnSeek(const char* pszStreamID, long long offset, int whence) {};
467 
480  virtual void OnVideoDataCallback(const unsigned char **pData, int* dataLen, const char* pszStreamID, int width, int height, int strides[4], VideoPixelFormat pixel_format) {}
481 
488  virtual void OnAudioDataCallback(const char* pszStreamID, const AudioFrame &frame) {};
489 
497  virtual void OnMixStreamRecordUpdate(const char** ppszStreamID, int nStreamCount) = 0;
498 
510  virtual void OnRecordFilePath(const char *pszStreamID, const char *filePath, MuxerStreamType muxerType, unsigned int startTimeStamp, unsigned int stopTimeStamp) {};
511 
518  virtual void OnExternalVideoDataSource(const char *pszStreamID, IExternalVideoDataSource *source) {};
519 
526  virtual void OnExternalMediaDataSource(const char *pszStreamID, IExternalMediaDataSource *source) {};
527 
535  virtual void OnStreamSnapshotFilePath(int nErrorCode, const char* pszStreamID, const char* pszFilePath) {};
536 
537  virtual ~ICallback() {}
538  };
539 
541  {
542  public:
550  virtual void OnRecvMediaSideInfo(const char * pszStreamID, const unsigned char *buf, int dataLen) = 0;
551 
552  virtual ~IMediaSideCallback() {}
553  };
554 
560  ZEGO_API const char* GetSDKVersion();
561 
571  ZEGO_API bool SetLogDirAndSize(const char* pszLogDir, unsigned long long lLogFileSize = 5 * 1024 * 1024);
572 
576  ZEGO_API void UploadLog();
577 
584  ZEGO_API void SetUseTestEnv(bool bTestEnv);
585 
595  ZEGO_API void SetConfig(const char *config);
596 
606  ZEGO_API bool InitSDK(unsigned int uiAppID, unsigned char* pBufAppSignature, int nSignatureSize);
607 
615  ZEGO_API bool InitSDK(unsigned int uiAppID);
616 
622  ZEGO_API bool UnInitSDK();
623 
630  ZEGO_API bool SetCallback(ICallback* pCB);
631 
639  ZEGO_API bool LoginRoom(const char* pszRoomID);
640 
641 
652  ZEGO_API bool SetUser(const char* pszUserID, const char* pszUserName);
653 
661  ZEGO_API void SetCustomToken(const char *thirdPartyToken);
662 
669  ZEGO_API bool LogoutRoom();
670 
677 
685 
692  ZEGO_API void SetMuxerCacheSize(int size);
693 
700  ZEGO_API void EnableSingleAndMixRecordMode(bool enable);
701 
708  ZEGO_API void EnableExternalRender(bool bEnable);
709 
716  ZEGO_API bool SetFontFile(const char *pszPathAndName);
717 
726  ZEGO_API void EnableExternalAudioData(bool bEnable, int sampleRate, int channels);
727 
741  ZEGO_API bool StartRecordSingleStream(const char* pszStreamID, const char *pszPathAndName, MuxerStreamType nMuxerStreamType = MuxerStreamTypeBoth, int nFragmentSeconds = 2, ZegoRecordSingleStreamConfig *config = nullptr);
742 
749  ZEGO_API bool StopRecordSingleStream(const char* pszStreamID);
750 
759  ZEGO_API bool StartRecordMixStream(ZegoMixStreamRecordConfig* pConfig);
760 
769  ZEGO_API bool UpdateInputStreamConfig(ZegoStreamConfig* pInputStream, int nInputStreamCount);
770 
778  ZEGO_API bool UpdateImageWaterMarkConfig(ZegoImageWaterMarkConfig* pConfig);
779 
786 
793 
800 
810  ZEGO_API bool GetRecordStatus(const char* streamID, ZegoRecordStatus& status);
811 
820  ZEGO_API unsigned int GetRecordLastMediaSideTime(const char* streamID);
821 
828  ZEGO_API bool SetMediaSideCallback(IMediaSideCallback *pCB);
829 
836  ZEGO_API bool TakeStreamSnapshot(const char* pszStreamID, const char* pszPathAndName);
837 
838  }
839 }
840 
841 #endif /* LiveRoom.h */
ZegoVideoStreamLayerType streamLayerType
Definition: LiveRoom.h:104
virtual void OnRecordFilePath(const char *pszStreamID, const char *filePath, MuxerStreamType muxerType, unsigned int startTimeStamp, unsigned int stopTimeStamp)
Definition: LiveRoom.h:510
bool videoAudioSeperateFile
Definition: LiveRoom.h:239
Definition: LiveRoom.h:89
int nOutputFps
Definition: LiveRoom.h:227
Definition: LiveRoom.h:54
Definition: LiveRoom.h:93
int channels
Definition: LiveRoom.h:210
#define ZEGO_MAX_USERNAME_LEN
Definition: LiveRoom.h:26
const char * info
Definition: LiveRoom.h:114
ZEGO_API void EnableSingleAndMixRecordMode(bool enable)
bool videoAndAudioSeperate
Definition: LiveRoom.h:102
virtual void OnExternalMediaDataSource(const char *pszStreamID, IExternalMediaDataSource *source)
Definition: LiveRoom.h:526
RecordEndReason
Definition: LiveRoom.h:270
int externalVideoBitrate
Definition: LiveRoom.h:106
int nFragmentSeconds
Definition: LiveRoom.h:226
unsigned long uStreamCreateTime
Definition: LiveRoom.h:48
ZEGO_API bool LoginRoom(const char *pszRoomID)
virtual void OnStreamRecordBegin(const char *pszStreamID, const char *pszPathAndName)=0
int right
Definition: LiveRoom.h:132
ZegoFillMode fillMode
Definition: LiveRoom.h:138
ZEGO_API bool LogoutRoom()
virtual void OnStreamUpdate(ZegoStreamUpdateType type, ZegoStreamInfo *pStreamInfo, unsigned int streamCount, const char *pszRoomID)=0
int nOutputHeight
Definition: LiveRoom.h:230
int samples
Definition: LiveRoom.h:208
Definition: LiveRoom.h:168
int nOutputBackgroundColor
Definition: LiveRoom.h:236
ZegoImageWaterMarkConfig * pImageWaterMark
Definition: LiveRoom.h:242
const char * pOutputBackgroundImage
Definition: LiveRoom.h:237
ZEGO_API bool UpdateInputStreamConfig(ZegoStreamConfig *pInputStream, int nInputStreamCount)
unsigned char * buffer
Definition: LiveRoom.h:216
int left
Definition: LiveRoom.h:130
int nHeight
Definition: LiveRoom.h:188
char szExtraInfo[ZEGO_MAX_COMMON_LEN]
Definition: LiveRoom.h:47
int nInputStreamCount
Definition: LiveRoom.h:234
ZegoMixStreamRecordConfig()
Definition: LiveRoom.h:246
char szUserId[ZEGO_MAX_USERID_LEN]
Definition: LiveRoom.h:44
ZEGO_API bool GetRecordStatus(const char *streamID, ZegoRecordStatus &status)
ZegoImageWaterMarkFillMode fillMode
Definition: LiveRoom.h:189
int nWidth
Definition: LiveRoom.h:187
unsigned int recordDuration
Definition: LiveRoom.h:96
RecordEvent
Definition: LiveRoom.h:292
ZegoImageWaterMarkFillMode
Definition: LiveRoom.h:175
virtual void OnStreamRecordEnd(const char *pszStreamID, const char *pszPathAndName, RecordEndReason reason)=0
virtual void OnDisconnect(int errorCode, const char *pszRoomID)=0
ZEGO_API void SetMuxerCacheSize(int size)
ZEGO_API bool StopRecordSingleStream(const char *pszStreamID)
ZegoStreamConfig()
Definition: LiveRoom.h:142
ZEGO_API void UploadLog()
int nOutputWidth
Definition: LiveRoom.h:229
virtual void OnInitSDK(int errorCode)
Definition: LiveRoom.h:336
Definition: LiveRoom.h:294
virtual int OnRecordAudioFrame(const AudioFrame &audioFrame)=0
int bufLen
Definition: LiveRoom.h:214
virtual void OnStreamRecordData(const char *pszStreamID, const char *data, int len)
Definition: LiveRoom.h:456
MuxerStreamType nMuxerStreamType
Definition: LiveRoom.h:225
Definition: LiveRoom.h:61
Definition: LiveRoom.h:302
int nHeight
Definition: LiveRoom.h:118
#define ZEGO_MAX_COMMON_LEN
Definition: LiveRoom.h:24
virtual void OnStreamRecordEvent(const char *pszStreamID, RecordEvent event)
Definition: LiveRoom.h:446
Definition: LiveRoom.h:328
char szStreamID[ZEGO_MAX_COMMON_LEN]
Definition: LiveRoom.h:126
ZegoFillMode
Definition: LiveRoom.h:80
ZEGO_API bool SetLogDirAndSize(const char *pszLogDir, unsigned long long lLogFileSize=5 *1024 *1024)
ZegoFrameFillMode frameFillMode
Definition: LiveRoom.h:139
virtual void OnRecvMediaSideInfo(const char *pszStreamID, const unsigned char *buf, int dataLen)=0
int frameFillColor
Definition: LiveRoom.h:140
ZegoTimestampConfig * pTimestampConfig
Definition: LiveRoom.h:238
double timeStamp
Definition: LiveRoom.h:212
int height
Definition: LiveRoom.h:172
bool isExternalVideoDataSource
Definition: LiveRoom.h:137
Definition: LiveRoom.h:303
Definition: LiveRoom.h:112
Definition: LiveRoom.h:164
int nOutputAudioBitrate
Definition: LiveRoom.h:231
Definition: LiveRoom.h:192
ZEGO_API bool StopRecordMixStream()
ZegoStreamUpdateType
Definition: LiveRoom.h:52
Definition: LiveRoom.h:305
ZEGO_API bool SetCallback(ICallback *pCB)
ZegoStreamConfig * pInputStream
Definition: LiveRoom.h:233
ZegoStreamInfo()
Definition: LiveRoom.h:35
char filePath[ZEGO_MAX_COMMON_LEN]
Definition: LiveRoom.h:95
virtual ~ICallback()
Definition: LiveRoom.h:537
ZEGO_API void SetUseTestEnv(bool bTestEnv)
virtual void OnLogoutRoom(int errorCode, const char *pszRoomID)
Definition: LiveRoom.h:352
#define ZEGO_MAX_USERID_LEN
Definition: LiveRoom.h:25
Definition: LiveRoom.h:540
const char * imagePath
Definition: LiveRoom.h:184
virtual ~IMediaSideCallback()
Definition: LiveRoom.h:552
Definition: LiveRoom.h:178
virtual void OnSeek(const char *pszStreamID, long long offset, int whence)
Definition: LiveRoom.h:466
ZEGO_API unsigned int GetRecordLastMediaSideTime(const char *streamID)
ZEGO_API void SetMuxerOutType(MuxerOutType type)
Definition: LiveRoom.h:90
int yPosition
Definition: LiveRoom.h:186
virtual void OnPlayQualityUpdate(const char *pszStreamID, int quality, double videoFPS, double videoKBPS, double audioKBPS)
Definition: LiveRoom.h:402
ZEGO_API int GetMaxRecordCount()
char szPathAndName[ZEGO_MAX_COMMON_LEN]
Definition: LiveRoom.h:222
virtual void OnMixStreamRecordUpdate(const char **ppszStreamID, int nStreamCount)=0
ZEGO_API bool SetFontFile(const char *pszPathAndName)
struct ZEGO::LIVEROOM::ZegoStreamConfig::@0 layout
virtual void OnPlayQualityUpdate(const char *pszStreamID, int quality, double videoFPS, double videoKBPS)
Definition: LiveRoom.h:387
int bottom
Definition: LiveRoom.h:131
ZEGO_API bool StartRecordSingleStream(const char *pszStreamID, const char *pszPathAndName, MuxerStreamType nMuxerStreamType=MuxerStreamTypeBoth, int nFragmentSeconds=2, ZegoRecordSingleStreamConfig *config=nullptr)
ZegoTimestampPosition position
Definition: LiveRoom.h:170
int xPosition
Definition: LiveRoom.h:185
virtual void OnStreamRecordRemoteMicOperation(const char *pszStreamID, int operation, int reason)
Definition: LiveRoom.h:438
virtual void OnStreamRecordVideoSizeChanged(const char *pszStreamID, int width, int height)
Definition: LiveRoom.h:429
int xPosition
Definition: LiveRoom.h:115
Definition: LiveRoom.h:63
ZEGO_API bool InitSDK(unsigned int uiAppID, unsigned char *pBufAppSignature, int nSignatureSize)
virtual void OnLoginRoom(int errorCode, const char *pszRoomID)=0
ZegoVideoStreamLayerType
Definition: LiveRoom.h:73
Definition: LiveRoom.h:55
Definition: LiveRoom.h:161
int nOutputBitrate
Definition: LiveRoom.h:228
char szStreamId[ZEGO_MAX_COMMON_LEN]
Definition: LiveRoom.h:46
bool isExternalVideoDataSource
Definition: LiveRoom.h:105
ZEGO_API const char * GetSDKVersion()
ZEGO_API bool PauseRecordMixStream()
Definition: LiveRoom.h:62
VideoPixelFormat
Definition: LiveRoom.h:298
virtual int OnIncomingVideoData(const unsigned char *pData[4], int dataLen[4], int width, int height, int strides[4], VideoPixelFormat format, unsigned long long referenceTime, unsigned int referenceTimeScale)=0
int yPosition
Definition: LiveRoom.h:116
int configLen
Definition: LiveRoom.h:213
virtual void OnVideoDataCallback(const unsigned char **pData, int *dataLen, const char *pszStreamID, int width, int height, int strides[4], VideoPixelFormat pixel_format)
Definition: LiveRoom.h:480
int width
Definition: LiveRoom.h:171
Definition: LiveRoom.h:304
Definition: LiveRoom.h:279
bool bRecordSoundLevel
Definition: LiveRoom.h:244
int fontColor
Definition: LiveRoom.h:119
virtual void OnStreamSnapshotFilePath(int nErrorCode, const char *pszStreamID, const char *pszFilePath)
Definition: LiveRoom.h:535
AudioFrame()
Definition: LiveRoom.h:194
bool bGenerateMp3
Definition: LiveRoom.h:224
ZEGO_API bool UnInitSDK()
ZEGO_API bool StartRecordMixStream(ZegoMixStreamRecordConfig *pConfig)
ZegoWaterMarkConfig waterMark
Definition: LiveRoom.h:136
Definition: LiveRoom.h:88
int backgroundColor
Definition: LiveRoom.h:120
int bytesPerSample
Definition: LiveRoom.h:209
ZEGO_API void EnableExternalAudioData(bool bEnable, int sampleRate, int channels)
Definition: LiveRoom.h:162
const char * pBackgroundImagePath
Definition: LiveRoom.h:141
Definition: LiveRoom.h:124
MuxerOutType
Definition: LiveRoom.h:67
int frameType
Definition: LiveRoom.h:207
virtual void OnExternalVideoDataSource(const char *pszStreamID, IExternalVideoDataSource *source)
Definition: LiveRoom.h:518
int nWidth
Definition: LiveRoom.h:117
Definition: LiveRoom.h:281
Definition: LiveRoom.h:295
char szUserName[ZEGO_MAX_USERNAME_LEN]
Definition: LiveRoom.h:45
ZEGO_API bool SetUser(const char *pszUserID, const char *pszUserName)
Definition: LiveRoom.h:280
ZEGO_API bool UpdateImageWaterMarkConfig(ZegoImageWaterMarkConfig *pConfig)
ZegoTimestampPosition
Definition: LiveRoom.h:159
int top
Definition: LiveRoom.h:129
ZEGO_API void EnableExternalRender(bool bEnable)
int layer
Definition: LiveRoom.h:134
unsigned int fileSize
Definition: LiveRoom.h:97
ZEGO_API bool SetMediaSideCallback(IMediaSideCallback *pCB)
Definition: LiveRoom.h:33
ZEGO_API bool ResumeRecordMixStream()
ZegoVideoStreamLayerType streamLayerType
Definition: LiveRoom.h:240
#define ZEGO_API
Definition: LiveRoom.h:16
virtual void OnAudioDataCallback(const char *pszStreamID, const AudioFrame &frame)
Definition: LiveRoom.h:488
Definition: LiveRoom.h:301
ZEGO_API void SetCustomToken(const char *thirdPartyToken)
ZegoFrameFillMode
Definition: LiveRoom.h:86
int sampleRate
Definition: LiveRoom.h:211
ZEGO_API bool TakeStreamSnapshot(const char *pszStreamID, const char *pszPathAndName)
Definition: LiveRoom.h:300
MuxerStreamType
Definition: LiveRoom.h:59
Definition: LiveRoom.h:177
ZEGO_API void SetConfig(const char *config)
Definition: LiveRoom.h:82