Skip to content
Merged
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
1 change: 1 addition & 0 deletions ci/test_ported_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"obs-source-deinterlace-draw.c.h.o",
"obs-source-deinterlace-pacing.c.h.o",
"obs-source-draw-plan.c.h.o",
"obs-source-frame-copy.c.h.o",
"obs-source-load.c.h.o",
"obs-source-ptm-gate.c.h.o",
"obs-source-render-route.c.h.o",
Expand Down
14 changes: 14 additions & 0 deletions libobs/build/libobs-ported-source-frame-copy.pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Precompiled header (BUILD.md) for the libobs unity group
* libobs.ported-source-frame-copy. obs-source-frame-copy.c needs its
* declarations (obs-source-frame-copy.h), the video_format and
* video_range_type enums and the format_is_yuv() and resolve_video_range()
* inlines (media-io/video-io.h) and memset, so the C oracle and the C test
* can compile it on their own. The implementation file includes this header
* and nothing else. */

#pragma once

#include <string.h>

#include "media-io/video-io.h"
#include "obs-source-frame-copy.h"
1 change: 1 addition & 0 deletions libobs/build/libobs.pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
#include "obs-source-color-space.h"
#include "obs-source-conversion-plan.h"
#include "obs-source-draw-plan.h"
#include "obs-source-frame-copy.h"
#include "obs-source-ptm-gate.h"
#include "obs-source-render-route.h"
#include "obs-source-size.h"
Expand Down
5 changes: 5 additions & 0 deletions libobs/build/libobs.ported-source-frame-copy+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Unity group (BUILD.md): ported obs-source-frame-copy.c. */

#include "libobs/build/libobs-ported-source-frame-copy.pch.h"

#include "libobs/obs-source-frame-copy.c.h"
2 changes: 2 additions & 0 deletions libobs/build/source-sets.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"obs-source-deinterlace-pacing.h",
"obs-source-draw-plan.h",
"obs-source-draw-technique.h",
"obs-source-frame-copy.h",
"obs-source-load.h",
"obs-source-ptm-gate.h",
"obs-source-render-route.h",
Expand Down Expand Up @@ -194,6 +195,7 @@
"build/libobs.ported-source-deinterlace-draw+.h.c",
"build/libobs.ported-source-deinterlace-pacing+.h.c",
"build/libobs.ported-source-draw-plan+.h.c",
"build/libobs.ported-source-frame-copy+.h.c",
"build/libobs.ported-source-load+.h.c",
"build/libobs.ported-source-profiler+.h.c",
"build/libobs.ported-source-ptm-gate+.h.c",
Expand Down
8 changes: 8 additions & 0 deletions libobs/cmake/rust-exports.map
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@
obs_source_draw_plan_reads_white_level;
obs_source_draw_plan_multiplier;
obs_source_draw_plan_convert;
/* obs-source-frame-copy.c. obs-source.c calls them inside libobs. Not
* EXPORT. */
obs_source_frame_copy_plan;
obs_source_frame_copy_cache_step;
obs_source_frame_copy_cache_clean;
obs_source_frame_copy_full_range;
obs_source_frame_copy_full_range2;
obs_source_frame_copy_preload_changed;
/* obs-source-ptm-gate.c. obs-source.c calls them inside libobs. Not
* EXPORT. */
obs_source_ptm_gate_stop_time;
Expand Down
11 changes: 11 additions & 0 deletions libobs/cmake/rust-hidden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ obs_source_draw_plan_technique
obs_source_draw_plan_reads_white_level
obs_source_draw_plan_multiplier
obs_source_draw_plan_convert
# obs-source-frame-copy.c: copy_frame_data(), cache_video(), clean_cache(),
# preload_frame_changed() and the obs_source_output_video(),
# obs_source_preload_video() and obs_source_set_video_frame() families in
# obs-source.c call them inside libobs. Declared in obs-source-frame-copy.h
# without EXPORT, so the shims stay hidden the same way.
obs_source_frame_copy_plan
obs_source_frame_copy_cache_step
obs_source_frame_copy_cache_clean
obs_source_frame_copy_full_range
obs_source_frame_copy_full_range2
obs_source_frame_copy_preload_changed
# obs-source-ptm-gate.c: source_muted() and get_source_volume() in
# obs-source.c call them inside libobs. Declared in obs-source-ptm-gate.h
# without EXPORT, so the shims stay hidden the same way.
Expand Down
7 changes: 7 additions & 0 deletions libobs/cmake/rust-unexports-macos.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ _obs_source_draw_plan_technique
_obs_source_draw_plan_reads_white_level
_obs_source_draw_plan_multiplier
_obs_source_draw_plan_convert
# obs-source-frame-copy.c: obs-source.c calls them inside libobs. Not EXPORT.
_obs_source_frame_copy_plan
_obs_source_frame_copy_cache_step
_obs_source_frame_copy_cache_clean
_obs_source_frame_copy_full_range
_obs_source_frame_copy_full_range2
_obs_source_frame_copy_preload_changed
# obs-source-ptm-gate.c: obs-source.c calls them inside libobs. Not EXPORT.
_obs_source_ptm_gate_stop_time
_obs_source_ptm_gate_held
Expand Down
184 changes: 184 additions & 0 deletions libobs/obs-source-frame-copy.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/******************************************************************************
Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include "libobs/build/libobs-ported-source-frame-copy.pch.h"

/* The async frame copy plan and cache decisions, moved from obs-source.c:
* the plane copies of copy_frame_data_line(), copy_frame_data_plane() and
* copy_frame_data(), async_texture_changed() and the queue limit of
* cache_video(), one entry of clean_cache(), the full-range rule of the
* obs_source_output_video(), _preload_video() and _set_video_frame()
* families, and preload_frame_changed(), on plain values. obs-source.c runs
* the copies and keeps the frames, the cache and the locks. Declared in
* obs-source-frame-copy.h without EXPORT. */

