Skip to content

Commit

Permalink
Win: add MSVC sample code and build guide (#278)
Browse files Browse the repository at this point in the history
Signed-off-by: Ric Li <ming3.li@intel.com>
  • Loading branch information
ricmli committed May 19, 2023
1 parent 6c50d8b commit 0f1c83c
Show file tree
Hide file tree
Showing 12 changed files with 508 additions and 396 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The library also includes SIMD CSC (color space format conversion), DMA, and plu

Please refer to [build guide](doc/build.md) for instructions on how to build DPDK, the library, and the sample application.

For Windows, please refer to the [Win build guide](doc/build_WIN_MSYS2.md) or instructions on how to build.
For Windows, please refer to the [Win build guide](doc/build_WIN.md) for instructions on how to build.

## 3. Run ST2110

Expand Down
39 changes: 39 additions & 0 deletions app/sample/msvc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Sample code for how to develop application in MSVC

## 1. Introduction

The is sample code for how to develop MSVC application quickly based on Intel® Media Transport Library. The guide is verified with Visual Studio 2022 (v143).

## 2. Steps

### 2.1 Prepare latest .lib file

* Build IMTL library in MSYS2, see [WIN build guide](../../../doc/build_WIN.md), also need to add MSYS2 binary PATH to system environment variables.

* After build, in the build folder, you will get `libmtl.def` file.

* Open Developer Command Prompt for VS here, run below command:

```powershell
lib /machine:x64 /def:libmtl.def
```

* Copy `libmtl.lib` to project folder.

### 2.2 Set project properties

* Double-click `imtl_sample.sln` to launch VS or create a console app in VS with the `imtl_sample.cpp`.

* In Solution Explorer, right click on project, open Properties window, choose the configuration needed, such as `Release - x64`.

* Go to VC++ Directories, add MSYS2 Environment include folder(eg. for UCRT64, `C:\msys64\ucrt64\include`) to `External Include Directories`.

* Go to Linker - Input, add `libmtl.lib` to `Additional Dependencies`

* Click `OK` or `Apply` to save properties.

### 2.3 Build and run

* Inside IDE: Click Run button (Local Windows Debugger/ Start Without Debugging) to build and run the application.

* Run binary: After build, go to output folder(eg. x64\Release), double-click `imtl_sample.exe` to run.
135 changes: 135 additions & 0 deletions app/sample/msvc/imtl_sample/imtl_sample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2023 Intel Corporation
*/

#include <Windows.h>
#include <mtl/mtl_api.h>
#include <mtl/st20_api.h>
#include <mtl/st_pipeline_api.h>

#include <condition_variable>
#include <csignal>
#include <iostream>
#include <mutex>
#include <thread>

static std::mutex mtx;
static std::condition_variable cv;
static uint32_t fb_done = 0;
static bool stop = false;
static mtl_handle g_st = NULL;

void signalHandler(int signum) {
std::cout << "SIGINT received - exiting!\n";
switch (signum) {
case SIGINT:
stop = true;
if (g_st != NULL) mtl_abort(g_st);
break;
}
}

int main() {
int ret = 0;
std::cout << "Starting IMTL sample..." << std::endl << mtl_version() << std::endl;

std::signal(SIGINT, signalHandler);

/* setting of parameters */
struct mtl_init_params param;
memset(&param, 0, sizeof(param));
strncpy_s(param.port[MTL_PORT_P], "0000:03:00.0", MTL_PORT_MAX_LEN);
param.num_ports = 1;
param.sip_addr[MTL_PORT_P][0] = 192;
param.sip_addr[MTL_PORT_P][1] = 168;
param.sip_addr[MTL_PORT_P][2] = 96;
param.sip_addr[MTL_PORT_P][3] = 12;
param.log_level = MTL_LOG_LEVEL_INFO;
param.tx_sessions_cnt_max = 1;
param.rx_sessions_cnt_max = 0;

/* init mtl */
mtl_handle st = mtl_init(&param);
if (st == NULL) {
std::cout << "mtl_init fail" << std::endl;
return -EIO;
}
g_st = st;

/* create a st2110-20 pipeline tx session */
struct st20p_tx_ops ops_tx;
memset(&ops_tx, 0, sizeof(ops_tx));
ops_tx.name = "st20p_tx_sample";
ops_tx.port.num_port = 1;
uint8_t dip[4] = {239, 19, 96, 1};
memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], dip, MTL_IP_ADDR_LEN);
strncpy_s(ops_tx.port.port[MTL_SESSION_PORT_P], param.port[MTL_PORT_P],
MTL_PORT_MAX_LEN);
ops_tx.port.udp_port[MTL_SESSION_PORT_P] = 20000;
ops_tx.port.payload_type = 112;
ops_tx.width = 1920;
ops_tx.height = 1080;
ops_tx.fps = ST_FPS_P59_94;
ops_tx.input_fmt = ST_FRAME_FMT_YUV422RFC4175PG2BE10;
ops_tx.transport_fmt = ST20_FMT_YUV_422_10BIT;
ops_tx.device = ST_PLUGIN_DEVICE_AUTO;
ops_tx.framebuff_cnt = 3;
auto sample_frame_available = [](void* priv) {
cv.notify_one();
return 0;
};
auto sample_frame_done = [](void* priv, struct st_frame* frame) {
fb_done++;
return 0;
};
ops_tx.notify_frame_available = sample_frame_available;
ops_tx.notify_frame_done = sample_frame_done;

