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

335 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
jp9000
8225a0697a util/darray.h: Fix astoundingly silly assert 2014-04-19 20:35:03 -07:00
jp9000
7a60694159 obs-properties: Add a few features
Just wanted the ability to be able to add private data to the properties
data.  Makes it a little easier to manage data if you get updates from
controls.
2014-04-19 20:29:11 -07:00
jp9000
79b88c4cbb Merge branch 'master' of https://github.com/jp9000/obs-studio 2014-04-19 06:34:13 -07:00
jp9000
c78fe3e306 obs-video.c: Fix minor bug
The pointer here is confusing, so I'm just going to remove it and have
it return the value instead.
2014-04-19 06:33:11 -07:00
Palana
4bb4b859bf Initialize returned pointer to always trigger NULL checks in callers
Also avoid allocation roundtrip if the file is empty after the BOM
2014-04-19 07:37:38 +02:00
jp9000
81153cb16d Fix code that breaks with VC (terrible compiler)
VC2013 still does not properly support placement of variables anywhere
in the scope.  It's a garbage compiler, always will be a garbage
compiler.
2014-04-14 14:21:32 -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
Palana
c86fa7bb30 Use libc++ inspired clock instead of the deprecated AbsoluteToNanoseconds
This also makes the clang static analyzer happy (it complained about
uninitialized fields in the AbsoluteTime struct)
2014-04-14 23:02:53 +02:00
jp9000
fa490fa8c4 Implement some basic logging for windows 2014-04-14 04:02:11 -07:00
jp9000
a4a52d1c87 Fix bug where packets weren't interleaving
Packets were not interleaving, thus new data was being sent out with
potentially non-monotonically increasing timestamps
2014-04-14 02:02:59 -07:00
BtbN
075820028f Improve bundle fixup 2014-04-13 11:05:46 -07:00
jp9000
2451b80ef6 Fix drawing bug with async video sources
Before, async video sources would flicker because they were only being
drawn when they were updated.  So when updated, they'd draw that frame,
then it would stop drawing it until it updated again.  This fixes that
issue and they should now draw properly.

Also, fix a few other minor bugs and issues relating to async video,
and make it so that non-async video filters can be properly applied to
them.

For the purposes of testing, change the 'test-random' source to an async
video source that updates every quarter of a second with a new random
face.

Also fix a bug where non-async video sources wouldn't have filter
effects applied properly.
2014-04-13 02:22:28 -07:00
Jim
b53e2a88a3 Merge pull request #59 from BtbN/linux_fixes
Linux fixes and additions
2014-04-12 10:53:09 -07:00
jp9000
b427397aa9 RTMP output: Implement frame drop code
A little bit of history about frame dropping:

I did a large number of experiments with frame dropping in old versions
of OBS1, and it's not an easy thing to deal with.  I tried just about
everything from standard i-frame delay, to large buffers, to dumping
packets, to super-unnecessarily-complex things that just ended up
causing more problems than they was worth.

When I did my experiments, I found that the most ideal frame drop system
(in terms of reducing the amount of total data that needed to be
dropped) was in the 0.4xx days where I had a 3 second frame-drop buffer
where I could calculate the actual buffer size in bytes, and then
intellgently choose packets in that buffer to trim it down to a specific
size while minimizing the number of p-frames and i-frames dropped, and
preventing the actual impact of dropped frames on the stream.  The
downside of it was that it required too much extra latency, and far too
many people complained about it, so it was removed in favor of the
current system.

The current system I just refer to just as 'packet dumping', which when
combined with low keyframe intervals (like most services use these
days), is the next-best method from my experience.  Just dump the buffer
when you reach a threshold of buffering (which I prefer to measure with
time rather than in size), then wait for a new i-frame.  Simple,
effective, and reduces the risk of consecutive buffering, while still
having fairly low impact on the stream output due to the low keyframe
interval of services.

By the way, audio will not (and should not ever) be dropped, lest you
end up with syncing issues (among other nasty things) specific to server
implementation.
2014-04-12 04:34:15 -07:00
BtbN
97c94b183a Add copy_texture_region function 2014-04-12 12:45:18 +02:00
Timo R
b312261abd Flush after logging 2014-04-12 12:45:18 +02:00
jp9000
519c4f4118 Fix issue when using multiple video encoders
- Fix an issue that could occur when using more than one video encoder.
   Audio/video would not sync up correctly because they were expected to
   be paired with a particular encoder.  This simply adds a little
   helper variable to encoder packets that specifies the system time in
   microseconds.  We then use that system time to sync

 - Fix an issue with x264 with fractional FPS rates (29.97 and 59.94
   particularly) where it would create ridiculously large stream
   outputs.  The problem was that you shouldn't set the timebase_*
   variables in the x264 params manually, let x264 handle the default
   values for it and leave them at 0.

 - Make x264 use CFR output, because there's no reason to ever use VFR
   in this case.
