Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ endif()

target_sources(
${CMAKE_PROJECT_NAME}

PRIVATE
src/forms/output-settings.cpp
src/forms/output-settings.h
Expand All @@ -49,6 +50,8 @@ target_sources(
src/obs-support/remote-text.hpp
src/obs-support/shared-update.cpp
src/obs-support/shared-update.hpp
src/obs-support/sync-debug.cpp
src/obs-support/sync-debug.h
src/config.cpp
src/config.h
src/main-output.cpp
Expand Down
44 changes: 42 additions & 2 deletions src/ndi-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
******************************************************************************/

#include "plugin-main.h"
#include "obs-support/sync-debug.h"

#include <util/platform.h>
#include <util/threading.h>
Expand Down Expand Up @@ -114,6 +115,10 @@ void ndi_filter_raw_video(void *data, video_data *frame)
if (!frame || !frame->data[0])
return;

obs_sync_debug_log("OBS -> ndi_filter_raw_video",
obs_source_get_name(f->obs_source), (uint64_t)0,
frame->timestamp);

NDIlib_video_frame_v2_t video_frame = {0};
video_frame.xres = f->known_width;
video_frame.yres = f->known_height;
Expand All @@ -122,11 +127,23 @@ void ndi_filter_raw_video(void *data, video_data *frame)
video_frame.frame_rate_D = f->ovi.fps_den;
video_frame.picture_aspect_ratio = 0; // square pixels
video_frame.frame_format_type = NDIlib_frame_format_type_progressive;
video_frame.timecode = NDIlib_send_timecode_synthesize;

// video_frame.timecode = NDIlib_send_timecode_synthesize;
video_frame.timecode = (frame->timestamp / 100);
video_frame.timestamp = frame->timestamp;

video_frame.p_data = frame->data[0];
video_frame.line_stride_in_bytes = frame->linesize[0];

pthread_mutex_lock(&f->ndi_sender_video_mutex);

obs_sync_debug_log("NDI <- ndi_filter_raw_video",
obs_source_get_name(f->obs_source),
video_frame.timecode, video_frame.timestamp);
OBS_SYNC_DEBUG_LOG_VIDEO_TIME("NDI <- ndi_filter",
obs_source_get_name(f->obs_source),
video_frame.timestamp,
(uint8_t *)video_frame.p_data);
ndiLib->send_send_video_v2(f->ndi_sender, &video_frame);
pthread_mutex_unlock(&f->ndi_sender_video_mutex);
}
Expand Down Expand Up @@ -185,7 +202,12 @@ void ndi_filter_offscreen_render(void *data, uint32_t, uint32_t)
}

video_frame output_frame;