_Static_assert(sizeof(enum video_format) == sizeof(int), "enum video_format is passed as int");
_Static_assert(sizeof(enum video_range_type) == sizeof(int), "enum video_range_type is passed as int");

/* copy_frame_data_plane(): one copy when the line sizes are equal, else
* lines rows of the smaller line size. */
static inline void frame_copy_plane(struct obs_source_frame_copy_plan *plan, uint32_t plane, uint32_t lines,
const struct obs_source_frame_copy_lines *src,
const struct obs_source_frame_copy_lines *dst)
{
struct obs_source_frame_plane_copy *copy = &plan->planes[plan->count++];
const uint32_t src_linesize = src->linesize[plane];
const uint32_t dst_linesize = dst->linesize[plane];

copy->rows = lines;
copy->src_stride = src_linesize;
copy->dst_stride = dst_linesize;

if (dst_linesize != src_linesize) {
copy->whole = false;
copy->bytes = dst_linesize < src_linesize ? dst_linesize : src_linesize;
} else {
copy->whole = true;
copy->bytes = (size_t)dst_linesize * (size_t)lines;
}
}

struct obs_source_frame_copy_plan obs_source_frame_copy_plan(int format, bool full_range, uint32_t height,
struct obs_source_frame_copy_lines src,
struct obs_source_frame_copy_lines dst)
{
struct obs_source_frame_copy_plan plan;
memset(&plan, 0, sizeof(plan));

plan.color_range = !full_range;

switch ((enum video_format)format) {
case VIDEO_FORMAT_I420:
case VIDEO_FORMAT_I010: {
const uint32_t half_height = (height + 1) / 2;
frame_copy_plane(&plan, 0, height, &src, &dst);
frame_copy_plane(&plan, 1, half_height, &src, &dst);
frame_copy_plane(&plan, 2, half_height, &src, &dst);
break;
}

case VIDEO_FORMAT_NV12:
case VIDEO_FORMAT_P010: {
const uint32_t half_height = (height + 1) / 2;
frame_copy_plane(&plan, 0, height, &src, &dst);
frame_copy_plane(&plan, 1, half_height, &src, &dst);
break;
}

case VIDEO_FORMAT_I444:
case VIDEO_FORMAT_I422:
case VIDEO_FORMAT_I210:
case VIDEO_FORMAT_I412:
frame_copy_plane(&plan, 0, height, &src, &dst);
frame_copy_plane(&plan, 1, height, &src, &dst);
frame_copy_plane(&plan, 2, height, &src, &dst);
break;

case VIDEO_FORMAT_YVYU:
case VIDEO_FORMAT_YUY2:
case VIDEO_FORMAT_UYVY:
case VIDEO_FORMAT_NONE:
case VIDEO_FORMAT_RGBA:
case VIDEO_FORMAT_BGRA:
case VIDEO_FORMAT_BGRX:
case VIDEO_FORMAT_Y800:
case VIDEO_FORMAT_BGR3:
case VIDEO_FORMAT_AYUV:
case VIDEO_FORMAT_V210:
case VIDEO_FORMAT_R10L:
frame_copy_plane(&plan, 0, height, &src, &dst);
break;

case VIDEO_FORMAT_I40A: {
const uint32_t half_height = (height + 1) / 2;
frame_copy_plane(&plan, 0, height, &src, &dst);
frame_copy_plane(&plan, 1, half_height, &src, &dst);
frame_copy_plane(&plan, 2, half_height, &src, &dst);
frame_copy_plane(&plan, 3, height, &src, &dst);
break;
}

case VIDEO_FORMAT_I42A:
case VIDEO_FORMAT_YUVA:
case VIDEO_FORMAT_YA2L:
frame_copy_plane(&plan, 0, height, &src, &dst);
frame_copy_plane(&plan, 1, height, &src, &dst);
frame_copy_plane(&plan, 2, height, &src, &dst);
frame_copy_plane(&plan, 3, height, &src, &dst);
break;

case VIDEO_FORMAT_P216:
case VIDEO_FORMAT_P416:
/* Unimplemented */
break;
}

return plan;
}

