mirror of
https://repo.dec05eba.com/gpu-screen-recorder
synced 2026-05-07 15:19:55 +09:00
fm content: make sure to capture frame on damage and then no damage after fps frame timeout
This commit is contained in:
@@ -21,7 +21,8 @@ struct gsr_capture {
|
|||||||
/* These methods should not be called manually. Call gsr_capture_* instead */
|
/* These methods should not be called manually. Call gsr_capture_* instead */
|
||||||
int (*start)(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame *frame);
|
int (*start)(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame *frame);
|
||||||
void (*tick)(gsr_capture *cap, AVCodecContext *video_codec_context); /* can be NULL */
|
void (*tick)(gsr_capture *cap, AVCodecContext *video_codec_context); /* can be NULL */
|
||||||
bool (*consume_damage)(gsr_capture *cap); /* can be NULL */
|
bool (*is_damaged)(gsr_capture *cap); /* can be NULL */
|
||||||
|
void (*clear_damage)(gsr_capture *cap); /* can be NULL */
|
||||||
bool (*should_stop)(gsr_capture *cap, bool *err); /* can be NULL */
|
bool (*should_stop)(gsr_capture *cap, bool *err); /* can be NULL */
|
||||||
int (*capture)(gsr_capture *cap, AVFrame *frame);
|
int (*capture)(gsr_capture *cap, AVFrame *frame);
|
||||||
void (*capture_end)(gsr_capture *cap, AVFrame *frame); /* can be NULL */
|
void (*capture_end)(gsr_capture *cap, AVFrame *frame); /* can be NULL */
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ void gsr_capture_xcomposite_init(gsr_capture_xcomposite *self, const gsr_capture
|
|||||||
int gsr_capture_xcomposite_start(gsr_capture_xcomposite *self, AVCodecContext *video_codec_context, AVFrame *frame);
|
int gsr_capture_xcomposite_start(gsr_capture_xcomposite *self, AVCodecContext *video_codec_context, AVFrame *frame);
|
||||||
void gsr_capture_xcomposite_stop(gsr_capture_xcomposite *self);
|
void gsr_capture_xcomposite_stop(gsr_capture_xcomposite *self);
|
||||||
void gsr_capture_xcomposite_tick(gsr_capture_xcomposite *self, AVCodecContext *video_codec_context);
|
void gsr_capture_xcomposite_tick(gsr_capture_xcomposite *self, AVCodecContext *video_codec_context);
|
||||||
bool gsr_capture_xcomposite_consume_damage(gsr_capture_xcomposite *self);
|
bool gsr_capture_xcomposite_is_damaged(gsr_capture_xcomposite *self);
|
||||||
|
void gsr_capture_xcomposite_clear_damage(gsr_capture_xcomposite *self);
|
||||||
bool gsr_capture_xcomposite_should_stop(gsr_capture_xcomposite *self, bool *err);
|
bool gsr_capture_xcomposite_should_stop(gsr_capture_xcomposite *self, bool *err);
|
||||||
int gsr_capture_xcomposite_capture(gsr_capture_xcomposite *self, AVFrame *frame);
|
int gsr_capture_xcomposite_capture(gsr_capture_xcomposite *self, AVFrame *frame);
|
||||||
|
|
||||||
|
|||||||
@@ -285,15 +285,12 @@ void gsr_capture_xcomposite_tick(gsr_capture_xcomposite *self, AVCodecContext *v
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gsr_capture_xcomposite_consume_damage(gsr_capture_xcomposite *self) {
|
bool gsr_capture_xcomposite_is_damaged(gsr_capture_xcomposite *self) {
|
||||||
if(self->damage_event) {
|
return self->damage_event ? self->damaged : true;
|
||||||
const bool damaged = self->damaged;
|
}
|
||||||
self->damaged = false;
|
|
||||||
//fprintf(stderr, "consume: %s\n", damaged ? "yes" : "no");
|
void gsr_capture_xcomposite_clear_damage(gsr_capture_xcomposite *self) {
|
||||||
return damaged;
|
self->damaged = false;
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gsr_capture_xcomposite_should_stop(gsr_capture_xcomposite *self, bool *err) {
|
bool gsr_capture_xcomposite_should_stop(gsr_capture_xcomposite *self, bool *err) {
|
||||||
|
|||||||
@@ -76,9 +76,14 @@ static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *v
|
|||||||
gsr_capture_xcomposite_tick(&cap_xcomp->xcomposite, video_codec_context);
|
gsr_capture_xcomposite_tick(&cap_xcomp->xcomposite, video_codec_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool gsr_capture_xcomposite_cuda_consume_damage(gsr_capture *cap) {
|
static bool gsr_capture_xcomposite_cuda_is_damaged(gsr_capture *cap) {
|
||||||
gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv;
|
gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv;
|
||||||
return gsr_capture_xcomposite_consume_damage(&cap_xcomp->xcomposite);
|
return gsr_capture_xcomposite_is_damaged(&cap_xcomp->xcomposite);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gsr_capture_xcomposite_cuda_clear_damage(gsr_capture *cap) {
|
||||||
|
gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv;
|
||||||
|
gsr_capture_xcomposite_clear_damage(&cap_xcomp->xcomposite);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool gsr_capture_xcomposite_cuda_should_stop(gsr_capture *cap, bool *err) {
|
static bool gsr_capture_xcomposite_cuda_should_stop(gsr_capture *cap, bool *err) {
|
||||||
@@ -149,7 +154,8 @@ gsr_capture* gsr_capture_xcomposite_cuda_create(const gsr_capture_xcomposite_cud
|
|||||||
*cap = (gsr_capture) {
|
*cap = (gsr_capture) {
|
||||||
.start = gsr_capture_xcomposite_cuda_start,
|
.start = gsr_capture_xcomposite_cuda_start,
|
||||||
.tick = gsr_capture_xcomposite_cuda_tick,
|
.tick = gsr_capture_xcomposite_cuda_tick,
|
||||||
.consume_damage = gsr_capture_xcomposite_cuda_consume_damage,
|
.is_damaged = gsr_capture_xcomposite_cuda_is_damaged,
|
||||||
|
.clear_damage = gsr_capture_xcomposite_cuda_clear_damage,
|
||||||
.should_stop = gsr_capture_xcomposite_cuda_should_stop,
|
.should_stop = gsr_capture_xcomposite_cuda_should_stop,
|
||||||
.capture = gsr_capture_xcomposite_cuda_capture,
|
.capture = gsr_capture_xcomposite_cuda_capture,
|
||||||
.capture_end = NULL,
|
.capture_end = NULL,
|
||||||
|
|||||||
@@ -43,9 +43,14 @@ static void gsr_capture_xcomposite_vaapi_tick(gsr_capture *cap, AVCodecContext *
|
|||||||
gsr_capture_xcomposite_tick(&cap_xcomp->xcomposite, video_codec_context);
|
gsr_capture_xcomposite_tick(&cap_xcomp->xcomposite, video_codec_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool gsr_capture_xcomposite_vaapi_consume_damage(gsr_capture *cap) {
|
static bool gsr_capture_xcomposite_vaapi_is_damaged(gsr_capture *cap) {
|
||||||
gsr_capture_xcomposite_vaapi *cap_xcomp = cap->priv;
|
gsr_capture_xcomposite_vaapi *cap_xcomp = cap->priv;
|
||||||
return gsr_capture_xcomposite_consume_damage(&cap_xcomp->xcomposite);
|
return gsr_capture_xcomposite_is_damaged(&cap_xcomp->xcomposite);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gsr_capture_xcomposite_vaapi_clear_damage(gsr_capture *cap) {
|
||||||
|
gsr_capture_xcomposite_vaapi *cap_xcomp = cap->priv;
|
||||||
|
gsr_capture_xcomposite_clear_damage(&cap_xcomp->xcomposite);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool gsr_capture_xcomposite_vaapi_should_stop(gsr_capture *cap, bool *err) {
|
static bool gsr_capture_xcomposite_vaapi_should_stop(gsr_capture *cap, bool *err) {
|
||||||
@@ -103,7 +108,8 @@ gsr_capture* gsr_capture_xcomposite_vaapi_create(const gsr_capture_xcomposite_va
|
|||||||
*cap = (gsr_capture) {
|
*cap = (gsr_capture) {
|
||||||
.start = gsr_capture_xcomposite_vaapi_start,
|
.start = gsr_capture_xcomposite_vaapi_start,
|
||||||
.tick = gsr_capture_xcomposite_vaapi_tick,
|
.tick = gsr_capture_xcomposite_vaapi_tick,
|
||||||
.consume_damage = gsr_capture_xcomposite_vaapi_consume_damage,
|
.is_damaged = gsr_capture_xcomposite_vaapi_is_damaged,
|
||||||
|
.clear_damage = gsr_capture_xcomposite_vaapi_clear_damage,
|
||||||
.should_stop = gsr_capture_xcomposite_vaapi_should_stop,
|
.should_stop = gsr_capture_xcomposite_vaapi_should_stop,
|
||||||
.capture = gsr_capture_xcomposite_vaapi_capture,
|
.capture = gsr_capture_xcomposite_vaapi_capture,
|
||||||
.capture_end = NULL,
|
.capture_end = NULL,
|
||||||
|
|||||||
@@ -2719,13 +2719,15 @@ int main(int argc, char **argv) {
|
|||||||
damage_fps_counter = 0;
|
damage_fps_counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool damaged = !capture->consume_damage || capture->consume_damage(capture);
|
const bool damaged = !capture->is_damaged || capture->is_damaged(capture);
|
||||||
if(damaged) {
|
if(damaged) {
|
||||||
++damage_fps_counter;
|
++damage_fps_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
double frame_time_overflow = frame_timer_elapsed - target_fps;
|
double frame_time_overflow = frame_timer_elapsed - target_fps;
|
||||||
if (frame_time_overflow >= 0.0 && damaged) {
|
if (frame_time_overflow >= 0.0 && damaged) {
|
||||||
|
if(capture->clear_damage)
|
||||||
|
capture->clear_damage(capture);
|
||||||
frame_time_overflow = std::min(frame_time_overflow, target_fps);
|
frame_time_overflow = std::min(frame_time_overflow, target_fps);
|
||||||
frame_timer_start = time_now - frame_time_overflow;
|
frame_timer_start = time_now - frame_time_overflow;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user