0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00
Commit Graph

46 Commits

Author SHA1 Message Date
jp9000
4a6d19f206 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
Palana
3990c18aac Add NULL checks and assertions to fix clang static analysis problems
Also remove an unused variable from obs-encoder.c (via clang static
analysis)
2014-04-14 23:02:53 +02:00
jp9000
154e0c59e1 Use atomic functions where appropriate
Also, rename atomic functions to be consistent with the rest of the
platform/threading functions, and move atomic functions to threading*
files rather than platform* files
2014-03-16 18:26:46 -07:00
jp9000
5288467aeb Ensure names are valid
Ensure that a source has a valid name.  Duplicates aren't a big deal
internally, but sources without a name are probably something that
should be avoided.  Made is so that if a source is programmatically
created without a name, it's assigned an index based name.

In the main basic-mode window, made it check to make sure the name was
valid as well.
2014-03-10 13:39:51 -07:00
jp9000
9c6da6f52d Split output/input audio capture sources
- Split input and output audio captures so that they're different
   sources.  This allows easier handling and enumeration of audio
   devices without having to do some sort of string processing.

   This way the user interface code can handle this a bit more easily,
   and so that it doesn't confuse users either.  This should be done for
   all audio capture sources for all operating systems.  You don't have
   to duplicate any code, you just need to create input/output wrapper
   functions to designate the audio as input or output before creation.

 - Make it detect soundflower and wavtap devices as mac "output" devices
   (even though they're actually input) for the mac output capture, and
   make it so that users can select a default output capture and
   automatically use soundflower or wavtap.

   I'm not entirely happy about having to do this, but because mac is
   designed this way, this is really the only way to handle it that
   makes it easier for users and UI code to deal with.

   Note that soundflower and wavtap are still also designated as input
   devices, so will still show up in input device enumeration.

 - Remove pragma messages because they were kind polluting the other
   compiler messages and just getting in the way.  In the future we can
   just do a grep for TODO to find them.

 - Redo list property again, this time using a safer internal array,
   rather than requiring sketchy array inputs.  Having functions handle
   everything behind the scenes is much safer.

 - Remove the reference counter debug log code, as it was included
   unintentionally in a commit.
2014-03-03 02:56:54 -07:00
jp9000
e9342143a7 Simplify and extend callback/signalling system
- Signals and dynamic callbacks now require declarations to be made
  before being used.  What this does is allows us to get information
  about the functions dynamically which can be relayed to the user and
  plugins for future extended usage (this should have big implications
  later for scripting in particular, hopefully).

- Reduced the number of types calldata uses from "everything I could
  think of" to simply integer, float, bool, pointer/object, string.
  Integer data is now stored as long long.  Floats are now stored as
  doubles (check em).

- Use a more consistent naming scheme for lexer error/warning macros.

- Fixed a rather nasty bug where switching to an existing scene would
  cause it to increment sourceSceneRefs, which would mean that it would
  never end up never properly removing the source when the user clicks
  removed (stayed in limbo, obs_source_remove never got called)
2014-03-01 05:54:55 -07:00
jp9000
771eac6015 Be more consistent about log levels
LOG_ERROR should be used in places where though recoverable (or at least
something that can be handled safely), was unexpected, and may affect
the user/application.

LOG_WARNING should be used in places where it's not entirely unexpected,
is recoverable, and doesn't really affect the user/application.
2014-02-28 20:02:29 -07:00
jp9000
268e4e7811 Add more checks for NULL pointers 2014-02-23 22:39:33 -07:00
jp9000
096cce9a86 Rename scene signals
the signals for scenes could have potentially conflicted with default
source signals.  "remove" should be used for source removal, for
example.  Changed the scene signals to "item-add" and "item-remove" for
its items.
2014-02-23 18:58:01 -07:00
jp9000
be81276f03 Implement volume handling
- Remove obs_source::type because it became redundant now that the
   type is always stored in the obs_source::info variable.

 - Apply presentation volumes of 1.0 and 0.0 to sources when they
   activate/deactivate, respectively.  It also applies that presentation
   volume to all sub-sources, with exception of transition sources.
   Transition sources must apply presentation volume manually to their
   sub-sources with the new transition functions below.

 - Add a "transition_volume" variable to obs_source structure, and add
   three functions for handling volume for transitions:

   * obs_transition_begin_frame
   * obs_source_set_transition_vol
   * obs_transition_end_frame

   Because the to/from targets of a transition source might both contain
   some of the same sources, handling the transitioning of volumes for
   that specific situation becomes an issue.

   So for transitions, instead of modifying the presentation volumes
   directly for both sets of sources, we do this:

   - First, call obs_transition_begin_frame at the beginning of each
     transition frame, which will reset transition volumes for all
     sub-sources to 0.  Presentation volumes remain unchanged.

   - Call obs_source_set_transition_vol on each sub-source, which will
     then add the volume to the transition volume for each source in
     that source's tree.  Presentation volumes still remain unchanged.

   - Then you call obs_trandition_end_frame when complete, which will
     then finally set the presentation volumes to the transition
     volumes.

   For example, let's say that there's one source that's within both the
   "transitioning from" sources and "transition to" sources.  It would
   add both the fade in and fade out volumes to that source, and then
   when the frame is complete, it would set the presentation volume to
   the sum of those two values, rather than set the presentation volume
   for that same source twice which would cause weird volume jittering
   and also set the wrong values.
2014-02-21 19:41:38 -07:00
jp9000
d4f1eacc1f Implement source activation/deactivation
Now sources will be properly activated and deactivated when they are in
use or not in use.

Had to figure out a way to handle child sources, and children of
children, just ended up implementing simple functions that parents use
to signal adding/removal to help with hierarchial activation and
deactivation of child sources.

To prevent the source activate/deactivate callbacks from being called
more than once, added an activation reference counter.  The first
increment will call the activate callback, and the last decrement will
call the deactivate callback.

Added "source-activate" and "source-deactivate" signals to the main obs
signal handler, and "activate" and "deactivate" to individual source
signal handlers.

Also, fixed the main window so it properly selects a source when the
current active scene has been changed.
2014-02-20 22:04:14 -07:00
jp9000
14c95ac421 Add functions to enumerate source children/tree 2014-02-20 17:44:42 -07:00
jp9000
966b943d5b Remove majority of warnings
There were a *lot* of warnings, managed to remove most of them.

Also, put warning flags before C_FLAGS and CXX_FLAGS, rather than after,
as -Wall -Wextra was overwriting flags that came before it.
2014-02-14 15:13:36 -07:00
jp9000
8e81d8be56 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
jp9000
b067440f73 Use bzalloc instead of bmalloc then memset
Reduces needless code repetition and still allows for proper memory
alignment.  Cleans up the code a bit.
2014-02-09 12:34:07 -07:00
Palana
ac23df500a Remove external ref count visibility
The returned ref count was never used and the returned value doesn't
actually confer any meaning in a multithreaded environment
2014-02-03 02:34:06 +01:00
jp9000
37ed83acec Use QMetaObject::invokeMethod in libobs callbacks
Doing this ensures Qt thread safety when adding/removing sources and
scenes, because it will defer the function call to the main thread.
2014-02-02 17:03:55 -07:00
jp9000
6e1dd92f0c Improve thread safety in UI code
- Implemented better C++ classes for handling scenes/sources/items in
  obs.hpp, allowing them to automatically increment and decrement the
  references of each, as well as assign them to QVariants.

- Because QVariants are now using the C++ classes, remove the pointer
  QVariant wrapper.

- Use the new C++ classes with the QVariant user data of list box items,
  both for the sake of thread safety and to ensure that the data
  referenced is not freed until removed.  NOTE: still might need some
  testing.

- Implemented a source-remove signal from libobs, and start using that
  signal instead of the source-destroy signal for signalling item
  removal.
2014-02-02 14:26:23 -07:00
jp9000
74032922bc Fix another bug (don't commit without compiling)
Also don't code in anger
2014-01-30 12:42:20 -07:00
jp9000
73d4e1331c And cover the one in scene_destroy 2014-01-30 12:41:11 -07:00
jp9000
7b37dc6cbb Oh and while we're at it I suppose another fix 2014-01-30 12:39:26 -07:00
jp9000
f26cb706c2 Clean up the previous commit a bit
The was_removed variable was rather unnecessary
2014-01-30 12:35:21 -07:00
jp9000
f2e1ce533c Use mutex instead of variable for RC check 2014-01-30 12:29:13 -07:00
jp9000
103ef75310 Improve thread safety for scene items
Scene items previously were removed by calling obs_sceneitem_destroy,
but this proved to be a potential race condition where two different
threads could try to destroy the same scene item at the same time.

Instead of doing that, reference counting is now used on scene items,
and an explicit obs_sceneitem_remove function is used instead for item
removal, which sets a 'removed' variable to ensure it can only be called
exactly one time.
2014-01-30 01:31:52 -07:00
jp9000
3243a9f8c5 Fix the design flaw with obs_sceneitem_destroy
The previous commit used the scene as a  parameter to check to see if
the scene item was still present within the scene before destroying, but
this was actually unnecessary because the fault was because the destroy
signal was being triggered *before* the scene's mutex locked, thus
causing a race condition.  I changed the code so that it signals after
the lock instead of before, so the scene parameter should no longer be
necessary.
2014-01-29 18:27:42 -07:00
Palana
2fa208adfb Check if scene item is actually alive when calling obs_sceneitem_destroy
Prevents a double free in case the scene item was previously removed
2014-01-29 22:52:05 +01:00
Palana
af03444cbe Use recursive mutex for scene mutex
Fixes a deadlock when trying to remove a source from the GUI. The scene
item signal handlers would mark the source as removed which results in
the video thread also trying to run obs_sceneitem_destroy thereby
deadlocking the video thread (and the GUI thread)
2014-01-29 22:46:39 +01:00
jp9000
9116be8d9c Improve safety for settings usage
- Add 'set_default' functions to obs-data.*.  These functions ensure
  that a paramter exists and that the parameter is of a specific type.
  If not, it will create or overwrite the value with the default setting
  instead.

  These functions are meant to be explicitly called before using any of
  the 'get' functions.  The reason why it was designed this way is to
  encourage defaults to be set in a single place/function.

  For example, ideal usage is to create one function for your data,
  "set_my_defaults(obs_data_t data)", set all the default values within
  that function, and then call that function on create/update, that way
  all defaults are centralized to a single place.

- Ensure that data passed to sources/encoders/outputs/etc is always
  valid, and not a null value.

- While I'm remembering, fix a few defaults of the main program config
  file data.
2014-01-28 18:41:24 -07:00
jp9000
6c44291693 Implement settings interface for plugins
Add a fairly easy to use settings interface that can be passed to
plugins, and replaced the old character string system that was being
used before.  The new data interface allows for an easier method of
getting/altering settings for plugins, and is built to be serializable
to/from JSON.

Also, removed another wxFormBuilder file that was no longer in use.
2014-01-27 23:14:58 -07:00
jp9000
a2a8a5f148 Added add/remove signals to scenes
Scenes will now signal via their source when an item has been added
or removed from them.

  "add" - Item added to the scene.
  Parameters:  "scene": Scene that the item was added to.
               "item":  Item that was added.

  "remove" - Item removed from the scene.
  Parameters:  "scene": Scene that the item was removed from.
               "item":  Item that was removed.
2014-01-04 13:47:48 -07:00
jp9000
1c91e0d0e0 forgot to lock the mutex when destroying a scene item 2014-01-01 10:28:37 -07:00
jp9000
966c091078 make scene items use linked list rather than array (containers are a bad habit), add a few functions for getting scene item information, also use a mutex to prevent race conditions when using the linked list 2014-01-01 10:22:55 -07:00
jp9000
c129cc37cb update API and implement preliminary ability to add sources to scenes 2013-12-30 06:56:39 -07:00
jp9000
c4af3e2a75 change obs_scene_destroy to obs_scene_release, add ability to add scenes, fix name dialog sizing 2013-12-29 08:54:06 -07:00
jp9000
cec94b042e implement scene adding callbacks, make a few API tweaks 2013-12-28 05:33:16 -07:00
jp9000
95a7da2d4c add names to sources, use 'id' for the internal source identifier names rather than 'name' 2013-12-20 17:23:19 -07:00
jp9000
eeb76237eb removed deprecated/unused function 2013-12-17 22:45:50 -07:00
jp9000
aead95f5e3 converted project to vs2013, removed 2010 support (ugh) 2013-12-14 16:01:30 -07:00
jp9000
8298fa4dc7 With the permission of my fellow contributors, I'm switching obs-studio back to GPL v2+ to prevent issues between this project and the original OBS project, and for personal reasons to avoid legal ambiguity (not political reasons, I admittedly would prefer GPL v3+) 2013-12-02 22:24:38 -07:00
jp9000
71890e0365 removed now-redundant callback enum_children from sources 2013-11-20 21:52:20 -07:00
jp9000
409b011a8e cleaned up main internal data structure design, changed to reference counting for sources to ensure safe destruction of source objects from all parts of the system, added some service-related stuff for testing 2013-11-20 15:00:16 -07:00
jp9000
146e9a7dbd added support for jansson, added new output files, made some adjustments to the API, fixed a UI subclass issue 2013-11-13 06:24:20 -07:00
jp9000
ac2c08927f added intial async audio/video code, fixed a few bugs, improved thread safety, and made a few other minor adjustments 2013-10-24 00:57:55 -07:00
jp9000
18834c6a45 some static analysis cleanup 2013-10-17 17:21:42 -07:00
jp9000
9570f0b8d7 change names, fix some bugs, minor GL/D3D fixes, update tests, fix effect files, output a little more debug information 2013-10-14 12:37:52 -07:00
jp9000
f255ae1922 first commit 2013-09-30 19:37:13 -07:00