mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-08-29 02:03:03 +08:00
virtualcam-module: Clarify resolution variables
The `cx`/`cy`/`interval` variables specifically specify the OBS/placeholder resolution/interval. The resolution may not be the same as the filter's resolution (when scaling is used). Instead, prefix these variables with `obs_` to improve clarity.
This commit is contained in:
@@ -49,15 +49,15 @@ VCamFilter::VCamFilter()
|
||||
/* ---------------------------------------- */
|
||||
/* add last/current obs res/interval */
|
||||
|
||||
uint32_t new_cx = cx;
|
||||
uint32_t new_cy = cy;
|
||||
uint64_t new_interval = interval;
|
||||
uint32_t new_obs_cx = obs_cx;
|
||||
uint32_t new_obs_cy = obs_cy;
|
||||
uint64_t new_obs_interval = obs_interval;
|
||||
|
||||
vq = video_queue_open();
|
||||
if (vq) {
|
||||
if (video_queue_state(vq) == SHARED_QUEUE_STATE_READY) {
|
||||
video_queue_get_info(vq, &new_cx, &new_cy,
|
||||
&new_interval);
|
||||
video_queue_get_info(vq, &new_obs_cx, &new_obs_cy,
|
||||
&new_obs_interval);
|
||||
}
|
||||
|
||||
/* don't keep it open until the filter actually starts */
|
||||
@@ -79,13 +79,15 @@ VCamFilter::VCamFilter()
|
||||
if (ReadFile(file, res, sizeof(res) - 1, &len,
|
||||
nullptr)) {
|
||||
res[len] = 0;
|
||||
int vals = sscanf(
|
||||
res, "%" PRIu32 "x%" PRIu32 "x%" PRIu64,
|
||||
&new_cx, &new_cy, &new_interval);
|
||||
int vals = sscanf(res,
|
||||
"%" PRIu32 "x%" PRIu32
|
||||
"x%" PRIu64,
|
||||
&new_obs_cx, &new_obs_cy,
|
||||
&new_obs_interval);
|
||||
if (vals != 3) {
|
||||
new_cx = cx;
|
||||
new_cy = cy;
|
||||
new_interval = interval;
|
||||
new_obs_cx = obs_cx;
|
||||
new_obs_cy = obs_cy;
|
||||
new_obs_interval = obs_interval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,14 +95,20 @@ VCamFilter::VCamFilter()
|
||||
}
|
||||
}
|
||||
|
||||
if (new_cx != cx || new_cy != cy || new_interval != interval) {
|
||||
AddVideoFormat(VideoFormat::NV12, new_cx, new_cy, new_interval);
|
||||
AddVideoFormat(VideoFormat::I420, new_cx, new_cy, new_interval);
|
||||
AddVideoFormat(VideoFormat::YUY2, new_cx, new_cy, new_interval);
|
||||
SetVideoFormat(VideoFormat::NV12, new_cx, new_cy, new_interval);
|
||||
cx = new_cx;
|
||||
cy = new_cy;
|
||||
interval = new_interval;
|
||||
if (new_obs_cx != obs_cx || new_obs_cy != obs_cy ||
|
||||
new_obs_interval != obs_interval) {
|
||||
AddVideoFormat(VideoFormat::NV12, new_obs_cx, new_obs_cy,
|
||||
new_obs_interval);
|
||||
AddVideoFormat(VideoFormat::I420, new_obs_cx, new_obs_cy,
|
||||
new_obs_interval);
|
||||
AddVideoFormat(VideoFormat::YUY2, new_obs_cx, new_obs_cy,
|
||||
new_obs_interval);
|
||||
SetVideoFormat(VideoFormat::NV12, new_obs_cx, new_obs_cy,
|
||||
new_obs_interval);
|
||||
|
||||
obs_cx = new_obs_cx;
|
||||
obs_cy = new_obs_cy;
|
||||
obs_interval = new_obs_interval;
|
||||
}
|
||||
|
||||
/* ---------------------------------------- */
|
||||
@@ -178,9 +186,9 @@ void VCamFilter::Thread()
|
||||
uint64_t cur_time = gettime_100ns();
|
||||
uint64_t filter_time = GetTime();
|
||||
|
||||
cx = GetCX();
|
||||
cy = GetCY();
|
||||
interval = GetInterval();
|
||||
obs_cx = (uint32_t)GetCX();
|
||||
obs_cy = (uint32_t)GetCY();
|
||||
obs_interval = (uint64_t)GetInterval();
|
||||
|
||||
/* ---------------------------------------- */
|
||||
/* load placeholder image */
|
||||
@@ -195,8 +203,9 @@ void VCamFilter::Thread()
|
||||
/* Created dynamically based on output resolution changes */
|
||||
placeholder.scaled_data = nullptr;
|
||||
|
||||
nv12_scale_init(&scaler, TARGET_FORMAT_NV12, cx, cy, cx, cy);
|
||||
nv12_scale_init(&placeholder.scaler, TARGET_FORMAT_NV12, cx, cy,
|
||||
nv12_scale_init(&scaler, TARGET_FORMAT_NV12, obs_cx, obs_cy, obs_cx,
|
||||
obs_cy);
|
||||
nv12_scale_init(&placeholder.scaler, TARGET_FORMAT_NV12, obs_cx, obs_cy,
|
||||
placeholder.cx, placeholder.cy);
|
||||
|
||||
UpdatePlaceholder();
|
||||
@@ -204,16 +213,16 @@ void VCamFilter::Thread()
|
||||
while (!stopped()) {
|
||||
if (os_atomic_load_bool(&active))
|
||||
Frame(filter_time);
|
||||
sleepto_100ns(cur_time += interval);
|
||||
filter_time += interval;
|
||||
sleepto_100ns(cur_time += obs_interval);
|
||||
filter_time += obs_interval;
|
||||
}
|
||||
}
|
||||
|
||||
void VCamFilter::Frame(uint64_t ts)
|
||||
{
|
||||
uint32_t new_cx = cx;
|
||||
uint32_t new_cy = cy;
|
||||
uint64_t new_interval = interval;
|
||||
uint32_t new_obs_cx = obs_cx;
|
||||
uint32_t new_obs_cy = obs_cy;
|
||||
uint64_t new_obs_interval = obs_interval;
|
||||
|
||||
/* cx, cy and interval are the resolution and frame rate of the
|
||||
virtual camera _source_, ie OBS' output. Do not confuse cx / cy
|
||||
@@ -229,8 +238,8 @@ void VCamFilter::Frame(uint64_t ts)
|
||||
if (state == SHARED_QUEUE_STATE_READY) {
|
||||
/* The virtualcam output from OBS has started, get
|
||||
the actual cx / cy of the data stream */
|
||||
video_queue_get_info(vq, &new_cx, &new_cy,
|
||||
&new_interval);
|
||||
video_queue_get_info(vq, &new_obs_cx, &new_obs_cy,
|
||||
&new_obs_interval);
|
||||
} else if (state == SHARED_QUEUE_STATE_STOPPING) {
|
||||
video_queue_close(vq);
|
||||
vq = nullptr;
|
||||
@@ -242,28 +251,29 @@ void VCamFilter::Frame(uint64_t ts)
|
||||
if (state != SHARED_QUEUE_STATE_READY) {
|
||||
/* Virtualcam output not yet started, assume it's
|
||||
the same resolution as the filter output */
|
||||
new_cx = GetCX();
|
||||
new_cy = GetCY();
|
||||
new_interval = GetInterval();
|
||||
new_obs_cx = GetCX();
|
||||
new_obs_cy = GetCY();
|
||||
new_obs_interval = GetInterval();
|
||||
}
|
||||
|
||||
if (new_cx != cx || new_cy != cy || new_interval != interval) {
|
||||
if (new_obs_cx != obs_cx || new_obs_cy != obs_cy ||
|
||||
new_obs_interval != obs_interval) {
|
||||
/* The res / FPS of the video coming from OBS has
|
||||
changed, update parameters as needed */
|
||||
if (in_obs) {
|
||||
/* If the vcam is being used inside obs, adjust
|
||||
the format we present to match */
|
||||
SetVideoFormat(GetVideoFormat(), new_cx, new_cy,
|
||||
new_interval);
|
||||
SetVideoFormat(GetVideoFormat(), new_obs_cx, new_obs_cy,
|
||||
new_obs_interval);
|
||||
}
|
||||
|
||||
/* Re-initialize the main scaler to use the new resolution */
|
||||
nv12_scale_init(&scaler, scaler.format, GetCX(), GetCY(),
|
||||
new_cx, new_cy);
|
||||
new_obs_cx, new_obs_cy);
|
||||
|
||||
cx = new_cx;
|
||||
cy = new_cy;
|
||||
interval = new_interval;
|
||||
obs_cx = new_obs_cx;
|
||||
obs_cy = new_obs_cy;
|
||||
obs_interval = new_obs_interval;
|
||||
|
||||
UpdatePlaceholder();
|
||||
}
|
||||
@@ -295,7 +305,7 @@ void VCamFilter::Frame(uint64_t ts)
|
||||
else
|
||||
ShowDefaultFrame(ptr);
|
||||
|
||||
UnlockSampleData(ts, ts + interval);
|
||||
UnlockSampleData(ts, ts + obs_interval);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ class VCamFilter : public DShow::OutputFilter {
|
||||
bool in_obs = false;
|
||||
enum queue_state prev_state = SHARED_QUEUE_STATE_INVALID;
|
||||
placeholder_t placeholder;
|
||||
uint32_t cx = DEFAULT_CX;
|
||||
uint32_t cy = DEFAULT_CY;
|
||||
uint32_t obs_cx = DEFAULT_CX;
|
||||
uint32_t obs_cy = DEFAULT_CY;
|
||||
uint64_t obs_interval = DEFAULT_INTERVAL;
|
||||
DShow::VideoFormat format;
|
||||
uint64_t interval = DEFAULT_INTERVAL;
|
||||
WinHandle thread_start;
|
||||
WinHandle thread_stop;
|
||||
volatile bool active = false;
|
||||
|
||||
Reference in New Issue
Block a user