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_FROM_BROADCAST = 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) {}
112 : quit(
false), rtcp(
false), need_reliable(
false), real_quit(
false) {}
121 audio_packet_t() : ts(0), vad(0), codec(0), last_error(0), reqMs(0) {}
125 enum VIDEO_STREAM_TYPE {
126 VIDEO_STREAM_UNKNOWN = -1,
127 VIDEO_STREAM_HIGH = 0,
128 VIDEO_STREAM_LOW = 1,
129 VIDEO_STREAM_MEDIUM = 2,
130 VIDEO_STREAM_LIVE = 3,
131 VIDEO_STREAM_MIN = VIDEO_STREAM_HIGH,
132 VIDEO_STREAM_MAX = VIDEO_STREAM_LIVE,
135 enum VIDEO_FLAG_TYPE {
137 VIDEO_FLAG_KEY_FRAME = 0x80,
138 VIDEO_FLAG_FEC = 0x40,
139 VIDEO_FLAG_LIVE = 0x20,
140 VIDEO_FLAG_STD_CODEC = 0x8,
141 VIDEO_FLAG_B_FRAME = 0x10,
143 VIDEO_FLAG_HARDWARE_ENCODE = 0x4,
146 enum VIDEO_FRAME_TYPE {
153 enum VIDEO_CODEC_TYPE {
155 VIDEO_CODEC_H264 = 2,
157 VIDEO_CODEC_E264 = 4,
160 enum VIDEO_EXTRA_FLAG_TYPE {
162 VIDEO_EXTRA_FLAG_TIMESTAMP_SET = 0x1,
165 enum EXTENSION_VERSION {
166 EXTENSION_VERSION_0 = 0,
167 EXTENSION_VERSION_1 = 1,
168 EXTENSION_VERSION_2 = 2,
172 bool has_extension_ =
false;
173 uint16_t tag_ = EXTENSION_VERSION_0;
174 std::vector<uint32_t> content_;
185 uint8_t protocolVersion;
189 int64_t transport_seq;
209 uint8_t stream_type : 4;
210 uint8_t frame_type : 4;
215 void fromVideType(uint8_t f) {
218 streamType = t.stream_type;
219 frameType = t.frame_type;
222 uint8_t toVideoType()
const {
224 t.stream_type = streamType;
225 t.frame_type = frameType;
229 bool hasReserveBit(uint16_t bit) {
return (reserve1 & (1 << bit)) == (1 << bit); }
234 bool from_vos =
false;
250 enum VideoStreamType {
251 MASTER_VIDEO_STREAM = 0,
252 LOW_BITRATE_VIDEO_STREAM = 1,
253 MEDIUM_BITRATE_VIDEO_STREAM = 2,
254 LIVE_VIDEO_STREAM = 3,
266 unsigned int prevFrameNumber;
295 int sentTargetBitRate;
296 int sentTargetFrameRate;
297 int sentBitrateExcludeFec;
298 unsigned int encodeTimeMs;
299 unsigned int minEncodeTimeMs;
300 unsigned int maxEncodeTimeMs;
304 int encoderRecvFrames;
306 int encodedKeyFrames;
307 unsigned int totalEncodedFrames;
308 int encodeFailFrames;
309 int encoderSkipFrames;
313 int estimateBandwidth;
314 unsigned int maxFrameOutInterval;
315 int uplinkFreezeCount;
316 int uplinkFreezeTime;
317 int cameraOpenStatus;
320 uint64_t render_buffer_size;
336 unsigned int bitFieldStates;
343 sentTargetBitRate = 0;
344 sentTargetFrameRate = 0;
345 sentBitrateExcludeFec = 0;
352 encoderRecvFrames = 0;
354 encodeFailFrames = 0;
355 encoderSkipFrames = 0;
359 estimateBandwidth = 0;
360 maxFrameOutInterval = 0;
361 cameraOpenStatus = -1;
364 render_buffer_size = 0;
380 int decodeFailedFrames;
381 int decodeRejectedFrames;
384 int rendererRecvFrames;
388 unsigned int maxRenderInterval;
389 unsigned int lastRenderMs;
390 unsigned int minFrameNumber;
391 unsigned int maxFrameNumber;
392 unsigned int freezeCnt;
393 unsigned int freezeCnt300;
394 unsigned int freezeCnt500;
398 bool isHardwareDecoding;
402 uint64_t render_buffer_size;
403 int decodeBgDroppedFrames;
404 bool isSuperResolutionEnabled;
414 decodeFailedFrames = 0;
417 rendererRecvFrames = 0;
418 decodeRejectedFrames = 0;
422 maxRenderInterval = 0;
424 minFrameNumber = 0xFFFFFFFF;
432 isHardwareDecoding =
false;
435 render_buffer_size = 0;
436 decodeBgDroppedFrames = 0;
437 isSuperResolutionEnabled =
false;
445 #define VIDEO_ENGINE_FLAG_SCALABLE_DELTA 0x00000080
446 #define VIDEO_ENGINE_FLAG_NASA 0x00000040
447 #define VIDEO_ENGINE_FLAG_HAS_PISE 0x00000020
448 #define VIDEO_ENGINE_FLAG_HAS_INTRA_REQUEST 0x00000010
449 #define VIDEO_ENGINE_FLAG_STD_CODEC 0x00000008
450 #define VIDEO_ENGINE_FLAG_HARDWARE_ENCODE 0x00000004
451 #define VIDEO_ENGINE_FLAG_NEW_AVSYNC_TIMESTAMP 0x00000002
452 #define VIDEO_ENGINE_FLAG_MULTI_STREAM 0x00000001
454 enum VideoFrameType {
459 SCALABLE_DELTA_FRAME = 4,
461 enum VideoCodecType {
463 VIDEO_CODEC_H264 = 2,
465 VIDEO_CODEC_E264 = 4,
467 enum VideoFeedbackPacketType {
468 VIDEO_FEEDBACK_INTRA_REQUEST = 1,
469 VIDEO_FEEDBACK_DISABLE_INTRA_FEC = 2,
470 VIDEO_FEEDBACK_INTRA_REQUEST_QUICK = 3,
471 VIDEO_FEEDBACK_DECODE_FB = 4,
472 VIDEO_FEEDBACK_BANDWIDTH_ESTIMATION = 5,
473 VIDEO_FEEDBACK_REQUEST_MULTISTREAM = 6,
474 VIDEO_FEEDBACK_AUT = 7,
479 unsigned short packetLen;
480 unsigned int frame_num;
481 uint16_t frame_pkg_num;
482 uint16_t pkg_seq_in_frame;
483 unsigned char fec_num;
484 unsigned char fec_method;
486 VideoFrameType frame_type;
487 VideoStreamType stream_type;
490 unsigned short reserve1;
494 uint8_t recv_stream_type;
495 uint8_t expected_stream_type;
503 uint16_t queueing_time;
504 uint16_t active_uid_counts;
508 std::list<AutStreamData> stream_info;
511 virtual int sendVideoPacket(
const PacketInfo& info) = 0;
512 virtual int sendVideoRtcpPacket(
unsigned int uid,
const void* packet,
unsigned short packetLen,
bool isToVos) = 0;
515 virtual int sendVideoRtcpFeedbackPacket(
const VideoFeedbackPacketType type,
unsigned int toUid,
const void* packet,
int packetSize) = 0;
517 virtual void onRemoteFirstFrameDrawed(
int viewIndex,
unsigned int uid,
int width,
int height) = 0;
518 virtual void onLocalFirstFrameDrawed(
int width,
int height) = 0;
519 virtual void onRemoteFirstFrameDecoded(
unsigned int uid,
int width,
int height) = 0;
520 virtual void onRemoteVideoInterrupted(
unsigned int uid,
unsigned int elapse_time) = 0;
522 virtual void onVideoProfile(
unsigned int width,
unsigned int height,
unsigned int fps,
unsigned int bitrate) = 0;
523 virtual void switchVideoStream(
unsigned int uid, VideoStreamType stream) = 0;
524 virtual void onBandWidthLevelChanged(
int level) = 0;
525 virtual void onCameraFocusAreaChanged(
int x,
int y,
int width,
int height) = 0;
526 virtual void onCameraExposureAreaChanged(
int x,
int y,
int width,
int height) = 0;
527 virtual void onVideoViewSizeChanged(
int userID,
int newWidth,
int newHeight) {
533 virtual void onVideoFrameFrozen(
unsigned int uid,
bool frozen) = 0;
535 virtual void onAppSetVideoStartBitRate(
int value) = 0;
537 virtual int onEncodeVideoSEI(
char** info,
int *len) = 0;
538 virtual void onVideoSizeChanged(
unsigned int uid,
int newWidth,
int newHeight,
int newRotation) {
545 virtual void onSendVideoPaced(
bool status) = 0;
546 virtual void onBWELevel(
int level) = 0;
547 virtual void onVideoRexferStatus(
bool status,
int target_bitrate) = 0;
548 virtual void onStartCaptureSuccess() = 0;
550 virtual int onSendSEI(
char **info,
int *len,
long long timeStampMs,
int streamType,
bool isDualStream) = 0;
551 virtual int onReceiveSEI(
char *info,
int len,
unsigned int uid,
long long timeStampMs) = 0;
552 virtual void OnVideoStreamBitrateRangeChanged(VideoStreamType type,
553 uint32_t max_kbps, uint32_t min_kbps) = 0;