st20p_tx_handle tx_handle = st20p_tx_create(st, &ops_tx);
if (tx_handle == NULL) {
mtl_uninit(st);
return -EIO;
}

auto sample_frame_thread = [tx_handle]() {
struct st_frame* frame;
while (!stop) {
frame = st20p_tx_get_frame(tx_handle);
if (!frame) { /* no frame */
{
std::unique_lock<std::mutex> lock(mtx);
cv.wait(lock);
}
continue;
}

// do something to frame

st20p_tx_put_frame(tx_handle, frame);
}
};

std::thread frame_thread(sample_frame_thread);

ret = mtl_start(st);

while (!stop) {
Sleep(1000);
}

cv.notify_one();
frame_thread.join();
if (tx_handle) st20p_tx_free(tx_handle);

ret = mtl_stop(st);

/* uninit mtl */
if (st != NULL) {
mtl_uninit(st);
st = NULL;
}

std::cout << "Stopped, fb_done: " << fb_done << std::endl;

return ret;
}
31 changes: 31 additions & 0 deletions app/sample/msvc/imtl_sample/imtl_sample.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33627.172
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "imtl_sample", "imtl_sample.vcxproj", "{CBC62708-F271-4168-9F29-5FA5C061F541}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CBC62708-F271-4168-9F29-5FA5C061F541}.Debug|x64.ActiveCfg = Debug|x64
{CBC62708-F271-4168-9F29-5FA5C061F541}.Debug|x64.Build.0 = Debug|x64
{CBC62708-F271-4168-9F29-5FA5C061F541}.Debug|x86.ActiveCfg = Debug|Win32
{CBC62708-F271-4168-9F29-5FA5C061F541}.Debug|x86.Build.0 = Debug|Win32
{CBC62708-F271-4168-9F29-5FA5C061F541}.Release|x64.ActiveCfg = Release|x64
{CBC62708-F271-4168-9F29-5FA5C061F541}.Release|x64.Build.0 = Release|x64
{CBC62708-F271-4168-9F29-5FA5C061F541}.Release|x86.ActiveCfg = Release|Win32
{CBC62708-F271-4168-9F29-5FA5C061F541}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {12481933-37E5-4B00-B0F6-974E7A13CF83}
EndGlobalSection
EndGlobal
144 changes: 144 additions & 0 deletions app/sample/msvc/imtl_sample/imtl_sample.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{cbc62708-f271-4168-9f29-5fa5c061f541}</ProjectGuid>
<RootNamespace>imtlsample</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ExternalIncludePath>C:\msys64\ucrt64\include;$(ExternalIncludePath)</ExternalIncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ExternalIncludePath>C:\msys64\ucrt64\include;$(ExternalIncludePath)</ExternalIncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libmtl.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libmtl.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="imtl_sample.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
22 changes: 22 additions & 0 deletions app/sample/msvc/imtl_sample/imtl_sample.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="imtl_sample.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions app/sample/msvc/imtl_sample/imtl_sample.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
Loading

0 comments on commit 0f1c83c

Please sign in to comment.