2014-01-17 02:38:35 +01:00
|
|
|
#include <stdlib.h>
|
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 08:04:50 -07:00
|
|
|
#include <obs.h>
|
2014-03-23 21:05:43 +01:00
|
|
|
#include <util/threading.h>
|
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 08:04:50 -07:00
|
|
|
#include <pthread.h>
|
2014-01-17 02:38:35 +01:00
|
|
|
|
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 08:04:50 -07:00
|
|
|
#import <CoreGraphics/CGDisplayStream.h>
|
2014-01-17 02:38:35 +01:00
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
struct display_capture {
|
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 08:04:50 -07:00
|
|
|
samplerstate_t sampler;
|
2014-03-23 21:05:43 +01:00
|
|
|
effect_t draw_effect;
|
|
|
|
texture_t tex;
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
unsigned display;
|
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 08:04:50 -07:00
|
|
|
uint32_t width, height;
|
2014-04-16 17:20:01 +02:00
|
|
|
bool hide_cursor;
|
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 08:04:50 -07:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
os_event_t disp_finished;
|
|
|
|
CGDisplayStreamRef disp;
|
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 08:04:50 -07:00
|
|
|
IOSurfaceRef current, prev;
|
2014-03-23 21:05:43 +01:00
|
|
|
|
|
|
|
pthread_mutex_t mutex;
|
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 08:04:50 -07:00
|
|
|
};
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
static void destroy_display_stream(struct display_capture *dc)
|
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 08:04:50 -07:00
|
|
|
{
|
2014-03-23 21:05:43 +01:00
|
|
|
if (dc->disp) {
|
|
|
|
CGDisplayStreamStop(dc->disp);
|
|
|
|
os_event_wait(dc->disp_finished);
|
|
|
|
}
|
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 08:04:50 -07:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
if (dc->tex) {
|
|
|
|
texture_destroy(dc->tex);
|
|
|
|
dc->tex = NULL;
|
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 08:04:50 -07:00
|
|
|
}
|
2014-03-23 21:05:43 +01:00
|
|
|
|
|
|
|
if (dc->current) {
|
|
|
|
IOSurfaceDecrementUseCount(dc->current);
|
|
|
|
CFRelease(dc->current);
|
|
|
|
dc->current = NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-26 01:24:54 +01:00
|
|
|
if (dc->prev) {
|
|
|
|
IOSurfaceDecrementUseCount(dc->prev);
|
|
|
|
CFRelease(dc->prev);
|
|
|
|
dc->prev = NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
if (dc->disp) {
|
|
|
|
CFRelease(dc->disp);
|
|
|
|
dc->disp = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_event_destroy(dc->disp_finished);
|
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 08:04:50 -07:00
|
|
|
}
|
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
static void display_capture_destroy(void *data)
|
2014-01-17 02:38:35 +01:00
|
|
|
{
|
2014-03-23 21:05:43 +01:00
|
|
|
struct display_capture *dc = data;
|
|
|
|
|
|
|
|
if (!dc)
|
|
|
|
return;
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
pthread_mutex_lock(&dc->mutex);
|
2014-01-17 02:38:35 +01:00
|
|
|
gs_entercontext(obs_graphics());
|
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
destroy_display_stream(dc);
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
if (dc->sampler)
|
|
|
|
samplerstate_destroy(dc->sampler);
|
|
|
|
if (dc->draw_effect)
|
|
|
|
effect_destroy(dc->draw_effect);
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
gs_leavecontext();
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
pthread_mutex_destroy(&dc->mutex);
|
|
|
|
bfree(dc);
|
|
|
|
}
|
|
|
|
|
2014-05-11 21:14:40 +02:00
|
|
|
static inline void display_stream_update(struct display_capture *dc,
|
|
|
|
CGDisplayStreamFrameStatus status, uint64_t display_time,
|
|
|
|
IOSurfaceRef frame_surface, CGDisplayStreamUpdateRef update_ref)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(display_time);
|
|
|
|
UNUSED_PARAMETER(update_ref);
|
|
|
|
|
|
|
|
if (status == kCGDisplayStreamFrameStatusStopped) {
|
|
|
|
os_event_signal(dc->disp_finished);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!frame_surface || pthread_mutex_trylock(&dc->mutex))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (dc->current) {
|
|
|
|
IOSurfaceDecrementUseCount(dc->current);
|
|
|
|
CFRelease(dc->current);
|
|
|
|
dc->current = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dc->current = frame_surface;
|
|
|
|
CFRetain(dc->current);
|
|
|
|
IOSurfaceIncrementUseCount(dc->current);
|
|
|
|
pthread_mutex_unlock(&dc->mutex);
|
|
|
|
}
|
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
static bool init_display_stream(struct display_capture *dc)
|
|
|
|
{
|
|
|
|
if (dc->display >= [NSScreen screens].count)
|
|
|
|
return false;
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
NSScreen *screen = [NSScreen screens][dc->display];
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
NSRect frame = [screen convertRectToBacking:screen.frame];
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
dc->width = frame.size.width;
|
|
|
|
dc->height = frame.size.height;
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
NSNumber *screen_num = screen.deviceDescription[@"NSScreenNumber"];
|
|
|
|
CGDirectDisplayID disp_id = (CGDirectDisplayID)screen_num.pointerValue;
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-04-14 22:35:45 +02:00
|
|
|
NSDictionary *rect_dict = CFBridgingRelease(
|
|
|
|
CGRectCreateDictionaryRepresentation(
|
2014-04-16 14:18:27 +02:00
|
|
|
CGRectMake(0, 0,
|
|
|
|
screen.frame.size.width,
|
|
|
|
screen.frame.size.height)));
|
2014-04-14 22:35:45 +02:00
|
|
|
|
2014-01-17 02:38:35 +01:00
|
|
|
NSDictionary *dict = @{
|
2014-04-14 22:35:45 +02:00
|
|
|
(__bridge NSString*)kCGDisplayStreamSourceRect: rect_dict,
|
2014-04-16 17:20:01 +02:00
|
|
|
(__bridge NSString*)kCGDisplayStreamQueueDepth: @5,
|
|
|
|
(__bridge NSString*)kCGDisplayStreamShowCursor:
|
|
|
|
@(!dc->hide_cursor),
|
2014-01-17 02:38:35 +01:00
|
|
|
};
|
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
os_event_init(&dc->disp_finished, OS_EVENT_TYPE_MANUAL);
|
|
|
|
|
|
|
|
dc->disp = CGDisplayStreamCreateWithDispatchQueue(disp_id,
|
|
|
|
dc->width, dc->height, 'BGRA',
|
2014-01-17 02:38:35 +01:00
|
|
|
(__bridge CFDictionaryRef)dict,
|
2014-01-29 19:42:36 +01:00
|
|
|
dispatch_queue_create(NULL, NULL),
|
2014-04-16 17:20:01 +02:00
|
|
|
^(CGDisplayStreamFrameStatus status,
|
|
|
|
uint64_t displayTime,
|
|
|
|
IOSurfaceRef frameSurface,
|
2014-01-17 02:38:35 +01:00
|
|
|
CGDisplayStreamUpdateRef updateRef)
|
|
|
|
{
|
2014-05-11 21:14:40 +02:00
|
|
|
display_stream_update(dc, status, displayTime,
|
|
|
|
frameSurface, updateRef);
|
2014-01-17 02:38:35 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
return !CGDisplayStreamStart(dc->disp);
|
|
|
|
}
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
static void *display_capture_create(obs_data_t settings,
|
|
|
|
obs_source_t source)
|
|
|
|
{
|
2014-02-14 15:13:36 -07:00
|
|
|
UNUSED_PARAMETER(source);
|
|
|
|
UNUSED_PARAMETER(settings);
|
2014-03-23 21:05:43 +01:00
|
|
|
|
|
|
|
struct display_capture *dc = bzalloc(sizeof(struct display_capture));
|
|
|
|
|
|
|
|
gs_entercontext(obs_graphics());
|
|
|
|
|
|
|
|
struct gs_sampler_info info = {
|
|
|
|
.filter = GS_FILTER_LINEAR,
|
|
|
|
.address_u = GS_ADDRESS_CLAMP,
|
|
|
|
.address_v = GS_ADDRESS_CLAMP,
|
|
|
|
.address_w = GS_ADDRESS_CLAMP,
|
|
|
|
.max_anisotropy = 1,
|
|
|
|
};
|
|
|
|
dc->sampler = gs_create_samplerstate(&info);
|
|
|
|
if (!dc->sampler)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
char *effect_file = obs_find_plugin_file("test-input/draw_rect.effect");
|
|
|
|
dc->draw_effect = gs_create_effect_from_file(effect_file, NULL);
|
|
|
|
bfree(effect_file);
|
|
|
|
if (!dc->draw_effect)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
gs_leavecontext();
|
|
|
|
|
|
|
|
dc->display = obs_data_getint(settings, "display");
|
|
|
|
pthread_mutex_init(&dc->mutex, NULL);
|
|
|
|
|
|
|
|
if (!init_display_stream(dc))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return dc;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
gs_leavecontext();
|
|
|
|
display_capture_destroy(dc);
|
|
|
|
return NULL;
|
2014-01-17 02:38:35 +01:00
|
|
|
}
|
|
|
|
|
2014-05-11 21:10:40 +02:00
|
|
|
static void display_capture_video_tick(void *data, float seconds)
|
2014-01-17 02:38:35 +01:00
|
|
|
{
|
2014-05-11 21:10:40 +02:00
|
|
|
UNUSED_PARAMETER(seconds);
|
2014-03-23 21:05:43 +01:00
|
|
|
|
|
|
|
struct display_capture *dc = data;
|
2014-02-14 15:13:36 -07:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
pthread_mutex_lock(&dc->mutex);
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-26 01:24:54 +01:00
|
|
|
if (dc->current && dc->prev != dc->current) {
|
2014-05-11 21:10:40 +02:00
|
|
|
gs_entercontext(obs_graphics());
|
2014-03-23 21:05:43 +01:00
|
|
|
if (dc->tex)
|
|
|
|
texture_rebind_iosurface(dc->tex, dc->current);
|
2014-01-17 02:38:35 +01:00
|
|
|
else
|
2014-03-23 21:05:43 +01:00
|
|
|
dc->tex = gs_create_texture_from_iosurface(
|
|
|
|
dc->current);
|
2014-05-11 21:10:40 +02:00
|
|
|
gs_leavecontext();
|
2014-03-26 01:24:54 +01:00
|
|
|
|
|
|
|
if (dc->prev) {
|
|
|
|
IOSurfaceDecrementUseCount(dc->prev);
|
|
|
|
CFRelease(dc->prev);
|
|
|
|
}
|
2014-03-23 21:05:43 +01:00
|
|
|
dc->prev = dc->current;
|
2014-03-26 01:24:54 +01:00
|
|
|
dc->current = NULL;
|
2014-01-17 02:38:35 +01:00
|
|
|
}
|
|
|
|
|
2014-05-11 21:10:40 +02:00
|
|
|
pthread_mutex_unlock(&dc->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void display_capture_video_render(void *data, effect_t effect)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(effect);
|
|
|
|
|
|
|
|
struct display_capture *dc = data;
|
|
|
|
|
|
|
|
if (!dc->tex)
|
|
|
|
return;
|
2014-01-17 02:38:35 +01:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
gs_load_samplerstate(dc->sampler, 0);
|
|
|
|
technique_t tech = effect_gettechnique(dc->draw_effect, "Default");
|
|
|
|
effect_settexture(dc->draw_effect,
|
|
|
|
effect_getparambyidx(dc->draw_effect, 1),
|
|
|
|
dc->tex);
|
2014-01-17 02:38:35 +01:00
|
|
|
technique_begin(tech);
|
|
|
|
technique_beginpass(tech, 0);
|
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
gs_draw_sprite(dc->tex, 0, 0, 0);
|
2014-01-17 02:38:35 +01:00
|
|
|
|
|
|
|
technique_endpass(tech);
|
|
|
|
technique_end(tech);
|
2014-03-23 21:05:43 +01:00
|
|
|
}
|
2014-02-14 15:13:36 -07:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
static const char *display_capture_getname(const char *locale)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(locale);
|
|
|
|
return "Display Capture";
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t display_capture_getwidth(void *data)
|
|
|
|
{
|
|
|
|
struct display_capture *dc = data;
|
|
|
|
return dc->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t display_capture_getheight(void *data)
|
|
|
|
{
|
|
|
|
struct display_capture *dc = data;
|
|
|
|
return dc->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void display_capture_defaults(obs_data_t settings)
|
|
|
|
{
|
|
|
|
obs_data_set_default_int(settings, "display", 0);
|
2014-04-16 17:20:01 +02:00
|
|
|
obs_data_set_default_bool(settings, "show_cursor", true);
|
2014-01-17 02:38:35 +01:00
|
|
|
}
|
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
static void display_capture_update(void *data, obs_data_t settings)
|
2014-01-17 02:38:35 +01:00
|
|
|
{
|
2014-03-23 21:05:43 +01:00
|
|
|
struct display_capture *dc = data;
|
|
|
|
unsigned display = obs_data_getint(settings, "display");
|
2014-04-16 17:20:01 +02:00
|
|
|
bool show_cursor = obs_data_getbool(settings, "show_cursor");
|
|
|
|
if (dc->display == display && dc->hide_cursor != show_cursor)
|
2014-03-23 21:05:43 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
gs_entercontext(obs_graphics());
|
|
|
|
|
|
|
|
destroy_display_stream(dc);
|
|
|
|
dc->display = display;
|
2014-04-16 17:20:01 +02:00
|
|
|
dc->hide_cursor = !show_cursor;
|
2014-03-23 21:05:43 +01:00
|
|
|
init_display_stream(dc);
|
|
|
|
|
|
|
|
gs_leavecontext();
|
2014-01-17 02:38:35 +01:00
|
|
|
}
|
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
static obs_properties_t display_capture_properties(char const *locale)
|
2014-01-17 02:38:35 +01:00
|
|
|
{
|
2014-04-04 00:30:37 -07:00
|
|
|
obs_properties_t props = obs_properties_create(locale);
|
2014-03-23 21:05:43 +01:00
|
|
|
|
|
|
|
obs_property_t list = obs_properties_add_list(props,
|
|
|
|
"display", "Display",
|
|
|
|
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
|
|
|
|
2014-04-04 00:30:37 -07:00
|
|
|
for (unsigned i = 0; i < [NSScreen screens].count; i++) {
|
2014-03-23 21:05:43 +01:00
|
|
|
char buf[10];
|
|
|
|
sprintf(buf, "%u", i);
|
2014-04-04 00:30:37 -07:00
|
|
|
obs_property_list_add_int(list, buf, i);
|
2014-03-23 21:05:43 +01:00
|
|
|
}
|
|
|
|
|
2014-04-16 17:20:01 +02:00
|
|
|
obs_properties_add_bool(props, "show_cursor", "Show Cursor");
|
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
return props;
|
2014-01-17 02:38:35 +01:00
|
|
|
}
|
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 08:04:50 -07:00
|
|
|
|
2014-03-23 21:05:43 +01:00
|
|
|
struct obs_source_info display_capture_info = {
|
|
|
|
.id = "display_capture",
|
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 08:04:50 -07:00
|
|
|
.type = OBS_SOURCE_TYPE_INPUT,
|
2014-03-23 21:05:43 +01:00
|
|
|
.getname = display_capture_getname,
|
|
|
|
|
|
|
|
.create = display_capture_create,
|
|
|
|
.destroy = display_capture_destroy,
|
|
|
|
|
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 08:04:50 -07:00
|
|
|
.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW,
|
2014-05-11 21:10:40 +02:00
|
|
|
.video_tick = display_capture_video_tick,
|
2014-03-23 21:05:43 +01:00
|
|
|
.video_render = display_capture_video_render,
|
|
|
|
|
|
|
|
.getwidth = display_capture_getwidth,
|
|
|
|
.getheight = display_capture_getheight,
|
|
|
|
|
|
|
|
.defaults = display_capture_defaults,
|
|
|
|
.properties = display_capture_properties,
|
|
|
|
.update = display_capture_update,
|
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 08:04:50 -07:00
|
|
|
};
|