2013-09-30 19:37:13 -07:00
|
|
|
/******************************************************************************
|
2014-02-13 07:58:31 -08:00
|
|
|
Copyright (C) 2013-2014 by Hugh Bailey <obs.jim@gmail.com>
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
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
|
2013-12-02 21:24:38 -08:00
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
2013-09-30 19:37:13 -07:00
|
|
|
(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.h"
|
2014-01-26 17:48:14 -08:00
|
|
|
#include "obs-internal.h"
|
2013-09-30 19:37:13 -07:00
|
|
|
#include "graphics/vec4.h"
|
2014-02-09 04:51:06 -08:00
|
|
|
#include "media-io/format-conversion.h"
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-04-19 06:33:11 -07:00
|
|
|
static uint64_t tick_sources(uint64_t cur_time, uint64_t last_time)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-19 20:38:53 -07:00
|
|
|
struct obs_core_data *data = &obs->data;
|
|
|
|
struct obs_source *source;
|
|
|
|
uint64_t delta_time;
|
|
|
|
float seconds;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
if (!last_time)
|
2014-04-19 06:33:11 -07:00
|
|
|
last_time = cur_time - video_getframetime(obs->video.video);
|
|
|
|
delta_time = cur_time - last_time;
|
2013-09-30 19:37:13 -07:00
|
|
|
seconds = (float)((double)delta_time / 1000000000.0);
|
|
|
|
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-19 20:38:53 -07:00
|
|
|
pthread_mutex_lock(&data->sources_mutex);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-19 20:38:53 -07:00
|
|
|
source = data->first_source;
|
|
|
|
while (source) {
|
|
|
|
if (source->refs)
|
|
|
|
obs_source_video_tick(source, seconds);
|
|
|
|
source = (struct obs_source*)source->context.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&data->sources_mutex);
|
|
|
|
|
|
|
|
return cur_time;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-02-13 07:58:31 -08:00
|
|
|
/* in obs-display.c */
|
|
|
|
extern void render_display(struct obs_display *display);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2013-10-18 20:25:13 -07:00
|
|
|
static inline void render_displays(void)
|
|
|
|
{
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-19 20:38:53 -07:00
|
|
|
struct obs_display *display;
|
|
|
|
|
2014-01-23 16:00:42 -08:00
|
|
|
if (!obs->data.valid)
|
|
|
|
return;
|
|
|
|
|
2014-08-04 05:48:58 -07:00
|
|
|
gs_entercontext(obs->video.graphics);
|
2014-02-09 04:51:06 -08:00
|
|
|
|
2013-11-20 14:00:16 -08:00
|
|
|
/* render extra displays/swaps */
|
|
|
|
pthread_mutex_lock(&obs->data.displays_mutex);
|
2013-10-18 20:25:13 -07:00
|
|
|
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-19 20:38:53 -07:00
|
|
|
display = obs->data.first_display;
|
|
|
|
while (display) {
|
|
|
|
render_display(display);
|
|
|
|
display = display->next;
|
|
|
|
}
|
2013-10-18 20:25:13 -07:00
|
|
|
|
2013-11-20 14:00:16 -08:00
|
|
|
pthread_mutex_unlock(&obs->data.displays_mutex);
|
2013-10-18 20:25:13 -07:00
|
|
|
|
2013-11-20 14:00:16 -08:00
|
|
|
/* render main display */
|
2014-02-13 07:58:31 -08:00
|
|
|
render_display(&obs->video.main_display);
|
2014-02-09 04:51:06 -08:00
|
|
|
|
|
|
|
gs_leavecontext();
|
2013-10-18 20:25:13 -07:00
|
|
|
}
|
|
|
|
|
2014-02-05 19:36:21 -08:00
|
|
|
static inline void set_render_size(uint32_t width, uint32_t height)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-09 04:51:06 -08:00
|
|
|
gs_enable_depthtest(false);
|
2014-02-16 18:28:21 -08:00
|
|
|
gs_enable_blending(false);
|
2014-02-09 04:51:06 -08:00
|
|
|
gs_setcullmode(GS_NEITHER);
|
|
|
|
|
2014-02-05 19:36:21 -08:00
|
|
|
gs_ortho(0.0f, (float)width, 0.0f, (float)height, -100.0f, 100.0f);
|
|
|
|
gs_setviewport(0, 0, width, height);
|
|
|
|
}
|
|
|
|
|
2014-02-05 20:03:06 -08:00
|
|
|
static inline void unmap_last_surface(struct obs_core_video *video)
|
2014-02-05 19:36:21 -08:00
|
|
|
{
|
|
|
|
if (video->mapped_surface) {
|
|
|
|
stagesurface_unmap(video->mapped_surface);
|
|
|
|
video->mapped_surface = NULL;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
2014-02-05 19:36:21 -08:00
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-02-05 20:03:06 -08:00
|
|
|
static inline void render_main_texture(struct obs_core_video *video,
|
2014-02-14 14:13:36 -08:00
|
|
|
int cur_texture)
|
2014-02-05 19:36:21 -08:00
|
|
|
{
|
|
|
|
struct vec4 clear_color;
|
2014-03-07 09:19:03 -08:00
|
|
|
vec4_set(&clear_color, 0.0f, 0.0f, 0.0f, 1.0f);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-02-05 19:36:21 -08:00
|
|
|
gs_setrendertarget(video->render_textures[cur_texture], NULL);
|
|
|
|
gs_clear(GS_CLEAR_COLOR, &clear_color, 1.0f, 0);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-02-05 19:36:21 -08:00
|
|
|
set_render_size(video->base_width, video->base_height);
|
2014-02-13 09:21:16 -08:00
|
|
|
obs_view_render(&obs->data.main_view);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-02-05 19:36:21 -08:00
|
|
|
video->textures_rendered[cur_texture] = true;
|
|
|
|
}
|
|
|
|
|
2014-02-05 20:03:06 -08:00
|
|
|
static inline void render_output_texture(struct obs_core_video *video,
|
2014-02-05 19:36:21 -08:00
|
|
|
int cur_texture, int prev_texture)
|
|
|
|
{
|
|
|
|
texture_t texture = video->render_textures[prev_texture];
|
|
|
|
texture_t target = video->output_textures[cur_texture];
|
|
|
|
uint32_t width = texture_getwidth(target);
|
|
|
|
uint32_t height = texture_getheight(target);
|
|
|
|
|
|
|
|
/* TODO: replace with actual downscalers or unpackers */
|
|
|
|
effect_t effect = video->default_effect;
|
|
|
|
technique_t tech = effect_gettechnique(effect, "DrawMatrix");
|
Revamp API and start using doxygen
The API used to be designed in such a way to where it would expect
exports for each individual source/output/encoder/etc. You would export
functions for each and it would automatically load those functions based
on a specific naming scheme from the module.
The idea behind this was that I wanted to limit the usage of structures
in the API so only functions could be used. It was an interesting idea
in theory, but this idea turned out to be flawed in a number of ways:
1.) Requiring exports to create sources/outputs/encoders/etc meant that
you could not create them by any other means, which meant that
things like faruton's .net plugin would become difficult.
2.) Export function declarations could not be checked, therefore if you
created a function with the wrong parameters and parameter types,
the compiler wouldn't know how to check for that.
3.) Required overly complex load functions in libobs just to handle it.
It makes much more sense to just have a load function that you call
manually. Complexity is the bane of all good programs.
4.) It required that you have functions of specific names, which looked
and felt somewhat unsightly.
So, to fix these issues, I replaced it with a more commonly used API
scheme, seen commonly in places like kernels and typical C libraries
with abstraction. You simply create a structure that contains the
callback definitions, and you pass it to a function to register that
definition (such as obs_register_source), which you call in the
obs_module_load of the module.
It will also automatically check the structure size and ensure that it
only loads the required values if the structure happened to add new
values in an API change.
The "main" source file for each module must include obs-module.h, and
must use OBS_DECLARE_MODULE() within that source file.
Also, started writing some doxygen documentation in to the main library
headers. Will add more detailed documentation as I go.
2014-02-12 07:04:50 -08:00
|
|
|
eparam_t image = effect_getparambyname(effect, "image");
|
2014-02-05 19:36:21 -08:00
|
|
|
eparam_t matrix = effect_getparambyname(effect, "color_matrix");
|
|
|
|
size_t passes, i;
|
|
|
|
|
|
|
|
if (!video->textures_rendered[prev_texture])
|
|
|
|
return;
|
|
|
|
|
|
|
|
gs_setrendertarget(target, NULL);
|
|
|
|
set_render_size(width, height);
|
|
|
|
|
|
|
|
/* TODO: replace with programmable code */
|
|
|
|
const float mat_val[16] =
|
|
|
|
{
|
2014-02-09 04:51:06 -08:00
|
|
|
-0.100644f, -0.338572f, 0.439216f, 0.501961f,
|
|
|
|
0.182586f, 0.614231f, 0.062007f, 0.062745f,
|
|
|
|
0.439216f, -0.398942f, -0.040274f, 0.501961f,
|
2014-02-05 19:36:21 -08:00
|
|
|
0.000000f, 0.000000f, 0.000000f, 1.000000f
|
|
|
|
};
|
|
|
|
|
2014-06-25 20:29:46 -07:00
|
|
|
effect_setval(matrix, mat_val, sizeof(mat_val));
|
|
|
|
effect_settexture(image, texture);
|
2014-02-05 19:36:21 -08:00
|
|
|
|
|
|
|
passes = technique_begin(tech);
|
|
|
|
for (i = 0; i < passes; i++) {
|
|
|
|
technique_beginpass(tech, i);
|
|
|
|
gs_draw_sprite(texture, 0, width, height);
|
|
|
|
technique_endpass(tech);
|
|
|
|
}
|
|
|
|
technique_end(tech);
|
|
|
|
|
|
|
|
video->textures_output[cur_texture] = true;
|
|
|
|
}
|
|
|
|
|
2014-02-16 18:28:21 -08:00
|
|
|
static inline void set_eparam(effect_t effect, const char *name, float val)
|
|
|
|
{
|
|
|
|
eparam_t param = effect_getparambyname(effect, name);
|
2014-06-25 20:29:46 -07:00
|
|
|
effect_setfloat(param, val);
|
2014-02-16 18:28:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void render_convert_texture(struct obs_core_video *video,
|
2014-02-05 19:36:21 -08:00
|
|
|
int cur_texture, int prev_texture)
|
|
|
|
{
|
|
|
|
texture_t texture = video->output_textures[prev_texture];
|
2014-02-16 18:28:21 -08:00
|
|
|
texture_t target = video->convert_textures[cur_texture];
|
|
|
|
float fwidth = (float)video->output_width;
|
|
|
|
float fheight = (float)video->output_height;
|
|
|
|
size_t passes, i;
|
2014-02-05 19:36:21 -08:00
|
|
|
|
2014-02-16 18:28:21 -08:00
|
|
|
effect_t effect = video->conversion_effect;
|
|
|
|
eparam_t image = effect_getparambyname(effect, "image");
|
|
|
|
technique_t tech = effect_gettechnique(effect,
|
|
|
|
video->conversion_tech);
|
2014-02-05 19:36:21 -08:00
|
|
|
|
|
|
|
if (!video->textures_output[prev_texture])
|
|
|
|
return;
|
|
|
|
|
2014-02-16 18:28:21 -08:00
|
|
|
set_eparam(effect, "u_plane_offset", (float)video->plane_offsets[1]);
|
|
|
|
set_eparam(effect, "v_plane_offset", (float)video->plane_offsets[2]);
|
|
|
|
set_eparam(effect, "width", fwidth);
|
|
|
|
set_eparam(effect, "height", fheight);
|
|
|
|
set_eparam(effect, "width_i", 1.0f / fwidth);
|
|
|
|
set_eparam(effect, "height_i", 1.0f / fheight);
|
|
|
|
set_eparam(effect, "width_d2", fwidth * 0.5f);
|
|
|
|
set_eparam(effect, "height_d2", fheight * 0.5f);
|
|
|
|
set_eparam(effect, "width_d2_i", 1.0f / (fwidth * 0.5f));
|
|
|
|
set_eparam(effect, "height_d2_i", 1.0f / (fheight * 0.5f));
|
|
|
|
set_eparam(effect, "input_height", (float)video->conversion_height);
|
|
|
|
|
2014-06-25 20:29:46 -07:00
|
|
|
effect_settexture(image, texture);
|
2014-02-16 18:28:21 -08:00
|
|
|
|
|
|
|
gs_setrendertarget(target, NULL);
|
|
|
|
set_render_size(video->output_width, video->conversion_height);
|
|
|
|
|
|
|
|
passes = technique_begin(tech);
|
|
|
|
for (i = 0; i < passes; i++) {
|
|
|
|
technique_beginpass(tech, i);
|
|
|
|
gs_draw_sprite(texture, 0, video->output_width,
|
|
|
|
video->conversion_height);
|
|
|
|
technique_endpass(tech);
|
|
|
|
}
|
|
|
|
technique_end(tech);
|
|
|
|
|
|
|
|
video->textures_converted[cur_texture] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void stage_output_texture(struct obs_core_video *video,
|
|
|
|
int cur_texture, int prev_texture)
|
|
|
|
{
|
|
|
|
texture_t texture;
|
|
|
|
bool texture_ready;
|
|
|
|
stagesurf_t copy = video->copy_surfaces[cur_texture];
|
|
|
|
|
|
|
|
if (video->gpu_conversion) {
|
|
|
|
texture = video->convert_textures[prev_texture];
|
|
|
|
texture_ready = video->textures_converted[prev_texture];
|
|
|
|
} else {
|
|
|
|
texture = video->output_textures[prev_texture];
|
|
|
|
texture_ready = video->output_textures[prev_texture];
|
|
|
|
}
|
|
|
|
|
|
|
|
unmap_last_surface(video);
|
|
|
|
|
|
|
|
if (!texture_ready)
|
|
|
|
return;
|
|
|
|
|
2014-02-05 19:36:21 -08:00
|
|
|
gs_stage_texture(copy, texture);
|
|
|
|
|
|
|
|
video->textures_copied[cur_texture] = true;
|
|
|
|
}
|
|
|
|
|
2014-02-05 20:03:06 -08:00
|
|
|
static inline void render_video(struct obs_core_video *video, int cur_texture,
|
2014-02-05 19:36:21 -08:00
|
|
|
int prev_texture)
|
|
|
|
{
|
|
|
|
gs_beginscene();
|
|
|
|
|
|
|
|
gs_enable_depthtest(false);
|
|
|
|
gs_setcullmode(GS_NEITHER);
|
|
|
|
|
2014-02-14 14:13:36 -08:00
|
|
|
render_main_texture(video, cur_texture);
|
2014-02-05 19:36:21 -08:00
|
|
|
render_output_texture(video, cur_texture, prev_texture);
|
2014-02-16 18:28:21 -08:00
|
|
|
if (video->gpu_conversion)
|
|
|
|
render_convert_texture(video, cur_texture, prev_texture);
|
|
|
|
|
2014-02-05 19:36:21 -08:00
|
|
|
stage_output_texture(video, cur_texture, prev_texture);
|
|
|
|
|
|
|
|
gs_setrendertarget(NULL, NULL);
|
2014-02-16 18:28:21 -08:00
|
|
|
gs_enable_blending(true);
|
2014-02-05 19:36:21 -08:00
|
|
|
|
|
|
|
gs_endscene();
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:13:36 -08:00
|
|
|
static inline bool download_frame(struct obs_core_video *video,
|
2014-02-18 12:37:56 -08:00
|
|
|
int prev_texture, struct video_data *frame)
|
2014-02-05 19:36:21 -08:00
|
|
|
{
|
|
|
|
stagesurf_t surface = video->copy_surfaces[prev_texture];
|
|
|
|
|
|
|
|
if (!video->textures_copied[prev_texture])
|
2014-02-09 04:51:06 -08:00
|
|
|
return false;
|
2014-02-05 19:36:21 -08:00
|
|
|
|
2014-02-09 04:51:06 -08:00
|
|
|
if (!stagesurface_map(surface, &frame->data[0], &frame->linesize[0]))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
video->mapped_surface = surface;
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-05 19:36:21 -08:00
|
|
|
|
2014-02-16 18:28:21 -08:00
|
|
|
static inline uint32_t calc_linesize(uint32_t pos, uint32_t linesize)
|
|
|
|
{
|
|
|
|
uint32_t size = pos % linesize;
|
|
|
|
return size ? size : linesize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void copy_dealign(
|
|
|
|
uint8_t *dst, uint32_t dst_pos, uint32_t dst_linesize,
|
|
|
|
const uint8_t *src, uint32_t src_pos, uint32_t src_linesize,
|
|
|
|
uint32_t remaining)
|
|
|
|
{
|
|
|
|
while (remaining) {
|
|
|
|
uint32_t src_remainder = src_pos % src_linesize;
|
|
|
|
uint32_t dst_offset = dst_linesize - src_remainder;
|
|
|
|
uint32_t src_offset = src_linesize - src_remainder;
|
|
|
|
|
|
|
|
if (remaining < dst_offset) {
|
|
|
|
memcpy(dst + dst_pos, src + src_pos, remaining);
|
|
|
|
src_pos += remaining;
|
|
|
|
dst_pos += remaining;
|
|
|
|
remaining = 0;
|
|
|
|
} else {
|
|
|
|
memcpy(dst + dst_pos, src + src_pos, dst_offset);
|
|
|
|
src_pos += src_offset;
|
|
|
|
dst_pos += dst_offset;
|
|
|
|
remaining -= dst_offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t make_aligned_linesize_offset(uint32_t offset,
|
|
|
|
uint32_t dst_linesize, uint32_t src_linesize)
|
|
|
|
{
|
|
|
|
uint32_t remainder = offset % dst_linesize;
|
|
|
|
return (offset / dst_linesize) * src_linesize + remainder;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fix_gpu_converted_alignment(struct obs_core_video *video,
|
2014-02-18 12:37:56 -08:00
|
|
|
struct video_data *frame, int cur_texture)
|
2014-02-16 18:28:21 -08:00
|
|
|
{
|
2014-08-02 01:04:45 -07:00
|
|
|
struct obs_source_frame *new_frame =
|
|
|
|
&video->convert_frames[cur_texture];
|
2014-02-16 18:28:21 -08:00
|
|
|
uint32_t src_linesize = frame->linesize[0];
|
|
|
|
uint32_t dst_linesize = video->output_width * 4;
|
|
|
|
uint32_t src_pos = 0;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 3; i++) {
|
|
|
|
if (video->plane_linewidth[i] == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
src_pos = make_aligned_linesize_offset(video->plane_offsets[i],
|
|
|
|
dst_linesize, src_linesize);
|
|
|
|
|
|
|
|
copy_dealign(new_frame->data[i], 0, dst_linesize,
|
|
|
|
frame->data[0], src_pos, src_linesize,
|
|
|
|
video->plane_sizes[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* replace with cached frames */
|
|
|
|
for (size_t i = 0; i < MAX_AV_PLANES; i++) {
|
|
|
|
frame->data[i] = new_frame->data[i];
|
|
|
|
frame->linesize[i] = new_frame->linesize[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool set_gpu_converted_data(struct obs_core_video *video,
|
2014-02-18 12:37:56 -08:00
|
|
|
struct video_data *frame, int cur_texture)
|
2014-02-16 18:28:21 -08:00
|
|
|
{
|
|
|
|
if (frame->linesize[0] == video->output_width*4) {
|
|
|
|
for (size_t i = 0; i < 3; i++) {
|
|
|
|
if (video->plane_linewidth[i] == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
frame->linesize[i] = video->plane_linewidth[i];
|
|
|
|
frame->data[i] =
|
|
|
|
frame->data[0] + video->plane_offsets[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
fix_gpu_converted_alignment(video, frame, cur_texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-09 04:51:06 -08:00
|
|
|
static bool convert_frame(struct obs_core_video *video,
|
2014-02-18 12:37:56 -08:00
|
|
|
struct video_data *frame,
|
2014-02-09 04:51:06 -08:00
|
|
|
const struct video_output_info *info, int cur_texture)
|
|
|
|
{
|
2014-08-02 01:04:45 -07:00
|
|
|
struct obs_source_frame *new_frame =
|
|
|
|
&video->convert_frames[cur_texture];
|
2014-02-09 04:51:06 -08:00
|
|
|
|
|
|
|
if (info->format == VIDEO_FORMAT_I420) {
|
|
|
|
compress_uyvx_to_i420(
|
|
|
|
frame->data[0], frame->linesize[0],
|
|
|
|
0, info->height,
|
|
|
|
new_frame->data, new_frame->linesize);
|
|
|
|
|
|
|
|
} else if (info->format == VIDEO_FORMAT_NV12) {
|
|
|
|
compress_uyvx_to_nv12(
|
|
|
|
frame->data[0], frame->linesize[0],
|
|
|
|
0, info->height,
|
|
|
|
new_frame->data, new_frame->linesize);
|
|
|
|
|
|
|
|
} else {
|
2014-02-28 19:02:29 -08:00
|
|
|
blog(LOG_ERROR, "convert_frame: unsupported texture format");
|
2014-02-09 04:51:06 -08:00
|
|
|
return false;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
2014-02-09 04:51:06 -08:00
|
|
|
|
2014-02-14 14:13:36 -08:00
|
|
|
for (size_t i = 0; i < MAX_AV_PLANES; i++) {
|
2014-02-09 04:51:06 -08:00
|
|
|
frame->data[i] = new_frame->data[i];
|
|
|
|
frame->linesize[i] = new_frame->linesize[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void output_video_data(struct obs_core_video *video,
|
2014-02-18 12:37:56 -08:00
|
|
|
struct video_data *frame, int cur_texture)
|
2014-02-09 04:51:06 -08:00
|
|
|
{
|
|
|
|
const struct video_output_info *info;
|
|
|
|
info = video_output_getinfo(video->video);
|
|
|
|
|
2014-02-16 18:28:21 -08:00
|
|
|
if (video->gpu_conversion) {
|
|
|
|
if (!set_gpu_converted_data(video, frame, cur_texture))
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else if (format_is_yuv(info->format)) {
|
2014-02-09 04:51:06 -08:00
|
|
|
if (!convert_frame(video, frame, info, cur_texture))
|
|
|
|
return;
|
2014-02-16 18:28:21 -08:00
|
|
|
}
|
2014-02-09 04:51:06 -08:00
|
|
|
|
2014-02-18 12:37:56 -08:00
|
|
|
video_output_swap_frame(video->video, frame);
|
2014-02-05 19:36:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void output_frame(uint64_t timestamp)
|
|
|
|
{
|
2014-02-05 20:03:06 -08:00
|
|
|
struct obs_core_video *video = &obs->video;
|
2014-02-05 19:36:21 -08:00
|
|
|
int cur_texture = video->cur_texture;
|
|
|
|
int prev_texture = cur_texture == 0 ? NUM_TEXTURES-1 : cur_texture-1;
|
2014-02-18 12:37:56 -08:00
|
|
|
struct video_data frame;
|
2014-02-09 04:51:06 -08:00
|
|
|
bool frame_ready;
|
|
|
|
|
2014-02-18 12:37:56 -08:00
|
|
|
memset(&frame, 0, sizeof(struct video_data));
|
2014-02-09 04:51:06 -08:00
|
|
|
frame.timestamp = timestamp;
|
|
|
|
|
2014-08-04 05:48:58 -07:00
|
|
|
gs_entercontext(video->graphics);
|
2014-02-05 19:36:21 -08:00
|
|
|
|
|
|
|
render_video(video, cur_texture, prev_texture);
|
2014-02-14 14:13:36 -08:00
|
|
|
frame_ready = download_frame(video, prev_texture, &frame);
|
2014-02-09 04:51:06 -08:00
|
|
|
|
|
|
|
gs_leavecontext();
|
|
|
|
|
|
|
|
if (frame_ready)
|
|
|
|
output_video_data(video, &frame, cur_texture);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-02-05 19:36:21 -08:00
|
|
|
if (++video->cur_texture == NUM_TEXTURES)
|
|
|
|
video->cur_texture = 0;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void *obs_video_thread(void *param)
|
|
|
|
{
|
|
|
|
uint64_t last_time = 0;
|
|
|
|
|
2013-11-20 14:00:16 -08:00
|
|
|
while (video_output_wait(obs->video.video)) {
|
|
|
|
uint64_t cur_time = video_gettime(obs->video.video);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-04-19 06:33:11 -07:00
|
|
|
last_time = tick_sources(cur_time, last_time);
|
2014-02-09 04:51:06 -08:00
|
|
|
|
2013-10-14 12:37:52 -07:00
|
|
|
render_displays();
|
2014-02-09 04:51:06 -08:00
|
|
|
|
2014-02-05 19:36:21 -08:00
|
|
|
output_frame(cur_time);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:13:36 -08:00
|
|
|
UNUSED_PARAMETER(param);
|
2013-09-30 19:37:13 -07:00
|
|
|
return NULL;
|
|
|
|
}
|