Commit graph

135 commits

Author SHA1 Message Date
Ryan Foster 797c9d330c libobs: Copy metadata for tracks/streams when remuxing 2018-06-02 10:15:13 -04:00
Shaolin ffd2303a36 libobs: Log YUV space/range on video reset
Closes jp9000/obs-studio#1196
2018-02-20 04:26:29 -08:00
pkviet 645d6ae8dd libobs/media-io: Change speaker layout to match FFmpeg aac.
(This commit also modifies the obs-ffmpeg module)

The default channel layouts from aac spec are implemented in FFmpeg
native aac encoder as follows:

    AV_CH_LAYOUT_MONO,
    AV_CH_LAYOUT_STEREO,
    AV_CH_LAYOUT_SURROUND,
    AV_CH_LAYOUT_4POINT0,
    AV_CH_LAYOUT_5POINT0_BACK,
    AV_CH_LAYOUT_5POINT1_BACK,
    AV_CH_LAYOUT_7POINT1,

The correspondence of speaker layouts to AV_CH_LAYOUT from FFmpeg is
changed to reflect the previous table.

Although FFmpeg native aac encoder can now encode all the layouts listed
in avutil channel_layout.h (on master), there might be issues with older
FFmpeg binaries.

Note that 2.1 speaker layout will be encoded as AV_CH_LAYOUT_SURROUND
(FL FR FC) because it is not listed as the default layout for three
channels.

This just means some optimizations for LFE channel will not be used by
the encoder which will treat it as an SCE (single channel element).

Closes jp9000/obs-studio#1182
2018-02-06 06:14:24 -08:00
Jim 77643cce1e
Merge pull request #1139 from takev/pulseaudio-surround-selection
linux-pulseaudio: Surround speaker map
2018-01-19 16:14:04 -08:00
Tjienta Vara 48a8e750bb linux-pulseaudio: Surround speaker map
When using more than two channels, the channel map of pulse-audio is incorrect.

Add an API for getting a speaker map based on OBS speaker layout. Then use the
speaker map when connecting to a pulse-audio device, for both source and
monitor output.
2018-01-17 13:05:04 +01:00
Christoph Hohmann f4142a8ac8 libobs: Fix audio buffer clear in custom source mixing
The memset in custom_audio_render() did not clear all audio buffers when
the number of output channels was less then 8.  This caused wrong audio
output on mixes that did not get cleared.

Closes jp9000/obs-studio#1123
2018-01-16 11:56:11 -08:00
Jim 98d291c037
Merge pull request #1122 from SuslikV/patch-5
libobs: Fix incomplete struct in scaler call
2018-01-05 16:00:54 -08:00
pkviet 67e48ecc2c libobs/media-io: Replace quad with 4.0
(also obs, deps/media-playback, libobs/audio-monitoring, decklink,
linux-alsa, linux-pulseaudio, mac-capture, obs-ffmpeg, win-dshow,
win-wasapi)

Default channel layout for 4 channels is 4.0 in FFmpeg.
Replacing quad with 4.0 will improve compatibility since FFmpeg has
better support of its default channel layouts.
2018-01-05 09:48:52 -08:00
pkviet fb580535c9 libobs/media-io: Clean surround API
(also modifies obs-ffmpeg, audio-monitoring, win-wasapi, decklink,
obs-outputs)

Removes speaker layouts which are not exposed in UI.  The speaker
layouts selectable by users in the UI are the most common ones.  It is
not necessary to keep other layouts.  (This basically removes
5POINT1_SURROUND, 7POINT1_SURROUND, SURROUND =3.0).
2018-01-05 09:47:59 -08:00
SuslikV ac906ba6e5
libobs: Fix incomplete struct in scaler call
Fixes the Rescale Output range and colorspace conversion issue.

When range and colorspace properties were missing and thus undefined:
get_ffmpeg_coeffs returns SWS_CS_ITU601
get_ffmpeg_range_type returns 0 (wich is VIDEO_RANGE_PARTIAL).

Should solve mantis: https://obsproject.com/mantis/view.php?id=947
More info: https://obsproject.com/forum/threads/x264-rescale-output-over-saturating-colors.69730/
2017-12-24 11:13:20 +02:00
jp9000 3114a240b4 libobs/media-io: Add ifdef for newer FFmpeg functions
The AVCodecParameters weren't introduced until avcodec version 57.48.101
(FFmpeg version 3.1), so this will make sure to still use the older
avcodec_copy_context if the detected FFmpeg version is earlier.
2017-12-06 07:46:49 -08:00
jp9000 0d6204c8af Fix a number of MSVC warnings
Fixes a number of warnings with all modules
2017-12-05 13:53:44 -08:00
pkviet bbac3280c1 libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)

