Throttle IDR frames: max once every 100 frames
This commit is contained in:
@@ -20,9 +20,11 @@
|
|||||||
// Include first because of incompatibility between Eigen and X includes
|
// Include first because of incompatibility between Eigen and X includes
|
||||||
#include "driver/wivrn_session.h"
|
#include "driver/wivrn_session.h"
|
||||||
|
|
||||||
#include "os/os_time.h"
|
|
||||||
#include "video_encoder.h"
|
#include "video_encoder.h"
|
||||||
|
|
||||||
|
#include "os/os_time.h"
|
||||||
|
#include "util/u_logging.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "wivrn_config.h"
|
#include "wivrn_config.h"
|
||||||
@@ -91,6 +93,11 @@ std::unique_ptr<VideoEncoder> VideoEncoder::Create(
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const uint64_t idr_throttle = 100;
|
||||||
|
|
||||||
|
VideoEncoder::VideoEncoder() :
|
||||||
|
last_idr_frame(-idr_throttle) {}
|
||||||
|
|
||||||
void VideoEncoder::SyncNeeded()
|
void VideoEncoder::SyncNeeded()
|
||||||
{
|
{
|
||||||
sync_needed = true;
|
sync_needed = true;
|
||||||
@@ -103,6 +110,15 @@ void VideoEncoder::Encode(wivrn_session & cnx,
|
|||||||
this->cnx = &cnx;
|
this->cnx = &cnx;
|
||||||
auto target_timestamp = std::chrono::steady_clock::time_point(std::chrono::nanoseconds(view_info.display_time));
|
auto target_timestamp = std::chrono::steady_clock::time_point(std::chrono::nanoseconds(view_info.display_time));
|
||||||
bool idr = sync_needed.exchange(false);
|
bool idr = sync_needed.exchange(false);
|
||||||
|
// Throttle idr to prevent overloading the decoder
|
||||||
|
if (idr and frame_index < last_idr_frame + idr_throttle)
|
||||||
|
{
|
||||||
|
U_LOG_D("Throttle IDR: stream %d frame %ld", stream_idx, frame_index);
|
||||||
|
sync_needed = true;
|
||||||
|
idr = false;
|
||||||
|
}
|
||||||
|
if (idr)
|
||||||
|
last_idr_frame = frame_index;
|
||||||
const char * extra = idr ? ",idr" : ",p";
|
const char * extra = idr ? ",idr" : ",p";
|
||||||
clock = cnx.get_offset();
|
clock = cnx.get_offset();
|
||||||
timing_info.encode_begin = clock.to_headset(os_monotonic_get_ns());
|
timing_info.encode_begin = clock.to_headset(os_monotonic_get_ns());
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ private:
|
|||||||
clock_offset clock;
|
clock_offset clock;
|
||||||
|
|
||||||
std::atomic_bool sync_needed = true;
|
std::atomic_bool sync_needed = true;
|
||||||
|
uint64_t last_idr_frame;
|
||||||
|
|
||||||
std::ofstream video_dump;
|
std::ofstream video_dump;
|
||||||
|
|
||||||
@@ -72,6 +73,7 @@ public:
|
|||||||
int input_height,
|
int input_height,
|
||||||
float fps);
|
float fps);
|
||||||
|
|
||||||
|
VideoEncoder();
|
||||||
virtual ~VideoEncoder() = default;
|
virtual ~VideoEncoder() = default;
|
||||||
|
|
||||||
// called on present to submit command buffers for the image.
|
// called on present to submit command buffers for the image.
|
||||||
|
|||||||
Reference in New Issue
Block a user