├── Installation manual(Ubuntu).md
├── Installation manual(Windows).md
├── LICENSE
├── Makefile
├── Makefile
└── Makefile.proj
├── NDI-Video-Receiver
├── NDI-Video-Receiver.sln
└── NDI-Video-Receiver
│ ├── ConfigRead.cpp
│ ├── ConfigRead.h
│ ├── NDI-Video-Receiver.vcxproj
│ ├── NDI-Video-Receiver.vcxproj.filters
│ ├── NDI-Video-Receiver.vcxproj.user
│ ├── NdiCom.cpp
│ ├── NdiCom.h
│ ├── NdiVideoReceiver.config
│ └── NdiVideoReceiver.cpp
├── NDI-Video-Sender2.15
├── NDI-Video-Sender.sln
└── NDI-Video-Sender
│ ├── ConfigRead.cpp
│ ├── ConfigRead.h
│ ├── NDI-Video-Sender.vcxproj
│ ├── NDI-Video-Sender.vcxproj.filters
│ ├── NDI-Video-Sender.vcxproj.user
│ ├── NdiCom.cpp
│ ├── NdiCom.h
│ ├── NdiVideoSender.config
│ ├── NdiVideoSender.cpp
│ ├── Realsense.cpp
│ └── Realsense.h
├── NDI-Video-Sender2.16
├── NDI-Video-Sender.sln
└── NDI-Video-Sender
│ ├── ConfigRead.cpp
│ ├── ConfigRead.h
│ ├── NDI-Video-Sender.vcxproj
│ ├── NDI-Video-Sender.vcxproj.filters
│ ├── NDI-Video-Sender.vcxproj.user
│ ├── NdiCom.cpp
│ ├── NdiCom.h
│ ├── NdiVideoSender.config
│ ├── NdiVideoSender.cpp
│ ├── Realsense.cpp
│ └── Realsense.h
└── README.md
/Installation manual(Ubuntu).md:
--------------------------------------------------------------------------------
1 | 環境構築手順書 ~Ubuntu編~
2 | =======
3 |
4 | 開発/実行環境について
5 | -------------------
6 | * OS:Ubuntu 16.04 LTS
7 |
8 | * コンパイラ:gcc バージョン5.4.0
9 |
10 | * 使用ライブラリ :
11 | Newtek NDI バージョン3.5
12 | OpenCV バージョン3.2.0
13 | RealSense バージョン 2.0 (buildバージョン ~2.16.0)
14 |
15 | 開発環境のセットアップ
16 | --------------------
17 | **1、パッケージマネージャーの更新**
18 | ターミナルを起動し、 以下のコマンドを打ちます。
19 | ```bash
20 | $ sudo apt-get update
21 | $ sudo apt-get upgrade
22 | ```
23 |
24 | **2、開発ツールのインストール**
25 | 以下のコマンドを打ち、開発ツールをインストールします。
26 | ```bash
27 | $ sudo apt-get install build-essential cmake git pkg-config
28 | ```
29 |
30 | NewTek NDI SDK v3.5のインストール
31 | --------------------
32 | **1、NewTek NDI SDK v3.5をダウンロード**
33 | 以下よりダウンロードを行います。
34 | https://jp.newtek.com/ndi/sdk/
35 | ダウンロード時に名前やメールアドレスなどの送信が必要です。
36 |
37 | **2、インストール**
38 | ダウンロードされたInstallNDISDK_v3_Linux.shを、NDIをインストールしたいフォルダにコピーします。
39 | ターミナル上で以下のコマンドを入力します。
40 | ```bash
41 | $ cd “コピーしたディレクトリ”
42 | $ ll InstallNDISDK_v3_Linux.sh
43 | $ sh ./InstallNDISDK_v3_Linux.sh
44 | ```
45 |
46 | OpenCV v3.2.0のインストール
47 | --------------------
48 | **1、画像表示ライブラリと画像フォーマットのインストール**
49 | ターミナル上で以下のコマンドを実行します。
50 | ```bash
51 | $ sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev
52 | ```
53 |
54 | **2、GUI表示用のライブラリのインストール**
55 | ターミナル上で以下のコマンドを実行します。
56 | ```bash
57 | $ sudo apt-get install libgtk2.0-dev
58 | ```
59 |
60 | **3、ビデオストリーム及びフレームの処理に必要なライブラリのインストール**
61 | ターミナル上で以下のコマンドを実行します。
62 | ```bash
63 | $ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
64 | ```
65 |
66 | **4、OpenCVの最適化を行うライブラリのインストール**
67 | ターミナル上で以下のコマンドを実行します。
68 | ```bash
69 | $ sudo apt-get install libatlas-base-dev gfortran
70 | ```
71 |
72 | **5、GitHub上のOpenCV v3.2.0のリポジトリからクローンを行う**
73 | ターミナル上で以下のコマンドを実行します。
74 | ```bash
75 | $ git clone https://github.com/Itseez/opencv.git
76 | $ cd opencv
77 | $ git checkout 3.2.0
78 | $ cd ..
79 | $ git clone https://github.com/Itseez/opencv_contrib.git
80 | $ cd opencv_contrib
81 | $ git checkout 3.2.0
82 | ```
83 |
84 | **6、Cmakeを実行する**
85 | ターミナル上で以下のコマンドを実行します。
86 | ```bash
87 | $ cd ~/opencv
88 | $ mkdir build
89 | $ cd build
90 | $ cmake -D CMAKE_BUILD_TYPE=RELEASE \
91 | -D WITH_V4L=ON \
92 | -D CMAKE_INSTALL_PREFIX=/usr/local \
93 | -D INSTALL_C_EXAMPLES=ON \
94 | -D INSTALL_PYTHON_EXAMPLES=ON \
95 | -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
96 | -D BUILD_EXAMPLES=ON ..
97 | ```
98 |
99 | **7、makeを行う**
100 | ターミナル上で以下のコマンドを実行します。
101 | ```bash
102 | $ make -j4
103 | $ sudo make install
104 | ```
105 |
106 | **8、OpenCVを適用させる**
107 | ターミナル上で以下のコマンドを実行します。
108 | ```bash
109 | $ sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
110 | $ sudo ldconfig
111 | $ echo PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig >> ~/bash.bashrc
112 | $ echo export PKG_CONFIG_PATH >> ~/bash.bashrc && cat ~/bash.bashrc
113 | ```
114 |
115 | RealSense SDK 2.0のインストール
116 | ---------------------------
117 | **1、サーバーの公開鍵を登録**
118 | ターミナル上で以下のコマンドを実行します。
119 | ```bash
120 | $ sudo apt-key adv --keyserver keys.gnupg.net --recv-key C8B3A55A6F3EFCDE || \
121 | sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key C8B3A55A6F3EFCDE
122 | ```
123 |
124 | **2、リポジトリリストにサーバーの登録**
125 | ターミナル上で以下のコマンドを実行します。
126 | ```bash
127 | $ sudo add-apt-repository "deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial main" -u
128 | ```
129 |
130 | **3、実行用ツールのインストール**
131 | ターミナル上で以下のコマンドを実行します。
132 | ```bash
133 | $ sudo apt-get install librealsense2-dkms
134 | $ sudo apt-get install librealsense2-utils
135 | ※インストールが成功すれば以下コマンドでRealsense Viewer
136 | を起動できるようになります。
137 | $ realsense-viewer
138 | ```
139 |
140 | **4、開発者用ツールのインストール**
141 | ターミナル上で以下のコマンドを実行します。
142 | ```bash
143 | $ sudo apt-get install librealsense2-dev
144 | $ sudo apt-get install librealsense2-dbg
145 | ```
146 |
147 | **5、RealSense SDKのbuildバージョン確認**
148 | 実行時にmakeするファイルが2.15.0以下と2.16.0以上で異なるため、インストールしたSDKのバージョン確認を行います。
149 | ```bash
150 | $ sudo apt-cache policy librealsense2-dev
151 | $ sudo apt-cache policy librealsense2-dbg
152 | ```
153 | 以下のように`インストールされているバージョン:`がbuildバージョンとなります。
154 | ```bash
155 | librealsense2-dev:
156 | インストールされているバージョン: 2.16.0-0~realsense0.84
157 | 候補: 2.16.0-0~realsense0.85
158 | バージョンテーブル:
159 | 2.16.0-0~realsense0.85 500
160 | 500 http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial/main amd64 Packages
161 | *** 2.16.0-0~realsense0.84 500
162 | 500 http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial/main amd64 Packages
163 | 100 /var/lib/dpkg/status
164 | 2.15.0-0~realsense0.83 500
165 | 500 http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial/main amd64 Packages
166 | (以下省略)
167 | ```
168 |
169 | 実行
170 | ---------------------------
171 | **1、実行前準備**
172 | ターミナル上でNDIをインストールしたディレクトリに移動します。
173 | ```bash
174 | $ cd “インストールしたディレクトリ”/”NDI SDK for Linux”/examples/C++
175 | ```
176 |
177 |
178 | 以下のコマンドでC++フォルダの中にMakefile及びMakefile.projがあることを確認します。
179 | ```bash
180 | $ ll Makefile*
181 | ```
182 |
183 | Makefile.projをvimまたはテキストエディターなどで編集します。
184 | 3行目のCXXFLAGSを以下のように変更して下さい。
185 | ```d
186 | CXXFLAGS = -std=c++11 -pthread -MMD -I../../../include
187 | ```
188 |
189 | 5行目を以下のように変更して下さい。
190 | ```d
191 | LDLIBS = -lm -lndi -ldl -lpthread -lopencv_core -lopencv_imgcodecs -lopencv_highgui \
192 | -lopencv_videoio -lopencv_imgproc -lrealsense2
193 | ```
194 |
195 | 30行目も以下のように変更して下さい。
196 | ```d
197 | $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
198 | ```
199 |
200 | 続いて実行用のフォルダを作ります。
201 | ``` bash
202 | $ mkdir NDI-Vidoe-Sender
203 | ```
204 | Makefileを編集します。
205 | 8行目のPROJECTSを以下のように変更して下さい。
206 | ```d
207 | PROJECTS = \
208 | NDI-Video-Sender \
209 | ```
210 |
211 | **2、実行**
212 | **RealSense SDKのbuildバージョンによってソースファイルが異なりますので注意が必要です。**
213 | * バージョン2.15以下の場合
214 | `NDI-Video-Sender2.15`のフォルダ内のソースファイル及びコンフィグファイルをご利用下さい。
215 |
216 | * バージョン2.16以上の場合
217 | `NDI-Video-Sender-2.16`のフォルダ内のソースファイル及びコンフィグファイルをご利用下さい。
218 |
219 | 先程作りましたフォルダに実行したいソースファイル及びコンフィグファイルをコピーします。
220 | ```bash
221 | $ cd “コピーしたいソースファイルのあるディレクトリ”
222 | $ cp * “インストールしたディレクトリ”/”NDI SDK for Linux”/examples/C++/NDI-Video-Sender/
223 | ```
224 |
225 | コピーが完了したら、再度C++フォルダに戻ります。
226 | ```bash
227 | $ cd “インストールしたディレクトリ”/”NDI SDK for Linux”/examples/C++
228 | ```
229 |
230 | 以下コマンドでMakeを実行します。
231 | ```bash
232 | $ make
233 | ```
234 | エラーが発生しなければビルド成功です。
235 | ※以下のようなエラーが発生する場合、RealSense SDKのbuildバージョンと一致しているか再確認して下さい。
236 | ```bash
237 | Realsense.cpp:156:54: error: no match for call to ‘(rs2::colorizer) (rs2::depth_frame)’
238 | depth_frame = color_map(frameset.get_depth_frame());
239 | ^
240 | ```
241 |
242 | ソースファイルをおいたフォルダに移動します。
243 | ```bash
244 | $ cd NDI-Video-Sender
245 | ```
246 | 以下コマンドで実行します。
247 | ```bash
248 | $ ./NDI-Video-Sender X(Xには送信したいカメラ番号を指定)
249 | ```
250 |
251 | NDI-Video-Receiverを実行する際も同様の流れ(NDI-Video-Senderの箇所をNDI-Video-Receiverに変更となります。
252 |
253 | **3、ソースの修正後再度実行するまで**
254 | make済みのソースファイルを修正した場合、make clean後再度makeする必要があります。
255 | ```bash
256 | $ make clean
257 | $ make
258 | ```
259 |
--------------------------------------------------------------------------------
/Installation manual(Windows).md:
--------------------------------------------------------------------------------
1 | 環境構築手順書 ~Windows編~
2 | =======
3 |
4 | 開発/実行環境について
5 | -------------------
6 | * OS:Windows 10 Pro 64bit
7 |
8 | * IDE:Visual Studio 2017 Community
9 |
10 | * 使用ライブラリ :
11 | Newtek NDI バージョン3.5
12 | OpenCV バージョン3.2.0
13 | RealSense バージョン 2.0(buildバージョン2.16.0 )
14 |
15 | Visual Studio 2017 Communityのインストール
16 | --------------------
17 | **1、Visual Studio 2017 Communityのダウンロード**
18 | 以下よりダウンロードを行います。
19 | https://visualstudio.microsoft.com/ja/thank-you-downloading-visual-studio/?sku=Community&rel=15
20 |
21 | **2、インストール**
22 | Visual Studio Instllerを起動します。
23 | 続行ボタンを押します。
24 | 
25 |
26 | エディションの選択画面が出るのでCommunityを選択します。
27 | 
28 |
29 | ワークロード画面が出ましたら、
30 | ①C++によるデスクトップ開発にチェックを入れます。
31 | ②Windows SDKのチェックを入れます。
32 | ③インストールボタンを押します。
33 | 
34 |
35 | インストールが完了するまでしばらく待ちます。
36 |
37 | NewTek NDI SDK v3.5のインストール
38 | --------------------
39 | **1、NewTek NDI SDK v3.5をダウンロード**
40 | 以下よりダウンロードを行います。
41 | https://jp.newtek.com/ndi/sdk/
42 | ダウンロード時に名前やメールアドレスなどの送信が必要です。
43 |
44 | **2、インストール**
45 | インストーラーを起動します。
46 | I accept the agreementにチェックを入れてNextをクリックします。
47 | 
48 |
49 | Installを押してしばらく待ちます。
50 | 
51 |
52 | `C:\Program Files\`の中に`NewTek`フォルダがればインストールが完了です。
53 |
54 | **3、システムの環境変数にPATHを通す**
55 | システムのプロパティから環境変数をクリックします。
56 | 
57 |
58 | システムの環境変数のPATHを選択し、編集ボタンをクリックします。
59 | 
60 |
61 | 新規ボタンから次の一行を記述します。
62 | ```bash
63 | C:\Program Files\NewTek\NewTek NDI SDK\Bin\x64\
64 | ```
65 | 
66 |
67 | OpenCV v3.2.0のインストール
68 | --------------------
69 | **1、OpenCV v3.2.0をダウンロード**
70 | 以下よりOpenCV 3.2.0をダウンロードします。
71 | https://opencv.org/releases.html
72 |
73 | **2、インストール**
74 | インストーラーを起動します。
75 | `Extract to:`と表示されましたら、パスを以下のように設定します。
76 | ```bash
77 | c:\
78 | ```
79 | 
80 |
81 |
82 | Extractボタンで展開します。
83 | 展開が完了後`C:\`上に`opencv`というフォルダがあるので、フォルダ名を`opencv320`と変更して下さい。
84 | `opencv320`フォルダの直下に`build`フォルダが有るか確認して下さい。
85 |
86 | **3、システムの環境変数にPATHを通す**
87 | システムのプロパティから環境変数をクリックします。
88 | 
89 |
90 | システムの環境変数のPATHを選択し、編集ボタンをクリックします。
91 | 
92 |
93 | 新規ボタンから次の一行を記述します。
94 | ```bash
95 | C:\opencv320\build\x64\vc14\bin\
96 | ```
97 | 
98 |
99 | RealSense SDK 2.0のインストール
100 | ---------------------------
101 | **1、RealSense SDK v2.0をダウンロード**
102 | 以下よりRealSense SDKをダウンロードします。
103 | https://github.com/IntelRealSense/librealsense/releases
104 |
105 | ※buildバージョンによって実行できるプログラムが異なるため気をつけて下さい。
106 |
107 | **2、インストール**
108 | インストーラーを起動します。 I accept the agreementにチェックを入れてNextをクリックします。
109 | 
110 |
111 | すべてのオプションにチェックを入れ、Nextをクリックします。
112 | 
113 |
114 | Nextを押します。
115 | 
116 |
117 | Installを押してしばらく待ちます。
118 | 
119 |
120 | `C:\Program Files (x86)`の中に`Intel RealSense SDK 2.0`フォルダがればインストールが完了です。
121 |
122 | **3、システムの環境変数にPATHを通す**
123 | システムのプロパティから環境変数をクリックします。
124 | 
125 |
126 | システムの環境変数のPATHを選択し、編集ボタンをクリックします。
127 | 
128 |
129 | 新規ボタンから次の一行を記述します。
130 | ```bash
131 | C:\Program Files (x86)\Intel RealSense SDK 2.0\bin\x64\
132 | ```
133 | 
134 |
135 | **4、インストールしたbuildバージョンの確認**
136 | アプリと機能より確認することが可能です。
137 | 
138 |
139 | プロジェクトの実行
140 | ---------------------------
141 | **1、ソリューションファイルを実行します。**
142 | NDI-Video-SenderはRealSense SDKのbuildバージョンによって実行できるものが異なります。
143 | NDI-Video-Receiverはどのバージョンでも実行可能です。
144 | * buildバージョンが`2.15.0`以下の場合
145 | `NDI-Video-Sender2.15`を開き、中にある`NDI-Video-Sender.sln`を実行します。
146 | 
147 |
148 | * buildバージョンが`2.16.0`以上の場合
149 | `NDI-Video-Sender2.16`を開き、中にある`NDI-Video-Sender.sln`を実行します。
150 | 
151 |
152 | プロジェクトソリューションを自前で用意する場合もRealSense SDKのバージョンによって、利用するソースファイルが異なるため、必ず確認して下さい。
153 |
154 | Visual Studio環境整備
155 | ---------------------------
156 | **1、Visual Studioにインクルードディレクトリのパスを通す**
157 | メニューバーのプロジェクトからプロパティを開きます。
158 | 
159 |
160 | VC++ ディレクトリタブを選択します。
161 | インクルード ディレクトリを選択し<編集...>から編集を行います。
162 | 
163 |
164 | ①フォルダマークをクリックします。
165 | ②...ボタンが出現するのでクリックします。
166 | 
167 |
168 | NDIのインクルードディレクトリを選択します。パスは以下の通りです。
169 | ```bash
170 | C:\Program Files\NewTek\NewTek NDI SDK\Include
171 | ```
172 | 
173 |
174 | 続いて再度フォルダマークを押し、...からOpenCVのインクルードディレクトリを選択します。パスは以下の通りです。
175 | ```bash
176 | C:\opencv320\build\include
177 | ```
178 | 
179 |
180 | 再度フォルダマークを押し、...からRealSenseのインクルードディレクトリを選択します。パスは以下の通りです。
181 | ```bash
182 | C:\Program Files (x86)\Intel RealSense SDK 2.0\include
183 | ```
184 | 
185 |
186 | **2、ライブラリディレクトリのパスを通す**
187 | インクルード ディレクトリと同じようにでライブラリ ディレクトリのパスを通します。
188 | NDIのライブラリディレクトリのパスは以下の通りです。
189 | ```bash
190 | C:\Program Files\NewTek\NewTek NDI SDK\Lib\x64
191 | ```
192 | 
193 |
194 | OpenCVのライブラリディレクトリは以下の通りです。
195 | ```bash
196 | C:\opencv320\build\x64\vc14\lib
197 | ```
198 | 
199 |
200 | RealSenseのライブラリディレクトリは以下の通りです。
201 | ```bash
202 | C:\Program Files (x86)\Intel RealSense SDK 2.0\lib\x64
203 | ```
204 | 
205 |
206 | **3、追加の依存ファイルの追加**
207 | リンカーから入力を選択し、追加の依存ファイルを選択し<編集...>から編集を行います。
208 | 
209 |
210 | 以下の3行を追記します。
211 | ```bash
212 | opencv_world320.lib
213 | Processing.NDI.Lib.x64.lib
214 | realsense2.lib
215 | ```
216 | 
217 |
218 | **4、その他の設定**
219 | C/C++タブから詳細設定タブを開きます。
220 | 指定の警告を無効にするを選択し、`4996`を追加します。
221 | 
222 |
223 | また、プリコンパイル済みヘッダータブを選択します。
224 | プリコンパイル済みヘッダーを使用からプリコンパイル済みヘッダーを使用しないに変更します。
225 | 
226 |
227 | 更に、コマンドラインタブを選択します。
228 | 以下の追加のオプションで`/source-charset:utf-8`を入力します。
229 | 
230 |
231 | Ctrl+Alt+Eキーを押し、例外設定を開きます。
232 | Win32 Exceptionsを選択し、Control-Cのチェックを外します。
233 | 
234 |
235 | Visual Studio上で実行
236 | ---------------------------
237 | **1、実行前準備**
238 | プロジェクトのプロパティを開きます。
239 | デバックタブを選択し、コマンド引数を指定します。
240 | 指定する値はカメラの番号1~6です。
241 | 
242 |
243 | ReleaseまたはDebugのx64に設定されていることを確認して下さい。
244 | 
245 |
246 | **2、実行**
247 | ローカル Windowsデバッガーをクリックします。
248 | デバッグが始まるので、しばらく待ちます。
249 | エラーなく送信または受信できれば無事導入は完了です。
250 | 
251 |
252 | 以下のようにDLLが見つからない場合、環境変数のPATHの設定が間違っています。
253 | 今一度以下のように設定されているか確認して下さい。
254 | ```bash
255 | C:\Program Files\NewTek\NewTek NDI SDK\Bin\x64;
256 | C:\opencv320\build\x64\vc14\bin
257 | ```
258 | 
259 | 
260 |
261 | それでもDLLが見つからない場合、ソースファイルのフォルダに直接DLLを置きます。
262 |
263 | 実行ファイルを直接実行する
264 | ---------------------------
265 | **1、exeファイルと同じ場所にコンフィグファイルを配置**
266 | NDI-Video-Senderの場合:
267 | コンフィグファイルの場所
268 | ```bash
269 | NDI-Video-Sender\NDI-Video-Sender\NdiVideoSender.config
270 | ```
271 | 
272 |
273 | コンフィグを以下のフォルダに配置して下さい。
274 | ```bash
275 | \NDI-Video-Sender\x64\Release
276 | ```
277 | または
278 | ```bash
279 | \NDI-Video-Sender\x64\Debug
280 | ```
281 | 
282 |
283 | NDI-Video-ReceiverもNDI-Video-Senderと同様に配置します。
284 | コンフィグファイルを編集します。
285 |
286 | **2、実行**
287 | コマンド・プロンプトを開きます。
288 | 以下のコマンドを入力します。
289 | ```bash
290 | cd “フォルダまでの場所”\NDI-Video-Sender\x64\Release
291 | ```
292 | 
293 |
294 | exeファイル名を入力し、コンフィグファイルで指定したカメラ番号に対応する起動引数を入力しEnterを押します。
295 | 
296 |
297 | 停止する際はCtrl+Cを押します。
298 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 2-Clause License
2 |
3 | Copyright (c) 2018, jadsys
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
--------------------------------------------------------------------------------
/Makefile/Makefile:
--------------------------------------------------------------------------------
1 | ifeq ($(NDILIB),)
2 | CC ?= gcc
3 | NDILIB = $(shell $(CC) -dumpmachine)
4 | endif
5 |
6 | BMDSDK = NDIlib_Send_BMD/BMDSDK/Linux
7 |
8 | PROJECTS = \
9 | NDI-Video-Receiver \
10 | NDI-Video-Sender \
11 |
12 |
13 | .PHONY: all
14 | all:
15 | @test -d ../../lib/$(NDILIB) || (echo NDILIB not found: $(NDILIB) >&2 ; false)
16 | -@for proj in $(PROJECTS); do \
17 | $(MAKE) -C $$proj -f ../Makefile.proj NDILIB=$(NDILIB); \
18 | done
19 |
20 | .PHONY: clean
21 | clean:
22 | -@for proj in $(PROJECTS); do \
23 | $(MAKE) -C $$proj -f ../Makefile.proj clean; \
24 | done
25 |
26 |
--------------------------------------------------------------------------------
/Makefile/Makefile.proj:
--------------------------------------------------------------------------------
1 | CC = gcc
2 | CXX = g++
3 | CXXFLAGS = -std=c++11 -pthread -MMD -I../../../include
4 | LDFLAGS = -L../../../lib/$(NDILIB) -Wl,-rpath='$$ORIGIN'
5 | LDLIBS = -lm -lndi -ldl -lpthread -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_videoio -lopencv_imgproc -lrealsense2
6 | RM = @rm
7 | LN = @ln
8 | SRC = $(wildcard *.cpp)
9 | PROJ = $(shell basename "$(CURDIR)")
10 | NDILIBFILE = libndi.so.3
11 |
12 | ifneq ($(findstring BMD,$(PROJ)),)
13 | CXXFLAGS += -IBMDSDK/Linux/include
14 | endif
15 |
16 | .SUFFIXES:
17 | .SUFFIXES: .cpp
18 |
19 | .PHONY: all
20 | all: $(PROJ) $(NDILIBFILE)
21 |
22 | .PHONY: clean
23 | clean:
24 | -$(RM) -f $(PROJ) $(NDILIBFILE)
25 |
26 | $(NDILIBFILE): ../../../lib/$(NDILIB)/$(NDILIBFILE)
27 | $(LN) -s ../../../lib/$(NDILIB)/$(NDILIBFILE)
28 |
29 | $(PROJ): $(SRC)
30 | $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
31 |
32 | # vim: syntax=make
33 |
--------------------------------------------------------------------------------
/NDI-Video-Receiver/NDI-Video-Receiver.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26730.15
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NDI-Video-Receiver", "NDI-Video-Receiver\NDI-Video-Receiver.vcxproj", "{C91C991C-BF39-4164-B0E6-696C09BC9D9D}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {C91C991C-BF39-4164-B0E6-696C09BC9D9D}.Debug|x64.ActiveCfg = Debug|x64
17 | {C91C991C-BF39-4164-B0E6-696C09BC9D9D}.Debug|x64.Build.0 = Debug|x64
18 | {C91C991C-BF39-4164-B0E6-696C09BC9D9D}.Debug|x86.ActiveCfg = Debug|Win32
19 | {C91C991C-BF39-4164-B0E6-696C09BC9D9D}.Debug|x86.Build.0 = Debug|Win32
20 | {C91C991C-BF39-4164-B0E6-696C09BC9D9D}.Release|x64.ActiveCfg = Release|x64
21 | {C91C991C-BF39-4164-B0E6-696C09BC9D9D}.Release|x64.Build.0 = Release|x64
22 | {C91C991C-BF39-4164-B0E6-696C09BC9D9D}.Release|x86.ActiveCfg = Release|Win32
23 | {C91C991C-BF39-4164-B0E6-696C09BC9D9D}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {34734BA3-0792-4ADE-B3A6-46452C537B98}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/NDI-Video-Receiver/NDI-Video-Receiver/ConfigRead.cpp:
--------------------------------------------------------------------------------
1 | #include "ConfigRead.h"
2 |
3 | using namespace std;
4 |
5 | /****************************************************************************
6 | *
7 | * コンストラクタ・デストラクタ
8 | *
9 | *****************************************************************************/
10 | /* コンストラクタ */
11 | ConfigRead::ConfigRead()
12 | {
13 | // 初期化
14 | m_defvalue = "";
15 | m_int_defvalue = 0;
16 | }
17 |
18 | /* デストラクタ */
19 | ConfigRead::~ConfigRead()
20 | {
21 | // 処理なし
22 | }
23 |
24 | /****************************************************************************
25 | *
26 | * getterメソッド
27 | *
28 | *****************************************************************************/
29 | /* コンフィグからの値取得 */
30 | string ConfigRead::GetStringProperty(string op_name)
31 | {
32 | return (readConfigFile(op_name));
33 | }
34 |
35 | /* デフォルト値の読み込み */
36 | string ConfigRead::getDefaultValue()
37 | {
38 | return (m_defvalue);
39 | }
40 |
41 | /****************************************************************************
42 | *
43 | * setterメソッド
44 | *
45 | *****************************************************************************/
46 | /* デフォルト値の設定 */
47 | void ConfigRead::setDefaltValue(string op_name)
48 | {
49 | // op_nameに入ってきたオプションに一致するデフォルト値が入る
50 | if (!op_name.find("Resources_ID_CH"))
51 | {
52 | m_defvalue = ""; // デフォルトは空文字
53 | m_int_defvalue = 1; // 設定項目番号
54 | }
55 | }
56 |
57 | /****************************************************************************
58 | *
59 | * ファイル読み込み
60 | *
61 | *****************************************************************************/
62 | string ConfigRead::readConfigFile(string op_name)
63 | {
64 | string str_cnf; // 1行分のコンフィグデータ格納
65 | string str_property; // プロパティ格納用
66 |
67 | // 検索前の初期化
68 | setDefaltValue(op_name);
69 |
70 | // configファイル読み込み
71 | ifstream iconfig_stream(CONFIG_FILE_NAME);
72 |
73 | // 読み込みチェック
74 | if (!iconfig_stream)
75 | {
76 | printf("ファイル名が%sと一致しているか確認して下さい。\n", CONFIG_FILE_NAME);
77 | return (getDefaultValue()); // 読み込み失敗時defaultを読み込む
78 | }
79 | else
80 | {
81 | while (true)
82 | {
83 | // 一行読み出す
84 | if (getline(iconfig_stream, str_cnf))
85 | {
86 | // コメントと不正な値を弾く
87 | if (str_cnf.find("#") == -1 && str_cnf.find(op_name) != -1)
88 | {
89 | // 読み出した1行からプロパティだけをトリミング
90 | str_property = getProperty(str_cnf, op_name);
91 | break;
92 | }
93 | }
94 | else
95 | {
96 | str_property = getDefaultValue(); // 読み込み失敗時defaultを読み込む
97 | break;
98 | }
99 | }
100 | }
101 | return (str_property);
102 | }
103 |
104 | /****************************************************************************
105 | *
106 | * プロパティ値取り出し
107 | *
108 | *****************************************************************************/
109 | string ConfigRead::getProperty(string conf_data, string op_name)
110 | {
111 | /* プロパティの値を抜き出す */
112 | const char* trimCharacterList = " \t\v\r\n"; // 各特殊文字のトリム用
113 | // ex)lineStr:"Option1 = true \n"
114 | // 右側から最初の文字列を検索
115 | size_t p_end = conf_data.find_last_not_of(trimCharacterList); // lineStr:"Option1 = true"
116 | // =の位置検索
117 | size_t p_start = conf_data.find("=") + 1; // lineStr:" true"
118 | // オプション値の空欄を検出
119 | if (!(p_start < p_end))
120 | {
121 | return (getDefaultValue()); // defaultを読み込む
122 | }
123 | // 左側から最初の文字列を検索
124 | p_start = conf_data.find_first_not_of(trimCharacterList, p_start); // lineStr = "true"
125 |
126 | // プロパティの値の文字の長さ
127 | size_t p_leng = p_end - p_start + 1;
128 |
129 | // プロパティ値だけ抜き出し返す
130 | return (conf_data.substr(p_start, p_leng));
131 | }
132 |
133 |
--------------------------------------------------------------------------------
/NDI-Video-Receiver/NDI-Video-Receiver/ConfigRead.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadsys/NDI-Video-Sender_Receiver/d18ba6f25d7403d4a773d99051ac7cda2f4e8f4a/NDI-Video-Receiver/NDI-Video-Receiver/ConfigRead.h
--------------------------------------------------------------------------------
/NDI-Video-Receiver/NDI-Video-Receiver/NDI-Video-Receiver.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | 15.0
32 | {C91C991C-BF39-4164-B0E6-696C09BC9D9D}
33 | Win32Proj
34 | NDIVideoReceiver
35 | 10.0.15063.0
36 |
37 |
38 |
39 | Application
40 | true
41 | v141
42 | Unicode
43 |
44 |
45 | Application
46 | false
47 | v141
48 | true
49 | Unicode
50 |
51 |
52 | Application
53 | true
54 | v141
55 | Unicode
56 |
57 |
58 | Application
59 | false
60 | v141
61 | true
62 | Unicode
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | true
84 |
85 |
86 | true
87 | C:\opencv320\build\include;C:\opencv320\build\include\opencv;C:\Program Files\NewTek\NewTek NDI SDK\Include;$(IncludePath)
88 | C:\opencv320\build\x64\vc14\lib;C:\Program Files\NewTek\NewTek NDI SDK\Lib\x64;$(LibraryPath)
89 |
90 |
91 | false
92 |
93 |
94 | false
95 | C:\opencv320\build\include;C:\opencv320\build\include\opencv;C:\Program Files\NewTek\NewTek NDI SDK\Include;C:\Program Files %28x86%29\ZBar\include;C:\Program Files %28x86%29\ZBar\include\zbar;$(IncludePath)
96 | C:\opencv320\build\x64\vc14\lib;C:\Program Files\NewTek\NewTek NDI SDK\Lib\x64;$(LibraryPath)
97 |
98 |
99 |
100 |
101 |
102 | Level3
103 | Disabled
104 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
105 | true
106 |
107 |
108 | Console
109 | true
110 |
111 |
112 |
113 |
114 |
115 |
116 | Level3
117 | Disabled
118 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
119 | true
120 |
121 |
122 | 4996
123 | /source-charset:utf-8 %(AdditionalOptions)
124 |
125 |
126 | Console
127 | true
128 | C:\opencv320\build\x64\vc14\lib;D:\AIZU\ZBarWin64-master\x64\Release;C:\Program Files\NewTek\NewTek NDI SDK\Lib\x64
129 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;opencv_world320.lib;Processing.NDI.Lib.x64.lib;%(AdditionalDependencies)
130 |
131 |
132 |
133 |
134 |
135 |
136 | Level3
137 | MaxSpeed
138 | true
139 | true
140 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
141 | true
142 |
143 |
144 | Console
145 | true
146 | true
147 | true
148 |
149 |
150 |
151 |
152 |
153 |
154 | Level3
155 | Disabled
156 | true
157 | true
158 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
159 | true
160 |
161 |
162 | true
163 | 4996
164 | /source-charset:utf-8 %(AdditionalOptions)
165 |
166 |
167 | Console
168 | true
169 | true
170 | true
171 | C:\opencv320\build\x64\vc14\lib;D:\AIZU\ZBarWin64-master\x64\Release;C:\Program Files\NewTek\NewTek NDI SDK\Lib\x64
172 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;opencv_world320.lib;Processing.NDI.Lib.x64.lib;%(AdditionalDependencies)
173 |
174 |
175 |
176 |
177 |
178 |
--------------------------------------------------------------------------------
/NDI-Video-Receiver/NDI-Video-Receiver/NDI-Video-Receiver.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | ヘッダー ファイル
20 |
21 |
22 | ヘッダー ファイル
23 |
24 |
25 |
26 |
27 | ソース ファイル
28 |
29 |
30 | ソース ファイル
31 |
32 |
33 | ソース ファイル
34 |
35 |
36 |
--------------------------------------------------------------------------------
/NDI-Video-Receiver/NDI-Video-Receiver/NDI-Video-Receiver.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1
5 | WindowsLocalDebugger
6 |
7 |
8 | 1
9 | WindowsLocalDebugger
10 |
11 |
--------------------------------------------------------------------------------
/NDI-Video-Receiver/NDI-Video-Receiver/NdiCom.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadsys/NDI-Video-Sender_Receiver/d18ba6f25d7403d4a773d99051ac7cda2f4e8f4a/NDI-Video-Receiver/NDI-Video-Receiver/NdiCom.cpp
--------------------------------------------------------------------------------
/NDI-Video-Receiver/NDI-Video-Receiver/NdiCom.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadsys/NDI-Video-Sender_Receiver/d18ba6f25d7403d4a773d99051ac7cda2f4e8f4a/NDI-Video-Receiver/NDI-Video-Receiver/NdiCom.h
--------------------------------------------------------------------------------
/NDI-Video-Receiver/NDI-Video-Receiver/NdiVideoReceiver.config:
--------------------------------------------------------------------------------
1 | #########################################################################
2 | #
3 | #ユーザー設定ファイル
4 | # 注意
5 | # ・変更する際は=の後のみ変更して下さい。
6 | # ・オプションの順番を変更しないで下さい。
7 | # ・インデントを入れる際は全角スペースを入れないで下さい。
8 | # ・値に#を入れるとコメント文として認識します。
9 | #
10 | #########################################################################
11 | #例:
12 | #
13 | ##CHのリソース名
14 | #CH = Camera_
15 | # ※リソース名はNdiVideoSender.configのResources_ID_CAMと一致していること
16 | #
17 | #########################################################################
18 |
19 | ############# チャンネル1の設定 #############
20 | #CH1のリソース名
21 | Resources_ID_CH1 = Camera_1
22 |
23 | ############# チャンネル2の設定 #############
24 | #CH2のリソース名
25 | Resources_ID_CH2 = Camera_2
26 |
27 | ############# チャンネル3の設定 #############
28 | #CH3のリソース名
29 | Resources_ID_CH3 = Camera_3
30 |
31 | ############# チャンネル4の設定 #############
32 | #CH4のリソース名
33 | Resources_ID_CH4 = Camera_4
34 |
35 | ############# チャンネル5の設定 #############
36 | #CH5のリソース名
37 | Resources_ID_CH5 = Camera_5
38 |
39 | ############# チャンネル6の設定 #############
40 | #CH6のリソース名
41 | Resources_ID_CH6 = Camera_6
--------------------------------------------------------------------------------
/NDI-Video-Receiver/NDI-Video-Receiver/NdiVideoReceiver.cpp:
--------------------------------------------------------------------------------
1 | // NDIVideoReceiver.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
2 | //
3 | #include "NdiCom.h"
4 | #include "ConfigRead.h"
5 |
6 | using namespace std;
7 |
8 | /* グローバル変数 */
9 | static atomic exit_main_loop(false); // メインループの終了フラグ
10 | static atomic exit_find_loop(false); // 検索ループの終了フラグ
11 | NdiCom *ndi_video_rec = NULL; // 受信インスタンス変数の宣言と初期化
12 |
13 | /* シグナルハンドラ */
14 | void sigint_handler(int)
15 | {
16 | // 終了フラグをオン
17 | exit_find_loop = true;
18 | exit_main_loop = true;
19 | }
20 |
21 | /* リソース名を取得 */
22 | string getResourceName(int argv_no)
23 | {
24 | string str_value; // 取得したリソース名を格納する変数
25 | ConfigRead *config_read = new ConfigRead(); // コンフィグ読み込み用インスタンスの生成
26 | str_value = config_read->GetStringProperty("CH" + to_string(argv_no)); // リソース名の取得
27 | delete config_read; // インスタンスの開放
28 |
29 | return (str_value);
30 | }
31 |
32 | int main(int argc, char* argv[])
33 | {
34 | // シグナルハンドラ
35 | signal(SIGINT, sigint_handler); // SIGINTはCtrl+C押されたとき
36 | printf("Press + to exit...\n");
37 |
38 | // NDIの初期化
39 | if (!NDIlib_initialize())
40 | {
41 | printf("Cannot run NDI.\n");
42 | return (0); // CPUがNDIに対応していなければ終了
43 | }
44 |
45 | // ローカル変数宣言
46 | int argv_no = 0; // 起動引数格納用
47 | uint32_t no_sources; // 発見したリソース数格納用
48 | string str_readname;; // configファイルから読み込んだリソース名の格納用
49 | string str_findname; // 発見したリソース名の格納用
50 | NDIlib_find_create_t NDI_find_create_desc; // 検索に必要な構造体定義(デフォルト値)
51 | const NDIlib_source_t* p_sources; // 検索したNDIリソース情報格納用
52 | NDIlib_find_instance_t pNDI_find = NDIlib_find_create_v2(&NDI_find_create_desc); // 検索インスタンス生成
53 |
54 | // 生成チェック
55 | if (!pNDI_find)
56 | {
57 | printf("NDIlib_find_instance_t create failure.\n");
58 | return (0);
59 | }
60 |
61 | // 起動オプションの引数チェック
62 | if (argc != 2 || atoi(argv[1]) <= 0 || NDI_REC_MAX < atoi(argv[1]))
63 | {
64 | printf("起動オプション(カメラ番号1~6)を指定して下さい。プログラムを終了します。\n");
65 | return (0);
66 | }
67 |
68 | argv_no = atoi(argv[1]); // 起動引数をint型に変換して代入
69 |
70 | // リソース名の取得
71 | str_readname = getResourceName(argv_no);
72 |
73 | // コンフィグファイル読み込み失敗時
74 | if (str_readname == "")
75 | {
76 | printf("コンフィグファイルの読み込みに失敗しました。プログラムを終了します。\n");
77 | return (0);
78 | }
79 |
80 | // 検索処理開始
81 | printf("SEARCHING...\n");
82 | while (!exit_find_loop)
83 | {
84 | NDIlib_find_wait_for_sources(pNDI_find, 1000); // 見つかるまで待機(タイムアウト1000msec)
85 | p_sources = NDIlib_find_get_current_sources(pNDI_find, &no_sources); // リソース情報の取得
86 | for (int i = 0; i < (int)no_sources; i++)
87 | {
88 | str_findname = string(p_sources[i].p_ndi_name); // 発見したリソース名の格納
89 |
90 | // 発見したリソース名にconfigから読み込んだリソース名が存在するか?見つからなければ-1が返る
91 | if (str_findname.find(str_readname) != -1)
92 | {
93 | printf("HIT\n");
94 | ndi_video_rec = new NdiCom(argv_no, p_sources[i]); // 受信インスタンスの生成
95 | exit_find_loop = true; // ループ終了フラグオン
96 | break;
97 | }
98 | }
99 | }
100 | NDIlib_find_destroy(pNDI_find); // ファインダの削除
101 |
102 | // メインループ
103 | while (!exit_main_loop)
104 | {
105 | // Sleep
106 | chrono::milliseconds dura(100); // ミリセカンドを表現
107 | this_thread::sleep_for(dura); // 100msの間Sleep
108 |
109 | // Ctrl+Cが押されたか監視
110 | if (!ndi_video_rec->GetIsRecFlg())
111 | {
112 | exit_main_loop = true; // メインループ終了フラグをオン
113 | }
114 | }
115 |
116 | // 終了処理
117 | printf("FREE NDI FRAME...\n");
118 | if (ndi_video_rec)
119 | {
120 | ndi_video_rec->DeleteRecVideoThread(); // 受信Threadの削除
121 | delete ndi_video_rec; // インスタンスの削除
122 | }
123 |
124 | // NDIの削除
125 | NDIlib_destroy();
126 |
127 | return (0);
128 | }
129 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.15/NDI-Video-Sender.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27428.2015
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NDI-Video-Sender-win", "NDI-Video-Sender\NDI-Video-Sender.vcxproj", "{9796FEF8-53A7-47FB-9B66-7926D134996D}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Debug|x64.ActiveCfg = Debug|x64
17 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Debug|x64.Build.0 = Debug|x64
18 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Debug|x86.ActiveCfg = Debug|Win32
19 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Debug|x86.Build.0 = Debug|Win32
20 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Release|x64.ActiveCfg = Release|x64
21 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Release|x64.Build.0 = Release|x64
22 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Release|x86.ActiveCfg = Release|Win32
23 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {6C861C4C-B588-4085-9451-E0D34740A7E2}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.15/NDI-Video-Sender/ConfigRead.cpp:
--------------------------------------------------------------------------------
1 | #include "ConfigRead.h"
2 |
3 | using namespace std;
4 |
5 | /****************************************************************************
6 | *
7 | * コンストラクタ・デストラクタ
8 | *
9 | *****************************************************************************/
10 | /* コンストラクタ */
11 | ConfigRead::ConfigRead()
12 | {
13 | // 初期化
14 | m_defvalue = "";
15 | m_int_defvalue = 0;
16 | }
17 |
18 | /* デストラクタ */
19 | ConfigRead::~ConfigRead()
20 | {
21 | // 処理なし
22 | }
23 |
24 | /****************************************************************************
25 | *
26 | * getterメソッド
27 | *
28 | *****************************************************************************/
29 | /* コンフィグからの値取得(String型) */
30 | string ConfigRead::GetStringProperty(string op_name)
31 | {
32 | string str_read_property = readConfigFile(op_name); // configファイルから読み込んだ生の値を格納用
33 |
34 | // configから読み込んだ値が想定された値かチェック
35 | if (!checkValue(str_read_property))
36 | {
37 | str_read_property = getDefaultValue(op_name); // デフォルトを読み込む
38 | }
39 |
40 | return (str_read_property);
41 | }
42 |
43 | /* コンフィグからの値取得(bool型) */
44 | bool ConfigRead::GetBoolProperty(string op_name)
45 | {
46 | string str_read_property = readConfigFile(op_name); // configファイルから読み込んだ生の値を格納用
47 | bool bool_read_property = false; // bool型に変換した値の格納用
48 |
49 | // configから読み込んだ値が想定された値かチェック
50 | if (!checkValue(str_read_property))
51 | {
52 | // デフォルトの値を読み込む
53 | str_read_property = getDefaultValue(op_name);
54 | }
55 |
56 | // string型→bool型へ変換(デフォルトがfalseのため、falseの変換は必要なし)
57 | // windowsでは標準関数がstricmpになる
58 | // 機能はどちらも大文字小文字関係なく比較を行う
59 | if (strcasecmp(str_read_property.c_str(), "true") == 0)
60 | {
61 | bool_read_property = true;
62 | }
63 |
64 | return (bool_read_property);
65 | }
66 |
67 | /* コンフィグからの値取得(int型) */
68 | int ConfigRead::GetIntProperty(string op_name)
69 | {
70 | string str_read_property = readConfigFile(op_name); // configファイルから読み込んだ生の値を格納用
71 | int int_read_property; // int型に変換した値の格納用
72 |
73 | // configから読み込んだ値が想定された値かチェック
74 | if (!checkValue(str_read_property))
75 | {
76 | // デフォルトの値を読み込む
77 | str_read_property = getDefaultValue(op_name);
78 | }
79 |
80 | // string型→int型へ変換
81 | int_read_property = stoi(str_read_property);
82 |
83 | return (int_read_property);
84 | }
85 |
86 | /* デフォルト値の読み込み */
87 | string ConfigRead::getDefaultValue(string op_name)
88 | {
89 | return (m_defvalue);
90 | }
91 |
92 | /****************************************************************************
93 | *
94 | * setterメソッド
95 | *
96 | *****************************************************************************/
97 | /* デフォルト値の設定 */
98 | void ConfigRead::setDefaltValue(string op_name)
99 | {
100 | // op_nameに入ってきたオプションに一致するデフォルト値が入る
101 | if (!op_name.find("SwitchCamera", 0))
102 | {
103 | m_defvalue = "false";
104 | m_int_defvalue = 1;
105 | }
106 | else if (!op_name.find("Resources"))
107 | {
108 | m_defvalue = "Camera_default";
109 | m_int_defvalue = 2;
110 | }
111 | else if (!op_name.find("Camera_Types"))
112 | {
113 | m_defvalue = "web";
114 | m_int_defvalue = 3;
115 | }
116 | else if (!op_name.find("Camera_ID"))
117 | {
118 | m_defvalue = "0";
119 | m_int_defvalue = 4;
120 | }
121 | else if (!op_name.find("xres"))
122 | {
123 | m_defvalue = "640";
124 | m_int_defvalue = 5;
125 | }
126 | else if (!op_name.find("yres"))
127 | {
128 | m_defvalue = "480";
129 | m_int_defvalue = 6;
130 | }
131 | else if (!op_name.find("FPS"))
132 | {
133 | m_defvalue = "30";
134 | m_int_defvalue = 7;
135 | }
136 | else if (!op_name.find("ColorFormat"))
137 | {
138 | m_defvalue = "1";
139 | m_int_defvalue = 8;
140 | }
141 | else if (!op_name.find("Preview_Show_Flag"))
142 | {
143 | m_defvalue = "true";
144 | m_int_defvalue = 9;
145 | }
146 | else if (!op_name.find("Timecode_Show_Flag"))
147 | {
148 | m_defvalue = "true";
149 | m_int_defvalue = 10;
150 | }
151 |
152 | }
153 |
154 | /****************************************************************************
155 | *
156 | * ファイル読み込み
157 | *
158 | *****************************************************************************/
159 | string ConfigRead::readConfigFile(string op_name)
160 | {
161 | string str_cnf; // 1行分のコンフィグデータ格納
162 | string str_property; // プロパティ格納用
163 |
164 | // 検索前の初期化
165 | setDefaltValue(op_name);
166 |
167 | // configファイル読み込み
168 | ifstream iconfig_stream(CONFIG_FILE_NAME);
169 | if (!iconfig_stream)
170 | {
171 | return (getDefaultValue(op_name)); // 読み込み失敗時defaultを読み込む
172 | }
173 | else
174 | {
175 | while (true)
176 | {
177 | // 一行読み出す
178 | if (getline(iconfig_stream, str_cnf))
179 | {
180 | // コメントと不正な値を弾く
181 | if (str_cnf.find("#") == -1 && str_cnf.find(op_name) != -1)
182 | {
183 | // 読み出した1行からプロパティだけをトリミング
184 | str_property = getProperty(str_cnf, op_name);
185 | break;
186 | }
187 | }
188 | else
189 | {
190 | str_property = getDefaultValue(op_name); // 読み込み失敗時defaultを読み込む
191 | break;
192 | }
193 | }
194 | }
195 | return (str_property);
196 | }
197 |
198 | /****************************************************************************
199 | *
200 | * プロパティ値取り出し
201 | *
202 | *****************************************************************************/
203 | string ConfigRead::getProperty(string conf_data, string op_name)
204 | {
205 | /* プロパティの値を抜き出す */
206 | const char* trimCharacterList = " \t\v\r\n";
207 | // ex)lineStr = "Option1 = true \n"
208 | // 右側から最初の文字列を検索
209 | size_t p_end = conf_data.find_last_not_of(trimCharacterList); // lineStr = "Option1 = true"
210 | // =の位置検索
211 | size_t p_start = conf_data.find("=") + 1; // lineStr = " true"
212 | // オプション値の空欄を検出
213 | if (!(p_start < p_end))
214 | {
215 | return (getDefaultValue(op_name)); // defaultを読み込む
216 | }
217 | // 左側から最初の文字列を検索
218 | p_start = conf_data.find_first_not_of(trimCharacterList, p_start); // lineStr = "true"
219 | // プロパティの値の文字の長さ
220 | size_t p_leng = p_end - p_start + 1;
221 |
222 | // プロパティ値だけ抜き出し返す
223 | return (conf_data.substr(p_start, p_leng));
224 | }
225 |
226 | /****************************************************************************
227 | *
228 | * 中身のチェック
229 | *
230 | *****************************************************************************/
231 | bool ConfigRead::checkValue(string value)
232 | {
233 | switch (m_int_defvalue)
234 | {
235 | case 1: // カメラを使用するか
236 | // windowsでは標準関数がstricmpになる
237 | // 機能はどちらも大文字小文字関係なく比較を行う
238 | if (!strcasecmp(value.c_str(), "true") == 0)
239 | {
240 | return (false);
241 | }
242 | break;
243 |
244 | case 9: // 送信側のタイムコードを表示するか
245 | case 10: // プレビューを表示するか
246 | // windowsでは標準関数がstricmpになる
247 | // 機能はどちらも大文字小文字関係なく比較を行う
248 | if (!strcasecmp(value.c_str(), "false") == 0)
249 | {
250 | return (false);
251 | }
252 | break;
253 | case 3: // リソースのカメラの種類
254 | if ((strcasecmp(value.c_str(), "web") != 0) &&
255 | (strcasecmp(value.c_str(), "ip") != 0) &&
256 | (strcasecmp(value.c_str(), "realsense") != 0) &&
257 | (strcasecmp(value.c_str(), "rs") != 0))
258 | {
259 | return (false);
260 | }
261 | break;
262 | case 2: // リソース名
263 | break;
264 | case 4: // リソース先
265 | try
266 | {
267 | // string→int変換
268 | if (!(0 <= stoi(value)))
269 | {
270 | return (false);
271 | }
272 | break;
273 | }
274 | catch (invalid_argument)
275 | {
276 | break;
277 | }
278 | catch (out_of_range)
279 | {
280 | break;
281 | }
282 | case 5: // フレームサイズxres
283 | try
284 | {
285 | if (!(0 < stoi(value)))
286 | {
287 | return (false);
288 | }
289 | }
290 | catch (invalid_argument)
291 | {
292 | // 数値以外入ってきた場合
293 | return (false);
294 | }
295 | break;
296 | case 6: // フレームサイズyres
297 | try
298 | {
299 | if (!(0 < stoi(value)))
300 | {
301 | return (false);
302 | }
303 | }
304 | catch (invalid_argument)
305 | {
306 | // 数値以外入ってきた場合
307 | return (false);
308 | }
309 | break;
310 | case 7: // フレームレート
311 | try
312 | {
313 | if (!(0 < stoi(value) && stoi(value) <= 250))
314 | {
315 | return (false);
316 | }
317 | }
318 | catch (invalid_argument)
319 | {
320 | // 数値以外入ってきた場合
321 | return (false);
322 | }
323 | break;
324 | case 8: // 色のフォーマット
325 | try
326 | {
327 | if (!(0 < stoi(value) && stoi(value) < 6))
328 | {
329 | return (false);
330 | }
331 | break;
332 | }
333 | catch (invalid_argument)
334 | {
335 | // 数値以外入ってきた場合
336 | return (false);
337 | }
338 | break;
339 | }
340 | return (true);
341 | }
342 |
343 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.15/NDI-Video-Sender/ConfigRead.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 | /* linux����p�w�b�_ */
7 | #ifdef __linux__
8 | #include
9 |
10 | #endif // __linux__
11 | /* Windows����p�w�b�_ */
12 | #ifdef _WIN32
13 | #define strcasecmp stricmp // LinuxとWindowsで標準関数が違う
14 | #endif // _WIN32
15 |
16 | #define CONFIG_FILE_NAME "NdiVideoSender.config"
17 |
18 |
19 | class ConfigRead
20 | {
21 | public:
22 | ConfigRead();
23 | ~ConfigRead();
24 | std::string GetStringProperty(std::string op_name);
25 | bool GetBoolProperty(std::string op_name);
26 | int GetIntProperty(std::string op_name);
27 |
28 | private:
29 | std::string m_defvalue; // デフォルト値格納用
30 | int m_int_defvalue; // 設定項目番号格納用
31 |
32 | std::string getDefaultValue(std::string op_name);
33 | void setDefaltValue(std::string op_name);
34 | std::string getProperty(std::string conf_data, std::string op_name);
35 | bool checkValue(std::string value);
36 | std::string readConfigFile(std::string op_name);
37 |
38 | };
39 |
40 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.15/NDI-Video-Sender/NDI-Video-Sender.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 15.0
23 | {9796FEF8-53A7-47FB-9B66-7926D134996D}
24 | Win32Proj
25 | NDIVideoSender
26 | 10.0.15063.0
27 | NDI-Video-Sender
28 |
29 |
30 |
31 | Application
32 | true
33 | v141
34 | Unicode
35 |
36 |
37 | Application
38 | false
39 | v141
40 | true
41 | Unicode
42 |
43 |
44 | Application
45 | true
46 | v141
47 | Unicode
48 |
49 |
50 | Application
51 | false
52 | v141
53 | true
54 | Unicode
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | true
76 |
77 |
78 | true
79 |
80 |
81 | false
82 | C:\opencv320\build\include;C:\Program Files\NewTek\NewTek NDI SDK\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);
83 | C:\Program Files\NewTek\NewTek NDI SDK\Lib\x64;C:\opencv320\build\x64\vc14\lib;$(LibraryPath)
84 |
85 |
86 | false
87 | C:\opencv320\build\include;C:\Program Files %28x86%29\Intel RealSense SDK 2.0\include;C:\Program Files\NewTek\NewTek NDI SDK\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath)
88 | C:\Program Files %28x86%29\Intel RealSense SDK 2.0\lib\x64;C:\Program Files\NewTek\NewTek NDI SDK\Lib\x64;C:\opencv320\build\x64\vc14\lib;$(LibraryPath)
89 |
90 |
91 |
92 | NotUsing
93 | Level3
94 | Disabled
95 | true
96 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
97 | true
98 |
99 |
100 | Console
101 | true
102 |
103 |
104 |
105 |
106 | NotUsing
107 | Level3
108 | Disabled
109 | true
110 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
111 | true
112 |
113 |
114 | Console
115 | true
116 |
117 |
118 |
119 |
120 | NotUsing
121 | Level3
122 | Disabled
123 | true
124 | true
125 | false
126 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
127 | true
128 | 4996
129 |
130 |
131 | Console
132 | true
133 | true
134 | true
135 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;;opencv_world320.lib;Processing.NDI.Lib.x64.lib;%(AdditionalDependencies)
136 |
137 |
138 |
139 |
140 | NotUsing
141 | Level3
142 | Disabled
143 | true
144 | true
145 | false
146 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
147 | true
148 | 4996
149 |
150 |
151 | Console
152 | true
153 | true
154 | true
155 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;opencv_world320.lib;Processing.NDI.Lib.x64.lib;realsense2.lib;%(AdditionalDependencies)
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.15/NDI-Video-Sender/NDI-Video-Sender.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | ヘッダー ファイル
20 |
21 |
22 | ヘッダー ファイル
23 |
24 |
25 | ヘッダー ファイル
26 |
27 |
28 | ヘッダー ファイル
29 |
30 |
31 |
32 |
33 | ソース ファイル
34 |
35 |
36 | ソース ファイル
37 |
38 |
39 | ソース ファイル
40 |
41 |
42 | ソース ファイル
43 |
44 |
45 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.15/NDI-Video-Sender/NDI-Video-Sender.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 3
5 | WindowsLocalDebugger
6 |
7 |
8 | 1
9 | WindowsLocalDebugger
10 |
11 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.15/NDI-Video-Sender/NdiCom.cpp:
--------------------------------------------------------------------------------
1 | #include "NdiCom.h"
2 |
3 | using namespace std;
4 |
5 | /****************************************************************************
6 | *
7 | * コンストラクタ・デストラクタ
8 | *
9 | *****************************************************************************/
10 | /* コンストラクタ */
11 | NdiCom::NdiCom()
12 | {
13 | // 初期化
14 | m_use_flg = true;
15 | m_exit_snd_loop = true;
16 | m_preview_flg = true;
17 | m_sndtmcode_flg = true;
18 | m_isRecflg = false;
19 | m_pNDI_send = NULL;
20 | m_webcam_no = 0;
21 |
22 |
23 | }
24 |
25 | /* コンストラクタ */
26 | NdiCom::NdiCom(int argv_no)
27 | {
28 | initialize(argv_no);
29 | }
30 |
31 | /* デストラクタ */
32 | NdiCom::~NdiCom()
33 | {
34 | // 処理なし
35 | }
36 |
37 | /* メンバ初期化 */
38 | void NdiCom::initialize(int argv_no)
39 | {
40 | ConfigRead *config_read = new ConfigRead(); // コンフィグファイル読み込み処理用インスタンス
41 | string str_int; // 起動引数で指定した値からカメラ番号を設定するための変数
42 | str_int = "_CAM";
43 | str_int += to_string(argv_no); // 指定したカメラ番号を格納
44 |
45 | setUseFlg(config_read->GetBoolProperty("SwitchCamera" + str_int)); // カメラを使用するかをセット
46 |
47 | // 使用フラグ
48 | if (!GetUseFlg())
49 | {
50 | return;
51 | }
52 |
53 | setResourcesID(config_read->GetStringProperty("Resources_ID" + str_int)); // リソース名をセット
54 | setUseWebCameraFlg(config_read->GetStringProperty("Camera_Types" + str_int)); // WEBカメラかどうかセット
55 |
56 | // WEBカメラならデバイス番号、RealSenseならシリアル番号、IPカメラならURLの指定
57 | if (getWebcamFlg())
58 | {
59 | setCamera(config_read->GetIntProperty("Camera_ID" + str_int)); // WEBカメラのデバイス番号のセット
60 | }
61 | else
62 | {
63 | setCamera(config_read->GetStringProperty("Camera_ID" + str_int)); // Realsenseカメラのシリアル番号及びIPカメラURLのセット
64 | }
65 |
66 | setVideoSz(config_read->GetIntProperty("xres" + str_int), config_read->GetIntProperty("yres" + str_int)); // 解像度をセット
67 | setFps(config_read->GetIntProperty("FPS" + str_int)); // FPS値をセット
68 | setColor(config_read->GetIntProperty("ColorFormat" + str_int)); // 送信するカラーフォーマットをセット
69 | setUseSndTimeCodeFlg(config_read->GetBoolProperty("Timecode_Show_Flag" + str_int)); // タイムスタンプを使用フラグのセット
70 | setUsetPreViewFlg(config_read->GetBoolProperty("Preview_Show_Flag" + str_int)); // imshow使用フラグのセット
71 |
72 | delete config_read; // コンフィグファイル読み込みインスタンスの削除
73 | }
74 |
75 | /****************************************************************************
76 | *
77 | * getterメソッド
78 | *
79 | *****************************************************************************/
80 | /* 使用フラグの取得 */
81 | bool NdiCom::GetUseFlg()
82 | {
83 | return (m_use_flg);
84 | }
85 |
86 | /* ウェブカメラフラグの取得 */
87 | bool NdiCom::getWebcamFlg()
88 | {
89 | bool webcam_flg = true; // webカメラ使用フラグ
90 | if (!strcasecmp(m_camera_types.c_str(), "web") == 0)
91 | {
92 | webcam_flg = false;
93 | }
94 | return (webcam_flg);
95 | }
96 |
97 | /* 送信フラグの取得 */
98 | bool NdiCom::GetIsRecflg()
99 | {
100 | return (m_isRecflg);
101 | }
102 |
103 | /****************************************************************************
104 | *
105 | * setterメソッド
106 | *
107 | *****************************************************************************/
108 | /* リソースの使用フラグの設定 */
109 | void NdiCom::setUseFlg(bool str_use_flg)
110 | {
111 | m_use_flg = str_use_flg;
112 | }
113 |
114 | /* リソースのIDを設定 */
115 | void NdiCom::setResourcesID(string resources_id)
116 | {
117 | m_resources_id = resources_id;
118 | }
119 |
120 | /* 取得する映像サイズの設定 */
121 | void NdiCom::setVideoSz(int xres, int yres)
122 | {
123 | m_xres = xres;
124 | m_yres = yres;
125 | }
126 |
127 | /* FPSの設定 */
128 | void NdiCom::setFps(int sndfps)
129 | {
130 | m_sndfps = sndfps;
131 | }
132 |
133 | /* 送信するカラーフォーマットの設定 */
134 | void NdiCom::setColor(int sndColor)
135 | {
136 | // 現状ではこの設定は固定である
137 | switch (sndColor)
138 | {
139 | case 1:
140 | m_sndNDIColor = NDIlib_FourCC_type_BGRX;
141 | m_sndCVColor = CV_BGR2BGRA;
142 | m_setCVCamColor = CV_FOURCC_DEFAULT;
143 | break;
144 | case 2:
145 | m_sndNDIColor = NDIlib_FourCC_type_BGRA;
146 | m_sndCVColor = CV_BGR2BGRA;
147 | m_setCVCamColor = CV_FOURCC_DEFAULT;
148 | break;
149 | case 3:
150 | m_sndNDIColor = NDIlib_FourCC_type_RGBX;
151 | m_sndCVColor = CV_BGR2RGBA;
152 | m_setCVCamColor = CV_FOURCC_DEFAULT;
153 | break;
154 | case 4:
155 | m_sndNDIColor = NDIlib_FourCC_type_RGBA;
156 | m_sndCVColor = CV_BGR2RGBA;
157 | m_setCVCamColor = CV_FOURCC_DEFAULT;
158 | break;
159 | case 5: // 利用不可
160 | m_sndNDIColor = NDIlib_FourCC_type_UYVY;
161 | m_sndCVColor = CV_YUV2BGRA_UYVY;
162 | m_setCVCamColor = CV_FOURCC('U', 'Y', 'V', 'Y');
163 | break;
164 | }
165 |
166 | }
167 |
168 | /* プレビュー画面の表示フラグのセット */
169 | void NdiCom::setUsetPreViewFlg(bool view_flg)
170 | {
171 | m_preview_flg = view_flg;
172 | }
173 |
174 | /* 送信側タイムコードの使用フラグのセット */
175 | void NdiCom::setUseSndTimeCodeFlg(bool timecode_flg)
176 | {
177 | m_sndtmcode_flg = timecode_flg;
178 | }
179 |
180 | /* カメラの種類のセット */
181 | void NdiCom::setUseWebCameraFlg(string camera_types)
182 | {
183 | m_camera_types = camera_types;
184 | }
185 |
186 | /* 使用するwebカメラのデバイス番号の設定 */
187 | void NdiCom::setCamera(int cam_no)
188 | {
189 | m_webcam_no = cam_no;
190 | }
191 |
192 | /* 使用するipカメラのURLの設定 */
193 | void NdiCom::setCamera(string cam_no)
194 | {
195 | m_other_camera = cam_no;
196 | }
197 |
198 | /****************************************************************************
199 | *
200 | * 送信処理
201 | *
202 | *****************************************************************************/
203 | /* 送信準備 */
204 | void NdiCom::sendCreate()
205 | {
206 | // 送信用インスタンスの生成
207 | NDIlib_send_create_t NDI_send_create_desc;
208 |
209 | // WEBカメラかIPカメラか判定
210 | if (strcasecmp(m_camera_types.c_str(), "web") == 0)
211 | {
212 | // WEBカメラの場合
213 | m_str_resname = string("WebCameraID:") + m_resources_id; // カメラ番号指定
214 | }
215 | else if(strcasecmp(m_camera_types.c_str(), "ip") == 0)
216 | {
217 | // IPカメラの場合
218 | m_str_resname = string("IPCameraID:") + m_resources_id; // URL指定
219 | }
220 | else if (strcasecmp(m_camera_types.c_str(), "rs") == 0 || strcasecmp(m_camera_types.c_str(), "realsense") == 0)
221 | {
222 | // RealSenseカメラの場合
223 | m_str_resname = string("RealSenseID:") + m_resources_id; // シリアル番号指定
224 | }
225 | NDI_send_create_desc.p_ndi_name = m_str_resname.c_str(); // 送信インスタンス
226 | NDI_send_create_desc.clock_video = true; // 送信時間を同期させるかどうか
227 | NDI_send_create_desc.clock_audio = false; // 送信時間を同期させるかどうか
228 | m_pNDI_send = NDIlib_send_create(&NDI_send_create_desc); // NDI送信インスタンス生成
229 |
230 | // インスタンスの生成チェック
231 | if (!m_pNDI_send)
232 | {
233 | printf("Generation failure of the instance.");
234 | }
235 | }
236 |
237 | /* 時刻取得 */
238 | string NdiCom::getCurrentTime()
239 | {
240 | // ローカル変数宣言
241 | time_t crrent_time; // 時間格納用
242 | struct tm *current_time_t; // 暦時刻の格納用
243 | char crrent_time_c[20]; // 時刻格納用変数
244 |
245 | // 時間取得
246 | crrent_time = time(NULL); // 1970/1/1 00:00:00 から現在までの経過秒数を取得
247 | // 取得チェック
248 | if (crrent_time == -1)
249 | {
250 | return ("GET TIME ERROR");
251 | }
252 |
253 | // 日本時間に変更
254 | current_time_t = localtime(&crrent_time);
255 |
256 | // 構造体だと扱いづらいので所定の書式に変換
257 | if (!strftime(crrent_time_c, 128, "%Y/%m/%d %H:%M:%S", current_time_t))
258 | {
259 | return ("GET TIME ERROR"); // 変換失敗時
260 | }
261 |
262 | return (string(crrent_time_c));
263 | }
264 |
265 | /* 映像送信 */
266 | void NdiCom::sndVideo()
267 | {
268 | // ローカル変数宣言
269 | cv::VideoCapture cap; // カメラオープン用変数
270 | cv::Mat myframe, sndframe; // カメラから取得したフレームと送信用フレームのデータを格納するする変数
271 | cv::Point point(30, 30); // フレーム上の座標を指定する
272 | string strTimecode; // 文字列に変換された時間を格納するための変数
273 |
274 | m_isRecflg = true; // 送信フラグオン
275 |
276 |
277 |
278 | // カメラオープン
279 | if (getWebcamFlg())
280 | {
281 | // Webカメラの場合
282 | cap.open(m_webcam_no); // stringをint型に変換
283 | }
284 | else
285 | {
286 | // IPカメラの場合
287 | cap.open(m_other_camera);
288 | }
289 |
290 | // オープンしたカメラデバイスの設定
291 | // cap.set(CV_CAP_PROP_FOURCC, setCVCamColor); // m_setCVCamColor指摘先
292 | cap.set(CV_CAP_PROP_FRAME_WIDTH, m_xres); // 幅
293 | cap.set(CV_CAP_PROP_FRAME_HEIGHT, m_yres); // 高さ
294 | cap.set(CV_CAP_PROP_FPS, m_sndfps); // フレームレート
295 |
296 | // フレームサイズ更新(カメラの性能以上要求によるエラー落ち対策)
297 | m_xres = (int)cap.get(CV_CAP_PROP_FRAME_WIDTH); // 横方向
298 | m_yres = (int)cap.get(CV_CAP_PROP_FRAME_HEIGHT); // 縦方向
299 |
300 | // カメラオープン成功判定
301 | if (!cap.isOpened())
302 | {
303 | // カメラオープン失敗時
304 | if (getWebcamFlg())
305 | {
306 | cout << "Camera_ID " << m_webcam_no << " could not open." << endl; // WEBカメラならカメラ番号
307 | }
308 | else
309 | {
310 | cout << "Camera_ID " << m_other_camera << " could not open." << endl; // IPカメラならURL
311 | }
312 | m_isRecflg = false;
313 | return;
314 | }
315 |
316 | // 送信用インスタンス生成
317 | sendCreate();
318 |
319 | // 映像用フレームの生成と初期化
320 | NDIlib_video_frame_v2_t video_frame;
321 | video_frame.xres = m_xres; // 横方向解像度の指定
322 | video_frame.yres = m_yres; // 縦方向解像度の指定
323 | video_frame.FourCC = NDIlib_FourCC_type_BGRA; // m_sndNDIColor指定先。フレームのカラーフォーマット指定
324 | video_frame.frame_format_type = NDIlib_frame_format_type_interleaved;
325 | video_frame.p_data = (uint8_t*)malloc(m_xres * m_yres * 4); // データサイズの指定
326 | video_frame.line_stride_in_bytes = m_xres * 4;
327 |
328 |
329 |
330 |
331 | // Send Start
332 | printf("%s SENDING...\n", m_resources_id.c_str());
333 | m_exit_snd_loop = false;
334 |
335 | // 送信処理
336 | while (!m_exit_snd_loop)
337 | {
338 | // カメラから読み込み
339 | cap.read(myframe);
340 |
341 | // 読み込んだフレームが空か
342 | if (myframe.empty())
343 | {
344 | continue;
345 | }
346 |
347 | // タイムスタンプ挿入するか
348 | if (m_sndtmcode_flg)
349 | {
350 | // タイムスタンプ挿入
351 | strTimecode = getCurrentTime();
352 | cv::putText(
353 | myframe, // 画像
354 | strTimecode, // 文字列
355 | point, // 座標
356 | cv::FONT_HERSHEY_SIMPLEX, // フォントの種類
357 | 0.8, // 文字の大きさ
358 | cv::Scalar(255, 255, 255), // 文字の色
359 | 3 // 線の太さ
360 | );
361 | cv::putText( // インラインフォント
362 | myframe, // 画像
363 | strTimecode, // 文字列
364 | point, // 座標
365 | cv::FONT_HERSHEY_SIMPLEX, // フォントの種類
366 | 0.8, // 文字の大きさ
367 | cv::Scalar(0, 0, 0), // 文字の色
368 | 1, // 線の太さ
369 | CV_AA // アンチエイリアス
370 | );
371 | }
372 | cv::cvtColor(myframe, sndframe, CV_BGR2BGRA); // m_sndCVColorの指定先。色の変換(NDI送信用フレームに乗せるにはBGRXに変換する必要がある)
373 |
374 | memcpy((void*)video_frame.p_data, sndframe.data, (m_xres * m_yres * 4)); // OpenCVのフレームをNDIフレームデータにコピー
375 |
376 | // 送信
377 | NDIlib_send_send_video_v2(m_pNDI_send, &video_frame);
378 |
379 | if (m_preview_flg)
380 | {
381 | cv::imshow(m_str_resname, sndframe); // 画像を表示
382 |
383 | // キー入力を待つ
384 | switch (cv::waitKey(1))
385 | {
386 | case 3: // imshow中にCtrl+cが入力されたら終了
387 | case 227: // windowsだとCtrl+cは3、LinuxだとCtrl+cが正しく認識できない。227が返る
388 | m_exit_snd_loop = true;
389 | cv::destroyWindow(m_str_resname);
390 | break;
391 | default:
392 | break;
393 | }
394 | }
395 | }
396 | free(video_frame.p_data); // 映像フレームのデータ領域を解放
397 | NDIlib_send_destroy(m_pNDI_send); // 送信用フレームの開放
398 | m_isRecflg = false;
399 | }
400 |
401 | /* 送信Threadの作成 */
402 | void NdiCom::CretateSndVideoThread()
403 | {
404 | if (m_use_flg)
405 | {
406 | m_isRecflg = true; // 送信フラグオン
407 | m_thread_video = thread(&NdiCom::sndVideo, this);
408 | }
409 | }
410 |
411 | /* 送信Threadの開放 */
412 | void NdiCom::DeleteSndVideoThread()
413 | {
414 | for (;;) // 無限ループ
415 | {
416 | if (!m_exit_snd_loop)
417 | {
418 | m_exit_snd_loop = true; // 送信ループ終了フラグオン
419 | }
420 |
421 | // Sleep
422 | chrono::milliseconds dura(100);
423 | this_thread::sleep_for(dura);
424 |
425 | // 送信処理終了済みまで待機
426 | if (!GetIsRecflg())
427 | {
428 | if (!GetUseFlg())
429 | {
430 | break;
431 | }
432 | // join可能か判定
433 | if (m_thread_video.joinable())
434 | {
435 | m_thread_video.join(); // スレッドをjoinするまで待機
436 | break; // forループ抜ける
437 | }
438 | }
439 | }
440 | }
--------------------------------------------------------------------------------
/NDI-Video-Sender2.15/NDI-Video-Sender/NdiCom.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include "ConfigRead.h"
12 |
13 | /* linux動作用ヘッダ */
14 | #ifdef __linux__
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include // cv::cvtColor
24 | #include
25 | #include
26 |
27 | #endif // __linux__
28 |
29 | /* Windows動作用ヘッダ */
30 | #ifdef _WIN32
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 | #define strcasecmp stricmp // LinuxとWindowsで標準関数が違う
37 | #endif
38 |
39 | #define NDI_SND_MAX 6
40 |
41 |
42 | class NdiCom
43 | {
44 | public:
45 | NdiCom();
46 | NdiCom(int argv_no);
47 | ~NdiCom();
48 | bool GetUseFlg();
49 | bool GetIsRecflg();
50 | virtual void CretateSndVideoThread();
51 | void DeleteSndVideoThread();
52 |
53 | protected:
54 | NDIlib_send_instance_t m_pNDI_send; // 送信インスタンス
55 | int m_xres, m_yres; // 解像度
56 | int m_sndfps; // FPS指定用
57 | bool m_use_flg; // 使用フラグ
58 | bool m_preview_flg; // imshowフラグ
59 | bool m_sndtmcode_flg; // タイムスタンプ挿入フラグ
60 | bool m_exit_snd_loop; // 送信ループ終了フラグ
61 | bool m_isRecflg; // 送信処理フラグ
62 | std::string m_resources_id; // リソース番号格納用
63 | std::string m_other_camera; // ipカメラ番号格納用
64 | std::string m_str_resname; // 送信リソース名格納用
65 | std::thread m_thread_video; // 送信用Thread
66 |
67 | virtual void sndVideo();
68 | std::string getCurrentTime();
69 | void sendCreate();
70 |
71 | private:
72 | NDIlib_FourCC_type_e m_sndNDIColor; // 送信カラーフォーマット
73 | int m_sndCVColor; // 変換するカラーフォーマットの指定
74 | int m_setCVCamColor; // カメラデバイスのカラーフォーマット
75 | int m_webcam_no; // カメラ番号格納用
76 | std::string m_camera_types; // カメラの種類
77 |
78 | void initialize(int argv_no);
79 | bool getWebcamFlg();
80 | void setUseFlg(bool str_use_flg);
81 | void setResourcesID(std::string resources_id);
82 | void setVideoSz(int xres, int yres);
83 | void setFps(int sndfps);
84 | void setColor(int sndColor);
85 | void setUsetPreViewFlg(bool view_flg);
86 | void setUseSndTimeCodeFlg(bool timecode_flg);
87 | void setUseWebCameraFlg(std::string webcam_flg);
88 | void setCamera(int cam_no);
89 | void setCamera(std::string cam_no);
90 | };
91 |
92 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.15/NDI-Video-Sender/NdiVideoSender.config:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadsys/NDI-Video-Sender_Receiver/d18ba6f25d7403d4a773d99051ac7cda2f4e8f4a/NDI-Video-Sender2.15/NDI-Video-Sender/NdiVideoSender.config
--------------------------------------------------------------------------------
/NDI-Video-Sender2.15/NDI-Video-Sender/NdiVideoSender.cpp:
--------------------------------------------------------------------------------
1 | // NDI-Video-Sender-win.cpp : アプリケーションのエントリ ポイントを定義します。
2 | #include "NdiCom.h"
3 | #include "ConfigRead.h"
4 | #include "Realsense.h"
5 |
6 | using namespace std;
7 |
8 | /* グローバル変数 */
9 | static atomic exit_main_loop(false); // メインループの終了フラグ
10 | NdiCom *ndi_video_snd = NULL;
11 |
12 | /* シグナルハンドラ */
13 | void sigint_handler(int)
14 | {
15 | exit_main_loop = true;
16 | }
17 |
18 |
19 |
20 |
21 | int main(int argc, char *argv[])
22 | {
23 | // シグナルハンドラ
24 | signal(SIGINT, sigint_handler); // SIGINTはCtrl+C押されたとき
25 | puts("Press + to exit...");
26 |
27 | // NDIの初期化
28 | if (!NDIlib_initialize())
29 | {
30 | printf("Cannot run NDI.\n");
31 | return (0); // CPUがNDIに対応していなければ終了
32 | }
33 |
34 | // ローカル変数宣言
35 | int argv_no = 0;
36 |
37 | // 起動オプションの引数チェック
38 | if (argc != 2 || (atoi(argv[1]) <= 0 || NDI_SND_MAX < atoi(argv[1])))
39 | {
40 | printf("起動オプション(カメラ番号1~6)を指定して下さい。プログラムを終了します。\n");
41 | return (0);
42 | }
43 |
44 | argv_no = atoi(argv[1]); // 起動引数をint型に変換して代入
45 |
46 | // NDI送信インスタンス生成
47 | ConfigRead config_read;
48 | string camera_types = config_read.GetStringProperty("Camera_Types_CAM" + string(argv[1]));
49 | if (strcasecmp(camera_types.c_str(), "rs") == 0 || strcasecmp(camera_types.c_str(), "realsense") == 0)
50 | {
51 | ndi_video_snd = new Realsense(argv_no);
52 | }
53 | else
54 | {
55 | ndi_video_snd = new NdiCom(argv_no);
56 | }
57 |
58 | // 送信フラグチェック
59 | if(!ndi_video_snd->GetUseFlg())
60 | {
61 | printf("カメラ%dのSwitchCameraの設定が使用しない(false)になっているため終了致します。\n", argv_no);
62 | delete ndi_video_snd; // インスタンス削除
63 | return (0);
64 | }
65 |
66 | // 送信スレッド開始
67 | ndi_video_snd->CretateSndVideoThread(); // 送信用Thread作成
68 |
69 | // メインループ
70 | while (!exit_main_loop)
71 | {
72 | // Sleep
73 | chrono::milliseconds dura(1000);
74 | this_thread::sleep_for(dura);
75 |
76 | // Ctrl+Cが押されたか監視
77 | if (!ndi_video_snd->GetIsRecflg())
78 | {
79 | exit_main_loop = true; // メインループ終了
80 | }
81 |
82 | }
83 |
84 | // 終了処理
85 | printf("FREE NDI FRAME...\n");
86 | if (ndi_video_snd)
87 | {
88 | ndi_video_snd->DeleteSndVideoThread(); // 受信Threadの削除
89 | delete ndi_video_snd; // インスタンス開放
90 | }
91 |
92 | // NDIの削除
93 | NDIlib_destroy();
94 |
95 | return (0);
96 | }
97 |
98 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.15/NDI-Video-Sender/Realsense.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadsys/NDI-Video-Sender_Receiver/d18ba6f25d7403d4a773d99051ac7cda2f4e8f4a/NDI-Video-Sender2.15/NDI-Video-Sender/Realsense.cpp
--------------------------------------------------------------------------------
/NDI-Video-Sender2.15/NDI-Video-Sender/Realsense.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadsys/NDI-Video-Sender_Receiver/d18ba6f25d7403d4a773d99051ac7cda2f4e8f4a/NDI-Video-Sender2.15/NDI-Video-Sender/Realsense.h
--------------------------------------------------------------------------------
/NDI-Video-Sender2.16/NDI-Video-Sender.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27428.2015
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NDI-Video-Sender-win", "NDI-Video-Sender\NDI-Video-Sender.vcxproj", "{9796FEF8-53A7-47FB-9B66-7926D134996D}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Debug|x64.ActiveCfg = Debug|x64
17 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Debug|x64.Build.0 = Debug|x64
18 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Debug|x86.ActiveCfg = Debug|Win32
19 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Debug|x86.Build.0 = Debug|Win32
20 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Release|x64.ActiveCfg = Release|x64
21 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Release|x64.Build.0 = Release|x64
22 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Release|x86.ActiveCfg = Release|Win32
23 | {9796FEF8-53A7-47FB-9B66-7926D134996D}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {6C861C4C-B588-4085-9451-E0D34740A7E2}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.16/NDI-Video-Sender/ConfigRead.cpp:
--------------------------------------------------------------------------------
1 | #include "ConfigRead.h"
2 |
3 | using namespace std;
4 |
5 | /****************************************************************************
6 | *
7 | * コンストラクタ・デストラクタ
8 | *
9 | *****************************************************************************/
10 | /* コンストラクタ */
11 | ConfigRead::ConfigRead()
12 | {
13 | // 初期化
14 | m_defvalue = "";
15 | m_int_defvalue = 0;
16 | }
17 |
18 | /* デストラクタ */
19 | ConfigRead::~ConfigRead()
20 | {
21 | // 処理なし
22 | }
23 |
24 | /****************************************************************************
25 | *
26 | * getterメソッド
27 | *
28 | *****************************************************************************/
29 | /* コンフィグからの値取得(String型) */
30 | string ConfigRead::GetStringProperty(string op_name)
31 | {
32 | string str_read_property = readConfigFile(op_name); // configファイルから読み込んだ生の値を格納用
33 |
34 | // configから読み込んだ値が想定された値かチェック
35 | if (!checkValue(str_read_property))
36 | {
37 | str_read_property = getDefaultValue(op_name); // デフォルトを読み込む
38 | }
39 |
40 | return (str_read_property);
41 | }
42 |
43 | /* コンフィグからの値取得(bool型) */
44 | bool ConfigRead::GetBoolProperty(string op_name)
45 | {
46 | string str_read_property = readConfigFile(op_name); // configファイルから読み込んだ生の値を格納用
47 | bool bool_read_property = false; // bool型に変換した値の格納用
48 |
49 | // configから読み込んだ値が想定された値かチェック
50 | if (!checkValue(str_read_property))
51 | {
52 | // デフォルトの値を読み込む
53 | str_read_property = getDefaultValue(op_name);
54 | }
55 |
56 | // string型→bool型へ変換(デフォルトがfalseのため、falseの変換は必要なし)
57 | // windowsでは標準関数がstricmpになる
58 | // 機能はどちらも大文字小文字関係なく比較を行う
59 | if (strcasecmp(str_read_property.c_str(), "true") == 0)
60 | {
61 | bool_read_property = true;
62 | }
63 |
64 | return (bool_read_property);
65 | }
66 |
67 | /* コンフィグからの値取得(int型) */
68 | int ConfigRead::GetIntProperty(string op_name)
69 | {
70 | string str_read_property = readConfigFile(op_name); // configファイルから読み込んだ生の値を格納用
71 | int int_read_property; // int型に変換した値の格納用
72 |
73 | // configから読み込んだ値が想定された値かチェック
74 | if (!checkValue(str_read_property))
75 | {
76 | // デフォルトの値を読み込む
77 | str_read_property = getDefaultValue(op_name);
78 | }
79 |
80 | // string型→int型へ変換
81 | int_read_property = stoi(str_read_property);
82 |
83 | return (int_read_property);
84 | }
85 |
86 | /* デフォルト値の読み込み */
87 | string ConfigRead::getDefaultValue(string op_name)
88 | {
89 | return (m_defvalue);
90 | }
91 |
92 | /****************************************************************************
93 | *
94 | * setterメソッド
95 | *
96 | *****************************************************************************/
97 | /* デフォルト値の設定 */
98 | void ConfigRead::setDefaltValue(string op_name)
99 | {
100 | // op_nameに入ってきたオプションに一致するデフォルト値が入る
101 | if (!op_name.find("SwitchCamera", 0))
102 | {
103 | m_defvalue = "false";
104 | m_int_defvalue = 1;
105 | }
106 | else if (!op_name.find("Resources"))
107 | {
108 | m_defvalue = "Camera_default";
109 | m_int_defvalue = 2;
110 | }
111 | else if (!op_name.find("Camera_Types"))
112 | {
113 | m_defvalue = "web";
114 | m_int_defvalue = 3;
115 | }
116 | else if (!op_name.find("Camera_ID"))
117 | {
118 | m_defvalue = "0";
119 | m_int_defvalue = 4;
120 | }
121 | else if (!op_name.find("xres"))
122 | {
123 | m_defvalue = "640";
124 | m_int_defvalue = 5;
125 | }
126 | else if (!op_name.find("yres"))
127 | {
128 | m_defvalue = "480";
129 | m_int_defvalue = 6;
130 | }
131 | else if (!op_name.find("FPS"))
132 | {
133 | m_defvalue = "30";
134 | m_int_defvalue = 7;
135 | }
136 | else if (!op_name.find("ColorFormat"))
137 | {
138 | m_defvalue = "1";
139 | m_int_defvalue = 8;
140 | }
141 | else if (!op_name.find("Preview_Show_Flag"))
142 | {
143 | m_defvalue = "true";
144 | m_int_defvalue = 9;
145 | }
146 | else if (!op_name.find("Timecode_Show_Flag"))
147 | {
148 | m_defvalue = "true";
149 | m_int_defvalue = 10;
150 | }
151 |
152 | }
153 |
154 | /****************************************************************************
155 | *
156 | * ファイル読み込み
157 | *
158 | *****************************************************************************/
159 | string ConfigRead::readConfigFile(string op_name)
160 | {
161 | string str_cnf; // 1行分のコンフィグデータ格納
162 | string str_property; // プロパティ格納用
163 |
164 | // 検索前の初期化
165 | setDefaltValue(op_name);
166 |
167 | // configファイル読み込み
168 | ifstream iconfig_stream(CONFIG_FILE_NAME);
169 | if (!iconfig_stream)
170 | {
171 | return (getDefaultValue(op_name)); // 読み込み失敗時defaultを読み込む
172 | }
173 | else
174 | {
175 | while (true)
176 | {
177 | // 一行読み出す
178 | if (getline(iconfig_stream, str_cnf))
179 | {
180 | // コメントと不正な値を弾く
181 | if (str_cnf.find("#") == -1 && str_cnf.find(op_name) != -1)
182 | {
183 | // 読み出した1行からプロパティだけをトリミング
184 | str_property = getProperty(str_cnf, op_name);
185 | break;
186 | }
187 | }
188 | else
189 | {
190 | str_property = getDefaultValue(op_name); // 読み込み失敗時defaultを読み込む
191 | break;
192 | }
193 | }
194 | }
195 | return (str_property);
196 | }
197 |
198 | /****************************************************************************
199 | *
200 | * プロパティ値取り出し
201 | *
202 | *****************************************************************************/
203 | string ConfigRead::getProperty(string conf_data, string op_name)
204 | {
205 | /* プロパティの値を抜き出す */
206 | const char* trimCharacterList = " \t\v\r\n";
207 | // ex)lineStr = "Option1 = true \n"
208 | // 右側から最初の文字列を検索
209 | size_t p_end = conf_data.find_last_not_of(trimCharacterList); // lineStr = "Option1 = true"
210 | // =の位置検索
211 | size_t p_start = conf_data.find("=") + 1; // lineStr = " true"
212 | // オプション値の空欄を検出
213 | if (!(p_start < p_end))
214 | {
215 | return (getDefaultValue(op_name)); // defaultを読み込む
216 | }
217 | // 左側から最初の文字列を検索
218 | p_start = conf_data.find_first_not_of(trimCharacterList, p_start); // lineStr = "true"
219 | // プロパティの値の文字の長さ
220 | size_t p_leng = p_end - p_start + 1;
221 |
222 | // プロパティ値だけ抜き出し返す
223 | return (conf_data.substr(p_start, p_leng));
224 | }
225 |
226 | /****************************************************************************
227 | *
228 | * 中身のチェック
229 | *
230 | *****************************************************************************/
231 | bool ConfigRead::checkValue(string value)
232 | {
233 | switch (m_int_defvalue)
234 | {
235 | case 1: // カメラを使用するか
236 | // windowsでは標準関数がstricmpになる
237 | // 機能はどちらも大文字小文字関係なく比較を行う
238 | if (!strcasecmp(value.c_str(), "true") == 0)
239 | {
240 | return (false);
241 | }
242 | break;
243 |
244 | case 9: // 送信側のタイムコードを表示するか
245 | case 10: // プレビューを表示するか
246 | // windowsでは標準関数がstricmpになる
247 | // 機能はどちらも大文字小文字関係なく比較を行う
248 | if (!strcasecmp(value.c_str(), "false") == 0)
249 | {
250 | return (false);
251 | }
252 | break;
253 | case 3: // リソースのカメラの種類
254 | if ((strcasecmp(value.c_str(), "web") != 0) &&
255 | (strcasecmp(value.c_str(), "ip") != 0) &&
256 | (strcasecmp(value.c_str(), "realsense") != 0) &&
257 | (strcasecmp(value.c_str(), "rs") != 0))
258 | {
259 | return (false);
260 | }
261 | break;
262 | case 2: // リソース名
263 | break;
264 | case 4: // リソース先
265 | try
266 | {
267 | // string→int変換
268 | if (!(0 <= stoi(value)))
269 | {
270 | return (false);
271 | }
272 | break;
273 | }
274 | catch (invalid_argument)
275 | {
276 | break;
277 | }
278 | catch (out_of_range)
279 | {
280 | break;
281 | }
282 | case 5: // フレームサイズxres
283 | try
284 | {
285 | if (!(0 < stoi(value)))
286 | {
287 | return (false);
288 | }
289 | }
290 | catch (invalid_argument)
291 | {
292 | // 数値以外入ってきた場合
293 | return (false);
294 | }
295 | break;
296 | case 6: // フレームサイズyres
297 | try
298 | {
299 | if (!(0 < stoi(value)))
300 | {
301 | return (false);
302 | }
303 | }
304 | catch (invalid_argument)
305 | {
306 | // 数値以外入ってきた場合
307 | return (false);
308 | }
309 | break;
310 | case 7: // フレームレート
311 | try
312 | {
313 | if (!(0 < stoi(value) && stoi(value) <= 250))
314 | {
315 | return (false);
316 | }
317 | }
318 | catch (invalid_argument)
319 | {
320 | // 数値以外入ってきた場合
321 | return (false);
322 | }
323 | break;
324 | case 8: // 色のフォーマット
325 | try
326 | {
327 | if (!(0 < stoi(value) && stoi(value) < 6))
328 | {
329 | return (false);
330 | }
331 | break;
332 | }
333 | catch (invalid_argument)
334 | {
335 | // 数値以外入ってきた場合
336 | return (false);
337 | }
338 | break;
339 | }
340 | return (true);
341 | }
342 |
343 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.16/NDI-Video-Sender/ConfigRead.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 | /* linux����p�w�b�_ */
7 | #ifdef __linux__
8 | #include
9 |
10 | #endif // __linux__
11 | /* Windows����p�w�b�_ */
12 | #ifdef _WIN32
13 | #define strcasecmp stricmp // LinuxとWindowsで標準関数が違う
14 | #endif // _WIN32
15 |
16 | #define CONFIG_FILE_NAME "NdiVideoSender.config"
17 |
18 |
19 | class ConfigRead
20 | {
21 | public:
22 | ConfigRead();
23 | ~ConfigRead();
24 | std::string GetStringProperty(std::string op_name);
25 | bool GetBoolProperty(std::string op_name);
26 | int GetIntProperty(std::string op_name);
27 |
28 | private:
29 | std::string m_defvalue; // デフォルト値格納用
30 | int m_int_defvalue; // 設定項目番号格納用
31 |
32 | std::string getDefaultValue(std::string op_name);
33 | void setDefaltValue(std::string op_name);
34 | std::string getProperty(std::string conf_data, std::string op_name);
35 | bool checkValue(std::string value);
36 | std::string readConfigFile(std::string op_name);
37 |
38 | };
39 |
40 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.16/NDI-Video-Sender/NDI-Video-Sender.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 15.0
23 | {9796FEF8-53A7-47FB-9B66-7926D134996D}
24 | Win32Proj
25 | NDIVideoSender
26 | 10.0.15063.0
27 | NDI-Video-Sender
28 |
29 |
30 |
31 | Application
32 | true
33 | v141
34 | Unicode
35 |
36 |
37 | Application
38 | false
39 | v141
40 | true
41 | Unicode
42 |
43 |
44 | Application
45 | true
46 | v141
47 | Unicode
48 |
49 |
50 | Application
51 | false
52 | v141
53 | true
54 | Unicode
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | true
76 |
77 |
78 | true
79 | C:\opencv320\build\include;C:\Program Files %28x86%29\Intel RealSense SDK 2.0\include;C:\Program Files\NewTek\NewTek NDI SDK\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath)
80 | C:\Program Files %28x86%29\Intel RealSense SDK 2.0\lib\x64;C:\Program Files\NewTek\NewTek NDI SDK\Lib\x64;C:\opencv320\build\x64\vc14\lib;$(LibraryPath)
81 |
82 |
83 | false
84 | C:\opencv320\build\include;C:\Program Files\NewTek\NewTek NDI SDK\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);
85 | C:\Program Files\NewTek\NewTek NDI SDK\Lib\x64;C:\opencv320\build\x64\vc14\lib;$(LibraryPath)
86 |
87 |
88 | false
89 | C:\opencv320\build\include;C:\Program Files %28x86%29\Intel RealSense SDK 2.0\include;C:\Program Files\NewTek\NewTek NDI SDK\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath)
90 | C:\Program Files %28x86%29\Intel RealSense SDK 2.0\lib\x64;C:\Program Files\NewTek\NewTek NDI SDK\Lib\x64;C:\opencv320\build\x64\vc14\lib;$(LibraryPath)
91 |
92 |
93 |
94 | NotUsing
95 | Level3
96 | Disabled
97 | true
98 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
99 | true
100 |
101 |
102 | Console
103 | true
104 |
105 |
106 |
107 |
108 | NotUsing
109 | Level3
110 | Disabled
111 | true
112 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
113 | true
114 | 4996
115 |
116 |
117 | Console
118 | true
119 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;opencv_world320.lib;Processing.NDI.Lib.x64.lib;realsense2.lib;%(AdditionalDependencies)
120 |
121 |
122 |
123 |
124 | NotUsing
125 | Level3
126 | Disabled
127 | true
128 | true
129 | false
130 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
131 | true
132 | 4996
133 |
134 |
135 | Console
136 | true
137 | true
138 | true
139 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;;opencv_world320.lib;Processing.NDI.Lib.x64.lib;%(AdditionalDependencies)
140 |
141 |
142 |
143 |
144 | NotUsing
145 | Level3
146 | Disabled
147 | true
148 | true
149 | false
150 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
151 | true
152 | 4996
153 |
154 |
155 | Console
156 | true
157 | true
158 | true
159 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;opencv_world320.lib;Processing.NDI.Lib.x64.lib;realsense2.lib;%(AdditionalDependencies)
160 | /source-charset:utf-8 %(AdditionalOptions)
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.16/NDI-Video-Sender/NDI-Video-Sender.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | ヘッダー ファイル
20 |
21 |
22 | ヘッダー ファイル
23 |
24 |
25 | ヘッダー ファイル
26 |
27 |
28 | ヘッダー ファイル
29 |
30 |
31 |
32 |
33 | ソース ファイル
34 |
35 |
36 | ソース ファイル
37 |
38 |
39 | ソース ファイル
40 |
41 |
42 | ソース ファイル
43 |
44 |
45 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.16/NDI-Video-Sender/NDI-Video-Sender.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 3
5 | WindowsLocalDebugger
6 |
7 |
8 | 1
9 | WindowsLocalDebugger
10 |
11 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.16/NDI-Video-Sender/NdiCom.cpp:
--------------------------------------------------------------------------------
1 | #include "NdiCom.h"
2 |
3 | using namespace std;
4 |
5 | /****************************************************************************
6 | *
7 | * コンストラクタ・デストラクタ
8 | *
9 | *****************************************************************************/
10 | /* コンストラクタ */
11 | NdiCom::NdiCom()
12 | {
13 | // 初期化
14 | m_use_flg = true;
15 | m_exit_snd_loop = true;
16 | m_preview_flg = true;
17 | m_sndtmcode_flg = true;
18 | m_isRecflg = false;
19 | m_pNDI_send = NULL;
20 | m_webcam_no = 0;
21 |
22 |
23 | }
24 |
25 | /* コンストラクタ */
26 | NdiCom::NdiCom(int argv_no)
27 | {
28 | initialize(argv_no);
29 | }
30 |
31 | /* デストラクタ */
32 | NdiCom::~NdiCom()
33 | {
34 | // 処理なし
35 | }
36 |
37 | /* メンバ初期化 */
38 | void NdiCom::initialize(int argv_no)
39 | {
40 | ConfigRead *config_read = new ConfigRead(); // コンフィグファイル読み込み処理用インスタンス
41 | string str_int; // 起動引数で指定した値からカメラ番号を設定するための変数
42 | str_int = "_CAM";
43 | str_int += to_string(argv_no); // 指定したカメラ番号を格納
44 |
45 | setUseFlg(config_read->GetBoolProperty("SwitchCamera" + str_int)); // カメラを使用するかをセット
46 |
47 | // 使用フラグ
48 | if (!GetUseFlg())
49 | {
50 | return;
51 | }
52 |
53 | setResourcesID(config_read->GetStringProperty("Resources_ID" + str_int)); // リソース名をセット
54 | setUseWebCameraFlg(config_read->GetStringProperty("Camera_Types" + str_int)); // WEBカメラかどうかセット
55 |
56 | // WEBカメラならデバイス番号、RealSenseならシリアル番号、IPカメラならURLの指定
57 | if (getWebcamFlg())
58 | {
59 | setCamera(config_read->GetIntProperty("Camera_ID" + str_int)); // WEBカメラのデバイス番号のセット
60 | }
61 | else
62 | {
63 | setCamera(config_read->GetStringProperty("Camera_ID" + str_int)); // Realsenseカメラのシリアル番号及びIPカメラURLのセット
64 | }
65 |
66 | setVideoSz(config_read->GetIntProperty("xres" + str_int), config_read->GetIntProperty("yres" + str_int)); // 解像度をセット
67 | setFps(config_read->GetIntProperty("FPS" + str_int)); // FPS値をセット
68 | setColor(config_read->GetIntProperty("ColorFormat" + str_int)); // 送信するカラーフォーマットをセット
69 | setUseSndTimeCodeFlg(config_read->GetBoolProperty("Timecode_Show_Flag" + str_int)); // タイムスタンプを使用フラグのセット
70 | setUsetPreViewFlg(config_read->GetBoolProperty("Preview_Show_Flag" + str_int)); // imshow使用フラグのセット
71 |
72 | delete config_read; // コンフィグファイル読み込みインスタンスの削除
73 | }
74 |
75 | /****************************************************************************
76 | *
77 | * getterメソッド
78 | *
79 | *****************************************************************************/
80 | /* 使用フラグの取得 */
81 | bool NdiCom::GetUseFlg()
82 | {
83 | return (m_use_flg);
84 | }
85 |
86 | /* ウェブカメラフラグの取得 */
87 | bool NdiCom::getWebcamFlg()
88 | {
89 | bool webcam_flg = true; // webカメラ使用フラグ
90 | if (!strcasecmp(m_camera_types.c_str(), "web") == 0)
91 | {
92 | webcam_flg = false;
93 | }
94 | return (webcam_flg);
95 | }
96 |
97 | /* 送信フラグの取得 */
98 | bool NdiCom::GetIsRecflg()
99 | {
100 | return (m_isRecflg);
101 | }
102 |
103 | /****************************************************************************
104 | *
105 | * setterメソッド
106 | *
107 | *****************************************************************************/
108 | /* リソースの使用フラグの設定 */
109 | void NdiCom::setUseFlg(bool str_use_flg)
110 | {
111 | m_use_flg = str_use_flg;
112 | }
113 |
114 | /* リソースのIDを設定 */
115 | void NdiCom::setResourcesID(string resources_id)
116 | {
117 | m_resources_id = resources_id;
118 | }
119 |
120 | /* 取得する映像サイズの設定 */
121 | void NdiCom::setVideoSz(int xres, int yres)
122 | {
123 | m_xres = xres;
124 | m_yres = yres;
125 | }
126 |
127 | /* FPSの設定 */
128 | void NdiCom::setFps(int sndfps)
129 | {
130 | m_sndfps = sndfps;
131 | }
132 |
133 | /* 送信するカラーフォーマットの設定 */
134 | void NdiCom::setColor(int sndColor)
135 | {
136 | // 現状ではこの設定は固定である
137 | switch (sndColor)
138 | {
139 | case 1:
140 | m_sndNDIColor = NDIlib_FourCC_type_BGRX;
141 | m_sndCVColor = CV_BGR2BGRA;
142 | m_setCVCamColor = CV_FOURCC_DEFAULT;
143 | break;
144 | case 2:
145 | m_sndNDIColor = NDIlib_FourCC_type_BGRA;
146 | m_sndCVColor = CV_BGR2BGRA;
147 | m_setCVCamColor = CV_FOURCC_DEFAULT;
148 | break;
149 | case 3:
150 | m_sndNDIColor = NDIlib_FourCC_type_RGBX;
151 | m_sndCVColor = CV_BGR2RGBA;
152 | m_setCVCamColor = CV_FOURCC_DEFAULT;
153 | break;
154 | case 4:
155 | m_sndNDIColor = NDIlib_FourCC_type_RGBA;
156 | m_sndCVColor = CV_BGR2RGBA;
157 | m_setCVCamColor = CV_FOURCC_DEFAULT;
158 | break;
159 | case 5: // 利用不可
160 | m_sndNDIColor = NDIlib_FourCC_type_UYVY;
161 | m_sndCVColor = CV_YUV2BGRA_UYVY;
162 | m_setCVCamColor = CV_FOURCC('U', 'Y', 'V', 'Y');
163 | break;
164 | }
165 |
166 | }
167 |
168 | /* プレビュー画面の表示フラグのセット */
169 | void NdiCom::setUsetPreViewFlg(bool view_flg)
170 | {
171 | m_preview_flg = view_flg;
172 | }
173 |
174 | /* 送信側タイムコードの使用フラグのセット */
175 | void NdiCom::setUseSndTimeCodeFlg(bool timecode_flg)
176 | {
177 | m_sndtmcode_flg = timecode_flg;
178 | }
179 |
180 | /* カメラの種類のセット */
181 | void NdiCom::setUseWebCameraFlg(string camera_types)
182 | {
183 | m_camera_types = camera_types;
184 | }
185 |
186 | /* 使用するwebカメラのデバイス番号の設定 */
187 | void NdiCom::setCamera(int cam_no)
188 | {
189 | m_webcam_no = cam_no;
190 | }
191 |
192 | /* 使用するipカメラのURLの設定 */
193 | void NdiCom::setCamera(string cam_no)
194 | {
195 | m_other_camera = cam_no;
196 | }
197 |
198 | /****************************************************************************
199 | *
200 | * 送信処理
201 | *
202 | *****************************************************************************/
203 | /* 送信準備 */
204 | void NdiCom::sendCreate()
205 | {
206 | // 送信用インスタンスの生成
207 | NDIlib_send_create_t NDI_send_create_desc;
208 |
209 | // WEBカメラかIPカメラか判定
210 | if (strcasecmp(m_camera_types.c_str(), "web") == 0)
211 | {
212 | // WEBカメラの場合
213 | m_str_resname = string("WebCameraID:") + m_resources_id; // カメラ番号指定
214 | }
215 | else if(strcasecmp(m_camera_types.c_str(), "ip") == 0)
216 | {
217 | // IPカメラの場合
218 | m_str_resname = string("IPCameraID:") + m_resources_id; // URL指定
219 | }
220 | else if (strcasecmp(m_camera_types.c_str(), "rs") == 0 || strcasecmp(m_camera_types.c_str(), "realsense") == 0)
221 | {
222 | // RealSenseカメラの場合
223 | m_str_resname = string("RealSenseID:") + m_resources_id; // シリアル番号指定
224 | }
225 | NDI_send_create_desc.p_ndi_name = m_str_resname.c_str(); // 送信インスタンス
226 | NDI_send_create_desc.clock_video = true; // 送信時間を同期させるかどうか
227 | NDI_send_create_desc.clock_audio = false; // 送信時間を同期させるかどうか
228 | m_pNDI_send = NDIlib_send_create(&NDI_send_create_desc); // NDI送信インスタンス生成
229 |
230 | // インスタンスの生成チェック
231 | if (!m_pNDI_send)
232 | {
233 | printf("Generation failure of the instance.");
234 | }
235 | }
236 |
237 | /* 時刻取得 */
238 | string NdiCom::getCurrentTime()
239 | {
240 | // ローカル変数宣言
241 | time_t crrent_time; // 時間格納用
242 | struct tm *current_time_t; // 暦時刻の格納用
243 | char crrent_time_c[20]; // 時刻格納用変数
244 |
245 | // 時間取得
246 | crrent_time = time(NULL); // 1970/1/1 00:00:00 から現在までの経過秒数を取得
247 | // 取得チェック
248 | if (crrent_time == -1)
249 | {
250 | return ("GET TIME ERROR");
251 | }
252 |
253 | // 日本時間に変更
254 | current_time_t = localtime(&crrent_time);
255 |
256 | // 構造体だと扱いづらいので所定の書式に変換
257 | if (!strftime(crrent_time_c, 128, "%Y/%m/%d %H:%M:%S", current_time_t))
258 | {
259 | return ("GET TIME ERROR"); // 変換失敗時
260 | }
261 |
262 | return (string(crrent_time_c));
263 | }
264 |
265 | /* 映像送信 */
266 | void NdiCom::sndVideo()
267 | {
268 | // ローカル変数宣言
269 | cv::VideoCapture cap; // カメラオープン用変数
270 | cv::Mat myframe, sndframe; // カメラから取得したフレームと送信用フレームのデータを格納するする変数
271 | cv::Point point(30, 30); // フレーム上の座標を指定する
272 | string strTimecode; // 文字列に変換された時間を格納するための変数
273 |
274 | m_isRecflg = true; // 送信フラグオン
275 |
276 |
277 |
278 | // カメラオープン
279 | if (getWebcamFlg())
280 | {
281 | // Webカメラの場合
282 | cap.open(m_webcam_no); // stringをint型に変換
283 | }
284 | else
285 | {
286 | // IPカメラの場合
287 | cap.open(m_other_camera);
288 | }
289 |
290 | // オープンしたカメラデバイスの設定
291 | // cap.set(CV_CAP_PROP_FOURCC, setCVCamColor); // m_setCVCamColor指摘先
292 | cap.set(CV_CAP_PROP_FRAME_WIDTH, m_xres); // 幅
293 | cap.set(CV_CAP_PROP_FRAME_HEIGHT, m_yres); // 高さ
294 | cap.set(CV_CAP_PROP_FPS, m_sndfps); // フレームレート
295 |
296 | // フレームサイズ更新(カメラの性能以上要求によるエラー落ち対策)
297 | m_xres = (int)cap.get(CV_CAP_PROP_FRAME_WIDTH); // 横方向
298 | m_yres = (int)cap.get(CV_CAP_PROP_FRAME_HEIGHT); // 縦方向
299 |
300 | // カメラオープン成功判定
301 | if (!cap.isOpened())
302 | {
303 | // カメラオープン失敗時
304 | if (getWebcamFlg())
305 | {
306 | cout << "Camera_ID " << m_webcam_no << " could not open." << endl; // WEBカメラならカメラ番号
307 | }
308 | else
309 | {
310 | cout << "Camera_ID " << m_other_camera << " could not open." << endl; // IPカメラならURL
311 | }
312 | m_isRecflg = false;
313 | return;
314 | }
315 |
316 | // 送信用インスタンス生成
317 | sendCreate();
318 |
319 | // 映像用フレームの生成と初期化
320 | NDIlib_video_frame_v2_t video_frame;
321 | video_frame.xres = m_xres; // 横方向解像度の指定
322 | video_frame.yres = m_yres; // 縦方向解像度の指定
323 | video_frame.FourCC = NDIlib_FourCC_type_BGRA; // m_sndNDIColor指定先。フレームのカラーフォーマット指定
324 | video_frame.frame_format_type = NDIlib_frame_format_type_interleaved;
325 | video_frame.p_data = (uint8_t*)malloc(m_xres * m_yres * 4); // データサイズの指定
326 | video_frame.line_stride_in_bytes = m_xres * 4;
327 |
328 |
329 |
330 |
331 | // Send Start
332 | printf("%s SENDING...\n", m_resources_id.c_str());
333 | m_exit_snd_loop = false;
334 |
335 | // 送信処理
336 | while (!m_exit_snd_loop)
337 | {
338 | // カメラから読み込み
339 | cap.read(myframe);
340 |
341 | // 読み込んだフレームが空か
342 | if (myframe.empty())
343 | {
344 | continue;
345 | }
346 |
347 | // タイムスタンプ挿入するか
348 | if (m_sndtmcode_flg)
349 | {
350 | // タイムスタンプ挿入
351 | strTimecode = getCurrentTime();
352 | cv::putText(
353 | myframe, // 画像
354 | strTimecode, // 文字列
355 | point, // 座標
356 | cv::FONT_HERSHEY_SIMPLEX, // フォントの種類
357 | 0.8, // 文字の大きさ
358 | cv::Scalar(255, 255, 255), // 文字の色
359 | 3 // 線の太さ
360 | );
361 | cv::putText( // インラインフォント
362 | myframe, // 画像
363 | strTimecode, // 文字列
364 | point, // 座標
365 | cv::FONT_HERSHEY_SIMPLEX, // フォントの種類
366 | 0.8, // 文字の大きさ
367 | cv::Scalar(0, 0, 0), // 文字の色
368 | 1, // 線の太さ
369 | CV_AA // アンチエイリアス
370 | );
371 | }
372 | cv::cvtColor(myframe, sndframe, CV_BGR2BGRA); // m_sndCVColorの指定先。色の変換(NDI送信用フレームに乗せるにはBGRXに変換する必要がある)
373 |
374 | memcpy((void*)video_frame.p_data, sndframe.data, (m_xres * m_yres * 4)); // OpenCVのフレームをNDIフレームデータにコピー
375 |
376 | // 送信
377 | NDIlib_send_send_video_v2(m_pNDI_send, &video_frame);
378 |
379 | if (m_preview_flg)
380 | {
381 | cv::imshow(m_str_resname, sndframe); // 画像を表示
382 |
383 | // キー入力を待つ
384 | switch (cv::waitKey(1))
385 | {
386 | case 3: // imshow中にCtrl+cが入力されたら終了
387 | case 227: // windowsだとCtrl+cは3、LinuxだとCtrl+cが正しく認識できない。227が返る
388 | m_exit_snd_loop = true;
389 | cv::destroyWindow(m_str_resname);
390 | break;
391 | default:
392 | break;
393 | }
394 | }
395 | }
396 | free(video_frame.p_data); // 映像フレームのデータ領域を解放
397 | NDIlib_send_destroy(m_pNDI_send); // 送信用フレームの開放
398 | m_isRecflg = false;
399 | }
400 |
401 | /* 送信Threadの作成 */
402 | void NdiCom::CretateSndVideoThread()
403 | {
404 | if (m_use_flg)
405 | {
406 | m_isRecflg = true; // 送信フラグオン
407 | m_thread_video = thread(&NdiCom::sndVideo, this);
408 | }
409 | }
410 |
411 | /* 送信Threadの開放 */
412 | void NdiCom::DeleteSndVideoThread()
413 | {
414 | for (;;) // 無限ループ
415 | {
416 | if (!m_exit_snd_loop)
417 | {
418 | m_exit_snd_loop = true; // 送信ループ終了フラグオン
419 | }
420 |
421 | // Sleep
422 | chrono::milliseconds dura(100);
423 | this_thread::sleep_for(dura);
424 |
425 | // 送信処理終了済みまで待機
426 | if (!GetIsRecflg())
427 | {
428 | if (!GetUseFlg())
429 | {
430 | break;
431 | }
432 | // join可能か判定
433 | if (m_thread_video.joinable())
434 | {
435 | m_thread_video.join(); // スレッドをjoinするまで待機
436 | break; // forループ抜ける
437 | }
438 | }
439 | }
440 | }
--------------------------------------------------------------------------------
/NDI-Video-Sender2.16/NDI-Video-Sender/NdiCom.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include "ConfigRead.h"
12 |
13 | /* linux動作用ヘッダ */
14 | #ifdef __linux__
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include // cv::cvtColor
24 | #include
25 | #include
26 |
27 | #endif // __linux__
28 |
29 | /* Windows動作用ヘッダ */
30 | #ifdef _WIN32
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 | #define strcasecmp stricmp // LinuxとWindowsで標準関数が違う
37 | #endif
38 |
39 | #define NDI_SND_MAX 6
40 |
41 |
42 | class NdiCom
43 | {
44 | public:
45 | NdiCom();
46 | NdiCom(int argv_no);
47 | ~NdiCom();
48 | bool GetUseFlg();
49 | bool GetIsRecflg();
50 | virtual void CretateSndVideoThread();
51 | void DeleteSndVideoThread();
52 |
53 | protected:
54 | NDIlib_send_instance_t m_pNDI_send; // 送信インスタンス
55 | int m_xres, m_yres; // 解像度
56 | int m_sndfps; // FPS指定用
57 | bool m_use_flg; // 使用フラグ
58 | bool m_preview_flg; // imshowフラグ
59 | bool m_sndtmcode_flg; // タイムスタンプ挿入フラグ
60 | bool m_exit_snd_loop; // 送信ループ終了フラグ
61 | bool m_isRecflg; // 送信処理フラグ
62 | std::string m_resources_id; // リソース番号格納用
63 | std::string m_other_camera; // ipカメラ番号格納用
64 | std::string m_str_resname; // 送信リソース名格納用
65 | std::thread m_thread_video; // 送信用Thread
66 |
67 | virtual void sndVideo();
68 | std::string getCurrentTime();
69 | void sendCreate();
70 |
71 | private:
72 | NDIlib_FourCC_type_e m_sndNDIColor; // 送信カラーフォーマット
73 | int m_sndCVColor; // 変換するカラーフォーマットの指定
74 | int m_setCVCamColor; // カメラデバイスのカラーフォーマット
75 | int m_webcam_no; // カメラ番号格納用
76 | std::string m_camera_types; // カメラの種類
77 |
78 | void initialize(int argv_no);
79 | bool getWebcamFlg();
80 | void setUseFlg(bool str_use_flg);
81 | void setResourcesID(std::string resources_id);
82 | void setVideoSz(int xres, int yres);
83 | void setFps(int sndfps);
84 | void setColor(int sndColor);
85 | void setUsetPreViewFlg(bool view_flg);
86 | void setUseSndTimeCodeFlg(bool timecode_flg);
87 | void setUseWebCameraFlg(std::string webcam_flg);
88 | void setCamera(int cam_no);
89 | void setCamera(std::string cam_no);
90 | };
91 |
92 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.16/NDI-Video-Sender/NdiVideoSender.config:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadsys/NDI-Video-Sender_Receiver/d18ba6f25d7403d4a773d99051ac7cda2f4e8f4a/NDI-Video-Sender2.16/NDI-Video-Sender/NdiVideoSender.config
--------------------------------------------------------------------------------
/NDI-Video-Sender2.16/NDI-Video-Sender/NdiVideoSender.cpp:
--------------------------------------------------------------------------------
1 | // NDI-Video-Sender-win.cpp : アプリケーションのエントリ ポイントを定義します。
2 | #include "NdiCom.h"
3 | #include "ConfigRead.h"
4 | #include "Realsense.h"
5 |
6 | using namespace std;
7 |
8 | /* グローバル変数 */
9 | static atomic exit_main_loop(false); // メインループの終了フラグ
10 | NdiCom *ndi_video_snd = NULL;
11 |
12 | /* シグナルハンドラ */
13 | void sigint_handler(int)
14 | {
15 | exit_main_loop = true;
16 | }
17 |
18 |
19 |
20 |
21 | int main(int argc, char *argv[])
22 | {
23 | // シグナルハンドラ
24 | signal(SIGINT, sigint_handler); // SIGINTはCtrl+C押されたとき
25 | puts("Press + to exit...");
26 |
27 | // NDIの初期化
28 | if (!NDIlib_initialize())
29 | {
30 | printf("Cannot run NDI.\n");
31 | return (0); // CPUがNDIに対応していなければ終了
32 | }
33 |
34 | // ローカル変数宣言
35 | int argv_no = 0;
36 |
37 | // 起動オプションの引数チェック
38 | if (argc != 2 || (atoi(argv[1]) <= 0 || NDI_SND_MAX < atoi(argv[1])))
39 | {
40 | printf("起動オプション(カメラ番号1~6)を指定して下さい。プログラムを終了します。\n");
41 | return (0);
42 | }
43 |
44 | argv_no = atoi(argv[1]); // 起動引数をint型に変換して代入
45 |
46 | // NDI送信インスタンス生成
47 | ConfigRead config_read;
48 | string camera_types = config_read.GetStringProperty("Camera_Types_CAM" + string(argv[1]));
49 | if (strcasecmp(camera_types.c_str(), "rs") == 0 || strcasecmp(camera_types.c_str(), "realsense") == 0)
50 | {
51 | ndi_video_snd = new Realsense(argv_no);
52 | }
53 | else
54 | {
55 | ndi_video_snd = new NdiCom(argv_no);
56 | }
57 |
58 | // 送信フラグチェック
59 | if(!ndi_video_snd->GetUseFlg())
60 | {
61 | printf("カメラ%dのSwitchCameraの設定が使用しない(false)になっているため終了致します。\n", argv_no);
62 | delete ndi_video_snd; // インスタンス削除
63 | return (0);
64 | }
65 |
66 | // 送信スレッド開始
67 | ndi_video_snd->CretateSndVideoThread(); // 送信用Thread作成
68 |
69 | // メインループ
70 | while (!exit_main_loop)
71 | {
72 | // Sleep
73 | chrono::milliseconds dura(1000);
74 | this_thread::sleep_for(dura);
75 |
76 | // Ctrl+Cが押されたか監視
77 | if (!ndi_video_snd->GetIsRecflg())
78 | {
79 | exit_main_loop = true; // メインループ終了
80 | }
81 |
82 | }
83 |
84 | // 終了処理
85 | printf("FREE NDI FRAME...\n");
86 | if (ndi_video_snd)
87 | {
88 | ndi_video_snd->DeleteSndVideoThread(); // 受信Threadの削除
89 | delete ndi_video_snd; // インスタンス開放
90 | }
91 |
92 | // NDIの削除
93 | NDIlib_destroy();
94 |
95 | return (0);
96 | }
97 |
98 |
--------------------------------------------------------------------------------
/NDI-Video-Sender2.16/NDI-Video-Sender/Realsense.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadsys/NDI-Video-Sender_Receiver/d18ba6f25d7403d4a773d99051ac7cda2f4e8f4a/NDI-Video-Sender2.16/NDI-Video-Sender/Realsense.cpp
--------------------------------------------------------------------------------
/NDI-Video-Sender2.16/NDI-Video-Sender/Realsense.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadsys/NDI-Video-Sender_Receiver/d18ba6f25d7403d4a773d99051ac7cda2f4e8f4a/NDI-Video-Sender2.16/NDI-Video-Sender/Realsense.h
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | NDI Video Sender / NDI Video Receiver
2 | =======
3 |
4 | 
5 |
6 | ** NDI Video Sender / NDI Video Receiver ** は、Windows/Ubuntuで動作する
7 | [NewTek NDI]プロトコルのサンプルプログラムで、ローカルエリアネットワーク経由で
8 | 複数のコンピュータ間でビデオを送受信できます。
9 | UVC規格のWebカメラ、IPカメラ、Depthカメラ(RealSense D435)からの映像をNDIプロトコルを
10 | 介して送受信することが可能です。
11 |
12 | NDI™ is a trademark of NewTek, Inc.
13 |
14 | [NewTek NDI]: http://NDI.NewTek.com/
15 |
16 | System requirements & Installations
17 | -------------------
18 | Windowsのシステム要件および構築の手順については
19 | "Installation manual (Windows) .pdf"をご参照下さい。
20 |
21 | Linux(Ubuntu)のシステム要件および構築の手順については
22 | "Installation manual (Ubuntu) .pdf"をご参照下さい。
23 |
24 | How to use
25 | --------------------
26 |
27 | ### NDI Video Sender
28 |
29 | 1.Webカメラ or IPカメラ or Depthカメラ(RealSense)を接続する。
30 |
31 | 2.カメラの送信設定を行う。
32 | ソースフォルダ内にある「NdiVideoSender.config」を、実行ファイル(.exe)と
33 | 同じフォルダにコピーし、中身を編集する。
34 | (編集内容については同ファイル内のコメント及び例をご参照下さい。
35 | 最大6個のカメラ設定を入れることが可能です)
36 |
37 | 3.プログラム実行時の起動引数に、2.で編集したカメラ番号を指定する。
38 | (実行の方法は「Installation manual」をご参照下さい)
39 |
40 | 4.終了時は「Ctrl+C」を押下する。
41 |
42 | ※IPカメラも指定することが可能です。その場合、Camera_Flag_CAMXを
43 | 「false」に設定し、Camera_ID_CAMXにカメラURLを指定して下さい。
44 |
45 |
46 | ### NDI Video Receiver
47 |
48 | 1.カメラの受信設定を行う。
49 | ソースフォルダ内にある「NdiVideoReceiver.config」を、実行ファイル(.exe)と
50 | 同じフォルダにコピーし、中身を編集する。
51 | (Resources_ID_CHXの値はSenderで設定したResources_ID_CAMXを指定して下さい)
52 |
53 | 2.プログラム実行時の起動引数に、2.で編集したカメラ番号を指定する。
54 | (実行の方法は「Installation manual」をご参照下さい)
55 |
56 | 3.終了時は「Ctrl+C」を押下する。
57 |
58 |
59 | License
60 | -------
61 |
62 | [BSD](LICENSE)
63 |
64 | The NDI DLL file (`Processing.NDI.Lib.x64.dll`) is provided by NewTek,
65 | Inc under the NDI® SDK License Agreement.
66 | Please review the original license when distributing program.
67 |
--------------------------------------------------------------------------------