Skip to content

Commit

Permalink
EHN: VP9 download and link for Visual studio 2013 and 2015. build of …
Browse files Browse the repository at this point in the history
…openigtlink use the other

compilers in windows platform will still succeed, but without vp9
support.
  • Loading branch information
leochan2009 committed Jan 26, 2018
1 parent 70c9cb5 commit 0e91008
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 118 deletions.
9 changes: 7 additions & 2 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ If all went OK you will have the executable and the library:

VideoStreaming
---------------
You might want to use OpenIGTLink library to perform video streaming. Currently OpenH264, H265 and VP9 are supported in the OpenIGTLink.
You might want to use OpenIGTLink library to perform video streaming. Currently OpenH264, H265, VP9 and AV1 are supported in the OpenIGTLink.

* Prerequisites

Expand All @@ -64,6 +64,7 @@ In the case of H265 build, H265 have many implementations, the encoder used in l
OpenIGTLink library doesn't build H265 libraries, so the users need to download and compile the libraries by themselves.
Afterwards, set the variables-"X265_INCLUDE_DIR, X265_LIBRARY_DIR, OPENHEVC_INCLUDE_DIR, OpenHEVC_LIBRARY"-correctly in cmake configuration.

In the case of AV1 build, the AV1 codec is cmakefied. Once the OpenIGTLink_USE_AV1 option is selected, the openigtlink libray will superbuild the codec and link automatically.
* Linux / Mac OS X

In the case of Linux and Mac, after installing the required program in the Prerequisites section,
Expand All @@ -84,7 +85,6 @@ $ make
* Windows Build

In the case of windows build, please refer to the following websites for H264, X265 and VP9 respectively.
Make sure the build are 32 bit.
Useful H264 build instructions:

https://github.com/cisco/openh264
Expand All @@ -94,6 +94,11 @@ Useful VP9 build instructions:
https://www.webmproject.org/code/build-prerequisites/
http://wiki.webmproject.org/ffmpeg/building-with-libvpx

OpenIGTLink provides binary library files for visual studio 12 2013 and visual studio 14 2015.
The libray will be automatically downloaded during the project build when user configure OpenIGTLink library using these cmake generators:
"Visual Studio 12 2013", "Visual Studio 12 2013 Win64", "Visual Studio 14 2015" and "Visual Studio 14 2015 Win64".
For the rest cmake generators, the user need to provide the VP9_INCLUDE_DIR and VP9_BINARY_DIR, otherwize the video streaming feature will be deactivated.

Useful X265 build intructions:

https://bitbucket.org/multicoreware/x265/wiki/CrossCompile
Expand Down
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ SET(OpenIGTLink_BUILD_EXAMPLES ${BUILD_EXAMPLES})
OPTION(BUILD_TESTING "Build the testing tree." ON)
OPTION(USE_GTEST "Use googletest for testing" ON)
SET(OpenIGTLink_BUILD_TESTING ${BUILD_TESTING})
SET(OpenIGTLink_USE_GTEST "0")
IF(USE_GTEST)
SET(OpenIGTLink_USE_GTEST "1")
#link to google test library tend to fail https://github.com/openigtlink/OpenIGTLink/issues/122
IF(OpenIGTLink_BUILD_SHARED_LIBS)
SET(USE_GTEST OFF)
ENDIF()

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -165,10 +165,10 @@ IF(CMAKE_USE_PTHREADS)
ENDIF()
ENDIF()

SET(OpenIGTLink_ENABLE_VIDEOSTREAMING "0")
OPTION(OpenIGTLink_ENABLE_VIDEOSTREAMING "Video stream feature activated." OFF)
IF(${OpenIGTLink_PROTOCOL_VERSION} GREATER "2")
IF (OpenIGTLink_USE_H264 OR OpenIGTLink_USE_VP9 OR OpenIGTLink_USE_X265 OR OpenIGTLink_USE_OpenHEVC OR OpenIGTLink_USE_AV1)
SET(OpenIGTLink_ENABLE_VIDEOSTREAMING "1")
SET(OpenIGTLink_ENABLE_VIDEOSTREAMING ON)
ENDIF()
ENDIF()
#-----------------------------------------------------------------------------
Expand Down
39 changes: 37 additions & 2 deletions Examples/VideoStreaming/VideoServer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int Width = 256;
int Height = 256;
std::string testFileName(OpenIGTLink_SOURCE_ROOTDIR);
int startIndex = 0;
int inputFrameNum = 500;
int inputFrameNum = 2000;

void* ThreadFunction(void* ptr);

