Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
featherbear committed Dec 12, 2022
1 parent 144f18a commit 4b9e2e8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
5 changes: 4 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ group 'com.example.flutter_ndi'
version '1.0'

buildscript {

ext.kotlin_version = '1.6.0'

repositories {
google()
jcenter()
Expand All @@ -22,7 +25,7 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
minSdkVersion 16
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
36 changes: 20 additions & 16 deletions lib/flutter_ndi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ abstract class FlutterNdi {
}
}

static Pointer<Void> createSendHandle(String sourceName) {
static Pointer<NDIlib_send_instance_type> createSendHandle(
String sourceName) {
final source_data = calloc<NDIlib_send_create_t>();
source_data.ref.p_ndi_name = sourceName.toNativeUtf8().cast<Int8>();
source_data.ref.p_ndi_name = sourceName.toNativeUtf8().cast<Char>();

return libNDI.NDIlib_send_create(source_data);
}

static Pointer<Void> createSourceFinder() {
static Pointer<NDIlib_find_instance_type> createSourceFinder() {
final finder_data = calloc<NDIlib_find_create_t>();
finder_data.ref.show_local_sources = true_1;
finder_data.ref.show_local_sources = true;
var result = libNDI.NDIlib_find_create_v2(finder_data);
return result;
// calloc.free(finder_data);
Expand All @@ -91,7 +92,8 @@ abstract class FlutterNdi {
}

static List<NDISource> findSources(
{Pointer<Void>? sourceFinder, bool onlyImmediate = false}) {
{Pointer<NDIlib_find_instance_type>? sourceFinder,
bool onlyImmediate = false}) {
var __orig_sourceFinder = sourceFinder;
if (sourceFinder == null) sourceFinder = createSourceFinder();

Expand All @@ -100,6 +102,7 @@ abstract class FlutterNdi {
Pointer<Uint32> numSources = malloc<Uint32>();
Pointer<NDIlib_source_t> sources =
libNDI.NDIlib_find_get_current_sources(sourceFinder, numSources);

for (var i = 0; i < numSources.value; i++) {
NDIlib_source_t source_t = sources.elementAt(i).ref;
var sourceAddress = source_t.p_url_address.cast<Utf8>().toDartString();
Expand Down Expand Up @@ -127,8 +130,8 @@ abstract class FlutterNdi {
static ReceivePort listenToFrameData(NDISource source) {
var source_t = malloc<NDIlib_source_t>();

source_t.ref.p_ndi_name = source.name.toNativeUtf8().cast<Int8>();
source_t.ref.p_url_address = source.address.toNativeUtf8().cast<Int8>();
source_t.ref.p_ndi_name = source.name.toNativeUtf8().cast<Char>();
source_t.ref.p_url_address = source.address.toNativeUtf8().cast<Char>();

var recvDescription = malloc<NDIlib_recv_create_v3_t>();
recvDescription.ref.source_to_connect_to = source_t.ref;
Expand All @@ -137,12 +140,12 @@ abstract class FlutterNdi {
recvDescription.ref.bandwidth =
NDIlib_recv_bandwidth_e.NDIlib_recv_bandwidth_lowest;
// NDIlib_recv_bandwidth_e.NDIlib_recv_bandwidth_highest;
recvDescription.ref.allow_video_fields = false_1;
recvDescription.ref.allow_video_fields = false;
recvDescription.ref.p_ndi_recv_name =
"Channel 1".toNativeUtf8().cast<Int8>();
"Channel 1".toNativeUtf8().cast<Char>();

Pointer<Void> Receiver =
libNDI.NDIlib_recv_create_v4(recvDescription, nullptr);
Pointer<NDIlib_recv_instance_type> Receiver =
libNDI.NDIlib_recv_create_v3(recvDescription);

// malloc.free(source_t);
// malloc.free(recvDescription)
Expand Down Expand Up @@ -177,7 +180,8 @@ abstract class FlutterNdi {
// https://api.flutter.dev/flutter/dart-isolate/Isolate-class.html

static void _receiverThread(Map map) {
Pointer<Void> Receiver = Pointer<Void>.fromAddress(map['receiver']);
NDIlib_recv_instance_t Receiver =
NDIlib_recv_instance_t.fromAddress(map['receiver']);
SendPort emitter = map['port'];

bool active = true;
Expand Down Expand Up @@ -206,16 +210,16 @@ abstract class FlutterNdi {
int yres = vFrame.ref.yres;
int xres = vFrame.ref.xres;
double dpi = 96.0 * vFrame.ref.picture_aspect_ratio / (xres / yres);
int stride =
vFrame.ref.data_size_if_fourcc_compressed_else_line_stride;
int data_size__if_fourcc_compressed__else_line_stride =
vFrame.ref.data_size_in_bytes;
// Stride = bytes per line
// Should be 4 * width -- BGRA

emitter.send(VideoFrameData(
width: xres,
height: yres,
data: Uint8List.fromList(
vFrame.ref.p_data.asTypedList(yres * stride))));
data: Uint8List.fromList(vFrame.ref.p_data.asTypedList(
yres * data_size__if_fourcc_compressed__else_line_stride))));

libNDI.NDIlib_recv_free_video_v2(Receiver, vFrame);

Expand Down
8 changes: 2 additions & 6 deletions lib/ndi/includes/Processing.NDI.structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,12 @@ typedef struct NDIlib_source_t {
// application readable and might well change in the future. This can be NULL if you do not know it and
// the API internally will instantiate a finder that is used to discover it even if it is not yet
// available on the network.
union { // The current way of addressing the value.
// The current way of addressing the value.
const char* p_url_address;

// We used to use an IP address before we used the more general URL notification this is now
// depreciated but maintained for compatibility.
PROCESSINGNDILIB_DEPRECATED const char* p_ip_address;
};

#if NDILIB_CPP_DEFAULT_CONSTRUCTORS
NDIlib_source_t(const char* p_ndi_name_ = NULL, const char* p_url_address_ = NULL);
Expand Down Expand Up @@ -230,13 +229,12 @@ typedef struct NDIlib_video_frame_v2_t {
// The video data itself.
uint8_t* p_data;

union { // If the FourCC is not a compressed type, then this will be the inter-line stride of the video data
// If the FourCC is not a compressed type, then this will be the inter-line stride of the video data
// in bytes. If the stride is 0, then it will default to sizeof(one pixel)*xres.
int line_stride_in_bytes;

// If the FourCC is a compressed type, then this will be the size of the p_data buffer in bytes.
int data_size_in_bytes;
};

// Per frame metadata for this frame. This is a NULL terminated UTF8 string that should be in XML format.
// If you do not want any metadata then you may specify NULL here.
Expand Down Expand Up @@ -322,14 +320,12 @@ typedef struct NDIlib_audio_frame_v3_t {
// The audio data.
uint8_t* p_data;

union {
// If the FourCC is not a compressed type and the audio format is planar, then this will be the
// stride in bytes for a single channel.
int channel_stride_in_bytes;

// If the FourCC is a compressed type, then this will be the size of the p_data buffer in bytes.
int data_size_in_bytes;
};

// Per frame metadata for this frame. This is a NULL terminated UTF8 string that should be in XML format.
// If you do not want any metadata then you may specify NULL here.
Expand Down

0 comments on commit 4b9e2e8

Please sign in to comment.