Skip to content

Commit

Permalink
Merge pull request #31 from Johnny-Martin/master
Browse files Browse the repository at this point in the history
feat:add unreal engine sample code
  • Loading branch information
liuqijun authored Oct 10, 2023
2 parents 179cbfb + 1e7b326 commit d53998d
Show file tree
Hide file tree
Showing 57 changed files with 34,642 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


[/Script/HardwareTargeting.HardwareTargetingSettings]
TargetedHardwareClass=Desktop
AppliedTargetedHardwareClass=Desktop
DefaultGraphicsPerformance=Maximum
AppliedDefaultGraphicsPerformance=Maximum

[/Script/Engine.Engine]
+ActiveGameNameRedirects=(OldGameName="TP_Blank",NewGameName="/Script/NertcSampleCode")
+ActiveGameNameRedirects=(OldGameName="/Script/TP_Blank",NewGameName="/Script/NertcSampleCode")
+ActiveClassRedirects=(OldClassName="TP_BlankGameModeBase",NewClassName="NertcSampleCodeGameModeBase")

[/Script/EngineSettings.GameMapsSettings]
EditorStartupMap=/Game/Home.Home
GameDefaultMap=/Game/Home.Home

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

[/Script/EngineSettings.GeneralProjectSettings]
ProjectID=2696690546CC2874D37E89AE01510A16
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"FileVersion": 3,
"EngineAssociation": "4.25",
"Category": "",
"Description": "",
"Modules": [
{
"Name": "NertcSampleCode",
"Type": "Runtime",
"LoadingPhase": "Default",
"AdditionalDependencies": [
"UMGEditor",
"UMG"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "1.0",
"FriendlyName": "NertcPlugin",
"Description": "",
"Category": "Other",
"CreatedBy": "",
"CreatedByURL": "",
"DocsURL": "",
"MarketplaceURL": "",
"SupportURL": "",
"CanContainContent": true,
"IsBetaVersion": false,
"IsExperimentalVersion": false,
"Installed": false,
"Modules": [
{
"Name": "NertcPlugin",
"Type": "Runtime",
"LoadingPhase": "Default",
"WhitelistPlatforms" : [
"Win64",
"Mac",
"Android",
"IOS"
],
"BlacklistPlatforms": [

]
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright Epic Games, Inc. All Rights Reserved.
using System.IO;
using UnrealBuildTool;

public class NertcPlugin : ModuleRules
{
public NertcPlugin(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicIncludePaths.AddRange(
new string[] {
// ... add public include paths required here ...
}
);


PrivateIncludePaths.AddRange(
new string[] {
// ... add other private include paths required here ...
}
);


PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"Nertc",
"Projects"
// ... add other public dependencies that you statically link with here ...
}
);


PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"Slate",
"SlateCore",
"UMG",
"AndroidPermission",
// ... add private dependencies that you statically link with here ...
}
);


DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright Epic Games, Inc. All Rights Reserved.

#include "NertcAudioDeviceManager.h"

#include "Nertc/api/nertc_engine.h"
#include "Nertc/api/nertc_engine_ex.h"
#include "Nertc/api/nertc_audio_device_manager.h"

#include <utility>

namespace nertc {
NertcAudioDeviceManager::NertcAudioDeviceManager(nertc_audio_device_manager* manager) :m_nertc_audio_device_manager(manager){

}
IDeviceCollection* NertcAudioDeviceManager::enumerateRecordDevices() {
auto csdk_collection = nertc_audio_device_manager_enumerate_record_devices(m_nertc_audio_device_manager);
if (csdk_collection) {
return new NertcDeviceCollection(csdk_collection);
}
return nullptr;
}
int NertcAudioDeviceManager::setRecordDevice(const char device_id[kNERtcMaxDeviceIDLength]) {
return nertc_audio_device_manager_set_record_device(m_nertc_audio_device_manager, device_id);
}
int NertcAudioDeviceManager::getRecordDevice(char device_id[kNERtcMaxDeviceIDLength]) {
return nertc_audio_device_manager_get_record_device(m_nertc_audio_device_manager, device_id);
}
IDeviceCollection* NertcAudioDeviceManager::enumeratePlayoutDevices() {
auto csdk_collection = nertc_audio_device_manager_enumerate_playout_devices(m_nertc_audio_device_manager);
return new NertcDeviceCollection(csdk_collection);
}
int NertcAudioDeviceManager::setPlayoutDevice(const char device_id[kNERtcMaxDeviceIDLength]) {
return nertc_audio_device_manager_set_playout_device(m_nertc_audio_device_manager, device_id);
}
int NertcAudioDeviceManager::getPlayoutDevice(char device_id[kNERtcMaxDeviceIDLength]) {
return nertc_audio_device_manager_get_playout_device(m_nertc_audio_device_manager, device_id);
}
// Device volume manager
// The volume value: [0, 255]
int NertcAudioDeviceManager::setRecordDeviceVolume(uint32_t volume) {
return nertc_audio_device_manager_set_record_device_volume(m_nertc_audio_device_manager, volume);
}
int NertcAudioDeviceManager::getRecordDeviceVolume(uint32_t* volume) {
return nertc_audio_device_manager_get_record_device_volume(m_nertc_audio_device_manager, volume);
}
int NertcAudioDeviceManager::setPlayoutDeviceVolume(uint32_t volume) {
return nertc_audio_device_manager_set_playout_device_volume(m_nertc_audio_device_manager, volume);
}
int NertcAudioDeviceManager::getPlayoutDeviceVolume(uint32_t* volume) {
return nertc_audio_device_manager_get_playout_device_volume(m_nertc_audio_device_manager, volume);
}

int NertcAudioDeviceManager::setPlayoutDeviceMute(bool mute) {
return nertc_audio_device_manager_set_playout_device_mute(m_nertc_audio_device_manager, mute);
}
int NertcAudioDeviceManager::getPlayoutDeviceMute(bool* mute) {
return nertc_audio_device_manager_get_playout_device_mute(m_nertc_audio_device_manager, mute);
}
int NertcAudioDeviceManager::setRecordDeviceMute(bool mute) {
return nertc_audio_device_manager_set_record_device_mute(m_nertc_audio_device_manager, mute);
}
int NertcAudioDeviceManager::getRecordDeviceMute(bool* mute) {
return nertc_audio_device_manager_get_record_device_mute(m_nertc_audio_device_manager, mute);
}

// Device test
// NOTE: Recoding and loopback test can not being started at the same time
int NertcAudioDeviceManager::startRecordDeviceTest(uint64_t indication_interval) {
return nertc_audio_device_manager_start_record_device_test(m_nertc_audio_device_manager, indication_interval);
}
int NertcAudioDeviceManager::stopRecordDeviceTest() {
return nertc_audio_device_manager_stop_record_device_test(m_nertc_audio_device_manager);
}
int NertcAudioDeviceManager::startPlayoutDeviceTest(const char* test_audio_file_path) {
return nertc_audio_device_manager_start_playout_device_test(m_nertc_audio_device_manager, test_audio_file_path);
}
int NertcAudioDeviceManager::stopPlayoutDeviceTest() {
return nertc_audio_device_manager_stop_playout_device_test(m_nertc_audio_device_manager);
}
int NertcAudioDeviceManager::startAudioDeviceLoopbackTest(uint64_t indication_interval) {
return nertc_audio_device_manager_start_audio_device_loopback_test(m_nertc_audio_device_manager, indication_interval);
}
int NertcAudioDeviceManager::stopAudioDeviceLoopbackTest() {
return nertc_audio_device_manager_stop_audio_device_loopback_test(m_nertc_audio_device_manager);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/** @file NertcAudioDeviceManager.h
* @brief The interface header file of audio device management of the NERTC UE SDK.
* All parameter descriptions of the NERTC UE SDK. All string-related parameters (char *) are encoded in UTF-8.
* @copyright (c) 2021 NetEase, Inc. All rights reserved.
*/

#pragma once
#include "NertcDeviceCollection.h"
#include "INertcAudioDeviceManager.h"
#include <string>
//#include "Nertc/include/nertc_engine_ex.h"

struct nertc_audio_device_manager;
namespace nertc {
class NertcEngine;

class NertcAudioDeviceManager:public IAudioDeviceManager {
public:
NertcAudioDeviceManager() = default;
NertcAudioDeviceManager(const NertcAudioDeviceManager& other) = delete;
NertcAudioDeviceManager(NertcAudioDeviceManager&& other) noexcept = delete;
NertcAudioDeviceManager& operator=(const NertcAudioDeviceManager& other) = delete;
NertcAudioDeviceManager& operator=(NertcAudioDeviceManager&& other) noexcept = delete;
virtual ~NertcAudioDeviceManager() = default;
private:
friend class NertcEngineEx;
NertcAudioDeviceManager(nertc_audio_device_manager* manager);
public:

IDeviceCollection* enumerateRecordDevices() override;

int setRecordDevice(const char device_id[kNERtcMaxDeviceIDLength]) override;

int getRecordDevice(char device_id[kNERtcMaxDeviceIDLength]) override;

IDeviceCollection* enumeratePlayoutDevices() override;

int setPlayoutDevice(const char device_id[kNERtcMaxDeviceIDLength]) override;

int getPlayoutDevice(char device_id[kNERtcMaxDeviceIDLength]) override;

int setRecordDeviceVolume(uint32_t volume) override;

int getRecordDeviceVolume(uint32_t* volume) override;

int setPlayoutDeviceVolume(uint32_t volume) override;

int getPlayoutDeviceVolume(uint32_t* volume) override;

int setPlayoutDeviceMute(bool mute) override;

int getPlayoutDeviceMute(bool* mute) override;

int setRecordDeviceMute(bool mute) override;

int getRecordDeviceMute(bool* mute) override;

int startRecordDeviceTest(uint64_t indication_interval) override;

int stopRecordDeviceTest() override;

int startPlayoutDeviceTest(const char* test_audio_file_path) override;

int stopPlayoutDeviceTest() override;

int startAudioDeviceLoopbackTest(uint64_t indication_interval) override;

int stopAudioDeviceLoopbackTest() override;
private:
nertc_audio_device_manager* m_nertc_audio_device_manager{ nullptr };
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright Epic Games, Inc. All Rights Reserved.

#include "NertcEngineEx.h"
#include "NertcEngineUtil.h"
#include <map>
namespace nertc {
static std::map<void*, INERtcAudioFrameObserver*> g_engine_audio_observer_map;
namespace {
void on_audio_frame_did_record(void* self, struct nertc_audio_frame* frame) {
if (g_engine_audio_observer_map.find(self) == g_engine_audio_observer_map.end())
return;
NERtcAudioFrame nertc_frame{};
convertToNertcStruct(*frame, nertc_frame);
g_engine_audio_observer_map[self]->onAudioFrameDidRecord(&nertc_frame);
}
void on_audio_frame_will_playback(void* self, struct nertc_audio_frame* frame) {
if (g_engine_audio_observer_map.find(self) == g_engine_audio_observer_map.end())
return;
NERtcAudioFrame nertc_frame{};
convertToNertcStruct(*frame, nertc_frame);
g_engine_audio_observer_map[self]->onAudioFrameWillPlayback(&nertc_frame);
}
void on_mixed_audio_frame(void* self, struct nertc_audio_frame* frame) {
if (g_engine_audio_observer_map.find(self) == g_engine_audio_observer_map.end())
return;
NERtcAudioFrame nertc_frame{};
convertToNertcStruct(*frame, nertc_frame);
g_engine_audio_observer_map[self]->onMixedAudioFrame(&nertc_frame);
}
void on_playback_audio_frame_before_mixing(void* self, uint64_t user_id, struct nertc_audio_frame* frame, channel_id_t cid) {
if (g_engine_audio_observer_map.find(self) == g_engine_audio_observer_map.end())
return;
NERtcAudioFrame nertc_frame{};
convertToNertcStruct(*frame, nertc_frame);
g_engine_audio_observer_map[self]->onPlaybackAudioFrameBeforeMixing(user_id, &nertc_frame, cid);
}
}
void NertcEngineEx::clearCsdkAudioFrameObserver() {
//g_engine_audio_observer_map.erase(m_nertc_engine);
g_engine_audio_observer_map.clear();
}
void NertcEngineEx::fillCsdkAudioFrameObserver(INERtcAudioFrameObserver* observer) {
g_engine_audio_observer_map[m_nertc_engine] = observer;
if (!m_nertc_audio_frame_observer) {
m_nertc_audio_frame_observer = new nertc_audio_frame_observer();
}
if (!observer) {
*m_nertc_audio_frame_observer = nertc_audio_frame_observer{};
}
m_nertc_audio_frame_observer->self = m_nertc_engine;

m_nertc_audio_frame_observer->on_audio_frame_did_record = on_audio_frame_did_record;
m_nertc_audio_frame_observer->on_audio_frame_will_playback = on_audio_frame_will_playback;
m_nertc_audio_frame_observer->on_mixed_audio_frame = on_mixed_audio_frame;
m_nertc_audio_frame_observer->on_playback_audio_frame_before_mixing = on_playback_audio_frame_before_mixing;
}


}
Loading

0 comments on commit d53998d

Please sign in to comment.