2014-04-10 11:59:42 -07:00
jp9000
92522d1886 Implement RTMP module (still needs drop code)
- Implement the RTMP output module.  This time around, we just use a
   simple FLV muxer, then just write to the stream with RTMP_Write.
   Easy and effective.

 - Fix the FLV muxer, the muxer now outputs proper FLV packets.

 - Output API:
   * When using encoders, automatically interleave encoded packets
     before sending it to the output.

   * Pair encoders and have them automatically wait for the other to
     start to ensure sync.

   * Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
     because it was a bit confusing, and doing this makes a lot more
     sense for outputs that need to stop suddenly (disconnections/etc).

 - Encoder API:
   * Remove some unnecessary encoder functions from the actual API and
     make them internal.  Most of the encoder functions are handled
     automatically by outputs anyway, so there's no real need to expose
     them and end up inadvertently confusing plugin writers.

   * Have audio encoders wait for the video encoder to get a frame, then
     start at the exact data point that the first video frame starts to
     ensure the most accrate sync of video/audio possible.

   * Add a required 'frame_size' callback for audio encoders that
     returns the expected number of frames desired to encode with.  This
     way, the libobs encoder API can handle the circular buffering
     internally automatically for the encoder modules, so encoder
     writers don't have to do it themselves.

 - Fix a few bugs in the serializer interface.  It was passing the wrong
   variable for the data in a few cases.

 - If a source has video, make obs_source_update defer the actual update
   callback until the tick function is called to prevent threading
   issues.
2014-04-07 22:00:10 -07:00
jp9000
7eec72245d Fix graphics device export header
Caused D3D11 library to fail on load.  Don't know how I didn't see this
sooner.
2014-04-07 01:31:13 -07:00
jp9000
59969844a1 Add comments to config-file.h
Someone got rather confused over what the "default" functions did, so
hopefully this clears it up a bit.
2014-04-07 01:29:56 -07:00
jp9000
fd24d0de2f Use atomics for allocation counter
I was getting cases where the CPU cache was causing issues with the
allocation counter, for the longest time I thought I was doing something
wrong, but when the allocation counter went below 0, I realized it was
because I didn't use atomics for incrementing/decrementing the
allocation counter variable.  The allocation counter now always should
have the correct value.
2014-04-07 01:25:38 -07:00
jp9000
22aec1c391 Well, that was embarassing. (Remove size macro)
...I think I need sleep.  That last commit before this one shows it
quite clearly.
2014-04-05 01:49:21 -07:00
jp9000
ac43d9bb89 And fix another bug that I just made
Accidentally removed a function from the main module declaration macro.
2014-04-05 01:47:08 -07:00
jp9000
bd331c8ffe Remove the weird size stuff from OBS_DECLARE_MODULE
Instead of doing this, just use macros to handle this situation.

Also, fix a minor bug in AAC encoder
2014-04-05 01:45:53 -07:00
jp9000
8c74db9ffc Add packet interleaving and improve encoder API
- Add interleaving of video/audio packets for outputs that are encoded
   and expect both video and audio data, sorting the packets and sending
   them to the output when both video and audio is received.

 - Combine create and initialize callbacks for the encoder API callback
   interface.
2014-04-04 23:21:19 -07:00
Palana
4edadcc0a6 Add NV12 conversion shader 2014-04-04 20:55:38 +02:00
jp9000
1bca7e0a3e Improve properties API
Improve the properties API so that it can actually respond somewhat to
user input.  Maybe later this might be further improved or replaced with
something script-based.

When creating a property, you can now add a callback to that property
that notifies when the property has been changed in the user interface.
Return true if you want the properties to be refreshed, or false if not.
Though now that I think about it I doubt there would ever be a case
where you would have this callback and *not* refresh the properties.

Regardless, this allows functions to change the values of properties or
settings, or enable/disable/hide other property controls from view
dynamically.
2014-04-04 00:30:37 -07:00
BtbN
23c3dfc6be Fix log_level check 2014-04-03 23:41:07 +02:00
jp9000
4a652ec82d obs-output module: Fill out more functions
- Add start/stop code to obs-output module

 - Use a circular buffer for the buffered encoder packets instead of a
   dynamic array

 - Add pthreads.lib as a dependency to obs-output module on windows in
   visual studio project files

 - Fix an windows export bug for avc parsing functions on windows.
   Also, rename those functions to be more consistent with each other.

 - Make outputs use a single function for encoded data rather than
   multiple functions

 - Add the ability to make 'text' properties be passworded
