Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support native 4.3.1 #1168

Merged
merged 20 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build/
js/
types/
ts/Private/ti/
native/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,5 @@ js/
docs/
types/
iris/
native/
appId.*
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ file(GLOB TARGET_AGORA_NODE_EXT_FILE
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(AGORA_IRIS_PROJECT_ARCH "MAC")
set(AGORA_RTC_SDK_PATH
${CMAKE_CURRENT_SOURCE_DIR}/iris/DCG/Agora_Native_SDK_for_Mac_FULL/libs
${CMAKE_CURRENT_SOURCE_DIR}/native/Agora_Native_SDK_for_Mac_FULL/libs
)
# native rtc sdk library
set(AGORA_RTC_SDK_LIBRARY
${AGORA_RTC_SDK_PATH}/*.framework
${AGORA_RTC_SDK_PATH}/*.xcframework/macos-arm64_x86_64/*.framework
)

# iris sdk path
Expand Down Expand Up @@ -98,7 +98,7 @@ elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")

# native rtc sdk path
set(AGORA_RTC_SDK_PATH
${CMAKE_CURRENT_SOURCE_DIR}/iris/DCG)
${CMAKE_CURRENT_SOURCE_DIR}/native)

file(GLOB AGORA_RTC_SDK_LIBRARY
${AGORA_RTC_SDK_PATH}/Agora_Native_SDK_for_Windows_FULL/sdk/${AGORA_RTC_PROJECT_ARCH}/*.dll
Expand Down
5 changes: 2 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"agora-electron-sdk": "4.3.0",
"antd": "^4.20.3",
"download": "^8.0.0",
"ffi-napi": "^4.0.3",
"koffi": "^2.8.0",
"react": "^18.1.0",
"react-color": "^2.19.3",
"react-dom": "^18.1.0",
Expand All @@ -94,13 +94,12 @@
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.6",
"@teamsupercell/typings-for-css-modules-loader": "^2.5.1",
"@types/download": "^8.0.2",
"@types/ffi-napi": "^4.0.7",
"@types/react": "^16.9.44",
"@types/react-color": "^3.0.6",
"@types/react-dom": "^18.0.3",
"@types/react-router-dom": "^5.1.6",
"@types/ref-napi": "^3.0.7",
"electron": "18.2.3",
"electron": "22.0.0",
"electron-builder": "^23.1.0",
"electron-webpack": "^2.8.2",
"fork-ts-checker-webpack-plugin": "^4.1.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,14 @@ export default class LocalVideoTranscoder
this.error('sourceType is invalid');
return;
}
this.engine?.startCameraCapture(sourceType, { deviceId });
this.engine?.startCameraCapture(sourceType, {
deviceId,
format: {
width: 1920,
height: 1080,
fps: 60,
},
});
};

stopCameraCapture = (deviceId: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {
createAgoraRtcEngine,
} from 'agora-electron-sdk';
import download from 'download';
import ffi, {
LibraryObject,
LibraryObjectDefinitionToLibraryDefinition,
} from 'ffi-napi';
import ffi, { IKoffiLib } from 'koffi';
import React, { ReactElement } from 'react';

import {
Expand All @@ -33,12 +30,21 @@ if (process.platform === 'darwin') {
}
pluginName += postfix;

type PluginType = {
EnablePlugin: ['bool', ['uint64']];
DisablePlugin: ['bool', ['uint64']];
CreateSamplePlugin: ['uint64', ['uint64']];
DestroySamplePlugin: ['void', ['uint64']];
CreateSampleAudioPlugin: ['uint64', ['uint64']];
type FuncConfig = {
returnType: string;
paramTypes: string[];
};

type PluginConfig = {
[funcName: string]: FuncConfig;
};

const pluginConfig: PluginConfig = {
CreateSampleAudioPlugin: { returnType: 'uint64', paramTypes: ['uint64'] },
CreateSamplePlugin: { returnType: 'uint64', paramTypes: ['uint64'] },
DestroySamplePlugin: { returnType: 'void', paramTypes: ['uint64'] },
DisablePlugin: { returnType: 'bool', paramTypes: ['uint64'] },
EnablePlugin: { returnType: 'bool', paramTypes: ['uint64'] },
};

interface State extends BaseVideoComponentState {
Expand All @@ -49,9 +55,16 @@ export default class ProcessVideoRawData
extends BaseComponent<{}, State>
implements IRtcEngineEventHandler
{
pluginLibrary?: LibraryObject<
LibraryObjectDefinitionToLibraryDefinition<PluginType>
>;
nativeLib?: IKoffiLib;
pluginLibrary: {
[funcName: string]: Function;
} = {
CreateSampleAudioPlugin: () => {},
CreateSamplePlugin: () => {},
DestroySamplePlugin: () => {},
DisablePlugin: () => {},
EnablePlugin: () => {},
};
plugin?: string | number;
pluginAudio?: string | number;

Expand Down Expand Up @@ -137,21 +150,24 @@ export default class ProcessVideoRawData
console.log(`download success`);
}

const plugin: PluginType = {
CreateSampleAudioPlugin: ['uint64', ['uint64']],
CreateSamplePlugin: ['uint64', ['uint64']],
DestroySamplePlugin: ['void', ['uint64']],
DisablePlugin: ['bool', ['uint64']],
EnablePlugin: ['bool', ['uint64']],
};
this.pluginLibrary ??= ffi.Library(dllPath, plugin);
this.nativeLib ??= ffi.load(dllPath);

for (const [funcName, { returnType, paramTypes }] of Object.entries(
pluginConfig
)) {
this.pluginLibrary[funcName] = this.nativeLib.func(
funcName,
returnType,
paramTypes
);
}

const handle = this.engine?.getNativeHandle();
if (handle !== undefined) {
this.plugin = this.pluginLibrary.CreateSamplePlugin(handle);
this.pluginLibrary.EnablePlugin(this.plugin);
this.pluginAudio = this.pluginLibrary.CreateSampleAudioPlugin(handle);
this.pluginLibrary.EnablePlugin(this.pluginAudio);
this.plugin = this.pluginLibrary.CreateSamplePlugin?.(handle);
this.pluginLibrary.EnablePlugin?.(this.plugin);
this.pluginAudio = this.pluginLibrary.CreateSampleAudioPlugin?.(handle);
this.pluginLibrary.EnablePlugin?.(this.pluginAudio);
}
this.setState({ enablePlugin: true });
};
Expand All @@ -161,16 +177,16 @@ export default class ProcessVideoRawData
*/
disablePlugin = () => {
if (this.plugin) {
this.pluginLibrary?.DisablePlugin(this.plugin);
this.pluginLibrary?.DestroySamplePlugin(this.plugin);
this.pluginLibrary.DisablePlugin?.(this.plugin);
this.pluginLibrary.DestroySamplePlugin?.(this.plugin);
this.plugin = undefined;
} else {
this.error('plugin is invalid');
}

if (this.pluginAudio) {
this.pluginLibrary?.DisablePlugin(this.pluginAudio);
this.pluginLibrary?.DestroySamplePlugin(this.pluginAudio);
this.pluginLibrary.DisablePlugin?.(this.pluginAudio);
this.pluginLibrary.DestroySamplePlugin?.(this.pluginAudio);
this.pluginAudio = undefined;
} else {
this.error('pluginAudio is invalid');
Expand Down
2 changes: 1 addition & 1 deletion example/webpack.renderer.additions.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = function (config) {
// ...config.externals,
'webpack',
'agora-electron-sdk',
'ffi-napi',
'koffi',
'ref-napi',
];
console.log('config', config.module.rules);
Expand Down
Loading
Loading