14 #include "AgoraBase.h"
20 static const uint8_t kVideoEngineFlagHasIntraRequest = 0x10;
21 static const uint8_t kVideoEngineFlagStdCodec = 0x8;
22 static const uint8_t kVideoEngineFlagNasa = 0x40;
23 static const uint8_t kVideoEngineFlagScalableDelta = 0x80;
24 static const uint8_t kVideoEngineFlagMajorStreamOnly = 0x01;
26 static const uint8_t kAgoraHeaderLength = 3;
27 static const uint8_t kAgoraAudioExtendLength = 5;
29 enum MEDIA_STREAM_TYPE {
30 MEDIA_STREAM_TYPE_AUDIO = (1 << 0),
31 MEDIA_STREAM_TYPE_VIDEO_LOW = (1 << 1),
32 MEDIA_STREAM_TYPE_VIDEO_HIGH = (1 << 2),
33 MEDIA_STREAM_TYPE_VIDEO = (MEDIA_STREAM_TYPE_VIDEO_LOW | MEDIA_STREAM_TYPE_VIDEO_HIGH),
41 uint64_t packetSentTs_;
45 SMediaFrame() : uid_(0), flags_(0), seq_(0), ssrc_(0), sentTs_(0), receiveTs_(0) {}
52 uint8_t internalFlags_;
53 uint8_t audio_fec_level_;
57 using SharedSAudioFrame = std::shared_ptr<SAudioFrame>;
60 enum AUDIO_PACKET_TYPE {
61 AUDIO_PACKET_REXFERRED = 0x1,
62 AUDIO_PACKET_FROM_VOS = 0x2,
63 AUDIO_PACKET_FROM_P2P = 0x4,
67 uint8_t internalFlags_;
70 uint16_t payloadLength_;
71 uint16_t latestFrameSeq_;
72 std::list<SharedSAudioFrame> frames_;
84 enum INTERNAL_FLAG_TYPE {
85 RTC_FLAG_REXFERRED = 0x1,
86 RTC_FLAG_FROM_VOS = 0x2,
87 RTC_FLAG_FROM_P2P = 0x4,
88 RTC_FLAG_UNIQUE_PACKET = 0x8,
89 VIDEO_FLAG_TIMESTAMP_SET = 0x10,
90 VIDEO_FLAG_CACHED = 0x20,
91 VIDEO_FLAG_VIDEO3 = 0x40,
95 uint16_t payload_length;
99 uint8_t internal_flags;
102 : uid(0), seq(0), payload_length(0), sent_ts(0), recv_ts(0), link_id(-1), internal_flags(0) {}
118 audio_packet_t() : ts(0), vad(0), codec(0), last_error(0), reqMs(0) {}
122 enum VIDEO_STREAM_TYPE {
123 VIDEO_STREAM_UNKNOWN = -1,
124 VIDEO_STREAM_HIGH = 0,
125 VIDEO_STREAM_LOW = 1,
126 VIDEO_STREAM_MEDIUM = 2,
127 VIDEO_STREAM_LIVE = 3,
128 VIDEO_STREAM_MIN = VIDEO_STREAM_HIGH,
129 VIDEO_STREAM_MAX = VIDEO_STREAM_LIVE,
132 enum VIDEO_FLAG_TYPE {
134 VIDEO_FLAG_KEY_FRAME = 0x80,
135 VIDEO_FLAG_FEC = 0x40,
136 VIDEO_FLAG_LIVE = 0x20,
137 VIDEO_FLAG_STD_CODEC = 0x8,
138 VIDEO_FLAG_B_FRAME = 0x10,
140 VIDEO_FLAG_HARDWARE_ENCODE = 0x4,
143 enum VIDEO_FRAME_TYPE {
150 enum VIDEO_CODEC_TYPE {
152 VIDEO_CODEC_H264 = 2,
154 VIDEO_CODEC_E264 = 4,
157 enum VIDEO_EXTRA_FLAG_TYPE {
159 VIDEO_EXTRA_FLAG_TIMESTAMP_SET = 0x1,
162 enum EXTENSION_VERSION {
163 EXTENSION_VERSION_0 = 0,
164 EXTENSION_VERSION_1 = 1,
165 EXTENSION_VERSION_2 = 2,
169 bool has_extension_ =
false;
170 uint16_t tag_ = EXTENSION_VERSION_0;
171 std::vector<uint32_t> content_;
182 uint8_t protocolVersion;
186 int64_t transport_seq;
206 uint8_t stream_type : 4;
207 uint8_t frame_type : 4;
212 void fromVideType(uint8_t f) {
215 streamType = t.stream_type;
216 frameType = t.frame_type;
219 uint8_t toVideoType()
const {
221 t.stream_type = streamType;
222 t.frame_type = frameType;
226 bool hasReserveBit(uint16_t bit) {
return (reserve1 & (1 << bit)) == (1 << bit); }
231 bool from_vos =
false;
247 enum VideoStreamType {
248 MASTER_VIDEO_STREAM = 0,
249 LOW_BITRATE_VIDEO_STREAM = 1,
250 MEDIUM_BITRATE_VIDEO_STREAM = 2,
251 LIVE_VIDEO_STREAM = 3,
263 unsigned int prevFrameNumber;
292 int sentTargetBitRate;
293 int sentTargetFrameRate;
294 int sentBitrateExcludeFec;
295 unsigned int encodeTimeMs;
296 unsigned int minEncodeTimeMs;
297 unsigned int maxEncodeTimeMs;
301 int encoderRecvFrames;
303 int encodedKeyFrames;
304 unsigned int totalEncodedFrames;
305 int encodeFailFrames;
306 int encoderSkipFrames;
310 int estimateBandwidth;
311 unsigned int maxFrameOutInterval;
312 int uplinkFreezeCount;
313 int uplinkFreezeTime;
314 int cameraOpenStatus;
317 uint64_t render_buffer_size;
333 unsigned int bitFieldStates;
340 sentTargetBitRate = 0;
341 sentTargetFrameRate = 0;
342 sentBitrateExcludeFec = 0;
349 encoderRecvFrames = 0;
351 encodeFailFrames = 0;
352 encoderSkipFrames = 0;
356 estimateBandwidth = 0;
357 maxFrameOutInterval = 0;
358 cameraOpenStatus = -1;
361 render_buffer_size = 0;
377 int decodeFailedFrames;
378 int decodeRejectedFrames;
381 int rendererRecvFrames;
385 unsigned int maxRenderInterval;
386 unsigned int lastRenderMs;
387 unsigned int minFrameNumber;
388 unsigned int maxFrameNumber;
389 unsigned int freezeCnt;
390 unsigned int freezeCnt300;
391 unsigned int freezeCnt500;
395 bool isHardwareDecoding;
399 uint64_t render_buffer_size;
400 int decodeBgDroppedFrames;
401 bool isSuperResolutionEnabled;
411 decodeFailedFrames = 0;
414 rendererRecvFrames = 0;
415 decodeRejectedFrames = 0;
419 maxRenderInterval = 0;
421 minFrameNumber = 0xFFFFFFFF;
429 isHardwareDecoding =
false;
432 render_buffer_size = 0;
433 decodeBgDroppedFrames = 0;
434 isSuperResolutionEnabled =
false;
442 #define VIDEO_ENGINE_FLAG_SCALABLE_DELTA 0x00000080
443 #define VIDEO_ENGINE_FLAG_NASA 0x00000040
444 #define VIDEO_ENGINE_FLAG_HAS_PISE 0x00000020
445 #define VIDEO_ENGINE_FLAG_HAS_INTRA_REQUEST 0x00000010
446 #define VIDEO_ENGINE_FLAG_STD_CODEC 0x00000008
447 #define VIDEO_ENGINE_FLAG_HARDWARE_ENCODE 0x00000004
448 #define VIDEO_ENGINE_FLAG_NEW_AVSYNC_TIMESTAMP 0x00000002
449 #define VIDEO_ENGINE_FLAG_MULTI_STREAM 0x00000001
451 enum VideoFrameType {
456 SCALABLE_DELTA_FRAME = 4,
458 enum VideoCodecType {
460 VIDEO_CODEC_H264 = 2,
462 VIDEO_CODEC_E264 = 4,
464 enum VideoFeedbackPacketType {
465 VIDEO_FEEDBACK_INTRA_REQUEST = 1,
466 VIDEO_FEEDBACK_DISABLE_INTRA_FEC = 2,
467 VIDEO_FEEDBACK_INTRA_REQUEST_QUICK = 3,
468 VIDEO_FEEDBACK_DECODE_FB = 4,
469 VIDEO_FEEDBACK_BANDWIDTH_ESTIMATION = 5,
470 VIDEO_FEEDBACK_REQUEST_MULTISTREAM = 6,
471 VIDEO_FEEDBACK_AUT = 7,
476 unsigned short packetLen;
477 unsigned int frame_num;
478 uint16_t frame_pkg_num;
479 uint16_t pkg_seq_in_frame;
480 unsigned char fec_num;
481 unsigned char fec_method;
483 VideoFrameType frame_type;
484 VideoStreamType stream_type;
487 unsigned short reserve1;
491 uint8_t recv_stream_type;
492 uint8_t expected_stream_type;
500 uint16_t queueing_time;
501 uint16_t active_uid_counts;
505 std::list<AutStreamData> stream_info;
508 virtual int sendVideoPacket(
const PacketInfo& info) = 0;
509 virtual int sendVideoRtcpPacket(
unsigned int uid,
const void* packet,
unsigned short packetLen,
bool isToVos) = 0;
512 virtual int sendVideoRtcpFeedbackPacket(
const VideoFeedbackPacketType type,
unsigned int toUid,
const void* packet,
int packetSize) = 0;
514 virtual void onRemoteFirstFrameDrawed(
int viewIndex,
unsigned int uid,
int width,
int height) = 0;
515 virtual void onLocalFirstFrameDrawed(
int width,
int height) = 0;
516 virtual void onRemoteFirstFrameDecoded(
unsigned int uid,
int width,
int height) = 0;
517 virtual void onRemoteVideoInterrupted(
unsigned int uid,
unsigned int elapse_time) = 0;
519 virtual void onVideoProfile(
unsigned int width,
unsigned int height,
unsigned int fps,
unsigned int bitrate) = 0;
520 virtual void switchVideoStream(
unsigned int uid, VideoStreamType stream) = 0;
521 virtual void onBandWidthLevelChanged(
int level) = 0;
522 virtual void onCameraFocusAreaChanged(
int x,
int y,
int width,
int height) = 0;
523 virtual void onCameraExposureAreaChanged(
int x,
int y,
int width,
int height) = 0;
524 virtual void onVideoViewSizeChanged(
int userID,
int newWidth,
int newHeight) {
530 virtual void onVideoFrameFrozen(
unsigned int uid,
bool frozen) = 0;
532 virtual void onAppSetVideoStartBitRate(
int value) = 0;
534 virtual int onEncodeVideoSEI(
char** info,
int *len) = 0;
535 virtual void onVideoSizeChanged(
unsigned int uid,
int newWidth,
int newHeight,
int newRotation) {
542 virtual void onSendVideoPaced(
bool status) = 0;
543 virtual void onBWELevel(
int level) = 0;
544 virtual void onVideoRexferStatus(
bool status,
int target_bitrate) = 0;
545 virtual void onStartCaptureSuccess() = 0;
547 virtual int onSendSEI(
char **info,
int *len,
long long timeStampMs,
int streamType,
bool isDualStream) = 0;
548 virtual int onReceiveSEI(
char *info,
int len,
unsigned int uid,
long long timeStampMs) = 0;
549 virtual void OnVideoStreamBitrateRangeChanged(VideoStreamType type,
550 uint32_t max_kbps, uint32_t min_kbps) = 0;