2014-04-02 00:42:12 -07:00
BtbN
044680f0b8 Add config.h generation and wrapper header, currently only for OBS_VERSION 2014-04-01 22:11:44 +02:00
jp9000
0cf9e0cfdd Add preliminary FLV/RTMP output (incomplete)
- obs-outputs module:  Add preliminary code to send out data, and add
   an FLV muxer.  This time we don't really need to build the packets
   ourselves, we can just use the FLV muxer and send it directly to
   RTMP_Write and it should automatically parse the entire stream for us
   without us having to do much manual code at all.  We'll see how it
   goes.

 - libobs:  Add AVC NAL packet parsing code

 - libobs/media-io:  Add quick helper functions for audio/video to get
   the width/height/fps/samplerate/etc rather than having to query the
   info structures each time.

 - libobs (obs-output.c):  Change 'connect' signal to 'start' and 'stop'
   signals.  'start' now specifies an error code rather than whether it
   simply failed, that way the client can actually know *why* a failure
   occurred.  Added those error codes to obs-defs.h.

 - libobs:  Add a few functions to duplicate/free encoder packets
2014-04-01 11:55:18 -07:00
jp9000
d42ff7f0dd Improve serializer and add array serializer
The serializer code is meant to be used as a means of reading/writing
data from any arbitrary type of input/output.

The array output serializer makes it so we can stream data to a dynamic
array on the fly.
2014-04-01 11:27:27 -07:00
jp9000
263f940806 Fix CMakeLists.txt for each project (my fault) 2014-03-29 17:29:02 -07:00
jp9000
0a86e8fb3f Add dummy GL texture flag & direct object access
- Add dummy GL texture support to allow libobs texture references to be
   created for GL without

 - Add a texture_getobj function to allow the retrieval of the
   context-specific object, such as the D3D texture pointer, or the
   OpenGL texture object handle.

 - Also cleaned up the export stuff.  I realized it was all totally
   superfluous.  Kind of a dumb moment, but nice to clean it up
   regardless.
2014-03-29 17:19:31 -07:00
jp9000
6da26a3a1c Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs.  If an encoder
   is destroyed, it will automatically remove itself from that output.
   I specifically didn't want to do reference counting because it leaves
   too much potential for unchecked references and it just felt like it
   would be more trouble than it's worth.

 - Add a 'flags' value to the output definition structure.  This lets
   the output specify if it uses video/audio, and whether the output is
   meant to be used with OBS encoders or not.

 - Remove boilerplate code for outputs.  This makes it easier to program
   outputs.  The boilerplate code involved before was mostly just
   involving connecting to the audio/video data streams directly in each
   output plugin.

   Instead of doing that, simply add plugin callback functions for
   receiving video/audio (either encoded or non-encoded, whichever it's
   set to use), and then call obs_output_begin_data_capture and
   obs_output_end_data_capture to automatically handle setting up
   connections to raw or encoded video/audio streams for the plugin.

 - Remove 'active' function from output callbacks, as it's no longer
   really needed now that the libobs output context automatically knows
   when the output is active or not.

 - Make it so that an encoder cannot be destroyed until all data
   connections to the encoder have been removed.

 - Change the 'start' and 'stop' functions in the encoder interface to
   just an 'initialize' callback, which initializes the encoder.

 - Make it so that the encoder must be initialized first before the data
   stream can be started.  The reason why initialization was separated
   from starting the encoder stream was because we need to be able to
   check that the settings used with the encoder *can* be used first.

   This problem was especially annoying if you had both video/audio
   encoding.  Before, you'd have to check the return value from
   obs_encoder_start, and if that second encoder fails, then you
   basically had to stop the first encoder again, making for
   unnecessary boilerplate code whenever starting up two encoders.
