diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 000000000..b3e96becb
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,4 @@
+{
+ "version": "0.2.0",
+ "configurations": []
+}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644
index 000000000..56c4b8b72
--- /dev/null
+++ b/.vscode/tasks.json
@@ -0,0 +1,4 @@
+{
+ "tasks": [],
+ "version": "2.0.0"
+}
\ No newline at end of file
diff --git a/Android/APIExample/.gitignore b/Android/APIExample/.gitignore
new file mode 100644
index 000000000..23d57e4d8
--- /dev/null
+++ b/Android/APIExample/.gitignore
@@ -0,0 +1,18 @@
+*.so
+*.iml
+.gradle
+/local.properties
+/.idea
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+.DS_Store
+/build
+/captures
+.externalNativeBuild
+.cxx
+androidTest/
+Test/
diff --git a/Android/APIExample/README.md b/Android/APIExample/README.md
new file mode 100644
index 000000000..7e45e247e
--- /dev/null
+++ b/Android/APIExample/README.md
@@ -0,0 +1,48 @@
+# API Example Android
+
+*English | [中文](README.zh.md)*
+
+This project presents you a set of API examples to help you understand how to use Agora APIs.
+
+## Prerequisites
+
+- Android Studio 3.0+
+- Physical Android device
+- Android simulator is supported
+
+## Quick Start
+
+This section shows you how to prepare, build, and run the sample application.
+
+### Obtain an App Id
+
+To build and run the sample application, get an App Id:
+
+1. Create a developer account at [agora.io](https://dashboard.agora.io/signin/). Once you finish the signup process, you will be redirected to the Dashboard.
+2. Navigate in the Dashboard tree on the left to **Projects** > **Project List**.
+3. Save the **App Id** from the Dashboard for later use.
+4. Generate a temp **Access Token** (valid for 24 hours) from dashboard page with given channel name, save for later use.
+
+5. Open `Android/APIExample` and edit the `app/src/main/res/values/string-config.xml` file. Update `<#Your App Id#>` with your App Id, and change `<#Temp Access Token#>` with the temp Access Token generated from dashboard. Note you can leave the token variable `null` if your project has not turned on security token.
+
+ ```
+ YOUR APP ID
+ // assign token to null if you have not enabled app certificate
+ YOUR ACCESS TOKEN
+ ```
+
+You are all set. Now connect your Android device and run the project.
+
+## Contact Us
+
+- For potential issues, take a look at our [FAQ](https://docs.agora.io/en/faq) first
+- Dive into [Agora SDK Samples](https://github.com/AgoraIO) to see more tutorials
+- Take a look at [Agora Use Case](https://github.com/AgoraIO-usecase) for more complicated real use case
+- Repositories managed by developer communities can be found at [Agora Community](https://github.com/AgoraIO-Community)
+- You can find full API documentation at [Document Center](https://docs.agora.io/en/)
+- If you encounter problems during integration, you can ask question in [Stack Overflow](https://stackoverflow.com/questions/tagged/agora.io)
+- You can file bugs about this sample at [issue](https://github.com/AgoraIO/Basic-Video-Call/issues)
+
+## License
+
+The MIT License (MIT)
diff --git a/Android/APIExample/README.zh.md b/Android/APIExample/README.zh.md
new file mode 100644
index 000000000..e322ea18d
--- /dev/null
+++ b/Android/APIExample/README.zh.md
@@ -0,0 +1,49 @@
+# API Example Android
+
+*[English](README.md) | 中文*
+
+这个开源示例项目演示了Agora视频SDK的部分API使用示例,以帮助开发者更好地理解和运用Agora视频SDK的API。
+
+## 环境准备
+
+- Android Studio 3.0+
+- Android 真机设备
+- 支持模拟器
+
+## 运行示例程序
+
+这个段落主要讲解了如何编译和运行实例程序。
+
+### 创建Agora账号并获取AppId
+
+在编译和启动实例程序前,你需要首先获取一个可用的App Id:
+
+1. 在[agora.io](https://dashboard.agora.io/signin/)创建一个开发者账号
+2. 前往后台页面,点击左部导航栏的 **项目 > 项目列表** 菜单
+3. 复制后台的 **App Id** 并备注,稍后启动应用时会用到它
+4. 在项目页面生成临时 **Access Token** (24小时内有效)并备注,注意生成的Token只能适用于对应的频道名。
+
+5. 打开 `Android/APIExample` 并编辑 `app/src/main/res/values/string-config.xml`,将你的 AppID 和 Token 分别替换到 `<#Your App Id#>` 与 `<#Temp Access Token#>`
+
+ ```
+ YOUR APP ID
+ // 如果你没有打开Token功能,token可以直接给null或者不填
+ YOUR ACCESS TOKEN
+ ```
+
+然后你就可以编译并运行项目了。
+
+## 联系我们
+
+- 如果你遇到了困难,可以先参阅 [常见问题](https://docs.agora.io/cn/faq)
+- 如果你想了解更多官方示例,可以参考 [官方SDK示例](https://github.com/AgoraIO)
+- 如果你想了解声网SDK在复杂场景下的应用,可以参考 [官方场景案例](https://github.com/AgoraIO-usecase)
+- 如果你想了解声网的一些社区开发者维护的项目,可以查看 [社区](https://github.com/AgoraIO-Community)
+- 完整的 API 文档见 [文档中心](https://docs.agora.io/cn/)
+- 若遇到问题需要开发者帮助,你可以到 [开发者社区](https://rtcdeveloper.com/) 提问
+- 如果需要售后技术支持, 你可以在 [Agora Dashboard](https://dashboard.agora.io) 提交工单
+- 如果发现了示例代码的 bug,欢迎提交 [issue](https://github.com/AgoraIO/Basic-Video-Call/issues)
+
+## 代码许可
+
+The MIT License (MIT)
diff --git a/Android/APIExample/app/.gitignore b/Android/APIExample/app/.gitignore
new file mode 100644
index 000000000..da62f148c
--- /dev/null
+++ b/Android/APIExample/app/.gitignore
@@ -0,0 +1,20 @@
+*.iml
+.gradle
+/local.properties
+/.idea
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+.DS_Store
+/build
+/captures
+gradle
+gradlew
+gradlew.bat
+.externalNativeBuild
+.cxx
+androidTest/
+Test/
diff --git a/Android/APIExample/app/build.gradle b/Android/APIExample/app/build.gradle
new file mode 100644
index 000000000..36cd36372
--- /dev/null
+++ b/Android/APIExample/app/build.gradle
@@ -0,0 +1,60 @@
+apply plugin: 'com.android.application'
+apply plugin: "androidx.navigation.safeargs"
+
+android {
+ compileSdkVersion 29
+ buildToolsVersion "29.0.2"
+
+ defaultConfig {
+ applicationId "io.agora.api.example"
+ minSdkVersion 19
+ targetSdkVersion 29
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+
+ sourceSets {
+ main {
+ jniLibs.srcDirs = ['src/main/jniLibs']
+ }
+ }
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
+
+ implementation 'androidx.appcompat:appcompat:1.1.0'
+ implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+
+ // Java language implementation
+ implementation "androidx.navigation:navigation-fragment:2.3.0-alpha06"
+ implementation "androidx.navigation:navigation-ui:2.3.0-alpha06"
+
+ implementation 'androidx.legacy:legacy-support-v4:1.0.0'
+ implementation 'androidx.recyclerview:recyclerview:1.1.0'
+ testImplementation 'junit:junit:4.12'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+
+ implementation 'io.github.luizgrp.sectionedrecyclerviewadapter:sectionedrecyclerviewadapter:1.2.0'
+ implementation 'com.yanzhenjie:permission:2.0.3'
+
+ implementation project(path: ':lib-stream-encrypt')
+ implementation project(path: ':lib-push-externalvideo')
+ implementation project(path: ':lib-raw-data')
+ implementation project(path: ':lib-switch-external-video')
+}
diff --git a/Android/APIExample/app/libs/RtcChannelPublishHelper.aar b/Android/APIExample/app/libs/RtcChannelPublishHelper.aar
new file mode 100644
index 000000000..c9f8e2b87
Binary files /dev/null and b/Android/APIExample/app/libs/RtcChannelPublishHelper.aar differ
diff --git a/Android/APIExample/app/proguard-rules.pro b/Android/APIExample/app/proguard-rules.pro
new file mode 100644
index 000000000..f1b424510
--- /dev/null
+++ b/Android/APIExample/app/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/Android/APIExample/app/src/androidTest/java/io/agora/api/example/ExampleInstrumentedTest.java b/Android/APIExample/app/src/androidTest/java/io/agora/api/example/ExampleInstrumentedTest.java
new file mode 100644
index 000000000..26eca4eba
--- /dev/null
+++ b/Android/APIExample/app/src/androidTest/java/io/agora/api/example/ExampleInstrumentedTest.java
@@ -0,0 +1,27 @@
+package io.agora.api.example;
+
+import android.content.Context;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.*;
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * @see Testing documentation
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+ @Test
+ public void useAppContext() {
+ // Context of the app under test.
+ Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+
+ assertEquals("io.agora.api.example", appContext.getPackageName());
+ }
+}
diff --git a/Android/APIExample/app/src/main/AndroidManifest.xml b/Android/APIExample/app/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..61b501b5e
--- /dev/null
+++ b/Android/APIExample/app/src/main/AndroidManifest.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/assets/effectA.wav b/Android/APIExample/app/src/main/assets/effectA.wav
new file mode 100644
index 000000000..dc31fdb68
Binary files /dev/null and b/Android/APIExample/app/src/main/assets/effectA.wav differ
diff --git a/Android/APIExample/app/src/main/assets/music_1.m4a b/Android/APIExample/app/src/main/assets/music_1.m4a
new file mode 100644
index 000000000..3fb0b5ba5
Binary files /dev/null and b/Android/APIExample/app/src/main/assets/music_1.m4a differ
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/ExampleActivity.java b/Android/APIExample/app/src/main/java/io/agora/api/example/ExampleActivity.java
new file mode 100644
index 000000000..20f1bc395
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/ExampleActivity.java
@@ -0,0 +1,154 @@
+package io.agora.api.example;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.MenuItem;
+
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.fragment.app.Fragment;
+
+import io.agora.api.component.Constant;
+import io.agora.api.example.common.model.ExampleBean;
+import io.agora.api.example.examples.advanced.AdjustVolume;
+import io.agora.api.example.examples.advanced.ChannelEncryption;
+import io.agora.api.example.examples.advanced.CustomRemoteVideoRender;
+import io.agora.api.example.examples.advanced.HostAcrossChannel;
+import io.agora.api.example.examples.advanced.InCallReport;
+import io.agora.api.example.examples.advanced.JoinMultipleChannel;
+import io.agora.api.example.examples.advanced.MediaPlayerKit;
+import io.agora.api.example.examples.advanced.PlayAudioFiles;
+import io.agora.api.example.examples.advanced.PreCallTest;
+import io.agora.api.example.examples.advanced.ProcessRawData;
+import io.agora.api.example.examples.advanced.PushExternalVideo;
+import io.agora.api.example.examples.advanced.SetVideoProfile;
+import io.agora.api.example.examples.advanced.SwitchExternalVideo;
+import io.agora.api.example.examples.advanced.SetAudioProfile;
+import io.agora.api.example.examples.advanced.VideoQuickSwitch;
+import io.agora.api.example.examples.advanced.RTMPInjection;
+import io.agora.api.example.examples.advanced.RTMPStreaming;
+import io.agora.api.example.examples.advanced.StreamEncrypt;
+import io.agora.api.example.examples.advanced.SwitchCameraScreenShare;
+import io.agora.api.example.examples.advanced.VideoMetadata;
+import io.agora.api.example.examples.advanced.customaudio.CustomAudioSource;
+import io.agora.api.example.examples.basic.JoinChannelAudio;
+import io.agora.api.example.examples.basic.JoinChannelVideo;
+
+/**
+ * @author cjw
+ */
+public class ExampleActivity extends AppCompatActivity {
+ private static final String TAG = "ExampleActivity";
+
+ private ExampleBean exampleBean;
+
+ public static void instance(Activity activity, ExampleBean exampleBean) {
+ Intent intent = new Intent(activity, ExampleActivity.class);
+ intent.putExtra(Constant.DATA, exampleBean);
+ activity.startActivity(intent);
+ }
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_example_layout);
+ exampleBean = getIntent().getParcelableExtra(Constant.DATA);
+
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setTitle(exampleBean.getName());
+ actionBar.setHomeButtonEnabled(true);
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+
+ Fragment fragment;
+ switch (exampleBean.getActionId()) {
+ case R.id.action_mainFragment_to_joinChannelAudio:
+ fragment = new JoinChannelAudio();
+ break;
+ case R.id.action_mainFragment_to_joinChannelVideo:
+ fragment = new JoinChannelVideo();
+ break;
+ case R.id.action_mainFragment_to_CustomAudioSource:
+ fragment = new CustomAudioSource();
+ break;
+ case R.id.action_mainFragment_to_CustomRemoteRender:
+ fragment = new CustomRemoteVideoRender();
+ break;
+ case R.id.action_mainFragment_to_ProcessRawData:
+ fragment = new ProcessRawData();
+ break;
+ case R.id.action_mainFragment_to_PushExternalVideo:
+ fragment = new PushExternalVideo();
+ break;
+ case R.id.action_mainFragment_to_QuickSwitch:
+ fragment = new VideoQuickSwitch();
+ break;
+ case R.id.action_mainFragment_to_MultiChannel:
+ fragment = new JoinMultipleChannel();
+ break;
+ case R.id.action_mainFragment_to_SetAudioProfile:
+ fragment = new SetAudioProfile();
+ break;
+ case R.id.action_mainFragment_to_PlayAudioFiles:
+ fragment = new PlayAudioFiles();
+ break;
+ case R.id.action_mainFragment_to_MediaPlayerKit:
+ fragment = new MediaPlayerKit();
+ break;
+ case R.id.action_mainFragment_to_RTMPInjection:
+ fragment = new RTMPInjection();
+ break;
+ case R.id.action_mainFragment_to_RTMPStreaming:
+ fragment = new RTMPStreaming();
+ break;
+ case R.id.action_mainFragment_to_StreamEncrypt:
+ fragment = new StreamEncrypt();
+ break;
+ case R.id.action_mainFragment_to_SwitchExternalVideo:
+ fragment = new SwitchExternalVideo();
+ break;
+ case R.id.action_mainFragment_to_SwitchCameraScreenShare:
+ fragment = new SwitchCameraScreenShare();
+ break;
+ case R.id.action_mainFragment_to_VideoMetadata:
+ fragment = new VideoMetadata();
+ break;
+ case R.id.action_mainFragment_to_InCallReport:
+ fragment = new InCallReport();
+ break;
+ case R.id.action_mainFragment_to_AdjustVolume:
+ fragment = new AdjustVolume();
+ break;
+ case R.id.action_mainFragment_to_PreCallTest:
+ fragment = new PreCallTest();
+ break;
+ case R.id.action_mainFragment_to_hostacrosschannel:
+ fragment = new HostAcrossChannel();
+ break;
+ case R.id.action_mainFragment_to_set_video_profile:
+ fragment = new SetVideoProfile();
+ break;
+ case R.id.action_mainFragment_to_channel_encryption:
+ fragment = new ChannelEncryption();
+ break;
+ default:
+ fragment = new JoinChannelAudio();
+ break;
+ }
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.fragment_Layout, fragment)
+ .commit();
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ this.finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/MainActivity.java b/Android/APIExample/app/src/main/java/io/agora/api/example/MainActivity.java
new file mode 100644
index 000000000..73062c4fa
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/MainActivity.java
@@ -0,0 +1,66 @@
+package io.agora.api.example;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.constraintlayout.solver.GoalRow;
+import androidx.navigation.ActionOnlyNavDirections;
+import androidx.navigation.NavController;
+import androidx.navigation.Navigation;
+import androidx.navigation.ui.AppBarConfiguration;
+import androidx.navigation.ui.NavigationUI;
+
+import io.agora.api.component.Constant;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.model.ExampleBean;
+
+/**
+ * @author cjw
+ */
+public class MainActivity extends AppCompatActivity implements MainFragment.OnListFragmentInteractionListener {
+ private AppBarConfiguration appBarConfiguration;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
+ appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build();
+ NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
+ }
+
+ @Override
+ public boolean onSupportNavigateUp() {
+ NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
+ return NavigationUI.navigateUp(navController, appBarConfiguration)
+ || super.onSupportNavigateUp();
+ }
+
+ @Override
+ public void onListFragmentInteraction(Example item) {
+ ExampleBean exampleBean = new ExampleBean(item.index(), item.group(), item.name(), item.actionId(), item.tipsId());
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(Constant.DATA, exampleBean);
+ Navigation.findNavController(this, R.id.nav_host_fragment)
+ .navigate(R.id.action_mainFragment_to_Ready, bundle);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.menu_main_activity, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if (item.getItemId() == R.id.setting) {
+ startActivity(new Intent(this, SettingActivity.class));
+ }
+ return false;
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/MainApplication.java b/Android/APIExample/app/src/main/java/io/agora/api/example/MainApplication.java
new file mode 100644
index 000000000..556369805
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/MainApplication.java
@@ -0,0 +1,40 @@
+package io.agora.api.example;
+
+import android.app.Application;
+import android.content.Context;
+
+import java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.Set;
+
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.model.Examples;
+import io.agora.api.example.utils.ClassUtils;
+
+public class MainApplication extends Application {
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ initExamples();
+ }
+
+ private void initExamples() {
+ try {
+ Set packageName = ClassUtils.getFileNameByPackageName(this, "io.agora.api.example.examples");
+ for (String name : packageName) {
+ Class> aClass = Class.forName(name);
+ Annotation[] declaredAnnotations = aClass.getAnnotations();
+ for (Annotation annotation : declaredAnnotations) {
+ if (annotation instanceof Example) {
+ Example example = (Example) annotation;
+ Examples.addItem(example);
+ }
+ }
+ }
+ Examples.sortItem();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/MainFragment.java b/Android/APIExample/app/src/main/java/io/agora/api/example/MainFragment.java
new file mode 100644
index 000000000..e1ae6e5e1
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/MainFragment.java
@@ -0,0 +1,118 @@
+package io.agora.api.example;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.fragment.app.Fragment;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import java.util.List;
+import java.util.Map;
+
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.adapter.ExampleSection;
+import io.agora.api.example.common.model.Examples;
+import io.github.luizgrp.sectionedrecyclerviewadapter.SectionedRecyclerViewAdapter;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.api.example.common.model.Examples.BASIC;
+
+/**
+ * A fragment representing a list of Items.
+ *
+ * Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener}
+ * interface.
+ */
+public class MainFragment extends Fragment {
+ // TODO: Customize parameter argument names
+ private static final String ARG_COLUMN_COUNT = "column-count";
+ // TODO: Customize parameters
+ private int mColumnCount = 1;
+ private OnListFragmentInteractionListener mListener;
+
+ /**
+ * Mandatory empty constructor for the fragment manager to instantiate the
+ * fragment (e.g. upon screen orientation changes).
+ */
+ public MainFragment() {
+ }
+
+ // TODO: Customize parameter initialization
+ @SuppressWarnings("unused")
+ public static MainFragment newInstance(int columnCount) {
+ MainFragment fragment = new MainFragment();
+ Bundle args = new Bundle();
+ args.putInt(ARG_COLUMN_COUNT, columnCount);
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (getArguments() != null) {
+ mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
+ }
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_main, container, false);
+
+ // Set the adapter
+ if (view instanceof RecyclerView) {
+ Context context = view.getContext();
+ RecyclerView recyclerView = (RecyclerView) view;
+ if (mColumnCount <= 1) {
+ recyclerView.setLayoutManager(new LinearLayoutManager(context));
+ } else {
+ recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
+ }
+ SectionedRecyclerViewAdapter sectionedAdapter = new SectionedRecyclerViewAdapter();
+ sectionedAdapter.addSection(new ExampleSection(BASIC, Examples.ITEM_MAP.get(BASIC), mListener));
+ sectionedAdapter.addSection(new ExampleSection(ADVANCED, Examples.ITEM_MAP.get(ADVANCED), mListener));
+ recyclerView.setAdapter(sectionedAdapter);
+ }
+ return view;
+ }
+
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ if (context instanceof OnListFragmentInteractionListener) {
+ mListener = (OnListFragmentInteractionListener) context;
+ } else {
+ throw new RuntimeException(context.toString()
+ + " must implement OnListFragmentInteractionListener");
+ }
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ mListener = null;
+ }
+
+ /**
+ * This interface must be implemented by activities that contain this
+ * fragment to allow an interaction in this fragment to be communicated
+ * to the activity and potentially other fragments contained in that
+ * activity.
+ *
+ * See the Android Training lesson Communicating with Other Fragments for more information.
+ */
+ public interface OnListFragmentInteractionListener {
+ // TODO: Update argument type and name
+ void onListFragmentInteraction(Example item);
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/ReadyFragment.java b/Android/APIExample/app/src/main/java/io/agora/api/example/ReadyFragment.java
new file mode 100644
index 000000000..f3224dfa0
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/ReadyFragment.java
@@ -0,0 +1,75 @@
+package io.agora.api.example;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.AppCompatTextView;
+
+import io.agora.api.component.Constant;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.common.model.ExampleBean;
+
+/**
+ * @author cjw
+ */
+public class ReadyFragment extends BaseFragment {
+ private static final String TAG = ReadyFragment.class.getSimpleName();
+
+ private AppCompatTextView tips;
+ private ExampleBean exampleBean;
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setHasOptionsMenu(true);
+ exampleBean = getArguments().getParcelable(Constant.DATA);
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_ready_layout, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
+ if(actionBar != null){
+ actionBar.setTitle(exampleBean.getName());
+ actionBar.setHomeButtonEnabled(true);
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+
+ tips = view.findViewById(R.id.tips);
+ tips.setText(getString(exampleBean.getTipsId()));
+ view.findViewById(R.id.next).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ getActivity().onBackPressed();
+ }
+ }, 300);
+ ExampleActivity.instance(getActivity(), exampleBean);
+ }
+ });
+ }
+
+ @Override
+ public void onPrepareOptionsMenu(@NonNull Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+ menu.setGroupVisible(R.id.main_setting_group, false);
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/SettingActivity.java b/Android/APIExample/app/src/main/java/io/agora/api/example/SettingActivity.java
new file mode 100644
index 000000000..5e2670be5
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/SettingActivity.java
@@ -0,0 +1,43 @@
+package io.agora.api.example;
+
+import android.os.Bundle;
+import android.view.MenuItem;
+
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.AppCompatTextView;
+
+import io.agora.rtc.RtcEngine;
+
+/**
+ * @author cjw
+ */
+public class SettingActivity extends AppCompatActivity {
+ private static final String TAG = SettingActivity.class.getSimpleName();
+
+ private AppCompatTextView sdkVersion;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_setting_layout);
+ ActionBar actionBar = getSupportActionBar();
+ if(actionBar != null)
+ {
+ actionBar.setHomeButtonEnabled(true);
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+ sdkVersion = findViewById(R.id.sdkVersion);
+ sdkVersion.setText(String.format(getString(R.string.sdkversion1), RtcEngine.getSdkVersion()));
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ this.finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/annotation/Example.java b/Android/APIExample/app/src/main/java/io/agora/api/example/annotation/Example.java
new file mode 100644
index 000000000..bea15b542
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/annotation/Example.java
@@ -0,0 +1,40 @@
+package io.agora.api.example.annotation;
+
+import android.os.Parcelable;
+
+import java.io.Serializable;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author
+ */
+@Target({ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Example {
+ /**
+ * @return example index
+ */
+ int index();
+ /**
+ * @return group name
+ */
+ String group() default "";
+
+ /**
+ * @return example name
+ */
+ int name();
+
+ /**
+ * @return action ID
+ */
+ int actionId();
+
+ /**
+ * @return tips ID
+ * */
+ int tipsId();
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/common/BaseFragment.java b/Android/APIExample/app/src/main/java/io/agora/api/example/common/BaseFragment.java
new file mode 100644
index 000000000..60233b788
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/common/BaseFragment.java
@@ -0,0 +1,49 @@
+package io.agora.api.example.common;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.widget.Toast;
+
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.Fragment;
+
+public class BaseFragment extends Fragment
+{
+ protected Handler handler;
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ handler = new Handler(Looper.getMainLooper());
+ }
+
+ protected void showAlert(String message)
+ {
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+
+ new AlertDialog.Builder(context).setTitle("Tips").setMessage(message)
+ .setPositiveButton("OK", (dialog, which) -> dialog.dismiss())
+ .show();
+ }
+
+ protected final void showLongToast(final String msg)
+ {
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ if (BaseFragment.this == null || getContext() == null)
+ {return;}
+ Toast.makeText(getContext().getApplicationContext(), msg, Toast.LENGTH_LONG).show();
+ }
+ });
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/common/adapter/ExampleSection.java b/Android/APIExample/app/src/main/java/io/agora/api/example/common/adapter/ExampleSection.java
new file mode 100644
index 000000000..31505545d
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/common/adapter/ExampleSection.java
@@ -0,0 +1,79 @@
+package io.agora.api.example.common.adapter;
+
+import android.view.View;
+import android.widget.TextView;
+
+import androidx.recyclerview.widget.RecyclerView;
+
+import java.util.List;
+
+import io.agora.api.example.MainFragment;
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.github.luizgrp.sectionedrecyclerviewadapter.Section;
+import io.github.luizgrp.sectionedrecyclerviewadapter.SectionParameters;
+
+public class ExampleSection extends Section {
+ private final String mTitle;
+ private final List mValues;
+ private final MainFragment.OnListFragmentInteractionListener mListener;
+
+ public ExampleSection(String title, List items, MainFragment.OnListFragmentInteractionListener listener) {
+ super(SectionParameters.builder().headerResourceId(R.layout.layout_main_list_section).itemResourceId(R.layout.layout_main_list_item).build());
+ mTitle = title;
+ mValues = items;
+ mListener = listener;
+ }
+
+ @Override
+ public int getContentItemsTotal() {
+ return mValues.size();
+ }
+
+ @Override
+ public RecyclerView.ViewHolder getItemViewHolder(View view) {
+ return new ViewHolder(view);
+ }
+
+ @Override
+ public void onBindItemViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
+ if (viewHolder instanceof ViewHolder) {
+ ViewHolder holder = (ViewHolder) viewHolder;
+ holder.mItem = mValues.get(position);
+ holder.mNameView.setText(holder.mView.getContext().getString(holder.mItem.name()));
+
+ holder.mView.setOnClickListener(v -> {
+ if (null != mListener) {
+ // Notify the active callbacks interface (the activity, if the
+ // fragment is attached to one) that an item has been selected.
+ mListener.onListFragmentInteraction(holder.mItem);
+ }
+ });
+ }
+ }
+
+ @Override
+ public RecyclerView.ViewHolder getHeaderViewHolder(View view) {
+ return new ViewHolder(view);
+ }
+
+ @Override
+ public void onBindHeaderViewHolder(RecyclerView.ViewHolder viewHolder) {
+ if (viewHolder instanceof ViewHolder) {
+ ViewHolder holder = (ViewHolder) viewHolder;
+ holder.mNameView.setText(mTitle);
+ }
+ }
+
+ static class ViewHolder extends RecyclerView.ViewHolder {
+ final View mView;
+ final TextView mNameView;
+ Example mItem;
+
+ ViewHolder(View view) {
+ super(view);
+ mView = view;
+ mNameView = view.findViewById(R.id.item_name);
+ }
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/common/model/ExampleBean.java b/Android/APIExample/app/src/main/java/io/agora/api/example/common/model/ExampleBean.java
new file mode 100644
index 000000000..331ae96a7
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/common/model/ExampleBean.java
@@ -0,0 +1,99 @@
+package io.agora.api.example.common.model;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * @author cjw
+ */
+public class ExampleBean implements Parcelable {
+ private int index;
+ private String group;
+ private int name;
+ private int actionId;
+ private int tipsId;
+
+ public ExampleBean(int index, String group, int name, int actionId, int tipsId) {
+ this.index = index;
+ this.group = group;
+ this.name = name;
+ this.actionId = actionId;
+ this.tipsId = tipsId;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
+ public String getGroup() {
+ return group;
+ }
+
+ public void setGroup(String group) {
+ this.group = group;
+ }
+
+ public int getName() {
+ return name;
+ }
+
+ public void setName(int name) {
+ this.name = name;
+ }
+
+ public int getActionId() {
+ return actionId;
+ }
+
+ public void setActionId(int actionId) {
+ this.actionId = actionId;
+ }
+
+ public int getTipsId() {
+ return tipsId;
+ }
+
+ public void setTipsId(int tipsId) {
+ this.tipsId = tipsId;
+ }
+
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(this.group);
+ dest.writeInt(this.name);
+ dest.writeInt(this.actionId);
+ dest.writeInt(this.tipsId);
+ }
+
+ public ExampleBean() {
+ }
+
+ protected ExampleBean(Parcel in) {
+ this.group = in.readString();
+ this.name = in.readInt();
+ this.actionId = in.readInt();
+ this.tipsId = in.readInt();
+ }
+
+ public static final Creator CREATOR = new Creator() {
+ @Override
+ public ExampleBean createFromParcel(Parcel source) {
+ return new ExampleBean(source);
+ }
+
+ @Override
+ public ExampleBean[] newArray(int size) {
+ return new ExampleBean[size];
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/common/model/Examples.java b/Android/APIExample/app/src/main/java/io/agora/api/example/common/model/Examples.java
new file mode 100644
index 000000000..80ec5092b
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/common/model/Examples.java
@@ -0,0 +1,41 @@
+package io.agora.api.example.common.model;
+
+import androidx.annotation.NonNull;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import io.agora.api.example.annotation.Example;
+
+public class Examples {
+ public static final String BASIC = "BASIC";
+ public static final String ADVANCED = "ADVANCED";
+
+ public static final Map> ITEM_MAP = new HashMap<>();
+
+ public static void addItem(@NonNull Example item) {
+ String group = item.group();
+ List list = ITEM_MAP.get(group);
+ if (list == null) {
+ list = new ArrayList<>();
+ ITEM_MAP.put(group, list);
+ }
+ list.add(item);
+ }
+
+ public static void sortItem() {
+ for (Map.Entry> entry : ITEM_MAP.entrySet()) {
+ List exampleList = ITEM_MAP.get(entry.getKey());
+ Collections.sort(exampleList, new Comparator() {
+ @Override
+ public int compare(Example o1, Example o2) {
+ return o1.index() - o2.index();
+ }
+ });
+ }
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/common/model/StatisticsInfo.java b/Android/APIExample/app/src/main/java/io/agora/api/example/common/model/StatisticsInfo.java
new file mode 100644
index 000000000..dd27ae8c9
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/common/model/StatisticsInfo.java
@@ -0,0 +1,168 @@
+package io.agora.api.example.common.model;
+
+import io.agora.rtc.IRtcEngineEventHandler.*;
+
+public class StatisticsInfo {
+ private LocalVideoStats localVideoStats;
+ private LocalAudioStats localAudioStats;
+ private RemoteVideoStats remoteVideoStats;
+ private RemoteAudioStats remoteAudioStats;
+ private RtcStats rtcStats;
+ private int quality;
+ private LastmileProbeResult lastMileProbeResult;
+
+ public void setLocalVideoStats(LocalVideoStats localVideoStats) {
+ this.localVideoStats = localVideoStats;
+ }
+
+ public void setLocalAudioStats(LocalAudioStats localAudioStats) {
+ this.localAudioStats = localAudioStats;
+ }
+
+ public void setRemoteVideoStats(RemoteVideoStats remoteVideoStats) {
+ this.remoteVideoStats = remoteVideoStats;
+ }
+
+ public void setRemoteAudioStats(RemoteAudioStats remoteAudioStats) {
+ this.remoteAudioStats = remoteAudioStats;
+ }
+
+ public void setRtcStats(RtcStats rtcStats) {
+ this.rtcStats = rtcStats;
+ }
+
+ public String getLocalVideoStats() {
+ StringBuilder builder = new StringBuilder();
+ return builder
+ .append(localVideoStats.encodedFrameWidth)
+ .append("×")
+ .append(localVideoStats.encodedFrameHeight)
+ .append(",")
+ .append(localVideoStats.encoderOutputFrameRate)
+ .append("fps")
+ .append("\n")
+ .append("LM Delay: ")
+ .append(rtcStats.lastmileDelay)
+ .append("ms")
+ .append("\n")
+ .append("VSend: ")
+ .append(localVideoStats.sentBitrate)
+ .append("kbps")
+ .append("\n")
+ .append("ASend: ")
+ .append(localAudioStats.sentBitrate)
+ .append("kbps")
+ .append("\n")
+ .append("CPU: ")
+ .append(rtcStats.cpuAppUsage)
+ .append("%/")
+ .append(rtcStats.cpuTotalUsage)
+ .append("%/")
+ .append("\n")
+ .append("VSend Loss: ")
+ .append(localVideoStats.txPacketLossRate)
+ .append("%")
+ .append("\n")
+ .append("ASend Loss: ")
+ .append(localAudioStats.txPacketLossRate)
+ .append("%")
+ .toString();
+ }
+
+ public String getRemoteVideoStats() {
+ StringBuilder builder = new StringBuilder();
+ return builder
+ .append(remoteVideoStats.width)
+ .append("×")
+ .append(remoteVideoStats.height)
+ .append(",")
+ .append(remoteVideoStats.rendererOutputFrameRate)
+ .append("fps")
+ .append("\n")
+ .append("VRecv: ")
+ .append(remoteVideoStats.receivedBitrate)
+ .append("kbps")
+ .append("\n")
+ .append("ARecv: ")
+ .append(remoteAudioStats.receivedBitrate)
+ .append("kbps")
+ .append("\n")
+ .append("VLoss: ")
+ .append(remoteVideoStats.packetLossRate)
+ .append("%")
+ .append("\n")
+ .append("ALoss: ")
+ .append(remoteAudioStats.audioLossRate)
+ .append("%")
+ .append("\n")
+ .append("AQuality: ")
+ .append(remoteAudioStats.quality)
+ .toString();
+ }
+
+ public void setLastMileQuality(int quality) {
+ this.quality = quality;
+ }
+
+ public String getLastMileQuality(){
+ switch (quality){
+ case 1:
+ return "EXCELLENT";
+ case 2:
+ return "GOOD";
+ case 3:
+ return "POOR";
+ case 4:
+ return "BAD";
+ case 5:
+ return "VERY BAD";
+ case 6:
+ return "DOWN";
+ case 7:
+ return "UNSUPPORTED";
+ case 8:
+ return "DETECTING";
+ default:
+ return "UNKNOWN";
+ }
+ }
+
+ public String getLastMileResult() {
+ if(lastMileProbeResult == null)
+ return null;
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append("Rtt: ")
+ .append(lastMileProbeResult.rtt)
+ .append("ms")
+ .append("\n")
+ .append("DownlinkAvailableBandwidth: ")
+ .append(lastMileProbeResult.downlinkReport.availableBandwidth)
+ .append("Kbps")
+ .append("\n")
+ .append("DownlinkJitter: ")
+ .append(lastMileProbeResult.downlinkReport.jitter)
+ .append("ms")
+ .append("\n")
+ .append("DownlinkLoss: ")
+ .append(lastMileProbeResult.downlinkReport.packetLossRate)
+ .append("%")
+ .append("\n")
+ .append("UplinkAvailableBandwidth: ")
+ .append(lastMileProbeResult.uplinkReport.availableBandwidth)
+ .append("Kbps")
+ .append("\n")
+ .append("UplinkJitter: ")
+ .append(lastMileProbeResult.uplinkReport.jitter)
+ .append("ms")
+ .append("\n")
+ .append("UplinkLoss: ")
+ .append(lastMileProbeResult.uplinkReport.packetLossRate)
+ .append("%");
+ return stringBuilder.toString();
+ }
+
+ public void setLastMileProbeResult(LastmileProbeResult lastmileProbeResult) {
+ this.lastMileProbeResult = lastmileProbeResult;
+ }
+
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/AdjustVolume.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/AdjustVolume.java
new file mode 100755
index 000000000..d5e70bb7b
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/AdjustVolume.java
@@ -0,0 +1,385 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.SeekBar;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.api.example.common.model.Examples.BASIC;
+
+@Example(
+ index = 19,
+ group = ADVANCED,
+ name = R.string.item_adjustvolume,
+ actionId = R.id.action_mainFragment_to_AdjustVolume,
+ tipsId = R.string.adjustvolume
+)
+public class AdjustVolume extends BaseFragment implements View.OnClickListener {
+ private static final String TAG = AdjustVolume.class.getSimpleName();
+ private EditText et_channel;
+ private Button mute, join, speaker;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false;
+ private SeekBar record, playout, inear;
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ handler = new Handler();
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_adjust_volume, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ mute = view.findViewById(R.id.btn_mute);
+ mute.setOnClickListener(this);
+ speaker = view.findViewById(R.id.btn_speaker);
+ speaker.setOnClickListener(this);
+ record = view.findViewById(R.id.recordingVol);
+ playout = view.findViewById(R.id.playoutVol);
+ inear = view.findViewById(R.id.inEarMonitorVol);
+ record.setOnSeekBarChangeListener(seekBarChangeListener);
+ playout.setOnSeekBarChangeListener(seekBarChangeListener);
+ inear.setOnSeekBarChangeListener(seekBarChangeListener);
+ record.setEnabled(false);
+ playout.setEnabled(false);
+ inear.setEnabled(false);
+ }
+
+ SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ if(seekBar.getId() == record.getId()){
+ engine.adjustRecordingSignalVolume(progress);
+ }
+ else if(seekBar.getId() == playout.getId()){
+ engine.adjustPlaybackSignalVolume(progress);
+ }
+ else if(seekBar.getId() == inear.getId()){
+ if(progress == 0){
+ engine.enableInEarMonitoring(false);
+ }
+ else {
+ engine.enableInEarMonitoring(true);
+ engine.setInEarMonitoringVolume(progress);
+ }
+ }
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+
+ }
+ };
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ try {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ String appId = getString(R.string.agora_app_id);
+ engine = RtcEngine.create(getContext().getApplicationContext(), appId, iRtcEngineEventHandler);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if (engine != null) {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.btn_join) {
+ if (!joined) {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA)) {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ } else {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ speaker.setText(getString(R.string.speaker));
+ speaker.setEnabled(false);
+ mute.setText(getString(R.string.closemicrophone));
+ mute.setEnabled(false);
+ record.setEnabled(false);
+ record.setProgress(0);
+ playout.setEnabled(false);
+ playout.setProgress(0);
+ inear.setEnabled(false);
+ inear.setProgress(0);
+ }
+ } else if (v.getId() == R.id.btn_mute) {
+ mute.setActivated(!mute.isActivated());
+ mute.setText(getString(mute.isActivated() ? R.string.openmicrophone : R.string.closemicrophone));
+ /**Turn off / on the microphone, stop / start local audio collection and push streaming.*/
+ engine.muteLocalAudioStream(mute.isActivated());
+ } else if (v.getId() == R.id.btn_speaker) {
+ speaker.setActivated(!speaker.isActivated());
+ speaker.setText(getString(speaker.isActivated() ? R.string.earpiece : R.string.speaker));
+ /**Turn off / on the speaker and change the audio playback route.*/
+ engine.setEnableSpeakerphone(speaker.isActivated());
+ }
+ }
+
+ /**
+ * @param channelId Specify the channel name that you want to join.
+ * Users that input the same channel name join the same channel.
+ */
+ private void joinChannel(String channelId) {
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>")) {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ engine.enableAudioVolumeIndication(1000, 3, true);
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0) {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ Log.e(TAG, RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+
+
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler() {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn) {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err) {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats) {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ speaker.setEnabled(true);
+ mute.setEnabled(true);
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ record.setEnabled(true);
+ record.setProgress(100);
+ playout.setEnabled(true);
+ playout.setProgress(100);
+ inear.setEnabled(true);
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed) {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed) {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason) {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ }
+
+ @Override
+ public void onActiveSpeaker(int uid) {
+ super.onActiveSpeaker(uid);
+ Log.i(TAG, String.format("onActiveSpeaker:%d", uid));
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/ChannelEncryption.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/ChannelEncryption.java
new file mode 100644
index 000000000..44227fe05
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/ChannelEncryption.java
@@ -0,0 +1,456 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+import android.widget.Spinner;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.internal.EncryptionConfig;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+/**This demo demonstrates how to make a one-to-one video call*/
+@Example(
+ index = 22,
+ group = ADVANCED,
+ name = R.string.item_channelencryption,
+ actionId = R.id.action_mainFragment_to_channel_encryption,
+ tipsId = R.string.channelencryption
+)
+public class ChannelEncryption extends BaseFragment implements View.OnClickListener
+{
+ private static final String TAG = ChannelEncryption.class.getSimpleName();
+
+ private FrameLayout fl_local, fl_remote;
+ private Button join;
+ private EditText et_channel, et_password;
+ private Spinner encry_mode;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_channel_encryption, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ et_password = view.findViewById(R.id.et_encry_pass);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ encry_mode = view.findViewById(R.id.encry_mode_spinner);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if(engine != null)
+ {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+ if (v.getId() == R.id.btn_join)
+ {
+ if (!joined)
+ {
+ // Creates an EncryptionConfig instance.
+ EncryptionConfig config = new EncryptionConfig();
+ // Sets the encryption mode as AES_128_XTS.
+ config.encryptionMode = EncryptionConfig.EncryptionMode.valueOf(encry_mode.getSelectedItem().toString());
+ // Sets the encryption key.
+ config.encryptionKey = et_password.getText().toString();
+ // Enables the built-in encryption.
+ engine.enableEncryption(true, config);
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ }
+ else
+ {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ et_password.setEnabled(true);
+ encry_mode.setEnabled(true);
+ }
+ }
+ }
+
+ private void joinChannel(String channelId)
+ {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+ surfaceView.setZOrderMediaOverlay(true);
+ if(fl_local.getChildCount() > 0)
+ {
+ fl_local.removeAllViews();
+ }
+ // Add to the local container
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+ // Set audio route to microPhone
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ VD_640x360,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats)
+ {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ et_password.setEnabled(false);
+ encry_mode.setEnabled(false);
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed)
+ {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ SurfaceView surfaceView = null;
+ if (fl_remote.getChildCount() > 0)
+ {
+ fl_remote.removeAllViews();
+ }
+ // Create render view by RtcEngine
+ surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason)
+ {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/CustomRemoteVideoRender.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/CustomRemoteVideoRender.java
new file mode 100644
index 000000000..61d25c262
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/CustomRemoteVideoRender.java
@@ -0,0 +1,417 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.mediaio.AgoraSurfaceView;
+import io.agora.rtc.mediaio.MediaIO;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+/**
+ * This example demonstrates how to customize the renderer to render the local scene of the remote video stream.
+ */
+@Example(
+ index = 9,
+ group = ADVANCED,
+ name = R.string.item_customremoterender,
+ actionId = R.id.action_mainFragment_to_CustomRemoteRender,
+ tipsId = R.string.customremoterender
+)
+public class CustomRemoteVideoRender extends BaseFragment implements View.OnClickListener {
+ private static final String TAG = CustomRemoteVideoRender.class.getSimpleName();
+
+ private FrameLayout fl_local, fl_remote;
+ private Button join;
+ private EditText et_channel;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_custom_remoterender, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ try {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if (engine != null) {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.btn_join) {
+ if (!joined) {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA)) {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ } else {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ }
+ }
+ }
+
+ private void joinChannel(String channelId) {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the local container
+ if (fl_local.getChildCount() > 0) {
+ fl_local.removeAllViews();
+ }
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+ /**Set up to play remote sound with receiver*/
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+ engine.setEnableSpeakerphone(false);
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ VD_640x360,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>")) {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0) {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler() {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn) {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err) {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats) {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed) {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed) {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed) {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**custom remote video surfaceView
+ * about AgoraSurfaceView,you can see this(
+ * https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1mediaio_1_1_agora_surface_view.html#ab4dcf3124f4bb4b945a043143babe41b)*/
+ AgoraSurfaceView surfaceView = new AgoraSurfaceView(getContext());
+ surfaceView.init(null);
+ surfaceView.setZOrderMediaOverlay(true);
+ surfaceView.setBufferType(MediaIO.BufferType.BYTE_BUFFER);
+ surfaceView.setPixelFormat(MediaIO.PixelFormat.I420);
+ if (fl_remote.getChildCount() > 0) {
+ fl_remote.removeAllViews();
+ }
+ fl_remote.addView(surfaceView);
+ /**Customizes the remote video renderer.
+ * Call this method to add an external remote video renderer to the SDK.
+ * @param uid The ID of the remote user.
+ * @param render Sets the remote video renderer. See IVideoSink(
+ * https://docs.agora.io/en/Voice/API%20Reference/java/v3.0.1/interfaceio_1_1agora_1_1rtc_1_1mediaio_1_1_i_video_sink.html).*/
+ engine.setRemoteVideoRenderer(uid, surfaceView);
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason) {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/HostAcrossChannel.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/HostAcrossChannel.java
new file mode 100644
index 000000000..b7c89c668
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/HostAcrossChannel.java
@@ -0,0 +1,523 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.video.ChannelMediaInfo;
+import io.agora.rtc.video.ChannelMediaRelayConfiguration;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.api.example.common.model.Examples.BASIC;
+import static io.agora.rtc.Constants.RELAY_STATE_CONNECTING;
+import static io.agora.rtc.Constants.RELAY_STATE_FAILURE;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+/**This demo demonstrates how to make a one-to-one video call*/
+@Example(
+ index = 19,
+ group = ADVANCED,
+ name = R.string.item_hostacrosschannel,
+ actionId = R.id.action_mainFragment_to_hostacrosschannel,
+ tipsId = R.string.hostacrosschannel
+)
+public class HostAcrossChannel extends BaseFragment implements View.OnClickListener
+{
+ private static final String TAG = HostAcrossChannel.class.getSimpleName();
+
+ private FrameLayout fl_local, fl_remote;
+ private Button join, join_ex;
+ private EditText et_channel, et_channel_ex;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false;
+ private boolean mediaReplaying = false;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_host_across_channel, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ join_ex = view.findViewById(R.id.btn_join_ex);
+ et_channel = view.findViewById(R.id.et_channel);
+ et_channel_ex = view.findViewById(R.id.et_channel_ex);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ view.findViewById(R.id.btn_join_ex).setOnClickListener(this);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ join_ex.setEnabled(false);
+ et_channel_ex.setEnabled(false);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if(engine != null)
+ {
+ engine.leaveChannel();
+ engine.stopChannelMediaRelay();
+ mediaReplaying = false;
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+ if (v.getId() == R.id.btn_join)
+ {
+ if (!joined)
+ {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ }
+ else
+ {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ join_ex.setText(getString(R.string.join));
+ }
+ }
+ else if(v.getId() == R.id.btn_join_ex){
+ if(!mediaReplaying){
+ String destChannelName = et_channel_ex.getText().toString();
+ if(destChannelName.length() == 0){
+ showAlert("Destination channel name is empty!");
+ }
+
+ ChannelMediaInfo srcChannelInfo = new ChannelMediaInfo(et_channel.getText().toString(), null, myUid);
+ ChannelMediaRelayConfiguration mediaRelayConfiguration = new ChannelMediaRelayConfiguration();
+ mediaRelayConfiguration.setSrcChannelInfo(srcChannelInfo);
+ ChannelMediaInfo destChannelInfo = new ChannelMediaInfo(destChannelName, null, myUid);
+ mediaRelayConfiguration.setDestChannelInfo(destChannelName, destChannelInfo);
+ engine.startChannelMediaRelay(mediaRelayConfiguration);
+ et_channel_ex.setEnabled(false);
+ join_ex.setEnabled(false);
+ }
+ else{
+ engine.stopChannelMediaRelay();
+ et_channel_ex.setEnabled(true);
+ join_ex.setText(getString(R.string.join));
+ mediaReplaying = false;
+ }
+ }
+ }
+
+ private void joinChannel(String channelId)
+ {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+ surfaceView.setZOrderMediaOverlay(true);
+ if(fl_local.getChildCount() > 0)
+ {
+ fl_local.removeAllViews();
+ }
+ // Add to the local container
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+ // Set audio route to microPhone
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ VD_640x360,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats)
+ {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ join_ex.setEnabled(true);
+ et_channel_ex.setEnabled(true);
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed)
+ {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ SurfaceView surfaceView = null;
+ if (fl_remote.getChildCount() > 0)
+ {
+ fl_remote.removeAllViews();
+ }
+ // Create render view by RtcEngine
+ surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason)
+ {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+
+ /**
+ * Occurs when the state of the media stream relay changes.
+ *
+ * Since
+ * v2.9.0.
+ * The SDK reports the state of the current media relay and possible error messages in this callback.
+ * @param state The state code:
+ * RELAY_STATE_IDLE(0): The SDK is initializing.
+ * RELAY_STATE_CONNECTING(1): The SDK tries to relay the media stream to the destination channel.
+ * RELAY_STATE_RUNNING(2): The SDK successfully relays the media stream to the destination channel.
+ * RELAY_STATE_FAILURE(3): A failure occurs. See the details in code.
+ * @param code The error code
+ * RELAY_OK(0): The state is normal.
+ * RELAY_ERROR_SERVER_ERROR_RESPONSE(1): An error occurs in the server response.
+ * RELAY_ERROR_SERVER_NO_RESPONSE(2): No server response. You can call the leaveChannel method to leave the channel.
+ * RELAY_ERROR_NO_RESOURCE_AVAILABLE(3): The SDK fails to access the service, probably due to limited resources of the server.
+ * RELAY_ERROR_FAILED_JOIN_SRC(4): Fails to send the relay request.
+ * RELAY_ERROR_FAILED_JOIN_DEST(5): Fails to accept the relay request.
+ * RELAY_ERROR_FAILED_PACKET_RECEIVED_FROM_SRC(6): The server fails to receive the media stream.
+ * RELAY_ERROR_FAILED_PACKET_SENT_TO_DEST(7): The server fails to send the media stream.
+ * RELAY_ERROR_SERVER_CONNECTION_LOST(8): The SDK disconnects from the server due to poor network connections. You can call the leaveChannel method to leave the channel.
+ * RELAY_ERROR_INTERNAL_ERROR(9): An internal error occurs in the server.
+ * RELAY_ERROR_SRC_TOKEN_EXPIRED(10): The token of the source channel has expired.
+ * RELAY_ERROR_DEST_TOKEN_EXPIRED(11): The token of the destination channel has expired.
+ */
+ @Override
+ public void onChannelMediaRelayStateChanged(int state, int code) {
+ switch (state){
+ case RELAY_STATE_CONNECTING:
+ mediaReplaying = true;
+ handler.post(() ->{
+ et_channel_ex.setEnabled(false);
+ join_ex.setEnabled(true);
+ join_ex.setText(getText(R.string.stop));
+ showLongToast("channel media replay connected.");
+ });
+ break;
+ case RELAY_STATE_FAILURE:
+ mediaReplaying = false;
+ handler.post(() ->{
+ showLongToast(String.format("channel media replay failed at error code: %d", code));
+ });
+ }
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/InCallReport.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/InCallReport.java
new file mode 100644
index 000000000..3b60e12a4
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/InCallReport.java
@@ -0,0 +1,483 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.widget.AppCompatTextView;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.common.model.StatisticsInfo;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+@Example(
+ index = 17,
+ group = ADVANCED,
+ name = R.string.item_incallreport,
+ actionId = R.id.action_mainFragment_to_InCallReport,
+ tipsId = R.string.incallstats
+)
+public class InCallReport extends BaseFragment implements View.OnClickListener {
+ private static final String TAG = InCallReport.class.getSimpleName();
+
+ private FrameLayout fl_local, fl_remote;
+ private Button join;
+ private EditText et_channel;
+ private AppCompatTextView localStats, remoteStats;
+ private RtcEngine engine;
+ private StatisticsInfo statisticsInfo;
+ private int myUid;
+ private boolean joined = false;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_in_call_report, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ statisticsInfo = new StatisticsInfo();
+ et_channel = view.findViewById(R.id.et_channel);
+ localStats = view.findViewById(R.id.local_stats);
+ localStats.bringToFront();
+ remoteStats = view.findViewById(R.id.remote_stats);
+ remoteStats.bringToFront();
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ }
+
+ private void updateLocalStats(){
+ localStats.setText(statisticsInfo.getLocalVideoStats());
+ }
+
+ private void updateRemoteStats(){
+ remoteStats.setText(statisticsInfo.getRemoteVideoStats());
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if(engine != null)
+ {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+ if (v.getId() == R.id.btn_join)
+ {
+ if (!joined)
+ {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ }
+ else
+ {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ }
+ }
+ }
+
+ private void joinChannel(String channelId)
+ {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+ surfaceView.setZOrderMediaOverlay(true);
+ if(fl_local.getChildCount() > 0)
+ {
+ fl_local.removeAllViews();
+ }
+ // Add to the local container
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+ // Set audio route to microPhone
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ VD_640x360,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats)
+ {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed)
+ {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ SurfaceView surfaceView = null;
+ if (fl_remote.getChildCount() > 0)
+ {
+ fl_remote.removeAllViews();
+ }
+ // Create render view by RtcEngine
+ surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason)
+ {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+
+ @Override
+ public void onRemoteAudioStats(RemoteAudioStats remoteAudioStats) {
+ statisticsInfo.setRemoteAudioStats(remoteAudioStats);
+ updateRemoteStats();
+ }
+
+ @Override
+ public void onLocalAudioStats(LocalAudioStats localAudioStats) {
+ statisticsInfo.setLocalAudioStats(localAudioStats);
+ updateLocalStats();
+ }
+
+ @Override
+ public void onRemoteVideoStats(RemoteVideoStats remoteVideoStats) {
+ statisticsInfo.setRemoteVideoStats(remoteVideoStats);
+ updateRemoteStats();
+ }
+
+ @Override
+ public void onLocalVideoStats(LocalVideoStats localVideoStats) {
+ statisticsInfo.setLocalVideoStats(localVideoStats);
+ updateLocalStats();
+ }
+
+ @Override
+ public void onRtcStats(RtcStats rtcStats) {
+ statisticsInfo.setRtcStats(rtcStats);
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/JoinMultipleChannel.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/JoinMultipleChannel.java
new file mode 100644
index 000000000..804ee1993
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/JoinMultipleChannel.java
@@ -0,0 +1,532 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.examples.basic.JoinChannelVideo;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcChannelEventHandler;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcChannel;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.models.ChannelMediaOptions;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_FIT;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+@Example(
+ index = 12,
+ group = ADVANCED,
+ name = R.string.item_joinmultichannel,
+ actionId = R.id.action_mainFragment_to_MultiChannel,
+ tipsId = R.string.joinmultichannel
+)
+public class JoinMultipleChannel extends BaseFragment implements View.OnClickListener {
+ private static final String TAG = JoinChannelVideo.class.getSimpleName();
+
+ private FrameLayout fl_local, fl_remote, fl_remote2;
+ private Button join;
+ private EditText et_channel;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false;
+ private String channel1;
+ private String channel2;
+ private RtcChannel rtcChannel;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_join_multi_channel, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ fl_remote2 = view.findViewById(R.id.fl_remote2);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if(engine != null)
+ {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+ if (v.getId() == R.id.btn_join)
+ {
+ if (!joined)
+ {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ channel1 = et_channel.getText().toString();
+ channel2 = channel1 + "-2";
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channel1);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channel1);
+ }).start();
+ }
+ else
+ {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ rtcChannel.leaveChannel();
+ join.setText(getString(R.string.join));
+ }
+ }
+ }
+
+ private void joinChannel(String channelId)
+ {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+ surfaceView.setZOrderMediaOverlay(true);
+ if(fl_local.getChildCount() > 0)
+ {
+ fl_local.removeAllViews();
+ }
+ // Add to the local container
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+ // Set audio route to microPhone
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ VD_640x360,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0 || !joinSecondChannel())
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ private boolean joinSecondChannel() {
+ // 1. Create rtcChannel
+ rtcChannel = engine.createRtcChannel(channel2);
+ // 2. Set rtcChannelEventHandler
+ rtcChannel.setRtcChannelEventHandler(new IRtcChannelEventHandler() {
+ // Override events
+ /**
+ * Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ *
+ * @param rtcChannel Channel object
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered
+ */
+ @Override
+ public void onJoinChannelSuccess(RtcChannel rtcChannel, int uid, int elapsed) {
+ super.onJoinChannelSuccess(rtcChannel, uid, elapsed);
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel2, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel2, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ }
+ });
+ }
+ /**
+ * Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ *
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.
+ */
+ @Override
+ public void onUserJoined(RtcChannel rtcChannel, int uid, int elapsed) {
+ super.onUserJoined(rtcChannel, uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ SurfaceView surfaceView = null;
+ if (fl_remote2.getChildCount() > 0) {
+ fl_remote2.removeAllViews();
+ }
+ // Create render view by RtcEngine
+ surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the remote container
+ fl_remote2.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_FIT, channel2, uid));
+ });
+ }
+ });
+ // 3. Configurate mediaOptions
+ ChannelMediaOptions mediaOptions = new ChannelMediaOptions();
+ mediaOptions.autoSubscribeAudio = true;
+ mediaOptions.autoSubscribeVideo = true;
+ // 4. Join channel
+ int ret = rtcChannel.joinChannel(null, "", 0, mediaOptions);
+ return (ret == 0);
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler() {
+ /**
+ * Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html
+ */
+ @Override
+ public void onWarning(int warn) {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**
+ * Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ */
+ @Override
+ public void onError(int err) {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**
+ * Occurs when a user leaves the channel.
+ *
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.
+ */
+ @Override
+ public void onLeaveChannel(RtcStats stats) {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**
+ * Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ *
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered
+ */
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ }
+ });
+ }
+
+ /**
+ * Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ *
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.
+ */
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed) {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**
+ * Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ *
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.
+ */
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed) {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**
+ * Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ *
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.
+ */
+ @Override
+ public void onUserJoined(int uid, int elapsed) {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ SurfaceView surfaceView = null;
+ if (fl_remote.getChildCount() > 0) {
+ fl_remote.removeAllViews();
+ }
+ // Create render view by RtcEngine
+ surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_FIT, uid));
+ });
+ }
+
+ /**
+ * Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ *
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.
+ */
+ @Override
+ public void onUserOffline(int uid, int reason) {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/MediaPlayerKit.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/MediaPlayerKit.java
new file mode 100644
index 000000000..ce7f04b31
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/MediaPlayerKit.java
@@ -0,0 +1,516 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+import android.widget.SeekBar;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.RtcChannelPublishHelper;
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.mediaplayer.AgoraMediaPlayerKit;
+import io.agora.mediaplayer.AudioFrameObserver;
+import io.agora.mediaplayer.Constants;
+import io.agora.mediaplayer.MediaPlayerObserver;
+import io.agora.mediaplayer.VideoFrameObserver;
+import io.agora.mediaplayer.data.AudioFrame;
+import io.agora.mediaplayer.data.VideoFrame;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+import io.agora.utils.LogUtil;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.mediaplayer.Constants.MediaPlayerState.PLAYER_STATE_OPEN_COMPLETED;
+import static io.agora.mediaplayer.Constants.MediaPlayerState.PLAYER_STATE_PLAYING;
+import static io.agora.mediaplayer.Constants.PLAYER_RENDER_MODE_FIT;
+import static io.agora.mediaplayer.Constants.PLAYER_RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+@Example(
+ index = 16,
+ group = ADVANCED,
+ name = R.string.item_mediaplayerkit,
+ actionId = R.id.action_mainFragment_to_MediaPlayerKit,
+ tipsId = R.string.mediaplayerkit
+)
+public class MediaPlayerKit extends BaseFragment implements View.OnClickListener {
+
+ private static final String TAG = MediaPlayerKit.class.getSimpleName();
+
+ private Button join;
+ private EditText et_channel;
+ private RtcEngine engine;
+ private int myUid;
+ private FrameLayout fl_local, fl_remote;
+
+ private AgoraMediaPlayerKit agoraMediaPlayerKit;
+ private boolean joined = false;
+ private SeekBar progressBar;
+
+ RtcChannelPublishHelper rtcChannelPublishHelper = RtcChannelPublishHelper.getInstance();
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_media_player_kit, container, false);
+ return view;
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ progressBar = view.findViewById(R.id.ctrl_progress_bar);
+ progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ agoraMediaPlayerKit.seek(progress);
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+
+ }
+
+ });
+ et_channel = view.findViewById(R.id.et_channel);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ agoraMediaPlayerKit = new AgoraMediaPlayerKit(this.getActivity());
+ agoraMediaPlayerKit.registerPlayerObserver(new MediaPlayerObserver() {
+ @Override
+ public void onPlayerStateChanged(Constants.MediaPlayerState state, Constants.MediaPlayerError error) {
+ LogUtil.i("agoraMediaPlayerKit1 onPlayerStateChanged:"+state+" "+error);
+ if(state.equals(PLAYER_STATE_OPEN_COMPLETED)){
+ agoraMediaPlayerKit.play();
+ }
+ else if(state.equals(PLAYER_STATE_PLAYING)){
+ rtcChannelPublishHelper.publishVideo();
+ rtcChannelPublishHelper.publishAudio();
+ }
+ }
+
+
+ @Override
+ public void onPositionChanged(final long position) {
+ LogUtil.i("agoraMediaPlayerKit1 onPositionChanged:"+position);
+ progressBar.setProgress(Long.valueOf(position).intValue());
+ }
+
+
+ @Override
+ public void onMetaData(Constants.MediaPlayerMetadataType mediaPlayerMetadataType, byte[] bytes) {
+
+ }
+
+ @Override
+ public void onPlayerEvent(Constants.MediaPlayerEvent eventCode) {
+ LogUtil.i("agoraMediaPlayerKit1 onEvent:"+eventCode);
+ }
+
+ });
+ agoraMediaPlayerKit.registerVideoFrameObserver(new VideoFrameObserver() {
+ @Override
+ public void onFrame(VideoFrame videoFrame) {
+ LogUtil.i("agoraMediaPlayerKit1 video onFrame :"+videoFrame);
+ }
+ });
+ agoraMediaPlayerKit.registerAudioFrameObserver(new AudioFrameObserver() {
+ @Override
+ public void onFrame(AudioFrame audioFrame) {
+ LogUtil.i("agoraMediaPlayerKit1 audio onFrame :"+audioFrame);
+ }
+ });
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+ if (v.getId() == R.id.btn_join)
+ {
+ if (!joined)
+ {
+// agoraMediaPlayerKit1.open("https://webdemo.agora.io/agora-web-showcase/examples/Agora-Custom-VideoSource-Web/assets/sample.mp4", 0);
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ }
+ else
+ {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ }
+ }
+ }
+
+ private void joinChannel(String channelId)
+ {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(io.agora.rtc.Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ VD_640x360,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+
+ rtcChannelPublishHelper.attachPlayerToRtc(agoraMediaPlayerKit, engine); // Create render view by RtcEngine
+ SurfaceView surfaceView = new SurfaceView(this.getActivity());
+ surfaceView.setZOrderMediaOverlay(false);
+ if(fl_local.getChildCount() > 0)
+ {
+ fl_local.removeAllViews();
+ }
+ String videoUrl = "https://webdemo.agora.io/agora-web-showcase/examples/Agora-Custom-VideoSource-Web/assets/sample.mp4";
+ fl_local.addView(surfaceView);
+ agoraMediaPlayerKit.setView(surfaceView);
+ agoraMediaPlayerKit.setRenderMode(PLAYER_RENDER_MODE_FIT);
+ agoraMediaPlayerKit.open(videoUrl, 0);
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats)
+ {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(() -> {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed)
+ {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ SurfaceView surfaceView = null;
+ if (fl_remote.getChildCount() > 0)
+ {
+ fl_remote.removeAllViews();
+ }
+ // Create render view by RtcEngine
+ surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason)
+ {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+ };
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ agoraMediaPlayerKit.destroy();
+ if(engine != null)
+ {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/PlayAudioFiles.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/PlayAudioFiles.java
new file mode 100644
index 000000000..a271a9087
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/PlayAudioFiles.java
@@ -0,0 +1,464 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.SeekBar;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.component.Constant;
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IAudioEffectManager;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+
+@Example(
+ index = 14,
+ group = ADVANCED,
+ name = R.string.item_playaudiofiles,
+ actionId = R.id.action_mainFragment_to_PlayAudioFiles,
+ tipsId = R.string.playaudiofiles
+)
+public class PlayAudioFiles extends BaseFragment implements View.OnClickListener, SeekBar.OnSeekBarChangeListener {
+ private static final String TAG = PlayAudioFiles.class.getSimpleName();
+ private EditText et_channel;
+ private Button mute, join, speaker, bgm, effect;
+ private SeekBar mixingPublishVolBar, mixingPlayoutVolBar, mixingVolBar;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false;
+ private IAudioEffectManager audioEffectManager;
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ handler = new Handler();
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_play_audio_files, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ mute = view.findViewById(R.id.btn_mute);
+ mute.setOnClickListener(this);
+ speaker = view.findViewById(R.id.btn_speaker);
+ speaker.setOnClickListener(this);
+ bgm = view.findViewById(R.id.btn_bgm);
+ bgm.setOnClickListener(this);
+ effect = view.findViewById(R.id.btn_effect);
+ effect.setOnClickListener(this);
+ mixingPublishVolBar = view.findViewById(R.id.mixingPublishVolBar);
+ mixingPlayoutVolBar = view.findViewById(R.id.mixingPlayoutVolBar);
+ mixingVolBar = view.findViewById(R.id.mixingVolBar);
+ mixingPlayoutVolBar.setOnSeekBarChangeListener(this);
+ mixingPublishVolBar.setOnSeekBarChangeListener(this);
+ mixingVolBar.setOnSeekBarChangeListener(this);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ String appId = getString(R.string.agora_app_id);
+ engine = RtcEngine.create(getContext().getApplicationContext(), appId, iRtcEngineEventHandler);
+
+ preloadAudioEffect();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ /**
+ * To ensure smooth communication, limit the size of the audio effect file.
+ * We recommend using this method to preload the audio effect before calling the joinChannel method.
+ */
+ private void preloadAudioEffect(){
+ // Gets the global audio effect manager.
+ audioEffectManager = engine.getAudioEffectManager();
+ // Preloads the audio effect (recommended). Note the file size, and preload the file before joining the channel.
+ // Only mp3, aac, m4a, 3gp, and wav files are supported.
+ // You may need to record the sound IDs and their file paths.
+ int id = 0;
+ audioEffectManager.preloadEffect(id++, Constant.EFFECT_FILE_PATH);
+ /** Plays an audio effect file.
+ * Returns
+ * 0: Success.
+ * < 0: Failure.
+ */
+ audioEffectManager.playEffect(
+ 0, // The sound ID of the audio effect file to be played.
+ Constant.EFFECT_FILE_PATH, // The file path of the audio effect file.
+ -1, // The number of playback loops. -1 means an infinite loop.
+ 1, // pitch The pitch of the audio effect. The value ranges between 0.5 and 2. The default value is 1 (no change to the pitch). The lower the value, the lower the pitch.
+ 0.0, // Sets the spatial position of the effect. 0 means the effect shows ahead.
+ 100, // Sets the volume. The value ranges between 0 and 100. 100 is the original volume.
+ true // Sets whether to publish the audio effect.
+ );
+ // Pauses all audio effects.
+ audioEffectManager.pauseAllEffects();
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if(engine != null)
+ {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+ if (v.getId() == R.id.btn_join)
+ {
+ if (!joined)
+ {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ }
+ else
+ {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ speaker.setText(getString(R.string.speaker));
+ speaker.setEnabled(false);
+ mute.setText(getString(R.string.closemicrophone));
+ mute.setEnabled(false);
+ bgm.setEnabled(false);
+ bgm.setText(getString(R.string.bgm_on));
+ effect.setEnabled(false);
+ effect.setText(getString(R.string.effect_on));
+ }
+ }
+ else if (v.getId() == R.id.btn_mute)
+ {
+ mute.setActivated(!mute.isActivated());
+ mute.setText(getString(mute.isActivated() ? R.string.openmicrophone : R.string.closemicrophone));
+ /**Turn off / on the microphone, stop / start local audio collection and push streaming.*/
+ engine.muteLocalAudioStream(mute.isActivated());
+ }
+ else if (v.getId() == R.id.btn_speaker)
+ {
+ speaker.setActivated(!speaker.isActivated());
+ speaker.setText(getString(speaker.isActivated() ? R.string.earpiece : R.string.speaker));
+ /**Turn off / on the speaker and change the audio playback route.*/
+ engine.setEnableSpeakerphone(speaker.isActivated());
+ }
+ else if(v.getId() == R.id.btn_bgm)
+ {
+ bgm.setActivated(!bgm.isActivated());
+ bgm.setText(!bgm.isActivated()?getString(R.string.bgm_on):getString(R.string.bgm_off));
+ if(bgm.isActivated()){
+ engine.startAudioMixing(Constant.MIX_FILE_PATH, false, false, -1);
+ }
+ else{
+ engine.stopAudioMixing();
+ }
+ }
+ else if (v.getId() == R.id.btn_effect)
+ {
+ effect.setActivated(!effect.isActivated());
+ effect.setText(!effect.isActivated() ? getString(R.string.effect_on): getString(R.string.effect_off));
+ if(effect.isActivated()){
+ // Resumes playing all audio effects.
+ audioEffectManager.resumeAllEffects();
+ }
+ else {
+ // Pauses all audio effects.
+ audioEffectManager.pauseAllEffects();
+ }
+ }
+ }
+
+ /**
+ * @param channelId Specify the channel name that you want to join.
+ * Users that input the same channel name join the same channel.*/
+ private void joinChannel(String channelId)
+ {
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ Log.e(TAG, RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ /**IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats)
+ {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ speaker.setEnabled(true);
+ mute.setEnabled(true);
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ bgm.setEnabled(true);
+ effect.setEnabled(true);
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed)
+ {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason)
+ {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ }
+ };
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ if(seekBar.getId() == R.id.mixingPublishVolBar){
+ /**
+ * Adjusts the volume of audio mixing for publishing (sending to other users).
+ * @param volume: Audio mixing volume for publishing. The value ranges between 0 and 100 (default).
+ */
+ engine.adjustAudioMixingPublishVolume(progress);
+ }
+ else if(seekBar.getId() == R.id.mixingPlayoutVolBar){
+ /**
+ * Adjusts the volume of audio mixing for local playback.
+ * @param volume: Audio mixing volume for local playback. The value ranges between 0 and 100 (default).
+ */
+ engine.adjustAudioMixingPlayoutVolume(progress);
+ }
+ else if(seekBar.getId() == R.id.mixingVolBar){
+ /**
+ * Adjusts the volume of audio mixing.
+ * Call this method when you are in a channel.
+ * @param volume: Audio mixing volume. The value ranges between 0 and 100 (default).
+ */
+ engine.adjustAudioMixingVolume(progress);
+ }
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/PreCallTest.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/PreCallTest.java
new file mode 100644
index 000000000..af92d1098
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/PreCallTest.java
@@ -0,0 +1,300 @@
+package io.agora.api.example.examples.advanced;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.util.StringUtils;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.common.model.StatisticsInfo;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.internal.LastmileProbeConfig;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+
+@Example(
+ index = 18,
+ group = ADVANCED,
+ name = R.string.item_precalltest,
+ actionId = R.id.action_mainFragment_to_PreCallTest,
+ tipsId = R.string.precalltest
+)
+public class PreCallTest extends BaseFragment implements View.OnClickListener {
+ private static final String TAG = PreCallTest.class.getSimpleName();
+
+ private RtcEngine engine;
+ private int myUid;
+ private Button btn_lastmile, btn_echo;
+ private StatisticsInfo statisticsInfo;
+ private TextView lastmileQuality, lastmileResult;
+ private static final Integer MAX_COUNT_DOWN = 8;
+ private int num;
+ private Timer timer;
+ private TimerTask task;
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ handler = new Handler();
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_precall_test, container, false);
+ return view;
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ try {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ String appId = getString(R.string.agora_app_id);
+ engine = RtcEngine.create(getContext().getApplicationContext(), appId, iRtcEngineEventHandler);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ statisticsInfo = new StatisticsInfo();
+ btn_echo = view.findViewById(R.id.btn_echo);
+ btn_echo.setOnClickListener(this);
+ btn_lastmile = view.findViewById(R.id.btn_lastmile);
+ btn_lastmile.setOnClickListener(this);
+ lastmileQuality = view.findViewById(R.id.lastmile_quality);
+ lastmileResult = view.findViewById(R.id.lastmile_result);
+ task = new TimerTask(){
+ public void run() {
+ num++;
+ if(num >= MAX_COUNT_DOWN * 2){
+ handler.post(() -> {
+ btn_echo.setEnabled(true);
+ btn_echo.setText("Start");
+ });
+ engine.stopEchoTest();
+ timer.cancel();
+ task.cancel();
+ }
+ else if(num >= MAX_COUNT_DOWN) {
+ handler.post(() -> btn_echo.setText("PLaying with " + (MAX_COUNT_DOWN * 2 - num) + "Seconds"));
+ }
+ else{
+ handler.post(() -> btn_echo.setText("Recording with " + (MAX_COUNT_DOWN - num) + "Seconds"));
+ }
+ }
+ };
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.btn_lastmile)
+ {
+ // Configure a LastmileProbeConfig instance.
+ LastmileProbeConfig config = new LastmileProbeConfig(){};
+ // Probe the uplink network quality.
+ config.probeUplink = true;
+ // Probe the downlink network quality.
+ config.probeDownlink = true;
+ // The expected uplink bitrate (bps). The value range is [100000, 5000000].
+ config.expectedUplinkBitrate = 100000;
+ // The expected downlink bitrate (bps). The value range is [100000, 5000000].
+ config.expectedDownlinkBitrate = 100000;
+ // Start the last-mile network test before joining the channel.
+ engine.startLastmileProbeTest(config);
+ btn_lastmile.setEnabled(false);
+ btn_lastmile.setText("Testing ...");
+ }
+ else if (v.getId() == R.id.btn_echo){
+ num = 0;
+ engine.startEchoTest(MAX_COUNT_DOWN);
+ btn_echo.setEnabled(false);
+ btn_echo.setText("Recording on Microphone ...");
+ timer = new Timer(true);
+ timer.schedule(task, 1000, 1000);
+ }
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler() {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn) {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err) {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats) {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed) {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed) {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason) {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ }
+
+ /**
+ * Implemented in the global IRtcEngineEventHandler class.
+ * Triggered 2 seconds after starting the last-mile test.
+ * @param quality
+ */
+ @Override
+ public void onLastmileQuality(int quality){
+ statisticsInfo.setLastMileQuality(quality);
+ updateLastMileResult();
+ }
+
+ /**
+ * Implemented in the global IRtcEngineEventHandler class.
+ * Triggered 30 seconds after starting the last-mile test.
+ * @param lastmileProbeResult
+ */
+ @Override
+ public void onLastmileProbeResult(LastmileProbeResult lastmileProbeResult) {
+ // (1) Stop the test. Agora recommends not calling any other API method before the test ends.
+ engine.stopLastmileProbeTest();
+ statisticsInfo.setLastMileProbeResult(lastmileProbeResult);
+ updateLastMileResult();
+ handler.post(() -> {
+ btn_lastmile.setEnabled(true);
+ btn_lastmile.setText("Start");
+ });
+ }
+ };
+
+ private void updateLastMileResult() {
+ handler.post(() -> {
+ if(statisticsInfo.getLastMileQuality() != null){
+ lastmileQuality.setText("Quality: " + statisticsInfo.getLastMileQuality());
+ }
+ if(statisticsInfo.getLastMileResult() != null){
+ lastmileResult.setText(statisticsInfo.getLastMileResult());
+ }
+ });
+ }
+
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/ProcessRawData.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/ProcessRawData.java
new file mode 100644
index 000000000..866a020a7
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/ProcessRawData.java
@@ -0,0 +1,487 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.advancedvideo.rawdata.MediaDataAudioObserver;
+import io.agora.advancedvideo.rawdata.MediaDataObserverPlugin;
+import io.agora.advancedvideo.rawdata.MediaDataVideoObserver;
+import io.agora.advancedvideo.rawdata.MediaPreProcessing;
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.api.example.utils.YUVUtils;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.Constants.RAW_AUDIO_FRAME_OP_MODE_READ_ONLY;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+@Example(
+ index = 10,
+ group = ADVANCED,
+ name = R.string.item_processraw,
+ actionId = R.id.action_mainFragment_to_ProcessRawData,
+ tipsId = R.string.processrawdata
+)
+public class ProcessRawData extends BaseFragment implements View.OnClickListener, MediaDataVideoObserver,
+ MediaDataAudioObserver {
+ private static final String TAG = ProcessRawData.class.getSimpleName();
+
+ private FrameLayout fl_local, fl_remote;
+ private Button join, blurBtn;
+ private EditText et_channel;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false, blur = true;
+ private MediaDataObserverPlugin mediaDataObserverPlugin;
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ try {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_process_rawdata, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ blurBtn = view.findViewById(R.id.btn_blur);
+ et_channel = view.findViewById(R.id.et_channel);
+ join.setOnClickListener(this);
+ blurBtn.setOnClickListener(this);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ mediaDataObserverPlugin = MediaDataObserverPlugin.the();
+ MediaPreProcessing.setCallback(mediaDataObserverPlugin);
+ MediaPreProcessing.setVideoCaptureByteBuffer(mediaDataObserverPlugin.byteBufferCapture);
+ mediaDataObserverPlugin.addVideoObserver(this);
+ }
+
+ @Override
+ public void onDestroy() {
+ if (mediaDataObserverPlugin != null) {
+ mediaDataObserverPlugin.removeVideoObserver(this);
+ mediaDataObserverPlugin.removeAllBuffer();
+ }
+ MediaPreProcessing.releasePoint();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if (engine != null) {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ super.onDestroy();
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.btn_join) {
+ if (!joined) {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA)) {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ } else {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ }
+ } else if (v.getId() == R.id.btn_blur) {
+ if (!blur) {
+ blur = true;
+ blurBtn.setText(getString(R.string.blur));
+ } else {
+ blur = false;
+ blurBtn.setText(getString(R.string.closeblur));
+ }
+ }
+ }
+
+ private void joinChannel(String channelId) {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the local container
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ VD_640x360,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+ /**Set up to play remote sound with receiver*/
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+ engine.setEnableSpeakerphone(false);
+
+ /**
+ * Sets the audio recording format for the onRecordAudioFrame callback.
+ * sampleRate Sets the sample rate (samplesPerSec) returned in the onRecordAudioFrame callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
+ * channel Sets the number of audio channels (channels) returned in the onRecordAudioFrame callback:
+ * 1: Mono
+ * 2: Stereo
+ * mode Sets the use mode (see RAW_AUDIO_FRAME_OP_MODE_TYPE) of the onRecordAudioFrame callback.
+ * samplesPerCall Sets the number of samples returned in the onRecordAudioFrame callback. samplesPerCall is usually set as 1024 for RTMP streaming.
+ * The SDK triggers the onRecordAudioFrame callback according to the sample interval. Ensure that the sample interval ≥ 0.01 (s). And, Sample interval (sec) = samplePerCall/(sampleRate × channel).
+ */
+ engine.setRecordingAudioFrameParameters(4000, 1, RAW_AUDIO_FRAME_OP_MODE_READ_ONLY, 1024);
+
+ /**
+ * Sets the audio playback format for the onPlaybackAudioFrame callback.
+ * sampleRate Sets the sample rate (samplesPerSec) returned in the onRecordAudioFrame callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
+ * channel Sets the number of audio channels (channels) returned in the onRecordAudioFrame callback:
+ * 1: Mono
+ * 2: Stereo
+ * mode Sets the use mode (see RAW_AUDIO_FRAME_OP_MODE_TYPE) of the onRecordAudioFrame callback.
+ * samplesPerCall Sets the number of samples returned in the onRecordAudioFrame callback. samplesPerCall is usually set as 1024 for RTMP streaming.
+ * The SDK triggers the onRecordAudioFrame callback according to the sample interval. Ensure that the sample interval ≥ 0.01 (s). And, Sample interval (sec) = samplePerCall/(sampleRate × channel).
+ */
+ engine.setPlaybackAudioFrameParameters(4000, 1, RAW_AUDIO_FRAME_OP_MODE_READ_ONLY, 1024);
+
+ /**
+ * Sets the mixed audio format for the onMixedAudioFrame callback.
+ * sampleRate Sets the sample rate (samplesPerSec) returned in the onMixedAudioFrame callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
+ * samplesPerCall Sets the number of samples (samples) returned in the onMixedAudioFrame callback. samplesPerCall is usually set as 1024 for RTMP streaming.
+ */
+ engine.setMixedAudioFrameParameters(8000, 1024);
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>")) {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0) {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler() {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn) {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err) {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats) {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ }
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed) {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ if (mediaDataObserverPlugin != null) {
+ mediaDataObserverPlugin.addDecodeBuffer(uid);
+ }
+
+ /**Display remote video stream*/
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ if (fl_remote.getChildCount() > 0) {
+ fl_remote.removeAllViews();
+ }
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason) {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ if (mediaDataObserverPlugin != null) {
+ mediaDataObserverPlugin.removeDecodeBuffer(uid);
+ }
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+ };
+
+ @Override
+ public void onCaptureVideoFrame(byte[] data, int frameType, int width, int height, int bufferLength, int yStride, int uStride, int vStride, int rotation, long renderTimeMs) {
+ /**You can do some processing on the video frame here*/
+ Log.e(TAG, "onCaptureVideoFrame0");
+ if (blur) {
+ return;
+ }
+ Bitmap bitmap = YUVUtils.i420ToBitmap(width, height, rotation, bufferLength, data, yStride, uStride, vStride);
+ Bitmap bmp = YUVUtils.blur(getContext(), bitmap, 4);
+ System.arraycopy(YUVUtils.bitmapToI420(width, height, bmp), 0, data, 0, bufferLength);
+ }
+
+ @Override
+ public void onRenderVideoFrame(int uid, byte[] data, int frameType, int width, int height, int bufferLength, int yStride, int uStride, int vStride, int rotation, long renderTimeMs) {
+ if (blur) {
+ return;
+ }
+ Bitmap bmp = YUVUtils.blur(getContext(), YUVUtils.i420ToBitmap(width, height, rotation, bufferLength, data, yStride, uStride, vStride), 4);
+ System.arraycopy(YUVUtils.bitmapToI420(width, height, bmp), 0, data, 0, bufferLength);
+ }
+
+ @Override
+ public void onPreEncodeVideoFrame(byte[] data, int frameType, int width, int height, int bufferLength, int yStride, int uStride, int vStride, int rotation, long renderTimeMs) {
+ /**You can do some processing on the video frame here*/
+ Log.e(TAG, "onPreEncodeVideoFrame0");
+ }
+
+ /**
+ * Retrieves the recorded audio frame.
+ * @param audioFrameType only support FRAME_TYPE_PCM16
+ * @param samples The number of samples per channel in the audio frame.
+ * @param bytesPerSample The number of bytes per audio sample, which is usually 16-bit (2-byte).
+ * @param channels The number of audio channels.
+ * 1: Mono
+ * 2: Stereo (the data is interleaved)
+ * @param samplesPerSec The sample rate.
+ * @param renderTimeMs The timestamp of the external audio frame.
+ * @param bufferLength audio frame size*/
+ @Override
+ public void onRecordAudioFrame(byte[] data, int audioFrameType, int samples, int bytesPerSample, int channels, int samplesPerSec, long renderTimeMs, int bufferLength) {
+
+ }
+
+ /**
+ * Retrieves the audio playback frame for getting the audio.
+ * @param audioFrameType only support FRAME_TYPE_PCM16
+ * @param samples The number of samples per channel in the audio frame.
+ * @param bytesPerSample The number of bytes per audio sample, which is usually 16-bit (2-byte).
+ * @param channels The number of audio channels.
+ * 1: Mono
+ * 2: Stereo (the data is interleaved)
+ * @param samplesPerSec The sample rate.
+ * @param renderTimeMs The timestamp of the external audio frame.
+ * @param bufferLength audio frame size*/
+ @Override
+ public void onPlaybackAudioFrame(byte[] data, int audioFrameType, int samples, int bytesPerSample, int channels, int samplesPerSec, long renderTimeMs, int bufferLength) {
+
+ }
+
+
+ /**
+ * Retrieves the audio frame of a specified user before mixing.
+ * The SDK triggers this callback if isMultipleChannelFrameWanted returns false.
+ * @param uid remote user id
+ * @param audioFrameType only support FRAME_TYPE_PCM16
+ * @param samples The number of samples per channel in the audio frame.
+ * @param bytesPerSample The number of bytes per audio sample, which is usually 16-bit (2-byte).
+ * @param channels The number of audio channels.
+ * 1: Mono
+ * 2: Stereo (the data is interleaved)
+ * @param samplesPerSec The sample rate.
+ * @param renderTimeMs The timestamp of the external audio frame.
+ * @param bufferLength audio frame size*/
+ @Override
+ public void onPlaybackAudioFrameBeforeMixing(int uid, byte[] data, int audioFrameType, int samples, int bytesPerSample, int channels, int samplesPerSec, long renderTimeMs, int bufferLength) {
+
+ }
+
+ /**
+ * Retrieves the mixed recorded and playback audio frame.
+ * @param audioFrameType only support FRAME_TYPE_PCM16
+ * @param samples The number of samples per channel in the audio frame.
+ * @param bytesPerSample The number of bytes per audio sample, which is usually 16-bit (2-byte).
+ * @param channels The number of audio channels.
+ * 1: Mono
+ * 2: Stereo (the data is interleaved)
+ * @param samplesPerSec The sample rate.
+ * @param renderTimeMs The timestamp of the external audio frame.
+ * @param bufferLength audio frame size*/
+ @Override
+ public void onMixedAudioFrame(byte[] data, int audioFrameType, int samples, int bytesPerSample, int channels, int samplesPerSec, long renderTimeMs, int bufferLength) {
+
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/PushExternalVideo.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/PushExternalVideo.java
new file mode 100644
index 000000000..55e2d4094
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/PushExternalVideo.java
@@ -0,0 +1,501 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.graphics.SurfaceTexture;
+import android.hardware.Camera;
+import android.opengl.EGLSurface;
+import android.opengl.GLES11Ext;
+import android.opengl.GLES20;
+import android.opengl.Matrix;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.TextureView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import java.io.IOException;
+
+import io.agora.api.component.gles.ProgramTextureOES;
+import io.agora.api.component.gles.core.EglCore;
+import io.agora.api.component.gles.core.GlUtil;
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.gl.VideoFrame;
+import io.agora.rtc.video.AgoraVideoFrame;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_FIXED_PORTRAIT;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+@Example(
+ index = 5,
+ group = ADVANCED,
+ name = R.string.item_pushexternal,
+ actionId = R.id.action_mainFragment_to_PushExternalVideo,
+ tipsId = R.string.pushexternalvideo
+)
+public class PushExternalVideo extends BaseFragment implements View.OnClickListener, TextureView.SurfaceTextureListener,
+ SurfaceTexture.OnFrameAvailableListener {
+ private static final String TAG = PushExternalVideo.class.getSimpleName();
+ private final int DEFAULT_CAPTURE_WIDTH = 640;
+ private final int DEFAULT_CAPTURE_HEIGHT = 480;
+
+ private FrameLayout fl_local, fl_remote;
+ private Button join;
+ private EditText et_channel;
+ private RtcEngine engine;
+ private int myUid;
+ private volatile boolean joined = false;
+
+ private int mPreviewTexture;
+ private SurfaceTexture mPreviewSurfaceTexture;
+ private EglCore mEglCore;
+ private EGLSurface mDummySurface;
+ private EGLSurface mDrawSurface;
+ private ProgramTextureOES mProgram;
+ private float[] mTransform = new float[16];
+ private float[] mMVPMatrix = new float[16];
+ private boolean mMVPMatrixInit = false;
+ private Camera mCamera;
+ private int mFacing = Camera.CameraInfo.CAMERA_FACING_FRONT;
+ private boolean mPreviewing = false;
+ private int mSurfaceWidth;
+ private int mSurfaceHeight;
+ private boolean mTextureDestroyed;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_push_externalvideo, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ try {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+
+ @Override
+ public void onDestroy() {
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if (engine != null) {
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ super.onDestroy();
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.btn_join) {
+ if (!joined) {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA)) {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ } else {
+ fl_local.setVisibility(View.GONE);
+ getActivity().onBackPressed();
+ }
+ }
+ }
+
+ private void joinChannel(String channelId) {
+// engine.setParameters("{\"rtc.log_filter\":65535}");
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ TextureView textureView = new TextureView(getContext());
+ //add SurfaceTextureListener
+ textureView.setSurfaceTextureListener(this);
+ // Add to the local container
+ fl_local.addView(textureView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+ /**Set up to play remote sound with receiver*/
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+ engine.setEnableSpeakerphone(false);
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enables the video module.
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ new VideoEncoderConfiguration.VideoDimensions(DEFAULT_CAPTURE_WIDTH, DEFAULT_CAPTURE_HEIGHT),
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_FIXED_PORTRAIT
+ ));
+ /**Configures the external video source.
+ * @param enable Sets whether or not to use the external video source:
+ * true: Use the external video source.
+ * false: Do not use the external video source.
+ * @param useTexture Sets whether or not to use texture as an input:
+ * true: Use texture as an input.
+ * false: (Default) Do not use texture as an input.
+ * @param pushMode Sets whether or not the external video source needs to call the PushExternalVideoFrame
+ * method to send the video frame to the Agora SDK:
+ * true: Use the push mode.
+ * false: Use the pull mode (not supported).*/
+ engine.setExternalVideoSource(true, true, true);
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>")) {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0) {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ @Override
+ public void onFrameAvailable(SurfaceTexture surfaceTexture) {
+ if (mTextureDestroyed) {
+ return;
+ }
+
+ if (!mEglCore.isCurrent(mDrawSurface)) {
+ mEglCore.makeCurrent(mDrawSurface);
+ }
+ try {
+ mPreviewSurfaceTexture.updateTexImage();
+ mPreviewSurfaceTexture.getTransformMatrix(mTransform);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ /**The rectangle ratio of frames and the screen surface may be different, so cropping may
+ * happen when display frames to the screen.
+ * The display transformation matrix does not change for the same camera when the screen
+ * orientation remains the same.*/
+ if (!mMVPMatrixInit) {
+ /***/
+ /**For simplicity, we only consider the activity as portrait mode. In this case, the captured
+ * images should be rotated 90 degrees (left or right).Thus the frame width and height
+ * should be swapped.*/
+ float frameRatio = DEFAULT_CAPTURE_HEIGHT / (float) DEFAULT_CAPTURE_WIDTH;
+ float surfaceRatio = mSurfaceWidth / (float) mSurfaceHeight;
+ Matrix.setIdentityM(mMVPMatrix, 0);
+
+ if (frameRatio >= surfaceRatio) {
+ float w = DEFAULT_CAPTURE_WIDTH * surfaceRatio;
+ float scaleW = DEFAULT_CAPTURE_HEIGHT / w;
+ Matrix.scaleM(mMVPMatrix, 0, scaleW, 1, 1);
+ } else {
+ float h = DEFAULT_CAPTURE_HEIGHT / surfaceRatio;
+ float scaleH = DEFAULT_CAPTURE_WIDTH / h;
+ Matrix.scaleM(mMVPMatrix, 0, 1, scaleH, 1);
+ }
+ mMVPMatrixInit = true;
+ }
+ GLES20.glViewport(0, 0, mSurfaceWidth, mSurfaceHeight);
+ mProgram.drawFrame(mPreviewTexture, mTransform, mMVPMatrix);
+ mEglCore.swapBuffers(mDrawSurface);
+
+ if (joined) {
+ /**about AgoraVideoFrame, see https://docs.agora.io/en/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1video_1_1_agora_video_frame.html*/
+ AgoraVideoFrame frame = new AgoraVideoFrame();
+ frame.textureID = mPreviewTexture;
+ frame.format = AgoraVideoFrame.FORMAT_TEXTURE_OES;
+ frame.transform = mTransform;
+ frame.stride = DEFAULT_CAPTURE_HEIGHT;
+ frame.height = DEFAULT_CAPTURE_WIDTH;
+ frame.eglContext14 = mEglCore.getEGLContext();
+ frame.timeStamp = System.currentTimeMillis();
+ /**Pushes the video frame using the AgoraVideoFrame class and passes the video frame to the Agora SDK.
+ * Call the setExternalVideoSource method and set pushMode as true before calling this
+ * method. Otherwise, a failure returns after calling this method.
+ * @param frame AgoraVideoFrame
+ * @return
+ * true: The frame is pushed successfully.
+ * false: Failed to push the frame.
+ * PS:
+ * In the Communication profile, the SDK does not support textured video frames.*/
+ boolean a = engine.pushExternalVideoFrame(frame);
+ Log.e(TAG, "pushExternalVideoFrame:" + a);
+ }
+ }
+
+ @Override
+ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
+ Log.i(TAG, "onSurfaceTextureAvailable");
+ mTextureDestroyed = false;
+ mSurfaceWidth = width;
+ mSurfaceHeight = height;
+ mEglCore = new EglCore();
+ mDummySurface = mEglCore.createOffscreenSurface(1, 1);
+ mEglCore.makeCurrent(mDummySurface);
+ mPreviewTexture = GlUtil.createTextureObject(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
+ mPreviewSurfaceTexture = new SurfaceTexture(mPreviewTexture);
+ mPreviewSurfaceTexture.setOnFrameAvailableListener(this);
+ mDrawSurface = mEglCore.createWindowSurface(surface);
+ mProgram = new ProgramTextureOES();
+ if (mCamera != null || mPreviewing) {
+ Log.e(TAG, "Camera preview has been started");
+ return;
+ }
+ try {
+ mCamera = Camera.open(mFacing);
+ /**It is assumed to capture images of resolution 640x480. During development, it should
+ * be the most suitable supported resolution that best fits the scenario.*/
+ Camera.Parameters parameters = mCamera.getParameters();
+ parameters.setPreviewSize(DEFAULT_CAPTURE_WIDTH, DEFAULT_CAPTURE_HEIGHT);
+ mCamera.setParameters(parameters);
+ mCamera.setPreviewTexture(mPreviewSurfaceTexture);
+ /**The display orientation is 90 for both front and back facing cameras using a surface
+ * texture for the preview when the screen is in portrait mode.*/
+ mCamera.setDisplayOrientation(90);
+ mCamera.startPreview();
+ mPreviewing = true;
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
+
+ }
+
+ @Override
+ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
+ Log.i(TAG, "onSurfaceTextureDestroyed");
+ mTextureDestroyed = true;
+ if (mCamera != null && mPreviewing) {
+ mCamera.stopPreview();
+ mPreviewing = false;
+ mCamera.release();
+ mCamera = null;
+ }
+ mProgram.release();
+ mEglCore.releaseSurface(mDummySurface);
+ mEglCore.releaseSurface(mDrawSurface);
+ mEglCore.release();
+ return true;
+ }
+
+ @Override
+ public void onSurfaceTextureUpdated(SurfaceTexture surface) {
+
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler() {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn) {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err) {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats) {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ }
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed) {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ if (fl_remote.getChildCount() > 0) {
+ fl_remote.removeAllViews();
+ }
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason) {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/RTMPInjection.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/RTMPInjection.java
new file mode 100644
index 000000000..65db0521b
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/RTMPInjection.java
@@ -0,0 +1,541 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.live.LiveInjectStreamConfig;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+/**
+ * This example demonstrates how to pull flow from an external address.
+ *
+ * Important:
+ * Users who push and pull streams cannot be in one channel,
+ * otherwise unexpected errors will occur.
+ */
+@Example(
+ index = 4,
+ group = ADVANCED,
+ name = R.string.item_rtmpinjection,
+ actionId = R.id.action_mainFragment_to_RTMPInjection,
+ tipsId = R.string.rtmpinjection
+)
+public class RTMPInjection extends BaseFragment implements View.OnClickListener
+{
+ private static final String TAG = RTMPInjection.class.getSimpleName();
+
+ private FrameLayout fl_local, fl_remote;
+ private EditText et_url, et_channel;
+ private Button join, inject;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false, injecting = false;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_rtmp_injection, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ et_channel = view.findViewById(R.id.et_channel);
+ et_url = view.findViewById(R.id.et_url);
+ join = view.findViewById(R.id.btn_join);
+ join.setOnClickListener(this);
+ inject = view.findViewById(R.id.btn_inject);
+ inject.setOnClickListener(this);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if(engine != null)
+ {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+
+ if (v.getId() == R.id.btn_join)
+ {
+ if(!joined)
+ {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ }
+ else
+ {
+ engine.leaveChannel();
+ joined = false;
+ join.setText(getString(R.string.join));
+ injecting = false;
+ inject.setEnabled(false);
+ inject.setText(getString(R.string.inject));
+ }
+ }
+ else if (v.getId() == R.id.btn_inject)
+ {
+ /**Ensure that the user joins a channel before calling this method.*/
+ if(joined && !injecting)
+ {
+ startInjection();
+ }
+ else if(joined && injecting)
+ {
+ stopInjection();
+ }
+ }
+ }
+
+ private void joinChannel(String channelId)
+ {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the local container
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+ /**Set up to play remote sound with receiver*/
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+ engine.setEnableSpeakerphone(false);
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ VD_640x360,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ private void startInjection()
+ {
+ /**Configuration of the imported live broadcast voice or video stream.
+ * See */
+ LiveInjectStreamConfig config = new LiveInjectStreamConfig();
+ /**Injects an online media stream to a live broadcast.
+ * If this method call is successful, the server pulls the voice or video stream and injects
+ * it into a live channel. This is applicable to scenarios where all audience members in the
+ * channel can watch a live show and interact with each other.
+ * The addInjectStreamUrl method call triggers the following callbacks:
+ * The local client:
+ * onStreamInjectedStatus, with the state of the injecting the online stream.
+ * onUserJoined(uid: 666), if the method call is successful and the online media stream
+ * is injected into the channel.
+ * The remote client:
+ * onUserJoined(uid: 666), if the method call is successful and the online media stream
+ * is injected into the channel.
+ * @param url The URL address to be added to the ongoing live broadcast. Valid protocols are RTMP, HLS, and HTTP-FLV.
+ * Supported FLV audio codec type: AAC.
+ * Supported FLV video codec type: H264(AVC).
+ * @param config The LiveInjectStreamConfig object which contains the configuration information
+ * for the added voice or video stream.
+ * @return
+ * 0: Success.
+ * < 0: Failure.
+ * ERR_INVALID_ARGUMENT(2): The injected URL does not exist. Call this method again to
+ * inject the stream and ensure that the URL is valid.
+ * ERR_NOT_READY(3): The user is not in the channel.
+ * ERR_NOT_SUPPORTED(4): The channel profile is not Live Broadcast. Call the setChannelProfile
+ * method and set the channel profile to Live Broadcast before calling this method.
+ * ERR_NOT_INITIALIZED(7): The SDK is not initialized. Ensure that the RtcEngine object
+ * is initialized before using this method.
+ * PS:
+ * This method applies to the Live-Broadcast profile only.
+ * Ensure that you enable the RTMP Converter service before using this function. See
+ * Prerequisites in Push Streams to CDN.
+ * You can inject only one media stream into the channel at the same time.*/
+ engine.addInjectStreamUrl(et_url.getText().toString(), config);
+ }
+
+ private void stopInjection()
+ {
+ injecting = false;
+ inject.setEnabled(true);
+ inject.setText(getString(R.string.inject));
+ /**Removes the injected online media stream from a live broadcast.
+ * This method removes the URL address (added by addInjectStreamUrl) from a live broadcast.
+ * If this method call is successful, the SDK triggers the onUserOffline callback and returns
+ * a stream uid of 666.
+ * @param url HTTP/HTTPS URL address of the added stream to be removed.
+ * @return
+ * 0: Success.
+ * < 0: Failure.*/
+ int ret = engine.removeInjectStreamUrl(et_url.getText().toString());
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats)
+ {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ inject.setEnabled(true);
+ inject.setText(getString(R.string.inject));
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Reports the status of injecting the online media stream.
+ * @param url The URL address of the externally injected stream.
+ * @param uid User ID.
+ * @param status
+ * INJECT_STREAM_STATUS_START_SUCCESS(0): The external video stream imports successfully.
+ * INJECT_STREAM_STATUS_START_ALREADY_EXIST(1): The external video stream already exists.
+ * INJECT_STREAM_STATUS_START_UNAUTHORIZED(2): The external video stream import is unauthorized.
+ * INJECT_STREAM_STATUS_START_TIMEDOUT(3): Timeout when importing the external video stream.
+ * INJECT_STREAM_STATUS_START_FAILED(4): The external video stream fails to import.
+ * INJECT_STREAM_STATUS_STOP_SUCCESS(5): The external video stream stops importing successfully.
+ * INJECT_STREAM_STATUS_STOP_NOT_FOUND(6): No external video stream is found.
+ * INJECT_STREAM_STATUS_STOP_UNAUTHORIZED(7): The external video stream stops from being unauthorized.
+ * INJECT_STREAM_STATUS_STOP_TIMEDOUT(8): Timeout when stopping the import of the external video stream.
+ * INJECT_STREAM_STATUS_STOP_FAILED(9): Fails to stop importing the external video stream.
+ * INJECT_STREAM_STATUS_BROKEN(10): The external video stream import is interrupted.*/
+ @Override
+ public void onStreamInjectedStatus(String url, int uid, int status)
+ {
+ super.onStreamInjectedStatus(url, uid, status);
+ Log.i(TAG, "onStreamInjectedStatus->" + url + ", uid->" + uid + ", status->" + status);
+ if(status == Constants.INJECT_STREAM_STATUS_START_SUCCESS)
+ {
+ /**After confirming the successful push, make changes to the UI.*/
+ injecting = true;
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ inject.setEnabled(true);
+ inject.setText(getString(R.string.stopinject));
+ }
+ });
+ }
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed)
+ {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+
+ /**Display remote video stream*/
+ SurfaceView surfaceView = null;
+ // Create render view by RtcEngine
+ surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ if(fl_remote.getChildCount() > 0)
+ {
+ fl_remote.removeAllViews();
+ }
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason)
+ {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/RTMPStreaming.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/RTMPStreaming.java
new file mode 100644
index 000000000..7d6b2680d
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/RTMPStreaming.java
@@ -0,0 +1,617 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.CompoundButton;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.Switch;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.component.Constant;
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.live.LiveTranscoding;
+import io.agora.rtc.video.AgoraImage;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+/**
+ * This example demonstrates how to push a stream to an external address.
+ *
+ * Important:
+ * Users who push and pull streams cannot be in one channel,
+ * otherwise unexpected errors will occur.
+ */
+@Example(
+ index = 3,
+ group = ADVANCED,
+ name = R.string.item_rtmpstreaming,
+ actionId = R.id.action_mainFragment_to_RTMPStreaming,
+ tipsId = R.string.rtmpstreaming
+)
+public class RTMPStreaming extends BaseFragment implements View.OnClickListener {
+ private static final String TAG = RTMPStreaming.class.getSimpleName();
+
+ private LinearLayout llTransCode;
+ private Switch transCodeSwitch;
+ private FrameLayout fl_local, fl_remote;
+ private EditText et_url, et_channel;
+ private Button join, publish;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false, publishing = false;
+ private VideoEncoderConfiguration.VideoDimensions dimensions = VD_640x360;
+ private LiveTranscoding transcoding;
+ /**
+ * Maximum number of users participating in transcoding (even number)
+ */
+ private final int MAXUserCount = 2;
+ private LiveTranscoding.TranscodingUser localTranscodingUser;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_rtmp_streaming, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ llTransCode = view.findViewById(R.id.ll_TransCode);
+ transCodeSwitch = view.findViewById(R.id.transCode_Switch);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ et_channel = view.findViewById(R.id.et_channel);
+ et_url = view.findViewById(R.id.et_url);
+ join = view.findViewById(R.id.btn_join);
+ join.setOnClickListener(this);
+ publish = view.findViewById(R.id.btn_publish);
+ publish.setOnClickListener(this);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ try {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if (engine != null) {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v) {
+
+ if (v.getId() == R.id.btn_join) {
+ if (!joined) {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA)) {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ } else {
+ engine.leaveChannel();
+ transCodeSwitch.setEnabled(true);
+ joined = false;
+ join.setText(getString(R.string.join));
+ publishing = false;
+ publish.setEnabled(false);
+ publish.setText(getString(R.string.publish));
+ }
+ } else if (v.getId() == R.id.btn_publish) {
+ /**Ensure that the user joins a channel before calling this method.*/
+ if (joined && !publishing) {
+ startPublish();
+ } else if (joined && publishing) {
+ stopPublish();
+ }
+ }
+ }
+
+ private void joinChannel(String channelId) {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the local container
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+ // Set audio route to speaker
+ engine.setDefaultAudioRoutetoSpeakerphone(true);
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ dimensions,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+ /**Set up to play remote sound with receiver*/
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+ engine.setEnableSpeakerphone(false);
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>")) {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0) {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ private void startPublish() {
+ if (transCodeSwitch.isChecked()) {
+ /**LiveTranscoding: A class for managing user-specific CDN live audio/video transcoding settings.
+ * See */
+ transcoding = new LiveTranscoding();
+ transcoding.width = dimensions.height;
+ transcoding.height = dimensions.width;
+ /**The transcodingUser class which defines the video properties of the user displaying the
+ * video in the CDN live. Agora supports a maximum of 17 transcoding users in a CDN live streaming channel.
+ * See */
+ localTranscodingUser = new LiveTranscoding.TranscodingUser();
+ localTranscodingUser.x = 0;
+ localTranscodingUser.y = 0;
+ localTranscodingUser.width = transcoding.width;
+ localTranscodingUser.height = transcoding.height / MAXUserCount;
+ localTranscodingUser.uid = myUid;
+ /**Adds a user displaying the video in CDN live.
+ * @return
+ * 0: Success.
+ * <0: Failure.*/
+ int ret = transcoding.addUser(localTranscodingUser);
+ /**Sets the video layout and audio settings for CDN live.
+ * The SDK triggers the onTranscodingUpdated callback when you call this method to update
+ * the LiveTranscodingclass. If you call this method to set the LiveTranscoding class for
+ * the first time, the SDK does not trigger the onTranscodingUpdated callback.
+ * @param transcoding Sets the CDN live audio/video transcoding settings See
+ *
+ * @return
+ * 0: Success.
+ * <0: Failure.
+ * PS:
+ * This method applies to Live Broadcast only.
+ * Ensure that you enable the RTMP Converter service before using this function. See
+ * Prerequisites in Push Streams to CDN.
+ * Ensure that you call the setClientRole method and set the user role as the host.
+ * Ensure that you call the setLiveTranscoding method before calling the addPublishStreamUrl method.*/
+ engine.setLiveTranscoding(transcoding);
+ }
+ /**Publishes the local stream to the CDN.
+ * The addPublishStreamUrl method call triggers the onRtmpStreamingStateChanged callback on
+ * the local client to report the state of adding a local stream to the CDN.
+ * @param url The CDN streaming URL in the RTMP format. The maximum length of this parameter
+ * is 1024 bytes. The URL address must not contain special characters, such as
+ * Chinese language characters.
+ * @param transcodingEnabled Sets whether transcoding is enabled/disabled. If you set this
+ * parameter as true, ensure that you call the setLiveTranscoding
+ * method before this method.
+ * true: Enable transcoding. To transcode the audio or video
+ * streams when publishing them to CDN live, often used for
+ * combining the audio and video streams of multiple hosts in CDN live.
+ * false: Disable transcoding.
+ * @return
+ * 0: Success.
+ * < 0: Failure.
+ * ERR_INVALID_ARGUMENT(2): Invalid parameter, usually because the URL address is null or the string length is 0.
+ * ERR_NOT_INITIALIZED(7): You have not initialized RtcEngine when publishing the stream.
+ * PS:
+ * Ensure that you enable the RTMP Converter service before using this function. See
+ * Prerequisites in Push Streams to CDN.
+ * This method applies to Live Broadcast only.
+ * Ensure that the user joins a channel before calling this method.
+ * This method adds only one stream HTTP/HTTPS URL address each time it is called.*/
+ int code = engine.addPublishStreamUrl(et_url.getText().toString(), transCodeSwitch.isChecked());
+ /**Prevent repeated entry*/
+ publish.setEnabled(false);
+ /**Prevent duplicate clicks*/
+ transCodeSwitch.setEnabled(false);
+ }
+
+ private void stopPublish() {
+ /**Removes an RTMP stream from the CDN.
+ * This method removes the RTMP URL address (added by addPublishStreamUrl) from a CDN live
+ * stream. The SDK reports the result of this method call in the onRtmpStreamingStateChanged callback.
+ * @param url The RTMP URL address to be removed. The maximum length of this parameter is
+ * 1024 bytes. The URL address must not contain special characters, such as
+ * Chinese language characters.
+ * @return
+ * 0: Success.
+ * <0: Failure.
+ * PS:
+ * Ensure that you enable the RTMP Converter service before using this function. See
+ * Prerequisites in Push Streams to CDN.
+ * Ensure that the user joins a channel before calling this method.
+ * This method applies to Live Broadcast only.
+ * This method removes only one stream RTMP URL address each time it is called.*/
+ int ret = engine.removePublishStreamUrl(et_url.getText().toString());
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler() {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn) {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err) {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats) {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ publish.setEnabled(true);
+ publish.setText(getString(R.string.publish));
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed) {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed) {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Since v2.4.1
+ * Occurs when the state of the RTMP streaming changes.
+ * This callback indicates the state of the RTMP streaming. When exceptions occur, you can
+ * troubleshoot issues by referring to the detailed error descriptions in the errCode parameter.
+ * @param url The RTMP URL address.
+ * @param state The RTMP streaming state:
+ * RTMP_STREAM_PUBLISH_STATE_IDLE(0): The RTMP streaming has not started or has ended.
+ * This state is also triggered after you remove an RTMP address from the CDN
+ * by calling removePublishStreamUrl.
+ * RTMP_STREAM_PUBLISH_STATE_CONNECTING(1): The SDK is connecting to Agora streaming server
+ * and the RTMP server. This state is triggered after you call the addPublishStreamUrl method.
+ * RTMP_STREAM_PUBLISH_STATE_RUNNING(2): The RTMP streaming publishes. The SDK successfully
+ * publishes the RTMP streaming and returns this state.
+ * RTMP_STREAM_PUBLISH_STATE_RECOVERING(3): The RTMP streaming is recovering. When exceptions
+ * occur to the CDN, or the streaming is interrupted, the SDK attempts to resume
+ * RTMP streaming and returns this state.
+ * 1:If the SDK successfully resumes the streaming, RTMP_STREAM_PUBLISH_STATE_RUNNING(2)
+ * returns.
+ * 2:If the streaming does not resume within 60 seconds or server errors occur,
+ * RTMP_STREAM_PUBLISH_STATE_FAILURE(4) returns. You can also reconnect to the
+ * server by calling the removePublishStreamUrl and addPublishStreamUrl methods.
+ * RTMP_STREAM_PUBLISH_STATE_FAILURE(4): The RTMP streaming fails. See the errCode parameter
+ * for the detailed error information. You can also call the addPublishStreamUrl
+ * method to publish the RTMP streaming again.
+ * @param errCode The detailed error information for streaming:
+ * RTMP_STREAM_PUBLISH_ERROR_OK(0): The RTMP streaming publishes successfully.
+ * RTMP_STREAM_PUBLISH_ERROR_INVALID_ARGUMEN(1): Invalid argument used. If, for example,
+ * you do not call the setLiveTranscoding method to configure the LiveTranscoding
+ * parameters before calling the addPublishStreamUrl method, the SDK returns
+ * this error. Check whether you set the parameters in the setLiveTranscoding method properly.
+ * RTMP_STREAM_PUBLISH_ERROR_ENCRYPTED_STREAM_NOT_ALLOWED(2): The RTMP streaming is
+ * encrypted and cannot be published.
+ * RTMP_STREAM_PUBLISH_ERROR_CONNECTION_TIMEOUT(3): Timeout for the RTMP streaming. Call
+ * the addPublishStreamUrl method to publish the streaming again.
+ * RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR(4): An error occurs in Agora streaming
+ * server. Call the addPublishStreamUrl method to publish the streaming again.
+ * RTMP_STREAM_PUBLISH_ERROR_RTMP_SERVER_ERROR(5): An error occurs in the RTMP server.
+ * RTMP_STREAM_PUBLISH_ERROR_TOO_OFTEN(6): The RTMP streaming publishes too frequently.
+ * RTMP_STREAM_PUBLISH_ERROR_REACH_LIMIT(7): The host publishes more than 10 URLs. Delete
+ * the unnecessary URLs before adding new ones.
+ * RTMP_STREAM_PUBLISH_ERROR_NOT_AUTHORIZED(8): The host manipulates other hosts' URLs.
+ * Check your app logic.
+ * RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND(9): Agora server fails to find the RTMP
+ * streaming.
+ * RTMP_STREAM_PUBLISH_ERROR_FORMAT_NOT_SUPPORTED(10): The format of the RTMP streaming
+ * URL is not supported. Check whether the URL format is correct.*/
+ @Override
+ public void onRtmpStreamingStateChanged(String url, int state, int errCode) {
+ super.onRtmpStreamingStateChanged(url, state, errCode);
+ Log.i(TAG, "onRtmpStreamingStateChanged->" + url + ", state->" + state + ", errCode->" + errCode);
+ if (state == Constants.RTMP_STREAM_PUBLISH_STATE_RUNNING) {
+ /**After confirming the successful push, make changes to the UI.*/
+ publishing = true;
+ handler.post(() -> {
+ publish.setEnabled(true);
+ publish.setText(getString(R.string.stoppublish));
+ });
+ } else if (state == Constants.RTMP_STREAM_PUBLISH_STATE_FAILURE) {
+ /**if failed, make changes to the UI.*/
+ publishing = true;
+ handler.post(() -> {
+ publish.setEnabled(true);
+ publish.setText(getString(R.string.publish));
+ transCodeSwitch.setEnabled(true);
+ publishing = false;
+ });
+ } else if (state == Constants.RTMP_STREAM_PUBLISH_STATE_IDLE) {
+ /**Push stream not started or ended, make changes to the UI.*/
+ publishing = true;
+ handler.post(() -> {
+ publish.setEnabled(true);
+ publish.setText(getString(R.string.publish));
+ transCodeSwitch.setEnabled(true);
+ publishing = false;
+ });
+ }
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed) {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ if (fl_remote.getChildCount() > 0) {
+ fl_remote.removeAllViews();
+ }
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ /**Determine whether to open transcoding service and whether the current number of
+ * transcoding users exceeds the maximum number of users*/
+ if (transCodeSwitch.isChecked() && transcoding.getUserCount() < MAXUserCount) {
+ /**The transcoding images are arranged vertically according to the adding order*/
+ LiveTranscoding.TranscodingUser transcodingUser = new LiveTranscoding.TranscodingUser();
+ transcodingUser.x = 0;
+ transcodingUser.y = localTranscodingUser.height;
+ transcodingUser.width = transcoding.width;
+ transcodingUser.height = transcoding.height / MAXUserCount;
+ transcodingUser.uid = uid;
+ int ret = transcoding.addUser(transcodingUser);
+ /**refresh transCoding configuration*/
+ engine.setLiveTranscoding(transcoding);
+ }
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason) {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ if(transcoding != null) {
+ /**Removes a user from CDN live.
+ * @return
+ * 0: Success.
+ * < 0: Failure.*/
+ int code = transcoding.removeUser(uid);
+ if (code == Constants.ERR_OK) {
+ /**refresh transCoding configuration*/
+ engine.setLiveTranscoding(transcoding);
+ }
+ }
+ }
+ });
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SetAudioProfile.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SetAudioProfile.java
new file mode 100644
index 000000000..4850f0673
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SetAudioProfile.java
@@ -0,0 +1,366 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Spinner;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.examples.basic.JoinChannelAudio;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+
+@Example(
+ index = 13,
+ group = ADVANCED,
+ name = R.string.item_setaudioprofile,
+ actionId = R.id.action_mainFragment_to_SetAudioProfile,
+ tipsId = R.string.setaudioprofile
+)
+public class SetAudioProfile extends BaseFragment implements View.OnClickListener{
+ private static final String TAG = JoinChannelAudio.class.getSimpleName();
+ private Spinner audioProfileInput;
+ private Spinner audioScenarioInput;
+ private EditText et_channel;
+ private Button mute, join, speaker;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false;
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ handler = new Handler();
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_set_audio_profile, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ audioProfileInput = view.findViewById(R.id.audio_profile_spinner);
+ audioScenarioInput = view.findViewById(R.id.audio_scenario_spinner);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ mute = view.findViewById(R.id.btn_mute);
+ mute.setOnClickListener(this);
+ speaker = view.findViewById(R.id.btn_speaker);
+ speaker.setOnClickListener(this);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ String appId = getString(R.string.agora_app_id);
+ engine = RtcEngine.create(getContext().getApplicationContext(), appId, iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if(engine != null)
+ {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+ if (v.getId() == R.id.btn_join)
+ {
+ if (!joined)
+ {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelId);
+ audioProfileInput.setEnabled(false);
+ audioScenarioInput.setEnabled(false);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ audioProfileInput.setEnabled(false);
+ audioScenarioInput.setEnabled(false);
+ }).start();
+ }
+ else
+ {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ speaker.setText(getString(R.string.speaker));
+ speaker.setEnabled(false);
+ mute.setText(getString(R.string.closemicrophone));
+ mute.setEnabled(false);
+ audioProfileInput.setEnabled(true);
+ audioScenarioInput.setEnabled(true);
+ }
+ }
+ else if (v.getId() == R.id.btn_mute)
+ {
+ mute.setActivated(!mute.isActivated());
+ mute.setText(getString(mute.isActivated() ? R.string.openmicrophone : R.string.closemicrophone));
+ /**Turn off / on the microphone, stop / start local audio collection and push streaming.*/
+ engine.muteLocalAudioStream(mute.isActivated());
+ }
+ else if (v.getId() == R.id.btn_speaker)
+ {
+ speaker.setActivated(!speaker.isActivated());
+ speaker.setText(getString(speaker.isActivated() ? R.string.earpiece : R.string.speaker));
+ /**Turn off / on the speaker and change the audio playback route.*/
+ engine.setEnableSpeakerphone(speaker.isActivated());
+ }
+ }
+
+ /**
+ * @param channelId Specify the channel name that you want to join.
+ * Users that input the same channel name join the same channel.*/
+ private void joinChannel(String channelId)
+ {
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ int profile = Constants.AudioProfile.valueOf(audioProfileInput.getSelectedItem().toString()).ordinal();
+ int scenario = Constants.AudioScenario.valueOf(audioScenarioInput.getSelectedItem().toString()).ordinal();
+ engine.setAudioProfile(profile, scenario);
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ Log.e(TAG, RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ /**IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats)
+ {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ speaker.setEnabled(true);
+ mute.setEnabled(true);
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed)
+ {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason)
+ {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SetVideoProfile.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SetVideoProfile.java
new file mode 100644
index 000000000..fce590fbc
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SetVideoProfile.java
@@ -0,0 +1,467 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+import android.widget.Spinner;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import java.lang.reflect.Field;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+/**This demo demonstrates how to make a one-to-one video call*/
+@Example(
+ index = 21,
+ group = ADVANCED,
+ name = R.string.item_setvideoprofile,
+ actionId = R.id.action_mainFragment_to_set_video_profile,
+ tipsId = R.string.setvideoprofile
+)
+public class SetVideoProfile extends BaseFragment implements View.OnClickListener
+{
+ private static final String TAG = SetVideoProfile.class.getSimpleName();
+
+ private FrameLayout fl_local, fl_remote;
+ private Button join;
+ private EditText et_channel, et_bitrate;
+ private RtcEngine engine;
+ private Spinner dimension, framerate, orientation;
+ private int myUid;
+ private boolean joined = false;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_set_video_profile, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ et_bitrate = view.findViewById(R.id.et_bitrate);
+ dimension = view.findViewById(R.id.dimension_spinner);
+ framerate = view.findViewById(R.id.frame_rate_spinner);
+ orientation = view.findViewById(R.id.orientation_spinner);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if(engine != null)
+ {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+ if (v.getId() == R.id.btn_join)
+ {
+ if (!joined)
+ {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ }
+ else
+ {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ et_bitrate.setEnabled(true);
+ dimension.setEnabled(true);
+ framerate.setEnabled(true);
+ orientation.setEnabled(true);
+ }
+ }
+ }
+
+ private void joinChannel(String channelId)
+ {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+ surfaceView.setZOrderMediaOverlay(true);
+ if(fl_local.getChildCount() > 0)
+ {
+ fl_local.removeAllViews();
+ }
+ // Add to the local container
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+ // Set audio route to microPhone
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+
+ VideoEncoderConfiguration.VideoDimensions value = VD_640x360;
+ try {
+ Field tmp = VideoEncoderConfiguration.class.getDeclaredField(dimension.getSelectedItem().toString());
+ tmp.setAccessible(true);
+ value = (VideoEncoderConfiguration.VideoDimensions) tmp.get(null);
+ } catch (NoSuchFieldException e) {
+ Log.e("Field", "Can not find field " + dimension.getSelectedItem().toString());
+ } catch (IllegalAccessException e) {
+ Log.e("Field", "Could not access field " + dimension.getSelectedItem().toString());
+ }
+
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ value,
+ VideoEncoderConfiguration.FRAME_RATE.valueOf(framerate.getSelectedItem().toString()),
+ Integer.valueOf(et_bitrate.getText().toString()),
+ VideoEncoderConfiguration.ORIENTATION_MODE.valueOf(orientation.getSelectedItem().toString())
+ ));
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats)
+ {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ et_bitrate.setEnabled(false);
+ framerate.setEnabled(false);
+ orientation.setEnabled(false);
+ dimension.setEnabled(false);
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed)
+ {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ SurfaceView surfaceView = null;
+ if (fl_remote.getChildCount() > 0)
+ {
+ fl_remote.removeAllViews();
+ }
+ // Create render view by RtcEngine
+ surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason)
+ {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/StreamEncrypt.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/StreamEncrypt.java
new file mode 100644
index 000000000..a72b69ab1
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/StreamEncrypt.java
@@ -0,0 +1,359 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.api.streamencrypt.PacketProcessor;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+/**This example demonstrates how to use a custom encryption scheme to encrypt audio and video streams.*/
+@Example(
+ index = 12,
+ group = ADVANCED,
+ name = R.string.item_streamencrypt,
+ actionId = R.id.action_mainFragment_to_StreamEncrypt,
+ tipsId = R.string.streamencrypt
+)
+public class StreamEncrypt extends BaseFragment implements View.OnClickListener
+{
+ private static final String TAG = StreamEncrypt.class.getSimpleName();
+
+ private FrameLayout fl_local, fl_remote;
+ private Button join;
+ private EditText et_channel;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false;
+ private PacketProcessor packetProcessor = new PacketProcessor();
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_stream_encrypt, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ /**register AgoraPacketObserver for encrypt/decrypt stream*/
+ packetProcessor.registerProcessing();
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if(engine != null)
+ {
+ engine.leaveChannel();
+ }
+ /**unregister AgoraPacketObserver*/
+ packetProcessor.unregisterProcessing();
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+ if (v.getId() == R.id.btn_join)
+ {
+ if (!joined)
+ {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ }
+ else
+ {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ }
+ }
+ }
+
+ private void joinChannel(String channelId)
+ {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the local container
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+ /**Set up to play remote sound with receiver*/
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+ engine.setEnableSpeakerphone(false);
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ VD_640x360,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+ /**Set up to play remote sound with receiver*/
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+ engine.setEnableSpeakerphone(false);
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats)
+ {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ }
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed)
+ {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ if (fl_remote.getChildCount() > 0)
+ {
+ fl_remote.removeAllViews();
+ }
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason)
+ {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SwitchCameraScreenShare.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SwitchCameraScreenShare.java
new file mode 100644
index 000000000..10f4f4c5f
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SwitchCameraScreenShare.java
@@ -0,0 +1,541 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.media.projection.MediaProjectionManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.text.TextUtils;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.TextureView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+import android.widget.RelativeLayout;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.advancedvideo.externvideosource.ExternalVideoInputManager;
+import io.agora.advancedvideo.externvideosource.ExternalVideoInputService;
+import io.agora.advancedvideo.externvideosource.IExternalVideoInputService;
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.mediaio.AgoraDefaultSource;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static android.app.Activity.RESULT_OK;
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.Constants.REMOTE_VIDEO_STATE_STARTING;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_FIT;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.api.component.Constant.ENGINE;
+import static io.agora.api.component.Constant.TEXTUREVIEW;
+
+/**
+ * This example demonstrates how video can be flexibly switched between the camera stream and the
+ * screen share stream during an audio-video call.
+ */
+@Example(
+ index = 7,
+ group = ADVANCED,
+ name = R.string.item_cameraorscreen,
+ actionId = R.id.action_mainFragment_to_SwitchCameraScreenShare,
+ tipsId = R.string.switchcamerascreen
+)
+public class SwitchCameraScreenShare extends BaseFragment implements View.OnClickListener {
+ private static final String TAG = SwitchCameraScreenShare.class.getSimpleName();
+
+ private FrameLayout fl_remote;
+ private RelativeLayout fl_local;
+ private Button join, renderMode, camera, screenShare;
+ private EditText et_channel;
+ private int myUid, remoteUid = -1;
+ private boolean joined = false;
+ private static final int PROJECTION_REQ_CODE = 1 << 2;
+ private static final int DEFAULT_SHARE_FRAME_RATE = 15;
+ private IExternalVideoInputService mService;
+ private VideoInputServiceConnection mServiceConnection;
+ private int curRenderMode = RENDER_MODE_HIDDEN;
+ private VideoEncoderConfiguration.ORIENTATION_MODE curMirrorMode =
+ VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_switch_camera_screenshare, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ renderMode = view.findViewById(R.id.renderMode);
+ camera = view.findViewById(R.id.camera);
+ screenShare = view.findViewById(R.id.screenShare);
+ et_channel = view.findViewById(R.id.et_channel);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ fl_local = view.findViewById(R.id.fl_local);
+ join.setOnClickListener(this);
+ renderMode.setOnClickListener(this);
+ camera.setOnClickListener(this);
+ screenShare.setOnClickListener(this);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ try {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ ENGINE = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == PROJECTION_REQ_CODE && resultCode == RESULT_OK) {
+ camera.setEnabled(true);
+ screenShare.setEnabled(false);
+ try {
+ DisplayMetrics metrics = new DisplayMetrics();
+ getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
+
+ float percent = 0.f;
+ float hp = ((float) metrics.heightPixels) - 1920.f;
+ float wp = ((float) metrics.widthPixels) - 1080.f;
+
+ if (hp < wp) {
+ percent = (((float) metrics.widthPixels) - 1080.f) / ((float) metrics.widthPixels);
+ } else {
+ percent = (((float) metrics.heightPixels) - 1920.f) / ((float) metrics.heightPixels);
+ }
+ metrics.heightPixels = (int) (((float) metrics.heightPixels) - (metrics.heightPixels * percent));
+ metrics.widthPixels = (int) (((float) metrics.widthPixels) - (metrics.widthPixels * percent));
+
+ data.putExtra(ExternalVideoInputManager.FLAG_SCREEN_WIDTH, metrics.widthPixels);
+ data.putExtra(ExternalVideoInputManager.FLAG_SCREEN_HEIGHT, metrics.heightPixels);
+ data.putExtra(ExternalVideoInputManager.FLAG_SCREEN_DPI, (int) metrics.density);
+ data.putExtra(ExternalVideoInputManager.FLAG_FRAME_RATE, DEFAULT_SHARE_FRAME_RATE);
+ setVideoConfig(ExternalVideoInputManager.TYPE_SCREEN_SHARE, metrics.widthPixels, metrics.heightPixels);
+ mService.setExternalVideoInput(ExternalVideoInputManager.TYPE_SCREEN_SHARE, data);
+ }
+ catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ unbindVideoService();
+ TEXTUREVIEW = null;
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if (ENGINE != null) {
+ ENGINE.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ ENGINE = null;
+ super.onDestroy();
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.btn_join) {
+ if (!joined) {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ /**Instantiate the view ready to display the local preview screen*/
+ TEXTUREVIEW = new TextureView(getContext());
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA)) {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ } else {
+ joined = false;
+ join.setText(getString(R.string.join));
+ camera.setEnabled(false);
+ screenShare.setEnabled(false);
+ fl_remote.removeAllViews();
+ fl_local.removeAllViews();
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ ENGINE.leaveChannel();
+ TEXTUREVIEW = null;
+ unbindVideoService();
+ }
+ } else if (v.getId() == R.id.renderMode) {
+ if (remoteUid == -1) {
+ return;
+ }
+ if (curRenderMode == RENDER_MODE_HIDDEN) {
+ curRenderMode = RENDER_MODE_FIT;
+ renderMode.setText(String.format(getString(R.string.rendermode), getString(R.string.fit)));
+ } else if (curRenderMode == RENDER_MODE_FIT) {
+ curRenderMode = RENDER_MODE_HIDDEN;
+ renderMode.setText(String.format(getString(R.string.rendermode), getString(R.string.hidden)));
+ }
+// setRemotePreview(getContext());
+// ENGINE.setRemoteRenderMode(remoteUid, curRenderMode, curMirrorMode.getValue());
+ } else if (v.getId() == R.id.camera) {
+ unbindVideoService();
+ handler.postDelayed(() -> {
+ /**setVideoSource must be called in {@link ExternalVideoInputManager.ExternalVideoInputThread#release()}
+ * after calling. Here the handler delay is used to guarantee this process.
+ * Developers can flexibly call them according to their own business logic*/
+ ENGINE.setVideoSource(new AgoraDefaultSource());
+ addLocalPreview();
+ camera.setEnabled(false);
+ screenShare.setEnabled(true);
+ }, 1000);
+ } else if (v.getId() == R.id.screenShare) {
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
+ /**remove local preview*/
+ fl_local.removeAllViews();
+ /**start input service*/
+ bindVideoService();
+ } else {
+ showAlert(getString(R.string.lowversiontip));
+ }
+ }
+ }
+
+ private void setVideoConfig(int sourceType, int width, int height) {
+ switch (sourceType) {
+ case ExternalVideoInputManager.TYPE_LOCAL_VIDEO:
+ case ExternalVideoInputManager.TYPE_SCREEN_SHARE:
+ curMirrorMode = VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_FIXED_PORTRAIT;
+ break;
+ default:
+ curMirrorMode = VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+ break;
+ }
+
+ Log.e(TAG, "SDK设置的编码宽高->width:" + width + ",height:" + height);
+ /**Setup video stream encoding configs*/
+ ENGINE.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ new VideoEncoderConfiguration.VideoDimensions(width, height),
+ VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15,
+ VideoEncoderConfiguration.STANDARD_BITRATE, curMirrorMode
+ ));
+
+// ENGINE.setParameters("{\"rtc.log_filter\": 65535}");
+ }
+
+ private void addLocalPreview() {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+// surfaceView.setZOrderMediaOverlay(true);
+ if (fl_local.getChildCount() > 0) {
+ fl_local.removeAllViews();
+ }
+ // Add to the local container
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ ENGINE.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+ }
+
+ private void setRemotePreview(Context context) {
+ /**Display remote video stream*/
+ SurfaceView remoteSurfaceView = RtcEngine.CreateRendererView(context);
+ remoteSurfaceView.setZOrderMediaOverlay(true);
+ if (fl_remote.getChildCount() > 0) {
+ fl_remote.removeAllViews();
+ }
+ fl_remote.addView(remoteSurfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+ /**Setup remote video to render*/
+ ENGINE.setupRemoteVideo(new VideoCanvas(remoteSurfaceView, curRenderMode, remoteUid));
+ }
+
+ private void joinChannel(String channelId) {
+ addLocalPreview();
+
+ ENGINE.setParameters("{\"che.video.mobile_1080p\":true}");
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ ENGINE.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**Sets the role of a user (Live Broadcast only).*/
+ ENGINE.setClientRole(Constants.CLIENT_ROLE_BROADCASTER);
+ /**Enable video module*/
+ ENGINE.enableVideo();
+ ENGINE.setVideoSource(new AgoraDefaultSource());
+ /**Set up to play remote sound with receiver*/
+ ENGINE.setDefaultAudioRoutetoSpeakerphone(false);
+ ENGINE.setEnableSpeakerphone(false);
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>")) {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = ENGINE.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0) {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ private void bindVideoService() {
+ Intent intent = new Intent();
+ intent.setClass(getContext(), ExternalVideoInputService.class);
+ mServiceConnection = new VideoInputServiceConnection();
+ getContext().bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
+ }
+
+ private void unbindVideoService() {
+ if (mServiceConnection != null) {
+ getContext().unbindService(mServiceConnection);
+ mServiceConnection = null;
+ }
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler() {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn) {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err) {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(() -> {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ camera.setEnabled(false);
+ screenShare.setEnabled(true);
+ });
+ }
+
+ @Override
+ public void onLocalVideoStateChanged(int localVideoState, int error) {
+ super.onLocalVideoStateChanged(localVideoState, error);
+ if (localVideoState == 1) {
+ Log.e(TAG, "启动成功");
+ }
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed) {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged:uid->" + uid + ", state->" + state);
+ if (state == REMOTE_VIDEO_STATE_STARTING) {
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ remoteUid = uid;
+ renderMode.setEnabled(true);
+ renderMode.setText(String.format(getString(R.string.rendermode), getString(R.string.hidden)));
+ curRenderMode = RENDER_MODE_HIDDEN;
+ setRemotePreview(context);
+ });
+ }
+ }
+
+ @Override
+ public void onRemoteVideoStats(RemoteVideoStats stats) {
+ super.onRemoteVideoStats(stats);
+ Log.d(TAG, "onRemoteVideoStats: width:" + stats.width + " x height:" + stats.height);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed) {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason) {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(() -> {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ ENGINE.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ fl_remote.removeAllViews();
+ });
+ }
+ };
+
+ private class VideoInputServiceConnection implements ServiceConnection {
+ @Override
+ public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
+ mService = (IExternalVideoInputService) iBinder;
+ /**Start the screen recording service of the system*/
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
+ MediaProjectionManager mpm = (MediaProjectionManager)
+ getContext().getSystemService(Context.MEDIA_PROJECTION_SERVICE);
+ Intent intent = mpm.createScreenCaptureIntent();
+ startActivityForResult(intent, PROJECTION_REQ_CODE);
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName componentName) {
+ mService = null;
+ }
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SwitchExternalVideo.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SwitchExternalVideo.java
new file mode 100644
index 000000000..99864eca7
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SwitchExternalVideo.java
@@ -0,0 +1,495 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.media.projection.MediaProjectionManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.text.TextUtils;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.Surface;
+import android.view.SurfaceView;
+import android.view.TextureView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+import android.widget.RelativeLayout;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import java.io.File;
+
+import io.agora.advancedvideo.externvideosource.ExternalVideoInputManager;
+import io.agora.advancedvideo.externvideosource.ExternalVideoInputService;
+import io.agora.advancedvideo.externvideosource.IExternalVideoInputService;
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static android.app.Activity.RESULT_OK;
+import static io.agora.api.component.Constant.ENGINE;
+import static io.agora.api.component.Constant.TEXTUREVIEW;
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.Constants.REMOTE_VIDEO_STATE_STARTING;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+
+/**
+ * This example demonstrates how to switch the external video source. The implementation method is
+ * similar to PushExternalVideo, all by rendering the external video to a TextureId
+ * (the specific form is Surface{@link io.agora.advancedvideo.externvideosource.IExternalVideoInput#onVideoInitialized(Surface)}),
+ * and then calling consumeTextureFrame in a loop to push the stream.
+ */
+@Example(
+ index = 6,
+ group = ADVANCED,
+ name = R.string.item_switchexternal,
+ actionId = R.id.action_mainFragment_to_SwitchExternalVideo,
+ tipsId = R.string.switchexternalvideo
+)
+public class SwitchExternalVideo extends BaseFragment implements View.OnClickListener {
+ private static final String TAG = SwitchExternalVideo.class.getSimpleName();
+
+ private FrameLayout fl_remote;
+ private RelativeLayout fl_local;
+ private Button join, localVideo, screenShare;
+ private EditText et_channel;
+ private int myUid;
+ private boolean joined = false;
+ private static final String VIDEO_NAME = "localvideo.mp4";
+ private static final int PROJECTION_REQ_CODE = 1 << 2;
+ private static final int DEFAULT_SHARE_FRAME_RATE = 15;
+ /**
+ * The developers should defines their video dimension, for the
+ * video info cannot be obtained before the video is extracted.
+ */
+ private static final int LOCAL_VIDEO_WIDTH = 1280;
+ private static final int LOCAL_VIDEO_HEIGHT = 720;
+ private String mLocalVideoPath;
+ private boolean mLocalVideoExists = false;
+ private IExternalVideoInputService mService;
+ private VideoInputServiceConnection mServiceConnection;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_switch_external_video, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ localVideo = view.findViewById(R.id.localVideo);
+ screenShare = view.findViewById(R.id.screenShare);
+ et_channel = view.findViewById(R.id.et_channel);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ fl_local = view.findViewById(R.id.fl_local);
+ join.setOnClickListener(this);
+ localVideo.setOnClickListener(this);
+ screenShare.setOnClickListener(this);
+ checkLocalVideo();
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ try {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ ENGINE = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == PROJECTION_REQ_CODE && resultCode == RESULT_OK) {
+ try {
+ DisplayMetrics metrics = new DisplayMetrics();
+ getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
+ data.putExtra(ExternalVideoInputManager.FLAG_SCREEN_WIDTH, metrics.widthPixels);
+ data.putExtra(ExternalVideoInputManager.FLAG_SCREEN_HEIGHT, metrics.heightPixels);
+ data.putExtra(ExternalVideoInputManager.FLAG_SCREEN_DPI, (int) metrics.density);
+ data.putExtra(ExternalVideoInputManager.FLAG_FRAME_RATE, DEFAULT_SHARE_FRAME_RATE);
+
+ setVideoConfig(ExternalVideoInputManager.TYPE_SCREEN_SHARE, metrics.widthPixels, metrics.heightPixels);
+ mService.setExternalVideoInput(ExternalVideoInputManager.TYPE_SCREEN_SHARE, data);
+ }
+ catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ unbindVideoService();
+ TEXTUREVIEW = null;
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if (ENGINE != null) {
+ ENGINE.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ ENGINE = null;
+ super.onDestroy();
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.btn_join) {
+ if (!joined) {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ /**Instantiate the view ready to display the local preview screen*/
+ TEXTUREVIEW = new TextureView(getContext());
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA)) {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ } else {
+ joined = false;
+ join.setText(getString(R.string.join));
+ localVideo.setEnabled(false);
+ screenShare.setEnabled(false);
+ fl_remote.removeAllViews();
+ fl_local.removeAllViews();
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ ENGINE.leaveChannel();
+ TEXTUREVIEW = null;
+ unbindVideoService();
+ }
+ } else if (v.getId() == R.id.localVideo) {
+ try {
+ Intent intent = new Intent();
+ setVideoConfig(ExternalVideoInputManager.TYPE_LOCAL_VIDEO, LOCAL_VIDEO_WIDTH, LOCAL_VIDEO_HEIGHT);
+ intent.putExtra(ExternalVideoInputManager.FLAG_VIDEO_PATH, mLocalVideoPath);
+ if (mService.setExternalVideoInput(ExternalVideoInputManager.TYPE_LOCAL_VIDEO, intent)) {
+ fl_local.removeAllViews();
+ fl_local.addView(TEXTUREVIEW,
+ RelativeLayout.LayoutParams.MATCH_PARENT,
+ RelativeLayout.LayoutParams.MATCH_PARENT);
+ }
+ }
+ catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ } else if (v.getId() == R.id.screenShare) {
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
+ /**remove local preview*/
+ fl_local.removeAllViews();
+ /***/
+ MediaProjectionManager mpm = (MediaProjectionManager)
+ getContext().getSystemService(Context.MEDIA_PROJECTION_SERVICE);
+ Intent intent = mpm.createScreenCaptureIntent();
+ startActivityForResult(intent, PROJECTION_REQ_CODE);
+ } else {
+ showAlert(getString(R.string.lowversiontip));
+ }
+ }
+ }
+
+ private boolean checkLocalVideo() {
+ File dir = getContext().getExternalFilesDir(Environment.DIRECTORY_MOVIES);
+ File videoFile = new File(dir, VIDEO_NAME);
+ mLocalVideoPath = videoFile.getAbsolutePath();
+ mLocalVideoExists = videoFile.exists();
+ if (!mLocalVideoExists) {
+ showAlert(String.format(getString(R.string.alert_no_local_video_message), mLocalVideoPath));
+ }
+ return mLocalVideoExists;
+ }
+
+ private void setVideoConfig(int sourceType, int width, int height) {
+ VideoEncoderConfiguration.ORIENTATION_MODE mode;
+ switch (sourceType) {
+ case ExternalVideoInputManager.TYPE_LOCAL_VIDEO:
+ case ExternalVideoInputManager.TYPE_SCREEN_SHARE:
+ mode = VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_FIXED_PORTRAIT;
+ break;
+ default:
+ mode = VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+ break;
+ }
+ /**Setup video stream encoding configs*/
+ ENGINE.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ new VideoEncoderConfiguration.VideoDimensions(width, height),
+ VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15,
+ VideoEncoderConfiguration.STANDARD_BITRATE, mode
+ ));
+ }
+
+ private void joinChannel(String channelId) {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ ENGINE.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**Sets the role of a user (Live Broadcast only).*/
+ ENGINE.setClientRole(Constants.CLIENT_ROLE_BROADCASTER);
+ /**Enable video module*/
+ ENGINE.enableVideo();
+ /**Set up to play remote sound with receiver*/
+ ENGINE.setDefaultAudioRoutetoSpeakerphone(false);
+ ENGINE.setEnableSpeakerphone(false);
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>")) {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = ENGINE.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0) {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ private void bindVideoService() {
+ Intent intent = new Intent();
+ intent.setClass(getContext(), ExternalVideoInputService.class);
+ mServiceConnection = new VideoInputServiceConnection();
+ getContext().bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
+ }
+
+ private void unbindVideoService() {
+ if (mServiceConnection != null) {
+ getContext().unbindService(mServiceConnection);
+ mServiceConnection = null;
+ }
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler() {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn) {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err) {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(() -> {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ screenShare.setEnabled(true);
+ localVideo.setEnabled(mLocalVideoExists);
+ bindVideoService();
+ });
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed) {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged:uid->" + uid + ", state->" + state);
+ if (state == REMOTE_VIDEO_STATE_STARTING) {
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ if (fl_remote.getChildCount() > 0) {
+ fl_remote.removeAllViews();
+ }
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+ /**Setup remote video to render*/
+ ENGINE.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ }
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed) {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason) {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ ENGINE.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ fl_remote.removeAllViews();
+ }
+ });
+ }
+ };
+
+ private class VideoInputServiceConnection implements ServiceConnection {
+ @Override
+ public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
+ mService = (IExternalVideoInputService) iBinder;
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName componentName) {
+ mService = null;
+ }
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/VideoMetadata.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/VideoMetadata.java
new file mode 100644
index 000000000..c4e3a1cfd
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/VideoMetadata.java
@@ -0,0 +1,527 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import java.nio.charset.Charset;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IMetadataObserver;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+@Example(
+ index = 11,
+ group = ADVANCED,
+ name = R.string.item_videometadata,
+ actionId = R.id.action_mainFragment_to_VideoMetadata,
+ tipsId = R.string.videometadata
+)
+public class VideoMetadata extends BaseFragment implements View.OnClickListener
+{
+ public static final String TAG = VideoMetadata.class.getSimpleName();
+ private FrameLayout fl_local, fl_remote;
+ private Button send, join;
+ private EditText et_channel;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false;
+ /**
+ * Maximum length of meta data
+ */
+ private int MAX_META_SIZE = 1024;
+ /**
+ * Meta data to be sent
+ */
+ private byte[] metadata;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_video_metadata, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ send = view.findViewById(R.id.btn_send);
+ send.setOnClickListener(this);
+ send.setEnabled(false);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if (engine != null)
+ {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+ if (v.getId() == R.id.btn_join)
+ {
+ if (!joined)
+ {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ }
+ else
+ {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ send.setEnabled(false);
+ join.setText(getString(R.string.join));
+ }
+ }
+ else if (v.getId() == R.id.btn_send)
+ {
+ /**Click once, the metadata is sent once.
+ * {@link VideoMetadata#iMetadataObserver}.
+ * The metadata here can be flexibly replaced according to your own business.*/
+ metadata = String.valueOf(System.currentTimeMillis()).getBytes(Charset.forName("UTF-8"));
+ }
+ }
+
+ private void joinChannel(String channelId)
+ {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the local container
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ VD_640x360,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+ /**Set up to play remote sound with receiver*/
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+ engine.setEnableSpeakerphone(false);
+
+ /**register metadata observer
+ * @return 0:Success
+ * < 0:Failure*/
+ int code = engine.registerMediaMetadataObserver(iMetadataObserver, IMetadataObserver.VIDEO_METADATA);
+ Log.e(TAG, code + "");
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ /**
+ * By implementing this interface, metadata can be sent and received with video frames.
+ */
+ private final IMetadataObserver iMetadataObserver = new IMetadataObserver()
+ {
+ /**Returns the maximum data size of Metadata*/
+ @Override
+ public int getMaxMetadataSize()
+ {
+ return MAX_META_SIZE;
+ }
+
+ /**Occurs when the SDK is ready to receive and send metadata.
+ * You need to specify the metadata in the return value of this callback.
+ * @param timeStampMs The timestamp (ms) of the current metadata.
+ * @return The metadata that you want to send in the format of byte[]. Ensure that you set the return value.
+ * PS: Ensure that the size of the metadata does not exceed the value set in the getMaxMetadataSize callback.*/
+ @Override
+ public byte[] onReadyToSendMetadata(long timeStampMs)
+ {
+ /**Check if the metadata is empty.*/
+ if (metadata == null)
+ {
+ return null;
+ }
+ Log.i(TAG, "There is metadata to send!");
+ /**Recycle metadata objects.*/
+ byte[] toBeSend = metadata;
+ metadata = null;
+ if (toBeSend.length > MAX_META_SIZE)
+ {
+ Log.e(TAG, String.format("Metadata exceeding max length %d!", MAX_META_SIZE));
+ return null;
+ }
+ String data = new String(toBeSend, Charset.forName("UTF-8"));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(getContext(), String.format(getString(R.string.sent), data), 300).show();
+ }
+ });
+ Log.i(TAG, String.format("Metadata sent successfully! The content is %s", data));
+ return toBeSend;
+ }
+
+ /**Occurs when the local user receives the metadata.
+ * @param buffer The received metadata.
+ * @param uid The ID of the user who sent the metadata.
+ * @param timeStampMs The timestamp (ms) of the received metadata.*/
+ @Override
+ public void onMetadataReceived(byte[] buffer, int uid, long timeStampMs)
+ {
+ String data = new String(buffer, Charset.forName("UTF-8"));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(getContext(), String.format(getString(R.string.received), data), 300).show();
+ }
+ });
+ Log.i(TAG, "onMetadataReceived:" + data);
+ }
+ };
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats)
+ {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ send.setEnabled(true);
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed)
+ {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ if (fl_remote.getChildCount() > 0)
+ {
+ fl_remote.removeAllViews();
+ }
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason)
+ {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/VideoQuickSwitch.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/VideoQuickSwitch.java
new file mode 100644
index 000000000..344a71bdf
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/VideoQuickSwitch.java
@@ -0,0 +1,614 @@
+package io.agora.api.example.examples.advanced;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.util.SparseArray;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.viewpager.widget.PagerAdapter;
+import androidx.viewpager.widget.ViewPager;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.rtc.Constants.REMOTE_VIDEO_STATE_DECODING;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+/**---------------------------------------Important!!!----------------------------------------------
+ * This example demonstrates how audience can quickly switch channels. The following points need to be noted:
+ 1: You can only access the channel as an audience{@link VideoQuickSwitch#joinChannel(String)}.
+ 2: If you want to see a normal remote screen, you need to set up several live rooms in advance and
+ push the stream as a live one (the name of the live room is in the channels instance{"channel0", "channel1", "channel2"};
+ at the same time, the appid you used to set up the live room should be consistent with this example program).
+ * @author cjw*/
+@Example(
+ index = 2,
+ group = ADVANCED,
+ name = R.string.item_quickswitck,
+ actionId = R.id.action_mainFragment_to_QuickSwitch,
+ tipsId = R.string.quickswitchchannel
+)
+public class VideoQuickSwitch extends BaseFragment
+{
+ private static final String TAG = VideoQuickSwitch.class.getSimpleName();
+ private ViewPager viewPager;
+ private RtcEngine engine;
+ private int myUid;
+ private final String[] channels = new String[]{"channel0", "channel1", "channel2"};
+ private List channelList = new ArrayList<>();
+ private ViewPagerAdapter viewPagerAdapter;
+ private int currentIndex = 0;
+ private int lastIndex = -1;
+ private boolean noBroadcaster = true;
+ private Runnable runnable = new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ if(noBroadcaster)
+ {
+ /**There is no broadcaster in the current channel*/
+ viewPagerAdapter.notifyBroadcaster(currentIndex, !noBroadcaster);
+ }
+ }
+ };
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_quick_switch_channel, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ viewPager = view.findViewById(R.id.viewPager);
+ /**Prepare data*/
+ for (String channel : channels)
+ {
+ channelList.add(channel);
+ }
+ viewPagerAdapter = new ViewPagerAdapter(getContext(), channelList);
+ viewPager.setAdapter(viewPagerAdapter);
+ viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener()
+ {
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
+ {
+ if (positionOffset == 0f && position != currentIndex)
+ {
+ viewPager.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ Log.i(TAG, "Will switch channel to " + channelList.get(position));
+
+ currentIndex = position;
+ if (lastIndex >= 0)
+ {
+ viewPagerAdapter.removeSurfaceViewByIndex(lastIndex);
+ viewPagerAdapter.notifyBroadcaster(lastIndex, true);
+ }
+
+ /**Since v2.9.0.
+ * Switches to a different channel.
+ * This method allows the audience of a Live-broadcast channel to switch to a different channel.
+ * After the user successfully switches to another channel, the onLeaveChannel
+ * and onJoinChannelSuccess callbacks are triggered to indicate that the
+ * user has left the original channel and joined a new one.
+ * @param token The token for authentication:
+ * In situations not requiring high security: You can use
+ * the temporary token generated at Console. For details,
+ * see Get a temporary token.
+ * In situations requiring high security: Set it as the token
+ * generated at your server. For details, see Get a token.
+ * @param channelName Unique channel name for the AgoraRTC session in the
+ * string format. The string length must be less than
+ * 64 bytes. Supported character scopes are:
+ * All lowercase English letters: a to z.
+ * All uppercase English letters: A to Z.
+ * All numeric characters: 0 to 9.
+ * The space character.
+ * Punctuation characters and other symbols, including:
+ * "!", "#", "$", "%", "&", "(", ")", "+", "-", ":",
+ * ";", "<", "=", ".", ">", "?", "@", "[", "]", "^",
+ * "_", " {", "}", "|", "~", ",".
+ * @return
+ * 0: Success.
+ * < 0: Failure.
+ * PS:
+ * Important!!!This method applies to the audience role in a
+ * Live-broadcast channel only.*/
+ int code = engine.switchChannel(null, channelList.get(position));
+
+ lastIndex = currentIndex;
+ }
+ });
+ }
+ }
+ @Override
+ public void onPageSelected(int position)
+ {}
+ @Override
+ public void onPageScrollStateChanged(int state)
+ {}
+ });
+ /**Swipe left and right to switch channel tips*/
+ showAlert(getString(R.string.swiptips));
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelList.get(0));
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.READ_EXTERNAL_STORAGE,
+ Permission.WRITE_EXTERNAL_STORAGE
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelList.get(0));
+ }).start();
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if (engine != null)
+ {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ private final void joinChannel(String channelId)
+ {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+
+ // Set audio route to speaker
+ engine.setDefaultAudioRoutetoSpeakerphone(true);
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the broadcaster.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_AUDIENCE);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ VD_640x360,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+ /**Set up to play remote sound with receiver*/
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+ engine.setEnableSpeakerphone(false);
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+
+ /**Allows a user to join a channel.
+ * if you do not specify the uid, we will generate the uid for you.
+ * If your account has enabled token mechanism through the console, you must fill in the
+ * corresponding token here. In general, it is not recommended to open the token mechanism in the test phase.*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.
+ * PS:
+ * Important! Because the channel is entered by the role of an audience, this callback will
+ * only be received when the broadcaster exits the channel.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats)
+ {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ handler.removeCallbacks(runnable);
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ /**Determine if there is a host in the channel*/
+ noBroadcaster = true;
+ handler.post(runnable);
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ if(state == REMOTE_VIDEO_STATE_DECODING)
+ {
+ /**REMOTE_VIDEO_STATE_DECODING as the basis for judging whether there is a broadcaster
+ * in the channel.
+ * But you should judge according to your own business logic, here is just for example,
+ * not for reference.*/
+ noBroadcaster = false;
+ }
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.
+ * PS:
+ * Important! Because the channel is entered by the role of an audience, this callback will
+ * only be received when the broadcaster exits the channel.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed)
+ {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ if(uid != myUid)
+ {
+ SurfaceView surfaceV = RtcEngine.CreateRendererView(getContext().getApplicationContext());
+ surfaceV.setZOrderMediaOverlay(true);
+ engine.setupRemoteVideo(new VideoCanvas(surfaceV, VideoCanvas.RENDER_MODE_HIDDEN, uid));
+ viewPagerAdapter.setSurfaceView(currentIndex, uid, surfaceV);
+ }
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.
+ * PS:
+ * Important! Because the channel is entered by the role of an audience, this callback will
+ * only be received when the broadcaster exits the channel.*/
+ @Override
+ public void onUserOffline(int uid, int reason)
+ {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ viewPagerAdapter.removeSurfaceView(uid);
+ }
+ });
+ }
+ };
+
+ public class ViewPagerAdapter extends PagerAdapter
+ {
+ private SparseArray viewList = new SparseArray<>();
+ private Context context;
+ private List roomNameList = new ArrayList<>();
+
+ public ViewPagerAdapter(Context context, List roomNameList)
+ {
+ this.context = context;
+ this.roomNameList = roomNameList;
+ }
+
+ @Override
+ public Object instantiateItem(ViewGroup collection, int position)
+ {
+ ViewGroup layout = viewList.get(position);
+ if (layout == null)
+ {
+ LayoutInflater inflater = LayoutInflater.from(context);
+ layout = (ViewGroup) inflater.inflate(R.layout.view_item_quickswitch, collection, false);
+ viewList.put(position, layout);
+
+ TextView channel = layout.findViewById(R.id.channelName);
+ channel.setText(String.format(getString(R.string.channelstr), roomNameList.get(position)));
+ }
+
+ collection.addView(layout);
+
+ return layout;
+ }
+
+ @Override
+ public void destroyItem(ViewGroup collection, int position, Object view)
+ {
+ collection.removeView((View) view);
+ }
+
+ @Override
+ public int getCount()
+ {
+ return roomNameList.size();
+ }
+
+ private void setSurfaceView(int position, final int uid, final SurfaceView view)
+ {
+ final ViewGroup viewGroup = viewList.get(position);
+ if (viewGroup != null)
+ {
+ ViewGroup surfaceContainer = viewGroup.findViewById(R.id.fl_remote);
+ surfaceContainer.removeAllViews();
+ view.setZOrderMediaOverlay(true);
+ surfaceContainer.addView(view, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+
+ TextView uidTextView = viewGroup.findViewById(R.id.uid);
+ uidTextView.setText(String.format("Uid: %d", uid));
+
+ viewGroup.setTag(uid);
+ }
+ }
+
+ private void removeSurfaceView(int uid)
+ {
+ for (int i = 0; i < viewList.size(); i++)
+ {
+ ViewGroup viewGroup = viewList.get(i);
+
+ if (viewGroup.getTag() != null && ((Integer) viewGroup.getTag()) == uid)
+ {
+ removeSurfaceView(viewGroup);
+ }
+ }
+ }
+
+ private void removeSurfaceViewByIndex(int index)
+ {
+ ViewGroup viewGroup = viewList.get(index);
+ if (viewGroup != null)
+ {
+ removeSurfaceView(viewGroup);
+ }
+ }
+
+ private void removeSurfaceView(ViewGroup viewGroup)
+ {
+ ViewGroup surfaceContainer = viewGroup.findViewById(R.id.fl_remote);
+ surfaceContainer.removeAllViews();
+
+ TextView uidTextView = viewGroup.findViewById(R.id.uid);
+ uidTextView.setText("");
+ }
+
+ public void notifyBroadcaster(int index, boolean exists)
+ {
+ ViewGroup viewGroup = viewList.get(index);
+ if (viewGroup != null)
+ {
+ TextView textView = viewGroup.findViewById(R.id.noBroadcaster);
+ textView.setVisibility(exists ? View.GONE : View.VISIBLE);
+ }
+ }
+
+ @Override
+ public boolean isViewFromObject(@NonNull View view, @NonNull Object object)
+ {
+ return view == object;
+ }
+
+ @Override
+ public CharSequence getPageTitle(int position)
+ {
+ return "";
+ }
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/customaudio/AudioRecordService.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/customaudio/AudioRecordService.java
new file mode 100644
index 000000000..0b32f2b6a
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/customaudio/AudioRecordService.java
@@ -0,0 +1,173 @@
+package io.agora.api.example.examples.advanced.customaudio;
+
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Intent;
+import android.media.AudioFormat;
+import android.media.AudioRecord;
+import android.media.MediaRecorder;
+import android.os.Build;
+import android.os.IBinder;
+import android.util.Log;
+
+import androidx.annotation.Nullable;
+import androidx.core.app.NotificationCompat;
+
+import io.agora.api.example.MainActivity;
+
+public class AudioRecordService extends Service
+{
+ private static final String TAG = AudioRecordService.class.getSimpleName();
+
+ private RecordThread thread;
+ private volatile boolean stopped;
+
+ @Nullable
+ @Override
+ public IBinder onBind(Intent intent)
+ {
+ return null;
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId)
+ {
+ startForeground();
+ startRecording();
+ return Service.START_STICKY;
+ }
+
+ private void startForeground()
+ {
+ createNotificationChannel();
+ Intent notificationIntent = new Intent(this, MainActivity.class);
+ PendingIntent pendingIntent = PendingIntent.getActivity(this,
+ 0, notificationIntent, 0);
+
+ Notification notification = new NotificationCompat.Builder(this, TAG)
+ .setContentTitle(TAG)
+ .setContentIntent(pendingIntent)
+ .build();
+
+ startForeground(1, notification);
+ }
+
+ private void createNotificationChannel()
+ {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ {
+ NotificationChannel serviceChannel = new NotificationChannel(
+ TAG, TAG, NotificationManager.IMPORTANCE_DEFAULT
+ );
+
+ NotificationManager manager = getSystemService(NotificationManager.class);
+ manager.createNotificationChannel(serviceChannel);
+ }
+ }
+
+ private void startRecording()
+ {
+ thread = new RecordThread();
+ thread.start();
+ }
+
+ private void stopRecording()
+ {
+ stopped = true;
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ stopRecording();
+ super.onDestroy();
+ }
+
+ public class RecordThread extends Thread
+ {
+ private AudioRecord audioRecord;
+ public static final int DEFAULT_SAMPLE_RATE = 16000;
+ /**1 corresponds to AudioFormat.CHANNEL_IN_MONO;
+ * 2 corresponds to AudioFormat.CHANNEL_IN_STEREO*/
+ public static final int DEFAULT_CHANNEL_COUNT = 1, DEFAULT_CHANNEL_CONFIG = AudioFormat.CHANNEL_IN_MONO;
+ private byte[] buffer;
+
+ RecordThread()
+ {
+ int bufferSize = AudioRecord.getMinBufferSize(DEFAULT_SAMPLE_RATE, DEFAULT_CHANNEL_CONFIG,
+ AudioFormat.ENCODING_PCM_16BIT);
+ audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, DEFAULT_SAMPLE_RATE, DEFAULT_CHANNEL_COUNT,
+ AudioFormat.ENCODING_PCM_16BIT, bufferSize);
+ buffer = new byte[bufferSize];
+ }
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ audioRecord.startRecording();
+ while (!stopped)
+ {
+ int result = audioRecord.read(buffer, 0, buffer.length);
+ if (result >= 0)
+ {
+ /**Pushes the external audio frame to the Agora SDK for encoding.
+ * @param data External audio data to be pushed.
+ * @param timeStamp Timestamp of the external audio frame. It is mandatory.
+ * You can use this parameter for the following purposes:
+ * 1:Restore the order of the captured audio frame.
+ * 2:Synchronize audio and video frames in video-related
+ * scenarios, including scenarios where external video sources are used.
+ * @return
+ * 0: Success.
+ * < 0: Failure.*/
+ CustomAudioSource.engine.pushExternalAudioFrame(
+ buffer, System.currentTimeMillis());
+ }
+ else
+ {
+ logRecordError(result);
+ }
+ Log.e(TAG, "数据大小:" + result);
+ }
+ release();
+ }
+ catch (Exception e)
+ {e.printStackTrace();}
+ }
+
+ private void logRecordError(int error)
+ {
+ String message = "";
+ switch (error)
+ {
+ case AudioRecord.ERROR:
+ message = "generic operation failure";
+ break;
+ case AudioRecord.ERROR_BAD_VALUE:
+ message = "failure due to the use of an invalid value";
+ break;
+ case AudioRecord.ERROR_DEAD_OBJECT:
+ message = "object is no longer valid and needs to be recreated";
+ break;
+ case AudioRecord.ERROR_INVALID_OPERATION:
+ message = "failure due to the improper use of method";
+ break;
+ }
+ Log.e(TAG, message);
+ }
+
+ private void release()
+ {
+ if (audioRecord != null)
+ {
+ audioRecord.stop();
+ buffer = null;
+ }
+ }
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/customaudio/CustomAudioSource.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/customaudio/CustomAudioSource.java
new file mode 100755
index 000000000..e46f3e059
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/customaudio/CustomAudioSource.java
@@ -0,0 +1,332 @@
+package io.agora.api.example.examples.advanced.customaudio;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+
+import static io.agora.api.example.common.model.Examples.ADVANCED;
+import static io.agora.api.example.examples.advanced.customaudio.AudioRecordService.RecordThread.DEFAULT_CHANNEL_COUNT;
+import static io.agora.api.example.examples.advanced.customaudio.AudioRecordService.RecordThread.DEFAULT_SAMPLE_RATE;
+
+/**This demo demonstrates how to make a one-to-one voice call*/
+@Example(
+ index = 8,
+ group = ADVANCED,
+ name = R.string.item_customaudiosource,
+ actionId = R.id.action_mainFragment_to_CustomAudioSource,
+ tipsId = R.string.customaudio
+)
+public class CustomAudioSource extends BaseFragment implements View.OnClickListener
+{
+ private static final String TAG = CustomAudioSource.class.getSimpleName();
+ private EditText et_channel;
+ private Button mute, join;
+ private int myUid;
+ private boolean joined = false;
+ public static RtcEngine engine;
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ handler = new Handler();
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_custom_audiorecord, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ mute = view.findViewById(R.id.btn_mute);
+ mute.setOnClickListener(this);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(getContext().getApplicationContext(), getString(R.string.agora_app_id),
+ iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ stopAudioRecord();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if(engine != null)
+ {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+ if (v.getId() == R.id.btn_join)
+ {
+ if (!joined)
+ {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ }
+ else
+ {
+ joined = false;
+ stopAudioRecord();
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ mute.setText(getString(R.string.closemicrophone));
+ mute.setEnabled(false);
+ }
+ }
+ else if (v.getId() == R.id.btn_mute)
+ {
+ mute.setActivated(!mute.isActivated());
+ mute.setText(getString(mute.isActivated() ? R.string.openmicrophone : R.string.closemicrophone));
+ /**Turn off / on the microphone, stop / start local audio collection and push streaming.*/
+ engine.muteLocalAudioStream(mute.isActivated());
+ }
+ }
+
+ /**
+ * @param channelId Specify the channel name that you want to join.
+ * Users that input the same channel name join the same channel.*/
+ private void joinChannel(String channelId)
+ {
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ /**Sets the external audio source.
+ * @param enabled Sets whether to enable/disable the external audio source:
+ * true: Enable the external audio source.
+ * false: (Default) Disable the external audio source.
+ * @param sampleRate Sets the sample rate (Hz) of the external audio source, which can be
+ * set as 8000, 16000, 32000, 44100, or 48000 Hz.
+ * @param channels Sets the number of channels of the external audio source:
+ * 1: Mono.
+ * 2: Stereo.
+ * @return
+ * 0: Success.
+ * < 0: Failure.
+ * PS: Ensure that you call this method before the joinChannel method.*/
+ engine.setExternalAudioSource(true, DEFAULT_SAMPLE_RATE, DEFAULT_CHANNEL_COUNT);
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ private void startAudioRecord()
+ {
+ Intent intent = new Intent(getContext(), AudioRecordService.class);
+ getActivity().startService(intent);
+ }
+
+ private void stopAudioRecord()
+ {
+ Intent intent = new Intent(getContext(), AudioRecordService.class);
+ getActivity().stopService(intent);
+ }
+
+ /**IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ mute.setEnabled(true);
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ }
+ });
+ startAudioRecord();
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/basic/JoinChannelAudio.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/basic/JoinChannelAudio.java
new file mode 100755
index 000000000..3190f2069
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/basic/JoinChannelAudio.java
@@ -0,0 +1,336 @@
+package io.agora.api.example.examples.basic;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+
+import static io.agora.api.example.common.model.Examples.BASIC;
+
+/**
+ * This demo demonstrates how to make a one-to-one voice call
+ *
+ * @author cjw
+ */
+@Example(
+ index = 1,
+ group = BASIC,
+ name = R.string.item_joinaudio,
+ actionId = R.id.action_mainFragment_to_joinChannelAudio,
+ tipsId = R.string.joinchannelaudio
+)
+public class JoinChannelAudio extends BaseFragment implements View.OnClickListener {
+ private static final String TAG = JoinChannelAudio.class.getSimpleName();
+ private EditText et_channel;
+ private Button mute, join, speaker;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false;
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ handler = new Handler();
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_joinchannel_audio, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ mute = view.findViewById(R.id.btn_mute);
+ mute.setOnClickListener(this);
+ speaker = view.findViewById(R.id.btn_speaker);
+ speaker.setOnClickListener(this);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ try {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ String appId = getString(R.string.agora_app_id);
+ engine = RtcEngine.create(getContext().getApplicationContext(), appId, iRtcEngineEventHandler);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if (engine != null) {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.btn_join) {
+ if (!joined) {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA)) {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ } else {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ speaker.setText(getString(R.string.speaker));
+ speaker.setEnabled(false);
+ mute.setText(getString(R.string.closemicrophone));
+ mute.setEnabled(false);
+ }
+ } else if (v.getId() == R.id.btn_mute) {
+ mute.setActivated(!mute.isActivated());
+ mute.setText(getString(mute.isActivated() ? R.string.openmicrophone : R.string.closemicrophone));
+ /**Turn off / on the microphone, stop / start local audio collection and push streaming.*/
+ engine.muteLocalAudioStream(mute.isActivated());
+ } else if (v.getId() == R.id.btn_speaker) {
+ speaker.setActivated(!speaker.isActivated());
+ speaker.setText(getString(speaker.isActivated() ? R.string.earpiece : R.string.speaker));
+ /**Turn off / on the speaker and change the audio playback route.*/
+ engine.setEnableSpeakerphone(speaker.isActivated());
+ }
+ }
+
+ /**
+ * @param channelId Specify the channel name that you want to join.
+ * Users that input the same channel name join the same channel.
+ */
+ private void joinChannel(String channelId) {
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>")) {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ engine.enableAudioVolumeIndication(1000, 3, true);
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0) {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ Log.e(TAG, RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+
+
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler() {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn) {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err) {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats) {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ speaker.setEnabled(true);
+ mute.setEnabled(true);
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed) {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed) {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason) {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ }
+
+ @Override
+ public void onActiveSpeaker(int uid) {
+ super.onActiveSpeaker(uid);
+ Log.i(TAG, String.format("onActiveSpeaker:%d", uid));
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/examples/basic/JoinChannelVideo.java b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/basic/JoinChannelVideo.java
new file mode 100644
index 000000000..ba1ee523a
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/examples/basic/JoinChannelVideo.java
@@ -0,0 +1,439 @@
+package io.agora.api.example.examples.basic;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.yanzhenjie.permission.AndPermission;
+import com.yanzhenjie.permission.runtime.Permission;
+
+import io.agora.api.example.R;
+import io.agora.api.example.annotation.Example;
+import io.agora.api.example.common.BaseFragment;
+import io.agora.api.example.utils.CommonUtil;
+import io.agora.rtc.Constants;
+import io.agora.rtc.IRtcEngineEventHandler;
+import io.agora.rtc.RtcEngine;
+import io.agora.rtc.video.VideoCanvas;
+import io.agora.rtc.video.VideoEncoderConfiguration;
+
+import static io.agora.api.example.common.model.Examples.BASIC;
+import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
+import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
+import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
+import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
+
+/**This demo demonstrates how to make a one-to-one video call*/
+@Example(
+ index = 0,
+ group = BASIC,
+ name = R.string.item_joinvideo,
+ actionId = R.id.action_mainFragment_to_joinChannelVideo,
+ tipsId = R.string.joinchannelvideo
+)
+public class JoinChannelVideo extends BaseFragment implements View.OnClickListener
+{
+ private static final String TAG = JoinChannelVideo.class.getSimpleName();
+
+ private FrameLayout fl_local, fl_remote;
+ private Button join;
+ private EditText et_channel;
+ private RtcEngine engine;
+ private int myUid;
+ private boolean joined = false;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
+ {
+ View view = inflater.inflate(R.layout.fragment_joinchannel_video, container, false);
+ return view;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
+ {
+ super.onViewCreated(view, savedInstanceState);
+ join = view.findViewById(R.id.btn_join);
+ et_channel = view.findViewById(R.id.et_channel);
+ view.findViewById(R.id.btn_join).setOnClickListener(this);
+ fl_local = view.findViewById(R.id.fl_local);
+ fl_remote = view.findViewById(R.id.fl_remote);
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+ try
+ {
+ /**Creates an RtcEngine instance.
+ * @param context The context of Android Activity
+ * @param appId The App ID issued to you by Agora. See
+ * How to get the App ID
+ * @param handler IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.*/
+ engine = RtcEngine.create(context.getApplicationContext(), getString(R.string.agora_app_id), iRtcEngineEventHandler);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ getActivity().onBackPressed();
+ }
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ /**leaveChannel and Destroy the RtcEngine instance*/
+ if(engine != null)
+ {
+ engine.leaveChannel();
+ }
+ handler.post(RtcEngine::destroy);
+ engine = null;
+ }
+
+ @Override
+ public void onClick(View v)
+ {
+ if (v.getId() == R.id.btn_join)
+ {
+ if (!joined)
+ {
+ CommonUtil.hideInputBoard(getActivity(), et_channel);
+ // call when join button hit
+ String channelId = et_channel.getText().toString();
+ // Check permission
+ if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
+ {
+ joinChannel(channelId);
+ return;
+ }
+ // Request permission
+ AndPermission.with(this).runtime().permission(
+ Permission.Group.STORAGE,
+ Permission.Group.MICROPHONE,
+ Permission.Group.CAMERA
+ ).onGranted(permissions ->
+ {
+ // Permissions Granted
+ joinChannel(channelId);
+ }).start();
+ }
+ else
+ {
+ joined = false;
+ /**After joining a channel, the user must call the leaveChannel method to end the
+ * call before joining another channel. This method returns 0 if the user leaves the
+ * channel and releases all resources related to the call. This method call is
+ * asynchronous, and the user has not exited the channel when the method call returns.
+ * Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
+ * A successful leaveChannel method call triggers the following callbacks:
+ * 1:The local client: onLeaveChannel.
+ * 2:The remote client: onUserOffline, if the user leaving the channel is in the
+ * Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+ * @returns 0: Success.
+ * < 0: Failure.
+ * PS:
+ * 1:If you call the destroy method immediately after calling the leaveChannel
+ * method, the leaveChannel process interrupts, and the SDK does not trigger
+ * the onLeaveChannel callback.
+ * 2:If you call the leaveChannel method during CDN live streaming, the SDK
+ * triggers the removeInjectStreamUrl method.*/
+ engine.leaveChannel();
+ join.setText(getString(R.string.join));
+ }
+ }
+ }
+
+ private void joinChannel(String channelId)
+ {
+ // Check if the context is valid
+ Context context = getContext();
+ if (context == null)
+ {
+ return;
+ }
+
+ // Create render view by RtcEngine
+ SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
+ // Local video is on the top
+ surfaceView.setZOrderMediaOverlay(true);
+ if(fl_local.getChildCount() > 0)
+ {
+ fl_local.removeAllViews();
+ }
+ // Add to the local container
+ fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ // Setup local video to render your local camera preview
+ engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
+ // Set audio route to microPhone
+ engine.setDefaultAudioRoutetoSpeakerphone(false);
+
+ /** Sets the channel profile of the Agora RtcEngine.
+ CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
+ Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
+ channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
+ an audience can only receive streams.*/
+ engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
+ /**In the demo, the default is to enter as the anchor.*/
+ engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
+ // Enable video module
+ engine.enableVideo();
+ // Setup video encoding configs
+ engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
+ VD_640x360,
+ FRAME_RATE_FPS_15,
+ STANDARD_BITRATE,
+ ORIENTATION_MODE_ADAPTIVE
+ ));
+
+ /**Please configure accessToken in the string_config file.
+ * A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
+ * https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
+ * A token generated at the server. This applies to scenarios with high-security requirements. For details, see
+ * https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
+ String accessToken = getString(R.string.agora_access_token);
+ if (TextUtils.equals(accessToken, "") || TextUtils.equals(accessToken, "<#YOUR ACCESS TOKEN#>"))
+ {
+ accessToken = null;
+ }
+ /** Allows a user to join a channel.
+ if you do not specify the uid, we will generate the uid for you*/
+ int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
+ if (res != 0)
+ {
+ // Usually happens with invalid parameters
+ // Error code description can be found at:
+ // en: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ // cn: https://docs.agora.io/cn/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html
+ showAlert(RtcEngine.getErrorDescription(Math.abs(res)));
+ return;
+ }
+ // Prevent repeated entry
+ join.setEnabled(false);
+ }
+
+ /**
+ * IRtcEngineEventHandler is an abstract class providing default implementation.
+ * The SDK uses this class to report to the app on SDK runtime events.
+ */
+ private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
+ {
+ /**Reports a warning during SDK runtime.
+ * Warning code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_warn_code.html*/
+ @Override
+ public void onWarning(int warn)
+ {
+ Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
+ }
+
+ /**Reports an error during SDK runtime.
+ * Error code: https://docs.agora.io/en/Voice/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_engine_event_handler_1_1_error_code.html*/
+ @Override
+ public void onError(int err)
+ {
+ Log.e(TAG, String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ showAlert(String.format("onError code %d message %s", err, RtcEngine.getErrorDescription(err)));
+ }
+
+ /**Occurs when a user leaves the channel.
+ * @param stats With this callback, the application retrieves the channel information,
+ * such as the call duration and statistics.*/
+ @Override
+ public void onLeaveChannel(RtcStats stats)
+ {
+ super.onLeaveChannel(stats);
+ Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
+ showLongToast(String.format("local user %d leaveChannel!", myUid));
+ }
+
+ /**Occurs when the local user joins a specified channel.
+ * The channel name assignment is based on channelName specified in the joinChannel method.
+ * If the uid is not specified when joinChannel is called, the server automatically assigns a uid.
+ * @param channel Channel name
+ * @param uid User ID
+ * @param elapsed Time elapsed (ms) from the user calling joinChannel until this callback is triggered*/
+ @Override
+ public void onJoinChannelSuccess(String channel, int uid, int elapsed)
+ {
+ Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
+ myUid = uid;
+ joined = true;
+ handler.post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ join.setEnabled(true);
+ join.setText(getString(R.string.leave));
+ }
+ });
+ }
+
+ /**Since v2.9.0.
+ * This callback indicates the state change of the remote audio stream.
+ * PS: This callback does not work properly when the number of users (in the Communication profile) or
+ * broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the user whose audio state changes.
+ * @param state State of the remote audio
+ * REMOTE_AUDIO_STATE_STOPPED(0): The remote audio is in the default state, probably due
+ * to REMOTE_AUDIO_REASON_LOCAL_MUTED(3), REMOTE_AUDIO_REASON_REMOTE_MUTED(5),
+ * or REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
+ * REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally,
+ * probably due to REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2),
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4) or REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6).
+ * REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen, probably due to
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1).
+ * REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start, probably due to
+ * REMOTE_AUDIO_REASON_INTERNAL(0).
+ * @param reason The reason of the remote audio state change.
+ * REMOTE_AUDIO_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio
+ * stream or disables the audio module.
+ * REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio
+ * stream or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or
+ * disables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream
+ * or enables the audio module.
+ * REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method
+ * until the SDK triggers this callback.*/
+ @Override
+ public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Since v2.9.0.
+ * Occurs when the remote video state changes.
+ * PS: This callback does not work properly when the number of users (in the Communication
+ * profile) or broadcasters (in the Live-broadcast profile) in the channel exceeds 17.
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video:
+ * REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the default state, probably due
+ * to REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5),
+ * or REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7).
+ * REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
+ * REMOTE_VIDEO_STATE_DECODING(2): The remote video stream is decoded and plays normally,
+ * probably due to REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2),
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6),
+ * or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
+ * REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen, probably due to
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
+ * REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start, probably due to
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
+ * @param reason The reason of the remote video state change:
+ * REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
+ * REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote
+ * video stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote
+ * video stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video
+ * stream or disables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video
+ * stream or enables the video module.
+ * REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the
+ * audio-only stream due to poor network conditions.
+ * REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches
+ * back to the video stream after the network conditions improve.
+ * @param elapsed Time elapsed (ms) from the local user calling the joinChannel method until
+ * the SDK triggers this callback.*/
+ @Override
+ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed)
+ {
+ super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
+ Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) joins the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param elapsed Time delay (ms) from the local user calling joinChannel/setClientRole
+ * until this callback is triggered.*/
+ @Override
+ public void onUserJoined(int uid, int elapsed)
+ {
+ super.onUserJoined(uid, elapsed);
+ Log.i(TAG, "onUserJoined->" + uid);
+ showLongToast(String.format("user %d joined!", uid));
+ /**Check if the context is correct*/
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+ handler.post(() ->
+ {
+ /**Display remote video stream*/
+ SurfaceView surfaceView = null;
+ if (fl_remote.getChildCount() > 0)
+ {
+ fl_remote.removeAllViews();
+ }
+ // Create render view by RtcEngine
+ surfaceView = RtcEngine.CreateRendererView(context);
+ surfaceView.setZOrderMediaOverlay(true);
+ // Add to the remote container
+ fl_remote.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+
+ // Setup remote video to render
+ engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
+ });
+ }
+
+ /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+ * @param uid ID of the user whose audio state changes.
+ * @param reason Reason why the user goes offline:
+ * USER_OFFLINE_QUIT(0): The user left the current channel.
+ * USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because no data
+ * packet was received within a certain period of time. If a user quits the
+ * call and the message is not passed to the SDK (due to an unreliable channel),
+ * the SDK assumes the user dropped offline.
+ * USER_OFFLINE_BECOME_AUDIENCE(2): (Live broadcast only.) The client role switched from
+ * the host to the audience.*/
+ @Override
+ public void onUserOffline(int uid, int reason)
+ {
+ Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
+ showLongToast(String.format("user %d offline! reason:%d", uid, reason));
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ /**Clear render view
+ Note: The video will stay at its last frame, to completely remove it you will need to
+ remove the SurfaceView from its parent*/
+ engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
+ }
+ });
+ }
+ };
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/utils/ClassUtils.java b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/ClassUtils.java
new file mode 100644
index 000000000..0c281272d
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/ClassUtils.java
@@ -0,0 +1,285 @@
+package io.agora.api.example.utils;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import android.util.Log;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import dalvik.system.DexFile;
+import io.agora.api.example.BuildConfig;
+
+public class ClassUtils
+{
+ private static final String TAG = ClassUtils.class.getSimpleName();
+ private static final String EXTRACTED_NAME_EXT = ".classes";
+ private static final String EXTRACTED_SUFFIX = ".zip";
+
+ private static final String SECONDARY_FOLDER_NAME = "code_cache" + File.separator + "secondary-dexes";
+
+ private static final String PREFS_FILE = "multidex.version";
+ private static final String KEY_DEX_NUMBER = "dex.number";
+
+ private static final int VM_WITH_MULTIDEX_VERSION_MAJOR = 2;
+ private static final int VM_WITH_MULTIDEX_VERSION_MINOR = 1;
+
+ private static SharedPreferences getMultiDexPreferences(Context context)
+ {
+ return context.getSharedPreferences(PREFS_FILE, Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? Context.MODE_PRIVATE : Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS);
+ }
+
+ /**
+ * By specifying the package name, scan all ClassName contained under the package
+ *
+ * @param context
+ * @param packageName
+ * @return Collection of all classes
+ */
+ public static Set getFileNameByPackageName(Context context, final String packageName) throws PackageManager.NameNotFoundException, IOException, InterruptedException
+ {
+ final Set classNames = new HashSet<>();
+
+ List paths = getSourcePaths(context);
+ final CountDownLatch parserCtl = new CountDownLatch(paths.size());
+
+ for (final String path : paths)
+ {
+ DefaultPoolExecutor.getInstance().execute(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ DexFile dexfile = null;
+
+ try
+ {
+ if (path.endsWith(EXTRACTED_SUFFIX))
+ {
+ //NOT use new DexFile(path), because it will throw "permission error in /data/dalvik-cache"
+ dexfile = DexFile.loadDex(path, path + ".tmp", 0);
+ }
+ else
+ {
+ dexfile = new DexFile(path);
+ }
+
+ Enumeration dexEntries = dexfile.entries();
+ while (dexEntries.hasMoreElements())
+ {
+ String className = dexEntries.nextElement();
+ if (className.startsWith(packageName))
+ {
+ classNames.add(className);
+ }
+ }
+ }
+ catch (Throwable ignore)
+ {
+ Log.e("ARouter", "Scan map file in dex files made error.", ignore);
+ }
+ finally
+ {
+ if (null != dexfile)
+ {
+ try
+ {
+ dexfile.close();
+ }
+ catch (Throwable ignore)
+ {
+ }
+ }
+
+ parserCtl.countDown();
+ }
+ }
+ });
+ }
+
+ parserCtl.await();
+
+ Log.d(TAG, "Filter " + classNames.size() + " classes by packageName <" + packageName + ">");
+ return classNames;
+ }
+
+ /**
+ * get all the dex path
+ *
+ * @param context the application context
+ * @return all the dex path
+ * @throws PackageManager.NameNotFoundException
+ * @throws IOException
+ */
+ public static List getSourcePaths(Context context) throws PackageManager.NameNotFoundException, IOException
+ {
+ ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
+ File sourceApk = new File(applicationInfo.sourceDir);
+
+ List sourcePaths = new ArrayList<>();
+ sourcePaths.add(applicationInfo.sourceDir); //add the default apk path
+
+ //the prefix of extracted file, ie: test.classes
+ String extractedFilePrefix = sourceApk.getName() + EXTRACTED_NAME_EXT;
+
+ /** If MultiDex already supported by VM, we will not to load Classesx.zip from
+ * Secondary Folder, because there is none.*/
+ if (!isVMMultidexCapable())
+ {
+ //the total dex numbers
+ int totalDexNumber = getMultiDexPreferences(context).getInt(KEY_DEX_NUMBER, 1);
+ File dexDir = new File(applicationInfo.dataDir, SECONDARY_FOLDER_NAME);
+
+ for (int secondaryNumber = 2; secondaryNumber <= totalDexNumber; secondaryNumber++)
+ {
+ //for each dex file, ie: test.classes2.zip, test.classes3.zip...
+ String fileName = extractedFilePrefix + secondaryNumber + EXTRACTED_SUFFIX;
+ File extractedFile = new File(dexDir, fileName);
+ if (extractedFile.isFile())
+ {
+ sourcePaths.add(extractedFile.getAbsolutePath());
+ //we ignore the verify zip part
+ }
+ else
+ {
+ throw new IOException("Missing extracted secondary dex file '" + extractedFile.getPath() + "'");
+ }
+ }
+ }
+
+ if (BuildConfig.DEBUG)
+ { // Search instant run support only debuggable
+ sourcePaths.addAll(tryLoadInstantRunDexFile(applicationInfo));
+ }
+ return sourcePaths;
+ }
+
+ /**
+ * Get instant run dex path, used to catch the branch usingApkSplits=false.
+ */
+ private static List tryLoadInstantRunDexFile(ApplicationInfo applicationInfo)
+ {
+ List instantRunSourcePaths = new ArrayList<>();
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && null != applicationInfo.splitSourceDirs)
+ {
+ // add the split apk, normally for InstantRun, and newest version.
+ instantRunSourcePaths.addAll(Arrays.asList(applicationInfo.splitSourceDirs));
+ Log.d(TAG, "Found InstantRun support");
+ }
+ else
+ {
+ try
+ {
+ // This man is reflection from Google instant run sdk, he will tell me where the dex files go.
+ Class pathsByInstantRun = Class.forName("com.android.tools.fd.runtime.Paths");
+ Method getDexFileDirectory = pathsByInstantRun.getMethod("getDexFileDirectory", String.class);
+ String instantRunDexPath = (String) getDexFileDirectory.invoke(null, applicationInfo.packageName);
+
+ File instantRunFilePath = new File(instantRunDexPath);
+ if (instantRunFilePath.exists() && instantRunFilePath.isDirectory())
+ {
+ File[] dexFile = instantRunFilePath.listFiles();
+ for (File file : dexFile)
+ {
+ if (null != file && file.exists() && file.isFile() && file.getName().endsWith(".dex"))
+ {
+ instantRunSourcePaths.add(file.getAbsolutePath());
+ }
+ }
+ Log.d(TAG, "Found InstantRun support");
+ }
+
+ }
+ catch (Exception e)
+ {
+ Log.e(TAG, "InstantRun support error, " + e.getMessage());
+ }
+ }
+
+ return instantRunSourcePaths;
+ }
+
+ /**
+ * Identifies if the current VM has a native support for multidex, meaning there is no need for
+ * additional installation by this library.
+ *
+ * @return true if the VM handles multidex
+ */
+ private static boolean isVMMultidexCapable()
+ {
+ boolean isMultidexCapable = false;
+ String vmName = null;
+
+ try
+ {
+ if (isYunOS())
+ { // YunOS need special judgment
+ vmName = "'YunOS'";
+ isMultidexCapable = Integer.valueOf(System.getProperty("ro.build.version.sdk")) >= 21;
+ }
+ else
+ { // Native Android system
+ vmName = "'Android'";
+ String versionString = System.getProperty("java.vm.version");
+ if (versionString != null)
+ {
+ Matcher matcher = Pattern.compile("(\\d+)\\.(\\d+)(\\.\\d+)?").matcher(versionString);
+ if (matcher.matches())
+ {
+ try
+ {
+ int major = Integer.parseInt(matcher.group(1));
+ int minor = Integer.parseInt(matcher.group(2));
+ isMultidexCapable = (major > VM_WITH_MULTIDEX_VERSION_MAJOR)
+ || ((major == VM_WITH_MULTIDEX_VERSION_MAJOR)
+ && (minor >= VM_WITH_MULTIDEX_VERSION_MINOR));
+ }
+ catch (NumberFormatException ignore)
+ {
+ // let isMultidexCapable be false
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ignore)
+ {
+
+ }
+
+ Log.i(TAG, "VM with name " + vmName + (isMultidexCapable ? " has multidex support" : " does not have multidex support"));
+ return isMultidexCapable;
+ }
+
+ /**
+ * Determine whether the system is a YunOS system
+ */
+ private static boolean isYunOS()
+ {
+ try
+ {
+ String version = System.getProperty("ro.yunos.version");
+ String vmName = System.getProperty("java.vm.name");
+ return (vmName != null && vmName.toLowerCase().contains("lemur"))
+ || (version != null && version.trim().length() > 0);
+ }
+ catch (Exception ignore)
+ {
+ return false;
+ }
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/utils/CommonUtil.java b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/CommonUtil.java
new file mode 100644
index 000000000..b78399dc2
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/CommonUtil.java
@@ -0,0 +1,18 @@
+package io.agora.api.example.utils;
+
+import android.app.Activity;
+import android.content.Context;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+
+/**
+ * @author cjw
+ */
+public class CommonUtil {
+
+ public static void hideInputBoard(Activity activity, EditText editText)
+ {
+ InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/utils/DefaultPoolExecutor.java b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/DefaultPoolExecutor.java
new file mode 100644
index 000000000..324fc3087
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/DefaultPoolExecutor.java
@@ -0,0 +1,97 @@
+package io.agora.api.example.utils;
+
+import android.util.Log;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.RejectedExecutionHandler;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Executors
+ *
+ * @version 1.0
+ * @since 16/4/28 下午4:07
+ */
+public class DefaultPoolExecutor extends ThreadPoolExecutor
+{
+ private static final String TAG = DefaultPoolExecutor.class.getSimpleName();
+ // Thread args
+ private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
+ private static final int INIT_THREAD_COUNT = CPU_COUNT + 1;
+ private static final int MAX_THREAD_COUNT = INIT_THREAD_COUNT;
+ private static final long SURPLUS_THREAD_LIFE = 30L;
+
+ private static DefaultPoolExecutor instance;
+
+ public static DefaultPoolExecutor getInstance()
+ {
+ if (null == instance)
+ {
+ synchronized (DefaultPoolExecutor.class)
+ {
+ if (null == instance)
+ {
+ instance = new DefaultPoolExecutor(
+ INIT_THREAD_COUNT,
+ MAX_THREAD_COUNT,
+ SURPLUS_THREAD_LIFE,
+ TimeUnit.SECONDS,
+ new ArrayBlockingQueue(64),
+ new DefaultThreadFactory());
+ }
+ }
+ }
+ return instance;
+ }
+
+ private DefaultPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue workQueue, ThreadFactory threadFactory)
+ {
+ super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, new RejectedExecutionHandler()
+ {
+ @Override
+ public void rejectedExecution(Runnable r, ThreadPoolExecutor executor)
+ {
+ Log.e(TAG, "Task rejected, too many task!");
+ }
+ });
+ }
+
+ /* thread execution complete, handle possible exceptions.
+ * @param r the runnable that has completed
+ * @param t the exception that caused termination, or null if
+ */
+ @Override
+ protected void afterExecute(Runnable r, Throwable t)
+ {
+ super.afterExecute(r, t);
+ if (t == null && r instanceof Future>)
+ {
+ try
+ {
+ ((Future>) r).get();
+ }
+ catch (CancellationException ce)
+ {
+ t = ce;
+ }
+ catch (ExecutionException ee)
+ {
+ t = ee.getCause();
+ }
+ catch (InterruptedException ie)
+ {
+ Thread.currentThread().interrupt(); // ignore/reset
+ }
+ }
+ if (t != null)
+ {
+ Log.w(TAG, "Running task appeared exception! Thread [" + Thread.currentThread().getName() + "], because [" + t.getMessage() + "]\n" + TextUtils.formatStackTrace(t.getStackTrace()));
+ }
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/utils/DefaultThreadFactory.java b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/DefaultThreadFactory.java
new file mode 100644
index 000000000..7a6f99fca
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/DefaultThreadFactory.java
@@ -0,0 +1,53 @@
+package io.agora.api.example.utils;
+
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * DefaultThreadFactory
+ *
+ * @author zhilong Contact me.
+ * @version 1.0
+ * @since 15/12/25 上午10:51
+ */
+public class DefaultThreadFactory implements ThreadFactory
+{
+ private static final String TAG = DefaultThreadFactory.class.getSimpleName();
+
+ private static final AtomicInteger poolNumber = new AtomicInteger(1);
+
+ private final AtomicInteger threadNumber = new AtomicInteger(1);
+ private final ThreadGroup group;
+ private final String namePrefix;
+
+ public DefaultThreadFactory()
+ {
+ SecurityManager s = System.getSecurityManager();
+ group = (s != null) ? s.getThreadGroup() :
+ Thread.currentThread().getThreadGroup();
+ namePrefix = "ARouter task pool No." + poolNumber.getAndIncrement() + ", thread No.";
+ }
+
+ public Thread newThread(@NonNull Runnable runnable)
+ {
+ String threadName = namePrefix + threadNumber.getAndIncrement();
+ Log.i(TAG, "Thread production, name is [" + threadName + "]");
+ Thread thread = new Thread(group, runnable, threadName, 0);
+ if (thread.isDaemon())
+ { //Make non-background thread
+ thread.setDaemon(false);
+ }
+ if (thread.getPriority() != Thread.NORM_PRIORITY)
+ {
+ thread.setPriority(Thread.NORM_PRIORITY);
+ }
+
+ // Catching exceptions in multi-threaded processing
+ thread.setUncaughtExceptionHandler((thread1, ex) -> Log.i(TAG, "Running task appeared exception! Thread [" + thread1.getName() + "], because [" + ex.getMessage() + "]"));
+ return thread;
+ }
+}
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/utils/ErrorUtil.java b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/ErrorUtil.java
new file mode 100644
index 000000000..23e865bd1
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/ErrorUtil.java
@@ -0,0 +1,11 @@
+package io.agora.api.example.utils;
+
+import io.agora.api.component.Constant;
+import io.agora.rtc.Constants;
+import io.agora.rtc.RtcEngine;
+
+/**
+ * @author cjw
+ */
+public class ErrorUtil {
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/utils/TextUtils.java b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/TextUtils.java
new file mode 100644
index 000000000..0f8034b3a
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/TextUtils.java
@@ -0,0 +1,15 @@
+package io.agora.api.example.utils;
+
+public class TextUtils {
+ /**
+ * Print thread stack
+ */
+ public static String formatStackTrace(StackTraceElement[] stackTrace) {
+ StringBuilder sb = new StringBuilder();
+ for (StackTraceElement element : stackTrace) {
+ sb.append(" at ").append(element.toString());
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+}
diff --git a/Android/APIExample/app/src/main/java/io/agora/api/example/utils/YUVUtils.java b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/YUVUtils.java
new file mode 100644
index 000000000..41dd89583
--- /dev/null
+++ b/Android/APIExample/app/src/main/java/io/agora/api/example/utils/YUVUtils.java
@@ -0,0 +1,148 @@
+package io.agora.api.example.utils;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.ImageFormat;
+import android.graphics.Matrix;
+import android.graphics.Rect;
+import android.graphics.YuvImage;
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.RenderScript;
+import android.renderscript.ScriptIntrinsicBlur;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+public class YUVUtils {
+
+ public static void encodeI420(byte[] i420, int[] argb, int width, int height) {
+ final int frameSize = width * height;
+
+ int yIndex = 0; // Y start index
+ int uIndex = frameSize; // U statt index
+ int vIndex = frameSize * 5 / 4; // V start index: w*h*5/4
+
+ int a, R, G, B, Y, U, V;
+ int index = 0;
+ for (int j = 0; j < height; j++) {
+ for (int i = 0; i < width; i++) {
+ a = (argb[index] & 0xff000000) >> 24; // is not used obviously
+ R = (argb[index] & 0xff0000) >> 16;
+ G = (argb[index] & 0xff00) >> 8;
+ B = (argb[index] & 0xff) >> 0;
+
+ // well known RGB to YUV algorithm
+ Y = ((66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
+ U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
+ V = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
+
+ // I420(YUV420p) -> YYYYYYYY UU VV
+ i420[yIndex++] = (byte) ((Y < 0) ? 0 : ((Y > 255) ? 255 : Y));
+ if (j % 2 == 0 && i % 2 == 0) {
+ i420[uIndex++] = (byte) ((U < 0) ? 0 : ((U > 255) ? 255 : U));
+ i420[vIndex++] = (byte) ((V < 0) ? 0 : ((V > 255) ? 255 : V));
+ }
+ index++;
+ }
+ }
+ }
+
+ public static void encodeNV21(byte[] yuv420sp, int[] argb, int width, int height) {
+ final int frameSize = width * height;
+
+ int yIndex = 0;
+ int uvIndex = frameSize;
+
+ int a, R, G, B, Y, U, V;
+ int index = 0;
+ for (int j = 0; j < height; j++) {
+ for (int i = 0; i < width; i++) {
+ a = (argb[index] & 0xff000000) >> 24; // a is not used obviously
+ R = (argb[index] & 0xff0000) >> 16;
+ G = (argb[index] & 0xff00) >> 8;
+ B = (argb[index] & 0xff) >> 0;
+
+ // well known RGB to YUV algorithm
+ Y = ((66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
+ U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
+ V = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
+
+ // NV21 has a plane of Y and interleaved planes of VU each sampled by a factor of 2
+ // meaning for every 4 Y pixels there are 1 V and 1 U. Note the sampling is every other
+ // pixel AND every other scanline.
+ yuv420sp[yIndex++] = (byte) ((Y < 0) ? 0 : ((Y > 255) ? 255 : Y));
+ if (j % 2 == 0 && index % 2 == 0) {
+ yuv420sp[uvIndex++] = (byte) ((V < 0) ? 0 : ((V > 255) ? 255 : V));
+ yuv420sp[uvIndex++] = (byte) ((U < 0) ? 0 : ((U > 255) ? 255 : U));
+ }
+ index++;
+ }
+ }
+ }
+
+ public static void swapYU12toYUV420SP(byte[] yu12bytes, byte[] i420bytes, int width, int height, int yStride, int uStride, int vStride) {
+ System.arraycopy(yu12bytes, 0, i420bytes, 0, yStride * height);
+ int startPos = yStride * height;
+ int yv_start_pos_u = startPos;
+ int yv_start_pos_v = startPos + startPos / 4;
+ for (int i = 0; i < startPos / 4; i++) {
+ i420bytes[startPos + 2 * i + 0] = yu12bytes[yv_start_pos_v + i];
+ i420bytes[startPos + 2 * i + 1] = yu12bytes[yv_start_pos_u + i];
+ }
+ }
+
+ public static Bitmap i420ToBitmap(int width, int height, int rotation, int bufferLength, byte[] buffer, int yStride, int uStride, int vStride) {
+ byte[] NV21 = new byte[bufferLength];
+ swapYU12toYUV420SP(buffer, NV21, width, height, yStride, uStride, vStride);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ int[] strides = {yStride, yStride};
+ YuvImage image = new YuvImage(NV21, ImageFormat.NV21, width, height, strides);
+
+ image.compressToJpeg(
+ new Rect(0, 0, image.getWidth(), image.getHeight()),
+ 100, baos);
+
+ // rotate picture when saving to file
+ Matrix matrix = new Matrix();
+ matrix.postRotate(rotation);
+ byte[] bytes = baos.toByteArray();
+ try {
+ baos.close();
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
+ }
+
+ public static Bitmap blur(Context context, Bitmap image, float radius) {
+ RenderScript rs = RenderScript.create(context);
+ Bitmap outputBitmap = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888);
+ Allocation in = Allocation.createFromBitmap(rs, image);
+ Allocation out = Allocation.createFromBitmap(rs, outputBitmap);
+ ScriptIntrinsicBlur intrinsicBlur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
+ intrinsicBlur.setRadius(radius);
+ intrinsicBlur.setInput(in);
+ intrinsicBlur.forEach(out);
+
+ out.copyTo(outputBitmap);
+ image.recycle();
+ rs.destroy();
+
+ return outputBitmap;
+ }
+
+ public static byte[] bitmapToI420(int inputWidth, int inputHeight, Bitmap scaled) {
+ int[] argb = new int[inputWidth * inputHeight];
+ scaled.getPixels(argb, 0, inputWidth, 0, 0, inputWidth, inputHeight);
+ byte[] yuv = new byte[inputWidth * inputHeight * 3 / 2];
+ YUVUtils.encodeI420(yuv, argb, inputWidth, inputHeight);
+ scaled.recycle();
+ return yuv;
+ }
+
+}
diff --git a/Android/APIExample/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/Android/APIExample/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
new file mode 100644
index 000000000..2b068d114
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/drawable/ic_launcher_background.xml b/Android/APIExample/app/src/main/res/drawable/ic_launcher_background.xml
new file mode 100644
index 000000000..07d5da9cb
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/activity_example_layout.xml b/Android/APIExample/app/src/main/res/layout/activity_example_layout.xml
new file mode 100644
index 000000000..bac3666bb
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/activity_example_layout.xml
@@ -0,0 +1,9 @@
+
+
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/layout/activity_main.xml b/Android/APIExample/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 000000000..400fb109a
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/activity_setting_layout.xml b/Android/APIExample/app/src/main/res/layout/activity_setting_layout.xml
new file mode 100644
index 000000000..32c8b1362
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/activity_setting_layout.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_adjust_volume.xml b/Android/APIExample/app/src/main/res/layout/fragment_adjust_volume.xml
new file mode 100755
index 000000000..dd3238918
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_adjust_volume.xml
@@ -0,0 +1,132 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_channel_encryption.xml b/Android/APIExample/app/src/main/res/layout/fragment_channel_encryption.xml
new file mode 100644
index 000000000..01af00f57
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_channel_encryption.xml
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_custom_audiorecord.xml b/Android/APIExample/app/src/main/res/layout/fragment_custom_audiorecord.xml
new file mode 100644
index 000000000..2b5d101c0
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_custom_audiorecord.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_custom_remoterender.xml b/Android/APIExample/app/src/main/res/layout/fragment_custom_remoterender.xml
new file mode 100644
index 000000000..2d1ac930b
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_custom_remoterender.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_geo_fencing.xml b/Android/APIExample/app/src/main/res/layout/fragment_geo_fencing.xml
new file mode 100644
index 000000000..26d264a7d
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_geo_fencing.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_host_across_channel.xml b/Android/APIExample/app/src/main/res/layout/fragment_host_across_channel.xml
new file mode 100644
index 000000000..a71bcb175
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_host_across_channel.xml
@@ -0,0 +1,78 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_in_call_report.xml b/Android/APIExample/app/src/main/res/layout/fragment_in_call_report.xml
new file mode 100644
index 000000000..f2ef0b03f
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_in_call_report.xml
@@ -0,0 +1,93 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_join_multi_channel.xml b/Android/APIExample/app/src/main/res/layout/fragment_join_multi_channel.xml
new file mode 100644
index 000000000..51bc73fdb
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_join_multi_channel.xml
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_joinchannel_audio.xml b/Android/APIExample/app/src/main/res/layout/fragment_joinchannel_audio.xml
new file mode 100755
index 000000000..a3821212f
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_joinchannel_audio.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_joinchannel_video.xml b/Android/APIExample/app/src/main/res/layout/fragment_joinchannel_video.xml
new file mode 100644
index 000000000..88b8f29cb
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_joinchannel_video.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_main.xml b/Android/APIExample/app/src/main/res/layout/fragment_main.xml
new file mode 100644
index 000000000..6dc9c4382
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_main.xml
@@ -0,0 +1,14 @@
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_media_player_kit.xml b/Android/APIExample/app/src/main/res/layout/fragment_media_player_kit.xml
new file mode 100644
index 000000000..006410a4c
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_media_player_kit.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_play_audio_files.xml b/Android/APIExample/app/src/main/res/layout/fragment_play_audio_files.xml
new file mode 100644
index 000000000..bd2e1b5f1
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_play_audio_files.xml
@@ -0,0 +1,181 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_precall_test.xml b/Android/APIExample/app/src/main/res/layout/fragment_precall_test.xml
new file mode 100755
index 000000000..7c688fe61
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_precall_test.xml
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_process_rawdata.xml b/Android/APIExample/app/src/main/res/layout/fragment_process_rawdata.xml
new file mode 100644
index 000000000..fc51abf6b
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_process_rawdata.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_push_externalvideo.xml b/Android/APIExample/app/src/main/res/layout/fragment_push_externalvideo.xml
new file mode 100644
index 000000000..d2dcd58a3
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_push_externalvideo.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_quick_switch_channel.xml b/Android/APIExample/app/src/main/res/layout/fragment_quick_switch_channel.xml
new file mode 100644
index 000000000..ac5e60148
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_quick_switch_channel.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_ready_layout.xml b/Android/APIExample/app/src/main/res/layout/fragment_ready_layout.xml
new file mode 100644
index 000000000..5dd563107
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_ready_layout.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_rtmp_injection.xml b/Android/APIExample/app/src/main/res/layout/fragment_rtmp_injection.xml
new file mode 100644
index 000000000..4cb70ddcd
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_rtmp_injection.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_rtmp_streaming.xml b/Android/APIExample/app/src/main/res/layout/fragment_rtmp_streaming.xml
new file mode 100644
index 000000000..c9609db7b
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_rtmp_streaming.xml
@@ -0,0 +1,108 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_set_audio_profile.xml b/Android/APIExample/app/src/main/res/layout/fragment_set_audio_profile.xml
new file mode 100644
index 000000000..bd6781979
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_set_audio_profile.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_set_video_profile.xml b/Android/APIExample/app/src/main/res/layout/fragment_set_video_profile.xml
new file mode 100644
index 000000000..c5dc169c0
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_set_video_profile.xml
@@ -0,0 +1,87 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_stream_encrypt.xml b/Android/APIExample/app/src/main/res/layout/fragment_stream_encrypt.xml
new file mode 100644
index 000000000..2d1ac930b
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_stream_encrypt.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_super_resolution.xml b/Android/APIExample/app/src/main/res/layout/fragment_super_resolution.xml
new file mode 100644
index 000000000..06893e21e
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_super_resolution.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_switch_camera_screenshare.xml b/Android/APIExample/app/src/main/res/layout/fragment_switch_camera_screenshare.xml
new file mode 100644
index 000000000..32406e54e
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_switch_camera_screenshare.xml
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_switch_external_video.xml b/Android/APIExample/app/src/main/res/layout/fragment_switch_external_video.xml
new file mode 100644
index 000000000..a7961eadf
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_switch_external_video.xml
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_video_metadata.xml b/Android/APIExample/app/src/main/res/layout/fragment_video_metadata.xml
new file mode 100644
index 000000000..d3c785e43
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_video_metadata.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/fragment_voice_effects.xml b/Android/APIExample/app/src/main/res/layout/fragment_voice_effects.xml
new file mode 100644
index 000000000..d7c3e403c
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/fragment_voice_effects.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/layout_main_list_item.xml b/Android/APIExample/app/src/main/res/layout/layout_main_list_item.xml
new file mode 100644
index 000000000..b80e29520
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/layout_main_list_item.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/layout_main_list_section.xml b/Android/APIExample/app/src/main/res/layout/layout_main_list_section.xml
new file mode 100644
index 000000000..5060dded4
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/layout_main_list_section.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/popup_effect_options.xml b/Android/APIExample/app/src/main/res/layout/popup_effect_options.xml
new file mode 100644
index 000000000..ba4396d0e
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/popup_effect_options.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/layout/view_item_quickswitch.xml b/Android/APIExample/app/src/main/res/layout/view_item_quickswitch.xml
new file mode 100644
index 000000000..1bc3293df
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/layout/view_item_quickswitch.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/menu/menu_main_activity.xml b/Android/APIExample/app/src/main/res/menu/menu_main_activity.xml
new file mode 100644
index 000000000..314359087
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/menu/menu_main_activity.xml
@@ -0,0 +1,15 @@
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/Android/APIExample/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
new file mode 100644
index 000000000..eca70cfe5
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/Android/APIExample/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
new file mode 100644
index 000000000..eca70cfe5
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/mipmap-hdpi/ic_launcher.png b/Android/APIExample/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 000000000..a571e6009
Binary files /dev/null and b/Android/APIExample/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/Android/APIExample/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/Android/APIExample/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
new file mode 100644
index 000000000..61da551c5
Binary files /dev/null and b/Android/APIExample/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ
diff --git a/Android/APIExample/app/src/main/res/mipmap-mdpi/ic_launcher.png b/Android/APIExample/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 000000000..c41dd2853
Binary files /dev/null and b/Android/APIExample/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/Android/APIExample/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/Android/APIExample/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
new file mode 100644
index 000000000..db5080a75
Binary files /dev/null and b/Android/APIExample/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ
diff --git a/Android/APIExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/Android/APIExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..6dba46dab
Binary files /dev/null and b/Android/APIExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/Android/APIExample/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/Android/APIExample/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
new file mode 100644
index 000000000..da31a871c
Binary files /dev/null and b/Android/APIExample/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ
diff --git a/Android/APIExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/Android/APIExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..15ac68172
Binary files /dev/null and b/Android/APIExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/Android/APIExample/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/Android/APIExample/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
new file mode 100644
index 000000000..b216f2d31
Binary files /dev/null and b/Android/APIExample/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ
diff --git a/Android/APIExample/app/src/main/res/mipmap-xxhdpi/icon_setting.png b/Android/APIExample/app/src/main/res/mipmap-xxhdpi/icon_setting.png
new file mode 100644
index 000000000..b06b87d48
Binary files /dev/null and b/Android/APIExample/app/src/main/res/mipmap-xxhdpi/icon_setting.png differ
diff --git a/Android/APIExample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/Android/APIExample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 000000000..f25a41974
Binary files /dev/null and b/Android/APIExample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/Android/APIExample/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/Android/APIExample/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
new file mode 100644
index 000000000..e96783ccc
Binary files /dev/null and b/Android/APIExample/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ
diff --git a/Android/APIExample/app/src/main/res/navigation/nav_graph.xml b/Android/APIExample/app/src/main/res/navigation/nav_graph.xml
new file mode 100755
index 000000000..dd40ee376
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/navigation/nav_graph.xml
@@ -0,0 +1,209 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/values-zh/strings.xml b/Android/APIExample/app/src/main/res/values-zh/strings.xml
new file mode 100644
index 000000000..5a7908de9
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/values-zh/strings.xml
@@ -0,0 +1,109 @@
+
+
+ Agora API Example
+ 拉流
+ 停止拉流
+ 推流
+ 停止推流
+ 链接地址
+ 频道ID
+ 目标频道ID
+ 加密密钥
+ 加入
+ 打开模糊
+ 关闭模糊
+ 离开
+ 停止
+ 请授予权限
+ 听筒
+ 扬声器
+ 打开麦克风
+ 关闭超级分辨率
+ 关闭麦克风
+ 打开超级分辨率
+ 发送元数据
+ 请确保你已经按照QuickSwitchChannel类中的注释所说的那样建立频道,否则你将看到一片空白。
+ 等待主播中
+ 频道:%s
+ 你可以左右滑动切换频道
+ 请选择你的角色
+ 主播
+ 观众
+ 本地视频
+ 屏幕分享
+ 摄像头
+ 渲染模式:%s
+ 本地视频源不可用,请将MP4视频文件拷贝到 %s/ 并且命名为 localvideo.mp4.
+ 系统版本过低,无法使用此功能;请使用Android5.0的系统。
+
+
+ 设置
+ SDK版本
+ V%s
+ 已发送:%s
+ 接收到:%s
+ 关闭背景音乐
+ 开启背景音乐
+ 开启音效
+ 关闭音效
+ 混音音量
+ 码率
+ 确定
+ 3D人声
+ 电音
+ 3D音效环绕周期
+
+ 加入频道(纯音频)
+ 加入频道
+ 调整通话音量
+ 跨频道连麦
+ 通话前质量检测
+ 快速切换频道
+ 超级分辨率
+ 设置音频编码属性
+ 播放音频文件
+ 美声与音效
+ 媒体播放器组件
+ 区域访问限制
+ 加入多个频道
+ 旁路推流
+ 输入在线媒体流
+ 视频自采集(Push)
+ 视频自采集(MediaIO)/屏幕共享
+ 摄像头和屏幕共享切换
+ 音频自采集
+ 自定义渲染
+ 原始音视频数据
+ 插如视频元数据(SEI)
+ 自定义流媒体加密
+ 缺省媒体流加密
+ 设置视频编码属性
+ 通话中质量监测
+
+ 此示例演示了如何使用SDK加入频道进行纯语音通话的功能。
+ 此示例演示了如何使用SDK加入频道进行音视频通话的功能。
+ 此示例演示了如何使用SDK在频道中调整通话音量的功能。
+ 此示例演示了如何使用SDK在进入频道前检测网络质量状况。
+ 此示例演示了在语音通话过程中如何自采集音频帧并主动推送的功能。
+ 此示例演示了在音视频通话过程中如何自定义远端视频流渲染器的功能。
+ 此示例演示了在音视频通话过程中如何通过回调获取裸数据,以及在数据被处理后如何返回给SDK的功能。\nPS:裸数据包括视频帧和音频帧。
+ 此示例演示了在音视频通话过程中如何以主动Push的方式进行视频自采集的功能。
+ 此示例演示了在音视频通话过程中如何快速切换频道的功能。
+ 此示例演示了在音视频通话过程中如何加入多个频道功能。
+ 此示例演示了在音视频通话过程中如何输入在线媒体流并渲染的功能。
+ 此示例演示了在音视频通话过程中如何使用旁路推流的功能。\nPS:需要配合RTMP服务器实现功能。
+ 此示例演示了在音视频通话过程中如何进行音视频帧的加解密的方法。
+ 此示例演示了在音视频通话过程中如何以MediaIO的方式进行视频自采集和如何进行屏幕分享的功能。
+ 此示例演示了在音视频通话过程中,视频如何在摄像头流和屏幕分享流之间灵活切换。
+ 此示例演示了在音视频通话过程中如何伴随视频帧发送meta信息的方法。
+ 此示例演示了在音视频通话过程中如何通过AreaCode指定SDK访问限制。
+ 此示例演示了在音视频通话过程中如何通过setAudioProfile设置profile和scenario来适配最佳音频性能。
+ 此示例演示了在音视频通话过程中播放并管理audio effect和audio mixing文件。
+ 此示例演示了在音视频通话过程中如何使用API提供的一些人声效果,或使用API自行组合出想要的人声效果。
+ 此示例演示了在音视频通话过程中如何集成和使用Agora SDK的媒体播放器组件。
+ 此示例演示了在音视频通话过程中如何通过回调获取当前通话质量。>
+ 此示例演示了在音视频通话过程中如何将A频道的主播流转发到B频道,实现主播PK。
+ 此示例演示了在音视频通话过程中如何进行音视频帧的加解密的方法。
+ 此示例演示了在音视频通话过程中如何通过VideoEncoderConfiguration来适配最佳视频性能。
+ 此示例演示了在音视频通话过程中如何使用超级分辨率接口显著提升远端视频显示效果。
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/values/arrays.xml b/Android/APIExample/app/src/main/res/values/arrays.xml
new file mode 100644
index 000000000..c6c6cddd4
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/values/arrays.xml
@@ -0,0 +1,117 @@
+
+
+
+ DEFAULT
+ SPEECH_STANDARD
+ MUSIC_STANDARD
+ MUSIC_STANDARD_STEREO
+ MUSIC_HIGH_QUALITY
+ MUSIC_HIGH_QUALITY_STEREO
+
+
+ DEFAULT
+ CHATROOM_ENTERTAINMENT
+ EDUCATION
+ GAME_STREAMING
+ SHOWROOM
+ CHATROOM_GAMING
+
+
+ GLOBAL
+ CN
+ NA
+ EU
+ AS
+ JP
+ IN
+
+
+ ROOM_ACOUSTICS_KTV
+ ROOM_ACOUSTICS_VOCAL_CONCERT
+ ROOM_ACOUSTICS_STUDIO
+ ROOM_ACOUSTICS_PHONOGRAPH
+ ROOM_ACOUSTICS_VIRTUAL_STEREO
+ ROOM_ACOUSTICS_SPACIAL
+ ROOM_ACOUSTICS_ETHEREAL
+ ROOM_ACOUSTICS_3D_VOICE
+ VOICE_CHANGER_EFFECT_UNCLE
+ VOICE_CHANGER_EFFECT_OLDMAN
+ VOICE_CHANGER_EFFECT_BOY
+ VOICE_CHANGER_EFFECT_SISTER
+ VOICE_CHANGER_EFFECT_GIRL
+ VOICE_CHANGER_EFFECT_PIGKING
+ VOICE_CHANGER_EFFECT_HULK
+ STYLE_TRANSFORMATION_RNB
+ STYLE_TRANSFORMATION_POPULAR
+ PITCH_CORRECTION
+
+
+ CHAT_BEAUTIFIER_MAGNETIC
+ CHAT_BEAUTIFIER_FRESH
+ CHAT_BEAUTIFIER_VITALITY
+ TIMBRE_TRANSFORMATION_VIGOROUS
+ TIMBRE_TRANSFORMATION_DEEP
+ TIMBRE_TRANSFORMATION_MELLOW
+ TIMBRE_TRANSFORMATION_FALSETTO
+ TIMBRE_TRANSFORMATION_FULL
+ TIMBRE_TRANSFORMATION_CLEAR
+ TIMBRE_TRANSFORMATION_RESOUNDING
+ TIMBRE_TRANSFORMATION_RINGING
+
+
+ Natural Major
+ Natural Minor
+ Breeze Minor
+
+
+ A Pitch
+ A# Pitch
+ B Pitch
+ C Pitch
+ C# Pitch
+ D Pitch
+ D# Pitch
+ E Pitch
+ F Pitch
+ F# Pitch
+ G Pitch
+ G# Pitch
+
+
+ AES_128_XTS
+ AES_128_ECB
+ AES_256_XTS
+ SM4_128_ECB
+
+
+ VD_120x120
+ VD_160x120
+ VD_180x180
+ VD_240x180
+ VD_320x180
+ VD_240x240
+ VD_320x240
+ VD_424x240
+ VD_360x360
+ VD_480x360
+ VD_640x360
+ VD_480x480
+ VD_640x480
+ VD_840x480
+ VD_960x720
+ VD_1280x720
+
+
+ ORIENTATION_MODE_ADAPTIVE
+ ORIENTATION_MODE_FIXED_LANDSCAPE
+ ORIENTATION_MODE_FIXED_PORTRAIT
+
+
+ FRAME_RATE_FPS_1
+ FRAME_RATE_FPS_7
+ FRAME_RATE_FPS_10
+ FRAME_RATE_FPS_15
+ FRAME_RATE_FPS_24
+ FRAME_RATE_FPS_30
+
+
\ No newline at end of file
diff --git a/Android/APIExample/app/src/main/res/values/colors.xml b/Android/APIExample/app/src/main/res/values/colors.xml
new file mode 100644
index 000000000..030098fe0
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/values/colors.xml
@@ -0,0 +1,6 @@
+
+
+ #6200EE
+ #3700B3
+ #03DAC5
+
diff --git a/Android/APIExample/app/src/main/res/values/dimens.xml b/Android/APIExample/app/src/main/res/values/dimens.xml
new file mode 100644
index 000000000..29260009d
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/values/dimens.xml
@@ -0,0 +1,4 @@
+
+
+ 16dp
+
diff --git a/Android/APIExample/app/src/main/res/values/string_configs.xml b/Android/APIExample/app/src/main/res/values/string_configs.xml
new file mode 100644
index 000000000..c5804b299
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/values/string_configs.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/main/res/values/strings.xml b/Android/APIExample/app/src/main/res/values/strings.xml
new file mode 100644
index 000000000..31fea3bf6
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/values/strings.xml
@@ -0,0 +1,112 @@
+
+ Agora API Example
+ Inject
+ StopInject
+ Publish
+ StopPublish
+ Url
+ Channel ID
+ Destination Channel ID
+ Encryption Password
+ Join
+ Open Blur
+ Close Blur
+ Leave
+ Stop
+ Please granted the request permissions
+ Earpiece
+ Speaker
+ OpenMicrophone
+ CloseMicrophone
+ Close Super Resolution
+ Open Super Resolution
+ Send Metadata
+ Make sure you have set up the channel as the comments in the QuickSwitchChannel class say, or you will see a blank.
+ Waiting for the broadcaster
+ Channel:%s
+ You can swipe left and right to switch channels
+ Please choose your role
+ BROADCASTER
+ AUDIENCE
+ LocalVideo
+ ScreenShare
+ Camera
+ RenderMode:%s
+ Local video share will not be accessible.\n Please copy your MP4 video file to %s and change the name as localvideo.mp4.
+ The system version is too low to use this feature; please use Android 5.0 System.
+
+ qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890 !#$%()+-:;<=.>?@[]^_{}|~,&
+
+ Fit
+ Hidden
+
+ Setting
+ SDK Version
+ V%s
+ Sent:%s
+ Received:%s
+ BGM OFF
+ BGM ON
+ Effect ON
+ Effect OFF
+ Mixing Volume
+ Bitrate
+ OK
+ 3D Voice
+ Pitch Correction
+ 3D Voice Circle in Second
+
+ Join Channel Audio
+ Join Channel Video
+ Quick Switch Channel
+ Adjust In Call Volume
+ Join Multiple Channel
+ Precall Tests
+ Co-hosting Across Channel
+ Set the Audio Profile
+ Play Audio Files
+ Set the Voice Beautifier and Effects
+ MediaPlayer Kit
+ Geo Fencing
+ RTMP Streaming
+ Inject Online Media Stream
+ Custom Video Source(Push)
+ Custom Video Source(MediaIO)/Screen Share
+ Switch Camera and Screen Share
+ Custom Audio Source
+ Custom Video Renderer
+ Raw Video/Audio Data
+ Video Metadata(SEI)
+ Custom Stream Encryption
+ Channel Encryption
+ Set the Video Profile
+ In Call Stats
+ Super Resolution
+
+ This example demonstrates how to use the SDK to join channels for voice only calls.
+ This example demonstrates how to use the SDK to join channels for audio and video calls.
+ This example demonstrates how to use the SDK to adjust in cal volume.
+ This example demonstrates how to use the SDK to check uplink network condition before joining the channel.
+ This example demonstrates how to automatically collect audio frames and actively push them during a voice call.
+ This example demonstrates how to customize the functions of the remote video stream renderer during audio and video calls.
+ This example demonstrates how to obtain raw data through callback during audio and video calls, and how to return the data to the SDK after processing.\nPS:Bare data includes video frames and audio frames
+ This example demonstrates how to use the active push mode to collect video during audio and video calls.
+ This example demonstrates how to quickly switch channels during audio and video calls.
+ This example demonstrates how to join multiple channels during audio and video calls.
+ This example demonstrates how to input and render an online media stream during an audio and video call.
+ This example demonstrates how to use the bypass streaming function during an audio and video call.\nPS:Need to cooperate with RTMP server to realize the function.
+ This example demonstrates how to encrypt and decrypt audio and video frames during audio and video calls.
+ This example demonstrates how to use MediaIO to collect video and share screen during audio and video call.
+ This example demonstrates how video can be flexibly switched between the camera stream and the screen share stream during an audio-video call.
+ This example demonstrates how to send meta information along with video frames during audio and video calls.
+ This example demonstrates how to use Area Code to enable SDK geographical fencing feature.
+ This example demonstrates how to use audio profile and audio scenario to adjust audio configurations.
+ This example demonstrates how to play and manage audio effect and audio mixing files.
+ This example demonstrates how to use embedded audio effects in SDK.
+ This example demonstrates how to use MediaPlayer Kit. It is one of components for Agora SDK.
+ This example demonstrates how to display in call statistics.
+ This example demonstrates how to transfer media streaming to another rtc channel.
+ This example demonstrates how to encrypt and decrypt audio and video frames during audio and video calls.
+ This example demonstrates how to use VideoEncoderConfiguration to adjust video configurations.
+ This example demonstrates how to use the SDK to display remote video in super resolution.
+
diff --git a/Android/APIExample/app/src/main/res/values/styles.xml b/Android/APIExample/app/src/main/res/values/styles.xml
new file mode 100644
index 000000000..5885930df
--- /dev/null
+++ b/Android/APIExample/app/src/main/res/values/styles.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
diff --git a/Android/APIExample/app/src/test/java/io/agora/api/example/ExampleUnitTest.java b/Android/APIExample/app/src/test/java/io/agora/api/example/ExampleUnitTest.java
new file mode 100644
index 000000000..c297ae4cf
--- /dev/null
+++ b/Android/APIExample/app/src/test/java/io/agora/api/example/ExampleUnitTest.java
@@ -0,0 +1,17 @@
+package io.agora.api.example;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see Testing documentation
+ */
+public class ExampleUnitTest {
+ @Test
+ public void addition_isCorrect() {
+ assertEquals(4, 2 + 2);
+ }
+}
\ No newline at end of file
diff --git a/Android/APIExample/build.gradle b/Android/APIExample/build.gradle
new file mode 100644
index 000000000..fe391e839
--- /dev/null
+++ b/Android/APIExample/build.gradle
@@ -0,0 +1,30 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ mavenCentral()
+ google()
+ jcenter()
+
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:3.4.2'
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+
+ classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0-alpha06"
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ google()
+ jcenter()
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
diff --git a/Android/APIExample/ci.env.py b/Android/APIExample/ci.env.py
new file mode 100644
index 000000000..c02174716
--- /dev/null
+++ b/Android/APIExample/ci.env.py
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+# -*- coding: UTF-8 -*-
+import re
+import os
+
+def main():
+ appId = ""
+ if "AGORA_APP_ID" in os.environ:
+ appId = os.environ["AGORA_APP_ID"]
+ token = ""
+
+ f = open("./app/src/main/res/values/string_configs.xml", 'r+')
+ content = f.read()
+ contentNew = re.sub(r'YOUR APP ID', appId, content)
+ contentNew = re.sub(r'YOUR ACCESS TOKEN', token, contentNew)
+ f.seek(0)
+ f.write(contentNew)
+ f.truncate()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/Android/APIExample/gradle.properties b/Android/APIExample/gradle.properties
new file mode 100644
index 000000000..199d16ede
--- /dev/null
+++ b/Android/APIExample/gradle.properties
@@ -0,0 +1,20 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx1536m
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+# AndroidX package structure to make it clearer which packages are bundled with the
+# Android operating system, and which are packaged with your app's APK
+# https://developer.android.com/topic/libraries/support-library/androidx-rn
+android.useAndroidX=true
+# Automatically convert third-party libraries to use AndroidX
+android.enableJetifier=true
+
diff --git a/Android/APIExample/gradle/wrapper/gradle-wrapper.jar b/Android/APIExample/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..f6b961fd5
Binary files /dev/null and b/Android/APIExample/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/Android/APIExample/gradle/wrapper/gradle-wrapper.properties b/Android/APIExample/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..ce54223f7
--- /dev/null
+++ b/Android/APIExample/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Thu May 28 16:45:32 CST 2020
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
diff --git a/Android/APIExample/gradlew b/Android/APIExample/gradlew
new file mode 100644
index 000000000..cccdd3d51
--- /dev/null
+++ b/Android/APIExample/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/Android/APIExample/gradlew.bat b/Android/APIExample/gradlew.bat
new file mode 100644
index 000000000..f9553162f
--- /dev/null
+++ b/Android/APIExample/gradlew.bat
@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/Android/APIExample/lib-component/.gitignore b/Android/APIExample/lib-component/.gitignore
new file mode 100644
index 000000000..0d4bafd52
--- /dev/null
+++ b/Android/APIExample/lib-component/.gitignore
@@ -0,0 +1,17 @@
+*.iml
+.gradle
+/local.properties
+/.idea
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+.DS_Store
+/build
+/captures
+.externalNativeBuild
+.cxx
+androidTest/
+Test/
diff --git a/Android/APIExample/lib-component/build.gradle b/Android/APIExample/lib-component/build.gradle
new file mode 100644
index 000000000..8b7ca55ca
--- /dev/null
+++ b/Android/APIExample/lib-component/build.gradle
@@ -0,0 +1,41 @@
+apply plugin: 'com.android.library'
+
+android {
+ compileSdkVersion 29
+ buildToolsVersion "29.0.3"
+
+ defaultConfig {
+ minSdkVersion 19
+ targetSdkVersion 29
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ consumerProguardFiles 'consumer-rules.pro'
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+
+ implementation 'androidx.appcompat:appcompat:1.1.0'
+ testImplementation 'junit:junit:4.12'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+
+
+// api 'io.agora.rtc:full-sdk:2.9.0.104'
+// api 'io.agora.rtc:full-sdk:3.0.0'
+// api 'io.agora.rtc:full-sdk:3.1.2'
+
+ api 'io.agora.rtc:full-sdk:3.1.2'
+ api 'io.agora:agoraplayer:1.1.2'
+
+}
diff --git a/Android/APIExample/lib-component/consumer-rules.pro b/Android/APIExample/lib-component/consumer-rules.pro
new file mode 100644
index 000000000..e69de29bb
diff --git a/Android/APIExample/lib-component/proguard-rules.pro b/Android/APIExample/lib-component/proguard-rules.pro
new file mode 100644
index 000000000..f1b424510
--- /dev/null
+++ b/Android/APIExample/lib-component/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/Android/APIExample/lib-component/src/main/AndroidManifest.xml b/Android/APIExample/lib-component/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..d8659af65
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/AndroidManifest.xml
@@ -0,0 +1,2 @@
+
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/Constant.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/Constant.java
new file mode 100644
index 000000000..510bf84c1
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/Constant.java
@@ -0,0 +1,19 @@
+package io.agora.api.component;
+
+import android.view.TextureView;
+
+import io.agora.rtc.RtcEngine;
+
+public class Constant {
+ public static TextureView TEXTUREVIEW;
+
+ public static RtcEngine ENGINE;
+
+ public static String TIPS = "tips";
+
+ public static String DATA = "data";
+
+ public static final String MIX_FILE_PATH = "/assets/music_1.m4a";
+
+ public static final String EFFECT_FILE_PATH = "/assets/effectA.wav";
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/Drawable2dFull.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/Drawable2dFull.java
new file mode 100644
index 000000000..fab05fc70
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/Drawable2dFull.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2014 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.agora.api.component.gles;
+
+
+import io.agora.api.component.gles.core.Drawable2d;
+
+/**
+ * Base class for stuff we like to draw.
+ */
+public class Drawable2dFull extends Drawable2d {
+
+ /**
+ * A "full" square, extending from -1 to +1 in both dimensions. When the model/view/projection
+ * matrix is identity, this will exactly cover the viewport.
+ *
+ * The texture coordinates are Y-inverted relative to RECTANGLE. (This seems to work out
+ * right with external textures from SurfaceTexture.)
+ */
+ private static final float FULL_RECTANGLE_COORDS[] = {
+ -1.0f, -1.0f, // 0 bottom left
+ 1.0f, -1.0f, // 1 bottom right
+ -1.0f, 1.0f, // 2 top left
+ 1.0f, 1.0f, // 3 top right
+ };
+ private static final float FULL_RECTANGLE_TEX_COORDS[] = {
+ 0.0f, 0.0f, // 0 bottom left
+ 1.0f, 0.0f, // 1 bottom right
+ 0.0f, 1.0f, // 2 top left
+ 1.0f, 1.0f // 3 top right
+ };
+
+ public Drawable2dFull() {
+ super(FULL_RECTANGLE_COORDS, FULL_RECTANGLE_TEX_COORDS);
+ }
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/Drawable2dLandmarks.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/Drawable2dLandmarks.java
new file mode 100644
index 000000000..539f7809e
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/Drawable2dLandmarks.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2014 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.agora.api.component.gles;
+
+
+import io.agora.api.component.gles.core.Drawable2d;
+
+/**
+ * Base class for stuff we like to draw.
+ */
+public class Drawable2dLandmarks extends Drawable2d {
+
+
+ private float pointsCoords[] = new float[150];
+
+ public Drawable2dLandmarks() {
+ updateVertexArray(pointsCoords);
+ }
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/ProgramLandmarks.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/ProgramLandmarks.java
new file mode 100644
index 000000000..a2fef5d63
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/ProgramLandmarks.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.agora.api.component.gles;
+
+import android.hardware.Camera;
+import android.opengl.GLES20;
+import android.opengl.Matrix;
+
+import java.util.Arrays;
+
+import io.agora.api.component.gles.core.Drawable2d;
+import io.agora.api.component.gles.core.GlUtil;
+import io.agora.api.component.gles.core.Program;
+
+
+public class ProgramLandmarks extends Program {
+
+ private static final String vertexShaderCode =
+ // This matrix member variable provides a hook to manipulate
+ // the coordinates of the objects that use this vertex shader
+ "uniform mat4 uMVPMatrix;" +
+ "attribute vec4 vPosition;" +
+ "uniform float uPointSize;" +
+ "void main() {" +
+ // the matrix must be included as a modifier of gl_Position
+ // Note that the uMVPMatrix factor *must be first* in order
+ // for the matrix multiplication product to be correct.
+ " gl_Position = uMVPMatrix * vPosition;" +
+ " gl_PointSize = uPointSize;" +
+ "}";
+
+ private static final String fragmentShaderCode =
+ "precision mediump float;" +
+ "uniform vec4 vColor;" +
+ "void main() {" +
+ " gl_FragColor = vColor;" +
+ "}";
+
+ private static final float color[] = {0.63671875f, 0.76953125f, 0.22265625f, 1.0f};
+
+ private int mPositionHandle;
+ private int mColorHandle;
+ private int mMVPMatrixHandle;
+ private int mPointSizeHandle;
+
+ private float mPointSize = 6.0f;
+
+ public ProgramLandmarks() {
+ super(vertexShaderCode, fragmentShaderCode);
+ }
+
+ @Override
+ protected Drawable2d getDrawable2d() {
+ return new Drawable2dLandmarks();
+ }
+
+ @Override
+ protected void getLocations() {
+ // get handle to vertex shader's vPosition member
+ mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "vPosition");
+ GlUtil.checkGlError("vPosition");
+ // get handle to fragment shader's vColor member
+ mColorHandle = GLES20.glGetUniformLocation(mProgramHandle, "vColor");
+ GlUtil.checkGlError("vColor");
+ // get handle to shape's transformation matrix
+ mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "uMVPMatrix");
+ GlUtil.checkGlError("glGetUniformLocation");
+ mPointSizeHandle = GLES20.glGetUniformLocation(mProgramHandle, "uPointSize");
+ GlUtil.checkGlError("uPointSize");
+ }
+
+ @Override
+ public void drawFrame(int textureId, float[] texMatrix, float[] mvpMatrix) {
+ // Add program to OpenGL environment
+ GLES20.glUseProgram(mProgramHandle);
+
+ // Enable a handle to the triangle vertices
+ GLES20.glEnableVertexAttribArray(mPositionHandle);
+
+ // Prepare the triangle coordinate data
+ GLES20.glVertexAttribPointer(
+ mPositionHandle, Drawable2d.COORDS_PER_VERTEX,
+ GLES20.GL_FLOAT, false,
+ Drawable2d.VERTEXTURE_STRIDE, mDrawable2d.vertexArray());
+
+ // Set color for drawing the triangle
+ GLES20.glUniform4fv(mColorHandle, 1, color, 0);
+
+ // Apply the projection and view transformation
+ GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMtx, 0);
+
+ GLES20.glUniform1f(mPointSizeHandle, mPointSize);
+
+ // Draw the triangle
+ GLES20.glDrawArrays(GLES20.GL_POINTS, 0, mDrawable2d.vertexCount());
+
+ // Disable vertex array
+ GLES20.glDisableVertexAttribArray(mPositionHandle);
+ }
+
+ public void drawFrame(int x, int y, int width, int height) {
+ drawFrame(0, null, null, x, y, width, height);
+ }
+
+ private final float[] mvpMtx = new float[16];
+ private int mCameraType;
+ private int mOrientation;
+ private int mWidth;
+ private int mHeight;
+
+ public void refresh(float[] landmarksData, int width, int height, int orientation, int cameraType) {
+ if (mWidth != width || mHeight != height || mOrientation != orientation || mCameraType != cameraType) {
+ float[] orthoMtx = new float[16];
+ float[] rotateMtx = new float[16];
+ Matrix.orthoM(orthoMtx, 0, 0, width, 0, height, -1, 1);
+ Matrix.setRotateM(rotateMtx, 0, 360 - orientation, 0.0f, 0.0f, 1.0f);
+ if (cameraType == Camera.CameraInfo.CAMERA_FACING_BACK) {
+ Matrix.rotateM(rotateMtx, 0, 180, 1.0f, 0.0f, 0.0f);
+ }
+ Matrix.multiplyMM(mvpMtx, 0, rotateMtx, 0, orthoMtx, 0);
+
+ mWidth = width;
+ mHeight = height;
+ mOrientation = orientation;
+ mCameraType = cameraType;
+ }
+
+ updateVertexArray(Arrays.copyOf(landmarksData, landmarksData.length));
+ }
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/ProgramTexture2d.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/ProgramTexture2d.java
new file mode 100644
index 000000000..7bd8d34a9
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/ProgramTexture2d.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2014 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.agora.api.component.gles;
+
+import android.opengl.GLES20;
+
+import io.agora.api.component.gles.core.Drawable2d;
+import io.agora.api.component.gles.core.GlUtil;
+import io.agora.api.component.gles.core.Program;
+
+
+public class ProgramTexture2d extends Program {
+
+ // Simple vertex shader, used for all programs.
+ private static final String VERTEX_SHADER =
+ "uniform mat4 uMVPMatrix;\n" +
+ "uniform mat4 uTexMatrix;\n" +
+ "attribute vec4 aPosition;\n" +
+ "attribute vec4 aTextureCoord;\n" +
+ "varying vec2 vTextureCoord;\n" +
+ "void main() {\n" +
+ " gl_Position = uMVPMatrix * aPosition;\n" +
+ " vTextureCoord = (uTexMatrix * aTextureCoord).xy;\n" +
+ "}\n";
+
+ // Simple fragment shader for use with "normal" 2D textures.
+ private static final String FRAGMENT_SHADER_2D =
+ "precision mediump float;\n" +
+ "varying vec2 vTextureCoord;\n" +
+ "uniform sampler2D sTexture;\n" +
+ "void main() {\n" +
+ " gl_FragColor = vec4(texture2D(sTexture, vTextureCoord).rgb, 1.0);\n" +
+ "}\n";
+
+ private int muMVPMatrixLoc;
+ private int muTexMatrixLoc;
+ private int maPositionLoc;
+ private int maTextureCoordLoc;
+
+ public ProgramTexture2d() {
+ super(VERTEX_SHADER, FRAGMENT_SHADER_2D);
+ }
+
+ @Override
+ protected Drawable2d getDrawable2d() {
+ return new Drawable2dFull();
+ }
+
+ @Override
+ protected void getLocations() {
+ maPositionLoc = GLES20.glGetAttribLocation(mProgramHandle, "aPosition");
+ GlUtil.checkLocation(maPositionLoc, "aPosition");
+ maTextureCoordLoc = GLES20.glGetAttribLocation(mProgramHandle, "aTextureCoord");
+ GlUtil.checkLocation(maTextureCoordLoc, "aTextureCoord");
+ muMVPMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uMVPMatrix");
+ GlUtil.checkLocation(muMVPMatrixLoc, "uMVPMatrix");
+ muTexMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexMatrix");
+ GlUtil.checkLocation(muTexMatrixLoc, "uTexMatrix");
+ }
+
+ @Override
+ public void drawFrame(int textureId, float[] texMatrix, float[] mvpMatrix) {
+ GlUtil.checkGlError("draw start");
+
+ // Select the program.
+ GLES20.glUseProgram(mProgramHandle);
+ GlUtil.checkGlError("glUseProgram");
+
+ // Set the texture.
+ GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
+
+ // Copy the model / view / projection matrix over.
+ GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
+ GlUtil.checkGlError("glUniformMatrix4fv");
+
+ // Copy the texture transformation matrix over.
+ GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);
+ GlUtil.checkGlError("glUniformMatrix4fv");
+
+ // Enable the "aPosition" vertex attribute.
+ GLES20.glEnableVertexAttribArray(maPositionLoc);
+ GlUtil.checkGlError("glEnableVertexAttribArray");
+
+ // Connect vertexBuffer to "aPosition".
+ GLES20.glVertexAttribPointer(maPositionLoc, Drawable2d.COORDS_PER_VERTEX,
+ GLES20.GL_FLOAT, false, Drawable2d.VERTEXTURE_STRIDE, mDrawable2d.vertexArray());
+ GlUtil.checkGlError("glVertexAttribPointer");
+
+ // Enable the "aTextureCoord" vertex attribute.
+ GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
+ GlUtil.checkGlError("glEnableVertexAttribArray");
+
+ // Connect texBuffer to "aTextureCoord".
+ GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
+ GLES20.GL_FLOAT, false, Drawable2d.TEXTURE_COORD_STRIDE, mDrawable2d.texCoordArray());
+ GlUtil.checkGlError("glVertexAttribPointer");
+
+ // Draw the rect.
+ GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mDrawable2d.vertexCount());
+ GlUtil.checkGlError("glDrawArrays");
+
+ // Done -- disable vertex array, texture, and program.
+ GLES20.glDisableVertexAttribArray(maPositionLoc);
+ GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
+ GLES20.glUseProgram(0);
+ }
+
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/ProgramTextureOES.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/ProgramTextureOES.java
new file mode 100644
index 000000000..4a77467f3
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/ProgramTextureOES.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2014 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.agora.api.component.gles;
+
+import android.opengl.GLES11Ext;
+import android.opengl.GLES20;
+
+import io.agora.api.component.gles.core.Drawable2d;
+import io.agora.api.component.gles.core.GlUtil;
+import io.agora.api.component.gles.core.Program;
+
+
+public class ProgramTextureOES extends Program {
+
+ // Simple vertex shader, used for all programs.
+ private static final String VERTEX_SHADER =
+ "uniform mat4 uMVPMatrix;\n" +
+ "uniform mat4 uTexMatrix;\n" +
+ "attribute vec4 aPosition;\n" +
+ "attribute vec4 aTextureCoord;\n" +
+ "varying vec2 vTextureCoord;\n" +
+ "void main() {\n" +
+ " gl_Position = uMVPMatrix * aPosition;\n" +
+ " vTextureCoord = (uTexMatrix * aTextureCoord).xy;\n" +
+ "}\n";
+
+ // Simple fragment shader for use with external 2D textures (e.g. what we get from
+ // SurfaceTexture).
+ private static final String FRAGMENT_SHADER_EXT =
+ "#extension GL_OES_EGL_image_external : require\n" +
+ "precision mediump float;\n" +
+ "varying vec2 vTextureCoord;\n" +
+ "uniform samplerExternalOES sTexture;\n" +
+ "void main() {\n" +
+ " gl_FragColor = texture2D(sTexture, vTextureCoord);\n" +
+ "}\n";
+
+ private int muMVPMatrixLoc;
+ private int muTexMatrixLoc;
+ private int maPositionLoc;
+ private int maTextureCoordLoc;
+
+ /**
+ * Prepares the program in the current EGL context.
+ */
+ public ProgramTextureOES() {
+ super(VERTEX_SHADER, FRAGMENT_SHADER_EXT);
+ }
+
+ @Override
+ protected Drawable2d getDrawable2d() {
+ return new Drawable2dFull();
+ }
+
+ @Override
+ protected void getLocations() {
+ maPositionLoc = GLES20.glGetAttribLocation(mProgramHandle, "aPosition");
+ GlUtil.checkLocation(maPositionLoc, "aPosition");
+ maTextureCoordLoc = GLES20.glGetAttribLocation(mProgramHandle, "aTextureCoord");
+ GlUtil.checkLocation(maTextureCoordLoc, "aTextureCoord");
+ muMVPMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uMVPMatrix");
+ GlUtil.checkLocation(muMVPMatrixLoc, "uMVPMatrix");
+ muTexMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexMatrix");
+ GlUtil.checkLocation(muTexMatrixLoc, "uTexMatrix");
+ }
+
+ @Override
+ public void drawFrame(int textureId, float[] texMatrix, float[] mvpMatrix) {
+ GlUtil.checkGlError("draw start");
+
+ // Select the program.
+ GLES20.glUseProgram(mProgramHandle);
+ GlUtil.checkGlError("glUseProgram");
+
+ // Set the texture.
+ GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
+ GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId);
+
+ // Copy the model / view / projection matrix over.
+ GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);
+ GlUtil.checkGlError("glUniformMatrix4fv");
+
+ // Copy the texture transformation matrix over.
+ GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);
+ GlUtil.checkGlError("glUniformMatrix4fv");
+
+ // Enable the "aPosition" vertex attribute.
+ GLES20.glEnableVertexAttribArray(maPositionLoc);
+ GlUtil.checkGlError("glEnableVertexAttribArray");
+
+ // Connect vertexBuffer to "aPosition".
+ GLES20.glVertexAttribPointer(maPositionLoc, Drawable2d.COORDS_PER_VERTEX,
+ GLES20.GL_FLOAT, false, Drawable2d.VERTEXTURE_STRIDE, mDrawable2d.vertexArray());
+ GlUtil.checkGlError("glVertexAttribPointer");
+
+ // Enable the "aTextureCoord" vertex attribute.
+ GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
+ GlUtil.checkGlError("glEnableVertexAttribArray");
+
+ // Connect texBuffer to "aTextureCoord".
+ GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
+ GLES20.GL_FLOAT, false, Drawable2d.TEXTURE_COORD_STRIDE, mDrawable2d.texCoordArray());
+ GlUtil.checkGlError("glVertexAttribPointer");
+
+ // Draw the rect.
+ GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mDrawable2d.vertexCount());
+ GlUtil.checkGlError("glDrawArrays");
+
+ // Done -- disable vertex array, texture, and program.
+ GLES20.glDisableVertexAttribArray(maPositionLoc);
+ GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
+ GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
+ GLES20.glUseProgram(0);
+ }
+
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/Drawable2d.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/Drawable2d.java
new file mode 100644
index 000000000..69a383375
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/Drawable2d.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2014 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.agora.api.component.gles.core;
+
+import java.nio.FloatBuffer;
+
+/**
+ * Base class for stuff we like to draw.
+ */
+public class Drawable2d {
+
+ public static final int SIZEOF_FLOAT = 4;
+ public static final int COORDS_PER_VERTEX = 2;
+ public static final int TEXTURE_COORD_STRIDE = 2 * SIZEOF_FLOAT;
+ public static final int VERTEXTURE_STRIDE = COORDS_PER_VERTEX * SIZEOF_FLOAT;
+
+ private FloatBuffer mTexCoordArray;
+ private FloatBuffer mVertexArray;
+ private int mVertexCount;
+
+ public Drawable2d() {
+ }
+
+ /**
+ * Prepares a drawable from a "pre-fabricated" shape definition.
+ *
+ * Does no EGL/GL operations, so this can be done at any time.
+ */
+ public Drawable2d(float[] FULL_RECTANGLE_COORDS, float[] FULL_RECTANGLE_TEX_COORDS) {
+ updateVertexArray(FULL_RECTANGLE_COORDS);
+ updateTexCoordArray(FULL_RECTANGLE_TEX_COORDS);
+ }
+
+ public void updateVertexArray(float[] FULL_RECTANGLE_COORDS) {
+ mVertexArray = GlUtil.createFloatBuffer(FULL_RECTANGLE_COORDS);
+ mVertexCount = FULL_RECTANGLE_COORDS.length / COORDS_PER_VERTEX;
+ }
+
+ public void updateTexCoordArray(float[] FULL_RECTANGLE_TEX_COORDS) {
+ mTexCoordArray = GlUtil.createFloatBuffer(FULL_RECTANGLE_TEX_COORDS);
+ }
+
+ /**
+ * Returns the array of vertices.
+ *
+ * To avoid allocations, this returns internal state. The caller must not modify it.
+ */
+ public FloatBuffer vertexArray() {
+ return mVertexArray;
+ }
+
+ /**
+ * Returns the array of texture coordinates.
+ *
+ * To avoid allocations, this returns internal state. The caller must not modify it.
+ */
+ public FloatBuffer texCoordArray() {
+ return mTexCoordArray;
+ }
+
+ /**
+ * Returns the number of vertices stored in the vertex array.
+ */
+ public int vertexCount() {
+ return mVertexCount;
+ }
+
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/EglCore.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/EglCore.java
new file mode 100644
index 000000000..351b0a6fb
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/EglCore.java
@@ -0,0 +1,385 @@
+/*
+ * Copyright 2013 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.agora.api.component.gles.core;
+
+import android.graphics.SurfaceTexture;
+import android.opengl.EGL14;
+import android.opengl.EGLConfig;
+import android.opengl.EGLContext;
+import android.opengl.EGLDisplay;
+import android.opengl.EGLExt;
+import android.opengl.EGLSurface;
+import android.util.Log;
+import android.view.Surface;
+
+/**
+ * Core EGL state (display, context, config).
+ *
+ * The EGLContext must only be attached to one thread at a time. This class is not thread-safe.
+ */
+public final class EglCore {
+ private static final String TAG = GlUtil.TAG;
+
+ /**
+ * Constructor flag: surface must be recordable. This discourages EGL from using a
+ * pixel format that cannot be converted efficiently to something usable by the video
+ * encoder.
+ */
+ public static final int FLAG_RECORDABLE = 0x01;
+
+ /**
+ * Constructor flag: ask for GLES3, fall back to GLES2 if not available. Without this
+ * flag, GLES2 is used.
+ */
+ public static final int FLAG_TRY_GLES3 = 0x02;
+
+ // Android-specific extension.
+ private static final int EGL_RECORDABLE_ANDROID = 0x3142;
+
+ private EGLDisplay mEGLDisplay = EGL14.EGL_NO_DISPLAY;
+ private EGLContext mEGLContext = EGL14.EGL_NO_CONTEXT;
+ private EGLConfig mEGLConfig = null;
+ private int mGlVersion = -1;
+
+
+ /**
+ * Prepares EGL display and context.
+ *
+ * Equivalent to EglCore(null, 0).
+ */
+ public EglCore() {
+ this(null, 0);
+ }
+
+ /**
+ * Prepares EGL display and context.
+ *
+ *
+ * @param sharedContext The context to share, or null if sharing is not desired.
+ * @param flags Configuration bit flags, e.g. FLAG_RECORDABLE.
+ */
+ public EglCore(EGLContext sharedContext, int flags) {
+ if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) {
+ throw new RuntimeException("EGL already set up");
+ }
+
+ if (sharedContext == null) {
+ sharedContext = EGL14.EGL_NO_CONTEXT;
+ }
+
+ mEGLDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
+ if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
+ throw new RuntimeException("unable to get EGL14 display");
+ }
+ int[] version = new int[2];
+ if (!EGL14.eglInitialize(mEGLDisplay, version, 0, version, 1)) {
+ mEGLDisplay = null;
+ throw new RuntimeException("unable to initialize EGL14");
+ }
+
+ // Try to get a GLES3 context, if requested.
+ if ((flags & FLAG_TRY_GLES3) != 0) {
+ //Log.d(TAG, "Trying GLES 3");
+ EGLConfig config = getConfig(flags, 3);
+ if (config != null) {
+ int[] attrib3_list = {
+ EGL14.EGL_CONTEXT_CLIENT_VERSION, 3,
+ EGL14.EGL_NONE
+ };
+ EGLContext context = EGL14.eglCreateContext(mEGLDisplay, config, sharedContext,
+ attrib3_list, 0);
+
+ if (EGL14.eglGetError() == EGL14.EGL_SUCCESS) {
+ //Log.d(TAG, "Got GLES 3 config");
+ mEGLConfig = config;
+ mEGLContext = context;
+ mGlVersion = 3;
+ }
+ }
+ }
+ if (mEGLContext == EGL14.EGL_NO_CONTEXT) { // GLES 2 only, or GLES 3 attempt failed
+ //Log.d(TAG, "Trying GLES 2");
+ EGLConfig config = getConfig(flags, 2);
+ if (config == null) {
+ throw new RuntimeException("Unable to find a suitable EGLConfig");
+ }
+ int[] attrib2_list = {
+ EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL14.EGL_NONE
+ };
+ EGLContext context = EGL14.eglCreateContext(mEGLDisplay, config, sharedContext,
+ attrib2_list, 0);
+ checkEglError("eglCreateContext");
+ mEGLConfig = config;
+ mEGLContext = context;
+ mGlVersion = 2;
+ }
+
+ // Confirm with query.
+ int[] values = new int[1];
+ EGL14.eglQueryContext(mEGLDisplay, mEGLContext, EGL14.EGL_CONTEXT_CLIENT_VERSION,
+ values, 0);
+ Log.d(TAG, "EGLContext created, client version " + values[0]);
+ }
+
+ /**
+ * Finds a suitable EGLConfig.
+ *
+ * @param flags Bit flags from constructor.
+ * @param version Must be 2 or 3.
+ */
+ private EGLConfig getConfig(int flags, int version) {
+ int renderableType = EGL14.EGL_OPENGL_ES2_BIT;
+ if (version >= 3) {
+ renderableType |= EGLExt.EGL_OPENGL_ES3_BIT_KHR;
+ }
+
+ // The actual surface is generally RGBA or RGBX, so situationally omitting alpha
+ // doesn't really help. It can also lead to a huge performance hit on glReadPixels()
+ // when reading into a GL_RGBA buffer.
+ int[] attribList = {
+ EGL14.EGL_RED_SIZE, 8,
+ EGL14.EGL_GREEN_SIZE, 8,
+ EGL14.EGL_BLUE_SIZE, 8,
+ EGL14.EGL_ALPHA_SIZE, 8,
+ //EGL14.EGL_DEPTH_SIZE, 16,
+ //EGL14.EGL_STENCIL_SIZE, 8,
+ EGL14.EGL_RENDERABLE_TYPE, renderableType,
+ EGL14.EGL_NONE, 0, // placeholder for recordable [@-3]
+ EGL14.EGL_NONE
+ };
+ if ((flags & FLAG_RECORDABLE) != 0) {
+ attribList[attribList.length - 3] = EGL_RECORDABLE_ANDROID;
+ attribList[attribList.length - 2] = 1;
+ }
+ EGLConfig[] configs = new EGLConfig[1];
+ int[] numConfigs = new int[1];
+ if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length,
+ numConfigs, 0)) {
+ Log.w(TAG, "unable to find RGB8888 / " + version + " EGLConfig");
+ return null;
+ }
+ return configs[0];
+ }
+
+ /**
+ * Discards all resources held by this class, notably the EGL context. This must be
+ * called from the thread where the context was created.
+ *
+ * On completion, no context will be current.
+ */
+ public void release() {
+ if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) {
+ // Android is unusual in that it uses a reference-counted EGLDisplay. So for
+ // every eglInitialize() we need an eglTerminate().
+ EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
+ EGL14.EGL_NO_CONTEXT);
+ EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
+ EGL14.eglReleaseThread();
+ EGL14.eglTerminate(mEGLDisplay);
+ }
+
+ mEGLDisplay = EGL14.EGL_NO_DISPLAY;
+ mEGLContext = EGL14.EGL_NO_CONTEXT;
+ mEGLConfig = null;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ try {
+ if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) {
+ // We're limited here -- finalizers don't run on the thread that holds
+ // the EGL state, so if a surface or context is still current on another
+ // thread we can't fully release it here. Exceptions thrown from here
+ // are quietly discarded. Complain in the log file.
+ Log.w(TAG, "WARNING: EglCore was not explicitly released -- state may be leaked");
+ release();
+ }
+ } finally {
+ super.finalize();
+ }
+ }
+
+ public EGLContext getEGLContext() {
+ return mEGLContext;
+ }
+
+ /**
+ * Destroys the specified surface. Note the EGLSurface won't actually be destroyed if it's
+ * still current in a context.
+ */
+ public void releaseSurface(EGLSurface eglSurface) {
+ EGL14.eglDestroySurface(mEGLDisplay, eglSurface);
+ }
+
+ /**
+ * Creates an EGL surface associated with a Surface.
+ *
+ * If this is destined for MediaCodec, the EGLConfig should have the "recordable" attribute.
+ */
+ public EGLSurface createWindowSurface(Object surface) {
+ if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture)) {
+ throw new RuntimeException("invalid surface: " + surface);
+ }
+
+ // Create a window surface, and attach it to the Surface we received.
+ int[] surfaceAttribs = {
+ EGL14.EGL_NONE
+ };
+ EGLSurface eglSurface = EGL14.eglCreateWindowSurface(mEGLDisplay, mEGLConfig, surface,
+ surfaceAttribs, 0);
+ checkEglError("eglCreateWindowSurface");
+ if (eglSurface == null) {
+ throw new RuntimeException("surface was null");
+ }
+ return eglSurface;
+ }
+
+ /**
+ * Creates an EGL surface associated with an offscreen buffer.
+ */
+ public EGLSurface createOffscreenSurface(int width, int height) {
+ int[] surfaceAttribs = {
+ EGL14.EGL_WIDTH, width,
+ EGL14.EGL_HEIGHT, height,
+ EGL14.EGL_NONE
+ };
+ EGLSurface eglSurface = EGL14.eglCreatePbufferSurface(mEGLDisplay, mEGLConfig,
+ surfaceAttribs, 0);
+ checkEglError("eglCreatePbufferSurface");
+ if (eglSurface == null) {
+ throw new RuntimeException("surface was null");
+ }
+ return eglSurface;
+ }
+
+ /**
+ * Makes our EGL context current, using the supplied surface for both "draw" and "read".
+ */
+ public void makeCurrent(EGLSurface eglSurface) {
+ if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
+ // called makeCurrent() before create?
+ Log.d(TAG, "NOTE: makeCurrent w/o display");
+ }
+ if (!EGL14.eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext)) {
+ throw new RuntimeException("eglMakeCurrent failed");
+ }
+ }
+
+ /**
+ * Makes our EGL context current, using the supplied "draw" and "read" surfaces.
+ */
+ public void makeCurrent(EGLSurface drawSurface, EGLSurface readSurface) {
+ if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
+ // called makeCurrent() before create?
+ Log.d(TAG, "NOTE: makeCurrent w/o display");
+ }
+ if (!EGL14.eglMakeCurrent(mEGLDisplay, drawSurface, readSurface, mEGLContext)) {
+ throw new RuntimeException("eglMakeCurrent(draw,read) failed");
+ }
+ }
+
+ /**
+ * Makes no context current.
+ */
+ public void makeNothingCurrent() {
+ if (!EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
+ EGL14.EGL_NO_CONTEXT)) {
+ throw new RuntimeException("eglMakeCurrent failed");
+ }
+ }
+
+ /**
+ * Calls eglSwapBuffers. Use this to "publish" the current frame.
+ *
+ * @return false on failure
+ */
+ public boolean swapBuffers(EGLSurface eglSurface) {
+ return EGL14.eglSwapBuffers(mEGLDisplay, eglSurface);
+ }
+
+ /**
+ * Sends the presentation time stamp to EGL. Time is expressed in nanoseconds.
+ */
+ public void setPresentationTime(EGLSurface eglSurface, long nsecs) {
+ EGLExt.eglPresentationTimeANDROID(mEGLDisplay, eglSurface, nsecs);
+ }
+
+ /**
+ * Returns true if our context and the specified surface are current.
+ */
+ public boolean isCurrent(EGLSurface eglSurface) {
+ return mEGLContext.equals(EGL14.eglGetCurrentContext()) &&
+ eglSurface.equals(EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW));
+ }
+
+ public EGLSurface getCurrentDrawingSurface() {
+ EGLSurface surface = null;
+ if (mEGLContext.equals(EGL14.eglGetCurrentContext())) {
+ surface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW);
+ }
+ return surface;
+ }
+
+ /**
+ * Performs a simple surface query.
+ */
+ public int querySurface(EGLSurface eglSurface, int what) {
+ int[] value = new int[1];
+ EGL14.eglQuerySurface(mEGLDisplay, eglSurface, what, value, 0);
+ return value[0];
+ }
+
+ /**
+ * Queries a string value.
+ */
+ public String queryString(int what) {
+ return EGL14.eglQueryString(mEGLDisplay, what);
+ }
+
+ /**
+ * Returns the GLES version this context is configured for (currently 2 or 3).
+ */
+ public int getGlVersion() {
+ return mGlVersion;
+ }
+
+ /**
+ * Writes the current display, context, and surface to the log.
+ */
+ public static void logCurrent(String msg) {
+ EGLDisplay display;
+ EGLContext context;
+ EGLSurface surface;
+
+ display = EGL14.eglGetCurrentDisplay();
+ context = EGL14.eglGetCurrentContext();
+ surface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW);
+ Log.i(TAG, "Current EGL (" + msg + "): display=" + display + ", context=" + context +
+ ", surface=" + surface);
+ }
+
+ /**
+ * Checks for EGL errors. Throws an exception if an error has been raised.
+ */
+ private void checkEglError(String msg) {
+ int error;
+ if ((error = EGL14.eglGetError()) != EGL14.EGL_SUCCESS) {
+ throw new RuntimeException(msg + ": EGL error: 0x" + Integer.toHexString(error));
+ }
+ }
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/EglSurfaceBase.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/EglSurfaceBase.java
new file mode 100644
index 000000000..e7c29b20f
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/EglSurfaceBase.java
@@ -0,0 +1,198 @@
+/*
+ * Copyright 2013 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.agora.api.component.gles.core;
+
+import android.graphics.Bitmap;
+import android.opengl.EGL14;
+import android.opengl.EGLSurface;
+import android.opengl.GLES20;
+import android.util.Log;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * Common base class for EGL surfaces.
+ *
+ * There can be multiple surfaces associated with a single context.
+ */
+public class EglSurfaceBase {
+ protected static final String TAG = GlUtil.TAG;
+
+ // EglCore object we're associated with. It may be associated with multiple surfaces.
+ protected EglCore mEglCore;
+
+ private EGLSurface mEGLSurface = EGL14.EGL_NO_SURFACE;
+ private int mWidth = -1;
+ private int mHeight = -1;
+
+ protected EglSurfaceBase(EglCore eglCore) {
+ mEglCore = eglCore;
+ }
+
+ /**
+ * Creates a window surface.
+ *
+ *
+ * @param surface May be a Surface or SurfaceTexture.
+ */
+ public void createWindowSurface(Object surface) {
+ if (mEGLSurface != EGL14.EGL_NO_SURFACE) {
+ throw new IllegalStateException("surface already created");
+ }
+ mEGLSurface = mEglCore.createWindowSurface(surface);
+
+ // Don't cache width/height here, because the size of the underlying surface can change
+ // out from under us (see e.g. HardwareScalerActivity).
+ //mWidth = mEglCore.querySurface(mEGLSurface, EGL14.EGL_WIDTH);
+ //mHeight = mEglCore.querySurface(mEGLSurface, EGL14.EGL_HEIGHT);
+ }
+
+ /**
+ * Creates an off-screen surface.
+ */
+ public void createOffscreenSurface(int width, int height) {
+ if (mEGLSurface != EGL14.EGL_NO_SURFACE) {
+ throw new IllegalStateException("surface already created");
+ }
+ mEGLSurface = mEglCore.createOffscreenSurface(width, height);
+ mWidth = width;
+ mHeight = height;
+ }
+
+ /**
+ * Returns the surface's width, in pixels.
+ *
+ * If this is called on a window surface, and the underlying surface is in the process
+ * of changing size, we may not see the new size right away (e.g. in the "surfaceChanged"
+ * callback). The size should match after the next buffer swap.
+ */
+ public int getWidth() {
+ if (mWidth < 0) {
+ return mEglCore.querySurface(mEGLSurface, EGL14.EGL_WIDTH);
+ } else {
+ return mWidth;
+ }
+ }
+
+ /**
+ * Returns the surface's height, in pixels.
+ */
+ public int getHeight() {
+ if (mHeight < 0) {
+ return mEglCore.querySurface(mEGLSurface, EGL14.EGL_HEIGHT);
+ } else {
+ return mHeight;
+ }
+ }
+
+ /**
+ * Release the EGL surface.
+ */
+ public void releaseEglSurface() {
+ mEglCore.releaseSurface(mEGLSurface);
+ mEGLSurface = EGL14.EGL_NO_SURFACE;
+ mWidth = mHeight = -1;
+ }
+
+ /**
+ * Makes our EGL context and surface current.
+ */
+ public void makeCurrent() {
+ mEglCore.makeCurrent(mEGLSurface);
+ }
+
+ /**
+ * Makes our EGL context and surface current for drawing, using the supplied surface
+ * for reading.
+ */
+ public void makeCurrentReadFrom(EglSurfaceBase readSurface) {
+ mEglCore.makeCurrent(mEGLSurface, readSurface.mEGLSurface);
+ }
+
+ /**
+ * Calls eglSwapBuffers. Use this to "publish" the current frame.
+ *
+ * @return false on failure
+ */
+ public boolean swapBuffers() {
+ boolean result = mEglCore.swapBuffers(mEGLSurface);
+ if (!result) {
+ Log.d(TAG, "WARNING: swapBuffers() failed");
+ }
+ return result;
+ }
+
+ /**
+ * Sends the presentation time stamp to EGL.
+ *
+ * @param nsecs Timestamp, in nanoseconds.
+ */
+ public void setPresentationTime(long nsecs) {
+ mEglCore.setPresentationTime(mEGLSurface, nsecs);
+ }
+
+ /**
+ * Saves the EGL surface to a file.
+ *
+ * Expects that this object's EGL surface is current.
+ */
+ public void saveFrame(File file) throws IOException {
+ if (!mEglCore.isCurrent(mEGLSurface)) {
+ throw new RuntimeException("Expected EGL context/surface is not current");
+ }
+
+ // glReadPixels fills in a "direct" ByteBuffer with what is essentially big-endian RGBA
+ // data (i.e. a byte of red, followed by a byte of green...). While the Bitmap
+ // constructor that takes an int[] wants little-endian ARGB (blue/red swapped), the
+ // Bitmap "copy pixels" method wants the same format GL provides.
+ //
+ // Ideally we'd have some way to re-use the ByteBuffer, especially if we're calling
+ // here often.
+ //
+ // Making this even more interesting is the upside-down nature of GL, which means
+ // our output will look upside down relative to what appears on screen if the
+ // typical GL conventions are used.
+
+ String filename = file.toString();
+
+ int width = getWidth();
+ int height = getHeight();
+ ByteBuffer buf = ByteBuffer.allocateDirect(width * height * 4);
+ buf.order(ByteOrder.LITTLE_ENDIAN);
+ GLES20.glReadPixels(0, 0, width, height,
+ GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buf);
+ GlUtil.checkGlError("glReadPixels");
+ buf.rewind();
+
+ BufferedOutputStream bos = null;
+ try {
+ bos = new BufferedOutputStream(new FileOutputStream(filename));
+ Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ bmp.copyPixelsFromBuffer(buf);
+ bmp.compress(Bitmap.CompressFormat.PNG, 90, bos);
+ bmp.recycle();
+ } finally {
+ if (bos != null) bos.close();
+ }
+ Log.d(TAG, "Saved " + width + "x" + height + " frame as '" + filename + "'");
+ }
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/Extensions.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/Extensions.java
new file mode 100644
index 000000000..a876c736c
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/Extensions.java
@@ -0,0 +1,38 @@
+package io.agora.api.component.gles.core;
+
+import android.content.Context;
+import android.content.res.AssetManager;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public abstract class Extensions {
+
+ public static byte[] getBytes(InputStream inputStream) {
+ try {
+ byte[] bytes = new byte[inputStream.available()];
+ inputStream.read(bytes);
+ inputStream.close();
+ return bytes;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return new byte[0];
+ }
+
+ public static byte[] getBytes(AssetManager assetManager, String fileName) {
+ try {
+ return getBytes(assetManager.open(fileName));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return new byte[0];
+ }
+
+ public static String readTextFileFromResource(Context context, int resourceId) {
+ return new String(Extensions.getBytes(context.getResources().openRawResource(resourceId)));
+ }
+
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/GlUtil.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/GlUtil.java
new file mode 100644
index 000000000..3fa1bb991
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/GlUtil.java
@@ -0,0 +1,282 @@
+/*
+ * Copyright 2014 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.agora.api.component.gles.core;
+
+import android.graphics.Bitmap;
+import android.opengl.GLES11Ext;
+import android.opengl.GLES20;
+import android.opengl.GLES30;
+import android.opengl.GLUtils;
+import android.opengl.Matrix;
+import android.util.Log;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+/**
+ * Some OpenGL utility functions.
+ */
+public abstract class GlUtil {
+ //public static final String TAG = "Grafika";
+ public static final String TAG = "mqi";
+ /**
+ * Identity matrix for general use. Don't modify or life will get weird.
+ */
+ public static final float[] IDENTITY_MATRIX;
+
+ static {
+ IDENTITY_MATRIX = new float[16];
+ Matrix.setIdentityM(IDENTITY_MATRIX, 0);
+ }
+
+ private static final int SIZEOF_FLOAT = 4;
+
+
+ private GlUtil() {
+ } // do not instantiate
+
+ /**
+ * Creates a new program from the supplied vertex and fragment shaders.
+ *
+ * @return A handle to the program, or 0 on failure.
+ */
+ public static int createProgram(String vertexSource, String fragmentSource) {
+ int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
+ if (vertexShader == 0) {
+ return 0;
+ }
+ int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
+ if (pixelShader == 0) {
+ return 0;
+ }
+
+ int program = GLES20.glCreateProgram();
+ checkGlError("glCreateProgram");
+ if (program == 0) {
+ Log.e(TAG, "Could not create program");
+ }
+ GLES20.glAttachShader(program, vertexShader);
+ checkGlError("glAttachShader");
+ GLES20.glAttachShader(program, pixelShader);
+ checkGlError("glAttachShader");
+ GLES20.glLinkProgram(program);
+ int[] linkStatus = new int[1];
+ GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
+ if (linkStatus[0] != GLES20.GL_TRUE) {
+ Log.e(TAG, "Could not link program: ");
+ Log.e(TAG, GLES20.glGetProgramInfoLog(program));
+ GLES20.glDeleteProgram(program);
+ program = 0;
+ }
+ return program;
+ }
+
+ /**
+ * Compiles the provided shader source.
+ *
+ * @return A handle to the shader, or 0 on failure.
+ */
+ public static int loadShader(int shaderType, String source) {
+ int shader = GLES20.glCreateShader(shaderType);
+ checkGlError("glCreateShader type=" + shaderType);
+ GLES20.glShaderSource(shader, source);
+ GLES20.glCompileShader(shader);
+ int[] compiled = new int[1];
+ GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
+ if (compiled[0] == 0) {
+ Log.e(TAG, "Could not compile shader " + shaderType + ":");
+ Log.e(TAG, " " + GLES20.glGetShaderInfoLog(shader));
+ GLES20.glDeleteShader(shader);
+ shader = 0;
+ }
+ return shader;
+ }
+
+ /**
+ * Checks to see if a GLES error has been raised.
+ */
+ public static void checkGlError(String op) {
+ int error = GLES20.glGetError();
+ if (error != GLES20.GL_NO_ERROR) {
+ String msg = op + ": glError 0x" + Integer.toHexString(error);
+ Log.e(TAG, msg);
+ }
+ }
+
+ /**
+ * Checks to see if the location we obtained is valid. GLES returns -1 if a label
+ * could not be found, but does not set the GL error.
+ *
+ * Throws a RuntimeException if the location is invalid.
+ */
+ public static void checkLocation(int location, String label) {
+ if (location < 0) {
+ Log.e(TAG, "Unable to locate '" + label + "' in program");
+ }
+ }
+
+ /**
+ * Creates a texture from raw data.
+ *
+ * @param data Image data, in a "direct" ByteBuffer.
+ * @param width Texture width, in pixels (not bytes).
+ * @param height Texture height, in pixels.
+ * @param format Image data format (use constant appropriate for glTexImage2D(), e.g. GL_RGBA).
+ * @return Handle to texture.
+ */
+ public static int createImageTexture(ByteBuffer data, int width, int height, int format) {
+ int[] textureHandles = new int[1];
+ int textureHandle;
+
+ GLES20.glGenTextures(1, textureHandles, 0);
+ textureHandle = textureHandles[0];
+ GlUtil.checkGlError("glGenTextures");
+
+ // Bind the texture handle to the 2D texture target.
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle);
+
+ // Configure min/mag filtering, i.e. what scaling method do we use if what we're rendering
+ // is smaller or larger than the source image.
+ GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
+ GLES20.GL_LINEAR);
+ GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,
+ GLES20.GL_LINEAR);
+ GlUtil.checkGlError("loadImageTexture");
+
+ // Load the data from the buffer into the texture handle.
+ GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, /*level*/ 0, format,
+ width, height, /*border*/ 0, format, GLES20.GL_UNSIGNED_BYTE, data);
+ GlUtil.checkGlError("loadImageTexture");
+
+ return textureHandle;
+ }
+
+ /**
+ * Creates a texture from bitmap.
+ *
+ * @param bmp bitmap data
+ * @return Handle to texture.
+ */
+ public static int createImageTexture(Bitmap bmp) {
+ int[] textureHandles = new int[1];
+ int textureHandle;
+
+ GLES20.glGenTextures(1, textureHandles, 0);
+ textureHandle = textureHandles[0];
+ GlUtil.checkGlError("glGenTextures");
+
+ // Bind the texture handle to the 2D texture target.
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle);
+
+ // Configure min/mag filtering, i.e. what scaling method do we use if what we're rendering
+ // is smaller or larger than the source image.
+ GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
+ GLES20.GL_LINEAR);
+ GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,
+ GLES20.GL_LINEAR);
+ GlUtil.checkGlError("loadImageTexture");
+
+ // Load the data from the buffer into the texture handle.
+ GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, /*level*/ 0, bmp, 0);
+ GlUtil.checkGlError("loadImageTexture");
+
+ return textureHandle;
+ }
+
+ /**
+ * Allocates a direct float buffer, and populates it with the float array data.
+ */
+ public static FloatBuffer createFloatBuffer(float[] coords) {
+ // Allocate a direct ByteBuffer, using 4 bytes per float, and copy coords into it.
+ ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * SIZEOF_FLOAT);
+ bb.order(ByteOrder.nativeOrder());
+ FloatBuffer fb = bb.asFloatBuffer();
+ fb.put(coords);
+ fb.position(0);
+ return fb;
+ }
+
+ /**
+ * Writes GL version info to the log.
+ */
+ public static void logVersionInfo() {
+ Log.i(TAG, "vendor : " + GLES20.glGetString(GLES20.GL_VENDOR));
+ Log.i(TAG, "renderer: " + GLES20.glGetString(GLES20.GL_RENDERER));
+ Log.i(TAG, "version : " + GLES20.glGetString(GLES20.GL_VERSION));
+
+ if (false) {
+ int[] values = new int[1];
+ GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, values, 0);
+ int majorVersion = values[0];
+ GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, values, 0);
+ int minorVersion = values[0];
+ if (GLES30.glGetError() == GLES30.GL_NO_ERROR) {
+ Log.i(TAG, "iversion: " + majorVersion + "." + minorVersion);
+ }
+ }
+ }
+
+
+ /**
+ * Creates a texture object suitable for use with this program.
+ *
+ * On exit, the texture will be bound.
+ */
+ public static int createTextureObject(int textureTarget) {
+ int[] textures = new int[1];
+ GLES20.glGenTextures(1, textures, 0);
+ GlUtil.checkGlError("glGenTextures");
+
+ int texId = textures[0];
+ GLES20.glBindTexture(textureTarget, texId);
+ GlUtil.checkGlError("glBindTexture " + texId);
+
+ GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER,
+ GLES20.GL_NEAREST);
+ GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER,
+ GLES20.GL_LINEAR);
+ GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S,
+ GLES20.GL_CLAMP_TO_EDGE);
+ GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T,
+ GLES20.GL_CLAMP_TO_EDGE);
+ GlUtil.checkGlError("glTexParameter");
+
+ return texId;
+ }
+
+ public static void deleteTextureObject(int textureId) {
+ int[] textures = new int[1];
+ textures[0] = textureId;
+ GLES20.glDeleteTextures(1, textures, 0);
+ GlUtil.checkGlError("glDeleteTextures");
+ }
+
+ public static float[] changeMVPMatrix(float[] mvpMatrix, float viewWidth, float viewHeight, float textureWidth, float textureHeight) {
+ float scale = viewWidth * textureHeight / viewHeight / textureWidth;
+ if (scale == 1) {
+ return mvpMatrix;
+ } else {
+ float[] mvp = new float[16];
+ float[] tmp = new float[16];
+ Matrix.setIdentityM(tmp, 0);
+ Matrix.scaleM(tmp, 0, scale > 1 ? 1F : (1F / scale), scale > 1 ? scale : 1F, 1F);
+ Matrix.multiplyMM(mvp, 0, tmp, 0, mvpMatrix, 0);
+ return mvp;
+ }
+ }
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/OffscreenSurface.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/OffscreenSurface.java
new file mode 100644
index 000000000..1481f5b6a
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/OffscreenSurface.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2013 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.agora.api.component.gles.core;
+
+/**
+ * Off-screen EGL surface (pbuffer).
+ *
+ * It's good practice to explicitly release() the surface, preferably from a "finally" block.
+ */
+public class OffscreenSurface extends EglSurfaceBase {
+ /**
+ * Creates an off-screen surface with the specified width and height.
+ */
+ public OffscreenSurface(EglCore eglCore, int width, int height) {
+ super(eglCore);
+ createOffscreenSurface(width, height);
+ }
+
+ /**
+ * Releases any resources associated with the surface.
+ */
+ public void release() {
+ releaseEglSurface();
+ }
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/Program.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/Program.java
new file mode 100644
index 000000000..95ddcf6b5
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/Program.java
@@ -0,0 +1,74 @@
+package io.agora.api.component.gles.core;
+
+import android.content.Context;
+import android.opengl.GLES20;
+
+/**
+ * Created by tujh on 2018/1/24.
+ */
+
+public abstract class Program {
+ private static final String TAG = GlUtil.TAG;
+
+ // Handles to the GL program and various components of it.
+ protected int mProgramHandle;
+
+
+ protected Drawable2d mDrawable2d;
+
+ /**
+ * Prepares the program in the current EGL context.
+ */
+ public Program(String VERTEX_SHADER, String FRAGMENT_SHADER_2D) {
+ mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_2D);
+ mDrawable2d = getDrawable2d();
+ getLocations();
+ }
+
+ public Program(Context context, int vertexShaderResourceId, int fragmentShaderResourceId) {
+ this(Extensions.readTextFileFromResource(context, vertexShaderResourceId), Extensions.readTextFileFromResource(context, fragmentShaderResourceId));
+ }
+
+ public void updateVertexArray(float[] FULL_RECTANGLE_COORDS) {
+ mDrawable2d.updateVertexArray(FULL_RECTANGLE_COORDS);
+ }
+
+ public void updateTexCoordArray(float[] FULL_RECTANGLE_TEX_COORDS) {
+ mDrawable2d.updateTexCoordArray(FULL_RECTANGLE_TEX_COORDS);
+ }
+
+ protected abstract Drawable2d getDrawable2d();
+
+ /**
+ * get locations of attributes and uniforms
+ */
+ protected abstract void getLocations();
+
+ /**
+ * Issues the draw call. Does the full setup on every call.
+ */
+ public abstract void drawFrame(int textureId, float[] texMatrix, float[] mvpMatrix);
+
+ public void drawFrame(int textureId, float[] texMatrix) {
+ drawFrame(textureId, texMatrix, GlUtil.IDENTITY_MATRIX);
+ }
+
+ public void drawFrame(int textureId, float[] texMatrix, float[] mvpMatrix, int x, int y, int width, int height) {
+ int[] originalViewport = new int[4];
+ GLES20.glGetIntegerv(GLES20.GL_VIEWPORT, originalViewport, 0);
+ GLES20.glViewport(x, y, width, height);
+ drawFrame(textureId, texMatrix, mvpMatrix);
+ GLES20.glViewport(originalViewport[0], originalViewport[1], originalViewport[2], originalViewport[3]);
+ }
+
+ /**
+ * Releases the program.
+ *
+ * The appropriate EGL context must be current (i.e. the one that was used to create
+ * the program).
+ */
+ public void release() {
+ GLES20.glDeleteProgram(mProgramHandle);
+ mProgramHandle = -1;
+ }
+}
diff --git a/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/WindowSurface.java b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/WindowSurface.java
new file mode 100644
index 000000000..1831f6f96
--- /dev/null
+++ b/Android/APIExample/lib-component/src/main/java/io/agora/api/component/gles/core/WindowSurface.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2013 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.agora.api.component.gles.core;
+
+import android.graphics.SurfaceTexture;
+import android.view.Surface;
+
+/**
+ * Recordable EGL window surface.
+ *
+ * It's good practice to explicitly release() the surface, preferably from a "finally" block.
+ */
+public class WindowSurface extends EglSurfaceBase {
+ private Surface mSurface;
+ private boolean mReleaseSurface;
+
+ /**
+ * Associates an EGL surface with the native window surface.
+ *
+ * Set releaseSurface to true if you want the Surface to be released when release() is
+ * called. This is convenient, but can interfere with framework classes that expect to
+ * manage the Surface themselves (e.g. if you release a SurfaceView's Surface, the
+ * surfaceDestroyed() callback won't fire).
+ */
+ public WindowSurface(EglCore eglCore, Surface surface, boolean releaseSurface) {
+ super(eglCore);
+ createWindowSurface(surface);
+ mSurface = surface;
+ mReleaseSurface = releaseSurface;
+ }
+
+ /**
+ * Associates an EGL surface with the SurfaceTexture.
+ */
+ public WindowSurface(EglCore eglCore, SurfaceTexture surfaceTexture) {
+ super(eglCore);
+ createWindowSurface(surfaceTexture);
+ }
+
+ public WindowSurface(EglCore eglCore, int width, int height) {
+ super(eglCore);
+ createOffscreenSurface(width, height);
+ }
+
+ /**
+ * Releases any resources associated with the EGL surface (and, if configured to do so,
+ * with the Surface as well).
+ *
+ * Does not require that the surface's EGL context be current.
+ */
+ public void release() {
+ releaseEglSurface();
+ if (mSurface != null) {
+ if (mReleaseSurface) {
+ mSurface.release();
+ }
+ mSurface = null;
+ }
+ }
+
+ /**
+ * Recreate the EGLSurface, using the new EglBase. The caller should have already
+ * freed the old EGLSurface with releaseEglSurface().
+ *
+ * This is useful when we want to update the EGLSurface associated with a Surface.
+ * For example, if we want to share with a different EGLContext, which can only
+ * be done by tearing down and recreating the context. (That's handled by the caller;
+ * this just creates a new EGLSurface for the Surface we were handed earlier.)
+ *
+ * If the previous EGLSurface isn't fully destroyed, e.g. it's still current on a
+ * context somewhere, the create call will fail with complaints from the Surface
+ * about already being connected.
+ */
+ public void recreate(EglCore newEglCore) {
+ if (mSurface == null) {
+ throw new RuntimeException("not yet implemented for SurfaceTexture");
+ }
+ mEglCore = newEglCore; // switch to new context
+ createWindowSurface(mSurface); // create new surface
+ }
+}
diff --git a/Android/APIExample/lib-push-externalvideo/.gitignore b/Android/APIExample/lib-push-externalvideo/.gitignore
new file mode 100644
index 000000000..796b96d1c
--- /dev/null
+++ b/Android/APIExample/lib-push-externalvideo/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/Android/APIExample/lib-push-externalvideo/build.gradle b/Android/APIExample/lib-push-externalvideo/build.gradle
new file mode 100644
index 000000000..0580f8882
--- /dev/null
+++ b/Android/APIExample/lib-push-externalvideo/build.gradle
@@ -0,0 +1,35 @@
+apply plugin: 'com.android.library'
+
+android {
+ compileSdkVersion 29
+ buildToolsVersion "29.0.3"
+
+ defaultConfig {
+ minSdkVersion 19
+ targetSdkVersion 29
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ consumerProguardFiles 'consumer-rules.pro'
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+
+ implementation 'androidx.appcompat:appcompat:1.1.0'
+ testImplementation 'junit:junit:4.12'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+
+ api project(path: ':lib-component')
+}
diff --git a/Android/APIExample/lib-push-externalvideo/consumer-rules.pro b/Android/APIExample/lib-push-externalvideo/consumer-rules.pro
new file mode 100644
index 000000000..e69de29bb
diff --git a/Android/APIExample/lib-push-externalvideo/proguard-rules.pro b/Android/APIExample/lib-push-externalvideo/proguard-rules.pro
new file mode 100644
index 000000000..f1b424510
--- /dev/null
+++ b/Android/APIExample/lib-push-externalvideo/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/Android/APIExample/lib-push-externalvideo/src/main/AndroidManifest.xml b/Android/APIExample/lib-push-externalvideo/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..c03c01e71
--- /dev/null
+++ b/Android/APIExample/lib-push-externalvideo/src/main/AndroidManifest.xml
@@ -0,0 +1,2 @@
+
diff --git a/Android/APIExample/lib-raw-data/.gitignore b/Android/APIExample/lib-raw-data/.gitignore
new file mode 100644
index 000000000..796b96d1c
--- /dev/null
+++ b/Android/APIExample/lib-raw-data/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/Android/APIExample/lib-raw-data/CMakeLists.txt b/Android/APIExample/lib-raw-data/CMakeLists.txt
new file mode 100644
index 000000000..268f125e4
--- /dev/null
+++ b/Android/APIExample/lib-raw-data/CMakeLists.txt
@@ -0,0 +1,44 @@
+# For more information about using CMake with Android Studio, read the
+# documentation: https://d.android.com/studio/projects/add-native-code.html
+
+# Sets the minimum version of CMake required to build the native library.
+
+cmake_minimum_required(VERSION 3.4.1)
+
+# Creates and names a library, sets it as either STATIC
+# or SHARED, and provides the relative paths to its source code.
+# You can define multiple libraries, and CMake builds them for you.
+# Gradle automatically packages shared libraries with your APK.
+
+add_library( # Sets the name of the library.
+ apm-plugin-raw-data
+
+ # Sets the library as a shared library.
+ SHARED
+
+ # Provides a relative path to your source file(s).
+ src/main/cpp/io_agora_advancedvideo_rawdata_MediaPreProcessing.cpp)
+
+# Searches for a specified prebuilt library and stores the path as a
+# variable. Because CMake includes system libraries in the search path by
+# default, you only need to specify the name of the public NDK library
+# you want to add. CMake verifies that the library exists before
+# completing its build.
+
+find_library( # Sets the name of the path variable.
+ log-lib
+
+ # Specifies the name of the NDK library that
+ # you want CMake to locate.
+ log)
+
+# Specifies libraries CMake should link to your target library. You
+# can link multiple libraries, such as libraries you define in this
+# build script, prebuilt third-party libraries, or system libraries.
+
+target_link_libraries( # Specifies the target library.
+ apm-plugin-raw-data
+
+ # Links the target library to the log library
+ # included in the NDK.
+ ${log-lib})
\ No newline at end of file
diff --git a/Android/APIExample/lib-raw-data/build.gradle b/Android/APIExample/lib-raw-data/build.gradle
new file mode 100644
index 000000000..e04fd9311
--- /dev/null
+++ b/Android/APIExample/lib-raw-data/build.gradle
@@ -0,0 +1,53 @@
+apply plugin: 'com.android.library'
+
+android {
+ compileSdkVersion 29
+ buildToolsVersion "29.0.2"
+
+ defaultConfig {
+ minSdkVersion 19
+ targetSdkVersion 29
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ consumerProguardFiles 'consumer-rules.pro'
+
+ externalNativeBuild {
+ cmake {
+ cppFlags "-std=c++11"
+ arguments "-DANDROID_STL=c++_static",
+ "-DANDROID_PLATFORM=android-15",
+ "-DANDROID_TOOLCHAIN=clang",
+ "-DANDROID_STL_FORCE_FEATURES=OFF",
+ "-DANDROID_ARM_NEON=TRUE"
+ }
+ }
+
+ ndk {
+ abiFilters "arm64-v8a", "armeabi-v7a", "x86_64", "x86"
+ }
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+
+ externalNativeBuild {
+ cmake {
+ path "CMakeLists.txt"
+ }
+ }
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+
+ implementation 'androidx.appcompat:appcompat:1.1.0'
+ testImplementation 'junit:junit:4.12'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+}
diff --git a/Android/APIExample/lib-raw-data/consumer-rules.pro b/Android/APIExample/lib-raw-data/consumer-rules.pro
new file mode 100644
index 000000000..e69de29bb
diff --git a/Android/APIExample/lib-raw-data/proguard-rules.pro b/Android/APIExample/lib-raw-data/proguard-rules.pro
new file mode 100644
index 000000000..f1b424510
--- /dev/null
+++ b/Android/APIExample/lib-raw-data/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/Android/APIExample/lib-raw-data/src/main/AndroidManifest.xml b/Android/APIExample/lib-raw-data/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..97d8ccdc0
--- /dev/null
+++ b/Android/APIExample/lib-raw-data/src/main/AndroidManifest.xml
@@ -0,0 +1 @@
+
diff --git a/Android/APIExample/lib-raw-data/src/main/cpp/include/AgoraBase.h b/Android/APIExample/lib-raw-data/src/main/cpp/include/AgoraBase.h
new file mode 100644
index 000000000..955d13d70
--- /dev/null
+++ b/Android/APIExample/lib-raw-data/src/main/cpp/include/AgoraBase.h
@@ -0,0 +1,786 @@
+// Agora Engine SDK
+//
+// Copyright (c) 2019 Agora.io. All rights reserved.
+//
+
+#ifndef AGORA_BASE_H
+#define AGORA_BASE_H
+
+#include
+#include
+#include
+#include
+#include
+
+#if defined(_WIN32)
+#define WIN32_LEAN_AND_MEAN
+#include
+#define AGORA_CALL __cdecl
+#if defined(AGORARTC_EXPORT)
+#define AGORA_API extern "C" __declspec(dllexport)
+#else
+#define AGORA_API extern "C" __declspec(dllimport)
+#endif
+#elif defined(__APPLE__)
+#include
+#define AGORA_API __attribute__((visibility("default"))) extern "C"
+#define AGORA_CALL
+#elif defined(__ANDROID__) || defined(__linux__)
+#define AGORA_API extern "C" __attribute__((visibility("default")))
+#define AGORA_CALL
+#else
+#define AGORA_API extern "C"
+#define AGORA_CALL
+#endif
+
+namespace agora {
+namespace util {
+
+template
+class AutoPtr {
+ typedef T value_type;
+ typedef T* pointer_type;
+public:
+ AutoPtr(pointer_type p=0)
+ :ptr_(p)
+ {}
+ ~AutoPtr() {
+ if (ptr_)
+ ptr_->release();
+ }
+ operator bool() const { return ptr_ != (pointer_type)0; }
+ value_type& operator*() const {
+ return *get();
+ }
+
+ pointer_type operator->() const {
+ return get();
+ }
+
+ pointer_type get() const {
+ return ptr_;
+ }
+
+ pointer_type release() {
+ pointer_type tmp = ptr_;
+ ptr_ = 0;
+ return tmp;
+ }
+
+ void reset(pointer_type ptr = 0) {
+ if (ptr != ptr_ && ptr_)
+ ptr_->release();
+ ptr_ = ptr;
+ }
+ template
+ bool queryInterface(C1* c, C2 iid) {
+ pointer_type p = NULL;
+ if (c && !c->queryInterface(iid, (void**)&p))
+ {
+ reset(p);
+ }
+ return p != NULL;
+ }
+private:
+ AutoPtr(const AutoPtr&);
+ AutoPtr& operator=(const AutoPtr&);
+private:
+ pointer_type ptr_;
+};
+class IString {
+protected:
+ virtual ~IString(){}
+public:
+ virtual bool empty() const = 0;
+ virtual const char* c_str() = 0;
+ virtual const char* data() = 0;
+ virtual size_t length() = 0;
+ virtual void release() = 0;
+};
+typedef AutoPtr AString;
+
+}//namespace util
+
+enum INTERFACE_ID_TYPE
+{
+ AGORA_IID_AUDIO_DEVICE_MANAGER = 1,
+ AGORA_IID_VIDEO_DEVICE_MANAGER = 2,
+ AGORA_IID_RTC_ENGINE_PARAMETER = 3,
+ AGORA_IID_MEDIA_ENGINE = 4,
+ AGORA_IID_SIGNALING_ENGINE = 8,
+};
+
+ /** Warning code.
+ */
+enum WARN_CODE_TYPE
+{
+ /** 8: The specified view is invalid. Specify a view when using the video call function.
+ */
+ WARN_INVALID_VIEW = 8,
+ /** 16: Failed to initialize the video function, possibly caused by a lack of resources. The users cannot see the video while the voice communication is not affected.
+ */
+ WARN_INIT_VIDEO = 16,
+ /** 20: The request is pending, usually due to some module not being ready, and the SDK postponed processing the request.
+ */
+ WARN_PENDING = 20,
+ /** 103: No channel resources are available. Maybe because the server cannot allocate any channel resource.
+ */
+ WARN_NO_AVAILABLE_CHANNEL = 103,
+ /** 104: A timeout occurs when looking up the channel. When joining a channel, the SDK looks up the specified channel. This warning usually occurs when the network condition is too poor for the SDK to connect to the server.
+ */
+ WARN_LOOKUP_CHANNEL_TIMEOUT = 104,
+ /** **DEPRECATED** 105: The server rejects the request to look up the channel. The server cannot process this request or the request is illegal.
+
+ Deprecated as of v2.4.1. Use CONNECTION_CHANGED_REJECTED_BY_SERVER(10) in the \ref agora::rtc::IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged" callback instead.
+ */
+ WARN_LOOKUP_CHANNEL_REJECTED = 105,
+ /** 106: A timeout occurs when opening the channel. Once the specific channel is found, the SDK opens the channel. This warning usually occurs when the network condition is too poor for the SDK to connect to the server.
+ */
+ WARN_OPEN_CHANNEL_TIMEOUT = 106,
+ /** 107: The server rejects the request to open the channel. The server cannot process this request or the request is illegal.
+ */
+ WARN_OPEN_CHANNEL_REJECTED = 107,
+
+ // sdk: 100~1000
+ /** 111: A timeout occurs when switching to the live video.
+ */
+ WARN_SWITCH_LIVE_VIDEO_TIMEOUT = 111,
+ /** 118: A timeout occurs when setting the client role in the live broadcast profile.
+ */
+ WARN_SET_CLIENT_ROLE_TIMEOUT = 118,
+ /** 121: The ticket to open the channel is invalid.
+ */
+ WARN_OPEN_CHANNEL_INVALID_TICKET = 121,
+ /** 122: Try connecting to another server.
+ */
+ WARN_OPEN_CHANNEL_TRY_NEXT_VOS = 122,
+ WARN_CHANNEL_CONNECTION_UNRECOVERABLE = 131,
+ WARN_CHANNEL_CONNECTION_IP_CHANGED = 132,
+ WARN_CHANNEL_CONNECTION_PORT_CHANGED = 133,
+ /** 701: An error occurs in opening the audio mixing file.
+ */
+ WARN_AUDIO_MIXING_OPEN_ERROR = 701,
+ /** 1014: Audio Device Module: a warning occurs in the playback device.
+ */
+ WARN_ADM_RUNTIME_PLAYOUT_WARNING = 1014,
+ /** 1016: Audio Device Module: a warning occurs in the recording device.
+ */
+ WARN_ADM_RUNTIME_RECORDING_WARNING = 1016,
+ /** 1019: Audio Device Module: no valid audio data is collected.
+ */
+ WARN_ADM_RECORD_AUDIO_SILENCE = 1019,
+ /** 1020: Audio Device Module: the playback device fails.
+ */
+ WARN_ADM_PLAYOUT_MALFUNCTION = 1020,
+ /** 1021: Audio Device Module: the recording device fails.
+ */
+ WARN_ADM_RECORD_MALFUNCTION = 1021,
+ /** 1025: The audio playback or recording is interrupted by system events (such as a phone call).
+ */
+ WARN_ADM_CALL_INTERRUPTION = 1025,
+ /** 1029: During a call, the audio session category should be set to
+ * AVAudioSessionCategoryPlayAndRecord, and RtcEngine monitors this value.
+ * If the audio session category is set to other values, this warning code
+ * is triggered and RtcEngine will forcefully set it back to
+ * AVAudioSessionCategoryPlayAndRecord.
+ */
+ WARN_ADM_IOS_CATEGORY_NOT_PLAYANDRECORD = 1029,
+ /**
+ */
+ WARN_ADM_IOS_SAMPLERATE_CHANGE = 1030,
+ /** 1031: Audio Device Module: the recorded audio voice is too low.
+ */
+ WARN_ADM_RECORD_AUDIO_LOWLEVEL = 1031,
+ /** 1032: Audio Device Module: the playback audio voice is too low.
+ */
+ WARN_ADM_PLAYOUT_AUDIO_LOWLEVEL = 1032,
+ /** 1040: Audio device module: An exception occurs with the audio drive.
+ * Solutions:
+ * - Disable or re-enable the audio device.
+ * - Re-enable your device.
+ * - Update the sound card drive.
+ */
+ WARN_ADM_WINDOWS_NO_DATA_READY_EVENT = 1040,
+ /** 1051: Audio Device Module: howling is detected.
+ */
+ WARN_APM_HOWLING = 1051,
+ /** 1052: Audio Device Module: the device is in the glitch state.
+ */
+ WARN_ADM_GLITCH_STATE = 1052,
+ /** 1053: Audio Device Module: the underlying audio settings have changed.
+ */
+ WARN_ADM_IMPROPER_SETTINGS = 1053,
+ /**
+ */
+ WARN_ADM_WIN_CORE_NO_RECORDING_DEVICE = 1322,
+ /** 1323: Audio device module: No available playback device.
+ * Solution: Plug in the audio device.
+ */
+ WARN_ADM_WIN_CORE_NO_PLAYOUT_DEVICE = 1323,
+ /** Audio device module: The capture device is released improperly.
+ * Solutions:
+ * - Disable or re-enable the audio device.
+ * - Re-enable your device.
+ * - Update the sound card drive.
+ */
+ WARN_ADM_WIN_CORE_IMPROPER_CAPTURE_RELEASE = 1324,
+ /** 1610: Super-resolution warning: the original video dimensions of the remote user exceed 640 × 480.
+ */
+ WARN_SUPER_RESOLUTION_STREAM_OVER_LIMITATION = 1610,
+ /** 1611: Super-resolution warning: another user is using super resolution.
+ */
+ WARN_SUPER_RESOLUTION_USER_COUNT_OVER_LIMITATION = 1611,
+ /** 1612: The device is not supported.
+ */
+ WARN_SUPER_RESOLUTION_DEVICE_NOT_SUPPORTED = 1612,
+
+ WARN_RTM_LOGIN_TIMEOUT = 2005,
+ WARN_RTM_KEEP_ALIVE_TIMEOUT = 2009
+};
+
+/** Error code.
+*/
+enum ERROR_CODE_TYPE
+{
+ /** 0: No error occurs.
+ */
+ ERR_OK = 0,
+ //1~1000
+ /** 1: A general error occurs (no specified reason).
+ */
+ ERR_FAILED = 1,
+ /** 2: An invalid parameter is used. For example, the specific channel name includes illegal characters.
+ */
+ ERR_INVALID_ARGUMENT = 2,
+ /** 3: The SDK module is not ready. Possible solutions:
+
+ - Check the audio device.
+ - Check the completeness of the application.
+ - Re-initialize the RTC engine.
+ */
+ ERR_NOT_READY = 3,
+ /** 4: The SDK does not support this function.
+ */
+ ERR_NOT_SUPPORTED = 4,
+ /** 5: The request is rejected.
+ */
+ ERR_REFUSED = 5,
+ /** 6: The buffer size is not big enough to store the returned data.
+ */
+ ERR_BUFFER_TOO_SMALL = 6,
+ /** 7: The SDK is not initialized before calling this method.
+ */
+ ERR_NOT_INITIALIZED = 7,
+ /** 9: No permission exists. Check if the user has granted access to the audio or video device.
+ */
+ ERR_NO_PERMISSION = 9,
+ /** 10: An API method timeout occurs. Some API methods require the SDK to return the execution result, and this error occurs if the request takes too long (more than 10 seconds) for the SDK to process.
+ */
+ ERR_TIMEDOUT = 10,
+ /** 11: The request is canceled. This is for internal SDK use only, and it does not return to the application through any method or callback.
+ */
+ ERR_CANCELED = 11,
+ /** 12: The method is called too often. This is for internal SDK use only, and it does not return to the application through any method or callback.
+ */
+ ERR_TOO_OFTEN = 12,
+ /** 13: The SDK fails to bind to the network socket. This is for internal SDK use only, and it does not return to the application through any method or callback.
+ */
+ ERR_BIND_SOCKET = 13,
+ /** 14: The network is unavailable. This is for internal SDK use only, and it does not return to the application through any method or callback.
+ */
+ ERR_NET_DOWN = 14,
+ /** 15: No network buffers are available. This is for internal SDK internal use only, and it does not return to the application through any method or callback.
+ */
+ ERR_NET_NOBUFS = 15,
+ /** 17: The request to join the channel is rejected. This error usually occurs when the user is already in the channel, and still calls the method to join the channel, for example, \ref agora::rtc::IRtcEngine::joinChannel "joinChannel".
+ */
+ ERR_JOIN_CHANNEL_REJECTED = 17,
+ /** 18: The request to leave the channel is rejected.
+
+ This error usually occurs:
+
+ - When the user has left the channel and still calls \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" to leave the channel. In this case, stop calling \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel".
+ - When the user has not joined the channel and still calls \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" to leave the channel. In this case, no extra operation is needed.
+ */
+ ERR_LEAVE_CHANNEL_REJECTED = 18,
+ /** 19: Resources are occupied and cannot be reused.
+ */
+ ERR_ALREADY_IN_USE = 19,
+ /** 20: The SDK gives up the request due to too many requests.
+ */
+ ERR_ABORTED = 20,
+ /** 21: In Windows, specific firewall settings can cause the SDK to fail to initialize and crash.
+ */
+ ERR_INIT_NET_ENGINE = 21,
+ /** 22: The application uses too much of the system resources and the SDK fails to allocate the resources.
+ */
+ ERR_RESOURCE_LIMITED = 22,
+ /** 101: The specified App ID is invalid. Please try to rejoin the channel with a valid App ID.
+ */
+ ERR_INVALID_APP_ID = 101,
+ /** 102: The specified channel name is invalid. Please try to rejoin the channel with a valid channel name.
+ */
+ ERR_INVALID_CHANNEL_NAME = 102,
+ /** **DEPRECATED** 109: Deprecated as of v2.4.1. Use CONNECTION_CHANGED_TOKEN_EXPIRED(9) in the \ref agora::rtc::IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged" callback instead.
+
+ The token expired due to one of the following reasons:
+
+ - Authorized Timestamp expired: The timestamp is represented by the number of seconds elapsed since 1/1/1970. The user can use the Token to access the Agora service within five minutes after the Token is generated. If the user does not access the Agora service after five minutes, this Token is no longer valid.
+ - Call Expiration Timestamp expired: The timestamp is the exact time when a user can no longer use the Agora service (for example, when a user is forced to leave an ongoing call). When a value is set for the Call Expiration Timestamp, it does not mean that the token will expire, but that the user will be banned from the channel.
+ */
+ ERR_TOKEN_EXPIRED = 109,
+ /** **DEPRECATED** 110: Deprecated as of v2.4.1. Use CONNECTION_CHANGED_INVALID_TOKEN(8) in the \ref agora::rtc::IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged" callback instead.
+
+ The token is invalid due to one of the following reasons:
+
+ - The App Certificate for the project is enabled in Console, but the user is still using the App ID. Once the App Certificate is enabled, the user must use a token.
+ - The uid is mandatory, and users must set the same uid as the one set in the \ref agora::rtc::IRtcEngine::joinChannel "joinChannel" method.
+ */
+ ERR_INVALID_TOKEN = 110,
+ /** 111: The internet connection is interrupted. This applies to the Agora Web SDK only.
+ */
+ ERR_CONNECTION_INTERRUPTED = 111, // only used in web sdk
+ /** 112: The internet connection is lost. This applies to the Agora Web SDK only.
+ */
+ ERR_CONNECTION_LOST = 112, // only used in web sdk
+ /** 113: The user is not in the channel when calling the \ref agora::rtc::IRtcEngine::sendStreamMessage "sendStreamMessage" or \ref agora::rtc::IRtcEngine::getUserInfoByUserAccount "getUserInfoByUserAccount" method.
+ */
+ ERR_NOT_IN_CHANNEL = 113,
+ /** 114: The size of the sent data is over 1024 bytes when the user calls the \ref agora::rtc::IRtcEngine::sendStreamMessage "sendStreamMessage" method.
+ */
+ ERR_SIZE_TOO_LARGE = 114,
+ /** 115: The bitrate of the sent data exceeds the limit of 6 Kbps when the user calls the \ref agora::rtc::IRtcEngine::sendStreamMessage "sendStreamMessage" method.
+ */
+ ERR_BITRATE_LIMIT = 115,
+ /** 116: Too many data streams (over 5 streams) are created when the user calls the \ref agora::rtc::IRtcEngine::createDataStream "createDataStream" method.
+ */
+ ERR_TOO_MANY_DATA_STREAMS = 116,
+ /** 117: The data stream transmission timed out.
+ */
+ ERR_STREAM_MESSAGE_TIMEOUT = 117,
+ /** 119: Switching roles fail. Please try to rejoin the channel.
+ */
+ ERR_SET_CLIENT_ROLE_NOT_AUTHORIZED = 119,
+ /** 120: Decryption fails. The user may have used a different encryption password to join the channel. Check your settings or try rejoining the channel.
+ */
+ ERR_DECRYPTION_FAILED = 120,
+ /** 123: The client is banned by the server.
+ */
+ ERR_CLIENT_IS_BANNED_BY_SERVER = 123,
+ /** 124: Incorrect watermark file parameter.
+ */
+ ERR_WATERMARK_PARAM = 124,
+ /** 125: Incorrect watermark file path.
+ */
+ ERR_WATERMARK_PATH = 125,
+ /** 126: Incorrect watermark file format.
+ */
+ ERR_WATERMARK_PNG = 126,
+ /** 127: Incorrect watermark file information.
+ */
+ ERR_WATERMARKR_INFO = 127,
+ /** 128: Incorrect watermark file data format.
+ */
+ ERR_WATERMARK_ARGB = 128,
+ /** 129: An error occurs in reading the watermark file.
+ */
+ ERR_WATERMARK_READ = 129,
+ /** 130: Encryption is enabled when the user calls the \ref agora::rtc::IRtcEngine::addPublishStreamUrl "addPublishStreamUrl" method (CDN live streaming does not support encrypted streams).
+ */
+ ERR_ENCRYPTED_STREAM_NOT_ALLOWED_PUBLISH = 130,
+ /** 134: The user account is invalid. */
+ ERR_INVALID_USER_ACCOUNT = 134,
+
+ /** 151: CDN related errors. Remove the original URL address and add a new one by calling the \ref agora::rtc::IRtcEngine::removePublishStreamUrl "removePublishStreamUrl" and \ref agora::rtc::IRtcEngine::addPublishStreamUrl "addPublishStreamUrl" methods.
+ */
+ ERR_PUBLISH_STREAM_CDN_ERROR = 151,
+ /** 152: The host publishes more than 10 URLs. Delete the unnecessary URLs before adding new ones.
+ */
+ ERR_PUBLISH_STREAM_NUM_REACH_LIMIT = 152,
+ /** 153: The host manipulates other hosts' URLs. Check your app logic.
+ */
+ ERR_PUBLISH_STREAM_NOT_AUTHORIZED = 153,
+ /** 154: An error occurs in Agora's streaming server. Call the addPublishStreamUrl method to publish the streaming again.
+ */
+ ERR_PUBLISH_STREAM_INTERNAL_SERVER_ERROR = 154,
+ /** 155: The server fails to find the stream.
+ */
+ ERR_PUBLISH_STREAM_NOT_FOUND = 155,
+ /** 156: The format of the RTMP stream URL is not supported. Check whether the URL format is correct.
+ */
+ ERR_PUBLISH_STREAM_FORMAT_NOT_SUPPORTED = 156,
+
+ //signaling: 400~600
+ /**
+ */
+ ERR_LOGOUT_OTHER = 400, //
+ /** 401: The user logged out.
+ */
+ ERR_LOGOUT_USER = 401, // logout by user
+ /** 402: Network failure.
+ */
+ ERR_LOGOUT_NET = 402, // network failure
+ /** 403: Logged in another device.
+ */
+ ERR_LOGOUT_KICKED = 403, // login in other device
+ /**
+ */
+ ERR_LOGOUT_PACKET = 404, //
+ /** 405: The token expired.
+ */
+ ERR_LOGOUT_TOKEN_EXPIRED = 405, // token expired
+ /**
+ */
+ ERR_LOGOUT_OLDVERSION = 406, //
+ /**
+ */
+ ERR_LOGOUT_TOKEN_WRONG = 407,
+ /**
+ */
+ ERR_LOGOUT_ALREADY_LOGOUT = 408,
+ /**
+ */
+ ERR_LOGIN_OTHER = 420,
+ /**
+ */
+ ERR_LOGIN_NET = 421,
+ /**
+ */
+ ERR_LOGIN_FAILED = 422,
+ /**
+ */
+ ERR_LOGIN_CANCELED = 423,
+ /**
+ */
+ ERR_LOGIN_TOKEN_EXPIRED = 424,
+ /**
+ */
+ ERR_LOGIN_OLD_VERSION = 425,
+ /**
+ */
+ ERR_LOGIN_TOKEN_WRONG = 426,
+ /**
+ */
+ ERR_LOGIN_TOKEN_KICKED = 427,
+ /**
+ */
+ ERR_LOGIN_ALREADY_LOGIN = 428,
+ /**
+ */
+ ERR_JOIN_CHANNEL_OTHER = 440,
+ /**
+ */
+ ERR_SEND_MESSAGE_OTHER = 440,
+ /**
+ */
+ ERR_SEND_MESSAGE_TIMEOUT = 441,
+ /**
+ */
+ ERR_QUERY_USERNUM_OTHER = 450,
+ /**
+ */
+ ERR_QUERY_USERNUM_TIMEOUT = 451,
+ /**
+ */
+ ERR_QUERY_USERNUM_BYUSER = 452,
+ /**
+ */
+ ERR_LEAVE_CHANNEL_OTHER = 460,
+ /**
+ */
+ ERR_LEAVE_CHANNEL_KICKED = 461,
+ /**
+ */
+ ERR_LEAVE_CHANNEL_BYUSER = 462,
+ /**
+ */
+ ERR_LEAVE_CHANNEL_LOGOUT = 463,
+ /**
+ */
+ ERR_LEAVE_CHANNEL_DISCONNECTED = 464,
+ /**
+ */
+ ERR_INVITE_OTHER = 470,
+ /**
+ */
+ ERR_INVITE_REINVITE = 471,
+ /**
+ */
+ ERR_INVITE_NET = 472,
+ /**
+ */
+ ERR_INVITE_PEER_OFFLINE = 473,
+ ERR_INVITE_TIMEOUT = 474,
+ ERR_INVITE_CANT_RECV = 475,
+
+
+ //1001~2000
+ /** 1001: Fails to load the media engine.
+ */
+ ERR_LOAD_MEDIA_ENGINE = 1001,
+ /** 1002: Fails to start the call after enabling the media engine.
+ */
+ ERR_START_CALL = 1002,
+ /** **DEPRECATED** 1003: Fails to start the camera.
+
+ Deprecated as of v2.4.1. Use LOCAL_VIDEO_STREAM_ERROR_CAPTURE_FAILURE(4) in the \ref agora::rtc::IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged" callback instead.
+ */
+ ERR_START_CAMERA = 1003,
+ /** 1004: Fails to start the video rendering module.
+ */
+ ERR_START_VIDEO_RENDER = 1004,
+ /** 1005: A general error occurs in the Audio Device Module (no specified reason). Check if the audio device is used by another application, or try rejoining the channel.
+ */
+ ERR_ADM_GENERAL_ERROR = 1005,
+ /** 1006: Audio Device Module: An error occurs in using the Java resources.
+ */
+ ERR_ADM_JAVA_RESOURCE = 1006,
+ /** 1007: Audio Device Module: An error occurs in setting the sampling frequency.
+ */
+ ERR_ADM_SAMPLE_RATE = 1007,
+ /** 1008: Audio Device Module: An error occurs in initializing the playback device.
+ */
+ ERR_ADM_INIT_PLAYOUT = 1008,
+ /** 1009: Audio Device Module: An error occurs in starting the playback device.
+ */
+ ERR_ADM_START_PLAYOUT = 1009,
+ /** 1010: Audio Device Module: An error occurs in stopping the playback device.
+ */
+ ERR_ADM_STOP_PLAYOUT = 1010,
+ /** 1011: Audio Device Module: An error occurs in initializing the recording device.
+ */
+ ERR_ADM_INIT_RECORDING = 1011,
+ /** 1012: Audio Device Module: An error occurs in starting the recording device.
+ */
+ ERR_ADM_START_RECORDING = 1012,
+ /** 1013: Audio Device Module: An error occurs in stopping the recording device.
+ */
+ ERR_ADM_STOP_RECORDING = 1013,
+ /** 1015: Audio Device Module: A playback error occurs. Check your playback device and try rejoining the channel.
+ */
+ ERR_ADM_RUNTIME_PLAYOUT_ERROR = 1015,
+ /** 1017: Audio Device Module: A recording error occurs.
+ */
+ ERR_ADM_RUNTIME_RECORDING_ERROR = 1017,
+ /** 1018: Audio Device Module: Fails to record.
+ */
+ ERR_ADM_RECORD_AUDIO_FAILED = 1018,
+ /** 1022: Audio Device Module: An error occurs in initializing the
+ * loopback device.
+ */
+ ERR_ADM_INIT_LOOPBACK = 1022,
+ /** 1023: Audio Device Module: An error occurs in starting the loopback
+ * device.
+ */
+ ERR_ADM_START_LOOPBACK = 1023,
+ /** 1027: Audio Device Module: No recording permission exists. Check if the
+ * recording permission is granted.
+ */
+ ERR_ADM_NO_PERMISSION = 1027,
+ /** 1033: Audio device module: The device is occupied.
+ */
+ ERR_ADM_RECORD_AUDIO_IS_ACTIVE = 1033,
+ /** 1101: Audio device module: A fatal exception occurs.
+ */
+ ERR_ADM_ANDROID_JNI_JAVA_RESOURCE = 1101,
+ /** 1108: Audio device module: The recording frequency is lower than 50.
+ * 0 indicates that the recording is not yet started. We recommend
+ * checking your recording permission.
+ */
+ ERR_ADM_ANDROID_JNI_NO_RECORD_FREQUENCY = 1108,
+ /** 1109: The playback frequency is lower than 50. 0 indicates that the
+ * playback is not yet started. We recommend checking if you have created
+ * too many AudioTrack instances.
+ */
+ ERR_ADM_ANDROID_JNI_NO_PLAYBACK_FREQUENCY = 1109,
+ /** 1111: Audio device module: AudioRecord fails to start up. A ROM system
+ * error occurs. We recommend the following options to debug:
+ * - Restart your App.
+ * - Restart your cellphone.
+ * - Check your recording permission.
+ */
+ ERR_ADM_ANDROID_JNI_JAVA_START_RECORD = 1111,
+ /** 1112: Audio device module: AudioTrack fails to start up. A ROM system
+ * error occurs. We recommend the following options to debug:
+ * - Restart your App.
+ * - Restart your cellphone.
+ * - Check your playback permission.
+ */
+ ERR_ADM_ANDROID_JNI_JAVA_START_PLAYBACK = 1112,
+ /** 1115: Audio device module: AudioRecord returns error. The SDK will
+ * automatically restart AudioRecord. */
+ ERR_ADM_ANDROID_JNI_JAVA_RECORD_ERROR = 1115,
+ /** **DEPRECATED** */
+ ERR_ADM_ANDROID_OPENSL_CREATE_ENGINE = 1151,
+ /** **DEPRECATED** */
+ ERR_ADM_ANDROID_OPENSL_CREATE_AUDIO_RECORDER = 1153,
+ /** **DEPRECATED** */
+ ERR_ADM_ANDROID_OPENSL_START_RECORDER_THREAD = 1156,
+ /** **DEPRECATED** */
+ ERR_ADM_ANDROID_OPENSL_CREATE_AUDIO_PLAYER = 1157,
+ /** **DEPRECATED** */
+ ERR_ADM_ANDROID_OPENSL_START_PLAYER_THREAD = 1160,
+ /** 1201: Audio device module: The current device does not support audio
+ * input, possibly because you have mistakenly configured the audio session
+ * category, or because some other app is occupying the input device. We
+ * recommend terminating all background apps and re-joining the channel. */
+ ERR_ADM_IOS_INPUT_NOT_AVAILABLE = 1201,
+ /** 1206: Audio device module: Cannot activate the Audio Session.*/
+ ERR_ADM_IOS_ACTIVATE_SESSION_FAIL = 1206,
+ /** 1210: Audio device module: Fails to initialize the audio device,
+ * normally because the audio device parameters are wrongly set.*/
+ ERR_ADM_IOS_VPIO_INIT_FAIL = 1210,
+ /** 1213: Audio device module: Fails to re-initialize the audio device,
+ * normally because the audio device parameters are wrongly set.*/
+ ERR_ADM_IOS_VPIO_REINIT_FAIL = 1213,
+ /** 1214: Fails to re-start up the Audio Unit, possibly because the audio
+ * session category is not compatible with the settings of the Audio Unit.
+ */
+ ERR_ADM_IOS_VPIO_RESTART_FAIL = 1214,
+ ERR_ADM_IOS_SET_RENDER_CALLBACK_FAIL = 1219,
+ /** **DEPRECATED** */
+ ERR_ADM_IOS_SESSION_SAMPLERATR_ZERO = 1221,
+ /** 1301: Audio device module: An audio driver abnomality or a
+ * compatibility issue occurs. Solutions: Disable and restart the audio
+ * device, or reboot the system.*/
+ ERR_ADM_WIN_CORE_INIT = 1301,
+ /** 1303: Audio device module: A recording driver abnomality or a
+ * compatibility issue occurs. Solutions: Disable and restart the audio
+ * device, or reboot the system. */
+ ERR_ADM_WIN_CORE_INIT_RECORDING = 1303,
+ /** 1306: Audio device module: A playout driver abnomality or a
+ * compatibility issue occurs. Solutions: Disable and restart the audio
+ * device, or reboot the system. */
+ ERR_ADM_WIN_CORE_INIT_PLAYOUT = 1306,
+ /** 1307: Audio device module: No audio device is available. Solutions:
+ * Plug in a proper audio device. */
+ ERR_ADM_WIN_CORE_INIT_PLAYOUT_NULL = 1307,
+ /** 1309: Audio device module: An audio driver abnomality or a
+ * compatibility issue occurs. Solutions: Disable and restart the audio
+ * device, or reboot the system. */
+ ERR_ADM_WIN_CORE_START_RECORDING = 1309,
+ /** 1311: Audio device module: Insufficient system memory or poor device
+ * performance. Solutions: Reboot the system or replace the device.
+ */
+ ERR_ADM_WIN_CORE_CREATE_REC_THREAD = 1311,
+ /** 1314: Audio device module: An audio driver abnormality occurs.
+ * Solutions:
+ * - Disable and then re-enable the audio device.
+ * - Reboot the system.
+ * - Upgrade your audio card driver.*/
+ ERR_ADM_WIN_CORE_CAPTURE_NOT_STARTUP = 1314,
+ /** 1319: Audio device module: Insufficient system memory or poor device
+ * performance. Solutions: Reboot the system or replace the device. */
+ ERR_ADM_WIN_CORE_CREATE_RENDER_THREAD = 1319,
+ /** 1320: Audio device module: An audio driver abnormality occurs.
+ * Solutions:
+ * - Disable and then re-enable the audio device.
+ * - Reboot the system.
+ * - Replace the device. */
+ ERR_ADM_WIN_CORE_RENDER_NOT_STARTUP = 1320,
+ /** 1322: Audio device module: No audio sampling device is available.
+ * Solutions: Plug in a proper recording device. */
+ ERR_ADM_WIN_CORE_NO_RECORDING_DEVICE = 1322,
+ /** 1323: Audio device module: No audio playout device is available.
+ * Solutions: Plug in a proper playback device.*/
+ ERR_ADM_WIN_CORE_NO_PLAYOUT_DEVICE = 1323,
+ /** 1351: Audio device module: An audio driver abnormality or a
+ * compatibility issue occurs. Solutions:
+ * - Disable and then re-enable the audio device.
+ * - Reboot the system.
+ * - Upgrade your audio card driver. */
+ ERR_ADM_WIN_WAVE_INIT = 1351,
+ /** 1353: Audio device module: An audio driver abnormality occurs.
+ * Solutions:
+ * - Disable and then re-enable the audio device.
+ * - Reboot the system.
+ * - Upgrade your audio card driver. */
+ ERR_ADM_WIN_WAVE_INIT_RECORDING = 1353,
+ /** 1354: Audio device module: An audio driver abnormality occurs.
+ * Solutions:
+ * - Disable and then re-enable the audio device.
+ * - Reboot the system.
+ * - Upgrade your audio card driver. */
+ ERR_ADM_WIN_WAVE_INIT_MICROPHONE = 1354,
+ /** 1355: Audio device module: An audio driver abnormality occurs.
+ * Solutions:
+ * - Disable and then re-enable the audio device.
+ * - Reboot the system.
+ * - Upgrade your audio card driver. */
+ ERR_ADM_WIN_WAVE_INIT_PLAYOUT = 1355,
+ /** 1356: Audio device module: An audio driver abnormality occurs.
+ * Solutions:
+ * - Disable and then re-enable the audio device.
+ * - Reboot the system.
+ * - Upgrade your audio card driver. */
+ ERR_ADM_WIN_WAVE_INIT_SPEAKER = 1356,
+ /** 1357: Audio device module: An audio driver abnormality occurs.
+ * Solutions:
+ * - Disable and then re-enable the audio device.
+ * - Reboot the system.
+ * - Upgrade your audio card driver. */
+ ERR_ADM_WIN_WAVE_START_RECORDING = 1357,
+ /** 1358: Audio device module: An audio driver abnormality occurs.
+ * Solutions:
+ * - Disable and then re-enable the audio device.
+ * - Reboot the system.
+ * - Upgrade your audio card driver.*/
+ ERR_ADM_WIN_WAVE_START_PLAYOUT = 1358,
+ /** 1359: Audio Device Module: No recording device exists.
+ */
+ ERR_ADM_NO_RECORDING_DEVICE = 1359,
+ /** 1360: Audio Device Module: No playback device exists.
+ */
+ ERR_ADM_NO_PLAYOUT_DEVICE = 1360,
+
+ // VDM error code starts from 1500
+ /** 1501: Video Device Module: The camera is unauthorized.
+ */
+ ERR_VDM_CAMERA_NOT_AUTHORIZED = 1501,
+
+ // VDM error code starts from 1500
+ /** **DEPRECATED** 1502: Video Device Module: The camera in use.
+
+ Deprecated as of v2.4.1. Use LOCAL_VIDEO_STREAM_ERROR_DEVICE_BUSY(3) in the \ref agora::rtc::IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged" callback instead.
+ */
+ ERR_VDM_WIN_DEVICE_IN_USE = 1502,
+
+ // VCM error code starts from 1600
+ /** 1600: Video Device Module: An unknown error occurs.
+ */
+ ERR_VCM_UNKNOWN_ERROR = 1600,
+ /** 1601: Video Device Module: An error occurs in initializing the video encoder.
+ */
+ ERR_VCM_ENCODER_INIT_ERROR = 1601,
+ /** 1602: Video Device Module: An error occurs in encoding.
+ */
+ ERR_VCM_ENCODER_ENCODE_ERROR = 1602,
+ /** 1603: Video Device Module: An error occurs in setting the video encoder.
+ */
+ ERR_VCM_ENCODER_SET_ERROR = 1603,
+};
+
+ /** Output log filter level. */
+enum LOG_FILTER_TYPE
+{
+/** 0: Do not output any log information. */
+ LOG_FILTER_OFF = 0,
+ /** 0x080f: Output all log information.
+ Set your log filter as debug if you want to get the most complete log file. */
+ LOG_FILTER_DEBUG = 0x080f,
+ /** 0x000f: Output CRITICAL, ERROR, WARNING, and INFO level log information.
+ We recommend setting your log filter as this level.
+ */
+ LOG_FILTER_INFO = 0x000f,
+ /** 0x000e: Outputs CRITICAL, ERROR, and WARNING level log information.
+ */
+ LOG_FILTER_WARN = 0x000e,
+ /** 0x000c: Outputs CRITICAL and ERROR level log information. */
+ LOG_FILTER_ERROR = 0x000c,
+ /** 0x0008: Outputs CRITICAL level log information. */
+ LOG_FILTER_CRITICAL = 0x0008,
+ LOG_FILTER_MASK = 0x80f,
+};
+} // namespace agora
+
+#endif
diff --git a/Android/APIExample/lib-raw-data/src/main/cpp/include/IAgoraMediaEngine.h b/Android/APIExample/lib-raw-data/src/main/cpp/include/IAgoraMediaEngine.h
new file mode 100755
index 000000000..5b0b7a531
--- /dev/null
+++ b/Android/APIExample/lib-raw-data/src/main/cpp/include/IAgoraMediaEngine.h
@@ -0,0 +1,227 @@
+#ifndef AGORA_MEDIA_ENGINE_H
+#define AGORA_MEDIA_ENGINE_H
+#if defined _WIN32 || defined __CYGWIN__
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+#else
+#include
+#endif
+
+namespace agora
+{
+namespace media
+{
+
+enum MEDIA_SOURCE_TYPE {
+ AUDIO_PLAYOUT_SOURCE = 0,
+ AUDIO_RECORDING_SOURCE = 1,
+};
+
+class IAudioFrameObserver
+{
+public:
+ enum AUDIO_FRAME_TYPE {
+ FRAME_TYPE_PCM16 = 0, //PCM 16bit little endian
+ };
+ struct AudioFrame {
+ AUDIO_FRAME_TYPE type;
+ int samples; //number of samples in this frame
+ int bytesPerSample; //number of bytes per sample: 2 for PCM16
+ int channels; //number of channels (data are interleaved if stereo)
+ int samplesPerSec; //sampling rate
+ void* buffer; //data buffer
+ int64_t renderTimeMs;
+ int avsync_type;
+ };
+public:
+ virtual bool onRecordAudioFrame(AudioFrame& audioFrame) = 0;
+ virtual bool onPlaybackAudioFrame(AudioFrame& audioFrame) = 0;
+ virtual bool onMixedAudioFrame(AudioFrame& audioFrame) = 0;
+ virtual bool onPlaybackAudioFrameBeforeMixing(unsigned int uid, AudioFrame& audioFrame) = 0;
+};
+
+class IVideoFrameObserver
+{
+public:
+ enum VIDEO_FRAME_TYPE {
+ FRAME_TYPE_YUV420 = 0, //YUV 420 format
+ FRAME_TYPE_YUV422 = 1, //YUV 422P format
+ FRAME_TYPE_RGBA = 2, //RGBA
+ };
+ struct VideoFrame {
+ VIDEO_FRAME_TYPE type;
+ int width; //width of video frame
+ int height; //height of video frame
+ int yStride; //stride of Y data buffer
+ int uStride; //stride of U data buffer
+ int vStride; //stride of V data buffer
+ void* yBuffer; //Y data buffer
+ void* uBuffer; //U data buffer
+ void* vBuffer; //V data buffer
+ int rotation; // rotation of this frame (0, 90, 180, 270)
+ int64_t renderTimeMs;
+ int avsync_type;
+ };
+public:
+ virtual bool onCaptureVideoFrame(VideoFrame& videoFrame) = 0;
+ virtual bool onPreEncodeVideoFrame(VideoFrame& videoFrame) { return true; }
+ virtual bool onRenderVideoFrame(unsigned int uid, VideoFrame& videoFrame) = 0;
+ virtual VIDEO_FRAME_TYPE getVideoFormatPreference() { return FRAME_TYPE_YUV420; }
+ virtual bool getRotationApplied() { return false; }
+ virtual bool getMirrorApplied() { return false; }
+ virtual bool getSmoothRenderingEnabled(){ return false; }
+};
+
+class IVideoFrame
+{
+public:
+ enum PLANE_TYPE {
+ Y_PLANE = 0,
+ U_PLANE = 1,
+ V_PLANE = 2,
+ NUM_OF_PLANES = 3
+ };
+ enum VIDEO_TYPE {
+ VIDEO_TYPE_UNKNOWN = 0,
+ VIDEO_TYPE_I420 = 1,
+ VIDEO_TYPE_IYUV = 2,
+ VIDEO_TYPE_RGB24 = 3,
+ VIDEO_TYPE_ABGR = 4,
+ VIDEO_TYPE_ARGB = 5,
+ VIDEO_TYPE_ARGB4444 = 6,
+ VIDEO_TYPE_RGB565 = 7,
+ VIDEO_TYPE_ARGB1555 = 8,
+ VIDEO_TYPE_YUY2 = 9,
+ VIDEO_TYPE_YV12 = 10,
+ VIDEO_TYPE_UYVY = 11,
+ VIDEO_TYPE_MJPG = 12,
+ VIDEO_TYPE_NV21 = 13,
+ VIDEO_TYPE_NV12 = 14,
+ VIDEO_TYPE_BGRA = 15,
+ VIDEO_TYPE_RGBA = 16,
+ VIDEO_TYPE_I422 = 17,
+ };
+ virtual void release() = 0;
+ virtual const unsigned char* buffer(PLANE_TYPE type) const = 0;
+
+ // Copy frame: If required size is bigger than allocated one, new buffers of
+ // adequate size will be allocated.
+ // Return value: 0 on success ,-1 on error.
+ virtual int copyFrame(IVideoFrame** dest_frame) const = 0;
+
+ // Convert frame
+ // Input:
+ // - src_frame : Reference to a source frame.
+ // - dst_video_type : Type of output video.
+ // - dst_sample_size : Required only for the parsing of MJPG.
+ // - dst_frame : Pointer to a destination frame.
+ // Return value: 0 if OK, < 0 otherwise.
+ // It is assumed that source and destination have equal height.
+ virtual int convertFrame(VIDEO_TYPE dst_video_type, int dst_sample_size, unsigned char* dst_frame) const = 0;
+
+ // Get allocated size per plane.
+ virtual int allocated_size(PLANE_TYPE type) const = 0;
+
+ // Get allocated stride per plane.
+ virtual int stride(PLANE_TYPE type) const = 0;
+
+ // Get frame width.
+ virtual int width() const = 0;
+
+ // Get frame height.
+ virtual int height() const = 0;
+
+ // Get frame timestamp (90kHz).
+ virtual unsigned int timestamp() const = 0;
+
+ // Get render time in milliseconds.
+ virtual int64_t render_time_ms() const = 0;
+
+ // Return true if underlying plane buffers are of zero size, false if not.
+ virtual bool IsZeroSize() const = 0;
+
+ virtual VIDEO_TYPE GetVideoType() const = 0;
+};
+
+class IExternalVideoRenderCallback
+{
+public:
+ virtual void onViewSizeChanged(int width, int height) = 0;
+ virtual void onViewDestroyed() = 0;
+};
+
+struct ExternalVideoRenerContext
+{
+ IExternalVideoRenderCallback* renderCallback;
+ void* view;
+ int renderMode;
+ int zOrder;
+ float left;
+ float top;
+ float right;
+ float bottom;
+};
+
+class IExternalVideoRender
+{
+public:
+ virtual void release() = 0;
+ virtual int initialize() = 0;
+ virtual int deliverFrame(const IVideoFrame& videoFrame, int rotation, bool mirrored) = 0;
+};
+
+class IExternalVideoRenderFactory
+{
+public:
+ virtual IExternalVideoRender* createRenderInstance(const ExternalVideoRenerContext& context) = 0;
+};
+
+struct ExternalVideoFrame
+{
+ enum VIDEO_BUFFER_TYPE
+ {
+ VIDEO_BUFFER_RAW_DATA = 1,
+ };
+
+ enum VIDEO_PIXEL_FORMAT
+ {
+ VIDEO_PIXEL_UNKNOWN = 0,
+ VIDEO_PIXEL_I420 = 1,
+ VIDEO_PIXEL_BGRA = 2,
+
+ VIDEO_PIXEL_NV12 = 8,
+ VIDEO_PIXEL_I422 = 16,
+ };
+
+ VIDEO_BUFFER_TYPE type;
+ VIDEO_PIXEL_FORMAT format;
+ void* buffer;
+ int stride;
+ int height;
+ int cropLeft;
+ int cropTop;
+ int cropRight;
+ int cropBottom;
+ int rotation;
+ long long timestamp;
+};
+
+class IMediaEngine {
+public:
+ virtual void release() = 0;
+ virtual int registerAudioFrameObserver(IAudioFrameObserver* observer) = 0;
+ virtual int registerVideoFrameObserver(IVideoFrameObserver* observer) = 0;
+ virtual int registerVideoRenderFactory(IExternalVideoRenderFactory* factory) = 0;
+ virtual int pushAudioFrame(MEDIA_SOURCE_TYPE type, IAudioFrameObserver::AudioFrame *frame, bool wrap) = 0;
+ virtual int pushAudioFrame(IAudioFrameObserver::AudioFrame *frame) = 0;
+ virtual int pullAudioFrame(IAudioFrameObserver::AudioFrame *frame) = 0;
+
+ virtual int setExternalVideoSource(bool enable, bool useTexture) = 0;
+ virtual int pushVideoFrame(ExternalVideoFrame *frame) = 0;
+};
+
+} //media
+
+} //agora
+
+#endif //AGORA_MEDIA_ENGINE_H
diff --git a/Android/APIExample/lib-raw-data/src/main/cpp/include/IAgoraRtcChannel.h b/Android/APIExample/lib-raw-data/src/main/cpp/include/IAgoraRtcChannel.h
new file mode 100755
index 000000000..b19c71c86
--- /dev/null
+++ b/Android/APIExample/lib-raw-data/src/main/cpp/include/IAgoraRtcChannel.h
@@ -0,0 +1,1203 @@
+//
+// AgoraRtcEngine SDK
+//
+// Copyright (c) 2019 Agora.io. All rights reserved.
+//
+
+#ifndef IAgoraRtcChannel_h
+#define IAgoraRtcChannel_h
+#include "IAgoraRtcEngine.h"
+
+namespace agora {
+namespace rtc {
+/** The channel media options. */
+struct ChannelMediaOptions {
+ /** Determines whether to subscribe to audio streams when the user joins the channel:
+ - true: (Default) Subscribe.
+ - false: Do not subscribe.
+
+ This member serves a similar function to the \ref agora::rtc::IChannel::muteAllRemoteAudioStreams "muteAllRemoteAudioStreams" method. After joining the channel,
+ you can call the `muteAllRemoteAudioStreams` method to set whether to subscribe to audio streams in the channel.
+ */
+ bool autoSubscribeAudio;
+ /** Determines whether to subscribe to video streams when the user joins the channel:
+ - true: (Default) Subscribe.
+ - false: Do not subscribe.
+
+ This member serves a similar function to the \ref agora::rtc::IChannel::muteAllRemoteVideoStreams "muteAllRemoteVideoStreams" method. After joining the channel,
+ you can call the `muteAllRemoteVideoStreams` method to set whether to subscribe to video streams in the channel.
+ */
+ bool autoSubscribeVideo;
+ ChannelMediaOptions()
+ : autoSubscribeAudio(true)
+ , autoSubscribeVideo(true)
+ {}
+};
+/** The IChannel class. */
+class IChannel;
+/** The IChannelEventHandler class. */
+class IChannelEventHandler
+{
+public:
+ virtual ~IChannelEventHandler() {}
+ /** Reports the warning code of `IChannel`.
+
+ @param rtcChannel IChannel
+ @param warn The warning code: #WARN_CODE_TYPE
+ @param msg The warning message.
+
+ */
+ virtual void onChannelWarning(IChannel *rtcChannel, int warn, const char* msg) {
+ (void)rtcChannel;
+ (void)warn;
+ (void)msg;
+ }
+ /** Reports the error code of `IChannel`.
+
+ @param rtcChannel IChannel
+ @param err The error code: #ERROR_CODE_TYPE
+ @param msg The error message.
+ */
+ virtual void onChannelError(IChannel *rtcChannel, int err, const char* msg) {
+ (void)rtcChannel;
+ (void)err;
+ (void)msg;
+ }
+ /** Occurs when a user joins a channel.
+
+ This callback notifies the application that a user joins a specified channel.
+
+ @param rtcChannel IChannel
+ @param uid The user ID. If the `uid` is not specified in the \ref IChannel::joinChannel "joinChannel" method, the server automatically assigns a `uid`.
+
+ @param elapsed Time elapsed (ms) from the local user calling \ref IChannel::joinChannel "joinChannel" until this callback is triggered.
+ */
+ virtual void onJoinChannelSuccess(IChannel *rtcChannel, uid_t uid, int elapsed) {
+ (void)rtcChannel;
+ (void)uid;
+ (void)elapsed;
+ }
+ /** Occurs when a user rejoins the channel after being disconnected due to network problems.
+
+ @param rtcChannel IChannel
+ @param uid The user ID.
+ @param elapsed Time elapsed (ms) from the local user starting to reconnect until this callback is triggered.
+
+ */
+ virtual void onRejoinChannelSuccess(IChannel *rtcChannel, uid_t uid, int elapsed) {
+ (void)rtcChannel;
+ (void)uid;
+ (void)elapsed;
+ }
+ /** Occurs when a user leaves the channel.
+
+ This callback notifies the application that a user leaves the channel when the application calls the \ref agora::rtc::IChannel::leaveChannel "leaveChannel" method.
+
+ The application retrieves information, such as the call duration and statistics.
+
+ @param rtcChannel IChannel
+ @param stats The call statistics: RtcStats.
+ */
+ virtual void onLeaveChannel(IChannel *rtcChannel, const RtcStats& stats) {
+ (void)rtcChannel;
+ (void)stats;
+ }
+ /** Occurs when the user role switches in a live broadcast. For example, from a host to an audience or vice versa.
+
+ This callback notifies the application of a user role switch when the application calls the \ref IChannel::setClientRole "setClientRole" method.
+
+ The SDK triggers this callback when the local user switches the user role by calling the \ref IChannel::setClientRole "setClientRole" method after joining the channel.
+
+ @param rtcChannel IChannel
+ @param oldRole Role that the user switches from: #CLIENT_ROLE_TYPE.
+ @param newRole Role that the user switches to: #CLIENT_ROLE_TYPE.
+ */
+ virtual void onClientRoleChanged(IChannel *rtcChannel, CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole) {
+ (void)rtcChannel;
+ (void)oldRole;
+ (void)newRole;
+ }
+ /** Occurs when a remote user (Communication)/ host (Live Broadcast) joins the channel.
+
+ - Communication profile: This callback notifies the application that another user joins the channel. If other users are already in the channel, the SDK also reports to the application on the existing users.
+ - Live-broadcast profile: This callback notifies the application that the host joins the channel. If other hosts are already in the channel, the SDK also reports to the application on the existing hosts. We recommend limiting the number of hosts to 17.
+
+ The SDK triggers this callback under one of the following circumstances:
+ - A remote user/host joins the channel by calling the \ref agora::rtc::IChannel::joinChannel "joinChannel" method.
+ - A remote user switches the user role to the host by calling the \ref agora::rtc::IChannel::setClientRole "setClientRole" method after joining the channel.
+ - A remote user/host rejoins the channel after a network interruption.
+ - The host injects an online media stream into the channel by calling the \ref agora::rtc::IChannel::addInjectStreamUrl "addInjectStreamUrl" method.
+
+ @note In the Live-broadcast profile:
+ - The host receives this callback when another host joins the channel.
+ - The audience in the channel receives this callback when a new host joins the channel.
+ - When a web application joins the channel, the SDK triggers this callback as long as the web application publishes streams.
+
+ @param rtcChannel IChannel
+ @param uid User ID of the user or host joining the channel.
+ @param elapsed Time delay (ms) from the local user calling the \ref IChannel::joinChannel "joinChannel" method until the SDK triggers this callback.
+ */
+ virtual void onUserJoined(IChannel *rtcChannel, uid_t uid, int elapsed) {
+ (void)rtcChannel;
+ (void)uid;
+ (void)elapsed;
+ }
+ /** Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+
+ Reasons why the user is offline:
+
+ - Leave the channel: When the user/host leaves the channel, the user/host sends a goodbye message. When the message is received, the SDK assumes that the user/host leaves the channel.
+ - Drop offline: When no data packet of the user or host is received for a certain period of time, the SDK assumes that the user/host drops offline. Unreliable network connections may lead to false detections, so we recommend using a signaling system for more reliable offline detection.
+
+ @param rtcChannel IChannel
+ @param uid User ID of the user leaving the channel or going offline.
+ @param reason Reason why the user is offline: #USER_OFFLINE_REASON_TYPE.
+ */
+ virtual void onUserOffline(IChannel *rtcChannel, uid_t uid, USER_OFFLINE_REASON_TYPE reason) {
+ (void)rtcChannel;
+ (void)uid;
+ (void)reason;
+ }
+ /** Occurs when the SDK cannot reconnect to Agora's edge server 10 seconds after its connection to the server is interrupted.
+
+ The SDK triggers this callback when it cannot connect to the server 10 seconds after calling the \ref IChannel::joinChannel "joinChannel" method, whether or not it is in the channel.
+
+ This callback is different from \ref agora::rtc::IChannelEventHandler::onConnectionInterrupted "onConnectionInterrupted":
+
+ - The SDK triggers the \ref agora::rtc::IChannelEventHandler::onConnectionInterrupted "onConnectionInterrupted" callback when it loses connection with the server for more than four seconds after it successfully joins the channel.
+ - The SDK triggers the \ref agora::rtc::IChannelEventHandler::onConnectionLost "onConnectionLost" callback when it loses connection with the server for more than 10 seconds, whether or not it joins the channel.
+
+ If the SDK fails to rejoin the channel 20 minutes after being disconnected from Agora's edge server, the SDK stops rejoining the channel.
+
+ @param rtcChannel IChannel
+ */
+ virtual void onConnectionLost(IChannel *rtcChannel) {
+ (void)rtcChannel;
+ }
+ /** Occurs when the token expires.
+
+ After a token is specified by calling the \ref IChannel::joinChannel "joinChannel" method, if the SDK losses connection with the Agora server due to network issues, the token may expire after a certain period of time and a new token may be required to reconnect to the server.
+
+ This callback notifies the application to generate a new token. Call the \ref IChannel::renewToken "renewToken" method to renew the token.
+
+ @param rtcChannel IChannel
+ */
+ virtual void onRequestToken(IChannel *rtcChannel) {
+ (void)rtcChannel;
+ }
+ /** Occurs when the token expires in 30 seconds.
+
+ The user becomes offline if the token used in the \ref IChannel::joinChannel "joinChannel" method expires. The SDK triggers this callback 30 seconds before the token expires to remind the application to get a new token. Upon receiving this callback, generate a new token on the server and call the \ref IChannel::renewToken "renewToken" method to pass the new token to the SDK.
+
+ @param rtcChannel IChannel
+ @param token Token that expires in 30 seconds.
+ */
+ virtual void onTokenPrivilegeWillExpire(IChannel *rtcChannel, const char* token) {
+ (void)rtcChannel;
+ (void)token;
+ }
+ /** Reports the statistics of the current call.
+
+ The SDK triggers this callback once every two seconds after the user joins the channel.
+
+ @param rtcChannel IChannel
+ @param stats Statistics of the RtcEngine: RtcStats.
+ */
+ virtual void onRtcStats(IChannel *rtcChannel, const RtcStats& stats) {
+ (void)rtcChannel;
+ (void)stats;
+ }
+ /** Reports the last mile network quality of each user in the channel once every two seconds.
+
+ Last mile refers to the connection between the local device and Agora's edge server. This callback reports once every two seconds the last mile network conditions of each user in the channel. If a channel includes multiple users, the SDK triggers this callback as many times.
+
+ @param rtcChannel IChannel
+ @param uid User ID. The network quality of the user with this @p uid is reported. If @p uid is 0, the local network quality is reported.
+ @param txQuality Uplink transmission quality rating of the user in terms of the transmission bitrate, packet loss rate, average RTT (Round-Trip Time), and jitter of the uplink network. @p txQuality is a quality rating helping you understand how well the current uplink network conditions can support the selected VideoEncoderConfiguration. For example, a 1000 Kbps uplink network may be adequate for video frames with a resolution of 640 × 480 and a frame rate of 15 fps in the Live-broadcast profile, but may be inadequate for resolutions higher than 1280 × 720. See #QUALITY_TYPE.
+ @param rxQuality Downlink network quality rating of the user in terms of the packet loss rate, average RTT, and jitter of the downlink network. See #QUALITY_TYPE.
+ */
+ virtual void onNetworkQuality(IChannel *rtcChannel, uid_t uid, int txQuality, int rxQuality) {
+ (void)rtcChannel;
+ (void)uid;
+ (void)txQuality;
+ (void)rxQuality;
+ }
+ /** Reports the statistics of the video stream from each remote user/host.
+ *
+ * The SDK triggers this callback once every two seconds for each remote
+ * user/host. If a channel includes multiple remote users, the SDK
+ * triggers this callback as many times.
+ *
+ * @param rtcChannel IChannel
+ * @param stats Statistics of the remote video stream. See
+ * RemoteVideoStats.
+ */
+ virtual void onRemoteVideoStats(IChannel *rtcChannel, const RemoteVideoStats& stats) {
+ (void)rtcChannel;
+ (void)stats;
+ }
+ /** Reports the statistics of the audio stream from each remote user/host.
+
+ This callback replaces the \ref agora::rtc::IChannelEventHandler::onAudioQuality "onAudioQuality" callback.
+
+ The SDK triggers this callback once every two seconds for each remote user/host. If a channel includes multiple remote users, the SDK triggers this callback as many times.
+
+ @param rtcChannel IChannel
+ @param stats The statistics of the received remote audio streams. See RemoteAudioStats.
+ */
+ virtual void onRemoteAudioStats(IChannel *rtcChannel, const RemoteAudioStats& stats) {
+ (void)rtcChannel;
+ (void)stats;
+ }
+ /** Occurs when the remote audio state changes.
+ *
+ * This callback indicates the state change of the remote audio stream.
+ *
+ * @param rtcChannel IChannel
+ * @param uid ID of the remote user whose audio state changes.
+ * @param state State of the remote audio. See #REMOTE_AUDIO_STATE.
+ * @param reason The reason of the remote audio state change.
+ * See #REMOTE_AUDIO_STATE_REASON.
+ * @param elapsed Time elapsed (ms) from the local user calling the
+ * \ref IChannel::joinChannel "joinChannel" method until the SDK
+ * triggers this callback.
+ */
+ virtual void onRemoteAudioStateChanged(IChannel *rtcChannel, uid_t uid, REMOTE_AUDIO_STATE state, REMOTE_AUDIO_STATE_REASON reason, int elapsed) {
+ (void)rtcChannel;
+ (void)uid;
+ (void)state;
+ (void)reason;
+ (void)elapsed;
+ }
+ /** Reports which user is the loudest speaker.
+
+ If the user enables the audio volume indication by calling the \ref IChannel::enableAudioVolumeIndication(int, int, bool) "enableAudioVolumeIndication" method, this callback returns the @p uid of the active speaker detected by the audio volume detection module of the SDK.
+
+ @note
+ - To receive this callback, you need to call the \ref IChannel::enableAudioVolumeIndication(int, int, bool) "enableAudioVolumeIndication" method.
+ - This callback returns the user ID of the user with the highest voice volume during a period of time, instead of at the moment.
+
+ @param rtcChannel IChannel
+ @param uid User ID of the active speaker. A @p uid of 0 represents the local user.
+ */
+ virtual void onActiveSpeaker(IChannel *rtcChannel, uid_t uid) {
+ (void)rtcChannel;
+ (void)uid;
+ }
+ /** Occurs when the video size or rotation of a specified user changes.
+
+ @param rtcChannel IChannel
+ @param uid User ID of the remote user or local user (0) whose video size or rotation changes.
+ @param width New width (pixels) of the video.
+ @param height New height (pixels) of the video.
+ @param rotation New rotation of the video [0 to 360).
+ */
+ virtual void onVideoSizeChanged(IChannel *rtcChannel, uid_t uid, int width, int height, int rotation) {
+ (void)rtcChannel;
+ (void)uid;
+ (void)width;
+ (void)height;
+ (void)rotation;
+ }
+ /** Occurs when the remote video state changes.
+ *
+ * @param rtcChannel IChannel
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video. See #REMOTE_VIDEO_STATE.
+ * @param reason The reason of the remote video state change. See
+ * #REMOTE_VIDEO_STATE_REASON.
+ * @param elapsed Time elapsed (ms) from the local user calling the
+ * \ref agora::rtc::IChannel::joinChannel "joinChannel" method until the
+ * SDK triggers this callback.
+ */
+ virtual void onRemoteVideoStateChanged(IChannel *rtcChannel, uid_t uid, REMOTE_VIDEO_STATE state, REMOTE_VIDEO_STATE_REASON reason, int elapsed) {
+ (void)rtcChannel;
+ (void)uid;
+ (void)state;
+ (void)reason;
+ (void)elapsed;
+ }
+ /** Occurs when the local user receives the data stream from the remote user within five seconds.
+
+ The SDK triggers this callback when the local user receives the stream message that the remote user sends by calling the \ref agora::rtc::IChannel::sendStreamMessage "sendStreamMessage" method.
+
+ @param rtcChannel IChannel
+ @param uid User ID of the remote user sending the message.
+ @param streamId Stream ID.
+ @param data The data received by the local user.
+ @param length Length of the data in bytes.
+ */
+ virtual void onStreamMessage(IChannel *rtcChannel, uid_t uid, int streamId, const char* data, size_t length) {
+ (void)rtcChannel;
+ (void)uid;
+ (void)streamId;
+ (void)data;
+ (void)length;
+ }
+ /** Occurs when the local user does not receive the data stream from the remote user within five seconds.
+
+ The SDK triggers this callback when the local user fails to receive the stream message that the remote user sends by calling the \ref agora::rtc::IChannel::sendStreamMessage "sendStreamMessage" method.
+
+ @param rtcChannel IChannel
+ @param uid User ID of the remote user sending the message.
+ @param streamId Stream ID.
+ @param code Error code: #ERROR_CODE_TYPE.
+ @param missed Number of lost messages.
+ @param cached Number of incoming cached messages when the data stream is interrupted.
+ */
+ virtual void onStreamMessageError(IChannel *rtcChannel, uid_t uid, int streamId, int code, int missed, int cached) {
+ (void)rtcChannel;
+ (void)uid;
+ (void)streamId;
+ (void)code;
+ (void)missed;
+ (void)cached;
+ }
+ /** Occurs when the state of the media stream relay changes.
+ *
+ * The SDK returns the state of the current media relay with any error
+ * message.
+ * @param rtcChannel IChannel
+ * @param state The state code in #CHANNEL_MEDIA_RELAY_STATE.
+ * @param code The error code in #CHANNEL_MEDIA_RELAY_ERROR.
+ */
+ virtual void onChannelMediaRelayStateChanged(IChannel *rtcChannel, CHANNEL_MEDIA_RELAY_STATE state,CHANNEL_MEDIA_RELAY_ERROR code) {
+ (void)rtcChannel;
+ (void)state;
+ (void)code;
+ }
+ /** Reports events during the media stream relay.
+ * @param rtcChannel IChannel
+ * @param code The event code in #CHANNEL_MEDIA_RELAY_EVENT.
+ */
+ virtual void onChannelMediaRelayEvent(IChannel *rtcChannel, CHANNEL_MEDIA_RELAY_EVENT code) {
+ (void)rtcChannel;
+ (void)code;
+ }
+ /**
+ Occurs when the state of the RTMP streaming changes.
+
+ The SDK triggers this callback to report the result of the local user calling the \ref agora::rtc::IChannel::addPublishStreamUrl "addPublishStreamUrl" or \ref agora::rtc::IChannel::removePublishStreamUrl "removePublishStreamUrl" method.
+
+ This callback indicates the state of the RTMP streaming. When exceptions occur, you can troubleshoot issues by referring to the detailed error descriptions in the *errCode* parameter.
+
+ @param rtcChannel IChannel
+ @param url The RTMP URL address.
+ @param state The RTMP streaming state. See: #RTMP_STREAM_PUBLISH_STATE.
+ @param errCode The detailed error information for streaming. See: #RTMP_STREAM_PUBLISH_ERROR.
+ */
+ virtual void onRtmpStreamingStateChanged(IChannel *rtcChannel, const char *url, RTMP_STREAM_PUBLISH_STATE state, RTMP_STREAM_PUBLISH_ERROR errCode) {
+ (void)rtcChannel;
+ (void) url;
+ (RTMP_STREAM_PUBLISH_STATE) state;
+ (RTMP_STREAM_PUBLISH_ERROR) errCode;
+ }
+ /** Occurs when the publisher's transcoding is updated.
+
+ When the `LiveTranscoding` class in the \ref agora::rtc::IChannel::setLiveTranscoding "setLiveTranscoding" method updates, the SDK triggers the `onTranscodingUpdated` callback to report the update information to the local host.
+
+ @note If you call the `setLiveTranscoding` method to set the LiveTranscoding class for the first time, the SDK does not trigger the `onTranscodingUpdated` callback.
+
+ @param rtcChannel IChannel
+ */
+ virtual void onTranscodingUpdated(IChannel *rtcChannel) {
+ (void)rtcChannel;
+ }
+ /** Occurs when a voice or video stream URL address is added to a live broadcast.
+
+ @param rtcChannel IChannel
+ @param url The URL address of the externally injected stream.
+ @param uid User ID.
+ @param status State of the externally injected stream: #INJECT_STREAM_STATUS.
+ */
+ virtual void onStreamInjectedStatus(IChannel *rtcChannel, const char* url, uid_t uid, int status) {
+ (void)rtcChannel;
+ (void)url;
+ (void)uid;
+ (void)status;
+ }
+ /** Occurs when the remote media stream falls back to audio-only stream
+ * due to poor network conditions or switches back to the video stream
+ * after the network conditions improve.
+ *
+ * If you call
+ * \ref IChannel::setRemoteSubscribeFallbackOption
+ * "setRemoteSubscribeFallbackOption" and set
+ * @p option as #STREAM_FALLBACK_OPTION_AUDIO_ONLY, the SDK triggers this
+ * callback when the remote media stream falls back to audio-only mode due
+ * to poor uplink conditions, or when the remote media stream switches
+ * back to the video after the uplink network condition improves.
+ *
+ * @note Once the remote media stream switches to the low stream due to
+ * poor network conditions, you can monitor the stream switch between a
+ * high and low stream in the RemoteVideoStats callback.
+ * @param rtcChannel IChannel
+ * @param uid ID of the remote user sending the stream.
+ * @param isFallbackOrRecover Whether the remotely subscribed media stream
+ * falls back to audio-only or switches back to the video:
+ * - true: The remotely subscribed media stream falls back to audio-only
+ * due to poor network conditions.
+ * - false: The remotely subscribed media stream switches back to the
+ * video stream after the network conditions improved.
+ */
+ virtual void onRemoteSubscribeFallbackToAudioOnly(IChannel *rtcChannel, uid_t uid, bool isFallbackOrRecover) {
+ (void)rtcChannel;
+ (void)uid;
+ (void)isFallbackOrRecover;
+ }
+ /** Occurs when the connection state between the SDK and the server changes.
+
+ @param rtcChannel IChannel
+ @param state See #CONNECTION_STATE_TYPE.
+ @param reason See #CONNECTION_CHANGED_REASON_TYPE.
+ */
+ virtual void onConnectionStateChanged(IChannel *rtcChannel,
+ CONNECTION_STATE_TYPE state,
+ CONNECTION_CHANGED_REASON_TYPE reason) {
+ (void)rtcChannel;
+ (void)state;
+ (void)reason;
+ }
+};
+
+/** The IChannel class. */
+class IChannel
+{
+public:
+ virtual ~IChannel() {}
+ /** Releases all IChannel resources.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ - `ERR_NOT_INITIALIZED (7)`: The SDK is not initialized before calling this method.
+ */
+ virtual int release() = 0;
+ /** Sets the channel event handler.
+
+ After setting the channel event handler, you can listen for channel events and receive the statistics of the corresponding `IChannel` object.
+
+ @param channelEh The event handler of the `IChannel` object. For details, see IChannelEventHandler.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setChannelEventHandler(IChannelEventHandler *channelEh) = 0;
+ /** Joins the channel with a user ID.
+
+ This method differs from the `joinChannel` method in the `IRtcEngine` class in the following aspects:
+
+ | IChannel::joinChannel | IRtcEngine::joinChannel |
+ |------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
+ | Does not contain the `channelId` parameter, because `channelId` is specified when creating the `IChannel` object. | Contains the `channelId` parameter, which specifies the channel to join. |
+ | Contains the `options` parameter, which decides whether to subscribe to all streams before joining the channel. | Does not contain the `options` parameter. By default, users subscribe to all streams when joining the channel. |
+ | Users can join multiple channels simultaneously by creating multiple `IChannel` objects and calling the `joinChannel` method of each object. | Users can join only one channel. |
+ | By default, the SDK does not publish any stream after the user joins the channel. You need to call the publish method to do that. | By default, the SDK publishes streams once the user joins the channel. |
+
+ @note
+ - If you are already in a channel, you cannot rejoin it with the same `uid`.
+ - We recommend using different UIDs for different channels.
+ - If you want to join the same channel from different devices, ensure that the UIDs in all devices are different.
+ - Ensure that the app ID you use to generate the token is the same with the app ID used when creating the `IChannel` object.
+
+ @param token The token for authentication:
+ - In situations not requiring high security: You can use the temporary token generated at Console. For details, see [Get a temporary token](https://docs.agora.io/en/Agora%20Platform/token?platfor%20*%20m=All%20Platforms#get-a-temporary-token).
+ - In situations requiring high security: Set it as the token generated at your server. For details, see [Generate a token](https://docs.agora.io/en/Agora%20Platform/token?platfor%20*%20m=All%20Platforms#get-a-token).
+ @param info (Optional) Additional information about the channel. This parameter can be set as null. Other users in the channel do not receive this information.
+ @param uid The user ID. A 32-bit unsigned integer with a value ranging from 1 to (232-1). This parameter must be unique. If `uid` is not assigned (or set as `0`), the SDK assigns a `uid` and reports it in the \ref agora::rtc::IChannelEventHandler::onJoinChannelSuccess "onJoinChannelSuccess" callback. The app must maintain this user ID.
+ @param options The channel media options: ChannelMediaOptions.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ - #ERR_INVALID_ARGUMENT (-2)
+ - #ERR_NOT_READY (-3)
+ - #ERR_REFUSED (-5)
+ */
+ virtual int joinChannel(const char* token,
+ const char* info,
+ uid_t uid,
+ const ChannelMediaOptions& options) = 0;
+ /** Joins the channel with a user account.
+
+ After the user successfully joins the channel, the SDK triggers the following callbacks:
+
+ - The local client: \ref agora::rtc::IChannelEventHandler::onLocalUserRegistered "onLocalUserRegistered" and \ref agora::rtc::IChannelEventHandler::onJoinChannelSuccess "onJoinChannelSuccess" .
+ The remote client: \ref agora::rtc::IChannelEventHandler::onUserJoined "onUserJoined" and \ref agora::rtc::IChannelEventHandler::onUserInfoUpdated "onUserInfoUpdated" , if the user joining the channel is in the Communication profile, or is a BROADCASTER in the Live Broadcast profile.
+
+ @note To ensure smooth communication, use the same parameter type to identify the user. For example, if a user joins the channel with a user ID, then ensure all the other users use the user ID too. The same applies to the user account.
+ If a user joins the channel with the Agora Web SDK, ensure that the uid of the user is set to the same parameter type.
+
+ @param token The token generated at your server:
+ - For low-security requirements: You can use the temporary token generated at Console. For details, see [Get a temporary toke](https://docs.agora.io/en/Voice/token?platform=All%20Platforms#get-a-temporary-token).
+ - For high-security requirements: Set it as the token generated at your server. For details, see [Get a token](https://docs.agora.io/en/Voice/token?platform=All%20Platforms#get-a-token).
+ @param channelId The channel name. The maximum length of this parameter is 64 bytes. Supported character scopes are:
+ The 26 lowercase English letters: a to z.
+ - The 26 uppercase English letters: A to Z.
+ - The 10 numbers: 0 to 9.
+ - The space.
+ - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
+ @param userAccount The user account. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as null. Supported character scopes are:
+ - The 26 lowercase English letters: a to z.
+ - The 26 uppercase English letters: A to Z.
+ - The 10 numbers: 0 to 9.
+ - The space.
+ - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ - #ERR_INVALID_ARGUMENT (-2)
+ - #ERR_NOT_READY (-3)
+ - #ERR_REFUSED (-5)
+ */
+ virtual int joinChannelWithUserAccount(const char* token,
+ const char* userAccount,
+ const ChannelMediaOptions& options) = 0;
+ /** Allows a user to leave a channel, such as hanging up or exiting a call.
+
+ After joining a channel, the user must call the *leaveChannel* method to end the call before joining another channel.
+
+ This method returns 0 if the user leaves the channel and releases all resources related to the call.
+
+ This method call is asynchronous, and the user has not left the channel when the method call returns. Once the user leaves the channel, the SDK triggers the \ref IChannelEventHandler::onLeaveChannel "onLeaveChannel" callback.
+
+ A successful \ref agora::rtc::IChannel::leaveChannel "leaveChannel" method call triggers the following callbacks:
+ - The local client: \ref agora::rtc::IChannelEventHandler::onLeaveChannel "onLeaveChannel"
+ - The remote client: \ref agora::rtc::IChannelEventHandler::onUserOffline "onUserOffline" , if the user leaving the channel is in the Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+
+ @note
+ - If you call the \ref IChannel::release "release" method immediately after the *leaveChannel* method, the *leaveChannel* process interrupts, and the \ref IChannelEventHandler::onLeaveChannel "onLeaveChannel" callback is not triggered.
+ - If you call the *leaveChannel* method during a CDN live streaming, the SDK triggers the \ref IChannel::removePublishStreamUrl "removePublishStreamUrl" method.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int leaveChannel() = 0;
+
+ /** Publishes the local stream to the channel.
+
+ You must keep the following restrictions in mind when calling this method. Otherwise, the SDK returns the #ERR_REFUSED (5):
+ - This method publishes one stream only to the channel corresponding to the current `IChannel` object.
+ - In a Live Broadcast channel, only a broadcaster can call this method. To switch the client role, call \ref agora::rtc::IChannel::setClientRole "setClientRole" of the current `IChannel` object.
+ - You can publish a stream to only one channel at a time. For details on joining multiple channels, see the advanced guide *Join Multiple Channels*.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ - #ERR_REFUSED (5): The method call is refused.
+ */
+ virtual int publish() = 0;
+
+ /** Stops publishing a stream to the channel.
+
+ If you call this method in a channel where you are not publishing streams, the SDK returns #ERR_REFUSED (5).
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ - #ERR_REFUSED (5): The method call is refused.
+ */
+ virtual int unpublish() = 0;
+
+ /** Gets the channel ID of the current `IChannel` object.
+
+ @return
+ - The channel ID of the current `IChannel` object, if the method call succeeds.
+ - The empty string "", if the method call fails.
+ */
+ virtual const char *channelId() = 0;
+ /** Retrieves the current call ID.
+
+ When a user joins a channel on a client, a `callId` is generated to identify the call from the client.
+ Feedback methods, such as \ref IChannel::rate "rate" and \ref IChannel::complain "complain", must be called after the call ends to submit feedback to the SDK.
+
+ The \ref `rate` and `complain` methods require the `callId` parameter retrieved from the `getCallId` method during a call. `callId` is passed as an argument into the `rate` and `complain` methods after the call ends.
+
+ @param callId The current call ID.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getCallId(agora::util::AString& callId) = 0;
+ /** Gets a new token when the current token expires after a period of time.
+
+ The `token` expires after a period of time once the token schema is enabled when:
+
+ - The SDK triggers the \ref IChannelEventHandler::onTokenPrivilegeWillExpire "onTokenPrivilegeWillExpire" callback, or
+ - The \ref IChannelEventHandler::onConnectionStateChanged "onConnectionStateChanged" reports CONNECTION_CHANGED_TOKEN_EXPIRED(9).
+
+ The application should call this method to get the new `token`. Failure to do so will result in the SDK disconnecting from the server.
+
+ @param token Pointer to the new token.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int renewToken(const char* token) = 0;
+ /** Enables built-in encryption with an encryption password before users join a channel.
+
+ All users in a channel must use the same encryption password. The encryption password is automatically cleared once a user leaves the channel.
+
+ If an encryption password is not specified, the encryption functionality will be disabled.
+
+ @note
+ - Do not use this method for CDN live streaming.
+ - For optimal transmission, ensure that the encrypted data size does not exceed the original data size + 16 bytes. 16 bytes is the maximum padding size for AES encryption.
+
+ @param secret Pointer to the encryption password.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setEncryptionSecret(const char* secret) = 0;
+ /** Sets the built-in encryption mode.
+
+ The Agora SDK supports built-in encryption, which is set to the `aes-128-xts` mode by default. Call this method to use other encryption modes.
+
+ All users in the same channel must use the same encryption mode and password.
+
+ Refer to the information related to the AES encryption algorithm on the differences between the encryption modes.
+
+ @note Call the \ref IChannel::setEncryptionSecret "setEncryptionSecret" method to enable the built-in encryption function before calling this method.
+
+ @param encryptionMode The set encryption mode:
+ - "aes-128-xts": (Default) 128-bit AES encryption, XTS mode.
+ - "aes-128-ecb": 128-bit AES encryption, ECB mode.
+ - "aes-256-xts": 256-bit AES encryption, XTS mode.
+ - "": When encryptionMode is set as NULL, the encryption mode is set as "aes-128-xts" by default.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setEncryptionMode(const char* encryptionMode) = 0;
+ /** Registers a packet observer.
+
+ The Agora SDK allows your application to register a packet observer to receive callbacks for voice or video packet transmission.
+
+ @note
+ - The size of the packet sent to the network after processing should not exceed 1200 bytes, otherwise, the packet may fail to be sent.
+ - Ensure that both receivers and senders call this method, otherwise, you may meet undefined behaviors such as no voice and black screen.
+ - When you use CDN live streaming, recording or storage functions, Agora doesn't recommend calling this method.
+
+ @param observer The registered packet observer. See IPacketObserver.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int registerPacketObserver(IPacketObserver* observer) = 0;
+ /** Registers the metadata observer.
+
+ Registers the metadata observer. You need to implement the IMetadataObserver class and specify the metadata type in this method. A successful call of this method triggers the \ref agora::rtc::IMetadataObserver::getMaxMetadataSize "getMaxMetadataSize" callback.
+ This method enables you to add synchronized metadata in the video stream for more diversified live broadcast interactions, such as sending shopping links, digital coupons, and online quizzes.
+
+ @note
+ - Call this method before the joinChannel method.
+ - This method applies to the Live-broadcast channel profile.
+
+ @param observer The IMetadataObserver class. See the definition of IMetadataObserver for details.
+ @param type See \ref IMetadataObserver::METADATA_TYPE "METADATA_TYPE". The SDK supports VIDEO_METADATA (0) only for now.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int registerMediaMetadataObserver(IMetadataObserver *observer, IMetadataObserver::METADATA_TYPE type) = 0;
+ /** Sets the role of the user, such as a host or an audience (default), before joining a channel in a live broadcast.
+
+ This method can be used to switch the user role in a live broadcast after the user joins a channel.
+
+ In the Live Broadcast profile, when a user switches user roles after joining a channel, a successful \ref agora::rtc::IChannel::setClientRole "setClientRole" method call triggers the following callbacks:
+ - The local client: \ref agora::rtc::IChannelEventHandler::onClientRoleChanged "onClientRoleChanged"
+ - The remote client: \ref agora::rtc::IChannelEventHandler::onUserJoined "onUserJoined" or \ref agora::rtc::IChannelEventHandler::onUserOffline "onUserOffline" (BECOME_AUDIENCE)
+
+ @note
+ This method applies only to the Live-broadcast profile.
+
+ @param role Sets the role of the user. See #CLIENT_ROLE_TYPE.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setClientRole(CLIENT_ROLE_TYPE role) = 0;
+ /** Prioritizes a remote user's stream.
+
+ Use this method with the \ref IChannel::setRemoteSubscribeFallbackOption "setRemoteSubscribeFallbackOption" method.
+ If the fallback function is enabled for a subscribed stream, the SDK ensures the high-priority user gets the best possible stream quality.
+
+ @note The Agora SDK supports setting `serPriority` as high for one user only.
+
+ @param uid The ID of the remote user.
+ @param userPriority Sets the priority of the remote user. See #PRIORITY_TYPE.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRemoteUserPriority(uid_t uid, PRIORITY_TYPE userPriority) = 0;
+ /** Sets the sound position and gain of a remote user.
+
+ When the local user calls this method to set the sound position of a remote user, the sound difference between the left and right channels allows the
+ local user to track the real-time position of the remote user, creating a real sense of space. This method applies to massively multiplayer online games,
+ such as Battle Royale games.
+
+ @note
+ - For this method to work, enable stereo panning for remote users by calling the \ref agora::rtc::IChannel::enableSoundPositionIndication "enableSoundPositionIndication" method before joining a channel.
+ - This method requires hardware support. For the best sound positioning, we recommend using a stereo speaker.
+
+ @param uid The ID of the remote user.
+ @param pan The sound position of the remote user. The value ranges from -1.0 to 1.0:
+ - 0.0: the remote sound comes from the front.
+ - -1.0: the remote sound comes from the left.
+ - 1.0: the remote sound comes from the right.
+ @param gain Gain of the remote user. The value ranges from 0.0 to 100.0. The default value is 100.0 (the original gain of the remote user).
+ The smaller the value, the less the gain.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRemoteVoicePosition(int uid, double pan, double gain) = 0;
+ /** Updates the display mode of the video view of a remote user.
+
+ After initializing the video view of a remote user, you can call this method to update its rendering and mirror modes.
+ This method affects only the video view that the local user sees.
+
+ @note
+ - Call this method after calling the \ref IChannel::setupRemoteVideo "setupRemoteVideo" method to initialize the remote video view.
+ - During a call, you can call this method as many times as necessary to update the display mode of the video view of a remote user.
+
+ @param userId The ID of the remote user.
+ @param renderMode The rendering mode of the remote video view. See #RENDER_MODE_TYPE.
+ @param mirrorMode
+ - The mirror mode of the remote video view. See #VIDEO_MIRROR_MODE_TYPE.
+ - **Note**: The SDK disables the mirror mode by default.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRemoteRenderMode(uid_t userId, RENDER_MODE_TYPE renderMode, VIDEO_MIRROR_MODE_TYPE mirrorMode) = 0;
+ /** Stops/Resumes receiving all remote users' audio streams by default.
+
+ @param mute Sets whether to receive/stop receiving all remote users' audio streams by default:
+ - true: Stops receiving all remote users' audio streams by default.
+ - false: (Default) Receives all remote users' audio streams by default.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setDefaultMuteAllRemoteAudioStreams(bool mute) = 0;
+ /** Stops/Resumes receiving all remote users' video streams by default.
+
+ @param mute Sets whether to receive/stop receiving all remote users' video streams by default:
+ - true: Stop receiving all remote users' video streams by default.
+ - false: (Default) Receive all remote users' video streams by default.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setDefaultMuteAllRemoteVideoStreams(bool mute) = 0;
+ /** Stops/Resumes receiving all remote users' audio streams.
+
+ @param mute Sets whether to receive/stop receiving all remote users' audio streams.
+ - true: Stops receiving all remote users' audio streams.
+ - false: (Default) Receives all remote users' audio streams.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int muteAllRemoteAudioStreams(bool mute) = 0;
+ /** Adjust the playback volume of the specified remote user.
+
+ After joining a channel, call \ref agora::rtc::IChannel::adjustPlaybackSignalVolume "adjustPlaybackSignalVolume" to adjust the playback volume of different remote users,
+ or adjust multiple times for one remote user.
+
+ @note
+ - Call this method after joining a channel.
+ - This method adjusts the playback volume, which is the mixed volume for the specified remote user.
+ - This method can only adjust the playback volume of one specified remote user at a time. If you want to adjust the playback volume of several remote users,
+ call the method multiple times, once for each remote user.
+
+ @param uid The user ID, which should be the same as the `uid` of \ref agora::rtc::IChannel::joinChannel "joinChannel"
+ @param volume The playback volume of the voice. The value ranges from 0 to 100:
+ - 0: Mute.
+ - 100: Original volume.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int adjustUserPlaybackSignalVolume(uid_t userId, int volume) = 0;
+ /** Stops/Resumes receiving a specified remote user's audio stream.
+
+ @note If you called the \ref agora::rtc::IChannel::muteAllRemoteAudioStreams "muteAllRemoteAudioStreams" method and set `mute` as `true` to stop
+ receiving all remote users' audio streams, call the m`uteAllRemoteAudioStreams` method and set `mute` as `false` before calling this method.
+ The `muteAllRemoteAudioStreams` method sets all remote audio streams, while the `muteRemoteAudioStream` method sets a specified remote audio stream.
+
+ @param userId The user ID of the specified remote user sending the audio.
+ @param mute Sets whether to receive/stop receiving a specified remote user's audio stream:
+ - true: Stops receiving the specified remote user's audio stream.
+ - false: (Default) Receives the specified remote user's audio stream.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+
+ */
+ virtual int muteRemoteAudioStream(uid_t userId, bool mute) = 0;
+ /** Stops/Resumes receiving all video stream from a specified remote user.
+
+ @param mute Sets whether to receive/stop receiving all remote users' video streams:
+ - true: Stop receiving all remote users' video streams.
+ - false: (Default) Receive all remote users' video streams.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int muteAllRemoteVideoStreams(bool mute) = 0;
+ /** Stops/Resumes receiving the video stream from a specified remote user.
+
+ @note If you called the \ref agora::rtc::IChannel::muteAllRemoteVideoStreams "muteAllRemoteVideoStreams" method and
+ set `mute` as `true` to stop receiving all remote video streams, call the `muteAllRemoteVideoStreams` method and
+ set `mute` as `false` before calling this method.
+
+ @param userId The user ID of the specified remote user.
+ @param mute Sets whether to stop/resume receiving the video stream from a specified remote user:
+ - true: Stop receiving the specified remote user's video stream.
+ - false: (Default) Receive the specified remote user's video stream.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int muteRemoteVideoStream(uid_t userId, bool mute) = 0;
+ /** Sets the remote user's video stream type received by the local user when the remote user sends dual streams.
+
+ This method allows the application to adjust the corresponding video-stream type based on the size of the video window to reduce the bandwidth and resources.
+
+ - If the remote user enables the dual-stream mode by calling the \ref agora::rtc::IChannel::enableDualStreamMode "enableDualStreamMode" method,
+ the SDK receives the high-stream video by default.
+ - If the dual-stream mode is not enabled, the SDK receives the high-stream video by default.
+
+ The method result returns in the \ref agora::rtc::IChannelEventHandler::onApiCallExecuted "onApiCallExecuted" callback.
+ The SDK receives the high-stream video by default to reduce the bandwidth. If needed, users may use this method to switch to the low-stream video.
+ By default, the aspect ratio of the low-stream video is the same as the high-stream video. Once the resolution of the high-stream video is set,
+ the system automatically sets the resolution, frame rate, and bitrate of the low-stream video.
+
+ @param userId The ID of the remote user sending the video stream.
+ @param streamType Sets the video-stream type. See #REMOTE_VIDEO_STREAM_TYPE.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRemoteVideoStreamType(uid_t userId, REMOTE_VIDEO_STREAM_TYPE streamType) = 0;
+ /** Sets the default video-stream type for the video received by the local user when the remote user sends dual streams.
+
+ - If the dual-stream mode is enabled by calling the \ref agora::rtc::IChannel::enableDualStreamMode "enableDualStreamMode" method,
+ the user receives the high-stream video by default. The `setRemoteDefaultVideoStreamType` method allows the application to adjust the corresponding video-stream type according to the size of the video window, reducing the bandwidth and resources.
+ - If the dual-stream mode is not enabled, the user receives the high-stream video by default.
+
+ The result after calling this method is returned in the \ref agora::rtc::IChannelEventHandler::onApiCallExecuted "onApiCallExecuted" callback.
+ The Agora SDK receives the high-stream video by default to reduce the bandwidth. If needed, users can switch to the low-stream video through this method.
+
+ @param streamType Sets the default video-stream type. See #REMOTE_VIDEO_STREAM_TYPE.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRemoteDefaultVideoStreamType(REMOTE_VIDEO_STREAM_TYPE streamType) = 0;
+ /** Creates a data stream.
+
+ Each user can create up to five data streams during the lifecycle of the IChannel.
+
+ @note Set both the `reliable` and `ordered` parameters to `true` or `false`. Do not set one as `true` and the other as `false`.
+
+ @param streamId The ID of the created data stream.
+ @param reliable Sets whether or not the recipients are guaranteed to receive the data stream from the sender within five seconds:
+ - true: The recipients receive the data stream from the sender within five seconds. If the recipient does not receive the data stream within five seconds,
+ an error is reported to the application.
+ - false: There is no guarantee that the recipients receive the data stream within five seconds and no error message is reported for
+ any delay or missing data stream.
+ @param ordered Sets whether or not the recipients receive the data stream in the sent order:
+ - true: The recipients receive the data stream in the sent order.
+ - false: The recipients do not receive the data stream in the sent order.
+
+ @return
+ - Returns 0: Success.
+ - < 0: Failure.
+ */
+ virtual int createDataStream(int* streamId, bool reliable, bool ordered) = 0;
+ /** Sends data stream messages to all users in a channel.
+
+ The SDK has the following restrictions on this method:
+ - Up to 30 packets can be sent per second in a channel with each packet having a maximum size of 1 kB.
+ - Each client can send up to 6 kB of data per second.
+ - Each user can have up to five data streams simultaneously.
+
+ A successful \ref agora::rtc::IChannel::sendStreamMessage "sendStreamMessage" method call triggers
+ the \ref agora::rtc::IChannelEventHandler::onStreamMessage "onStreamMessage" callback on the remote client, from which the remote user gets the stream message.
+
+ A failed \ref agora::rtc::IChannel::sendStreamMessage "sendStreamMessage" method call triggers
+ the \ref agora::rtc::IChannelEventHandler::onStreamMessageError "onStreamMessage" callback on the remote client.
+
+ @note This method applies only to the Communication profile or to the hosts in the Live-broadcast profile.
+ If an audience in the Live-broadcast profile calls this method, the audience may be switched to a host.
+
+ @param streamId The ID of the sent data stream, returned in the \ref IChannel::createDataStream "createDataStream" method.
+ @param data The sent data.
+ @param length The length of the sent data.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int sendStreamMessage(int streamId, const char* data, size_t length) = 0;
+ /** Publishes the local stream to a specified CDN live RTMP address. (CDN live only.)
+
+ The SDK returns the result of this method call in the \ref IChannelEventHandler::onStreamPublished "onStreamPublished" callback.
+
+ The \ref agora::rtc::IChannel::addPublishStreamUrl "addPublishStreamUrl" method call triggers
+ the \ref agora::rtc::IChannelEventHandler::onRtmpStreamingStateChanged "onRtmpStreamingStateChanged" callback on the local client
+ to report the state of adding a local stream to the CDN.
+
+ @note
+ - Ensure that the user joins the channel before calling this method.
+ - Ensure that you enable the RTMP Converter service before using this function. See [Prerequisites](https://docs.agora.io/en/Interactive%20Broadcast/cdn_streaming_windows?platform=Windows#prerequisites).
+ - This method adds only one stream RTMP URL address each time it is called.
+
+ @param url The CDN streaming URL in the RTMP format. The maximum length of this parameter is 1024 bytes. The RTMP URL address must not contain special characters, such as Chinese language characters.
+ @param transcodingEnabled Sets whether transcoding is enabled/disabled:
+ - true: Enable transcoding. To [transcode](https://docs.agora.io/en/Agora%20Platform/terms?platform=All%20Platforms#transcoding) the audio or video streams when publishing them to CDN live, often used for combining the audio and video streams of multiple hosts in CDN live. If you set this parameter as `true`, ensure that you call the \ref IChannel::setLiveTranscoding "setLiveTranscoding" method before this method.
+ - false: Disable transcoding.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ - #ERR_INVALID_ARGUMENT (2): The RTMP URL address is NULL or has a string length of 0.
+ - #ERR_NOT_INITIALIZED (7): You have not initialized `IChannel` when publishing the stream.
+ */
+ virtual int addPublishStreamUrl(const char *url, bool transcodingEnabled) = 0;
+ /** Removes an RTMP stream from the CDN.
+
+ This method removes the RTMP URL address (added by the \ref IChannel::addPublishStreamUrl "addPublishStreamUrl" method) from a CDN live stream.
+ The SDK returns the result of this method call in the \ref IChannelEventHandler::onStreamUnpublished "onStreamUnpublished" callback.
+
+ The \ref agora::rtc::IChannel::removePublishStreamUrl "removePublishStreamUrl" method call triggers
+ the \ref agora::rtc::IChannelEventHandler::onRtmpStreamingStateChanged "onRtmpStreamingStateChanged" callback on the local client to report the state of removing an RTMP stream from the CDN.
+
+ @note
+ - This method removes only one RTMP URL address each time it is called.
+ - The RTMP URL address must not contain special characters, such as Chinese language characters.
+
+ @param url The RTMP URL address to be removed. The maximum length of this parameter is 1024 bytes.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int removePublishStreamUrl(const char *url) = 0;
+ /** Sets the video layout and audio settings for CDN live. (CDN live only.)
+
+ The SDK triggers the \ref agora::rtc::IChannelEventHandler::onTranscodingUpdated "onTranscodingUpdated" callback when you
+ call the `setLiveTranscoding` method to update the transcoding setting.
+
+ @note
+ - Ensure that you enable the RTMP Converter service before using this function. See [Prerequisites](https://docs.agora.io/en/Interactive%20Broadcast/cdn_streaming_windows?platform=Windows#prerequisites).
+ - If you call the `setLiveTranscoding` method to update the transcoding setting for the first time, the SDK does not trigger the `onTranscodingUpdated` callback.
+
+ @param transcoding Sets the CDN live audio/video transcoding settings. See LiveTranscoding.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLiveTranscoding(const LiveTranscoding &transcoding) = 0;
+ /** Adds a voice or video stream URL address to a live broadcast.
+
+ The \ref IChannelEventHandler::onStreamPublished "onStreamPublished" callback returns the inject status.
+ If this method call is successful, the server pulls the voice or video stream and injects it into a live channel.
+ This is applicable to scenarios where all audience members in the channel can watch a live show and interact with each other.
+
+ The \ref agora::rtc::IChannel::addInjectStreamUrl "addInjectStreamUrl" method call triggers the following callbacks:
+ - The local client:
+ - \ref agora::rtc::IChannelEventHandler::onStreamInjectedStatus "onStreamInjectedStatus" , with the state of the injecting the online stream.
+ - \ref agora::rtc::IChannelEventHandler::onUserJoined "onUserJoined" (uid: 666), if the method call is successful and the online media stream is injected into the channel.
+ - The remote client:
+ - \ref agora::rtc::IChannelEventHandler::onUserJoined "onUserJoined" (uid: 666), if the method call is successful and the online media stream is injected into the channel.
+
+ @note
+ - Ensure that you enable the RTMP Converter service before using this function. See [Prerequisites](https://docs.agora.io/en/Interactive%20Broadcast/cdn_streaming_windows?platform=Windows#prerequisites).
+ - This method applies to the Native SDK v2.4.1 and later.
+
+ @param url The URL address to be added to the ongoing live broadcast. Valid protocols are RTMP, HLS, and FLV.
+ - Supported FLV audio codec type: AAC.
+ - Supported FLV video codec type: H264 (AVC).
+ @param config The InjectStreamConfig object that contains the configuration of the added voice or video stream.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ - #ERR_INVALID_ARGUMENT (2): The injected URL does not exist. Call this method again to inject the stream and ensure that the URL is valid.
+ - #ERR_NOT_READY (3): The user is not in the channel.
+ - #ERR_NOT_SUPPORTED (4): The channel profile is not live broadcast. Call the \ref agora::rtc::IChannel::setChannelProfile "setChannelProfile" method and set the channel profile to live broadcast before calling this method.
+ - #ERR_NOT_INITIALIZED (7): The SDK is not initialized. Ensure that the IChannel object is initialized before calling this method.
+ */
+ virtual int addInjectStreamUrl(const char* url, const InjectStreamConfig& config) = 0;
+ /** Removes the voice or video stream URL address from a live broadcast.
+
+ This method removes the URL address (added by the \ref IChannel::addInjectStreamUrl "addInjectStreamUrl" method) from the live broadcast.
+
+ @note If this method is called successfully, the SDK triggers the \ref IChannelEventHandler::onUserOffline "onUserOffline" callback and returns a stream uid of 666.
+
+ @param url Pointer to the URL address of the added stream to be removed.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int removeInjectStreamUrl(const char* url) = 0;
+ /** Starts to relay media streams across channels.
+ *
+ * After a successful method call, the SDK triggers the
+ * \ref agora::rtc::IChannelEventHandler::onChannelMediaRelayStateChanged
+ * "onChannelMediaRelayStateChanged" and
+ * \ref agora::rtc::IChannelEventHandler::onChannelMediaRelayEvent
+ * "onChannelMediaRelayEvent" callbacks, and these callbacks return the
+ * state and events of the media stream relay.
+ * - If the
+ * \ref agora::rtc::IChannelEventHandler::onChannelMediaRelayStateChanged
+ * "onChannelMediaRelayStateChanged" callback returns
+ * #RELAY_STATE_RUNNING (2) and #RELAY_OK (0), and the
+ * \ref agora::rtc::IChannelEventHandler::onChannelMediaRelayEvent
+ * "onChannelMediaRelayEvent" callback returns
+ * #RELAY_EVENT_PACKET_SENT_TO_DEST_CHANNEL (4), the broadcaster starts
+ * sending data to the destination channel.
+ * - If the
+ * \ref agora::rtc::IChannelEventHandler::onChannelMediaRelayStateChanged
+ * "onChannelMediaRelayStateChanged" callback returns
+ * #RELAY_STATE_FAILURE (3), an exception occurs during the media stream
+ * relay.
+ *
+ * @note
+ * - Call this method after the \ref joinChannel() "joinChannel" method.
+ * - This method takes effect only when you are a broadcaster in a
+ * Live-broadcast channel.
+ * - After a successful method call, if you want to call this method
+ * again, ensure that you call the
+ * \ref stopChannelMediaRelay() "stopChannelMediaRelay" method to quit the
+ * current relay.
+ * - Contact sales-us@agora.io before implementing this function.
+ * - We do not support string user accounts in this API.
+ *
+ * @param configuration The configuration of the media stream relay:
+ * ChannelMediaRelayConfiguration.
+ *
+ * @return
+ * - 0: Success.
+ * - < 0: Failure.
+ */
+ virtual int startChannelMediaRelay(const ChannelMediaRelayConfiguration &configuration) = 0;
+ /** Updates the channels for media stream relay. After a successful
+ * \ref startChannelMediaRelay() "startChannelMediaRelay" method call, if
+ * you want to relay the media stream to more channels, or leave the
+ * current relay channel, you can call the
+ * \ref updateChannelMediaRelay() "updateChannelMediaRelay" method.
+ *
+ * After a successful method call, the SDK triggers the
+ * \ref agora::rtc::IChannelEventHandler::onChannelMediaRelayEvent
+ * "onChannelMediaRelayEvent" callback with the
+ * #RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL (7) state code.
+ *
+ * @note
+ * Call this method after the
+ * \ref startChannelMediaRelay() "startChannelMediaRelay" method to update
+ * the destination channel.
+ *
+ * @param configuration The media stream relay configuration:
+ * ChannelMediaRelayConfiguration.
+ *
+ * @return
+ * - 0: Success.
+ * - < 0: Failure.
+ */
+ virtual int updateChannelMediaRelay(const ChannelMediaRelayConfiguration &configuration) = 0;
+ /** Stops the media stream relay.
+ *
+ * Once the relay stops, the broadcaster quits all the destination
+ * channels.
+ *
+ * After a successful method call, the SDK triggers the
+ * \ref agora::rtc::IChannelEventHandler::onChannelMediaRelayStateChanged
+ * "onChannelMediaRelayStateChanged" callback. If the callback returns
+ * #RELAY_STATE_IDLE (0) and #RELAY_OK (0), the broadcaster successfully
+ * stops the relay.
+ *
+ * @note
+ * If the method call fails, the SDK triggers the
+ * \ref agora::rtc::IChannelEventHandler::onChannelMediaRelayStateChanged
+ * "onChannelMediaRelayStateChanged" callback with the
+ * #RELAY_ERROR_SERVER_NO_RESPONSE (2) or
+ * #RELAY_ERROR_SERVER_CONNECTION_LOST (8) state code. You can leave the
+ * channel by calling the \ref leaveChannel() "leaveChannel" method, and
+ * the media stream relay automatically stops.
+ *
+ * @return
+ * - 0: Success.
+ * - < 0: Failure.
+ */
+ virtual int stopChannelMediaRelay() = 0;
+ /** Gets the current connection state of the SDK.
+
+ @return #CONNECTION_STATE_TYPE.
+ */
+ virtual CONNECTION_STATE_TYPE getConnectionState() = 0;
+};
+/** The IRtcEngine2 class. */
+class IRtcEngine2 : public IRtcEngine
+{
+public:
+
+ /** Creates and gets an `IChannel` object.
+
+ To join more than one channel, call this method multiple times to create as many `IChannel` objects as needed, and
+ call the \ref agora::rtc::IChannel::joinChannel "joinChannel" method of each created `IChannel` object.
+
+ After joining multiple channels, you can simultaneously subscribe to streams of all the channels, but publish a stream in only one channel at one time.
+ @param channelId The unique channel name for an Agora RTC session. It must be in the string format and not exceed 64 bytes in length. Supported character scopes are:
+ - All lowercase English letters: a to z.
+ - All uppercase English letters: A to Z.
+ - All numeric characters: 0 to 9.
+ - The space character.
+ - Punctuation characters and other symbols, including: "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
+
+ @note
+ - This parameter does not have a default value. You must set it.
+ - Do not set it as the empty string "". Otherwise, the SDK returns #ERR_REFUSED (5).
+
+ @return
+ - The `IChannel` object, if the method call succeeds.
+ - An empty pointer NULL, if the method call fails.
+ - #ERR_REFUSED(5), if you set channelId as the empty string "".
+ */
+ virtual IChannel* createChannel(const char *channelId) = 0;
+
+};
+
+
+}
+}
+
+
+#endif
diff --git a/Android/APIExample/lib-raw-data/src/main/cpp/include/IAgoraRtcEngine.h b/Android/APIExample/lib-raw-data/src/main/cpp/include/IAgoraRtcEngine.h
new file mode 100755
index 000000000..ebc52f39c
--- /dev/null
+++ b/Android/APIExample/lib-raw-data/src/main/cpp/include/IAgoraRtcEngine.h
@@ -0,0 +1,7155 @@
+//
+// AgoraRtcEngine SDK
+//
+// Copyright (c) 2019 Agora.io. All rights reserved.
+//
+
+/**
+ @defgroup createAgoraRtcEngine Create an AgoraRtcEngine
+ */
+
+#ifndef AGORA_RTC_ENGINE_H
+#define AGORA_RTC_ENGINE_H
+#include "AgoraBase.h"
+#include "IAgoraService.h"
+
+namespace agora {
+namespace rtc {
+ typedef unsigned int uid_t;
+ typedef void* view_t;
+/** Maximum length of the device ID.
+*/
+enum MAX_DEVICE_ID_LENGTH_TYPE
+{
+ /** The maximum length of the device ID is 512 bytes.
+ */
+ MAX_DEVICE_ID_LENGTH = 512
+};
+/** Maximum length of user account.
+ */
+enum MAX_USER_ACCOUNT_LENGTH_TYPE
+{
+ /** The maximum length of user account is 255 bytes.
+ */
+ MAX_USER_ACCOUNT_LENGTH = 256
+};
+/** Maximum length of channel ID.
+ */
+enum MAX_CHANNEL_ID_LENGTH_TYPE
+{
+ /** The maximum length of channel id is 64 bytes.
+ */
+ MAX_CHANNEL_ID_LENGTH = 65
+};
+/** Formats of the quality report.
+*/
+enum QUALITY_REPORT_FORMAT_TYPE
+{
+ /** 0: The quality report in JSON format,
+ */
+ QUALITY_REPORT_JSON = 0,
+ /** 1: The quality report in HTML format.
+ */
+ QUALITY_REPORT_HTML = 1,
+};
+
+enum MEDIA_ENGINE_EVENT_CODE_TYPE
+{
+ /** 0: For internal use only.
+ */
+ MEDIA_ENGINE_RECORDING_ERROR = 0,
+ /** 1: For internal use only.
+ */
+ MEDIA_ENGINE_PLAYOUT_ERROR = 1,
+ /** 2: For internal use only.
+ */
+ MEDIA_ENGINE_RECORDING_WARNING = 2,
+ /** 3: For internal use only.
+ */
+ MEDIA_ENGINE_PLAYOUT_WARNING = 3,
+ /** 10: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_FILE_MIX_FINISH = 10,
+ /** 12: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_FAREND_MUSIC_BEGINS = 12,
+ /** 13: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_FAREND_MUSIC_ENDS = 13,
+ /** 14: For internal use only.
+ */
+ MEDIA_ENGINE_LOCAL_AUDIO_RECORD_ENABLED = 14,
+ /** 15: For internal use only.
+ */
+ MEDIA_ENGINE_LOCAL_AUDIO_RECORD_DISABLED = 15,
+ // media engine role changed
+ /** 20: For internal use only.
+ */
+ MEDIA_ENGINE_ROLE_BROADCASTER_SOLO = 20,
+ /** 21: For internal use only.
+ */
+ MEDIA_ENGINE_ROLE_BROADCASTER_INTERACTIVE = 21,
+ /** 22: For internal use only.
+ */
+ MEDIA_ENGINE_ROLE_AUDIENCE = 22,
+ /** 23: For internal use only.
+ */
+ MEDIA_ENGINE_ROLE_COMM_PEER = 23,
+ /** 24: For internal use only.
+ */
+ MEDIA_ENGINE_ROLE_GAME_PEER = 24,
+ // iOS adm sample rate changed
+ /** 110: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_ADM_REQUIRE_RESTART = 110,
+ /** 111: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_ADM_SPECIAL_RESTART = 111,
+ /** 112: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_ADM_USING_COMM_PARAMS = 112,
+ /** 113: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_ADM_USING_NORM_PARAMS = 113,
+ // audio mix state
+ /** 710: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_EVENT_MIXING_PLAY = 710,
+ /** 711: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_EVENT_MIXING_PAUSED = 711,
+ /** 712: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_EVENT_MIXING_RESTART = 712,
+ /** 713: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_EVENT_MIXING_STOPPED = 713,
+ /** 714: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_EVENT_MIXING_ERROR = 714,
+ //Mixing error codes
+ /** 701: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_ERROR_MIXING_OPEN = 701,
+ /** 702: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_ERROR_MIXING_TOO_FREQUENT = 702,
+ /** 703: The audio mixing file playback is interrupted. For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_ERROR_MIXING_INTERRUPTED_EOF = 703,
+ /** 0: For internal use only.
+ */
+ MEDIA_ENGINE_AUDIO_ERROR_MIXING_NO_ERROR = 0,
+};
+
+/** The states of the local user's audio mixing file.
+*/
+enum AUDIO_MIXING_STATE_TYPE{
+ /** 710: The audio mixing file is playing.
+ */
+ AUDIO_MIXING_STATE_PLAYING = 710,
+ /** 711: The audio mixing file pauses playing.
+ */
+ AUDIO_MIXING_STATE_PAUSED = 711,
+ /** 713: The audio mixing file stops playing.
+ */
+ AUDIO_MIXING_STATE_STOPPED = 713,
+ /** 714: An exception occurs when playing the audio mixing file. See #AUDIO_MIXING_ERROR_TYPE.
+ */
+ AUDIO_MIXING_STATE_FAILED = 714,
+};
+
+/** The error codes of the local user's audio mixing file.
+*/
+enum AUDIO_MIXING_ERROR_TYPE{
+ /** 701: The SDK cannot open the audio mixing file.
+ */
+ AUDIO_MIXING_ERROR_CAN_NOT_OPEN = 701,
+ /** 702: The SDK opens the audio mixing file too frequently.
+ */
+ AUDIO_MIXING_ERROR_TOO_FREQUENT_CALL = 702,
+ /** 703: The audio mixing file playback is interrupted.
+ */
+ AUDIO_MIXING_ERROR_INTERRUPTED_EOF = 703,
+ /** 0: The SDK can open the audio mixing file.
+ */
+ AUDIO_MIXING_ERROR_OK = 0,
+};
+
+/** Media device states.
+ */
+enum MEDIA_DEVICE_STATE_TYPE
+{
+ /** 1: The device is active.
+ */
+ MEDIA_DEVICE_STATE_ACTIVE = 1,
+ /** 2: The device is disabled.
+ */
+ MEDIA_DEVICE_STATE_DISABLED = 2,
+ /** 4: The device is not present.
+ */
+ MEDIA_DEVICE_STATE_NOT_PRESENT = 4,
+ /** 8: The device is unplugged.
+ */
+ MEDIA_DEVICE_STATE_UNPLUGGED = 8
+};
+
+/** Media device types.
+ */
+enum MEDIA_DEVICE_TYPE
+{
+ /** -1: Unknown device type.
+ */
+ UNKNOWN_AUDIO_DEVICE = -1,
+ /** 0: Audio playback device.
+ */
+ AUDIO_PLAYOUT_DEVICE = 0,
+ /** 1: Audio recording device.
+ */
+ AUDIO_RECORDING_DEVICE = 1,
+ /** 2: Video renderer.
+ */
+ VIDEO_RENDER_DEVICE = 2,
+ /** 3: Video capturer.
+ */
+ VIDEO_CAPTURE_DEVICE = 3,
+ /** 4: Application audio playback device.
+ */
+ AUDIO_APPLICATION_PLAYOUT_DEVICE = 4,
+};
+
+/** Local video state types
+ */
+enum LOCAL_VIDEO_STREAM_STATE
+{
+ /** Initial state */
+ LOCAL_VIDEO_STREAM_STATE_STOPPED = 0,
+ /** The capturer starts successfully. */
+ LOCAL_VIDEO_STREAM_STATE_CAPTURING = 1,
+ /** The first video frame is successfully encoded. */
+ LOCAL_VIDEO_STREAM_STATE_ENCODING = 2,
+ /** The local video fails to start. */
+ LOCAL_VIDEO_STREAM_STATE_FAILED = 3
+};
+
+/** Local video state error codes
+ */
+enum LOCAL_VIDEO_STREAM_ERROR {
+ /** The local video is normal. */
+ LOCAL_VIDEO_STREAM_ERROR_OK = 0,
+ /** No specified reason for the local video failure. */
+ LOCAL_VIDEO_STREAM_ERROR_FAILURE = 1,
+ /** No permission to use the local video capturing device. */
+ LOCAL_VIDEO_STREAM_ERROR_DEVICE_NO_PERMISSION = 2,
+ /** The local video capturing device is in use. */
+ LOCAL_VIDEO_STREAM_ERROR_DEVICE_BUSY = 3,
+ /** The local video capture fails. Check whether the capturing device is working properly. */
+ LOCAL_VIDEO_STREAM_ERROR_CAPTURE_FAILURE = 4,
+ /** The local video encoding fails. */
+ LOCAL_VIDEO_STREAM_ERROR_ENCODE_FAILURE = 5
+};
+
+/** Local audio state types.
+ */
+enum LOCAL_AUDIO_STREAM_STATE
+{
+ /** 0: The local audio is in the initial state.
+ */
+ LOCAL_AUDIO_STREAM_STATE_STOPPED = 0,
+ /** 1: The recording device starts successfully.
+ */
+ LOCAL_AUDIO_STREAM_STATE_RECORDING = 1,
+ /** 2: The first audio frame encodes successfully.
+ */
+ LOCAL_AUDIO_STREAM_STATE_ENCODING = 2,
+ /** 3: The local audio fails to start.
+ */
+ LOCAL_AUDIO_STREAM_STATE_FAILED = 3
+};
+
+/** Local audio state error codes.
+ */
+enum LOCAL_AUDIO_STREAM_ERROR
+{
+ /** 0: The local audio is normal.
+ */
+ LOCAL_AUDIO_STREAM_ERROR_OK = 0,
+ /** 1: No specified reason for the local audio failure.
+ */
+ LOCAL_AUDIO_STREAM_ERROR_FAILURE = 1,
+ /** 2: No permission to use the local audio device.
+ */
+ LOCAL_AUDIO_STREAM_ERROR_DEVICE_NO_PERMISSION = 2,
+ /** 3: The microphone is in use.
+ */
+ LOCAL_AUDIO_STREAM_ERROR_DEVICE_BUSY = 3,
+ /** 4: The local audio recording fails. Check whether the recording device
+ * is working properly.
+ */
+ LOCAL_AUDIO_STREAM_ERROR_RECORD_FAILURE = 4,
+ /** 5: The local audio encoding fails.
+ */
+ LOCAL_AUDIO_STREAM_ERROR_ENCODE_FAILURE = 5
+};
+
+/** Audio recording qualities.
+*/
+enum AUDIO_RECORDING_QUALITY_TYPE
+{
+ /** 0: Low quality. The sample rate is 32 kHz, and the file size is around
+ * 1.2 MB after 10 minutes of recording.
+ */
+ AUDIO_RECORDING_QUALITY_LOW = 0,
+ /** 1: Medium quality. The sample rate is 32 kHz, and the file size is
+ * around 2 MB after 10 minutes of recording.
+ */
+ AUDIO_RECORDING_QUALITY_MEDIUM = 1,
+ /** 2: High quality. The sample rate is 32 kHz, and the file size is
+ * around 3.75 MB after 10 minutes of recording.
+ */
+ AUDIO_RECORDING_QUALITY_HIGH = 2,
+};
+
+/** Network quality types. */
+enum QUALITY_TYPE
+{
+ /** 0: The network quality is unknown. */
+ QUALITY_UNKNOWN = 0,
+ /** 1: The network quality is excellent. */
+ QUALITY_EXCELLENT = 1,
+ /** 2: The network quality is quite good, but the bitrate may be slightly lower than excellent. */
+ QUALITY_GOOD = 2,
+ /** 3: Users can feel the communication slightly impaired. */
+ QUALITY_POOR = 3,
+ /** 4: Users cannot communicate smoothly. */
+ QUALITY_BAD = 4,
+ /** 5: The network is so bad that users can barely communicate. */
+ QUALITY_VBAD = 5,
+ /** 6: The network is down and users cannot communicate at all. */
+ QUALITY_DOWN = 6,
+ /** 7: Users cannot detect the network quality. (Not in use.) */
+ QUALITY_UNSUPPORTED = 7,
+ /** 8: Detecting the network quality. */
+ QUALITY_DETECTING = 8,
+};
+
+/** Video display modes. */
+enum RENDER_MODE_TYPE
+{
+ /**
+1: Uniformly scale the video until it fills the visible boundaries (cropped). One dimension of the video may have clipped contents.
+ */
+ RENDER_MODE_HIDDEN = 1,
+ /**
+2: Uniformly scale the video until one of its dimension fits the boundary (zoomed to fit). Areas that are not filled due to disparity in the aspect ratio are filled with black.
+ */
+ RENDER_MODE_FIT = 2,
+ /** **DEPRECATED** 3: This mode is deprecated.
+ */
+ RENDER_MODE_ADAPTIVE = 3,
+};
+
+/** Video mirror modes. */
+enum VIDEO_MIRROR_MODE_TYPE
+{
+ /** 0: (Default) The SDK enables the mirror mode.
+ */
+ VIDEO_MIRROR_MODE_AUTO = 0,//determined by SDK
+ /** 1: Enable mirror mode. */
+ VIDEO_MIRROR_MODE_ENABLED = 1,//enabled mirror
+ /** 2: Disable mirror mode. */
+ VIDEO_MIRROR_MODE_DISABLED = 2,//disable mirror
+};
+
+/** **DEPRECATED** Video profiles. */
+enum VIDEO_PROFILE_TYPE
+{
+ /** 0: 160 × 120, frame rate 15 fps, bitrate 65 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_120P = 0,
+ /** 2: 120 × 120, frame rate 15 fps, bitrate 50 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_120P_3 = 2,
+ /** 10: 320×180, frame rate 15 fps, bitrate 140 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_180P = 10,
+ /** 12: 180 × 180, frame rate 15 fps, bitrate 100 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_180P_3 = 12,
+ /** 13: 240 × 180, frame rate 15 fps, bitrate 120 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_180P_4 = 13,
+ /** 20: 320 × 240, frame rate 15 fps, bitrate 200 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_240P = 20,
+ /** 22: 240 × 240, frame rate 15 fps, bitrate 140 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_240P_3 = 22,
+ /** 23: 424 × 240, frame rate 15 fps, bitrate 220 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_240P_4 = 23,
+ /** 30: 640 × 360, frame rate 15 fps, bitrate 400 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_360P = 30,
+ /** 32: 360 × 360, frame rate 15 fps, bitrate 260 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_360P_3 = 32,
+ /** 33: 640 × 360, frame rate 30 fps, bitrate 600 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_360P_4 = 33,
+ /** 35: 360 × 360, frame rate 30 fps, bitrate 400 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_360P_6 = 35,
+ /** 36: 480 × 360, frame rate 15 fps, bitrate 320 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_360P_7 = 36,
+ /** 37: 480 × 360, frame rate 30 fps, bitrate 490 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_360P_8 = 37,
+ /** 38: 640 × 360, frame rate 15 fps, bitrate 800 Kbps.
+ @note Live broadcast profile only.
+ */
+ VIDEO_PROFILE_LANDSCAPE_360P_9 = 38,
+ /** 39: 640 × 360, frame rate 24 fps, bitrate 800 Kbps.
+ @note Live broadcast profile only.
+ */
+ VIDEO_PROFILE_LANDSCAPE_360P_10 = 39,
+ /** 100: 640 × 360, frame rate 24 fps, bitrate 1000 Kbps.
+ @note Live broadcast profile only.
+ */
+ VIDEO_PROFILE_LANDSCAPE_360P_11 = 100,
+ /** 40: 640 × 480, frame rate 15 fps, bitrate 500 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_480P = 40,
+ /** 42: 480 × 480, frame rate 15 fps, bitrate 400 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_480P_3 = 42,
+ /** 43: 640 × 480, frame rate 30 fps, bitrate 750 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_480P_4 = 43,
+ /** 45: 480 × 480, frame rate 30 fps, bitrate 600 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_480P_6 = 45,
+ /** 47: 848 × 480, frame rate 15 fps, bitrate 610 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_480P_8 = 47,
+ /** 48: 848 × 480, frame rate 30 fps, bitrate 930 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_480P_9 = 48,
+ /** 49: 640 × 480, frame rate 10 fps, bitrate 400 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_480P_10 = 49,
+ /** 50: 1280 × 720, frame rate 15 fps, bitrate 1130 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_720P = 50,
+ /** 52: 1280 × 720, frame rate 30 fps, bitrate 1710 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_720P_3 = 52,
+ /** 54: 960 × 720, frame rate 15 fps, bitrate 910 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_720P_5 = 54,
+ /** 55: 960 × 720, frame rate 30 fps, bitrate 1380 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_720P_6 = 55,
+ /** 60: 1920 × 1080, frame rate 15 fps, bitrate 2080 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_1080P = 60,
+ /** 62: 1920 × 1080, frame rate 30 fps, bitrate 3150 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_1080P_3 = 62,
+ /** 64: 1920 × 1080, frame rate 60 fps, bitrate 4780 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_1080P_5 = 64,
+ /** 66: 2560 × 1440, frame rate 30 fps, bitrate 4850 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_1440P = 66,
+ /** 67: 2560 × 1440, frame rate 60 fps, bitrate 6500 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_1440P_2 = 67,
+ /** 70: 3840 × 2160, frame rate 30 fps, bitrate 6500 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_4K = 70,
+ /** 72: 3840 × 2160, frame rate 60 fps, bitrate 6500 Kbps. */
+ VIDEO_PROFILE_LANDSCAPE_4K_3 = 72,
+ /** 1000: 120 × 160, frame rate 15 fps, bitrate 65 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_120P = 1000,
+ /** 1002: 120 × 120, frame rate 15 fps, bitrate 50 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_120P_3 = 1002,
+ /** 1010: 180 × 320, frame rate 15 fps, bitrate 140 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_180P = 1010,
+ /** 1012: 180 × 180, frame rate 15 fps, bitrate 100 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_180P_3 = 1012,
+ /** 1013: 180 × 240, frame rate 15 fps, bitrate 120 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_180P_4 = 1013,
+ /** 1020: 240 × 320, frame rate 15 fps, bitrate 200 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_240P = 1020,
+ /** 1022: 240 × 240, frame rate 15 fps, bitrate 140 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_240P_3 = 1022,
+ /** 1023: 240 × 424, frame rate 15 fps, bitrate 220 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_240P_4 = 1023,
+ /** 1030: 360 × 640, frame rate 15 fps, bitrate 400 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_360P = 1030,
+ /** 1032: 360 × 360, frame rate 15 fps, bitrate 260 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_360P_3 = 1032,
+ /** 1033: 360 × 640, frame rate 30 fps, bitrate 600 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_360P_4 = 1033,
+ /** 1035: 360 × 360, frame rate 30 fps, bitrate 400 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_360P_6 = 1035,
+ /** 1036: 360 × 480, frame rate 15 fps, bitrate 320 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_360P_7 = 1036,
+ /** 1037: 360 × 480, frame rate 30 fps, bitrate 490 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_360P_8 = 1037,
+ /** 1038: 360 × 640, frame rate 15 fps, bitrate 800 Kbps.
+ @note Live broadcast profile only.
+ */
+ VIDEO_PROFILE_PORTRAIT_360P_9 = 1038,
+ /** 1039: 360 × 640, frame rate 24 fps, bitrate 800 Kbps.
+ @note Live broadcast profile only.
+ */
+ VIDEO_PROFILE_PORTRAIT_360P_10 = 1039,
+ /** 1100: 360 × 640, frame rate 24 fps, bitrate 1000 Kbps.
+ @note Live broadcast profile only.
+ */
+ VIDEO_PROFILE_PORTRAIT_360P_11 = 1100,
+ /** 1040: 480 × 640, frame rate 15 fps, bitrate 500 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_480P = 1040,
+ /** 1042: 480 × 480, frame rate 15 fps, bitrate 400 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_480P_3 = 1042,
+ /** 1043: 480 × 640, frame rate 30 fps, bitrate 750 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_480P_4 = 1043,
+ /** 1045: 480 × 480, frame rate 30 fps, bitrate 600 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_480P_6 = 1045,
+ /** 1047: 480 × 848, frame rate 15 fps, bitrate 610 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_480P_8 = 1047,
+ /** 1048: 480 × 848, frame rate 30 fps, bitrate 930 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_480P_9 = 1048,
+ /** 1049: 480 × 640, frame rate 10 fps, bitrate 400 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_480P_10 = 1049,
+ /** 1050: 720 × 1280, frame rate 15 fps, bitrate 1130 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_720P = 1050,
+ /** 1052: 720 × 1280, frame rate 30 fps, bitrate 1710 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_720P_3 = 1052,
+ /** 1054: 720 × 960, frame rate 15 fps, bitrate 910 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_720P_5 = 1054,
+ /** 1055: 720 × 960, frame rate 30 fps, bitrate 1380 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_720P_6 = 1055,
+ /** 1060: 1080 × 1920, frame rate 15 fps, bitrate 2080 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_1080P = 1060,
+ /** 1062: 1080 × 1920, frame rate 30 fps, bitrate 3150 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_1080P_3 = 1062,
+ /** 1064: 1080 × 1920, frame rate 60 fps, bitrate 4780 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_1080P_5 = 1064,
+ /** 1066: 1440 × 2560, frame rate 30 fps, bitrate 4850 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_1440P = 1066,
+ /** 1067: 1440 × 2560, frame rate 60 fps, bitrate 6500 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_1440P_2 = 1067,
+ /** 1070: 2160 × 3840, frame rate 30 fps, bitrate 6500 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_4K = 1070,
+ /** 1072: 2160 × 3840, frame rate 60 fps, bitrate 6500 Kbps. */
+ VIDEO_PROFILE_PORTRAIT_4K_3 = 1072,
+ /** Default 640 × 360, frame rate 15 fps, bitrate 400 Kbps. */
+ VIDEO_PROFILE_DEFAULT = VIDEO_PROFILE_LANDSCAPE_360P,
+};
+
+/** Audio profiles.
+
+Sets the sample rate, bitrate, encoding mode, and the number of channels:*/
+enum AUDIO_PROFILE_TYPE // sample rate, bit rate, mono/stereo, speech/music codec
+{
+ /**
+ 0: Default audio profile.
+
+ - In the Communication profile, the default value is #AUDIO_PROFILE_SPEECH_STANDARD;
+ - In the Live-broadcast profile, the default value is #AUDIO_PROFILE_MUSIC_STANDARD.
+ */
+ AUDIO_PROFILE_DEFAULT = 0, // use default settings
+ /**
+ 1: A sample rate of 32 KHz, audio encoding, mono, and a bitrate of up to 18 Kbps.
+ */
+ AUDIO_PROFILE_SPEECH_STANDARD = 1, // 32Khz, 18Kbps, mono, speech
+ /**
+ 2: A sample rate of 48 KHz, music encoding, mono, and a bitrate of up to 48 Kbps.
+ */
+ AUDIO_PROFILE_MUSIC_STANDARD = 2, // 48Khz, 48Kbps, mono, music
+ /**
+ 3: A sample rate of 48 KHz, music encoding, stereo, and a bitrate of up to 56 Kbps.
+ */
+ AUDIO_PROFILE_MUSIC_STANDARD_STEREO = 3, // 48Khz, 56Kbps, stereo, music
+ /**
+ 4: A sample rate of 48 KHz, music encoding, mono, and a bitrate of up to 128 Kbps.
+ */
+ AUDIO_PROFILE_MUSIC_HIGH_QUALITY = 4, // 48Khz, 128Kbps, mono, music
+ /**
+ 5: A sample rate of 48 KHz, music encoding, stereo, and a bitrate of up to 192 Kbps.
+ */
+ AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO = 5, // 48Khz, 192Kbps, stereo, music
+ /**
+ 6: A sample rate of 16 KHz, audio encoding, mono, and Acoustic Echo Cancellation (AES) enabled.
+ */
+ AUDIO_PROFILE_IOT = 6,
+ AUDIO_PROFILE_NUM = 7,
+};
+
+/** Audio application scenarios.
+*/
+enum AUDIO_SCENARIO_TYPE // set a suitable scenario for your app type
+{
+ /** 0: Default. */
+ AUDIO_SCENARIO_DEFAULT = 0,
+ /** 1: Entertainment scenario, supporting voice during gameplay. */
+ AUDIO_SCENARIO_CHATROOM_ENTERTAINMENT = 1,
+ /** 2: Education scenario, prioritizing smoothness and stability. */
+ AUDIO_SCENARIO_EDUCATION = 2,
+ /** 3: Live gaming scenario, enabling the gaming audio effects in the speaker mode in a live broadcast scenario. Choose this scenario for high-fidelity music playback. */
+ AUDIO_SCENARIO_GAME_STREAMING = 3,
+ /** 4: Showroom scenario, optimizing the audio quality with external professional equipment. */
+ AUDIO_SCENARIO_SHOWROOM = 4,
+ /** 5: Gaming scenario. */
+ AUDIO_SCENARIO_CHATROOM_GAMING = 5,
+ /** 6: Applicable to the IoT scenario. */
+ AUDIO_SCENARIO_IOT = 6,
+ AUDIO_SCENARIO_NUM = 7,
+};
+
+ /** The channel profile of the Agora RtcEngine.
+ */
+enum CHANNEL_PROFILE_TYPE
+{
+ /** (Default) The Communication profile. Use this profile in one-on-one calls or group calls, where all users can talk freely.
+ */
+ CHANNEL_PROFILE_COMMUNICATION = 0,
+ /** The Live-Broadcast profile. Users in a live-broadcast channel have a role as either broadcaster or audience.
+ A broadcaster can both send and receive streams; an audience can only receive streams.
+ */
+ CHANNEL_PROFILE_LIVE_BROADCASTING = 1,
+ /** 2: The Gaming profile. This profile uses a codec with a lower bitrate and consumes less power. Applies to the gaming scenario, where all game players can talk freely.
+ */
+ CHANNEL_PROFILE_GAME = 2,
+};
+
+/** Client roles in a live broadcast. */
+enum CLIENT_ROLE_TYPE
+{
+ /** 1: Host */
+ CLIENT_ROLE_BROADCASTER = 1,
+ /** 2: Audience */
+ CLIENT_ROLE_AUDIENCE = 2,
+};
+
+/** Reasons for a user being offline. */
+enum USER_OFFLINE_REASON_TYPE
+{
+ /** 0: The user quits the call. */
+ USER_OFFLINE_QUIT = 0,
+ /** 1: The SDK times out and the user drops offline because no data packet is received within a certain period of time. If the user quits the call and the message is not passed to the SDK (due to an unreliable channel), the SDK assumes the user dropped offline. */
+ USER_OFFLINE_DROPPED = 1,
+ /** 2: (Live broadcast only.) The client role switched from the host to the audience. */
+ USER_OFFLINE_BECOME_AUDIENCE = 2,
+};
+/**
+ States of the RTMP streaming.
+ */
+enum RTMP_STREAM_PUBLISH_STATE
+{
+ /** The RTMP streaming has not started or has ended. This state is also triggered after you remove an RTMP address from the CDN by calling removePublishStreamUrl.
+ */
+ RTMP_STREAM_PUBLISH_STATE_IDLE = 0,
+ /** The SDK is connecting to Agora's streaming server and the RTMP server. This state is triggered after you call the \ref IRtcEngine::addPublishStreamUrl "addPublishStreamUrl" method.
+ */
+ RTMP_STREAM_PUBLISH_STATE_CONNECTING = 1,
+ /** The RTMP streaming publishes. The SDK successfully publishes the RTMP streaming and returns this state.
+ */
+ RTMP_STREAM_PUBLISH_STATE_RUNNING = 2,
+ /** The RTMP streaming is recovering. When exceptions occur to the CDN, or the streaming is interrupted, the SDK tries to resume RTMP streaming and returns this state.
+
+ - If the SDK successfully resumes the streaming, #RTMP_STREAM_PUBLISH_STATE_RUNNING (2) returns.
+ - If the streaming does not resume within 60 seconds or server errors occur, #RTMP_STREAM_PUBLISH_STATE_FAILURE (4) returns. You can also reconnect to the server by calling the \ref IRtcEngine::removePublishStreamUrl "removePublishStreamUrl" and \ref IRtcEngine::addPublishStreamUrl "addPublishStreamUrl" methods.
+ */
+ RTMP_STREAM_PUBLISH_STATE_RECOVERING = 3,
+ /** The RTMP streaming fails. See the errCode parameter for the detailed error information. You can also call the \ref IRtcEngine::addPublishStreamUrl "addPublishStreamUrl" method to publish the RTMP streaming again.
+ */
+ RTMP_STREAM_PUBLISH_STATE_FAILURE = 4,
+};
+
+/**
+ Error codes of the RTMP streaming.
+ */
+enum RTMP_STREAM_PUBLISH_ERROR
+{
+ /** The RTMP streaming publishes successfully. */
+ RTMP_STREAM_PUBLISH_ERROR_OK = 0,
+ /** Invalid argument used. If, for example, you do not call the \ref IRtcEngine::setLiveTranscoding "setLiveTranscoding" method to configure the LiveTranscoding parameters before calling the addPublishStreamUrl method, the SDK returns this error. Check whether you set the parameters in the *setLiveTranscoding* method properly. */
+ RTMP_STREAM_PUBLISH_ERROR_INVALID_ARGUMENT = 1,
+ /** The RTMP streaming is encrypted and cannot be published. */
+ RTMP_STREAM_PUBLISH_ERROR_ENCRYPTED_STREAM_NOT_ALLOWED = 2,
+ /** Timeout for the RTMP streaming. Call the \ref IRtcEngine::addPublishStreamUrl "addPublishStreamUrl" method to publish the streaming again. */
+ RTMP_STREAM_PUBLISH_ERROR_CONNECTION_TIMEOUT = 3,
+ /** An error occurs in Agora's streaming server. Call the addPublishStreamUrl method to publish the streaming again. */
+ RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR = 4,
+ /** An error occurs in the RTMP server. */
+ RTMP_STREAM_PUBLISH_ERROR_RTMP_SERVER_ERROR = 5,
+ /** The RTMP streaming publishes too frequently. */
+ RTMP_STREAM_PUBLISH_ERROR_TOO_OFTEN = 6,
+ /** The host publishes more than 10 URLs. Delete the unnecessary URLs before adding new ones. */
+ RTMP_STREAM_PUBLISH_ERROR_REACH_LIMIT = 7,
+ /** The host manipulates other hosts' URLs. Check your app logic. */
+ RTMP_STREAM_PUBLISH_ERROR_NOT_AUTHORIZED = 8,
+ /** Agora's server fails to find the RTMP streaming. */
+ RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND = 9,
+ /** The format of the RTMP streaming URL is not supported. Check whether the URL format is correct. */
+ RTMP_STREAM_PUBLISH_ERROR_FORMAT_NOT_SUPPORTED = 10,
+};
+
+/** States of importing an external video stream in a live broadcast. */
+enum INJECT_STREAM_STATUS
+{
+ /** 0: The external video stream imported successfully. */
+ INJECT_STREAM_STATUS_START_SUCCESS = 0,
+ /** 1: The external video stream already exists. */
+ INJECT_STREAM_STATUS_START_ALREADY_EXISTS = 1,
+ /** 2: The external video stream to be imported is unauthorized. */
+ INJECT_STREAM_STATUS_START_UNAUTHORIZED = 2,
+ /** 3: Import external video stream timeout. */
+ INJECT_STREAM_STATUS_START_TIMEDOUT = 3,
+ /** 4: Import external video stream failed. */
+ INJECT_STREAM_STATUS_START_FAILED = 4,
+ /** 5: The external video stream stopped importing successfully. */
+ INJECT_STREAM_STATUS_STOP_SUCCESS = 5,
+ /** 6: No external video stream is found. */
+ INJECT_STREAM_STATUS_STOP_NOT_FOUND = 6,
+ /** 7: The external video stream to be stopped importing is unauthorized. */
+ INJECT_STREAM_STATUS_STOP_UNAUTHORIZED = 7,
+ /** 8: Stop importing external video stream timeout. */
+ INJECT_STREAM_STATUS_STOP_TIMEDOUT = 8,
+ /** 9: Stop importing external video stream failed. */
+ INJECT_STREAM_STATUS_STOP_FAILED = 9,
+ /** 10: The external video stream is corrupted. */
+ INJECT_STREAM_STATUS_BROKEN = 10,
+};
+/** Remote video stream types. */
+enum REMOTE_VIDEO_STREAM_TYPE
+{
+ /** 0: High-stream video. */
+ REMOTE_VIDEO_STREAM_HIGH = 0,
+ /** 1: Low-stream video. */
+ REMOTE_VIDEO_STREAM_LOW = 1,
+};
+
+/** Use modes of the \ref media::IAudioFrameObserver::onRecordAudioFrame "onRecordAudioFrame" callback. */
+enum RAW_AUDIO_FRAME_OP_MODE_TYPE
+{
+ /** 0: Read-only mode: Users only read the \ref agora::media::IAudioFrameObserver::AudioFrame "AudioFrame" data without modifying anything. For example, when users acquire the data with the Agora SDK, then push the RTMP streams. */
+ RAW_AUDIO_FRAME_OP_MODE_READ_ONLY = 0,
+ /** 1: Write-only mode: Users replace the \ref agora::media::IAudioFrameObserver::AudioFrame "AudioFrame" data with their own data and pass the data to the SDK for encoding. For example, when users acquire the data. */
+ RAW_AUDIO_FRAME_OP_MODE_WRITE_ONLY = 1,
+ /** 2: Read and write mode: Users read the data from \ref agora::media::IAudioFrameObserver::AudioFrame "AudioFrame", modify it, and then play it. For example, when users have their own sound-effect processing module and perform some voice pre-processing, such as a voice change. */
+ RAW_AUDIO_FRAME_OP_MODE_READ_WRITE = 2,
+};
+
+/** Audio-sample rates. */
+enum AUDIO_SAMPLE_RATE_TYPE
+{
+ /** 32000: 32 kHz */
+ AUDIO_SAMPLE_RATE_32000 = 32000,
+ /** 44100: 44.1 kHz */
+ AUDIO_SAMPLE_RATE_44100 = 44100,
+ /** 48000: 48 kHz */
+ AUDIO_SAMPLE_RATE_48000 = 48000,
+};
+
+/** Video codec profile types. */
+enum VIDEO_CODEC_PROFILE_TYPE
+{ /** 66: Baseline video codec profile. Generally used in video calls on mobile phones. */
+ VIDEO_CODEC_PROFILE_BASELINE = 66,
+ /** 77: Main video codec profile. Generally used in mainstream electronics such as MP4 players, portable video players, PSP, and iPads. */
+ VIDEO_CODEC_PROFILE_MAIN = 77,
+ /** 100: (Default) High video codec profile. Generally used in high-resolution broadcasts or television. */
+ VIDEO_CODEC_PROFILE_HIGH = 100,
+};
+
+/** Video codec types */
+enum VIDEO_CODEC_TYPE {
+ /** Standard VP8 */
+ VIDEO_CODEC_VP8 = 1,
+ /** Standard H264 */
+ VIDEO_CODEC_H264 = 2,
+ /** Enhanced VP8 */
+ VIDEO_CODEC_EVP = 3,
+ /** Enhanced H264 */
+ VIDEO_CODEC_E264 = 4,
+};
+
+/** Audio equalization band frequencies. */
+enum AUDIO_EQUALIZATION_BAND_FREQUENCY
+{
+ /** 0: 31 Hz */
+ AUDIO_EQUALIZATION_BAND_31 = 0,
+ /** 1: 62 Hz */
+ AUDIO_EQUALIZATION_BAND_62 = 1,
+ /** 2: 125 Hz */
+ AUDIO_EQUALIZATION_BAND_125 = 2,
+ /** 3: 250 Hz */
+ AUDIO_EQUALIZATION_BAND_250 = 3,
+ /** 4: 500 Hz */
+ AUDIO_EQUALIZATION_BAND_500 = 4,
+ /** 5: 1 kHz */
+ AUDIO_EQUALIZATION_BAND_1K = 5,
+ /** 6: 2 kHz */
+ AUDIO_EQUALIZATION_BAND_2K = 6,
+ /** 7: 4 kHz */
+ AUDIO_EQUALIZATION_BAND_4K = 7,
+ /** 8: 8 kHz */
+ AUDIO_EQUALIZATION_BAND_8K = 8,
+ /** 9: 16 kHz */
+ AUDIO_EQUALIZATION_BAND_16K = 9,
+};
+
+/** Audio reverberation types. */
+enum AUDIO_REVERB_TYPE
+{
+ /** 0: The level of the dry signal (db). The value is between -20 and 10. */
+ AUDIO_REVERB_DRY_LEVEL = 0, // (dB, [-20,10]), the level of the dry signal
+ /** 1: The level of the early reflection signal (wet signal) (dB). The value is between -20 and 10. */
+ AUDIO_REVERB_WET_LEVEL = 1, // (dB, [-20,10]), the level of the early reflection signal (wet signal)
+ /** 2: The room size of the reflection. The value is between 0 and 100. */
+ AUDIO_REVERB_ROOM_SIZE = 2, // ([0,100]), the room size of the reflection
+ /** 3: The length of the initial delay of the wet signal (ms). The value is between 0 and 200. */
+ AUDIO_REVERB_WET_DELAY = 3, // (ms, [0,200]), the length of the initial delay of the wet signal in ms
+ /** 4: The reverberation strength. The value is between 0 and 100. */
+ AUDIO_REVERB_STRENGTH = 4, // ([0,100]), the strength of the reverberation
+};
+
+/** Local voice changer options. */
+enum VOICE_CHANGER_PRESET {
+ /** 0: The original voice (no local voice change).
+ */
+ VOICE_CHANGER_OFF = 0, //Turn off the voice changer
+ /** 1: An old man's voice.
+ */
+ VOICE_CHANGER_OLDMAN = 1,
+ /** 2: A little boy's voice.
+ */
+ VOICE_CHANGER_BABYBOY = 2,
+ /** 3: A little girl's voice.
+ */
+ VOICE_CHANGER_BABYGIRL = 3,
+ /** 4: The voice of a growling bear.
+ */
+ VOICE_CHANGER_ZHUBAJIE = 4,
+ /** 5: Ethereal vocal effects.
+ */
+ VOICE_CHANGER_ETHEREAL = 5,
+ /** 6: Hulk's voice.
+ */
+ VOICE_CHANGER_HULK = 6
+};
+
+/** Local voice reverberation presets. */
+enum AUDIO_REVERB_PRESET {
+ /** 0: The original voice (no local voice reverberation).
+ */
+ AUDIO_REVERB_OFF = 0, // Turn off audio reverb
+ /** 1: Pop music.
+ */
+ AUDIO_REVERB_POPULAR = 1,
+ /** 2: R&B.
+ */
+ AUDIO_REVERB_RNB = 2,
+ /** 3: Rock music.
+ */
+ AUDIO_REVERB_ROCK = 3,
+ /** 4: Hip-hop.
+ */
+ AUDIO_REVERB_HIPHOP = 4,
+ /** 5: Pop concert.
+ */
+ AUDIO_REVERB_VOCAL_CONCERT = 5,
+ /** 6: Karaoke.
+ */
+ AUDIO_REVERB_KTV = 6,
+ /** 7: Recording studio.
+ */
+ AUDIO_REVERB_STUDIO = 7
+};
+/** Audio codec profile types. The default value is LC_ACC. */
+enum AUDIO_CODEC_PROFILE_TYPE
+{
+ /** 0: LC-AAC, which is the low-complexity audio codec type. */
+ AUDIO_CODEC_PROFILE_LC_AAC = 0,
+ /** 1: HE-AAC, which is the high-efficiency audio codec type. */
+ AUDIO_CODEC_PROFILE_HE_AAC = 1,
+};
+
+/** Remote audio states.
+ */
+enum REMOTE_AUDIO_STATE
+{
+ /** 0: The remote audio is in the default state, probably due to
+ * #REMOTE_AUDIO_REASON_LOCAL_MUTED (3),
+ * #REMOTE_AUDIO_REASON_REMOTE_MUTED (5), or
+ * #REMOTE_AUDIO_REASON_REMOTE_OFFLINE (7).
+ */
+ REMOTE_AUDIO_STATE_STOPPED = 0, // Default state, audio is started or remote user disabled/muted audio stream
+ /** 1: The first remote audio packet is received.
+ */
+ REMOTE_AUDIO_STATE_STARTING = 1, // The first audio frame packet has been received
+ /** 2: The remote audio stream is decoded and plays normally, probably
+ * due to #REMOTE_AUDIO_REASON_NETWORK_RECOVERY (2),
+ * #REMOTE_AUDIO_REASON_LOCAL_UNMUTED (4), or
+ * #REMOTE_AUDIO_REASON_REMOTE_UNMUTED (6).
+ */
+ REMOTE_AUDIO_STATE_DECODING = 2, // The first remote audio frame has been decoded or fronzen state ends
+ /** 3: The remote audio is frozen, probably due to
+ * #REMOTE_AUDIO_REASON_NETWORK_CONGESTION (1).
+ */
+ REMOTE_AUDIO_STATE_FROZEN = 3, // Remote audio is frozen, probably due to network issue
+ /** 4: The remote audio fails to start, probably due to
+ * #REMOTE_AUDIO_REASON_INTERNAL (0).
+ */
+ REMOTE_AUDIO_STATE_FAILED = 4, // Remote audio play failed
+};
+
+/** Remote audio state reasons.
+ */
+enum REMOTE_AUDIO_STATE_REASON
+{
+ /** 0: Internal reasons.
+ */
+ REMOTE_AUDIO_REASON_INTERNAL = 0,
+ /** 1: Network congestion.
+ */
+ REMOTE_AUDIO_REASON_NETWORK_CONGESTION = 1,
+ /** 2: Network recovery.
+ */
+ REMOTE_AUDIO_REASON_NETWORK_RECOVERY = 2,
+ /** 3: The local user stops receiving the remote audio stream or
+ * disables the audio module.
+ */
+ REMOTE_AUDIO_REASON_LOCAL_MUTED = 3,
+ /** 4: The local user resumes receiving the remote audio stream or
+ * enables the audio module.
+ */
+ REMOTE_AUDIO_REASON_LOCAL_UNMUTED = 4,
+ /** 5: The remote user stops sending the audio stream or disables the
+ * audio module.
+ */
+ REMOTE_AUDIO_REASON_REMOTE_MUTED = 5,
+ /** 6: The remote user resumes sending the audio stream or enables the
+ * audio module.
+ */
+ REMOTE_AUDIO_REASON_REMOTE_UNMUTED = 6,
+ /** 7: The remote user leaves the channel.
+ */
+ REMOTE_AUDIO_REASON_REMOTE_OFFLINE = 7,
+};
+
+/** Remote video states. */
+// enum REMOTE_VIDEO_STATE
+// {
+// // REMOTE_VIDEO_STATE_STOPPED is not used at this version. Ignore this value.
+// // REMOTE_VIDEO_STATE_STOPPED = 0, // Default state, video is started or remote user disabled/muted video stream
+// /** 1: The remote video is playing. */
+// REMOTE_VIDEO_STATE_RUNNING = 1, // Running state, remote video can be displayed normally
+// /** 2: The remote video is frozen. */
+// REMOTE_VIDEO_STATE_FROZEN = 2, // Remote video is frozen, probably due to network issue.
+// };
+
+/** The state of the remote video. */
+enum REMOTE_VIDEO_STATE {
+ /** 0: The remote video is in the default state, probably due to #REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED (3), #REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED (5), or #REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE (7).
+ */
+ REMOTE_VIDEO_STATE_STOPPED = 0,
+
+ /** 1: The first remote video packet is received.
+ */
+ REMOTE_VIDEO_STATE_STARTING = 1,
+
+ /** 2: The remote video stream is decoded and plays normally, probably due to #REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY (2), #REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED (4), #REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED (6), or #REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY (9).
+ */
+ REMOTE_VIDEO_STATE_DECODING = 2,
+
+ /** 3: The remote video is frozen, probably due to #REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION (1) or #REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK (8).
+ */
+ REMOTE_VIDEO_STATE_FROZEN = 3,
+
+ /** 4: The remote video fails to start, probably due to #REMOTE_VIDEO_STATE_REASON_INTERNAL (0).
+ */
+ REMOTE_VIDEO_STATE_FAILED = 4
+};
+
+/** The reason of the remote video state change. */
+enum REMOTE_VIDEO_STATE_REASON {
+ /** 0: Internal reasons.
+ */
+ REMOTE_VIDEO_STATE_REASON_INTERNAL = 0,
+
+ /** 1: Network congestion.
+ */
+ REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION = 1,
+
+ /** 2: Network recovery.
+ */
+ REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY = 2,
+
+ /** 3: The local user stops receiving the remote video stream or disables the video module.
+ */
+ REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED = 3,
+
+ /** 4: The local user resumes receiving the remote video stream or enables the video module.
+ */
+ REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED = 4,
+
+ /** 5: The remote user stops sending the video stream or disables the video module.
+ */
+ REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED = 5,
+
+ /** 6: The remote user resumes sending the video stream or enables the video module.
+ */
+ REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED = 6,
+
+ /** 7: The remote user leaves the channel.
+ */
+ REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE = 7,
+
+ /** 8: The remote media stream falls back to the audio-only stream due to poor network conditions.
+ */
+ REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK = 8,
+
+ /** 9: The remote media stream switches back to the video stream after the network conditions improve.
+ */
+ REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY = 9
+
+};
+
+/** Video frame rates. */
+enum FRAME_RATE
+{
+ /** 1: 1 fps */
+ FRAME_RATE_FPS_1 = 1,
+ /** 7: 7 fps */
+ FRAME_RATE_FPS_7 = 7,
+ /** 10: 10 fps */
+ FRAME_RATE_FPS_10 = 10,
+ /** 15: 15 fps */
+ FRAME_RATE_FPS_15 = 15,
+ /** 24: 24 fps */
+ FRAME_RATE_FPS_24 = 24,
+ /** 30: 30 fps */
+ FRAME_RATE_FPS_30 = 30,
+ /** 60: 60 fps (Windows and macOS only) */
+ FRAME_RATE_FPS_60 = 60,
+};
+
+/** Video output orientation modes.
+ */
+enum ORIENTATION_MODE {
+ /** 0: (Default) Adaptive mode.
+
+ The video encoder adapts to the orientation mode of the video input device.
+
+ - If the width of the captured video from the SDK is greater than the height, the encoder sends the video in landscape mode. The encoder also sends the rotational information of the video, and the receiver uses the rotational information to rotate the received video.
+ - When you use a custom video source, the output video from the encoder inherits the orientation of the original video. If the original video is in portrait mode, the output video from the encoder is also in portrait mode. The encoder also sends the rotational information of the video to the receiver.
+ */
+ ORIENTATION_MODE_ADAPTIVE = 0,
+ /** 1: Landscape mode.
+
+ The video encoder always sends the video in landscape mode. The video encoder rotates the original video before sending it and the rotational infomation is 0. This mode applies to scenarios involving CDN live streaming.
+ */
+ ORIENTATION_MODE_FIXED_LANDSCAPE = 1,
+ /** 2: Portrait mode.
+
+ The video encoder always sends the video in portrait mode. The video encoder rotates the original video before sending it and the rotational infomation is 0. This mode applies to scenarios involving CDN live streaming.
+ */
+ ORIENTATION_MODE_FIXED_PORTRAIT = 2,
+};
+
+/** Video degradation preferences when the bandwidth is a constraint. */
+enum DEGRADATION_PREFERENCE {
+ /** 0: (Default) Degrade the frame rate in order to maintain the video quality. */
+ MAINTAIN_QUALITY = 0,
+ /** 1: Degrade the video quality in order to maintain the frame rate. */
+ MAINTAIN_FRAMERATE = 1,
+ /** 2: (For future use) Maintain a balance between the frame rate and video quality. */
+ MAINTAIN_BALANCED = 2,
+};
+
+/** Stream fallback options. */
+enum STREAM_FALLBACK_OPTIONS
+{
+ /** 0: No fallback behavior for the local/remote video stream when the uplink/downlink network conditions are poor. The quality of the stream is not guaranteed. */
+ STREAM_FALLBACK_OPTION_DISABLED = 0,
+ /** 1: Under poor downlink network conditions, the remote video stream, to which you subscribe, falls back to the low-stream (low resolution and low bitrate) video. You can set this option only in the \ref IRtcEngine::setRemoteSubscribeFallbackOption "setRemoteSubscribeFallbackOption" method. Nothing happens when you set this in the \ref IRtcEngine::setLocalPublishFallbackOption "setLocalPublishFallbackOption" method. */
+ STREAM_FALLBACK_OPTION_VIDEO_STREAM_LOW = 1,
+ /** 2: Under poor uplink network conditions, the locally published video stream falls back to audio only.
+
+ Under poor downlink network conditions, the remote video stream, to which you subscribe, first falls back to the low-stream (low resolution and low bitrate) video; and then to an audio-only stream if the network conditions worsen.*/
+ STREAM_FALLBACK_OPTION_AUDIO_ONLY = 2,
+};
+
+ /** Camera capturer configuration.
+ */
+ enum CAPTURER_OUTPUT_PREFERENCE
+ {
+ /** 0: (Default) self-adapts the camera output parameters to the system performance and network conditions to balance CPU consumption and video preview quality.
+ */
+ CAPTURER_OUTPUT_PREFERENCE_AUTO = 0,
+ /** 1: Prioritizes the system performance. The SDK chooses the dimension and frame rate of the local camera capture closest to those set by \ref IRtcEngine::setVideoEncoderConfiguration "setVideoEncoderConfiguration".
+ */
+ CAPTURER_OUTPUT_PREFERENCE_PERFORMANCE = 1,
+ /** 2: Prioritizes the local preview quality. The SDK chooses higher camera output parameters to improve the local video preview quality. This option requires extra CPU and RAM usage for video pre-processing.
+ */
+ CAPTURER_OUTPUT_PREFERENCE_PREVIEW = 2,
+ };
+
+/** The priority of the remote user.
+ */
+enum PRIORITY_TYPE
+{
+ /** 50: The user's priority is high.
+ */
+ PRIORITY_HIGH = 50,
+ /** 100: (Default) The user's priority is normal.
+ */
+ PRIORITY_NORMAL = 100,
+};
+
+/** Connection states. */
+enum CONNECTION_STATE_TYPE
+{
+ /** 1: The SDK is disconnected from Agora's edge server.
+
+ - This is the initial state before calling the \ref agora::rtc::IRtcEngine::joinChannel "joinChannel" method.
+ - The SDK also enters this state when the application calls the \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" method.
+ */
+ CONNECTION_STATE_DISCONNECTED = 1,
+ /** 2: The SDK is connecting to Agora's edge server.
+
+ - When the application calls the \ref agora::rtc::IRtcEngine::joinChannel "joinChannel" method, the SDK starts to establish a connection to the specified channel, triggers the \ref agora::rtc::IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged" callback, and switches to the #CONNECTION_STATE_CONNECTING state.
+ - When the SDK successfully joins the channel, it triggers the \ref agora::rtc::IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged" callback and switches to the #CONNECTION_STATE_CONNECTED state.
+ - After the SDK joins the channel and when it finishes initializing the media engine, the SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onJoinChannelSuccess "onJoinChannelSuccess" callback.
+ */
+ CONNECTION_STATE_CONNECTING = 2,
+ /** 3: The SDK is connected to Agora's edge server and has joined a channel. You can now publish or subscribe to a media stream in the channel.
+
+ If the connection to the channel is lost because, for example, if the network is down or switched, the SDK automatically tries to reconnect and triggers:
+ - The \ref agora::rtc::IRtcEngineEventHandler::onConnectionInterrupted "onConnectionInterrupted" callback (deprecated).
+ - The \ref agora::rtc::IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged" callback and switches to the #CONNECTION_STATE_RECONNECTING state.
+ */
+ CONNECTION_STATE_CONNECTED = 3,
+ /** 4: The SDK keeps rejoining the channel after being disconnected from a joined channel because of network issues.
+
+ - If the SDK cannot rejoin the channel within 10 seconds after being disconnected from Agora's edge server, the SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onConnectionLost "onConnectionLost" callback, stays in the #CONNECTION_STATE_RECONNECTING state, and keeps rejoining the channel.
+ - If the SDK fails to rejoin the channel 20 minutes after being disconnected from Agora's edge server, the SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged" callback, switches to the #CONNECTION_STATE_FAILED state, and stops rejoining the channel.
+ */
+ CONNECTION_STATE_RECONNECTING = 4,
+ /** 5: The SDK fails to connect to Agora's edge server or join the channel.
+
+ You must call the \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" method to leave this state, and call the \ref agora::rtc::IRtcEngine::joinChannel "joinChannel" method again to rejoin the channel.
+
+ If the SDK is banned from joining the channel by Agora's edge server (through the RESTful API), the SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onConnectionBanned "onConnectionBanned" (deprecated) and \ref agora::rtc::IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged" callbacks.
+ */
+ CONNECTION_STATE_FAILED = 5,
+};
+
+/** Reasons for a connection state change. */
+enum CONNECTION_CHANGED_REASON_TYPE
+{
+ /** 0: The SDK is connecting to Agora's edge server. */
+ CONNECTION_CHANGED_CONNECTING = 0,
+ /** 1: The SDK has joined the channel successfully. */
+ CONNECTION_CHANGED_JOIN_SUCCESS = 1,
+ /** 2: The connection between the SDK and Agora's edge server is interrupted. */
+ CONNECTION_CHANGED_INTERRUPTED = 2,
+ /** 3: The connection between the SDK and Agora's edge server is banned by Agora's edge server. */
+ CONNECTION_CHANGED_BANNED_BY_SERVER = 3,
+ /** 4: The SDK fails to join the channel for more than 20 minutes and stops reconnecting to the channel. */
+ CONNECTION_CHANGED_JOIN_FAILED = 4,
+ /** 5: The SDK has left the channel. */
+ CONNECTION_CHANGED_LEAVE_CHANNEL = 5,
+ /** 6: The connection failed since Appid is not valid. */
+ CONNECTION_CHANGED_INVALID_APP_ID = 6,
+ /** 7: The connection failed since channel name is not valid. */
+ CONNECTION_CHANGED_INVALID_CHANNEL_NAME = 7,
+ /** 8: The connection failed since token is not valid, possibly because:
+
+ - The App Certificate for the project is enabled in Console, but you do not use Token when joining the channel. If you enable the App Certificate, you must use a token to join the channel.
+ - The uid that you specify in the \ref agora::rtc::IRtcEngine::joinChannel "joinChannel" method is different from the uid that you pass for generating the token.
+ */
+ CONNECTION_CHANGED_INVALID_TOKEN = 8,
+ /** 9: The connection failed since token is expired. */
+ CONNECTION_CHANGED_TOKEN_EXPIRED = 9,
+ /** 10: The connection is rejected by server. */
+ CONNECTION_CHANGED_REJECTED_BY_SERVER = 10,
+ /** 11: The connection changed to reconnecting since SDK has set a proxy server. */
+ CONNECTION_CHANGED_SETTING_PROXY_SERVER = 11,
+ /** 12: When SDK is in connection failed, the renew token operation will make it connecting. */
+ CONNECTION_CHANGED_RENEW_TOKEN = 12,
+ /** 13: The IP Address of SDK client has changed. i.e., Network type or IP/Port changed by network operator might change client IP address. */
+ CONNECTION_CHANGED_CLIENT_IP_ADDRESS_CHANGED = 13,
+ /** 14: Timeout for the keep-alive of the connection between the SDK and Agora's edge server. The connection state changes to CONNECTION_STATE_RECONNECTING(4). */
+ CONNECTION_CHANGED_KEEP_ALIVE_TIMEOUT = 14,
+};
+
+/** Network type. */
+enum NETWORK_TYPE
+{
+ /** -1: The network type is unknown. */
+ NETWORK_TYPE_UNKNOWN = -1,
+ /** 0: The SDK disconnects from the network. */
+ NETWORK_TYPE_DISCONNECTED = 0,
+ /** 1: The network type is LAN. */
+ NETWORK_TYPE_LAN = 1,
+ /** 2: The network type is Wi-Fi(including hotspots). */
+ NETWORK_TYPE_WIFI = 2,
+ /** 3: The network type is mobile 2G. */
+ NETWORK_TYPE_MOBILE_2G = 3,
+ /** 4: The network type is mobile 3G. */
+ NETWORK_TYPE_MOBILE_3G = 4,
+ /** 5: The network type is mobile 4G. */
+ NETWORK_TYPE_MOBILE_4G = 5,
+};
+
+/** States of the last-mile network probe test. */
+enum LASTMILE_PROBE_RESULT_STATE {
+ /** 1: The last-mile network probe test is complete. */
+ LASTMILE_PROBE_RESULT_COMPLETE = 1,
+ /** 2: The last-mile network probe test is incomplete and the bandwidth estimation is not available, probably due to limited test resources. */
+ LASTMILE_PROBE_RESULT_INCOMPLETE_NO_BWE = 2,
+ /** 3: The last-mile network probe test is not carried out, probably due to poor network conditions. */
+ LASTMILE_PROBE_RESULT_UNAVAILABLE = 3
+};
+/** Audio output routing. */
+enum AUDIO_ROUTE_TYPE {
+ /** Default.
+ */
+ AUDIO_ROUTE_DEFAULT = -1,
+ /** Headset.
+ */
+ AUDIO_ROUTE_HEADSET = 0,
+ /** Earpiece.
+ */
+ AUDIO_ROUTE_EARPIECE = 1,
+ /** Headset with no microphone.
+ */
+ AUDIO_ROUTE_HEADSET_NO_MIC = 2,
+ /** Speakerphone.
+ */
+ AUDIO_ROUTE_SPEAKERPHONE = 3,
+ /** Loudspeaker.
+ */
+ AUDIO_ROUTE_LOUDSPEAKER = 4,
+ /** Bluetooth headset.
+ */
+ AUDIO_ROUTE_BLUETOOTH = 5
+};
+
+#if (defined(__APPLE__) && TARGET_OS_IOS)
+/** Audio session restriction. */
+enum AUDIO_SESSION_OPERATION_RESTRICTION {
+ /** No restriction, the SDK has full control of the audio session operations. */
+ AUDIO_SESSION_OPERATION_RESTRICTION_NONE = 0,
+ /** The SDK does not change the audio session category. */
+ AUDIO_SESSION_OPERATION_RESTRICTION_SET_CATEGORY = 1,
+ /** The SDK does not change any setting of the audio session (category, mode, categoryOptions). */
+ AUDIO_SESSION_OPERATION_RESTRICTION_CONFIGURE_SESSION = 1 << 1,
+ /** The SDK keeps the audio session active when leaving a channel. */
+ AUDIO_SESSION_OPERATION_RESTRICTION_DEACTIVATE_SESSION = 1 << 2,
+ /** The SDK does not configure the audio session anymore. */
+ AUDIO_SESSION_OPERATION_RESTRICTION_ALL = 1 << 7,
+};
+#endif
+
+#if defined(__ANDROID__) || (defined(__APPLE__) && TARGET_OS_IOS)
+enum CAMERA_DIRECTION {
+ /** The rear camera. */
+ CAMERA_REAR = 0,
+ /** The front camera. */
+ CAMERA_FRONT = 1,
+};
+#endif
+
+/** The uplink or downlink last-mile network probe test result. */
+struct LastmileProbeOneWayResult {
+ /** The packet loss rate (%). */
+ unsigned int packetLossRate;
+ /** The network jitter (ms). */
+ unsigned int jitter;
+ /* The estimated available bandwidth (Kbps). */
+ unsigned int availableBandwidth;
+};
+
+/** The uplink and downlink last-mile network probe test result. */
+struct LastmileProbeResult{
+ /** The state of the probe test. */
+ LASTMILE_PROBE_RESULT_STATE state;
+ /** The uplink last-mile network probe test result. */
+ LastmileProbeOneWayResult uplinkReport;
+ /** The downlink last-mile network probe test result. */
+ LastmileProbeOneWayResult downlinkReport;
+ /** The round-trip delay time (ms). */
+ unsigned int rtt;
+};
+
+/** Configurations of the last-mile network probe test. */
+struct LastmileProbeConfig {
+ /** Sets whether or not to test the uplink network. Some users, for example, the audience in a Live-broadcast channel, do not need such a test:
+ - true: test.
+ - false: do not test. */
+ bool probeUplink;
+ /** Sets whether or not to test the downlink network:
+ - true: test.
+ - false: do not test. */
+ bool probeDownlink;
+ /** The expected maximum sending bitrate (Kbps) of the local user. The value ranges between 100 and 5000. We recommend setting this parameter according to the bitrate value set by \ref IRtcEngine::setVideoEncoderConfiguration "setVideoEncoderConfiguration". */
+ unsigned int expectedUplinkBitrate;
+ /** The expected maximum receiving bitrate (Kbps) of the local user. The value ranges between 100 and 5000. */
+ unsigned int expectedDownlinkBitrate;
+};
+
+/** Properties of the audio volume information.
+
+ An array containing the user ID and volume information for each speaker.
+ */
+struct AudioVolumeInfo
+{
+ /**
+ User ID of the speaker. The uid of the local user is 0.
+ */
+ uid_t uid;
+ /** The volume of the speaker. The volume ranges between 0 (lowest volume) and 255 (highest volume).
+ */
+ unsigned int volume;
+ /** Voice activity status of the local user.
+ * - 0: The local user is not speaking.
+ * - 1: The local user is speaking.
+ *
+ * @note
+ * - The `vad` parameter cannot report the voice activity status of the remote users. In the remote users' callback, `vad` = 0.
+ * - Ensure that you set `report_vad`(true) in the \ref agora::rtc::IRtcEngine::enableAudioVolumeIndication(int, int, bool) "enableAudioVolumeIndication" method to enable the voice activity detection of the local user.
+ */
+ unsigned int vad;
+ /** The channel ID, which indicates which channel the speaker is in.
+ */
+ const char * channelId;
+};
+
+/** Statistics of the channel.
+ */
+struct RtcStats
+{
+ /**
+ Call duration (s), represented by an aggregate value.
+ */
+ unsigned int duration;
+ /**
+ Total number of bytes transmitted, represented by an aggregate value.
+ */
+ unsigned int txBytes;
+ /**
+ Total number of bytes received, represented by an aggregate value.
+ */
+ unsigned int rxBytes;
+ /** Total number of audio bytes sent (bytes), represented
+ * by an aggregate value.
+ */
+ unsigned int txAudioBytes;
+ /** Total number of video bytes sent (bytes), represented
+ * by an aggregate value.
+ */
+ unsigned int txVideoBytes;
+ /** Total number of audio bytes received (bytes) before
+ * network countermeasures, represented by an aggregate value.
+ */
+ unsigned int rxAudioBytes;
+ /** Total number of video bytes received (bytes),
+ * represented by an aggregate value.
+ */
+ unsigned int rxVideoBytes;
+
+ /**
+ Transmission bitrate (Kbps), represented by an instantaneous value.
+ */
+ unsigned short txKBitRate;
+ /**
+ Receive bitrate (Kbps), represented by an instantaneous value.
+ */
+ unsigned short rxKBitRate;
+ /**
+ Audio receive bitrate (Kbps), represented by an instantaneous value.
+ */
+ unsigned short rxAudioKBitRate;
+ /**
+ Audio transmission bitrate (Kbps), represented by an instantaneous value.
+ */
+ unsigned short txAudioKBitRate;
+ /**
+ Video receive bitrate (Kbps), represented by an instantaneous value.
+ */
+ unsigned short rxVideoKBitRate;
+ /**
+ Video transmission bitrate (Kbps), represented by an instantaneous value.
+ */
+ unsigned short txVideoKBitRate;
+ /** Client-server latency (ms)
+ */
+ unsigned short lastmileDelay;
+ /** The packet loss rate (%) from the local client to Agora's edge server,
+ * before using the anti-packet-loss method.
+ */
+ unsigned short txPacketLossRate;
+ /** The packet loss rate (%) from Agora's edge server to the local client,
+ * before using the anti-packet-loss method.
+ */
+ unsigned short rxPacketLossRate;
+ /** Number of users in the channel.
+
+ - Communication profile: The number of users in the channel.
+ - Live broadcast profile:
+
+ - If the local user is an audience: The number of users in the channel = The number of hosts in the channel + 1.
+ - If the user is a host: The number of users in the channel = The number of hosts in the channel.
+ */
+ unsigned int userCount;
+ /**
+ Application CPU usage (%).
+ */
+ double cpuAppUsage;
+ /**
+ System CPU usage (%).
+ */
+ double cpuTotalUsage;
+ /** The round-trip time delay from the client to the local router.
+ */
+ int gatewayRtt;
+ /**
+ The memory usage ratio of the app (%).
+ @note This value is for reference only. Due to system limitations, you may not get the value of this member.
+ */
+ double memoryAppUsageRatio;
+ /**
+ The memory usage ratio of the system (%).
+ @note This value is for reference only. Due to system limitations, you may not get the value of this member.
+ */
+ double memoryTotalUsageRatio;
+ /**
+ The memory usage of the app (KB).
+ @note This value is for reference only. Due to system limitations, you may not get the value of this member.
+ */
+ int memoryAppUsageInKbytes;
+ RtcStats()
+ : duration(0)
+ , txBytes(0)
+ , rxBytes(0)
+ , txAudioBytes(0)
+ , txVideoBytes(0)
+ , rxAudioBytes(0)
+ , rxVideoBytes(0)
+ , txKBitRate(0)
+ , rxKBitRate(0)
+ , rxAudioKBitRate(0)
+ , txAudioKBitRate(0)
+ , rxVideoKBitRate(0)
+ , txVideoKBitRate(0)
+ , lastmileDelay(0)
+ , txPacketLossRate(0)
+ , rxPacketLossRate(0)
+ , userCount(0)
+ , cpuAppUsage(0)
+ , cpuTotalUsage(0)
+ , gatewayRtt(0)
+ , memoryAppUsageRatio(0)
+ , memoryTotalUsageRatio(0)
+ , memoryAppUsageInKbytes(0) {}
+};
+
+/** Quality change of the local video in terms of target frame rate and target bit rate since last count.
+ */
+enum QUALITY_ADAPT_INDICATION {
+ /** The quality of the local video stays the same. */
+ ADAPT_NONE = 0,
+ /** The quality improves because the network bandwidth increases. */
+ ADAPT_UP_BANDWIDTH = 1,
+ /** The quality worsens because the network bandwidth decreases. */
+ ADAPT_DOWN_BANDWIDTH = 2,
+};
+
+/** The error code in CHANNEL_MEDIA_RELAY_ERROR. */
+enum CHANNEL_MEDIA_RELAY_ERROR {
+ /** 0: The state is normal.
+ */
+ RELAY_OK = 0,
+ /** 1: An error occurs in the server response.
+ */
+ RELAY_ERROR_SERVER_ERROR_RESPONSE = 1,
+ /** 2: No server response. You can call the
+ * \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" method to
+ * leave the channel.
+ */
+ RELAY_ERROR_SERVER_NO_RESPONSE = 2,
+ /** 3: The SDK fails to access the service, probably due to limited
+ * resources of the server.
+ */
+ RELAY_ERROR_NO_RESOURCE_AVAILABLE = 3,
+ /** 4: Fails to send the relay request.
+ */
+ RELAY_ERROR_FAILED_JOIN_SRC = 4,
+ /** 5: Fails to accept the relay request.
+ */
+ RELAY_ERROR_FAILED_JOIN_DEST = 5,
+ /** 6: The server fails to receive the media stream.
+ */
+ RELAY_ERROR_FAILED_PACKET_RECEIVED_FROM_SRC = 6,
+ /** 7: The server fails to send the media stream.
+ */
+ RELAY_ERROR_FAILED_PACKET_SENT_TO_DEST = 7,
+ /** 8: The SDK disconnects from the server due to poor network
+ * connections. You can call the \ref agora::rtc::IRtcEngine::leaveChannel
+ * "leaveChannel" method to leave the channel.
+ */
+ RELAY_ERROR_SERVER_CONNECTION_LOST = 8,
+ /** 9: An internal error occurs in the server.
+ */
+ RELAY_ERROR_INTERNAL_ERROR = 9,
+ /** 10: The token of the source channel has expired.
+ */
+ RELAY_ERROR_SRC_TOKEN_EXPIRED = 10,
+ /** 11: The token of the destination channel has expired.
+ */
+ RELAY_ERROR_DEST_TOKEN_EXPIRED = 11,
+};
+
+/** The event code in CHANNEL_MEDIA_RELAY_EVENT. */
+enum CHANNEL_MEDIA_RELAY_EVENT {
+ /** 0: The user disconnects from the server due to poor network
+ * connections.
+ */
+ RELAY_EVENT_NETWORK_DISCONNECTED = 0,
+ /** 1: The network reconnects.
+ */
+ RELAY_EVENT_NETWORK_CONNECTED = 1,
+ /** 2: The user joins the source channel.
+ */
+ RELAY_EVENT_PACKET_JOINED_SRC_CHANNEL = 2,
+ /** 3: The user joins the destination channel.
+ */
+ RELAY_EVENT_PACKET_JOINED_DEST_CHANNEL = 3,
+ /** 4: The SDK starts relaying the media stream to the destination channel.
+ */
+ RELAY_EVENT_PACKET_SENT_TO_DEST_CHANNEL = 4,
+ /** 5: The server receives the video stream from the source channel.
+ */
+ RELAY_EVENT_PACKET_RECEIVED_VIDEO_FROM_SRC = 5,
+ /** 6: The server receives the audio stream from the source channel.
+ */
+ RELAY_EVENT_PACKET_RECEIVED_AUDIO_FROM_SRC = 6,
+ /** 7: The destination channel is updated.
+ */
+ RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL = 7,
+ /** 8: The destination channel update fails due to internal reasons.
+ */
+ RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL_REFUSED = 8,
+ /** 9: The destination channel does not change, which means that the
+ * destination channel fails to be updated.
+ */
+ RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL_NOT_CHANGE = 9,
+ /** 10: The destination channel name is NULL.
+ */
+ RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL_IS_NULL = 10,
+ /** 11: The video profile is sent to the server.
+ */
+ RELAY_EVENT_VIDEO_PROFILE_UPDATE = 11,
+};
+
+/** The state code in CHANNEL_MEDIA_RELAY_STATE. */
+enum CHANNEL_MEDIA_RELAY_STATE {
+ /** 0: The SDK is initializing.
+ */
+ RELAY_STATE_IDLE = 0,
+ /** 1: The SDK tries to relay the media stream to the destination channel.
+ */
+ RELAY_STATE_CONNECTING = 1,
+ /** 2: The SDK successfully relays the media stream to the destination
+ * channel.
+ */
+ RELAY_STATE_RUNNING = 2,
+ /** 3: A failure occurs. See the details in code.
+ */
+ RELAY_STATE_FAILURE = 3,
+};
+
+/** Statistics of the local video stream.
+ */
+struct LocalVideoStats
+{
+ /** Bitrate (Kbps) sent in the reported interval, which does not include
+ * the bitrate of the retransmission video after packet loss.
+ */
+ int sentBitrate;
+ /** Frame rate (fps) sent in the reported interval, which does not include
+ * the frame rate of the retransmission video after packet loss.
+ */
+ int sentFrameRate;
+ /** The encoder output frame rate (fps) of the local video.
+ */
+ int encoderOutputFrameRate;
+ /** The render output frame rate (fps) of the local video.
+ */
+ int rendererOutputFrameRate;
+ /** The target bitrate (Kbps) of the current encoder. This value is estimated by the SDK based on the current network conditions.
+ */
+ int targetBitrate;
+ /** The target frame rate (fps) of the current encoder.
+ */
+ int targetFrameRate;
+ /** Quality change of the local video in terms of target frame rate and
+ * target bit rate in this reported interval. See #QUALITY_ADAPT_INDICATION.
+ */
+ QUALITY_ADAPT_INDICATION qualityAdaptIndication;
+ /** The encoding bitrate (Kbps), which does not include the bitrate of the
+ * re-transmission video after packet loss.
+ */
+ int encodedBitrate;
+ /** The width of the encoding frame (px).
+ */
+ int encodedFrameWidth;
+ /** The height of the encoding frame (px).
+ */
+ int encodedFrameHeight;
+ /** The value of the sent frames, represented by an aggregate value.
+ */
+ int encodedFrameCount;
+ /** The codec type of the local video:
+ * - VIDEO_CODEC_VP8 = 1: VP8.
+ * - VIDEO_CODEC_H264 = 2: (Default) H.264.
+ */
+ VIDEO_CODEC_TYPE codecType;
+};
+
+/** Statistics of the remote video stream.
+ */
+struct RemoteVideoStats
+{
+ /**
+ User ID of the remote user sending the video streams.
+ */
+ uid_t uid;
+ /** **DEPRECATED** Time delay (ms).
+ */
+ int delay;
+/**
+ Width (pixels) of the video stream.
+ */
+ int width;
+ /**
+ Height (pixels) of the video stream.
+ */
+ int height;
+ /**
+ Bitrate (Kbps) received since the last count.
+ */
+ int receivedBitrate;
+ /** The decoder output frame rate (fps) of the remote video.
+ */
+ int decoderOutputFrameRate;
+ /** The render output frame rate (fps) of the remote video.
+ */
+ int rendererOutputFrameRate;
+ /** Packet loss rate (%) of the remote video stream after using the anti-packet-loss method.
+ */
+ int packetLossRate;
+ REMOTE_VIDEO_STREAM_TYPE rxStreamType;
+ /**
+ The total freeze time (ms) of the remote video stream after the remote user joins the channel.
+ In a video session where the frame rate is set to no less than 5 fps, video freeze occurs when
+ the time interval between two adjacent renderable video frames is more than 500 ms.
+ */
+ int totalFrozenTime;
+ /**
+ The total video freeze time as a percentage (%) of the total time when the video is available.
+ */
+ int frozenRate;
+};
+
+/** Audio statistics of the local user */
+struct LocalAudioStats
+{
+ /** The number of channels.
+ */
+ int numChannels;
+ /** The sample rate (Hz).
+ */
+ int sentSampleRate;
+ /** The average sending bitrate (Kbps).
+ */
+ int sentBitrate;
+};
+
+/** Audio statistics of a remote user */
+struct RemoteAudioStats
+{
+ /** User ID of the remote user sending the audio streams.
+ *
+ */
+ uid_t uid;
+ /** Audio quality received by the user: #QUALITY_TYPE.
+ */
+ int quality;
+ /** Network delay (ms) from the sender to the receiver.
+ */
+ int networkTransportDelay;
+ /** Network delay (ms) from the receiver to the jitter buffer.
+ */
+ int jitterBufferDelay;
+ /** The audio frame loss rate in the reported interval.
+ */
+ int audioLossRate;
+ /** The number of channels.
+ */
+ int numChannels;
+ /** The sample rate (Hz) of the received audio stream in the reported
+ * interval.
+ */
+ int receivedSampleRate;
+ /** The average bitrate (Kbps) of the received audio stream in the
+ * reported interval. */
+ int receivedBitrate;
+ /** The total freeze time (ms) of the remote audio stream after the remote user joins the channel. In a session, audio freeze occurs when the audio frame loss rate reaches 4%.
+ * Agora uses 2 seconds as an audio piece unit to calculate the audio freeze time. The total audio freeze time = The audio freeze number × 2 seconds
+ */
+ int totalFrozenTime;
+ /** The total audio freeze time as a percentage (%) of the total time when the audio is available. */
+ int frozenRate;
+};
+
+/**
+ * Video dimensions.
+ */
+struct VideoDimensions {
+ /** Width (pixels) of the video. */
+ int width;
+ /** Height (pixels) of the video. */
+ int height;
+ VideoDimensions()
+ : width(640), height(480)
+ {}
+ VideoDimensions(int w, int h)
+ : width(w), height(h)
+ {}
+};
+
+/** (Recommended) The standard bitrate set in the \ref IRtcEngine::setVideoEncoderConfiguration "setVideoEncoderConfiguration" method.
+
+ In this mode, the bitrates differ between the live broadcast and communication profiles:
+
+ - Communication profile: The video bitrate is the same as the base bitrate.
+ - Live broadcast profile: The video bitrate is twice the base bitrate.
+
+ */
+const int STANDARD_BITRATE = 0;
+
+/** The compatible bitrate set in the \ref IRtcEngine::setVideoEncoderConfiguration "setVideoEncoderConfiguration" method.
+
+ The bitrate remains the same regardless of the channel profile. If you choose this mode in the Live-broadcast profile, the video frame rate may be lower than the set value.
+ */
+const int COMPATIBLE_BITRATE = -1;
+
+/** Use the default minimum bitrate.
+ */
+const int DEFAULT_MIN_BITRATE = -1;
+
+/** Video encoder configurations.
+ */
+struct VideoEncoderConfiguration {
+ /** The video frame dimensions (px) used to specify the video quality and measured by the total number of pixels along a frame's width and height: VideoDimensions. The default value is 640 x 360.
+ */
+ VideoDimensions dimensions;
+ /** The frame rate of the video: #FRAME_RATE. The default value is 15.
+
+ Note that we do not recommend setting this to a value greater than 30.
+ */
+ FRAME_RATE frameRate;
+ /** The minimum frame rate of the video. The default value is -1.
+ */
+ int minFrameRate;
+ /** The video encoding bitrate (Kbps).
+
+ Choose one of the following options:
+
+ - #STANDARD_BITRATE: (Recommended) The standard bitrate.
+ - The Communication profile: the encoding bitrate equals the base bitrate.
+ - The Live-broadcast profile: the encoding bitrate is twice the base bitrate.
+ - #COMPATIBLE_BITRATE: The compatible bitrate: the bitrate stays the same regardless of the profile.
+
+ The Communication profile prioritizes smoothness, while the Live-broadcast profile prioritizes video quality (requiring a higher bitrate). We recommend setting the bitrate mode as #STANDARD_BITRATE to address this difference.
+
+ The following table lists the recommended video encoder configurations, where the base bitrate applies to the Communication profile. Set your bitrate based on this table. If you set a bitrate beyond the proper range, the SDK automatically sets it to within the range.
+
+ | Resolution | Frame Rate (fps) | Base Bitrate (Kbps, for Communication) | Live Bitrate (Kbps, for Live Broadcast)|
+ |------------------------|------------------|----------------------------------------|----------------------------------------|
+ | 160 × 120 | 15 | 65 | 130 |
+ | 120 × 120 | 15 | 50 | 100 |
+ | 320 × 180 | 15 | 140 | 280 |
+ | 180 × 180 | 15 | 100 | 200 |
+ | 240 × 180 | 15 | 120 | 240 |
+ | 320 × 240 | 15 | 200 | 400 |
+ | 240 × 240 | 15 | 140 | 280 |
+ | 424 × 240 | 15 | 220 | 440 |
+ | 640 × 360 | 15 | 400 | 800 |
+ | 360 × 360 | 15 | 260 | 520 |
+ | 640 × 360 | 30 | 600 | 1200 |
+ | 360 × 360 | 30 | 400 | 800 |
+ | 480 × 360 | 15 | 320 | 640 |
+ | 480 × 360 | 30 | 490 | 980 |
+ | 640 × 480 | 15 | 500 | 1000 |
+ | 480 × 480 | 15 | 400 | 800 |
+ | 640 × 480 | 30 | 750 | 1500 |
+ | 480 × 480 | 30 | 600 | 1200 |
+ | 848 × 480 | 15 | 610 | 1220 |
+ | 848 × 480 | 30 | 930 | 1860 |
+ | 640 × 480 | 10 | 400 | 800 |
+ | 1280 × 720 | 15 | 1130 | 2260 |
+ | 1280 × 720 | 30 | 1710 | 3420 |
+ | 960 × 720 | 15 | 910 | 1820 |
+ | 960 × 720 | 30 | 1380 | 2760 |
+ | 1920 × 1080 | 15 | 2080 | 4160 |
+ | 1920 × 1080 | 30 | 3150 | 6300 |
+ | 1920 × 1080 | 60 | 4780 | 6500 |
+ | 2560 × 1440 | 30 | 4850 | 6500 |
+ | 2560 × 1440 | 60 | 6500 | 6500 |
+ | 3840 × 2160 | 30 | 6500 | 6500 |
+ | 3840 × 2160 | 60 | 6500 | 6500 |
+
+ */
+ int bitrate;
+ /** The minimum encoding bitrate (Kbps).
+
+ The SDK automatically adjusts the encoding bitrate to adapt to the network conditions. Using a value greater than the default value forces the video encoder to output high-quality images but may cause more packet loss and hence sacrifice the smoothness of the video transmission. That said, unless you have special requirements for image quality, Agora does not recommend changing this value.
+
+ @note This parameter applies only to the Live-broadcast profile.
+ */
+ int minBitrate;
+ /** The video orientation mode of the video: #ORIENTATION_MODE.
+ */
+ ORIENTATION_MODE orientationMode;
+ /** The video encoding degradation preference under limited bandwidth: #DEGRADATION_PREFERENCE.
+ */
+ DEGRADATION_PREFERENCE degradationPreference;
+ /** Sets the mirror mode of the published local video stream. It only affects the video that the remote user sees. See #VIDEO_MIRROR_MODE_TYPE
+
+ @note: The SDK disables the mirror mode by default.
+ */
+ VIDEO_MIRROR_MODE_TYPE mirrorMode;
+
+ VideoEncoderConfiguration(
+ const VideoDimensions& d, FRAME_RATE f,
+ int b, ORIENTATION_MODE m, VIDEO_MIRROR_MODE_TYPE mr = VIDEO_MIRROR_MODE_AUTO)
+ : dimensions(d), frameRate(f), minFrameRate(-1), bitrate(b),
+ minBitrate(DEFAULT_MIN_BITRATE), orientationMode(m),
+ degradationPreference(MAINTAIN_QUALITY), mirrorMode(mr)
+ {}
+ VideoEncoderConfiguration(
+ int width, int height, FRAME_RATE f,
+ int b, ORIENTATION_MODE m, VIDEO_MIRROR_MODE_TYPE mr = VIDEO_MIRROR_MODE_AUTO)
+ : dimensions(width, height), frameRate(f),
+ minFrameRate(-1), bitrate(b),
+ minBitrate(DEFAULT_MIN_BITRATE), orientationMode(m),
+ degradationPreference(MAINTAIN_QUALITY), mirrorMode(mr)
+ {}
+ VideoEncoderConfiguration()
+ : dimensions(640, 480)
+ , frameRate(FRAME_RATE_FPS_15)
+ , minFrameRate(-1)
+ , bitrate(STANDARD_BITRATE)
+ , minBitrate(DEFAULT_MIN_BITRATE)
+ , orientationMode(ORIENTATION_MODE_ADAPTIVE)
+ , degradationPreference(MAINTAIN_QUALITY)
+ , mirrorMode(VIDEO_MIRROR_MODE_AUTO)
+ {}
+};
+
+/** The video properties of the user displaying the video in the CDN live. Agora supports a maximum of 17 transcoding users in a CDN streaming channel.
+*/
+typedef struct TranscodingUser {
+ /** User ID of the user displaying the video in the CDN live.
+ */
+ uid_t uid;
+
+/** Horizontal position (pixel) of the video frame relative to the top left corner.
+*/
+ int x;
+ /** Vertical position (pixel) of the video frame relative to the top left corner.
+ */
+ int y;
+ /** Width (pixel) of the video frame. The default value is 360.
+ */
+ int width;
+ /** Height (pixel) of the video frame. The default value is 640.
+ */
+ int height;
+
+ /** Layer position of the video frame. The value ranges between 0 and 100.
+
+ - 0: (Default) Lowest
+ - 100: Highest
+
+ @note
+ - If zOrder is beyond this range, the SDK reports #ERR_INVALID_ARGUMENT.
+ - As of v2.3, the SDK supports zOrder = 0.
+ */
+ int zOrder;
+ /** Transparency of the video frame in CDN live. The value ranges between 0 and 1.0:
+
+ - 0: Completely transparent
+ - 1.0: (Default) Opaque
+ */
+ double alpha;
+ /** The audio channel of the sound. The default value is 0:
+
+ - 0: (Default) Supports dual channels at most, depending on the upstream of the broadcaster.
+ - 1: The audio stream of the broadcaster uses the FL audio channel. If the upstream of the broadcaster uses multiple audio channels, these channels are mixed into mono first.
+ - 2: The audio stream of the broadcaster uses the FC audio channel. If the upstream of the broadcaster uses multiple audio channels, these channels are mixed into mono first.
+ - 3: The audio stream of the broadcaster uses the FR audio channel. If the upstream of the broadcaster uses multiple audio channels, these channels are mixed into mono first.
+ - 4: The audio stream of the broadcaster uses the BL audio channel. If the upstream of the broadcaster uses multiple audio channels, these channels are mixed into mono first.
+ - 5: The audio stream of the broadcaster uses the BR audio channel. If the upstream of the broadcaster uses multiple audio channels, these channels are mixed into mono first.
+
+ @note If your setting is not 0, you may need a specialized player.
+ */
+ int audioChannel;
+ TranscodingUser()
+ : uid(0)
+ , x(0)
+ , y(0)
+ , width(0)
+ , height(0)
+ , zOrder(0)
+ , alpha(1.0)
+ , audioChannel(0)
+ {}
+
+} TranscodingUser;
+
+/** Image properties.
+
+ The properties of the watermark and background images.
+ */
+typedef struct RtcImage {
+ RtcImage() :
+ url(NULL),
+ x(0),
+ y(0),
+ width(0),
+ height(0)
+ {}
+ /** HTTP/HTTPS URL address of the image on the broadcasting video. The maximum length of this parameter is 1024 bytes. */
+ const char* url;
+ /** Horizontal position of the image from the upper left of the broadcasting video. */
+ int x;
+ /** Vertical position of the image from the upper left of the broadcasting video. */
+ int y;
+ /** Width of the image on the broadcasting video. */
+ int width;
+ /** Height of the image on the broadcasting video. */
+ int height;
+} RtcImage;
+
+/** A struct for managing CDN live audio/video transcoding settings.
+*/
+typedef struct LiveTranscoding {
+ /** Width of the video. The default value is 360.
+ * - If you push video streams to the CDN, set the value of width × height to at least 64 × 64 (px), or the SDK will adjust it to 64 × 64 (px).
+ * - If you push audio streams to the CDN, set the value of width × height to 0 × 0 (px).
+ */
+ int width;
+ /** Height of the video. The default value is 640.
+ * - If you push video streams to the CDN, set the value of width × height to at least 64 × 64 (px), or the SDK will adjust it to 64 × 64 (px).
+ * - If you push audio streams to the CDN, set the value of width × height to 0 × 0 (px).
+ */
+ int height;
+ /** Bitrate of the CDN live output video stream. The default value is 400 Kbps.
+
+ Set this parameter according to the Video Bitrate Table. If you set a bitrate beyond the proper range, the SDK automatically adapts it to a value within the range.
+ */
+ int videoBitrate;
+ /** Frame rate of the output video stream set for the CDN live broadcast. The default value is 15 fps, and the value range is (0,30].
+
+ @note Agora adjusts all values over 30 to 30.
+ */
+ int videoFramerate;
+
+ /** **DEPRECATED** Latency mode:
+
+ - true: Low latency with unassured quality.
+ - false: (Default) High latency with assured quality.
+ */
+ bool lowLatency;
+
+ /** Video GOP in frames. The default value is 30 fps.
+ */
+ int videoGop;
+ /** Self-defined video codec profile: #VIDEO_CODEC_PROFILE_TYPE.
+
+ @note If you set this parameter to other values, Agora adjusts it to the default value of 100.
+ */
+ VIDEO_CODEC_PROFILE_TYPE videoCodecProfile;
+ /** The background color in RGB hex value. Value only, do not include a #. For example, 0xFFB6C1 (light pink). The default value is 0x000000 (black).
+ */
+ unsigned int backgroundColor;
+ /** The number of users in the live broadcast.
+ */
+ unsigned int userCount;
+ /** TranscodingUser
+ */
+ TranscodingUser *transcodingUsers;
+ /** Reserved property. Extra user-defined information to send SEI for the H.264/H.265 video stream to the CDN live client. Maximum length: 4096 Bytes.
+
+ For more information on SEI frame, see [SEI-related questions](https://docs.agora.io/en/faq/sei).
+ */
+ const char *transcodingExtraInfo;
+
+ /** **DEPRECATED** The metadata sent to the CDN live client defined by the RTMP or FLV metadata.
+ */
+ const char *metadata;
+ /** The watermark image added to the CDN live publishing stream.
+
+ Ensure that the format of the image is PNG. Once a watermark image is added, the audience of the CDN live publishing stream can see the watermark image. See RtcImage.
+ */
+ RtcImage* watermark;
+ /** The background image added to the CDN live publishing stream.
+
+ Once a background image is added, the audience of the CDN live publishing stream can see the background image. See RtcImage.
+ */
+ RtcImage* backgroundImage;
+ /** Self-defined audio-sample rate: #AUDIO_SAMPLE_RATE_TYPE.
+ */
+ AUDIO_SAMPLE_RATE_TYPE audioSampleRate;
+ /** Bitrate of the CDN live audio output stream. The default value is 48 Kbps, and the highest value is 128.
+ */
+ int audioBitrate;
+ /** Agora's self-defined audio-channel types. We recommend choosing option 1 or 2. A special player is required if you choose option 3, 4, or 5:
+
+ - 1: (Default) Mono
+ - 2: Two-channel stereo
+ - 3: Three-channel stereo
+ - 4: Four-channel stereo
+ - 5: Five-channel stereo
+ */
+ int audioChannels;
+ /** Self-defined audio codec profile: #AUDIO_CODEC_PROFILE_TYPE.
+ */
+
+ AUDIO_CODEC_PROFILE_TYPE audioCodecProfile;
+
+
+ LiveTranscoding()
+ : width(360)
+ , height(640)
+ , videoBitrate(400)
+ , videoFramerate(15)
+ , lowLatency(false)
+ , videoGop(30)
+ , videoCodecProfile(VIDEO_CODEC_PROFILE_HIGH)
+ , backgroundColor(0x000000)
+ , userCount(0)
+ , transcodingUsers(NULL)
+ , transcodingExtraInfo(NULL)
+ , metadata(NULL)
+ , watermark(NULL)
+ , backgroundImage(NULL)
+ , audioSampleRate(AUDIO_SAMPLE_RATE_48000)
+ , audioBitrate(48)
+ , audioChannels(1)
+ , audioCodecProfile(AUDIO_CODEC_PROFILE_LC_AAC)
+ {}
+} LiveTranscoding;
+
+ /** Camera capturer configuration.
+ */
+ struct CameraCapturerConfiguration{
+
+ /** Camera capturer preference settings. See: #CAPTURER_OUTPUT_PREFERENCE. */
+ CAPTURER_OUTPUT_PREFERENCE preference;
+ #if defined(__ANDROID__) || (defined(__APPLE__) && TARGET_OS_IOS)
+ /** Camera direction settings (for Android/iOS only). See: #CAMERA_DIRECTION. */
+ CAMERA_DIRECTION cameraDirection;
+ #endif
+ };
+
+/** Configuration of the imported live broadcast voice or video stream.
+ */
+struct InjectStreamConfig {
+ /** Width of the added stream in the live broadcast. The default value is 0 (same width as the original stream).
+ */
+ int width;
+ /** Height of the added stream in the live broadcast. The default value is 0 (same height as the original stream).
+ */
+ int height;
+ /** Video GOP of the added stream in the live broadcast in frames. The default value is 30 fps.
+ */
+ int videoGop;
+ /** Video frame rate of the added stream in the live broadcast. The default value is 15 fps.
+ */
+ int videoFramerate;
+ /** Video bitrate of the added stream in the live broadcast. The default value is 400 Kbps.
+
+ @note The setting of the video bitrate is closely linked to the resolution. If the video bitrate you set is beyond a reasonable range, the SDK sets it within a reasonable range.
+ */
+ int videoBitrate;
+ /** Audio-sample rate of the added stream in the live broadcast: #AUDIO_SAMPLE_RATE_TYPE. The default value is 48000 Hz.
+
+ @note We recommend setting the default value.
+ */
+ AUDIO_SAMPLE_RATE_TYPE audioSampleRate;
+ /** Audio bitrate of the added stream in the live broadcast. The default value is 48.
+
+ @note We recommend setting the default value.
+ */
+ int audioBitrate;
+ /** Audio channels in the live broadcast.
+
+ - 1: (Default) Mono
+ - 2: Two-channel stereo
+
+ @note We recommend setting the default value.
+ */
+ int audioChannels;
+
+ // width / height default set to 0 means pull the stream with its original resolution
+ InjectStreamConfig()
+ : width(0)
+ , height(0)
+ , videoGop(30)
+ , videoFramerate(15)
+ , videoBitrate(400)
+ , audioSampleRate(AUDIO_SAMPLE_RATE_48000)
+ , audioBitrate(48)
+ , audioChannels(1)
+ {}
+};
+/** The definition of ChannelMediaInfo.
+ */
+struct ChannelMediaInfo {
+ /** The channel name.
+ */
+ const char* channelName;
+ /** The token that enables the user to join the channel.
+ */
+ const char* token;
+ /** The user ID.
+ */
+ uid_t uid;
+};
+
+/** The definition of ChannelMediaRelayConfiguration.
+ */
+struct ChannelMediaRelayConfiguration {
+ /** Pointer to the information of the source channel: ChannelMediaInfo. It contains the following members:
+ * - `channelName`: The name of the source channel. The default value is `NULL`, which means the SDK applies the name of the current channel.
+ * - `uid`: ID of the broadcaster whose media stream you want to relay. The default value is 0, which means the SDK generates a random UID. You must set it as 0.
+ * - `token`: The token for joining the source channel. It is generated with the `channelName` and `uid` you set in `srcInfo`.
+ * - If you have not enabled the App Certificate, set this parameter as the default value `NULL`, which means the SDK applies the App ID.
+ * - If you have enabled the App Certificate, you must use the `token` generated with the `channelName` and `uid`, and the `uid` must be set as 0.
+ */
+ ChannelMediaInfo *srcInfo;
+ /** Pointer to the information of the destination channel: ChannelMediaInfo. It contains the following members:
+ * - `channelName`: The name of the destination channel.
+ * - `uid`: ID of the broadcaster in the destination channel. The value ranges from 0 to (232-1). To avoid UID conflicts, this `uid` must be different from any other UIDs in the destination channel. The default value is 0, which means the SDK generates a random UID.
+ * - `token`: The token for joining the destination channel. It is generated with the `channelName` and `uid` you set in `destInfos`.
+ * - If you have not enabled the App Certificate, set this parameter as the default value `NULL`, which means the SDK applies the App ID.
+ * - If you have enabled the App Certificate, you must use the `token` generated with the `channelName` and `uid`.
+ */
+ ChannelMediaInfo *destInfos;
+ /** The number of destination channels. The default value is 0, and the
+ * value range is [0,4). Ensure that the value of this parameter
+ * corresponds to the number of ChannelMediaInfo structs you define in
+ * `destInfos`.
+ */
+ int destCount;
+
+ ChannelMediaRelayConfiguration()
+ : srcInfo(nullptr)
+ , destInfos(nullptr)
+ , destCount(0)
+ {}
+};
+
+/** **DEPRECATED** Lifecycle of the CDN live video stream.
+*/
+enum RTMP_STREAM_LIFE_CYCLE_TYPE
+{
+ /** Bind to the channel lifecycle. If all hosts leave the channel, the CDN live streaming stops after 30 seconds.
+ */
+ RTMP_STREAM_LIFE_CYCLE_BIND2CHANNEL = 1,
+ /** Bind to the owner of the RTMP stream. If the owner leaves the channel, the CDN live streaming stops immediately.
+ */
+ RTMP_STREAM_LIFE_CYCLE_BIND2OWNER = 2,
+};
+
+/** Content hints for screen sharing.
+*/
+enum VideoContentHint
+{
+ /** (Default) No content hint.
+ */
+ CONTENT_HINT_NONE,
+ /** Motion-intensive content. Choose this option if you prefer smoothness or when you are sharing a video clip, movie, or video game.
+ */
+ CONTENT_HINT_MOTION,
+ /** Motionless content. Choose this option if you prefer sharpness or when you are sharing a picture, PowerPoint slide, or text.
+ */
+ CONTENT_HINT_DETAILS
+};
+
+/** The relative location of the region to the screen or window.
+ */
+struct Rectangle
+{
+ /** The horizontal offset from the top-left corner.
+ */
+ int x;
+ /** The vertical offset from the top-left corner.
+ */
+ int y;
+ /** The width of the region.
+ */
+ int width;
+ /** The height of the region.
+ */
+ int height;
+
+ Rectangle(): x(0), y(0), width(0), height(0) {}
+ Rectangle(int xx, int yy, int ww, int hh): x(xx), y(yy), width(ww), height(hh) {}
+};
+
+/** **DEPRECATED** Definition of the rectangular region. */
+typedef struct Rect {
+ /** Y-axis of the top line.
+ */
+ int top;
+ /** X-axis of the left line.
+ */
+ int left;
+ /** Y-axis of the bottom line.
+ */
+ int bottom;
+ /** X-axis of the right line.
+ */
+ int right;
+
+ Rect(): top(0), left(0), bottom(0), right(0) {}
+ Rect(int t, int l, int b, int r): top(t), left(l), bottom(b), right(r) {}
+} Rect;
+
+/** The options of the watermark image to be added. */
+typedef struct WatermarkOptions {
+ /** Sets whether or not the watermark image is visible in the local video preview:
+ * - true: (Default) The watermark image is visible in preview.
+ * - false: The watermark image is not visible in preview.
+ */
+ bool visibleInPreview;
+ /**
+ * The watermark position in the landscape mode. See Rectangle.
+ * For detailed information on the landscape mode, see [Rotate the video](https://docs.agora.io/en/Interactive%20Broadcast/rotation_guide_windows?platform=Windows).
+ */
+ Rectangle positionInLandscapeMode;
+ /**
+ * The watermark position in the portrait mode. See Rectangle.
+ * For detailed information on the portrait mode, see [Rotate the video](https://docs.agora.io/en/Interactive%20Broadcast/rotation_guide_windows?platform=Windows).
+ */
+ Rectangle positionInPortraitMode;
+
+ WatermarkOptions()
+ : visibleInPreview(true)
+ , positionInLandscapeMode(0, 0, 0, 0)
+ , positionInPortraitMode(0, 0, 0, 0)
+ {}
+} WatermarkOptions;
+
+/** Screen sharing encoding parameters.
+*/
+struct ScreenCaptureParameters
+{
+ /** The maximum encoding dimensions of the shared region in terms of width × height.
+
+ The default value is 1920 × 1080 pixels, that is, 2073600 pixels. Agora uses the value of this parameter to calculate the charges.
+
+ If the aspect ratio is different between the encoding dimensions and screen dimensions, Agora applies the following algorithms for encoding. Suppose the encoding dimensions are 1920 x 1080:
+
+ - If the value of the screen dimensions is lower than that of the encoding dimensions, for example, 1000 × 1000, the SDK uses 1000 × 1000 for encoding.
+ - If the value of the screen dimensions is higher than that of the encoding dimensions, for example, 2000 × 1500, the SDK uses the maximum value under 1920 × 1080 with the aspect ratio of the screen dimension (4:3) for encoding, that is, 1440 × 1080.
+ */
+ VideoDimensions dimensions;
+ /** The frame rate (fps) of the shared region.
+
+ The default value is 5. We do not recommend setting this to a value greater than 15.
+ */
+ int frameRate;
+ /** The bitrate (Kbps) of the shared region.
+
+ The default value is 0 (the SDK works out a bitrate according to the dimensions of the current screen).
+ */
+ int bitrate;
+ /** Sets whether or not to capture the mouse for screen sharing:
+
+ - true: (Default) Capture the mouse.
+ - false: Do not capture the mouse.
+ */
+ bool captureMouseCursor;
+
+ ScreenCaptureParameters() : dimensions(1920, 1080), frameRate(5), bitrate(STANDARD_BITRATE), captureMouseCursor(true) {}
+ ScreenCaptureParameters(const VideoDimensions& d, int f, int b, bool c) : dimensions(d), frameRate(f), bitrate(b), captureMouseCursor(c) {}
+ ScreenCaptureParameters(int width, int height, int f, int b, bool c) : dimensions(width, height), frameRate(f), bitrate(b), captureMouseCursor(c) {}
+};
+
+/** Video display settings of the VideoCanvas class.
+*/
+struct VideoCanvas
+{
+ /** Video display window (view).
+ */
+ view_t view;
+ /** The rendering mode of the video view. See RENDER_MODE_TYPE
+ */
+ int renderMode;
+ /** The unique channel name for the AgoraRTC session in the string format. The string length must be less than 64 bytes. Supported character scopes are:
+ - All lowercase English letters: a to z.
+ - All uppercase English letters: A to Z.
+ - All numeric characters: 0 to 9.
+ - The space character.
+ - Punctuation characters and other symbols, including: "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
+
+ @note
+ - The default value is the empty string "". Use the default value if the user joins the channel using the \ref IRtcEngine::joinChannel "joinChannel" method in the IRtcEngine class. The `VideoCanvas` struct defines the video canvas of the user in the channel.
+ - If the user joins the channel using the \ref IRtcEngine::joinChannel "joinChannel" method in the IChannel class, set this parameter as the `channelId` of the `IChannel` object. The `VideoCanvas` struct defines the video canvas of the user in the channel with the specified channel ID.
+ */
+ char channelId[MAX_CHANNEL_ID_LENGTH];
+ /** The user ID. */
+ uid_t uid;
+ void *priv; // private data (underlying video engine denotes it)
+ /** The mirror mode of the video view. See VIDEO_MIRROR_MODE_TYPE
+ @note
+ - For the mirror mode of the local video view: If you use a front camera, the SDK enables the mirror mode by default; if you use a rear camera, the SDK disables the mirror mode by default.
+ - For the mirror mode of the remote video view: The SDK disables the mirror mode by default.
+ */
+ VIDEO_MIRROR_MODE_TYPE mirrorMode;
+
+ VideoCanvas()
+ : view(NULL)
+ , renderMode(RENDER_MODE_HIDDEN)
+ , uid(0)
+ , priv(NULL)
+ , mirrorMode(VIDEO_MIRROR_MODE_AUTO)
+ {
+ channelId[0] = '\0';
+ }
+ VideoCanvas(view_t v, int m, uid_t u)
+ : view(v)
+ , renderMode(m)
+ , uid(u)
+ , priv(NULL)
+ , mirrorMode(VIDEO_MIRROR_MODE_AUTO)
+ {
+ channelId[0] = '\0';
+ }
+ VideoCanvas(view_t v, int m, const char *ch, uid_t u)
+ : view(v)
+ , renderMode(m)
+ , uid(u)
+ , priv(NULL)
+ , mirrorMode(VIDEO_MIRROR_MODE_AUTO)
+ {
+ strncpy(channelId, ch, MAX_CHANNEL_ID_LENGTH);
+ channelId[MAX_CHANNEL_ID_LENGTH - 1] = '\0';
+ }
+ VideoCanvas(view_t v, int rm, uid_t u, VIDEO_MIRROR_MODE_TYPE mm)
+ : view(v)
+ , renderMode(rm)
+ , uid(u)
+ , priv(NULL)
+ , mirrorMode(mm)
+ {
+ channelId[0] = '\0';
+ }
+ VideoCanvas(view_t v, int rm, const char *ch, uid_t u, VIDEO_MIRROR_MODE_TYPE mm)
+ : view(v)
+ , renderMode(rm)
+ , uid(u)
+ , priv(NULL)
+ , mirrorMode(mm)
+ {
+ strncpy(channelId, ch, MAX_CHANNEL_ID_LENGTH);
+ channelId[MAX_CHANNEL_ID_LENGTH - 1] = '\0';
+ }
+};
+
+/** Image enhancement options.
+*/
+struct BeautyOptions {
+ /** The contrast level, used with the @p lightening parameter.
+ */
+ enum LIGHTENING_CONTRAST_LEVEL
+ {
+ /** Low contrast level. */
+ LIGHTENING_CONTRAST_LOW = 0,
+ /** (Default) Normal contrast level. */
+ LIGHTENING_CONTRAST_NORMAL,
+ /** High contrast level. */
+ LIGHTENING_CONTRAST_HIGH
+ };
+
+/** The contrast level, used with the @p lightening parameter.
+*/
+LIGHTENING_CONTRAST_LEVEL lighteningContrastLevel;
+
+/** The brightness level. The value ranges from 0.0 (original) to 1.0. */
+float lighteningLevel;
+
+/** The sharpness level. The value ranges between 0 (original) and 1. This parameter is usually used to remove blemishes.
+ */
+float smoothnessLevel;
+
+/** The redness level. The value ranges between 0 (original) and 1. This parameter adjusts the red saturation level.
+*/
+float rednessLevel;
+
+BeautyOptions(LIGHTENING_CONTRAST_LEVEL contrastLevel, float lightening, float smoothness, float redness)
+ : lighteningLevel(lightening),
+ smoothnessLevel(smoothness),
+ rednessLevel(redness),
+ lighteningContrastLevel(contrastLevel) {}
+
+BeautyOptions()
+ : lighteningLevel(0),
+ smoothnessLevel(0),
+ rednessLevel(0),
+ lighteningContrastLevel(LIGHTENING_CONTRAST_NORMAL) {}
+};
+
+struct UserInfo {
+ uid_t uid;
+ char userAccount[MAX_USER_ACCOUNT_LENGTH];
+ UserInfo()
+ : uid(0) {
+ userAccount[0] = '\0';
+ }
+};
+
+/** Definition of IPacketObserver.
+*/
+class IPacketObserver
+{
+public:
+/** Definition of Packet.
+ */
+ struct Packet
+ {
+ /** Buffer address of the sent or received data.
+ * @note Agora recommends that the value of buffer is more than 2048 bytes, otherwise, you may meet undefined behaviors such as a crash.
+ */
+ const unsigned char* buffer;
+ /** Buffer size of the sent or received data.
+ */
+ unsigned int size;
+ };
+ /** Occurs when the local user sends an audio packet.
+
+ @param packet The sent audio packet. See Packet.
+ @return
+ - true: The audio packet is sent successfully.
+ - false: The audio packet is discarded.
+ */
+ virtual bool onSendAudioPacket(Packet& packet) = 0;
+ /** Occurs when the local user sends a video packet.
+
+ @param packet The sent video packet. See Packet.
+ @return
+ - true: The video packet is sent successfully.
+ - false: The video packet is discarded.
+ */
+ virtual bool onSendVideoPacket(Packet& packet) = 0;
+ /** Occurs when the local user receives an audio packet.
+
+ @param packet The received audio packet. See Packet.
+ @return
+ - true: The audio packet is received successfully.
+ - false: The audio packet is discarded.
+ */
+ virtual bool onReceiveAudioPacket(Packet& packet) = 0;
+ /** Occurs when the local user receives a video packet.
+
+ @param packet The received video packet. See Packet.
+ @return
+ - true: The video packet is received successfully.
+ - false: The video packet is discarded.
+ */
+ virtual bool onReceiveVideoPacket(Packet& packet) = 0;
+};
+
+/** The SDK uses the IRtcEngineEventHandler interface class to send callbacks to the application. The application inherits the methods of this interface class to retrieve these callbacks.
+
+ All methods in this interface class have default (empty) implementations. Therefore, the application can only inherit some required events. In the callbacks, avoid time-consuming tasks or calling blocking APIs, such as the SendMessage method. Otherwise, the SDK may not work properly.
+ */
+class IRtcEngineEventHandler
+{
+public:
+ virtual ~IRtcEngineEventHandler() {}
+
+ /** Reports a warning during SDK runtime.
+
+ In most cases, the application can ignore the warning reported by the SDK because the SDK can usually fix the issue and resume running. For example, when losing connection with the server, the SDK may report #WARN_LOOKUP_CHANNEL_TIMEOUT and automatically try to reconnect.
+
+ @param warn Warning code: #WARN_CODE_TYPE.
+ @param msg Pointer to the warning message.
+ */
+ virtual void onWarning(int warn, const char* msg) {
+ (void)warn;
+ (void)msg;
+ }
+
+ /** Reports an error during SDK runtime.
+
+ In most cases, the SDK cannot fix the issue and resume running. The SDK requires the application to take action or informs the user about the issue.
+
+ For example, the SDK reports an #ERR_START_CALL error when failing to initialize a call. The application informs the user that the call initialization failed and invokes the \ref IRtcEngine::leaveChannel "leaveChannel" method to leave the channel.
+
+ @param err Error code: #ERROR_CODE_TYPE.
+ @param msg Pointer to the error message.
+ */
+ virtual void onError(int err, const char* msg) {
+ (void)err;
+ (void)msg;
+ }
+
+ /** Occurs when a user joins a channel.
+
+ This callback notifies the application that a user joins a specified channel when the application calls the \ref IRtcEngine::joinChannel "joinChannel" method.
+
+ The channel name assignment is based on @p channelName specified in the \ref IRtcEngine::joinChannel "joinChannel" method.
+
+ If the @p uid is not specified in the *joinChannel* method, the server automatically assigns a @p uid.
+
+ @param channel Pointer to the channel name.
+ @param uid User ID of the user joining the channel.
+ @param elapsed Time elapsed (ms) from the user calling the \ref IRtcEngine::joinChannel "joinChannel" method until the SDK triggers this callback.
+ */
+ virtual void onJoinChannelSuccess(const char* channel, uid_t uid, int elapsed) {
+ (void)channel;
+ (void)uid;
+ (void)elapsed;
+ }
+
+ /** Occurs when a user rejoins the channel after disconnection due to network problems.
+
+ When a user loses connection with the server because of network problems, the SDK automatically tries to reconnect and triggers this callback upon reconnection.
+
+ @param channel Pointer to the channel name.
+ @param uid User ID of the user rejoining the channel.
+ @param elapsed Time elapsed (ms) from starting to reconnect until the SDK triggers this callback.
+ */
+ virtual void onRejoinChannelSuccess(const char* channel, uid_t uid, int elapsed) {
+ (void)channel;
+ (void)uid;
+ (void)elapsed;
+ }
+
+ /** Occurs when a user leaves the channel.
+
+ This callback notifies the application that a user leaves the channel when the application calls the \ref IRtcEngine::leaveChannel "leaveChannel" method.
+
+ The application retrieves information, such as the call duration and statistics.
+
+ @param stats Pointer to the statistics of the call: RtcStats.
+ */
+ virtual void onLeaveChannel(const RtcStats& stats) {
+ (void)stats;
+ }
+
+ /** Occurs when the user role switches in a live broadcast. For example, from a host to an audience or vice versa.
+
+ This callback notifies the application of a user role switch when the application calls the \ref IRtcEngine::setClientRole "setClientRole" method.
+
+ The SDK triggers this callback when the local user switches the user role by calling the \ref agora::rtc::IRtcEngine::setClientRole "setClientRole" method after joining the channel.
+ @param oldRole Role that the user switches from: #CLIENT_ROLE_TYPE.
+ @param newRole Role that the user switches to: #CLIENT_ROLE_TYPE.
+ */
+ virtual void onClientRoleChanged(CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole) {
+ }
+
+ /** Occurs when a remote user (Communication)/ host (Live Broadcast) joins the channel.
+
+ - Communication profile: This callback notifies the application that another user joins the channel. If other users are already in the channel, the SDK also reports to the application on the existing users.
+ - Live-broadcast profile: This callback notifies the application that the host joins the channel. If other hosts are already in the channel, the SDK also reports to the application on the existing hosts. We recommend limiting the number of hosts to 17.
+
+ The SDK triggers this callback under one of the following circumstances:
+ - A remote user/host joins the channel by calling the \ref agora::rtc::IRtcEngine::joinChannel "joinChannel" method.
+ - A remote user switches the user role to the host by calling the \ref agora::rtc::IRtcEngine::setClientRole "setClientRole" method after joining the channel.
+ - A remote user/host rejoins the channel after a network interruption.
+ - The host injects an online media stream into the channel by calling the \ref agora::rtc::IRtcEngine::addInjectStreamUrl "addInjectStreamUrl" method.
+
+ @note In the Live-broadcast profile:
+ - The host receives this callback when another host joins the channel.
+ - The audience in the channel receives this callback when a new host joins the channel.
+ - When a web application joins the channel, the SDK triggers this callback as long as the web application publishes streams.
+
+ @param uid User ID of the user or host joining the channel.
+ @param elapsed Time delay (ms) from the local user calling the \ref IRtcEngine::joinChannel "joinChannel" method until the SDK triggers this callback.
+ */
+ virtual void onUserJoined(uid_t uid, int elapsed) {
+ (void)uid;
+ (void)elapsed;
+ }
+
+ /** Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
+
+ Reasons why the user is offline:
+
+ - Leave the channel: When the user/host leaves the channel, the user/host sends a goodbye message. When the message is received, the SDK assumes that the user/host leaves the channel.
+ - Drop offline: When no data packet of the user or host is received for a certain period of time, the SDK assumes that the user/host drops offline. Unreliable network connections may lead to false detections, so we recommend using a signaling system for more reliable offline detection.
+
+ @param uid User ID of the user leaving the channel or going offline.
+ @param reason Reason why the user is offline: #USER_OFFLINE_REASON_TYPE.
+ */
+ virtual void onUserOffline(uid_t uid, USER_OFFLINE_REASON_TYPE reason) {
+ (void)uid;
+ (void)reason;
+ }
+
+ /** Reports the last mile network quality of the local user once every two seconds before the user joins the channel.
+
+ Last mile refers to the connection between the local device and Agora's edge server. After the application calls the \ref IRtcEngine::enableLastmileTest "enableLastmileTest" method, this callback reports once every two seconds the uplink and downlink last mile network conditions of the local user before the user joins the channel.
+
+ @param quality The last mile network quality: #QUALITY_TYPE.
+ */
+ virtual void onLastmileQuality(int quality) {
+ (void)quality;
+ }
+
+ /** Reports the last-mile network probe result.
+
+ The SDK triggers this callback within 30 seconds after the app calls the \ref agora::rtc::IRtcEngine::startLastmileProbeTest "startLastmileProbeTest" method.
+
+ @param result The uplink and downlink last-mile network probe test result. See LastmileProbeResult.
+ */
+ virtual void onLastmileProbeResult(const LastmileProbeResult& result) {
+ (void)result;
+ }
+
+ /** **DEPRECATED** Occurs when the connection between the SDK and the server is interrupted.
+
+ Deprecated as of v2.3.2. Replaced by the \ref agora::rtc::IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged(CONNECTION_STATE_RECONNECTING, CONNECTION_CHANGED_INTERRUPTED)" callback.
+
+ The SDK triggers this callback when it loses connection with the server for more than four seconds after the connection is established.
+
+ After triggering this callback, the SDK tries reconnecting to the server. You can use this callback to implement pop-up reminders.
+
+ This callback is different from \ref agora::rtc::IRtcEngineEventHandler::onConnectionLost "onConnectionLost":
+ - The SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onConnectionInterrupted "onConnectionInterrupted" callback when it loses connection with the server for more than four seconds after it successfully joins the channel.
+ - The SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onConnectionLost "onConnectionLost" callback when it loses connection with the server for more than 10 seconds, whether or not it joins the channel.
+
+ If the SDK fails to rejoin the channel 20 minutes after being disconnected from Agora's edge server, the SDK stops rejoining the channel.
+
+ */
+ virtual void onConnectionInterrupted() {}
+
+ /** Occurs when the SDK cannot reconnect to Agora's edge server 10 seconds after its connection to the server is interrupted.
+
+ The SDK triggers this callback when it cannot connect to the server 10 seconds after calling the \ref IRtcEngine::joinChannel "joinChannel" method, whether or not it is in the channel.
+
+ This callback is different from \ref agora::rtc::IRtcEngineEventHandler::onConnectionInterrupted "onConnectionInterrupted":
+
+ - The SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onConnectionInterrupted "onConnectionInterrupted" callback when it loses connection with the server for more than four seconds after it successfully joins the channel.
+ - The SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onConnectionLost "onConnectionLost" callback when it loses connection with the server for more than 10 seconds, whether or not it joins the channel.
+
+ If the SDK fails to rejoin the channel 20 minutes after being disconnected from Agora's edge server, the SDK stops rejoining the channel.
+
+ */
+ virtual void onConnectionLost() {}
+
+ /** **DEPRECATED** Deprecated as of v2.3.2. Replaced by the \ref agora::rtc::IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged(CONNECTION_STATE_FAILED, CONNECTION_CHANGED_BANNED_BY_SERVER)" callback.
+
+ Occurs when your connection is banned by the Agora Server.
+ */
+ virtual void onConnectionBanned() {}
+
+ /** Occurs when a method is executed by the SDK.
+
+ @param err The error code (#ERROR_CODE_TYPE) returned by the SDK when a method call fails. If the SDK returns 0, then the method call is successful.
+ @param api Pointer to the method executed by the SDK.
+ @param result Pointer to the result of the method call.
+ */
+ virtual void onApiCallExecuted(int err, const char* api, const char* result) {
+ (void)err;
+ (void)api;
+ (void)result;
+ }
+
+ /** Occurs when the token expires.
+
+ After a token is specified by calling the \ref IRtcEngine::joinChannel "joinChannel" method, if the SDK losses connection with the Agora server due to network issues, the token may expire after a certain period of time and a new token may be required to reconnect to the server.
+
+ This callback notifies the application to generate a new token. Call the \ref IRtcEngine::renewToken "renewToken" method to renew the token.
+ */
+ virtual void onRequestToken() {
+ }
+
+ /** Occurs when the token expires in 30 seconds.
+
+ The user becomes offline if the token used in the \ref IRtcEngine::joinChannel "joinChannel" method expires. The SDK triggers this callback 30 seconds before the token expires to remind the application to get a new token. Upon receiving this callback, generate a new token on the server and call the \ref IRtcEngine::renewToken "renewToken" method to pass the new token to the SDK.
+
+ @param token Pointer to the token that expires in 30 seconds.
+ */
+ virtual void onTokenPrivilegeWillExpire(const char* token) {
+ (void)token;
+ }
+
+ /** **DEPRECATED** Reports the statistics of the audio stream from each remote user/host.
+
+ Deprecated as of v2.3.2. Use the \ref agora::rtc::IRtcEngineEventHandler::onRemoteAudioStats "onRemoteAudioStats" callback instead.
+
+ The SDK triggers this callback once every two seconds to report the audio quality of each remote user/host sending an audio stream. If a channel has multiple users/hosts sending audio streams, the SDK triggers this callback as many times.
+
+ @param uid User ID of the speaker.
+ @param quality Audio quality of the user: #QUALITY_TYPE.
+ @param delay Time delay (ms) of sending the audio packet from the sender to the receiver, including the time delay of audio sampling pre-processing, transmission, and the jitter buffer.
+ @param lost Packet loss rate (%) of the audio packet sent from the sender to the receiver.
+ */
+ virtual void onAudioQuality(uid_t uid, int quality, unsigned short delay, unsigned short lost) {
+ (void)uid;
+ (void)quality;
+ (void)delay;
+ (void)lost;
+ }
+
+ /** Reports the statistics of the current call.
+
+ The SDK triggers this callback once every two seconds after the user joins the channel.
+
+ @param stats Statistics of the RtcEngine: RtcStats.
+ */
+ virtual void onRtcStats(const RtcStats& stats) {
+ (void)stats;
+ }
+
+ /** Reports the last mile network quality of each user in the channel once every two seconds.
+
+ Last mile refers to the connection between the local device and Agora's edge server. This callback reports once every two seconds the last mile network conditions of each user in the channel. If a channel includes multiple users, the SDK triggers this callback as many times.
+
+ @param uid User ID. The network quality of the user with this @p uid is reported. If @p uid is 0, the local network quality is reported.
+ @param txQuality Uplink transmission quality rating of the user in terms of the transmission bitrate, packet loss rate, average RTT (Round-Trip Time), and jitter of the uplink network. @p txQuality is a quality rating helping you understand how well the current uplink network conditions can support the selected VideoEncoderConfiguration. For example, a 1000 Kbps uplink network may be adequate for video frames with a resolution of 640 × 480 and a frame rate of 15 fps in the Live-broadcast profile, but may be inadequate for resolutions higher than 1280 × 720. See #QUALITY_TYPE.
+ @param rxQuality Downlink network quality rating of the user in terms of the packet loss rate, average RTT, and jitter of the downlink network. See #QUALITY_TYPE.
+ */
+ virtual void onNetworkQuality(uid_t uid, int txQuality, int rxQuality) {
+ (void)uid;
+ (void)txQuality;
+ (void)rxQuality;
+ }
+
+ /** Reports the statistics of the local video stream.
+ *
+ * The SDK triggers this callback once every two seconds for each
+ * user/host. If there are multiple users/hosts in the channel, the SDK
+ * triggers this callback as many times.
+ *
+ * @note
+ * If you have called the \ref agora::rtc::IRtcEngine::enableDualStream
+ * "enableDualStream" method, the \ref onLocalVideoStats()
+ * "onLocalVideoStats" callback reports the statistics of the high-video
+ * stream (high bitrate, and high-resolution video stream).
+ *
+ * @param stats Statistics of the local video stream. See LocalVideoStats.
+ */
+ virtual void onLocalVideoStats(const LocalVideoStats& stats) {
+ (void)stats;
+ }
+
+ /** Reports the statistics of the video stream from each remote user/host.
+ *
+ * The SDK triggers this callback once every two seconds for each remote
+ * user/host. If a channel includes multiple remote users, the SDK
+ * triggers this callback as many times.
+ *
+ * @param stats Statistics of the remote video stream. See
+ * RemoteVideoStats.
+ */
+ virtual void onRemoteVideoStats(const RemoteVideoStats& stats) {
+ (void)stats;
+ }
+
+ /** Reports the statistics of the local audio stream.
+ *
+ * The SDK triggers this callback once every two seconds.
+ *
+ * @param stats The statistics of the local audio stream.
+ * See LocalAudioStats.
+ */
+ virtual void onLocalAudioStats(const LocalAudioStats& stats) {
+ (void)stats;
+ }
+
+ /** Reports the statistics of the audio stream from each remote user/host.
+
+ This callback replaces the \ref agora::rtc::IRtcEngineEventHandler::onAudioQuality "onAudioQuality" callback.
+
+ The SDK triggers this callback once every two seconds for each remote user/host. If a channel includes multiple remote users, the SDK triggers this callback as many times.
+
+ @param stats Pointer to the statistics of the received remote audio streams. See RemoteAudioStats.
+ */
+ virtual void onRemoteAudioStats(const RemoteAudioStats& stats) {
+ (void)stats;
+ }
+
+ /** Occurs when the local audio state changes.
+ *
+ * This callback indicates the state change of the local audio stream,
+ * including the state of the audio recording and encoding, and allows
+ * you to troubleshoot issues when exceptions occur.
+ *
+ * @note
+ * When the state is #LOCAL_AUDIO_STREAM_STATE_FAILED (3), see the `error`
+ * parameter for details.
+ *
+ * @param state State of the local audio. See #LOCAL_AUDIO_STREAM_STATE.
+ * @param error The error information of the local audio.
+ * See #LOCAL_AUDIO_STREAM_ERROR.
+ */
+ virtual void onLocalAudioStateChanged(LOCAL_AUDIO_STREAM_STATE state, LOCAL_AUDIO_STREAM_ERROR error) {
+ (void)state;
+ (void)error;
+ }
+
+ /** Occurs when the remote audio state changes.
+ *
+ * This callback indicates the state change of the remote audio stream.
+ *
+ * @param uid ID of the remote user whose audio state changes.
+ * @param state State of the remote audio. See #REMOTE_AUDIO_STATE.
+ * @param reason The reason of the remote audio state change.
+ * See #REMOTE_AUDIO_STATE_REASON.
+ * @param elapsed Time elapsed (ms) from the local user calling the
+ * \ref IRtcEngine::joinChannel "joinChannel" method until the SDK
+ * triggers this callback.
+ */
+ virtual void onRemoteAudioStateChanged(uid_t uid, REMOTE_AUDIO_STATE state, REMOTE_AUDIO_STATE_REASON reason, int elapsed) {
+ (void)uid;
+ (void)state;
+ (void)reason;
+ (void)elapsed;
+ }
+
+ /** Reports which users are speaking, the speakers' volume and whether the local user is speaking.
+
+ This callback reports the IDs and volumes of the loudest speakers at the moment in the channel, and whether the local user is speaking.
+
+ By default, this callback is disabled. You can enable it by calling the \ref IRtcEngine::enableAudioVolumeIndication(int, int, bool) "enableAudioVolumeIndication" method.
+ Once enabled, this callback is triggered at the set interval, regardless of whether a user speaks or not.
+
+ The SDK triggers two independent `onAudioVolumeIndication` callbacks at one time, which separately report the volume information of the local user and all the remote speakers.
+ For more information, see the detailed parameter descriptions.
+
+ @note
+ - To enable the voice activity detection of the local user, ensure that you set `report_vad`(true) in the `enableAudioVolumeIndication` method.
+ - Calling the \ref agora::rtc::IRtcEngine::muteLocalAudioStream "muteLocalAudioStream" method affects the SDK's behavior:
+ - If the local user calls the \ref agora::rtc::IRtcEngine::muteLocalAudioStream "muteLocalAudioStream" method, the SDK stops triggering the local user's callback.
+ - 20 seconds after a remote speaker calls the *muteLocalAudioStream* method, the remote speakers' callback excludes this remote user's information; 20 seconds after all remote users call the *muteLocalAudioStream* method, the SDK stops triggering the remote speakers' callback.
+ - An empty @p speakers array in the *onAudioVolumeIndication* callback suggests that no remote user is speaking at the moment.
+
+ @param speakers A pointer to AudioVolumeInfo:
+ - In the local user's callback, this struct contains the following members:
+ - `uid` = 0,
+ - `volume` = `totalVolume`, which reports the sum of the voice volume and audio-mixing volume of the local user, and
+ - `vad`, which reports the voice activity status of the local user.
+ - In the remote speakers' callback, this array contains the following members:
+ - `uid` of the remote speaker,
+ - `volume`, which reports the sum of the voice volume and audio-mixing volume of each remote speaker, and
+ - `vad` = 0.
+
+ An empty speakers array in the callback indicates that no remote user is speaking at the moment.
+ @param speakerNumber Total number of speakers. The value range is [0, 3].
+ - In the local user’s callback, `speakerNumber` = 1, regardless of whether the local user speaks or not.
+ - In the remote speakers' callback, the callback reports the IDs and volumes of the three loudest speakers when there are more than three remote users in the channel, and `speakerNumber` = 3.
+ @param totalVolume Total volume after audio mixing. The value ranges between 0 (lowest volume) and 255 (highest volume).
+ - In the local user’s callback, `totalVolume` is the sum of the voice volume and audio-mixing volume of the local user.
+ - In the remote speakers' callback, `totalVolume` is the sum of the voice volume and audio-mixing volume of all the remote speakers.
+ */
+ virtual void onAudioVolumeIndication(const AudioVolumeInfo* speakers, unsigned int speakerNumber, int totalVolume) {
+ (void)speakers;
+ (void)speakerNumber;
+ (void)totalVolume;
+ }
+
+ /** Reports which user is the loudest speaker.
+
+ If the user enables the audio volume indication by calling the \ref IRtcEngine::enableAudioVolumeIndication(int, int, bool) "enableAudioVolumeIndication" method, this callback returns the @p uid of the active speaker detected by the audio volume detection module of the SDK.
+
+ @note
+ - To receive this callback, you need to call the \ref IRtcEngine::enableAudioVolumeIndication(int, int, bool) "enableAudioVolumeIndication" method.
+ - This callback returns the user ID of the user with the highest voice volume during a period of time, instead of at the moment.
+
+ @param uid User ID of the active speaker. A @p uid of 0 represents the local user.
+ */
+ virtual void onActiveSpeaker(uid_t uid) {
+ (void)uid;
+ }
+
+ /** **DEPRECATED** Occurs when the video stops playing.
+
+ The application can use this callback to change the configuration of the view (for example, displaying other pictures in the view) after the video stops playing.
+
+ Deprecated as of v2.4.1. Use LOCAL_VIDEO_STREAM_STATE_STOPPED(0) in the \ref agora::rtc::IRtcEngineEventHandler::onLocalVideoStateChanged "onLocalVideoStateChanged" callback instead.
+ */
+ virtual void onVideoStopped() {}
+
+ /** Occurs when the first local video frame is displayed/rendered on the local video view.
+
+ @param width Width (px) of the first local video frame.
+ @param height Height (px) of the first local video frame.
+ @param elapsed Time elapsed (ms) from the local user calling the \ref IRtcEngine::joinChannel "joinChannel" method until the SDK triggers this callback.
+ If you call the \ref IRtcEngine::startPreview "startPreview" method before calling the *joinChannel* method, then @p elapsed is the time elapsed from calling the *startPreview* method until the SDK triggers this callback.
+ */
+ virtual void onFirstLocalVideoFrame(int width, int height, int elapsed) {
+ (void)width;
+ (void)height;
+ (void)elapsed;
+ }
+
+ /** Occurs when the first remote video frame is received and decoded.
+ *
+ * @deprecated
+ * This callback is deprecated and replaced by the
+ * \ref onRemoteVideoStateChanged() "onRemoteVideoStateChanged" callback
+ * with the following parameters:
+ * - #REMOTE_VIDEO_STATE_STARTING (1)
+ * - #REMOTE_VIDEO_STATE_DECODING (2)
+ *
+ * This callback is triggered in either of the following scenarios:
+ *
+ * - The remote user joins the channel and sends the video stream.
+ * - The remote user stops sending the video stream and re-sends it after
+ * 15 seconds. Reasons for such an interruption include:
+ * - The remote user leaves the channel.
+ * - The remote user drops offline.
+ * - The remote user calls the
+ * \ref agora::rtc::IRtcEngine::muteLocalVideoStream "muteLocalVideoStream"
+ * method to stop sending the video stream.
+ * - The remote user calls the
+ * \ref agora::rtc::IRtcEngine::disableVideo "disableVideo" method to
+ * disable video.
+ *
+ * The application can configure the user view settings in this callback.
+ *
+ * @param uid User ID of the remote user sending the video stream.
+ * @param width Width (px) of the video stream.
+ * @param height Height (px) of the video stream.
+ * @param elapsed Time elapsed (ms) from the local user calling the
+ * \ref IRtcEngine::joinChannel "joinChannel" method until the SDK
+ * triggers this callback.
+ */
+ virtual void onFirstRemoteVideoDecoded(uid_t uid, int width, int height, int elapsed) {
+ (void)uid;
+ (void)width;
+ (void)height;
+ (void)elapsed;
+ }
+
+ /** Occurs when the first remote video frame is rendered.
+
+ The SDK triggers this callback when the first frame of the remote video is displayed in the user's video window. The application can retrieve the time elapsed from a user joining the channel until the first video frame is displayed.
+
+ @param uid User ID of the remote user sending the video stream.
+ @param width Width (px) of the video frame.
+ @param height Height (px) of the video stream.
+ @param elapsed Time elapsed (ms) from the local user calling the \ref IRtcEngine::joinChannel "joinChannel" method until the SDK triggers this callback.
+ */
+ virtual void onFirstRemoteVideoFrame(uid_t uid, int width, int height, int elapsed) {
+ (void)uid;
+ (void)width;
+ (void)height;
+ (void)elapsed;
+ }
+
+ /** Occurs when a remote user's audio stream playback pauses/resumes.
+
+ The SDK triggers this callback when the remote user stops or resumes sending the audio stream by calling the \ref agora::rtc::IRtcEngine::muteLocalAudioStream "muteLocalAudioStream" method.
+ @note This callback returns invalid when the number of users in a channel exceeds 20.
+
+ @param uid User ID of the remote user.
+ @param muted Whether the remote user's audio stream is muted/unmuted:
+ - true: Muted.
+ - false: Unmuted.
+ */
+ virtual void onUserMuteAudio(uid_t uid, bool muted) {
+ (void)uid;
+ (void)muted;
+ }
+
+ /** Occurs when a remote user's video stream playback pauses/resumes.
+ *
+ * You can also use the
+ * \ref onRemoteVideoStateChanged() "onRemoteVideoStateChanged" callback
+ * with the following parameters:
+ * - #REMOTE_VIDEO_STATE_STOPPED (0) and
+ * #REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED (5).
+ * - #REMOTE_VIDEO_STATE_DECODING (2) and
+ * #REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED (6).
+ *
+ * The SDK triggers this callback when the remote user stops or resumes
+ * sending the video stream by calling the
+ * \ref agora::rtc::IRtcEngine::muteLocalVideoStream
+ * "muteLocalVideoStream" method.
+ *
+ * @note This callback returns invalid when the number of users in a
+ * channel exceeds 20.
+ *
+ * @param uid User ID of the remote user.
+ * @param muted Whether the remote user's video stream playback is
+ * paused/resumed:
+ * - true: Paused.
+ * - false: Resumed.
+ */
+ virtual void onUserMuteVideo(uid_t uid, bool muted) {
+ (void)uid;
+ (void)muted;
+ }
+
+ /** Occurs when a specific remote user enables/disables the video
+ * module.
+ *
+ * @deprecated
+ * This callback is deprecated and replaced by the
+ * \ref onRemoteVideoStateChanged() "onRemoteVideoStateChanged" callback
+ * with the following parameters:
+ * - #REMOTE_VIDEO_STATE_STOPPED (0) and
+ * #REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED (5).
+ * - #REMOTE_VIDEO_STATE_DECODING (2) and
+ * #REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED (6).
+ *
+ * Once the video module is disabled, the remote user can only use a
+ * voice call. The remote user cannot send or receive any video from
+ * other users.
+ *
+ * The SDK triggers this callback when the remote user enables or disables
+ * the video module by calling the
+ * \ref agora::rtc::IRtcEngine::enableVideo "enableVideo" or
+ * \ref agora::rtc::IRtcEngine::disableVideo "disableVideo" method.
+ *
+ * @note This callback returns invalid when the number of users in a
+ * channel exceeds 20.
+ *
+ * @param uid User ID of the remote user.
+ * @param enabled Whether the remote user enables/disables the video
+ * module:
+ * - true: Enable. The remote user can enter a video session.
+ * - false: Disable. The remote user can only enter a voice session, and
+ * cannot send or receive any video stream.
+ */
+ virtual void onUserEnableVideo(uid_t uid, bool enabled) {
+ (void)uid;
+ (void)enabled;
+ }
+
+ /** Occurs when the audio device state changes.
+
+ This callback notifies the application that the system's audio device state is changed. For example, a headset is unplugged from the device.
+
+ @param deviceId Pointer to the device ID.
+ @param deviceType Device type: #MEDIA_DEVICE_TYPE.
+ @param deviceState Device state: #MEDIA_DEVICE_STATE_TYPE.
+ */
+ virtual void onAudioDeviceStateChanged(const char* deviceId, int deviceType, int deviceState) {
+ (void)deviceId;
+ (void)deviceType;
+ (void)deviceState;
+ }
+
+ /** Occurs when the volume of the playback device, microphone, or application changes.
+
+ @param deviceType Device type: #MEDIA_DEVICE_TYPE.
+ @param volume Volume of the device. The value ranges between 0 and 255.
+ @param muted
+ - true: The audio device is muted.
+ - false: The audio device is not muted.
+ */
+ virtual void onAudioDeviceVolumeChanged(MEDIA_DEVICE_TYPE deviceType, int volume, bool muted) {
+ (void)deviceType;
+ (void)volume;
+ (void)muted;
+ }
+
+ /** **DEPRECATED** Occurs when the camera turns on and is ready to capture the video.
+
+ If the camera fails to turn on, fix the error reported in the \ref IRtcEngineEventHandler::onError "onError" callback.
+
+ Deprecated as of v2.4.1. Use #LOCAL_VIDEO_STREAM_STATE_CAPTURING (1) in the \ref agora::rtc::IRtcEngineEventHandler::onLocalVideoStateChanged "onLocalVideoStateChanged" callback instead.
+ */
+ virtual void onCameraReady() {}
+
+ /** Occurs when the camera focus area changes.
+
+ The SDK triggers this callback when the local user changes the camera focus position by calling the setCameraFocusPositionInPreview method.
+
+ @note This callback is for Android and iOS only.
+
+ @param x x coordinate of the changed camera focus area.
+ @param y y coordinate of the changed camera focus area.
+ @param width Width of the changed camera focus area.
+ @param height Height of the changed camera focus area.
+ */
+ virtual void onCameraFocusAreaChanged(int x, int y, int width, int height) {
+ (void)x;
+ (void)y;
+ (void)width;
+ (void)height;
+ }
+
+ /** Occurs when the camera exposure area changes.
+
+ The SDK triggers this callback when the local user changes the camera exposure position by calling the setCameraExposurePosition method.
+
+ @note This callback is for Android and iOS only.
+
+ @param x x coordinate of the changed camera exposure area.
+ @param y y coordinate of the changed camera exposure area.
+ @param width Width of the changed camera exposure area.
+ @param height Height of the changed camera exposure area.
+ */
+ virtual void onCameraExposureAreaChanged(int x, int y, int width, int height) {
+ (void)x;
+ (void)y;
+ (void)width;
+ (void)height;
+ }
+
+ /** Occurs when the audio mixing file playback finishes.
+
+ **DEPRECATED** use onAudioMixingStateChanged instead.
+
+ You can start an audio mixing file playback by calling the \ref IRtcEngine::startAudioMixing "startAudioMixing" method. The SDK triggers this callback when the audio mixing file playback finishes.
+
+ If the *startAudioMixing* method call fails, an error code returns in the \ref IRtcEngineEventHandler::onError "onError" callback.
+
+ */
+ virtual void onAudioMixingFinished() {
+ }
+
+ /** Occurs when the state of the local user's audio mixing file changes.
+
+ - When the audio mixing file plays, pauses playing, or stops playing, this callback returns 710, 711, or 713 in @p state, and 0 in @p errorCode.
+ - When exceptions occur during playback, this callback returns 714 in @p state and an error in @p errorCode.
+ - If the local audio mixing file does not exist, or if the SDK does not support the file format or cannot access the music file URL, the SDK returns WARN_AUDIO_MIXING_OPEN_ERROR = 701.
+
+ @param state The state code. See #AUDIO_MIXING_STATE_TYPE.
+ @param errorCode The error code. See #AUDIO_MIXING_ERROR_TYPE.
+ */
+ virtual void onAudioMixingStateChanged(AUDIO_MIXING_STATE_TYPE state, AUDIO_MIXING_ERROR_TYPE errorCode){
+ }
+ /** Occurs when a remote user starts audio mixing.
+
+ When a remote user calls \ref IRtcEngine::startAudioMixing "startAudioMixing" to play the background music, the SDK reports this callback.
+ */
+ virtual void onRemoteAudioMixingBegin() {
+ }
+ /** Occurs when a remote user finishes audio mixing.
+ */
+ virtual void onRemoteAudioMixingEnd() {
+ }
+
+ /** Occurs when the local audio effect playback finishes.
+
+ The SDK triggers this callback when the local audio effect file playback finishes.
+
+ @param soundId ID of the local audio effect. Each local audio effect has a unique ID.
+ */
+ virtual void onAudioEffectFinished(int soundId) {
+ }
+
+
+ /**
+ Occurs when the SDK decodes the first remote audio frame for playback.
+
+ This callback is triggered in either of the following scenarios:
+
+ - The remote user joins the channel and sends the audio stream.
+ - The remote user stops sending the audio stream and re-sends it after 15 seconds. Reasons for such an interruption include:
+ - The remote user leaves channel.
+ - The remote user drops offline.
+ - The remote user calls the \ref agora::rtc::IRtcEngine::muteLocalAudioStream "muteLocalAudioStream" method to stop sending the local audio stream.
+ - The remote user calls the \ref agora::rtc::IRtcEngine::disableAudio "disableAudio" method to disable audio.
+
+ @param uid User ID of the remote user sending the audio stream.
+ @param elapsed Time elapsed (ms) from the local user calling the \ref IRtcEngine::joinChannel "joinChannel" method until the SDK triggers this callback.
+ */
+ virtual void onFirstRemoteAudioDecoded(uid_t uid, int elapsed) {
+ (void)uid;
+ (void)elapsed;
+ }
+
+ /** Occurs when the video device state changes.
+
+ @note On a Windows device with an external camera for video capturing, the video disables once the external camera is unplugged.
+
+ @param deviceId Pointer to the device ID of the video device that changes state.
+ @param deviceType Device type: #MEDIA_DEVICE_TYPE.
+ @param deviceState Device state: #MEDIA_DEVICE_STATE_TYPE.
+ */
+ virtual void onVideoDeviceStateChanged(const char* deviceId, int deviceType, int deviceState) {
+ (void)deviceId;
+ (void)deviceType;
+ (void)deviceState;
+ }
+
+ /** Occurs when the local video stream state changes.
+
+ This callback indicates the state of the local video stream, including camera capturing and video encoding, and allows you to troubleshoot issues when exceptions occur.
+
+ @note For some device models, the SDK will not trigger this callback when the state of the local video changes while the local video capturing device is in use, so you have to make your own timeout judgment.
+
+ @param localVideoState State type #LOCAL_VIDEO_STREAM_STATE. When the state is LOCAL_VIDEO_STREAM_STATE_FAILED (3), see the `error` parameter for details.
+ @param error The detailed error information: #LOCAL_VIDEO_STREAM_ERROR.
+ */
+ virtual void onLocalVideoStateChanged(LOCAL_VIDEO_STREAM_STATE localVideoState, LOCAL_VIDEO_STREAM_ERROR error) {
+ (void)localVideoState;
+ (void)error;
+ }
+
+ /** Occurs when the video size or rotation of a specified user changes.
+
+ @param uid User ID of the remote user or local user (0) whose video size or rotation changes.
+ @param width New width (pixels) of the video.
+ @param height New height (pixels) of the video.
+ @param rotation New rotation of the video [0 to 360).
+ */
+ virtual void onVideoSizeChanged(uid_t uid, int width, int height, int rotation) {
+ (void)uid;
+ (void)width;
+ (void)height;
+ (void)rotation;
+ }
+ /** Occurs when the remote video state changes.
+ *
+ * @param uid ID of the remote user whose video state changes.
+ * @param state State of the remote video. See #REMOTE_VIDEO_STATE.
+ * @param reason The reason of the remote video state change. See
+ * #REMOTE_VIDEO_STATE_REASON.
+ * @param elapsed Time elapsed (ms) from the local user calling the
+ * \ref agora::rtc::IRtcEngine::joinChannel "joinChannel" method until the
+ * SDK triggers this callback.
+ */
+ virtual void onRemoteVideoStateChanged(uid_t uid, REMOTE_VIDEO_STATE state, REMOTE_VIDEO_STATE_REASON reason, int elapsed) {
+ (void)uid;
+ (void)state;
+ (void)reason;
+ (void)elapsed;
+ }
+
+ /** Occurs when a specified remote user enables/disables the local video
+ * capturing function.
+ *
+ * @deprecated
+ * This callback is deprecated and replaced by the
+ * \ref onRemoteVideoStateChanged() "onRemoteVideoStateChanged" callback
+ * with the following parameters:
+ * - #REMOTE_VIDEO_STATE_STOPPED (0) and
+ * #REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED (5).
+ * - #REMOTE_VIDEO_STATE_DECODING (2) and
+ * #REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED (6).
+ *
+ * This callback is only applicable to the scenario when the user only
+ * wants to watch the remote video without sending any video stream to the
+ * other user.
+ *
+ * The SDK triggers this callback when the remote user resumes or stops
+ * capturing the video stream by calling the
+ * \ref agora::rtc::IRtcEngine::enableLocalVideo "enableLocalVideo" method.
+ *
+ * @param uid User ID of the remote user.
+ * @param enabled Whether the specified remote user enables/disables the
+ * local video capturing function:
+ * - true: Enable. Other users in the channel can see the video of this
+ * remote user.
+ * - false: Disable. Other users in the channel can no longer receive the
+ * video stream from this remote user, while this remote user can still
+ * receive the video streams from other users.
+ */
+ virtual void onUserEnableLocalVideo(uid_t uid, bool enabled) {
+ (void)uid;
+ (void)enabled;
+ }
+
+// virtual void onStreamError(int streamId, int code, int parameter, const char* message, size_t length) {}
+ /** Occurs when the local user receives the data stream from the remote user within five seconds.
+
+ The SDK triggers this callback when the local user receives the stream message that the remote user sends by calling the \ref agora::rtc::IRtcEngine::sendStreamMessage "sendStreamMessage" method.
+ @param uid User ID of the remote user sending the message.
+ @param streamId Stream ID.
+ @param data Pointer to the data received by the local user.
+ @param length Length of the data in bytes.
+ */
+ virtual void onStreamMessage(uid_t uid, int streamId, const char* data, size_t length) {
+ (void)uid;
+ (void)streamId;
+ (void)data;
+ (void)length;
+ }
+
+ /** Occurs when the local user does not receive the data stream from the remote user within five seconds.
+
+ The SDK triggers this callback when the local user fails to receive the stream message that the remote user sends by calling the \ref agora::rtc::IRtcEngine::sendStreamMessage "sendStreamMessage" method.
+ @param uid User ID of the remote user sending the message.
+ @param streamId Stream ID.
+ @param code Error code: #ERROR_CODE_TYPE.
+ @param missed Number of lost messages.
+ @param cached Number of incoming cached messages when the data stream is interrupted.
+ */
+ virtual void onStreamMessageError(uid_t uid, int streamId, int code, int missed, int cached) {
+ (void)uid;
+ (void)streamId;
+ (void)code;
+ (void)missed;
+ (void)cached;
+ }
+
+ /** Occurs when the media engine loads.*/
+ virtual void onMediaEngineLoadSuccess() {
+ }
+ /** Occurs when the media engine call starts.*/
+ virtual void onMediaEngineStartCallSuccess() {
+ }
+
+ /** Occurs when the state of the media stream relay changes.
+ *
+ * The SDK returns the state of the current media relay with any error
+ * message.
+ *
+ * @param state The state code in #CHANNEL_MEDIA_RELAY_STATE.
+ * @param code The error code in #CHANNEL_MEDIA_RELAY_ERROR.
+ */
+ virtual void onChannelMediaRelayStateChanged(CHANNEL_MEDIA_RELAY_STATE state,CHANNEL_MEDIA_RELAY_ERROR code) {
+ }
+
+ /** Reports events during the media stream relay.
+ *
+ * @param code The event code in #CHANNEL_MEDIA_RELAY_EVENT.
+ */
+ virtual void onChannelMediaRelayEvent(CHANNEL_MEDIA_RELAY_EVENT code) {
+ }
+
+ /** Occurs when the engine sends the first local audio frame.
+
+ @param elapsed Time elapsed (ms) from the local user calling \ref IRtcEngine::joinChannel "joinChannel" until the SDK triggers this callback.
+ */
+ virtual void onFirstLocalAudioFrame(int elapsed) {
+ (void)elapsed;
+ }
+
+ /** Occurs when the engine receives the first audio frame from a specific remote user.
+
+ @param uid User ID of the remote user.
+ @param elapsed Time elapsed (ms) from the remote user calling \ref IRtcEngine::joinChannel "joinChannel" until the SDK triggers this callback.
+ */
+ virtual void onFirstRemoteAudioFrame(uid_t uid, int elapsed) {
+ (void)uid;
+ (void)elapsed;
+ }
+
+ /**
+ Occurs when the state of the RTMP streaming changes.
+
+ The SDK triggers this callback to report the result of the local user calling the \ref agora::rtc::IRtcEngine::addPublishStreamUrl "addPublishStreamUrl" or \ref agora::rtc::IRtcEngine::removePublishStreamUrl "removePublishStreamUrl" method.
+
+ This callback indicates the state of the RTMP streaming. When exceptions occur, you can troubleshoot issues by referring to the detailed error descriptions in the *errCode* parameter.
+
+ @param url The RTMP URL address.
+ @param state The RTMP streaming state. See: #RTMP_STREAM_PUBLISH_STATE.
+ @param errCode The detailed error information for streaming. See: #RTMP_STREAM_PUBLISH_ERROR.
+ */
+ virtual void onRtmpStreamingStateChanged(const char *url, RTMP_STREAM_PUBLISH_STATE state, RTMP_STREAM_PUBLISH_ERROR errCode) {
+ (void) url;
+ (void) state;
+ (void) errCode;
+ }
+
+ /** Reports the result of calling the \ref IRtcEngine::addPublishStreamUrl "addPublishStreamUrl" method. (CDN live only.)
+
+ @param url The RTMP URL address.
+ @param error Error code: #ERROR_CODE_TYPE. Main errors include:
+ - #ERR_OK (0): The publishing succeeds.
+ - #ERR_FAILED (1): The publishing fails.
+ - #ERR_INVALID_ARGUMENT (2): Invalid argument used. If, for example, you did not call \ref agora::rtc::IRtcEngine::setLiveTranscoding "setLiveTranscoding" to configure LiveTranscoding before calling \ref agora::rtc::IRtcEngine::addPublishStreamUrl "addPublishStreamUrl", the SDK reports #ERR_INVALID_ARGUMENT.
+ - #ERR_TIMEDOUT (10): The publishing timed out.
+ - #ERR_ALREADY_IN_USE (19): The chosen URL address is already in use for CDN live streaming.
+ - #ERR_RESOURCE_LIMITED (22): The backend system does not have enough resources for the CDN live streaming.
+ - #ERR_ENCRYPTED_STREAM_NOT_ALLOWED_PUBLISH (130): You cannot publish an encrypted stream.
+ - #ERR_PUBLISH_STREAM_CDN_ERROR (151)
+ - #ERR_PUBLISH_STREAM_NUM_REACH_LIMIT (152)
+ - #ERR_PUBLISH_STREAM_NOT_AUTHORIZED (153)
+ - #ERR_PUBLISH_STREAM_INTERNAL_SERVER_ERROR (154)
+ - #ERR_PUBLISH_STREAM_FORMAT_NOT_SUPPORTED (156)
+ */
+ virtual void onStreamPublished(const char *url, int error) {
+ (void)url;
+ (void)error;
+ }
+ /** Reports the result of calling the \ref agora::rtc::IRtcEngine::removePublishStreamUrl "removePublishStreamUrl" method. (CDN live only.)
+
+ This callback indicates whether you have successfully removed an RTMP stream from the CDN.
+
+ @param url The RTMP URL address.
+ */
+ virtual void onStreamUnpublished(const char *url) {
+ (void)url;
+ }
+/** Occurs when the publisher's transcoding is updated.
+ *
+ * When the `LiveTranscoding` class in the \ref agora::rtc::IRtcEngine::setLiveTranscoding "setLiveTranscoding" method updates, the SDK triggers the `onTranscodingUpdated` callback to report the update information to the local host.
+ *
+ * @note If you call the `setLiveTranscoding` method to set the LiveTranscoding class for the first time, the SDK does not trigger the `onTranscodingUpdated` callback.
+ *
+ */
+ virtual void onTranscodingUpdated() {
+ }
+ /** Occurs when a voice or video stream URL address is added to a live broadcast.
+
+ @param url Pointer to the URL address of the externally injected stream.
+ @param uid User ID.
+ @param status State of the externally injected stream: #INJECT_STREAM_STATUS.
+ */
+ virtual void onStreamInjectedStatus(const char* url, uid_t uid, int status) {
+ (void)url;
+ (void)uid;
+ (void)status;
+ }
+
+ /** Occurs when the local audio route changes.
+
+ The SDK triggers this callback when the local audio route switches to an earpiece, speakerphone, headset, or Bluetooth device.
+
+ @note This callback is for Android and iOS only.
+
+ @param routing Audio output routing. See: #AUDIO_ROUTE_TYPE.
+ */
+ virtual void onAudioRouteChanged(AUDIO_ROUTE_TYPE routing) {
+ (void)routing;
+ }
+
+ /** Occurs when the locally published media stream falls back to an audio-only stream due to poor network conditions or switches back to the video after the network conditions improve.
+
+ If you call \ref IRtcEngine::setLocalPublishFallbackOption "setLocalPublishFallbackOption" and set *option* as #STREAM_FALLBACK_OPTION_AUDIO_ONLY, the SDK triggers this callback when the locally published stream falls back to audio-only mode due to poor uplink conditions, or when the audio stream switches back to the video after the uplink network condition improves.
+
+ @param isFallbackOrRecover Whether the locally published stream falls back to audio-only or switches back to the video:
+ - true: The locally published stream falls back to audio-only due to poor network conditions.
+ - false: The locally published stream switches back to the video after the network conditions improve.
+ */
+ virtual void onLocalPublishFallbackToAudioOnly(bool isFallbackOrRecover) {
+ (void)isFallbackOrRecover;
+ }
+
+ /** Occurs when the remote media stream falls back to audio-only stream
+ * due to poor network conditions or switches back to the video stream
+ * after the network conditions improve.
+ *
+ * If you call
+ * \ref IRtcEngine::setRemoteSubscribeFallbackOption
+ * "setRemoteSubscribeFallbackOption" and set
+ * @p option as #STREAM_FALLBACK_OPTION_AUDIO_ONLY, the SDK triggers this
+ * callback when the remote media stream falls back to audio-only mode due
+ * to poor uplink conditions, or when the remote media stream switches
+ * back to the video after the uplink network condition improves.
+ *
+ * @note Once the remote media stream switches to the low stream due to
+ * poor network conditions, you can monitor the stream switch between a
+ * high and low stream in the RemoteVideoStats callback.
+ *
+ * @param uid ID of the remote user sending the stream.
+ * @param isFallbackOrRecover Whether the remotely subscribed media stream
+ * falls back to audio-only or switches back to the video:
+ * - true: The remotely subscribed media stream falls back to audio-only
+ * due to poor network conditions.
+ * - false: The remotely subscribed media stream switches back to the
+ * video stream after the network conditions improved.
+ */
+ virtual void onRemoteSubscribeFallbackToAudioOnly(uid_t uid, bool isFallbackOrRecover) {
+ (void)uid;
+ (void)isFallbackOrRecover;
+ }
+
+ /** Reports the transport-layer statistics of each remote audio stream.
+ *
+ * @deprecated
+ * This callback is deprecated and replaced by the
+ * \ref onRemoteAudioStats() "onRemoteAudioStats" callback.
+ *
+ * This callback reports the transport-layer statistics, such as the
+ * packet loss rate and network time delay, once every two seconds after
+ * the local user receives an audio packet from a remote user.
+ *
+ * @param uid User ID of the remote user sending the audio packet.
+ * @param delay Network time delay (ms) from the remote user sending the
+ * audio packet to the local user.
+ * @param lost Packet loss rate (%) of the audio packet sent from the
+ * remote user.
+ * @param rxKBitRate Received bitrate (Kbps) of the audio packet sent
+ * from the remote user.
+ */
+ virtual void onRemoteAudioTransportStats(
+ uid_t uid, unsigned short delay, unsigned short lost,
+ unsigned short rxKBitRate) {
+ (void)uid;
+ (void)delay;
+ (void)lost;
+ (void)rxKBitRate;
+ }
+
+ /** Reports the transport-layer statistics of each remote video stream.
+ *
+ * @deprecated
+ * This callback is deprecated and replaced by the
+ * \ref onRemoteVideoStats() "onRemoteVideoStats" callback.
+ *
+ * This callback reports the transport-layer statistics, such as the
+ * packet loss rate and network time delay, once every two seconds after
+ * the local user receives a video packet from a remote user.
+ *
+ * @param uid User ID of the remote user sending the video packet.
+ * @param delay Network time delay (ms) from the remote user sending the
+ * video packet to the local user.
+ * @param lost Packet loss rate (%) of the video packet sent from the
+ * remote user.
+ * @param rxKBitRate Received bitrate (Kbps) of the video packet sent
+ * from the remote user.
+ */
+ virtual void onRemoteVideoTransportStats(
+ uid_t uid, unsigned short delay, unsigned short lost,
+ unsigned short rxKBitRate) {
+ (void)uid;
+ (void)delay;
+ (void)lost;
+ (void)rxKBitRate;
+ }
+
+ /** **DEPRECATED** Occurs when the microphone is enabled/disabled.
+ *
+ * The \ref onMicrophoneEnabled() "onMicrophoneEnabled" callback is
+ * deprecated. Use #LOCAL_AUDIO_STREAM_STATE_STOPPED (0) or
+ * #LOCAL_AUDIO_STREAM_STATE_RECORDING (1) in the
+ * \ref onLocalAudioStateChanged() "onLocalAudioStateChanged" callback
+ * instead.
+ *
+ * The SDK triggers this callback when the local user resumes or stops
+ * capturing the local audio stream by calling the
+ * \ref agora::rtc::IRtcEngine::enableLocalAudio "enbaleLocalAudio" method.
+ *
+ * @param enabled Whether the microphone is enabled/disabled:
+ * - true: Enabled.
+ * - false: Disabled.
+ */
+ virtual void onMicrophoneEnabled(bool enabled) {
+ (void)enabled;
+ }
+ /** Occurs when the connection state between the SDK and the server changes.
+
+ @param state See #CONNECTION_STATE_TYPE.
+ @param reason See #CONNECTION_CHANGED_REASON_TYPE.
+ */
+ virtual void onConnectionStateChanged(
+ CONNECTION_STATE_TYPE state, CONNECTION_CHANGED_REASON_TYPE reason) {
+ (void)state;
+ (void)reason;
+ }
+
+ /** Occurs when the local network type changes.
+
+ When the network connection is interrupted, this callback indicates whether the interruption is caused by a network type change or poor network conditions.
+
+ @param type See #NETWORK_TYPE.
+ */
+ virtual void onNetworkTypeChanged(NETWORK_TYPE type) {
+ (void)type;
+ }
+ /** Occurs when the local user successfully registers a user account by calling the \ref agora::rtc::IRtcEngine::registerLocalUserAccount "registerLocalUserAccount" method or joins a channel by calling the \ref agora::rtc::IRtcEngine::joinChannelWithUserAccount "joinChannelWithUserAccount" method.This callback reports the user ID and user account of the local user.
+
+ @param uid The ID of the local user.
+ @param userAccount The user account of the local user.
+ */
+ virtual void onLocalUserRegistered(uid_t uid, const char* userAccount) {
+ (void)uid;
+ (void)userAccount;
+ }
+ /** Occurs when the SDK gets the user ID and user account of the remote user.
+
+ After a remote user joins the channel, the SDK gets the UID and user account of the remote user,
+ caches them in a mapping table object (`userInfo`), and triggers this callback on the local client.
+
+ @param uid The ID of the remote user.
+ @param info The `UserInfo` object that contains the user ID and user account of the remote user.
+ */
+ virtual void onUserInfoUpdated(uid_t uid, const UserInfo& info) {
+ (void)uid;
+ (void)info;
+ }
+};
+
+/**
+* Video device collection methods.
+
+ The IVideoDeviceCollection interface class retrieves the video device information.
+*/
+class IVideoDeviceCollection
+{
+protected:
+ virtual ~IVideoDeviceCollection(){}
+public:
+ /** Retrieves the total number of the indexed video devices in the system.
+
+ @return Total number of the indexed video devices:
+ */
+ virtual int getCount() = 0;
+
+ /** Retrieves a specified piece of information about an indexed video device.
+
+ @param index The specified index of the video device that must be less than the return value of \ref IVideoDeviceCollection::getCount "getCount".
+ @param deviceName Pointer to the video device name.
+ @param deviceId Pointer to the video device ID.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getDevice(int index, char deviceName[MAX_DEVICE_ID_LENGTH], char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
+
+ /** Sets the device with the device ID.
+
+ @param deviceId Device ID of the device.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setDevice(const char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
+
+ /** Releases all IVideoDeviceCollection resources.
+ */
+ virtual void release() = 0;
+};
+
+/** Video device management methods.
+
+ The IVideoDeviceManager interface class tests the video device interfaces. Instantiate an AVideoDeviceManager class to retrieve an IVideoDeviceManager interface.
+*/
+class IVideoDeviceManager
+{
+protected:
+ virtual ~IVideoDeviceManager(){}
+public:
+
+ /** Enumerates the video devices.
+
+ This method returns an IVideoDeviceCollection object including all video devices in the system. With the IVideoDeviceCollection object, the application can enumerate the video devices. The application must call the \ref IVideoDeviceCollection::release "release" method to release the returned object after using it.
+
+ @return
+ - An IVideoDeviceCollection object including all video devices in the system: Success.
+ - NULL: Failure.
+ */
+ virtual IVideoDeviceCollection* enumerateVideoDevices() = 0;
+
+ /** Starts the video-capture device test.
+
+ This method tests whether the video-capture device works properly. Before calling this method, ensure that you have already called the \ref IRtcEngine::enableVideo "enableVideo" method, and the window handle (*hwnd*) parameter is valid.
+
+ @param hwnd The window handle used to display the screen.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int startDeviceTest(view_t hwnd) = 0;
+
+ /** Stops the video-capture device test.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int stopDeviceTest() = 0;
+
+ /** Sets a device with the device ID.
+
+ @param deviceId Pointer to the video-capture device ID. Call the \ref IVideoDeviceManager::enumerateVideoDevices "enumerateVideoDevices" method to retrieve it.
+
+ @note Plugging or unplugging the device does not change the device ID.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setDevice(const char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
+
+ /** Retrieves the video-capture device that is in use.
+
+ @param deviceId Pointer to the video-capture device ID.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getDevice(char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
+
+ /** Releases all IVideoDeviceManager resources.
+ */
+ virtual void release() = 0;
+};
+
+/** Audio device collection methods.
+
+The IAudioDeviceCollection interface class retrieves device-related information.
+*/
+class IAudioDeviceCollection
+{
+protected:
+ virtual ~IAudioDeviceCollection(){}
+public:
+
+ /** Retrieves the total number of audio playback or audio recording devices.
+
+ @note You must first call the \ref IAudioDeviceManager::enumeratePlaybackDevices "enumeratePlaybackDevices" or \ref IAudioDeviceManager::enumerateRecordingDevices "enumerateRecordingDevices" method before calling this method to return the number of audio playback or audio recording devices.
+
+ @return Number of audio playback or audio recording devices.
+ */
+ virtual int getCount() = 0;
+
+ /** Retrieves a specified piece of information about an indexed audio device.
+
+ @param index The specified index that must be less than the return value of \ref IAudioDeviceCollection::getCount "getCount".
+ @param deviceName Pointer to the audio device name.
+ @param deviceId Pointer to the audio device ID.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getDevice(int index, char deviceName[MAX_DEVICE_ID_LENGTH], char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
+
+ /** Specifies a device with the device ID.
+
+ @param deviceId Pointer to the device ID of the device.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setDevice(const char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
+
+ /** Sets the volume of the application.
+
+ @param volume Application volume. The value ranges between 0 (lowest volume) and 255 (highest volume).
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setApplicationVolume(int volume) = 0;
+
+ /** Retrieves the volume of the application.
+
+ @param volume Pointer to the application volume. The volume value ranges between 0 (lowest volume) and 255 (highest volume).
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getApplicationVolume(int& volume) = 0;
+
+ /** Mutes the application.
+
+ @param mute Sets whether to mute/unmute the application:
+ - true: Mute the application.
+ - false: Unmute the application.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setApplicationMute(bool mute) = 0;
+ /** Gets the mute state of the application.
+
+ @param mute Pointer to whether the application is muted/unmuted.
+ - true: The application is muted.
+ - false: The application is not muted.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int isApplicationMute(bool& mute) = 0;
+
+ /** Releases all IAudioDeviceCollection resources.
+ */
+ virtual void release() = 0;
+};
+/** Audio device management methods.
+
+ The IAudioDeviceManager interface class allows for audio device interface testing. Instantiate an AAudioDeviceManager class to retrieve the IAudioDeviceManager interface.
+*/
+class IAudioDeviceManager
+{
+protected:
+ virtual ~IAudioDeviceManager(){}
+public:
+
+ /** Enumerates the audio playback devices.
+
+ This method returns an IAudioDeviceCollection object that includes all audio playback devices in the system. With the IAudioDeviceCollection object, the application can enumerate the audio playback devices.
+
+ @note The application must call the \ref IAudioDeviceCollection::release "release" method to release the returned object after using it.
+
+ @return
+ - Success: Returns an IAudioDeviceCollection object that includes all audio playback devices in the system. For wireless Bluetooth headset devices with master and slave headsets, the master headset is the playback device.
+ - Returns NULL: Failure.
+ */
+ virtual IAudioDeviceCollection* enumeratePlaybackDevices() = 0;
+
+ /** Enumerates the audio recording devices.
+
+ This method returns an IAudioDeviceCollection object that includes all audio recording devices in the system. With the IAudioDeviceCollection object, the application can enumerate the audio recording devices.
+
+ @note The application needs to call the \ref IAudioDeviceCollection::release "release" method to release the returned object after using it.
+
+ @return
+ - Returns an IAudioDeviceCollection object that includes all audio recording devices in the system: Success.
+ - Returns NULL: Failure.
+ */
+ virtual IAudioDeviceCollection* enumerateRecordingDevices() = 0;
+
+ /** Sets the audio playback device using the device ID.
+
+ @note Plugging or unplugging the audio device does not change the device ID.
+
+ @param deviceId Device ID of the audio playback device, retrieved by calling the \ref IAudioDeviceManager::enumeratePlaybackDevices "enumeratePlaybackDevices" method.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setPlaybackDevice(const char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
+
+ /** Sets the audio recording device using the device ID.
+
+ @param deviceId Device ID of the audio recording device, retrieved by calling the \ref IAudioDeviceManager::enumerateRecordingDevices "enumerateRecordingDevices" method.
+
+ @note Plugging or unplugging the audio device does not change the device ID.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRecordingDevice(const char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
+
+ /** Starts the audio playback device test.
+
+ This method tests if the playback device works properly. In the test, the SDK plays an audio file specified by the user. If the user can hear the audio, the playback device works properly.
+
+ @param testAudioFilePath Pointer to the path of the audio file for the audio playback device test in UTF-8:
+ - Supported file formats: wav, mp3, m4a, and aac.
+ - Supported file sample rates: 8000, 16000, 32000, 44100, and 48000 Hz.
+
+ @return
+ - 0: Success, and you can hear the sound of the specified audio file.
+ - < 0: Failure.
+ */
+ virtual int startPlaybackDeviceTest(const char* testAudioFilePath) = 0;
+
+ /** Stops the audio playback device test.
+
+ This method stops testing the audio playback device. You must call this method to stop the test after calling the \ref IAudioDeviceManager::startPlaybackDeviceTest "startPlaybackDeviceTest" method.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int stopPlaybackDeviceTest() = 0;
+
+ /** Sets the volume of the audio playback device.
+
+ @param volume Sets the volume of the audio playback device. The value ranges between 0 (lowest volume) and 255 (highest volume).
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setPlaybackDeviceVolume(int volume) = 0;
+
+ /** Retrieves the volume of the audio playback device.
+
+ @param volume Pointer to the audio playback device volume. The volume value ranges between 0 (lowest volume) and 255 (highest volume).
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getPlaybackDeviceVolume(int *volume) = 0;
+
+ /** Sets the volume of the microphone.
+
+ @param volume Sets the volume of the microphone. The value ranges between 0 (lowest volume) and 255 (highest volume).
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRecordingDeviceVolume(int volume) = 0;
+
+ /** Retrieves the volume of the microphone.
+
+ @param volume Pointer to the microphone volume. The volume value ranges between 0 (lowest volume) and 255 (highest volume).
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getRecordingDeviceVolume(int *volume) = 0;
+
+ /** Mutes the audio playback device.
+
+ @param mute Sets whether to mute/unmute the audio playback device:
+ - true: Mutes.
+ - false: Unmutes.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setPlaybackDeviceMute(bool mute) = 0;
+ /** Retrieves the mute status of the audio playback device.
+
+ @param mute Pointer to whether the audio playback device is muted/unmuted.
+ - true: Muted.
+ - false: Unmuted.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getPlaybackDeviceMute(bool *mute) = 0;
+ /** Mutes/Unmutes the microphone.
+
+ @param mute Sets whether to mute/unmute the microphone:
+ - true: Mutes.
+ - false: Unmutes.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRecordingDeviceMute(bool mute) = 0;
+
+ /** Retrieves the microphone's mute status.
+
+ @param mute Pointer to whether the microphone is muted/unmuted.
+ - true: Muted.
+ - false: Unmuted.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getRecordingDeviceMute(bool *mute) = 0;
+
+ /** Starts the microphone test.
+
+ This method tests whether the microphone works properly. Once the test starts, the SDK uses the \ref IRtcEngineEventHandler::onAudioVolumeIndication "onAudioVolumeIndication" callback to notify the application with the volume information.
+
+ @param indicationInterval Interval period (ms) of the \ref IRtcEngineEventHandler::onAudioVolumeIndication "onAudioVolumeIndication" callback cycle.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int startRecordingDeviceTest(int indicationInterval) = 0;
+
+ /** Stops the microphone test.
+
+ This method stops the microphone test. You must call this method to stop the test after calling the \ref IAudioDeviceManager::startRecordingDeviceTest "startRecordingDeviceTest" method.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int stopRecordingDeviceTest() = 0;
+
+ /** Retrieves the audio playback device associated with the device ID.
+
+ @param deviceId Pointer to the ID of the audio playback device.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getPlaybackDevice(char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
+
+ /** Retrieves the audio playback device information associated with the device ID and device name.
+
+ @param deviceId Pointer to the device ID of the audio playback device.
+ @param deviceName Pointer to the device name of the audio playback device.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getPlaybackDeviceInfo(char deviceId[MAX_DEVICE_ID_LENGTH], char deviceName[MAX_DEVICE_ID_LENGTH]) = 0;
+
+ /** Retrieves the audio recording device associated with the device ID.
+
+ @param deviceId Pointer to the device ID of the audio recording device.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getRecordingDevice(char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
+
+ /** Retrieves the audio recording device information associated with the device ID and device name.
+
+ @param deviceId Pointer to the device ID of the recording audio device.
+ @param deviceName Pointer to the device name of the recording audio device.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getRecordingDeviceInfo(char deviceId[MAX_DEVICE_ID_LENGTH], char deviceName[MAX_DEVICE_ID_LENGTH]) = 0;
+
+ /** Starts the audio device loopback test.
+
+ This method tests whether the local audio devices are working properly. After calling this method, the microphone captures the local audio and plays it through the speaker. The \ref IRtcEngineEventHandler::onAudioVolumeIndication "onAudioVolumeIndication" callback returns the local audio volume information at the set interval.
+
+ @note This method tests the local audio devices and does not report the network conditions.
+
+ @param indicationInterval The time interval (ms) at which the \ref IRtcEngineEventHandler::onAudioVolumeIndication "onAudioVolumeIndication" callback returns.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int startAudioDeviceLoopbackTest(int indicationInterval) = 0;
+
+ /** Stops the audio device loopback test.
+
+ @note Ensure that you call this method to stop the loopback test after calling the \ref IAudioDeviceManager::startAudioDeviceLoopbackTest "startAudioDeviceLoopbackTest" method.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int stopAudioDeviceLoopbackTest() = 0;
+
+ /** Releases all IAudioDeviceManager resources.
+ */
+ virtual void release() = 0;
+};
+
+/** Definition of RtcEngineContext.
+*/
+struct RtcEngineContext
+{
+ /** The IRtcEngineEventHandler object.
+ */
+ IRtcEngineEventHandler* eventHandler;
+ /** App ID issued to you by Agora. Apply for a new App ID from Agora if
+ * it is missing from your kit.
+ */
+ const char* appId;
+ // For android, it the context(Activity or Application
+ // for windows,Video hot plug device
+ /** The video window handle. Once set, this parameter enables you to plug
+ * or unplug the video devices while they are powered.
+ */
+ void* context;
+ RtcEngineContext()
+ :eventHandler(NULL)
+ ,appId(NULL)
+ ,context(NULL)
+ {}
+};
+
+/** Definition of IMetadataObserver
+*/
+class IMetadataObserver
+{
+public:
+ /** Metadata type of the observer.
+ @note We only support video metadata for now.
+ */
+ enum METADATA_TYPE
+ {
+ /** -1: the metadata type is unknown.
+ */
+ UNKNOWN_METADATA = -1,
+ /** 0: the metadata type is video.
+ */
+ VIDEO_METADATA = 0,
+ };
+
+ struct Metadata
+ {
+ /** The User ID.
+
+ - For the receiver: the ID of the user who sent the metadata.
+ - For the sender: ignore it.
+ */
+ unsigned int uid;
+ /** Buffer size of the sent or received Metadata.
+ */
+ unsigned int size;
+ /** Buffer address of the sent or received Metadata.
+ */
+ unsigned char *buffer;
+ /** Time statmp of the frame following the metadata.
+ */
+ long long timeStampMs;
+ };
+
+ virtual ~IMetadataObserver() {};
+
+ /** Occurs when the SDK requests the maximum size of the Metadata.
+
+ The metadata includes the following parameters:
+ - `uid`: ID of the user who sends the metadata.
+ - `size`: The size of the sent or received metadata.
+ - `buffer`: The sent or received metadata.
+ - `timeStampMs`: The timestamp of the metadata.
+
+ The SDK triggers this callback after you successfully call the \ref agora::rtc::IRtcEngine::registerMediaMetadataObserver "registerMediaMetadataObserver" method. You need to specify the maximum size of the metadata in the return value of this callback.
+
+ @return The maximum size of the buffer of the metadata that you want to use. The highest value is 1024 bytes. Ensure that you set the return value.
+ */
+ virtual int getMaxMetadataSize() = 0;
+
+ /** Occurs when the SDK is ready to receive and send metadata.
+
+ @note Ensure that the size of the metadata does not exceed the value set in the \ref agora::rtc::IMetadataObserver::getMaxMetadataSize "getMaxMetadataSize" callback.
+
+ @param metadata The Metadata to be sent.
+ @return
+ - true: Send.
+ - false: Do not send.
+ */
+ virtual bool onReadyToSendMetadata(Metadata &metadata) = 0;
+
+ /** Occurs when the local user receives the metadata.
+
+ @param metadata The received Metadata.
+ */
+ virtual void onMetadataReceived(const Metadata &metadata) = 0;
+};
+
+/** IRtcEngine is the base interface class of the Agora SDK that provides the main Agora SDK methods invoked by your application.
+
+Enable the Agora SDK's communication functionality through the creation of an IRtcEngine object, then call the methods of this object.
+ */
+class IRtcEngine
+{
+protected:
+ virtual ~IRtcEngine() {}
+public:
+
+ /** Initializes the Agora service.
+ *
+ * Ensure that you call the
+ * \ref agora::rtc::IRtcEngine::createAgoraRtcEngine
+ * "createAgoraRtcEngine" and \ref agora::rtc::IRtcEngine::initialize
+ * "initialize" methods before calling any other API.
+ *
+ * @param context Pointer to the RTC engine context. See RtcEngineContext.
+ *
+ * @return
+ * - 0: Success.
+ * - < 0: Failure.
+ * - `ERR_INVALID_APP_ID (101)`: The app ID is invalid. Check if it is in the correct format.
+ */
+ virtual int initialize(const RtcEngineContext& context) = 0;
+
+ /** Releases all IRtcEngine resources.
+
+ @param sync
+ - true: (Synchronous call) The result returns after the IRtcEngine resources are released. The application should not call this method in the SDK generated callbacks. Otherwise, the SDK must wait for the callbacks to return to recover the associated IRtcEngine resources, resulting in a deadlock. The SDK automatically detects the deadlock and converts this method into an asynchronous call, causing the test to take additional time.
+ - false: (Asynchronous call) The result returns immediately, even when the IRtcEngine resources have not been released. The SDK releases all resources.
+
+ @note Do not immediately uninstall the SDK's dynamic library after the call, or it may cause a crash due to the SDK clean-up thread not quitting.
+ */
+ virtual void release(bool sync=false) = 0;
+
+ /** Sets the channel profile of the Agora RtcEngine.
+
+ The Agora RtcEngine differentiates channel profiles and applies optimization algorithms accordingly.
+ For example, it prioritizes smoothness and low latency for a video call, and prioritizes video quality for a video broadcast.
+
+ @note
+ - To ensure the quality of real-time communication, we recommend that all users in a channel use the same channel profile.
+ - Call this method before calling \ref IRtcEngine::joinChannel "joinChannel" . You cannot set the channel profile once you have joined the channel.
+
+ @param profile The channel profile of the Agora RtcEngine. See #CHANNEL_PROFILE_TYPE
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setChannelProfile(CHANNEL_PROFILE_TYPE profile) = 0;
+
+ /** Sets the role of the user, such as a host or an audience (default), before joining a channel in a live broadcast.
+
+ This method can be used to switch the user role in a live broadcast after the user joins a channel.
+
+ In the Live Broadcast profile, when a user switches user roles after joining a channel, a successful \ref agora::rtc::IRtcEngine::setClientRole "setClientRole" method call triggers the following callbacks:
+ - The local client: \ref agora::rtc::IRtcEngineEventHandler::onClientRoleChanged "onClientRoleChanged"
+ - The remote client: \ref agora::rtc::IRtcEngineEventHandler::onUserJoined "onUserJoined" or \ref agora::rtc::IRtcEngineEventHandler::onUserOffline "onUserOffline" (BECOME_AUDIENCE)
+
+ @note
+ This method applies only to the Live-broadcast profile.
+
+ @param role Sets the role of the user. See #CLIENT_ROLE_TYPE.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setClientRole(CLIENT_ROLE_TYPE role) = 0;
+
+ /** Joins a channel with the user ID.
+
+ Users in the same channel can talk to each other, and multiple users in the same channel can start a group chat. Users with different App IDs cannot call each other.
+
+
+ You must call the \ref IRtcEngine::leaveChannel "leaveChannel" method to exit the current call before entering another channel.
+
+ A successful \ref agora::rtc::IRtcEngine::joinChannel "joinChannel" method call triggers the following callbacks:
+ - The local client: \ref agora::rtc::IRtcEngineEventHandler::onJoinChannelSuccess "onJoinChannelSuccess"
+ - The remote client: \ref agora::rtc::IRtcEngineEventHandler::onUserJoined "onUserJoined" , if the user joining the channel is in the Communication profile, or is a BROADCASTER in the Live Broadcast profile.
+
+ When the connection between the client and Agora's server is interrupted due to poor network conditions, the SDK tries reconnecting to the server. When the local client successfully rejoins the channel, the SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onRejoinChannelSuccess "onRejoinChannelSuccess" callback on the local client.
+
+ @note A channel does not accept duplicate uids, such as two users with the same @p uid. If you set @p uid as 0, the system automatically assigns a @p uid. If you want to join a channel from different devices, ensure that each device has a different uid.
+ @warning Ensure that the App ID used for creating the token is the same App ID used by the \ref IRtcEngine::initialize "initialize" method for initializing the RTC engine. Otherwise, the CDN live streaming may fail.
+
+ @param token Pointer to the token generated by the application server. In most circumstances, a static App ID suffices. For added security, use a Channel Key.
+ - If the user uses a static App ID, *token* is optional and can be set as NULL.
+ - If the user uses a Channel Key, Agora issues an additional App Certificate for you to generate a user key based on the algorithm and App Certificate for user authentication on the server.
+ @param channelId Pointer to the unique channel name for the Agora RTC session in the string format smaller than 64 bytes. Supported characters:
+ - The 26 lowercase English letters: a to z
+ - The 26 uppercase English letters: A to Z
+ - The 10 numbers: 0 to 9
+ - The space
+ - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ","
+ @param info (Optional) Pointer to additional information about the channel. This parameter can be set to NULL or contain channel related information. Other users in the channel will not receive this message.
+ @param uid (Optional) User ID. A 32-bit unsigned integer with a value ranging from 1 to 232-1. The @p uid must be unique. If a @p uid is not assigned (or set to 0), the SDK assigns and returns a @p uid in the \ref IRtcEngineEventHandler::onJoinChannelSuccess "onJoinChannelSuccess" callback. Your application must record and maintain the returned *uid* since the SDK does not do so.
+
+ @return
+ - 0: Success.
+ - < 0: Failure:
+ - #ERR_INVALID_ARGUMENT (-2)
+ - #ERR_NOT_READY (-3)
+ - #ERR_REFUSED (-5)
+ */
+ virtual int joinChannel(const char* token, const char* channelId, const char* info, uid_t uid) = 0;
+ /** Switches to a different channel.
+ *
+ * This method allows the audience of a Live-broadcast channel to switch
+ * to a different channel.
+ *
+ * After the user successfully switches to another channel, the
+ * \ref agora::rtc::IRtcEngineEventHandler::onLeaveChannel "onLeaveChannel"
+ * and \ref agora::rtc::IRtcEngineEventHandler::onJoinChannelSuccess
+ * "onJoinChannelSuccess" callbacks are triggered to indicate that the
+ * user has left the original channel and joined a new one.
+ *
+ * @note
+ * This method applies to the audience role in a Live-broadcast channel
+ * only.
+ *
+ * @param token The token generated at your server:
+ * - For low-security requirements: You can use the temporary token
+ * generated in Console. For details, see
+ * [Get a temporary token](https://docs.agora.io/en/Agora%20Platform/token?platfor%20*%20m=All%20Platforms#get-a-temporary-token).
+ * - For high-security requirements: Use the token generated at your
+ * server. For details, see
+ * [Get a token](https://docs.agora.io/en/Agora%20Platform/token?platfor%20*%20m=All%20Platforms#get-a-token).
+ * @param channelId Unique channel name for the AgoraRTC session in the
+ * string format. The string length must be less than 64 bytes. Supported
+ * character scopes are:
+ * - The 26 lowercase English letters: a to z.
+ * - The 26 uppercase English letters: A to Z.
+ * - The 10 numbers: 0 to 9.
+ * - The space.
+ * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".",
+ * ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ - #ERR_INVALID_ARGUMENT (-2)
+ - #ERR_NOT_READY (-3)
+ - #ERR_REFUSED (-5)
+ */
+ virtual int switchChannel(const char* token, const char* channelId) = 0;
+
+ /** Allows a user to leave a channel, such as hanging up or exiting a call.
+
+ After joining a channel, the user must call the *leaveChannel* method to end the call before joining another channel.
+
+ This method returns 0 if the user leaves the channel and releases all resources related to the call.
+
+ This method call is asynchronous, and the user has not left the channel when the method call returns. Once the user leaves the channel, the SDK triggers the \ref IRtcEngineEventHandler::onLeaveChannel "onLeaveChannel" callback.
+
+ A successful \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" method call triggers the following callbacks:
+ - The local client: \ref agora::rtc::IRtcEngineEventHandler::onLeaveChannel "onLeaveChannel"
+ - The remote client: \ref agora::rtc::IRtcEngineEventHandler::onUserOffline "onUserOffline" , if the user leaving the channel is in the Communication channel, or is a BROADCASTER in the Live Broadcast profile.
+
+ @note
+ - If you call the \ref IRtcEngine::release "release" method immediately after the *leaveChannel* method, the *leaveChannel* process interrupts, and the \ref IRtcEngineEventHandler::onLeaveChannel "onLeaveChannel" callback is not triggered.
+ - If you call the *leaveChannel* method during a CDN live streaming, the SDK triggers the \ref IRtcEngine::removePublishStreamUrl "removePublishStreamUrl" method.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int leaveChannel() = 0;
+
+ /** Gets a new token when the current token expires after a period of time.
+
+ The `token` expires after a period of time once the token schema is enabled when:
+
+ - The SDK triggers the \ref IRtcEngineEventHandler::onTokenPrivilegeWillExpire "onTokenPrivilegeWillExpire" callback, or
+ - The \ref IRtcEngineEventHandler::onConnectionStateChanged "onConnectionStateChanged" reports CONNECTION_CHANGED_TOKEN_EXPIRED(9).
+
+ The application should call this method to get the new `token`. Failure to do so will result in the SDK disconnecting from the server.
+
+ @param token Pointer to the new token.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int renewToken(const char* token) = 0;
+
+ /** Retrieves the pointer to the device manager object.
+
+ @param iid ID of the interface.
+ @param inter Pointer to the *DeviceManager* object.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int queryInterface(INTERFACE_ID_TYPE iid, void** inter) = 0;
+
+ /** Registers a user account.
+
+ Once registered, the user account can be used to identify the local user when the user joins the channel.
+ After the user successfully registers a user account, the SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onLocalUserRegistered "onLocalUserRegistered" callback on the local client,
+ reporting the user ID and user account of the local user.
+
+ To join a channel with a user account, you can choose either of the following:
+
+ - Call the \ref agora::rtc::IRtcEngine::registerLocalUserAccount "registerLocalUserAccount" method to create a user account, and then the \ref agora::rtc::IRtcEngine::joinChannelWithUserAccount "joinChannelWithUserAccount" method to join the channel.
+ - Call the \ref agora::rtc::IRtcEngine::joinChannelWithUserAccount "joinChannelWithUserAccount" method to join the channel.
+
+ The difference between the two is that for the former, the time elapsed between calling the \ref agora::rtc::IRtcEngine::joinChannelWithUserAccount "joinChannelWithUserAccount" method
+ and joining the channel is shorter than the latter.
+
+ @note
+ - Ensure that you set the `userAccount` parameter. Otherwise, this method does not take effect.
+ - Ensure that the value of the `userAccount` parameter is unique in the channel.
+ - To ensure smooth communication, use the same parameter type to identify the user. For example, if a user joins the channel with a user ID, then ensure all the other users use the user ID too. The same applies to the user account. If a user joins the channel with the Agora Web SDK, ensure that the uid of the user is set to the same parameter type.
+
+ @param appId The App ID of your project.
+ @param userAccount The user account. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as null. Supported character scopes are:
+ - The 26 lowercase English letters: a to z.
+ - The 26 uppercase English letters: A to Z.
+ - The 10 numbers: 0 to 9.
+ - The space.
+ - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int registerLocalUserAccount(
+ const char* appId, const char* userAccount) = 0;
+ /** Joins the channel with a user account.
+
+ After the user successfully joins the channel, the SDK triggers the following callbacks:
+
+ - The local client: \ref agora::rtc::IRtcEngineEventHandler::onLocalUserRegistered "onLocalUserRegistered" and \ref agora::rtc::IRtcEngineEventHandler::onJoinChannelSuccess "onJoinChannelSuccess" .
+ The remote client: \ref agora::rtc::IRtcEngineEventHandler::onUserJoined "onUserJoined" and \ref agora::rtc::IRtcEngineEventHandler::onUserInfoUpdated "onUserInfoUpdated" , if the user joining the channel is in the Communication profile, or is a BROADCASTER in the Live Broadcast profile.
+
+ @note To ensure smooth communication, use the same parameter type to identify the user. For example, if a user joins the channel with a user ID, then ensure all the other users use the user ID too. The same applies to the user account.
+ If a user joins the channel with the Agora Web SDK, ensure that the uid of the user is set to the same parameter type.
+
+ @param token The token generated at your server:
+ - For low-security requirements: You can use the temporary token generated at Console. For details, see [Get a temporary toke](https://docs.agora.io/en/Voice/token?platform=All%20Platforms#get-a-temporary-token).
+ - For high-security requirements: Set it as the token generated at your server. For details, see [Get a token](https://docs.agora.io/en/Voice/token?platform=All%20Platforms#get-a-token).
+ @param channelId The channel name. The maximum length of this parameter is 64 bytes. Supported character scopes are:
+ The 26 lowercase English letters: a to z.
+ - The 26 uppercase English letters: A to Z.
+ - The 10 numbers: 0 to 9.
+ - The space.
+ - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
+ @param userAccount The user account. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as null. Supported character scopes are:
+ - The 26 lowercase English letters: a to z.
+ - The 26 uppercase English letters: A to Z.
+ - The 10 numbers: 0 to 9.
+ - The space.
+ - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ - #ERR_INVALID_ARGUMENT (-2)
+ - #ERR_NOT_READY (-3)
+ - #ERR_REFUSED (-5)
+ */
+ virtual int joinChannelWithUserAccount(const char* token,
+ const char* channelId,
+ const char* userAccount) = 0;
+
+ /** Gets the user information by passing in the user account.
+
+ After a remote user joins the channel, the SDK gets the user ID and user account of the remote user, caches them
+ in a mapping table object (`userInfo`), and triggers the \ref agora::rtc::IRtcEngineEventHandler::onUserInfoUpdated "onUserInfoUpdated" callback on the local client.
+
+ After receiving the o\ref agora::rtc::IRtcEngineEventHandler::onUserInfoUpdated "onUserInfoUpdated" callback, you can call this method to get the user ID of the
+ remote user from the `userInfo` object by passing in the user account.
+
+ @param userAccount The user account of the user. Ensure that you set this parameter.
+ @param[in/out] userInfo A userInfo object that identifies the user:
+ - Input: A userInfo object.
+ - Output: A userInfo object that contains the user account and user ID of the user.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getUserInfoByUserAccount(const char* userAccount, UserInfo* userInfo) = 0;
+ /** Gets the user information by passing in the user ID.
+
+ After a remote user joins the channel, the SDK gets the user ID and user account of the remote user,
+ caches them in a mapping table object (`userInfo`), and triggers the \ref agora::rtc::IRtcEngineEventHandler::onUserInfoUpdated "onUserInfoUpdated" callback on the local client.
+
+ After receiving the \ref agora::rtc::IRtcEngineEventHandler::onUserInfoUpdated "onUserInfoUpdated" callback, you can call this method to get the user account of the remote user
+ from the `userInfo` object by passing in the user ID.
+
+ @param uid The user ID of the remote user. Ensure that you set this parameter.
+ @param[in/out] userInfo A userInfo object that identifies the user:
+ - Input: A userInfo object.
+ - Output: A userInfo object that contains the user account and user ID of the user.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getUserInfoByUid(uid_t uid, UserInfo* userInfo) = 0;
+
+ /** **DEPRECATED** Starts an audio call test.
+
+ This method is deprecated as of v2.4.0.
+
+ This method starts an audio call test to check whether the audio devices (for example, headset and speaker) and the network connection are working properly.
+
+ To conduct the test:
+
+ - The user speaks and the recording is played back within 10 seconds.
+ - If the user can hear the recording within 10 seconds, the audio devices and network connection are working properly.
+
+ @note
+ - After calling this method, always call the \ref IRtcEngine::stopEchoTest "stopEchoTest" method to end the test. Otherwise, the application cannot run the next echo test.
+ - In the Live-broadcast profile, only the hosts can call this method. If the user switches from the Communication to Live-broadcast profile, the user must call the \ref IRtcEngine::setClientRole "setClientRole" method to change the user role from the audience (default) to the host before calling this method.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int startEchoTest() = 0;
+
+ /** Starts an audio call test.
+
+ This method starts an audio call test to determine whether the audio devices (for example, headset and speaker) and the network connection are working properly.
+
+ In the audio call test, you record your voice. If the recording plays back within the set time interval, the audio devices and the network connection are working properly.
+
+ @note
+ - Call this method before joining a channel.
+ - After calling this method, call the \ref IRtcEngine::stopEchoTest "stopEchoTest" method to end the test. Otherwise, the app cannot run the next echo test, or call the \ref IRtcEngine::joinChannel "joinChannel" method.
+ - In the Live-broadcast profile, only a host can call this method.
+ @param intervalInSeconds The time interval (s) between when you speak and when the recording plays back.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int startEchoTest(int intervalInSeconds) = 0;
+
+ /** Stops the audio call test.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int stopEchoTest() = 0;
+
+ /** Enables the video module.
+
+ Call this method either before joining a channel or during a call. If this method is called before joining a channel, the call starts in the video mode. If this method is called during an audio call, the audio mode switches to the video mode. To disable the video module, call the \ref IRtcEngine::disableVideo "disableVideo" method.
+
+ A successful \ref agora::rtc::IRtcEngine::enableVideo "enableVideo" method call triggers the \ref agora::rtc::IRtcEngineEventHandler::onUserEnableVideo "onUserEnableVideo" (true) callback on the remote client.
+ @note
+ - This method affects the internal engine and can be called after the \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" method.
+ - This method resets the internal engine and takes some time to take effect. We recommend using the following API methods to control the video engine modules separately:
+ - \ref IRtcEngine::enableLocalVideo "enableLocalVideo": Whether to enable the camera to create the local video stream.
+ - \ref IRtcEngine::muteLocalVideoStream "muteLocalVideoStream": Whether to publish the local video stream.
+ - \ref IRtcEngine::muteRemoteVideoStream "muteRemoteVideoStream": Whether to subscribe to and play the remote video stream.
+ - \ref IRtcEngine::muteAllRemoteVideoStreams "muteAllRemoteVideoStreams": Whether to subscribe to and play all remote video streams.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int enableVideo() = 0;
+
+ /** Disables the video module.
+
+ This method can be called before joining a channel or during a call. If this method is called before joining a channel, the call starts in audio mode. If this method is called during a video call, the video mode switches to the audio mode. To enable the video module, call the \ref IRtcEngine::enableVideo "enableVideo" method.
+
+ A successful \ref agora::rtc::IRtcEngine::disableVideo "disableVideo" method call triggers the \ref agora::rtc::IRtcEngineEventHandler::onUserEnableVideo "onUserEnableVideo" (false) callback on the remote client.
+ @note
+ - This method affects the internal engine and can be called after the \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" method.
+ - This method resets the internal engine and takes some time to take effect. We recommend using the following API methods to control the video engine modules separately:
+ - \ref IRtcEngine::enableLocalVideo "enableLocalVideo": Whether to enable the camera to create the local video stream.
+ - \ref IRtcEngine::muteLocalVideoStream "muteLocalVideoStream": Whether to publish the local video stream.
+ - \ref IRtcEngine::muteRemoteVideoStream "muteRemoteVideoStream": Whether to subscribe to and play the remote video stream.
+ - \ref IRtcEngine::muteAllRemoteVideoStreams "muteAllRemoteVideoStreams": Whether to subscribe to and play all remote video streams.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int disableVideo() = 0;
+
+ /** **DEPRECATED** Sets the video profile.
+
+ This method is deprecated as of v2.3. Use the \ref IRtcEngine::setVideoEncoderConfiguration "setVideoEncoderConfiguration" method instead.
+
+ Each video profile includes a set of parameters, such as the resolution, frame rate, and bitrate. If the camera device does not support the specified resolution, the SDK automatically chooses a suitable camera resolution, keeping the encoder resolution specified by the *setVideoProfile* method.
+
+ @note
+ - If you do not need to set the video profile after joining the channel, call this method before the \ref IRtcEngine::enableVideo "enableVideo" method to reduce the render time of the first video frame.
+ - Always set the video profile before calling the \ref IRtcEngine::joinChannel "joinChannel" or \ref IRtcEngine::startPreview "startPreview" method.
+
+ @param profile Sets the video profile. See #VIDEO_PROFILE_TYPE.
+ @param swapWidthAndHeight Sets whether to swap the width and height of the video stream:
+ - true: Swap the width and height.
+ - false: (Default) Do not swap the width and height.
+ The width and height of the output video are consistent with the set video profile.
+ @note Since the landscape or portrait mode of the output video can be decided directly by the video profile, We recommend setting *swapWidthAndHeight* to *false* (default).
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setVideoProfile(VIDEO_PROFILE_TYPE profile, bool swapWidthAndHeight) = 0;
+
+ /** Sets the video encoder configuration.
+
+ Each video encoder configuration corresponds to a set of video parameters, including the resolution, frame rate, bitrate, and video orientation.
+
+ The parameters specified in this method are the maximum values under ideal network conditions. If the video engine cannot render the video using the specified parameters due to poor network conditions, the parameters further down the list are considered until a successful configuration is found.
+
+ @note If you do not need to set the video encoder configuration after joining the channel, you can call this method before the \ref IRtcEngine::enableVideo "enableVideo" method to reduce the render time of the first video frame.
+
+ @param config Sets the local video encoder configuration. See VideoEncoderConfiguration.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setVideoEncoderConfiguration(const VideoEncoderConfiguration& config) = 0;
+ /** Sets the camera capture configuration.
+
+ For a video call or live broadcast, generally the SDK controls the camera output parameters. When the default camera capturer settings do not meet special requirements or cause performance problems, we recommend using this method to set the camera capturer configuration:
+
+ - If the resolution or frame rate of the captured raw video data are higher than those set by \ref IRtcEngine::setVideoEncoderConfiguration "setVideoEncoderConfiguration", processing video frames requires extra CPU and RAM usage and degrades performance. We recommend setting config as CAPTURER_OUTPUT_PREFERENCE_PERFORMANCE = 1 to avoid such problems.
+ - If you do not need local video preview or are willing to sacrifice preview quality, we recommend setting config as CAPTURER_OUTPUT_PREFERENCE_PERFORMANCE = 1 to optimize CPU and RAM usage.
+ - If you want better quality for the local video preview, we recommend setting config as CAPTURER_OUTPUT_PREFERENCE_PREVIEW = 2.
+
+ @note Call this method before enabling the local camera. That said, you can call this method before calling \ref agora::rtc::IRtcEngine::joinChannel "joinChannel", \ref agora::rtc::IRtcEngine::enableVideo "enableVideo", or \ref IRtcEngine::enableLocalVideo "enableLocalVideo", depending on which method you use to turn on your local camera.
+
+ @param config Sets the camera capturer configuration. See CameraCapturerConfiguration.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setCameraCapturerConfiguration(const CameraCapturerConfiguration& config) = 0;
+
+ /** Initializes the local video view.
+
+ This method initializes the video view of a local stream on the local device. It affects only the video view that the local user sees, not the published local video stream.
+
+ Call this method to bind the local video stream to a video view and to set the rendering and mirror modes of the video view.
+ The binding is still valid after the user leaves the channel, which means that the window still displays. To unbind the view, set the *view* in VideoCanvas to NULL.
+
+ @note
+ - Call this method before joining a channel.
+ - To update the rendering or mirror mode of the local video view during a call, use the \ref IRtcEngine::setLocalRenderMode "setLocalRenderMode" method.
+ @param canvas Pointer to the local video view and settings. See VideoCanvas.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setupLocalVideo(const VideoCanvas& canvas) = 0;
+
+ /** Initializes the video view of a remote user.
+
+ This method initializes the video view of a remote stream on the local device. It affects only the video view that the local user sees.
+
+ Call this method to bind the remote video stream to a video view and to set the rendering and mirror modes of the video view.
+
+ The application specifies the uid of the remote video in this method before the remote user joins the channel. If the remote uid is unknown to the application, set it after the application receives the \ref IRtcEngineEventHandler::onUserJoined "onUserJoined" callback.
+ If the Video Recording function is enabled, the Video Recording Service joins the channel as a dummy client, causing other clients to also receive the \ref IRtcEngineEventHandler::onUserJoined "onUserJoined" callback. Do not bind the dummy client to the application view because the dummy client does not send any video streams. If your application does not recognize the dummy client, bind the remote user to the view when the SDK triggers the \ref IRtcEngineEventHandler::onFirstRemoteVideoDecoded "onFirstRemoteVideoDecoded" callback.
+ To unbind the remote user from the view, set the view in VideoCanvas to NULL. Once the remote user leaves the channel, the SDK unbinds the remote user.
+
+ @note To update the rendering or mirror mode of the remote video view during a call, use the \ref IRtcEngine::setRemoteRenderMode "setRemoteRenderMode" method.
+
+ @param canvas Pointer to the remote video view and settings. See VideoCanvas.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setupRemoteVideo(const VideoCanvas& canvas) = 0;
+
+ /** Starts the local video preview before joining the channel.
+
+ Before calling this method, you must:
+
+ - Call the \ref IRtcEngine::setupLocalVideo "setupLocalVideo" method to set up the local preview window and configure the attributes.
+ - Call the \ref IRtcEngine::enableVideo "enableVideo" method to enable video.
+
+ @note Once the startPreview method is called to start the local video preview, if you leave the channel by calling the \ref IRtcEngine::leaveChannel "leaveChannel" method, the local video preview remains until you call the \ref IRtcEngine::stopPreview "stopPreview" method to disable it.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int startPreview() = 0;
+
+ /** Prioritizes a remote user's stream.
+
+ Use this method with the \ref IRtcEngine::setRemoteSubscribeFallbackOption "setRemoteSubscribeFallbackOption" method. If the fallback function is enabled for a subscribed stream, the SDK ensures the high-priority user gets the best possible stream quality.
+
+ @note The Agora SDK supports setting @p userPriority as high for one user only.
+
+ @param uid The ID of the remote user.
+ @param userPriority Sets the priority of the remote user. See #PRIORITY_TYPE.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRemoteUserPriority(uid_t uid, PRIORITY_TYPE userPriority) = 0;
+
+ /** Stops the local video preview and disables video.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int stopPreview() = 0;
+
+ /** Enables the audio module.
+
+ The audio mode is enabled by default.
+
+ @note
+ - This method affects the internal engine and can be called after the \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" method. You can call this method either before or after joining a channel.
+ - This method resets the internal engine and takes some time to take effect. We recommend using the following API methods to control the audio engine modules separately:
+ - \ref IRtcEngine::enableLocalAudio "enableLocalAudio": Whether to enable the microphone to create the local audio stream.
+ - \ref IRtcEngine::muteLocalAudioStream "muteLocalAudioStream": Whether to publish the local audio stream.
+ - \ref IRtcEngine::muteRemoteAudioStream "muteRemoteAudioStream": Whether to subscribe to and play the remote audio stream.
+ - \ref IRtcEngine::muteAllRemoteAudioStreams "muteAllRemoteAudioStreams": Whether to subscribe to and play all remote audio streams.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int enableAudio() = 0;
+
+ /** Disables/Re-enables the local audio function.
+
+ The audio function is enabled by default. This method disables or re-enables the local audio function, that is, to stop or restart local audio capturing.
+
+ This method does not affect receiving or playing the remote audio streams,and enableLocalAudio(false) is applicable to scenarios where the user wants to
+ receive remote audio streams without sending any audio stream to other users in the channel.
+
+ The SDK triggers the \ref IRtcEngineEventHandler::onMicrophoneEnabled "onMicrophoneEnabled" callback once the local audio function is disabled or enabled.
+
+ @note
+ - Call this method after the \ref IRtcEngine::joinChannel "joinChannel" method.
+ - This method is different from the \ref agora::rtc::IRtcEngine::muteLocalAudioStream "muteLocalAudioStream" method:
+
+ - \ref agora::rtc::IRtcEngine::enableLocalAudio "enableLocalAudio": Disables/Re-enables the local audio capturing and processing.
+ If you disable or re-enable local audio recording using the `enableLocalAudio` method, the local user may hear a pause in the remote audio playback.
+ - \ref agora::rtc::IRtcEngine::muteLocalAudioStream "muteLocalAudioStream": Sends/Stops sending the local audio streams.
+
+ @param enabled Sets whether to disable/re-enable the local audio function:
+ - true: (Default) Re-enable the local audio function, that is, to start the local audio capturing device (for example, the microphone).
+ - false: Disable the local audio function, that is, to stop local audio capturing.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int enableLocalAudio(bool enabled) = 0;
+
+ /** Disables the audio module.
+
+ @note
+ - This method affects the internal engine and can be called after the \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" method. You can call this method either before or after joining a channel.
+ - This method resets the internal engine and takes some time to take effect. We recommend using the \ref agora::rtc::IRtcEngine::enableLocalAudio "enableLocalAudio" and \ref agora::rtc::IRtcEngine::muteLocalAudioStream "muteLocalAudioStream" methods to capture, process, and send the local audio streams.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int disableAudio() = 0;
+
+ /** Sets the audio parameters and application scenarios.
+
+ @note
+ - The *setAudioProfile* method must be called before the \ref IRtcEngine::joinChannel "joinChannel" method.
+ - In the Communication and Live-broadcast profiles, the bitrate may be different from your settings due to network self-adaptation.
+ - In scenarios requiring high-quality audio, for example, a music teaching scenario, we recommend setting profile as AUDIO_PROFILE_MUSIC_HIGH_QUALITY (4) and scenario as AUDIO_SCENARIO_GAME_STREAMING (3).
+
+ @param profile Sets the sample rate, bitrate, encoding mode, and the number of channels. See #AUDIO_PROFILE_TYPE.
+ @param scenario Sets the audio application scenario. See #AUDIO_SCENARIO_TYPE. Under different audio scenarios, the device uses different volume tracks, i.e. either the in-call volume or the media volume. For details, see [What is the difference between the in-call volume and the media volume?](https://docs.agora.io/en/faq/system_volume).
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setAudioProfile(AUDIO_PROFILE_TYPE profile, AUDIO_SCENARIO_TYPE scenario) = 0;
+ /** Stops/Resumes sending the local audio stream.
+
+ A successful \ref agora::rtc::IRtcEngine::muteLocalAudioStream "muteLocalAudioStream" method call triggers the \ref agora::rtc::IRtcEngineEventHandler::onUserMuteAudio "onUserMuteAudio" callback on the remote client.
+ @note
+ - When @p mute is set as @p true, this method does not disable the microphone, which does not affect any ongoing recording.
+ - If you call \ref agora::rtc::IRtcEngine::setChannelProfile "setChannelProfile" after this method, the SDK resets whether or not to mute the local audio according to the channel profile and user role. Therefore, we recommend calling this method after the `setChannelProfile` method.
+
+ @param mute Sets whether to send/stop sending the local audio stream:
+ - true: Stops sending the local audio stream.
+ - false: (Default) Sends the local audio stream.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int muteLocalAudioStream(bool mute) = 0;
+ /** Stops/Resumes receiving all remote users' audio streams.
+
+ @param mute Sets whether to receive/stop receiving all remote users' audio streams.
+ - true: Stops receiving all remote users' audio streams.
+ - false: (Default) Receives all remote users' audio streams.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int muteAllRemoteAudioStreams(bool mute) = 0;
+ /** Stops/Resumes receiving all remote users' audio streams by default.
+
+ @param mute Sets whether to receive/stop receiving all remote users' audio streams by default:
+ - true: Stops receiving all remote users' audio streams by default.
+ - false: (Default) Receives all remote users' audio streams by default.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setDefaultMuteAllRemoteAudioStreams(bool mute) = 0;
+
+ /** Adjusts the playback volume of a specified remote user.
+
+ You can call this method as many times as necessary to adjust the playback volume of different remote users, or to repeatedly adjust the playback volume of the same remote user.
+
+ @note
+ - Call this method after joining a channel.
+ - The playback volume here refers to the mixed volume of a specified remote user.
+ - This method can only adjust the playback volume of one specified remote user at a time. To adjust the playback volume of different remote users, call the method as many times, once for each remote user.
+
+ @param uid The ID of the remote user.
+ @param volume The playback volume of the specified remote user. The value ranges from 0 to 100:
+ - 0: Mute.
+ - 100: Original volume.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int adjustUserPlaybackSignalVolume(unsigned int uid, int volume) = 0;
+ /** Stops/Resumes receiving a specified remote user's audio stream.
+
+ @note If you called the \ref agora::rtc::IRtcEngine::muteAllRemoteAudioStreams "muteAllRemoteAudioStreams" method and set @p mute as @p true to stop receiving all remote users' audio streams, call the *muteAllRemoteAudioStreams* method and set @p mute as @p false before calling this method. The *muteAllRemoteAudioStreams* method sets all remote audio streams, while the *muteRemoteAudioStream* method sets a specified remote audio stream.
+
+ @param userId User ID of the specified remote user sending the audio.
+ @param mute Sets whether to receive/stop receiving a specified remote user's audio stream:
+ - true: Stops receiving the specified remote user's audio stream.
+ - false: (Default) Receives the specified remote user's audio stream.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+
+ */
+ virtual int muteRemoteAudioStream(uid_t userId, bool mute) = 0;
+ /** Stops/Resumes sending the local video stream.
+
+ A successful \ref agora::rtc::IRtcEngine::muteLocalVideoStream "muteLocalVideoStream" method call triggers the \ref agora::rtc::IRtcEngineEventHandler::onUserMuteVideo "onUserMuteVideo" callback on the remote client.
+
+ @note
+ - When set to *true*, this method does not disable the camera which does not affect the retrieval of the local video streams. This method executes faster than the \ref agora::rtc::IRtcEngine::enableLocalVideo "enableLocalVideo" method which controls the sending of the local video stream.
+ - If you call \ref agora::rtc::IRtcEngine::setChannelProfile "setChannelProfile" after this method, the SDK resets whether or not to mute the local video according to the channel profile and user role. Therefore, we recommend calling this method after the `setChannelProfile` method.
+
+ @param mute Sets whether to send/stop sending the local video stream:
+ - true: Stop sending the local video stream.
+ - false: (Default) Send the local video stream.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int muteLocalVideoStream(bool mute) = 0;
+ /** Enables/Disables the local video capture.
+
+ This method disables or re-enables the local video capturer, and does not affect receiving the remote video stream.
+
+ After you call the \ref agora::rtc::IRtcEngine::enableVideo "enableVideo" method, the local video capturer is enabled by default. You can call \ref agora::rtc::IRtcEngine::enableLocalVideo "enableLocalVideo(false)" to disable the local video capturer. If you want to re-enable it, call \ref agora::rtc::IRtcEngine::enableLocalVideo "enableLocalVideo(true)".
+
+ After the local video capturer is successfully disabled or re-enabled, the SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onUserEnableLocalVideo "onUserEnableLocalVideo" callback on the remote client.
+
+ @note This method affects the internal engine and can be called after the \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" method.
+
+ @param enabled Sets whether to disable/re-enable the local video, including the capturer, renderer, and sender:
+ - true: (Default) Re-enable the local video.
+ - false: Disable the local video. Once the local video is disabled, the remote users can no longer receive the video stream of this user, while this user can still receive the video streams of the other remote users.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int enableLocalVideo(bool enabled) = 0;
+ /** Stops/Resumes receiving all video stream from a specified remote user.
+
+ @param mute Sets whether to receive/stop receiving all remote users' video streams:
+ - true: Stop receiving all remote users' video streams.
+ - false: (Default) Receive all remote users' video streams.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int muteAllRemoteVideoStreams(bool mute) = 0;
+ /** Stops/Resumes receiving all remote users' video streams by default.
+
+ @param mute Sets whether to receive/stop receiving all remote users' video streams by default:
+ - true: Stop receiving all remote users' video streams by default.
+ - false: (Default) Receive all remote users' video streams by default.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setDefaultMuteAllRemoteVideoStreams(bool mute) = 0;
+ /** Stops/Resumes receiving the video stream from a specified remote user.
+
+ @note If you called the \ref agora::rtc::IRtcEngine::muteAllRemoteVideoStreams "muteAllRemoteVideoStreams" method and set @p mute as @p true to stop receiving all remote video streams, call the *muteAllRemoteVideoStreams* method and set @p mute as @p false before calling this method.
+
+ @param userId User ID of the specified remote user.
+ @param mute Sets whether to stop/resume receiving the video stream from a specified remote user:
+ - true: Stop receiving the specified remote user's video stream.
+ - false: (Default) Receive the specified remote user's video stream.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int muteRemoteVideoStream(uid_t userId, bool mute) = 0;
+ /** Sets the remote user's video stream type received by the local user when the remote user sends dual streams.
+
+ This method allows the application to adjust the corresponding video-stream type based on the size of the video window to reduce the bandwidth and resources.
+
+ - If the remote user enables the dual-stream mode by calling the \ref agora::rtc::IRtcEngine::enableDualStreamMode "enableDualStreamMode" method, the SDK receives the high-stream video by default.
+ - If the dual-stream mode is not enabled, the SDK receives the high-stream video by default.
+
+ The method result returns in the \ref agora::rtc::IRtcEngineEventHandler::onApiCallExecuted "onApiCallExecuted" callback. The SDK receives the high-stream video by default to reduce the bandwidth. If needed, users may use this method to switch to the low-stream video.
+ By default, the aspect ratio of the low-stream video is the same as the high-stream video. Once the resolution of the high-stream video is set, the system automatically sets the resolution, frame rate, and bitrate of the low-stream video.
+
+ @param userId ID of the remote user sending the video stream.
+ @param streamType Sets the video-stream type. See #REMOTE_VIDEO_STREAM_TYPE.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRemoteVideoStreamType(uid_t userId, REMOTE_VIDEO_STREAM_TYPE streamType) = 0;
+ /** Sets the default video-stream type for the video received by the local user when the remote user sends dual streams.
+
+ - If the dual-stream mode is enabled by calling the \ref agora::rtc::IRtcEngine::enableDualStreamMode "enableDualStreamMode" method, the user receives the high-stream video by default. The @p setRemoteDefaultVideoStreamType method allows the application to adjust the corresponding video-stream type according to the size of the video window, reducing the bandwidth and resources.
+ - If the dual-stream mode is not enabled, the user receives the high-stream video by default.
+
+ The result after calling this method is returned in the \ref agora::rtc::IRtcEngineEventHandler::onApiCallExecuted "onApiCallExecuted" callback. The Agora SDK receives the high-stream video by default to reduce the bandwidth. If needed, users can switch to the low-stream video through this method.
+
+ @param streamType Sets the default video-stream type. See #REMOTE_VIDEO_STREAM_TYPE.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRemoteDefaultVideoStreamType(REMOTE_VIDEO_STREAM_TYPE streamType) = 0;
+
+ /** Enables the \ref agora::rtc::IRtcEngineEventHandler::onAudioVolumeIndication "onAudioVolumeIndication" callback at a set time interval to report on which users are speaking and the speakers' volume.
+
+ Once this method is enabled, the SDK returns the volume indication in the \ref agora::rtc::IRtcEngineEventHandler::onAudioVolumeIndication "onAudioVolumeIndication" callback at the set time interval, whether or not any user is speaking in the channel.
+
+ @param interval Sets the time interval between two consecutive volume indications:
+ - ≤ 0: Disables the volume indication.
+ - > 0: Time interval (ms) between two consecutive volume indications. We recommend setting @p interval > 200 ms. Do not set @p interval < 10 ms, or the *onAudioVolumeIndication* callback will not be triggered.
+ @param smooth Smoothing factor sets the sensitivity of the audio volume indicator. The value ranges between 0 and 10. The greater the value, the more sensitive the indicator. The recommended value is 3.
+ @param report_vad
+
+ - true: Enable the voice activity detection of the local user. Once it is enabled, the `vad` parameter of the `onAudioVolumeIndication` callback reports the voice activity status of the local user.
+ - false: (Default) Disable the voice activity detection of the local user. Once it is disabled, the `vad` parameter of the `onAudioVolumeIndication` callback does not report the voice activity status of the local user, except for the scenario where the engine automatically detects the voice activity of the local user.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int enableAudioVolumeIndication(int interval, int smooth, bool report_vad) = 0;
+ /** **DEPRECATED** Starts an audio recording.
+ * Use \ref IRtcEngine::startAudioRecording(const char* filePath, int sampleRate, AUDIO_RECORDING_QUALITY_TYPE quality) "startAudioRecording"2 instead.
+
+ The SDK allows recording during a call. Supported formats:
+
+ - .wav: Large file size with high fidelity.
+ - .aac: Small file size with low fidelity.
+
+ This method has a fixed sample rate of 32 kHz.
+
+ Ensure that the directory to save the recording file exists and is writable.
+ This method is usually called after the \ref agora::rtc::IRtcEngine::joinChannel "joinChannel" method.
+ The recording automatically stops when the \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" method is called.
+
+ @param filePath Pointer to the absolute file path of the recording file. The string of the file name is in UTF-8.
+ @param quality Sets the audio recording quality. See #AUDIO_RECORDING_QUALITY_TYPE.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int startAudioRecording(const char* filePath, AUDIO_RECORDING_QUALITY_TYPE quality) = 0;
+
+ /** Starts an audio recording on the client.
+ *
+ * The SDK allows recording during a call. After successfully calling this method, you can record the audio of all the users in the channel and get an audio recording file.
+ * Supported formats of the recording file are as follows:
+ * - .wav: Large file size with high fidelity.
+ * - .aac: Small file size with low fidelity.
+ *
+ * @note
+ * - Ensure that the directory you use to save the recording file exists and is writable.
+ * - This method is usually called after the `joinChannel` method. The recording automatically stops when you call the `leaveChannel` method.
+ * - For better recording effects, set quality as #AUDIO_RECORDING_QUALITY_MEDIUM or #AUDIO_RECORDING_QUALITY_HIGH when `sampleRate` is 44.1 kHz or 48 kHz.
+ *
+ * @param filePath Pointer to the absolute file path of the recording file. The string of the file name is in UTF-8.
+ * @param sampleRate Sample rate (kHz) of the recording file. Supported values are as follows:
+ * - 16
+ * - (Default) 32
+ * - 44.1
+ * - 48
+ * @param quality Sets the audio recording quality. See #AUDIO_RECORDING_QUALITY_TYPE.
+ *
+ * @return
+ * - 0: Success.
+ * - < 0: Failure.
+ */
+ virtual int startAudioRecording(const char* filePath, int sampleRate, AUDIO_RECORDING_QUALITY_TYPE quality) = 0;
+ /** Stops an audio recording on the client.
+
+ You can call this method before calling the \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" method else, the recording automatically stops when the \ref agora::rtc::IRtcEngine::leaveChannel "leaveChannel" method is called.
+
+ @return
+ - 0: Success
+ - < 0: Failure.
+ */
+ virtual int stopAudioRecording() = 0;
+ /** Starts playing and mixing the music file.
+
+ This method mixes the specified local audio file with the audio stream from the microphone, or replaces the microphone's audio stream with the specified local audio file. You can choose whether the other user can hear the local audio playback and specify the number of playback loops. This method also supports online music playback.
+
+ When the audio mixing file playback finishes after calling this method, the SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onAudioMixingFinished "onAudioMixingFinished" callback.
+
+ A successful \ref agora::rtc::IRtcEngine::startAudioMixing "startAudioMixing" method call triggers the \ref agora::rtc::IRtcEngineEventHandler::onAudioMixingStateChanged "onAudioMixingStateChanged" (PLAY) callback on the local client.
+
+ When the audio mixing file playback finishes, the SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onAudioMixingStateChanged "onAudioMixingStateChanged" (STOPPED) callback on the local client.
+ @note
+ - Call this method when you are in a channel.
+ - If the local audio mixing file does not exist, or if the SDK does not support the file format or cannot access the music file URL, the SDK returns WARN_AUDIO_MIXING_OPEN_ERROR = 701.
+
+ @param filePath Pointer to the absolute path of the local or online audio file to mix. Supported audio formats: 3GP, ASF, ADTS, AVI, MP3, MPEG-4, SAMI, and WAVE. For more information, see [Supported Media Formats in Media Foundation](https://docs.microsoft.com/en-us/windows/desktop/medfound/supported-media-formats-in-media-foundation).
+ @param loopback Sets which user can hear the audio mixing:
+ - true: Only the local user can hear the audio mixing.
+ - false: Both users can hear the audio mixing.
+ @param replace Sets the audio mixing content:
+ - true: Only the specified audio file is published; the audio stream received by the microphone is not published.
+ - false: The local audio file is mixed with the audio stream from the microphone.
+ @param cycle Sets the number of playback loops:
+ - Positive integer: Number of playback loops.
+ - -1: Infinite playback loops.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int startAudioMixing(const char* filePath, bool loopback, bool replace, int cycle) = 0;
+ /** Stops playing and mixing the music file.
+
+ Call this method when you are in a channel.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int stopAudioMixing() = 0;
+ /** Pauses playing and mixing the music file.
+
+ Call this method when you are in a channel.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int pauseAudioMixing() = 0;
+ /** Resumes playing and mixing the music file.
+
+ Call this method when you are in a channel.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int resumeAudioMixing() = 0;
+ /** **DEPRECATED** Agora does not recommend using this method.
+
+ Sets the high-quality audio preferences. Call this method and set all parameters before joining a channel.
+
+ Do not call this method again after joining a channel.
+
+ @param fullband Sets whether to enable/disable full-band codec (48-kHz sample rate). Not compatible with SDK versions before v1.7.4:
+ - true: Enable full-band codec.
+ - false: Disable full-band codec.
+ @param stereo Sets whether to enable/disable stereo codec. Not compatible with SDK versions before v1.7.4:
+ - true: Enable stereo codec.
+ - false: Disable stereo codec.
+ @param fullBitrate Sets whether to enable/disable high-bitrate mode. Recommended in voice-only mode:
+ - true: Enable high-bitrate mode.
+ - false: Disable high-bitrate mode.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setHighQualityAudioParameters(bool fullband, bool stereo, bool fullBitrate) = 0;
+ /** Adjusts the volume during audio mixing.
+
+ Call this method when you are in a channel.
+
+ @note Calling this method does not affect the volume of audio effect file playback invoked by the \ref agora::rtc::IRtcEngine::playEffect "playEffect" method.
+
+ @param volume Audio mixing volume. The value ranges between 0 and 100 (default).
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int adjustAudioMixingVolume(int volume) = 0;
+ /** Adjusts the audio mixing volume for local playback.
+
+ @note Call this method when you are in a channel.
+
+ @param volume Audio mixing volume for local playback. The value ranges between 0 and 100 (default).
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int adjustAudioMixingPlayoutVolume(int volume) = 0;
+ /** Retrieves the audio mixing volume for local playback.
+
+ This method helps troubleshoot audio volume related issues.
+
+ @note Call this method when you are in a channel.
+
+ @return
+ - ≥ 0: The audio mixing volume, if this method call succeeds. The value range is [0,100].
+ - < 0: Failure.
+ */
+ virtual int getAudioMixingPlayoutVolume() = 0;
+ /** Adjusts the audio mixing volume for publishing (for remote users).
+
+ @note Call this method when you are in a channel.
+
+ @param volume Audio mixing volume for publishing. The value ranges between 0 and 100 (default).
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int adjustAudioMixingPublishVolume(int volume) = 0;
+ /** Retrieves the audio mixing volume for publishing.
+
+ This method helps troubleshoot audio volume related issues.
+
+ @note Call this method when you are in a channel.
+
+ @return
+ - ≥ 0: The audio mixing volume for publishing, if this method call succeeds. The value range is [0,100].
+ - < 0: Failure.
+ */
+ virtual int getAudioMixingPublishVolume() = 0;
+
+ /** Retrieves the duration (ms) of the music file.
+
+ Call this method when you are in a channel.
+
+ @return
+ - ≥ 0: The audio mixing duration, if this method call succeeds.
+ - < 0: Failure.
+ */
+ virtual int getAudioMixingDuration() = 0;
+ /** Retrieves the playback position (ms) of the music file.
+
+ Call this method when you are in a channel.
+
+ @return
+ - ≥ 0: The current playback position of the audio mixing, if this method call succeeds.
+ - < 0: Failure.
+ */
+ virtual int getAudioMixingCurrentPosition() = 0;
+ /** Sets the playback position of the music file to a different starting position (the default plays from the beginning).
+
+ @param pos The playback starting position (ms) of the music file.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setAudioMixingPosition(int pos /*in ms*/) = 0;
+ /** Retrieves the volume of the audio effects.
+
+ The value ranges between 0.0 and 100.0.
+
+ @return
+ - ≥ 0: Volume of the audio effects, if this method call succeeds.
+
+ - < 0: Failure.
+ */
+ virtual int getEffectsVolume() = 0;
+ /** Sets the volume of the audio effects.
+
+ @param volume Sets the volume of the audio effects. The value ranges between 0 and 100 (default).
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setEffectsVolume(int volume) = 0;
+ /** Sets the volume of a specified audio effect.
+
+ @param soundId ID of the audio effect. Each audio effect has a unique ID.
+ @param volume Sets the volume of the specified audio effect. The value ranges between 0 and 100 (default).
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setVolumeOfEffect(int soundId, int volume) = 0;
+
+ /** Plays a specified local or online audio effect file.
+
+ This method allows you to set the loop count, pitch, pan, and gain of the audio effect file, as well as whether the remote user can hear the audio effect.
+
+ To play multiple audio effect files simultaneously, call this method multiple times with different soundIds and filePaths. We recommend playing no more than three audio effect files at the same time.
+
+ @param soundId ID of the specified audio effect. Each audio effect has a unique ID.
+
+ @note
+ - If the audio effect is preloaded into the memory through the \ref IRtcEngine::preloadEffect "preloadEffect" method, the value of @p soundID must be the same as that in the *preloadEffect* method.
+ - Playing multiple online audio effect files simultaneously is not supported on macOS and Windows.
+
+ @param filePath The absolute path to the local audio effect file or the URL of the online audio effect file.
+ @param loopCount Sets the number of times the audio effect loops:
+ - 0: Play the audio effect once.
+ - 1: Play the audio effect twice.
+ - -1: Play the audio effect in an indefinite loop until the \ref IRtcEngine::stopEffect "stopEffect" or \ref IRtcEngine::stopAllEffects "stopAllEffects" method is called.
+ @param pitch Sets the pitch of the audio effect. The value ranges between 0.5 and 2. The default value is 1 (no change to the pitch). The lower the value, the lower the pitch.
+ @param pan Sets the spatial position of the audio effect. The value ranges between -1.0 and 1.0:
+ - 0.0: The audio effect displays ahead.
+ - 1.0: The audio effect displays to the right.
+ - -1.0: The audio effect displays to the left.
+ @param gain Sets the volume of the audio effect. The value ranges between 0 and 100 (default). The lower the value, the lower the volume of the audio effect.
+ @param publish Sets whether or not to publish the specified audio effect to the remote stream:
+ - true: The locally played audio effect is published to the Agora Cloud and the remote users can hear it.
+ - false: The locally played audio effect is not published to the Agora Cloud and the remote users cannot hear it.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int playEffect(int soundId, const char* filePath, int loopCount, double pitch, double pan, int gain, bool publish = false) = 0;
+ /** Stops playing a specified audio effect.
+
+ @param soundId ID of the audio effect to stop playing. Each audio effect has a unique ID.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int stopEffect(int soundId) = 0;
+ /** Stops playing all audio effects.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int stopAllEffects() = 0;
+
+ /** Preloads a specified audio effect file into the memory.
+
+ @note This method does not support online audio effect files.
+
+ To ensure smooth communication, limit the size of the audio effect file. We recommend using this method to preload the audio effect before calling the \ref IRtcEngine::joinChannel "joinChannel" method.
+
+ Supported audio formats: mp3, aac, m4a, 3gp, and wav.
+
+ @param soundId ID of the audio effect. Each audio effect has a unique ID.
+ @param filePath Pointer to the absolute path of the audio effect file.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int preloadEffect(int soundId, const char* filePath) = 0;
+ /** Releases a specified preloaded audio effect from the memory.
+
+ @param soundId ID of the audio effect. Each audio effect has a unique ID.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int unloadEffect(int soundId) = 0;
+ /** Pauses a specified audio effect.
+
+ @param soundId ID of the audio effect. Each audio effect has a unique ID.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int pauseEffect(int soundId) = 0;
+ /** Pauses all audio effects.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int pauseAllEffects() = 0;
+ /** Resumes playing a specified audio effect.
+
+ @param soundId ID of the audio effect. Each audio effect has a unique ID.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int resumeEffect(int soundId) = 0;
+ /** Resumes playing all audio effects.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int resumeAllEffects() = 0;
+ /** Enables/Disables stereo panning for remote users.
+
+ Ensure that you call this method before joinChannel to enable stereo panning for remote users so that the local user can track the position of a remote user by calling \ref agora::rtc::IRtcEngine::setRemoteVoicePosition "setRemoteVoicePosition".
+
+ @param enabled Sets whether or not to enable stereo panning for remote users:
+ - true: enables stereo panning.
+ - false: disables stereo panning.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int enableSoundPositionIndication(bool enabled) = 0;
+ /** Sets the sound position and gain of a remote user.
+
+ When the local user calls this method to set the sound position of a remote user, the sound difference between the left and right channels allows the local user to track the real-time position of the remote user, creating a real sense of space. This method applies to massively multiplayer online games, such as Battle Royale games.
+
+ @note
+ - For this method to work, enable stereo panning for remote users by calling the \ref agora::rtc::IRtcEngine::enableSoundPositionIndication "enableSoundPositionIndication" method before joining a channel.
+ - This method requires hardware support. For the best sound positioning, we recommend using a stereo speaker.
+
+ @param uid The ID of the remote user.
+ @param pan The sound position of the remote user. The value ranges from -1.0 to 1.0:
+ - 0.0: the remote sound comes from the front.
+ - -1.0: the remote sound comes from the left.
+ - 1.0: the remote sound comes from the right.
+ @param gain Gain of the remote user. The value ranges from 0.0 to 100.0. The default value is 100.0 (the original gain of the remote user). The smaller the value, the less the gain.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRemoteVoicePosition(uid_t uid, double pan, double gain) = 0;
+
+ /** Changes the voice pitch of the local speaker.
+
+ @param pitch Sets the voice pitch. The value ranges between 0.5 and 2.0. The lower the value, the lower the voice pitch. The default value is 1.0 (no change to the local voice pitch).
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLocalVoicePitch(double pitch) = 0;
+ /** Sets the local voice equalization effect.
+
+ @param bandFrequency Sets the band frequency. The value ranges between 0 and 9, representing the respective 10-band center frequencies of the voice effects, including 31, 62, 125, 500, 1k, 2k, 4k, 8k, and 16k Hz. See #AUDIO_EQUALIZATION_BAND_FREQUENCY.
+ @param bandGain Sets the gain of each band in dB. The value ranges between -15 and 15.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLocalVoiceEqualization(AUDIO_EQUALIZATION_BAND_FREQUENCY bandFrequency, int bandGain) = 0;
+ /** Sets the local voice reverberation.
+
+ v2.4.0 adds the \ref agora::rtc::IRtcEngine::setLocalVoiceReverbPreset "setLocalVoiceReverbPreset" method, a more user-friendly method for setting the local voice reverberation. You can use this method to set the local reverberation effect, such as pop music, R&B, rock music, and hip-hop.
+
+ @param reverbKey Sets the reverberation key. See #AUDIO_REVERB_TYPE.
+ @param value Sets the value of the reverberation key.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLocalVoiceReverb(AUDIO_REVERB_TYPE reverbKey, int value) = 0;
+ /** Sets the local voice changer option.
+
+ @note Do not use this method together with the \ref agora::rtc::IRtcEngine::setLocalVoiceReverbPreset "setLocalVoiceReverbPreset" method, because the method called later overrides the one called earlier.
+
+ @param voiceChanger Sets the local voice changer option. See #VOICE_CHANGER_PRESET.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLocalVoiceChanger(VOICE_CHANGER_PRESET voiceChanger) = 0;
+ /** Sets the preset local voice reverberation effect.
+
+ @note
+ - Do not use this method together with \ref agora::rtc::IRtcEngine::setLocalVoiceReverb "setLocalVoiceReverb".
+ - Do not use this method together with the \ref agora::rtc::IRtcEngine::setLocalVoiceChanger "setLocalVoiceChanger" method, because the method called later overrides the one called earlier.
+
+ @param reverbPreset Sets the preset audio reverberation configuration. See #AUDIO_REVERB_PRESET.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLocalVoiceReverbPreset(AUDIO_REVERB_PRESET reverbPreset) = 0;
+
+ /** Specifies an SDK output log file.
+
+ The log file records all SDK operations during runtime. If it does not exist, the SDK creates one.
+
+ @note
+ - The default log file is located at: C:\Users\\AppData\Local\Agora\.
+ - Ensure that you call this method immediately after calling the \ref agora::rtc::IRtcEngine::initialize "initialize" method, otherwise the output log may not be complete.
+
+ @param filePath File path of the log file. The string of the log file is in UTF-8.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLogFile(const char* filePath) = 0;
+ /** Sets the output log level of the SDK.
+
+ You can use one or a combination of the log filter levels. The log level follows the sequence of OFF, CRITICAL, ERROR, WARNING, INFO, and DEBUG. Choose a level to see the logs preceding that level.
+
+ If you set the log level to WARNING, you see the logs within levels CRITICAL, ERROR, and WARNING.
+
+ @param filter Sets the log filter level. See #LOG_FILTER_TYPE.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLogFilter(unsigned int filter) = 0;
+ /** Sets the log file size (KB).
+
+ The SDK has two log files, each with a default size of 512 KB. If you set @p fileSizeInBytes as 1024 KB, the SDK outputs log files with a total maximum size of 2 MB. If the total size of the log files exceed the set value, the new output log files overwrite the old output log files.
+
+ @param fileSizeInKBytes The SDK log file size (KB).
+ @return
+ - 0: Success.
+ - <0: Failure.
+ */
+ virtual int setLogFileSize(unsigned int fileSizeInKBytes) = 0;
+ /**
+ @deprecated This method is deprecated, use the \ref IRtcEngine::setLocalRenderMode(RENDER_MODE_TYPE renderMode, VIDEO_MIRROR_MODE_TYPE mirrorMode) "setLocalRenderMode"2 method instead.
+ Sets the local video display mode.
+
+ This method can be called multiple times during a call to change the display mode.
+
+ @param renderMode Sets the local video display mode. See #RENDER_MODE_TYPE.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLocalRenderMode(RENDER_MODE_TYPE renderMode) = 0;
+ /** Updates the display mode of the local video view.
+
+ After initializing the local video view, you can call this method to update its rendering and mirror modes. It affects only the video view that the local user sees, not the published local video stream.
+
+ @note
+ - Ensure that you have called the \ref IRtcEngine::setupLocalVideo "setupLocalVideo" method to initialize the local video view before calling this method.
+ @param renderMode The rendering mode of the local video view. See #RENDER_MODE_TYPE.
+ @param mirrorMode
+ - The mirror mode of the local video view. See #VIDEO_MIRROR_MODE_TYPE.
+ - **Note**: If you use a front camera, the SDK enables the mirror mode by default; if you use a rear camera, the SDK disables the mirror mode by default.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLocalRenderMode(RENDER_MODE_TYPE renderMode, VIDEO_MIRROR_MODE_TYPE mirrorMode) = 0;
+ /**
+ @deprecated This method is deprecated, use the \ref IRtcEngine::setRemoteRenderMode(uid_t userId, RENDER_MODE_TYPE renderMode, VIDEO_MIRROR_MODE_TYPE mirrorMode) "setRemoteRenderMode"2 method instead.
+ Sets the video display mode of a specified remote user.
+
+ This method can be called multiple times during a call to change the display mode.
+
+ @param userId ID of the remote user.
+ @param renderMode Sets the video display mode. See #RENDER_MODE_TYPE.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRemoteRenderMode(uid_t userId, RENDER_MODE_TYPE renderMode) = 0;
+ /** Updates the display mode of the video view of a remote user.
+
+ After initializing the video view of a remote user, you can call this method to update its rendering and mirror modes. This method affects only the video view that the local user sees.
+
+ @note
+ - Ensure that you have called the \ref IRtcEngine::setupRemoteVideo "setupRemoteVideo" method to initialize the remote video view before calling this method.
+ - During a call, you can call this method as many times as necessary to update the display mode of the video view of a remote user.
+
+ @param userId The ID of the remote user.
+ @param renderMode The rendering mode of the remote video view. See #RENDER_MODE_TYPE.
+ @param mirrorMode
+ - The mirror mode of the remote video view. See #VIDEO_MIRROR_MODE_TYPE.
+ - **Note**: The SDK disables the mirror mode by default.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRemoteRenderMode(uid_t userId, RENDER_MODE_TYPE renderMode, VIDEO_MIRROR_MODE_TYPE mirrorMode) = 0;
+ /**
+ @deprecated This method is deprecated, use the \ref IRtcEngine::setupLocalVideo "setupLocalVideo"
+ or \ref IRtcEngine::setLocalRenderMode(RENDER_MODE_TYPE renderMode, VIDEO_MIRROR_MODE_TYPE mirrorMode) "setLocalRenderMode" method instead.
+ Sets the local video mirror mode.
+
+ You must call this method before calling the \ref agora::rtc::IRtcEngine::startPreview "startPreview" method, otherwise the mirror mode will not work.
+
+ @note The SDK enables the mirror mode by default.
+
+ @param mirrorMode Sets the local video mirror mode. See #VIDEO_MIRROR_MODE_TYPE.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLocalVideoMirrorMode(VIDEO_MIRROR_MODE_TYPE mirrorMode) = 0;
+ /** Sets the stream mode to the single-stream (default) or dual-stream mode. (Live broadcast only.)
+
+ If the dual-stream mode is enabled, the receiver can choose to receive the high stream (high-resolution and high-bitrate video stream), or the low stream (low-resolution and low-bitrate video stream).
+
+ @param enabled Sets the stream mode:
+ - true: Dual-stream mode.
+ - false: (Default) Single-stream mode.
+ */
+ virtual int enableDualStreamMode(bool enabled) = 0;
+ /** Sets the external audio source. Please call this method before \ref agora::rtc::IRtcEngine::joinChannel "joinChannel".
+
+ @param enabled Sets whether to enable/disable the external audio source:
+ - true: Enables the external audio source.
+ - false: (Default) Disables the external audio source.
+ @param sampleRate Sets the sample rate (Hz) of the external audio source, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
+ @param channels Sets the number of audio channels of the external audio source:
+ - 1: Mono.
+ - 2: Stereo.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setExternalAudioSource(bool enabled, int sampleRate, int channels) = 0;
+ /** Sets the external audio sink.
+ * This method applies to scenarios where you want to use external audio
+ * data for playback. After enabling the external audio sink, you can call
+ * the \ref agora::media::IMediaEngine::pullAudioFrame "pullAudioFrame" method to pull the remote audio data, process
+ * it, and play it with the audio effects that you want.
+ *
+ * @note
+ * Once you enable the external audio sink, the app will not retrieve any
+ * audio data from the
+ * \ref agora::media::IAudioFrameObserver::onPlaybackAudioFrame "onPlaybackAudioFrame" callback.
+ *
+ * @param enabled
+ * - true: Enables the external audio sink.
+ * - false: (Default) Disables the external audio sink.
+ * @param sampleRate Sets the sample rate (Hz) of the external audio sink, which can be set as 16000, 32000, 44100 or 48000.
+ * @param channels Sets the number of audio channels of the external
+ * audio sink:
+ * - 1: Mono.
+ * - 2: Stereo.
+ *
+ * @return
+ * - 0: Success.
+ * - < 0: Failure.
+ */
+ virtual int setExternalAudioSink(bool enabled, int sampleRate, int channels) = 0;
+ /** Sets the audio recording format for the \ref agora::media::IAudioFrameObserver::onRecordAudioFrame "onRecordAudioFrame" callback.
+
+
+ @param sampleRate Sets the sample rate (@p samplesPerSec) returned in the *onRecordAudioFrame* callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
+ @param channel Sets the number of audio channels (@p channels) returned in the *onRecordAudioFrame* callback:
+ - 1: Mono
+ - 2: Stereo
+ @param mode Sets the use mode (see #RAW_AUDIO_FRAME_OP_MODE_TYPE) of the *onRecordAudioFrame* callback.
+ @param samplesPerCall Sets the number of samples returned in the *onRecordAudioFrame* callback. `samplesPerCall` is usually set as 1024 for RTMP streaming.
+
+
+ @note The SDK triggers the `onRecordAudioFrame` callback according to the sample interval. Ensure that the sample interval ≥ 0.01 (s). And, Sample interval (sec) = `samplePerCall`/(`sampleRate` × `channel`).
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRecordingAudioFrameParameters(int sampleRate, int channel, RAW_AUDIO_FRAME_OP_MODE_TYPE mode, int samplesPerCall) = 0;
+ /** Sets the audio playback format for the \ref agora::media::IAudioFrameObserver::onPlaybackAudioFrame "onPlaybackAudioFrame" callback.
+
+
+ @param sampleRate Sets the sample rate (@p samplesPerSec) returned in the *onPlaybackAudioFrame* callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
+ @param channel Sets the number of channels (@p channels) returned in the *onPlaybackAudioFrame* callback:
+ - 1: Mono
+ - 2: Stereo
+ @param mode Sets the use mode (see #RAW_AUDIO_FRAME_OP_MODE_TYPE) of the *onPlaybackAudioFrame* callback.
+ @param samplesPerCall Sets the number of samples returned in the *onPlaybackAudioFrame* callback. `samplesPerCall` is usually set as 1024 for RTMP streaming.
+
+ @note The SDK triggers the `onPlaybackAudioFrame` callback according to the sample interval. Ensure that the sample interval ≥ 0.01 (s). And, Sample interval (sec) = `samplePerCall`/(`sampleRate` × `channel`).
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setPlaybackAudioFrameParameters(int sampleRate, int channel, RAW_AUDIO_FRAME_OP_MODE_TYPE mode, int samplesPerCall) = 0;
+ /** Sets the mixed audio format for the \ref agora::media::IAudioFrameObserver::onMixedAudioFrame "onMixedAudioFrame" callback.
+
+
+ @param sampleRate Sets the sample rate (@p samplesPerSec) returned in the *onMixedAudioFrame* callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
+ @param samplesPerCall Sets the number of samples (`samples`) returned in the *onMixedAudioFrame* callback. `samplesPerCall` is usually set as 1024 for RTMP streaming.
+
+ @note The SDK triggers the `onMixedAudioFrame` callback according to the sample interval. Ensure that the sample interval ≥ 0.01 (s). And, Sample interval (sec) = `samplePerCall`/(`sampleRate` × `channels`).
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setMixedAudioFrameParameters(int sampleRate, int samplesPerCall) = 0;
+ /** Adjusts the recording volume.
+
+ @param volume Recording volume. The value ranges between 0 and 400:
+ - 0: Mute.
+ - 100: Original volume.
+ - 400: (Maximum) Four times the original volume with signal clipping protection.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int adjustRecordingSignalVolume(int volume) = 0;
+ /** Adjusts the playback volume of all remote users.
+
+ @note
+ - This method adjusts the playback volume that is the mixed volume of all remote users.
+ - (Since v2.3.2) To mute the local audio playback, call both the `adjustPlaybackSignalVolume` and \ref IRtcEngine::adjustAudioMixingVolume "adjustAudioMixingVolume" methods and set the volume as `0`.
+
+ @param volume The playback volume of all remote users. The value ranges from 0 to 400:
+ - 0: Mute.
+ - 100: Original volume.
+ - 400: (Maximum) Four times the original volume with signal clipping protection.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int adjustPlaybackSignalVolume(int volume) = 0;
+
+ /**
+ @deprecated This method is deprecated. As of v3.0.0, the Native SDK automatically enables interoperability with the Web SDK, so you no longer need to call this method.
+ Enables interoperability with the Agora Web SDK.
+
+ @note
+ - This method applies only to the Live-broadcast profile. In the Communication profile, interoperability with the Agora Web SDK is enabled by default.
+ - If the channel has Web SDK users, ensure that you call this method, or the video of the Native user will be a black screen for the Web user.
+
+ @param enabled Sets whether to enable/disable interoperability with the Agora Web SDK:
+ - true: Enable.
+ - false: (Default) Disable.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int enableWebSdkInteroperability(bool enabled) = 0;
+ //only for live broadcast
+ /** **DEPRECATED** Sets the preferences for the high-quality video. (Live broadcast only).
+
+ This method is deprecated as of v2.4.0.
+
+ @param preferFrameRateOverImageQuality Sets the video quality preference:
+ - true: Frame rate over image quality.
+ - false: (Default) Image quality over frame rate.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setVideoQualityParameters(bool preferFrameRateOverImageQuality) = 0;
+ /** Sets the fallback option for the locally published video stream based on the network conditions.
+
+ If `option` is set as #STREAM_FALLBACK_OPTION_AUDIO_ONLY (2), the SDK will:
+
+ - Disable the upstream video but enable audio only when the network conditions deteriorate and cannot support both video and audio.
+ - Re-enable the video when the network conditions improve.
+
+ When the locally published video stream falls back to audio only or when the audio-only stream switches back to the video, the SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onLocalPublishFallbackToAudioOnly "onLocalPublishFallbackToAudioOnly" callback.
+
+ @note Agora does not recommend using this method for CDN live streaming, because the remote CDN live user will have a noticeable lag when the locally published video stream falls back to audio only.
+
+ @param option Sets the fallback option for the locally published video stream:
+ - #STREAM_FALLBACK_OPTION_DISABLED (0): (Default) No fallback behavior for the locally published video stream when the uplink network condition is poor. The stream quality is not guaranteed.
+ - #STREAM_FALLBACK_OPTION_AUDIO_ONLY (2): The locally published video stream falls back to audio only when the uplink network condition is poor.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLocalPublishFallbackOption(STREAM_FALLBACK_OPTIONS option) = 0;
+ /** Sets the fallback option for the remotely subscribed video stream based on the network conditions.
+
+ The default setting for `option` is #STREAM_FALLBACK_OPTION_VIDEO_STREAM_LOW (1), where the remotely subscribed video stream falls back to the low-stream video (low resolution and low bitrate) under poor downlink network conditions.
+
+ If `option` is set as #STREAM_FALLBACK_OPTION_AUDIO_ONLY (2), the SDK automatically switches the video from a high-stream to a low-stream, or disables the video when the downlink network conditions cannot support both audio and video to guarantee the quality of the audio. The SDK monitors the network quality and restores the video stream when the network conditions improve.
+
+ When the remotely subscribed video stream falls back to audio only or when the audio-only stream switches back to the video stream, the SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onRemoteSubscribeFallbackToAudioOnly "onRemoteSubscribeFallbackToAudioOnly" callback.
+
+ @param option Sets the fallback option for the remotely subscribed video stream. See #STREAM_FALLBACK_OPTIONS.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setRemoteSubscribeFallbackOption(STREAM_FALLBACK_OPTIONS option) = 0;
+
+#if defined(__ANDROID__) || (defined(__APPLE__) && TARGET_OS_IOS)
+ /** Switches between front and rear cameras.
+
+ @note This method is for Android and iOS only.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int switchCamera() = 0;
+ /** Switches between front and rear cameras.
+
+ @note This method is for Android and iOS only, and it is private.
+
+ @param direction Sets the camera to be used:
+ - CAMERA_DIRECTION.CAMERA_REAR: Use the rear camera.
+ - CAMERA_DIRECTION.CAMERA_FRONT: Use the front camera.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int switchCamera(CAMERA_DIRECTION direction) = 0;
+ /** Sets the default audio playback route.
+
+ This method sets whether the received audio is routed to the earpiece or speakerphone by default before joining a channel.
+ If a user does not call this method, the audio is routed to the earpiece by default. If you need to change the default audio route after joining a channel, call the \ref IRtcEngine::setEnableSpeakerphone "setEnableSpeakerphone" method.
+
+ The default setting for each mode:
+ - Voice: Earpiece.
+ - Video: Speakerphone. If a user who is in the Communication profile calls the \ref IRtcEngine::disableVideo "disableVideo" method or if the user calls the \ref IRtcEngine::muteLocalVideoStream "muteLocalVideoStream" and \ref IRtcEngine::muteAllRemoteVideoStreams "muteAllRemoteVideoStreams" methods, the default audio route switches back to the earpiece automatically.
+ - Live Broadcast: Speakerphone.
+ - Gaming Voice: Speakerphone.
+
+ @note
+ - This method is for Android and iOS only.
+ - This method only works in audio mode.
+ - Call this method before calling the \ref IRtcEngine::joinChannel "joinChannel" method.
+ - Regardless of whether the audio is routed to the speakerphone or earpiece by default, once a headset is plugged in or Bluetooth device is connected, the default audio route changes. The default audio route switches to the earpiece once removing the headset or disconnecting the Bluetooth device.
+
+ @param defaultToSpeaker Sets the default audio route:
+ - true: Speakerphone.
+ - false: (Default) Earpiece.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setDefaultAudioRouteToSpeakerphone(bool defaultToSpeaker) = 0;
+ /** Enables/Disables the audio playback route to the speakerphone.
+
+ This method sets whether the audio is routed to the speakerphone or earpiece.
+
+ See the default audio route explanation in the \ref IRtcEngine::setDefaultAudioRouteToSpeakerphone "setDefaultAudioRouteToSpeakerphone" method and check whether it is necessary to call this method.
+
+ @note
+ - This method is for Android and iOS only.
+ - Ensure that you have successfully called the \ref IRtcEngine::joinChannel "joinChannel" method before calling this method.
+ - After calling this method, the SDK returns the \ref IRtcEngineEventHandler::onAudioRouteChanged "onAudioRouteChanged" callback to indicate the changes.
+ - This method does not take effect if a headset is used.
+
+ @param speakerOn Sets whether to route the audio to the speakerphone or earpiece:
+ - true: Route the audio to the speakerphone.
+ - false: Route the audio to the earpiece.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setEnableSpeakerphone(bool speakerOn) = 0;
+ /** Enables in-ear monitoring (for Android and iOS only).
+ @param enabled Sets whether to enable/disable in-ear monitoring:
+ - true: Enable.
+ - false: (Default) Disable.
+
+ * @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int enableInEarMonitoring(bool enabled) = 0;
+ /** Sets the volume of the in-ear monitor.
+
+ @param volume Sets the volume of the in-ear monitor. The value ranges between 0 and 100 (default).
+
+ @note This method is for Android and iOS only.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setInEarMonitoringVolume(int volume) = 0;
+ /** Checks whether the speakerphone is enabled.
+
+ @note This method is for Android and iOS only.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual bool isSpeakerphoneEnabled() = 0;
+#endif
+
+#if (defined(__APPLE__) && TARGET_OS_IOS)
+ /** Sets the audio session’s operational restriction.
+
+ The SDK and the app can both configure the audio session by default. The app may occasionally use other apps or third-party components to manipulate the audio session and restrict the SDK from doing so. This method allows the app to restrict the SDK’s manipulation of the audio session.
+
+ You can call this method at any time to return the control of the audio sessions to the SDK.
+
+ @note
+ - This method is for iOS only.
+ - This method restricts the SDK’s manipulation of the audio session. Any operation to the audio session relies solely on the app, other apps, or third-party components.
+
+ @param restriction The operational restriction (bit mask) of the SDK on the audio session. See #AUDIO_SESSION_OPERATION_RESTRICTION.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setAudioSessionOperationRestriction(AUDIO_SESSION_OPERATION_RESTRICTION restriction) = 0;
+#endif
+
+#if (defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE) || defined(_WIN32)
+ /** Enables loopback recording.
+
+ If you enable loopback recording, the output of the sound card is mixed into the audio stream sent to the other end.
+
+ @param enabled Sets whether to enable/disable loopback recording.
+ - true: Enable loopback recording.
+ - false: (Default) Disable loopback recording.
+ @param deviceName Pointer to the device name of the sound card. The default value is NULL (the default sound card).
+
+ @note
+ - This method is for macOS and Windows only.
+ - macOS does not support loopback recording of the default sound card. If you need to use this method, please use a virtual sound card and pass its name to the deviceName parameter. Agora has tested and recommends using soundflower.
+
+ */
+ virtual int enableLoopbackRecording(bool enabled, const char* deviceName = NULL) = 0;
+
+#if (defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE)
+ /** Shares the whole or part of a screen by specifying the display ID.
+
+ @note This method is for macOS only.
+
+ @param displayId The display ID of the screen to be shared. This parameter specifies which screen you want to share.
+ @param regionRect (Optional) Sets the relative location of the region to the screen. NIL means sharing the whole screen. See Rectangle. If the specified region overruns the screen, the SDK shares only the region within it; if you set width or height as 0, the SDK shares the whole screen.
+ @param captureParams Sets the screen sharing encoding parameters. See ScreenCaptureParameters.
+
+
+ @return
+ - 0: Success.
+ - < 0: Failure:
+ - ERR_INVALID_STATE: the screen sharing state is invalid, probably because another screen or window is being shared. Call \ref agora::rtc::IRtcEngine::stopScreenCapture "stopScreenCapture" to stop the current screen sharing.
+ - #ERR_INVALID_ARGUMENT: the argument is invalid.
+ */
+ virtual int startScreenCaptureByDisplayId(unsigned int displayId, const Rectangle& regionRect, const ScreenCaptureParameters& captureParams) = 0;
+#endif
+
+#if defined(_WIN32)
+ /** Shares the whole or part of a screen by specifying the screen rect.
+
+ @param screenRect Sets the relative location of the screen to the virtual screen. For information on how to get screenRect, see [Share the Screen](https://docs.agora.io/en/Video/screensharing_windows?platform=Windows).
+ @param regionRect (Optional) Sets the relative location of the region to the screen. NULL means sharing the whole screen. See Rectangle. If the specified region overruns the screen, the SDK shares only the region within it; if you set width or height as 0, the SDK shares the whole screen.
+ @param captureParams Sets the screen sharing encoding parameters. See ScreenCaptureParameters.
+
+ @return
+ - 0: Success.
+ - < 0: Failure:
+ - ERR_INVALID_STATE: the screen sharing state is invalid, probably because another screen or window is being shared. Call \ref agora::rtc::IRtcEngine::stopScreenCapture "stopScreenCapture" to stop the current screen sharing.
+ - ERR_INVALID_ARGUMENT: the argument is invalid.
+ */
+ virtual int startScreenCaptureByScreenRect(const Rectangle& screenRect, const Rectangle& regionRect, const ScreenCaptureParameters& captureParams) = 0;
+#endif
+
+ /** Shares the whole or part of a window by specifying the window ID.
+
+ @param windowId The ID of the window to be shared. For information on how to get the windowId, see [Share the Screen](https://docs.agora.io/en/Video/screensharing_windows?platform=Windows).
+ @param regionRect (Optional) The relative location of the region to the window. NULL/NIL means sharing the whole window. See Rectangle. If the specified region overruns the window, the SDK shares only the region within it; if you set width or height as 0, the SDK shares the whole window.
+ @param captureParams Window sharing encoding parameters. See ScreenCaptureParameters.
+
+ @return
+ - 0: Success.
+ - < 0: Failure:
+ - ERR_INVALID_STATE: the window sharing state is invalid, probably because another screen or window is being shared. Call \ref agora::rtc::IRtcEngine::stopScreenCapture "stopScreenCapture" to stop sharing the current window.
+ - #ERR_INVALID_ARGUMENT: the argument is invalid.
+ */
+ virtual int startScreenCaptureByWindowId(view_t windowId, const Rectangle& regionRect, const ScreenCaptureParameters& captureParams) = 0;
+
+ /** Sets the content hint for screen sharing.
+
+ A content hint suggests the type of the content being shared, so that the SDK applies different optimization algorithm to different types of content.
+
+ @param contentHint Sets the content hint for screen sharing. See VideoContentHint.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setScreenCaptureContentHint(VideoContentHint contentHint) = 0;
+
+ /** Updates the screen sharing parameters.
+
+ @param captureParams Sets the screen sharing encoding parameters. See ScreenCaptureParameters.
+
+ @return
+ - 0: Success.
+ - < 0: Failure:
+ - #ERR_NOT_READY: no screen or windows is being shared.
+ */
+ virtual int updateScreenCaptureParameters(const ScreenCaptureParameters& captureParams) = 0;
+
+ /** Updates the screen sharing region.
+
+ @param regionRect Sets the relative location of the region to the screen or window. NULL means sharing the whole screen or window. See Rectangle. If the specified region overruns the screen or window, the SDK shares only the region within it; if you set width or height as 0, the SDK shares the whole screen or window.
+
+ @return
+ - 0: Success.
+ - < 0: Failure:
+ - #ERR_NOT_READY: no screen or window is being shared.
+ */
+ virtual int updateScreenCaptureRegion(const Rectangle& regionRect) = 0;
+
+ /** Stop screen sharing.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int stopScreenCapture() = 0;
+
+#if defined(__APPLE__)
+ typedef unsigned int WindowIDType;
+#elif defined(_WIN32)
+ typedef HWND WindowIDType;
+#endif
+
+ /** **DEPRECATED** Starts screen sharing.
+
+ This method is deprecated as of v2.4.0. See the following methods instead:
+
+ - \ref agora::rtc::IRtcEngine::startScreenCaptureByDisplayId "startScreenCaptureByDisplayId"
+ - \ref agora::rtc::IRtcEngine::startScreenCaptureByScreenRect "startScreenCaptureByScreenRect"
+ - \ref agora::rtc::IRtcEngine::startScreenCaptureByWindowId "startScreenCaptureByWindowId"
+
+ This method shares the whole screen, specified window, or specified region:
+
+ - Whole screen: Set @p windowId as 0 and @p rect as NULL.
+ - Specified window: Set @p windowId as a value other than 0. Each window has a @p windowId that is not 0.
+ - Specified region: Set @p windowId as 0 and @p rect not as NULL. In this case, you can share the specified region, for example by dragging the mouse or implementing your own logic.
+
+ @note The specified region is a region on the whole screen. Currently, sharing a specified region in a specific window is not supported.
+ *captureFreq* is the captured frame rate once the screen-sharing function is enabled. The mandatory value ranges between 1 fps and 15 fps.
+
+ @param windowId Sets the screen sharing area. See WindowIDType.
+ @param captureFreq (Mandatory) The captured frame rate. The value ranges between 1 fps and 15 fps.
+ @param rect Specifies the screen-sharing region. @p rect is valid when @p windowsId is set as 0. When @p rect is set as NULL, the whole screen is shared.
+ @param bitrate The captured bitrate.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int startScreenCapture(WindowIDType windowId, int captureFreq, const Rect *rect, int bitrate) = 0;
+
+ /** **DEPRECATED** Updates the screen capture region.
+
+ @param rect Specifies the required region inside the screen or window.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int updateScreenCaptureRegion(const Rect *rect) = 0;
+#endif
+
+ /** Retrieves the current call ID.
+
+ When a user joins a channel on a client, a @p callId is generated to identify the call from the client. Feedback methods, such as \ref IRtcEngine::rate "rate" and \ref IRtcEngine::complain "complain", must be called after the call ends to submit feedback to the SDK.
+
+ The \ref IRtcEngine::rate "rate" and \ref IRtcEngine::complain "complain" methods require the @p callId parameter retrieved from the *getCallId* method during a call. @p callId is passed as an argument into the \ref IRtcEngine::rate "rate" and \ref IRtcEngine::complain "complain" methods after the call ends.
+
+ @param callId Pointer to the current call ID.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getCallId(agora::util::AString& callId) = 0;
+
+ /** Allows a user to rate a call after the call ends.
+
+ @param callId Pointer to the ID of the call, retrieved from the \ref IRtcEngine::getCallId "getCallId" method.
+ @param rating Rating of the call. The value is between 1 (lowest score) and 5 (highest score). If you set a value out of this range, the #ERR_INVALID_ARGUMENT (2) error returns.
+ @param description (Optional) Pointer to the description of the rating, with a string length of less than 800 bytes.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int rate(const char* callId, int rating, const char* description) = 0;
+
+ /** Allows a user to complain about the call quality after a call ends.
+
+ @param callId Pointer to the ID of the call, retrieved from the \ref IRtcEngine::getCallId "getCallId" method.
+ @param description (Optional) Pointer to the description of the complaint, with a string length of less than 800 bytes.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+
+ */
+ virtual int complain(const char* callId, const char* description) = 0;
+
+ /** Retrieves the SDK version number.
+
+ @param build Pointer to the build number.
+ @return The version of the current SDK in the string format. For example, 2.3.1.
+ */
+ virtual const char* getVersion(int* build) = 0;
+
+ /** Enables the network connection quality test.
+
+ This method tests the quality of the users' network connections and is disabled by default.
+
+ Before a user joins a channel or before an audience switches to a host, call this method to check the uplink network quality.
+
+ This method consumes additional network traffic, and hence may affect communication quality.
+
+ Call the \ref IRtcEngine::disableLastmileTest "disableLastmileTest" method to disable this test after receiving the \ref IRtcEngineEventHandler::onLastmileQuality "onLastmileQuality" callback, and before joining a channel.
+
+ @note
+ - Do not call any other methods before receiving the \ref IRtcEngineEventHandler::onLastmileQuality "onLastmileQuality" callback. Otherwise, the callback may be interrupted by other methods, and hence may not be triggered.
+ - A host should not call this method after joining a channel (when in a call).
+ - If you call this method to test the last-mile quality, the SDK consumes the bandwidth of a video stream, whose bitrate corresponds to the bitrate you set in the \ref agora::rtc::IRtcEngine::setVideoEncoderConfiguration "setVideoEncoderConfiguration" method. After you join the channel, whether you have called the `disableLastmileTest` method or not, the SDK automatically stops consuming the bandwidth.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int enableLastmileTest() = 0;
+
+ /** Disables the network connection quality test.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int disableLastmileTest() = 0;
+
+ /** Starts the last-mile network probe test.
+
+ This method starts the last-mile network probe test before joining a channel to get the uplink and downlink last-mile network statistics, including the bandwidth, packet loss, jitter, and round-trip time (RTT).
+
+ Call this method to check the uplink network quality before users join a channel or before an audience switches to a host.
+ Once this method is enabled, the SDK returns the following callbacks:
+ - \ref IRtcEngineEventHandler::onLastmileQuality "onLastmileQuality": the SDK triggers this callback within two seconds depending on the network conditions. This callback rates the network conditions and is more closely linked to the user experience.
+ - \ref IRtcEngineEventHandler::onLastmileProbeResult "onLastmileProbeResult": the SDK triggers this callback within 30 seconds depending on the network conditions. This callback returns the real-time statistics of the network conditions and is more objective.
+
+ @note
+ - This method consumes extra network traffic and may affect communication quality. We do not recommend calling this method together with enableLastmileTest.
+ - Do not call other methods before receiving the \ref IRtcEngineEventHandler::onLastmileQuality "onLastmileQuality" and \ref IRtcEngineEventHandler::onLastmileProbeResult "onLastmileProbeResult" callbacks. Otherwise, the callbacks may be interrupted.
+ - In the Live-broadcast profile, a host should not call this method after joining a channel.
+
+ @param config Sets the configurations of the last-mile network probe test. See LastmileProbeConfig.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int startLastmileProbeTest(const LastmileProbeConfig& config) = 0;
+
+ /** Stops the last-mile network probe test. */
+ virtual int stopLastmileProbeTest() = 0;
+
+ /** Retrieves the warning or error description.
+
+ @param code Warning code or error code returned in the \ref agora::rtc::IRtcEngineEventHandler::onWarning "onWarning" or \ref agora::rtc::IRtcEngineEventHandler::onError "onError" callback.
+
+ @return #WARN_CODE_TYPE or #ERROR_CODE_TYPE.
+ */
+ virtual const char* getErrorDescription(int code) = 0;
+
+ /** Enables built-in encryption with an encryption password before users join a channel.
+
+ All users in a channel must use the same encryption password. The encryption password is automatically cleared once a user leaves the channel.
+
+ If an encryption password is not specified, the encryption functionality will be disabled.
+
+ @note
+ - Do not use this method for CDN live streaming.
+ - For optimal transmission, ensure that the encrypted data size does not exceed the original data size + 16 bytes. 16 bytes is the maximum padding size for AES encryption.
+
+ @param secret Pointer to the encryption password.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setEncryptionSecret(const char* secret) = 0;
+
+ /** Sets the built-in encryption mode.
+
+ The Agora SDK supports built-in encryption, which is set to the @p aes-128-xts mode by default. Call this method to use other encryption modes.
+
+ All users in the same channel must use the same encryption mode and password.
+
+ Refer to the information related to the AES encryption algorithm on the differences between the encryption modes.
+
+ @note Call the \ref IRtcEngine::setEncryptionSecret "setEncryptionSecret" method to enable the built-in encryption function before calling this method.
+
+ @param encryptionMode Pointer to the set encryption mode:
+ - "aes-128-xts": (Default) 128-bit AES encryption, XTS mode.
+ - "aes-128-ecb": 128-bit AES encryption, ECB mode.
+ - "aes-256-xts": 256-bit AES encryption, XTS mode.
+ - "": When encryptionMode is set as NULL, the encryption mode is set as "aes-128-xts" by default.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setEncryptionMode(const char* encryptionMode) = 0;
+
+ /** Registers a packet observer.
+
+ The Agora SDK allows your application to register a packet observer to receive callbacks for voice or video packet transmission.
+
+ @note
+ - The size of the packet sent to the network after processing should not exceed 1200 bytes, otherwise, the packet may fail to be sent.
+ - Ensure that both receivers and senders call this method, otherwise, you may meet undefined behaviors such as no voice and black screen.
+ - When you use CDN live streaming, recording or storage functions, Agora doesn't recommend calling this method.
+
+ @param observer Pointer to the registered packet observer. See IPacketObserver.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int registerPacketObserver(IPacketObserver* observer) = 0;
+
+ /** Creates a data stream.
+
+ Each user can create up to five data streams during the lifecycle of the IRtcEngine.
+
+ @note Set both the @p reliable and @p ordered parameters to true or false. Do not set one as true and the other as false.
+
+ @param streamId Pointer to the ID of the created data stream.
+ @param reliable Sets whether or not the recipients are guaranteed to receive the data stream from the sender within five seconds:
+ - true: The recipients receive the data stream from the sender within five seconds. If the recipient does not receive the data stream within five seconds, an error is reported to the application.
+ - false: There is no guarantee that the recipients receive the data stream within five seconds and no error message is reported for any delay or missing data stream.
+ @param ordered Sets whether or not the recipients receive the data stream in the sent order:
+ - true: The recipients receive the data stream in the sent order.
+ - false: The recipients do not receive the data stream in the sent order.
+
+ @return
+ - Returns 0: Success.
+ - < 0: Failure.
+ */
+ virtual int createDataStream(int* streamId, bool reliable, bool ordered) = 0;
+
+ /** Sends data stream messages to all users in a channel.
+
+ The SDK has the following restrictions on this method:
+ - Up to 30 packets can be sent per second in a channel with each packet having a maximum size of 1 kB.
+ - Each client can send up to 6 kB of data per second.
+ - Each user can have up to five data streams simultaneously.
+
+ A successful \ref agora::rtc::IRtcEngine::sendStreamMessage "sendStreamMessage" method call triggers the \ref agora::rtc::IRtcEngineEventHandler::onStreamMessage "onStreamMessage" callback on the remote client, from which the remote user gets the stream message.
+
+ A failed \ref agora::rtc::IRtcEngine::sendStreamMessage "sendStreamMessage" method call triggers the \ref agora::rtc::IRtcEngineEventHandler::onStreamMessageError "onStreamMessage" callback on the remote client.
+ @note This method applies only to the Communication profile or to the hosts in the Live-broadcast profile. If an audience in the Live-broadcast profile calls this method, the audience may be switched to a host.
+
+ @param streamId ID of the sent data stream, returned in the \ref IRtcEngine::createDataStream "createDataStream" method.
+ @param data Pointer to the sent data.
+ @param length Length of the sent data.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int sendStreamMessage(int streamId, const char* data, size_t length) = 0;
+
+ /** Publishes the local stream to a specified CDN live RTMP address. (CDN live only.)
+
+ The SDK returns the result of this method call in the \ref IRtcEngineEventHandler::onStreamPublished "onStreamPublished" callback.
+
+ The \ref agora::rtc::IRtcEngine::addPublishStreamUrl "addPublishStreamUrl" method call triggers the \ref agora::rtc::IRtcEngineEventHandler::onRtmpStreamingStateChanged "onRtmpStreamingStateChanged" callback on the local client to report the state of adding a local stream to the CDN.
+ @note
+ - Ensure that the user joins the channel before calling this method.
+ - Ensure that you enable the RTMP Converter service before using this function. See [Prerequisites](https://docs.agora.io/en/Interactive%20Broadcast/cdn_streaming_windows?platform=Windows#prerequisites).
+ - This method adds only one stream RTMP URL address each time it is called.
+ - This method applies to Live Broadcast only.
+
+ @param url The CDN streaming URL in the RTMP format. The maximum length of this parameter is 1024 bytes. The RTMP URL address must not contain special characters, such as Chinese language characters.
+ @param transcodingEnabled Sets whether transcoding is enabled/disabled:
+ - true: Enable transcoding. To [transcode](https://docs.agora.io/en/Agora%20Platform/terms?platform=All%20Platforms#transcoding) the audio or video streams when publishing them to CDN live, often used for combining the audio and video streams of multiple hosts in CDN live. If you set this parameter as `true`, ensure that you call the \ref IRtcEngine::setLiveTranscoding "setLiveTranscoding" method before this method.
+ - false: Disable transcoding.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ - #ERR_INVALID_ARGUMENT (2): The RTMP URL address is NULL or has a string length of 0.
+ - #ERR_NOT_INITIALIZED (7): You have not initialized the RTC engine when publishing the stream.
+ */
+ virtual int addPublishStreamUrl(const char *url, bool transcodingEnabled) = 0;
+
+ /** Removes an RTMP stream from the CDN. (CDN live only.)
+
+ This method removes the RTMP URL address (added by the \ref IRtcEngine::addPublishStreamUrl "addPublishStreamUrl" method) from a CDN live stream. The SDK returns the result of this method call in the \ref IRtcEngineEventHandler::onStreamUnpublished "onStreamUnpublished" callback.
+
+ The \ref agora::rtc::IRtcEngine::removePublishStreamUrl "removePublishStreamUrl" method call triggers the \ref agora::rtc::IRtcEngineEventHandler::onRtmpStreamingStateChanged "onRtmpStreamingStateChanged" callback on the local client to report the state of removing an RTMP stream from the CDN.
+ @note
+ - This method removes only one RTMP URL address each time it is called.
+ - The RTMP URL address must not contain special characters, such as Chinese language characters.
+ - This method applies to Live Broadcast only.
+
+ @param url The RTMP URL address to be removed. The maximum length of this parameter is 1024 bytes.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int removePublishStreamUrl(const char *url) = 0;
+
+ /** Sets the video layout and audio settings for CDN live. (CDN live only.)
+
+ The SDK triggers the \ref agora::rtc::IRtcEngineEventHandler::onTranscodingUpdated "onTranscodingUpdated" callback when you call the `setLiveTranscoding` method to update the transcoding setting.
+
+ @note
+ - This method applies to Live Broadcast only.
+ - Ensure that you enable the RTMP Converter service before using this function. See [Prerequisites](https://docs.agora.io/en/Interactive%20Broadcast/cdn_streaming_windows?platform=Windows#prerequisites).
+ - If you call the `setLiveTranscoding` method to update the transcoding setting for the first time, the SDK does not trigger the `onTranscodingUpdated` callback.
+
+ @param transcoding Sets the CDN live audio/video transcoding settings. See LiveTranscoding.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setLiveTranscoding(const LiveTranscoding &transcoding) = 0;
+
+ /** **DEPRECATED** Adds a watermark image to the local video or CDN live stream.
+
+ This method is deprecated from v2.9.1. Use \ref agora::rtc::IRtcEngine::addVideoWatermark(const char* watermarkUrl, const WatermarkOptions& options) "addVideoWatermark"2 instead.
+
+ This method adds a PNG watermark image to the local video stream for the recording device, channel audience, and CDN live audience to view and capture.
+
+ To add the PNG file to the CDN live publishing stream, see the \ref IRtcEngine::setLiveTranscoding "setLiveTranscoding" method.
+
+ @param watermark Pointer to the watermark image to be added to the local video stream. See RtcImage.
+
+ @note
+ - The URL descriptions are different for the local video and CDN live streams:
+ - In a local video stream, @p url in RtcImage refers to the absolute path of the added watermark image file in the local video stream.
+ - In a CDN live stream, @p url in RtcImage refers to the URL address of the added watermark image in the CDN live broadcast.
+ - The source file of the watermark image must be in the PNG file format. If the width and height of the PNG file differ from your settings in this method, the PNG file will be cropped to conform to your settings.
+ - The Agora SDK supports adding only one watermark image onto a local video or CDN live stream. The newly added watermark image replaces the previous one.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int addVideoWatermark(const RtcImage& watermark) = 0;
+
+ /** Adds a watermark image to the local video.
+
+ This method adds a PNG watermark image to the local video in a live broadcast. Once the watermark image is added, all the audience in the channel (CDN audience included),
+ and the recording device can see and capture it. Agora supports adding only one watermark image onto the local video, and the newly watermark image replaces the previous one.
+
+ The watermark position depends on the settings in the \ref IRtcEngine::setVideoEncoderConfiguration "setVideoEncoderConfiguration" method:
+ - If the orientation mode of the encoding video is #ORIENTATION_MODE_FIXED_LANDSCAPE, or the landscape mode in #ORIENTATION_MODE_ADAPTIVE, the watermark uses the landscape orientation.
+ - If the orientation mode of the encoding video is #ORIENTATION_MODE_FIXED_PORTRAIT, or the portrait mode in #ORIENTATION_MODE_ADAPTIVE, the watermark uses the portrait orientation.
+ - When setting the watermark position, the region must be less than the dimensions set in the `setVideoEncoderConfiguration` method. Otherwise, the watermark image will be cropped.
+
+ @note
+ - Ensure that you have called the \ref agora::rtc::IRtcEngine::enableVideo "enableVideo" method to enable the video module before calling this method.
+ - If you only want to add a watermark image to the local video for the audience in the CDN live broadcast channel to see and capture, you can call this method or the \ref agora::rtc::IRtcEngine::setLiveTranscoding "setLiveTranscoding" method.
+ - This method supports adding a watermark image in the PNG file format only. Supported pixel formats of the PNG image are RGBA, RGB, Palette, Gray, and Alpha_gray.
+ - If the dimensions of the PNG image differ from your settings in this method, the image will be cropped or zoomed to conform to your settings.
+ - If you have enabled the local video preview by calling the \ref agora::rtc::IRtcEngine::startPreview "startPreview" method, you can use the `visibleInPreview` member in the WatermarkOptions class to set whether or not the watermark is visible in preview.
+ - If you have mirrored the local video by calling the \ref agora::rtc::IRtcEngine::setupLocalVideo "setupLocalVideo" or \ref agora::rtc::IRtcEngine::setLocalRenderMode(RENDER_MODE_TYPE renderMode, VIDEO_MIRROR_MODE_TYPE mirrorMode) "setLocalRenderMode" method, the watermark image in preview is also mirrored.
+
+ @param watermarkUrl The local file path of the watermark image to be added. This method supports adding a watermark image from the local absolute or relative file path.
+ @param options Pointer to the watermark's options to be added. See WatermarkOptions for more infomation.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int addVideoWatermark(const char* watermarkUrl, const WatermarkOptions& options) = 0;
+
+ /** Removes the watermark image from the video stream added by the \ref agora::rtc::IRtcEngine::addVideoWatermark(const char* watermarkUrl, const WatermarkOptions& options) "addVideoWatermark" method.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int clearVideoWatermarks() = 0;
+
+ /** Enables/Disables image enhancement and sets the options.
+
+ @note
+ - Call this method after calling the enableVideo method.
+ - Currently this method does not apply for macOS.
+
+ @param enabled Sets whether or not to enable image enhancement:
+ - true: enables image enhancement.
+ - false: disables image enhancement.
+ @param options Sets the image enhancement option. See BeautyOptions.
+ */
+ virtual int setBeautyEffectOptions(bool enabled, BeautyOptions options) = 0;
+
+ /** Adds a voice or video stream URL address to a live broadcast.
+
+ The \ref IRtcEngineEventHandler::onStreamPublished "onStreamPublished" callback returns the inject status. If this method call is successful, the server pulls the voice or video stream and injects it into a live channel. This is applicable to scenarios where all audience members in the channel can watch a live show and interact with each other.
+
+ The \ref agora::rtc::IRtcEngine::addInjectStreamUrl "addInjectStreamUrl" method call triggers the following callbacks:
+ - The local client:
+ - \ref agora::rtc::IRtcEngineEventHandler::onStreamInjectedStatus "onStreamInjectedStatus" , with the state of the injecting the online stream.
+ - \ref agora::rtc::IRtcEngineEventHandler::onUserJoined "onUserJoined" (uid: 666), if the method call is successful and the online media stream is injected into the channel.
+ - The remote client:
+ - \ref agora::rtc::IRtcEngineEventHandler::onUserJoined "onUserJoined" (uid: 666), if the method call is successful and the online media stream is injected into the channel.
+
+ @note
+ - Ensure that you enable the RTMP Converter service before using this function. See [Prerequisites](https://docs.agora.io/en/Interactive%20Broadcast/cdn_streaming_windows?platform=Windows#prerequisites).
+ - This method applies to the Native SDK v2.4.1 and later.
+
+ @param url Pointer to the URL address to be added to the ongoing live broadcast. Valid protocols are RTMP, HLS, and FLV.
+ - Supported FLV audio codec type: AAC.
+ - Supported FLV video codec type: H264 (AVC).
+ @param config Pointer to the InjectStreamConfig object that contains the configuration of the added voice or video stream.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ - #ERR_INVALID_ARGUMENT (2): The injected URL does not exist. Call this method again to inject the stream and ensure that the URL is valid.
+ - #ERR_NOT_READY (3): The user is not in the channel.
+ - #ERR_NOT_SUPPORTED (4): The channel profile is not live broadcast. Call the \ref agora::rtc::IRtcEngine::setChannelProfile "setChannelProfile" method and set the channel profile to live broadcast before calling this method.
+ - #ERR_NOT_INITIALIZED (7): The SDK is not initialized. Ensure that the IRtcEngine object is initialized before calling this method.
+ */
+ virtual int addInjectStreamUrl(const char* url, const InjectStreamConfig& config) = 0;
+ /** Starts to relay media streams across channels.
+ *
+ * After a successful method call, the SDK triggers the
+ * \ref agora::rtc::IRtcEngineEventHandler::onChannelMediaRelayStateChanged
+ * "onChannelMediaRelayStateChanged" and
+ * \ref agora::rtc::IRtcEngineEventHandler::onChannelMediaRelayEvent
+ * "onChannelMediaRelayEvent" callbacks, and these callbacks return the
+ * state and events of the media stream relay.
+ * - If the
+ * \ref agora::rtc::IRtcEngineEventHandler::onChannelMediaRelayStateChanged
+ * "onChannelMediaRelayStateChanged" callback returns
+ * #RELAY_STATE_RUNNING (2) and #RELAY_OK (0), and the
+ * \ref agora::rtc::IRtcEngineEventHandler::onChannelMediaRelayEvent
+ * "onChannelMediaRelayEvent" callback returns
+ * #RELAY_EVENT_PACKET_SENT_TO_DEST_CHANNEL (4), the broadcaster starts
+ * sending data to the destination channel.
+ * - If the
+ * \ref agora::rtc::IRtcEngineEventHandler::onChannelMediaRelayStateChanged
+ * "onChannelMediaRelayStateChanged" callback returns
+ * #RELAY_STATE_FAILURE (3), an exception occurs during the media stream
+ * relay.
+ *
+ * @note
+ * - Call this method after the \ref joinChannel() "joinChannel" method.
+ * - This method takes effect only when you are a broadcaster in a
+ * Live-broadcast channel.
+ * - After a successful method call, if you want to call this method
+ * again, ensure that you call the
+ * \ref stopChannelMediaRelay() "stopChannelMediaRelay" method to quit the
+ * current relay.
+ * - Contact sales-us@agora.io before implementing this function.
+ * - We do not support string user accounts in this API.
+ *
+ * @param configuration The configuration of the media stream relay:
+ * ChannelMediaRelayConfiguration.
+ *
+ * @return
+ * - 0: Success.
+ * - < 0: Failure.
+ */
+ virtual int startChannelMediaRelay(const ChannelMediaRelayConfiguration &configuration) = 0;
+ /** Updates the channels for media stream relay. After a successful
+ * \ref startChannelMediaRelay() "startChannelMediaRelay" method call, if
+ * you want to relay the media stream to more channels, or leave the
+ * current relay channel, you can call the
+ * \ref updateChannelMediaRelay() "updateChannelMediaRelay" method.
+ *
+ * After a successful method call, the SDK triggers the
+ * \ref agora::rtc::IRtcEngineEventHandler::onChannelMediaRelayEvent
+ * "onChannelMediaRelayEvent" callback with the
+ * #RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL (7) state code.
+ *
+ * @note
+ * Call this method after the
+ * \ref startChannelMediaRelay() "startChannelMediaRelay" method to update
+ * the destination channel.
+ *
+ * @param configuration The media stream relay configuration:
+ * ChannelMediaRelayConfiguration.
+ *
+ * @return
+ * - 0: Success.
+ * - < 0: Failure.
+ */
+ virtual int updateChannelMediaRelay(const ChannelMediaRelayConfiguration &configuration) = 0;
+ /** Stops the media stream relay.
+ *
+ * Once the relay stops, the broadcaster quits all the destination
+ * channels.
+ *
+ * After a successful method call, the SDK triggers the
+ * \ref agora::rtc::IRtcEngineEventHandler::onChannelMediaRelayStateChanged
+ * "onChannelMediaRelayStateChanged" callback. If the callback returns
+ * #RELAY_STATE_IDLE (0) and #RELAY_OK (0), the broadcaster successfully
+ * stops the relay.
+ *
+ * @note
+ * If the method call fails, the SDK triggers the
+ * \ref agora::rtc::IRtcEngineEventHandler::onChannelMediaRelayStateChanged
+ * "onChannelMediaRelayStateChanged" callback with the
+ * #RELAY_ERROR_SERVER_NO_RESPONSE (2) or
+ * #RELAY_ERROR_SERVER_CONNECTION_LOST (8) state code. You can leave the
+ * channel by calling the \ref leaveChannel() "leaveChannel" method, and
+ * the media stream relay automatically stops.
+ *
+ * @return
+ * - 0: Success.
+ * - < 0: Failure.
+ */
+ virtual int stopChannelMediaRelay() = 0;
+
+ /** Removes the voice or video stream URL address from a live broadcast.
+
+ This method removes the URL address (added by the \ref IRtcEngine::addInjectStreamUrl "addInjectStreamUrl" method) from the live broadcast.
+
+ @note If this method is called successfully, the SDK triggers the \ref IRtcEngineEventHandler::onUserOffline "onUserOffline" callback and returns a stream uid of 666.
+
+ @param url Pointer to the URL address of the added stream to be removed.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int removeInjectStreamUrl(const char* url) = 0;
+ virtual bool registerEventHandler(IRtcEngineEventHandler *eventHandler) = 0;
+ virtual bool unregisterEventHandler(IRtcEngineEventHandler *eventHandler) = 0;
+ /** Gets the current connection state of the SDK.
+
+ @return #CONNECTION_STATE_TYPE.
+ */
+ virtual CONNECTION_STATE_TYPE getConnectionState() = 0;
+
+ /** Registers the metadata observer.
+
+ Registers the metadata observer. You need to implement the IMetadataObserver class and specify the metadata type in this method. A successful call of this method triggers the \ref agora::rtc::IMetadataObserver::getMaxMetadataSize "getMaxMetadataSize" callback.
+ This method enables you to add synchronized metadata in the video stream for more diversified live broadcast interactions, such as sending shopping links, digital coupons, and online quizzes.
+
+ @note
+ - Call this method before the joinChannel method.
+ - This method applies to the Live-broadcast channel profile.
+
+ @param observer The IMetadataObserver class. See the definition of IMetadataObserver for details.
+ @param type See \ref IMetadataObserver::METADATA_TYPE "METADATA_TYPE". The SDK supports VIDEO_METADATA (0) only for now.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int registerMediaMetadataObserver(IMetadataObserver *observer, IMetadataObserver::METADATA_TYPE type) = 0;
+ /** Provides technical preview functionalities or special customizations by configuring the SDK with JSON options.
+
+ The JSON options are not public by default. Agora is working on making commonly used JSON options public in a standard way.
+
+ @param parameters Sets the parameter as a JSON string in the specified format.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setParameters(const char* parameters) = 0;
+};
+
+
+class IRtcEngineParameter
+{
+public:
+ /**
+ * Releases all IRtcEngineParameter resources.
+ */
+ virtual void release() = 0;
+
+ /** Sets the bool value of a specified key in the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Sets the value.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setBool(const char* key, bool value) = 0;
+
+ /** Sets the int value of a specified key in the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Sets the value.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setInt(const char* key, int value) = 0;
+
+ /** Sets the unsigned int value of a specified key in the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Sets the value.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setUInt(const char* key, unsigned int value) = 0;
+
+ /** Sets the double value of a specified key in the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Sets the value.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setNumber(const char* key, double value) = 0;
+
+ /** Sets the string value of a specified key in the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Pointer to the set value.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setString(const char* key, const char* value) = 0;
+
+ /** Sets the object value of a specified key in the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Pointer to the set value.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setObject(const char* key, const char* value) = 0;
+
+ /** Retrieves the bool value of a specified key in the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Pointer to the retrieved value.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getBool(const char* key, bool& value) = 0;
+
+ /** Retrieves the int value of the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Pointer to the retrieved value.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getInt(const char* key, int& value) = 0;
+
+ /** Retrieves the unsigned int value of a specified key in the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Pointer to the retrieved value.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getUInt(const char* key, unsigned int& value) = 0;
+
+ /** Retrieves the double value of a specified key in the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Pointer to the retrieved value.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getNumber(const char* key, double& value) = 0;
+
+ /** Retrieves the string value of a specified key in the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Pointer to the retrieved value.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getString(const char* key, agora::util::AString& value) = 0;
+
+ /** Retrieves a child object value of a specified key in the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Pointer to the retrieved value.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getObject(const char* key, agora::util::AString& value) = 0;
+
+ /** Retrieves the array value of a specified key in the JSON format.
+
+ @param key Pointer to the name of the key.
+ @param value Pointer to the retrieved value.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int getArray(const char* key, agora::util::AString& value) = 0;
+
+ /** Provides the technical preview functionalities or special customizations by configuring the SDK with JSON options.
+
+ @param parameters Pointer to the set parameters in a JSON string.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setParameters(const char* parameters) = 0;
+
+ /** Sets the profile to control the RTC engine.
+
+ @param profile Pointer to the set profile.
+ @param merge Sets whether to merge the profile data with the original value:
+ - true: Merge the profile data with the original value.
+ - false: Do not merge the profile data with the original value.
+
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int setProfile(const char* profile, bool merge) = 0;
+
+ virtual int convertPath(const char* filePath, agora::util::AString& value) = 0;
+};
+
+class AAudioDeviceManager : public agora::util::AutoPtr
+{
+public:
+ AAudioDeviceManager(IRtcEngine* engine)
+ {
+ queryInterface(engine, AGORA_IID_AUDIO_DEVICE_MANAGER);
+ }
+};
+
+class AVideoDeviceManager : public agora::util::AutoPtr
+{
+public:
+ AVideoDeviceManager(IRtcEngine* engine)
+ {
+ queryInterface(engine, AGORA_IID_VIDEO_DEVICE_MANAGER);
+ }
+};
+
+class AParameter : public agora::util::AutoPtr
+{
+public:
+ AParameter(IRtcEngine& engine) { initialize(&engine); }
+ AParameter(IRtcEngine* engine) { initialize(engine); }
+ AParameter(IRtcEngineParameter* p) :agora::util::AutoPtr(p) {}
+private:
+ bool initialize(IRtcEngine* engine)
+ {
+ IRtcEngineParameter* p = NULL;
+ if (engine && !engine->queryInterface(AGORA_IID_RTC_ENGINE_PARAMETER, (void**)&p))
+ reset(p);
+ return p != NULL;
+ }
+};
+/** **DEPRECATED** The RtcEngineParameters class is deprecated, use the IRtcEngine class instead.
+*/
+class RtcEngineParameters
+{
+public:
+ RtcEngineParameters(IRtcEngine& engine)
+ :m_parameter(&engine){}
+ RtcEngineParameters(IRtcEngine* engine)
+ :m_parameter(engine){}
+
+
+ int enableLocalVideo(bool enabled) {
+ return setParameters("{\"rtc.video.capture\":%s,\"che.video.local.capture\":%s,\"che.video.local.render\":%s,\"che.video.local.send\":%s}", enabled ? "true" : "false", enabled ? "true" : "false", enabled ? "true" : "false", enabled ? "true" : "false");
+ }
+
+
+
+ int muteLocalVideoStream(bool mute) {
+ return setParameters("{\"rtc.video.mute_me\":%s,\"che.video.local.send\":%s}", mute ? "true" : "false", mute ? "false" : "true");
+ }
+
+
+ int muteAllRemoteVideoStreams(bool mute) {
+ return m_parameter ? m_parameter->setBool("rtc.video.mute_peers", mute) : -ERR_NOT_INITIALIZED;
+ }
+
+
+
+ int setDefaultMuteAllRemoteVideoStreams(bool mute) {
+ return m_parameter ? m_parameter->setBool("rtc.video.set_default_mute_peers", mute) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int muteRemoteVideoStream(uid_t uid, bool mute) {
+ return setObject("rtc.video.mute_peer", "{\"uid\":%u,\"mute\":%s}", uid, mute ? "true" : "false");
+ }
+
+
+ int setPlaybackDeviceVolume(int volume) {// [0,255]
+ return m_parameter ? m_parameter->setInt("che.audio.output.volume", volume) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int startAudioRecording(const char* filePath, AUDIO_RECORDING_QUALITY_TYPE quality) {
+ return startAudioRecording(filePath, 32000, quality);
+ }
+
+ int startAudioRecording(const char* filePath, int sampleRate, AUDIO_RECORDING_QUALITY_TYPE quality) {
+ if (!m_parameter) return -ERR_NOT_INITIALIZED;
+#if defined(_WIN32)
+ util::AString path;
+ if (!m_parameter->convertPath(filePath, path))
+ filePath = path->c_str();
+ else
+ return -ERR_INVALID_ARGUMENT;
+#endif
+ return setObject("che.audio.start_recording", "{\"filePath\":\"%s\",\"sampleRate\":%d,\"quality\":%d}", filePath, sampleRate, quality);
+ }
+
+
+ int stopAudioRecording() {
+ return m_parameter ? m_parameter->setBool("che.audio.stop_recording", true) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int startAudioMixing(const char* filePath, bool loopback, bool replace, int cycle) {
+ if (!m_parameter) return -ERR_NOT_INITIALIZED;
+#if defined(_WIN32)
+ util::AString path;
+ if (!m_parameter->convertPath(filePath, path))
+ filePath = path->c_str();
+ else
+ return -ERR_INVALID_ARGUMENT;
+#endif
+ return setObject("che.audio.start_file_as_playout", "{\"filePath\":\"%s\",\"loopback\":%s,\"replace\":%s,\"cycle\":%d}",
+ filePath,
+ loopback?"true":"false",
+ replace?"true":"false",
+ cycle);
+ }
+
+
+ int stopAudioMixing() {
+ return m_parameter ? m_parameter->setBool("che.audio.stop_file_as_playout", true) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int pauseAudioMixing() {
+ return m_parameter ? m_parameter->setBool("che.audio.pause_file_as_playout", true) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int resumeAudioMixing() {
+ return m_parameter ? m_parameter->setBool("che.audio.pause_file_as_playout", false) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int adjustAudioMixingVolume(int volume) {
+ int ret = adjustAudioMixingPlayoutVolume(volume);
+ if (ret == 0) {
+ adjustAudioMixingPublishVolume(volume);
+ }
+ return ret;
+ }
+
+
+ int adjustAudioMixingPlayoutVolume(int volume) {
+ return m_parameter ? m_parameter->setInt("che.audio.set_file_as_playout_volume", volume) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int getAudioMixingPlayoutVolume() {
+ int volume = 0;
+ int r = m_parameter ? m_parameter->getInt("che.audio.get_file_as_playout_volume", volume) : -ERR_NOT_INITIALIZED;
+ if (r == 0)
+ r = volume;
+ return r;
+ }
+
+
+ int adjustAudioMixingPublishVolume(int volume) {
+ return m_parameter ? m_parameter->setInt("che.audio.set_file_as_playout_publish_volume", volume) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int getAudioMixingPublishVolume() {
+ int volume = 0;
+ int r = m_parameter ? m_parameter->getInt("che.audio.get_file_as_playout_publish_volume", volume) : -ERR_NOT_INITIALIZED;
+ if (r == 0)
+ r = volume;
+ return r;
+ }
+
+
+ int getAudioMixingDuration() {
+ int duration = 0;
+ int r = m_parameter ? m_parameter->getInt("che.audio.get_mixing_file_length_ms", duration) : -ERR_NOT_INITIALIZED;
+ if (r == 0)
+ r = duration;
+ return r;
+ }
+
+
+ int getAudioMixingCurrentPosition() {
+ if (!m_parameter) return -ERR_NOT_INITIALIZED;
+ int pos = 0;
+ int r = m_parameter->getInt("che.audio.get_mixing_file_played_ms", pos);
+ if (r == 0)
+ r = pos;
+ return r;
+ }
+
+ int setAudioMixingPosition(int pos /*in ms*/) {
+ return m_parameter ? m_parameter->setInt("che.audio.mixing.file.position", pos) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int getEffectsVolume() {
+ if (!m_parameter) return -ERR_NOT_INITIALIZED;
+ int volume = 0;
+ int r = m_parameter->getInt("che.audio.game_get_effects_volume", volume);
+ if (r == 0)
+ r = volume;
+ return r;
+ }
+
+
+ int setEffectsVolume(int volume) {
+ return m_parameter ? m_parameter->setInt("che.audio.game_set_effects_volume", volume) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int setVolumeOfEffect(int soundId, int volume) {
+ return setObject(
+ "che.audio.game_adjust_effect_volume",
+ "{\"soundId\":%d,\"gain\":%d}",
+ soundId, volume);
+ }
+
+
+ int playEffect(int soundId, const char* filePath, int loopCount, double pitch, double pan, int gain, bool publish = false) {
+#if defined(_WIN32)
+ util::AString path;
+ if (!m_parameter->convertPath(filePath, path))
+ filePath = path->c_str();
+ else if (!filePath)
+ filePath = "";
+#endif
+ return setObject(
+ "che.audio.game_play_effect",
+ "{\"soundId\":%d,\"filePath\":\"%s\",\"loopCount\":%d, \"pitch\":%lf,\"pan\":%lf,\"gain\":%d, \"send2far\":%d}",
+ soundId, filePath, loopCount, pitch, pan, gain, publish);
+ }
+
+
+ int stopEffect(int soundId) {
+ return m_parameter ? m_parameter->setInt(
+ "che.audio.game_stop_effect", soundId) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int stopAllEffects() {
+ return m_parameter ? m_parameter->setBool(
+ "che.audio.game_stop_all_effects", true) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int preloadEffect(int soundId, char* filePath) {
+ return setObject(
+ "che.audio.game_preload_effect",
+ "{\"soundId\":%d,\"filePath\":\"%s\"}",
+ soundId, filePath);
+ }
+
+
+ int unloadEffect(int soundId) {
+ return m_parameter ? m_parameter->setInt(
+ "che.audio.game_unload_effect", soundId) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int pauseEffect(int soundId) {
+ return m_parameter ? m_parameter->setInt(
+ "che.audio.game_pause_effect", soundId) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int pauseAllEffects() {
+ return m_parameter ? m_parameter->setBool(
+ "che.audio.game_pause_all_effects", true) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int resumeEffect(int soundId) {
+ return m_parameter ? m_parameter->setInt(
+ "che.audio.game_resume_effect", soundId) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int resumeAllEffects() {
+ return m_parameter ? m_parameter->setBool(
+ "che.audio.game_resume_all_effects", true) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int enableSoundPositionIndication(bool enabled) {
+ return m_parameter ? m_parameter->setBool(
+ "che.audio.enable_sound_position", enabled) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int setRemoteVoicePosition(uid_t uid, double pan, double gain) {
+ return setObject("che.audio.game_place_sound_position", "{\"uid\":%u,\"pan\":%lf,\"gain\":%lf}", uid, pan, gain);
+ }
+
+
+ int setLocalVoicePitch(double pitch) {
+ return m_parameter ? m_parameter->setInt(
+ "che.audio.morph.pitch_shift",
+ static_cast(pitch * 100)) : -ERR_NOT_INITIALIZED;
+ }
+
+ int setLocalVoiceEqualization(AUDIO_EQUALIZATION_BAND_FREQUENCY bandFrequency, int bandGain) {
+ return setObject(
+ "che.audio.morph.equalization",
+ "{\"index\":%d,\"gain\":%d}",
+ static_cast(bandFrequency), bandGain);
+ }
+
+ int setLocalVoiceReverb(AUDIO_REVERB_TYPE reverbKey, int value) {
+ return setObject(
+ "che.audio.morph.reverb",
+ "{\"key\":%d,\"value\":%d}",
+ static_cast(reverbKey), value);
+ }
+
+
+ int setLocalVoiceChanger(VOICE_CHANGER_PRESET voiceChanger) {
+ return m_parameter ? m_parameter->setInt("che.audio.morph.voice_changer", static_cast(voiceChanger)) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int setLocalVoiceReverbPreset(AUDIO_REVERB_PRESET reverbPreset) {
+ return m_parameter ? m_parameter->setInt("che.audio.morph.reverb_preset", static_cast(reverbPreset)) : -ERR_NOT_INITIALIZED;
+ }
+
+
+
+ int pauseAudio() {
+ return m_parameter ? m_parameter->setBool("che.pause.audio", true) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int resumeAudio() {
+ return m_parameter ? m_parameter->setBool("che.pause.audio", false) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int setHighQualityAudioParameters(bool fullband, bool stereo, bool fullBitrate) {
+ return setObject("che.audio.codec.hq", "{\"fullband\":%s,\"stereo\":%s,\"fullBitrate\":%s}", fullband ? "true" : "false", stereo ? "true" : "false", fullBitrate ? "true" : "false");
+ }
+
+
+ int adjustRecordingSignalVolume(int volume) {//[0, 400]: e.g. 50~0.5x 100~1x 400~4x
+ if (volume < 0)
+ volume = 0;
+ else if (volume > 400)
+ volume = 400;
+ return m_parameter ? m_parameter->setInt("che.audio.record.signal.volume", volume) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int adjustPlaybackSignalVolume(int volume) {//[0, 400]
+ if (volume < 0)
+ volume = 0;
+ else if (volume > 400)
+ volume = 400;
+ return m_parameter ? m_parameter->setInt("che.audio.playout.signal.volume", volume) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int enableAudioVolumeIndication(int interval, int smooth, bool report_vad) { // in ms: <= 0: disable, > 0: enable, interval in ms
+ if (interval < 0)
+ interval = 0;
+ return setObject("che.audio.volume_indication", "{\"interval\":%d,\"smooth\":%d,\"vad\":%d}", interval, smooth, report_vad);
+ }
+
+
+ int muteLocalAudioStream(bool mute) {
+ return setParameters("{\"rtc.audio.mute_me\":%s,\"che.audio.mute_me\":%s}", mute ? "true" : "false", mute ? "true" : "false");
+ }
+ // mute/unmute all peers. unmute will clear all muted peers specified mutePeer() interface
+
+
+ int muteRemoteAudioStream(uid_t uid, bool mute) {
+ return setObject("rtc.audio.mute_peer", "{\"uid\":%u,\"mute\":%s}", uid, mute?"true":"false");
+ }
+
+
+ int muteAllRemoteAudioStreams(bool mute) {
+ return m_parameter ? m_parameter->setBool("rtc.audio.mute_peers", mute) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int setDefaultMuteAllRemoteAudioStreams(bool mute) {
+ return m_parameter ? m_parameter->setBool("rtc.audio.set_default_mute_peers", mute) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int setExternalAudioSource(bool enabled, int sampleRate, int channels) {
+ if (enabled)
+ return setParameters("{\"che.audio.external_capture\":true,\"che.audio.external_capture.push\":true,\"che.audio.set_capture_raw_audio_format\":{\"sampleRate\":%d,\"channelCnt\":%d,\"mode\":%d}}", sampleRate, channels, RAW_AUDIO_FRAME_OP_MODE_TYPE::RAW_AUDIO_FRAME_OP_MODE_READ_WRITE);
+ else
+ return setParameters("{\"che.audio.external_capture\":false,\"che.audio.external_capture.push\":false}");
+ }
+
+
+ int setExternalAudioSink(bool enabled, int sampleRate, int channels) {
+ if (enabled)
+ return setParameters("{\"che.audio.external_render\":true,\"che.audio.external_render.pull\":true,\"che.audio.set_render_raw_audio_format\":{\"sampleRate\":%d,\"channelCnt\":%d,\"mode\":%d}}", sampleRate, channels, RAW_AUDIO_FRAME_OP_MODE_TYPE::RAW_AUDIO_FRAME_OP_MODE_READ_ONLY);
+ else
+ return setParameters("{\"che.audio.external_render\":false,\"che.audio.external_render.pull\":false}");
+ }
+
+
+ int setLogFile(const char* filePath) {
+ if (!m_parameter) return -ERR_NOT_INITIALIZED;
+#if defined(_WIN32)
+ util::AString path;
+ if (!m_parameter->convertPath(filePath, path))
+ filePath = path->c_str();
+ else if (!filePath)
+ filePath = "";
+#endif
+ return m_parameter->setString("rtc.log_file", filePath);
+ }
+
+
+ int setLogFilter(unsigned int filter) {
+ return m_parameter ? m_parameter->setUInt("rtc.log_filter", filter&LOG_FILTER_MASK) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int setLogFileSize(unsigned int fileSizeInKBytes) {
+ return m_parameter ? m_parameter->setUInt("rtc.log_size", fileSizeInKBytes) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int setLocalRenderMode(RENDER_MODE_TYPE renderMode) {
+ return setRemoteRenderMode(0, renderMode);
+ }
+
+
+ int setRemoteRenderMode(uid_t uid, RENDER_MODE_TYPE renderMode) {
+ return setObject("che.video.render_mode", "{\"uid\":%u,\"renderMode\":%d}", uid, renderMode);
+ }
+
+
+ int setCameraCapturerConfiguration(const CameraCapturerConfiguration& config) {
+ if (!m_parameter) return -ERR_NOT_INITIALIZED;
+ return m_parameter->setInt("che.video.camera_capture_mode", (int)config.preference);
+ }
+
+
+ int enableDualStreamMode(bool enabled) {
+ return setParameters("{\"rtc.dual_stream_mode\":%s,\"che.video.enableLowBitRateStream\":%d}", enabled ? "true" : "false", enabled ? 1 : 0);
+ }
+
+
+ int setRemoteVideoStreamType(uid_t uid, REMOTE_VIDEO_STREAM_TYPE streamType) {
+ return setParameters("{\"rtc.video.set_remote_video_stream\":{\"uid\":%u,\"stream\":%d}, \"che.video.setstream\":{\"uid\":%u,\"stream\":%d}}", uid, streamType, uid, streamType);
+// return setObject("rtc.video.set_remote_video_stream", "{\"uid\":%u,\"stream\":%d}", uid, streamType);
+ }
+
+
+ int setRemoteDefaultVideoStreamType(REMOTE_VIDEO_STREAM_TYPE streamType) {
+ return m_parameter ? m_parameter->setInt("rtc.video.set_remote_default_video_stream_type", streamType) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int setRecordingAudioFrameParameters(int sampleRate, int channel, RAW_AUDIO_FRAME_OP_MODE_TYPE mode, int samplesPerCall) {
+ return setObject("che.audio.set_capture_raw_audio_format", "{\"sampleRate\":%d,\"channelCnt\":%d,\"mode\":%d,\"samplesPerCall\":%d}", sampleRate, channel, mode, samplesPerCall);
+ }
+
+ int setPlaybackAudioFrameParameters(int sampleRate, int channel, RAW_AUDIO_FRAME_OP_MODE_TYPE mode, int samplesPerCall) {
+ return setObject("che.audio.set_render_raw_audio_format", "{\"sampleRate\":%d,\"channelCnt\":%d,\"mode\":%d,\"samplesPerCall\":%d}", sampleRate, channel, mode, samplesPerCall);
+ }
+
+ int setMixedAudioFrameParameters(int sampleRate, int samplesPerCall) {
+ return setObject("che.audio.set_mixed_raw_audio_format", "{\"sampleRate\":%d,\"samplesPerCall\":%d}", sampleRate, samplesPerCall);
+ }
+
+
+ int enableWebSdkInteroperability(bool enabled) {//enable interoperability with zero-plugin web sdk
+ return setParameters("{\"rtc.video.web_h264_interop_enable\":%s,\"che.video.web_h264_interop_enable\":%s}", enabled ? "true" : "false", enabled ? "true" : "false");
+ }
+
+ //only for live broadcast
+
+ int setVideoQualityParameters(bool preferFrameRateOverImageQuality) {
+ return setParameters("{\"rtc.video.prefer_frame_rate\":%s,\"che.video.prefer_frame_rate\":%s}", preferFrameRateOverImageQuality ? "true" : "false", preferFrameRateOverImageQuality ? "true" : "false");
+ }
+
+
+ int setLocalVideoMirrorMode(VIDEO_MIRROR_MODE_TYPE mirrorMode) {
+ if (!m_parameter) return -ERR_NOT_INITIALIZED;
+ const char *value;
+ switch (mirrorMode) {
+ case VIDEO_MIRROR_MODE_AUTO:
+ value = "default";
+ break;
+ case VIDEO_MIRROR_MODE_ENABLED:
+ value = "forceMirror";
+ break;
+ case VIDEO_MIRROR_MODE_DISABLED:
+ value = "disableMirror";
+ break;
+ default:
+ return -ERR_INVALID_ARGUMENT;
+ }
+ return m_parameter->setString("che.video.localViewMirrorSetting", value);
+ }
+
+
+ int setLocalPublishFallbackOption(STREAM_FALLBACK_OPTIONS option) {
+ return m_parameter ? m_parameter->setInt("rtc.local_publish_fallback_option", option) : -ERR_NOT_INITIALIZED;
+ }
+
+
+ int setRemoteSubscribeFallbackOption(STREAM_FALLBACK_OPTIONS option) {
+ return m_parameter ? m_parameter->setInt("rtc.remote_subscribe_fallback_option", option) : -ERR_NOT_INITIALIZED;
+ }
+
+#if (defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE) || defined(_WIN32)
+
+ int enableLoopbackRecording(bool enabled, const char* deviceName = NULL) {
+ if (!deviceName) {
+ return setParameters("{\"che.audio.loopback.recording\":%s}", enabled ? "true" : "false");
+ }
+ else {
+ return setParameters("{\"che.audio.loopback.deviceName\":\"%s\",\"che.audio.loopback.recording\":%s}", deviceName, enabled ? "true" : "false");
+ }
+ }
+#endif
+
+
+ int setInEarMonitoringVolume(int volume) {
+ return m_parameter ? m_parameter->setInt("che.audio.headset.monitoring.parameter", volume) : -ERR_NOT_INITIALIZED;
+ }
+
+protected:
+ AParameter& parameter() {
+ return m_parameter;
+ }
+ int setParameters(const char* format, ...) {
+ char buf[512];
+ va_list args;
+ va_start(args, format);
+ vsnprintf(buf, sizeof(buf)-1, format, args);
+ va_end(args);
+ return m_parameter ? m_parameter->setParameters(buf) : -ERR_NOT_INITIALIZED;
+ }
+ int setObject(const char* key, const char* format, ...) {
+ char buf[512];
+ va_list args;
+ va_start(args, format);
+ vsnprintf(buf, sizeof(buf)-1, format, args);
+ va_end(args);
+ return m_parameter ? m_parameter->setObject(key, buf) : -ERR_NOT_INITIALIZED;
+ }
+ int stopAllRemoteVideo() {
+ return m_parameter ? m_parameter->setBool("che.video.peer.stop_render", true) : -ERR_NOT_INITIALIZED;
+ }
+private:
+ AParameter m_parameter;
+};
+
+} //namespace rtc
+} // namespace agora
+
+
+#define getAgoraRtcEngineVersion getAgoraSdkVersion
+
+////////////////////////////////////////////////////////
+/** \addtogroup createAgoraRtcEngine
+ @{
+ */
+////////////////////////////////////////////////////////
+
+/** Creates the IRtcEngine object and returns the pointer.
+ *
+ * @return Pointer to the IRtcEngine object.
+ */
+AGORA_API agora::rtc::IRtcEngine* AGORA_CALL createAgoraRtcEngine();
+
+////////////////////////////////////////////////////////
+/** @} */
+////////////////////////////////////////////////////////
+
+#define getAgoraRtcEngineErrorDescription getAgoraSdkErrorDescription
+#define setAgoraRtcEngineExternalSymbolLoader setAgoraSdkExternalSymbolLoader
+
+#endif
diff --git a/Android/APIExample/lib-raw-data/src/main/cpp/include/IAgoraService.h b/Android/APIExample/lib-raw-data/src/main/cpp/include/IAgoraService.h
new file mode 100644
index 000000000..a607ed311
--- /dev/null
+++ b/Android/APIExample/lib-raw-data/src/main/cpp/include/IAgoraService.h
@@ -0,0 +1,76 @@
+// Agora SDK
+//
+// Copyright (c) 2019 Agora.io. All rights reserved.
+//
+
+#ifndef AGORA_SERVICE_H
+#define AGORA_SERVICE_H
+#include "AgoraBase.h"
+
+namespace agora {
+ namespace rtc {
+ class IRtcEngine;
+ }
+ namespace rtm {
+ class IRtmService;
+ }
+namespace base {
+
+struct AgoraServiceContext
+{
+};
+
+
+class IAgoraService
+{
+protected:
+ virtual ~IAgoraService(){}
+public:
+ virtual void release() = 0;
+
+ /** Initializes the engine.
+
+ @param context RtcEngine context.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+ */
+ virtual int initialize(const AgoraServiceContext& context) = 0;
+
+ /** Retrieves the SDK version number.
+ * @param build Build number.
+ * @return The current SDK version in the string format. For example, 2.4.0
+ */
+ virtual const char* getVersion(int* build) = 0;
+
+ virtual rtm::IRtmService* createRtmService() = 0;
+};
+
+} //namespace base
+} // namespace agora
+
+/** Gets the SDK version number.
+
+ @param build Build number of the Agora SDK.
+ @return
+ - 0: Success.
+ - < 0: Failure.
+*/
+AGORA_API const char* AGORA_CALL getAgoraSdkVersion(int* build);
+
+/**
+* Creates the RtcEngine object and returns the pointer.
+* @param err Error code
+* @return returns Description of the error code
+*/
+AGORA_API const char* AGORA_CALL getAgoraSdkErrorDescription(int err);
+
+/**
+* Creates the Agora Service object and returns the pointer.
+* @return returns Pointer of the Agora Service object
+*/
+AGORA_API agora::base::IAgoraService* AGORA_CALL createAgoraService();
+
+AGORA_API int AGORA_CALL setAgoraSdkExternalSymbolLoader(void* (*func)(const char* symname));
+
+#endif
diff --git a/Android/APIExample/lib-raw-data/src/main/cpp/include/VMUtil.h b/Android/APIExample/lib-raw-data/src/main/cpp/include/VMUtil.h
new file mode 100644
index 000000000..f414b5f74
--- /dev/null
+++ b/Android/APIExample/lib-raw-data/src/main/cpp/include/VMUtil.h
@@ -0,0 +1,52 @@
+#ifndef __VM_UTIL_H__
+#define __VM_UTIL_H__
+
+#include
+#include
+
+#include
+
+#include
+#include
+
+#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "AG_EX_AV", __VA_ARGS__)
+#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "AG_EX_AV", __VA_ARGS__)
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "AG_EX_AV", __VA_ARGS__)
+#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "AG_EX_AV", __VA_ARGS__)
+
+#define TRUE true
+#define FALSE false
+
+#define CHECK_POINTER(pValue, rValue, ...) if (NULL == pValue) { \
+ LOGE(__VA_ARGS__); \
+ return rValue; }
+
+class AttachThreadScoped {
+public:
+ explicit AttachThreadScoped(JavaVM *jvm)
+ : attached_(false), jvm_(jvm), env_(nullptr) {
+ jint ret_val = jvm->GetEnv(reinterpret_cast(&env_),
+ JNI_VERSION_1_6);
+ if (ret_val == JNI_EDETACHED) {
+ // Attach the thread to the Java VM.
+ ret_val = jvm_->AttachCurrentThread(&env_, nullptr);
+ attached_ = ret_val >= 0;
+ assert(attached_);
+ }
+ }
+
+ ~AttachThreadScoped() {
+ if (attached_ && (jvm_->DetachCurrentThread() < 0)) {
+ assert(false);
+ }
+ }
+
+ JNIEnv *env() { return env_; }
+
+private:
+ bool attached_;
+ JavaVM *jvm_;
+ JNIEnv *env_;
+};
+
+#endif // __VM_UTIL_H__
diff --git a/Android/APIExample/lib-raw-data/src/main/cpp/io_agora_advancedvideo_rawdata_MediaPreProcessing.cpp b/Android/APIExample/lib-raw-data/src/main/cpp/io_agora_advancedvideo_rawdata_MediaPreProcessing.cpp
new file mode 100644
index 000000000..0578e45fc
--- /dev/null
+++ b/Android/APIExample/lib-raw-data/src/main/cpp/io_agora_advancedvideo_rawdata_MediaPreProcessing.cpp
@@ -0,0 +1,464 @@
+#include
+#include
+#include
+#include "include/IAgoraMediaEngine.h"
+
+#include "include/IAgoraRtcEngine.h"
+#include
+#include "io_agora_advancedvideo_rawdata_MediaPreProcessing.h"
+#include "include/VMUtil.h"
+
+#include