Agora Server Gateway SDK C++ API Reference
AgoraMediaBase.h
Go to the documentation of this file.
1//
2// Agora Engine SDK
3//
4// Created by Sting Feng in 2017-11.
5// Copyright (c) 2017 Agora.io. All rights reserved.
6
7#pragma once // NOLINT(build/header_guard)
8
9#include <cstring>
10#include <stdint.h>
11#include <limits>
12#include <stddef.h>
13
14#ifndef OPTIONAL_ENUM_SIZE_T
15#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
16#define OPTIONAL_ENUM_SIZE_T enum : size_t
17#else
18#define OPTIONAL_ENUM_SIZE_T enum
19#endif
20#endif
21
22namespace agora {
23namespace rtc {
24
25typedef unsigned int uid_t;
26typedef unsigned int track_id_t;
27typedef unsigned int conn_id_t;
28
29static const unsigned int DEFAULT_CONNECTION_ID = 0;
30static const unsigned int DUMMY_CONNECTION_ID = (std::numeric_limits<unsigned int>::max)();
31
32
34
43};
44
47 size_t channels;
49
51 : sample_rate(0),
52 channels(0),
54};
55
62
68};
69
70} // namespace rtc
71
72namespace media {
134namespace base {
135
136typedef void* view_t;
137
138typedef const char* user_id_t;
139
140static const uint8_t kMaxCodecNameLength = 50;
141
143
146enum MAX_METADATA_SIZE_TYPE {
147 MAX_METADATA_SIZE_IN_BYTE = 1024
148};
149
154struct PacketOptions {
158 uint32_t timestamp;
159 // Audio level indication.
160 uint8_t audioLevelIndication;
161 PacketOptions()
162 : timestamp(0),
163 audioLevelIndication(127) {}
164};
166
175 // Stereo, 32 kHz, 60 ms (2 * 32 * 60)
182 kMaxDataSizeSamples = 3840,
184 kMaxDataSizeBytes = kMaxDataSizeSamples * sizeof(int16_t),
185 };
186
203 int16_t data_[kMaxDataSizeSamples];
204
206 if(this == &src) {
207 return *this;
208 }
209
210 this->capture_timestamp = src.capture_timestamp;
211 this->samples_per_channel_ = src.samples_per_channel_;
212 this->sample_rate_hz_ = src.sample_rate_hz_;
213 this->bytes_per_sample = src.bytes_per_sample;
214 this->num_channels_ = src.num_channels_;
215
216 size_t length = src.samples_per_channel_ * src.num_channels_;
217 if (length > kMaxDataSizeSamples) {
218 length = kMaxDataSizeSamples;
219 }
220
221 memcpy(this->data_, src.data_, length * sizeof(int16_t));
222
223 return *this;
224 }
225
230 num_channels_(0),
232 memset(data_, 0, sizeof(data_));
233 }
234
241 size_t length = src.samples_per_channel_ * src.num_channels_;
242 if (length > kMaxDataSizeSamples) {
243 length = kMaxDataSizeSamples;
244 }
245
246 memcpy(this->data_, src.data_, length * sizeof(int16_t));
247 }
248};
249
251
253enum AUDIO_DUAL_MONO_MODE {
255 AUDIO_DUAL_MONO_STEREO = 0,
257 AUDIO_DUAL_MONO_L = 1,
259 AUDIO_DUAL_MONO_R = 2,
261 AUDIO_DUAL_MONO_MIX = 3
262};
264
266class IAudioFrameObserver {
267 public:
276 virtual void onFrame(AudioPcmFrame* frame) = 0;
277 virtual ~IAudioFrameObserver() {}
278};
280
321};
322
324
327enum RENDER_MODE_TYPE {
332 RENDER_MODE_HIDDEN = 1,
338 RENDER_MODE_FIT = 2,
343 RENDER_MODE_ADAPTIVE = 3,
344};
346
354 buffer(NULL),
355 stride(0),
356 height(0),
357 cropLeft(0),
358 cropTop(0),
359 cropRight(0),
360 cropBottom(0),
361 rotation(0),
362 timestamp(0),
363 eglContext(NULL),
364 eglType(EGL_CONTEXT10),
365 textureId(0),
366 metadata_buffer(NULL),
367 metadata_size(0),
368 alphaBuffer(NULL){}
369
371
374 enum EGL_CONTEXT_TYPE {
378 EGL_CONTEXT10 = 0,
382 EGL_CONTEXT14 = 1,
383 };
385
401 };
402
414 void* buffer;
453 long long timestamp;
455
460 void *eglContext;
464 EGL_CONTEXT_TYPE eglType;
468 int textureId;
472 float matrix[16];
477 uint8_t* metadata_buffer;
482 int metadata_size;
484
496 uint8_t* alphaBuffer;
497};
498
505 width(0),
506 height(0),
507 yStride(0),
508 uStride(0),
509 vStride(0),
510 yBuffer(NULL),
511 uBuffer(NULL),
512 vBuffer(NULL),
513 rotation(0),
514 renderTimeMs(0),
515 avsync_type(0),
516 metadata_buffer(NULL),
517 metadata_size(0),
518 sharedContext(0),
519 textureId(0),
520 alphaBuffer(NULL){}
521
529 int width;
549 uint8_t* yBuffer;
553 uint8_t* uBuffer;
557 uint8_t* vBuffer;
574
578 uint8_t* metadata_buffer;
583 int metadata_size;
587 void* sharedContext;
591 int textureId;
595 float matrix[16];
601 uint8_t* alphaBuffer;
603};
604
607 public:
615 virtual void onFrame(const VideoFrame* frame) = 0;
616 virtual ~IVideoFrameObserver() {}
617 virtual bool isExternal() { return true; }
618 virtual VIDEO_PIXEL_FORMAT getVideoPixelFormatPreference() { return VIDEO_PIXEL_UNKNOWN; }
619};
620
621enum MEDIA_PLAYER_SOURCE_TYPE {
627 MEDIA_PLAYER_SOURCE_DEFAULT,
633 MEDIA_PLAYER_SOURCE_FULL_FEATURED,
638 MEDIA_PLAYER_SOURCE_SIMPLE,
639};
641
647};
648
649} // namespace base
650
655 public:
664 };
668 struct AudioFrame {
692 void* buffer;
702
706 channels(0),
707 samplesPerSec(0),
708 buffer(NULL),
709 renderTimeMs(0),
710 avsync_type(0) {}
711 };
712
713 public:
715
724 virtual bool onRecordAudioFrame(const char* channelId, AudioFrame& audioFrame) = 0;
733 virtual bool onPlaybackAudioFrame(const char* channelId, AudioFrame& audioFrame) = 0;
742 virtual bool onMixedAudioFrame(const char* channelId, AudioFrame& audioFrame) = 0;
752 virtual bool onPlaybackAudioFrameBeforeMixing(const char* channelId, base::user_id_t userId, AudioFrame& audioFrame) {
753 (void) channelId;
754 (void) userId;
755 (void) audioFrame;
756 return true;
757 }
758};
759
764 public:
775 virtual bool onPlaybackAudioFrameBeforeMixing(const char* channelId, rtc::uid_t uid, AudioFrame& audioFrame) = 0;
776};
777
782 public:
793 virtual bool OnEncodedVideoFrame(rtc::uid_t uid, const uint8_t* imageBuffer, size_t length,
794 const rtc::EncodedVideoFrameInfo& videoEncodedFrameInfo) = 0;
795
797};
798
803 public:
805
807 PROCESS_MODE_READ_ONLY, // Observer works as a pure renderer and will not modify the original frame.
808 PROCESS_MODE_READ_WRITE, // Observer works as a filter that will process the video frame and affect the following frame processing in SDK.
809 };
810
811 public:
813
815
833 virtual bool onCaptureVideoFrame(VideoFrame& videoFrame) = 0;
835
853 virtual bool onPreEncodeVideoFrame(VideoFrame& videoFrame) = 0;
854
856 virtual bool onSecondaryCameraCaptureVideoFrame(VideoFrame& videoFrame) = 0;
857
875 virtual bool onSecondaryPreEncodeCameraVideoFrame(VideoFrame& videoFrame) = 0;
878
893 virtual bool onScreenCaptureVideoFrame(VideoFrame& videoFrame) = 0;
894
895 virtual bool onPreEncodeScreenVideoFrame(VideoFrame& videoFrame) = 0;
896
913 virtual bool onMediaPlayerVideoFrame(VideoFrame& videoFrame, int mediaPlayerId) = 0;
914
915 virtual bool onSecondaryScreenCaptureVideoFrame(VideoFrame& videoFrame) = 0;
916
917 virtual bool onSecondaryPreEncodeScreenVideoFrame(VideoFrame& videoFrame) = 0;
919
936 virtual bool onRenderVideoFrame(const char* channelId, rtc::uid_t remoteUid, VideoFrame& videoFrame) = 0;
937
938 virtual bool onTranscodedVideoFrame(VideoFrame& videoFrame) = 0;
939
946 }
947
948 /*
949 * Occurs each time needs to get preference video frame type.
950 *
951 * @return preference video pixel format.
952 */
954
962 virtual bool getRotationApplied() { return false; }
963
971 virtual bool getMirrorApplied() { return false; }
972
990 virtual uint32_t getObservedFramePosition() {
992 }
993
1001 virtual bool isExternal() { return true; }
1002};
1003
1005
1007#define MAX_CONTENT_INSPECT_MODULE_COUNT 32
1008enum CONTENT_INSPECT_RESULT {
1009 CONTENT_INSPECT_NEUTRAL = 1,
1010 CONTENT_INSPECT_SEXY = 2,
1011 CONTENT_INSPECT_PORN = 3,
1012};
1013enum CONTENT_INSPECT_DEVICE_TYPE{
1014 CONTENT_INSPECT_DEVICE_INVALID = 0,
1015 CONTENT_INSPECT_DEVICE_AGORA = 1,
1016 CONTENT_INSPECT_DEVICE_HIVE = 2,
1017 CONTENT_INSPECT_DEVICE_TUPU = 3
1018};
1019enum CONTENT_INSPECT_TYPE {
1023CONTENT_INSPECT_INVALIDE = 0,
1027CONTENT_INSPECT_MODERATION = 1,
1031CONTENT_INSPECT_SUPERVISE = 2
1032};
1033struct ContentInspectModule {
1037 CONTENT_INSPECT_TYPE type;
1041 unsigned int frequency;
1042};
1044
1056};
1057} // namespace media
1058} // namespace agora
Definition: AgoraMediaBase.h:654
virtual bool onPlaybackAudioFrame(const char *channelId, AudioFrame &audioFrame)=0
virtual ~IAudioFrameObserverBase()
Definition: AgoraMediaBase.h:714
AUDIO_FRAME_TYPE
Definition: AgoraMediaBase.h:659
@ FRAME_TYPE_PCM16
Definition: AgoraMediaBase.h:663
virtual bool onRecordAudioFrame(const char *channelId, AudioFrame &audioFrame)=0
virtual bool onMixedAudioFrame(const char *channelId, AudioFrame &audioFrame)=0
virtual bool onPlaybackAudioFrameBeforeMixing(const char *channelId, base::user_id_t userId, AudioFrame &audioFrame)
Definition: AgoraMediaBase.h:752
Definition: AgoraMediaBase.h:763
virtual bool onPlaybackAudioFrameBeforeMixing(const char *channelId, rtc::uid_t uid, AudioFrame &audioFrame)=0
Definition: AgoraMediaBase.h:781
virtual ~IVideoEncodedFrameObserver()
Definition: AgoraMediaBase.h:796
virtual bool OnEncodedVideoFrame(rtc::uid_t uid, const uint8_t *imageBuffer, size_t length, const rtc::EncodedVideoFrameInfo &videoEncodedFrameInfo)=0
Definition: AgoraMediaBase.h:802
virtual base::VIDEO_PIXEL_FORMAT getVideoPixelFormatPreference()
Definition: AgoraMediaBase.h:953
virtual bool isExternal()
Definition: AgoraMediaBase.h:1001
virtual bool onRenderVideoFrame(const char *channelId, rtc::uid_t remoteUid, VideoFrame &videoFrame)=0
VIDEO_FRAME_PROCESS_MODE
Definition: AgoraMediaBase.h:806
@ PROCESS_MODE_READ_ONLY
Definition: AgoraMediaBase.h:807
@ PROCESS_MODE_READ_WRITE
Definition: AgoraMediaBase.h:808
virtual ~IVideoFrameObserver()
Definition: AgoraMediaBase.h:812
virtual bool onPreEncodeVideoFrame(VideoFrame &videoFrame)=0
virtual uint32_t getObservedFramePosition()
Definition: AgoraMediaBase.h:990
virtual bool onTranscodedVideoFrame(VideoFrame &videoFrame)=0
media::base::VideoFrame VideoFrame
Definition: AgoraMediaBase.h:804
virtual VIDEO_FRAME_PROCESS_MODE getVideoFrameProcessMode()
Definition: AgoraMediaBase.h:944
virtual bool getMirrorApplied()
Definition: AgoraMediaBase.h:971
virtual bool getRotationApplied()
Definition: AgoraMediaBase.h:962
static const uint8_t kMaxCodecNameLength
Definition: AgoraMediaBase.h:140
VIDEO_MODULE_POSITION
Definition: AgoraMediaBase.h:642
@ POSITION_PRE_RENDERER
Definition: AgoraMediaBase.h:644
@ POSITION_POST_FILTERS
Definition: AgoraMediaBase.h:646
@ POSITION_POST_CAPTURER
Definition: AgoraMediaBase.h:643
@ POSITION_PRE_ENCODER
Definition: AgoraMediaBase.h:645
const char * user_id_t
Definition: AgoraMediaBase.h:138
void * view_t
Definition: AgoraMediaBase.h:136
VIDEO_PIXEL_FORMAT
Definition: AgoraMediaBase.h:284
@ VIDEO_TEXTURE_OES
Definition: AgoraMediaBase.h:316
@ VIDEO_TEXTURE_2D
Definition: AgoraMediaBase.h:312
@ VIDEO_PIXEL_BGRA
Definition: AgoraMediaBase.h:296
@ VIDEO_PIXEL_I420
Definition: AgoraMediaBase.h:292
@ VIDEO_PIXEL_NV21
Definition: AgoraMediaBase.h:300
@ VIDEO_PIXEL_I422
Definition: AgoraMediaBase.h:320
@ VIDEO_PIXEL_UNKNOWN
Definition: AgoraMediaBase.h:288
@ VIDEO_PIXEL_NV12
Definition: AgoraMediaBase.h:308
@ VIDEO_PIXEL_RGBA
Definition: AgoraMediaBase.h:304
MEDIA_SOURCE_TYPE
Definition: AgoraMediaBase.h:76
@ PRIMARY_SCREEN_SOURCE
Definition: AgoraMediaBase.h:96
@ AUDIO_RECORDING_SOURCE
Definition: AgoraMediaBase.h:84
@ RTC_IMAGE_JPEG_SOURCE
Definition: AgoraMediaBase.h:116
@ REMOTE_VIDEO_SOURCE
Definition: AgoraMediaBase.h:124
@ RTC_IMAGE_PNG_SOURCE
Definition: AgoraMediaBase.h:112
@ SECONDARY_CAMERA_SOURCE
Definition: AgoraMediaBase.h:92
@ CUSTOM_VIDEO_SOURCE
Definition: AgoraMediaBase.h:104
@ PRIMARY_CAMERA_SOURCE
Definition: AgoraMediaBase.h:88
@ TRANSCODED_VIDEO_SOURCE
Definition: AgoraMediaBase.h:128
@ MEDIA_PLAYER_SOURCE
Definition: AgoraMediaBase.h:108
@ RTC_IMAGE_GIF_SOURCE
Definition: AgoraMediaBase.h:120
@ AUDIO_PLAYOUT_SOURCE
Definition: AgoraMediaBase.h:80
@ SECONDARY_SCREEN_SOURCE
Definition: AgoraMediaBase.h:100
@ UNKNOWN_MEDIA_SOURCE
Definition: AgoraMediaBase.h:132
EXTERNAL_VIDEO_SOURCE_TYPE
Definition: AgoraMediaBase.h:1047
@ ENCODED_VIDEO_FRAME
Definition: AgoraMediaBase.h:1055
@ VIDEO_FRAME
Definition: AgoraMediaBase.h:1051
unsigned int track_id_t
Definition: AgoraMediaBase.h:26
BYTES_PER_SAMPLE
Definition: AgoraMediaBase.h:38
@ TWO_BYTES_PER_SAMPLE
Definition: AgoraMediaBase.h:42
unsigned int uid_t
Definition: AgoraMediaBase.h:25
unsigned int conn_id_t
Definition: AgoraMediaBase.h:27
static const unsigned int DUMMY_CONNECTION_ID
Definition: AgoraMediaBase.h:30
RAW_AUDIO_FRAME_OP_MODE_TYPE
Definition: AgoraMediaBase.h:56
@ RAW_AUDIO_FRAME_OP_MODE_READ_WRITE
Definition: AgoraMediaBase.h:67
@ RAW_AUDIO_FRAME_OP_MODE_READ_ONLY
Definition: AgoraMediaBase.h:61
static const unsigned int DEFAULT_CONNECTION_ID
Definition: AgoraMediaBase.h:29
Definition: AgoraBase.h:86
AudioFrame()
Definition: AgoraMediaBase.h:703
int channels
Definition: AgoraMediaBase.h:684
int samplesPerChannel
Definition: AgoraMediaBase.h:676
int samplesPerSec
Definition: AgoraMediaBase.h:688
int avsync_type
Definition: AgoraMediaBase.h:701
void * buffer
Definition: AgoraMediaBase.h:692
AUDIO_FRAME_TYPE type
Definition: AgoraMediaBase.h:672
agora::rtc::BYTES_PER_SAMPLE bytesPerSample
Definition: AgoraMediaBase.h:680
int64_t renderTimeMs
Definition: AgoraMediaBase.h:700
Definition: AgoraMediaBase.h:170
rtc::BYTES_PER_SAMPLE bytes_per_sample
Definition: AgoraMediaBase.h:201
AudioPcmFrame()
Definition: AgoraMediaBase.h:226
int sample_rate_hz_
Definition: AgoraMediaBase.h:195
size_t num_channels_
Definition: AgoraMediaBase.h:198
size_t samples_per_channel_
Definition: AgoraMediaBase.h:192
uint32_t capture_timestamp
Definition: AgoraMediaBase.h:189
int16_t data_[kMaxDataSizeSamples]
Definition: AgoraMediaBase.h:203
OPTIONAL_ENUM_SIZE_T
Definition: AgoraMediaBase.h:174
AudioPcmFrame & operator=(const AudioPcmFrame &src)
Definition: AgoraMediaBase.h:205
AudioPcmFrame(const AudioPcmFrame &src)
Definition: AgoraMediaBase.h:235
Definition: AgoraMediaBase.h:350
int cropTop
Definition: AgoraMediaBase.h:433
VIDEO_PIXEL_FORMAT format
Definition: AgoraMediaBase.h:410
int cropLeft
Definition: AgoraMediaBase.h:428
int cropRight
Definition: AgoraMediaBase.h:438
int stride
Definition: AgoraMediaBase.h:419
uint8_t * alphaBuffer
Definition: AgoraMediaBase.h:496
void * buffer
Definition: AgoraMediaBase.h:414
int cropBottom
Definition: AgoraMediaBase.h:443
int height
Definition: AgoraMediaBase.h:423
ExternalVideoFrame()
Definition: AgoraMediaBase.h:351
long long timestamp
Definition: AgoraMediaBase.h:453
VIDEO_BUFFER_TYPE
Definition: AgoraMediaBase.h:388
@ VIDEO_BUFFER_RAW_DATA
Definition: AgoraMediaBase.h:392
@ VIDEO_BUFFER_ARRAY
Definition: AgoraMediaBase.h:396
@ VIDEO_BUFFER_TEXTURE
Definition: AgoraMediaBase.h:400
int rotation
Definition: AgoraMediaBase.h:448
VIDEO_BUFFER_TYPE type
Definition: AgoraMediaBase.h:406
Definition: AgoraMediaBase.h:502
int uStride
Definition: AgoraMediaBase.h:541
int rotation
Definition: AgoraMediaBase.h:561
VideoFrame()
Definition: AgoraMediaBase.h:503
VIDEO_PIXEL_FORMAT type
Definition: AgoraMediaBase.h:525
int vStride
Definition: AgoraMediaBase.h:545
int avsync_type
Definition: AgoraMediaBase.h:572
uint8_t * vBuffer
Definition: AgoraMediaBase.h:557
uint8_t * yBuffer
Definition: AgoraMediaBase.h:549
int yStride
Definition: AgoraMediaBase.h:537
int height
Definition: AgoraMediaBase.h:533
int width
Definition: AgoraMediaBase.h:529
uint8_t * uBuffer
Definition: AgoraMediaBase.h:553
int64_t renderTimeMs
Definition: AgoraMediaBase.h:568
Definition: AgoraMediaBase.h:45
size_t channels
Definition: AgoraMediaBase.h:47
int sample_rate
Definition: AgoraMediaBase.h:46
AudioParameters()
Definition: AgoraMediaBase.h:50
size_t frames_per_buffer
Definition: AgoraMediaBase.h:48
Definition: AgoraBase.h:1880