@@ -39,6 +39,8 @@ napi_value sendVideo(napi_env env, napi_callback_info info)
39
39
40
40
// Create an NDI source that is called "My 16bpp Audio" and is clocked to the audio.
41
41
NDIlib_send_create_t NDI_send_create_desc;
42
+
43
+ // Set name of NDI source
42
44
NDI_send_create_desc.p_ndi_name = " My 8bpp video" ;
43
45
NDI_send_create_desc.clock_audio = true ;
44
46
@@ -47,40 +49,49 @@ napi_value sendVideo(napi_env env, napi_callback_info info)
47
49
if (!pNDI_send)
48
50
NAPI_THROW_ERROR (" Failed to create send instance." );
49
51
50
- // We are going to create a 1920x1080 interlaced frame at 29.97Hz.
51
- NDIlib_video_frame_v2_t NDI_video_frame;
52
- NDI_video_frame.xres = 1920 ;
53
- NDI_video_frame.yres = 1080 ;
54
- NDI_video_frame.FourCC = NDIlib_FourCC_type_BGRX;
55
- NDI_video_frame.p_data = (uint8_t *)malloc (NDI_video_frame.xres *NDI_video_frame.yres * 4 );
52
+ // We are going to create a 1920x1080 interlaced frame at 29.97Hz.
53
+ NDIlib_video_frame_v2_t NDI_video_frame;
54
+
55
+ NDI_video_frame.xres = 1920 ;
56
+ NDI_video_frame.yres = 1080 ;
57
+ NDI_video_frame.FourCC = NDIlib_FourCC_type_BGRX;
58
+
59
+ // Calculate number of pixels in video frame
60
+ const auto number_of_pixels = NDI_video_frame.xres * NDI_video_frame.yres ;
61
+
62
+ // Allocate buffer for the video frame
63
+ // 8 bit per channel (BGRX) per pixel
64
+ NDI_video_frame.p_data = (uint8_t *)malloc (number_of_pixels * 4 );
56
65
57
- // Run for one minute
58
- using namespace std ::chrono;
59
- for (const auto start = high_resolution_clock::now (); high_resolution_clock::now () - start < minutes (5 );)
60
- { // Get the current time
61
- const auto start_send = high_resolution_clock::now ();
66
+ // Run for 5 minutes
67
+ using namespace std ::chrono;
68
+ for (const auto start = high_resolution_clock::now (); high_resolution_clock::now () - start < minutes (5 );)
69
+ { // Get the current time
70
+ const auto start_send = high_resolution_clock::now ();
62
71
63
- // Send 200 frames
64
- for (int idx = 200 ; idx; idx--)
65
- { // Fill in the buffer. It is likely that you would do something much smarter than this.
66
- memset ((void *)NDI_video_frame.p_data , (idx & 1 ) ? 255 : 0 , NDI_video_frame.xres *NDI_video_frame.yres * 4 );
72
+ // Send 200 frames
73
+ for (int idx = 200 ; idx; idx--)
74
+ {
75
+ // Fill in the buffer. It is likely that you would do something much smarter than this.
76
+ // All pixels is painted the same color - the color is switching between black and white based on the frame number
77
+ memset ((void *)NDI_video_frame.p_data , (idx & 1 ) ? 255 : 0 , number_of_pixels * 4 );
67
78
68
- // We now submit the frame. Note that this call will be clocked so that we end up submitting at exactly 29.97fps.
69
- NDIlib_send_send_video_v2 (pNDI_send, &NDI_video_frame);
70
- }
79
+ // We now submit the frame. Note that this call will be clocked so that we end up submitting at exactly 29.97fps.
80
+ NDIlib_send_send_video_v2 (pNDI_send, &NDI_video_frame);
81
+ }
71
82
72
- // Just display something helpful
73
- printf (" 200 frames sent, at %1.2ffps\n " , 200 .0f / duration_cast<duration<float >>(high_resolution_clock::now () - start_send).count ());
74
- }
83
+ // Just display something helpful
84
+ printf (" 200 frames sent, at %1.2ffps\n " , 200 .0f / duration_cast<duration<float >>(high_resolution_clock::now () - start_send).count ());
85
+ }
75
86
76
- // Free the video frame
77
- free (NDI_video_frame.p_data );
87
+ // Free the video frame
88
+ free (NDI_video_frame.p_data );
78
89
79
- // Destroy the NDI sender
80
- NDIlib_send_destroy (pNDI_send);
90
+ // Destroy the NDI sender
91
+ NDIlib_send_destroy (pNDI_send);
81
92
82
- // Not required, but nice
83
- NDIlib_destroy ();
93
+ // Not required, but nice
94
+ NDIlib_destroy ();
84
95
85
96
status = napi_get_undefined (env, &result);
86
97
CHECK_STATUS;
0 commit comments