New upstream version 23.2.1+dfsg1
This commit is contained in:
parent
cdc9a9fc87
commit
b14f9eae6d
1017 changed files with 37232 additions and 11111 deletions
|
|
@ -116,7 +116,8 @@ elseif(APPLE)
|
|||
util/platform-nix.c
|
||||
util/platform-cocoa.m)
|
||||
set(libobs_PLATFORM_HEADERS
|
||||
util/threading-posix.h)
|
||||
util/threading-posix.h
|
||||
util/apple/cfstring-utils.h)
|
||||
set(libobs_audio_monitoring_SOURCES
|
||||
audio-monitoring/osx/coreaudio-enum-devices.c
|
||||
audio-monitoring/osx/coreaudio-output.c
|
||||
|
|
@ -383,6 +384,7 @@ set(libobs_libobs_SOURCES
|
|||
obs-view.c
|
||||
obs-scene.c
|
||||
obs-audio.c
|
||||
obs-video-gpu-encode.c
|
||||
obs-video.c)
|
||||
set(libobs_libobs_HEADERS
|
||||
${libobs_PLATFORM_HEADERS}
|
||||
|
|
@ -446,6 +448,14 @@ if(BUILD_CAPTIONS)
|
|||
endif()
|
||||
|
||||
add_library(libobs SHARED ${libobs_SOURCES} ${libobs_HEADERS})
|
||||
if(UNIX AND NOT APPLE)
|
||||
set(DEST_DIR "${CMAKE_INSTALL_PREFIX}")
|
||||
foreach(LIB "obs" "rt")
|
||||
set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}")
|
||||
endforeach()
|
||||
CONFIGURE_FILE("libobs.pc.in" "libobs.pc" @ONLY)
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libobs.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
|
||||
endif()
|
||||
|
||||
set_target_properties(libobs PROPERTIES
|
||||
OUTPUT_NAME obs
|
||||
|
|
@ -455,7 +465,12 @@ target_compile_definitions(libobs
|
|||
PUBLIC
|
||||
HAVE_OBSCONFIG_H)
|
||||
|
||||
if(NOT MSVC)
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le")
|
||||
target_compile_options(libobs
|
||||
PUBLIC
|
||||
-mvsx)
|
||||
add_compile_definitions(NO_WARN_X86_INTRINSICS)
|
||||
elseif(NOT MSVC)
|
||||
target_compile_options(libobs
|
||||
PUBLIC
|
||||
-mmmx
|
||||
|
|
|
|||
|
|
@ -3,23 +3,18 @@
|
|||
|
||||
#include "../../obs-internal.h"
|
||||
#include "../../util/dstr.h"
|
||||
#include "../../util/apple/cfstring-utils.h"
|
||||
|
||||
#include "mac-helpers.h"
|
||||
|
||||
static inline bool cf_to_cstr(CFStringRef ref, char *buf, size_t size)
|
||||
{
|
||||
if (!ref) return false;
|
||||
return (bool)CFStringGetCString(ref, buf, size, kCFStringEncodingUTF8);
|
||||
}
|
||||
|
||||
static bool obs_enum_audio_monitoring_device(obs_enum_audio_device_cb cb,
|
||||
void *data, AudioDeviceID id, bool allow_inputs)
|
||||
{
|
||||
UInt32 size = 0;
|
||||
CFStringRef cf_name = NULL;
|
||||
CFStringRef cf_uid = NULL;
|
||||
char name[1024];
|
||||
char uid[1024];
|
||||
char *name = NULL;
|
||||
char *uid = NULL;
|
||||
OSStatus stat;
|
||||
bool cont = true;
|
||||
|
||||
|
|
@ -46,12 +41,14 @@ static bool obs_enum_audio_monitoring_device(obs_enum_audio_device_cb cb,
|
|||
if (!success(stat, "get audio device name"))
|
||||
goto fail;
|
||||
|
||||
if (!cf_to_cstr(cf_name, name, sizeof(name))) {
|
||||
name = cfstr_copy_cstr(cf_name, kCFStringEncodingUTF8);
|
||||
if (!name) {
|
||||
blog(LOG_WARNING, "%s: failed to convert name", __FUNCTION__);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!cf_to_cstr(cf_uid, uid, sizeof(uid))) {
|
||||
uid = cfstr_copy_cstr(cf_uid, kCFStringEncodingUTF8);
|
||||
if (!uid) {
|
||||
blog(LOG_WARNING, "%s: failed to convert uid", __FUNCTION__);
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -59,6 +56,8 @@ static bool obs_enum_audio_monitoring_device(obs_enum_audio_device_cb cb,
|
|||
cont = cb(data, name, uid);
|
||||
|
||||
fail:
|
||||
bfree(name);
|
||||
bfree(uid);
|
||||
if (cf_name)
|
||||
CFRelease(cf_name);
|
||||
if (cf_uid)
|
||||
|
|
|
|||
|
|
@ -307,14 +307,15 @@ int_fast32_t pulseaudio_connect_playback(pa_stream *s, const char *name,
|
|||
return -1;
|
||||
|
||||
size_t dev_len = strlen(name) - 8;
|
||||
char device[dev_len];
|
||||
char *device = bzalloc(dev_len + 1);
|
||||
memcpy(device, name, dev_len);
|
||||
device[dev_len] = '\0';
|
||||
|
||||
pulseaudio_lock();
|
||||
int_fast32_t ret = pa_stream_connect_playback(s, device, attr, flags,
|
||||
NULL, NULL);
|
||||
pulseaudio_unlock();
|
||||
|
||||
bfree(device);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmdeviceapi.h>
|
||||
#include <audioclient.h>
|
||||
|
|
|
|||
64
libobs/data/area.effect
Normal file
64
libobs/data/area.effect
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
uniform float4x4 ViewProj;
|
||||
uniform float2 base_dimension_i;
|
||||
uniform texture2d image;
|
||||
|
||||
struct VertInOut {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertInOut VSDefault(VertInOut vert_in)
|
||||
{
|
||||
VertInOut vert_out;
|
||||
vert_out.pos = mul(float4(vert_in.pos.xyz, 1.0), ViewProj);
|
||||
vert_out.uv = vert_in.uv;
|
||||
return vert_out;
|
||||
}
|
||||
|
||||
float4 PSDrawAreaRGBA(VertInOut vert_in) : TARGET
|
||||
{
|
||||
float4 totalcolor = float4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
float2 uv = vert_in.uv;
|
||||
float2 uvdelta = float2(ddx(uv.x), ddy(uv.y));
|
||||
|
||||
// Handle potential OpenGL flip.
|
||||
uvdelta.y = abs(uvdelta.y);
|
||||
|
||||
float2 uvhalfdelta = 0.5 * uvdelta;
|
||||
float2 uvmin = uv - uvhalfdelta;
|
||||
float2 uvmax = uv + uvhalfdelta;
|
||||
|
||||
int2 loadindexmin = int2(uvmin / base_dimension_i);
|
||||
int2 loadindexmax = int2(uvmax / base_dimension_i);
|
||||
|
||||
float2 targetpos = uv / uvdelta;
|
||||
float2 targetposmin = targetpos - 0.5;
|
||||
float2 targetposmax = targetpos + 0.5;
|
||||
float2 scale = base_dimension_i / uvdelta;
|
||||
for (int loadindexy = loadindexmin.y; loadindexy <= loadindexmax.y; ++loadindexy)
|
||||
{
|
||||
for (int loadindexx = loadindexmin.x; loadindexx <= loadindexmax.x; ++loadindexx)
|
||||
{
|
||||
int2 loadindex = int2(loadindexx, loadindexy);
|
||||
float2 potentialtargetmin = float2(loadindex) * scale;
|
||||
float2 potentialtargetmax = potentialtargetmin + scale;
|
||||
float2 targetmin = max(potentialtargetmin, targetposmin);
|
||||
float2 targetmax = min(potentialtargetmax, targetposmax);
|
||||
float area = (targetmax.x - targetmin.x) * (targetmax.y - targetmin.y);
|
||||
float4 sample = image.Load(int3(loadindex, 0));
|
||||
totalcolor += area * sample;
|
||||
}
|
||||
}
|
||||
|
||||
return totalcolor;
|
||||
}
|
||||
|
||||
technique Draw
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(vert_in);
|
||||
pixel_shader = PSDrawAreaRGBA(vert_in);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,8 +7,6 @@
|
|||
uniform float4x4 ViewProj;
|
||||
uniform texture2d image;
|
||||
uniform float4x4 color_matrix;
|
||||
uniform float3 color_range_min = {0.0, 0.0, 0.0};
|
||||
uniform float3 color_range_max = {1.0, 1.0, 1.0};
|
||||
uniform float2 base_dimension_i;
|
||||
uniform float undistort_factor = 1.0;
|
||||
|
||||
|
|
@ -132,13 +130,19 @@ float4 PSDrawBicubicRGBA(VertData v_in, bool undistort) : TARGET
|
|||
return DrawBicubic(v_in, undistort);
|
||||
}
|
||||
|
||||
float4 PSDrawBicubicMatrix(VertData v_in) : TARGET
|
||||
float4 PSDrawBicubicRGBADivide(VertData v_in) : TARGET
|
||||
{
|
||||
float4 rgba = DrawBicubic(v_in, false);
|
||||
float4 yuv;
|
||||
float alpha = rgba.a;
|
||||
float multiplier = (alpha > 0.0) ? (1.0 / alpha) : 0.0;
|
||||
return float4(rgba.rgb * multiplier, alpha);
|
||||
}
|
||||
|
||||
yuv.xyz = clamp(rgba.xyz, color_range_min, color_range_max);
|
||||
return saturate(mul(float4(yuv.xyz, 1.0), color_matrix));
|
||||
float4 PSDrawBicubicMatrix(VertData v_in) : TARGET
|
||||
{
|
||||
float3 rgb = DrawBicubic(v_in, false).rgb;
|
||||
float3 yuv = mul(float4(saturate(rgb), 1.0), color_matrix).xyz;
|
||||
return float4(yuv, 1.0);
|
||||
}
|
||||
|
||||
technique Draw
|
||||
|
|
@ -150,6 +154,15 @@ technique Draw
|
|||
}
|
||||
}
|
||||
|
||||
technique DrawAlphaDivide
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(v_in);
|
||||
pixel_shader = PSDrawBicubicRGBADivide(v_in);
|
||||
}
|
||||
}
|
||||
|
||||
technique DrawUndistort
|
||||
{
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@
|
|||
uniform float4x4 ViewProj;
|
||||
uniform texture2d image;
|
||||
uniform float4x4 color_matrix;
|
||||
uniform float3 color_range_min = {0.0, 0.0, 0.0};
|
||||
uniform float3 color_range_max = {1.0, 1.0, 1.0};
|
||||
uniform float2 base_dimension_i;
|
||||
|
||||
sampler_state textureSampler {
|
||||
|
|
@ -56,12 +54,19 @@ float4 PSDrawLowresBilinearRGBA(VertData v_in) : TARGET
|
|||
return DrawLowresBilinear(v_in);
|
||||
}
|
||||
|
||||
float4 PSDrawLowresBilinearRGBADivide(VertData v_in) : TARGET
|
||||
{
|
||||
float4 rgba = DrawLowresBilinear(v_in);
|
||||
float alpha = rgba.a;
|
||||
float multiplier = (alpha > 0.0) ? (1.0 / alpha) : 0.0;
|
||||
return float4(rgba.rgb * multiplier, alpha);
|
||||
}
|
||||
|
||||
float4 PSDrawLowresBilinearMatrix(VertData v_in) : TARGET
|
||||
{
|
||||
float4 yuv = DrawLowresBilinear(v_in);
|
||||
|
||||
yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max);
|
||||
return saturate(mul(float4(yuv.xyz, 1.0), color_matrix));
|
||||
float3 rgb = DrawLowresBilinear(v_in).rgb;
|
||||
float3 yuv = mul(float4(saturate(rgb), 1.0), color_matrix).xyz;
|
||||
return float4(yuv, 1.0);
|
||||
}
|
||||
|
||||
technique Draw
|
||||
|
|
@ -73,6 +78,15 @@ technique Draw
|
|||
}
|
||||
}
|
||||
|
||||
technique DrawAlphaDivide
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(v_in);
|
||||
pixel_shader = PSDrawLowresBilinearRGBADivide(v_in);
|
||||
}
|
||||
}
|
||||
|
||||
technique DrawMatrix
|
||||
{
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
uniform float4x4 ViewProj;
|
||||
uniform float4x4 color_matrix;
|
||||
uniform float3 color_range_min = {0.0, 0.0, 0.0};
|
||||
uniform float3 color_range_max = {1.0, 1.0, 1.0};
|
||||
uniform texture2d image;
|
||||
|
||||
sampler_state def_sampler {
|
||||
|
|
@ -28,11 +26,19 @@ float4 PSDrawBare(VertInOut vert_in) : TARGET
|
|||
return image.Sample(def_sampler, vert_in.uv);
|
||||
}
|
||||
|
||||
float4 PSDrawAlphaDivide(VertInOut vert_in) : TARGET
|
||||
{
|
||||
float4 rgba = image.Sample(def_sampler, vert_in.uv);
|
||||
float alpha = rgba.a;
|
||||
float multiplier = (alpha > 0.0) ? (1.0 / alpha) : 0.0;
|
||||
return float4(rgba.rgb * multiplier, alpha);
|
||||
}
|
||||
|
||||
float4 PSDrawMatrix(VertInOut vert_in) : TARGET
|
||||
{
|
||||
float4 yuv = image.Sample(def_sampler, vert_in.uv);
|
||||
yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max);
|
||||
return saturate(mul(float4(yuv.xyz, 1.0), color_matrix));
|
||||
float3 rgb = image.Sample(def_sampler, vert_in.uv).rgb;
|
||||
float3 yuv = mul(float4(rgb, 1.0), color_matrix).xyz;
|
||||
return float4(yuv, 1.0);
|
||||
}
|
||||
|
||||
technique Draw
|
||||
|
|
@ -44,6 +50,15 @@ technique Draw
|
|||
}
|
||||
}
|
||||
|
||||
technique DrawAlphaDivide
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(vert_in);
|
||||
pixel_shader = PSDrawAlphaDivide(vert_in);
|
||||
}
|
||||
}
|
||||
|
||||
technique DrawMatrix
|
||||
{
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -18,9 +18,6 @@
|
|||
|
||||
uniform float4x4 ViewProj;
|
||||
uniform texture2d image;
|
||||
uniform float4x4 color_matrix;
|
||||
uniform float3 color_range_min = {0.0, 0.0, 0.0};
|
||||
uniform float3 color_range_max = {1.0, 1.0, 1.0};
|
||||
|
||||
uniform texture2d previous_image;
|
||||
uniform float2 dimensions;
|
||||
|
|
@ -267,7 +264,7 @@ VertData VSDefault(VertData v_in)
|
|||
return vert_out;
|
||||
}
|
||||
|
||||
#define TECHNIQUE(rgba_ps, matrix_ps) \
|
||||
#define TECHNIQUE(rgba_ps) \
|
||||
technique Draw \
|
||||
{ \
|
||||
pass \
|
||||
|
|
@ -275,19 +272,4 @@ technique Draw \
|
|||
vertex_shader = VSDefault(v_in); \
|
||||
pixel_shader = rgba_ps(v_in); \
|
||||
} \
|
||||
} \
|
||||
float4 matrix_ps(VertData v_in) : TARGET \
|
||||
{ \
|
||||
float4 yuv = rgba_ps(v_in); \
|
||||
yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max); \
|
||||
return saturate(mul(float4(yuv.xyz, 1.0), color_matrix)); \
|
||||
} \
|
||||
\
|
||||
technique DrawMatrix \
|
||||
{ \
|
||||
pass \
|
||||
{ \
|
||||
vertex_shader = VSDefault(v_in); \
|
||||
pixel_shader = matrix_ps(v_in); \
|
||||
} \
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,4 +18,4 @@
|
|||
|
||||
#include "deinterlace_base.effect"
|
||||
|
||||
TECHNIQUE( PSBlendRGBA, PSBlendMatrix);
|
||||
TECHNIQUE(PSBlendRGBA);
|
||||
|
|
|
|||
|
|
@ -18,4 +18,4 @@
|
|||
|
||||
#include "deinterlace_base.effect"
|
||||
|
||||
TECHNIQUE(PSBlendRGBA_2x, PSBlendMatrix_2x);
|
||||
TECHNIQUE(PSBlendRGBA_2x);
|
||||
|
|
|
|||
|
|
@ -18,4 +18,4 @@
|
|||
|
||||
#include "deinterlace_base.effect"
|
||||
|
||||
TECHNIQUE(PSDiscardRGBA, PSDiscardMatrix);
|
||||
TECHNIQUE(PSDiscardRGBA);
|
||||
|
|
|
|||
|
|
@ -18,4 +18,4 @@
|
|||
|
||||
#include "deinterlace_base.effect"
|
||||
|
||||
TECHNIQUE(PSDiscardRGBA_2x, PSDiscardMatrix_2x);
|
||||
TECHNIQUE(PSDiscardRGBA_2x);
|
||||
|
|
|
|||
|
|
@ -18,4 +18,4 @@
|
|||
|
||||
#include "deinterlace_base.effect"
|
||||
|
||||
TECHNIQUE(PSLinearRGBA, PSLinearMatrix);
|
||||
TECHNIQUE(PSLinearRGBA);
|
||||
|
|
|
|||
|
|
@ -18,4 +18,4 @@
|
|||
|
||||
#include "deinterlace_base.effect"
|
||||
|
||||
TECHNIQUE(PSLinearRGBA_2x, PSLinearxMatrixA_2x);
|
||||
TECHNIQUE(PSLinearRGBA_2x);
|
||||
|
|
|
|||
|
|
@ -18,4 +18,4 @@
|
|||
|
||||
#include "deinterlace_base.effect"
|
||||
|
||||
TECHNIQUE(PSYadifMode0RGBA, PSYadifMode0Matrix);
|
||||
TECHNIQUE(PSYadifMode0RGBA);
|
||||
|
|
|
|||
|
|
@ -18,4 +18,4 @@
|
|||
|
||||
#include "deinterlace_base.effect"
|
||||
|
||||
TECHNIQUE(PSYadifMode0RGBA_2x, PSYadifMode0Matrix_2x);
|
||||
TECHNIQUE(PSYadifMode0RGBA_2x);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,10 @@ uniform int int_input_width;
|
|||
uniform int int_u_plane_offset;
|
||||
uniform int int_v_plane_offset;
|
||||
|
||||
uniform float4x4 color_matrix;
|
||||
uniform float3 color_range_min = {0.0, 0.0, 0.0};
|
||||
uniform float3 color_range_max = {1.0, 1.0, 1.0};
|
||||
|
||||
uniform texture2d image;
|
||||
|
||||
sampler_state def_sampler {
|
||||
|
|
@ -126,6 +130,16 @@ float4 PSNV12(VertInOut vert_in) : TARGET
|
|||
}
|
||||
}
|
||||
|
||||
float PSNV12_Y(VertInOut vert_in) : TARGET
|
||||
{
|
||||
return image.Sample(def_sampler, vert_in.uv.xy).y;
|
||||
}
|
||||
|
||||
float2 PSNV12_UV(VertInOut vert_in) : TARGET
|
||||
{
|
||||
return image.Sample(def_sampler, vert_in.uv.xy).xz;
|
||||
}
|
||||
|
||||
float4 PSPlanar420(VertInOut vert_in) : TARGET
|
||||
{
|
||||
float v_mul = floor(vert_in.uv.y * input_height);
|
||||
|
|
@ -273,8 +287,10 @@ float4 PSPacked422_Reverse(VertInOut vert_in, int u_pos, int v_pos,
|
|||
x += input_width_i_d2;
|
||||
|
||||
float4 texel = image.Sample(def_sampler, float2(x, y));
|
||||
return float4(odd > 0.5 ? texel[y1_pos] : texel[y0_pos],
|
||||
texel[u_pos], texel[v_pos], 1.0);
|
||||
float3 yuv = float3(odd > 0.5 ? texel[y1_pos] : texel[y0_pos],
|
||||
texel[u_pos], texel[v_pos]);
|
||||
yuv = clamp(yuv, color_range_min, color_range_max);
|
||||
return saturate(mul(float4(yuv, 1.0), color_matrix));
|
||||
}
|
||||
|
||||
float4 PSPlanar420_Reverse(VertInOut vert_in) : TARGET
|
||||
|
|
@ -287,12 +303,32 @@ float4 PSPlanar420_Reverse(VertInOut vert_in) : TARGET
|
|||
int chroma1 = int_u_plane_offset + chroma_offset;
|
||||
int chroma2 = int_v_plane_offset + chroma_offset;
|
||||
|
||||
return float4(
|
||||
float3 yuv = float3(
|
||||
GetIntOffsetColor(lum_offset),
|
||||
GetIntOffsetColor(chroma1),
|
||||
GetIntOffsetColor(chroma2),
|
||||
1.0
|
||||
GetIntOffsetColor(chroma2)
|
||||
);
|
||||
yuv = clamp(yuv, color_range_min, color_range_max);
|
||||
return saturate(mul(float4(yuv, 1.0), color_matrix));
|
||||
}
|
||||
|
||||
float4 PSPlanar444_Reverse(VertInOut vert_in) : TARGET
|
||||
{
|
||||
int x = int(vert_in.uv.x * width + PRECISION_OFFSET);
|
||||
int y = int(vert_in.uv.y * height + PRECISION_OFFSET);
|
||||
|
||||
int lum_offset = y * int_width + x;
|
||||
int chroma_offset = y * int_width + x;
|
||||
int chroma1 = int_u_plane_offset + chroma_offset;
|
||||
int chroma2 = int_v_plane_offset + chroma_offset;
|
||||
|
||||
float3 yuv = float3(
|
||||
GetIntOffsetColor(lum_offset),
|
||||
GetIntOffsetColor(chroma1),
|
||||
GetIntOffsetColor(chroma2)
|
||||
);
|
||||
yuv = clamp(yuv, color_range_min, color_range_max);
|
||||
return saturate(mul(float4(yuv, 1.0), color_matrix));
|
||||
}
|
||||
|
||||
float4 PSNV12_Reverse(VertInOut vert_in) : TARGET
|
||||
|
|
@ -304,12 +340,42 @@ float4 PSNV12_Reverse(VertInOut vert_in) : TARGET
|
|||
int chroma_offset = (y / 2) * (int_width / 2) + x / 2;
|
||||
int chroma = int_u_plane_offset + chroma_offset * 2;
|
||||
|
||||
return float4(
|
||||
float3 yuv = float3(
|
||||
GetIntOffsetColor(lum_offset),
|
||||
GetIntOffsetColor(chroma),
|
||||
GetIntOffsetColor(chroma + 1),
|
||||
1.0
|
||||
GetIntOffsetColor(chroma + 1)
|
||||
);
|
||||
yuv = clamp(yuv, color_range_min, color_range_max);
|
||||
return saturate(mul(float4(yuv, 1.0), color_matrix));
|
||||
}
|
||||
|
||||
float4 PSY800_Limited(VertInOut vert_in) : TARGET
|
||||
{
|
||||
int x = int(vert_in.uv.x * width + PRECISION_OFFSET);
|
||||
int y = int(vert_in.uv.y * height + PRECISION_OFFSET);
|
||||
|
||||
float limited = image.Load(int3(x, y, 0)).x;
|
||||
float full = saturate((limited - (16.0 / 255.0)) * (255.0 / 219.0));
|
||||
return float4(full, full, full, 1.0);
|
||||
}
|
||||
|
||||
float4 PSY800_Full(VertInOut vert_in) : TARGET
|
||||
{
|
||||
int x = int(vert_in.uv.x * width + PRECISION_OFFSET);
|
||||
int y = int(vert_in.uv.y * height + PRECISION_OFFSET);
|
||||
|
||||
float3 full = image.Load(int3(x, y, 0)).xxx;
|
||||
return float4(full, 1.0);
|
||||
}
|
||||
|
||||
float4 PSRGB_Limited(VertInOut vert_in) : TARGET
|
||||
{
|
||||
int x = int(vert_in.uv.x * width + PRECISION_OFFSET);
|
||||
int y = int(vert_in.uv.y * height + PRECISION_OFFSET);
|
||||
|
||||
float4 rgba = image.Load(int3(x, y, 0));
|
||||
rgba.rgb = saturate((rgba.rgb - (16.0 / 255.0)) * (255.0 / 219.0));
|
||||
return rgba;
|
||||
}
|
||||
|
||||
technique Planar420
|
||||
|
|
@ -339,6 +405,24 @@ technique NV12
|
|||
}
|
||||
}
|
||||
|
||||
technique NV12_Y
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(vert_in);
|
||||
pixel_shader = PSNV12_Y(vert_in);
|
||||
}
|
||||
}
|
||||
|
||||
technique NV12_UV
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(vert_in);
|
||||
pixel_shader = PSNV12_UV(vert_in);
|
||||
}
|
||||
}
|
||||
|
||||
technique UYVY_Reverse
|
||||
{
|
||||
pass
|
||||
|
|
@ -375,6 +459,15 @@ technique I420_Reverse
|
|||
}
|
||||
}
|
||||
|
||||
technique I444_Reverse
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(vert_in);
|
||||
pixel_shader = PSPlanar444_Reverse(vert_in);
|
||||
}
|
||||
}
|
||||
|
||||
technique NV12_Reverse
|
||||
{
|
||||
pass
|
||||
|
|
@ -383,3 +476,30 @@ technique NV12_Reverse
|
|||
pixel_shader = PSNV12_Reverse(vert_in);
|
||||
}
|
||||
}
|
||||
|
||||
technique Y800_Limited
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(vert_in);
|
||||
pixel_shader = PSY800_Limited(vert_in);
|
||||
}
|
||||
}
|
||||
|
||||
technique Y800_Full
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(vert_in);
|
||||
pixel_shader = PSY800_Full(vert_in);
|
||||
}
|
||||
}
|
||||
|
||||
technique RGB_Limited
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(vert_in);
|
||||
pixel_shader = PSRGB_Limited(vert_in);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@
|
|||
uniform float4x4 ViewProj;
|
||||
uniform texture2d image;
|
||||
uniform float4x4 color_matrix;
|
||||
uniform float3 color_range_min = {0.0, 0.0, 0.0};
|
||||
uniform float3 color_range_max = {1.0, 1.0, 1.0};
|
||||
uniform float2 base_dimension_i;
|
||||
uniform float undistort_factor = 1.0;
|
||||
|
||||
|
|
@ -140,13 +138,19 @@ float4 PSDrawLanczosRGBA(FragData v_in, bool undistort) : TARGET
|
|||
return DrawLanczos(v_in, undistort);
|
||||
}
|
||||
|
||||
float4 PSDrawLanczosMatrix(FragData v_in) : TARGET
|
||||
float4 PSDrawLanczosRGBADivide(FragData v_in) : TARGET
|
||||
{
|
||||
float4 rgba = DrawLanczos(v_in, false);
|
||||
float4 yuv;
|
||||
float alpha = rgba.a;
|
||||
float multiplier = (alpha > 0.0) ? (1.0 / alpha) : 0.0;
|
||||
return float4(rgba.rgb * multiplier, alpha);
|
||||
}
|
||||
|
||||
yuv.xyz = clamp(rgba.xyz, color_range_min, color_range_max);
|
||||
return saturate(mul(float4(yuv.xyz, 1.0), color_matrix));
|
||||
float4 PSDrawLanczosMatrix(FragData v_in) : TARGET
|
||||
{
|
||||
float3 rgb = DrawLanczos(v_in, false).rgb;
|
||||
float3 yuv = mul(float4(saturate(rgb), 1.0), color_matrix).xyz;
|
||||
return float4(yuv, 1.0);
|
||||
}
|
||||
|
||||
technique Draw
|
||||
|
|
@ -158,6 +162,15 @@ technique Draw
|
|||
}
|
||||
}
|
||||
|
||||
technique DrawAlphaDivide
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(v_in);
|
||||
pixel_shader = PSDrawLanczosRGBADivide(v_in);
|
||||
}
|
||||
}
|
||||
|
||||
technique DrawUndistort
|
||||
{
|
||||
pass
|
||||
|
|
|
|||
36
libobs/data/repeat.effect
Normal file
36
libobs/data/repeat.effect
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
uniform float4x4 ViewProj;
|
||||
uniform texture2d image;
|
||||
uniform float2 scale;
|
||||
|
||||
sampler_state def_sampler {
|
||||
Filter = Linear;
|
||||
AddressU = Repeat;
|
||||
AddressV = Repeat;
|
||||
};
|
||||
|
||||
struct VertInOut {
|
||||
float4 pos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertInOut VSDefault(VertInOut vert_in)
|
||||
{
|
||||
VertInOut vert_out;
|
||||
vert_out.pos = mul(float4(vert_in.pos.xyz, 1.0), ViewProj);
|
||||
vert_out.uv = vert_in.uv * scale;
|
||||
return vert_out;
|
||||
}
|
||||
|
||||
float4 PSDrawBare(VertInOut vert_in) : TARGET
|
||||
{
|
||||
return image.Sample(def_sampler, vert_in.uv);
|
||||
}
|
||||
|
||||
technique Draw
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_shader = VSDefault(vert_in);
|
||||
pixel_shader = PSDrawBare(vert_in);
|
||||
}
|
||||
}
|
||||
|
|
@ -142,6 +142,9 @@ EXPORT void device_frustum(gs_device_t *device, float left, float right,
|
|||
float top, float bottom, float znear, float zfar);
|
||||
EXPORT void device_projection_push(gs_device_t *device);
|
||||
EXPORT void device_projection_pop(gs_device_t *device);
|
||||
EXPORT void device_debug_marker_begin(gs_device_t *device,
|
||||
const char *markername, const float color[4]);
|
||||
EXPORT void device_debug_marker_end(gs_device_t *device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,39 @@
|
|||
#include "effect-parser.h"
|
||||
#include "effect.h"
|
||||
|
||||
static inline bool ep_parse_param_assign(struct effect_parser *ep,
|
||||
struct ep_param *param);
|
||||
|
||||
static enum gs_shader_param_type get_effect_param_type(const char *type)
|
||||
{
|
||||
if (strcmp(type, "float") == 0)
|
||||
return GS_SHADER_PARAM_FLOAT;
|
||||
else if (strcmp(type, "float2") == 0)
|
||||
return GS_SHADER_PARAM_VEC2;
|
||||
else if (strcmp(type, "float3") == 0)
|
||||
return GS_SHADER_PARAM_VEC3;
|
||||
else if (strcmp(type, "float4") == 0)
|
||||
return GS_SHADER_PARAM_VEC4;
|
||||
else if (strcmp(type, "int2") == 0)
|
||||
return GS_SHADER_PARAM_INT2;
|
||||
else if (strcmp(type, "int3") == 0)
|
||||
return GS_SHADER_PARAM_INT3;
|
||||
else if (strcmp(type, "int4") == 0)
|
||||
return GS_SHADER_PARAM_INT4;
|
||||
else if (astrcmp_n(type, "texture", 7) == 0)
|
||||
return GS_SHADER_PARAM_TEXTURE;
|
||||
else if (strcmp(type, "float4x4") == 0)
|
||||
return GS_SHADER_PARAM_MATRIX4X4;
|
||||
else if (strcmp(type, "bool") == 0)
|
||||
return GS_SHADER_PARAM_BOOL;
|
||||
else if (strcmp(type, "int") == 0)
|
||||
return GS_SHADER_PARAM_INT;
|
||||
else if (strcmp(type, "string") == 0)
|
||||
return GS_SHADER_PARAM_STRING;
|
||||
|
||||
return GS_SHADER_PARAM_UNKNOWN;
|
||||
}
|
||||
|
||||
void ep_free(struct effect_parser *ep)
|
||||
{
|
||||
size_t i;
|
||||
|
|
@ -92,6 +125,18 @@ static inline struct ep_param *ep_getparam(struct effect_parser *ep,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static inline struct ep_param *ep_getannotation(struct ep_param *param,
|
||||
const char *name)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < param->annotations.num; i++) {
|
||||
if (strcmp(name, param->annotations.array[i].name) == 0)
|
||||
return param->annotations.array+i;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline struct ep_func *ep_getfunc_strref(struct effect_parser *ep,
|
||||
const struct strref *ref)
|
||||
{
|
||||
|
|
@ -262,6 +307,145 @@ error:
|
|||
ep_struct_free(&eps);
|
||||
}
|
||||
|
||||
static inline int ep_parse_param_annotation_var(struct effect_parser *ep,
|
||||
struct ep_param *var)
|
||||
{
|
||||
int code;
|
||||
|
||||
/* -------------------------------------- */
|
||||
/* variable type */
|
||||
|
||||
if (!cf_next_valid_token(&ep->cfp))
|
||||
return PARSE_EOF;
|
||||
|
||||
if (cf_token_is(&ep->cfp, ";"))
|
||||
return PARSE_CONTINUE;
|
||||
if (cf_token_is(&ep->cfp, ">"))
|
||||
return PARSE_BREAK;
|
||||
|
||||
code = cf_token_is_type(&ep->cfp, CFTOKEN_NAME, "type name", ";");
|
||||
if (code != PARSE_SUCCESS)
|
||||
return code;
|
||||
|
||||
bfree(var->type);
|
||||
cf_copy_token(&ep->cfp, &var->type);
|
||||
|
||||
/* -------------------------------------- */
|
||||
/* variable name */
|
||||
|
||||
if (!cf_next_valid_token(&ep->cfp))
|
||||
return PARSE_EOF;
|
||||
|
||||
if (cf_token_is(&ep->cfp, ";")) {
|
||||
cf_adderror_expecting(&ep->cfp, "variable name");
|
||||
return PARSE_UNEXPECTED_CONTINUE;
|
||||
}
|
||||
if (cf_token_is(&ep->cfp, ">")) {
|
||||
cf_adderror_expecting(&ep->cfp, "variable name");
|
||||
return PARSE_UNEXPECTED_BREAK;
|
||||
}
|
||||
|
||||
code = cf_token_is_type(&ep->cfp, CFTOKEN_NAME, "variable name", ";");
|
||||
if (code != PARSE_SUCCESS)
|
||||
return code;
|
||||
|
||||
bfree(var->name);
|
||||
cf_copy_token(&ep->cfp, &var->name);
|
||||
|
||||
/* -------------------------------------- */
|
||||
/* variable mapping if any (POSITION, TEXCOORD, etc) */
|
||||
|
||||
if (!cf_next_valid_token(&ep->cfp))
|
||||
return PARSE_EOF;
|
||||
|
||||
if (cf_token_is(&ep->cfp, ":")) {
|
||||
cf_adderror_expecting(&ep->cfp, "= or ;");
|
||||
return PARSE_UNEXPECTED_BREAK;
|
||||
} else if (cf_token_is(&ep->cfp, ">")) {
|
||||
cf_adderror_expecting(&ep->cfp, "= or ;");
|
||||
return PARSE_UNEXPECTED_BREAK;
|
||||
} else if (cf_token_is(&ep->cfp, "=")) {
|
||||
if (!ep_parse_param_assign(ep, var)) {
|
||||
cf_adderror_expecting(&ep->cfp, "assignment value");
|
||||
return PARSE_UNEXPECTED_BREAK;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------- */
|
||||
|
||||
if (!cf_token_is(&ep->cfp, ";")) {
|
||||
if (!cf_go_to_valid_token(&ep->cfp, ";", ">")) {
|
||||
cf_adderror_expecting(&ep->cfp, "; or >");
|
||||
return PARSE_EOF;
|
||||
}
|
||||
return PARSE_CONTINUE;
|
||||
}
|
||||
|
||||
return PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
static int ep_parse_annotations(struct effect_parser *ep,
|
||||
struct darray *annotations)
|
||||
{
|
||||
if (!cf_token_is(&ep->cfp, "<")) {
|
||||
cf_adderror_expecting(&ep->cfp, "<");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* get annotation variables */
|
||||
while (true) {
|
||||
bool do_break = false;
|
||||
struct ep_param var;
|
||||
|
||||
ep_param_init(&var, bstrdup(""), bstrdup(""), false, false,
|
||||
false);
|
||||
|
||||
switch (ep_parse_param_annotation_var(ep, &var)) {
|
||||
case PARSE_UNEXPECTED_CONTINUE:
|
||||
cf_adderror_syntax_error(&ep->cfp);
|
||||
/* Falls through. */
|
||||
case PARSE_CONTINUE:
|
||||
ep_param_free(&var);
|
||||
continue;
|
||||
|
||||
case PARSE_UNEXPECTED_BREAK:
|
||||
cf_adderror_syntax_error(&ep->cfp);
|
||||
/* Falls through. */
|
||||
case PARSE_BREAK:
|
||||
ep_param_free(&var);
|
||||
do_break = true;
|
||||
break;
|
||||
|
||||
case PARSE_EOF:
|
||||
ep_param_free(&var);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (do_break)
|
||||
break;
|
||||
|
||||
darray_push_back(sizeof(struct ep_param), annotations, &var);
|
||||
}
|
||||
|
||||
if (!cf_token_is(&ep->cfp, ">")) {
|
||||
cf_adderror_expecting(&ep->cfp, ">");
|
||||
goto error;
|
||||
}
|
||||
if (!cf_next_valid_token(&ep->cfp))
|
||||
goto error;
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
return false;
|
||||
}
|
||||
|
||||
static int ep_parse_param_annotations(struct effect_parser *ep,
|
||||
struct ep_param *param)
|
||||
{
|
||||
return ep_parse_annotations(ep, ¶m->annotations.da);
|
||||
}
|
||||
|
||||
static inline int ep_parse_pass_command_call(struct effect_parser *ep,
|
||||
struct darray *call)
|
||||
{
|
||||
|
|
@ -328,7 +512,7 @@ static int ep_parse_pass(struct effect_parser *ep, struct ep_pass *pass)
|
|||
|
||||
if (!cf_token_is(&ep->cfp, "{")) {
|
||||
pass->name = bstrdup_n(ep->cfp.cur_token->str.array,
|
||||
ep->cfp.cur_token->str.len);
|
||||
ep->cfp.cur_token->str.len);
|
||||
if (!cf_next_valid_token(&ep->cfp)) return PARSE_EOF;
|
||||
}
|
||||
|
||||
|
|
@ -356,9 +540,19 @@ static void ep_parse_technique(struct effect_parser *ep)
|
|||
|
||||
if (cf_next_name(&ep->cfp, &ept.name, "name", ";") != PARSE_SUCCESS)
|
||||
goto error;
|
||||
if (cf_next_token_should_be(&ep->cfp, "{", ";", NULL) != PARSE_SUCCESS)
|
||||
goto error;
|
||||
|
||||
if (!cf_next_valid_token(&ep->cfp))
|
||||
return;
|
||||
|
||||
if (!cf_token_is(&ep->cfp, "{")) {
|
||||
if (!cf_go_to_token(&ep->cfp, ";", NULL)) {
|
||||
cf_adderror_expecting(&ep->cfp, ";");
|
||||
return;
|
||||
}
|
||||
|
||||
cf_adderror_expecting(&ep->cfp, "{");
|
||||
goto error;
|
||||
}
|
||||
if (!cf_next_valid_token(&ep->cfp))
|
||||
goto error;
|
||||
|
||||
|
|
@ -756,6 +950,30 @@ static inline int ep_parse_param_assign_texture(struct effect_parser *ep,
|
|||
return PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
static inline int ep_parse_param_assign_string(struct effect_parser *ep,
|
||||
struct ep_param *param)
|
||||
{
|
||||
int code;
|
||||
char *str = NULL;
|
||||
|
||||
if (!cf_next_valid_token(&ep->cfp))
|
||||
return PARSE_EOF;
|
||||
|
||||
code = cf_token_is_type(&ep->cfp, CFTOKEN_STRING, "string", ";");
|
||||
if (code != PARSE_SUCCESS)
|
||||
return code;
|
||||
|
||||
str = cf_literal_to_str(ep->cfp.cur_token->str.array,
|
||||
ep->cfp.cur_token->str.len);
|
||||
|
||||
if (str) {
|
||||
da_copy_array(param->default_val, str, strlen(str) + 1);
|
||||
bfree(str);
|
||||
}
|
||||
|
||||
return PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
static inline int ep_parse_param_assign_intfloat(struct effect_parser *ep,
|
||||
struct ep_param *param, bool is_float)
|
||||
{
|
||||
|
|
@ -789,30 +1007,51 @@ static inline int ep_parse_param_assign_intfloat(struct effect_parser *ep,
|
|||
return PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* parses assignment for float1, float2, float3, float4, and any combination
|
||||
* for float3x3, float4x4, etc
|
||||
*/
|
||||
static inline int ep_parse_param_assign_float_array(struct effect_parser *ep,
|
||||
static inline int ep_parse_param_assign_bool(struct effect_parser *ep,
|
||||
struct ep_param *param)
|
||||
{
|
||||
const char *float_type = param->type+5;
|
||||
int float_count = 0, code, i;
|
||||
if (!cf_next_valid_token(&ep->cfp))
|
||||
return PARSE_EOF;
|
||||
|
||||
if (cf_token_is(&ep->cfp, "true")) {
|
||||
long l = 1;
|
||||
da_push_back_array(param->default_val, &l, sizeof(long));
|
||||
return PARSE_SUCCESS;
|
||||
} else if (cf_token_is(&ep->cfp, "false")) {
|
||||
long l = 0;
|
||||
da_push_back_array(param->default_val, &l, sizeof(long));
|
||||
return PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
cf_adderror_expecting(&ep->cfp, "true or false");
|
||||
|
||||
return PARSE_EOF;
|
||||
}
|
||||
|
||||
/*
|
||||
* parses assignment for float1, float2, float3, float4, int1, int2, int3, int4,
|
||||
* and any combination for float3x3, float4x4, int3x3, int4x4, etc
|
||||
*/
|
||||
static inline int ep_parse_param_assign_intfloat_array(struct effect_parser *ep,
|
||||
struct ep_param *param, bool is_float)
|
||||
{
|
||||
const char *intfloat_type = param->type + (is_float ? 5 : 3);
|
||||
int intfloat_count = 0, code, i;
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
if (float_type[0] < '1' || float_type[0] > '4')
|
||||
if (intfloat_type[0] < '1' || intfloat_type[0] > '4')
|
||||
cf_adderror(&ep->cfp, "Invalid row count", LEX_ERROR,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
float_count = float_type[0]-'0';
|
||||
intfloat_count = intfloat_type[0]-'0';
|
||||
|
||||
if (float_type[1] == 'x') {
|
||||
if (float_type[2] < '1' || float_type[2] > '4')
|
||||
if (intfloat_type[1] == 'x') {
|
||||
if (intfloat_type[2] < '1' || intfloat_type[2] > '4')
|
||||
cf_adderror(&ep->cfp, "Invalid column count",
|
||||
LEX_ERROR, NULL, NULL, NULL);
|
||||
|
||||
float_count *= float_type[2]-'0';
|
||||
intfloat_count *= intfloat_type[2]-'0';
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
|
@ -820,10 +1059,10 @@ static inline int ep_parse_param_assign_float_array(struct effect_parser *ep,
|
|||
code = cf_next_token_should_be(&ep->cfp, "{", ";", NULL);
|
||||
if (code != PARSE_SUCCESS) return code;
|
||||
|
||||
for (i = 0; i < float_count; i++) {
|
||||
char *next = ((i+1) < float_count) ? "," : "}";
|
||||
for (i = 0; i < intfloat_count; i++) {
|
||||
char *next = ((i+1) < intfloat_count) ? "," : "}";
|
||||
|
||||
code = ep_parse_param_assign_intfloat(ep, param, true);
|
||||
code = ep_parse_param_assign_intfloat(ep, param, is_float);
|
||||
if (code != PARSE_SUCCESS) return code;
|
||||
|
||||
code = cf_next_token_should_be(&ep->cfp, next, ";", NULL);
|
||||
|
|
@ -842,8 +1081,14 @@ static int ep_parse_param_assignment_val(struct effect_parser *ep,
|
|||
return ep_parse_param_assign_intfloat(ep, param, false);
|
||||
else if (strcmp(param->type, "float") == 0)
|
||||
return ep_parse_param_assign_intfloat(ep, param, true);
|
||||
else if (astrcmp_n(param->type, "int", 3) == 0)
|
||||
return ep_parse_param_assign_intfloat_array(ep, param, false);
|
||||
else if (astrcmp_n(param->type, "float", 5) == 0)
|
||||
return ep_parse_param_assign_float_array(ep, param);
|
||||
return ep_parse_param_assign_intfloat_array(ep, param, true);
|
||||
else if (astrcmp_n(param->type, "string", 6) == 0)
|
||||
return ep_parse_param_assign_string(ep, param);
|
||||
else if (strcmp(param->type, "bool") == 0)
|
||||
return ep_parse_param_assign_bool(ep, param);
|
||||
|
||||
cf_adderror(&ep->cfp, "Invalid type '$1' used for assignment",
|
||||
LEX_ERROR, param->type, NULL, NULL);
|
||||
|
|
@ -879,6 +1124,9 @@ static void ep_parse_param(struct effect_parser *ep,
|
|||
goto complete;
|
||||
if (cf_token_is(&ep->cfp, "[") && !ep_parse_param_array(ep, ¶m))
|
||||
goto error;
|
||||
if (cf_token_is(&ep->cfp, "<") && !ep_parse_param_annotations(ep,
|
||||
¶m))
|
||||
goto error;
|
||||
if (cf_token_is(&ep->cfp, "=") && !ep_parse_param_assign(ep, ¶m))
|
||||
goto error;
|
||||
/*
|
||||
|
|
@ -945,7 +1193,6 @@ static void ep_parse_other(struct effect_parser *ep)
|
|||
goto error;
|
||||
if (cf_next_name(&ep->cfp, &name, "name", ";") != PARSE_SUCCESS)
|
||||
goto error;
|
||||
|
||||
if (!cf_next_valid_token(&ep->cfp))
|
||||
goto error;
|
||||
|
||||
|
|
@ -971,6 +1218,213 @@ static bool ep_compile(struct effect_parser *ep);
|
|||
|
||||
extern const char *gs_preprocessor_name(void);
|
||||
|
||||
#if defined(_DEBUG) && defined(_DEBUG_SHADERS)
|
||||
static void debug_get_default_value(struct gs_effect_param *param,
|
||||
char* buffer, unsigned long long buf_size)
|
||||
{
|
||||
if (param->default_val.num == 0) {
|
||||
snprintf(buffer, buf_size, "(null)");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (param->type) {
|
||||
case GS_SHADER_PARAM_STRING:
|
||||
snprintf(buffer, buf_size, "'%.*s'",
|
||||
param->default_val.num,
|
||||
param->default_val.array);
|
||||
break;
|
||||
case GS_SHADER_PARAM_INT:
|
||||
snprintf(buffer, buf_size, "%ld",
|
||||
*(int*)(param->default_val.array + 0));
|
||||
break;
|
||||
case GS_SHADER_PARAM_INT2:
|
||||
snprintf(buffer, buf_size, "%ld,%ld",
|
||||
*(int*)(param->default_val.array + 0),
|
||||
*(int*)(param->default_val.array + 4));
|
||||
break;
|
||||
case GS_SHADER_PARAM_INT3:
|
||||
snprintf(buffer, buf_size, "%ld,%ld,%ld",
|
||||
*(int*)(param->default_val.array + 0),
|
||||
*(int*)(param->default_val.array + 4),
|
||||
*(int*)(param->default_val.array + 8));
|
||||
break;
|
||||
case GS_SHADER_PARAM_INT4:
|
||||
snprintf(buffer, buf_size, "%ld,%ld,%ld,%ld",
|
||||
*(int*)(param->default_val.array + 0),
|
||||
*(int*)(param->default_val.array + 4),
|
||||
*(int*)(param->default_val.array + 8),
|
||||
*(int*)(param->default_val.array + 12));
|
||||
break;
|
||||
case GS_SHADER_PARAM_FLOAT:
|
||||
snprintf(buffer, buf_size, "%e",
|
||||
*(float*)(param->default_val.array + 0));
|
||||
break;
|
||||
case GS_SHADER_PARAM_VEC2:
|
||||
snprintf(buffer, buf_size, "%e,%e",
|
||||
*(float*)(param->default_val.array + 0),
|
||||
*(float*)(param->default_val.array + 4));
|
||||
break;
|
||||
case GS_SHADER_PARAM_VEC3:
|
||||
snprintf(buffer, buf_size, "%e,%e,%e",
|
||||
*(float*)(param->default_val.array + 0),
|
||||
*(float*)(param->default_val.array + 4),
|
||||
*(float*)(param->default_val.array + 8));
|
||||
break;
|
||||
case GS_SHADER_PARAM_VEC4:
|
||||
snprintf(buffer, buf_size, "%e,%e,%e,%e",
|
||||
*(float*)(param->default_val.array + 0),
|
||||
*(float*)(param->default_val.array + 4),
|
||||
*(float*)(param->default_val.array + 8),
|
||||
*(float*)(param->default_val.array + 12));
|
||||
break;
|
||||
case GS_SHADER_PARAM_MATRIX4X4:
|
||||
snprintf(buffer, buf_size,
|
||||
"[[%e,%e,%e,%e],[%e,%e,%e,%e],"
|
||||
"[%e,%e,%e,%e],[%e,%e,%e,%e]]",
|
||||
*(float*)(param->default_val.array + 0),
|
||||
*(float*)(param->default_val.array + 4),
|
||||
*(float*)(param->default_val.array + 8),
|
||||
*(float*)(param->default_val.array + 12),
|
||||
*(float*)(param->default_val.array + 16),
|
||||
*(float*)(param->default_val.array + 20),
|
||||
*(float*)(param->default_val.array + 24),
|
||||
*(float*)(param->default_val.array + 28),
|
||||
*(float*)(param->default_val.array + 32),
|
||||
*(float*)(param->default_val.array + 36),
|
||||
*(float*)(param->default_val.array + 40),
|
||||
*(float*)(param->default_val.array + 44),
|
||||
*(float*)(param->default_val.array + 48),
|
||||
*(float*)(param->default_val.array + 52),
|
||||
*(float*)(param->default_val.array + 56),
|
||||
*(float*)(param->default_val.array + 60));
|
||||
break;
|
||||
case GS_SHADER_PARAM_BOOL:
|
||||
snprintf(buffer, buf_size, "%s",
|
||||
(*param->default_val.array) != 0
|
||||
? "true\0"
|
||||
: "false\0");
|
||||
break;
|
||||
case GS_SHADER_PARAM_UNKNOWN:
|
||||
case GS_SHADER_PARAM_TEXTURE:
|
||||
snprintf(buffer, buf_size, "<unknown>");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void debug_param(struct gs_effect_param *param,
|
||||
struct ep_param *param_in, unsigned long long idx, const char* offset)
|
||||
{
|
||||
char _debug_type[4096];
|
||||
switch (param->type) {
|
||||
case GS_SHADER_PARAM_STRING:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "string");
|
||||
break;
|
||||
case GS_SHADER_PARAM_INT:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "int");
|
||||
break;
|
||||
case GS_SHADER_PARAM_INT2:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "int2");
|
||||
break;
|
||||
case GS_SHADER_PARAM_INT3:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "int3");
|
||||
break;
|
||||
case GS_SHADER_PARAM_INT4:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "int4");
|
||||
break;
|
||||
case GS_SHADER_PARAM_FLOAT:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "float");
|
||||
break;
|
||||
case GS_SHADER_PARAM_VEC2:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "float2");
|
||||
break;
|
||||
case GS_SHADER_PARAM_VEC3:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "float3");
|
||||
break;
|
||||
case GS_SHADER_PARAM_VEC4:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "float4");
|
||||
break;
|
||||
case GS_SHADER_PARAM_MATRIX4X4:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "float4x4");
|
||||
break;
|
||||
case GS_SHADER_PARAM_BOOL:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "bool");
|
||||
break;
|
||||
case GS_SHADER_PARAM_UNKNOWN:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "unknown");
|
||||
break;
|
||||
case GS_SHADER_PARAM_TEXTURE:
|
||||
snprintf(_debug_type, sizeof(_debug_type), "texture");
|
||||
break;
|
||||
}
|
||||
|
||||
char _debug_buf[4096];
|
||||
debug_get_default_value(param, _debug_buf, sizeof(_debug_buf));
|
||||
if (param->annotations.num > 0) {
|
||||
blog(LOG_DEBUG, "%s[%4lld] %.*s '%s' with value %.*s and %lld annotations:",
|
||||
offset,
|
||||
idx,
|
||||
sizeof(_debug_type), _debug_type,
|
||||
param->name,
|
||||
sizeof(_debug_buf), _debug_buf,
|
||||
param->annotations.num);
|
||||
} else {
|
||||
blog(LOG_DEBUG, "%s[%4lld] %.*s '%s' with value %.*s.",
|
||||
offset,
|
||||
idx,
|
||||
sizeof(_debug_type), _debug_type,
|
||||
param->name,
|
||||
sizeof(_debug_buf), _debug_buf);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void debug_param_annotation(struct gs_effect_param *param,
|
||||
struct ep_param *param_in, unsigned long long idx, const char* offset)
|
||||
{
|
||||
char _debug_buf[4096];
|
||||
debug_get_default_value(param, _debug_buf, sizeof(_debug_buf));
|
||||
blog(LOG_DEBUG, "%s[%4lld] %s '%s' with value %.*s",
|
||||
offset,
|
||||
idx,
|
||||
param_in->type,
|
||||
param->name,
|
||||
sizeof(_debug_buf), _debug_buf);
|
||||
}
|
||||
|
||||
static void debug_print_string(const char* offset, const char* str)
|
||||
{
|
||||
// Bypass 4096 limit in def_log_handler.
|
||||
char const *begin = str;
|
||||
unsigned long long line = 1;
|
||||
for (char const *here = begin; here[0] != '\0'; here++) {
|
||||
char const * str = begin;
|
||||
unsigned long long len = here - begin;
|
||||
bool is_line = false;
|
||||
|
||||
if (here[0] == '\r') {
|
||||
is_line = true;
|
||||
if (here[1] == '\n') {
|
||||
here += 1;
|
||||
}
|
||||
begin = here + 1;
|
||||
} else if (here[0] == '\n') {
|
||||
is_line = true;
|
||||
begin = here + 1;
|
||||
}
|
||||
|
||||
if (is_line) {
|
||||
blog(LOG_DEBUG, "\t\t\t\t[%4lld] %.*s", line,
|
||||
len, str);
|
||||
line++;
|
||||
}
|
||||
}
|
||||
if (begin[0] != '\0') {
|
||||
// Final line was not written.
|
||||
blog(LOG_DEBUG, "\t\t\t\t[%4lld] %*s", line, strlen(begin), begin);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool ep_parse(struct effect_parser *ep, gs_effect_t *effect,
|
||||
const char *effect_string, const char *file)
|
||||
{
|
||||
|
|
@ -1020,10 +1474,21 @@ bool ep_parse(struct effect_parser *ep, gs_effect_t *effect,
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(_DEBUG) && defined(_DEBUG_SHADERS)
|
||||
blog(LOG_DEBUG, "================================================================================");
|
||||
blog(LOG_DEBUG, "Effect Parser reformatted shader '%s' to:", file);
|
||||
debug_print_string("\t", ep->cfp.lex.reformatted);
|
||||
#endif
|
||||
|
||||
success = !error_data_has_errors(&ep->cfp.error_list);
|
||||
if (success)
|
||||
success = ep_compile(ep);
|
||||
|
||||
|
||||
#if defined(_DEBUG) && defined(_DEBUG_SHADERS)
|
||||
blog(LOG_DEBUG, "================================================================================");
|
||||
#endif
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
|
@ -1309,6 +1774,9 @@ static void ep_makeshaderstring(struct effect_parser *ep,
|
|||
|
||||
dstr_init(&call_str);
|
||||
|
||||
if (!token)
|
||||
return;
|
||||
|
||||
while (token->type != CFTOKEN_NONE && is_whitespace(*token->str.array))
|
||||
token++;
|
||||
|
||||
|
|
@ -1339,6 +1807,39 @@ static void ep_makeshaderstring(struct effect_parser *ep,
|
|||
ep_reset_written(ep);
|
||||
}
|
||||
|
||||
static void ep_compile_annotations(struct darray *ep_annotations,
|
||||
struct darray *gsp_annotations, struct effect_parser *ep)
|
||||
{
|
||||
darray_resize(sizeof(struct gs_effect_param),
|
||||
gsp_annotations, ep_annotations->num);
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < ep_annotations->num; i++) {
|
||||
struct gs_effect_param *param = ((struct gs_effect_param *)
|
||||
gsp_annotations->array)+i;
|
||||
struct ep_param *param_in = ((struct ep_param *)
|
||||
ep_annotations->array)+i;
|
||||
|
||||
param->name = bstrdup(param_in->name);
|
||||
param->section = EFFECT_ANNOTATION;
|
||||
param->effect = ep->effect;
|
||||
da_move(param->default_val, param_in->default_val);
|
||||
|
||||
param->type = get_effect_param_type(param_in->type);
|
||||
|
||||
#if defined(_DEBUG) && defined(_DEBUG_SHADERS)
|
||||
debug_param(param, param_in, i, "\t\t");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void ep_compile_param_annotations(struct ep_param *ep_param_input,
|
||||
struct gs_effect_param *gs_effect_input, struct effect_parser *ep)
|
||||
{
|
||||
ep_compile_annotations(&(ep_param_input->annotations.da),
|
||||
&(gs_effect_input->annotations.da), ep);
|
||||
}
|
||||
|
||||
static void ep_compile_param(struct effect_parser *ep, size_t idx)
|
||||
{
|
||||
struct gs_effect_param *param;
|
||||
|
|
@ -1353,27 +1854,18 @@ static void ep_compile_param(struct effect_parser *ep, size_t idx)
|
|||
param->effect = ep->effect;
|
||||
da_move(param->default_val, param_in->default_val);
|
||||
|
||||
if (strcmp(param_in->type, "bool") == 0)
|
||||
param->type = GS_SHADER_PARAM_BOOL;
|
||||
else if (strcmp(param_in->type, "float") == 0)
|
||||
param->type = GS_SHADER_PARAM_FLOAT;
|
||||
else if (strcmp(param_in->type, "int") == 0)
|
||||
param->type = GS_SHADER_PARAM_INT;
|
||||
else if (strcmp(param_in->type, "float2") == 0)
|
||||
param->type = GS_SHADER_PARAM_VEC2;
|
||||
else if (strcmp(param_in->type, "float3") == 0)
|
||||
param->type = GS_SHADER_PARAM_VEC3;
|
||||
else if (strcmp(param_in->type, "float4") == 0)
|
||||
param->type = GS_SHADER_PARAM_VEC4;
|
||||
else if (strcmp(param_in->type, "float4x4") == 0)
|
||||
param->type = GS_SHADER_PARAM_MATRIX4X4;
|
||||
else if (param_in->is_texture)
|
||||
param->type = GS_SHADER_PARAM_TEXTURE;
|
||||
param->type = get_effect_param_type(param_in->type);
|
||||
|
||||
if (strcmp(param_in->name, "ViewProj") == 0)
|
||||
ep->effect->view_proj = param;
|
||||
else if (strcmp(param_in->name, "World") == 0)
|
||||
ep->effect->world = param;
|
||||
|
||||
#if defined(_DEBUG) && defined(_DEBUG_SHADERS)
|
||||
debug_param(param, param_in, idx, "\t");
|
||||
#endif
|
||||
|
||||
ep_compile_param_annotations(param_in, param, ep);
|
||||
}
|
||||
|
||||
static bool ep_compile_pass_shaderparams(struct effect_parser *ep,
|
||||
|
|
@ -1397,6 +1889,10 @@ static bool ep_compile_pass_shaderparams(struct effect_parser *ep,
|
|||
param->sparam = gs_shader_get_param_by_name(shader,
|
||||
param_name->array);
|
||||
|
||||
#if defined(_DEBUG) && defined(_DEBUG_SHADERS)
|
||||
debug_param(param->eparam, 0, i, "\t\t\t\t");
|
||||
#endif
|
||||
|
||||
if (!param->sparam) {
|
||||
blog(LOG_ERROR, "Effect shader parameter not found");
|
||||
return false;
|
||||
|
|
@ -1441,6 +1937,7 @@ static inline bool ep_compile_pass_shader(struct effect_parser *ep,
|
|||
pass->vertshader = gs_vertexshader_create(shader_str.array,
|
||||
location.array, NULL);
|
||||
|
||||
|
||||
shader = pass->vertshader;
|
||||
pass_params = &pass->vertshader_params.da;
|
||||
} else if (type == GS_SHADER_PIXEL) {
|
||||
|
|
@ -1454,12 +1951,12 @@ static inline bool ep_compile_pass_shader(struct effect_parser *ep,
|
|||
pass_params = &pass->pixelshader_params.da;
|
||||
}
|
||||
|
||||
#if 0
|
||||
blog(LOG_DEBUG, "+++++++++++++++++++++++++++++++++++");
|
||||
blog(LOG_DEBUG, " %s", location.array);
|
||||
blog(LOG_DEBUG, "-----------------------------------");
|
||||
blog(LOG_DEBUG, "%s", shader_str.array);
|
||||
blog(LOG_DEBUG, "+++++++++++++++++++++++++++++++++++");
|
||||
#if defined(_DEBUG) && defined(_DEBUG_SHADERS)
|
||||
blog(LOG_DEBUG, "\t\t\t%s Shader:",
|
||||
type == GS_SHADER_VERTEX ? "Vertex" : "Fragment");
|
||||
blog(LOG_DEBUG, "\t\t\tCode:");
|
||||
debug_print_string("\t\t\t\t\t", shader_str.array);
|
||||
blog(LOG_DEBUG, "\t\t\tParameters:");
|
||||
#endif
|
||||
|
||||
if (shader)
|
||||
|
|
@ -1491,14 +1988,23 @@ static bool ep_compile_pass(struct effect_parser *ep,
|
|||
pass->name = bstrdup(pass_in->name);
|
||||
pass->section = EFFECT_PASS;
|
||||
|
||||
if (!ep_compile_pass_shader(ep, tech, pass, pass_in, idx,
|
||||
GS_SHADER_VERTEX))
|
||||
success = false;
|
||||
#if defined(_DEBUG) && defined(_DEBUG_SHADERS)
|
||||
blog(LOG_DEBUG, "\t\t[%4lld] Pass '%s':",
|
||||
idx, pass->name);
|
||||
#endif
|
||||
|
||||
if (!ep_compile_pass_shader(ep, tech, pass, pass_in, idx,
|
||||
GS_SHADER_PIXEL))
|
||||
GS_SHADER_VERTEX)) {
|
||||
success = false;
|
||||
|
||||
blog(LOG_ERROR, "Pass (%zu) <%s> missing vertex shader!",
|
||||
idx, pass->name ? pass->name : "");
|
||||
}
|
||||
if (!ep_compile_pass_shader(ep, tech, pass, pass_in, idx,
|
||||
GS_SHADER_PIXEL)) {
|
||||
success = false;
|
||||
blog(LOG_ERROR, "Pass (%zu) <%s> missing pixel shader!",
|
||||
idx, pass->name ? pass->name : "");
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
|
@ -1518,6 +2024,11 @@ static inline bool ep_compile_technique(struct effect_parser *ep, size_t idx)
|
|||
|
||||
da_resize(tech->passes, tech_in->passes.num);
|
||||
|
||||
#if defined(_DEBUG) && defined(_DEBUG_SHADERS)
|
||||
blog(LOG_DEBUG, "\t[%4lld] Technique '%s' has %lld passes:",
|
||||
idx, tech->name, tech->passes.num);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < tech->passes.num; i++) {
|
||||
if (!ep_compile_pass(ep, tech, tech_in, i))
|
||||
success = false;
|
||||
|
|
@ -1536,8 +2047,17 @@ static bool ep_compile(struct effect_parser *ep)
|
|||
da_resize(ep->effect->params, ep->params.num);
|
||||
da_resize(ep->effect->techniques, ep->techniques.num);
|
||||
|
||||
#if defined(_DEBUG) && defined(_DEBUG_SHADERS)
|
||||
blog(LOG_DEBUG, "Shader has %lld parameters:", ep->params.num);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < ep->params.num; i++)
|
||||
ep_compile_param(ep, i);
|
||||
|
||||
#if defined(_DEBUG) && defined(_DEBUG_SHADERS)
|
||||
blog(LOG_DEBUG, "Shader has %lld techniques:", ep->techniques.num);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < ep->techniques.num; i++) {
|
||||
if (!ep_compile_technique(ep, i))
|
||||
success = false;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include "../util/darray.h"
|
||||
#include "../util/cf-parser.h"
|
||||
#include "graphics.h"
|
||||
#include "shader-parser.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -72,6 +73,7 @@ struct ep_param {
|
|||
struct gs_effect_param *param;
|
||||
bool is_const, is_property, is_uniform, is_texture, written;
|
||||
int writeorder, array_count;
|
||||
DARRAY(struct ep_param) annotations;
|
||||
};
|
||||
|
||||
extern void ep_param_writevar(struct dstr *dst, struct darray *use_params);
|
||||
|
|
@ -91,6 +93,7 @@ static inline void ep_param_init(struct ep_param *epp,
|
|||
epp->array_count = 0;
|
||||
da_init(epp->default_val);
|
||||
da_init(epp->properties);
|
||||
da_init(epp->annotations);
|
||||
}
|
||||
|
||||
static inline void ep_param_free(struct ep_param *epp)
|
||||
|
|
@ -99,6 +102,10 @@ static inline void ep_param_free(struct ep_param *epp)
|
|||
bfree(epp->name);
|
||||
da_free(epp->default_val);
|
||||
da_free(epp->properties);
|
||||
|
||||
for (size_t i = 0; i < epp->annotations.num; i++)
|
||||
ep_param_free(epp->annotations.array + i);
|
||||
da_free(epp->annotations);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
|
|
|||
|
|
@ -286,6 +286,63 @@ gs_eparam_t *gs_effect_get_param_by_name(const gs_effect_t *effect,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
size_t gs_param_get_num_annotations(const gs_eparam_t *param)
|
||||
{
|
||||
return param ? param->annotations.num : 0;
|
||||
}
|
||||
|
||||
gs_eparam_t *gs_param_get_annotation_by_idx(const gs_eparam_t *param,
|
||||
size_t annotation)
|
||||
{
|
||||
if (!param) return NULL;
|
||||
|
||||
struct gs_effect_param *params = param->annotations.array;
|
||||
if (annotation > param->annotations.num)
|
||||
return NULL;
|
||||
|
||||
return params + annotation;
|
||||
}
|
||||
|
||||
gs_eparam_t *gs_param_get_annotation_by_name(const gs_eparam_t *param,
|
||||
const char *name)
|
||||
{
|
||||
if (!param) return NULL;
|
||||
struct gs_effect_param *params = param->annotations.array;
|
||||
|
||||
for (size_t i = 0; i < param->annotations.num; i++) {
|
||||
struct gs_effect_param *g_param = params + i;
|
||||
if (strcmp(g_param->name, name) == 0)
|
||||
return g_param;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gs_epass_t *gs_technique_get_pass_by_idx(const gs_technique_t *technique,
|
||||
size_t pass)
|
||||
{
|
||||
if (!technique) return NULL;
|
||||
struct gs_effect_pass *passes = technique->passes.array;
|
||||
|
||||
if (pass > technique->passes.num)
|
||||
return NULL;
|
||||
|
||||
return passes + pass;
|
||||
}
|
||||
|
||||
gs_epass_t *gs_technique_get_pass_by_name(const gs_technique_t *technique,
|
||||
const char *name)
|
||||
{
|
||||
if (!technique) return NULL;
|
||||
struct gs_effect_pass *passes = technique->passes.array;
|
||||
|
||||
for (size_t i = 0; i < technique->passes.num; i++) {
|
||||
struct gs_effect_pass *g_pass = passes + i;
|
||||
if (strcmp(g_pass->name, name) == 0)
|
||||
return g_pass;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gs_eparam_t *gs_effect_get_viewproj_matrix(const gs_effect_t *effect)
|
||||
{
|
||||
return effect ? effect->view_proj : NULL;
|
||||
|
|
@ -332,6 +389,45 @@ static inline void effect_setval_inline(gs_eparam_t *param,
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
static inline void effect_getval_inline(gs_eparam_t *param, void *data,
|
||||
size_t size)
|
||||
{
|
||||
if (!param) {
|
||||
blog(LOG_ERROR, "effect_getval_inline: invalid param");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
blog(LOG_ERROR, "effect_getval_inline: invalid data");
|
||||
return;
|
||||
}
|
||||
|
||||
size_t bytes = min(size, param->cur_val.num);
|
||||
|
||||
memcpy(data, param->cur_val.array, bytes);
|
||||
}
|
||||
|
||||
static inline void effect_getdefaultval_inline(gs_eparam_t *param, void *data,
|
||||
size_t size)
|
||||
{
|
||||
if (!param) {
|
||||
blog(LOG_ERROR, "effect_getdefaultval_inline: invalid param");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
blog(LOG_ERROR, "effect_getdefaultval_inline: invalid data");
|
||||
return;
|
||||
}
|
||||
|
||||
size_t bytes = min(size, param->default_val.num);
|
||||
|
||||
memcpy(data, param->default_val.array, bytes);
|
||||
}
|
||||
|
||||
void gs_effect_set_bool(gs_eparam_t *param, bool val)
|
||||
{
|
||||
int b_val = (int)val;
|
||||
|
|
@ -385,6 +481,54 @@ void gs_effect_set_val(gs_eparam_t *param, const void *val, size_t size)
|
|||
effect_setval_inline(param, val, size);
|
||||
}
|
||||
|
||||
void *gs_effect_get_val(gs_eparam_t *param)
|
||||
{
|
||||
if (!param) {
|
||||
blog(LOG_ERROR, "gs_effect_get_val: invalid param");
|
||||
return NULL;
|
||||
}
|
||||
size_t size = param->cur_val.num;
|
||||
void *data;
|
||||
|
||||
if (size)
|
||||
data = (void*)bzalloc(size);
|
||||
else
|
||||
return NULL;
|
||||
|
||||
effect_getval_inline(param, data, size);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
size_t gs_effect_get_val_size(gs_eparam_t *param)
|
||||
{
|
||||
return param ? param->cur_val.num : 0;
|
||||
}
|
||||
|
||||
void *gs_effect_get_default_val(gs_eparam_t *param)
|
||||
{
|
||||
if (!param) {
|
||||
blog(LOG_ERROR, "gs_effect_get_default_val: invalid param");
|
||||
return NULL;
|
||||
}
|
||||
size_t size = param->default_val.num;
|
||||
void *data;
|
||||
|
||||
if (size)
|
||||
data = (void*)bzalloc(size);
|
||||
else
|
||||
return NULL;
|
||||
|
||||
effect_getdefaultval_inline(param, data, size);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
size_t gs_effect_get_default_val_size(gs_eparam_t *param)
|
||||
{
|
||||
return param ? param->default_val.num : 0;
|
||||
}
|
||||
|
||||
void gs_effect_set_default(gs_eparam_t *param)
|
||||
{
|
||||
effect_setval_inline(param, param->default_val.array,
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ enum effect_section {
|
|||
EFFECT_PARAM,
|
||||
EFFECT_TECHNIQUE,
|
||||
EFFECT_SAMPLER,
|
||||
EFFECT_PASS
|
||||
EFFECT_PASS,
|
||||
EFFECT_ANNOTATION
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
|
@ -61,11 +62,13 @@ struct gs_effect_param {
|
|||
|
||||
/*char *full_name;
|
||||
float scroller_min, scroller_max, scroller_inc, scroller_mul;*/
|
||||
DARRAY(struct gs_effect_param) annotations;
|
||||
};
|
||||
|
||||
static inline void effect_param_init(struct gs_effect_param *param)
|
||||
{
|
||||
memset(param, 0, sizeof(struct gs_effect_param));
|
||||
da_init(param->annotations);
|
||||
}
|
||||
|
||||
static inline void effect_param_free(struct gs_effect_param *param)
|
||||
|
|
@ -74,6 +77,12 @@ static inline void effect_param_free(struct gs_effect_param *param)
|
|||
//bfree(param->full_name);
|
||||
da_free(param->cur_val);
|
||||
da_free(param->default_val);
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < param->annotations.num; i++)
|
||||
effect_param_free(param->annotations.array + i);
|
||||
|
||||
da_free(param->annotations);
|
||||
}
|
||||
|
||||
EXPORT void effect_param_parse_property(gs_eparam_t *param,
|
||||
|
|
@ -106,6 +115,7 @@ static inline void effect_pass_free(struct gs_effect_pass *pass)
|
|||
bfree(pass->name);
|
||||
da_free(pass->vertshader_params);
|
||||
da_free(pass->pixelshader_params);
|
||||
|
||||
gs_shader_destroy(pass->vertshader);
|
||||
gs_shader_destroy(pass->pixelshader);
|
||||
}
|
||||
|
|
@ -130,6 +140,7 @@ static inline void effect_technique_free(struct gs_effect_technique *t)
|
|||
size_t i;
|
||||
for (i = 0; i < t->passes.num; i++)
|
||||
effect_pass_free(t->passes.array+i);
|
||||
|
||||
da_free(t->passes);
|
||||
bfree(t->name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,6 +171,11 @@ bool load_graphics_imports(struct gs_exports *exports, void *module,
|
|||
GRAPHICS_IMPORT(gs_shader_set_default);
|
||||
GRAPHICS_IMPORT(gs_shader_set_next_sampler);
|
||||
|
||||
GRAPHICS_IMPORT_OPTIONAL(device_nv12_available);
|
||||
|
||||
GRAPHICS_IMPORT(device_debug_marker_begin);
|
||||
GRAPHICS_IMPORT(device_debug_marker_end);
|
||||
|
||||
/* OSX/Cocoa specific functions */
|
||||
#ifdef __APPLE__
|
||||
GRAPHICS_IMPORT_OPTIONAL(device_texture_create_from_iosurface);
|
||||
|
|
@ -189,6 +194,11 @@ bool load_graphics_imports(struct gs_exports *exports, void *module,
|
|||
GRAPHICS_IMPORT_OPTIONAL(gs_texture_get_dc);
|
||||
GRAPHICS_IMPORT_OPTIONAL(gs_texture_release_dc);
|
||||
GRAPHICS_IMPORT_OPTIONAL(device_texture_open_shared);
|
||||
GRAPHICS_IMPORT_OPTIONAL(device_texture_get_shared_handle);
|
||||
GRAPHICS_IMPORT_OPTIONAL(device_texture_acquire_sync);
|
||||
GRAPHICS_IMPORT_OPTIONAL(device_texture_release_sync);
|
||||
GRAPHICS_IMPORT_OPTIONAL(device_texture_create_nv12);
|
||||
GRAPHICS_IMPORT_OPTIONAL(device_stagesurface_create_nv12);
|
||||
#endif
|
||||
|
||||
return success;
|
||||
|
|
|
|||
|
|
@ -232,6 +232,12 @@ struct gs_exports {
|
|||
void (*gs_shader_set_next_sampler)(gs_sparam_t *param,
|
||||
gs_samplerstate_t *sampler);
|
||||
|
||||
bool (*device_nv12_available)(gs_device_t *device);
|
||||
|
||||
void (*device_debug_marker_begin)(gs_device_t *device,
|
||||
const char *markername, const float color[4]);
|
||||
void (*device_debug_marker_end)(gs_device_t *device);
|
||||
|
||||
#ifdef __APPLE__
|
||||
/* OSX/Cocoa specific functions */
|
||||
gs_texture_t *(*device_texture_create_from_iosurface)(gs_device_t *dev,
|
||||
|
|
@ -261,6 +267,16 @@ struct gs_exports {
|
|||
|
||||
gs_texture_t *(*device_texture_open_shared)(gs_device_t *device,
|
||||
uint32_t handle);
|
||||
uint32_t (*device_texture_get_shared_handle)(gs_texture_t *tex);
|
||||
int (*device_texture_acquire_sync)(gs_texture_t *tex, uint64_t key,
|
||||
uint32_t ms);
|
||||
int (*device_texture_release_sync)(gs_texture_t *tex, uint64_t key);
|
||||
bool (*device_texture_create_nv12)(gs_device_t *device,
|
||||
gs_texture_t **tex_y, gs_texture_t **tex_uv,
|
||||
uint32_t width, uint32_t height, uint32_t flags);
|
||||
|
||||
gs_stagesurf_t *(*device_stagesurface_create_nv12)(gs_device_t *device,
|
||||
uint32_t width, uint32_t height);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -160,12 +160,12 @@ static bool graphics_init(struct graphics_subsystem *graphics)
|
|||
|
||||
graphics->exports.device_blend_function_separate(graphics->device,
|
||||
GS_BLEND_SRCALPHA, GS_BLEND_INVSRCALPHA,
|
||||
GS_BLEND_ONE, GS_BLEND_ONE);
|
||||
GS_BLEND_ONE, GS_BLEND_INVSRCALPHA);
|
||||
graphics->cur_blend_state.enabled = true;
|
||||
graphics->cur_blend_state.src_c = GS_BLEND_SRCALPHA;
|
||||
graphics->cur_blend_state.dest_c = GS_BLEND_INVSRCALPHA;
|
||||
graphics->cur_blend_state.src_a = GS_BLEND_ONE;
|
||||
graphics->cur_blend_state.dest_a = GS_BLEND_ONE;
|
||||
graphics->cur_blend_state.dest_a = GS_BLEND_INVSRCALPHA;
|
||||
|
||||
graphics->exports.device_leave_context(graphics->device);
|
||||
|
||||
|
|
@ -1240,10 +1240,10 @@ void gs_reset_blend_state(void)
|
|||
if (graphics->cur_blend_state.src_c != GS_BLEND_SRCALPHA ||
|
||||
graphics->cur_blend_state.dest_c != GS_BLEND_INVSRCALPHA ||
|
||||
graphics->cur_blend_state.src_a != GS_BLEND_ONE ||
|
||||
graphics->cur_blend_state.dest_a != GS_BLEND_ONE)
|
||||
graphics->cur_blend_state.dest_a != GS_BLEND_INVSRCALPHA)
|
||||
gs_blend_function_separate(
|
||||
GS_BLEND_SRCALPHA, GS_BLEND_INVSRCALPHA,
|
||||
GS_BLEND_ONE, GS_BLEND_ONE);
|
||||
GS_BLEND_ONE, GS_BLEND_INVSRCALPHA);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
|
@ -1517,9 +1517,7 @@ gs_indexbuffer_t *gs_indexbuffer_create(enum gs_index_type type,
|
|||
return NULL;
|
||||
|
||||
if (indices && num && (flags & GS_DUP_BUFFER) != 0) {
|
||||
size_t size = type == GS_UNSIGNED_SHORT
|
||||
? sizeof(unsigned short)
|
||||
: sizeof(unsigned long);
|
||||
size_t size = type == GS_UNSIGNED_SHORT ? 2 : 4;
|
||||
indices = bmemdup(indices, size * num);
|
||||
}
|
||||
|
||||
|
|
@ -2545,6 +2543,61 @@ enum gs_index_type gs_indexbuffer_get_type(const gs_indexbuffer_t *indexbuffer)
|
|||
return thread_graphics->exports.gs_indexbuffer_get_type(indexbuffer);
|
||||
}
|
||||
|
||||
bool gs_nv12_available(void)
|
||||
{
|
||||
if (!gs_valid("gs_nv12_available"))
|
||||
return false;
|
||||
|
||||
if (!thread_graphics->exports.device_nv12_available)
|
||||
return false;
|
||||
|
||||
return thread_graphics->exports.device_nv12_available(
|
||||
thread_graphics->device);
|
||||
}
|
||||
|
||||
void gs_debug_marker_begin(const float color[4],
|
||||
const char *markername)
|
||||
{
|
||||
if (!gs_valid("gs_debug_marker_begin"))
|
||||
return;
|
||||
|
||||
if (!markername)
|
||||
markername = "(null)";
|
||||
|
||||
thread_graphics->exports.device_debug_marker_begin(
|
||||
thread_graphics->device, markername,
|
||||
color);
|
||||
}
|
||||
|
||||
void gs_debug_marker_begin_format(const float color[4],
|
||||
const char *format, ...)
|
||||
{
|
||||
if (!gs_valid("gs_debug_marker_begin"))
|
||||
return;
|
||||
|
||||
if (format) {
|
||||
char markername[64];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf(markername, sizeof(markername), format, args);
|
||||
va_end(args);
|
||||
thread_graphics->exports.device_debug_marker_begin(
|
||||
thread_graphics->device, markername,
|
||||
color);
|
||||
} else {
|
||||
gs_debug_marker_begin(color, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void gs_debug_marker_end(void)
|
||||
{
|
||||
if (!gs_valid("gs_debug_marker_end"))
|
||||
return;
|
||||
|
||||
thread_graphics->exports.device_debug_marker_end(
|
||||
thread_graphics->device);
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
/** Platform specific functions */
|
||||
|
|
@ -2692,4 +2745,98 @@ gs_texture_t *gs_texture_open_shared(uint32_t handle)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t gs_texture_get_shared_handle(gs_texture_t *tex)
|
||||
{
|
||||
graphics_t *graphics = thread_graphics;
|
||||
if (!gs_valid("gs_texture_get_shared_handle"))
|
||||
return GS_INVALID_HANDLE;
|
||||
|
||||
if (graphics->exports.device_texture_get_shared_handle)
|
||||
return graphics->exports.device_texture_get_shared_handle(tex);
|
||||
return GS_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
int gs_texture_acquire_sync(gs_texture_t *tex, uint64_t key, uint32_t ms)
|
||||
{
|
||||
graphics_t *graphics = thread_graphics;
|
||||
if (!gs_valid("gs_texture_acquire_sync"))
|
||||
return -1;
|
||||
|
||||
if (graphics->exports.device_texture_acquire_sync)
|
||||
return graphics->exports.device_texture_acquire_sync(tex,
|
||||
key, ms);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int gs_texture_release_sync(gs_texture_t *tex, uint64_t key)
|
||||
{
|
||||
graphics_t *graphics = thread_graphics;
|
||||
if (!gs_valid("gs_texture_release_sync"))
|
||||
return -1;
|
||||
|
||||
if (graphics->exports.device_texture_release_sync)
|
||||
return graphics->exports.device_texture_release_sync(tex, key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool gs_texture_create_nv12(gs_texture_t **tex_y, gs_texture_t **tex_uv,
|
||||
uint32_t width, uint32_t height, uint32_t flags)
|
||||
{
|
||||
graphics_t *graphics = thread_graphics;
|
||||
bool success = false;
|
||||
|
||||
if (!gs_valid("gs_texture_create_nv12"))
|
||||
return false;
|
||||
|
||||
if ((width & 1) == 1 || (height & 1) == 1) {
|
||||
blog(LOG_ERROR, "NV12 textures must have dimensions "
|
||||
"divisible by 2.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (graphics->exports.device_texture_create_nv12) {
|
||||
success = graphics->exports.device_texture_create_nv12(
|
||||
graphics->device, tex_y, tex_uv,
|
||||
width, height, flags);
|
||||
if (success)
|
||||
return true;
|
||||
}
|
||||
|
||||
*tex_y = gs_texture_create(width, height, GS_R8, 1, NULL, flags);
|
||||
*tex_uv = gs_texture_create(width / 2, height / 2, GS_R8G8, 1, NULL,
|
||||
flags);
|
||||
|
||||
if (!*tex_y || !*tex_uv) {
|
||||
if (*tex_y)
|
||||
gs_texture_destroy(*tex_y);
|
||||
if (*tex_uv)
|
||||
gs_texture_destroy(*tex_uv);
|
||||
*tex_y = NULL;
|
||||
*tex_uv = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
gs_stagesurf_t *gs_stagesurface_create_nv12(uint32_t width, uint32_t height)
|
||||
{
|
||||
graphics_t *graphics = thread_graphics;
|
||||
|
||||
if (!gs_valid("gs_stagesurface_create_nv12"))
|
||||
return NULL;
|
||||
|
||||
if ((width & 1) == 1 || (height & 1) == 1) {
|
||||
blog(LOG_ERROR, "NV12 textures must have dimensions "
|
||||
"divisible by 2.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (graphics->exports.device_stagesurface_create_nv12)
|
||||
return graphics->exports.device_stagesurface_create_nv12(
|
||||
graphics->device, width, height);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -71,7 +71,8 @@ enum gs_color_format {
|
|||
GS_R32F,
|
||||
GS_DXT1,
|
||||
GS_DXT3,
|
||||
GS_DXT5
|
||||
GS_DXT5,
|
||||
GS_R8G8,
|
||||
};
|
||||
|
||||
enum gs_zstencil_format {
|
||||
|
|
@ -267,6 +268,7 @@ typedef struct gs_shader gs_shader_t;
|
|||
typedef struct gs_shader_param gs_sparam_t;
|
||||
typedef struct gs_effect gs_effect_t;
|
||||
typedef struct gs_effect_technique gs_technique_t;
|
||||
typedef struct gs_effect_pass gs_epass_t;
|
||||
typedef struct gs_effect_param gs_eparam_t;
|
||||
typedef struct gs_device gs_device_t;
|
||||
typedef struct graphics_subsystem graphics_t;
|
||||
|
|
@ -368,12 +370,21 @@ EXPORT bool gs_technique_begin_pass(gs_technique_t *technique, size_t pass);
|
|||
EXPORT bool gs_technique_begin_pass_by_name(gs_technique_t *technique,
|
||||
const char *name);
|
||||
EXPORT void gs_technique_end_pass(gs_technique_t *technique);
|
||||
EXPORT gs_epass_t *gs_technique_get_pass_by_idx(const gs_technique_t *technique,
|
||||
size_t pass);
|
||||
EXPORT gs_epass_t *gs_technique_get_pass_by_name(
|
||||
const gs_technique_t *technique, const char *name);
|
||||
|
||||
EXPORT size_t gs_effect_get_num_params(const gs_effect_t *effect);
|
||||
EXPORT gs_eparam_t *gs_effect_get_param_by_idx(const gs_effect_t *effect,
|
||||
size_t param);
|
||||
EXPORT gs_eparam_t *gs_effect_get_param_by_name(const gs_effect_t *effect,
|
||||
const char *name);
|
||||
EXPORT size_t gs_param_get_num_annotations(const gs_eparam_t *param);
|
||||
EXPORT gs_eparam_t *gs_param_get_annotation_by_idx(const gs_eparam_t *param,
|
||||
size_t annotation);
|
||||
EXPORT gs_eparam_t *gs_param_get_annotation_by_name(const gs_eparam_t *param,
|
||||
const char *name);
|
||||
|
||||
/** Helper function to simplify effect usage. Use with a while loop that
|
||||
* contains drawing functions. Automatically handles techniques, passes, and
|
||||
|
|
@ -402,6 +413,10 @@ EXPORT void gs_effect_set_vec4(gs_eparam_t *param, const struct vec4 *val);
|
|||
EXPORT void gs_effect_set_texture(gs_eparam_t *param, gs_texture_t *val);
|
||||
EXPORT void gs_effect_set_val(gs_eparam_t *param, const void *val, size_t size);
|
||||
EXPORT void gs_effect_set_default(gs_eparam_t *param);
|
||||
EXPORT size_t gs_effect_get_val_size(gs_eparam_t *param);
|
||||
EXPORT void *gs_effect_get_val(gs_eparam_t *param);
|
||||
EXPORT size_t gs_effect_get_default_val_size(gs_eparam_t *param);
|
||||
EXPORT void *gs_effect_get_default_val(gs_eparam_t *param);
|
||||
EXPORT void gs_effect_set_next_sampler(gs_eparam_t *param,
|
||||
gs_samplerstate_t *sampler);
|
||||
|
||||
|
|
@ -430,6 +445,8 @@ EXPORT gs_texture_t *gs_texrender_get_texture(const gs_texrender_t *texrender);
|
|||
#define GS_GL_DUMMYTEX (1<<3) /**<< texture with no allocated texture data */
|
||||
#define GS_DUP_BUFFER (1<<4) /**<< do not pass buffer ownership when
|
||||
* creating a vertex/index buffer */
|
||||
#define GS_SHARED_TEX (1<<5)
|
||||
#define GS_SHARED_KM_TEX (1<<6)
|
||||
|
||||
/* ---------------- */
|
||||
/* global functions */
|
||||
|
|
@ -742,6 +759,36 @@ EXPORT size_t gs_indexbuffer_get_num_indices(
|
|||
EXPORT enum gs_index_type gs_indexbuffer_get_type(
|
||||
const gs_indexbuffer_t *indexbuffer);
|
||||
|
||||
EXPORT bool gs_nv12_available(void);
|
||||
|
||||
#define GS_USE_DEBUG_MARKERS 0
|
||||
#if GS_USE_DEBUG_MARKERS
|
||||
static const float GS_DEBUG_COLOR_DEFAULT[] = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
static const float GS_DEBUG_COLOR_RENDER_VIDEO[] = { 0.0f, 0.5f, 0.0f, 1.0f };
|
||||
static const float GS_DEBUG_COLOR_MAIN_TEXTURE[] = { 0.0f, 0.25f, 0.0f, 1.0f };
|
||||
static const float GS_DEBUG_COLOR_DISPLAY[] = { 0.0f, 0.5f, 0.5f, 1.0f };
|
||||
static const float GS_DEBUG_COLOR_SOURCE[] = { 0.0f, 0.5f, 5.0f, 1.0f };
|
||||
static const float GS_DEBUG_COLOR_ITEM[] = { 0.5f, 0.0f, 0.0f, 1.0f };
|
||||
static const float GS_DEBUG_COLOR_ITEM_TEXTURE[] = { 0.25f, 0.0f, 0.0f, 1.0f };
|
||||
static const float GS_DEBUG_COLOR_CONVERT_FORMAT[] = { 0.5f, 0.5f, 0.0f, 1.0f };
|
||||
#define GS_DEBUG_MARKER_BEGIN(color, markername) \
|
||||
gs_debug_marker_begin(color, markername)
|
||||
#define GS_DEBUG_MARKER_BEGIN_FORMAT(color, format, ...) \
|
||||
gs_debug_marker_begin_format(color, format, \
|
||||
__VA_ARGS__)
|
||||
#define GS_DEBUG_MARKER_END() gs_debug_marker_end()
|
||||
#else
|
||||
#define GS_DEBUG_MARKER_BEGIN(color, markername) ((void)0)
|
||||
#define GS_DEBUG_MARKER_BEGIN_FORMAT(color, format, ...) ((void)0)
|
||||
#define GS_DEBUG_MARKER_END() ((void)0)
|
||||
#endif
|
||||
|
||||
EXPORT void gs_debug_marker_begin(const float color[4],
|
||||
const char *markername);
|
||||
EXPORT void gs_debug_marker_begin_format(const float color[4],
|
||||
const char *format, ...);
|
||||
EXPORT void gs_debug_marker_end(void);
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
/** platform specific function for creating (GL_TEXTURE_RECTANGLE) textures
|
||||
|
|
@ -780,6 +827,30 @@ EXPORT void gs_texture_release_dc(gs_texture_t *gdi_tex);
|
|||
|
||||
/** creates a windows shared texture from a texture handle */
|
||||
EXPORT gs_texture_t *gs_texture_open_shared(uint32_t handle);
|
||||
|
||||
#define GS_INVALID_HANDLE (uint32_t)-1
|
||||
EXPORT uint32_t gs_texture_get_shared_handle(gs_texture_t *tex);
|
||||
|
||||
#define GS_WAIT_INFINITE (uint32_t)-1
|
||||
|
||||
/**
|
||||
* acquires a lock on a keyed mutex texture.
|
||||
* returns -1 on generic failure, ETIMEDOUT if timed out
|
||||
*/
|
||||
EXPORT int gs_texture_acquire_sync(gs_texture_t *tex, uint64_t key, uint32_t ms);
|
||||
|
||||
/**
|
||||
* releases a lock on a keyed mutex texture to another device.
|
||||
* return 0 on success, -1 on error
|
||||
*/
|
||||
EXPORT int gs_texture_release_sync(gs_texture_t *tex, uint64_t key);
|
||||
|
||||
EXPORT bool gs_texture_create_nv12(gs_texture_t **tex_y, gs_texture_t **tex_uv,
|
||||
uint32_t width, uint32_t height, uint32_t flags);
|
||||
|
||||
EXPORT gs_stagesurf_t *gs_stagesurface_create_nv12(
|
||||
uint32_t width, uint32_t height);
|
||||
|
||||
#endif
|
||||
|
||||
/* inline functions used by modules */
|
||||
|
|
@ -804,6 +875,7 @@ static inline uint32_t gs_get_format_bpp(enum gs_color_format format)
|
|||
case GS_DXT1: return 4;
|
||||
case GS_DXT3: return 8;
|
||||
case GS_DXT5: return 8;
|
||||
case GS_R8G8: return 16;
|
||||
case GS_UNKNOWN: return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,18 @@ static inline int get_full_decoded_gif_size(gs_image_file_t *image)
|
|||
return image->gif.width * image->gif.height * 4 * image->gif.frame_count;
|
||||
}
|
||||
|
||||
static bool init_animated_gif(gs_image_file_t *image, const char *path)
|
||||
static inline void *alloc_mem(gs_image_file_t *image, uint64_t *mem_usage,
|
||||
size_t size)
|
||||
{
|
||||
UNUSED_PARAMETER(image);
|
||||
|
||||
if (mem_usage)
|
||||
*mem_usage += size;
|
||||
return bzalloc(size);
|
||||
}
|
||||
|
||||
static bool init_animated_gif(gs_image_file_t *image, const char *path,
|
||||
uint64_t *mem_usage)
|
||||
{
|
||||
bool is_animated_gif = true;
|
||||
gif_result result;
|
||||
|
|
@ -121,9 +132,9 @@ static bool init_animated_gif(gs_image_file_t *image, const char *path)
|
|||
if (image->is_animated_gif) {
|
||||
gif_decode_frame(&image->gif, 0);
|
||||
|
||||
image->animation_frame_cache = bzalloc(
|
||||
image->animation_frame_cache = alloc_mem(image, mem_usage,
|
||||
image->gif.frame_count * sizeof(uint8_t*));
|
||||
image->animation_frame_data = bzalloc(
|
||||
image->animation_frame_data = alloc_mem(image, mem_usage,
|
||||
get_full_decoded_gif_size(image));
|
||||
|
||||
for (unsigned int i = 0; i < image->gif.frame_count; i++) {
|
||||
|
|
@ -137,6 +148,11 @@ static bool init_animated_gif(gs_image_file_t *image, const char *path)
|
|||
image->cx = (uint32_t)image->gif.width;
|
||||
image->cy = (uint32_t)image->gif.height;
|
||||
image->format = GS_RGBA;
|
||||
|
||||
if (mem_usage) {
|
||||
*mem_usage += image->cx * image->cy * 4;
|
||||
*mem_usage += size;
|
||||
}
|
||||
} else {
|
||||
gif_finalise(&image->gif);
|
||||
bfree(image->gif_data);
|
||||
|
|
@ -157,7 +173,8 @@ not_animated:
|
|||
return is_animated_gif;
|
||||
}
|
||||
|
||||
void gs_image_file_init(gs_image_file_t *image, const char *file)
|
||||
static void gs_image_file_init_internal(gs_image_file_t *image,
|
||||
const char *file, uint64_t *mem_usage)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
|
|
@ -172,13 +189,18 @@ void gs_image_file_init(gs_image_file_t *image, const char *file)
|
|||
len = strlen(file);
|
||||
|
||||
if (len > 4 && strcmp(file + len - 4, ".gif") == 0) {
|
||||
if (init_animated_gif(image, file))
|
||||
if (init_animated_gif(image, file, mem_usage))
|
||||
return;
|
||||
}
|
||||
|
||||
image->texture_data = gs_create_texture_file_data(file,
|
||||
&image->format, &image->cx, &image->cy);
|
||||
|
||||
if (mem_usage) {
|
||||
*mem_usage += image->cx * image->cy *
|
||||
gs_get_format_bpp(image->format) / 8;
|
||||
}
|
||||
|
||||
image->loaded = !!image->texture_data;
|
||||
if (!image->loaded) {
|
||||
blog(LOG_WARNING, "Failed to load file '%s'", file);
|
||||
|
|
@ -186,6 +208,11 @@ void gs_image_file_init(gs_image_file_t *image, const char *file)
|
|||
}
|
||||
}
|
||||
|
||||
void gs_image_file_init(gs_image_file_t *image, const char *file)
|
||||
{
|
||||
gs_image_file_init_internal(image, file, NULL);
|
||||
}
|
||||
|
||||
void gs_image_file_free(gs_image_file_t *image)
|
||||
{
|
||||
if (!image)
|
||||
|
|
@ -206,6 +233,11 @@ void gs_image_file_free(gs_image_file_t *image)
|
|||
memset(image, 0, sizeof(*image));
|
||||
}
|
||||
|
||||
void gs_image_file2_init(gs_image_file2_t *if2, const char *file)
|
||||
{
|
||||
gs_image_file_init_internal(&if2->image, file, &if2->mem_usage);
|
||||
}
|
||||
|
||||
void gs_image_file_init_texture(gs_image_file_t *image)
|
||||
{
|
||||
if (!image->loaded)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@
|
|||
#include "graphics.h"
|
||||
#include "libnsgif/libnsgif.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct gs_image_file {
|
||||
gs_texture_t *texture;
|
||||
enum gs_color_format format;
|
||||
|
|
@ -42,7 +46,13 @@ struct gs_image_file {
|
|||
gif_bitmap_callback_vt bitmap_callbacks;
|
||||
};
|
||||
|
||||
struct gs_image_file2 {
|
||||
struct gs_image_file image;
|
||||
uint64_t mem_usage;
|
||||
};
|
||||
|
||||
typedef struct gs_image_file gs_image_file_t;
|
||||
typedef struct gs_image_file2 gs_image_file2_t;
|
||||
|
||||
EXPORT void gs_image_file_init(gs_image_file_t *image, const char *file);
|
||||
EXPORT void gs_image_file_free(gs_image_file_t *image);
|
||||
|
|
@ -51,3 +61,31 @@ EXPORT void gs_image_file_init_texture(gs_image_file_t *image);
|
|||
EXPORT bool gs_image_file_tick(gs_image_file_t *image,
|
||||
uint64_t elapsed_time_ns);
|
||||
EXPORT void gs_image_file_update_texture(gs_image_file_t *image);
|
||||
|
||||
EXPORT void gs_image_file2_init(gs_image_file2_t *if2, const char *file);
|
||||
|
||||
static void gs_image_file2_free(gs_image_file2_t *if2)
|
||||
{
|
||||
gs_image_file_free(&if2->image);
|
||||
if2->mem_usage = 0;
|
||||
}
|
||||
|
||||
static inline void gs_image_file2_init_texture(gs_image_file2_t *if2)
|
||||
{
|
||||
gs_image_file_init_texture(&if2->image);
|
||||
}
|
||||
|
||||
static inline bool gs_image_file2_tick(gs_image_file2_t *if2,
|
||||
uint64_t elapsed_time_ns)
|
||||
{
|
||||
return gs_image_file_tick(&if2->image, elapsed_time_ns);
|
||||
}
|
||||
|
||||
static inline void gs_image_file2_update_texture(gs_image_file2_t *if2)
|
||||
{
|
||||
gs_image_file_update_texture(&if2->image);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -104,6 +104,8 @@ void shader_sampler_convert(struct shader_sampler *ss,
|
|||
size_t i;
|
||||
memset(info, 0, sizeof(struct gs_sampler_info));
|
||||
|
||||
info->max_anisotropy = 1;
|
||||
|
||||
for (i = 0; i < ss->states.num; i++) {
|
||||
const char *state = ss->states.array[i];
|
||||
const char *value = ss->values.array[i];
|
||||
|
|
|
|||
11
libobs/libobs.pc.in
Normal file
11
libobs/libobs.pc.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
prefix=@DEST_DIR@
|
||||
exec_prefix=${prefix}
|
||||
libdir=${prefix}/@OBS_LIBRARY_DESTINATION@
|
||||
includedir=${prefix}/include
|
||||
|
||||
Name: libobs
|
||||
Description: OBS Studio Library
|
||||
Version: @OBS_VERSION@
|
||||
Requires: x11
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} @PRIVATE_LIBS@
|
||||
|
|
@ -102,6 +102,21 @@ audio_resampler_t *audio_resampler_create(const struct resample_info *dst,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (rs->input_layout == AV_CH_LAYOUT_MONO && rs->output_ch > 1) {
|
||||
const double matrix[MAX_AUDIO_CHANNELS][MAX_AUDIO_CHANNELS] = {
|
||||
{1},
|
||||
{1, 1},
|
||||
{1, 1, 0},
|
||||
{1, 1, 1, 1},
|
||||
{1, 1, 1, 0, 1},
|
||||
{1, 1, 1, 1, 1, 1},
|
||||
{1, 1, 1, 0, 1, 1, 1},
|
||||
{1, 1, 1, 0, 1, 1, 1, 1},
|
||||
};
|
||||
if (swr_set_matrix(rs->context, matrix[rs->output_ch - 1], 1) < 0)
|
||||
blog(LOG_DEBUG, "swr_set_matrix failed for mono upmix\n");
|
||||
}
|
||||
|
||||
errcode = swr_init(rs->context);
|
||||
if (errcode != 0) {
|
||||
blog(LOG_ERROR, "avresample_open failed: error code %d",
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ struct video_output {
|
|||
|
||||
os_sem_t *update_semaphore;
|
||||
uint64_t frame_time;
|
||||
uint32_t skipped_frames;
|
||||
uint32_t total_frames;
|
||||
volatile long skipped_frames;
|
||||
volatile long total_frames;
|
||||
|
||||
bool initialized;
|
||||
|
||||
|
|
@ -77,6 +77,9 @@ struct video_output {
|
|||
size_t first_added;
|
||||
size_t last_added;
|
||||
struct cached_frame_info cache[MAX_CACHE_SIZE];
|
||||
|
||||
volatile bool raw_active;
|
||||
volatile long gpu_refs;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
|
@ -156,7 +159,7 @@ static inline bool video_output_cur_frame(struct video_output *video)
|
|||
video->last_added = video->first_added;
|
||||
} else if (skipped) {
|
||||
--frame_info->skipped;
|
||||
++video->skipped_frames;
|
||||
os_atomic_inc_long(&video->skipped_frames);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&video->data_mutex);
|
||||
|
|
@ -182,10 +185,10 @@ static void *video_thread(void *param)
|
|||
|
||||
profile_start(video_thread_name);
|
||||
while (!video->stop && !video_output_cur_frame(video)) {
|
||||
video->total_frames++;
|
||||
os_atomic_inc_long(&video->total_frames);
|
||||
}
|
||||
|
||||
video->total_frames++;
|
||||
os_atomic_inc_long(&video->total_frames);
|
||||
profile_end(video_thread_name);
|
||||
|
||||
profile_reenable_thread();
|
||||
|
|
@ -330,6 +333,12 @@ static inline bool video_input_init(struct video_input *input,
|
|||
return true;
|
||||
}
|
||||
|
||||
static inline void reset_frames(video_t *video)
|
||||
{
|
||||
os_atomic_set_long(&video->skipped_frames, 0);
|
||||
os_atomic_set_long(&video->total_frames, 0);
|
||||
}
|
||||
|
||||
bool video_output_connect(video_t *video,
|
||||
const struct video_scale_info *conversion,
|
||||
void (*callback)(void *param, struct video_data *frame),
|
||||
|
|
@ -342,11 +351,6 @@ bool video_output_connect(video_t *video,
|
|||
|
||||
pthread_mutex_lock(&video->input_mutex);
|
||||
|
||||
if (video->inputs.num == 0) {
|
||||
video->skipped_frames = 0;
|
||||
video->total_frames = 0;
|
||||
}
|
||||
|
||||
if (video_get_input_idx(video, callback, param) == DARRAY_INVALID) {
|
||||
struct video_input input;
|
||||
memset(&input, 0, sizeof(input));
|
||||
|
|
@ -368,8 +372,15 @@ bool video_output_connect(video_t *video,
|
|||
input.conversion.height = video->info.height;
|
||||
|
||||
success = video_input_init(&input, video);
|
||||
if (success)
|
||||
if (success) {
|
||||
if (video->inputs.num == 0) {
|
||||
if (!os_atomic_load_long(&video->gpu_refs)) {
|
||||
reset_frames(video);
|
||||
}
|
||||
os_atomic_set_bool(&video->raw_active, true);
|
||||
}
|
||||
da_push_back(video->inputs, &input);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&video->input_mutex);
|
||||
|
|
@ -377,6 +388,24 @@ bool video_output_connect(video_t *video,
|
|||
return success;
|
||||
}
|
||||
|
||||
static void log_skipped(video_t *video)
|
||||
{
|
||||
long skipped = os_atomic_load_long(&video->skipped_frames);
|
||||
double percentage_skipped =
|
||||
(double)skipped /
|
||||
(double)os_atomic_load_long(&video->total_frames) *
|
||||
100.0;
|
||||
|
||||
if (skipped)
|
||||
blog(LOG_INFO, "Video stopped, number of "
|
||||
"skipped frames due "
|
||||
"to encoding lag: "
|
||||
"%ld/%ld (%0.1f%%)",
|
||||
video->skipped_frames,
|
||||
video->total_frames,
|
||||
percentage_skipped);
|
||||
}
|
||||
|
||||
void video_output_disconnect(video_t *video,
|
||||
void (*callback)(void *param, struct video_data *frame),
|
||||
void *param)
|
||||
|
|
@ -390,20 +419,13 @@ void video_output_disconnect(video_t *video,
|
|||
if (idx != DARRAY_INVALID) {
|
||||
video_input_free(video->inputs.array+idx);
|
||||
da_erase(video->inputs, idx);
|
||||
}
|
||||
|
||||
if (video->inputs.num == 0) {
|
||||
double percentage_skipped = (double)video->skipped_frames /
|
||||
(double)video->total_frames * 100.0;
|
||||
|
||||
if (video->skipped_frames)
|
||||
blog(LOG_INFO, "Video stopped, number of "
|
||||
"skipped frames due "
|
||||
"to encoding lag: "
|
||||
"%"PRIu32"/%"PRIu32" (%0.1f%%)",
|
||||
video->skipped_frames,
|
||||
video->total_frames,
|
||||
percentage_skipped);
|
||||
if (video->inputs.num == 0) {
|
||||
os_atomic_set_bool(&video->raw_active, false);
|
||||
if (!os_atomic_load_long(&video->gpu_refs)) {
|
||||
log_skipped(video);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&video->input_mutex);
|
||||
|
|
@ -412,7 +434,7 @@ void video_output_disconnect(video_t *video,
|
|||
bool video_output_active(const video_t *video)
|
||||
{
|
||||
if (!video) return false;
|
||||
return video->inputs.num != 0;
|
||||
return os_atomic_load_bool(&video->raw_active);
|
||||
}
|
||||
|
||||
const struct video_output_info *video_output_get_info(const video_t *video)
|
||||
|
|
@ -521,10 +543,42 @@ double video_output_get_frame_rate(const video_t *video)
|
|||
|
||||
uint32_t video_output_get_skipped_frames(const video_t *video)
|
||||
{
|
||||
return video->skipped_frames;
|
||||
return (uint32_t)os_atomic_load_long(&video->skipped_frames);
|
||||
}
|
||||
|
||||
uint32_t video_output_get_total_frames(const video_t *video)
|
||||
{
|
||||
return video->total_frames;
|
||||
return (uint32_t)os_atomic_load_long(&video->total_frames);
|
||||
}
|
||||
|
||||
/* Note: These four functions below are a very slight bit of a hack. If the
|
||||
* texture encoder thread is active while the raw encoder thread is active, the
|
||||
* total frame count will just be doubled while they're both active. Which is
|
||||
* fine. What's more important is having a relatively accurate skipped frame
|
||||
* count. */
|
||||
|
||||
void video_output_inc_texture_encoders(video_t *video)
|
||||
{
|
||||
if (os_atomic_inc_long(&video->gpu_refs) == 1 &&
|
||||
!os_atomic_load_bool(&video->raw_active)) {
|
||||
reset_frames(video);
|
||||
}
|
||||
}
|
||||
|
||||
void video_output_dec_texture_encoders(video_t *video)
|
||||
{
|
||||
if (os_atomic_dec_long(&video->gpu_refs) == 0 &&
|
||||
!os_atomic_load_bool(&video->raw_active)) {
|
||||
log_skipped(video);
|
||||
}
|
||||
}
|
||||
|
||||
void video_output_inc_texture_frames(video_t *video)
|
||||
{
|
||||
os_atomic_inc_long(&video->total_frames);
|
||||
}
|
||||
|
||||
void video_output_inc_texture_skipped_frames(video_t *video)
|
||||
{
|
||||
os_atomic_inc_long(&video->skipped_frames);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,15 +135,23 @@ static inline const char *get_video_colorspace_name(enum video_colorspace cs)
|
|||
return "601";
|
||||
}
|
||||
|
||||
static inline const char *get_video_range_name(enum video_range_type range)
|
||||
static inline enum video_range_type resolve_video_range(
|
||||
enum video_format format, enum video_range_type range)
|
||||
{
|
||||
switch (range) {
|
||||
case VIDEO_RANGE_FULL: return "Full";
|
||||
case VIDEO_RANGE_PARTIAL:
|
||||
case VIDEO_RANGE_DEFAULT:;
|
||||
if (range == VIDEO_RANGE_DEFAULT) {
|
||||
range = format_is_yuv(format)
|
||||
? VIDEO_RANGE_PARTIAL
|
||||
: VIDEO_RANGE_FULL;
|
||||
}
|
||||
|
||||
return "Partial";
|
||||
return range;
|
||||
}
|
||||
|
||||
static inline const char *get_video_range_name(enum video_format format,
|
||||
enum video_range_type range)
|
||||
{
|
||||
range = resolve_video_range(format, range);
|
||||
return range == VIDEO_RANGE_FULL ? "Full" : "Partial";
|
||||
}
|
||||
|
||||
enum video_scale_type {
|
||||
|
|
@ -202,6 +210,11 @@ EXPORT double video_output_get_frame_rate(const video_t *video);
|
|||
EXPORT uint32_t video_output_get_skipped_frames(const video_t *video);
|
||||
EXPORT uint32_t video_output_get_total_frames(const video_t *video);
|
||||
|
||||
extern void video_output_inc_texture_encoders(video_t *video);
|
||||
extern void video_output_dec_texture_encoders(video_t *video);
|
||||
extern void video_output_inc_texture_frames(video_t *video);
|
||||
extern void video_output_inc_texture_skipped_frames(video_t *video);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -932,3 +932,12 @@ void obs_volmeter_remove_callback(obs_volmeter_t *volmeter,
|
|||
pthread_mutex_unlock(&volmeter->callback_mutex);
|
||||
}
|
||||
|
||||
float obs_mul_to_db(float mul)
|
||||
{
|
||||
return mul_to_db(mul);
|
||||
}
|
||||
|
||||
float obs_db_to_mul(float db)
|
||||
{
|
||||
return db_to_mul(db);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -273,6 +273,9 @@ EXPORT void obs_volmeter_add_callback(obs_volmeter_t *volmeter,
|
|||
EXPORT void obs_volmeter_remove_callback(obs_volmeter_t *volmeter,
|
||||
obs_volmeter_updated_t callback, void *param);
|
||||
|
||||
EXPORT float obs_mul_to_db(float mul);
|
||||
EXPORT float obs_db_to_mul(float db);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ static void push_audio_tree(obs_source_t *parent, obs_source_t *source, void *p)
|
|||
struct obs_core_audio *audio = p;
|
||||
|
||||
if (da_find(audio->render_order, &source, 0) == DARRAY_INVALID) {
|
||||
obs_source_addref(source);
|
||||
da_push_back(audio->render_order, &source);
|
||||
obs_source_t *s = obs_source_get_ref(source);
|
||||
if (s) da_push_back(audio->render_order, &s);
|
||||
}
|
||||
|
||||
UNUSED_PARAMETER(parent);
|
||||
|
|
@ -227,7 +227,8 @@ static inline void discard_audio(struct obs_core_audio *audio,
|
|||
}
|
||||
|
||||
static void add_audio_buffering(struct obs_core_audio *audio,
|
||||
size_t sample_rate, struct ts_info *ts, uint64_t min_ts)
|
||||
size_t sample_rate, struct ts_info *ts, uint64_t min_ts,
|
||||
const char *buffering_name)
|
||||
{
|
||||
struct ts_info new_ts;
|
||||
uint64_t offset;
|
||||
|
|
@ -259,8 +260,9 @@ static void add_audio_buffering(struct obs_core_audio *audio,
|
|||
sample_rate;
|
||||
|
||||
blog(LOG_INFO, "adding %d milliseconds of audio buffering, total "
|
||||
"audio buffering is now %d milliseconds",
|
||||
(int)ms, (int)total_ms);
|
||||
"audio buffering is now %d milliseconds"
|
||||
" (source: %s)\n",
|
||||
(int)ms, (int)total_ms, buffering_name);
|
||||
#if DEBUG_AUDIO == 1
|
||||
blog(LOG_DEBUG, "min_ts (%"PRIu64") < start timestamp "
|
||||
"(%"PRIu64")", min_ts, ts->start);
|
||||
|
|
@ -322,17 +324,21 @@ static bool audio_buffer_insuffient(struct obs_source *source,
|
|||
return false;
|
||||
}
|
||||
|
||||
static inline void find_min_ts(struct obs_core_data *data,
|
||||
static inline const char *find_min_ts(struct obs_core_data *data,
|
||||
uint64_t *min_ts)
|
||||
{
|
||||
obs_source_t *buffering_source = NULL;
|
||||
struct obs_source *source = data->first_audio_source;
|
||||
while (source) {
|
||||
if (!source->audio_pending && source->audio_ts &&
|
||||
source->audio_ts < *min_ts)
|
||||
source->audio_ts < *min_ts) {
|
||||
*min_ts = source->audio_ts;
|
||||
buffering_source = source;
|
||||
}
|
||||
|
||||
source = (struct obs_source*)source->next_audio_source;
|
||||
}
|
||||
return buffering_source ? obs_source_get_name(buffering_source) : NULL;
|
||||
}
|
||||
|
||||
static inline bool mark_invalid_sources(struct obs_core_data *data,
|
||||
|
|
@ -350,12 +356,13 @@ static inline bool mark_invalid_sources(struct obs_core_data *data,
|
|||
return recalculate;
|
||||
}
|
||||
|
||||
static inline void calc_min_ts(struct obs_core_data *data,
|
||||
static inline const char *calc_min_ts(struct obs_core_data *data,
|
||||
size_t sample_rate, uint64_t *min_ts)
|
||||
{
|
||||
find_min_ts(data, min_ts);
|
||||
const char *buffering_name = find_min_ts(data, min_ts);
|
||||
if (mark_invalid_sources(data, sample_rate, *min_ts))
|
||||
find_min_ts(data, min_ts);
|
||||
buffering_name = find_min_ts(data, min_ts);
|
||||
return buffering_name;
|
||||
}
|
||||
|
||||
static inline void release_audio_sources(struct obs_core_audio *audio)
|
||||
|
|
@ -425,13 +432,14 @@ bool audio_callback(void *param,
|
|||
/* ------------------------------------------------ */
|
||||
/* get minimum audio timestamp */
|
||||
pthread_mutex_lock(&data->audio_sources_mutex);
|
||||
calc_min_ts(data, sample_rate, &min_ts);
|
||||
const char *buffering_name = calc_min_ts(data, sample_rate, &min_ts);
|
||||
pthread_mutex_unlock(&data->audio_sources_mutex);
|
||||
|
||||
/* ------------------------------------------------ */
|
||||
/* if a source has gone backward in time, buffer */
|
||||
if (min_ts < ts.start)
|
||||
add_audio_buffering(audio, sample_rate, &ts, min_ts);
|
||||
add_audio_buffering(audio, sample_rate, &ts, min_ts,
|
||||
buffering_name);
|
||||
|
||||
/* ------------------------------------------------ */
|
||||
/* mix audio */
|
||||
|
|
|
|||
|
|
@ -27,21 +27,21 @@
|
|||
/*
|
||||
* Increment if major breaking API changes
|
||||
*/
|
||||
#define LIBOBS_API_MAJOR_VER 22
|
||||
#define LIBOBS_API_MAJOR_VER 23
|
||||
|
||||
/*
|
||||
* Increment if backward-compatible additions
|
||||
*
|
||||
* Reset to zero each major version
|
||||
*/
|
||||
#define LIBOBS_API_MINOR_VER 0
|
||||
#define LIBOBS_API_MINOR_VER 2
|
||||
|
||||
/*
|
||||
* Increment if backward-compatible bug fix
|
||||
*
|
||||
* Reset to zero each major or minor version
|
||||
*/
|
||||
#define LIBOBS_API_PATCH_VER 3
|
||||
#define LIBOBS_API_PATCH_VER 1
|
||||
|
||||
#define MAKE_SEMANTIC_VERSION(major, minor, patch) \
|
||||
((major << 24) | \
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
#define OBS_OUTPUT_DISCONNECTED -5
|
||||
#define OBS_OUTPUT_UNSUPPORTED -6
|
||||
#define OBS_OUTPUT_NO_SPACE -7
|
||||
#define OBS_OUTPUT_ENCODE_ERROR -8
|
||||
|
||||
#define OBS_VIDEO_SUCCESS 0
|
||||
#define OBS_VIDEO_FAIL -1
|
||||
|
|
|
|||
|
|
@ -46,17 +46,19 @@ bool obs_display_init(struct obs_display *display,
|
|||
return false;
|
||||
}
|
||||
|
||||
display->background_color = 0x4C4C4C;
|
||||
display->enabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
obs_display_t *obs_display_create(const struct gs_init_data *graphics_data)
|
||||
obs_display_t *obs_display_create(const struct gs_init_data *graphics_data,
|
||||
uint32_t background_color)
|
||||
{
|
||||
struct obs_display *display = bzalloc(sizeof(struct obs_display));
|
||||
|
||||
gs_enter_context(obs->video.graphics);
|
||||
|
||||
display->background_color = background_color;
|
||||
|
||||
if (!obs_display_init(display, graphics_data)) {
|
||||
obs_display_destroy(display);
|
||||
display = NULL;
|
||||
|
|
@ -173,7 +175,6 @@ static inline void render_display_begin(struct obs_display *display,
|
|||
static inline void render_display_end()
|
||||
{
|
||||
gs_end_scene();
|
||||
gs_present();
|
||||
}
|
||||
|
||||
void render_display(struct obs_display *display)
|
||||
|
|
@ -183,6 +184,8 @@ void render_display(struct obs_display *display)
|
|||
|
||||
if (!display || !display->enabled) return;
|
||||
|
||||
GS_DEBUG_MARKER_BEGIN(GS_DEBUG_COLOR_DISPLAY, "obs_display");
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
pthread_mutex_lock(&display->draw_info_mutex);
|
||||
|
|
@ -212,6 +215,10 @@ void render_display(struct obs_display *display)
|
|||
pthread_mutex_unlock(&display->draw_callbacks_mutex);
|
||||
|
||||
render_display_end();
|
||||
|
||||
GS_DEBUG_MARKER_END();
|
||||
|
||||
gs_present();
|
||||
}
|
||||
|
||||
void obs_display_set_enabled(obs_display_t *display, bool enable)
|
||||
|
|
@ -230,3 +237,19 @@ void obs_display_set_background_color(obs_display_t *display, uint32_t color)
|
|||
if (display)
|
||||
display->background_color = color;
|
||||
}
|
||||
|
||||
void obs_display_size(obs_display_t *display,
|
||||
uint32_t *width, uint32_t *height)
|
||||
{
|
||||
*width = 0;
|
||||
*height = 0;
|
||||
|
||||
if (display) {
|
||||
pthread_mutex_lock(&display->draw_info_mutex);
|
||||
|
||||
*width = display->cx;
|
||||
*height = display->cy;
|
||||
|
||||
pthread_mutex_unlock(&display->draw_info_mutex);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,8 +64,8 @@ static bool init_encoder(struct obs_encoder *encoder, const char *name,
|
|||
if (pthread_mutex_init(&encoder->outputs_mutex, NULL) != 0)
|
||||
return false;
|
||||
|
||||
if (encoder->info.get_defaults)
|
||||
encoder->info.get_defaults(encoder->context.settings);
|
||||
if (encoder->orig_info.get_defaults)
|
||||
encoder->orig_info.get_defaults(encoder->context.settings);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -90,8 +90,10 @@ static struct obs_encoder *create_encoder(const char *id,
|
|||
encoder->info.id = bstrdup(id);
|
||||
encoder->info.type = type;
|
||||
encoder->owns_info_id = true;
|
||||
encoder->orig_info = encoder->info;
|
||||
} else {
|
||||
encoder->info = *ei;
|
||||
encoder->orig_info = *ei;
|
||||
}
|
||||
|
||||
success = init_encoder(encoder, name, settings, hotkey_data);
|
||||
|
|
@ -177,6 +179,12 @@ static inline bool has_scaling(const struct obs_encoder *encoder)
|
|||
video_height != encoder->scaled_height);
|
||||
}
|
||||
|
||||
static inline bool gpu_encode_available(const struct obs_encoder *encoder)
|
||||
{
|
||||
return (encoder->info.caps & OBS_ENCODER_CAP_PASS_TEXTURE) != 0 &&
|
||||
obs->video.using_nv12_tex;
|
||||
}
|
||||
|
||||
static void add_connection(struct obs_encoder *encoder)
|
||||
{
|
||||
if (encoder->info.type == OBS_ENCODER_AUDIO) {
|
||||
|
|
@ -189,21 +197,37 @@ static void add_connection(struct obs_encoder *encoder)
|
|||
struct video_scale_info info = {0};
|
||||
get_video_info(encoder, &info);
|
||||
|
||||
start_raw_video(encoder->media, &info, receive_video, encoder);
|
||||
if (gpu_encode_available(encoder)) {
|
||||
start_gpu_encode(encoder);
|
||||
} else {
|
||||
start_raw_video(encoder->media, &info, receive_video,
|
||||
encoder);
|
||||
}
|
||||
}
|
||||
|
||||
set_encoder_active(encoder, true);
|
||||
}
|
||||
|
||||
static void remove_connection(struct obs_encoder *encoder)
|
||||
static void remove_connection(struct obs_encoder *encoder, bool shutdown)
|
||||
{
|
||||
if (encoder->info.type == OBS_ENCODER_AUDIO)
|
||||
if (encoder->info.type == OBS_ENCODER_AUDIO) {
|
||||
audio_output_disconnect(encoder->media, encoder->mixer_idx,
|
||||
receive_audio, encoder);
|
||||
else
|
||||
stop_raw_video(encoder->media, receive_video, encoder);
|
||||
} else {
|
||||
if (gpu_encode_available(encoder)) {
|
||||
stop_gpu_encode(encoder);
|
||||
} else {
|
||||
stop_raw_video(encoder->media, receive_video, encoder);
|
||||
}
|
||||
}
|
||||
|
||||
obs_encoder_shutdown(encoder);
|
||||
/* obs_encoder_shutdown locks init_mutex, so don't call it on encode
|
||||
* errors, otherwise you can get a deadlock with outputs when they end
|
||||
* data capture, which will lock init_mutex and the video callback
|
||||
* mutex in the reverse order. instead, call shutdown before starting
|
||||
* up again */
|
||||
if (shutdown)
|
||||
obs_encoder_shutdown(encoder);
|
||||
set_encoder_active(encoder, false);
|
||||
}
|
||||
|
||||
|
|
@ -253,11 +277,13 @@ void obs_encoder_destroy(obs_encoder_t *encoder)
|
|||
|
||||
obs_context_data_remove(&encoder->context);
|
||||
|
||||
pthread_mutex_lock(&encoder->init_mutex);
|
||||
pthread_mutex_lock(&encoder->callbacks_mutex);
|
||||
destroy = encoder->callbacks.num == 0;
|
||||
if (!destroy)
|
||||
encoder->destroy_on_stop = true;
|
||||
pthread_mutex_unlock(&encoder->callbacks_mutex);
|
||||
pthread_mutex_unlock(&encoder->init_mutex);
|
||||
|
||||
if (destroy)
|
||||
obs_encoder_actually_destroy(encoder);
|
||||
|
|
@ -282,8 +308,11 @@ void obs_encoder_set_name(obs_encoder_t *encoder, const char *name)
|
|||
static inline obs_data_t *get_defaults(const struct obs_encoder_info *info)
|
||||
{
|
||||
obs_data_t *settings = obs_data_create();
|
||||
if (info->get_defaults)
|
||||
if (info->get_defaults2) {
|
||||
info->get_defaults2(settings, info->type_data);
|
||||
} else if (info->get_defaults) {
|
||||
info->get_defaults(settings);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
|
@ -304,11 +333,16 @@ obs_data_t *obs_encoder_get_defaults(const obs_encoder_t *encoder)
|
|||
obs_properties_t *obs_get_encoder_properties(const char *id)
|
||||
{
|
||||
const struct obs_encoder_info *ei = find_encoder(id);
|
||||
if (ei && ei->get_properties) {
|
||||
if (ei && (ei->get_properties || ei->get_properties2)) {
|
||||
obs_data_t *defaults = get_defaults(ei);
|
||||
obs_properties_t *properties;
|
||||
|
||||
properties = ei->get_properties(NULL);
|
||||
if (ei->get_properties2) {
|
||||
properties = ei->get_properties2(NULL, ei->type_data);
|
||||
} else if (ei->get_properties) {
|
||||
properties = ei->get_properties(NULL);
|
||||
}
|
||||
|
||||
obs_properties_apply_settings(properties, defaults);
|
||||
obs_data_release(defaults);
|
||||
return properties;
|
||||
|
|
@ -321,12 +355,21 @@ obs_properties_t *obs_encoder_properties(const obs_encoder_t *encoder)
|
|||
if (!obs_encoder_valid(encoder, "obs_encoder_properties"))
|
||||
return NULL;
|
||||
|
||||
if (encoder->info.get_properties) {
|
||||
if (encoder->orig_info.get_properties2) {
|
||||
obs_properties_t *props;
|
||||
props = encoder->info.get_properties(encoder->context.data);
|
||||
props = encoder->orig_info.get_properties2(
|
||||
encoder->context.data,
|
||||
encoder->orig_info.type_data);
|
||||
obs_properties_apply_settings(props, encoder->context.settings);
|
||||
return props;
|
||||
|
||||
} else if (encoder->orig_info.get_properties) {
|
||||
obs_properties_t *props;
|
||||
props = encoder->orig_info.get_properties(encoder->context.data);
|
||||
obs_properties_apply_settings(props, encoder->context.settings);
|
||||
return props;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -388,6 +431,8 @@ static void intitialize_audio_encoder(struct obs_encoder *encoder)
|
|||
reset_audio_buffers(encoder);
|
||||
}
|
||||
|
||||
static THREAD_LOCAL bool can_reroute = false;
|
||||
|
||||
static inline bool obs_encoder_initialize_internal(obs_encoder_t *encoder)
|
||||
{
|
||||
if (encoder_active(encoder))
|
||||
|
|
@ -397,19 +442,45 @@ static inline bool obs_encoder_initialize_internal(obs_encoder_t *encoder)
|
|||
|
||||
obs_encoder_shutdown(encoder);
|
||||
|
||||
if (encoder->info.create)
|
||||
encoder->context.data = encoder->info.create(
|
||||
if (encoder->orig_info.create) {
|
||||
can_reroute = true;
|
||||
encoder->info = encoder->orig_info;
|
||||
encoder->context.data = encoder->orig_info.create(
|
||||
encoder->context.settings, encoder);
|
||||
can_reroute = false;
|
||||
}
|
||||
if (!encoder->context.data)
|
||||
return false;
|
||||
|
||||
if (encoder->info.type == OBS_ENCODER_AUDIO)
|
||||
if (encoder->orig_info.type == OBS_ENCODER_AUDIO)
|
||||
intitialize_audio_encoder(encoder);
|
||||
|
||||
encoder->initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void *obs_encoder_create_rerouted(obs_encoder_t *encoder, const char *reroute_id)
|
||||
{
|
||||
if (!obs_ptr_valid(encoder, "obs_encoder_reroute"))
|
||||
return NULL;
|
||||
if (!obs_ptr_valid(reroute_id, "obs_encoder_reroute"))
|
||||
return NULL;
|
||||
if (!can_reroute)
|
||||
return NULL;
|
||||
|
||||
const struct obs_encoder_info *ei = find_encoder(reroute_id);
|
||||
if (ei) {
|
||||
if (ei->type != encoder->orig_info.type ||
|
||||
astrcmpi(ei->codec, encoder->orig_info.codec) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
encoder->info = *ei;
|
||||
return encoder->info.create(encoder->context.settings, encoder);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool obs_encoder_initialize(obs_encoder_t *encoder)
|
||||
{
|
||||
bool success;
|
||||
|
|
@ -510,7 +581,7 @@ static inline bool obs_encoder_stop_internal(obs_encoder_t *encoder,
|
|||
pthread_mutex_unlock(&encoder->callbacks_mutex);
|
||||
|
||||
if (last) {
|
||||
remove_connection(encoder);
|
||||
remove_connection(encoder, true);
|
||||
encoder->initialized = false;
|
||||
|
||||
if (encoder->destroy_on_stop) {
|
||||
|
|
@ -766,19 +837,65 @@ static inline void send_packet(struct obs_encoder *encoder,
|
|||
cb->new_packet(cb->param, packet);
|
||||
}
|
||||
|
||||
static void full_stop(struct obs_encoder *encoder)
|
||||
void full_stop(struct obs_encoder *encoder)
|
||||
{
|
||||
if (encoder) {
|
||||
pthread_mutex_lock(&encoder->outputs_mutex);
|
||||
for (size_t i = 0; i < encoder->outputs.num; i++) {
|
||||
struct obs_output *output = encoder->outputs.array[i];
|
||||
obs_output_force_stop(output);
|
||||
|
||||
pthread_mutex_lock(&output->interleaved_mutex);
|
||||
output->info.encoded_packet(output->context.data, NULL);
|
||||
pthread_mutex_unlock(&output->interleaved_mutex);
|
||||
}
|
||||
pthread_mutex_unlock(&encoder->outputs_mutex);
|
||||
|
||||
pthread_mutex_lock(&encoder->callbacks_mutex);
|
||||
da_free(encoder->callbacks);
|
||||
remove_connection(encoder);
|
||||
pthread_mutex_unlock(&encoder->callbacks_mutex);
|
||||
|
||||
remove_connection(encoder, false);
|
||||
encoder->initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
void send_off_encoder_packet(obs_encoder_t *encoder, bool success,
|
||||
bool received, struct encoder_packet *pkt)
|
||||
{
|
||||
if (!success) {
|
||||
blog(LOG_ERROR, "Error encoding with encoder '%s'",
|
||||
encoder->context.name);
|
||||
full_stop(encoder);
|
||||
return;
|
||||
}
|
||||
|
||||
if (received) {
|
||||
if (!encoder->first_received) {
|
||||
encoder->offset_usec = packet_dts_usec(pkt);
|
||||
encoder->first_received = true;
|
||||
}
|
||||
|
||||
/* we use system time here to ensure sync with other encoders,
|
||||
* you do not want to use relative timestamps here */
|
||||
pkt->dts_usec = encoder->start_ts / 1000 +
|
||||
packet_dts_usec(pkt) - encoder->offset_usec;
|
||||
pkt->sys_dts_usec = pkt->dts_usec;
|
||||
|
||||
pthread_mutex_lock(&encoder->callbacks_mutex);
|
||||
|
||||
for (size_t i = encoder->callbacks.num; i > 0; i--) {
|
||||
struct encoder_callback *cb;
|
||||
cb = encoder->callbacks.array+(i-1);
|
||||
send_packet(encoder, cb, pkt);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&encoder->callbacks_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
static const char *do_encode_name = "do_encode";
|
||||
static inline void do_encode(struct obs_encoder *encoder,
|
||||
struct encoder_frame *frame)
|
||||
bool do_encode(struct obs_encoder *encoder, struct encoder_frame *frame)
|
||||
{
|
||||
profile_start(do_encode_name);
|
||||
if (!encoder->profile_encoder_encode_name)
|
||||
|
|
@ -798,38 +915,11 @@ static inline void do_encode(struct obs_encoder *encoder,
|
|||
success = encoder->info.encode(encoder->context.data, frame, &pkt,
|
||||
&received);
|
||||
profile_end(encoder->profile_encoder_encode_name);
|
||||
if (!success) {
|
||||
full_stop(encoder);
|
||||
blog(LOG_ERROR, "Error encoding with encoder '%s'",
|
||||
encoder->context.name);
|
||||
goto error;
|
||||
}
|
||||
send_off_encoder_packet(encoder, success, received, &pkt);
|
||||
|
||||
if (received) {
|
||||
if (!encoder->first_received) {
|
||||
encoder->offset_usec = packet_dts_usec(&pkt);
|
||||
encoder->first_received = true;
|
||||
}
|
||||
|
||||
/* we use system time here to ensure sync with other encoders,
|
||||
* you do not want to use relative timestamps here */
|
||||
pkt.dts_usec = encoder->start_ts / 1000 +
|
||||
packet_dts_usec(&pkt) - encoder->offset_usec;
|
||||
pkt.sys_dts_usec = pkt.dts_usec;
|
||||
|
||||
pthread_mutex_lock(&encoder->callbacks_mutex);
|
||||
|
||||
for (size_t i = encoder->callbacks.num; i > 0; i--) {
|
||||
struct encoder_callback *cb;
|
||||
cb = encoder->callbacks.array+(i-1);
|
||||
send_packet(encoder, cb, &pkt);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&encoder->callbacks_mutex);
|
||||
}
|
||||
|
||||
error:
|
||||
profile_end(do_encode_name);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static const char *receive_video_name = "receive_video";
|
||||
|
|
@ -861,9 +951,8 @@ static void receive_video(void *param, struct video_data *frame)
|
|||
enc_frame.frames = 1;
|
||||
enc_frame.pts = encoder->cur_pts;
|
||||
|
||||
do_encode(encoder, &enc_frame);
|
||||
|
||||
encoder->cur_pts += encoder->timebase_num;
|
||||
if (do_encode(encoder, &enc_frame))
|
||||
encoder->cur_pts += encoder->timebase_num;
|
||||
|
||||
wait_for_audio:
|
||||
profile_end(receive_video_name);
|
||||
|
|
@ -971,7 +1060,7 @@ fail:
|
|||
return success;
|
||||
}
|
||||
|
||||
static void send_audio_data(struct obs_encoder *encoder)
|
||||
static bool send_audio_data(struct obs_encoder *encoder)
|
||||
{
|
||||
struct encoder_frame enc_frame;
|
||||
|
||||
|
|
@ -989,9 +1078,11 @@ static void send_audio_data(struct obs_encoder *encoder)
|
|||
enc_frame.frames = (uint32_t)encoder->framesize;
|
||||
enc_frame.pts = encoder->cur_pts;
|
||||
|
||||
do_encode(encoder, &enc_frame);
|
||||
if (!do_encode(encoder, &enc_frame))
|
||||
return false;
|
||||
|
||||
encoder->cur_pts += encoder->framesize;
|
||||
return true;
|
||||
}
|
||||
|
||||
static const char *receive_audio_name = "receive_audio";
|
||||
|
|
@ -1010,8 +1101,11 @@ static void receive_audio(void *param, size_t mix_idx, struct audio_data *data)
|
|||
if (!buffer_audio(encoder, data))
|
||||
goto end;
|
||||
|
||||
while (encoder->audio_input_buffer[0].size >= encoder->framesize_bytes)
|
||||
send_audio_data(encoder);
|
||||
while (encoder->audio_input_buffer[0].size >= encoder->framesize_bytes) {
|
||||
if (!send_audio_data(encoder)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UNUSED_PARAMETER(mix_idx);
|
||||
|
||||
|
|
@ -1186,13 +1280,13 @@ bool obs_weak_encoder_references_encoder(obs_weak_encoder_t *weak,
|
|||
void *obs_encoder_get_type_data(obs_encoder_t *encoder)
|
||||
{
|
||||
return obs_encoder_valid(encoder, "obs_encoder_get_type_data")
|
||||
? encoder->info.type_data : NULL;
|
||||
? encoder->orig_info.type_data : NULL;
|
||||
}
|
||||
|
||||
const char *obs_encoder_get_id(const obs_encoder_t *encoder)
|
||||
{
|
||||
return obs_encoder_valid(encoder, "obs_encoder_get_id")
|
||||
? encoder->info.id : NULL;
|
||||
? encoder->orig_info.id : NULL;
|
||||
}
|
||||
|
||||
uint32_t obs_get_encoder_caps(const char *encoder_id)
|
||||
|
|
@ -1200,3 +1294,9 @@ uint32_t obs_get_encoder_caps(const char *encoder_id)
|
|||
struct obs_encoder_info *info = find_encoder(encoder_id);
|
||||
return info ? info->caps : 0;
|
||||
}
|
||||
|
||||
uint32_t obs_encoder_get_caps(const obs_encoder_t *encoder)
|
||||
{
|
||||
return obs_encoder_valid(encoder, "obs_encoder_get_caps")
|
||||
? encoder->orig_info.caps : 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#define OBS_ENCODER_CAP_DEPRECATED (1<<0)
|
||||
#define OBS_ENCODER_CAP_PASS_TEXTURE (1<<1)
|
||||
|
||||
/** Specifies the encoder type */
|
||||
enum obs_encoder_type {
|
||||
|
|
@ -234,6 +235,27 @@ struct obs_encoder_info {
|
|||
void (*free_type_data)(void *type_data);
|
||||
|
||||
uint32_t caps;
|
||||
|
||||
/**
|
||||
* Gets the default settings for this encoder
|
||||
*
|
||||
* @param[out] settings Data to assign default settings to
|
||||
* @param[in] typedata Type Data
|
||||
*/
|
||||
void (*get_defaults2)(obs_data_t *settings, void *type_data);
|
||||
|
||||
/**
|
||||
* Gets the property information of this encoder
|
||||
*
|
||||
* @param[in] data Pointer from create (or null)
|
||||
* @param[in] typedata Type Data
|
||||
* @return The properties data
|
||||
*/
|
||||
obs_properties_t *(*get_properties2)(void *data, void *type_data);
|
||||
|
||||
bool (*encode_texture)(void *data, uint32_t handle, int64_t pts,
|
||||
uint64_t lock_key, uint64_t *next_key,
|
||||
struct encoder_packet *packet, bool *received_packet);
|
||||
};
|
||||
|
||||
EXPORT void obs_register_encoder_s(const struct obs_encoder_info *info,
|
||||
|
|
|
|||
|
|
@ -1479,6 +1479,7 @@ void obs_hotkeys_set_translations_s(
|
|||
ADD_TRANSLATION(OBS_KEY_META, meta);
|
||||
ADD_TRANSLATION(OBS_KEY_MENU, menu);
|
||||
ADD_TRANSLATION(OBS_KEY_SPACE, space);
|
||||
ADD_TRANSLATION(OBS_KEY_ESCAPE, escape);
|
||||
#ifdef __APPLE__
|
||||
const char *numpad_str = t.apple_keypad_num;
|
||||
ADD_TRANSLATION(OBS_KEY_NUMSLASH, apple_keypad_divide);
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ struct obs_hotkeys_translations {
|
|||
const char *apple_keypad_decimal;
|
||||
const char *apple_keypad_equal;
|
||||
const char *mouse_num; /* For example, "Mouse %1" */
|
||||
const char *escape;
|
||||
};
|
||||
|
||||
/* This function is an optional way to provide translations for specific keys
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@
|
|||
|
||||
#define NUM_TEXTURES 2
|
||||
#define MICROSECOND_DEN 1000000
|
||||
#define NUM_ENCODE_TEXTURES 3
|
||||
#define NUM_ENCODE_TEXTURE_FRAMES_TO_WAIT 1
|
||||
|
||||
static inline int64_t packet_dts_usec(struct encoder_packet *packet)
|
||||
{
|
||||
|
|
@ -225,30 +227,55 @@ struct obs_vframe_info {
|
|||
int count;
|
||||
};
|
||||
|
||||
struct obs_tex_frame {
|
||||
gs_texture_t *tex;
|
||||
gs_texture_t *tex_uv;
|
||||
uint32_t handle;
|
||||
uint64_t timestamp;
|
||||
uint64_t lock_key;
|
||||
int count;
|
||||
bool released;
|
||||
};
|
||||
|
||||
struct obs_core_video {
|
||||
graphics_t *graphics;
|
||||
gs_stagesurf_t *copy_surfaces[NUM_TEXTURES];
|
||||
gs_texture_t *render_textures[NUM_TEXTURES];
|
||||
gs_texture_t *output_textures[NUM_TEXTURES];
|
||||
gs_texture_t *convert_textures[NUM_TEXTURES];
|
||||
gs_texture_t *convert_uv_textures[NUM_TEXTURES];
|
||||
bool textures_rendered[NUM_TEXTURES];
|
||||
bool textures_output[NUM_TEXTURES];
|
||||
bool textures_copied[NUM_TEXTURES];
|
||||
bool textures_converted[NUM_TEXTURES];
|
||||
bool using_nv12_tex;
|
||||
struct circlebuf vframe_info_buffer;
|
||||
struct circlebuf vframe_info_buffer_gpu;
|
||||
gs_effect_t *default_effect;
|
||||
gs_effect_t *default_rect_effect;
|
||||
gs_effect_t *opaque_effect;
|
||||
gs_effect_t *solid_effect;
|
||||
gs_effect_t *repeat_effect;
|
||||
gs_effect_t *conversion_effect;
|
||||
gs_effect_t *bicubic_effect;
|
||||
gs_effect_t *lanczos_effect;
|
||||
gs_effect_t *area_effect;
|
||||
gs_effect_t *bilinear_lowres_effect;
|
||||
gs_effect_t *premultiplied_alpha_effect;
|
||||
gs_samplerstate_t *point_sampler;
|
||||
gs_stagesurf_t *mapped_surface;
|
||||
int cur_texture;
|
||||
long raw_active;
|
||||
long gpu_encoder_active;
|
||||
pthread_mutex_t gpu_encoder_mutex;
|
||||
struct circlebuf gpu_encoder_queue;
|
||||
struct circlebuf gpu_encoder_avail_queue;
|
||||
DARRAY(obs_encoder_t *) gpu_encoders;
|
||||
os_sem_t *gpu_encode_semaphore;
|
||||
os_event_t *gpu_encode_inactive;
|
||||
pthread_t gpu_encode_thread;
|
||||
bool gpu_encode_thread_initialized;
|
||||
volatile bool gpu_encode_stop;
|
||||
|
||||
uint64_t video_time;
|
||||
uint64_t video_avg_frame_time_ns;
|
||||
|
|
@ -608,6 +635,7 @@ struct obs_source {
|
|||
float volume;
|
||||
int64_t sync_offset;
|
||||
int64_t last_sync_offset;
|
||||
float balance;
|
||||
|
||||
/* async video data */
|
||||
gs_texture_t *async_texture;
|
||||
|
|
@ -615,12 +643,10 @@ struct obs_source {
|
|||
struct obs_source_frame *cur_async_frame;
|
||||
bool async_gpu_conversion;
|
||||
enum video_format async_format;
|
||||
enum video_format async_cache_format;
|
||||
enum gs_color_format async_texture_format;
|
||||
float async_color_matrix[16];
|
||||
bool async_full_range;
|
||||
float async_color_range_min[3];
|
||||
float async_color_range_max[3];
|
||||
enum video_format async_cache_format;
|
||||
bool async_cache_full_range;
|
||||
enum gs_color_format async_texture_format;
|
||||
int async_plane_offset[2];
|
||||
bool async_flip;
|
||||
bool async_active;
|
||||
|
|
@ -816,6 +842,7 @@ struct obs_weak_output {
|
|||
#define CAPTION_LINE_BYTES (4*CAPTION_LINE_CHARS)
|
||||
struct caption_text {
|
||||
char text[CAPTION_LINE_BYTES+1];
|
||||
double display_duration;
|
||||
struct caption_text *next;
|
||||
};
|
||||
|
||||
|
|
@ -862,7 +889,7 @@ struct obs_output {
|
|||
obs_encoder_t *video_encoder;
|
||||
obs_encoder_t *audio_encoders[MAX_AUDIO_MIXES];
|
||||
obs_service_t *service;
|
||||
size_t mixer_idx;
|
||||
size_t mixer_mask;
|
||||
|
||||
uint32_t scaled_width;
|
||||
uint32_t scaled_height;
|
||||
|
|
@ -939,6 +966,9 @@ struct obs_encoder {
|
|||
struct obs_encoder_info info;
|
||||
struct obs_weak_encoder *control;
|
||||
|
||||
/* allows re-routing to another encoder */
|
||||
struct obs_encoder_info orig_info;
|
||||
|
||||
pthread_mutex_t init_mutex;
|
||||
|
||||
uint32_t samplerate;
|
||||
|
|
@ -1009,6 +1039,13 @@ extern void obs_encoder_add_output(struct obs_encoder *encoder,
|
|||
extern void obs_encoder_remove_output(struct obs_encoder *encoder,
|
||||
struct obs_output *output);
|
||||
|
||||
extern bool start_gpu_encode(obs_encoder_t *encoder);
|
||||
extern void stop_gpu_encode(obs_encoder_t *encoder);
|
||||
|
||||
extern bool do_encode(struct obs_encoder *encoder, struct encoder_frame *frame);
|
||||
extern void send_off_encoder_packet(obs_encoder_t *encoder, bool success,
|
||||
bool received, struct encoder_packet *pkt);
|
||||
|
||||
void obs_encoder_destroy(obs_encoder_t *encoder);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ extern const char *get_module_extension(void);
|
|||
|
||||
static inline int req_func_not_found(const char *name, const char *path)
|
||||
{
|
||||
blog(LOG_ERROR, "Required module function '%s' in module '%s' not "
|
||||
blog(LOG_DEBUG, "Required module function '%s' in module '%s' not "
|
||||
"found, loading of module failed",
|
||||
name, path);
|
||||
return MODULE_MISSING_EXPORTS;
|
||||
|
|
@ -675,9 +675,15 @@ void obs_register_output_s(const struct obs_output_info *info, size_t size)
|
|||
CHECK_REQUIRED_VAL_(info, raw_video,
|
||||
obs_register_output);
|
||||
|
||||
if (info->flags & OBS_OUTPUT_AUDIO)
|
||||
CHECK_REQUIRED_VAL_(info, raw_audio,
|
||||
obs_register_output);
|
||||
if (info->flags & OBS_OUTPUT_AUDIO) {
|
||||
if (info->flags & OBS_OUTPUT_MULTI_TRACK) {
|
||||
CHECK_REQUIRED_VAL_(info, raw_audio2,
|
||||
obs_register_output);
|
||||
} else {
|
||||
CHECK_REQUIRED_VAL_(info, raw_audio,
|
||||
obs_register_output);
|
||||
}
|
||||
}
|
||||
}
|
||||
#undef CHECK_REQUIRED_VAL_
|
||||
|
||||
|
|
@ -701,7 +707,11 @@ void obs_register_encoder_s(const struct obs_encoder_info *info, size_t size)
|
|||
CHECK_REQUIRED_VAL_(info, get_name, obs_register_encoder);
|
||||
CHECK_REQUIRED_VAL_(info, create, obs_register_encoder);
|
||||
CHECK_REQUIRED_VAL_(info, destroy, obs_register_encoder);
|
||||
CHECK_REQUIRED_VAL_(info, encode, obs_register_encoder);
|
||||
|
||||
if ((info->caps & OBS_ENCODER_CAP_PASS_TEXTURE) != 0)
|
||||
CHECK_REQUIRED_VAL_(info, encode_texture, obs_register_encoder);
|
||||
else
|
||||
CHECK_REQUIRED_VAL_(info, encode, obs_register_encoder);
|
||||
|
||||
if (info->type == OBS_ENCODER_AUDIO)
|
||||
CHECK_REQUIRED_VAL_(info, get_frame_size, obs_register_encoder);
|
||||
|
|
|
|||
|
|
@ -422,6 +422,17 @@ static int get_keysym(obs_key_t key)
|
|||
case OBS_KEY_F22: return XK_F22;
|
||||
case OBS_KEY_F23: return XK_F23;
|
||||
case OBS_KEY_F24: return XK_F24;
|
||||
case OBS_KEY_F25: return XK_F25;
|
||||
case OBS_KEY_F26: return XK_F26;
|
||||
case OBS_KEY_F27: return XK_F27;
|
||||
case OBS_KEY_F28: return XK_F28;
|
||||
case OBS_KEY_F29: return XK_F29;
|
||||
case OBS_KEY_F30: return XK_F30;
|
||||
case OBS_KEY_F31: return XK_F31;
|
||||
case OBS_KEY_F32: return XK_F32;
|
||||
case OBS_KEY_F33: return XK_F33;
|
||||
case OBS_KEY_F34: return XK_F34;
|
||||
case OBS_KEY_F35: return XK_F35;
|
||||
|
||||
case OBS_KEY_MENU: return XK_Menu;
|
||||
case OBS_KEY_HYPER_L: return XK_Hyper_L;
|
||||
|
|
@ -1114,6 +1125,8 @@ void obs_key_to_str(obs_key_t key, struct dstr *dstr)
|
|||
case OBS_KEY_NUMCOMMA: return translate_key(key, "Numpad ,");
|
||||
case OBS_KEY_NUMPERIOD: return translate_key(key, "Numpad .");
|
||||
case OBS_KEY_NUMSLASH: return translate_key(key, "Numpad /");
|
||||
case OBS_KEY_SPACE: return translate_key(key, "Space");
|
||||
case OBS_KEY_ESCAPE: return translate_key(key, "Escape");
|
||||
default:;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -255,13 +255,17 @@ bool obs_output_actual_start(obs_output_t *output)
|
|||
bool obs_output_start(obs_output_t *output)
|
||||
{
|
||||
bool encoded;
|
||||
bool has_service;
|
||||
if (!obs_output_valid(output, "obs_output_start"))
|
||||
return false;
|
||||
if (!output->context.data)
|
||||
return false;
|
||||
|
||||
encoded = (output->info.flags & OBS_OUTPUT_ENCODED) != 0;
|
||||
has_service = (output->info.flags & OBS_OUTPUT_SERVICE) != 0;
|
||||
if (has_service && !obs_service_initialize(output->service, output))
|
||||
return false;
|
||||
|
||||
encoded = (output->info.flags & OBS_OUTPUT_ENCODED) != 0;
|
||||
if (encoded && output->delay_sec) {
|
||||
return obs_output_delay_start(output);
|
||||
} else {
|
||||
|
|
@ -544,19 +548,46 @@ audio_t *obs_output_audio(const obs_output_t *output)
|
|||
output->audio : NULL;
|
||||
}
|
||||
|
||||
static inline size_t get_first_mixer(const obs_output_t *output)
|
||||
{
|
||||
for (size_t i = 0; i < MAX_AUDIO_MIXES; i++) {
|
||||
if ((((size_t)1 << i) & output->mixer_mask) != 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void obs_output_set_mixer(obs_output_t *output, size_t mixer_idx)
|
||||
{
|
||||
if (!obs_output_valid(output, "obs_output_set_mixer"))
|
||||
return;
|
||||
|
||||
if (!active(output))
|
||||
output->mixer_idx = mixer_idx;
|
||||
output->mixer_mask = (size_t)1 << mixer_idx;
|
||||
}
|
||||
|
||||
size_t obs_output_get_mixer(const obs_output_t *output)
|
||||
{
|
||||
return obs_output_valid(output, "obs_output_get_mixer") ?
|
||||
output->mixer_idx : 0;
|
||||
if (!obs_output_valid(output, "obs_output_get_mixer"))
|
||||
return 0;
|
||||
|
||||
return get_first_mixer(output);
|
||||
}
|
||||
|
||||
void obs_output_set_mixers(obs_output_t *output, size_t mixers)
|
||||
{
|
||||
if (!obs_output_valid(output, "obs_output_set_mixers"))
|
||||
return;
|
||||
|
||||
output->mixer_mask = mixers;
|
||||
}
|
||||
|
||||
size_t obs_output_get_mixers(const obs_output_t *output)
|
||||
{
|
||||
return obs_output_valid(output, "obs_output_get_mixers") ?
|
||||
output->mixer_mask : 0;
|
||||
}
|
||||
|
||||
void obs_output_remove_encoder(struct obs_output *output,
|
||||
|
|
@ -1043,17 +1074,18 @@ static inline void send_interleaved(struct obs_output *output)
|
|||
double frame_timestamp = (out.pts * out.timebase_num) /
|
||||
(double)out.timebase_den;
|
||||
|
||||
/* TODO if output->caption_timestamp is more than 5 seconds
|
||||
* old, send empty frame */
|
||||
if (output->caption_head &&
|
||||
output->caption_timestamp <= frame_timestamp) {
|
||||
blog(LOG_INFO,"Sending caption: %f \"%s\"",
|
||||
blog(LOG_DEBUG,"Sending caption: %f \"%s\"",
|
||||
frame_timestamp,
|
||||
&output->caption_head->text[0]);
|
||||
|
||||
double display_duration =
|
||||
output->caption_head->display_duration;
|
||||
|
||||
if (add_caption(output, &out)) {
|
||||
output->caption_timestamp =
|
||||
frame_timestamp + 2.0;
|
||||
frame_timestamp + display_duration;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1476,6 +1508,7 @@ static void default_raw_video_callback(void *param, struct video_data *frame)
|
|||
output->total_frames++;
|
||||
}
|
||||
|
||||
|
||||
static void default_raw_audio_callback(void *param, size_t mix_idx,
|
||||
struct audio_data *frames)
|
||||
{
|
||||
|
|
@ -1483,9 +1516,10 @@ static void default_raw_audio_callback(void *param, size_t mix_idx,
|
|||
if (!data_active(output))
|
||||
return;
|
||||
|
||||
output->info.raw_audio(output->context.data, frames);
|
||||
|
||||
UNUSED_PARAMETER(mix_idx);
|
||||
if (output->info.raw_audio2)
|
||||
output->info.raw_audio2(output->context.data, mix_idx, frames);
|
||||
else
|
||||
output->info.raw_audio(output->context.data, frames);
|
||||
}
|
||||
|
||||
static inline void start_audio_encoders(struct obs_output *output,
|
||||
|
|
@ -1499,6 +1533,25 @@ static inline void start_audio_encoders(struct obs_output *output,
|
|||
}
|
||||
}
|
||||
|
||||
static inline void start_raw_audio(obs_output_t *output)
|
||||
{
|
||||
if (output->info.raw_audio2) {
|
||||
for (int idx = 0; idx < MAX_AUDIO_MIXES; idx++) {
|
||||
if ((output->mixer_mask & ((size_t)1 << idx)) != 0) {
|
||||
audio_output_connect(output->audio, idx,
|
||||
get_audio_conversion(output),
|
||||
default_raw_audio_callback,
|
||||
output);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
audio_output_connect(output->audio, get_first_mixer(output),
|
||||
get_audio_conversion(output),
|
||||
default_raw_audio_callback,
|
||||
output);
|
||||
}
|
||||
}
|
||||
|
||||
static void reset_packet_data(obs_output_t *output)
|
||||
{
|
||||
output->received_audio = false;
|
||||
|
|
@ -1508,7 +1561,7 @@ static void reset_packet_data(obs_output_t *output)
|
|||
output->video_offset = 0;
|
||||
|
||||
for (size_t i = 0; i < MAX_AUDIO_MIXES; i++)
|
||||
output->audio_offsets[0] = 0;
|
||||
output->audio_offsets[i] = 0;
|
||||
|
||||
free_packets(output);
|
||||
}
|
||||
|
|
@ -1557,9 +1610,7 @@ static void hook_data_capture(struct obs_output *output, bool encoded,
|
|||
get_video_conversion(output),
|
||||
default_raw_video_callback, output);
|
||||
if (has_audio)
|
||||
audio_output_connect(output->audio, output->mixer_idx,
|
||||
get_audio_conversion(output),
|
||||
default_raw_audio_callback, output);
|
||||
start_raw_audio(output);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1653,7 +1704,7 @@ static inline obs_encoder_t *find_inactive_audio_encoder(obs_output_t *output,
|
|||
for (size_t i = 0; i < num_mixes; i++) {
|
||||
struct obs_encoder *audio = output->audio_encoders[i];
|
||||
|
||||
if (!audio->active && !audio->paired_encoder)
|
||||
if (audio && !audio->active && !audio->paired_encoder)
|
||||
return audio;
|
||||
}
|
||||
|
||||
|
|
@ -1700,16 +1751,11 @@ bool obs_output_initialize_encoders(obs_output_t *output, uint32_t flags)
|
|||
|
||||
if (!encoded)
|
||||
return false;
|
||||
if (has_service && !obs_service_initialize(output->service, output))
|
||||
return false;
|
||||
if (has_video && !obs_encoder_initialize(output->video_encoder))
|
||||
return false;
|
||||
if (has_audio && !initialize_audio_encoders(output, num_mixes))
|
||||
return false;
|
||||
|
||||
if (has_video && has_audio)
|
||||
pair_encoders(output, num_mixes);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1736,6 +1782,7 @@ static bool begin_delayed_capture(obs_output_t *output)
|
|||
bool obs_output_begin_data_capture(obs_output_t *output, uint32_t flags)
|
||||
{
|
||||
bool encoded, has_video, has_audio, has_service;
|
||||
size_t num_mixes;
|
||||
|
||||
if (!obs_output_valid(output, "obs_output_begin_data_capture"))
|
||||
return false;
|
||||
|
|
@ -1752,6 +1799,10 @@ bool obs_output_begin_data_capture(obs_output_t *output, uint32_t flags)
|
|||
has_service))
|
||||
return false;
|
||||
|
||||
num_mixes = num_audio_mixes(output);
|
||||
if (has_video && has_audio)
|
||||
pair_encoders(output, num_mixes);
|
||||
|
||||
os_atomic_set_bool(&output->data_active, true);
|
||||
hook_data_capture(output, encoded, has_video, has_audio);
|
||||
|
||||
|
|
@ -1786,6 +1837,25 @@ static inline void stop_audio_encoders(obs_output_t *output,
|
|||
}
|
||||
}
|
||||
|
||||
static inline void stop_raw_audio(obs_output_t *output)
|
||||
{
|
||||
if (output->info.raw_audio2) {
|
||||
for (int idx = 0; idx < MAX_AUDIO_MIXES; idx++) {
|
||||
if ((output->mixer_mask & ((size_t)1 << idx)) != 0) {
|
||||
audio_output_disconnect(output->audio,
|
||||
idx,
|
||||
default_raw_audio_callback,
|
||||
output);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
audio_output_disconnect(output->audio,
|
||||
get_first_mixer(output),
|
||||
default_raw_audio_callback,
|
||||
output);
|
||||
}
|
||||
}
|
||||
|
||||
static void *end_data_capture_thread(void *data)
|
||||
{
|
||||
bool encoded, has_video, has_audio, has_service;
|
||||
|
|
@ -1812,9 +1882,7 @@ static void *end_data_capture_thread(void *data)
|
|||
stop_raw_video(output->video,
|
||||
default_raw_video_callback, output);
|
||||
if (has_audio)
|
||||
audio_output_disconnect(output->audio,
|
||||
output->mixer_idx,
|
||||
default_raw_audio_callback, output);
|
||||
stop_raw_audio(output);
|
||||
}
|
||||
|
||||
if (has_service)
|
||||
|
|
@ -2070,11 +2138,13 @@ const char *obs_output_get_id(const obs_output_t *output)
|
|||
|
||||
#if BUILD_CAPTIONS
|
||||
static struct caption_text *caption_text_new(const char *text, size_t bytes,
|
||||
struct caption_text *tail, struct caption_text **head)
|
||||
struct caption_text *tail, struct caption_text **head,
|
||||
double display_duration)
|
||||
{
|
||||
struct caption_text *next = bzalloc(sizeof(struct caption_text));
|
||||
snprintf(&next->text[0], CAPTION_LINE_BYTES + 1, "%.*s",
|
||||
(int)bytes, text);
|
||||
next->display_duration = display_duration;
|
||||
|
||||
if (!*head) {
|
||||
*head = next;
|
||||
|
|
@ -2089,6 +2159,14 @@ void obs_output_output_caption_text1(obs_output_t *output, const char *text)
|
|||
{
|
||||
if (!obs_output_valid(output, "obs_output_output_caption_text1"))
|
||||
return;
|
||||
obs_output_output_caption_text2(output, text, 2.0f);
|
||||
}
|
||||
|
||||
void obs_output_output_caption_text2(obs_output_t *output, const char *text,
|
||||
double display_duration)
|
||||
{
|
||||
if (!obs_output_valid(output, "obs_output_output_caption_text2"))
|
||||
return;
|
||||
if (!active(output))
|
||||
return;
|
||||
|
||||
|
|
@ -2101,7 +2179,8 @@ void obs_output_output_caption_text1(obs_output_t *output, const char *text)
|
|||
output->caption_tail = caption_text_new(
|
||||
text, size,
|
||||
output->caption_tail,
|
||||
&output->caption_head);
|
||||
&output->caption_head,
|
||||
display_duration);
|
||||
|
||||
pthread_mutex_unlock(&output->caption_mutex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,9 @@ struct obs_output_info {
|
|||
/* only used with encoded outputs, separated with semicolon */
|
||||
const char *encoded_video_codecs;
|
||||
const char *encoded_audio_codecs;
|
||||
|
||||
/* raw audio callback for multi track outputs */
|
||||
void (*raw_audio2)(void *data, size_t idx, struct audio_data *frames);
|
||||
};
|
||||
|
||||
EXPORT void obs_register_output_s(const struct obs_output_info *info,
|
||||
|
|
|
|||
|
|
@ -27,11 +27,13 @@ static inline void *get_property_data(struct obs_property *prop);
|
|||
struct float_data {
|
||||
double min, max, step;
|
||||
enum obs_number_type type;
|
||||
char *suffix;
|
||||
};
|
||||
|
||||
struct int_data {
|
||||
int min, max, step;
|
||||
enum obs_number_type type;
|
||||
char *suffix;
|
||||
};
|
||||
|
||||
struct list_item {
|
||||
|
|
@ -86,6 +88,11 @@ struct frame_rate_data {
|
|||
DARRAY(struct frame_rate_range) ranges;
|
||||
};
|
||||
|
||||
struct group_data {
|
||||
enum obs_group_type type;
|
||||
obs_properties_t *content;
|
||||
};
|
||||
|
||||
static inline void path_data_free(struct path_data *data)
|
||||
{
|
||||
bfree(data->default_path);
|
||||
|
|
@ -140,6 +147,20 @@ static inline void frame_rate_data_free(struct frame_rate_data *data)
|
|||
da_free(data->ranges);
|
||||
}
|
||||
|
||||
static inline void group_data_free(struct group_data *data) {
|
||||
obs_properties_destroy(data->content);
|
||||
}
|
||||
|
||||
static inline void int_data_free(struct int_data *data) {
|
||||
if (data->suffix)
|
||||
bfree(data->suffix);
|
||||
}
|
||||
|
||||
static inline void float_data_free(struct float_data *data) {
|
||||
if (data->suffix)
|
||||
bfree(data->suffix);
|
||||
}
|
||||
|
||||
struct obs_properties;
|
||||
|
||||
struct obs_property {
|
||||
|
|
@ -166,6 +187,7 @@ struct obs_properties {
|
|||
|
||||
struct obs_property *first_property;
|
||||
struct obs_property **last;
|
||||
struct obs_property *parent;
|
||||
};
|
||||
|
||||
obs_properties_t *obs_properties_create(void)
|
||||
|
|
@ -223,6 +245,12 @@ static void obs_property_destroy(struct obs_property *property)
|
|||
editable_list_data_free(get_property_data(property));
|
||||
else if (property->type == OBS_PROPERTY_FRAME_RATE)
|
||||
frame_rate_data_free(get_property_data(property));
|
||||
else if (property->type == OBS_PROPERTY_GROUP)
|
||||
group_data_free(get_property_data(property));
|
||||
else if (property->type == OBS_PROPERTY_INT)
|
||||
int_data_free(get_property_data(property));
|
||||
else if (property->type == OBS_PROPERTY_FLOAT)
|
||||
float_data_free(get_property_data(property));
|
||||
|
||||
bfree(property->name);
|
||||
bfree(property->desc);
|
||||
|
|
@ -265,12 +293,51 @@ obs_property_t *obs_properties_get(obs_properties_t *props, const char *name)
|
|||
if (strcmp(property->name, name) == 0)
|
||||
return property;
|
||||
|
||||
if (property->type == OBS_PROPERTY_GROUP) {
|
||||
obs_properties_t *group =
|
||||
obs_property_group_content(property);
|
||||
obs_property_t *found = obs_properties_get(group, name);
|
||||
if (found != NULL) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
property = property->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
obs_properties_t *obs_properties_get_parent(obs_properties_t *props)
|
||||
{
|
||||
return props->parent ? props->parent->parent : NULL;
|
||||
}
|
||||
|
||||
void obs_properties_remove_by_name(obs_properties_t *props, const char *name)
|
||||
{
|
||||
if (!props)
|
||||
return;
|
||||
|
||||
/* obs_properties_t is a forward-linked-list, so we need to keep both
|
||||
* previous and current pointers around. That way we can fix up the
|
||||
* pointers for the previous element if we find a match.
|
||||
*/
|
||||
struct obs_property *cur = props->first_property;
|
||||
struct obs_property *prev = props->first_property;
|
||||
|
||||
while (cur) {
|
||||
if (strcmp(cur->name, name) == 0) {
|
||||
prev->next = cur->next;
|
||||
cur->next = 0;
|
||||
obs_property_destroy(cur);
|
||||
break;
|
||||
}
|
||||
|
||||
prev = cur;
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
|
||||
void obs_properties_apply_settings(obs_properties_t *props, obs_data_t *settings)
|
||||
{
|
||||
struct obs_property *p;
|
||||
|
|
@ -313,6 +380,7 @@ static inline size_t get_property_size(enum obs_property_type type)
|
|||
case OBS_PROPERTY_EDITABLE_LIST:
|
||||
return sizeof(struct editable_list_data);
|
||||
case OBS_PROPERTY_FRAME_RATE:return sizeof(struct frame_rate_data);
|
||||
case OBS_PROPERTY_GROUP: return sizeof(struct group_data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -337,7 +405,18 @@ static inline struct obs_property *new_prop(struct obs_properties *props,
|
|||
return p;
|
||||
}
|
||||
|
||||
static inline bool has_prop(struct obs_properties *props, const char *name)
|
||||
static inline obs_properties_t *get_topmost_parent(obs_properties_t *props)
|
||||
{
|
||||
obs_properties_t *parent = props;
|
||||
obs_properties_t *last_parent = parent;
|
||||
while (parent) {
|
||||
last_parent = parent;
|
||||
parent = obs_properties_get_parent(parent);
|
||||
}
|
||||
return last_parent;
|
||||
}
|
||||
|
||||
static inline bool contains_prop(struct obs_properties *props, const char *name)
|
||||
{
|
||||
struct obs_property *p = props->first_property;
|
||||
|
||||
|
|
@ -347,12 +426,23 @@ static inline bool has_prop(struct obs_properties *props, const char *name)
|
|||
return true;
|
||||
}
|
||||
|
||||
if (p->type == OBS_PROPERTY_GROUP) {
|
||||
if (contains_prop(obs_property_group_content(p), name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool has_prop(struct obs_properties *props, const char *name)
|
||||
{
|
||||
return contains_prop(get_topmost_parent(props), name);
|
||||
}
|
||||
|
||||
static inline void *get_property_data(struct obs_property *prop)
|
||||
{
|
||||
return (uint8_t*)prop + sizeof(struct obs_property);
|
||||
|
|
@ -553,6 +643,70 @@ obs_property_t *obs_properties_add_frame_rate(obs_properties_t *props,
|
|||
return p;
|
||||
}
|
||||
|
||||
static bool check_property_group_recursion(obs_properties_t *parent,
|
||||
obs_properties_t *group)
|
||||
{
|
||||
/* Scan the group for the parent. */
|
||||
obs_property_t *current_property = group->first_property;
|
||||
while (current_property) {
|
||||
if (current_property->type == OBS_PROPERTY_GROUP) {
|
||||
obs_properties_t *cprops =
|
||||
obs_property_group_content(current_property);
|
||||
if (cprops == parent) {
|
||||
/* Contains find_props */
|
||||
return true;
|
||||
} else if (cprops == group) {
|
||||
/* Contains self, shouldn't be possible but
|
||||
* lets verify anyway. */
|
||||
return true;
|
||||
}
|
||||
check_property_group_recursion(cprops, group);
|
||||
}
|
||||
|
||||
current_property = current_property->next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool check_property_group_duplicates(obs_properties_t *parent,
|
||||
obs_properties_t *group)
|
||||
{
|
||||
obs_property_t *current_property = group->first_property;
|
||||
while (current_property) {
|
||||
if (has_prop(parent, current_property->name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
current_property = current_property->next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
obs_property_t *obs_properties_add_group(obs_properties_t *props,
|
||||
const char *name, const char *desc, enum obs_group_type type,
|
||||
obs_properties_t *group)
|
||||
{
|
||||
if (!props || has_prop(props, name)) return NULL;
|
||||
if (!group) return NULL;
|
||||
|
||||
/* Prevent recursion. */
|
||||
if (props == group) return NULL;
|
||||
if (check_property_group_recursion(props, group)) return NULL;
|
||||
|
||||
/* Prevent duplicate properties */
|
||||
if (check_property_group_duplicates(props, group)) return NULL;
|
||||
|
||||
obs_property_t *p = new_prop(props, name, desc, OBS_PROPERTY_GROUP);
|
||||
group->parent = p;
|
||||
|
||||
struct group_data *data = get_property_data(p);
|
||||
data->type = type;
|
||||
data->content = group;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
static inline bool is_combo(struct obs_property *p)
|
||||
|
|
@ -605,9 +759,11 @@ bool obs_property_modified(obs_property_t *p, obs_data_t *settings)
|
|||
{
|
||||
if (p) {
|
||||
if (p->modified) {
|
||||
return p->modified(p->parent, p, settings);
|
||||
obs_properties_t *top = get_topmost_parent(p->parent);
|
||||
return p->modified(top, p, settings);
|
||||
} else if (p->modified2) {
|
||||
return p->modified2(p->priv, p->parent, p, settings);
|
||||
obs_properties_t *top = get_topmost_parent(p->parent);
|
||||
return p->modified2(p->priv, top, p, settings);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -620,9 +776,10 @@ bool obs_property_button_clicked(obs_property_t *p, void *obj)
|
|||
struct button_data *data = get_type_data(p,
|
||||
OBS_PROPERTY_BUTTON);
|
||||
if (data && data->callback) {
|
||||
obs_properties_t *top = get_topmost_parent(p->parent);
|
||||
if (p->priv)
|
||||
return data->callback(p->parent, p, p->priv);
|
||||
return data->callback(p->parent, p,
|
||||
return data->callback(top, p, p->priv);
|
||||
return data->callback(top, p,
|
||||
(context ? context->data : NULL));
|
||||
}
|
||||
}
|
||||
|
|
@ -714,6 +871,12 @@ enum obs_number_type obs_property_int_type(obs_property_t *p)
|
|||
return data ? data->type : OBS_NUMBER_SCROLLER;
|
||||
}
|
||||
|
||||
const char *obs_property_int_suffix(obs_property_t *p)
|
||||
{
|
||||
struct int_data *data = get_type_data(p, OBS_PROPERTY_INT);
|
||||
return data ? data->suffix : NULL;
|
||||
}
|
||||
|
||||
double obs_property_float_min(obs_property_t *p)
|
||||
{
|
||||
struct float_data *data = get_type_data(p, OBS_PROPERTY_FLOAT);
|
||||
|
|
@ -732,6 +895,12 @@ double obs_property_float_step(obs_property_t *p)
|
|||
return data ? data->step : 0;
|
||||
}
|
||||
|
||||
const char *obs_property_float_suffix(obs_property_t *p)
|
||||
{
|
||||
struct float_data *data = get_type_data(p, OBS_PROPERTY_FLOAT);
|
||||
return data ? data->suffix : NULL;
|
||||
}
|
||||
|
||||
enum obs_number_type obs_property_float_type(obs_property_t *p)
|
||||
{
|
||||
struct float_data *data = get_type_data(p, OBS_PROPERTY_FLOAT);
|
||||
|
|
@ -789,7 +958,7 @@ void obs_property_int_set_limits(obs_property_t *p,
|
|||
void obs_property_float_set_limits(obs_property_t *p,
|
||||
double min, double max, double step)
|
||||
{
|
||||
struct float_data *data = get_type_data(p, OBS_PROPERTY_INT);
|
||||
struct float_data *data = get_type_data(p, OBS_PROPERTY_FLOAT);
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
|
|
@ -798,6 +967,26 @@ void obs_property_float_set_limits(obs_property_t *p,
|
|||
data->step = step;
|
||||
}
|
||||
|
||||
void obs_property_int_set_suffix(obs_property_t *p, const char *suffix)
|
||||
{
|
||||
struct int_data *data = get_type_data(p, OBS_PROPERTY_INT);
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
bfree(data->suffix);
|
||||
data->suffix = bstrdup(suffix);
|
||||
}
|
||||
|
||||
void obs_property_float_set_suffix(obs_property_t *p, const char *suffix)
|
||||
{
|
||||
struct float_data *data = get_type_data(p, OBS_PROPERTY_FLOAT);
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
bfree(data->suffix);
|
||||
data->suffix = bstrdup(suffix);
|
||||
}
|
||||
|
||||
void obs_property_list_clear(obs_property_t *p)
|
||||
{
|
||||
struct list_data *data = get_list_data(p);
|
||||
|
|
@ -1112,3 +1301,15 @@ enum obs_text_type obs_proprety_text_type(obs_property_t *p)
|
|||
{
|
||||
return obs_property_text_type(p);
|
||||
}
|
||||
|
||||
enum obs_group_type obs_property_group_type(obs_property_t *p)
|
||||
{
|
||||
struct group_data *data = get_type_data(p, OBS_PROPERTY_GROUP);
|
||||
return data ? data->type : OBS_COMBO_INVALID;
|
||||
}
|
||||
|
||||
obs_properties_t *obs_property_group_content(obs_property_t *p)
|
||||
{
|
||||
struct group_data *data = get_type_data(p, OBS_PROPERTY_GROUP);
|
||||
return data ? data->content : NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ enum obs_property_type {
|
|||
OBS_PROPERTY_FONT,
|
||||
OBS_PROPERTY_EDITABLE_LIST,
|
||||
OBS_PROPERTY_FRAME_RATE,
|
||||
OBS_PROPERTY_GROUP,
|
||||
};
|
||||
|
||||
enum obs_combo_format {
|
||||
|
|
@ -93,6 +94,12 @@ enum obs_number_type {
|
|||
OBS_NUMBER_SLIDER
|
||||
};
|
||||
|
||||
enum obs_group_type {
|
||||
OBS_COMBO_INVALID,
|
||||
OBS_GROUP_NORMAL,
|
||||
OBS_GROUP_CHECKABLE,
|
||||
};
|
||||
|
||||
#define OBS_FONT_BOLD (1<<0)
|
||||
#define OBS_FONT_ITALIC (1<<1)
|
||||
#define OBS_FONT_UNDERLINE (1<<2)
|
||||
|
|
@ -122,6 +129,21 @@ EXPORT obs_property_t *obs_properties_first(obs_properties_t *props);
|
|||
EXPORT obs_property_t *obs_properties_get(obs_properties_t *props,
|
||||
const char *property);
|
||||
|
||||
EXPORT obs_properties_t *obs_properties_get_parent(obs_properties_t *props);
|
||||
|
||||
/** Remove a property from a properties list.
|
||||
*
|
||||
* Removes a property from a properties list. Only valid in either
|
||||
* get_properties or modified_callback(2). modified_callback(2) must return
|
||||
* true so that all UI properties are rebuilt and returning false is undefined
|
||||
* behavior.
|
||||
*
|
||||
* @param props Properties to remove from.
|
||||
* @param property Name of the property to remove.
|
||||
*/
|
||||
EXPORT void obs_properties_remove_by_name(obs_properties_t *props,
|
||||
const char *property);
|
||||
|
||||
/**
|
||||
* Applies settings to the properties by calling all the necessary
|
||||
* modification callbacks
|
||||
|
|
@ -218,6 +240,11 @@ EXPORT obs_property_t *obs_properties_add_editable_list(obs_properties_t *props,
|
|||
EXPORT obs_property_t *obs_properties_add_frame_rate(obs_properties_t *props,
|
||||
const char *name, const char *description);
|
||||
|
||||
EXPORT obs_property_t *obs_properties_add_group(obs_properties_t *props,
|
||||
const char *name, const char *description, enum obs_group_type type,
|
||||
obs_properties_t *group);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
|
|
@ -259,10 +286,12 @@ EXPORT int obs_property_int_min(obs_property_t *p);
|
|||
EXPORT int obs_property_int_max(obs_property_t *p);
|
||||
EXPORT int obs_property_int_step(obs_property_t *p);
|
||||
EXPORT enum obs_number_type obs_property_int_type(obs_property_t *p);
|
||||
EXPORT const char * obs_property_int_suffix(obs_property_t *p);
|
||||
EXPORT double obs_property_float_min(obs_property_t *p);
|
||||
EXPORT double obs_property_float_max(obs_property_t *p);
|
||||
EXPORT double obs_property_float_step(obs_property_t *p);
|
||||
EXPORT enum obs_number_type obs_property_float_type(obs_property_t *p);
|
||||
EXPORT const char * obs_property_float_suffix(obs_property_t *p);
|
||||
EXPORT enum obs_text_type obs_property_text_type(obs_property_t *p);
|
||||
EXPORT enum obs_path_type obs_property_path_type(obs_property_t *p);
|
||||
EXPORT const char * obs_property_path_filter(obs_property_t *p);
|
||||
|
|
@ -274,6 +303,8 @@ EXPORT void obs_property_int_set_limits(obs_property_t *p,
|
|||
int min, int max, int step);
|
||||
EXPORT void obs_property_float_set_limits(obs_property_t *p,
|
||||
double min, double max, double step);
|
||||
EXPORT void obs_property_int_set_suffix(obs_property_t *p, const char *suffix);
|
||||
EXPORT void obs_property_float_set_suffix(obs_property_t *p, const char *suffix);
|
||||
|
||||
EXPORT void obs_property_list_clear(obs_property_t *p);
|
||||
|
||||
|
|
@ -336,6 +367,9 @@ EXPORT struct media_frames_per_second obs_property_frame_rate_fps_range_min(
|
|||
EXPORT struct media_frames_per_second obs_property_frame_rate_fps_range_max(
|
||||
obs_property_t *p, size_t idx);
|
||||
|
||||
EXPORT enum obs_group_type obs_property_group_type(obs_property_t *p);
|
||||
EXPORT obs_properties_t *obs_property_group_content(obs_property_t *p);
|
||||
|
||||
#ifndef SWIG
|
||||
DEPRECATED
|
||||
EXPORT enum obs_text_type obs_proprety_text_type(obs_property_t *p);
|
||||
|
|
|
|||
|
|
@ -395,6 +395,8 @@ static void update_item_transform(struct obs_scene_item *item, bool update_tex)
|
|||
scale.y = (float)height * item->scale.y;
|
||||
}
|
||||
|
||||
item->box_scale = scale;
|
||||
|
||||
add_alignment(&base_origin, item->align, (int)scale.x, (int)scale.y);
|
||||
|
||||
matrix4_identity(&item->box_transform);
|
||||
|
|
@ -462,6 +464,8 @@ static inline bool item_texture_enabled(const struct obs_scene_item *item)
|
|||
|
||||
static void render_item_texture(struct obs_scene_item *item)
|
||||
{
|
||||
GS_DEBUG_MARKER_BEGIN(GS_DEBUG_COLOR_ITEM_TEXTURE, "render_item_texture");
|
||||
|
||||
gs_texture_t *tex = gs_texrender_get_texture(item->item_render);
|
||||
gs_effect_t *effect = obs->video.default_effect;
|
||||
enum obs_scale_type type = item->scale_filter;
|
||||
|
|
@ -486,6 +490,8 @@ static void render_item_texture(struct obs_scene_item *item)
|
|||
effect = obs->video.bicubic_effect;
|
||||
} else if (type == OBS_SCALE_LANCZOS) {
|
||||
effect = obs->video.lanczos_effect;
|
||||
} else if (type == OBS_SCALE_AREA) {
|
||||
effect = obs->video.area_effect;
|
||||
}
|
||||
|
||||
scale_param = gs_effect_get_param_by_name(effect,
|
||||
|
|
@ -501,18 +507,29 @@ static void render_item_texture(struct obs_scene_item *item)
|
|||
}
|
||||
}
|
||||
|
||||
gs_blend_state_push();
|
||||
gs_blend_function(GS_BLEND_ONE, GS_BLEND_INVSRCALPHA);
|
||||
|
||||
while (gs_effect_loop(effect, "Draw"))
|
||||
obs_source_draw(tex, 0, 0, 0, 0, 0);
|
||||
|
||||
gs_blend_state_pop();
|
||||
|
||||
GS_DEBUG_MARKER_END();
|
||||
}
|
||||
|
||||
static inline void render_item(struct obs_scene_item *item)
|
||||
{
|
||||
GS_DEBUG_MARKER_BEGIN_FORMAT(GS_DEBUG_COLOR_ITEM, "Item: %s",
|
||||
obs_source_get_name(item->source));
|
||||
|
||||
if (item->item_render) {
|
||||
uint32_t width = obs_source_get_width(item->source);
|
||||
uint32_t height = obs_source_get_height(item->source);
|
||||
|
||||
if (!width || !height)
|
||||
return;
|
||||
if (!width || !height) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
uint32_t cx = calc_cx(item, width);
|
||||
uint32_t cy = calc_cy(item, height);
|
||||
|
|
@ -533,10 +550,8 @@ static inline void render_item(struct obs_scene_item *item)
|
|||
-(float)item->crop.top,
|
||||
0.0f);
|
||||
|
||||
gs_blend_state_push();
|
||||
gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO);
|
||||
obs_source_video_render(item->source);
|
||||
gs_blend_state_pop();
|
||||
|
||||
gs_texrender_end(item->item_render);
|
||||
}
|
||||
}
|
||||
|
|
@ -549,6 +564,9 @@ static inline void render_item(struct obs_scene_item *item)
|
|||
obs_source_video_render(item->source);
|
||||
}
|
||||
gs_matrix_pop();
|
||||
|
||||
cleanup:
|
||||
GS_DEBUG_MARKER_END();
|
||||
}
|
||||
|
||||
static void scene_video_tick(void *data, float seconds)
|
||||
|
|
@ -748,6 +766,8 @@ static void scene_load_item(struct obs_scene *scene, obs_data_t *item_data)
|
|||
item->scale_filter = OBS_SCALE_BICUBIC;
|
||||
else if (astrcmpi(scale_filter_str, "lanczos") == 0)
|
||||
item->scale_filter = OBS_SCALE_LANCZOS;
|
||||
else if (astrcmpi(scale_filter_str, "area") == 0)
|
||||
item->scale_filter = OBS_SCALE_AREA;
|
||||
}
|
||||
|
||||
if (item->item_render && !item_texture_enabled(item)) {
|
||||
|
|
@ -857,6 +877,8 @@ static void scene_save_item(obs_data_array_t *array,
|
|||
scale_filter = "bicubic";
|
||||
else if (item->scale_filter == OBS_SCALE_LANCZOS)
|
||||
scale_filter = "lanczos";
|
||||
else if (item->scale_filter == OBS_SCALE_AREA)
|
||||
scale_filter = "area";
|
||||
else
|
||||
scale_filter = "disable";
|
||||
|
||||
|
|
@ -1243,6 +1265,7 @@ static inline void duplicate_item_data(struct obs_scene_item *dst,
|
|||
dst->output_scale = src->output_scale;
|
||||
dst->scale_filter = src->scale_filter;
|
||||
dst->box_transform = src->box_transform;
|
||||
dst->box_scale = src->box_scale;
|
||||
dst->draw_transform = src->draw_transform;
|
||||
dst->bounds_type = src->bounds_type;
|
||||
dst->bounds_align = src->bounds_align;
|
||||
|
|
@ -2030,6 +2053,13 @@ void obs_sceneitem_get_box_transform(const obs_sceneitem_t *item,
|
|||
matrix4_copy(transform, &item->box_transform);
|
||||
}
|
||||
|
||||
void obs_sceneitem_get_box_scale(const obs_sceneitem_t *item,
|
||||
struct vec2 *scale)
|
||||
{
|
||||
if (item)
|
||||
*scale = item->box_scale;
|
||||
}
|
||||
|
||||
bool obs_sceneitem_visible(const obs_sceneitem_t *item)
|
||||
{
|
||||
return item ? item->user_visible : false;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ struct obs_scene_item {
|
|||
enum obs_scale_type scale_filter;
|
||||
|
||||
struct matrix4 box_transform;
|
||||
struct vec2 box_scale;
|
||||
struct matrix4 draw_transform;
|
||||
|
||||
enum obs_bounds_type bounds_type;
|
||||
|
|
|
|||
|
|
@ -315,9 +315,6 @@ void deinterlace_render(obs_source_t *s)
|
|||
gs_eparam_t *dimensions = gs_effect_get_param_by_name(effect,
|
||||
"dimensions");
|
||||
struct vec2 size = {(float)s->async_width, (float)s->async_height};
|
||||
bool yuv = format_is_yuv(s->async_format);
|
||||
bool limited_range = yuv && !s->async_full_range;
|
||||
const char *tech = yuv ? "DrawMatrix" : "Draw";
|
||||
|
||||
gs_texture_t *cur_tex = s->async_texrender ?
|
||||
gs_texrender_get_texture(s->async_texrender) :
|
||||
|
|
@ -334,30 +331,12 @@ void deinterlace_render(obs_source_t *s)
|
|||
gs_effect_set_int(field, s->deinterlace_top_first);
|
||||
gs_effect_set_vec2(dimensions, &size);
|
||||
|
||||
if (yuv) {
|
||||
gs_eparam_t *color_matrix = gs_effect_get_param_by_name(
|
||||
effect, "color_matrix");
|
||||
gs_effect_set_val(color_matrix, s->async_color_matrix,
|
||||
sizeof(float) * 16);
|
||||
}
|
||||
if (limited_range) {
|
||||
const size_t size = sizeof(float) * 3;
|
||||
gs_eparam_t *color_range_min = gs_effect_get_param_by_name(
|
||||
effect, "color_range_min");
|
||||
gs_eparam_t *color_range_max = gs_effect_get_param_by_name(
|
||||
effect, "color_range_max");
|
||||
gs_effect_set_val(color_range_min, s->async_color_range_min,
|
||||
size);
|
||||
gs_effect_set_val(color_range_max, s->async_color_range_max,
|
||||
size);
|
||||
}
|
||||
|
||||
frame2_ts = s->deinterlace_frame_ts + s->deinterlace_offset +
|
||||
s->deinterlace_half_duration - TWOX_TOLERANCE;
|
||||
|
||||
gs_effect_set_bool(frame2, obs->video.video_time >= frame2_ts);
|
||||
|
||||
while (gs_effect_loop(effect, tech))
|
||||
while (gs_effect_loop(effect, "Draw"))
|
||||
gs_draw_sprite(NULL, s->async_flip ? GS_FLIP_V : 0,
|
||||
s->async_width, s->async_height);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -665,6 +665,11 @@ static inline void handle_stop(obs_source_t *transition)
|
|||
"transition_stop");
|
||||
}
|
||||
|
||||
void obs_transition_force_stop(obs_source_t *transition)
|
||||
{
|
||||
handle_stop(transition);
|
||||
}
|
||||
|
||||
void obs_transition_video_render(obs_source_t *transition,
|
||||
obs_transition_video_render_callback_t callback)
|
||||
{
|
||||
|
|
@ -718,10 +723,16 @@ void obs_transition_video_render(obs_source_t *transition,
|
|||
|
||||
cx = get_cx(transition);
|
||||
cy = get_cy(transition);
|
||||
if (cx && cy)
|
||||
if (cx && cy) {
|
||||
gs_blend_state_push();
|
||||
gs_blend_function(GS_BLEND_ONE, GS_BLEND_INVSRCALPHA);
|
||||
|
||||
callback(transition->context.data, tex[0], tex[1], t,
|
||||
cx, cy);
|
||||
|
||||
gs_blend_state_pop();
|
||||
}
|
||||
|
||||
} else if (state.transitioning_audio) {
|
||||
if (state.s[1]) {
|
||||
gs_matrix_push();
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "media-io/format-conversion.h"
|
||||
#include "media-io/video-frame.h"
|
||||
|
|
@ -140,6 +141,7 @@ bool obs_source_init(struct obs_source *source)
|
|||
source->user_volume = 1.0f;
|
||||
source->volume = 1.0f;
|
||||
source->sync_offset = 0;
|
||||
source->balance = 0.5f;
|
||||
pthread_mutex_init_value(&source->filter_mutex);
|
||||
pthread_mutex_init_value(&source->async_mutex);
|
||||
pthread_mutex_init_value(&source->audio_mutex);
|
||||
|
|
@ -1327,15 +1329,21 @@ enum convert_type {
|
|||
CONVERT_420,
|
||||
CONVERT_422_U,
|
||||
CONVERT_422_Y,
|
||||
CONVERT_444,
|
||||
CONVERT_800,
|
||||
CONVERT_RGB_LIMITED,
|
||||
};
|
||||
|
||||
static inline enum convert_type get_convert_type(enum video_format format)
|
||||
static inline enum convert_type get_convert_type(enum video_format format,
|
||||
bool full_range)
|
||||
{
|
||||
switch (format) {
|
||||
case VIDEO_FORMAT_I420:
|
||||
return CONVERT_420;
|
||||
case VIDEO_FORMAT_NV12:
|
||||
return CONVERT_NV12;
|
||||
case VIDEO_FORMAT_I444:
|
||||
return CONVERT_444;
|
||||
|
||||
case VIDEO_FORMAT_YVYU:
|
||||
case VIDEO_FORMAT_YUY2:
|
||||
|
|
@ -1344,12 +1352,13 @@ static inline enum convert_type get_convert_type(enum video_format format)
|
|||
return CONVERT_422_U;
|
||||
|
||||
case VIDEO_FORMAT_Y800:
|
||||
case VIDEO_FORMAT_I444:
|
||||
return CONVERT_800;
|
||||
|
||||
case VIDEO_FORMAT_NONE:
|
||||
case VIDEO_FORMAT_RGBA:
|
||||
case VIDEO_FORMAT_BGRA:
|
||||
case VIDEO_FORMAT_BGRX:
|
||||
return CONVERT_NONE;
|
||||
return full_range ? CONVERT_NONE : CONVERT_RGB_LIMITED;
|
||||
}
|
||||
|
||||
return CONVERT_NONE;
|
||||
|
|
@ -1358,12 +1367,23 @@ static inline enum convert_type get_convert_type(enum video_format format)
|
|||
static inline bool set_packed422_sizes(struct obs_source *source,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
source->async_convert_height = frame->height;
|
||||
source->async_convert_width = frame->width / 2;
|
||||
source->async_convert_height = frame->height;
|
||||
source->async_texture_format = GS_BGRA;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool set_planar444_sizes(struct obs_source *source,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
source->async_convert_width = frame->width;
|
||||
source->async_convert_height = frame->height * 3;
|
||||
source->async_texture_format = GS_R8;
|
||||
source->async_plane_offset[0] = (int)(frame->data[1] - frame->data[0]);
|
||||
source->async_plane_offset[1] = (int)(frame->data[2] - frame->data[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool set_planar420_sizes(struct obs_source *source,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
|
|
@ -1391,10 +1411,28 @@ static inline bool set_nv12_sizes(struct obs_source *source,
|
|||
return true;
|
||||
}
|
||||
|
||||
static inline bool set_y800_sizes(struct obs_source *source,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
source->async_convert_width = frame->width;
|
||||
source->async_convert_height = frame->height;
|
||||
source->async_texture_format = GS_R8;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool set_rgb_limited_sizes(struct obs_source *source,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
source->async_convert_width = frame->width;
|
||||
source->async_convert_height = frame->height;
|
||||
source->async_texture_format = convert_video_format(frame->format);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool init_gpu_conversion(struct obs_source *source,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
switch (get_convert_type(frame->format)) {
|
||||
switch (get_convert_type(frame->format, frame->full_range)) {
|
||||
case CONVERT_422_Y:
|
||||
case CONVERT_422_U:
|
||||
return set_packed422_sizes(source, frame);
|
||||
|
|
@ -1404,7 +1442,15 @@ static inline bool init_gpu_conversion(struct obs_source *source,
|
|||
|
||||
case CONVERT_NV12:
|
||||
return set_nv12_sizes(source, frame);
|
||||
break;
|
||||
|
||||
case CONVERT_444:
|
||||
return set_planar444_sizes(source, frame);
|
||||
|
||||
case CONVERT_800:
|
||||
return set_y800_sizes(source, frame);
|
||||
|
||||
case CONVERT_RGB_LIMITED:
|
||||
return set_rgb_limited_sizes(source, frame);
|
||||
|
||||
case CONVERT_NONE:
|
||||
assert(false && "No conversion requested");
|
||||
|
|
@ -1417,16 +1463,19 @@ static inline bool init_gpu_conversion(struct obs_source *source,
|
|||
bool set_async_texture_size(struct obs_source *source,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
enum convert_type cur = get_convert_type(frame->format);
|
||||
enum convert_type cur = get_convert_type(frame->format,
|
||||
frame->full_range);
|
||||
|
||||
if (source->async_width == frame->width &&
|
||||
source->async_height == frame->height &&
|
||||
source->async_format == frame->format)
|
||||
if (source->async_width == frame->width &&
|
||||
source->async_height == frame->height &&
|
||||
source->async_format == frame->format &&
|
||||
source->async_full_range == frame->full_range)
|
||||
return true;
|
||||
|
||||
source->async_width = frame->width;
|
||||
source->async_height = frame->height;
|
||||
source->async_format = frame->format;
|
||||
source->async_width = frame->width;
|
||||
source->async_height = frame->height;
|
||||
source->async_format = frame->format;
|
||||
source->async_full_range = frame->full_range;
|
||||
|
||||
gs_enter_context(obs->video.graphics);
|
||||
|
||||
|
|
@ -1442,8 +1491,10 @@ bool set_async_texture_size(struct obs_source *source,
|
|||
if (cur != CONVERT_NONE && init_gpu_conversion(source, frame)) {
|
||||
source->async_gpu_conversion = true;
|
||||
|
||||
enum gs_color_format format = CONVERT_RGB_LIMITED ?
|
||||
convert_video_format(frame->format) : GS_BGRX;
|
||||
source->async_texrender =
|
||||
gs_texrender_create(GS_BGRX, GS_ZS_NONE);
|
||||
gs_texrender_create(format, GS_ZS_NONE);
|
||||
|
||||
source->async_texture = gs_texture_create(
|
||||
source->async_convert_width,
|
||||
|
|
@ -1472,19 +1523,18 @@ bool set_async_texture_size(struct obs_source *source,
|
|||
static void upload_raw_frame(gs_texture_t *tex,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
switch (get_convert_type(frame->format)) {
|
||||
switch (get_convert_type(frame->format, frame->full_range)) {
|
||||
case CONVERT_422_U:
|
||||
case CONVERT_422_Y:
|
||||
case CONVERT_800:
|
||||
case CONVERT_RGB_LIMITED:
|
||||
gs_texture_set_image(tex, frame->data[0],
|
||||
frame->linesize[0], false);
|
||||
break;
|
||||
|
||||
case CONVERT_420:
|
||||
gs_texture_set_image(tex, frame->data[0],
|
||||
frame->width, false);
|
||||
break;
|
||||
|
||||
case CONVERT_NV12:
|
||||
case CONVERT_444:
|
||||
gs_texture_set_image(tex, frame->data[0],
|
||||
frame->width, false);
|
||||
break;
|
||||
|
|
@ -1495,7 +1545,8 @@ static void upload_raw_frame(gs_texture_t *tex,
|
|||
}
|
||||
}
|
||||
|
||||
static const char *select_conversion_technique(enum video_format format)
|
||||
static const char *select_conversion_technique(enum video_format format,
|
||||
bool full_range)
|
||||
{
|
||||
switch (format) {
|
||||
case VIDEO_FORMAT_UYVY:
|
||||
|
|
@ -1512,15 +1563,21 @@ static const char *select_conversion_technique(enum video_format format)
|
|||
|
||||
case VIDEO_FORMAT_NV12:
|
||||
return "NV12_Reverse";
|
||||
break;
|
||||
|
||||
case VIDEO_FORMAT_I444:
|
||||
return "I444_Reverse";
|
||||
|
||||
case VIDEO_FORMAT_Y800:
|
||||
return full_range ? "Y800_Full" : "Y800_Limited";
|
||||
|
||||
case VIDEO_FORMAT_BGRA:
|
||||
case VIDEO_FORMAT_BGRX:
|
||||
case VIDEO_FORMAT_RGBA:
|
||||
case VIDEO_FORMAT_NONE:
|
||||
case VIDEO_FORMAT_I444:
|
||||
assert(false && "No conversion requested");
|
||||
if (full_range)
|
||||
assert(false && "No conversion requested");
|
||||
else
|
||||
return "RGB_Limited";
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
|
|
@ -1542,6 +1599,8 @@ static bool update_async_texrender(struct obs_source *source,
|
|||
const struct obs_source_frame *frame,
|
||||
gs_texture_t *tex, gs_texrender_t *texrender)
|
||||
{
|
||||
GS_DEBUG_MARKER_BEGIN(GS_DEBUG_COLOR_CONVERT_FORMAT, "Convert Format");
|
||||
|
||||
gs_texrender_reset(texrender);
|
||||
|
||||
upload_raw_frame(tex, frame);
|
||||
|
|
@ -1552,11 +1611,16 @@ static bool update_async_texrender(struct obs_source *source,
|
|||
float convert_width = (float)source->async_convert_width;
|
||||
|
||||
gs_effect_t *conv = obs->video.conversion_effect;
|
||||
gs_technique_t *tech = gs_effect_get_technique(conv,
|
||||
select_conversion_technique(frame->format));
|
||||
const char *tech_name = select_conversion_technique(frame->format,
|
||||
frame->full_range);
|
||||
gs_technique_t *tech = gs_effect_get_technique(conv, tech_name);
|
||||
|
||||
if (!gs_texrender_begin(texrender, cx, cy))
|
||||
if (!gs_texrender_begin(texrender, cx, cy)) {
|
||||
GS_DEBUG_MARKER_END();
|
||||
return false;
|
||||
}
|
||||
|
||||
gs_enable_blending(false);
|
||||
|
||||
gs_technique_begin(tech);
|
||||
gs_technique_begin_pass(tech, 0);
|
||||
|
|
@ -1575,6 +1639,19 @@ static bool update_async_texrender(struct obs_source *source,
|
|||
set_eparami(conv, "int_v_plane_offset",
|
||||
(int)source->async_plane_offset[1]);
|
||||
|
||||
gs_effect_set_val(gs_effect_get_param_by_name(conv, "color_matrix"),
|
||||
frame->color_matrix, sizeof(float) * 16);
|
||||
if (!frame->full_range) {
|
||||
gs_eparam_t *min_param = gs_effect_get_param_by_name(
|
||||
conv, "color_range_min");
|
||||
gs_effect_set_val(min_param, frame->color_range_min,
|
||||
sizeof(float) * 3);
|
||||
gs_eparam_t *max_param = gs_effect_get_param_by_name(
|
||||
conv, "color_range_max");
|
||||
gs_effect_set_val(max_param, frame->color_range_max,
|
||||
sizeof(float) * 3);
|
||||
}
|
||||
|
||||
gs_ortho(0.f, (float)cx, 0.f, (float)cy, -100.f, 100.f);
|
||||
|
||||
gs_draw_sprite(tex, 0, cx, cy);
|
||||
|
|
@ -1582,8 +1659,11 @@ static bool update_async_texrender(struct obs_source *source,
|
|||
gs_technique_end_pass(tech);
|
||||
gs_technique_end(tech);
|
||||
|
||||
gs_enable_blending(true);
|
||||
|
||||
gs_texrender_end(texrender);
|
||||
|
||||
GS_DEBUG_MARKER_END();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1591,56 +1671,25 @@ bool update_async_texture(struct obs_source *source,
|
|||
const struct obs_source_frame *frame,
|
||||
gs_texture_t *tex, gs_texrender_t *texrender)
|
||||
{
|
||||
enum convert_type type = get_convert_type(frame->format);
|
||||
uint8_t *ptr;
|
||||
uint32_t linesize;
|
||||
enum convert_type type;
|
||||
|
||||
source->async_flip = frame->flip;
|
||||
source->async_full_range = frame->full_range;
|
||||
memcpy(source->async_color_matrix, frame->color_matrix,
|
||||
sizeof(frame->color_matrix));
|
||||
memcpy(source->async_color_range_min, frame->color_range_min,
|
||||
sizeof frame->color_range_min);
|
||||
memcpy(source->async_color_range_max, frame->color_range_max,
|
||||
sizeof frame->color_range_max);
|
||||
|
||||
if (source->async_gpu_conversion && texrender)
|
||||
return update_async_texrender(source, frame, tex, texrender);
|
||||
|
||||
type = get_convert_type(frame->format, frame->full_range);
|
||||
if (type == CONVERT_NONE) {
|
||||
gs_texture_set_image(tex, frame->data[0], frame->linesize[0],
|
||||
false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!gs_texture_map(tex, &ptr, &linesize))
|
||||
return false;
|
||||
|
||||
if (type == CONVERT_420)
|
||||
decompress_420((const uint8_t* const*)frame->data,
|
||||
frame->linesize,
|
||||
0, frame->height, ptr, linesize);
|
||||
|
||||
else if (type == CONVERT_NV12)
|
||||
decompress_nv12((const uint8_t* const*)frame->data,
|
||||
frame->linesize,
|
||||
0, frame->height, ptr, linesize);
|
||||
|
||||
else if (type == CONVERT_422_Y)
|
||||
decompress_422(frame->data[0], frame->linesize[0],
|
||||
0, frame->height, ptr, linesize, true);
|
||||
|
||||
else if (type == CONVERT_422_U)
|
||||
decompress_422(frame->data[0], frame->linesize[0],
|
||||
0, frame->height, ptr, linesize, false);
|
||||
|
||||
gs_texture_unmap(tex);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void obs_source_draw_texture(struct obs_source *source,
|
||||
gs_effect_t *effect, float *color_matrix,
|
||||
float const *color_range_min, float const *color_range_max)
|
||||
gs_effect_t *effect)
|
||||
{
|
||||
gs_texture_t *tex = source->async_texture;
|
||||
gs_eparam_t *param;
|
||||
|
|
@ -1648,23 +1697,6 @@ static inline void obs_source_draw_texture(struct obs_source *source,
|
|||
if (source->async_texrender)
|
||||
tex = gs_texrender_get_texture(source->async_texrender);
|
||||
|
||||
if (color_range_min) {
|
||||
size_t const size = sizeof(float) * 3;
|
||||
param = gs_effect_get_param_by_name(effect, "color_range_min");
|
||||
gs_effect_set_val(param, color_range_min, size);
|
||||
}
|
||||
|
||||
if (color_range_max) {
|
||||
size_t const size = sizeof(float) * 3;
|
||||
param = gs_effect_get_param_by_name(effect, "color_range_max");
|
||||
gs_effect_set_val(param, color_range_max, size);
|
||||
}
|
||||
|
||||
if (color_matrix) {
|
||||
param = gs_effect_get_param_by_name(effect, "color_matrix");
|
||||
gs_effect_set_val(param, color_matrix, sizeof(float) * 16);
|
||||
}
|
||||
|
||||
param = gs_effect_get_param_by_name(effect, "image");
|
||||
gs_effect_set_texture(param, tex);
|
||||
|
||||
|
|
@ -1673,24 +1705,18 @@ static inline void obs_source_draw_texture(struct obs_source *source,
|
|||
|
||||
static void obs_source_draw_async_texture(struct obs_source *source)
|
||||
{
|
||||
gs_effect_t *effect = gs_get_effect();
|
||||
bool yuv = format_is_yuv(source->async_format);
|
||||
bool limited_range = yuv && !source->async_full_range;
|
||||
const char *type = yuv ? "DrawMatrix" : "Draw";
|
||||
gs_effect_t *effect = gs_get_effect();
|
||||
bool def_draw = (!effect);
|
||||
gs_technique_t *tech = NULL;
|
||||
gs_technique_t *tech = NULL;
|
||||
|
||||
if (def_draw) {
|
||||
effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
|
||||
tech = gs_effect_get_technique(effect, type);
|
||||
tech = gs_effect_get_technique(effect, "Draw");
|
||||
gs_technique_begin(tech);
|
||||
gs_technique_begin_pass(tech, 0);
|
||||
}
|
||||
|
||||
obs_source_draw_texture(source, effect,
|
||||
yuv ? source->async_color_matrix : NULL,
|
||||
limited_range ? source->async_color_range_min : NULL,
|
||||
limited_range ? source->async_color_range_max : NULL);
|
||||
obs_source_draw_texture(source, effect);
|
||||
|
||||
if (def_draw) {
|
||||
gs_technique_end_pass(tech);
|
||||
|
|
@ -1783,6 +1809,24 @@ static inline void obs_source_main_render(obs_source_t *source)
|
|||
|
||||
static bool ready_async_frame(obs_source_t *source, uint64_t sys_time);
|
||||
|
||||
#if GS_USE_DEBUG_MARKERS
|
||||
static const char *get_type_format(enum obs_source_type type)
|
||||
{
|
||||
switch (type) {
|
||||
case OBS_SOURCE_TYPE_INPUT:
|
||||
return "Input: %s";
|
||||
case OBS_SOURCE_TYPE_FILTER:
|
||||
return "Filter: %s";
|
||||
case OBS_SOURCE_TYPE_TRANSITION:
|
||||
return "Transition: %s";
|
||||
case OBS_SOURCE_TYPE_SCENE:
|
||||
return "Scene: %s";
|
||||
default:
|
||||
return "[Unknown]: %s";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void render_video(obs_source_t *source)
|
||||
{
|
||||
if (source->info.type != OBS_SOURCE_TYPE_FILTER &&
|
||||
|
|
@ -1806,6 +1850,10 @@ static inline void render_video(obs_source_t *source)
|
|||
return;
|
||||
}
|
||||
|
||||
GS_DEBUG_MARKER_BEGIN_FORMAT(GS_DEBUG_COLOR_SOURCE,
|
||||
get_type_format(source->info.type),
|
||||
obs_source_get_name(source));
|
||||
|
||||
if (source->filters.num && !source->rendering_filter)
|
||||
obs_source_render_filters(source);
|
||||
|
||||
|
|
@ -1820,6 +1868,8 @@ static inline void render_video(obs_source_t *source)
|
|||
|
||||
else
|
||||
obs_source_render_async_video(source);
|
||||
|
||||
GS_DEBUG_MARKER_END();
|
||||
}
|
||||
|
||||
void obs_source_video_render(obs_source_t *source)
|
||||
|
|
@ -1835,11 +1885,12 @@ void obs_source_video_render(obs_source_t *source)
|
|||
static uint32_t get_base_width(const obs_source_t *source)
|
||||
{
|
||||
bool is_filter = !!source->filter_parent;
|
||||
bool func_valid = source->context.data && source->info.get_width;
|
||||
|
||||
if (source->info.type == OBS_SOURCE_TYPE_TRANSITION) {
|
||||
return source->enabled ? source->transition_actual_cx : 0;
|
||||
|
||||
} else if (source->info.get_width && (!is_filter || source->enabled)) {
|
||||
} else if (func_valid && (!is_filter || source->enabled)) {
|
||||
return source->info.get_width(source->context.data);
|
||||
|
||||
} else if (is_filter) {
|
||||
|
|
@ -1852,11 +1903,12 @@ static uint32_t get_base_width(const obs_source_t *source)
|
|||
static uint32_t get_base_height(const obs_source_t *source)
|
||||
{
|
||||
bool is_filter = !!source->filter_parent;
|
||||
bool func_valid = source->context.data && source->info.get_height;
|
||||
|
||||
if (source->info.type == OBS_SOURCE_TYPE_TRANSITION) {
|
||||
return source->enabled ? source->transition_actual_cy : 0;
|
||||
|
||||
} else if (source->info.get_height && (!is_filter || source->enabled)) {
|
||||
} else if (func_valid && (!is_filter || source->enabled)) {
|
||||
return source->info.get_height(source->context.data);
|
||||
|
||||
} else if (is_filter) {
|
||||
|
|
@ -2213,41 +2265,6 @@ static inline void copy_frame_data_plane(struct obs_source_frame *dst,
|
|||
dst->linesize[plane] * lines);
|
||||
}
|
||||
|
||||
static void copy_frame_data_line_y800(uint32_t *dst, uint8_t *src, uint8_t *end)
|
||||
{
|
||||
while (src < end) {
|
||||
register uint32_t val = *(src++);
|
||||
val |= (val << 8);
|
||||
val |= (val << 16);
|
||||
*(dst++) = val;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void copy_frame_data_y800(struct obs_source_frame *dst,
|
||||
const struct obs_source_frame *src)
|
||||
{
|
||||
uint32_t *ptr_dst;
|
||||
uint8_t *ptr_src;
|
||||
uint8_t *src_end;
|
||||
|
||||
if ((src->linesize[0] * 4) != dst->linesize[0]) {
|
||||
for (uint32_t cy = 0; cy < src->height; cy++) {
|
||||
ptr_dst = (uint32_t*)
|
||||
(dst->data[0] + cy * dst->linesize[0]);
|
||||
ptr_src = (src->data[0] + cy * src->linesize[0]);
|
||||
src_end = ptr_src + src->width;
|
||||
|
||||
copy_frame_data_line_y800(ptr_dst, ptr_src, src_end);
|
||||
}
|
||||
} else {
|
||||
ptr_dst = (uint32_t*)dst->data[0];
|
||||
ptr_src = (uint8_t *)src->data[0];
|
||||
src_end = ptr_src + src->height * src->linesize[0];
|
||||
|
||||
copy_frame_data_line_y800(ptr_dst, ptr_src, src_end);
|
||||
}
|
||||
}
|
||||
|
||||
static void copy_frame_data(struct obs_source_frame *dst,
|
||||
const struct obs_source_frame *src)
|
||||
{
|
||||
|
|
@ -2286,11 +2303,8 @@ static void copy_frame_data(struct obs_source_frame *dst,
|
|||
case VIDEO_FORMAT_RGBA:
|
||||
case VIDEO_FORMAT_BGRA:
|
||||
case VIDEO_FORMAT_BGRX:
|
||||
copy_frame_data_plane(dst, src, 0, dst->height);
|
||||
break;
|
||||
|
||||
case VIDEO_FORMAT_Y800:
|
||||
copy_frame_data_y800(dst, src);
|
||||
copy_frame_data_plane(dst, src, 0, dst->height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -2305,8 +2319,9 @@ static inline bool async_texture_changed(struct obs_source *source,
|
|||
const struct obs_source_frame *frame)
|
||||
{
|
||||
enum convert_type prev, cur;
|
||||
prev = get_convert_type(source->async_cache_format);
|
||||
cur = get_convert_type(frame->format);
|
||||
prev = get_convert_type(source->async_cache_format,
|
||||
source->async_cache_full_range);
|
||||
cur = get_convert_type(frame->format, frame->full_range);
|
||||
|
||||
return source->async_cache_width != frame->width ||
|
||||
source->async_cache_height != frame->height ||
|
||||
|
|
@ -2342,7 +2357,7 @@ static void clean_cache(obs_source_t *source)
|
|||
}
|
||||
|
||||
#define MAX_ASYNC_FRAMES 30
|
||||
|
||||
//if return value is not null then do (os_atomic_dec_long(&output->refs) == 0) && obs_source_frame_destroy(output)
|
||||
static inline struct obs_source_frame *cache_video(struct obs_source *source,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
|
|
@ -2359,9 +2374,10 @@ static inline struct obs_source_frame *cache_video(struct obs_source *source,
|
|||
|
||||
if (async_texture_changed(source, frame)) {
|
||||
free_async_cache(source);
|
||||
source->async_cache_width = frame->width;
|
||||
source->async_cache_height = frame->height;
|
||||
source->async_cache_format = frame->format;
|
||||
source->async_cache_width = frame->width;
|
||||
source->async_cache_height = frame->height;
|
||||
source->async_cache_format = frame->format;
|
||||
source->async_cache_full_range = frame->full_range;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < source->async_cache.num; i++) {
|
||||
|
|
@ -2380,9 +2396,6 @@ static inline struct obs_source_frame *cache_video(struct obs_source *source,
|
|||
struct async_frame new_af;
|
||||
enum video_format format = frame->format;
|
||||
|
||||
if (format == VIDEO_FORMAT_Y800)
|
||||
format = VIDEO_FORMAT_BGRX;
|
||||
|
||||
new_frame = obs_source_frame_create(format,
|
||||
frame->width, frame->height);
|
||||
new_af.frame = new_frame;
|
||||
|
|
@ -2399,15 +2412,10 @@ static inline struct obs_source_frame *cache_video(struct obs_source *source,
|
|||
|
||||
copy_frame_data(new_frame, frame);
|
||||
|
||||
if (os_atomic_dec_long(&new_frame->refs) == 0) {
|
||||
obs_source_frame_destroy(new_frame);
|
||||
new_frame = NULL;
|
||||
}
|
||||
|
||||
return new_frame;
|
||||
}
|
||||
|
||||
void obs_source_output_video(obs_source_t *source,
|
||||
static void obs_source_output_video_internal(obs_source_t *source,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
if (!obs_source_valid(source, "obs_source_output_video"))
|
||||
|
|
@ -2422,13 +2430,67 @@ void obs_source_output_video(obs_source_t *source,
|
|||
cache_video(source, frame) : NULL;
|
||||
|
||||
/* ------------------------------------------- */
|
||||
|
||||
pthread_mutex_lock(&source->async_mutex);
|
||||
if (output) {
|
||||
pthread_mutex_lock(&source->async_mutex);
|
||||
da_push_back(source->async_frames, &output);
|
||||
pthread_mutex_unlock(&source->async_mutex);
|
||||
source->async_active = true;
|
||||
if (os_atomic_dec_long(&output->refs) == 0) {
|
||||
obs_source_frame_destroy(output);
|
||||
output = NULL;
|
||||
} else {
|
||||
da_push_back(source->async_frames, &output);
|
||||
source->async_active = true;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&source->async_mutex);
|
||||
}
|
||||
|
||||
void obs_source_output_video(obs_source_t *source,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
if (!frame) {
|
||||
obs_source_output_video_internal(source, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
struct obs_source_frame new_frame = *frame;
|
||||
new_frame.full_range = format_is_yuv(frame->format)
|
||||
? new_frame.full_range
|
||||
: true;
|
||||
|
||||
obs_source_output_video_internal(source, &new_frame);
|
||||
}
|
||||
|
||||
void obs_source_output_video2(obs_source_t *source,
|
||||
const struct obs_source_frame2 *frame)
|
||||
{
|
||||
if (!frame) {
|
||||
obs_source_output_video_internal(source, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
struct obs_source_frame new_frame;
|
||||
enum video_range_type range = resolve_video_range(frame->format,
|
||||
frame->range);
|
||||
|
||||
for (size_t i = 0; i < MAX_AV_PLANES; i++) {
|
||||
new_frame.data[i] = frame->data[i];
|
||||
new_frame.linesize[i] = frame->linesize[i];
|
||||
}
|
||||
|
||||
new_frame.width = frame->width;
|
||||
new_frame.height = frame->height;
|
||||
new_frame.timestamp = frame->timestamp;
|
||||
new_frame.format = frame->format;
|
||||
new_frame.full_range = range == VIDEO_RANGE_FULL;
|
||||
new_frame.flip = frame->flip;
|
||||
|
||||
memcpy(&new_frame.color_matrix, &frame->color_matrix,
|
||||
sizeof(frame->color_matrix));
|
||||
memcpy(&new_frame.color_range_min, &frame->color_range_min,
|
||||
sizeof(frame->color_range_min));
|
||||
memcpy(&new_frame.color_range_max, &frame->color_range_max,
|
||||
sizeof(frame->color_range_max));
|
||||
|
||||
obs_source_output_video_internal(source, &new_frame);
|
||||
}
|
||||
|
||||
static inline bool preload_frame_changed(obs_source_t *source,
|
||||
|
|
@ -2442,7 +2504,7 @@ static inline bool preload_frame_changed(obs_source_t *source,
|
|||
in->format != source->async_preload_frame->format;
|
||||
}
|
||||
|
||||
void obs_source_preload_video(obs_source_t *source,
|
||||
static void obs_source_preload_video_internal(obs_source_t *source,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
if (!obs_source_valid(source, "obs_source_preload_video"))
|
||||
|
|
@ -2471,6 +2533,56 @@ void obs_source_preload_video(obs_source_t *source,
|
|||
obs_leave_graphics();
|
||||
}
|
||||
|
||||
void obs_source_preload_video(obs_source_t *source,
|
||||
const struct obs_source_frame *frame)
|
||||
{
|
||||
if (!frame) {
|
||||
obs_source_preload_video_internal(source, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
struct obs_source_frame new_frame = *frame;
|
||||
new_frame.full_range = format_is_yuv(frame->format)
|
||||
? new_frame.full_range
|
||||
: true;
|
||||
|
||||
obs_source_preload_video_internal(source, &new_frame);
|
||||
}
|
||||
|
||||
void obs_source_preload_video2(obs_source_t *source,
|
||||
const struct obs_source_frame2 *frame)
|
||||
{
|
||||
if (!frame) {
|
||||
obs_source_preload_video_internal(source, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
struct obs_source_frame new_frame;
|
||||
enum video_range_type range = resolve_video_range(frame->format,
|
||||
frame->range);
|
||||
|
||||
for (size_t i = 0; i < MAX_AV_PLANES; i++) {
|
||||
new_frame.data[i] = frame->data[i];
|
||||
new_frame.linesize[i] = frame->linesize[i];
|
||||
}
|
||||
|
||||
new_frame.width = frame->width;
|
||||
new_frame.height = frame->height;
|
||||
new_frame.timestamp = frame->timestamp;
|
||||
new_frame.format = frame->format;
|
||||
new_frame.full_range = range == VIDEO_RANGE_FULL;
|
||||
new_frame.flip = frame->flip;
|
||||
|
||||
memcpy(&new_frame.color_matrix, &frame->color_matrix,
|
||||
sizeof(frame->color_matrix));
|
||||
memcpy(&new_frame.color_range_min, &frame->color_range_min,
|
||||
sizeof(frame->color_range_min));
|
||||
memcpy(&new_frame.color_range_max, &frame->color_range_max,
|
||||
sizeof(frame->color_range_max));
|
||||
|
||||
obs_source_preload_video_internal(source, &new_frame);
|
||||
}
|
||||
|
||||
void obs_source_show_preloaded_video(obs_source_t *source)
|
||||
{
|
||||
uint64_t sys_ts;
|
||||
|
|
@ -2481,7 +2593,9 @@ void obs_source_show_preloaded_video(obs_source_t *source)
|
|||
source->async_active = true;
|
||||
|
||||
pthread_mutex_lock(&source->audio_buf_mutex);
|
||||
sys_ts = os_gettime_ns();
|
||||
sys_ts = (source->monitoring_type != OBS_MONITORING_TYPE_MONITOR_ONLY)
|
||||
? os_gettime_ns()
|
||||
: 0;
|
||||
reset_audio_timing(source, source->last_frame_ts, sys_ts);
|
||||
reset_audio_data(source, sys_ts);
|
||||
pthread_mutex_unlock(&source->audio_buf_mutex);
|
||||
|
|
@ -2589,6 +2703,37 @@ static void downmix_to_mono_planar(struct obs_source *source, uint32_t frames)
|
|||
}
|
||||
}
|
||||
|
||||
static void process_audio_balancing(struct obs_source *source, uint32_t frames,
|
||||
float balance, enum obs_balance_type type)
|
||||
{
|
||||
float **data = (float**)source->audio_data.data;
|
||||
|
||||
switch(type) {
|
||||
case OBS_BALANCE_TYPE_SINE_LAW:
|
||||
for (uint32_t frame = 0; frame < frames; frame++) {
|
||||
data[0][frame] = data[0][frame] *
|
||||
sinf((1.0f - balance) * (M_PI/2.0f));
|
||||
data[1][frame] = data[1][frame] *
|
||||
sinf(balance * (M_PI/2.0f));
|
||||
}
|
||||
break;
|
||||
case OBS_BALANCE_TYPE_SQUARE_LAW:
|
||||
for (uint32_t frame = 0; frame < frames; frame++) {
|
||||
data[0][frame] = data[0][frame] * sqrtf(1.0f - balance);
|
||||
data[1][frame] = data[1][frame] * sqrtf(balance);
|
||||
}
|
||||
break;
|
||||
case OBS_BALANCE_TYPE_LINEAR:
|
||||
for (uint32_t frame = 0; frame < frames; frame++) {
|
||||
data[0][frame] = data[0][frame] * (1.0f - balance);
|
||||
data[1][frame] = data[1][frame] * balance;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* resamples/remixes new audio to the designated main audio output format */
|
||||
static void process_audio(obs_source_t *source,
|
||||
const struct obs_source_audio *audio)
|
||||
|
|
@ -2622,6 +2767,12 @@ static void process_audio(obs_source_t *source,
|
|||
|
||||
mono_output = audio_output_get_channels(obs->audio.audio) == 1;
|
||||
|
||||
if (!mono_output && source->sample_info.speakers == SPEAKERS_STEREO &&
|
||||
(source->balance > 0.51f || source->balance < 0.49f)) {
|
||||
process_audio_balancing(source, frames, source->balance,
|
||||
OBS_BALANCE_TYPE_SINE_LAW);
|
||||
}
|
||||
|
||||
if (!mono_output && (source->flags & OBS_SOURCE_FLAG_FORCE_MONO) != 0)
|
||||
downmix_to_mono_planar(source, frames);
|
||||
}
|
||||
|
|
@ -3503,12 +3654,25 @@ void obs_source_inc_showing(obs_source_t *source)
|
|||
obs_source_activate(source, AUX_VIEW);
|
||||
}
|
||||
|
||||
void obs_source_inc_active(obs_source_t *source)
|
||||
{
|
||||
if (obs_source_valid(source, "obs_source_inc_active"))
|
||||
obs_source_activate(source, MAIN_VIEW);
|
||||
}
|
||||
|
||||
void obs_source_dec_showing(obs_source_t *source)
|
||||
{
|
||||
if (obs_source_valid(source, "obs_source_dec_showing"))
|
||||
obs_source_deactivate(source, AUX_VIEW);
|
||||
}
|
||||
|
||||
void obs_source_dec_active(obs_source_t *source)
|
||||
{
|
||||
if (obs_source_valid(source, "obs_source_dec_active"))
|
||||
obs_source_deactivate(source, MAIN_VIEW);
|
||||
}
|
||||
|
||||
|
||||
void obs_source_enum_filters(obs_source_t *source,
|
||||
obs_source_enum_proc_t callback, void *param)
|
||||
{
|
||||
|
|
@ -4165,3 +4329,25 @@ EXPORT void obs_enable_source_type(const char *name, bool enable)
|
|||
else
|
||||
info->output_flags |= OBS_SOURCE_CAP_DISABLED;
|
||||
}
|
||||
|
||||
enum speaker_layout obs_source_get_speaker_layout(obs_source_t *source)
|
||||
{
|
||||
if (!obs_source_valid(source, "obs_source_get_audio_channels"))
|
||||
return SPEAKERS_UNKNOWN;
|
||||
|
||||
return source->sample_info.speakers;
|
||||
}
|
||||
|
||||
void obs_source_set_balance_value(obs_source_t *source, float balance)
|
||||
{
|
||||
if (!obs_source_valid(source, "obs_source_set_balance_value"))
|
||||
return;
|
||||
|
||||
source->balance = balance;
|
||||
}
|
||||
|
||||
float obs_source_get_balance_value(const obs_source_t *source)
|
||||
{
|
||||
return obs_source_valid(source, "obs_source_get_balance_value") ?
|
||||
source->balance : 0.5f;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,11 @@ enum obs_source_type {
|
|||
OBS_SOURCE_TYPE_SCENE,
|
||||
};
|
||||
|
||||
enum obs_balance_type {
|
||||
OBS_BALANCE_TYPE_SINE_LAW,
|
||||
OBS_BALANCE_TYPE_SQUARE_LAW,
|
||||
OBS_BALANCE_TYPE_LINEAR,
|
||||
};
|
||||
|
||||
/**
|
||||
* @name Source output flags
|
||||
|
|
|
|||
228
libobs/obs-video-gpu-encode.c
Normal file
228
libobs/obs-video-gpu-encode.c
Normal file
|
|
@ -0,0 +1,228 @@
|
|||
/******************************************************************************
|
||||
Copyright (C) 2018 by Hugh Bailey <obs.jim@gmail.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 "obs-internal.h"
|
||||
|
||||
static void *gpu_encode_thread(void *unused)
|
||||
{
|
||||
struct obs_core_video *video = &obs->video;
|
||||
uint64_t interval = video_output_get_frame_time(obs->video.video);
|
||||
DARRAY(obs_encoder_t *) encoders;
|
||||
int wait_frames = NUM_ENCODE_TEXTURE_FRAMES_TO_WAIT;
|
||||
|
||||
UNUSED_PARAMETER(unused);
|
||||
da_init(encoders);
|
||||
|
||||
os_set_thread_name("obs gpu encode thread");
|
||||
|
||||
while (os_sem_wait(video->gpu_encode_semaphore) == 0) {
|
||||
struct obs_tex_frame tf;
|
||||
uint64_t timestamp;
|
||||
uint64_t lock_key;
|
||||
uint64_t next_key;
|
||||
size_t lock_count = 0;
|
||||
|
||||
if (os_atomic_load_bool(&video->gpu_encode_stop))
|
||||
break;
|
||||
|
||||
if (wait_frames) {
|
||||
wait_frames--;
|
||||
continue;
|
||||
}
|
||||
|
||||
os_event_reset(video->gpu_encode_inactive);
|
||||
|
||||
/* -------------- */
|
||||
|
||||
pthread_mutex_lock(&video->gpu_encoder_mutex);
|
||||
|
||||
circlebuf_pop_front(&video->gpu_encoder_queue, &tf, sizeof(tf));
|
||||
timestamp = tf.timestamp;
|
||||
lock_key = tf.lock_key;
|
||||
next_key = tf.lock_key;
|
||||
|
||||
video_output_inc_texture_frames(video->video);
|
||||
|
||||
for (size_t i = 0; i < video->gpu_encoders.num; i++) {
|
||||
obs_encoder_t *encoder = video->gpu_encoders.array[i];
|
||||
da_push_back(encoders, &encoder);
|
||||
obs_encoder_addref(encoder);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&video->gpu_encoder_mutex);
|
||||
|
||||
/* -------------- */
|
||||
|
||||
for (size_t i = 0; i < encoders.num; i++) {
|
||||
struct encoder_packet pkt = {0};
|
||||
bool received = false;
|
||||
bool success;
|
||||
|
||||
obs_encoder_t *encoder = encoders.array[i];
|
||||
struct obs_encoder *pair = encoder->paired_encoder;
|
||||
|
||||
pkt.timebase_num = encoder->timebase_num;
|
||||
pkt.timebase_den = encoder->timebase_den;
|
||||
pkt.encoder = encoder;
|
||||
|
||||
if (!encoder->first_received && pair) {
|
||||
if (!pair->first_received ||
|
||||
pair->first_raw_ts > timestamp) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!encoder->start_ts)
|
||||
encoder->start_ts = timestamp;
|
||||
|
||||
if (++lock_count == encoders.num)
|
||||
next_key = 0;
|
||||
else
|
||||
next_key++;
|
||||
|
||||
success = encoder->info.encode_texture(
|
||||
encoder->context.data, tf.handle,
|
||||
encoder->cur_pts, lock_key, &next_key,
|
||||
&pkt, &received);
|
||||
send_off_encoder_packet(encoder, success, received,
|
||||
&pkt);
|
||||
|
||||
lock_key = next_key;
|
||||
|
||||
encoder->cur_pts += encoder->timebase_num;
|
||||
}
|
||||
|
||||
/* -------------- */
|
||||
|
||||
pthread_mutex_lock(&video->gpu_encoder_mutex);
|
||||
|
||||
tf.lock_key = next_key;
|
||||
|
||||
if (--tf.count) {
|
||||
tf.timestamp += interval;
|
||||
circlebuf_push_front(&video->gpu_encoder_queue,
|
||||
&tf, sizeof(tf));
|
||||
|
||||
video_output_inc_texture_skipped_frames(video->video);
|
||||
} else {
|
||||
circlebuf_push_back(
|
||||
&video->gpu_encoder_avail_queue,
|
||||
&tf, sizeof(tf));
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&video->gpu_encoder_mutex);
|
||||
|
||||
/* -------------- */
|
||||
|
||||
os_event_signal(video->gpu_encode_inactive);
|
||||
|
||||
for (size_t i = 0; i < encoders.num; i++)
|
||||
obs_encoder_release(encoders.array[i]);
|
||||
|
||||
da_resize(encoders, 0);
|
||||
}
|
||||
|
||||
da_free(encoders);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool init_gpu_encoding(struct obs_core_video *video)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
struct obs_video_info *ovi = &video->ovi;
|
||||
|
||||
video->gpu_encode_stop = false;
|
||||
|
||||
circlebuf_reserve(&video->gpu_encoder_avail_queue, NUM_ENCODE_TEXTURES);
|
||||
for (size_t i = 0; i < NUM_ENCODE_TEXTURES; i++) {
|
||||
gs_texture_t *tex;
|
||||
gs_texture_t *tex_uv;
|
||||
|
||||
gs_texture_create_nv12(
|
||||
&tex, &tex_uv,
|
||||
ovi->output_width, ovi->output_height,
|
||||
GS_RENDER_TARGET | GS_SHARED_KM_TEX);
|
||||
if (!tex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t handle = gs_texture_get_shared_handle(tex);
|
||||
|
||||
struct obs_tex_frame frame = {
|
||||
.tex = tex,
|
||||
.tex_uv = tex_uv,
|
||||
.handle = handle
|
||||
};
|
||||
|
||||
circlebuf_push_back(&video->gpu_encoder_avail_queue, &frame,
|
||||
sizeof(frame));
|
||||
}
|
||||
|
||||
if (os_sem_init(&video->gpu_encode_semaphore, 0) != 0)
|
||||
return false;
|
||||
if (os_event_init(&video->gpu_encode_inactive, OS_EVENT_TYPE_MANUAL) != 0)
|
||||
return false;
|
||||
if (pthread_create(&video->gpu_encode_thread, NULL,
|
||||
gpu_encode_thread, NULL) != 0)
|
||||
return false;
|
||||
|
||||
os_event_signal(video->gpu_encode_inactive);
|
||||
|
||||
video->gpu_encode_thread_initialized = true;
|
||||
return true;
|
||||
#else
|
||||
UNUSED_PARAMETER(video);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void stop_gpu_encoding_thread(struct obs_core_video *video)
|
||||
{
|
||||
if (video->gpu_encode_thread_initialized) {
|
||||
os_atomic_set_bool(&video->gpu_encode_stop, true);
|
||||
os_sem_post(video->gpu_encode_semaphore);
|
||||
pthread_join(video->gpu_encode_thread, NULL);
|
||||
video->gpu_encode_thread_initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
void free_gpu_encoding(struct obs_core_video *video)
|
||||
{
|
||||
if (video->gpu_encode_semaphore) {
|
||||
os_sem_destroy(video->gpu_encode_semaphore);
|
||||
video->gpu_encode_semaphore = NULL;
|
||||
}
|
||||
if (video->gpu_encode_inactive) {
|
||||
os_event_destroy(video->gpu_encode_inactive);
|
||||
video->gpu_encode_inactive = NULL;
|
||||
}
|
||||
|
||||
#define free_circlebuf(x) \
|
||||
do { \
|
||||
while (x.size) { \
|
||||
struct obs_tex_frame frame; \
|
||||
circlebuf_pop_front(&x, &frame, sizeof(frame)); \
|
||||
gs_texture_destroy(frame.tex); \
|
||||
gs_texture_destroy(frame.tex_uv); \
|
||||
} \
|
||||
circlebuf_free(&x); \
|
||||
} while (false)
|
||||
|
||||
free_circlebuf(video->gpu_encoder_queue);
|
||||
free_circlebuf(video->gpu_encoder_avail_queue);
|
||||
#undef free_circlebuf
|
||||
}
|
||||
|
|
@ -58,8 +58,13 @@ static uint64_t tick_sources(uint64_t cur_time, uint64_t last_time)
|
|||
|
||||
source = data->first_source;
|
||||
while (source) {
|
||||
obs_source_video_tick(source, seconds);
|
||||
struct obs_source *cur_source = obs_source_get_ref(source);
|
||||
source = (struct obs_source*)source->context.next;
|
||||
|
||||
if (cur_source) {
|
||||
obs_source_video_tick(cur_source, seconds);
|
||||
obs_source_release(cur_source);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&data->sources_mutex);
|
||||
|
|
@ -115,9 +120,11 @@ static inline void render_main_texture(struct obs_core_video *video,
|
|||
int cur_texture)
|
||||
{
|
||||
profile_start(render_main_texture_name);
|
||||
GS_DEBUG_MARKER_BEGIN(GS_DEBUG_COLOR_MAIN_TEXTURE,
|
||||
render_main_texture_name);
|
||||
|
||||
struct vec4 clear_color;
|
||||
vec4_set(&clear_color, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
vec4_set(&clear_color, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
gs_set_render_target(video->render_textures[cur_texture], NULL);
|
||||
gs_clear(GS_CLEAR_COLOR, &clear_color, 1.0f, 0);
|
||||
|
|
@ -140,6 +147,7 @@ static inline void render_main_texture(struct obs_core_video *video,
|
|||
|
||||
video->textures_rendered[cur_texture] = true;
|
||||
|
||||
GS_DEBUG_MARKER_END();
|
||||
profile_end(render_main_texture_name);
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +215,14 @@ static inline void render_output_texture(struct obs_core_video *video,
|
|||
1.0f / (float)video->base_height);
|
||||
|
||||
gs_effect_t *effect = get_scale_effect(video, width, height);
|
||||
gs_technique_t *tech = gs_effect_get_technique(effect, "DrawMatrix");
|
||||
gs_technique_t *tech;
|
||||
|
||||
if (video->ovi.output_format == VIDEO_FORMAT_RGBA) {
|
||||
tech = gs_effect_get_technique(effect, "DrawAlphaDivide");
|
||||
} else {
|
||||
tech = gs_effect_get_technique(effect, "DrawMatrix");
|
||||
}
|
||||
|
||||
gs_eparam_t *image = gs_effect_get_param_by_name(effect, "image");
|
||||
gs_eparam_t *matrix = gs_effect_get_param_by_name(effect,
|
||||
"color_matrix");
|
||||
|
|
@ -303,6 +318,57 @@ end:
|
|||
profile_end(render_convert_texture_name);
|
||||
}
|
||||
|
||||
static void render_nv12(struct obs_core_video *video, gs_texture_t *target,
|
||||
int cur_texture, int prev_texture, const char *tech_name,
|
||||
uint32_t width, uint32_t height)
|
||||
{
|
||||
gs_texture_t *texture = video->output_textures[prev_texture];
|
||||
|
||||
gs_effect_t *effect = video->conversion_effect;
|
||||
gs_eparam_t *image = gs_effect_get_param_by_name(effect, "image");
|
||||
gs_technique_t *tech = gs_effect_get_technique(effect, tech_name);
|
||||
size_t passes, i;
|
||||
|
||||
gs_effect_set_texture(image, texture);
|
||||
|
||||
gs_set_render_target(target, NULL);
|
||||
set_render_size(width, height);
|
||||
|
||||
gs_enable_blending(false);
|
||||
passes = gs_technique_begin(tech);
|
||||
for (i = 0; i < passes; i++) {
|
||||
gs_technique_begin_pass(tech, i);
|
||||
gs_draw_sprite(texture, 0, width, height);
|
||||
gs_technique_end_pass(tech);
|
||||
}
|
||||
gs_technique_end(tech);
|
||||
gs_enable_blending(true);
|
||||
|
||||
UNUSED_PARAMETER(cur_texture);
|
||||
}
|
||||
|
||||
static const char *render_convert_nv12_name = "render_convert_texture_nv12";
|
||||
static void render_convert_texture_nv12(struct obs_core_video *video,
|
||||
int cur_texture, int prev_texture)
|
||||
{
|
||||
profile_start(render_convert_nv12_name);
|
||||
|
||||
if (!video->textures_output[prev_texture])
|
||||
goto end;
|
||||
|
||||
render_nv12(video, video->convert_textures[cur_texture],
|
||||
cur_texture, prev_texture, "NV12_Y",
|
||||
video->output_width, video->output_height);
|
||||
render_nv12(video, video->convert_uv_textures[cur_texture],
|
||||
cur_texture, prev_texture, "NV12_UV",
|
||||
video->output_width / 2, video->output_height / 2);
|
||||
|
||||
video->textures_converted[cur_texture] = true;
|
||||
|
||||
end:
|
||||
profile_end(render_convert_nv12_name);
|
||||
}
|
||||
|
||||
static const char *stage_output_texture_name = "stage_output_texture";
|
||||
static inline void stage_output_texture(struct obs_core_video *video,
|
||||
int cur_texture, int prev_texture)
|
||||
|
|
@ -334,7 +400,100 @@ end:
|
|||
profile_end(stage_output_texture_name);
|
||||
}
|
||||
|
||||
static inline void render_video(struct obs_core_video *video, bool raw_active,
|
||||
#ifdef _WIN32
|
||||
static inline bool queue_frame(struct obs_core_video *video, bool raw_active,
|
||||
struct obs_vframe_info *vframe_info, int prev_texture)
|
||||
{
|
||||
bool duplicate = !video->gpu_encoder_avail_queue.size ||
|
||||
(video->gpu_encoder_queue.size && vframe_info->count > 1);
|
||||
|
||||
if (duplicate) {
|
||||
struct obs_tex_frame *tf = circlebuf_data(
|
||||
&video->gpu_encoder_queue,
|
||||
video->gpu_encoder_queue.size - sizeof(*tf));
|
||||
|
||||
/* texture-based encoding is stopping */
|
||||
if (!tf) {
|
||||
return false;
|
||||
}
|
||||
|
||||
tf->count++;
|
||||
os_sem_post(video->gpu_encode_semaphore);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
struct obs_tex_frame tf;
|
||||
circlebuf_pop_front(&video->gpu_encoder_avail_queue, &tf, sizeof(tf));
|
||||
|
||||
if (tf.released) {
|
||||
gs_texture_acquire_sync(tf.tex, tf.lock_key, GS_WAIT_INFINITE);
|
||||
tf.released = false;
|
||||
}
|
||||
|
||||
/* the vframe_info->count > 1 case causing a copy can only happen if by
|
||||
* some chance the very first frame has to be duplicated for whatever
|
||||
* reason. otherwise, it goes to the 'duplicate' case above, which
|
||||
* will ensure better performance. */
|
||||
if (raw_active || vframe_info->count > 1) {
|
||||
gs_copy_texture(tf.tex, video->convert_textures[prev_texture]);
|
||||
} else {
|
||||
gs_texture_t *tex = video->convert_textures[prev_texture];
|
||||
gs_texture_t *tex_uv = video->convert_uv_textures[prev_texture];
|
||||
|
||||
video->convert_textures[prev_texture] = tf.tex;
|
||||
video->convert_uv_textures[prev_texture] = tf.tex_uv;
|
||||
|
||||
tf.tex = tex;
|
||||
tf.tex_uv = tex_uv;
|
||||
}
|
||||
|
||||
tf.count = 1;
|
||||
tf.timestamp = vframe_info->timestamp;
|
||||
tf.released = true;
|
||||
tf.handle = gs_texture_get_shared_handle(tf.tex);
|
||||
gs_texture_release_sync(tf.tex, ++tf.lock_key);
|
||||
circlebuf_push_back(&video->gpu_encoder_queue, &tf, sizeof(tf));
|
||||
|
||||
os_sem_post(video->gpu_encode_semaphore);
|
||||
|
||||
finish:
|
||||
return --vframe_info->count;
|
||||
}
|
||||
|
||||
extern void full_stop(struct obs_encoder *encoder);
|
||||
|
||||
static inline void encode_gpu(struct obs_core_video *video, bool raw_active,
|
||||
struct obs_vframe_info *vframe_info, int prev_texture)
|
||||
{
|
||||
while (queue_frame(video, raw_active, vframe_info, prev_texture));
|
||||
}
|
||||
|
||||
static const char *output_gpu_encoders_name = "output_gpu_encoders";
|
||||
static void output_gpu_encoders(struct obs_core_video *video, bool raw_active,
|
||||
int prev_texture)
|
||||
{
|
||||
profile_start(output_gpu_encoders_name);
|
||||
|
||||
if (!video->textures_converted[prev_texture])
|
||||
goto end;
|
||||
if (!video->vframe_info_buffer_gpu.size)
|
||||
goto end;
|
||||
|
||||
struct obs_vframe_info vframe_info;
|
||||
circlebuf_pop_front(&video->vframe_info_buffer_gpu, &vframe_info,
|
||||
sizeof(vframe_info));
|
||||
|
||||
pthread_mutex_lock(&video->gpu_encoder_mutex);
|
||||
encode_gpu(video, raw_active, &vframe_info, prev_texture);
|
||||
pthread_mutex_unlock(&video->gpu_encoder_mutex);
|
||||
|
||||
end:
|
||||
profile_end(output_gpu_encoders_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void render_video(struct obs_core_video *video,
|
||||
bool raw_active, const bool gpu_active,
|
||||
int cur_texture, int prev_texture)
|
||||
{
|
||||
gs_begin_scene();
|
||||
|
|
@ -344,12 +503,34 @@ static inline void render_video(struct obs_core_video *video, bool raw_active,
|
|||
|
||||
render_main_texture(video, cur_texture);
|
||||
|
||||
if (raw_active) {
|
||||
if (raw_active || gpu_active) {
|
||||
render_output_texture(video, cur_texture, prev_texture);
|
||||
if (video->gpu_conversion)
|
||||
render_convert_texture(video, cur_texture, prev_texture);
|
||||
|
||||
stage_output_texture(video, cur_texture, prev_texture);
|
||||
#ifdef _WIN32
|
||||
if (gpu_active) {
|
||||
gs_flush();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (raw_active || gpu_active) {
|
||||
if (video->gpu_conversion) {
|
||||
if (video->using_nv12_tex)
|
||||
render_convert_texture_nv12(video,
|
||||
cur_texture, prev_texture);
|
||||
else
|
||||
render_convert_texture(video,
|
||||
cur_texture, prev_texture);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (gpu_active) {
|
||||
gs_flush();
|
||||
output_gpu_encoders(video, raw_active, prev_texture);
|
||||
}
|
||||
#endif
|
||||
if (raw_active)
|
||||
stage_output_texture(video, cur_texture, prev_texture);
|
||||
}
|
||||
|
||||
gs_set_render_target(NULL, NULL);
|
||||
|
|
@ -448,6 +629,25 @@ static void set_gpu_converted_data(struct obs_core_video *video,
|
|||
|
||||
video_frame_copy(output, &frame, info->format, info->height);
|
||||
|
||||
} else if (video->using_nv12_tex) {
|
||||
size_t width = info->width;
|
||||
size_t height = info->height;
|
||||
size_t height_d2 = height / 2;
|
||||
uint8_t *out_y = output->data[0];
|
||||
uint8_t *out_uv = output->data[1];
|
||||
uint8_t *in = input->data[0];
|
||||
|
||||
for (size_t y = 0; y < height; y++) {
|
||||
memcpy(out_y, in, width);
|
||||
out_y += output->linesize[0];
|
||||
in += input->linesize[0];
|
||||
}
|
||||
for (size_t y = 0; y < height_d2; y++) {
|
||||
memcpy(out_uv, in, width);
|
||||
out_uv += output->linesize[0];
|
||||
in += input->linesize[0];
|
||||
}
|
||||
|
||||
} else {
|
||||
fix_gpu_converted_alignment(video, output, input);
|
||||
}
|
||||
|
|
@ -525,7 +725,8 @@ static inline void output_video_data(struct obs_core_video *video,
|
|||
}
|
||||
}
|
||||
|
||||
static inline void video_sleep(struct obs_core_video *video, bool active,
|
||||
static inline void video_sleep(struct obs_core_video *video,
|
||||
bool raw_active, const bool gpu_active,
|
||||
uint64_t *p_time, uint64_t interval_ns)
|
||||
{
|
||||
struct obs_vframe_info vframe_info;
|
||||
|
|
@ -546,9 +747,13 @@ static inline void video_sleep(struct obs_core_video *video, bool active,
|
|||
|
||||
vframe_info.timestamp = cur_time;
|
||||
vframe_info.count = count;
|
||||
if (active)
|
||||
|
||||
if (raw_active)
|
||||
circlebuf_push_back(&video->vframe_info_buffer, &vframe_info,
|
||||
sizeof(vframe_info));
|
||||
if (gpu_active)
|
||||
circlebuf_push_back(&video->vframe_info_buffer_gpu,
|
||||
&vframe_info, sizeof(vframe_info));
|
||||
}
|
||||
|
||||
static const char *output_frame_gs_context_name = "gs_context(video->graphics)";
|
||||
|
|
@ -556,13 +761,13 @@ static const char *output_frame_render_video_name = "render_video";
|
|||
static const char *output_frame_download_frame_name = "download_frame";
|
||||
static const char *output_frame_gs_flush_name = "gs_flush";
|
||||
static const char *output_frame_output_video_data_name = "output_video_data";
|
||||
static inline void output_frame(bool raw_active)
|
||||
static inline void output_frame(bool raw_active, const bool gpu_active)
|
||||
{
|
||||
struct obs_core_video *video = &obs->video;
|
||||
int cur_texture = video->cur_texture;
|
||||
int prev_texture = cur_texture == 0 ? NUM_TEXTURES-1 : cur_texture-1;
|
||||
struct video_data frame;
|
||||
bool frame_ready;
|
||||
bool frame_ready = 0;
|
||||
|
||||
memset(&frame, 0, sizeof(struct video_data));
|
||||
|
||||
|
|
@ -570,7 +775,10 @@ static inline void output_frame(bool raw_active)
|
|||
gs_enter_context(video->graphics);
|
||||
|
||||
profile_start(output_frame_render_video_name);
|
||||
render_video(video, raw_active, cur_texture, prev_texture);
|
||||
GS_DEBUG_MARKER_BEGIN(GS_DEBUG_COLOR_RENDER_VIDEO,
|
||||
output_frame_render_video_name);
|
||||
render_video(video, raw_active, gpu_active, cur_texture, prev_texture);
|
||||
GS_DEBUG_MARKER_END();
|
||||
profile_end(output_frame_render_video_name);
|
||||
|
||||
if (raw_active) {
|
||||
|
|
@ -603,17 +811,31 @@ static inline void output_frame(bool raw_active)
|
|||
|
||||
#define NBSP "\xC2\xA0"
|
||||
|
||||
static void clear_frame_data(void)
|
||||
static void clear_base_frame_data(void)
|
||||
{
|
||||
struct obs_core_video *video = &obs->video;
|
||||
memset(video->textures_rendered, 0, sizeof(video->textures_rendered));
|
||||
memset(video->textures_output, 0, sizeof(video->textures_output));
|
||||
memset(video->textures_copied, 0, sizeof(video->textures_copied));
|
||||
memset(video->textures_converted, 0, sizeof(video->textures_converted));
|
||||
circlebuf_free(&video->vframe_info_buffer);
|
||||
video->cur_texture = 0;
|
||||
}
|
||||
|
||||
static void clear_raw_frame_data(void)
|
||||
{
|
||||
struct obs_core_video *video = &obs->video;
|
||||
memset(video->textures_copied, 0, sizeof(video->textures_copied));
|
||||
circlebuf_free(&video->vframe_info_buffer);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
static void clear_gpu_frame_data(void)
|
||||
{
|
||||
struct obs_core_video *video = &obs->video;
|
||||
circlebuf_free(&video->vframe_info_buffer_gpu);
|
||||
}
|
||||
#endif
|
||||
|
||||
static const char *tick_sources_name = "tick_sources";
|
||||
static const char *render_displays_name = "render_displays";
|
||||
static const char *output_frame_name = "output_frame";
|
||||
|
|
@ -624,7 +846,11 @@ void *obs_graphics_thread(void *param)
|
|||
uint64_t frame_time_total_ns = 0;
|
||||
uint64_t fps_total_ns = 0;
|
||||
uint32_t fps_total_frames = 0;
|
||||
#ifdef _WIN32
|
||||
bool gpu_was_active = false;
|
||||
#endif
|
||||
bool raw_was_active = false;
|
||||
bool was_active = false;
|
||||
|
||||
obs->video.video_time = os_gettime_ns();
|
||||
|
||||
|
|
@ -641,10 +867,26 @@ void *obs_graphics_thread(void *param)
|
|||
uint64_t frame_start = os_gettime_ns();
|
||||
uint64_t frame_time_ns;
|
||||
bool raw_active = obs->video.raw_active > 0;
|
||||
#ifdef _WIN32
|
||||
const bool gpu_active = obs->video.gpu_encoder_active > 0;
|
||||
const bool active = raw_active || gpu_active;
|
||||
#else
|
||||
const bool gpu_active = 0;
|
||||
const bool active = raw_active;
|
||||
#endif
|
||||
|
||||
if (!was_active && active)
|
||||
clear_base_frame_data();
|
||||
if (!raw_was_active && raw_active)
|
||||
clear_frame_data();
|
||||
clear_raw_frame_data();
|
||||
#ifdef _WIN32
|
||||
if (!gpu_was_active && gpu_active)
|
||||
clear_gpu_frame_data();
|
||||
|
||||
gpu_was_active = gpu_active;
|
||||
#endif
|
||||
raw_was_active = raw_active;
|
||||
was_active = active;
|
||||
|
||||
profile_start(video_thread_name);
|
||||
|
||||
|
|
@ -653,7 +895,7 @@ void *obs_graphics_thread(void *param)
|
|||
profile_end(tick_sources_name);
|
||||
|
||||
profile_start(output_frame_name);
|
||||
output_frame(raw_active);
|
||||
output_frame(raw_active, gpu_active);
|
||||
profile_end(output_frame_name);
|
||||
|
||||
profile_start(render_displays_name);
|
||||
|
|
@ -666,8 +908,8 @@ void *obs_graphics_thread(void *param)
|
|||
|
||||
profile_reenable_thread();
|
||||
|
||||
video_sleep(&obs->video, raw_active, &obs->video.video_time,
|
||||
interval);
|
||||
video_sleep(&obs->video, raw_active, gpu_active,
|
||||
&obs->video.video_time, interval);
|
||||
|
||||
frame_time_total_ns += frame_time_ns;
|
||||
fps_total_ns += (obs->video.video_time - last_time);
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ static void log_processor_info(void)
|
|||
DWORD size, speed;
|
||||
LSTATUS status;
|
||||
|
||||
memset(data, 0, 1024);
|
||||
memset(data, 0, sizeof(data));
|
||||
|
||||
status = RegOpenKeyW(HKEY_LOCAL_MACHINE,
|
||||
L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
|
||||
|
|
@ -90,7 +90,7 @@ static void log_processor_info(void)
|
|||
if (status != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
size = 1024;
|
||||
size = sizeof(data);
|
||||
status = RegQueryValueExW(key, L"ProcessorNameString", NULL, NULL,
|
||||
(LPBYTE)data, &size);
|
||||
if (status == ERROR_SUCCESS) {
|
||||
|
|
@ -220,6 +220,10 @@ static void log_gaming_features(void)
|
|||
L"HistoricalCaptureEnabled", &game_dvr_bg_recording);
|
||||
get_reg_dword(HKEY_CURRENT_USER, WIN10_GAME_MODE_REG_KEY,
|
||||
L"AllowAutoGameMode", &game_mode_enabled);
|
||||
if (game_mode_enabled.status != ERROR_SUCCESS) {
|
||||
get_reg_dword(HKEY_CURRENT_USER, WIN10_GAME_MODE_REG_KEY,
|
||||
L"AutoGameModeEnabled", &game_mode_enabled);
|
||||
}
|
||||
|
||||
blog(LOG_INFO, "Windows 10 Gaming Features:");
|
||||
if (game_bar_enabled.status == ERROR_SUCCESS) {
|
||||
|
|
|
|||
265
libobs/obs.c
265
libobs/obs.c
|
|
@ -164,17 +164,42 @@ static bool obs_init_gpu_conversion(struct obs_video_info *ovi)
|
|||
|
||||
calc_gpu_conversion_sizes(ovi);
|
||||
|
||||
video->using_nv12_tex = ovi->output_format == VIDEO_FORMAT_NV12
|
||||
? gs_nv12_available() : false;
|
||||
|
||||
if (!video->conversion_height) {
|
||||
blog(LOG_INFO, "GPU conversion not available for format: %u",
|
||||
(unsigned int)ovi->output_format);
|
||||
video->gpu_conversion = false;
|
||||
video->using_nv12_tex = false;
|
||||
blog(LOG_INFO, "NV12 texture support not available");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (video->using_nv12_tex)
|
||||
blog(LOG_INFO, "NV12 texture support enabled");
|
||||
else
|
||||
blog(LOG_INFO, "NV12 texture support not available");
|
||||
|
||||
for (size_t i = 0; i < NUM_TEXTURES; i++) {
|
||||
video->convert_textures[i] = gs_texture_create(
|
||||
ovi->output_width, video->conversion_height,
|
||||
GS_RGBA, 1, NULL, GS_RENDER_TARGET);
|
||||
#ifdef _WIN32
|
||||
if (video->using_nv12_tex) {
|
||||
gs_texture_create_nv12(
|
||||
&video->convert_textures[i],
|
||||
&video->convert_uv_textures[i],
|
||||
ovi->output_width, ovi->output_height,
|
||||
GS_RENDER_TARGET | GS_SHARED_KM_TEX);
|
||||
if (!video->convert_uv_textures[i])
|
||||
return false;
|
||||
} else {
|
||||
#endif
|
||||
video->convert_textures[i] = gs_texture_create(
|
||||
ovi->output_width,
|
||||
video->conversion_height,
|
||||
GS_RGBA, 1, NULL, GS_RENDER_TARGET);
|
||||
#ifdef _WIN32
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!video->convert_textures[i])
|
||||
return false;
|
||||
|
|
@ -191,11 +216,23 @@ static bool obs_init_textures(struct obs_video_info *ovi)
|
|||
size_t i;
|
||||
|
||||
for (i = 0; i < NUM_TEXTURES; i++) {
|
||||
video->copy_surfaces[i] = gs_stagesurface_create(
|
||||
ovi->output_width, output_height, GS_RGBA);
|
||||
#ifdef _WIN32
|
||||
if (video->using_nv12_tex) {
|
||||
video->copy_surfaces[i] = gs_stagesurface_create_nv12(
|
||||
ovi->output_width, ovi->output_height);
|
||||
if (!video->copy_surfaces[i])
|
||||
return false;
|
||||
|
||||
if (!video->copy_surfaces[i])
|
||||
return false;
|
||||
} else {
|
||||
#endif
|
||||
video->copy_surfaces[i] = gs_stagesurface_create(
|
||||
ovi->output_width, output_height,
|
||||
GS_RGBA);
|
||||
if (!video->copy_surfaces[i])
|
||||
return false;
|
||||
#ifdef _WIN32
|
||||
}
|
||||
#endif
|
||||
|
||||
video->render_textures[i] = gs_texture_create(
|
||||
ovi->base_width, ovi->base_height,
|
||||
|
|
@ -272,6 +309,11 @@ static int obs_init_graphics(struct obs_video_info *ovi)
|
|||
NULL);
|
||||
bfree(filename);
|
||||
|
||||
filename = obs_find_data_file("repeat.effect");
|
||||
video->repeat_effect = gs_effect_create_from_file(filename,
|
||||
NULL);
|
||||
bfree(filename);
|
||||
|
||||
filename = obs_find_data_file("format_conversion.effect");
|
||||
video->conversion_effect = gs_effect_create_from_file(filename,
|
||||
NULL);
|
||||
|
|
@ -287,6 +329,11 @@ static int obs_init_graphics(struct obs_video_info *ovi)
|
|||
NULL);
|
||||
bfree(filename);
|
||||
|
||||
filename = obs_find_data_file("area.effect");
|
||||
video->area_effect = gs_effect_create_from_file(filename,
|
||||
NULL);
|
||||
bfree(filename);
|
||||
|
||||
filename = obs_find_data_file("bilinear_lowres_scale.effect");
|
||||
video->bilinear_lowres_effect = gs_effect_create_from_file(filename,
|
||||
NULL);
|
||||
|
|
@ -297,6 +344,7 @@ static int obs_init_graphics(struct obs_video_info *ovi)
|
|||
NULL);
|
||||
bfree(filename);
|
||||
|
||||
point_sampler.max_anisotropy = 1;
|
||||
video->point_sampler = gs_samplerstate_create(&point_sampler);
|
||||
|
||||
obs->video.transparent_texture = gs_texture_create(2, 2, GS_RGBA, 1,
|
||||
|
|
@ -351,6 +399,7 @@ static int obs_init_video(struct obs_video_info *ovi)
|
|||
{
|
||||
struct obs_core_video *video = &obs->video;
|
||||
struct video_output_info vi;
|
||||
pthread_mutexattr_t attr;
|
||||
int errorcode;
|
||||
|
||||
make_video_info(&vi, ovi);
|
||||
|
|
@ -384,6 +433,13 @@ static int obs_init_video(struct obs_video_info *ovi)
|
|||
|
||||
gs_leave_context();
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return OBS_VIDEO_FAIL;
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
||||
return OBS_VIDEO_FAIL;
|
||||
if (pthread_mutex_init(&video->gpu_encoder_mutex, NULL) < 0)
|
||||
return OBS_VIDEO_FAIL;
|
||||
|
||||
errorcode = pthread_create(&video->video_thread, NULL,
|
||||
obs_graphics_thread, obs);
|
||||
if (errorcode != 0)
|
||||
|
|
@ -431,17 +487,20 @@ static void obs_free_video(void)
|
|||
gs_stagesurface_destroy(video->copy_surfaces[i]);
|
||||
gs_texture_destroy(video->render_textures[i]);
|
||||
gs_texture_destroy(video->convert_textures[i]);
|
||||
gs_texture_destroy(video->convert_uv_textures[i]);
|
||||
gs_texture_destroy(video->output_textures[i]);
|
||||
|
||||
video->copy_surfaces[i] = NULL;
|
||||
video->render_textures[i] = NULL;
|
||||
video->convert_textures[i] = NULL;
|
||||
video->output_textures[i] = NULL;
|
||||
video->copy_surfaces[i] = NULL;
|
||||
video->render_textures[i] = NULL;
|
||||
video->convert_textures[i] = NULL;
|
||||
video->convert_uv_textures[i] = NULL;
|
||||
video->output_textures[i] = NULL;
|
||||
}
|
||||
|
||||
gs_leave_context();
|
||||
|
||||
circlebuf_free(&video->vframe_info_buffer);
|
||||
circlebuf_free(&video->vframe_info_buffer_gpu);
|
||||
|
||||
memset(&video->textures_rendered, 0,
|
||||
sizeof(video->textures_rendered));
|
||||
|
|
@ -452,6 +511,11 @@ static void obs_free_video(void)
|
|||
memset(&video->textures_converted, 0,
|
||||
sizeof(video->textures_converted));
|
||||
|
||||
pthread_mutex_destroy(&video->gpu_encoder_mutex);
|
||||
pthread_mutex_init_value(&video->gpu_encoder_mutex);
|
||||
da_free(video->gpu_encoders);
|
||||
|
||||
video->gpu_encoder_active = 0;
|
||||
video->cur_texture = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -473,7 +537,9 @@ static void obs_free_graphics(void)
|
|||
gs_effect_destroy(video->solid_effect);
|
||||
gs_effect_destroy(video->conversion_effect);
|
||||
gs_effect_destroy(video->bicubic_effect);
|
||||
gs_effect_destroy(video->repeat_effect);
|
||||
gs_effect_destroy(video->lanczos_effect);
|
||||
gs_effect_destroy(video->area_effect);
|
||||
gs_effect_destroy(video->bilinear_lowres_effect);
|
||||
video->default_effect = NULL;
|
||||
|
||||
|
|
@ -753,6 +819,7 @@ static bool obs_init(const char *locale, const char *module_config_path,
|
|||
obs = bzalloc(sizeof(struct obs_core));
|
||||
|
||||
pthread_mutex_init_value(&obs->audio.monitoring_mutex);
|
||||
pthread_mutex_init_value(&obs->video.gpu_encoder_mutex);
|
||||
|
||||
obs->name_store_owned = !store;
|
||||
obs->name_store = store ? store : profiler_name_store_create();
|
||||
|
|
@ -853,6 +920,42 @@ bool obs_startup(const char *locale, const char *module_config_path,
|
|||
return success;
|
||||
}
|
||||
|
||||
static struct obs_cmdline_args cmdline_args = {0, NULL};
|
||||
void obs_set_cmdline_args(int argc, const char * const *argv)
|
||||
{
|
||||
char *data;
|
||||
size_t len;
|
||||
int i;
|
||||
|
||||
/* Once argc is set (non-zero) we shouldn't call again */
|
||||
if (cmdline_args.argc)
|
||||
return;
|
||||
|
||||
cmdline_args.argc = argc;
|
||||
|
||||
/* Safely copy over argv */
|
||||
len = 0;
|
||||
for (i = 0; i < argc; i++)
|
||||
len += strlen(argv[i]) + 1;
|
||||
|
||||
cmdline_args.argv = bmalloc(sizeof(char *) * (argc + 1) + len);
|
||||
data = (char *) cmdline_args.argv + sizeof(char *) * (argc + 1);
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
cmdline_args.argv[i] = data;
|
||||
len = strlen(argv[i]) + 1;
|
||||
memcpy(data, argv[i], len);
|
||||
data += len;
|
||||
}
|
||||
|
||||
cmdline_args.argv[argc] = NULL;
|
||||
}
|
||||
|
||||
struct obs_cmdline_args obs_get_cmdline_args(void)
|
||||
{
|
||||
return cmdline_args;
|
||||
}
|
||||
|
||||
void obs_shutdown(void)
|
||||
{
|
||||
struct obs_module *module;
|
||||
|
|
@ -918,6 +1021,7 @@ void obs_shutdown(void)
|
|||
bfree(core->module_config_path);
|
||||
bfree(core->locale);
|
||||
bfree(core);
|
||||
bfree(cmdline_args.argv);
|
||||
|
||||
#ifdef _WIN32
|
||||
uninitialize_com();
|
||||
|
|
@ -977,7 +1081,7 @@ int obs_reset_video(struct obs_video_info *ovi)
|
|||
if (!obs) return OBS_VIDEO_FAIL;
|
||||
|
||||
/* don't allow changing of video settings if active. */
|
||||
if (obs->video.video && video_output_active(obs->video.video))
|
||||
if (obs->video.video && obs_video_active())
|
||||
return OBS_VIDEO_CURRENTLY_ACTIVE;
|
||||
|
||||
if (!size_valid(ovi->output_width, ovi->output_height) ||
|
||||
|
|
@ -1018,11 +1122,15 @@ int obs_reset_video(struct obs_video_info *ovi)
|
|||
case OBS_SCALE_LANCZOS:
|
||||
scale_type_name = "Lanczos";
|
||||
break;
|
||||
case OBS_SCALE_AREA:
|
||||
scale_type_name = "Area";
|
||||
break;
|
||||
}
|
||||
|
||||
bool yuv = format_is_yuv(ovi->output_format);
|
||||
const char *yuv_format = get_video_colorspace_name(ovi->colorspace);
|
||||
const char *yuv_range = get_video_range_name(ovi->range);
|
||||
const char *yuv_range = get_video_range_name(ovi->output_format,
|
||||
ovi->range);
|
||||
|
||||
blog(LOG_INFO, "---------------------------------");
|
||||
blog(LOG_INFO, "video settings reset:\n"
|
||||
|
|
@ -1323,6 +1431,31 @@ void obs_enum_sources(bool (*enum_proc)(void*, obs_source_t*), void *param)
|
|||
pthread_mutex_unlock(&obs->data.sources_mutex);
|
||||
}
|
||||
|
||||
void obs_enum_scenes(bool (*enum_proc)(void*, obs_source_t*), void *param)
|
||||
{
|
||||
obs_source_t *source;
|
||||
|
||||
if (!obs) return;
|
||||
|
||||
pthread_mutex_lock(&obs->data.sources_mutex);
|
||||
source = obs->data.first_source;
|
||||
|
||||
while (source) {
|
||||
obs_source_t *next_source =
|
||||
(obs_source_t*)source->context.next;
|
||||
|
||||
if (source->info.type == OBS_SOURCE_TYPE_SCENE &&
|
||||
!source->context.private &&
|
||||
!enum_proc(param, source)) {
|
||||
break;
|
||||
}
|
||||
|
||||
source = next_source;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&obs->data.sources_mutex);
|
||||
}
|
||||
|
||||
static inline void obs_enum(void *pstart, pthread_mutex_t *mutex, void *proc,
|
||||
void *param)
|
||||
{
|
||||
|
|
@ -1454,10 +1587,14 @@ gs_effect_t *obs_get_base_effect(enum obs_base_effect effect)
|
|||
return obs->video.opaque_effect;
|
||||
case OBS_EFFECT_SOLID:
|
||||
return obs->video.solid_effect;
|
||||
case OBS_EFFECT_REPEAT:
|
||||
return obs->video.repeat_effect;
|
||||
case OBS_EFFECT_BICUBIC:
|
||||
return obs->video.bicubic_effect;
|
||||
case OBS_EFFECT_LANCZOS:
|
||||
return obs->video.lanczos_effect;
|
||||
case OBS_EFFECT_AREA:
|
||||
return obs->video.area_effect;
|
||||
case OBS_EFFECT_BILINEAR_LOWRES:
|
||||
return obs->video.bilinear_lowres_effect;
|
||||
case OBS_EFFECT_PREMULTIPLIED_ALPHA:
|
||||
|
|
@ -1514,8 +1651,13 @@ void obs_render_main_texture(void)
|
|||
param = gs_effect_get_param_by_name(effect, "image");
|
||||
gs_effect_set_texture(param, tex);
|
||||
|
||||
gs_blend_state_push();
|
||||
gs_blend_function(GS_BLEND_ONE, GS_BLEND_INVSRCALPHA);
|
||||
|
||||
while (gs_effect_loop(effect, "Draw"))
|
||||
gs_draw_sprite(tex, 0, 0, 0);
|
||||
|
||||
gs_blend_state_pop();
|
||||
}
|
||||
|
||||
gs_texture_t *obs_get_main_texture(void)
|
||||
|
|
@ -1563,6 +1705,7 @@ static obs_source_t *obs_load_source_type(obs_data_t *source_data)
|
|||
obs_data_t *settings = obs_data_get_obj(source_data, "settings");
|
||||
obs_data_t *hotkeys = obs_data_get_obj(source_data, "hotkeys");
|
||||
double volume;
|
||||
double balance;
|
||||
int64_t sync;
|
||||
uint32_t flags;
|
||||
uint32_t mixers;
|
||||
|
|
@ -1578,6 +1721,10 @@ static obs_source_t *obs_load_source_type(obs_data_t *source_data)
|
|||
volume = obs_data_get_double(source_data, "volume");
|
||||
obs_source_set_volume(source, (float)volume);
|
||||
|
||||
obs_data_set_default_double(source_data, "balance", 0.5);
|
||||
balance = obs_data_get_double(source_data, "balance");
|
||||
obs_source_set_balance_value(source, (float)balance);
|
||||
|
||||
sync = obs_data_get_int(source_data, "sync");
|
||||
obs_source_set_sync_offset(source, sync);
|
||||
|
||||
|
|
@ -1694,6 +1841,11 @@ void obs_load_sources(obs_data_array_t *array, obs_load_source_cb cb,
|
|||
if (source->info.type == OBS_SOURCE_TYPE_TRANSITION)
|
||||
obs_transition_load(source, source_data);
|
||||
obs_source_load(source);
|
||||
for (size_t i = source->filters.num; i > 0; i--) {
|
||||
obs_source_t *filter =
|
||||
source->filters.array[i - 1];
|
||||
obs_source_load(filter);
|
||||
}
|
||||
if (cb)
|
||||
cb(private_data, source);
|
||||
}
|
||||
|
|
@ -1716,6 +1868,7 @@ obs_data_t *obs_save_source(obs_source_t *source)
|
|||
obs_data_t *hotkey_data = source->context.hotkey_data;
|
||||
obs_data_t *hotkeys;
|
||||
float volume = obs_source_get_volume(source);
|
||||
float balance = obs_source_get_balance_value(source);
|
||||
uint32_t mixers = obs_source_get_audio_mixers(source);
|
||||
int64_t sync = obs_source_get_sync_offset(source);
|
||||
uint32_t flags = obs_source_get_flags(source);
|
||||
|
|
@ -1748,6 +1901,7 @@ obs_data_t *obs_save_source(obs_source_t *source)
|
|||
obs_data_set_int (source_data, "sync", sync);
|
||||
obs_data_set_int (source_data, "flags", flags);
|
||||
obs_data_set_double(source_data, "volume", volume);
|
||||
obs_data_set_double(source_data, "balance", balance);
|
||||
obs_data_set_bool (source_data, "enabled", enabled);
|
||||
obs_data_set_bool (source_data, "muted", muted);
|
||||
obs_data_set_bool (source_data, "push-to-mute", push_to_mute);
|
||||
|
|
@ -2013,6 +2167,15 @@ bool obs_obj_invalid(void *obj)
|
|||
return !context->data;
|
||||
}
|
||||
|
||||
void *obs_obj_get_data(void *obj)
|
||||
{
|
||||
struct obs_context_data *context = obj;
|
||||
if (!context)
|
||||
return NULL;
|
||||
|
||||
return context->data;
|
||||
}
|
||||
|
||||
bool obs_set_audio_monitoring_device(const char *name, const char *id)
|
||||
{
|
||||
if (!obs || !name || !id || !*name || !*id)
|
||||
|
|
@ -2189,3 +2352,79 @@ obs_data_t *obs_get_private_data(void)
|
|||
obs_data_addref(private_data);
|
||||
return private_data;
|
||||
}
|
||||
|
||||
extern bool init_gpu_encoding(struct obs_core_video *video);
|
||||
extern void stop_gpu_encoding_thread(struct obs_core_video *video);
|
||||
extern void free_gpu_encoding(struct obs_core_video *video);
|
||||
|
||||
bool start_gpu_encode(obs_encoder_t *encoder)
|
||||
{
|
||||
struct obs_core_video *video = &obs->video;
|
||||
bool success = true;
|
||||
|
||||
obs_enter_graphics();
|
||||
pthread_mutex_lock(&video->gpu_encoder_mutex);
|
||||
|
||||
if (!video->gpu_encoders.num)
|
||||
success = init_gpu_encoding(video);
|
||||
if (success)
|
||||
da_push_back(video->gpu_encoders, &encoder);
|
||||
else
|
||||
free_gpu_encoding(video);
|
||||
|
||||
pthread_mutex_unlock(&video->gpu_encoder_mutex);
|
||||
obs_leave_graphics();
|
||||
|
||||
if (success) {
|
||||
os_atomic_inc_long(&video->gpu_encoder_active);
|
||||
video_output_inc_texture_encoders(video->video);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void stop_gpu_encode(obs_encoder_t *encoder)
|
||||
{
|
||||
struct obs_core_video *video = &obs->video;
|
||||
bool call_free = false;
|
||||
|
||||
os_atomic_dec_long(&video->gpu_encoder_active);
|
||||
video_output_dec_texture_encoders(video->video);
|
||||
|
||||
pthread_mutex_lock(&video->gpu_encoder_mutex);
|
||||
da_erase_item(video->gpu_encoders, &encoder);
|
||||
if (!video->gpu_encoders.num)
|
||||
call_free = true;
|
||||
pthread_mutex_unlock(&video->gpu_encoder_mutex);
|
||||
|
||||
os_event_wait(video->gpu_encode_inactive);
|
||||
|
||||
if (call_free) {
|
||||
stop_gpu_encoding_thread(video);
|
||||
|
||||
obs_enter_graphics();
|
||||
pthread_mutex_lock(&video->gpu_encoder_mutex);
|
||||
free_gpu_encoding(video);
|
||||
pthread_mutex_unlock(&video->gpu_encoder_mutex);
|
||||
obs_leave_graphics();
|
||||
}
|
||||
}
|
||||
|
||||
bool obs_video_active(void)
|
||||
{
|
||||
struct obs_core_video *video = &obs->video;
|
||||
if (!obs)
|
||||
return false;
|
||||
|
||||
return os_atomic_load_long(&video->raw_active) > 0 ||
|
||||
os_atomic_load_long(&video->gpu_encoder_active) > 0;
|
||||
}
|
||||
|
||||
bool obs_nv12_tex_active(void)
|
||||
{
|
||||
struct obs_core_video *video = &obs->video;
|
||||
if (!obs)
|
||||
return false;
|
||||
|
||||
return video->using_nv12_tex;
|
||||
}
|
||||
|
|
|
|||
132
libobs/obs.h
132
libobs/obs.h
|
|
@ -116,7 +116,8 @@ enum obs_scale_type {
|
|||
OBS_SCALE_POINT,
|
||||
OBS_SCALE_BICUBIC,
|
||||
OBS_SCALE_BILINEAR,
|
||||
OBS_SCALE_LANCZOS
|
||||
OBS_SCALE_LANCZOS,
|
||||
OBS_SCALE_AREA,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -219,6 +220,10 @@ struct obs_source_audio {
|
|||
*
|
||||
* If a YUV format is specified, it will be automatically upsampled and
|
||||
* converted to RGB via shader on the graphics processor.
|
||||
*
|
||||
* NOTE: Non-YUV formats will always be treated as full range with this
|
||||
* structure! Use obs_source_frame2 along with obs_source_output_video2
|
||||
* instead if partial range support is desired for non-YUV video formats.
|
||||
*/
|
||||
struct obs_source_frame {
|
||||
uint8_t *data[MAX_AV_PLANES];
|
||||
|
|
@ -239,6 +244,27 @@ struct obs_source_frame {
|
|||
bool prev_frame;
|
||||
};
|
||||
|
||||
struct obs_source_frame2 {
|
||||
uint8_t *data[MAX_AV_PLANES];
|
||||
uint32_t linesize[MAX_AV_PLANES];
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint64_t timestamp;
|
||||
|
||||
enum video_format format;
|
||||
enum video_range_type range;
|
||||
float color_matrix[16];
|
||||
float color_range_min[3];
|
||||
float color_range_max[3];
|
||||
bool flip;
|
||||
};
|
||||
|
||||
/** Access to the argc/argv used to start OBS. What you see is what you get. */
|
||||
struct obs_cmdline_args {
|
||||
int argc;
|
||||
char **argv;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* OBS context */
|
||||
|
||||
|
|
@ -291,6 +317,24 @@ EXPORT uint32_t obs_get_version(void);
|
|||
/** @return The current core version string */
|
||||
EXPORT const char *obs_get_version_string(void);
|
||||
|
||||
/**
|
||||
* Sets things up for calls to obs_get_cmdline_args. Called onl yonce at startup
|
||||
* and safely copies argv/argc from main(). Subsequent calls do nothing.
|
||||
*
|
||||
* @param argc The count of command line arguments, from main()
|
||||
* @param argv An array of command line arguments, copied from main() and ends
|
||||
* with NULL.
|
||||
*/
|
||||
EXPORT void obs_set_cmdline_args(int argc, const char * const *argv);
|
||||
|
||||
/**
|
||||
* Get the argc/argv used to start OBS
|
||||
*
|
||||
* @return The command line arguments used for main(). Don't modify this or
|
||||
* you'll mess things up for other callers.
|
||||
*/
|
||||
EXPORT struct obs_cmdline_args obs_get_cmdline_args(void);
|
||||
|
||||
/**
|
||||
* Sets a new locale to use for modules. This will call obs_module_set_locale
|
||||
* for each module with the new locale.
|
||||
|
|
@ -511,6 +555,9 @@ EXPORT audio_t *obs_get_audio(void);
|
|||
/** Gets the main video output handler for this OBS context */
|
||||
EXPORT video_t *obs_get_video(void);
|
||||
|
||||
/** Returns true if video is active, false otherwise */
|
||||
EXPORT bool obs_video_active(void);
|
||||
|
||||
/** Sets the primary output source for a channel. */
|
||||
EXPORT void obs_set_output_source(uint32_t channel, obs_source_t *source);
|
||||
|
||||
|
|
@ -532,6 +579,10 @@ EXPORT obs_source_t *obs_get_output_source(uint32_t channel);
|
|||
EXPORT void obs_enum_sources(bool (*enum_proc)(void*, obs_source_t*),
|
||||
void *param);
|
||||
|
||||
/** Enumerates scenes */
|
||||
EXPORT void obs_enum_scenes(bool (*enum_proc)(void*, obs_source_t*),
|
||||
void *param);
|
||||
|
||||
/** Enumerates outputs */
|
||||
EXPORT void obs_enum_outputs(bool (*enum_proc)(void*, obs_output_t*),
|
||||
void *param);
|
||||
|
|
@ -570,6 +621,8 @@ enum obs_base_effect {
|
|||
OBS_EFFECT_LANCZOS, /**< Lanczos downscale */
|
||||
OBS_EFFECT_BILINEAR_LOWRES, /**< Bilinear low resolution downscale */
|
||||
OBS_EFFECT_PREMULTIPLIED_ALPHA,/**< Premultiplied alpha */
|
||||
OBS_EFFECT_REPEAT, /**< RGB/YUV (repeating) */
|
||||
OBS_EFFECT_AREA, /**< Area rescale */
|
||||
};
|
||||
|
||||
/** Returns a commonly used base effect */
|
||||
|
|
@ -642,6 +695,7 @@ enum obs_obj_type {
|
|||
EXPORT enum obs_obj_type obs_obj_get_type(void *obj);
|
||||
EXPORT const char *obs_obj_get_id(void *obj);
|
||||
EXPORT bool obs_obj_invalid(void *obj);
|
||||
EXPORT void *obs_obj_get_data(void *obj);
|
||||
|
||||
typedef bool (*obs_enum_audio_device_cb)(void *data, const char *name,
|
||||
const char *id);
|
||||
|
|
@ -682,6 +736,8 @@ EXPORT uint64_t obs_get_average_frame_time_ns(void);
|
|||
EXPORT uint32_t obs_get_total_frames(void);
|
||||
EXPORT uint32_t obs_get_lagged_frames(void);
|
||||
|
||||
EXPORT bool obs_nv12_tex_active(void);
|
||||
|
||||
EXPORT void obs_apply_private_data(obs_data_t *settings);
|
||||
EXPORT void obs_set_private_data(obs_data_t *settings);
|
||||
EXPORT obs_data_t *obs_get_private_data(void);
|
||||
|
|
@ -724,7 +780,8 @@ EXPORT void obs_view_render(obs_view_t *view);
|
|||
* @return The new display context, or NULL if failed.
|
||||
*/
|
||||
EXPORT obs_display_t *obs_display_create(
|
||||
const struct gs_init_data *graphics_data);
|
||||
const struct gs_init_data *graphics_data,
|
||||
uint32_t backround_color);
|
||||
|
||||
/** Destroys a display context */
|
||||
EXPORT void obs_display_destroy(obs_display_t *display);
|
||||
|
|
@ -756,6 +813,9 @@ EXPORT bool obs_display_enabled(obs_display_t *display);
|
|||
EXPORT void obs_display_set_background_color(obs_display_t *display,
|
||||
uint32_t color);
|
||||
|
||||
EXPORT void obs_display_size(obs_display_t *display,
|
||||
uint32_t *width, uint32_t *height);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Sources */
|
||||
|
|
@ -893,6 +953,15 @@ EXPORT void obs_source_set_volume(obs_source_t *source, float volume);
|
|||
/** Gets the user volume for a source that has audio output */
|
||||
EXPORT float obs_source_get_volume(const obs_source_t *source);
|
||||
|
||||
/* Gets speaker layout of a source */
|
||||
EXPORT enum speaker_layout obs_source_get_speaker_layout(obs_source_t *source);
|
||||
|
||||
/** Sets the balance value for a stereo audio source */
|
||||
EXPORT void obs_source_set_balance_value(obs_source_t *source, float balance);
|
||||
|
||||
/** Gets the balance value for a stereo audio source */
|
||||
EXPORT float obs_source_get_balance_value(const obs_source_t *source);
|
||||
|
||||
/** Sets the audio sync offset (in nanoseconds) for a source */
|
||||
EXPORT void obs_source_set_sync_offset(obs_source_t *source, int64_t offset);
|
||||
|
||||
|
|
@ -948,6 +1017,18 @@ EXPORT uint32_t obs_source_get_audio_mixers(const obs_source_t *source);
|
|||
*/
|
||||
EXPORT void obs_source_inc_showing(obs_source_t *source);
|
||||
|
||||
/**
|
||||
* Increments the 'active' reference counter to indicate that the source is
|
||||
* fully active. If the reference counter was 0, will call the 'activate'
|
||||
* callback.
|
||||
*
|
||||
* Unlike obs_source_inc_showing, this will cause children of this source to be
|
||||
* considered showing as well (currently used by transition previews to make
|
||||
* the stinger transition show correctly). obs_source_inc_showing should
|
||||
* generally be used instead.
|
||||
*/
|
||||
EXPORT void obs_source_inc_active(obs_source_t *source);
|
||||
|
||||
/**
|
||||
* Decrements the 'showing' reference counter to indicate that the source is
|
||||
* no longer being shown somewhere. If the reference counter is set to 0,
|
||||
|
|
@ -955,6 +1036,17 @@ EXPORT void obs_source_inc_showing(obs_source_t *source);
|
|||
*/
|
||||
EXPORT void obs_source_dec_showing(obs_source_t *source);
|
||||
|
||||
/**
|
||||
* Decrements the 'active' reference counter to indicate that the source is no
|
||||
* longer fully active. If the reference counter is set to 0, will call the
|
||||
* 'deactivate' callback
|
||||
*
|
||||
* Unlike obs_source_dec_showing, this will cause children of this source to be
|
||||
* considered not showing as well. obs_source_dec_showing should generally be
|
||||
* used instead.
|
||||
*/
|
||||
EXPORT void obs_source_dec_active(obs_source_t *source);
|
||||
|
||||
/** Enumerates filters assigned to the source */
|
||||
EXPORT void obs_source_enum_filters(obs_source_t *source,
|
||||
obs_source_enum_proc_t callback, void *param);
|
||||
|
|
@ -1070,13 +1162,29 @@ EXPORT void obs_source_draw_set_color_matrix(
|
|||
EXPORT void obs_source_draw(gs_texture_t *image, int x, int y,
|
||||
uint32_t cx, uint32_t cy, bool flip);
|
||||
|
||||
/** Outputs asynchronous video data. Set to NULL to deactivate the texture */
|
||||
/**
|
||||
* Outputs asynchronous video data. Set to NULL to deactivate the texture
|
||||
*
|
||||
* NOTE: Non-YUV formats will always be treated as full range with this
|
||||
* function! Use obs_source_output_video2 instead if partial range support is
|
||||
* desired for non-YUV video formats.
|
||||
*/
|
||||
EXPORT void obs_source_output_video(obs_source_t *source,
|
||||
const struct obs_source_frame *frame);
|
||||
EXPORT void obs_source_output_video2(obs_source_t *source,
|
||||
const struct obs_source_frame2 *frame);
|
||||
|
||||
/** Preloads asynchronous video data to allow instantaneous playback */
|
||||
/**
|
||||
* Preloads asynchronous video data to allow instantaneous playback
|
||||
*
|
||||
* NOTE: Non-YUV formats will always be treated as full range with this
|
||||
* function! Use obs_source_preload_video2 instead if partial range support is
|
||||
* desired for non-YUV video formats.
|
||||
*/
|
||||
EXPORT void obs_source_preload_video(obs_source_t *source,
|
||||
const struct obs_source_frame *frame);
|
||||
EXPORT void obs_source_preload_video2(obs_source_t *source,
|
||||
const struct obs_source_frame2 *frame);
|
||||
|
||||
/** Shows any preloaded video data */
|
||||
EXPORT void obs_source_show_preloaded_video(obs_source_t *source);
|
||||
|
|
@ -1257,6 +1365,8 @@ typedef float (*obs_transition_audio_mix_callback_t)(void *data, float t);
|
|||
|
||||
EXPORT float obs_transition_get_time(obs_source_t *transition);
|
||||
|
||||
EXPORT void obs_transition_force_stop(obs_source_t *transition);
|
||||
|
||||
EXPORT void obs_transition_video_render(obs_source_t *transition,
|
||||
obs_transition_video_render_callback_t callback);
|
||||
|
||||
|
|
@ -1406,6 +1516,8 @@ EXPORT void obs_sceneitem_get_draw_transform(const obs_sceneitem_t *item,
|
|||
struct matrix4 *transform);
|
||||
EXPORT void obs_sceneitem_get_box_transform(const obs_sceneitem_t *item,
|
||||
struct matrix4 *transform);
|
||||
EXPORT void obs_sceneitem_get_box_scale(const obs_sceneitem_t *item,
|
||||
struct vec2 *scale);
|
||||
|
||||
EXPORT bool obs_sceneitem_visible(const obs_sceneitem_t *item);
|
||||
EXPORT bool obs_sceneitem_set_visible(obs_sceneitem_t *item, bool visible);
|
||||
|
|
@ -1594,6 +1706,12 @@ EXPORT void obs_output_set_mixer(obs_output_t *output, size_t mixer_idx);
|
|||
/** Gets the current audio mixer for non-encoded outputs */
|
||||
EXPORT size_t obs_output_get_mixer(const obs_output_t *output);
|
||||
|
||||
/** Sets the current audio mixes (mask) for a non-encoded multi-track output */
|
||||
EXPORT void obs_output_set_mixers(obs_output_t *output, size_t mixers);
|
||||
|
||||
/** Gets the current audio mixes (mask) for a non-encoded multi-track output */
|
||||
EXPORT size_t obs_output_get_mixers(const obs_output_t *output);
|
||||
|
||||
/**
|
||||
* Sets the current video encoder associated with this output,
|
||||
* required for encoded outputs
|
||||
|
|
@ -1664,6 +1782,8 @@ EXPORT const char *obs_output_get_id(const obs_output_t *output);
|
|||
#if BUILD_CAPTIONS
|
||||
EXPORT void obs_output_output_caption_text1(obs_output_t *output,
|
||||
const char *text);
|
||||
EXPORT void obs_output_output_caption_text2(obs_output_t *output,
|
||||
const char *text, double display_duration);
|
||||
#endif
|
||||
|
||||
EXPORT float obs_output_get_congestion(obs_output_t *output);
|
||||
|
|
@ -1871,6 +1991,7 @@ EXPORT void *obs_encoder_get_type_data(obs_encoder_t *encoder);
|
|||
EXPORT const char *obs_encoder_get_id(const obs_encoder_t *encoder);
|
||||
|
||||
EXPORT uint32_t obs_get_encoder_caps(const char *encoder_id);
|
||||
EXPORT uint32_t obs_encoder_get_caps(const obs_encoder_t *encoder);
|
||||
|
||||
#ifndef SWIG
|
||||
/** Duplicates an encoder packet */
|
||||
|
|
@ -1886,6 +2007,9 @@ EXPORT void obs_encoder_packet_ref(struct encoder_packet *dst,
|
|||
struct encoder_packet *src);
|
||||
EXPORT void obs_encoder_packet_release(struct encoder_packet *packet);
|
||||
|
||||
EXPORT void *obs_encoder_create_rerouted(obs_encoder_t *encoder,
|
||||
const char *reroute_id);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Stream Services */
|
||||
|
|
|
|||
17
libobs/util/apple/cfstring-utils.h
Normal file
17
libobs/util/apple/cfstring-utils.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "../c99defs.h"
|
||||
#include "../dstr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
EXPORT char *cfstr_copy_cstr(CFStringRef cfstr, CFStringEncoding cfstr_enc);
|
||||
|
||||
EXPORT bool cfstr_copy_dstr(CFStringRef cfstr, CFStringEncoding cfstr_enc,
|
||||
struct dstr *str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -292,7 +292,7 @@ static inline void circlebuf_pop_front(struct circlebuf *cb, void *data,
|
|||
static inline void circlebuf_pop_back(struct circlebuf *cb, void *data,
|
||||
size_t size)
|
||||
{
|
||||
circlebuf_peek_front(cb, data, size);
|
||||
circlebuf_peek_back(cb, data, size);
|
||||
|
||||
cb->size -= size;
|
||||
if (!cb->size) {
|
||||
|
|
@ -311,7 +311,7 @@ static inline void *circlebuf_data(struct circlebuf *cb, size_t idx)
|
|||
uint8_t *ptr = (uint8_t*)cb->data;
|
||||
size_t offset = cb->start_pos + idx;
|
||||
|
||||
if (idx > cb->size)
|
||||
if (idx >= cb->size)
|
||||
return NULL;
|
||||
|
||||
if (offset >= cb->capacity)
|
||||
|
|
|
|||
|
|
@ -359,6 +359,7 @@ int config_save(config_t *config)
|
|||
FILE *f;
|
||||
struct dstr str, tmp;
|
||||
size_t i, j;
|
||||
int ret = CONFIG_ERROR;
|
||||
|
||||
if (!config)
|
||||
return CONFIG_ERROR;
|
||||
|
|
@ -405,9 +406,15 @@ int config_save(config_t *config)
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
fwrite("\xEF\xBB\xBF", 1, 3, f);
|
||||
if (fwrite("\xEF\xBB\xBF", 3, 1, f) != 1)
|
||||
goto cleanup;
|
||||
#endif
|
||||
fwrite(str.array, 1, str.len, f);
|
||||
if (fwrite(str.array, str.len, 1, f) != 1)
|
||||
goto cleanup;
|
||||
|
||||
ret = CONFIG_SUCCESS;
|
||||
|
||||
cleanup:
|
||||
fclose(f);
|
||||
|
||||
pthread_mutex_unlock(&config->mutex);
|
||||
|
|
@ -415,7 +422,7 @@ int config_save(config_t *config)
|
|||
dstr_free(&tmp);
|
||||
dstr_free(&str);
|
||||
|
||||
return CONFIG_SUCCESS;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int config_save_safe(config_t *config, const char *temp_ext,
|
||||
|
|
@ -444,6 +451,8 @@ int config_save_safe(config_t *config, const char *temp_ext,
|
|||
config->file = file;
|
||||
|
||||
if (ret != CONFIG_SUCCESS) {
|
||||
blog(LOG_ERROR, "config_save_safe: failed to "
|
||||
"write to %s", temp_file.array);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,6 +73,15 @@ size_t os_process_pipe_read(os_process_pipe_t *pp, uint8_t *data, size_t len)
|
|||
return fread(data, 1, len, pp->file);
|
||||
}
|
||||
|
||||
size_t os_process_pipe_read_err(os_process_pipe_t *pp, uint8_t *data, size_t len)
|
||||
{
|
||||
/* XXX: unsupported on posix */
|
||||
UNUSED_PARAMETER(pp);
|
||||
UNUSED_PARAMETER(data);
|
||||
UNUSED_PARAMETER(len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t os_process_pipe_write(os_process_pipe_t *pp, const uint8_t *data,
|
||||
size_t len)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
struct os_process_pipe {
|
||||
bool read_pipe;
|
||||
HANDLE handle;
|
||||
HANDLE handle_err;
|
||||
HANDLE process;
|
||||
};
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ static bool create_pipe(HANDLE *input, HANDLE *output)
|
|||
}
|
||||
|
||||
static inline bool create_process(const char *cmd_line, HANDLE stdin_handle,
|
||||
HANDLE stdout_handle, HANDLE *process)
|
||||
HANDLE stdout_handle, HANDLE stderr_handle, HANDLE *process)
|
||||
{
|
||||
PROCESS_INFORMATION pi = {0};
|
||||
wchar_t *cmd_line_w = NULL;
|
||||
|
|
@ -53,6 +54,7 @@ static inline bool create_process(const char *cmd_line, HANDLE stdin_handle,
|
|||
si.dwFlags = STARTF_USESTDHANDLES | STARTF_FORCEOFFFEEDBACK;
|
||||
si.hStdInput = stdin_handle;
|
||||
si.hStdOutput = stdout_handle;
|
||||
si.hStdError = stderr_handle;
|
||||
|
||||
os_utf8_to_wcs_ptr(cmd_line, 0, &cmd_line_w);
|
||||
if (cmd_line_w) {
|
||||
|
|
@ -77,6 +79,7 @@ os_process_pipe_t *os_process_pipe_create(const char *cmd_line,
|
|||
bool read_pipe;
|
||||
HANDLE process;
|
||||
HANDLE output;
|
||||
HANDLE err_input, err_output;
|
||||
HANDLE input;
|
||||
bool success;
|
||||
|
||||
|
|
@ -90,26 +93,38 @@ os_process_pipe_t *os_process_pipe_create(const char *cmd_line,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!create_pipe(&err_input, &err_output)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
read_pipe = *type == 'r';
|
||||
|
||||
success = !!SetHandleInformation(read_pipe ? input : output,
|
||||
HANDLE_FLAG_INHERIT, false);
|
||||
HANDLE_FLAG_INHERIT, false);
|
||||
if (!success) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
success = !!SetHandleInformation(err_input, HANDLE_FLAG_INHERIT, false);
|
||||
if (!success) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
success = create_process(cmd_line, read_pipe ? NULL : input,
|
||||
read_pipe ? output : NULL, &process);
|
||||
read_pipe ? output : NULL, err_output, &process);
|
||||
if (!success) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
pp = bmalloc(sizeof(*pp));
|
||||
|
||||
pp->handle = read_pipe ? input : output;
|
||||
pp->read_pipe = read_pipe;
|
||||
pp->process = process;
|
||||
pp->handle_err = err_input;
|
||||
|
||||
CloseHandle(read_pipe ? output : input);
|
||||
CloseHandle(err_output);
|
||||
return pp;
|
||||
|
||||
error:
|
||||
|
|
@ -126,6 +141,7 @@ int os_process_pipe_destroy(os_process_pipe_t *pp)
|
|||
DWORD code;
|
||||
|
||||
CloseHandle(pp->handle);
|
||||
CloseHandle(pp->handle_err);
|
||||
|
||||
WaitForSingleObject(pp->process, INFINITE);
|
||||
if (GetExitCodeProcess(pp->process, &code))
|
||||
|
|
@ -158,6 +174,25 @@ size_t os_process_pipe_read(os_process_pipe_t *pp, uint8_t *data, size_t len)
|
|||
return 0;
|
||||
}
|
||||
|
||||
size_t os_process_pipe_read_err(os_process_pipe_t *pp, uint8_t *data, size_t len)
|
||||
{
|
||||
DWORD bytes_read;
|
||||
bool success;
|
||||
|
||||
if (!pp || !pp->handle_err) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
success = !!ReadFile(pp->handle_err, data, (DWORD)len, &bytes_read, NULL);
|
||||
if (success && bytes_read) {
|
||||
return bytes_read;
|
||||
}
|
||||
else
|
||||
bytes_read = GetLastError();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t os_process_pipe_write(os_process_pipe_t *pp, const uint8_t *data,
|
||||
size_t len)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,5 +27,7 @@ EXPORT int os_process_pipe_destroy(os_process_pipe_t *pp);
|
|||
|
||||
EXPORT size_t os_process_pipe_read(os_process_pipe_t *pp, uint8_t *data,
|
||||
size_t len);
|
||||
EXPORT size_t os_process_pipe_read_err(os_process_pipe_t *pp, uint8_t *data,
|
||||
size_t len);
|
||||
EXPORT size_t os_process_pipe_write(os_process_pipe_t *pp, const uint8_t *data,
|
||||
size_t len);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2014 Ruwen Hahn <palana@stunned.de>
|
||||
* Copyright (c) 2013-2018 Ruwen Hahn <palana@stunned.de>
|
||||
* Hugh "Jim" Bailey <obs.jim@gmail.com>
|
||||
* Marvin Scholz <epirat07@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
|
@ -23,16 +24,20 @@
|
|||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <mach/mach.h>
|
||||
#include <mach/mach_time.h>
|
||||
#include <mach-o/dyld.h>
|
||||
|
||||
#include <IOKit/pwr_mgt/IOPMLib.h>
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "apple/cfstring-utils.h"
|
||||
|
||||
/* clock function selection taken from libc++ */
|
||||
static uint64_t ns_time_simple()
|
||||
{
|
||||
|
|
@ -137,6 +142,35 @@ char *os_get_program_data_path_ptr(const char *name)
|
|||
return os_get_path_ptr_internal(name, NSLocalDomainMask);
|
||||
}
|
||||
|
||||
char *os_get_executable_path_ptr(const char *name)
|
||||
{
|
||||
char exe[PATH_MAX];
|
||||
char abs_path[PATH_MAX];
|
||||
uint32_t size = sizeof(exe);
|
||||
struct dstr path;
|
||||
char *slash;
|
||||
|
||||
if (_NSGetExecutablePath(exe, &size) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!realpath(exe, abs_path)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dstr_init_copy(&path, abs_path);
|
||||
slash = strrchr(path.array, '/');
|
||||
if (slash) {
|
||||
size_t len = slash - path.array + 1;
|
||||
dstr_resize(&path, len);
|
||||
}
|
||||
|
||||
if (name && *name) {
|
||||
dstr_cat(&path, name);
|
||||
}
|
||||
return path.array;
|
||||
}
|
||||
|
||||
struct os_cpu_usage_info {
|
||||
int64_t last_cpu_time;
|
||||
int64_t last_sys_time;
|
||||
|
|
@ -417,3 +451,90 @@ uint64_t os_get_proc_virtual_size(void)
|
|||
return 0;
|
||||
return taskinfo.virtual_size;
|
||||
}
|
||||
|
||||
/* Obtains a copy of the contents of a CFString in specified encoding.
|
||||
* Returns char* (must be bfree'd by caller) or NULL on failure.
|
||||
*/
|
||||
char *cfstr_copy_cstr(CFStringRef cfstring, CFStringEncoding cfstring_encoding)
|
||||
{
|
||||
if (!cfstring)
|
||||
return NULL;
|
||||
|
||||
// Try the quick way to obtain the buffer
|
||||
const char *tmp_buffer = CFStringGetCStringPtr(cfstring,
|
||||
cfstring_encoding);
|
||||
|
||||
if (tmp_buffer != NULL)
|
||||
return bstrdup(tmp_buffer);
|
||||
|
||||
// The quick way did not work, try the more expensive one
|
||||
CFIndex length = CFStringGetLength(cfstring);
|
||||
CFIndex max_size =
|
||||
CFStringGetMaximumSizeForEncoding(length, cfstring_encoding);
|
||||
|
||||
// If result would exceed LONG_MAX, kCFNotFound is returned
|
||||
if (max_size == kCFNotFound)
|
||||
return NULL;
|
||||
|
||||
// Account for the null terminator
|
||||
max_size++;
|
||||
|
||||
char *buffer = bmalloc(max_size);
|
||||
|
||||
if (buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Copy CFString in requested encoding to buffer
|
||||
Boolean success =
|
||||
CFStringGetCString(cfstring, buffer, max_size, cfstring_encoding);
|
||||
|
||||
if (!success) {
|
||||
bfree(buffer);
|
||||
buffer = NULL;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/* Copies the contents of a CFString in specified encoding to a given dstr.
|
||||
* Returns true on success or false on failure.
|
||||
* In case of failure, the dstr capacity but not size is changed.
|
||||
*/
|
||||
bool cfstr_copy_dstr(CFStringRef cfstring,
|
||||
CFStringEncoding cfstring_encoding, struct dstr *str)
|
||||
{
|
||||
if (!cfstring)
|
||||
return false;
|
||||
|
||||
// Try the quick way to obtain the buffer
|
||||
const char *tmp_buffer = CFStringGetCStringPtr(cfstring,
|
||||
cfstring_encoding);
|
||||
|
||||
if (tmp_buffer != NULL) {
|
||||
dstr_copy(str, tmp_buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
// The quick way did not work, try the more expensive one
|
||||
CFIndex length = CFStringGetLength(cfstring);
|
||||
CFIndex max_size =
|
||||
CFStringGetMaximumSizeForEncoding(length, cfstring_encoding);
|
||||
|
||||
// If result would exceed LONG_MAX, kCFNotFound is returned
|
||||
if (max_size == kCFNotFound)
|
||||
return NULL;
|
||||
|
||||
// Account for the null terminator
|
||||
max_size++;
|
||||
|
||||
dstr_ensure_capacity(str, max_size);
|
||||
|
||||
// Copy CFString in requested encoding to dstr buffer
|
||||
Boolean success = CFStringGetCString(
|
||||
cfstring, str->array, max_size, cfstring_encoding);
|
||||
|
||||
if (success)
|
||||
dstr_resize(str, max_size);
|
||||
|
||||
return (bool)success;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#if !defined(__APPLE__)
|
||||
#include <sys/times.h>
|
||||
#include <sys/wait.h>
|
||||
#include <libgen.h>
|
||||
#ifdef __FreeBSD__
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
|
@ -66,7 +67,11 @@ void *os_dlopen(const char *path)
|
|||
#endif
|
||||
dstr_cat(&dylib_name, ".so");
|
||||
|
||||
#ifdef __APPLE__
|
||||
void *res = dlopen(dylib_name.array, RTLD_LAZY | RTLD_FIRST);
|
||||
#else
|
||||
void *res = dlopen(dylib_name.array, RTLD_LAZY);
|
||||
#endif
|
||||
if (!res)
|
||||
blog(LOG_ERROR, "os_dlopen(%s->%s): %s\n",
|
||||
path, dylib_name.array, dlerror());
|
||||
|
|
@ -265,6 +270,32 @@ char *os_get_program_data_path_ptr(const char *name)
|
|||
return str;
|
||||
}
|
||||
|
||||
char *os_get_executable_path_ptr(const char *name)
|
||||
{
|
||||
char exe[PATH_MAX];
|
||||
ssize_t count = readlink("/proc/self/exe", exe, PATH_MAX);
|
||||
const char *path_out = NULL;
|
||||
struct dstr path;
|
||||
|
||||
if (count == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
path_out = dirname(exe);
|
||||
if (!path_out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dstr_init_copy(&path, path_out);
|
||||
dstr_cat(&path, "/");
|
||||
|
||||
if (name && *name) {
|
||||
dstr_cat(&path, name);
|
||||
}
|
||||
|
||||
return path.array;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool os_file_exists(const char *path)
|
||||
|
|
@ -848,7 +879,7 @@ static inline bool os_get_proc_memory_usage_internal(statm_t *statm)
|
|||
if (!f)
|
||||
return false;
|
||||
|
||||
if (fscanf(f, "%ld %ld %ld %ld %ld %ld %ld",
|
||||
if (fscanf(f, "%lu %lu %lu %lu %lu %lu %lu",
|
||||
&statm->virtual_size,
|
||||
&statm->resident_size,
|
||||
&statm->share_pages,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ static inline uint32_t get_winver(void)
|
|||
if (!winver) {
|
||||
struct win_version_info ver;
|
||||
get_win_ver(&ver);
|
||||
winver = (ver.major << 16) | ver.minor;
|
||||
winver = (ver.major << 8) | ver.minor;
|
||||
}
|
||||
|
||||
return winver;
|
||||
|
|
@ -92,6 +92,12 @@ void *os_dlopen(const char *path)
|
|||
|
||||
if (!h_library) {
|
||||
DWORD error = GetLastError();
|
||||
|
||||
/* don't print error for libraries that aren't meant to be
|
||||
* dynamically linked */
|
||||
if (error == ERROR_PROC_NOT_FOUND)
|
||||
return NULL;
|
||||
|
||||
char *message = NULL;
|
||||
|
||||
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
|
|
@ -289,6 +295,31 @@ char *os_get_program_data_path_ptr(const char *name)
|
|||
return os_get_path_ptr_internal(name, CSIDL_COMMON_APPDATA);
|
||||
}
|
||||
|
||||
char *os_get_executable_path_ptr(const char *name)
|
||||
{
|
||||
char *ptr;
|
||||
char *slash;
|
||||
wchar_t path_utf16[MAX_PATH];
|
||||
struct dstr path;
|
||||
|
||||
GetModuleFileNameW(NULL, path_utf16, MAX_PATH);
|
||||
|
||||
os_wcs_to_utf8_ptr(path_utf16, 0, &ptr);
|
||||
dstr_init_move_array(&path, ptr);
|
||||
dstr_replace(&path, "\\", "/");
|
||||
slash = strrchr(path.array, '/');
|
||||
if (slash) {
|
||||
size_t len = slash - path.array + 1;
|
||||
dstr_resize(&path, len);
|
||||
}
|
||||
|
||||
if (name && *name) {
|
||||
dstr_cat(&path, name);
|
||||
}
|
||||
|
||||
return path.array;
|
||||
}
|
||||
|
||||
bool os_file_exists(const char *path)
|
||||
{
|
||||
WIN32_FIND_DATAW wfd;
|
||||
|
|
@ -869,6 +900,11 @@ void get_win_ver(struct win_version_info *info)
|
|||
*info = ver;
|
||||
}
|
||||
|
||||
uint32_t get_win_ver_int(void)
|
||||
{
|
||||
return get_winver();
|
||||
}
|
||||
|
||||
struct os_inhibit_info {
|
||||
bool active;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -262,10 +262,19 @@ bool os_quick_write_utf8_file(const char *path, const char *str, size_t len,
|
|||
if (!f)
|
||||
return false;
|
||||
|
||||
if (marker)
|
||||
fwrite("\xEF\xBB\xBF", 1, 3, f);
|
||||
if (len)
|
||||
fwrite(str, 1, len, f);
|
||||
if (marker) {
|
||||
if (fwrite("\xEF\xBB\xBF", 3, 1, f) != 1) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (len) {
|
||||
if (fwrite(str, len, 1, f) != 1) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
fflush(f);
|
||||
fclose(f);
|
||||
|
||||
|
|
@ -292,6 +301,8 @@ bool os_quick_write_utf8_file_safe(const char *path, const char *str,
|
|||
dstr_cat(&temp_path, temp_ext);
|
||||
|
||||
if (!os_quick_write_utf8_file(temp_path.array, str, len, marker)) {
|
||||
blog(LOG_ERROR, "os_quick_write_utf8_file_safe: failed to "
|
||||
"write to %s", temp_path.array);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,6 +111,8 @@ EXPORT char *os_get_config_path_ptr(const char *name);
|
|||
EXPORT int os_get_program_data_path(char *dst, size_t size, const char *name);
|
||||
EXPORT char *os_get_program_data_path_ptr(const char *name);
|
||||
|
||||
EXPORT char *os_get_executable_path_ptr(const char *name);
|
||||
|
||||
EXPORT bool os_file_exists(const char *path);
|
||||
|
||||
EXPORT size_t os_get_abs_path(const char *path, char *abspath, size_t size);
|
||||
|
|
|
|||
|
|
@ -253,6 +253,12 @@ void os_set_thread_name(const char *name)
|
|||
#elif defined(__FreeBSD__)
|
||||
pthread_set_name_np(pthread_self(), name);
|
||||
#elif defined(__GLIBC__) && !defined(__MINGW32__)
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
if (strlen(name) <= 15) {
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
} else {
|
||||
char *thread_name = bstrdup_n(name, 15);
|
||||
pthread_setname_np(pthread_self(), thread_name);
|
||||
bfree(thread_name);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ size_t utf8_to_wchar(const char *in, size_t insize, wchar_t *out,
|
|||
if (has_utf8_bom(in)) {
|
||||
if (i_insize >= 3) {
|
||||
in += 3;
|
||||
insize -= 3;
|
||||
i_insize -= 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,11 +51,19 @@ static inline util_uint128_t util_add128(util_uint128_t a, util_uint128_t b)
|
|||
return out;
|
||||
}
|
||||
|
||||
static inline util_uint128_t util_lshift64(uint64_t a, int num)
|
||||
static inline util_uint128_t util_lshift64_internal_32(uint64_t a)
|
||||
{
|
||||
util_uint128_t val;
|
||||
val.low = a << num;
|
||||
val.high = a >> (64 - num);
|
||||
val.low = a << 32;
|
||||
val.high = a >> 32;
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline util_uint128_t util_lshift64_internal_64(uint64_t a)
|
||||
{
|
||||
util_uint128_t val;
|
||||
val.low = 0;
|
||||
val.high = a;
|
||||
return val;
|
||||
}
|
||||
|
||||
|
|
@ -69,13 +77,13 @@ static inline util_uint128_t util_mul64_64(uint64_t a, uint64_t b)
|
|||
out.high = 0;
|
||||
|
||||
m = (a >> 32) * (b & 0xFFFFFFFFULL);
|
||||
out = util_add128(out, util_lshift64(m, 32));
|
||||
out = util_add128(out, util_lshift64_internal_32(m));
|
||||
|
||||
m = (a & 0xFFFFFFFFULL) * (b >> 32);
|
||||
out = util_add128(out, util_lshift64(m, 32));
|
||||
out = util_add128(out, util_lshift64_internal_32(m));
|
||||
|
||||
m = (a >> 32) * (b >> 32);
|
||||
out = util_add128(out, util_lshift64(m, 64));
|
||||
out = util_add128(out, util_lshift64_internal_64(m));
|
||||
|
||||
return out;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public:
|
|||
|
||||
inline ComPtr<T> &operator=(ComPtr<T> &&c)
|
||||
{
|
||||
if (this != &c) {
|
||||
if (&ptr != &c.ptr) {
|
||||
Kill();
|
||||
ptr = c.ptr;
|
||||
c.ptr = nullptr;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
#pragma once
|
||||
|
||||
class WinHandle {
|
||||
HANDLE handle;
|
||||
HANDLE handle = INVALID_HANDLE_VALUE;
|
||||
|
||||
inline void Clear()
|
||||
{
|
||||
|
|
@ -26,7 +26,7 @@ class WinHandle {
|
|||
}
|
||||
|
||||
public:
|
||||
inline WinHandle() : handle(NULL) {}
|
||||
inline WinHandle() {}
|
||||
inline WinHandle(HANDLE handle_) : handle(handle_) {}
|
||||
inline ~WinHandle() {Clear();}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ struct win_version_info {
|
|||
EXPORT bool is_64_bit_windows(void);
|
||||
EXPORT bool get_dll_ver(const wchar_t *lib, struct win_version_info *info);
|
||||
EXPORT void get_win_ver(struct win_version_info *info);
|
||||
EXPORT uint32_t get_win_ver_int(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue