mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-18 09:09:14 +00:00
obs-outputs: Replace circlebuf with deque
This commit is contained in:
parent
8ec91bab04
commit
9f306fa832
|
@ -18,7 +18,7 @@
|
|||
#include <obs-module.h>
|
||||
#include <obs-avc.h>
|
||||
#include <util/platform.h>
|
||||
#include <util/circlebuf.h>
|
||||
#include <util/deque.h>
|
||||
#include <util/dstr.h>
|
||||
#include <util/threading.h>
|
||||
#include <inttypes.h>
|
||||
|
@ -64,7 +64,7 @@ struct ftl_stream {
|
|||
obs_output_t *output;
|
||||
|
||||
pthread_mutex_t packets_mutex;
|
||||
struct circlebuf packets;
|
||||
struct deque packets;
|
||||
bool sent_headers;
|
||||
int64_t frames_sent;
|
||||
|
||||
|
@ -134,7 +134,7 @@ static inline void free_packets(struct ftl_stream *stream)
|
|||
|
||||
while (stream->packets.size) {
|
||||
struct encoder_packet packet;
|
||||
circlebuf_pop_front(&stream->packets, &packet, sizeof(packet));
|
||||
deque_pop_front(&stream->packets, &packet, sizeof(packet));
|
||||
obs_encoder_packet_release(&packet);
|
||||
}
|
||||
pthread_mutex_unlock(&stream->packets_mutex);
|
||||
|
@ -205,7 +205,7 @@ static void ftl_stream_destroy(void *data)
|
|||
os_event_destroy(stream->stop_event);
|
||||
os_sem_destroy(stream->send_sem);
|
||||
pthread_mutex_destroy(&stream->packets_mutex);
|
||||
circlebuf_free(&stream->packets);
|
||||
deque_free(&stream->packets);
|
||||
bfree(stream);
|
||||
}
|
||||
}
|
||||
|
@ -276,8 +276,8 @@ static inline bool get_next_packet(struct ftl_stream *stream,
|
|||
|
||||
pthread_mutex_lock(&stream->packets_mutex);
|
||||
if (stream->packets.size) {
|
||||
circlebuf_pop_front(&stream->packets, packet,
|
||||
sizeof(struct encoder_packet));
|
||||
deque_pop_front(&stream->packets, packet,
|
||||
sizeof(struct encoder_packet));
|
||||
new_packet = true;
|
||||
}
|
||||
pthread_mutex_unlock(&stream->packets_mutex);
|
||||
|
@ -658,8 +658,8 @@ static bool ftl_stream_start(void *data)
|
|||
static inline bool add_packet(struct ftl_stream *stream,
|
||||
struct encoder_packet *packet)
|
||||
{
|
||||
circlebuf_push_back(&stream->packets, packet,
|
||||
sizeof(struct encoder_packet));
|
||||
deque_push_back(&stream->packets, packet,
|
||||
sizeof(struct encoder_packet));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -673,7 +673,7 @@ static void drop_frames(struct ftl_stream *stream, const char *name,
|
|||
{
|
||||
UNUSED_PARAMETER(pframes);
|
||||
|
||||
struct circlebuf new_buf = {0};
|
||||
struct deque new_buf = {0};
|
||||
int num_frames_dropped = 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
@ -682,16 +682,16 @@ static void drop_frames(struct ftl_stream *stream, const char *name,
|
|||
UNUSED_PARAMETER(name);
|
||||
#endif
|
||||
|
||||
circlebuf_reserve(&new_buf, sizeof(struct encoder_packet) * 8);
|
||||
deque_reserve(&new_buf, sizeof(struct encoder_packet) * 8);
|
||||
|
||||
while (stream->packets.size) {
|
||||
struct encoder_packet packet;
|
||||
circlebuf_pop_front(&stream->packets, &packet, sizeof(packet));
|
||||
deque_pop_front(&stream->packets, &packet, sizeof(packet));
|
||||
|
||||
/* do not drop audio data or video keyframes */
|
||||
if (packet.type == OBS_ENCODER_AUDIO ||
|
||||
packet.drop_priority >= highest_priority) {
|
||||
circlebuf_push_back(&new_buf, &packet, sizeof(packet));
|
||||
deque_push_back(&new_buf, &packet, sizeof(packet));
|
||||
|
||||
} else {
|
||||
num_frames_dropped++;
|
||||
|
@ -699,7 +699,7 @@ static void drop_frames(struct ftl_stream *stream, const char *name,
|
|||
}
|
||||
}
|
||||
|
||||
circlebuf_free(&stream->packets);
|
||||
deque_free(&stream->packets);
|
||||
stream->packets = new_buf;
|
||||
|
||||
if (stream->min_priority < highest_priority)
|
||||
|
@ -721,7 +721,7 @@ static bool find_first_video_packet(struct ftl_stream *stream,
|
|||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
struct encoder_packet *cur =
|
||||
circlebuf_data(&stream->packets, i * sizeof(*first));
|
||||
deque_data(&stream->packets, i * sizeof(*first));
|
||||
if (cur->type == OBS_ENCODER_VIDEO && !cur->keyframe) {
|
||||
*first = *cur;
|
||||
return true;
|
||||
|
|
|
@ -72,7 +72,7 @@ static inline void free_packets(struct rtmp_stream *stream)
|
|||
|
||||
while (stream->packets.size) {
|
||||
struct encoder_packet packet;
|
||||
circlebuf_pop_front(&stream->packets, &packet, sizeof(packet));
|
||||
deque_pop_front(&stream->packets, &packet, sizeof(packet));
|
||||
obs_encoder_packet_release(&packet);
|
||||
}
|
||||
pthread_mutex_unlock(&stream->packets_mutex);
|
||||
|
@ -130,11 +130,11 @@ static void rtmp_stream_destroy(void *data)
|
|||
os_event_destroy(stream->stop_event);
|
||||
os_sem_destroy(stream->send_sem);
|
||||
pthread_mutex_destroy(&stream->packets_mutex);
|
||||
circlebuf_free(&stream->packets);
|
||||
deque_free(&stream->packets);
|
||||
#ifdef TEST_FRAMEDROPS
|
||||
circlebuf_free(&stream->droptest_info);
|
||||
deque_free(&stream->droptest_info);
|
||||
#endif
|
||||
circlebuf_free(&stream->dbr_frames);
|
||||
deque_free(&stream->dbr_frames);
|
||||
pthread_mutex_destroy(&stream->dbr_mutex);
|
||||
|
||||
os_event_destroy(stream->buffer_space_available_event);
|
||||
|
@ -241,8 +241,8 @@ static inline bool get_next_packet(struct rtmp_stream *stream,
|
|||
|
||||
pthread_mutex_lock(&stream->packets_mutex);
|
||||
if (stream->packets.size) {
|
||||
circlebuf_pop_front(&stream->packets, packet,
|
||||
sizeof(struct encoder_packet));
|
||||
deque_pop_front(&stream->packets, packet,
|
||||
sizeof(struct encoder_packet));
|
||||
new_packet = true;
|
||||
}
|
||||
pthread_mutex_unlock(&stream->packets_mutex);
|
||||
|
@ -326,12 +326,11 @@ static void droptest_cap_data_rate(struct rtmp_stream *stream, size_t size)
|
|||
info.ts = ts;
|
||||
info.size = size;
|
||||
|
||||
circlebuf_push_back(&stream->droptest_info, &info, sizeof(info));
|
||||
deque_push_back(&stream->droptest_info, &info, sizeof(info));
|
||||
stream->droptest_size += size;
|
||||
|
||||
if (stream->droptest_info.size) {
|
||||
circlebuf_peek_front(&stream->droptest_info, &info,
|
||||
sizeof(info));
|
||||
deque_peek_front(&stream->droptest_info, &info, sizeof(info));
|
||||
|
||||
if (stream->droptest_size > stream->droptest_max) {
|
||||
uint64_t elapsed = ts - info.ts;
|
||||
|
@ -342,8 +341,8 @@ static void droptest_cap_data_rate(struct rtmp_stream *stream, size_t size)
|
|||
}
|
||||
|
||||
while (stream->droptest_size > stream->droptest_max) {
|
||||
circlebuf_pop_front(&stream->droptest_info,
|
||||
&info, sizeof(info));
|
||||
deque_pop_front(&stream->droptest_info, &info,
|
||||
sizeof(info));
|
||||
stream->droptest_size -= info.size;
|
||||
}
|
||||
}
|
||||
|
@ -585,8 +584,8 @@ static void dbr_add_frame(struct rtmp_stream *stream, struct dbr_frame *back)
|
|||
struct dbr_frame front;
|
||||
uint64_t dur;
|
||||
|
||||
circlebuf_push_back(&stream->dbr_frames, back, sizeof(*back));
|
||||
circlebuf_peek_front(&stream->dbr_frames, &front, sizeof(front));
|
||||
deque_push_back(&stream->dbr_frames, back, sizeof(*back));
|
||||
deque_peek_front(&stream->dbr_frames, &front, sizeof(front));
|
||||
|
||||
stream->dbr_data_size += back->size;
|
||||
|
||||
|
@ -594,7 +593,7 @@ static void dbr_add_frame(struct rtmp_stream *stream, struct dbr_frame *back)
|
|||
|
||||
if (dur >= MAX_ESTIMATE_DURATION_MS) {
|
||||
stream->dbr_data_size -= front.size;
|
||||
circlebuf_pop_front(&stream->dbr_frames, NULL, sizeof(front));
|
||||
deque_pop_front(&stream->dbr_frames, NULL, sizeof(front));
|
||||
}
|
||||
|
||||
stream->dbr_est_bitrate =
|
||||
|
@ -1287,7 +1286,7 @@ static bool init_connect(struct rtmp_stream *stream)
|
|||
const char *codec = obs_encoder_get_codec(venc);
|
||||
stream->video_codec = to_video_type(codec);
|
||||
|
||||
circlebuf_free(&stream->dbr_frames);
|
||||
deque_free(&stream->dbr_frames);
|
||||
stream->audio_bitrate = (long)obs_data_get_int(asettings, "bitrate");
|
||||
stream->dbr_data_size = 0;
|
||||
stream->dbr_orig_bitrate = (long)obs_data_get_int(vsettings, "bitrate");
|
||||
|
@ -1415,8 +1414,8 @@ static bool rtmp_stream_start(void *data)
|
|||
static inline bool add_packet(struct rtmp_stream *stream,
|
||||
struct encoder_packet *packet)
|
||||
{
|
||||
circlebuf_push_back(&stream->packets, packet,
|
||||
sizeof(struct encoder_packet));
|
||||
deque_push_back(&stream->packets, packet,
|
||||
sizeof(struct encoder_packet));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1430,7 +1429,7 @@ static void drop_frames(struct rtmp_stream *stream, const char *name,
|
|||
{
|
||||
UNUSED_PARAMETER(pframes);
|
||||
|
||||
struct circlebuf new_buf = {0};
|
||||
struct deque new_buf = {0};
|
||||
int num_frames_dropped = 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
@ -1439,16 +1438,16 @@ static void drop_frames(struct rtmp_stream *stream, const char *name,
|
|||
UNUSED_PARAMETER(name);
|
||||
#endif
|
||||
|
||||
circlebuf_reserve(&new_buf, sizeof(struct encoder_packet) * 8);
|
||||
deque_reserve(&new_buf, sizeof(struct encoder_packet) * 8);
|
||||
|
||||
while (stream->packets.size) {
|
||||
struct encoder_packet packet;
|
||||
circlebuf_pop_front(&stream->packets, &packet, sizeof(packet));
|
||||
deque_pop_front(&stream->packets, &packet, sizeof(packet));
|
||||
|
||||
/* do not drop audio data or video keyframes */
|
||||
if (packet.type == OBS_ENCODER_AUDIO ||
|
||||
packet.drop_priority >= highest_priority) {
|
||||
circlebuf_push_back(&new_buf, &packet, sizeof(packet));
|
||||
deque_push_back(&new_buf, &packet, sizeof(packet));
|
||||
|
||||
} else {
|
||||
num_frames_dropped++;
|
||||
|
@ -1456,7 +1455,7 @@ static void drop_frames(struct rtmp_stream *stream, const char *name,
|
|||
}
|
||||
}
|
||||
|
||||
circlebuf_free(&stream->packets);
|
||||
deque_free(&stream->packets);
|
||||
stream->packets = new_buf;
|
||||
|
||||
if (stream->min_priority < highest_priority)
|
||||
|
@ -1478,7 +1477,7 @@ static bool find_first_video_packet(struct rtmp_stream *stream,
|
|||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
struct encoder_packet *cur =
|
||||
circlebuf_data(&stream->packets, i * sizeof(*first));
|
||||
deque_data(&stream->packets, i * sizeof(*first));
|
||||
if (cur->type == OBS_ENCODER_VIDEO && !cur->keyframe) {
|
||||
*first = *cur;
|
||||
return true;
|
||||
|
@ -1497,8 +1496,8 @@ static bool dbr_bitrate_lowered(struct rtmp_stream *stream)
|
|||
if (stream->dbr_est_bitrate &&
|
||||
stream->dbr_est_bitrate < stream->dbr_cur_bitrate) {
|
||||
stream->dbr_data_size = 0;
|
||||
circlebuf_pop_front(&stream->dbr_frames, NULL,
|
||||
stream->dbr_frames.size);
|
||||
deque_pop_front(&stream->dbr_frames, NULL,
|
||||
stream->dbr_frames.size);
|
||||
est_bitrate = stream->dbr_est_bitrate / 100 * 100;
|
||||
if (est_bitrate < 50) {
|
||||
est_bitrate = 50;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <obs-module.h>
|
||||
#include <util/platform.h>
|
||||
#include <util/circlebuf.h>
|
||||
#include <util/deque.h>
|
||||
#include <util/dstr.h>
|
||||
#include <util/threading.h>
|
||||
#include <inttypes.h>
|
||||
|
@ -57,7 +57,7 @@ struct rtmp_stream {
|
|||
obs_output_t *output;
|
||||
|
||||
pthread_mutex_t packets_mutex;
|
||||
struct circlebuf packets;
|
||||
struct deque packets;
|
||||
bool sent_headers;
|
||||
|
||||
bool got_first_video;
|
||||
|
@ -96,14 +96,14 @@ struct rtmp_stream {
|
|||
int dropped_frames;
|
||||
|
||||
#ifdef TEST_FRAMEDROPS
|
||||
struct circlebuf droptest_info;
|
||||
struct deque droptest_info;
|
||||
uint64_t droptest_last_key_check;
|
||||
size_t droptest_max;
|
||||
size_t droptest_size;
|
||||
#endif
|
||||
|
||||
pthread_mutex_t dbr_mutex;
|
||||
struct circlebuf dbr_frames;
|
||||
struct deque dbr_frames;
|
||||
size_t dbr_data_size;
|
||||
uint64_t dbr_inc_timeout;
|
||||
long audio_bitrate;
|
||||
|
|
Loading…
Reference in a new issue