# Go (/en/api-reference/api-ref/server-gateway/go)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

Server Gateway SDK API reference for Go.

## Overview

- `agoraservice` package

  | Method                             | Description                                                |
  | ---------------------------------- | ---------------------------------------------------------- |
  | [`Initialize`](#initialize)        | Initializes the `agoraservice` package.                    |
  | [`Release`](#agoraservice-release) | Releases resources occupied by the `agoraservice` package. |

- `RtcConnection`

  | Method                                      | Description                           |
  | ------------------------------------------- | ------------------------------------- |
  | [`NewRtcConnection`](#newrtcconnection)     | Creates an RTC connection object.     |
  | [`Connect`](#connect)                       | Connects to the RTC channel.          |
  | [`Disconnect`](#disconnect)                 | Disconnects from the RTC channel.     |
  | [`RenewToken`](#renewtoken)                 | Renews the token.                     |
  | [`RegisterObserver`](#registerobserver)     | Registers an RTC connection observer. |
  | [`UnregisterObserver`](#unregisterobserver) | Destroys the RTC connection observer. |
  | [`CreateDataStream`](#createdatastream)     | Creates a data stream.                |
  | [`SendStreamMessage`](#sendstreammessage)   | Sends a data stream message.          |
  | [`GetAgoraParameter`](#getagoraparameter)   | Gets the `AgoraParameter` object.     |
  | [`GetLocalUser`](#getlocaluser)             | Gets the `LocalUser` object.          |
  | [`Release`](#rtc-connection-release)        | Releases the RTC connection.          |
  | [`EnableEncryption`](#enableencryption)     | Enables encryption.                   |

- `RtcConnectionObserver`

  | Method                                                      | Description                                                    |
  | ----------------------------------------------------------- | -------------------------------------------------------------- |
  | [`OnConnected`](#onconnected)                               | Occurs when the SDK connection state changes to `3`.           |
  | [`OnDisconnected`](#ondisconnected)                         | Occurs when the SDK connection state changes to `1`.           |
  | [`OnTokenPrivilegeWillExpire`](#ontokenprivilegewillexpire) | Occurs when the token service will expire in 30 seconds.       |
  | [`OnTokenPrivilegeDidExpire`](#ontokenprivilegedidexpire)   | Occurs when the token has expired.                             |
  | [`OnUserJoined`](#onuserjoined)                             | Occurs when a remote user joins the channel.                   |
  | [`OnUserLeft`](#onuserleft)                                 | Occurs when a remote user leaves the channel.                  |
  | [`OnStreamMessageError`](#onstreammessageerror)             | Occurs when there is an error receiving a data stream message. |
  | [`OnError`](#onerror)                                       | Occurs when an error occurs.                                   |
  | [`OnEncryptionError`](#onencryptionerror)                   | Occurs when encryption errors occur.                           |

- `LocalUser`

  | Method                                                                                        | Description                                                                          |
  | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
  | [`SetUserRole`](#setuserrole)                                                                 | Sets the user role.                                                                  |
  | [`SetAudioEncoderConfiguration`](#setaudioencoderconfiguration)                               | Sets the audio encoder configuration.                                                |
  | [`PublishAudio`](#publishaudio)                                                               | Sends the local audio track to the channel.                                          |
  | [`UnpublishAudio`](#unpublishaudio)                                                           | Stops sending the local audio track to the channel.                                  |
  | [`PublishVideo`](#publishvideo)                                                               | Sends the local video track to the channel.                                          |
  | [`UnpublishVideo`](#unpublishvideo)                                                           | Stops sending the local video track to the channel.                                  |
  | [`SubscribeAudio`](#subscribeaudio)                                                           | Subscribes to the audio stream sent by a specific remote user in the channel.        |
  | [`SubscribeAllAudio`](#subscribeallaudio)                                                     | Subscribes to all audio streams sent by remote users in the channel.                 |
  | [`UnsubscribeAudio`](#unsubscribeaudio)                                                       | Stops subscribing to the audio stream sent by a specific remote user in the channel. |
  | [`UnsubscribeAllAudio`](#unsubscribeallaudio)                                                 | Stops subscribing to all audio streams sent by remote users in the channel.          |
  | [`SetPlaybackAudioFrameBeforeMixingParameters`](#setplaybackaudioframebeforemixingparameters) | Sets the playback audio format.                                                      |
  | [`RegisterAudioFrameObserver`](#registeraudioframeobserver)                                   | Registers an audio frame observer.                                                   |
  | [`UnregisterAudioFrameObserver`](#unregisteraudioframeobserver)                               | Destroys the [`AudioFrameObserver`](#audioframeobserver) object.                     |
  | [`SubscribeVideo`](#subscribevideo)                                                           | Subscribes to the video stream sent by a specific remote user in the channel.        |
  | [`SubscribeAllVideo`](#subscribeallvideo)                                                     | Subscribes to all video streams sent by remote users in the channel.                 |
  | [`UnsubscribeVideo`](#unsubscribevideo)                                                       | Stops subscribing to the video stream sent by a specific remote user in the channel. |
  | [`UnsubscribeAllVideo`](#unsubscribeallvideo)                                                 | Stops subscribing to all video streams sent by remote users in the channel.          |
  | [`RegisterLocalUserObserver`](#registerlocaluserobserver)                                     | Registers a local user observer.                                                     |
  | [`UnregisterLocalUserObserver`](#unregisterlocaluserobserver)                                 | Destroys the local user observer.                                                    |
  | [`RegisterVideoFrameObserver`](#registervideoframeobserver)                                   | Registers a [`VideoFrameObserver`](#videoframeobserver) object.                      |
  | [`UnregisterVideoFrameObserver`](#unregistervideoframeobserver)                               | Destroys the [`VideoFrameObserver`](#videoframeobserver) object.                     |
  | [`GetRtcConnection`](#getrtcconnection)                                                       | Gets the `RtcConnection` object.                                                     |
  | [`SendAudioMetaData`](#sendaudiometadata)                                                     | Sends the audio metadata.                                                            |

- `LocalUserObserver`

  | Callback                                                        | Description                                            |
  | --------------------------------------------------------------- | ------------------------------------------------------ |
  | [`OnUserAudioTrackStateChanged`](#onuseraudiotrackstatechanged) | Occurs when the state of a remote audio track changes. |
  | [`OnStreamMessage`](#onstreammessage)                           | Occurs when a data stream message is received.         |
  | [`OnUserInfoUpdated`](#onuserinfoupdated)                       | Occurs when user media information is updated.         |
  | [`OnAudioMetaDataReceived`](#onaudiometadatareceived)           | Occurs when the remote audio metadata is received.     |

- `LocalAudioTrack`

  | Method                                                              | Description                                                                 |
  | ------------------------------------------------------------------- | --------------------------------------------------------------------------- |
  | [`NewCustomAudioTrackPcm`](#newcustomaudiotrackpcm)                 | Creates a custom PCM data track.                                            |
  | [`NewCustomAudioTrackEncoded`](#newcustomaudiotrackencoded)         | Creates a custom encoded data track.                                        |
  | [`SetEnabled`](#setenabled)                                         | Enables or disables the local audio track.                                  |
  | [`AdjustPublishVolume`](#adjustpublishvolume)                       | Adjusts the audio publish volume.                                           |
  | [`SetMaxBufferedAudioFrameNumber`](#setmaxbufferedaudioframenumber) | Sets the maximum capacity of the audio send buffer.                         |
  | [`ClearSenderBuffer`](#clearsenderbuffer)                           | Clears the current audio send buffer.                                       |
  | [`SetSendDelayMs`](#setsenddelayms)                                 | Sets the minimum data duration allowed to be sent by the audio send buffer. |
  | [`Release`](#local-audiotrack-release)                              | Releases the local audio track resources.                                   |

- `LocalVideoTrack`

  | Method                                                          | Description                                                                              |
  | --------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
  | [`NewCustomVideoTrackFrame`](#newcustomvideotrackframe)         | Creates a local video track object with a video source that sends YUV format video data. |
  | [`NewCustomVideoTrackEncoded`](#newcustomvideotrackencoded)     | Creates a local video track object with a video source that sends encoded video data.    |
  | [`SetEnabled`](#local-video-track-set-enabled)                  | Enables or disables the local video track.                                               |
  | [`SetVideoEncoderConfiguration`](#setvideoencoderconfiguration) | Sets the video encoder properties.                                                       |

- `MediaNodeFactory`

  | Method                                        | Description                             |
  | --------------------------------------------- | --------------------------------------- |
  | [`NewMediaNodeFactory`](#newmedianodefactory) | Creates a media node factory object.    |
  | [`Release`](#media-node-factory-release)      | Releases the `MediaNodeFactory` object. |

- `AudioEncodedFrameSender`

  | Method                                                      | Description                                            |
  | ----------------------------------------------------------- | ------------------------------------------------------ |
  | [`NewAudioEncodedFrameSender`](#newaudioencodedframesender) | Creates an encoded audio data sending module.          |
  | [`SendEncodedAudioFrame`](#sendencodedaudioframe)           | Sends an encoded audio frame to the local audio track. |
  | [`Release`](#audio-encoded-frame-sender-release)            | Releases the `AudioEncodedFrameSender` object.         |

- `AudioPcmDataSender`

  | Method                                            | Description                                           |
  | ------------------------------------------------- | ----------------------------------------------------- |
  | [`NewAudioPcmDataSender`](#newaudiopcmdatasender) | Creates a PCM data sending module.                    |
  | [`SendAudioPcmData`](#sendaudiopcmdata)           | Sends PCM format audio data to the local audio track. |
  | [`Release`](#audio-pcm-data-sender-release)       | Releases the `AudioPcmDataSender` object.             |

- `AudioFrameObserver`

  | Callback                                                                | Description                                           |
  | ----------------------------------------------------------------------- | ----------------------------------------------------- |
  | [`OnPlaybackAudioFrameBeforeMixing`](#onplaybackaudioframebeforemixing) | Occurs when the audio data before mixing is received. |

- `VideoEncodedImageSender`

  | Method                                                      | Description                                      |
  | ----------------------------------------------------------- | ------------------------------------------------ |
  | [`NewVideoEncodedImageSender`](#newvideoencodedimagesender) | Creates an encoded video data sending module.    |
  | [`SendEncodedVideoImage`](#sendencodedvideoimage)           | Sends an encoded video frame to the video track. |

- `VideoEncodedFrameObserver`

  | Callback                                      | Description                                     |
  | --------------------------------------------- | ----------------------------------------------- |
  | [`OnEncodedVideoFrame`](#onencodedvideoframe) | Occurs when an encoded video frame is received. |

- `VideoFrameSender`

  | Method                                        | Description                                        |
  | --------------------------------------------- | -------------------------------------------------- |
  | [`NewVideoFrameSender`](#newvideoframesender) | Creates a raw video data sending module.           |
  | [`SendVideoFrame`](#sendvideoframe)           | Sends a YUV format video frame to the video track. |

- `VideoFrameObserver`

  | Callback              | Description                            |
  | --------------------- | -------------------------------------- |
  | [`OnFrame`](#onframe) | Occurs when a video frame is received. |

## `agoraservice` package

The `agoraservice` package serves as the entry point for the SDK, allowing you to create media tracks and establish connections.

### `Initialize`

Initialize the `agoraservice` package:

```go
func Initialize(cfg *AgoraServiceConfig) int
```

#### Parameters

| Parameter | Description                                                                                |
| --------- | ------------------------------------------------------------------------------------------ |
| `cfg`     | Initialization configuration. See [`AgoraServiceConfig`](#agoraserviceconfig) for details. |

#### Returns

- `0`: Success.
- `< 0`: Failure.

### `Release`

Release the resources occupied by the `agoraservice` package:

```go
func Release() int
```

## RtcConnection

The `RtcConnection` class is used to manage the connection between the SDK and the RTC channel. Once the connection is established, you can use the `LocalUser` object to send and receive media streams in the RTC channel. Connecting to the channel is an asynchronous operation, and you can monitor connection state changes and events through the [`RtcConnectionObserver`](#rtcconnectionobserver) object. `RtcConnection` can also monitor whether a remote user joins or leaves the channel.

### `NewRtcConnection`

Creates an RTC connection object.

```go
func NewRtcConnection(cfg *RtcConnectionConfig) *RtcConnection
```

#### Parameters

| Parameter | Description                                                                                  |
| --------- | -------------------------------------------------------------------------------------------- |
| `cfg`     | RTC connection configuration. See [`RtcConnectionConfig`](#rtcconnectionconfig) for details. |

#### Returns

- `RtcConnection` object, if the method call succeeds.
- `nil`, if the method call fails.

### Connect

Connects to the RTC channel.

```go
func (conn *RtcConnection) Connect(token string, channel string, uid string) int
```

When the method succeeds, the connection state changes from `true` to `2`.

Depending on whether the connection is successful, the connection state will change to `3` or `5`. The SDK will trigger [`OnConnected`](#onconnected) or [`OnDisconnected`](#ondisconnected) to notify the connection state change.

#### Parameters

| Parameter | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `token`   | RTC Token. See [Use tokens](/en/realtime-media/rtc/build/authenticate-users/authentication-workflow) for details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `channel` | Channel name. Must be a string with a length of no more than 64 bytes. Supported character types include: - All lowercase letters: a to z; - All uppercase letters: A to Z; - All Arabic numerals: 0 to 9; - Space; - Punctuation and other special symbols: `!`, `#`, `$`, `%`, `&`, `(`, `)`, `+`, `-`, `:`, `;`, `<`, `=`, `.`, `>`, `?`, `@`, `[`, `]`, `^`, `_`, `{`, `}`, `\|`, `~`, `,`                                                                                                                                                                                                                                                                                                                                                           |
| `uid`     | Local user ID. No more than 64 bytes in length. If you do not set a user ID or set it to nil, the SDK will automatically return a user ID in the `OnConnected` callback. You must save and manage this ID yourself. Depending on the user ID type you choose in the [`Initialize`](#initialize) method, the supported character sets for this parameter are different: - For int type user ID, the supported character set includes 10 digits 0-9 - For String type user ID, the supported character set includes: - 26 lowercase English letters a-z; - 26 uppercase English letters A-Z; - 10 digits 0-9; - Space; - `!`, `#`, `$`, `%`, `&`, `(`, `)`, `+`, `-`, `:`, `;`, `<`, `=`, `.`, `>`, `?`, `@`, `[`, `]`, `^`, `_`, `{`, `}`, `\|`, `~`, `,` |

#### Returns

- `0`: Success.
- < `0`: Failure.
  - `-2`: Invalid parameter.
  - `-8`: The current connection state is not `true`.

### `Disconnect`

Disconnects from the RTC channel. When the SDK disconnects from the channel, the connection state changes to `true`. You can also be notified through the [`OnDisconnected`](#ondisconnected) callback.

```go
func (conn *RtcConnection) Disconnect() int
```

#### Returns

- `0`: Success.
- < `0`: Failure.

### `RenewToken`

Renews the Token. The Token will expire after a certain period. When you receive the [`OnTokenPrivilegeWillExpire`](#ontokenprivilegewillexpire) callback, you must generate a new token from your server and use this method to update the token. Otherwise, the SDK will disconnect from the channel.

```go
func (conn *RtcConnection) RenewToken(token string) int
```

#### Parameters

| Parameter | Description    |
| --------- | -------------- |
| `token`   | The new Token. |

#### Returns

- `0`: Success.
- < `0`: Failure.

### `RegisterObserver`

Registers an RTC connection observer.

```go
func (conn *RtcConnection) RegisterObserver(handler *RtcConnectionObserver) int
```

#### Parameters

| Parameter | Description                                               |
| --------- | --------------------------------------------------------- |
| `handler` | [`RtcConnectionObserver`](#rtcconnectionobserver) object. |

#### Returns

- `0`: Success.
- < `0`: Failure.

### `UnregisterObserver`

Unregisters the RTC connection observer.

```go
func (conn *RtcConnection) UnregisterObserver() int
```

#### Returns

- `0`: Success.
- < `0`: Failure.

### `CreateDataStream`

Creates a data stream.

```go
func (conn *RtcConnection) CreateDataStream(reliable bool, ordered bool) (int, int)
```

Each user can create up to 5 data streams per channel.

> **Note**
>
> - Agora does not support setting `reliable` to `true` and `ordered` to `false`.
> - When immediate data packet delivery is required, do not set the `ordered` parameter to `true`.

#### Parameters

| Parameter  | Description                                                                                                                                                                                                                                    |
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `reliable` | Indicates whether the data stream is reliable: - `true`: The receiver will receive the data sent by the sender within 5 seconds. - `false`: The receiver is not guaranteed to receive the data, and no error will be reported if data is lost. |
| `ordered`  | Indicates whether the data stream is ordered: - `true`: The receiver will receive data packets in the order sent by the sender. - `false`: The receiver is not guaranteed to receive data packets in the order sent by the sender.             |

#### Returns

- `stream_id`: The stream ID, if the method call succeeds.
- `nil`, if the method call fails.

### `SendStreamMessage`

Sends a data stream message.

```go
func (conn *RtcConnection) SendStreamMessage(streamId int, msg []byte) int
```

This method sends a data stream message to all users in the channel. The SDK imposes the following restrictions on this method:

- A maximum of 30 packets can be sent per second within the channel, with each packet being up to 1 KB in size.
- Each client can send up to 6 KB of data per second.
- Each user in the channel can have up to 5 data channels simultaneously.

Upon successfully calling this method, the remote end will trigger the [`OnStreamMessage`](#onstreammessage) callback, where the remote user can receive the stream message.

> **Note**
>
> - Ensure that you have called [`CreateDataStream`](#createdatastream) to create a data channel before using this method.
> - In a live broadcast use-case, this method is only applicable to host users.

#### Parameters

| Parameter   | Description                                                                             |
| ----------- | --------------------------------------------------------------------------------------- |
| `stream_id` | The data stream ID. It can be obtained through [`CreateDataStream`](#createdatastream). |
| `data`      | The data to be sent.                                                                    |

#### Returns

- `0`: Success.
- < `0`: Failure.

### `GetAgoraParameter`

Get `AgoraParameter` object.

```go
func (conn *RtcConnection) GetAgoraParameter() *AgoraParameter
```

#### Returns

- `AgoraParameter` object, if the method call was succeeds.
- `nil`, if the method call fails.

### `GetLocalUser`

Get `LocalUser` Object. Each connection corresponds to only one local user.

```go
func (conn *RtcConnection) GetLocalUser() *LocalUser
```

#### Returns

- `LocalUser` object, if the method call succeeds.
- `nil`, if the method call fails.

### `Release`

Releases the RTC connection.

```go
func (conn *RtcConnection) Release()
```

### EnableEncryption

```go
func (conn *RtcConnection) EnableEncryption(enable int, config *EncryptionConfig) int
```

Enables encryption.

> **Info: Since**
>
> v2.2.4.

This method needs to be called before [`Connect`](#connect). You need to set the encryption mode and encryption configuration in this method.

#### Parameters

**`enable`**

Whether to enable encryption functionality.

- `1`: Enable
- `0`: Disable

**`config`**

The encryption configuration: [`EncryptionConfig`](#encryptionconfig).

#### Return Values

- `0`: Success.
- < `0`: Failure.

## RtcConnectionObserver

The `RtcConnectionObserver` class is used to monitor the SDK connection state.

### `OnConnected`

Triggered when the SDK's connection state to the channel changes to `3`.

```go
OnConnected func(con *RtcConnection, conInfo *RtcConnectionInfo, reason int)
```

#### Parameters

**`con`**

The RTC connection object. See [`RtcConnection`](#rtcconnection) for details.

**`conInfo`**

Connection information. See [`RtcConnectionInfo`](#rtcconnectioninfo) for details.

**`reason`**

Connection state change reason:

- `0`: Establishing a network connection.

- `1`: Successfully joined the channel.

- `2`: Network connection interrupted.

- `3`: Network connection forbidden by the server.

- `4`: Failed to join the channel.

- `5`: Left the channel.

- `6`: Invalid App ID. Please change to a valid App ID and try again.

- `7`: Invalid channel name. Please change to a valid channel name and try again.

- `8`: The generated token is invalid. Generally, the following reasons:
  - App Certificate is enabled on the console, but the Token is not used when joining the channel. When App Certificate is enabled, you must use a Token.
  - The uid specified in [`connect`](#connect) when joining the channel does not match the uid used when generating the Token.

- `9`: The generated Token is invalid.

- `10`: This user is banned by the server.

- `11`: SDK attempts to reconnect due to setting a proxy server.

- `12`: The network connection state changes due to updating the Token.

- `13`: The client IP address changes, possibly due to changes in network type or the IP or port of the network operator.

- `14`: SDK connection to the server times out, enters the automatic reconnection state.

- `15`: Rejoined the channel successfully.

- `16`: SDK and the server lose connection.

- `17`: The connection state changes due to the echo test.

- `18`: The user changed the local IP address.

### `OnDisconnected`

Triggered when the SDK's connection state to the channel changes to `1`.

```go
OnDisconnected func(con *RtcConnection, conInfo *RtcConnectionInfo, reason int)
```

#### Parameters

**`con`**

RTC connection object. See [`RtcConnection`](#rtcconnection) for details.

**`conInfo`**

Connection information. See [`RtcConnectionInfo`](#rtcconnectioninfo) for details.

**`reason`**

Connection state change reason:

- `0`: Establishing a network connection.

- `1`: Successfully joined the channel.

- `2`: Network connection interrupted.

- `3`: Network connection forbidden by the server.

- `4`: Failed to join the channel.

- `5`: Left the channel.

- `6`: Invalid App ID. Please change to a valid App ID and try again.

- `7`: Invalid channel name. Please change to a valid channel name and try again.

- `8`: The generated token is invalid. Generally, the following reasons:
  - App Certificate is enabled on the console, but the Token is not used when joining the channel. When App Certificate is enabled, you must use a Token.
  - The uid specified in [`connect`](#connect) when joining the channel does not match the uid used when generating the Token.

- `9`: The generated Token is invalid.

- `10`: This user is banned by the server.

- `11`: SDK attempts to reconnect due to setting a proxy server.

- `12`: The network connection state changes due to updating the Token.

- `13`: The client IP address changes, possibly due to changes in network type or the IP or port of the network operator.

- `14`: SDK connection to the server times out, enters the automatic reconnection state.

- `15`: Rejoined the channel successfully.

- `16`: SDK and the server lose connection.

- `17`: The connection state changes due to the echo test.

- `18`: The user changed the local IP address.

### `OnTokenPrivilegeWillExpire`

Triggered when the token is about to expire within 30 seconds.

```go
OnTokenPrivilegeWillExpire func(con *RtcConnection, token string)
```

During a call, if the token is about to expire, the SDK will trigger this callback 30 seconds in advance to remind the app to update the token.

Upon receiving this callback, you need to generate a new token on your server and then call [`RenewToken`](#renewtoken) to pass the newly generated token to the SDK.

#### Parameters

| Parameter | Description                                                               |
| --------- | ------------------------------------------------------------------------- |
| `con`     | RTC connection object. See [`RtcConnection`](#rtcconnection) for details. |
| `token`   | The token that is about to expire.                                        |

### `OnTokenPrivilegeDidExpire`

Triggered when the token has expired.

```go
OnTokenPrivilegeDidExpire func(con *RtcConnection)
```

During a call, if the token has expired, the SDK will trigger this callback to remind the app to update the token.

Upon receiving this callback, you need to generate a new token on your server and then call [`Connect`](#connect) to reconnect to the channel.

#### Parameters

| Parameter | Description                                                               |
| --------- | ------------------------------------------------------------------------- |
| `con`     | RTC connection object. See [`RtcConnection`](#rtcconnection) for details. |

### `OnUserJoined`

Triggered when a remote user joins the channel. You can use this callback to get the ID of the remote user.

```go
OnUserJoined func(con *RtcConnection, uid string)
```

#### Parameters

| Parameter | Description                                                               |
| --------- | ------------------------------------------------------------------------- |
| `con`     | RTC connection object. See [`RtcConnection`](#rtcconnection) for details. |
| `uid`     | User ID of the remote user.                                               |

### `OnUserLeft`

Triggered when a remote user leaves the channel. You can use the `reason` parameter to get the reason why the user left the channel.

```go
OnUserLeft func(con *RtcConnection, uid string, reason int)
```

#### Parameters

**`con`**

RTC connection object. See [`RtcConnection`](#rtcconnection) for details.

**`uid`**

User ID of the remote user.

**`reason`**

Connection state change reason:

- `0`: Establishing a network connection.

- `1`: Successfully joined the channel.

- `2`: Network connection interrupted.

- `3`: Network connection forbidden by the server.

- `4`: Failed to join the channel.

- `5`: Left the channel.

- `6`: Invalid App ID. Please change to a valid App ID and try again.

- `7`: Invalid channel name. Please change to a valid channel name and try again.

- `8`: The generated token is invalid. Generally, the following reasons:
  - App Certificate is enabled on the console, but the Token is not used when joining the channel. When App Certificate is enabled, you must use a Token.
  - The uid specified in [`connect`](#connect) when joining the channel does not match the uid used when generating the Token.

- `9`: The generated Token is invalid.

- `10`: This user is banned by the server.

- `11`: SDK attempts to reconnect due to setting a proxy server.

- `12`: The network connection state changes due to updating the Token.

- `13`: The client IP address changes, possibly due to changes in network type or the IP or port of the network operator.

- `14`: SDK connection to the server times out, enters the automatic reconnection state.

- `15`: Rejoined the channel successfully.

- `16`: SDK and the server lose connection.

- `17`: The connection state changes due to the echo test.

- `18`: The user changed the local IP address.

### `OnStreamMessageError`

Triggered when an error occurs in receiving stream messages. This callback indicates that the local user did not receive the stream message sent by the remote user using the [`send_stream_message`](#sendstreammessage) method.

```go
OnStreamMessageError func(con *RtcConnection, uid string, streamId int, errCode int, missed int, cached int)
```

#### Parameters

| Parameter  | Description                                                               |
| ---------- | ------------------------------------------------------------------------- |
| `con`      | RTC connection object. See [`RtcConnection`](#rtcconnection) for details. |
| `uid`      | User ID of the sender.                                                    |
| `streamId` | Stream ID of the received message.                                        |
| `errCode`  | Error code of the occurred error.                                         |
| `missed`   | Number of missed messages.                                                |
| `cached`   | Number of cached messages when the stream was interrupted.                |

### `OnError`

Triggered when an error occurs. This callback method indicates that a network or media-related error occurred while the SDK was running. Generally, errors reported by the SDK mean that the SDK cannot automatically recover and requires intervention from the app or user notification.

```go
OnError func(con *RtcConnection, err int, msg string)
```

#### Parameters

| Parameter | Description                                                               |
| --------- | ------------------------------------------------------------------------- |
| `con`     | RTC connection object. See [`RtcConnection`](#rtcconnection) for details. |
| `err`     | Error code.                                                               |
| `msg`     | Error description.                                                        |

### `OnEncryptionError`

```go
OnEncryptionError func(con *RtcConnection, err int)
```

Occurs when encryption errors occur.

> **Info: Since**
>
> v2.2.4.

#### Parameters

| Parameter | Description                               |
| --------- | ----------------------------------------- |
| `con`     | [`RtcConnection`](#rtcconnection) object. |
| `err`     | Error code.                               |

## LocalUser

The `LocalUser` class defines the behavior and state of the local user. Each RTC connection has its own user. You can get the local user through [`GetLocalUser`](#getlocaluser). Each user has two roles: broadcaster (can send and receive audio and video streams) and audience (can only receive audio and video streams).

### `SetUserRole`

Sets the user role. You can call this method before or after the user connects to the channel.

```go
func (localUser *LocalUser) SetUserRole(role int) int
```

> **Note**
>
> If the `role` set in the `token` parameter of [`Connect`](#connect) is different from the role set here, the connection will fail.

#### Parameters

| Parameter | Description                                             |
| --------- | ------------------------------------------------------- |
| `role`    | User role. See [`ClientRole`](#clientrole) for details. |

#### Returns

- `0`: Success.
- < `0`: Failure.

### `SetAudioEncoderConfiguration`

Sets audio encoding. The SDK will apply the configuration to all sent audio tracks.

```go
func (localUser *LocalUser) SetAudioEncoderConfiguration(config *AudioEncoderConfiguration) int
```

#### Parameters

| Parameter | Description                                                                                              |
| --------- | -------------------------------------------------------------------------------------------------------- |
| `config`  | Audio encoding configuration. See [`AudioEncoderConfiguration`](#audioencoderconfiguration) for details. |

#### Returns

- `0`: Success.
- < `0`: Failure.

### `PublishAudio`

Sends the local audio track to the channel. By default, all published audio tracks are mixed.

```go
func (localUser *LocalUser) PublishAudio(track *LocalAudioTrack) int
```

#### Parameters

| Parameter | Description                                                                                   |
| --------- | --------------------------------------------------------------------------------------------- |
| `track`   | The local audio track to be published. See [`LocalAudioTrack`](#localaudiotrack) for details. |

#### Returns

- `0`: Success.
- < `0`: Failure.
  - `-5`: Returned if the local user's role is not a broadcaster.

### UnpublishAudio

Stops sending the local audio track to the channel.

```go
func (localUser *LocalUser) UnpublishAudio(track *LocalAudioTrack) int
```

#### Parameters

| Parameter | Description                                                                                      |
| --------- | ------------------------------------------------------------------------------------------------ |
| `track`   | The local audio track to stop publishing. See [`LocalAudioTrack`](#localaudiotrack) for details. |

#### Returns

- `0`: Success.
- < `0`: Failure.

### `PublishVideo`

Sends the local video track to the channel.

```go
func (localUser *LocalUser) PublishVideo(track *LocalVideoTrack) int
```

#### Parameters

| Parameter | Description                                                                                   |
| --------- | --------------------------------------------------------------------------------------------- |
| `track`   | The local video track to be published. See [`LocalVideoTrack`](#localvideotrack) for details. |

#### Returns

- `0`: Success.
- < `0`: Failure.

### `UnpublishVideo`

Stops sending the local video track to the channel.

```go
func (localUser *LocalUser) UnpublishVideo(track *LocalVideoTrack) int
```

#### Parameters

| Parameter | Description                                                                                      |
| --------- | ------------------------------------------------------------------------------------------------ |
| `track`   | The local video track to stop publishing. See [`LocalVideoTrack`](#localvideotrack) for details. |

#### Returns

- `0`: Success.
- < `0`: Failure.

### `SubscribeAudio`

Subscribes to the audio stream sent by a specific remote user in the channel.

```go
func (localUser *LocalUser) SubscribeAudio(uid string) int
```

#### Parameters

| Parameter | Description                     |
| --------- | ------------------------------- |
| `uid`     | The user ID of the remote user. |

#### Returns

- `0`: Success.
- < `0`: Failure.
  - `-2`: Error returned if the user does not exist or the `uid` is invalid.

### `SubscribeAllAudio`

Subscribes to the audio streams sent by all remote users in the channel. This method will automatically subscribe to the audio streams of users who join the channel later.

```go
func (localUser *LocalUser) SubscribeAllAudio() int
```

#### Returns

- `0`: Success.
- < `0`: Failure.

### `UnsubscribeAudio`

Stops subscribing to the audio stream sent by a specific remote user in the channel.

```go
func (localUser *LocalUser) UnsubscribeAudio(uid string) int
```

#### Parameters

| Parameter | Description                     |
| --------- | ------------------------------- |
| `uid`     | The user ID of the remote user. |

#### Returns

- `0`: Success.
- < `0`: Failure.
  - `-2`: Error returned if the user does not exist or the `uid` is invalid.

### UnsubscribeAllAudio

Stops subscribing to the audio streams sent by all remote users in the channel. This method will automatically unsubscribe from the audio streams of users who join the channel later. You must call [`SubscribeAudio`](#subscribeaudio) or [`SubscribeAllAudio`](#subscribeallaudio) to resume subscribing to audio.

```go
func (localUser *LocalUser) UnsubscribeAllAudio() int
```

#### Returns

- `0`: Success.
- < `0`: Failure.

### `SetPlaybackAudioFrameBeforeMixingParameters`

Sets the playback audio format. This method sets the format of the data for the [`OnPlaybackAudioFrameBeforeMixing`](#onplaybackaudioframebeforemixing) callback.

```go
func (localUser *LocalUser) SetPlaybackAudioFrameBeforeMixingParameters(channels int, sampleRate int) int
```

#### Parameters

| Parameter    | Description                                                                             |
| ------------ | --------------------------------------------------------------------------------------- |
| `channels`   | The number of audio channels. Can be set to 1 (mono) or 2 (stereo).                     |
| `sampleRate` | The sampling rate of the audio data. Can be set to 8000, 16000, 32000, 44100, or 48000. |

#### Returns

- `0`: Success.
- < `0`: Failure.

### `RegisterAudioFrameObserver`

Registers the audio frame observer. You must implement the [`AudioFrameObserver`](#audioframeobserver) class and register the callbacks as needed.

```go
func (localUser *LocalUser) RegisterAudioFrameObserver(observer *AudioFrameObserver, enableVad int, vadConfigure *AudioVadConfigV2) int
```

#### Parameters

**`observer`**

An instance of the `AudioFrameObserver` class.

**`enableVad`**

Whether to enable the built-in voice activity detection (VAD):

- `0`: Disable VAD.
- `1`: Enable VAD. The SDK returns the VAD results in the [`OnPlaybackAudioFrameBeforeMixing`](#onplaybackaudioframebeforemixing) callback.

**`vadConfigure`**

The VAD configuration, an `AudioVadConfigV2` object. The SDK uses this parameter only when `enableVad` is `1`.

#### Returns

- `0`: Success.
- < `0`: Failure.

### `UnregisterAudioFrameObserver`

Destroys the [`AudioFrameObserver`](#audioframeobserver) object.

```go
func (localUser *LocalUser) UnregisterAudioFrameObserver() int
```

#### Returns

- `0`: Success.
- < `0`: Failure.

### `SubscribeVideo`

Subscribes to the video stream sent by a specified remote user in the channel.

```go
func (localUser *LocalUser) SubscribeVideo(uid string, options *VideoSubscriptionOptions) int
```

#### Parameters

| Parameter | Description                                                                                    |
| --------- | ---------------------------------------------------------------------------------------------- |
| `uid`     | The user ID of the remote user.                                                                |
| `options` | Subscription options. See [`VideoSubscriptionOptions`](#videosubscriptionoptions) for details. |

#### Returns

- `0`: Success.
- < `0`: Failure.
  - `-2`: Error returned if the user does not exist or the `uid` is invalid.

### `SubscribeAllVideo`

Subscribes to the video streams sent by all remote users in the channel. This method automatically subscribes to the video streams of users who join the channel later.

```go
func (localUser *LocalUser) SubscribeAllVideo(options *VideoSubscriptionOptions) int
```

#### Parameters

| Parameter | Description                                                                                    |
| --------- | ---------------------------------------------------------------------------------------------- |
| `options` | Subscription options. See [`VideoSubscriptionOptions`](#videosubscriptionoptions) for details. |

#### Returns

- `0`: Success.
- < `0`: Failure.

### `UnsubscribeVideo`

Stops subscribing to the video stream sent by a specified remote user in the channel.

```go
func (localUser *LocalUser) UnsubscribeVideo(uid string) int
```

#### Parameters

| Parameter | Description                     |
| --------- | ------------------------------- |
| `uid`     | The user ID of the remote user. |

#### Returns

- `0`: Success.
- < `0`: Failure.
  - `-2`: Error returned if the user does not exist or the `uid` is invalid.

### `UnsubscribeAllVideo`

Stops subscribing to the video streams sent by all remote users in the channel. This method automatically unsubscribes from the video streams of users who join the channel later. You must call [`SubscribeVideo`](#subscribevideo) or [`SubscribeAllVideo`](#subscribeallvideo) to resume the subscription.

```go
func (localUser *LocalUser) UnsubscribeAllVideo() int
```

#### Returns

- `0`: Success.
- < `0`: Failure.

### `RegisterLocalUserObserver`

Registers a local user observer.

```go
func (localUser *LocalUser) RegisterLocalUserObserver(observer *LocalUserObserver) int
```

#### Parameters

| Parameter  | Description                                          |
| ---------- | ---------------------------------------------------- |
| `observer` | The [`LocalUserObserver`](#localuserobserver) class. |

#### Returns

- `0`: Success.
- < `0`: Failure.

### `UnregisterLocalUserObserver`

Destroys the local user observer.

```go
func (localUser *LocalUser) UnregisterLocalUserObserver() int
```

#### Returns

- `0`: Success.
- < `0`: Failure.

### `RegisterVideoFrameObserver`

Registers a [`VideoFrameObserver`](#videoframeobserver) object.

```go
func (localUser *LocalUser) RegisterVideoFrameObserver(observer *VideoFrameObserver) int
```

#### Parameters

| Parameter  | Description                     |
| ---------- | ------------------------------- |
| `observer` | The `VideoFrameObserver` class. |

#### Returns

- `0`: Success.
- < `0`: Failure.

### `UnregisterVideoFrameObserver`

Destroys the [`VideoFrameObserver`](#videoframeobserver) object.

```go
func (localUser *LocalUser) UnregisterVideoFrameObserver() int
```

#### Returns

- `0`: Success.
- < `0`: Failure.

### `GetRtcConnection`

Gets the `RtcConnection` object.

```go
func (localUser *LocalUser) GetRtcConnection() *RtcConnection
```

#### Returns

- `RtcConnection` object, if the method call succeeds.
- `nil`, if the method call fails.

### `SendAudioMetaData`

```go
func (localUser *LocalUser) SendAudioMetaData(metaData []byte) int
```

Sends the audio metadata.

> **Info: Since**
>
> v2.2.0.

A successful call triggers the [`OnAudioMetaDataReceived`](#onaudiometadatareceived) callback on the remote end. The remote user can get the audio metadata in this callback.

#### Parameters

| Parameter  | Description         |
| ---------- | ------------------- |
| `metaData` | The audio metadata. |

#### Returns

- `0`: Success.
- < 0: Failure.

## LocalUserObserver

The `LocalUserObserver` class.

### `OnUserAudioTrackStateChanged`

Triggered when the state of a remote audio track changes.

```go
OnUserAudioTrackStateChanged func(localUser *LocalUser, uid string, remoteAudioTrack *RemoteAudioTrack, state int, reason int, elapsed int)
```

#### Parameters

| Parameter          | Description                                                              |
| ------------------ | ------------------------------------------------------------------------ |
| `localUser`        | `LocalUserObserver` class.                                               |
| `uid`              | Remote user ID.                                                          |
| `remoteAudioTrack` | Remote audio track.                                                      |
| `state`            | Current state of the audio track.                                        |
| `reason`           | Reason for the state change.                                             |
| `elapsed`          | Time elapsed (in milliseconds) since the remote user joined the channel. |

### `OnStreamMessage`

Callback for receiving stream messages. This callback indicates that the local user has received a stream message sent by a remote user using the `SendStreamMessage` method.

```go
OnStreamMessage func(localUser *LocalUser, uid string, streamId int, data []byte)
```

#### Parameters

| Parameter   | Description                        |
| ----------- | ---------------------------------- |
| `localUser` | `LocalUserObserver` class.         |
| `uid`       | User ID of the sender.             |
| `streamId`  | Stream ID of the received message. |
| `data`      | Received data.                     |

### `OnUserInfoUpdated`

Triggered when user media information is updated.

```go
OnUserInfoUpdated func(localUser *LocalUser, uid string, userMediaInfo int, val int)
```

#### Parameters

| Parameter       | Description                                                                       |
| --------------- | --------------------------------------------------------------------------------- |
| `localUser`     | [`LocalUser`](#localuser) class.                                                  |
| `uid`           | User ID.                                                                          |
| `userMediaInfo` | User media information. See [`UserMediaInfo`](#usermediainfo) for details.        |
| `val`           | Whether the user has stopped sending streams. - `0`: Not stopped. - `1`: Stopped. |

### `OnAudioMetaDataReceived`

```go
OnAudioMetaDataReceived func(localUser *LocalUser, uid string, metaData []byte)
```

Occurs when the remote audio metadata is received.

This callback indicates that the local user has received the audio metadata sent by the remote user using the [`SendAudioMetaData`](#sendaudiometadata) method.

> **Info: Since**
>
> v2.2.0.

#### Parameters

| Parameter   | Description                      |
| ----------- | -------------------------------- |
| `localUser` | [`LocalUser`](#localuser) class. |
| `uid`       | The UID of the remote user.      |
| `metaData`  | The audio metadata.              |

## LocalAudioTrack

The `LocalAudioTrack` class is the base class for local audio tracks.

### `NewCustomAudioTrackPcm`

Creates a custom PCM data track.

```go
func NewCustomAudioTrackPcm(pcmSender *AudioPcmDataSender) *LocalAudioTrack
```

#### Parameters

| Parameter   | Description                                         |
| ----------- | --------------------------------------------------- |
| `pcmSender` | [`AudioPcmDataSender`](#audiopcmdatasender) object. |

#### Returns

- `LocalAudioTrack` object, if the method call succeeds.
- `nil`, if the method call fails.

### `NewCustomAudioTrackEncoded`

Creates a custom encoded data track.

```go
func NewCustomAudioTrackEncoded(encodedAudioSender *AudioEncodedFrameSender, mixMode AudioTrackMixingState) *LocalAudioTrack
```

#### Parameters

| Parameter            | Description                                                   |
| -------------------- | ------------------------------------------------------------- |
| `encodedAudioSender` | [`AudioEncodedFrameSender`](#audioencodedframesender) object. |
| `mixMode`            | Audio track mixing mode.                                      |

#### Returns

- `LocalAudioTrack` object, if the method call succeeds.
- `nil`, if the method call fails.

### `SetEnabled`

Enables or disables the local audio track. Once enabled, the SDK can capture, process, and encode local audio.

```go
func (track *LocalAudioTrack) SetEnabled(enable bool)
```

#### Parameters

| Parameter | Description                                                                                              |
| --------- | -------------------------------------------------------------------------------------------------------- |
| `enable`  | Whether to enable the audio track: - `true`: Enable the audio track. - `false`: Disable the audio track. |

### `AdjustPublishVolume`

Adjusts the audio publish volume.

```go
func (track *LocalAudioTrack) AdjustPublishVolume(volume int) int
```

#### Parameters

| Parameter | Description                                                                                              |
| --------- | -------------------------------------------------------------------------------------------------------- |
| `volume`  | Audio publish volume. The range is \[0, 100], where `0` means mute, and `100` means the original volume. |

#### Returns

- 0: Success.
- < 0: Failure.

### `SetMaxBufferedAudioFrameNumber`

Sets the maximum capacity of the audio send buffer.

```go
func (track *LocalAudioTrack) SetMaxBufferedAudioFrameNumber(frameNum int)
```

In applications like AI interaction, the frequency of sending audio frames from the sender may be irregular. For example, sometimes 1 frame is sent every 20 ms, and sometimes 3 frames are sent every 20 ms. If the SDK sends data to the Agora server based on the actual sending frequency, the receiver may experience stuttering or frame drops. To optimize audio transmission performance, the SDK sets an audio send buffer. Regardless of the actual frequency of sending audio frames, the SDK stores the data in the audio send buffer. Once the data in the audio send buffer reaches the minimum duration allowed to be sent, the SDK starts sending data to the receiver at a rate of 10 ms per frame.

The default maximum capacity of the audio send buffer in the SDK is 6000 frames, which means it can store up to 6000 frames of data, or 60 seconds of data. If you need a larger buffer capacity, you can call this method to adjust it. If you also need to set the minimum duration of data allowed to be sent in the audio send buffer, call the [`SetSendDelayMs`](#setsenddelayms) method.

> **Caution**
>
> This method should be called before the [`PublishAudio`](#publishaudio) method.

#### Parameters

| Parameter  | Description                                                                                                               |
| ---------- | ------------------------------------------------------------------------------------------------------------------------- |
| `frameNum` | The maximum number of audio frames stored in the buffer. For example, setting it to 6000 means 6000 frames of audio data. |

### `ClearSenderBuffer`

Clears the current audio send buffer.

```go
func (track *LocalAudioTrack) ClearSenderBuffer() int
```

If you no longer need the data in the current audio send buffer, you can call this method to clear the buffer. For example, if a user asks an AI a question and the AI is transmitting audio to the user through the SDK, the SDK's audio send buffer continuously has data in and out. When the user interrupts the AI's response and asks another question, you can call this method to let the SDK clear the current unsent buffered data to quickly buffer the AI's response to the new topic.

#### Returns

- 0: Success.
- < 0: Failure.

### `SetSendDelayMs`

Sets the minimum duration of data allowed to be sent in the audio send buffer.

```go
func (track *LocalAudioTrack) SetSendDelayMs(delayMs int) int
```

The SDK's default minimum duration of data allowed to be sent is 160 ms. This means the SDK will wait until the audio send buffer is filled with 160 ms of data before sending it to the receiver, which has the following effects:

- If the sender sends data greater than or equal to 160 ms at a time, such as 800 ms, the SDK will immediately start sending data to the receiver at a rate of 10 ms per frame.
- If the sender sends data less than 160 ms at a time, such as 100 ms, the SDK will wait until the buffer has 160 ms of data before sending it to the receiver at a rate of 10 ms per frame. This can cause a delay of up to 60 ms.

You can adjust the minimum duration of data allowed to be sent in the buffer according to your actual business needs by calling this method.

#### Parameters

| Parameter | Description                                                                                                                                                                                                                                                                                                   |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `delayMs` | The minimum duration of data allowed to be sent in the buffer (ms). This parameter needs to be set to a multiple of 10, and the value range is greater than 0 and less than 10 times the value of the `frameNum` parameter in the [`SetMaxBufferedAudioFrameNumber`](#setmaxbufferedaudioframenumber) method. |

### Release

Releases the local audio track resources.

```go
func (track *LocalAudioTrack) Release()
```

## LocalVideoTrack

The `LocalVideoTrack` class provides basic methods for local video tracks. You can publish one or more video tracks using the [`PublishVideo`](#publishvideo) method.

### `NewCustomVideoTrackFrame`

Creates a local video track object with a video source that sends YUV format video data. This track object can be used to send YUV format video data.

```go
func NewCustomVideoTrackFrame(videoSender *VideoFrameSender) *LocalVideoTrack
```

#### Parameters

| Parameter     | Description                                                                              |
| ------------- | ---------------------------------------------------------------------------------------- |
| `videoSender` | YUV format video source object. See [`VideoFrameSender`](#videoframesender) for details. |

#### Returns

- `LocalVideoTrack` object: If the method call succeeds.
- `nil`: If the method call fails.

### `NewCustomVideoTrackEncoded`

Creates a local video track object with a video source that sends encoded video data. This track object can be used to send encoded video data, such as H.264 or VP8 format encoded data.

```go
func NewCustomVideoTrackEncoded(videoSender *VideoEncodedImageSender, senderOptions *VideoEncodedImageSenderOptions) *LocalVideoTrack
```

#### Parameters

| Parameter       | Description                                                                                                         |
| --------------- | ------------------------------------------------------------------------------------------------------------------- |
| `videoSender`   | Video source for sending encoded video data. See [`VideoEncodedImageSender`](#videoencodedimagesender) for details. |
| `senderOptions` | Video track settings. See [`VideoEncodedImageSenderOptions`](#videoencodedimagesenderoptions) for details.          |

#### Returns

- `LocalVideoTrack` object: If the method call succeeds.
- `nil`: If the method call fails.

### `SetEnabled`

Enables or disables the local video track. After the local video track is enabled, the SDK can capture, process, and encode local video.

```go
func (track *LocalVideoTrack) SetEnabled(enable bool)
```

#### Parameters

| Parameter | Description                                                                                                                |
| --------- | -------------------------------------------------------------------------------------------------------------------------- |
| `enable`  | Enable or disable the local video track: - `false`: Disable the local video track. - `true`: Enable the local video track. |

### `SetVideoEncoderConfiguration`

Sets the video encoding properties.

```go
func (track *LocalVideoTrack) SetVideoEncoderConfiguration(cfg *VideoEncoderConfiguration) int
```

#### Parameters

| Parameter | Description                                                                                                        |
| --------- | ------------------------------------------------------------------------------------------------------------------ |
| `cfg`     | Video encoding parameter configuration. See [`VideoEncoderConfiguration`](#videoencoderconfiguration) for details. |

#### Returns

- `0`: If the method call succeeds.
- < `0`: If the method call fails.

## MediaNodeFactory

The `MediaNodeFactory` class.

### `NewMediaNodeFactory`

Creates a media node factory object.

```go
func NewMediaNodeFactory() *MediaNodeFactory
```

#### Returns

- `MediaNodeFactory` object, if the method call succeeds.
- `nil`, if the method call fails.

### `Release`

Releases the `MediaNodeFactory` object.

```go
func (factory *MediaNodeFactory) Release()
```

## AudioEncodedFrameSender

The `AudioEncodedFrameSender` class.

### `NewAudioEncodedFrameSender`

Creates an encoded audio data sending module. This method creates an `AudioEncodedFrameSender` object, which can be used in the [`NewCustomAudioTrackEncoded`](#newcustomaudiotrackencoded) method.

```go
func (mediaNodeFactory *MediaNodeFactory) NewAudioEncodedFrameSender() *AudioEncodedFrameSender
```

#### Returns

- `AudioEncodedFrameSender` object, if the method call succeeds.
- `nil`, if the method call fails.

### `SendEncodedAudioFrame`

Sends the encoded audio frame to the local audio track.

```go
func (sender *AudioEncodedFrameSender) SendEncodedAudioFrame(payload []byte, frameInfo *EncodedAudioFrameInfo) int
```

#### Parameters

| Parameter   | Description                                                                                           |
| ----------- | ----------------------------------------------------------------------------------------------------- |
| `payload`   | The encoded audio data to send.                                                                       |
| `frameInfo` | Information about the audio frame, see [`EncodedAudioFrameInfo`](#encodedaudioframeinfo) for details. |

#### Returns

- 0: Success.
- < 0: Failure.

### `Release`

Releases the `AudioEncodedFrameSender` object.

```go
func (sender *AudioEncodedFrameSender) Release()
```

## AudioPcmDataSender

The `AudioPcmDataSender` class.

### `NewAudioPcmDataSender`

Creates a PCM data sender module. This method creates an `AudioPcmDataSender` object, which can be used in the [`NewCustomAudioTrackPcm`](#newcustomaudiotrackpcm) method.

```go
func (mediaNodeFactory *MediaNodeFactory) NewAudioPcmDataSender() *AudioPcmDataSender
```

#### Returns

- `AudioPcmDataSender` object, if the method call succeeds.
- `nil`, if the method call fails.

### `SendAudioPcmData`

Sends PCM format audio data to the local audio track.

```go
func (sender *AudioPcmDataSender) SendAudioPcmData(frame *AudioFrame) int
```

#### Parameters

| Parameter | Description                                                                  |
| --------- | ---------------------------------------------------------------------------- |
| `frame`   | [`AudioFrame`](#audioframe) object containing the PCM audio data to be sent. |

#### Returns

- 0: Success.
- < 0: Failure.

### `Release`

Releases the `AudioPcmDataSender` object.

```go
func (sender *AudioPcmDataSender) Release()
```

## AudioFrameObserver

The `AudioFrameObserver` class.

### `OnPlaybackAudioFrameBeforeMixing`

Obtains the audio data before mixing for playback.

```go
OnPlaybackAudioFrameBeforeMixing func(localUser *LocalUser, channelId string, uid string, frame *AudioFrame, vadResultStat VadState, vadResultFrame *AudioFrame) bool
```

#### Parameters

**`localUser`**

[`LocalUser`](#localuser) class.

**`channelId`**

Channel name.

**`uid`**

User ID of the remote user.

**`frame`**

Raw audio data. See [`AudioFrame`](#audioframe) for details.

**`vadResultStat`**

The VAD state. Valid only when you enable VAD in [`RegisterAudioFrameObserver`](#registeraudioframeobserver):

- `-1` (`VadStateInvalid`): VAD is not enabled.
- `0` (`VadStateNoSpeeking`): Not speaking.
- `1` (`VadStateStartSpeeking`): Started speaking.
- `2` (`VadStateSpeeking`): Speaking.
- `3` (`VadStateStopSpeeking`): Stopped speaking.

**`vadResultFrame`**

The audio data processed by VAD. When VAD is enabled, use this data instead of `frame` for downstream processing, such as speech recognition.

#### Returns

- `true`: The audio frame data is valid and will be sent.
- `false`: The audio frame data is invalid and will be discarded.

## VideoEncodedImageSender

The `VideoEncodedImageSender` class.

### `NewVideoEncodedImageSender`

Creates a video encoded data sender module. This method creates a `VideoEncodedImageSender` object, which can be used in the [`NewCustomVideoTrackEncoded`](#newcustomvideotrackencoded) method.

```go
func (mediaNodeFactory *MediaNodeFactory) NewVideoEncodedImageSender() *VideoEncodedImageSender
```

#### Returns

- `VideoEncodedImageSender` object, if the method call succeeds.
- `nil`, if the method call fails.

### `SendEncodedVideoImage`

Sends an encoded video frame to the video track.

```go
func (sender *VideoEncodedImageSender) SendEncodedVideoImage(payload []byte, frameInfo *EncodedVideoFrameInfo) int
```

#### Parameters

| Parameter   | Description                                                                                             |
| ----------- | ------------------------------------------------------------------------------------------------------- |
| `payload`   | The video buffer.                                                                                       |
| `frameInfo` | The encoded video frame information. See [`EncodedVideoFrameInfo`](#encodedvideoframeinfo) for details. |

#### Returns

- 0: Success.
- < 0: Failure.

## VideoEncodedFrameObserver

The `VideoEncodedFrameObserver` class.

### `OnEncodedVideoFrame`

Occurs when an encoded video frame is received.

```go
OnEncodedVideoFrame func(uid string, imageBuffer []byte, frameInfo *EncodedVideoFrameInfo) bool
```

#### Parameters

| Parameter     | Description                                                                                             |
| ------------- | ------------------------------------------------------------------------------------------------------- |
| `uid`         | The user ID of the remote user.                                                                         |
| `imageBuffer` | The video frame buffer.                                                                                 |
| `frameInfo`   | The encoded video frame information. See [`EncodedVideoFrameInfo`](#encodedvideoframeinfo) for details. |

#### Returns

Whether to accept the encoded video frame:

- `true`: Accept.
- `false`: Do not accept.

## VideoFrameSender

The `VideoFrameSender` class.

### `NewVideoFrameSender`

Creates a raw video data sender module. This method creates a `VideoFrameSender` object, which can be used in the [`NewCustomVideoTrackFrame`](#newcustomvideotrackframe) method.

```go
func (mediaNodeFactory *MediaNodeFactory) NewVideoFrameSender() *VideoFrameSender
```

#### Returns

- `VideoFrameSender` object, if the method call succeeds.
- `nil`, if the method call fails.

### `SendVideoFrame`

Sends a YUV format video frame to the video track.

```go
func (sender *VideoFrameSender) SendVideoFrame(frame *ExternalVideoFrame) int
```

#### Parameters

| Parameter | Description                                                                           |
| --------- | ------------------------------------------------------------------------------------- |
| `frame`   | The video frame to send. See [`ExternalVideoFrame`](#externalvideoframe) for details. |

#### Returns

- 0: Success.
- < 0: Failure.

## VideoFrameObserver

The `VideoFrameObserver` class.

### `OnFrame`

Triggered when a video frame is received.

```go
OnFrame func(channelId string, userId string, frame *VideoFrame) bool
```

#### Parameters

| Parameter   | Description                                                  |
| ----------- | ------------------------------------------------------------ |
| `channelId` | The channel name.                                            |
| `userId`    | The user ID of the remote user.                              |
| `frame`     | The video data. See [`VideoFrame`](#videoframe) for details. |

## Data type

### Classes

#### `AgoraServiceConfig`

Global configuration for the `AgoraServiceConfig` class, set when calling the [`Initialize`](#initialize) method.

```go
type AgoraServiceConfig struct {
    EnableAudioProcessor bool
    EnableAudioDevice    bool
    EnableVideo          bool
    AppId                string
    AreaCode             AreaCode
    ChannelProfile       ChannelProfile
    AudioScenario        AudioScenario
    UseStringUid         bool
    LogPath              string
    LogSize              int
    DomainLimit          int
    ShouldCallbackWhenMuted int
    EnableSteroEncodeMode   int
}
```

**`EnableAudioProcessor`**

Whether to enable the audio processing module. - `true`: (Default) Enable the audio processing module. - `false`: Disable the audio processing module. You will not be able to create audio tracks.

**`EnableAudioDevice`**

Whether to enable the Audio Device Module (ADM). ADM is used to manage audio devices, such as recording and playing audio. - `true`: (Default) Enable the audio device module. You can record and play audio. - `false`: Disable the audio device module. You cannot record or play audio. Note: If you set `EnableAudioDevice` to `false` and `EnableAudioProcessor` to `true`, you will not be able to use audio devices, but you can push PCM audio data.

**`EnableVideo`**

Whether to enable video. - `true`: Enable video. - `false`: (Default) Disable video.

**`AppId`**

Your Agora project App ID. If your Agora project has token authentication enabled, you can also set this parameter to the RTC Token. See Get App ID for details.

**`AreaCode`**

Server access area. This feature is an advanced setting and is applicable to use-cases with access security restrictions. Area codes support bitwise operations. After specifying the access area, the SDK connects to the Agora servers within the specified area. See [`AreaCode`](#areacode) for details.

**`ChannelProfile`**

Channel use-case. See [`ChannelProfile`](#channelprofile) for details.

**`AudioScenario`**

Audio encoding properties. See [`AudioScenario`](#audioscenario) for details.

**`UseStringUid`**

Whether to use String user ID. - `true`: Use. - `false`: Do not use.

**`LogPath`**

Log file path.

**`LogSize`**

Log file size (in bytes).

**`DomainLimit`**

Whether to enable domain limit:

- `1`: Yes. Only connects to domains that are parsed by DNS
- `0`: (Default) No. There is no limit when connecting to domains

**`ShouldCallbackWhenMuted`**

Whether the SDK still triggers the [`OnPlaybackAudioFrameBeforeMixing`](#onplaybackaudioframebeforemixing) callback after a remote user mutes their audio:

- `0`: (Default) No. The SDK stops triggering the callback when the remote user mutes their audio.
- Greater than `0`: Yes. The SDK keeps triggering the callback when the remote user mutes their audio.

**`EnableSteroEncodeMode`**

Whether to enable stereo encoding mode:

- `0`: (Default) No.
- Greater than `0`: Yes. Each connection uses the `AudioScenarioGameStreaming` audio scenario and the `AudioProfileMusicHighQualityStereo` audio profile, with echo cancellation, noise suppression, and automatic gain control disabled. The encoding bitrate is 32 Kbps.

#### `AudioEncoderConfiguration`

Audio encoding settings.

```go
type AudioEncoderConfiguration struct {
    AudioProfile int
}
```

| Parameter      | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `AudioProfile` | Audio scenarios:- `0`: Default audio scenario.- In communication scenario: 16 KHz sampling rate, voice encoding, mono, maximum encoding bitrate of 16 Kbps. - In live broadcast scenario: 48 KHz sampling rate, music encoding, mono, maximum encoding bitrate of 64 Kbps. - `1`: Specifies 32 KHz sampling rate, voice encoding, mono, maximum encoding bitrate of 18 Kbps. - `2`: Specifies 48 KHz sampling rate, music encoding, mono, maximum encoding bitrate of 64 Kbps. - `3`: Specifies 48 KHz sampling rate, music encoding, stereo, maximum encoding bitrate of 80 Kbps. - `4`: Specifies 48 KHz sampling rate, music encoding, mono, maximum encoding bitrate of 96 Kbps. - `5`: Specifies 48 KHz sampling rate, music encoding, stereo, maximum encoding bitrate of 128 Kbps. - `6`: Specifies 16 KHz sampling rate, voice encoding, mono, applies Acoustic Echo Cancellation (AEC) algorithm. |

#### `AudioFrame`

PCM audio data.

```go
type AudioFrame struct {
    Type              AudioFrameType
    SamplesPerChannel int
    BytesPerSample    int
    Channels          int
    SamplesPerSec     int
    Buffer            []byte
    RenderTimeMs      int64
    AvsyncType        int
    FarFieldFlag      int
    Rms               int
    VoiceProb         int
    MusicProb         int
    Pitch             int
}
```

| Parameter           | Description                                                                                       |
| ------------------- | ------------------------------------------------------------------------------------------------- |
| `Type`              | Audio frame type. See [`AudioFrameType`](#audioframetype).                                        |
| `SamplesPerChannel` | Number of audio samples collected in 10 milliseconds for each channel.                            |
| `BytesPerSample`    | Number of bytes per sample.                                                                       |
| `Channels`          | Number of channels per sample.                                                                    |
| `SamplesPerSec`     | Sampling rate (Hz). Minimum value is 8000.                                                        |
| `Buffer`            | PCM audio data to be sent.                                                                        |
| `RenderTimeMs`      | Timestamp (in milliseconds) when the audio data was collected.                                    |
| `AvsyncType`        | Audio-video synchronization type.                                                                 |
| `FarFieldFlag`      | The far-field flag of the audio frame. Only used in audio frame observer callbacks.               |
| `Rms`               | The root mean square (RMS) of the audio frame. Only used in audio frame observer callbacks.       |
| `VoiceProb`         | The probability that the audio frame contains voice. Only used in audio frame observer callbacks. |
| `MusicProb`         | The probability that the audio frame contains music. Only used in audio frame observer callbacks. |
| `Pitch`             | The pitch of the audio frame. Only used in audio frame observer callbacks.                        |

#### `EncodedAudioFrameInfo`

Encoded audio data.

```go
type EncodedAudioFrameInfo struct {
    Speech bool
    Codec AudioCodecType
    SampleRateHz int
    SamplesPerChannel int
    SendEvenIfEmpty bool
    NumberOfChannels int
}
```

| Parameter           | Description                                                                                                                          |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `Speech`            | Indicates whether the audio source is speech: - `0`: The audio source is not speech. - `1`: (Default) The audio source is speech.    |
| `Codec`             | Audio codec type. See [`AudioCodecType`](#audiocodectype).                                                                           |
| `SampleRateHz`      | Sampling rate of the audio frame (Hz).                                                                                               |
| `SamplesPerChannel` | Number of samples per channel. Defaults to 1024 for AAC codec format and 960 for Opus codec format.                                  |
| `SendEvenIfEmpty`   | Indicates whether to send an empty audio frame: - `0`: Do not send an empty audio frame. - `1`: (Default) Send an empty audio frame. |
| `NumberOfChannels`  | Number of channels in the audio frame.                                                                                               |

#### `EncodedVideoFrameInfo`

Encoded video data.

```go
type EncodedVideoFrameInfo struct {
    CodecType        VideoCodecType
    Width            int
    Height           int
    FramesPerSecond  int
    FrameType        VideoFrameType
    Rotation         VideoOrientation
    TrackId          int
    CaptureTimeMs    int64
    DecodeTimeMs     int64
    Uid              uint32
    StreamType       int
}
```

| Parameter         | Description                                                                                                                                   |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `CodecType`       | Video codec type. See [`VideoCodecType`](#videocodectype).                                                                                    |
| `Width`           | Width of the video frame (pixels).                                                                                                            |
| `Height`          | Height of the video frame (pixels).                                                                                                           |
| `FramesPerSecond` | Number of video frames per second. Used to calculate the timestamp for the encoded video frame. If set to 0, the SDK uses the real timestamp. |
| `FrameType`       | Type of encoded video frame. See [`VideoFrameType`](#videoframetype).                                                                         |
| `Rotation`        | Rotation information of the encoded video frame. See [`VideoOrientation`](#videoorientation).                                                 |
| `TrackID`         | Track ID of the video frame.                                                                                                                  |
| `CaptureTimeMs`   | Unix timestamp (milliseconds) for capturing the external encoded video frame.                                                                 |
| `DecodeTimeMs`    | Timestamp (milliseconds) for decoding the external encoded video frame.                                                                       |
| `UID`             | User ID.                                                                                                                                      |
| `StreamType`      | Stream type of the video frame: - `0`: High stream. Higher resolution and bitrate. - `1`: Low stream. Lower resolution and bitrate.           |

#### `EncryptionConfig`

```go
type EncryptionConfig struct {
	EncryptionMode int
	EncryptionKey string
	EncryptionKdfSalt []byte
}
```

**`EncryptionMode`**

Encryption mode:

- 1: 128-bit AES encryption, XTS mode.
- 2: 128-bit AES encryption, ECB mode.
- 3: 256-bit AES encryption, XTS mode.
- 4: 128-bit SM4 encryption, ECB mode.
- 5: 128-bit AES encryption, GCM mode.
- 6: 256-bit AES encryption, GCM mode.
- 7: (Default) 128-bit AES encryption, GCM mode. This encryption mode requires setting a salt (`EncryptionKdfSalt`).
- 8: 256-bit AES encryption, GCM mode. This encryption mode requires setting a salt (`EncryptionKdfSalt`).

**`EncryptionKey`**

Encryption key, string type, with no length limit. It is recommended to use a 32-byte key.

**`encryptionKdfSalt`**

Encryption salt, 32 bytes in length. It is recommended to generate the salt using OpenSSL on the server side.

#### `ExternalVideoFrame`

YUV format video data.

```go
type ExternalVideoFrame struct {
    Type           VideoBufferType
    Format         VideoPixelFormat
    Buffer         []byte
    Stride         int
    Height         int
    CropLeft       int
    CropTop        int
    CropRight      int
    CropBottom     int
    Rotation       VideoOrientation
    Timestamp      int64
    EGLContext     unsafe.Pointer
    EGLType        int
    TextureID      int
    Matrix         [16]float32
    MetadataBuffer []byte
    AlphaBuffer    []byte
    FillAlphaBuffer bool
    AlphaMode      int
    ColorSpace     ColorSpaceType;
}
```

**`Type`**

Type of video data. See [`VideoBufferType`](#videobuffertype).

**`Format`**

Pixel format. See [`VideoPixelFormat`](#videopixelformat).

**`Buffer`**

Video buffer.

**`Stride`**

Stride of the incoming video frame, in pixels, not bytes. For Texture, this value indicates the width of the Texture.

**`Height`**

Height of the incoming video frame.

**`CropLeft`**

Field related to raw data. Specifies the number of pixels to crop from the left. Default is 0. This parameter is only applicable to raw video data.

**`CropTop`**

Field related to raw data. Specifies the number of pixels to crop from the top. Default is 0. This parameter is only applicable to raw video data.

**`CropRight`**

Field related to raw data. Specifies the number of pixels to crop from the right. Default is 0. This parameter is only applicable to raw video data.

**`CropBottom`**

Field related to raw data. Specifies the number of pixels to crop from the bottom. Default is 0. This parameter is only applicable to raw video data.

**`Rotation`**

Field related to raw data. Specifies whether to rotate the incoming video clockwise. Default is 0. See [`VideoOrientation`](#videoorientation).

**`Timestamp`**

Timestamp of the incoming video frame in milliseconds. Incorrect timestamps can cause frame drops or audio-video desynchronization.

**`EGLContext`**

This parameter is only applicable to video data in Texture format. - When using the Khronos-defined OpenGL interface (javax.microedition.khronos.egl.*), set the eglContext to this field. - When using the Android-defined OpenGL interface (android.opengl.*), set the eglContext to this field.

**`EGLType`**

This parameter is only applicable to video data in Texture format. Specifies the EGL context type.

**`TextureID`**

This parameter is only applicable to video data in Texture format. Specifies the Texture ID of the video frame.

**`Matrix`**

This parameter is only applicable to video data in Texture format. It is an input 4x4 transformation matrix, typically an identity matrix.

**`MetadataBuffer`**

The metadata buffer of the video frame. The default value is `nil`.

**`AlphaBuffer`**

Alpha channel data output by the portrait segmentation algorithm. This data matches the size of the video frame, with each pixel value ranging from \[0,255], where 0 represents the background and 255 represents the foreground (portrait). By setting this parameter, you can render the video background with various effects, such as transparency, solid color, image, or video.

**`FillAlphaBuffer`**

\[For BGRA or RGBA only] Whether to extract `alphaBuffer` from BGRA or RGBA data.

- `true`: Yes. Set it to true if you do not explicitly specify the `alphaBuffer`.
- `false`: (Default) No.

**`AlphaMode`**

The relative position between `alphaBuffer` and the frame.

- `0`: (Default) Normal frame.
- `1`: `alphaBuffer` is above the frame.
- `2`: `alphaBuffer` is below the frame.
- `3`: `alphaBuffer` is on the left of the frame.
- `4`: `alphaBuffer` is on the right of the frame.

**`ColorSpace`**

The color space of the video frame. See [`ColorSpaceType`](https://developer.mozilla.org/en-US/docs/Web/API/VideoColorSpace).

#### `RtcConnectionConfig`

RTC connection configuration.

```go
type RtcConnectionConfig struct {
    AutoSubscribeAudio bool
    AutoSubscribeVideo bool
    EnableAudioRecordingOrPlayout bool
    MaxSendBitrate int
    MinPort int
    MaxPort int
    ClientRole     ClientRole
    ChannelProfile ChannelProfile
    AudioRecvMediaPacket bool
    VideoRecvMediaPacket bool
}
```

| Parameter                       | Description                                                                                                                                                                      |
| ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `AutoSubscribeAudio`            | Whether to automatically subscribe to all audio tracks. - `0`: Do not automatically subscribe to all audio tracks. - `1`: (Default) Automatically subscribe to all audio tracks. |
| `AutoSubscribeVideo`            | Whether to automatically subscribe to all video tracks. - `0`: Do not automatically subscribe to all video tracks. - `1`: (Default) Automatically subscribe to all video tracks. |
| `EnableAudioRecordingOrPlayout` | Whether to enable audio recording or playback. - `false`: Disable audio recording or playback. - `true`: Enable audio recording or playback.                                     |
| `MaxSendBitrate`                | Maximum send bitrate.                                                                                                                                                            |
| `MinPort`                       | Minimum port.                                                                                                                                                                    |
| `MaxPort`                       | Maximum port.                                                                                                                                                                    |
| `ClientRole`                    | User role. See [`ClientRole`](#clientrole).                                                                                                                                      |
| `ChannelProfile`                | Channel profile. See [`ChannelProfile`](#channelprofile).                                                                                                                        |
| `AudioRecvMediaPacket`          | Whether to receive audio media packets. - `false`: Do not receive. - `true`: Receive.                                                                                            |
| `VideoRecvMediaPacket`          | Whether to receive video media packets. - `false`: Do not receive. - `true`: Receive.                                                                                            |

#### `RtcConnectionInfo`

RTC connection information.

```go
type RtcConnectionInfo struct {
    ConnectionId uint
    ChannelId string
    State int
    LocalUserId string
    InternalUid uint
}
```

| Parameter      | Description                                                                                                                                                                                              |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ConnectionId` | ID of the RTC connection.                                                                                                                                                                                |
| `ChannelId`    | RTC channel ID. If you have not called the [`connect`](#connect) method, this parameter returns `nil`.                                                                                                   |
| `State`        | Connection state: - `1`: Network connection disconnected. - `2`: Establishing network connection. - `3`: Network connected. - `4`: Re-establishing network connection. - `5`: Network connection failed. |
| `LocalUserId`  | Local user ID.                                                                                                                                                                                           |
| `InternalUid`  | For internal use only.                                                                                                                                                                                   |

#### `VideoEncodedImageSenderOptions`

Configuration for the local video track object containing the video source that sends encoded video data.

```go
type VideoEncodedImageSenderOptions struct {
    CcMode         VideoSendCcState
    CodecType      VideoCodecType
    TargetBitrate  int
}
```

| Parameter       | Description                                                                                                                             |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `CcMode`        | Congestion control mode. See [`VideoSendCcState`](#videosendccstate).                                                                   |
| `CodecType`     | Video codec type. See [`VideoCodecType`](#videocodectype).                                                                              |
| `TargetBitrate` | Target encoding bitrate (Kbps) for the current encoder, which is an estimated value by the SDK based on the current network conditions. |

#### `VideoEncoderConfiguration`

The video encoding properties.

```go
type VideoEncoderConfiguration struct {
    CodecType          VideoCodecType
    Width              int
    Height             int
    Framerate          int
    Bitrate            int
    MinBitrate         int
    OrientationMode    OrientationMode
    DegradePreference  DegradationPreference
    MirrorMode         VideoMirrorModeType
    EncodeAlpha        bool
}
```

| Parameter           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CodecType`         | Video codec type. See [`VideoCodecType`](#videocodectype).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `Width`             | Width of the video encoding (px).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `Height`            | Height of the video encoding (px).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `Framerate`         | Frame rate of the video encoding (fps), default is 15.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `Bitrate`           | Video encoding bitrate in Kbps.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `MinBitrate`        | Minimum encoding bitrate in Kbps. The SDK automatically adjusts the video encoding bitrate based on network conditions. Setting this parameter higher than the default value can force the video encoder to output higher quality images, but may cause packet loss and affect video playback smoothness under poor network conditions, resulting in stuttering. Therefore, unless there is a special requirement for image quality, it is recommended not to modify this parameter. **Note**: This parameter is only applicable in live broadcast scenarios.                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `OrientationMode`   | Video encoding orientation mode: - `0` (`OrientationModeAdaptive`): (Default) The output video follows the orientation of the captured video. The receiver rotates the video based on the rotation information it receives. - `1` (`OrientationModeFixedLandscape`): The SDK always outputs landscape video. If the captured video is in portrait mode, the video encoder crops it. - `2` (`OrientationModeFixedPortrait`): The SDK always outputs portrait video. If the captured video is in landscape mode, the video encoder crops it.                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `DegradePreference` | Video encoding degrade preference when bandwidth is limited: - `0` (`DegradeMaintainQuality`): (Default) When bandwidth is limited, prioritize reducing video frame rate while maintaining video quality. This degrade preference is suitable for use-cases where image quality is prioritized. - `1` (`DegradeMaintainFramerate`): When bandwidth is limited, prioritize reducing video quality while maintaining video frame rate. This degrade preference is suitable for use-cases where smoothness is prioritized and quality reduction is acceptable. - `2` (`DegradeMaintainBalanced`): When bandwidth is limited, reduce both video frame rate and video quality. The reduction in `2` is less than in `0` and `1`, suitable for use-cases with limited smoothness and quality. - `3` (`DegradeMaintainResolution`): When bandwidth is limited, reduce the video frame rate to maintain resolution. - `100` (`DegradeDisabled`): Disable video quality control adjustment. |
| `MirrorMode`        | Whether to enable mirror mode when encoding video. - `0` (`VideoMirrorModeAuto`): (Default) The SDK determines the mirror mode. - `1` (`VideoMirrorModeEnabled`): Enable mirror mode. The SDK mirrors the video frame before encoding. - `2` (`VideoMirrorModeDisabled`): Disable mirror mode.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `EncodeAlpha`       | Whether to encode and send the alpha data to the remote user when the video frame contains alpha data. - `true`: Encode and send the alpha data. - `false`: (Default) Do not encode or send the alpha data.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |

#### `VideoFrame`

Properties of the video frame. The video data format is YUV420. The buffer is given as a pointer to a pointer, and this interface cannot modify the buffer's pointer, only the content of the buffer.

```go
type VideoFrame struct {
    Type            VideoBufferType
    Width           int
    Height          int
    YStride         int
    UStride         int
    VStride         int
    YBuffer         []byte
    UBuffer         []byte
    VBuffer         []byte
    Rotation        VideoOrientation
    RenderTimeMs    int64
    AVSyncType      int
    MetadataBuffer  []byte
    SharedContext   unsafe.Pointer
    TextureID       int
    Matrix          [16]float32
    AlphaBuffer     []byte
    AlphaMode       int
}
```

| Parameter        | Description                                                                                                                                                                                                                                                                      |
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Type`           | Video data type. See [`VideoBufferType`](#videobuffertype).                                                                                                                                                                                                                      |
| `Width`          | Width of the video frame (pixels).                                                                                                                                                                                                                                               |
| `Height`         | Height of the video frame (pixels).                                                                                                                                                                                                                                              |
| `YStride`        | Stride of the Y buffer in YUV data.                                                                                                                                                                                                                                              |
| `UStride`        | Stride of the U buffer in YUV data.                                                                                                                                                                                                                                              |
| `VStride`        | Stride of the V buffer in YUV data.                                                                                                                                                                                                                                              |
| `YBuffer`        | Pointer to the pointer of the Y buffer in YUV data.                                                                                                                                                                                                                              |
| `UBuffer`        | Pointer to the pointer of the U buffer in YUV data.                                                                                                                                                                                                                              |
| `VBuffer`        | Pointer to the pointer of the V buffer in YUV data.                                                                                                                                                                                                                              |
| `Rotation`       | Clockwise rotation angle of the frame before rendering the video. See [`VideoOrientation`](#videoorientation).                                                                                                                                                                   |
| `RenderTimeMs`   | Timestamp of the external audio frame. This parameter is required. You can use this timestamp to restore the order of audio frames; in use-cases with video (including those using external video sources), this parameter helps achieve audio-video synchronization.            |
| `AVSyncType`     | Reserved parameter.                                                                                                                                                                                                                                                              |
| `MetadataBuffer` | The metadata buffer of the video frame.                                                                                                                                                                                                                                          |
| `SharedContext`  | The EGL context. Only applicable to Texture format video data.                                                                                                                                                                                                                   |
| `TextureID`      | The Texture ID of the video frame. Only applicable to Texture format video data.                                                                                                                                                                                                 |
| `Matrix`         | The input 4x4 transformation matrix. Only applicable to Texture format video data.                                                                                                                                                                                               |
| `AlphaBuffer`    | The alpha channel data of the video frame. The data matches the size of the video frame.                                                                                                                                                                                         |
| `AlphaMode`      | The relative position between `AlphaBuffer` and the frame. - `0`: (Default) Normal frame. - `1`: `AlphaBuffer` is above the frame. - `2`: `AlphaBuffer` is below the frame. - `3`: `AlphaBuffer` is on the left of the frame. - `4`: `AlphaBuffer` is on the right of the frame. |

#### `VideoSubscriptionOptions`

The video subscription options.

```go
type VideoSubscriptionOptions struct {
    StreamType        VideoStreamType
    EncodedFrameOnly  bool
}
```

| Parameter          | Description                                                                                                                                                 |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `StreamType`       | Type of video to subscribe to. See [`VideoStreamType`](#videostreamtype).                                                                                   |
| `EncodedFrameOnly` | Whether to subscribe only to encoded video data: - `true`: Subscribe only to encoded video data. - `false`: (Default) Subscribe only to decoded video data. |

### Enums

#### `AreaCode`

Server access regions. This function is an advanced setting suitable for use-cases with access security restrictions. The area code supports bitwise operations. After specifying the access region, the SDK will connect to the Agora servers within the specified region.

| Parameter      | Description                                   |
| -------------- | --------------------------------------------- |
| `AreaCodeCN`   | `0x00000001`: Mainland China.                 |
| `AreaCodeNA`   | `0x00000002`: North America.                  |
| `AreaCodeEU`   | `0x00000004`: Europe.                         |
| `AreaCodeAS`   | `0x00000008`: Asia, excluding Mainland China. |
| `AreaCodeJP`   | `0x00000010`: Japan.                          |
| `AreaCodeIN`   | `0x00000020`: India.                          |
| `AreaCodeGlob` | `0xFFFFFFFF`: (Default) Global.               |

#### `AudioCodecType`

Audio codec types.

| Parameter          | Description  |
| ------------------ | ------------ |
| `AudioCodecOpus`   | `1`: OPUS    |
| `AudioCodecPcma`   | `3`: PCMA    |
| `AudioCodecPcmu`   | `4`: PCMU    |
| `AudioCodecG722`   | `5`: G722    |
| `AudioCodecAacLc`  | `8`: AAC LC  |
| `AudioCodecHeAac`  | `9`: HE AAC  |
| `AudioCodecHeAac2` | `11`: HEAAC2 |

#### `AudioFrameType`

Audio frame types.

| Parameter             | Description      |
| --------------------- | ---------------- |
| `AudioFrameTypePCM16` | `0`: 16-bit PCM. |

#### `AudioScenario`

Audio encoding properties.

| Parameter                    | Description                                                                                                                                                                                               |
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `AudioScenarioDefault`       | `0`: (Default) Automatic scenario, automatically matches the appropriate sound quality based on user role and audio routing.                                                                              |
| `AudioScenarioGameStreaming` | `3`: High-quality audio scenario, suitable for music-centric situations.                                                                                                                                  |
| `AudioScenarioChatRoom`      | `5`: Chat room scenario, suitable for situations where users frequently join and leave the microphone. In this scenario, audience members will receive a pop-up prompt to request microphone permissions. |
| `AudioScenarioChorus`        | `7`: Chorus scenario, suitable for real-time chorus with extremely low latency in good network conditions.                                                                                                |
| `AudioScenarioMeeting`       | `8`: Meeting scenario, suitable for multi-person meetings primarily focused on voice.                                                                                                                     |

#### `ChannelProfile`

Channel use-case.

| Parameter                        | Description                                                                                                                                                                                                                                                                                              |
| -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ChannelProfileCommunication`    | `0`: (Default) Communication use-case. Recommended for channels with only two users.                                                                                                                                                                                                                     |
| `ChannelProfileLiveBroadcasting` | `1`: Live broadcasting use-case. This use-case includes two user roles: host and audience. Hosts can publish and receive audio and video streams, while the audience can only receive streams. Suitable for voice chat rooms, video live streaming, interactive large classes, and similar applications. |

#### `ClientRole`

User roles.

| Parameter               | Description                                                                          |
| ----------------------- | ------------------------------------------------------------------------------------ |
| `ClientRoleBroadcaster` | `1`: Broadcaster. The broadcaster can send and receive media streams simultaneously. |
| `ClientRoleAudience`    | `2`: Audience. The audience can only receive media streams.                          |

#### `UserMediaInfo`

User media information.

| Parameter                  | Description                                         |
| -------------------------- | --------------------------------------------------- |
| `UserMediaInfoMuteAudio`   | `0`: The user has stopped publishing audio streams. |
| `UserMediaInfoMuteVideo`   | `1`: The user has stopped publishing video streams. |
| `UserMediaInfoEnableVideo` | `4`: The user has enabled video functionality.      |

#### `VideoBufferType`

Video data types.

| Parameter            | Description      |
| -------------------- | ---------------- |
| `VideoBufferRawData` | `1`: Raw data.   |
| `VideoBufferArray`   | `2`: Array data. |
| `VideoBufferTexture` | `3`: Texture.    |

#### `VideoCodecType`

Video codec types.

| Parameter                   | Description       |
| --------------------------- | ----------------- |
| `VideoCodecTypeNone`        | `0`: None         |
| `VideoCodecTypeVp8`         | `1`: VP8          |
| `VideoCodecTypeH264`        | `2`: H.264        |
| `VideoCodecTypeH265`        | `3`: H.265        |
| `VideoCodecTypeGeneric`     | `6`: Generic      |
| `VideoCodecTypeGenericH264` | `7`: Generic H264 |
| `VideoCodecTypeAv1`         | `12`: AV1         |
| `VideoCodecTypeVp9`         | `13`: VP9         |
| `VideoCodecTypeGenericJpeg` | `20`: JPEG        |

#### `VideoFrameType`

Encoded video frame types.

| Parameter                      | Description                                                                                                                     |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
| `VideoFrameTypeBlankFrame`     | `0`: Blank frame.                                                                                                               |
| `VideoFrameTypeKeyFrame`       | `3`: Key frame. For H.264 encoding, the SDK classifies I-frames with SPS and PPS information as key frames.                     |
| `VideoFrameTypeDeltaFrame`     | `4`: Delta frame. For H.264 encoding, the SDK classifies P-frames and I-frames without SPS and PPS information as delta frames. |
| `VideoFrameTypeBFrame`         | `5`: B frame.                                                                                                                   |
| `VideoFrameTypeDroppableFrame` | `6`: Droppable frame.                                                                                                           |
| `VideoFrameTypeUnknown`        | `-1`: Unknown.                                                                                                                  |

#### VideoOrientation

Fields related to raw data. Specifies whether to rotate the incoming video clockwise.

| Parameter             | Description                                |
| --------------------- | ------------------------------------------ |
| `VideoOrientation0`   | `0`: (Default) Rotate 0 degrees clockwise. |
| `VideoOrientation90`  | `90`: Rotate 90 degrees clockwise.         |
| `VideoOrientation180` | `180`: Rotate 180 degrees clockwise.       |
| `VideoOrientation270` | `270`: Rotate 270 degrees clockwise.       |

#### `VideoPixelFormat`

Pixel formats.

| Parameter                     | Description                                                                                                                                    |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `VideoPixelDefault`           | `0`: Raw video pixel format.                                                                                                                   |
| `VideoPixelI420`              | `1`: I420 format.                                                                                                                              |
| `VideoPixelRGBA`              | `4`: RGBA format.                                                                                                                              |
| `VideoPixelI422`              | `16`: I422 format.                                                                                                                             |
| `VideoTextureID3D11Texture2D` | `17`: `ID3D11TEXTURE2D` format. Supported types include `DXGI_FORMAT_B8G8R8A8_UNORM`, `DXGI_FORMAT_B8G8R8A8_TYPELESS`, and `DXGI_FORMAT_NV12`. |

> **Caution**
>
> The SDK does not currently support the Alpha channel. The incoming Alpha value will be discarded.

#### `VideoSendCcState`

Congestion control modes.

| Parameter             | Description                      |
| --------------------- | -------------------------------- |
| `VideoSendCcEnabled`  | `0`: Enable congestion control.  |
| `VideoSendCcDisabled` | `1`: Disable congestion control. |

#### `VideoStreamType`

Video stream types.

| Parameter         | Description                                                |
| ----------------- | ---------------------------------------------------------- |
| `VideoStreamHigh` | `0`: (Default) High stream. Higher resolution and bitrate. |
| `VideoStreamLow`  | `1`: Low stream. Lower resolution and bitrate.             |