Adds surround sound audio support to the core, core plugins, and user
interface.

Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts  (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
		   opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
	 HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
	 videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
         (due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST:	 stereo plugins keep in general only the first two channels.
	 surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
         (not implemented due to lack of usefulness)

Closes jp9000/obs-studio#968
2017-11-26 03:41:53 -08:00
pkviet d670d7badb libobs: Fix FFmpeg constants
(This commit also modifies the deps/media-playback, obs-ffmpeg, and
win-dshow modules)

More fixes due to ffmpeg renaming some constants and deprecating
AVFMT_RAWPICTURE and AV_PIX_FMT_VDA_VLD.
Latter replaced by AV_PIX_FMT_VIDEOTOOLBOX per ffmpeg dev advice.

Closes jp9000/obs-studio#1061
2017-11-16 21:38:37 -08:00
Richard Stanway a4a8b385c5 libobs: Use new ffmpeg constants 2017-10-26 19:18:30 +02:00
jp9000 849944ca79 libobs/media-io: Fix decompress_420 function
This function had a number of bugs and just wasn't working properly at
all.  This function is currently not used in public builds because GPU
is used for color conversion instead (hence why it had probably not
really been tested), but a need came up where CPU conversion was useful
for the sake of testing something else in the back-end, and it needed to
be fixed before CPU conversion could be used.
2017-10-02 07:36:02 -07:00
jp9000 dc1e233168 libobs: Move macro to internal C file
Modifying this value would cause the entire project to recompile when
it's only used in one file in the first place.
2017-10-02 07:36:02 -07:00
jp9000 a81646ed9c libobs: Don't allow lagged frames to be counted as skipped
Prevents lagged frames (frames that took too long to render) to be
counted as skipped frames (frames that are skipped due to encoding
taking too long to process)
2017-05-06 11:29:32 -07:00
jp9000 829ec5be2d libobs: Fix skipped frames reporting
When frames are skipped the skipped frame count would increment, but the
total frame count would not increment, causing the percentage
calculation to fail.

Additionally, the skipped frames log reporting has been moved to
media-io/video-io.c instead of each output.
2017-05-06 11:29:25 -07:00
jp9000 f10e2c6740 libobs: Increase maximum audio tracks to 6 2016-12-21 17:13:19 -08:00
jpk c3629eacb5 libobs: Add Y800 color format support
(Note: Also modified the obs-ffmpeg plugin module)

Allows the ability for frame data to pass 8-bit grayscale images (Y800
color format).

Closes jp9000/obs-studio#515
2016-03-24 03:33:35 -07:00
jp9000 20db7649aa libobs/media-io: Reset audio array for each input
The audio data would get overwritten and become invalid if there was
more than one input
2016-01-26 11:49:36 -08:00
jp9000 27438a5156 libobs/media-io: Remove 'volume' from audio_data (skip)
(Note: This commit breaks libobs compilation.  Skip if bisecting)

This variable is somewhat redundant.  Volume is already known/accessible
to front-ends.
2016-01-26 11:49:31 -08:00
jp9000 ee1842d1f5 libobs/media-io: Remove audio lines (skip)
(Note: This commit breaks libobs compilation.  Skip if bisecting)

Uses a callback and allows the caller to mix audio.  Additionally,
allows the callback to return audio later, allowing it to buffer as much
as it needs.
2016-01-26 11:49:28 -08:00
jp9000 23f4d17d41 libobs/media-io: Fix bug (skipped frames including lagged frames)
The skipped frame count (dropped frames due to encoding being
overloaded) would erroneously include lagged frames (dropped frames due
to render stalls).  This will make diagnosing actual issues a user might
be having a bit easier.
2016-01-25 17:29:09 -08:00
jp9000 8f7d8d05b2 libobs: Add sample_rate param to conv_frames_to_time
Prevents from having to query the base audio subsystem for the sample
rate each time the function is called
2015-12-22 06:18:21 -08:00
jp9000 fc057f6d88 libobs/media-io: Add funcs to convert between nanoseconds/frames
Uses 128bit integer math to prevent overflow
2015-12-22 06:18:18 -08:00
jp9000 c32407d1df libobs/media-io: Increase TS smooth threshold to 70ms
With certain devices (AVerMedia C985 and LGP), audio timestamps are
bad, and a 50ms threshold of audio data "smoothing" (making consecutive
audio packets seamless with one another) isn't enough to handle bad
consecutive timestamp values.  After testing, 70ms sufficiently solves
the issue.
2015-11-28 16:42:32 -08:00
Palana 95487c3eec libobs/media-io: Add frame rate helpers 2015-11-14 15:37:47 +01:00
jp9000 ff6cf508e5 libobs/media-io: Improve audio data logging
This improves logging for when audio data insertion is way out of bounds
or is getting cut off in the front due to a bad negative sync offset.

Instead of throwing out a log message for every time this happens with
each piece of data, it now states when the out of bounds or cutoff has
started and stopped only.
2015-08-27 16:33:07 -07:00
jp9000 263037102b libobs/media-io: Fix potential crash inserting audio
This fixes a case where an insertion of audio data would pass
valid_timestamp_range yet the insert position would cause a negative
integer position and thus an unsigned integer overflow.
2015-08-27 16:33:06 -07:00
Palana c6140b4756 libobs/media-io: Profile audio/video_thread 2015-08-12 15:30:29 +02:00
jp9000 c82da7da93 libobs/media-io: Add common audio math functions
This adds functions specific to audio math, which at the moment is just
converting to and from decibel and multiple.
2015-06-26 03:40:27 -07:00
jp9000 693962a468 libobs: Allow audio-io callback self-removal
Allows audio-io callbacks to remove themselves while in a callback.
2015-06-21 22:34:45 -07:00
Palana 4daa5c7aa7 media-io: Fix check before passing pointer to av_freep
Found by clang-3.7 (trunk 236075) via -Wpointer-bool-conversion:

warning: address of array 'rs->output_buffer' will always evaluate
to 'true'
2015-05-11 20:42:53 +02:00
jp9000 1b53215b99 libobs: Add function to get video format name 2015-04-18 00:03:21 -07:00
jp9000 908a165d62 Add planar YUV 4:4:4 format support
Adds the ability to natively output with planar YUV 4:4:4.
2015-04-17 20:16:40 -07:00
jp9000 822d1ec3fc libobs: Add packed yuv to planar 4:4:4 conversion 2015-04-16 22:51:31 -07:00
jp9000 0f346561ff libobs: Refactor pack_lum to pack_shift
Allows the ability to specify the bytes to shift as a parameter.  Useful
for planar 4:4:4 conversion.
2015-04-16 22:48:54 -07:00
jp9000 4e54c89f9c libobs: Fix full range min/max output
The minimum and maximum color range values were not being set by the
video_format_get_parameters function when full range was in use; I
assume it's because the expected min/max values of full range is
{0.0, 0.0, 0.0} and {1.0, 1.0, 1.0}, so I'm just making it so that it
sets those values if using full range.

Way to replicate the issue (windows):
1.) Create a win-dshow device capture source
2.) Select a device and set it to a YUV color format to enable YUV color
conversion
3.) Select "Full Range" in the color range property.
4.) Restart OBS, the device will then start up, but will display green
due to the fact that the min/max range values were never set, and are
left at their default value of 0.
2015-04-10 07:27:26 -07:00
jp9000 84e1f47ced (API Change) Add support for multiple audio mixers
API changed:
--------------------------

