From 91ce2349dba66d1bd74afc8112638fc33295fb98 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 15 Aug 2019 08:41:21 -0700 Subject: [PATCH] obs-outputs: Allow changing bitrate test limit on the fly When doing the bitrate limit test, it can be useful to have the ability to change the current maximum bitrate limit. This adds the ability to press keys on windows (numpad 0-6) to change between bitrates. Numpad 0 being no limit, 1 being 1000, 2 being 2000, etc. --- plugins/obs-outputs/rtmp-stream.c | 47 +++++++++++++++++++++++++++++-- plugins/obs-outputs/rtmp-stream.h | 3 ++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/plugins/obs-outputs/rtmp-stream.c b/plugins/obs-outputs/rtmp-stream.c index 03136c44e..b3d3a4b3f 100644 --- a/plugins/obs-outputs/rtmp-stream.c +++ b/plugins/obs-outputs/rtmp-stream.c @@ -267,6 +267,49 @@ static void droptest_cap_data_rate(struct rtmp_stream *stream, size_t size) uint64_t ts = os_gettime_ns(); struct droptest_info info; +#if defined(_WIN32) && defined(TEST_FRAMEDROPS_WITH_BITRATE_SHORTCUTS) + uint64_t check_elapsed = ts - stream->droptest_last_key_check; + + if (check_elapsed > (200ULL * MSEC_TO_NSEC)) { + size_t bitrate = 0; + + stream->droptest_last_key_check = ts; + + if (GetAsyncKeyState(VK_NUMPAD0) & 0x8000) { + stream->droptest_max = 0; + } else if (GetAsyncKeyState(VK_NUMPAD1) & 0x8000) { + bitrate = 1000; + } else if (GetAsyncKeyState(VK_NUMPAD2) & 0x8000) { + bitrate = 2000; + } else if (GetAsyncKeyState(VK_NUMPAD3) & 0x8000) { + bitrate = 3000; + } else if (GetAsyncKeyState(VK_NUMPAD4) & 0x8000) { + bitrate = 4000; + } else if (GetAsyncKeyState(VK_NUMPAD5) & 0x8000) { + bitrate = 5000; + } else if (GetAsyncKeyState(VK_NUMPAD6) & 0x8000) { + bitrate = 6000; + } else if (GetAsyncKeyState(VK_NUMPAD7) & 0x8000) { + bitrate = 7000; + } else if (GetAsyncKeyState(VK_NUMPAD8) & 0x8000) { + bitrate = 8000; + } else if (GetAsyncKeyState(VK_NUMPAD9) & 0x8000) { + bitrate = 9000; + } + + if (bitrate) { + stream->droptest_max = (bitrate * 1000 / 8); + } + } + if (!stream->droptest_max) { + return; + } +#else + if (!stream->droptest_max) { + stream->droptest_max = DROPTEST_MAX_BYTES; + } +#endif + info.ts = ts; info.size = size; @@ -277,7 +320,7 @@ static void droptest_cap_data_rate(struct rtmp_stream *stream, size_t size) circlebuf_peek_front(&stream->droptest_info, &info, sizeof(info)); - if (stream->droptest_size > DROPTEST_MAX_BYTES) { + if (stream->droptest_size > stream->droptest_max) { uint64_t elapsed = ts - info.ts; if (elapsed < 1000000000ULL) { @@ -285,7 +328,7 @@ static void droptest_cap_data_rate(struct rtmp_stream *stream, size_t size) os_sleepto_ns(ts + elapsed); } - while (stream->droptest_size > DROPTEST_MAX_BYTES) { + while (stream->droptest_size > stream->droptest_max) { circlebuf_pop_front(&stream->droptest_info, &info, sizeof(info)); stream->droptest_size -= info.size; diff --git a/plugins/obs-outputs/rtmp-stream.h b/plugins/obs-outputs/rtmp-stream.h index b872ce077..4c1bd7870 100644 --- a/plugins/obs-outputs/rtmp-stream.h +++ b/plugins/obs-outputs/rtmp-stream.h @@ -32,6 +32,7 @@ #define OPT_LOWLATENCY_ENABLED "low_latency_mode_enabled" //#define TEST_FRAMEDROPS +//#define TEST_FRAMEDROPS_WITH_BITRATE_SHORTCUTS #ifdef TEST_FRAMEDROPS @@ -87,6 +88,8 @@ struct rtmp_stream { #ifdef TEST_FRAMEDROPS struct circlebuf droptest_info; + uint64_t droptest_last_key_check; + size_t droptest_max; size_t droptest_size; #endif