2014-03-27 21:50:15 -07:00
jp9000
d9251f9e87 Add source properties window (very preliminary)
- Add a properties window for sources so that you can now actually edit
   the settings for sources.  Also, display the source by itself in the
   window (Note: not working on mac, and possibly not working on linux).

   When changing the settings for a source, it will call
   obs_source_update on that source when you have modified any values
   automatically.

 - Add a properties 'widget', eventually I want to turn this in to a
   regular nice properties view like you'd see in the designer, but
   right now it just uses a form layout in a QScrollArea with regular
   controls to display the properties.  It's clunky but works for the
   time being.

 - Make it so that swap chains and the main graphics subsystem will
   automatically use at least one backbuffer if none was specified

 - Fix bug where displays weren't added to the main display array

 - Make it so that you can get the properties of a source via the actual
   pointer of a source/encoder/output in addition to being able to look
   up properties via identifier.

 - When registering source types, check for required functions (wasn't
   doing it before).  getheight/getwidth should not be optional if it's
   a video source as well.

 - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted
   libobs pointers

 - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to
   automatically disconnect them on destruction

 - Move the "scale and center" calculation in window-basic-main.cpp to
   its own function and in its own source file

 - Add an 'update' callback to WASAPI audio sources
2014-03-23 01:07:54 -07:00
jp9000
6c904650b3 Fix GNU atomic builtins
The ones that were being used returned the previous value rather than
the new value
2014-03-17 14:16:05 -07:00
jp9000
950f780b81 Make sure ot use the right enum name
Microsoft's garbage compiler just doesn't even..  read the names of
enums.  It sees an enum and goes "durr, that's an int" without even
properly evaluating it.  Just total garbage, as per usual.
2014-03-16 20:44:27 -07:00
jp9000
291d9961cd obs-data: Internally store as int or double
If integers are used, then store as integers.  If doubles are used, then
store as doubles.  This way precision issues are prevented.
2014-03-16 20:38:13 -07: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
3ed647b8a0 Set defaults automatically
Automatically query defaults for sources/outputs/encoders and set them
before calling create
2014-03-16 17:42:37 -07:00
jp9000
2920369daf Call send_packet instead of.. doing nothing
GCC warned of this, but strangely not clang.
2014-03-16 16:28:21 -07:00
jp9000
bb92d582bf Add atomic increment/decrement platform funcs 2014-03-16 16:23:11 -07:00
jp9000
fd37d9e9a8 Implement encoder interface (still preliminary)
- Implement OBS encoder interface.  It was previously incomplete, but
   now is reaching some level of completion, though probably should
   still be considered preliminary.

   I had originally implemented it so that encoders only have a 'reset'
   function to reset their parameters, but I felt that having both a
   'start' and 'stop' function would be useful.

   Encoders are now assigned to a specific video/audio media output each
   rather than implicitely assigned to the main obs video/audio
   contexts.  This allows separate encoder contexts that aren't
   necessarily assigned to the main video/audio context (which is useful
   for things such as recording specific sources).  Will probably have
   to do this for regular obs outputs as well.

   When creating an encoder, you must now explicitely state whether that
   encoder is an audio or video encoder.

   Audio and video can optionally be automatically converted depending
   on what the encoder specifies.

   When something 'attaches' to an encoder, the first attachment starts
   the encoder, and the encoder automatically attaches to the media
   output context associated with it.  Subsequent attachments won't have
   the same effect, they will just start receiving the same encoder data
   when the next keyframe plays (along with SEI if any).  When detaching
   from the encoder, the last detachment will fully stop the encoder and
   detach the encoder from the media output context associated with the
   encoder.

   SEI must actually be exported separately; because new encoder
   attachments may not always be at the beginning of the stream, the
   first keyframe they get must have that SEI data in it.  If the
   encoder has SEI data, it needs only add one small function to simply
   query that SEI data, and then that data will be handled automatically
   by libobs for all subsequent encoder attachments.

 - Implement x264 encoder plugin, move x264 files to separate plugin to
   separate necessary dependencies.

 - Change video/audio frame output structures to not use const
   qualifiers to prevent issues with non-const function usage elsewhere.
   This was an issue when writing the x264 encoder, as the x264 encoder
   expects non-const frame data.

   Change stagesurf_map to return a non-const data type to prevent this
   as well.

 - Change full range parameter of video scaler to be an enum rather than
   boolean
2014-03-16 16:21:34 -07:00
jp9000
3aedfdfb73 Fix wrong linux function
Used the mac function instead by accident
2014-03-10 19:27:59 -07:00
jp9000
5e1cac68f4 Fix semaphore mac code and mac plugin
Didn't convert the event names and didn't have the right mac includes
2014-03-10 19:24:09 -07:00
jp9000
c023ef69ea Fix non-windows event code
And remember to compile on non-windows systems before committing
2014-03-10 19:08:42 -07:00
jp9000
585fd8f969 Fix audio streaming and mac semaphores
...The reason why audio didn't work was because I overwrote the bitrate
values.

As for semaphores, mac doesn't support unnamed semaphores without using
mach semaphores.  So, I just implemented a semaphore wrapper for each
OS.
2014-03-10 19:04:00 -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