void obs_output_set_audio_encoder(
		obs_output_t *output,
		obs_encoder_t *encoder);

obs_encoder_t *obs_output_get_audio_encoder(
		const obs_output_t *output);

obs_encoder_t *obs_audio_encoder_create(
		const char *id,
		const char *name,
		obs_data_t *settings);

Changed to:
--------------------------

/* 'idx' specifies the track index of the output */
void obs_output_set_audio_encoder(
		obs_output_t *output,
		obs_encoder_t *encoder,
		size_t idx);

/* 'idx' specifies the track index of the output */
obs_encoder_t *obs_output_get_audio_encoder(
		const obs_output_t *output,
		size_t idx);

/* 'mixer_idx' specifies the mixer index to capture audio from */
obs_encoder_t *obs_audio_encoder_create(
		const char *id,
		const char *name,
		obs_data_t *settings,
		size_t mixer_idx);

Overview
--------------------------
This feature allows multiple audio mixers to be used at a time.  This
capability was able to be added with surprisingly very little extra
overhead.  Audio will not be mixed unless it's assigned to a specific
mixer, and mixers will not mix unless they have an active mix
connection.

Mostly this will be useful for being able to separate out specific audio
for recording versus streaming, but will also be useful for certain
streaming services that support multiple audio streams via RTMP.

I didn't want to use a variable amount of mixers due to the desire to
reduce heap allocations, so currently I set the limit to 4 simultaneous
mixers; this number can be increased later if needed, but honestly I
feel like it's just the right number to use.

Sources:

Sources can now specify which audio mixers their audio is mixed to; this
can be a single mixer or multiple mixers at a time.  The
obs_source_set_audio_mixers function sets the audio mixer which an audio
source applies to.  For example, 0xF would mean that the source applies
to all four mixers.