/* async_texture_changed(): the size or the convert type differs. */
static inline bool frame_copy_texture_changed(struct obs_source_frame_copy_key cache,
struct obs_source_frame_copy_key frame)
{
return cache.width != frame.width || cache.height != frame.height || cache.convert_type != frame.convert_type;
}

enum obs_source_frame_cache_step obs_source_frame_copy_cache_step(size_t queued, struct obs_source_frame_copy_key cache,
struct obs_source_frame_copy_key frame)
{
if (queued >= OBS_SOURCE_FRAME_COPY_MAX_ASYNC_FRAMES)
return OBS_SOURCE_FRAME_CACHE_OVERFLOW;

if (frame_copy_texture_changed(cache, frame))
return OBS_SOURCE_FRAME_CACHE_RESET;

return OBS_SOURCE_FRAME_CACHE_KEEP;
}

struct obs_source_frame_cache_age obs_source_frame_copy_cache_clean(bool used, long unused_count)
{
struct obs_source_frame_cache_age age;
memset(&age, 0, sizeof(age));

age.unused_count = unused_count;
if (!used) {
age.counted = true;
if (++age.unused_count == OBS_SOURCE_FRAME_COPY_MAX_UNUSED)
age.drop = true;
}

return age;
}

bool obs_source_frame_copy_full_range(int format, bool full_range)
{
return format_is_yuv((enum video_format)format) ? full_range : true;
}

bool obs_source_frame_copy_full_range2(int format, int range)
{
return resolve_video_range((enum video_format)format, (enum video_range_type)range) == VIDEO_RANGE_FULL;
}

bool obs_source_frame_copy_preload_changed(bool has_preload, struct obs_source_frame_copy_shape preload,
struct obs_source_frame_copy_shape in)
{
if (!has_preload)
return true;

return in.width != preload.width || in.height != preload.height || in.format != preload.format;
}
Loading
Loading