Expand Down Expand Up @@ -103,11 +103,41 @@ int main(int argc, char* argv[])
{
std::cerr << "A client is connected." << std::endl;
// Create a message buffer to receive header
td.interval = 30;
td.interval = 100;
td.glock = glock;
td.socket = socket;
td.stop = 0;
threadID = threader->SpawnThread((igtl::ThreadFunctionType) &ThreadFunction, &td);
// Create a message buffer to receive header
igtl::MessageHeader::Pointer headerMsg;
headerMsg = igtl::MessageHeader::New();
//------------------------------------------------------------
// loop
for (;;)
{
// Initialize receive buffer
headerMsg->InitPack();

// Receive generic header from the socket
int rs = socket->Receive(headerMsg->GetPackPointer(), headerMsg->GetPackSize());
if (rs == 0)
{
if (threadID >= 0)
{
td.stop = 1;
threader->TerminateThread(threadID);
threadID = -1;
}
std::cerr << "Disconnecting the client." << std::endl;
td.socket = NULL; // VERY IMPORTANT. Completely remove the instance.
socket->CloseSocket();
break;
}
if (rs != headerMsg->GetPackSize())
{
continue;
}
}
}
}

Expand Down Expand Up @@ -141,6 +171,7 @@ void* ThreadFunction(void * ptr)
VP9StreamEncoder->SetPicWidthAndHeight(Width,Height);
VP9StreamEncoder->InitializeEncoder();
VP9StreamEncoder->SetLosslessLink(true);
VP9StreamEncoder->SetKeyFrameDistance(50);
encoder = VP9StreamEncoder;
#elif defined(OpenIGTLink_USE_AV1)
igtlAV1Encoder* AV1StreamEncoder = new igtlAV1Encoder();
Expand Down Expand Up @@ -173,6 +204,10 @@ void* ThreadFunction(void * ptr)
memset(pDecodedPic->data[0], 0, Width * Height * 3 / 2);
for(int i = 0; i <inputFrameNum; i++)
{
if(td->stop)
{
break;
}
std::string sep = "/";
#if defined(_WIN32) || defined(_WIN64)
sep = "\\";
Expand Down
2 changes: 1 addition & 1 deletion OpenIGTLinkConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SET(OpenIGTLink_USE_VP9 @OpenIGTLink_USE_VP9@)
SET(OpenIGTLink_USE_X265 @OpenIGTLink_USE_X265@)
SET(OpenIGTLink_USE_OpenHEVC @OpenIGTLink_USE_OpenHEVC@)
SET(OpenIGTLink_USE_AV1 @OpenIGTLink_USE_AV1@)
SET(OpenIGTLink_ENABLE_VIDEOSTREAMING "@OpenIGTLink_ENABLE_VIDEOSTREAMING@")
SET(OpenIGTLink_ENABLE_VIDEOSTREAMING @OpenIGTLink_ENABLE_VIDEOSTREAMING@)
SET(OpenIGTLink_USE_WEBSOCKET @OpenIGTLink_USE_WEBSOCKET@)

# Path to CableSwig configuration used by OpenIGTLink.
Expand Down
10 changes: 5 additions & 5 deletions Source/VideoStreaming/igtlVP9Decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
#include "igtl_types.h"
#include "igtlVideoMessage.h"
#include "igtlCodecCommonClasses.h"
#include "vpx/vpx_decoder.h"
#include "vpx_decoder.h"
#include "vpx_config.h"
#include "vpx/vp8dx.h"
#include "vpx/vpx_codec.h"
#include "vpx/vpx_image.h"
#include "vpx/vpx_integer.h"
#include "vp8dx.h"
#include "vpx_codec.h"
#include "vpx_image.h"
#include "vpx_integer.h"

namespace igtl {

Expand Down
4 changes: 2 additions & 2 deletions Source/VideoStreaming/igtlVP9Encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include <stdlib.h>
#include <string.h>

#include "vpx/vp8cx.h"
#include "vpx/vpx_image.h"
#include "vp8cx.h"
#include "vpx_image.h"

#include "igtlCodecCommonClasses.h"
#include "igtl_header.h"
Expand Down
18 changes: 11 additions & 7 deletions Source/VideoStreaming/igtlVideoStreaming.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ IF(OpenIGTLink_USE_H264)
ENDIF()
IF(OpenIGTLink_USE_VP9)
INCLUDE(${OpenIGTLink_SOURCE_DIR}/SuperBuild/External_VP9.cmake)
IF(EXISTS ${VP9_LIBRARY_DIR})
IF((NOT "${VP9_LIBRARY_DIR}" STREQUAL "") AND (NOT "${VP9_INCLUDE_DIR}" STREQUAL ""))
LIST(APPEND OpenIGTLink_INCLUDE_DIRS
${VP9_INCLUDE_DIR}
)
Expand All @@ -52,11 +52,9 @@ IF(OpenIGTLink_USE_VP9)
${PROJECT_SOURCE_DIR}/Source/VideoStreaming/igtlVP9Decoder.h
${PROJECT_SOURCE_DIR}/Source/VideoStreaming/igtlVP9Encoder.h
)
IF(NOT ${VP9_LIBRARY_DIR} EQUAL "")
LIST(APPEND OpenIGTLink_INCLUDE_DIRS
"${VP9_LIBRARY_DIR}" )
LINK_DIRECTORIES("${VP9_LIBRARY_DIR}/lib")
ENDIF()
LIST(APPEND OpenIGTLink_INCLUDE_DIRS
${VP9_LIBRARY_DIR} )
LINK_DIRECTORIES("${VP9_LIBRARY_DIR}/lib")
ELSE()
MESSAGE("VP9_INCLUDE_DIR or VP9_LIBRARY_DIR no found")
ENDIF()
Expand Down Expand Up @@ -113,8 +111,14 @@ IF(WIN32) # for Windows
ENDIF()
IF(OpenIGTLink_USE_VP9)
#To do, library name depends on the compiler setting, could be vpxmt.lib and vpxmtd also. Make sure the setting matches.
#SET(VP9_lib optimized ${VP9_LIBRARY_DIR}\\Release\\vpxmd.lib debug ${VP9_LIBRARY_DIR}\\Debug\\vpxmdd.lib)
if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
SET(VP9_lib optimized ${VP9_LIBRARY_DIR}\\x64\\Release\\vpxmd.lib debug ${VP9_LIBRARY_DIR}\\x64\\Debug\\vpxmdd.lib)
else()
SET(VP9_lib optimized ${VP9_LIBRARY_DIR}\\Win32\\Release\\vpxmd.lib debug ${VP9_LIBRARY_DIR}\\Win32\\Debug\\vpxmdd.lib)
endif()
LIST(APPEND LINK_LIBS
VP9_lib
${VP9_lib}
)
ENDIF()
IF(OpenIGTLink_USE_X265)
Expand Down
4 changes: 2 additions & 2 deletions Source/igtlMessageFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ PURPOSE. See the above copyright notices for more information.
#include "igtlCommandMessage.h"
#endif // OpenIGTLink_PROTOCOL_VERSION >= 3

#if OpenIGTLink_ENABLE_VIDEOSTREAMING
#if defined(OpenIGTLink_ENABLE_VIDEOSTREAMING)
#include "igtlVideoMessage.h"
#endif

Expand Down Expand Up @@ -92,7 +92,7 @@ MessageFactory::MessageFactory()
this->AddMessageType("RTS_COMMAND", (PointerToMessageBaseNew)&igtl::RTSCommandMessage::New);
#endif

#if OpenIGTLink_ENABLE_VIDEOSTREAMING
#if defined(OpenIGTLink_ENABLE_VIDEOSTREAMING)
this->AddMessageType("VIDEO", (PointerToMessageBaseNew)&igtl::VideoMessage::New);
#endif
}
Expand Down
40 changes: 23 additions & 17 deletions SuperBuild/External_VP9.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ELSE()
# OpenIGTLink has not been built yet, so download and build it as an external project
MESSAGE(STATUS "Downloading VP9 from https://github.com/webmproject/libvpx.git")
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
SET (VP9_INCLUDE_DIR "${CMAKE_BINARY_DIR}/Deps/VP9" CACHE PATH "VP9 source directory" FORCE)
SET (VP9_INCLUDE_DIR "${CMAKE_BINARY_DIR}/Deps/VP9/vpx" CACHE PATH "VP9 source directory" FORCE)
SET (VP9_LIBRARY_DIR "${CMAKE_BINARY_DIR}/Deps/VP9" CACHE PATH "VP9 library directory" FORCE)
ExternalProject_Add(VP9
PREFIX "${CMAKE_BINARY_DIR}/Deps/VP9-prefix"
Expand All @@ -36,32 +36,38 @@ ELSE()
DEPENDS ${VP9_DEPENDENCIES}
)
else()
if("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 14 2015")
SET (VP9_INCLUDE_DIR "${CMAKE_BINARY_DIR}/Deps/VP9" CACHE PATH "VP9 source directory" FORCE)
SET (VP9_LIBRARY_DIR "${CMAKE_BINARY_DIR}/Deps/VP9-Binary/VP9" CACHE PATH "VP9 library directory" FORCE)
ExternalProject_Add(VP9-Source
GIT_REPOSITORY https://github.com/webmproject/libvpx/
GIT_TAG v1.6.1
SOURCE_DIR "${CMAKE_BINARY_DIR}/Deps/VP9"
CONFIGURE_COMMAND ""
BUILD_ALWAYS 0
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
if( ("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 14 2015") OR ("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 14 2015 Win64" ) OR
("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 12 2013") OR ("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 12 2013 Win64" )
)
SET (VP9_INCLUDE_DIR "${CMAKE_BINARY_DIR}/Deps/VP9-Binary/vpx" CACHE PATH "VP9 source directory" FORCE)
SET (BinaryURL "")
if ("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 14 2015")
SET (VP9_LIBRARY_DIR "${CMAKE_BINARY_DIR}/Deps/VP9-Binary/VP9-vs14" CACHE PATH "VP9 library directory" FORCE)
SET (BinaryURL "https://github.com/openigtlink/CodecLibrariesFile/archive/vs14.zip")
elseif("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 14 2015 Win64" )
SET (VP9_LIBRARY_DIR "${CMAKE_BINARY_DIR}/Deps/VP9-Binary/VP9-vs14-Win64" CACHE PATH "VP9 library directory" FORCE)
SET (BinaryURL "https://github.com/openigtlink/CodecLibrariesFile/archive/vs14-Win64.zip")
elseif ("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 12 2013")
SET (VP9_LIBRARY_DIR "${CMAKE_BINARY_DIR}/Deps/VP9-Binary/VP9-vs12" CACHE PATH "VP9 library directory" FORCE)
SET (BinaryURL "https://github.com/openigtlink/CodecLibrariesFile/archive/vs12.zip")
elseif("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 12 2013 Win64" )
SET (VP9_LIBRARY_DIR "${CMAKE_BINARY_DIR}/Deps/VP9-Binary/VP9-vs12-Win64" CACHE PATH "VP9 library directory" FORCE)
SET (BinaryURL "https://github.com/openigtlink/CodecLibrariesFile/archive/vs12-Win64.zip")
endif()
ExternalProject_Add(VP9
GIT_REPOSITORY https://github.com/openigtlink/CodecLibrariesFile.git
GIT_TAG master
URL ${BinaryURL}
SOURCE_DIR "${CMAKE_BINARY_DIR}/Deps/VP9-Binary"
CONFIGURE_COMMAND ""
BUILD_ALWAYS 0
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
DEPENDS VP9-Source
)
else()
SET(OpenIGTLink_USE_VP9 OFF CACHE BOOL "" FORCE)
IF (OpenIGTLink_USE_H264 OR OpenIGTLink_USE_VP9 OR OpenIGTLink_USE_X265 OR OpenIGTLink_USE_OpenHEVC OR OpenIGTLink_USE_AV1)
SET(OpenIGTLink_ENABLE_VIDEOSTREAMING OFF)
ENDIF()
message(WARNING "Only support for Visual Studio 14 2015")
endif()
endif()
Expand Down
8 changes: 6 additions & 2 deletions SuperBuild/External_yasm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
include(${OpenIGTLink_SOURCE_DIR}/SuperBuild/FindYASM.cmake)
include(${CMAKE_ROOT}/Modules/FindPythonInterp.cmake)

find_package(PythonInterp "2.7" REQUIRED)
IF(YASM_FOUND)
# YASM has been built already
MESSAGE(STATUS "Using YASM available at: ${YASM_BINARY_DIR}")
ELSE()
SET(YASM_PYTHON_EXECUTABLE "" CACHE STRING "Python Interpreter")
if("${YASM_PYTHON_EXECUTABLE}" STREQUAL "")
find_package(PythonInterp "2.7" REQUIRED)
SET(YASM_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
endif()
# yas has not been built yet, so download and build it as an external project
SET(GIT_REPOSITORY "https://github.com/yasm/yasm.git")
SET(GIT_TAG "master")
Expand Down Expand Up @@ -35,7 +39,7 @@ ELSE()
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY:STRING=${YASM_BINARY_DIR}
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY:STRING=${YASM_BINARY_DIR}
-DYASM_INSTALL_BIN_DIR:STRING="bin"
-DPYTHON_EXECUTABLE:STRING=${PYTHON_EXECUTABLE}
-DPYTHON_EXECUTABLE:STRING=${YASM_PYTHON_EXECUTABLE}
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH=${YASM_BINARY_DIR}
-DBUILD_SHARED_LIBS:BOOL=${OpenIGTLink_BUILD_SHARED_LIBS}
-DBUILD_TESTING:BOOL=OFF
Expand Down
Loading

0 comments on commit 0e91008

Please sign in to comment.