]> git.sesse.net Git - casparcg/blob - modules/newtek/util/air_send.cpp
Log full path of the actual loaded iVGA DLL
[casparcg] / modules / newtek / util / air_send.cpp
1 /*
2 * Copyright 2013 Sveriges Television AB http://casparcg.com/
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Helge Norberg, helge.norberg@svt.se
20 */
21
22 #include "../StdAfx.h"
23
24 #include "air_send.h"
25
26 #include <memory>
27
28 #include <Windows.h>
29
30 #include <common/exception/exceptions.h>
31
32 namespace caspar { namespace newtek { namespace airsend {
33
34 void* (*create)(
35                 const int width, const int height,
36                 const int timescale, const int duration,
37                 const bool progressive,
38                 const float aspect_ratio,
39                 const bool audio_enabled,
40                 const int num_channels,
41                 const int sample_rate) = nullptr;
42 void (*destroy)(void* instance) = nullptr;
43 bool (*add_audio)(
44                 void* instance, const short* samples, const int num_samples) = nullptr;
45 bool (*add_frame_bgra)(void* instance, const unsigned char* data) = nullptr;
46
47 const std::wstring& dll_name()
48 {
49         static std::wstring name = L"Processing.AirSend.x86.dll";
50
51         return name;
52 }
53
54 std::shared_ptr<void> load_library()
55 {
56         auto module = LoadLibrary(dll_name().c_str());
57
58         if (!module)
59                 return nullptr;
60
61         std::shared_ptr<void> lib(module, FreeLibrary);
62
63         wchar_t actualFilename[256];
64
65         GetModuleFileNameW(module, actualFilename, sizeof(actualFilename));
66
67         CASPAR_LOG(debug) << L"Loaded " << actualFilename;
68
69         create = reinterpret_cast<decltype(create)>(
70                         GetProcAddress(module, "AirSend_Create"));
71         destroy = reinterpret_cast<decltype(destroy)>(
72                         GetProcAddress(module, "AirSend_Destroy"));
73         add_audio = reinterpret_cast<decltype(add_audio)>(
74                         GetProcAddress(module, "AirSend_add_audio"));
75         add_frame_bgra = reinterpret_cast<decltype(add_frame_bgra)>(
76                         GetProcAddress(module, "AirSend_add_frame_bgra"));
77
78         if (create == nullptr
79                         || destroy == nullptr
80                         || add_audio == nullptr
81                         || add_frame_bgra == nullptr)
82         {
83                 create = nullptr;
84                 destroy = nullptr;
85                 add_audio = nullptr;
86                 add_frame_bgra = nullptr;
87
88                 return nullptr;
89         }
90
91         return lib;
92 }
93
94 bool is_available()
95 {
96         static std::shared_ptr<void> lib = load_library();
97
98         return lib;
99 }
100
101 }}}