-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from pandres95:develop
Feature: Find API + Recv/SetTally
- Loading branch information
Showing
17 changed files
with
261 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { SourceInstance } from './source_instance'; | ||
|
||
export function findSources (timeout?: number): Promise<SourceInstance[]>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <napi.h> | ||
|
||
#ifndef _SRC_FIND_FIND_SOURCES_H_ | ||
#define _SRC_FIND_FIND_SOURCES_H_ | ||
|
||
Napi::Value FindSources(const Napi::CallbackInfo&); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { TallyState } from '../structures/tally_state'; | ||
|
||
export interface SourceInstance { | ||
setTally (tallyState: TallyState): void; | ||
|
||
get ipAddress(): string; | ||
get name(): string; | ||
get urlAddress(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <napi.h> | ||
#include <Processing.NDI.Lib.h> | ||
|
||
#ifndef _SRC_STRUCTURES_SOURCE_INSTANCE_H_ | ||
#define _SRC_STRUCTURES_SOURCE_INSTANCE_H_ | ||
|
||
class SourceInstance : public Napi::ObjectWrap<SourceInstance> { | ||
public: | ||
static void Init(Napi::Env env, Napi::Object exports); | ||
static Napi::Object New(Napi::Env env, NDIlib_source_t *ndiSourceInstance); | ||
static Napi::FunctionReference constructor; | ||
|
||
SourceInstance(const Napi::CallbackInfo &info); | ||
~SourceInstance(); | ||
|
||
void SetTally(const Napi::CallbackInfo &info); | ||
|
||
Napi::Value GetIpAddress(const Napi::CallbackInfo &info); | ||
Napi::Value GetName(const Napi::CallbackInfo &info); | ||
Napi::Value GetUrlAddress(const Napi::CallbackInfo &info); | ||
|
||
|
||
private: | ||
void Initialize(const Napi::CallbackInfo &info); | ||
|
||
NDIlib_source_t ndiSourceInstance; | ||
NDIlib_recv_instance_t ndiRecvInstance; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface TallyState { | ||
/** | ||
* Whether a source should be marked as "onProgram", which can be understood as "LIVE", "Recording", etc. | ||
*/ | ||
onProgram: boolean; | ||
|
||
/** | ||
* Whether a source should be marked as "onPreview", which indicates that e.g the source is being previewed by a monitor. | ||
*/ | ||
onPreview: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <napi.h> | ||
#include <Processing.NDI.Lib.h> | ||
|
||
#ifndef _SRC_STRUCTURES_TALLY_STATE_H_ | ||
#define _SRC_STRUCTURES_TALLY_STATE_H_ | ||
|
||
class TallyState { | ||
public: | ||
TallyState(const Napi::Object &); | ||
|
||
bool onProgram; | ||
bool onPreview; | ||
|
||
operator NDIlib_tally_t() const; | ||
}; | ||
|
||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <find/find_sources.h> | ||
#include <find/source_instance.h> | ||
#include <iostream> | ||
|
||
Napi::Value FindSources(const Napi::CallbackInfo &info) { | ||
NDIlib_find_create_t NDI_find_create_desc; | ||
NDIlib_find_instance_t pNDI_find = | ||
NDIlib_find_create_v2(&NDI_find_create_desc); | ||
|
||
uint32_t timeout_in_ms = 5000; | ||
if (info.Length() == 1) { | ||
timeout_in_ms = info[0].As<Napi::Number>(); | ||
} | ||
|
||
if (!NDIlib_find_wait_for_sources(pNDI_find, timeout_in_ms)) { | ||
return Napi::Array::New(info.Env()); | ||
} else { | ||
// Get the updated list of sources | ||
uint32_t no_sources = 0; | ||
const NDIlib_source_t *p_sources = | ||
NDIlib_find_get_current_sources(pNDI_find, &no_sources); | ||
|
||
// Display all the sources. | ||
Napi::Array sourcesList = Napi::Array::New(info.Env(), (size_t)no_sources); | ||
|
||
for (uint32_t i = 0; i < no_sources; i++) { | ||
NDIlib_source_t p_source = NDIlib_source_t(p_sources[i]); | ||
|
||
Napi::Object sourceInstance = SourceInstance::New(info.Env(), &p_source); | ||
sourcesList[i] = sourceInstance; | ||
} | ||
|
||
NDIlib_find_destroy(pNDI_find); | ||
|
||
return sourcesList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include <find/source_instance.h> | ||
#include <iostream> | ||
#include <structures/tally_state.h> | ||
|
||
using namespace std; | ||
|
||
Napi::Object SourceInstance::New(Napi::Env env, | ||
NDIlib_source_t *ndiSourceInstance) { | ||
return SourceInstance::constructor.Value().New({ | ||
Napi::External<NDIlib_source_t>::New(env, ndiSourceInstance), | ||
}); | ||
} | ||
|
||
SourceInstance::SourceInstance(const Napi::CallbackInfo &info) | ||
: Napi::ObjectWrap<SourceInstance>(info) { | ||
Napi::Env env = info.Env(); | ||
|
||
if (info.Length() < 1 || (info[0].Type() != napi_external)) { | ||
throw Napi::Error::New( | ||
env, "SourceInstances can only be constructed by native code"); | ||
} | ||
|
||
NDIlib_source_t ndiSourceInstance = | ||
*(info[0].As<Napi::External<NDIlib_source_t> >().Data()); | ||
|
||
string str_ndi_name = ndiSourceInstance.p_ndi_name; | ||
char *cstr_ndi_name = new char[str_ndi_name.length()]; | ||
strcpy(cstr_ndi_name, str_ndi_name.c_str()); | ||
|
||
string str_url_address = ndiSourceInstance.p_url_address; | ||
char *cstr_url_address = new char[str_url_address.length()]; | ||
strcpy(cstr_url_address, str_url_address.c_str()); | ||
|
||
this->ndiSourceInstance = NDIlib_source_t(cstr_ndi_name, cstr_url_address); | ||
|
||
this->Initialize(info); | ||
} | ||
|
||
void SourceInstance::Initialize(const Napi::CallbackInfo &info) { | ||
NDIlib_recv_create_v3_t NDI_recv_create_desc(this->ndiSourceInstance); | ||
|
||
try { | ||
this->ndiRecvInstance = NDIlib_recv_create_v3(&NDI_recv_create_desc); | ||
|
||
if (!this->ndiRecvInstance) { | ||
throw Napi::Error::New(info.Env(), | ||
"Could not initialize source receiver"); | ||
} | ||
} catch (const Napi::Error &error) { | ||
error.ThrowAsJavaScriptException(); | ||
} | ||
} | ||
|
||
void SourceInstance::SetTally(const Napi::CallbackInfo &info) { | ||
if (!info[0].IsObject()) { | ||
Napi::TypeError::New(info.Env(), | ||
"The tallyState argument is expected to be an object") | ||
.ThrowAsJavaScriptException(); | ||
return; | ||
} | ||
|
||
NDIlib_tally_t tally_state = (TallyState)info[0].ToObject(); | ||
NDIlib_recv_set_tally(this->ndiRecvInstance, &tally_state); | ||
} | ||
|
||
Napi::Value SourceInstance::GetIpAddress(const Napi::CallbackInfo &info) { | ||
return Napi::String::New(info.Env(), this->ndiSourceInstance.p_ip_address); | ||
} | ||
|
||
Napi::Value SourceInstance::GetName(const Napi::CallbackInfo &info) { | ||
return Napi::String::New(info.Env(), this->ndiSourceInstance.p_ndi_name); | ||
} | ||
|
||
Napi::Value SourceInstance::GetUrlAddress(const Napi::CallbackInfo &info) { | ||
return Napi::String::New(info.Env(), this->ndiSourceInstance.p_url_address); | ||
} | ||
|
||
SourceInstance::~SourceInstance() { | ||
if (!this->ndiRecvInstance) { | ||
return; | ||
} | ||
|
||
NDIlib_recv_destroy(this->ndiRecvInstance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <structures/tally_state.h> | ||
|
||
TallyState::TallyState(const Napi::Object &object) | ||
: onProgram(object.Get("onProgram").ToBoolean()), | ||
onPreview(object.Get("onPreview").ToBoolean()) {} | ||
|
||
TallyState::operator NDIlib_tally_t() const { | ||
NDIlib_tally_t out; | ||
|
||
out.on_preview = this->onPreview; | ||
out.on_program = this->onProgram; | ||
|
||
return out; | ||
} |