if (video_output_lock_frame(f->video_output, &output_frame, 1, os_gettime_ns())) {
obs_sync_debug_log("OBS -> ndi_filter_offscreen_render",
obs_source_get_name(f->obs_source),
0, os_gettime_ns());

if (f->video_data) {
gs_stagesurface_unmap(f->stagesurface);
f->video_data = nullptr;
Expand Down Expand Up @@ -353,12 +375,20 @@ obs_audio_data *ndi_filter_asyncaudio(void *data, obs_audio_data *audio_data)
// ndi-output.cpp/ndi_output_raw_audio(...)
auto f = (ndi_filter_t *)data;

obs_sync_debug_log("OBS -> ndi_filter_asyncaudio",
obs_source_get_name(f->obs_source), 0,
audio_data->timestamp);

obs_get_audio_info(&f->oai);

NDIlib_audio_frame_v3_t audio_frame = {0};
audio_frame.sample_rate = f->oai.samples_per_sec;
audio_frame.no_channels = f->oai.speakers;
audio_frame.timecode = NDIlib_send_timecode_synthesize;

// audio_frame.timecode = NDIlib_send_timecode_synthesize;
audio_frame.timecode = audio_data->timestamp / 100;
audio_frame.timestamp = audio_data->timestamp;

audio_frame.no_samples = audio_data->frames;
audio_frame.channel_stride_in_bytes =
audio_frame.no_samples *
Expand Down Expand Up @@ -389,7 +419,17 @@ obs_audio_data *ndi_filter_asyncaudio(void *data, obs_audio_data *audio_data)
audio_frame.p_data = f->audio_conv_buffer;

pthread_mutex_lock(&f->ndi_sender_audio_mutex);

obs_sync_debug_log("NDI <- ndi_filter_asyncaudio",
obs_source_get_name(f->obs_source),
audio_frame.timecode, audio_frame.timestamp);
OBS_SYNC_DEBUG_LOG_AUDIO_TIME("NDI <- ndi_filter",
obs_source_get_name(f->obs_source),
audio_frame.timestamp, audio_frame.p_data,
audio_frame.no_samples,
audio_frame.sample_rate);
ndiLib->send_send_audio_v3(f->ndi_sender, &audio_frame);

pthread_mutex_unlock(&f->ndi_sender_audio_mutex);

return audio_data;
Expand Down
21 changes: 19 additions & 2 deletions src/ndi-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
******************************************************************************/

#include "plugin-main.h"
#include "obs-support/sync-debug.h"
// #include "plugin-support.h"


static FORCE_INLINE uint32_t min_uint32(uint32_t a, uint32_t b)
{
return a < b ? a : b;
Expand Down Expand Up @@ -312,7 +314,8 @@ void ndi_output_rawvideo(void *data, video_data *frame)
auto o = (ndi_output_t *)data;
if (!o->started || !o->frame_width || !o->frame_height)
return;

obs_sync_debug_log("OBS -> ndi_output_rawvideo", o->ndi_name,
(uint64_t)0, frame->timestamp);
uint32_t width = o->frame_width;
uint32_t height = o->frame_height;

Expand All @@ -336,6 +339,11 @@ void ndi_output_rawvideo(void *data, video_data *frame)
video_frame.line_stride_in_bytes = frame->linesize[0];
}

obs_sync_debug_log("NDI <- ndi_output_rawvideo", o->ndi_name,
video_frame.timecode, video_frame.timestamp);
OBS_SYNC_DEBUG_LOG_VIDEO_TIME("NDI <- ndi_output", o->ndi_name,
frame->timestamp,
(uint8_t *)video_frame.p_data);
ndiLib->send_send_video_async_v2(o->ndi_sender, &video_frame);
}

Expand All @@ -347,6 +355,9 @@ void ndi_output_rawaudio(void *data, audio_data *frame)
if (!o->started || !o->audio_samplerate || !o->audio_channels)
return;

obs_sync_debug_log("OBS -> ndi_output_rawaudio", o->ndi_name,
(uint64_t)0, frame->timestamp);

NDIlib_audio_frame_v3_t audio_frame = {0};
audio_frame.sample_rate = o->audio_samplerate;
audio_frame.no_channels = (int)o->audio_channels;
Expand Down Expand Up @@ -376,7 +387,13 @@ void ndi_output_rawaudio(void *data, audio_data *frame)
}

audio_frame.p_data = o->audio_conv_buffer;

OBS_SYNC_DEBUG_LOG_AUDIO_TIME("NDI <- ndi_output", o->ndi_name,
frame->timestamp,
(float *)audio_frame.p_data,
audio_frame.no_samples,
audio_frame.sample_rate);
obs_sync_debug_log("NDI <- ndi_output_rawaudio", o->ndi_name,
audio_frame.timecode, audio_frame.timestamp);
ndiLib->send_send_audio_v3(o->ndi_sender, &audio_frame);
}

Expand Down
92 changes: 90 additions & 2 deletions src/ndi-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <util/platform.h>
#include <util/threading.h>

#include "obs-support/sync-debug.h"
#include <QDesktopServices>
#include <QUrl>

Expand Down Expand Up @@ -706,6 +707,14 @@
return;
}

obs_sync_debug_log("NDI -> ndi_source_thread_process_audio2",
obs_source_get_name(obs_source),
ndi_audio_frame->timecode,
ndi_audio_frame->timestamp);
OBS_SYNC_DEBUG_LOG_AUDIO_TIME(
"NDI -> ndi_source_thread", obs_source_get_name(obs_source),
ndi_audio_frame->timestamp, ndi_audio_frame2->p_data,

Check failure on line 716 in src/ndi-source.cpp

View workflow job for this annotation

GitHub Actions / Build Project 🧱 / Build for macOS 🍏

use of undeclared identifier 'ndi_audio_frame2'
ndi_audio_frame->no_samples, ndi_audio_frame2->sample_rate);

Check failure on line 717 in src/ndi-source.cpp

View workflow job for this annotation

GitHub Actions / Build Project 🧱 / Build for macOS 🍏

use of undeclared identifier 'ndi_audio_frame2'
const int channelCount = ndi_audio_frame->no_channels > 8 ? 8 : ndi_audio_frame->no_channels;

obs_audio_frame->speakers = channel_count_to_layout(channelCount);
Expand All @@ -728,12 +737,84 @@
(uint8_t *)ndi_audio_frame->p_data + (i * ndi_audio_frame->channel_stride_in_bytes);
}

