2014-04-05 01:13:11 -07:00
|
|
|
/******************************************************************************
|
|
|
|
Copyright (C) 2014 by Hugh Bailey <obs.jim@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <util/base.h>
|
|
|
|
#include <util/circlebuf.h>
|
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
|
|
|
#include <util/darray.h>
|
2019-10-09 09:28:26 -07:00
|
|
|
#include <util/dstr.h>
|
2014-07-09 22:12:57 -07:00
|
|
|
#include <obs-module.h>
|
2014-04-05 01:13:11 -07:00
|
|
|
|
2018-02-26 00:07:52 -08:00
|
|
|
#include <libavutil/opt.h>
|
2014-04-05 01:13:11 -07:00
|
|
|
#include <libavformat/avformat.h>
|
2014-04-05 07:12:32 -07:00
|
|
|
|
2014-04-05 01:13:11 -07:00
|
|
|
#include "obs-ffmpeg-formats.h"
|
2014-04-05 07:12:32 -07:00
|
|
|
#include "obs-ffmpeg-compat.h"
|
2014-04-05 01:13:11 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
#define do_log(level, format, ...) \
|
|
|
|
blog(level, "[FFmpeg %s encoder: '%s'] " format, enc->type, \
|
|
|
|
obs_encoder_get_name(enc->encoder), ##__VA_ARGS__)
|
2015-07-05 23:53:36 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
|
|
|
|
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
|
|
|
|
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
|
2015-07-05 23:53:36 -07:00
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
struct enc_encoder {
|
2019-06-22 22:13:45 -07:00
|
|
|
obs_encoder_t *encoder;
|
2014-04-05 01:13:11 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
const char *type;
|
2017-07-31 14:48:20 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
AVCodec *codec;
|
|
|
|
AVCodecContext *context;
|
2014-04-05 01:13:11 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
uint8_t *samples[MAX_AV_PLANES];
|
|
|
|
AVFrame *aframe;
|
|
|
|
int64_t total_samples;
|
2014-04-05 01:13:11 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
DARRAY(uint8_t) packet_buffer;
|
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
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
size_t audio_planes;
|
|
|
|
size_t audio_size;
|
2014-04-05 01:13:11 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
int frame_size; /* pretty much always 1024 for AAC */
|
|
|
|
int frame_size_bytes;
|
2014-04-05 01:13:11 -07:00
|
|
|
};
|
|
|
|
|
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-05-26 17:15:54 -07:00
|
|
|
static inline uint64_t convert_speaker_layout(enum speaker_layout layout)
|
|
|
|
{
|
|
|
|
switch (layout) {
|
2019-06-22 22:13:45 -07:00
|
|
|
case SPEAKERS_UNKNOWN:
|
|
|
|
return 0;
|
|
|
|
case SPEAKERS_MONO:
|
|
|
|
return AV_CH_LAYOUT_MONO;
|
|
|
|
case SPEAKERS_STEREO:
|
|
|
|
return AV_CH_LAYOUT_STEREO;
|
|
|
|
case SPEAKERS_2POINT1:
|
|
|
|
return AV_CH_LAYOUT_SURROUND;
|
|
|
|
case SPEAKERS_4POINT0:
|
|
|
|
return AV_CH_LAYOUT_4POINT0;
|
|
|
|
case SPEAKERS_4POINT1:
|
|
|
|
return AV_CH_LAYOUT_4POINT1;
|
|
|
|
case SPEAKERS_5POINT1:
|
|
|
|
return AV_CH_LAYOUT_5POINT1_BACK;
|
|
|
|
case SPEAKERS_7POINT1:
|
|
|
|
return AV_CH_LAYOUT_7POINT1;
|
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-05-26 17:15:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* shouldn't get here */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
static inline enum speaker_layout
|
|
|
|
convert_ff_channel_layout(uint64_t channel_layout)
|
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-05-26 17:15:54 -07:00
|
|
|
{
|
|
|
|
switch (channel_layout) {
|
2019-06-22 22:13:45 -07:00
|
|
|
case AV_CH_LAYOUT_MONO:
|
|
|
|
return SPEAKERS_MONO;
|
|
|
|
case AV_CH_LAYOUT_STEREO:
|
|
|
|
return SPEAKERS_STEREO;
|
|
|
|
case AV_CH_LAYOUT_SURROUND:
|
|
|
|
return SPEAKERS_2POINT1;
|
|
|
|
case AV_CH_LAYOUT_4POINT0:
|
|
|
|
return SPEAKERS_4POINT0;
|
|
|
|
case AV_CH_LAYOUT_4POINT1:
|
|
|
|
return SPEAKERS_4POINT1;
|
|
|
|
case AV_CH_LAYOUT_5POINT1_BACK:
|
|
|
|
return SPEAKERS_5POINT1;
|
|
|
|
case AV_CH_LAYOUT_7POINT1:
|
|
|
|
return SPEAKERS_7POINT1;
|
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-05-26 17:15:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* shouldn't get here */
|
2019-06-22 22:13:45 -07:00
|
|
|
return SPEAKERS_UNKNOWN;
|
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-05-26 17:15:54 -07:00
|
|
|
}
|
|
|
|
|
2015-09-16 01:30:51 -07:00
|
|
|
static const char *aac_getname(void *unused)
|
2014-04-05 01:13:11 -07:00
|
|
|
{
|
2015-09-16 01:30:51 -07:00
|
|
|
UNUSED_PARAMETER(unused);
|
2014-07-09 22:12:57 -07:00
|
|
|
return obs_module_text("FFmpegAAC");
|
2014-04-05 01:13:11 -07:00
|
|
|
}
|
|
|
|
|
2017-07-31 15:55:02 -07:00
|
|
|
static const char *opus_getname(void *unused)
|
|
|
|
{
|
|
|
|
UNUSED_PARAMETER(unused);
|
|
|
|
return obs_module_text("FFmpegOpus");
|
|
|
|
}
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
static void enc_destroy(void *data)
|
2014-04-05 01:13:11 -07:00
|
|
|
{
|
2017-07-31 14:48:20 -07:00
|
|
|
struct enc_encoder *enc = data;
|
2014-04-05 01:13:11 -07:00
|
|
|
|
|
|
|
if (enc->samples[0])
|
|
|
|
av_freep(&enc->samples[0]);
|
|
|
|
if (enc->context)
|
|
|
|
avcodec_close(enc->context);
|
|
|
|
if (enc->aframe)
|
|
|
|
av_frame_free(&enc->aframe);
|
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
|
|
|
|
|
|
|
da_free(enc->packet_buffer);
|
2014-04-05 01:13:11 -07:00
|
|
|
bfree(enc);
|
|
|
|
}
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
static bool initialize_codec(struct enc_encoder *enc)
|
2014-04-05 01:13:11 -07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
enc->aframe = av_frame_alloc();
|
2014-04-05 01:13:11 -07:00
|
|
|
if (!enc->aframe) {
|
2015-07-05 23:53:36 -07:00
|
|
|
warn("Failed to allocate audio frame");
|
2014-04-05 01:13:11 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
ret = avcodec_open2(enc->context, enc->codec, NULL);
|
2014-04-05 01:13:11 -07:00
|
|
|
if (ret < 0) {
|
2019-10-09 09:28:26 -07:00
|
|
|
struct dstr error_message = {0};
|
|
|
|
dstr_printf(&error_message, "Failed to open AAC codec: %s",
|
|
|
|
av_err2str(ret));
|
|
|
|
obs_encoder_set_last_error(enc->encoder, error_message.array);
|
|
|
|
dstr_free(&error_message);
|
2015-07-05 23:53:36 -07:00
|
|
|
warn("Failed to open AAC codec: %s", av_err2str(ret));
|
2014-04-05 01:13:11 -07:00
|
|
|
return false;
|
|
|
|
}
|
obs-ffmpeg: fill in more fields on audio frames
After you call av_frame_alloc(), ffmpeg expects you to fill in certain
fields on the frame, depending on whether it's an audio or video frame.
obs-ffmpeg did this in the two places where it allocates video frames,
but not where it allocates audio frames. On my system, using trunk
ffmpeg and the Opus codec, this causes OBS to crash while calling
avcodec_send_frame, ultimately because av_frame_copy fails due to
'dst->format < 0' (as 'format' stays at the default of -1), causing a
null pointer to be added to a buffer queue, which later gets
dereferenced.
Oddly, the fields in question can just be copied directly from
corresponding fields in the AVCodecContext, but I don't see any ffmpeg
API to automatically copy all relevant fields, and all the examples I've
seen do it by hand. So this patch does the same.
2018-04-18 13:13:48 -07:00
|
|
|
enc->aframe->format = enc->context->sample_fmt;
|
|
|
|
enc->aframe->channels = enc->context->channels;
|
|
|
|
enc->aframe->channel_layout = enc->context->channel_layout;
|
|
|
|
enc->aframe->sample_rate = enc->context->sample_rate;
|
2014-04-05 01:13:11 -07:00
|
|
|
|
|
|
|
enc->frame_size = enc->context->frame_size;
|
|
|
|
if (!enc->frame_size)
|
|
|
|
enc->frame_size = 1024;
|
|
|
|
|
|
|
|
enc->frame_size_bytes = enc->frame_size * (int)enc->audio_size;
|
|
|
|
|
|
|
|
ret = av_samples_alloc(enc->samples, NULL, enc->context->channels,
|
2019-06-22 22:13:45 -07:00
|
|
|
enc->frame_size, enc->context->sample_fmt, 0);
|
2014-04-05 01:13:11 -07:00
|
|
|
if (ret < 0) {
|
2015-07-05 23:53:36 -07:00
|
|
|
warn("Failed to create audio buffer: %s", av_err2str(ret));
|
2014-04-05 01:13:11 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
static void init_sizes(struct enc_encoder *enc, audio_t *audio)
|
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
|
|
|
{
|
|
|
|
const struct audio_output_info *aoi;
|
|
|
|
enum audio_format format;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
aoi = audio_output_get_info(audio);
|
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
|
|
|
format = convert_ffmpeg_sample_format(enc->context->sample_fmt);
|
|
|
|
|
|
|
|
enc->audio_planes = get_audio_planes(format, aoi->speakers);
|
2019-06-22 22:13:45 -07:00
|
|
|
enc->audio_size = get_audio_size(format, aoi->speakers, 1);
|
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
|
|
|
}
|
|
|
|
|
2014-11-10 01:10:19 -08:00
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
|
|
|
#endif
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
static void *enc_create(obs_data_t *settings, obs_encoder_t *encoder,
|
2019-06-22 22:13:45 -07:00
|
|
|
const char *type, const char *alt)
|
2014-04-05 01:13:11 -07:00
|
|
|
{
|
2017-07-31 14:48:20 -07:00
|
|
|
struct enc_encoder *enc;
|
2019-06-22 22:13:45 -07:00
|
|
|
int bitrate = (int)obs_data_get_int(settings, "bitrate");
|
|
|
|
audio_t *audio = obs_encoder_audio(encoder);
|
2014-04-05 01:13:11 -07:00
|
|
|
|
2019-07-28 18:31:43 -07:00
|
|
|
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
|
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
|
|
|
avcodec_register_all();
|
2019-07-28 18:31:43 -07:00
|
|
|
#endif
|
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
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
enc = bzalloc(sizeof(struct enc_encoder));
|
2014-04-05 01:13:11 -07:00
|
|
|
enc->encoder = encoder;
|
2019-06-22 22:13:45 -07:00
|
|
|
enc->codec = avcodec_find_encoder_by_name(type);
|
|
|
|
enc->type = type;
|
2015-07-05 23:53:36 -07:00
|
|
|
|
2017-07-31 15:55:02 -07:00
|
|
|
if (!enc->codec && alt) {
|
|
|
|
enc->codec = avcodec_find_encoder_by_name(alt);
|
2019-06-22 22:13:45 -07:00
|
|
|
enc->type = alt;
|
2017-07-31 15:55:02 -07:00
|
|
|
}
|
|
|
|
|
2015-07-05 23:53:36 -07:00
|
|
|
blog(LOG_INFO, "---------------------------------");
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
if (!enc->codec) {
|
2015-07-05 23:53:36 -07:00
|
|
|
warn("Couldn't find encoder");
|
2014-04-05 01:13:11 -07:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2015-07-05 23:53:36 -07:00
|
|
|
if (!bitrate) {
|
|
|
|
warn("Invalid bitrate specified");
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-05-22 04:49:10 -07:00
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
enc->context = avcodec_alloc_context3(enc->codec);
|
2014-04-05 01:13:11 -07:00
|
|
|
if (!enc->context) {
|
2015-07-05 23:53:36 -07:00
|
|
|
warn("Failed to create codec context");
|
2014-04-05 01:13:11 -07:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
enc->context->bit_rate = bitrate * 1000;
|
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-05-26 17:15:54 -07:00
|
|
|
const struct audio_output_info *aoi;
|
|
|
|
aoi = audio_output_get_info(audio);
|
2019-06-22 22:13:45 -07:00
|
|
|
enc->context->channels = (int)audio_output_get_channels(audio);
|
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-05-26 17:15:54 -07:00
|
|
|
enc->context->channel_layout = convert_speaker_layout(aoi->speakers);
|
2014-08-05 15:07:54 -07:00
|
|
|
enc->context->sample_rate = audio_output_get_sample_rate(audio);
|
2019-06-22 22:13:45 -07:00
|
|
|
enc->context->sample_fmt = enc->codec->sample_fmts
|
|
|
|
? enc->codec->sample_fmts[0]
|
|
|
|
: AV_SAMPLE_FMT_FLTP;
|
2014-04-05 01:13:11 -07:00
|
|
|
|
2017-07-31 14:51:21 -07:00
|
|
|
/* check to make sure sample rate is supported */
|
|
|
|
if (enc->codec->supported_samplerates) {
|
|
|
|
const int *rate = enc->codec->supported_samplerates;
|
|
|
|
int cur_rate = enc->context->sample_rate;
|
|
|
|
int closest = 0;
|
|
|
|
|
2017-07-31 15:55:02 -07:00
|
|
|
while (*rate) {
|
2017-07-31 14:51:21 -07:00
|
|
|
int dist = abs(cur_rate - *rate);
|
|
|
|
int closest_dist = abs(cur_rate - closest);
|
|
|
|
|
|
|
|
if (dist < closest_dist)
|
|
|
|
closest = *rate;
|
2017-07-31 15:55:02 -07:00
|
|
|
rate++;
|
2017-07-31 14:51:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (closest)
|
|
|
|
enc->context->sample_rate = closest;
|
|
|
|
}
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
if (strcmp(enc->codec->name, "aac") == 0) {
|
2018-02-26 00:07:52 -08:00
|
|
|
av_opt_set(enc->context->priv_data, "aac_coder", "fast", 0);
|
2014-11-10 01:10:19 -08:00
|
|
|
}
|
|
|
|
|
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-05-26 17:15:54 -07:00
|
|
|
info("bitrate: %" PRId64 ", channels: %d, channel_layout: %x\n",
|
2019-06-22 22:13:45 -07:00
|
|
|
(int64_t)enc->context->bit_rate / 1000,
|
|
|
|
(int)enc->context->channels,
|
|
|
|
(unsigned int)enc->context->channel_layout);
|
2014-07-13 03:10:16 -07:00
|
|
|
|
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
|
|
|
init_sizes(enc, audio);
|
2014-04-05 01:13:11 -07:00
|
|
|
|
|
|
|
/* enable experimental FFmpeg encoder if the only one available */
|
|
|
|
enc->context->strict_std_compliance = -2;
|
|
|
|
|
2017-10-29 15:50:01 -07:00
|
|
|
enc->context->flags = CODEC_FLAG_GLOBAL_H;
|
2014-05-08 05:19:10 -07:00
|
|
|
|
2014-04-05 01:13:11 -07:00
|
|
|
if (initialize_codec(enc))
|
|
|
|
return enc;
|
|
|
|
|
|
|
|
fail:
|
2017-07-31 14:48:20 -07:00
|
|
|
enc_destroy(enc);
|
2014-04-05 01:13:11 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
static void *aac_create(obs_data_t *settings, obs_encoder_t *encoder)
|
|
|
|
{
|
2017-07-31 15:55:02 -07:00
|
|
|
return enc_create(settings, encoder, "aac", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *opus_create(obs_data_t *settings, obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
return enc_create(settings, encoder, "libopus", "opus");
|
2017-07-31 14:48:20 -07:00
|
|
|
}
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
static bool do_encode(struct enc_encoder *enc, struct encoder_packet *packet,
|
|
|
|
bool *received_packet)
|
2014-04-05 01:13:11 -07:00
|
|
|
{
|
|
|
|
AVRational time_base = {1, enc->context->sample_rate};
|
2019-06-22 22:13:45 -07:00
|
|
|
AVPacket avpacket = {0};
|
|
|
|
int got_packet;
|
|
|
|
int ret;
|
2014-04-05 01:13:11 -07:00
|
|
|
|
|
|
|
enc->aframe->nb_samples = enc->frame_size;
|
2019-06-22 22:13:45 -07:00
|
|
|
enc->aframe->pts = av_rescale_q(
|
|
|
|
enc->total_samples, (AVRational){1, enc->context->sample_rate},
|
|
|
|
enc->context->time_base);
|
|
|
|
|
|
|
|
ret = avcodec_fill_audio_frame(
|
|
|
|
enc->aframe, enc->context->channels, enc->context->sample_fmt,
|
|
|
|
enc->samples[0], enc->frame_size_bytes * enc->context->channels,
|
|
|
|
1);
|
2014-04-05 01:13:11 -07:00
|
|
|
if (ret < 0) {
|
2015-07-05 23:53:36 -07:00
|
|
|
warn("avcodec_fill_audio_frame failed: %s", av_err2str(ret));
|
2014-04-05 01:13:11 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
enc->total_samples += enc->frame_size;
|
|
|
|
|
2017-12-05 13:53:18 -08:00
|
|
|
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 40, 101)
|
|
|
|
ret = avcodec_send_frame(enc->context, enc->aframe);
|
|
|
|
if (ret == 0)
|
|
|
|
ret = avcodec_receive_packet(enc->context, &avpacket);
|
|
|
|
|
|
|
|
got_packet = (ret == 0);
|
|
|
|
|
|
|
|
if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN))
|
|
|
|
ret = 0;
|
|
|
|
#else
|
2014-04-05 01:13:11 -07:00
|
|
|
ret = avcodec_encode_audio2(enc->context, &avpacket, enc->aframe,
|
2019-06-22 22:13:45 -07:00
|
|
|
&got_packet);
|
2017-12-05 13:53:18 -08:00
|
|
|
#endif
|
2014-04-05 01:13:11 -07:00
|
|
|
if (ret < 0) {
|
2015-07-05 23:53:36 -07:00
|
|
|
warn("avcodec_encode_audio2 failed: %s", av_err2str(ret));
|
2014-04-05 01:13:11 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*received_packet = !!got_packet;
|
|
|
|
if (!got_packet)
|
|
|
|
return true;
|
|
|
|
|
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
|
|
|
da_resize(enc->packet_buffer, 0);
|
|
|
|
da_push_back_array(enc->packet_buffer, avpacket.data, avpacket.size);
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
packet->pts = rescale_ts(avpacket.pts, enc->context, time_base);
|
|
|
|
packet->dts = rescale_ts(avpacket.dts, enc->context, time_base);
|
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
|
|
|
packet->data = enc->packet_buffer.array;
|
2014-04-05 01:43:59 -07:00
|
|
|
packet->size = avpacket.size;
|
2014-04-05 01:13:11 -07:00
|
|
|
packet->type = OBS_ENCODER_AUDIO;
|
|
|
|
packet->timebase_num = 1;
|
|
|
|
packet->timebase_den = (int32_t)enc->context->sample_rate;
|
|
|
|
av_free_packet(&avpacket);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
static bool enc_encode(void *data, struct encoder_frame *frame,
|
2019-06-22 22:13:45 -07:00
|
|
|
struct encoder_packet *packet, bool *received_packet)
|
2014-04-05 01:13:11 -07:00
|
|
|
{
|
2017-07-31 14:48:20 -07:00
|
|
|
struct enc_encoder *enc = data;
|
2014-04-05 01:13:11 -07:00
|
|
|
|
|
|
|
for (size_t i = 0; i < enc->audio_planes; i++)
|
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
|
|
|
memcpy(enc->samples[i], frame->data[i], enc->frame_size_bytes);
|
2014-04-05 01:13:11 -07:00
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
return do_encode(enc, packet, received_packet);
|
2014-04-05 01:13:11 -07:00
|
|
|
}
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
static void enc_defaults(obs_data_t *settings)
|
2014-04-05 01:13:11 -07:00
|
|
|
{
|
2014-04-05 01:17:32 -07:00
|
|
|
obs_data_set_default_int(settings, "bitrate", 128);
|
2014-04-05 01:13:11 -07:00
|
|
|
}
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
static obs_properties_t *enc_properties(void *unused)
|
2014-04-05 01:13:11 -07:00
|
|
|
{
|
2014-09-29 08:36:13 -07:00
|
|
|
UNUSED_PARAMETER(unused);
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
obs_properties_t *props = obs_properties_create();
|
2019-06-22 22:13:45 -07:00
|
|
|
obs_properties_add_int(props, "bitrate", obs_module_text("Bitrate"), 64,
|
|
|
|
1024, 32);
|
2014-04-05 01:13:11 -07:00
|
|
|
return props;
|
|
|
|
}
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
static bool enc_extra_data(void *data, uint8_t **extra_data, size_t *size)
|
2014-04-05 01:13:11 -07:00
|
|
|
{
|
2017-07-31 14:48:20 -07:00
|
|
|
struct enc_encoder *enc = data;
|
2014-04-05 01:13:11 -07:00
|
|
|
|
|
|
|
*extra_data = enc->context->extradata;
|
2019-06-22 22:13:45 -07:00
|
|
|
*size = enc->context->extradata_size;
|
2014-04-05 01:13:11 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
static void enc_audio_info(void *data, struct audio_convert_info *info)
|
2014-04-05 01:13:11 -07:00
|
|
|
{
|
2017-07-31 14:48:20 -07:00
|
|
|
struct enc_encoder *enc = data;
|
2014-04-05 01:13:11 -07:00
|
|
|
info->format = convert_ffmpeg_sample_format(enc->context->sample_fmt);
|
2017-07-31 14:51:21 -07:00
|
|
|
info->samples_per_sec = (uint32_t)enc->context->sample_rate;
|
2019-06-22 22:13:45 -07:00
|
|
|
info->speakers =
|
|
|
|
convert_ff_channel_layout(enc->context->channel_layout);
|
2014-04-05 01:13:11 -07:00
|
|
|
}
|
|
|
|
|
2017-07-31 14:48:20 -07:00
|
|
|
static size_t enc_frame_size(void *data)
|
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
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
struct enc_encoder *enc = data;
|
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
|
|
|
return enc->frame_size;
|
|
|
|
}
|
|
|
|
|
2014-04-05 01:13:11 -07:00
|
|
|
struct obs_encoder_info aac_encoder_info = {
|
2019-06-22 22:13:45 -07:00
|
|
|
.id = "ffmpeg_aac",
|
|
|
|
.type = OBS_ENCODER_AUDIO,
|
|
|
|
.codec = "AAC",
|
|
|
|
.get_name = aac_getname,
|
|
|
|
.create = aac_create,
|
|
|
|
.destroy = enc_destroy,
|
|
|
|
.encode = enc_encode,
|
2017-07-31 14:48:20 -07:00
|
|
|
.get_frame_size = enc_frame_size,
|
2019-06-22 22:13:45 -07:00
|
|
|
.get_defaults = enc_defaults,
|
2017-07-31 14:48:20 -07:00
|
|
|
.get_properties = enc_properties,
|
|
|
|
.get_extra_data = enc_extra_data,
|
2019-06-22 22:13:45 -07:00
|
|
|
.get_audio_info = enc_audio_info,
|
2014-04-05 01:13:11 -07:00
|
|
|
};
|
2017-07-31 15:55:02 -07:00
|
|
|
|
|
|
|
struct obs_encoder_info opus_encoder_info = {
|
2019-06-22 22:13:45 -07:00
|
|
|
.id = "ffmpeg_opus",
|
|
|
|
.type = OBS_ENCODER_AUDIO,
|
|
|
|
.codec = "opus",
|
|
|
|
.get_name = opus_getname,
|
|
|
|
.create = opus_create,
|
|
|
|
.destroy = enc_destroy,
|
|
|
|
.encode = enc_encode,
|
2017-07-31 15:55:02 -07:00
|
|
|
.get_frame_size = enc_frame_size,
|
2019-06-22 22:13:45 -07:00
|
|
|
.get_defaults = enc_defaults,
|
2017-07-31 15:55:02 -07:00
|
|
|
.get_properties = enc_properties,
|
|
|
|
.get_extra_data = enc_extra_data,
|
2019-06-22 22:13:45 -07:00
|
|
|
.get_audio_info = enc_audio_info,
|
2017-07-31 15:55:02 -07:00
|
|
|
};
|