Skip to content
Closed
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
31 changes: 31 additions & 0 deletions Plugin~/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# プラグイン

`com.unity.webrtc` が依存するネイティブプラグインのビルド及び配置の方法について説明します。

### libwebrtc の組み込み

プラグインは **libwebrtc** に依存しているため、ビルドするために libwebrtc をスタティックリンクする必要があります。Github Release ページに `webrtc-win.zip` を配置しています。
<img src="../Packages/com.unity.webrtc/Documentation~/images/libwebrtc_github_release.png" width=600 align=center>

zip ファイルを展開後、Plugin フォルダ直下に配置します。

<img src="../Packages/com.unity.webrtc/Documentation~/images/deploy_libwebrtc.png" width=500 align=center>

### 開発環境

version 1.0 現在、ビルドは **Visual Studio 2017** を利用しています。

### プロジェクトの設定

プラグインの開発を行うためには、個別の環境に合わせて`WebRTCPlugin` プロジェクトのプロパティを変更する必要があります。

`Command` に Unity の実行ファイルパス、`Command Arguments` にプロジェクトパスを指定してください。この設定を行うことで、デバッグ実行時に Unity エディタが起動し、ブレークポイントが有効になります。

<img src="../Packages/com.unity.webrtc/Documentation~/images/command_config_vs2017.png" width=600 align=center>

### プラグインの配置

ビルド実行すると、`webrtc.dll` が `Packages\com.unity.webrtc\Runtime\Plugins\x86_64` に配置されます。このとき Unity のインスペクタ上で以下の設定になっていることを確認してください。

<img src="../Packages/com.unity.webrtc/Documentation~/images/inspector_webrtc_plugin.png" width=600 align=center>

32 changes: 32 additions & 0 deletions Plugin~/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Building the Plugin

This guide will cover building and deploying the native plugin `com.unity.webrtc` depends on.

### Embedding libwebrtc

The plugin relies on **libwebrtc**, so building it requires a static libwebrtc link. `webrtc-win.zip` can be found on the Github Release page.

<img src="../Packages/com.unity.webrtc/Documentation~/images/libwebrtc_github_release.png" width=600 align=center>

Extract the files from the zip, and place them in the Plugin folder.

<img src="../Packages/com.unity.webrtc/Documentation~/images/deploy_libwebrtc.png" width=500 align=center>

### Build

Version 1.0 is currently built with **Visual Studio 2017**.

### Project Settings

The `WebRTCPlugin` project properties must be adjusted to match your environment in order to build the plugin.

Set the Unity .exe path under `Command` and the project path under `Command Arguments`. Once set, during debugging the Unity Editor will run and breakpoints will be enabled.

<img src="../Packages/com.unity.webrtc/Documentation~/images/command_config_vs2017.png" width=600 align=center>

### Deploying the Plugin

When you run the build, `webrtc.dll` will be placed in `Packages\com.unity.webrtc\Runtime\Plugins\x86_64`. You should then be able to verify the following settings in the Unity Inspector window.

<img src="../Packages/com.unity.webrtc/Documentation~/images/inspector_webrtc_plugin.png" width=600 align=center>

85 changes: 85 additions & 0 deletions Plugin~/WebRTCPlugin/Callback.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "pch.h"
#include "Context.h"
#include "IUnityGraphics.h"
#include "IUnityGraphicsD3D11.h"

namespace WebRTC
{
IUnityInterfaces* s_UnityInterfaces = nullptr;
IUnityGraphics* s_Graphics = nullptr;
UnityGfxRenderer s_RenderType;
//d3d11 context
ID3D11DeviceContext* context;
//d3d11 device
ID3D11Device* g_D3D11Device = nullptr;
//natively created ID3D11Texture2D ptrs
UnityFrameBuffer* renderTextures[bufferedFrameNum];

Context* s_context;
}
using namespace WebRTC;
//get d3d11 device
static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType)
{
switch (eventType)
{
case kUnityGfxDeviceEventInitialize:
{
s_RenderType = s_UnityInterfaces->Get<IUnityGraphics>()->GetRenderer();
if (s_RenderType == kUnityGfxRendererD3D11)
{
g_D3D11Device = s_UnityInterfaces->Get<IUnityGraphicsD3D11>()->GetDevice();
g_D3D11Device->GetImmediateContext(&context);
}
break;
}
case kUnityGfxDeviceEventShutdown:
{
for (auto rt : renderTextures)
{
if (rt)
{
rt->Release();
rt = nullptr;
}
}
//UnityPluginUnload not called normally
s_Graphics->UnregisterDeviceEventCallback(OnGraphicsDeviceEvent);
break;
}
case kUnityGfxDeviceEventBeforeReset:
{
break;
}
case kUnityGfxDeviceEventAfterReset:
{
break;
}
};
}
// Unity plugin load event
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
{
s_UnityInterfaces = unityInterfaces;
s_Graphics = unityInterfaces->Get<IUnityGraphics>();
s_Graphics->RegisterDeviceEventCallback(OnGraphicsDeviceEvent);
OnGraphicsDeviceEvent(kUnityGfxDeviceEventInitialize);
}
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload()
{
s_Graphics->UnregisterDeviceEventCallback(OnGraphicsDeviceEvent);
}

static void UNITY_INTERFACE_API OnRenderEvent(int eventID)
{
if (s_context != nullptr)
{
s_context->EncodeFrame();
}
}

extern "C" UnityRenderingEvent UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API GetRenderEventFunc(Context* context)
{
s_context = context;
return OnRenderEvent;
}
Loading