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.
This commit is contained in:
jp9000
2019-08-15 08:41:21 -07:00
parent 15ade1e2c4
commit 91ce2349db
2 changed files with 48 additions and 2 deletions

View File

@@ -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;

View File

@@ -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