Audio Encoders:

Audio encoders now must specify which specific audio mixer they use when
they encode audio data.

Outputs:

Outputs that use encoders can now support multiple audio tracks at once
if they have the OBS_OUTPUT_MULTI_TRACK capability flag set.  This is
mostly only useful for certain types of RTMP transmissions, though may
be useful for file formats that support multiple audio tracks as well
later on.
2015-02-04 16:51:29 -08:00
jp9000 24eaf77963 libobs: Fix typo, 'audio' instead of 'video'
For some extremely inexplicable reason, I somehow managed to use 'video'
for the audio data instead of 'audio'.
2015-02-04 15:40:21 -08:00
jp9000 f93b2fe794 Set various thread names
Helps identify which threads are which when debugging
2015-01-03 02:37:20 -08:00
jp9000 11106c2fce libobs: Redesign/optimize frame encoding handling
Previously, the design for the interaction between the encoder thread
and the graphics thread was that the encoder thread would signal to the
graphics thread when to start drawing each frame.  The original idea
behind this was to prevent mutually cascading stalls of encoding or
graphics rendering (i.e., if rendering took too long, then encoding
would have to catch up, then rendering would have to catch up again, and
so on, cascading upon each other).  The ultimate goal was to prevent
encoding from impacting graphics and vise versa.

However, eventually it was realized that there were some fundamental
flaws with this design.

1. Stray frame duplication.  You could not guarantee that a frame would
   render on time, so sometimes frames would unintentionally be lost if
   there was any sort of minor hiccup or if the thread took too long to
   be scheduled I'm guessing.

2. Frame timing in the rendering thread was less accurate.  The only
   place where frame timing was accurate was in the encoder thread, and
   the graphics thread was at the whim of thread scheduling.  On higher
   end computers it was typically fine, but it was just generally not
   guaranteed that a frame would be rendered when it was supposed to be
   rendered.

So the solution (originally proposed by r1ch and paibox) is to instead
keep the encoding and graphics threads separate as usual, but instead of
the encoder thread controlling the graphics thread, the graphics thread
now controls the encoder thread.  The encoder thread keeps a limited
cache of frames, then the graphics thread copies frames in to the cache
and increments a semaphore to schedule the encoder thread to encode that
data.

In the cache, each frame has an encode counter.  If the frame cache is
full (e.g., the encoder taking too long to return frames), it will not
cache a new frame, but instead will just increment the counter on the
last frame in the cache to schedule that frame to encode again, ensuring
that frames are on time and reducing CPU usage by lowering video
complexity.  If the graphics thread takes too long to render a frame,
then it will add that frame with the count value set to the total amount
of frames that were missed (actual legitimately duplicated frames).

Because the cache gives many frames of breathing room for the encoder to
encode frames, this design helps improve results especially when using
encoding presets that have higher complexity and CPU usage, minimizing
the risk of needlessly skipped or duplicated frames.

I also managed to sneak in what should be a bit of an optimization to
reduce copying of frame data, though how much of an optimization it
ultimately ends up being is debatable.

So to sum it up, this commit increases accuracy of frame timing,
completely removes stray frame duplication, gives better results for
higher complexity encoding presets, and potentially optimizes the frame
pipeline a tiny bit.
2014-12-31 04:03:47 -08:00
jp9000 8e1549820b libobs/media-io: Add frame copying function 2014-12-31 04:03:45 -08:00
jp9000 5d0551eb27 libobs/media-io: Add #pragma once to video-frame.h 2014-12-31 04:03:44 -08:00
jp9000 c52406c178 libobs/media-io: Fix recursive lock in video
In certain cases the video thread could end up trying to lock itself
recursively.  This just allows the mutexes to safely be locked
recursively.
2014-12-21 10:14:19 -08:00
jp9000 59c4731aa6 libobs/media-io: Add colorspace to video info
This is useful for keeping track of what the current colorspace/range is
if a YUV format is being used.
2014-12-11 19:47:51 -08:00
jp9000 a07ebf44e6 media-io: Fix repeating video timestamps
In video-io.c, video frames could skip, but what would happen is the
frame's timestamp would repeat for the next frame, giving the next frame
a non-monotonic timestamp, and then jump.  This could mess up syncing
slightly when the frame is finally given to an outputs.
2014-10-22 20:32:49 -07:00
jp9000 f6d635e586 Change default audio smoothing threshold to 50ms
70 milliseconds is a bit too high for the default audio timestamp
smoothing threshold.  The full range of error thus becomes 140
milliseconds, which is a bit more than necessary to worry about.  For
the time being, I feel it may be worth it to try 50 milliseconds.
2014-10-22 20:32:46 -07:00