obs_sync_debug_log("OBS <- ndi_source_thread_process_audio2",
obs_source_get_name(obs_source), (int64_t)0,
obs_audio_frame->timestamp);
OBS_SYNC_DEBUG_LOG_AUDIO_TIME(
"OBS <- ndi_source_thread", obs_source_get_name(obs_source),
obs_audio_frame->timestamp, (float *)obs_audio_frame->data[0],
obs_audio_frame->frames, obs_audio_frame->samples_per_sec);
obs_source_output_audio(obs_source, obs_audio_frame);
}

void ndi_source_thread_process_video2(ndi_source_config_t *config, NDIlib_video_frame_v2_t *ndi_video_frame,
obs_source *obs_source, obs_source_frame *obs_video_frame)
void ndi_source_thread_process_audio3(ndi_source_config_t *config,

Check failure on line 750 in src/ndi-source.cpp

View workflow job for this annotation

GitHub Actions / Build Project 🧱 / Build for macOS 🍏

redefinition of 'ndi_source_thread_process_audio3'
NDIlib_audio_frame_v3_t *ndi_audio_frame3,
obs_source_t *obs_source,
obs_source_audio *obs_audio_frame)
{
if (!config->audio_enabled) {
return;
}

obs_sync_debug_log("NDI -> ndi_source_thread_process_audio3",
obs_source_get_name(obs_source),
ndi_audio_frame3->timecode,
ndi_audio_frame3->timestamp);

OBS_SYNC_DEBUG_LOG_AUDIO_TIME(
"NDI -> ndi_source_thread", obs_source_get_name(obs_source),
ndi_audio_frame3->timestamp, (float *)ndi_audio_frame3->p_data,
ndi_audio_frame3->no_samples, ndi_audio_frame3->sample_rate);

const int channelCount = ndi_audio_frame3->no_channels > 8
? 8
: ndi_audio_frame3->no_channels;

obs_audio_frame->speakers = channel_count_to_layout(channelCount);

switch (config->sync_mode) {
case PROP_SYNC_NDI_TIMESTAMP:
obs_audio_frame->timestamp =
(uint64_t)(ndi_audio_frame3->timestamp * 100);
break;

case PROP_SYNC_NDI_SOURCE_TIMECODE:
obs_audio_frame->timestamp =
(uint64_t)(ndi_audio_frame3->timecode * 100);
break;
}

obs_audio_frame->samples_per_sec = ndi_audio_frame3->sample_rate;
obs_audio_frame->format = AUDIO_FORMAT_FLOAT_PLANAR;
obs_audio_frame->frames = ndi_audio_frame3->no_samples;
for (int i = 0; i < channelCount; ++i) {
obs_audio_frame->data[i] =
(uint8_t *)ndi_audio_frame3->p_data +
(i * ndi_audio_frame3->channel_stride_in_bytes);
}

obs_sync_debug_log("OBS <- ndi_source_thread_process_audio3",
obs_source_get_name(obs_source), (int64_t)0,
obs_audio_frame->timestamp);
OBS_SYNC_DEBUG_LOG_AUDIO_TIME(
"OBS <- ndi_source_thread", obs_source_get_name(obs_source),
obs_audio_frame->timestamp, (float *)obs_audio_frame->data[0],
obs_audio_frame->frames, obs_audio_frame->samples_per_sec);
obs_source_output_audio(obs_source, obs_audio_frame);
}

void ndi_source_thread_process_video2(ndi_source_config_t *config, NDIlib_video_frame_v2_t *ndi_video_frame,
obs_source *obs_source, obs_source_frame *obs_video_frame)

{
obs_sync_debug_log("NDI -> ndi_source_thread_process_video2",
obs_source_get_name(obs_source),
ndi_video_frame->timecode,
ndi_video_frame->timestamp);
OBS_SYNC_DEBUG_LOG_VIDEO_TIME("NDI -> ndi_source_thread",
obs_source_get_name(obs_source),
ndi_video_frame->timestamp,
(uint8_t *)ndi_video_frame->p_data);
switch (ndi_video_frame->FourCC) {
case NDIlib_FourCC_type_BGRA:
obs_video_frame->format = VIDEO_FORMAT_BGRA;
Expand Down Expand Up @@ -787,6 +868,13 @@
video_format_get_parameters(config->yuv_colorspace, config->yuv_range, obs_video_frame->color_matrix,
obs_video_frame->color_range_min, obs_video_frame->color_range_max);

obs_sync_debug_log("OBS <- ndi_source_thread_process_video2",
obs_source_get_name(obs_source), (int64_t)0,
obs_video_frame->timestamp);
OBS_SYNC_DEBUG_LOG_VIDEO_TIME("OBS <- ndi_source_thread",
obs_source_get_name(obs_source),
(int64_t)obs_video_frame->timestamp,
obs_video_frame->data[0]);
obs_source_output_video(obs_source, obs_video_frame);
}

Expand Down
Loading
Loading