提交 91418e90 编写于 作者: P pkv 提交者: jp9000

obs-ffmpeg: Use obs-ffmpeg-mux for mpegts network output

This replaces the ffmpeg-encoded-output which had serious issues
(missing headers, muxing issues with non compliant mpegts streams) with
an output grafted from obs-ffmpeg-mux.
上级 c1657989
......@@ -21,8 +21,7 @@ set(obs-ffmpeg_config_HEADERS
set(obs-ffmpeg_HEADERS
obs-ffmpeg-formats.h
obs-ffmpeg-compat.h
ffmpeg-encoded-output.h)
obs-ffmpeg-compat.h)
set(obs-ffmpeg_SOURCES
obs-ffmpeg.c
......@@ -30,7 +29,6 @@ set(obs-ffmpeg_SOURCES
obs-ffmpeg-nvenc.c
obs-ffmpeg-output.c
obs-ffmpeg-mux.c
ffmpeg-encoded-output.c
obs-ffmpeg-source.c)
if(UNIX AND NOT APPLE)
......
此差异已折叠。
/******************************************************************************
Copyright (C) 2019 Haivision Systems Inc.
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 <obs-module.h>
#include <obs-avc.h>
#include <util/platform.h>
#include <util/circlebuf.h>
#include <util/dstr.h>
#include <util/threading.h>
#include <inttypes.h>
#include "obs-ffmpeg-output.h"
#include "obs-ffmpeg-formats.h"
#define do_log(level, format, ...) \
blog(level, "[ffmpeg-encoded-output: '%s'] " format, \
obs_output_get_name(stream->output), ##__VA_ARGS__)
#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__)
#define OPT_DROP_THRESHOLD "drop_threshold_ms"
#define OPT_PFRAME_DROP_THRESHOLD "pframe_drop_threshold_ms"
#define OPT_MAX_SHUTDOWN_TIME_SEC "max_shutdown_time_sec"
#define OPT_LOWLATENCY_ENABLED "low_latency_mode_enabled"
//#define TEST_FRAMEDROPS
#ifdef TEST_FRAMEDROPS
#define DROPTEST_MAX_KBPS 3000
#define DROPTEST_MAX_BYTES (DROPTEST_MAX_KBPS * 1000 / 8)
struct droptest_info {
uint64_t ts;
size_t size;
};
#endif
struct ffmpeg_encoded_output {
obs_output_t *output;
pthread_mutex_t packets_mutex;
struct circlebuf packets;
bool sent_sps_pps;
bool got_first_video;
int64_t start_dts_offset;
volatile bool connecting;
pthread_t connect_thread;
volatile bool active;
volatile bool disconnected;
pthread_t send_thread;
int max_shutdown_time_sec;
os_sem_t *send_sem;
os_event_t *stop_event;
uint64_t stop_ts;
uint64_t shutdown_timeout_ts;
struct dstr path, key;
struct dstr username, password;
struct dstr encoder_name;
/* frame drop variables */
int64_t drop_threshold_usec;
int64_t pframe_drop_threshold_usec;
int min_priority;
float congestion;
int64_t last_dts_usec;
uint64_t total_bytes_sent;
int dropped_frames;
#ifdef TEST_FRAMEDROPS
struct circlebuf droptest_info;
size_t droptest_size;
#endif
uint8_t *write_buf;
size_t write_buf_len;
size_t write_buf_size;
pthread_mutex_t write_buf_mutex;
os_event_t *buffer_space_available_event;
os_event_t *buffer_has_data_event;
os_event_t *send_thread_signaled_exit;
struct ffmpeg_data ff_data;
};
......@@ -64,6 +64,8 @@ struct ffmpeg_muxer {
pthread_t mux_thread;
bool mux_thread_joinable;
volatile bool muxing;
bool is_network;
};
static const char *ffmpeg_mux_getname(void *type)
......@@ -72,6 +74,12 @@ static const char *ffmpeg_mux_getname(void *type)
return obs_module_text("FFmpegMuxer");
}
static const char *ffmpeg_mpegts_mux_getname(void *type)
{
UNUSED_PARAMETER(type);
return obs_module_text("FFmpegMpegtsMuxer");
}
static inline void replay_buffer_clear(struct ffmpeg_muxer *stream)
{
while (stream->packets.size > 0) {
......@@ -108,6 +116,9 @@ static void *ffmpeg_mux_create(obs_data_t *settings, obs_output_t *output)
struct ffmpeg_muxer *stream = bzalloc(sizeof(*stream));
stream->output = output;
if (obs_output_get_flags(output) & OBS_OUTPUT_SERVICE)
stream->is_network = true;
UNUSED_PARAMETER(settings);
return stream;
}
......@@ -297,19 +308,32 @@ static bool ffmpeg_mux_start(void *data)
return false;
settings = obs_output_get_settings(stream->output);
path = obs_data_get_string(settings, "path");
if (stream->is_network) {
obs_service_t *service;
service = obs_output_get_service(stream->output);
if (!service)
return false;
path = obs_service_get_url(service);
} else {
path = obs_data_get_string(settings, "path");
}
if (!stream->is_network) {
/* ensure output path is writable to avoid generic error
* message.
*
* TODO: remove once ffmpeg-mux is refactored to pass
* errors back */
FILE *test_file = os_fopen(path, "wb");
if (!test_file) {
set_file_not_readable_error(stream, settings, path);
return false;
}
/* ensure output path is writable to avoid generic error message */
/* TODO: remove once ffmpeg-mux is refactored to pass errors back */
FILE *test_file = os_fopen(path, "wb");
if (!test_file) {
set_file_not_readable_error(stream, settings, path);
return false;
fclose(test_file);
os_unlink(path);
}
fclose(test_file);
os_unlink(path);
start_pipe(stream, path);
obs_data_release(settings);
......@@ -532,6 +556,37 @@ struct obs_output_info ffmpeg_muxer = {
.get_properties = ffmpeg_mux_properties,
};
static int connect_time(struct ffmpeg_mux *stream)
{
UNUSED_PARAMETER(stream);
/* TODO */
return 0;
}
static int ffmpeg_mpegts_mux_connect_time(void *data)
{
struct ffmpeg_mux *stream = data;
/* TODO */
return connect_time(stream);
}
struct obs_output_info ffmpeg_mpegts_muxer = {
.id = "ffmpeg_mpegts_muxer",
.flags = OBS_OUTPUT_AV | OBS_OUTPUT_ENCODED | OBS_OUTPUT_MULTI_TRACK |
OBS_OUTPUT_SERVICE,
.encoded_video_codecs = "h264",
.encoded_audio_codecs = "aac",
.get_name = ffmpeg_mpegts_mux_getname,
.create = ffmpeg_mux_create,
.destroy = ffmpeg_mux_destroy,
.start = ffmpeg_mux_start,
.stop = ffmpeg_mux_stop,
.encoded_packet = ffmpeg_mux_data,
.get_total_bytes = ffmpeg_mux_total_bytes,
.get_properties = ffmpeg_mux_properties,
.get_connect_time_ms = ffmpeg_mpegts_mux_connect_time,
};
/* ------------------------------------------------------------------------ */
static const char *replay_buffer_getname(void *type)
......
......@@ -22,11 +22,11 @@ MODULE_EXPORT const char *obs_module_description(void)
extern struct obs_source_info ffmpeg_source;
extern struct obs_output_info ffmpeg_output;
extern struct obs_output_info ffmpeg_muxer;
extern struct obs_output_info ffmpeg_mpegts_muxer;
extern struct obs_output_info replay_buffer;
extern struct obs_encoder_info aac_encoder_info;
extern struct obs_encoder_info opus_encoder_info;
extern struct obs_encoder_info nvenc_encoder_info;
extern struct obs_output_info ffmpeg_encoded_output_info;
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(55, 27, 100)
#define LIBAVUTIL_VAAPI_AVAILABLE
......@@ -230,10 +230,10 @@ bool obs_module_load(void)
obs_register_source(&ffmpeg_source);
obs_register_output(&ffmpeg_output);
obs_register_output(&ffmpeg_muxer);
obs_register_output(&ffmpeg_mpegts_muxer);
obs_register_output(&replay_buffer);
obs_register_encoder(&aac_encoder_info);
obs_register_encoder(&opus_encoder_info);
obs_register_output(&ffmpeg_encoded_output_info);
#ifndef __APPLE__
if (nvenc_supported()) {
blog(LOG_INFO, "NVENC supported");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册